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 using namespace std;
19 
20 #include "mythlogging.h"
21 #include "audiooutputnull.h"
22 
23 #define CHANNELS_MIN 1
24 #define CHANNELS_MAX 8
25 
27  AudioOutputBase(settings)
28 {
29  InitSettings(settings);
30  if (settings.m_init)
31  Reconfigure(settings);
32 }
33 
35 {
36  KillAudio();
37 }
38 
40 {
41  LOG(VB_GENERAL, LOG_INFO, "Opening NULL audio device, will fail.");
42 
45 
46  return false;
47 }
48 
50 {
51 }
52 
54 {
55  // Pretend that we support everything
56  auto *settings = new AudioOutputSettings();
57 
58  // NOLINTNEXTLINE(bugprone-infinite-loop)
59  while (int rate = settings->GetNextRate())
60  {
61  settings->AddSupportedRate(rate);
62  }
63 
64  // NOLINTNEXTLINE(bugprone-infinite-loop)
65  while (AudioFormat fmt = settings->GetNextFormat())
66  {
67  settings->AddSupportedFormat(fmt);
68  }
69 
70  for (uint channels = CHANNELS_MIN; channels <= CHANNELS_MAX; channels++)
71  {
72  settings->AddSupportedChannels(channels);
73  }
74 
75  settings->setPassthrough(-1); // no passthrough
76 
77  return settings;
78 }
79 
80 
81 void AudioOutputNULL::WriteAudio(unsigned char* aubuf, int size)
82 {
84  {
86  {
87  LOG(VB_GENERAL, LOG_ERR, "null audio output should not have just "
88  "had data written to it");
89  return;
90  }
92  memcpy(m_pcmOutputBuffer + m_currentBufferSize, aubuf, size);
93  m_currentBufferSize += size;
94  m_pcmOutputBufferMutex.unlock();
95  }
96 }
97 
98 int AudioOutputNULL::readOutputData(unsigned char *read_buffer, int max_length)
99 {
100  int amount_to_read = max_length;
101  if (amount_to_read > m_currentBufferSize)
102  {
103  amount_to_read = m_currentBufferSize;
104  }
105 
106  m_pcmOutputBufferMutex.lock();
107  memcpy(read_buffer, m_pcmOutputBuffer, amount_to_read);
108  memmove(m_pcmOutputBuffer, m_pcmOutputBuffer + amount_to_read,
109  m_currentBufferSize - amount_to_read);
110  m_currentBufferSize -= amount_to_read;
111  m_pcmOutputBufferMutex.unlock();
112 
113  return amount_to_read;
114 }
115 
117 {
119  {
120  m_pcmOutputBufferMutex.lock();
122  m_pcmOutputBufferMutex.unlock();
123  }
125 }
126 
128 {
130  {
131  return m_currentBufferSize;
132  }
133 
134  return 0;
135 }
void WriteAudio(unsigned char *aubuf, int size) override
void InitSettings(const AudioSettings &settings)
bool OpenDevice(void) override
#define CHANNELS_MIN
void Reset(void) override
Reset the audiobuffer, timecode and mythmusic visualisation.
AudioOutputNULL(const AudioSettings &settings)
AudioOutputSettings * GetOutputSettings(bool digital) override
void Reset(void) override
Reset the audiobuffer, timecode and mythmusic visualisation.
#define CHANNELS_MAX
unsigned int uint
Definition: compat.h:140
unsigned char m_pcmOutputBuffer[NULLAUDIO_OUTPUT_BUFFER_SIZE]
int readOutputData(unsigned char *read_buffer, int max_length) override
~AudioOutputNULL() override
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QMutex m_pcmOutputBufferMutex
void KillAudio(void)
Kill the output thread and cleanup.
void Reconfigure(const AudioSettings &settings) override
(Re)Configure AudioOutputBase
int GetBufferedOnSoundcard(void) const override
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
void CloseDevice(void) override
bool m_init
If set to false, AudioOutput instance will not try to initially open the audio device.
Definition: audiosettings.h:84
#define NULLAUDIO_OUTPUT_BUFFER_SIZE