mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:56:14 +00:00
move out some code to a function
Original commit message from CVS: move out some code to a function
This commit is contained in:
parent
99da9aa987
commit
7df5e894a6
2 changed files with 78 additions and 60 deletions
2
common
2
common
|
@ -1 +1 @@
|
||||||
Subproject commit 92ff5101d55c0f853620bf13f8dd528992824137
|
Subproject commit 773e3a64961084c37477faa464f12add3dfcd6dc
|
136
ext/mad/gstmad.c
136
ext/mad/gstmad.c
|
@ -931,6 +931,66 @@ fail:
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_mad_handle_event (GstPad *pad, GstBuffer *buffer)
|
||||||
|
{
|
||||||
|
GstEvent *event = GST_EVENT (buffer);
|
||||||
|
GstMad *mad = GST_MAD (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
|
switch (GST_EVENT_TYPE (event))
|
||||||
|
{
|
||||||
|
case GST_EVENT_DISCONTINUOUS:
|
||||||
|
{
|
||||||
|
gint n = GST_EVENT_DISCONT_OFFSET_LEN (event);
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
if (gst_pad_handles_format (pad,
|
||||||
|
GST_EVENT_DISCONT_OFFSET(event, i).format))
|
||||||
|
{
|
||||||
|
gint64 value = GST_EVENT_DISCONT_OFFSET (event, i).value;
|
||||||
|
gint64 time;
|
||||||
|
GstFormat format;
|
||||||
|
GstEvent *discont;
|
||||||
|
|
||||||
|
/* see how long the input bytes take */
|
||||||
|
format = GST_FORMAT_TIME;
|
||||||
|
if (!gst_pad_convert (pad,
|
||||||
|
GST_EVENT_DISCONT_OFFSET (event, i).format,
|
||||||
|
value, &format, &time))
|
||||||
|
{
|
||||||
|
time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for now, this is the best we can do. Let's hope a real timestamp
|
||||||
|
* arrives with the next buffer */
|
||||||
|
mad->base_time = time;
|
||||||
|
|
||||||
|
gst_event_unref (event);
|
||||||
|
|
||||||
|
if (GST_PAD_IS_USABLE (mad->srcpad))
|
||||||
|
{
|
||||||
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
|
||||||
|
time, NULL);
|
||||||
|
gst_pad_push (mad->srcpad, GST_BUFFER (discont));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mad->total_samples = 0;
|
||||||
|
mad->tempsize = 0;
|
||||||
|
/* we don't need to restart when we get here */
|
||||||
|
mad->restart = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
gst_pad_event_default (pad, event);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_mad_chain (GstPad *pad, GstBuffer *buffer)
|
gst_mad_chain (GstPad *pad, GstBuffer *buffer)
|
||||||
{
|
{
|
||||||
|
@ -941,58 +1001,12 @@ gst_mad_chain (GstPad *pad, GstBuffer *buffer)
|
||||||
|
|
||||||
mad = GST_MAD (gst_pad_get_parent (pad));
|
mad = GST_MAD (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
if (GST_IS_EVENT (buffer)) {
|
/* handle events */
|
||||||
GstEvent *event = GST_EVENT (buffer);
|
if (GST_IS_EVENT (buffer))
|
||||||
|
{
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
gst_mad_handle_event (pad, buffer);
|
||||||
case GST_EVENT_DISCONTINUOUS:
|
|
||||||
{
|
|
||||||
gint n = GST_EVENT_DISCONT_OFFSET_LEN (event);
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
for (i=0; i<n; i++) {
|
|
||||||
if (gst_pad_handles_format (pad, GST_EVENT_DISCONT_OFFSET(event,i).format))
|
|
||||||
{
|
|
||||||
gint64 value = GST_EVENT_DISCONT_OFFSET (event, i).value;
|
|
||||||
gint64 time;
|
|
||||||
GstFormat format;
|
|
||||||
GstEvent *discont;
|
|
||||||
|
|
||||||
/* see how long the input bytes take */
|
|
||||||
format = GST_FORMAT_TIME;
|
|
||||||
if (!gst_pad_convert (pad,
|
|
||||||
GST_EVENT_DISCONT_OFFSET (event, i).format, value,
|
|
||||||
&format, &time))
|
|
||||||
{
|
|
||||||
time = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* for now, this is the best we can do. Let's hope a real timestamp
|
|
||||||
* arrives with the next buffer */
|
|
||||||
mad->base_time = time;
|
|
||||||
|
|
||||||
gst_event_unref (event);
|
|
||||||
|
|
||||||
if (GST_PAD_IS_USABLE (mad->srcpad)) {
|
|
||||||
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time, NULL);
|
|
||||||
gst_pad_push (mad->srcpad, GST_BUFFER (discont));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mad->total_samples = 0;
|
|
||||||
mad->tempsize = 0;
|
|
||||||
/* we don't need to restart when we get here */
|
|
||||||
mad->restart = FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
gst_pad_event_default (pad, event);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GST_BUFFER_TIMESTAMP (buffer) != -1) {
|
if (GST_BUFFER_TIMESTAMP (buffer) != -1) {
|
||||||
/* if there is nothing queued (partial buffer), we prepare to set the
|
/* if there is nothing queued (partial buffer), we prepare to set the
|
||||||
* timestamp on the next buffer */
|
* timestamp on the next buffer */
|
||||||
|
@ -1011,13 +1025,14 @@ gst_mad_chain (GstPad *pad, GstBuffer *buffer)
|
||||||
data = GST_BUFFER_DATA (buffer);
|
data = GST_BUFFER_DATA (buffer);
|
||||||
size = GST_BUFFER_SIZE (buffer);
|
size = GST_BUFFER_SIZE (buffer);
|
||||||
|
|
||||||
while (size > 0) {
|
/* process the incoming buffer in chunks of maximum MDLEN bytes */
|
||||||
|
while (size > 0)
|
||||||
|
{
|
||||||
gint tocopy;
|
gint tocopy;
|
||||||
guchar *mad_input_buffer;
|
guchar *mad_input_buffer;
|
||||||
|
|
||||||
/* cut the buffer in MDLEN pieces */
|
|
||||||
tocopy = MIN (MAD_BUFFER_MDLEN, size);
|
tocopy = MIN (MAD_BUFFER_MDLEN, size);
|
||||||
|
|
||||||
memcpy (mad->tempbuffer + mad->tempsize, data, tocopy);
|
memcpy (mad->tempbuffer + mad->tempsize, data, tocopy);
|
||||||
mad->tempsize += tocopy;
|
mad->tempsize += tocopy;
|
||||||
|
|
||||||
|
@ -1039,31 +1054,34 @@ gst_mad_chain (GstPad *pad, GstBuffer *buffer)
|
||||||
/* not enough data, need to wait for next buffer? */
|
/* not enough data, need to wait for next buffer? */
|
||||||
if (mad->stream.error == MAD_ERROR_BUFLEN) {
|
if (mad->stream.error == MAD_ERROR_BUFLEN) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!MAD_RECOVERABLE (mad->stream.error)) {
|
if (!MAD_RECOVERABLE (mad->stream.error)) {
|
||||||
gst_element_error (GST_ELEMENT (mad), "fatal error decoding stream");
|
gst_element_error (GST_ELEMENT (mad), "fatal error decoding stream");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (mad->stream.error == MAD_ERROR_LOSTSYNC) {
|
else if (mad->stream.error == MAD_ERROR_LOSTSYNC) {
|
||||||
|
/* lost sync, force a resync */
|
||||||
signed long tagsize;
|
signed long tagsize;
|
||||||
|
|
||||||
tagsize = id3_tag_query (mad->stream.this_frame,
|
tagsize = id3_tag_query (mad->stream.this_frame,
|
||||||
mad->stream.bufend - mad->stream.this_frame);
|
mad->stream.bufend - mad->stream.this_frame);
|
||||||
|
|
||||||
if (tagsize > mad->tempsize) {
|
if (tagsize > mad->tempsize) {
|
||||||
GST_INFO (GST_CAT_PLUGIN_INFO, "mad: got partial id3 tag in buffer, skipping");
|
GST_INFO (GST_CAT_PLUGIN_INFO,
|
||||||
|
"mad: got partial id3 tag in buffer, skipping");
|
||||||
}
|
}
|
||||||
else if (tagsize > 0) {
|
else if (tagsize > 0) {
|
||||||
struct id3_tag *tag;
|
struct id3_tag *tag;
|
||||||
id3_byte_t const *data;
|
id3_byte_t const *data;
|
||||||
|
|
||||||
GST_INFO (GST_CAT_PLUGIN_INFO, "mad: got ID3 tag size %ld", tagsize);
|
GST_INFO (GST_CAT_PLUGIN_INFO,
|
||||||
|
"mad: got ID3 tag size %ld", tagsize);
|
||||||
|
|
||||||
data = mad->stream.this_frame;
|
data = mad->stream.this_frame;
|
||||||
|
|
||||||
/* mad has moved the pointer to the next frame over the start of the
|
/* mad has moved the pointer to the next frame over the start of the
|
||||||
* id3 tags, so we need to flush one byte less n the tagsize */
|
* id3 tags, so we need to flush one byte less than the tagsize */
|
||||||
mad_stream_skip(&mad->stream, tagsize-1);
|
mad_stream_skip (&mad->stream, tagsize - 1);
|
||||||
|
|
||||||
tag = id3_tag_parse (data, tagsize);
|
tag = id3_tag_parse (data, tagsize);
|
||||||
if (tag) {
|
if (tag) {
|
||||||
|
|
Loading…
Reference in a new issue