vdr 2.6.1
PLUGINS/src/pictures/player.c
Go to the documentation of this file.
1/*
2 * player.c: A player for still pictures
3 *
4 * See the README file for copyright information and how to reach the author.
5 *
6 * $Id: player.c 3.1 2014/02/08 12:48:12 kls Exp $
7 */
8
9#include "player.h"
10#include <vdr/remote.h>
11#include <vdr/tools.h>
12
13int SlideShowDelay = 3; // seconds
14
16{
17 // Skip anything before and including the first '_' and replace
18 // any remaining '_' with blanks:
19 const char *p = strchr(s, '_');
20 if (p) {
21 p++;
22 char buf[strlen(p) + 1];
23 strcpy(buf, p);
24 return strreplace(buf, '_', ' ');
25 }
26 return s;
27}
28
29// --- cPicturePlayer --------------------------------------------------------
30
31class cPicturePlayer : public cPlayer {
32private:
33 int size;
34 int length;
36 virtual void Activate(bool On);
37public:
38 cPicturePlayer(void);
40 void SetPicture(const char *FileName);
41 };
42
44{
45 size = KILOBYTE(100); // will be adjusted automatically if files are larger
46 length = 0;
48}
49
51{
52 free(buffer);
53}
54
56{
57 if (length > 0)
59}
60
61void cPicturePlayer::SetPicture(const char *FileName)
62{
63 int f = open(FileName, O_RDONLY);
64 if (f >= 0) {
65 for (;;) {
66 length = read(f, buffer, size);
67 if (length > 0) {
68 if (length >= size) {
69 int NewSize = size * 3 / 2;
70 if (uchar *NewBuffer = (uchar *)realloc(buffer, NewSize)) {
71 buffer = NewBuffer;
72 size = NewSize;
73 }
74 else {
75 LOG_ERROR_STR("out of memory");
76 break;
77 }
78 lseek(f, 0, SEEK_SET);
79 continue;
80 }
82 }
83 else
84 LOG_ERROR_STR(FileName);
85 break;
86 }
87 close(f);
88 }
89 else
90 LOG_ERROR_STR(FileName);
91}
92
93// --- cPictureControl -------------------------------------------------------
94
97
98cPictureControl::cPictureControl(cPictureEntry *Pictures, const cPictureEntry *PictureEntry, bool SlideShow)
99:cControl(player = new cPicturePlayer)
100{
101 pictures = Pictures;
102 pictureEntry = PictureEntry;
103 osd = NULL;
104 lastPath = "/";
106 slideShow = SlideShow;
107 alwaysDisplayCaption = false;
109 active++;
110}
111
113{
114 active--;
115 delete osd;
116 delete player;
117 delete pictures;
118}
119
121{
122 if (Direction) {
123 const cPictureEntry *pe = Direction > 0 ? pictureEntry->NextPicture() : pictureEntry->PrevPicture();
124 if (pe)
125 pictureEntry = pe;
126 }
127 if (pictureEntry) {
130 }
131}
132
134{
135 // This only works reliable if a directory contains only subdirectories or pictures, not both!
136 if (Direction) {
137 const cPictureEntry *pe = Direction > 0 ? pictureEntry->Parent()->Entries()->Last()->NextPicture() : pictureEntry->Parent()->Entries()->First()->PrevPicture();
138 if (pe && Direction < 0)
139 pe = pe->Parent()->Entries()->First();
140 if (pe && pe != pictureEntry) {
141 pictureEntry = pe;
144 }
145 }
146}
147
148static void DrawTextOutlined(cOsd *Osd, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font)
149{
150 for (int dx = -1; dx <= 1; dx++) {
151 for (int dy = -1; dy <= 1; dy++) {
152 if (dx || dy)
153 Osd->DrawText(x + dx, y + dy, s, ColorBg, clrTransparent, Font);
154 }
155 }
156 Osd->DrawText(x, y, s, ColorFg, clrTransparent, Font);
157}
158
160{
161 bool Force = false;
162 cString Path = pictureEntry->Path();
163 lastDisplayed = Path + strlen(pictures->Name()) + 1;
164 const char *p = strrchr(Path, '/');
165 const char *q = strrchr(lastPath, '/');
166 if (p && q) {
167 int lp = p - Path;
168 int lq = q - lastPath;
169 if (lp != lq || strncmp(lastPath, Path, lp)) {
170 lastPath = Path;
171 Force = true;
172 }
173 }
174 if (!alwaysDisplayCaption && !Force) {
176 return;
177 }
179 int w = cOsd::OsdWidth();
180 int h = 2 * Font->Height();
181 if (!osd) {
183 tArea Areas[] = { { 0, 0, w - 1, h - 1, 8 } };
184 if (Setup.AntiAlias && osd->CanHandleAreas(Areas, sizeof(Areas) / sizeof(tArea)) == oeOk)
185 osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea));
186 else {
187 tArea Areas[] = { { 0, 0, w - 1, h - 1, 4 } };
188 osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea));
189 }
190 }
191 const char *Year = pictureEntry->Parent()->Parent() ? pictureEntry->Parent()->Parent()->Name() : "";
192 cString Description = HandleUnderscores(pictureEntry->Parent()->Name());
193 osd->DrawRectangle(0, 0, w - 1, h - 1, clrTransparent);
194 DrawTextOutlined(osd, 0, 0, Description, clrWhite, clrBlack, Font);
195 DrawTextOutlined(osd, 0, h / 2, Year, clrWhite, clrBlack, Font);
196 struct stat sb;
197 if (stat(Path, &sb) == 0) {
198 cString Time = DayDateTime(sb.st_mtime);
199 DrawTextOutlined(osd, w - Font->Width(Time), h / 2, Time, clrWhite, clrBlack, Font);
200 }
201 p++;
202 Path.Truncate(-4); // don't display the ".mpg" extension
204 osd->Flush();
205}
206
208{
209 return tr("Pictures");
210}
211
213{
214 switch (int(Key)) {
215 case kUp:
216 case kPlay: slideShowDelay.Set();
217 slideShow = true;
218 break;
219 case kDown:
220 case kPause: slideShow = false;
221 break;
222 case kLeft|k_Repeat:
223 case kLeft: NextPicture(-1);
224 slideShow = false;
225 break;
226 case kRight|k_Repeat:
227 case kRight: NextPicture(+1);
228 slideShow = false;
229 break;
230 case kOk: if (osd && !alwaysDisplayCaption)
232 else {
235 }
236 break;
237 case kGreen:
238 case kPrev: NextDirectory(-1);
239 slideShow = false;
240 break;
241 case kYellow:
242 case kNext: NextDirectory(+1);
243 slideShow = false;
244 break;
245 case kBlue:
246 case kStop: return osEnd;
247 case kBack: slideShow = false;
248 cRemote::CallPlugin(PLUGIN_NAME_I18N);
249 break;
250 default: break;
251 }
253 NextPicture(+1);
255 }
256 return osContinue;
257}
258
260{
261 return lastDisplayed;
262}
static void DrawTextOutlined(cOsd *Osd, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font)
cString HandleUnderscores(const char *s)
virtual int Width(void) const
Returns the original character width as requested when the font was created, or 0 if the default widt...
Definition: skincurses.c:23
virtual int Height(void) const
Returns the height of this font in pixel (all characters have the same height).
Definition: skincurses.c:26
Definition: font.h:37
static const cFont * GetFont(eDvbFont Font)
Gets the given Font, which was previously set by a call to SetFont().
Definition: font.c:411
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
const T * Last(void) const
Returns the last element in this list, or NULL if the list is empty.
static cOsd * NewOsd(int Left, int Top, uint Level=OSD_LEVEL_DEFAULT)
Returns a pointer to a newly created cOsd object, which will be located at the given coordinates.
Definition: osd.c:2215
The cOsd class is the interface to the "On Screen Display".
static int OsdHeight(void)
virtual eOsdError SetAreas(const tArea *Areas, int NumAreas)
Sets the sub-areas to the given areas.
Definition: osd.c:2029
virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas)
Checks whether the OSD can display the given set of sub-areas.
Definition: osd.c:2007
static int OsdTop(void)
virtual void Flush(void)
Actually commits all data to the OSD hardware.
Definition: osd.c:2191
virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
Draws a filled rectangle defined by the upper left (x1, y1) and lower right (x2, y2) corners with the...
Definition: osd.c:2161
static int OsdLeft(void)
static int OsdWidth(void)
virtual void DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width=0, int Height=0, int Alignment=taDefault)
Draws the given string at coordinates (x, y) with the given foreground and background color and font.
Definition: osd.c:2151
virtual eOSState ProcessKey(eKeys Key)
static const char * LastDisplayed(void)
void NextDirectory(int Direction)
cPictureControl(cPictureEntry *Pictures, const cPictureEntry *PictureEntry, bool SlideShow=false)
void NextPicture(int Direction)
virtual cString GetHeader(void)
This can be used by players that don't play a cRecording, but rather do something completely differen...
const cPictureEntry * pictureEntry
const cPictureEntry * PrevPicture(const cPictureEntry *This=NULL) const
Definition: entry.c:106
const cPictureEntry * Parent(void) const
Definition: entry.h:26
const cPictureEntry * NextPicture(const cPictureEntry *This=NULL) const
Definition: entry.c:125
bool IsDirectory(void) const
Definition: entry.h:27
const char * Name(void) const
Definition: entry.h:25
const cList< cPictureEntry > * Entries(void) const
Definition: entry.c:66
cString Path(void) const
Definition: entry.c:38
virtual void Activate(bool On)
void SetPicture(const char *FileName)
void DeviceStillPicture(const uchar *Data, int Length)
static bool CallPlugin(const char *Plugin)
Initiates calling the given plugin's main menu function.
Definition: remote.c:151
int AntiAlias
Definition: config.h:334
cString & Truncate(int Index)
Truncate the string at the given Index (if Index is < 0 it is counted from the end of the string).
Definition: tools.c:1133
void Set(int Ms=0)
Sets the timer.
Definition: tools.c:792
bool TimedOut(void) const
Definition: tools.c:797
cSetup Setup
Definition: config.c:372
@ fontOsd
Definition: font.h:22
uint32_t tColor
Definition: font.h:30
#define tr(s)
Definition: i18n.h:85
@ kRight
@ kPause
@ kUp
@ kPlay
@ kDown
@ kGreen
@ kStop
@ kLeft
@ kBlue
@ kPrev
@ kYellow
@ kBack
@ k_Repeat
@ kNext
@ kOk
#define OSD_LEVEL_SUBTITLES
@ oeOk
@ osContinue
char * strreplace(char *s, char c1, char c2)
Definition: tools.c:139
#define LOG_ERROR_STR(s)
unsigned char uchar
#define MALLOC(type, size)
void DELETENULL(T *&p)
cString DayDateTime(time_t t=0)
Converts the given time to a string of the form "www dd.mm. hh:mm".
Definition: tools.c:1214
#define KILOBYTE(n)
#define clrTransparent
Definition: skincurses.c:36
#define clrBlack
Definition: skincurses.c:37
#define clrWhite
Definition: skincurses.c:44
static const cCursesFont Font
Definition: skincurses.c:31