nullrenderer.c 6.9 KB
Newer Older
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
/*
 * Null Renderer (Promiscuous, not rendering anything at all!)
 *
 * Copyright 2004 Christian Costa
 * Copyright 2008 Maarten Lankhorst
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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 "config.h"

#define NONAMELESSSTRUCT
#define NONAMELESSUNION
#include "quartz_private.h"
#include "pin.h"

#include "uuids.h"
#include "vfwmsgs.h"
#include "amvideo.h"
#include "windef.h"
#include "winbase.h"
#include "dshow.h"
#include "evcode.h"
#include "strmif.h"
#include "ddraw.h"

#include "wine/unicode.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(quartz);

typedef struct NullRendererImpl
{
46
    BaseRenderer renderer;
47
    IUnknown IUnknown_inner;
48
    IAMFilterMiscFlags IAMFilterMiscFlags_iface;
49
    IUnknown *outer_unk;
50 51
} NullRendererImpl;

52
static HRESULT WINAPI NullRenderer_DoRenderSample(BaseRenderer *iface, IMediaSample *pMediaSample)
53
{
54
    return S_OK;
55 56
}

57
static HRESULT WINAPI NullRenderer_CheckMediaType(BaseRenderer *iface, const AM_MEDIA_TYPE * pmt)
58 59 60 61 62
{
    TRACE("Not a stub!\n");
    return S_OK;
}

63
static const BaseRendererFuncTable RendererFuncTable = {
64
    NullRenderer_CheckMediaType,
65
    NullRenderer_DoRenderSample,
66
    /**/
67 68 69 70 71 72 73 74 75 76
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
77 78 79 80
    /**/
    NULL,
    NULL,
    NULL,
81
    NULL,
82
    NULL,
83 84
};

85
static inline NullRendererImpl *impl_from_IUnknown(IUnknown *iface)
86
{
87 88 89 90 91 92
    return CONTAINING_RECORD(iface, NullRendererImpl, IUnknown_inner);
}

static HRESULT WINAPI NullRendererInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
{
    NullRendererImpl *This = impl_from_IUnknown(iface);
93

94
    TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
95 96 97 98

    *ppv = NULL;

    if (IsEqualIID(riid, &IID_IUnknown))
99
        *ppv = &This->IUnknown_inner;
100
    else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
101
        *ppv = &This->IAMFilterMiscFlags_iface;
102 103 104 105 106 107 108
    else
    {
        HRESULT hr;
        hr = BaseRendererImpl_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppv);
        if (SUCCEEDED(hr))
            return hr;
    }
109 110 111

    if (*ppv)
    {
112
        IUnknown_AddRef((IUnknown *)*ppv);
113 114 115
        return S_OK;
    }

116
    if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
117
        FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
118 119 120 121

    return E_NOINTERFACE;
}

122
static ULONG WINAPI NullRendererInner_AddRef(IUnknown *iface)
123
{
124
    NullRendererImpl *This = impl_from_IUnknown(iface);
125
    return BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
126 127
}

128
static ULONG WINAPI NullRendererInner_Release(IUnknown *iface)
129
{
130 131
    NullRendererImpl *This = impl_from_IUnknown(iface);
    ULONG refCount = BaseFilterImpl_Release(&This->renderer.filter.IBaseFilter_iface);
132 133 134 135 136 137

    if (!refCount)
    {
        TRACE("Destroying Null Renderer\n");
        CoTaskMemFree(This);
    }
138 139

    return refCount;
140 141 142 143 144 145 146 147 148
}

static const IUnknownVtbl IInner_VTable =
{
    NullRendererInner_QueryInterface,
    NullRendererInner_AddRef,
    NullRendererInner_Release
};

149 150 151 152 153
static inline NullRendererImpl *impl_from_IBaseFilter(IBaseFilter *iface)
{
    return CONTAINING_RECORD(iface, NullRendererImpl, renderer.filter.IBaseFilter_iface);
}

154 155
static HRESULT WINAPI NullRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
{
156
    NullRendererImpl *This = impl_from_IBaseFilter(iface);
157
    return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
158 159 160 161
}

static ULONG WINAPI NullRenderer_AddRef(IBaseFilter * iface)
{
162
    NullRendererImpl *This = impl_from_IBaseFilter(iface);
163
    return IUnknown_AddRef(This->outer_unk);
164 165 166 167
}

static ULONG WINAPI NullRenderer_Release(IBaseFilter * iface)
{
168
    NullRendererImpl *This = impl_from_IBaseFilter(iface);
169
    return IUnknown_Release(This->outer_unk);
170 171 172 173 174 175 176
}

static const IBaseFilterVtbl NullRenderer_Vtbl =
{
    NullRenderer_QueryInterface,
    NullRenderer_AddRef,
    NullRenderer_Release,
177
    BaseFilterImpl_GetClassID,
178 179 180
    BaseRendererImpl_Stop,
    BaseRendererImpl_Pause,
    BaseRendererImpl_Run,
181
    BaseRendererImpl_GetState,
182
    BaseRendererImpl_SetSyncSource,
183
    BaseFilterImpl_GetSyncSource,
184
    BaseFilterImpl_EnumPins,
185
    BaseRendererImpl_FindPin,
186 187 188
    BaseFilterImpl_QueryFilterInfo,
    BaseFilterImpl_JoinFilterGraph,
    BaseFilterImpl_QueryVendorInfo
189 190
};

191 192 193
static NullRendererImpl *impl_from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface)
{
    return CONTAINING_RECORD(iface, NullRendererImpl, IAMFilterMiscFlags_iface);
194 195
}

196 197 198 199
static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, REFIID riid,
        void **ppv)
{
    NullRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
200
    return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
201 202
}

203 204 205
static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface)
{
    NullRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
206
    return IUnknown_AddRef(This->outer_unk);
207 208
}

209 210 211
static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface)
{
    NullRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
212
    return IUnknown_Release(This->outer_unk);
213 214
}

215 216
static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface)
{
217 218 219 220 221 222 223 224 225
    return AM_FILTER_MISC_FLAGS_IS_RENDERER;
}

static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
    AMFilterMiscFlags_QueryInterface,
    AMFilterMiscFlags_AddRef,
    AMFilterMiscFlags_Release,
    AMFilterMiscFlags_GetMiscFlags
};
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258

HRESULT NullRenderer_create(IUnknown *pUnkOuter, void **ppv)
{
    HRESULT hr;
    NullRendererImpl *pNullRenderer;

    TRACE("(%p, %p)\n", pUnkOuter, ppv);

    *ppv = NULL;

    pNullRenderer = CoTaskMemAlloc(sizeof(NullRendererImpl));
    pNullRenderer->IUnknown_inner.lpVtbl = &IInner_VTable;
    pNullRenderer->IAMFilterMiscFlags_iface.lpVtbl = &IAMFilterMiscFlags_Vtbl;

    if (pUnkOuter)
        pNullRenderer->outer_unk = pUnkOuter;
    else
        pNullRenderer->outer_unk = &pNullRenderer->IUnknown_inner;

    hr = BaseRenderer_Init(&pNullRenderer->renderer, &NullRenderer_Vtbl, pUnkOuter,
            &CLSID_NullRenderer, (DWORD_PTR)(__FILE__ ": NullRendererImpl.csFilter"),
            &RendererFuncTable);

    if (FAILED(hr))
    {
        BaseRendererImpl_Release(&pNullRenderer->renderer.filter.IBaseFilter_iface);
        CoTaskMemFree(pNullRenderer);
    }
    else
        *ppv = &pNullRenderer->IUnknown_inner;

    return S_OK;
}