summaryrefslogtreecommitdiff
path: root/sys/dshowsrcwrapper/gstdshowfakesink.cpp
blob: 2ef298c2f20b87d0875816361cd0b4bde2312d26 (plain)
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
/* GStreamer
 * Copyright (C) 2007 Sebastien Moutte <sebastien@moutte.net>
 *
 * gstdshowfakesink.cpp:
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "gstdshowfakesink.h"

CDshowFakeSink::CDshowFakeSink ():
m_hres (S_OK),
m_callback (NULL),
m_data (NULL),
CBaseRenderer (CLSID_DshowFakeSink, _T("DshowFakeSink"), NULL, &m_hres)
{
}

STDMETHODIMP CDshowFakeSink::gst_set_media_type (AM_MEDIA_TYPE * pmt)
{
  m_MediaType.Set (*pmt);
  return S_OK;
}

STDMETHODIMP
    CDshowFakeSink::gst_set_buffer_callback (push_buffer_func push,
    gpointer data)
{
  m_callback = push;
  m_data = data;
  return S_OK;
}

HRESULT CDshowFakeSink::CheckMediaType (const CMediaType * pmt)
{
  if (pmt != NULL) {
    if (*pmt == m_MediaType)
      return S_OK;
  }

  return S_FALSE;
}

HRESULT CDshowFakeSink::DoRenderSample (IMediaSample * pMediaSample)
{
  if (pMediaSample && m_callback) {
    guint8 *pBuffer = NULL;
    pMediaSample->GetPointer (&pBuffer);

    guint size = pMediaSample->GetActualDataLength ();

    GstClockTimeDiff lStart = 0;
    GstClockTimeDiff lStop = 0;
    pMediaSample->GetTime (&lStart, &lStop);

    GstClockTime duration = (lStop - lStart) * 100;
    m_callback (pBuffer, size, m_data, duration);
  }

  return S_OK;
}