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 I_CODEC_SERVICE_H
17 #define I_CODEC_SERVICE_H
18 
19 #include <string>
20 #include "avcodec_common.h"
21 #include "avcodec_info.h"
22 #include "buffer/avsharedmemory.h"
23 #include "refbase.h"
24 #include "surface.h"
25 #include "meta/meta.h"
26 #include "meta/format.h"
27 #include "buffer/avbuffer.h"
28 #include "buffer/avbuffer_queue.h"
29 #include "buffer/avbuffer_queue_consumer.h"
30 #include "buffer/avbuffer_queue_define.h"
31 #include "buffer/avbuffer_queue_producer.h"
32 #include "foundation/multimedia/drm_framework/services/drm_service/ipc/i_keysession_service.h"
33 
34 namespace OHOS {
35 namespace MediaAVCodec {
36 class ICodecService {
37 public:
38     virtual ~ICodecService() = default;
39 
40     virtual int32_t Init(AVCodecType type, bool isMimeType,
41         const std::string &name, Media::Meta &callerInfo, API_VERSION apiVersion = API_VERSION::API_VERSION_10) = 0;
42     virtual int32_t Configure(const Format &format) = 0;
43     virtual int32_t SetCustomBuffer(std::shared_ptr<AVBuffer> buffer) = 0;
44     virtual int32_t Start() = 0;
45     virtual int32_t Stop() = 0;
46     virtual int32_t Flush() = 0;
47     virtual int32_t Reset() = 0;
48     virtual int32_t Release() = 0;
49     virtual int32_t NotifyEos() = 0;
50     virtual sptr<Surface> CreateInputSurface() = 0;
51     virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0;
52     virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
53     virtual int32_t QueueInputBuffer(uint32_t index) = 0;
54     virtual int32_t QueueInputParameter(uint32_t index) = 0;
55     virtual int32_t GetOutputFormat(Format &format) = 0;
56     virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render = false) = 0;
57     virtual int32_t RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs) = 0;
58     virtual int32_t SetParameter(const Format &format) = 0;
59     virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) = 0;
60     virtual int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback) = 0;
61     virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback) = 0;
62     virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterWithAttrCallback> &callback) = 0;
63     virtual int32_t GetInputFormat(Format &format) = 0;
SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)64     virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
65         const bool svpFlag)
66     {
67         (void)keySession;
68         (void)svpFlag;
69         return AVCODEC_ERROR_EXTEND_START;
70     }
71 
72     /* API11 audio codec interface */
CreateCodecByName(const std::string & name)73     virtual int32_t CreateCodecByName(const std::string &name)
74     {
75         (void)name;
76         return AVCODEC_ERROR_EXTEND_START;
77     }
78 
Configure(const std::shared_ptr<Media::Meta> & meta)79     virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta)
80     {
81         (void)meta;
82         return AVCODEC_ERROR_EXTEND_START;
83     }
SetParameter(const std::shared_ptr<Media::Meta> & parameter)84     virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> &parameter)
85     {
86         (void)parameter;
87         return AVCODEC_ERROR_EXTEND_START;
88     }
GetOutputFormat(std::shared_ptr<Media::Meta> & parameter)89     virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> &parameter)
90     {
91         (void)parameter;
92         return AVCODEC_ERROR_EXTEND_START;
93     }
94 
SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> & bufferQueueProducer)95     virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer)
96     {
97         (void)bufferQueueProducer;
98         return AVCODEC_ERROR_EXTEND_START;
99     }
Prepare()100     virtual int32_t Prepare()
101     {
102         return AVCODEC_ERROR_EXTEND_START;
103     }
GetInputBufferQueue()104     virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue()
105     {
106         return nullptr;
107     }
ProcessInputBuffer()108     virtual void ProcessInputBuffer()
109     {
110         return;
111     }
CheckRunning()112     virtual bool CheckRunning()
113     {
114         return false;
115     }
116 
117     /* API12 audio codec interface for drm */
SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)118     virtual int32_t SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
119         const bool svpFlag)
120     {
121         (void)keySession;
122         (void)svpFlag;
123         return AVCODEC_ERROR_EXTEND_START;
124     }
125 };
126 } // namespace MediaAVCodec
127 } // namespace OHOS
128 #endif // I_CODEC_SERVICE_H