diff mbox series

[FFmpeg-devel,2/4] avcodec/av1_frame_merge_bsf: Use separate contexts for reading/writing

Message ID 20200708012949.13522-2-jamrial@gmail.com
State Accepted
Commit 2493944e31a48e42fab0e78207d76ddd7231ed89
Headers show
Series [FFmpeg-devel,1/4] avcodec/av1_metadata_bsf: Use separate contexts for reading/writing
Related show

Checks

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

Commit Message

James Almer July 8, 2020, 1:29 a.m. UTC
Based on code from 235a5734e0

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/av1_frame_merge_bsf.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/av1_frame_merge_bsf.c b/libavcodec/av1_frame_merge_bsf.c
index baea5596d7..fce5bdb67e 100644
--- a/libavcodec/av1_frame_merge_bsf.c
+++ b/libavcodec/av1_frame_merge_bsf.c
@@ -24,7 +24,8 @@ 
 #include "cbs_av1.h"
 
 typedef struct AV1FMergeContext {
-    CodedBitstreamContext *cbc;
+    CodedBitstreamContext *input;
+    CodedBitstreamContext *output;
     CodedBitstreamFragment frag[2];
     AVPacket *pkt, *in;
     int idx;
@@ -54,7 +55,7 @@  static int av1_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
         return err;
     }
 
-    err = ff_cbs_read_packet(ctx->cbc, frag, in);
+    err = ff_cbs_read_packet(ctx->input, frag, in);
     if (err < 0) {
         av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
         goto fail;
@@ -82,7 +83,7 @@  static int av1_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
 
     if (tu->nb_units > 0 && frag->units[0].type == AV1_OBU_TEMPORAL_DELIMITER) {
 eof:
-        err = ff_cbs_write_packet(ctx->cbc, buffer_pkt, tu);
+        err = ff_cbs_write_packet(ctx->output, buffer_pkt, tu);
         if (err < 0) {
             av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
             goto fail;
@@ -120,13 +121,18 @@  fail:
 static int av1_frame_merge_init(AVBSFContext *bsf)
 {
     AV1FMergeContext *ctx = bsf->priv_data;
+    int err;
 
     ctx->in  = av_packet_alloc();
     ctx->pkt = av_packet_alloc();
     if (!ctx->in || !ctx->pkt)
         return AVERROR(ENOMEM);
 
-    return ff_cbs_init(&ctx->cbc, AV_CODEC_ID_AV1, bsf);
+    err =  ff_cbs_init(&ctx->input, AV_CODEC_ID_AV1, bsf);
+    if (err < 0)
+        return err;
+
+    return ff_cbs_init(&ctx->output, AV_CODEC_ID_AV1, bsf);
 }
 
 static void av1_frame_merge_close(AVBSFContext *bsf)
@@ -137,7 +143,8 @@  static void av1_frame_merge_close(AVBSFContext *bsf)
     ff_cbs_fragment_free(&ctx->frag[1]);
     av_packet_free(&ctx->in);
     av_packet_free(&ctx->pkt);
-    ff_cbs_close(&ctx->cbc);
+    ff_cbs_close(&ctx->input);
+    ff_cbs_close(&ctx->output);
 }
 
 static const enum AVCodecID av1_frame_merge_codec_ids[] = {