[FFmpeg-cvslog] avformat/dvenc: check the format before vst and ast[i] are initialized

Limin Wang git at videolan.org
Thu Nov 19 16:44:25 EET 2020


ffmpeg | branch: master | Limin Wang <lance.lmwang at gmail.com> | Thu Aug 27 23:40:02 2020 +0800| [3871326910ee86e87114fd3e5d1b003ac14b195e] | committer: Limin Wang

avformat/dvenc: check the format before vst and ast[i] are initialized

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3871326910ee86e87114fd3e5d1b003ac14b195e
---

 libavformat/dvenc.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 1c386733b2..6c0d40f819 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -311,10 +311,20 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
         switch (st->codecpar->codec_type) {
         case AVMEDIA_TYPE_VIDEO:
             if (vst) return NULL;
+            if (st->codecpar->codec_id != AV_CODEC_ID_DVVIDEO)
+                goto bail_out;
             vst = st;
             break;
         case AVMEDIA_TYPE_AUDIO:
             if (c->n_ast > 1) return NULL;
+            /* Some checks -- DV format is very picky about its incoming streams */
+            if(st->codecpar->codec_id    != AV_CODEC_ID_PCM_S16LE ||
+               st->codecpar->channels    != 2)
+                goto bail_out;
+            if (st->codecpar->sample_rate != 48000 &&
+                st->codecpar->sample_rate != 44100 &&
+                st->codecpar->sample_rate != 32000    )
+                goto bail_out;
             c->ast[c->n_ast++] = st;
             break;
         default:
@@ -322,20 +332,9 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
         }
     }
 
-    /* Some checks -- DV format is very picky about its incoming streams */
-    if (!vst || vst->codecpar->codec_id != AV_CODEC_ID_DVVIDEO)
+    if (!vst)
         goto bail_out;
-    for (i=0; i<c->n_ast; i++) {
-        if (c->ast[i]) {
-            if(c->ast[i]->codecpar->codec_id    != AV_CODEC_ID_PCM_S16LE ||
-               c->ast[i]->codecpar->channels    != 2)
-                goto bail_out;
-            if (c->ast[i]->codecpar->sample_rate != 48000 &&
-                c->ast[i]->codecpar->sample_rate != 44100 &&
-                c->ast[i]->codecpar->sample_rate != 32000    )
-                goto bail_out;
-        }
-    }
+
     c->sys = av_dv_codec_profile2(vst->codecpar->width, vst->codecpar->height,
                                   vst->codecpar->format, vst->time_base);
     if (!c->sys)



More information about the ffmpeg-cvslog mailing list