Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MyFilter.cpp « src - github.com/mpc-hc/sanear.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12711a7fc763dd7dbc5e803b7e33aaafcdf69fea (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
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
#include "pch.h"
#include "MyFilter.h"

#include "AudioRenderer.h"
#include "Factory.h"
#include "MyBasicAudio.h"
#include "MyPin.h"
#include "MyPropertyPage.h"

namespace SaneAudioRenderer
{
    MyFilter::MyFilter(ISettings* pSettings, HRESULT& result)
        : CBaseFilter("Audio Renderer", nullptr, this, Factory::GetFilterGuid())
        , m_bufferFilled(TRUE/*manual reset*/)
    {
        assert(result == S_OK);

        try
        {
            if (SUCCEEDED(result))
                m_clock = new MyClock(result);

            if (SUCCEEDED(result))
                m_renderer = std::make_unique<AudioRenderer>(pSettings, m_clock, m_bufferFilled, result);

            if (SUCCEEDED(result))
                m_basicAudio = new MyBasicAudio(*m_renderer);

            if (SUCCEEDED(result))
                m_pin = std::make_unique<MyPin>(*m_renderer, this, m_bufferFilled, result);

            if (SUCCEEDED(result))
                result = CreatePosPassThru(nullptr, FALSE, m_pin.get(), &m_seeking);
        }
        catch (std::bad_alloc&)
        {
            result = E_OUTOFMEMORY;
        }
    }

    STDMETHODIMP MyFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
    {
        if (riid == IID_IReferenceClock || riid == IID_IReferenceClockTimerControl)
            return m_clock->QueryInterface(riid, ppv);

        if (riid == IID_IBasicAudio)
            return m_basicAudio->QueryInterface(riid, ppv);

        if (riid == IID_IMediaSeeking)
            return m_seeking->QueryInterface(riid, ppv);

        if (riid == __uuidof(ISpecifyPropertyPages2))
            return GetInterface(static_cast<ISpecifyPropertyPages2*>(this), ppv);

        if (riid == IID_ISpecifyPropertyPages)
            return GetInterface(static_cast<ISpecifyPropertyPages*>(this), ppv);

        return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
    }

    int MyFilter::GetPinCount()
    {
        return 1;
    }

    CBasePin* MyFilter::GetPin(int n)
    {
        return (n == 0) ? m_pin.get() : nullptr;
    }

    STDMETHODIMP MyFilter::Stop()
    {
        return ChangeState<State_Stopped>(std::bind(&MyPin::Inactive, m_pin.get()));
    }

    STDMETHODIMP MyFilter::Pause()
    {
        return ChangeState<State_Paused>(std::bind(&MyPin::Active, m_pin.get()));
    }

    STDMETHODIMP MyFilter::Run(REFERENCE_TIME startTime)
    {
        return ChangeState<State_Running>(std::bind(&MyPin::Run, m_pin.get(), startTime));
    }

    STDMETHODIMP MyFilter::GetState(DWORD timeoutMilliseconds, FILTER_STATE* pState)
    {
        CheckPointer(pState, E_POINTER);

        CAutoLock objectLock(this);

        *pState = m_State;

        if (!m_pin->StateTransitionFinished(timeoutMilliseconds))
            return VFW_S_STATE_INTERMEDIATE;

        return S_OK;
    }

    STDMETHODIMP MyFilter::GetPages(CAUUID* pPages)
    {
        CheckPointer(pPages, E_POINTER);

        pPages->cElems = 1;
        pPages->pElems = (GUID*)CoTaskMemAlloc(sizeof(GUID));
        CheckPointer(pPages->pElems, E_OUTOFMEMORY);
        *pPages->pElems = __uuidof(MyPropertyPage);

        return S_OK;
    }

    STDMETHODIMP MyFilter::CreatePage(const GUID& guid, IPropertyPage** ppPage)
    {
        CheckPointer(ppPage, E_POINTER);

        if (guid != __uuidof(MyPropertyPage))
            return E_UNEXPECTED;

        MyPropertyPage* pPage;

        try
        {
            CAutoLock rendererLock(m_renderer.get());
            auto inputFormat = m_renderer->GetInputFormat();
            auto devicetFormat = m_renderer->GetDeviceFormat();
            pPage = new MyPropertyPage(inputFormat.get(), devicetFormat.get());
        }
        catch (std::bad_alloc&)
        {
            return E_OUTOFMEMORY;
        }

        pPage->AddRef();

        HRESULT result = pPage->QueryInterface(IID_PPV_ARGS(ppPage));

        pPage->Release();

        return result;
    }

    template <FILTER_STATE NewState, typename PinFunction>
    STDMETHODIMP MyFilter::ChangeState(PinFunction pinFunction)
    {
        CAutoLock objectLock(this);

        if (m_State != NewState)
        {
            ReturnIfFailed(pinFunction());
            m_State = NewState;
        }

        if (!m_pin->StateTransitionFinished(0))
            return S_FALSE;

        return S_OK;
    }
}