diff options
| author | Thomas Reufer <thomas@reufer.ch> | 2014-06-15 18:57:16 +0200 |
|---|---|---|
| committer | Thomas Reufer <thomas@reufer.ch> | 2014-06-15 18:57:16 +0200 |
| commit | 4ea708c5af163339a5dd1565687d9815f1a2bb84 (patch) | |
| tree | e52b2f6430ba50a420075cd9e6341ae33b6ea9a0 | |
| parent | f717b2da8de2806bec23282d663f7d4482fb722e (diff) | |
| download | vdr-plugin-rpihddevice-4ea708c5af163339a5dd1565687d9815f1a2bb84.tar.gz vdr-plugin-rpihddevice-4ea708c5af163339a5dd1565687d9815f1a2bb84.tar.bz2 | |
reworked setup parameter handling
| -rw-r--r-- | HISTORY | 1 | ||||
| -rw-r--r-- | audio.c | 22 | ||||
| -rw-r--r-- | audio.h | 6 | ||||
| -rw-r--r-- | omxdevice.c | 10 | ||||
| -rw-r--r-- | omxdevice.h | 4 | ||||
| -rw-r--r-- | setup.c | 110 | ||||
| -rw-r--r-- | setup.h | 64 |
7 files changed, 142 insertions, 75 deletions
@@ -4,6 +4,7 @@ VDR Plugin 'rpihddevice' Revision History - new: - redirect ffmpeg messages to plugin/VDR logs - added cppcheck as Makefile target (suggested by Rolf Ahrenberg) + - reworked setup parameter handling - fixed: - updated parameter when setting clock latency target according omxplayer - code clean up based on cppcheck's results (thanks to Rolf Ahrenberg) @@ -693,6 +693,7 @@ cRpiAudioDecoder::cRpiAudioDecoder(cOmx *omx) : cThread(), m_passthrough(false), m_reset(false), + m_setupChanged(true), m_wait(new cCondWait()), m_parser(new cParser()), m_omx(omx) @@ -751,6 +752,8 @@ int cRpiAudioDecoder::Init(void) if (ret < 0) DeInit(); + cRpiSetup::SetAudioSetupChangedCallback(&OnAudioSetupChanged, this); + Start(); return ret; @@ -767,6 +770,8 @@ int cRpiAudioDecoder::DeInit(void) while (Active()) cCondWait::SleepMs(50); + cRpiSetup::SetAudioSetupChangedCallback(0); + for (int i = 0; i < cAudioCodec::eNumCodecs; i++) { cAudioCodec::eCodec codec = static_cast<cAudioCodec::eCodec>(i); @@ -814,6 +819,12 @@ bool cRpiAudioDecoder::Poll(void) return m_parser->GetFreeSpace() > KILOBYTE(16); } +void cRpiAudioDecoder::HandleAudioSetupChanged() +{ + DBG("HandleAudioSetupChanged()"); + m_setupChanged = true; +} + void cRpiAudioDecoder::Action(void) { DLOG("cAudioDecoder() thread started"); @@ -821,7 +832,6 @@ void cRpiAudioDecoder::Action(void) unsigned int channels = 0; unsigned int outputChannels = 0; unsigned int samplingRate = 0; - bool setupChanged = true; cAudioCodec::eCodec codec = cAudioCodec::eInvalid; OMX_BUFFERHEADERTYPE *buf = 0; @@ -835,16 +845,14 @@ void cRpiAudioDecoder::Action(void) while (Running()) { - setupChanged |= cRpiSetup::HasAudioSetupChanged(); - // test for codec change if there is data in parser and no left over if (!m_parser->Empty() && !frame->nb_samples) - setupChanged |= codec != m_parser->GetCodec() || + m_setupChanged |= codec != m_parser->GetCodec() || channels != m_parser->GetChannels() || samplingRate != m_parser->GetSamplingRate(); // if necessary, set up audio codec - if (setupChanged) + if (m_setupChanged) { codec = m_parser->GetCodec(); channels = m_parser->GetChannels(); @@ -854,7 +862,7 @@ void cRpiAudioDecoder::Action(void) SetCodec(codec, outputChannels, samplingRate); avcodec_get_frame_defaults(frame); - setupChanged = false; + m_setupChanged = false; if (codec == cAudioCodec::eInvalid) m_reset = true; @@ -873,7 +881,7 @@ void cRpiAudioDecoder::Action(void) // decoding loop while ((!m_parser->Empty() || frame->nb_samples) && buf && !m_reset) { - if (setupChanged |= (codec != m_parser->GetCodec() || + if (m_setupChanged |= (codec != m_parser->GetCodec() || channels != m_parser->GetChannels() || samplingRate != m_parser->GetSamplingRate())) break; @@ -35,6 +35,11 @@ protected: void SetCodec(cAudioCodec::eCodec codec, unsigned int &channels, unsigned int samplingRate); + static void OnAudioSetupChanged(void *data) + { (static_cast <cRpiAudioDecoder*> (data))->HandleAudioSetupChanged(); } + + void HandleAudioSetupChanged(); + static void Log(void* ptr, int level, const char* fmt, va_list vl); static int s_printPrefix; @@ -51,6 +56,7 @@ private: Codec m_codecs[cAudioCodec::eNumCodecs]; bool m_passthrough; bool m_reset; + bool m_setupChanged; cCondWait *m_wait; cParser *m_parser; diff --git a/omxdevice.c b/omxdevice.c index fec8cfd..69b77dd 100644 --- a/omxdevice.c +++ b/omxdevice.c @@ -78,11 +78,16 @@ int cOmxDevice::Init(void) } m_omx->SetBufferStallCallback(&OnBufferStall, this); m_omx->SetEndOfStreamCallback(&OnEndOfStream, this); + + cRpiSetup::SetVideoSetupChangedCallback(&OnVideoSetupChanged, this); + return 0; } int cOmxDevice::DeInit(void) { + cRpiSetup::SetVideoSetupChangedCallback(0); + if (m_audio->DeInit() < 0) { ELOG("failed to deinitialize audio!"); @@ -563,6 +568,11 @@ void cOmxDevice::HandleEndOfStream() m_omx->StartClock(m_hasVideo, m_hasAudio); } +void cOmxDevice::HandleVideoSetupChanged() +{ + DBG("HandleVideoSettingsChanged()"); +} + void cOmxDevice::FlushStreams(bool flushVideoRender) { DBG("FlushStreams(%s)", flushVideoRender ? "flushVideoRender" : ""); diff --git a/omxdevice.h b/omxdevice.h index ea2672c..42a097b 100644 --- a/omxdevice.h +++ b/omxdevice.h @@ -133,8 +133,12 @@ private: static void OnEndOfStream(void *data) { (static_cast <cOmxDevice*> (data))->HandleEndOfStream(); } + static void OnVideoSetupChanged(void *data) + { (static_cast <cOmxDevice*> (data))->HandleVideoSetupChanged(); } + void HandleBufferStall(); void HandleEndOfStream(); + void HandleVideoSetupChanged(); void FlushStreams(bool flushVideoRender = false); @@ -36,31 +36,29 @@ class cRpiSetupPage : public cMenuSetupPage public: - cRpiSetupPage(int *audioPort, int *passthrough, int *ignoreAudioEDID, - bool *audioSetupChanged) : - m_audioPort(audioPort), - m_passthrough(passthrough), - m_ignoreAudioEDID(ignoreAudioEDID), - m_audioSetupChanged(audioSetupChanged) - { - m_newAudioPort = *m_audioPort; - m_newPassthrough = *m_passthrough; - m_newIgnoreAudioEDID = *m_ignoreAudioEDID; + cRpiSetupPage( + cRpiSetup::AudioParameters audio, + cRpiSetup::VideoParameters video) : + m_audio(audio), + m_video(video) + { Setup(); } eOSState ProcessKey(eKeys Key) { - int newAudioPort = m_newAudioPort; - int newPassthrough = m_newPassthrough; + int newAudioPort = m_audio.port; + int newPassthrough = m_audio.passthrough; eOSState state = cMenuSetupPage::ProcessKey(Key); if (Key != kNone) - if ((newAudioPort != m_newAudioPort) || - (newPassthrough != m_newPassthrough)) + { + if ((newAudioPort != m_audio.port) || + (newPassthrough != m_audio.passthrough)) Setup(); + } return state; } @@ -69,15 +67,12 @@ protected: virtual void Store(void) { - *m_audioSetupChanged = - (*m_audioPort != m_newAudioPort) || - (*m_passthrough != m_newPassthrough) || - (*m_ignoreAudioEDID != m_newIgnoreAudioEDID); - - SetupStore("AudioPort", *m_audioPort = m_newAudioPort); - SetupStore("PassThrough", *m_passthrough = m_newPassthrough); - SetupStore("IgnoreAudioEDID", *m_ignoreAudioEDID = m_newIgnoreAudioEDID); - } + SetupStore("AudioPort", m_audio.port); + SetupStore("PassThrough", m_audio.passthrough); + SetupStore("IgnoreAudioEDID", m_audio.ignoreEDID); + + cRpiSetup::GetInstance()->Set(m_audio, m_video); +} private: @@ -87,31 +82,24 @@ private: Clear(); Add(new cMenuEditStraItem( - tr("Audio Port"), &m_newAudioPort, 2, s_audioport)); + tr("Audio Port"), &m_audio.port, 2, s_audioport)); - if (m_newAudioPort == 1) + if (m_audio.port == 1) { Add(new cMenuEditBoolItem( - tr("Digital Audio Pass-Through"), &m_newPassthrough)); + tr("Digital Audio Pass-Through"), &m_audio.passthrough)); - if (m_newPassthrough) + if (m_audio.passthrough) Add(new cMenuEditBoolItem( - tr("Ignore Audio EDID"), &m_newIgnoreAudioEDID)); + tr("Ignore Audio EDID"), &m_audio.ignoreEDID)); } SetCurrent(Get(current)); Display(); } - int m_newAudioPort; - int m_newPassthrough; - int m_newIgnoreAudioEDID; - - int *m_audioPort; - int *m_passthrough; - int *m_ignoreAudioEDID; - - bool *m_audioSetupChanged; + cRpiSetup::AudioParameters m_audio; + cRpiSetup::VideoParameters m_video; static const char *const s_audioport[2]; }; @@ -175,6 +163,18 @@ bool cRpiSetup::HwInit(void) return true; } +void cRpiSetup::SetAudioSetupChangedCallback(void (*callback)(void*), void* data) +{ + GetInstance()->m_onAudioSetupChanged = callback; + GetInstance()->m_onAudioSetupChangedData = data; +} + +void cRpiSetup::SetVideoSetupChangedCallback(void (*callback)(void*), void* data) +{ + GetInstance()->m_onVideoSetupChanged = callback; + GetInstance()->m_onVideoSetupChangedData = data; +} + bool cRpiSetup::IsAudioFormatSupported(cAudioCodec::eCodec codec, int channels, int samplingRate) { @@ -183,7 +183,7 @@ bool cRpiSetup::IsAudioFormatSupported(cAudioCodec::eCodec codec, if (codec == cAudioCodec::eMPG || codec == cAudioCodec::eAAC) return false; - if (GetInstance()->m_ignoreAudioEDID) + if (GetInstance()->m_audio.ignoreEDID) return true; if (vc_tv_hdmi_audio_supported( @@ -217,28 +217,32 @@ int cRpiSetup::GetDisplaySize(int &width, int &height, double &aspect) return 0; } -bool cRpiSetup::HasAudioSetupChanged(void) -{ - if (!GetInstance()->m_audioSetupChanged) - return false; - - GetInstance()->m_audioSetupChanged = false; - return true; -} - cMenuSetupPage* cRpiSetup::GetSetupPage(void) { - return new cRpiSetupPage( - &m_audioPort, &m_passthrough, &m_ignoreAudioEDID, - &m_audioSetupChanged); + return new cRpiSetupPage(m_audio, m_video); } bool cRpiSetup::Parse(const char *name, const char *value) { - if (!strcasecmp(name, "AudioPort")) m_audioPort = atoi(value); - else if (!strcasecmp(name, "PassThrough")) m_passthrough = atoi(value); - else if (!strcasecmp(name, "IgnoreAudioEDID")) m_ignoreAudioEDID = atoi(value); + if (!strcasecmp(name, "AudioPort")) + m_audio.port = atoi(value); + else if (!strcasecmp(name, "PassThrough")) + m_audio.passthrough = atoi(value); + else if (!strcasecmp(name, "IgnoreAudioEDID")) + m_audio.ignoreEDID = atoi(value); else return false; return true; } + +void cRpiSetup::Set(AudioParameters audio, VideoParameters video) +{ + if (audio != m_audio && m_onAudioSetupChanged) + m_onAudioSetupChanged(m_onAudioSetupChangedData); + + if (video != m_video && m_onVideoSetupChanged) + m_onVideoSetupChanged(m_onVideoSetupChangedData); + + m_audio = audio; + m_video = video; +} @@ -15,18 +15,43 @@ class cRpiSetup public: + struct AudioParameters + { + AudioParameters() : + port(0), + passthrough(0), + ignoreEDID(0) { } + + int port; + int passthrough; + int ignoreEDID; + + bool operator!=(const AudioParameters& a) { + return (a.port != port) || (a.passthrough != passthrough) || + (a.ignoreEDID != ignoreEDID); + } + }; + + struct VideoParameters + { + VideoParameters() { } + + bool operator!=(const VideoParameters& a) { + return true; + } + }; + static bool HwInit(void); static cRpiAudioPort::ePort GetAudioPort(void) { - return (GetInstance()->m_audioPort) ? cRpiAudioPort::eHDMI : cRpiAudioPort::eLocal; } + return (GetInstance()->m_audio.port) ? + cRpiAudioPort::eHDMI : cRpiAudioPort::eLocal; } static bool IsAudioPassthrough(void) { - return GetInstance()->m_passthrough; } + return GetInstance()->m_audio.passthrough; } static bool IgnoreAudioEDID(void) { - return GetInstance()->m_ignoreAudioEDID; } - - static bool HasAudioSetupChanged(void); + return GetInstance()->m_audio.ignoreEDID; } static bool IsAudioFormatSupported(cAudioCodec::eCodec codec, int channels, int samplingRate); @@ -47,33 +72,42 @@ public: class cMenuSetupPage* GetSetupPage(void); bool Parse(const char *name, const char *value); + void Set(AudioParameters audio, VideoParameters video); + + static void SetAudioSetupChangedCallback(void (*callback)(void*), void* data = 0); + static void SetVideoSetupChangedCallback(void (*callback)(void*), void* data = 0); + private: cRpiSetup() : - m_audioPort(0), - m_passthrough(0), - m_ignoreAudioEDID(0), - m_audioSetupChanged(false), m_mpeg2Enabled(false), m_isProgressive(false), m_displayHeight(0), - m_displayWidth(0) { } + m_displayWidth(0), + m_onAudioSetupChanged(0), + m_onAudioSetupChangedData(0), + m_onVideoSetupChanged(0), + m_onVideoSetupChangedData(0) + { } virtual ~cRpiSetup() { } static cRpiSetup* s_instance; - int m_audioPort; - int m_passthrough; - int m_ignoreAudioEDID; - - bool m_audioSetupChanged; + AudioParameters m_audio; + VideoParameters m_video; bool m_mpeg2Enabled; bool m_isProgressive; int m_displayHeight; int m_displayWidth; + + void (*m_onAudioSetupChanged)(void*); + void *m_onAudioSetupChangedData; + + void (*m_onVideoSetupChanged)(void*); + void *m_onVideoSetupChangedData; }; #endif |
