[vlc-devel] commit: Stored vlc_epg_t array inside input_item_t. (Laurent Aimar )

git version control git at videolan.org
Tue Sep 22 22:59:45 CEST 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Tue Sep 22 22:25:07 2009 +0200| [f804bf433dd4a9352237b03f250200cb032d7a84] | committer: Laurent Aimar 

Stored vlc_epg_t array inside input_item_t.

As a side effect, the EPG informations are no more lost when stopping.

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

 include/vlc_input_item.h    |    4 +++
 src/input/es_out.c          |   45 +++++++++++++++++++------------------
 src/input/input_interface.h |    3 +-
 src/input/item.c            |   51 +++++++++++++++++++++++++++++++++++++-----
 4 files changed, 73 insertions(+), 30 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 6d4800e..4136bf1 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -31,6 +31,7 @@
  */
 
 #include <vlc_meta.h>
+#include <vlc_epg.h>
 
 #include <string.h>
 
@@ -82,6 +83,9 @@ struct input_item_t
 
     vlc_meta_t *p_meta;
 
+    int         i_epg;               /**< Number of EPG entries */
+    vlc_epg_t   **pp_epg;            /**< EPG entries */
+
     vlc_event_manager_t event_manager;
 
     vlc_mutex_t lock;                 /**< Lock for the item */
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 31a894b..30c5326 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -71,8 +71,6 @@ typedef struct
     char    *psz_name;
     char    *psz_now_playing;
     char    *psz_publisher;
-
-    vlc_epg_t *p_epg;
 } es_out_pgrm_t;
 
 struct es_out_id_t
@@ -382,8 +380,6 @@ static void EsOutDelete( es_out_t *out )
         free( p_pgrm->psz_now_playing );
         free( p_pgrm->psz_publisher );
         free( p_pgrm->psz_name );
-        if( p_pgrm->p_epg )
-            vlc_epg_Delete( p_pgrm->p_epg );
 
         free( p_pgrm );
     }
@@ -1065,7 +1061,6 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
     p_pgrm->psz_name = NULL;
     p_pgrm->psz_now_playing = NULL;
     p_pgrm->psz_publisher = NULL;
-    p_pgrm->p_epg = NULL;
     p_pgrm->p_clock = input_clock_New( p_sys->i_rate );
     if( !p_pgrm->p_clock )
     {
@@ -1128,8 +1123,6 @@ static int EsOutProgramDel( es_out_t *out, int i_group )
     free( p_pgrm->psz_name );
     free( p_pgrm->psz_now_playing );
     free( p_pgrm->psz_publisher );
-    if( p_pgrm->p_epg )
-        vlc_epg_Delete( p_pgrm->p_epg );
     free( p_pgrm );
 
     /* Update "program" variable */
@@ -1264,6 +1257,7 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg
 {
     es_out_sys_t      *p_sys = out->p_sys;
     input_thread_t    *p_input = p_sys->p_input;
+    input_item_t      *p_item = p_input->p->p_item;
     es_out_pgrm_t     *p_pgrm;
     char *psz_cat;
 
@@ -1272,28 +1266,35 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg
     if( !p_pgrm )
         return;
 
-    /* Merge EPG */
-    if( !p_pgrm->p_epg )
-        p_pgrm->p_epg = vlc_epg_New( p_pgrm->psz_name );
-    vlc_epg_Merge( p_pgrm->p_epg, p_epg );
-
     /* Update info */
-    msg_Dbg( p_input, "EsOutProgramEpg: number=%d name=%s", i_group, p_pgrm->p_epg->psz_name );
-
     psz_cat = EsOutProgramGetMetaName( p_pgrm );
+    msg_Dbg( p_input, "EsOutProgramEpg: number=%d name=%s", i_group, psz_cat );
 
-    char *psz_epg;
-    if( asprintf( &psz_epg, "EPG %s", psz_cat ) >= 0 )
-    {
-        input_item_SetEpg( p_input->p->p_item, psz_epg, p_pgrm->p_epg );
-        free( psz_epg );
-    }
+    /* Merge EPG */
+    vlc_epg_t epg;
+
+    epg = *p_epg;
+    epg.psz_name = psz_cat;
+
+    input_item_SetEpg( p_item, &epg );
 
     /* Update now playing */
     free( p_pgrm->psz_now_playing );
     p_pgrm->psz_now_playing = NULL;
-    if( p_pgrm->p_epg->p_current && p_pgrm->p_epg->p_current->psz_name && *p_pgrm->p_epg->p_current->psz_name )
-        p_pgrm->psz_now_playing = strdup( p_pgrm->p_epg->p_current->psz_name );
+
+    vlc_mutex_lock( &p_item->lock );
+    for( int i = 0; i < p_item->i_epg; i++ )
+    {
+        const vlc_epg_t *p_tmp = p_item->pp_epg[i];
+
+        if( p_tmp->psz_name && !strcmp(p_tmp->psz_name, psz_cat) )
+        {
+            if( p_tmp->p_current && p_tmp->p_current->psz_name && *p_tmp->p_current->psz_name )
+                p_pgrm->psz_now_playing = strdup( p_tmp->p_current->psz_name );
+            break;
+        }
+    }
+    vlc_mutex_unlock( &p_item->lock );
 
     if( p_pgrm == p_sys->p_pgrm )
     {
diff --git a/src/input/input_interface.h b/src/input/input_interface.h
index 4483510..9c3183b 100644
--- a/src/input/input_interface.h
+++ b/src/input/input_interface.h
@@ -37,8 +37,7 @@
 void input_item_SetPreparsed( input_item_t *p_i, bool b_preparsed );
 void input_item_SetArtNotFound( input_item_t *p_i, bool b_not_found );
 void input_item_SetArtFetched( input_item_t *p_i, bool b_art_fetched );
-void input_item_SetEpg( input_item_t *p_item,
-                        const char *psz_epg, const vlc_epg_t *p_epg );
+void input_item_SetEpg( input_item_t *p_item, const vlc_epg_t *p_epg );
 
 int input_Preparse( vlc_object_t *, input_item_t * );
 
diff --git a/src/input/item.c b/src/input/item.c
index ab804aa..d3030b7 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -47,6 +47,7 @@ static inline void input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
     TAB_INIT( p_i->i_options, p_i->ppsz_options );
     p_i->optflagv = NULL, p_i->optflagc = 0;
     TAB_INIT( p_i->i_categories, p_i->pp_categories );
+    TAB_INIT( p_i->i_epg, p_i->pp_epg );
 
     p_i->i_type = ITEM_TYPE_UNKNOWN;
     p_i->b_fixed_name = true;
@@ -95,6 +96,10 @@ static inline void input_item_Clean( input_item_t *p_i )
     }
     TAB_CLEAN( p_i->i_es, p_i->es );
 
+    for( i = 0; i < p_i->i_epg; i++ )
+        vlc_epg_Delete( p_i->pp_epg[i] );
+    TAB_CLEAN( p_i->i_epg, p_i->pp_epg );
+
     for( i = 0; i < p_i->i_categories; i++ )
     {
         info_category_t *p_category = p_i->pp_categories[i];
@@ -710,9 +715,43 @@ int input_item_DelInfo( input_item_t *p_i,
     return VLC_SUCCESS;
 }
 
-void input_item_SetEpg( input_item_t *p_item,
-                        const char *psz_epg, const vlc_epg_t *p_epg )
+#define EPG_DEBUG
+void input_item_SetEpg( input_item_t *p_item, const vlc_epg_t *p_update )
 {
+    vlc_mutex_lock( &p_item->lock );
+
+    /* */
+    vlc_epg_t *p_epg = NULL;
+    for( int i = 0; i < p_item->i_epg; i++ )
+    {
+        vlc_epg_t *p_tmp = p_item->pp_epg[i];
+
+        if( (p_tmp->psz_name == NULL) != (p_update->psz_name == NULL) )
+            continue;
+        if( p_tmp->psz_name && p_update->psz_name && strcmp(p_tmp->psz_name, p_update->psz_name) )
+            continue;
+
+        p_epg = p_tmp;
+        break;
+    }
+
+    /* */
+    if( !p_epg )
+    {
+        p_epg = vlc_epg_New( p_update->psz_name );
+        if( p_epg )
+            TAB_APPEND( p_item->i_epg, p_item->pp_epg, p_epg );
+    }
+    if( p_epg )
+        vlc_epg_Merge( p_epg, p_update );
+
+    vlc_mutex_unlock( &p_item->lock );
+
+#ifdef EPG_DEBUG
+    char *psz_epg;
+    if( asprintf( &psz_epg, "EPG %s", p_epg->psz_name ? p_epg->psz_name : "unknown" ) < 0 )
+        goto signal;
+
     input_item_DelInfo( p_item, psz_epg, NULL );
 
     vlc_mutex_lock( &p_item->lock );
@@ -740,17 +779,17 @@ void input_item_SetEpg( input_item_t *p_item,
                               p_evt->i_duration/60/60, (p_evt->i_duration/60)%60 );
     }
     vlc_mutex_unlock( &p_item->lock );
+    free( psz_epg );
+signal:
+#endif
 
     if( p_epg->i_event > 0 )
     {
-        vlc_event_t event;
-
-        event.type = vlc_InputItemInfoChanged;
+        vlc_event_t event = { .type = vlc_InputItemInfoChanged, };
         vlc_event_send( &p_item->event_manager, &event );
     }
 }
 
-
 input_item_t *__input_item_NewExt( vlc_object_t *p_obj, const char *psz_uri,
                                   const char *psz_name,
                                   int i_options,




More information about the vlc-devel mailing list