• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong DID 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 CODEC_INSTANCE_H
17 #define CODEC_INSTANCE_H
18 
19 #include <pthread.h>
20 #include <stdio.h>
21 #include "buffer_manager_iface.h"
22 #include "buffer_manager_wrapper.h"
23 #include "codec_oem_if.h"
24 #include "share_mem.h"
25 
26 #define MAX_BUFFER_NUM  64
27 #define QUEUE_TIME_OUT  10
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34 typedef enum {
35     CODEC_STATUS_IDLE,
36     CODEC_STATUS_STARTED,
37     CODEC_STATUS_STOPED,
38 } CodecStatus;
39 
40 struct CodecInstance {
41     pthread_t task;
42     ShareMemory inputBuffers[MAX_BUFFER_NUM];
43     ShareMemory outputBuffers[MAX_BUFFER_NUM];
44     int32_t inputBuffersCount;
45     int32_t outputBuffersCount;
46     CodecBuffer *inputInfos[MAX_BUFFER_NUM];
47     CodecBuffer *outputInfos[MAX_BUFFER_NUM];
48     int32_t inputInfoCount;
49     int32_t outputInfoCount;
50 
51     void *oemLibHandle;
52     struct CodecOemIf *codecOemIface;
53 
54     void *bufferManagerLibHandle;
55     struct BufferManagerIf *bufferManagerIface;
56     struct BufferManagerWrapper *bufferManagerWrapper;
57 
58     CODEC_HANDLETYPE handle;
59     CodecType codecType;
60     volatile CodecStatus codecStatus;
61     CodecCallback defaultCb;
62     bool hasCallback;
63 };
64 
65 struct CodecInstance* GetCodecInstance(void);
66 int32_t InitCodecInstance(struct CodecInstance *instance);
67 int32_t RunCodecInstance(struct CodecInstance *instance);
68 int32_t StopCodecInstance(struct CodecInstance *instance);
69 int32_t DestroyCodecInstance(struct CodecInstance *instance);
70 bool SetOemCodecBufferType(CodecBuffer *bufferToOemCodec, CodecBuffer *bufferInQueue);
71 int32_t AddInputShm(struct CodecInstance *instance, const CodecBufferInfo *bufferInfo, int32_t bufferId);
72 int32_t AddOutputShm(struct CodecInstance *instance, const CodecBufferInfo *bufferInfo, int32_t bufferId);
73 int32_t GetFdById(struct CodecInstance *instance, int32_t id);
74 void ReleaseInputShm(struct CodecInstance *instance);
75 void ReleaseOutputShm(struct CodecInstance *instance);
76 int32_t AddInputInfo(struct CodecInstance *instance, CodecBuffer *info);
77 int32_t AddOutputInfo(struct CodecInstance *instance, CodecBuffer *info);
78 CodecBuffer* GetInputInfo(struct CodecInstance *instance, uint32_t id);
79 CodecBuffer* GetOutputInfo(struct CodecInstance *instance, uint32_t id);
80 void ReleaseInputInfo(struct CodecInstance *instance);
81 void ReleaseOutputInfo(struct CodecInstance *instance);
82 void ResetBuffers(struct CodecInstance *instance);
83 void EmptyCodecBuffer(CodecBuffer *buf);
84 bool CopyCodecBufferWithTypeSwitch(struct CodecInstance *instance, CodecBuffer *dst,
85     const CodecBuffer *src, bool ignoreBuf);
86 CodecBuffer* DupCodecBuffer(const CodecBuffer *src);
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 #endif  // CODEC_INSTANCE_H
92