-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Helpers.h
98 lines (79 loc) · 2.31 KB
/
Helpers.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
//////////////////////////////////////////////////////////////////////////
//
// Helpers.cpp : Miscellaneous helpers.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
//////////////////////////////////////////////////////////////////////////
#pragma once
//-----------------------------------------------------------------------------
// SamplePool class
//
// Manages a list of allocated samples.
//-----------------------------------------------------------------------------
class SamplePool
{
public:
SamplePool();
virtual ~SamplePool();
HRESULT Initialize(VideoSampleList& samples);
HRESULT Clear();
HRESULT GetSample(IMFSample **ppSample); // Does not block.
HRESULT ReturnSample(IMFSample *pSample);
BOOL AreSamplesPending();
private:
CritSec m_lock;
VideoSampleList m_VideoSampleQueue; // Available queue
BOOL m_bInitialized;
DWORD m_cPending;
};
//-----------------------------------------------------------------------------
// ThreadSafeQueue template
// Thread-safe queue of COM interface pointers.
//
// T: COM interface type.
//
// This class is used by the scheduler.
//
// Note: This class uses a critical section to protect the state of the queue.
// With a little work, the scheduler could probably use a lock-free queue.
//-----------------------------------------------------------------------------
template <class T>
class ThreadSafeQueue
{
public:
HRESULT Queue(T *p)
{
AutoLock lock(m_lock);
return m_list.InsertBack(p);
}
HRESULT Dequeue(T **pp)
{
AutoLock lock(m_lock);
if (m_list.IsEmpty())
{
*pp = NULL;
return S_FALSE;
}
return m_list.RemoveFront(pp);
}
HRESULT PutBack(T *p)
{
AutoLock lock(m_lock);
return m_list.InsertFront(p);
}
void Clear()
{
AutoLock lock(m_lock);
m_list.Clear();
}
private:
CritSec m_lock;
ComPtrList<T> m_list;
};