MythTV  master
audiooutputnull.cpp
Go to the documentation of this file.
1 #include <cerrno>
2 #include <cstdio>
3 #include <cstdlib>
4 #include <cstring>
5 #include <ctime>
6 #include <fcntl.h>
7 #include <iostream>
8 #include <sys/time.h>
9 #include <unistd.h>
10 #ifndef _WIN32
11 #include <sys/ioctl.h>
12 #else
13 #include "compat.h"
14 #endif
15 
16 #include "config.h"
17 
18 #include "mythlogging.h"
19 #include "audiooutputnull.h"
20 
21 #define CHANNELS_MIN 1
22 #define CHANNELS_MAX 8
23 
25  AudioOutputBase(settings)
26 {
27  InitSettings(settings);
28  if (settings.m_init)
29  Reconfigure(settings);
30 }
31 
33 {
34  KillAudio();
35 }
36 
38 {
39  LOG(VB_GENERAL, LOG_INFO, "Opening NULL audio device, will fail.");
40 
43 
44  return false;
45 }
46 
48 {
49 }
50 
52 {
53  // Pretend that we support everything
54  auto *settings = new AudioOutputSettings();
55 
56  // NOLINTNEXTLINE(bugprone-infinite-loop)
57  while (int rate = settings->GetNextRate())
58  {
59  settings->AddSupportedRate(rate);
60  }
61 
62  // NOLINTNEXTLINE(bugprone-infinite-loop)
63  while (AudioFormat fmt = settings->GetNextFormat())
64  {
65  settings->AddSupportedFormat(fmt);
66  }
67 
68  for (uint channels = CHANNELS_MIN; channels <= CHANNELS_MAX; channels++)
69  {
70  settings->AddSupportedChannels(channels);
71  }
72 
73  settings->setPassthrough(-1); // no passthrough
74 
75  return settings;
76 }
77 
78 
79 void AudioOutputNULL::WriteAudio(unsigned char* aubuf, int size)
80 {
82  {
84  {
85  LOG(VB_GENERAL, LOG_ERR, "null audio output should not have just "
86  "had data written to it");
87  return;
88  }
90  m_pcmOutputBuffer.insert(m_pcmOutputBuffer.end(), aubuf, aubuf+size);
91  m_pcmOutputBufferMutex.unlock();
92  }
93 }
94 
95 int AudioOutputNULL::readOutputData(unsigned char *read_buffer, size_t max_length)
96 {
97  size_t amount_to_read = max_length;
98  if (amount_to_read > m_pcmOutputBuffer.size())
99  {
100  amount_to_read = m_pcmOutputBuffer.size();
101  }
102 
103  m_pcmOutputBufferMutex.lock();
104  std::copy(m_pcmOutputBuffer.cbegin(),
105  m_pcmOutputBuffer.cbegin() + amount_to_read,
106  read_buffer);
107  m_pcmOutputBuffer.erase(m_pcmOutputBuffer.cbegin(),
108  m_pcmOutputBuffer.cbegin() + amount_to_read);
109  m_pcmOutputBufferMutex.unlock();
110 
111  return amount_to_read;
112 }
113 
115 {
117  {
118  m_pcmOutputBufferMutex.lock();
119  m_pcmOutputBuffer.clear();
120  m_pcmOutputBufferMutex.unlock();
121  }
123 }
124 
126 {
128  return m_pcmOutputBuffer.size();
129 
130  return 0;
131 }
AudioOutputBase::Reset
void Reset(void) override
Reset the audiobuffer, timecode and mythmusic visualisation.
Definition: audiooutputbase.cpp:924
AudioOutputNULL::m_pcmOutputBufferMutex
QMutex m_pcmOutputBufferMutex
Definition: audiooutputnull.h:47
AudioOutputNULL::CloseDevice
void CloseDevice(void) override
Definition: audiooutputnull.cpp:47
AudioOutputNULL::AudioOutputNULL
AudioOutputNULL(const AudioSettings &settings)
Definition: audiooutputnull.cpp:24
copy
long long copy(QFile &dst, QFile &src, uint block_size)
Copies src file to dst file.
Definition: mythmiscutil.cpp:314
CHANNELS_MIN
#define CHANNELS_MIN
Definition: audiooutputnull.cpp:21
AudioOutputBase::m_bufferOutputDataForUse
bool m_bufferOutputDataForUse
Definition: audiooutputbase.h:202
AudioOutputNULL::WriteAudio
void WriteAudio(unsigned char *aubuf, int size) override
Definition: audiooutputnull.cpp:79
AudioOutputNULL::Reset
void Reset(void) override
Reset the audiobuffer, timecode and mythmusic visualisation.
Definition: audiooutputnull.cpp:114
AudioOutputBase::KillAudio
void KillAudio(void)
Kill the output thread and cleanup.
Definition: audiooutputbase.cpp:860
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
AudioOutputNULL::OpenDevice
bool OpenDevice(void) override
Definition: audiooutputnull.cpp:37
AudioSettings
Definition: audiosettings.h:28
AudioOutputBase::m_soundcardBufferSize
long m_soundcardBufferSize
Definition: audiooutputbase.h:181
AudioOutputBase
Definition: audiooutputbase.h:49
AudioSettings::m_init
bool m_init
If set to false, AudioOutput instance will not try to initially open the audio device.
Definition: audiosettings.h:85
mythlogging.h
audiooutputnull.h
compat.h
AudioOutputBase::Reconfigure
void Reconfigure(const AudioSettings &settings) override
(Re)Configure AudioOutputBase
Definition: audiooutputbase.cpp:466
AudioOutputNULL::m_pcmOutputBuffer
std::vector< unsigned char > m_pcmOutputBuffer
Definition: audiooutputnull.h:48
uint
unsigned int uint
Definition: compat.h:144
AudioOutputNULL::GetOutputSettings
AudioOutputSettings * GetOutputSettings(bool digital) override
Definition: audiooutputnull.cpp:51
AudioOutputSettings
Definition: audiooutputsettings.h:49
CHANNELS_MAX
#define CHANNELS_MAX
Definition: audiooutputnull.cpp:22
AudioOutputBase::InitSettings
void InitSettings(const AudioSettings &settings)
Definition: audiooutputbase.cpp:117
AudioOutputNULL::readOutputData
int readOutputData(unsigned char *read_buffer, size_t max_length) override
Definition: audiooutputnull.cpp:95
NULLAUDIO_OUTPUT_BUFFER_SIZE
#define NULLAUDIO_OUTPUT_BUFFER_SIZE
Definition: audiooutputnull.h:6
AudioOutputBase::m_fragmentSize
int m_fragmentSize
Definition: audiooutputbase.h:180
AudioFormat
AudioFormat
Definition: audiooutputsettings.h:25
AudioOutputNULL::GetBufferedOnSoundcard
int GetBufferedOnSoundcard(void) const override
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
Definition: audiooutputnull.cpp:125
AudioOutputNULL::~AudioOutputNULL
~AudioOutputNULL() override
Definition: audiooutputnull.cpp:32