1 /*
2  * Copyright (C) 2023 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 CODEC_EENGIN_AUDIO_FFMPEG_ADAPTER_H
17 #define CODEC_EENGIN_AUDIO_FFMPEG_ADAPTER_H
18 
19 #include "audio_base_codec.h"
20 #include "audio_codec_worker.h"
21 #include "avcodec_common.h"
22 #include "codecbase.h"
23 #include "nocopyable.h"
24 
25 namespace OHOS {
26 namespace MediaAVCodec {
27 class AudioCodecAdapter : public CodecBase, public NoCopyable {
28 public:
29     explicit AudioCodecAdapter(const std::string &name);
30 
31     ~AudioCodecAdapter() override;
32 
33     int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) override;
34 
35     int32_t Configure(const Format &format) override;
36 
37     int32_t Start() override;
38 
39     int32_t Stop() override;
40 
41     int32_t Init(Media::Meta &callerInfo) override;
42 
43     int32_t Flush() override;
44 
45     int32_t Reset() override;
46 
47     int32_t Release() override;
48 
49     int32_t NotifyEos() override;
50 
51     int32_t SetParameter(const Format &format) override;
52 
53     int32_t GetOutputFormat(Format &format) override;
54 
55     int32_t QueueInputBuffer(uint32_t index, const AVCodecBufferInfo &info, AVCodecBufferFlag flag) override;
56 
57     int32_t ReleaseOutputBuffer(uint32_t index) override;
58 
59 private:
60     std::atomic<CodecState> state_;
61     const std::string name_;
62     std::shared_ptr<AVCodecCallback> callback_;
63     std::shared_ptr<AudioBaseCodec> audioCodec;
64     std::shared_ptr<AudioCodecWorker> worker_;
65 
66 private:
67     int32_t doFlush();
68     int32_t doStart();
69     int32_t doStop();
70     int32_t doResume();
71     int32_t doRelease();
72     int32_t doInit();
73     int32_t doConfigure(const Format &format);
74     std::string_view stateToString(CodecState state);
75 };
76 } // namespace MediaAVCodec
77 } // namespace OHOS
78 #endif