Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 1 | From 141d3b3593722eb3d588e7c4b1542f810bc25853 Mon Sep 17 00:00:00 2001 |
| 2 | From: Koen Kooi <koen@dominion.thruhere.net> |
| 3 | Date: Thu, 5 Jun 2014 11:29:20 -0500 |
| 4 | Subject: [PATCH] Add stdout mode to allow streaming over the network with nc |
| 5 | |
| 6 | Signed-off-by: Koen Kooi <koen@dominion.thruhere.net> |
| 7 | Signed-off-by: Chase Maupin <Chase.Maupin@ti.com> |
| 8 | --- |
| 9 | yavta.c | 315 ++++++++++++++++++++++++++++++++++----------------------------- |
| 10 | 1 file changed, 169 insertions(+), 146 deletions(-) |
| 11 | |
| 12 | diff --git a/yavta.c b/yavta.c |
| 13 | index 32adc26..b398da0 100644 |
| 14 | --- a/yavta.c |
| 15 | +++ b/yavta.c |
| 16 | @@ -309,7 +309,7 @@ static bool video_has_fd(struct device *dev) |
| 17 | static int video_set_fd(struct device *dev, int fd) |
| 18 | { |
| 19 | if (video_has_fd(dev)) { |
| 20 | - printf("Can't set fd (already open).\n"); |
| 21 | + fprintf(stderr, "Can't set fd (already open).\n"); |
| 22 | return -1; |
| 23 | } |
| 24 | |
| 25 | @@ -321,18 +321,18 @@ static int video_set_fd(struct device *dev, int fd) |
| 26 | static int video_open(struct device *dev, const char *devname) |
| 27 | { |
| 28 | if (video_has_fd(dev)) { |
| 29 | - printf("Can't open device (already open).\n"); |
| 30 | + fprintf(stderr, "Can't open device (already open).\n"); |
| 31 | return -1; |
| 32 | } |
| 33 | |
| 34 | dev->fd = open(devname, O_RDWR); |
| 35 | if (dev->fd < 0) { |
| 36 | - printf("Error opening device %s: %s (%d).\n", devname, |
| 37 | + fprintf(stderr, "Error opening device %s: %s (%d).\n", devname, |
| 38 | strerror(errno), errno); |
| 39 | return dev->fd; |
| 40 | } |
| 41 | |
| 42 | - printf("Device %s opened.\n", devname); |
| 43 | + fprintf(stderr, "Device %s opened.\n", devname); |
| 44 | |
| 45 | dev->opened = 1; |
| 46 | |
| 47 | @@ -352,7 +352,7 @@ static int video_querycap(struct device *dev, unsigned int *capabilities) |
| 48 | *capabilities = cap.capabilities & V4L2_CAP_DEVICE_CAPS |
| 49 | ? cap.device_caps : cap.capabilities; |
| 50 | |
| 51 | - printf("Device `%s' on `%s' is a video %s (%s mplanes) device.\n", |
| 52 | + fprintf(stderr, "Device `%s' on `%s' is a video %s (%s mplanes) device.\n", |
| 53 | cap.card, cap.bus_info, |
| 54 | video_is_capture(dev) ? "capture" : "output", |
| 55 | video_is_mplane(dev) ? "with" : "without"); |
| 56 | @@ -370,7 +370,7 @@ static int cap_get_buf_type(unsigned int capabilities) |
| 57 | } else if (capabilities & V4L2_CAP_VIDEO_OUTPUT) { |
| 58 | return V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 59 | } else { |
| 60 | - printf("Device supports neither capture nor output.\n"); |
| 61 | + fprintf(stderr, "Device supports neither capture nor output.\n"); |
| 62 | return -EINVAL; |
| 63 | } |
| 64 | |
| 65 | @@ -440,7 +440,7 @@ static int get_control(struct device *dev, unsigned int id, int type, |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | - printf("unable to get control 0x%8.8x: %s (%d).\n", |
| 70 | + fprintf(stderr, "unable to get control 0x%8.8x: %s (%d).\n", |
| 71 | id, strerror(errno), errno); |
| 72 | return -1; |
| 73 | } |
| 74 | @@ -484,12 +484,12 @@ static void set_control(struct device *dev, unsigned int id, int type, |
| 75 | val = old.value; |
| 76 | } |
| 77 | if (ret == -1) { |
| 78 | - printf("unable to set control 0x%8.8x: %s (%d).\n", |
| 79 | + fprintf(stderr, "unable to set control 0x%8.8x: %s (%d).\n", |
| 80 | id, strerror(errno), errno); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | - printf("Control 0x%08x set to %" PRId64 ", is %" PRId64 "\n", |
| 85 | + fprintf(stderr, "Control 0x%08x set to %" PRId64 ", is %" PRId64 "\n", |
| 86 | id, old_val, val); |
| 87 | } |
| 88 | |
| 89 | @@ -504,7 +504,7 @@ static int video_get_format(struct device *dev) |
| 90 | |
| 91 | ret = ioctl(dev->fd, VIDIOC_G_FMT, &fmt); |
| 92 | if (ret < 0) { |
| 93 | - printf("Unable to get format: %s (%d).\n", strerror(errno), |
| 94 | + fprintf(stderr, "Unable to get format: %s (%d).\n", strerror(errno), |
| 95 | errno); |
| 96 | return ret; |
| 97 | } |
| 98 | @@ -514,7 +514,7 @@ static int video_get_format(struct device *dev) |
| 99 | dev->height = fmt.fmt.pix_mp.height; |
| 100 | dev->num_planes = fmt.fmt.pix_mp.num_planes; |
| 101 | |
| 102 | - printf("Video format: %s (%08x) %ux%u field %s, %u planes: \n", |
| 103 | + fprintf(stderr, "Video format: %s (%08x) %ux%u field %s, %u planes: \n", |
| 104 | v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat, |
| 105 | fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height, |
| 106 | v4l2_field_name(fmt.fmt.pix_mp.field), |
| 107 | @@ -527,7 +527,7 @@ static int video_get_format(struct device *dev) |
| 108 | fmt.fmt.pix_mp.plane_fmt[i].bytesperline ? |
| 109 | fmt.fmt.pix_mp.plane_fmt[i].sizeimage : 0; |
| 110 | |
| 111 | - printf(" * Stride %u, buffer size %u\n", |
| 112 | + fprintf(stderr, " * Stride %u, buffer size %u\n", |
| 113 | fmt.fmt.pix_mp.plane_fmt[i].bytesperline, |
| 114 | fmt.fmt.pix_mp.plane_fmt[i].sizeimage); |
| 115 | } |
| 116 | @@ -539,7 +539,7 @@ static int video_get_format(struct device *dev) |
| 117 | dev->plane_fmt[0].bytesperline = fmt.fmt.pix.bytesperline; |
| 118 | dev->plane_fmt[0].sizeimage = fmt.fmt.pix.bytesperline ? fmt.fmt.pix.sizeimage : 0; |
| 119 | |
| 120 | - printf("Video format: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n", |
| 121 | + fprintf(stderr, "Video format: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n", |
| 122 | v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat, |
| 123 | fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline, |
| 124 | v4l2_field_name(fmt.fmt.pix_mp.field), |
| 125 | @@ -581,25 +581,25 @@ static int video_set_format(struct device *dev, unsigned int w, unsigned int h, |
| 126 | |
| 127 | ret = ioctl(dev->fd, VIDIOC_S_FMT, &fmt); |
| 128 | if (ret < 0) { |
| 129 | - printf("Unable to set format: %s (%d).\n", strerror(errno), |
| 130 | + fprintf(stderr, "Unable to set format: %s (%d).\n", strerror(errno), |
| 131 | errno); |
| 132 | return ret; |
| 133 | } |
| 134 | |
| 135 | if (video_is_mplane(dev)) { |
| 136 | - printf("Video format set: %s (%08x) %ux%u field %s, %u planes: \n", |
| 137 | + fprintf(stderr, "Video format set: %s (%08x) %ux%u field %s, %u planes: \n", |
| 138 | v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat, |
| 139 | fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height, |
| 140 | v4l2_field_name(fmt.fmt.pix_mp.field), |
| 141 | fmt.fmt.pix_mp.num_planes); |
| 142 | |
| 143 | for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++) { |
| 144 | - printf(" * Stride %u, buffer size %u\n", |
| 145 | + fprintf(stderr, " * Stride %u, buffer size %u\n", |
| 146 | fmt.fmt.pix_mp.plane_fmt[i].bytesperline, |
| 147 | fmt.fmt.pix_mp.plane_fmt[i].sizeimage); |
| 148 | } |
| 149 | } else { |
| 150 | - printf("Video format set: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n", |
| 151 | + fprintf(stderr, "Video format set: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n", |
| 152 | v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat, |
| 153 | fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline, |
| 154 | v4l2_field_name(fmt.fmt.pix.field), |
| 155 | @@ -619,16 +619,16 @@ static int video_set_framerate(struct device *dev, struct v4l2_fract *time_per_f |
| 156 | |
| 157 | ret = ioctl(dev->fd, VIDIOC_G_PARM, &parm); |
| 158 | if (ret < 0) { |
| 159 | - printf("Unable to get frame rate: %s (%d).\n", |
| 160 | + fprintf(stderr, "Unable to get frame rate: %s (%d).\n", |
| 161 | strerror(errno), errno); |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | - printf("Current frame rate: %u/%u\n", |
| 166 | + fprintf(stderr, "Current frame rate: %u/%u\n", |
| 167 | parm.parm.capture.timeperframe.numerator, |
| 168 | parm.parm.capture.timeperframe.denominator); |
| 169 | |
| 170 | - printf("Setting frame rate to: %u/%u\n", |
| 171 | + fprintf(stderr, "Setting frame rate to: %u/%u\n", |
| 172 | time_per_frame->numerator, |
| 173 | time_per_frame->denominator); |
| 174 | |
| 175 | @@ -637,19 +637,19 @@ static int video_set_framerate(struct device *dev, struct v4l2_fract *time_per_f |
| 176 | |
| 177 | ret = ioctl(dev->fd, VIDIOC_S_PARM, &parm); |
| 178 | if (ret < 0) { |
| 179 | - printf("Unable to set frame rate: %s (%d).\n", strerror(errno), |
| 180 | + fprintf(stderr, "Unable to set frame rate: %s (%d).\n", strerror(errno), |
| 181 | errno); |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | ret = ioctl(dev->fd, VIDIOC_G_PARM, &parm); |
| 186 | if (ret < 0) { |
| 187 | - printf("Unable to get frame rate: %s (%d).\n", strerror(errno), |
| 188 | + fprintf(stderr, "Unable to get frame rate: %s (%d).\n", strerror(errno), |
| 189 | errno); |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | - printf("Frame rate set: %u/%u\n", |
| 194 | + fprintf(stderr, "Frame rate set: %u/%u\n", |
| 195 | parm.parm.capture.timeperframe.numerator, |
| 196 | parm.parm.capture.timeperframe.denominator); |
| 197 | return 0; |
| 198 | @@ -674,7 +674,7 @@ static int video_buffer_mmap(struct device *dev, struct buffer *buffer, |
| 199 | buffer->mem[i] = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, |
| 200 | dev->fd, offset); |
| 201 | if (buffer->mem[i] == MAP_FAILED) { |
| 202 | - printf("Unable to map buffer %u/%u: %s (%d)\n", |
| 203 | + fprintf(stderr, "Unable to map buffer %u/%u: %s (%d)\n", |
| 204 | buffer->idx, i, strerror(errno), errno); |
| 205 | return -1; |
| 206 | } |
| 207 | @@ -682,7 +682,7 @@ static int video_buffer_mmap(struct device *dev, struct buffer *buffer, |
| 208 | buffer->size[i] = length; |
| 209 | buffer->padding[i] = 0; |
| 210 | |
| 211 | - printf("Buffer %u/%u mapped at address %p.\n", |
| 212 | + fprintf(stderr, "Buffer %u/%u mapped at address %p.\n", |
| 213 | buffer->idx, i, buffer->mem[i]); |
| 214 | } |
| 215 | |
| 216 | @@ -697,7 +697,7 @@ static int video_buffer_munmap(struct device *dev, struct buffer *buffer) |
| 217 | for (i = 0; i < dev->num_planes; i++) { |
| 218 | ret = munmap(buffer->mem[i], buffer->size[i]); |
| 219 | if (ret < 0) { |
| 220 | - printf("Unable to unmap buffer %u/%u: %s (%d)\n", |
| 221 | + fprintf(stderr, "Unable to unmap buffer %u/%u: %s (%d)\n", |
| 222 | buffer->idx, i, strerror(errno), errno); |
| 223 | } |
| 224 | |
| 225 | @@ -725,7 +725,7 @@ static int video_buffer_alloc_userptr(struct device *dev, struct buffer *buffer, |
| 226 | ret = posix_memalign(&buffer->mem[i], page_size, |
| 227 | length + offset + padding); |
| 228 | if (ret < 0) { |
| 229 | - printf("Unable to allocate buffer %u/%u (%d)\n", |
| 230 | + fprintf(stderr, "Unable to allocate buffer %u/%u (%d)\n", |
| 231 | buffer->idx, i, ret); |
| 232 | return -ENOMEM; |
| 233 | } |
| 234 | @@ -734,7 +734,7 @@ static int video_buffer_alloc_userptr(struct device *dev, struct buffer *buffer, |
| 235 | buffer->size[i] = length; |
| 236 | buffer->padding[i] = padding; |
| 237 | |
| 238 | - printf("Buffer %u/%u allocated at address %p.\n", |
| 239 | + fprintf(stderr, "Buffer %u/%u allocated at address %p.\n", |
| 240 | buffer->idx, i, buffer->mem[i]); |
| 241 | } |
| 242 | |
| 243 | @@ -809,12 +809,12 @@ static int video_alloc_buffers(struct device *dev, int nbufs, |
| 244 | |
| 245 | ret = ioctl(dev->fd, VIDIOC_REQBUFS, &rb); |
| 246 | if (ret < 0) { |
| 247 | - printf("Unable to request buffers: %s (%d).\n", strerror(errno), |
| 248 | + fprintf(stderr, "Unable to request buffers: %s (%d).\n", strerror(errno), |
| 249 | errno); |
| 250 | return ret; |
| 251 | } |
| 252 | |
| 253 | - printf("%u buffers requested.\n", rb.count); |
| 254 | + fprintf(stderr, "%u buffers requested.\n", rb.count); |
| 255 | |
| 256 | buffers = malloc(rb.count * sizeof buffers[0]); |
| 257 | if (buffers == NULL) |
| 258 | @@ -835,12 +835,12 @@ static int video_alloc_buffers(struct device *dev, int nbufs, |
| 259 | |
| 260 | ret = ioctl(dev->fd, VIDIOC_QUERYBUF, &buf); |
| 261 | if (ret < 0) { |
| 262 | - printf("Unable to query buffer %u: %s (%d).\n", i, |
| 263 | + fprintf(stderr, "Unable to query buffer %u: %s (%d).\n", i, |
| 264 | strerror(errno), errno); |
| 265 | return ret; |
| 266 | } |
| 267 | get_ts_flags(buf.flags, &ts_type, &ts_source); |
| 268 | - printf("length: %u offset: %u timestamp type/source: %s/%s\n", |
| 269 | + fprintf(stderr, "length: %u offset: %u timestamp type/source: %s/%s\n", |
| 270 | buf.length, buf.m.offset, ts_type, ts_source); |
| 271 | |
| 272 | buffers[i].idx = i; |
| 273 | @@ -899,12 +899,12 @@ static int video_free_buffers(struct device *dev) |
| 274 | |
| 275 | ret = ioctl(dev->fd, VIDIOC_REQBUFS, &rb); |
| 276 | if (ret < 0) { |
| 277 | - printf("Unable to release buffers: %s (%d).\n", |
| 278 | + fprintf(stderr, "Unable to release buffers: %s (%d).\n", |
| 279 | strerror(errno), errno); |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | - printf("%u buffers released.\n", dev->nbufs); |
| 284 | + fprintf(stderr, "%u buffers released.\n", dev->nbufs); |
| 285 | |
| 286 | free(dev->buffers); |
| 287 | dev->nbufs = 0; |
| 288 | @@ -974,7 +974,7 @@ static int video_queue_buffer(struct device *dev, int index, enum buffer_fill_mo |
| 289 | |
| 290 | ret = ioctl(dev->fd, VIDIOC_QBUF, &buf); |
| 291 | if (ret < 0) |
| 292 | - printf("Unable to queue buffer: %s (%d).\n", |
| 293 | + fprintf(stderr, "Unable to queue buffer: %s (%d).\n", |
| 294 | strerror(errno), errno); |
| 295 | |
| 296 | return ret; |
| 297 | @@ -987,7 +987,7 @@ static int video_enable(struct device *dev, int enable) |
| 298 | |
| 299 | ret = ioctl(dev->fd, enable ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &type); |
| 300 | if (ret < 0) { |
| 301 | - printf("Unable to %s streaming: %s (%d).\n", |
| 302 | + fprintf(stderr, "Unable to %s streaming: %s (%d).\n", |
| 303 | enable ? "start" : "stop", strerror(errno), errno); |
| 304 | return ret; |
| 305 | } |
| 306 | @@ -1009,10 +1009,10 @@ static void video_query_menu(struct device *dev, struct v4l2_queryctrl *query, |
| 307 | continue; |
| 308 | |
| 309 | if (query->type == V4L2_CTRL_TYPE_MENU) |
| 310 | - printf(" %u: %.32s%s\n", menu.index, menu.name, |
| 311 | + fprintf(stderr, " %u: %.32s%s\n", menu.index, menu.name, |
| 312 | menu.index == value ? " (*)" : ""); |
| 313 | else |
| 314 | - printf(" %u: %lld%s\n", menu.index, menu.value, |
| 315 | + fprintf(stderr, " %u: %lld%s\n", menu.index, menu.value, |
| 316 | menu.index == value ? " (*)" : ""); |
| 317 | }; |
| 318 | } |
| 319 | @@ -1043,7 +1043,7 @@ static void video_list_controls(struct device *dev) |
| 320 | continue; |
| 321 | |
| 322 | if (query.type == V4L2_CTRL_TYPE_CTRL_CLASS) { |
| 323 | - printf("--- %s (class 0x%08x) ---\n", query.name, query.id); |
| 324 | + fprintf(stderr, "--- %s (class 0x%08x) ---\n", query.name, query.id); |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | @@ -1053,7 +1053,7 @@ static void video_list_controls(struct device *dev) |
| 329 | else |
| 330 | sprintf(value, "%" PRId64, val64); |
| 331 | |
| 332 | - printf("control 0x%08x `%s' min %d max %d step %d default %d current %s.\n", |
| 333 | + fprintf(stderr, "control 0x%08x `%s' min %d max %d step %d default %d current %s.\n", |
| 334 | query.id, query.name, query.minimum, query.maximum, |
| 335 | query.step, query.default_value, value); |
| 336 | |
| 337 | @@ -1065,9 +1065,9 @@ static void video_list_controls(struct device *dev) |
| 338 | } |
| 339 | |
| 340 | if (nctrls) |
| 341 | - printf("%u control%s found.\n", nctrls, nctrls > 1 ? "s" : ""); |
| 342 | + fprintf(stderr, "%u control%s found.\n", nctrls, nctrls > 1 ? "s" : ""); |
| 343 | else |
| 344 | - printf("No control found.\n"); |
| 345 | + fprintf(stderr, "No control found.\n"); |
| 346 | } |
| 347 | |
| 348 | static void video_enum_frame_intervals(struct device *dev, __u32 pixelformat, |
| 349 | @@ -1088,30 +1088,30 @@ static void video_enum_frame_intervals(struct device *dev, __u32 pixelformat, |
| 350 | break; |
| 351 | |
| 352 | if (i != ival.index) |
| 353 | - printf("Warning: driver returned wrong ival index " |
| 354 | + fprintf(stderr, "Warning: driver returned wrong ival index " |
| 355 | "%u.\n", ival.index); |
| 356 | if (pixelformat != ival.pixel_format) |
| 357 | - printf("Warning: driver returned wrong ival pixel " |
| 358 | + fprintf(stderr, "Warning: driver returned wrong ival pixel " |
| 359 | "format %08x.\n", ival.pixel_format); |
| 360 | if (width != ival.width) |
| 361 | - printf("Warning: driver returned wrong ival width " |
| 362 | + fprintf(stderr, "Warning: driver returned wrong ival width " |
| 363 | "%u.\n", ival.width); |
| 364 | if (height != ival.height) |
| 365 | - printf("Warning: driver returned wrong ival height " |
| 366 | + fprintf(stderr, "Warning: driver returned wrong ival height " |
| 367 | "%u.\n", ival.height); |
| 368 | |
| 369 | if (i != 0) |
| 370 | - printf(", "); |
| 371 | + fprintf(stderr, ", "); |
| 372 | |
| 373 | switch (ival.type) { |
| 374 | case V4L2_FRMIVAL_TYPE_DISCRETE: |
| 375 | - printf("%u/%u", |
| 376 | + fprintf(stderr, "%u/%u", |
| 377 | ival.discrete.numerator, |
| 378 | ival.discrete.denominator); |
| 379 | break; |
| 380 | |
| 381 | case V4L2_FRMIVAL_TYPE_CONTINUOUS: |
| 382 | - printf("%u/%u - %u/%u", |
| 383 | + fprintf(stderr, "%u/%u - %u/%u", |
| 384 | ival.stepwise.min.numerator, |
| 385 | ival.stepwise.min.denominator, |
| 386 | ival.stepwise.max.numerator, |
| 387 | @@ -1119,7 +1119,7 @@ static void video_enum_frame_intervals(struct device *dev, __u32 pixelformat, |
| 388 | return; |
| 389 | |
| 390 | case V4L2_FRMIVAL_TYPE_STEPWISE: |
| 391 | - printf("%u/%u - %u/%u (by %u/%u)", |
| 392 | + fprintf(stderr, "%u/%u - %u/%u (by %u/%u)", |
| 393 | ival.stepwise.min.numerator, |
| 394 | ival.stepwise.min.denominator, |
| 395 | ival.stepwise.max.numerator, |
| 396 | @@ -1149,23 +1149,23 @@ static void video_enum_frame_sizes(struct device *dev, __u32 pixelformat) |
| 397 | break; |
| 398 | |
| 399 | if (i != frame.index) |
| 400 | - printf("Warning: driver returned wrong frame index " |
| 401 | + fprintf(stderr, "Warning: driver returned wrong frame index " |
| 402 | "%u.\n", frame.index); |
| 403 | if (pixelformat != frame.pixel_format) |
| 404 | - printf("Warning: driver returned wrong frame pixel " |
| 405 | + fprintf(stderr, "Warning: driver returned wrong frame pixel " |
| 406 | "format %08x.\n", frame.pixel_format); |
| 407 | |
| 408 | switch (frame.type) { |
| 409 | case V4L2_FRMSIZE_TYPE_DISCRETE: |
| 410 | - printf("\tFrame size: %ux%u (", frame.discrete.width, |
| 411 | + fprintf(stderr, "\tFrame size: %ux%u (", frame.discrete.width, |
| 412 | frame.discrete.height); |
| 413 | video_enum_frame_intervals(dev, frame.pixel_format, |
| 414 | frame.discrete.width, frame.discrete.height); |
| 415 | - printf(")\n"); |
| 416 | + fprintf(stderr, ")\n"); |
| 417 | break; |
| 418 | |
| 419 | case V4L2_FRMSIZE_TYPE_CONTINUOUS: |
| 420 | - printf("\tFrame size: %ux%u - %ux%u (", |
| 421 | + fprintf(stderr, "\tFrame size: %ux%u - %ux%u (", |
| 422 | frame.stepwise.min_width, |
| 423 | frame.stepwise.min_height, |
| 424 | frame.stepwise.max_width, |
| 425 | @@ -1173,11 +1173,11 @@ static void video_enum_frame_sizes(struct device *dev, __u32 pixelformat) |
| 426 | video_enum_frame_intervals(dev, frame.pixel_format, |
| 427 | frame.stepwise.max_width, |
| 428 | frame.stepwise.max_height); |
| 429 | - printf(")\n"); |
| 430 | + fprintf(stderr, ")\n"); |
| 431 | break; |
| 432 | |
| 433 | case V4L2_FRMSIZE_TYPE_STEPWISE: |
| 434 | - printf("\tFrame size: %ux%u - %ux%u (by %ux%u) (\n", |
| 435 | + fprintf(stderr, "\tFrame size: %ux%u - %ux%u (by %ux%u) (\n", |
| 436 | frame.stepwise.min_width, |
| 437 | frame.stepwise.min_height, |
| 438 | frame.stepwise.max_width, |
| 439 | @@ -1187,7 +1187,7 @@ static void video_enum_frame_sizes(struct device *dev, __u32 pixelformat) |
| 440 | video_enum_frame_intervals(dev, frame.pixel_format, |
| 441 | frame.stepwise.max_width, |
| 442 | frame.stepwise.max_height); |
| 443 | - printf(")\n"); |
| 444 | + fprintf(stderr, ")\n"); |
| 445 | break; |
| 446 | |
| 447 | default: |
| 448 | @@ -1211,19 +1211,19 @@ static void video_enum_formats(struct device *dev, enum v4l2_buf_type type) |
| 449 | break; |
| 450 | |
| 451 | if (i != fmt.index) |
| 452 | - printf("Warning: driver returned wrong format index " |
| 453 | + fprintf(stderr, "Warning: driver returned wrong format index " |
| 454 | "%u.\n", fmt.index); |
| 455 | if (type != fmt.type) |
| 456 | - printf("Warning: driver returned wrong format type " |
| 457 | + fprintf(stderr, "Warning: driver returned wrong format type " |
| 458 | "%u.\n", fmt.type); |
| 459 | |
| 460 | - printf("\tFormat %u: %s (%08x)\n", i, |
| 461 | + fprintf(stderr, "\tFormat %u: %s (%08x)\n", i, |
| 462 | v4l2_format_name(fmt.pixelformat), fmt.pixelformat); |
| 463 | - printf("\tType: %s (%u)\n", v4l2_buf_type_name(fmt.type), |
| 464 | + fprintf(stderr, "\tType: %s (%u)\n", v4l2_buf_type_name(fmt.type), |
| 465 | fmt.type); |
| 466 | - printf("\tName: %.32s\n", fmt.description); |
| 467 | + fprintf(stderr, "\tName: %.32s\n", fmt.description); |
| 468 | video_enum_frame_sizes(dev, fmt.pixelformat); |
| 469 | - printf("\n"); |
| 470 | + fprintf(stderr, "\n"); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | @@ -1241,13 +1241,13 @@ static void video_enum_inputs(struct device *dev) |
| 475 | break; |
| 476 | |
| 477 | if (i != input.index) |
| 478 | - printf("Warning: driver returned wrong input index " |
| 479 | + fprintf(stderr, "Warning: driver returned wrong input index " |
| 480 | "%u.\n", input.index); |
| 481 | |
| 482 | - printf("\tInput %u: %s.\n", i, input.name); |
| 483 | + fprintf(stderr, "\tInput %u: %s.\n", i, input.name); |
| 484 | } |
| 485 | |
| 486 | - printf("\n"); |
| 487 | + fprintf(stderr, "\n"); |
| 488 | } |
| 489 | |
| 490 | static int video_get_input(struct device *dev) |
| 491 | @@ -1257,7 +1257,7 @@ static int video_get_input(struct device *dev) |
| 492 | |
| 493 | ret = ioctl(dev->fd, VIDIOC_G_INPUT, &input); |
| 494 | if (ret < 0) { |
| 495 | - printf("Unable to get current input: %s (%d).\n", |
| 496 | + fprintf(stderr, "Unable to get current input: %s (%d).\n", |
| 497 | strerror(errno), errno); |
| 498 | return ret; |
| 499 | } |
| 500 | @@ -1272,7 +1272,7 @@ static int video_set_input(struct device *dev, unsigned int input) |
| 501 | |
| 502 | ret = ioctl(dev->fd, VIDIOC_S_INPUT, &_input); |
| 503 | if (ret < 0) |
| 504 | - printf("Unable to select input %u: %s (%d).\n", input, |
| 505 | + fprintf(stderr, "Unable to select input %u: %s (%d).\n", input, |
| 506 | strerror(errno), errno); |
| 507 | |
| 508 | return ret; |
| 509 | @@ -1291,14 +1291,14 @@ static int video_set_quality(struct device *dev, unsigned int quality) |
| 510 | |
| 511 | ret = ioctl(dev->fd, VIDIOC_S_JPEGCOMP, &jpeg); |
| 512 | if (ret < 0) { |
| 513 | - printf("Unable to set quality to %u: %s (%d).\n", quality, |
| 514 | + fprintf(stderr, "Unable to set quality to %u: %s (%d).\n", quality, |
| 515 | strerror(errno), errno); |
| 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | ret = ioctl(dev->fd, VIDIOC_G_JPEGCOMP, &jpeg); |
| 520 | if (ret >= 0) |
| 521 | - printf("Quality set to %u\n", jpeg.quality); |
| 522 | + fprintf(stderr, "Quality set to %u\n", jpeg.quality); |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | @@ -1313,7 +1313,7 @@ static int video_load_test_pattern(struct device *dev, const char *filename) |
| 527 | if (filename != NULL) { |
| 528 | fd = open(filename, O_RDONLY); |
| 529 | if (fd == -1) { |
| 530 | - printf("Unable to open test pattern file '%s': %s (%d).\n", |
| 531 | + fprintf(stderr, "Unable to open test pattern file '%s': %s (%d).\n", |
| 532 | filename, strerror(errno), errno); |
| 533 | return -errno; |
| 534 | } |
| 535 | @@ -1331,7 +1331,7 @@ static int video_load_test_pattern(struct device *dev, const char *filename) |
| 536 | if (filename != NULL) { |
| 537 | ret = read(fd, dev->pattern[plane], size); |
| 538 | if (ret != (int)size && dev->plane_fmt[plane].bytesperline != 0) { |
| 539 | - printf("Test pattern file size %u doesn't match image size %u\n", |
| 540 | + fprintf(stderr, "Test pattern file size %u doesn't match image size %u\n", |
| 541 | ret, size); |
| 542 | ret = -EINVAL; |
| 543 | goto done; |
| 544 | @@ -1341,7 +1341,7 @@ static int video_load_test_pattern(struct device *dev, const char *filename) |
| 545 | unsigned int i; |
| 546 | |
| 547 | if (dev->plane_fmt[plane].bytesperline == 0) { |
| 548 | - printf("Compressed format detected for plane %u and no test pattern filename given.\n" |
| 549 | + fprintf(stderr, "Compressed format detected for plane %u and no test pattern filename given.\n" |
| 550 | "The test pattern can't be generated automatically.\n", plane); |
| 551 | ret = -EINVAL; |
| 552 | goto done; |
| 553 | @@ -1410,7 +1410,7 @@ static void video_verify_buffer(struct device *dev, struct v4l2_buffer *buf) |
| 554 | |
| 555 | if (dev->plane_fmt[plane].sizeimage && |
| 556 | dev->plane_fmt[plane].sizeimage != length) |
| 557 | - printf("Warning: bytes used %u != image size %u for plane %u\n", |
| 558 | + fprintf(stderr, "Warning: bytes used %u != image size %u for plane %u\n", |
| 559 | length, dev->plane_fmt[plane].sizeimage, plane); |
| 560 | |
| 561 | if (buffer->padding[plane] == 0) |
| 562 | @@ -1424,16 +1424,16 @@ static void video_verify_buffer(struct device *dev, struct v4l2_buffer *buf) |
| 563 | } |
| 564 | |
| 565 | if (errors) { |
| 566 | - printf("Warning: %u bytes overwritten among %u first padding bytes for plane %u\n", |
| 567 | + fprintf(stderr, "Warning: %u bytes overwritten among %u first padding bytes for plane %u\n", |
| 568 | errors, dirty, plane); |
| 569 | |
| 570 | dirty = (dirty + 15) & ~15; |
| 571 | dirty = dirty > 32 ? 32 : dirty; |
| 572 | |
| 573 | for (i = 0; i < dirty; ++i) { |
| 574 | - printf("%02x ", data[i]); |
| 575 | + fprintf(stderr, "%02x ", data[i]); |
| 576 | if (i % 16 == 15) |
| 577 | - printf("\n"); |
| 578 | + fprintf(stderr, "\n"); |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | @@ -1481,18 +1481,32 @@ static void video_save_image(struct device *dev, struct v4l2_buffer *buf, |
| 583 | |
| 584 | ret = write(fd, dev->buffers[buf->index].mem[i], length); |
| 585 | if (ret < 0) { |
| 586 | - printf("write error: %s (%d)\n", strerror(errno), errno); |
| 587 | + fprintf(stderr, "write error: %s (%d)\n", strerror(errno), errno); |
| 588 | break; |
| 589 | } else if (ret != (int)length) |
| 590 | - printf("write error: only %d bytes written instead of %u\n", |
| 591 | + fprintf(stderr, "write error: only %d bytes written instead of %u\n", |
| 592 | ret, length); |
| 593 | } |
| 594 | close(fd); |
| 595 | } |
| 596 | |
| 597 | +static void video_stdout_image(struct device *dev, struct v4l2_buffer *buf) |
| 598 | +{ |
| 599 | + int ret; |
| 600 | + |
| 601 | + fprintf(stderr, "stdout"); |
| 602 | + ret = fwrite(dev->buffers[buf->index].mem, buf->bytesused, 1, stdout); |
| 603 | + |
| 604 | + if (ret < 0) |
| 605 | + fprintf(stderr, "write error: %s (%d)\n", strerror(errno), errno); |
| 606 | + else if (ret != (int)buf->bytesused) |
| 607 | + fprintf(stderr, "write error: only %d bytes written instead of %u\n", |
| 608 | + ret, buf->bytesused); |
| 609 | +} |
| 610 | + |
| 611 | static int video_do_capture(struct device *dev, unsigned int nframes, |
| 612 | unsigned int skip, unsigned int delay, const char *pattern, |
| 613 | - int do_requeue_last, enum buffer_fill_mode fill) |
| 614 | + int do_requeue_last, enum buffer_fill_mode fill, int do_stdout) |
| 615 | { |
| 616 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; |
| 617 | struct v4l2_buffer buf; |
| 618 | @@ -1529,7 +1543,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes, |
| 619 | ret = ioctl(dev->fd, VIDIOC_DQBUF, &buf); |
| 620 | if (ret < 0) { |
| 621 | if (errno != EIO) { |
| 622 | - printf("Unable to dequeue buffer: %s (%d).\n", |
| 623 | + fprintf(stderr, "Unable to dequeue buffer: %s (%d).\n", |
| 624 | strerror(errno), errno); |
| 625 | goto done; |
| 626 | } |
| 627 | @@ -1550,7 +1564,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes, |
| 628 | |
| 629 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 630 | get_ts_flags(buf.flags, &ts_type, &ts_source); |
| 631 | - printf("%u (%u) [%c] %s %u %u B %ld.%06ld %ld.%06ld %.3f fps ts %s/%s\n", i, buf.index, |
| 632 | + fprintf(stderr, "%u (%u) [%c] %s %u %u B %ld.%06ld %ld.%06ld %.3f fps ts %s/%s\n", i, buf.index, |
| 633 | (buf.flags & V4L2_BUF_FLAG_ERROR) ? 'E' : '-', |
| 634 | v4l2_field_name(buf.field), |
| 635 | buf.sequence, buf.bytesused, buf.timestamp.tv_sec, |
| 636 | @@ -1563,6 +1577,9 @@ static int video_do_capture(struct device *dev, unsigned int nframes, |
| 637 | if (video_is_capture(dev) && pattern && !skip) |
| 638 | video_save_image(dev, &buf, pattern, i); |
| 639 | |
| 640 | + if (video_is_capture(dev) && do_stdout && !skip) |
| 641 | + video_stdout_image(dev, &buf); |
| 642 | + |
| 643 | if (skip) |
| 644 | --skip; |
| 645 | |
| 646 | @@ -1577,7 +1594,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes, |
| 647 | |
| 648 | ret = video_queue_buffer(dev, buf.index, fill); |
| 649 | if (ret < 0) { |
| 650 | - printf("Unable to requeue buffer: %s (%d).\n", |
| 651 | + fprintf(stderr, "Unable to requeue buffer: %s (%d).\n", |
| 652 | strerror(errno), errno); |
| 653 | goto done; |
| 654 | } |
| 655 | @@ -1587,7 +1604,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes, |
| 656 | video_enable(dev, 0); |
| 657 | |
| 658 | if (nframes == 0) { |
| 659 | - printf("No frames captured.\n"); |
| 660 | + fprintf(stderr, "No frames captured.\n"); |
| 661 | goto done; |
| 662 | } |
| 663 | |
| 664 | @@ -1604,7 +1621,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes, |
| 665 | bps = size/(ts.tv_nsec/1000.0+1000000.0*ts.tv_sec)*1000000.0; |
| 666 | fps = i/(ts.tv_nsec/1000.0+1000000.0*ts.tv_sec)*1000000.0; |
| 667 | |
| 668 | - printf("Captured %u frames in %lu.%06lu seconds (%f fps, %f B/s).\n", |
| 669 | + fprintf(stderr, "Captured %u frames in %lu.%06lu seconds (%f fps, %f B/s).\n", |
| 670 | i, ts.tv_sec, ts.tv_nsec/1000, fps, bps); |
| 671 | |
| 672 | done: |
| 673 | @@ -1616,42 +1633,42 @@ done: |
| 674 | |
| 675 | static void usage(const char *argv0) |
| 676 | { |
| 677 | - printf("Usage: %s [options] device\n", argv0); |
| 678 | - printf("Supported options:\n"); |
| 679 | - printf("-B, --buffer-type Buffer type (\"capture\", \"output\",\n"); |
| 680 | - printf(" \"capture-mplane\" or \"output-mplane\")\n"); |
| 681 | - printf("-c, --capture[=nframes] Capture frames\n"); |
| 682 | - printf("-C, --check-overrun Verify dequeued frames for buffer overrun\n"); |
| 683 | - printf("-d, --delay Delay (in ms) before requeuing buffers\n"); |
| 684 | - printf("-f, --format format Set the video format\n"); |
| 685 | - printf("-F, --file[=name] Read/write frames from/to disk\n"); |
| 686 | - printf("\tFor video capture devices, the first '#' character in the file name is\n"); |
| 687 | - printf("\texpanded to the frame sequence number. The default file name is\n"); |
| 688 | - printf("\t'frame-#.bin'.\n"); |
| 689 | - printf("-h, --help Show this help screen\n"); |
| 690 | - printf("-i, --input input Select the video input\n"); |
| 691 | - printf("-I, --fill-frames Fill frames with check pattern before queuing them\n"); |
| 692 | - printf("-l, --list-controls List available controls\n"); |
| 693 | - printf("-n, --nbufs n Set the number of video buffers\n"); |
| 694 | - printf("-p, --pause Pause before starting the video stream\n"); |
| 695 | - printf("-q, --quality n MJPEG quality (0-100)\n"); |
| 696 | - printf("-r, --get-control ctrl Get control 'ctrl'\n"); |
| 697 | - printf("-R, --realtime=[priority] Enable realtime RR scheduling\n"); |
| 698 | - printf("-s, --size WxH Set the frame size\n"); |
| 699 | - printf("-t, --time-per-frame num/denom Set the time per frame (eg. 1/25 = 25 fps)\n"); |
| 700 | - printf("-u, --userptr Use the user pointers streaming method\n"); |
| 701 | - printf("-w, --set-control 'ctrl value' Set control 'ctrl' to 'value'\n"); |
| 702 | - printf(" --enum-formats Enumerate formats\n"); |
| 703 | - printf(" --enum-inputs Enumerate inputs\n"); |
| 704 | - printf(" --fd Use a numeric file descriptor insted of a device\n"); |
| 705 | - printf(" --field Interlaced format field order\n"); |
| 706 | - printf(" --no-query Don't query capabilities on open\n"); |
| 707 | - printf(" --offset User pointer buffer offset from page start\n"); |
| 708 | - printf(" --requeue-last Requeue the last buffers before streamoff\n"); |
| 709 | - printf(" --timestamp-source Set timestamp source on output buffers [eof, soe]\n"); |
| 710 | - printf(" --skip n Skip the first n frames\n"); |
| 711 | - printf(" --sleep-forever Sleep forever after configuring the device\n"); |
| 712 | - printf(" --stride value Line stride in bytes\n"); |
| 713 | + fprintf(stderr, "Usage: %s [options] device\n", argv0); |
| 714 | + fprintf(stderr, "Supported options:\n"); |
| 715 | + fprintf(stderr, "-B, --buffer-type Buffer type (\"capture\", \"output\",\n"); |
| 716 | + fprintf(stderr, " \"capture-mplane\" or \"output-mplane\")\n"); |
| 717 | + fprintf(stderr, "-c, --capture[=nframes] Capture frames\n"); |
| 718 | + fprintf(stderr, "-C, --check-overrun Verify dequeued frames for buffer overrun\n"); |
| 719 | + fprintf(stderr, "-d, --delay Delay (in ms) before requeuing buffers\n"); |
| 720 | + fprintf(stderr, "-f, --format format Set the video format\n"); |
| 721 | + fprintf(stderr, "-F, --file[=name] Read/write frames from/to disk\n"); |
| 722 | + fprintf(stderr, "\tFor video capture devices, the first '#' character in the file name is\n"); |
| 723 | + fprintf(stderr, "\texpanded to the frame sequence number. The default file name is\n"); |
| 724 | + fprintf(stderr, "\t'frame-#.bin'.\n"); |
| 725 | + fprintf(stderr, "-h, --help Show this help screen\n"); |
| 726 | + fprintf(stderr, "-i, --input input Select the video input\n"); |
| 727 | + fprintf(stderr, "-I, --fill-frames Fill frames with check pattern before queuing them\n"); |
| 728 | + fprintf(stderr, "-l, --list-controls List available controls\n"); |
| 729 | + fprintf(stderr, "-n, --nbufs n Set the number of video buffers\n"); |
| 730 | + fprintf(stderr, "-p, --pause Pause before starting the video stream\n"); |
| 731 | + fprintf(stderr, "-q, --quality n MJPEG quality (0-100)\n"); |
| 732 | + fprintf(stderr, "-r, --get-control ctrl Get control 'ctrl'\n"); |
| 733 | + fprintf(stderr, "-R, --realtime=[priority] Enable realtime RR scheduling\n"); |
| 734 | + fprintf(stderr, "-s, --size WxH Set the frame size\n"); |
| 735 | + fprintf(stderr, "-t, --time-per-frame num/denom Set the time per frame (eg. 1/25 = 25 fps)\n"); |
| 736 | + fprintf(stderr, "-u, --userptr Use the user pointers streaming method\n"); |
| 737 | + fprintf(stderr, "-w, --set-control 'ctrl value' Set control 'ctrl' to 'value'\n"); |
| 738 | + fprintf(stderr, " --enum-formats Enumerate formats\n"); |
| 739 | + fprintf(stderr, " --enum-inputs Enumerate inputs\n"); |
| 740 | + fprintf(stderr, " --fd Use a numeric file descriptor insted of a device\n"); |
| 741 | + fprintf(stderr, " --field Interlaced format field order\n"); |
| 742 | + fprintf(stderr, " --no-query Don't query capabilities on open\n"); |
| 743 | + fprintf(stderr, " --offset User pointer buffer offset from page start\n"); |
| 744 | + fprintf(stderr, " --requeue-last Requeue the last buffers before streamoff\n"); |
| 745 | + fprintf(stderr, " --timestamp-source Set timestamp source on output buffers [eof, soe]\n"); |
| 746 | + fprintf(stderr, " --skip n Skip the first n frames\n"); |
| 747 | + fprintf(stderr, " --sleep-forever Sleep forever after configuring the device\n"); |
| 748 | + fprintf(stderr, " --stride value Line stride in bytes\n"); |
| 749 | } |
| 750 | |
| 751 | #define OPT_ENUM_FORMATS 256 |
| 752 | @@ -1665,6 +1682,7 @@ static void usage(const char *argv0) |
| 753 | #define OPT_FD 264 |
| 754 | #define OPT_TSTAMP_SRC 265 |
| 755 | #define OPT_FIELD 266 |
| 756 | +#define OPT_STDOUT 267 |
| 757 | |
| 758 | static struct option opts[] = { |
| 759 | {"buffer-type", 1, 0, 'B'}, |
| 760 | @@ -1677,6 +1695,7 @@ static struct option opts[] = { |
| 761 | {"field", 1, 0, OPT_FIELD}, |
| 762 | {"file", 2, 0, 'F'}, |
| 763 | {"fill-frames", 0, 0, 'I'}, |
| 764 | + {"stdout", 0, 0, OPT_STDOUT}, |
| 765 | {"format", 1, 0, 'f'}, |
| 766 | {"help", 0, 0, 'h'}, |
| 767 | {"input", 1, 0, 'i'}, |
| 768 | @@ -1717,7 +1736,8 @@ int main(int argc, char *argv[]) |
| 769 | int do_list_controls = 0, do_get_control = 0, do_set_control = 0; |
| 770 | int do_sleep_forever = 0, do_requeue_last = 0; |
| 771 | int do_rt = 0; |
| 772 | - int no_query = 0; |
| 773 | + int no_query = 0; |
| 774 | + int do_stdout = 0; |
| 775 | char *endptr; |
| 776 | int c; |
| 777 | |
| 778 | @@ -1755,7 +1775,7 @@ int main(int argc, char *argv[]) |
| 779 | case 'B': |
| 780 | ret = v4l2_buf_type_from_string(optarg); |
| 781 | if (ret == -1) { |
| 782 | - printf("Bad buffer type \"%s\"\n", optarg); |
| 783 | + fprintf(stderr, "Bad buffer type \"%s\"\n", optarg); |
| 784 | return 1; |
| 785 | } |
| 786 | video_set_buf_type(&dev, ret); |
| 787 | @@ -1775,7 +1795,7 @@ int main(int argc, char *argv[]) |
| 788 | do_set_format = 1; |
| 789 | info = v4l2_format_by_name(optarg); |
| 790 | if (info == NULL) { |
| 791 | - printf("Unsupported video format '%s'\n", optarg); |
| 792 | + fprintf(stderr, "Unsupported video format '%s'\n", optarg); |
| 793 | return 1; |
| 794 | } |
| 795 | pixelformat = info->fourcc; |
| 796 | @@ -1812,7 +1832,7 @@ int main(int argc, char *argv[]) |
| 797 | case 'r': |
| 798 | ctrl_name = strtol(optarg, &endptr, 0); |
| 799 | if (*endptr != 0) { |
| 800 | - printf("Invalid control name '%s'\n", optarg); |
| 801 | + fprintf(stderr, "Invalid control name '%s'\n", optarg); |
| 802 | return 1; |
| 803 | } |
| 804 | do_get_control = 1; |
| 805 | @@ -1826,12 +1846,12 @@ int main(int argc, char *argv[]) |
| 806 | do_set_format = 1; |
| 807 | width = strtol(optarg, &endptr, 10); |
| 808 | if (*endptr != 'x' || endptr == optarg) { |
| 809 | - printf("Invalid size '%s'\n", optarg); |
| 810 | + fprintf(stderr, "Invalid size '%s'\n", optarg); |
| 811 | return 1; |
| 812 | } |
| 813 | height = strtol(endptr + 1, &endptr, 10); |
| 814 | if (*endptr != 0) { |
| 815 | - printf("Invalid size '%s'\n", optarg); |
| 816 | + fprintf(stderr, "Invalid size '%s'\n", optarg); |
| 817 | return 1; |
| 818 | } |
| 819 | break; |
| 820 | @@ -1839,12 +1859,12 @@ int main(int argc, char *argv[]) |
| 821 | do_set_time_per_frame = 1; |
| 822 | time_per_frame.numerator = strtol(optarg, &endptr, 10); |
| 823 | if (*endptr != '/' || endptr == optarg) { |
| 824 | - printf("Invalid time per frame '%s'\n", optarg); |
| 825 | + fprintf(stderr, "Invalid time per frame '%s'\n", optarg); |
| 826 | return 1; |
| 827 | } |
| 828 | time_per_frame.denominator = strtol(endptr + 1, &endptr, 10); |
| 829 | if (*endptr != 0) { |
| 830 | - printf("Invalid time per frame '%s'\n", optarg); |
| 831 | + fprintf(stderr, "Invalid time per frame '%s'\n", optarg); |
| 832 | return 1; |
| 833 | } |
| 834 | break; |
| 835 | @@ -1854,12 +1874,12 @@ int main(int argc, char *argv[]) |
| 836 | case 'w': |
| 837 | ctrl_name = strtol(optarg, &endptr, 0); |
| 838 | if (*endptr != ' ' || endptr == optarg) { |
| 839 | - printf("Invalid control name '%s'\n", optarg); |
| 840 | + fprintf(stderr, "Invalid control name '%s'\n", optarg); |
| 841 | return 1; |
| 842 | } |
| 843 | ctrl_value = strtol(endptr + 1, &endptr, 0); |
| 844 | if (*endptr != 0) { |
| 845 | - printf("Invalid control value '%s'\n", optarg); |
| 846 | + fprintf(stderr, "Invalid control value '%s'\n", optarg); |
| 847 | return 1; |
| 848 | } |
| 849 | do_set_control = 1; |
| 850 | @@ -1873,16 +1893,16 @@ int main(int argc, char *argv[]) |
| 851 | case OPT_FD: |
| 852 | ret = atoi(optarg); |
| 853 | if (ret < 0) { |
| 854 | - printf("Bad file descriptor %d\n", ret); |
| 855 | + fprintf(stderr, "Bad file descriptor %d\n", ret); |
| 856 | return 1; |
| 857 | } |
| 858 | - printf("Using file descriptor %d\n", ret); |
| 859 | + fprintf(stderr, "Using file descriptor %d\n", ret); |
| 860 | video_set_fd(&dev, ret); |
| 861 | break; |
| 862 | case OPT_FIELD: |
| 863 | field = v4l2_field_from_string(optarg); |
| 864 | if (field == (enum v4l2_field)-1) { |
| 865 | - printf("Invalid field order '%s'\n", optarg); |
| 866 | + fprintf(stderr, "Invalid field order '%s'\n", optarg); |
| 867 | return 1; |
| 868 | } |
| 869 | break; |
| 870 | @@ -1907,22 +1927,25 @@ int main(int argc, char *argv[]) |
| 871 | } else if (!strcmp(optarg, "soe")) { |
| 872 | dev.buffer_output_flags |= V4L2_BUF_FLAG_TSTAMP_SRC_SOE; |
| 873 | } else { |
| 874 | - printf("Invalid timestamp source %s\n", optarg); |
| 875 | + fprintf(stderr, "Invalid timestamp source %s\n", optarg); |
| 876 | return 1; |
| 877 | } |
| 878 | break; |
| 879 | case OPT_USERPTR_OFFSET: |
| 880 | userptr_offset = atoi(optarg); |
| 881 | break; |
| 882 | + case OPT_STDOUT: |
| 883 | + do_stdout = 1; |
| 884 | + break; |
| 885 | default: |
| 886 | - printf("Invalid option -%c\n", c); |
| 887 | - printf("Run %s -h for help.\n", argv[0]); |
| 888 | + fprintf(stderr, "Invalid option -%c\n", c); |
| 889 | + fprintf(stderr, "Run %s -h for help.\n", argv[0]); |
| 890 | return 1; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | if ((fill_mode & BUFFER_FILL_PADDING) && memtype != V4L2_MEMORY_USERPTR) { |
| 895 | - printf("Buffer overrun can only be checked in USERPTR mode.\n"); |
| 896 | + fprintf(stderr, "Buffer overrun can only be checked in USERPTR mode.\n"); |
| 897 | return 1; |
| 898 | } |
| 899 | |
| 900 | @@ -1959,7 +1982,7 @@ int main(int argc, char *argv[]) |
| 901 | ret = get_control(&dev, ctrl_name, |
| 902 | get_control_type(&dev, ctrl_name), &val); |
| 903 | if (ret >= 0) |
| 904 | - printf("Control 0x%08x value %" PRId64 "\n", ctrl_name, val); |
| 905 | + fprintf(stderr, "Control 0x%08x value %" PRId64 "\n", ctrl_name, val); |
| 906 | } |
| 907 | |
| 908 | if (do_set_control) |
| 909 | @@ -1970,7 +1993,7 @@ int main(int argc, char *argv[]) |
| 910 | video_list_controls(&dev); |
| 911 | |
| 912 | if (do_enum_formats) { |
| 913 | - printf("- Available formats:\n"); |
| 914 | + fprintf(stderr, "- Available formats:\n"); |
| 915 | video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
| 916 | video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); |
| 917 | video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 918 | @@ -1979,14 +2002,14 @@ int main(int argc, char *argv[]) |
| 919 | } |
| 920 | |
| 921 | if (do_enum_inputs) { |
| 922 | - printf("- Available inputs:\n"); |
| 923 | + fprintf(stderr, "- Available inputs:\n"); |
| 924 | video_enum_inputs(&dev); |
| 925 | } |
| 926 | |
| 927 | if (do_set_input) { |
| 928 | video_set_input(&dev, input); |
| 929 | ret = video_get_input(&dev); |
| 930 | - printf("Input %d selected\n", ret); |
| 931 | + fprintf(stderr, "Input %d selected\n", ret); |
| 932 | } |
| 933 | |
| 934 | /* Set the video format. */ |
| 935 | @@ -2028,7 +2051,7 @@ int main(int argc, char *argv[]) |
| 936 | } |
| 937 | |
| 938 | if (do_pause) { |
| 939 | - printf("Press enter to start capture\n"); |
| 940 | + fprintf(stderr, "Press enter to start capture\n"); |
| 941 | getchar(); |
| 942 | } |
| 943 | |
| 944 | @@ -2037,12 +2060,12 @@ int main(int argc, char *argv[]) |
| 945 | sched.sched_priority = rt_priority; |
| 946 | ret = sched_setscheduler(0, SCHED_RR, &sched); |
| 947 | if (ret < 0) |
| 948 | - printf("Failed to select RR scheduler: %s (%d)\n", |
| 949 | + fprintf(stderr, "Failed to select RR scheduler: %s (%d)\n", |
| 950 | strerror(errno), errno); |
| 951 | } |
| 952 | |
| 953 | if (video_do_capture(&dev, nframes, skip, delay, filename, |
| 954 | - do_requeue_last, fill_mode) < 0) { |
| 955 | + do_requeue_last, fill_mode, do_stdout) < 0) { |
| 956 | video_close(&dev); |
| 957 | return 1; |
| 958 | } |
| 959 | -- |
| 960 | 1.7.9.5 |
| 961 | |