• 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 #ifndef CODECBASE_H
16 #define CODECBASE_H
17 
18 #include <string>
19 #include "avcodec_common.h"
20 #include "buffer/avsharedmemorybase.h"
21 #include "surface.h"
22 #include "buffer/avbuffer.h"
23 #include "buffer/avbuffer_queue.h"
24 #include "buffer/avbuffer_queue_consumer.h"
25 #include "buffer/avbuffer_queue_define.h"
26 #include "buffer/avbuffer_queue_producer.h"
27 #include "drm_i_keysession_service.h"
28 
29 namespace OHOS {
30 namespace MediaAVCodec {
31 class CodecBase {
32 public:
33     CodecBase() = default;
34     virtual ~CodecBase() = default;
35     virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback);
36     virtual int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback);
37     virtual int32_t Configure(const Format &format) = 0;
38     virtual int32_t Start() = 0;
39     virtual int32_t Stop() = 0;
40     virtual int32_t Flush() = 0;
41     virtual int32_t Reset() = 0;
42     virtual int32_t Release() = 0;
43     virtual int32_t SetParameter(const Format& format) = 0;
44     virtual int32_t GetOutputFormat(Format &format) = 0;
45     virtual int32_t QueueInputBuffer(uint32_t index, const AVCodecBufferInfo &info, AVCodecBufferFlag flag);
46     virtual int32_t QueueInputBuffer(uint32_t index);
47     virtual int32_t ReleaseOutputBuffer(uint32_t index) = 0;
48 
49     virtual int32_t NotifyEos();
50     virtual sptr<Surface> CreateInputSurface();
51     virtual int32_t SetInputSurface(sptr<Surface> surface);
52     virtual int32_t SetOutputSurface(sptr<Surface> surface);
53     virtual int32_t RenderOutputBuffer(uint32_t index);
54     virtual int32_t SignalRequestIDRFrame();
55     virtual int32_t GetInputFormat(Format& format);
56     virtual int32_t SetCustomBuffer(std::shared_ptr<AVBuffer> buffer);
57     virtual int32_t NotifyMemoryRecycle();
58     virtual int32_t NotifyMemoryWriteBack();
59     virtual int32_t NotifySuspend();
60     virtual int32_t NotifyResume();
ChangePlugin(const std::string & mime,bool isEncoder,const std::shared_ptr<Media::Meta> & meta)61     virtual int32_t ChangePlugin(const std::string &mime, bool isEncoder, const std::shared_ptr<Media::Meta> &meta)
62     {
63         (void)mime;
64         (void)isEncoder;
65         (void)meta;
66         return AVCODEC_ERROR_EXTEND_START;
67     }
68 
SetDumpInfo(bool isDump,uint64_t instanceId)69     virtual void SetDumpInfo(bool isDump, uint64_t instanceId)
70     {
71         (void)isDump;
72         (void)instanceId;
73     }
74 
GetHidumperInfo()75     virtual std::string GetHidumperInfo()
76     {
77         return "";
78     }
79 
80     /* API11 audio codec interface */
CreateCodecByName(const std::string & name)81     virtual int32_t CreateCodecByName(const std::string &name)
82     {
83         (void)name;
84         return AVCODEC_ERROR_EXTEND_START;
85     }
86 
Init(Media::Meta & callerInfo)87     virtual int32_t Init(Media::Meta &callerInfo)
88     {
89         (void)callerInfo;
90         return 0;
91     }
92 
Configure(const std::shared_ptr<Media::Meta> & meta)93     virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta)
94     {
95         (void)meta;
96         return AVCODEC_ERROR_EXTEND_START;
97     }
98 
SetParameter(const std::shared_ptr<Media::Meta> & parameter)99     virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> &parameter)
100     {
101         (void)parameter;
102         return AVCODEC_ERROR_EXTEND_START;
103     }
104 
GetOutputFormat(std::shared_ptr<Media::Meta> & parameter)105     virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> &parameter)
106     {
107         (void)parameter;
108         return AVCODEC_ERROR_EXTEND_START;
109     }
110 
SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> & bufferQueueProducer)111     virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer)
112     {
113         (void)bufferQueueProducer;
114         return AVCODEC_ERROR_EXTEND_START;
115     }
116 
Prepare()117     virtual int32_t Prepare()
118     {
119         return AVCODEC_ERROR_EXTEND_START;
120     }
121 
GetInputBufferQueue()122     virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue()
123     {
124         return nullptr;
125     }
126 
ProcessInputBuffer()127     virtual void ProcessInputBuffer()
128     {
129         return;
130     }
131 
SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)132     virtual int32_t SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
133         const bool svpFlag)
134     {
135         (void)keySession;
136         (void)svpFlag;
137         return 0;
138     }
139 
GetInputBufferQueueConsumer()140     virtual sptr<Media::AVBufferQueueConsumer> GetInputBufferQueueConsumer()
141     {
142         return nullptr;
143     }
144 
GetOutputBufferQueueProducer()145     virtual sptr<Media::AVBufferQueueProducer> GetOutputBufferQueueProducer()
146     {
147         return nullptr;
148     }
149 
ProcessInputBufferInner(bool isTriggeredByOutPort,bool isFlushed,uint32_t & bufferStatus)150     virtual void ProcessInputBufferInner(bool isTriggeredByOutPort, bool isFlushed, uint32_t &bufferStatus)
151     {
152         (void)isTriggeredByOutPort;
153         (void)isFlushed;
154         (void)bufferStatus;
155     }
156 
GetChannelId(int32_t & channelId)157     virtual int32_t GetChannelId(int32_t &channelId)
158     {
159         (void)channelId;
160         return 0;
161     }
162 
SetLowPowerPlayerMode(const bool isLpp)163     virtual int32_t SetLowPowerPlayerMode(const bool isLpp)
164     {
165         (void) isLpp;
166         return AVCODEC_ERROR_EXTEND_START;
167     }
168 };
169 } // namespace MediaAVCodec
170 } // namespace OHOS
171 #endif // CODECBASE_H