1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
/*
* File: resources.h
* Author: savop
*
* Created on 30. September 2009, 15:17
*/
#ifndef _RESOURCES_H
#define _RESOURCES_H
#include "database.h"
#include "object.h"
#include <vdr/channels.h>
#include <vdr/recording.h>
class cUPnPResourceMediator;
class cMediaDatabase;
/**
* UPnP Resource
*
* This contains all details about a resource
*/
class cUPnPResource : public cListObject {
friend class cUPnPResourceMediator;
friend class cUPnPResources;
private:
unsigned int mResourceID;
int mResourceType;
cString mResource;
cString mDuration;
cString mResolution;
cString mProtocolInfo;
cString mContentType;
cString mImportURI;
off64_t mSize;
unsigned int mBitrate;
unsigned int mSampleFrequency;
unsigned int mBitsPerSample;
unsigned int mNrAudioChannels;
unsigned int mColorDepth;
cUPnPResource();
public:
/**
* Get resource ID
*
* Gets the resource ID
*
* @return the resource ID
*/
unsigned int getID() const { return this->mResourceID; }
/**
* Get the resources
*
* Returns the resource. This is in most cases the file name or resource locator
* where to find the resource
*
* @return the resource string
*/
const char* getResource() const { return this->mResource; }
/**
* Get the duration
*
* Returns a date time string with the duration of the resource
*
* @return the duration of the resource
*/
const char* getDuration() const { return this->mDuration; }
/**
* Get the resolution
*
* Returns the resolution string with the pattern width x height in pixels
*
* @return the resolution of the resource
*/
const char* getResolution() const { return this->mResolution; }
/**
* Get the protocol info
*
* This returns the protocol info field of a resource
*
* @return the protocol info string
*/
const char* getProtocolInfo() const { return this->mProtocolInfo; }
/**
* Get the content type
*
* Returns the mime type of the content of the resource
*
* @return the content type of the resource
*/
const char* getContentType() const { return this->mContentType; }
/**
* Get the import URI
*
* This returns the import URI where the resource was located before importing
* it
*
* @return the import URI
*/
const char* getImportURI() const { return this->mImportURI; }
/**
* Get the resource type
*
* This returns the resource type of the resource.
*
* @return the resource type
*/
int getResourceType() const { return this->mResourceType; }
/**
* Get the file size
*
* Returns the file size in bytes of the resource or 0 if its unknown or a
* stream
*
* @return the file size
*/
off64_t getFileSize() const { return this->mSize; };
/**
* Get the last modification
*
* This returns the timestamp of the last modification to the file. If it
* is a stream, then its the current time.
*
* @return the timestamp with the last modification of the resource
*/
time_t getLastModification() const;
/**
* Get the bitrate
*
* This returns the bitrate of the resource in bits per second.
*
* @return the bitrate of the resource
*/
unsigned int getBitrate() const { return this->mBitrate; }
/**
* Get the sample frequency
*
* Returns the sample frequency in samples per second.
*
* @return the sample frequency of the resource
*/
unsigned int getSampleFrequency() const { return this->mSampleFrequency; }
/**
* Get the bits per sample
*
* Returns the number of bits per sample.
*
* @return the bits per sample of the resource
*/
unsigned int getBitsPerSample() const { return this->mBitsPerSample; }
/**
* Get number of audio channels
*
* Returns the number of audio channels of the audio stream in a video
*
* @return the number of audio channels
*/
unsigned int getNrAudioChannels() const { return this->mNrAudioChannels; }
/**
* Get the color depth
*
* Returns the color depth of the resource in pits per pixel
*
* @return the color depth of the resource
*/
unsigned int getColorDepth() const { return this->mColorDepth; }
};
class cUPnPClassObject;
class cUPnPClassItem;
class cUPnPClassVideoItem;
class cUPnPClassVideoBroadcast;
/**
* The resource manager
*
* This manages the resources in an internal cache. It may create a new resource
* from a channel, a recording or a custom file.
*/
class cUPnPResources {
private:
cHash<cUPnPResource>* mResources;
static cUPnPResources* mInstance;
cUPnPResourceMediator* mMediator;
cSQLiteDatabase* mDatabase;
cUPnPResources();
public:
/**
* Fill object with its resources
*
* This will load all the resources from the database, which are associated
* to the given object
*
* @param Object the object, which shall be filled
* @return returns
* - \bc 0, if loading was successful
* - \bc <0, otherwise
*/
int getResourcesOfObject(cUPnPClassObject* Object);
/**
* Loads all resources from database
*
* This loads all resources from the database into the internal cache.
*
* @return returns
* - \bc 0, if loading was successful
* - \bc <0, otherwise
*/
int loadResources();
/*! @copydoc cUPnPResourceMediator::getResource */
cUPnPResource* getResource(unsigned int ResourceID);
virtual ~cUPnPResources();
/**
* Get the instance of the resource manager
*
* This returns the instance of the resource manager.
*
* @return the instance of the manager
*/
static cUPnPResources* getInstance();
/**
* Create resource from channel
*
* This creates a new resource from the given channel. It determines what
* kind of video stream it is and further details if available. It stores
* the resource in the database after creating it.
*
* @param Object the videoBroadcast item which holds the resource
* @param Channel the VDR TV channel
* @return returns
* - \bc 0, if loading was successful
* - \bc <0, otherwise
*/
int createFromChannel(cUPnPClassVideoBroadcast* Object, cChannel* Channel);
/**
* Create resource from recording
*
* This creates a new resource from the given recording. It determines what
* kind of video stream it is and further details if available. It stores
* the resource in the database after creating it.
*
* @param Object the videoItem item which holds the resource
* @param Recording the VDR TV recording
* @return returns
* - \bc 0, if loading was successful
* - \bc <0, otherwise
*/
int createFromRecording(cUPnPClassVideoItem* Object, cRecording* Recording);
/**
* Create resource from file
*
* This creates a new resource from the given file. It determines all available
* information about the resource by analizing the content. It stores
* the resource in the database after creating it.
*
* @param Object the item which holds the resource
* @param File the file name
* @return returns
* - \bc 0, if loading was successful
* - \bc <0, otherwise
*/
int createFromFile(cUPnPClassItem* Object, cString File);
};
/**
* The resource mediator
*
* This is another mediator which communicates with the database. It manages the
* resources in the database
*/
class cUPnPResourceMediator {
friend class cUPnPResources;
private:
cSQLiteDatabase* mDatabase;
cUPnPResourceMediator();
unsigned int getNextResourceID();
public:
virtual ~cUPnPResourceMediator();
/**
* Get a resource by ID
*
* This returns a resource by its resource ID
*
* @param ResourceID the resource ID of the demanded resource
* @return the requested resource
*/
cUPnPResource* getResource(unsigned int ResourceID);
/**
* Saves the resource
*
* This updates the information in the database with those in the resource
* object
*
* @param Resource the resource which shall be saved
* @return returns
* - \bc 0, if saving was successful
* - \bc <0, if an error occured
*/
int saveResource(cUPnPClassObject* Object, cUPnPResource* Resource);
/**
* Create new resource
*
* This creates a new resource and stores the skeleton in the database. The
* newly created resource will only contain all required information.
*
* @param Object the Object which will hold the resource
* @param ResourceType the type of the resource
* @param ResourceFile the file or URL, where the resource can be located
* @param ContentType the mime type of the content
* @param ProtocolInfo the protocol information of the resource
* @return the newly created resource
*/
cUPnPResource* newResource(cUPnPClassObject* Object, int ResourceType, cString ResourceFile, cString ContentType, cString ProtocolInfo);
};
#endif /* _RESOURCES_H */
|