Sweden-Number/dlls/qcap/filewriter.c

103 lines
2.9 KiB
C

/*
* File writer filter
*
* Copyright (C) 2020 Zebediah Figura
*
* 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
*/
#define COBJMACROS
#include "dshow.h"
#include "qcap_main.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(qcap);
struct file_writer
{
struct strmbase_filter filter;
struct strmbase_sink sink;
};
static inline struct file_writer *impl_from_strmbase_pin(struct strmbase_pin *iface)
{
return CONTAINING_RECORD(iface, struct file_writer, sink.pin);
}
static HRESULT file_writer_sink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
{
struct file_writer *filter = impl_from_strmbase_pin(iface);
if (IsEqualGUID(iid, &IID_IMemInputPin))
*out = &filter->sink.IMemInputPin_iface;
else
return E_NOINTERFACE;
IUnknown_AddRef((IUnknown *)*out);
return S_OK;
}
static const struct strmbase_sink_ops sink_ops =
{
.base.pin_query_interface = file_writer_sink_query_interface,
};
static inline struct file_writer *impl_from_strmbase_filter(struct strmbase_filter *iface)
{
return CONTAINING_RECORD(iface, struct file_writer, filter);
}
static struct strmbase_pin *file_writer_get_pin(struct strmbase_filter *iface, unsigned int index)
{
struct file_writer *filter = impl_from_strmbase_filter(iface);
if (!index)
return &filter->sink.pin;
return NULL;
}
static void file_writer_destroy(struct strmbase_filter *iface)
{
struct file_writer *filter = impl_from_strmbase_filter(iface);
strmbase_sink_cleanup(&filter->sink);
strmbase_filter_cleanup(&filter->filter);
heap_free(filter);
}
static struct strmbase_filter_ops filter_ops =
{
.filter_get_pin = file_writer_get_pin,
.filter_destroy = file_writer_destroy,
};
HRESULT file_writer_create(IUnknown *outer, IUnknown **out)
{
static const WCHAR sink_name[] = {'i','n',0};
struct file_writer *object;
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
strmbase_filter_init(&object->filter, outer, &CLSID_FileWriter, &filter_ops);
strmbase_sink_init(&object->sink, &object->filter, sink_name, &sink_ops, NULL);
TRACE("Created file writer %p.\n", object);
*out = &object->filter.IUnknown_inner;
return S_OK;
}