1da853ecaSopenharmony_ci/*
2da853ecaSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3da853ecaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4da853ecaSopenharmony_ci * you may not use this file except in compliance with the License.
5da853ecaSopenharmony_ci * You may obtain a copy of the License at
6da853ecaSopenharmony_ci *
7da853ecaSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8da853ecaSopenharmony_ci *
9da853ecaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10da853ecaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11da853ecaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12da853ecaSopenharmony_ci * See the License for the specific language governing permissions and
13da853ecaSopenharmony_ci * limitations under the License.
14da853ecaSopenharmony_ci */
15da853ecaSopenharmony_ci
16da853ecaSopenharmony_ci#ifndef I_CODEC_SERVICE_H
17da853ecaSopenharmony_ci#define I_CODEC_SERVICE_H
18da853ecaSopenharmony_ci
19da853ecaSopenharmony_ci#include <string>
20da853ecaSopenharmony_ci#include "avcodec_common.h"
21da853ecaSopenharmony_ci#include "avcodec_info.h"
22da853ecaSopenharmony_ci#include "buffer/avsharedmemory.h"
23da853ecaSopenharmony_ci#include "refbase.h"
24da853ecaSopenharmony_ci#include "surface.h"
25da853ecaSopenharmony_ci#include "meta/meta.h"
26da853ecaSopenharmony_ci#include "meta/format.h"
27da853ecaSopenharmony_ci#include "buffer/avbuffer.h"
28da853ecaSopenharmony_ci#include "buffer/avbuffer_queue.h"
29da853ecaSopenharmony_ci#include "buffer/avbuffer_queue_consumer.h"
30da853ecaSopenharmony_ci#include "buffer/avbuffer_queue_define.h"
31da853ecaSopenharmony_ci#include "buffer/avbuffer_queue_producer.h"
32da853ecaSopenharmony_ci#include "drm_i_keysession_service.h"
33da853ecaSopenharmony_ci
34da853ecaSopenharmony_cinamespace OHOS {
35da853ecaSopenharmony_cinamespace MediaAVCodec {
36da853ecaSopenharmony_ciclass ICodecService {
37da853ecaSopenharmony_cipublic:
38da853ecaSopenharmony_ci    virtual ~ICodecService() = default;
39da853ecaSopenharmony_ci
40da853ecaSopenharmony_ci    virtual int32_t Init(AVCodecType type, bool isMimeType,
41da853ecaSopenharmony_ci        const std::string &name, Media::Meta &callerInfo, API_VERSION apiVersion = API_VERSION::API_VERSION_10) = 0;
42da853ecaSopenharmony_ci    virtual int32_t Configure(const Format &format) = 0;
43da853ecaSopenharmony_ci    virtual int32_t SetCustomBuffer(std::shared_ptr<AVBuffer> buffer) = 0;
44da853ecaSopenharmony_ci    virtual int32_t Start() = 0;
45da853ecaSopenharmony_ci    virtual int32_t Stop() = 0;
46da853ecaSopenharmony_ci    virtual int32_t Flush() = 0;
47da853ecaSopenharmony_ci    virtual int32_t Reset() = 0;
48da853ecaSopenharmony_ci    virtual int32_t Release() = 0;
49da853ecaSopenharmony_ci    virtual int32_t NotifyEos() = 0;
50da853ecaSopenharmony_ci    virtual sptr<Surface> CreateInputSurface() = 0;
51da853ecaSopenharmony_ci    virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0;
52da853ecaSopenharmony_ci    virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
53da853ecaSopenharmony_ci    virtual int32_t QueueInputBuffer(uint32_t index) = 0;
54da853ecaSopenharmony_ci    virtual int32_t QueueInputParameter(uint32_t index) = 0;
55da853ecaSopenharmony_ci    virtual int32_t GetOutputFormat(Format &format) = 0;
56da853ecaSopenharmony_ci    virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render = false) = 0;
57da853ecaSopenharmony_ci    virtual int32_t RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs) = 0;
58da853ecaSopenharmony_ci    virtual int32_t SetParameter(const Format &format) = 0;
59da853ecaSopenharmony_ci    virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) = 0;
60da853ecaSopenharmony_ci    virtual int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback) = 0;
61da853ecaSopenharmony_ci    virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback) = 0;
62da853ecaSopenharmony_ci    virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterWithAttrCallback> &callback) = 0;
63da853ecaSopenharmony_ci    virtual int32_t GetInputFormat(Format &format) = 0;
64da853ecaSopenharmony_ci    virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
65da853ecaSopenharmony_ci        const bool svpFlag)
66da853ecaSopenharmony_ci    {
67da853ecaSopenharmony_ci        (void)keySession;
68da853ecaSopenharmony_ci        (void)svpFlag;
69da853ecaSopenharmony_ci        return AVCODEC_ERROR_EXTEND_START;
70da853ecaSopenharmony_ci    }
71da853ecaSopenharmony_ci
72da853ecaSopenharmony_ci    /* API11 audio codec interface */
73da853ecaSopenharmony_ci    virtual int32_t CreateCodecByName(const std::string &name)
74da853ecaSopenharmony_ci    {
75da853ecaSopenharmony_ci        (void)name;
76da853ecaSopenharmony_ci        return AVCODEC_ERROR_EXTEND_START;
77da853ecaSopenharmony_ci    }
78da853ecaSopenharmony_ci
79da853ecaSopenharmony_ci    virtual int32_t Configure(const std::shared_ptr<Media::Meta> &meta)
80da853ecaSopenharmony_ci    {
81da853ecaSopenharmony_ci        (void)meta;
82da853ecaSopenharmony_ci        return AVCODEC_ERROR_EXTEND_START;
83da853ecaSopenharmony_ci    }
84da853ecaSopenharmony_ci    virtual int32_t SetParameter(const std::shared_ptr<Media::Meta> &parameter)
85da853ecaSopenharmony_ci    {
86da853ecaSopenharmony_ci        (void)parameter;
87da853ecaSopenharmony_ci        return AVCODEC_ERROR_EXTEND_START;
88da853ecaSopenharmony_ci    }
89da853ecaSopenharmony_ci    virtual int32_t GetOutputFormat(std::shared_ptr<Media::Meta> &parameter)
90da853ecaSopenharmony_ci    {
91da853ecaSopenharmony_ci        (void)parameter;
92da853ecaSopenharmony_ci        return AVCODEC_ERROR_EXTEND_START;
93da853ecaSopenharmony_ci    }
94da853ecaSopenharmony_ci
95da853ecaSopenharmony_ci    virtual int32_t SetOutputBufferQueue(const sptr<Media::AVBufferQueueProducer> &bufferQueueProducer)
96da853ecaSopenharmony_ci    {
97da853ecaSopenharmony_ci        (void)bufferQueueProducer;
98da853ecaSopenharmony_ci        return AVCODEC_ERROR_EXTEND_START;
99da853ecaSopenharmony_ci    }
100da853ecaSopenharmony_ci    virtual int32_t Prepare()
101da853ecaSopenharmony_ci    {
102da853ecaSopenharmony_ci        return AVCODEC_ERROR_EXTEND_START;
103da853ecaSopenharmony_ci    }
104da853ecaSopenharmony_ci    virtual sptr<Media::AVBufferQueueProducer> GetInputBufferQueue()
105da853ecaSopenharmony_ci    {
106da853ecaSopenharmony_ci        return nullptr;
107da853ecaSopenharmony_ci    }
108da853ecaSopenharmony_ci    virtual void ProcessInputBuffer()
109da853ecaSopenharmony_ci    {
110da853ecaSopenharmony_ci        return;
111da853ecaSopenharmony_ci    }
112da853ecaSopenharmony_ci    virtual bool CheckRunning()
113da853ecaSopenharmony_ci    {
114da853ecaSopenharmony_ci        return false;
115da853ecaSopenharmony_ci    }
116da853ecaSopenharmony_ci
117da853ecaSopenharmony_ci    /* API12 audio codec interface for drm */
118da853ecaSopenharmony_ci    virtual int32_t SetAudioDecryptionConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
119da853ecaSopenharmony_ci        const bool svpFlag)
120da853ecaSopenharmony_ci    {
121da853ecaSopenharmony_ci        (void)keySession;
122da853ecaSopenharmony_ci        (void)svpFlag;
123da853ecaSopenharmony_ci        return AVCODEC_ERROR_EXTEND_START;
124da853ecaSopenharmony_ci    }
125da853ecaSopenharmony_ci};
126da853ecaSopenharmony_ci} // namespace MediaAVCodec
127da853ecaSopenharmony_ci} // namespace OHOS
128da853ecaSopenharmony_ci#endif // I_CODEC_SERVICE_H