Commit 01aca2cc authored by Clément Stenac's avatar Clément Stenac

*experimental* input pre-parsing support.

Won't work for many things (only those for which metadata can be gotten during initialization).

Processing is done asynchronously, use playlist_PreparseEnqueue to add an item to the queue.
parent 3e46b414
......@@ -104,8 +104,8 @@ struct access_t
access_sys_t *p_sys;
};
#define access2_New( a, b, c, d ) __access2_New(VLC_OBJECT(a), b, c, d )
VLC_EXPORT( access_t *, __access2_New, ( vlc_object_t *p_obj, char *psz_access, char *psz_demux, char *psz_path ) );
#define access2_New( a, b, c, d, e ) __access2_New(VLC_OBJECT(a), b, c, d, e )
VLC_EXPORT( access_t *, __access2_New, ( vlc_object_t *p_obj, char *psz_access, char *psz_demux, char *psz_path, vlc_bool_t b_quick ) );
VLC_EXPORT( void, access2_Delete, ( access_t * ) );
static inline int access2_vaControl( access_t *p_access, int i_query, va_list args )
......
......@@ -225,6 +225,7 @@ typedef struct playlist_export_t playlist_export_t;
typedef struct services_discovery_t services_discovery_t;
typedef struct services_discovery_sys_t services_discovery_sys_t;
typedef struct playlist_add_t playlist_add_t;
typedef struct playlist_preparse_t playlist_preparse_t;
/* Modules */
typedef struct module_bank_t module_bank_t;
......
......@@ -109,8 +109,8 @@ enum demux_query_e
};
/* stream_t *s could be null and then it mean a access+demux in one */
#define demux2_New( a, b, c, d, e, f ) __demux2_New(VLC_OBJECT(a),b,c,d,e,f)
VLC_EXPORT( demux_t *, __demux2_New, ( vlc_object_t *p_obj, char *psz_access, char *psz_demux, char *psz_path, stream_t *s, es_out_t *out ) );
#define demux2_New( a, b, c, d, e, f,g ) __demux2_New(VLC_OBJECT(a),b,c,d,e,f,g)
VLC_EXPORT( demux_t *, __demux2_New, ( vlc_object_t *p_obj, char *psz_access, char *psz_demux, char *psz_path, stream_t *s, es_out_t *out, vlc_bool_t ) );
VLC_EXPORT( void, demux2_Delete, ( demux_t * ) );
VLC_EXPORT( int, demux2_vaControlHelper, ( stream_t *, int64_t i_start, int64_t i_end, int i_bitrate, int i_align, int i_query, va_list args ) );
......
......@@ -398,6 +398,8 @@ struct input_thread_t
*****************************************************************************/
#define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b)
VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item_t * ) );
#define input_Preparse(a,b) __input_Preparse(VLC_OBJECT(a),b)
VLC_EXPORT( int, __input_Preparse, ( vlc_object_t *, input_item_t * ) );
VLC_EXPORT( void, input_StopThread, ( input_thread_t * ) );
VLC_EXPORT( void, input_DestroyThread, ( input_thread_t * ) );
......
......@@ -127,6 +127,14 @@ struct services_discovery_t
void (*pf_run) ( services_discovery_t *);
};
struct playlist_preparse_t
{
VLC_COMMON_MEMBERS
vlc_mutex_t lock;
int i_waiting;
input_item_t **pp_waiting;
};
/**
* Structure containing information about the playlist
......@@ -191,9 +199,11 @@ struct playlist_t
vlc_bool_t b_request; /**< Set to true by the requester
The playlist sets it back to false
when processing the request */
vlc_mutex_t lock; /**< Lock to protect request */
vlc_mutex_t lock; /**< Lock to protect request */
} request;
playlist_preparse_t *p_preparse;
/*@}*/
};
......@@ -238,6 +248,7 @@ VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ... ) );
VLC_EXPORT( int, playlist_Clear, ( playlist_t * ) );
VLC_EXPORT( int, playlist_PreparseEnqueue, (playlist_t *, input_item_t *) );
/* Services discovery */
......
......@@ -90,6 +90,7 @@ enum
PopupPlay_Event,
PopupPlayThis_Event,
PopupPreparse_Event,
PopupSort_Event,
PopupDel_Event,
PopupEna_Event,
......@@ -150,6 +151,7 @@ BEGIN_EVENT_TABLE(Playlist, wxFrame)
/* Popup events */
EVT_MENU( PopupPlay_Event, Playlist::OnPopupPlay)
EVT_MENU( PopupPlayThis_Event, Playlist::OnPopupPlay)
EVT_MENU( PopupPreparse_Event, Playlist::OnPopupPreparse)
EVT_MENU( PopupSort_Event, Playlist::OnPopupSort)
EVT_MENU( PopupDel_Event, Playlist::OnPopupDel)
EVT_MENU( PopupEna_Event, Playlist::OnPopupEna)
......@@ -266,6 +268,7 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
popup_menu = new wxMenu;
popup_menu->Append( PopupPlay_Event, wxU(_("Play")) );
popup_menu->Append( PopupPlayThis_Event, wxU(_("Play this branch")) );
popup_menu->Append( PopupPreparse_Event, wxU(_("Preparse")) );
popup_menu->Append( PopupSort_Event, wxU(_("Sort this branch")) );
popup_menu->Append( PopupDel_Event, wxU(_("Delete")) );
popup_menu->Append( PopupEna_Event, wxU(_("Enable/Disable")) );
......@@ -1139,8 +1142,9 @@ void Playlist::OnActivateItem( wxTreeEvent& event )
playlist_item_t *p_item,*p_node;
playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
VLC_OBJECT_PLAYLIST,FIND_ANYWHERE );
PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
event.GetItem() );
event.GetItem() );
wxTreeItemId parent = treectrl->GetItemParent( event.GetItem() );
PlaylistItem *p_wxparent = (PlaylistItem *)treectrl->GetItemData( parent );
......@@ -1380,9 +1384,6 @@ void Playlist::OnPopup( wxContextMenuEvent& event )
Playlist::PopupMenu( popup_menu,
ScreenToClient( wxGetMousePosition() ) );
}
else
{
}
}
void Playlist::OnPopupPlay( wxMenuEvent& event )
......@@ -1424,6 +1425,38 @@ void Playlist::OnPopupPlay( wxMenuEvent& event )
vlc_object_release( p_playlist );
}
void Playlist::OnPopupPreparse( wxMenuEvent& event )
{
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist == NULL )
{
return;
}
if( p_popup_item != NULL )
{
if( p_popup_item->i_children == -1 )
{
playlist_PreparseEnqueue( p_playlist, &p_popup_item->input );
}
else
{
int i = 0;
playlist_item_t *p_parent = p_popup_item;
for( i = 0; i< p_parent->i_children ; i++ )
{
wxMenuEvent dummy;
i_popup_item = FindItem( treectrl->GetRootItem(),
p_parent->pp_children[i] );
p_popup_item = p_parent->pp_children[i];
OnPopupPreparse( dummy );
}
}
}
vlc_object_release( p_playlist );
}
void Playlist::OnPopupDel( wxMenuEvent& event )
{
PlaylistItem *p_wxitem;
......
......@@ -108,9 +108,14 @@ void Timer::Notify()
/* Update the input */
if( p_intf->p_sys->p_input == NULL )
{
p_intf->p_sys->p_input =
(input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist != NULL )
{
p_intf->p_sys->p_input = p_playlist->p_input;
vlc_object_release( p_playlist );
}
/* Refresh interface */
if( p_intf->p_sys->p_input )
......@@ -140,7 +145,6 @@ void Timer::Notify()
p_main_interface->statusbar->SetStatusText( wxT(""), 0 );
p_main_interface->statusbar->SetStatusText( wxT(""), 2 );
vlc_object_release( p_intf->p_sys->p_input );
p_intf->p_sys->p_input = NULL;
}
......
......@@ -175,11 +175,6 @@ static void Close( vlc_object_t *p_this )
{
intf_thread_t *p_intf = (intf_thread_t *)p_this;
if( p_intf->p_sys->p_input )
{
vlc_object_release( p_intf->p_sys->p_input );
}
vlc_mutex_lock( &p_intf->object_lock );
p_intf->b_dead = VLC_TRUE;
vlc_mutex_unlock( &p_intf->object_lock );
......
......@@ -846,6 +846,7 @@ private:
playlist_item_t *p_popup_parent;
void OnPopup( wxContextMenuEvent& event );
void OnPopupPlay( wxMenuEvent& event );
void OnPopupPreparse( wxMenuEvent& event );
void OnPopupSort( wxMenuEvent& event );
void OnPopupDel( wxMenuEvent& event );
void OnPopupEna( wxMenuEvent& event );
......
......@@ -31,7 +31,8 @@
* access2_New:
*****************************************************************************/
access_t *__access2_New( vlc_object_t *p_obj,
char *psz_access, char *psz_demux, char *psz_path )
char *psz_access, char *psz_demux, char *psz_path,
vlc_bool_t b_quick )
{
access_t *p_access = vlc_object_create( p_obj, VLC_OBJECT_ACCESS );
......@@ -42,12 +43,13 @@ access_t *__access2_New( vlc_object_t *p_obj,
}
/* Parse URL */
p_access->psz_access = strdup( psz_access );
p_access->psz_access = b_quick ? strdup( "file" ) : strdup( psz_access );
p_access->psz_path = strdup( psz_path );
p_access->psz_demux = strdup( "" );
msg_Dbg( p_obj, "access2_New: access='%s' path='%s'",
p_access->psz_access, p_access->psz_path );
if( !b_quick )
msg_Dbg( p_obj, "access2_New: access='%s' path='%s'",
p_access->psz_access, p_access->psz_path );
p_access->pf_read = NULL;
p_access->pf_block = NULL;
......@@ -66,7 +68,8 @@ access_t *__access2_New( vlc_object_t *p_obj,
vlc_object_attach( p_access, p_obj );
p_access->p_module =
module_Need( p_access, "access2", p_access->psz_access, VLC_FALSE );
module_Need( p_access, "access2", p_access->psz_access,
b_quick ? VLC_TRUE : VLC_FALSE );
if( p_access->p_module == NULL )
{
......
......@@ -33,7 +33,7 @@
*****************************************************************************/
demux_t *__demux2_New( vlc_object_t *p_obj,
char *psz_access, char *psz_demux, char *psz_path,
stream_t *s, es_out_t *out )
stream_t *s, es_out_t *out, vlc_bool_t b_quick )
{
demux_t *p_demux = vlc_object_create( p_obj, VLC_OBJECT_DEMUX );
char *psz_module;
......@@ -55,8 +55,11 @@ demux_t *__demux2_New( vlc_object_t *p_obj,
p_demux->psz_demux = var_GetString( p_obj, "demux" );
}
msg_Dbg( p_obj, "demux2_New: access='%s' demux='%s' path='%s'",
p_demux->psz_access, p_demux->psz_demux, p_demux->psz_path );
if( !b_quick )
{
msg_Dbg( p_obj, "demux2_New: access='%s' demux='%s' path='%s'",
p_demux->psz_access, p_demux->psz_demux, p_demux->psz_path );
}
p_demux->s = s;
p_demux->out = out;
......@@ -79,8 +82,8 @@ demux_t *__demux2_New( vlc_object_t *p_obj,
* - no .mp3, .a52, ... (aac is added as it works only by file ext anyway
* - wav can't be added 'cause of a52 and dts in them as raw audio
*/
static struct { char *ext; char *demux; } exttodemux[] =
{
static struct { char *ext; char *demux; } exttodemux[] =
{
{ "aac", "aac" },
{ "aiff", "aiff" },
{ "asf", "asf" }, { "wmv", "asf" }, { "wma", "asf" },
......@@ -98,17 +101,40 @@ demux_t *__demux2_New( vlc_object_t *p_obj,
{ "rm", "rm" },
{ NULL, NULL },
};
/* Here, we don't mind if it does not work, it must be quick */
static struct { char *ext; char *demux; } exttodemux_quick[] =
{
{ "mp3", "mpga" },
{ "ogg", "ogg" },
{ "wma", "asf" },
{ NULL, NULL }
};
char *psz_ext = strrchr( p_demux->psz_path, '.' ) + 1;
int i;
for( i = 0; exttodemux[i].ext != NULL; i++ )
if( !b_quick )
{
for( i = 0; exttodemux[i].ext != NULL; i++ )
{
if( !strcasecmp( psz_ext, exttodemux[i].ext ) )
{
psz_module = exttodemux[i].demux;
break;
}
}
}
else
{
if( !strcasecmp( psz_ext, exttodemux[i].ext ) )
for( i = 0; exttodemux_quick[i].ext != NULL; i++ )
{
psz_module = exttodemux[i].demux;
break;
if( !strcasecmp( psz_ext, exttodemux_quick[i].ext ) )
{
psz_module = exttodemux_quick[i].demux;
break;
}
}
}
}
......@@ -486,7 +512,8 @@ static int DStreamThread( stream_t *s )
demux_t *p_demux;
/* Create the demuxer */
if( !(p_demux = demux2_New( s, "", p_sys->psz_name, "", s, p_sys->out )) )
if( !(p_demux = demux2_New( s, "", p_sys->psz_name, "", s, p_sys->out,
VLC_FALSE )) )
{
return VLC_EGENERIC;
}
......
This diff is collapsed.
......@@ -102,7 +102,7 @@ void input_ControlVarTitle( input_thread_t *, int i_title );
void input_ConfigVarInit ( input_thread_t * );
/* stream.c */
stream_t *stream_AccessNew( access_t *p_access );
stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t );
void stream_AccessDelete( stream_t *s );
void stream_AccessReset( stream_t *s );
void stream_AccessUpdate( stream_t *s );
......
......@@ -136,6 +136,9 @@ struct stream_sys_t
int i_seek_count;
int64_t i_seek_time;
} stat;
/* Preparse mode ? */
vlc_bool_t b_quick;
};
/* Method 1: */
......@@ -157,7 +160,7 @@ static int AStreamControl( stream_t *, int i_query, va_list );
/****************************************************************************
* stream_AccessNew: create a stream from a access
****************************************************************************/
stream_t *stream_AccessNew( access_t *p_access )
stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick )
{
stream_t *s = vlc_object_create( p_access, VLC_OBJECT_STREAM );
stream_sys_t *p_sys;
......@@ -188,6 +191,8 @@ stream_t *stream_AccessNew( access_t *p_access )
p_sys->stat.i_seek_count = 0;
p_sys->stat.i_seek_time = 0;
p_sys->b_quick = b_quick;
/* Peek */
p_sys->i_peek = 0;
p_sys->p_peek = NULL;
......@@ -1129,8 +1134,9 @@ static void AStreamPrebufferStream( stream_t *s )
int64_t i_first = 0;
int64_t i_start;
int64_t i_prebuffer = (s->p_sys->p_access->info.i_title > 1 ||
s->p_sys->p_access->info.i_seekpoint > 1) ? STREAM_CACHE_PREBUFFER_SIZE : STREAM_CACHE_TRACK_SIZE / 3;
int64_t i_prebuffer = p_sys->b_quick ? STREAM_CACHE_TRACK_SIZE /100 :
((s->p_sys->p_access->info.i_title > 1 ||
s->p_sys->p_access->info.i_seekpoint > 1) ? STREAM_CACHE_PREBUFFER_SIZE : STREAM_CACHE_TRACK_SIZE / 3);
msg_Dbg( s, "pre buffering" );
i_start = mdate();
......
......@@ -43,6 +43,7 @@
* Local prototypes
*****************************************************************************/
static void RunThread ( playlist_t * );
static void RunPreparse( playlist_preparse_t * );
static playlist_item_t * NextItem ( playlist_t * );
static int PlayItem ( playlist_t *, playlist_item_t * );
......@@ -147,6 +148,31 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
return NULL;
}
/* Preparsing stuff */
p_playlist->p_preparse = vlc_object_create( p_playlist,
sizeof( playlist_preparse_t ) );
if( !p_playlist->p_preparse )
{
msg_Err( p_playlist, "unable to create preparser" );
vlc_object_destroy( p_playlist );
return NULL;
}
p_playlist->p_preparse->i_waiting = 0;
p_playlist->p_preparse->pp_waiting = NULL;
vlc_mutex_init( p_playlist->p_preparse,
&p_playlist->p_preparse->object_lock );
vlc_object_attach( p_playlist->p_preparse, p_playlist );
if( vlc_thread_create( p_playlist->p_preparse, "preparser",
RunPreparse, VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
{
msg_Err( p_playlist, "cannot spawn preparse thread" );
vlc_object_detach( p_playlist->p_preparse );
vlc_object_destroy( p_playlist->p_preparse );
return NULL;
}
/* The object has been initialized, now attach it */
vlc_object_attach( p_playlist, p_parent );
......@@ -171,8 +197,13 @@ int playlist_Destroy( playlist_t * p_playlist )
p_playlist->pp_sds[i]->psz_module );
}
vlc_thread_join( p_playlist->p_preparse );
vlc_thread_join( p_playlist );
vlc_object_detach( p_playlist->p_preparse );
vlc_mutex_destroy( &p_playlist->p_preparse->object_lock );
var_Destroy( p_playlist, "intf-change" );
var_Destroy( p_playlist, "item-change" );
var_Destroy( p_playlist, "playlist-current" );
......@@ -195,6 +226,7 @@ int playlist_Destroy( playlist_t * p_playlist )
free( p_view );
}
vlc_object_destroy( p_playlist->p_preparse );
vlc_object_destroy( p_playlist );
return VLC_SUCCESS;
......@@ -368,6 +400,18 @@ int playlist_vaControl( playlist_t * p_playlist, int i_query, va_list args )
return VLC_SUCCESS;
}
int playlist_PreparseEnqueue( playlist_t *p_playlist,
input_item_t *p_item )
{
vlc_mutex_lock( &p_playlist->p_preparse->object_lock );
INSERT_ELEM( p_playlist->p_preparse->pp_waiting,
p_playlist->p_preparse->i_waiting,
p_playlist->p_preparse->i_waiting,
p_item );
vlc_mutex_unlock( &p_playlist->p_preparse->object_lock );
return VLC_SUCCESS;
}
/* Destroy remaining objects */
static mtime_t ObjectGarbageCollector( playlist_t *p_playlist, int i_type,
......@@ -641,6 +685,37 @@ static void RunThread ( playlist_t *p_playlist )
}
}
/* Queue for items to preparse */
static void RunPreparse ( playlist_preparse_t *p_obj )
{
playlist_t *p_playlist = p_obj->p_parent;
vlc_bool_t b_sleep;
/* Tell above that we're ready */
vlc_thread_ready( p_obj );
while( !p_playlist->b_die )
{
vlc_mutex_lock( &p_obj->object_lock );
if( p_obj->i_waiting > 0 )
{
input_Preparse( p_playlist, p_obj->pp_waiting[0] );
var_SetInteger( p_playlist, "item-change",
p_obj->pp_waiting[0]->i_id );
REMOVE_ELEM( p_obj->pp_waiting, p_obj->i_waiting, 0 );
}
b_sleep = ( p_obj->i_waiting == 0 );
vlc_mutex_unlock( &p_obj->object_lock );
if( p_obj->i_waiting == 0 )
{
msleep( INTF_IDLE_SLEEP );
}
}
}
/*****************************************************************************
* NextItem
*****************************************************************************
......@@ -840,6 +915,10 @@ static playlist_item_t * NextItem( playlist_t *p_playlist )
playlist_view_t *p_view =
playlist_ViewFind( p_playlist,
p_playlist->status.i_view );
fprintf(stderr,"Finding next of %s within %s, view %i\n",
p_playlist->status.p_item ? p_playlist->status.p_item->input.psz_name : "coincoin",
p_playlist->status.p_node->input.psz_name,
p_playlist->status.i_view) ;
p_new = playlist_FindNextFromParent( p_playlist,
p_playlist->status.i_view,
p_view->p_root,
......
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