From: Rémi Bernon rbernon@codeweavers.com
And wg_parser_push_data to wg_parser_reply_read.
Wrapping the request in a more general structure so we can later emit buffer pool allocation request to the reader thread.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winegstreamer/gst_private.h | 4 ++-- dlls/winegstreamer/main.c | 17 ++++++++-------- dlls/winegstreamer/media_source.c | 24 ++++++++++++++++------- dlls/winegstreamer/quartz_parser.c | 24 ++++++++++++++++------- dlls/winegstreamer/unixlib.h | 29 ++++++++++++++++++++++------ dlls/winegstreamer/wg_parser.c | 31 +++++++++++++++--------------- dlls/winegstreamer/wm_reader.c | 24 ++++++++++++++++------- 7 files changed, 100 insertions(+), 53 deletions(-)
diff --git a/dlls/winegstreamer/gst_private.h b/dlls/winegstreamer/gst_private.h index e1abe7018da..2552e1d7f61 100644 --- a/dlls/winegstreamer/gst_private.h +++ b/dlls/winegstreamer/gst_private.h @@ -76,8 +76,8 @@ void wg_parser_destroy(struct wg_parser *parser); HRESULT wg_parser_connect(struct wg_parser *parser, uint64_t file_size); void wg_parser_disconnect(struct wg_parser *parser);
-bool wg_parser_get_next_read_offset(struct wg_parser *parser, uint64_t *offset, uint32_t *size); -void wg_parser_push_data(struct wg_parser *parser, const void *data, uint32_t size); +bool wg_parser_wait_request(struct wg_parser *parser, struct wg_request *request); +void wg_parser_reply_read(struct wg_parser *parser, const void *data, uint32_t size);
uint32_t wg_parser_get_stream_count(struct wg_parser *parser); struct wg_parser_stream *wg_parser_get_stream(struct wg_parser *parser, uint32_t index); diff --git a/dlls/winegstreamer/main.c b/dlls/winegstreamer/main.c index 5075b3118cd..25f0c38b700 100644 --- a/dlls/winegstreamer/main.c +++ b/dlls/winegstreamer/main.c @@ -107,25 +107,24 @@ void wg_parser_disconnect(struct wg_parser *parser) __wine_unix_call(unix_handle, unix_wg_parser_disconnect, parser); }
-bool wg_parser_get_next_read_offset(struct wg_parser *parser, uint64_t *offset, uint32_t *size) +bool wg_parser_wait_request(struct wg_parser *parser, struct wg_request *wg_request) { - struct wg_parser_get_next_read_offset_params params = + struct wg_parser_wait_request_params params = { .parser = parser, };
- TRACE("parser %p, offset %p, size %p.\n", parser, offset, size); + TRACE("parser %p, wg_request %p.\n", parser, wg_request);
- if (__wine_unix_call(unix_handle, unix_wg_parser_get_next_read_offset, ¶ms)) + if (__wine_unix_call(unix_handle, unix_wg_parser_wait_request, ¶ms)) return false; - *offset = params.offset; - *size = params.size; + *wg_request = params.request; return true; }
-void wg_parser_push_data(struct wg_parser *parser, const void *data, uint32_t size) +void wg_parser_reply_read(struct wg_parser *parser, const void *data, uint32_t size) { - struct wg_parser_push_data_params params = + struct wg_parser_reply_read_params params = { .parser = parser, .data = data, @@ -134,7 +133,7 @@ void wg_parser_push_data(struct wg_parser *parser, const void *data, uint32_t si
TRACE("parser %p, data %p, size %u.\n", parser, data, size);
- __wine_unix_call(unix_handle, unix_wg_parser_push_data, ¶ms); + __wine_unix_call(unix_handle, unix_wg_parser_reply_read, ¶ms); }
uint32_t wg_parser_get_stream_count(struct wg_parser *parser) diff --git a/dlls/winegstreamer/media_source.c b/dlls/winegstreamer/media_source.c index ac23b1bc94c..5b98c90a8b4 100644 --- a/dlls/winegstreamer/media_source.c +++ b/dlls/winegstreamer/media_source.c @@ -593,9 +593,11 @@ static const IMFAsyncCallbackVtbl source_async_commands_callback_vtbl = };
static void handle_read_request(struct media_source *source, QWORD file_size, - void **buffer, size_t *buffer_size, uint64_t offset, uint32_t size) + void **buffer, size_t *buffer_size, struct wg_request *request) { IMFByteStream *byte_stream = source->byte_stream; + uint64_t offset = request->u.read.offset; + uint32_t size = request->u.read.size; ULONG ret_size = 0; HRESULT hr; void *data; @@ -607,7 +609,7 @@ static void handle_read_request(struct media_source *source, QWORD file_size,
if (!array_reserve(buffer, buffer_size, size, 1)) { - wg_parser_push_data(source->wg_parser, NULL, 0); + wg_parser_reply_read(source->wg_parser, NULL, 0); return; } data = *buffer; @@ -631,7 +633,7 @@ static void handle_read_request(struct media_source *source, QWORD file_size, size = ret_size; }
- wg_parser_push_data(source->wg_parser, data, size); + wg_parser_reply_read(source->wg_parser, data, size); }
static DWORD CALLBACK read_thread(void *arg) @@ -651,13 +653,21 @@ static DWORD CALLBACK read_thread(void *arg)
while (!source->read_thread_shutdown) { - uint64_t offset; - uint32_t size; + struct wg_request request;
- if (!wg_parser_get_next_read_offset(source->wg_parser, &offset, &size)) + if (!wg_parser_wait_request(source->wg_parser, &request)) continue;
- handle_read_request(source, file_size, &data, &buffer_size, offset, size); + switch (request.type) + { + case WG_REQUEST_READ: + handle_read_request(source, file_size, &data, &buffer_size, &request); + break; + + default: + FIXME("Ingoring unknown request %u\n", request.type); + continue; + } }
free(data); diff --git a/dlls/winegstreamer/quartz_parser.c b/dlls/winegstreamer/quartz_parser.c index 0e9f183d499..edf7ed6454b 100644 --- a/dlls/winegstreamer/quartz_parser.c +++ b/dlls/winegstreamer/quartz_parser.c @@ -866,8 +866,10 @@ static DWORD CALLBACK stream_thread(void *arg) }
static void handle_read_request(struct parser *filter, LONGLONG file_size, - void **buffer, size_t *buffer_size, uint64_t offset, uint32_t size) + void **buffer, size_t *buffer_size, struct wg_request *request) { + uint64_t offset = request->u.read.offset; + uint32_t size = request->u.read.size; HRESULT hr; void *data;
@@ -878,7 +880,7 @@ static void handle_read_request(struct parser *filter, LONGLONG file_size,
if (!array_reserve(buffer, buffer_size, size, 1)) { - wg_parser_push_data(filter->wg_parser, NULL, 0); + wg_parser_reply_read(filter->wg_parser, NULL, 0); return; } data = *buffer; @@ -891,7 +893,7 @@ static void handle_read_request(struct parser *filter, LONGLONG file_size, data = NULL; }
- wg_parser_push_data(filter->wg_parser, data, size); + wg_parser_reply_read(filter->wg_parser, data, size); }
static DWORD CALLBACK read_thread(void *arg) @@ -910,13 +912,21 @@ static DWORD CALLBACK read_thread(void *arg)
while (filter->sink_connected) { - uint64_t offset; - uint32_t size; + struct wg_request request;
- if (!wg_parser_get_next_read_offset(filter->wg_parser, &offset, &size)) + if (!wg_parser_wait_request(filter->wg_parser, &request)) continue;
- handle_read_request(filter, file_size, &data, &buffer_size, offset, size); + switch (request.type) + { + case WG_REQUEST_READ: + handle_read_request(filter, file_size, &data, &buffer_size, &request); + break; + + default: + FIXME("Ingoring unknown request %u\n", request.type); + continue; + } }
free(data); diff --git a/dlls/winegstreamer/unixlib.h b/dlls/winegstreamer/unixlib.h index 860a8ab2a52..f767daed513 100644 --- a/dlls/winegstreamer/unixlib.h +++ b/dlls/winegstreamer/unixlib.h @@ -135,6 +135,24 @@ struct wg_sample BYTE *data; };
+struct wg_request +{ + enum wg_request_type + { + WG_REQUEST_NONE = 0, + WG_REQUEST_READ = 1, + } type; + + union + { + struct + { + UINT32 size; + UINT64 offset; + } read; + } u; +}; + struct wg_parser_buffer { /* pts and duration are in 100-nanosecond units. */ @@ -165,14 +183,13 @@ struct wg_parser_connect_params UINT64 file_size; };
-struct wg_parser_get_next_read_offset_params +struct wg_parser_wait_request_params { struct wg_parser *parser; - UINT32 size; - UINT64 offset; + struct wg_request request; };
-struct wg_parser_push_data_params +struct wg_parser_reply_read_params { struct wg_parser *parser; const void *data; @@ -271,8 +288,8 @@ enum unix_funcs unix_wg_parser_connect, unix_wg_parser_disconnect,
- unix_wg_parser_get_next_read_offset, - unix_wg_parser_push_data, + unix_wg_parser_wait_request, + unix_wg_parser_reply_read,
unix_wg_parser_get_stream_count, unix_wg_parser_get_stream, diff --git a/dlls/winegstreamer/wg_parser.c b/dlls/winegstreamer/wg_parser.c index 865b6d3643a..56525da1348 100644 --- a/dlls/winegstreamer/wg_parser.c +++ b/dlls/winegstreamer/wg_parser.c @@ -77,7 +77,7 @@ struct wg_parser pthread_cond_t init_cond; bool no_more_pads, has_duration, error;
- pthread_cond_t read_cond, read_done_cond; + pthread_cond_t request_cond, read_done_cond; struct { GstBuffer *buffer; @@ -126,15 +126,15 @@ static NTSTATUS wg_parser_get_stream(void *args) return S_OK; }
-static NTSTATUS wg_parser_get_next_read_offset(void *args) +static NTSTATUS wg_parser_wait_request(void *args) { - struct wg_parser_get_next_read_offset_params *params = args; + struct wg_parser_wait_request_params *params = args; struct wg_parser *parser = params->parser;
pthread_mutex_lock(&parser->mutex);
while (parser->sink_connected && !parser->read_request.size) - pthread_cond_wait(&parser->read_cond, &parser->mutex); + pthread_cond_wait(&parser->request_cond, &parser->mutex);
if (!parser->sink_connected) { @@ -142,16 +142,17 @@ static NTSTATUS wg_parser_get_next_read_offset(void *args) return VFW_E_WRONG_STATE; }
- params->offset = parser->read_request.offset; - params->size = parser->read_request.size; + params->request.type = WG_REQUEST_READ; + params->request.u.read.offset = parser->read_request.offset; + params->request.u.read.size = parser->read_request.size;
pthread_mutex_unlock(&parser->mutex); return S_OK; }
-static NTSTATUS wg_parser_push_data(void *args) +static NTSTATUS wg_parser_reply_read(void *args) { - const struct wg_parser_push_data_params *params = args; + const struct wg_parser_reply_read_params *params = args; struct wg_parser *parser = params->parser; const void *data = params->data; uint32_t size = params->size; @@ -890,7 +891,7 @@ static GstFlowReturn src_getrange_cb(GstPad *pad, GstObject *parent, parser->read_request.offset = offset; parser->read_request.size = size; parser->read_request.done = false; - pthread_cond_signal(&parser->read_cond); + pthread_cond_signal(&parser->request_cond);
/* Note that we don't unblock this wait on GST_EVENT_FLUSH_START. We expect * the upstream pin to flush if necessary. We should never be blocked on @@ -1328,7 +1329,7 @@ out: pthread_mutex_lock(&parser->mutex); parser->sink_connected = false; pthread_mutex_unlock(&parser->mutex); - pthread_cond_signal(&parser->read_cond); + pthread_cond_signal(&parser->request_cond);
return E_FAIL; } @@ -1355,7 +1356,7 @@ static NTSTATUS wg_parser_disconnect(void *args) pthread_mutex_lock(&parser->mutex); parser->sink_connected = false; pthread_mutex_unlock(&parser->mutex); - pthread_cond_signal(&parser->read_cond); + pthread_cond_signal(&parser->request_cond);
for (i = 0; i < parser->stream_count; ++i) free_stream(parser->streams[i]); @@ -1557,7 +1558,7 @@ static NTSTATUS wg_parser_create(void *args)
pthread_mutex_init(&parser->mutex, NULL); pthread_cond_init(&parser->init_cond, NULL); - pthread_cond_init(&parser->read_cond, NULL); + pthread_cond_init(&parser->request_cond, NULL); pthread_cond_init(&parser->read_done_cond, NULL); parser->init_gst = init_funcs[params->type]; parser->unlimited_buffering = params->unlimited_buffering; @@ -1579,7 +1580,7 @@ static NTSTATUS wg_parser_destroy(void *args)
pthread_mutex_destroy(&parser->mutex); pthread_cond_destroy(&parser->init_cond); - pthread_cond_destroy(&parser->read_cond); + pthread_cond_destroy(&parser->request_cond); pthread_cond_destroy(&parser->read_done_cond);
free(parser); @@ -1595,8 +1596,8 @@ const unixlib_entry_t __wine_unix_call_funcs[] = X(wg_parser_connect), X(wg_parser_disconnect),
- X(wg_parser_get_next_read_offset), - X(wg_parser_push_data), + X(wg_parser_wait_request), + X(wg_parser_reply_read),
X(wg_parser_get_stream_count), X(wg_parser_get_stream), diff --git a/dlls/winegstreamer/wm_reader.c b/dlls/winegstreamer/wm_reader.c index 9d1eb2a95ed..9de7ab6edf3 100644 --- a/dlls/winegstreamer/wm_reader.c +++ b/dlls/winegstreamer/wm_reader.c @@ -527,9 +527,11 @@ static const IWMMediaPropsVtbl stream_props_vtbl = };
static void handle_read_request(struct wm_reader *reader, uint64_t file_size, - void **buffer, size_t *buffer_size, uint64_t offset, uint32_t size) + void **buffer, size_t *buffer_size, struct wg_request *request) { + uint64_t offset = request->u.read.offset; IStream *stream = reader->source_stream; + uint32_t size = request->u.read.size; LARGE_INTEGER large_offset; HANDLE file = reader->file; ULONG ret_size = 0; @@ -543,7 +545,7 @@ static void handle_read_request(struct wm_reader *reader, uint64_t file_size,
if (!array_reserve(buffer, buffer_size, size, 1)) { - wg_parser_push_data(reader->wg_parser, NULL, 0); + wg_parser_reply_read(reader->wg_parser, NULL, 0); return; } data = *buffer; @@ -576,7 +578,7 @@ static void handle_read_request(struct wm_reader *reader, uint64_t file_size, size = ret_size; }
- wg_parser_push_data(reader->wg_parser, data, size); + wg_parser_reply_read(reader->wg_parser, data, size); }
static DWORD CALLBACK read_thread(void *arg) @@ -610,13 +612,21 @@ static DWORD CALLBACK read_thread(void *arg)
while (!reader->read_thread_shutdown) { - uint64_t offset; - uint32_t size; + struct wg_request request;
- if (!wg_parser_get_next_read_offset(reader->wg_parser, &offset, &size)) + if (!wg_parser_wait_request(reader->wg_parser, &request)) continue;
- handle_read_request(reader, file_size, &data, &buffer_size, offset, size); + switch (request.type) + { + case WG_REQUEST_READ: + handle_read_request(reader, file_size, &data, &buffer_size, &request); + break; + + default: + FIXME("Ingoring unknown request %u\n", request.type); + continue; + } }
free(data);