MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / device_try_init

Function device_try_init

libavdevice/v4l2.c:816–867  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

814}
815
816static int device_try_init(AVFormatContext *ctx,
817 enum AVPixelFormat pix_fmt,
818 int *width,
819 int *height,
820 uint32_t *desired_format,
821 enum AVCodecID *codec_id)
822{
823 int ret, i;
824
825 *desired_format = ff_fmt_ff2v4l(pix_fmt, ctx->video_codec_id);
826
827 if (*desired_format) {
828 ret = device_init(ctx, width, height, *desired_format);
829 if (ret < 0) {
830 *desired_format = 0;
831 if (ret != AVERROR(EINVAL))
832 return ret;
833 }
834 }
835
836 if (!*desired_format) {
837 for (i = 0; ff_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) {
838 if (ctx->video_codec_id == AV_CODEC_ID_NONE ||
839 ff_fmt_conversion_table[i].codec_id == ctx->video_codec_id) {
840 av_log(ctx, AV_LOG_DEBUG, "Trying to set codec:%s pix_fmt:%s\n",
841 avcodec_get_name(ff_fmt_conversion_table[i].codec_id),
842 (char *)av_x_if_null(av_get_pix_fmt_name(ff_fmt_conversion_table[i].ff_fmt), "none"));
843
844 *desired_format = ff_fmt_conversion_table[i].v4l2_fmt;
845 ret = device_init(ctx, width, height, *desired_format);
846 if (ret >= 0)
847 break;
848 else if (ret != AVERROR(EINVAL))
849 return ret;
850 *desired_format = 0;
851 }
852 }
853
854 if (*desired_format == 0) {
855 av_log(ctx, AV_LOG_ERROR, "Cannot find a proper format for "
856 "codec '%s' (id %d), pixel format '%s' (id %d)\n",
857 avcodec_get_name(ctx->video_codec_id), ctx->video_codec_id,
858 (char *)av_x_if_null(av_get_pix_fmt_name(pix_fmt), "none"), pix_fmt);
859 ret = AVERROR(EINVAL);
860 }
861 }
862
863 *codec_id = ff_fmt_v4l2codec(*desired_format);
864 if (*codec_id == AV_CODEC_ID_NONE)
865 av_assert0(ret == AVERROR(EINVAL));
866 return ret;
867}
868
869static int v4l2_read_probe(const AVProbeData *p)
870{

Callers 1

v4l2_read_headerFunction · 0.85

Calls 7

ff_fmt_ff2v4lFunction · 0.85
device_initFunction · 0.85
av_logFunction · 0.85
avcodec_get_nameFunction · 0.85
av_x_if_nullFunction · 0.85
av_get_pix_fmt_nameFunction · 0.85
ff_fmt_v4l2codecFunction · 0.85

Tested by

no test coverage detected