diff options
author | louis <louis.braun@gmx.de> | 2014-10-20 17:35:52 +0200 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2014-10-20 17:35:52 +0200 |
commit | 2c17177f2faa9e03d29fad3e0e4d9b0a827ca401 (patch) | |
tree | 1d47610c1ffc227251dabc5ef5958902f5ca86d4 /libcore | |
parent | 49c6ef552c7964bd60d19380605c14ec21c36e7e (diff) | |
download | vdr-plugin-skindesigner-2c17177f2faa9e03d29fad3e0e4d9b0a827ca401.tar.gz vdr-plugin-skindesigner-2c17177f2faa9e03d29fad3e0e4d9b0a827ca401.tar.bz2 |
added extented recording information
Diffstat (limited to 'libcore')
-rw-r--r-- | libcore/extrecinfo.c | 96 | ||||
-rw-r--r-- | libcore/extrecinfo.h | 36 | ||||
-rw-r--r-- | libcore/helpers.c | 43 | ||||
-rw-r--r-- | libcore/helpers.h | 4 |
4 files changed, 179 insertions, 0 deletions
diff --git a/libcore/extrecinfo.c b/libcore/extrecinfo.c new file mode 100644 index 0000000..435d43b --- /dev/null +++ b/libcore/extrecinfo.c @@ -0,0 +1,96 @@ +#include "../config.h" +#include "helpers.h" +#include "extrecinfo.h" + +cExtRecInfo::cExtRecInfo(const char *xml) { + this->xml = xml; +} + +cExtRecInfo::~cExtRecInfo(void) { + +} + +bool cExtRecInfo::Parse(void) { + //read media info + string mediaInfoXml; + StripXmlTag(xml, mediaInfoXml, "mediainfo"); + if (mediaInfoXml.size() == 0) { + return false; + } + StripXmlTag(mediaInfoXml, resWidth, "res_width"); + StripXmlTag(mediaInfoXml, resHeight, "res_height"); + resString = GetScreenResolutionString(resWidth, resHeight, &isHD); + StripXmlTag(mediaInfoXml, aspectratio, "aspectratio"); + isWideScreen = !aspectratio.compare("16:9"); + StripXmlTag(mediaInfoXml, codec, "codec"); + StripXmlTag(mediaInfoXml, format, "format"); + StripXmlTag(mediaInfoXml, framerate, "framerate"); + StripXmlTag(mediaInfoXml, interlace, "interlace"); + + size_t found = 0; + isDolby = false; + do { + string track; + found = StripXmlTag(mediaInfoXml, track, "track", found); + if (found == string::npos) + break; + tAudioTrack sTrack; + StripXmlTag(track, sTrack.codec, "codec"); + StripXmlTag(track, sTrack.bitrate, "bitrate"); + StripXmlTag(track, sTrack.language, "language"); + if (!sTrack.codec.compare("AC-3")) + isDolby = true; + tracks.push_back(sTrack); + } while (found != string::npos); + + return true; +} + +//get content of <tag> ... </tag> inside xml +size_t cExtRecInfo::StripXmlTag(string &xmlstring, string &content, const char *tag, int start) { + // set the search strings + stringstream strStart, strStop; + strStart << "<" << tag << ">"; + strStop << "</" << tag << ">"; + // find the strings + size_t locStart = xmlstring.find(strStart.str(), start); + size_t locStop = xmlstring.find(strStop.str(), start); + if (locStart == string::npos || locStop == string::npos) + return string::npos; + // extract relevant text + int pos = locStart + strStart.str().size(); + int len = locStop - pos; + + content = (len < 0) ? "" : xmlstring.substr(pos, len); + return locStop + strStop.str().size(); +} + +size_t cExtRecInfo::StripXmlTag(string &xmlstring, int &content, const char *tag, int start) { + // set the search strings + stringstream strStart, strStop; + strStart << "<" << tag << ">"; + strStop << "</" << tag << ">"; + // find the strings + size_t locStart = xmlstring.find(strStart.str(), start); + size_t locStop = xmlstring.find(strStop.str(), start); + if (locStart == string::npos || locStop == string::npos) + return string::npos; + // extract relevant text + int pos = locStart + strStart.str().size(); + int len = locStop - pos; + + string value = (len < 0) ? "" : xmlstring.substr(pos, len); + content = atoi(value.c_str()); + return locStop + strStop.str().size(); +} + +void cExtRecInfo::Debug(void) { + dsyslog("skindesigner: extRecInfo xml: %s", xml.c_str()); + dsyslog("skindesigner: : res_width %d, res_height %d, res %s, aspectratio %s, codec %s, format %s, framerate %s, interlace %s, hd %s, widescreen %s", + resWidth, resHeight, resString.c_str(), aspectratio.c_str(), codec.c_str(), format.c_str(), framerate.c_str(), interlace.c_str(), + isHD ? "true": "false", isWideScreen ? "true" : "false"); + int numTrack = 1; + for (vector<tAudioTrack>::iterator it = tracks.begin(); it != tracks.end(); it++) { + dsyslog("skindesigner: audio track %d, codec %s, bitrate %s, language: %s", numTrack++, (*it).codec.c_str(), (*it).bitrate.c_str(), (*it).language.c_str()); + } +} diff --git a/libcore/extrecinfo.h b/libcore/extrecinfo.h new file mode 100644 index 0000000..9fb5bab --- /dev/null +++ b/libcore/extrecinfo.h @@ -0,0 +1,36 @@ +#ifndef __EXTRECINFO_H +#define __EXTRECINFO_H + +#include <vdr/recording.h> + +struct tAudioTrack { + string codec; + string bitrate; + string language; +}; + +class cExtRecInfo { +private: + string xml; + size_t StripXmlTag(string &xmlstring, string &content, const char *tag, int start = 0); + size_t StripXmlTag(string &xmlstring, int &content, const char *tag, int start = 0); +public: + cExtRecInfo(const char *xml); + ~cExtRecInfo(void); + bool Parse(void); + void Debug(void); + int resWidth; + int resHeight; + string resString; + bool isHD; + string aspectratio; + bool isWideScreen; + string codec; + string format; + string framerate; + string interlace; + bool isDolby; + vector< tAudioTrack > tracks; +}; + +#endif // __EXTRECINFO_H
\ No newline at end of file diff --git a/libcore/helpers.c b/libcore/helpers.c index c8e7fe2..1934f3e 100644 --- a/libcore/helpers.c +++ b/libcore/helpers.c @@ -175,3 +175,46 @@ void cStopWatch::Report(const char* message) { void cStopWatch::Stop(const char* message) { dsyslog("skindesigner: %s - needed %d ms", message, (int)(cTimeMs::Now() - start)); } + +//View Helpers +string GetScreenResolutionString(int width, int height, bool *isHD) { + string name = ""; + switch (width) { + case 1920: + case 1440: + name = "hd1080i"; + *isHD = true; + break; + case 1280: + if (height == 720) + name = "hd720p"; + else + name = "hd1080i"; + *isHD = true; + break; + case 720: + name = "sd576i"; + break; + default: + name = "sd576i"; + break; + } + return name; +} + +string GetScreenAspectString(double aspect, bool *isWideScreen) { + string name = ""; + *isWideScreen = false; + if (aspect == 4.0/3.0) { + name = "4:3"; + *isWideScreen = false; + } else if (aspect == 16.0/9.0) { + name = "16:9"; + *isWideScreen = true; + } else if (aspect == 2.21) { + name = "21:9"; + *isWideScreen = true; + } + return name; +} + diff --git a/libcore/helpers.h b/libcore/helpers.h index 884738d..f489555 100644 --- a/libcore/helpers.h +++ b/libcore/helpers.h @@ -37,4 +37,8 @@ public: void Report(const char* message); void Stop(const char* message); }; + +string GetScreenResolutionString(int width, int height, bool *isHD); +string GetScreenAspectString(double aspect, bool *isWideScreen); + #endif // __HELPERS_H |