mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 01:30:38 +00:00
videoencoder: Refactor GstVideoEncoder::reset() handling a bit
Let gst_video_encoder_reset() call it as would be intuitive and only call it indirectly from gst_video_encoder_drain(). Now it actually makes sense.
This commit is contained in:
parent
612a2cf9d0
commit
7074fff7b4
1 changed files with 38 additions and 45 deletions
|
@ -295,14 +295,20 @@ gst_video_encoder_class_init (GstVideoEncoderClass * klass)
|
||||||
klass->negotiate = gst_video_encoder_negotiate_default;
|
klass->negotiate = gst_video_encoder_negotiate_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
gst_video_encoder_reset (GstVideoEncoder * encoder)
|
gst_video_encoder_reset (GstVideoEncoder * encoder, gboolean hard)
|
||||||
{
|
{
|
||||||
|
GstVideoEncoderClass *klass = GST_VIDEO_ENCODER_GET_CLASS (encoder);
|
||||||
GstVideoEncoderPrivate *priv = encoder->priv;
|
GstVideoEncoderPrivate *priv = encoder->priv;
|
||||||
GList *g;
|
gboolean ret = TRUE;
|
||||||
|
|
||||||
GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
|
GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
|
||||||
|
|
||||||
|
if (klass->reset) {
|
||||||
|
GST_DEBUG_OBJECT (encoder, "requesting subclass to reset");
|
||||||
|
ret = klass->reset (encoder, hard);
|
||||||
|
}
|
||||||
|
|
||||||
priv->presentation_frame_number = 0;
|
priv->presentation_frame_number = 0;
|
||||||
priv->distance_from_sync = 0;
|
priv->distance_from_sync = 0;
|
||||||
|
|
||||||
|
@ -312,40 +318,46 @@ gst_video_encoder_reset (GstVideoEncoder * encoder)
|
||||||
priv->force_key_unit = NULL;
|
priv->force_key_unit = NULL;
|
||||||
|
|
||||||
priv->drained = TRUE;
|
priv->drained = TRUE;
|
||||||
priv->min_latency = 0;
|
|
||||||
priv->max_latency = 0;
|
|
||||||
|
|
||||||
g_list_foreach (priv->headers, (GFunc) gst_event_unref, NULL);
|
|
||||||
g_list_free (priv->headers);
|
|
||||||
priv->headers = NULL;
|
|
||||||
priv->new_headers = FALSE;
|
|
||||||
|
|
||||||
g_list_foreach (priv->current_frame_events, (GFunc) gst_event_unref, NULL);
|
g_list_foreach (priv->current_frame_events, (GFunc) gst_event_unref, NULL);
|
||||||
g_list_free (priv->current_frame_events);
|
g_list_free (priv->current_frame_events);
|
||||||
priv->current_frame_events = NULL;
|
priv->current_frame_events = NULL;
|
||||||
|
|
||||||
for (g = priv->frames; g; g = g->next) {
|
g_list_foreach (priv->frames, (GFunc) gst_video_codec_frame_unref, NULL);
|
||||||
gst_video_codec_frame_unref ((GstVideoCodecFrame *) g->data);
|
|
||||||
}
|
|
||||||
g_list_free (priv->frames);
|
g_list_free (priv->frames);
|
||||||
priv->frames = NULL;
|
priv->frames = NULL;
|
||||||
|
|
||||||
priv->bytes = 0;
|
priv->bytes = 0;
|
||||||
priv->time = 0;
|
priv->time = 0;
|
||||||
|
|
||||||
if (priv->input_state)
|
if (hard) {
|
||||||
gst_video_codec_state_unref (priv->input_state);
|
gst_segment_init (&encoder->input_segment, GST_FORMAT_TIME);
|
||||||
priv->input_state = NULL;
|
gst_segment_init (&encoder->output_segment, GST_FORMAT_TIME);
|
||||||
if (priv->output_state)
|
|
||||||
gst_video_codec_state_unref (priv->output_state);
|
|
||||||
priv->output_state = NULL;
|
|
||||||
|
|
||||||
if (priv->tags)
|
if (priv->input_state)
|
||||||
gst_tag_list_unref (priv->tags);
|
gst_video_codec_state_unref (priv->input_state);
|
||||||
priv->tags = NULL;
|
priv->input_state = NULL;
|
||||||
priv->tags_changed = FALSE;
|
if (priv->output_state)
|
||||||
|
gst_video_codec_state_unref (priv->output_state);
|
||||||
|
priv->output_state = NULL;
|
||||||
|
|
||||||
|
if (priv->tags)
|
||||||
|
gst_tag_list_unref (priv->tags);
|
||||||
|
priv->tags = NULL;
|
||||||
|
priv->tags_changed = FALSE;
|
||||||
|
|
||||||
|
priv->min_latency = 0;
|
||||||
|
priv->max_latency = 0;
|
||||||
|
|
||||||
|
g_list_foreach (priv->headers, (GFunc) gst_event_unref, NULL);
|
||||||
|
g_list_free (priv->headers);
|
||||||
|
priv->headers = NULL;
|
||||||
|
priv->new_headers = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
GST_VIDEO_ENCODER_STREAM_UNLOCK (encoder);
|
GST_VIDEO_ENCODER_STREAM_UNLOCK (encoder);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -393,7 +405,7 @@ gst_video_encoder_init (GstVideoEncoder * encoder, GstVideoEncoderClass * klass)
|
||||||
priv->headers = NULL;
|
priv->headers = NULL;
|
||||||
priv->new_headers = FALSE;
|
priv->new_headers = FALSE;
|
||||||
|
|
||||||
gst_video_encoder_reset (encoder);
|
gst_video_encoder_reset (encoder, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -477,10 +489,7 @@ static gboolean
|
||||||
gst_video_encoder_drain (GstVideoEncoder * enc)
|
gst_video_encoder_drain (GstVideoEncoder * enc)
|
||||||
{
|
{
|
||||||
GstVideoEncoderPrivate *priv;
|
GstVideoEncoderPrivate *priv;
|
||||||
GstVideoEncoderClass *enc_class;
|
|
||||||
gboolean ret = TRUE;
|
|
||||||
|
|
||||||
enc_class = GST_VIDEO_ENCODER_GET_CLASS (enc);
|
|
||||||
priv = enc->priv;
|
priv = enc->priv;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (enc, "draining");
|
GST_DEBUG_OBJECT (enc, "draining");
|
||||||
|
@ -490,19 +499,7 @@ gst_video_encoder_drain (GstVideoEncoder * enc)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enc_class->reset) {
|
return gst_video_encoder_reset (enc, FALSE);
|
||||||
GST_DEBUG_OBJECT (enc, "requesting subclass to finish");
|
|
||||||
ret = enc_class->reset (enc, TRUE);
|
|
||||||
}
|
|
||||||
/* everything should be away now */
|
|
||||||
if (priv->frames) {
|
|
||||||
/* not fatal/impossible though if subclass/enc eats stuff */
|
|
||||||
g_list_foreach (priv->frames, (GFunc) gst_video_codec_frame_unref, NULL);
|
|
||||||
g_list_free (priv->frames);
|
|
||||||
priv->frames = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstVideoCodecState *
|
static GstVideoCodecState *
|
||||||
|
@ -861,10 +858,6 @@ gst_video_encoder_finalize (GObject * object)
|
||||||
GST_DEBUG_OBJECT (object, "finalize");
|
GST_DEBUG_OBJECT (object, "finalize");
|
||||||
|
|
||||||
encoder = GST_VIDEO_ENCODER (object);
|
encoder = GST_VIDEO_ENCODER (object);
|
||||||
if (encoder->priv->headers) {
|
|
||||||
g_list_foreach (encoder->priv->headers, (GFunc) gst_buffer_unref, NULL);
|
|
||||||
g_list_free (encoder->priv->headers);
|
|
||||||
}
|
|
||||||
g_rec_mutex_clear (&encoder->stream_lock);
|
g_rec_mutex_clear (&encoder->stream_lock);
|
||||||
|
|
||||||
if (encoder->priv->allocator) {
|
if (encoder->priv->allocator) {
|
||||||
|
@ -1395,7 +1388,7 @@ gst_video_encoder_change_state (GstElement * element, GstStateChange transition)
|
||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
gst_video_encoder_reset (encoder);
|
gst_video_encoder_reset (encoder, TRUE);
|
||||||
if (encoder_class->stop && !encoder_class->stop (encoder))
|
if (encoder_class->stop && !encoder_class->stop (encoder))
|
||||||
goto stop_failed;
|
goto stop_failed;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue