• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 OH_VEF_AUDIO_ENCODER_H
17 #define OH_VEF_AUDIO_ENCODER_H
18 
19 #include <mutex>
20 #include <string>
21 #include <native_avcodec_base.h>
22 #include <native_avmuxer.h>
23 #include "ffrt.h"
24 #include "codec/common/codec_common.h"
25 #include "codec/common/codec_encoder.h"
26 #include "codec/audio/pcm_buffer_queue.h"
27 #include "video_editor.h"
28 
29 namespace OHOS {
30 namespace Media {
31 
32 class AudioEncoder : public CodecEncoder {
33 public:
34     AudioEncoder(uint64_t id, const CodecOnOutData& encodecCallback);
35     ~AudioEncoder();
36 
37     VEFError Init(OH_AVFormat* format) override;
38     VEFError Start() override;
39     VEFError Stop() override;
40     VEFError Flush() override;
41 
42     std::shared_ptr<PcmBufferQueue> GetPcmInputBufferQueue() const;
43 
44 protected:
45     void CodecOnErrorInner(OH_AVCodec* codec, int32_t errorCode) override;
46 
47 private:
48     VEFError CreateEncoder();
49     VEFError ConfigureEncoder(OH_AVFormat* format);
50     VEFError PushPcmData(uint32_t index, OH_AVCodecBufferAttr& attr);
51 
52     void CodecOnStreamChangedInner(OH_AVFormat* format) override;
53     void CodecOnNeedInputDataInner(OH_AVCodec* codec, uint32_t index, OH_AVMemory* data) override;
54     void CodecOnNewOutputDataInner(OH_AVCodec* codec, uint32_t index, OH_AVMemory* data,
55         OH_AVCodecBufferAttr* attr) override;
56 private:
57     CodecOnOutData encodeCallback_;
58     ffrt::mutex encoderMutex_;
59     std::shared_ptr<PcmBufferQueue> pcmInputBufferQueue_;
60 };
61 } // namespace Media
62 } // namespace OHOS
63 
64 #endif // OH_VEF_AUDIO_ENCODER_H
65