• 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 BUFFER_MANAGER_H
17 #define BUFFER_MANAGER_H
18 
19 #include <queue>
20 #include <csignal>
21 #include <pthread.h>
22 #include "codec_type.h"
23 #include "osal_mutex.h"
24 
25 #define CODEC_STATUS_RUN        0
26 #define CODEC_STATUS_STOPPED    1
27 
28 #define HDF_NANO_UNITS 1000000000
29 
30 class BufferManager {
31 public:
32     BufferManager();
33     ~BufferManager();
34     void Stop();
35     CodecBuffer* GetBuffer(uint32_t timeoutMs, bool isChecking);
36     CodecBuffer* GetUsedBuffer(uint32_t timeoutMs, bool isChecking);
37     void PutBuffer(CodecBuffer *buffer);
38     void PutUsedBuffer(CodecBuffer *buffer);
39 
40 private:
41     void ConstructTimespec(struct timespec *time,  uint32_t timeoutMs);
42     CodecBuffer* PollBufferQueue(bool isChecking);
43     CodecBuffer* PollUsedBufferQueue(bool isChecking);
44 
45     int32_t status = 0;
46     OsalMutex bufferQueueLock;
47     OsalMutex usedBufferQueueLock;
48     pthread_cond_t inputCond = PTHREAD_COND_INITIALIZER;
49     pthread_cond_t outputCond = PTHREAD_COND_INITIALIZER;
50     std::queue<CodecBuffer*> bufferQueue;
51     std::queue<CodecBuffer*> usedBufferQueue;
52 };
53 
54 #endif  // BUFFER_MANAGER_H
55 
56