1 /*
2  * Copyright (c) 2020-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 DECODER_H
17 #define DECODER_H
18 #include <string>
19 #include "codec_type.h"
20 
21 namespace OHOS {
22 namespace Media {
23 const int CODEC_SUCCESS = 0;
24 const int CODEC_FAILURE = -1;
25 
26 typedef struct {
27     CodecBuffer info;
28     CodecBufferInfo buffer;
29 } PlayerBufferInfo;
30 
31 typedef struct {
32     AvCodecMime mime;
33     uint32_t maxWidth;
34     uint32_t maxHeight;
35     uint32_t bufSize;
36     uint32_t frameBufCnt; // todo buffer ����Ӧ������������������
37     void *priv;
38 } VdecAttr;
39 
40 typedef struct {
41     AvCodecMime mime;
42     int32_t bufSize;
43     int32_t channelCnt; /* for pcm frame */
44     void *priv;
45 } AdecAttr;
46 
47 typedef struct {
48     union {
49         AdecAttr adecAttr;
50         VdecAttr vdecAttr;
51     };
52     CodecType type;
53 } AvAttribute;
54 
55 class Decoder {
56 public:
57     Decoder();
58 
59     virtual ~Decoder();
60 
61     int32_t GetCapbilityByMime(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapability &cap);
62 
63     int32_t CreateHandle(const std::string &name, AvAttribute &attr);
64 
65     int32_t DestroyHandle();
66 
67     int32_t SetPortBufferMode(DirectionType direct, AllocateBufferMode mode, BufferType type);
68 
69     int32_t SetMetadata(const Param *params, int paramCnt);
70 
71     int32_t GetMetadata(Param *param, int paramCnt);
72 
73     int32_t StartDec();
74 
75     int32_t StopDec();
76 
77     int32_t FlushDec();
78 
79     int32_t QueueInputBuffer(CodecBuffer* inputData, uint32_t timeoutMs);
80 
81     int32_t DequeInputBuffer(CodecBuffer* inputData, uint32_t timeoutMs);
82 
83     int32_t QueueOutputBuffer(CodecBuffer* outInfo, uint32_t timeoutMs);
84 
85     int32_t DequeueOutputBuffer(CodecBuffer* outInfo, uint32_t timeoutMs);
86 
87     int32_t SetCallback(CodecCallback &cb, UINTPTR instance);
88 
89 private:
90     CODEC_HANDLETYPE codecHandle_;
91 };
92 }
93 }
94 #endif
95