Lines Matching refs:ctx

124 static int device_open(AVFormatContext *ctx, const char* device_path)
126 struct video_data *s = ctx->priv_data;
146 av_log(ctx, AV_LOG_ERROR, "libavdevice is not built with libv4l2 support.\n");
161 if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
168 av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s: %s\n",
175 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n",
180 av_log(ctx, AV_LOG_VERBOSE, "fd:%d capabilities:%x\n",
184 av_log(ctx, AV_LOG_ERROR, "Not a video capture device.\n");
190 av_log(ctx, AV_LOG_ERROR,
203 static int device_init(AVFormatContext *ctx, int *width, int *height,
206 struct video_data *s = ctx->priv_data;
221 av_log(ctx, AV_LOG_INFO,
229 av_log(ctx, AV_LOG_DEBUG,
237 av_log(ctx, AV_LOG_DEBUG,
260 static void list_framesizes(AVFormatContext *ctx, uint32_t pixelformat)
262 const struct video_data *s = ctx->priv_data;
268 av_log(ctx, AV_LOG_INFO, " %ux%u",
273 av_log(ctx, AV_LOG_INFO, " {%u-%u, %u}x{%u-%u, %u}",
286 static void list_formats(AVFormatContext *ctx, int type)
288 const struct video_data *s = ctx->priv_data;
300 av_log(ctx, AV_LOG_INFO, "Raw : %11s : %20s :",
306 av_log(ctx, AV_LOG_INFO, "Compressed: %11s : %20s :",
315 av_log(ctx, AV_LOG_INFO, " Emulated :");
318 list_framesizes(ctx, vfd.pixelformat);
320 av_log(ctx, AV_LOG_INFO, "\n");
324 static void list_standards(AVFormatContext *ctx)
327 struct video_data *s = ctx->priv_data;
339 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMSTD): %s\n", av_err2str(ret));
343 av_log(ctx, AV_LOG_INFO, "%2d, %16"PRIx64", %s\n",
348 static int mmap_init(AVFormatContext *ctx)
351 struct video_data *s = ctx->priv_data;
360 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS): %s\n", av_err2str(res));
365 av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n");
371 av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n");
376 av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n");
389 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF): %s\n", av_err2str(res));
395 av_log(ctx, AV_LOG_ERROR,
406 av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", av_err2str(res));
449 static int init_convert_timestamp(AVFormatContext *ctx, int64_t ts)
451 struct video_data *s = ctx->priv_data;
457 av_log(ctx, AV_LOG_INFO, "Detected absolute timestamps\n");
462 if (ctx->streams[0]->avg_frame_rate.num) {
467 int64_t period = av_rescale_q(1, tb, ctx->streams[0]->avg_frame_rate);
468 av_log(ctx, AV_LOG_INFO, "Detected monotonic timestamps, converting\n");
478 av_log(ctx, AV_LOG_ERROR, "Unknown timestamps\n");
482 static int convert_timestamp(AVFormatContext *ctx, int64_t *ts)
484 struct video_data *s = ctx->priv_data;
487 int r = init_convert_timestamp(ctx, *ts);
503 static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
505 struct video_data *s = ctx->priv_data;
522 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n",
530 av_log(ctx, AV_LOG_ERROR, "Invalid buffer index received.\n");
539 av_log(ctx, AV_LOG_WARNING,
548 if (ctx->video_codec_id == AV_CODEC_ID_CPIA)
552 av_log(ctx, AV_LOG_WARNING,
564 av_log(ctx, AV_LOG_ERROR, "Error allocating a packet.\n");
586 av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n");
597 av_log(ctx, AV_LOG_ERROR, "Failed to create a buffer\n");
604 convert_timestamp(ctx, &pkt->pts);
609 static int mmap_start(AVFormatContext *ctx)
611 struct video_data *s = ctx->priv_data;
624 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n",
634 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n",
659 static int v4l2_set_parameters(AVFormatContext *ctx)
661 struct video_data *s = ctx->priv_data;
670 av_log(ctx, AV_LOG_ERROR, "Could not parse framerate '%s'.\n",
678 av_log(ctx, AV_LOG_DEBUG, "Setting standard: %s\n", s->standard);
690 av_log(ctx, AV_LOG_ERROR, "Unknown or unsupported standard '%s'\n", s->standard);
696 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_S_STD): %s\n", av_err2str(ret));
700 av_log(ctx, AV_LOG_WARNING,
720 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMSTD): %s\n", av_err2str(ret));
724 av_log(ctx, AV_LOG_DEBUG,
737 av_log(ctx, AV_LOG_WARNING, "ioctl(VIDIOC_G_PARM): %s\n", av_err2str(ret));
742 av_log(ctx, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
749 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_S_PARM): %s\n",
756 av_log(ctx, AV_LOG_INFO,
763 av_log(ctx, AV_LOG_WARNING,
768 ctx->streams[0]->avg_frame_rate.num = tpf->denominator;
769 ctx->streams[0]->avg_frame_rate.den = tpf->numerator;
770 ctx->streams[0]->r_frame_rate = ctx->streams[0]->avg_frame_rate;
772 av_log(ctx, AV_LOG_WARNING, "Time per frame unknown\n");
777 static int device_try_init(AVFormatContext *ctx,
786 *desired_format = ff_fmt_ff2v4l(pix_fmt, ctx->video_codec_id);
789 ret = device_init(ctx, width, height, *desired_format);
799 if (ctx->video_codec_id == AV_CODEC_ID_NONE ||
800 ff_fmt_conversion_table[i].codec_id == ctx->video_codec_id) {
801 av_log(ctx, AV_LOG_DEBUG, "Trying to set codec:%s pix_fmt:%s\n",
806 ret = device_init(ctx, width, height, *desired_format);
816 av_log(ctx, AV_LOG_ERROR, "Cannot find a proper format for "
818 avcodec_get_name(ctx->video_codec_id), ctx->video_codec_id,
837 static int v4l2_read_header(AVFormatContext *ctx)
839 struct video_data *s = ctx->priv_data;
847 st = avformat_new_stream(ctx, NULL);
858 s->fd = device_open(ctx, ctx->url);
864 av_log(ctx, AV_LOG_DEBUG, "Selecting input_channel: %d\n", s->channel);
867 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_S_INPUT): %s\n", av_err2str(res));
874 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_G_INPUT): %s\n", av_err2str(res));
883 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMINPUT): %s\n", av_err2str(res));
887 av_log(ctx, AV_LOG_DEBUG, "Current input_channel: %d, input_name: %s, input_std: %"PRIx64"\n",
891 list_formats(ctx, s->list_format);
897 list_standards(ctx);
908 ctx->video_codec_id = desc->id;
913 av_log(ctx, AV_LOG_ERROR, "No such input format: %s.\n",
924 av_log(ctx, AV_LOG_VERBOSE,
928 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n",
935 av_log(ctx, AV_LOG_VERBOSE,
939 res = device_try_init(ctx, pix_fmt, &s->width, &s->height, &desired_format, &codec_id);
947 if (codec_id != AV_CODEC_ID_NONE && ctx->video_codec_id == AV_CODEC_ID_NONE)
948 ctx->video_codec_id = codec_id;
950 if ((res = av_image_check_size(s->width, s->height, 0, ctx)) < 0)
955 if ((res = v4l2_set_parameters(ctx)) < 0)
963 if ((res = mmap_init(ctx)) ||
964 (res = mmap_start(ctx)) < 0)
993 static int v4l2_read_packet(AVFormatContext *ctx, AVPacket *pkt)
997 if ((res = mmap_read_frame(ctx, pkt)) < 0) {
1004 static int v4l2_read_close(AVFormatContext *ctx)
1006 struct video_data *s = ctx->priv_data;
1009 av_log(ctx, AV_LOG_WARNING, "Some buffers are still owned by the caller on "
1026 static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_list)
1028 struct video_data *s = ctx->priv_data;
1039 av_log(ctx, AV_LOG_ERROR, "Couldn't open the directory: %s\n", av_err2str(ret));
1053 av_log(ctx, AV_LOG_ERROR, "Device name too long.\n");
1058 if ((fd = device_open(ctx, device_name)) < 0)
1063 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", av_err2str(ret));