Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
f33dec29 by Alexandre Janniaux at 2023-01-26T21:16:07+00:00
mux: extradata: add missing priv assignment

The ->priv assignment was only allocated by calloc.

- - - - -
8b79ab60 by Alexandre Janniaux at 2023-01-26T21:16:07+00:00
mux: extradata: use early return to deindent

- - - - -
b1e89425 by Alexandre Janniaux at 2023-01-26T21:16:07+00:00
mux: extradata: free p_extra in deinit callback

Ensure a deinit callback is set and use it to free the p_extra value in
the current extradata_builder implementations.

In particular, p_extra might be allocated from another object and we
would want to *not* free it, and free the other object instead.

- - - - -
43d04253 by Alexandre Janniaux at 2023-01-26T21:16:07+00:00
mux: extradata: pass vlc_object_t during creation

A VLC object is currently needed for parsers like hxxx_helper.

- - - - -
b30232a0 by Alexandre Janniaux at 2023-01-26T21:16:07+00:00
mux: extradata: add support for H264 and HEVC

Use hxxx_helper to extract the SPS/PPS/VPS payload from the stream and
report it when it has been found.

It adds support for late-signalling of h264 and hevc codec specific data
to the mp4 mux, after pf_add has been called, which is needed for some
asynchronous encoders like VideoToolbox and MediaCodec that won't report
the format until they can also output the first I-frame, which means
after encoder_t::ops::encode_video has been called at least once.

- - - - -


4 changed files:

- modules/mux/Makefile.am
- modules/mux/extradata.c
- modules/mux/extradata.h
- modules/mux/mp4/mp4.c


Changes:

=====================================
modules/mux/Makefile.am
=====================================
@@ -1,7 +1,9 @@
 muxdir = $(pluginsdir)/mux
 
 extradata_builder_SOURCES = mux/extradata.c mux/extradata.h \
-                            packetizer/av1_obu.c
+                            packetizer/av1_obu.c \
+                            codec/hxxx_helper.c \
+                            codec/hxxx_helper.h
 
 libmux_dummy_plugin_la_SOURCES = mux/dummy.c
 


=====================================
modules/mux/extradata.c
=====================================
@@ -27,6 +27,7 @@
 #include "extradata.h"
 #include "../packetizer/av1_obu.h"
 #include "../packetizer/a52.h"
+#include "../codec/hxxx_helper.h"
 
 struct mux_extradata_builder_cb
 {
@@ -38,12 +39,18 @@ struct mux_extradata_builder_cb
 struct mux_extradata_builder_t
 {
     struct mux_extradata_builder_cb cb;
+    vlc_object_t *obj;
     void *priv;
     uint8_t *p_extra;
     size_t i_extra;
     vlc_fourcc_t fcc;
 };
 
+static void generic_free_extra_Deinit(mux_extradata_builder_t *m)
+{
+    free(m->p_extra);
+}
+
 static void ac3_extradata_builder_Feed(mux_extradata_builder_t *m,
                                        const uint8_t *p_data, size_t i_data)
 {
@@ -76,7 +83,7 @@ const struct mux_extradata_builder_cb ac3_cb =
 {
     NULL,
     ac3_extradata_builder_Feed,
-    NULL,
+    generic_free_extra_Deinit,
 };
 
 static void eac3_extradata_builder_Feed(mux_extradata_builder_t *m,
@@ -120,7 +127,7 @@ const struct mux_extradata_builder_cb eac3_cb =
 {
     NULL,
     eac3_extradata_builder_Feed,
-    NULL,
+    generic_free_extra_Deinit,
 };
 
 static void av1_extradata_builder_Feed(mux_extradata_builder_t *m,
@@ -152,14 +159,47 @@ const struct mux_extradata_builder_cb av1_cb =
 {
     NULL,
     av1_extradata_builder_Feed,
+    generic_free_extra_Deinit,
+};
+
+static void hxxx_extradata_builder_Feed(mux_extradata_builder_t *m,
+                                        const uint8_t *data, size_t size)
+{
+    if (m->i_extra)
+        return;
+
+    struct hxxx_helper hh;
+    hxxx_helper_init(&hh, m->obj, m->fcc, 0, 0);
+
+    int ret = hxxx_helper_process_buffer(&hh, data, size);
+    (void)ret;
+
+    if (hxxx_helper_has_config(&hh) && m->i_extra == 0)
+    {
+        assert(m->priv == NULL);
+        block_t *config = hxxx_helper_get_extradata_block(&hh);
+        m->i_extra = config->i_buffer;
+        m->p_extra = config->p_buffer;
+        m->priv = config;
+    }
+}
+
+static void hxxx_extradata_builder_Deinit(mux_extradata_builder_t *m)
+{
+    if (m->priv)
+        block_Release(m->priv);
+}
+
+const struct mux_extradata_builder_cb hxxx_cb =
+{
     NULL,
+    hxxx_extradata_builder_Feed,
+    hxxx_extradata_builder_Deinit,
 };
 
 void mux_extradata_builder_Delete(mux_extradata_builder_t *m)
 {
-    if(m->cb.pf_deinit)
-        m->cb.pf_deinit(m);
-    free(m->p_extra);
+    m->cb.pf_deinit(m);
     free(m);
 }
 
@@ -172,9 +212,12 @@ static const struct
     { EXTRADATA_ISOBMFF, VLC_CODEC_AV1,  &av1_cb },
     { EXTRADATA_ISOBMFF, VLC_CODEC_A52,  &ac3_cb },
     { EXTRADATA_ISOBMFF, VLC_CODEC_EAC3, &eac3_cb },
+    { EXTRADATA_ISOBMFF, VLC_CODEC_H264, &hxxx_cb },
+    { EXTRADATA_ISOBMFF, VLC_CODEC_HEVC, &hxxx_cb },
 };
 
-mux_extradata_builder_t * mux_extradata_builder_New(vlc_fourcc_t fcc,
+mux_extradata_builder_t * mux_extradata_builder_New(vlc_object_t *obj,
+                                                    vlc_fourcc_t fcc,
                                                     enum mux_extradata_type_e 
type)
 {
     const struct mux_extradata_builder_cb *cb = NULL;
@@ -189,16 +232,21 @@ mux_extradata_builder_t * 
mux_extradata_builder_New(vlc_fourcc_t fcc,
     if(cb == NULL)
         return NULL;
 
+    assert(cb->pf_feed != NULL);
+    assert(cb->pf_deinit != NULL);
+
     mux_extradata_builder_t *m = calloc(1, sizeof(*m));
-    if(m)
+    if(m == NULL)
+        return NULL;
+
+    m->priv = NULL;
+    m->fcc = fcc;
+    m->cb = *cb;
+    m->obj = obj;
+    if(m->cb.pf_init && m->cb.pf_init(m) != 0)
     {
-        m->fcc = fcc;
-        m->cb = *cb;
-        if(m->cb.pf_init && m->cb.pf_init(m) != 0)
-        {
-            free(m);
-            m = NULL;
-        }
+        free(m);
+        m = NULL;
     }
     return m;
 }


=====================================
modules/mux/extradata.h
=====================================
@@ -25,7 +25,9 @@ enum mux_extradata_type_e
     EXTRADATA_ISOBMFF,
 };
 
-mux_extradata_builder_t * mux_extradata_builder_New(vlc_fourcc_t, enum 
mux_extradata_type_e);
+mux_extradata_builder_t * mux_extradata_builder_New(vlc_object_t *obj,
+                                                    vlc_fourcc_t,
+                                                    enum mux_extradata_type_e);
 void mux_extradata_builder_Delete(mux_extradata_builder_t *);
 void mux_extradata_builder_Feed(mux_extradata_builder_t *, const uint8_t *, 
size_t);
 size_t mux_extradata_builder_Get(mux_extradata_builder_t *, const uint8_t **);


=====================================
modules/mux/mp4/mp4.c
=====================================
@@ -516,7 +516,8 @@ static int AddStream(sout_mux_t *p_mux, sout_input_t 
*p_input)
         return VLC_ENOMEM;
     }
 
-    p_stream->extrabuilder = mux_extradata_builder_New(p_input->p_fmt->i_codec,
+    p_stream->extrabuilder = mux_extradata_builder_New(VLC_OBJECT(p_mux),
+                                                       p_input->p_fmt->i_codec,
                                                        EXTRADATA_ISOBMFF);
 
     p_input->p_sys          = p_stream;



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/d80e9d0c057dfcd223aea94f83fb6ee7c668c16c...b30232a07d7f6748427cd31b731c093c6fedbe6b

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/d80e9d0c057dfcd223aea94f83fb6ee7c668c16c...b30232a07d7f6748427cd31b731c093c6fedbe6b
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to