[vlc-commits] bd: use single allocation for ES output

Rémi Denis-Courmont git at videolan.org
Sun Jun 10 16:44:35 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 10 17:27:44 2018 +0300| [c4a517bd8a11e27f2fe6810f0b30be1008c43fb2] | committer: Rémi Denis-Courmont

bd: use single allocation for ES output

And simplify accordingly.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c4a517bd8a11e27f2fe6810f0b30be1008c43fb2
---

 modules/access/bluray.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/modules/access/bluray.c b/modules/access/bluray.c
index bcf53aba13..4fca6b79a7 100644
--- a/modules/access/bluray.c
+++ b/modules/access/bluray.c
@@ -928,6 +928,7 @@ typedef struct
     es_out_t *p_dst_out;
     vlc_object_t *p_obj;
     void *priv;
+    es_out_t es_out;
 } es_out_sys_t;
 
 typedef struct  fmt_es_pair {
@@ -1006,7 +1007,7 @@ static int blurayEsPid(demux_sys_t *p_sys, int es_type, int i_es_idx)
 
 static es_out_id_t *esOutAdd(es_out_t *p_out, const es_format_t *p_fmt)
 {
-    es_out_sys_t *es_out_sys = p_out->p_sys;
+    es_out_sys_t *es_out_sys = container_of(p_out, es_out_sys_t, es_out);
     demux_t *p_demux = es_out_sys->priv;
     demux_sys_t *p_sys = p_demux->p_sys;
     es_format_t fmt;
@@ -1067,14 +1068,14 @@ static es_out_id_t *esOutAdd(es_out_t *p_out, const es_format_t *p_fmt)
 
 static int esOutSend(es_out_t *p_out, es_out_id_t *p_es, block_t *p_block)
 {
-    es_out_sys_t *es_out_sys = p_out->p_sys;
+    es_out_sys_t *es_out_sys = container_of(p_out, es_out_sys_t, es_out);
 
     return es_out_Send(es_out_sys->p_dst_out, p_es, p_block);
 }
 
 static void esOutDel(es_out_t *p_out, es_out_id_t *p_es)
 {
-    es_out_sys_t *es_out_sys = p_out->p_sys;
+    es_out_sys_t *es_out_sys = container_of(p_out, es_out_sys_t, es_out);
     demux_t *p_demux = es_out_sys->priv;
     demux_sys_t *p_sys = p_demux->p_sys;
 
@@ -1088,22 +1089,21 @@ static void esOutDel(es_out_t *p_out, es_out_id_t *p_es)
 
 static int esOutControl(es_out_t *p_out, int i_query, va_list args)
 {
-    es_out_sys_t *es_out_sys = p_out->p_sys;
+    es_out_sys_t *es_out_sys = container_of(p_out, es_out_sys_t, es_out);
 
     return es_out_vaControl(es_out_sys->p_dst_out, i_query, args);
 }
 
 static void esOutDestroy(es_out_t *p_out)
 {
-    es_out_sys_t *es_out_sys = p_out->p_sys;
+    es_out_sys_t *es_out_sys = container_of(p_out, es_out_sys_t, es_out);
     demux_t *p_demux = es_out_sys->priv;
     demux_sys_t *p_sys = p_demux->p_sys;
 
     for (size_t i = 0; i < vlc_array_count(&p_sys->es); ++i)
         free(vlc_array_item_at_index(&p_sys->es, i));
     vlc_array_clear(&p_sys->es);
-    free(p_out->p_sys);
-    free(p_out);
+    free(es_out_sys);
 }
 
 static const struct es_out_callbacks esOutCallbacks = {
@@ -1116,22 +1116,15 @@ static const struct es_out_callbacks esOutCallbacks = {
 
 static es_out_t *esOutNew(vlc_object_t *p_obj, es_out_t *p_dst_out, void *priv)
 {
-    es_out_t    *p_out = malloc(sizeof(*p_out));
-    if (unlikely(p_out == NULL))
-        return NULL;
-
-    p_out->cbs = &esOutCallbacks;
-
     es_out_sys_t *es_out_sys = malloc(sizeof(*es_out_sys));
-    if (unlikely(es_out_sys == NULL)) {
-        free(p_out);
+    if (unlikely(es_out_sys == NULL))
         return NULL;
-    }
-    p_out->p_sys = es_out_sys;
+
     es_out_sys->p_dst_out = p_dst_out;
     es_out_sys->p_obj = p_obj;
     es_out_sys->priv = priv;
-    return p_out;
+    es_out_sys->es_out.cbs = &esOutCallbacks;
+    return &es_out_sys->es_out;
 }
 
 /*****************************************************************************



More information about the vlc-commits mailing list