[FFmpeg-devel,v2,10/11] cbs_vp9: Use table-based alloc/free

Submitted by Mark Thompson on May 20, 2019, 11:02 p.m.

Details

Message ID 20190520230224.19221-10-sw@jkqxz.net
State New
Headers show

Commit Message

Mark Thompson May 20, 2019, 11:02 p.m.
---
 libavcodec/cbs_vp9.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
index 0b5f137ed8..71c1b38032 100644
--- a/libavcodec/cbs_vp9.c
+++ b/libavcodec/cbs_vp9.c
@@ -474,13 +474,6 @@  static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx,
     return 0;
 }
 
-static void cbs_vp9_free_frame(void *unit, uint8_t *content)
-{
-    VP9RawFrame *frame = (VP9RawFrame*)content;
-    av_buffer_unref(&frame->data_ref);
-    av_freep(&frame);
-}
-
 static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
                              CodedBitstreamUnit *unit)
 {
@@ -492,8 +485,7 @@  static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
     if (err < 0)
         return err;
 
-    err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*frame),
-                                    &cbs_vp9_free_frame);
+    err = ff_cbs_alloc_unit_content2(ctx, unit);
     if (err < 0)
         return err;
     frame = unit->content;
@@ -678,11 +670,19 @@  static void cbs_vp9_close(CodedBitstreamContext *ctx)
     av_freep(&priv->write_buffer);
 }
 
+static const CodedBitstreamUnitTypeDescriptor cbs_vp9_unit_types[] = {
+    CBS_UNIT_TYPE_INTERNAL_REFS(0, VP9RawFrame, 1,
+                                { offsetof(VP9RawFrame, data) }),
+    CBS_UNIT_TYPE_END_OF_LIST
+};
+
 const CodedBitstreamType ff_cbs_type_vp9 = {
     .codec_id          = AV_CODEC_ID_VP9,
 
     .priv_data_size    = sizeof(CodedBitstreamVP9Context),
 
+    .unit_types        = cbs_vp9_unit_types,
+
     .split_fragment    = &cbs_vp9_split_fragment,
     .read_unit         = &cbs_vp9_read_unit,
     .write_unit        = &cbs_vp9_write_unit,