From abd8fd8db042ae860bb5346ce886ee961a847ae6 Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 28 Oct 2014 16:39:42 +0100 Subject: [PATCH] added tokens for current video and audio bitrate in displaychannel --- HISTORY | 4 +- Makefile | 1 + config.c | 2 + config.h | 1 + displaychannel.c | 2 + dtd/displaychannel.dtd | 7 +- libcore/femonreceiver.c | 184 +++++++++++++++++++++ libcore/femonreceiver.h | 53 ++++++ libtemplate/templateview.c | 6 + libtemplate/templateviewelement.h | 1 + skindesigner.c | 2 +- skins/metrixhd/xmlfiles/displaychannel.xml | 18 +- skinskeleton/xmlfiles/displaychannel.xml | 9 + views/displaychannelview.c | 29 +++- views/displaychannelview.h | 2 + views/viewhelpers.c | 74 ++++++++- views/viewhelpers.h | 17 +- 17 files changed, 402 insertions(+), 10 deletions(-) create mode 100644 libcore/femonreceiver.c create mode 100644 libcore/femonreceiver.h diff --git a/HISTORY b/HISTORY index e458949..e918aea 100644 --- a/HISTORY +++ b/HISTORY @@ -42,6 +42,8 @@ Version 0.0.2 Version 0.0.3 - +- added tokens for current video and audio bitrate in displaychannel. Thx @rofafor for the original code + in the femon plugin and _Martin_ for extracting the code in skinflatplus +- changed skin metrixHD to display bitrate infos diff --git a/Makefile b/Makefile index 2be7976..2160ae6 100644 --- a/Makefile +++ b/Makefile @@ -78,6 +78,7 @@ OBJS = $(PLUGIN).o \ libcore/recfolderinfo.o \ libcore/extrecinfo.o \ libcore/timers.o \ + libcore/femonreceiver.o \ libtemplate/globals.o \ libtemplate/parameter.o \ libtemplate/template.o \ diff --git a/config.c b/config.c index 4ef6964..a3ec23d 100644 --- a/config.c +++ b/config.c @@ -23,6 +23,8 @@ cDesignerConfig::cDesignerConfig() { //menu display style, display menu items //one after each other or in one step blockFlush = 1; + //interval for femon receiver to recalculate bitrates in tenth of a second + bitrateCalcInterval = 10; //remember current skin and theme, osd size and osd fonts SetSkin(); SetOSDSize(); diff --git a/config.h b/config.h index 7773208..9c5429e 100644 --- a/config.h +++ b/config.h @@ -61,6 +61,7 @@ public: int rerunDistance; int rerunMaxChannel; int blockFlush; + int bitrateCalcInterval; }; #ifdef DEFINE_CONFIG diff --git a/displaychannel.c b/displaychannel.c index 97013bb..0ddb514 100644 --- a/displaychannel.c +++ b/displaychannel.c @@ -186,12 +186,14 @@ void cSDDisplayChannel::Flush(void) { channelView->DrawSignal(); channelView->DrawAudioInfo(); channelView->DrawDevices(initial); + channelView->DrawBitrates(); } else { channelView->ClearStatusIcons(); channelView->ClearScreenResolution(); channelView->ClearSignal(); channelView->ClearSignalBackground(); channelView->ClearDevices(); + channelView->DrawBitrates(); } if (initial) { diff --git a/dtd/displaychannel.dtd b/dtd/displaychannel.dtd index a99e87e..f3b76ab 100644 --- a/dtd/displaychannel.dtd +++ b/dtd/displaychannel.dtd @@ -4,7 +4,7 @@ + + + +#include "../config.h" +#include "femonreceiver.h" + +cFemonReceiver::cFemonReceiver(const cChannel *Channel, int ATrack, int DTrack) + : cReceiver(Channel), + cThread("femon receiver"), + m_Mutex(), + m_Sleep(), + m_Active(false), + m_VideoBuffer(KILOBYTE(512), TS_SIZE, false, "Femon video"), + m_VideoType(Channel ? Channel->Vtype(): 0), + m_VideoPid(Channel ? Channel->Vpid() : 0), + m_VideoPacketCount(0), + m_AudioBuffer(KILOBYTE(256), TS_SIZE, false, "Femon audio"), + m_AudioPid(Channel ? Channel->Apid(ATrack) : 0), + m_AudioPacketCount(0), + m_AC3Buffer(KILOBYTE(256), TS_SIZE, false, "Femon AC3"), + m_AC3Pid(Channel ? Channel->Dpid(DTrack) : 0), + m_AC3PacketCount(0) +{ + SetPids(NULL); + AddPid(m_VideoPid); + AddPid(m_AudioPid); + AddPid(m_AC3Pid); + + m_VideoBuffer.SetTimeouts(0, 100); + m_AudioBuffer.SetTimeouts(0, 100); + m_AC3Buffer.SetTimeouts(0, 100); + + m_VideoBitrate = 0.0; + m_AudioBitrate = 0.0; + m_AC3Bitrate = 0.0; +} + +cFemonReceiver::~cFemonReceiver(void) +{ + Deactivate(); +} + +void cFemonReceiver::Deactivate(void) +{ + Detach(); + if (m_Active) { + m_Active = false; + m_Sleep.Signal(); + if (Running()) + Cancel(3); + } +} + +void cFemonReceiver::Activate(bool On) +{ + if (On) + Start(); + else + Deactivate(); +} + +void cFemonReceiver::Receive(uchar *Data, int Length) +{ + // TS packet length: TS_SIZE + if (Running() && (*Data == TS_SYNC_BYTE) && (Length == TS_SIZE)) { + int len, pid = TsPid(Data); + if (pid == m_VideoPid) { + ++m_VideoPacketCount; + len = m_VideoBuffer.Put(Data, Length); + if (len != Length) { + m_VideoBuffer.ReportOverflow(Length - len); + m_VideoBuffer.Clear(); + } + } + else if (pid == m_AudioPid) { + ++m_AudioPacketCount; + len = m_AudioBuffer.Put(Data, Length); + if (len != Length) { + m_AudioBuffer.ReportOverflow(Length - len); + m_AudioBuffer.Clear(); + } + } + else if (pid == m_AC3Pid) { + ++m_AC3PacketCount; + len = m_AC3Buffer.Put(Data, Length); + if (len != Length) { + m_AC3Buffer.ReportOverflow(Length - len); + m_AC3Buffer.Clear(); + } + } + } +} + +void cFemonReceiver::Action(void) +{ + cTimeMs calcPeriod(0); + m_Active = true; + bool init = true; + while (Running() && m_Active) { + uint8_t *Data; + double timeout; + int Length; + bool processed = false; + + // process available video data + while ((Data = m_VideoBuffer.Get(Length))) { + if (!m_Active || (Length < TS_SIZE)) + break; + Length = TS_SIZE; + if (*Data != TS_SYNC_BYTE) { + for (int i = 1; i < Length; ++i) { + if (Data[i] == TS_SYNC_BYTE) { + Length = i; + break; + } + } + m_VideoBuffer.Del(Length); + continue; + } + processed = true; + if (TsPayloadStart(Data)) { + m_VideoAssembler.Reset(); + } + m_VideoAssembler.PutTs(Data, Length); + m_VideoBuffer.Del(Length); + } + + // process available audio data + while ((Data = m_AudioBuffer.Get(Length))) { + if (!m_Active || (Length < TS_SIZE)) + break; + Length = TS_SIZE; + if (*Data != TS_SYNC_BYTE) { + for (int i = 1; i < Length; ++i) { + if (Data[i] == TS_SYNC_BYTE) { + Length = i; + break; + } + } + m_AudioBuffer.Del(Length); + continue; + } + processed = true; + m_AudioAssembler.PutTs(Data, Length); + m_AudioBuffer.Del(Length); + } + + // process available dolby data + while ((Data = m_AC3Buffer.Get(Length))) { + if (!m_Active || (Length < TS_SIZE)) + break; + Length = TS_SIZE; + if (*Data != TS_SYNC_BYTE) { + for (int i = 1; i < Length; ++i) { + if (Data[i] == TS_SYNC_BYTE) { + Length = i; + break; + } + } + m_AC3Buffer.Del(Length); + continue; + } + processed = true; + m_AC3Assembler.PutTs(Data, Length); + m_AC3Buffer.Del(Length); + } + + // calculate bitrates + timeout = double(calcPeriod.Elapsed()); + if (m_Active && (init || (timeout >= (100.0 * config.bitrateCalcInterval )))) { + // TS packet 188 bytes - 4 byte header; MPEG standard defines 1Mbit = 1000000bit + // PES headers should be compensated! + m_VideoBitrate = (1000.0 * 8.0 * 184.0 * m_VideoPacketCount) / timeout; + m_VideoPacketCount = 0; + m_AudioBitrate = (1000.0 * 8.0 * 184.0 * m_AudioPacketCount) / timeout; + m_AudioPacketCount = 0; + m_AC3Bitrate = (1000.0 * 8.0 * 184.0 * m_AC3PacketCount) / timeout; + m_AC3PacketCount = 0; + calcPeriod.Set(0); + init = false; + } + + if (!processed) + m_Sleep.Wait(10); // to avoid busy loop and reduce cpu load + } +} diff --git a/libcore/femonreceiver.h b/libcore/femonreceiver.h new file mode 100644 index 0000000..2720ff1 --- /dev/null +++ b/libcore/femonreceiver.h @@ -0,0 +1,53 @@ +#ifndef __FEMONRECEIVER_H +#define __FEMONRECEIVER_H + +#include +#include + +class cFemonReceiver : public cReceiver, public cThread { + private: + cMutex m_Mutex; + cCondWait m_Sleep; + bool m_Active; + + cRingBufferLinear m_VideoBuffer; + cTsToPes m_VideoAssembler; + int m_VideoType; + int m_VideoPid; + int m_VideoPacketCount; + double m_VideoBitrate; + + cRingBufferLinear m_AudioBuffer; + cTsToPes m_AudioAssembler; + int m_AudioPid; + int m_AudioPacketCount; + double m_AudioBitrate; + bool m_AudioValid; + + cRingBufferLinear m_AC3Buffer; + cTsToPes m_AC3Assembler; + int m_AC3Pid; + int m_AC3PacketCount; + double m_AC3Bitrate; + bool m_AC3Valid; + + protected: + virtual void Activate(bool On); + virtual void Receive(uchar *Data, int Length); + virtual void Action(void); + + public: + cFemonReceiver(const cChannel* Channel, int ATrack, int DTrack); + virtual ~cFemonReceiver(); + void Deactivate(void); + + double VideoBitrate(void) { cMutexLock MutexLock(&m_Mutex); + return m_VideoBitrate; }; // bit/s + double AudioBitrate(void) { cMutexLock MutexLock(&m_Mutex); + return m_AudioBitrate; }; // bit/s + double AC3Bitrate(void) { cMutexLock MutexLock(&m_Mutex); + return m_AC3Bitrate; }; // bit/s +}; + +#endif //__FEMONRECEIVER_H + diff --git a/libtemplate/templateview.c b/libtemplate/templateview.c index f122732..a032349 100644 --- a/libtemplate/templateview.c +++ b/libtemplate/templateview.c @@ -613,6 +613,7 @@ void cTemplateViewChannel::SetViewElements(void) { viewElementsAllowed.insert("signalquality"); viewElementsAllowed.insert("signalqualityback"); viewElementsAllowed.insert("devices"); + viewElementsAllowed.insert("bitrate"); viewElementsAllowed.insert("scrapercontent"); viewElementsAllowed.insert("datetime"); viewElementsAllowed.insert("message"); @@ -655,6 +656,9 @@ string cTemplateViewChannel::GetViewElementName(eViewElement ve) { case veSignalQualityBack: name = "Signal Quality Background"; break; + case veBitRate: + name = "Bit Rate"; + break; case veDevices: name = "Devices"; break; @@ -702,6 +706,8 @@ void cTemplateViewChannel::AddPixmap(string sViewElement, cTemplatePixmap *pix, ve = veSignalQuality; } else if (!sViewElement.compare("signalqualityback")) { ve = veSignalQualityBack; + } else if (!sViewElement.compare("bitrate")) { + ve = veBitRate; } else if (!sViewElement.compare("devices")) { ve = veDevices; } else if (!sViewElement.compare("scrapercontent")) { diff --git a/libtemplate/templateviewelement.h b/libtemplate/templateviewelement.h index 7fe78b9..a2605ca 100644 --- a/libtemplate/templateviewelement.h +++ b/libtemplate/templateviewelement.h @@ -37,6 +37,7 @@ enum eViewElement { veScreenResolution, veSignalQuality, veSignalQualityBack, + veBitRate, veScraperContent, //DisplayMenu ViewElements veHeader, diff --git a/skindesigner.c b/skindesigner.c index d6e8168..c2f499a 100644 --- a/skindesigner.c +++ b/skindesigner.c @@ -19,7 +19,7 @@ #endif -static const char *VERSION = "0.0.3"; +static const char *VERSION = "0.0.4dev"; static const char *DESCRIPTION = "SkinDesigner"; static const char *MAINMENUENTRY = "Skin Designer"; diff --git a/skins/metrixhd/xmlfiles/displaychannel.xml b/skins/metrixhd/xmlfiles/displaychannel.xml index 030e937..1e087d7 100644 --- a/skins/metrixhd/xmlfiles/displaychannel.xml +++ b/skins/metrixhd/xmlfiles/displaychannel.xml @@ -164,8 +164,9 @@ {signalquality} SNR value of currently displayed channel --> - - + + + @@ -208,6 +209,19 @@ + + + + + + + + + + +