Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/winegstreamer/gst_private.h | 3 + dlls/winegstreamer/quartz_parser.c | 113 ++++++++++++++++++++-------- dlls/winegstreamer/wm_asyncreader.c | 11 ++- dlls/winegstreamer/wm_reader.c | 18 +++++ dlls/wmvcore/tests/wmvcore.c | 18 ++++- 5 files changed, 127 insertions(+), 36 deletions(-)
diff --git a/dlls/winegstreamer/gst_private.h b/dlls/winegstreamer/gst_private.h index e0f8bdae4a6..9e1d67417d4 100644 --- a/dlls/winegstreamer/gst_private.h +++ b/dlls/winegstreamer/gst_private.h @@ -96,6 +96,8 @@ uint64_t wg_parser_stream_get_duration(struct wg_parser_stream *stream) DECLSPEC void wg_parser_stream_seek(struct wg_parser_stream *stream, double rate, uint64_t start_pos, uint64_t stop_pos, DWORD start_flags, DWORD stop_flags) DECLSPEC_HIDDEN;
+unsigned int wg_format_get_max_size(const struct wg_format *format); + HRESULT avi_splitter_create(IUnknown *outer, IUnknown **out) DECLSPEC_HIDDEN; HRESULT decodebin_parser_create(IUnknown *outer, IUnknown **out) DECLSPEC_HIDDEN; HRESULT mpeg_splitter_create(IUnknown *outer, IUnknown **out) DECLSPEC_HIDDEN; @@ -168,6 +170,7 @@ struct wm_reader_ops
void wm_reader_cleanup(struct wm_reader *reader); HRESULT wm_reader_close(struct wm_reader *reader); +HRESULT wm_reader_get_max_stream_size(struct wm_reader *reader, WORD stream_number, DWORD *size); HRESULT wm_reader_get_output_format(struct wm_reader *reader, DWORD output, DWORD index, IWMOutputMediaProps **props); HRESULT wm_reader_get_output_format_count(struct wm_reader *reader, DWORD output, DWORD *count); diff --git a/dlls/winegstreamer/quartz_parser.c b/dlls/winegstreamer/quartz_parser.c index 89df41feb66..d91a93532c4 100644 --- a/dlls/winegstreamer/quartz_parser.c +++ b/dlls/winegstreamer/quartz_parser.c @@ -231,44 +231,97 @@ static bool amt_from_wg_format_audio(AM_MEDIA_TYPE *mt, const struct wg_format *
#define ALIGN(n, alignment) (((n) + (alignment) - 1) & ~((alignment) - 1))
-static unsigned int get_image_size(const struct wg_format *format) +unsigned int wg_format_get_max_size(const struct wg_format *format) { - unsigned int width = format->u.video.width, height = format->u.video.height; - - switch (format->u.video.format) + switch (format->major_type) { - case WG_VIDEO_FORMAT_BGRA: - case WG_VIDEO_FORMAT_BGRx: - case WG_VIDEO_FORMAT_AYUV: - return width * height * 4; + case WG_MAJOR_TYPE_VIDEO: + { + unsigned int width = format->u.video.width, height = format->u.video.height;
- case WG_VIDEO_FORMAT_BGR: - return ALIGN(width * 3, 4) * height; + switch (format->u.video.format) + { + case WG_VIDEO_FORMAT_BGRA: + case WG_VIDEO_FORMAT_BGRx: + case WG_VIDEO_FORMAT_AYUV: + return width * height * 4;
- case WG_VIDEO_FORMAT_RGB15: - case WG_VIDEO_FORMAT_RGB16: - case WG_VIDEO_FORMAT_UYVY: - case WG_VIDEO_FORMAT_YUY2: - case WG_VIDEO_FORMAT_YVYU: - return ALIGN(width * 2, 4) * height; + case WG_VIDEO_FORMAT_BGR: + return ALIGN(width * 3, 4) * height;
- case WG_VIDEO_FORMAT_I420: - case WG_VIDEO_FORMAT_YV12: - return ALIGN(width, 4) * ALIGN(height, 2) /* Y plane */ - + 2 * ALIGN((width + 1) / 2, 4) * ((height + 1) / 2); /* U and V planes */ + case WG_VIDEO_FORMAT_RGB15: + case WG_VIDEO_FORMAT_RGB16: + case WG_VIDEO_FORMAT_UYVY: + case WG_VIDEO_FORMAT_YUY2: + case WG_VIDEO_FORMAT_YVYU: + return ALIGN(width * 2, 4) * height;
- case WG_VIDEO_FORMAT_NV12: - return ALIGN(width, 4) * ALIGN(height, 2) /* Y plane */ - + ALIGN(width, 4) * ((height + 1) / 2); /* U/V plane */ + case WG_VIDEO_FORMAT_I420: + case WG_VIDEO_FORMAT_YV12: + return ALIGN(width, 4) * ALIGN(height, 2) /* Y plane */ + + 2 * ALIGN((width + 1) / 2, 4) * ((height + 1) / 2); /* U and V planes */
- case WG_VIDEO_FORMAT_CINEPAK: - /* Both ffmpeg's encoder and a Cinepak file seen in the wild report - * 24 bpp. ffmpeg sets biSizeImage as below; others may be smaller, - * but as long as every sample fits into our allocator, we're fine. */ - return width * height * 3; + case WG_VIDEO_FORMAT_NV12: + return ALIGN(width, 4) * ALIGN(height, 2) /* Y plane */ + + ALIGN(width, 4) * ((height + 1) / 2); /* U/V plane */
- case WG_VIDEO_FORMAT_UNKNOWN: + case WG_VIDEO_FORMAT_CINEPAK: + /* Both ffmpeg's encoder and a Cinepak file seen in the wild report + * 24 bpp. ffmpeg sets biSizeImage as below; others may be smaller, + * but as long as every sample fits into our allocator, we're fine. */ + return width * height * 3; + + case WG_VIDEO_FORMAT_UNKNOWN: + FIXME("Cannot guess maximum sample size for unknown video format.\n"); + return 0; + } break; + } + + case WG_MAJOR_TYPE_AUDIO: + { + unsigned int rate = format->u.audio.rate, channels = format->u.audio.channels; + + /* Actually we don't know how large of a sample GStreamer will give + * us. Hopefully 1 second is enough... */ + + switch (format->u.audio.format) + { + case WG_AUDIO_FORMAT_U8: + return rate * channels; + + case WG_AUDIO_FORMAT_S16LE: + return rate * channels * 2; + + case WG_AUDIO_FORMAT_S24LE: + return rate * channels * 3; + + case WG_AUDIO_FORMAT_S32LE: + case WG_AUDIO_FORMAT_F32LE: + return rate * channels * 4; + + case WG_AUDIO_FORMAT_F64LE: + return rate * channels * 8; + + case WG_AUDIO_FORMAT_MPEG1_LAYER1: + return 56000; + + case WG_AUDIO_FORMAT_MPEG1_LAYER2: + return 48000; + + case WG_AUDIO_FORMAT_MPEG1_LAYER3: + return 40000; + + case WG_AUDIO_FORMAT_UNKNOWN: + FIXME("Cannot guess maximum sample size for unknown audio format.\n"); + return 0; + } + break; + } + + case WG_MAJOR_TYPE_UNKNOWN: + FIXME("Cannot guess maximum sample size for unknown format.\n"); + return 0; }
assert(0); @@ -338,7 +391,7 @@ static bool amt_from_wg_format_video(AM_MEDIA_TYPE *mt, const struct wg_format * video_format->bmiHeader.biPlanes = 1; video_format->bmiHeader.biBitCount = format_table[format->u.video.format].depth; video_format->bmiHeader.biCompression = format_table[format->u.video.format].compression; - video_format->bmiHeader.biSizeImage = get_image_size(format); + video_format->bmiHeader.biSizeImage = wg_format_get_max_size(format);
if (format->u.video.format == WG_VIDEO_FORMAT_RGB16) { diff --git a/dlls/winegstreamer/wm_asyncreader.c b/dlls/winegstreamer/wm_asyncreader.c index b3dd7d41873..6549c9052e1 100644 --- a/dlls/winegstreamer/wm_asyncreader.c +++ b/dlls/winegstreamer/wm_asyncreader.c @@ -566,11 +566,14 @@ static HRESULT WINAPI WMReaderAdvanced_GetMaxOutputSampleSize(IWMReaderAdvanced6 return E_NOTIMPL; }
-static HRESULT WINAPI WMReaderAdvanced_GetMaxStreamSampleSize(IWMReaderAdvanced6 *iface, WORD stream, DWORD *max) +static HRESULT WINAPI WMReaderAdvanced_GetMaxStreamSampleSize(IWMReaderAdvanced6 *iface, + WORD stream_number, DWORD *size) { - struct async_reader *This = impl_from_IWMReaderAdvanced6(iface); - FIXME("(%p)->(%d %p)\n", This, stream, max); - return E_NOTIMPL; + struct async_reader *reader = impl_from_IWMReaderAdvanced6(iface); + + TRACE("reader %p, stream_number %u, size %p.\n", reader, stream_number, size); + + return wm_reader_get_max_stream_size(&reader->reader, stream_number, size); }
static HRESULT WINAPI WMReaderAdvanced_NotifyLateDelivery(IWMReaderAdvanced6 *iface, QWORD lateness) diff --git a/dlls/winegstreamer/wm_reader.c b/dlls/winegstreamer/wm_reader.c index a6e73c2857e..deef2031c96 100644 --- a/dlls/winegstreamer/wm_reader.c +++ b/dlls/winegstreamer/wm_reader.c @@ -2016,6 +2016,24 @@ HRESULT wm_reader_set_read_compressed(struct wm_reader *reader, WORD stream_numb return S_OK; }
+HRESULT wm_reader_get_max_stream_size(struct wm_reader *reader, WORD stream_number, DWORD *size) +{ + struct wm_stream *stream; + + EnterCriticalSection(&reader->cs); + + if (!(stream = wm_reader_get_stream_by_stream_number(reader, stream_number))) + { + LeaveCriticalSection(&reader->cs); + return E_INVALIDARG; + } + + *size = wg_format_get_max_size(&stream->format); + + LeaveCriticalSection(&reader->cs); + return S_OK; +} + void wm_reader_init(struct wm_reader *reader, const struct wm_reader_ops *ops) { reader->IWMHeaderInfo3_iface.lpVtbl = &header_info_vtbl; diff --git a/dlls/wmvcore/tests/wmvcore.c b/dlls/wmvcore/tests/wmvcore.c index 9ddd53ab9e7..c979a06fdb0 100644 --- a/dlls/wmvcore/tests/wmvcore.c +++ b/dlls/wmvcore/tests/wmvcore.c @@ -1390,7 +1390,9 @@ struct callback unsigned int got_closed, got_started, got_sample, got_end_of_streaming, got_eof; bool all_streams_off; bool allocated_samples; + bool read_compressed; + DWORD max_stream_sample_size[2]; };
static struct callback *impl_from_IWMReaderCallback(IWMReaderCallback *iface) @@ -1661,6 +1663,7 @@ static HRESULT WINAPI callback_advanced_AllocateForStream(IWMReaderCallbackAdvan WORD stream_number, DWORD size, INSSBuffer **sample, void *context) { struct callback *callback = impl_from_IWMReaderCallbackAdvanced(iface); + DWORD max_size = callback->max_stream_sample_size[stream_number - 1]; struct buffer *object;
if (winetest_debug > 1) @@ -1670,6 +1673,8 @@ static HRESULT WINAPI callback_advanced_AllocateForStream(IWMReaderCallbackAdvan ok(callback->read_compressed, "AllocateForStream() should only be called when reading compressed samples.\n"); ok(callback->allocated_samples, "AllocateForStream() should only be called when using a custom allocator.\n");
+ ok(size <= max_size, "Got size %u, max stream sample size %u.\n", size, max_size); + if (!(object = malloc(offsetof(struct buffer, data[size])))) return E_OUTOFMEMORY;
@@ -2016,12 +2021,21 @@ static void test_async_reader_compressed(IWMReader *reader, { HRESULT hr;
+ hr = IWMReaderAdvanced2_GetMaxStreamSampleSize(advanced, 0, &callback->max_stream_sample_size[0]); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + hr = IWMReaderAdvanced2_GetMaxStreamSampleSize(advanced, 3, &callback->max_stream_sample_size[0]); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + hr = IWMReaderAdvanced2_GetMaxStreamSampleSize(advanced, 1, &callback->max_stream_sample_size[0]); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(callback->max_stream_sample_size[0] > 0, "Expected nonzero size.\n"); + hr = IWMReaderAdvanced2_GetMaxStreamSampleSize(advanced, 2, &callback->max_stream_sample_size[1]); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(callback->max_stream_sample_size[1] > 0, "Expected nonzero size.\n"); + hr = IWMReaderAdvanced2_SetReceiveStreamSamples(advanced, 0, TRUE); ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); - hr = IWMReaderAdvanced2_SetReceiveStreamSamples(advanced, 3, TRUE); ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); - hr = IWMReaderAdvanced2_SetReceiveStreamSamples(advanced, 1, TRUE); ok(hr == S_OK, "Got hr %#x.\n", hr); hr = IWMReaderAdvanced2_SetReceiveStreamSamples(advanced, 2, TRUE);
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/winegstreamer/wm_reader.c | 55 ++++++++++++++++++++++++++++++++++ dlls/wmvcore/tests/wmvcore.c | 15 ++++++++++ 2 files changed, 70 insertions(+)
diff --git a/dlls/winegstreamer/wm_reader.c b/dlls/winegstreamer/wm_reader.c index deef2031c96..6b5d9629389 100644 --- a/dlls/winegstreamer/wm_reader.c +++ b/dlls/winegstreamer/wm_reader.c @@ -293,6 +293,7 @@ static const INSSBufferVtbl buffer_vtbl = struct stream_config { IWMStreamConfig IWMStreamConfig_iface; + IWMMediaProps IWMMediaProps_iface; LONG refcount;
const struct wm_stream *stream; @@ -311,6 +312,8 @@ static HRESULT WINAPI stream_config_QueryInterface(IWMStreamConfig *iface, REFII
if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IWMStreamConfig)) *out = &config->IWMStreamConfig_iface; + else if (IsEqualGUID(iid, &IID_IWMMediaProps)) + *out = &config->IWMMediaProps_iface; else { *out = NULL; @@ -454,6 +457,57 @@ static const IWMStreamConfigVtbl stream_config_vtbl = stream_config_SetBufferWindow, };
+static struct stream_config *impl_from_IWMMediaProps(IWMMediaProps *iface) +{ + return CONTAINING_RECORD(iface, struct stream_config, IWMMediaProps_iface); +} + +static HRESULT WINAPI stream_props_QueryInterface(IWMMediaProps *iface, REFIID iid, void **out) +{ + struct stream_config *config = impl_from_IWMMediaProps(iface); + return IWMStreamConfig_QueryInterface(&config->IWMStreamConfig_iface, iid, out); +} + +static ULONG WINAPI stream_props_AddRef(IWMMediaProps *iface) +{ + struct stream_config *config = impl_from_IWMMediaProps(iface); + return IWMStreamConfig_AddRef(&config->IWMStreamConfig_iface); +} + +static ULONG WINAPI stream_props_Release(IWMMediaProps *iface) +{ + struct stream_config *config = impl_from_IWMMediaProps(iface); + return IWMStreamConfig_Release(&config->IWMStreamConfig_iface); +} + +static HRESULT WINAPI stream_props_GetType(IWMMediaProps *iface, GUID *major_type) +{ + FIXME("iface %p, major_type %p, stub!\n", iface, major_type); + return E_NOTIMPL; +} + +static HRESULT WINAPI stream_props_GetMediaType(IWMMediaProps *iface, WM_MEDIA_TYPE *mt, DWORD *size) +{ + FIXME("iface %p, mt %p, size %p, stub!\n", iface, mt, size); + return E_NOTIMPL; +} + +static HRESULT WINAPI stream_props_SetMediaType(IWMMediaProps *iface, WM_MEDIA_TYPE *mt) +{ + FIXME("iface %p, mt %p, stub!\n", iface, mt); + return E_NOTIMPL; +} + +static const IWMMediaPropsVtbl stream_props_vtbl = +{ + stream_props_QueryInterface, + stream_props_AddRef, + stream_props_Release, + stream_props_GetType, + stream_props_GetMediaType, + stream_props_SetMediaType, +}; + static DWORD CALLBACK read_thread(void *arg) { struct wm_reader *reader = arg; @@ -688,6 +742,7 @@ static HRESULT WINAPI profile_GetStream(IWMProfile3 *iface, DWORD index, IWMStre }
object->IWMStreamConfig_iface.lpVtbl = &stream_config_vtbl; + object->IWMMediaProps_iface.lpVtbl = &stream_props_vtbl; object->refcount = 1; object->stream = &reader->streams[index]; IWMProfile3_AddRef(&reader->IWMProfile3_iface); diff --git a/dlls/wmvcore/tests/wmvcore.c b/dlls/wmvcore/tests/wmvcore.c index c979a06fdb0..d6bd331ea91 100644 --- a/dlls/wmvcore/tests/wmvcore.c +++ b/dlls/wmvcore/tests/wmvcore.c @@ -1125,6 +1125,17 @@ static void check_audio_type(const WM_MEDIA_TYPE *mt) ok(wave_format->wFormatTag == WAVE_FORMAT_PCM, "Got tag %#x.\n", wave_format->wFormatTag); }
+static void test_stream_media_props(IWMStreamConfig *config) +{ + IWMMediaProps *props; + HRESULT hr; + + hr = IWMStreamConfig_QueryInterface(config, &IID_IWMMediaProps, (void **)&props); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + IWMMediaProps_Release(props); +} + static void test_sync_reader_types(void) { char mt_buffer[2000], mt2_buffer[2000]; @@ -1177,6 +1188,8 @@ static void test_sync_reader_types(void) else ok(IsEqualGUID(&majortype, &MEDIATYPE_Audio), "Got major type %s.\n", debugstr_guid(&majortype));
+ test_stream_media_props(config); + ref = IWMStreamConfig_Release(config); ok(!ref, "Got outstanding refcount %d.\n", ref);
@@ -2267,6 +2280,8 @@ static void test_async_reader_types(void) else ok(IsEqualGUID(&majortype, &MEDIATYPE_Audio), "Got major type %s.\n", debugstr_guid(&majortype));
+ test_stream_media_props(config); + ref = IWMStreamConfig_Release(config); ok(!ref, "Got outstanding refcount %d.\n", ref);
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/winegstreamer/wm_reader.c | 23 +++++++++++++++++++++-- dlls/wmvcore/tests/wmvcore.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/dlls/winegstreamer/wm_reader.c b/dlls/winegstreamer/wm_reader.c index 6b5d9629389..970bdac44ab 100644 --- a/dlls/winegstreamer/wm_reader.c +++ b/dlls/winegstreamer/wm_reader.c @@ -488,8 +488,27 @@ static HRESULT WINAPI stream_props_GetType(IWMMediaProps *iface, GUID *major_typ
static HRESULT WINAPI stream_props_GetMediaType(IWMMediaProps *iface, WM_MEDIA_TYPE *mt, DWORD *size) { - FIXME("iface %p, mt %p, size %p, stub!\n", iface, mt, size); - return E_NOTIMPL; + struct stream_config *config = impl_from_IWMMediaProps(iface); + const DWORD req_size = *size; + AM_MEDIA_TYPE stream_mt; + + TRACE("iface %p, mt %p, size %p.\n", iface, mt, size); + + if (!amt_from_wg_format(&stream_mt, &config->stream->format, true)) + return E_OUTOFMEMORY; + + *size = sizeof(stream_mt) + stream_mt.cbFormat; + if (!mt) + return S_OK; + if (req_size < *size) + return ASF_E_BUFFERTOOSMALL; + + strmbase_dump_media_type(&stream_mt); + + memcpy(mt, &stream_mt, sizeof(*mt)); + memcpy(mt + 1, stream_mt.pbFormat, stream_mt.cbFormat); + mt->pbFormat = (BYTE *)(mt + 1); + return S_OK; }
static HRESULT WINAPI stream_props_SetMediaType(IWMMediaProps *iface, WM_MEDIA_TYPE *mt) diff --git a/dlls/wmvcore/tests/wmvcore.c b/dlls/wmvcore/tests/wmvcore.c index d6bd331ea91..bca611e4208 100644 --- a/dlls/wmvcore/tests/wmvcore.c +++ b/dlls/wmvcore/tests/wmvcore.c @@ -1125,14 +1125,37 @@ static void check_audio_type(const WM_MEDIA_TYPE *mt) ok(wave_format->wFormatTag == WAVE_FORMAT_PCM, "Got tag %#x.\n", wave_format->wFormatTag); }
-static void test_stream_media_props(IWMStreamConfig *config) +static void test_stream_media_props(IWMStreamConfig *config, const GUID *majortype) { + char mt_buffer[2000]; + WM_MEDIA_TYPE *mt = (WM_MEDIA_TYPE *)mt_buffer; IWMMediaProps *props; + DWORD size, ret_size; HRESULT hr;
hr = IWMStreamConfig_QueryInterface(config, &IID_IWMMediaProps, (void **)&props); ok(hr == S_OK, "Got hr %#x.\n", hr);
+ size = 0xdeadbeef; + hr = IWMMediaProps_GetMediaType(props, NULL, &size); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(size != 0xdeadbeef && size >= sizeof(WM_MEDIA_TYPE), "Got size %u.\n", size); + + ret_size = size - 1; + hr = IWMMediaProps_GetMediaType(props, mt, &ret_size); + ok(hr == ASF_E_BUFFERTOOSMALL, "Got hr %#x.\n", hr); + ok(ret_size == size, "Expected size %u, got %u.\n", size, ret_size); + + ret_size = sizeof(mt_buffer); + memset(mt_buffer, 0xcc, sizeof(mt_buffer)); + hr = IWMMediaProps_GetMediaType(props, mt, &ret_size); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(ret_size == size, "Expected size %u, got %u.\n", size, ret_size); + ok(size == sizeof(WM_MEDIA_TYPE) + mt->cbFormat, "Expected size %u, got %u.\n", + sizeof(WM_MEDIA_TYPE) + mt->cbFormat, size); + ok(IsEqualGUID(&mt->majortype, majortype), "Expected major type %s, got %s.\n", + debugstr_guid(majortype), debugstr_guid(&mt->majortype)); + IWMMediaProps_Release(props); }
@@ -1188,7 +1211,7 @@ static void test_sync_reader_types(void) else ok(IsEqualGUID(&majortype, &MEDIATYPE_Audio), "Got major type %s.\n", debugstr_guid(&majortype));
- test_stream_media_props(config); + test_stream_media_props(config, &majortype);
ref = IWMStreamConfig_Release(config); ok(!ref, "Got outstanding refcount %d.\n", ref); @@ -2280,7 +2303,7 @@ static void test_async_reader_types(void) else ok(IsEqualGUID(&majortype, &MEDIATYPE_Audio), "Got major type %s.\n", debugstr_guid(&majortype));
- test_stream_media_props(config); + test_stream_media_props(config, &majortype);
ref = IWMStreamConfig_Release(config); ok(!ref, "Got outstanding refcount %d.\n", ref);
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/winegstreamer/wm_asyncreader.c | 14 ++++++++++++++ dlls/wmvcore/tests/wmvcore.c | 23 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/dlls/winegstreamer/wm_asyncreader.c b/dlls/winegstreamer/wm_asyncreader.c index 6549c9052e1..18698a698e2 100644 --- a/dlls/winegstreamer/wm_asyncreader.c +++ b/dlls/winegstreamer/wm_asyncreader.c @@ -101,6 +101,10 @@ static DWORD WINAPI stream_thread(void *arg) { if (reader->user_clock) { + QWORD user_time = reader->user_time; + + if (pts > user_time && reader->reader.callback_advanced) + IWMReaderCallbackAdvanced_OnTime(reader->reader.callback_advanced, user_time, reader->context); while (pts > reader->user_time && reader->running) SleepConditionVariableCS(&reader->stream_cv, &reader->stream_cs, INFINITE); if (!reader->running) @@ -152,6 +156,16 @@ static DWORD WINAPI stream_thread(void *arg) WMT_TYPE_DWORD, (BYTE *)&zero, reader->context); IWMReaderCallback_OnStatus(callback, WMT_EOF, S_OK, WMT_TYPE_DWORD, (BYTE *)&zero, reader->context); + + if (reader->user_clock && reader->reader.callback_advanced) + { + /* We can only get here if user_time is greater than the PTS + * of all samples, in which case we cannot have sent this + * notification already. */ + IWMReaderCallbackAdvanced_OnTime(reader->reader.callback_advanced, + reader->user_time, reader->context); + } + TRACE("Reached end of stream; exiting.\n"); LeaveCriticalSection(&reader->stream_cs); return 0; diff --git a/dlls/wmvcore/tests/wmvcore.c b/dlls/wmvcore/tests/wmvcore.c index bca611e4208..e27011f49a0 100644 --- a/dlls/wmvcore/tests/wmvcore.c +++ b/dlls/wmvcore/tests/wmvcore.c @@ -1429,6 +1429,9 @@ struct callback
bool read_compressed; DWORD max_stream_sample_size[2]; + + QWORD expect_ontime; + HANDLE ontime_event; };
static struct callback *impl_from_IWMReaderCallback(IWMReaderCallback *iface) @@ -1672,12 +1675,15 @@ static HRESULT WINAPI callback_advanced_OnStreamSample(IWMReaderCallbackAdvanced
static HRESULT WINAPI callback_advanced_OnTime(IWMReaderCallbackAdvanced *iface, QWORD time, void *context) { + struct callback *callback = impl_from_IWMReaderCallbackAdvanced(iface); + if (winetest_debug > 1) trace("%u: %04x: IWMReaderCallbackAdvanced::OnTime(time %I64u)\n", GetTickCount(), GetCurrentThreadId(), time);
- ok(time == 3000 * 10000, "Got time %I64u.\n", time); + ok(time == callback->expect_ontime, "Got time %I64u.\n", time); ok(context == (void *)0xfacade, "Got unexpected context %p.\n", context); + SetEvent(callback->ontime_event); return S_OK; }
@@ -1837,6 +1843,7 @@ static void callback_init(struct callback *callback) callback->got_opened = CreateEventW(NULL, FALSE, FALSE, NULL); callback->got_stopped = CreateEventW(NULL, FALSE, FALSE, NULL); callback->eof_event = CreateEventW(NULL, FALSE, FALSE, NULL); + callback->ontime_event = CreateEventW(NULL, FALSE, FALSE, NULL); }
static void callback_cleanup(struct callback *callback) @@ -1844,6 +1851,7 @@ static void callback_cleanup(struct callback *callback) CloseHandle(callback->got_opened); CloseHandle(callback->got_stopped); CloseHandle(callback->eof_event); + CloseHandle(callback->ontime_event); }
static void run_async_reader(IWMReader *reader, IWMReaderAdvanced2 *advanced, struct callback *callback) @@ -2197,8 +2205,21 @@ static void test_async_reader_streaming(void) ok(hr == E_UNEXPECTED, "Got hr %#x.\n", hr); hr = IWMReaderAdvanced2_SetUserProvidedClock(advanced, TRUE); ok(hr == S_OK, "Got hr %#x.\n", hr); + callback.expect_ontime = 0; + hr = IWMReaderAdvanced2_DeliverTime(advanced, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ret = WaitForSingleObject(callback.ontime_event, 1000); + ok(!ret, "Wait timed out.\n"); + callback.expect_ontime = 1000 * 10000; + hr = IWMReaderAdvanced2_DeliverTime(advanced, 1000 * 10000); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ret = WaitForSingleObject(callback.ontime_event, 1000); + ok(!ret, "Wait timed out.\n"); + callback.expect_ontime = 3000 * 10000; hr = IWMReaderAdvanced2_DeliverTime(advanced, 3000 * 10000); ok(hr == S_OK, "Got hr %#x.\n", hr); + ret = WaitForSingleObject(callback.ontime_event, 1000); + ok(!ret, "Wait timed out.\n");
ret = WaitForSingleObject(callback.eof_event, 1000); ok(!ret, "Wait timed out.\n");