1 /*
2 * Copyright (C) 2021 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 "native_module_ohos_media.h"
17 #include "media_log.h"
18
19 namespace {
20 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "JSMediaModule"};
21 }
22
23 /*
24 * Function registering all props and functions of ohos.media module
25 * which involves player and the recorder
26 */
Export(napi_env env,napi_value exports)27 static napi_value Export(napi_env env, napi_value exports)
28 {
29 MEDIA_LOGD("Export() is called");
30
31 OHOS::Media::MediaEnumNapi::Init(env, exports);
32
33 #ifdef SUPPORT_PLAYER
34 OHOS::Media::AudioPlayerNapi::Init(env, exports);
35 OHOS::Media::VideoPlayerNapi::Init(env, exports);
36 #endif
37 #ifdef SUPPORT_METADATA
38 OHOS::Media::AVMetadataExtractorNapi::Init(env, exports);
39 OHOS::Media::AVImageGeneratorNapi::Init(env, exports);
40 #endif
41 #ifdef SUPPORT_PLAYER_API9
42 OHOS::Media::AVPlayerNapi::Init(env, exports);
43 #endif
44 #ifdef SUPPORT_RECORDER
45 OHOS::Media::AudioRecorderNapi::Init(env, exports);
46 OHOS::Media::VideoRecorderNapi::Init(env, exports);
47 #endif
48 #ifdef SUPPORT_RECORDER_API9
49 OHOS::Media::AVRecorderNapi::Init(env, exports);
50 #endif
51 #ifdef SUPPORT_TRANSCODER
52 OHOS::Media::AVTransCoderNapi::Init(env, exports);
53 #endif
54 #ifdef SUPPORT_SOUND_POOL
55 OHOS::Media::SoundPoolNapi::Init(env, exports);
56 #endif
57 #ifdef SUPPORT_SCREEN_CAPTURE
58 OHOS::Media::AVScreenCaptureNapi::Init(env, exports);
59 #endif
60 #ifdef SUPPORT_MEDIA_SOURCE
61 OHOS::Media::MediaSourceNapi::Init(env, exports);
62 #endif
63
64 return exports;
65 }
66
67 /*
68 * module define
69 */
70 static napi_module g_module = {
71 .nm_version = 1,
72 .nm_flags = 0,
73 .nm_filename = nullptr,
74 .nm_register_func = Export,
75 .nm_modname = "multimedia.media",
76 .nm_priv = (reinterpret_cast<void*>(0)),
77 .reserved = {0}
78 };
79
80 /*
81 * module register
82 */
RegisterModule(void)83 extern "C" __attribute__((constructor)) void RegisterModule(void)
84 {
85 MEDIA_LOGD("RegisterModule() is called");
86 napi_module_register(&g_module);
87 }
88