1 /* GStreamer
2  * Copyright (C) 2007 Sebastien Moutte <sebastien@moutte.net>
3  *
4  * gstdshowfakesink.cpp:
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include "gstdshowfakesink.h"
23 
CDshowFakeSink()24 CDshowFakeSink::CDshowFakeSink ():
25 m_hres (S_OK),
26 m_callback (NULL),
27 m_data (NULL),
28 CBaseRenderer (CLSID_DshowFakeSink, TEXT("DshowFakeSink"), NULL, &m_hres)
29 {
30 }
31 
gst_set_media_type(AM_MEDIA_TYPE * pmt)32 STDMETHODIMP CDshowFakeSink::gst_set_media_type (AM_MEDIA_TYPE * pmt)
33 {
34   m_MediaType.Set (*pmt);
35   return S_OK;
36 }
37 
38 STDMETHODIMP
gst_set_buffer_callback(push_buffer_func push,gpointer data)39     CDshowFakeSink::gst_set_buffer_callback (push_buffer_func push,
40     gpointer data)
41 {
42   m_callback = push;
43   m_data = data;
44   return S_OK;
45 }
46 
CheckMediaType(const CMediaType * pmt)47 HRESULT CDshowFakeSink::CheckMediaType (const CMediaType * pmt)
48 {
49   if (!IsEqualGUID(pmt->majortype, m_MediaType.majortype) ||
50       !IsEqualGUID(pmt->subtype, m_MediaType.subtype) ||
51       !IsEqualGUID(pmt->formattype, m_MediaType.formattype) ||
52       (pmt->cbFormat != m_MediaType.cbFormat))
53     return S_FALSE;
54 
55   VIDEOINFOHEADER *info1 = (VIDEOINFOHEADER*)pmt->pbFormat;
56   VIDEOINFOHEADER *info2 = (VIDEOINFOHEADER*)m_MediaType.pbFormat;
57 
58   if (memcmp(&info1->bmiHeader, &info2->bmiHeader, sizeof(BITMAPINFOHEADER)))
59     return S_FALSE;
60 
61   return S_OK;
62 }
63 
DoRenderSample(IMediaSample * pMediaSample)64 HRESULT CDshowFakeSink::DoRenderSample (IMediaSample * pMediaSample)
65 {
66   if (pMediaSample && m_callback) {
67     guint8 *pBuffer = NULL;
68     pMediaSample->GetPointer (&pBuffer);
69 
70     guint size = pMediaSample->GetActualDataLength ();
71 
72     GstClockTimeDiff lStart = 0;
73     GstClockTimeDiff lStop = 0;
74     pMediaSample->GetTime (&lStart, &lStop);
75 
76     GstClockTime duration = (lStop - lStart) * 100;
77     m_callback (pBuffer, size, m_data, duration);
78   }
79 
80   return S_OK;
81 }
82