winegstreamer: Map the read buffer in the Unix library.
Signed-off-by: Zebediah Figura <z.figura12@gmail.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
491945ee41
commit
9a6aa56cd8
|
@ -157,11 +157,11 @@ struct wg_parser
|
|||
pthread_cond_t read_cond, read_done_cond;
|
||||
struct
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
void *data;
|
||||
uint64_t offset;
|
||||
uint32_t size;
|
||||
bool done;
|
||||
GstFlowReturn ret;
|
||||
bool ret;
|
||||
} read_request;
|
||||
|
||||
bool flushing, sink_connected;
|
||||
|
@ -228,8 +228,8 @@ struct unix_funcs
|
|||
void (CDECL *wg_parser_end_flush)(struct wg_parser *parser);
|
||||
|
||||
bool (CDECL *wg_parser_get_read_request)(struct wg_parser *parser,
|
||||
GstBuffer **buffer, uint64_t *offset, uint32_t *size);
|
||||
void (CDECL *wg_parser_complete_read_request)(struct wg_parser *parser, GstFlowReturn ret);
|
||||
void **data, uint64_t *offset, uint32_t *size);
|
||||
void (CDECL *wg_parser_complete_read_request)(struct wg_parser *parser, bool ret);
|
||||
|
||||
uint32_t (CDECL *wg_parser_get_stream_count)(struct wg_parser *parser);
|
||||
struct wg_parser_stream *(CDECL *wg_parser_get_stream)(struct wg_parser *parser, uint32_t index);
|
||||
|
|
|
@ -787,25 +787,6 @@ static DWORD CALLBACK stream_thread(void *arg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static GstFlowReturn read_buffer(struct parser *This, guint64 ofs, guint len, GstBuffer *buffer)
|
||||
{
|
||||
HRESULT hr;
|
||||
GstMapInfo info;
|
||||
|
||||
TRACE("filter %p, offset %s, length %u, buffer %p.\n", This, wine_dbgstr_longlong(ofs), len, buffer);
|
||||
|
||||
gst_buffer_map(buffer, &info, GST_MAP_WRITE);
|
||||
hr = IAsyncReader_SyncRead(This->reader, ofs, len, info.data);
|
||||
gst_buffer_unmap(buffer, &info);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
ERR("Failed to read data, hr %#x.\n", hr);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
static DWORD CALLBACK read_thread(void *arg)
|
||||
{
|
||||
struct parser *filter = arg;
|
||||
|
@ -814,15 +795,15 @@ static DWORD CALLBACK read_thread(void *arg)
|
|||
|
||||
while (filter->sink_connected)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
uint64_t offset;
|
||||
uint32_t size;
|
||||
HRESULT hr;
|
||||
void *data;
|
||||
|
||||
if (!unix_funcs->wg_parser_get_read_request(filter->wg_parser, &buffer, &offset, &size))
|
||||
if (!unix_funcs->wg_parser_get_read_request(filter->wg_parser, &data, &offset, &size))
|
||||
continue;
|
||||
|
||||
unix_funcs->wg_parser_complete_read_request(filter->wg_parser,
|
||||
read_buffer(filter, offset, size, buffer));
|
||||
hr = IAsyncReader_SyncRead(filter->reader, offset, size, data);
|
||||
unix_funcs->wg_parser_complete_read_request(filter->wg_parser, SUCCEEDED(hr));
|
||||
}
|
||||
|
||||
TRACE("Streaming stopped; exiting.\n");
|
||||
|
|
|
@ -350,11 +350,11 @@ static void CDECL wg_parser_end_flush(struct wg_parser *parser)
|
|||
}
|
||||
|
||||
static bool CDECL wg_parser_get_read_request(struct wg_parser *parser,
|
||||
GstBuffer **buffer, uint64_t *offset, uint32_t *size)
|
||||
void **data, uint64_t *offset, uint32_t *size)
|
||||
{
|
||||
pthread_mutex_lock(&parser->mutex);
|
||||
|
||||
while (parser->sink_connected && !parser->read_request.buffer)
|
||||
while (parser->sink_connected && !parser->read_request.data)
|
||||
pthread_cond_wait(&parser->read_cond, &parser->mutex);
|
||||
|
||||
if (!parser->sink_connected)
|
||||
|
@ -363,7 +363,7 @@ static bool CDECL wg_parser_get_read_request(struct wg_parser *parser,
|
|||
return false;
|
||||
}
|
||||
|
||||
*buffer = parser->read_request.buffer;
|
||||
*data = parser->read_request.data;
|
||||
*offset = parser->read_request.offset;
|
||||
*size = parser->read_request.size;
|
||||
|
||||
|
@ -371,12 +371,12 @@ static bool CDECL wg_parser_get_read_request(struct wg_parser *parser,
|
|||
return true;
|
||||
}
|
||||
|
||||
static void CDECL wg_parser_complete_read_request(struct wg_parser *parser, GstFlowReturn ret)
|
||||
static void CDECL wg_parser_complete_read_request(struct wg_parser *parser, bool ret)
|
||||
{
|
||||
pthread_mutex_lock(&parser->mutex);
|
||||
parser->read_request.done = true;
|
||||
parser->read_request.ret = ret;
|
||||
parser->read_request.buffer = NULL;
|
||||
parser->read_request.data = NULL;
|
||||
pthread_mutex_unlock(&parser->mutex);
|
||||
pthread_cond_signal(&parser->read_done_cond);
|
||||
}
|
||||
|
@ -985,7 +985,8 @@ static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64
|
|||
{
|
||||
struct wg_parser *parser = gst_pad_get_element_private(pad);
|
||||
GstBuffer *new_buffer = NULL;
|
||||
GstFlowReturn ret;
|
||||
GstMapInfo map_info;
|
||||
bool ret;
|
||||
|
||||
GST_LOG("pad %p, offset %" G_GINT64_MODIFIER "u, length %u, buffer %p.", pad, offset, size, *buffer);
|
||||
|
||||
|
@ -1000,10 +1001,12 @@ static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64
|
|||
if (!*buffer)
|
||||
*buffer = new_buffer = gst_buffer_new_and_alloc(size);
|
||||
|
||||
gst_buffer_map(*buffer, &map_info, GST_MAP_WRITE);
|
||||
|
||||
pthread_mutex_lock(&parser->mutex);
|
||||
|
||||
assert(!parser->read_request.buffer);
|
||||
parser->read_request.buffer = *buffer;
|
||||
assert(!parser->read_request.data);
|
||||
parser->read_request.data = map_info.data;
|
||||
parser->read_request.offset = offset;
|
||||
parser->read_request.size = size;
|
||||
parser->read_request.done = false;
|
||||
|
@ -1020,12 +1023,14 @@ static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64
|
|||
|
||||
pthread_mutex_unlock(&parser->mutex);
|
||||
|
||||
GST_LOG("Request returned %s.", gst_flow_get_name(ret));
|
||||
gst_buffer_unmap(*buffer, &map_info);
|
||||
|
||||
if (ret != GST_FLOW_OK && new_buffer)
|
||||
GST_LOG("Request returned %d.", ret);
|
||||
|
||||
if (!ret && new_buffer)
|
||||
gst_buffer_unref(new_buffer);
|
||||
|
||||
return ret;
|
||||
return ret ? GST_FLOW_OK : GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
static gboolean query_function(GstPad *pad, GstObject *parent, GstQuery *query)
|
||||
|
|
Loading…
Reference in New Issue