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