Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/qcap/qcap_private.h | 4 +--- dlls/qcap/v4l.c | 40 ++-------------------------------------- dlls/qcap/vfwcapture.c | 38 ++++++++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 51 deletions(-)
diff --git a/dlls/qcap/qcap_private.h b/dlls/qcap/qcap_private.h index d715219c645..1d2b49d7394 100644 --- a/dlls/qcap/qcap_private.h +++ b/dlls/qcap/qcap_private.h @@ -42,7 +42,7 @@ HRESULT vfw_capture_create(IUnknown *outer, IUnknown **out) DECLSPEC_HIDDEN;
struct video_capture_funcs { - struct video_capture_device *(*create)(struct strmbase_source *pin, USHORT index); + struct video_capture_device *(*create)(USHORT index); void (*destroy)(struct video_capture_device *device); HRESULT (*check_format)(struct video_capture_device *device, const AM_MEDIA_TYPE *mt); HRESULT (*set_format)(struct video_capture_device *device, const AM_MEDIA_TYPE *mt); @@ -55,8 +55,6 @@ struct video_capture_funcs HRESULT (*get_prop)(struct video_capture_device *device, VideoProcAmpProperty property, LONG *value, LONG *flags); HRESULT (*set_prop)(struct video_capture_device *device, VideoProcAmpProperty property, LONG value, LONG flags); BOOL (*read_frame)(struct video_capture_device *device, BYTE *data); - void (*init_stream)(struct video_capture_device *device); - void (*cleanup_stream)(struct video_capture_device *device); };
extern const struct video_capture_funcs v4l_funcs; diff --git a/dlls/qcap/v4l.c b/dlls/qcap/v4l.c index e0095379b34..d525989172a 100644 --- a/dlls/qcap/v4l.c +++ b/dlls/qcap/v4l.c @@ -97,7 +97,6 @@ struct video_capture_device int image_size, image_pitch; BYTE *image_data;
- struct strmbase_source *pin; int fd, mmap; };
@@ -338,37 +337,6 @@ static BOOL v4l_device_read_frame(struct video_capture_device *device, BYTE *dat return TRUE; }
-static void v4l_device_init_stream(struct video_capture_device *device) -{ - ALLOCATOR_PROPERTIES req_props, ret_props; - HRESULT hr; - - req_props.cBuffers = 3; - req_props.cbBuffer = device->image_size; - req_props.cbAlign = 1; - req_props.cbPrefix = 0; - - hr = IMemAllocator_SetProperties(device->pin->pAllocator, &req_props, &ret_props); - if (FAILED(hr)) - ERR("Failed to set allocator properties (buffer size %u), hr %#x.\n", req_props.cbBuffer, hr); - - if (SUCCEEDED(hr)) - { - if (FAILED(hr = IMemAllocator_Commit(device->pin->pAllocator))) - ERR("Failed to commit allocator, hr %#x.\n", hr); - } -} - -static void v4l_device_cleanup_stream(struct video_capture_device *device) -{ - HRESULT hr; - - hr = IMemAllocator_Decommit(device->pin->pAllocator); - if (hr != S_OK && hr != VFW_E_NOT_COMMITTED) - ERR("Failed to decommit allocator, hr %#x.\n", hr); -} - - static void fill_caps(__u32 pixelformat, __u32 width, __u32 height, __u32 max_fps, __u32 min_fps, struct caps *caps) { @@ -425,7 +393,7 @@ static LONG v4l_device_get_caps_count(struct video_capture_device *device) return device->caps_count; }
-struct video_capture_device *v4l_device_create(struct strmbase_source *pin, USHORT index) +struct video_capture_device *v4l_device_create(USHORT index) { struct v4l2_frmsizeenum frmsize = {0}; struct video_capture_device *device; @@ -562,8 +530,6 @@ struct video_capture_device *v4l_device_create(struct strmbase_source *pin, USHO goto error; }
- device->pin = pin; - TRACE("Format: %d bpp - %dx%d.\n", device->current_caps->video_info.bmiHeader.biBitCount, device->current_caps->video_info.bmiHeader.biWidth, device->current_caps->video_info.bmiHeader.biHeight); @@ -589,13 +555,11 @@ const struct video_capture_funcs v4l_funcs = .get_prop = v4l_device_get_prop, .set_prop = v4l_device_set_prop, .read_frame = v4l_device_read_frame, - .init_stream = v4l_device_init_stream, - .cleanup_stream = v4l_device_cleanup_stream, };
#else
-static struct video_capture_device *v4l_device_create(struct strmbase_source *pin, USHORT index) +static struct video_capture_device *v4l_device_create(USHORT index) { ERR("v4l2 was not present at compilation time.\n"); return NULL; diff --git a/dlls/qcap/vfwcapture.c b/dlls/qcap/vfwcapture.c index 9fb694ba678..f0a985d5f4b 100644 --- a/dlls/qcap/vfwcapture.c +++ b/dlls/qcap/vfwcapture.c @@ -94,11 +94,7 @@ static void vfw_capture_destroy(struct strmbase_filter *iface) struct vfw_capture *filter = impl_from_strmbase_filter(iface);
if (filter->init) - { - if (filter->filter.state != State_Stopped) - capture_funcs->cleanup_stream(filter->device); capture_funcs->destroy(filter->device); - }
if (filter->source.pin.peer) { @@ -132,12 +128,17 @@ static HRESULT vfw_capture_query_interface(struct strmbase_filter *iface, REFIID return S_OK; }
+static unsigned int get_image_size(struct vfw_capture *filter) +{ + const VIDEOINFOHEADER *format = (const VIDEOINFOHEADER *)filter->source.pin.mt.pbFormat; + + return format->bmiHeader.biWidth * format->bmiHeader.biHeight * format->bmiHeader.biBitCount / 8; +} + static DWORD WINAPI stream_thread(void *arg) { struct vfw_capture *filter = arg; - const VIDEOINFOHEADER *format = (const VIDEOINFOHEADER *)filter->source.pin.mt.pbFormat; - const unsigned int image_size = format->bmiHeader.biWidth - * format->bmiHeader.biHeight * format->bmiHeader.biBitCount / 8; + const unsigned int image_size = get_image_size(filter);
for (;;) { @@ -188,8 +189,21 @@ static DWORD WINAPI stream_thread(void *arg) static HRESULT vfw_capture_init_stream(struct strmbase_filter *iface) { struct vfw_capture *filter = impl_from_strmbase_filter(iface); + ALLOCATOR_PROPERTIES req_props, ret_props; + HRESULT hr;
- capture_funcs->init_stream(filter->device); + req_props.cBuffers = 3; + req_props.cbBuffer = get_image_size(filter); + req_props.cbAlign = 1; + req_props.cbPrefix = 0; + if (FAILED(hr = IMemAllocator_SetProperties(filter->source.pAllocator, &req_props, &ret_props))) + { + ERR("Failed to set allocator properties (buffer size %u), hr %#x.\n", req_props.cbBuffer, hr); + return hr; + } + + if (FAILED(hr = IMemAllocator_Commit(filter->source.pAllocator))) + ERR("Failed to commit allocator, hr %#x.\n", hr);
EnterCriticalSection(&filter->state_cs); filter->state = State_Paused; @@ -224,6 +238,7 @@ static HRESULT vfw_capture_stop_stream(struct strmbase_filter *iface) static HRESULT vfw_capture_cleanup_stream(struct strmbase_filter *iface) { struct vfw_capture *filter = impl_from_strmbase_filter(iface); + HRESULT hr;
EnterCriticalSection(&filter->state_cs); filter->state = State_Stopped; @@ -234,7 +249,10 @@ static HRESULT vfw_capture_cleanup_stream(struct strmbase_filter *iface) CloseHandle(filter->thread); filter->thread = NULL;
- capture_funcs->cleanup_stream(filter->device); + hr = IMemAllocator_Decommit(filter->source.pAllocator); + if (hr != S_OK && hr != VFW_E_NOT_COMMITTED) + ERR("Failed to decommit allocator, hr %#x.\n", hr); + return S_OK; }
@@ -478,7 +496,7 @@ static HRESULT WINAPI PPB_Load(IPersistPropertyBag *iface, IPropertyBag *bag, IE if (FAILED(hr = IPropertyBag_Read(bag, VFWIndex, &var, error_log))) return hr;
- if (!(filter->device = capture_funcs->create(&filter->source, V_I4(&var)))) + if (!(filter->device = capture_funcs->create(V_I4(&var)))) return E_FAIL;
filter->init = TRUE;