4 * Copyright 2020 Jactry Zeng for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "qasf_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(qasf
);
27 struct strmbase_filter filter
;
28 IFileSourceFilter IFileSourceFilter_iface
;
34 static inline struct asf_reader
*impl_reader_from_strmbase_filter(struct strmbase_filter
*iface
)
36 return CONTAINING_RECORD(iface
, struct asf_reader
, filter
);
39 static struct strmbase_pin
*asf_reader_get_pin(struct strmbase_filter
*iface
, unsigned int index
)
44 static void asf_reader_destroy(struct strmbase_filter
*iface
)
46 struct asf_reader
*filter
= impl_reader_from_strmbase_filter(iface
);
48 free(filter
->filename
);
49 FreeMediaType(&filter
->type
);
51 strmbase_filter_cleanup(&filter
->filter
);
55 static HRESULT
asf_reader_query_interface(struct strmbase_filter
*iface
, REFIID iid
, void **out
)
57 struct asf_reader
*filter
= impl_reader_from_strmbase_filter(iface
);
59 if (IsEqualGUID(iid
, &IID_IFileSourceFilter
))
61 *out
= &filter
->IFileSourceFilter_iface
;
62 IUnknown_AddRef((IUnknown
*)*out
);
69 static struct strmbase_filter_ops filter_ops
=
71 .filter_get_pin
= asf_reader_get_pin
,
72 .filter_destroy
= asf_reader_destroy
,
73 .filter_query_interface
= asf_reader_query_interface
,
76 static inline struct asf_reader
*impl_from_IFileSourceFilter(IFileSourceFilter
*iface
)
78 return CONTAINING_RECORD(iface
, struct asf_reader
, IFileSourceFilter_iface
);
81 static HRESULT WINAPI
filesourcefilter_QueryInterface(IFileSourceFilter
*iface
, REFIID iid
, void **out
)
83 struct asf_reader
*filter
= impl_from_IFileSourceFilter(iface
);
85 return IBaseFilter_QueryInterface(&filter
->filter
.IBaseFilter_iface
, iid
, out
);
88 static ULONG WINAPI
filesourcefilter_AddRef(IFileSourceFilter
*iface
)
90 struct asf_reader
*filter
= impl_from_IFileSourceFilter(iface
);
92 return IBaseFilter_AddRef(&filter
->filter
.IBaseFilter_iface
);
95 static ULONG WINAPI
filesourcefilter_Release(IFileSourceFilter
*iface
)
97 struct asf_reader
*filter
= impl_from_IFileSourceFilter(iface
);
99 return IBaseFilter_Release(&filter
->filter
.IBaseFilter_iface
);
102 static HRESULT WINAPI
filesourcefilter_Load(IFileSourceFilter
*iface
, LPCOLESTR filename
, const AM_MEDIA_TYPE
*type
)
104 struct asf_reader
*filter
= impl_from_IFileSourceFilter(iface
);
106 TRACE("filter %p, filename %s, type %p.\n", filter
, debugstr_w(filename
), type
);
107 strmbase_dump_media_type(type
);
112 if (filter
->filename
)
115 if (!(filter
->filename
= wcsdup(filename
)))
116 return E_OUTOFMEMORY
;
119 CopyMediaType(&filter
->type
, type
);
124 static HRESULT WINAPI
filesourcefilter_GetCurFile(IFileSourceFilter
*iface
, LPOLESTR
*filename
, AM_MEDIA_TYPE
*type
)
126 struct asf_reader
*filter
= impl_from_IFileSourceFilter(iface
);
128 TRACE("filter %p, filename %p, type %p.\n", filter
, filename
, type
);
136 type
->majortype
= filter
->type
.majortype
;
137 type
->subtype
= filter
->type
.subtype
;
138 type
->lSampleSize
= filter
->type
.lSampleSize
;
139 type
->pUnk
= filter
->type
.pUnk
;
140 type
->cbFormat
= filter
->type
.cbFormat
;
143 if (filter
->filename
)
145 *filename
= CoTaskMemAlloc((wcslen(filter
->filename
) + 1) * sizeof(WCHAR
));
146 wcscpy(*filename
, filter
->filename
);
152 static const IFileSourceFilterVtbl filesourcefilter_vtbl
=
154 filesourcefilter_QueryInterface
,
155 filesourcefilter_AddRef
,
156 filesourcefilter_Release
,
157 filesourcefilter_Load
,
158 filesourcefilter_GetCurFile
,
161 HRESULT
asf_reader_create(IUnknown
*outer
, IUnknown
**out
)
163 struct asf_reader
*object
;
165 if (!(object
= calloc(1, sizeof(*object
))))
166 return E_OUTOFMEMORY
;
168 strmbase_filter_init(&object
->filter
, outer
, &CLSID_WMAsfReader
, &filter_ops
);
169 object
->IFileSourceFilter_iface
.lpVtbl
= &filesourcefilter_vtbl
;
171 TRACE("Created WM ASF reader %p.\n", object
);
172 *out
= &object
->filter
.IUnknown_inner
;