Debian Codegraph @

contrib/parsers/cx25821/setvideosetting.c

raw
1 /*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <[email protected]>, <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <fcntl.h>
26 #include <string.h>
27 #include <linux/errno.h>
28 #include <linux/ioctl.h>
29
30
31 #define SET_VIDEO_STD 800
32 #define SET_PIXEL_FORMAT 1000
33 #define ENABLE_CIF_RESOLUTION 1001
34
35
36 #define PIXEL_FRMT_422 4
37 #define PIXEL_FRMT_411 5
38 #define PIXEL_FRMT_Y8 6
39 #define ALL_DECODERS 752
40
41 typedef struct {
42 char *vid_stdname;
43 int pixel_format;
44 int cif_resolution_enable;
45 int cif_width;
46 int decoder_select;
47 int command;
48 } downstream_user_struct;
49
50
51 void print_usage()
52 {
53 printf("\n*********************************\n");
54 printf("Sample Usage: ./set d 1 standard NTSC format 422 7 resolution 320 7\n");
55 printf(" device_id Device ID (1 and above) for MultiCard\n");
56 printf(" standard Video Standard (PAL/NTSC)\n");
57 printf(" format Output Pixel Format (422 or 411) for specific decoder (e.g. 7)\n");
58 printf(" resolution 352/320 for CIF and 720 for D1 resolution for specific decoder (e.g. 7)\n");
59 }
60
61 int main(int argc, char** argv)
62 {
63 unsigned int cmd= 0 ;
64 int fp;
65 int i = 1, j = 0, k = 0, len = 0;
66 int mode = 0;
67 int pixel_format = 0;
68 int width_input = 0;
69 int decoder_input = 0;
70 int device_id = 0, video_id = 11;
71 char * temp2;
72 char *device_str[4] = {"/dev/video11", "/dev/video23", "/dev/video35", "/dev/video47"};
73
74 char mode_temp = 's';
75 char *param_temp;
76
77
78 if(argc < 3 || (tolower(*(argv[1])) != 'd') )
79 {
80 print_usage();
81 return -EINVAL;
82 }
83
84 sscanf(argv[2], "%d", &device_id );
85 i += 2;
86
87 if( device_id <= 0 || device_id > 4 )
88 {
89 print_usage();
90 return -EINVAL;
91 }
92
93 printf("\n********************************* \n");
94
95 if((fp = open(device_str[device_id-1], O_RDWR)) == -1)
96 {
97 printf("Error: cannot open device file %s !\n", device_str[device_id-1]);
98 return -EINVAL;
99 }
100
101 printf("Device %s open for IOCTL successfully!\n", device_str[device_id-1]);
102
103
104 for( ; i < argc; i++)
105 {
106 temp2 = argv[i];
107 mode_temp = tolower(temp2[0]);
108 param_temp = argv[i+1];
109
110
111 switch(mode_temp)
112 {
113 case 's':
114 {
115 downstream_user_struct arguments;
116 char * temp = param_temp;
117 arguments.vid_stdname = (tolower(temp[0]) == 'p') ? "PAL" : "NTSC";
118 arguments.command = SET_VIDEO_STD;
119
120 printf("User parameters: vid_stdname = %s, command = %d \n", arguments.vid_stdname, arguments.command);
121
122 if((ioctl(fp, arguments.command, (char *) &arguments)) == -1)
123 printf("Error: ioctl FAILED!\n");
124 }
125 break;
126
127 case 'f':
128 {
129 sscanf(param_temp, "%d", &pixel_format );
130 sscanf(argv[i+2], "%d", &decoder_input ); i++;
131
132 if( pixel_format < 411 || pixel_format > 422)
133 pixel_format = 422;
134
135 if( decoder_input < 0 )
136 decoder_input = ALL_DECODERS;
137
138 downstream_user_struct arguments;
139 arguments.pixel_format = (pixel_format == 411) ? PIXEL_FRMT_411 : PIXEL_FRMT_422;
140 arguments.decoder_select = decoder_input;
141 arguments.command = SET_PIXEL_FORMAT;
142
143 printf("User parameters: pixel_format = %d, decoder_input = %d, command = %d \n", arguments.pixel_format, arguments.decoder_select, arguments.command);
144
145 if((ioctl(fp, arguments.command, (char *) &arguments)) == -1)
146 printf("Error: ioctl FAILED!\n");
147 }
148 break;
149
150 case 'r':
151 {
152 sscanf(param_temp, "%d", &width_input );
153 sscanf(argv[i+2], "%d", &decoder_input ); i++;
154
155 if( width_input < 320 || width_input > 352 )
156 width_input = 720;
157
158 if( decoder_input < 0 )
159 decoder_input = ALL_DECODERS;
160
161 downstream_user_struct arguments;
162 arguments.cif_resolution_enable = (width_input == 320 || width_input == 352) ? 1 : 0;
163 arguments.cif_width = width_input;
164 arguments.decoder_select = decoder_input;
165 arguments.command = ENABLE_CIF_RESOLUTION;
166
167 printf("User parameters: cif_resolution_enable = %d, decoder_input = %d, command = %d \n", arguments.cif_resolution_enable, arguments.decoder_select, arguments.command);
168
169
170 if((ioctl(fp, arguments.command, (char *) &arguments)) == -1)
171 printf("Error: ioctl FAILED!\n");
172 }
173 break;
174
175 default:
176 printf("Please verify the options are correct!\n");
177 break;
178 }
179
180 i++;
181 }
182
183
184 printf("********************************* \n\n");
185 close(fp);
186 return 0;
187 }