theora: Use new video codec base classes' flush vfunc

This commit is contained in:
Sebastian Dröge 2013-08-15 13:15:05 +02:00
parent 695675ab7e
commit 5bd27953b4
2 changed files with 84 additions and 73 deletions

View file

@ -99,9 +99,10 @@ static void theora_dec_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static gboolean theora_dec_start (GstVideoDecoder * decoder);
static gboolean theora_dec_stop (GstVideoDecoder * decoder);
static gboolean theora_dec_set_format (GstVideoDecoder * decoder,
GstVideoCodecState * state);
static gboolean theora_dec_reset (GstVideoDecoder * decoder, gboolean hard);
static gboolean theora_dec_flush (GstVideoDecoder * decoder);
static GstFlowReturn theora_dec_parse (GstVideoDecoder * decoder,
GstVideoCodecFrame * frame, GstAdapter * adapter, gboolean at_eos);
static GstFlowReturn theora_dec_handle_frame (GstVideoDecoder * decoder,
@ -183,7 +184,8 @@ gst_theora_dec_class_init (GstTheoraDecClass * klass)
"Benjamin Otte <otte@gnome.org>, Wim Taymans <wim@fluendo.com>");
video_decoder_class->start = GST_DEBUG_FUNCPTR (theora_dec_start);
video_decoder_class->reset = GST_DEBUG_FUNCPTR (theora_dec_reset);
video_decoder_class->stop = GST_DEBUG_FUNCPTR (theora_dec_stop);
video_decoder_class->flush = GST_DEBUG_FUNCPTR (theora_dec_flush);
video_decoder_class->set_format = GST_DEBUG_FUNCPTR (theora_dec_set_format);
video_decoder_class->parse = GST_DEBUG_FUNCPTR (theora_dec_parse);
video_decoder_class->handle_frame =
@ -215,40 +217,49 @@ theora_dec_start (GstVideoDecoder * decoder)
GST_DEBUG_OBJECT (dec, "start");
GST_DEBUG_OBJECT (dec, "Setting have_header to FALSE");
dec->have_header = FALSE;
dec->can_crop = FALSE;
return TRUE;
}
static gboolean
theora_dec_reset (GstVideoDecoder * decoder, gboolean hard)
theora_dec_stop (GstVideoDecoder * decoder)
{
GstTheoraDec *dec = GST_THEORA_DEC (decoder);
GST_DEBUG_OBJECT (dec, "stop");
th_info_clear (&dec->info);
th_comment_clear (&dec->comment);
if (dec->setup) {
th_setup_free (dec->setup);
dec->setup = NULL;
}
if (dec->decoder) {
th_decode_free (dec->decoder);
dec->decoder = NULL;
}
if (dec->input_state) {
gst_video_codec_state_unref (dec->input_state);
dec->input_state = NULL;
}
if (dec->output_state) {
gst_video_codec_state_unref (dec->output_state);
dec->output_state = NULL;
}
dec->can_crop = FALSE;
return TRUE;
}
static gboolean
theora_dec_flush (GstVideoDecoder * decoder)
{
GstTheoraDec *dec = GST_THEORA_DEC (decoder);
dec->need_keyframe = TRUE;
if (hard) {
th_info_clear (&dec->info);
th_comment_clear (&dec->comment);
if (dec->setup) {
th_setup_free (dec->setup);
dec->setup = NULL;
}
if (dec->decoder) {
th_decode_free (dec->decoder);
dec->decoder = NULL;
}
if (dec->input_state) {
gst_video_codec_state_unref (dec->input_state);
dec->input_state = NULL;
}
if (dec->output_state) {
gst_video_codec_state_unref (dec->output_state);
dec->output_state = NULL;
}
dec->can_crop = FALSE;
}
return TRUE;
}

View file

@ -177,7 +177,7 @@ G_DEFINE_TYPE (GstTheoraEnc, gst_theora_enc, GST_TYPE_VIDEO_ENCODER);
static gboolean theora_enc_start (GstVideoEncoder * enc);
static gboolean theora_enc_stop (GstVideoEncoder * enc);
static gboolean theora_enc_reset (GstVideoEncoder * enc, gboolean hard);
static gboolean theora_enc_flush (GstVideoEncoder * enc);
static gboolean theora_enc_set_format (GstVideoEncoder * enc,
GstVideoCodecState * state);
static GstFlowReturn theora_enc_handle_frame (GstVideoEncoder * enc,
@ -222,7 +222,7 @@ gst_theora_enc_class_init (GstTheoraEncClass * klass)
gstvideo_encoder_class->start = GST_DEBUG_FUNCPTR (theora_enc_start);
gstvideo_encoder_class->stop = GST_DEBUG_FUNCPTR (theora_enc_stop);
gstvideo_encoder_class->reset = GST_DEBUG_FUNCPTR (theora_enc_reset);
gstvideo_encoder_class->flush = GST_DEBUG_FUNCPTR (theora_enc_flush);
gstvideo_encoder_class->set_format =
GST_DEBUG_FUNCPTR (theora_enc_set_format);
gstvideo_encoder_class->handle_frame =
@ -358,7 +358,7 @@ theora_enc_finalize (GObject * object)
}
static gboolean
theora_enc_reset (GstVideoEncoder * encoder, gboolean hard)
theora_enc_flush (GstVideoEncoder * encoder)
{
GstTheoraEnc *enc = GST_THEORA_ENC (encoder);
ogg_uint32_t keyframe_force;
@ -374,54 +374,41 @@ theora_enc_reset (GstVideoEncoder * encoder, gboolean hard)
if (enc->encoder)
th_encode_free (enc->encoder);
if (!hard) {
enc->encoder = th_encode_alloc (&enc->info);
/* We ensure this function cannot fail. */
g_assert (enc->encoder != NULL);
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_SPLEVEL, &enc->speed_level,
sizeof (enc->speed_level));
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_VP3_COMPATIBLE,
&enc->vp3_compatible, sizeof (enc->vp3_compatible));
enc->encoder = th_encode_alloc (&enc->info);
/* We ensure this function cannot fail. */
g_assert (enc->encoder != NULL);
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_SPLEVEL, &enc->speed_level,
sizeof (enc->speed_level));
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_VP3_COMPATIBLE,
&enc->vp3_compatible, sizeof (enc->vp3_compatible));
rate_flags = 0;
if (enc->drop_frames)
rate_flags |= TH_RATECTL_DROP_FRAMES;
if (enc->drop_frames)
rate_flags |= TH_RATECTL_CAP_OVERFLOW;
if (enc->drop_frames)
rate_flags |= TH_RATECTL_CAP_UNDERFLOW;
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_RATE_FLAGS,
&rate_flags, sizeof (rate_flags));
rate_flags = 0;
if (enc->drop_frames)
rate_flags |= TH_RATECTL_DROP_FRAMES;
if (enc->drop_frames)
rate_flags |= TH_RATECTL_CAP_OVERFLOW;
if (enc->drop_frames)
rate_flags |= TH_RATECTL_CAP_UNDERFLOW;
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_RATE_FLAGS,
&rate_flags, sizeof (rate_flags));
if (enc->rate_buffer) {
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_RATE_BUFFER,
&enc->rate_buffer, sizeof (enc->rate_buffer));
} else {
/* FIXME */
}
keyframe_force = enc->keyframe_auto ?
enc->keyframe_force : enc->keyframe_freq;
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
&keyframe_force, sizeof (keyframe_force));
/* Get placeholder data */
if (enc->multipass_cache_fd
&& enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS)
theora_enc_write_multipass_cache (enc, TRUE, FALSE);
if (enc->rate_buffer) {
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_RATE_BUFFER,
&enc->rate_buffer, sizeof (enc->rate_buffer));
} else {
enc->encoder = NULL;
th_comment_clear (&enc->comment);
th_info_clear (&enc->info);
if (enc->input_state)
gst_video_codec_state_unref (enc->input_state);
enc->input_state = NULL;
enc->packetno = 0;
enc->initialised = FALSE;
/* FIXME */
}
keyframe_force = enc->keyframe_auto ?
enc->keyframe_force : enc->keyframe_freq;
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
&keyframe_force, sizeof (keyframe_force));
/* Get placeholder data */
if (enc->multipass_cache_fd
&& enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS)
theora_enc_write_multipass_cache (enc, TRUE, FALSE);
return TRUE;
}
@ -457,6 +444,9 @@ theora_enc_start (GstVideoEncoder * benc)
g_io_channel_set_encoding (enc->multipass_cache_fd, NULL, NULL);
}
enc->packetno = 0;
enc->initialised = FALSE;
return TRUE;
}
@ -468,6 +458,16 @@ theora_enc_stop (GstVideoEncoder * benc)
GST_DEBUG_OBJECT (benc, "stop: clearing theora state");
enc = GST_THEORA_ENC (benc);
if (enc->encoder)
th_encode_free (enc->encoder);
enc->encoder = NULL;
th_comment_clear (&enc->comment);
th_info_clear (&enc->info);
if (enc->input_state)
gst_video_codec_state_unref (enc->input_state);
enc->input_state = NULL;
/* Everything else is handled in reset() */
theora_enc_clear_multipass_cache (enc);
@ -596,7 +596,7 @@ theora_enc_set_format (GstVideoEncoder * benc, GstVideoCodecState * state)
"keyframe_frequency_force is %d, granule shift is %d",
enc->keyframe_force, enc->info.keyframe_granule_shift);
theora_enc_reset (benc, FALSE);
theora_enc_flush (benc);
enc->initialised = TRUE;
return TRUE;