]> git.vomp.tv Git - vompclient.git/blob - imagereader.h
Windows fixes
[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 #include "threadsystem.h"
35
36
37
38 class MediaProvider;
39 class Log;
40
41
42 class ImageReader : public Thread_TYPE, public Callback
43 {
44   public:
45
46     //create an image reader for a media channel
47     //the channel must already been opened
48     ImageReader(int channel,MediaProvider *p);
49     //call shutdown before destroying the reader!
50     virtual ~ImageReader();
51     //request the next image block
52     //will return the current block (if already read) and request the next from the server
53     //rsize will return the received len: 0 on EOF, -1 on error
54     //the returned buffer has to be freed outside (really use free!)
55     //if the buffer is not filled it will wait until the chunk is received!
56     int getImageChunk(ULLONG offset,UINT len, UINT * rsize,UCHAR **buffer);
57
58     //is the reader still running?
59     bool isReaderRunning();
60
61     void shutdown();
62
63     //stop the reader (waits until the reader thread does not access anything)
64     void stop();
65
66     
67     virtual void call(void * caller);
68
69
70   protected:
71     void threadMethod();
72
73   private:
74     MediaProvider * provider;
75     int  channel;
76     static const int MAXCHUNKS=2;
77     //start the player thread
78     void run();
79     Log* logger;
80
81     bool running;
82     bool readerRunning;
83     void waitTimed(int ms);
84
85     typedef enum {
86       S_REQUEST=1,
87       S_FETCHING=2,
88       S_READY=3,
89       S_BREAK=4,
90       S_FREE=0
91       } rstate;
92
93     class Chunk{
94       public:
95       UCHAR * buffer; //receive buffer (to be deallocated with free)
96       ULLONG offset;  //offset within stream/file
97       UINT reqlen;    //requested len
98       ULONG len;       //received len
99       rstate state;   //current state
100       Chunk() {
101         buffer=NULL;
102         offset=0;
103         reqlen=0;
104         len=0;
105         state=S_FREE;
106         } 
107     };
108     //received data
109     //setting state in this array requires the thread lock
110     Chunk data[MAXCHUNKS];
111
112 };
113
114 #endif
115