diff mbox series

[FFmpeg-devel,2/2] avcodec/s302m: support multiple ST 302 frames per AVPacket

Message ID 1594397247-169433-2-git-send-email-knneth@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avcodec/s302m: document ST 302 format
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

knneth@gmail.com July 10, 2020, 4:07 p.m. UTC
From: Kenneth Klette Jonassen <kenneth@bridgetech.tv>

Enable s302m decoder to process AVPacket buffers containing multiple
ST 302 frames.

Validate that frame_size is within packet bounds. Change return value to
reflect only number of processed bytes instead of entire packet.

This patch allows us to decode the entire fate sample, including the last PES
packet containing two ST 302 frames. Update fate reference to match.

Signed-off-by: Kenneth Klette Jonassen <kenneth@bridgetech.tv>
---
 libavcodec/s302m.c     | 14 +++++++-------
 tests/ref/acodec/s302m |  4 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index 1e49e9e..e7b48c0 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -71,7 +71,7 @@  static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf,
     channels   = ((h >> 14) & 0x0003) * 2 +  2;
     bits       = ((h >>  4) & 0x0003) * 4 + 16;
 
-    if (AES3_HEADER_LEN + frame_size != buf_size || bits > 24) {
+    if (AES3_HEADER_LEN + frame_size > buf_size || bits > 24) {
         av_log(avctx, AV_LOG_ERROR, "frame has invalid header\n");
         return AVERROR_INVALIDDATA;
     }
@@ -107,16 +107,16 @@  static int s302m_decode_frame(AVCodecContext *avctx, void *data,
     S302Context *s = avctx->priv_data;
     AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
-    int buf_size       = avpkt->size;
     int block_size, ret;
+    int buf_size;
     int i;
     int non_pcm_data_type = -1;
 
-    int frame_size = s302m_parse_frame_header(avctx, buf, buf_size);
+    int frame_size = s302m_parse_frame_header(avctx, buf, avpkt->size);
     if (frame_size < 0)
         return frame_size;
 
-    buf_size -= AES3_HEADER_LEN;
+    buf_size  = frame_size;
     buf      += AES3_HEADER_LEN;
 
     /* get output buffer */
@@ -202,7 +202,7 @@  static int s302m_decode_frame(AVCodecContext *avctx, void *data,
             return AVERROR_PATCHWELCOME;
         }
         if (s->non_pcm_mode & 1) {
-            return avpkt->size;
+            return AES3_HEADER_LEN + frame_size;
         }
     }
 
@@ -210,7 +210,7 @@  static int s302m_decode_frame(AVCodecContext *avctx, void *data,
 
     *got_frame_ptr = 1;
 
-    return avpkt->size;
+    return AES3_HEADER_LEN + frame_size;
 }
 
 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_DECODING_PARAM
@@ -237,6 +237,6 @@  AVCodec ff_s302m_decoder = {
     .id             = AV_CODEC_ID_S302M,
     .priv_data_size = sizeof(S302Context),
     .decode         = s302m_decode_frame,
-    .capabilities   = AV_CODEC_CAP_DR1,
+    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SUBFRAMES,
     .priv_class     = &s302m_class,
 };
diff --git a/tests/ref/acodec/s302m b/tests/ref/acodec/s302m
index 2919ed6..0c7345a 100644
--- a/tests/ref/acodec/s302m
+++ b/tests/ref/acodec/s302m
@@ -1,4 +1,4 @@ 
 0bf5457fd41a22fc5cdd99ae5ad4e273 *tests/data/fate/acodec-s302m.mpegts
 1527688 tests/data/fate/acodec-s302m.mpegts
-31f25a0020fd9017de9c3c608316854b *tests/data/fate/acodec-s302m.out.wav
-stddev:  986.94 PSNR: 36.44 MAXDIFF:18571 bytes:  1058400/  1056708
+abc1b26737c8103c3f122539d239f6be *tests/data/fate/acodec-s302m.out.wav
+stddev:  986.15 PSNR: 36.45 MAXDIFF:18571 bytes:  1058400/  1058400