1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "avmeta_data.h"
17 #include "avsession_log.h"
18
19 namespace OHOS::AVSession {
Marshalling(Parcel & parcel) const20 bool AVMetaData::Marshalling(Parcel& parcel) const
21 {
22 return WriteToParcel(static_cast<MessageParcel&>(parcel));
23 }
24
WriteToParcel(MessageParcel & parcel) const25 bool AVMetaData::WriteToParcel(MessageParcel& parcel) const
26 {
27 int mediaImageLength = 0;
28 std::vector<uint8_t> mediaImageBuffer;
29 std::shared_ptr<AVSessionPixelMap> mediaPixelMap = GetMediaImage();
30 if (mediaPixelMap != nullptr) {
31 mediaImageBuffer = mediaPixelMap->GetInnerImgBuffer();
32 mediaImageLength = static_cast<int>(mediaImageBuffer.size());
33 SetMediaLength(mediaImageLength);
34 }
35
36 int avQueueImageLength = 0;
37 std::vector<uint8_t> avQueueImageBuffer;
38 std::shared_ptr<AVSessionPixelMap> avQueuePixelMap = GetAVQueueImage();
39 if (avQueuePixelMap != nullptr) {
40 avQueueImageBuffer = avQueuePixelMap->GetInnerImgBuffer();
41 avQueueImageLength = static_cast<int>(avQueueImageBuffer.size());
42 SetAVQueueLength(avQueueImageLength);
43 }
44 int32_t twoImageLength = mediaImageLength + avQueueImageLength;
45 CHECK_AND_RETURN_RET_LOG(parcel.WriteInt32(twoImageLength), false, "write twoImageLength failed");
46 CHECK_AND_RETURN_RET_LOG(MarshallingExceptImg(parcel), false, "MarshallingExceptImg failed");
47
48 int32_t maxImageSize = 10 * 1024 *1024;
49 bool isImageValid = twoImageLength > 0 && twoImageLength <= maxImageSize;
50 CHECK_AND_RETURN_RET(isImageValid, true);
51
52 unsigned char *buffer = new (std::nothrow) unsigned char[twoImageLength];
53 CHECK_AND_RETURN_RET_LOG(buffer != nullptr, false, "new buffer failed");
54 for (int i = 0; i < mediaImageLength; i++) {
55 buffer[i] = mediaImageBuffer[i];
56 }
57
58 for (int j = mediaImageLength, k = 0; j < twoImageLength && k < avQueueImageLength; j++, k++) {
59 buffer[j] = avQueueImageBuffer[k];
60 }
61
62 bool retForWriteRawData = parcel.WriteRawData(buffer, twoImageLength);
63 SLOGD("write rawdata ret %{public}d", retForWriteRawData);
64 delete[] buffer;
65 return retForWriteRawData;
66 }
67
Unmarshalling(Parcel & in)68 AVMetaData *AVMetaData::Unmarshalling(Parcel& in)
69 {
70 AVMetaData* metaData = new (std::nothrow) AVMetaData();
71 CHECK_AND_RETURN_RET_LOG(metaData != nullptr, nullptr, "create metaData failed");
72 int twoImageLength = 0;
73 if (!in.ReadInt32(twoImageLength)) {
74 SLOGI("read twoImageLength failed");
75 delete metaData;
76 metaData = nullptr;
77 return nullptr;
78 }
79 if (metaData->UnmarshallingExceptImg(static_cast<MessageParcel&>(in))) {
80 SLOGI("UnmarshallingExceptImg failed");
81 delete metaData;
82 metaData = nullptr;
83 return nullptr;
84 }
85 int32_t maxImageSize = 10 * 1024 *1024;
86 bool isImageValid = twoImageLength > 0 && twoImageLength <= maxImageSize;
87 CHECK_AND_RETURN_RET(isImageValid, metaData);
88 if (!metaData->ReadFromParcel(static_cast<MessageParcel&>(in), twoImageLength)) {
89 SLOGI("ReadFromParcel failed");
90 delete metaData;
91 metaData = nullptr;
92 return nullptr;
93 }
94 return metaData;
95 }
96
ReadFromParcel(MessageParcel & in,int32_t twoImageLength)97 bool AVMetaData::ReadFromParcel(MessageParcel& in, int32_t twoImageLength)
98 {
99 const char *buffer = nullptr;
100 buffer = reinterpret_cast<const char *>(in.ReadRawData(twoImageLength));
101 int mediaImageLength = GetMediaLength();
102 CHECK_AND_RETURN_RET_LOG(
103 buffer != nullptr && mediaImageLength >= 0 && mediaImageLength <= twoImageLength,
104 false, "readRawData failed");
105 std::shared_ptr<AVSessionPixelMap> mediaPixelMap = std::make_shared<AVSessionPixelMap>();
106 std::vector<uint8_t> mediaImageBuffer;
107 for (int i = 0; i < mediaImageLength; i++) {
108 mediaImageBuffer.push_back((uint8_t)buffer[i]);
109 }
110 mediaPixelMap->SetInnerImgBuffer(mediaImageBuffer);
111 SetMediaImage(mediaPixelMap);
112
113 CHECK_AND_RETURN_RET_LOG(twoImageLength > mediaImageLength, true,
114 "twoImageLength <= mediaImageLength");
115 std::shared_ptr<AVSessionPixelMap> avQueuePixelMap = std::make_shared<AVSessionPixelMap>();
116 std::vector<uint8_t> avQueueImageBuffer;
117 for (int j = mediaImageLength; j < twoImageLength; j++) {
118 avQueueImageBuffer.push_back((uint8_t)buffer[j]);
119 }
120 avQueuePixelMap->SetInnerImgBuffer(avQueueImageBuffer);
121 SetAVQueueImage(avQueuePixelMap);
122 return true;
123 }
124
MarshallingExceptImg(MessageParcel & data) const125 bool AVMetaData::MarshallingExceptImg(MessageParcel& data) const
126 {
127 bool ret = data.WriteString(metaMask_.to_string()) &&
128 data.WriteString(assetId_) &&
129 data.WriteString(title_) &&
130 data.WriteString(artist_) &&
131 data.WriteString(author_) &&
132 data.WriteString(avQueueName_) &&
133 data.WriteString(avQueueId_) &&
134 data.WriteString(avQueueImageUri_) &&
135 data.WriteString(album_) &&
136 data.WriteString(writer_) &&
137 data.WriteString(composer_) &&
138 data.WriteInt64(duration_) &&
139 data.WriteString(mediaImageUri_) &&
140 data.WriteDouble(publishDate_) &&
141 data.WriteString(subTitle_) &&
142 data.WriteString(description_) &&
143 data.WriteString(lyric_) &&
144 data.WriteString(singleLyricText_) &&
145 data.WriteString(previousAssetId_) &&
146 data.WriteString(nextAssetId_) &&
147 data.WriteInt32(skipIntervals_) &&
148 data.WriteInt32(filter_) &&
149 data.WriteInt32(mediaLength_) &&
150 data.WriteInt32(avQueueLength_) &&
151 data.WriteInt32(displayTags_) &&
152 data.WriteParcelable(bundleIcon_.get());
153 WriteDrmSchemes(data);
154 SLOGD("MarshallingExceptImg without small img ret %{public}d", static_cast<int>(ret));
155 return ret;
156 }
157
UnmarshallingExceptImg(MessageParcel & data)158 bool AVMetaData::UnmarshallingExceptImg(MessageParcel& data)
159 {
160 std::string mask;
161 data.ReadString(mask);
162 int32_t maskSize = static_cast<int32_t>(mask.size());
163 if (maskSize <= 0 || maskSize > META_KEY_MAX) {
164 SLOGE("get err mask, return");
165 return false;
166 }
167 SLOGD("get mask with %{public}s", mask.c_str());
168 for (int32_t i = 0; i < maskSize; ++i) {
169 if (mask[i] == '1') {
170 metaMask_.flip(maskSize - i - 1);
171 }
172 }
173
174 bool ret = !data.ReadString(assetId_) ||
175 !data.ReadString(title_) ||
176 !data.ReadString(artist_) ||
177 !data.ReadString(author_) ||
178 !data.ReadString(avQueueName_) ||
179 !data.ReadString(avQueueId_) ||
180 !data.ReadString(avQueueImageUri_) ||
181 !data.ReadString(album_) ||
182 !data.ReadString(writer_) ||
183 !data.ReadString(composer_) ||
184 !data.ReadInt64(duration_) ||
185 !data.ReadString(mediaImageUri_) ||
186 !data.ReadDouble(publishDate_) ||
187 !data.ReadString(subTitle_) ||
188 !data.ReadString(description_) ||
189 !data.ReadString(lyric_) ||
190 !data.ReadString(singleLyricText_) ||
191 !data.ReadString(previousAssetId_) ||
192 !data.ReadString(nextAssetId_) ||
193 !data.ReadInt32(skipIntervals_) ||
194 !data.ReadInt32(filter_) ||
195 !data.ReadInt32(mediaLength_) ||
196 !data.ReadInt32(avQueueLength_) ||
197 !data.ReadInt32(displayTags_);
198 bundleIcon_ = std::shared_ptr<AVSessionPixelMap>(data.ReadParcelable<AVSessionPixelMap>());
199 CHECK_AND_RETURN_RET_LOG(!metaMask_.test(META_KEY_BUNDLE_ICON) || bundleIcon_ != nullptr,
200 false, "read bundle icon failed");
201 ret = ret || !ReadDrmSchemes(data);
202 SLOGD("UnmarshallingExceptImg with drm but no small img ret %{public}d", static_cast<int>(ret));
203 return ret;
204 }
205
WriteDrmSchemes(Parcel & parcel) const206 bool AVMetaData::WriteDrmSchemes(Parcel& parcel) const
207 {
208 CHECK_AND_RETURN_RET_LOG(parcel.WriteInt32(drmSchemes_.size()), false,
209 "write drmSchemes size failed");
210 for (auto drmScheme : drmSchemes_) {
211 CHECK_AND_RETURN_RET_LOG(parcel.WriteString(drmScheme), false, "write drmScheme failed");
212 }
213 return true;
214 }
215
WriteDrmSchemes(MessageParcel & parcel)216 bool AVMetaData::WriteDrmSchemes(MessageParcel& parcel)
217 {
218 CHECK_AND_RETURN_RET_LOG(parcel.WriteInt32(drmSchemes_.size()), false,
219 "write drmSchemes size failed");
220 for (auto drmScheme : drmSchemes_) {
221 CHECK_AND_RETURN_RET_LOG(parcel.WriteString(drmScheme), false, "write drmScheme failed");
222 }
223 return true;
224 }
225
ReadDrmSchemes(Parcel & parcel,AVMetaData * metaData)226 bool AVMetaData::ReadDrmSchemes(Parcel& parcel, AVMetaData* metaData)
227 {
228 int32_t drmSchemesLen = 0;
229 CHECK_AND_RETURN_RET_LOG(parcel.ReadInt32(drmSchemesLen), false, "read drmSchemesLen failed");
230 std::vector<std::string> drmSchemes;
231 int32_t maxDrmSchemesLen = 10;
232 CHECK_AND_RETURN_RET_LOG((drmSchemesLen >= 0) &&
233 (drmSchemesLen <= maxDrmSchemesLen), false, "drmSchemesLen is illegal");
234 for (int i = 0; i < drmSchemesLen; i++) {
235 std::string drmScheme;
236 CHECK_AND_RETURN_RET_LOG(parcel.ReadString(drmScheme), false, "read drmScheme failed");
237 drmSchemes.emplace_back(drmScheme);
238 }
239 metaData->drmSchemes_ = drmSchemes;
240 return true;
241 }
242
ReadDrmSchemes(MessageParcel & parcel)243 bool AVMetaData::ReadDrmSchemes(MessageParcel& parcel)
244 {
245 int32_t drmSchemesLen = 0;
246 CHECK_AND_RETURN_RET_LOG(parcel.ReadInt32(drmSchemesLen), false, "read drmSchemesLen failed");
247 std::vector<std::string> drmSchemes;
248 int32_t maxDrmSchemesLen = 10;
249 CHECK_AND_RETURN_RET_LOG((drmSchemesLen >= 0) &&
250 (drmSchemesLen <= maxDrmSchemesLen), false, "drmSchemesLen is illegal");
251 for (int i = 0; i < drmSchemesLen; i++) {
252 std::string drmScheme;
253 CHECK_AND_RETURN_RET_LOG(parcel.ReadString(drmScheme), false, "read drmScheme failed");
254 drmSchemes.emplace_back(drmScheme);
255 }
256 drmSchemes_ = drmSchemes;
257 return true;
258 }
259
SetAssetId(const std::string & assetId)260 void AVMetaData::SetAssetId(const std::string& assetId)
261 {
262 assetId_ = assetId;
263 metaMask_.set(META_KEY_ASSET_ID);
264 }
265
GetAssetId() const266 std::string AVMetaData::GetAssetId() const
267 {
268 return assetId_;
269 }
270
SetTitle(const std::string & title)271 void AVMetaData::SetTitle(const std::string& title)
272 {
273 title_ = title;
274 metaMask_.set(META_KEY_TITLE);
275 }
276
GetTitle() const277 std::string AVMetaData::GetTitle() const
278 {
279 return title_;
280 }
281
SetArtist(const std::string & artist)282 void AVMetaData::SetArtist(const std::string& artist)
283 {
284 artist_ = artist;
285 metaMask_.set(META_KEY_ARTIST);
286 }
287
GetArtist() const288 std::string AVMetaData::GetArtist() const
289 {
290 return artist_;
291 }
292
SetAuthor(const std::string & author)293 void AVMetaData::SetAuthor(const std::string& author)
294 {
295 author_ = author;
296 metaMask_.set(META_KEY_AUTHOR);
297 }
298
GetAuthor() const299 std::string AVMetaData::GetAuthor() const
300 {
301 return author_;
302 }
303
SetAVQueueName(const std::string & avQueueName)304 void AVMetaData::SetAVQueueName(const std::string& avQueueName)
305 {
306 avQueueName_ = avQueueName;
307 metaMask_.set(META_KEY_AVQUEUE_NAME);
308 }
309
GetAVQueueName() const310 std::string AVMetaData::GetAVQueueName() const
311 {
312 return avQueueName_;
313 }
314
SetAVQueueId(const std::string & avQueueId)315 void AVMetaData::SetAVQueueId(const std::string& avQueueId)
316 {
317 avQueueId_ = avQueueId;
318 metaMask_.set(META_KEY_AVQUEUE_ID);
319 }
320
GetAVQueueId() const321 std::string AVMetaData::GetAVQueueId() const
322 {
323 return avQueueId_;
324 }
325
SetAVQueueImage(const std::shared_ptr<AVSessionPixelMap> & avQueueImage)326 void AVMetaData::SetAVQueueImage(const std::shared_ptr<AVSessionPixelMap>& avQueueImage)
327 {
328 avQueueImage_ = avQueueImage;
329 metaMask_.set(META_KEY_AVQUEUE_IMAGE);
330 }
331
GetAVQueueImage() const332 std::shared_ptr<AVSessionPixelMap> AVMetaData::GetAVQueueImage() const
333 {
334 return avQueueImage_;
335 }
336
SetBundleIcon(const std::shared_ptr<AVSessionPixelMap> & bundleIcon)337 void AVMetaData::SetBundleIcon(const std::shared_ptr<AVSessionPixelMap>& bundleIcon)
338 {
339 bundleIcon_ = bundleIcon;
340 metaMask_.set(META_KEY_BUNDLE_ICON);
341 }
342
GetBundleIcon() const343 std::shared_ptr<AVSessionPixelMap> AVMetaData::GetBundleIcon() const
344 {
345 return bundleIcon_;
346 }
347
SetAVQueueImageUri(const std::string & avQueueImageUri)348 void AVMetaData::SetAVQueueImageUri(const std::string& avQueueImageUri)
349 {
350 avQueueImageUri_ = avQueueImageUri;
351 metaMask_.set(META_KEY_AVQUEUE_IMAGE_URI);
352 }
353
GetAVQueueImageUri() const354 std::string AVMetaData::GetAVQueueImageUri() const
355 {
356 return avQueueImageUri_;
357 }
358
SetAlbum(const std::string & album)359 void AVMetaData::SetAlbum(const std::string& album)
360 {
361 album_ = album;
362 metaMask_.set(META_KEY_ALBUM);
363 }
364
GetAlbum() const365 std::string AVMetaData::GetAlbum() const
366 {
367 return album_;
368 }
369
SetWriter(const std::string & writer)370 void AVMetaData::SetWriter(const std::string& writer)
371 {
372 writer_ = writer;
373 metaMask_.set(META_KEY_WRITER);
374 }
375
GetWriter() const376 std::string AVMetaData::GetWriter() const
377 {
378 return writer_;
379 }
380
SetComposer(const std::string & composer)381 void AVMetaData::SetComposer(const std::string& composer)
382 {
383 composer_ = composer;
384 metaMask_.set(META_KEY_COMPOSER);
385 }
386
GetComposer() const387 std::string AVMetaData::GetComposer() const
388 {
389 return composer_;
390 }
391
SetDuration(int64_t duration)392 void AVMetaData::SetDuration(int64_t duration)
393 {
394 if (duration < AVMetaData::DURATION_ALWAYS_PLAY) {
395 SLOGW("invalid duration");
396 }
397 duration_ = duration;
398 metaMask_.set(META_KEY_DURATION);
399 }
400
GetDuration() const401 int64_t AVMetaData::GetDuration() const
402 {
403 return duration_;
404 }
405
SetMediaImage(const std::shared_ptr<AVSessionPixelMap> & mediaImage)406 void AVMetaData::SetMediaImage(const std::shared_ptr<AVSessionPixelMap>& mediaImage)
407 {
408 mediaImage_ = mediaImage;
409 metaMask_.set(META_KEY_MEDIA_IMAGE);
410 }
411
GetMediaImage() const412 std::shared_ptr<AVSessionPixelMap> AVMetaData::GetMediaImage() const
413 {
414 return mediaImage_;
415 }
416
SetMediaImageUri(const std::string & mediaImageUri)417 void AVMetaData::SetMediaImageUri(const std::string& mediaImageUri)
418 {
419 mediaImageUri_ = mediaImageUri;
420 metaMask_.set(META_KEY_MEDIA_IMAGE_URI);
421 }
422
GetMediaImageUri() const423 std::string AVMetaData::GetMediaImageUri() const
424 {
425 return mediaImageUri_;
426 }
427
SetPublishDate(double date)428 void AVMetaData::SetPublishDate(double date)
429 {
430 if (date < 0) {
431 SLOGW("invalid publish date");
432 }
433 publishDate_ = date;
434 metaMask_.set(META_KEY_PUBLISH_DATE);
435 }
436
GetPublishDate() const437 double AVMetaData::GetPublishDate() const
438 {
439 return publishDate_;
440 }
441
SetSubTitle(const std::string & subTitle)442 void AVMetaData::SetSubTitle(const std::string& subTitle)
443 {
444 subTitle_ = subTitle;
445 metaMask_.set(META_KEY_SUBTITLE);
446 }
447
GetSubTitle() const448 std::string AVMetaData::GetSubTitle() const
449 {
450 return subTitle_;
451 }
452
SetDescription(const std::string & description)453 void AVMetaData::SetDescription(const std::string& description)
454 {
455 description_ = description;
456 metaMask_.set(META_KEY_DESCRIPTION);
457 }
458
GetDescription() const459 std::string AVMetaData::GetDescription() const
460 {
461 return description_;
462 }
463
SetLyric(const std::string & lyric)464 void AVMetaData::SetLyric(const std::string& lyric)
465 {
466 lyric_ = lyric;
467 metaMask_.set(META_KEY_LYRIC);
468 }
469
GetLyric() const470 std::string AVMetaData::GetLyric() const
471 {
472 return lyric_;
473 }
474
SetSingleLyricText(const std::string & singleLyricText)475 void AVMetaData::SetSingleLyricText(const std::string& singleLyricText)
476 {
477 singleLyricText_ = singleLyricText;
478 metaMask_.set(META_KEY_SINGLE_LYRIC_TEXT);
479 }
480
GetSingleLyricText() const481 std::string AVMetaData::GetSingleLyricText() const
482 {
483 return singleLyricText_;
484 }
485
SetPreviousAssetId(const std::string & assetId)486 void AVMetaData::SetPreviousAssetId(const std::string& assetId)
487 {
488 previousAssetId_ = assetId;
489 metaMask_.set(META_KEY_PREVIOUS_ASSET_ID);
490 }
491
GetPreviousAssetId() const492 std::string AVMetaData::GetPreviousAssetId() const
493 {
494 return previousAssetId_;
495 }
496
SetNextAssetId(const std::string & assetId)497 void AVMetaData::SetNextAssetId(const std::string& assetId)
498 {
499 nextAssetId_ = assetId;
500 metaMask_.set(META_KEY_NEXT_ASSET_ID);
501 }
502
GetNextAssetId() const503 std::string AVMetaData::GetNextAssetId() const
504 {
505 return nextAssetId_;
506 }
507
SetSkipIntervals(int32_t skipIntervals)508 void AVMetaData::SetSkipIntervals(int32_t skipIntervals)
509 {
510 SLOGD("SetSkipIntervals %{public}d", static_cast<int32_t>(skipIntervals));
511 skipIntervals_ = skipIntervals;
512 metaMask_.set(META_KEY_SKIP_INTERVALS);
513 }
514
GetSkipIntervals() const515 int32_t AVMetaData::GetSkipIntervals() const
516 {
517 SLOGD("GetSkipIntervals %{public}d", static_cast<int32_t>(skipIntervals_));
518 return skipIntervals_;
519 }
520
SetFilter(int32_t filter)521 void AVMetaData::SetFilter(int32_t filter)
522 {
523 SLOGD("SetFilter %{public}d", static_cast<int32_t>(filter));
524 filter_ = filter;
525 metaMask_.set(META_KEY_FILTER);
526 }
527
GetFilter() const528 int32_t AVMetaData::GetFilter() const
529 {
530 SLOGD("GetFilter %{public}d", static_cast<int32_t>(filter_));
531 return filter_;
532 }
533
SetMediaLength(int32_t mediaLength) const534 void AVMetaData::SetMediaLength(int32_t mediaLength) const
535 {
536 mediaLength_ = mediaLength;
537 }
538
GetMediaLength() const539 int32_t AVMetaData::GetMediaLength() const
540 {
541 return mediaLength_;
542 }
543
SetAVQueueLength(int32_t avQueueLength) const544 void AVMetaData::SetAVQueueLength(int32_t avQueueLength) const
545 {
546 avQueueLength_ = avQueueLength;
547 }
548
GetAVQueueLength() const549 int32_t AVMetaData::GetAVQueueLength() const
550 {
551 return avQueueLength_;
552 }
553
SetDisplayTags(int32_t displayTags)554 void AVMetaData::SetDisplayTags(int32_t displayTags)
555 {
556 SLOGD("SetDisplayTags %{public}d", static_cast<int32_t>(displayTags));
557 displayTags_ = displayTags;
558 metaMask_.set(META_KEY_DISPLAY_TAGS);
559 }
560
GetDisplayTags() const561 int32_t AVMetaData::GetDisplayTags() const
562 {
563 SLOGD("GetDisplayTags %{public}d", static_cast<int32_t>(displayTags_));
564 return displayTags_;
565 }
566
SetDrmSchemes(std::vector<std::string> drmSchemes)567 void AVMetaData::SetDrmSchemes(std::vector<std::string> drmSchemes)
568 {
569 drmSchemes_ = drmSchemes;
570 metaMask_.set(META_KEY_DRM_SCHEMES);
571 }
572
GetDrmSchemes() const573 std::vector<std::string> AVMetaData::GetDrmSchemes() const
574 {
575 return drmSchemes_;
576 }
577
GetMetaMask() const578 AVMetaData::MetaMaskType AVMetaData::GetMetaMask() const
579 {
580 return metaMask_;
581 }
582
Reset()583 void AVMetaData::Reset()
584 {
585 metaMask_.reset();
586 assetId_ = "";
587 title_ = "";
588 artist_ = "";
589 author_ = "";
590 avQueueName_ = "";
591 avQueueId_ = "";
592 avQueueImage_ = nullptr;
593 avQueueImageUri_ = "";
594 bundleIcon_ = nullptr;
595 album_ = "";
596 writer_ = "";
597 composer_ = "";
598 duration_ = 0;
599 mediaImage_ = nullptr;
600 mediaImageUri_ = "";
601 publishDate_ = 0;
602 subTitle_ = "";
603 description_ = "";
604 lyric_ = "";
605 singleLyricText_ = "";
606 previousAssetId_ = "";
607 nextAssetId_ = "";
608 skipIntervals_ = SECONDS_15;
609 displayTags_ = 0;
610 drmSchemes_.clear();
611 }
612
ResetToBaseMeta()613 void AVMetaData::ResetToBaseMeta()
614 {
615 metaMask_.reset();
616 metaMask_.set(META_KEY_ASSET_ID);
617 metaMask_.set(META_KEY_MEDIA_IMAGE);
618 metaMask_.set(META_KEY_MEDIA_IMAGE_URI);
619 title_ = "";
620 artist_ = "";
621 author_ = "";
622 avQueueName_ = "";
623 avQueueId_ = "";
624 avQueueImage_ = nullptr;
625 avQueueImageUri_ = "";
626 bundleIcon_ = nullptr;
627 album_ = "";
628 writer_ = "";
629 composer_ = "";
630 duration_ = 0;
631 publishDate_ = 0;
632 subTitle_ = "";
633 description_ = "";
634 lyric_ = "";
635 singleLyricText_ = "";
636 previousAssetId_ = "";
637 nextAssetId_ = "";
638 skipIntervals_ = SECONDS_15;
639 displayTags_ = 0;
640 drmSchemes_.clear();
641 }
642
CopyToByMask(MetaMaskType & mask,AVMetaData & metaOut) const643 bool AVMetaData::CopyToByMask(MetaMaskType& mask, AVMetaData& metaOut) const
644 {
645 bool result = false;
646 auto intersection = metaMask_ & mask;
647 for (int i = 0; i < META_KEY_MAX; i++) {
648 if (intersection.test(i)) {
649 cloneActions[i](*this, metaOut);
650 metaOut.metaMask_.set(i);
651 result = true;
652 }
653 }
654
655 return result;
656 }
657
CopyFrom(const AVMetaData & metaIn)658 bool AVMetaData::CopyFrom(const AVMetaData& metaIn)
659 {
660 if (metaIn.assetId_.empty()) {
661 SLOGE("assetId is empty");
662 return false;
663 }
664
665 if (metaIn.assetId_ != assetId_) {
666 SLOGD("assetId not equal here");
667 *this = metaIn;
668 return true;
669 }
670
671 bool result = false;
672 for (int i = 0; i < META_KEY_MAX; i++) {
673 if (metaIn.metaMask_.test(i)) {
674 cloneActions[i](metaIn, *this);
675 metaMask_.set(i);
676 result = true;
677 }
678 }
679
680 return result;
681 }
682
EqualWithUri(const AVMetaData & metaData)683 bool AVMetaData::EqualWithUri(const AVMetaData& metaData)
684 {
685 if (metaData.mediaImage_ != nullptr) {
686 SLOGI("Current fun cannot determine whether mediaImage_ is equal,\
687 not perform subsequent judgments when mediaImage_ is not null.");
688 return false;
689 }
690
691 return (assetId_ == metaData.assetId_)
692 && (title_ == metaData.title_)
693 && (artist_ == metaData.artist_)
694 && (author_ == metaData.author_)
695 && (avQueueName_ == metaData.avQueueName_)
696 && (avQueueId_ == metaData.avQueueId_)
697 && (avQueueImageUri_ == metaData.avQueueImageUri_)
698 && (album_ == metaData.album_)
699 && (writer_ == metaData.writer_)
700 && (composer_ == metaData.composer_)
701 && (duration_ == metaData.duration_)
702 && (mediaImageUri_ == metaData.mediaImageUri_)
703 && (publishDate_ == metaData.publishDate_)
704 && (subTitle_ == metaData.subTitle_)
705 && (description_ == metaData.description_)
706 && (lyric_ == metaData.lyric_)
707 && (singleLyricText_ == metaData.singleLyricText_)
708 && (previousAssetId_ == metaData.previousAssetId_)
709 && (nextAssetId_ == metaData.nextAssetId_)
710 && (skipIntervals_ == metaData.skipIntervals_)
711 && (filter_ == metaData.filter_)
712 && (displayTags_ == metaData.displayTags_)
713 && (drmSchemes_ == metaData.drmSchemes_);
714 }
715
IsValid() const716 bool AVMetaData::IsValid() const
717 {
718 return duration_ >= AVMetaData::DURATION_ALWAYS_PLAY && publishDate_ >= 0
719 && displayTags_ <= AVMetaData::DISPLAY_TAG_ALL;
720 }
721
CloneAssetId(const AVMetaData & from,AVMetaData & to)722 void AVMetaData::CloneAssetId(const AVMetaData& from, AVMetaData& to)
723 {
724 to.assetId_ = from.assetId_;
725 }
726
CloneTitle(const AVMetaData & from,AVMetaData & to)727 void AVMetaData::CloneTitle(const AVMetaData& from, AVMetaData& to)
728 {
729 to.title_ = from.title_;
730 }
731
CloneArtist(const AVMetaData & from,AVMetaData & to)732 void AVMetaData::CloneArtist(const AVMetaData& from, AVMetaData& to)
733 {
734 to.artist_ = from.artist_;
735 }
736
CloneAuthor(const AVMetaData & from,AVMetaData & to)737 void AVMetaData::CloneAuthor(const AVMetaData& from, AVMetaData& to)
738 {
739 to.author_ = from.author_;
740 }
741
CloneAVQueueName(const AVMetaData & from,AVMetaData & to)742 void AVMetaData::CloneAVQueueName(const AVMetaData& from, AVMetaData& to)
743 {
744 to.avQueueName_ = from.avQueueName_;
745 }
746
CloneAVQueueId(const AVMetaData & from,AVMetaData & to)747 void AVMetaData::CloneAVQueueId(const AVMetaData& from, AVMetaData& to)
748 {
749 to.avQueueId_ = from.avQueueId_;
750 }
751
CloneAVQueueImage(const AVMetaData & from,AVMetaData & to)752 void AVMetaData::CloneAVQueueImage(const AVMetaData& from, AVMetaData& to)
753 {
754 to.avQueueImage_ = from.avQueueImage_;
755 }
756
CloneAVQueueImageUri(const AVMetaData & from,AVMetaData & to)757 void AVMetaData::CloneAVQueueImageUri(const AVMetaData& from, AVMetaData& to)
758 {
759 to.avQueueImageUri_ = from.avQueueImageUri_;
760 }
761
CloneBundleIcon(const AVMetaData & from,AVMetaData & to)762 void AVMetaData::CloneBundleIcon(const AVMetaData& from, AVMetaData& to)
763 {
764 to.bundleIcon_ = from.bundleIcon_;
765 }
766
CloneAlbum(const AVMetaData & from,AVMetaData & to)767 void AVMetaData::CloneAlbum(const AVMetaData& from, AVMetaData& to)
768 {
769 to.album_ = from.album_;
770 }
771
CloneWriter(const AVMetaData & from,AVMetaData & to)772 void AVMetaData::CloneWriter(const AVMetaData& from, AVMetaData& to)
773 {
774 to.writer_ = from.writer_;
775 }
776
CloneComposer(const AVMetaData & from,AVMetaData & to)777 void AVMetaData::CloneComposer(const AVMetaData& from, AVMetaData& to)
778 {
779 to.composer_ = from.composer_;
780 }
781
CloneDuration(const AVMetaData & from,AVMetaData & to)782 void AVMetaData::CloneDuration(const AVMetaData& from, AVMetaData& to)
783 {
784 to.duration_ = from.duration_;
785 }
786
CloneMediaImage(const AVMetaData & from,AVMetaData & to)787 void AVMetaData::CloneMediaImage(const AVMetaData& from, AVMetaData& to)
788 {
789 to.mediaImage_ = from.mediaImage_;
790 }
791
CloneMediaImageUri(const AVMetaData & from,AVMetaData & to)792 void AVMetaData::CloneMediaImageUri(const AVMetaData& from, AVMetaData& to)
793 {
794 to.mediaImageUri_ = from.mediaImageUri_;
795 }
796
ClonePublishData(const AVMetaData & from,AVMetaData & to)797 void AVMetaData::ClonePublishData(const AVMetaData& from, AVMetaData& to)
798 {
799 to.publishDate_ = from.publishDate_;
800 }
801
CloneSubTitle(const AVMetaData & from,AVMetaData & to)802 void AVMetaData::CloneSubTitle(const AVMetaData& from, AVMetaData& to)
803 {
804 to.subTitle_ = from.subTitle_;
805 }
806
CloneDescription(const AVMetaData & from,AVMetaData & to)807 void AVMetaData::CloneDescription(const AVMetaData& from, AVMetaData& to)
808 {
809 to.description_ = from.description_;
810 }
811
CloneLyric(const AVMetaData & from,AVMetaData & to)812 void AVMetaData::CloneLyric(const AVMetaData& from, AVMetaData& to)
813 {
814 to.lyric_ = from.lyric_;
815 }
816
CloneSingleLyricText(const AVMetaData & from,AVMetaData & to)817 void AVMetaData::CloneSingleLyricText(const AVMetaData& from, AVMetaData& to)
818 {
819 to.singleLyricText_ = from.singleLyricText_;
820 }
821
ClonePreviousAssetId(const AVMetaData & from,AVMetaData & to)822 void AVMetaData::ClonePreviousAssetId(const AVMetaData& from, AVMetaData& to)
823 {
824 to.previousAssetId_ = from.previousAssetId_;
825 }
826
CloneNextAssetId(const AVMetaData & from,AVMetaData & to)827 void AVMetaData::CloneNextAssetId(const AVMetaData& from, AVMetaData& to)
828 {
829 to.nextAssetId_ = from.nextAssetId_;
830 }
831
CloneSkipIntervals(const AVMetaData & from,AVMetaData & to)832 void AVMetaData::CloneSkipIntervals(const AVMetaData& from, AVMetaData& to)
833 {
834 to.skipIntervals_ = from.skipIntervals_;
835 }
836
CloneFilter(const AVMetaData & from,AVMetaData & to)837 void AVMetaData::CloneFilter(const AVMetaData& from, AVMetaData& to)
838 {
839 to.filter_ = from.filter_;
840 }
841
CloneDisplayTags(const AVMetaData & from,AVMetaData & to)842 void AVMetaData::CloneDisplayTags(const AVMetaData& from, AVMetaData& to)
843 {
844 to.displayTags_ = from.displayTags_;
845 }
846
CloneDrmSchemes(const AVMetaData & from,AVMetaData & to)847 void AVMetaData::CloneDrmSchemes(const AVMetaData& from, AVMetaData& to)
848 {
849 to.drmSchemes_ = from.drmSchemes_;
850 }
851 } // namespace OHOS::AVSession
852