]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/v4l2_m2m.c
avcodec/v4l2_m2m: fix av_pix_fmt changing when multiple /dev/video* devices are probed
[ffmpeg] / libavcodec / v4l2_m2m.c
index 82ff847cf70b8db2ab1105ba2764c331bf3a6c48..827662b9a53745133c6eb984c39634a5d4c0a0b5 100644 (file)
@@ -60,7 +60,7 @@ static inline int v4l2_mplane_video(struct v4l2_capability *cap)
     return 0;
 }
 
-static int v4l2_prepare_contexts(V4L2m2mContext* s)
+static int v4l2_prepare_contexts(V4L2m2mContext* s, int probe)
 {
     struct v4l2_capability cap;
     int ret;
@@ -76,9 +76,10 @@ static int v4l2_prepare_contexts(V4L2m2mContext* s)
     if (ret < 0)
         return ret;
 
-    av_log(s->avctx, AV_LOG_INFO, "driver '%s' on card '%s' in %s mode\n", cap.driver, cap.card,
-                                   v4l2_mplane_video(&cap) ? "mplane" :
-                                   v4l2_splane_video(&cap) ? "splane" : "unknown");
+    av_log(s->avctx, probe ? AV_LOG_DEBUG : AV_LOG_INFO,
+                     "driver '%s' on card '%s' in %s mode\n", cap.driver, cap.card,
+                     v4l2_mplane_video(&cap) ? "mplane" :
+                     v4l2_splane_video(&cap) ? "splane" : "unknown");
 
     if (v4l2_mplane_video(&cap)) {
         s->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
@@ -103,17 +104,17 @@ static int v4l2_probe_driver(V4L2m2mContext* s)
     if (s->fd < 0)
         return AVERROR(errno);
 
-    ret = v4l2_prepare_contexts(s);
+    ret = v4l2_prepare_contexts(s, 1);
     if (ret < 0)
         goto done;
 
-    ret = ff_v4l2_context_get_format(&s->output);
+    ret = ff_v4l2_context_get_format(&s->output, 1);
     if (ret) {
         av_log(s->avctx, AV_LOG_DEBUG, "v4l2 output format not supported\n");
         goto done;
     }
 
-    ret = ff_v4l2_context_get_format(&s->capture);
+    ret = ff_v4l2_context_get_format(&s->capture, 1);
     if (ret) {
         av_log(s->avctx, AV_LOG_DEBUG, "v4l2 capture format not supported\n");
         goto done;
@@ -140,7 +141,7 @@ static int v4l2_configure_contexts(V4L2m2mContext* s)
     if (s->fd < 0)
         return AVERROR(errno);
 
-    ret = v4l2_prepare_contexts(s);
+    ret = v4l2_prepare_contexts(s, 0);
     if (ret < 0)
         goto error;
 
@@ -221,7 +222,7 @@ int ff_v4l2_m2m_codec_reinit(V4L2m2mContext* s)
     ff_v4l2_context_release(&s->capture);
 
     /* 3. get the new capture format */
-    ret = ff_v4l2_context_get_format(&s->capture);
+    ret = ff_v4l2_context_get_format(&s->capture, 0);
     if (ret) {
         av_log(s->avctx, AV_LOG_ERROR, "query the new capture format\n");
         return ret;
@@ -254,13 +255,13 @@ int ff_v4l2_m2m_codec_full_reinit(V4L2m2mContext *s)
 
     ret = ff_v4l2_context_set_status(&s->output, VIDIOC_STREAMOFF);
     if (ret) {
-        av_log(s->avctx, AV_LOG_ERROR, "output VIDIOC_STREAMOFF\n");
+        av_log(log_ctx, AV_LOG_ERROR, "output VIDIOC_STREAMOFF\n");
         goto error;
     }
 
     ret = ff_v4l2_context_set_status(&s->capture, VIDIOC_STREAMOFF);
     if (ret) {
-            av_log(s->avctx, AV_LOG_ERROR, "capture VIDIOC_STREAMOFF\n");
+            av_log(log_ctx, AV_LOG_ERROR, "capture VIDIOC_STREAMOFF\n");
             goto error;
     }
 
@@ -272,13 +273,13 @@ int ff_v4l2_m2m_codec_full_reinit(V4L2m2mContext *s)
     s->draining = 0;
     s->reinit = 0;
 
-    ret = ff_v4l2_context_get_format(&s->output);
+    ret = ff_v4l2_context_get_format(&s->output, 0);
     if (ret) {
         av_log(log_ctx, AV_LOG_DEBUG, "v4l2 output format not supported\n");
         goto error;
     }
 
-    ret = ff_v4l2_context_get_format(&s->capture);
+    ret = ff_v4l2_context_get_format(&s->capture, 0);
     if (ret) {
         av_log(log_ctx, AV_LOG_DEBUG, "v4l2 capture format not supported\n");
         goto error;
@@ -337,7 +338,7 @@ int ff_v4l2_m2m_codec_end(AVCodecContext *avctx)
 
     ret = ff_v4l2_context_set_status(&s->output, VIDIOC_STREAMOFF);
     if (ret)
-            av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", s->output.name);
+        av_log(avctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", s->output.name);
 
     ret = ff_v4l2_context_set_status(&s->capture, VIDIOC_STREAMOFF);
     if (ret)