mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:36:20 +00:00
ext/theora/theoraenc.c: Some cleanups, make sure the timestamps are correct.
Original commit message from CVS: * ext/theora/theoraenc.c: (gst_theora_enc_class_init), (theora_enc_sink_link), (theora_buffer_from_packet), (theora_push_packet), (theora_enc_chain): Some cleanups, make sure the timestamps are correct.
This commit is contained in:
parent
148c90439a
commit
01226c6e8d
2 changed files with 34 additions and 15 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2004-06-22 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
|
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
|
||||||
|
(theora_enc_sink_link), (theora_buffer_from_packet),
|
||||||
|
(theora_push_packet), (theora_enc_chain):
|
||||||
|
Some cleanups, make sure the timestamps are correct.
|
||||||
|
|
||||||
2004-06-22 Wim Taymans <wim@fluendo.com>
|
2004-06-22 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
* ext/alsa/gstalsa.c: (gst_alsa_get_time), (gst_alsa_clock_update),
|
* ext/alsa/gstalsa.c: (gst_alsa_get_time), (gst_alsa_clock_update),
|
||||||
|
|
|
@ -69,6 +69,7 @@ struct _GstTheoraEnc
|
||||||
|
|
||||||
guint packetno;
|
guint packetno;
|
||||||
guint64 bytes_out;
|
guint64 bytes_out;
|
||||||
|
guint64 next_ts;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstTheoraEncClass
|
struct _GstTheoraEncClass
|
||||||
|
@ -278,7 +279,8 @@ theora_enc_sink_link (GstPad * pad, const GstCaps * caps)
|
||||||
|
|
||||||
/* prepare a buffer for transmission by passing data through libtheora */
|
/* prepare a buffer for transmission by passing data through libtheora */
|
||||||
static GstBuffer *
|
static GstBuffer *
|
||||||
theora_buffer_from_packet (GstTheoraEnc * enc, ogg_packet * packet)
|
theora_buffer_from_packet (GstTheoraEnc * enc, ogg_packet * packet,
|
||||||
|
GstClockTime timestamp, GstClockTime duration)
|
||||||
{
|
{
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
|
|
||||||
|
@ -287,9 +289,8 @@ theora_buffer_from_packet (GstTheoraEnc * enc, ogg_packet * packet)
|
||||||
memcpy (GST_BUFFER_DATA (buf), packet->packet, packet->bytes);
|
memcpy (GST_BUFFER_DATA (buf), packet->packet, packet->bytes);
|
||||||
GST_BUFFER_OFFSET (buf) = enc->bytes_out;
|
GST_BUFFER_OFFSET (buf) = enc->bytes_out;
|
||||||
GST_BUFFER_OFFSET_END (buf) = packet->granulepos;
|
GST_BUFFER_OFFSET_END (buf) = packet->granulepos;
|
||||||
GST_BUFFER_TIMESTAMP (buf) =
|
GST_BUFFER_TIMESTAMP (buf) = timestamp;
|
||||||
theora_granule_time (&enc->state, packet->granulepos) * GST_SECOND;
|
GST_BUFFER_DURATION (buf) = duration;
|
||||||
GST_BUFFER_DURATION (buf) = GST_SECOND / enc->fps;
|
|
||||||
|
|
||||||
enc->packetno++;
|
enc->packetno++;
|
||||||
|
|
||||||
|
@ -310,11 +311,12 @@ theora_push_buffer (GstTheoraEnc * enc, GstBuffer * buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
theora_push_packet (GstTheoraEnc * enc, ogg_packet * packet)
|
theora_push_packet (GstTheoraEnc * enc, ogg_packet * packet,
|
||||||
|
GstClockTime timestamp, GstClockTime duration)
|
||||||
{
|
{
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
|
|
||||||
buf = theora_buffer_from_packet (enc, packet);
|
buf = theora_buffer_from_packet (enc, packet, timestamp, duration);
|
||||||
theora_push_buffer (enc, buf);
|
theora_push_buffer (enc, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,20 +356,28 @@ theora_enc_chain (GstPad * pad, GstData * data)
|
||||||
{
|
{
|
||||||
GstTheoraEnc *enc;
|
GstTheoraEnc *enc;
|
||||||
ogg_packet op;
|
ogg_packet op;
|
||||||
|
GstBuffer *buf;
|
||||||
|
GstClockTime in_time;
|
||||||
|
|
||||||
enc = GST_THEORA_ENC (gst_pad_get_parent (pad));
|
enc = GST_THEORA_ENC (gst_pad_get_parent (pad));
|
||||||
if (GST_IS_EVENT (data)) {
|
if (GST_IS_EVENT (data)) {
|
||||||
switch (GST_EVENT_TYPE (data)) {
|
switch (GST_EVENT_TYPE (data)) {
|
||||||
case GST_EVENT_EOS:
|
case GST_EVENT_EOS:
|
||||||
/* push last packet with eos flag */
|
/* push last packet with eos flag */
|
||||||
if (theora_encode_packetout (&enc->state, 1, &op))
|
while (theora_encode_packetout (&enc->state, 1, &op)) {
|
||||||
theora_push_packet (enc, &op);
|
GstClockTime out_time =
|
||||||
|
theora_granule_time (&enc->state, op.granulepos) * GST_SECOND;
|
||||||
|
theora_push_packet (enc, &op, out_time, GST_SECOND / enc->fps);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
gst_pad_event_default (pad, GST_EVENT (data));
|
gst_pad_event_default (pad, GST_EVENT (data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf = GST_BUFFER (data);
|
||||||
|
in_time = GST_BUFFER_TIMESTAMP (buf);
|
||||||
|
|
||||||
/* no packets written yet, setup headers */
|
/* no packets written yet, setup headers */
|
||||||
/* Theora streams begin with three headers; the initial header (with
|
/* Theora streams begin with three headers; the initial header (with
|
||||||
most of the codec setup parameters) which is mandated by the Ogg
|
most of the codec setup parameters) which is mandated by the Ogg
|
||||||
|
@ -380,17 +390,16 @@ theora_enc_chain (GstPad * pad, GstData * data)
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GstBuffer *buf1, *buf2, *buf3;
|
GstBuffer *buf1, *buf2, *buf3;
|
||||||
|
|
||||||
|
|
||||||
/* first packet will get its own page automatically */
|
/* first packet will get its own page automatically */
|
||||||
theora_encode_header (&enc->state, &op);
|
theora_encode_header (&enc->state, &op);
|
||||||
buf1 = theora_buffer_from_packet (enc, &op);
|
buf1 = theora_buffer_from_packet (enc, &op, 0, 0);
|
||||||
|
|
||||||
/* create the remaining theora headers */
|
/* create the remaining theora headers */
|
||||||
theora_comment_init (&enc->comment);
|
theora_comment_init (&enc->comment);
|
||||||
theora_encode_comment (&enc->comment, &op);
|
theora_encode_comment (&enc->comment, &op);
|
||||||
buf2 = theora_buffer_from_packet (enc, &op);
|
buf2 = theora_buffer_from_packet (enc, &op, 0, 0);
|
||||||
theora_encode_tables (&enc->state, &op);
|
theora_encode_tables (&enc->state, &op);
|
||||||
buf3 = theora_buffer_from_packet (enc, &op);
|
buf3 = theora_buffer_from_packet (enc, &op, 0, 0);
|
||||||
|
|
||||||
/* mark buffers and put on caps */
|
/* mark buffers and put on caps */
|
||||||
caps = gst_pad_get_caps (enc->srcpad);
|
caps = gst_pad_get_caps (enc->srcpad);
|
||||||
|
@ -415,7 +424,7 @@ theora_enc_chain (GstPad * pad, GstData * data)
|
||||||
gint y_size;
|
gint y_size;
|
||||||
guchar *pixels;
|
guchar *pixels;
|
||||||
|
|
||||||
pixels = GST_BUFFER_DATA (GST_BUFFER (data));
|
pixels = GST_BUFFER_DATA (buf);
|
||||||
|
|
||||||
yuv.y_width = enc->width;
|
yuv.y_width = enc->width;
|
||||||
yuv.y_height = enc->height;
|
yuv.y_height = enc->height;
|
||||||
|
@ -432,8 +441,11 @@ theora_enc_chain (GstPad * pad, GstData * data)
|
||||||
yuv.v = pixels + y_size * 5 / 4;
|
yuv.v = pixels + y_size * 5 / 4;
|
||||||
|
|
||||||
theora_encode_YUVin (&enc->state, &yuv);
|
theora_encode_YUVin (&enc->state, &yuv);
|
||||||
if (theora_encode_packetout (&enc->state, 0, &op))
|
while (theora_encode_packetout (&enc->state, 0, &op)) {
|
||||||
theora_push_packet (enc, &op);
|
GstClockTime out_time =
|
||||||
|
theora_granule_time (&enc->state, op.granulepos) * GST_SECOND;
|
||||||
|
theora_push_packet (enc, &op, out_time, GST_SECOND / enc->fps);
|
||||||
|
}
|
||||||
|
|
||||||
gst_data_unref (data);
|
gst_data_unref (data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue