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 "libmythbase/compat.h"
14 #endif
15 
17 #include "audiooutputnull.h"
18 
19 static constexpr uint8_t CHANNELS_MIN { 1 };
20 static constexpr uint8_t CHANNELS_MAX { 8 };
21 
23  AudioOutputBase(settings)
24 {
25  InitSettings(settings);
26  if (settings.m_init)
27  Reconfigure(settings);
28 }
29 
31 {
32  KillAudio();
33 }
34 
36 {
37  LOG(VB_GENERAL, LOG_INFO, "Opening NULL audio device, will fail.");
38 
41 
42  return false;
43 }
44 
46 {
47 }
48 
50 {
51  // Pretend that we support everything
52  auto *settings = new AudioOutputSettings();
53 
54  // NOLINTNEXTLINE(bugprone-infinite-loop)
55  while (int rate = settings->GetNextRate())
56  {
57  settings->AddSupportedRate(rate);
58  }
59 
60  // NOLINTNEXTLINE(bugprone-infinite-loop)
61  while (AudioFormat fmt = settings->GetNextFormat())
62  {
63  settings->AddSupportedFormat(fmt);
64  }
65 
66  for (uint channels = CHANNELS_MIN; channels <= CHANNELS_MAX; channels++)
67  {
68  settings->AddSupportedChannels(channels);
69  }
70 
71  settings->setPassthrough(-1); // no passthrough
72 
73  return settings;
74 }
75 
76 
77 void AudioOutputNULL::WriteAudio(unsigned char* aubuf, int size)
78 {
80  {
82  {
83  LOG(VB_GENERAL, LOG_ERR, "null audio output should not have just "
84  "had data written to it");
85  return;
86  }
88  m_pcmOutputBuffer.insert(m_pcmOutputBuffer.end(), aubuf, aubuf+size);
89  m_pcmOutputBufferMutex.unlock();
90  }
91 }
92 
93 int AudioOutputNULL::readOutputData(unsigned char *read_buffer, size_t max_length)
94 {
95  size_t amount_to_read = max_length;
96  if (amount_to_read > m_pcmOutputBuffer.size())
97  {
98  amount_to_read = m_pcmOutputBuffer.size();
99  }
100 
101  m_pcmOutputBufferMutex.lock();
102  std::copy(m_pcmOutputBuffer.cbegin(),
103  m_pcmOutputBuffer.cbegin() + amount_to_read,
104  read_buffer);
105  m_pcmOutputBuffer.erase(m_pcmOutputBuffer.cbegin(),
106  m_pcmOutputBuffer.cbegin() + amount_to_read);
107  m_pcmOutputBufferMutex.unlock();
108 
109  return amount_to_read;
110 }
111 
113 {
115  {
116  m_pcmOutputBufferMutex.lock();
117  m_pcmOutputBuffer.clear();
118  m_pcmOutputBufferMutex.unlock();
119  }
121 }
122 
124 {
126  return m_pcmOutputBuffer.size();
127 
128  return 0;
129 }
AudioOutputBase::Reset
void Reset(void) override
Reset the audiobuffer, timecode and mythmusic visualisation.
Definition: audiooutputbase.cpp:932
AudioOutputNULL::m_pcmOutputBufferMutex
QMutex m_pcmOutputBufferMutex
Definition: audiooutputnull.h:47
AudioOutputNULL::CloseDevice
void CloseDevice(void) override
Definition: audiooutputnull.cpp:45
AudioOutputNULL::AudioOutputNULL
AudioOutputNULL(const AudioSettings &settings)
Definition: audiooutputnull.cpp:22
AudioOutputBase::m_bufferOutputDataForUse
bool m_bufferOutputDataForUse
Definition: audiooutputbase.h:204
AudioOutputNULL::WriteAudio
void WriteAudio(unsigned char *aubuf, int size) override
Definition: audiooutputnull.cpp:77
AudioOutputNULL::Reset
void Reset(void) override
Reset the audiobuffer, timecode and mythmusic visualisation.
Definition: audiooutputnull.cpp:112
AudioOutputBase::KillAudio
void KillAudio(void)
Kill the output thread and cleanup.
Definition: audiooutputbase.cpp:868
CHANNELS_MAX
static constexpr uint8_t CHANNELS_MAX
Definition: audiooutputnull.cpp:20
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
AudioOutputNULL::OpenDevice
bool OpenDevice(void) override
Definition: audiooutputnull.cpp:35
AudioSettings
Definition: audiosettings.h:28
AudioOutputBase::m_soundcardBufferSize
long m_soundcardBufferSize
Definition: audiooutputbase.h:183
AudioOutputBase
Definition: audiooutputbase.h:51
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
MythFile::copy
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.
Definition: mythmiscutil.cpp:264
compat.h
AudioOutputBase::Reconfigure
void Reconfigure(const AudioSettings &settings) override
(Re)Configure AudioOutputBase
Definition: audiooutputbase.cpp:474
AudioOutputNULL::m_pcmOutputBuffer
std::vector< unsigned char > m_pcmOutputBuffer
Definition: audiooutputnull.h:48
uint
unsigned int uint
Definition: compat.h:79
NULLAUDIO_OUTPUT_BUFFER_SIZE
static constexpr int32_t NULLAUDIO_OUTPUT_BUFFER_SIZE
Definition: audiooutputnull.h:6
CHANNELS_MIN
static constexpr uint8_t CHANNELS_MIN
Definition: audiooutputnull.cpp:19
AudioOutputNULL::GetOutputSettings
AudioOutputSettings * GetOutputSettings(bool digital) override
Definition: audiooutputnull.cpp:49
AudioOutputSettings
Definition: audiooutputsettings.h:48
AudioOutputBase::InitSettings
void InitSettings(const AudioSettings &settings)
Definition: audiooutputbase.cpp:125
AudioOutputNULL::readOutputData
int readOutputData(unsigned char *read_buffer, size_t max_length) override
Definition: audiooutputnull.cpp:93
AudioOutputBase::m_fragmentSize
int m_fragmentSize
Definition: audiooutputbase.h:182
AudioFormat
AudioFormat
Definition: audiooutputsettings.h:24
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:123
AudioOutputNULL::~AudioOutputNULL
~AudioOutputNULL() override
Definition: audiooutputnull.cpp:30