• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "osal_mutex.h"
25 #include "share_mem.h"
26 #ifndef CODEC_HAL_PASSTHROUGH
27 #include "codec_callback.h"
28 #endif
29 
30 #define MAX_BUFFER_NUM              64
31 #define QUEUE_TIME_OUT              10
32 #define NO_TRANSMIT_FD              (-1)
33 #define NO_TRANSMIT_BUFFERHANDLE    0
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
40 typedef enum {
41     CODEC_STATUS_IDLE,
42     CODEC_STATUS_STARTED,
43     CODEC_STATUS_STOPPING,
44     CODEC_STATUS_STOPPED,
45 } CodecStatus;
46 
47 struct CodecInstance {
48     pthread_attr_t codecTaskAttr;
49     pthread_t codecTask;
50     pthread_attr_t codecCallbackTaskAttr;
51     pthread_t codecCallbackTask;
52     ShareMemory inputBuffers[MAX_BUFFER_NUM];
53     ShareMemory outputBuffers[MAX_BUFFER_NUM];
54     int32_t inputBuffersCount;
55     int32_t outputBuffersCount;
56     CodecBuffer *inputInfos[MAX_BUFFER_NUM];
57     CodecBuffer *outputInfos[MAX_BUFFER_NUM];
58     int32_t inputInfoCount;
59     int32_t outputInfoCount;
60     volatile bool inputEos;
61 
62     void *oemLibHandle;
63     struct CodecOemIf *codecOemIface;
64 
65     struct BufferManagerWrapper *bufferManagerWrapper;
66 
67     CODEC_HANDLETYPE handle;
68     CodecType codecType;
69     volatile CodecStatus codecStatus;
70     struct OsalMutex codecStatusLock;
71     pthread_cond_t codecStatusCond;
72     volatile CodecStatus codecCallbackStatus;
73     struct OsalMutex codecCallbackStatusLock;
74     pthread_cond_t codecCallbackStatusCond;
75 #ifndef CODEC_HAL_PASSTHROUGH
76     struct ICodecCallbackProxy *callbackProxy;
77 #else
78     CodecCallback *codecCallback;
79 #endif
80     CodecCallback defaultCb;
81     bool hasCustomerCallback;
82     UINTPTR callbackUserData;
83 };
84 
85 struct CodecInstance* GetCodecInstance(void);
86 int32_t InitCodecInstance(struct CodecInstance *instance, struct CodecOemIf *oemIf);
87 int32_t RunCodecInstance(struct CodecInstance *instance);
88 int32_t StopCodecInstance(struct CodecInstance *instance);
89 int32_t DestroyCodecInstance(struct CodecInstance *instance);
90 bool SetOemCodecBufferType(CodecBuffer *bufferToOemCodec, CodecBuffer *bufferInQueue);
91 int32_t AddInputShm(struct CodecInstance *instance, const CodecBufferInfo *bufferInfo, int32_t bufferId);
92 int32_t AddOutputShm(struct CodecInstance *instance, const CodecBufferInfo *bufferInfo, int32_t bufferId);
93 int32_t GetFdById(struct CodecInstance *instance, int32_t id);
94 void ReleaseInputShm(struct CodecInstance *instance);
95 void ReleaseOutputShm(struct CodecInstance *instance);
96 int32_t AddInputInfo(struct CodecInstance *instance, CodecBuffer *info);
97 int32_t AddOutputInfo(struct CodecInstance *instance, CodecBuffer *info);
98 CodecBuffer* GetInputInfo(struct CodecInstance *instance, uint32_t id);
99 CodecBuffer* GetOutputInfo(struct CodecInstance *instance, uint32_t id);
100 void ReleaseInputInfo(struct CodecInstance *instance);
101 void ReleaseOutputInfo(struct CodecInstance *instance);
102 void ResetBuffers(struct CodecInstance *instance);
103 void EmptyCodecBuffer(CodecBuffer *buf);
104 bool CopyCodecBufferWithTypeSwitch(struct CodecInstance *instance, CodecBuffer *dst,
105     const CodecBuffer *src, bool ignoreBuf);
106 CodecBuffer* DupCodecBuffer(const CodecBuffer *src);
107 void ReleaseCodecBuffer(CodecBuffer *info);
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 #endif  // CODEC_INSTANCE_H
113