gint CloseZStream (ZStream *zstream) { gint status; gint flush_status; if (zstream == NULL) return ARGUMENT_ERROR; status = 0; if (zstream->compress) { if (zstream->stream->total_in > 0) { do { status = deflate (zstream->stream, Z_FINISH); flush_status = flush_internal (zstream, TRUE); } while (status == Z_OK); /* We want Z_STREAM_END or error here here */ if (status == Z_STREAM_END) status = flush_status; } deflateEnd (zstream->stream); } else { inflateEnd (zstream->stream); } g_free (zstream->buffer); g_free (zstream->stream); memset (zstream, 0, sizeof (ZStream)); g_free (zstream); return status; }
static gboolean handle_queued_objects (APP_STATE_T * state) { GstMiniObject *object = NULL; g_mutex_lock (&state->queue_lock); if (state->flushing) { g_cond_broadcast (&state->cond); goto beach; } else if (g_async_queue_length (state->queue) == 0) { goto beach; } if ((object = g_async_queue_try_pop (state->queue))) { if (GST_IS_BUFFER (object)) { GstBuffer *buffer = GST_BUFFER_CAST (object); update_image (state, buffer); render_scene (state); gst_buffer_unref (buffer); if (!SYNC_BUFFERS) { object = NULL; } } else if (GST_IS_QUERY (object)) { GstQuery *query = GST_QUERY_CAST (object); GstStructure *s = (GstStructure *) gst_query_get_structure (query); if (gst_structure_has_name (s, "not-used")) { g_assert_not_reached (); } else { g_assert_not_reached (); } } else if (GST_IS_EVENT (object)) { GstEvent *event = GST_EVENT_CAST (object); g_print ("\nevent %p %s\n", event, gst_event_type_get_name (GST_EVENT_TYPE (event))); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: flush_internal (state); break; default: break; } gst_event_unref (event); object = NULL; } } if (object) { state->popped_obj = object; g_cond_broadcast (&state->cond); } beach: g_mutex_unlock (&state->queue_lock); return FALSE; }
static void flush_stop (APP_STATE_T * state) { GstMiniObject *object = NULL; g_mutex_lock (state->queue_lock); while ((object = GST_MINI_OBJECT_CAST (g_async_queue_try_pop (state->queue)))) { gst_mini_object_unref (object); } flush_internal (state); state->popped_obj = NULL; state->flushing = FALSE; g_mutex_unlock (state->queue_lock); }
static GstPadProbeReturn query_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) { APP_STATE_T *state = (APP_STATE_T *) user_data; GstQuery *query = GST_PAD_PROBE_INFO_QUERY (info); GstStructure *external_gl_context_desc = NULL; gchar *platform = NULL; gchar *gl_apis = NULL; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_ALLOCATION: { platform = gst_gl_platform_to_string (GST_GL_PLATFORM_EGL); gl_apis = gst_gl_api_to_string (GST_GL_API_GLES2); external_gl_context_desc = gst_structure_new ("GstVideoGLTextureUploadMeta", "gst.gl.context.handle", G_TYPE_POINTER, state->context, "gst.gl.context.type", G_TYPE_STRING, platform, "gst.gl.context.apis", G_TYPE_STRING, gl_apis, NULL); gst_query_add_allocation_meta (query, GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, external_gl_context_desc); gst_structure_free (external_gl_context_desc); g_free (gl_apis); g_free (platform); GST_DEBUG ("done alocation"); return GST_PAD_PROBE_OK; break; } case GST_QUERY_CONTEXT: { return gst_gl_handle_context_query (state->pipeline, query, (GstGLDisplay **) & state->gst_display); break; } case GST_QUERY_DRAIN: { flush_internal (state); break; } default: break; } return GST_PAD_PROBE_OK; }
static void flush_start (APP_STATE_T * state) { GstMiniObject *object = NULL; g_mutex_lock (state->queue_lock); state->flushing = TRUE; g_cond_broadcast (state->cond); g_mutex_unlock (state->queue_lock); while ((object = g_async_queue_try_pop (state->queue))) { gst_mini_object_unref (object); } g_mutex_lock (state->queue_lock); flush_internal (state); state->popped_obj = NULL; g_mutex_unlock (state->queue_lock); }
static gboolean handle_queued_objects (APP_STATE_T * state) { GstMiniObject *object = NULL; g_mutex_lock (state->queue_lock); if (state->flushing) { g_cond_broadcast (state->cond); goto beach; } else if (g_async_queue_length (state->queue) == 0) { goto beach; } if ((object = g_async_queue_try_pop (state->queue))) { if (GST_IS_BUFFER (object)) { GstBuffer *buffer = GST_BUFFER_CAST (object); update_image (state, buffer); render_scene (state); gst_buffer_unref (buffer); if (!SYNC_BUFFERS) { object = NULL; } } else if (GST_IS_QUERY (object)) { GstQuery *query = GST_QUERY_CAST (object); GstStructure *s = (GstStructure *) gst_query_get_structure (query); if (gst_structure_has_name (s, "eglglessink-allocate-eglimage")) { GstBuffer *buffer; GstVideoFormat format; gint width, height; GValue v = { 0, }; if (!gst_structure_get_enum (s, "format", GST_TYPE_VIDEO_FORMAT, (gint *) & format) || !gst_structure_get_int (s, "width", &width) || !gst_structure_get_int (s, "height", &height)) { g_assert_not_reached (); } buffer = gst_egl_allocate_eglimage (state, GST_EGL_IMAGE_BUFFER_POOL (state->pool)->allocator, format, width, height); g_value_init (&v, G_TYPE_POINTER); g_value_set_pointer (&v, buffer); gst_structure_set_value (s, "buffer", &v); g_value_unset (&v); } else { g_assert_not_reached (); } } else if (GST_IS_EVENT (object)) { GstEvent *event = GST_EVENT_CAST (object); g_print ("\nevent %p %s\n", event, gst_event_type_get_name (GST_EVENT_TYPE (event))); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: flush_internal (state); break; default: break; } gst_event_unref (event); object = NULL; } } if (object) { state->popped_obj = object; g_cond_broadcast (state->cond); } beach: g_mutex_unlock (state->queue_lock); return FALSE; }
gint Flush (ZStream *stream) { return flush_internal (stream, FALSE); }