-
Notifications
You must be signed in to change notification settings - Fork 1
/
FrameQueue.h
executable file
·133 lines (99 loc) · 3.15 KB
/
FrameQueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef _FRAME_QUEUE
#define _FRAME_QUEUE
/*
* Copyright 1993-2017 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
#include "dynlink_nvcuvid.h" // <nvcuvid.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <string.h>
#include <pthread.h>
typedef pthread_mutex_t CRITICAL_SECTION;
typedef void* HANDLE;
#define Sleep(x) usleep(1000*x);
#endif
#define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
class FrameQueue
{
public:
static const unsigned int cnMaximumSize = 20; // MAX_FRM_CNT;
FrameQueue(CUvideoctxlock ctxLock);
virtual
~FrameQueue();
void
waitForQueueUpdate();
void
enter_CS(CRITICAL_SECTION *pCS);
void
leave_CS(CRITICAL_SECTION *pCS);
void
set_event(HANDLE event);
void
reset_event(HANDLE event);
virtual void
init(int frameWidth, int frameHeight) { }
virtual void
enqueue(const void * pData) = 0;
// Deque the next frame.
// Parameters:
// pDisplayInfo - New frame info gets placed into this object.
// Note: This pointer must point to a valid struct. The method
// does not create memory for this.
// Returns:
// true, if a new frame was returned,
// false, if the queue was empty and no new frame could be returned.
// In that case, pPicParams doesn't contain valid data.
virtual bool
dequeue(void * pData) = 0;
virtual void
releaseFrame(const void * pPicParams) = 0;
bool
isInUse(int nPictureIndex)
const;
bool
isEndOfDecode()
const;
void
endDecode();
// Spins until frame becomes available or decoding
// gets canceled.
// If the requested frame is available the method returns true.
// If decoding was interupted before the requested frame becomes
// available, the method returns false.
bool
waitUntilFrameAvailable(int nPictureIndex);
size_t getPitch() { return nPitch; }
bool isEmpty() { return nFramesInQueue_ == 0; }
protected:
void
signalStatusChange();
HANDLE hEvent_;
CRITICAL_SECTION oCriticalSection_;
volatile int nReadPosition_;
volatile int nWritePosition_;
volatile int nFramesInQueue_;
volatile int aIsFrameInUse_[cnMaximumSize];
volatile int bEndOfDecode_;
CUvideoctxlock m_ctxLock;
size_t nPitch;
};
class CUVIDFrameQueue: public FrameQueue {
public:
CUVIDFrameQueue(CUvideoctxlock ctxLock);
~CUVIDFrameQueue();
virtual void enqueue(const void * pData);
virtual bool dequeue(void * pData);
virtual void releaseFrame(const void * pPicParams);
protected:
CUVIDPARSERDISPINFO aDisplayQueue_[cnMaximumSize];
};
#endif