-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helpers.cpp
197 lines (150 loc) · 4.66 KB
/
Helpers.cpp
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//////////////////////////////////////////////////////////////////////////
//
// 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.
//
//
//////////////////////////////////////////////////////////////////////////
/* Modifications made from the sample EVR Presenter are covered under
*
* Copyright (C) 2014 Andrew Van Til
* http://babgvant.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "stdafx.h"
#include "EVRPresenter.h"
//-----------------------------------------------------------------------------
// SamplePool class
//-----------------------------------------------------------------------------
SamplePool::SamplePool() : m_bInitialized(FALSE), m_cPending(0)
{
}
SamplePool::~SamplePool()
{
}
//-----------------------------------------------------------------------------
// GetSample
//
// Gets a sample from the pool. If no samples are available, the method
// returns MF_E_SAMPLEALLOCATOR_EMPTY.
//-----------------------------------------------------------------------------
HRESULT SamplePool::GetSample(IMFSample **ppSample)
{
AutoLock lock(m_lock);
if (!m_bInitialized)
{
return MF_E_NOT_INITIALIZED;
}
if (m_VideoSampleQueue.IsEmpty())
{
return MF_E_SAMPLEALLOCATOR_EMPTY;
}
HRESULT hr = S_OK;
IMFSample *pSample = NULL;
// Get a sample from the allocated queue.
// It doesn't matter if we pull them from the head or tail of the list,
// but when we get it back, we want to re-insert it onto the opposite end.
// (see ReturnSample)
CHECK_HR(hr = m_VideoSampleQueue.RemoveFront(&pSample));
m_cPending++;
// Give the sample to the caller.
*ppSample = pSample;
(*ppSample)->AddRef();
done:
SAFE_RELEASE(pSample);
return hr;
}
//-----------------------------------------------------------------------------
// ReturnSample
//
// Returns a sample to the pool.
//-----------------------------------------------------------------------------
HRESULT SamplePool::ReturnSample(IMFSample *pSample)
{
AutoLock lock(m_lock);
if (!m_bInitialized)
{
return MF_E_NOT_INITIALIZED;
}
HRESULT hr = S_OK;
CHECK_HR(hr = m_VideoSampleQueue.InsertBack(pSample));
m_cPending--;
done:
return hr;
}
//-----------------------------------------------------------------------------
// AreSamplesPending
//
// Returns TRUE if any samples are in use.
//-----------------------------------------------------------------------------
BOOL SamplePool::AreSamplesPending()
{
AutoLock lock(m_lock);
if (!m_bInitialized)
{
return FALSE;
}
return (m_cPending > 0);
}
//-----------------------------------------------------------------------------
// Initialize
//
// Initializes the pool with a list of samples.
//-----------------------------------------------------------------------------
HRESULT SamplePool::Initialize(VideoSampleList& samples)
{
AutoLock lock(m_lock);
if (m_bInitialized)
{
return MF_E_INVALIDREQUEST;
}
HRESULT hr = S_OK;
IMFSample *pSample = NULL;
// Move these samples into our allocated queue.
VideoSampleList::POSITION pos = samples.FrontPosition();
while (pos != samples.EndPosition())
{
CHECK_HR(hr = samples.GetItemPos(pos, &pSample));
CHECK_HR(hr = m_VideoSampleQueue.InsertBack(pSample));
pos = samples.Next(pos);
SAFE_RELEASE(pSample);
}
m_bInitialized = TRUE;
done:
samples.Clear();
SAFE_RELEASE(pSample);
return hr;
}
//-----------------------------------------------------------------------------
// Clear
//
// Releases all samples.
//-----------------------------------------------------------------------------
HRESULT SamplePool::Clear()
{
HRESULT hr = S_OK;
AutoLock lock(m_lock);
m_VideoSampleQueue.Clear();
m_bInitialized = FALSE;
m_cPending = 0;
return S_OK;
}