[vlc-commits] es_out: use constant callback structures

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 10 15:37:00 2018 +0300| [ab6dfaa92fc459b687a7aa1372021e83040d5826] | committer: Rémi Denis-Courmont

es_out: use constant callback structures

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

 include/vlc_es_out.h                          | 26 +++++++++++++++-----------
 modules/access/bluray.c                       | 14 +++++++++-----
 modules/demux/adaptive/plumbing/FakeESOut.cpp | 15 ++++++++++-----
 src/input/es_out.c                            | 21 ++++++++++++---------
 src/input/es_out_timeshift.c                  | 22 ++++++++++++----------
 test/src/input/demux-run.c                    | 15 ++++++++++-----
 6 files changed, 68 insertions(+), 45 deletions(-)

diff --git a/include/vlc_es_out.h b/include/vlc_es_out.h
index 5f70251dc7..4b93db692d 100644
--- a/include/vlc_es_out.h
+++ b/include/vlc_es_out.h
@@ -108,37 +108,41 @@ enum es_out_policy_e
     ES_OUT_ES_POLICY_SIMULTANEOUS, /* Allows multiple ES per cat */
 };
 
-struct es_out_t
+struct es_out_callbacks
 {
-    es_out_id_t *(*pf_add)    ( es_out_t *, const es_format_t * );
-    int          (*pf_send)   ( es_out_t *, es_out_id_t *, block_t * );
-    void         (*pf_del)    ( es_out_t *, es_out_id_t * );
-    int          (*pf_control)( es_out_t *, int i_query, va_list );
-    void         (*pf_destroy)( es_out_t * );
+    es_out_id_t *(*add)(es_out_t *, const es_format_t *);
+    int          (*send)(es_out_t *, es_out_id_t *, block_t *);
+    void         (*del)(es_out_t *, es_out_id_t *);
+    int          (*control)(es_out_t *, int query, va_list);
+    void         (*destroy)(es_out_t *);
+};
 
+struct es_out_t
+{
+    const struct es_out_callbacks *cbs;
     void        *p_sys;
 };
 
 VLC_USED
 static inline es_out_id_t * es_out_Add( es_out_t *out, const es_format_t *fmt )
 {
-    return out->pf_add( out, fmt );
+    return out->cbs->add( out, fmt );
 }
 
 static inline void es_out_Del( es_out_t *out, es_out_id_t *id )
 {
-    out->pf_del( out, id );
+    out->cbs->del( out, id );
 }
 
 static inline int es_out_Send( es_out_t *out, es_out_id_t *id,
                                block_t *p_block )
 {
-    return out->pf_send( out, id, p_block );
+    return out->cbs->send( out, id, p_block );
 }
 
 static inline int es_out_vaControl( es_out_t *out, int i_query, va_list args )
 {
-    return out->pf_control( out, i_query, args );
+    return out->cbs->control( out, i_query, args );
 }
 
 static inline int es_out_Control( es_out_t *out, int i_query, ... )
@@ -154,7 +158,7 @@ static inline int es_out_Control( es_out_t *out, int i_query, ... )
 
 static inline void es_out_Delete( es_out_t *p_out )
 {
-    p_out->pf_destroy( p_out );
+    p_out->cbs->destroy( p_out );
 }
 
 static inline int es_out_SetPCR( es_out_t *out, mtime_t pcr )
diff --git a/modules/access/bluray.c b/modules/access/bluray.c
index 43841689ee..bcf53aba13 100644
--- a/modules/access/bluray.c
+++ b/modules/access/bluray.c
@@ -1106,17 +1106,21 @@ static void esOutDestroy(es_out_t *p_out)
     free(p_out);
 }
 
+static const struct es_out_callbacks esOutCallbacks = {
+    .add = esOutAdd,
+    .send = esOutSend,
+    .del = esOutDel,
+    .control = esOutControl,
+    .destroy = esOutDestroy,
+};
+
 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->pf_add       = esOutAdd;
-    p_out->pf_control   = esOutControl;
-    p_out->pf_del       = esOutDel;
-    p_out->pf_destroy   = esOutDestroy;
-    p_out->pf_send      = esOutSend;
+    p_out->cbs = &esOutCallbacks;
 
     es_out_sys_t *es_out_sys = malloc(sizeof(*es_out_sys));
     if (unlikely(es_out_sys == NULL)) {
diff --git a/modules/demux/adaptive/plumbing/FakeESOut.cpp b/modules/demux/adaptive/plumbing/FakeESOut.cpp
index ffd1d91de7..62f50cada9 100644
--- a/modules/demux/adaptive/plumbing/FakeESOut.cpp
+++ b/modules/demux/adaptive/plumbing/FakeESOut.cpp
@@ -31,6 +31,15 @@
 
 using namespace adaptive;
 
+static const struct es_out_callbacks esOutCallbacks =
+{
+    FakeESOut::esOutAdd_Callback,
+    FakeESOut::esOutSend_Callback,
+    FakeESOut::esOutDel_Callback,
+    FakeESOut::esOutControl_Callback,
+    FakeESOut::esOutDestroy_Callback,
+};
+
 FakeESOut::FakeESOut( es_out_t *es, CommandsQueue *queue )
     : real_es_out( es )
     , extrainfo( NULL )
@@ -40,11 +49,7 @@ FakeESOut::FakeESOut( es_out_t *es, CommandsQueue *queue )
     , timestamps_expected( 0 )
     , timestamps_check_done( false )
 {
-    fakeesout->pf_add = esOutAdd_Callback;
-    fakeesout->pf_control = esOutControl_Callback;
-    fakeesout->pf_del = esOutDel_Callback;
-    fakeesout->pf_destroy = esOutDestroy_Callback;
-    fakeesout->pf_send = esOutSend_Callback;
+    fakeesout->cbs = &esOutCallbacks;
     fakeesout->p_sys = this;
 
     vlc_mutex_init(&lock);
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 83b6532d98..a3aed200d5 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -177,11 +177,7 @@ typedef struct
     int         i_prev_stream_level;
 } es_out_sys_t;
 
-static es_out_id_t *EsOutAdd    ( es_out_t *, const es_format_t * );
-static int          EsOutSend   ( es_out_t *, es_out_id_t *, block_t * );
 static void         EsOutDel    ( es_out_t *, es_out_id_t * );
-static int          EsOutControl( es_out_t *, int i_query, va_list );
-static void         EsOutDelete ( es_out_t * );
 
 static void         EsOutTerminate( es_out_t * );
 static void         EsOutSelect( es_out_t *, es_out_id_t *es, bool b_force );
@@ -282,6 +278,8 @@ static void EsOutPropsInit( es_out_es_props_t *p_props,
     }
 }
 
+static const struct es_out_callbacks es_out_cbs;
+
 /*****************************************************************************
  * input_EsOutNew:
  *****************************************************************************/
@@ -298,11 +296,7 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
         return NULL;
     }
 
-    out->pf_add     = EsOutAdd;
-    out->pf_send    = EsOutSend;
-    out->pf_del     = EsOutDel;
-    out->pf_control = EsOutControl;
-    out->pf_destroy = EsOutDelete;
+    out->cbs = &es_out_cbs;
     out->p_sys      = p_sys;
 
     vlc_mutex_init_recursive( &p_sys->lock );
@@ -2907,6 +2901,15 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
     return i_ret;
 }
 
+static const struct es_out_callbacks es_out_cbs =
+{
+    .add = EsOutAdd,
+    .send = EsOutSend,
+    .del = EsOutDel,
+    .control = EsOutControl,
+    .destroy = EsOutDelete,
+};
+
 /****************************************************************************
  * LanguageGetName: try to expend iso639 into plain name
  ****************************************************************************/
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index b048a47887..d8103b7d51 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -247,11 +247,7 @@ typedef struct
     es_out_id_t    **pp_es;
 } es_out_sys_t;
 
-static es_out_id_t *Add    ( es_out_t *, const es_format_t * );
-static int          Send   ( es_out_t *, es_out_id_t *, block_t * );
 static void         Del    ( es_out_t *, es_out_id_t * );
-static int          Control( es_out_t *, int i_query, va_list );
-static void         Destroy( es_out_t * );
 
 static int          TsStart( es_out_t * );
 static void         TsAutoStop( es_out_t * );
@@ -296,6 +292,8 @@ static int  CmdExecuteControl( es_out_t *, ts_cmd_t * );
 /* File helpers */
 static int GetTmpFile( char **ppsz_file, const char *psz_path );
 
+static const struct es_out_callbacks es_out_timeshift_cbs;
+
 /*****************************************************************************
  * input_EsOutTimeshiftNew:
  *****************************************************************************/
@@ -312,12 +310,7 @@ es_out_t *input_EsOutTimeshiftNew( input_thread_t *p_input, es_out_t *p_next_out
         return NULL;
     }
 
-    /* */
-    p_out->pf_add     = Add;
-    p_out->pf_send    = Send;
-    p_out->pf_del     = Del;
-    p_out->pf_control = Control;
-    p_out->pf_destroy = Destroy;
+    p_out->cbs = &es_out_timeshift_cbs;
     p_out->p_sys      = p_sys;
 
     /* */
@@ -751,6 +744,15 @@ static int Control( es_out_t *p_out, int i_query, va_list args )
     return i_ret;
 }
 
+static const struct es_out_callbacks es_out_timeshift_cbs =
+{
+    .add = Add,
+    .send = Send,
+    .del = Del,
+    .control = Control,
+    .destroy = Destroy,
+};
+
 /*****************************************************************************
  *
  *****************************************************************************/
diff --git a/test/src/input/demux-run.c b/test/src/input/demux-run.c
index b6b88d95e0..24bf321203 100644
--- a/test/src/input/demux-run.c
+++ b/test/src/input/demux-run.c
@@ -206,6 +206,15 @@ static void EsOutDestroy(es_out_t *out)
     free(ctx);
 }
 
+static const struct es_out_callbacks es_out_cbs =
+{
+    .add = EsOutAdd,
+    .send = EsOutSend,
+    .del = EsOutDelete,
+    .control = EsOutControl,
+    .destroy = EsOutDestroy,
+};
+
 static es_out_t *test_es_out_create(vlc_object_t *parent)
 {
     struct test_es_out_t *ctx = malloc(sizeof (*ctx));
@@ -218,11 +227,7 @@ static es_out_t *test_es_out_create(vlc_object_t *parent)
     ctx->ids = NULL;
 
     es_out_t *out = &ctx->out;
-    out->pf_add = EsOutAdd;
-    out->pf_send = EsOutSend;
-    out->pf_del = EsOutDelete;
-    out->pf_control = EsOutControl;
-    out->pf_destroy = EsOutDestroy;
+    out->cbs = &es_out_cbs;
     out->p_sys = (void *)parent;
 
     return out;



More information about the vlc-commits mailing list