32 value = QString::fromUtf16(
reinterpret_cast<
const char16_t *>(var.pwszVal));
35 value = uint(var.ulVal);
38 value = qulonglong(var.uhVal.QuadPart);
41 value =
bool(var.boolVal);
45 if (!FileTimeToSystemTime(&var.filetime, &t))
48 value = QDateTime(QDate(t.wYear, t.wMonth, t.wDay),
49 QTime(t.wHour, t.wMinute, t.wSecond, t.wMilliseconds),
50 QTimeZone(QTimeZone::UTC));
55 if (FAILED(var.pStream->Stat(&stat, STATFLAG_NONAME)))
57 void *data = malloc(stat.cbSize.QuadPart);
59 if (FAILED(var.pStream->Read(data, stat.cbSize.QuadPart, &read))) {
63 value = QImage::fromData((
const uchar*)data, read);
67 case VT_VECTOR | VT_LPWSTR:
69 for (ULONG i = 0; i < var.calpwstr.cElems; ++i)
70 vList.append(QString::fromUtf16(
reinterpret_cast<
const char16_t *>(var.calpwstr.pElems[i])));
82 PropVariantInit(&var);
85 hr = content->GetValue(key, &var);
88 value = convertValue(var);
91 if (value.isValid() && content) {
92 if (key == PKEY_Media_ClassPrimaryID ) {
93 QString v = value.toString();
94 if (v == QLatin1String(
"{D1607DBC-E323-4BE2-86A1-48A42A28441E}"))
95 value = QStringLiteral(
"Music");
96 else if (v == QLatin1String(
"{DB9830BD-3AB3-4FAB-8A37-1A995F7FF74B}"))
97 value = QStringLiteral(
"Video");
98 else if (v == QLatin1String(
"{01CD0F29-DA4E-4157-897B-6275D50C4F11}"))
99 value = QStringLiteral(
"Audio");
100 else if (v == QLatin1String(
"{FCF24A76-9A57-4036-990D-E35DD8B244E1}"))
101 value = QStringLiteral(
"Other");
102 }
else if (key == PKEY_Media_Duration) {
104 value = (value.toLongLong() + 10000) / 10000;
105 }
else if (key == PKEY_Video_Compression) {
106 value =
int(QWindowsMultimediaUtils::codecForVideoFormat(value.toUuid()));
107 }
else if (key == PKEY_Audio_Format) {
108 value =
int(QWindowsMultimediaUtils::codecForAudioFormat(value.toUuid()));
109 }
else if (key == PKEY_Video_FrameHeight ) {
111 res.setHeight(value.toUInt());
112 if (content && SUCCEEDED(content->GetValue(PKEY_Video_FrameWidth, &var)))
113 res.setWidth(convertValue(var).toUInt());
115 }
else if (key == PKEY_Video_Orientation) {
116 uint orientation = 0;
117 if (content && SUCCEEDED(content->GetValue(PKEY_Video_Orientation, &var)))
118 orientation = convertValue(var).toUInt();
120 }
else if (key == PKEY_Video_FrameRate) {
121 value = value.toReal() / 1000.f;
126 PropVariantClear(&var);
130QMediaMetaData MFMetaData::fromNative(IMFMediaSource* mediaSource)
132 QMediaMetaData metaData;
134 IPropertyStore *content =
nullptr;
135 if (!SUCCEEDED(MFGetService(mediaSource, MF_PROPERTY_HANDLER_SERVICE, IID_PPV_ARGS(&content))))
140 if (SUCCEEDED(content->GetCount(&cProps))) {
141 for (DWORD i = 0; i < cProps; i++)
144 if (FAILED(content->GetAt(i, &key)))
146 QMediaMetaData::Key mediaKey;
147 if (key == PKEY_Author) {
148 mediaKey = QMediaMetaData::Author;
149 }
else if (key == PKEY_Title) {
150 mediaKey = QMediaMetaData::Title;
155 }
else if (key == PKEY_Media_EncodingSettings) {
156 mediaKey = QMediaMetaData::Description;
157 }
else if (key == PKEY_Copyright) {
158 mediaKey = QMediaMetaData::Copyright;
159 }
else if (key == PKEY_Comment) {
160 mediaKey = QMediaMetaData::Comment;
161 }
else if (key == PKEY_Media_ProviderStyle) {
162 mediaKey = QMediaMetaData::Genre;
163 }
else if (key == PKEY_Media_DateEncoded) {
164 mediaKey = QMediaMetaData::Date;
169 }
else if (key == PKEY_Language) {
170 mediaKey = QMediaMetaData::Language;
171 }
else if (key == PKEY_Media_Publisher) {
172 mediaKey = QMediaMetaData::Publisher;
173 }
else if (key == PKEY_Media_ClassPrimaryID) {
174 mediaKey = QMediaMetaData::MediaType;
175 }
else if (key == PKEY_Media_Duration) {
176 mediaKey = QMediaMetaData::Duration;
177 }
else if (key == PKEY_Audio_EncodingBitrate) {
178 mediaKey = QMediaMetaData::AudioBitRate;
179 }
else if (key == PKEY_Audio_Format) {
180 mediaKey = QMediaMetaData::AudioCodec;
189 }
else if (key == PKEY_Music_AlbumTitle) {
190 mediaKey = QMediaMetaData::AlbumTitle;
191 }
else if (key == PKEY_Music_AlbumArtist) {
192 mediaKey = QMediaMetaData::AlbumArtist;
193 }
else if (key == PKEY_Music_Artist) {
194 mediaKey = QMediaMetaData::ContributingArtist;
195 }
else if (key == PKEY_Music_Composer) {
196 mediaKey = QMediaMetaData::Composer;
203 }
else if (key == PKEY_Music_TrackNumber) {
204 mediaKey = QMediaMetaData::TrackNumber;
205 }
else if (key == PKEY_Music_Genre) {
206 mediaKey = QMediaMetaData::Genre;
207 }
else if (key == PKEY_ThumbnailStream) {
208 QVariant val = metaDataValue(content, key);
209 if (val.canConvert<QImage>())
210 QtMultimediaPrivate::setCoverArtImage(metaData, val.value<QImage>());
212 }
else if (key == PKEY_Video_FrameHeight) {
213 mediaKey = QMediaMetaData::Resolution;
214 }
else if (key == PKEY_Video_Orientation) {
215 mediaKey = QMediaMetaData::Orientation;
216 }
else if (key == PKEY_Video_FrameRate) {
217 mediaKey = QMediaMetaData::VideoFrameRate;
218 }
else if (key == PKEY_Video_EncodingBitrate) {
219 mediaKey = QMediaMetaData::VideoBitRate;
220 }
else if (key == PKEY_Video_Compression) {
221 mediaKey = QMediaMetaData::VideoCodec;
229 metaData.insert(mediaKey, metaDataValue(content, key));
241 case QMediaMetaData::Key::Title:
243 case QMediaMetaData::Key::Author:
245 case QMediaMetaData::Key::Comment:
247 case QMediaMetaData::Key::Genre:
248 return PKEY_Music_Genre;
249 case QMediaMetaData::Key::Copyright:
250 return PKEY_Copyright;
251 case QMediaMetaData::Key::Publisher:
252 return PKEY_Media_Publisher;
253 case QMediaMetaData::Key::Url:
254 return PKEY_Media_AuthorUrl;
255 case QMediaMetaData::Key::AlbumTitle:
256 return PKEY_Music_AlbumTitle;
257 case QMediaMetaData::Key::AlbumArtist:
258 return PKEY_Music_AlbumArtist;
259 case QMediaMetaData::Key::TrackNumber:
260 return PKEY_Music_TrackNumber;
261 case QMediaMetaData::Key::Date:
262 return PKEY_Media_DateEncoded;
263 case QMediaMetaData::Key::Composer:
264 return PKEY_Music_Composer;
265 case QMediaMetaData::Key::Duration:
266 return PKEY_Media_Duration;
267 case QMediaMetaData::Key::Language:
268 return PKEY_Language;
269 case QMediaMetaData::Key::Description:
270 return PKEY_Media_EncodingSettings;
271 case QMediaMetaData::Key::AudioBitRate:
272 return PKEY_Audio_EncodingBitrate;
273 case QMediaMetaData::Key::ContributingArtist:
274 return PKEY_Music_Artist;
275#if QT_DEPRECATED_SINCE(6
, 12
)
276 case QtMultimediaPrivate::deprecatedThumbnailImage:
278 case QMediaMetaData::Key::CoverArtImage:
279 return PKEY_ThumbnailStream;
280 case QMediaMetaData::Key::Orientation:
281 return PKEY_Video_Orientation;
282 case QMediaMetaData::Key::VideoFrameRate:
283 return PKEY_Video_FrameRate;
284 case QMediaMetaData::Key::VideoBitRate:
285 return PKEY_Video_EncodingBitrate;
286 case QMediaMetaData::MediaType:
287 return PKEY_Media_ClassPrimaryID;
289 return PROP_KEY_NULL;
295 PROPVARIANT propValue = {};
296 if (SUCCEEDED(InitPropVariantFromString(
reinterpret_cast<LPCWSTR>(value.utf16()), &propValue))) {
297 if (SUCCEEDED(PSCoerceToCanonicalValue(key, &propValue)))
298 content->SetValue(key, propValue);
299 PropVariantClear(&propValue);
333void MFMetaData::toNative(
const QMediaMetaData &metaData, IPropertyStore *content)
337 for (
const auto &key : metaData.keys()) {
339 QVariant value = metaData.value(key);
341 if (key == QMediaMetaData::Key::MediaType) {
343 QString strValue = metaData.stringValue(key);
348 if (strValue == QLatin1String(
"Music"))
349 v = QLatin1String(
"{D1607DBC-E323-4BE2-86A1-48A42A28441E}");
350 else if (strValue == QLatin1String(
"Video"))
351 v = QLatin1String(
"{DB9830BD-3AB3-4FAB-8A37-1A995F7FF74B}");
352 else if (strValue == QLatin1String(
"Audio"))
353 v = QLatin1String(
"{01CD0F29-DA4E-4157-897B-6275D50C4F11}");
355 v = QLatin1String(
"{FCF24A76-9A57-4036-990D-E35DD8B244E1}");
357 setStringProperty(content, PKEY_Media_ClassPrimaryID, v);
359 }
else if (key == QMediaMetaData::Key::Duration) {
361 setUInt64Property(content, PKEY_Media_Duration, value.toULongLong() * 10000);
363 }
else if (key == QMediaMetaData::Key::Resolution) {
365 QSize res = value.toSize();
366 setUInt32Property(content, PKEY_Video_FrameWidth, quint32(res.width()));
367 setUInt32Property(content, PKEY_Video_FrameHeight, quint32(res.height()));
369 }
else if (key == QMediaMetaData::Key::Orientation) {
371 setUInt32Property(content, PKEY_Video_Orientation, value.toUInt());
373 }
else if (key == QMediaMetaData::Key::VideoFrameRate) {
375 qreal fps = value.toReal();
376 setUInt32Property(content, PKEY_Video_FrameRate, quint32(fps * 1000));
378 }
else if (key == QMediaMetaData::Key::TrackNumber) {
380 setUInt32Property(content, PKEY_Music_TrackNumber, value.toUInt());
382 }
else if (key == QMediaMetaData::Key::AudioBitRate) {
384 setUInt32Property(content, PKEY_Audio_EncodingBitrate, value.toUInt());
386 }
else if (key == QMediaMetaData::Key::VideoBitRate) {
388 setUInt32Property(content, PKEY_Video_EncodingBitrate, value.toUInt());
390 }
else if (key == QMediaMetaData::Key::Date) {
394 ULARGE_INTEGER t = {};
395 t.QuadPart = ULONGLONG(value.toDateTime().toUTC().toMSecsSinceEpoch() * 10000
396 + 116444736000000000LL);
399 ft.dwHighDateTime = t.HighPart;
400 ft.dwLowDateTime = t.LowPart;
402 setFileTimeProperty(content, PKEY_Media_DateEncoded, &ft);
408 REFPROPERTYKEY propKey = propertyKeyForMetaDataKey(key);
410 if (propKey != PROP_KEY_NULL) {
411 QString strValue = metaData.stringValue(key);
412 if (!strValue.isEmpty())
413 setStringProperty(content, propKey, strValue);