📄 input.c
字号:
/***************************************************************************** * input.c: input thread ***************************************************************************** * Copyright (C) 1998-2007 the VideoLAN team * $Id: bbccf7e925518293c219eaf932e25250de2208ed $ * * Authors: Christophe Massiot <massiot@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <ctype.h>#include <limits.h>#include <assert.h>#include "input_internal.h"#include <vlc_sout.h>#include "../stream_output/stream_output.h"#include <vlc_interface.h>#include <vlc_url.h>#include <vlc_charset.h>#ifdef HAVE_SYS_STAT_H# include <sys/stat.h>#endif/***************************************************************************** * Local prototypes *****************************************************************************/static void Destructor( input_thread_t * p_input );static void* Run ( vlc_object_t *p_this );static void* RunAndDestroy ( vlc_object_t *p_this );static input_thread_t * Create ( vlc_object_t *, input_item_t *, const char *, bool, sout_instance_t * );static int Init ( input_thread_t *p_input );static void WaitDie ( input_thread_t *p_input );static void End ( input_thread_t *p_input );static void MainLoop( input_thread_t *p_input );static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );static void ControlReduce( input_thread_t * );static bool Control( input_thread_t *, int, vlc_value_t );static int UpdateFromAccess( input_thread_t * );static int UpdateFromDemux( input_thread_t * );static void UpdateItemLength( input_thread_t *, int64_t i_length );static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);static input_source_t *InputSourceNew( input_thread_t *);static int InputSourceInit( input_thread_t *, input_source_t *, const char *, const char *psz_forced_demux );static void InputSourceClean( input_source_t * );/* TODO *///static void InputGetAttachments( input_thread_t *, input_source_t * );static void SlaveDemux( input_thread_t *p_input );static void SlaveSeek( input_thread_t *p_input );static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta );static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta );static void DemuxMeta( input_thread_t *p_input, vlc_meta_t *p_meta, demux_t *p_demux );static void AccessMeta( input_thread_t * p_input, vlc_meta_t *p_meta );static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment, int i_new, input_attachment_t **pp_new );/***************************************************************************** * This function creates a new input, and returns a pointer * to its description. On error, it returns NULL. * * Variables for _public_ use: * * Get and Set: * - state * - rate,rate-slower, rate-faster * - position, position-offset * - time, time-offset * - title,title-next,title-prev * - chapter,chapter-next, chapter-prev * - program, audio-es, video-es, spu-es * - audio-delay, spu-delay * - bookmark * * Get only: * - length * - bookmarks * - seekable (if you can seek, it doesn't say if 'bar display' has be shown * or not, for that check position != 0.0) * - can-pause * - teletext-es to get the index of spu track that is teletext --1 if no teletext) * * For intf callback upon changes: * - intf-change * - intf-change-vout for when a vout is created or destroyed * - rate-change for when playback rate changes * TODO explain when Callback is called * TODO complete this list (?) *****************************************************************************/static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item, const char *psz_header, bool b_quick, sout_instance_t *p_sout ){ static const char input_name[] = "input"; input_thread_t *p_input = NULL; /* thread descriptor */ vlc_value_t val; int i; /* Allocate descriptor */ p_input = vlc_custom_create( p_parent, sizeof( *p_input ), VLC_OBJECT_INPUT, input_name ); if( p_input == NULL ) return NULL; /* Construct a nice name for the input timer */ char psz_timer_name[255]; char * psz_name = input_item_GetName( p_item ); snprintf( psz_timer_name, sizeof(psz_timer_name), "input launching for '%s'", psz_name ); msg_Dbg( p_input, "Creating an input for '%s'", psz_name); free( psz_name ); /* Start a timer to mesure how long it takes * to launch an input */ stats_TimerStart( p_input, psz_timer_name, STATS_TIMER_INPUT_LAUNCHING ); MALLOC_NULL( p_input->p, input_thread_private_t ); memset( p_input->p, 0, sizeof( input_thread_private_t ) ); /* One "randomly" selected input thread is responsible for computing * the global stats. Check if there is already someone doing this */ if( p_input->p_libvlc->p_stats && !b_quick ) { libvlc_priv_t *priv = libvlc_priv (p_input->p_libvlc); vlc_mutex_lock( &p_input->p_libvlc->p_stats->lock ); if( priv->p_stats_computer == NULL ) priv->p_stats_computer = p_input; vlc_mutex_unlock( &p_input->p_libvlc->p_stats->lock ); } p_input->b_preparsing = b_quick; p_input->psz_header = psz_header ? strdup( psz_header ) : NULL; /* Init events */ vlc_event_manager_t * p_em = &p_input->p->event_manager; vlc_event_manager_init_with_vlc_object( p_em, p_input ); vlc_event_manager_register_event_type( p_em, vlc_InputStateChanged ); vlc_event_manager_register_event_type( p_em, vlc_InputSelectedStreamChanged ); /* Init Common fields */ p_input->b_eof = false; p_input->b_can_pace_control = true; p_input->p->i_start = 0; p_input->i_time = 0; p_input->p->i_stop = 0; p_input->p->i_run = 0; p_input->p->i_title = 0; p_input->p->title = NULL; p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0; p_input->i_state = INIT_S; p_input->p->i_rate = INPUT_RATE_DEFAULT; TAB_INIT( p_input->p->i_bookmark, p_input->p->bookmark ); TAB_INIT( p_input->p->i_attachment, p_input->p->attachment ); p_input->p->p_es_out = NULL; p_input->p->p_sout = NULL; p_input->p->b_out_pace_control = false; p_input->i_pts_delay = 0; /* Init Input fields */ vlc_gc_incref( p_item ); /* Released in Destructor() */ p_input->p->input.p_item = p_item; p_input->p->input.p_access = NULL; p_input->p->input.p_stream = NULL; p_input->p->input.p_demux = NULL; p_input->p->input.b_title_demux = false; p_input->p->input.i_title = 0; p_input->p->input.title = NULL; p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0; p_input->p->input.b_can_pace_control = true; p_input->p->input.b_can_rate_control = true; p_input->p->input.b_rescale_ts = true; p_input->p->input.b_eof = false; p_input->p->input.i_cr_average = 0; vlc_mutex_lock( &p_item->lock ); if( !p_item->p_stats ) p_item->p_stats = stats_NewInputStats( p_input ); vlc_mutex_unlock( &p_item->lock ); /* No slave */ p_input->p->i_slave = 0; p_input->p->slave = NULL; /* Init control buffer */ vlc_mutex_init( &p_input->p->lock_control ); p_input->p->i_control = 0; /* Parse input options */ vlc_mutex_lock( &p_item->lock ); assert( (int)p_item->optflagc == p_item->i_options ); for( i = 0; i < p_item->i_options; i++ ) var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i], !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) ); vlc_mutex_unlock( &p_item->lock ); /* Create Object Variables for private use only */ input_ConfigVarInit( p_input ); /* Create Objects variables for public Get and Set */ input_ControlVarInit( p_input ); p_input->p->input.i_cr_average = var_GetInteger( p_input, "cr-average" ); if( !p_input->b_preparsing ) { var_Get( p_input, "bookmarks", &val ); if( val.psz_string ) { /* FIXME: have a common cfg parsing routine used by sout and others */ char *psz_parser, *psz_start, *psz_end; psz_parser = val.psz_string; while( (psz_start = strchr( psz_parser, '{' ) ) ) { seekpoint_t *p_seekpoint = vlc_seekpoint_New(); char backup; psz_start++; psz_end = strchr( psz_start, '}' ); if( !psz_end ) break; psz_parser = psz_end + 1; backup = *psz_parser; *psz_parser = 0; *psz_end = ','; while( (psz_end = strchr( psz_start, ',' ) ) ) { *psz_end = 0; if( !strncmp( psz_start, "name=", 5 ) ) { p_seekpoint->psz_name = strdup(psz_start + 5); } else if( !strncmp( psz_start, "bytes=", 6 ) ) { p_seekpoint->i_byte_offset = atoll(psz_start + 6); } else if( !strncmp( psz_start, "time=", 5 ) ) { p_seekpoint->i_time_offset = atoll(psz_start + 5) * 1000000; } psz_start = psz_end + 1; } msg_Dbg( p_input, "adding bookmark: %s, bytes=%"PRId64", time=%"PRId64, p_seekpoint->psz_name, p_seekpoint->i_byte_offset, p_seekpoint->i_time_offset ); input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint ); vlc_seekpoint_Delete( p_seekpoint ); *psz_parser = backup; } free( val.psz_string ); } } /* Remove 'Now playing' info as it is probably outdated */ input_item_SetNowPlaying( p_item, NULL ); /* */ if( p_input->b_preparsing ) p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT; /* */ if( p_sout ) p_input->p->p_sout = p_sout; memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) ); vlc_mutex_init( &p_input->p->counters.counters_lock ); /* Set the destructor when we are sure we are initialized */ vlc_object_set_destructor( p_input, (vlc_destructor_t)Destructor ); /* Attach only once we are ready */ vlc_object_attach( p_input, p_parent ); return p_input;}/** * Input destructor (called when the object's refcount reaches 0). */static void Destructor( input_thread_t * p_input ){ input_thread_private_t *priv = p_input->p;#ifndef NDEBUG char * psz_name = input_item_GetName( p_input->p->input.p_item ); msg_Dbg( p_input, "Destroying the input for '%s'", psz_name); free( psz_name );#endif vlc_event_manager_fini( &p_input->p->event_manager ); stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING ); stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );#ifdef ENABLE_SOUT if( priv->p_sout ) sout_DeleteInstance( priv->p_sout );#endif vlc_gc_decref( p_input->p->input.p_item ); vlc_mutex_destroy( &p_input->p->counters.counters_lock ); vlc_mutex_destroy( &priv->lock_control ); free( priv );}/** * Initialize an input thread and run it. You will need to monitor the * thread to clean up after it is done * * \param p_parent a vlc_object * \param p_item an input item * \return a pointer to the spawned input thread */input_thread_t *__input_CreateThread( vlc_object_t *p_parent, input_item_t *p_item ){ return __input_CreateThreadExtended( p_parent, p_item, NULL, NULL );}/* */input_thread_t *__input_CreateThreadExtended( vlc_object_t *p_parent, input_item_t *p_item, const char *psz_log, sout_instance_t *p_sout ){ input_thread_t *p_input; p_input = Create( p_parent, p_item, psz_log, false, p_sout ); if( !p_input ) return NULL; /* Create thread and wait for its readiness. */ if( vlc_thread_create( p_input, "input", Run, VLC_THREAD_PRIORITY_INPUT, true ) ) { input_ChangeState( p_input, ERROR_S ); msg_Err( p_input, "cannot create input thread" ); vlc_object_detach( p_input ); vlc_object_release( p_input ); return NULL; } return p_input;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -