• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 IAVCODEC_ENGINE_H
17 #define IAVCODEC_ENGINE_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <memory>
22 #include <refbase.h>
23 #include "nocopyable.h"
24 #include "avcodec_common.h"
25 #include "avcodec_info.h"
26 #include "avsharedmemory.h"
27 #include "format.h"
28 
29 namespace OHOS {
30 class Surface;
31 
32 namespace Media {
33 class IAVCodecEngineObs : public std::enable_shared_from_this<IAVCodecEngineObs> {
34 public:
35     virtual ~IAVCodecEngineObs() = default;
36 
37     virtual void OnError(int32_t errorType, int32_t errorCode) = 0;
38     virtual void OnOutputFormatChanged(const Format &format) = 0;
39     virtual void OnInputBufferAvailable(uint32_t index) = 0;
40     virtual void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
41 };
42 
43 class IAVCodecEngine {
44 public:
45     virtual ~IAVCodecEngine() = default;
46 
47     virtual int32_t Init(AVCodecType type, bool isMimeType, const std::string &name) = 0;
48     virtual int32_t Configure(const Format &format) = 0;
49     virtual int32_t Prepare() = 0;
50     virtual int32_t Start() = 0;
51     virtual int32_t Stop() = 0;
52     virtual int32_t Flush() = 0;
53     virtual int32_t Reset() = 0;
54     virtual int32_t NotifyEos() = 0;
55     virtual sptr<Surface> CreateInputSurface() = 0;
56     virtual int32_t SetOutputSurface(const sptr<Surface> &surface) = 0;
57     virtual std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index) = 0;
58     virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
59     virtual std::shared_ptr<AVSharedMemory> GetOutputBuffer(uint32_t index) = 0;
60     virtual int32_t GetOutputFormat(Format &format) = 0;
61     virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render) = 0;
62     virtual int32_t SetParameter(const Format &format) = 0;
63     virtual int32_t SetObs(const std::weak_ptr<IAVCodecEngineObs> &obs) = 0;
64 };
65 } // namespace Media
66 } // namespace OHOS
67 #endif // IAVCODEC_ENGINE_H
68