diff mbox series

[FFmpeg-devel,14/25] avformat/matroskaenc: Redo reformatting AV1

Message ID AM7PR03MB6660E6D86360ADB4600D92DF8F569@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 83186275588c6482da5d4abb827914252736655a
Headers show
Series [FFmpeg-devel,01/25] avformat/matroskaenc: Fix potential overflow | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 16, 2022, 11:03 p.m. UTC
This avoids allocations+copies in all cases, not only those
in which the desired OBUs are contiguous in the input buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
ff_av1_filter_obus_buf() now has only one user left: movenc.c
Maybe movenc.c should be modified accordingly to remove it?

 libavformat/matroskaenc.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 08d2d338a6..d275d6cd6c 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2389,6 +2389,16 @@  static int mkv_reformat_wavpack(MatroskaMuxContext *mkv, AVIOContext *pb,
 }
 #endif
 
+static int mkv_reformat_av1(MatroskaMuxContext *mkv, AVIOContext *pb,
+                            const AVPacket *pkt, int *size)
+{
+    int ret = ff_av1_filter_obus(pb, pkt->data, pkt->size);
+    if (ret < 0)
+        return ret;
+    *size = ret;
+    return 0;
+}
+
 static int mkv_write_block(AVFormatContext *s, AVIOContext *pb,
                            uint32_t blockid, const AVPacket *pkt, int keyframe)
 {
@@ -2426,9 +2436,7 @@  static int mkv_write_block(AVFormatContext *s, AVIOContext *pb,
         err = ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL);
     } else
 #endif
-           if (par->codec_id == AV_CODEC_ID_AV1) {
-        err = ff_av1_filter_obus_buf(pkt->data, &data, &size, &offset);
-    } else if (track->reformat) {
+    if (track->reformat) {
         err = track->reformat(mkv, NULL, pkt, &size);
     } else
         data = pkt->data;
@@ -3106,6 +3114,9 @@  static int mkv_init(struct AVFormatContext *s)
             track->reformat = mkv_reformat_wavpack;
             break;
 #endif
+        case AV_CODEC_ID_AV1:
+            track->reformat = mkv_reformat_av1;
+            break;
         }
 
         if (s->flags & AVFMT_FLAG_BITEXACT) {