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