• 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 VIDEOENCODER_H
17 #define VIDEOENCODER_H
18 
19 #include "multimedia/player_framework/native_avcodec_videoencoder.h"
20 #include "multimedia/player_framework/native_avbuffer_info.h"
21 #include "sample_info.h"
22 #include "native_window/external_window.h"
23 #include "native_window/buffer_handle.h"
24 #include "sample_callback.h"
25 #include "dfx/error/av_codec_sample_error.h"
26 #include "av_codec_sample_log.h"
27 
28 class VideoEncoder {
29 public:
30     VideoEncoder() = default;
31     ~VideoEncoder();
32 
33     int32_t Create(const std::string &videoCodecMime);
34     int32_t Config(SampleInfo &sampleInfo, CodecUserData *codecUserData);
35     int32_t Start();
36     int32_t PushInputBuffer(CodecBufferInfo &info);
37     int32_t FreeOutputBuffer(uint32_t bufferIndex);
38     int32_t NotifyEndOfStream();
39     int32_t Stop();
40     int32_t Release();
41 
42 private:
43     int32_t SetCallback(CodecUserData *codecUserData);
44     int32_t Configure(const SampleInfo &sampleInfo);
45     int32_t GetSurface(SampleInfo &sampleInfo);
46     bool isAVBufferMode_ = false;
47     OH_AVCodec *encoder_ = nullptr;
48 };
49 #endif // VIDEOENCODER_H