theora: separate encode and push block in chain, into own function.

This commit is contained in:
Luis de Bethencourt 2011-06-03 16:29:00 +02:00 committed by Sebastian Dröge
parent 407b77740e
commit 8b18508778

View file

@ -1143,6 +1143,83 @@ theora_enc_write_multipass_cache (GstTheoraEnc * enc, gboolean begin,
return TRUE;
}
static GstFlowReturn
theora_enc_encode_and_push (GstTheoraEnc * enc, ogg_packet op,
GstClockTime timestamp, GstClockTime running_time,
GstClockTime duration, GstBuffer * buffer)
{
GstFlowReturn ret;
th_ycbcr_buffer ycbcr;
gint res;
theora_enc_init_buffer (ycbcr, &enc->info, GST_BUFFER_DATA (buffer));
if (theora_enc_is_discontinuous (enc, running_time, duration)) {
theora_enc_reset (enc);
enc->granulepos_offset =
gst_util_uint64_scale (running_time, enc->fps_n,
GST_SECOND * enc->fps_d);
enc->timestamp_offset = running_time;
enc->next_ts = 0;
enc->next_discont = TRUE;
}
if (enc->multipass_cache_fd
&& enc->multipass_mode == MULTIPASS_MODE_SECOND_PASS) {
if (!theora_enc_read_multipass_cache (enc)) {
ret = GST_FLOW_ERROR;
goto multipass_read_failed;
}
}
res = th_encode_ycbcr_in (enc->encoder, ycbcr);
/* none of the failure cases can happen here */
g_assert (res == 0);
if (enc->multipass_cache_fd
&& enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) {
if (!theora_enc_write_multipass_cache (enc, FALSE, FALSE)) {
ret = GST_FLOW_ERROR;
goto multipass_write_failed;
}
}
ret = GST_FLOW_OK;
while (th_encode_packetout (enc->encoder, 0, &op)) {
GstClockTime next_time;
next_time = th_granule_time (enc->encoder, op.granulepos) * GST_SECOND;
ret =
theora_push_packet (enc, &op, timestamp, enc->next_ts,
next_time - enc->next_ts);
enc->next_ts = next_time;
if (ret != GST_FLOW_OK)
goto data_push;
}
gst_buffer_unref (buffer);
return ret;
/* ERRORS */
multipass_read_failed:
{
gst_buffer_unref (buffer);
return ret;
}
multipass_write_failed:
{
gst_buffer_unref (buffer);
return ret;
}
data_push:
{
gst_buffer_unref (buffer);
return ret;
}
}
static GstFlowReturn
theora_enc_chain (GstPad * pad, GstBuffer * buffer)
{
@ -1291,72 +1368,12 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
enc->next_ts = 0;
}
{
th_ycbcr_buffer ycbcr;
gint res;
theora_enc_init_buffer (ycbcr, &enc->info, GST_BUFFER_DATA (buffer));
if (theora_enc_is_discontinuous (enc, running_time, duration)) {
theora_enc_reset (enc);
enc->granulepos_offset =
gst_util_uint64_scale (running_time, enc->fps_n,
GST_SECOND * enc->fps_d);
enc->timestamp_offset = running_time;
enc->next_ts = 0;
enc->next_discont = TRUE;
}
if (enc->multipass_cache_fd
&& enc->multipass_mode == MULTIPASS_MODE_SECOND_PASS) {
if (!theora_enc_read_multipass_cache (enc)) {
ret = GST_FLOW_ERROR;
goto multipass_read_failed;
}
}
res = th_encode_ycbcr_in (enc->encoder, ycbcr);
/* none of the failure cases can happen here */
g_assert (res == 0);
if (enc->multipass_cache_fd
&& enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) {
if (!theora_enc_write_multipass_cache (enc, FALSE, FALSE)) {
ret = GST_FLOW_ERROR;
goto multipass_write_failed;
}
}
ret = GST_FLOW_OK;
while (th_encode_packetout (enc->encoder, 0, &op)) {
GstClockTime next_time;
next_time = th_granule_time (enc->encoder, op.granulepos) * GST_SECOND;
ret =
theora_push_packet (enc, &op, timestamp, enc->next_ts,
next_time - enc->next_ts);
enc->next_ts = next_time;
if (ret != GST_FLOW_OK)
goto data_push;
}
gst_buffer_unref (buffer);
}
ret = theora_enc_encode_and_push (enc, op, timestamp, running_time, duration,
buffer);
return ret;
/* ERRORS */
multipass_read_failed:
{
gst_buffer_unref (buffer);
return ret;
}
multipass_write_failed:
{
gst_buffer_unref (buffer);
return ret;
}
header_buffer_alloc:
{
gst_buffer_unref (buffer);
@ -1367,11 +1384,6 @@ header_push:
gst_buffer_unref (buffer);
return ret;
}
data_push:
{
gst_buffer_unref (buffer);
return ret;
}
encoder_disabled:
{
GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL),