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

📄 input.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * input.c: input thread ***************************************************************************** * Copyright (C) 1998-2004 VideoLAN * $Id: input.c 10811 2005-04-26 07:17:42Z fenrir $ * * 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., 59 Temple Place - Suite 330, Boston, MA  02111, 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"/***************************************************************************** * Local prototypes *****************************************************************************/static  int Run  ( input_thread_t *p_input );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 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 ParseOption( input_thread_t *p_input, const char *psz_option );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 );/***************************************************************************** * input_CreateThread: creates a new input thread ***************************************************************************** * 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 (?) *****************************************************************************/input_thread_t *__input_CreateThread( vlc_object_t *p_parent,                                      input_item_t *p_item ){    input_thread_t *p_input;                        /* 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;    }    /* 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;    /* 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++ )    {        ParseOption( 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" );    /* TODO */    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, _("Meta-information"),                   VLC_META_NOW_PLAYING );    /* 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 ) )    {        msg_Err( p_input, "cannot create input thread" );        vlc_object_detach( p_input );        vlc_object_destroy( p_input );        return NULL;    }    return p_input;}/***************************************************************************** * input_PreParse: Lightweight input for playlist item preparsing *****************************************************************************/int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item ){    input_thread_t *p_input;                        /* thread descriptor */    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 VLC_EGENERIC;    }    /* 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;    /* 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++ )    {        ParseOption( p_input, p_item->ppsz_options[i] );    }    vlc_mutex_unlock( &p_item->lock );    /* Create Object Variables for private use only */    input_ConfigVarInit( p_input );    input_ControlVarInit( p_input );    p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );    /* 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 );    /* Kill access and demux */    if( p_input->input.p_access ) p_input->input.p_access->b_die = VLC_TRUE;    if( p_input->input.p_demux ) p_input->input.p_access->b_die = VLC_TRUE;    /* 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;}/***************************************************************************** * input_StopThread: mark an input thread as zombie ***************************************************************************** * This function should not return until the thread is effectively cancelled. *****************************************************************************/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 );    /* Set die for all stream */    p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, 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 );    /* Set die for all demux */    p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, 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 );    input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );}/***************************************************************************** * input_DestroyThread: mark an input thread as zombie

⌨️ 快捷键说明

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