]> git.vomp.tv Git - vompclient.git/blob - imagereader.h
Display channel name, duration, resume point and size on recording info screen
[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     void threadPostStopCleanup();
73
74   private:
75     MediaProvider * provider;
76     int  channel;
77     static const int MAXCHUNKS=2;
78     //start the player thread
79     void run();
80     Log* logger;
81
82     bool running;
83     bool readerRunning;
84     void waitTimed(int ms);
85
86     typedef enum {
87       S_REQUEST=1,
88       S_FETCHING=2,
89       S_READY=3,
90       S_BREAK=4,
91       S_FREE=0
92       } rstate;
93
94     class Chunk{
95       public:
96       UCHAR * buffer; //receive buffer (to be deallocated with free)
97       ULLONG offset;  //offset within stream/file
98       UINT reqlen;    //requested len
99       ULONG len;       //received len
100       rstate state;   //current state
101       Chunk() {
102         buffer=NULL;
103         offset=0;
104         reqlen=0;
105         len=0;
106         state=S_FREE;
107         } 
108     };
109     //received data
110     //setting state in this array requires the thread lock
111     Chunk data[MAXCHUNKS];
112
113 };
114
115 #endif
116