• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef NAPI_TONEPLAYER_H
16 #define NAPI_TONEPLAYER_H
17 #include <iostream>
18 #include <map>
19 #include <queue>
20 
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 #include "securec.h"
24 #include "audio_errors.h"
25 #include "tone_player.h"
26 #include "napi_async_work.h"
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 const std::string NAPI_TONE_PLAYER_CLASS_NAME = "TonePlayer";
31 const int32_t ARGS_LOAD_MAX = 28;
32 const int32_t TONE_TYPE_ARR[ARGS_LOAD_MAX] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
33     100, 101, 102, 103, 104, 106, 107, 108, 200, 201, 203, 204};
34 
35 class NapiTonePlayer {
36 public:
37     NapiTonePlayer();
38     ~NapiTonePlayer();
39     static napi_value Init(napi_env env, napi_value exports);
40     std::shared_ptr<TonePlayer> tonePlayer_;
41 
42 private:
43     struct TonePlayerAsyncContext : public ContextBase {
44         bool isTrue;
45         int32_t intValue;
46         AudioRendererInfo rendererInfo;
47         int32_t toneType;
48     };
49 
50     static void Destructor(napi_env env, void *nativeObject, void *finalizeHint);
51     static napi_value Construct(napi_env env, napi_callback_info info);
52     static napi_value CreateTonePlayer(napi_env env, napi_callback_info info);
53     static napi_value CreateTonePlayerSync(napi_env env, napi_callback_info info);
54     static napi_value Load(napi_env env, napi_callback_info info);
55     static napi_value Start(napi_env env, napi_callback_info info);
56     static napi_value Stop(napi_env env, napi_callback_info info);
57     static napi_value Release(napi_env env, napi_callback_info info);
58     static napi_value CreateTonePlayerWrapper(napi_env env, std::unique_ptr<AudioRendererInfo> &rendererInfo);
59     static bool CheckTonePlayerStatus(NapiTonePlayer *napi, std::shared_ptr<TonePlayerAsyncContext> context);
60     static bool ToneTypeCheck(napi_env env, int32_t type);
61 
62     static std::unique_ptr<AudioRendererInfo> sRendererInfo_;
63     static std::mutex createMutex_;
64     static int32_t isConstructSuccess_;
65     napi_env env_;
66 };
67 } // namespace AudioStandard
68 } // namespace OHOS
69 #endif // NAPI_TONEPLAYER_H
70