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

📄 dshow.cpp

📁 video linux conference
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * dshow.cpp : DirectShow access module for vlc ***************************************************************************** * Copyright (C) 2002, 2003 VideoLAN * $Id: dshow.cpp 11176 2005-05-27 12:35:57Z xtophe $ * * Author: Gildas Bazin <gbazin@videolan.org> * * 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 <stdio.h>#include <string.h>#include <vlc/vlc.h>#include <vlc/input.h>#include <vlc/vout.h>#include "common.h"#include "filter.h"/***************************************************************************** * Access: local prototypes *****************************************************************************/static block_t *ReadCompressed( access_t * );static int AccessControl ( access_t *, int, va_list );static int Demux       ( demux_t * );static int DemuxControl( demux_t *, int, va_list );static int OpenDevice( vlc_object_t *, access_sys_t *, string, vlc_bool_t );static IBaseFilter *FindCaptureDevice( vlc_object_t *, string *,                                       list<string> *, vlc_bool_t );static size_t EnumDeviceCaps( vlc_object_t *, IBaseFilter *,                              int, int, int, int, int, int,                              AM_MEDIA_TYPE *mt, size_t );static bool ConnectFilters( vlc_object_t *, access_sys_t *,                            IBaseFilter *, CaptureFilter * );static int FindDevicesCallback( vlc_object_t *, char const *,                                vlc_value_t, vlc_value_t, void * );static int ConfigDevicesCallback( vlc_object_t *, char const *,                                  vlc_value_t, vlc_value_t, void * );static void ShowPropertyPage( IUnknown * );static void ShowDeviceProperties( vlc_object_t *, ICaptureGraphBuilder2 *,                                   IBaseFilter *, vlc_bool_t );static void ShowTunerProperties( vlc_object_t *, ICaptureGraphBuilder2 *,                                  IBaseFilter *, vlc_bool_t );static void ConfigTuner( vlc_object_t *, ICaptureGraphBuilder2 *,                         IBaseFilter * );/***************************************************************************** * Module descriptor *****************************************************************************/static char *ppsz_vdev[] = { "", "none" };static char *ppsz_vdev_text[] = { N_("Default"), N_("None") };static char *ppsz_adev[] = { "", "none" };static char *ppsz_adev_text[] = { N_("Default"), N_("None") };static int  pi_tuner_input[] = { 0, 1, 2 };static char *ppsz_tuner_input_text[] =    {N_("Default"), N_("Cable"), N_("Antenna")};#define CACHING_TEXT N_("Caching value in ms")#define CACHING_LONGTEXT N_( \    "Allows you to modify the default caching value for DirectShow streams. " \    "This value should be set in milliseconds units." )#define VDEV_TEXT N_("Video device name")#define VDEV_LONGTEXT N_( \    "You can specify the name of the video device that will be used by the " \    "DirectShow plugin. If you don't specify anything, the default device " \    "will be used.")#define ADEV_TEXT N_("Audio device name")#define ADEV_LONGTEXT N_( \    "You can specify the name of the audio device that will be used by the " \    "DirectShow plugin. If you don't specify anything, the default device " \    "will be used.")#define SIZE_TEXT N_("Video size")#define SIZE_LONGTEXT N_( \    "You can specify the size of the video that will be displayed by the " \    "DirectShow plugin. If you don't specify anything the default size for " \    "your device will be used.")#define CHROMA_TEXT N_("Video input chroma format")#define CHROMA_LONGTEXT N_( \    "Force the DirectShow video input to use a specific chroma format " \    "(eg. I420 (default), RV24, etc.)")#define FPS_TEXT N_("Video input frame rate")#define FPS_LONGTEXT N_( \    "Force the DirectShow video input to use a specific frame rate" \    "(eg. 0 means default, 25, 29.97, 50, 59.94, etc.)")#define CONFIG_TEXT N_("Device properties")#define CONFIG_LONGTEXT N_( \    "Show the properties dialog of the selected device before starting the " \    "stream.")#define TUNER_TEXT N_("Tuner properties")#define TUNER_LONGTEXT N_( \    "Show the tuner properties [channel selection] page." )#define CHANNEL_TEXT N_("Tuner TV Channel")#define CHANNEL_LONGTEXT N_( \    "Allows you to set the TV channel the tuner will set to " \    "(0 means default)." )#define COUNTRY_TEXT N_("Tuner country code")#define COUNTRY_LONGTEXT N_( \    "Allows you to set the tuner country code that establishes the current " \    "channel-to-frequency mapping (0 means default)." )#define TUNER_INPUT_TEXT N_("Tuner input type")#define TUNER_INPUT_LONGTEXT N_( \    "Allows you to select the tuner input type (Cable/Antenna)." )static int  CommonOpen ( vlc_object_t *, access_sys_t *, vlc_bool_t );static void CommonClose( vlc_object_t *, access_sys_t * );static int  AccessOpen ( vlc_object_t * );static void AccessClose( vlc_object_t * );static int  DemuxOpen  ( vlc_object_t * );static void DemuxClose ( vlc_object_t * );vlc_module_begin();    set_shortname( _("DirectShow") );    set_description( _("DirectShow input") );    set_category( CAT_INPUT );    set_subcategory( SUBCAT_INPUT_ACCESS );    add_integer( "dshow-caching", (mtime_t)(0.2*CLOCK_FREQ) / 1000, NULL,                 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );    add_string( "dshow-vdev", NULL, NULL, VDEV_TEXT, VDEV_LONGTEXT, VLC_FALSE);        change_string_list( ppsz_vdev, ppsz_vdev_text, FindDevicesCallback );        change_action_add( FindDevicesCallback, N_("Refresh list") );        change_action_add( ConfigDevicesCallback, N_("Configure") );    add_string( "dshow-adev", NULL, NULL, ADEV_TEXT, ADEV_LONGTEXT, VLC_FALSE);        change_string_list( ppsz_adev, ppsz_adev_text, FindDevicesCallback );        change_action_add( FindDevicesCallback, N_("Refresh list") );        change_action_add( ConfigDevicesCallback, N_("Configure") );    add_string( "dshow-size", NULL, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE);    add_string( "dshow-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,                VLC_TRUE );    add_float( "dshow-fps", 0.0f, NULL, FPS_TEXT, FPS_LONGTEXT,                VLC_TRUE );    add_bool( "dshow-config", VLC_FALSE, NULL, CONFIG_TEXT, CONFIG_LONGTEXT,              VLC_FALSE );    add_bool( "dshow-tuner", VLC_FALSE, NULL, TUNER_TEXT, TUNER_LONGTEXT,              VLC_FALSE );    add_integer( "dshow-tuner-channel", 0, NULL, CHANNEL_TEXT,                 CHANNEL_LONGTEXT, VLC_TRUE );    add_integer( "dshow-tuner-country", 0, NULL, COUNTRY_TEXT,                 COUNTRY_LONGTEXT, VLC_TRUE );    add_integer( "dshow-tuner-input", 0, NULL, TUNER_INPUT_TEXT,                 TUNER_INPUT_LONGTEXT, VLC_TRUE );        change_integer_list( pi_tuner_input, ppsz_tuner_input_text, 0 );    add_shortcut( "dshow" );    set_capability( "access_demux", 0 );    set_callbacks( DemuxOpen, DemuxClose );    add_submodule();    set_description( _("DirectShow input") );    add_shortcut( "dshow" );    set_capability( "access2", 0 );    set_callbacks( AccessOpen, AccessClose );vlc_module_end();/***************************************************************************** * DirectShow elementary stream descriptor *****************************************************************************/typedef struct dshow_stream_t{    string          devicename;    IBaseFilter     *p_device_filter;    CaptureFilter   *p_capture_filter;    AM_MEDIA_TYPE   mt;    union    {      VIDEOINFOHEADER video;      WAVEFORMATEX    audio;    } header;    int             i_fourcc;    es_out_id_t     *p_es;    vlc_bool_t      b_pts;} dshow_stream_t;/***************************************************************************** * DirectShow utility functions *****************************************************************************/static void CreateDirectShowGraph( access_sys_t *p_sys ){    p_sys->i_crossbar_route_depth = 0;    /* Create directshow filter graph */    if( SUCCEEDED( CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,                       (REFIID)IID_IFilterGraph, (void **)&p_sys->p_graph) ) )    {        /* Create directshow capture graph builder if available */        if( SUCCEEDED( CoCreateInstance( CLSID_CaptureGraphBuilder2, 0,                         CLSCTX_INPROC, (REFIID)IID_ICaptureGraphBuilder2,                         (void **)&p_sys->p_capture_graph_builder2 ) ) )        {            p_sys->p_capture_graph_builder2->                SetFiltergraph((IGraphBuilder *)p_sys->p_graph);        }        p_sys->p_graph->QueryInterface( IID_IMediaControl,                                        (void **)&p_sys->p_control );    }}static void DeleteDirectShowGraph( access_sys_t *p_sys ){    DeleteCrossbarRoutes( p_sys );    /* Remove filters from graph */    for( int i = 0; i < p_sys->i_streams; i++ )    {        p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_capture_filter );        p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_device_filter );        p_sys->pp_streams[i]->p_capture_filter->Release();        p_sys->pp_streams[i]->p_device_filter->Release();    }    /* Release directshow objects */    if( p_sys->p_control )    {        p_sys->p_control->Release();        p_sys->p_control = NULL;    }    if( p_sys->p_capture_graph_builder2 )    {        p_sys->p_capture_graph_builder2->Release();        p_sys->p_capture_graph_builder2 = NULL;    }    if( p_sys->p_graph )    {        p_sys->p_graph->Release();        p_sys->p_graph = NULL;    }}/***************************************************************************** * CommonOpen: open direct show device *****************************************************************************/static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys,                       vlc_bool_t b_access_demux ){    vlc_value_t  val;    int i;    /* Get/parse options and open device(s) */    string vdevname, adevname;    int i_width = 0, i_height = 0, i_chroma = 0;    vlc_bool_t b_audio = VLC_TRUE;    var_Create( p_this, "dshow-config", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );    var_Create( p_this, "dshow-tuner", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );    var_Create( p_this, "dshow-vdev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );    var_Get( p_this, "dshow-vdev", &val );    if( val.psz_string ) vdevname = string( val.psz_string );    if( val.psz_string ) free( val.psz_string );    var_Create( p_this, "dshow-adev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );    var_Get( p_this, "dshow-adev", &val );    if( val.psz_string ) adevname = string( val.psz_string );    if( val.psz_string ) free( val.psz_string );    static struct {char *psz_size; int  i_width; int  i_height;} size_table[] =    { { "subqcif", 128, 96 }, { "qsif", 160, 120 }, { "qcif", 176, 144 },      { "sif", 320, 240 }, { "cif", 352, 288 }, { "cif", 640, 480 },      { 0, 0, 0 },    };    var_Create( p_this, "dshow-size", VLC_VAR_STRING | VLC_VAR_DOINHERIT );    var_Get( p_this, "dshow-size", &val );    if( val.psz_string && *val.psz_string )    {        for( i = 0; size_table[i].psz_size; i++ )        {            if( !strcmp( val.psz_string, size_table[i].psz_size ) )            {                i_width = size_table[i].i_width;                i_height = size_table[i].i_height;                break;            }        }        if( !size_table[i].psz_size ) /* Try to parse "WidthxHeight" */        {            char *psz_parser;            i_width = strtol( val.psz_string, &psz_parser, 0 );            if( *psz_parser == 'x' || *psz_parser == 'X')            {                i_height = strtol( psz_parser + 1, &psz_parser, 0 );            }            msg_Dbg( p_this, "Width x Height %dx%d", i_width, i_height );        }    }    if( val.psz_string ) free( val.psz_string );    var_Create( p_this, "dshow-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT );    var_Get( p_this, "dshow-chroma", &val );    if( val.psz_string && strlen( val.psz_string ) >= 4 )    {        i_chroma = VLC_FOURCC( val.psz_string[0], val.psz_string[1],                               val.psz_string[2], val.psz_string[3] );    }    if( val.psz_string ) free( val.psz_string );    var_Create( p_this, "dshow-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );    var_Create( p_this, "dshow-tuner-channel",                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Create( p_this, "dshow-tuner-country",                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Create( p_this, "dshow-tuner-input",                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    var_Create( p_this, "dshow-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );    /* Initialize OLE/COM */    CoInitialize( 0 );    /* Initialize some data */    p_sys->i_streams = 0;    p_sys->pp_streams = 0;    p_sys->i_width = i_width;    p_sys->i_height = i_height;    p_sys->i_chroma = i_chroma;    p_sys->p_graph = NULL;

⌨️ 快捷键说明

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