• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 AVSCREENCAPTURENDKDEMO_MAIN_H
17 #define AVSCREENCAPTURENDKDEMO_MAIN_H
18 #endif // AVSCREENCAPTURENDKDEMO_MAIN_H
19 
20 #include "napi/native_api.h"
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <multimedia/player_framework/native_avscreen_capture.h>
24 #include <multimedia/player_framework/native_avscreen_capture_base.h>
25 #include <multimedia/player_framework/native_avbuffer.h>
26 #include <multimedia/player_framework/native_avscreen_capture_errors.h>
27 #include "hilog/log.h"
28 #include <string>
29 #include "multimedia/player_framework/native_avcodec_videodecoder.h"
30 #include "multimedia/player_framework/native_avcodec_videoencoder.h"
31 #include <native_buffer/native_buffer.h>
32 #include "native_window/external_window.h"
33 #include <ace/xcomponent/native_interface_xcomponent.h>
34 #include <multimedia/player_framework/native_avcapability.h>
35 #include <multimedia/player_framework/native_avcodec_base.h>
36 #include <multimedia/player_framework/native_avformat.h>
37 #include <multimedia/player_framework/native_avbuffer.h>
38 #include <iostream>
39 #include <stdio.h>
40 #include <unistd.h>
41 #include <atomic>
42 #include <fstream>
43 #include <thread>
44 #include <mutex>
45 #include <queue>
46 #include <unordered_map>
47 #include "sample_callback.h"
48 #include "muxer.h"
49 
50 static struct OH_AVScreenCapture *g_avCapture = {};
51 static FILE *micFile_ = nullptr;
52 static FILE *vFile_ = nullptr;
53 static FILE *innerFile_ = nullptr;
54 std::unique_ptr<Muxer> g_muxer;
55 
56 static char filename[100] = {0};
57 bool m_isRunning = false;
58 bool m_scSaveFileIsRunning = false;
59 bool m_scSurfaceIsRunning = false;
60 OH_AVCodec *g_videoEnc;
61 CodecUserData *g_encContext = nullptr;
62 SampleInfo sampleInfo_;
63 std::unique_ptr<std::thread> inputVideoThread_;
64 std::atomic<bool> isStarted_{false};
65 
66 constexpr uint32_t DEFAULT_WIDTH = 4096;
67 // 配置视频帧高度(必须)
68 constexpr uint32_t DEFAULT_HEIGHT = 4096;
69 // 配置视频颜色格式(必须)
70 constexpr OH_AVPixelFormat DEFAULT_PIXELFORMAT = AV_PIXEL_FORMAT_NV12;