29 value = QString::fromUtf16(
reinterpret_cast<
const char16_t *>(var.pwszVal));
32 value = uint(var.ulVal);
35 value = qulonglong(var.uhVal.QuadPart);
38 value =
bool(var.boolVal);
42 if (!FileTimeToSystemTime(&var.filetime, &t))
45 value = QDateTime(QDate(t.wYear, t.wMonth, t.wDay),
46 QTime(t.wHour, t.wMinute, t.wSecond, t.wMilliseconds),
47 QTimeZone(QTimeZone::UTC));
52 if (FAILED(var.pStream->Stat(&stat, STATFLAG_NONAME)))
54 void *data = malloc(stat.cbSize.QuadPart);
56 if (FAILED(var.pStream->Read(data, stat.cbSize.QuadPart, &read))) {
60 value = QImage::fromData((
const uchar*)data, read);
64 case VT_VECTOR | VT_LPWSTR:
66 for (ULONG i = 0; i < var.calpwstr.cElems; ++i)
67 vList.append(QString::fromUtf16(
reinterpret_cast<
const char16_t *>(var.calpwstr.pElems[i])));
74static QVariant
metaDataValue(IPropertyStore *content,
const PROPERTYKEY &key)
79 PropVariantInit(&var);
82 hr = content->GetValue(key, &var);
85 value = convertValue(var);
88 if (value.isValid() && content) {
89 if (key == PKEY_Media_ClassPrimaryID ) {
90 QString v = value.toString();
91 if (v == QLatin1String(
"{D1607DBC-E323-4BE2-86A1-48A42A28441E}"))
92 value = QStringLiteral(
"Music");
93 else if (v == QLatin1String(
"{DB9830BD-3AB3-4FAB-8A37-1A995F7FF74B}"))
94 value = QStringLiteral(
"Video");
95 else if (v == QLatin1String(
"{01CD0F29-DA4E-4157-897B-6275D50C4F11}"))
96 value = QStringLiteral(
"Audio");
97 else if (v == QLatin1String(
"{FCF24A76-9A57-4036-990D-E35DD8B244E1}"))
98 value = QStringLiteral(
"Other");
99 }
else if (key == PKEY_Media_Duration) {
101 value = (value.toLongLong() + 10000) / 10000;
102 }
else if (key == PKEY_Video_Compression) {
103 value =
int(QWindowsMultimediaUtils::codecForVideoFormat(value.toUuid()));
104 }
else if (key == PKEY_Audio_Format) {
105 value =
int(QWindowsMultimediaUtils::codecForAudioFormat(value.toUuid()));
106 }
else if (key == PKEY_Video_FrameHeight ) {
108 res.setHeight(value.toUInt());
109 if (content && SUCCEEDED(content->GetValue(PKEY_Video_FrameWidth, &var)))
110 res.setWidth(convertValue(var).toUInt());
112 }
else if (key == PKEY_Video_Orientation) {
113 uint orientation = 0;
114 if (content && SUCCEEDED(content->GetValue(PKEY_Video_Orientation, &var)))
115 orientation = convertValue(var).toUInt();
117 }
else if (key == PKEY_Video_FrameRate) {
118 value = value.toReal() / 1000.f;
123 PropVariantClear(&var);
127QMediaMetaData
MFMetaData::fromNative(IMFMediaSource* mediaSource)
131 IPropertyStore *content =
nullptr;
132 if (!SUCCEEDED(MFGetService(mediaSource, MF_PROPERTY_HANDLER_SERVICE, IID_PPV_ARGS(&content))))
137 if (SUCCEEDED(content->GetCount(&cProps))) {
138 for (DWORD i = 0; i < cProps; i++)
141 if (FAILED(content->GetAt(i, &key)))
143 QMediaMetaData::Key mediaKey;
144 if (key == PKEY_Author) {
145 mediaKey = QMediaMetaData::Author;
146 }
else if (key == PKEY_Title) {
147 mediaKey = QMediaMetaData::Title;
152 }
else if (key == PKEY_Media_EncodingSettings) {
153 mediaKey = QMediaMetaData::Description;
154 }
else if (key == PKEY_Copyright) {
155 mediaKey = QMediaMetaData::Copyright;
156 }
else if (key == PKEY_Comment) {
157 mediaKey = QMediaMetaData::Comment;
158 }
else if (key == PKEY_Media_ProviderStyle) {
159 mediaKey = QMediaMetaData::Genre;
160 }
else if (key == PKEY_Media_DateEncoded) {
161 mediaKey = QMediaMetaData::Date;
166 }
else if (key == PKEY_Language) {
167 mediaKey = QMediaMetaData::Language;
168 }
else if (key == PKEY_Media_Publisher) {
169 mediaKey = QMediaMetaData::Publisher;
170 }
else if (key == PKEY_Media_ClassPrimaryID) {
171 mediaKey = QMediaMetaData::MediaType;
172 }
else if (key == PKEY_Media_Duration) {
173 mediaKey = QMediaMetaData::Duration;
174 }
else if (key == PKEY_Audio_EncodingBitrate) {
175 mediaKey = QMediaMetaData::AudioBitRate;
176 }
else if (key == PKEY_Audio_Format) {
177 mediaKey = QMediaMetaData::AudioCodec;
186 }
else if (key == PKEY_Music_AlbumTitle) {
187 mediaKey = QMediaMetaData::AlbumTitle;
188 }
else if (key == PKEY_Music_AlbumArtist) {
189 mediaKey = QMediaMetaData::AlbumArtist;
190 }
else if (key == PKEY_Music_Artist) {
191 mediaKey = QMediaMetaData::ContributingArtist;
192 }
else if (key == PKEY_Music_Composer) {
193 mediaKey = QMediaMetaData::Composer;
200 }
else if (key == PKEY_Music_TrackNumber) {
201 mediaKey = QMediaMetaData::TrackNumber;
202 }
else if (key == PKEY_Music_Genre) {
203 mediaKey = QMediaMetaData::Genre;
204 }
else if (key == PKEY_ThumbnailStream) {
205 mediaKey = QMediaMetaData::ThumbnailImage;
206 }
else if (key == PKEY_Video_FrameHeight) {
207 mediaKey = QMediaMetaData::Resolution;
208 }
else if (key == PKEY_Video_Orientation) {
209 mediaKey = QMediaMetaData::Orientation;
210 }
else if (key == PKEY_Video_FrameRate) {
211 mediaKey = QMediaMetaData::VideoFrameRate;
212 }
else if (key == PKEY_Video_EncodingBitrate) {
213 mediaKey = QMediaMetaData::VideoBitRate;
214 }
else if (key == PKEY_Video_Compression) {
215 mediaKey = QMediaMetaData::VideoCodec;
223 metaData.insert(mediaKey, metaDataValue(content, key));
235 case QMediaMetaData::Key::Title:
237 case QMediaMetaData::Key::Author:
239 case QMediaMetaData::Key::Comment:
241 case QMediaMetaData::Key::Genre:
242 return PKEY_Music_Genre;
243 case QMediaMetaData::Key::Copyright:
244 return PKEY_Copyright;
245 case QMediaMetaData::Key::Publisher:
246 return PKEY_Media_Publisher;
247 case QMediaMetaData::Key::Url:
248 return PKEY_Media_AuthorUrl;
249 case QMediaMetaData::Key::AlbumTitle:
250 return PKEY_Music_AlbumTitle;
251 case QMediaMetaData::Key::AlbumArtist:
252 return PKEY_Music_AlbumArtist;
253 case QMediaMetaData::Key::TrackNumber:
254 return PKEY_Music_TrackNumber;
255 case QMediaMetaData::Key::Date:
256 return PKEY_Media_DateEncoded;
257 case QMediaMetaData::Key::Composer:
258 return PKEY_Music_Composer;
259 case QMediaMetaData::Key::Duration:
260 return PKEY_Media_Duration;
261 case QMediaMetaData::Key::Language:
262 return PKEY_Language;
263 case QMediaMetaData::Key::Description:
264 return PKEY_Media_EncodingSettings;
265 case QMediaMetaData::Key::AudioBitRate:
266 return PKEY_Audio_EncodingBitrate;
267 case QMediaMetaData::Key::ContributingArtist:
268 return PKEY_Music_Artist;
269 case QMediaMetaData::Key::ThumbnailImage:
270 return PKEY_ThumbnailStream;
271 case QMediaMetaData::Key::Orientation:
272 return PKEY_Video_Orientation;
273 case QMediaMetaData::Key::VideoFrameRate:
274 return PKEY_Video_FrameRate;
275 case QMediaMetaData::Key::VideoBitRate:
276 return PKEY_Video_EncodingBitrate;
277 case QMediaMetaData::MediaType:
278 return PKEY_Media_ClassPrimaryID;
280 return PROP_KEY_NULL;
286 PROPVARIANT propValue = {};
287 if (SUCCEEDED(InitPropVariantFromString(
reinterpret_cast<LPCWSTR>(value.utf16()), &propValue))) {
288 if (SUCCEEDED(PSCoerceToCanonicalValue(key, &propValue)))
289 content->SetValue(key, propValue);
290 PropVariantClear(&propValue);
324void MFMetaData::toNative(
const QMediaMetaData &metaData, IPropertyStore *content)
328 for (
const auto &key : metaData.keys()) {
330 QVariant value = metaData.value(key);
332 if (key == QMediaMetaData::Key::MediaType) {
334 QString strValue = metaData.stringValue(key);
339 if (strValue == QLatin1String(
"Music"))
340 v = QLatin1String(
"{D1607DBC-E323-4BE2-86A1-48A42A28441E}");
341 else if (strValue == QLatin1String(
"Video"))
342 v = QLatin1String(
"{DB9830BD-3AB3-4FAB-8A37-1A995F7FF74B}");
343 else if (strValue == QLatin1String(
"Audio"))
344 v = QLatin1String(
"{01CD0F29-DA4E-4157-897B-6275D50C4F11}");
346 v = QLatin1String(
"{FCF24A76-9A57-4036-990D-E35DD8B244E1}");
348 setStringProperty(content, PKEY_Media_ClassPrimaryID, v);
350 }
else if (key == QMediaMetaData::Key::Duration) {
352 setUInt64Property(content, PKEY_Media_Duration, value.toULongLong() * 10000);
354 }
else if (key == QMediaMetaData::Key::Resolution) {
356 QSize res = value.toSize();
357 setUInt32Property(content, PKEY_Video_FrameWidth, quint32(res.width()));
358 setUInt32Property(content, PKEY_Video_FrameHeight, quint32(res.height()));
360 }
else if (key == QMediaMetaData::Key::Orientation) {
362 setUInt32Property(content, PKEY_Video_Orientation, value.toUInt());
364 }
else if (key == QMediaMetaData::Key::VideoFrameRate) {
366 qreal fps = value.toReal();
367 setUInt32Property(content, PKEY_Video_FrameRate, quint32(fps * 1000));
369 }
else if (key == QMediaMetaData::Key::TrackNumber) {
371 setUInt32Property(content, PKEY_Music_TrackNumber, value.toUInt());
373 }
else if (key == QMediaMetaData::Key::AudioBitRate) {
375 setUInt32Property(content, PKEY_Audio_EncodingBitrate, value.toUInt());
377 }
else if (key == QMediaMetaData::Key::VideoBitRate) {
379 setUInt32Property(content, PKEY_Video_EncodingBitrate, value.toUInt());
381 }
else if (key == QMediaMetaData::Key::Date) {
385 ULARGE_INTEGER t = {};
386 t.QuadPart = ULONGLONG(value.toDateTime().toUTC().toMSecsSinceEpoch() * 10000
387 + 116444736000000000LL);
390 ft.dwHighDateTime = t.HighPart;
391 ft.dwLowDateTime = t.LowPart;
393 setFileTimeProperty(content, PKEY_Media_DateEncoded, &ft);
399 REFPROPERTYKEY propKey = propertyKeyForMetaDataKey(key);
401 if (propKey != PROP_KEY_NULL) {
402 QString strValue = metaData.stringValue(key);
403 if (!strValue.isEmpty())
404 setStringProperty(content, propKey, strValue);