|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qmediaresource.h" |
|
43 |
|
44 #include <QtCore/qsize.h> |
|
45 #include <QtCore/qurl.h> |
|
46 #include <QtCore/qvariant.h> |
|
47 |
|
48 QT_BEGIN_NAMESPACE |
|
49 |
|
50 /*! |
|
51 \class QMediaResource |
|
52 \preliminary |
|
53 \brief The QMediaResource class provides a description of a media resource. |
|
54 \ingroup multimedia |
|
55 |
|
56 A media resource is composed of a \l {url()}{URL} containing the |
|
57 location of the resource and a set of properties that describe the |
|
58 format of the resource. The properties provide a means to assess a |
|
59 resource without first attempting to load it, and in situations where |
|
60 media be represented by multiple alternative representations provide a |
|
61 means to select the appropriate resource. |
|
62 |
|
63 Media made available by a remote services can often be available in |
|
64 multiple encodings or quality levels, this allows a client to select |
|
65 an appropriate resource based on considerations such as codecs supported, |
|
66 network bandwidth, and display constraints. QMediaResource includes |
|
67 information such as the \l {mimeType()}{MIME type}, \l {audioCodec()}{audio} |
|
68 and \l {videoCodec()}{video} codecs, \l {audioBitRate()}{audio} and |
|
69 \l {videoBitRate()}{video} bit rates, and \l {resolution()}{resolution} |
|
70 so these constraints and others can be evaluated. |
|
71 |
|
72 The only mandatory property of a QMediaResource is the url(). |
|
73 |
|
74 \sa QMediaContent |
|
75 */ |
|
76 |
|
77 /*! |
|
78 \typedef QMediaResourceList |
|
79 |
|
80 Synonym for \c QList<QMediaResource> |
|
81 */ |
|
82 |
|
83 /*! |
|
84 Constructs a null media resource. |
|
85 */ |
|
86 QMediaResource::QMediaResource() |
|
87 { |
|
88 } |
|
89 |
|
90 /*! |
|
91 Constructs a media resource with the given \a mimeType from a \a url. |
|
92 */ |
|
93 QMediaResource::QMediaResource(const QUrl &url, const QString &mimeType) |
|
94 { |
|
95 values.insert(Url, url); |
|
96 values.insert(MimeType, mimeType); |
|
97 } |
|
98 |
|
99 /*! |
|
100 Constructs a media resource with the given \a mimeType from a network \a request. |
|
101 */ |
|
102 QMediaResource::QMediaResource(const QNetworkRequest &request, const QString &mimeType) |
|
103 { |
|
104 values.insert(Request, QVariant::fromValue(request)); |
|
105 values.insert(Url, request.url()); |
|
106 values.insert(MimeType, mimeType); |
|
107 } |
|
108 |
|
109 /*! |
|
110 Constructs a copy of a media resource \a other. |
|
111 */ |
|
112 QMediaResource::QMediaResource(const QMediaResource &other) |
|
113 : values(other.values) |
|
114 { |
|
115 } |
|
116 |
|
117 /*! |
|
118 Assigns the value of \a other to a media resource. |
|
119 */ |
|
120 QMediaResource &QMediaResource::operator =(const QMediaResource &other) |
|
121 { |
|
122 values = other.values; |
|
123 |
|
124 return *this; |
|
125 } |
|
126 |
|
127 /*! |
|
128 Destroys a media resource. |
|
129 */ |
|
130 QMediaResource::~QMediaResource() |
|
131 { |
|
132 } |
|
133 |
|
134 |
|
135 /*! |
|
136 Compares a media resource to \a other. |
|
137 |
|
138 Returns true if the resources are identical, and false otherwise. |
|
139 */ |
|
140 bool QMediaResource::operator ==(const QMediaResource &other) const |
|
141 { |
|
142 return values == other.values; |
|
143 } |
|
144 |
|
145 /*! |
|
146 Compares a media resource to \a other. |
|
147 |
|
148 Returns true if they are different, and false otherwise. |
|
149 */ |
|
150 bool QMediaResource::operator !=(const QMediaResource &other) const |
|
151 { |
|
152 return values != other.values; |
|
153 } |
|
154 |
|
155 /*! |
|
156 Identifies if a media resource is null. |
|
157 |
|
158 Returns true if the resource is null, and false otherwise. |
|
159 */ |
|
160 bool QMediaResource::isNull() const |
|
161 { |
|
162 return values.isEmpty(); |
|
163 } |
|
164 |
|
165 /*! |
|
166 Returns the URL of a media resource. |
|
167 */ |
|
168 QUrl QMediaResource::url() const |
|
169 { |
|
170 return qvariant_cast<QUrl>(values.value(Url)); |
|
171 } |
|
172 |
|
173 /*! |
|
174 Returns the network request associated with this media resource. |
|
175 */ |
|
176 QNetworkRequest QMediaResource::request() const |
|
177 { |
|
178 if(values.contains(Request)) |
|
179 return qvariant_cast<QNetworkRequest>(values.value(Request)); |
|
180 |
|
181 return QNetworkRequest(url()); |
|
182 } |
|
183 |
|
184 /*! |
|
185 Returns the MIME type of a media resource. |
|
186 |
|
187 This may be null if the MIME type is unknown. |
|
188 */ |
|
189 QString QMediaResource::mimeType() const |
|
190 { |
|
191 return qvariant_cast<QString>(values.value(MimeType)); |
|
192 } |
|
193 |
|
194 /*! |
|
195 Returns the language of a media resource as an ISO 639-2 code. |
|
196 |
|
197 This may be null if the language is unknown. |
|
198 */ |
|
199 QString QMediaResource::language() const |
|
200 { |
|
201 return qvariant_cast<QString>(values.value(Language)); |
|
202 } |
|
203 |
|
204 /*! |
|
205 Sets the \a language of a media resource. |
|
206 */ |
|
207 void QMediaResource::setLanguage(const QString &language) |
|
208 { |
|
209 if (!language.isNull()) |
|
210 values.insert(Language, language); |
|
211 else |
|
212 values.remove(Language); |
|
213 } |
|
214 |
|
215 /*! |
|
216 Returns the audio codec of a media resource. |
|
217 |
|
218 This may be null if the media resource does not contain an audio stream, or the codec is |
|
219 unknown. |
|
220 */ |
|
221 QString QMediaResource::audioCodec() const |
|
222 { |
|
223 return qvariant_cast<QString>(values.value(AudioCodec)); |
|
224 } |
|
225 |
|
226 /*! |
|
227 Sets the audio \a codec of a media resource. |
|
228 */ |
|
229 void QMediaResource::setAudioCodec(const QString &codec) |
|
230 { |
|
231 if (!codec.isNull()) |
|
232 values.insert(AudioCodec, codec); |
|
233 else |
|
234 values.remove(AudioCodec); |
|
235 } |
|
236 |
|
237 /*! |
|
238 Returns the video codec of a media resource. |
|
239 |
|
240 This may be null if the media resource does not contain a video stream, or the codec is |
|
241 unknonwn. |
|
242 */ |
|
243 QString QMediaResource::videoCodec() const |
|
244 { |
|
245 return qvariant_cast<QString>(values.value(VideoCodec)); |
|
246 } |
|
247 |
|
248 /*! |
|
249 Sets the video \a codec of media resource. |
|
250 */ |
|
251 void QMediaResource::setVideoCodec(const QString &codec) |
|
252 { |
|
253 if (!codec.isNull()) |
|
254 values.insert(VideoCodec, codec); |
|
255 else |
|
256 values.remove(VideoCodec); |
|
257 } |
|
258 |
|
259 /*! |
|
260 Returns the size in bytes of a media resource. |
|
261 |
|
262 This may be zero if the size is unknown. |
|
263 */ |
|
264 qint64 QMediaResource::dataSize() const |
|
265 { |
|
266 return qvariant_cast<qint64>(values.value(DataSize)); |
|
267 } |
|
268 |
|
269 /*! |
|
270 Sets the \a size in bytes of a media resource. |
|
271 */ |
|
272 void QMediaResource::setDataSize(const qint64 size) |
|
273 { |
|
274 if (size != 0) |
|
275 values.insert(DataSize, size); |
|
276 else |
|
277 values.remove(DataSize); |
|
278 } |
|
279 |
|
280 /*! |
|
281 Returns the bit rate in bits per second of a media resource's audio stream. |
|
282 |
|
283 This may be zero if the bit rate is unknown, or the resource contains no audio stream. |
|
284 */ |
|
285 int QMediaResource::audioBitRate() const |
|
286 { |
|
287 return values.value(AudioBitRate).toInt(); |
|
288 } |
|
289 |
|
290 /*! |
|
291 Sets the bit \a rate in bits per second of a media resource's video stream. |
|
292 */ |
|
293 void QMediaResource::setAudioBitRate(int rate) |
|
294 { |
|
295 if (rate != 0) |
|
296 values.insert(AudioBitRate, rate); |
|
297 else |
|
298 values.remove(AudioBitRate); |
|
299 } |
|
300 |
|
301 /*! |
|
302 Returns the audio sample rate of a media resource. |
|
303 |
|
304 This may be zero if the sample size is unknown, or the resource contains no audio stream. |
|
305 */ |
|
306 int QMediaResource::sampleRate() const |
|
307 { |
|
308 return qvariant_cast<int>(values.value(SampleRate)); |
|
309 } |
|
310 |
|
311 /*! |
|
312 Sets the audio \a sampleRate of a media resource. |
|
313 */ |
|
314 void QMediaResource::setSampleRate(int sampleRate) |
|
315 { |
|
316 if (sampleRate != 0) |
|
317 values.insert(SampleRate, sampleRate); |
|
318 else |
|
319 values.remove(SampleRate); |
|
320 } |
|
321 |
|
322 /*! |
|
323 Returns the number of audio channels in a media resource. |
|
324 |
|
325 This may be zero if the sample size is unknown, or the resource contains no audio stream. |
|
326 */ |
|
327 int QMediaResource::channelCount() const |
|
328 { |
|
329 return qvariant_cast<int>(values.value(ChannelCount)); |
|
330 } |
|
331 |
|
332 /*! |
|
333 Sets the number of audio \a channels in a media resource. |
|
334 */ |
|
335 void QMediaResource::setChannelCount(int channels) |
|
336 { |
|
337 if (channels != 0) |
|
338 values.insert(ChannelCount, channels); |
|
339 else |
|
340 values.remove(ChannelCount); |
|
341 } |
|
342 |
|
343 /*! |
|
344 Returns the bit rate in bits per second of a media resource's video stream. |
|
345 |
|
346 This may be zero if the bit rate is unknown, or the resource contains no video stream. |
|
347 */ |
|
348 int QMediaResource::videoBitRate() const |
|
349 { |
|
350 return values.value(VideoBitRate).toInt(); |
|
351 } |
|
352 |
|
353 /*! |
|
354 Sets the bit \a rate in bits per second of a media resource's video stream. |
|
355 */ |
|
356 void QMediaResource::setVideoBitRate(int rate) |
|
357 { |
|
358 if (rate != 0) |
|
359 values.insert(VideoBitRate, rate); |
|
360 else |
|
361 values.remove(VideoBitRate); |
|
362 } |
|
363 |
|
364 /*! |
|
365 Returns the resolution in pixels of a media resource. |
|
366 |
|
367 This may be null is the resolution is unknown, or the resource contains no pixel data (i.e. the |
|
368 resource is an audio stream. |
|
369 */ |
|
370 QSize QMediaResource::resolution() const |
|
371 { |
|
372 return qvariant_cast<QSize>(values.value(Resolution)); |
|
373 } |
|
374 |
|
375 /*! |
|
376 Sets the \a resolution in pixels of a media resource. |
|
377 */ |
|
378 void QMediaResource::setResolution(const QSize &resolution) |
|
379 { |
|
380 if (resolution.width() != -1 || resolution.height() != -1) |
|
381 values.insert(Resolution, resolution); |
|
382 else |
|
383 values.remove(Resolution); |
|
384 } |
|
385 |
|
386 /*! |
|
387 Sets the \a width and \a height in pixels of a media resource. |
|
388 */ |
|
389 void QMediaResource::setResolution(int width, int height) |
|
390 { |
|
391 if (width != -1 || height != -1) |
|
392 values.insert(Resolution, QSize(width, height)); |
|
393 else |
|
394 values.remove(Resolution); |
|
395 } |
|
396 QT_END_NAMESPACE |
|
397 |