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 #ifndef NAPI_DEMO_H 17 #define NAPI_DEMO_H 18 19 #include <atomic> 20 #include <thread> 21 #include <string> 22 #include "nocopyable.h" 23 #include "media_errors.h" 24 #include "napi/native_api.h" 25 #include "napi/native_node_api.h" 26 #include "surface.h" 27 #include "window_manager.h" 28 29 namespace OHOS { 30 namespace Media { 31 class NapiDemo : public NoCopyable { 32 public: 33 static napi_value Init(napi_env env, napi_value exports); 34 35 private: 36 static napi_value Constructor(napi_env env, napi_callback_info info); 37 static void Destructor(napi_env env, void *nativeObject, void *finalize); 38 static napi_value CreateMediaTest(napi_env env, napi_callback_info info); 39 static napi_value StartStream(napi_env env, napi_callback_info info); 40 static napi_value CloseStream(napi_env env, napi_callback_info info); 41 static napi_value SetResolution(napi_env env, napi_callback_info info); 42 static napi_value SetFrameCount(napi_env env, napi_callback_info info); 43 static napi_value SetFrameRate(napi_env env, napi_callback_info info); 44 static std::string GetStringArgument(napi_env env, napi_value value); 45 static bool StrToUint64(const std::string &str, uint64_t &value); 46 47 void BufferLoop(); 48 49 NapiDemo(); 50 ~NapiDemo(); 51 52 static thread_local napi_ref constructor_; 53 napi_env env_ = nullptr; 54 napi_ref wrap_ = nullptr; 55 int64_t pts_ = 0; 56 int32_t count_ = 0; 57 unsigned char color_ = 0; 58 int32_t totalFrameCount_ = 0; 59 int32_t frameRate_ = 0; 60 int32_t width_ = 0; 61 int32_t height_ = 0; 62 OHOS::sptr<OHOS::Surface> producerSurface_ = nullptr; 63 std::atomic<bool> isStart_ = false; 64 OHOS::BufferFlushConfig flushConfig_; 65 OHOS::BufferRequestConfig requestConfig_; 66 std::unique_ptr<std::thread> bufferThread_; 67 }; 68 } // namespace Media 69 } // namespace OHOS 70 #endif // NAPI_DEMO_H 71