⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * input.c: input thread ***************************************************************************** * Copyright (C) 1998-2004 the VideoLAN team * $Id: input.c 17365 2006-10-30 08:28:18Z jpsaman $ * * 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 *****************************************************************************/#include <stdlib.h>#include <ctype.h>#include <vlc/vlc.h>#include <vlc/input.h>#include <vlc/decoder.h>#include <vlc/vout.h>#include "input_internal.h"#include "stream_output.h"#include "vlc_playlist.h"#include "vlc_interface.h"#include "vlc_interaction.h"#include "charset.h"/***************************************************************************** * Local prototypes *****************************************************************************/static  int Run  ( input_thread_t *p_input );static  int RunAndClean  ( input_thread_t *p_input );static input_thread_t * Create  ( vlc_object_t *, input_item_t *, char *,                                  vlc_bool_t );static  int             Init    ( input_thread_t *p_input, vlc_bool_t b_quick );static void             Error   ( 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 vlc_bool_t Control( input_thread_t *, int, vlc_value_t );static int  UpdateFromAccess( input_thread_t * );static int  UpdateFromDemux( input_thread_t * );static int  UpdateMeta( input_thread_t *, vlc_bool_t );static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );static void DecodeUrl( char * );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 *,                             char *, char *psz_forced_demux,                             vlc_bool_t b_quick );static void InputSourceClean( input_thread_t *, input_source_t * );static void SlaveDemux( input_thread_t *p_input );static void SlaveSeek( input_thread_t *p_input );static vlc_meta_t *InputMetaUser( input_thread_t *p_input );/***************************************************************************** * 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) * * For intf callback upon changes *  - intf-change * 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,                               char *psz_header, vlc_bool_t b_quick ){    input_thread_t *p_input = NULL;                 /* thread descriptor */    vlc_value_t val;    int i;    /* Allocate descriptor */    p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );    if( p_input == NULL )    {        msg_Err( p_parent, "out of memory" );        return NULL;    }    p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;    /* Init Common fields */    p_input->b_eof = VLC_FALSE;    p_input->b_can_pace_control = VLC_TRUE;    p_input->i_start = 0;    p_input->i_time  = 0;    p_input->i_stop  = 0;    p_input->i_title = 0;    p_input->title   = NULL;    p_input->i_title_offset = p_input->i_seekpoint_offset = 0;    p_input->i_state = INIT_S;    p_input->i_rate  = INPUT_RATE_DEFAULT;    p_input->i_bookmark = 0;    p_input->bookmark = NULL;    p_input->p_meta  = NULL;    p_input->p_es_out = NULL;    p_input->p_sout  = NULL;    p_input->b_out_pace_control = VLC_FALSE;    p_input->i_pts_delay = 0;    /* Init Input fields */    p_input->input.p_item = p_item;    p_input->input.p_access = NULL;    p_input->input.p_stream = NULL;    p_input->input.p_demux  = NULL;    p_input->input.b_title_demux = VLC_FALSE;    p_input->input.i_title  = 0;    p_input->input.title    = NULL;    p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;    p_input->input.b_can_pace_control = VLC_TRUE;    p_input->input.b_eof = VLC_FALSE;    p_input->input.i_cr_average = 0;    stats_ReinitInputStats( p_item->p_stats );    /* No slave */    p_input->i_slave = 0;    p_input->slave   = NULL;    /* Init control buffer */    vlc_mutex_init( p_input, &p_input->lock_control );    p_input->i_control = 0;    /* Parse input options */    vlc_mutex_lock( &p_item->lock );    for( i = 0; i < p_item->i_options; i++ )    {        var_OptionParse( p_input, p_item->ppsz_options[i] );    }    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->input.i_cr_average = var_GetInteger( p_input, "cr-average" );    if( !b_quick )    {        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 = 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="I64Fd", time="I64Fd,                                  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_Control( p_input, INPUT_DEL_INFO, _(VLC_META_INFO_CAT),                   VLC_META_NOW_PLAYING );     /* ? Don't translate as it might has been copied ? */    return p_input;}/** * 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_CreateThread2( p_parent, p_item, NULL );}/* Gruik ! */input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,                                       input_item_t *p_item,                                       char *psz_header ){    input_thread_t *p_input = NULL;      /* thread descriptor */    p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );    if( !p_input )        return NULL;    /* Now we can attach our new input */    vlc_object_attach( p_input, p_parent );    /* Create thread and wait for its readiness. */    if( vlc_thread_create( p_input, "input", Run,                            VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )    {        input_ChangeState( p_input, ERROR_S );        msg_Err( p_input, "cannot create input thread" );        vlc_object_detach( p_input );        vlc_object_destroy( p_input );        return NULL;    }    return p_input;}/** * Initialize an input thread and run it. This thread will clean after himself, * you can forget about it. It can work either in blocking or non-blocking mode * * \param p_parent a vlc_object * \param p_item an input item * \param b_block should we block until read is finished ? * \return the input object id if non blocking, an error code else */int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,                   vlc_bool_t b_block ){    input_thread_t *p_input = NULL;         /* thread descriptor */    p_input = Create( p_parent, p_item, NULL, VLC_FALSE );    if( !p_input )        return VLC_EGENERIC;    /* Now we can attach our new input */    vlc_object_attach( p_input, p_parent );    if( b_block )    {        RunAndClean( p_input );        return VLC_SUCCESS;    }    else    {        if( vlc_thread_create( p_input, "input", RunAndClean,                               VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )        {            input_ChangeState( p_input, ERROR_S );            msg_Err( p_input, "cannot create input thread" );            vlc_object_detach( p_input );            vlc_object_destroy( p_input );            return VLC_EGENERIC;        }    }    return p_input->i_object_id;}/** * Initialize an input and initialize it to preparse the item * This function is blocking. It will only accept to parse files * * \param p_parent a vlc_object_t * \param p_item an input item * \return VLC_SUCCESS or an error */int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item ){    input_thread_t *p_input = NULL;           /* thread descriptor */    /* Allocate descriptor */    p_input = Create( p_parent, p_item, NULL, VLC_TRUE );    if( !p_input )        return VLC_EGENERIC;    p_input->i_flags |= OBJECT_FLAGS_QUIET;    p_input->i_flags |= OBJECT_FLAGS_NOINTERACT;    /* Now we can attach our new input */    vlc_object_attach( p_input, p_parent );    Init( p_input, VLC_TRUE );    /* Clean up master */    InputSourceClean( p_input, &p_input->input );    /* Unload all modules */    if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );    /* Delete meta */    if( p_input->p_meta ) vlc_meta_Delete( p_input->p_meta );    vlc_object_detach( p_input );    vlc_object_destroy( p_input );    return VLC_SUCCESS;}/** * Request a running input thread to stop and die * * \param the input thread to stop */void input_StopThread( input_thread_t *p_input ){    vlc_list_t *p_list;    int i;    /* Set die for input */    p_input->b_die = VLC_TRUE;    /* We cannot touch p_input fields directly (we can from another thread),     * so use the vlc_object_find way, it's perfectly safe */    /* Set die for all access */    p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );    for( i = 0; i < p_list->i_count; i++ )    {        p_list->p_values[i].p_object->b_die = VLC_TRUE;    }    vlc_list_release( p_list );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -