diff options
author | Andreas Brugger <brougs78@gmx.net> | 2005-12-11 12:00:00 +0100 |
---|---|---|
committer | Thomas Günther <tom@toms-cafe.de> | 2009-06-03 01:10:21 +0200 |
commit | bb39010021b5fd8a1046200839c678afc76227d5 (patch) | |
tree | 81c27dc44e9c40512514334030ce7309c48efaa2 | |
parent | 662dd62488f6f842fe5d940e986f798abe1c7691 (diff) | |
download | vdr-plugin-text2skin-bb39010021b5fd8a1046200839c678afc76227d5.tar.gz vdr-plugin-text2skin-bb39010021b5fd8a1046200839c678afc76227d5.tar.bz2 |
2005-12-11: Version 1.1-cvs_ext-0.3 (vdr-text2skin-1.1-cvs_ext-0.3.diff)
- added recording-tokens:
RecordingLength, RecordingCuttedLength
-rw-r--r-- | HISTORY | 5 | ||||
-rw-r--r-- | common.c | 140 | ||||
-rw-r--r-- | common.h | 4 | ||||
-rw-r--r-- | display.c | 51 | ||||
-rw-r--r-- | status.c | 19 | ||||
-rw-r--r-- | status.h | 6 | ||||
-rw-r--r-- | xml/string.c | 2 | ||||
-rw-r--r-- | xml/string.h | 2 |
8 files changed, 185 insertions, 44 deletions
@@ -1,6 +1,11 @@ VDR Plugin 'text2skin' Revision History --------------------------------------- +2005-12-11: Version 1.1-cvs_ext-0.3 (vdr-text2skin-1.1-cvs_ext-0.3.diff) + +- added recording-tokens: + RecordingLength, RecordingCuttedLength + 2005-11-19: Version 1.1-cvs_ext-0.2 (vdr-text2skin-1.1-cvs_ext-0.2.diff) - removed the previously introduced tokens NextTimerName, NextTimerStart, @@ -115,6 +115,146 @@ const cRecording *GetRecordingByName(const char *Name) return NULL; } +const cRecording *GetRecordingByFileName(const char *FileName) +{ + return Recordings.GetByName(FileName); +} + +int GetRecordingSize(const char *FileName) +{ + if (FileName != NULL) { + bool bRet=false; + long long size = 0; + int nFiles; + struct stat fileinfo; // Holds file information structure + char *cmd = NULL; + cReadLine reader; + asprintf(&cmd, "find '%s' -follow -type f -name '*.*'|sort ", FileName); + + FILE *p = popen(cmd, "r"); + int ret=0; + if (p) + { + char *s; + + while ((s = reader.Read(p)) != NULL) + { + if ((ret=stat(s, &fileinfo)) != -1) + { + size += (long long)fileinfo.st_size; + nFiles++; + } + } + + bRet=true; + } + + pclose(p); + delete cmd; + + return (int)(size / 1024 / 1024); // [MB] + } + else + { + return 0; + } +} + +int GetRecordingLength(const char *FileName) +{ + // based on the enAIO-Patch for VDR + #define INDEXFILESUFFIX "/index.vdr" + + struct tIndex { int offset; uchar type; uchar number; short reserved; }; + tIndex *index; + char RecLength[21]; + char *filename = NULL; + int last = -1; + index = NULL; + if (FileName) { + filename = MALLOC(char, strlen(FileName) + strlen(INDEXFILESUFFIX) + 1); + if (filename) { + strcpy(filename, FileName); + char *pFileExt = filename + strlen(filename); + strcpy(pFileExt, INDEXFILESUFFIX); + int delta = 0; + if (access(filename, R_OK) == 0) { + struct stat buf; + if (stat(filename, &buf) == 0) { + delta = buf.st_size % sizeof(tIndex); + if (delta) { + delta = sizeof(tIndex) - delta; + esyslog("ERROR: invalid file size (%ld) in '%s'", buf.st_size, filename); + } + last = (buf.st_size + delta) / sizeof(tIndex) - 1; + char hour[2], min[3]; + snprintf(RecLength, sizeof(RecLength), "%s", *IndexToHMSF(last, true)); + snprintf(hour, sizeof(hour), "%c", RecLength[0]); + snprintf(min, sizeof(min), "%c%c", RecLength[2], RecLength[3]); + return (atoi(hour) * 60) + atoi(min); + } + } + free(filename); + } + } + + return 0; +} + +int GetRecordingCuttedLength(const char *FileName) +{ + cMarks marks; + double length = 0; + int totalLength = GetRecordingLength(FileName); + const double diffIFrame = FRAMESPERSEC / 2; // approx. 1/2 sec. + /* + // not useful + static std::string lastFileName = ""; + static uint64 nextUpdate = 0; + static int totalLength = 0; + const uint64 bufferTime = 30 * 1000; // [ms] + */ + + + marks.Load(FileName); + + /* + // buffer the result of 'GetRecordingLength' + if (FileName != lastFileName || time_ms() >= nextUpdate) + { + lastFileName = FileName; + nextUpdate = time_ms() + bufferTime; + totalLength = GetRecordingLength(FileName); + } + */ + + if (marks.Count()) + { + int start = 1; // first frame + bool isStart = true; + + for (cMark *m = marks.First(); m; m = marks.GetNext(m->position)) + { + if (isStart) + { + start = m->position; + } + else + { + length += (double)(m->position - start + 1 + diffIFrame) / (FRAMESPERSEC * 60); // [min] + } + + isStart = !isStart; + } + + // if there is no end-mark the last segment goes to the end of the rec. + if (!isStart) length += totalLength - (double)(start - 1 - diffIFrame) / (FRAMESPERSEC * 60); // [min] + } + + // just to avoid, that the cutted length is bigger than the total length + return (int)length > totalLength ? totalLength : (int)length; +} + cxType TimeType(time_t Time, const std::string &Format) { static char result[1000]; @@ -51,6 +51,10 @@ const char *ChannelShortName(const cChannel *Channel, int Number); bool StoppedTimer(const char *Name); const cRecording *GetRecordingByName(const char *Name); +const cRecording *GetRecordingByFileName(const char *FileName); +int GetRecordingSize(const char *FileName); // [MB] +int GetRecordingLength(const char *FileName); // [min] +int GetRecordingCuttedLength(const char *FileName); // [min] cxType TimeType(time_t Time, const std::string &Format); cxType DurationType(uint Index, const std::string &Format); @@ -1270,43 +1270,20 @@ cxType cText2SkinDisplayMenu::GetTokenData(const txToken &Token) #endif case tRecordingSize: - if (mRecording != NULL) { - bool bRet=false; - long long size = 0; - int nFiles; - struct stat fileinfo; // Holds file information structure - char *cmd = NULL; - cReadLine reader; - asprintf(&cmd, "find '%s' -follow -type f -name '*.*'|sort ", mRecording->FileName()); - - FILE *p = popen(cmd, "r"); - int ret=0; - if (p) - { - char *s; - - while ((s = reader.Read(p)) != NULL) - { - if ((ret=stat(s, &fileinfo)) != -1) - { - size += (long long)fileinfo.st_size; - nFiles++; - } - } - - bRet=true; - } - - pclose(p); - delete cmd; - - return (long)(size / 1024 / 1024); // [MB] - } - else - { - return false; - } - + return mRecording != NULL + ? (cxType)GetRecordingSize(mRecording->FileName()) + : (cxType)false; + + case tRecordingLength: + return mRecording != NULL + ? (cxType)GetRecordingLength(mRecording->FileName()) + : (cxType)false; + + case tRecordingCuttedLength: + return mRecording != NULL + ? (cxType)GetRecordingCuttedLength(mRecording->FileName()) + : (cxType)false; + default: return cText2SkinRender::GetTokenData(Token); } @@ -7,6 +7,7 @@ #include "menu.h" #include <vdr/timers.h> #include <vdr/plugin.h> +#include <vdr/menu.h> const std::string ReplayNames[__REPLAY_COUNT__] = { "", "normal", "mp3", "mplayer", "dvd", "vcd", "image" }; @@ -53,11 +54,11 @@ void cText2SkinStatus::Replaying(const cControl* /*Control*/, const char *Name) mReplayIsShuffle = Name[2] == 'S'; } } - else if (const cRecording *rec = GetRecordingByName(Name)) - { - mReplay = rec; - mReplayMode = replayNormal; - } + else if (const cRecording *rec = GetRecordingByFileName(cReplayControl::LastReplayed())) + { + mReplay = rec; + mReplayMode = replayNormal; + } else if (strcmp(Name, "DVD") == 0) mReplayMode = replayDVD; else if (strcmp(Name, "VCD") == 0) @@ -308,7 +309,13 @@ cxType cText2SkinStatus::GetTokenData(const txToken &Token) { const tComponent *c = components->Component(i); if (c->stream != 2) index++; // only audio-streams - if (i == index) return (cxType)c->language; + { + std::string buffer(c->language); + if (c->type == 1) buffer.append("MONO"); + if (c->type == 2) buffer.append("DUAL"); + if (c->type == 5) buffer.append("DD"); + return (cxType)buffer.c_str(); + } } } } @@ -5,8 +5,14 @@ #ifndef VDR_TEXT2SKIN_STATUS_H #define VDR_TEXT2SKIN_STATUS_H +#ifndef __STL_CONFIG_H +#define __STL_CONFIG_H +#endif + #include "common.h" #include <vdr/status.h> +#include <algorithm> +#include <vector> class cText2SkinRender; diff --git a/xml/string.c b/xml/string.c index c64fbb1..76aa317 100644 --- a/xml/string.c +++ b/xml/string.c @@ -46,7 +46,7 @@ static const char *Tokens[__COUNT_TOKEN__] = { "MenuTitle", "MenuGroup", "IsMenuGroup", "MenuItem", "IsMenuItem", "MenuCurrent", "IsMenuCurrent", "MenuText", "RecordingName", "RecordingDateTime", "RecordingTitle", "RecordingShortText", "RecordingDescription", "RecordingLanguageCode", - "RecordingVideoAR", "RecordingSize", + "RecordingVideoAR", "RecordingSize", "RecordingLength", "RecordingCuttedLength", "RecordingLanguageDescription", "ButtonRed", "ButtonGreen", "ButtonYellow", "ButtonBlue", "CanScrollUp", "CanScrollDown" }; diff --git a/xml/string.h b/xml/string.h index 8b3d4a4..098e43b 100644 --- a/xml/string.h +++ b/xml/string.h @@ -151,6 +151,8 @@ enum exToken { tRecordingLanguageCode, tRecordingVideoAR, tRecordingSize, + tRecordingLength, + tRecordingCuttedLength, tRecordingLanguageDescription, // next four also in Channel and Replay display (if supported by vdr/plugin) tButtonRed, |