Skip to content

Commit

Permalink
Merge pull request #57 from fluendo/RDI-2126
Browse files Browse the repository at this point in the history
RDI-2126 Fix codecs sample playback until the end
  • Loading branch information
aslobodeniuk authored Nov 5, 2024
2 parents d920b37 + 8e79c2b commit 982f69c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ gst_web_video_frame_allocator_free (GstAllocator *allocator, GstMemory *memory)
/* FIXME can be async */
gst_web_runner_send_message (
self->priv->runner, gst_web_video_frame_close, &close_data);

gst_object_unref (self->priv->runner);
self->priv->video_frame = val::undefined ();
g_free (self->priv);
}

static void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

using namespace emscripten;

#define GST_WEB_CODECS_VIDEO_DECODER_MAX_DEQUEUE 32

#define GST_WEB_CODECS_VIDEO_DECODER_FROM_JS \
reinterpret_cast<GstWebCodecsVideoDecoder *> ( \
val::module_property ("self").as<int> ())
Expand Down Expand Up @@ -164,10 +166,6 @@ gst_web_codecs_video_decoder_on_output (val video_frame)
val vf_timestamp;

GST_INFO_OBJECT (self, "VideoFrame Received");
g_mutex_lock (&self->dequeue_lock);
self->has_video_frame = TRUE;
g_cond_signal (&self->dequeue_cond);
g_mutex_unlock (&self->dequeue_lock);

GST_VIDEO_DECODER_STREAM_LOCK (self);
frame = gst_video_decoder_get_oldest_frame (GST_VIDEO_DECODER (self));
Expand Down Expand Up @@ -226,11 +224,6 @@ gst_web_codecs_video_decoder_on_output (val video_frame)
if (frame)
gst_video_codec_frame_unref (frame);

g_mutex_lock (&self->dequeue_lock);
self->has_video_frame = FALSE;
g_cond_signal (&self->dequeue_cond);
g_mutex_unlock (&self->dequeue_lock);

GST_VIDEO_DECODER_STREAM_UNLOCK (self);
}

Expand Down Expand Up @@ -409,15 +402,16 @@ gst_web_codecs_video_decoder_handle_frame (
GST_DEBUG_OBJECT (decoder, "Handling frame");
/* Wait until there is nothing pending to be to dequeued or there is a buffer
*/
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
g_mutex_lock (&self->dequeue_lock);
while (self->dequeue_size && !self->has_video_frame) {
GST_INFO_OBJECT (self,
"Waiting until everything is dequeued, pending: %d, has_video_frame: "
"%d",
self->dequeue_size, self->has_video_frame);
while (self->dequeue_size >= GST_WEB_CODECS_VIDEO_DECODER_MAX_DEQUEUE) {
GST_DEBUG_OBJECT (self, "Reached queue limit [%d/%d], waiting for dequeue",
self->dequeue_size, GST_WEB_CODECS_VIDEO_DECODER_MAX_DEQUEUE);
g_cond_wait (&self->dequeue_cond, &self->dequeue_lock);
}
self->dequeue_size++;
g_mutex_unlock (&self->dequeue_lock);
GST_VIDEO_DECODER_STREAM_LOCK (self);

/* We are ready to process data */
GST_DEBUG_OBJECT (self, "Ready to process more data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ struct _GstWebCodecsVideoDecoder
gboolean need_negotiation;

emscripten::val decoder;
/* The size of the output frames pending to be dequeued */
/* Amount of the output frames pending to be dequeued */
gint dequeue_size;
/* In case we receive a VideoFrame, in order to allow the
* blocked stream lock to continue despite the dequeue size */
gboolean has_video_frame;
GMutex dequeue_lock;
GCond dequeue_cond;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ gst_web_canvas_sink_draw_video_frame (gpointer data)
self->val_context.call<void> ("drawImage", video_frame, 0, 0,
video_frame["displayWidth"], video_frame["displayHeight"], 0, 0,
self->val_canvas["width"], self->val_canvas["height"]);
gst_memory_unref (GST_MEMORY_CAST (vf));
}
static void
Expand Down

0 comments on commit 982f69c

Please sign in to comment.