aboutsummaryrefslogtreecommitdiffstats
path: root/src/v4l.c
blob: 7732346e0d09e5d028d64f79aef6fd01b0178c17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include"v4l.h"
#include<time.h>
#include<errno.h>
#include<gnome.h>
#include "support.h"

extern int frame_number;
extern int errno;

void print_cam(cam *cam){
	printf("\nCamera Info\n");
	printf("-------------\n");
	printf("device = %s, x = %d, y = %d\n",cam->video_dev, cam->x,cam->y);
	printf("depth = %d, desk_depth = %d, size = %d\n",cam->depth,cam->desk_depth,cam->size);
	printf("capture directory = %s, capture file = %s\n",cam->pixdir, cam->capturefile);
	printf("remote capture directory = %s, remote capture file = %s\n",cam->rpixdir, cam->rcapturefile);
	printf("remote host = %s, remote login = %s\n",cam->rhost,cam->rlogin);
	printf("timestamp = %s\n\n",cam->ts_string);
	
}
void print_palette(int p)
{

   switch (p) {
   case VIDEO_PALETTE_HI240:
      printf("High 240 cube (BT848)\n");
      break;

   case VIDEO_PALETTE_RGB565:
      printf("565 16 bit RGB\n");
      break;

   case VIDEO_PALETTE_RGB24:
      printf("24bit RGB\n");
      break;

   case VIDEO_PALETTE_RGB32:
      printf("32bit RGB\n");
      break;

   case VIDEO_PALETTE_RGB555:
      printf("555 15bit RGB\n");
      break;

   case VIDEO_PALETTE_YUV422:
      printf("YUV422 capture");
      break;

   case VIDEO_PALETTE_YUYV:
      printf("YUYV\n");
      break;

   case VIDEO_PALETTE_UYVY:
      printf("UYVY\n");
      break;

   case VIDEO_PALETTE_YUV420:
      printf("YUV420\n");
      break;

   case VIDEO_PALETTE_YUV411:
      printf("YUV411 capture\n");
      break;

   case VIDEO_PALETTE_RAW:
      printf("RAW capture (BT848)\n");
      break;

   case VIDEO_PALETTE_YUV422P:
      printf("YUV 4:2:2 Planar");
      break;

   case VIDEO_PALETTE_YUV411P:
      printf("YUV 4:1:1 Planar\n");
      break;

   case VIDEO_PALETTE_YUV420P:
      printf("YUV 4:2:0 Planar\n");
      break;

   case VIDEO_PALETTE_YUV410P:
      printf("YUV 4:1:0 Planar\n");
      break;
   }
}

void camera_cap(cam * cam)
{
   char *msg;
   if(ioctl(cam->dev, VIDIOCGCAP, &cam->vid_cap) == -1) {
      if(cam->debug == TRUE) {
         fprintf(stderr, "VIDIOCGCAP  --  could not get camera capabilities, exiting.....\n");
      }
      msg = g_strdup_printf(_("Could not connect to video device (%s).\nPlease check connection."), cam->video_dev);
      error_dialog(msg);
      g_free(msg);
      exit(0);
   }
   if(cam->x > 0 && cam->y > 0) {
      if(cam->vid_cap.maxwidth < cam->x) {
         cam->x = cam->vid_cap.maxwidth;
      }
      if(cam->vid_cap.minwidth > cam->x) {
         cam->x = cam->vid_cap.minwidth;
      }
      if(cam->vid_cap.maxheight < cam->y) {
         cam->y = cam->vid_cap.maxheight;
      }
      if(cam->vid_cap.minheight > cam->y) {
         cam->y = cam->vid_cap.minheight;
      }
   } else {
      switch (cam->size) {
      case PICMAX:
         cam->x = cam->vid_cap.maxwidth;
         cam->y = cam->vid_cap.maxheight;
         break;

      case PICMIN:
         cam->x = cam->vid_cap.minwidth;
         cam->y = cam->vid_cap.minheight;
         break;

      case PICHALF:
         cam->x = cam->vid_cap.maxwidth / 2;
         cam->y = cam->vid_cap.maxheight / 2;
         break;

      default:
         cam->x = cam->vid_cap.maxwidth / 2;
         cam->y = cam->vid_cap.maxheight / 2;
         break;
      }
   }
   if((cam->vid_cap.type & VID_TYPE_CAPTURE) != 1) {
      cam->read = TRUE;
   }

   if(cam->debug == TRUE) {
      printf("\nVIDIOCGCAP\n");
      printf("device name = %s\n", cam->vid_cap.name);
      printf("device type = %d\n", cam->vid_cap.type);
      if(cam->read == FALSE){
		  printf("can use mmap()\n");
	  }
      printf("# of channels = %d\n", cam->vid_cap.channels);
      printf("# of audio devices = %d\n", cam->vid_cap.audios);
      printf("max width = %d\n", cam->vid_cap.maxwidth);
      printf("max height = %d\n", cam->vid_cap.maxheight);
      printf("min width = %d\n", cam->vid_cap.minwidth);
      printf("min height = %d\n", cam->vid_cap.minheight);
   }
}

void
set_pic_info(cam* cam) {
	char *msg;
	if(cam->debug) {
		g_message("SET PIC");
	}
	//cam->vid_pic.palette = VIDEO_PALETTE_RGB24;
	//cam->vid_pic.depth = 24;
	//cam->vid_pic.palette = VIDEO_PALETTE_YUV420P;
	if(ioctl(cam->dev, VIDIOCSPICT, &cam->vid_pic) == -1) {
		if(cam->debug) {
			g_message("VIDIOCSPICT  --  could not set picture info, exiting....");
		}
		msg = g_strdup_printf(_("Could not connect to video device (%s).\nPlease check connection."), cam->video_dev);
		error_dialog(msg);
		g_free(msg);
		exit(0);
	}
}

void get_pic_info(cam * cam){
//set_pic_info(cam);
   char *msg;
	
   if(ioctl(cam->dev, VIDIOCGPICT, &cam->vid_pic) == -1) {
      msg = g_strdup_printf(_("Could not connect to video device (%s).\nPlease check connection."), cam->video_dev);
      error_dialog(msg);
      if(cam->debug == TRUE) {
         fprintf(stderr, "VIDIOCGPICT  --  could not get picture info, exiting....\n");
      }
      g_free(msg);
      exit(0);
   }
	
   if(cam->debug == TRUE) {
      printf("\nVIDIOCGPICT:\n");
      printf("bright = %d\n", cam->vid_pic.brightness);
      printf("hue = %d\n", cam->vid_pic.hue);
      printf("colour = %d\n", cam->vid_pic.colour);
      printf("contrast = %d\n", cam->vid_pic.contrast);
      printf("whiteness = %d\n", cam->vid_pic.whiteness);
      printf("colour depth = %d\n", cam->vid_pic.depth);
      print_palette(cam->vid_pic.palette);
   }
}

void get_win_info(cam * cam)
{
   gchar *msg;
   if(ioctl(cam->dev, VIDIOCGWIN, &cam->vid_win) == -1) {
      msg = g_strdup_printf(_("Could not connect to video device (%s).\nPlease check connection."), cam->video_dev);
      error_dialog(msg);
      if(cam->debug == TRUE) {
         fprintf(stderr, "VIDIOCGWIN  --  could not get window info, exiting....\n");
      }
      exit(0);
   }
   if(cam->debug == TRUE) {
      printf("\nVIDIOCGWIN\n");
      printf("x = %d\n", cam->vid_win.x);
      printf("y = %d\n", cam->vid_win.y);
      printf("width = %d\n", cam->vid_win.width);
      printf("height = %d\n", cam->vid_win.height);
      printf("chromakey = %d\n", cam->vid_win.chromakey);
      printf("flags = %d\n", cam->vid_win.flags);
   }
}
void set_win_info(cam * cam)
{
   gchar *msg;
   if(ioctl(cam->dev, VIDIOCSWIN, &cam->vid_win) == -1) {
      msg = g_strdup_printf(_("Could not connect to video device (%s).\nPlease check connection."), cam->video_dev);
      error_dialog(msg);
      if(cam->debug == TRUE) {
         fprintf(stderr, "VIDIOCSWIN  --  could not set window info, exiting....\nerrno = %d", errno);
      }
      g_free(msg);
      exit(0);
   }

}

void set_buffer(cam * cam)
{
   char *msg;
   if(ioctl(cam->dev, VIDIOCGMBUF, &cam->vid_buf) == -1) {
      msg = g_strdup_printf(_("Could not connect to video device (%s).\nPlease check connection."), cam->video_dev);
      error_dialog(msg);
      if(cam->debug == TRUE) {
         fprintf(stderr, "VIDIOCGMBF  --  could not set buffer info, exiting...\n");
      }
      g_free(msg);
      exit(0);

   }
   
   if(cam->debug == TRUE) {
      printf("\nVIDIOCGMBUF\n");
      printf("mb.size = %d\n", cam->vid_buf.size);
      printf("mb.frames = %d\n", cam->vid_buf.frames);
      printf("mb.offset = %d\n", cam->vid_buf.offsets[1]);
   }

}

Privacy Policy