Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
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
26
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
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);
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);
81
82 value = strm_dict_find_rstr(dict, commentKey);
84
85 value = strm_dict_find_rstr(dict, genreKey);
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);
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
147{
148 strm_dict_t *dict;
149 dict = strm_dict_new();
150 update(dict);
151 strm_dict_destroy(dict);
152}
153
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
170{
171 return m_height * m_pixelHeight;
172}
173
175{
176 return m_width * m_pixelWidth;
177}
178
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
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
198{
199 return m_title;
200}
201
203{
204 return m_seekable;
205}
206
208{
209 return m_artist;
210}
211
213{
214 return m_comment;
215}
216
218{
219 return m_genre;
220}
221
223{
224 return m_year;
225}
226
228{
229 if (hasVideo())
230 return QLatin1String("video");
231 else if (hasAudio())
232 return QLatin1String("audio");
233 else
234 return QString();
235}
236
238{
239 return m_audioBitRate;
240}
241
243{
244 return m_sampleRate;
245}
246
248{
249 return m_album;
250}
251
253{
254 return m_track;
255}
256
258{
259 return QSize(width(), height());
260}
261
QString comment() const
bool update(const strm_dict_t *dict)
QString mediaType() const
qlonglong duration() const
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
Combined button and popup list for selecting options.
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum type
static const char * artistKey
static const char * heightKey
static const char * yearKey
static const char * durationKey
static const char * widthKey
static const char * albumKey
static const int mediaTypeVideoFlag
static const char * trackSampleKey
static const char * bitRateKey
static const char * trackKey
static const char * trackWidthKey
static const char * pixelWidthKey
static const char * mediaTypeKey
static const char * sampleKey
strm_dict_t * mmr_metadata_split(strm_dict_t const *md, const char *type, unsigned idx)
static const char * trackPixelWidthKey
static const char * strm_string_getx(const strm_string_t *sstr, const char *defaultValue)
static const char * seekableKey
static const char * pixelHeightKey
static const char * trackBitRateKey
static const char * titleKey
static const char * trackHeightKey
static const char * genreKey
static const char * trackPixelHeightKey
static const int mediaTypeAudioFlag
static const char * commentKey
struct strm_dict strm_dict_t
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
qint64 qlonglong
Definition qtypes.h:63
QAction * at