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

📄 waveout.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * waveout.c : Windows waveOut plugin for vlc ***************************************************************************** * Copyright (C) 2001 the VideoLAN team * $Id: 7b48bf451aa4aeffa2f7eb7212bb677c6c5ba9ac $ * * Authors: 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_aout.h>#include <vlc_charset.h>#include <windows.h>#include <mmsystem.h>#define FRAME_SIZE 4096              /* The size is in samples, not in bytes */#define FRAMES_NUM 8/***************************************************************************** * Useful macros *****************************************************************************/#ifdef UNDER_CE#   define DWORD_PTR DWORD#   ifdef waveOutGetDevCaps#       undef waveOutGetDevCaps        MMRESULT WINAPI waveOutGetDevCaps(UINT, LPWAVEOUTCAPS, UINT);#   endif#endif#ifndef WAVE_FORMAT_IEEE_FLOAT#   define WAVE_FORMAT_IEEE_FLOAT 0x0003#endif#ifndef WAVE_FORMAT_DOLBY_AC3_SPDIF#   define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092#endif#ifndef WAVE_FORMAT_EXTENSIBLE#define  WAVE_FORMAT_EXTENSIBLE   0xFFFE#endif#ifndef SPEAKER_FRONT_LEFT#   define SPEAKER_FRONT_LEFT             0x1#   define SPEAKER_FRONT_RIGHT            0x2#   define SPEAKER_FRONT_CENTER           0x4#   define SPEAKER_LOW_FREQUENCY          0x8#   define SPEAKER_BACK_LEFT              0x10#   define SPEAKER_BACK_RIGHT             0x20#   define SPEAKER_FRONT_LEFT_OF_CENTER   0x40#   define SPEAKER_FRONT_RIGHT_OF_CENTER  0x80#   define SPEAKER_BACK_CENTER            0x100#   define SPEAKER_SIDE_LEFT              0x200#   define SPEAKER_SIDE_RIGHT             0x400#   define SPEAKER_TOP_CENTER             0x800#   define SPEAKER_TOP_FRONT_LEFT         0x1000#   define SPEAKER_TOP_FRONT_CENTER       0x2000#   define SPEAKER_TOP_FRONT_RIGHT        0x4000#   define SPEAKER_TOP_BACK_LEFT          0x8000#   define SPEAKER_TOP_BACK_CENTER        0x10000#   define SPEAKER_TOP_BACK_RIGHT         0x20000#   define SPEAKER_RESERVED               0x80000000#endif#ifndef _WAVEFORMATEXTENSIBLE_typedef struct {    WAVEFORMATEX    Format;    union {        WORD wValidBitsPerSample;       /* bits of precision  */        WORD wSamplesPerBlock;          /* valid if wBitsPerSample==0 */        WORD wReserved;                 /* If neither applies, set to zero. */    } Samples;    DWORD           dwChannelMask;      /* which channels are */                                        /* present in stream  */    GUID            SubFormat;} WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;#endifstatic const GUID __KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = {WAVE_FORMAT_IEEE_FLOAT, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};static const GUID __KSDATAFORMAT_SUBTYPE_PCM = {WAVE_FORMAT_PCM, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};static const GUID __KSDATAFORMAT_SUBTYPE_DOLBY_AC3_SPDIF = {WAVE_FORMAT_DOLBY_AC3_SPDIF, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};/***************************************************************************** * Local prototypes *****************************************************************************/static int  Open         ( vlc_object_t * );static void Close        ( vlc_object_t * );static void Play         ( aout_instance_t * );/***************************************************************************** * notification_thread_t: waveOut event thread *****************************************************************************/typedef struct notification_thread_t{    VLC_COMMON_MEMBERS    aout_instance_t *p_aout;} notification_thread_t;/* local functions */static void Probe        ( aout_instance_t * );static int OpenWaveOut   ( aout_instance_t *, uint32_t,                           int, int, int, int, bool );static int OpenWaveOutPCM( aout_instance_t *, uint32_t,                           int*, int, int, int, bool );static int PlayWaveOut   ( aout_instance_t *, HWAVEOUT, WAVEHDR *,                           aout_buffer_t *, bool );static void CALLBACK WaveOutCallback ( HWAVEOUT, UINT, DWORD, DWORD, DWORD );static void* WaveOutThread( vlc_object_t * );static int VolumeInfos( aout_instance_t *, audio_volume_t * );static int VolumeGet( aout_instance_t *, audio_volume_t * );static int VolumeSet( aout_instance_t *, audio_volume_t );static int WaveOutClearDoneBuffers(aout_sys_t *p_sys);static int ReloadWaveoutDevices( vlc_object_t *, char const *,                                vlc_value_t, vlc_value_t, void * );static uint32_t findDeviceID(char *);static const char psz_device_name_fmt[] = "%s ($%x,$%x)";static const char *const ppsz_adev[] = { "wavemapper", };static const char *const ppsz_adev_text[] = { N_("Microsoft Soundmapper") };/***************************************************************************** * Module descriptor *****************************************************************************/#define FLOAT_TEXT N_("Use float32 output")#define FLOAT_LONGTEXT N_( \    "The option allows you to enable or disable the high-quality float32 " \    "audio output mode (which is not well supported by some soundcards)." )#define DEVICE_TEXT N_("Select Audio Device")#define DEVICE_LONG N_("Select special Audio device, or let windows "\                       "decide (default), change needs VLC restart "\                       "to apply.")#define DEFAULT_AUDIO_DEVICE N_("Default Audio Device")vlc_module_begin();    set_shortname( "WaveOut" );    set_description( N_("Win32 waveOut extension output") );    set_capability( "audio output", 50 );    set_category( CAT_AUDIO );    set_subcategory( SUBCAT_AUDIO_AOUT );    add_bool( "waveout-float32", 1, 0, FLOAT_TEXT, FLOAT_LONGTEXT, true );    add_string( "waveout-dev", "wavemapper", NULL,                 DEVICE_TEXT, DEVICE_LONG, false );       change_string_list( ppsz_adev, ppsz_adev_text, ReloadWaveoutDevices );       change_need_restart();       change_action_add( ReloadWaveoutDevices, N_("Refresh list") );    set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * aout_sys_t: waveOut audio output method descriptor ***************************************************************************** * This structure is part of the audio output thread descriptor. * It describes the waveOut specific properties of an audio device. *****************************************************************************/struct aout_sys_t{    uint32_t i_wave_device_id;               /* ID of selected output device */    HWAVEOUT h_waveout;                        /* handle to waveout instance */    WAVEFORMATEXTENSIBLE waveformat;                         /* audio format */    WAVEHDR waveheader[FRAMES_NUM];    notification_thread_t *p_notif;                      /* WaveOutThread id */    HANDLE event;    HANDLE new_buffer_event;    // rental from alsa.c to synchronize startup of audiothread    int b_playing;                                         /* playing status */    mtime_t start_date;    int i_repeat_counter;    int i_buffer_size;    uint8_t *p_silence_buffer;              /* buffer we use to play silence */    bool b_chan_reorder;              /* do we need channel reordering */    int pi_chan_table[AOUT_CHAN_MAX];};static const uint32_t pi_channels_src[] =    { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,      AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,      AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER,      AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 };static const uint32_t pi_channels_in[] =    { SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT,      SPEAKER_SIDE_LEFT, SPEAKER_SIDE_RIGHT,      SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT, SPEAKER_BACK_CENTER,      SPEAKER_FRONT_CENTER, SPEAKER_LOW_FREQUENCY, 0 };static const uint32_t pi_channels_out[] =    { SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT,      SPEAKER_FRONT_CENTER, SPEAKER_LOW_FREQUENCY,      SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT,      SPEAKER_BACK_CENTER,      SPEAKER_SIDE_LEFT, SPEAKER_SIDE_RIGHT, 0 };/***************************************************************************** * Open: open the audio device ***************************************************************************** * This function opens and setups Win32 waveOut *****************************************************************************/static int Open( vlc_object_t *p_this ){    aout_instance_t *p_aout = (aout_instance_t *)p_this;    vlc_value_t val;    int i;    /* Allocate structure */    p_aout->output.p_sys = malloc( sizeof( aout_sys_t ) );    if( p_aout->output.p_sys == NULL )        return VLC_ENOMEM;    p_aout->output.pf_play = Play;    p_aout->b_die = false;    /*     initialize/update Device selection List    */    ReloadWaveoutDevices( p_this, "waveout-dev", val, val, NULL);    /*      check for configured audio device!    */    char *psz_waveout_dev = var_CreateGetString( p_aout, "waveout-dev");    p_aout->output.p_sys->i_wave_device_id =         findDeviceID( psz_waveout_dev );    if(p_aout->output.p_sys->i_wave_device_id == WAVE_MAPPER)    {       if(psz_waveout_dev &&          stricmp(psz_waveout_dev,"wavemapper"))       {           msg_Warn( p_aout, "configured audio device '%s' not available, "\                         "use default instead", psz_waveout_dev );       }    }    free( psz_waveout_dev );    WAVEOUTCAPS waveoutcaps;    if(waveOutGetDevCaps( p_aout->output.p_sys->i_wave_device_id,                          &waveoutcaps,                          sizeof(WAVEOUTCAPS)) == MMSYSERR_NOERROR)    {      /* log debug some infos about driver, to know who to blame         if it doesn't work */        msg_Dbg( p_aout, "Drivername: %s", waveoutcaps.szPname);        msg_Dbg( p_aout, "Driver Version: %d.%d",                          (waveoutcaps.vDriverVersion>>8)&255,                          waveoutcaps.vDriverVersion & 255);        msg_Dbg( p_aout, "Manufacturer identifier: 0x%x", waveoutcaps.wMid );        msg_Dbg( p_aout, "Product identifier: 0x%x", waveoutcaps.wPid );    }    if( var_Type( p_aout, "audio-device" ) == 0 )    {        Probe( p_aout );    }    if( var_Get( p_aout, "audio-device", &val ) < 0 )    {        /* Probe() has failed. */        var_Destroy( p_aout, "waveout-device");        free( p_aout->output.p_sys );        return VLC_EGENERIC;    }    /* Open the device */    if( val.i_int == AOUT_VAR_SPDIF )    {        p_aout->output.output.i_format = VLC_FOURCC('s','p','d','i');        if( OpenWaveOut( p_aout,                         p_aout->output.p_sys->i_wave_device_id,                         VLC_FOURCC('s','p','d','i'),                         p_aout->output.output.i_physical_channels,                         aout_FormatNbChannels( &p_aout->output.output ),                         p_aout->output.output.i_rate, false )            != VLC_SUCCESS )        {            msg_Err( p_aout, "cannot open waveout audio device" );            free( p_aout->output.p_sys );            return VLC_EGENERIC;        }        /* Calculate the frame size in bytes */        p_aout->output.i_nb_samples = A52_FRAME_NB;        p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE;        p_aout->output.output.i_frame_length = A52_FRAME_NB;        p_aout->output.p_sys->i_buffer_size =            p_aout->output.output.i_bytes_per_frame;        aout_VolumeNoneInit( p_aout );    }    else    {        WAVEOUTCAPS wocaps;        if( val.i_int == AOUT_VAR_5_1 )        {            p_aout->output.output.i_physical_channels                = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER                   | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT                   | AOUT_CHAN_LFE;        }        else if( val.i_int == AOUT_VAR_2F2R )        {            p_aout->output.output.i_physical_channels                = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT                   | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT;        }        else if( val.i_int == AOUT_VAR_MONO )        {            p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER;        }        else        {            p_aout->output.output.i_physical_channels                = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;        }        if( OpenWaveOutPCM( p_aout,                            p_aout->output.p_sys->i_wave_device_id,                            &p_aout->output.output.i_format,                            p_aout->output.output.i_physical_channels,                            aout_FormatNbChannels( &p_aout->output.output ),                            p_aout->output.output.i_rate, false )            != VLC_SUCCESS )        {            msg_Err( p_aout, "cannot open waveout audio device" );            free( p_aout->output.p_sys );            return VLC_EGENERIC;        }        /* Calculate the frame size in bytes */        p_aout->output.i_nb_samples = FRAME_SIZE;        aout_FormatPrepare( &p_aout->output.output );        p_aout->output.p_sys->i_buffer_size = FRAME_SIZE *            p_aout->output.output.i_bytes_per_frame;        aout_VolumeSoftInit( p_aout );        /* Check for hardware volume support */        if( waveOutGetDevCaps( (UINT_PTR)p_aout->output.p_sys->h_waveout,                               &wocaps, sizeof(wocaps) ) == MMSYSERR_NOERROR &&            wocaps.dwSupport & WAVECAPS_VOLUME )        {            DWORD i_dummy;            if( waveOutGetVolume( p_aout->output.p_sys->h_waveout, &i_dummy )                == MMSYSERR_NOERROR )            {                p_aout->output.pf_volume_infos = VolumeInfos;                p_aout->output.pf_volume_get = VolumeGet;                p_aout->output.pf_volume_set = VolumeSet;            }        }    }    waveOutReset( p_aout->output.p_sys->h_waveout );    /* Allocate silence buffer */    p_aout->output.p_sys->p_silence_buffer =        malloc( p_aout->output.p_sys->i_buffer_size );    if( p_aout->output.p_sys->p_silence_buffer == NULL )    {        free( p_aout->output.p_sys );        return 1;    }    p_aout->output.p_sys->i_repeat_counter = 0;    /* Zero the buffer. WinCE doesn't have calloc(). */

⌨️ 快捷键说明

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