• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-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 MEDIA_AVCODEC_AUDIO_CODEC_H
17 #define MEDIA_AVCODEC_AUDIO_CODEC_H
18 
19 #include "avcodec_common.h"
20 #include "meta/format.h"
21 #include "meta/meta.h"
22 #include "buffer/avbuffer_queue_producer.h"
23 #include "drm_i_keysession_service.h"
24 
25 namespace OHOS {
26 namespace MediaAVCodec {
27 class AVCodecAudioCodec {
28 public:
29     virtual ~AVCodecAudioCodec() = default;
30 
31     virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta);
32 
33     virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer);
34 
35     virtual int32_t Prepare();
36 
37     virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue();
38 
39     virtual int32_t Start();
40 
41     virtual int32_t Stop();
42 
43     virtual int32_t Flush();
44 
45     virtual int32_t Reset();
46 
47     virtual int32_t Release();
48 
49     virtual int32_t NotifyEos();
50 
51     virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> &parameter);
52 
53     virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> &parameter);
54 
55     virtual int32_t ChangePlugin(const std::string &mime, bool isEncoder, const std::shared_ptr<Media::Meta> &meta);
56 
57     virtual int32_t SetCodecCallback(const std::shared_ptr<MediaCodecCallback> &codecCallback);
58 
59     virtual int32_t SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
60         const bool svpFlag);
61 
62     virtual void ProcessInputBuffer();
63 
64     virtual void SetDumpInfo(bool isDump, uint64_t instanceId);
65 
GetInputBufferQueueConsumer()66     virtual sptr<Media::AVBufferQueueConsumer> GetInputBufferQueueConsumer()
67     {
68         return nullptr;
69     }
70 
GetOutputBufferQueueProducer()71     virtual sptr<Media::AVBufferQueueProducer> GetOutputBufferQueueProducer()
72     {
73         return nullptr;
74     }
75 
ProcessInputBufferInner(bool isTriggeredByOutPort,bool isFlushed)76     virtual void ProcessInputBufferInner(bool isTriggeredByOutPort, bool isFlushed)
77     {
78         (void)isTriggeredByOutPort;
79         (void)isFlushed;
80     }
81 };
82 
83 class __attribute__((visibility("default"))) AudioCodecFactory {
84 public:
85 #ifdef UNSUPPORT_CODEC
CreateByMime(const std::string & mime,bool isEncoder)86     static std::shared_ptr<AVCodecAudioCodec> CreateByMime(const std::string &mime, bool isEncoder)
87     {
88         (void)mime;
89         return nullptr;
90     }
91 
CreateByName(const std::string & name)92     static std::shared_ptr<AVCodecAudioCodec> CreateByName(const std::string &name)
93     {
94         (void)name;
95         return nullptr;
96     }
97 #else
98     /**
99      * @brief Instantiate the preferred decoder of the given mime type.
100      * @param mime The mime type.
101      * @return Returns the preferred decoder.
102      * @since 4.1
103      */
104     static std::shared_ptr<AVCodecAudioCodec> CreateByMime(const std::string &mime, bool isEncoder);
105 
106     /**
107      * @brief Instantiates the designated decoder.
108      * @param name The codec's name.
109      * @return Returns the designated decoder.
110      * @since 4.1
111      */
112     static std::shared_ptr<AVCodecAudioCodec> CreateByName(const std::string &name);
113 #endif
114 private:
115     AudioCodecFactory() = default;
116     ~AudioCodecFactory() = default;
117 };
118 
119 } // namespace MediaAVCodec
120 } // namespace OHOS
121 #endif // MEDIA_AVCODEC_AUDIO_CODEC_H