diff mbox series

[FFmpeg-devel,14/18] lavf/dv: forward errors from avformat_new_stream()

Message ID 20220824084318.333-14-anton@khirnov.net
State Accepted
Commit b2e1d1443c12bb4cab54137154ae395b2d11c744
Headers show
Series [FFmpeg-devel,01/18] tests/fate/mov: add a test for dv audio demuxed through dv demuxer | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed

Commit Message

Anton Khirnov Aug. 24, 2022, 8:43 a.m. UTC
---
 libavformat/dv.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/dv.c b/libavformat/dv.c
index c888111789..24d6897da5 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -268,11 +268,13 @@  static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame)
         ach = 2;
 
     /* Dynamic handling of the audio streams in DV */
+    c->ach = 0;
     for (i = 0; i < ach; i++) {
         if (!c->ast[i]) {
             c->ast[i] = avformat_new_stream(c->fctx, NULL);
             if (!c->ast[i])
-                break;
+                return AVERROR(ENOMEM);
+
             avpriv_set_pts_info(c->ast[i], 64, c->sys->time_base.num, c->sys->time_base.den);
             c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
             c->ast[i]->codecpar->codec_id   = AV_CODEC_ID_PCM_S16LE;
@@ -290,7 +292,7 @@  static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame)
         c->ast[i]->codecpar->bit_rate       = 2 * dv_audio_frequency[freq] * 16;
         c->ast[i]->start_time            = 0;
     }
-    c->ach = i;
+    c->ach = ach;
 
     return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
 }
@@ -410,6 +412,9 @@  int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
     /* Queueing audio packet */
     /* FIXME: in case of no audio/bad audio we have to do something */
     size = dv_extract_audio_info(c, buf);
+    if (size < 0)
+        return size;
+
     for (i = 0; i < c->ach; i++) {
         c->audio_pkt[i].pos  = pos;
         c->audio_pkt[i].size = size;