Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqnxmediametadata.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Research In Motion
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <QtCore/qdebug.h>
6#include <QtCore/qfile.h>
7#include <QtCore/qstringlist.h>
8
9#include <mm/renderer/types.h>
10#include <sys/neutrino.h>
11#include <sys/strm.h>
12
13extern "C" {
14// ### include this properly from mm/renderer/events.h once the toolchain is fixed
15extern strm_dict_t* mmr_metadata_split(strm_dict_t const *md,
16 const char *type,
17 unsigned idx);
18}
19
20static const char *strm_string_getx(const strm_string_t *sstr, const char *defaultValue)
21{
22 return sstr ? strm_string_get(sstr) : defaultValue;
23}
24
25QT_BEGIN_NAMESPACE
26
27QQnxMediaMetaData::QQnxMediaMetaData()
28{
29 clear();
30}
31
32static const char * titleKey = "md_title_name";
33static const char * artistKey = "md_title_artist";
34static const char * commentKey = "md_title_comment";
35static const char * genreKey = "md_title_genre";
36static const char * yearKey = "md_title_year";
37static const char * durationKey = "md_title_duration";
38static const char * bitRateKey = "md_title_bitrate";
39static const char * sampleKey = "md_title_samplerate";
40static const char * albumKey = "md_title_album";
41static const char * trackKey = "md_title_track";
42static const char * widthKey = "md_video_width";
43static const char * heightKey = "md_video_height";
44static const char * mediaTypeKey = "md_title_mediatype";
45static const char * pixelWidthKey = "md_video_pixel_width";
46static const char * pixelHeightKey = "md_video_pixel_height";
47static const char * seekableKey = "md_title_seekable";
48static const char * trackSampleKey = "sample_rate";
49static const char * trackBitRateKey = "bitrate";
50static const char * trackWidthKey = "width";
51static const char * trackHeightKey = "height";
52static const char * trackPixelWidthKey = "pixel_width";
53static const char * trackPixelHeightKey = "pixel_height";
54
55static const int mediaTypeAudioFlag = 4;
56static const int mediaTypeVideoFlag = 2;
57
58bool QQnxMediaMetaData::update(const strm_dict_t *dict)
59{
60 if (!dict) {
61 clear();
62 return true;
63 }
64
65 const strm_string_t *value;
66
67 value = strm_dict_find_rstr(dict, durationKey);
68 m_duration = QByteArray(strm_string_getx(value, "0")).toLongLong();
69
70 value = strm_dict_find_rstr(dict, mediaTypeKey);
71 m_mediaType = QByteArray(strm_string_getx(value, "-1")).toInt();
72
73 value = strm_dict_find_rstr(dict, titleKey);
74 m_title = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
75
76 value = strm_dict_find_rstr(dict, seekableKey);
77 m_seekable = (strcmp(strm_string_getx(value, "1"), "0") != 0);
78
79 value = strm_dict_find_rstr(dict, artistKey);
80 m_artist = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
81
82 value = strm_dict_find_rstr(dict, commentKey);
83 m_comment = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
84
85 value = strm_dict_find_rstr(dict, genreKey);
86 m_genre = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
87
88 value = strm_dict_find_rstr(dict, yearKey);
89 m_year = QByteArray(strm_string_getx(value, "0")).toInt();
90
91 value = strm_dict_find_rstr(dict, albumKey);
92 m_album = QString::fromLatin1(QByteArray(strm_string_getx(value, nullptr)));
93
94 value = strm_dict_find_rstr(dict, trackKey);
95 m_track = QByteArray(strm_string_getx(value, "0")).toInt();
96
97 strm_dict_t *at = mmr_metadata_split(dict, "audio", 0);
98 if (at) {
99 value = strm_dict_find_rstr(at, trackSampleKey);
100 m_sampleRate = QByteArray(strm_string_getx(value, "0")).toInt();
101
102 value = strm_dict_find_rstr(at, trackBitRateKey);
103 m_audioBitRate = QByteArray(strm_string_getx(value, "0")).toInt();
104
105 strm_dict_destroy(at);
106 } else {
107 value = strm_dict_find_rstr(dict, sampleKey);
108 m_sampleRate = QByteArray(strm_string_getx(value, "0")).toInt();
109
110 value = strm_dict_find_rstr(dict, bitRateKey);
111 m_audioBitRate = QByteArray(strm_string_getx(value, "0")).toInt();
112 }
113
114 strm_dict_t *vt = mmr_metadata_split(dict, "video", 0);
115 if (vt) {
116 value = strm_dict_find_rstr(vt, trackWidthKey);
117 m_width = QByteArray(strm_string_getx(value, "0")).toInt();
118
119 value = strm_dict_find_rstr(vt, trackHeightKey);
120 m_height = QByteArray(strm_string_getx(value, "0")).toInt();
121
122 value = strm_dict_find_rstr(vt, trackPixelWidthKey);
123 m_pixelWidth = QByteArray(strm_string_getx(value, "1")).toFloat();
124
125 value = strm_dict_find_rstr(vt, trackPixelHeightKey);
126 m_pixelHeight = QByteArray(strm_string_getx(value, "1")).toFloat();
127
128 strm_dict_destroy(vt);
129 } else {
130 value = strm_dict_find_rstr(dict, widthKey);
131 m_width = QByteArray(strm_string_getx(value, "0")).toInt();
132
133 value = strm_dict_find_rstr(dict, heightKey);
134 m_height = QByteArray(strm_string_getx(value, "0")).toInt();
135
136 value = strm_dict_find_rstr(dict, pixelWidthKey);
137 m_pixelWidth = QByteArray(strm_string_getx(value, "1")).toFloat();
138
139 value = strm_dict_find_rstr(dict, pixelHeightKey);
140 m_pixelHeight = QByteArray(strm_string_getx(value, "1")).toFloat();
141 }
142
143 return true;
144}
145
146void QQnxMediaMetaData::clear()
147{
148 strm_dict_t *dict;
149 dict = strm_dict_new();
150 update(dict);
151 strm_dict_destroy(dict);
152}
153
154qlonglong QQnxMediaMetaData::duration() const
155{
156 return m_duration;
157}
158
159// Handling of pixel aspect ratio
160//
161// If the pixel aspect ratio is different from 1:1, it means the video needs to be stretched in
162// order to look natural.
163// For example, if the pixel width is 2, and the pixel height is 1, it means a video of 300x200
164// pixels needs to be displayed as 600x200 to look correct.
165// In order to support this the easiest way, we simply pretend that the actual size of the video
166// is 600x200, which will cause the video to be displayed in an aspect ratio of 3:1 instead of 3:2,
167// and therefore look correct.
168
169int QQnxMediaMetaData::height() const
170{
171 return m_height * m_pixelHeight;
172}
173
174int QQnxMediaMetaData::width() const
175{
176 return m_width * m_pixelWidth;
177}
178
179bool QQnxMediaMetaData::hasVideo() const
180{
181 // By default, assume no video if we can't extract the information
182 if (m_mediaType == -1)
183 return false;
184
185 return (m_mediaType & mediaTypeVideoFlag);
186}
187
188bool QQnxMediaMetaData::hasAudio() const
189{
190 // By default, assume audio only if we can't extract the information
191 if (m_mediaType == -1)
192 return true;
193
194 return (m_mediaType & mediaTypeAudioFlag);
195}
196
197QString QQnxMediaMetaData::title() const
198{
199 return m_title;
200}
201
202bool QQnxMediaMetaData::isSeekable() const
203{
204 return m_seekable;
205}
206
207QString QQnxMediaMetaData::artist() const
208{
209 return m_artist;
210}
211
212QString QQnxMediaMetaData::comment() const
213{
214 return m_comment;
215}
216
217QString QQnxMediaMetaData::genre() const
218{
219 return m_genre;
220}
221
222int QQnxMediaMetaData::year() const
223{
224 return m_year;
225}
226
227QString QQnxMediaMetaData::mediaType() const
228{
229 if (hasVideo())
230 return QLatin1String("video");
231 else if (hasAudio())
232 return QLatin1String("audio");
233 else
234 return QString();
235}
236
237int QQnxMediaMetaData::audioBitRate() const
238{
239 return m_audioBitRate;
240}
241
242int QQnxMediaMetaData::sampleRate() const
243{
244 return m_sampleRate;
245}
246
247QString QQnxMediaMetaData::album() const
248{
249 return m_album;
250}
251
252int QQnxMediaMetaData::track() const
253{
254 return m_track;
255}
256
257QSize QQnxMediaMetaData::resolution() const
258{
259 return QSize(width(), height());
260}
261
262QT_END_NAMESPACE
static const char * widthKey
static const char * trackKey
static const char * titleKey
static const char * pixelHeightKey
static const char * trackPixelHeightKey
static const char * artistKey
static const char * trackHeightKey
static const char * trackPixelWidthKey
static const char * pixelWidthKey
static const char * mediaTypeKey
static const char * genreKey
static const char * trackSampleKey
static const char * bitRateKey
static const char * trackWidthKey
static const char * trackBitRateKey
static const int mediaTypeAudioFlag
static const char * yearKey
static const char * durationKey
static const int mediaTypeVideoFlag
static const char * strm_string_getx(const strm_string_t *sstr, const char *defaultValue)
static const char * commentKey
static const char * heightKey
static const char * sampleKey
static const char * albumKey
static const char * seekableKey
struct strm_dict strm_dict_t