Ticket #4981: 4981-v3.patch

File 4981-v3.patch, 94.7 KB (added by danielk, 12 years ago)

2nd draft with audiosettings.{h,cpp} missing in last patch..

  • libs/libmythtv/NuppelVideoPlayer.cpp

     
    481481bool NuppelVideoPlayer::IsPaused(bool *is_pause_still_possible) const
    482482{
    483483    bool rbf_playing = (ringBuffer != NULL) && !ringBuffer->isPaused();
    484     bool aud_playing = (audioOutput != NULL) && !audioOutput->GetPause();
     484    bool aud_playing = (audioOutput != NULL) && !audioOutput->IsPaused();
    485485    if (is_pause_still_possible)
    486486    {
    487487        bool decoder_pausing = (0.0f == next_play_speed) && !next_normal_speed;
     
    798798
    799799    if (audioOutput)
    800800    {
    801         audioOutput->Reconfigure(audio_bits, audio_channels,
    802                                  audio_samplerate, audio_passthru,
    803                                  audio_codec);
     801        const AudioSettings settings(
     802            audio_bits, audio_channels, audio_samplerate,
     803            audio_passthru, audio_codec);
     804        audioOutput->Reconfigure(settings);
    804805        errMsg = audioOutput->GetError();
    805806        if (!errMsg.isEmpty())
    806807            audioOutput->SetStretchFactor(audio_stretchfactor);
     
    27262727        videoOutput->ProcessFrame(frame, osd, videoFilters, pipplayer);
    27272728    videofiltersLock.unlock();
    27282729
    2729     if (audioOutput && !audio_paused && audioOutput->GetPause())
     2730    if (audioOutput && !audio_paused && audioOutput->IsPaused())
    27302731        audioOutput->Pause(false);
    27312732
    27322733    AVSync();
  • libs/libmyth/audiooutputwin.cpp

     
    7171    }
    7272}
    7373
    74 AudioOutputWin::AudioOutputWin(
    75     QString laudio_main_device,  QString           laudio_passthru_device,
    76     int     laudio_bits,         int               laudio_channels,
    77     int     laudio_samplerate,   AudioOutputSource lsource,
    78     bool    lset_initial_vol,    bool              laudio_passthru) :
    79     AudioOutputBase(laudio_main_device, laudio_passthru_device,
    80                     laudio_bits,        laudio_channels,
    81                     laudio_samplerate,  lsource,
    82                     lset_initial_vol,   laudio_passthru),
     74AudioOutputWin::AudioOutputWin(const AudioSettings &settings) :
     75    AudioOutputBase(settings),
    8376    m_priv(new AudioOutputWinPrivate()),
    8477    m_nPkts(0),
    8578    m_CurrentPkt(0),
    8679    m_OutPkts(NULL)
    8780{
    88     Reconfigure(laudio_bits,       laudio_channels,
    89                 laudio_samplerate, laudio_passthru);
     81    Reconfigure(settings);
    9082
    9183    m_OutPkts = (unsigned char**) calloc(kPacketCnt, sizeof(unsigned char*));
    9284}
     
    193185    m_CurrentPkt++;
    194186}
    195187
    196 int AudioOutputWin::getSpaceOnSoundcard(void)
     188int AudioOutputWin::GetSpaceOnSoundcard(void) const
    197189{
    198190    return (kPacketCnt - m_nPkts) * 1536 * 4;
    199191}
    200192
    201 int AudioOutputWin::getBufferedOnSoundcard(void)
     193int AudioOutputWin::GetBufferedOnSoundcard(void) const
    202194{
    203195    return m_nPkts * 1536 * 4;
    204196}
  • libs/libmyth/audiooutputbase.h

     
    2424class AudioOutputDigitalEncoder;
    2525struct AVCodecContext;
    2626
    27 #define AUDIO_SRC_IN_SIZE   16384
    28 #define AUDIO_SRC_OUT_SIZE (16384*6)
    29 #define AUDIO_TMP_BUF_SIZE (16384*6)
    30 
    31 //#define AUDBUFSIZE 768000
    32 //divisible by 12,10,8,6,4,2 and around 1024000
    33 //#define AUDBUFSIZE 1024080
    34 #define AUDBUFSIZE 1536000
    35 
    3627class AudioOutputBase : public AudioOutput
    3728{
    3829 public:
    39     AudioOutputBase(QString laudio_main_device,
    40                     QString laudio_passthru_device,
    41                     int laudio_bits,
    42                     int laudio_channels, int laudio_samplerate,
    43                     AudioOutputSource lsource,
    44                     bool lset_initial_vol, bool laudio_passthru);
     30    AudioOutputBase(const AudioSettings &settings);
    4531    virtual ~AudioOutputBase();
    4632
    4733    // reconfigure sound out for new params
    48     virtual void Reconfigure(int   audio_bits,
    49                              int   audio_channels,
    50                              int   audio_samplerate,
    51                              bool  audio_passthru,
    52                              void *audio_codec = NULL);
    53    
     34    virtual void Reconfigure(const AudioSettings &settings);
     35
    5436    // do AddSamples calls block?
    5537    virtual void SetBlocking(bool blocking);
    56    
     38
    5739    // dsprate is in 100 * samples/second
    5840    virtual void SetEffDsp(int dsprate);
    5941
    6042    virtual void SetStretchFactor(float factor);
    61     virtual float GetStretchFactor(void);
     43    virtual float GetStretchFactor(void) const;
    6244
    6345    virtual void Reset(void);
    6446
     
    6749    virtual bool AddSamples(char *buffers[], int samples, long long timecode);
    6850
    6951    virtual void SetTimecode(long long timecode);
    70     virtual bool GetPause(void);
     52    virtual bool IsPaused(void) const { return audio_actually_paused; }
    7153    virtual void Pause(bool paused);
    7254
    7355    // Wait for all data to finish playing
    7456    virtual void Drain(void);
    75  
    76     virtual int GetAudiotime(void);
    7757
     58    virtual int GetAudiotime(void) const;
     59
    7860    // Send output events showing current progress
    7961    virtual void Status(void);
    8062
    8163    virtual void SetSourceBitrate(int rate);
    8264
    83     virtual void GetBufferStatus(uint &fill, uint &total);
     65    virtual void GetBufferStatus(uint &fill, uint &total) const;
    8466
    8567    //  Only really used by the AudioOutputNULL object
    86    
     68
    8769    virtual void bufferOutputData(bool y){ buffer_output_data_for_use = y; }
    8870    virtual int readOutputData(unsigned char *read_buffer, int max_length);
    89    
    90  protected:
    9171
     72    static const uint kAudioSourceInputSize  = 16384;
     73    static const uint kAudioSourceOutputSize = (16384*6);
     74    static const uint kAudioTempBufSize      = (16384*6);
     75    /// Audio Buffer Size -- should be divisible by 12,10,8,6,4,2..
     76    static const uint kAudioRingBufferSize   = 1536000;
     77
     78 protected:
    9279    // You need to implement the following functions
    9380    virtual bool OpenDevice(void) = 0;
    9481    virtual void CloseDevice(void) = 0;
    9582    virtual void WriteAudio(unsigned char *aubuf, int size) = 0;
    96     virtual int getSpaceOnSoundcard(void) = 0;
    97     virtual int getBufferedOnSoundcard(void) = 0;
    98     virtual int GetVolumeChannel(int channel) = 0; // Returns 0-100
    99     virtual void SetVolumeChannel(int channel, int volume) = 0; // range 0-100 for vol
     83    virtual int  GetSpaceOnSoundcard(void) const = 0;
     84    virtual int  GetBufferedOnSoundcard(void) const = 0;
     85    /// You need to call this from any implementation in the dtor.
     86    void KillAudio(void);
    10087
    10188    // The following functions may be overridden, but don't need to be
    10289    virtual bool StartOutputThread(void);
     
    10592    int GetAudioData(unsigned char *buffer, int buf_size, bool fill_buffer);
    10693
    10794    void _AddSamples(void *buffer, bool interleaved, int samples, long long timecode);
    108  
    109     void KillAudio();
     95
    11096    void OutputAudioLoop(void);
    11197    static void *kickoffOutputAudioLoop(void *player);
    11298    void SetAudiotime(void);
    11399    int WaitForFreeSpace(int len);
    114100
    115     int audiolen(bool use_lock); // number of valid bytes in audio buffer
    116     int audiofree(bool use_lock); // number of free bytes in audio buffer
     101    int audiolen(bool use_lock) const; // number of valid bytes in audio buffer
     102    int audiofree(bool use_lock) const; // number of free bytes in audio buffer
    117103
    118104    void UpdateVolume(void);
    119    
     105
    120106    void SetStretchFactorLocked(float factor);
    121107
    122108    int GetBaseAudioTime()                    const { return audiotime;       }
     
    124110    soundtouch::SoundTouch *GetSoundStretch() const { return pSoundStretch;   }
    125111    void SetBaseAudioTime(const int inAudioTime) { audiotime = inAudioTime; }
    126112
     113  protected:
    127114    int effdsp; // from the recorded stream
    128115    int effdspstretched; // from the recorded stream
    129116
     
    132119    int audio_bytes_per_sample;
    133120    int audio_bits;
    134121    int audio_samplerate;
    135     int audio_buffer_unused;
     122    mutable int audio_buffer_unused; ///< set on error conditions
    136123    int fragment_size;
    137124    long soundcard_buffer_size;
    138125    QString audio_main_device;
     
    149136    bool pauseaudio, audio_actually_paused, was_paused;
    150137    bool set_initial_vol;
    151138    bool buffer_output_data_for_use; //  used by AudioOutputNULL
    152    
     139
    153140    int configured_audio_channels;
    154141
    155142 private:
    156143    // resampler
    157144    bool need_resampler;
    158145    SRC_STATE *src_ctx;
    159     SRC_DATA src_data;
    160     float src_in[AUDIO_SRC_IN_SIZE];
    161     float src_out[AUDIO_SRC_OUT_SIZE];
    162     short tmp_buff[AUDIO_TMP_BUF_SIZE];
    163146
    164147    // timestretch
    165148    soundtouch::SoundTouch    *pSoundStretch;
     
    175158
    176159    int lastaudiolen;
    177160    long long samples_buffered;
    178    
     161
    179162    bool audio_thread_exists;
    180163    pthread_t audio_thread;
    181164
    182     pthread_mutex_t audio_buflock; /* adjustments to audiotimecode, waud, and
    183                                       raud can only be made while holding this
    184                                       lock */
    185     pthread_cond_t audio_bufsig;  /* condition is signaled when the buffer
    186                                      gets more free space. Must be holding
    187                                      audio_buflock to use. */
     165    /** adjustments to audiotimecode, waud, and raud can only be made
     166        while holding this lock */
     167    mutable pthread_mutex_t audio_buflock;
    188168
    189     pthread_mutex_t avsync_lock; /* must hold avsync_lock to read or write
    190                                     'audiotime' and 'audiotime_updated' */
     169    /** condition is signaled when the buffer gets more free space.
     170        Must be holding audio_buflock to use. */
     171    pthread_cond_t audio_bufsig;
     172
     173    /** must hold avsync_lock to read or write 'audiotime' and
     174        'audiotime_updated' */
     175    mutable pthread_mutex_t avsync_lock;
     176
    191177    /// timecode of audio leaving the soundcard (same units as timecodes)
    192178    long long audiotime;
    193179    struct timeval audiotime_updated; // ... which was last updated at this time
    194180
    195181    /* Audio circular buffer */
    196     unsigned char audiobuffer[AUDBUFSIZE];  /* buffer */
    197182    int raud, waud;     /* read and write positions */
    198183    /// timecode of audio most recently placed into buffer
    199184    long long audbuf_timecode;
     
    203188    QMutex killAudioLock;
    204189
    205190    long current_seconds;
    206     long source_bitrate;   
    207    
     191    long source_bitrate;
    208192
     193    // All actual buffers
     194    SRC_DATA src_data;
     195    uint memory_corruption_test0;
     196    float src_in[kAudioSourceInputSize];
     197    uint memory_corruption_test1;
     198    float src_out[kAudioSourceOutputSize];
     199    uint memory_corruption_test2;
     200    short tmp_buff[kAudioTempBufSize];
     201    uint memory_corruption_test3;
     202    /** main audio buffer */
     203    unsigned char audiobuffer[kAudioRingBufferSize];
     204    uint memory_corruption_test4;
    209205};
    210206
    211207#endif
  • libs/libmyth/audiooutputalsa.cpp

     
    1313#define LOC_WARN QString("ALSA, Warning: ")
    1414#define LOC_ERR QString("ALSA, Error: ")
    1515
    16 AudioOutputALSA::AudioOutputALSA(
    17     QString laudio_main_device, QString           laudio_passthru_device,
    18     int     laudio_bits,        int               laudio_channels,
    19     int     laudio_samplerate,  AudioOutputSource lsource,
    20     bool    lset_initial_vol,   bool              laudio_passthru) :
    21     AudioOutputBase(laudio_main_device, laudio_passthru_device,
    22                     laudio_bits,        laudio_channels,
    23                     laudio_samplerate,  lsource,
    24                     lset_initial_vol,   laudio_passthru),
     16AudioOutputALSA::AudioOutputALSA(const AudioSettings &settings) :
     17    AudioOutputBase(settings),
    2518    pcm_handle(NULL),             numbadioctls(0),
    2619    killAudioLock(false),         mixer_handle(NULL),
    27     mixer_control(QString::null), volume_range_multiplier(1.0f),
    28     playback_vol_min(0),          playback_vol_max(1)
     20    mixer_control(QString::null)
    2921{
    3022    // Set everything up
    31     Reconfigure(laudio_bits,       laudio_channels,
    32                 laudio_samplerate, laudio_passthru);
     23    Reconfigure(settings);
    3324}
    3425
    3526AudioOutputALSA::~AudioOutputALSA()
     
    236227    }
    237228}
    238229
    239 inline int AudioOutputALSA::getBufferedOnSoundcard(void)
     230int AudioOutputALSA::GetBufferedOnSoundcard(void) const
    240231{
    241232    if (pcm_handle == NULL)
    242233    {
     
    265256}
    266257
    267258
    268 inline int AudioOutputALSA::getSpaceOnSoundcard(void)
     259int AudioOutputALSA::GetSpaceOnSoundcard(void) const
    269260{
    270261    if (pcm_handle == NULL)
    271262    {
    272         VERBOSE(VB_IMPORTANT, QString("getSpaceOnSoundcard() called with pcm_handle == NULL!"));
     263        VERBOSE(VB_IMPORTANT, QString("GetSpaceOnSoundcard() ") +
     264                "called with pcm_handle == NULL!");
     265
    273266        return 0;
    274267    }
    275268
     
    477470}
    478471
    479472
    480 int AudioOutputALSA::GetVolumeChannel(int channel)
     473int AudioOutputALSA::GetVolumeChannel(int channel) const
    481474{
    482     long actual_volume, volume;
     475    long actual_volume;
    483476
    484477    if (mixer_handle == NULL)
    485478        return 100;
     
    509502        }
    510503    }
    511504
    512     GetVolumeRange(elem);
     505    ALSAVolumeInfo vinfo = GetVolumeRange(elem);
    513506
    514     snd_mixer_selem_get_playback_volume(elem, (snd_mixer_selem_channel_id_t)channel,
    515                                         &actual_volume);
    516     volume = (int)((actual_volume - playback_vol_min) *
    517                    volume_range_multiplier);
     507    snd_mixer_selem_get_playback_volume(
     508        elem, (snd_mixer_selem_channel_id_t)channel, &actual_volume);
    518509
    519     return volume;
     510    return vinfo.ToMythRange(actual_volume);
    520511}
     512
    521513void AudioOutputALSA::SetVolumeChannel(int channel, int volume)
    522514{
    523515    SetCurrentVolume(mixer_control, channel, volume);
     
    557549        }
    558550    }
    559551
    560     GetVolumeRange(elem);
     552    ALSAVolumeInfo vinfo = GetVolumeRange(elem);
    561553
    562     int set_vol = (int)(volume / volume_range_multiplier +
    563                         playback_vol_min + 0.5);
     554    long set_vol = vinfo.ToALSARange(volume);
    564555
    565556    int err = snd_mixer_selem_set_playback_volume(elem, chan, set_vol);
    566557    if (err < 0)
     
    677668    }
    678669}
    679670
    680 void AudioOutputALSA::GetVolumeRange(snd_mixer_elem_t *elem)
     671ALSAVolumeInfo AudioOutputALSA::GetVolumeRange(snd_mixer_elem_t *elem) const
    681672{
    682     snd_mixer_selem_get_playback_volume_range(elem, &playback_vol_min,
    683                                               &playback_vol_max);
    684     volume_range_multiplier = (100.0 / (float)(playback_vol_max -
    685                                                playback_vol_min));
     673    long volume_min, volume_max;
    686674
     675    int err = snd_mixer_selem_get_playback_volume_range(
     676        elem, &volume_min, &volume_max);
     677
     678    if (err < 0)
     679    {
     680        static bool first_time = true;
     681        if (first_time)
     682        {
     683            VERBOSE(VB_IMPORTANT,
     684                    "snd_mixer_selem_get_playback_volume_range()" + ENO);
     685            first_time = false;
     686        }
     687    }
     688
     689    ALSAVolumeInfo vinfo(volume_min, volume_max);
     690
    687691    VERBOSE(VB_AUDIO, QString("Volume range is %1 to %2, mult=%3")
    688             .arg(playback_vol_min).arg(playback_vol_max)
    689             .arg(volume_range_multiplier));
     692            .arg(vinfo.volume_min).arg(vinfo.volume_max)
     693            .arg(vinfo.range_multiplier));
     694
     695    return vinfo;
    690696}
    691 
  • libs/libmyth/volumebase.cpp

     
    55using namespace std;
    66#include "volumebase.h"
    77
    8 VolumeBase::VolumeBase()
     8VolumeBase::VolumeBase() :
     9    internal_vol(false), volume(80), current_mute_state(MUTE_OFF)
    910{
    10     volume = 80;
    11     current_mute_state=MUTE_OFF;
    12     internal_vol = false;
    13 };
     11}
    1412
    15 int VolumeBase::GetCurrentVolume(void)
     13int VolumeBase::GetCurrentVolume(void) const
    1614{
    1715    return volume;
    1816}
     
    5856    SetMute(current_mute_state == MUTE_OFF);
    5957}
    6058
    61 kMuteState VolumeBase::GetMute(void)
     59kMuteState VolumeBase::GetMute(void) const
    6260{
    6361    return current_mute_state;
    6462}
  • libs/libmyth/volumebase.h

     
    2020    VolumeBase();   
    2121    virtual ~VolumeBase() {};
    2222
    23     virtual int GetCurrentVolume(void);
     23    virtual int  GetCurrentVolume(void) const;
    2424    virtual void SetCurrentVolume(int value);
    2525    virtual void AdjustCurrentVolume(int change);
    2626    virtual void SetMute(bool on);
    2727    virtual void ToggleMute(void);
    28     virtual kMuteState GetMute(void);
     28    virtual kMuteState GetMute(void) const;
    2929    virtual kMuteState IterateMutedChannels(void);
    3030
    3131 protected:
    3232
    33     virtual int GetVolumeChannel(int channel) = 0; // Returns 0-100
     33    virtual int GetVolumeChannel(int channel) const = 0; // Returns 0-100
    3434    virtual void SetVolumeChannel(int channel, int volume) = 0; // range 0-100 for vol
    3535
    3636    void UpdateVolume(void);
  • libs/libmyth/audiooutputarts.cpp

     
    77#include "mythcontext.h"
    88#include "audiooutputarts.h"
    99
    10 AudioOutputARTS::AudioOutputARTS(
    11     QString laudio_main_device,     QString laudio_passthru_device,
    12     int     laudio_bits,            int     laudio_channels,
    13     int     laudio_samplerate,      AudioOutputSource lsource,
    14     bool    lset_initial_vol,       bool    laudio_passthru) :
    15     AudioOutputBase(laudio_main_device, laudio_passthru_device,
    16                     laudio_bits,        laudio_channels,
    17                     laudio_samplerate,  lsource,
    18                     lset_initial_vol,   laudio_passthru),
     10AudioOutputARTS::AudioOutputARTS(const AudioSettings &settings) :
     11    AudioOutputBase(settings),
    1912    pcm_handle(NULL), buff_size(-1), can_hw_pause(false)
    2013{
    2114    // Set everything up
    22     Reconfigure(laudio_bits,       laudio_channels,
    23                 laudio_samplerate, laudio_passthru);
     15    Reconfigure(settings);
    2416}
    2517
    2618AudioOutputARTS::~AudioOutputARTS()
     
    8880    }
    8981}
    9082
    91 inline int AudioOutputARTS::getBufferedOnSoundcard(void)
     83int AudioOutputARTS::GetBufferedOnSoundcard(void) const
    9284{
    93     return buff_size - getSpaceOnSoundcard();
     85    return buff_size - GetSpaceOnSoundcard();
    9486}
    9587
    96 inline int AudioOutputARTS::getSpaceOnSoundcard(void)
     88int AudioOutputARTS::GetSpaceOnSoundcard(void) const
    9789{
    9890    return arts_stream_get(pcm_handle, ARTS_P_BUFFER_SIZE);
    9991}
    10092
    101 int AudioOutputARTS::GetVolumeChannel(int /*channel*/)
     93int AudioOutputARTS::GetVolumeChannel(int /*channel*/) const
    10294{
    10395    // Do nothing
    10496    return 100;
  • libs/libmyth/volumecontrol.h

     
    1 #ifndef VOLUMECONTROL_H_
    2 #define VOLUMECONTROL_H_
    3 
    4 typedef enum { MUTE_OFF=0, MUTE_LEFT, MUTE_RIGHT, MUTE_BOTH } kMuteState;
    5 
    6 class VolumeControl
    7 {
    8   public:
    9     VolumeControl(bool setstartingvolume = true);
    10    ~VolumeControl();
    11 
    12     int GetCurrentVolume(void);
    13     void SetCurrentVolume(int value);
    14     void AdjustCurrentVolume(int change);
    15 
    16     void SetMute(bool on);
    17     void ToggleMute(void);
    18     bool GetMute(void) { return mute; }
    19     kMuteState IterateMutedChannels(void);
    20 
    21   private:
    22     int mixerfd;
    23     int volume;
    24     int internal_volume;
    25     int control;
    26 
    27     bool mute;
    28     kMuteState current_mute_state;
    29 };
    30 
    31 #endif
  • libs/libmyth/audiooutputnull.cpp

     
    2020#include "mythcontext.h"
    2121#include "audiooutputnull.h"
    2222
    23 AudioOutputNULL::AudioOutputNULL(
    24     QString laudio_main_device, QString           laudio_passthru_device,
    25     int     laudio_bits,        int               laudio_channels,
    26     int     laudio_samplerate,  AudioOutputSource lsource,
    27     bool    lset_initial_vol,   bool              laudio_passthru) :
    28     AudioOutputBase(laudio_main_device, laudio_passthru_device,
    29                     laudio_bits,        laudio_channels,
    30                     laudio_samplerate,  lsource,
    31                     lset_initial_vol,   laudio_passthru),
     23AudioOutputNULL::AudioOutputNULL(const AudioSettings &settings) :
     24    AudioOutputBase(settings),
    3225    pcm_output_buffer_mutex(false),
    3326    current_buffer_size(0),
    34     locked_audio_channels(laudio_channels),
    35     locked_audio_bits(laudio_bits),
    36     locked_audio_samplerate(laudio_samplerate)
     27    locked_audio_channels(settings.channels),
     28    locked_audio_bits(settings.bits),
     29    locked_audio_samplerate(settings.samplerate)
    3730{
    3831    bzero(pcm_output_buffer, sizeof(char) * NULLAUDIO_OUTPUT_BUFFER_SIZE);
    3932
    40     Reconfigure(laudio_bits,       laudio_channels,
    41                 laudio_samplerate, laudio_passthru);
     33    Reconfigure(settings);
    4234}
    4335
    4436AudioOutputNULL::~AudioOutputNULL()
     
    111103    AudioOutputBase::Reset();
    112104}
    113105
    114 inline int AudioOutputNULL::getBufferedOnSoundcard(void)
     106int AudioOutputNULL::GetBufferedOnSoundcard(void) const
    115107{
    116108    if (buffer_output_data_for_use)
    117109    {
     
    122114}
    123115
    124116
    125 inline int AudioOutputNULL::getSpaceOnSoundcard(void)
     117int AudioOutputNULL::GetSpaceOnSoundcard(void) const
    126118{
    127119    if (buffer_output_data_for_use)
    128120    {
  • libs/libmyth/audiooutputjack.h

     
    1212class AudioOutputJACK : public AudioOutputBase
    1313{
    1414  public:
    15     AudioOutputJACK(QString laudio_main_device,
    16                     QString laudio_passthru_device,
    17                     int laudio_bits,
    18                     int laudio_channels, int laudio_samplerate,
    19                     AudioOutputSource lsource,
    20                     bool lset_initial_vol, bool laudio_passthru);
     15    AudioOutputJACK(const AudioSettings &settings);
    2116    virtual ~AudioOutputJACK();
    2217   
    2318    // Volume control
    24     virtual int GetVolumeChannel(int channel); // Returns 0-100
     19    virtual int GetVolumeChannel(int channel) const; // Returns 0-100
    2520    virtual void SetVolumeChannel(int channel, int volume); // range 0-100 for vol
    2621 
    2722  protected:
     
    3025    virtual bool OpenDevice(void);
    3126    virtual void CloseDevice(void);
    3227    virtual void WriteAudio(unsigned char *aubuf, int size);
    33     virtual inline int getSpaceOnSoundcard(void);
    34     virtual inline int getBufferedOnSoundcard(void);
     28    virtual int  GetSpaceOnSoundcard(void) const;
     29    virtual int  GetBufferedOnSoundcard(void) const;
    3530
    3631  private:
    3732
  • libs/libmyth/audiosettings.cpp

     
     1/* -*- Mode: c++ -*-
     2 *
     3 * Copyright (C) Daniel Kristjansson 2008
     4 *
     5 * Licensed under the GPL v2 or a later version at your choosing.
     6 */
     7
     8#include <qdeepcopy.h>
     9
     10#include "audiosettings.h"
     11
     12AudioSettings::AudioSettings() :
     13    main_device(QString::null),
     14    passthru_device(QString::null),
     15    bits(-1),
     16    channels(-1),
     17    samplerate(-1),
     18    set_initial_vol(false),
     19    use_passthru(false),
     20    codec(NULL),
     21    source(AUDIOOUTPUT_UNKNOWN)
     22{
     23}
     24
     25AudioSettings::AudioSettings(const AudioSettings &other) :
     26    main_device(other.main_device),
     27    passthru_device(other.passthru_device),
     28    bits(other.bits),
     29    channels(other.channels),
     30    samplerate(other.samplerate),
     31    set_initial_vol(other.set_initial_vol),
     32    use_passthru(other.use_passthru),
     33    codec(other.codec),
     34    source(other.source)
     35{
     36}
     37
     38AudioSettings::AudioSettings(
     39    const QString &audio_main_device,
     40    const QString &audio_passthru_device,
     41    int audio_bits,
     42    int audio_channels,
     43    int audio_samplerate,
     44    AudioOutputSource audio_source,
     45    bool audio_set_initial_vol,
     46    bool audio_use_passthru,
     47    void *audio_codec) :
     48    main_device(audio_main_device),
     49    passthru_device(audio_passthru_device),
     50    bits(audio_bits),
     51    channels(audio_channels),
     52    samplerate(audio_samplerate),
     53    set_initial_vol(audio_set_initial_vol),
     54    use_passthru(audio_use_passthru),
     55    codec(audio_codec),
     56    source(audio_source)
     57{
     58}
     59
     60AudioSettings::AudioSettings(
     61    int   audio_bits,
     62    int   audio_channels,
     63    int   audio_samplerate,
     64    bool  audio_use_passthru,
     65    void *audio_codec) :
     66    main_device(QString::null),
     67    passthru_device(QString::null),
     68    bits(audio_bits),
     69    channels(audio_channels),
     70    samplerate(audio_samplerate),
     71    set_initial_vol(false),
     72    use_passthru(audio_use_passthru),
     73    codec(audio_codec),
     74    source(AUDIOOUTPUT_UNKNOWN)
     75{
     76}
     77
     78void AudioSettings::FixPassThrough(void)
     79{
     80    if (passthru_device.isEmpty() || passthru_device.lower() == "default")
     81        passthru_device = GetMainDevice();
     82}
     83
     84void AudioSettings::TrimDeviceType(void)
     85{
     86    main_device.remove(0, 5);
     87    passthru_device.remove(0, 5);
     88}
     89
     90QString AudioSettings::GetMainDevice(void) const
     91{
     92    return QDeepCopy<QString>(main_device);
     93}
     94
     95QString AudioSettings::GetPassthruDevice(void) const
     96{
     97    return QDeepCopy<QString>(passthru_device);
     98}
     99
  • libs/libmyth/audiooutputca.cpp

     
    111111 *  \brief Implements Core Audio (Mac OS X Hardware Abstraction Layer) output.
    112112 */
    113113
    114 AudioOutputCA::AudioOutputCA(QString laudio_main_device,
    115                              QString laudio_passthru_device,
    116                              int laudio_bits, int laudio_channels,
    117                              int laudio_samplerate,
    118                              AudioOutputSource lsource,
    119                              bool lset_initial_vol, bool laudio_passthru)
    120     : AudioOutputBase(laudio_main_device, laudio_passthru_device,
    121                       laudio_bits,        laudio_channels,
    122                       laudio_samplerate,  lsource,
    123                       lset_initial_vol,   laudio_passthru),
     114AudioOutputCA::AudioOutputCA(const AudioSettings &settings)
     115    : AudioOutputBase(settings),
    124116      d(new CoreAudioData(this))
    125117{
    126     Reconfigure(laudio_bits, laudio_channels,
    127                 laudio_samplerate, laudio_passthru);
     118    Reconfigure(settings);
    128119}
    129120
    130121AudioOutputCA::~AudioOutputCA()
     
    320311    return;     // unneeded and unused in CA
    321312}
    322313
    323 int AudioOutputCA::getSpaceOnSoundcard(void)
     314int AudioOutputCA::GetSpaceOnSoundcard(void) const
    324315{
    325316    return 0;   // unneeded and unused in CA
    326317}
    327318
    328 int AudioOutputCA::getBufferedOnSoundcard(void)
     319int AudioOutputCA::GetBufferedOnSoundcard(void) const
    329320{
    330321    return bufferedBytes;
    331322}
     
    333324/** Reimplement the base class's version of GetAudiotime()
    334325 *  so that we don't use gettimeofday or pthread mutexes.
    335326 */
    336 int AudioOutputCA::GetAudiotime(void)
     327int AudioOutputCA::GetAudiotime(void) const
    337328{
    338329    int ret;
    339330
  • libs/libmyth/audiooutputwin.h

     
    1313{
    1414  friend class AudioOutputWinPrivate;
    1515  public:
    16     AudioOutputWin(QString laudio_main_device,
    17                    QString laudio_passthru_device,
    18                    int laudio_bits,
    19                    int laudio_channels, int laudio_samplerate,
    20                    AudioOutputSource lsource,
    21                    bool lset_initial_vol, bool laudio_passthru);
     16    AudioOutputWin(const AudioSettings &settings);
    2217    virtual ~AudioOutputWin();
    2318
    2419    // Volume control
    25     virtual int  GetVolumeChannel(int channel);
     20    virtual int  GetVolumeChannel(int channel) const;
    2621    virtual void SetVolumeChannel(int channel, int volume);
    2722
    2823  protected:
    2924    virtual bool OpenDevice(void);
    3025    virtual void CloseDevice(void);
    3126    virtual void WriteAudio(unsigned char *aubuf, int size);
    32     virtual inline int getSpaceOnSoundcard(void);
    33     virtual inline int getBufferedOnSoundcard(void);
     27    virtual int  GetSpaceOnSoundcard(void) const;
     28    virtual int  GetBufferedOnSoundcard(void) const;
    3429
    3530  protected:
    3631    AudioOutputWinPrivate *m_priv;
  • libs/libmyth/volumecontrol.cpp

     
    1 #include "volumecontrol.h"
    2 #include "config.h"
    3 
    4 #ifdef USING_OSS
    5     #include <sys/ioctl.h>
    6     #ifdef HAVE_SYS_SOUNDCARD_H
    7         #include <sys/soundcard.h>
    8     #elif HAVE_SOUNDCARD_H
    9         #include <soundcard.h>
    10     #endif
    11 #endif
    12 
    13 #include <fcntl.h>
    14 #include <cstdio>
    15 #include <unistd.h>
    16 
    17 #include <iostream>
    18 using namespace std;
    19 
    20 #include "mythcontext.h"
    21 
    22 VolumeControl::VolumeControl(bool setstartingvolume)
    23 {
    24     (void) setstartingvolume;
    25 
    26     mixerfd = -1;
    27     volume = 0;
    28 
    29 #ifdef USING_OSS
    30     mute = false;
    31     current_mute_state = MUTE_OFF;
    32  
    33     QString device = gContext->GetSetting("MixerDevice", "/dev/mixer");
    34     mixerfd = open(device.ascii(), O_RDONLY);
    35 
    36     QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
    37 
    38     if (controlLabel == "Master")
    39     {
    40         control = SOUND_MIXER_VOLUME;
    41     }
    42     else
    43     {
    44         control = SOUND_MIXER_PCM;
    45     }
    46 
    47     if (mixerfd < 0)
    48     {
    49         cerr << "Unable to open mixer: '" << device << "'\n";
    50         return;
    51     }
    52 
    53     int realvol;
    54 
    55     if (setstartingvolume)
    56     {
    57         volume = gContext->GetNumSetting("MasterMixerVolume", 80);
    58         realvol = (volume << 8) + volume;
    59         int ret = ioctl(mixerfd, MIXER_WRITE(SOUND_MIXER_VOLUME), &realvol);
    60         if (ret < 0)
    61             perror("Setting master volume: ");
    62 
    63         volume = gContext->GetNumSetting("PCMMixerVolume", 80);
    64         realvol = (volume << 8) + volume;
    65         ret = ioctl(mixerfd, MIXER_WRITE(SOUND_MIXER_PCM), &realvol);
    66         if (ret < 0)
    67             perror("Setting PCM volume: ");
    68     }
    69 
    70     internal_volume = GetCurrentVolume();
    71 #endif
    72 }
    73 
    74 VolumeControl::~VolumeControl()
    75 {
    76     if (mixerfd >= 0)
    77         close(mixerfd);
    78 }
    79 
    80 int VolumeControl::GetCurrentVolume(void)
    81 {
    82 #ifdef USING_OSS
    83     int realvol;
    84    
    85     if (mute)
    86     {
    87         return internal_volume;
    88     }
    89     else
    90     {
    91         int ret = ioctl(mixerfd, MIXER_READ(control), &realvol);
    92         if (ret < 0)
    93         {
    94             perror("Reading PCM volume: ");
    95         }
    96         volume = realvol & 0xff; // just use the left channel
    97         internal_volume = volume;
    98     }
    99 #endif   
    100 
    101     return volume;
    102 }
    103 
    104 void VolumeControl::SetCurrentVolume(int value)
    105 {
    106     (void) value;
    107 
    108 #ifdef USING_OSS
    109     volume = value;
    110 
    111     if (volume > 100)
    112         volume = 100;
    113     if (volume < 0)
    114         volume = 0;
    115 
    116     internal_volume = volume;
    117     if (mixerfd >= 0)
    118     {
    119         if (!mute)
    120         {
    121             int realvol = (volume << 8) + volume;
    122             int ret = ioctl(mixerfd, MIXER_WRITE(control), &realvol);
    123             if (ret < 0)
    124                 perror("Setting volume: ");
    125         }
    126     }
    127 
    128     //mute = false;
    129 
    130     QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
    131     controlLabel += "MixerVolume";
    132     gContext->SaveSetting(controlLabel, volume);
    133 #endif
    134 }
    135 
    136 void VolumeControl::AdjustCurrentVolume(int change)
    137 {
    138     int newvol = GetCurrentVolume() + change;
    139 
    140     SetCurrentVolume(newvol);
    141 }
    142 
    143 void VolumeControl::SetMute(bool on)
    144 {
    145     (void) on;
    146 
    147 #ifdef USING_OSS
    148     int realvol;
    149 
    150     if (on)
    151     {
    152         realvol = 0;
    153     }
    154     else
    155     {
    156         realvol = (internal_volume << 8) + internal_volume;
    157     }
    158     if (mixerfd >= 0)
    159     {
    160         int ret = ioctl(mixerfd, MIXER_WRITE(control), &realvol);
    161         if (ret < 0)
    162             perror("Setting mute:");
    163     }
    164 
    165     mute = on;
    166 #endif
    167 }
    168 
    169 void VolumeControl::ToggleMute(void)
    170 {
    171     SetMute(!mute);
    172 }
    173 
    174 kMuteState VolumeControl::IterateMutedChannels(void)
    175 {
    176 // current_mute_state is initialized to "MUTE_OFF".  If individual muting
    177 // is enabled, each call to SetMute will advance to the next state:
    178 // MUTE_OFF -> MUTE_LEFT -> MUTE_RIGHT -> MUTE_BOTH -> MUTE_OFF
    179 #ifdef USING_OSS
    180     int realvol;
    181 
    182     switch (current_mute_state)
    183     {
    184        case MUTE_OFF:
    185            current_mute_state = MUTE_LEFT;
    186            realvol = (internal_volume << 8) + 0;
    187            break;
    188        case MUTE_LEFT:
    189            current_mute_state = MUTE_RIGHT;
    190            realvol = (0 << 8) + internal_volume;
    191            break;
    192        case MUTE_RIGHT:
    193            current_mute_state = MUTE_BOTH;
    194            realvol = 0;
    195            break;
    196        case MUTE_BOTH:
    197            current_mute_state = MUTE_OFF;
    198            realvol = (internal_volume << 8) + internal_volume;
    199            break;
    200     }
    201 
    202     if (mixerfd >= 0)
    203     {
    204         int ret = ioctl(mixerfd, MIXER_WRITE(control), &realvol);
    205         if (ret < 0)
    206             perror("IterateMutedChannels:");
    207     }
    208 #endif // USING_OSS
    209 
    210     return current_mute_state;
    211 }
  • libs/libmyth/audiooutputjack.cpp

     
    2121#include "bio2jack.h"
    2222}
    2323
    24 AudioOutputJACK::AudioOutputJACK(
    25     QString laudio_main_device, QString           laudio_passthru_device,
    26     int     laudio_bits,        int               laudio_channels,
    27     int     laudio_samplerate,  AudioOutputSource lsource,
    28     bool    lset_initial_vol,   bool              laudio_passthru) :
    29     AudioOutputBase(laudio_main_device, laudio_passthru_device,
    30                     laudio_bits,        laudio_channels,
    31                     laudio_samplerate,  lsource,
    32                     lset_initial_vol,   laudio_passthru),
    33     audioid(-1)
     24AudioOutputJACK::AudioOutputJACK(const AudioSettings &settings) :
     25    AudioOutputBase(settings), audioid(-1)
    3426{
    3527    // Initialise the Jack output layer
    3628    JACK_Init();
    3729
    3830    // Set everything up
    39     Reconfigure(laudio_bits, laudio_channels,
    40                 laudio_samplerate, laudio_passthru);
     31    Reconfigure(settings);
    4132}
    4233
    4334AudioOutputJACK::~AudioOutputJACK()
     
    6859    audioid = -1;
    6960    while (timer.elapsed() < 2000 && audioid == -1)
    7061    {
    71         err = JACK_OpenEx(&audioid, 16, (unsigned long *) &audio_samplerate,
     62        unsigned long audio_samplerate_long = audio_samplerate;
     63        err = JACK_OpenEx(&audioid, 16, &audio_samplerate_long,
    7264                          audio_channels, audio_channels, &jack_port_name,
    7365                          jack_port_name_count, jack_port_flags);
     66        audio_samplerate = audio_samplerate_long;
    7467        if (err == 1) {
    7568            Error(QString("Error connecting to jackd:%1.  Is it running?")
    7669                  .arg(audio_main_device));
     
    7972            // need to resample
    8073            VERBOSE(VB_AUDIO, QString("Failed to open device at"
    8174                                      " requested samplerate.  Retrying"));
    82             err = JACK_OpenEx(&audioid, 16, (unsigned long *) &audio_samplerate,
     75            unsigned long audio_samplerate_long = audio_samplerate;
     76            err = JACK_OpenEx(&audioid, 16, &audio_samplerate_long,
    8377                              audio_channels, audio_channels, &jack_port_name,
    8478                              jack_port_name_count, jack_port_flags);
     79            audio_samplerate = audio_samplerate_long;
    8580        } else if (err == ERR_PORT_NOT_FOUND) {
    8681            VERBOSE(VB_IMPORTANT, QString("Error opening audio device (%1), "
    8782                    " Port not found.").arg(audio_main_device));
     
    156151}
    157152
    158153
    159 inline int AudioOutputJACK::getBufferedOnSoundcard(void)
     154int AudioOutputJACK::GetBufferedOnSoundcard(void) const
    160155{
    161156    return  JACK_GetBytesStored(audioid) + fragment_size * 2;
    162157}
    163158
    164 inline int AudioOutputJACK::getSpaceOnSoundcard(void)
     159int AudioOutputJACK::GetSpaceOnSoundcard(void) const
    165160{
    166161    int space = 0;
    167162
     
    184179    JACK_SetAllVolume(audioid, volume);
    185180}
    186181
    187 int AudioOutputJACK::GetVolumeChannel(int channel)
     182int AudioOutputJACK::GetVolumeChannel(int channel) const
    188183{
    189184    unsigned int vol = 0;
    190185   
  • libs/libmyth/audiooutputoss.h

     
    1212
    1313class AudioOutputOSS : public AudioOutputBase
    1414{
    15 public:
    16     AudioOutputOSS(QString audiodevice, QString passthrudevice,
    17                    int laudio_bits,
    18                    int laudio_channels, int laudio_samplerate,
    19                    AudioOutputSource source, bool set_initial_vol,
    20                    bool laudio_passthru);
     15  public:
     16    AudioOutputOSS(const AudioSettings &settings);
    2117    virtual ~AudioOutputOSS();
    2218
    2319    // Volume control
    24     virtual int GetVolumeChannel(int channel); // Returns 0-100
    25     virtual void SetVolumeChannel(int channel, int volume); // range 0-100 for vol
     20    virtual int GetVolumeChannel(int channel) const;
     21    virtual void SetVolumeChannel(int channel, int volume);
    2622
    27 protected:
     23  protected:
    2824    // You need to implement the following functions
    2925    virtual bool OpenDevice(void);
    3026    virtual void CloseDevice(void);
    3127    virtual void WriteAudio(unsigned char *aubuf, int size);
    32     virtual inline int getSpaceOnSoundcard(void);
    33     virtual inline int getBufferedOnSoundcard(void);
     28    virtual int  GetSpaceOnSoundcard(void) const;
     29    virtual int  GetBufferedOnSoundcard(void) const;
    3430
    35 private:
     31  private:
    3632    void VolumeInit(void);
    3733    void VolumeCleanup(void);
    3834   
    3935    void SetFragSize(void);
    4036   
    4137    int audiofd;
    42     int numbadioctls;
     38    mutable int numbadioctls;
    4339
    4440    // Volume related
    4541    int mixerfd;
    4642    int control;
    47 
    4843};
    4944
    5045#endif
  • libs/libmyth/audiooutputbase.cpp

     
    11// Std C headers
    2 #include <cstdio>
    3 #include <cstdlib>
    42#include <cmath>
    53
    64// POSIX headers
     
    2321#define LOC QString("AO: ")
    2422#define LOC_ERR QString("AO, ERROR: ")
    2523
    26 AudioOutputBase::AudioOutputBase(
    27     QString laudio_main_device,    QString           laudio_passthru_device,
    28     int     /*laudio_bits*/,       int               /*laudio_channels*/,
    29     int     /*laudio_samplerate*/, AudioOutputSource lsource,
    30     bool    lset_initial_vol,      bool              /*laudio_passthru*/) :
    31 
     24AudioOutputBase::AudioOutputBase(const AudioSettings &settings) :
     25    // protected
    3226    effdsp(0),                  effdspstretched(0),
    3327    audio_channels(-1),         audio_bytes_per_sample(0),
    3428    audio_bits(-1),             audio_samplerate(-1),
    3529    audio_buffer_unused(0),
    3630    fragment_size(0),           soundcard_buffer_size(0),
    3731
    38     audio_main_device(QDeepCopy<QString>(laudio_main_device)),
    39     audio_passthru_device(QDeepCopy<QString>(laudio_passthru_device)),
     32    audio_main_device(settings.GetMainDevice()),
     33    audio_passthru_device(settings.GetPassthruDevice()),
    4034    audio_passthru(false),      audio_stretchfactor(1.0f),
    4135
    4236    audio_codec(NULL),
    43     source(lsource),            killaudio(false),
     37    source(settings.source),    killaudio(false),
    4438
    4539    pauseaudio(false),          audio_actually_paused(false),
    4640    was_paused(false),
    4741
    48     set_initial_vol(lset_initial_vol),
     42    set_initial_vol(settings.set_initial_vol),
    4943    buffer_output_data_for_use(false),
     44
     45    // private
    5046    need_resampler(false),
    5147
    5248    src_ctx(NULL),
    5349
    54     pSoundStretch(NULL),       
     50    pSoundStretch(NULL),
    5551    encoder(NULL),
    5652    upmixer(NULL),
    5753    source_audio_channels(-1),
     
    7066    audbuf_timecode(0),
    7167
    7268    numlowbuffer(0),            killAudioLock(false),
    73     current_seconds(-1),        source_bitrate(-1)
     69    current_seconds(-1),        source_bitrate(-1),
     70
     71    memory_corruption_test0(0xdeadbeef),
     72    memory_corruption_test1(0xdeadbeef),
     73    memory_corruption_test2(0xdeadbeef),
     74    memory_corruption_test3(0xdeadbeef),
     75    memory_corruption_test4(0xdeadbeef)
    7476{
    7577    pthread_mutex_init(&audio_buflock, NULL);
    7678    pthread_mutex_init(&avsync_lock, NULL);
     
    7880
    7981    // The following are not bzero() because MS Windows doesn't like it.
    8082    memset(&src_data,          0, sizeof(SRC_DATA));
    81     memset(src_in,             0, sizeof(float) * AUDIO_SRC_IN_SIZE);
    82     memset(src_out,            0, sizeof(float) * AUDIO_SRC_OUT_SIZE);
    83     memset(tmp_buff,           0, sizeof(short) * AUDIO_TMP_BUF_SIZE);
     83    memset(src_in,             0, sizeof(float) * kAudioSourceInputSize);
     84    memset(src_out,            0, sizeof(float) * kAudioSourceOutputSize);
     85    memset(tmp_buff,           0, sizeof(short) * kAudioTempBufSize);
    8486    memset(&audiotime_updated, 0, sizeof(audiotime_updated));
    85     memset(audiobuffer,        0, sizeof(char)  * AUDBUFSIZE);
     87    memset(audiobuffer,        0, sizeof(char)  * kAudioRingBufferSize);
    8688    configured_audio_channels = gContext->GetNumSetting("MaxChannels", 2);
    8789
    8890    // You need to call Reconfigure from your concrete class.
     
    9294
    9395AudioOutputBase::~AudioOutputBase()
    9496{
    95     // Make sure you call the next line in your concrete class to ensure everything is shutdown correctly.
    96     // Cant be called here due to use of virtual functions
    97     // KillAudio();
    98    
     97    if (!killaudio)
     98    {
     99        VERBOSE(VB_IMPORTANT,
     100                "Programmer Error: "
     101                "~AudioOutputBase called, but KillAudio has not been called!");
     102    }
     103
    99104    pthread_mutex_destroy(&audio_buflock);
    100105    pthread_mutex_destroy(&avsync_lock);
    101106    pthread_cond_destroy(&audio_bufsig);
     107
     108    assert(memory_corruption_test0 == 0xdeadbeef);
     109    assert(memory_corruption_test1 == 0xdeadbeef);
     110    assert(memory_corruption_test2 == 0xdeadbeef);
     111    assert(memory_corruption_test3 == 0xdeadbeef);
     112    assert(memory_corruption_test4 == 0xdeadbeef);
    102113}
    103114
    104115void AudioOutputBase::SetSourceBitrate(int rate)
     
    179190    pthread_mutex_unlock(&audio_buflock);
    180191}
    181192
    182 float AudioOutputBase::GetStretchFactor(void)
     193float AudioOutputBase::GetStretchFactor(void) const
    183194{
    184195    return audio_stretchfactor;
    185196}
    186197
    187 void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels,
    188                                   int laudio_samplerate, bool laudio_passthru,
    189                                   void *laudio_codec)
     198void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
    190199{
     200    AudioSettings settings = orig_settings;
     201
    191202    int codec_id = CODEC_ID_NONE;
    192203    int lcodec_id = CODEC_ID_NONE;
    193204    int lcchannels = 0;
    194205    int cchannels = 0;
    195     int lsource_audio_channels = laudio_channels;
     206    int lsource_audio_channels = settings.channels;
    196207    bool lneeds_upmix = false;
    197208
    198     if (laudio_codec)
     209    if (settings.codec)
    199210    {
    200         lcodec_id = ((AVCodecContext*)laudio_codec)->codec_id;
    201         laudio_bits = 16;
    202         laudio_channels = 2;
    203         lsource_audio_channels = laudio_channels;
    204         laudio_samplerate = 48000;
    205         lcchannels = ((AVCodecContext*)laudio_codec)->channels;
     211        lcodec_id = ((AVCodecContext*)settings.codec)->codec_id;
     212        settings.bits = 16;
     213        settings.channels = 2;
     214        lsource_audio_channels = settings.channels;
     215        settings.samplerate = 48000;
     216        lcchannels = ((AVCodecContext*)settings.codec)->channels;
    206217    }
    207218
    208219    if (audio_codec)
     
    211222        cchannels = ((AVCodecContext*)audio_codec)->channels;
    212223    }
    213224
    214     if ((configured_audio_channels == 6) && 
    215         !(laudio_codec || audio_codec))
     225    if ((configured_audio_channels == 6) &&
     226        !(settings.codec || audio_codec))
    216227    {
    217         laudio_channels = configured_audio_channels;
     228        settings.channels = configured_audio_channels;
    218229        lneeds_upmix = true;
    219230        VERBOSE(VB_AUDIO,LOC + "Needs upmix");
    220231    }
    221232
    222233    ClearError();
    223     bool general_deps = (laudio_bits == audio_bits &&
    224         laudio_channels == audio_channels &&
    225         laudio_samplerate == audio_samplerate && !need_resampler &&
    226         laudio_passthru == audio_passthru &&
     234    bool general_deps = (settings.bits == audio_bits &&
     235        settings.channels == audio_channels &&
     236        settings.samplerate == audio_samplerate && !need_resampler &&
     237        settings.use_passthru == audio_passthru &&
    227238        lneeds_upmix == needs_upmix &&
    228239        lcodec_id == codec_id && lcchannels == cchannels);
    229240    bool upmix_deps =
     
    244255    }
    245256
    246257    KillAudio();
    247    
     258
    248259    pthread_mutex_lock(&audio_buflock);
    249260    pthread_mutex_lock(&avsync_lock);
    250261
    251262    lastaudiolen = 0;
    252263    waud = raud = 0;
    253264    audio_actually_paused = false;
    254    
    255     bool redo_stretch = (pSoundStretch && audio_channels != laudio_channels);
    256     audio_channels = laudio_channels;
     265
     266    bool redo_stretch = (pSoundStretch && audio_channels != settings.channels);
     267    audio_channels = settings.channels;
    257268    source_audio_channels = lsource_audio_channels;
    258     audio_bits = laudio_bits;
    259     audio_samplerate = laudio_samplerate;
    260     audio_codec = (AVCodecContext*)laudio_codec;
    261     audio_passthru = laudio_passthru;
     269    audio_bits = settings.bits;
     270    audio_samplerate = settings.samplerate;
     271    audio_codec = (AVCodecContext*)settings.codec;
     272    audio_passthru = settings.use_passthru;
    262273    needs_upmix = lneeds_upmix;
    263274
    264275    if (audio_bits != 8 && audio_bits != 16)
     
    270281    }
    271282    audio_bytes_per_sample = audio_channels * audio_bits / 8;
    272283    source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8;
    273    
     284
    274285    need_resampler = false;
    275286    killaudio = false;
    276287    pauseaudio = false;
    277288    was_paused = true;
    278289    internal_vol = gContext->GetNumSetting("MythControlsVolume", 0);
    279    
     290
    280291    numlowbuffer = 0;
    281292
    282293    VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4")
    283294            .arg(audio_main_device).arg(audio_channels)
    284295            .arg(source_audio_channels).arg(audio_samplerate));
    285  
     296
    286297    // Actually do the device specific open call
    287298    if (!OpenDevice())
    288299    {
     
    296307    }
    297308
    298309    SyncVolume();
    299    
     310
    300311    VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1")
    301312            .arg(fragment_size));
    302313
     
    316327
    317328    // NOTE: this won't do anything as above samplerate vars are set equal
    318329    // Check if we need the resampler
    319     if (audio_samplerate != laudio_samplerate)
     330    if (audio_samplerate != settings.samplerate)
    320331    {
    321332        int error;
    322333        VERBOSE(VB_GENERAL, LOC + QString("Using resampler. From: %1 to %2")
    323                                .arg(laudio_samplerate).arg(audio_samplerate));
     334                               .arg(settings.samplerate).arg(audio_samplerate));
    324335        src_ctx = src_new (SRC_SINC_BEST_QUALITY, audio_channels, &error);
    325336        if (error)
    326337        {
     
    330341            pthread_mutex_unlock(&audio_buflock);
    331342            return;
    332343        }
    333         src_data.src_ratio = (double) audio_samplerate / laudio_samplerate;
     344        src_data.src_ratio = (double) audio_samplerate / settings.samplerate;
    334345        src_data.data_in = src_in;
    335346        src_data.data_out = src_out;
    336347        src_data.output_frames = 16384*6;
     
    346357        }
    347358
    348359        upmixer = new FreeSurround(
    349             audio_samplerate, 
    350             source == AUDIOOUTPUT_VIDEO, 
     360            audio_samplerate,
     361            source == AUDIOOUTPUT_VIDEO,
    351362            (FreeSurround::SurroundMode)surround_mode);
    352363
    353364        VERBOSE(VB_AUDIO, LOC +
     
    486497    killAudioLock.unlock();
    487498}
    488499
    489 
    490 bool AudioOutputBase::GetPause(void)
    491 {
    492     return audio_actually_paused;
    493 }
    494 
    495500void AudioOutputBase::Pause(bool paused)
    496501{
    497502    VERBOSE(VB_AUDIO, LOC + QString("Pause %0").arg(paused));
     
    540545    this->blocking = blocking;
    541546}
    542547
    543 int AudioOutputBase::audiolen(bool use_lock)
     548int AudioOutputBase::audiolen(bool use_lock) const
    544549{
    545550    /* Thread safe, returns the number of valid bytes in the audio buffer */
    546551    int ret;
    547    
    548     if (use_lock) 
     552
     553    if (use_lock)
    549554        pthread_mutex_lock(&audio_buflock);
    550555
    551556    if (waud >= raud)
    552557        ret = waud - raud;
    553558    else
    554         ret = AUDBUFSIZE - (raud - waud);
     559        ret = kAudioRingBufferSize - (raud - waud);
    555560
    556561    if (use_lock)
    557562        pthread_mutex_unlock(&audio_buflock);
     
    559564    return ret;
    560565}
    561566
    562 int AudioOutputBase::audiofree(bool use_lock)
     567int AudioOutputBase::audiofree(bool use_lock) const
    563568{
    564     return AUDBUFSIZE - audiolen(use_lock) - 1;
     569    return kAudioRingBufferSize - audiolen(use_lock) - 1;
    565570    /* There is one wasted byte in the buffer. The case where waud = raud is
    566571       interpreted as an empty buffer, so the fullest the buffer can ever
    567        be is AUDBUFSIZE - 1. */
     572       be is kAudioRingBufferSize - 1. */
    568573}
    569574
    570 int AudioOutputBase::GetAudiotime(void)
     575int AudioOutputBase::GetAudiotime(void) const
    571576{
    572577    /* Returns the current timecode of audio leaving the soundcard, based
    573578       on the 'audiotime' computed earlier, and the delay since it was computed.
    574579
    575580       This is a little roundabout...
    576581
    577        The reason is that computing 'audiotime' requires acquiring the audio 
     582       The reason is that computing 'audiotime' requires acquiring the audio
    578583       lock, which the video thread should not do. So, we call 'SetAudioTime()'
    579584       from the audio thread, and then call this from the video thread. */
    580585    long long ret;
     
    592597    ret = (long long)(ret * audio_stretchfactor);
    593598
    594599#if 1
    595     VERBOSE(VB_AUDIO|VB_TIMESTAMP, 
     600    VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    596601            QString("GetAudiotime now=%1.%2, set=%3.%4, ret=%5, audt=%6 sf=%7")
    597602            .arg(now.tv_sec).arg(now.tv_usec)
    598603            .arg(audiotime_updated.tv_sec).arg(audiotime_updated.tv_usec)
     
    624629       'effdsp' is samples/sec, multiplied by 100.
    625630       Bytes per sample is assumed to be 4.
    626631
    627        'audiotimecode' is the timecode of the audio that has just been 
     632       'audiotimecode' is the timecode of the audio that has just been
    628633       written into the buffer.
    629634
    630635       'totalbuffer' is the total # of bytes in our audio buffer, and the
     
    635640
    636641    pthread_mutex_lock(&audio_buflock);
    637642    pthread_mutex_lock(&avsync_lock);
    638  
    639     soundcard_buffer = getBufferedOnSoundcard(); // bytes
     643
     644    soundcard_buffer = GetBufferedOnSoundcard(); // bytes
    640645    totalbuffer = audiolen(false) + soundcard_buffer;
    641  
     646
    642647    // include algorithmic latencies
    643648    if (pSoundStretch)
    644649    {
     
    658663
    659664    audiotime = audbuf_timecode - (int)(totalbuffer * 100000.0 /
    660665                                   (audio_bytes_per_sample * effdspstretched));
    661  
     666
    662667    gettimeofday(&audiotime_updated, NULL);
    663668#if 1
    664     VERBOSE(VB_AUDIO|VB_TIMESTAMP, 
     669    VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    665670            QString("SetAudiotime set=%1.%2, audt=%3 atc=%4 "
    666671                    "tb=%5 sb=%6 eds=%7 abps=%8 sf=%9")
    667672            .arg(audiotime_updated.tv_sec).arg(audiotime_updated.tv_usec)
     
    678683    pthread_mutex_unlock(&audio_buflock);
    679684}
    680685
    681 bool AudioOutputBase::AddSamples(char *buffers[], int samples, 
     686bool AudioOutputBase::AddSamples(char *buffers[], int samples,
    682687                                 long long timecode)
    683688{
    684689    // NOTE: This function is not threadsafe
     
    699704        len += (pSoundStretch->numUnprocessedSamples() +
    700705                (int)(pSoundStretch->numSamples()/audio_stretchfactor))*abps;
    701706
    702     if (((len > afree) || ((audbuf_timecode - GetAudiotime()) > 2000)) && !blocking) 
     707    if (((len > afree) || ((audbuf_timecode - GetAudiotime()) > 2000)) && !blocking)
    703708    {
    704709        VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + QString(
    705                 "AddSamples FAILED bytes=%1, used=%2, free=%3, timecode=%4") 
    706                 .arg(len).arg(AUDBUFSIZE-afree).arg(afree)
    707                 .arg(timecode)); 
     710                "AddSamples FAILED bytes=%1, used=%2, free=%3, timecode=%4")
     711                .arg(len).arg(kAudioRingBufferSize-afree).arg(afree)
     712                .arg(timecode));
    708713
    709714        return false; // would overflow
    710715    }
    711716
    712717    // resample input if necessary
    713     if (need_resampler && src_ctx) 
     718    if (need_resampler && src_ctx)
    714719    {
    715720        // Convert to floats
    716721        // TODO: Implicit assumption dealing with 16 bit input only.
    717722        short **buf_ptr = (short**)buffers;
    718         for (int sample = 0; sample < samples; sample++) 
     723        for (int sample = 0; sample < samples; sample++)
    719724        {
    720             for (int channel = 0; channel < audio_channels; channel++) 
     725            for (int channel = 0; channel < audio_channels; channel++)
    721726            {
    722727                src_in[sample] = buf_ptr[channel][sample] / (1.0 * 0x8000);
    723728            }
     
    735740                                 src_data.output_frames_gen*audio_channels);
    736741
    737742        _AddSamples(tmp_buff, true, src_data.output_frames_gen, timecode);
    738     } 
    739     else 
     743    }
     744    else
    740745    {
    741746        // Call our function to do the work
    742747        _AddSamples(buffers, false, samples, timecode);
     
    761766    // include samples in upmix buffer that may be flushed
    762767    if (needs_upmix && upmixer)
    763768        len += upmixer->numUnprocessedSamples() * abps;
    764  
     769
    765770    if (pSoundStretch)
    766771    {
    767772        len += (pSoundStretch->numUnprocessedSamples() +
    768773                (int)(pSoundStretch->numSamples()/audio_stretchfactor))*abps;
    769774    }
    770775
    771     if (((len > afree) || (audiotime && ((audbuf_timecode - GetAudiotime()) > 2000))) && !blocking) 
     776    if (((len > afree) || (audiotime && ((audbuf_timecode - GetAudiotime()) > 2000))) && !blocking)
    772777    {
    773778        VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + QString(
    774                 "AddSamples FAILED bytes=%1, used=%2, free=%3, timecode=%4") 
    775                 .arg(len).arg(AUDBUFSIZE-afree).arg(afree)
    776                 .arg(timecode)); 
     779                "AddSamples FAILED bytes=%1, used=%2, free=%3, timecode=%4")
     780                .arg(len).arg(kAudioRingBufferSize-afree).arg(afree)
     781                .arg(timecode));
    777782        return false; // would overflow
    778783    }
    779784
    780785    // resample input if necessary
    781     if (need_resampler && src_ctx) 
     786    if (need_resampler && src_ctx)
    782787    {
    783788        // Convert to floats
    784789        short *buf_ptr = (short*)buffer;
    785         for (int sample = 0; sample < samples * audio_channels; sample++) 
    786         {       
     790        for (int sample = 0; sample < samples * audio_channels; sample++)
     791        {
    787792            src_in[sample] = (float)buf_ptr[sample] / (1.0 * 0x8000);
    788793        }
    789         
     794 
    790795        src_data.input_frames = samples;
    791796        src_data.end_of_input = 0;
    792797        int error = src_process(src_ctx, &src_data);
     
    794799            VERBOSE(VB_IMPORTANT, LOC_ERR +
    795800                    QString("Error occured while resampling audio: %1")
    796801                    .arg(src_strerror(error)));
    797         src_float_to_short_array(src_data.data_out, (short int*)tmp_buff, 
     802        src_float_to_short_array(src_data.data_out, (short int*)tmp_buff,
    798803                                 src_data.output_frames_gen*audio_channels);
    799804
    800805        _AddSamples(tmp_buff, true, src_data.output_frames_gen, timecode);
    801     } 
    802     else 
     806    }
     807    else
    803808    {
    804809        // Call our function to do the work
    805810        _AddSamples(buffer, true, samples, timecode);
     
    828833        }
    829834        else
    830835        {
    831             VERBOSE(VB_IMPORTANT, LOC_ERR + 
     836            VERBOSE(VB_IMPORTANT, LOC_ERR +
    832837                    QString("Audio buffer overflow, %1 audio samples lost!")
    833838                    .arg(samples - (afree / abps)));
    834839            samples = afree / abps;
    835840            len = samples * abps;
    836             if (src_ctx) 
     841            if (src_ctx)
    837842            {
    838843                int error = src_reset(src_ctx);
    839844                if (error)
     
    846851    return len;
    847852}
    848853
    849 void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
     854void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples,
    850855                                  long long timecode)
    851856{
    852857    pthread_mutex_lock(&audio_buflock);
     
    854859    int len; // = samples * audio_bytes_per_sample;
    855860    int audio_bytes = audio_bits / 8;
    856861    int org_waud = waud;
    857    
     862
    858863    int afree = audiofree(false);
    859864
    860865    int abps = (encoder) ?
    861866        encoder->audio_bytes_per_sample : audio_bytes_per_sample;
    862867
    863     VERBOSE(VB_AUDIO|VB_TIMESTAMP, 
     868    VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    864869            LOC + QString("_AddSamples samples=%1 bytes=%2, used=%3, "
    865870                          "free=%4, timecode=%5 needsupmix %6")
    866871            .arg(samples)
    867872            .arg(samples * abps)
    868             .arg(AUDBUFSIZE-afree).arg(afree).arg(timecode)
     873            .arg(kAudioRingBufferSize-afree).arg(afree).arg(timecode)
    869874            .arg(needs_upmix));
    870    
     875
    871876    if (upmixer && needs_upmix)
    872877    {
    873878        int out_samples = 0;
     
    903908                out_samples += copy_samples;
    904909                if (out_samples > samples)
    905910                    len = WaitForFreeSpace(out_samples);
    906                 int bdiff = AUDBUFSIZE - org_waud;
    907                 if (bdiff < copy_len) 
     911                int bdiff = kAudioRingBufferSize - org_waud;
     912                if (bdiff < copy_len)
    908913                {
    909914                    int bdiff_samples = bdiff/abps;
    910915                    upmixer->receiveSamples(
     
    917922                    upmixer->receiveSamples(
    918923                        (short*)(audiobuffer + org_waud), copy_samples);
    919924                }
    920                 org_waud = (org_waud + copy_len) % AUDBUFSIZE;
     925                org_waud = (org_waud + copy_len) % kAudioRingBufferSize;
    921926            }
    922927        }
    923928
     
    930935    {
    931936        len = WaitForFreeSpace(samples);
    932937
    933         if (interleaved) 
     938        if (interleaved)
    934939        {
    935940            char *mybuf = (char*)buffer;
    936             int bdiff = AUDBUFSIZE - org_waud;
     941            int bdiff = kAudioRingBufferSize - org_waud;
    937942            if (bdiff < len)
    938943            {
    939944                memcpy(audiobuffer + org_waud, mybuf, bdiff);
     
    943948            {
    944949                memcpy(audiobuffer + org_waud, mybuf, len);
    945950            }
    946      
    947             org_waud = (org_waud + len) % AUDBUFSIZE;
    948         } 
    949         else 
     951
     952            org_waud = (org_waud + len) % kAudioRingBufferSize;
     953        }
     954        else
    950955        {
    951956            char **mybuf = (char**)buffer;
    952957            for (int itemp = 0; itemp < samples * audio_bytes;
     
    958963                    if (audio_bits == 16)
    959964                        audiobuffer[org_waud++] = mybuf[chan][itemp+1];
    960965
    961                     if (org_waud >= AUDBUFSIZE)
    962                         org_waud -= AUDBUFSIZE;
     966                    if (org_waud >= (int)kAudioRingBufferSize)
     967                        org_waud -= kAudioRingBufferSize;
    963968                }
    964969            }
    965970        }
     
    973978            // does not change the timecode, only the number of samples
    974979            // back to orig pos
    975980            org_waud = waud;
    976             int bdiff = AUDBUFSIZE - org_waud;
     981            int bdiff = kAudioRingBufferSize - org_waud;
    977982            int nSamplesToEnd = bdiff/abps;
    978983            if (bdiff < len)
    979984            {
    980985                pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
    981                                           (audiobuffer + 
     986                                          (audiobuffer +
    982987                                           org_waud), nSamplesToEnd);
    983988                pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer,
    984989                                          (len - bdiff) / abps);
     
    994999            {
    9951000                // pull out a packet's worth and reencode it until we
    9961001                // don't have enough for any more packets
    997                 soundtouch::SAMPLETYPE *temp_buff = 
     1002                soundtouch::SAMPLETYPE *temp_buff =
    9981003                    (soundtouch::SAMPLETYPE*)encoder->GetFrameBuffer();
    9991004                size_t frameSize = encoder->FrameSize()/abps;
    10001005
     
    10121017                        temp_buff, frameSize);
    10131018                    int amount = encoder->Encode(temp_buff);
    10141019
    1015                     VERBOSE(VB_AUDIO|VB_TIMESTAMP, 
     1020                    VERBOSE(VB_AUDIO|VB_TIMESTAMP,
    10161021                            QString("_AddSamples Enc bytes=%1 got=%2 left=%3")
    10171022                            .arg(amount)
    10181023                            .arg(got)
     
    10331038                    if (amount > 0)
    10341039                        memcpy(audiobuffer + org_waud, ob, amount);
    10351040
    1036                     bdiff = AUDBUFSIZE - amount;
     1041                    bdiff = kAudioRingBufferSize - amount;
    10371042                    org_waud += amount;
    10381043                }
    10391044            }
     
    10411046            {
    10421047                int newLen = 0;
    10431048                int nSamples;
    1044                 len = WaitForFreeSpace(pSoundStretch->numSamples() * 
     1049                len = WaitForFreeSpace(pSoundStretch->numSamples() *
    10451050                                       audio_bytes_per_sample);
    1046                 do 
     1051                do
    10471052                {
    10481053                    int samplesToGet = len/audio_bytes_per_sample;
    10491054                    if (samplesToGet > nSamplesToEnd)
    10501055                    {
    1051                         samplesToGet = nSamplesToEnd;   
     1056                        samplesToGet = nSamplesToEnd;
    10521057                    }
    10531058
    10541059                    nSamples = pSoundStretch->receiveSamples(
     
    10571062                    if (nSamples == nSamplesToEnd)
    10581063                    {
    10591064                        org_waud = 0;
    1060                         nSamplesToEnd = AUDBUFSIZE/audio_bytes_per_sample;
     1065                        nSamplesToEnd = kAudioRingBufferSize/audio_bytes_per_sample;
    10611066                    }
    10621067                    else
    10631068                    {
     
    10791084            // mythmusic doesn't give timestamps..
    10801085            timecode = (int)((samples_buffered * 100000.0) / effdsp);
    10811086        }
    1082         
     1087 
    10831088        samples_buffered += samples;
    1084         
     1089 
    10851090        /* we want the time at the end -- but the file format stores
    10861091           time at the start of the chunk. */
    10871092        // even with timestretch, timecode is still calculated from original
     
    11101115        source_bitrate = audio_samplerate * source_audio_channels * audio_bits;
    11111116    }
    11121117
    1113     if (ct / 1000 != current_seconds) 
     1118    if (ct / 1000 != current_seconds)
    11141119    {
    11151120        current_seconds = ct / 1000;
    11161121        OutputEvent e(current_seconds, ct,
    1117                       source_bitrate, audio_samplerate, audio_bits, 
     1122                      source_bitrate, audio_samplerate, audio_bits,
    11181123                      source_audio_channels);
    11191124        dispatch(e);
    11201125    }
    11211126}
    11221127
    1123 void AudioOutputBase::GetBufferStatus(uint &fill, uint &total)
     1128void AudioOutputBase::GetBufferStatus(uint &fill, uint &total) const
    11241129{
    1125     fill = AUDBUFSIZE - audiofree(true);
    1126     total = AUDBUFSIZE;
     1130    fill = kAudioRingBufferSize - audiofree(true);
     1131    total = kAudioRingBufferSize;
    11271132}
    11281133
    11291134void AudioOutputBase::OutputAudioLoop(void)
     
    11311136    int space_on_soundcard, last_space_on_soundcard;
    11321137    unsigned char zeros[fragment_size];
    11331138    unsigned char fragment[fragment_size];
    1134  
     1139
    11351140    bzero(zeros, fragment_size);
    11361141    last_space_on_soundcard = 0;
    11371142
     
    11481153            }
    11491154
    11501155            audio_actually_paused = true;
    1151             
     1156     
    11521157            audiotime = 0; // mark 'audiotime' as invalid.
    11531158
    1154             space_on_soundcard = getSpaceOnSoundcard();
     1159            space_on_soundcard = GetSpaceOnSoundcard();
    11551160
    11561161            if (space_on_soundcard != last_space_on_soundcard)
    11571162            {
     
    11641169
    11651170            // only send zeros if card doesn't already have at least one
    11661171            // fragment of zeros -dag
    1167             if (fragment_size >= soundcard_buffer_size - space_on_soundcard) 
     1172            if (fragment_size >= soundcard_buffer_size - space_on_soundcard)
    11681173            {
    11691174                if (fragment_size <= space_on_soundcard) {
    11701175                    WriteAudio(zeros, fragment_size);
    11711176                } else {
    11721177                    // this should never happen now -dag
    1173                     VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + 
     1178                    VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC +
    11741179                            QString("waiting for space on soundcard "
    11751180                                    "to write zeros: have %1 need %2")
    11761181                            .arg(space_on_soundcard).arg(fragment_size));
     
    11831188        }
    11841189        else
    11851190        {
    1186             if (was_paused) 
     1191            if (was_paused)
    11871192            {
    11881193                VERBOSE(VB_AUDIO, LOC + "OutputAudioLoop: Play Event");
    11891194                OutputEvent e(OutputEvent::Playing);
     
    11921197            }
    11931198        }
    11941199
    1195         space_on_soundcard = getSpaceOnSoundcard();
    1196         
     1200        space_on_soundcard = GetSpaceOnSoundcard();
     1201 
    11971202        // if nothing has gone out the soundcard yet no sense calling
    11981203        // this (think very fast loops here when soundcard doesn't have
    11991204        // space to take another fragment) -dag
     
    12011206            SetAudiotime(); // once per loop, calculate stuff for a/v sync
    12021207
    12031208        /* do audio output */
    1204         
     1209 
    12051210        // wait for the buffer to fill with enough to play
    12061211        if (fragment_size > audiolen(true))
    12071212        {
     
    12201225            usleep(2000);
    12211226            continue;
    12221227        }
    1223         
     1228 
    12241229        // wait for there to be free space on the sound card so we can write
    12251230        // without blocking.  We don't want to block while holding audio_buflock
    12261231        if (fragment_size > space_on_soundcard)
     
    12601265int AudioOutputBase::GetAudioData(unsigned char *buffer, int buf_size, bool full_buffer)
    12611266{
    12621267    pthread_mutex_lock(&audio_buflock); // begin critical section
    1263    
     1268
    12641269    // re-check audiolen() in case things changed.
    12651270    // for example, ClearAfterSeek() might have run
    12661271    int avail_size = audiolen(false);
     
    12711276        // when full_buffer is false, return any available data
    12721277        fragment_size = avail_size;
    12731278    }
    1274    
     1279
    12751280    if (avail_size && (fragment_size <= avail_size))
    12761281    {
    1277         int bdiff = AUDBUFSIZE - raud;
     1282        int bdiff = kAudioRingBufferSize - raud;
    12781283        if (fragment_size > bdiff)
    12791284        {
    12801285            // always want to write whole fragments
     
    12871292        }
    12881293
    12891294        /* update raud */
    1290         raud = (raud + fragment_size) % AUDBUFSIZE;
     1295        raud = (raud + fragment_size) % kAudioRingBufferSize;
    12911296        VERBOSE(VB_AUDIO|VB_TIMESTAMP, LOC + "Broadcasting free space avail");
    12921297        pthread_cond_broadcast(&audio_bufsig);
    12931298
    12941299        written_size = fragment_size;
    12951300    }
    12961301    pthread_mutex_unlock(&audio_buflock); // end critical section
    1297    
     1302
    12981303    // Mute individual channels through mono->stereo duplication
    12991304    kMuteState mute_state = GetMute();
    13001305    if (written_size &&
     
    13031308    {
    13041309        int offset_src = 0;
    13051310        int offset_dst = 0;
    1306         
     1311 
    13071312        if (mute_state == MUTE_LEFT)
    13081313            offset_src = audio_bits / 8;    // copy channel 1 to channel 0
    13091314        else if (mute_state == MUTE_RIGHT)
    13101315            offset_dst = audio_bits / 8;    // copy channel 0 to channel 1
    1311             
     1316     
    13121317        for (int i = 0; i < written_size; i += audio_bytes_per_sample)
    13131318        {
    13141319            buffer[i + offset_dst] = buffer[i + offset_src];
     
    13161321                buffer[i + offset_dst + 1] = buffer[i + offset_src + 1];
    13171322        }
    13181323    }
    1319    
     1324
    13201325    return written_size;
    13211326}
    13221327
  • libs/libmyth/audiooutput.cpp

     
    1 #include <qstring.h>
    21#include <cstdio>
    32#include <cstdlib>
    43
    54using namespace std;
    65
    7 #include "config.h"
     6#include "mythconfig.h"
    87#include "audiooutput.h"
    98#include "compat.h"
    109
     
    3130#include "audiooutputjack.h"
    3231#endif
    3332
    34 AudioOutput *AudioOutput::OpenAudio(QString main_device,
    35                                     QString passthru_device,
    36                                     int audio_bits,
    37                                     int audio_channels, int audio_samplerate,
    38                                     AudioOutputSource source,
    39                                     bool set_initial_vol, bool audio_passthru)
     33AudioOutput *AudioOutput::OpenAudio(
     34    const QString &main_device,
     35    const QString &passthru_device,
     36    int audio_bits, int audio_channels, int audio_samplerate,
     37    AudioOutputSource source,
     38    bool set_initial_vol, bool audio_passthru)
    4039{
    41     if (passthru_device.isEmpty() || passthru_device.lower() == "default")
    42         passthru_device = main_device;
     40    AudioSettings settings(
     41        main_device, passthru_device, audio_bits,
     42        audio_channels, audio_samplerate, source,
     43        set_initial_vol, audio_passthru);
    4344
     45    settings.FixPassThrough();
     46
    4447    if (main_device.startsWith("ALSA:"))
    4548    {
    4649#ifdef USE_ALSA
    47         return new AudioOutputALSA(main_device.remove(0, 5),
    48                                    passthru_device.remove(0, 5), audio_bits,
    49                                    audio_channels, audio_samplerate, source,
    50                                    set_initial_vol, audio_passthru);
     50        settings.TrimDeviceType();
     51        return new AudioOutputALSA(settings);
    5152#else
    5253        VERBOSE(VB_IMPORTANT, "Audio output device is set to an ALSA device "
    5354                              "but ALSA support is not compiled in!");
     
    5657    }
    5758    else if (main_device.startsWith("NULL"))
    5859    {
    59         return new AudioOutputNULL(main_device, passthru_device, audio_bits,
    60                                    audio_channels, audio_samplerate, source,
    61                                    set_initial_vol, audio_passthru);
     60        return new AudioOutputNULL(settings);
    6261    }
    6362    else if (main_device.startsWith("ARTS:"))
    6463    {
    6564#ifdef USE_ARTS
    66         return new AudioOutputARTS(main_device.remove(0, 5),
    67                                    passthru_device.remove(0, 5), audio_bits,
    68                                    audio_channels, audio_samplerate, source,
    69                                    set_initial_vol, audio_passthru);
     65        settings.TrimDeviceType();
     66        return new AudioOutputARTS(settings);
    7067#else
    7168        VERBOSE(VB_IMPORTANT, "Audio output device is set to an ARTS device "
    7269                              "but ARTS support is not compiled in!");
     
    7673    else if (main_device.startsWith("JACK:"))
    7774    {
    7875#ifdef USE_JACK
    79         return new AudioOutputJACK(main_device.remove(0, 5),
    80                                    passthru_device.remove(0, 5), audio_bits,
    81                                    audio_channels, audio_samplerate, source,
    82                                    set_initial_vol, audio_passthru);
     76        settings.TrimDeviceType();
     77        return new AudioOutputJACK(settings);
    8378#else
    8479        VERBOSE(VB_IMPORTANT, "Audio output device is set to a JACK device "
    8580                              "but JACK support is not compiled in!");
     
    8984    else if (main_device.startsWith("DirectX:"))
    9085    {
    9186#ifdef USING_DIRECTX
    92         return new AudioOutputDX(main_device, passthru_device, audio_bits,
    93                                  audio_channels, audio_samplerate, source,
    94                                  set_initial_vol, audio_passthru);
     87        return new AudioOutputDX(settings);
    9588#else
    9689        VERBOSE(VB_IMPORTANT, "Audio output device is set to DirectX device "
    9790                              "but DirectX support is not compiled in!");
     
    10194    else if (main_device.startsWith("Windows:"))
    10295    {
    10396#ifdef USING_WINAUDIO
    104         return new AudioOutputWin(main_device, passthru_device, audio_bits,
    105                                   audio_channels, audio_samplerate, source,
    106                                   set_initial_vol, audio_passthru);
     97        return new AudioOutputWin(settings);
    10798#else
    10899        VERBOSE(VB_IMPORTANT, "Audio output device is set to a Windows device "
    109100                              "but Windows support is not compiled in!");
     
    112103    }
    113104#if defined(USING_OSS)
    114105    else
    115         return new AudioOutputOSS(main_device, passthru_device, audio_bits,
    116                                   audio_channels, audio_samplerate, source,
    117                                   set_initial_vol, audio_passthru);
     106        return new AudioOutputOSS(settings);
    118107#elif defined(CONFIG_DARWIN)
    119108    else
    120         return new AudioOutputCA(main_device, passthru_device, audio_bits,
    121                                  audio_channels, audio_samplerate, source,
    122                                  set_initial_vol, audio_passthru);
     109        return new AudioOutputCA(settings);
    123110#endif
    124111
    125112    VERBOSE(VB_IMPORTANT, "No useable audio output driver found.");
     
    133120{
    134121}
    135122
     123void AudioOutput::Error(const QString &msg)
     124{
     125    lastError = QDeepCopy<QString>(msg);
     126    VERBOSE(VB_IMPORTANT, "AudioOutput Error: " + lastError);
     127}
    136128
     129void AudioOutput::Warn(const QString &msg)
     130{
     131    lastWarn = QDeepCopy<QString>(msg);
     132    VERBOSE(VB_IMPORTANT, "AudioOutput Warning: " + lastWarn);
     133}
     134
     135void AudioOutput::ClearError(void)
     136{
     137    lastError = QString::null;
     138}
     139
     140void AudioOutput::ClearWarning(void)
     141{
     142    lastWarn = QString::null;
     143}
     144
  • libs/libmyth/libmyth.pro

     
    1111
    1212# Input
    1313HEADERS += audiooutput.h audiooutputbase.h audiooutputnull.h
    14 HEADERS += audiooutputdigitalencoder.h
     14HEADERS += audiooutputdigitalencoder.h audiosettings.cpp
    1515HEADERS += backendselect.h dbsettings.h dialogbox.h
    1616HEADERS += DisplayRes.h DisplayResScreen.h exitcodes.h
    1717HEADERS += generictree.h httpcomms.h langsettings.h lcddevice.h
     
    2323HEADERS += oldsettings.h output.h qmdcodec.h remotefile.h
    2424HEADERS += screensaver.h screensaver-null.h settings.h themeinfo.h
    2525HEADERS += uilistbtntype.h uitypes.h util.h util-x11.h
    26 HEADERS += volumebase.h volumecontrol.h virtualkeyboard.h visual.h xmlparse.h
     26HEADERS += volumebase.h virtualkeyboard.h visual.h xmlparse.h
    2727HEADERS += mythhdd.h mythcdrom.h storagegroup.h dbutil.h
    2828HEADERS += compat.h
    2929
    3030SOURCES += audiooutput.cpp audiooutputbase.cpp audiooutputnull.cpp
    31 SOURCES += audiooutputdigitalencoder.cpp
     31SOURCES += audiooutputdigitalencoder.cpp audiosettings.cpp
    3232SOURCES += backendselect.cpp dbsettings.cpp dialogbox.cpp
    3333SOURCES += DisplayRes.cpp DisplayResScreen.cpp
    3434SOURCES += generictree.cpp httpcomms.cpp langsettings.cpp lcddevice.cpp
     
    4040SOURCES += oldsettings.cpp output.cpp qmdcodec.cpp remotefile.cpp
    4141SOURCES += screensaver.cpp screensaver-null.cpp settings.cpp themeinfo.cpp
    4242SOURCES += uilistbtntype.cpp uitypes.cpp util.cpp util-x11.cpp
    43 SOURCES += volumebase.cpp volumecontrol.cpp virtualkeyboard.cpp xmlparse.cpp
     43SOURCES += volumebase.cpp virtualkeyboard.cpp xmlparse.cpp
    4444SOURCES += mythhdd.cpp mythcdrom.cpp storagegroup.cpp dbutil.cpp
    4545
    4646INCLUDEPATH += ../libmythsamplerate ../libmythsoundtouch ../libmythfreesurround
     
    7070inc.files  = dialogbox.h lcddevice.h mythcontext.h mythdbcon.h mythverbose.h
    7171inc.files += mythwidgets.h remotefile.h util.h oldsettings.h volumecontrol.h
    7272inc.files += settings.h uitypes.h xmlparse.h mythplugin.h mythdialogs.h
    73 inc.files += audiooutput.h inetcomms.h httpcomms.h mythmedia.h mythwizard.h
     73inc.files += audiooutput.h audiosettings.h
     74inc.files += inetcomms.h httpcomms.h mythmedia.h mythwizard.h
    7475inc.files += uilistbtntype.h generictree.h managedlist.h mythmediamonitor.h
    7576inc.files += visual.h volumebase.h output.h langsettings.h qmdcodec.h
    7677inc.files += exitcodes.h mythconfig.h mythconfig.mak virtualkeyboard.h
  • libs/libmyth/audiosettings.h

     
     1/* -*- Mode: c++ -*-
     2 *
     3 * Copyright (C) Daniel Kristjansson 2008
     4 *
     5 * Licensed under the GPL v2 or a later version at your choosing.
     6 */
     7
     8#ifndef _AUDIO_SETTINGS_H_
     9#define _AUDIO_SETTINGS_H_
     10
     11#include <qstring.h>
     12
     13typedef enum {
     14    AUDIOOUTPUT_UNKNOWN,
     15    AUDIOOUTPUT_VIDEO,
     16    AUDIOOUTPUT_MUSIC,
     17    AUDIOOUTPUT_TELEPHONY,
     18} AudioOutputSource;
     19
     20class AudioSettings
     21{
     22  public:
     23    AudioSettings();
     24    AudioSettings(const AudioSettings &other);
     25    AudioSettings(
     26        const QString    &audio_main_device,
     27        const QString    &audio_passthru_device,
     28        int               audio_bits,
     29        int               audio_channels,
     30        int               audio_samplerate,
     31        AudioOutputSource audio_source,
     32        bool              audio_set_initial_vol,
     33        bool              audio_use_passthru,
     34        void             *audio_codec = NULL);
     35
     36    AudioSettings(int   audio_bits,
     37                  int   audio_channels,
     38                  int   audio_samplerate,
     39                  bool  audio_use_passthru,
     40                  void *audio_codec = NULL);
     41
     42    void FixPassThrough(void);
     43    void TrimDeviceType(void);
     44
     45    QString GetMainDevice(void) const;
     46    QString GetPassthruDevice(void) const;
     47
     48  private:
     49    QString main_device;
     50    QString passthru_device;
     51
     52  public:
     53    int     bits;
     54    int     channels;
     55    int     samplerate;
     56    bool    set_initial_vol;
     57    bool    use_passthru;
     58    void   *codec;
     59    AudioOutputSource source;
     60};
     61
     62#endif // _AUDIO_SETTINGS_H_
  • libs/libmyth/audiooutputca.h

     
    1818class AudioOutputCA : public AudioOutputBase
    1919{
    2020public:
    21     AudioOutputCA(QString laudio_main_device,
    22                   QString laudio_passthru_device,
    23                   int laudio_bits,
    24                   int laudio_channels, int laudio_samplerate,
    25                   AudioOutputSource lsource,
    26                   bool lset_initial_vol, bool laudio_passthru);
     21    AudioOutputCA(const AudioSettings &settings);
    2722    virtual ~AudioOutputCA();
    2823   
    29     virtual int GetAudiotime(void);
     24    virtual int GetAudiotime(void) const;
    3025    void        SetAudiotime(void);
    3126
    3227    // callback for delivering audio to output device
     
    5247    virtual bool OpenDevice(void);
    5348    virtual void CloseDevice(void);
    5449    virtual void WriteAudio(unsigned char *aubuf, int size);
    55     virtual int getSpaceOnSoundcard(void);
    56     virtual int getBufferedOnSoundcard(void);
     50    virtual int  GetSpaceOnSoundcard(void) const;
     51    virtual int  GetBufferedOnSoundcard(void) const;
    5752   
    5853    virtual bool StartOutputThread(void) { return true; }
    5954    virtual void StopOutputThread(void) {}
  • libs/libmyth/audiooutputoss.cpp

     
    2525#include "audiooutputoss.h"
    2626#include "util.h"
    2727
    28 AudioOutputOSS::AudioOutputOSS(
    29     QString laudio_main_device, QString           laudio_passthru_device,
    30     int     laudio_bits,        int               laudio_channels,
    31     int     laudio_samplerate,  AudioOutputSource lsource,
    32     bool    lset_initial_vol,   bool              laudio_passthru) :
    33     AudioOutputBase(laudio_main_device, laudio_passthru_device,
    34                     laudio_bits,        laudio_channels,
    35                     laudio_samplerate,  lsource,
    36                     lset_initial_vol,   laudio_passthru),
     28AudioOutputOSS::AudioOutputOSS(const AudioSettings &settings) :
     29    AudioOutputBase(settings),
    3730    audiofd(-1), numbadioctls(0),
    3831    mixerfd(-1), control(SOUND_MIXER_VOLUME)
    3932{
    4033    // Set everything up
    41     Reconfigure(laudio_bits,       laudio_channels,
    42                 laudio_samplerate, laudio_passthru);
     34    Reconfigure(settings);
    4335}
    4436
    4537AudioOutputOSS::~AudioOutputOSS()
     
    249241}
    250242
    251243
    252 inline int AudioOutputOSS::getBufferedOnSoundcard(void)
     244int AudioOutputOSS::GetBufferedOnSoundcard(void) const
    253245{
    254246    int soundcard_buffer=0;
    255247//GREG This is needs to be fixed for sure!
     
    259251    return soundcard_buffer;
    260252}
    261253
    262 
    263 inline int AudioOutputOSS::getSpaceOnSoundcard(void)
     254int AudioOutputOSS::GetSpaceOnSoundcard(void) const
    264255{
    265256    audio_buf_info info;
    266257    int space = 0;
     
    340331    }
    341332}
    342333
    343 int AudioOutputOSS::GetVolumeChannel(int channel)
     334int AudioOutputOSS::GetVolumeChannel(int channel) const
    344335{
    345336    int volume=0;
    346337    int tmpVol=0;
  • libs/libmyth/audiooutputdx.cpp

     
    287287    effdsp = dsprate / 100;
    288288}
    289289
    290 bool AudioOutputDX::GetPause(void)
    291 {
    292     return paused;
    293 }
    294 
    295290void AudioOutputDX::Pause(bool pause)
    296291{
    297292    HRESULT dsresult;
     
    326321    paused = pause;
    327322}
    328323
    329 int AudioOutputDX::GetAudiotime(void)
     324int AudioOutputDX::GetAudiotime(void) const
    330325{
    331326    DWORD play_pos;
    332327    HRESULT dsresult;
     
    746741
    747742}
    748743
    749 int AudioOutputDX::GetVolumeChannel(int channel)
     744int AudioOutputDX::GetVolumeChannel(int channel) const
    750745{
    751746    // Do nothing
    752747    return 100;
  • libs/libmyth/audiooutputnull.h

     
    2323
    2424class AudioOutputNULL : public AudioOutputBase
    2525{
    26 public:
    27     AudioOutputNULL(QString laudio_main_device,
    28                     QString laudio_passthru_device,
    29                     int laudio_bits,
    30                     int laudio_channels, int laudio_samplerate,
    31                     AudioOutputSource lsource,
    32                     bool lset_initial_vol, bool laudio_passthru);
     26  public:
     27    AudioOutputNULL(const AudioSettings &settings);
     28
    3329    virtual ~AudioOutputNULL();
    3430
    3531    virtual void Reset(void);
    3632
    3733
    3834    // Volume control
    39     virtual int GetVolumeChannel(int /* channel */){ return 100; }
    40     virtual void SetVolumeChannel(int /* channel */, int /* volume */){ return; }
     35    virtual int GetVolumeChannel(int /* channel */) const { return 100; }
     36    virtual void SetVolumeChannel(int /* channel */, int /* volume */){return;}
    4137
    4238    virtual int readOutputData(unsigned char *read_buffer, int max_length);
    4339
    44 protected:
    45     // You need to implement the following functions
     40  protected:
     41    // AudioOutputBase
    4642    virtual bool OpenDevice(void);
    4743    virtual void CloseDevice(void);
    4844    virtual void WriteAudio(unsigned char *aubuf, int size);
    49     virtual inline int getSpaceOnSoundcard(void);
    50     virtual inline int getBufferedOnSoundcard(void);
     45    virtual int  GetSpaceOnSoundcard(void) const;
     46    virtual int  GetBufferedOnSoundcard(void) const;
    5147
    52 private:
    53 
     48  private:
    5449    QMutex        pcm_output_buffer_mutex;
    5550    unsigned char pcm_output_buffer[NULLAUDIO_OUTPUT_BUFFER_SIZE];
    5651    int           current_buffer_size;
  • libs/libmyth/audiooutput.h

     
    11#ifndef AUDIOOUTPUT
    22#define AUDIOOUTPUT
    33
    4 #include <iostream>
    5 using namespace std;
     4#include <qstring.h>
    65
     6#include "audiosettings.h"
    77#include "mythcontext.h"
    88#include "volumebase.h"
    99#include "output.h"
    1010
    11 typedef enum {
    12     AUDIOOUTPUT_VIDEO,
    13     AUDIOOUTPUT_MUSIC,
    14     AUDIOOUTPUT_TELEPHONY
    15 } AudioOutputSource;
    16 
    1711class MPUBLIC AudioOutput : public VolumeBase, public OutputListeners
    1812{
    1913 public:
    2014    // opens one of the concrete subclasses
    21     static AudioOutput *OpenAudio(QString audiodevice, QString passthrudevice,
    22                                   int audio_bits,
    23                                   int audio_channels, int audio_samplerate,
    24                                   AudioOutputSource source,
    25                                   bool set_initial_vol, bool audio_passthru);
     15    static AudioOutput *OpenAudio(
     16        const QString &audiodevice,
     17        const QString &passthrudevice,
     18        int audio_bits, int audio_channels, int audio_samplerate,
     19        AudioOutputSource source,
     20        bool set_initial_vol, bool audio_passthru);
    2621
    2722    AudioOutput() :
    2823        VolumeBase(),             OutputListeners(),
     
    3126    virtual ~AudioOutput() { };
    3227
    3328    // reconfigure sound out for new params
    34     virtual void Reconfigure(int audio_bits,
    35                              int audio_channels,
    36                              int audio_samplerate,
    37                              bool audio_passthru,
    38                              void* audio_codec = NULL) = 0;
     29    virtual void Reconfigure(const AudioSettings &settings) = 0;
    3930   
    4031    virtual void SetStretchFactor(float factor);
    41     virtual float GetStretchFactor(void) { return 1.0f; }
     32    virtual float GetStretchFactor(void) const { return 1.0f; }
    4233
    4334    // do AddSamples calls block?
    4435    virtual void SetBlocking(bool blocking) = 0;
     
    5445    virtual bool AddSamples(char *buffers[], int samples, long long timecode) = 0;
    5546
    5647    virtual void SetTimecode(long long timecode) = 0;
    57     virtual bool GetPause(void) = 0;
     48    virtual bool IsPaused(void) const = 0;
    5849    virtual void Pause(bool paused) = 0;
    5950 
    6051    // Wait for all data to finish playing
    6152    virtual void Drain(void) = 0;
    6253
    63     virtual int GetAudiotime(void) = 0;
     54    virtual int GetAudiotime(void) const = 0;
    6455
    6556    virtual void SetSourceBitrate(int ) { }
    6657
    6758    QString GetError(void)   const { return lastError; }
    6859    QString GetWarning(void) const { return lastWarn; }
    6960
    70     virtual void GetBufferStatus(uint &fill, uint &total) { fill = total = 0; }
     61    virtual void GetBufferStatus(uint &fill, uint &total) const
     62        { fill = total = 0; }
    7163
    7264    //  Only really used by the AudioOutputNULL object
    7365   
     
    7567    virtual int readOutputData(unsigned char *read_buffer, int max_length) = 0;
    7668
    7769  protected:
    78     void Error(QString msg)
    79     {
    80         lastError = msg;
    81         VERBOSE(VB_IMPORTANT, "AudioOutput Error: " + lastError);
    82     }
    83     void ClearError(void) { lastError = QString::null; }
     70    void Error(const QString &msg);
     71    void Warn(const QString &msg);
     72    void ClearError(void);
     73    void ClearWarning(void);
    8474
    85     void Warn(QString msg)
    86     {
    87         lastWarn  = msg;
    88         VERBOSE(VB_IMPORTANT, "AudioOutput Warning: " + lastWarn);
    89     }
    90 
    9175  protected:
    9276    QString lastError;
    9377    QString lastWarn;
  • libs/libmyth/audiooutputarts.h

     
    1414class AudioOutputARTS : public AudioOutputBase
    1515{
    1616  public:
    17      AudioOutputARTS(QString main_device, QString passthru_device,
    18                      int audio_bits,
    19                      int audio_channels, int audio_samplerate,
    20                      AudioOutputSource source,
    21                      bool set_initial_vol, bool laudio_passthru);
     17     AudioOutputARTS(const AudioSettings &settings);
    2218     virtual ~AudioOutputARTS();
    2319
    2420    // Volume control
    25     virtual int GetVolumeChannel(int channel); // Returns 0-100
     21    virtual int GetVolumeChannel(int channel) const; // Returns 0-100
    2622    virtual void SetVolumeChannel(int channel, int volume); // range 0-100 for vol
    2723
    2824  protected:
     
    3127    virtual bool OpenDevice(void);
    3228    virtual void CloseDevice(void);
    3329    virtual void WriteAudio(unsigned char *aubuf, int size);
    34     virtual inline int getSpaceOnSoundcard(void);
    35     virtual inline int getBufferedOnSoundcard(void);
     30    virtual int  GetSpaceOnSoundcard(void) const;
     31    virtual int  GetBufferedOnSoundcard(void) const;
    3632
    3733     
    3834
  • libs/libmyth/audiooutputdx.h

     
    1717class AudioOutputDX : public AudioOutputBase
    1818{
    1919public:
    20     AudioOutputDX(QString laudio_main_device,
    21                   QString laudio_passthru_device,
    22                   int laudio_bits,
    23                   int laudio_channels, int laudio_samplerate,
    24                   AudioOutputSource lsource,
    25                   bool lset_initial_vol, bool laudio_passthru);
     20    AudioOutputDX(const AudioSettings &settings);
    2621    virtual ~AudioOutputDX();
    2722
    2823    /// BEGIN HACK HACK HACK HACK These need to actually be implemented!
    2924    bool OpenDevice(void) { return false; }
    30     void CloseDevice(void) {}
    31     void WriteAudio(unsigned char*, int) {}
    32     virtual int getSpaceOnSoundcard(void) { return 0; }
    33     virtual int getBufferedOnSoundcard(void) { return 0; }
     25    virtual void CloseDevice(void) {}
     26    virtual void WriteAudio(unsigned char*, int) {}
     27    virtual int  GetSpaceOnSoundcard(void)    const { return 0; }
     28    virtual int  GetBufferedOnSoundcard(void) const { return 0; }
    3429#warning Several methods in AudioOutputDX need to be implemented...
    3530    /// END HACK HACK HACK HACK
    3631       
    3732    virtual void Reset(void);
    38     virtual void Reconfigure(int audio_bits,
    39                              int audio_channels,
    40                              int audio_samplerate,
    41                              bool audio_passthru);
     33    virtual void Reconfigure(const AudioSettings &settings);
    4234    virtual void SetBlocking(bool blocking);
    4335
    4436    virtual bool AddSamples(char *buffer, int samples, long long timecode);
     
    4638    virtual void SetEffDsp(int dsprate);
    4739    virtual void SetTimecode(long long timecode);
    4840
    49     virtual bool GetPause(void);
     41    virtual bool IsPaused(void) const { return paused; }
    5042    virtual void Pause(bool paused);
    5143
    5244    virtual void Drain(void);
    5345
    54     virtual int GetAudiotime(void);
     46    virtual int GetAudiotime(void) const;
    5547
    5648    // Volume control
    5749    virtual int GetVolumeChannel(int channel); // Returns 0-100
  • libs/libmyth/audiooutputalsa.h

     
    1313
    1414using namespace std;
    1515
     16class ALSAVolumeInfo
     17{
     18  public:
     19    ALSAVolumeInfo(long  playback_vol_min,
     20                   long  playback_vol_max) :
     21        range_multiplier(1.0f),
     22        volume_min(playback_vol_min), volume_max(playback_vol_max)
     23    {
     24        float range = (float) (volume_max - volume_min);
     25        if (range > 0.0f)
     26            range_multiplier = 100.0f / range;
     27        range_multiplier_inv = 1.0f / range_multiplier;
     28    }
     29
     30    int ToMythRange(long alsa_volume)
     31    {
     32        long toz = alsa_volume - volume_min;
     33        int val = (int) (toz * range_multiplier);
     34        val = (val < 0)   ? 0   : val;
     35        val = (val > 100) ? 100 : val;
     36        return val;
     37    }
     38
     39    long ToALSARange(int myth_volume)
     40    {
     41        float tos = myth_volume * range_multiplier_inv;
     42        long val = (long) (tos + volume_min + 0.5);
     43        val = (val < volume_min) ? volume_min : val;
     44        val = (val > volume_max) ? volume_max : val;
     45        return val;
     46    }
     47
     48    float range_multiplier;
     49    float range_multiplier_inv;
     50    long  volume_min;
     51    long  volume_max;
     52};
     53
    1654class AudioOutputALSA : public AudioOutputBase
    1755{
    1856  public:
    19     AudioOutputALSA(QString laudio_main_device, QString laudio_passthru_device,
    20                     int laudio_bits,
    21                     int laudio_channels, int laudio_samplerate,
    22                     AudioOutputSource source,
    23                     bool set_initial_vol, bool laudio_passthru);
     57    AudioOutputALSA(const AudioSettings &settings);
    2458    virtual ~AudioOutputALSA();
    2559
    2660    // Volume control
    27     virtual int GetVolumeChannel(int channel); // Returns 0-100
     61    virtual int GetVolumeChannel(int channel) const; // Returns 0-100
    2862    virtual void SetVolumeChannel(int channel, int volume); // range 0-100 for vol
    2963
    3064   
     
    3367    virtual bool OpenDevice(void);
    3468    virtual void CloseDevice(void);
    3569    virtual void WriteAudio(unsigned char *aubuf, int size);
    36     virtual inline int getSpaceOnSoundcard(void);
    37     virtual inline int getBufferedOnSoundcard(void);
     70    virtual int  GetSpaceOnSoundcard(void) const;
     71    virtual int  GetBufferedOnSoundcard(void) const;
    3872
    3973  private:
    4074    inline int SetParameters(snd_pcm_t *handle,
     
    4882    void OpenMixer(bool setstartingvolume);
    4983    void CloseMixer(void);
    5084    void SetupMixer(void);
    51     void GetVolumeRange(snd_mixer_elem_t *elem);
     85    ALSAVolumeInfo GetVolumeRange(snd_mixer_elem_t *elem) const;
    5286
    5387  private:
    5488    snd_pcm_t   *pcm_handle;
     
    5690    QMutex       killAudioLock;
    5791    snd_mixer_t *mixer_handle;
    5892    QString      mixer_control; // e.g. "PCM"
    59     float        volume_range_multiplier;
    60     long         playback_vol_min;
    61     long         playback_vol_max;
    6293    snd_pcm_sframes_t (*pcm_write_func)(
    6394        snd_pcm_t*, const void*, snd_pcm_uframes_t);
    6495};
  • programs/mythtranscode/transcode.cpp

     
    4141    AudioReencodeBuffer(int audio_bits, int audio_channels)
    4242    {
    4343        Reset();
    44         Reconfigure(audio_bits, audio_channels, 0, 0);
     44        const AudioSettings settings(audio_bits, audio_channels, 0, false);
     45        Reconfigure(settings);
    4546        bufsize = 512000;
    4647        audiobuffer = new unsigned char[bufsize];
    4748
     
    5758    }
    5859
    5960    // reconfigure sound out for new params
    60     virtual void Reconfigure(int audio_bits, int audio_channels,
    61                              int audio_samplerate, bool audio_passthru,
    62                              void *audio_codec = NULL)
     61    virtual void Reconfigure(const AudioSettings &settings)
    6362    {
    64         (void)audio_samplerate;
    65         (void)audio_passthru;
    66         (void)audio_codec;
    67 
    6863        ClearError();
    69         bits = audio_bits;
    70         channels = audio_channels;
     64        bits = settings.bits;
     65        channels = settings.channels;
    7166        bytes_per_sample = bits * channels / 8;
    72         if ((uint)audio_channels > 2)
     67        if ((uint)settings.channels > 2)
    7368            Error(QString("Invalid channel count %1").arg(channels));
    7469    }
    7570
     
    156151    {
    157152        last_audiotime = timecode;
    158153    }
    159     virtual bool GetPause(void)
     154    virtual bool IsPaused(void) const
    160155    {
    161156        return false;
    162157    }
     
    170165        return;
    171166    }
    172167
    173     virtual int GetAudiotime(void)
     168    virtual int GetAudiotime(void) const
    174169    {
    175170        return last_audiotime;
    176171    }
    177172
    178     virtual int GetVolumeChannel(int)
     173    virtual int GetVolumeChannel(int) const
    179174    {
    180175        // Do nothing
    181176        return 100;
     
    190185    }
    191186   
    192187
    193     virtual int GetCurrentVolume(void)
     188    virtual int GetCurrentVolume(void) const
    194189    {
    195190        // Do nothing
    196191        return 100;
     
    211206    {
    212207        // Do nothing
    213208    }
    214     virtual kMuteState GetMute(void)
     209    virtual kMuteState GetMute(void) const
    215210    {
    216211        // Do nothing
    217212        return MUTE_OFF;