]> git.vomp.tv Git - vompserver.git/blob - media.h
15 years that line of code has been waiting to crash
[vompserver.git] / media.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #ifndef MEDIA_H
22 #define MEDIA_H
23
24 using namespace std;
25 #include <vector>
26 #include <stdio.h>
27 #include <string.h>
28 #include "defines.h"
29 #include "serialize.h"
30
31 /* media types form a bitmask
32    so you can add them to have > 1*/
33 #define MEDIA_TYPE_DIR 1
34 #define MEDIA_TYPE_AUDIO 2
35 #define MEDIA_TYPE_VIDEO 4
36 #define MEDIA_TYPE_PICTURE 8
37 #define MEDIA_TYPE_UNKNOWN 0
38
39 #define MEDIA_TYPE_ALL (1+2+4+8)
40
41 /**
42   * MediaURI - a data holder for the complete path to a media
43   * depending on the provider there is an internal name and a display name
44   * by providing own MediaList implementations the provider can control
45   * how URIs are concatenated
46   */
47 class MediaURI : public Serializable{
48   //to be able to access private members
49   friend class MediaList;
50   private:
51     char * _name;
52     char * _display;
53     ULONG _providerId;
54     ULONG _allowedTypes;
55   public:
56     MediaURI() {
57       _name=NULL;
58       _display=NULL;
59       _providerId=0;
60       _allowedTypes=MEDIA_TYPE_ALL;
61     }
62     //constructor copying params
63     MediaURI(ULONG provider, const char * name, const char * display);
64     virtual ~MediaURI() {
65       if (_name) delete _name;
66       if (_display) delete _display;
67     }
68     MediaURI(const MediaURI *cp) ;
69     const char * getName() const { return _name;}
70     const char * getDisplayName() const { 
71       if (_display) return _display;
72       return _name;
73     }
74     ULONG getProvider() const {
75       return _providerId;
76     }
77     void setProvider(ULONG pid) {
78       _providerId=pid;
79     }
80     ULONG getAllowedTypes() const {
81       return _allowedTypes;
82     }
83     void setAllowedTypes(ULONG allowedTypes) {
84       _allowedTypes=allowedTypes;
85     }
86     bool hasDisplayName() const {
87       return _display!=NULL;
88     }
89
90     //serialize functions
91     //get the #of bytes needed to serialize
92     virtual int getSerializedLenImpl();
93     //serialize
94     //advance buffer, check if >= end
95     //return 0 if OK
96     virtual int serializeImpl(SerializeBuffer *b);
97     //deserialize
98     //advance buffer, check if >= end
99     //return 0 if OK
100     virtual int deserializeImpl(SerializeBuffer *b);
101  
102 };
103
104 /**
105   * a class providing additional info for a medium
106   */
107 class MediaInfo : public Serializable{
108   public:
109     ULLONG  size;
110     bool                canPosition;
111     ULONG                 type; //a media type
112     ULONG                 subtype; //TODO
113     /**
114       * return any info item contained within this info
115       */
116     virtual const char * getInfo(ULONG infoId) { return NULL;}
117     virtual ULLONG getIntegerInfo(ULONG infoId) { return 0;}
118     virtual const char * getInfoName(ULONG infoId) { return NULL;}
119     virtual bool hasInfo(ULONG infoId) { return false;}
120     MediaInfo() {
121       size=0;
122       canPosition=true;
123       type=MEDIA_TYPE_UNKNOWN;
124       subtype=0;
125     }
126     virtual ~MediaInfo(){};
127     //serialize functions
128     //get the #of bytes needed to serialize
129     virtual int getSerializedLenImpl();
130     //serialize
131     //advance buffer, check if >= end
132     //return 0 if OK
133     virtual int serializeImpl(SerializeBuffer *b);
134     //deserialize
135     //advance buffer, check if >= end
136     //return 0 if OK
137     virtual int deserializeImpl(SerializeBuffer *b);
138 };
139
140
141 /**
142   * the Media class - a data holder describing a single media
143   * WITHOUT the complete path
144   * to retrieve an URI you need the list where this media is contained
145   * this has the root URI and can construct the URI for this media
146   * optional the media can contain an UIR by itself - then this is used
147   */
148
149 class Media : public Serializable
150 {
151   friend class MediaList;
152   public:
153     Media();
154     Media(const Media *m);
155     virtual ~Media();
156
157     void setTime(ULONG mtimeTime);
158     void setDisplayName(const char* displayName);
159     void setFileName(const char* fileName);
160     void setMediaType(ULONG mtype);
161
162     ULONG getTime() const;
163     const char* getDisplayName() const;
164     const char* getFileName() const;
165     //return the time as a string
166     //if the user provides a buffer, this one is used, if NULL
167     //is given a new buffer is allocated
168     //caller must delete the buffer after usage!
169     char * getTimeString(char *buffer) const;
170     //length for the time display buffer
171     const static int TIMEBUFLEN=100;
172     int index;
173     ULONG getMediaType() const;
174     bool hasDisplayName() const;
175     //optionally the media can contain an URI
176     //in this case the filename is not considered
177     //but the data from the URI is taken
178     //this enables having another providerId set in the media...
179     //returns URI without copy
180     const MediaURI * getURI() const;
181     void setURI(const MediaURI *uri);
182
183     //serialize functions
184     //get the #of bytes needed to serialize
185     virtual int getSerializedLenImpl();
186     //serialize
187     //advance buffer, check if >= end
188     //return 0 if OK
189     virtual int serializeImpl(SerializeBuffer *b);
190     //deserialize
191     //advance buffer, check if >= end
192     //return 0 if OK
193     virtual int deserializeImpl(SerializeBuffer *b);
194     
195   private:
196     ULONG mtime;
197     char* displayName;
198     char* fileName;
199     ULONG mediaType;
200     MediaURI *uri;
201
202
203 };
204
205
206 typedef vector<Media*> MediaListI;
207
208 /**
209   * the MediaList - containing a root URI and
210   * all the Media entries
211   * providers can provide derived classes to overwrite the URI-Methods
212   */
213 class MediaList : public MediaListI , public Serializable{
214   private:
215     MediaURI *_root;
216     bool _owning;
217     void emptyList();
218   public:
219     MediaList(const MediaURI *root); //root is copied
220     virtual ~MediaList();
221     //no copy root UIR
222     virtual MediaURI * getRoot() {return _root;}
223     //all methods return a copy of the URI
224     //so the caller has to destroy this
225     virtual MediaURI * getRootURI();
226     virtual MediaURI * getParent(MediaURI *c) ;
227     virtual MediaURI * getURI(Media *m);
228     virtual ULONG getProvider();
229     virtual void setOwning(bool owning);
230     //serialize functions
231     //get the #of bytes needed to serialize
232     virtual int getSerializedLenImpl();
233     //serialize
234     //advance buffer, check if >= end
235     //return 0 if OK
236     virtual int serializeImpl(SerializeBuffer *b);
237     //deserialize
238     //advance buffer, check if >= end
239     //return 0 if OK
240     virtual int deserializeImpl(SerializeBuffer *b);
241  };
242
243 #endif