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 "napi_meta_data.h"
17 #include "avsession_log.h"
18 #include "avsession_pixel_map_adapter.h"
19 #include "napi_utils.h"
20 #include "pixel_map_napi.h"
21
22 namespace OHOS::AVSession {
23 std::map<std::string, NapiMetaData::GetterType> NapiMetaData::getterMap_ = {
24 { "assetId", GetAssetId },
25 { "title", GetTitle },
26 { "artist", GetArtist },
27 { "author", GetAuthor },
28 { "avQueueName", GetAVQueueName },
29 { "avQueueId", GetAVQueueId },
30 { "avQueueImage", GetAVQueueImage },
31 { "album", GetAlbum },
32 { "writer", GetWriter },
33 { "composer", GetComposer },
34 { "duration", GetDuration },
35 { "mediaImage", GetMediaImage },
36 { "publishDate", GetPublishDate },
37 { "subtitle", GetSubtitle },
38 { "description", GetDescription },
39 { "lyric", GetLyric },
40 { "previousAssetId", GetPreviousAssetId },
41 { "nextAssetId", GetNextAssetId },
42 { "skipIntervals", GetSkipIntervals },
43 { "filter", GetFilter },
44 { "displayTags", GetDisplayTags },
45 { "drmSchemes", GetDrmSchemes }
46 };
47
48 std::map<int32_t, NapiMetaData::SetterType> NapiMetaData::setterMap_ = {
49 { AVMetaData::META_KEY_ASSET_ID, SetAssetId },
50 { AVMetaData::META_KEY_TITLE, SetTitle },
51 { AVMetaData::META_KEY_ARTIST, SetArtist },
52 { AVMetaData::META_KEY_AUTHOR, SetAuthor },
53 { AVMetaData::META_KEY_AVQUEUE_NAME, SetAVQueueName },
54 { AVMetaData::META_KEY_AVQUEUE_ID, SetAVQueueId },
55 { AVMetaData::META_KEY_AVQUEUE_IMAGE, SetAVQueueImage },
56 { AVMetaData::META_KEY_AVQUEUE_IMAGE_URI, SetAVQueueImageUri },
57 { AVMetaData::META_KEY_ALBUM, SetAlbum },
58 { AVMetaData::META_KEY_WRITER, SetWriter },
59 { AVMetaData::META_KEY_COMPOSER, SetComposer },
60 { AVMetaData::META_KEY_DURATION, SetDuration },
61 { AVMetaData::META_KEY_MEDIA_IMAGE, SetMediaImage },
62 { AVMetaData::META_KEY_MEDIA_IMAGE_URI, SetMediaImageUri },
63 { AVMetaData::META_KEY_PUBLISH_DATE, SetPublishDate },
64 { AVMetaData::META_KEY_SUBTITLE, SetSubtitle },
65 { AVMetaData::META_KEY_DESCRIPTION, SetDescription },
66 { AVMetaData::META_KEY_LYRIC, SetLyric },
67 { AVMetaData::META_KEY_PREVIOUS_ASSET_ID, SetPreviousAssetId },
68 { AVMetaData::META_KEY_NEXT_ASSET_ID, SetNextAssetId },
69 { AVMetaData::META_KEY_SKIP_INTERVALS, SetSkipIntervals },
70 { AVMetaData::META_KEY_FILTER, SetFilter },
71 { AVMetaData::META_KEY_DISPLAY_TAGS, SetDisplayTags },
72 { AVMetaData::META_KEY_DRM_SCHEMES, SetDrmSchemes }
73 };
74
75 std::pair<std::string, int32_t> NapiMetaData::filterMap_[] = {
76 { "assetId", AVMetaData::META_KEY_ASSET_ID },
77 { "title", AVMetaData::META_KEY_TITLE },
78 { "artist", AVMetaData::META_KEY_ARTIST },
79 { "author", AVMetaData::META_KEY_AUTHOR },
80 { "avQueueName", AVMetaData::META_KEY_AVQUEUE_NAME },
81 { "avQueueId", AVMetaData::META_KEY_AVQUEUE_ID },
82 { "avQueueImage", AVMetaData::META_KEY_AVQUEUE_IMAGE },
83 { "avQueueImage", AVMetaData::META_KEY_AVQUEUE_IMAGE_URI },
84 { "album", AVMetaData::META_KEY_ALBUM },
85 { "writer", AVMetaData::META_KEY_WRITER },
86 { "composer", AVMetaData::META_KEY_COMPOSER },
87 { "duration", AVMetaData::META_KEY_DURATION },
88 { "mediaImage", AVMetaData::META_KEY_MEDIA_IMAGE },
89 { "mediaImage", AVMetaData::META_KEY_MEDIA_IMAGE_URI },
90 { "publishDate", AVMetaData::META_KEY_PUBLISH_DATE },
91 { "subtitle", AVMetaData::META_KEY_SUBTITLE },
92 { "description", AVMetaData::META_KEY_DESCRIPTION },
93 { "lyric", AVMetaData::META_KEY_LYRIC },
94 { "previousAssetId", AVMetaData::META_KEY_PREVIOUS_ASSET_ID },
95 { "nextAssetId", AVMetaData::META_KEY_NEXT_ASSET_ID },
96 { "skipIntervals", AVMetaData::META_KEY_SKIP_INTERVALS },
97 { "filter", AVMetaData::META_KEY_FILTER },
98 { "displayTags", AVMetaData::META_KEY_DISPLAY_TAGS },
99 { "drmSchemes", AVMetaData::META_KEY_DRM_SCHEMES }
100 };
101
ConvertFilter(napi_env env,napi_value filter,AVMetaData::MetaMaskType & mask)102 napi_status NapiMetaData::ConvertFilter(napi_env env, napi_value filter, AVMetaData::MetaMaskType& mask)
103 {
104 napi_valuetype type = napi_undefined;
105 auto status = napi_typeof(env, filter, &type);
106 CHECK_RETURN(status == napi_ok, "napi_typeof failed", status);
107
108 if (type == napi_string) {
109 std::string stringFilter;
110 status = NapiUtils::GetValue(env, filter, stringFilter);
111 CHECK_RETURN(status == napi_ok, "get string filter failed", status);
112 if (stringFilter != "all") {
113 SLOGE("string filter only support all") ;
114 return napi_invalid_arg;
115 }
116 mask.set();
117 return napi_ok;
118 }
119
120 uint32_t count = 0;
121 status = napi_get_array_length(env, filter, &count);
122 CHECK_RETURN(status == napi_ok, "get array length failed", status);
123 for (uint32_t i = 0; i < count; i++) {
124 napi_value value {};
125 status = napi_get_element(env, filter, i, &value);
126 CHECK_RETURN(status == napi_ok, "get element failed", status);
127 std::string metaKey;
128 status = NapiUtils::GetValue(env, value, metaKey);
129 CHECK_RETURN(status == napi_ok, "get string value failed", status);
130 for (const auto& pair : filterMap_) {
131 if (pair.first == metaKey) {
132 mask.set(pair.second);
133 }
134 }
135 }
136
137 return napi_ok;
138 }
139
GetValue(napi_env env,napi_value in,AVMetaData & out)140 napi_status NapiMetaData::GetValue(napi_env env, napi_value in, AVMetaData& out)
141 {
142 std::vector<std::string> propertyNames;
143 auto status = NapiUtils::GetPropertyNames(env, in, propertyNames);
144 CHECK_RETURN(status == napi_ok, "get property name failed", status);
145
146 for (const auto& name : propertyNames) {
147 auto it = getterMap_.find(name);
148 if (it == getterMap_.end()) {
149 SLOGE("property %{public}s is not of metadata", name.c_str());
150 return napi_invalid_arg;
151 }
152 auto getter = it->second;
153 if (getter(env, in, out) != napi_ok) {
154 SLOGE("get property %{public}s failed", name.c_str());
155 return napi_generic_failure;
156 }
157 }
158
159 return napi_ok;
160 }
161
SetValue(napi_env env,const AVMetaData & in,napi_value & out)162 napi_status NapiMetaData::SetValue(napi_env env, const AVMetaData& in, napi_value& out)
163 {
164 napi_status status = napi_create_object(env, &out);
165 CHECK_RETURN((status == napi_ok) && (out != nullptr), "create object failed", status);
166
167 auto mask = in.GetMetaMask();
168 if (mask.none()) {
169 SLOGI("undefined meta");
170 return SetUndefinedMeta(env, out);
171 }
172
173 for (int i = 0; i < AVMetaData::META_KEY_MAX; ++i) {
174 if (!mask.test(i)) {
175 continue;
176 }
177 auto setter = setterMap_[i];
178 if (setter(env, in, out) != napi_ok) {
179 SLOGE("set property %{public}d failed", i);
180 return napi_generic_failure;
181 }
182 }
183
184 return napi_ok;
185 }
186
SetUndefinedMeta(napi_env env,napi_value & meta)187 napi_status NapiMetaData::SetUndefinedMeta(napi_env env, napi_value& meta)
188 {
189 auto status = napi_set_named_property(env, meta, "assetId", NapiUtils::GetUndefinedValue(env));
190 CHECK_RETURN(status == napi_ok, "set assetId to undefined failed", status);
191 return napi_ok;
192 }
193
GetAssetId(napi_env env,napi_value in,AVMetaData & out)194 napi_status NapiMetaData::GetAssetId(napi_env env, napi_value in, AVMetaData& out)
195 {
196 std::string property;
197 auto status = NapiUtils::GetNamedProperty(env, in, "assetId", property);
198 CHECK_RETURN(status == napi_ok, "get property failed", status);
199 out.SetAssetId(property);
200 return status;
201 }
202
SetAssetId(napi_env env,const AVMetaData & in,napi_value & out)203 napi_status NapiMetaData::SetAssetId(napi_env env, const AVMetaData& in, napi_value& out)
204 {
205 napi_value property {};
206 auto status = NapiUtils::SetValue(env, in.GetAssetId(), property);
207 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
208 status = napi_set_named_property(env, out, "assetId", property);
209 CHECK_RETURN(status == napi_ok, "set property failed", status);
210 return status;
211 }
212
GetTitle(napi_env env,napi_value in,AVMetaData & out)213 napi_status NapiMetaData::GetTitle(napi_env env, napi_value in, AVMetaData& out)
214 {
215 std::string property;
216 auto status = NapiUtils::GetNamedProperty(env, in, "title", property);
217 CHECK_RETURN(status == napi_ok, "get property failed", status);
218 out.SetTitle(property);
219 return status;
220 }
221
SetTitle(napi_env env,const AVMetaData & in,napi_value & out)222 napi_status NapiMetaData::SetTitle(napi_env env, const AVMetaData& in, napi_value& out)
223 {
224 napi_value property {};
225 auto status = NapiUtils::SetValue(env, in.GetTitle(), property);
226 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
227 status = napi_set_named_property(env, out, "title", property);
228 CHECK_RETURN(status == napi_ok, "set property failed", status);
229 return status;
230 }
231
GetArtist(napi_env env,napi_value in,AVMetaData & out)232 napi_status NapiMetaData::GetArtist(napi_env env, napi_value in, AVMetaData& out)
233 {
234 std::string property;
235 auto status = NapiUtils::GetNamedProperty(env, in, "artist", property);
236 CHECK_RETURN(status == napi_ok, "get property failed", status);
237 out.SetArtist(property);
238 return status;
239 }
240
SetArtist(napi_env env,const AVMetaData & in,napi_value & out)241 napi_status NapiMetaData::SetArtist(napi_env env, const AVMetaData& in, napi_value& out)
242 {
243 napi_value property {};
244 auto status = NapiUtils::SetValue(env, in.GetArtist(), property);
245 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
246 status = napi_set_named_property(env, out, "artist", property);
247 CHECK_RETURN(status == napi_ok, "set property failed", status);
248 return status;
249 }
250
GetAuthor(napi_env env,napi_value in,AVMetaData & out)251 napi_status NapiMetaData::GetAuthor(napi_env env, napi_value in, AVMetaData& out)
252 {
253 std::string property;
254 auto status = NapiUtils::GetNamedProperty(env, in, "author", property);
255 CHECK_RETURN(status == napi_ok, "get property failed", status);
256 out.SetAuthor(property);
257 return status;
258 }
259
SetAuthor(napi_env env,const AVMetaData & in,napi_value & out)260 napi_status NapiMetaData::SetAuthor(napi_env env, const AVMetaData& in, napi_value& out)
261 {
262 napi_value property {};
263 auto status = NapiUtils::SetValue(env, in.GetAuthor(), property);
264 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
265 status = napi_set_named_property(env, out, "author", property);
266 CHECK_RETURN(status == napi_ok, "set property failed", status);
267 return status;
268 }
269
GetAVQueueName(napi_env env,napi_value in,AVMetaData & out)270 napi_status NapiMetaData::GetAVQueueName(napi_env env, napi_value in, AVMetaData& out)
271 {
272 std::string property;
273 auto status = NapiUtils::GetNamedProperty(env, in, "avQueueName", property);
274 CHECK_RETURN(status == napi_ok, "get property failed", status);
275 out.SetAVQueueName(property);
276 return status;
277 }
278
SetAVQueueName(napi_env env,const AVMetaData & in,napi_value & out)279 napi_status NapiMetaData::SetAVQueueName(napi_env env, const AVMetaData& in, napi_value& out)
280 {
281 napi_value property {};
282 auto status = NapiUtils::SetValue(env, in.GetAVQueueName(), property);
283 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
284 status = napi_set_named_property(env, out, "avQueueName", property);
285 CHECK_RETURN(status == napi_ok, "set property failed", status);
286 return status;
287 }
288
GetAVQueueId(napi_env env,napi_value in,AVMetaData & out)289 napi_status NapiMetaData::GetAVQueueId(napi_env env, napi_value in, AVMetaData& out)
290 {
291 std::string property;
292 auto status = NapiUtils::GetNamedProperty(env, in, "avQueueId", property);
293 CHECK_RETURN(status == napi_ok, "get property failed", status);
294 out.SetAVQueueId(property);
295 return status;
296 }
297
SetAVQueueId(napi_env env,const AVMetaData & in,napi_value & out)298 napi_status NapiMetaData::SetAVQueueId(napi_env env, const AVMetaData& in, napi_value& out)
299 {
300 napi_value property {};
301 auto status = NapiUtils::SetValue(env, in.GetAVQueueId(), property);
302 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
303 status = napi_set_named_property(env, out, "avQueueId", property);
304 CHECK_RETURN(status == napi_ok, "set property failed", status);
305 return status;
306 }
307
308
GetAVQueueImage(napi_env env,napi_value in,AVMetaData & out)309 napi_status NapiMetaData::GetAVQueueImage(napi_env env, napi_value in, AVMetaData& out)
310 {
311 napi_value property {};
312 auto status = napi_get_named_property(env, in, "avQueueImage", &property);
313 CHECK_RETURN((status == napi_ok) && (property != nullptr), "get property failed", status);
314 napi_valuetype type = napi_undefined;
315 status = napi_typeof(env, property, &type);
316 CHECK_RETURN(status == napi_ok, "get napi_value type failed", status);
317 if (type == napi_string) {
318 std::string uri;
319 status = NapiUtils::GetValue(env, property, uri);
320 CHECK_RETURN(status == napi_ok, "get property failed", status);
321 out.SetAVQueueImageUri(uri);
322 } else if (type == napi_object) {
323 auto pixelMap = Media::PixelMapNapi::GetPixelMap(env, property);
324 if (pixelMap == nullptr) {
325 SLOGE("unwrap avqueue pixelMap failed");
326 return napi_invalid_arg;
327 }
328 out.SetAVQueueImage(AVSessionPixelMapAdapter::ConvertToInner(pixelMap));
329 SLOGD(" napi get avqueueimage");
330 } else {
331 SLOGE("avqueueimage property value type invalid");
332 return napi_invalid_arg;
333 }
334
335 return status;
336 }
337
SetAVQueueImage(napi_env env,const AVMetaData & in,napi_value & out)338 napi_status NapiMetaData::SetAVQueueImage(napi_env env, const AVMetaData& in, napi_value& out)
339 {
340 auto pixelMap = in.GetAVQueueImage();
341 if (pixelMap == nullptr) {
342 SLOGI("avqueue image is none");
343 return napi_ok;
344 }
345
346 napi_value property = Media::PixelMapNapi::CreatePixelMap(env,
347 AVSessionPixelMapAdapter::ConvertFromInner(pixelMap));
348 auto status = napi_set_named_property(env, out, "avQueueImage", property);
349 CHECK_RETURN(status == napi_ok, "set property failed", status);
350 return status;
351 }
352
SetAVQueueImageUri(napi_env env,const AVMetaData & in,napi_value & out)353 napi_status NapiMetaData::SetAVQueueImageUri(napi_env env, const AVMetaData& in, napi_value& out)
354 {
355 auto uri = in.GetAVQueueImageUri();
356 if (uri.empty()) {
357 SLOGI("avqueue image uri empty");
358 return napi_ok;
359 }
360
361 napi_value property {};
362 auto status = NapiUtils::SetValue(env, uri, property);
363 CHECK_RETURN(status == napi_ok, "create property failed", status);
364 status = napi_set_named_property(env, out, "avQueueImage", property);
365 CHECK_RETURN(status == napi_ok, "set property failed", status);
366 return status;
367 }
368
GetAlbum(napi_env env,napi_value in,AVMetaData & out)369 napi_status NapiMetaData::GetAlbum(napi_env env, napi_value in, AVMetaData& out)
370 {
371 std::string property;
372 auto status = NapiUtils::GetNamedProperty(env, in, "album", property);
373 CHECK_RETURN(status == napi_ok, "get property failed", status);
374 out.SetAlbum(property);
375 return status;
376 }
377
SetAlbum(napi_env env,const AVMetaData & in,napi_value & out)378 napi_status NapiMetaData::SetAlbum(napi_env env, const AVMetaData& in, napi_value& out)
379 {
380 napi_value property {};
381 auto status = NapiUtils::SetValue(env, in.GetAlbum(), property);
382 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
383 status = napi_set_named_property(env, out, "album", property);
384 CHECK_RETURN(status == napi_ok, "set property failed", status);
385 return status;
386 }
387
GetWriter(napi_env env,napi_value in,AVMetaData & out)388 napi_status NapiMetaData::GetWriter(napi_env env, napi_value in, AVMetaData& out)
389 {
390 std::string property;
391 auto status = NapiUtils::GetNamedProperty(env, in, "writer", property);
392 CHECK_RETURN(status == napi_ok, "get property failed", status);
393 out.SetWriter(property);
394 return status;
395 }
396
SetWriter(napi_env env,const AVMetaData & in,napi_value & out)397 napi_status NapiMetaData::SetWriter(napi_env env, const AVMetaData& in, napi_value& out)
398 {
399 napi_value property {};
400 auto status = NapiUtils::SetValue(env, in.GetWriter(), property);
401 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
402 status = napi_set_named_property(env, out, "writer", property);
403 CHECK_RETURN(status == napi_ok, "set property failed", status);
404 return status;
405 }
406
GetComposer(napi_env env,napi_value in,AVMetaData & out)407 napi_status NapiMetaData::GetComposer(napi_env env, napi_value in, AVMetaData& out)
408 {
409 std::string property;
410 auto status = NapiUtils::GetNamedProperty(env, in, "composer", property);
411 CHECK_RETURN(status == napi_ok, "get property failed", status);
412 out.SetComposer(property);
413 return status;
414 }
415
SetComposer(napi_env env,const AVMetaData & in,napi_value & out)416 napi_status NapiMetaData::SetComposer(napi_env env, const AVMetaData& in, napi_value& out)
417 {
418 napi_value property {};
419 auto status = NapiUtils::SetValue(env, in.GetComposer(), property);
420 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
421 status = napi_set_named_property(env, out, "composer", property);
422 CHECK_RETURN(status == napi_ok, "set property failed", status);
423 return status;
424 }
425
GetDuration(napi_env env,napi_value in,AVMetaData & out)426 napi_status NapiMetaData::GetDuration(napi_env env, napi_value in, AVMetaData& out)
427 {
428 int64_t property;
429 auto status = NapiUtils::GetNamedProperty(env, in, "duration", property);
430 CHECK_RETURN(status == napi_ok, "get property failed", status);
431 out.SetDuration(property);
432 return status;
433 }
434
SetDuration(napi_env env,const AVMetaData & in,napi_value & out)435 napi_status NapiMetaData::SetDuration(napi_env env, const AVMetaData& in, napi_value& out)
436 {
437 napi_value property {};
438 auto status = NapiUtils::SetValue(env, in.GetDuration(), property);
439 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
440 status = napi_set_named_property(env, out, "duration", property);
441 CHECK_RETURN(status == napi_ok, "set property failed", status);
442 return status;
443 }
444
GetMediaImage(napi_env env,napi_value in,AVMetaData & out)445 napi_status NapiMetaData::GetMediaImage(napi_env env, napi_value in, AVMetaData& out)
446 {
447 napi_value property {};
448 auto status = napi_get_named_property(env, in, "mediaImage", &property);
449 CHECK_RETURN((status == napi_ok) && (property != nullptr), "get property failed", status);
450 napi_valuetype type = napi_undefined;
451 status = napi_typeof(env, property, &type);
452 CHECK_RETURN(status == napi_ok, "get napi_value type failed", status);
453 if (type == napi_string) {
454 std::string uri;
455 status = NapiUtils::GetValue(env, property, uri);
456 CHECK_RETURN(status == napi_ok, "get property failed", status);
457 out.SetMediaImageUri(uri);
458 } else if (type == napi_object) {
459 auto pixelMap = Media::PixelMapNapi::GetPixelMap(env, property);
460 if (pixelMap == nullptr) {
461 SLOGE("unwrap failed");
462 return napi_invalid_arg;
463 }
464 SLOGI("set mediaImage without small size");
465 out.SetMediaImage(AVSessionPixelMapAdapter::ConvertToInner(pixelMap));
466 } else {
467 SLOGE("mediaImage property value type invalid");
468 return napi_invalid_arg;
469 }
470
471 return status;
472 }
473
SetMediaImage(napi_env env,const AVMetaData & in,napi_value & out)474 napi_status NapiMetaData::SetMediaImage(napi_env env, const AVMetaData& in, napi_value& out)
475 {
476 auto pixelMap = in.GetMediaImage();
477 if (pixelMap == nullptr) {
478 SLOGI("media image is none");
479 return napi_ok;
480 }
481
482 napi_value property = Media::PixelMapNapi::CreatePixelMap(env,
483 AVSessionPixelMapAdapter::ConvertFromInner(pixelMap));
484 auto status = napi_set_named_property(env, out, "mediaImage", property);
485 CHECK_RETURN(status == napi_ok, "set property failed", status);
486 return status;
487 }
488
SetMediaImageUri(napi_env env,const AVMetaData & in,napi_value & out)489 napi_status NapiMetaData::SetMediaImageUri(napi_env env, const AVMetaData& in, napi_value& out)
490 {
491 auto uri = in.GetMediaImageUri();
492 if (uri.empty()) {
493 SLOGI("media image uri empty");
494 return napi_ok;
495 }
496
497 napi_value property {};
498 auto status = NapiUtils::SetValue(env, uri, property);
499 CHECK_RETURN(status == napi_ok, "create property failed", status);
500 status = napi_set_named_property(env, out, "mediaImage", property);
501 CHECK_RETURN(status == napi_ok, "set property failed", status);
502 return status;
503 }
504
GetPublishDate(napi_env env,napi_value in,AVMetaData & out)505 napi_status NapiMetaData::GetPublishDate(napi_env env, napi_value in, AVMetaData& out)
506 {
507 napi_value property;
508 auto status = napi_get_named_property(env, in, "publishDate", &property);
509 CHECK_RETURN(status == napi_ok, "get property failed", status);
510 double date {};
511 status = NapiUtils::GetDateValue(env, property, date);
512 CHECK_RETURN(status == napi_ok, "get date value failed", status);
513 out.SetPublishDate(date);
514 return status;
515 }
516
SetPublishDate(napi_env env,const AVMetaData & in,napi_value & out)517 napi_status NapiMetaData::SetPublishDate(napi_env env, const AVMetaData& in, napi_value& out)
518 {
519 napi_value property {};
520 auto status = NapiUtils::SetDateValue(env, in.GetPublishDate(), property);
521 CHECK_RETURN(status == napi_ok, "create date object failed", status);
522 status = napi_set_named_property(env, out, "publishDate", property);
523 CHECK_RETURN(status == napi_ok, "set property failed", status);
524 return status;
525 }
526
GetSubtitle(napi_env env,napi_value in,AVMetaData & out)527 napi_status NapiMetaData::GetSubtitle(napi_env env, napi_value in, AVMetaData& out)
528 {
529 std::string property;
530 auto status = NapiUtils::GetNamedProperty(env, in, "subtitle", property);
531 CHECK_RETURN(status == napi_ok, "get property failed", status);
532 out.SetSubTitle(property);
533 return status;
534 }
535
SetSubtitle(napi_env env,const AVMetaData & in,napi_value & out)536 napi_status NapiMetaData::SetSubtitle(napi_env env, const AVMetaData& in, napi_value& out)
537 {
538 napi_value property {};
539 auto status = NapiUtils::SetValue(env, in.GetSubTitle(), property);
540 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
541 status = napi_set_named_property(env, out, "subtitle", property);
542 CHECK_RETURN(status == napi_ok, "set property failed", status);
543 return status;
544 }
545
GetDescription(napi_env env,napi_value in,AVMetaData & out)546 napi_status NapiMetaData::GetDescription(napi_env env, napi_value in, AVMetaData& out)
547 {
548 std::string property;
549 auto status = NapiUtils::GetNamedProperty(env, in, "description", property);
550 CHECK_RETURN(status == napi_ok, "get property failed", status);
551 out.SetDescription(property);
552 return status;
553 }
554
SetDescription(napi_env env,const AVMetaData & in,napi_value & out)555 napi_status NapiMetaData::SetDescription(napi_env env, const AVMetaData& in, napi_value& out)
556 {
557 napi_value property {};
558 auto status = NapiUtils::SetValue(env, in.GetDescription(), property);
559 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
560 status = napi_set_named_property(env, out, "description", property);
561 CHECK_RETURN(status == napi_ok, "set property failed", status);
562 return status;
563 }
564
GetLyric(napi_env env,napi_value in,AVMetaData & out)565 napi_status NapiMetaData::GetLyric(napi_env env, napi_value in, AVMetaData& out)
566 {
567 std::string property;
568 auto status = NapiUtils::GetNamedProperty(env, in, "lyric", property);
569 CHECK_RETURN(status == napi_ok, "get property failed", status);
570 out.SetLyric(property);
571 return status;
572 }
573
SetLyric(napi_env env,const AVMetaData & in,napi_value & out)574 napi_status NapiMetaData::SetLyric(napi_env env, const AVMetaData& in, napi_value& out)
575 {
576 napi_value property {};
577 auto status = NapiUtils::SetValue(env, in.GetLyric(), property);
578 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
579 status = napi_set_named_property(env, out, "lyric", property);
580 CHECK_RETURN(status == napi_ok, "set property failed", status);
581 return status;
582 }
583
GetPreviousAssetId(napi_env env,napi_value in,AVMetaData & out)584 napi_status NapiMetaData::GetPreviousAssetId(napi_env env, napi_value in, AVMetaData& out)
585 {
586 std::string property;
587 auto status = NapiUtils::GetNamedProperty(env, in, "previousAssetId", property);
588 CHECK_RETURN(status == napi_ok, "get property failed", status);
589 out.SetPreviousAssetId(property);
590 return status;
591 }
592
SetPreviousAssetId(napi_env env,const AVMetaData & in,napi_value & out)593 napi_status NapiMetaData::SetPreviousAssetId(napi_env env, const AVMetaData& in, napi_value& out)
594 {
595 napi_value property {};
596 auto status = NapiUtils::SetValue(env, in.GetPreviousAssetId(), property);
597 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
598 status = napi_set_named_property(env, out, "previousAssetId", property);
599 CHECK_RETURN(status == napi_ok, "set property failed", status);
600 return status;
601 }
602
GetNextAssetId(napi_env env,napi_value in,AVMetaData & out)603 napi_status NapiMetaData::GetNextAssetId(napi_env env, napi_value in, AVMetaData& out)
604 {
605 std::string property;
606 auto status = NapiUtils::GetNamedProperty(env, in, "nextAssetId", property);
607 CHECK_RETURN(status == napi_ok, "get property failed", status);
608 out.SetNextAssetId(property);
609 return status;
610 }
611
SetNextAssetId(napi_env env,const AVMetaData & in,napi_value & out)612 napi_status NapiMetaData::SetNextAssetId(napi_env env, const AVMetaData& in, napi_value& out)
613 {
614 napi_value property {};
615 auto status = NapiUtils::SetValue(env, in.GetNextAssetId(), property);
616 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
617 status = napi_set_named_property(env, out, "nextAssetId", property);
618 CHECK_RETURN(status == napi_ok, "set property failed", status);
619 return status;
620 }
621
GetSkipIntervals(napi_env env,napi_value in,AVMetaData & out)622 napi_status NapiMetaData::GetSkipIntervals(napi_env env, napi_value in, AVMetaData& out)
623 {
624 int32_t property;
625 auto status = NapiUtils::GetNamedProperty(env, in, "skipIntervals", property);
626 CHECK_RETURN(status == napi_ok, "get property failed", status);
627 SLOGD("GetSkipIntervals %{public}d", static_cast<int32_t>(property));
628 out.SetSkipIntervals(property);
629 return status;
630 }
631
SetSkipIntervals(napi_env env,const AVMetaData & in,napi_value & out)632 napi_status NapiMetaData::SetSkipIntervals(napi_env env, const AVMetaData& in, napi_value& out)
633 {
634 napi_value property {};
635 SLOGD("SetSkipIntervals %{public}d", static_cast<int32_t>(in.GetSkipIntervals()));
636 auto status = NapiUtils::SetValue(env, in.GetSkipIntervals(), property);
637 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
638 status = napi_set_named_property(env, out, "skipIntervals", property);
639 CHECK_RETURN(status == napi_ok, "set property failed", status);
640 return status;
641 }
642
GetFilter(napi_env env,napi_value in,AVMetaData & out)643 napi_status NapiMetaData::GetFilter(napi_env env, napi_value in, AVMetaData& out)
644 {
645 int32_t property;
646 auto status = NapiUtils::GetNamedProperty(env, in, "filter", property);
647 CHECK_RETURN(status == napi_ok, "get property failed", status);
648 SLOGD("GetFilter %{public}d", static_cast<int32_t>(property));
649 out.SetFilter(property);
650 return status;
651 }
652
SetFilter(napi_env env,const AVMetaData & in,napi_value & out)653 napi_status NapiMetaData::SetFilter(napi_env env, const AVMetaData& in, napi_value& out)
654 {
655 napi_value property {};
656 SLOGD("SetFilter %{public}d", static_cast<int32_t>(in.GetFilter()));
657 auto status = NapiUtils::SetValue(env, in.GetFilter(), property);
658 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property failed", status);
659 status = napi_set_named_property(env, out, "filter", property);
660 CHECK_RETURN(status == napi_ok, "set property failed", status);
661 return status;
662 }
663
GetDisplayTags(napi_env env,napi_value in,AVMetaData & out)664 napi_status NapiMetaData::GetDisplayTags(napi_env env, napi_value in, AVMetaData& out)
665 {
666 int32_t property;
667 auto status = NapiUtils::GetNamedProperty(env, in, "displayTags", property);
668 CHECK_RETURN(status == napi_ok, "get property displayTags failed", status);
669 SLOGD("GetDisplayTags %{public}d", static_cast<int32_t>(property));
670 out.SetDisplayTags(property);
671 return status;
672 }
673
SetDisplayTags(napi_env env,const AVMetaData & in,napi_value & out)674 napi_status NapiMetaData::SetDisplayTags(napi_env env, const AVMetaData& in, napi_value& out)
675 {
676 napi_value property {};
677 SLOGD("SetDisplayTags %{public}d", static_cast<int32_t>(in.GetDisplayTags()));
678 auto status = NapiUtils::SetValue(env, in.GetDisplayTags(), property);
679 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property displayTags failed", status);
680 status = napi_set_named_property(env, out, "displayTags", property);
681 CHECK_RETURN(status == napi_ok, "set property displayTags failed", status);
682 return status;
683 }
684
GetDrmSchemes(napi_env env,napi_value in,AVMetaData & out)685 napi_status NapiMetaData::GetDrmSchemes(napi_env env, napi_value in, AVMetaData& out)
686 {
687 std::vector<std::string> property;
688 auto status = NapiUtils::GetNamedProperty(env, in, "drmSchemes", property);
689 CHECK_RETURN(status == napi_ok, "get property drmSchemes failed", status);
690 out.SetDrmSchemes(property);
691 SLOGI("property %{public}zu", property.size());
692 return status;
693 }
694
SetDrmSchemes(napi_env env,const AVMetaData & in,napi_value & out)695 napi_status NapiMetaData::SetDrmSchemes(napi_env env, const AVMetaData& in, napi_value& out)
696 {
697 napi_value property {};
698 SLOGD("SetDrmSchemes in, drmSchemes len: %{public}zu", in.GetDrmSchemes().size());
699 auto status = NapiUtils::SetValue(env, in.GetDrmSchemes(), property);
700 CHECK_RETURN((status == napi_ok) && (property != nullptr), "create property drmSchemes failed", status);
701 status = napi_set_named_property(env, out, "drmSchemes", property);
702 CHECK_RETURN(status == napi_ok, "set property drmSchemes failed", status);
703 return status;
704 }
705 }
706