Commit 8b185087 authored by Luis de Bethencourt's avatar Luis de Bethencourt Committed by Sebastian Dröge
Browse files

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

parent 407b7774
......@@ -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),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment