ReactOS  0.4.14-dev-358-gbef841c
mediasample.cpp
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS WDM Streaming ActiveMovie Proxy
4  * FILE: dll/directx/ksproxy/mediasample.cpp
5  * PURPOSE: IMediaSample interface
6  *
7  * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 #include "precomp.h"
10 
11 class CMediaSample : public IMediaSample
12 {
13 public:
15 
17  {
19  return m_Ref;
20  }
22  {
24  if (!m_Ref)
25  {
26  if (m_Allocator)
27  {
29  return 0;
30  }
31  delete this;
32  return 0;
33  }
34  return m_Ref;
35  }
36 
38  long STDMETHODCALLTYPE GetSize(void);
51  HRESULT STDMETHODCALLTYPE GetMediaTime(LONGLONG *pTimeStart, LONGLONG *pTimeEnd);
52  HRESULT STDMETHODCALLTYPE SetMediaTime(LONGLONG *pTimeStart, LONGLONG *pTimeEnd);
53 
55  virtual ~CMediaSample(){}
56 
57 protected:
71 
72 public:
74 
76 
77 
78 };
79 
81  IMemAllocator * Allocator,
82  BYTE * Buffer,
83  LONG BufferSize) :
84  m_Flags(0),
85  m_TypeFlags(0),
86  m_Buffer(Buffer),
87  m_ActualLength(BufferSize),
88  m_BufferSize(BufferSize),
89  m_Allocator(Allocator),
90  m_Next(0),
91  m_StartTime(0),
92  m_StopTime(0),
93  m_MediaStart(0),
94  m_MediaStop(0),
95  m_MediaType(0),
96  m_StreamId(0),
97  m_Ref(0),
98  m_bMediaTimeValid(0)
99 {
100 }
101 
102 
103 HRESULT
106  IN REFIID refiid,
107  OUT PVOID* Output)
108 {
109  if (IsEqualGUID(refiid, IID_IUnknown) ||
110  IsEqualGUID(refiid, IID_IMediaSample))
111  {
112  *Output = PVOID(this);
113  reinterpret_cast<IMediaSample*>(*Output)->AddRef();
114  return NOERROR;
115  }
116  if (IsEqualGUID(refiid, IID_IMediaSample2))
117  {
118 #if 0
119  *Output = (IMediaSample2*)(this);
120  reinterpret_cast<IMediaSample2*>(*Output)->AddRef();
121  return NOERROR;
122 #endif
123  }
124 
125  return E_NOINTERFACE;
126 }
127 
128 //-------------------------------------------------------------------
129 // IMediaSample interface
130 //
131 HRESULT
134  BYTE **ppBuffer)
135 {
136  if (!ppBuffer)
137  return E_POINTER;
138 
139  *ppBuffer = m_Buffer;
140  return S_OK;
141 }
142 
143 long
146 {
147  return m_BufferSize;
148 }
149 
150 HRESULT
153  REFERENCE_TIME *pTimeStart,
154  REFERENCE_TIME *pTimeEnd)
155 {
156  HRESULT hr;
157 
158  if (!pTimeStart || !pTimeEnd)
159  return E_POINTER;
160 
162  {
163  // no time is set
165  }
166 
167  *pTimeStart = m_StartTime;
168 
170  {
171  *pTimeEnd = m_StopTime;
172  hr = NOERROR;
173  }
174  else
175  {
176  *pTimeEnd = m_StartTime + 1;
178  }
179  return hr;
180 }
181 
182 HRESULT
185 {
186  if (!pTimeStart)
187  {
189  return NOERROR;
190  }
191 
192  if (!pTimeEnd)
193  {
196  m_StartTime = *pTimeStart;
197  return NOERROR;
198  }
199 
200 
202  m_StartTime = *pTimeStart;
203  m_StopTime = *pTimeEnd;
204 
205  return NOERROR;
206 }
207 
208 HRESULT
211 {
212  return (m_Flags & AM_SAMPLE_SPLICEPOINT) ? S_OK : S_FALSE;
213 }
214 HRESULT
217 {
218  if (bIsSyncPoint)
220  else
222 
223  return NOERROR;
224 }
225 
226 HRESULT
229 {
230  return (m_Flags & AM_SAMPLE_PREROLL) ? S_OK : S_FALSE;
231 }
232 
233 HRESULT
236 {
237  if (bIsPreroll)
239  else
241 
242  return NOERROR;
243 }
244 
245 long
248 {
249  return m_ActualLength;
250 }
251 
252 HRESULT
255 {
256  if (Length > m_BufferSize)
257  return VFW_E_BUFFER_OVERFLOW;
258 
260  return NOERROR;
261 }
262 
263 HRESULT
266 {
267  if (!m_MediaType)
268  {
269  *ppMediaType = NULL;
270  return S_FALSE;
271  }
272 
273  assert(0);
274  return E_NOTIMPL;
275 }
276 
277 HRESULT
280 {
281  OutputDebugStringW(L"CMediaSample::SetMediaType NotImplemented\n");
282  return E_NOTIMPL;
283 }
284 
285 
286 HRESULT
289 {
291 }
292 
293 HRESULT
296 {
297  if (bDiscontinuity)
299  else
301 
302  return NOERROR;
303 }
304 
305 HRESULT
308 {
309  if (!pTimeStart || !pTimeEnd)
310  return E_POINTER;
311 
312  if (!m_bMediaTimeValid)
314 
315  m_MediaStart = *pTimeStart;
316  m_MediaStop = *pTimeEnd;
317 
318  return NOERROR;
319 }
320 
321 HRESULT
324 {
325  if (!pTimeStart || !pTimeEnd)
326  {
327  m_bMediaTimeValid = false;
328  return NOERROR;
329  }
330 
331  m_MediaStart = *pTimeStart;
332  m_MediaStop = *pTimeEnd;
333 
334  return NOERROR;
335 }
336 
337 
338 
339 
340 HRESULT
341 WINAPI
343  IMemAllocator* Allocator,
344  BYTE* pBuffer,
346  REFIID riid,
347  LPVOID * ppv)
348 {
349 #ifdef KSPROXY_TRACE
350  OutputDebugStringW(L"CMediaSample_Constructor\n");
351 #endif
352 
353  CMediaSample * handler = new CMediaSample(Allocator, pBuffer, BufferSize);
354 
355  if (!handler)
356  return E_OUTOFMEMORY;
357 
358  if (FAILED(handler->QueryInterface(riid, ppv)))
359  {
360  /* not supported */
361  delete handler;
362  return E_NOINTERFACE;
363  }
364 
365  return NOERROR;
366 }
#define IN
Definition: typedefs.h:38
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
ULONG m_StreamId
Definition: mediasample.cpp:70
HRESULT hr
Definition: shlfolder.c:183
#define NOERROR
Definition: winerror.h:2354
HRESULT STDMETHODCALLTYPE IsPreroll()
REFIID riid
Definition: precomp.h:44
IMemAllocator * m_Allocator
Definition: mediasample.cpp:63
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT STDMETHODCALLTYPE SetActualDataLength(long Length)
HRESULT STDMETHODCALLTYPE SetTime(REFERENCE_TIME *pTimeStart, REFERENCE_TIME *pTimeEnd)
HRESULT STDMETHODCALLTYPE GetMediaType(AM_MEDIA_TYPE **ppMediaType)
#define assert(x)
Definition: debug.h:53
#define VFW_E_SAMPLE_TIME_NOT_SET
Definition: vfwmsgs.h:104
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
HRESULT STDMETHODCALLTYPE GetMediaTime(LONGLONG *pTimeStart, LONGLONG *pTimeEnd)
LONG m_ActualLength
Definition: mediasample.cpp:61
void WINAPI SHIM_OBJ_NAME() OutputDebugStringW(LPCWSTR lpOutputString)
Definition: ignoredbgout.c:23
STDMETHODIMP_(ULONG) Release()
Definition: mediasample.cpp:21
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
HRESULT WINAPI CMediaSample_Constructor(IMemAllocator *Allocator, BYTE *pBuffer, ULONG BufferSize, REFIID riid, LPVOID *ppv)
#define STDMETHODIMP
Definition: basetyps.h:43
virtual ~CMediaSample()
Definition: mediasample.cpp:55
ULONG Release()
HRESULT STDMETHODCALLTYPE IsDiscontinuity()
#define S_FALSE
Definition: winerror.h:2357
HRESULT STDMETHODCALLTYPE SetDiscontinuity(BOOL bDiscontinuity)
ULONG m_TypeFlags
Definition: mediasample.cpp:59
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
HRESULT STDMETHODCALLTYPE SetPreroll(BOOL bIsPreroll)
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
STDMETHODIMP_(ULONG) AddRef()
Definition: mediasample.cpp:16
LONGLONG m_MediaStop
Definition: mediasample.cpp:68
BYTE * m_Buffer
Definition: mediasample.cpp:60
int64_t LONGLONG
Definition: typedefs.h:66
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
long STDMETHODCALLTYPE GetActualDataLength()
LONGLONG REFERENCE_TIME
Definition: dmusicks.h:9
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define BufferSize
Definition: classpnp.h:419
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ULONG AddRef()
long STDMETHODCALLTYPE GetSize(void)
#define VFW_E_BUFFER_OVERFLOW
Definition: vfwmsgs.h:52
static const WCHAR L[]
Definition: oid.c:1250
#define InterlockedDecrement
Definition: armddk.h:52
Definition: arc.h:85
HRESULT STDMETHODCALLTYPE GetTime(REFERENCE_TIME *pTimeStart, REFERENCE_TIME *pTimeEnd)
LONGLONG m_MediaStart
Definition: mediasample.cpp:67
unsigned char BYTE
Definition: mem.h:68
HRESULT ReleaseBuffer([in] IMediaSample *pBuffer)
#define VFW_E_MEDIA_TIME_NOT_SET
Definition: vfwmsgs.h:105
HRESULT STDMETHODCALLTYPE GetPointer(BYTE **ppBuffer)
#define S_OK
Definition: intsafe.h:59
HRESULT STDMETHODCALLTYPE SetMediaTime(LONGLONG *pTimeStart, LONGLONG *pTimeEnd)
#define InterlockedIncrement
Definition: armddk.h:53
CMediaSample(IMemAllocator *Allocator, BYTE *Buffer, LONG BufferSize)
Definition: mediasample.cpp:80
AM_MEDIA_TYPE * m_MediaType
Definition: mediasample.cpp:69
#define E_NOTIMPL
Definition: ddrawi.h:99
REFERENCE_TIME m_StopTime
Definition: mediasample.cpp:66
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define VFW_S_NO_STOP_TIME
Definition: vfwmsgs.h:34
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786
BOOL m_bMediaTimeValid
Definition: mediasample.cpp:75
CMediaSample * m_Next
Definition: mediasample.cpp:64
#define E_POINTER
Definition: winerror.h:2365
REFERENCE_TIME m_StartTime
Definition: mediasample.cpp:65
HRESULT STDMETHODCALLTYPE IsSyncPoint()
HRESULT STDMETHODCALLTYPE SetMediaType(AM_MEDIA_TYPE *pMediaType)
HRESULT STDMETHODCALLTYPE SetSyncPoint(BOOL bIsSyncPoint)