• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-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  * Description: supply napi interface for cast mirror player.
15  * Author: zhangjingnan
16  * Create: 2023-5-27
17  */
18 
19 #ifndef NAPI_CAST_MIRROR_PLAYER_H_
20 #define NAPI_CAST_MIRROR_PLAYER_H_
21 
22 #include <map>
23 #include <memory>
24 #include <mutex>
25 
26 #include "napi/native_api.h"
27 #include "napi/native_node_api.h"
28 #include "cast_engine_log.h"
29 #include "napi_errors.h"
30 #include "cast_engine_errors.h"
31 #include "i_mirror_player.h"
32 
33 namespace OHOS {
34 namespace CastEngine {
35 namespace CastEngineClient {
36 class NapiMirrorPlayer {
37 public:
38     static void DefineMirrorPlayerJSClass(napi_env env);
39     static napi_status CreateNapiMirrorPlayer(napi_env env, std::shared_ptr<IMirrorPlayer> mirrorPlayer,
40         napi_value &out);
41 
NapiMirrorPlayer(std::shared_ptr<IMirrorPlayer> mirrorPlayer)42     NapiMirrorPlayer(std::shared_ptr<IMirrorPlayer> mirrorPlayer) : mirrorPlayer_(mirrorPlayer) {}
43     NapiMirrorPlayer() = default;
44     ~NapiMirrorPlayer() = default;
GetMirrorPlayer()45     std::shared_ptr<IMirrorPlayer> GetMirrorPlayer()
46     {
47         std::lock_guard<std::mutex> lock(mutex_);
48         return mirrorPlayer_;
49     }
Reset()50     void Reset()
51     {
52         std::lock_guard<std::mutex> lock(mutex_);
53         mirrorPlayer_.reset();
54     }
55 
56 private:
57     static napi_value NapiMirrorPlayerConstructor(napi_env env, napi_callback_info info);
58     static napi_value Play(napi_env env, napi_callback_info info);
59     static napi_value Pause(napi_env env, napi_callback_info info);
60     static napi_value SetAppInfo(napi_env env, napi_callback_info info);
61     static napi_value SetSurface(napi_env env, napi_callback_info info);
62     static napi_value Release(napi_env env, napi_callback_info info);
63     static napi_value ResizeVirtualScreen(napi_env env, napi_callback_info info);
64     static napi_value SetCastRoute(napi_env env, napi_callback_info info);
65     static napi_value GetScreenshot(napi_env env, napi_callback_info info);
66     std::mutex mutex_;
67     std::shared_ptr<IMirrorPlayer> mirrorPlayer_;
68     static thread_local napi_ref consRef_;
69 };
70 } // namespace CastEngineClient
71 } // namespace CastEngine
72 } // namespace OHOS
73 #endif