mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 19:21:06 +00:00
unixfd: Allow sending buffers with no memories
There is no reason to not allow it, and it is useful for simple unit test. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6747>
This commit is contained in:
parent
b370afab76
commit
5593a3c698
1 changed files with 45 additions and 40 deletions
|
@ -90,17 +90,10 @@ typedef struct
|
|||
} BufferContext;
|
||||
|
||||
static void
|
||||
memory_weak_ref_cb (GstUnixFdSrc * self, GstMemory * mem)
|
||||
release_buffer (GstUnixFdSrc * self, guint64 id)
|
||||
{
|
||||
GST_OBJECT_LOCK (self);
|
||||
|
||||
BufferContext *ctx = g_hash_table_lookup (self->memories, mem);
|
||||
if (ctx == NULL)
|
||||
goto out;
|
||||
|
||||
if (--ctx->n_memory == 0) {
|
||||
/* Notify that we are not using this buffer anymore */
|
||||
ReleaseBufferPayload payload = { ctx->id };
|
||||
ReleaseBufferPayload payload = { id };
|
||||
GError *error = NULL;
|
||||
if (!gst_unix_fd_send_command (self->socket, COMMAND_TYPE_RELEASE_BUFFER,
|
||||
NULL, (guint8 *) & payload, sizeof (payload), &error)) {
|
||||
|
@ -108,12 +101,22 @@ memory_weak_ref_cb (GstUnixFdSrc * self, GstMemory * mem)
|
|||
error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
g_free (ctx);
|
||||
}
|
||||
|
||||
g_hash_table_remove (self->memories, mem);
|
||||
static void
|
||||
memory_weak_ref_cb (GstUnixFdSrc * self, GstMemory * mem)
|
||||
{
|
||||
GST_OBJECT_LOCK (self);
|
||||
|
||||
BufferContext *ctx = g_hash_table_lookup (self->memories, mem);
|
||||
if (ctx != NULL) {
|
||||
if (--ctx->n_memory == 0) {
|
||||
release_buffer (self, ctx->id);
|
||||
g_free (ctx);
|
||||
}
|
||||
g_hash_table_remove (self->memories, mem);
|
||||
}
|
||||
|
||||
out:
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
}
|
||||
|
||||
|
@ -335,33 +338,26 @@ again:
|
|||
goto on_error;
|
||||
}
|
||||
|
||||
if (fds == NULL) {
|
||||
GST_ERROR_OBJECT (self,
|
||||
"Received new buffer command without file descriptors");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
if (g_unix_fd_list_get_length (fds) != new_buffer->n_memory) {
|
||||
gint fds_arr_len = 0;
|
||||
gint *fds_arr =
|
||||
(fds != NULL) ? g_unix_fd_list_steal_fds (fds, &fds_arr_len) : NULL;
|
||||
if (fds_arr_len != new_buffer->n_memory) {
|
||||
GST_ERROR_OBJECT (self,
|
||||
"Received new buffer command with %d file descriptors instead of "
|
||||
"%d", g_unix_fd_list_get_length (fds), new_buffer->n_memory);
|
||||
"%d", fds_arr_len, new_buffer->n_memory);
|
||||
ret = GST_FLOW_ERROR;
|
||||
g_free (fds_arr);
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if (new_buffer->type >= MEMORY_TYPE_LAST) {
|
||||
GST_ERROR_OBJECT (self, "Unknown buffer type %d", new_buffer->type);
|
||||
ret = GST_FLOW_ERROR;
|
||||
g_free (fds_arr);
|
||||
goto on_error;
|
||||
}
|
||||
GstAllocator *allocator = self->allocators[new_buffer->type];
|
||||
|
||||
gint *fds_arr = g_unix_fd_list_steal_fds (fds, NULL);
|
||||
|
||||
BufferContext *ctx = g_new0 (BufferContext, 1);
|
||||
ctx->id = new_buffer->id;
|
||||
ctx->n_memory = new_buffer->n_memory;
|
||||
|
||||
*outbuf = gst_buffer_new ();
|
||||
|
||||
GstClockTime base_time =
|
||||
|
@ -394,6 +390,10 @@ again:
|
|||
}
|
||||
|
||||
GST_OBJECT_LOCK (self);
|
||||
if (new_buffer->n_memory > 0) {
|
||||
BufferContext *ctx = g_new0 (BufferContext, 1);
|
||||
ctx->id = new_buffer->id;
|
||||
ctx->n_memory = new_buffer->n_memory;
|
||||
for (int i = 0; i < new_buffer->n_memory; i++) {
|
||||
GstMemory *mem = gst_fd_allocator_alloc (allocator, fds_arr[i],
|
||||
new_buffer->memories[i].size, GST_FD_MEMORY_FLAG_NONE);
|
||||
|
@ -407,6 +407,11 @@ again:
|
|||
|
||||
gst_buffer_append_memory (*outbuf, mem);
|
||||
}
|
||||
} else {
|
||||
/* This buffer has no memories, we can release it immediately otherwise
|
||||
* it gets leaked. */
|
||||
release_buffer (self, new_buffer->id);
|
||||
}
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
|
||||
g_free (fds_arr);
|
||||
|
|
Loading…
Reference in a new issue