some code cleanup

Original commit message from CVS:
some code cleanup
This commit is contained in:
Thomas Vander Stichele 2003-01-08 16:11:48 +00:00
parent bb1917b897
commit 616b2b2bd7
2 changed files with 103 additions and 90 deletions

View File

@ -48,7 +48,7 @@ struct _GstMad {
struct mad_frame frame;
struct mad_synth synth;
guchar *tempbuffer;
glong tempsize;
glong tempsize; /* used to keep track of partial buffers */
gboolean need_sync;
guint64 base_time;
guint64 framestamp; /* timestamp-like, but counted in frames */
@ -146,7 +146,8 @@ static void gst_mad_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec);
static gboolean gst_mad_src_event (GstPad *pad, GstEvent *event);
static const GstFormat* gst_mad_get_formats (GstPad *pad);
static const GstFormat*
gst_mad_get_formats (GstPad *pad);
static const GstEventMask*
gst_mad_get_event_masks (GstPad *pad);
static const GstQueryType*
@ -154,10 +155,12 @@ static const GstQueryType*
static gboolean gst_mad_src_query (GstPad *pad, GstQueryType type,
GstFormat *format, gint64 *value);
static gboolean gst_mad_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value,
GstFormat *dest_format, gint64 *dest_value);
static gboolean gst_mad_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value,
GstFormat *dest_format, gint64 *dest_value);
static gboolean gst_mad_convert_sink (GstPad *pad, GstFormat src_format,
gint64 src_value, GstFormat
*dest_format, gint64 *dest_value);
static gboolean gst_mad_convert_src (GstPad *pad, GstFormat src_format,
gint64 src_value, GstFormat
*dest_format, gint64 *dest_value);
static void gst_mad_chain (GstPad *pad, GstBuffer *buffer);
@ -175,15 +178,15 @@ gst_mad_get_type (void)
if (!mad_type) {
static const GTypeInfo mad_info = {
sizeof(GstMadClass),
sizeof (GstMadClass),
NULL,
NULL,
(GClassInitFunc)gst_mad_class_init,
(GClassInitFunc) gst_mad_class_init,
NULL,
NULL,
sizeof(GstMad),
sizeof (GstMad),
0,
(GInstanceInitFunc)gst_mad_init,
(GInstanceInitFunc) gst_mad_init,
};
mad_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMad", &mad_info, 0);
}
@ -261,7 +264,8 @@ gst_mad_class_init (GstMadClass *klass)
/* init properties */
/* currently, string representations are used, we might want to change that */
/* FIXME: descriptions need to be more technical, default values and ranges need to be selected right */
/* FIXME: descriptions need to be more technical,
* default values and ranges need to be selected right */
g_object_class_install_property (gobject_class, ARG_HALF,
g_param_spec_boolean ("half", "Half", "Generate PCM at 1/2 sample rate",
FALSE, G_PARAM_READWRITE));
@ -620,12 +624,14 @@ gst_mad_src_event (GstPad *pad, GstEvent *event)
format = *peer_formats;
/* try to convert requested format to one we can seek with on the sinkpad */
if (gst_pad_convert (mad->sinkpad, GST_FORMAT_TIME, src_offset, &format, &desired_offset))
if (gst_pad_convert (mad->sinkpad, GST_FORMAT_TIME, src_offset,
&format, &desired_offset))
{
GstEvent *seek_event;
/* conversion succeeded, create the seek */
seek_event = gst_event_new_seek (format | GST_SEEK_METHOD_SET | flush, desired_offset);
seek_event = gst_event_new_seek (format | GST_SEEK_METHOD_SET | flush,
desired_offset);
/* do the seek */
if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), seek_event)) {
/* seek worked, we're done, loop will exit */
@ -668,11 +674,11 @@ scale (mad_fixed_t sample)
/* do we need this function? */
static void
gst_mad_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
gst_mad_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
GstMad *mad;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_MAD (object));
mad = GST_MAD (object);
@ -690,11 +696,11 @@ gst_mad_set_property (GObject *object, guint prop_id, const GValue *value, GPara
}
}
static void
gst_mad_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
gst_mad_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
GstMad *mad;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_MAD (object));
mad = GST_MAD (object);
@ -794,8 +800,8 @@ G_STMT_START{ \
mad->streaminfo = gst_mad_get_streaminfo (mad);
g_object_notify (G_OBJECT (mad), "streaminfo");
}
#undef CHECK_HEADER
}
/* gracefuly ripped from madplay */
@ -923,7 +929,7 @@ id3_to_caps(struct id3_tag const *tag)
props);
if (0) {
fail:
g_warning("mad: could not parse ID3 tag");
g_warning ("mad: could not parse ID3 tag");
return NULL;
}
@ -1010,6 +1016,8 @@ gst_mad_chain (GstPad *pad, GstBuffer *buffer)
gst_mad_handle_event (pad, buffer);
return;
}
/* handle timestamps */
if (GST_BUFFER_TIMESTAMP (buffer) != -1) {
/* if there is nothing queued (partial buffer), we prepare to set the
* timestamp on the next buffer */
@ -1024,11 +1032,12 @@ gst_mad_chain (GstPad *pad, GstBuffer *buffer)
}
}
/* end of new bit */
/* handle data */
data = GST_BUFFER_DATA (buffer);
size = GST_BUFFER_SIZE (buffer);
/* process the incoming buffer in chunks of maximum MDLEN bytes */
/* process the incoming buffer in chunks of maximum MAD_BUFFER_MDLEN bytes;
* this is the upper limit on processable chunk sizes set by mad */
while (size > 0)
{
gint tocopy;
@ -1036,15 +1045,17 @@ gst_mad_chain (GstPad *pad, GstBuffer *buffer)
tocopy = MIN (MAD_BUFFER_MDLEN, size);
/* append the chunk to process to our internal temporary buffer */
memcpy (mad->tempbuffer + mad->tempsize, data, tocopy);
mad->tempsize += tocopy;
/* update our incoming buffer's parameters to reflect this */
size -= tocopy;
data += tocopy;
mad_input_buffer = mad->tempbuffer;
/* if we have data we can try to proceed */
/* while we have data we can consume it */
while (mad->tempsize >= 0) {
gint consumed;
guint nchannels;
@ -1162,8 +1173,10 @@ gst_mad_chain (GstPad *pad, GstBuffer *buffer)
g_warning ("mad->frame.header.samplerate is 0 !");
}
else {
GST_BUFFER_TIMESTAMP (outbuffer) = mad->base_time +
mad->total_samples * GST_SECOND / mad->frame.header.samplerate;
guint64 increase;
increase = mad->total_samples * GST_SECOND
/ mad->frame.header.samplerate;
GST_BUFFER_TIMESTAMP (outbuffer) = mad->base_time + increase;
}
/* output sample(s) in 16-bit signed native-endian PCM */
@ -1186,7 +1199,7 @@ gst_mad_chain (GstPad *pad, GstBuffer *buffer)
mad->total_samples += nsamples;
/* we have a queued timestamp on the incomming buffer that we should
/* we have a queued timestamp on the incoming buffer that we should
* use for the next frame */
if (new_pts) {
new_pts = FALSE;