audiopayload: code cleanups

This commit is contained in:
Wim Taymans 2009-09-01 18:26:52 +02:00
parent 3c29efa692
commit bc3c8a1564

View file

@ -311,7 +311,7 @@ gst_base_rtp_audio_payload_handle_frame_based_buffer (GstBaseRTPPayload *
GstFlowReturn ret; GstFlowReturn ret;
guint available; guint available;
gint frame_size, frame_duration; gint frame_size, frame_duration;
guint max_frames;
guint maxptime_octets = G_MAXUINT; guint maxptime_octets = G_MAXUINT;
guint minptime_octets = 0; guint minptime_octets = 0;
guint min_payload_len; guint min_payload_len;
@ -324,11 +324,9 @@ gst_base_rtp_audio_payload_handle_frame_based_buffer (GstBaseRTPPayload *
basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basepayload); basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basepayload);
if (basertpaudiopayload->frame_size == 0 || if (basertpaudiopayload->frame_size == 0 ||
basertpaudiopayload->frame_duration == 0) { basertpaudiopayload->frame_duration == 0)
GST_DEBUG_OBJECT (basertpaudiopayload, "Required options not set"); goto config_error;
gst_buffer_unref (buffer);
return GST_FLOW_ERROR;
}
frame_size = basertpaudiopayload->frame_size; frame_size = basertpaudiopayload->frame_size;
frame_duration = basertpaudiopayload->frame_duration; frame_duration = basertpaudiopayload->frame_duration;
@ -345,12 +343,13 @@ gst_base_rtp_audio_payload_handle_frame_based_buffer (GstBaseRTPPayload *
} }
} }
max_payload_len = MIN ( /* MTU max */
/* MTU max */ max_frames = gst_rtp_buffer_calc_payload_len (GST_BASE_RTP_PAYLOAD_MTU
(int) (gst_rtp_buffer_calc_payload_len (GST_BASE_RTP_PAYLOAD_MTU (basertpaudiopayload), 0, 0);
(basertpaudiopayload), 0, 0) / frame_size) * frame_size, /* round down to frame_size */
/* ptime max */ max_frames = (max_frames / frame_size) * frame_size;
maxptime_octets); /* max payload length */
max_payload_len = MIN (max_frames, maxptime_octets);
/* min number of bytes based on a given ptime, has to be a multiple /* min number of bytes based on a given ptime, has to be a multiple
of frame duration */ of frame duration */
@ -360,9 +359,8 @@ gst_base_rtp_audio_payload_handle_frame_based_buffer (GstBaseRTPPayload *
min_payload_len = MAX (minptime_octets, frame_size); min_payload_len = MAX (minptime_octets, frame_size);
if (min_payload_len > max_payload_len) { if (min_payload_len > max_payload_len)
min_payload_len = max_payload_len; min_payload_len = max_payload_len;
}
GST_DEBUG_OBJECT (basertpaudiopayload, GST_DEBUG_OBJECT (basertpaudiopayload,
"Calculated min_payload_len %u and max_payload_len %u", "Calculated min_payload_len %u and max_payload_len %u",
@ -432,8 +430,15 @@ gst_base_rtp_audio_payload_handle_frame_based_buffer (GstBaseRTPPayload *
} }
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
} }
return ret; return ret;
/* ERRORS */
config_error:
{
GST_DEBUG_OBJECT (basertpaudiopayload, "Required options not set");
gst_buffer_unref (buffer);
return GST_FLOW_ERROR;
}
} }
static GstFlowReturn static GstFlowReturn
@ -457,11 +462,8 @@ gst_base_rtp_audio_payload_handle_sample_based_buffer (GstBaseRTPPayload *
basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basepayload); basertpaudiopayload = GST_BASE_RTP_AUDIO_PAYLOAD (basepayload);
if (basertpaudiopayload->sample_size == 0) { if (basertpaudiopayload->sample_size == 0)
GST_DEBUG_OBJECT (basertpaudiopayload, "Required options not set"); goto config_error;
gst_buffer_unref (buffer);
return GST_FLOW_ERROR;
}
/* sample_size is in bits and is converted into multiple bytes */ /* sample_size is in bits and is converted into multiple bytes */
fragment_size = basertpaudiopayload->sample_size; fragment_size = basertpaudiopayload->sample_size;
@ -489,9 +491,8 @@ gst_base_rtp_audio_payload_handle_sample_based_buffer (GstBaseRTPPayload *
min_payload_len = MAX (minptime_octets, fragment_size); min_payload_len = MAX (minptime_octets, fragment_size);
if (min_payload_len > max_payload_len) { if (min_payload_len > max_payload_len)
min_payload_len = max_payload_len; min_payload_len = max_payload_len;
}
GST_DEBUG_OBJECT (basertpaudiopayload, GST_DEBUG_OBJECT (basertpaudiopayload,
"Calculated min_payload_len %u and max_payload_len %u", "Calculated min_payload_len %u and max_payload_len %u",
@ -566,6 +567,14 @@ gst_base_rtp_audio_payload_handle_sample_based_buffer (GstBaseRTPPayload *
} }
return ret; return ret;
/* ERRORS */
config_error:
{
GST_DEBUG_OBJECT (basertpaudiopayload, "Required options not set");
gst_buffer_unref (buffer);
return GST_FLOW_ERROR;
}
} }
/** /**
@ -643,6 +652,7 @@ gst_base_rtp_payload_audio_handle_event (GstPad * pad, GstEvent * event)
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS: case GST_EVENT_EOS:
/* FIXME. push remaining bytes */
gst_adapter_clear (basertpaudiopayload->priv->adapter); gst_adapter_clear (basertpaudiopayload->priv->adapter);
break; break;
case GST_EVENT_FLUSH_STOP: case GST_EVENT_FLUSH_STOP: