Commit f804bf43 authored by Laurent Aimar's avatar Laurent Aimar

Stored vlc_epg_t array inside input_item_t.

As a side effect, the EPG informations are no more lost when stopping.
parent 7bf4dcbd
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
*/ */
#include <vlc_meta.h> #include <vlc_meta.h>
#include <vlc_epg.h>
#include <string.h> #include <string.h>
...@@ -82,6 +83,9 @@ struct input_item_t ...@@ -82,6 +83,9 @@ struct input_item_t
vlc_meta_t *p_meta; 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_event_manager_t event_manager;
vlc_mutex_t lock; /**< Lock for the item */ vlc_mutex_t lock; /**< Lock for the item */
......
...@@ -71,8 +71,6 @@ typedef struct ...@@ -71,8 +71,6 @@ typedef struct
char *psz_name; char *psz_name;
char *psz_now_playing; char *psz_now_playing;
char *psz_publisher; char *psz_publisher;
vlc_epg_t *p_epg;
} es_out_pgrm_t; } es_out_pgrm_t;
struct es_out_id_t struct es_out_id_t
...@@ -382,8 +380,6 @@ static void EsOutDelete( es_out_t *out ) ...@@ -382,8 +380,6 @@ static void EsOutDelete( es_out_t *out )
free( p_pgrm->psz_now_playing ); free( p_pgrm->psz_now_playing );
free( p_pgrm->psz_publisher ); free( p_pgrm->psz_publisher );
free( p_pgrm->psz_name ); free( p_pgrm->psz_name );
if( p_pgrm->p_epg )
vlc_epg_Delete( p_pgrm->p_epg );
free( p_pgrm ); free( p_pgrm );
} }
...@@ -1065,7 +1061,6 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group ) ...@@ -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_name = NULL;
p_pgrm->psz_now_playing = NULL; p_pgrm->psz_now_playing = NULL;
p_pgrm->psz_publisher = NULL; p_pgrm->psz_publisher = NULL;
p_pgrm->p_epg = NULL;
p_pgrm->p_clock = input_clock_New( p_sys->i_rate ); p_pgrm->p_clock = input_clock_New( p_sys->i_rate );
if( !p_pgrm->p_clock ) if( !p_pgrm->p_clock )
{ {
...@@ -1128,8 +1123,6 @@ static int EsOutProgramDel( es_out_t *out, int i_group ) ...@@ -1128,8 +1123,6 @@ static int EsOutProgramDel( es_out_t *out, int i_group )
free( p_pgrm->psz_name ); free( p_pgrm->psz_name );
free( p_pgrm->psz_now_playing ); free( p_pgrm->psz_now_playing );
free( p_pgrm->psz_publisher ); free( p_pgrm->psz_publisher );
if( p_pgrm->p_epg )
vlc_epg_Delete( p_pgrm->p_epg );
free( p_pgrm ); free( p_pgrm );
/* Update "program" variable */ /* Update "program" variable */
...@@ -1264,6 +1257,7 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg ...@@ -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; es_out_sys_t *p_sys = out->p_sys;
input_thread_t *p_input = p_sys->p_input; 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; es_out_pgrm_t *p_pgrm;
char *psz_cat; char *psz_cat;
...@@ -1272,28 +1266,35 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg ...@@ -1272,28 +1266,35 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg
if( !p_pgrm ) if( !p_pgrm )
return; 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 */ /* Update info */
msg_Dbg( p_input, "EsOutProgramEpg: number=%d name=%s", i_group, p_pgrm->p_epg->psz_name );
psz_cat = EsOutProgramGetMetaName( p_pgrm ); psz_cat = EsOutProgramGetMetaName( p_pgrm );
msg_Dbg( p_input, "EsOutProgramEpg: number=%d name=%s", i_group, psz_cat );
char *psz_epg; /* Merge EPG */
if( asprintf( &psz_epg, "EPG %s", psz_cat ) >= 0 ) vlc_epg_t epg;
{
input_item_SetEpg( p_input->p->p_item, psz_epg, p_pgrm->p_epg ); epg = *p_epg;
free( psz_epg ); epg.psz_name = psz_cat;
}
input_item_SetEpg( p_item, &epg );
/* Update now playing */ /* Update now playing */
free( p_pgrm->psz_now_playing ); free( p_pgrm->psz_now_playing );
p_pgrm->psz_now_playing = NULL; 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 ) if( p_pgrm == p_sys->p_pgrm )
{ {
......
...@@ -37,8 +37,7 @@ ...@@ -37,8 +37,7 @@
void input_item_SetPreparsed( input_item_t *p_i, bool b_preparsed ); 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_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_SetArtFetched( input_item_t *p_i, bool b_art_fetched );
void input_item_SetEpg( input_item_t *p_item, void input_item_SetEpg( input_item_t *p_item, const vlc_epg_t *p_epg );
const char *psz_epg, const vlc_epg_t *p_epg );
int input_Preparse( vlc_object_t *, input_item_t * ); int input_Preparse( vlc_object_t *, input_item_t * );
......
...@@ -47,6 +47,7 @@ static inline void input_item_Init( vlc_object_t *p_o, input_item_t *p_i ) ...@@ -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 ); TAB_INIT( p_i->i_options, p_i->ppsz_options );
p_i->optflagv = NULL, p_i->optflagc = 0; p_i->optflagv = NULL, p_i->optflagc = 0;
TAB_INIT( p_i->i_categories, p_i->pp_categories ); 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->i_type = ITEM_TYPE_UNKNOWN;
p_i->b_fixed_name = true; p_i->b_fixed_name = true;
...@@ -95,6 +96,10 @@ static inline void input_item_Clean( input_item_t *p_i ) ...@@ -95,6 +96,10 @@ static inline void input_item_Clean( input_item_t *p_i )
} }
TAB_CLEAN( p_i->i_es, p_i->es ); 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++ ) for( i = 0; i < p_i->i_categories; i++ )
{ {
info_category_t *p_category = p_i->pp_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, ...@@ -710,9 +715,43 @@ int input_item_DelInfo( input_item_t *p_i,
return VLC_SUCCESS; return VLC_SUCCESS;
} }
void input_item_SetEpg( input_item_t *p_item, #define EPG_DEBUG
const char *psz_epg, const vlc_epg_t *p_epg ) 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 ); input_item_DelInfo( p_item, psz_epg, NULL );
vlc_mutex_lock( &p_item->lock ); vlc_mutex_lock( &p_item->lock );
...@@ -740,17 +779,17 @@ void input_item_SetEpg( input_item_t *p_item, ...@@ -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 ); p_evt->i_duration/60/60, (p_evt->i_duration/60)%60 );
} }
vlc_mutex_unlock( &p_item->lock ); vlc_mutex_unlock( &p_item->lock );
free( psz_epg );
signal:
#endif
if( p_epg->i_event > 0 ) if( p_epg->i_event > 0 )
{ {
vlc_event_t event; vlc_event_t event = { .type = vlc_InputItemInfoChanged, };
event.type = vlc_InputItemInfoChanged;
vlc_event_send( &p_item->event_manager, &event ); vlc_event_send( &p_item->event_manager, &event );
} }
} }
input_item_t *__input_item_NewExt( vlc_object_t *p_obj, const char *psz_uri, input_item_t *__input_item_NewExt( vlc_object_t *p_obj, const char *psz_uri,
const char *psz_name, const char *psz_name,
int i_options, int i_options,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment