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 #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 "foundation/multimedia/drm_framework/services/drm_service/ipc/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 
GetHidumperInfo()58     virtual std::string GetHidumperInfo()
59     {
60         return "";
61     }
62 
63     /* API11 audio codec interface */
CreateCodecByName(const std::string & name)64     virtual int32_t CreateCodecByName(const std::string &name)
65     {
66         (void)name;
67         return AVCODEC_ERROR_EXTEND_START;
68     }
69 
Init(Media::Meta & callerInfo)70     virtual int32_t Init(Media::Meta &callerInfo)
71     {
72         (void)callerInfo;
73         return 0;
74     }
75 
Configure(const std::shared_ptr<Media::Meta> & meta)76     virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta)
77     {
78         (void)meta;
79         return AVCODEC_ERROR_EXTEND_START;
80     }
81 
SetParameter(const std::shared_ptr<Media::Meta> & parameter)82     virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> &parameter)
83     {
84         (void)parameter;
85         return AVCODEC_ERROR_EXTEND_START;
86     }
87 
GetOutputFormat(std::shared_ptr<Media::Meta> & parameter)88     virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> &parameter)
89     {
90         (void)parameter;
91         return AVCODEC_ERROR_EXTEND_START;
92     }
93 
SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> & bufferQueueProducer)94     virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer)
95     {
96         (void)bufferQueueProducer;
97         return AVCODEC_ERROR_EXTEND_START;
98     }
99 
Prepare()100     virtual int32_t Prepare()
101     {
102         return AVCODEC_ERROR_EXTEND_START;
103     }
104 
GetInputBufferQueue()105     virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue()
106     {
107         return nullptr;
108     }
109 
ProcessInputBuffer()110     virtual void ProcessInputBuffer()
111     {
112         return;
113     }
114 
SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)115     virtual int32_t SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
116         const bool svpFlag)
117     {
118         (void)keySession;
119         (void)svpFlag;
120         return 0;
121     }
122 };
123 } // namespace MediaAVCodec
124 } // namespace OHOS
125 #endif // CODECBASE_H