From 0d1f966a0b3581d3e96423ce34f32b4da7725c31 Mon Sep 17 00:00:00 2001 From: Pierre d'Herbemont Date: Fri, 21 Aug 2009 12:27:56 +0200 Subject: [PATCH] Implement access_GetParentInput and demux_GetParentInput and use. This try to avoid vlc_object_find() as much as possible. This is conservative, because where there is no associated parent input, we'll try to find in certain cases the parent input. This will probably be removed later on. Because yes, there is not necessarily a parent input for access and demux, especially if created from stream_UrlNew(). --- include/vlc_access.h | 9 +++++++++ include/vlc_demux.h | 9 +++++++++ include/vlc_stream.h | 7 +++++-- src/input/access.c | 16 ++++++++++++++-- src/input/access.h | 7 ++++--- src/input/demux.c | 13 ++++++++++++- src/input/demux.h | 4 ++-- src/input/input.c | 6 +++--- src/input/stream.c | 22 +++++++++++++++------- src/input/stream_demux.c | 7 ++++--- src/input/stream_filter.c | 2 ++ src/input/stream_memory.c | 6 ++++++ src/libvlccore.sym | 4 +++- 13 files changed, 88 insertions(+), 24 deletions(-) diff --git a/include/vlc_access.h b/include/vlc_access.h index 92044ebb6d..d12953a41c 100644 --- a/include/vlc_access.h +++ b/include/vlc_access.h @@ -115,6 +115,9 @@ struct access_t int i_seekpoint;/* idem, start from 0 */ } info; access_sys_t *p_sys; + + /* Weak link to parent input */ + input_thread_t *p_input; }; static inline int access_vaControl( access_t *p_access, int i_query, va_list args ) @@ -144,6 +147,12 @@ static inline void access_InitFields( access_t *p_a ) p_a->info.i_seekpoint = 0; } +/** + * This function will return the parent input of this access. + * It is retained. It can return NULL. + */ +VLC_EXPORT( input_thread_t *, access_GetParentInput, ( access_t *p_access ) ); + #define ACCESS_SET_CALLBACKS( read, block, control, seek ) \ p_access->pf_read = read; \ p_access->pf_block = block; \ diff --git a/include/vlc_demux.h b/include/vlc_demux.h index e2858e8e2b..9abdee0831 100644 --- a/include/vlc_demux.h +++ b/include/vlc_demux.h @@ -71,6 +71,9 @@ struct demux_t int i_seekpoint; /* idem, start from 0 */ } info; demux_sys_t *p_sys; + + /* Weak link to parent input */ + input_thread_t *p_input; }; @@ -190,6 +193,12 @@ VLC_EXPORT( decoder_t *,demux_PacketizerNew, ( demux_t *p_demux, es_format_t *p_ */ VLC_EXPORT( void, demux_PacketizerDestroy, ( decoder_t *p_packetizer ) ); +/** + * This function will return the parent input of this demux. + * It is retained. Can return NULL. + */ +VLC_EXPORT( input_thread_t *, demux_GetParentInput, ( demux_t *p_demux ) ); + /* */ #define DEMUX_INIT_COMMON() do { \ p_demux->pf_control = Control; \ diff --git a/include/vlc_stream.h b/include/vlc_stream.h index e5cd0e0130..96a2f0e5f7 100644 --- a/include/vlc_stream.h +++ b/include/vlc_stream.h @@ -75,6 +75,9 @@ struct stream_t /* Text reader state */ stream_text_t *p_text; + + /* Weak link to parent input */ + input_thread_t *p_input; }; /** @@ -157,8 +160,8 @@ static inline char *stream_ContentType( stream_t *s ) * Create a special stream and a demuxer, this allows chaining demuxers * You must delete it using stream_Delete. */ -#define stream_DemuxNew( a, b, c ) __stream_DemuxNew( VLC_OBJECT(a), b, c) -VLC_EXPORT( stream_t *,__stream_DemuxNew, ( vlc_object_t *p_obj, const char *psz_demux, es_out_t *out ) ); +VLC_EXPORT( stream_t *, stream_DemuxNew, ( demux_t *p_demux, const char *psz_demux, es_out_t *out ) ); + /** * Send data to a stream_t handle created by stream_DemuxNew. */ diff --git a/src/input/access.c b/src/input/access.c index b5668c0ddd..98e30d4ccf 100644 --- a/src/input/access.c +++ b/src/input/access.c @@ -31,8 +31,9 @@ /***************************************************************************** * access_New: *****************************************************************************/ -access_t *__access_New( vlc_object_t *p_obj, const char *psz_access, - const char *psz_demux, const char *psz_path ) +access_t *__access_New( vlc_object_t *p_obj, input_thread_t *p_parent_input, + const char *psz_access, const char *psz_demux, + const char *psz_path ) { access_t *p_access = vlc_custom_create( p_obj, sizeof (*p_access), VLC_OBJECT_GENERIC, "access" ); @@ -44,6 +45,8 @@ access_t *__access_New( vlc_object_t *p_obj, const char *psz_access, msg_Dbg( p_obj, "creating access '%s' path='%s'", psz_access, psz_path ); + p_access->p_input = p_parent_input; + p_access->psz_path = strdup( psz_path ); p_access->psz_access = strdup( psz_access ); p_access->psz_demux = strdup( psz_demux ); @@ -89,3 +92,12 @@ void access_Delete( access_t *p_access ) vlc_object_release( p_access ); } + +/***************************************************************************** + * access_GetParentInput: + *****************************************************************************/ +input_thread_t * access_GetParentInput( access_t *p_access ) +{ + return p_access->p_input ? vlc_object_hold((vlc_object_t *)p_access->p_input) : NULL; +} + diff --git a/src/input/access.h b/src/input/access.h index 42485d7eb6..0e8739b5ea 100644 --- a/src/input/access.h +++ b/src/input/access.h @@ -32,9 +32,10 @@ #include #include -#define access_New( a, b, c, d ) __access_New(VLC_OBJECT(a), b, c, d ) -access_t * __access_New( vlc_object_t *p_obj, const char *psz_access, - const char *psz_demux, const char *psz_path ); +#define access_New( a, b, c, d, e ) __access_New(VLC_OBJECT(a), b, c, d, e ) +access_t * __access_New( vlc_object_t *p_obj, input_thread_t *p_input, + const char *psz_access, const char *psz_demux, + const char *psz_path ); void access_Delete( access_t * ); #endif diff --git a/src/input/demux.c b/src/input/demux.c index 082f956bba..2a37ab1a4f 100644 --- a/src/input/demux.c +++ b/src/input/demux.c @@ -37,7 +37,7 @@ static bool SkipAPETag( demux_t *p_demux ); * demux_New: * if s is NULL then load a access_demux *****************************************************************************/ -demux_t *__demux_New( vlc_object_t *p_obj, +demux_t *__demux_New( vlc_object_t *p_obj, input_thread_t *p_parent_input, const char *psz_access, const char *psz_demux, const char *psz_path, stream_t *s, es_out_t *out, bool b_quick ) @@ -49,6 +49,8 @@ demux_t *__demux_New( vlc_object_t *p_obj, if( p_demux == NULL ) return NULL; + p_demux->p_input = p_parent_input; + /* Parse URL */ p_demux->psz_access = strdup( psz_access ); p_demux->psz_demux = strdup( psz_demux ); @@ -203,6 +205,15 @@ void demux_Delete( demux_t *p_demux ) vlc_object_release( p_demux ); } +/***************************************************************************** + * demux_GetParentInput: + *****************************************************************************/ +input_thread_t * demux_GetParentInput( demux_t *p_demux ) +{ + return p_demux->p_input ? vlc_object_hold((vlc_object_t*)p_demux->p_input) : NULL; +} + + /***************************************************************************** * demux_vaControlHelper: *****************************************************************************/ diff --git a/src/input/demux.h b/src/input/demux.h index a5ca31f040..8e9aa27088 100644 --- a/src/input/demux.h +++ b/src/input/demux.h @@ -35,8 +35,8 @@ #include "stream.h" /* stream_t *s could be null and then it mean a access+demux in one */ -#define demux_New( a, b, c, d, e, f,g ) __demux_New(VLC_OBJECT(a),b,c,d,e,f,g) -demux_t *__demux_New( vlc_object_t *p_obj, const char *psz_access, const char *psz_demux, const char *psz_path, stream_t *s, es_out_t *out, bool ); +#define demux_New( a, b, c, d, e, f, g, h ) __demux_New(VLC_OBJECT(a),b,c,d,e,f,g,h) +demux_t *__demux_New( vlc_object_t *p_obj, input_thread_t *p_parent_input, const char *psz_access, const char *psz_demux, const char *psz_path, stream_t *s, es_out_t *out, bool ); void demux_Delete( demux_t * ); diff --git a/src/input/input.c b/src/input/input.c index 4444e7241f..1e0a4c5979 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -2416,7 +2416,7 @@ static int InputSourceInit( input_thread_t *p_input, } /* Try access_demux first */ - in->p_demux = demux_New( p_input, psz_access, psz_demux, psz_path, + in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux, psz_path, NULL, p_input->p->p_es_out, false ); } else @@ -2481,7 +2481,7 @@ static int InputSourceInit( input_thread_t *p_input, else { /* Now try a real access */ - in->p_access = access_New( p_input, psz_access, psz_demux, psz_path ); + in->p_access = access_New( p_input, p_input, psz_access, psz_demux, psz_path ); if( in->p_access == NULL ) { if( vlc_object_alive( p_input ) ) @@ -2609,7 +2609,7 @@ static int InputSourceInit( input_thread_t *p_input, { psz_real_path = psz_path; } - in->p_demux = demux_New( p_input, psz_access, psz_demux, + in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux, psz_real_path, in->p_stream, p_input->p->p_es_out, p_input->b_preparsing ); diff --git a/src/input/stream.c b/src/input/stream.c index e148409b76..a616705931 100644 --- a/src/input/stream.c +++ b/src/input/stream.c @@ -229,6 +229,7 @@ stream_t *stream_CommonNew( vlc_object_t *p_obj ) return s; } + void stream_CommonDelete( stream_t *s ) { if( s->p_text ) @@ -258,8 +259,15 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url ) strcpy( psz_dup, psz_url ); input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup ); + /* Get a weak link to the parent input */ + /* FIXME: This should probably be removed in favor of a NULL input. */ + input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_parent, VLC_OBJECT_INPUT, FIND_PARENT ); + /* Now try a real access */ - p_access = access_New( p_parent, psz_access, psz_demux, psz_path ); + p_access = access_New( p_parent, p_input, psz_access, psz_demux, psz_path ); + + if(p_input) + vlc_object_release((vlc_object_t*)p_input); if( p_access == NULL ) { @@ -285,6 +293,7 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list ) if( !s ) return NULL; + s->p_input = p_access->p_input; s->psz_path = strdup( p_access->psz_path ); s->p_sys = p_sys = malloc( sizeof( *p_sys ) ); if( !s->psz_path || !s->p_sys ) @@ -348,7 +357,7 @@ stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list ) if( !psz_name ) break; - access_t *p_tmp = access_New( p_access, + access_t *p_tmp = access_New( p_access, p_access->p_input, p_access->psz_access, "", psz_name ); if( !p_tmp ) continue; @@ -1533,8 +1542,7 @@ char *stream_ReadLine( stream_t *s ) } /* FIXME that's UGLY */ - input_thread_t *p_input; - p_input = (input_thread_t *)vlc_object_find( s, VLC_OBJECT_INPUT, FIND_PARENT ); + input_thread_t *p_input = s->p_input; if( p_input != NULL) { var_Create( p_input, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); @@ -1716,7 +1724,7 @@ static int AReadStream( stream_t *s, void *p_read, unsigned int i_read ) msg_Dbg( s, "opening input `%s'", psz_name ); - p_list_access = access_New( s, p_access->psz_access, "", psz_name ); + p_list_access = access_New( s, s->p_input, p_access->psz_access, "", psz_name ); if( !p_list_access ) return 0; @@ -1788,7 +1796,7 @@ static block_t *AReadBlock( stream_t *s, bool *pb_eof ) msg_Dbg( s, "opening input `%s'", psz_name ); - p_list_access = access_New( s, p_access->psz_access, "", psz_name ); + p_list_access = access_New( s, s->p_input, p_access->psz_access, "", psz_name ); if( !p_list_access ) return 0; @@ -1843,7 +1851,7 @@ static int ASeek( stream_t *s, int64_t i_pos ) if( i != p_sys->i_list_index && i != 0 ) { p_list_access = - access_New( s, p_access->psz_access, "", psz_name ); + access_New( s, s->p_input, p_access->psz_access, "", psz_name ); } else if( i != p_sys->i_list_index ) { diff --git a/src/input/stream_demux.c b/src/input/stream_demux.c index 2d07eaecf9..69eac89beb 100644 --- a/src/input/stream_demux.c +++ b/src/input/stream_demux.c @@ -54,9 +54,9 @@ static void DStreamDelete ( stream_t * ); static void* DStreamThread ( vlc_object_t * ); -stream_t *__stream_DemuxNew( vlc_object_t *p_obj, const char *psz_demux, - es_out_t *out ) +stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *out ) { + vlc_object_t *p_obj = VLC_OBJECT(p_demux); /* We create a stream reader, and launch a thread */ stream_t *s; stream_sys_t *p_sys; @@ -64,6 +64,7 @@ stream_t *__stream_DemuxNew( vlc_object_t *p_obj, const char *psz_demux, s = stream_CommonNew( p_obj ); if( s == NULL ) return NULL; + s->p_input = p_demux->p_input; s->psz_path = strdup(""); /* N/A */ s->pf_read = DStreamRead; s->pf_peek = DStreamPeek; @@ -278,7 +279,7 @@ static void* DStreamThread( vlc_object_t* p_this ) int canc = vlc_savecancel(); /* Create the demuxer */ - if( !(p_demux = demux_New( s, "", p_sys->psz_name, "", s, p_sys->out, + if( !(p_demux = demux_New( s, s->p_input, "", p_sys->psz_name, "", s, p_sys->out, false )) ) { return NULL; diff --git a/src/input/stream_filter.c b/src/input/stream_filter.c index 99060f89c7..213643f58f 100644 --- a/src/input/stream_filter.c +++ b/src/input/stream_filter.c @@ -42,6 +42,8 @@ stream_t *stream_FilterNew( stream_t *p_source, if( s == NULL ) return NULL; + s->p_input = p_source->p_input; + /* */ s->psz_path = strdup( p_source->psz_path ); if( !s->psz_path ) diff --git a/src/input/stream_memory.c b/src/input/stream_memory.c index 8cd3c43725..7444fda2d0 100644 --- a/src/input/stream_memory.c +++ b/src/input/stream_memory.c @@ -78,6 +78,12 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, vlc_object_attach( s, p_this ); + /* Get a weak link to the parent input */ + /* FIXME: The usage of vlc_object_find has to be removed. */ + s->p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT ); + if(s->p_input) + vlc_object_release((vlc_object_t*)s->p_input); + return s; } diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 31df160a5e..b500402708 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -1,3 +1,4 @@ +access_GetParentInput ACL_AddNet ACL_Check __ACL_Create @@ -97,6 +98,7 @@ decoder_SynchroTrash decoder_UnlinkPicture decode_URI decode_URI_duplicate +demux_GetParentInput demux_PacketizerDestroy demux_PacketizerNew demux_vaControlHelper @@ -379,7 +381,7 @@ __stats_TimerStop stream_Block stream_Control stream_Delete -__stream_DemuxNew +stream_DemuxNew stream_DemuxSend __stream_MemoryNew stream_Peek -- 2.39.2