• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef AVRECORDER_CALLBACK_H
16 #define AVRECORDER_CALLBACK_H
17 
18 #include "avrecorder_napi.h"
19 #include "recorder.h"
20 #include "av_common.h"
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 #include "common_napi.h"
24 
25 namespace OHOS {
26 namespace Media {
27 class AVRecorderCallback : public RecorderCallback {
28 public:
29     explicit AVRecorderCallback(napi_env env);
30     virtual ~AVRecorderCallback();
31 
32     void SaveCallbackReference(const std::string &name, std::weak_ptr<AutoRef> ref);
33     void CancelCallbackReference(const std::string &name);
34     void ClearCallbackReference();
35     void SendErrorCallback(int32_t errCode, const std::string &msg);
36     void SendStateCallback(const std::string &state, const StateChangeReason &reason);
37     std::string GetState();
38 
39 protected:
40     void OnError(RecorderErrorType errorType, int32_t errCode) override;
41     void OnInfo(int32_t type, int32_t extra) override;
42 
43 private:
44     struct AVRecordJsCallback {
45         std::weak_ptr<AutoRef> autoRef;
46         std::string callbackName = "unknown";
47         std::string errorMsg = "unknown";
48         int32_t errorCode = MSERR_EXT_UNKNOWN;
49         int32_t reason = 1;
50         std::string state = "unknown";
51     };
52     void OnJsErrorCallBack(AVRecordJsCallback *jsCb) const;
53     void OnJsStateCallBack(AVRecordJsCallback *jsCb) const;
54     napi_env env_ = nullptr;
55     std::mutex mutex_;
56     std::string currentState_ = AVRecorderState::STATE_IDLE;
57     std::map<std::string, std::weak_ptr<AutoRef>> refMap_;
58 };
59 } // namespace Media
60 } // namespace OHOS
61 #endif // AVRECORDER_CALLBACK_H