]> git.vomp.tv Git - vompclient.git/blob - mediafile.h
Fix resuming recording directly after stopping it
[vompclient.git] / mediafile.h
1 /*
2     Copyright 2004-2005 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 MEDIAFILE_H
22 #define MEDIAFILE_H
23
24 #include "defines.h"
25 #include "mediaprovider.h"
26
27
28 class MediaFile : public MediaProvider 
29 {
30   public:
31     MediaFile(ULONG providerId);
32     virtual ~MediaFile();
33     /**
34       * get the root media list
35       * the returned list has to be destroyed by the caller
36       * if NULL is returned currently no media is available
37       */
38     virtual MediaList* getRootList();
39
40     /**
41       * get a medialist for a given parent
42       * the returned list has to be destroyed by the caller
43       * NULL if no entries found
44       */
45     virtual MediaList* getMediaList(const MediaURI * parent);
46
47     /**
48       * open a media uri
49       * afterwards getBlock or other functions must be possible
50       * currently only one medium is open at the same time
51       * for a given channel
52       * @param channel: channel id, NUMCHANNELS must be supported
53       * @param xsize,ysize: size of the screen
54       * @param size out: the size of the medium
55       * @return != 0 in case of error
56       * 
57       */
58     virtual int openMedium(ULONG channel, const MediaURI * uri, ULLONG * size, ULONG xsize, ULONG ysize);
59
60     /**
61       * get a block for a channel
62       * @param offset - the offset
63       * @param len - the required len
64       * @param outlen out - the read len if 0 this is EOF
65       * @param buffer out the allocated buffer (must be freed with free!)
66       * @return != 0 in case of error
67       */           
68     virtual int getMediaBlock(ULONG channel, ULLONG offset, ULONG len, ULONG * outlen,
69         unsigned char ** buffer);
70
71     /**
72       * close a media channel
73       */
74     virtual int closeMediaChannel(ULONG channel);
75
76     /**
77       * return the media info for a given channel
78       * return != 0 on error
79       * the caller has to provide a pointer to an existing media info
80       */
81     virtual int getMediaInfo(ULONG channel, MediaInfo * result);
82
83
84   protected:
85     /**
86       * create a Media out of a given file
87       * the Media object ha sto be deleted by the caller
88       * return NULL if not there or no matching type
89       */
90     Media * createMedia(const char * dirname, const char * filename, bool withURI=false);
91     struct ChannelInfo {
92       public:
93       FILE *file;
94       ULONG  provider;
95       char *filename;
96       ULLONG size;
97       ChannelInfo(){
98         file=NULL;
99         provider=0;
100         filename=NULL;
101         size=0;
102       }
103       ~ChannelInfo(){
104         if (filename) delete[]filename;
105         if (file) fclose(file);
106       }
107       void setFilename(const char *f) {
108         if (filename) delete[] filename;
109         filename=NULL;
110         if (f) {
111           filename=new char[strlen(f)+1];
112           strcpy(filename,f);
113         }
114       }
115       void reset() {
116         if (file) fclose(file);
117         file=NULL;
118         if (filename) delete [] filename;
119         filename=NULL;
120       }
121     };
122     struct ChannelInfo channels[NUMCHANNELS];
123     ULONG providerid;
124
125     virtual ULONG getMediaType(const char *filename);
126
127 };
128
129 #endif