]> git.vomp.tv Git - vompclient.git/blob - imagereader.h
Vogel Media Player 2008-11-28
[vompclient.git] / imagereader.h
1 /*
2     Copyright 2004-2006 Chris Tallon, Andreas Vogel
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef IMAGEREADER_H
22 #define IMAGEREADER_H
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #ifndef WIN32
27 #include <sys/time.h>
28 #endif
29 #include <time.h>
30
31 #include "callback.h"
32 #include "thread.h"
33
34 #ifdef WIN32
35 #include "threadwin.h"
36 #else
37 #include "threadp.h"
38 #endif
39
40
41
42 class MediaProvider;
43 class Log;
44
45
46 class ImageReader : public Thread_TYPE, public Callback
47 {
48   public:
49
50     //create an image reader for a media channel
51     //the channel must already been opened
52     ImageReader(int channel,MediaProvider *p);
53     //call shutdown before destroying the reader!
54     virtual ~ImageReader();
55     //request the next image block
56     //will return the current block (if already read) and request the next from the server
57     //rsize will return the received len: 0 on EOF, -1 on error
58     //the returned buffer has to be freed outside (really use free!)
59     //if the buffer is not filled it will wait until the chunk is received!
60     int getImageChunk(ULLONG offset,UINT len, UINT * rsize,UCHAR **buffer);
61
62     //is the reader still running?
63     bool isReaderRunning();
64
65     void shutdown();
66
67     //stop the reader (waits until the reader thread does not access anything)
68     void stop();
69
70     
71     virtual void call(void * caller);
72
73
74   protected:
75     void threadMethod();
76     void threadPostStopCleanup();
77
78   private:
79     MediaProvider * provider;
80     int  channel;
81     static const int MAXCHUNKS=2;
82     //start the player thread
83     void run();
84     Log* logger;
85
86     bool running;
87     bool readerRunning;
88     void waitTimed(int ms);
89
90     typedef enum {
91       S_REQUEST=1,
92       S_FETCHING=2,
93       S_READY=3,
94       S_BREAK=4,
95       S_FREE=0
96       } rstate;
97
98     class Chunk{
99       public:
100       UCHAR * buffer; //receive buffer (to be deallocated with free)
101       ULLONG offset;  //offset within stream/file
102       UINT reqlen;    //requested len
103       ULONG len;       //received len
104       rstate state;   //current state
105       Chunk() {
106         buffer=NULL;
107         offset=0;
108         reqlen=0;
109         len=0;
110         state=S_FREE;
111         } 
112     };
113     //received data
114     //setting state in this array requires the thread lock
115     Chunk data[MAXCHUNKS];
116
117 };
118
119 #endif
120