summaryrefslogtreecommitdiff
path: root/player-image.h
blob: c58da6a95a79fcc026ab65f87ae6ba4198c62fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * Image plugin to VDR (C++)
 *
 * (C) 2004-2011 Andreas Brachold    <vdr07 at deltab.de>
 *     2003 Kai Tobias Burwieck <kai-at-burwieck.net>
 *
 * This code is distributed under the terms and conditions of the
 * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
 *
 */

#ifndef ___DVB_IMAGE_H
#define ___DVB_IMAGE_H

#include <vector>
#define __STL_CONFIG_H

#include <vdr/thread.h>
#include <vdr/player.h>
#include <liboutput/stillimage-player.h>

class cImageData;
class cSlideShow;    

struct cShellWrapper {
    
  char* szCmd;
  char* szPNM;
  char  szNumber;
  bool bClearBackground;
  unsigned int nOffLeft;
  unsigned int nOffTop;
  unsigned int nWidth;
  unsigned int nHeight;

  cShellWrapper()
  : szCmd(NULL)
  , szPNM(NULL)
  , szNumber('\0')
  {
  }

  virtual ~cShellWrapper() {
    if(szPNM)
      free(szPNM);
    if(szCmd)
      free(szCmd);
  }
};

struct cShellWrapperQueue
 : public std::vector<cShellWrapper*>
{
  virtual ~cShellWrapperQueue()
  {
    iterator i = begin();
    const_iterator e = end();
    for(;e!=i;++i)
        delete(*i);
    clear();
  }

  inline size_t max_size() const 
  {
    return 64;
  }

  inline bool add(cShellWrapper* pCmd) {
    if(size()<max_size())
    {
      if(NULL == pCmd->szPNM || !pCmd->bClearBackground) //Pregeneration or Index
        push_back(pCmd);
      else { 
        // Remove all other viewed images from queue
        iterator i = begin();
        while(end()!=i) {
          if((*i)->szPNM) {
            delete(*i);
            erase(i);
            }
          else
            ++i;
          }
        //Place next viewed image at front of the queue
        insert(begin(),pCmd);
      }
      return true;
    }  
    return false;
  }
  
};

class cImagePlayer
: public cStillImagePlayer
{
    
  volatile bool               m_bConvertRunning;

  cMutex                      m_Mutex;
  cShellWrapperQueue          m_queue;
  cMutex                      m_MutexErr;
  char*                       m_szError;
protected:
  void Exec(cShellWrapper* pCmd);

  void LoadImage(cShellWrapper* pShell);
  /** Show Errorimage if operation failed*/
  void ExecFailed(cShellWrapper* pShell,const char* szErr);

  virtual void Activate(bool On);
  virtual bool Worker(bool bDoIt);
public:

  cImagePlayer(cSlideShow *pCurSlideShow);
  virtual ~ cImagePlayer();
  bool IsConvertRunning() const { return m_bConvertRunning; };
  bool NextImage(int Step);
  bool PrevImage(int Step);
  bool GotoImage(unsigned int nNewPictureIndex);
  
  /** Deliver the filename from the current number of viewed Image */
  const char* FileName(void) const;

  bool Convert(const char *szChange);
  bool ConvertZoom(const char *szChange, int nZoomFaktor,
			       int nLeftPos, int nTopPos);
  bool ConvertJump(int Step);
  
  /** Returns the current and total frame index, optionally snapped to the
  nearest I-frame.*/
  virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame);
  /** ThreadSafe Method to show messages from Worker thread*/
  void ErrorMsg();
};

#endif				//__DVB_IMAGE_H