diff --git a/ChangeLog b/ChangeLog index f76057477e..ca8989c9e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-03-14 Thomas Vander Stichele + + * *.c, *.h: run gst-indent + 2004-03-14 Benjamin Otte * gst/modplug/gstmodplug.cc: diff --git a/examples/capsfilter/capsfilter1.c b/examples/capsfilter/capsfilter1.c index 4d71109f40..46e127a212 100644 --- a/examples/capsfilter/capsfilter1.c +++ b/examples/capsfilter/capsfilter1.c @@ -6,7 +6,7 @@ * connection would use the I420 format (assuming Xv is enabled) */ static void -new_pad_func (GstElement *element, GstPad *newpad, gpointer data) +new_pad_func (GstElement * element, GstPad * newpad, gpointer data) { GstElement *pipeline = (GstElement *) data; GstElement *queue = gst_bin_get_by_name (GST_BIN (pipeline), "queue"); @@ -19,7 +19,7 @@ new_pad_func (GstElement *element, GstPad *newpad, gpointer data) } gint -main (gint argc, gchar *argv[]) +main (gint argc, gchar * argv[]) { GstElement *pipeline; GstElement *filesrc; @@ -44,7 +44,8 @@ main (gint argc, gchar *argv[]) g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); demux = gst_element_factory_make ("mpegdemux", "demux"); g_return_val_if_fail (demux, -1); - g_signal_connect (G_OBJECT (demux), "new_pad", G_CALLBACK (new_pad_func), pipeline); + g_signal_connect (G_OBJECT (demux), "new_pad", G_CALLBACK (new_pad_func), + pipeline); thread = gst_thread_new ("thread"); queue = gst_element_factory_make ("queue", "queue"); @@ -58,7 +59,7 @@ main (gint argc, gchar *argv[]) gst_bin_add (GST_BIN (pipeline), filesrc); gst_bin_add (GST_BIN (pipeline), demux); - + gst_bin_add (GST_BIN (thread), queue); gst_bin_add (GST_BIN (thread), mpeg2dec); gst_bin_add (GST_BIN (thread), colorspace); @@ -70,11 +71,9 @@ main (gint argc, gchar *argv[]) gst_element_link (mpeg2dec, "src", colorspace, "sink"); /* force RGB data passing between colorspace and xvideosink */ res = gst_element_link_filtered (colorspace, "src", xvideosink, "sink", - GST_CAPS_NEW ( - "filtercaps", - "video/raw", - "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")) - )); + GST_CAPS_NEW ("filtercaps", + "video/raw", "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")) + )); if (!res) { g_print ("could not connect colorspace and xvideosink\n"); return -1; @@ -83,7 +82,7 @@ main (gint argc, gchar *argv[]) gst_element_set_state (pipeline, GST_STATE_PLAYING); while (gst_bin_iterate (GST_BIN (pipeline))); - + gst_element_set_state (pipeline, GST_STATE_NULL); return 0; diff --git a/examples/dynparams/filter.c b/examples/dynparams/filter.c index ed0dd5aaa3..982a4c7ad1 100644 --- a/examples/dynparams/filter.c +++ b/examples/dynparams/filter.c @@ -18,13 +18,13 @@ struct _filter_ui GtkWidget *window; /* top-level interface window */ GtkWidget *buttons; /* all of the control buttons */ - GtkWidget *parse, *play, *stop; /* control buttons */ - + GtkWidget *parse, *play, *stop; /* control buttons */ + GtkWidget *feedback; /* here's where we'll tell you stuff */ GtkTextBuffer *fb_buffer; /* feedback buffer */ GtkWidget *selection; /* the place to input element stuff */ - GtkWidget *input, *filter, *output; /* the selection widgets */ - + GtkWidget *input, *filter, *output; /* the selection widgets */ + GtkWidget *control; /* the dynamically generated control UI */ }; @@ -33,13 +33,13 @@ typedef struct _filter_ui _filter_ui_t; /* back-end data */ struct _filter_data { - _filter_ui_t *ui; /* the UI data */ + _filter_ui_t *ui; /* the UI data */ gchar *input_pipe, *output_pipe, *filter_element; gchar *pipe_string; GList *filter_choices; gboolean playing; - GstElement *input, *output; /* these are in and out bins */ + GstElement *input, *output; /* these are in and out bins */ GstElement *pipeline; GstElement *filter; }; @@ -47,17 +47,18 @@ struct _filter_data typedef struct _filter_data _filter_data_t; /* internal prototypes when they can't be avoided */ -void cb_remove_and_destroy (GtkWidget *widget, gpointer user_data); -//void cb_dynparm_value_changed (GtkWidget *widget, gpointer user_data); -void cb_dynparm_value_changed (GtkRange *range, GstDParam *dparam); +void cb_remove_and_destroy (GtkWidget * widget, gpointer user_data); + +//void cb_dynparm_value_changed (GtkWidget *widget, gpointer user_data); +void cb_dynparm_value_changed (GtkRange * range, GstDParam * dparam); /* GStreamer helper functions go here */ - + /* go through a bin, finding the one pad that is unconnected in the given * direction, and return a ghost pad */ GstPad * -gst_bin_find_unconnected_pad (GstBin *bin, GstPadDirection direction, - gchar *name) +gst_bin_find_unconnected_pad (GstBin * bin, GstPadDirection direction, + gchar * name) { GstPad *pad = NULL; GList *elements = NULL; @@ -67,39 +68,36 @@ gst_bin_find_unconnected_pad (GstBin *bin, GstPadDirection direction, g_print ("DEBUG: find_unconnected start\n"); elements = (GList *) gst_bin_get_list (bin); /* traverse all elements looking for unconnected pads */ - while (elements && pad == NULL) - { + while (elements && pad == NULL) { element = GST_ELEMENT (elements->data); g_print ("DEBUG: looking in element %s\n", gst_element_get_name (element)); pads = gst_element_get_pad_list (element); - while (pads) - { + while (pads) { /* check if the direction matches */ - if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == direction) - { - if (GST_PAD_PEER (GST_PAD (pads->data)) == NULL) - { + if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == direction) { + if (GST_PAD_PEER (GST_PAD (pads->data)) == NULL) { /* found it ! */ g_print ("DEBUG: found an unconnected pad !\n"); pad = GST_PAD (pads->data); } } - if (pad) break; /* found one already */ + if (pad) + break; /* found one already */ pads = g_list_next (pads); } elements = g_list_next (elements); } g_print ("DEBUG: find_unconnected stop\n"); - if (pad == NULL) /* we didn't find it at all */ + if (pad == NULL) /* we didn't find it at all */ return NULL; - + pad = gst_ghost_pad_new (name, pad); return pad; } void -ui_feedback_add_text (_filter_ui_t *ui, const gchar *text) +ui_feedback_add_text (_filter_ui_t * ui, const gchar * text) { GtkTextIter iter; @@ -108,7 +106,7 @@ ui_feedback_add_text (_filter_ui_t *ui, const gchar *text) } void -ui_feedback_add (_filter_ui_t *ui, const gchar *format, ...) +ui_feedback_add (_filter_ui_t * ui, const gchar * format, ...) { va_list args; gchar *buffer = NULL; @@ -121,7 +119,7 @@ ui_feedback_add (_filter_ui_t *ui, const gchar *format, ...) } void -ui_feedback_clear (_filter_ui_t *ui) +ui_feedback_clear (_filter_ui_t * ui) { gtk_text_buffer_set_text (ui->fb_buffer, "", 0); } @@ -129,7 +127,7 @@ ui_feedback_clear (_filter_ui_t *ui) /* create the control widget using the element's dynparams * control is a vbox which we need to empty first */ void -ui_control_create (GstElement *element, GtkWidget *control, _filter_ui_t *ui) +ui_control_create (GstElement * element, GtkWidget * control, _filter_ui_t * ui) { GtkWidget *hbox = NULL; GtkWidget *widget = NULL; @@ -137,70 +135,63 @@ ui_control_create (GstElement *element, GtkWidget *control, _filter_ui_t *ui) GstDParam *dparam = NULL; GParamSpec **specs = NULL; int i = 0; - + g_assert (GTK_IS_VBOX (control)); /* empty control vbox */ g_print ("DEBUG: emptying control widget\n"); - gtk_container_foreach (GTK_CONTAINER (control), cb_remove_and_destroy, - (gpointer) control); + gtk_container_foreach (GTK_CONTAINER (control), cb_remove_and_destroy, + (gpointer) control); g_print ("DEBUG: adding label to control widget\n"); widget = gtk_label_new ("Dynamic Parameters"); gtk_container_add (GTK_CONTAINER (control), widget); gtk_widget_show (widget); - - if ((dpman = gst_dpman_get_manager (element))) - { + + if ((dpman = gst_dpman_get_manager (element))) { ui_feedback_add (ui, "Found Dynamic Parameters on filter element.\n"); specs = gst_dpman_list_dparam_specs (dpman); - for (i = 0; specs[i] != NULL; ++i) - { + for (i = 0; specs[i] != NULL; ++i) { hbox = gtk_hbox_new (FALSE, 0); widget = gtk_label_new (g_param_spec_get_name (specs[i])); gtk_container_add (GTK_CONTAINER (hbox), widget); gtk_widget_show (widget); - switch (G_PARAM_SPEC_VALUE_TYPE (specs[i])) - { - case G_TYPE_INT64: + switch (G_PARAM_SPEC_VALUE_TYPE (specs[i])) { + case G_TYPE_INT64: widget = gtk_hscale_new_with_range ( - (gdouble) (((GParamSpecInt64*)specs[i])->minimum), - (gdouble) (((GParamSpecInt64*)specs[i])->maximum), - 1.0); + (gdouble) (((GParamSpecInt64 *) specs[i])->minimum), + (gdouble) (((GParamSpecInt64 *) specs[i])->maximum), 1.0); gtk_range_set_value (GTK_RANGE (widget), - (gdouble) ((GParamSpecInt64*)specs[i])->default_value); - break; + (gdouble) ((GParamSpecInt64 *) specs[i])->default_value); + break; case G_TYPE_INT: widget = gtk_hscale_new_with_range ( - (gdouble) (((GParamSpecInt*)specs[i])->minimum), - (gdouble) (((GParamSpecInt*)specs[i])->maximum), - 1.0); + (gdouble) (((GParamSpecInt *) specs[i])->minimum), + (gdouble) (((GParamSpecInt *) specs[i])->maximum), 1.0); gtk_range_set_value (GTK_RANGE (widget), - (gdouble) ((GParamSpecInt*)specs[i])->default_value); - break; - case G_TYPE_FLOAT: + (gdouble) ((GParamSpecInt *) specs[i])->default_value); + break; + case G_TYPE_FLOAT: widget = gtk_hscale_new_with_range ( - (gdouble) (((GParamSpecFloat*)specs[i])->minimum), - (gdouble) (((GParamSpecFloat*)specs[i])->maximum), - 0.00001); + (gdouble) (((GParamSpecFloat *) specs[i])->minimum), + (gdouble) (((GParamSpecFloat *) specs[i])->maximum), 0.00001); gtk_range_set_value (GTK_RANGE (widget), - (gdouble) ((GParamSpecFloat*)specs[i])->default_value); + (gdouble) ((GParamSpecFloat *) specs[i])->default_value); break; } /* create the dparam object */ dparam = gst_dpsmooth_new (G_PARAM_SPEC_VALUE_TYPE (specs[i])); g_object_set (G_OBJECT (dparam), "update_period", 2000000LL, NULL); - g_assert (gst_dpman_attach_dparam (dpman, - (gchar *) g_param_spec_get_name (specs[i]), - dparam)); - gst_dpman_set_mode(dpman, "asynchronous"); + g_assert (gst_dpman_attach_dparam (dpman, + (gchar *) g_param_spec_get_name (specs[i]), dparam)); + gst_dpman_set_mode (dpman, "asynchronous"); g_signal_connect (widget, "value-changed", - G_CALLBACK (cb_dynparm_value_changed), dparam); + G_CALLBACK (cb_dynparm_value_changed), dparam); cb_dynparm_value_changed (GTK_RANGE (widget), dparam); - + gtk_container_add (GTK_CONTAINER (hbox), widget); - gtk_widget_show (widget); + gtk_widget_show (widget); } gtk_container_add (GTK_CONTAINER (control), hbox); gtk_widget_show (hbox); @@ -209,7 +200,7 @@ ui_control_create (GstElement *element, GtkWidget *control, _filter_ui_t *ui) /* all the pretty callbacks gather here please */ void -cb_remove_and_destroy (GtkWidget *widget, gpointer user_data) +cb_remove_and_destroy (GtkWidget * widget, gpointer user_data) { GtkContainer *container = GTK_CONTAINER (user_data); @@ -220,55 +211,51 @@ cb_remove_and_destroy (GtkWidget *widget, gpointer user_data) /* when the scale associated with a dparam changes, respond */ void -cb_dynparm_value_changed (GtkRange *range, GstDParam *dparam) +cb_dynparm_value_changed (GtkRange * range, GstDParam * dparam) { /* - GstDParam *dparam = GST_DPARAM (user_data); - GtkHScale *adj = GTK_HSCALE (widget); - */ + GstDParam *dparam = GST_DPARAM (user_data); + GtkHScale *adj = GTK_HSCALE (widget); + */ gdouble value = 0.0; + g_assert (GST_IS_DPARAM (dparam)); g_assert (GTK_IS_RANGE (range)); value = gtk_range_get_value (range); - g_print ("DEBUG: setting value to %f\n", value); + g_print ("DEBUG: setting value to %f\n", value); - switch (G_PARAM_SPEC_VALUE_TYPE (GST_DPARAM_PARAM_SPEC (dparam))) - { + switch (G_PARAM_SPEC_VALUE_TYPE (GST_DPARAM_PARAM_SPEC (dparam))) { case G_TYPE_INT64: - g_object_set (G_OBJECT (dparam), "value_int64", - (gint64) value, NULL); + g_object_set (G_OBJECT (dparam), "value_int64", (gint64) value, NULL); break; case G_TYPE_INT: - g_object_set (G_OBJECT (dparam), "value_int", - (gint) value, NULL); + g_object_set (G_OBJECT (dparam), "value_int", (gint) value, NULL); break; case G_TYPE_FLOAT: - g_object_set (G_OBJECT (dparam), "value_float", - (gfloat) value, NULL); + g_object_set (G_OBJECT (dparam), "value_float", (gfloat) value, NULL); break; } } - + void -cb_entry_activate (GtkEntry *entry, gpointer user_data) +cb_entry_activate (GtkEntry * entry, gpointer user_data) { g_print ("DEBUG: oi ! you activated an entry !\n"); g_print ("DEBUG: pipeline: %s\n", gtk_entry_get_text (entry)); } void -cb_play_clicked (GtkButton *button, gpointer *user_data) +cb_play_clicked (GtkButton * button, gpointer * user_data) { _filter_data_t *fd = (_filter_data_t *) user_data; g_return_if_fail (GST_IS_PIPELINE (fd->pipeline)); - if (GST_STATE (fd->pipeline) == GST_STATE_PLAYING) - { + if (GST_STATE (fd->pipeline) == GST_STATE_PLAYING) { ui_feedback_add (fd->ui, "Pipeline is already playing !\n"); return; } @@ -276,12 +263,11 @@ cb_play_clicked (GtkButton *button, gpointer *user_data) } void -cb_stop_clicked (GtkButton *button, gpointer *user_data) +cb_stop_clicked (GtkButton * button, gpointer * user_data) { _filter_data_t *fd = (_filter_data_t *) user_data; - if (GST_STATE (fd->pipeline) != GST_STATE_PLAYING) - { + if (GST_STATE (fd->pipeline) != GST_STATE_PLAYING) { ui_feedback_add (fd->ui, "Pipeline is not playing !\n"); return; } @@ -289,67 +275,72 @@ cb_stop_clicked (GtkButton *button, gpointer *user_data) } void -cb_parse_clicked (GtkButton *button, gpointer *user_data) +cb_parse_clicked (GtkButton * button, gpointer * user_data) { _filter_data_t *fd = (_filter_data_t *) user_data; GtkCombo *filter = GTK_COMBO (fd->ui->filter); GError *error = NULL; GstPad *src_pad, *sink_pad; - + g_print ("DEBUG: you pressed parse.\n"); ui_feedback_clear (fd->ui); ui_feedback_add (fd->ui, "Parsing pipeline ...\n"); - if (fd->input_pipe) g_free (fd->input_pipe); - if (fd->output_pipe) g_free (fd->output_pipe); - if (fd->filter_element) g_free (fd->filter_element); + if (fd->input_pipe) + g_free (fd->input_pipe); + if (fd->output_pipe) + g_free (fd->output_pipe); + if (fd->filter_element) + g_free (fd->filter_element); fd->input_pipe = g_strdup_printf ("bin.( %s )", - gtk_entry_get_text (GTK_ENTRY (fd->ui->input))); + gtk_entry_get_text (GTK_ENTRY (fd->ui->input))); fd->output_pipe = g_strdup_printf ("bin.( %s )", - gtk_entry_get_text (GTK_ENTRY (fd->ui->output))); + gtk_entry_get_text (GTK_ENTRY (fd->ui->output))); /* gtkcombo.h says I can access the entry field directly */ - fd->filter_element = g_strdup (gtk_entry_get_text (GTK_ENTRY (filter->entry))); - g_print ("Input pipeline :\t%s (%d)\n", fd->input_pipe, (int)strlen (fd->input_pipe)); - g_print ("Filter element :\t%s (%d)\n", fd->filter_element, (int)strlen (fd->filter_element)); - g_print ("Output pipeline :\t%s (%d)\n", fd->output_pipe, (int)strlen (fd->output_pipe)); + fd->filter_element = + g_strdup (gtk_entry_get_text (GTK_ENTRY (filter->entry))); + g_print ("Input pipeline :\t%s (%d)\n", fd->input_pipe, + (int) strlen (fd->input_pipe)); + g_print ("Filter element :\t%s (%d)\n", fd->filter_element, + (int) strlen (fd->filter_element)); + g_print ("Output pipeline :\t%s (%d)\n", fd->output_pipe, + (int) strlen (fd->output_pipe)); /* try to create in and out bins */ - if (strlen (fd->input_pipe) == 0) - { + if (strlen (fd->input_pipe) == 0) { ui_feedback_add (fd->ui, "Error : try setting an input pipe.\n"); return; } - if (fd->input) gst_object_unref (GST_OBJECT (fd->input)); + if (fd->input) + gst_object_unref (GST_OBJECT (fd->input)); fd->input = GST_ELEMENT (gst_parse_launch (fd->input_pipe, &error)); - if (error) - { - ui_feedback_add (fd->ui, "Error : parsing input pipeline : %s\n", - error->message); + if (error) { + ui_feedback_add (fd->ui, "Error : parsing input pipeline : %s\n", + error->message); g_error_free (error); return; } - - if (strlen (fd->output_pipe) == 0) - { + + if (strlen (fd->output_pipe) == 0) { ui_feedback_add (fd->ui, "Error : try setting an output pipe.\n"); return; } - if (fd->output) gst_object_unref (GST_OBJECT (fd->output)); + if (fd->output) + gst_object_unref (GST_OBJECT (fd->output)); fd->output = GST_ELEMENT (gst_parse_launch (fd->output_pipe, &error)); - if (error) - { - ui_feedback_add (fd->ui, "Error : parsing output pipeline : %s\n", - error->message); + if (error) { + ui_feedback_add (fd->ui, "Error : parsing output pipeline : %s\n", + error->message); g_error_free (error); return; } /* try to create filter */ - if (fd->filter) gst_object_unref (GST_OBJECT (fd->filter)); + if (fd->filter) + gst_object_unref (GST_OBJECT (fd->filter)); fd->filter = gst_element_factory_make (fd->filter_element, "filter"); - if (fd->filter == NULL) - { + if (fd->filter == NULL) { ui_feedback_add (fd->ui, "Error : could not create element %s\n", - fd->filter_element); + fd->filter_element); return; } @@ -360,35 +351,33 @@ cb_parse_clicked (GtkButton *button, gpointer *user_data) fd->pipeline = gst_thread_new ("toplevel"); /* add the players to it */ - gst_bin_add_many (GST_BIN (fd->pipeline), - fd->input, fd->filter, - fd->output, NULL); + gst_bin_add_many (GST_BIN (fd->pipeline), + fd->input, fd->filter, fd->output, NULL); /* connect filter to input and output bin */ - src_pad = gst_bin_find_unconnected_pad (GST_BIN (fd->input), GST_PAD_SRC, - "source"); - if (src_pad == NULL) - { - ui_feedback_add (fd->ui, - "Error : could not find an unconnected source pad !\n"); + src_pad = gst_bin_find_unconnected_pad (GST_BIN (fd->input), GST_PAD_SRC, + "source"); + if (src_pad == NULL) { + ui_feedback_add (fd->ui, + "Error : could not find an unconnected source pad !\n"); return; } - sink_pad = gst_bin_find_unconnected_pad (GST_BIN (fd->output), GST_PAD_SINK, - "sink"); - if (sink_pad == NULL) - { - ui_feedback_add (fd->ui, - "Error : could not find an unconnected sink pad !\n"); + sink_pad = gst_bin_find_unconnected_pad (GST_BIN (fd->output), GST_PAD_SINK, + "sink"); + if (sink_pad == NULL) { + ui_feedback_add (fd->ui, + "Error : could not find an unconnected sink pad !\n"); return; } gst_element_add_pad (fd->input, src_pad); gst_element_add_pad (fd->output, sink_pad); gst_element_link_many (fd->input, fd->filter, fd->output, NULL); - - if (fd->pipe_string) g_free (fd->pipe_string); + + if (fd->pipe_string) + g_free (fd->pipe_string); fd->pipe_string = g_strdup_printf ("%s ! %s ! %s", fd->input_pipe, - fd->filter_element, fd->output_pipe); + fd->filter_element, fd->output_pipe); g_print ("Pipeline : %s\n", fd->pipe_string); ui_feedback_add (fd->ui, "Complete parsed pipeline: %s\n", fd->pipe_string); @@ -404,12 +393,12 @@ get_filter_choices (void) choices = g_list_append (choices, "volume"); choices = g_list_append (choices, "ladspa_lpf"); choices = g_list_append (choices, "ladspa_hpf"); - + return choices; } void -init_data (_filter_data_t *fd) +init_data (_filter_data_t * fd) { fd->input_pipe = NULL; fd->output_pipe = NULL; @@ -426,11 +415,11 @@ init_data (_filter_data_t *fd) } void -create_ui (_filter_ui_t *fui, _filter_data_t *fd) +create_ui (_filter_ui_t * fui, _filter_data_t * fd) { GtkWidget *widget; /* temporary widget */ GtkWidget *vbox; /* temporary vbox */ - + g_print ("DEBUG: creating top-level window\n"); fui->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); widget = gtk_vbox_new (FALSE, 0); @@ -452,22 +441,22 @@ create_ui (_filter_ui_t *fui, _filter_data_t *fd) fui->parse = gtk_button_new_with_label ("Parse"); gtk_container_add (GTK_CONTAINER (fui->buttons), fui->parse); g_signal_connect (G_OBJECT (fui->parse), "clicked", - G_CALLBACK (cb_parse_clicked), fd); + G_CALLBACK (cb_parse_clicked), fd); fui->play = gtk_button_new_with_label ("Play"); gtk_container_add (GTK_CONTAINER (fui->buttons), fui->play); g_signal_connect (G_OBJECT (fui->play), "clicked", - G_CALLBACK (cb_play_clicked), fd); + G_CALLBACK (cb_play_clicked), fd); fui->stop = gtk_button_new_with_label ("Stop"); gtk_container_add (GTK_CONTAINER (fui->buttons), fui->stop); g_signal_connect (G_OBJECT (fui->stop), "clicked", - G_CALLBACK (cb_stop_clicked), fd); + G_CALLBACK (cb_stop_clicked), fd); /* feedback widget */ fui->fb_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (fui->feedback)); - gtk_text_buffer_set_text (fui->fb_buffer, - "Hello, and welcome to the GStreamer filter demo app !\n"\ + gtk_text_buffer_set_text (fui->fb_buffer, + "Hello, and welcome to the GStreamer filter demo app !\n" "I'll be your feedback window for today.\n", -1); - + /* selection widget */ vbox = gtk_vbox_new (FALSE, 0); widget = gtk_label_new ("Input Pipe"); @@ -476,8 +465,8 @@ create_ui (_filter_ui_t *fui, _filter_data_t *fd) gtk_entry_set_text (GTK_ENTRY (fui->input), "sinesrc"); gtk_container_add (GTK_CONTAINER (vbox), fui->input); gtk_container_add (GTK_CONTAINER (fui->selection), vbox); - g_signal_connect (G_OBJECT (fui->input), "activate", - G_CALLBACK (cb_entry_activate), NULL); + g_signal_connect (G_OBJECT (fui->input), "activate", + G_CALLBACK (cb_entry_activate), NULL); vbox = gtk_vbox_new (FALSE, 0); widget = gtk_label_new ("Filter"); @@ -491,18 +480,18 @@ create_ui (_filter_ui_t *fui, _filter_data_t *fd) widget = gtk_label_new ("Output Pipe"); gtk_container_add (GTK_CONTAINER (vbox), widget); fui->output = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (fui->output), "osssink fragment=1572872"); /* fixme: gconf default ? */ + gtk_entry_set_text (GTK_ENTRY (fui->output), "osssink fragment=1572872"); /* fixme: gconf default ? */ gtk_container_add (GTK_CONTAINER (vbox), fui->output); gtk_container_add (GTK_CONTAINER (fui->selection), vbox); - g_signal_connect (G_OBJECT (fui->output), "activate", - G_CALLBACK (cb_entry_activate), NULL); + g_signal_connect (G_OBJECT (fui->output), "activate", + G_CALLBACK (cb_entry_activate), NULL); /* control widget is dynamically generated */ /* - g_print ("DEBUG: labeling control area.\n"); - widget = gtk_label_new ("This is the big control area."); - gtk_container_add (GTK_CONTAINER (fui->control), widget); - */ + g_print ("DEBUG: labeling control area.\n"); + widget = gtk_label_new ("This is the big control area."); + gtk_container_add (GTK_CONTAINER (fui->control), widget); + */ } @@ -511,8 +500,8 @@ main (int argc, char *argv[]) { _filter_data_t filter_data; _filter_ui_t filter_ui; - - + + gtk_init (&argc, &argv); gst_init (&argc, &argv); gst_control_init (&argc, &argv); @@ -524,7 +513,6 @@ main (int argc, char *argv[]) gtk_widget_show_all (filter_ui.window); gtk_main (); - + return 0; } - diff --git a/examples/gstplay/player.c b/examples/gstplay/player.c index 32001a9029..3272778bf6 100644 --- a/examples/gstplay/player.c +++ b/examples/gstplay/player.c @@ -16,14 +16,14 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ - + #include static GMainLoop *loop = NULL; static gint64 length = 0; static void -print_tag (const GstTagList *list, const gchar *tag, gpointer unused) +print_tag (const GstTagList * list, const gchar * tag, gpointer unused) { gint i, count; @@ -31,14 +31,14 @@ print_tag (const GstTagList *list, const gchar *tag, gpointer unused) for (i = 0; i < count; i++) { gchar *str; - + if (gst_tag_get_type (tag) == G_TYPE_STRING) { g_assert (gst_tag_list_get_string_index (list, tag, i, &str)); } else { - str = g_strdup_value_contents ( - gst_tag_list_get_value_index (list, tag, i)); + str = + g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i)); } - + if (i == 0) { g_print ("%15s: %s\n", gst_tag_get_nick (tag), str); } else { @@ -50,46 +50,46 @@ print_tag (const GstTagList *list, const gchar *tag, gpointer unused) } static void -got_found_tag (GstPlay *play,GstElement *source, GstTagList *tag_list) +got_found_tag (GstPlay * play, GstElement * source, GstTagList * tag_list) { gst_tag_list_foreach (tag_list, print_tag, NULL); } static void -got_time_tick (GstPlay *play, gint64 time_nanos) +got_time_tick (GstPlay * play, gint64 time_nanos) { g_print ("time tick %f\n", time_nanos / (float) GST_SECOND); } static void -got_stream_length (GstPlay *play, gint64 length_nanos) +got_stream_length (GstPlay * play, gint64 length_nanos) { g_print ("got length %llu\n", length_nanos); length = length_nanos; } static void -got_video_size (GstPlay *play, gint width, gint height) +got_video_size (GstPlay * play, gint width, gint height) { g_print ("got video size %d, %d\n", width, height); } static void -got_eos (GstPlay *play) +got_eos (GstPlay * play) { g_print ("End Of Stream\n"); g_main_loop_quit (loop); } static gboolean -seek_timer (GstPlay *play) +seek_timer (GstPlay * play) { gst_play_seek_to_time (play, length / 2); return FALSE; } static gboolean -idle_iterate (GstPlay *play) +idle_iterate (GstPlay * play) { gst_bin_iterate (GST_BIN (play)); return (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING); @@ -114,8 +114,7 @@ main (int argc, char *argv[]) /* Creating the GstPlay object */ play = gst_play_new (&error); - if (error) - { + if (error) { g_print ("Error: could not create play object:\n%s\n", error->message); g_error_free (error); return 1; @@ -140,17 +139,16 @@ main (int argc, char *argv[]) /* gst_xml_write_file (GST_ELEMENT (play), stdout); */ g_signal_connect (G_OBJECT (play), "time_tick", - G_CALLBACK (got_time_tick), NULL); + G_CALLBACK (got_time_tick), NULL); g_signal_connect (G_OBJECT (play), "stream_length", - G_CALLBACK (got_stream_length), NULL); + G_CALLBACK (got_stream_length), NULL); g_signal_connect (G_OBJECT (play), "have_video_size", - G_CALLBACK (got_video_size), NULL); + G_CALLBACK (got_video_size), NULL); g_signal_connect (G_OBJECT (play), "found_tag", - G_CALLBACK (got_found_tag), NULL); + G_CALLBACK (got_found_tag), NULL); g_signal_connect (G_OBJECT (play), "error", - G_CALLBACK (gst_element_default_error), NULL); - g_signal_connect (G_OBJECT (play), "eos", - G_CALLBACK (got_eos), NULL); + G_CALLBACK (gst_element_default_error), NULL); + g_signal_connect (G_OBJECT (play), "eos", G_CALLBACK (got_eos), NULL); /* Change state to PLAYING */ gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING); @@ -163,9 +161,9 @@ main (int argc, char *argv[]) g_print ("setting pipeline to ready\n"); gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY); - + /* unref - gst_object_unref (GST_OBJECT (play)); */ + gst_object_unref (GST_OBJECT (play)); */ exit (0); } diff --git a/examples/indexing/indexmpeg.c b/examples/indexing/indexmpeg.c index 29b89280b6..48a7ca2372 100644 --- a/examples/indexing/indexmpeg.c +++ b/examples/indexing/indexmpeg.c @@ -24,26 +24,26 @@ static gboolean verbose = FALSE; static gboolean quiet = FALSE; static void -entry_added (GstIndex *index, GstIndexEntry *entry) +entry_added (GstIndex * index, GstIndexEntry * entry) { switch (entry->type) { case GST_INDEX_ENTRY_ID: - g_print ("id %d describes writer %s\n", entry->id, - GST_INDEX_ID_DESCRIPTION (entry)); + g_print ("id %d describes writer %s\n", entry->id, + GST_INDEX_ID_DESCRIPTION (entry)); break; case GST_INDEX_ENTRY_FORMAT: - g_print ("%d: registered format %d for %s\n", entry->id, - GST_INDEX_FORMAT_FORMAT (entry), - GST_INDEX_FORMAT_KEY (entry)); + g_print ("%d: registered format %d for %s\n", entry->id, + GST_INDEX_FORMAT_FORMAT (entry), GST_INDEX_FORMAT_KEY (entry)); break; case GST_INDEX_ENTRY_ASSOCIATION: { gint i; - g_print ("%p, %d: %08x ", entry, entry->id, GST_INDEX_ASSOC_FLAGS (entry)); + g_print ("%p, %d: %08x ", entry, entry->id, + GST_INDEX_ASSOC_FLAGS (entry)); for (i = 0; i < GST_INDEX_NASSOCS (entry); i++) { - g_print ("%d %lld ", GST_INDEX_ASSOC_FORMAT (entry, i), - GST_INDEX_ASSOC_VALUE (entry, i)); + g_print ("%d %lld ", GST_INDEX_ASSOC_FORMAT (entry, i), + GST_INDEX_ASSOC_VALUE (entry, i)); } g_print ("\n"); break; @@ -55,15 +55,15 @@ entry_added (GstIndex *index, GstIndexEntry *entry) typedef struct { - const gchar *padname; - GstPad *target; - GstElement *bin; - GstElement *pipeline; - GstIndex *index; + const gchar *padname; + GstPad *target; + GstElement *bin; + GstElement *pipeline; + GstIndex *index; } dyn_link; static void -dynamic_link (GstPadTemplate *templ, GstPad *newpad, gpointer data) +dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data) { dyn_link *link = (dyn_link *) data; @@ -77,27 +77,25 @@ dynamic_link (GstPadTemplate *templ, GstPad *newpad, gpointer data) } static void -setup_dynamic_linking (GstElement *pipeline, - GstElement *element, - const gchar *padname, - GstPad *target, - GstElement *bin, - GstIndex *index) +setup_dynamic_linking (GstElement * pipeline, + GstElement * element, + const gchar * padname, GstPad * target, GstElement * bin, GstIndex * index) { dyn_link *link; link = g_new0 (dyn_link, 1); - link->padname = g_strdup (padname); - link->target = target; - link->bin = bin; - link->pipeline = pipeline; - link->index = index; + link->padname = g_strdup (padname); + link->target = target; + link->bin = bin; + link->pipeline = pipeline; + link->index = index; - g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link), link); + g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link), + link); } -static GstElement* -make_mpeg_systems_pipeline (const gchar *path, GstIndex *index) +static GstElement * +make_mpeg_systems_pipeline (const gchar * path, GstIndex * index) { GstElement *pipeline; GstElement *src, *demux; @@ -117,12 +115,12 @@ make_mpeg_systems_pipeline (const gchar *path, GstIndex *index) } gst_element_link_pads (src, "src", demux, "sink"); - + return pipeline; } -static GstElement* -make_mpeg_decoder_pipeline (const gchar *path, GstIndex *index) +static GstElement * +make_mpeg_decoder_pipeline (const gchar * path, GstIndex * index) { GstElement *pipeline; GstElement *src, *demux; @@ -145,29 +143,27 @@ make_mpeg_decoder_pipeline (const gchar *path, GstIndex *index) video_decoder = gst_element_factory_make ("mpeg2dec", "video_decoder"); gst_bin_add (GST_BIN (video_bin), video_decoder); - - setup_dynamic_linking (pipeline, demux, "video_00", - gst_element_get_pad (video_decoder, "sink"), - video_bin, index); + + setup_dynamic_linking (pipeline, demux, "video_00", + gst_element_get_pad (video_decoder, "sink"), video_bin, index); audio_bin = gst_bin_new ("audio_bin"); audio_decoder = gst_element_factory_make ("mad", "audio_decoder"); - setup_dynamic_linking (pipeline, demux, "audio_00", - gst_element_get_pad (audio_decoder, "sink"), - audio_bin, index); + setup_dynamic_linking (pipeline, demux, "audio_00", + gst_element_get_pad (audio_decoder, "sink"), audio_bin, index); gst_bin_add (GST_BIN (audio_bin), audio_decoder); if (index) { gst_element_set_index (pipeline, index); } - + return pipeline; } static void -print_progress (GstPad *pad) +print_progress (GstPad * pad) { gint i = 0; gchar status[53]; @@ -181,14 +177,14 @@ print_progress (GstPad *pad) format = GST_FORMAT_PERCENT; res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &value); if (res) { - percent = value / (2 * GST_FORMAT_PERCENT_SCALE); + percent = value / (2 * GST_FORMAT_PERCENT_SCALE); } - + for (i = 0; i < percent; i++) { - status[i+1] = '='; + status[i + 1] = '='; } for (i = percent; i < 50; i++) { - status[i+1] = ' '; + status[i + 1] = ' '; } status[51] = '|'; status[52] = 0; @@ -196,8 +192,8 @@ print_progress (GstPad *pad) g_print ("%s\r", status); } -gint -main (gint argc, gchar *argv[]) +gint +main (gint argc, gchar * argv[]) { GstElement *pipeline; GstElement *src; @@ -208,27 +204,28 @@ main (gint argc, gchar *argv[]) gboolean res; GstElement *sink; struct poptOption options[] = { - { "verbose", 'v', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &verbose, 0, - "Print index entries", NULL}, - { "quiet", 'q', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &quiet, 0, - "don't print progress bar", NULL}, - POPT_TABLEEND - }; + {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0, + "Print index entries", NULL}, + {"quiet", 'q', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &quiet, 0, + "don't print progress bar", NULL}, + POPT_TABLEEND + }; if (!gst_init_check_with_popt_table (&argc, &argv, options) || argc < 3) { - g_print ("usage: %s [-v] \n" - " type can be: 0 mpeg_systems\n" - " 1 mpeg_decoder\n" - " -v : report added index entries\n" - " -q : don't print progress\n" , argv[0]); + g_print ("usage: %s [-v] \n" + " type can be: 0 mpeg_systems\n" + " 1 mpeg_decoder\n" + " -v : report added index entries\n" + " -q : don't print progress\n", argv[0]); return -1; } /* create index that elements can fill */ index = gst_index_factory_make ("memindex"); if (index) { - if (verbose) - g_signal_connect (G_OBJECT (index), "entry_added", G_CALLBACK (entry_added), NULL); + if (verbose) + g_signal_connect (G_OBJECT (index), "entry_added", + G_CALLBACK (entry_added), NULL); g_object_set (G_OBJECT (index), "resolver", 1, NULL); } @@ -247,10 +244,10 @@ main (gint argc, gchar *argv[]) } /* setup some default info/error handlers */ - g_signal_connect (G_OBJECT (pipeline), "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); - g_signal_connect (G_OBJECT (pipeline), "error", - G_CALLBACK (gst_element_default_error), NULL); + g_signal_connect (G_OBJECT (pipeline), "deep_notify", + G_CALLBACK (gst_element_default_deep_notify), NULL); + g_signal_connect (G_OBJECT (pipeline), "error", + G_CALLBACK (gst_element_default_error), NULL); /* get a pad to perform progress reporting on */ src = gst_bin_get_by_name (GST_BIN (pipeline), "src"); @@ -259,7 +256,7 @@ main (gint argc, gchar *argv[]) /* prepare for iteration */ gst_element_set_state (pipeline, GST_STATE_PLAYING); - g_print ("indexing %s...\n", argv [2]); + g_print ("indexing %s...\n", argv[2]); /* run through the complete stream to let it generate an index */ while (gst_bin_iterate (GST_BIN (pipeline))) { if (!quiet && (count % 1000 == 0)) { @@ -285,24 +282,23 @@ main (gint argc, gchar *argv[]) gint total_tm; gst_index_get_writer_id (index, GST_OBJECT (src), &id); - + entry = gst_index_get_assoc_entry (index, id, GST_INDEX_LOOKUP_BEFORE, 0, - GST_FORMAT_TIME, G_MAXINT64); + GST_FORMAT_TIME, G_MAXINT64); g_assert (entry); gst_index_entry_assoc_map (entry, GST_FORMAT_TIME, &result); total_tm = result * 60 / GST_SECOND; g_print ("total time = %.2fs\n", total_tm / 60.0); } - + pad = gst_element_get_pad (src, "src"); sink = gst_element_factory_make ("fakesink", "sink"); gst_element_link_pads (src, "src", sink, "sink"); gst_bin_add (GST_BIN (pipeline), sink); - g_print ("seeking %s...\n", argv [2]); + g_print ("seeking %s...\n", argv[2]); event = gst_event_new_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, 5 * GST_SECOND); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 5 * GST_SECOND); res = gst_pad_send_event (pad, event); if (!res) { @@ -322,4 +318,3 @@ main (gint argc, gchar *argv[]) return 1; } - diff --git a/examples/seeking/cdparanoia.c b/examples/seeking/cdparanoia.c index 646c121c10..e750f3468f 100644 --- a/examples/seeking/cdparanoia.c +++ b/examples/seeking/cdparanoia.c @@ -3,7 +3,7 @@ #include static void -get_position_info (GstElement *cdparanoia) +get_position_info (GstElement * cdparanoia) { GstFormat track_format; const GstFormat *formats; @@ -24,14 +24,13 @@ get_position_info (GstElement *cdparanoia) definition = gst_format_get_details (*formats); format = *formats; - res = gst_pad_query (pad, GST_QUERY_POSITION, - &format, &position); + res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &position); if (format == GST_FORMAT_TIME) { position /= GST_SECOND; - g_print ("%s: %lld:%02lld", definition->nick, position/60, position%60); - } - else { + g_print ("%s: %lld:%02lld", definition->nick, position / 60, + position % 60); + } else { g_print ("%s: %lld", definition->nick, position); } @@ -44,7 +43,7 @@ get_position_info (GstElement *cdparanoia) } static void -get_track_info (GstElement *cdparanoia) +get_track_info (GstElement * cdparanoia) { GstFormat track_format; gint64 total_tracks = 0, total_time = 0; @@ -52,7 +51,7 @@ get_track_info (GstElement *cdparanoia) const GstFormat *formats; gint i; gint64 time_count = 0; - + track_format = gst_format_get_by_nick ("track"); g_assert (track_format != 0); @@ -66,26 +65,24 @@ get_track_info (GstElement *cdparanoia) gint64 total; GstFormat format; gboolean res; - + definition = gst_format_get_details (*formats); format = *formats; - res = gst_pad_query (pad, GST_QUERY_TOTAL, - &format, &total); + res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &total); if (res) { if (format == GST_FORMAT_TIME) { total /= GST_SECOND; - g_print ("%s total: %lld:%02lld\n", definition->nick, total/60, total%60); - } - else - g_print ("%s total: %lld\n", definition->nick, total); + g_print ("%s total: %lld:%02lld\n", definition->nick, total / 60, + total % 60); + } else + g_print ("%s total: %lld\n", definition->nick, total); if (format == track_format) total_tracks = total; else if (format == GST_FORMAT_TIME) total_time = total; - } - else + } else g_print ("failed to get %s total\n", definition->nick); formats++; @@ -102,11 +99,9 @@ get_track_info (GstElement *cdparanoia) GstFormat format; format = GST_FORMAT_TIME; - res = gst_pad_convert (pad, track_format, i, - &format, &time); + res = gst_pad_convert (pad, track_format, i, &format, &time); time /= GST_SECOND; - } - else { + } else { time = total_time; res = TRUE; } @@ -117,14 +112,12 @@ get_track_info (GstElement *cdparanoia) if (i > 0) { gint64 length = time - time_count; - g_print ("track %d: %lld:%02lld -> %lld:%02lld, length: %lld:%02lld\n", - i-1, - time_count / 60, time_count % 60, - time / 60, time % 60, - length / 60, length % 60); + g_print ("track %d: %lld:%02lld -> %lld:%02lld, length: %lld:%02lld\n", + i - 1, + time_count / 60, time_count % 60, + time / 60, time % 60, length / 60, length % 60); } - } - else { + } else { g_print ("could not get time for track %d\n", i); } @@ -161,7 +154,7 @@ main (int argc, char **argv) gst_element_link_pads (cdparanoia, "src", osssink, "sink"); g_signal_connect (G_OBJECT (pipeline), "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); + G_CALLBACK (gst_element_default_deep_notify), NULL); gst_element_set_state (pipeline, GST_STATE_PAUSED); @@ -177,9 +170,7 @@ main (int argc, char **argv) g_print ("playing from track 3\n"); /* seek to track3 */ event = gst_event_new_seek (track_format | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, - 3); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 3); res = gst_pad_send_event (pad, event); if (!res) @@ -198,9 +189,8 @@ main (int argc, char **argv) g_print ("\nplaying from second 25 to second 29\n"); /* seek to some seconds */ event = gst_event_new_segment_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, - 25 * GST_SECOND, 29 * GST_SECOND); + GST_SEEK_METHOD_SET | + GST_SEEK_FLAG_FLUSH, 25 * GST_SECOND, 29 * GST_SECOND); res = gst_pad_send_event (pad, event); if (!res) g_warning ("seek failed"); diff --git a/examples/seeking/cdplayer.c b/examples/seeking/cdplayer.c index 6ce5547157..1e823cc5b5 100644 --- a/examples/seeking/cdplayer.c +++ b/examples/seeking/cdplayer.c @@ -15,11 +15,11 @@ static guint update_id; #define UPDATE_INTERVAL 500 -static GstElement* -make_cdaudio_pipeline (void) +static GstElement * +make_cdaudio_pipeline (void) { GstElement *cdaudio; - + cdaudio = gst_element_factory_make ("cdaudio", "cdaudio"); g_assert (cdaudio != NULL); @@ -28,9 +28,8 @@ make_cdaudio_pipeline (void) return cdaudio; } -static gchar* -format_value (GtkScale *scale, - gdouble value) +static gchar * +format_value (GtkScale * scale, gdouble value) { gint64 real; gint64 seconds; @@ -41,9 +40,7 @@ format_value (GtkScale *scale, subseconds = (gint64) real / (GST_SECOND / 100); return g_strdup_printf ("%02lld:%02lld:%02lld", - seconds/60, - seconds%60, - subseconds%100); + seconds / 60, seconds % 60, subseconds % 100); } typedef struct @@ -52,13 +49,12 @@ typedef struct const GstFormat format; } seek_format; -static seek_format seek_formats[] = -{ - { "tim", GST_FORMAT_TIME }, - { "byt", GST_FORMAT_BYTES }, - { "buf", GST_FORMAT_BUFFERS }, - { "def", GST_FORMAT_DEFAULT }, - { NULL, 0 }, +static seek_format seek_formats[] = { + {"tim", GST_FORMAT_TIME}, + {"byt", GST_FORMAT_BYTES}, + {"buf", GST_FORMAT_BUFFERS}, + {"def", GST_FORMAT_DEFAULT}, + {NULL, 0}, }; @@ -80,10 +76,9 @@ query_durations () format = seek_formats[i].format; res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value); if (res) { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; } @@ -110,10 +105,9 @@ query_positions () format = seek_formats[i].format; res = gst_element_query (element, GST_QUERY_POSITION, &format, &value); if (res) { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; } @@ -123,7 +117,7 @@ query_positions () } static gboolean -update_scale (gpointer data) +update_scale (gpointer data) { GstClock *clock; guint64 position = 0; @@ -134,6 +128,7 @@ update_scale (gpointer data) if (seekable_elements) { GstElement *element = GST_ELEMENT (seekable_elements->data); + gst_element_query (element, GST_QUERY_TOTAL, &format, &duration); } if (clock) @@ -141,7 +136,8 @@ update_scale (gpointer data) if (stats) { if (clock) - g_print ("clock: %13llu (%s)\n", position, gst_object_get_name (GST_OBJECT (clock))); + g_print ("clock: %13llu (%s)\n", position, + gst_object_get_name (GST_OBJECT (clock))); query_durations (); query_positions (); } @@ -167,7 +163,7 @@ iterate (gpointer data) } static gboolean -start_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) { gst_element_set_state (pipeline, GST_STATE_PAUSED); gtk_timeout_remove (update_id); @@ -176,7 +172,7 @@ start_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) } static gboolean -stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) { gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; gboolean res; @@ -188,8 +184,7 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) g_print ("seek to %lld on element %s\n", real, GST_ELEMENT_NAME (seekable)); s_event = gst_event_new_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, real); res = gst_element_send_event (seekable, s_event); @@ -199,7 +194,8 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) gst_element_set_state (pipeline, GST_STATE_PLAYING); if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE)) gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); + update_id = + gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); return FALSE; } @@ -211,7 +207,8 @@ play_cb (GtkButton * button, gpointer data) gst_element_set_state (pipeline, GST_STATE_PLAYING); if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE)) gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); + update_id = + gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); } } @@ -236,22 +233,23 @@ stop_cb (GtkButton * button, gpointer data) int main (int argc, char **argv) { - GtkWidget *window, *hbox, *vbox, - *play_button, *pause_button, *stop_button, - *hscale; + GtkWidget *window, *hbox, *vbox, + *play_button, *pause_button, *stop_button, *hscale; struct poptOption options[] = { - {"stats", 's', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &stats, 0, - "Show element stats", NULL}, - POPT_TABLEEND - }; + {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0, + "Show element stats", NULL}, + POPT_TABLEEND + }; gst_init_with_popt_table (&argc, &argv, options); gtk_init (&argc, &argv); pipeline = make_cdaudio_pipeline (); - g_signal_connect (pipeline, "deep_notify", G_CALLBACK (gst_element_default_deep_notify), NULL); - g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), NULL); + g_signal_connect (pipeline, "deep_notify", + G_CALLBACK (gst_element_default_deep_notify), NULL); + g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), + NULL); /* initialize gui elements ... */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); @@ -261,17 +259,18 @@ main (int argc, char **argv) pause_button = gtk_button_new_with_label ("pause"); stop_button = gtk_button_new_with_label ("stop"); - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); + adjustment = + GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); hscale = gtk_hscale_new (adjustment); gtk_scale_set_digits (GTK_SCALE (hscale), 2); gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - gtk_signal_connect(GTK_OBJECT(hscale), - "button_press_event", G_CALLBACK (start_seek), pipeline); - gtk_signal_connect(GTK_OBJECT(hscale), - "button_release_event", G_CALLBACK (stop_seek), pipeline); - gtk_signal_connect(GTK_OBJECT(hscale), - "format_value", G_CALLBACK (format_value), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "button_press_event", G_CALLBACK (start_seek), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "button_release_event", G_CALLBACK (stop_seek), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "format_value", G_CALLBACK (format_value), pipeline); /* do the packing stuff ... */ gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); @@ -283,9 +282,12 @@ main (int argc, char **argv) gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), pipeline); + g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), + pipeline); + g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), + pipeline); + g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), + pipeline); g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); /* show the gui. */ diff --git a/examples/seeking/seek.c b/examples/seeking/seek.c index 2ad1ca7f8b..34a6958dee 100644 --- a/examples/seeking/seek.c +++ b/examples/seeking/seek.c @@ -25,26 +25,25 @@ static guint update_id; typedef struct { - const gchar *padname; - GstPad *target; - GstElement *bin; + const gchar *padname; + GstPad *target; + GstElement *bin; } dyn_link; static GstElement * -gst_element_factory_make_or_warn (gchar *type, gchar *name) +gst_element_factory_make_or_warn (gchar * type, gchar * name) { GstElement *element = gst_element_factory_make (type, name); if (!element) { - g_warning ("Failed to create element %s of type %s", - name, type); + g_warning ("Failed to create element %s of type %s", name, type); } return element; } static void -dynamic_link (GstPadTemplate *templ, GstPad *newpad, gpointer data) +dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data) { dyn_link *connect = (dyn_link *) data; @@ -60,25 +59,27 @@ dynamic_link (GstPadTemplate *templ, GstPad *newpad, gpointer data) } static void -setup_dynamic_link (GstElement *element, const gchar *padname, GstPad *target, GstElement *bin) +setup_dynamic_link (GstElement * element, const gchar * padname, + GstPad * target, GstElement * bin) { dyn_link *connect; connect = g_new0 (dyn_link, 1); - connect->padname = g_strdup (padname); - connect->target = target; - connect->bin = bin; + connect->padname = g_strdup (padname); + connect->target = target; + connect->bin = bin; - g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link), connect); + g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link), + connect); } -static GstElement* -make_mod_pipeline (const gchar *location) +static GstElement * +make_mod_pipeline (const gchar * location) { GstElement *pipeline; GstElement *src, *decoder, *audiosink; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -103,13 +104,13 @@ make_mod_pipeline (const gchar *location) return pipeline; } -static GstElement* -make_dv_pipeline (const gchar *location) +static GstElement * +make_dv_pipeline (const gchar * location) { GstElement *pipeline; GstElement *src, *decoder, *audiosink, *videosink; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -140,13 +141,13 @@ make_dv_pipeline (const gchar *location) return pipeline; } -static GstElement* -make_wav_pipeline (const gchar *location) +static GstElement * +make_wav_pipeline (const gchar * location) { GstElement *pipeline; GstElement *src, *decoder, *audiosink; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -171,13 +172,13 @@ make_wav_pipeline (const gchar *location) return pipeline; } -static GstElement* -make_flac_pipeline (const gchar *location) +static GstElement * +make_flac_pipeline (const gchar * location) { GstElement *pipeline; GstElement *src, *decoder, *audiosink; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -202,13 +203,13 @@ make_flac_pipeline (const gchar *location) return pipeline; } -static GstElement* -make_sid_pipeline (const gchar *location) +static GstElement * +make_sid_pipeline (const gchar * location) { GstElement *pipeline; GstElement *src, *decoder, *audiosink; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -233,13 +234,13 @@ make_sid_pipeline (const gchar *location) return pipeline; } -static GstElement* -make_parse_pipeline (const gchar *location) +static GstElement * +make_parse_pipeline (const gchar * location) { GstElement *pipeline; GstElement *src, *parser, *fakesink; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -265,13 +266,13 @@ make_parse_pipeline (const gchar *location) return pipeline; } -static GstElement* -make_vorbis_pipeline (const gchar *location) +static GstElement * +make_vorbis_pipeline (const gchar * location) { GstElement *pipeline; GstElement *src, *decoder, *audiosink; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -296,13 +297,13 @@ make_vorbis_pipeline (const gchar *location) return pipeline; } -static GstElement* -make_mp3_pipeline (const gchar *location) +static GstElement * +make_mp3_pipeline (const gchar * location) { GstElement *pipeline; GstElement *src, *decoder, *osssink, *queue, *audio_thread; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -335,14 +336,15 @@ make_mp3_pipeline (const gchar *location) return pipeline; } -static GstElement* -make_avi_pipeline (const gchar *location) +static GstElement * +make_avi_pipeline (const gchar * location) { GstElement *pipeline, *audio_bin, *video_bin; GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink; - GstElement *a_queue = NULL, *audio_thread = NULL, *v_queue = NULL, *video_thread = NULL; + GstElement *a_queue = NULL, *audio_thread = NULL, *v_queue = + NULL, *video_thread = NULL; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -369,12 +371,14 @@ make_avi_pipeline (const gchar *location) gst_bin_add (GST_BIN (audio_thread), audiosink); gst_element_set_state (audio_bin, GST_STATE_PAUSED); - setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, "sink"), audio_bin); + setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, + "sink"), audio_bin); seekable = gst_element_get_pad (a_queue, "src"); seekable_pads = g_list_prepend (seekable_pads, seekable); rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); + rate_pads = + g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); video_bin = gst_bin_new ("v_decoder_bin"); //v_decoder = gst_element_factory_make_or_warn ("identity", "v_dec"); @@ -395,25 +399,27 @@ make_avi_pipeline (const gchar *location) gst_element_set_state (video_bin, GST_STATE_PAUSED); - setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, "sink"), video_bin); + setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, + "sink"), video_bin); seekable = gst_element_get_pad (v_queue, "src"); seekable_pads = g_list_prepend (seekable_pads, seekable); rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); + rate_pads = + g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); return pipeline; } -static GstElement* -make_mpeg_pipeline (const gchar *location) +static GstElement * +make_mpeg_pipeline (const gchar * location) { GstElement *pipeline, *audio_bin, *video_bin; GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter; GstElement *audiosink, *videosink; GstElement *a_queue, *audio_thread, *v_queue, *video_thread; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -441,12 +447,14 @@ make_mpeg_pipeline (const gchar *location) gst_bin_add (GST_BIN (audio_thread), a_queue); gst_bin_add (GST_BIN (audio_thread), audiosink); - setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, "sink"), audio_bin); + setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, + "sink"), audio_bin); seekable = gst_element_get_pad (a_queue, "src"); seekable_pads = g_list_prepend (seekable_pads, seekable); rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); + rate_pads = + g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); video_bin = gst_bin_new ("v_decoder_bin"); v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec"); @@ -456,30 +464,32 @@ make_mpeg_pipeline (const gchar *location) v_filter = gst_element_factory_make_or_warn ("colorspace", "v_filter"); videosink = gst_element_factory_make_or_warn ("xvideosink", "v_sink"); gst_element_link_many (v_decoder, v_queue, v_filter, NULL); - + gst_element_link (v_filter, videosink); gst_bin_add_many (GST_BIN (video_bin), v_decoder, video_thread, NULL); gst_bin_add_many (GST_BIN (video_thread), v_queue, v_filter, videosink, NULL); - setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, "sink"), video_bin); + setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, + "sink"), video_bin); seekable = gst_element_get_pad (v_queue, "src"); seekable_pads = g_list_prepend (seekable_pads, seekable); rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); + rate_pads = + g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); return pipeline; } -static GstElement* -make_mpegnt_pipeline (const gchar *location) +static GstElement * +make_mpegnt_pipeline (const gchar * location) { GstElement *pipeline, *audio_bin, *video_bin; GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter; GstElement *audiosink, *videosink; GstElement *a_queue, *audio_thread; GstPad *seekable; - + pipeline = gst_pipeline_new ("app"); src = gst_element_factory_make_or_warn (SOURCE, "src"); @@ -508,40 +518,43 @@ make_mpegnt_pipeline (const gchar *location) gst_bin_add (GST_BIN (audio_thread), a_queue); gst_bin_add (GST_BIN (audio_thread), audiosink); - setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, "sink"), audio_bin); + setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, + "sink"), audio_bin); seekable = gst_element_get_pad (a_queue, "src"); seekable_pads = g_list_prepend (seekable_pads, seekable); rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); + rate_pads = + g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); video_bin = gst_bin_new ("v_decoder_bin"); v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec"); v_filter = gst_element_factory_make_or_warn ("colorspace", "v_filter"); videosink = gst_element_factory_make_or_warn ("xvideosink", "v_sink"); gst_element_link_many (v_decoder, v_filter, videosink, NULL); - + gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL); - setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, "sink"), video_bin); + setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, + "sink"), video_bin); seekable = gst_element_get_pad (v_decoder, "src"); seekable_pads = g_list_prepend (seekable_pads, seekable); rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); + rate_pads = + g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); return pipeline; } -static GstElement* -make_playerbin_pipeline (const gchar *location) +static GstElement * +make_playerbin_pipeline (const gchar * location) { return NULL; } -static gchar* -format_value (GtkScale *scale, - gdouble value) +static gchar * +format_value (GtkScale * scale, gdouble value) { gint64 real; gint64 seconds; @@ -552,9 +565,7 @@ format_value (GtkScale *scale, subseconds = (gint64) real / (GST_SECOND / 100); return g_strdup_printf ("%02lld:%02lld:%02lld", - seconds/60, - seconds%60, - subseconds%100); + seconds / 60, seconds % 60, subseconds % 100); } typedef struct @@ -563,13 +574,12 @@ typedef struct const GstFormat format; } seek_format; -static seek_format seek_formats[] = -{ - { "tim", GST_FORMAT_TIME }, - { "byt", GST_FORMAT_BYTES }, - { "buf", GST_FORMAT_BUFFERS }, - { "def", GST_FORMAT_DEFAULT }, - { NULL, 0 }, +static seek_format seek_formats[] = { + {"tim", GST_FORMAT_TIME}, + {"byt", GST_FORMAT_BYTES}, + {"buf", GST_FORMAT_BUFFERS}, + {"def", GST_FORMAT_DEFAULT}, + {NULL, 0}, }; G_GNUC_UNUSED static void @@ -588,13 +598,10 @@ query_rates (void) format = seek_formats[i].format; - if (gst_pad_convert (pad, GST_FORMAT_TIME, GST_SECOND, - &format, &value)) - { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + if (gst_pad_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format, &value)) { + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; @@ -623,15 +630,14 @@ query_durations () format = seek_formats[i].format; res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &value); if (res) { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; } g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad)); - + walk = g_list_next (walk); } } @@ -654,10 +660,9 @@ query_positions () format = seek_formats[i].format; res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &value); if (res) { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; } @@ -668,7 +673,7 @@ query_positions () } static gboolean -update_scale (gpointer data) +update_scale (gpointer data) { GstClock *clock; guint64 position; @@ -679,12 +684,14 @@ update_scale (gpointer data) if (seekable_pads) { GstPad *pad = GST_PAD (seekable_pads->data); + gst_pad_query (pad, GST_QUERY_TOTAL, &format, &duration); } position = gst_clock_get_time (clock); if (stats) { - g_print ("clock: %13llu (%s)\n", position, gst_object_get_name (GST_OBJECT (clock))); + g_print ("clock: %13llu (%s)\n", position, + gst_object_get_name (GST_OBJECT (clock))); query_durations (); query_positions (); query_rates (); @@ -711,7 +718,7 @@ iterate (gpointer data) } static gboolean -start_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) { gst_element_set_state (pipeline, GST_STATE_PAUSED); gtk_timeout_remove (update_id); @@ -720,21 +727,23 @@ start_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) } static gboolean -stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) { gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; gboolean res; GstEvent *s_event; + #ifdef PAD_SEEK GList *walk = seekable_pads; while (walk) { GstPad *seekable = GST_PAD (walk->data); - g_print ("seek to %lld on pad %s:%s\n", real, GST_DEBUG_PAD_NAME (seekable)); - s_event = gst_event_new_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); + g_print ("seek to %lld on pad %s:%s\n", real, + GST_DEBUG_PAD_NAME (seekable)); + s_event = + gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | + GST_SEEK_FLAG_FLUSH, real); res = gst_pad_send_event (seekable, s_event); @@ -746,10 +755,11 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) while (walk) { GstElement *seekable = GST_ELEMENT (walk->data); - g_print ("seek to %lld on element %s\n", real, gst_element_get_name (seekable)); - s_event = gst_event_new_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); + g_print ("seek to %lld on element %s\n", real, + gst_element_get_name (seekable)); + s_event = + gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | + GST_SEEK_FLAG_FLUSH, real); res = gst_element_send_event (seekable, s_event); @@ -759,7 +769,8 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) gst_element_set_state (pipeline, GST_STATE_PLAYING); gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); + update_id = + gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); return FALSE; } @@ -770,7 +781,8 @@ play_cb (GtkButton * button, gpointer data) if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) { gst_element_set_state (pipeline, GST_STATE_PLAYING); gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); + update_id = + gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); } } @@ -795,23 +807,23 @@ stop_cb (GtkButton * button, gpointer data) typedef struct { gchar *name; - GstElement* (*func) (const gchar *location); + GstElement *(*func) (const gchar * location); } Pipeline; static Pipeline pipelines[] = { - { "mp3", make_mp3_pipeline }, - { "avi", make_avi_pipeline }, - { "mpeg1", make_mpeg_pipeline }, - { "mpegparse", make_parse_pipeline }, - { "vorbis", make_vorbis_pipeline }, - { "sid", make_sid_pipeline }, - { "flac", make_flac_pipeline }, - { "wav", make_wav_pipeline }, - { "mod", make_mod_pipeline }, - { "dv", make_dv_pipeline }, - { "mpeg1nothreads", make_mpegnt_pipeline }, - { "playerbin", make_playerbin_pipeline }, - { NULL, NULL}, + {"mp3", make_mp3_pipeline}, + {"avi", make_avi_pipeline}, + {"mpeg1", make_mpeg_pipeline}, + {"mpegparse", make_parse_pipeline}, + {"vorbis", make_vorbis_pipeline}, + {"sid", make_sid_pipeline}, + {"flac", make_flac_pipeline}, + {"wav", make_wav_pipeline}, + {"mod", make_mod_pipeline}, + {"dv", make_dv_pipeline}, + {"mpeg1nothreads", make_mpegnt_pipeline}, + {"playerbin", make_playerbin_pipeline}, + {NULL, NULL}, }; #define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1) @@ -832,16 +844,15 @@ print_usage (int argc, char **argv) int main (int argc, char **argv) { - GtkWidget *window, *hbox, *vbox, - *play_button, *pause_button, *stop_button, - *hscale; + GtkWidget *window, *hbox, *vbox, + *play_button, *pause_button, *stop_button, *hscale; struct poptOption options[] = { - { "stats", 's', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &stats, 0, - "Show pad stats", NULL }, + {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0, + "Show pad stats", NULL}, POPT_TABLEEND }; gint type; - + gst_init_with_popt_table (&argc, &argv, options); gtk_init (&argc, &argv); @@ -868,17 +879,18 @@ main (int argc, char **argv) pause_button = gtk_button_new_with_label ("pause"); stop_button = gtk_button_new_with_label ("stop"); - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); + adjustment = + GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); hscale = gtk_hscale_new (adjustment); gtk_scale_set_digits (GTK_SCALE (hscale), 2); gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - gtk_signal_connect(GTK_OBJECT(hscale), - "button_press_event", G_CALLBACK (start_seek), pipeline); - gtk_signal_connect(GTK_OBJECT(hscale), - "button_release_event", G_CALLBACK (stop_seek), pipeline); - gtk_signal_connect(GTK_OBJECT(hscale), - "format_value", G_CALLBACK (format_value), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "button_press_event", G_CALLBACK (start_seek), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "button_release_event", G_CALLBACK (stop_seek), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "format_value", G_CALLBACK (format_value), pipeline); /* do the packing stuff ... */ gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); @@ -890,16 +902,21 @@ main (int argc, char **argv) gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), pipeline); + g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), + pipeline); + g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), + pipeline); + g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), + pipeline); g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); /* show the gui. */ gtk_widget_show_all (window); - g_signal_connect (pipeline, "deep_notify", G_CALLBACK (gst_element_default_deep_notify), NULL); - g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), NULL); + g_signal_connect (pipeline, "deep_notify", + G_CALLBACK (gst_element_default_deep_notify), NULL); + g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), + NULL); gtk_main (); diff --git a/examples/seeking/spider_seek.c b/examples/seeking/spider_seek.c index a21aac166a..d2c2c6b217 100644 --- a/examples/seeking/spider_seek.c +++ b/examples/seeking/spider_seek.c @@ -19,19 +19,19 @@ static guint update_id; #define UPDATE_INTERVAL 500 -static GstElement* -make_spider_pipeline (const gchar *location, gboolean thread) +static GstElement * +make_spider_pipeline (const gchar * location, gboolean thread) { GstElement *pipeline; - GstElement *src, *decoder, *audiosink, *videosink, *a_thread, *v_thread, *a_queue, *v_queue; - + GstElement *src, *decoder, *audiosink, *videosink, *a_thread, *v_thread, + *a_queue, *v_queue; + if (thread) { pipeline = gst_thread_new ("app"); - } - else { + } else { pipeline = gst_pipeline_new ("app"); } - + src = gst_element_factory_make (SOURCE, "src"); decoder = gst_element_factory_make ("spider", "decoder"); @@ -64,15 +64,16 @@ make_spider_pipeline (const gchar *location, gboolean thread) seekable_elements = g_list_prepend (seekable_elements, videosink); seekable_elements = g_list_prepend (seekable_elements, audiosink); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (audiosink, "sink")); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (videosink, "sink")); + rate_pads = + g_list_prepend (rate_pads, gst_element_get_pad (audiosink, "sink")); + rate_pads = + g_list_prepend (rate_pads, gst_element_get_pad (videosink, "sink")); return pipeline; } -static gchar* -format_value (GtkScale *scale, - gdouble value) +static gchar * +format_value (GtkScale * scale, gdouble value) { gint64 real; gint64 seconds; @@ -83,9 +84,7 @@ format_value (GtkScale *scale, subseconds = (gint64) real / (GST_SECOND / 100); return g_strdup_printf ("%02lld:%02lld:%02lld", - seconds/60, - seconds%60, - subseconds%100); + seconds / 60, seconds % 60, subseconds % 100); } typedef struct @@ -94,13 +93,12 @@ typedef struct const GstFormat format; } seek_format; -static seek_format seek_formats[] = -{ - { "tim", GST_FORMAT_TIME }, - { "byt", GST_FORMAT_BYTES }, - { "buf", GST_FORMAT_BUFFERS }, - { "def", GST_FORMAT_DEFAULT }, - { NULL, 0 }, +static seek_format seek_formats[] = { + {"tim", GST_FORMAT_TIME}, + {"byt", GST_FORMAT_BYTES}, + {"buf", GST_FORMAT_BUFFERS}, + {"def", GST_FORMAT_DEFAULT}, + {NULL, 0}, }; G_GNUC_UNUSED static void @@ -119,13 +117,10 @@ query_rates (void) format = seek_formats[i].format; - if (gst_pad_convert (pad, GST_FORMAT_TIME, GST_SECOND, - &format, &value)) - { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + if (gst_pad_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format, &value)) { + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; @@ -154,10 +149,9 @@ query_durations () format = seek_formats[i].format; res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value); if (res) { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; } @@ -184,10 +178,9 @@ query_positions () format = seek_formats[i].format; res = gst_element_query (element, GST_QUERY_POSITION, &format, &value); if (res) { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; } @@ -197,7 +190,7 @@ query_positions () } static gboolean -update_scale (gpointer data) +update_scale (gpointer data) { GstClock *clock; guint64 position; @@ -208,12 +201,14 @@ update_scale (gpointer data) if (seekable_elements) { GstElement *element = GST_ELEMENT (seekable_elements->data); + gst_element_query (element, GST_QUERY_TOTAL, &format, &duration); } position = gst_clock_get_time (clock); if (stats) { - g_print ("clock: %13llu (%s)\n", position, gst_object_get_name (GST_OBJECT (clock))); + g_print ("clock: %13llu (%s)\n", position, + gst_object_get_name (GST_OBJECT (clock))); query_durations (); query_positions (); query_rates (); @@ -239,7 +234,7 @@ iterate (gpointer data) } static gboolean -start_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) { gst_element_set_state (pipeline, GST_STATE_PAUSED); gtk_timeout_remove (update_id); @@ -248,7 +243,7 @@ start_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) } static gboolean -stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) { gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; gboolean res; @@ -260,8 +255,7 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) g_print ("seek to %lld on element %s\n", real, GST_ELEMENT_NAME (seekable)); s_event = gst_event_new_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, real); res = gst_element_send_event (seekable, s_event); @@ -271,7 +265,8 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) gst_element_set_state (pipeline, GST_STATE_PLAYING); if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE)) gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); + update_id = + gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); return FALSE; } @@ -283,7 +278,8 @@ play_cb (GtkButton * button, gpointer data) gst_element_set_state (pipeline, GST_STATE_PLAYING); if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE)) gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); + update_id = + gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); } } @@ -308,17 +304,16 @@ stop_cb (GtkButton * button, gpointer data) int main (int argc, char **argv) { - GtkWidget *window, *hbox, *vbox, - *play_button, *pause_button, *stop_button, - *hscale; + GtkWidget *window, *hbox, *vbox, + *play_button, *pause_button, *stop_button, *hscale; gboolean threaded = FALSE; struct poptOption options[] = { - {"threaded", 't', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &threaded, 0, - "Run the pipeline in a toplevel thread", NULL}, - {"stats", 's', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &stats, 0, - "Show element stats", NULL}, - POPT_TABLEEND - }; + {"threaded", 't', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &threaded, 0, + "Run the pipeline in a toplevel thread", NULL}, + {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0, + "Show element stats", NULL}, + POPT_TABLEEND + }; gst_init_with_popt_table (&argc, &argv, options); gtk_init (&argc, &argv); @@ -338,17 +333,18 @@ main (int argc, char **argv) pause_button = gtk_button_new_with_label ("pause"); stop_button = gtk_button_new_with_label ("stop"); - adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); + adjustment = + GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); hscale = gtk_hscale_new (adjustment); gtk_scale_set_digits (GTK_SCALE (hscale), 2); gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - gtk_signal_connect(GTK_OBJECT(hscale), - "button_press_event", G_CALLBACK (start_seek), pipeline); - gtk_signal_connect(GTK_OBJECT(hscale), - "button_release_event", G_CALLBACK (stop_seek), pipeline); - gtk_signal_connect(GTK_OBJECT(hscale), - "format_value", G_CALLBACK (format_value), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "button_press_event", G_CALLBACK (start_seek), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "button_release_event", G_CALLBACK (stop_seek), pipeline); + gtk_signal_connect (GTK_OBJECT (hscale), + "format_value", G_CALLBACK (format_value), pipeline); /* do the packing stuff ... */ gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); @@ -360,9 +356,12 @@ main (int argc, char **argv) gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), pipeline); + g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), + pipeline); + g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), + pipeline); + g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), + pipeline); g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); /* show the gui. */ diff --git a/examples/seeking/vorbisfile.c b/examples/seeking/vorbisfile.c index acaa60c9d6..ec6844a07a 100644 --- a/examples/seeking/vorbisfile.c +++ b/examples/seeking/vorbisfile.c @@ -4,34 +4,37 @@ static gboolean ready = FALSE; -struct probe_context { +struct probe_context +{ GstElement *pipeline; GstElement *element; - GstPad *pad; - GstFormat ls_format; + GstPad *pad; + GstFormat ls_format; - gint total_ls; + gint total_ls; - GstCaps *metadata; - GstCaps *streaminfo; - GstCaps *caps; + GstCaps *metadata; + GstCaps *streaminfo; + GstCaps *caps; }; static void -print_caps (GstCaps *caps) +print_caps (GstCaps * caps) { char *s; + s = gst_caps_to_string (caps); - g_print(" %s\n", s); + g_print (" %s\n", s); g_free (s); } static void -print_format (GstCaps *caps) +print_format (GstCaps * caps) { char *s; + s = gst_caps_to_string (caps); - g_print(" format: %s\n", s); + g_print (" format: %s\n", s); g_free (s); } @@ -61,35 +64,31 @@ print_lbs_info (struct probe_context *context, gint stream) definition = gst_format_get_details (format); /* get start and end position of this stream */ - res = gst_pad_convert (context->pad, - context->ls_format, stream, - &format, &value_start); + res = gst_pad_convert (context->pad, + context->ls_format, stream, &format, &value_start); res &= gst_pad_convert (context->pad, - context->ls_format, stream + 1, - &format, &value_end); + context->ls_format, stream + 1, &format, &value_end); if (res) { /* substract to get the length */ value_end -= value_start; if (format == GST_FORMAT_TIME) { - value_end /= (GST_SECOND/100); - g_print (" %s: %lld:%02lld.%02lld\n", definition->nick, - value_end/6000, (value_end/100)%60, (value_end%100)); + value_end /= (GST_SECOND / 100); + g_print (" %s: %lld:%02lld.%02lld\n", definition->nick, + value_end / 6000, (value_end / 100) % 60, (value_end % 100)); + } else { + g_print (" %s: %lld\n", definition->nick, value_end); } - else { - g_print (" %s: %lld\n", definition->nick, value_end); - } - } - else + } else g_print (" could not get logical stream %s\n", definition->nick); } } static void -deep_notify (GObject *object, GstObject *origin, - GParamSpec *pspec, gpointer data) +deep_notify (GObject * object, GstObject * origin, + GParamSpec * pspec, gpointer data) { struct probe_context *context = (struct probe_context *) data; GValue value = { 0, }; @@ -99,8 +98,7 @@ deep_notify (GObject *object, GstObject *origin, g_value_init (&value, pspec->value_type); g_object_get_property (G_OBJECT (origin), pspec->name, &value); context->metadata = g_value_peek_pointer (&value); - } - else if (!strcmp (pspec->name, "streaminfo")) { + } else if (!strcmp (pspec->name, "streaminfo")) { g_value_init (&value, pspec->value_type); g_object_get_property (G_OBJECT (origin), pspec->name, &value); @@ -127,9 +125,7 @@ collect_logical_stream_properties (struct probe_context *context, gint stream) /* seek to stream */ event = gst_event_new_seek (context->ls_format | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, - stream); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, stream); res = gst_pad_send_event (context->pad, event); if (!res) { g_warning ("seek to logical track failed"); @@ -141,7 +137,8 @@ collect_logical_stream_properties (struct probe_context *context, gint stream) ready = FALSE; while (gst_bin_iterate (GST_BIN (context->pipeline)) && !ready) { count++; - if (count > 10) break; + if (count > 10) + break; } print_caps (context->metadata); @@ -177,21 +174,19 @@ collect_stream_properties (struct probe_context *context) format = *formats; formats++; - res = gst_pad_query (context->pad, GST_QUERY_TOTAL, - &format, &value); + res = gst_pad_query (context->pad, GST_QUERY_TOTAL, &format, &value); definition = gst_format_get_details (format); if (res) { if (format == GST_FORMAT_TIME) { - value /= (GST_SECOND/100); - g_print (" total %s: %lld:%02lld.%02lld\n", definition->nick, - value/6000, (value/100)%60, (value%100)); - } - else { - if (format == context->ls_format) - context->total_ls = value; - g_print (" total %s: %lld\n", definition->nick, value); + value /= (GST_SECOND / 100); + g_print (" total %s: %lld:%02lld.%02lld\n", definition->nick, + value / 6000, (value / 100) % 60, (value % 100)); + } else { + if (format == context->ls_format) + context->total_ls = value; + g_print (" total %s: %lld\n", definition->nick, value); } } } @@ -248,7 +243,7 @@ main (int argc, char **argv) context->ls_format = logical_stream_format; g_signal_connect (G_OBJECT (pipeline), "deep_notify", - G_CALLBACK (deep_notify), context); + G_CALLBACK (deep_notify), context); gst_element_set_state (pipeline, GST_STATE_PLAYING); diff --git a/examples/stats/mp2ogg.c b/examples/stats/mp2ogg.c index e5d3fbd9bc..55d79e90c7 100644 --- a/examples/stats/mp2ogg.c +++ b/examples/stats/mp2ogg.c @@ -24,8 +24,8 @@ * compression status of mpeg audio to ogg vorbis transcoding. */ -gint -main (gint argc, gchar *argv[]) +gint +main (gint argc, gchar * argv[]) { GstElement *pipeline; GError *error = NULL; @@ -34,21 +34,22 @@ main (gint argc, gchar *argv[]) GstPad *dec_sink, *enc_src; gst_init (&argc, &argv); - + if (argc < 3) { g_print ("usage: %s \n", argv[0]); return -1; } description = g_strdup_printf ("filesrc location=\"%s\" ! mad name=decoder ! " - "vorbisenc name=encoder ! filesink location=\"%s\"", argv[1], argv[2]); + "vorbisenc name=encoder ! filesink location=\"%s\"", argv[1], argv[2]); pipeline = GST_ELEMENT (gst_parse_launch (description, &error)); if (!pipeline) { if (error) - g_print ("ERROR: pipeline could not be constructed: %s\n", error->message); + g_print ("ERROR: pipeline could not be constructed: %s\n", + error->message); else - g_print ("ERROR: pipeline could not be constructed\n"); + g_print ("ERROR: pipeline could not be constructed\n"); return -1; } @@ -57,7 +58,7 @@ main (gint argc, gchar *argv[]) dec_sink = gst_element_get_pad (decoder, "sink"); enc_src = gst_element_get_pad (encoder, "src"); - + if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) { g_print ("pipeline doesn't want to play\n"); return -1; @@ -71,33 +72,29 @@ main (gint argc, gchar *argv[]) format = GST_FORMAT_TIME; /* get the position */ - gst_pad_query (enc_src, GST_QUERY_POSITION, - &format, &position); + gst_pad_query (enc_src, GST_QUERY_POSITION, &format, &position); /* get the total duration */ - gst_pad_query (enc_src, GST_QUERY_TOTAL, - &format, &duration); + gst_pad_query (enc_src, GST_QUERY_TOTAL, &format, &duration); format = GST_FORMAT_BYTES; /* see how many bytes are genereated per 8 seconds (== bitrate) */ gst_pad_convert (enc_src, GST_FORMAT_TIME, 8 * GST_SECOND, - &format, &bitrate_enc); + &format, &bitrate_enc); gst_pad_convert (dec_sink, GST_FORMAT_TIME, 8 * GST_SECOND, - &format, &bitrate_dec); + &format, &bitrate_dec); g_print ("[%2dm %.2ds] of [%2dm %.2ds], " - "src avg bitrate: %lld, dest avg birate: %lld, ratio [%02.2f] \r", - (gint)(position / (GST_SECOND * 60)), - (gint)(position / (GST_SECOND)) % 60, - (gint)(duration / (GST_SECOND * 60)), - (gint)(duration / (GST_SECOND)) % 60, - bitrate_dec, - bitrate_enc, - (gfloat)bitrate_dec/bitrate_enc); + "src avg bitrate: %lld, dest avg birate: %lld, ratio [%02.2f] \r", + (gint) (position / (GST_SECOND * 60)), + (gint) (position / (GST_SECOND)) % 60, + (gint) (duration / (GST_SECOND * 60)), + (gint) (duration / (GST_SECOND)) % 60, + bitrate_dec, bitrate_enc, (gfloat) bitrate_dec / bitrate_enc); } g_print ("\n"); - + return 0; } diff --git a/examples/switch/switcher.c b/examples/switch/switcher.c index d0bc4a670c..6296f6adcb 100644 --- a/examples/switch/switcher.c +++ b/examples/switch/switcher.c @@ -16,7 +16,7 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ - + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -28,38 +28,36 @@ static GMainLoop *loop = NULL; static void -got_eos (GstElement *pipeline) +got_eos (GstElement * pipeline) { g_main_loop_quit (loop); } static gboolean -idle_iterate (GstElement *pipeline) +idle_iterate (GstElement * pipeline) { gst_bin_iterate (GST_BIN (pipeline)); return (GST_STATE (GST_ELEMENT (pipeline)) == GST_STATE_PLAYING); } static gboolean -switch_timer (GstElement *video_switch) +switch_timer (GstElement * video_switch) { gint nb_sources, active_source; - + g_object_get (G_OBJECT (video_switch), "nb_sources", &nb_sources, NULL); - g_object_get (G_OBJECT (video_switch), "active_source", - &active_source, NULL); - - active_source ++; - + g_object_get (G_OBJECT (video_switch), "active_source", &active_source, NULL); + + active_source++; + if (active_source > nb_sources - 1) active_source = 0; - - g_object_set (G_OBJECT (video_switch), "active_source", - active_source, NULL); - + + g_object_set (G_OBJECT (video_switch), "active_source", active_source, NULL); + g_message ("current number of sources : %d, active source %d", - nb_sources, active_source); - + nb_sources, active_source); + return (GST_STATE (GST_ELEMENT (video_switch)) == GST_STATE_PLAYING); } @@ -72,7 +70,7 @@ main (int argc, char *argv[]) gst_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); - + pipeline = gst_pipeline_new ("pipeline"); src1 = gst_element_factory_make ("videotestsrc", "src1"); g_object_set (G_OBJECT (src1), "pattern", 0, NULL); @@ -80,26 +78,25 @@ main (int argc, char *argv[]) g_object_set (G_OBJECT (src2), "pattern", 1, NULL); video_switch = gst_element_factory_make ("switch", "video_switch"); video_sink = gst_element_factory_make ("ximagesink", "video_sink"); - + gst_bin_add_many (GST_BIN (pipeline), src1, src2, video_switch, - video_sink, NULL); - + video_sink, NULL); + gst_element_link (src1, video_switch); gst_element_link (src2, video_switch); gst_element_link (video_switch, video_sink); - - g_signal_connect (G_OBJECT (pipeline), "eos", - G_CALLBACK (got_eos), NULL); + + g_signal_connect (G_OBJECT (pipeline), "eos", G_CALLBACK (got_eos), NULL); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); - + g_idle_add ((GSourceFunc) idle_iterate, pipeline); g_timeout_add (2000, (GSourceFunc) switch_timer, video_switch); - + g_main_loop_run (loop); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY); - + /* unref */ gst_object_unref (GST_OBJECT (pipeline)); diff --git a/ext/a52dec/gsta52dec.c b/ext/a52dec/gsta52dec.c index 1dcb002535..682f93b46b 100644 --- a/ext/a52dec/gsta52dec.c +++ b/ext/a52dec/gsta52dec.c @@ -57,43 +57,37 @@ enum * "audio/a52" and "audio/ac3" are the same format. The name * "ac3" is now deprecated and should not be used in new code. */ -static GstStaticPadTemplate sink_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-ac3") -); +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-ac3") + ); -static GstStaticPadTemplate src_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-int, " - "endianness = (int) BYTE_ORDER, " - "signed = (boolean) true, " - "width = (int) 16, " - "depth = (int) 16, " - "rate = (int) [ 4000, 48000 ], " - "channels = (int) [ 1, 6 ]" - ) -); +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) BYTE_ORDER, " + "signed = (boolean) true, " + "width = (int) 16, " + "depth = (int) 16, " + "rate = (int) [ 4000, 48000 ], " "channels = (int) [ 1, 6 ]") + ); -static void gst_a52dec_base_init (gpointer g_class); -static void gst_a52dec_class_init (GstA52DecClass * klass); -static void gst_a52dec_init (GstA52Dec * a52dec); +static void gst_a52dec_base_init (gpointer g_class); +static void gst_a52dec_class_init (GstA52DecClass * klass); +static void gst_a52dec_init (GstA52Dec * a52dec); -static void gst_a52dec_loop (GstElement * element); -static GstElementStateReturn - gst_a52dec_change_state (GstElement * element); +static void gst_a52dec_loop (GstElement * element); +static GstElementStateReturn gst_a52dec_change_state (GstElement * element); -static void gst_a52dec_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_a52dec_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); +static void gst_a52dec_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_a52dec_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); static GstElementClass *parent_class = NULL; + /* static guint gst_a52dec_signals[LAST_SIGNAL] = { 0 }; */ GType @@ -103,8 +97,8 @@ gst_a52dec_get_type (void) if (!a52dec_type) { static const GTypeInfo a52dec_info = { - sizeof (GstA52DecClass), - gst_a52dec_base_init, + sizeof (GstA52DecClass), + gst_a52dec_base_init, NULL, (GClassInitFunc) gst_a52dec_class_init, NULL, NULL, @@ -113,7 +107,8 @@ gst_a52dec_get_type (void) (GInstanceInitFunc) gst_a52dec_init, }; - a52dec_type = g_type_register_static (GST_TYPE_ELEMENT, "GstA52Dec", &a52dec_info, 0); + a52dec_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstA52Dec", &a52dec_info, 0); } return a52dec_type; } @@ -141,9 +136,8 @@ gst_a52dec_class_init (GstA52DecClass * klass) parent_class = g_type_class_ref (GST_TYPE_ELEMENT); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DRC, - g_param_spec_boolean ("drc", "Dynamic Range Compression", - "Use Dynamic Range Compression", FALSE, - G_PARAM_READWRITE)); + g_param_spec_boolean ("drc", "Dynamic Range Compression", + "Use Dynamic Range Compression", FALSE, G_PARAM_READWRITE)); gobject_class->set_property = gst_a52dec_set_property; gobject_class->get_property = gst_a52dec_get_property; @@ -155,13 +149,15 @@ static void gst_a52dec_init (GstA52Dec * a52dec) { /* create the sink and src pads */ - a52dec->sinkpad = gst_pad_new_from_template ( - gst_element_get_pad_template (GST_ELEMENT (a52dec), "sink"), "sink"); + a52dec->sinkpad = + gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT + (a52dec), "sink"), "sink"); gst_element_add_pad (GST_ELEMENT (a52dec), a52dec->sinkpad); gst_element_set_loop_function ((GstElement *) a52dec, gst_a52dec_loop); - a52dec->srcpad = gst_pad_new_from_template ( - gst_element_get_pad_template (GST_ELEMENT (a52dec), "src"), "src"); + a52dec->srcpad = + gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT + (a52dec), "src"), "src"); gst_pad_use_explicit_caps (a52dec->srcpad); gst_element_add_pad (GST_ELEMENT (a52dec), a52dec->srcpad); @@ -190,87 +186,87 @@ float_to_int (float *_f, int16_t * s16, int flags) switch (flags) { case A52_MONO: for (i = 0; i < 256; i++) { - s16[5 * i] = s16[5 * i + 1] = s16[5 * i + 2] = s16[5 * i + 3] = 0; - s16[5 * i + 4] = convert (f[i]); + s16[5 * i] = s16[5 * i + 1] = s16[5 * i + 2] = s16[5 * i + 3] = 0; + s16[5 * i + 4] = convert (f[i]); } break; case A52_CHANNEL: case A52_STEREO: case A52_DOLBY: for (i = 0; i < 256; i++) { - s16[2 * i] = convert (f[i]); - s16[2 * i + 1] = convert (f[i + 256]); + s16[2 * i] = convert (f[i]); + s16[2 * i + 1] = convert (f[i + 256]); } break; case A52_3F: for (i = 0; i < 256; i++) { - s16[5 * i] = convert (f[i]); - s16[5 * i + 1] = convert (f[i + 512]); - s16[5 * i + 2] = s16[5 * i + 3] = 0; - s16[5 * i + 4] = convert (f[i + 256]); + s16[5 * i] = convert (f[i]); + s16[5 * i + 1] = convert (f[i + 512]); + s16[5 * i + 2] = s16[5 * i + 3] = 0; + s16[5 * i + 4] = convert (f[i + 256]); } break; case A52_2F2R: for (i = 0; i < 256; i++) { - s16[4 * i] = convert (f[i]); - s16[4 * i + 1] = convert (f[i + 256]); - s16[4 * i + 2] = convert (f[i + 512]); - s16[4 * i + 3] = convert (f[i + 768]); + s16[4 * i] = convert (f[i]); + s16[4 * i + 1] = convert (f[i + 256]); + s16[4 * i + 2] = convert (f[i + 512]); + s16[4 * i + 3] = convert (f[i + 768]); } break; case A52_3F2R: for (i = 0; i < 256; i++) { - s16[5 * i] = convert (f[i]); - s16[5 * i + 1] = convert (f[i + 512]); - s16[5 * i + 2] = convert (f[i + 768]); - s16[5 * i + 3] = convert (f[i + 1024]); - s16[5 * i + 4] = convert (f[i + 256]); + s16[5 * i] = convert (f[i]); + s16[5 * i + 1] = convert (f[i + 512]); + s16[5 * i + 2] = convert (f[i + 768]); + s16[5 * i + 3] = convert (f[i + 1024]); + s16[5 * i + 4] = convert (f[i + 256]); } break; case A52_MONO | A52_LFE: for (i = 0; i < 256; i++) { - s16[6 * i] = s16[6 * i + 1] = s16[6 * i + 2] = s16[6 * i + 3] = 0; - s16[6 * i + 4] = convert (f[i + 256]); - s16[6 * i + 5] = convert (f[i]); + s16[6 * i] = s16[6 * i + 1] = s16[6 * i + 2] = s16[6 * i + 3] = 0; + s16[6 * i + 4] = convert (f[i + 256]); + s16[6 * i + 5] = convert (f[i]); } break; case A52_CHANNEL | A52_LFE: case A52_STEREO | A52_LFE: case A52_DOLBY | A52_LFE: for (i = 0; i < 256; i++) { - s16[6 * i] = convert (f[i + 256]); - s16[6 * i + 1] = convert (f[i + 512]); - s16[6 * i + 2] = s16[6 * i + 3] = s16[6 * i + 4] = 0; - s16[6 * i + 5] = convert (f[i]); + s16[6 * i] = convert (f[i + 256]); + s16[6 * i + 1] = convert (f[i + 512]); + s16[6 * i + 2] = s16[6 * i + 3] = s16[6 * i + 4] = 0; + s16[6 * i + 5] = convert (f[i]); } break; case A52_3F | A52_LFE: for (i = 0; i < 256; i++) { - s16[6 * i] = convert (f[i + 256]); - s16[6 * i + 1] = convert (f[i + 768]); - s16[6 * i + 2] = s16[6 * i + 3] = 0; - s16[6 * i + 4] = convert (f[i + 512]); - s16[6 * i + 5] = convert (f[i]); + s16[6 * i] = convert (f[i + 256]); + s16[6 * i + 1] = convert (f[i + 768]); + s16[6 * i + 2] = s16[6 * i + 3] = 0; + s16[6 * i + 4] = convert (f[i + 512]); + s16[6 * i + 5] = convert (f[i]); } break; case A52_2F2R | A52_LFE: for (i = 0; i < 256; i++) { - s16[6 * i] = convert (f[i + 256]); - s16[6 * i + 1] = convert (f[i + 512]); - s16[6 * i + 2] = convert (f[i + 768]); - s16[6 * i + 3] = convert (f[i + 1024]); - s16[6 * i + 4] = 0; - s16[6 * i + 5] = convert (f[i]); + s16[6 * i] = convert (f[i + 256]); + s16[6 * i + 1] = convert (f[i + 512]); + s16[6 * i + 2] = convert (f[i + 768]); + s16[6 * i + 3] = convert (f[i + 1024]); + s16[6 * i + 4] = 0; + s16[6 * i + 5] = convert (f[i]); } break; case A52_3F2R | A52_LFE: for (i = 0; i < 256; i++) { - s16[6 * i] = convert (f[i + 256]); - s16[6 * i + 1] = convert (f[i + 768]); - s16[6 * i + 2] = convert (f[i + 1024]); - s16[6 * i + 3] = convert (f[i + 1280]); - s16[6 * i + 4] = convert (f[i + 512]); - s16[6 * i + 5] = convert (f[i]); + s16[6 * i] = convert (f[i + 256]); + s16[6 * i + 1] = convert (f[i + 768]); + s16[6 * i + 2] = convert (f[i + 1024]); + s16[6 * i + 3] = convert (f[i + 1280]); + s16[6 * i + 4] = convert (f[i + 512]); + s16[6 * i + 5] = convert (f[i]); } break; } @@ -310,7 +306,8 @@ gst_a52dec_channels (int flags) } static int -gst_a52dec_push (GstPad * srcpad, int flags, sample_t * _samples, gint64 timestamp) +gst_a52dec_push (GstPad * srcpad, int flags, sample_t * _samples, + gint64 timestamp) { GstBuffer *buf; int chans; @@ -348,21 +345,19 @@ gst_a52dec_push (GstPad * srcpad, int flags, sample_t * _samples, gint64 timesta static void gst_a52dec_reneg (GstPad * pad, int channels, int rate) { - GST_INFO ( "a52dec: reneg channels:%d rate:%d\n", channels, rate); + GST_INFO ("a52dec: reneg channels:%d rate:%d\n", channels, rate); - gst_pad_set_explicit_caps (pad, + gst_pad_set_explicit_caps (pad, gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, TRUE, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "channels", G_TYPE_INT, channels, - "rate", G_TYPE_INT, rate, - NULL)); + "endianness", G_TYPE_INT, G_BYTE_ORDER, + "signed", G_TYPE_BOOLEAN, TRUE, + "width", G_TYPE_INT, 16, + "depth", G_TYPE_INT, 16, + "channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, rate, NULL)); } static void -gst_a52dec_handle_event (GstA52Dec *a52dec) +gst_a52dec_handle_event (GstA52Dec * a52dec) { guint32 remaining; GstEvent *event; @@ -385,27 +380,26 @@ gst_a52dec_handle_event (GstA52Dec *a52dec) #if 0 static void -gst_a52dec_update_streaminfo (GstA52Dec *a52dec) +gst_a52dec_update_streaminfo (GstA52Dec * a52dec) { GstProps *props; GstPropsEntry *entry; - + props = gst_props_empty_new (); - + entry = gst_props_entry_new ("bitrate", GST_PROPS_INT (a52dec->bit_rate)); gst_props_add_entry (props, (GstPropsEntry *) entry); gst_caps_unref (a52dec->streaminfo); a52dec->streaminfo = gst_caps_new ("a52dec_streaminfo", - "application/x-gst-streaminfo", - props); + "application/x-gst-streaminfo", props); g_object_notify (G_OBJECT (a52dec), "streaminfo"); } #endif static void -gst_a52dec_loop (GstElement *element) +gst_a52dec_loop (GstElement * element) { GstA52Dec *a52dec; guint8 *data; @@ -429,8 +423,7 @@ gst_a52dec_loop (GstElement *element) if (length == 0) { /* slide window to next 7 bytesa */ gst_bytestream_flush_fast (a52dec->bs, 1); - } - else + } else break; /* FIXME this can potentially be an infinite loop, we might @@ -460,8 +453,7 @@ gst_a52dec_loop (GstElement *element) timestamp = gst_bytestream_get_timestamp (a52dec->bs); if (timestamp == a52dec->last_ts) { timestamp = a52dec->current_ts; - } - else { + } else { a52dec->last_ts = timestamp; } @@ -483,9 +475,9 @@ gst_a52dec_loop (GstElement *element) if (need_reneg == TRUE) { GST_DEBUG ("a52dec reneg: sample_rate:%d stream_chans:%d using_chans:%d\n", - a52dec->sample_rate, a52dec->stream_channels, a52dec->using_channels); + a52dec->sample_rate, a52dec->stream_channels, a52dec->using_channels); gst_a52dec_reneg (a52dec->srcpad, - gst_a52dec_channels (a52dec->using_channels), a52dec->sample_rate); + gst_a52dec_channels (a52dec->using_channels), a52dec->sample_rate); } if (a52dec->dynamic_range_compression == FALSE) { @@ -498,10 +490,10 @@ gst_a52dec_loop (GstElement *element) continue; } /* push on */ - if (gst_a52dec_push (a52dec->srcpad, a52dec->using_channels, a52dec->samples, timestamp)) { + if (gst_a52dec_push (a52dec->srcpad, a52dec->using_channels, + a52dec->samples, timestamp)) { g_warning ("a52dec push error\n"); - } - else { + } else { timestamp += sizeof (int16_t) * 256 * GST_SECOND / a52dec->sample_rate; } } @@ -558,7 +550,8 @@ gst_a52dec_change_state (GstElement * element) } static void -gst_a52dec_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) +gst_a52dec_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { GstA52Dec *src; @@ -577,7 +570,8 @@ gst_a52dec_set_property (GObject * object, guint prop_id, const GValue * value, } static void -gst_a52dec_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) +gst_a52dec_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstA52Dec *src; @@ -602,20 +596,15 @@ plugin_init (GstPlugin * plugin) if (!gst_library_load ("gstbytestream")) return FALSE; - if (!gst_element_register (plugin, "a52dec", GST_RANK_PRIMARY, GST_TYPE_A52DEC)) + if (!gst_element_register (plugin, "a52dec", GST_RANK_PRIMARY, + GST_TYPE_A52DEC)) return FALSE; return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "a52dec", - "Decodes ATSC A/52 encoded audio streams", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN -); +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "a52dec", + "Decodes ATSC A/52 encoded audio streams", + plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN); diff --git a/ext/a52dec/gsta52dec.h b/ext/a52dec/gsta52dec.h index 1796965f4e..4587f1669a 100644 --- a/ext/a52dec/gsta52dec.h +++ b/ext/a52dec/gsta52dec.h @@ -25,7 +25,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_A52DEC \ (gst_a52dec_get_type()) #define GST_A52DEC(obj) \ @@ -36,38 +35,37 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_A52DEC)) #define GST_IS_A52DEC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_A52DEC)) - typedef struct _GstA52Dec GstA52Dec; typedef struct _GstA52DecClass GstA52DecClass; -struct _GstA52Dec { - GstElement element; +struct _GstA52Dec +{ + GstElement element; /* pads */ - GstPad *sinkpad, - *srcpad; - int bit_rate; - int sample_rate; - int stream_channels; - int request_channels; - int using_channels; + GstPad *sinkpad, *srcpad; + int bit_rate; + int sample_rate; + int stream_channels; + int request_channels; + int using_channels; - sample_t level; - sample_t bias; - gboolean dynamic_range_compression; - sample_t *samples; - a52_state_t *state; + sample_t level; + sample_t bias; + gboolean dynamic_range_compression; + sample_t *samples; + a52_state_t *state; GstByteStream *bs; - GstClockTime last_ts; - GstClockTime current_ts; + GstClockTime last_ts; + GstClockTime current_ts; }; -struct _GstA52DecClass { +struct _GstA52DecClass +{ GstElementClass parent_class; }; G_END_DECLS - #endif /* __GST_A52DEC_H__ */ diff --git a/ext/dvdnav/dvdnavsrc.c b/ext/dvdnav/dvdnavsrc.c index 08ceb636b1..9e8bad2e54 100644 --- a/ext/dvdnav/dvdnavsrc.c +++ b/ext/dvdnav/dvdnavsrc.c @@ -47,11 +47,12 @@ typedef struct _DVDNavSrc DVDNavSrc; typedef struct _DVDNavSrcClass DVDNavSrcClass; -struct _DVDNavSrc { +struct _DVDNavSrc +{ GstElement element; /* pads */ - GstPad *srcpad; + GstPad *srcpad; GstCaps *streaminfo; /* location */ @@ -66,13 +67,14 @@ struct _DVDNavSrc { GstCaps *buttoninfo; }; -struct _DVDNavSrcClass { +struct _DVDNavSrcClass +{ GstElementClass parent_class; - void (*button_pressed) (DVDNavSrc *src, int button); - void (*pointer_select) (DVDNavSrc *src, int x, int y); - void (*pointer_activate) (DVDNavSrc *src, int x, int y); - void (*user_op) (DVDNavSrc *src, int op); + void (*button_pressed) (DVDNavSrc * src, int button); + void (*pointer_select) (DVDNavSrc * src, int x, int y); + void (*pointer_activate) (DVDNavSrc * src, int x, int y); + void (*user_op) (DVDNavSrc * src, int op); }; /* elementfactory information */ @@ -85,7 +87,8 @@ GstElementDetails dvdnavsrc_details = { /* DVDNavSrc signals and args */ -enum { +enum +{ BUTTON_PRESSED_SIGNAL, POINTER_SELECT_SIGNAL, POINTER_ACTIVATE_SIGNAL, @@ -93,7 +96,8 @@ enum { LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_LOCATION, ARG_STREAMINFO, @@ -104,50 +108,53 @@ enum { ARG_ANGLE }; -typedef enum { - DVDNAVSRC_OPEN = GST_ELEMENT_FLAG_LAST, +typedef enum +{ + DVDNAVSRC_OPEN = GST_ELEMENT_FLAG_LAST, - DVDNAVSRC_FLAG_LAST = GST_ELEMENT_FLAG_LAST+2, + DVDNAVSRC_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2, } DVDNavSrcFlags; -GType dvdnavsrc_get_type (void); -static void dvdnavsrc_base_init (gpointer g_class); -static void dvdnavsrc_class_init (DVDNavSrcClass *klass); -static void dvdnavsrc_init (DVDNavSrc *dvdnavsrc); +GType dvdnavsrc_get_type (void); +static void dvdnavsrc_base_init (gpointer g_class); +static void dvdnavsrc_class_init (DVDNavSrcClass * klass); +static void dvdnavsrc_init (DVDNavSrc * dvdnavsrc); -static void dvdnavsrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void dvdnavsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void dvdnavsrc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void dvdnavsrc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static GstData *dvdnavsrc_get (GstPad * pad); -static GstData * dvdnavsrc_get (GstPad *pad); /*static GstBuffer * dvdnavsrc_get_region (GstPad *pad,gulong offset,gulong size); */ -static gboolean dvdnavsrc_event (GstPad *pad, GstEvent *event); -static const GstEventMask* - dvdnavsrc_get_event_mask (GstPad *pad); -static const GstFormat* - dvdnavsrc_get_formats (GstPad *pad); +static gboolean dvdnavsrc_event (GstPad * pad, GstEvent * event); +static const GstEventMask *dvdnavsrc_get_event_mask (GstPad * pad); +static const GstFormat *dvdnavsrc_get_formats (GstPad * pad); + /*static gboolean dvdnavsrc_convert (GstPad *pad, GstFormat src_format, gint64 src_value, GstFormat *dest_format, gint64 *dest_value);*/ -static gboolean dvdnavsrc_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value); -static const GstQueryType* - dvdnavsrc_get_query_types (GstPad *pad); +static gboolean dvdnavsrc_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value); +static const GstQueryType *dvdnavsrc_get_query_types (GstPad * pad); -static gboolean dvdnavsrc_close (DVDNavSrc *src); -static gboolean dvdnavsrc_open (DVDNavSrc *src); -static gboolean dvdnavsrc_is_open (DVDNavSrc *src); -static void dvdnavsrc_print_event (DVDNavSrc *src, guint8 *data, int event, int len); -static void dvdnavsrc_update_streaminfo (DVDNavSrc *src); -static void dvdnavsrc_update_buttoninfo (DVDNavSrc *src); -static void dvdnavsrc_button_pressed (DVDNavSrc *src, int button); -static void dvdnavsrc_pointer_select (DVDNavSrc *src, int x, int y); -static void dvdnavsrc_pointer_activate (DVDNavSrc *src, int x, int y); -static void dvdnavsrc_user_op (DVDNavSrc *src, int op); +static gboolean dvdnavsrc_close (DVDNavSrc * src); +static gboolean dvdnavsrc_open (DVDNavSrc * src); +static gboolean dvdnavsrc_is_open (DVDNavSrc * src); +static void dvdnavsrc_print_event (DVDNavSrc * src, guint8 * data, int event, + int len); +static void dvdnavsrc_update_streaminfo (DVDNavSrc * src); +static void dvdnavsrc_update_buttoninfo (DVDNavSrc * src); +static void dvdnavsrc_button_pressed (DVDNavSrc * src, int button); +static void dvdnavsrc_pointer_select (DVDNavSrc * src, int x, int y); +static void dvdnavsrc_pointer_activate (DVDNavSrc * src, int x, int y); +static void dvdnavsrc_user_op (DVDNavSrc * src, int op); -static GstElementStateReturn dvdnavsrc_change_state (GstElement *element); +static GstElementStateReturn dvdnavsrc_change_state (GstElement * element); static GstElementClass *parent_class = NULL; @@ -159,23 +166,25 @@ static GstFormat chapter_format; static GstFormat angle_format; GType -dvdnavsrc_get_type (void) +dvdnavsrc_get_type (void) { static GType dvdnavsrc_type = 0; if (!dvdnavsrc_type) { static const GTypeInfo dvdnavsrc_info = { - sizeof(DVDNavSrcClass), + sizeof (DVDNavSrcClass), dvdnavsrc_base_init, NULL, - (GClassInitFunc)dvdnavsrc_class_init, + (GClassInitFunc) dvdnavsrc_class_init, NULL, NULL, - sizeof(DVDNavSrc), + sizeof (DVDNavSrc), 0, - (GInstanceInitFunc)dvdnavsrc_init, + (GInstanceInitFunc) dvdnavsrc_init, }; - dvdnavsrc_type = g_type_register_static (GST_TYPE_ELEMENT, "DVDNavSrc", &dvdnavsrc_info, 0); + dvdnavsrc_type = + g_type_register_static (GST_TYPE_ELEMENT, "DVDNavSrc", &dvdnavsrc_info, + 0); sector_format = gst_format_register ("sector", "DVD sector"); title_format = gst_format_register ("title", "DVD title"); @@ -194,105 +203,94 @@ dvdnavsrc_base_init (gpointer g_class) } static void -dvdnavsrc_class_init (DVDNavSrcClass *klass) +dvdnavsrc_class_init (DVDNavSrcClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); dvdnavsrc_signals[BUTTON_PRESSED_SIGNAL] = - g_signal_new ("button-pressed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (DVDNavSrcClass, button_pressed), - NULL, NULL, - gst_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); + g_signal_new ("button-pressed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (DVDNavSrcClass, button_pressed), + NULL, NULL, gst_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); dvdnavsrc_signals[POINTER_SELECT_SIGNAL] = - g_signal_new ("pointer-select", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (DVDNavSrcClass, pointer_select), - NULL, NULL, - gst_marshal_VOID__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_INT, G_TYPE_INT); + g_signal_new ("pointer-select", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (DVDNavSrcClass, pointer_select), + NULL, NULL, + gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); dvdnavsrc_signals[POINTER_ACTIVATE_SIGNAL] = - g_signal_new ("pointer-activate", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (DVDNavSrcClass, pointer_activate), - NULL, NULL, - gst_marshal_VOID__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_INT, G_TYPE_INT); + g_signal_new ("pointer-activate", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (DVDNavSrcClass, pointer_activate), + NULL, NULL, + gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); dvdnavsrc_signals[USER_OP_SIGNAL] = - g_signal_new ("user-op", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (DVDNavSrcClass, user_op), - NULL, NULL, - gst_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); + g_signal_new ("user-op", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (DVDNavSrcClass, user_op), + NULL, NULL, gst_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); klass->button_pressed = dvdnavsrc_button_pressed; klass->pointer_select = dvdnavsrc_pointer_select; klass->pointer_activate = dvdnavsrc_pointer_activate; klass->user_op = dvdnavsrc_user_op; - - g_object_class_install_property(gobject_class, ARG_LOCATION, - g_param_spec_string("location", "location", "location", - NULL, G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, ARG_TITLE_STRING, - g_param_spec_string("title_string", "title string", "DVD title string", - NULL, G_PARAM_READABLE)); - g_object_class_install_property(gobject_class, ARG_TITLE, - g_param_spec_int("title", "title", "title", - 0,99,1,G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, ARG_CHAPTER, - g_param_spec_int("chapter", "chapter", "chapter", - 0,99,1,G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, ARG_ANGLE, - g_param_spec_int("angle", "angle", "angle", - 1,9,1,G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, ARG_STREAMINFO, - g_param_spec_boxed("streaminfo", "streaminfo", "streaminfo", - GST_TYPE_CAPS, G_PARAM_READABLE)); - g_object_class_install_property(gobject_class, ARG_BUTTONINFO, - g_param_spec_boxed("buttoninfo", "buttoninfo", "buttoninfo", - GST_TYPE_CAPS, G_PARAM_READABLE)); - gobject_class->set_property = GST_DEBUG_FUNCPTR(dvdnavsrc_set_property); - gobject_class->get_property = GST_DEBUG_FUNCPTR(dvdnavsrc_get_property); + g_object_class_install_property (gobject_class, ARG_LOCATION, + g_param_spec_string ("location", "location", "location", + NULL, G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_TITLE_STRING, + g_param_spec_string ("title_string", "title string", "DVD title string", + NULL, G_PARAM_READABLE)); + g_object_class_install_property (gobject_class, ARG_TITLE, + g_param_spec_int ("title", "title", "title", + 0, 99, 1, G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_CHAPTER, + g_param_spec_int ("chapter", "chapter", "chapter", + 0, 99, 1, G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_ANGLE, + g_param_spec_int ("angle", "angle", "angle", 1, 9, 1, G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_STREAMINFO, + g_param_spec_boxed ("streaminfo", "streaminfo", "streaminfo", + GST_TYPE_CAPS, G_PARAM_READABLE)); + g_object_class_install_property (gobject_class, ARG_BUTTONINFO, + g_param_spec_boxed ("buttoninfo", "buttoninfo", "buttoninfo", + GST_TYPE_CAPS, G_PARAM_READABLE)); + + gobject_class->set_property = GST_DEBUG_FUNCPTR (dvdnavsrc_set_property); + gobject_class->get_property = GST_DEBUG_FUNCPTR (dvdnavsrc_get_property); gstelement_class->change_state = dvdnavsrc_change_state; } -static void -dvdnavsrc_init (DVDNavSrc *src) +static void +dvdnavsrc_init (DVDNavSrc * src) { src->srcpad = gst_pad_new ("src", GST_PAD_SRC); gst_pad_set_get_function (src->srcpad, dvdnavsrc_get); gst_pad_set_event_function (src->srcpad, dvdnavsrc_event); gst_pad_set_event_mask_function (src->srcpad, dvdnavsrc_get_event_mask); - /*gst_pad_set_convert_function (src->srcpad, dvdnavsrc_convert);*/ + /*gst_pad_set_convert_function (src->srcpad, dvdnavsrc_convert); */ gst_pad_set_query_function (src->srcpad, dvdnavsrc_query); gst_pad_set_query_type_function (src->srcpad, dvdnavsrc_get_query_types); gst_pad_set_formats_function (src->srcpad, dvdnavsrc_get_formats); gst_element_add_pad (GST_ELEMENT (src), src->srcpad); - src->location = g_strdup("/dev/dvd"); + src->location = g_strdup ("/dev/dvd"); src->did_seek = FALSE; src->need_flush = FALSE; src->title = 0; @@ -302,8 +300,8 @@ dvdnavsrc_init (DVDNavSrc *src) src->buttoninfo = NULL; } -static gboolean -dvdnavsrc_is_open (DVDNavSrc *src) +static gboolean +dvdnavsrc_is_open (DVDNavSrc * src) { g_return_val_if_fail (src != NULL, FALSE); g_return_val_if_fail (GST_IS_DVDNAVSRC (src), FALSE); @@ -311,14 +309,15 @@ dvdnavsrc_is_open (DVDNavSrc *src) return GST_FLAG_IS_SET (src, DVDNAVSRC_OPEN); } -static void -dvdnavsrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +static void +dvdnavsrc_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { DVDNavSrc *src; /* it's not null if we got it, but it might not be ours */ g_return_if_fail (GST_IS_DVDNAVSRC (object)); - + src = DVDNAVSRC (object); switch (prop_id) { @@ -327,13 +326,13 @@ dvdnavsrc_set_property (GObject *object, guint prop_id, const GValue *value, GPa /*g_return_if_fail(!GST_FLAG_IS_SET(src,GST_STATE_RUNNING)); */ if (src->location) - g_free (src->location); + g_free (src->location); /* clear the filename if we get a NULL (is that possible?) */ if (g_value_get_string (value) == NULL) - src->location = g_strdup("/dev/dvd"); + src->location = g_strdup ("/dev/dvd"); /* otherwise set the new filename */ else - src->location = g_strdup (g_value_get_string (value)); + src->location = g_strdup (g_value_get_string (value)); break; case ARG_TITLE: src->title = g_value_get_int (value); @@ -353,15 +352,16 @@ dvdnavsrc_set_property (GObject *object, guint prop_id, const GValue *value, GPa } -static void -dvdnavsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +static void +dvdnavsrc_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { DVDNavSrc *src; const char *title_string; /* it's not null if we got it, but it might not be ours */ g_return_if_fail (GST_IS_DVDNAVSRC (object)); - + src = DVDNAVSRC (object); switch (prop_id) { @@ -375,13 +375,13 @@ dvdnavsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe g_value_set_boxed (value, src->buttoninfo); break; case ARG_TITLE_STRING: - if (!dvdnavsrc_is_open(src)) { - g_value_set_string (value, ""); - } else if (dvdnav_get_title_string(src->dvdnav, &title_string) != - DVDNAV_STATUS_OK) { - g_value_set_string (value, "UNKNOWN"); + if (!dvdnavsrc_is_open (src)) { + g_value_set_string (value, ""); + } else if (dvdnav_get_title_string (src->dvdnav, &title_string) != + DVDNAV_STATUS_OK) { + g_value_set_string (value, "UNKNOWN"); } else { - g_value_set_string (value, title_string); + g_value_set_string (value, title_string); } break; case ARG_TITLE: @@ -400,7 +400,7 @@ dvdnavsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe } static gboolean -dvdnavsrc_tca_seek(DVDNavSrc *src, int title, int chapter, int angle) +dvdnavsrc_tca_seek (DVDNavSrc * src, int title, int chapter, int angle) { int titles, programs, curangle, angles; @@ -416,7 +416,8 @@ dvdnavsrc_tca_seek(DVDNavSrc *src, int title, int chapter, int angle) * Make sure our title number is valid. */ if (dvdnav_get_number_of_titles (src->dvdnav, &titles) != DVDNAV_STATUS_OK) { - fprintf (stderr, "dvdnav_get_number_of_titles error: %s\n", dvdnav_err_to_string(src->dvdnav)); + fprintf (stderr, "dvdnav_get_number_of_titles error: %s\n", + dvdnav_err_to_string (src->dvdnav)); return FALSE; } fprintf (stderr, "There are %d titles on this DVD.\n", titles); @@ -433,7 +434,7 @@ dvdnavsrc_tca_seek(DVDNavSrc *src, int title, int chapter, int angle) */ if (dvdnav_title_play (src->dvdnav, title) != DVDNAV_STATUS_OK) { fprintf (stderr, "dvdnav_title_play error: %s\n", - dvdnav_err_to_string(src->dvdnav)); + dvdnav_err_to_string (src->dvdnav)); return FALSE; } @@ -441,7 +442,8 @@ dvdnavsrc_tca_seek(DVDNavSrc *src, int title, int chapter, int angle) * Make sure the chapter number is valid for this title. */ if (dvdnav_get_number_of_titles (src->dvdnav, &programs) != DVDNAV_STATUS_OK) { - fprintf( stderr, "dvdnav_get_number_of_programs error: %s\n", dvdnav_err_to_string(src->dvdnav)); + fprintf (stderr, "dvdnav_get_number_of_programs error: %s\n", + dvdnav_err_to_string (src->dvdnav)); return FALSE; } fprintf (stderr, "There are %d chapters in this title.\n", programs); @@ -454,12 +456,14 @@ dvdnavsrc_tca_seek(DVDNavSrc *src, int title, int chapter, int angle) /** * Make sure the angle number is valid for this title. */ - if (dvdnav_get_angle_info (src->dvdnav, &curangle, &angles) != DVDNAV_STATUS_OK) { - fprintf (stderr, "dvdnav_get_angle_info error: %s\n", dvdnav_err_to_string(src->dvdnav)); + if (dvdnav_get_angle_info (src->dvdnav, &curangle, + &angles) != DVDNAV_STATUS_OK) { + fprintf (stderr, "dvdnav_get_angle_info error: %s\n", + dvdnav_err_to_string (src->dvdnav)); return FALSE; } fprintf (stderr, "There are %d angles in this title.\n", angles); - if( angle < 1 || angle > angles) { + if (angle < 1 || angle > angles) { fprintf (stderr, "Invalid angle %d\n", angle); dvdnavsrc_close (src); return FALSE; @@ -470,30 +474,33 @@ dvdnavsrc_tca_seek(DVDNavSrc *src, int title, int chapter, int angle) */ if (src->chapter == 0) { if (dvdnav_title_play (src->dvdnav, title) != DVDNAV_STATUS_OK) { - fprintf (stderr, "dvdnav_title_play error: %s\n", dvdnav_err_to_string(src->dvdnav)); + fprintf (stderr, "dvdnav_title_play error: %s\n", + dvdnav_err_to_string (src->dvdnav)); return FALSE; } } else { if (dvdnav_part_play (src->dvdnav, title, chapter) != DVDNAV_STATUS_OK) { - fprintf (stderr, "dvdnav_part_play error: %s\n", dvdnav_err_to_string(src->dvdnav)); + fprintf (stderr, "dvdnav_part_play error: %s\n", + dvdnav_err_to_string (src->dvdnav)); return FALSE; } } if (dvdnav_angle_change (src->dvdnav, angle) != DVDNAV_STATUS_OK) { - fprintf (stderr, "dvdnav_angle_change error: %s\n", dvdnav_err_to_string(src->dvdnav)); + fprintf (stderr, "dvdnav_angle_change error: %s\n", + dvdnav_err_to_string (src->dvdnav)); return FALSE; } /* - if (dvdnav_physical_audio_stream_change (src->dvdnav, 0) != DVDNAV_STATUS_OK) { - fprintf (stderr, "dvdnav_physical_audio_stream_change error: %s\n", dvdnav_err_to_string(src->dvdnav)); - return FALSE; - } - if (dvdnav_logical_audio_stream_change (src->dvdnav, 0) != DVDNAV_STATUS_OK) { - fprintf (stderr, "dvdnav_logical_audio_stream_change error: %s\n", dvdnav_err_to_string(src->dvdnav)); - return FALSE; - } - */ + if (dvdnav_physical_audio_stream_change (src->dvdnav, 0) != DVDNAV_STATUS_OK) { + fprintf (stderr, "dvdnav_physical_audio_stream_change error: %s\n", dvdnav_err_to_string(src->dvdnav)); + return FALSE; + } + if (dvdnav_logical_audio_stream_change (src->dvdnav, 0) != DVDNAV_STATUS_OK) { + fprintf (stderr, "dvdnav_logical_audio_stream_change error: %s\n", dvdnav_err_to_string(src->dvdnav)); + return FALSE; + } + */ src->did_seek = TRUE; @@ -501,34 +508,35 @@ dvdnavsrc_tca_seek(DVDNavSrc *src, int title, int chapter, int angle) } static void -dvdnavsrc_update_streaminfo (DVDNavSrc *src) +dvdnavsrc_update_streaminfo (DVDNavSrc * src) { GstCaps *caps; GstStructure *structure; gint64 value; - caps = gst_caps_new_empty(); + caps = gst_caps_new_empty (); structure = gst_structure_empty_new ("application/x-gst-streaminfo"); gst_caps_append_structure (caps, structure); - if (dvdnavsrc_query(src->srcpad, GST_QUERY_TOTAL, &title_format, &value)) { + if (dvdnavsrc_query (src->srcpad, GST_QUERY_TOTAL, &title_format, &value)) { gst_caps_set_simple (caps, "titles", G_TYPE_INT, value, NULL); } - if (dvdnavsrc_query(src->srcpad, GST_QUERY_POSITION, &title_format, &value)) { + if (dvdnavsrc_query (src->srcpad, GST_QUERY_POSITION, &title_format, &value)) { gst_caps_set_simple (caps, "title", G_TYPE_INT, value, NULL); } - if (dvdnavsrc_query(src->srcpad, GST_QUERY_TOTAL, &chapter_format, &value)) { + if (dvdnavsrc_query (src->srcpad, GST_QUERY_TOTAL, &chapter_format, &value)) { gst_caps_set_simple (caps, "chapters", G_TYPE_INT, value, NULL); } - if (dvdnavsrc_query(src->srcpad, GST_QUERY_POSITION, &chapter_format, &value)) { + if (dvdnavsrc_query (src->srcpad, GST_QUERY_POSITION, &chapter_format, + &value)) { gst_caps_set_simple (caps, "chapter", G_TYPE_INT, value, NULL); } - if (dvdnavsrc_query(src->srcpad, GST_QUERY_TOTAL, &angle_format, &value)) { + if (dvdnavsrc_query (src->srcpad, GST_QUERY_TOTAL, &angle_format, &value)) { gst_caps_set_simple (caps, "angles", G_TYPE_INT, value, NULL); } - if (dvdnavsrc_query(src->srcpad, GST_QUERY_POSITION, &angle_format, &value)) { + if (dvdnavsrc_query (src->srcpad, GST_QUERY_POSITION, &angle_format, &value)) { gst_caps_set_simple (caps, "angle", G_TYPE_INT, value, NULL); } @@ -540,29 +548,26 @@ dvdnavsrc_update_streaminfo (DVDNavSrc *src) } static void -dvdnavsrc_update_buttoninfo (DVDNavSrc *src) +dvdnavsrc_update_buttoninfo (DVDNavSrc * src) { GstCaps *caps; pci_t *pci; - pci = dvdnav_get_current_nav_pci(src->dvdnav); + pci = dvdnav_get_current_nav_pci (src->dvdnav); if (src->buttoninfo) { gint btn_ns; /* Don't notify if there is no actual change */ if (gst_structure_get_int (gst_caps_get_structure (src->buttoninfo, 0), - "total", &btn_ns) - && (btn_ns == pci->hli.hl_gi.btn_ns)) - { + "total", &btn_ns) + && (btn_ns == pci->hli.hl_gi.btn_ns)) { return; } } - caps = gst_caps_new_simple ( - "application/x-gst-dvdnavsrc-buttoninfo", - "total", G_TYPE_INT, (gint) pci->hli.hl_gi.btn_ns, - NULL); + caps = gst_caps_new_simple ("application/x-gst-dvdnavsrc-buttoninfo", + "total", G_TYPE_INT, (gint) pci->hli.hl_gi.btn_ns, NULL); if (src->buttoninfo) gst_caps_free (src->buttoninfo); @@ -572,204 +577,244 @@ dvdnavsrc_update_buttoninfo (DVDNavSrc *src) } static void -dvdnavsrc_button_pressed (DVDNavSrc *src, int button) +dvdnavsrc_button_pressed (DVDNavSrc * src, int button) { } static void -dvdnavsrc_pointer_select (DVDNavSrc *src, int x, int y) +dvdnavsrc_pointer_select (DVDNavSrc * src, int x, int y) { - dvdnav_mouse_select(src->dvdnav, - dvdnav_get_current_nav_pci(src->dvdnav), - x, y); + dvdnav_mouse_select (src->dvdnav, + dvdnav_get_current_nav_pci (src->dvdnav), x, y); } static void -dvdnavsrc_pointer_activate (DVDNavSrc *src, int x, int y) +dvdnavsrc_pointer_activate (DVDNavSrc * src, int x, int y) { - dvdnav_mouse_activate(src->dvdnav, - dvdnav_get_current_nav_pci(src->dvdnav), - x, y); + dvdnav_mouse_activate (src->dvdnav, + dvdnav_get_current_nav_pci (src->dvdnav), x, y); } static void -dvdnavsrc_user_op (DVDNavSrc *src, int op) +dvdnavsrc_user_op (DVDNavSrc * src, int op) { - pci_t *pci = dvdnav_get_current_nav_pci(src->dvdnav); + pci_t *pci = dvdnav_get_current_nav_pci (src->dvdnav); fprintf (stderr, "user_op %d\n", op); /* Magic user_op ids */ switch (op) { - case 0: /* None */ + case 0: /* None */ break; - case 1: /* Upper */ - if (dvdnav_upper_button_select(src->dvdnav, pci) != DVDNAV_STATUS_OK) { - goto naverr; + case 1: /* Upper */ + if (dvdnav_upper_button_select (src->dvdnav, pci) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 2: /* Lower */ - if (dvdnav_lower_button_select(src->dvdnav, pci) != DVDNAV_STATUS_OK) { - goto naverr; + case 2: /* Lower */ + if (dvdnav_lower_button_select (src->dvdnav, pci) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 3: /* Left */ - if (dvdnav_left_button_select(src->dvdnav, pci) != DVDNAV_STATUS_OK) { - goto naverr; + case 3: /* Left */ + if (dvdnav_left_button_select (src->dvdnav, pci) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 4: /* Right */ - if (dvdnav_right_button_select(src->dvdnav, pci) != DVDNAV_STATUS_OK) { - goto naverr; + case 4: /* Right */ + if (dvdnav_right_button_select (src->dvdnav, pci) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 5: /* Activate */ - if (dvdnav_button_activate(src->dvdnav, pci) != DVDNAV_STATUS_OK) { - goto naverr; + case 5: /* Activate */ + if (dvdnav_button_activate (src->dvdnav, pci) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 6: /* GoUp */ - if (dvdnav_go_up(src->dvdnav) != DVDNAV_STATUS_OK) { - goto naverr; + case 6: /* GoUp */ + if (dvdnav_go_up (src->dvdnav) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 7: /* TopPG */ - if (dvdnav_top_pg_search(src->dvdnav) != DVDNAV_STATUS_OK) { - goto naverr; + case 7: /* TopPG */ + if (dvdnav_top_pg_search (src->dvdnav) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 8: /* PrevPG */ - if (dvdnav_prev_pg_search(src->dvdnav) != DVDNAV_STATUS_OK) { - goto naverr; + case 8: /* PrevPG */ + if (dvdnav_prev_pg_search (src->dvdnav) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 9: /* NextPG */ - if (dvdnav_next_pg_search(src->dvdnav) != DVDNAV_STATUS_OK) { - goto naverr; + case 9: /* NextPG */ + if (dvdnav_next_pg_search (src->dvdnav) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 10: /* Menu - Title */ - if (dvdnav_menu_call(src->dvdnav, DVD_MENU_Title) != DVDNAV_STATUS_OK) { - goto naverr; + case 10: /* Menu - Title */ + if (dvdnav_menu_call (src->dvdnav, DVD_MENU_Title) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 11: /* Menu - Root */ - if (dvdnav_menu_call(src->dvdnav, DVD_MENU_Root) != DVDNAV_STATUS_OK) { - goto naverr; + case 11: /* Menu - Root */ + if (dvdnav_menu_call (src->dvdnav, DVD_MENU_Root) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 12: /* Menu - Subpicture */ - if (dvdnav_menu_call(src->dvdnav, DVD_MENU_Subpicture) != DVDNAV_STATUS_OK) { - goto naverr; + case 12: /* Menu - Subpicture */ + if (dvdnav_menu_call (src->dvdnav, + DVD_MENU_Subpicture) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 13: /* Menu - Audio */ - if (dvdnav_menu_call(src->dvdnav, DVD_MENU_Audio) != DVDNAV_STATUS_OK) { - goto naverr; + case 13: /* Menu - Audio */ + if (dvdnav_menu_call (src->dvdnav, DVD_MENU_Audio) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 14: /* Menu - Angle */ - if (dvdnav_menu_call(src->dvdnav, DVD_MENU_Angle) != DVDNAV_STATUS_OK) { - goto naverr; + case 14: /* Menu - Angle */ + if (dvdnav_menu_call (src->dvdnav, DVD_MENU_Angle) != DVDNAV_STATUS_OK) { + goto naverr; } break; - case 15: /* Menu - Part */ - if (dvdnav_menu_call(src->dvdnav, DVD_MENU_Part) != DVDNAV_STATUS_OK) { - goto naverr; + case 15: /* Menu - Part */ + if (dvdnav_menu_call (src->dvdnav, DVD_MENU_Part) != DVDNAV_STATUS_OK) { + goto naverr; } break; } return; naverr: GST_ELEMENT_ERROR (src, LIBRARY, TOO_LAZY, (NULL), - ("user op %d failure: %s", op, dvdnav_err_to_string(src->dvdnav))); + ("user op %d failure: %s", op, dvdnav_err_to_string (src->dvdnav))); } static gchar * -dvdnav_get_event_name(int event) +dvdnav_get_event_name (int event) { switch (event) { - case DVDNAV_BLOCK_OK: return "DVDNAV_BLOCK_OK"; break; - case DVDNAV_NOP: return "DVDNAV_NOP"; break; - case DVDNAV_STILL_FRAME: return "DVDNAV_STILL_FRAME"; break; - case DVDNAV_SPU_STREAM_CHANGE: return "DVDNAV_SPU_STREAM_CHANGE"; break; - case DVDNAV_AUDIO_STREAM_CHANGE: return "DVDNAV_AUDIO_STREAM_CHANGE"; break; - case DVDNAV_VTS_CHANGE: return "DVDNAV_VTS_CHANGE"; break; - case DVDNAV_CELL_CHANGE: return "DVDNAV_CELL_CHANGE"; break; - case DVDNAV_NAV_PACKET: return "DVDNAV_NAV_PACKET"; break; - case DVDNAV_STOP: return "DVDNAV_STOP"; break; - case DVDNAV_HIGHLIGHT: return "DVDNAV_HIGHLIGHT"; break; - case DVDNAV_SPU_CLUT_CHANGE: return "DVDNAV_SPU_CLUT_CHANGE"; break; - case DVDNAV_HOP_CHANNEL: return "DVDNAV_HOP_CHANNEL"; break; - case DVDNAV_WAIT: return "DVDNAV_WAIT"; break; + case DVDNAV_BLOCK_OK: + return "DVDNAV_BLOCK_OK"; + break; + case DVDNAV_NOP: + return "DVDNAV_NOP"; + break; + case DVDNAV_STILL_FRAME: + return "DVDNAV_STILL_FRAME"; + break; + case DVDNAV_SPU_STREAM_CHANGE: + return "DVDNAV_SPU_STREAM_CHANGE"; + break; + case DVDNAV_AUDIO_STREAM_CHANGE: + return "DVDNAV_AUDIO_STREAM_CHANGE"; + break; + case DVDNAV_VTS_CHANGE: + return "DVDNAV_VTS_CHANGE"; + break; + case DVDNAV_CELL_CHANGE: + return "DVDNAV_CELL_CHANGE"; + break; + case DVDNAV_NAV_PACKET: + return "DVDNAV_NAV_PACKET"; + break; + case DVDNAV_STOP: + return "DVDNAV_STOP"; + break; + case DVDNAV_HIGHLIGHT: + return "DVDNAV_HIGHLIGHT"; + break; + case DVDNAV_SPU_CLUT_CHANGE: + return "DVDNAV_SPU_CLUT_CHANGE"; + break; + case DVDNAV_HOP_CHANNEL: + return "DVDNAV_HOP_CHANNEL"; + break; + case DVDNAV_WAIT: + return "DVDNAV_WAIT"; + break; } return "UNKNOWN"; } static gchar * -dvdnav_get_read_domain_name(dvd_read_domain_t domain) +dvdnav_get_read_domain_name (dvd_read_domain_t domain) { switch (domain) { - case DVD_READ_INFO_FILE: return "DVD_READ_INFO_FILE"; break; - case DVD_READ_INFO_BACKUP_FILE: return "DVD_READ_INFO_BACKUP_FILE"; break; - case DVD_READ_MENU_VOBS: return "DVD_READ_MENU_VOBS"; break; - case DVD_READ_TITLE_VOBS: return "DVD_READ_TITLE_VOBS"; break; + case DVD_READ_INFO_FILE: + return "DVD_READ_INFO_FILE"; + break; + case DVD_READ_INFO_BACKUP_FILE: + return "DVD_READ_INFO_BACKUP_FILE"; + break; + case DVD_READ_MENU_VOBS: + return "DVD_READ_MENU_VOBS"; + break; + case DVD_READ_TITLE_VOBS: + return "DVD_READ_TITLE_VOBS"; + break; } return "UNKNOWN"; } static void -dvdnavsrc_print_event (DVDNavSrc *src, guint8 *data, int event, int len) +dvdnavsrc_print_event (DVDNavSrc * src, guint8 * data, int event, int len) { g_return_if_fail (src != NULL); g_return_if_fail (GST_IS_DVDNAVSRC (src)); - fprintf (stderr, "dvdnavsrc (%p): event: %s\n", src, dvdnav_get_event_name(event)); + fprintf (stderr, "dvdnavsrc (%p): event: %s\n", src, + dvdnav_get_event_name (event)); switch (event) { case DVDNAV_BLOCK_OK: break; case DVDNAV_NOP: break; case DVDNAV_STILL_FRAME: - { - dvdnav_still_event_t *event = (dvdnav_still_event_t *)data; - fprintf (stderr, " still frame: %d seconds\n", event->length); - } + { + dvdnav_still_event_t *event = (dvdnav_still_event_t *) data; + + fprintf (stderr, " still frame: %d seconds\n", event->length); + } break; case DVDNAV_SPU_STREAM_CHANGE: - { - dvdnav_spu_stream_change_event_t * event = (dvdnav_spu_stream_change_event_t *)data; - fprintf (stderr, " physical_wide: %d\n", event->physical_wide); - fprintf (stderr, " physical_letterbox: %d\n", event->physical_letterbox); - fprintf (stderr, " physical_pan_scan: %d\n", event->physical_pan_scan); - fprintf (stderr, " logical: %d\n", event->logical); - } + { + dvdnav_spu_stream_change_event_t *event = + (dvdnav_spu_stream_change_event_t *) data; + fprintf (stderr, " physical_wide: %d\n", event->physical_wide); + fprintf (stderr, " physical_letterbox: %d\n", event->physical_letterbox); + fprintf (stderr, " physical_pan_scan: %d\n", event->physical_pan_scan); + fprintf (stderr, " logical: %d\n", event->logical); + } break; case DVDNAV_AUDIO_STREAM_CHANGE: - { - dvdnav_audio_stream_change_event_t * event = (dvdnav_audio_stream_change_event_t *)data; - fprintf (stderr, " physical: %d\n", event->physical); - fprintf (stderr, " logical: %d\n", event->logical); - } + { + dvdnav_audio_stream_change_event_t *event = + (dvdnav_audio_stream_change_event_t *) data; + fprintf (stderr, " physical: %d\n", event->physical); + fprintf (stderr, " logical: %d\n", event->logical); + } break; case DVDNAV_VTS_CHANGE: - { - dvdnav_vts_change_event_t *event = (dvdnav_vts_change_event_t *)data; - fprintf (stderr, " old_vtsN: %d\n", event->old_vtsN); - fprintf (stderr, " old_domain: %s\n", dvdnav_get_read_domain_name(event->old_domain)); - fprintf (stderr, " new_vtsN: %d\n", event->new_vtsN); - fprintf (stderr, " new_domain: %s\n", dvdnav_get_read_domain_name(event->new_domain)); - } + { + dvdnav_vts_change_event_t *event = (dvdnav_vts_change_event_t *) data; + + fprintf (stderr, " old_vtsN: %d\n", event->old_vtsN); + fprintf (stderr, " old_domain: %s\n", + dvdnav_get_read_domain_name (event->old_domain)); + fprintf (stderr, " new_vtsN: %d\n", event->new_vtsN); + fprintf (stderr, " new_domain: %s\n", + dvdnav_get_read_domain_name (event->new_domain)); + } break; case DVDNAV_CELL_CHANGE: - { - /*dvdnav_cell_change_event_t *event = (dvdnav_cell_change_event_t *)data;*/ - /*fprintf (stderr, " old_cell: %p\n", event->old_cell);*/ - /*fprintf (stderr, " new_cell: %p\n", event->new_cell);*/ - } + { + /*dvdnav_cell_change_event_t *event = (dvdnav_cell_change_event_t *)data; */ + /*fprintf (stderr, " old_cell: %p\n", event->old_cell); */ + /*fprintf (stderr, " new_cell: %p\n", event->new_cell); */ + } break; case DVDNAV_NAV_PACKET: - { + { /* dvdnav_nav_packet_event_t *event = (dvdnav_nav_packet_event_t *)data; pci_t *pci; @@ -786,23 +831,26 @@ dvdnavsrc_print_event (DVDNavSrc *src, guint8 *data, int event, int len) navPrint_PCI(pci); navPrint_DSI(dsi); */ - } + } break; case DVDNAV_STOP: break; case DVDNAV_HIGHLIGHT: - { - dvdnav_highlight_event_t *event = (dvdnav_highlight_event_t *)data; - fprintf (stderr, " display: %s\n", - event->display == 0 ? "hide" : (event->display == 1 ? "show" : "unknown") - ); - if (event->display == 1) { - fprintf (stderr, " palette: %08x\n", event->palette); - fprintf (stderr, " coords (%u, %u) - (%u, %u)\n", event->sx, event->sy, event->ex, event->ey); - fprintf (stderr, " pts: %u\n", event->pts); - fprintf (stderr, " button: %u\n", event->buttonN); - } + { + dvdnav_highlight_event_t *event = (dvdnav_highlight_event_t *) data; + + fprintf (stderr, " display: %s\n", + event->display == 0 ? "hide" : (event->display == + 1 ? "show" : "unknown") + ); + if (event->display == 1) { + fprintf (stderr, " palette: %08x\n", event->palette); + fprintf (stderr, " coords (%u, %u) - (%u, %u)\n", event->sx, event->sy, + event->ex, event->ey); + fprintf (stderr, " pts: %u\n", event->pts); + fprintf (stderr, " button: %u\n", event->buttonN); } + } break; case DVDNAV_SPU_CLUT_CHANGE: break; @@ -817,7 +865,7 @@ dvdnavsrc_print_event (DVDNavSrc *src, guint8 *data, int event, int len) } static GstData * -dvdnavsrc_get (GstPad *pad) +dvdnavsrc_get (GstPad * pad) { DVDNavSrc *src; int event, len; @@ -843,7 +891,7 @@ dvdnavsrc_get (GstPad *pad) if (src->need_flush) { src->need_flush = FALSE; GST_DEBUG ("dvdnavsrc sending flush"); - return GST_DATA (gst_event_new_flush()); + return GST_DATA (gst_event_new_flush ()); } /* loop processing blocks until data is pushed */ @@ -851,66 +899,69 @@ dvdnavsrc_get (GstPad *pad) while (!have_buf) { buf = gst_buffer_new_and_alloc (DVD_VIDEO_LB_LEN); if (!buf) { - GST_ELEMENT_ERROR (src, CORE, TOO_LAZY, (NULL), ("Failed to create a new GstBuffer")); + GST_ELEMENT_ERROR (src, CORE, TOO_LAZY, (NULL), + ("Failed to create a new GstBuffer")); return NULL; } - data = GST_BUFFER_DATA(buf); + data = GST_BUFFER_DATA (buf); if (dvdnav_get_next_block (src->dvdnav, data, &event, &len) != - DVDNAV_STATUS_OK) { + DVDNAV_STATUS_OK) { GST_ELEMENT_ERROR (src, STREAM, DECODE, (NULL), - ("dvdnav_get_next_block error: %s\n", dvdnav_err_to_string(src->dvdnav))); + ("dvdnav_get_next_block error: %s\n", + dvdnav_err_to_string (src->dvdnav))); return NULL; } switch (event) { case DVDNAV_NOP: - break; + break; case DVDNAV_BLOCK_OK: - g_return_val_if_fail (GST_BUFFER_DATA(buf) != NULL, NULL); - g_return_val_if_fail (GST_BUFFER_SIZE(buf) == DVD_VIDEO_LB_LEN, NULL); - have_buf = TRUE; - break; + g_return_val_if_fail (GST_BUFFER_DATA (buf) != NULL, NULL); + g_return_val_if_fail (GST_BUFFER_SIZE (buf) == DVD_VIDEO_LB_LEN, NULL); + have_buf = TRUE; + break; case DVDNAV_STILL_FRAME: - /* FIXME: we should pause for event->length seconds before - * dvdnav_still_skip */ - dvdnavsrc_print_event (src, data, event, len); - if (dvdnav_still_skip (src->dvdnav) != DVDNAV_STATUS_OK) { - GST_ELEMENT_ERROR (src, STREAM, TOO_LAZY, (NULL), ("dvdnav_still_skip error: %s\n", - dvdnav_err_to_string(src->dvdnav))); - /* FIXME: close the stream??? */ - } - break; + /* FIXME: we should pause for event->length seconds before + * dvdnav_still_skip */ + dvdnavsrc_print_event (src, data, event, len); + if (dvdnav_still_skip (src->dvdnav) != DVDNAV_STATUS_OK) { + GST_ELEMENT_ERROR (src, STREAM, TOO_LAZY, (NULL), + ("dvdnav_still_skip error: %s\n", + dvdnav_err_to_string (src->dvdnav))); + /* FIXME: close the stream??? */ + } + break; case DVDNAV_STOP: - GST_DEBUG ("dvdnavsrc sending eos"); - gst_element_set_eos (GST_ELEMENT (src)); - dvdnavsrc_close(src); - buf = GST_BUFFER (gst_event_new (GST_EVENT_EOS)); - have_buf = TRUE; - break; + GST_DEBUG ("dvdnavsrc sending eos"); + gst_element_set_eos (GST_ELEMENT (src)); + dvdnavsrc_close (src); + buf = GST_BUFFER (gst_event_new (GST_EVENT_EOS)); + have_buf = TRUE; + break; case DVDNAV_CELL_CHANGE: - dvdnavsrc_update_streaminfo (src); - break; + dvdnavsrc_update_streaminfo (src); + break; case DVDNAV_NAV_PACKET: - dvdnavsrc_update_buttoninfo (src); - break; + dvdnavsrc_update_buttoninfo (src); + break; case DVDNAV_WAIT: /* FIXME: supposed to make sure all the data has made * it to the sinks before skipping the wait */ - dvdnavsrc_print_event (src, data, event, len); - dvdnav_wait_skip(src->dvdnav); + dvdnavsrc_print_event (src, data, event, len); + dvdnav_wait_skip (src->dvdnav); break; case DVDNAV_HOP_CHANNEL: /* Indicates a time discontinuity, and the downstream should * flush */ - dvdnavsrc_print_event (src, data, event, len); - buf = GST_BUFFER (gst_event_new (GST_EVENT_DISCONTINUOUS)); - have_buf = TRUE; + dvdnavsrc_print_event (src, data, event, len); + buf = GST_BUFFER (gst_event_new (GST_EVENT_DISCONTINUOUS)); + have_buf = TRUE; break; case DVDNAV_HIGHLIGHT: - dvdnavsrc_print_event (src, data, event, len); + dvdnavsrc_print_event (src, data, event, len); break; /* SPU_STREAM_CHANGE provides MPEG stream numbers for different @@ -921,28 +972,29 @@ dvdnavsrc_get (GstPad *pad) * audio stream (from a menu) */ case DVDNAV_AUDIO_STREAM_CHANGE: - /* VTS_CHANGE Indicates a change in VTS (Video Title Set) */ + /* VTS_CHANGE Indicates a change in VTS (Video Title Set) */ case DVDNAV_VTS_CHANGE: case DVDNAV_SPU_CLUT_CHANGE: default: - dvdnavsrc_print_event (src, data, event, len); - break; + dvdnavsrc_print_event (src, data, event, len); + break; } } - return GST_DATA(buf); + return GST_DATA (buf); } /* open the file, necessary to go to RUNNING state */ -static gboolean -dvdnavsrc_open (DVDNavSrc *src) +static gboolean +dvdnavsrc_open (DVDNavSrc * src) { g_return_val_if_fail (src != NULL, FALSE); - g_return_val_if_fail (GST_IS_DVDNAVSRC(src), FALSE); + g_return_val_if_fail (GST_IS_DVDNAVSRC (src), FALSE); g_return_val_if_fail (!dvdnavsrc_is_open (src), FALSE); g_return_val_if_fail (src->location != NULL, FALSE); - if (dvdnav_open (&src->dvdnav, (char*)src->location) != DVDNAV_STATUS_OK) { - fprintf( stderr, "dvdnav_open error: %s location: %s\n", dvdnav_err_to_string(src->dvdnav), src->location); + if (dvdnav_open (&src->dvdnav, (char *) src->location) != DVDNAV_STATUS_OK) { + fprintf (stderr, "dvdnav_open error: %s location: %s\n", + dvdnav_err_to_string (src->dvdnav), src->location); return FALSE; } @@ -966,44 +1018,45 @@ dvdnavsrc_open (DVDNavSrc *src) if (src->title > 0) { unsigned char buf[2048]; - int event, buflen = sizeof(buf); - fprintf(stderr, "+XXX\n"); - if (dvdnav_get_next_block(src->dvdnav, buf, &event, &buflen) != DVDNAV_STATUS_OK) { - fprintf(stderr, "pre seek dvdnav_get_next_block error: %s\n", dvdnav_err_to_string(src->dvdnav)); + int event, buflen = sizeof (buf); + + fprintf (stderr, "+XXX\n"); + if (dvdnav_get_next_block (src->dvdnav, buf, &event, + &buflen) != DVDNAV_STATUS_OK) { + fprintf (stderr, "pre seek dvdnav_get_next_block error: %s\n", + dvdnav_err_to_string (src->dvdnav)); return FALSE; } dvdnavsrc_print_event (src, buf, event, buflen); /* - while (dvdnav_get_next_block(src->dvdnav, buf, &event, &buflen) == DVDNAV_STATUS_OK) { - if (event != DVDNAV_BLOCK_OK) - dvdnavsrc_print_event (src, buf, event, buflen); - } - */ - fprintf(stderr, "pre seek dvdnav_get_next_block error: %s\n", dvdnav_err_to_string(src->dvdnav)); - fprintf(stderr, "-XXX\n"); + while (dvdnav_get_next_block(src->dvdnav, buf, &event, &buflen) == DVDNAV_STATUS_OK) { + if (event != DVDNAV_BLOCK_OK) + dvdnavsrc_print_event (src, buf, event, buflen); + } + */ + fprintf (stderr, "pre seek dvdnav_get_next_block error: %s\n", + dvdnav_err_to_string (src->dvdnav)); + fprintf (stderr, "-XXX\n"); - if (!dvdnavsrc_tca_seek(src, - src->title, - src->chapter, - src->angle)) + if (!dvdnavsrc_tca_seek (src, src->title, src->chapter, src->angle)) return FALSE; } - + return TRUE; } /* close the file */ static gboolean -dvdnavsrc_close (DVDNavSrc *src) +dvdnavsrc_close (DVDNavSrc * src) { g_return_val_if_fail (src != NULL, FALSE); - g_return_val_if_fail (GST_IS_DVDNAVSRC(src), FALSE); + g_return_val_if_fail (GST_IS_DVDNAVSRC (src), FALSE); g_return_val_if_fail (dvdnavsrc_is_open (src), FALSE); g_return_val_if_fail (src->dvdnav != NULL, FALSE); if (dvdnav_close (src->dvdnav) != DVDNAV_STATUS_OK) { - fprintf( stderr, "dvdnav_close error: %s\n", - dvdnav_err_to_string (src->dvdnav)); + fprintf (stderr, "dvdnav_close error: %s\n", + dvdnav_err_to_string (src->dvdnav)); return FALSE; } @@ -1013,7 +1066,7 @@ dvdnavsrc_close (DVDNavSrc *src) } static GstElementStateReturn -dvdnavsrc_change_state (GstElement *element) +dvdnavsrc_change_state (GstElement * element) { DVDNavSrc *src; @@ -1026,9 +1079,9 @@ dvdnavsrc_change_state (GstElement *element) break; case GST_STATE_READY_TO_PAUSED: if (!dvdnavsrc_is_open (src)) { - if (!dvdnavsrc_open (src)) { - return GST_STATE_FAILURE; - } + if (!dvdnavsrc_open (src)) { + return GST_STATE_FAILURE; + } } src->streaminfo = NULL; break; @@ -1038,9 +1091,9 @@ dvdnavsrc_change_state (GstElement *element) break; case GST_STATE_PAUSED_TO_READY: if (dvdnavsrc_is_open (src)) { - if (!dvdnavsrc_close (src)) { - return GST_STATE_FAILURE; - } + if (!dvdnavsrc_close (src)) { + return GST_STATE_FAILURE; + } } break; case GST_STATE_READY_TO_NULL: @@ -1055,20 +1108,18 @@ dvdnavsrc_change_state (GstElement *element) } static const GstEventMask * -dvdnavsrc_get_event_mask (GstPad *pad) +dvdnavsrc_get_event_mask (GstPad * pad) { static const GstEventMask masks[] = { - {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | - GST_SEEK_METHOD_CUR | - GST_SEEK_METHOD_END | - GST_SEEK_FLAG_FLUSH }, - /* - {GST_EVENT_SEEK_SEGMENT, GST_SEEK_METHOD_SET | - GST_SEEK_METHOD_CUR | - GST_SEEK_METHOD_END | - GST_SEEK_FLAG_FLUSH }, - */ - {GST_EVENT_NAVIGATION, GST_EVENT_FLAG_NONE }, + {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | + GST_SEEK_METHOD_CUR | GST_SEEK_METHOD_END | GST_SEEK_FLAG_FLUSH}, + /* + {GST_EVENT_SEEK_SEGMENT, GST_SEEK_METHOD_SET | + GST_SEEK_METHOD_CUR | + GST_SEEK_METHOD_END | + GST_SEEK_FLAG_FLUSH }, + */ + {GST_EVENT_NAVIGATION, GST_EVENT_FLAG_NONE}, {0,} }; @@ -1076,44 +1127,39 @@ dvdnavsrc_get_event_mask (GstPad *pad) } static gboolean -dvdnav_handle_navigation_event (DVDNavSrc *src, GstEvent *event) +dvdnav_handle_navigation_event (DVDNavSrc * src, GstEvent * event) { GstStructure *structure = event->event_data.structure.structure; const char *event_type = gst_structure_get_string (structure, "event"); g_return_val_if_fail (event != NULL, FALSE); - - if (strcmp (event_type, "key-press") == 0) - { - const char *key = gst_structure_get_string(structure, "key"); + + if (strcmp (event_type, "key-press") == 0) { + const char *key = gst_structure_get_string (structure, "key"); g_assert (key != NULL); g_print ("dvdnavsrc got a keypress: %s\n", key); - } - else if (strcmp (event_type, "mouse-move") == 0) - { + } else if (strcmp (event_type, "mouse-move") == 0) { double x, y; - gst_structure_get_double(structure, "pointer_x", &x); - gst_structure_get_double(structure, "pointer_y", &y); + gst_structure_get_double (structure, "pointer_x", &x); + gst_structure_get_double (structure, "pointer_y", &y); - dvdnavsrc_pointer_select (src, (int) x, (int) y); - } - else if (strcmp (event_type, "mouse-button-release") == 0) - { + dvdnavsrc_pointer_select (src, (int) x, (int) y); + } else if (strcmp (event_type, "mouse-button-release") == 0) { double x, y; - gst_structure_get_double(structure, "pointer_x", &x); - gst_structure_get_double(structure, "pointer_y", &y); + gst_structure_get_double (structure, "pointer_x", &x); + gst_structure_get_double (structure, "pointer_y", &y); - dvdnavsrc_pointer_activate (src, (int) x, (int) y); + dvdnavsrc_pointer_activate (src, (int) x, (int) y); } return TRUE; } static gboolean -dvdnavsrc_event (GstPad *pad, GstEvent *event) +dvdnavsrc_event (GstPad * pad, GstEvent * event) { DVDNavSrc *src; gboolean res = TRUE; @@ -1132,111 +1178,110 @@ dvdnavsrc_event (GstPad *pad, GstEvent *event) int parts, part, new_part; int angles, angle, new_angle; int origin; - - format = GST_EVENT_SEEK_FORMAT (event); - offset = GST_EVENT_SEEK_OFFSET (event); + + format = GST_EVENT_SEEK_FORMAT (event); + offset = GST_EVENT_SEEK_OFFSET (event); switch (format) { - default: - if (format == sector_format) { - switch (GST_EVENT_SEEK_METHOD (event)) { - case GST_SEEK_METHOD_SET: - origin = SEEK_SET; - break; - case GST_SEEK_METHOD_CUR: - origin = SEEK_CUR; - break; - case GST_SEEK_METHOD_END: - origin = SEEK_END; - break; - default: - goto error; - } - if (dvdnav_sector_search(src->dvdnav, offset, origin) != - DVDNAV_STATUS_OK) { - goto error; - } - } else if (format == title_format) { - if (dvdnav_current_title_info(src->dvdnav, &title, &part) != - DVDNAV_STATUS_OK) { - goto error; - } - switch (GST_EVENT_SEEK_METHOD (event)) { - case GST_SEEK_METHOD_SET: - new_title = offset; - break; - case GST_SEEK_METHOD_CUR: - new_title = title + offset; - break; - case GST_SEEK_METHOD_END: - if (dvdnav_get_number_of_titles(src->dvdnav, &titles) != - DVDNAV_STATUS_OK) { - goto error; - } - new_title = titles + offset; - break; - default: - goto error; - } - if (dvdnav_title_play(src->dvdnav, new_title) != - DVDNAV_STATUS_OK) { - goto error; - } - } else if (format == chapter_format) { - if (dvdnav_current_title_info(src->dvdnav, &title, &part) != - DVDNAV_STATUS_OK) { - goto error; - } - switch (GST_EVENT_SEEK_METHOD (event)) { - case GST_SEEK_METHOD_SET: - new_part = offset; - break; - case GST_SEEK_METHOD_CUR: - new_part = part + offset; - break; - case GST_SEEK_METHOD_END: - if (dvdnav_get_number_of_titles(src->dvdnav, &parts) != - DVDNAV_STATUS_OK) { - goto error; - } - new_part = parts + offset; - break; - default: - goto error; - } - /*if (dvdnav_part_search(src->dvdnav, new_part) !=*/ - if (dvdnav_part_play(src->dvdnav, title, new_part) != - DVDNAV_STATUS_OK) { - goto error; - } - } else if (format == angle_format) { - if (dvdnav_get_angle_info(src->dvdnav, &angle, &angles) != - DVDNAV_STATUS_OK) { - goto error; - } - switch (GST_EVENT_SEEK_METHOD (event)) { - case GST_SEEK_METHOD_SET: - new_angle = offset; - break; - case GST_SEEK_METHOD_CUR: - new_angle = angle + offset; - break; - case GST_SEEK_METHOD_END: - new_angle = angles + offset; - break; - default: - goto error; - } - if (dvdnav_angle_change(src->dvdnav, new_angle) != - DVDNAV_STATUS_OK) { - goto error; - } - } else { - goto error; - } + default: + if (format == sector_format) { + switch (GST_EVENT_SEEK_METHOD (event)) { + case GST_SEEK_METHOD_SET: + origin = SEEK_SET; + break; + case GST_SEEK_METHOD_CUR: + origin = SEEK_CUR; + break; + case GST_SEEK_METHOD_END: + origin = SEEK_END; + break; + default: + goto error; + } + if (dvdnav_sector_search (src->dvdnav, offset, origin) != + DVDNAV_STATUS_OK) { + goto error; + } + } else if (format == title_format) { + if (dvdnav_current_title_info (src->dvdnav, &title, &part) != + DVDNAV_STATUS_OK) { + goto error; + } + switch (GST_EVENT_SEEK_METHOD (event)) { + case GST_SEEK_METHOD_SET: + new_title = offset; + break; + case GST_SEEK_METHOD_CUR: + new_title = title + offset; + break; + case GST_SEEK_METHOD_END: + if (dvdnav_get_number_of_titles (src->dvdnav, &titles) != + DVDNAV_STATUS_OK) { + goto error; + } + new_title = titles + offset; + break; + default: + goto error; + } + if (dvdnav_title_play (src->dvdnav, new_title) != DVDNAV_STATUS_OK) { + goto error; + } + } else if (format == chapter_format) { + if (dvdnav_current_title_info (src->dvdnav, &title, &part) != + DVDNAV_STATUS_OK) { + goto error; + } + switch (GST_EVENT_SEEK_METHOD (event)) { + case GST_SEEK_METHOD_SET: + new_part = offset; + break; + case GST_SEEK_METHOD_CUR: + new_part = part + offset; + break; + case GST_SEEK_METHOD_END: + if (dvdnav_get_number_of_titles (src->dvdnav, &parts) != + DVDNAV_STATUS_OK) { + goto error; + } + new_part = parts + offset; + break; + default: + goto error; + } + /*if (dvdnav_part_search(src->dvdnav, new_part) != */ + if (dvdnav_part_play (src->dvdnav, title, new_part) != + DVDNAV_STATUS_OK) { + goto error; + } + } else if (format == angle_format) { + if (dvdnav_get_angle_info (src->dvdnav, &angle, &angles) != + DVDNAV_STATUS_OK) { + goto error; + } + switch (GST_EVENT_SEEK_METHOD (event)) { + case GST_SEEK_METHOD_SET: + new_angle = offset; + break; + case GST_SEEK_METHOD_CUR: + new_angle = angle + offset; + break; + case GST_SEEK_METHOD_END: + new_angle = angles + offset; + break; + default: + goto error; + } + if (dvdnav_angle_change (src->dvdnav, new_angle) != + DVDNAV_STATUS_OK) { + goto error; + } + } else { + goto error; + } } src->did_seek = TRUE; - src->need_flush = GST_EVENT_SEEK_FLAGS(event) & GST_SEEK_FLAG_FLUSH; + src->need_flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH; break; } case GST_EVENT_NAVIGATION: @@ -1249,7 +1294,7 @@ dvdnavsrc_event (GstPad *pad, GstEvent *event) } if (FALSE) { -error: + error: res = FALSE; } gst_event_unref (event); @@ -1258,25 +1303,25 @@ error: } static const GstFormat * -dvdnavsrc_get_formats (GstPad *pad) +dvdnavsrc_get_formats (GstPad * pad) { int i; static GstFormat formats[] = { /* - GST_FORMAT_TIME, - GST_FORMAT_BYTES, - GST_FORMAT_DEFAULT, - */ - 0, /* filled later */ - 0, /* filled later */ - 0, /* filled later */ - 0, /* filled later */ + GST_FORMAT_TIME, + GST_FORMAT_BYTES, + GST_FORMAT_DEFAULT, + */ + 0, /* filled later */ + 0, /* filled later */ + 0, /* filled later */ + 0, /* filled later */ 0 }; static gboolean format_initialized = FALSE; if (!format_initialized) { - for (i=0; formats[i] != 0; i++) { + for (i = 0; formats[i] != 0; i++) { } formats[i++] = sector_format; formats[i++] = title_format; @@ -1290,9 +1335,9 @@ dvdnavsrc_get_formats (GstPad *pad) #if 0 static gboolean -dvdnavsrc_convert (GstPad *pad, - GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value) +dvdnavsrc_convert (GstPad * pad, + GstFormat src_format, gint64 src_value, + GstFormat * dest_format, gint64 * dest_value) { DVDNavSrc *src; @@ -1304,23 +1349,22 @@ dvdnavsrc_convert (GstPad *pad, switch (src_format) { case GST_FORMAT_TIME: switch (*dest_format) { - case GST_FORMAT_BYTES: - src_value <<= 2; /* 4 bytes per sample */ - case GST_FORMAT_DEFAULT: + case GST_FORMAT_BYTES: + src_value <<= 2; /* 4 bytes per sample */ + case GST_FORMAT_DEFAULT: *dest_value = src_value * 44100 / GST_SECOND; break; default: - if (*dest_format == track_format || *dest_format == sector_format) { - gint sector = (src_value * 44100) / ((CD_FRAMESIZE_RAW >> 2) * GST_SECOND); + if (*dest_format == track_format || *dest_format == sector_format) { + gint sector = + (src_value * 44100) / ((CD_FRAMESIZE_RAW >> 2) * GST_SECOND); if (*dest_format == sector_format) { *dest_value = sector; - } - else { + } else { *dest_value = cdda_sector_gettrack (src->d, sector) - 1; } - } - else + } else return FALSE; break; } @@ -1329,24 +1373,22 @@ dvdnavsrc_convert (GstPad *pad, src_value >>= 2; case GST_FORMAT_DEFAULT: switch (*dest_format) { - case GST_FORMAT_BYTES: - *dest_value = src_value * 4; + case GST_FORMAT_BYTES: + *dest_value = src_value * 4; break; - case GST_FORMAT_TIME: - *dest_value = src_value * GST_SECOND / 44100; + case GST_FORMAT_TIME: + *dest_value = src_value * GST_SECOND / 44100; break; default: - if (*dest_format == track_format || *dest_format == sector_format) { - gint sector = src_value / (CD_FRAMESIZE_RAW >> 2); + if (*dest_format == track_format || *dest_format == sector_format) { + gint sector = src_value / (CD_FRAMESIZE_RAW >> 2); - if (*dest_format == track_format) { + if (*dest_format == track_format) { *dest_value = cdda_sector_gettrack (src->d, sector) - 1; - } - else { + } else { *dest_value = sector; } - } - else + } else return FALSE; break; } @@ -1358,38 +1400,34 @@ dvdnavsrc_convert (GstPad *pad, if (src_format == track_format) { /* some sanity checks */ if (src_value < 0 || src_value > src->d->tracks) - return FALSE; + return FALSE; sector = cdda_track_firstsector (src->d, src_value + 1); - } - else if (src_format == sector_format) { + } else if (src_format == sector_format) { sector = src_value; - } - else - return FALSE; + } else + return FALSE; switch (*dest_format) { - case GST_FORMAT_TIME: - *dest_value = ((CD_FRAMESIZE_RAW >> 2) * sector * GST_SECOND) / 44100; + case GST_FORMAT_TIME: + *dest_value = ((CD_FRAMESIZE_RAW >> 2) * sector * GST_SECOND) / 44100; break; - case GST_FORMAT_BYTES: - sector <<= 2; - case GST_FORMAT_DEFAULT: - *dest_value = (CD_FRAMESIZE_RAW >> 2) * sector; + case GST_FORMAT_BYTES: + sector <<= 2; + case GST_FORMAT_DEFAULT: + *dest_value = (CD_FRAMESIZE_RAW >> 2) * sector; break; default: - if (*dest_format == sector_format) { + if (*dest_format == sector_format) { *dest_value = sector; - } - else if (*dest_format == track_format) { + } else if (*dest_format == track_format) { /* if we go past the last sector, make sure to report the last track */ if (sector > src->last_sector) *dest_value = cdda_sector_gettrack (src->d, src->last_sector); - else + else *dest_value = cdda_sector_gettrack (src->d, sector) - 1; - } - else - return FALSE; + } else + return FALSE; break; } break; @@ -1400,8 +1438,8 @@ dvdnavsrc_convert (GstPad *pad, } #endif -static const GstQueryType* -dvdnavsrc_get_query_types (GstPad *pad) +static const GstQueryType * +dvdnavsrc_get_query_types (GstPad * pad) { static const GstQueryType src_query_types[] = { GST_QUERY_TOTAL, @@ -1412,8 +1450,8 @@ dvdnavsrc_get_query_types (GstPad *pad) } static gboolean -dvdnavsrc_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value) +dvdnavsrc_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value) { gboolean res = TRUE; DVDNavSrc *src; @@ -1430,52 +1468,58 @@ dvdnavsrc_query (GstPad *pad, GstQueryType type, switch (type) { case GST_QUERY_TOTAL: if (*format == sector_format) { - if (dvdnav_get_position(src->dvdnav, &pos, &len) != DVDNAV_STATUS_OK) { - res = FALSE; - } - *value = len; + if (dvdnav_get_position (src->dvdnav, &pos, &len) != DVDNAV_STATUS_OK) { + res = FALSE; + } + *value = len; } else if (*format == title_format) { - if (dvdnav_get_number_of_titles(src->dvdnav, &titles) != DVDNAV_STATUS_OK) { - res = FALSE; - } - *value = titles; + if (dvdnav_get_number_of_titles (src->dvdnav, + &titles) != DVDNAV_STATUS_OK) { + res = FALSE; + } + *value = titles; } else if (*format == chapter_format) { - if (dvdnav_get_number_of_titles(src->dvdnav, &parts) != DVDNAV_STATUS_OK) { - res = FALSE; - } - *value = parts; + if (dvdnav_get_number_of_titles (src->dvdnav, + &parts) != DVDNAV_STATUS_OK) { + res = FALSE; + } + *value = parts; } else if (*format == angle_format) { - if (dvdnav_get_angle_info(src->dvdnav, &angle, &angles) != DVDNAV_STATUS_OK) { - res = FALSE; - } - *value = angles; + if (dvdnav_get_angle_info (src->dvdnav, &angle, + &angles) != DVDNAV_STATUS_OK) { + res = FALSE; + } + *value = angles; } else { - res = FALSE; + res = FALSE; } break; case GST_QUERY_POSITION: if (*format == sector_format) { - if (dvdnav_get_position(src->dvdnav, &pos, &len) != DVDNAV_STATUS_OK) { - res = FALSE; - } - *value = pos; + if (dvdnav_get_position (src->dvdnav, &pos, &len) != DVDNAV_STATUS_OK) { + res = FALSE; + } + *value = pos; } else if (*format == title_format) { - if (dvdnav_current_title_info(src->dvdnav, &title, &part) != DVDNAV_STATUS_OK) { - res = FALSE; - } - *value = title; + if (dvdnav_current_title_info (src->dvdnav, &title, + &part) != DVDNAV_STATUS_OK) { + res = FALSE; + } + *value = title; } else if (*format == chapter_format) { - if (dvdnav_current_title_info(src->dvdnav, &title, &part) != DVDNAV_STATUS_OK) { - res = FALSE; - } - *value = part; + if (dvdnav_current_title_info (src->dvdnav, &title, + &part) != DVDNAV_STATUS_OK) { + res = FALSE; + } + *value = part; } else if (*format == angle_format) { - if (dvdnav_get_angle_info(src->dvdnav, &angle, &angles) != DVDNAV_STATUS_OK) { - res = FALSE; - } - *value = angle; + if (dvdnav_get_angle_info (src->dvdnav, &angle, + &angles) != DVDNAV_STATUS_OK) { + res = FALSE; + } + *value = angle; } else { - res = FALSE; + res = FALSE; } break; default: @@ -1486,21 +1530,17 @@ dvdnavsrc_query (GstPad *pad, GstQueryType type, } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "dvdnavsrc", GST_RANK_NONE, GST_TYPE_DVDNAVSRC)) + if (!gst_element_register (plugin, "dvdnavsrc", GST_RANK_NONE, + GST_TYPE_DVDNAVSRC)) return FALSE; - + return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "dvdnavsrc", - "Access a DVD with navigation features using libdvdnav", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "dvdnavsrc", + "Access a DVD with navigation features using libdvdnav", + plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/dvdread/demo-play.c b/ext/dvdread/demo-play.c index 4fcc5bb86e..2822255970 100644 --- a/ext/dvdread/demo-play.c +++ b/ext/dvdread/demo-play.c @@ -4,144 +4,155 @@ GstPipeline *pipeline; GstElement *v_queue, *a_queue, *v_thread, *a_thread; GtkWidget *appwindow; -GtkWidget *gtk_socket; +GtkWidget *gtk_socket; -void eof(GstElement *src) { - g_print("have eos, quitting\n"); - exit(0); +void +eof (GstElement * src) +{ + g_print ("have eos, quitting\n"); + exit (0); } -gboolean idle_func(gpointer data) { - gst_bin_iterate(GST_BIN(data)); +gboolean +idle_func (gpointer data) +{ + gst_bin_iterate (GST_BIN (data)); return TRUE; } -void mpeg2parse_newpad(GstElement *parser,GstPad *pad, GstElement *pipeline) { +void +mpeg2parse_newpad (GstElement * parser, GstPad * pad, GstElement * pipeline) +{ - g_print("***** a new pad %s was created\n", gst_pad_get_name(pad)); + g_print ("***** a new pad %s was created\n", gst_pad_get_name (pad)); - if (strncmp(gst_pad_get_name(pad), "video_", 6) == 0) { - gst_pad_link(pad, gst_element_get_pad(v_queue,"sink")); - gst_bin_add(GST_BIN(pipeline),v_thread); - gst_element_set_state(v_thread,GST_STATE_PLAYING); - } else if (strcmp(gst_pad_get_name(pad), "private_stream_1.0") == 0) { - gst_pad_link(pad, gst_element_get_pad(a_queue,"sink")); - gst_bin_add(GST_BIN(pipeline),a_thread); - gst_element_set_state(a_thread,GST_STATE_PLAYING); + if (strncmp (gst_pad_get_name (pad), "video_", 6) == 0) { + gst_pad_link (pad, gst_element_get_pad (v_queue, "sink")); + gst_bin_add (GST_BIN (pipeline), v_thread); + gst_element_set_state (v_thread, GST_STATE_PLAYING); + } else if (strcmp (gst_pad_get_name (pad), "private_stream_1.0") == 0) { + gst_pad_link (pad, gst_element_get_pad (a_queue, "sink")); + gst_bin_add (GST_BIN (pipeline), a_thread); + gst_element_set_state (a_thread, GST_STATE_PLAYING); } } -void mpeg2parse_have_size(GstElement *videosink,gint width,gint height) { - gtk_widget_set_usize(gtk_socket,width,height); - gtk_widget_show_all(appwindow); +void +mpeg2parse_have_size (GstElement * videosink, gint width, gint height) +{ + gtk_widget_set_usize (gtk_socket, width, height); + gtk_widget_show_all (appwindow); } -int main(int argc,char *argv[]) { +int +main (int argc, char *argv[]) +{ GstElement *src, *parse; GstElement *v_decode, *show, *color; GstElement *a_decode, *osssink; if (argc < 5) { - g_print("usage: %s dvdlocation title chapter angle\n", argv[0]); - exit(1); + g_print ("usage: %s dvdlocation title chapter angle\n", argv[0]); + exit (1); } - gst_init(&argc,&argv); - gnome_init("MPEG2 Video player","0.0.1",argc,argv); + gst_init (&argc, &argv); + gnome_init ("MPEG2 Video player", "0.0.1", argc, argv); /* ***** construct the main pipeline ***** */ - pipeline = GST_PIPELINE(gst_pipeline_new("pipeline")); - g_return_val_if_fail(pipeline != NULL, -1); + pipeline = GST_PIPELINE (gst_pipeline_new ("pipeline")); + g_return_val_if_fail (pipeline != NULL, -1); - src = gst_element_factory_make("dvdreadsrc","src"); - g_return_val_if_fail(src != NULL, -1); - gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL); - gtk_object_set(GTK_OBJECT(src),"title",atoi(argv[2]),NULL); - gtk_object_set(GTK_OBJECT(src),"chapter",atoi(argv[3]),NULL); - gtk_object_set(GTK_OBJECT(src),"angle",atoi(argv[4]),NULL); + src = gst_element_factory_make ("dvdreadsrc", "src"); + g_return_val_if_fail (src != NULL, -1); + gtk_object_set (GTK_OBJECT (src), "location", argv[1], NULL); + gtk_object_set (GTK_OBJECT (src), "title", atoi (argv[2]), NULL); + gtk_object_set (GTK_OBJECT (src), "chapter", atoi (argv[3]), NULL); + gtk_object_set (GTK_OBJECT (src), "angle", atoi (argv[4]), NULL); - parse = gst_element_factory_make("mpeg2parse","parse"); + parse = gst_element_factory_make ("mpeg2parse", "parse"); /*parse = gst_element_factory_make("mpeg1parse","parse"); */ - g_return_val_if_fail(parse != NULL, -1); + g_return_val_if_fail (parse != NULL, -1); - gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(src)); - gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(parse)); + gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (src)); + gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (parse)); - gst_element_link(src,"src",parse,"sink"); + gst_element_link (src, "src", parse, "sink"); /* ***** pre-construct the video thread ***** */ - v_thread = GST_ELEMENT(gst_thread_new("v_thread")); - g_return_val_if_fail(v_thread != NULL, -1); + v_thread = GST_ELEMENT (gst_thread_new ("v_thread")); + g_return_val_if_fail (v_thread != NULL, -1); - v_queue = gst_element_factory_make("queue","v_queue"); - g_return_val_if_fail(v_queue != NULL, -1); + v_queue = gst_element_factory_make ("queue", "v_queue"); + g_return_val_if_fail (v_queue != NULL, -1); - v_decode = gst_element_factory_make("mpeg2dec","decode_video"); - g_return_val_if_fail(v_decode != NULL, -1); + v_decode = gst_element_factory_make ("mpeg2dec", "decode_video"); + g_return_val_if_fail (v_decode != NULL, -1); - color = gst_element_factory_make("colorspace","color"); - g_return_val_if_fail(color != NULL, -1); + color = gst_element_factory_make ("colorspace", "color"); + g_return_val_if_fail (color != NULL, -1); - show = gst_element_factory_make("xvideosink","show"); - g_return_val_if_fail(show != NULL, -1); + show = gst_element_factory_make ("xvideosink", "show"); + g_return_val_if_fail (show != NULL, -1); - gst_bin_add(GST_BIN(v_thread),GST_ELEMENT(v_queue)); - gst_bin_add(GST_BIN(v_thread),GST_ELEMENT(v_decode)); - gst_bin_add(GST_BIN(v_thread),GST_ELEMENT(color)); - gst_bin_add(GST_BIN(v_thread),GST_ELEMENT(show)); + gst_bin_add (GST_BIN (v_thread), GST_ELEMENT (v_queue)); + gst_bin_add (GST_BIN (v_thread), GST_ELEMENT (v_decode)); + gst_bin_add (GST_BIN (v_thread), GST_ELEMENT (color)); + gst_bin_add (GST_BIN (v_thread), GST_ELEMENT (show)); - gst_element_link(v_queue,"src",v_decode,"sink"); - gst_element_link(v_decode,"src",color,"sink"); - gst_element_link(color,"src",show,"sink"); + gst_element_link (v_queue, "src", v_decode, "sink"); + gst_element_link (v_decode, "src", color, "sink"); + gst_element_link (color, "src", show, "sink"); /* ***** pre-construct the audio thread ***** */ - a_thread = GST_ELEMENT(gst_thread_new("a_thread")); - g_return_val_if_fail(a_thread != NULL, -1); + a_thread = GST_ELEMENT (gst_thread_new ("a_thread")); + g_return_val_if_fail (a_thread != NULL, -1); - a_queue = gst_element_factory_make("queue","a_queue"); - g_return_val_if_fail(a_queue != NULL, -1); - - a_decode = gst_element_factory_make("a52dec","decode_audio"); - g_return_val_if_fail(a_decode != NULL, -1); + a_queue = gst_element_factory_make ("queue", "a_queue"); + g_return_val_if_fail (a_queue != NULL, -1); - osssink = gst_element_factory_make("osssink","osssink"); - g_return_val_if_fail(osssink != NULL, -1); + a_decode = gst_element_factory_make ("a52dec", "decode_audio"); + g_return_val_if_fail (a_decode != NULL, -1); - gst_bin_add(GST_BIN(a_thread),GST_ELEMENT(a_queue)); - gst_bin_add(GST_BIN(a_thread),GST_ELEMENT(a_decode)); - gst_bin_add(GST_BIN(a_thread),GST_ELEMENT(osssink)); + osssink = gst_element_factory_make ("osssink", "osssink"); + g_return_val_if_fail (osssink != NULL, -1); - gst_element_link(a_queue,"src",a_decode,"sink"); - gst_element_link(a_decode,"src",osssink,"sink"); + gst_bin_add (GST_BIN (a_thread), GST_ELEMENT (a_queue)); + gst_bin_add (GST_BIN (a_thread), GST_ELEMENT (a_decode)); + gst_bin_add (GST_BIN (a_thread), GST_ELEMENT (osssink)); + + gst_element_link (a_queue, "src", a_decode, "sink"); + gst_element_link (a_decode, "src", osssink, "sink"); /* ***** construct the GUI ***** */ - appwindow = gnome_app_new("DVD Player","DVD Player"); + appwindow = gnome_app_new ("DVD Player", "DVD Player"); gtk_socket = gtk_socket_new (); gtk_widget_show (gtk_socket); - gnome_app_set_contents(GNOME_APP(appwindow), - GTK_WIDGET(gtk_socket)); + gnome_app_set_contents (GNOME_APP (appwindow), GTK_WIDGET (gtk_socket)); gtk_widget_realize (gtk_socket); - gtk_socket_steal (GTK_SOCKET (gtk_socket), - gst_util_get_int_arg (GTK_OBJECT(show), "xid")); + gtk_socket_steal (GTK_SOCKET (gtk_socket), + gst_util_get_int_arg (GTK_OBJECT (show), "xid")); - gtk_signal_connect(GTK_OBJECT(parse),"new_pad",mpeg2parse_newpad, pipeline); - gtk_signal_connect(GTK_OBJECT(src),"eos",GTK_SIGNAL_FUNC(eof),NULL); - gtk_signal_connect(GTK_OBJECT(show),"have_size",mpeg2parse_have_size, pipeline); + gtk_signal_connect (GTK_OBJECT (parse), "new_pad", mpeg2parse_newpad, + pipeline); + gtk_signal_connect (GTK_OBJECT (src), "eos", GTK_SIGNAL_FUNC (eof), NULL); + gtk_signal_connect (GTK_OBJECT (show), "have_size", mpeg2parse_have_size, + pipeline); - g_print("setting to PLAYING state\n"); - gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING); + g_print ("setting to PLAYING state\n"); + gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); - gtk_idle_add(idle_func,pipeline); + gtk_idle_add (idle_func, pipeline); - gdk_threads_enter(); - gtk_main(); - gdk_threads_leave(); + gdk_threads_enter (); + gtk_main (); + gdk_threads_leave (); return 0; } diff --git a/ext/dvdread/dvdreadsrc.c b/ext/dvdread/dvdreadsrc.c index ba3ad9046f..55fc699886 100644 --- a/ext/dvdread/dvdreadsrc.c +++ b/ext/dvdread/dvdreadsrc.c @@ -62,7 +62,8 @@ #include #include -struct _DVDReadSrcPrivate { +struct _DVDReadSrcPrivate +{ GstElement element; /* pads */ GstPad *srcpad; @@ -94,12 +95,14 @@ GstElementDetails dvdreadsrc_details = { /* DVDReadSrc signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_LOCATION, ARG_TITLE, @@ -107,41 +110,47 @@ enum { ARG_ANGLE }; -static void dvdreadsrc_base_init (gpointer g_class); -static void dvdreadsrc_class_init (DVDReadSrcClass *klass); -static void dvdreadsrc_init (DVDReadSrc *dvdreadsrc); +static void dvdreadsrc_base_init (gpointer g_class); +static void dvdreadsrc_class_init (DVDReadSrcClass * klass); +static void dvdreadsrc_init (DVDReadSrc * dvdreadsrc); -static void dvdreadsrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void dvdreadsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void dvdreadsrc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void dvdreadsrc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); /*static GstData * dvdreadsrc_get (GstPad *pad); */ -static void dvdreadsrc_loop (GstElement *element); +static void dvdreadsrc_loop (GstElement * element); + /*static GstBuffer * dvdreadsrc_get_region (GstPad *pad,gulong offset,gulong size); */ -static GstElementStateReturn dvdreadsrc_change_state (GstElement *element); +static GstElementStateReturn dvdreadsrc_change_state (GstElement * element); static GstElementClass *parent_class = NULL; + /*static guint dvdreadsrc_signals[LAST_SIGNAL] = { 0 }; */ GType -dvdreadsrc_get_type (void) +dvdreadsrc_get_type (void) { static GType dvdreadsrc_type = 0; if (!dvdreadsrc_type) { static const GTypeInfo dvdreadsrc_info = { - sizeof(DVDReadSrcClass), + sizeof (DVDReadSrcClass), dvdreadsrc_base_init, NULL, - (GClassInitFunc)dvdreadsrc_class_init, + (GClassInitFunc) dvdreadsrc_class_init, NULL, NULL, - sizeof(DVDReadSrc), + sizeof (DVDReadSrc), 0, - (GInstanceInitFunc)dvdreadsrc_init, + (GInstanceInitFunc) dvdreadsrc_init, }; - dvdreadsrc_type = g_type_register_static (GST_TYPE_ELEMENT, "DVDReadSrc", &dvdreadsrc_info, 0); + dvdreadsrc_type = + g_type_register_static (GST_TYPE_ELEMENT, "DVDReadSrc", + &dvdreadsrc_info, 0); } return dvdreadsrc_type; } @@ -155,44 +164,45 @@ dvdreadsrc_base_init (gpointer g_class) } static void -dvdreadsrc_class_init (DVDReadSrcClass *klass) +dvdreadsrc_class_init (DVDReadSrcClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LOCATION, - g_param_spec_string("location","location","location", - NULL, G_PARAM_READWRITE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_TITLE, - g_param_spec_int("title","title","title", - 0,G_MAXINT,0,G_PARAM_READWRITE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CHAPTER, - g_param_spec_int("chapter","chapter","chapter", - 0,G_MAXINT,0,G_PARAM_READWRITE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_ANGLE, - g_param_spec_int("angle","angle","angle", - 0,G_MAXINT,0,G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOCATION, + g_param_spec_string ("location", "location", "location", + NULL, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TITLE, + g_param_spec_int ("title", "title", "title", + 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CHAPTER, + g_param_spec_int ("chapter", "chapter", "chapter", + 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ANGLE, + g_param_spec_int ("angle", "angle", "angle", + 0, G_MAXINT, 0, G_PARAM_READWRITE)); - gobject_class->set_property = GST_DEBUG_FUNCPTR(dvdreadsrc_set_property); - gobject_class->get_property = GST_DEBUG_FUNCPTR(dvdreadsrc_get_property); + gobject_class->set_property = GST_DEBUG_FUNCPTR (dvdreadsrc_set_property); + gobject_class->get_property = GST_DEBUG_FUNCPTR (dvdreadsrc_get_property); gstelement_class->change_state = dvdreadsrc_change_state; } -static void -dvdreadsrc_init (DVDReadSrc *dvdreadsrc) +static void +dvdreadsrc_init (DVDReadSrc * dvdreadsrc) { - dvdreadsrc->priv = g_new(DVDReadSrcPrivate, 1); + dvdreadsrc->priv = g_new (DVDReadSrcPrivate, 1); dvdreadsrc->priv->srcpad = gst_pad_new ("src", GST_PAD_SRC); gst_element_add_pad (GST_ELEMENT (dvdreadsrc), dvdreadsrc->priv->srcpad); - gst_element_set_loop_function (GST_ELEMENT(dvdreadsrc), GST_DEBUG_FUNCPTR(dvdreadsrc_loop)); + gst_element_set_loop_function (GST_ELEMENT (dvdreadsrc), + GST_DEBUG_FUNCPTR (dvdreadsrc_loop)); - dvdreadsrc->priv->location = g_strdup("/dev/dvd"); + dvdreadsrc->priv->location = g_strdup ("/dev/dvd"); dvdreadsrc->priv->new_seek = FALSE; dvdreadsrc->priv->title = 1; dvdreadsrc->priv->chapter = 1; @@ -202,23 +212,24 @@ dvdreadsrc_init (DVDReadSrc *dvdreadsrc) /* FIXME: this code is not being used */ #ifdef PLEASEFIXTHISCODE static void -dvdreadsrc_destroy (DVDReadSrc *dvdreadsrc) +dvdreadsrc_destroy (DVDReadSrc * dvdreadsrc) { /* FIXME */ - g_print("FIXME\n"); - g_free(dvdreadsrc->priv); + g_print ("FIXME\n"); + g_free (dvdreadsrc->priv); } #endif -static void -dvdreadsrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +static void +dvdreadsrc_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { DVDReadSrc *src; DVDReadSrcPrivate *priv; /* it's not null if we got it, but it might not be ours */ g_return_if_fail (GST_IS_DVDREADSRC (object)); - + src = DVDREADSRC (object); priv = src->priv; @@ -228,13 +239,13 @@ dvdreadsrc_set_property (GObject *object, guint prop_id, const GValue *value, GP /*g_return_if_fail(!GST_FLAG_IS_SET(src,GST_STATE_RUNNING)); */ if (priv->location) - g_free (priv->location); + g_free (priv->location); /* clear the filename if we get a NULL (is that possible?) */ if (g_value_get_string (value) == NULL) - priv->location = g_strdup("/dev/dvd"); + priv->location = g_strdup ("/dev/dvd"); /* otherwise set the new filename */ else - priv->location = g_strdup (g_value_get_string (value)); + priv->location = g_strdup (g_value_get_string (value)); break; case ARG_TITLE: priv->title = g_value_get_int (value) - 1; @@ -254,15 +265,16 @@ dvdreadsrc_set_property (GObject *object, guint prop_id, const GValue *value, GP } -static void -dvdreadsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +static void +dvdreadsrc_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { DVDReadSrc *src; DVDReadSrcPrivate *priv; /* it's not null if we got it, but it might not be ours */ g_return_if_fail (GST_IS_DVDREADSRC (object)); - + src = DVDREADSRC (object); priv = src->priv; @@ -291,23 +303,23 @@ dvdreadsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSp * need to make this stronger. */ static int -is_nav_pack( unsigned char *buffer ) +is_nav_pack (unsigned char *buffer) { - return ( buffer[ 41 ] == 0xbf && buffer[ 1027 ] == 0xbf ); + return (buffer[41] == 0xbf && buffer[1027] == 0xbf); } static int -_open(DVDReadSrcPrivate *priv, const gchar *location) +_open (DVDReadSrcPrivate * priv, const gchar * location) { - g_return_val_if_fail(priv != NULL, -1); - g_return_val_if_fail(location != NULL, -1); + g_return_val_if_fail (priv != NULL, -1); + g_return_val_if_fail (location != NULL, -1); /** * Open the disc. */ - priv->dvd = DVDOpen( location ); - if( !priv->dvd ) { - fprintf( stderr, "Couldn't open DVD: %s\n", location ); + priv->dvd = DVDOpen (location); + if (!priv->dvd) { + fprintf (stderr, "Couldn't open DVD: %s\n", location); return -1; } @@ -316,10 +328,10 @@ _open(DVDReadSrcPrivate *priv, const gchar *location) * Load the video manager to find out the information about the titles on * this disc. */ - priv->vmg_file = ifoOpen( priv->dvd, 0 ); - if( !priv->vmg_file ) { - fprintf( stderr, "Can't open VMG info.\n" ); - DVDClose( priv->dvd ); + priv->vmg_file = ifoOpen (priv->dvd, 0); + if (!priv->vmg_file) { + fprintf (stderr, "Can't open VMG info.\n"); + DVDClose (priv->dvd); return -1; } priv->tt_srpt = priv->vmg_file->tt_srpt; @@ -328,102 +340,104 @@ _open(DVDReadSrcPrivate *priv, const gchar *location) } static int -_close(DVDReadSrcPrivate *priv) +_close (DVDReadSrcPrivate * priv) { - ifoClose( priv->vts_file ); - ifoClose( priv->vmg_file ); - DVDCloseFile( priv->dvd_title ); - DVDClose( priv->dvd ); - return 0; + ifoClose (priv->vts_file); + ifoClose (priv->vmg_file); + DVDCloseFile (priv->dvd_title); + DVDClose (priv->dvd); + return 0; } static int -_seek(DVDReadSrcPrivate *priv, int title, int chapter, int angle) +_seek (DVDReadSrcPrivate * priv, int title, int chapter, int angle) { /** * Make sure our title number is valid. */ - fprintf( stderr, "There are %d titles on this DVD.\n", - priv->tt_srpt->nr_of_srpts ); - if( title < 0 || title >= priv->tt_srpt->nr_of_srpts ) { - fprintf( stderr, "Invalid title %d.\n", title + 1 ); - ifoClose( priv->vmg_file ); - DVDClose( priv->dvd ); - return -1; - } + fprintf (stderr, "There are %d titles on this DVD.\n", + priv->tt_srpt->nr_of_srpts); + if (title < 0 || title >= priv->tt_srpt->nr_of_srpts) { + fprintf (stderr, "Invalid title %d.\n", title + 1); + ifoClose (priv->vmg_file); + DVDClose (priv->dvd); + return -1; + } /** * Make sure the chapter number is valid for this title. */ - fprintf( stderr, "There are %d chapters in this title.\n", - priv->tt_srpt->title[ title ].nr_of_ptts ); + fprintf (stderr, "There are %d chapters in this title.\n", + priv->tt_srpt->title[title].nr_of_ptts); - if( chapter < 0 || chapter >= priv->tt_srpt->title[ title ].nr_of_ptts ) { - fprintf( stderr, "Invalid chapter %d\n", chapter + 1 ); - ifoClose( priv->vmg_file ); - DVDClose( priv->dvd ); - return -1; - } + if (chapter < 0 || chapter >= priv->tt_srpt->title[title].nr_of_ptts) { + fprintf (stderr, "Invalid chapter %d\n", chapter + 1); + ifoClose (priv->vmg_file); + DVDClose (priv->dvd); + return -1; + } /** * Make sure the angle number is valid for this title. */ - fprintf( stderr, "There are %d angles in this title.\n", - priv->tt_srpt->title[ title ].nr_of_angles ); - if( angle < 0 || angle >= priv->tt_srpt->title[ title ].nr_of_angles ) { - fprintf( stderr, "Invalid angle %d\n", angle + 1 ); - ifoClose( priv->vmg_file ); - DVDClose( priv->dvd ); - return -1; - } + fprintf (stderr, "There are %d angles in this title.\n", + priv->tt_srpt->title[title].nr_of_angles); + if (angle < 0 || angle >= priv->tt_srpt->title[title].nr_of_angles) { + fprintf (stderr, "Invalid angle %d\n", angle + 1); + ifoClose (priv->vmg_file); + DVDClose (priv->dvd); + return -1; + } /** * Load the VTS information for the title set our title is in. */ - priv->vts_file = ifoOpen( priv->dvd, priv->tt_srpt->title[ title ].title_set_nr ); - if( !priv->vts_file ) { - fprintf( stderr, "Can't open the title %d info file.\n", - priv->tt_srpt->title[ title ].title_set_nr ); - ifoClose( priv->vmg_file ); - DVDClose( priv->dvd ); - return -1; - } + priv->vts_file = + ifoOpen (priv->dvd, priv->tt_srpt->title[title].title_set_nr); + if (!priv->vts_file) { + fprintf (stderr, "Can't open the title %d info file.\n", + priv->tt_srpt->title[title].title_set_nr); + ifoClose (priv->vmg_file); + DVDClose (priv->dvd); + return -1; + } /** * Determine which program chain we want to watch. This is based on the * chapter number. */ - priv->ttn = priv->tt_srpt->title[ title ].vts_ttn; - priv->vts_ptt_srpt = priv->vts_file->vts_ptt_srpt; - priv->pgc_id = priv->vts_ptt_srpt->title[ priv->ttn - 1 ].ptt[ chapter ].pgcn; - priv->pgn = priv->vts_ptt_srpt->title[ priv->ttn - 1 ].ptt[ chapter ].pgn; - priv->cur_pgc = priv->vts_file->vts_pgcit->pgci_srp[ priv->pgc_id - 1 ].pgc; - priv->start_cell = priv->cur_pgc->program_map[ priv->pgn - 1 ] - 1; + priv->ttn = priv->tt_srpt->title[title].vts_ttn; + priv->vts_ptt_srpt = priv->vts_file->vts_ptt_srpt; + priv->pgc_id = priv->vts_ptt_srpt->title[priv->ttn - 1].ptt[chapter].pgcn; + priv->pgn = priv->vts_ptt_srpt->title[priv->ttn - 1].ptt[chapter].pgn; + priv->cur_pgc = priv->vts_file->vts_pgcit->pgci_srp[priv->pgc_id - 1].pgc; + priv->start_cell = priv->cur_pgc->program_map[priv->pgn - 1] - 1; /** * We've got enough info, time to open the title set data. */ - priv->dvd_title = DVDOpenFile( priv->dvd, priv->tt_srpt->title[ title ].title_set_nr, - DVD_READ_TITLE_VOBS ); - if( !priv->dvd_title ) { - fprintf( stderr, "Can't open title VOBS (VTS_%02d_1.VOB).\n", - priv->tt_srpt->title[ title ].title_set_nr ); - ifoClose( priv->vts_file ); - ifoClose( priv->vmg_file ); - DVDClose( priv->dvd ); - return -1; - } + priv->dvd_title = + DVDOpenFile (priv->dvd, priv->tt_srpt->title[title].title_set_nr, + DVD_READ_TITLE_VOBS); + if (!priv->dvd_title) { + fprintf (stderr, "Can't open title VOBS (VTS_%02d_1.VOB).\n", + priv->tt_srpt->title[title].title_set_nr); + ifoClose (priv->vts_file); + ifoClose (priv->vmg_file); + DVDClose (priv->dvd); + return -1; + } - return 0; + return 0; } static void -dvdreadsrc_loop (GstElement *element) +dvdreadsrc_loop (GstElement * element) { DVDReadSrc *dvdreadsrc; DVDReadSrcPrivate *priv; @@ -439,82 +453,85 @@ dvdreadsrc_loop (GstElement *element) * Playback by cell in this pgc, starting at the cell for our chapter. */ priv->next_cell = priv->start_cell; - for( priv->cur_cell = priv->start_cell; priv->next_cell < priv->cur_pgc->nr_of_cells; ) { + for (priv->cur_cell = priv->start_cell; + priv->next_cell < priv->cur_pgc->nr_of_cells;) { - priv->cur_cell = priv->next_cell; + priv->cur_cell = priv->next_cell; - /* Check if we're entering an angle block. */ - if( priv->cur_pgc->cell_playback[ priv->cur_cell ].block_type - == BLOCK_TYPE_ANGLE_BLOCK ) { - int i; + /* Check if we're entering an angle block. */ + if (priv->cur_pgc->cell_playback[priv->cur_cell].block_type + == BLOCK_TYPE_ANGLE_BLOCK) { + int i; - priv->cur_cell += priv->angle; - for( i = 0;; ++i ) { - if( priv->cur_pgc->cell_playback[ priv->cur_cell + i ].block_mode - == BLOCK_MODE_LAST_CELL ) { - priv->next_cell = priv->cur_cell + i + 1; - break; - } - } - } else { - priv->next_cell = priv->cur_cell + 1; + priv->cur_cell += priv->angle; + for (i = 0;; ++i) { + if (priv->cur_pgc->cell_playback[priv->cur_cell + i].block_mode + == BLOCK_MODE_LAST_CELL) { + priv->next_cell = priv->cur_cell + i + 1; + break; + } } + } else { + priv->next_cell = priv->cur_cell + 1; + } /** * We loop until we're out of this cell. */ - for( priv->cur_pack = priv->cur_pgc->cell_playback[ priv->cur_cell ].first_sector; - priv->cur_pack < priv->cur_pgc->cell_playback[ priv->cur_cell ].last_sector; ) { + for (priv->cur_pack = + priv->cur_pgc->cell_playback[priv->cur_cell].first_sector; + priv->cur_pack < + priv->cur_pgc->cell_playback[priv->cur_cell].last_sector;) { - dsi_t dsi_pack; - unsigned int next_vobu, next_ilvu_start, cur_output_size; - GstBuffer *buf; - unsigned char *data; - int len; + dsi_t dsi_pack; + unsigned int next_vobu, next_ilvu_start, cur_output_size; + GstBuffer *buf; + unsigned char *data; + int len; - /* create the buffer */ - /* FIXME: should eventually use a bufferpool for this */ - buf = gst_buffer_new (); - g_return_if_fail (buf); + /* create the buffer */ + /* FIXME: should eventually use a bufferpool for this */ + buf = gst_buffer_new (); + g_return_if_fail (buf); - /* allocate the space for the buffer data */ - data = g_malloc (1024 * DVD_VIDEO_LB_LEN); - GST_BUFFER_DATA (buf) = data; + /* allocate the space for the buffer data */ + data = g_malloc (1024 * DVD_VIDEO_LB_LEN); + GST_BUFFER_DATA (buf) = data; - g_return_if_fail (GST_BUFFER_DATA (buf) != NULL); + g_return_if_fail (GST_BUFFER_DATA (buf) != NULL); - /** + /** * Read NAV packet. */ - len = DVDReadBlocks( priv->dvd_title, priv->cur_pack, 1, data ); - if( len == 0 ) { - fprintf( stderr, "Read failed for block %d\n", priv->cur_pack ); - _close(priv); - gst_element_set_eos (GST_ELEMENT (dvdreadsrc)); - return; - } - assert( is_nav_pack( data ) ); + len = DVDReadBlocks (priv->dvd_title, priv->cur_pack, 1, data); + if (len == 0) { + fprintf (stderr, "Read failed for block %d\n", priv->cur_pack); + _close (priv); + gst_element_set_eos (GST_ELEMENT (dvdreadsrc)); + return; + } + assert (is_nav_pack (data)); - /** + /** * Parse the contained dsi packet. */ - navRead_DSI( &dsi_pack, &(data[ DSI_START_BYTE ]) ); - assert( priv->cur_pack == dsi_pack.dsi_gi.nv_pck_lbn ); - /*navPrint_DSI(&dsi_pack); */ + navRead_DSI (&dsi_pack, &(data[DSI_START_BYTE])); + assert (priv->cur_pack == dsi_pack.dsi_gi.nv_pck_lbn); + /*navPrint_DSI(&dsi_pack); */ - /** + /** * Determine where we go next. These values are the ones we mostly * care about. */ - next_ilvu_start = priv->cur_pack - + dsi_pack.sml_agli.data[ priv->angle ].address; - cur_output_size = dsi_pack.dsi_gi.vobu_ea; + next_ilvu_start = priv->cur_pack + + dsi_pack.sml_agli.data[priv->angle].address; + cur_output_size = dsi_pack.dsi_gi.vobu_ea; - /** + /** * If we're not at the end of this cell, we can determine the next * VOBU to display using the VOBU_SRI information section of the * DSI. Using this value correctly follows the current angle, @@ -524,117 +541,117 @@ dvdreadsrc_loop (GstElement *element) * Otherwise, we set our next address past the end of this cell to * force the code above to go to the next cell in the program. */ - if( dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL ) { - next_vobu = priv->cur_pack - + ( dsi_pack.vobu_sri.next_vobu & 0x7fffffff ); - } else { - next_vobu = priv->cur_pack + cur_output_size + 1; - } + if (dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL) { + next_vobu = priv->cur_pack + (dsi_pack.vobu_sri.next_vobu & 0x7fffffff); + } else { + next_vobu = priv->cur_pack + cur_output_size + 1; + } - assert( cur_output_size < 1024 ); - priv->cur_pack++; + assert (cur_output_size < 1024); + priv->cur_pack++; - /** + /** * Read in and output cursize packs. */ - len = DVDReadBlocks( priv->dvd_title, priv->cur_pack, - cur_output_size, data ); - if( len != cur_output_size ) { - fprintf( stderr, "Read failed for %d blocks at %d\n", - cur_output_size, priv->cur_pack ); - _close(priv); - gst_element_set_eos (GST_ELEMENT (dvdreadsrc)); - return; - } - - GST_BUFFER_SIZE(buf) = cur_output_size * DVD_VIDEO_LB_LEN; - gst_pad_push(priv->srcpad, GST_DATA (buf)); - priv->cur_pack = next_vobu; + len = DVDReadBlocks (priv->dvd_title, priv->cur_pack, + cur_output_size, data); + if (len != cur_output_size) { + fprintf (stderr, "Read failed for %d blocks at %d\n", + cur_output_size, priv->cur_pack); + _close (priv); + gst_element_set_eos (GST_ELEMENT (dvdreadsrc)); + return; } + + GST_BUFFER_SIZE (buf) = cur_output_size * DVD_VIDEO_LB_LEN; + gst_pad_push (priv->srcpad, GST_DATA (buf)); + priv->cur_pack = next_vobu; + } } } #if 0 static int -_read(DVDReadSrcPrivate *priv, int angle, int new_seek, GstBuffer *buf) +_read (DVDReadSrcPrivate * priv, int angle, int new_seek, GstBuffer * buf) { - unsigned char *data; + unsigned char *data; - data = GST_BUFFER_DATA(buf); + data = GST_BUFFER_DATA (buf); /** * Playback by cell in this pgc, starting at the cell for our chapter. */ - if (new_seek) { - priv->next_cell = priv->start_cell; - priv->cur_cell = priv->start_cell; + if (new_seek) { + priv->next_cell = priv->start_cell; + priv->cur_cell = priv->start_cell; + } + if (priv->next_cell < priv->cur_pgc->nr_of_cells) { + + priv->cur_cell = priv->next_cell; + + /* Check if we're entering an angle block. */ + if (priv->cur_pgc->cell_playback[priv->cur_cell].block_type + == BLOCK_TYPE_ANGLE_BLOCK) { + int i; + + priv->cur_cell += angle; + for (i = 0;; ++i) { + if (priv->cur_pgc->cell_playback[priv->cur_cell + i].block_mode + == BLOCK_MODE_LAST_CELL) { + priv->next_cell = priv->cur_cell + i + 1; + break; + } + } + } else { + priv->next_cell = priv->cur_cell + 1; } - if (priv->next_cell < priv->cur_pgc->nr_of_cells) { - - priv->cur_cell = priv->next_cell; - - /* Check if we're entering an angle block. */ - if( priv->cur_pgc->cell_playback[ priv->cur_cell ].block_type - == BLOCK_TYPE_ANGLE_BLOCK ) { - int i; - - priv->cur_cell += angle; - for( i = 0;; ++i ) { - if( priv->cur_pgc->cell_playback[ priv->cur_cell + i ].block_mode - == BLOCK_MODE_LAST_CELL ) { - priv->next_cell = priv->cur_cell + i + 1; - break; - } - } - } else { - priv->next_cell = priv->cur_cell + 1; - } - /** + /** * We loop until we're out of this cell. */ - if (priv->new_cell) { - priv->cur_pack = priv->cur_pgc->cell_playback[ priv->cur_cell ].first_sector; - priv->new_cell = FALSE; - } + if (priv->new_cell) { + priv->cur_pack = + priv->cur_pgc->cell_playback[priv->cur_cell].first_sector; + priv->new_cell = FALSE; + } - if (priv->cur_pack < priv->cur_pgc->cell_playback[ priv->cur_cell ].last_sector; ) { + if (priv->cur_pack < + priv->cur_pgc->cell_playback[priv->cur_cell].last_sector;) { - dsi_t dsi_pack; - unsigned int next_vobu, next_ilvu_start, cur_output_size; - int len; + dsi_t dsi_pack; + unsigned int next_vobu, next_ilvu_start, cur_output_size; + int len; - /** + /** * Read NAV packet. */ - len = DVDReadBlocks( priv->title, priv->cur_pack, 1, data ); - if( len == 0 ) { - fprintf( stderr, "Read failed for block %d\n", priv->cur_pack ); - _close(priv); - return -1; - } - assert( is_nav_pack( data ) ); + len = DVDReadBlocks (priv->title, priv->cur_pack, 1, data); + if (len == 0) { + fprintf (stderr, "Read failed for block %d\n", priv->cur_pack); + _close (priv); + return -1; + } + assert (is_nav_pack (data)); - /** + /** * Parse the contained dsi packet. */ - navRead_DSI( &dsi_pack, &(data[ DSI_START_BYTE ]), sizeof(dsi_t) ); - assert( priv->cur_pack == dsi_pack.dsi_gi.nv_pck_lbn ); + navRead_DSI (&dsi_pack, &(data[DSI_START_BYTE]), sizeof (dsi_t)); + assert (priv->cur_pack == dsi_pack.dsi_gi.nv_pck_lbn); - /** + /** * Determine where we go next. These values are the ones we mostly * care about. */ - next_ilvu_start = priv->cur_pack - + dsi_pack.sml_agli.data[ angle ].address; - cur_output_size = dsi_pack.dsi_gi.vobu_ea; + next_ilvu_start = priv->cur_pack + dsi_pack.sml_agli.data[angle].address; + cur_output_size = dsi_pack.dsi_gi.vobu_ea; - /** + /** * If we're not at the end of this cell, we can determine the next * VOBU to display using the VOBU_SRI information section of the * DSI. Using this value correctly follows the current angle, @@ -644,40 +661,38 @@ _read(DVDReadSrcPrivate *priv, int angle, int new_seek, GstBuffer *buf) * Otherwise, we set our next address past the end of this cell to * force the code above to go to the next cell in the program. */ - if( dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL ) { - next_vobu = priv->cur_pack - + ( dsi_pack.vobu_sri.next_vobu & 0x7fffffff ); - } else { - next_vobu = priv->cur_pack + cur_output_size + 1; - } + if (dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL) { + next_vobu = priv->cur_pack + (dsi_pack.vobu_sri.next_vobu & 0x7fffffff); + } else { + next_vobu = priv->cur_pack + cur_output_size + 1; + } - assert( cur_output_size < 1024 ); - priv->cur_pack++; + assert (cur_output_size < 1024); + priv->cur_pack++; - /** + /** * Read in and output cursize packs. */ - len = DVDReadBlocks( priv->title, priv->cur_pack, - cur_output_size, data ); - if( len != cur_output_size ) { - fprintf( stderr, "Read failed for %d blocks at %d\n", - cur_output_size, priv->cur_pack ); - _close(priv); - return -1; - } + len = DVDReadBlocks (priv->title, priv->cur_pack, cur_output_size, data); + if (len != cur_output_size) { + fprintf (stderr, "Read failed for %d blocks at %d\n", + cur_output_size, priv->cur_pack); + _close (priv); + return -1; + } - GST_BUFFER_SIZE(buf) = cur_output_size * DVD_VIDEO_LB_LEN; - priv->cur_pack = next_vobu; - } - } else { - return -1; + GST_BUFFER_SIZE (buf) = cur_output_size * DVD_VIDEO_LB_LEN; + priv->cur_pack = next_vobu; } + } else { + return -1; + } - return 0; + return 0; } static GstData * -dvdreadsrc_get (GstPad *pad) +dvdreadsrc_get (GstPad * pad) { DVDReadSrc *dvdreadsrc; DVDReadSrcPrivate *priv; @@ -688,7 +703,7 @@ dvdreadsrc_get (GstPad *pad) dvdreadsrc = DVDREADSRC (gst_pad_get_parent (pad)); priv = dvdreadsrc->priv; - g_return_val_if_fail (GST_FLAG_IS_SET (dvdreadsrc, DVDREADSRC_OPEN),NULL); + g_return_val_if_fail (GST_FLAG_IS_SET (dvdreadsrc, DVDREADSRC_OPEN), NULL); /* create the buffer */ /* FIXME: should eventually use a bufferpool for this */ @@ -700,7 +715,7 @@ dvdreadsrc_get (GstPad *pad) g_return_val_if_fail (GST_BUFFER_DATA (buf) != NULL, NULL); if (priv->new_seek) { - _seek(priv, priv->titleid, priv->chapid, priv->angle); + _seek (priv, priv->titleid, priv->chapid, priv->angle); } /* read it in from the file */ @@ -718,39 +733,36 @@ dvdreadsrc_get (GstPad *pad) #endif /* open the file, necessary to go to RUNNING state */ -static gboolean -dvdreadsrc_open_file (DVDReadSrc *src) +static gboolean +dvdreadsrc_open_file (DVDReadSrc * src) { g_return_val_if_fail (src != NULL, FALSE); - g_return_val_if_fail (GST_IS_DVDREADSRC(src), FALSE); + g_return_val_if_fail (GST_IS_DVDREADSRC (src), FALSE); g_return_val_if_fail (!GST_FLAG_IS_SET (src, DVDREADSRC_OPEN), FALSE); - if (_open(src->priv, src->priv->location)) + if (_open (src->priv, src->priv->location)) return FALSE; - if (_seek(src->priv, - src->priv->title, - src->priv->chapter, - src->priv->angle)) + if (_seek (src->priv, src->priv->title, src->priv->chapter, src->priv->angle)) return FALSE; GST_FLAG_SET (src, DVDREADSRC_OPEN); - + return TRUE; } /* close the file */ -static void -dvdreadsrc_close_file (DVDReadSrc *src) +static void +dvdreadsrc_close_file (DVDReadSrc * src) { g_return_if_fail (GST_FLAG_IS_SET (src, DVDREADSRC_OPEN)); - _close(src->priv); + _close (src->priv); GST_FLAG_UNSET (src, DVDREADSRC_OPEN); } static GstElementStateReturn -dvdreadsrc_change_state (GstElement *element) +dvdreadsrc_change_state (GstElement * element) { g_return_val_if_fail (GST_IS_DVDREADSRC (element), GST_STATE_FAILURE); @@ -760,11 +772,11 @@ dvdreadsrc_change_state (GstElement *element) if (GST_STATE_PENDING (element) == GST_STATE_NULL) { if (GST_FLAG_IS_SET (element, DVDREADSRC_OPEN)) dvdreadsrc_close_file (DVDREADSRC (element)); - /* otherwise (READY or higher) we need to open the file */ + /* otherwise (READY or higher) we need to open the file */ } else { if (!GST_FLAG_IS_SET (element, DVDREADSRC_OPEN)) { if (!dvdreadsrc_open_file (DVDREADSRC (element))) - return GST_STATE_FAILURE; + return GST_STATE_FAILURE; } } @@ -776,22 +788,17 @@ dvdreadsrc_change_state (GstElement *element) } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "dvdreadsrc", GST_RANK_NONE, GST_TYPE_DVDREADSRC)) + if (!gst_element_register (plugin, "dvdreadsrc", GST_RANK_NONE, + GST_TYPE_DVDREADSRC)) return FALSE; return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "dvdreadsrc", - "Access a DVD with dvdread", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN) - +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "dvdreadsrc", + "Access a DVD with dvdread", + plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/dvdread/dvdreadsrc.h b/ext/dvdread/dvdreadsrc.h index c896f01d68..7ee6364fbd 100644 --- a/ext/dvdread/dvdreadsrc.h +++ b/ext/dvdread/dvdreadsrc.h @@ -25,9 +25,7 @@ #include -G_BEGIN_DECLS - -GstElementDetails dvdreadsrc_details; +G_BEGIN_DECLS GstElementDetails dvdreadsrc_details; #define GST_TYPE_DVDREADSRC \ @@ -42,27 +40,29 @@ GstElementDetails dvdreadsrc_details; (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DVDREADSRC)) /* NOTE: per-element flags start with 16 for now */ -typedef enum { - DVDREADSRC_OPEN = GST_ELEMENT_FLAG_LAST, +typedef enum +{ + DVDREADSRC_OPEN = GST_ELEMENT_FLAG_LAST, - DVDREADSRC_FLAG_LAST = GST_ELEMENT_FLAG_LAST+2, + DVDREADSRC_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2, } DVDReadSrcFlags; typedef struct _DVDReadSrc DVDReadSrc; typedef struct _DVDReadSrcPrivate DVDReadSrcPrivate; typedef struct _DVDReadSrcClass DVDReadSrcClass; -struct _DVDReadSrc { +struct _DVDReadSrc +{ GstElement element; DVDReadSrcPrivate *priv; }; -struct _DVDReadSrcClass { +struct _DVDReadSrcClass +{ GstElementClass parent_class; }; -GType dvdreadsrc_get_type(void); +GType dvdreadsrc_get_type (void); G_END_DECLS - #endif /* __DVDREADSRC_H__ */ diff --git a/ext/lame/gstlame.c b/ext/lame/gstlame.c index 0b32b4baa5..ba52981c65 100644 --- a/ext/lame/gstlame.c +++ b/ext/lame/gstlame.c @@ -24,8 +24,7 @@ #include "gstlame.h" /* elementfactory information */ -static GstElementDetails gst_lame_details = -{ +static GstElementDetails gst_lame_details = { "L.A.M.E. mp3 encoder", "Codec/Audio/Encoder", "High-quality free MP3 encoder", @@ -33,34 +32,28 @@ static GstElementDetails gst_lame_details = }; static GstStaticPadTemplate gst_lame_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "audio/x-raw-int, " - "endianness = (int) BYTE_ORDER, " - "signed = (boolean) true, " - "width = (int) 16, " - "depth = (int) 16, " - "rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, " - "channels = (int) [ 1, 2 ]" - ) -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) BYTE_ORDER, " + "signed = (boolean) true, " + "width = (int) 16, " + "depth = (int) 16, " + "rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, " + "channels = (int) [ 1, 2 ]") + ); static GstStaticPadTemplate gst_lame_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "audio/mpeg, " - "mpegversion = (int) 1, " - "layer = (int) 3, " - "rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, " - "channels = (int) [ 1, 2 ]" - ) -); +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/mpeg, " + "mpegversion = (int) 1, " + "layer = (int) 3, " + "rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, " + "channels = (int) [ 1, 2 ]") + ); /********** Define useful types for non-programmatic interfaces **********/ #define GST_TYPE_LAME_MODE (gst_lame_mode_get_type()) @@ -69,12 +62,12 @@ gst_lame_mode_get_type (void) { static GType lame_mode_type = 0; static GEnumValue lame_modes[] = { - { 0, "0", "Stereo" }, - { 1, "1", "Joint-Stereo" }, - { 2, "2", "Dual channel" }, - { 3, "3", "Mono" }, - { 4, "4", "Auto" }, - { 0, NULL, NULL }, + {0, "0", "Stereo"}, + {1, "1", "Joint-Stereo"}, + {2, "2", "Dual channel"}, + {3, "3", "Mono"}, + {4, "4", "Auto"}, + {0, NULL, NULL}, }; if (!lame_mode_type) { lame_mode_type = g_enum_register_static ("GstLameMode", lame_modes); @@ -88,17 +81,17 @@ gst_lame_quality_get_type (void) { static GType lame_quality_type = 0; static GEnumValue lame_quality[] = { - { 0, "0", "0 - Best" }, - { 1, "1", "1" }, - { 2, "2", "2" }, - { 3, "3", "3" }, - { 4, "4", "4" }, - { 5, "5", "5 - Default" }, - { 6, "6", "6" }, - { 7, "7", "7" }, - { 8, "8", "8" }, - { 9, "9", "9 - Worst" }, - { 0, NULL, NULL }, + {0, "0", "0 - Best"}, + {1, "1", "1"}, + {2, "2", "2"}, + {3, "3", "3"}, + {4, "4", "4"}, + {5, "5", "5 - Default"}, + {6, "6", "6"}, + {7, "7", "7"}, + {8, "8", "8"}, + {9, "9", "9 - Worst"}, + {0, NULL, NULL}, }; if (!lame_quality_type) { lame_quality_type = g_enum_register_static ("GstLameQuality", lame_quality); @@ -112,10 +105,10 @@ gst_lame_padding_get_type (void) { static GType lame_padding_type = 0; static GEnumValue lame_padding[] = { - { 0, "0", "No Padding" }, - { 1, "1", "Always Pad" }, - { 2, "2", "Adjust Padding" }, - { 0, NULL, NULL }, + {0, "0", "No Padding"}, + {1, "1", "Always Pad"}, + {2, "2", "Adjust Padding"}, + {0, NULL, NULL}, }; if (!lame_padding_type) { lame_padding_type = g_enum_register_static ("GstLamePadding", lame_padding); @@ -125,12 +118,14 @@ gst_lame_padding_get_type (void) /********** Standard stuff for signals and arguments **********/ /* GstLame signals and args */ -enum { +enum +{ /* FILL_ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_BITRATE, ARG_COMPRESSION_RATIO, @@ -164,19 +159,20 @@ enum { ARG_EMPHASIS, }; -static void gst_lame_base_init (gpointer g_class); -static void gst_lame_class_init (GstLameClass *klass); -static void gst_lame_init (GstLame *gst_lame); +static void gst_lame_base_init (gpointer g_class); +static void gst_lame_class_init (GstLameClass * klass); +static void gst_lame_init (GstLame * gst_lame); -static void gst_lame_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_lame_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); -static void gst_lame_chain (GstPad *pad, GstData *_data); -static gboolean gst_lame_setup (GstLame *lame); -static GstElementStateReturn gst_lame_change_state (GstElement *element); +static void gst_lame_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_lame_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static void gst_lame_chain (GstPad * pad, GstData * _data); +static gboolean gst_lame_setup (GstLame * lame); +static GstElementStateReturn gst_lame_change_state (GstElement * element); static GstElementClass *parent_class = NULL; + /* static guint gst_lame_signals[LAST_SIGNAL] = { 0 }; */ GType @@ -186,13 +182,13 @@ gst_lame_get_type (void) if (!gst_lame_type) { static const GTypeInfo gst_lame_info = { - sizeof (GstLameClass), + sizeof (GstLameClass), gst_lame_base_init, NULL, (GClassInitFunc) gst_lame_class_init, NULL, NULL, - sizeof(GstLame), + sizeof (GstLame), 0, (GInstanceInitFunc) gst_lame_init, }; @@ -203,8 +199,10 @@ gst_lame_get_type (void) NULL }; - gst_lame_type = g_type_register_static (GST_TYPE_ELEMENT, "GstLame", &gst_lame_info, 0); - g_type_add_interface_static (gst_lame_type, GST_TYPE_TAG_SETTER, &tag_setter_info); + gst_lame_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstLame", &gst_lame_info, 0); + g_type_add_interface_static (gst_lame_type, GST_TYPE_TAG_SETTER, + &tag_setter_info); } return gst_lame_type; @@ -215,123 +213,124 @@ gst_lame_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_pad_template (element_class, + gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_lame_src_template)); - gst_element_class_add_pad_template (element_class, + gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_lame_sink_template)); gst_element_class_set_details (element_class, &gst_lame_details); } static void -gst_lame_class_init (GstLameClass *klass) +gst_lame_class_init (GstLameClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BITRATE, - g_param_spec_int("bitrate", "Bitrate (kb/s)", "Bitrate in kbit/sec", - 8, 320, 128, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_COMPRESSION_RATIO, - g_param_spec_float ("compression_ratio", "Compression Ratio", - "choose bitrate to achive selected compression ratio", - 1.0, 200.0, 11.0, G_PARAM_READWRITE)); + g_param_spec_int ("bitrate", "Bitrate (kb/s)", "Bitrate in kbit/sec", + 8, 320, 128, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_COMPRESSION_RATIO, g_param_spec_float ("compression_ratio", + "Compression Ratio", + "choose bitrate to achive selected compression ratio", 1.0, 200.0, + 11.0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY, - g_param_spec_enum ("quality", "Quality", "Encoding Quality", - GST_TYPE_LAME_QUALITY, 5, G_PARAM_READWRITE)); + g_param_spec_enum ("quality", "Quality", "Encoding Quality", + GST_TYPE_LAME_QUALITY, 5, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MODE, - g_param_spec_enum ("mode", "Mode", "Encoding mode", - GST_TYPE_LAME_MODE, 0, G_PARAM_READWRITE)); + g_param_spec_enum ("mode", "Mode", "Encoding mode", GST_TYPE_LAME_MODE, 0, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FORCE_MS, - g_param_spec_boolean ("force_ms","Force ms","Force ms_stereo on all frames", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("force_ms", "Force ms", + "Force ms_stereo on all frames", TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FREE_FORMAT, - g_param_spec_boolean ("free_format","Free format","Produce a free format bitstream", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("free_format", "Free format", + "Produce a free format bitstream", TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_COPYRIGHT, - g_param_spec_boolean ("copyright","Copyright","Mark as copyright", - TRUE, G_PARAM_READWRITE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_ORIGINAL, - g_param_spec_boolean("original", "Original", "Mark as non-original", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("copyright", "Copyright", "Mark as copyright", TRUE, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ORIGINAL, + g_param_spec_boolean ("original", "Original", "Mark as non-original", + TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ERROR_PROTECTION, - g_param_spec_boolean ("error_protection","Error protection", - "Adds 16 bit checksum to every frame", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("error_protection", "Error protection", + "Adds 16 bit checksum to every frame", TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PADDING_TYPE, - g_param_spec_enum ("padding_type", "Padding type", "Padding type", - GST_TYPE_LAME_PADDING, 0, G_PARAM_READWRITE)); + g_param_spec_enum ("padding_type", "Padding type", "Padding type", + GST_TYPE_LAME_PADDING, 0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXTENSION, - g_param_spec_boolean ("extension", "Extension", "Extension", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("extension", "Extension", "Extension", TRUE, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STRICT_ISO, - g_param_spec_boolean ("strict_iso", "Strict ISO", - "Comply as much as possible to ISO MPEG spec", - TRUE, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DISABLE_RESERVOIR, - g_param_spec_boolean ("disable_reservoir", "Disable reservoir", "Disable the bit reservoir", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("strict_iso", "Strict ISO", + "Comply as much as possible to ISO MPEG spec", TRUE, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_DISABLE_RESERVOIR, g_param_spec_boolean ("disable_reservoir", + "Disable reservoir", "Disable the bit reservoir", TRUE, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR, - g_param_spec_boolean ("vbr", "VBR", "Use variable bitrate", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("vbr", "VBR", "Use variable bitrate", TRUE, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MEAN_BITRATE, - g_param_spec_int ("vbr_mean_bitrate", "VBR mean bitrate", "Specify mean bitrate", - 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_param_spec_int ("vbr_mean_bitrate", "VBR mean bitrate", + "Specify mean bitrate", 0, G_MAXINT, 0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MIN_BITRATE, - g_param_spec_int ("vbr_min_bitrate", "VBR min bitrate", "Specify min bitrate", - 0, G_MAXINT, 0, G_PARAM_READWRITE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VBR_MAX_BITRATE, - g_param_spec_int ("vbr_max_bitrate", "VBR max bitrate", "Specify max bitrate", - 0, G_MAXINT, 0, G_PARAM_READWRITE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VBR_HARD_MIN, - g_param_spec_int ("vbr_hard_min", "VBR hard min", "Specify hard min bitrate", - 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_param_spec_int ("vbr_min_bitrate", "VBR min bitrate", + "Specify min bitrate", 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_MAX_BITRATE, + g_param_spec_int ("vbr_max_bitrate", "VBR max bitrate", + "Specify max bitrate", 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VBR_HARD_MIN, + g_param_spec_int ("vbr_hard_min", "VBR hard min", + "Specify hard min bitrate", 0, G_MAXINT, 0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWPASS_FREQ, - g_param_spec_int ("lowpass_freq", "Lowpass freq", - "frequency(kHz), lowpass filter cutoff above freq", - 0, 50000, 0, G_PARAM_READWRITE)); + g_param_spec_int ("lowpass_freq", "Lowpass freq", + "frequency(kHz), lowpass filter cutoff above freq", 0, 50000, 0, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWPASS_WIDTH, - g_param_spec_int ("lowpass_width", "Lowpass width", - "frequency(kHz) - default 15% of lowpass freq", - 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_param_spec_int ("lowpass_width", "Lowpass width", + "frequency(kHz) - default 15% of lowpass freq", 0, G_MAXINT, 0, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HIGHPASS_FREQ, - g_param_spec_int ("highpass_freq", "Highpass freq", - "frequency(kHz), highpass filter cutoff below freq", - 0, 50000, 0, G_PARAM_READWRITE)); + g_param_spec_int ("highpass_freq", "Highpass freq", + "frequency(kHz), highpass filter cutoff below freq", 0, 50000, 0, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HIGHPASS_WIDTH, - g_param_spec_int ("highpass_width", "Highpass width", - "frequency(kHz) - default 15% of highpass freq", - 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_param_spec_int ("highpass_width", "Highpass width", + "frequency(kHz) - default 15% of highpass freq", 0, G_MAXINT, 0, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_ONLY, - g_param_spec_boolean ("ath_only", "ATH only", - "Ignore GPSYCHO completely, use ATH only", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("ath_only", "ATH only", + "Ignore GPSYCHO completely, use ATH only", TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_SHORT, - g_param_spec_boolean ("ath_short", "ATH short", - "Ignore GPSYCHO for short blocks, use ATH only", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("ath_short", "ATH short", + "Ignore GPSYCHO for short blocks, use ATH only", TRUE, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NO_ATH, - g_param_spec_boolean ("no_ath", "No ath", "turns ATH down to a flat noise floor", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("no_ath", "No ath", + "turns ATH down to a flat noise floor", TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ATH_LOWER, - g_param_spec_int ("ath_lower", "ATH lower", "lowers ATH by x dB", - G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); + g_param_spec_int ("ath_lower", "ATH lower", "lowers ATH by x dB", + G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CWLIMIT, - g_param_spec_int ("cwlimit", "Cwlimit", "Compute tonality up to freq (in kHz) default 8.8717", - 0, 50000, 0, G_PARAM_READWRITE)); + g_param_spec_int ("cwlimit", "Cwlimit", + "Compute tonality up to freq (in kHz) default 8.8717", 0, 50000, 0, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ALLOW_DIFF_SHORT, - g_param_spec_boolean ("allow_diff_short", "Allow diff short", "Allow diff short", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("allow_diff_short", "Allow diff short", + "Allow diff short", TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NO_SHORT_BLOCKS, - g_param_spec_boolean ("no_short_blocks", "No short blocks", "Do not use short blocks", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("no_short_blocks", "No short blocks", + "Do not use short blocks", TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EMPHASIS, - g_param_spec_boolean ("emphasis", "Emphasis", "Emphasis", - TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("emphasis", "Emphasis", "Emphasis", TRUE, + G_PARAM_READWRITE)); gobject_class->set_property = gst_lame_set_property; gobject_class->get_property = gst_lame_get_property; @@ -340,7 +339,7 @@ gst_lame_class_init (GstLameClass *klass) } static GstPadLinkReturn -gst_lame_sink_link (GstPad *pad, const GstCaps *caps) +gst_lame_sink_link (GstPad * pad, const GstCaps * caps) { GstLame *lame; gint out_samplerate; @@ -355,37 +354,36 @@ gst_lame_sink_link (GstPad *pad, const GstCaps *caps) if (!gst_lame_setup (lame)) { GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL), - ("could not initialize encoder (wrong parameters?)")); + ("could not initialize encoder (wrong parameters?)")); return GST_PAD_LINK_REFUSED; } out_samplerate = lame_get_out_samplerate (lame->lgf); - othercaps = - gst_caps_new_simple ( - "audio/mpeg", - "mpegversion", G_TYPE_INT, 1, - "layer", G_TYPE_INT, 3, - "channels", G_TYPE_INT, lame->num_channels, - "rate", G_TYPE_INT, out_samplerate, - NULL - ); + othercaps = + gst_caps_new_simple ("audio/mpeg", + "mpegversion", G_TYPE_INT, 1, + "layer", G_TYPE_INT, 3, + "channels", G_TYPE_INT, lame->num_channels, + "rate", G_TYPE_INT, out_samplerate, NULL); return gst_pad_try_set_caps (lame->srcpad, othercaps); } static void -gst_lame_init (GstLame *lame) +gst_lame_init (GstLame * lame) { GST_DEBUG_OBJECT (lame, "starting initialization"); - lame->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_lame_sink_template), "sink"); + lame->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_lame_sink_template), "sink"); gst_element_add_pad (GST_ELEMENT (lame), lame->sinkpad); gst_pad_set_chain_function (lame->sinkpad, gst_lame_chain); gst_pad_set_link_function (lame->sinkpad, gst_lame_sink_link); - lame->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_lame_src_template), "src"); + lame->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_lame_src_template), "src"); gst_element_add_pad (GST_ELEMENT (lame), lame->srcpad); GST_FLAG_SET (lame, GST_ELEMENT_EVENT_AWARE); @@ -431,12 +429,12 @@ gst_lame_init (GstLame *lame) lame->tags = gst_tag_list_new (); id3tag_init (lame->lgf); - + GST_DEBUG_OBJECT (lame, "done initializing"); } typedef struct _GstLameTagMatch GstLameTagMatch; -typedef void (*GstLameTagFunc)(lame_global_flags* gfp, const char *value); +typedef void (*GstLameTagFunc) (lame_global_flags * gfp, const char *value); struct _GstLameTagMatch { @@ -444,21 +442,19 @@ struct _GstLameTagMatch GstLameTagFunc tag_func; }; -static GstLameTagMatch tag_matches[] = - { - {GST_TAG_TITLE, id3tag_set_title}, - {GST_TAG_DATE, id3tag_set_year}, - {GST_TAG_TRACK_NUMBER, id3tag_set_track}, - {GST_TAG_COMMENT, id3tag_set_comment}, - {GST_TAG_ARTIST, id3tag_set_artist}, - {GST_TAG_ALBUM, id3tag_set_album}, - {GST_TAG_GENRE, (GstLameTagFunc)id3tag_set_genre}, - {NULL, NULL} - }; +static GstLameTagMatch tag_matches[] = { + {GST_TAG_TITLE, id3tag_set_title}, + {GST_TAG_DATE, id3tag_set_year}, + {GST_TAG_TRACK_NUMBER, id3tag_set_track}, + {GST_TAG_COMMENT, id3tag_set_comment}, + {GST_TAG_ARTIST, id3tag_set_artist}, + {GST_TAG_ALBUM, id3tag_set_album}, + {GST_TAG_GENRE, (GstLameTagFunc) id3tag_set_genre}, + {NULL, NULL} +}; -static void -add_one_tag (const GstTagList *list, const gchar *tag, - gpointer user_data) +static void +add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data) { GstLame *lame; gchar *value; @@ -473,31 +469,32 @@ add_one_tag (const GstTagList *list, const gchar *tag, } i++; } - + if (tag_matches[i].tag_func == NULL) { g_print ("Couldn't find matching gstreamer tag for %s\n", tag); return; } switch (gst_tag_get_type (tag)) { - case G_TYPE_UINT: { - guint ivalue; - if (!gst_tag_list_get_uint (list, tag, &ivalue)) { - GST_DEBUG ("Error reading \"%s\" tag value\n", tag); - return; + case G_TYPE_UINT:{ + guint ivalue; + + if (!gst_tag_list_get_uint (list, tag, &ivalue)) { + GST_DEBUG ("Error reading \"%s\" tag value\n", tag); + return; + } + value = g_strdup_printf ("%u", ivalue); + break; } - value = g_strdup_printf ("%u", ivalue); - break; - } - case G_TYPE_STRING: - if (!gst_tag_list_get_string (list, tag, &value)) { - GST_DEBUG ("Error reading \"%s\" tag value\n", tag); - return; - }; - break; - default: - GST_DEBUG ("Couldn't write tag %s", tag); - break; + case G_TYPE_STRING: + if (!gst_tag_list_get_string (list, tag, &value)) { + GST_DEBUG ("Error reading \"%s\" tag value\n", tag); + return; + }; + break; + default: + GST_DEBUG ("Couldn't write tag %s", tag); + break; } tag_matches[i].tag_func (lame->lgf, value); @@ -508,7 +505,7 @@ add_one_tag (const GstTagList *list, const gchar *tag, } static void -gst_lame_set_metadata (GstLame *lame) +gst_lame_set_metadata (GstLame * lame) { const GstTagList *user_tags; GstTagList *copy; @@ -518,9 +515,9 @@ gst_lame_set_metadata (GstLame *lame) if ((lame->tags == NULL) && (user_tags == NULL)) { return; } - copy = gst_tag_list_merge (user_tags, lame->tags, - gst_tag_setter_get_merge_mode (GST_TAG_SETTER (lame))); - gst_tag_list_foreach ((GstTagList*)copy, add_one_tag, lame); + copy = gst_tag_list_merge (user_tags, lame->tags, + gst_tag_setter_get_merge_mode (GST_TAG_SETTER (lame))); + gst_tag_list_foreach ((GstTagList *) copy, add_one_tag, lame); gst_tag_list_free (copy); } @@ -528,7 +525,8 @@ gst_lame_set_metadata (GstLame *lame) static void -gst_lame_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_lame_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { GstLame *lame; @@ -635,7 +633,8 @@ gst_lame_set_property (GObject *object, guint prop_id, const GValue *value, GPar } static void -gst_lame_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_lame_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstLame *lame; @@ -742,7 +741,7 @@ gst_lame_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec } static void -gst_lame_chain (GstPad *pad, GstData *_data) +gst_lame_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstLame *lame; @@ -760,71 +759,67 @@ gst_lame_chain (GstPad *pad, GstData *_data) case GST_EVENT_EOS: eos = TRUE; case GST_EVENT_FLUSH: - mp3_buffer_size = 7200; - mp3_data = g_malloc (mp3_buffer_size); + mp3_buffer_size = 7200; + mp3_data = g_malloc (mp3_buffer_size); - mp3_size = lame_encode_flush (lame->lgf, mp3_data, mp3_buffer_size); + mp3_size = lame_encode_flush (lame->lgf, mp3_data, mp3_buffer_size); gst_event_unref (GST_EVENT (buf)); - break; + break; case GST_EVENT_TAG: if (lame->tags) { - gst_tag_list_insert (lame->tags, gst_event_tag_get_list (GST_EVENT (buf)), - gst_tag_setter_get_merge_mode (GST_TAG_SETTER (lame))); + gst_tag_list_insert (lame->tags, + gst_event_tag_get_list (GST_EVENT (buf)), + gst_tag_setter_get_merge_mode (GST_TAG_SETTER (lame))); } else { g_assert_not_reached (); - } - // gst_pad_event_default (pad, GST_EVENT (buf)); + } + // gst_pad_event_default (pad, GST_EVENT (buf)); break; default: gst_pad_event_default (pad, GST_EVENT (buf)); break; } - } - else { + } else { gint64 duration; if (!lame->initialized) { gst_buffer_unref (buf); GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL), - ("encoder not initialized (input is not audio?)")); + ("encoder not initialized (input is not audio?)")); return; } /* allocate space for output */ - mp3_buffer_size = ((GST_BUFFER_SIZE(buf) / (2+lame->num_channels)) * 1.25) + 7200; + mp3_buffer_size = + ((GST_BUFFER_SIZE (buf) / (2 + lame->num_channels)) * 1.25) + 7200; mp3_data = g_malloc (mp3_buffer_size); if (lame->num_channels == 2) { - mp3_size = lame_encode_buffer_interleaved (lame->lgf, - (short int *) (GST_BUFFER_DATA (buf)), - GST_BUFFER_SIZE (buf) / 4, - mp3_data, mp3_buffer_size); - } - else { - mp3_size = lame_encode_buffer (lame->lgf, - (short int *) (GST_BUFFER_DATA (buf)), - (short int *) (GST_BUFFER_DATA (buf)), - GST_BUFFER_SIZE (buf) / 2, - mp3_data, mp3_buffer_size); + mp3_size = lame_encode_buffer_interleaved (lame->lgf, + (short int *) (GST_BUFFER_DATA (buf)), + GST_BUFFER_SIZE (buf) / 4, mp3_data, mp3_buffer_size); + } else { + mp3_size = lame_encode_buffer (lame->lgf, + (short int *) (GST_BUFFER_DATA (buf)), + (short int *) (GST_BUFFER_DATA (buf)), + GST_BUFFER_SIZE (buf) / 2, mp3_data, mp3_buffer_size); } - GST_DEBUG ( - "encoded %d bytes of audio to %d bytes of mp3", - GST_BUFFER_SIZE (buf), mp3_size); + GST_DEBUG ("encoded %d bytes of audio to %d bytes of mp3", + GST_BUFFER_SIZE (buf), mp3_size); duration = (GST_SECOND * GST_BUFFER_SIZE (buf) / - (2 * lame->samplerate * lame->num_channels)); + (2 * lame->samplerate * lame->num_channels)); if (GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE && GST_BUFFER_DURATION (buf) != duration) - GST_DEBUG ( - "mad: incoming buffer had incorrect duration %lld, " - "outgoing buffer will have correct duration %lld", - GST_BUFFER_DURATION (buf), duration); + GST_DEBUG ("mad: incoming buffer had incorrect duration %lld, " + "outgoing buffer will have correct duration %lld", + GST_BUFFER_DURATION (buf), duration); if (lame->last_ts == GST_CLOCK_TIME_NONE) { - lame->last_ts = GST_BUFFER_TIMESTAMP (buf); - lame->last_offs = GST_BUFFER_OFFSET (buf); + lame->last_ts = GST_BUFFER_TIMESTAMP (buf); + lame->last_offs = GST_BUFFER_OFFSET (buf); lame->last_duration = duration; } else { lame->last_duration += duration; @@ -832,20 +827,19 @@ gst_lame_chain (GstPad *pad, GstData *_data) gst_buffer_unref (buf); } - + if (mp3_size > 0) { outbuf = gst_buffer_new (); - GST_BUFFER_DATA (outbuf) = mp3_data; - GST_BUFFER_SIZE (outbuf) = mp3_size; + GST_BUFFER_DATA (outbuf) = mp3_data; + GST_BUFFER_SIZE (outbuf) = mp3_size; GST_BUFFER_TIMESTAMP (outbuf) = lame->last_ts; - GST_BUFFER_OFFSET (outbuf) = lame->last_offs; - GST_BUFFER_DURATION (outbuf) = lame->last_duration; + GST_BUFFER_OFFSET (outbuf) = lame->last_offs; + GST_BUFFER_DURATION (outbuf) = lame->last_duration; - gst_pad_push (lame->srcpad,GST_DATA (outbuf)); + gst_pad_push (lame->srcpad, GST_DATA (outbuf)); lame->last_ts = GST_CLOCK_TIME_NONE; - } - else { + } else { g_free (mp3_data); } @@ -857,7 +851,7 @@ gst_lame_chain (GstPad *pad, GstData *_data) /* transition to the READY state by configuring the gst_lame encoder */ static gboolean -gst_lame_setup (GstLame *lame) +gst_lame_setup (GstLame * lame) { GST_DEBUG_OBJECT (lame, "starting setup"); @@ -871,7 +865,7 @@ gst_lame_setup (GstLame *lame) lame_set_in_samplerate (lame->lgf, lame->samplerate); /* force mono encoding if we only have one channel */ - if (lame->num_channels == 1) + if (lame->num_channels == 1) lame->mode = 3; lame_set_brate (lame->lgf, lame->bitrate); @@ -910,13 +904,11 @@ gst_lame_setup (GstLame *lame) /* initialize the lame encoder */ if (lame_init_params (lame->lgf) < 0) { lame->initialized = FALSE; - } - else { + } else { lame->initialized = TRUE; /* FIXME: it would be nice to print out the mode here */ - GST_INFO ( - "lame encoder initialized (%d kbit/s, %d Hz, %d channels)", - lame->bitrate, lame->samplerate, lame->num_channels); + GST_INFO ("lame encoder initialized (%d kbit/s, %d Hz, %d channels)", + lame->bitrate, lame->samplerate, lame->num_channels); } GST_DEBUG_OBJECT (lame, "done with setup"); @@ -925,10 +917,10 @@ gst_lame_setup (GstLame *lame) } static GstElementStateReturn -gst_lame_change_state (GstElement *element) +gst_lame_change_state (GstElement * element) { GstLame *lame; - + g_return_val_if_fail (GST_IS_LAME (element), GST_STATE_FAILURE); lame = GST_LAME (element); @@ -941,7 +933,7 @@ gst_lame_change_state (GstElement *element) break; case GST_STATE_READY_TO_NULL: if (lame->initialized) { - lame_close (lame->lgf); + lame_close (lame->lgf); lame->initialized = FALSE; } break; @@ -957,21 +949,16 @@ gst_lame_change_state (GstElement *element) } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { if (!gst_element_register (plugin, "lame", GST_RANK_NONE, GST_TYPE_LAME)) return FALSE; - + return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "lame", - "Encode MP3's with LAME", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "lame", + "Encode MP3's with LAME", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/lame/gstlame.h b/ext/lame/gstlame.h index 4a0cfdcff7..abe1c0d44b 100644 --- a/ext/lame/gstlame.h +++ b/ext/lame/gstlame.h @@ -25,8 +25,9 @@ #include #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #include @@ -41,73 +42,76 @@ extern "C" { #define GST_IS_LAME_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_LAME)) -typedef enum { - GST_LAME_OPEN = GST_ELEMENT_FLAG_LAST, + typedef enum + { + GST_LAME_OPEN = GST_ELEMENT_FLAG_LAST, - GST_LAME_FLAG_LAST = GST_ELEMENT_FLAG_LAST+2, -} GstLameFlags; + GST_LAME_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2, + } GstLameFlags; -typedef struct _GstLame GstLame; -typedef struct _GstLameClass GstLameClass; + typedef struct _GstLame GstLame; + typedef struct _GstLameClass GstLameClass; -struct _GstLame { - GstElement element; - /* pads */ - GstPad *srcpad, *sinkpad; + struct _GstLame + { + GstElement element; + /* pads */ + GstPad *srcpad, *sinkpad; - gint samplerate; - gint num_channels; - gboolean initialized; + gint samplerate; + gint num_channels; + gboolean initialized; - gint bitrate; - gfloat compression_ratio; - gint quality; - gint mode; - gboolean force_ms; - gboolean free_format; - gboolean copyright; - gboolean original; - gboolean error_protection; - gint padding_type; - gboolean extension; - gboolean strict_iso; - gboolean disable_reservoir; - gboolean vbr; - gint vbr_mean_bitrate; - gint vbr_min_bitrate; - gint vbr_max_bitrate; - gint vbr_hard_min; - gint lowpass_freq; - gint lowpass_width; - gint highpass_freq; - gint highpass_width; - gboolean ath_only; - gboolean ath_short; - gboolean no_ath; - gint ath_type; - gint ath_lower; - gint cwlimit; - gboolean allow_diff_short; - gboolean no_short_blocks; - gboolean emphasis; + gint bitrate; + gfloat compression_ratio; + gint quality; + gint mode; + gboolean force_ms; + gboolean free_format; + gboolean copyright; + gboolean original; + gboolean error_protection; + gint padding_type; + gboolean extension; + gboolean strict_iso; + gboolean disable_reservoir; + gboolean vbr; + gint vbr_mean_bitrate; + gint vbr_min_bitrate; + gint vbr_max_bitrate; + gint vbr_hard_min; + gint lowpass_freq; + gint lowpass_width; + gint highpass_freq; + gint highpass_width; + gboolean ath_only; + gboolean ath_short; + gboolean no_ath; + gint ath_type; + gint ath_lower; + gint cwlimit; + gboolean allow_diff_short; + gboolean no_short_blocks; + gboolean emphasis; - lame_global_flags *lgf; + lame_global_flags *lgf; - GstTagList *tags; + GstTagList *tags; - /* time tracker */ - guint64 last_ts, last_offs, last_duration; -}; + /* time tracker */ + guint64 last_ts, last_offs, last_duration; + }; -struct _GstLameClass { - GstElementClass parent_class; -}; + struct _GstLameClass + { + GstElementClass parent_class; + }; -GType gst_lame_get_type(void); + GType gst_lame_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_LAME_H__ */ +#endif /* __GST_LAME_H__ */ diff --git a/ext/lame/test-lame.c b/ext/lame/test-lame.c index 417f6c2ab6..5145e8cb73 100644 --- a/ext/lame/test-lame.c +++ b/ext/lame/test-lame.c @@ -12,12 +12,12 @@ */ static void -error_callback (GObject *object, GstObject *orig, gchar *error) +error_callback (GObject * object, GstObject * orig, gchar * error) { - g_print ("ERROR: %s: %s\n", GST_OBJECT_NAME (orig), error); + g_print ("ERROR: %s: %s\n", GST_OBJECT_NAME (orig), error); } -int +int main (int argc, char *argv[]) { GstElement *pipeline; @@ -29,13 +29,20 @@ main (int argc, char *argv[]) gst_init (&argc, &argv); /* create elements */ - if (!(pipeline = gst_element_factory_make ("pipeline", "pipeline"))) return 1; - if (!(src = gst_element_factory_make ("fakesrc", "source"))) return 1; - if (!(tee = gst_element_factory_make ("tee", "tee"))) return 1; - if (!(encoder1 = gst_element_factory_make ("lame", "lame1"))) return 1; - if (!(encoder2 = gst_element_factory_make ("lame", "lame2"))) return 1; - if (!(sink1 = gst_element_factory_make ("fakesink", "sink1"))) return 1; - if (!(sink2 = gst_element_factory_make ("fakesink", "sink2"))) return 1; + if (!(pipeline = gst_element_factory_make ("pipeline", "pipeline"))) + return 1; + if (!(src = gst_element_factory_make ("fakesrc", "source"))) + return 1; + if (!(tee = gst_element_factory_make ("tee", "tee"))) + return 1; + if (!(encoder1 = gst_element_factory_make ("lame", "lame1"))) + return 1; + if (!(encoder2 = gst_element_factory_make ("lame", "lame2"))) + return 1; + if (!(sink1 = gst_element_factory_make ("fakesink", "sink1"))) + return 1; + if (!(sink2 = gst_element_factory_make ("fakesink", "sink2"))) + return 1; pipeline = gst_pipeline_new ("pipeline"); g_signal_connect (pipeline, "error", G_CALLBACK (error_callback), NULL); @@ -45,34 +52,31 @@ main (int argc, char *argv[]) gst_bin_add (GST_BIN (pipeline), src); gst_bin_add (GST_BIN (pipeline), tee); gst_pad_link (gst_element_get_pad (src, "src"), - gst_element_get_pad (tee, "sink")); + gst_element_get_pad (tee, "sink")); /* set up fakesrc */ g_object_set (G_OBJECT (src), "filltype", 3, NULL); g_object_set (G_OBJECT (src), "sizetype", 3, NULL); /* set caps on fakesrc */ - caps = GST_CAPS_NEW ( - "input audio", + caps = GST_CAPS_NEW ("input audio", "audio/raw", "format", GST_PROPS_STRING ("int"), "rate", GST_PROPS_INT (44100), "width", GST_PROPS_INT (16), "depth", GST_PROPS_INT (16), "law", GST_PROPS_INT (0), - "signed", GST_PROPS_BOOLEAN (TRUE), - "channels", GST_PROPS_INT (1) + "signed", GST_PROPS_BOOLEAN (TRUE), "channels", GST_PROPS_INT (1) ); - g_object_set (G_OBJECT (src), "sizetype", 3, - "filltype", 3, NULL); + g_object_set (G_OBJECT (src), "sizetype", 3, "filltype", 3, NULL); + - gst_element_set_state (pipeline, GST_STATE_READY); g_print ("Setting caps on fakesrc's src pad\n"); if (gst_pad_try_set_caps (gst_element_get_pad (src, "src"), caps) <= 0) - g_print ("Could not set caps !\n"); - + g_print ("Could not set caps !\n"); + /* request first pad from tee and connect */ g_print ("attaching first output pipe to tee\n"); teepad1 = gst_element_request_pad_by_name (tee, "src%d"); @@ -81,8 +85,8 @@ main (int argc, char *argv[]) gst_bin_add (GST_BIN (pipeline), sink1); gst_pad_link (teepad1, gst_element_get_pad (encoder1, "sink")); gst_pad_link (gst_element_get_pad (encoder1, "src"), - gst_element_get_pad (sink1, "sink")); - + gst_element_get_pad (sink1, "sink")); + gst_element_set_state (pipeline, GST_STATE_PLAYING); /* iterate */ g_print ("iterate\n"); @@ -97,7 +101,7 @@ main (int argc, char *argv[]) gst_bin_add (GST_BIN (pipeline), sink2); gst_pad_link (teepad2, gst_element_get_pad (encoder2, "sink")); gst_pad_link (gst_element_get_pad (encoder2, "src"), - gst_element_get_pad (sink2, "sink")); + gst_element_get_pad (sink2, "sink")); gst_element_set_state (pipeline, GST_STATE_PLAYING); g_print ("iterate\n"); diff --git a/ext/mad/gstid3tag.c b/ext/mad/gstid3tag.c index c56e157bbf..59b7924351 100644 --- a/ext/mad/gstid3tag.c +++ b/ext/mad/gstid3tag.c @@ -39,7 +39,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_id3_tag_debug); typedef struct _GstID3Tag GstID3Tag; typedef struct _GstID3TagClass GstID3TagClass; -typedef enum { +typedef enum +{ GST_ID3_TAG_STATE_READING_V2_TAG, GST_ID3_TAG_STATE_SEEKING_TO_V1_TAG, GST_ID3_TAG_STATE_READING_V1_TAG, @@ -48,117 +49,112 @@ typedef enum { GST_ID3_TAG_STATE_NORMAL, } GstID3TagState; -typedef enum { +typedef enum +{ GST_ID3_TAG_PARSE_UNKNOWN, GST_ID3_TAG_PARSE_TAG, GST_ID3_TAG_PARSE_WRITE, GST_ID3_TAG_PARSE_PARSE } GstID3ParseMode; -struct _GstID3Tag { - GstElement element; +struct _GstID3Tag +{ + GstElement element; /* pads */ - GstPad * sinkpad; - GstPad * srcpad; + GstPad *sinkpad; + GstPad *srcpad; /* caps */ - GstID3ParseMode parse_mode; - GstCaps * found_caps; + GstID3ParseMode parse_mode; + GstCaps *found_caps; /* tags */ - GstTagList * event_tags; - GstTagList * parsed_tags; + GstTagList *event_tags; + GstTagList *parsed_tags; /* state */ - GstID3TagState state; + GstID3TagState state; - GstBuffer * buffer; - gboolean prefer_v1tag; - glong v1tag_size; - glong v1tag_size_new; - guint64 v1tag_offset; - gboolean v1tag_render; - glong v2tag_size; - glong v2tag_size_new; - gboolean v2tag_render; + GstBuffer *buffer; + gboolean prefer_v1tag; + glong v1tag_size; + glong v1tag_size_new; + guint64 v1tag_offset; + gboolean v1tag_render; + glong v2tag_size; + glong v2tag_size_new; + gboolean v2tag_render; }; -struct _GstID3TagClass { +struct _GstID3TagClass +{ GstElementClass parent_class; }; /* elementfactory information */ -static GstElementDetails gst_id3_tag_details = GST_ELEMENT_DETAILS ( - "id3 tag extractor", - "Tag", - "Extract tagging information from mp3s", - "Benjamin Otte " -); +static GstElementDetails gst_id3_tag_details = +GST_ELEMENT_DETAILS ("id3 tag extractor", + "Tag", + "Extract tagging information from mp3s", + "Benjamin Otte "); /* signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_V1_TAG, ARG_V2_TAG, ARG_PREFER_V1 - /* FILL ME */ + /* FILL ME */ }; static GstStaticPadTemplate id3_tag_src_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, /* FIXME: for spider - GST_PAD_ALWAYS, */ - GST_PAD_SOMETIMES, - GST_STATIC_CAPS ("ANY") -); + GST_PAD_SOMETIMES, + GST_STATIC_CAPS ("ANY") + ); static GstStaticPadTemplate id3_tag_sink_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-id3") -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("application/x-id3") + ); -static void gst_id3_tag_base_init (gpointer g_class); -static void gst_id3_tag_class_init (GstID3TagClass * klass); -static void gst_id3_tag_init (GstID3Tag * tag); -static void gst_id3_tag_set_property (GObject * object, - guint prop_id, - const GValue * value, - GParamSpec * pspec); -static void gst_id3_tag_get_property (GObject * object, - guint prop_id, - GValue * value, - GParamSpec * pspec); +static void gst_id3_tag_base_init (gpointer g_class); +static void gst_id3_tag_class_init (GstID3TagClass * klass); +static void gst_id3_tag_init (GstID3Tag * tag); +static void gst_id3_tag_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec); +static void gst_id3_tag_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); -static gboolean gst_id3_tag_src_event (GstPad * pad, - GstEvent * event); -static const GstEventMask* gst_id3_tag_get_event_masks (GstPad * pad); -static const GstQueryType* gst_id3_tag_get_query_types (GstPad * pad); +static gboolean gst_id3_tag_src_event (GstPad * pad, GstEvent * event); +static const GstEventMask *gst_id3_tag_get_event_masks (GstPad * pad); +static const GstQueryType *gst_id3_tag_get_query_types (GstPad * pad); -static gboolean gst_id3_tag_src_query (GstPad * pad, - GstQueryType type, - GstFormat * format, - gint64 * value); +static gboolean gst_id3_tag_src_query (GstPad * pad, + GstQueryType type, GstFormat * format, gint64 * value); -static void gst_id3_tag_chain (GstPad * pad, - GstData * data); -static GstPadLinkReturn gst_id3_tag_src_link (GstPad * pad, - const GstCaps * caps); +static void gst_id3_tag_chain (GstPad * pad, GstData * data); +static GstPadLinkReturn gst_id3_tag_src_link (GstPad * pad, + const GstCaps * caps); -static GstElementStateReturn gst_id3_tag_change_state (GstElement * element); +static GstElementStateReturn gst_id3_tag_change_state (GstElement * element); static GstElementClass *parent_class = NULL; + /* static guint gst_id3_tag_signals[LAST_SIGNAL] = { 0 }; */ GType @@ -183,12 +179,16 @@ gst_id3_tag_get_type (void) NULL, NULL }; - - id3_tag_type = g_type_register_static(GST_TYPE_ELEMENT, "GstID3Tag", &id3_tag_info, 0); - g_type_add_interface_static (id3_tag_type, GST_TYPE_TAG_SETTER, &tag_setter_info); - - GST_DEBUG_CATEGORY_INIT (gst_id3_tag_debug, "id3tag", 0, "id3 tag reader / setter"); + id3_tag_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstID3Tag", &id3_tag_info, + 0); + + g_type_add_interface_static (id3_tag_type, GST_TYPE_TAG_SETTER, + &tag_setter_info); + + GST_DEBUG_CATEGORY_INIT (gst_id3_tag_debug, "id3tag", 0, + "id3 tag reader / setter"); } return id3_tag_type; } @@ -200,44 +200,48 @@ gst_id3_tag_base_init (gpointer g_class) gst_element_class_set_details (element_class, &gst_id3_tag_details); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&id3_tag_sink_template_factory)); + gst_static_pad_template_get (&id3_tag_sink_template_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&id3_tag_src_template_factory)); + gst_static_pad_template_get (&id3_tag_src_template_factory)); } static void -gst_id3_tag_class_init (GstID3TagClass *klass) +gst_id3_tag_class_init (GstID3TagClass * klass) { GstElementClass *gstelement_class; GObjectClass *gobject_class; - - gstelement_class = (GstElementClass*) klass; - gobject_class = (GObjectClass*) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + gstelement_class = (GstElementClass *) klass; + gobject_class = (GObjectClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gstelement_class->change_state = gst_id3_tag_change_state; g_object_class_install_property (gobject_class, ARG_V1_TAG, - g_param_spec_boolean ("v1-tag", "add version 1 tag", "Add version 1 tag at end of file", - FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_param_spec_boolean ("v1-tag", "add version 1 tag", + "Add version 1 tag at end of file", FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, ARG_V2_TAG, - g_param_spec_boolean ("v2-tag", "add version 2 tag", "Add version 2 tag at start of file", - TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_param_spec_boolean ("v2-tag", "add version 2 tag", + "Add version 2 tag at start of file", TRUE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, ARG_PREFER_V1, - g_param_spec_boolean ("prefer-v1", "prefer version 1 tag", "Prefer tags from tag at end of file", - FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - + g_param_spec_boolean ("prefer-v1", "prefer version 1 tag", + "Prefer tags from tag at end of file", FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_id3_tag_set_property); gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_id3_tag_get_property); } static GstCaps * -gst_id3_tag_get_caps (GstPad *pad) +gst_id3_tag_get_caps (GstPad * pad) { GstID3Tag *tag = GST_ID3_TAG (gst_pad_get_parent (pad)); if (tag->found_caps) { GstCaps *caps; + caps = gst_caps_from_string ("application/x-gst-tags; application/x-id3"); gst_caps_append (caps, gst_caps_copy (tag->found_caps)); return caps; @@ -247,55 +251,65 @@ gst_id3_tag_get_caps (GstPad *pad) } static void -gst_id3_tag_add_src_pad (GstID3Tag *tag) +gst_id3_tag_add_src_pad (GstID3Tag * tag) { g_assert (tag->srcpad == NULL); - tag->srcpad = gst_pad_new_from_template (gst_static_pad_template_get ( - &id3_tag_src_template_factory), "src"); - gst_pad_set_event_function (tag->srcpad, GST_DEBUG_FUNCPTR (gst_id3_tag_src_event)); - gst_pad_set_event_mask_function (tag->srcpad, GST_DEBUG_FUNCPTR (gst_id3_tag_get_event_masks)); - gst_pad_set_query_function (tag->srcpad, GST_DEBUG_FUNCPTR (gst_id3_tag_src_query)); - gst_pad_set_query_type_function (tag->srcpad, GST_DEBUG_FUNCPTR (gst_id3_tag_get_query_types)); - gst_pad_set_getcaps_function (tag->srcpad, GST_DEBUG_FUNCPTR (gst_id3_tag_get_caps)); - gst_pad_set_link_function (tag->srcpad, GST_DEBUG_FUNCPTR (gst_id3_tag_src_link)); + tag->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&id3_tag_src_template_factory), "src"); + gst_pad_set_event_function (tag->srcpad, + GST_DEBUG_FUNCPTR (gst_id3_tag_src_event)); + gst_pad_set_event_mask_function (tag->srcpad, + GST_DEBUG_FUNCPTR (gst_id3_tag_get_event_masks)); + gst_pad_set_query_function (tag->srcpad, + GST_DEBUG_FUNCPTR (gst_id3_tag_src_query)); + gst_pad_set_query_type_function (tag->srcpad, + GST_DEBUG_FUNCPTR (gst_id3_tag_get_query_types)); + gst_pad_set_getcaps_function (tag->srcpad, + GST_DEBUG_FUNCPTR (gst_id3_tag_get_caps)); + gst_pad_set_link_function (tag->srcpad, + GST_DEBUG_FUNCPTR (gst_id3_tag_src_link)); gst_element_add_pad (GST_ELEMENT (tag), tag->srcpad); } static void -gst_id3_tag_init (GstID3Tag *tag) +gst_id3_tag_init (GstID3Tag * tag) { /* create the sink and src pads */ - tag->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&id3_tag_sink_template_factory), "sink"); + tag->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&id3_tag_sink_template_factory), "sink"); gst_element_add_pad (GST_ELEMENT (tag), tag->sinkpad); - gst_pad_set_chain_function (tag->sinkpad, GST_DEBUG_FUNCPTR (gst_id3_tag_chain)); + gst_pad_set_chain_function (tag->sinkpad, + GST_DEBUG_FUNCPTR (gst_id3_tag_chain)); /* FIXME: for the alli^H^H^H^Hspider - gst_id3_tag_add_src_pad (tag); */ tag->state = GST_ID3_TAG_STATE_READING_V2_TAG; tag->parse_mode = GST_ID3_TAG_PARSE_UNKNOWN; tag->buffer = NULL; - + GST_FLAG_SET (tag, GST_ELEMENT_EVENT_AWARE); } static void -gst_id3_tag_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_id3_tag_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { GstID3Tag *tag; - + tag = GST_ID3_TAG (object); - + switch (prop_id) { case ARG_V1_TAG: tag->v1tag_render = g_value_get_boolean (value); - g_object_notify (object, "v1-tag"); + g_object_notify (object, "v1-tag"); break; case ARG_V2_TAG: tag->v2tag_render = g_value_get_boolean (value); - g_object_notify (object, "v2-tag"); + g_object_notify (object, "v2-tag"); break; case ARG_PREFER_V1: tag->prefer_v1tag = g_value_get_boolean (value); - g_object_notify (object, "prefer-v1"); + g_object_notify (object, "prefer-v1"); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -303,11 +317,13 @@ gst_id3_tag_set_property (GObject *object, guint prop_id, const GValue *value, G } } static void -gst_id3_tag_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_id3_tag_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { - GstID3Tag *tag; + GstID3Tag *tag; + tag = GST_ID3_TAG (object); - + switch (prop_id) { case ARG_V1_TAG: g_value_set_boolean (value, tag->v1tag_render); @@ -323,22 +339,22 @@ gst_id3_tag_get_property (GObject *object, guint prop_id, GValue *value, GParamS break; } } + #define gst_id3_tag_set_state(tag,new_state) G_STMT_START { \ GST_LOG_OBJECT (tag, "setting state to %s", #new_state ); \ tag->state = new_state; \ }G_STMT_END -static const GstEventMask* -gst_id3_tag_get_event_masks (GstPad *pad) +static const GstEventMask * +gst_id3_tag_get_event_masks (GstPad * pad) { static const GstEventMask gst_id3_tag_src_event_masks[] = { - { GST_EVENT_SEEK, GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH }, - { 0, } + {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH}, + {0,} }; return gst_id3_tag_src_event_masks; } -static const GstQueryType* -gst_id3_tag_get_query_types (GstPad *pad) +static const GstQueryType * +gst_id3_tag_get_query_types (GstPad * pad) { static const GstQueryType gst_id3_tag_src_query_types[] = { GST_QUERY_TOTAL, @@ -349,8 +365,8 @@ gst_id3_tag_get_query_types (GstPad *pad) } static gboolean -gst_id3_tag_src_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value) +gst_id3_tag_src_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value) { gboolean res = FALSE; GstID3Tag *tag; @@ -358,12 +374,13 @@ gst_id3_tag_src_query (GstPad *pad, GstQueryType type, tag = GST_ID3_TAG (gst_pad_get_parent (pad)); switch (type) { - case GST_QUERY_TOTAL: { + case GST_QUERY_TOTAL:{ switch (*format) { - case GST_FORMAT_BYTES: - if (GST_PAD_PEER (tag->sinkpad) && - tag->state == GST_ID3_TAG_STATE_NORMAL && - gst_pad_query (GST_PAD_PEER (tag->sinkpad), GST_QUERY_TOTAL, format, value)) { + case GST_FORMAT_BYTES: + if (GST_PAD_PEER (tag->sinkpad) && + tag->state == GST_ID3_TAG_STATE_NORMAL && + gst_pad_query (GST_PAD_PEER (tag->sinkpad), GST_QUERY_TOTAL, + format, value)) { *value -= tag->v2tag_size + tag->v1tag_size; *value += tag->v2tag_size_new + tag->v1tag_size_new; res = TRUE; @@ -378,7 +395,8 @@ gst_id3_tag_src_query (GstPad *pad, GstQueryType type, switch (*format) { case GST_FORMAT_BYTES: if (GST_PAD_PEER (tag->sinkpad) && - gst_pad_query (GST_PAD_PEER (tag->sinkpad), GST_QUERY_POSITION, format, value)) { + gst_pad_query (GST_PAD_PEER (tag->sinkpad), GST_QUERY_POSITION, + format, value)) { if (tag->state == GST_ID3_TAG_STATE_NORMAL) { *value -= tag->v2tag_size + tag->v2tag_size_new; } else { @@ -398,7 +416,7 @@ gst_id3_tag_src_query (GstPad *pad, GstQueryType type, } static gboolean -gst_id3_tag_src_event (GstPad *pad, GstEvent *event) +gst_id3_tag_src_event (GstPad * pad, GstEvent * event) { GstID3Tag *tag; @@ -406,20 +424,29 @@ gst_id3_tag_src_event (GstPad *pad, GstEvent *event) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_SEEK: - if (GST_EVENT_SEEK_FORMAT (event) == GST_FORMAT_BYTES && - tag->state == GST_ID3_TAG_STATE_NORMAL && + if (GST_EVENT_SEEK_FORMAT (event) == GST_FORMAT_BYTES && + tag->state == GST_ID3_TAG_STATE_NORMAL && GST_PAD_PEER (tag->sinkpad)) { GstEvent *new; gint diff = 0; switch (GST_EVENT_SEEK_METHOD (event)) { - case GST_SEEK_METHOD_SET: diff = tag->v2tag_size_new - tag->v2tag_size; break; - case GST_SEEK_METHOD_CUR: break; - case GST_SEEK_METHOD_END: diff = GST_EVENT_SEEK_OFFSET(event) ? tag->v1tag_size_new - tag->v1tag_size : 0; break; - default: g_assert_not_reached(); break; + case GST_SEEK_METHOD_SET: + diff = tag->v2tag_size_new - tag->v2tag_size; + break; + case GST_SEEK_METHOD_CUR: + break; + case GST_SEEK_METHOD_END: + diff = + GST_EVENT_SEEK_OFFSET (event) ? tag->v1tag_size_new - + tag->v1tag_size : 0; + break; + default: + g_assert_not_reached (); + break; } - new = gst_event_new_seek (GST_EVENT_SEEK_TYPE (event), - GST_EVENT_SEEK_OFFSET(event) + diff); + new = gst_event_new_seek (GST_EVENT_SEEK_TYPE (event), + GST_EVENT_SEEK_OFFSET (event) + diff); gst_event_unref (event); return gst_pad_send_event (GST_PAD_PEER (tag->sinkpad), new); } @@ -431,8 +458,9 @@ gst_id3_tag_src_event (GstPad *pad, GstEvent *event) gst_event_unref (event); return FALSE; } -GstTagList* -gst_mad_id3_to_tag_list(const struct id3_tag *tag) + +GstTagList * +gst_mad_id3_to_tag_list (const struct id3_tag * tag) { const struct id3_frame *frame; const id3_ucs4_t *ucs4; @@ -441,11 +469,12 @@ gst_mad_id3_to_tag_list(const struct id3_tag *tag) guint i = 0; tag_list = gst_tag_list_new (); - - while ((frame = id3_tag_findframe(tag, NULL, i++)) != NULL) { + + while ((frame = id3_tag_findframe (tag, NULL, i++)) != NULL) { const union id3_field *field; unsigned int nstrings, j; const gchar *tag_name; + /* find me the function to query the frame id */ gchar *id = g_strndup (frame->id, 5); @@ -455,20 +484,20 @@ gst_mad_id3_to_tag_list(const struct id3_tag *tag) continue; } - field = &frame->fields[1]; - nstrings = id3_field_getnstrings(field); - + field = &frame->fields[1]; + nstrings = id3_field_getnstrings (field); + for (j = 0; j < nstrings; ++j) { - ucs4 = id3_field_getstrings(field, j); - g_assert(ucs4); + ucs4 = id3_field_getstrings (field, j); + g_assert (ucs4); - if (strcmp(id, ID3_FRAME_GENRE) == 0) - ucs4 = id3_genre_name(ucs4); + if (strcmp (id, ID3_FRAME_GENRE) == 0) + ucs4 = id3_genre_name (ucs4); - utf8 = id3_ucs4_utf8duplicate(ucs4); + utf8 = id3_ucs4_utf8duplicate (ucs4); if (utf8 == 0) continue; - + if (!g_utf8_validate (utf8, -1, NULL)) { g_warning ("converted string is not valid utf-8"); free (utf8); @@ -487,64 +516,74 @@ gst_mad_id3_to_tag_list(const struct id3_tag *tag) if (strcmp (tag_name, GST_TAG_DATE) == 0) { GDate *d; - if (*check != '\0') break; - if (tmp == 0) break; + if (*check != '\0') + break; + if (tmp == 0) + break; d = g_date_new_dmy (1, 1, tmp); tmp = g_date_get_julian (d); g_date_free (d); - } else if (strcmp(tag_name,GST_TAG_TRACK_NUMBER) == 0) { + } else if (strcmp (tag_name, GST_TAG_TRACK_NUMBER) == 0) { if (*check == '/') { guint total; check++; total = strtoul (check, &check, 10); - if (*check != '\0') break; + if (*check != '\0') + break; - gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_TRACK_COUNT, total, NULL); + gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, + GST_TAG_TRACK_COUNT, total, NULL); } - } else if (strcmp(tag_name,GST_TAG_ALBUM_VOLUME_NUMBER) == 0) { + } else if (strcmp (tag_name, GST_TAG_ALBUM_VOLUME_NUMBER) == 0) { if (*check == '/') { guint total; check++; total = strtoul (check, &check, 10); - if (*check != '\0') break; + if (*check != '\0') + break; - gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_ALBUM_VOLUME_COUNT, total, NULL); + gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, + GST_TAG_ALBUM_VOLUME_COUNT, total, NULL); } } - if (*check != '\0') break; - gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, tag_name, tmp, NULL); + if (*check != '\0') + break; + gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, tag_name, tmp, + NULL); break; } - case G_TYPE_UINT64: + case G_TYPE_UINT64: { guint64 tmp; - g_assert ((strcmp(tag_name,GST_TAG_DURATION) == 0)); + + g_assert ((strcmp (tag_name, GST_TAG_DURATION) == 0)); tmp = strtoul (utf8, NULL, 10); if (tmp == 0) { break; } - gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, - GST_TAG_DURATION, tmp*1000*1000, - NULL); + gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, + GST_TAG_DURATION, tmp * 1000 * 1000, NULL); break; } - default: + default: g_assert (gst_tag_get_type (tag_name) == G_TYPE_STRING); - gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, tag_name, utf8, NULL); + gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, tag_name, utf8, + NULL); break; } free (utf8); } g_free (id); } - + return tag_list; } static void -tag_list_to_id3_tag_foreach (const GstTagList *list, const gchar *tag_name, gpointer user_data) +tag_list_to_id3_tag_foreach (const GstTagList * list, const gchar * tag_name, + gpointer user_data) { struct id3_frame *frame; union id3_field *field; @@ -554,7 +593,7 @@ tag_list_to_id3_tag_foreach (const GstTagList *list, const gchar *tag_name, gpoi if (id == NULL) return; - + if (values == 0) return; @@ -575,7 +614,7 @@ tag_list_to_id3_tag_foreach (const GstTagList *list, const gchar *tag_name, gpoi gchar *str; guint u; GDate *d; - + g_assert (gst_tag_list_get_uint_index (list, tag_name, values, &u)); d = g_date_new_julian (u); str = g_strdup_printf ("%u", (guint) (g_date_get_year (d))); @@ -585,7 +624,7 @@ tag_list_to_id3_tag_foreach (const GstTagList *list, const gchar *tag_name, gpoi } else if (strcmp (tag_name, GST_TAG_TRACK_NUMBER) == 0) { gchar *str; guint u; - + g_assert (gst_tag_list_get_uint_index (list, tag_name, values, &u)); str = g_strdup_printf ("%u", u); put = g_utf8_to_ucs4_fast (str, -1, NULL); @@ -609,7 +648,7 @@ tag_list_to_id3_tag_foreach (const GstTagList *list, const gchar *tag_name, gpoi id3_field_settextencoding (field, ID3_FIELD_TEXTENCODING_UTF_8); } struct id3_tag * -gst_mad_tag_list_to_id3_tag (GstTagList *list) +gst_mad_tag_list_to_id3_tag (GstTagList * list) { struct id3_tag *tag; @@ -619,10 +658,10 @@ gst_mad_tag_list_to_id3_tag (GstTagList *list) return tag; } static GstTagList * -gst_id3_tag_get_tag_to_render (GstID3Tag *tag) +gst_id3_tag_get_tag_to_render (GstID3Tag * tag) { GstTagList *ret = NULL; - + if (tag->event_tags) ret = gst_tag_list_copy (tag->event_tags); if (ret) { @@ -632,26 +671,30 @@ gst_id3_tag_get_tag_to_render (GstID3Tag *tag) } if (ret && gst_tag_setter_get_list (GST_TAG_SETTER (tag))) { gst_tag_list_insert (ret, gst_tag_setter_get_list (GST_TAG_SETTER (tag)), - gst_tag_setter_get_merge_mode (GST_TAG_SETTER (tag))); + gst_tag_setter_get_merge_mode (GST_TAG_SETTER (tag))); } else if (gst_tag_setter_get_list (GST_TAG_SETTER (tag))) { ret = gst_tag_list_copy (gst_tag_setter_get_list (GST_TAG_SETTER (tag))); } return ret; } static void -gst_id3_tag_handle_event (GstPad *pad, GstEvent *event) +gst_id3_tag_handle_event (GstPad * pad, GstEvent * event) { GstID3Tag *tag = GST_ID3_TAG (gst_pad_get_parent (pad)); - + switch (GST_EVENT_TYPE (event)) { case GST_EVENT_DISCONTINUOUS: switch (tag->state) { - case GST_ID3_TAG_STATE_READING_V2_TAG: { + case GST_ID3_TAG_STATE_READING_V2_TAG:{ guint64 value; + gst_event_discont_get_value (event, GST_FORMAT_BYTES, &value); - if (value != (tag->buffer ? GST_BUFFER_OFFSET (tag->buffer) + GST_BUFFER_SIZE (tag->buffer) - : 0)) - GST_ELEMENT_ERROR (tag, CORE, EVENT, (NULL), ("Seek during ID3v2 tag reading")); + if (value != + (tag->buffer ? GST_BUFFER_OFFSET (tag->buffer) + + GST_BUFFER_SIZE (tag->buffer) + : 0)) + GST_ELEMENT_ERROR (tag, CORE, EVENT, (NULL), + ("Seek during ID3v2 tag reading")); gst_data_unref (GST_DATA (event)); break; } @@ -660,7 +703,8 @@ gst_id3_tag_handle_event (GstPad *pad, GstEvent *event) gst_id3_tag_set_state (tag, GST_ID3_TAG_STATE_READING_V1_TAG); break; case GST_ID3_TAG_STATE_READING_V1_TAG: - GST_ELEMENT_ERROR (tag, CORE, EVENT, (NULL), ("Seek during ID3v1 tag reading")); + GST_ELEMENT_ERROR (tag, CORE, EVENT, (NULL), + ("Seek during ID3v1 tag reading")); gst_data_unref (GST_DATA (event)); break; case GST_ID3_TAG_STATE_SEEKING_TO_NORMAL: @@ -671,10 +715,10 @@ gst_id3_tag_handle_event (GstPad *pad, GstEvent *event) GST_ERROR_OBJECT (tag, "tag event not sent, FIXME"); gst_id3_tag_set_state (tag, GST_ID3_TAG_STATE_NORMAL); /* fall through */ - case GST_ID3_TAG_STATE_NORMAL: { + case GST_ID3_TAG_STATE_NORMAL:{ gint64 value; GstEvent *new; - + if (gst_event_discont_get_value (event, GST_FORMAT_BYTES, &value)) { value += tag->v1tag_size; new = gst_event_new_discontinuous (GST_FORMAT_BYTES, value, 0); @@ -691,7 +735,8 @@ gst_id3_tag_handle_event (GstPad *pad, GstEvent *event) break; case GST_EVENT_TAG: if (tag->event_tags) { - gst_tag_list_insert (tag->event_tags, gst_event_tag_get_list (event), GST_TAG_MERGE_PREPEND); + gst_tag_list_insert (tag->event_tags, gst_event_tag_get_list (event), + GST_TAG_MERGE_PREPEND); } else { tag->event_tags = gst_tag_list_copy (gst_event_tag_get_list (event)); } @@ -725,7 +770,8 @@ gst_id3_tag_handle_event (GstPad *pad, GstEvent *event) } return; } -typedef struct { +typedef struct +{ guint best_probability; GstCaps *caps; GstBuffer *buffer; @@ -734,17 +780,17 @@ guint8 * simple_find_peek (gpointer data, gint64 offset, guint size) { SimpleTypeFind *find = (SimpleTypeFind *) data; - + if (offset < 0) return NULL; - + if (GST_BUFFER_SIZE (find->buffer) >= offset + size) { return GST_BUFFER_DATA (find->buffer) + offset; } return NULL; } static void -simple_find_suggest (gpointer data, guint probability, const GstCaps *caps) +simple_find_suggest (gpointer data, guint probability, const GstCaps * caps) { SimpleTypeFind *find = (SimpleTypeFind *) data; @@ -754,18 +800,18 @@ simple_find_suggest (gpointer data, guint probability, const GstCaps *caps) } } static GstCaps * -gst_id3_tag_do_typefind (GstID3Tag *tag, GstBuffer *buffer) +gst_id3_tag_do_typefind (GstID3Tag * tag, GstBuffer * buffer) { GList *walk, *type_list; SimpleTypeFind find; GstTypeFind gst_find; - + /* this will help us detecting the media stream type after * this id3 thingy... Please note that this is a cruel hack * for as long as spider doesn't support multi-type-finding. */ walk = type_list = gst_type_find_factory_get_list (); - + find.buffer = buffer; find.best_probability = 0; find.caps = NULL; @@ -774,7 +820,7 @@ gst_id3_tag_do_typefind (GstID3Tag *tag, GstBuffer *buffer) gst_find.suggest = simple_find_suggest; while (walk) { GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walk->data); - + gst_type_find_factory_call_function (factory, &gst_find); if (find.best_probability >= GST_TYPE_FIND_MAXIMUM) break; @@ -789,13 +835,13 @@ gst_id3_tag_do_typefind (GstID3Tag *tag, GstBuffer *buffer) } } static gboolean -gst_id3_tag_do_caps_nego (GstID3Tag *tag, GstBuffer *buffer) +gst_id3_tag_do_caps_nego (GstID3Tag * tag, GstBuffer * buffer) { if (buffer != NULL) { tag->found_caps = gst_id3_tag_do_typefind (tag, buffer); if (!tag->found_caps) { return FALSE; - } + } } if (!tag->srcpad) gst_id3_tag_add_src_pad (tag); @@ -808,7 +854,7 @@ gst_id3_tag_do_caps_nego (GstID3Tag *tag, GstBuffer *buffer) } static GstPadLinkReturn -gst_id3_tag_src_link (GstPad *pad, const GstCaps *caps) +gst_id3_tag_src_link (GstPad * pad, const GstCaps * caps) { GstID3Tag *tag; const gchar *mimetype; @@ -817,7 +863,7 @@ gst_id3_tag_src_link (GstPad *pad, const GstCaps *caps) if (!tag->found_caps) return GST_PAD_LINK_DELAYED; - + mimetype = gst_structure_get_name (gst_caps_get_structure (caps, 0)); if (strcmp (mimetype, "application/x-id3") == 0) { @@ -828,24 +874,24 @@ gst_id3_tag_src_link (GstPad *pad, const GstCaps *caps) GST_LOG_OBJECT (tag, "fast operation, just outputting tags"); } else { tag->parse_mode = GST_ID3_TAG_PARSE_PARSE; - GST_LOG_OBJECT (tag, "parsing operation, extracting tags"); + GST_LOG_OBJECT (tag, "parsing operation, extracting tags"); } return GST_PAD_LINK_OK; } static void -gst_id3_tag_send_tag_event (GstID3Tag *tag) +gst_id3_tag_send_tag_event (GstID3Tag * tag) { /* FIXME: what's the correct merge mode? Docs need to tell... */ - GstTagList *merged = gst_tag_list_merge (tag->event_tags, tag->parsed_tags, GST_TAG_MERGE_KEEP); - + GstTagList *merged = gst_tag_list_merge (tag->event_tags, tag->parsed_tags, + GST_TAG_MERGE_KEEP); + if (merged) { - gst_element_found_tags_for_pad (GST_ELEMENT (tag), tag->srcpad, 0, - merged); + gst_element_found_tags_for_pad (GST_ELEMENT (tag), tag->srcpad, 0, merged); } } static void -gst_id3_tag_chain (GstPad *pad, GstData *data) +gst_id3_tag_chain (GstPad * pad, GstData * data) { GstID3Tag *tag; GstBuffer *buffer; @@ -868,6 +914,7 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) case GST_ID3_TAG_STATE_READING_V1_TAG: if (tag->buffer) { GstBuffer *temp; + temp = gst_buffer_merge (tag->buffer, buffer); gst_data_unref (GST_DATA (tag->buffer)); tag->buffer = temp; @@ -880,7 +927,7 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) return; g_assert (tag->v1tag_size == 0); tag->v1tag_size = id3_tag_query (GST_BUFFER_DATA (tag->buffer), - GST_BUFFER_SIZE (tag->buffer)); + GST_BUFFER_SIZE (tag->buffer)); if (tag->v1tag_size == 128) { GstTagList *newtag; @@ -890,7 +937,7 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) if (tag->parsed_tags) { /* FIXME: use append/prepend here ? */ gst_tag_list_insert (tag->parsed_tags, newtag, - tag->prefer_v1tag ? GST_TAG_MERGE_REPLACE : GST_TAG_MERGE_KEEP); + tag->prefer_v1tag ? GST_TAG_MERGE_REPLACE : GST_TAG_MERGE_KEEP); gst_tag_list_free (newtag); } else { tag->parsed_tags = newtag; @@ -901,7 +948,8 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) } else if (tag->v1tag_size != 0) { GST_WARNING_OBJECT (tag, "bad non-ID3v1 tag at end of file"); } else { - GST_LOG_OBJECT (tag, "no ID3v1 tag (%"G_GUINT64_FORMAT")", GST_BUFFER_OFFSET (tag->buffer)); + GST_LOG_OBJECT (tag, "no ID3v1 tag (%" G_GUINT64_FORMAT ")", + GST_BUFFER_OFFSET (tag->buffer)); } gst_data_unref (GST_DATA (tag->buffer)); tag->buffer = NULL; @@ -909,24 +957,26 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) /* seek to beginning */ GST_LOG_OBJECT (tag, "seeking back to beginning"); if (gst_pad_send_event (GST_PAD_PEER (tag->sinkpad), - gst_event_new_seek (GST_FORMAT_BYTES | GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, tag->v2tag_size))) { + gst_event_new_seek (GST_FORMAT_BYTES | GST_SEEK_METHOD_SET | + GST_SEEK_FLAG_FLUSH, tag->v2tag_size))) { gst_id3_tag_set_state (tag, GST_ID3_TAG_STATE_SEEKING_TO_NORMAL); } else { - GST_ELEMENT_ERROR (tag, CORE, SEEK, (NULL), ("can't seek back to beginning from reading ID3v1 tag")); + GST_ELEMENT_ERROR (tag, CORE, SEEK, (NULL), + ("can't seek back to beginning from reading ID3v1 tag")); } } else { gst_id3_tag_send_tag_event (tag); /* set eos, we're done parsing tags */ GST_LOG_OBJECT (tag, "setting EOS after reading ID3v1 tag"); gst_id3_tag_set_state (tag, GST_ID3_TAG_STATE_NORMAL); - gst_element_set_eos (GST_ELEMENT (tag)); - gst_pad_push (tag->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS))); + gst_element_set_eos (GST_ELEMENT (tag)); + gst_pad_push (tag->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS))); } return; case GST_ID3_TAG_STATE_READING_V2_TAG: if (tag->buffer) { GstBuffer *temp; + temp = gst_buffer_merge (tag->buffer, buffer); gst_data_unref (GST_DATA (tag->buffer)); tag->buffer = temp; @@ -938,7 +988,7 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) return; if (tag->v2tag_size == 0) { tag->v2tag_size = id3_tag_query (GST_BUFFER_DATA (tag->buffer), - GST_BUFFER_SIZE (tag->buffer)); + GST_BUFFER_SIZE (tag->buffer)); /* no footers supported */ if (tag->v2tag_size < 0) tag->v2tag_size = 0; @@ -948,11 +998,12 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) if (tag->v2tag_size != 0) { struct id3_tag *v2tag; - v2tag = id3_tag_parse (GST_BUFFER_DATA (tag->buffer), - GST_BUFFER_SIZE (tag->buffer)); + v2tag = id3_tag_parse (GST_BUFFER_DATA (tag->buffer), + GST_BUFFER_SIZE (tag->buffer)); if (v2tag) { GstTagList *list; - list = gst_mad_id3_to_tag_list (v2tag); + + list = gst_mad_id3_to_tag_list (v2tag); id3_tag_delete (v2tag); GST_LOG_OBJECT (tag, "parsed ID3v2 tag"); /* no other tag parsed yet */ @@ -963,9 +1014,12 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) } } /* caps nego and typefinding */ - GST_LOG_OBJECT (tag, "removing first %ld bytes, because they're the ID3v2 tag", tag->v2tag_size); - buffer = gst_buffer_create_sub (tag->buffer, tag->v2tag_size, - GST_BUFFER_SIZE (tag->buffer) - tag->v2tag_size); + GST_LOG_OBJECT (tag, + "removing first %ld bytes, because they're the ID3v2 tag", + tag->v2tag_size); + buffer = + gst_buffer_create_sub (tag->buffer, tag->v2tag_size, + GST_BUFFER_SIZE (tag->buffer) - tag->v2tag_size); gst_data_unref (GST_DATA (tag->buffer)); tag->buffer = NULL; if (tag->found_caps == NULL) @@ -973,24 +1027,23 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) return; /* seek to ID3v1 tag */ if (gst_pad_send_event (GST_PAD_PEER (tag->sinkpad), - gst_event_new_seek (GST_FORMAT_BYTES | GST_SEEK_METHOD_END | - GST_SEEK_FLAG_FLUSH, -128))) { + gst_event_new_seek (GST_FORMAT_BYTES | GST_SEEK_METHOD_END | + GST_SEEK_FLAG_FLUSH, -128))) { gst_id3_tag_set_state (tag, GST_ID3_TAG_STATE_SEEKING_TO_V1_TAG); gst_data_unref (GST_DATA (buffer)); return; } gst_id3_tag_set_state (tag, GST_ID3_TAG_STATE_NORMAL_START); /* fall through */ - case GST_ID3_TAG_STATE_NORMAL_START: + case GST_ID3_TAG_STATE_NORMAL_START: g_assert (tag->buffer == NULL); gst_id3_tag_send_tag_event (tag); - - if (tag->parse_mode == GST_ID3_TAG_PARSE_WRITE && - tag->v2tag_render) { + + if (tag->parse_mode == GST_ID3_TAG_PARSE_WRITE && tag->v2tag_render) { struct id3_tag *id3; GstTagList *merged; GstBuffer *tag_buffer; - + /* render tag */ tag->v2tag_size_new = 0; merged = gst_id3_tag_get_tag_to_render (tag); @@ -998,9 +1051,11 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) id3 = gst_mad_tag_list_to_id3_tag (merged); if (id3) { glong estimated; + estimated = id3_tag_render (id3, NULL); tag_buffer = gst_buffer_new_and_alloc (estimated); - tag->v2tag_size_new = id3_tag_render (id3, GST_BUFFER_DATA (tag_buffer)); + tag->v2tag_size_new = + id3_tag_render (id3, GST_BUFFER_DATA (tag_buffer)); g_assert (estimated >= tag->v2tag_size_new); GST_BUFFER_SIZE (tag_buffer) = tag->v2tag_size_new; gst_pad_push (tag->srcpad, GST_DATA (tag_buffer)); @@ -1010,10 +1065,11 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) } } gst_id3_tag_set_state (tag, GST_ID3_TAG_STATE_NORMAL); - tag->v1tag_size_new = (tag->v1tag_render && - tag->parse_mode == GST_ID3_TAG_PARSE_WRITE && - (tag->parsed_tags != NULL || - gst_tag_setter_get_list (GST_TAG_SETTER (tag)) != NULL)) ? 128 : 0; + tag->v1tag_size_new = (tag->v1tag_render && + tag->parse_mode == GST_ID3_TAG_PARSE_WRITE && + (tag->parsed_tags != NULL || + gst_tag_setter_get_list (GST_TAG_SETTER (tag)) != + NULL)) ? 128 : 0; /* fall through */ case GST_ID3_TAG_STATE_NORMAL: if (tag->parse_mode == GST_ID3_TAG_PARSE_TAG) { @@ -1025,7 +1081,8 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) return; } else if (buffer->offset + buffer->size > tag->v1tag_offset) { GstBuffer *sub = gst_buffer_create_sub (buffer, 0, - buffer->size - 128); + buffer->size - 128); + gst_data_unref (GST_DATA (buffer)); buffer = sub; } @@ -1037,7 +1094,7 @@ gst_id3_tag_chain (GstPad *pad, GstData *data) } static GstElementStateReturn -gst_id3_tag_change_state (GstElement *element) +gst_id3_tag_change_state (GstElement * element) { GstID3Tag *tag; @@ -1068,7 +1125,7 @@ gst_id3_tag_change_state (GstElement *element) tag->event_tags = NULL; } if (tag->buffer) { - gst_data_unref (GST_DATA (tag->buffer)); + gst_data_unref (GST_DATA (tag->buffer)); tag->buffer = NULL; } if (tag->found_caps) { @@ -1087,26 +1144,22 @@ gst_id3_tag_change_state (GstElement *element) /*** PLUGIN INITIALIZATION ****************************************************/ static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { if (!gst_library_load ("gsttags")) return FALSE; - if (!gst_element_register (plugin, "mad", GST_RANK_PRIMARY, gst_mad_get_type ()) || - !gst_element_register (plugin, "id3tag", GST_RANK_PRIMARY, gst_id3_tag_get_type ())) + if (!gst_element_register (plugin, "mad", GST_RANK_PRIMARY, + gst_mad_get_type ()) + || !gst_element_register (plugin, "id3tag", GST_RANK_PRIMARY, + gst_id3_tag_get_type ())) return FALSE; return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "mad", - "id3 tag manipulation and mp3 decoding based on the mad library", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mad", + "id3 tag manipulation and mp3 decoding based on the mad library", + plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/mad/gstmad.c b/ext/mad/gstmad.c index 01e48f2872..ea1071fecb 100644 --- a/ext/mad/gstmad.c +++ b/ext/mad/gstmad.c @@ -38,140 +38,132 @@ typedef struct _GstMad GstMad; typedef struct _GstMadClass GstMadClass; -struct _GstMad { - GstElement element; +struct _GstMad +{ + GstElement element; /* pads */ - GstPad *sinkpad, *srcpad; + GstPad *sinkpad, *srcpad; /* state */ struct mad_stream stream; struct mad_frame frame; struct mad_synth synth; - guchar *tempbuffer; - glong tempsize; /* used to keep track of partial buffers */ - gboolean need_sync; - GstClockTime last_ts; - guint64 base_byte_offset; - guint64 bytes_consumed; /* since the base_byte_offset */ - guint64 total_samples; /* the number of samples since the sync point */ + guchar *tempbuffer; + glong tempsize; /* used to keep track of partial buffers */ + gboolean need_sync; + GstClockTime last_ts; + guint64 base_byte_offset; + guint64 bytes_consumed; /* since the base_byte_offset */ + guint64 total_samples; /* the number of samples since the sync point */ - gboolean restart; - guint64 segment_start; + gboolean restart; + guint64 segment_start; /* info */ struct mad_header header; - gboolean new_header; - guint framecount; - gint vbr_average; /* average bitrate */ - guint64 vbr_rate; /* average * framecount */ + gboolean new_header; + guint framecount; + gint vbr_average; /* average bitrate */ + guint64 vbr_rate; /* average * framecount */ - gboolean half; - gboolean ignore_crc; + gboolean half; + gboolean ignore_crc; - GstTagList * tags; + GstTagList *tags; /* negotiated format */ - gint rate; - gint channels; + gint rate; + gint channels; - GstIndex *index; - gint index_id; + GstIndex *index; + gint index_id; - gboolean check_for_xing; + gboolean check_for_xing; }; -struct _GstMadClass { +struct _GstMadClass +{ GstElementClass parent_class; }; /* elementfactory information */ -static GstElementDetails gst_mad_details = GST_ELEMENT_DETAILS ( - "mad mp3 decoder", - "Codec/Decoder/Audio", - "Uses mad code to decode mp3 streams", - "Wim Taymans " -); +static GstElementDetails gst_mad_details = +GST_ELEMENT_DETAILS ("mad mp3 decoder", + "Codec/Decoder/Audio", + "Uses mad code to decode mp3 streams", + "Wim Taymans "); /* Mad signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_HALF, ARG_IGNORE_CRC, ARG_METADATA, ARG_STREAMINFO - /* FILL ME */ + /* FILL ME */ }; static GstStaticPadTemplate mad_src_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-int, " - "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " - "signed = (boolean) true, " - "width = (int) 16, " - "depth = (int) 16, " - "rate = (int) [ 11025, 48000 ], " - "channels = (int) [ 1, 2 ]" - ) -); +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " + "signed = (boolean) true, " + "width = (int) 16, " + "depth = (int) 16, " + "rate = (int) [ 11025, 48000 ], " "channels = (int) [ 1, 2 ]") + ); static GstStaticPadTemplate mad_sink_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/mpeg, " - "mpegversion = (int) 1, " - "layer = (int) [ 1, 3 ]" - ) -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/mpeg, " + "mpegversion = (int) 1, " "layer = (int) [ 1, 3 ]") + ); -static void gst_mad_base_init (gpointer g_class); -static void gst_mad_class_init (GstMadClass *klass); -static void gst_mad_init (GstMad *mad); -static void gst_mad_dispose (GObject *object); +static void gst_mad_base_init (gpointer g_class); +static void gst_mad_class_init (GstMadClass * klass); +static void gst_mad_init (GstMad * mad); +static void gst_mad_dispose (GObject * object); -static void gst_mad_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_mad_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); +static void gst_mad_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +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 GstEventMask* - gst_mad_get_event_masks (GstPad *pad); -static const GstQueryType* - gst_mad_get_query_types (GstPad *pad); +static gboolean gst_mad_src_event (GstPad * pad, GstEvent * event); +static const GstFormat *gst_mad_get_formats (GstPad * pad); +static const GstEventMask *gst_mad_get_event_masks (GstPad * pad); +static const GstQueryType *gst_mad_get_query_types (GstPad * pad); -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_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 void gst_mad_chain (GstPad *pad, GstData *_data); +static void gst_mad_chain (GstPad * pad, GstData * _data); -static GstElementStateReturn - gst_mad_change_state (GstElement *element); +static GstElementStateReturn gst_mad_change_state (GstElement * element); -static void gst_mad_set_index (GstElement *element, GstIndex *index); -static GstIndex* gst_mad_get_index (GstElement *element); +static void gst_mad_set_index (GstElement * element, GstIndex * index); +static GstIndex *gst_mad_get_index (GstElement * element); static GstElementClass *parent_class = NULL; + /* static guint gst_mad_signals[LAST_SIGNAL] = { 0 }; */ GType @@ -191,60 +183,64 @@ gst_mad_get_type (void) 0, (GInstanceInitFunc) gst_mad_init, }; - mad_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMad", &mad_info, 0); + mad_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstMad", &mad_info, 0); } return mad_type; } #define GST_TYPE_MAD_LAYER (gst_mad_layer_get_type()) G_GNUC_UNUSED static GType -gst_mad_layer_get_type(void) { +gst_mad_layer_get_type (void) +{ static GType mad_layer_type = 0; static GEnumValue mad_layer[] = { - {0, "0", "Unknown"}, - {MAD_LAYER_I, "1", "I"}, - {MAD_LAYER_II, "2", "II"}, + {0, "0", "Unknown"}, + {MAD_LAYER_I, "1", "I"}, + {MAD_LAYER_II, "2", "II"}, {MAD_LAYER_III, "3", "III"}, {0, NULL, NULL}, }; if (!mad_layer_type) { - mad_layer_type = g_enum_register_static("GstMadLayer", mad_layer); + mad_layer_type = g_enum_register_static ("GstMadLayer", mad_layer); } return mad_layer_type; } #define GST_TYPE_MAD_MODE (gst_mad_mode_get_type()) G_GNUC_UNUSED static GType -gst_mad_mode_get_type(void) { +gst_mad_mode_get_type (void) +{ static GType mad_mode_type = 0; static GEnumValue mad_mode[] = { - {-1, "-1", "Unknown"}, + {-1, "-1", "Unknown"}, {MAD_MODE_SINGLE_CHANNEL, "0", "Single Channel"}, - {MAD_MODE_DUAL_CHANNEL , "1", "Dual Channel"}, - {MAD_MODE_JOINT_STEREO , "2", "Joint Stereo"}, - {MAD_MODE_STEREO , "3", "Stereo"}, - { 0, NULL, NULL}, + {MAD_MODE_DUAL_CHANNEL, "1", "Dual Channel"}, + {MAD_MODE_JOINT_STEREO, "2", "Joint Stereo"}, + {MAD_MODE_STEREO, "3", "Stereo"}, + {0, NULL, NULL}, }; if (!mad_mode_type) { - mad_mode_type = g_enum_register_static("GstMadMode", mad_mode); + mad_mode_type = g_enum_register_static ("GstMadMode", mad_mode); } return mad_mode_type; } #define GST_TYPE_MAD_EMPHASIS (gst_mad_emphasis_get_type()) G_GNUC_UNUSED static GType -gst_mad_emphasis_get_type(void) { +gst_mad_emphasis_get_type (void) +{ static GType mad_emphasis_type = 0; static GEnumValue mad_emphasis[] = { - {-1, "-1", "Unknown"}, - {MAD_EMPHASIS_NONE, "0", "None"}, - {MAD_EMPHASIS_50_15_US, "1", "50/15 Microseconds"}, + {-1, "-1", "Unknown"}, + {MAD_EMPHASIS_NONE, "0", "None"}, + {MAD_EMPHASIS_50_15_US, "1", "50/15 Microseconds"}, {MAD_EMPHASIS_CCITT_J_17, "2", "CCITT J.17"}, - {MAD_EMPHASIS_RESERVED, "3", "Reserved"}, - { 0, NULL, NULL}, + {MAD_EMPHASIS_RESERVED, "3", "Reserved"}, + {0, NULL, NULL}, }; if (!mad_emphasis_type) { - mad_emphasis_type = g_enum_register_static("GstMadEmphasis", mad_emphasis); + mad_emphasis_type = g_enum_register_static ("GstMadEmphasis", mad_emphasis); } return mad_emphasis_type; } @@ -253,42 +249,42 @@ static void gst_mad_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - + gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&mad_sink_template_factory)); + gst_static_pad_template_get (&mad_sink_template_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&mad_src_template_factory)); + gst_static_pad_template_get (&mad_src_template_factory)); gst_element_class_set_details (element_class, &gst_mad_details); } static void -gst_mad_class_init (GstMadClass *klass) +gst_mad_class_init (GstMadClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*) klass; - gstelement_class = (GstElementClass*) klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gobject_class->set_property = gst_mad_set_property; gobject_class->get_property = gst_mad_get_property; gobject_class->dispose = gst_mad_dispose; gstelement_class->change_state = gst_mad_change_state; - gstelement_class->set_index = gst_mad_set_index; - gstelement_class->get_index = gst_mad_get_index; + gstelement_class->set_index = gst_mad_set_index; + gstelement_class->get_index = gst_mad_get_index; /* 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 */ 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)); + g_param_spec_boolean ("half", "Half", "Generate PCM at 1/2 sample rate", + FALSE, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, ARG_IGNORE_CRC, - g_param_spec_boolean ("ignore_crc", "Ignore CRC", "Ignore CRC errors", - FALSE, G_PARAM_READWRITE)); + g_param_spec_boolean ("ignore_crc", "Ignore CRC", "Ignore CRC errors", + FALSE, G_PARAM_READWRITE)); /* register tags */ #define GST_TAG_LAYER "layer" @@ -296,33 +292,43 @@ gst_mad_class_init (GstMadClass *klass) #define GST_TAG_EMPHASIS "emphasis" gst_tag_register (GST_TAG_LAYER, GST_TAG_FLAG_ENCODED, G_TYPE_UINT, - "layer", "MPEG audio layer", NULL); + "layer", "MPEG audio layer", NULL); gst_tag_register (GST_TAG_MODE, GST_TAG_FLAG_ENCODED, G_TYPE_STRING, - "mode", "MPEG audio channel mode", NULL); + "mode", "MPEG audio channel mode", NULL); gst_tag_register (GST_TAG_EMPHASIS, GST_TAG_FLAG_ENCODED, G_TYPE_STRING, - "emphasis", "MPEG audio emphasis", NULL); + "emphasis", "MPEG audio emphasis", NULL); } static void -gst_mad_init (GstMad *mad) +gst_mad_init (GstMad * mad) { /* create the sink and src pads */ - mad->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&mad_sink_template_factory), "sink"); + mad->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&mad_sink_template_factory), "sink"); gst_element_add_pad (GST_ELEMENT (mad), mad->sinkpad); gst_pad_set_chain_function (mad->sinkpad, GST_DEBUG_FUNCPTR (gst_mad_chain)); - gst_pad_set_convert_function (mad->sinkpad, GST_DEBUG_FUNCPTR (gst_mad_convert_sink)); - gst_pad_set_formats_function (mad->sinkpad, GST_DEBUG_FUNCPTR (gst_mad_get_formats)); + gst_pad_set_convert_function (mad->sinkpad, + GST_DEBUG_FUNCPTR (gst_mad_convert_sink)); + gst_pad_set_formats_function (mad->sinkpad, + GST_DEBUG_FUNCPTR (gst_mad_get_formats)); - mad->srcpad = gst_pad_new_from_template( - gst_static_pad_template_get (&mad_src_template_factory), "src"); + mad->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&mad_src_template_factory), "src"); gst_element_add_pad (GST_ELEMENT (mad), mad->srcpad); - gst_pad_set_event_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_src_event)); - gst_pad_set_event_mask_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_get_event_masks)); - gst_pad_set_query_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_src_query)); - gst_pad_set_query_type_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_get_query_types)); - gst_pad_set_convert_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_convert_src)); - gst_pad_set_formats_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_get_formats)); + gst_pad_set_event_function (mad->srcpad, + GST_DEBUG_FUNCPTR (gst_mad_src_event)); + gst_pad_set_event_mask_function (mad->srcpad, + GST_DEBUG_FUNCPTR (gst_mad_get_event_masks)); + gst_pad_set_query_function (mad->srcpad, + GST_DEBUG_FUNCPTR (gst_mad_src_query)); + gst_pad_set_query_type_function (mad->srcpad, + GST_DEBUG_FUNCPTR (gst_mad_get_query_types)); + gst_pad_set_convert_function (mad->srcpad, + GST_DEBUG_FUNCPTR (gst_mad_convert_src)); + gst_pad_set_formats_function (mad->srcpad, + GST_DEBUG_FUNCPTR (gst_mad_get_formats)); gst_pad_use_explicit_caps (mad->srcpad); mad->tempbuffer = g_malloc (MAD_BUFFER_MDLEN * 3); @@ -348,7 +354,7 @@ gst_mad_init (GstMad *mad) } static void -gst_mad_dispose (GObject *object) +gst_mad_dispose (GObject * object) { GstMad *mad = GST_MAD (object); @@ -360,26 +366,26 @@ gst_mad_dispose (GObject *object) } static void -gst_mad_set_index (GstElement *element, GstIndex *index) +gst_mad_set_index (GstElement * element, GstIndex * index) { GstMad *mad = GST_MAD (element); - + mad->index = index; if (index) gst_index_get_writer_id (index, GST_OBJECT (element), &mad->index_id); } -static GstIndex* -gst_mad_get_index (GstElement *element) +static GstIndex * +gst_mad_get_index (GstElement * element) { GstMad *mad = GST_MAD (element); return mad->index; } -static const GstFormat* -gst_mad_get_formats (GstPad *pad) +static const GstFormat * +gst_mad_get_formats (GstPad * pad) { static const GstFormat src_formats[] = { GST_FORMAT_BYTES, @@ -396,20 +402,19 @@ gst_mad_get_formats (GstPad *pad) return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats); } -static const GstEventMask* -gst_mad_get_event_masks (GstPad *pad) +static const GstEventMask * +gst_mad_get_event_masks (GstPad * pad) { static const GstEventMask gst_mad_src_event_masks[] = { - { GST_EVENT_SEEK, GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH }, - { 0, } + {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH}, + {0,} }; return gst_mad_src_event_masks; } static gboolean -gst_mad_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value) +gst_mad_convert_sink (GstPad * pad, GstFormat src_format, gint64 src_value, + GstFormat * dest_format, gint64 * dest_value) { gboolean res = TRUE; GstMad *mad; @@ -422,22 +427,22 @@ gst_mad_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value, switch (src_format) { case GST_FORMAT_BYTES: switch (*dest_format) { - case GST_FORMAT_TIME: - /* multiply by 8 because vbr is in bits/second */ - *dest_value = src_value * 8 * GST_SECOND / mad->vbr_average; - break; - default: - res = FALSE; + case GST_FORMAT_TIME: + /* multiply by 8 because vbr is in bits/second */ + *dest_value = src_value * 8 * GST_SECOND / mad->vbr_average; + break; + default: + res = FALSE; } break; case GST_FORMAT_TIME: switch (*dest_format) { - case GST_FORMAT_BYTES: - /* multiply by 8 because vbr is in bits/second */ - *dest_value = src_value * mad->vbr_average / (8 * GST_SECOND); - break; - default: - res = FALSE; + case GST_FORMAT_BYTES: + /* multiply by 8 because vbr is in bits/second */ + *dest_value = src_value * mad->vbr_average / (8 * GST_SECOND); + break; + default: + res = FALSE; } break; default: @@ -447,8 +452,8 @@ gst_mad_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value, } static gboolean -gst_mad_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value) +gst_mad_convert_src (GstPad * pad, GstFormat src_format, gint64 src_value, + GstFormat * dest_format, gint64 * dest_value) { gboolean res = TRUE; guint scale = 1; @@ -462,48 +467,49 @@ gst_mad_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, switch (src_format) { case GST_FORMAT_BYTES: switch (*dest_format) { - case GST_FORMAT_DEFAULT: + case GST_FORMAT_DEFAULT: if (bytes_per_sample == 0) - return FALSE; + return FALSE; *dest_value = src_value / bytes_per_sample; - break; - case GST_FORMAT_TIME: + break; + case GST_FORMAT_TIME: { - gint byterate = bytes_per_sample * mad->frame.header.samplerate; + gint byterate = bytes_per_sample * mad->frame.header.samplerate; if (byterate == 0) - return FALSE; + return FALSE; *dest_value = src_value * GST_SECOND / byterate; - break; + break; } - default: - res = FALSE; + default: + res = FALSE; } break; case GST_FORMAT_DEFAULT: switch (*dest_format) { - case GST_FORMAT_BYTES: + case GST_FORMAT_BYTES: *dest_value = src_value * bytes_per_sample; break; - case GST_FORMAT_TIME: + case GST_FORMAT_TIME: if (mad->frame.header.samplerate == 0) - return FALSE; + return FALSE; *dest_value = src_value * GST_SECOND / mad->frame.header.samplerate; - break; - default: - res = FALSE; + break; + default: + res = FALSE; } break; case GST_FORMAT_TIME: switch (*dest_format) { - case GST_FORMAT_BYTES: + case GST_FORMAT_BYTES: scale = bytes_per_sample; /* fallthrough */ - case GST_FORMAT_DEFAULT: - *dest_value = src_value * scale * mad->frame.header.samplerate / GST_SECOND; - break; - default: - res = FALSE; + case GST_FORMAT_DEFAULT: + *dest_value = + src_value * scale * mad->frame.header.samplerate / GST_SECOND; + break; + default: + res = FALSE; } break; default: @@ -512,8 +518,8 @@ gst_mad_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, return res; } -static const GstQueryType* -gst_mad_get_query_types (GstPad *pad) +static const GstQueryType * +gst_mad_get_query_types (GstPad * pad) { static const GstQueryType gst_mad_src_query_types[] = { GST_QUERY_TOTAL, @@ -524,8 +530,8 @@ gst_mad_get_query_types (GstPad *pad) } static gboolean -gst_mad_src_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value) +gst_mad_src_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value) { gboolean res = TRUE; GstMad *mad; @@ -539,9 +545,9 @@ gst_mad_src_query (GstPad *pad, GstQueryType type, case GST_FORMAT_BYTES: case GST_FORMAT_DEFAULT: case GST_FORMAT_TIME: - { + { gint64 peer_value; - const GstFormat *peer_formats; + const GstFormat *peer_formats; res = FALSE; @@ -552,19 +558,17 @@ gst_mad_src_query (GstPad *pad, GstQueryType type, GstFormat peer_format = *peer_formats; /* do the probe */ - if (gst_pad_query (GST_PAD_PEER (mad->sinkpad), GST_QUERY_TOTAL, - &peer_format, &peer_value)) - { - GstFormat conv_format; + if (gst_pad_query (GST_PAD_PEER (mad->sinkpad), GST_QUERY_TOTAL, + &peer_format, &peer_value)) { + GstFormat conv_format; + /* convert to TIME */ - conv_format = GST_FORMAT_TIME; + conv_format = GST_FORMAT_TIME; res = gst_pad_convert (mad->sinkpad, - peer_format, peer_value, - &conv_format, value); + peer_format, peer_value, &conv_format, value); /* and to final format */ res &= gst_pad_convert (pad, - GST_FORMAT_TIME, *value, - format, value); + GST_FORMAT_TIME, *value, format, value); } peer_formats++; } @@ -582,8 +586,7 @@ gst_mad_src_query (GstPad *pad, GstQueryType type, { /* we only know about our samples, convert to requested format */ res &= gst_pad_convert (pad, - GST_FORMAT_DEFAULT, mad->total_samples, - format, value); + GST_FORMAT_DEFAULT, mad->total_samples, format, value); break; } } @@ -596,12 +599,12 @@ gst_mad_src_query (GstPad *pad, GstQueryType type, } static gboolean -index_seek (GstMad *mad, GstPad *pad, GstEvent *event) +index_seek (GstMad * mad, GstPad * pad, GstEvent * event) { /* since we know the exact byteoffset of the frame, make sure to try bytes first */ - const GstFormat try_all_formats[] = { + const GstFormat try_all_formats[] = { GST_FORMAT_BYTES, GST_FORMAT_TIME, 0 @@ -609,33 +612,31 @@ index_seek (GstMad *mad, GstPad *pad, GstEvent *event) const GstFormat *try_formats = try_all_formats; const GstFormat *peer_formats; - GstIndexEntry *entry = - gst_index_get_assoc_entry (mad->index, mad->index_id, - GST_INDEX_LOOKUP_BEFORE, 0, - GST_EVENT_SEEK_FORMAT (event), - GST_EVENT_SEEK_OFFSET (event)); + GstIndexEntry *entry = gst_index_get_assoc_entry (mad->index, mad->index_id, + GST_INDEX_LOOKUP_BEFORE, 0, + GST_EVENT_SEEK_FORMAT (event), + GST_EVENT_SEEK_OFFSET (event)); + if (!entry) return FALSE; - + peer_formats = gst_pad_get_formats (GST_PAD_PEER (mad->sinkpad)); while (gst_formats_contains (peer_formats, *try_formats)) { gint64 value; GstEvent *seek_event; - + if (gst_index_entry_assoc_map (entry, *try_formats, &value)) { /* lookup succeeded, create the seek */ GST_DEBUG ("index %s %" G_GINT64_FORMAT - " -> %s %" G_GINT64_FORMAT, - gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, - GST_EVENT_SEEK_OFFSET (event), - gst_format_get_details (*try_formats)->nick, - value); + " -> %s %" G_GINT64_FORMAT, + gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, + GST_EVENT_SEEK_OFFSET (event), + gst_format_get_details (*try_formats)->nick, value); seek_event = gst_event_new_seek (*try_formats | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, value); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, value); if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), seek_event)) { /* seek worked, we're done, loop will exit */ @@ -652,59 +653,57 @@ index_seek (GstMad *mad, GstPad *pad, GstEvent *event) } static gboolean -normal_seek (GstMad *mad, GstPad *pad, GstEvent *event) +normal_seek (GstMad * mad, GstPad * pad, GstEvent * event) { gint64 src_offset; gboolean flush; GstFormat format; const GstFormat *peer_formats; gboolean res; - + format = GST_FORMAT_TIME; - + /* first bring the src_format to TIME */ if (!gst_pad_convert (pad, - GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event), - &format, &src_offset)) - { + GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event), + &format, &src_offset)) { /* didn't work, probably unsupported seek format then */ return FALSE; } - + /* shave off the flush flag, we'll need it later */ flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH; - + /* assume the worst */ res = FALSE; - + peer_formats = gst_pad_get_formats (GST_PAD_PEER (mad->sinkpad)); - + /* while we did not exhaust our seek formats without result */ while (peer_formats && *peer_formats && !res) { gint64 desired_offset; - + 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)) - { - GstEvent *seek_event; - - /* conversion succeeded, create the seek */ - 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 */ - res = TRUE; - } + &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); + /* do the seek */ + if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), seek_event)) { + /* seek worked, we're done, loop will exit */ + res = TRUE; } + } /* at this point, either the seek worked or res == FALSE */ if (res) /* we need to break out of the processing loop on flush */ mad->restart = flush; - + peer_formats++; } @@ -712,7 +711,7 @@ normal_seek (GstMad *mad, GstPad *pad, GstEvent *event) } static gboolean -gst_mad_src_event (GstPad *pad, GstEvent *event) +gst_mad_src_event (GstPad * pad, GstEvent * event) { gboolean res = TRUE; GstMad *mad; @@ -723,11 +722,11 @@ gst_mad_src_event (GstPad *pad, GstEvent *event) case GST_EVENT_SEEK_SEGMENT: gst_event_ref (event); if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), event)) { - /* seek worked, we're done, loop will exit */ - res = TRUE; + /* seek worked, we're done, loop will exit */ + res = TRUE; } break; - /* the all-formats seek logic */ + /* the all-formats seek logic */ case GST_EVENT_SEEK: if (mad->index) res = index_seek (mad, pad, event); @@ -762,8 +761,8 @@ 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; @@ -784,8 +783,8 @@ gst_mad_set_property (GObject *object, guint prop_id, } } 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; @@ -807,7 +806,7 @@ gst_mad_get_property (GObject *object, guint prop_id, } static void -gst_mad_update_info (GstMad *mad) +gst_mad_update_info (GstMad * mad) { gint abr = mad->vbr_average; struct mad_header *header = &mad->frame.header; @@ -832,9 +831,9 @@ G_STMT_START{ \ } mad->vbr_average = (gint) (mad->vbr_rate / mad->framecount); - CHECK_HEADER (layer, "layer"); - CHECK_HEADER (mode, "mode"); - CHECK_HEADER (emphasis, "emphasis"); + CHECK_HEADER (layer, "layer"); + CHECK_HEADER (mode, "mode"); + CHECK_HEADER (emphasis, "emphasis"); if (header->bitrate != mad->header.bitrate || mad->new_header) { mad->header.bitrate = header->bitrate; @@ -846,31 +845,31 @@ G_STMT_START{ \ GEnumValue *mode; GEnumValue *emphasis; - mode = g_enum_get_value (g_type_class_ref (GST_TYPE_MAD_MODE), mad->header.mode); - emphasis = g_enum_get_value (g_type_class_ref (GST_TYPE_MAD_EMPHASIS), mad->header.emphasis); + mode = + g_enum_get_value (g_type_class_ref (GST_TYPE_MAD_MODE), + mad->header.mode); + emphasis = + g_enum_get_value (g_type_class_ref (GST_TYPE_MAD_EMPHASIS), + mad->header.emphasis); list = gst_tag_list_new (); gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, - GST_TAG_LAYER, mad->header.layer, - GST_TAG_MODE, mode->value_nick, - GST_TAG_EMPHASIS, emphasis->value_nick, - NULL); + GST_TAG_LAYER, mad->header.layer, + GST_TAG_MODE, mode->value_nick, + GST_TAG_EMPHASIS, emphasis->value_nick, NULL); gst_element_found_tags (GST_ELEMENT (mad), list); gst_tag_list_free (list); } - - #undef CHECK_HEADER } static void -gst_mad_handle_event (GstPad *pad, GstBuffer *buffer) +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)) - { + switch (GST_EVENT_TYPE (event)) { case GST_EVENT_DISCONTINUOUS: { gint n = GST_EVENT_DISCONT_OFFSET_LEN (event); @@ -878,46 +877,43 @@ gst_mad_handle_event (GstPad *pad, GstBuffer *buffer) mad->total_samples = 0; - for (i = 0; i < n; i++) - { + for (i = 0; i < n; i++) { const GstFormat *formats; + formats = gst_pad_get_formats (pad); - if (gst_formats_contains (formats, GST_EVENT_DISCONT_OFFSET(event, i).format)) - { - gint64 value = GST_EVENT_DISCONT_OFFSET (event, i).value; - gint64 time; - GstFormat format; - GstEvent *discont; + if (gst_formats_contains (formats, 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; - } + /* 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 to get the total number + /* for now, this is the best we can do to get the total number * of samples */ - format = GST_FORMAT_DEFAULT; - if (!gst_pad_convert (mad->srcpad, - GST_FORMAT_TIME, time, &format, &mad->total_samples)) - { - mad->total_samples = 0; - } + format = GST_FORMAT_DEFAULT; + if (!gst_pad_convert (mad->srcpad, + GST_FORMAT_TIME, time, &format, &mad->total_samples)) { + mad->total_samples = 0; + } - gst_event_unref (event); + 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_DATA (discont)); - } - break; - } + if (GST_PAD_IS_USABLE (mad->srcpad)) { + discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, + time, NULL); + gst_pad_push (mad->srcpad, GST_DATA (discont)); + } + break; + } } mad->tempsize = 0; /* we don't need to restart when we get here */ @@ -932,9 +928,10 @@ gst_mad_handle_event (GstPad *pad, GstBuffer *buffer) } static gboolean -gst_mad_check_restart (GstMad *mad) +gst_mad_check_restart (GstMad * mad) { gboolean yes = mad->restart; + if (mad->restart) { mad->restart = FALSE; mad->tempsize = 0; @@ -966,9 +963,10 @@ gst_mad_check_restart (GstMad *mad) #define XING_TOC_LENGTH 100 /* check for valid "Xing" VBR header */ -static int is_xhead(unsigned char *buf) +static int +is_xhead (unsigned char *buf) { - return (BE_32(buf) == XING_TAG); + return (BE_32 (buf) == XING_TAG); } @@ -980,32 +978,33 @@ static int is_xhead(unsigned char *buf) #define lprintf(x...) #endif -static int mpg123_parse_xing_header(struct mad_header *header, - const guint8 *buf, int bufsize, int *bitrate, - int *time) +static int +mpg123_parse_xing_header (struct mad_header *header, + const guint8 * buf, int bufsize, int *bitrate, int *time) { int i; - guint8 *ptr = (guint8*)buf; + guint8 *ptr = (guint8 *) buf; double frame_duration; int xflags, xframes, xbytes, xvbr_scale; int abr; guint8 xtoc[XING_TOC_LENGTH]; + /* This should be the MPEG Audio version ID * (version 2.5, 2 or 1) least significant byte, but mad doesn't * provide that, so assume it's always MPEG 1 */ int lsf_bit = 1; + xframes = xbytes = 0; /* offset of the Xing header */ - if ( lsf_bit ) - { - if( header->mode != MAD_MODE_STEREO ) + if (lsf_bit) { + if (header->mode != MAD_MODE_STEREO) ptr += (32 + 4); else ptr += (17 + 4); } else { - if( header->mode != MAD_MODE_STEREO ) + if (header->mode != MAD_MODE_STEREO) ptr += (17 + 4); else ptr += (9 + 4); @@ -1014,67 +1013,71 @@ static int mpg123_parse_xing_header(struct mad_header *header, if (ptr >= (buf + bufsize - 4)) return 0; - if (is_xhead(ptr)) - { - lprintf("Xing header found\n"); + if (is_xhead (ptr)) { + lprintf ("Xing header found\n"); - ptr += 4; if (ptr >= (buf + bufsize - 4)) return 0; + ptr += 4; + if (ptr >= (buf + bufsize - 4)) + return 0; - xflags = BE_32(ptr); + xflags = BE_32 (ptr); ptr += 4; - if (xflags & XING_FRAMES_FLAG) - { - if (ptr >= (buf + bufsize - 4)) return 0; - xframes = BE_32(ptr); - lprintf("xframes: %d\n", xframes); + if (xflags & XING_FRAMES_FLAG) { + if (ptr >= (buf + bufsize - 4)) + return 0; + xframes = BE_32 (ptr); + lprintf ("xframes: %d\n", xframes); ptr += 4; } - if (xflags & XING_BYTES_FLAG) - { - if (ptr >= (buf + bufsize - 4)) return 0; - xbytes = BE_32(ptr); - lprintf("xbytes: %d\n", xbytes); - ptr += 4; + if (xflags & XING_BYTES_FLAG) { + if (ptr >= (buf + bufsize - 4)) + return 0; + xbytes = BE_32 (ptr); + lprintf ("xbytes: %d\n", xbytes); + ptr += 4; } - if (xflags & XING_TOC_FLAG) - { - lprintf("toc found\n"); - if (ptr >= (buf + bufsize - XING_TOC_LENGTH)) return 0; - for (i = 0; i < XING_TOC_LENGTH; i++) - { - xtoc[i] = *(ptr + i); - lprintf("%d ", xtoc[i]); + if (xflags & XING_TOC_FLAG) { + lprintf ("toc found\n"); + if (ptr >= (buf + bufsize - XING_TOC_LENGTH)) + return 0; + for (i = 0; i < XING_TOC_LENGTH; i++) { + xtoc[i] = *(ptr + i); + lprintf ("%d ", xtoc[i]); } - lprintf("\n"); - ptr += XING_TOC_LENGTH; + lprintf ("\n"); + ptr += XING_TOC_LENGTH; } xvbr_scale = -1; if (xflags & XING_VBR_SCALE_FLAG) { - if (ptr >= (buf + bufsize - 4)) return 0; - xvbr_scale = BE_32(ptr); - lprintf("xvbr_scale: %d\n", xvbr_scale); + if (ptr >= (buf + bufsize - 4)) + return 0; + xvbr_scale = BE_32 (ptr); + lprintf ("xvbr_scale: %d\n", xvbr_scale); } /* 1 kbit = 1000 bits ! (and not 1024 bits) */ if (xflags & (XING_FRAMES_FLAG | XING_BYTES_FLAG)) { if (header->layer == MAD_LAYER_I) { - frame_duration = 384.0 / (double)header->samplerate; + frame_duration = 384.0 / (double) header->samplerate; } else { - int slots_per_frame; - slots_per_frame = ((header->layer == MAD_LAYER_III) && !lsf_bit) ? 72 : 144; - frame_duration = slots_per_frame * 8.0 / (double)header->samplerate; + int slots_per_frame; + + slots_per_frame = ((header->layer == MAD_LAYER_III) + && !lsf_bit) ? 72 : 144; + frame_duration = slots_per_frame * 8.0 / (double) header->samplerate; } - abr = ((double)xbytes * 8.0) / ((double)xframes * frame_duration); - lprintf("abr: %d bps\n", abr); + abr = ((double) xbytes * 8.0) / ((double) xframes * frame_duration); + lprintf ("abr: %d bps\n", abr); if (bitrate != NULL) { *bitrate = abr; } if (time != NULL) { - *time = (double)xframes * frame_duration; - lprintf("stream_length: %d s, %d min %d s\n", *time, - *time / 60, *time % 60); + *time = (double) xframes *frame_duration; + + lprintf ("stream_length: %d s, %d min %d s\n", *time, + *time / 60, *time % 60); } } else { /* it's a stupid Xing header */ @@ -1082,15 +1085,16 @@ static int mpg123_parse_xing_header(struct mad_header *header, } return 1; } else { - lprintf("Xing header not found\n"); + lprintf ("Xing header not found\n"); return 0; } } + /* End of Xine code */ static void -gst_mad_chain (GstPad *pad, GstData *_data) +gst_mad_chain (GstPad * pad, GstData * _data) { GstBuffer *buffer = GST_BUFFER (_data); GstMad *mad; @@ -1103,8 +1107,7 @@ gst_mad_chain (GstPad *pad, GstData *_data) g_return_if_fail (GST_IS_MAD (mad)); /* handle events */ - if (GST_IS_EVENT (buffer)) - { + if (GST_IS_EVENT (buffer)) { gst_mad_handle_event (pad, buffer); return; } @@ -1138,8 +1141,7 @@ gst_mad_chain (GstPad *pad, GstData *_data) /* 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) - { + while (size > 0) { gint tocopy; guchar *mad_input_buffer; @@ -1171,25 +1173,23 @@ gst_mad_chain (GstPad *pad, GstData *_data) if (mad->stream.error == MAD_ERROR_BUFLEN) { break; } - if (!MAD_RECOVERABLE (mad->stream.error)) { - GST_ELEMENT_ERROR (mad, STREAM, DECODE, (NULL), (NULL)); - return; - } - else if (mad->stream.error == MAD_ERROR_LOSTSYNC) { + if (!MAD_RECOVERABLE (mad->stream.error)) { + GST_ELEMENT_ERROR (mad, STREAM, DECODE, (NULL), (NULL)); + return; + } else if (mad->stream.error == MAD_ERROR_LOSTSYNC) { /* lost sync, force a resync */ signed long tagsize; 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) { - GST_INFO ("mad: got partial id3 tag in buffer, skipping"); - } - else if (tagsize > 0) { + GST_INFO ("mad: got partial id3 tag in buffer, skipping"); + } else if (tagsize > 0) { struct id3_tag *tag; id3_byte_t const *data; - GST_INFO ("mad: got ID3 tag size %ld", tagsize); + GST_INFO ("mad: got ID3 tag size %ld", tagsize); data = mad->stream.this_frame; @@ -1232,14 +1232,12 @@ gst_mad_chain (GstPad *pad, GstData *_data) int frame_len = mad->stream.next_frame - mad->stream.this_frame; /* Assume Xing headers can only be the first frame in a mp3 file */ - if (mpg123_parse_xing_header (&mad->frame.header, - mad->stream.this_frame, - frame_len, &bitrate, &time)) { + if (mpg123_parse_xing_header (&mad->frame.header, + mad->stream.this_frame, frame_len, &bitrate, &time)) { list = gst_tag_list_new (); - gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, - GST_TAG_DURATION, (gint64)time*1000*1000*1000, - GST_TAG_BITRATE, bitrate, - NULL); + gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, + GST_TAG_DURATION, (gint64) time * 1000 * 1000 * 1000, + GST_TAG_BITRATE, bitrate, NULL); gst_element_found_tags (GST_ELEMENT (mad), list); if (GST_PAD_IS_USABLE (mad->srcpad)) { gst_pad_push (mad->srcpad, GST_DATA (gst_event_new_tag (list))); @@ -1252,8 +1250,8 @@ gst_mad_chain (GstPad *pad, GstData *_data) goto next; } nchannels = MAD_NCHANNELS (&mad->frame.header); - nsamples = MAD_NSBSAMPLES (&mad->frame.header) * - (mad->stream.options & MAD_OPTION_HALFSAMPLERATE ? 16 : 32); + nsamples = MAD_NSBSAMPLES (&mad->frame.header) * + (mad->stream.options & MAD_OPTION_HALFSAMPLERATE ? 16 : 32); #if MAD_VERSION_MINOR <= 12 rate = mad->header.sfreq; @@ -1266,19 +1264,17 @@ gst_mad_chain (GstPad *pad, GstData *_data) if (mad->channels != nchannels || mad->rate != rate) { GstCaps *caps; - if (mad->stream.options & MAD_OPTION_HALFSAMPLERATE) - rate >>=1; + if (mad->stream.options & MAD_OPTION_HALFSAMPLERATE) + rate >>= 1; /* we set the caps even when the pad is not connected so they * can be gotten for streaminfo */ caps = gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, TRUE, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "rate", G_TYPE_INT, rate, - "channels", G_TYPE_INT, nchannels, - NULL); + "endianness", G_TYPE_INT, G_BYTE_ORDER, + "signed", G_TYPE_BOOLEAN, TRUE, + "width", G_TYPE_INT, 16, + "depth", G_TYPE_INT, 16, + "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, nchannels, NULL); gst_pad_set_explicit_caps (mad->srcpad, caps); gst_caps_free (caps); @@ -1287,68 +1283,70 @@ gst_mad_chain (GstPad *pad, GstData *_data) } if (mad->frame.header.samplerate == 0) { - g_warning ("mad->frame.header.samplerate is 0; timestamps cannot be calculated"); + g_warning + ("mad->frame.header.samplerate is 0; timestamps cannot be calculated"); time_offset = GST_CLOCK_TIME_NONE; time_duration = GST_CLOCK_TIME_NONE; - } - else { + } else { /* if we have a pending timestamp, we can use it now to calculate the sample offset */ if (GST_CLOCK_TIME_IS_VALID (mad->last_ts)) { - GstFormat format = GST_FORMAT_DEFAULT; - gst_pad_convert (mad->srcpad, GST_FORMAT_TIME, mad->last_ts, &format, &mad->total_samples); + GstFormat format = GST_FORMAT_DEFAULT; + + gst_pad_convert (mad->srcpad, GST_FORMAT_TIME, mad->last_ts, &format, + &mad->total_samples); mad->last_ts = GST_CLOCK_TIME_NONE; } time_offset = mad->total_samples * GST_SECOND - / mad->frame.header.samplerate; - time_duration = (nsamples * GST_SECOND - / mad->frame.header.samplerate); + / mad->frame.header.samplerate; + time_duration = (nsamples * GST_SECOND / mad->frame.header.samplerate); } if (mad->index) { guint64 x_bytes = mad->base_byte_offset + mad->bytes_consumed; gst_index_add_association (mad->index, mad->index_id, 0, - GST_FORMAT_BYTES, x_bytes, - GST_FORMAT_TIME, time_offset, - NULL); + GST_FORMAT_BYTES, x_bytes, GST_FORMAT_TIME, time_offset, NULL); } if (GST_PAD_IS_USABLE (mad->srcpad) && - mad->segment_start <= (time_offset == GST_CLOCK_TIME_NONE ? 0 : time_offset)) { + mad->segment_start <= (time_offset == + GST_CLOCK_TIME_NONE ? 0 : time_offset)) { /* for sample accurate seeking, calculate how many samples to skip and send the remaining pcm samples */ - GstBuffer *outbuffer; - gint16 *outdata; - mad_fixed_t const *left_ch, *right_ch; + GstBuffer *outbuffer; + gint16 *outdata; + mad_fixed_t const *left_ch, *right_ch; - mad_synth_frame (&mad->synth, &mad->frame); - left_ch = mad->synth.pcm.samples[0]; - right_ch = mad->synth.pcm.samples[1]; + mad_synth_frame (&mad->synth, &mad->frame); + left_ch = mad->synth.pcm.samples[0]; + right_ch = mad->synth.pcm.samples[1]; - outbuffer = gst_buffer_new_and_alloc (nsamples * nchannels * 2); - outdata = (gint16 *) GST_BUFFER_DATA (outbuffer); + outbuffer = gst_buffer_new_and_alloc (nsamples * nchannels * 2); + outdata = (gint16 *) GST_BUFFER_DATA (outbuffer); GST_BUFFER_TIMESTAMP (outbuffer) = time_offset; GST_BUFFER_DURATION (outbuffer) = time_duration; GST_BUFFER_OFFSET (outbuffer) = mad->total_samples; - /* output sample(s) in 16-bit signed native-endian PCM */ - if (nchannels == 1) { - gint count = nsamples; - while (count--) { - *outdata++ = scale(*left_ch++) & 0xffff; - } - } else { - gint count = nsamples; - while (count--) { - *outdata++ = scale(*left_ch++) & 0xffff; - *outdata++ = scale(*right_ch++) & 0xffff; - } - } + /* output sample(s) in 16-bit signed native-endian PCM */ + if (nchannels == 1) { + gint count = nsamples; - gst_pad_push (mad->srcpad, GST_DATA (outbuffer)); + while (count--) { + *outdata++ = scale (*left_ch++) & 0xffff; + } + } else { + gint count = nsamples; + + while (count--) { + *outdata++ = scale (*left_ch++) & 0xffff; + *outdata++ = scale (*right_ch++) & 0xffff; + } + } + + gst_pad_push (mad->srcpad, GST_DATA (outbuffer)); } mad->total_samples += nsamples; @@ -1366,7 +1364,7 @@ gst_mad_chain (GstPad *pad, GstData *_data) goto end; } -next: + next: /* figure out how many bytes mad consumed */ consumed = mad->stream.next_frame - mad_input_buffer; /* move out pointer to where mad want the next data */ @@ -1382,7 +1380,7 @@ end: } static GstElementStateReturn -gst_mad_change_state (GstElement *element) +gst_mad_change_state (GstElement * element) { GstMad *mad; @@ -1409,8 +1407,10 @@ gst_mad_change_state (GstElement *element) mad->vbr_rate = 0; mad->frame.header.samplerate = 0; mad->last_ts = GST_CLOCK_TIME_NONE; - if (mad->ignore_crc) options |= MAD_OPTION_IGNORECRC; - if (mad->half) options |= MAD_OPTION_HALFSAMPLERATE; + if (mad->ignore_crc) + options |= MAD_OPTION_IGNORECRC; + if (mad->half) + options |= MAD_OPTION_HALFSAMPLERATE; mad_stream_options (&mad->stream, options); break; } diff --git a/ext/mad/gstmad.h b/ext/mad/gstmad.h index c1300ad2e4..26c2be5961 100644 --- a/ext/mad/gstmad.h +++ b/ext/mad/gstmad.h @@ -26,17 +26,13 @@ #include #include -G_BEGIN_DECLS - +G_BEGIN_DECLS GType gst_mad_get_type (void); +GType gst_id3_parse_get_type (void); +GType gst_id3_tag_get_type (void); -GType gst_mad_get_type (void); -GType gst_id3_parse_get_type (void); -GType gst_id3_tag_get_type (void); +GstTagList *gst_mad_id3_to_tag_list (const struct id3_tag *tag); +struct id3_tag *gst_mad_tag_list_to_id3_tag (GstTagList * list); -GstTagList* gst_mad_id3_to_tag_list (const struct id3_tag * tag); -struct id3_tag * gst_mad_tag_list_to_id3_tag (GstTagList * list); - G_END_DECLS - #endif /* __GST_MAD_H__ */ diff --git a/ext/mpeg2dec/gstmpeg2dec.c b/ext/mpeg2dec/gstmpeg2dec.c index 795dd39bbd..edb193ada4 100644 --- a/ext/mpeg2dec/gstmpeg2dec.c +++ b/ext/mpeg2dec/gstmpeg2dec.c @@ -35,6 +35,7 @@ #define MPEG2_RELEASE MPEG2_VERSION(0,3,1) typedef picture_t mpeg2_picture_t; typedef gint mpeg2_state_t; + #define STATE_BUFFER 0 #endif @@ -49,108 +50,102 @@ static GstElementDetails gst_mpeg2dec_details = { }; /* Mpeg2dec signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, /* FILL ME */ }; static GstStaticPadTemplate src_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-raw-yuv, " - "format = (fourcc) { YV12, I420 }, " - "width = (int) [ 16, 4096 ], " - "height = (int) [ 16, 4096 ], " - "pixel_width = (int) [ 1, 255 ], " - "pixel_height = (int) [ 1, 255 ], " - "framerate = (double) { 23.976024, 24.0, " - "25.0, 29.970030, 30.0, 50.0, 59.940060, 60.0 }") -); +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-raw-yuv, " + "format = (fourcc) { YV12, I420 }, " + "width = (int) [ 16, 4096 ], " + "height = (int) [ 16, 4096 ], " + "pixel_width = (int) [ 1, 255 ], " + "pixel_height = (int) [ 1, 255 ], " + "framerate = (double) { 23.976024, 24.0, " + "25.0, 29.970030, 30.0, 50.0, 59.940060, 60.0 }") + ); #ifdef enable_user_data static GstStaticPadTemplate user_data_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "user_data", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY -); +GST_STATIC_PAD_TEMPLATE ("user_data", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); #endif static GstStaticPadTemplate sink_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/mpeg, " - "mpegversion = (int) [ 1, 2 ], " - "systemstream = (boolean) false" - ) -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/mpeg, " + "mpegversion = (int) [ 1, 2 ], " "systemstream = (boolean) false") + ); -static void gst_mpeg2dec_base_init (gpointer g_class); -static void gst_mpeg2dec_class_init (GstMpeg2decClass *klass); -static void gst_mpeg2dec_init (GstMpeg2dec *mpeg2dec); +static void gst_mpeg2dec_base_init (gpointer g_class); +static void gst_mpeg2dec_class_init (GstMpeg2decClass * klass); +static void gst_mpeg2dec_init (GstMpeg2dec * mpeg2dec); -static void gst_mpeg2dec_dispose (GObject *object); +static void gst_mpeg2dec_dispose (GObject * object); -static void gst_mpeg2dec_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_mpeg2dec_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); -static void gst_mpeg2dec_set_index (GstElement *element, GstIndex *index); -static GstIndex* gst_mpeg2dec_get_index (GstElement *element); +static void gst_mpeg2dec_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_mpeg2dec_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static void gst_mpeg2dec_set_index (GstElement * element, GstIndex * index); +static GstIndex *gst_mpeg2dec_get_index (GstElement * element); -static const GstFormat* - gst_mpeg2dec_get_src_formats (GstPad *pad); -static const GstEventMask* - gst_mpeg2dec_get_src_event_masks (GstPad *pad); -static gboolean gst_mpeg2dec_src_event (GstPad *pad, GstEvent *event); -static const GstQueryType* - gst_mpeg2dec_get_src_query_types (GstPad *pad); -static gboolean gst_mpeg2dec_src_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value); +static const GstFormat *gst_mpeg2dec_get_src_formats (GstPad * pad); +static const GstEventMask *gst_mpeg2dec_get_src_event_masks (GstPad * pad); +static gboolean gst_mpeg2dec_src_event (GstPad * pad, GstEvent * event); +static const GstQueryType *gst_mpeg2dec_get_src_query_types (GstPad * pad); +static gboolean gst_mpeg2dec_src_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value); -static const GstFormat* - gst_mpeg2dec_get_sink_formats (GstPad *pad); -static gboolean gst_mpeg2dec_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value); -static gboolean gst_mpeg2dec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value); +static const GstFormat *gst_mpeg2dec_get_sink_formats (GstPad * pad); +static gboolean gst_mpeg2dec_convert_sink (GstPad * pad, GstFormat src_format, + gint64 src_value, GstFormat * dest_format, gint64 * dest_value); +static gboolean gst_mpeg2dec_convert_src (GstPad * pad, GstFormat src_format, + gint64 src_value, GstFormat * dest_format, gint64 * dest_value); -static GstElementStateReturn - gst_mpeg2dec_change_state (GstElement *element); +static GstElementStateReturn gst_mpeg2dec_change_state (GstElement * element); -static void gst_mpeg2dec_chain (GstPad *pad, GstData *_data); +static void gst_mpeg2dec_chain (GstPad * pad, GstData * _data); static GstElementClass *parent_class = NULL; + /*static guint gst_mpeg2dec_signals[LAST_SIGNAL] = { 0 };*/ GType gst_mpeg2dec_get_type (void) { static GType mpeg2dec_type = 0; - + if (!mpeg2dec_type) { static const GTypeInfo mpeg2dec_info = { - sizeof(GstMpeg2decClass), + sizeof (GstMpeg2decClass), gst_mpeg2dec_base_init, NULL, - (GClassInitFunc)gst_mpeg2dec_class_init, + (GClassInitFunc) gst_mpeg2dec_class_init, NULL, NULL, - sizeof(GstMpeg2dec), + sizeof (GstMpeg2dec), 0, - (GInstanceInitFunc)gst_mpeg2dec_init, + (GInstanceInitFunc) gst_mpeg2dec_init, }; - mpeg2dec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMpeg2dec", &mpeg2dec_info, 0); + mpeg2dec_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstMpeg2dec", &mpeg2dec_info, + 0); } return mpeg2dec_type; } @@ -160,59 +155,74 @@ gst_mpeg2dec_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_template_factory)); - gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&sink_template_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template_factory)); #ifdef enable_user_data - gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&user_data_template_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&user_data_template_factory)); #endif gst_element_class_set_details (element_class, &gst_mpeg2dec_details); } static void -gst_mpeg2dec_class_init(GstMpeg2decClass *klass) +gst_mpeg2dec_class_init (GstMpeg2decClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - gobject_class->set_property = gst_mpeg2dec_set_property; - gobject_class->get_property = gst_mpeg2dec_get_property; - gobject_class->dispose = gst_mpeg2dec_dispose; + gobject_class->set_property = gst_mpeg2dec_set_property; + gobject_class->get_property = gst_mpeg2dec_get_property; + gobject_class->dispose = gst_mpeg2dec_dispose; gstelement_class->change_state = gst_mpeg2dec_change_state; - gstelement_class->set_index = gst_mpeg2dec_set_index; - gstelement_class->get_index = gst_mpeg2dec_get_index; + gstelement_class->set_index = gst_mpeg2dec_set_index; + gstelement_class->get_index = gst_mpeg2dec_get_index; } static void -gst_mpeg2dec_init (GstMpeg2dec *mpeg2dec) +gst_mpeg2dec_init (GstMpeg2dec * mpeg2dec) { /* create the sink and src pads */ - mpeg2dec->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&sink_template_factory), "sink"); + mpeg2dec->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&sink_template_factory), "sink"); gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->sinkpad); - gst_pad_set_chain_function (mpeg2dec->sinkpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_chain)); - gst_pad_set_formats_function (mpeg2dec->sinkpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_sink_formats)); - gst_pad_set_convert_function (mpeg2dec->sinkpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_convert_sink)); + gst_pad_set_chain_function (mpeg2dec->sinkpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_chain)); + gst_pad_set_formats_function (mpeg2dec->sinkpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_sink_formats)); + gst_pad_set_convert_function (mpeg2dec->sinkpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_convert_sink)); - mpeg2dec->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&src_template_factory), "src"); + mpeg2dec->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&src_template_factory), "src"); gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->srcpad); gst_pad_use_explicit_caps (mpeg2dec->srcpad); - gst_pad_set_formats_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_formats)); - gst_pad_set_event_mask_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_event_masks)); - gst_pad_set_event_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_event)); - gst_pad_set_query_type_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_query_types)); - gst_pad_set_query_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_query)); - gst_pad_set_convert_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_convert_src)); + gst_pad_set_formats_function (mpeg2dec->srcpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_formats)); + gst_pad_set_event_mask_function (mpeg2dec->srcpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_event_masks)); + gst_pad_set_event_function (mpeg2dec->srcpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_event)); + gst_pad_set_query_type_function (mpeg2dec->srcpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_query_types)); + gst_pad_set_query_function (mpeg2dec->srcpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_query)); + gst_pad_set_convert_function (mpeg2dec->srcpad, + GST_DEBUG_FUNCPTR (gst_mpeg2dec_convert_src)); #ifdef enable_user_data - mpeg2dec->userdatapad = gst_pad_new_from_template ( - gst_static_pad_template_get (&user_data_template_factory), "user_data"); + mpeg2dec->userdatapad = + gst_pad_new_from_template (gst_static_pad_template_get + (&user_data_template_factory), "user_data"); gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->userdatapad); #endif @@ -225,7 +235,7 @@ gst_mpeg2dec_init (GstMpeg2dec *mpeg2dec) } static void -gst_mpeg2dec_close_decoder (GstMpeg2dec *mpeg2dec) +gst_mpeg2dec_close_decoder (GstMpeg2dec * mpeg2dec) { if (!mpeg2dec->closed) { mpeg2_close (mpeg2dec->decoder); @@ -235,7 +245,7 @@ gst_mpeg2dec_close_decoder (GstMpeg2dec *mpeg2dec) } static void -gst_mpeg2dec_open_decoder (GstMpeg2dec *mpeg2dec) +gst_mpeg2dec_open_decoder (GstMpeg2dec * mpeg2dec) { gst_mpeg2dec_close_decoder (mpeg2dec); mpeg2dec->decoder = mpeg2_init (); @@ -244,7 +254,7 @@ gst_mpeg2dec_open_decoder (GstMpeg2dec *mpeg2dec) } static void -gst_mpeg2dec_dispose (GObject *object) +gst_mpeg2dec_dispose (GObject * object) { GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (object); @@ -254,25 +264,26 @@ gst_mpeg2dec_dispose (GObject *object) } static void -gst_mpeg2dec_set_index (GstElement *element, GstIndex *index) +gst_mpeg2dec_set_index (GstElement * element, GstIndex * index) { GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element); - + mpeg2dec->index = index; gst_index_get_writer_id (index, GST_OBJECT (element), &mpeg2dec->index_id); } -static GstIndex* -gst_mpeg2dec_get_index (GstElement *element) +static GstIndex * +gst_mpeg2dec_get_index (GstElement * element) { GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element); return mpeg2dec->index; } -static GstBuffer* -gst_mpeg2dec_alloc_buffer (GstMpeg2dec *mpeg2dec, const mpeg2_info_t *info, gint64 offset) +static GstBuffer * +gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info, + gint64 offset) { GstBuffer *outbuf = NULL; gint size = mpeg2dec->width * mpeg2dec->height; @@ -286,11 +297,10 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec *mpeg2dec, const mpeg2_info_t *info, gint buf[0] = out; if (mpeg2dec->format == MPEG2DEC_FORMAT_I420) { buf[1] = buf[0] + size; - buf[2] = buf[1] + size/4; - } - else { + buf[2] = buf[1] + size / 4; + } else { buf[2] = buf[0] + size; - buf[1] = buf[2] + size/4; + buf[1] = buf[2] + size / 4; } gst_buffer_ref (outbuf); @@ -298,10 +308,10 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec *mpeg2dec, const mpeg2_info_t *info, gint picture = info->current_picture; - if (picture && (picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) { + if (picture + && (picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) { GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT); - } - else { + } else { GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_KEY_UNIT); } /* we store the original byteoffset of this picture in the stream here @@ -312,7 +322,7 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec *mpeg2dec, const mpeg2_info_t *info, gint } static gboolean -gst_mpeg2dec_negotiate_format (GstMpeg2dec *mpeg2dec) +gst_mpeg2dec_negotiate_format (GstMpeg2dec * mpeg2dec) { GstCaps *caps; guint32 fourcc; @@ -324,21 +334,22 @@ gst_mpeg2dec_negotiate_format (GstMpeg2dec *mpeg2dec) } caps = gst_caps_new_simple ("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, GST_STR_FOURCC ("I420"), - "width", G_TYPE_INT, mpeg2dec->width, - "height", G_TYPE_INT, mpeg2dec->height, - "pixel_width", G_TYPE_INT, mpeg2dec->pixel_width, + "format", GST_TYPE_FOURCC, GST_STR_FOURCC ("I420"), + "width", G_TYPE_INT, mpeg2dec->width, + "height", G_TYPE_INT, mpeg2dec->height, + "pixel_width", G_TYPE_INT, mpeg2dec->pixel_width, "pixel_height", G_TYPE_INT, mpeg2dec->pixel_height, - "framerate", G_TYPE_DOUBLE, 1. * GST_SECOND / mpeg2dec->frame_period, + "framerate", G_TYPE_DOUBLE, 1. * GST_SECOND / mpeg2dec->frame_period, NULL); ret = gst_pad_set_explicit_caps (mpeg2dec->srcpad, caps); - if (!ret) return FALSE; + if (!ret) + return FALSE; /* it worked, try to find what it was again */ - gst_structure_get_fourcc (gst_caps_get_structure (caps,0), + gst_structure_get_fourcc (gst_caps_get_structure (caps, 0), "format", &fourcc); - + if (fourcc == GST_STR_FOURCC ("I420")) { mpeg2dec->format = MPEG2DEC_FORMAT_I420; } else { @@ -350,7 +361,7 @@ gst_mpeg2dec_negotiate_format (GstMpeg2dec *mpeg2dec) #if 0 static void -update_streaminfo (GstMpeg2dec *mpeg2dec) +update_streaminfo (GstMpeg2dec * mpeg2dec) { GstCaps *caps; GstProps *props; @@ -361,14 +372,17 @@ update_streaminfo (GstMpeg2dec *mpeg2dec) props = gst_props_empty_new (); - entry = gst_props_entry_new ("framerate", G_TYPE_DOUBLE (GST_SECOND/(float)mpeg2dec->frame_period)); + entry = + gst_props_entry_new ("framerate", + G_TYPE_DOUBLE (GST_SECOND / (float) mpeg2dec->frame_period)); gst_props_add_entry (props, entry); - entry = gst_props_entry_new ("bitrate", G_TYPE_INT (info->sequence->byte_rate * 8)); + entry = + gst_props_entry_new ("bitrate", + G_TYPE_INT (info->sequence->byte_rate * 8)); gst_props_add_entry (props, entry); caps = gst_caps_new ("mpeg2dec_streaminfo", - "application/x-gst-streaminfo", - props); + "application/x-gst-streaminfo", props); gst_caps_replace_sink (&mpeg2dec->streaminfo, caps); g_object_notify (G_OBJECT (mpeg2dec), "streaminfo"); @@ -376,7 +390,7 @@ update_streaminfo (GstMpeg2dec *mpeg2dec) #endif static void -gst_mpeg2dec_flush_decoder (GstMpeg2dec *mpeg2dec) +gst_mpeg2dec_flush_decoder (GstMpeg2dec * mpeg2dec) { mpeg2_state_t state; @@ -387,16 +401,16 @@ gst_mpeg2dec_flush_decoder (GstMpeg2dec *mpeg2dec) state = mpeg2_parse (mpeg2dec->decoder); if (state == STATE_END) { if (info->discard_fbuf && info->discard_fbuf->id) { - gst_buffer_unref ((GstBuffer *)info->discard_fbuf->id); + gst_buffer_unref ((GstBuffer *) info->discard_fbuf->id); } } - } + } while (state != STATE_BUFFER && state != -1); } } static void -gst_mpeg2dec_chain (GstPad *pad, GstData *_data) +gst_mpeg2dec_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); @@ -413,19 +427,19 @@ gst_mpeg2dec_chain (GstPad *pad, GstData *_data) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_DISCONTINUOUS: { - GST_DEBUG ("discont"); - mpeg2dec->next_time = 0; - mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE; + GST_DEBUG ("discont"); + mpeg2dec->next_time = 0; + mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE; gst_mpeg2dec_flush_decoder (mpeg2dec); - gst_pad_event_default (pad, event); + gst_pad_event_default (pad, event); return; } case GST_EVENT_EOS: if (mpeg2dec->index && mpeg2dec->closed) { gst_index_commit (mpeg2dec->index, mpeg2dec->index_id); - } + } default: - gst_pad_event_default (pad, event); + gst_pad_event_default (pad, event); return; } } @@ -440,16 +454,16 @@ gst_mpeg2dec_chain (GstPad *pad, GstData *_data) if (pts != -1) { gint64 mpeg_pts = GSTTIME_TO_MPEGTIME (pts); - GST_DEBUG ("have pts: %" G_GINT64_FORMAT " (%" G_GINT64_FORMAT ")", - mpeg_pts, MPEGTIME_TO_GSTTIME (mpeg_pts)); + GST_DEBUG ("have pts: %" G_GINT64_FORMAT " (%" G_GINT64_FORMAT ")", + mpeg_pts, MPEGTIME_TO_GSTTIME (mpeg_pts)); #if MPEG2_RELEASE >= MPEG2_VERSION(0,4,0) - mpeg2_tag_picture (mpeg2dec->decoder, mpeg_pts&0xffffffff, mpeg_pts>>32); + mpeg2_tag_picture (mpeg2dec->decoder, mpeg_pts & 0xffffffff, + mpeg_pts >> 32); #else mpeg2_pts (mpeg2dec->decoder, mpeg_pts); #endif - } - else { + } else { GST_DEBUG ("no pts"); } @@ -471,17 +485,19 @@ gst_mpeg2dec_chain (GstPad *pad, GstData *_data) mpeg2dec->pixel_width = info->sequence->pixel_width; mpeg2dec->pixel_height = info->sequence->pixel_height; mpeg2dec->total_frames = 0; - mpeg2dec->frame_period = info->sequence->frame_period * GST_USECOND / 27; + mpeg2dec->frame_period = + info->sequence->frame_period * GST_USECOND / 27; - GST_DEBUG ("sequence flags: %d, frame period: %d", - info->sequence->flags, info->sequence->frame_period); - GST_DEBUG ("profile: %02x, colour_primaries: %d", - info->sequence->profile_level_id, info->sequence->colour_primaries); - GST_DEBUG ("transfer chars: %d, matrix coef: %d", - info->sequence->transfer_characteristics, info->sequence->matrix_coefficients); + GST_DEBUG ("sequence flags: %d, frame period: %d", + info->sequence->flags, info->sequence->frame_period); + GST_DEBUG ("profile: %02x, colour_primaries: %d", + info->sequence->profile_level_id, info->sequence->colour_primaries); + GST_DEBUG ("transfer chars: %d, matrix coef: %d", + info->sequence->transfer_characteristics, + info->sequence->matrix_coefficients); if (!gst_mpeg2dec_negotiate_format (mpeg2dec)) { - GST_ELEMENT_ERROR (mpeg2dec, CORE, NEGOTIATION, (NULL), (NULL)); + GST_ELEMENT_ERROR (mpeg2dec, CORE, NEGOTIATION, (NULL), (NULL)); goto exit; } @@ -495,29 +511,34 @@ gst_mpeg2dec_chain (GstPad *pad, GstData *_data) mpeg2dec->need_sequence = FALSE; if (mpeg2dec->pending_event) { - done = GST_EVENT_SEEK_FLAGS (mpeg2dec->pending_event) & GST_SEEK_FLAG_FLUSH; - - gst_mpeg2dec_src_event (mpeg2dec->srcpad, mpeg2dec->pending_event); + done = + GST_EVENT_SEEK_FLAGS (mpeg2dec-> + pending_event) & GST_SEEK_FLAG_FLUSH; + + gst_mpeg2dec_src_event (mpeg2dec->srcpad, mpeg2dec->pending_event); mpeg2dec->pending_event = NULL; } - break; + break; } case STATE_SEQUENCE_REPEATED: GST_DEBUG ("sequence repeated"); case STATE_GOP: - break; + break; case STATE_PICTURE: { gboolean key_frame = FALSE; GstBuffer *outbuf; - if (info->current_picture) { - key_frame = (info->current_picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I; + if (info->current_picture) { + key_frame = + (info->current_picture->flags & PIC_MASK_CODING_TYPE) == + PIC_FLAG_CODING_TYPE_I; } - outbuf = gst_mpeg2dec_alloc_buffer (mpeg2dec, info, GST_BUFFER_OFFSET (buf)); + outbuf = + gst_mpeg2dec_alloc_buffer (mpeg2dec, info, GST_BUFFER_OFFSET (buf)); - GST_DEBUG ("picture %d, %p, %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT, - key_frame, outbuf, GST_BUFFER_OFFSET (outbuf), pts); + GST_DEBUG ("picture %d, %p, %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT, + key_frame, outbuf, GST_BUFFER_OFFSET (outbuf), pts); if (mpeg2dec->discont_state == MPEG2DEC_DISC_NEW_PICTURE && key_frame) mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_KEYFRAME; @@ -527,14 +548,14 @@ gst_mpeg2dec_chain (GstPad *pad, GstData *_data) else mpeg2_skip (mpeg2dec->decoder, 0); - break; + break; } case STATE_SLICE_1ST: GST_DEBUG ("slice 1st"); - break; + break; case STATE_PICTURE_2ND: GST_DEBUG ("picture second"); - break; + break; case STATE_SLICE: slice = TRUE; #if MPEG2_RELEASE >= MPEG2_VERSION (0, 4, 0) @@ -548,95 +569,97 @@ gst_mpeg2dec_chain (GstPad *pad, GstData *_data) if (!slice) { mpeg2dec->need_sequence = TRUE; } - GST_DEBUG ("picture end %p %p %p %p", info->display_fbuf, info->display_picture, info->current_picture, - (info->display_fbuf ? info->display_fbuf->id : NULL)); + GST_DEBUG ("picture end %p %p %p %p", info->display_fbuf, + info->display_picture, info->current_picture, + (info->display_fbuf ? info->display_fbuf->id : NULL)); if (info->display_fbuf && info->display_fbuf->id) { - const mpeg2_picture_t *picture; + const mpeg2_picture_t *picture; gboolean key_frame = FALSE; - + outbuf = (GstBuffer *) info->display_fbuf->id; picture = info->display_picture; - key_frame = (picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I; + key_frame = + (picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I; GST_DEBUG ("picture keyfame %d", key_frame); if (key_frame) { - GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT); + GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT); } - if (mpeg2dec->discont_state == MPEG2DEC_DISC_NEW_KEYFRAME && key_frame) + if (mpeg2dec->discont_state == MPEG2DEC_DISC_NEW_KEYFRAME + && key_frame) mpeg2dec->discont_state = MPEG2DEC_DISC_NONE; #if MPEG2_RELEASE < MPEG2_VERSION(0,4,0) if (picture->flags & PIC_FLAG_PTS) { - GstClockTime time = MPEGTIME_TO_GSTTIME (picture->pts); + GstClockTime time = MPEGTIME_TO_GSTTIME (picture->pts); #else - if (picture->flags & PIC_FLAG_TAGS) { - GstClockTime time = MPEGTIME_TO_GSTTIME ((guint64) picture->tag2 << 32 | picture->tag); + if (picture->flags & PIC_FLAG_TAGS) { + GstClockTime time = + MPEGTIME_TO_GSTTIME ((guint64) picture->tag2 << 32 | picture-> + tag); #endif GST_DEBUG ("picture had pts %" G_GINT64_FORMAT, time); - GST_BUFFER_TIMESTAMP (outbuf) = mpeg2dec->next_time = time; - } - else { - GST_DEBUG ("picture didn't have pts using %" G_GINT64_FORMAT, mpeg2dec->next_time); - GST_BUFFER_TIMESTAMP (outbuf) = mpeg2dec->next_time; + GST_BUFFER_TIMESTAMP (outbuf) = mpeg2dec->next_time = time; + } else { + GST_DEBUG ("picture didn't have pts using %" G_GINT64_FORMAT, + mpeg2dec->next_time); + GST_BUFFER_TIMESTAMP (outbuf) = mpeg2dec->next_time; } - mpeg2dec->next_time += (mpeg2dec->frame_period * picture->nb_fields) >> 1; + mpeg2dec->next_time += + (mpeg2dec->frame_period * picture->nb_fields) >> 1; - GST_DEBUG ("picture: %s %s fields:%d off:%" G_GINT64_FORMAT " ts:%" G_GINT64_FORMAT, - (picture->flags & PIC_FLAG_TOP_FIELD_FIRST ? "tff " : " "), - (picture->flags & PIC_FLAG_PROGRESSIVE_FRAME ? "prog" : " "), - picture->nb_fields, - GST_BUFFER_OFFSET (outbuf), - GST_BUFFER_TIMESTAMP (outbuf)); + GST_DEBUG ("picture: %s %s fields:%d off:%" G_GINT64_FORMAT " ts:%" + G_GINT64_FORMAT, + (picture->flags & PIC_FLAG_TOP_FIELD_FIRST ? "tff " : " "), + (picture->flags & PIC_FLAG_PROGRESSIVE_FRAME ? "prog" : " "), + picture->nb_fields, GST_BUFFER_OFFSET (outbuf), + GST_BUFFER_TIMESTAMP (outbuf)); if (mpeg2dec->index) { - gst_index_add_association (mpeg2dec->index, mpeg2dec->index_id, - (key_frame ? GST_ASSOCIATION_FLAG_KEY_UNIT : 0), - GST_FORMAT_BYTES, GST_BUFFER_OFFSET (outbuf), - GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (outbuf), 0); + gst_index_add_association (mpeg2dec->index, mpeg2dec->index_id, + (key_frame ? GST_ASSOCIATION_FLAG_KEY_UNIT : 0), + GST_FORMAT_BYTES, GST_BUFFER_OFFSET (outbuf), + GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (outbuf), 0); } - - if (picture->flags & PIC_FLAG_SKIP || - !GST_PAD_IS_USABLE (mpeg2dec->srcpad) || + + if (picture->flags & PIC_FLAG_SKIP || + !GST_PAD_IS_USABLE (mpeg2dec->srcpad) || mpeg2dec->discont_state != MPEG2DEC_DISC_NONE || - mpeg2dec->next_time < mpeg2dec->segment_start || - skip) - { + mpeg2dec->next_time < mpeg2dec->segment_start || skip) { gst_buffer_unref (outbuf); - } - else { + } else { /* TODO set correct offset here based on frame number */ GST_BUFFER_DURATION (outbuf) = mpeg2dec->frame_period; gst_pad_push (mpeg2dec->srcpad, GST_DATA (outbuf)); } } if (info->discard_fbuf && info->discard_fbuf->id) { - gst_buffer_unref ((GstBuffer *)info->discard_fbuf->id); + gst_buffer_unref ((GstBuffer *) info->discard_fbuf->id); } - break; + break; } - /* need more data */ + /* need more data */ case STATE_BUFFER: case -1: done = TRUE; break; - /* error */ + /* error */ case STATE_INVALID: g_warning ("mpeg2dec: decoding error"); /* it looks like setting a new frame in libmpeg2 avoids a crash */ /* FIXME figure out how this screws up sync and buffer leakage */ gst_mpeg2dec_alloc_buffer (mpeg2dec, info, GST_BUFFER_OFFSET (buf)); - break; + break; default: - g_warning ("%s: unhandled state %d, FIXME", - gst_element_get_name (GST_ELEMENT (mpeg2dec)), - state); - break; + g_warning ("%s: unhandled state %d, FIXME", + gst_element_get_name (GST_ELEMENT (mpeg2dec)), state); + break; } /* @@ -645,21 +668,21 @@ gst_mpeg2dec_chain (GstPad *pad, GstData *_data) #ifdef enable_user_data if (info->user_data_len > 0) { if (GST_PAD_IS_USABLE (mpeg2dec->userdatapad)) { - GstBuffer *udbuf = gst_buffer_new_and_alloc (info->user_data_len); + GstBuffer *udbuf = gst_buffer_new_and_alloc (info->user_data_len); - memcpy (GST_BUFFER_DATA (udbuf), info->user_data, info->user_data_len); + memcpy (GST_BUFFER_DATA (udbuf), info->user_data, info->user_data_len); - gst_pad_push (mpeg2dec->userdatapad, GST_DATA (udbuf)); + gst_pad_push (mpeg2dec->userdatapad, GST_DATA (udbuf)); } } #endif } exit: - gst_buffer_unref(buf); + gst_buffer_unref (buf); } -static const GstFormat* -gst_mpeg2dec_get_sink_formats (GstPad *pad) +static const GstFormat * +gst_mpeg2dec_get_sink_formats (GstPad * pad) { static const GstFormat formats[] = { GST_FORMAT_BYTES, @@ -670,13 +693,13 @@ gst_mpeg2dec_get_sink_formats (GstPad *pad) } static gboolean -gst_mpeg2dec_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value) +gst_mpeg2dec_convert_sink (GstPad * pad, GstFormat src_format, gint64 src_value, + GstFormat * dest_format, gint64 * dest_value) { gboolean res = TRUE; GstMpeg2dec *mpeg2dec; const mpeg2_info_t *info; - + mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); if (mpeg2dec->decoder == NULL) @@ -687,24 +710,24 @@ gst_mpeg2dec_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value, switch (src_format) { case GST_FORMAT_BYTES: switch (*dest_format) { - case GST_FORMAT_TIME: + case GST_FORMAT_TIME: if (info->sequence && info->sequence->byte_rate) { - *dest_value = GST_SECOND * src_value / info->sequence->byte_rate; - break; + *dest_value = GST_SECOND * src_value / info->sequence->byte_rate; + break; } - default: - res = FALSE; + default: + res = FALSE; } break; case GST_FORMAT_TIME: switch (*dest_format) { - case GST_FORMAT_BYTES: + case GST_FORMAT_BYTES: if (info->sequence && info->sequence->byte_rate) { - *dest_value = src_value * info->sequence->byte_rate / GST_SECOND; - break; + *dest_value = src_value * info->sequence->byte_rate / GST_SECOND; + break; } - default: - res = FALSE; + default: + res = FALSE; } break; default: @@ -713,8 +736,8 @@ gst_mpeg2dec_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value, return res; } -static const GstFormat* -gst_mpeg2dec_get_src_formats (GstPad *pad) +static const GstFormat * +gst_mpeg2dec_get_src_formats (GstPad * pad) { static const GstFormat formats[] = { GST_FORMAT_BYTES, @@ -726,14 +749,14 @@ gst_mpeg2dec_get_src_formats (GstPad *pad) } static gboolean -gst_mpeg2dec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value) +gst_mpeg2dec_convert_src (GstPad * pad, GstFormat src_format, gint64 src_value, + GstFormat * dest_format, gint64 * dest_value) { gboolean res = TRUE; GstMpeg2dec *mpeg2dec; const mpeg2_info_t *info; guint64 scale = 1; - + mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); if (mpeg2dec->decoder == NULL) @@ -744,34 +767,35 @@ gst_mpeg2dec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, switch (src_format) { case GST_FORMAT_BYTES: switch (*dest_format) { - case GST_FORMAT_TIME: - default: - res = FALSE; + case GST_FORMAT_TIME: + default: + res = FALSE; } break; case GST_FORMAT_TIME: switch (*dest_format) { - case GST_FORMAT_BYTES: + case GST_FORMAT_BYTES: scale = 6 * (mpeg2dec->width * mpeg2dec->height >> 2); - case GST_FORMAT_DEFAULT: + case GST_FORMAT_DEFAULT: if (info->sequence && mpeg2dec->frame_period) { - *dest_value = src_value * scale / mpeg2dec->frame_period; - break; + *dest_value = src_value * scale / mpeg2dec->frame_period; + break; } - default: - res = FALSE; + default: + res = FALSE; } break; case GST_FORMAT_DEFAULT: switch (*dest_format) { - case GST_FORMAT_TIME: - *dest_value = src_value * mpeg2dec->frame_period; + case GST_FORMAT_TIME: + *dest_value = src_value * mpeg2dec->frame_period; break; - case GST_FORMAT_BYTES: - *dest_value = src_value * 6 * ((mpeg2dec->width * mpeg2dec->height) >> 2); + case GST_FORMAT_BYTES: + *dest_value = + src_value * 6 * ((mpeg2dec->width * mpeg2dec->height) >> 2); break; - default: - res = FALSE; + default: + res = FALSE; } break; default: @@ -780,8 +804,8 @@ gst_mpeg2dec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, return res; } -static const GstQueryType* -gst_mpeg2dec_get_src_query_types (GstPad *pad) +static const GstQueryType * +gst_mpeg2dec_get_src_query_types (GstPad * pad) { static const GstQueryType types[] = { GST_QUERY_TOTAL, @@ -791,9 +815,9 @@ gst_mpeg2dec_get_src_query_types (GstPad *pad) return types; } -static gboolean -gst_mpeg2dec_src_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value) +static gboolean +gst_mpeg2dec_src_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value) { gboolean res = TRUE; GstMpeg2dec *mpeg2dec; @@ -805,56 +829,52 @@ gst_mpeg2dec_src_query (GstPad *pad, GstQueryType type, case GST_QUERY_TOTAL: { switch (*format) { - case GST_FORMAT_TIME: - case GST_FORMAT_BYTES: - case GST_FORMAT_DEFAULT: + case GST_FORMAT_TIME: + case GST_FORMAT_BYTES: + case GST_FORMAT_DEFAULT: { - res = FALSE; + res = FALSE; - /* get our peer formats */ - formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad)); + /* get our peer formats */ + formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad)); - /* while we did not exhaust our seek formats without result */ - while (formats && *formats) { + /* while we did not exhaust our seek formats without result */ + while (formats && *formats) { GstFormat peer_format; gint64 peer_value; - - peer_format = *formats; - - /* do the probe */ - if (gst_pad_query (GST_PAD_PEER (mpeg2dec->sinkpad), GST_QUERY_TOTAL, - &peer_format, &peer_value)) - { - GstFormat conv_format; - /* convert to TIME */ - conv_format = GST_FORMAT_TIME; - res = gst_pad_convert (mpeg2dec->sinkpad, - peer_format, peer_value, - &conv_format, value); - /* and to final format */ - res &= gst_pad_convert (pad, - GST_FORMAT_TIME, *value, - format, value); - } + peer_format = *formats; + + /* do the probe */ + if (gst_pad_query (GST_PAD_PEER (mpeg2dec->sinkpad), + GST_QUERY_TOTAL, &peer_format, &peer_value)) { + GstFormat conv_format; + + /* convert to TIME */ + conv_format = GST_FORMAT_TIME; + res = gst_pad_convert (mpeg2dec->sinkpad, + peer_format, peer_value, &conv_format, value); + /* and to final format */ + res &= gst_pad_convert (pad, + GST_FORMAT_TIME, *value, format, value); + } formats++; } - break; + break; } - default: + default: res = FALSE; - break; + break; } break; } case GST_QUERY_POSITION: { switch (*format) { - default: - res = gst_pad_convert (pad, - GST_FORMAT_TIME, mpeg2dec->next_time, - format, value); - break; + default: + res = gst_pad_convert (pad, + GST_FORMAT_TIME, mpeg2dec->next_time, format, value); + break; } break; } @@ -867,38 +887,37 @@ gst_mpeg2dec_src_query (GstPad *pad, GstQueryType type, } -static const GstEventMask* -gst_mpeg2dec_get_src_event_masks (GstPad *pad) +static const GstEventMask * +gst_mpeg2dec_get_src_event_masks (GstPad * pad) { static const GstEventMask masks[] = { - { GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH }, - { GST_EVENT_NAVIGATION, GST_EVENT_FLAG_NONE }, - { 0, } + {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH}, + {GST_EVENT_NAVIGATION, GST_EVENT_FLAG_NONE}, + {0,} }; return masks; } -static gboolean -index_seek (GstPad *pad, GstEvent *event) +static gboolean +index_seek (GstPad * pad, GstEvent * event) { GstIndexEntry *entry; GstMpeg2dec *mpeg2dec; mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); - + entry = gst_index_get_assoc_entry (mpeg2dec->index, mpeg2dec->index_id, - GST_INDEX_LOOKUP_BEFORE, GST_ASSOCIATION_FLAG_KEY_UNIT, - GST_EVENT_SEEK_FORMAT (event), - GST_EVENT_SEEK_OFFSET (event)); + GST_INDEX_LOOKUP_BEFORE, GST_ASSOCIATION_FLAG_KEY_UNIT, + GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event)); if (entry) { const GstFormat *peer_formats, *try_formats; + /* since we know the exaxt byteoffset of the frame, make sure to seek on bytes first */ - const GstFormat try_all_formats[] = - { - GST_FORMAT_BYTES, - GST_FORMAT_TIME, - 0 + const GstFormat try_all_formats[] = { + GST_FORMAT_BYTES, + GST_FORMAT_TIME, + 0 }; try_formats = try_all_formats; @@ -906,26 +925,27 @@ index_seek (GstPad *pad, GstEvent *event) while (gst_formats_contains (peer_formats, *try_formats)) { gint64 value; - + if (gst_index_entry_assoc_map (entry, *try_formats, &value)) { - GstEvent *seek_event; + GstEvent *seek_event; GST_CAT_DEBUG (GST_CAT_SEEK, "index %s %" G_GINT64_FORMAT - " -> %s %" G_GINT64_FORMAT, - gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, - GST_EVENT_SEEK_OFFSET (event), - gst_format_get_details (*try_formats)->nick, - value); + " -> %s %" G_GINT64_FORMAT, + gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, + GST_EVENT_SEEK_OFFSET (event), + gst_format_get_details (*try_formats)->nick, value); - /* lookup succeeded, create the seek */ - seek_event = gst_event_new_seek (*try_formats | GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, value); - /* do the seekk */ - if (gst_pad_send_event (GST_PAD_PEER (mpeg2dec->sinkpad), seek_event)) { - /* seek worked, we're done, loop will exit */ + /* lookup succeeded, create the seek */ + seek_event = + gst_event_new_seek (*try_formats | GST_SEEK_METHOD_SET | + GST_SEEK_FLAG_FLUSH, value); + /* do the seekk */ + if (gst_pad_send_event (GST_PAD_PEER (mpeg2dec->sinkpad), seek_event)) { + /* seek worked, we're done, loop will exit */ gst_mpeg2dec_flush_decoder (mpeg2dec); mpeg2dec->segment_start = GST_EVENT_SEEK_OFFSET (event); - return TRUE; - } + return TRUE; + } } try_formats++; } @@ -934,8 +954,8 @@ index_seek (GstPad *pad, GstEvent *event) } -static gboolean -normal_seek (GstPad *pad, GstEvent *event) +static gboolean +normal_seek (GstPad * pad, GstEvent * event) { gint64 src_offset; gboolean flush; @@ -950,9 +970,8 @@ normal_seek (GstPad *pad, GstEvent *event) /* first bring the src_format to TIME */ if (!gst_pad_convert (pad, - GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event), - &format, &src_offset)) - { + GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event), + &format, &src_offset)) { /* didn't work, probably unsupported seek format then */ return res; } @@ -970,17 +989,19 @@ normal_seek (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 (mpeg2dec->sinkpad, GST_FORMAT_TIME, src_offset, &format, &desired_offset)) - { + if (gst_pad_convert (mpeg2dec->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 seekk */ if (gst_pad_send_event (GST_PAD_PEER (mpeg2dec->sinkpad), seek_event)) { - /* seek worked, we're done, loop will exit */ + /* seek worked, we're done, loop will exit */ mpeg2dec->segment_start = GST_EVENT_SEEK_OFFSET (event); - res = TRUE; + res = TRUE; break; } } @@ -995,8 +1016,9 @@ normal_seek (GstPad *pad, GstEvent *event) return res; } -static gboolean -gst_mpeg2dec_src_event (GstPad *pad, GstEvent *event) + +static gboolean +gst_mpeg2dec_src_event (GstPad * pad, GstEvent * event) { gboolean res = TRUE; GstMpeg2dec *mpeg2dec; @@ -1007,20 +1029,19 @@ gst_mpeg2dec_src_event (GstPad *pad, GstEvent *event) return FALSE; switch (GST_EVENT_TYPE (event)) { - /* the all-formats seek logic */ + /* the all-formats seek logic */ case GST_EVENT_SEEK: if (mpeg2dec->need_sequence) { - mpeg2dec->pending_event = event; + mpeg2dec->pending_event = event; return TRUE; - } - else { - if (mpeg2dec->index) - res = index_seek (pad, event); + } else { + if (mpeg2dec->index) + res = index_seek (pad, event); else - res = normal_seek (pad, event); - + res = normal_seek (pad, event); + if (res) - mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE; + mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE; } break; case GST_EVENT_NAVIGATION: @@ -1035,11 +1056,11 @@ gst_mpeg2dec_src_event (GstPad *pad, GstEvent *event) } static GstElementStateReturn -gst_mpeg2dec_change_state (GstElement *element) +gst_mpeg2dec_change_state (GstElement * element) { GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element); - switch (GST_STATE_TRANSITION (element)) { + switch (GST_STATE_TRANSITION (element)) { case GST_STATE_NULL_TO_READY: break; case GST_STATE_READY_TO_PAUSED: @@ -1075,7 +1096,8 @@ gst_mpeg2dec_change_state (GstElement *element) } static void -gst_mpeg2dec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_mpeg2dec_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstMpeg2dec *src; @@ -1090,7 +1112,8 @@ gst_mpeg2dec_set_property (GObject *object, guint prop_id, const GValue *value, } static void -gst_mpeg2dec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_mpeg2dec_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstMpeg2dec *mpeg2dec; @@ -1105,21 +1128,16 @@ gst_mpeg2dec_get_property (GObject *object, guint prop_id, GValue *value, GParam } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "mpeg2dec", GST_RANK_PRIMARY, GST_TYPE_MPEG2DEC)) + if (!gst_element_register (plugin, "mpeg2dec", GST_RANK_PRIMARY, + GST_TYPE_MPEG2DEC)) return FALSE; return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "mpeg2dec", - "LibMpeg2 decoder", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mpeg2dec", + "LibMpeg2 decoder", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/mpeg2dec/gstmpeg2dec.h b/ext/mpeg2dec/gstmpeg2dec.h index f72cd249bf..1bf7e3e5bb 100644 --- a/ext/mpeg2dec/gstmpeg2dec.h +++ b/ext/mpeg2dec/gstmpeg2dec.h @@ -26,7 +26,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_MPEG2DEC \ (gst_mpeg2dec_get_type()) #define GST_MPEG2DEC(obj) \ @@ -37,10 +36,8 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MPEG2DEC)) #define GST_IS_MPEG2DEC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MPEG2DEC)) - #define MPEGTIME_TO_GSTTIME(time) (((time) * (GST_MSECOND/10)) / 9LL) #define GSTTIME_TO_MPEGTIME(time) (((time) * 9LL) / (GST_MSECOND/10)) - typedef struct _GstMpeg2dec GstMpeg2dec; typedef struct _GstMpeg2decClass GstMpeg2decClass; @@ -51,54 +48,53 @@ typedef enum MPEG2DEC_FORMAT_YV12, } Mpeg2decFormat; -typedef enum +typedef enum { - MPEG2DEC_DISC_NONE = 0, + MPEG2DEC_DISC_NONE = 0, MPEG2DEC_DISC_NEW_PICTURE, MPEG2DEC_DISC_NEW_KEYFRAME, } DiscontState; -struct _GstMpeg2dec { - GstElement element; +struct _GstMpeg2dec +{ + GstElement element; /* pads */ - GstPad *sinkpad, - *srcpad, - *userdatapad; + GstPad *sinkpad, *srcpad, *userdatapad; - mpeg2dec_t *decoder; - gboolean closed; - gboolean have_fbuf; + mpeg2dec_t *decoder; + gboolean closed; + gboolean have_fbuf; /* the timestamp of the next frame */ - DiscontState discont_state; - gint64 next_time; - gint64 segment_start; - gint64 segment_end; + DiscontState discont_state; + gint64 next_time; + gint64 segment_start; + gint64 segment_end; /* video state */ Mpeg2decFormat format; - gint width; - gint height; - gint pixel_width; - gint pixel_height; - gint frame_rate_code; - gint64 total_frames; - gint64 frame_period; - gboolean need_sequence; + gint width; + gint height; + gint pixel_width; + gint pixel_height; + gint frame_rate_code; + gint64 total_frames; + gint64 frame_period; + gboolean need_sequence; - GstEvent *pending_event; + GstEvent *pending_event; - GstIndex *index; - gint index_id; + GstIndex *index; + gint index_id; }; -struct _GstMpeg2decClass { +struct _GstMpeg2decClass +{ GstElementClass parent_class; }; -GType gst_mpeg2dec_get_type(void); +GType gst_mpeg2dec_get_type (void); G_END_DECLS - #endif /* __GST_MPEG2DEC_H__ */ diff --git a/ext/mpeg2dec/perftest.c b/ext/mpeg2dec/perftest.c index 001826fea0..e5f10f66af 100644 --- a/ext/mpeg2dec/perftest.c +++ b/ext/mpeg2dec/perftest.c @@ -11,14 +11,15 @@ #include "gstmpeg2dec.h" -void new_frame (char *buf, void *data, uint64_t timestamp) +void +new_frame (char *buf, void *data, uint64_t timestamp) { - g_print("."); + g_print ("."); } -int -main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { int fd, count = 20000; mpeg2dec_t *decoder; @@ -30,7 +31,7 @@ main (int argc, char *argv[]) mpeg2_init (decoder, new_frame, NULL); while (read (fd, buffer, 2048) && count--) { - mpeg2_decode_data(decoder, buffer, buffer + 2048); + mpeg2_decode_data (decoder, buffer, buffer + 2048); } - g_print("\n"); + g_print ("\n"); } diff --git a/ext/sidplay/gstsiddec.h b/ext/sidplay/gstsiddec.h index a8789095fe..e6e8fe2ce8 100644 --- a/ext/sidplay/gstsiddec.h +++ b/ext/sidplay/gstsiddec.h @@ -28,7 +28,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_SIDDEC \ (gst_siddec_get_type()) #define GST_SIDDEC(obj) \ @@ -39,38 +38,37 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SIDDEC)) #define GST_IS_SIDDEC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SIDDEC)) - typedef struct _GstSidDec GstSidDec; typedef struct _GstSidDecClass GstSidDecClass; -struct _GstSidDec { - GstElement element; +struct _GstSidDec +{ + GstElement element; /* pads */ - GstPad *sinkpad, - *srcpad; + GstPad *sinkpad, *srcpad; - gint state; - guchar *tune_buffer; - gint tune_len; - gint tune_number; - guint64 total_bytes; + gint state; + guchar *tune_buffer; + gint tune_len; + gint tune_number; + guint64 total_bytes; - emuEngine *engine; - sidTune *tune; - emuConfig *config; + emuEngine *engine; + sidTune *tune; + emuConfig *config; - gulong blocksize; + gulong blocksize; - GstCaps *metadata; + GstCaps *metadata; }; -struct _GstSidDecClass { +struct _GstSidDecClass +{ GstElementClass parent_class; }; GType gst_siddec_get_type (void); - -G_END_DECLS +G_END_DECLS #endif /* __GST_SIDDEC_H__ */ diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c index d467af49a0..10a00142e6 100644 --- a/gst-libs/gst/audio/audio.c +++ b/gst-libs/gst/audio/audio.c @@ -26,7 +26,7 @@ #include int -gst_audio_frame_byte_size (GstPad* pad) +gst_audio_frame_byte_size (GstPad * pad) { /* calculate byte size of an audio frame * this should be moved closer to the gstreamer core @@ -45,20 +45,20 @@ gst_audio_frame_byte_size (GstPad* pad) if (caps == NULL) { /* ERROR: could not get caps of pad */ - g_warning ("gstaudio: could not get caps of pad %s:%s\n", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); + g_warning ("gstaudio: could not get caps of pad %s:%s\n", + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); return 0; } structure = gst_caps_get_structure (caps, 0); - gst_structure_get_int (structure, "width", &width); + gst_structure_get_int (structure, "width", &width); gst_structure_get_int (structure, "channels", &channels); - return (width / 8) * channels; + return (width / 8) * channels; } long -gst_audio_frame_length (GstPad* pad, GstBuffer* buf) +gst_audio_frame_length (GstPad * pad, GstBuffer * buf) /* calculate length of buffer in frames * this should be moved closer to the gstreamer core * and be implemented for every mime type IMO @@ -72,13 +72,13 @@ gst_audio_frame_length (GstPad* pad, GstBuffer* buf) /* error */ return 0; /* FIXME: this function assumes the buffer size to be a whole multiple - * of the frame byte size + * of the frame byte size */ return GST_BUFFER_SIZE (buf) / frame_byte_size; } long -gst_audio_frame_rate (GstPad *pad) +gst_audio_frame_rate (GstPad * pad) /* * calculate frame rate (based on caps of pad) * returns 0 if failed, rate if success @@ -93,19 +93,18 @@ gst_audio_frame_rate (GstPad *pad) if (caps == NULL) { /* ERROR: could not get caps of pad */ - g_warning ("gstaudio: could not get caps of pad %s:%s\n", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); + g_warning ("gstaudio: could not get caps of pad %s:%s\n", + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); return 0; - } - else { + } else { structure = gst_caps_get_structure (caps, 0); - gst_structure_get_int (structure, "rate", &rate); + gst_structure_get_int (structure, "rate", &rate); return rate; } } -double -gst_audio_length (GstPad* pad, GstBuffer* buf) +double +gst_audio_length (GstPad * pad, GstBuffer * buf) { /* calculate length in seconds * of audio buffer buf @@ -125,20 +124,17 @@ gst_audio_length (GstPad* pad, GstBuffer* buf) g_assert (GST_IS_BUFFER (buf)); /* get caps of pad */ caps = GST_PAD_CAPS (pad); - if (caps == NULL) - { + if (caps == NULL) { /* ERROR: could not get caps of pad */ - g_warning ("gstaudio: could not get caps of pad %s:%s\n", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); + g_warning ("gstaudio: could not get caps of pad %s:%s\n", + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); length = 0.0; - } - else - { + } else { structure = gst_caps_get_structure (caps, 0); bytes = GST_BUFFER_SIZE (buf); - gst_structure_get_int (structure, "width", &width); - gst_structure_get_int (structure, "channels", &channels); - gst_structure_get_int (structure, "rate", &rate); + gst_structure_get_int (structure, "width", &width); + gst_structure_get_int (structure, "channels", &channels); + gst_structure_get_int (structure, "rate", &rate); g_assert (bytes != 0); g_assert (width != 0); @@ -150,8 +146,8 @@ gst_audio_length (GstPad* pad, GstBuffer* buf) return length; } -long -gst_audio_highest_sample_value (GstPad* pad) +long +gst_audio_highest_sample_value (GstPad * pad) /* calculate highest possible sample value * based on capabilities of pad */ @@ -160,25 +156,25 @@ gst_audio_highest_sample_value (GstPad* pad) gint width = 0; const GstCaps *caps = NULL; GstStructure *structure; - + caps = GST_PAD_CAPS (pad); - if (caps == NULL) - { - g_warning ("gstaudio: could not get caps of pad %s:%s\n", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); + if (caps == NULL) { + g_warning ("gstaudio: could not get caps of pad %s:%s\n", + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); } - + structure = gst_caps_get_structure (caps, 0); - gst_structure_get_int (structure, "width", &width); - gst_structure_get_boolean (structure, "signed", &is_signed); - - if (is_signed) --width; + gst_structure_get_int (structure, "width", &width); + gst_structure_get_boolean (structure, "signed", &is_signed); + + if (is_signed) + --width; /* example : 16 bit, signed : samples between -32768 and 32767 */ return ((long) (1 << width)); } -gboolean -gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf) +gboolean +gst_audio_is_buffer_framed (GstPad * pad, GstBuffer * buf) /* check if the buffer size is a whole multiple of the frame size */ { if (GST_BUFFER_SIZE (buf) % gst_audio_frame_byte_size (pad) == 0) @@ -199,8 +195,8 @@ gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf) * number of list values, and each of the values, terminating with NULL */ static void -_gst_audio_structure_set_list (GstStructure *structure, const gchar *fieldname, - GType type, int number, ...) +_gst_audio_structure_set_list (GstStructure * structure, + const gchar * fieldname, GType type, int number, ...) { va_list varargs; GValue value = { 0 }; @@ -214,27 +210,27 @@ _gst_audio_structure_set_list (GstStructure *structure, const gchar *fieldname, va_start (varargs, number); - for (j = 0; j < number; ++j) - { + for (j = 0; j < number; ++j) { int i; gboolean b; GValue list_value = { 0 }; - switch (type) - { + switch (type) { case G_TYPE_INT: - i = va_arg (varargs, int); - g_value_init (&list_value, G_TYPE_INT); - g_value_set_int (&list_value, i); - break; + i = va_arg (varargs, int); + + g_value_init (&list_value, G_TYPE_INT); + g_value_set_int (&list_value, i); + break; case G_TYPE_BOOLEAN: - b = va_arg (varargs, gboolean); - g_value_init (&list_value, G_TYPE_BOOLEAN); - g_value_set_boolean (&list_value, b); - break; - default: - g_warning ("_gst_audio_structure_set_list: LIST of given type not implemented."); + b = va_arg (varargs, gboolean); + g_value_init (&list_value, G_TYPE_BOOLEAN); + g_value_set_boolean (&list_value, b); + break; + default: + g_warning + ("_gst_audio_structure_set_list: LIST of given type not implemented."); } g_array_append_val (array, list_value); @@ -244,38 +240,38 @@ _gst_audio_structure_set_list (GstStructure *structure, const gchar *fieldname, } void -gst_audio_structure_set_int (GstStructure *structure, GstAudioFieldFlag flag) +gst_audio_structure_set_int (GstStructure * structure, GstAudioFieldFlag flag) { if (flag & GST_AUDIO_FIELD_RATE) - gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); + gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, + NULL); if (flag & GST_AUDIO_FIELD_CHANNELS) - gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); + gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, G_MAXINT, + NULL); if (flag & GST_AUDIO_FIELD_ENDIANNESS) - _gst_audio_structure_set_list (structure, "endianness", G_TYPE_INT, 2, G_LITTLE_ENDIAN, G_BIG_ENDIAN, NULL); + _gst_audio_structure_set_list (structure, "endianness", G_TYPE_INT, 2, + G_LITTLE_ENDIAN, G_BIG_ENDIAN, NULL); if (flag & GST_AUDIO_FIELD_WIDTH) - _gst_audio_structure_set_list (structure, "width", G_TYPE_INT, 3, 8, 16, 32, NULL); + _gst_audio_structure_set_list (structure, "width", G_TYPE_INT, 3, 8, 16, 32, + NULL); if (flag & GST_AUDIO_FIELD_DEPTH) gst_structure_set (structure, "depth", GST_TYPE_INT_RANGE, 1, 32, NULL); if (flag & GST_AUDIO_FIELD_SIGNED) - _gst_audio_structure_set_list (structure, "signed", G_TYPE_BOOLEAN, 2, TRUE, FALSE, NULL); + _gst_audio_structure_set_list (structure, "signed", G_TYPE_BOOLEAN, 2, TRUE, + FALSE, NULL); if (flag & GST_AUDIO_FIELD_BUFFER_FRAMES) - gst_structure_set (structure, "buffer-frames", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); + gst_structure_set (structure, "buffer-frames", GST_TYPE_INT_RANGE, 1, + G_MAXINT, NULL); } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gstaudio", - "Support services for audio plugins", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -); +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstaudio", + "Support services for audio plugins", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN); diff --git a/gst-libs/gst/audio/audio.h b/gst-libs/gst/audio/audio.h index 4a3428ddb3..5f21e0180e 100644 --- a/gst-libs/gst/audio/audio.h +++ b/gst-libs/gst/audio/audio.h @@ -26,7 +26,6 @@ #define __GST_AUDIO_AUDIO_H__ G_BEGIN_DECLS - /* For people that are looking at this source: the purpose of these defines is * to make GstCaps a bit easier, in that you don't have to know all of the * properties that need to be defined. you can just use these macros. currently @@ -50,9 +49,7 @@ G_BEGIN_DECLS * * Andy Wingo, 18 August 2001 * Thomas, 6 September 2002 */ - #define GST_AUDIO_DEF_RATE 44100 - #define GST_AUDIO_INT_PAD_TEMPLATE_CAPS \ "audio/x-raw-int, " \ "rate = (int) [ 1, MAX ], " \ @@ -60,9 +57,7 @@ G_BEGIN_DECLS "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \ "width = (int) { 8, 16, 32 }, " \ "depth = (int) [ 1, 32 ], " \ - "signed = (boolean) { true, false }" - - + "signed = (boolean) { true, false }" /* "standard" int audio is native order, 16 bit stereo. */ #define GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS \ "audio/x-raw-int, " \ @@ -71,8 +66,7 @@ G_BEGIN_DECLS "endianness = (int) BYTE_ORDER, " \ "width = (int) 16, " \ "depth = (int) 16, " \ - "signed = (boolean) true" - + "signed = (boolean) true" #define GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS \ "audio/x-raw-float, " \ "rate = (int) [ 1, MAX ], " \ @@ -80,7 +74,6 @@ G_BEGIN_DECLS "endianness = (int) { LITTLE_ENDIAN , BIG_ENDIAN }, " \ "width = (int) { 32, 64 }, " \ "buffer-frames = (int) [ 1, MAX]" - /* "standard" float audio is native order, 32 bit mono. */ #define GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS \ "audio/x-raw-float, " \ @@ -88,43 +81,42 @@ G_BEGIN_DECLS "channels = (int) 1, " \ "endianness = (int) BYTE_ORDER, " \ "buffer-frames = (int) [ 1, MAX]" - /* * this library defines and implements some helper functions for audio * handling */ - /* get byte size of audio frame (based on caps of pad */ -int gst_audio_frame_byte_size (GstPad* pad); +int gst_audio_frame_byte_size (GstPad * pad); /* get length in frames of buffer */ -long gst_audio_frame_length (GstPad* pad, GstBuffer* buf); +long gst_audio_frame_length (GstPad * pad, GstBuffer * buf); /* get frame rate based on caps */ -long gst_audio_frame_rate (GstPad *pad); +long gst_audio_frame_rate (GstPad * pad); /* calculate length in seconds of audio buffer buf based on caps of pad */ -double gst_audio_length (GstPad* pad, GstBuffer* buf); +double gst_audio_length (GstPad * pad, GstBuffer * buf); /* calculate highest possible sample value based on capabilities of pad */ -long gst_audio_highest_sample_value (GstPad* pad); +long gst_audio_highest_sample_value (GstPad * pad); /* check if the buffer size is a whole multiple of the frame size */ -gboolean gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf); +gboolean gst_audio_is_buffer_framed (GstPad * pad, GstBuffer * buf); /* functions useful for _getcaps functions */ -typedef enum { - GST_AUDIO_FIELD_RATE = (1 << 0), - GST_AUDIO_FIELD_CHANNELS = (1 << 1), - GST_AUDIO_FIELD_ENDIANNESS = (1 << 2), - GST_AUDIO_FIELD_WIDTH = (1 << 3), - GST_AUDIO_FIELD_DEPTH = (1 << 4), - GST_AUDIO_FIELD_SIGNED = (1 << 5), +typedef enum +{ + GST_AUDIO_FIELD_RATE = (1 << 0), + GST_AUDIO_FIELD_CHANNELS = (1 << 1), + GST_AUDIO_FIELD_ENDIANNESS = (1 << 2), + GST_AUDIO_FIELD_WIDTH = (1 << 3), + GST_AUDIO_FIELD_DEPTH = (1 << 4), + GST_AUDIO_FIELD_SIGNED = (1 << 5), GST_AUDIO_FIELD_BUFFER_FRAMES = (1 << 6) } GstAudioFieldFlag; -void gst_audio_structure_set_int (GstStructure *structure, GstAudioFieldFlag flag); +void gst_audio_structure_set_int (GstStructure * structure, + GstAudioFieldFlag flag); G_END_DECLS - #endif /* __GST_AUDIO_AUDIO_H__ */ diff --git a/gst-libs/gst/audio/audioclock.c b/gst-libs/gst/audio/audioclock.c index 77c7e57671..d6d1da45e1 100644 --- a/gst-libs/gst/audio/audioclock.c +++ b/gst-libs/gst/audio/audioclock.c @@ -26,23 +26,24 @@ #include "audioclock.h" -static void gst_audio_clock_class_init (GstAudioClockClass *klass); -static void gst_audio_clock_init (GstAudioClock *clock); +static void gst_audio_clock_class_init (GstAudioClockClass * klass); +static void gst_audio_clock_init (GstAudioClock * clock); -static GstClockTime gst_audio_clock_get_internal_time (GstClock *clock); -static GstClockReturn gst_audio_clock_id_wait_async (GstClock *clock, - GstClockEntry *entry); -static void gst_audio_clock_id_unschedule (GstClock *clock, - GstClockEntry *entry); +static GstClockTime gst_audio_clock_get_internal_time (GstClock * clock); +static GstClockReturn gst_audio_clock_id_wait_async (GstClock * clock, + GstClockEntry * entry); +static void gst_audio_clock_id_unschedule (GstClock * clock, + GstClockEntry * entry); static GstSystemClockClass *parent_class = NULL; + /* static guint gst_audio_clock_signals[LAST_SIGNAL] = { 0 }; */ - + GType gst_audio_clock_get_type (void) -{ +{ static GType clock_type = 0; - + if (!clock_type) { static const GTypeInfo clock_info = { sizeof (GstAudioClockClass), @@ -57,32 +58,32 @@ gst_audio_clock_get_type (void) NULL }; clock_type = g_type_register_static (GST_TYPE_SYSTEM_CLOCK, "GstAudioClock", - &clock_info, 0); + &clock_info, 0); } return clock_type; } static void -gst_audio_clock_class_init (GstAudioClockClass *klass) +gst_audio_clock_class_init (GstAudioClockClass * klass) { GObjectClass *gobject_class; GstObjectClass *gstobject_class; GstClockClass *gstclock_class; - gobject_class = (GObjectClass*) klass; - gstobject_class = (GstObjectClass*) klass; - gstclock_class = (GstClockClass*) klass; + gobject_class = (GObjectClass *) klass; + gstobject_class = (GstObjectClass *) klass; + gstclock_class = (GstClockClass *) klass; parent_class = g_type_class_ref (GST_TYPE_SYSTEM_CLOCK); - gstclock_class->get_internal_time = gst_audio_clock_get_internal_time; - gstclock_class->wait_async = gst_audio_clock_id_wait_async; - gstclock_class->unschedule = gst_audio_clock_id_unschedule; + gstclock_class->get_internal_time = gst_audio_clock_get_internal_time; + gstclock_class->wait_async = gst_audio_clock_id_wait_async; + gstclock_class->unschedule = gst_audio_clock_id_unschedule; } static void -gst_audio_clock_init (GstAudioClock *clock) +gst_audio_clock_init (GstAudioClock * clock) { gst_object_set_name (GST_OBJECT (clock), "GstAudioClock"); @@ -90,20 +91,22 @@ gst_audio_clock_init (GstAudioClock *clock) clock->prev2 = 0; } -GstClock* -gst_audio_clock_new (gchar *name, GstAudioClockGetTimeFunc func, gpointer user_data) +GstClock * +gst_audio_clock_new (gchar * name, GstAudioClockGetTimeFunc func, + gpointer user_data) { - GstAudioClock *aclock = GST_AUDIO_CLOCK (g_object_new (GST_TYPE_AUDIO_CLOCK, NULL)); + GstAudioClock *aclock = + GST_AUDIO_CLOCK (g_object_new (GST_TYPE_AUDIO_CLOCK, NULL)); aclock->func = func; aclock->user_data = user_data; aclock->adjust = 0; - return (GstClock*)aclock; + return (GstClock *) aclock; } void -gst_audio_clock_set_active (GstAudioClock *aclock, gboolean active) +gst_audio_clock_set_active (GstAudioClock * aclock, gboolean active) { GstClockTime time; GstClock *clock; @@ -117,8 +120,9 @@ gst_audio_clock_set_active (GstAudioClock *aclock, gboolean active) aclock->adjust = time - aclock->func (clock, aclock->user_data); } else { GTimeVal timeval; + g_get_current_time (&timeval); - + aclock->adjust = GST_TIMEVAL_TO_TIME (timeval) - time; } @@ -126,22 +130,22 @@ gst_audio_clock_set_active (GstAudioClock *aclock, gboolean active) } static GstClockTime -gst_audio_clock_get_internal_time (GstClock *clock) +gst_audio_clock_get_internal_time (GstClock * clock) { GstAudioClock *aclock = GST_AUDIO_CLOCK (clock); - + if (aclock->active) { return aclock->func (clock, aclock->user_data) + aclock->adjust; } else { GTimeVal timeval; - + g_get_current_time (&timeval); return GST_TIMEVAL_TO_TIME (timeval); } } void -gst_audio_clock_update_time (GstAudioClock *aclock, GstClockTime time) +gst_audio_clock_update_time (GstAudioClock * aclock, GstClockTime time) { /* I don't know of a purpose in updating these; perhaps they can be removed */ aclock->prev2 = aclock->prev1; @@ -150,43 +154,41 @@ gst_audio_clock_update_time (GstAudioClock *aclock, GstClockTime time) /* FIXME: the wait_async subsystem should be made threadsafe, but I don't want * to lock and unlock a mutex on every iteration... */ while (aclock->async_entries) { - GstClockEntry *entry = (GstClockEntry*)aclock->async_entries->data; - + GstClockEntry *entry = (GstClockEntry *) aclock->async_entries->data; + if (entry->time > time) break; - entry->func ((GstClock*)aclock, time, entry, entry->user_data); + entry->func ((GstClock *) aclock, time, entry, entry->user_data); aclock->async_entries = g_slist_delete_link (aclock->async_entries, - aclock->async_entries); + aclock->async_entries); /* do I need to free the entry? */ } } static gint -compare_clock_entries (GstClockEntry *entry1, GstClockEntry *entry2) +compare_clock_entries (GstClockEntry * entry1, GstClockEntry * entry2) { return entry1->time - entry2->time; } static GstClockReturn -gst_audio_clock_id_wait_async (GstClock *clock, GstClockEntry *entry) +gst_audio_clock_id_wait_async (GstClock * clock, GstClockEntry * entry) { - GstAudioClock *aclock = (GstAudioClock*)clock; - + GstAudioClock *aclock = (GstAudioClock *) clock; + aclock->async_entries = g_slist_insert_sorted (aclock->async_entries, - entry, - (GCompareFunc)compare_clock_entries); + entry, (GCompareFunc) compare_clock_entries); /* is this the proper return val? */ return GST_CLOCK_EARLY; } static void -gst_audio_clock_id_unschedule (GstClock *clock, GstClockEntry *entry) +gst_audio_clock_id_unschedule (GstClock * clock, GstClockEntry * entry) { - GstAudioClock *aclock = (GstAudioClock*)clock; - - aclock->async_entries = g_slist_remove (aclock->async_entries, - entry); + GstAudioClock *aclock = (GstAudioClock *) clock; + + aclock->async_entries = g_slist_remove (aclock->async_entries, entry); } diff --git a/gst-libs/gst/audio/audioclock.h b/gst-libs/gst/audio/audioclock.h index 17439242b5..abb0754161 100644 --- a/gst-libs/gst/audio/audioclock.h +++ b/gst-libs/gst/audio/audioclock.h @@ -27,7 +27,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_AUDIO_CLOCK \ (gst_audio_clock_get_type()) #define GST_AUDIO_CLOCK(obj) \ @@ -38,14 +37,15 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_CLOCK)) #define GST_IS_AUDIO_CLOCK_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_CLOCK)) - typedef struct _GstAudioClock GstAudioClock; typedef struct _GstAudioClockClass GstAudioClockClass; -typedef GstClockTime (*GstAudioClockGetTimeFunc) (GstClock *clock, gpointer user_data); +typedef GstClockTime (*GstAudioClockGetTimeFunc) (GstClock * clock, + gpointer user_data); -struct _GstAudioClock { +struct _GstAudioClock +{ GstSystemClock clock; GstClockTime prev1, prev2; @@ -63,19 +63,19 @@ struct _GstAudioClock { gpointer _gst_reserved[GST_PADDING]; }; -struct _GstAudioClockClass { +struct _GstAudioClockClass +{ GstSystemClockClass parent_class; gpointer _gst_reserved[GST_PADDING]; }; -GType gst_audio_clock_get_type (void); -GstClock* gst_audio_clock_new (gchar *name, GstAudioClockGetTimeFunc func, - gpointer user_data); -void gst_audio_clock_set_active (GstAudioClock *aclock, gboolean active); +GType gst_audio_clock_get_type (void); +GstClock *gst_audio_clock_new (gchar * name, GstAudioClockGetTimeFunc func, + gpointer user_data); +void gst_audio_clock_set_active (GstAudioClock * aclock, gboolean active); -void gst_audio_clock_update_time (GstAudioClock *aclock, GstClockTime time); +void gst_audio_clock_update_time (GstAudioClock * aclock, GstClockTime time); G_END_DECLS - #endif /* __GST_AUDIO_CLOCK_H__ */ diff --git a/gst-libs/gst/audio/gstaudiofilter.c b/gst-libs/gst/audio/gstaudiofilter.c index 35ed48756f..ad491bb6ad 100644 --- a/gst-libs/gst/audio/gstaudiofilter.c +++ b/gst-libs/gst/audio/gstaudiofilter.c @@ -29,26 +29,30 @@ /* GstAudiofilter signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_METHOD, /* FILL ME */ }; -static void gst_audiofilter_base_init (gpointer g_class); -static void gst_audiofilter_class_init (gpointer g_class, gpointer class_data); -static void gst_audiofilter_init (GTypeInstance *instance, gpointer g_class); +static void gst_audiofilter_base_init (gpointer g_class); +static void gst_audiofilter_class_init (gpointer g_class, gpointer class_data); +static void gst_audiofilter_init (GTypeInstance * instance, gpointer g_class); -static void gst_audiofilter_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_audiofilter_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void gst_audiofilter_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_audiofilter_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static void gst_audiofilter_chain (GstPad *pad, GstData *_data); -GstCaps * gst_audiofilter_class_get_capslist(GstAudiofilterClass *klass); +static void gst_audiofilter_chain (GstPad * pad, GstData * _data); +GstCaps *gst_audiofilter_class_get_capslist (GstAudiofilterClass * klass); static GstElementClass *parent_class = NULL; @@ -59,23 +63,24 @@ gst_audiofilter_get_type (void) if (!audiofilter_type) { static const GTypeInfo audiofilter_info = { - sizeof(GstAudiofilterClass), + sizeof (GstAudiofilterClass), gst_audiofilter_base_init, NULL, gst_audiofilter_class_init, NULL, NULL, - sizeof(GstAudiofilter), + sizeof (GstAudiofilter), 0, gst_audiofilter_init, }; - audiofilter_type = g_type_register_static(GST_TYPE_ELEMENT, + audiofilter_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAudiofilter", &audiofilter_info, G_TYPE_FLAG_ABSTRACT); } return audiofilter_type; } -static void gst_audiofilter_base_init (gpointer g_class) +static void +gst_audiofilter_base_init (gpointer g_class) { static GstElementDetails audiofilter_details = { "Audio filter base class", @@ -89,24 +94,25 @@ static void gst_audiofilter_base_init (gpointer g_class) gst_element_class_set_details (element_class, &audiofilter_details); } -static void gst_audiofilter_class_init (gpointer g_class, gpointer class_data) +static void +gst_audiofilter_class_init (gpointer g_class, gpointer class_data) { GObjectClass *gobject_class; GstElementClass *gstelement_class; GstAudiofilterClass *klass; - klass = (GstAudiofilterClass *)g_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + klass = (GstAudiofilterClass *) g_class; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gobject_class->set_property = gst_audiofilter_set_property; gobject_class->get_property = gst_audiofilter_get_property; } static GstPadLinkReturn -gst_audiofilter_link (GstPad *pad, const GstCaps *caps) +gst_audiofilter_link (GstPad * pad, const GstCaps * caps) { GstAudiofilter *audiofilter; GstPadLinkReturn ret; @@ -114,11 +120,10 @@ gst_audiofilter_link (GstPad *pad, const GstCaps *caps) GstStructure *structure; GstAudiofilterClass *audiofilter_class; - GST_DEBUG("gst_audiofilter_link"); + GST_DEBUG ("gst_audiofilter_link"); audiofilter = GST_AUDIOFILTER (gst_pad_get_parent (pad)); - audiofilter_class = GST_AUDIOFILTER_CLASS ( - G_OBJECT_GET_CLASS (audiofilter)); - + audiofilter_class = GST_AUDIOFILTER_CLASS (G_OBJECT_GET_CLASS (audiofilter)); + if (pad == audiofilter->srcpad) { link_ret = gst_pad_try_set_caps (audiofilter->sinkpad, caps); @@ -135,53 +140,55 @@ gst_audiofilter_link (GstPad *pad, const GstCaps *caps) if (strcmp (gst_structure_get_name (structure), "audio/x-raw-int") == 0) { ret = gst_structure_get_int (structure, "depth", &audiofilter->depth); ret &= gst_structure_get_int (structure, "width", &audiofilter->width); - ret &= gst_structure_get_int (structure, "channels", &audiofilter->channels); + ret &= + gst_structure_get_int (structure, "channels", &audiofilter->channels); } else if (strcmp (gst_structure_get_name (structure), "audio/x-raw-float") == 0) { } else { - g_assert_not_reached(); + g_assert_not_reached (); } ret &= gst_structure_get_int (structure, "rate", &audiofilter->rate); - audiofilter->bytes_per_sample = (audiofilter->width/8) * - audiofilter->channels; + audiofilter->bytes_per_sample = (audiofilter->width / 8) * + audiofilter->channels; - if (audiofilter_class->setup) (audiofilter_class->setup) (audiofilter); + if (audiofilter_class->setup) + (audiofilter_class->setup) (audiofilter); return GST_PAD_LINK_OK; } static void -gst_audiofilter_init (GTypeInstance *instance, gpointer g_class) +gst_audiofilter_init (GTypeInstance * instance, gpointer g_class) { GstAudiofilter *audiofilter = GST_AUDIOFILTER (instance); GstPadTemplate *pad_template; - GST_DEBUG("gst_audiofilter_init"); + GST_DEBUG ("gst_audiofilter_init"); - pad_template = gst_element_class_get_pad_template(GST_ELEMENT_CLASS(g_class), - "sink"); - g_return_if_fail(pad_template != NULL); - audiofilter->sinkpad = gst_pad_new_from_template(pad_template, "sink"); - gst_element_add_pad(GST_ELEMENT(audiofilter),audiofilter->sinkpad); - gst_pad_set_chain_function(audiofilter->sinkpad,gst_audiofilter_chain); - gst_pad_set_link_function(audiofilter->sinkpad,gst_audiofilter_link); - gst_pad_set_getcaps_function(audiofilter->sinkpad,gst_pad_proxy_getcaps); + pad_template = + gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "sink"); + g_return_if_fail (pad_template != NULL); + audiofilter->sinkpad = gst_pad_new_from_template (pad_template, "sink"); + gst_element_add_pad (GST_ELEMENT (audiofilter), audiofilter->sinkpad); + gst_pad_set_chain_function (audiofilter->sinkpad, gst_audiofilter_chain); + gst_pad_set_link_function (audiofilter->sinkpad, gst_audiofilter_link); + gst_pad_set_getcaps_function (audiofilter->sinkpad, gst_pad_proxy_getcaps); - pad_template = gst_element_class_get_pad_template(GST_ELEMENT_CLASS(g_class), - "src"); - g_return_if_fail(pad_template != NULL); - audiofilter->srcpad = gst_pad_new_from_template(pad_template, "src"); - gst_element_add_pad(GST_ELEMENT(audiofilter),audiofilter->srcpad); - gst_pad_set_link_function(audiofilter->srcpad,gst_audiofilter_link); - gst_pad_set_getcaps_function(audiofilter->srcpad,gst_pad_proxy_getcaps); + pad_template = + gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src"); + g_return_if_fail (pad_template != NULL); + audiofilter->srcpad = gst_pad_new_from_template (pad_template, "src"); + gst_element_add_pad (GST_ELEMENT (audiofilter), audiofilter->srcpad); + gst_pad_set_link_function (audiofilter->srcpad, gst_audiofilter_link); + gst_pad_set_getcaps_function (audiofilter->srcpad, gst_pad_proxy_getcaps); audiofilter->inited = FALSE; } static void -gst_audiofilter_chain (GstPad *pad, GstData *data) +gst_audiofilter_chain (GstPad * pad, GstData * data) { GstBuffer *inbuf = GST_BUFFER (data); GstAudiofilter *audiofilter; @@ -196,60 +203,60 @@ gst_audiofilter_chain (GstPad *pad, GstData *data) audiofilter = GST_AUDIOFILTER (gst_pad_get_parent (pad)); //g_return_if_fail (audiofilter->inited); - audiofilter_class = GST_AUDIOFILTER_CLASS ( - G_OBJECT_GET_CLASS (audiofilter)); + audiofilter_class = GST_AUDIOFILTER_CLASS (G_OBJECT_GET_CLASS (audiofilter)); GST_DEBUG ("gst_audiofilter_chain: got buffer of %d bytes in '%s'", - GST_BUFFER_SIZE(inbuf), GST_OBJECT_NAME (audiofilter)); - - if(audiofilter->passthru){ - gst_pad_push(audiofilter->srcpad, data); + GST_BUFFER_SIZE (inbuf), GST_OBJECT_NAME (audiofilter)); + + if (audiofilter->passthru) { + gst_pad_push (audiofilter->srcpad, data); return; } audiofilter->size = GST_BUFFER_SIZE (inbuf); audiofilter->n_samples = audiofilter->size / audiofilter->bytes_per_sample; - if (gst_data_is_writable(data)) { + if (gst_data_is_writable (data)) { if (audiofilter_class->filter_inplace) { (audiofilter_class->filter_inplace) (audiofilter, inbuf); outbuf = inbuf; } else { - outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE(inbuf)); - GST_BUFFER_DURATION(outbuf) = GST_BUFFER_DURATION(inbuf); - GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(inbuf); + outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (inbuf)); + GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (inbuf); + GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (inbuf); (audiofilter_class->filter) (audiofilter, outbuf, inbuf); - gst_buffer_unref(inbuf); + gst_buffer_unref (inbuf); } } else { - outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE(inbuf)); - GST_BUFFER_DURATION(outbuf) = GST_BUFFER_DURATION(inbuf); - GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(inbuf); + outbuf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (inbuf)); + GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (inbuf); + GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (inbuf); if (audiofilter_class->filter) { (audiofilter_class->filter) (audiofilter, outbuf, inbuf); } else { - memcpy(GST_BUFFER_DATA(outbuf), GST_BUFFER_DATA(inbuf), - GST_BUFFER_SIZE(inbuf)); + memcpy (GST_BUFFER_DATA (outbuf), GST_BUFFER_DATA (inbuf), + GST_BUFFER_SIZE (inbuf)); (audiofilter_class->filter_inplace) (audiofilter, outbuf); } - gst_buffer_unref(inbuf); + gst_buffer_unref (inbuf); } - gst_pad_push(audiofilter->srcpad, GST_DATA (outbuf)); + gst_pad_push (audiofilter->srcpad, GST_DATA (outbuf)); } static void -gst_audiofilter_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_audiofilter_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstAudiofilter *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_AUDIOFILTER(object)); - src = GST_AUDIOFILTER(object); + g_return_if_fail (GST_IS_AUDIOFILTER (object)); + src = GST_AUDIOFILTER (object); - GST_DEBUG("gst_audiofilter_set_property"); + GST_DEBUG ("gst_audiofilter_set_property"); switch (prop_id) { default: break; @@ -257,13 +264,14 @@ gst_audiofilter_set_property (GObject *object, guint prop_id, const GValue *valu } static void -gst_audiofilter_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_audiofilter_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstAudiofilter *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_AUDIOFILTER(object)); - src = GST_AUDIOFILTER(object); + g_return_if_fail (GST_IS_AUDIOFILTER (object)); + src = GST_AUDIOFILTER (object); switch (prop_id) { default: @@ -272,37 +280,31 @@ gst_audiofilter_get_property (GObject *object, guint prop_id, GValue *value, GPa } } -void gst_audiofilter_class_add_pad_templates ( - GstAudiofilterClass *audiofilter_class, const GstCaps *caps) +void +gst_audiofilter_class_add_pad_templates (GstAudiofilterClass * + audiofilter_class, const GstCaps * caps) { GstElementClass *element_class = GST_ELEMENT_CLASS (audiofilter_class); - audiofilter_class->caps = gst_caps_copy(caps); + audiofilter_class->caps = gst_caps_copy (caps); gst_element_class_add_pad_template (element_class, - gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS, - gst_caps_copy(caps))); + gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + gst_caps_copy (caps))); gst_element_class_add_pad_template (element_class, - gst_pad_template_new("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - gst_caps_copy(caps))); + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + gst_caps_copy (caps))); } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gstaudiofilter", - "Audio filter parent class", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -) - +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstaudiofilter", + "Audio filter parent class", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/gst-libs/gst/audio/gstaudiofilter.h b/gst-libs/gst/audio/gstaudiofilter.h index 9786e16c78..534d4c6bbd 100644 --- a/gst-libs/gst/audio/gstaudiofilter.h +++ b/gst-libs/gst/audio/gstaudiofilter.h @@ -25,17 +25,15 @@ #include -G_BEGIN_DECLS - -typedef struct _GstAudiofilter GstAudiofilter; +G_BEGIN_DECLS typedef struct _GstAudiofilter GstAudiofilter; typedef struct _GstAudiofilterClass GstAudiofilterClass; -typedef void (*GstAudiofilterFilterFunc)(GstAudiofilter *filter, - GstBuffer *outbuf, GstBuffer *inbuf); -typedef void (*GstAudiofilterInplaceFilterFunc)(GstAudiofilter *filter, - GstBuffer *buffer); +typedef void (*GstAudiofilterFilterFunc) (GstAudiofilter * filter, + GstBuffer * outbuf, GstBuffer * inbuf); +typedef void (*GstAudiofilterInplaceFilterFunc) (GstAudiofilter * filter, + GstBuffer * buffer); -typedef void (*GstAudiofilterSetupFunc) (GstAudiofilter *filter); +typedef void (*GstAudiofilterSetupFunc) (GstAudiofilter * filter); #define GST_TYPE_AUDIOFILTER \ @@ -49,10 +47,11 @@ typedef void (*GstAudiofilterSetupFunc) (GstAudiofilter *filter); #define GST_IS_AUDIOFILTER_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIOFILTER)) -struct _GstAudiofilter { +struct _GstAudiofilter +{ GstElement element; - GstPad *sinkpad,*srcpad; + GstPad *sinkpad, *srcpad; /* audio state */ gboolean inited; @@ -68,7 +67,8 @@ struct _GstAudiofilter { int bytes_per_sample; }; -struct _GstAudiofilterClass { +struct _GstAudiofilterClass +{ GstElementClass parent_class; GstCaps *caps; @@ -77,11 +77,10 @@ struct _GstAudiofilterClass { GstAudiofilterFilterFunc filter; }; -GType gst_audiofilter_get_type(void); +GType gst_audiofilter_get_type (void); -void gst_audiofilter_class_add_pad_templates (GstAudiofilterClass *audiofilterclass, const GstCaps *caps); +void gst_audiofilter_class_add_pad_templates (GstAudiofilterClass * + audiofilterclass, const GstCaps * caps); G_END_DECLS - #endif /* __GST_AUDIOFILTER_H__ */ - diff --git a/gst-libs/gst/audio/gstaudiofiltertemplate.c b/gst-libs/gst/audio/gstaudiofiltertemplate.c index c7c0ce2bdc..994fdc59d5 100644 --- a/gst-libs/gst/audio/gstaudiofiltertemplate.c +++ b/gst-libs/gst/audio/gstaudiofiltertemplate.c @@ -48,37 +48,47 @@ typedef struct _GstAudiofilterTemplateClass GstAudiofilterTemplateClass; #define GST_IS_AUDIOFILTER_TEMPLATE_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIOFILTER_TEMPLATE)) -struct _GstAudiofilterTemplate { +struct _GstAudiofilterTemplate +{ GstAudiofilter audiofilter; }; -struct _GstAudiofilterTemplateClass { +struct _GstAudiofilterTemplateClass +{ GstAudiofilterClass parent_class; }; -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, /* FILL ME */ }; -static void gst_audiofilter_template_base_init (gpointer g_class); -static void gst_audiofilter_template_class_init (gpointer g_class, gpointer class_data); -static void gst_audiofilter_template_init (GTypeInstance *instance, gpointer g_class); +static void gst_audiofilter_template_base_init (gpointer g_class); +static void gst_audiofilter_template_class_init (gpointer g_class, + gpointer class_data); +static void gst_audiofilter_template_init (GTypeInstance * instance, + gpointer g_class); -static void gst_audiofilter_template_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_audiofilter_template_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void gst_audiofilter_template_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec); +static void gst_audiofilter_template_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); -static void gst_audiofilter_template_setup (GstAudiofilter *audiofilter); -static void gst_audiofilter_template_filter (GstAudiofilter *audiofilter, GstBuffer *outbuf, GstBuffer *inbuf); -static void gst_audiofilter_template_filter_inplace (GstAudiofilter *audiofilter, GstBuffer *buf); +static void gst_audiofilter_template_setup (GstAudiofilter * audiofilter); +static void gst_audiofilter_template_filter (GstAudiofilter * audiofilter, + GstBuffer * outbuf, GstBuffer * inbuf); +static void gst_audiofilter_template_filter_inplace (GstAudiofilter * + audiofilter, GstBuffer * buf); GType gst_audiofilter_template_get_type (void) @@ -87,23 +97,24 @@ gst_audiofilter_template_get_type (void) if (!audiofilter_template_type) { static const GTypeInfo audiofilter_template_info = { - sizeof(GstAudiofilterTemplateClass), + sizeof (GstAudiofilterTemplateClass), gst_audiofilter_template_base_init, NULL, gst_audiofilter_template_class_init, NULL, gst_audiofilter_template_init, - sizeof(GstAudiofilterTemplate), + sizeof (GstAudiofilterTemplate), 0, NULL, }; - audiofilter_template_type = g_type_register_static(GST_TYPE_AUDIOFILTER, + audiofilter_template_type = g_type_register_static (GST_TYPE_AUDIOFILTER, "GstAudiofilterTemplate", &audiofilter_template_info, 0); } return audiofilter_template_type; } -static void gst_audiofilter_template_base_init (gpointer g_class) +static void +gst_audiofilter_template_base_init (gpointer g_class) { static GstElementDetails audiofilter_template_details = { "Audio filter template", @@ -128,16 +139,16 @@ gst_audiofilter_template_class_init (gpointer g_class, gpointer class_data) GstAudiofilterTemplateClass *klass; GstAudiofilterClass *audiofilter_class; - klass = (GstAudiofilterTemplateClass *)g_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; - audiofilter_class = (GstAudiofilterClass *)g_class; + klass = (GstAudiofilterTemplateClass *) g_class; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + audiofilter_class = (GstAudiofilterClass *) g_class; #if 0 - g_object_class_install_property(gobject_class, ARG_METHOD, - g_param_spec_enum("method","method","method", - GST_TYPE_AUDIOTEMPLATE_METHOD, GST_AUDIOTEMPLATE_METHOD_1, - G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_METHOD, + g_param_spec_enum ("method", "method", "method", + GST_TYPE_AUDIOTEMPLATE_METHOD, GST_AUDIOTEMPLATE_METHOD_1, + G_PARAM_READWRITE)); #endif gobject_class->set_property = gst_audiofilter_template_set_property; @@ -146,11 +157,11 @@ gst_audiofilter_template_class_init (gpointer g_class, gpointer class_data) audiofilter_class->setup = gst_audiofilter_template_setup; audiofilter_class->filter = gst_audiofilter_template_filter; audiofilter_class->filter_inplace = gst_audiofilter_template_filter_inplace; -audiofilter_class->filter = NULL; + audiofilter_class->filter = NULL; } static void -gst_audiofilter_template_init (GTypeInstance *instance, gpointer g_class) +gst_audiofilter_template_init (GTypeInstance * instance, gpointer g_class) { //GstAudiofilterTemplate *audiofilter_template = GST_AUDIOFILTER_TEMPLATE (instance); //GstAudiofilter *audiofilter = GST_AUDIOFILTER (instance); @@ -162,15 +173,16 @@ gst_audiofilter_template_init (GTypeInstance *instance, gpointer g_class) } static void -gst_audiofilter_template_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_audiofilter_template_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstAudiofilterTemplate *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_AUDIOFILTER_TEMPLATE(object)); - src = GST_AUDIOFILTER_TEMPLATE(object); + g_return_if_fail (GST_IS_AUDIOFILTER_TEMPLATE (object)); + src = GST_AUDIOFILTER_TEMPLATE (object); - GST_DEBUG("gst_audiofilter_template_set_property"); + GST_DEBUG ("gst_audiofilter_template_set_property"); switch (prop_id) { default: break; @@ -178,13 +190,14 @@ gst_audiofilter_template_set_property (GObject *object, guint prop_id, const GVa } static void -gst_audiofilter_template_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_audiofilter_template_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { GstAudiofilterTemplate *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_AUDIOFILTER_TEMPLATE(object)); - src = GST_AUDIOFILTER_TEMPLATE(object); + g_return_if_fail (GST_IS_AUDIOFILTER_TEMPLATE (object)); + src = GST_AUDIOFILTER_TEMPLATE (object); switch (prop_id) { default: @@ -194,7 +207,7 @@ gst_audiofilter_template_get_property (GObject *object, guint prop_id, GValue *v } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { if (!gst_library_load ("gstaudiofilter")) return FALSE; @@ -203,20 +216,13 @@ plugin_init (GstPlugin *plugin) GST_TYPE_AUDIOFILTER_TEMPLATE); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gstaudiofilter_template", - "Audio filter template", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstaudiofilter_template", + "Audio filter template", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) -static void -gst_audiofilter_template_setup (GstAudiofilter *audiofilter) + static void gst_audiofilter_template_setup (GstAudiofilter * audiofilter) { GstAudiofilterTemplate *audiofilter_template; @@ -234,8 +240,8 @@ gst_audiofilter_template_setup (GstAudiofilter *audiofilter) * with a minimum of memory copies. */ static void -gst_audiofilter_template_filter (GstAudiofilter *audiofilter, - GstBuffer *outbuf, GstBuffer *inbuf) +gst_audiofilter_template_filter (GstAudiofilter * audiofilter, + GstBuffer * outbuf, GstBuffer * inbuf) { GstAudiofilterTemplate *audiofilter_template; @@ -245,13 +251,12 @@ gst_audiofilter_template_filter (GstAudiofilter *audiofilter, /* do something interesting here. This simply copies the source * to the destination. */ - memcpy (GST_BUFFER_DATA (outbuf), GST_BUFFER_DATA (inbuf), - audiofilter->size); + memcpy (GST_BUFFER_DATA (outbuf), GST_BUFFER_DATA (inbuf), audiofilter->size); } static void -gst_audiofilter_template_filter_inplace (GstAudiofilter *audiofilter, - GstBuffer *buf) +gst_audiofilter_template_filter_inplace (GstAudiofilter * audiofilter, + GstBuffer * buf) { GstAudiofilterTemplate *audiofilter_template; @@ -262,4 +267,3 @@ gst_audiofilter_template_filter_inplace (GstAudiofilter *audiofilter, * to the destination. */ } - diff --git a/gst-libs/gst/colorbalance/colorbalance.c b/gst-libs/gst/colorbalance/colorbalance.c index dd32ff8b78..fbf1858181 100644 --- a/gst-libs/gst/colorbalance/colorbalance.c +++ b/gst-libs/gst/colorbalance/colorbalance.c @@ -27,12 +27,13 @@ #include "colorbalance.h" #include "colorbalance-marshal.h" -enum { +enum +{ VALUE_CHANGED, LAST_SIGNAL }; -static void gst_color_balance_class_init (GstColorBalanceClass *klass); +static void gst_color_balance_class_init (GstColorBalanceClass * klass); static guint gst_color_balance_signals[LAST_SIGNAL] = { 0 }; @@ -55,35 +56,33 @@ gst_color_balance_get_type (void) }; gst_color_balance_type = g_type_register_static (G_TYPE_INTERFACE, - "GstColorBalance", - &gst_color_balance_info, 0); + "GstColorBalance", &gst_color_balance_info, 0); g_type_interface_add_prerequisite (gst_color_balance_type, - GST_TYPE_IMPLEMENTS_INTERFACE); + GST_TYPE_IMPLEMENTS_INTERFACE); } return gst_color_balance_type; } static void -gst_color_balance_class_init (GstColorBalanceClass *klass) +gst_color_balance_class_init (GstColorBalanceClass * klass) { static gboolean initialized = FALSE; - + if (!initialized) { gst_color_balance_signals[VALUE_CHANGED] = - g_signal_new ("value-changed", - GST_TYPE_COLOR_BALANCE, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstColorBalanceClass, value_changed), - NULL, NULL, - gst_color_balance_marshal_VOID__OBJECT_INT, - G_TYPE_NONE, 2, - GST_TYPE_COLOR_BALANCE_CHANNEL, G_TYPE_INT); - + g_signal_new ("value-changed", + GST_TYPE_COLOR_BALANCE, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstColorBalanceClass, value_changed), + NULL, NULL, + gst_color_balance_marshal_VOID__OBJECT_INT, + G_TYPE_NONE, 2, GST_TYPE_COLOR_BALANCE_CHANNEL, G_TYPE_INT); + initialized = TRUE; } klass->balance_type = GST_COLOR_BALANCE_SOFTWARE; - + /* default virtual functions */ klass->list_channels = NULL; klass->set_value = NULL; @@ -91,7 +90,7 @@ gst_color_balance_class_init (GstColorBalanceClass *klass) } const GList * -gst_color_balance_list_channels (GstColorBalance *balance) +gst_color_balance_list_channels (GstColorBalance * balance) { GstColorBalanceClass *klass = GST_COLOR_BALANCE_GET_CLASS (balance); @@ -103,9 +102,8 @@ gst_color_balance_list_channels (GstColorBalance *balance) } void -gst_color_balance_set_value (GstColorBalance *balance, - GstColorBalanceChannel *channel, - gint value) +gst_color_balance_set_value (GstColorBalance * balance, + GstColorBalanceChannel * channel, gint value) { GstColorBalanceClass *klass = GST_COLOR_BALANCE_GET_CLASS (balance); @@ -115,8 +113,8 @@ gst_color_balance_set_value (GstColorBalance *balance, } gint -gst_color_balance_get_value (GstColorBalance *balance, - GstColorBalanceChannel *channel) +gst_color_balance_get_value (GstColorBalance * balance, + GstColorBalanceChannel * channel) { GstColorBalanceClass *klass = GST_COLOR_BALANCE_GET_CLASS (balance); @@ -128,13 +126,11 @@ gst_color_balance_get_value (GstColorBalance *balance, } void -gst_color_balance_value_changed (GstColorBalance *balance, - GstColorBalanceChannel *channel, - gint value) +gst_color_balance_value_changed (GstColorBalance * balance, + GstColorBalanceChannel * channel, gint value) { g_signal_emit (G_OBJECT (balance), - gst_color_balance_signals[VALUE_CHANGED], - 0, channel, value); + gst_color_balance_signals[VALUE_CHANGED], 0, channel, value); g_signal_emit_by_name (G_OBJECT (channel), "value_changed", value); } diff --git a/gst-libs/gst/colorbalance/colorbalance.h b/gst-libs/gst/colorbalance/colorbalance.h index d7b92171ce..d0347579a6 100644 --- a/gst-libs/gst/colorbalance/colorbalance.h +++ b/gst-libs/gst/colorbalance/colorbalance.h @@ -27,7 +27,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_COLOR_BALANCE \ (gst_color_balance_get_type ()) #define GST_COLOR_BALANCE(obj) \ @@ -42,55 +41,48 @@ G_BEGIN_DECLS (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_COLOR_BALANCE)) #define GST_COLOR_BALANCE_GET_CLASS(inst) \ (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GST_TYPE_COLOR_BALANCE, GstColorBalanceClass)) - #define GST_COLOR_BALANCE_TYPE(klass) (klass->balance_type) - typedef struct _GstColorBalance GstColorBalance; - + typedef enum { GST_COLOR_BALANCE_HARDWARE, GST_COLOR_BALANCE_SOFTWARE } GstColorBalanceType; -typedef struct _GstColorBalanceClass { +typedef struct _GstColorBalanceClass +{ GTypeInterface klass; GstColorBalanceType balance_type; - - /* virtual functions */ - const GList * (* list_channels) (GstColorBalance *balance); - void (* set_value) (GstColorBalance *balance, - GstColorBalanceChannel *channel, - gint value); - gint (* get_value) (GstColorBalance *balance, - GstColorBalanceChannel *channel); + /* virtual functions */ + const GList *(*list_channels) (GstColorBalance * balance); + + void (*set_value) (GstColorBalance * balance, + GstColorBalanceChannel * channel, gint value); + gint (*get_value) (GstColorBalance * balance, + GstColorBalanceChannel * channel); /* signals */ - void (* value_changed) (GstColorBalance *balance, - GstColorBalanceChannel *channel, - gint value); + void (*value_changed) (GstColorBalance * balance, + GstColorBalanceChannel * channel, gint value); gpointer _gst_reserved[GST_PADDING]; } GstColorBalanceClass; -GType gst_color_balance_get_type (void); +GType gst_color_balance_get_type (void); /* virtual class function wrappers */ -const GList * - gst_color_balance_list_channels (GstColorBalance *balance); -void gst_color_balance_set_value (GstColorBalance *balance, - GstColorBalanceChannel *channel, - gint value); -gint gst_color_balance_get_value (GstColorBalance *balance, - GstColorBalanceChannel *channel); +const GList *gst_color_balance_list_channels (GstColorBalance * balance); +void gst_color_balance_set_value (GstColorBalance * balance, + GstColorBalanceChannel * channel, gint value); +gint gst_color_balance_get_value (GstColorBalance * balance, + GstColorBalanceChannel * channel); /* trigger signal */ -void gst_color_balance_value_changed (GstColorBalance *balance, - GstColorBalanceChannel *channel, - gint value); +void gst_color_balance_value_changed (GstColorBalance * balance, + GstColorBalanceChannel * channel, gint value); G_END_DECLS - #endif /* __GST_COLOR_BALANCE_H__ */ diff --git a/gst-libs/gst/colorbalance/colorbalancechannel.c b/gst-libs/gst/colorbalance/colorbalancechannel.c index b8a4eebdb6..7812ed9303 100644 --- a/gst-libs/gst/colorbalance/colorbalancechannel.c +++ b/gst-libs/gst/colorbalance/colorbalancechannel.c @@ -25,15 +25,17 @@ #include "colorbalancechannel.h" -enum { +enum +{ /* FILL ME */ SIGNAL_VALUE_CHANGED, LAST_SIGNAL }; -static void gst_color_balance_channel_class_init (GstColorBalanceChannelClass *klass); -static void gst_color_balance_channel_init (GstColorBalanceChannel *balance); -static void gst_color_balance_channel_dispose (GObject *object); +static void gst_color_balance_channel_class_init (GstColorBalanceChannelClass * + klass); +static void gst_color_balance_channel_init (GstColorBalanceChannel * balance); +static void gst_color_balance_channel_dispose (GObject * object); static GObjectClass *parent_class = NULL; static guint signals[LAST_SIGNAL] = { 0 }; @@ -59,46 +61,44 @@ gst_color_balance_channel_get_type (void) gst_color_balance_channel_type = g_type_register_static (G_TYPE_OBJECT, - "GstColorBalanceChannel", - &color_balance_channel_info, 0); + "GstColorBalanceChannel", &color_balance_channel_info, 0); } return gst_color_balance_channel_type; } static void -gst_color_balance_channel_class_init (GstColorBalanceChannelClass *klass) +gst_color_balance_channel_class_init (GstColorBalanceChannelClass * klass) { GObjectClass *object_klass = (GObjectClass *) klass; parent_class = g_type_class_ref (G_TYPE_OBJECT); signals[SIGNAL_VALUE_CHANGED] = - g_signal_new ("value-changed", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstColorBalanceChannelClass, - value_changed), - NULL, NULL, g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); + g_signal_new ("value-changed", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstColorBalanceChannelClass, + value_changed), + NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); object_klass->dispose = gst_color_balance_channel_dispose; } static void -gst_color_balance_channel_init (GstColorBalanceChannel *channel) +gst_color_balance_channel_init (GstColorBalanceChannel * channel) { channel->label = NULL; channel->min_value = channel->max_value = 0; } static void -gst_color_balance_channel_dispose (GObject *object) +gst_color_balance_channel_dispose (GObject * object) { GstColorBalanceChannel *channel = GST_COLOR_BALANCE_CHANNEL (object); if (channel->label) g_free (channel->label); - + channel->label = NULL; if (parent_class->dispose) diff --git a/gst-libs/gst/colorbalance/colorbalancechannel.h b/gst-libs/gst/colorbalance/colorbalancechannel.h index 23f73f8ec2..516fb72a53 100644 --- a/gst-libs/gst/colorbalance/colorbalancechannel.h +++ b/gst-libs/gst/colorbalance/colorbalancechannel.h @@ -25,7 +25,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_COLOR_BALANCE_CHANNEL \ (gst_color_balance_channel_get_type ()) #define GST_COLOR_BALANCE_CHANNEL(obj) \ @@ -38,27 +37,25 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_COLOR_BALANCE_CHANNEL)) #define GST_IS_COLOR_BALANCE_CHANNEL_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_COLOR_BALANCE_CHANNEL)) - -typedef struct _GstColorBalanceChannel { + typedef struct _GstColorBalanceChannel +{ GObject parent; - gchar *label; - gint min_value, - max_value; + gchar *label; + gint min_value, max_value; } GstColorBalanceChannel; -typedef struct _GstColorBalanceChannelClass { +typedef struct _GstColorBalanceChannelClass +{ GObjectClass parent; /* signals */ - void (* value_changed) (GstColorBalanceChannel *channel, - gint value); + void (*value_changed) (GstColorBalanceChannel * channel, gint value); gpointer _gst_reserved[GST_PADDING]; } GstColorBalanceChannelClass; -GType gst_color_balance_channel_get_type (void); +GType gst_color_balance_channel_get_type (void); G_END_DECLS - #endif /* __GST_COLOR_BALANCE_CHANNEL_H__ */ diff --git a/gst-libs/gst/floatcast/floatcast.h b/gst-libs/gst/floatcast/floatcast.h index ae87a43fbf..2951a8106d 100644 --- a/gst-libs/gst/floatcast/floatcast.h +++ b/gst-libs/gst/floatcast/floatcast.h @@ -29,53 +29,46 @@ #include G_BEGIN_DECLS - #if (HAVE_LRINT && HAVE_LRINTF) - - /* These defines enable functionality introduced with the 1999 ISO C - ** standard. They must be defined before the inclusion of math.h to - ** engage them. If optimisation is enabled, these functions will be - ** inlined. With optimisation switched off, you have to link in the - ** maths library using -lm. - */ - - #define _ISOC9X_SOURCE 1 - #define _ISOC99_SOURCE 1 - - #define __USE_ISOC9X 1 - #define __USE_ISOC99 1 - - #include - - #define gst_cast_float(x) ((gint)lrintf(x)) - #define gst_cast_double(x) ((gint)lrint(x)) - + /* These defines enable functionality introduced with the 1999 ISO C + ** standard. They must be defined before the inclusion of math.h to + ** engage them. If optimisation is enabled, these functions will be + ** inlined. With optimisation switched off, you have to link in the + ** maths library using -lm. + */ +#define _ISOC9X_SOURCE 1 +#define _ISOC99_SOURCE 1 +#define __USE_ISOC9X 1 +#define __USE_ISOC99 1 +#include +#define gst_cast_float(x) ((gint)lrintf(x)) +#define gst_cast_double(x) ((gint)lrint(x)) #else - /* use a standard c cast, but do rounding correctly */ - #define gst_cast_float(x) ((gint)floor((x)+0.5)) - #define gst_cast_double(x) ((gint)floor((x)+0.5)) - + /* use a standard c cast, but do rounding correctly */ +#define gst_cast_float(x) ((gint)floor((x)+0.5)) +#define gst_cast_double(x) ((gint)floor((x)+0.5)) #endif - inline static gfloat -GFLOAT_SWAP_LE_BE(gfloat in) +GFLOAT_SWAP_LE_BE (gfloat in) { gint32 swap; gfloat out; - memcpy(&swap, &in, 4); + + memcpy (&swap, &in, 4); swap = GUINT32_SWAP_LE_BE_CONSTANT (swap); - memcpy(&out, &swap, 4); + memcpy (&out, &swap, 4); return out; } inline static gdouble -GDOUBLE_SWAP_LE_BE(gdouble in) +GDOUBLE_SWAP_LE_BE (gdouble in) { gint64 swap; gdouble out; - memcpy(&swap, &in, 8); + + memcpy (&swap, &in, 8); swap = GUINT64_SWAP_LE_BE_CONSTANT (swap); - memcpy(&out, &swap, 8); + memcpy (&out, &swap, 8); return out; } @@ -101,6 +94,4 @@ GDOUBLE_SWAP_LE_BE(gdouble in) #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val)) G_END_DECLS - #endif /* __FLOATCAST_H__ */ - diff --git a/gst-libs/gst/gconf/gconf.c b/gst-libs/gst/gconf/gconf.c index a96b786f7d..1887b7184d 100644 --- a/gst-libs/gst/gconf/gconf.c +++ b/gst-libs/gst/gconf/gconf.c @@ -31,7 +31,7 @@ #error "GST_GCONF_DIR is not defined !" #endif -static GConfClient *_gst_gconf_client = NULL; /* GConf connection */ +static GConfClient *_gst_gconf_client = NULL; /* GConf connection */ /* internal functions */ @@ -48,7 +48,7 @@ gst_gconf_get_client (void) /* go through a bin, finding the one pad that is unconnected in the given * * direction, and return that pad */ static GstPad * -gst_bin_find_unconnected_pad (GstBin *bin, GstPadDirection direction) +gst_bin_find_unconnected_pad (GstBin * bin, GstPadDirection direction) { GstPad *pad = NULL; GList *elements = NULL; @@ -57,22 +57,19 @@ gst_bin_find_unconnected_pad (GstBin *bin, GstPadDirection direction) elements = (GList *) gst_bin_get_list (bin); /* traverse all elements looking for unconnected pads */ - while (elements && pad == NULL) - { + while (elements && pad == NULL) { element = GST_ELEMENT (elements->data); pads = gst_element_get_pad_list (element); - while (pads) - { + while (pads) { /* check if the direction matches */ - if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == direction) - { - if (GST_PAD_PEER (GST_PAD (pads->data)) == NULL) - { - /* found it ! */ + if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == direction) { + if (GST_PAD_PEER (GST_PAD (pads->data)) == NULL) { + /* found it ! */ pad = GST_PAD (pads->data); } } - if (pad) break; /* found one already */ + if (pad) + break; /* found one already */ pads = g_list_next (pads); } elements = g_list_next (elements); @@ -91,7 +88,7 @@ gst_bin_find_unconnected_pad (GstBin *bin, GstPadDirection direction) * Returns: a #gchar string containing @key's value. */ gchar * -gst_gconf_get_string (const gchar *key) +gst_gconf_get_string (const gchar * key) { GError *error = NULL; gchar *value = NULL; @@ -101,8 +98,7 @@ gst_gconf_get_string (const gchar *key) value = gconf_client_get_string (gst_gconf_get_client (), full_key, &error); g_free (full_key); - if (error) - { + if (error) { g_print ("gst_gconf_get_string: error: %s\n", error->message); g_error_free (error); } @@ -118,14 +114,13 @@ gst_gconf_get_string (const gchar *key) * Set GConf key @key to string value @value. */ void -gst_gconf_set_string (const gchar *key, const gchar *value) +gst_gconf_set_string (const gchar * key, const gchar * value) { GError *error = NULL; gchar *full_key = g_strdup_printf ("%s/%s", GST_GCONF_DIR, key); gconf_client_set_string (gst_gconf_get_client (), full_key, value, &error); - if (error) - { + if (error) { g_print ("gst_gconf_set_string: error: %s\n", error->message); g_error_free (error); } @@ -141,7 +136,7 @@ gst_gconf_set_string (const gchar *key, const gchar *value) * Returns: a #GstElement containing the rendered bin. */ GstElement * -gst_gconf_render_bin_from_description (const gchar *description) +gst_gconf_render_bin_from_description (const gchar * description) { GstElement *bin = NULL; GstPad *pad = NULL; @@ -152,19 +147,18 @@ gst_gconf_render_bin_from_description (const gchar *description) desc = g_strdup_printf ("bin.( %s )", description); bin = GST_ELEMENT (gst_parse_launch (desc, &error)); g_free (desc); - if (error) - { + if (error) { g_print ("DEBUG: gstgconf: error parsing pipeline %s\n%s\n", - description, error->message); + description, error->message); g_error_free (error); return NULL; } /* find pads and ghost them if necessary */ - if ((pad = gst_bin_find_unconnected_pad (GST_BIN (bin), GST_PAD_SRC))){ + if ((pad = gst_bin_find_unconnected_pad (GST_BIN (bin), GST_PAD_SRC))) { gst_element_add_ghost_pad (bin, pad, "src"); } - if ((pad = gst_bin_find_unconnected_pad (GST_BIN (bin), GST_PAD_SINK))){ + if ((pad = gst_bin_find_unconnected_pad (GST_BIN (bin), GST_PAD_SINK))) { gst_element_add_ghost_pad (bin, pad, "sink"); } return bin; @@ -179,11 +173,11 @@ gst_gconf_render_bin_from_description (const gchar *description) * Returns: a #GstElement containing the rendered bin. */ GstElement * -gst_gconf_render_bin_from_key (const gchar *key) +gst_gconf_render_bin_from_key (const gchar * key) { GstElement *bin = NULL; gchar *value; - + value = gst_gconf_get_string (key); if (value) bin = gst_gconf_render_bin_from_description (value); @@ -203,10 +197,10 @@ GstElement * gst_gconf_get_default_audio_sink (void) { GstElement *ret = gst_gconf_render_bin_from_key ("default/audiosink"); - + if (!ret) { ret = gst_element_factory_make ("osssink", NULL); - + if (!ret) g_warning ("No GConf default audio sink key and osssink doesn't work"); else @@ -229,10 +223,10 @@ GstElement * gst_gconf_get_default_video_sink (void) { GstElement *ret = gst_gconf_render_bin_from_key ("default/videosink"); - + if (!ret) { ret = gst_element_factory_make ("ximagesink", NULL); - + if (!ret) g_warning ("No GConf default video sink key and ximagesink doesn't work"); else @@ -255,10 +249,10 @@ GstElement * gst_gconf_get_default_audio_src (void) { GstElement *ret = gst_gconf_render_bin_from_key ("default/audiosrc"); - + if (!ret) { ret = gst_element_factory_make ("osssrc", NULL); - + if (!ret) g_warning ("No GConf default audio src key and osssrc doesn't work"); else @@ -282,10 +276,10 @@ GstElement * gst_gconf_get_default_video_src (void) { GstElement *ret = gst_gconf_render_bin_from_key ("default/videosrc"); - + if (!ret) { ret = gst_element_factory_make ("videotestsrc", NULL); - + if (!ret) g_warning ("No GConf default video src key and videotestrc doesn't work"); else @@ -308,16 +302,16 @@ GstElement * gst_gconf_get_default_visualization_element (void) { GstElement *ret = gst_gconf_render_bin_from_key ("default/visualization"); - + if (!ret) { ret = gst_element_factory_make ("goom", NULL); - + if (!ret) - g_warning ("No GConf default visualization plugin key and goom doesn't work"); + g_warning + ("No GConf default visualization plugin key and goom doesn't work"); else g_print ("GConf visualization plugin not found, using goom\n"); } return ret; } - diff --git a/gst-libs/gst/gconf/gconf.h b/gst-libs/gst/gconf/gconf.h index 70007f770b..79546a7a14 100644 --- a/gst-libs/gst/gconf/gconf.h +++ b/gst-libs/gst/gconf/gconf.h @@ -27,17 +27,16 @@ #include #include -gchar * gst_gconf_get_string (const gchar *key); -void gst_gconf_set_string (const gchar *key, - const gchar *value); +gchar *gst_gconf_get_string (const gchar * key); +void gst_gconf_set_string (const gchar * key, const gchar * value); -GstElement * gst_gconf_render_bin_from_key (const gchar *key); -GstElement * gst_gconf_render_bin_from_description (const gchar *description); +GstElement *gst_gconf_render_bin_from_key (const gchar * key); +GstElement *gst_gconf_render_bin_from_description (const gchar * description); -GstElement * gst_gconf_get_default_video_sink (void); -GstElement * gst_gconf_get_default_audio_sink (void); -GstElement * gst_gconf_get_default_video_src (void); -GstElement * gst_gconf_get_default_audio_src (void); -GstElement * gst_gconf_get_default_visualization_element (void); +GstElement *gst_gconf_get_default_video_sink (void); +GstElement *gst_gconf_get_default_audio_sink (void); +GstElement *gst_gconf_get_default_video_src (void); +GstElement *gst_gconf_get_default_audio_src (void); +GstElement *gst_gconf_get_default_visualization_element (void); #endif /* GST_GCONF_H */ diff --git a/gst-libs/gst/gconf/test-gconf.c b/gst-libs/gst/gconf/test-gconf.c index 06d5b61d25..a3c99646ab 100644 --- a/gst-libs/gst/gconf/test-gconf.c +++ b/gst-libs/gst/gconf/test-gconf.c @@ -22,13 +22,13 @@ int main (int argc, char *argv[]) { - printf ("Default video sink : %s\n", - gst_gconf_get_string ("default/videosink")); - printf ("Default audio sink : %s\n", - gst_gconf_get_string ("default/audiosink")); - printf ("Default video src : %s\n", - gst_gconf_get_string ("default/videosrc")); - printf ("Default audio src : %s\n", - gst_gconf_get_string ("default/audiosrc")); + printf ("Default video sink : %s\n", + gst_gconf_get_string ("default/videosink")); + printf ("Default audio sink : %s\n", + gst_gconf_get_string ("default/audiosink")); + printf ("Default video src : %s\n", + gst_gconf_get_string ("default/videosrc")); + printf ("Default audio src : %s\n", + gst_gconf_get_string ("default/audiosrc")); return 0; } diff --git a/gst-libs/gst/gst-i18n-plugin.h b/gst-libs/gst/gst-i18n-plugin.h index 2c37a61506..846b1b0a18 100644 --- a/gst-libs/gst/gst-i18n-plugin.h +++ b/gst-libs/gst/gst-i18n-plugin.h @@ -22,8 +22,8 @@ #ifndef __GST_I18N_PLUGIN_H__ #define __GST_I18N_PLUGIN_H__ -#include /* some people need it and some people don't */ -#include "gettext.h" /* included with gettext distribution and copied */ +#include /* some people need it and some people don't */ +#include "gettext.h" /* included with gettext distribution and copied */ #ifndef GETTEXT_PACKAGE #error You must define GETTEXT_PACKAGE before including this header. diff --git a/gst-libs/gst/idct/dct.h b/gst-libs/gst/idct/dct.h index efb3ddb36d..c2e3744995 100644 --- a/gst-libs/gst/idct/dct.h +++ b/gst-libs/gst/idct/dct.h @@ -16,7 +16,7 @@ typedef DCTELEM DCTBLOCK[DCTSIZE2]; typedef long INT32; /* must be at least 32 bits */ -extern void gst_idct_int_idct(); +extern void gst_idct_int_idct (); extern void gst_idct_init_fast_int_idct (void); extern void gst_idct_fast_int_idct (short *block); @@ -27,6 +27,5 @@ extern void gst_idct_mmx32_idct (short *block); extern void gst_idct_sse_idct (short *block); #endif /* HAVE_LIBMMX */ -extern void gst_idct_init_float_idct(void); +extern void gst_idct_init_float_idct (void); extern void gst_idct_float_idct (short *block); - diff --git a/gst-libs/gst/idct/fastintidct.c b/gst-libs/gst/idct/fastintidct.c index 2742667212..9bb1436dff 100644 --- a/gst-libs/gst/idct/fastintidct.c +++ b/gst-libs/gst/idct/fastintidct.c @@ -45,17 +45,17 @@ /* this code assumes >> to be a two's-complement arithmetic */ /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */ -#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */ -#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */ -#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */ -#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */ -#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */ -#define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */ +#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */ +#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */ +#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */ +#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */ +#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */ +#define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */ #include "dct.h" /* private data */ -static short iclip[1024]; /* clipping table */ +static short iclip[1024]; /* clipping table */ static short *iclp; /* private prototypes */ @@ -72,57 +72,58 @@ static void idctcol (short *blk); * c[1..7] = 128*sqrt(2) */ -static void idctrow(blk) -short *blk; +static void +idctrow (blk) + short *blk; { int x0, x1, x2, x3, x4, x5, x6, x7, x8; /* shortcut */ - if (!((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) | - (x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3]))) - { - blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3; + if (!((x1 = blk[4] << 11) | (x2 = blk[6]) | (x3 = blk[2]) | + (x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3]))) { + blk[0] = blk[1] = blk[2] = blk[3] = blk[4] = blk[5] = blk[6] = blk[7] = + blk[0] << 3; return; } - x0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage */ + x0 = (blk[0] << 11) + 128; /* for proper rounding in the fourth stage */ /* first stage */ - x8 = W7*(x4+x5); - x4 = x8 + (W1-W7)*x4; - x5 = x8 - (W1+W7)*x5; - x8 = W3*(x6+x7); - x6 = x8 - (W3-W5)*x6; - x7 = x8 - (W3+W5)*x7; - + x8 = W7 * (x4 + x5); + x4 = x8 + (W1 - W7) * x4; + x5 = x8 - (W1 + W7) * x5; + x8 = W3 * (x6 + x7); + x6 = x8 - (W3 - W5) * x6; + x7 = x8 - (W3 + W5) * x7; + /* second stage */ x8 = x0 + x1; x0 -= x1; - x1 = W6*(x3+x2); - x2 = x1 - (W2+W6)*x2; - x3 = x1 + (W2-W6)*x3; + x1 = W6 * (x3 + x2); + x2 = x1 - (W2 + W6) * x2; + x3 = x1 + (W2 - W6) * x3; x1 = x4 + x6; x4 -= x6; x6 = x5 + x7; x5 -= x7; - + /* third stage */ x7 = x8 + x3; x8 -= x3; x3 = x0 + x2; x0 -= x2; - x2 = (181*(x4+x5)+128)>>8; - x4 = (181*(x4-x5)+128)>>8; - + x2 = (181 * (x4 + x5) + 128) >> 8; + x4 = (181 * (x4 - x5) + 128) >> 8; + /* fourth stage */ - blk[0] = (x7+x1)>>8; - blk[1] = (x3+x2)>>8; - blk[2] = (x0+x4)>>8; - blk[3] = (x8+x6)>>8; - blk[4] = (x8-x6)>>8; - blk[5] = (x0-x4)>>8; - blk[6] = (x3-x2)>>8; - blk[7] = (x7-x1)>>8; + blk[0] = (x7 + x1) >> 8; + blk[1] = (x3 + x2) >> 8; + blk[2] = (x0 + x4) >> 8; + blk[3] = (x8 + x6) >> 8; + blk[4] = (x8 - x6) >> 8; + blk[5] = (x0 - x4) >> 8; + blk[6] = (x3 - x2) >> 8; + blk[7] = (x7 - x1) >> 8; } /* column (vertical) IDCT @@ -134,78 +135,81 @@ short *blk; * where: c[0] = 1/1024 * c[1..7] = (1/1024)*sqrt(2) */ -static void idctcol(blk) -short *blk; +static void +idctcol (blk) + short *blk; { int x0, x1, x2, x3, x4, x5, x6, x7, x8; /* shortcut */ - if (!((x1 = (blk[8*4]<<8)) | (x2 = blk[8*6]) | (x3 = blk[8*2]) | - (x4 = blk[8*1]) | (x5 = blk[8*7]) | (x6 = blk[8*5]) | (x7 = blk[8*3]))) - { - blk[8*0]=blk[8*1]=blk[8*2]=blk[8*3]=blk[8*4]=blk[8*5]=blk[8*6]=blk[8*7]= - iclp[(blk[8*0]+32)>>6]; + if (!((x1 = (blk[8 * 4] << 8)) | (x2 = blk[8 * 6]) | (x3 = blk[8 * 2]) | + (x4 = blk[8 * 1]) | (x5 = blk[8 * 7]) | (x6 = blk[8 * 5]) | (x7 = + blk[8 * 3]))) { + blk[8 * 0] = blk[8 * 1] = blk[8 * 2] = blk[8 * 3] = blk[8 * 4] = + blk[8 * 5] = blk[8 * 6] = blk[8 * 7] = iclp[(blk[8 * 0] + 32) >> 6]; return; } - x0 = (blk[8*0]<<8) + 8192; + x0 = (blk[8 * 0] << 8) + 8192; /* first stage */ - x8 = W7*(x4+x5) + 4; - x4 = (x8+(W1-W7)*x4)>>3; - x5 = (x8-(W1+W7)*x5)>>3; - x8 = W3*(x6+x7) + 4; - x6 = (x8-(W3-W5)*x6)>>3; - x7 = (x8-(W3+W5)*x7)>>3; - + x8 = W7 * (x4 + x5) + 4; + x4 = (x8 + (W1 - W7) * x4) >> 3; + x5 = (x8 - (W1 + W7) * x5) >> 3; + x8 = W3 * (x6 + x7) + 4; + x6 = (x8 - (W3 - W5) * x6) >> 3; + x7 = (x8 - (W3 + W5) * x7) >> 3; + /* second stage */ x8 = x0 + x1; x0 -= x1; - x1 = W6*(x3+x2) + 4; - x2 = (x1-(W2+W6)*x2)>>3; - x3 = (x1+(W2-W6)*x3)>>3; + x1 = W6 * (x3 + x2) + 4; + x2 = (x1 - (W2 + W6) * x2) >> 3; + x3 = (x1 + (W2 - W6) * x3) >> 3; x1 = x4 + x6; x4 -= x6; x6 = x5 + x7; x5 -= x7; - + /* third stage */ x7 = x8 + x3; x8 -= x3; x3 = x0 + x2; x0 -= x2; - x2 = (181*(x4+x5)+128)>>8; - x4 = (181*(x4-x5)+128)>>8; - + x2 = (181 * (x4 + x5) + 128) >> 8; + x4 = (181 * (x4 - x5) + 128) >> 8; + /* fourth stage */ - blk[8*0] = iclp[(x7+x1)>>14]; - blk[8*1] = iclp[(x3+x2)>>14]; - blk[8*2] = iclp[(x0+x4)>>14]; - blk[8*3] = iclp[(x8+x6)>>14]; - blk[8*4] = iclp[(x8-x6)>>14]; - blk[8*5] = iclp[(x0-x4)>>14]; - blk[8*6] = iclp[(x3-x2)>>14]; - blk[8*7] = iclp[(x7-x1)>>14]; + blk[8 * 0] = iclp[(x7 + x1) >> 14]; + blk[8 * 1] = iclp[(x3 + x2) >> 14]; + blk[8 * 2] = iclp[(x0 + x4) >> 14]; + blk[8 * 3] = iclp[(x8 + x6) >> 14]; + blk[8 * 4] = iclp[(x8 - x6) >> 14]; + blk[8 * 5] = iclp[(x0 - x4) >> 14]; + blk[8 * 6] = iclp[(x3 - x2) >> 14]; + blk[8 * 7] = iclp[(x7 - x1) >> 14]; } /* two dimensional inverse discrete cosine transform */ -void gst_idct_fast_int_idct(block) -short *block; +void +gst_idct_fast_int_idct (block) + short *block; { int i; - for (i=0; i<8; i++) - idctrow(block+8*i); + for (i = 0; i < 8; i++) + idctrow (block + 8 * i); - for (i=0; i<8; i++) - idctcol(block+i); + for (i = 0; i < 8; i++) + idctcol (block + i); } -void gst_idct_init_fast_int_idct() +void +gst_idct_init_fast_int_idct () { int i; - iclp = iclip+512; - for (i= -512; i<512; i++) - iclp[i] = (i<-256) ? -256 : ((i>255) ? 255 : i); + iclp = iclip + 512; + for (i = -512; i < 512; i++) + iclp[i] = (i < -256) ? -256 : ((i > 255) ? 255 : i); } diff --git a/gst-libs/gst/idct/floatidct.c b/gst-libs/gst/idct/floatidct.c index b215bd7843..0fa1e83009 100644 --- a/gst-libs/gst/idct/floatidct.c +++ b/gst-libs/gst/idct/floatidct.c @@ -56,51 +56,51 @@ static double gst_idct_float_c[8][8]; /* initialize DCT coefficient matrix */ -void gst_idct_init_float_idct() +void +gst_idct_init_float_idct () { int freq, time; double scale; - for (freq=0; freq < 8; freq++) - { - scale = (freq == 0) ? sqrt(0.125) : 0.5; - for (time=0; time<8; time++) - gst_idct_float_c[freq][time] = scale*cos((PI/8.0)*freq*(time + 0.5)); + for (freq = 0; freq < 8; freq++) { + scale = (freq == 0) ? sqrt (0.125) : 0.5; + for (time = 0; time < 8; time++) + gst_idct_float_c[freq][time] = + scale * cos ((PI / 8.0) * freq * (time + 0.5)); } } /* perform IDCT matrix multiply for 8x8 coefficient block */ -void gst_idct_float_idct(block) -short *block; +void +gst_idct_float_idct (block) + short *block; { int i, j, k, v; double partial_product; double tmp[64]; - for (i=0; i<8; i++) - for (j=0; j<8; j++) - { + for (i = 0; i < 8; i++) + for (j = 0; j < 8; j++) { partial_product = 0.0; - for (k=0; k<8; k++) - partial_product+= gst_idct_float_c[k][j]*block[8*i+k]; + for (k = 0; k < 8; k++) + partial_product += gst_idct_float_c[k][j] * block[8 * i + k]; - tmp[8*i+j] = partial_product; + tmp[8 * i + j] = partial_product; } /* Transpose operation is integrated into address mapping by switching loop order of i and j */ - for (j=0; j<8; j++) - for (i=0; i<8; i++) - { + for (j = 0; j < 8; j++) + for (i = 0; i < 8; i++) { partial_product = 0.0; - for (k=0; k<8; k++) - partial_product+= gst_idct_float_c[k][i]*tmp[8*k+j]; + for (k = 0; k < 8; k++) + partial_product += gst_idct_float_c[k][i] * tmp[8 * k + j]; - v = (int) floor(partial_product+0.5); - block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v); + v = (int) floor (partial_product + 0.5); + block[8 * i + j] = (v < -256) ? -256 : ((v > 255) ? 255 : v); } } diff --git a/gst-libs/gst/idct/idct.c b/gst-libs/gst/idct/idct.c index 59c6a844da..4be150f1fc 100644 --- a/gst-libs/gst/idct/idct.c +++ b/gst-libs/gst/idct/idct.c @@ -25,24 +25,25 @@ #include #include "dct.h" -static void gst_idct_int_sparse_idct(short *data); +static void gst_idct_int_sparse_idct (short *data); -GstIDCT *gst_idct_new(GstIDCTMethod method) +GstIDCT * +gst_idct_new (GstIDCTMethod method) { - GstIDCT *new = g_malloc(sizeof(GstIDCT)); + GstIDCT *new = g_malloc (sizeof (GstIDCT)); new->need_transpose = FALSE; if (method == GST_IDCT_DEFAULT) { #ifdef HAVE_LIBMMX - if (gst_cpu_get_flags() & GST_CPU_FLAG_MMX) { + if (gst_cpu_get_flags () & GST_CPU_FLAG_MMX) { method = GST_IDCT_MMX; } /* disabled for now - if (gst_cpu_get_flags() & GST_CPU_FLAG_SSE) { - method = GST_IDCT_SSE; - } - */ + if (gst_cpu_get_flags() & GST_CPU_FLAG_SSE) { + method = GST_IDCT_SSE; + } + */ else #endif /* HAVE_LIBMMX */ { @@ -53,49 +54,50 @@ GstIDCT *gst_idct_new(GstIDCTMethod method) new->convert_sparse = gst_idct_int_sparse_idct; switch (method) { - case GST_IDCT_FAST_INT: - GST_INFO ( "using fast_int_idct"); - gst_idct_init_fast_int_idct(); - new->convert = gst_idct_fast_int_idct; - break; - case GST_IDCT_INT: - GST_INFO ( "using int_idct"); - new->convert = gst_idct_int_idct; - break; - case GST_IDCT_FLOAT: - GST_INFO ( "using float_idct"); - gst_idct_init_float_idct(); - new->convert = gst_idct_float_idct; - break; + case GST_IDCT_FAST_INT: + GST_INFO ("using fast_int_idct"); + gst_idct_init_fast_int_idct (); + new->convert = gst_idct_fast_int_idct; + break; + case GST_IDCT_INT: + GST_INFO ("using int_idct"); + new->convert = gst_idct_int_idct; + break; + case GST_IDCT_FLOAT: + GST_INFO ("using float_idct"); + gst_idct_init_float_idct (); + new->convert = gst_idct_float_idct; + break; #ifdef HAVE_LIBMMX - case GST_IDCT_MMX: - GST_INFO ( "using MMX_idct"); - new->convert = gst_idct_mmx_idct; - new->need_transpose = TRUE; - break; - case GST_IDCT_MMX32: - GST_INFO ( "using MMX32_idct"); - new->convert = gst_idct_mmx32_idct; - new->need_transpose = TRUE; - break; - case GST_IDCT_SSE: - GST_INFO ( "using SSE_idct"); - new->convert = gst_idct_sse_idct; - new->need_transpose = TRUE; - break; + case GST_IDCT_MMX: + GST_INFO ("using MMX_idct"); + new->convert = gst_idct_mmx_idct; + new->need_transpose = TRUE; + break; + case GST_IDCT_MMX32: + GST_INFO ("using MMX32_idct"); + new->convert = gst_idct_mmx32_idct; + new->need_transpose = TRUE; + break; + case GST_IDCT_SSE: + GST_INFO ("using SSE_idct"); + new->convert = gst_idct_sse_idct; + new->need_transpose = TRUE; + break; #endif /* HAVE_LIBMMX */ - default: - GST_INFO ( "method not supported"); - g_free(new); - return NULL; + default: + GST_INFO ("method not supported"); + g_free (new); + return NULL; } return new; } -static void gst_idct_int_sparse_idct(short *data) +static void +gst_idct_int_sparse_idct (short *data) { short val; - gint32 v, *dp = (guint32 *)data; + gint32 v, *dp = (guint32 *) data; v = *data; @@ -104,43 +106,61 @@ static void gst_idct_int_sparse_idct(short *data) val += (8 >> 1); val /= 8; val = -val; - } - else { + } else { val = (v + (8 >> 1)) / 8; } - v = (( val & 0xffff) | (val << 16)); + v = ((val & 0xffff) | (val << 16)); - dp[0] = v; dp[1] = v; dp[2] = v; dp[3] = v; - dp[4] = v; dp[5] = v; dp[6] = v; dp[7] = v; - dp[8] = v; dp[9] = v; dp[10] = v; dp[11] = v; - dp[12] = v; dp[13] = v; dp[14] = v; dp[15] = v; - dp[16] = v; dp[17] = v; dp[18] = v; dp[19] = v; - dp[20] = v; dp[21] = v; dp[22] = v; dp[23] = v; - dp[24] = v; dp[25] = v; dp[26] = v; dp[27] = v; - dp[28] = v; dp[29] = v; dp[30] = v; dp[31] = v; + dp[0] = v; + dp[1] = v; + dp[2] = v; + dp[3] = v; + dp[4] = v; + dp[5] = v; + dp[6] = v; + dp[7] = v; + dp[8] = v; + dp[9] = v; + dp[10] = v; + dp[11] = v; + dp[12] = v; + dp[13] = v; + dp[14] = v; + dp[15] = v; + dp[16] = v; + dp[17] = v; + dp[18] = v; + dp[19] = v; + dp[20] = v; + dp[21] = v; + dp[22] = v; + dp[23] = v; + dp[24] = v; + dp[25] = v; + dp[26] = v; + dp[27] = v; + dp[28] = v; + dp[29] = v; + dp[30] = v; + dp[31] = v; } -void gst_idct_destroy(GstIDCT *idct) +void +gst_idct_destroy (GstIDCT * idct) { - g_return_if_fail(idct != NULL); + g_return_if_fail (idct != NULL); - g_free(idct); + g_free (idct); } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gstidct", - "Accelerated IDCT routines", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstidct", + "Accelerated IDCT routines", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) diff --git a/gst-libs/gst/idct/idct.h b/gst-libs/gst/idct/idct.h index fa6f62cd79..37a2a0b9a3 100644 --- a/gst-libs/gst/idct/idct.h +++ b/gst-libs/gst/idct/idct.h @@ -23,22 +23,24 @@ #include -typedef enum { - GST_IDCT_DEFAULT, - GST_IDCT_INT, - GST_IDCT_FAST_INT, - GST_IDCT_FLOAT, - GST_IDCT_MMX, +typedef enum +{ + GST_IDCT_DEFAULT, + GST_IDCT_INT, + GST_IDCT_FAST_INT, + GST_IDCT_FLOAT, + GST_IDCT_MMX, GST_IDCT_MMX32, GST_IDCT_SSE, } GstIDCTMethod; typedef struct _GstIDCT GstIDCT; -typedef void (*GstIDCTFunction) (gshort *block); +typedef void (*GstIDCTFunction) (gshort * block); #define GST_IDCT_TRANSPOSE(idct) ((idct)->need_transpose) -struct _GstIDCT { +struct _GstIDCT +{ /* private */ GstIDCTFunction convert; GstIDCTFunction convert_sparse; @@ -46,9 +48,10 @@ struct _GstIDCT { }; -GstIDCT *gst_idct_new(GstIDCTMethod method); +GstIDCT *gst_idct_new (GstIDCTMethod method); + #define gst_idct_convert(idct, blocks) (idct)->convert((blocks)) #define gst_idct_convert_sparse(idct, blocks) (idct)->convert_sparse((blocks)) -void gst_idct_destroy(GstIDCT *idct); +void gst_idct_destroy (GstIDCT * idct); #endif /* __GST_IDCT_H__ */ diff --git a/gst-libs/gst/idct/ieeetest.c b/gst-libs/gst/idct/ieeetest.c index f5b270ebb8..d26181c1a6 100644 --- a/gst-libs/gst/idct/ieeetest.c +++ b/gst-libs/gst/idct/ieeetest.c @@ -27,9 +27,9 @@ void usage (char *msg); long ieeerand (long L, long H); -void dct_init(void); -void ref_fdct(DCTELEM block[8][8]); -void ref_idct(DCTELEM block[8][8]); +void dct_init (void); +void ref_fdct (DCTELEM block[8][8]); +void ref_idct (DCTELEM block[8][8]); /* error stat accumulators -- assume initialized to 0 */ @@ -38,47 +38,49 @@ long sumsqerrs[DCTSIZE2]; int maxerr[DCTSIZE2]; -char * meets (double val, double limit) +char * +meets (double val, double limit) { - return ((fabs(val) <= limit) ? "meets" : "FAILS"); + return ((fabs (val) <= limit) ? "meets" : "FAILS"); } int -main(int argc, char **argv) +main (int argc, char **argv) { long minpix, maxpix, sign; long curiter, niters; int i, j; double max, total; int method; - DCTELEM block[DCTSIZE2]; /* random source data */ - DCTELEM refcoefs[DCTSIZE2]; /* coefs from reference FDCT */ - DCTELEM refout[DCTSIZE2]; /* output from reference IDCT */ - DCTELEM testout[DCTSIZE2]; /* output from test IDCT */ - GstIDCT *idct; - guint64 tscstart, tscmin = ~0, tscmax = 0; - guint64 tscstop; + DCTELEM block[DCTSIZE2]; /* random source data */ + DCTELEM refcoefs[DCTSIZE2]; /* coefs from reference FDCT */ + DCTELEM refout[DCTSIZE2]; /* output from reference IDCT */ + DCTELEM testout[DCTSIZE2]; /* output from test IDCT */ + GstIDCT *idct; + guint64 tscstart, tscmin = ~0, tscmax = 0; + guint64 tscstop; /* Argument parsing --- not very bulletproof at all */ - if (argc != 6) usage(NULL); + if (argc != 6) + usage (NULL); - method = atoi(argv[1]); - minpix = atoi(argv[2]); - maxpix = atoi(argv[3]); - sign = atoi(argv[4]); - niters = atol(argv[5]); + method = atoi (argv[1]); + minpix = atoi (argv[2]); + maxpix = atoi (argv[3]); + sign = atoi (argv[4]); + niters = atol (argv[5]); - gst_library_load("gstidct"); + gst_library_load ("gstidct"); - idct = gst_idct_new(method); + idct = gst_idct_new (method); if (idct == 0) { - printf("method not available\n\n\n"); + printf ("method not available\n\n\n"); return 0; } - dct_init(); + dct_init (); /* Loop once per generated random-data block */ @@ -86,164 +88,186 @@ main(int argc, char **argv) /* generate a pseudo-random block of data */ for (i = 0; i < DCTSIZE2; i++) - block[i] = (DCTELEM) (ieeerand(-minpix,maxpix) * sign); + block[i] = (DCTELEM) (ieeerand (-minpix, maxpix) * sign); /* perform reference FDCT */ - memcpy(refcoefs, block, sizeof(DCTELEM)*DCTSIZE2); - ref_fdct((DCTELEM **) &refcoefs); + memcpy (refcoefs, block, sizeof (DCTELEM) * DCTSIZE2); + ref_fdct ((DCTELEM **) & refcoefs); /* clip */ for (i = 0; i < DCTSIZE2; i++) { - if (refcoefs[i] < -2048) refcoefs[i] = -2048; - else if (refcoefs[i] > 2047) refcoefs[i] = 2047; + if (refcoefs[i] < -2048) + refcoefs[i] = -2048; + else if (refcoefs[i] > 2047) + refcoefs[i] = 2047; } /* perform reference IDCT */ - memcpy(refout, refcoefs, sizeof(DCTELEM)*DCTSIZE2); - ref_idct(refout); + memcpy (refout, refcoefs, sizeof (DCTELEM) * DCTSIZE2); + ref_idct (refout); /* clip */ for (i = 0; i < DCTSIZE2; i++) { - if (refout[i] < -256) refout[i] = -256; - else if (refout[i] > 255) refout[i] = 255; + if (refout[i] < -256) + refout[i] = -256; + else if (refout[i] > 255) + refout[i] = 255; } /* perform test IDCT */ - if (GST_IDCT_TRANSPOSE(idct)) { + if (GST_IDCT_TRANSPOSE (idct)) { for (j = 0; j < DCTSIZE; j++) { - for (i = 0; i < DCTSIZE; i++) { - testout[i*DCTSIZE+j] = refcoefs[j*DCTSIZE+i]; - } - } - } - else { - memcpy(testout, refcoefs, sizeof(DCTELEM)*DCTSIZE2); - } + for (i = 0; i < DCTSIZE; i++) { + testout[i * DCTSIZE + j] = refcoefs[j * DCTSIZE + i]; + } + } + } else { + memcpy (testout, refcoefs, sizeof (DCTELEM) * DCTSIZE2); + } - gst_trace_read_tsc(&tscstart); - gst_idct_convert(idct, testout); - gst_trace_read_tsc(&tscstop); - /*printf("time %llu, %llu %lld\n", tscstart, tscstop, tscstop-tscstart); */ - if (tscstop - tscstart < tscmin) tscmin = tscstop-tscstart; - if (tscstop - tscstart > tscmax) tscmax = tscstop-tscstart; + gst_trace_read_tsc (&tscstart); + gst_idct_convert (idct, testout); + gst_trace_read_tsc (&tscstop); + /*printf("time %llu, %llu %lld\n", tscstart, tscstop, tscstop-tscstart); */ + if (tscstop - tscstart < tscmin) + tscmin = tscstop - tscstart; + if (tscstop - tscstart > tscmax) + tscmax = tscstop - tscstart; /* clip */ for (i = 0; i < DCTSIZE2; i++) { - if (testout[i] < -256) testout[i] = -256; - else if (testout[i] > 255) testout[i] = 255; + if (testout[i] < -256) + testout[i] = -256; + else if (testout[i] > 255) + testout[i] = 255; } /* accumulate error stats */ for (i = 0; i < DCTSIZE2; i++) { register int err = testout[i] - refout[i]; + sumerrs[i] += err; sumsqerrs[i] += err * err; - if (err < 0) err = -err; - if (maxerr[i] < err) maxerr[i] = err; + if (err < 0) + err = -err; + if (maxerr[i] < err) + maxerr[i] = err; } if (curiter % 100 == 99) { - fprintf(stderr, "."); - fflush(stderr); + fprintf (stderr, "."); + fflush (stderr); } } - fprintf(stderr, "\n"); + fprintf (stderr, "\n"); /* print results */ - printf("IEEE test conditions: -L = %ld, +H = %ld, sign = %ld, #iters = %ld\n", - minpix, maxpix, sign, niters); + printf + ("IEEE test conditions: -L = %ld, +H = %ld, sign = %ld, #iters = %ld\n", + minpix, maxpix, sign, niters); - printf("Speed, min time %lld, max %lld\n", tscmin, tscmax); + printf ("Speed, min time %lld, max %lld\n", tscmin, tscmax); - printf("Peak absolute values of errors:\n"); + printf ("Peak absolute values of errors:\n"); for (i = 0, j = 0; i < DCTSIZE2; i++) { - if (j < maxerr[i]) j = maxerr[i]; - printf("%4d", maxerr[i]); - if ((i%DCTSIZE) == DCTSIZE-1) printf("\n"); + if (j < maxerr[i]) + j = maxerr[i]; + printf ("%4d", maxerr[i]); + if ((i % DCTSIZE) == DCTSIZE - 1) + printf ("\n"); } - printf("Worst peak error = %d (%s spec limit 1)\n\n", j, - meets((double) j, 1.0)); + printf ("Worst peak error = %d (%s spec limit 1)\n\n", j, + meets ((double) j, 1.0)); - printf("Mean square errors:\n"); + printf ("Mean square errors:\n"); max = total = 0.0; for (i = 0; i < DCTSIZE2; i++) { - double err = (double) sumsqerrs[i] / ((double) niters); + double err = (double) sumsqerrs[i] / ((double) niters); + total += (double) sumsqerrs[i]; - if (max < err) max = err; - printf(" %8.4f", err); - if ((i%DCTSIZE) == DCTSIZE-1) printf("\n"); + if (max < err) + max = err; + printf (" %8.4f", err); + if ((i % DCTSIZE) == DCTSIZE - 1) + printf ("\n"); } - printf("Worst pmse = %.6f (%s spec limit 0.06)\n", max, meets(max, 0.06)); - total /= (double) (64*niters); - printf("Overall mse = %.6f (%s spec limit 0.02)\n\n", total, - meets(total, 0.02)); + printf ("Worst pmse = %.6f (%s spec limit 0.06)\n", max, meets (max, 0.06)); + total /= (double) (64 * niters); + printf ("Overall mse = %.6f (%s spec limit 0.02)\n\n", total, + meets (total, 0.02)); - printf("Mean errors:\n"); + printf ("Mean errors:\n"); max = total = 0.0; for (i = 0; i < DCTSIZE2; i++) { - double err = (double) sumerrs[i] / ((double) niters); + double err = (double) sumerrs[i] / ((double) niters); + total += (double) sumerrs[i]; - printf(" %8.4f", err); - if (err < 0.0) err = -err; - if (max < err) max = err; - if ((i%DCTSIZE) == DCTSIZE-1) printf("\n"); + printf (" %8.4f", err); + if (err < 0.0) + err = -err; + if (max < err) + max = err; + if ((i % DCTSIZE) == DCTSIZE - 1) + printf ("\n"); } - printf("Worst mean error = %.6f (%s spec limit 0.015)\n", max, - meets(max, 0.015)); - total /= (double) (64*niters); - printf("Overall mean error = %.6f (%s spec limit 0.0015)\n\n", total, - meets(total, 0.0015)); + printf ("Worst mean error = %.6f (%s spec limit 0.015)\n", max, + meets (max, 0.015)); + total /= (double) (64 * niters); + printf ("Overall mean error = %.6f (%s spec limit 0.0015)\n\n", total, + meets (total, 0.0015)); /* test for 0 input giving 0 output */ - memset(testout, 0, sizeof(DCTELEM)*DCTSIZE2); - gst_idct_convert(idct, testout); - for (i = 0, j=0; i < DCTSIZE2; i++) { + memset (testout, 0, sizeof (DCTELEM) * DCTSIZE2); + gst_idct_convert (idct, testout); + for (i = 0, j = 0; i < DCTSIZE2; i++) { if (testout[i]) { - printf("Position %d of IDCT(0) = %d (FAILS)\n", i, testout[i]); + printf ("Position %d of IDCT(0) = %d (FAILS)\n", i, testout[i]); j++; } } - printf("%d elements of IDCT(0) were not zero\n\n\n", j); + printf ("%d elements of IDCT(0) were not zero\n\n\n", j); - exit(0); + exit (0); return 0; } -void usage (char *msg) +void +usage (char *msg) { if (msg != NULL) - fprintf(stderr, "\nerror: %s\n", msg); + fprintf (stderr, "\nerror: %s\n", msg); - fprintf(stderr, "\n"); - fprintf(stderr, "usage: ieeetest minpix maxpix sign niters\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " test = 1 - 5\n"); - fprintf(stderr, " minpix = -L value per IEEE spec\n"); - fprintf(stderr, " maxpix = H value per IEEE spec\n"); - fprintf(stderr, " sign = +1 for normal, -1 to run negated test\n"); - fprintf(stderr, " niters = # iterations (10000 for full test)\n"); - fprintf(stderr, "\n"); + fprintf (stderr, "\n"); + fprintf (stderr, "usage: ieeetest minpix maxpix sign niters\n"); + fprintf (stderr, "\n"); + fprintf (stderr, " test = 1 - 5\n"); + fprintf (stderr, " minpix = -L value per IEEE spec\n"); + fprintf (stderr, " maxpix = H value per IEEE spec\n"); + fprintf (stderr, " sign = +1 for normal, -1 to run negated test\n"); + fprintf (stderr, " niters = # iterations (10000 for full test)\n"); + fprintf (stderr, "\n"); - exit(1); + exit (1); } /* Pseudo-random generator specified by IEEE 1180 */ -long ieeerand (long L, long H) +long +ieeerand (long L, long H) { static long randx = 1; static double z = (double) 0x7fffffff; - long i,j; + long i, j; double x; randx = (randx * 1103515245) + 12345; i = randx & 0x7ffffffe; x = ((double) i) / z; - x *= (L+H+1); + x *= (L + H + 1); j = x; - return j-L; + return j - L; } @@ -256,33 +280,35 @@ double coslu[8][8]; /* Routine to initialise the cosine lookup table */ -void dct_init(void) +void +dct_init (void) { - int a,b; + int a, b; double tmp; - for(a=0;a<8;a++) - for(b=0;b<8;b++) { - tmp = cos((double)((a+a+1)*b) * (3.14159265358979323846 / 16.0)); - if(b==0) - tmp /= sqrt(2.0); + for (a = 0; a < 8; a++) + for (b = 0; b < 8; b++) { + tmp = cos ((double) ((a + a + 1) * b) * (3.14159265358979323846 / 16.0)); + if (b == 0) + tmp /= sqrt (2.0); coslu[a][b] = tmp * 0.5; } } -void ref_fdct (DCTELEM block[8][8]) +void +ref_fdct (DCTELEM block[8][8]) { - int x,y,u,v; + int x, y, u, v; double tmp, tmp2; double res[8][8]; - for (v=0; v<8; v++) { - for (u=0; u<8; u++) { + for (v = 0; v < 8; v++) { + for (u = 0; u < 8; u++) { tmp = 0.0; - for (y=0; y<8; y++) { + for (y = 0; y < 8; y++) { tmp2 = 0.0; - for (x=0; x<8; x++) { + for (x = 0; x < 8; x++) { tmp2 += (double) block[y][x] * coslu[x][u]; } tmp += coslu[y][v] * tmp2; @@ -291,11 +317,11 @@ void ref_fdct (DCTELEM block[8][8]) } } - for (v=0; v<8; v++) { - for (u=0; u<8; u++) { + for (v = 0; v < 8; v++) { + for (u = 0; u < 8; u++) { tmp = res[v][u]; if (tmp < 0.0) { - x = - ((int) (0.5 - tmp)); + x = -((int) (0.5 - tmp)); } else { x = (int) (tmp + 0.5); } @@ -305,18 +331,19 @@ void ref_fdct (DCTELEM block[8][8]) } -void ref_idct (DCTELEM block[8][8]) +void +ref_idct (DCTELEM block[8][8]) { - int x,y,u,v; + int x, y, u, v; double tmp, tmp2; double res[8][8]; - for (y=0; y<8; y++) { - for (x=0; x<8; x++) { + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x++) { tmp = 0.0; - for (v=0; v<8; v++) { + for (v = 0; v < 8; v++) { tmp2 = 0.0; - for (u=0; u<8; u++) { + for (u = 0; u < 8; u++) { tmp2 += (double) block[v][u] * coslu[x][u]; } tmp += coslu[y][v] * tmp2; @@ -325,11 +352,11 @@ void ref_idct (DCTELEM block[8][8]) } } - for (v=0; v<8; v++) { - for (u=0; u<8; u++) { + for (v = 0; v < 8; v++) { + for (u = 0; u < 8; u++) { tmp = res[v][u]; if (tmp < 0.0) { - x = - ((int) (0.5 - tmp)); + x = -((int) (0.5 - tmp)); } else { x = (int) (tmp + 0.5); } diff --git a/gst-libs/gst/idct/intidct.c b/gst-libs/gst/idct/intidct.c index e08e6adbe8..42f0ac842d 100644 --- a/gst-libs/gst/idct/intidct.c +++ b/gst-libs/gst/idct/intidct.c @@ -51,10 +51,8 @@ */ #if DCTSIZE != 8 - Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ +Sorry, this code only copes with 8 x8 DCTs. /* deliberate syntax err */ #endif - - /* * A 2-D IDCT can be done by 1-D IDCT on each row followed by 1-D IDCT * on each column. Direct algorithms are also available, but they are @@ -90,7 +88,6 @@ * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis * shows that the values given below are the most effective. */ - #ifdef EIGHT_BIT_SAMPLES #define CONST_BITS 13 #define PASS1_BITS 2 @@ -98,22 +95,16 @@ #define CONST_BITS 13 #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ #endif - #define ONE ((INT32) 1) - #define CONST_SCALE (ONE << CONST_BITS) - /* Convert a positive real constant to an integer scaled by CONST_SCALE. */ - #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5)) - /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus * causing a lot of useless floating-point operations at run time. * To get around this we use the following pre-calculated constants. * If you change CONST_BITS you may want to add appropriate values. * (With a reasonable C compiler, you can just rely on the FIX() macro...) */ - #if CONST_BITS == 13 #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */ #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */ @@ -141,15 +132,11 @@ #define FIX_2_562915447 FIX(2.562915447) #define FIX_3_072711026 FIX(3.072711026) #endif - - /* Descale and correctly round an INT32 value that's scaled by N bits. * We assume RIGHT_SHIFT rounds towards minus infinity, so adding * the fudge factor is correct for either sign of X. */ - #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) - /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. * For 8-bit samples with the recommended scaling, all the variable * and constant values involved are no more than 16 bits wide, so a @@ -160,7 +147,6 @@ * combination of casts. * NB: for 12-bit samples, a full 32-bit multiplication will be needed. */ - #ifdef EIGHT_BIT_SAMPLES #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ #define MULTIPLY(var,const) (((INT16) (var)) * ((INT16) (const))) @@ -169,17 +155,13 @@ #define MULTIPLY(var,const) (((INT16) (var)) * ((INT32) (const))) #endif #endif - #ifndef MULTIPLY /* default definition */ #define MULTIPLY(var,const) ((var) * (const)) #endif - - /* * Perform the inverse DCT on one block of coefficients. */ - -void + void gst_idct_int_idct (DCTBLOCK data) { INT32 tmp0, tmp1, tmp2, tmp3; @@ -187,14 +169,13 @@ gst_idct_int_idct (DCTBLOCK data) INT32 z1, z2, z3, z4, z5; register DCTELEM *dataptr; int rowctr; + SHIFT_TEMPS - - /* Pass 1: process rows. */ - /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ - /* furthermore, we scale the results by 2**PASS1_BITS. */ - - dataptr = data; - for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) { + /* Pass 1: process rows. */ + /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ + /* furthermore, we scale the results by 2**PASS1_BITS. */ + dataptr = data; + for (rowctr = DCTSIZE - 1; rowctr >= 0; rowctr--) { /* Due to quantization, we will usually find that many of the input * coefficients are zero, especially the AC terms. We can exploit this * by short-circuiting the IDCT calculation for any row in which all @@ -205,10 +186,10 @@ gst_idct_int_idct (DCTBLOCK data) */ if ((dataptr[1] | dataptr[2] | dataptr[3] | dataptr[4] | - dataptr[5] | dataptr[6] | dataptr[7]) == 0) { + dataptr[5] | dataptr[6] | dataptr[7]) == 0) { /* AC terms all zero */ DCTELEM dcval = (DCTELEM) (dataptr[0] << PASS1_BITS); - + dataptr[0] = dcval; dataptr[1] = dcval; dataptr[2] = dcval; @@ -217,7 +198,7 @@ gst_idct_int_idct (DCTBLOCK data) dataptr[5] = dcval; dataptr[6] = dcval; dataptr[7] = dcval; - + dataptr += DCTSIZE; /* advance pointer to next row */ continue; } @@ -228,9 +209,9 @@ gst_idct_int_idct (DCTBLOCK data) z2 = (INT32) dataptr[2]; z3 = (INT32) dataptr[6]; - z1 = MULTIPLY(z2 + z3, FIX_0_541196100); - tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); - tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); + z1 = MULTIPLY (z2 + z3, FIX_0_541196100); + tmp2 = z1 + MULTIPLY (z3, -FIX_1_847759065); + tmp3 = z1 + MULTIPLY (z2, FIX_0_765366865); tmp0 = ((INT32) dataptr[0] + (INT32) dataptr[4]) << CONST_BITS; tmp1 = ((INT32) dataptr[0] - (INT32) dataptr[4]) << CONST_BITS; @@ -239,7 +220,7 @@ gst_idct_int_idct (DCTBLOCK data) tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; - + /* Odd part per figure 8; the matrix is unitary and hence its * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. */ @@ -253,20 +234,20 @@ gst_idct_int_idct (DCTBLOCK data) z2 = tmp1 + tmp2; z3 = tmp0 + tmp2; z4 = tmp1 + tmp3; - z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ - - tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ - tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ - tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ - tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ - z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ - z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ - z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ - z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ - + z5 = MULTIPLY (z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp0 = MULTIPLY (tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp1 = MULTIPLY (tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp2 = MULTIPLY (tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp3 = MULTIPLY (tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY (z1, -FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY (z2, -FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY (z3, -FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY (z4, -FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + z3 += z5; z4 += z5; - + tmp0 += z1 + z3; tmp1 += z2 + z4; tmp2 += z2 + z3; @@ -274,14 +255,14 @@ gst_idct_int_idct (DCTBLOCK data) /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS); - dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS); - dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS); - dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS); - dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS); - dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS); - dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS); - dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS); + dataptr[0] = (DCTELEM) DESCALE (tmp10 + tmp3, CONST_BITS - PASS1_BITS); + dataptr[7] = (DCTELEM) DESCALE (tmp10 - tmp3, CONST_BITS - PASS1_BITS); + dataptr[1] = (DCTELEM) DESCALE (tmp11 + tmp2, CONST_BITS - PASS1_BITS); + dataptr[6] = (DCTELEM) DESCALE (tmp11 - tmp2, CONST_BITS - PASS1_BITS); + dataptr[2] = (DCTELEM) DESCALE (tmp12 + tmp1, CONST_BITS - PASS1_BITS); + dataptr[5] = (DCTELEM) DESCALE (tmp12 - tmp1, CONST_BITS - PASS1_BITS); + dataptr[3] = (DCTELEM) DESCALE (tmp13 + tmp0, CONST_BITS - PASS1_BITS); + dataptr[4] = (DCTELEM) DESCALE (tmp13 - tmp0, CONST_BITS - PASS1_BITS); dataptr += DCTSIZE; /* advance pointer to next row */ } @@ -291,7 +272,7 @@ gst_idct_int_idct (DCTBLOCK data) /* and also undo the PASS1_BITS scaling. */ dataptr = data; - for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) { + for (rowctr = DCTSIZE - 1; rowctr >= 0; rowctr--) { /* Columns of zeroes can be exploited in the same way as we did with rows. * However, the row calculation has created many nonzero AC terms, so the * simplification applies less often (typically 5% to 10% of the time). @@ -301,21 +282,21 @@ gst_idct_int_idct (DCTBLOCK data) */ #ifndef NO_ZERO_COLUMN_TEST - if ((dataptr[DCTSIZE*1] | dataptr[DCTSIZE*2] | dataptr[DCTSIZE*3] | - dataptr[DCTSIZE*4] | dataptr[DCTSIZE*5] | dataptr[DCTSIZE*6] | - dataptr[DCTSIZE*7]) == 0) { + if ((dataptr[DCTSIZE * 1] | dataptr[DCTSIZE * 2] | dataptr[DCTSIZE * 3] | + dataptr[DCTSIZE * 4] | dataptr[DCTSIZE * 5] | dataptr[DCTSIZE * 6] | + dataptr[DCTSIZE * 7]) == 0) { /* AC terms all zero */ - DCTELEM dcval = (DCTELEM) DESCALE((INT32) dataptr[0], PASS1_BITS+3); - - dataptr[DCTSIZE*0] = dcval; - dataptr[DCTSIZE*1] = dcval; - dataptr[DCTSIZE*2] = dcval; - dataptr[DCTSIZE*3] = dcval; - dataptr[DCTSIZE*4] = dcval; - dataptr[DCTSIZE*5] = dcval; - dataptr[DCTSIZE*6] = dcval; - dataptr[DCTSIZE*7] = dcval; - + DCTELEM dcval = (DCTELEM) DESCALE ((INT32) dataptr[0], PASS1_BITS + 3); + + dataptr[DCTSIZE * 0] = dcval; + dataptr[DCTSIZE * 1] = dcval; + dataptr[DCTSIZE * 2] = dcval; + dataptr[DCTSIZE * 3] = dcval; + dataptr[DCTSIZE * 4] = dcval; + dataptr[DCTSIZE * 5] = dcval; + dataptr[DCTSIZE * 6] = dcval; + dataptr[DCTSIZE * 7] = dcval; + dataptr++; /* advance pointer to next column */ continue; } @@ -324,48 +305,52 @@ gst_idct_int_idct (DCTBLOCK data) /* Even part: reverse the even part of the forward DCT. */ /* The rotator is sqrt(2)*c(-6). */ - z2 = (INT32) dataptr[DCTSIZE*2]; - z3 = (INT32) dataptr[DCTSIZE*6]; + z2 = (INT32) dataptr[DCTSIZE * 2]; + z3 = (INT32) dataptr[DCTSIZE * 6]; - z1 = MULTIPLY(z2 + z3, FIX_0_541196100); - tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); - tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); + z1 = MULTIPLY (z2 + z3, FIX_0_541196100); + tmp2 = z1 + MULTIPLY (z3, -FIX_1_847759065); + tmp3 = z1 + MULTIPLY (z2, FIX_0_765366865); - tmp0 = ((INT32) dataptr[DCTSIZE*0] + (INT32) dataptr[DCTSIZE*4]) << CONST_BITS; - tmp1 = ((INT32) dataptr[DCTSIZE*0] - (INT32) dataptr[DCTSIZE*4]) << CONST_BITS; + tmp0 = + ((INT32) dataptr[DCTSIZE * 0] + + (INT32) dataptr[DCTSIZE * 4]) << CONST_BITS; + tmp1 = + ((INT32) dataptr[DCTSIZE * 0] - + (INT32) dataptr[DCTSIZE * 4]) << CONST_BITS; tmp10 = tmp0 + tmp3; tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; - + /* Odd part per figure 8; the matrix is unitary and hence its * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. */ - tmp0 = (INT32) dataptr[DCTSIZE*7]; - tmp1 = (INT32) dataptr[DCTSIZE*5]; - tmp2 = (INT32) dataptr[DCTSIZE*3]; - tmp3 = (INT32) dataptr[DCTSIZE*1]; + tmp0 = (INT32) dataptr[DCTSIZE * 7]; + tmp1 = (INT32) dataptr[DCTSIZE * 5]; + tmp2 = (INT32) dataptr[DCTSIZE * 3]; + tmp3 = (INT32) dataptr[DCTSIZE * 1]; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; z3 = tmp0 + tmp2; z4 = tmp1 + tmp3; - z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ - - tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ - tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ - tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ - tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ - z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ - z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ - z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ - z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ - + z5 = MULTIPLY (z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp0 = MULTIPLY (tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp1 = MULTIPLY (tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp2 = MULTIPLY (tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp3 = MULTIPLY (tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY (z1, -FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY (z2, -FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY (z3, -FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY (z4, -FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + z3 += z5; z4 += z5; - + tmp0 += z1 + z3; tmp1 += z2 + z4; tmp2 += z2 + z3; @@ -373,23 +358,23 @@ gst_idct_int_idct (DCTBLOCK data) /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3, - CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3, - CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2, - CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2, - CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1, - CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1, - CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0, - CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0, - CONST_BITS+PASS1_BITS+3); - + dataptr[DCTSIZE * 0] = (DCTELEM) DESCALE (tmp10 + tmp3, + CONST_BITS + PASS1_BITS + 3); + dataptr[DCTSIZE * 7] = (DCTELEM) DESCALE (tmp10 - tmp3, + CONST_BITS + PASS1_BITS + 3); + dataptr[DCTSIZE * 1] = (DCTELEM) DESCALE (tmp11 + tmp2, + CONST_BITS + PASS1_BITS + 3); + dataptr[DCTSIZE * 6] = (DCTELEM) DESCALE (tmp11 - tmp2, + CONST_BITS + PASS1_BITS + 3); + dataptr[DCTSIZE * 2] = (DCTELEM) DESCALE (tmp12 + tmp1, + CONST_BITS + PASS1_BITS + 3); + dataptr[DCTSIZE * 5] = (DCTELEM) DESCALE (tmp12 - tmp1, + CONST_BITS + PASS1_BITS + 3); + dataptr[DCTSIZE * 3] = (DCTELEM) DESCALE (tmp13 + tmp0, + CONST_BITS + PASS1_BITS + 3); + dataptr[DCTSIZE * 4] = (DCTELEM) DESCALE (tmp13 - tmp0, + CONST_BITS + PASS1_BITS + 3); + dataptr++; /* advance pointer to next column */ } } diff --git a/gst-libs/gst/idct/mmx32idct.c b/gst-libs/gst/idct/mmx32idct.c index 3b640976ef..cd191f0c6d 100644 --- a/gst-libs/gst/idct/mmx32idct.c +++ b/gst-libs/gst/idct/mmx32idct.c @@ -19,9 +19,8 @@ * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * - */ - - + */ + /* MMX32 iDCT algorithm (IEEE-1180 compliant) :: idct_mmx32() */ /* */ /* MPEG2AVI */ @@ -102,8 +101,7 @@ /* */ /* liaor@umcc.ais.org http://members.tripod.com/~liaor */ /* */ - - + /*;============================================================================= */ /*; */ /*; AP-922 http://developer.intel.com/vtune/cbts/strmsimd */ @@ -113,68 +111,67 @@ /*;============================================================================= */ /* mword typedef qword -qword ptr equ mword ptr */ - +qword ptr equ mword ptr */ #ifdef HAVE_CONFIG_H #include "config.h" #endif - #include - + #define BITS_INV_ACC 4 /*; 4 or 5 for IEEE */ - /* 5 yields higher accuracy, but lessens dynamic range on the input matrix */ + /* 5 yields higher accuracy, but lessens dynamic range on the input matrix */ #define SHIFT_INV_ROW (16 - BITS_INV_ACC) -#define SHIFT_INV_COL (1 + BITS_INV_ACC +14 ) /* changed from Intel's val) */ +#define SHIFT_INV_COL (1 + BITS_INV_ACC +14 ) /* changed from Intel's val) */ /*#define SHIFT_INV_COL (1 + BITS_INV_ACC ) */ - + #define RND_INV_ROW (1 << (SHIFT_INV_ROW-1)) #define RND_INV_COL (1 << (SHIFT_INV_COL-1)) -#define RND_INV_CORR (RND_INV_COL - 1) /*; correction -1.0 and round */ +#define RND_INV_CORR (RND_INV_COL - 1) /*; correction -1.0 and round */ /*#define RND_INV_ROW (1024 * (6 - BITS_INV_ACC)) //; 1 << (SHIFT_INV_ROW-1) */ /*#define RND_INV_COL (16 * (BITS_INV_ACC - 3)) //; 1 << (SHIFT_INV_COL-1) */ - - + /*.data */ /*Align 16 */ -const static long r_inv_row[2] = { RND_INV_ROW, RND_INV_ROW}; -const static long r_inv_col[2] = {RND_INV_COL, RND_INV_COL}; -const static long r_inv_corr[2] = {RND_INV_CORR, RND_INV_CORR }; - +const static long r_inv_row[2] = { RND_INV_ROW, RND_INV_ROW }; + const static long r_inv_col[2] = { RND_INV_COL, RND_INV_COL }; + const static long r_inv_corr[2] = { RND_INV_CORR, RND_INV_CORR }; + + /*const static short r_inv_col[4] = */ /* {RND_INV_COL, RND_INV_COL, RND_INV_COL, RND_INV_COL}; */ /*const static short r_inv_corr[4] = */ /* {RND_INV_CORR, RND_INV_CORR, RND_INV_CORR, RND_INV_CORR}; */ - + /* constants for the forward DCT /*#define BITS_FRW_ACC 3 //; 2 or 3 for accuracy */ /*#define SHIFT_FRW_COL BITS_FRW_ACC */ /*#define SHIFT_FRW_ROW (BITS_FRW_ACC + 17) */ /*#define RND_FRW_ROW (262144 * (BITS_FRW_ACC - 1)) //; 1 << (SHIFT_FRW_ROW-1) */ - -const static __int64 one_corr = 0x0001000100010001; -const static long r_frw_row[2] = {RND_FRW_ROW, RND_FRW_ROW }; - + const static __int64 one_corr = 0x0001000100010001; + const static long r_frw_row[2] = { RND_FRW_ROW, RND_FRW_ROW }; + + /*const static short tg_1_16[4] = {13036, 13036, 13036, 13036 }; //tg * (2<<16) + 0.5 */ /*const static short tg_2_16[4] = {27146, 27146, 27146, 27146 }; //tg * (2<<16) + 0.5 */ /*const static short tg_3_16[4] = {-21746, -21746, -21746, -21746 }; //tg * (2<<16) + 0.5 */ /*const static short cos_4_16[4] = {-19195, -19195, -19195, -19195 }; //cos * (2<<16) + 0.5 */ /*const static short ocos_4_16[4] = {23170, 23170, 23170, 23170 }; //cos * (2<<15) + 0.5 */ - + /*concatenated table, for forward DCT transformation */ -const static short tg_all_16[] = { - 13036, 13036, 13036, 13036, /* tg * (2<<16) + 0.5 */ - 27146, 27146, 27146, 27146, /*tg * (2<<16) + 0.5 */ - -21746, -21746, -21746, -21746, /* tg * (2<<16) + 0.5 */ - -19195, -19195, -19195, -19195, /*cos * (2<<16) + 0.5 */ - 23170, 23170, 23170, 23170 }; /*cos * (2<<15) + 0.5 */ +const static short tg_all_16[] = { 13036, 13036, 13036, 13036, /* tg * (2<<16) + 0.5 */ + 27146, 27146, 27146, 27146, /*tg * (2<<16) + 0.5 */ + -21746, -21746, -21746, -21746, /* tg * (2<<16) + 0.5 */ + -19195, -19195, -19195, -19195, /*cos * (2<<16) + 0.5 */ + 23170, 23170, 23170, 23170 +}; /*cos * (2<<15) + 0.5 */ + #define tg_1_16 (tg_all_16 + 0) #define tg_2_16 (tg_all_16 + 8) #define tg_3_16 (tg_all_16 + 16) #define cos_4_16 (tg_all_16 + 24) #define ocos_4_16 (tg_all_16 + 32) -*/ + */ /* ;============================================================================= ; @@ -236,552 +233,456 @@ IF _MMX ; MMX code ;============================================================================= /*; Table for rows 0,4 - constants are multiplied by cos_4_16 */ -const short tab_i_04[] = { - 16384, 16384, 16384, -16384, /* ; movq-> w06 w04 w02 w00 */ - 21407, 8867, 8867, -21407, /* w07 w05 w03 w01 */ - 16384, -16384, 16384, 16384, /*; w14 w12 w10 w08 */ - -8867, 21407, -21407, -8867, /*; w15 w13 w11 w09 */ - 22725, 12873, 19266, -22725, /*; w22 w20 w18 w16 */ - 19266, 4520, -4520, -12873, /*; w23 w21 w19 w17 */ - 12873, 4520, 4520, 19266, /*; w30 w28 w26 w24 */ - -22725, 19266, -12873, -22725 };/*w31 w29 w27 w25 */ +const short tab_i_04[] = { 16384, 16384, 16384, -16384, /* ; movq-> w06 w04 w02 w00 */ + 21407, 8867, 8867, -21407, /* w07 w05 w03 w01 */ + 16384, -16384, 16384, 16384, /*; w14 w12 w10 w08 */ + -8867, 21407, -21407, -8867, /*; w15 w13 w11 w09 */ + 22725, 12873, 19266, -22725, /*; w22 w20 w18 w16 */ + 19266, 4520, -4520, -12873, /*; w23 w21 w19 w17 */ + 12873, 4520, 4520, 19266, /*; w30 w28 w26 w24 */ + -22725, 19266, -12873, -22725 +}; /*w31 w29 w27 w25 */ + /*; Table for rows 1,7 - constants are multiplied by cos_1_16 */ -const short tab_i_17[] = { - 22725, 22725, 22725, -22725, /* ; movq-> w06 w04 w02 w00 */ - 29692, 12299, 12299, -29692, /* ; w07 w05 w03 w01 */ - 22725, -22725, 22725, 22725, /*; w14 w12 w10 w08 */ - -12299, 29692, -29692, -12299, /*; w15 w13 w11 w09 */ - 31521, 17855, 26722, -31521, /*; w22 w20 w18 w16 */ - 26722, 6270, -6270, -17855, /*; w23 w21 w19 w17 */ - 17855, 6270, 6270, 26722, /*; w30 w28 w26 w24 */ - -31521, 26722, -17855, -31521}; /* w31 w29 w27 w25 */ +const short tab_i_17[] = { 22725, 22725, 22725, -22725, /* ; movq-> w06 w04 w02 w00 */ + 29692, 12299, 12299, -29692, /* ; w07 w05 w03 w01 */ + 22725, -22725, 22725, 22725, /*; w14 w12 w10 w08 */ + -12299, 29692, -29692, -12299, /*; w15 w13 w11 w09 */ + 31521, 17855, 26722, -31521, /*; w22 w20 w18 w16 */ + 26722, 6270, -6270, -17855, /*; w23 w21 w19 w17 */ + 17855, 6270, 6270, 26722, /*; w30 w28 w26 w24 */ + -31521, 26722, -17855, -31521 +}; /* w31 w29 w27 w25 */ + /*; Table for rows 2,6 - constants are multiplied by cos_2_16 */ -const short tab_i_26[] = { - 21407, 21407, 21407, -21407, /* ; movq-> w06 w04 w02 w00 */ - 27969, 11585, 11585, -27969, /* ; w07 w05 w03 w01 */ - 21407, -21407, 21407, 21407, /* ; w14 w12 w10 w08 */ - -11585, 27969, -27969, -11585, /* ;w15 w13 w11 w09 */ - 29692, 16819, 25172, -29692, /* ;w22 w20 w18 w16 */ - 25172, 5906, -5906, -16819, /* ;w23 w21 w19 w17 */ - 16819, 5906, 5906, 25172, /* ;w30 w28 w26 w24 */ - -29692, 25172, -16819, -29692}; /* ;w31 w29 w27 w25 */ - - +const short tab_i_26[] = { 21407, 21407, 21407, -21407, /* ; movq-> w06 w04 w02 w00 */ + 27969, 11585, 11585, -27969, /* ; w07 w05 w03 w01 */ + 21407, -21407, 21407, 21407, /* ; w14 w12 w10 w08 */ + -11585, 27969, -27969, -11585, /* ;w15 w13 w11 w09 */ + 29692, 16819, 25172, -29692, /* ;w22 w20 w18 w16 */ + 25172, 5906, -5906, -16819, /* ;w23 w21 w19 w17 */ + 16819, 5906, 5906, 25172, /* ;w30 w28 w26 w24 */ + -29692, 25172, -16819, -29692 +}; /* ;w31 w29 w27 w25 */ + + /*; Table for rows 3,5 - constants are multiplied by cos_3_16 */ -const short tab_i_35[] = { - 19266, 19266, 19266, -19266, /*; movq-> w06 w04 w02 w00 */ - 25172, 10426, 10426, -25172, /*; w07 w05 w03 w01 */ - 19266, -19266, 19266, 19266, /*; w14 w12 w10 w08 */ - -10426, 25172, -25172, -10426, /*; w15 w13 w11 w09 */ - 26722, 15137, 22654, -26722, /*; w22 w20 w18 w16 */ - 22654, 5315, -5315, -15137, /*; w23 w21 w19 w17 */ - 15137, 5315, 5315, 22654, /*; w30 w28 w26 w24 */ - -26722, 22654, -15137, -26722}; /*; w31 w29 w27 w25 */ -*/ - +const short tab_i_35[] = { 19266, 19266, 19266, -19266, /*; movq-> w06 w04 w02 w00 */ + 25172, 10426, 10426, -25172, /*; w07 w05 w03 w01 */ + 19266, -19266, 19266, 19266, /*; w14 w12 w10 w08 */ + -10426, 25172, -25172, -10426, /*; w15 w13 w11 w09 */ + 26722, 15137, 22654, -26722, /*; w22 w20 w18 w16 */ + 22654, 5315, -5315, -15137, /*; w23 w21 w19 w17 */ + 15137, 5315, 5315, 22654, /*; w30 w28 w26 w24 */ + -26722, 22654, -15137, -26722 +}; /*; w31 w29 w27 w25 */ + +*/ /* CONCATENATED TABLE, rows 0,1,2,3,4,5,6,7 (in order ) */ /* */ /* In our implementation, however, we only use row0 ! */ /* */ -static const short tab_i_01234567[] = { - /*row0, this row is required */ - 16384, 16384, 16384, -16384, /* ; movq-> w06 w04 w02 w00 */ - 21407, 8867, 8867, -21407, /* w07 w05 w03 w01 */ - 16384, -16384, 16384, 16384, /*; w14 w12 w10 w08 */ - -8867, 21407, -21407, -8867, /*; w15 w13 w11 w09 */ - 22725, 12873, 19266, -22725, /*; w22 w20 w18 w16 */ - 19266, 4520, -4520, -12873, /*; w23 w21 w19 w17 */ - 12873, 4520, 4520, 19266, /*; w30 w28 w26 w24 */ - -22725, 19266, -12873, -22725, /*w31 w29 w27 w25 */ - - /* the rest of these rows (1-7), aren't used ! */ - - /*row1 */ - 22725, 22725, 22725, -22725, /* ; movq-> w06 w04 w02 w00 */ - 29692, 12299, 12299, -29692, /* ; w07 w05 w03 w01 */ - 22725, -22725, 22725, 22725, /*; w14 w12 w10 w08 */ - -12299, 29692, -29692, -12299, /*; w15 w13 w11 w09 */ - 31521, 17855, 26722, -31521, /*; w22 w20 w18 w16 */ - 26722, 6270, -6270, -17855, /*; w23 w21 w19 w17 */ - 17855, 6270, 6270, 26722, /*; w30 w28 w26 w24 */ - -31521, 26722, -17855, -31521, /* w31 w29 w27 w25 */ - - /*row2 */ - 21407, 21407, 21407, -21407, /* ; movq-> w06 w04 w02 w00 */ - 27969, 11585, 11585, -27969, /* ; w07 w05 w03 w01 */ - 21407, -21407, 21407, 21407, /* ; w14 w12 w10 w08 */ - -11585, 27969, -27969, -11585, /* ;w15 w13 w11 w09 */ - 29692, 16819, 25172, -29692, /* ;w22 w20 w18 w16 */ - 25172, 5906, -5906, -16819, /* ;w23 w21 w19 w17 */ - 16819, 5906, 5906, 25172, /* ;w30 w28 w26 w24 */ - -29692, 25172, -16819, -29692, /* ;w31 w29 w27 w25 */ - - /*row3 */ - 19266, 19266, 19266, -19266, /*; movq-> w06 w04 w02 w00 */ - 25172, 10426, 10426, -25172, /*; w07 w05 w03 w01 */ - 19266, -19266, 19266, 19266, /*; w14 w12 w10 w08 */ - -10426, 25172, -25172, -10426, /*; w15 w13 w11 w09 */ - 26722, 15137, 22654, -26722, /*; w22 w20 w18 w16 */ - 22654, 5315, -5315, -15137, /*; w23 w21 w19 w17 */ - 15137, 5315, 5315, 22654, /*; w30 w28 w26 w24 */ - -26722, 22654, -15137, -26722, /*; w31 w29 w27 w25 */ - - /*row4 */ - 16384, 16384, 16384, -16384, /* ; movq-> w06 w04 w02 w00 */ - 21407, 8867, 8867, -21407, /* w07 w05 w03 w01 */ - 16384, -16384, 16384, 16384, /*; w14 w12 w10 w08 */ - -8867, 21407, -21407, -8867, /*; w15 w13 w11 w09 */ - 22725, 12873, 19266, -22725, /*; w22 w20 w18 w16 */ - 19266, 4520, -4520, -12873, /*; w23 w21 w19 w17 */ - 12873, 4520, 4520, 19266, /*; w30 w28 w26 w24 */ - -22725, 19266, -12873, -22725, /*w31 w29 w27 w25 */ - - /*row5 */ - 19266, 19266, 19266, -19266, /*; movq-> w06 w04 w02 w00 */ - 25172, 10426, 10426, -25172, /*; w07 w05 w03 w01 */ - 19266, -19266, 19266, 19266, /*; w14 w12 w10 w08 */ - -10426, 25172, -25172, -10426, /*; w15 w13 w11 w09 */ - 26722, 15137, 22654, -26722, /*; w22 w20 w18 w16 */ - 22654, 5315, -5315, -15137, /*; w23 w21 w19 w17 */ - 15137, 5315, 5315, 22654, /*; w30 w28 w26 w24 */ - -26722, 22654, -15137, -26722, /*; w31 w29 w27 w25 */ - - /*row6 */ - 21407, 21407, 21407, -21407, /* ; movq-> w06 w04 w02 w00 */ - 27969, 11585, 11585, -27969, /* ; w07 w05 w03 w01 */ - 21407, -21407, 21407, 21407, /* ; w14 w12 w10 w08 */ - -11585, 27969, -27969, -11585, /* ;w15 w13 w11 w09 */ - 29692, 16819, 25172, -29692, /* ;w22 w20 w18 w16 */ - 25172, 5906, -5906, -16819, /* ;w23 w21 w19 w17 */ - 16819, 5906, 5906, 25172, /* ;w30 w28 w26 w24 */ - -29692, 25172, -16819, -29692, /* ;w31 w29 w27 w25 */ - - /*row7 */ - 22725, 22725, 22725, -22725, /* ; movq-> w06 w04 w02 w00 */ - 29692, 12299, 12299, -29692, /* ; w07 w05 w03 w01 */ - 22725, -22725, 22725, 22725, /*; w14 w12 w10 w08 */ - -12299, 29692, -29692, -12299, /*; w15 w13 w11 w09 */ - 31521, 17855, 26722, -31521, /*; w22 w20 w18 w16 */ - 26722, 6270, -6270, -17855, /*; w23 w21 w19 w17 */ - 17855, 6270, 6270, 26722, /*; w30 w28 w26 w24 */ - -31521, 26722, -17855, -31521}; /* w31 w29 w27 w25 */ - - -#define INP eax /* pointer to (short *blk) */ -#define OUT ecx /* pointer to output (temporary store space qwTemp[]) */ -#define TABLE ebx /* pointer to tab_i_01234567[] */ +static const short tab_i_01234567[] = { + /*row0, this row is required */ + 16384, 16384, 16384, -16384, /* ; movq-> w06 w04 w02 w00 */ + 21407, 8867, 8867, -21407, /* w07 w05 w03 w01 */ + 16384, -16384, 16384, 16384, /*; w14 w12 w10 w08 */ + -8867, 21407, -21407, -8867, /*; w15 w13 w11 w09 */ + 22725, 12873, 19266, -22725, /*; w22 w20 w18 w16 */ + 19266, 4520, -4520, -12873, /*; w23 w21 w19 w17 */ + 12873, 4520, 4520, 19266, /*; w30 w28 w26 w24 */ + -22725, 19266, -12873, -22725, /*w31 w29 w27 w25 */ + + /* the rest of these rows (1-7), aren't used ! */ + + /*row1 */ + 22725, 22725, 22725, -22725, /* ; movq-> w06 w04 w02 w00 */ + 29692, 12299, 12299, -29692, /* ; w07 w05 w03 w01 */ + 22725, -22725, 22725, 22725, /*; w14 w12 w10 w08 */ + -12299, 29692, -29692, -12299, /*; w15 w13 w11 w09 */ + 31521, 17855, 26722, -31521, /*; w22 w20 w18 w16 */ + 26722, 6270, -6270, -17855, /*; w23 w21 w19 w17 */ + 17855, 6270, 6270, 26722, /*; w30 w28 w26 w24 */ + -31521, 26722, -17855, -31521, /* w31 w29 w27 w25 */ + + /*row2 */ + 21407, 21407, 21407, -21407, /* ; movq-> w06 w04 w02 w00 */ + 27969, 11585, 11585, -27969, /* ; w07 w05 w03 w01 */ + 21407, -21407, 21407, 21407, /* ; w14 w12 w10 w08 */ + -11585, 27969, -27969, -11585, /* ;w15 w13 w11 w09 */ + 29692, 16819, 25172, -29692, /* ;w22 w20 w18 w16 */ + 25172, 5906, -5906, -16819, /* ;w23 w21 w19 w17 */ + 16819, 5906, 5906, 25172, /* ;w30 w28 w26 w24 */ + -29692, 25172, -16819, -29692, /* ;w31 w29 w27 w25 */ + + /*row3 */ + 19266, 19266, 19266, -19266, /*; movq-> w06 w04 w02 w00 */ + 25172, 10426, 10426, -25172, /*; w07 w05 w03 w01 */ + 19266, -19266, 19266, 19266, /*; w14 w12 w10 w08 */ + -10426, 25172, -25172, -10426, /*; w15 w13 w11 w09 */ + 26722, 15137, 22654, -26722, /*; w22 w20 w18 w16 */ + 22654, 5315, -5315, -15137, /*; w23 w21 w19 w17 */ + 15137, 5315, 5315, 22654, /*; w30 w28 w26 w24 */ + -26722, 22654, -15137, -26722, /*; w31 w29 w27 w25 */ + + /*row4 */ + 16384, 16384, 16384, -16384, /* ; movq-> w06 w04 w02 w00 */ + 21407, 8867, 8867, -21407, /* w07 w05 w03 w01 */ + 16384, -16384, 16384, 16384, /*; w14 w12 w10 w08 */ + -8867, 21407, -21407, -8867, /*; w15 w13 w11 w09 */ + 22725, 12873, 19266, -22725, /*; w22 w20 w18 w16 */ + 19266, 4520, -4520, -12873, /*; w23 w21 w19 w17 */ + 12873, 4520, 4520, 19266, /*; w30 w28 w26 w24 */ + -22725, 19266, -12873, -22725, /*w31 w29 w27 w25 */ + + /*row5 */ + 19266, 19266, 19266, -19266, /*; movq-> w06 w04 w02 w00 */ + 25172, 10426, 10426, -25172, /*; w07 w05 w03 w01 */ + 19266, -19266, 19266, 19266, /*; w14 w12 w10 w08 */ + -10426, 25172, -25172, -10426, /*; w15 w13 w11 w09 */ + 26722, 15137, 22654, -26722, /*; w22 w20 w18 w16 */ + 22654, 5315, -5315, -15137, /*; w23 w21 w19 w17 */ + 15137, 5315, 5315, 22654, /*; w30 w28 w26 w24 */ + -26722, 22654, -15137, -26722, /*; w31 w29 w27 w25 */ + + /*row6 */ + 21407, 21407, 21407, -21407, /* ; movq-> w06 w04 w02 w00 */ + 27969, 11585, 11585, -27969, /* ; w07 w05 w03 w01 */ + 21407, -21407, 21407, 21407, /* ; w14 w12 w10 w08 */ + -11585, 27969, -27969, -11585, /* ;w15 w13 w11 w09 */ + 29692, 16819, 25172, -29692, /* ;w22 w20 w18 w16 */ + 25172, 5906, -5906, -16819, /* ;w23 w21 w19 w17 */ + 16819, 5906, 5906, 25172, /* ;w30 w28 w26 w24 */ + -29692, 25172, -16819, -29692, /* ;w31 w29 w27 w25 */ + + /*row7 */ + 22725, 22725, 22725, -22725, /* ; movq-> w06 w04 w02 w00 */ + 29692, 12299, 12299, -29692, /* ; w07 w05 w03 w01 */ + 22725, -22725, 22725, 22725, /*; w14 w12 w10 w08 */ + -12299, 29692, -29692, -12299, /*; w15 w13 w11 w09 */ + 31521, 17855, 26722, -31521, /*; w22 w20 w18 w16 */ + 26722, 6270, -6270, -17855, /*; w23 w21 w19 w17 */ + 17855, 6270, 6270, 26722, /*; w30 w28 w26 w24 */ + -31521, 26722, -17855, -31521 +}; /* w31 w29 w27 w25 */ + + +#define INP eax /* pointer to (short *blk) */ +#define OUT ecx /* pointer to output (temporary store space qwTemp[]) */ +#define TABLE ebx /* pointer to tab_i_01234567[] */ #define round_inv_row edx #define round_inv_col edx - -#define ROW_STRIDE 8 /* for 8x8 matrix transposer */ - + +#define ROW_STRIDE 8 /* for 8x8 matrix transposer */ + /* private variables and functions */ - + /*temporary storage space, 8x8 of shorts */ - -__inline static void idct_mmx32_rows( short *blk ); /* transform rows */ -__inline static void idct_mmx32_cols( short *blk ); /* transform "columns" */ + __inline static void idct_mmx32_rows (short *blk); /* transform rows */ +__inline static void idct_mmx32_cols (short *blk); /* transform "columns" */ + /* the "column" transform actually transforms rows, it is */ /* identical to the row-transform except for the ROUNDING */ /* and SHIFTING coefficients. */ - - -static void -idct_mmx32_rows( short *blk ) /* transform all 8 rows of 8x8 iDCT block */ -{ - int x; - short qwTemp[64]; - short *out = &qwTemp[0]; - short *inptr = blk; - /* this subroutine performs two operations */ - /* 1) iDCT row transform */ - /* for( i = 0; i < 8; ++ i) */ - /* DCT_8_INV_ROW_1( blk[i*8], qwTemp[i] ); */ - /* */ - /* 2) transpose the matrix (which was stored in qwTemp[]) */ - /* qwTemp[] -> [8x8 matrix transpose] -> blk[] */ - - for (x=0; x<8; x++) { /* transform one row per iteration */ - movq_m2r(*(inptr), mm0); /* 0 ; x3 x2 x1 x0 */ - - movq_m2r(*(inptr+4), mm1); /* 1 ; x7 x6 x5 x4 */ - movq_r2r(mm0, mm2); /* 2 ; x3 x2 x1 x0 */ - - movq_m2r(*(tab_i_01234567), mm3); /* 3 ; w06 w04 w02 w00 */ - punpcklwd_r2r(mm1, mm0); /* x5 x1 x4 x0 */ - - /* ---------- */ - movq_r2r(mm0, mm5); /* 5 ; x5 x1 x4 x0 */ - punpckldq_r2r(mm0, mm0); /* x4 x0 x4 x0 */ - - movq_m2r(*(tab_i_01234567+4), mm4); /* 4 ; w07 w05 w03 w01 */ - punpckhwd_r2r(mm1, mm2); /* 1 ; x7 x3 x6 x2 */ - - pmaddwd_r2r(mm0, mm3); /* x4*w06+x0*w04 x4*w02+x0*w00 */ - movq_r2r(mm2, mm6); /* 6 ; x7 x3 x6 x2 */ - - movq_m2r(*(tab_i_01234567+16), mm1);/* 1 ; w22 w20 w18 w16 */ - punpckldq_r2r(mm2, mm2); /* x6 x2 x6 x2 */ - - pmaddwd_r2r(mm2, mm4); /* x6*w07+x2*w05 x6*w03+x2*w01 */ - punpckhdq_r2r(mm5, mm5); /* x5 x1 x5 x1 */ - - pmaddwd_m2r(*(tab_i_01234567+8), mm0);/* x4*w14+x0*w12 x4*w10+x0*w08 */ - punpckhdq_r2r(mm6, mm6); /* x7 x3 x7 x3 */ - - movq_m2r(*(tab_i_01234567+20), mm7);/* 7 ; w23 w21 w19 w17 */ - pmaddwd_r2r(mm5, mm1); /* x5*w22+x1*w20 x5*w18+x1*w16 */ - - paddd_m2r(*(r_inv_row), mm3);/* +rounder */ - pmaddwd_r2r(mm6, mm7); /* x7*w23+x3*w21 x7*w19+x3*w17 */ - - pmaddwd_m2r(*(tab_i_01234567+12), mm2);/* x6*w15+x2*w13 x6*w11+x2*w09 */ - paddd_r2r(mm4, mm3); /* 4 ; a1=sum(even1) a0=sum(even0) */ - - pmaddwd_m2r(*(tab_i_01234567+24), mm5);/* x5*w30+x1*w28 x5*w26+x1*w24 */ - movq_r2r(mm3, mm4); /* 4 ; a1 a0 */ - - pmaddwd_m2r(*(tab_i_01234567+28), mm6);/* x7*w31+x3*w29 x7*w27+x3*w25 */ - paddd_r2r(mm7, mm1); /* 7 ; b1=sum(odd1) b0=sum(odd0) */ - - paddd_m2r(*(r_inv_row), mm0);/* +rounder */ - psubd_r2r(mm1, mm3); /* a1-b1 a0-b0 */ - - psrad_i2r(SHIFT_INV_ROW, mm3); /* y6=a1-b1 y7=a0-b0 */ - paddd_r2r(mm4, mm1); /* 4 ; a1+b1 a0+b0 */ - - paddd_r2r(mm2, mm0); /* 2 ; a3=sum(even3) a2=sum(even2) */ - psrad_i2r(SHIFT_INV_ROW, mm1); /* y1=a1+b1 y0=a0+b0 */ - - paddd_r2r(mm6, mm5); /* 6 ; b3=sum(odd3) b2=sum(odd2) */ - movq_r2r(mm0, mm4); /* 4 ; a3 a2 */ - - paddd_r2r(mm5, mm0); /* a3+b3 a2+b2 */ - psubd_r2r(mm5, mm4); /* 5 ; a3-b3 a2-b2 */ - - psrad_i2r(SHIFT_INV_ROW, mm4); /* y4=a3-b3 y5=a2-b2 */ - psrad_i2r(SHIFT_INV_ROW, mm0); /* y3=a3+b3 y2=a2+b2 */ - - packssdw_r2r(mm3, mm4); /* 3 ; y6 y7 y4 y5 */ - - packssdw_r2r(mm0, mm1); /* 0 ; y3 y2 y1 y0 */ - movq_r2r(mm4, mm7); /* 7 ; y6 y7 y4 y5 */ - - psrld_i2r(16, mm4); /* 0 y6 0 y4 */ - - movq_r2m(mm1, *(out)); /* 1 ; save y3 y2 y1 y0 */ - pslld_i2r(16, mm7); /* y7 0 y5 0 */ - - por_r2r(mm4, mm7); /* 4 ; y7 y6 y5 y4 */ - - /* begin processing row 1 */ - movq_r2m(mm7, *(out+4)); /* 7 ; save y7 y6 y5 y4 */ - - inptr += 8; - out += 8; - } - - - /* done with the iDCT row-transformation */ - - /* now we have to transpose the output 8x8 matrix */ - /* 8x8 (OUT) -> 8x8't' (IN) */ - /* the transposition is implemented as 4 sub-operations. */ - /* 1) transpose upper-left quad */ - /* 2) transpose lower-right quad */ - /* 3) transpose lower-left quad */ - /* 4) transpose upper-right quad */ - - - /* mm0 = 1st row [ A B C D ] row1 */ - /* mm1 = 2nd row [ E F G H ] 2 */ - /* mm2 = 3rd row [ I J K L ] 3 */ - /* mm3 = 4th row [ M N O P ] 4 */ - - /* 1) transpose upper-left quad */ - out = &qwTemp[0]; - - movq_m2r(*(out + ROW_STRIDE * 0), mm0); - - movq_m2r(*(out + ROW_STRIDE * 1), mm1); - movq_r2r(mm0, mm4); /* mm4 = copy of row1[A B C D] */ - - movq_m2r(*(out + ROW_STRIDE * 2), mm2); - punpcklwd_r2r(mm1, mm0); /* mm0 = [ 0 4 1 5] */ - - movq_m2r(*(out + ROW_STRIDE * 3), mm3); - punpckhwd_r2r(mm1, mm4); /* mm4 = [ 2 6 3 7] */ - - movq_r2r(mm2, mm6); - punpcklwd_r2r(mm3, mm2); /* mm2 = [ 8 12 9 13] */ - - punpckhwd_r2r(mm3, mm6); /* mm6 = 10 14 11 15] */ - movq_r2r(mm0, mm1); /* mm1 = [ 0 4 1 5] */ - - inptr = blk; - - punpckldq_r2r(mm2, mm0); /* final result mm0 = row1 [0 4 8 12] */ - - movq_r2r(mm4, mm3); /* mm3 = [ 2 6 3 7] */ - punpckhdq_r2r(mm2, mm1); /* mm1 = final result mm1 = row2 [1 5 9 13] */ - - movq_r2m(mm0, *(inptr + ROW_STRIDE * 0)); /* store row 1 */ - punpckldq_r2r(mm6, mm4); /* final result mm4 = row3 [2 6 10 14] */ - + static void +idct_mmx32_rows (short *blk) +{ /* transform all 8 rows of 8x8 iDCT block */ + int x; + short qwTemp[64]; + short *out = &qwTemp[0]; + short *inptr = blk; + + + /* this subroutine performs two operations */ + /* 1) iDCT row transform */ + /* for( i = 0; i < 8; ++ i) */ + /* DCT_8_INV_ROW_1( blk[i*8], qwTemp[i] ); */ + /* */ + /* 2) transpose the matrix (which was stored in qwTemp[]) */ + /* qwTemp[] -> [8x8 matrix transpose] -> blk[] */ + for (x = 0; x < 8; x++) { /* transform one row per iteration */ + movq_m2r (*(inptr), mm0); /* 0 ; x3 x2 x1 x0 */ + movq_m2r (*(inptr + 4), mm1); /* 1 ; x7 x6 x5 x4 */ + movq_r2r (mm0, mm2); /* 2 ; x3 x2 x1 x0 */ + movq_m2r (*(tab_i_01234567), mm3); /* 3 ; w06 w04 w02 w00 */ + punpcklwd_r2r (mm1, mm0); /* x5 x1 x4 x0 */ + + /* ---------- */ + movq_r2r (mm0, mm5); /* 5 ; x5 x1 x4 x0 */ + punpckldq_r2r (mm0, mm0); /* x4 x0 x4 x0 */ + movq_m2r (*(tab_i_01234567 + 4), mm4); /* 4 ; w07 w05 w03 w01 */ + punpckhwd_r2r (mm1, mm2); /* 1 ; x7 x3 x6 x2 */ + pmaddwd_r2r (mm0, mm3); /* x4*w06+x0*w04 x4*w02+x0*w00 */ + movq_r2r (mm2, mm6); /* 6 ; x7 x3 x6 x2 */ + movq_m2r (*(tab_i_01234567 + 16), mm1); /* 1 ; w22 w20 w18 w16 */ + punpckldq_r2r (mm2, mm2); /* x6 x2 x6 x2 */ + pmaddwd_r2r (mm2, mm4); /* x6*w07+x2*w05 x6*w03+x2*w01 */ + punpckhdq_r2r (mm5, mm5); /* x5 x1 x5 x1 */ + pmaddwd_m2r (*(tab_i_01234567 + 8), mm0); /* x4*w14+x0*w12 x4*w10+x0*w08 */ + punpckhdq_r2r (mm6, mm6); /* x7 x3 x7 x3 */ + movq_m2r (*(tab_i_01234567 + 20), mm7); /* 7 ; w23 w21 w19 w17 */ + pmaddwd_r2r (mm5, mm1); /* x5*w22+x1*w20 x5*w18+x1*w16 */ + paddd_m2r (*(r_inv_row), mm3); /* +rounder */ + pmaddwd_r2r (mm6, mm7); /* x7*w23+x3*w21 x7*w19+x3*w17 */ + pmaddwd_m2r (*(tab_i_01234567 + 12), mm2); /* x6*w15+x2*w13 x6*w11+x2*w09 */ + paddd_r2r (mm4, mm3); /* 4 ; a1=sum(even1) a0=sum(even0) */ + pmaddwd_m2r (*(tab_i_01234567 + 24), mm5); /* x5*w30+x1*w28 x5*w26+x1*w24 */ + movq_r2r (mm3, mm4); /* 4 ; a1 a0 */ + pmaddwd_m2r (*(tab_i_01234567 + 28), mm6); /* x7*w31+x3*w29 x7*w27+x3*w25 */ + paddd_r2r (mm7, mm1); /* 7 ; b1=sum(odd1) b0=sum(odd0) */ + paddd_m2r (*(r_inv_row), mm0); /* +rounder */ + psubd_r2r (mm1, mm3); /* a1-b1 a0-b0 */ + psrad_i2r (SHIFT_INV_ROW, mm3); /* y6=a1-b1 y7=a0-b0 */ + paddd_r2r (mm4, mm1); /* 4 ; a1+b1 a0+b0 */ + paddd_r2r (mm2, mm0); /* 2 ; a3=sum(even3) a2=sum(even2) */ + psrad_i2r (SHIFT_INV_ROW, mm1); /* y1=a1+b1 y0=a0+b0 */ + paddd_r2r (mm6, mm5); /* 6 ; b3=sum(odd3) b2=sum(odd2) */ + movq_r2r (mm0, mm4); /* 4 ; a3 a2 */ + paddd_r2r (mm5, mm0); /* a3+b3 a2+b2 */ + psubd_r2r (mm5, mm4); /* 5 ; a3-b3 a2-b2 */ + psrad_i2r (SHIFT_INV_ROW, mm4); /* y4=a3-b3 y5=a2-b2 */ + psrad_i2r (SHIFT_INV_ROW, mm0); /* y3=a3+b3 y2=a2+b2 */ + packssdw_r2r (mm3, mm4); /* 3 ; y6 y7 y4 y5 */ + packssdw_r2r (mm0, mm1); /* 0 ; y3 y2 y1 y0 */ + movq_r2r (mm4, mm7); /* 7 ; y6 y7 y4 y5 */ + psrld_i2r (16, mm4); /* 0 y6 0 y4 */ + movq_r2m (mm1, *(out)); /* 1 ; save y3 y2 y1 y0 */ + pslld_i2r (16, mm7); /* y7 0 y5 0 */ + por_r2r (mm4, mm7); /* 4 ; y7 y6 y5 y4 */ + + /* begin processing row 1 */ + movq_r2m (mm7, *(out + 4)); /* 7 ; save y7 y6 y5 y4 */ + inptr += 8; + out += 8; + } + + /* done with the iDCT row-transformation */ + + /* now we have to transpose the output 8x8 matrix */ + /* 8x8 (OUT) -> 8x8't' (IN) */ + /* the transposition is implemented as 4 sub-operations. */ + /* 1) transpose upper-left quad */ + /* 2) transpose lower-right quad */ + /* 3) transpose lower-left quad */ + /* 4) transpose upper-right quad */ + + /* mm0 = 1st row [ A B C D ] row1 */ + /* mm1 = 2nd row [ E F G H ] 2 */ + /* mm2 = 3rd row [ I J K L ] 3 */ + /* mm3 = 4th row [ M N O P ] 4 */ + + /* 1) transpose upper-left quad */ + out = &qwTemp[0]; + movq_m2r (*(out + ROW_STRIDE * 0), mm0); + movq_m2r (*(out + ROW_STRIDE * 1), mm1); + movq_r2r (mm0, mm4); /* mm4 = copy of row1[A B C D] */ + movq_m2r (*(out + ROW_STRIDE * 2), mm2); + punpcklwd_r2r (mm1, mm0); /* mm0 = [ 0 4 1 5] */ + movq_m2r (*(out + ROW_STRIDE * 3), mm3); + punpckhwd_r2r (mm1, mm4); /* mm4 = [ 2 6 3 7] */ + movq_r2r (mm2, mm6); + punpcklwd_r2r (mm3, mm2); /* mm2 = [ 8 12 9 13] */ + punpckhwd_r2r (mm3, mm6); /* mm6 = 10 14 11 15] */ + movq_r2r (mm0, mm1); /* mm1 = [ 0 4 1 5] */ + inptr = blk; + punpckldq_r2r (mm2, mm0); /* final result mm0 = row1 [0 4 8 12] */ + movq_r2r (mm4, mm3); /* mm3 = [ 2 6 3 7] */ + punpckhdq_r2r (mm2, mm1); /* mm1 = final result mm1 = row2 [1 5 9 13] */ + movq_r2m (mm0, *(inptr + ROW_STRIDE * 0)); /* store row 1 */ + punpckldq_r2r (mm6, mm4); /* final result mm4 = row3 [2 6 10 14] */ + /* begin reading next quadrant (lower-right) */ - movq_m2r(*(out + ROW_STRIDE*4 + 4), mm0); - punpckhdq_r2r(mm6, mm3); /* final result mm3 = row4 [3 7 11 15] */ - - movq_r2m(mm4, *(inptr + ROW_STRIDE * 2)); /* store row 3 */ - movq_r2r(mm0, mm4); /* mm4 = copy of row1[A B C D] */ - - movq_r2m(mm1, *(inptr + ROW_STRIDE * 1)); /* store row 2 */ - - movq_m2r(*(out + ROW_STRIDE*5 + 4), mm1); - - movq_r2m(mm3, *(inptr + ROW_STRIDE * 3)); /* store row 4 */ - punpcklwd_r2r(mm1, mm0); /* mm0 = [ 0 4 1 5] */ - - /* 2) transpose lower-right quadrant */ - + movq_m2r (*(out + ROW_STRIDE * 4 + 4), mm0); + punpckhdq_r2r (mm6, mm3); /* final result mm3 = row4 [3 7 11 15] */ + movq_r2m (mm4, *(inptr + ROW_STRIDE * 2)); /* store row 3 */ + movq_r2r (mm0, mm4); /* mm4 = copy of row1[A B C D] */ + movq_r2m (mm1, *(inptr + ROW_STRIDE * 1)); /* store row 2 */ + movq_m2r (*(out + ROW_STRIDE * 5 + 4), mm1); + movq_r2m (mm3, *(inptr + ROW_STRIDE * 3)); /* store row 4 */ + punpcklwd_r2r (mm1, mm0); /* mm0 = [ 0 4 1 5] */ + + /* 2) transpose lower-right quadrant */ + /* movq mm0, qword ptr [OUT + ROW_STRIDE*4 + 8] */ - + /* movq mm1, qword ptr [OUT + ROW_STRIDE*5 + 8] */ /* movq mm4, mm0; // mm4 = copy of row1[A B C D] */ - - movq_m2r(*(out + ROW_STRIDE*6 + 4), mm2); + movq_m2r (*(out + ROW_STRIDE * 6 + 4), mm2); + /* punpcklwd mm0, mm1; // mm0 = [ 0 4 1 5] */ - punpckhwd_r2r(mm1, mm4); /* mm4 = [ 2 6 3 7] */ - - movq_m2r(*(out + ROW_STRIDE*7 + 4), mm3); - movq_r2r(mm2, mm6); - - punpcklwd_r2r(mm3, mm2); /* mm2 = [ 8 12 9 13] */ - movq_r2r(mm0, mm1); /* mm1 = [ 0 4 1 5] */ - - punpckhwd_r2r(mm3, mm6); /* mm6 = 10 14 11 15] */ - movq_r2r(mm4, mm3); /* mm3 = [ 2 6 3 7] */ - - punpckldq_r2r(mm2, mm0); /* final result mm0 = row1 [0 4 8 12] */ - - punpckhdq_r2r(mm2, mm1); /* mm1 = final result mm1 = row2 [1 5 9 13] */ - ; /* slot */ - - movq_r2m(mm0, *(inptr + ROW_STRIDE*4 + 4)); /* store row 1 */ - punpckldq_r2r(mm6, mm4); /* final result mm4 = row3 [2 6 10 14] */ - - movq_m2r(*(out + ROW_STRIDE * 4 ), mm0); - punpckhdq_r2r(mm6, mm3); /* final result mm3 = row4 [3 7 11 15] */ + punpckhwd_r2r (mm1, mm4); /* mm4 = [ 2 6 3 7] */ + movq_m2r (*(out + ROW_STRIDE * 7 + 4), mm3); + movq_r2r (mm2, mm6); + punpcklwd_r2r (mm3, mm2); /* mm2 = [ 8 12 9 13] */ + movq_r2r (mm0, mm1); /* mm1 = [ 0 4 1 5] */ + punpckhwd_r2r (mm3, mm6); /* mm6 = 10 14 11 15] */ + movq_r2r (mm4, mm3); /* mm3 = [ 2 6 3 7] */ + punpckldq_r2r (mm2, mm0); /* final result mm0 = row1 [0 4 8 12] */ + punpckhdq_r2r (mm2, mm1); /* mm1 = final result mm1 = row2 [1 5 9 13] */ + ; /* slot */ + movq_r2m (mm0, *(inptr + ROW_STRIDE * 4 + 4)); /* store row 1 */ + punpckldq_r2r (mm6, mm4); /* final result mm4 = row3 [2 6 10 14] */ + movq_m2r (*(out + ROW_STRIDE * 4), mm0); + punpckhdq_r2r (mm6, mm3); /* final result mm3 = row4 [3 7 11 15] */ + movq_r2m (mm4, *(inptr + ROW_STRIDE * 6 + 4)); /* store row 3 */ + movq_r2r (mm0, mm4); /* mm4 = copy of row1[A B C D] */ + movq_r2m (mm1, *(inptr + ROW_STRIDE * 5 + 4)); /* store row 2 */ + ; /* slot */ + movq_m2r (*(out + ROW_STRIDE * 5), mm1); + ; /* slot */ + movq_r2m (mm3, *(inptr + ROW_STRIDE * 7 + 4)); /* store row 4 */ + punpcklwd_r2r (mm1, mm0); /* mm0 = [ 0 4 1 5] */ - movq_r2m(mm4, *(inptr + ROW_STRIDE*6 + 4)); /* store row 3 */ - movq_r2r(mm0, mm4); /* mm4 = copy of row1[A B C D] */ - - movq_r2m(mm1, *(inptr + ROW_STRIDE*5 + 4)); /* store row 2 */ - ; /* slot */ - - movq_m2r(*(out + ROW_STRIDE * 5 ), mm1); - ; /* slot */ - - movq_r2m(mm3, *(inptr + ROW_STRIDE*7 + 4)); /* store row 4 */ - punpcklwd_r2r(mm1, mm0); /* mm0 = [ 0 4 1 5] */ - - /* 3) transpose lower-left */ + /* 3) transpose lower-left */ /* movq mm0, qword ptr [OUT + ROW_STRIDE * 4 ] */ - + /* movq mm1, qword ptr [OUT + ROW_STRIDE * 5 ] */ /* movq mm4, mm0; // mm4 = copy of row1[A B C D] */ - - movq_m2r(*(out + ROW_STRIDE * 6 ), mm2); + movq_m2r (*(out + ROW_STRIDE * 6), mm2); + /* punpcklwd mm0, mm1; // mm0 = [ 0 4 1 5] */ - punpckhwd_r2r(mm1, mm4); /* mm4 = [ 2 6 3 7] */ - - movq_m2r(*(out + ROW_STRIDE * 7 ), mm3); - movq_r2r(mm2, mm6); - - punpcklwd_r2r(mm3, mm2); /* mm2 = [ 8 12 9 13] */ - movq_r2r(mm0, mm1); /* mm1 = [ 0 4 1 5] */ - - punpckhwd_r2r(mm3, mm6); /* mm6 = 10 14 11 15] */ - movq_r2r(mm4, mm3); /* mm3 = [ 2 6 3 7] */ - - punpckldq_r2r(mm2, mm0); /* final result mm0 = row1 [0 4 8 12] */ - - punpckhdq_r2r(mm2, mm1); /* mm1 = final result mm1 = row2 [1 5 9 13] */ - ;/*slot */ - - movq_r2m(mm0, *(inptr + ROW_STRIDE * 0 + 4 )); /* store row 1 */ - punpckldq_r2r(mm6, mm4); /* final result mm4 = row3 [2 6 10 14] */ - + punpckhwd_r2r (mm1, mm4); /* mm4 = [ 2 6 3 7] */ + movq_m2r (*(out + ROW_STRIDE * 7), mm3); + movq_r2r (mm2, mm6); + punpcklwd_r2r (mm3, mm2); /* mm2 = [ 8 12 9 13] */ + movq_r2r (mm0, mm1); /* mm1 = [ 0 4 1 5] */ + punpckhwd_r2r (mm3, mm6); /* mm6 = 10 14 11 15] */ + movq_r2r (mm4, mm3); /* mm3 = [ 2 6 3 7] */ + punpckldq_r2r (mm2, mm0); /* final result mm0 = row1 [0 4 8 12] */ + punpckhdq_r2r (mm2, mm1); /* mm1 = final result mm1 = row2 [1 5 9 13] */ + ; /*slot */ + movq_r2m (mm0, *(inptr + ROW_STRIDE * 0 + 4)); /* store row 1 */ + punpckldq_r2r (mm6, mm4); /* final result mm4 = row3 [2 6 10 14] */ + /* begin reading next quadrant (upper-right) */ - movq_m2r(*(out + ROW_STRIDE*0 + 4), mm0); - punpckhdq_r2r(mm6, mm3); /* final result mm3 = row4 [3 7 11 15] */ - - movq_r2m(mm4, *(inptr + ROW_STRIDE * 2 + 4)); /* store row 3 */ - movq_r2r(mm0, mm4); /* mm4 = copy of row1[A B C D] */ - - movq_r2m(mm1, *(inptr + ROW_STRIDE * 1 + 4)); /* store row 2 */ - movq_m2r(*(out + ROW_STRIDE*1 + 4), mm1); - - movq_r2m(mm3, *(inptr + ROW_STRIDE * 3 + 4)); /* store row 4 */ - punpcklwd_r2r(mm1, mm0); /* mm0 = [ 0 4 1 5] */ - - - /* 2) transpose lower-right quadrant */ - + movq_m2r (*(out + ROW_STRIDE * 0 + 4), mm0); + punpckhdq_r2r (mm6, mm3); /* final result mm3 = row4 [3 7 11 15] */ + movq_r2m (mm4, *(inptr + ROW_STRIDE * 2 + 4)); /* store row 3 */ + movq_r2r (mm0, mm4); /* mm4 = copy of row1[A B C D] */ + movq_r2m (mm1, *(inptr + ROW_STRIDE * 1 + 4)); /* store row 2 */ + movq_m2r (*(out + ROW_STRIDE * 1 + 4), mm1); + movq_r2m (mm3, *(inptr + ROW_STRIDE * 3 + 4)); /* store row 4 */ + punpcklwd_r2r (mm1, mm0); /* mm0 = [ 0 4 1 5] */ + + /* 2) transpose lower-right quadrant */ + /* movq mm0, qword ptr [OUT + ROW_STRIDE*4 + 8] */ - + /* movq mm1, qword ptr [OUT + ROW_STRIDE*5 + 8] */ /* movq mm4, mm0; // mm4 = copy of row1[A B C D] */ - - movq_m2r(*(out + ROW_STRIDE*2 + 4), mm2); + movq_m2r (*(out + ROW_STRIDE * 2 + 4), mm2); + /* punpcklwd mm0, mm1; // mm0 = [ 0 4 1 5] */ - punpckhwd_r2r(mm1, mm4); /* mm4 = [ 2 6 3 7] */ - - movq_m2r(*(out + ROW_STRIDE*3 + 4), mm3); - movq_r2r(mm2, mm6); - - punpcklwd_r2r(mm3, mm2); /* mm2 = [ 8 12 9 13] */ - movq_r2r(mm0, mm1); /* mm1 = [ 0 4 1 5] */ - - punpckhwd_r2r(mm3, mm6); /* mm6 = 10 14 11 15] */ - movq_r2r(mm4, mm3); /* mm3 = [ 2 6 3 7] */ - - punpckldq_r2r(mm2, mm0); /* final result mm0 = row1 [0 4 8 12] */ - - punpckhdq_r2r(mm2, mm1); /* mm1 = final result mm1 = row2 [1 5 9 13] */ - ; /* slot */ - - movq_r2m(mm0, *(inptr + ROW_STRIDE*4)); /* store row 1 */ - punpckldq_r2r(mm6, mm4); /* final result mm4 = row3 [2 6 10 14] */ - - movq_r2m(mm1, *(inptr + ROW_STRIDE*5)); /* store row 2 */ - punpckhdq_r2r(mm6, mm3); /* final result mm3 = row4 [3 7 11 15] */ - - movq_r2m(mm4, *(inptr + ROW_STRIDE*6)); /* store row 3 */ - ; /* slot */ - - movq_r2m(mm3, *(inptr + ROW_STRIDE*7)); /* store row 4 */ - ; /* slot */ - -} - - -static void -idct_mmx32_cols( short *blk ) /* transform all 8 cols of 8x8 iDCT block */ -{ - int x; - short *inptr = blk; - - /* Despite the function's name, the matrix is transformed */ - /* row by row. This function is identical to idct_mmx32_rows(), */ - /* except for the SHIFT amount and ROUND_INV amount. */ - - /* this subroutine performs two operations */ - /* 1) iDCT row transform */ - /* for( i = 0; i < 8; ++ i) */ - /* DCT_8_INV_ROW_1( blk[i*8], qwTemp[i] ); */ - /* */ - /* 2) transpose the matrix (which was stored in qwTemp[]) */ - /* qwTemp[] -> [8x8 matrix transpose] -> blk[] */ - - - for (x=0; x<8; x++) { /* transform one row per iteration */ - - movq_m2r(*(inptr), mm0); /* 0 ; x3 x2 x1 x0 */ - - movq_m2r(*(inptr+4), mm1); /* 1 ; x7 x6 x5 x4 */ - movq_r2r(mm0, mm2); /* 2 ; x3 x2 x1 x0 */ - - movq_m2r(*(tab_i_01234567), mm3); /* 3 ; w06 w04 w02 w00 */ - punpcklwd_r2r(mm1, mm0); /* x5 x1 x4 x0 */ - + punpckhwd_r2r (mm1, mm4); /* mm4 = [ 2 6 3 7] */ + movq_m2r (*(out + ROW_STRIDE * 3 + 4), mm3); + movq_r2r (mm2, mm6); + punpcklwd_r2r (mm3, mm2); /* mm2 = [ 8 12 9 13] */ + movq_r2r (mm0, mm1); /* mm1 = [ 0 4 1 5] */ + punpckhwd_r2r (mm3, mm6); /* mm6 = 10 14 11 15] */ + movq_r2r (mm4, mm3); /* mm3 = [ 2 6 3 7] */ + punpckldq_r2r (mm2, mm0); /* final result mm0 = row1 [0 4 8 12] */ + punpckhdq_r2r (mm2, mm1); /* mm1 = final result mm1 = row2 [1 5 9 13] */ + ; /* slot */ + movq_r2m (mm0, *(inptr + ROW_STRIDE * 4)); /* store row 1 */ + punpckldq_r2r (mm6, mm4); /* final result mm4 = row3 [2 6 10 14] */ + movq_r2m (mm1, *(inptr + ROW_STRIDE * 5)); /* store row 2 */ + punpckhdq_r2r (mm6, mm3); /* final result mm3 = row4 [3 7 11 15] */ + movq_r2m (mm4, *(inptr + ROW_STRIDE * 6)); /* store row 3 */ + ; /* slot */ + movq_r2m (mm3, *(inptr + ROW_STRIDE * 7)); /* store row 4 */ + ; /* slot */ + } + static void +idct_mmx32_cols (short *blk) +{ /* transform all 8 cols of 8x8 iDCT block */ + int x; + short *inptr = blk; + + + /* Despite the function's name, the matrix is transformed */ + /* row by row. This function is identical to idct_mmx32_rows(), */ + /* except for the SHIFT amount and ROUND_INV amount. */ + + /* this subroutine performs two operations */ + /* 1) iDCT row transform */ + /* for( i = 0; i < 8; ++ i) */ + /* DCT_8_INV_ROW_1( blk[i*8], qwTemp[i] ); */ + /* */ + /* 2) transpose the matrix (which was stored in qwTemp[]) */ + /* qwTemp[] -> [8x8 matrix transpose] -> blk[] */ + for (x = 0; x < 8; x++) { /* transform one row per iteration */ + movq_m2r (*(inptr), mm0); /* 0 ; x3 x2 x1 x0 */ + movq_m2r (*(inptr + 4), mm1); /* 1 ; x7 x6 x5 x4 */ + movq_r2r (mm0, mm2); /* 2 ; x3 x2 x1 x0 */ + movq_m2r (*(tab_i_01234567), mm3); /* 3 ; w06 w04 w02 w00 */ + punpcklwd_r2r (mm1, mm0); /* x5 x1 x4 x0 */ + /* ---------- */ - movq_r2r(mm0, mm5); /* 5 ; x5 x1 x4 x0 */ - punpckldq_r2r(mm0, mm0); /* x4 x0 x4 x0 */ - - movq_m2r(*(tab_i_01234567+4), mm4); /* 4 ; w07 w05 w03 w01 */ - punpckhwd_r2r(mm1, mm2); /* 1 ; x7 x3 x6 x2 */ - - pmaddwd_r2r(mm0, mm3); /* x4*w06+x0*w04 x4*w02+x0*w00 */ - movq_r2r(mm2, mm6); /* 6 ; x7 x3 x6 x2 */ - - movq_m2r(*(tab_i_01234567+16), mm1);/* 1 ; w22 w20 w18 w16 */ - punpckldq_r2r(mm2, mm2); /* x6 x2 x6 x2 */ - - pmaddwd_r2r(mm2, mm4); /* x6*w07+x2*w05 x6*w03+x2*w01 */ - punpckhdq_r2r(mm5, mm5); /* x5 x1 x5 x1 */ - - pmaddwd_m2r(*(tab_i_01234567+8), mm0);/* x4*w14+x0*w12 x4*w10+x0*w08 */ - punpckhdq_r2r(mm6, mm6); /* x7 x3 x7 x3 */ - - movq_m2r(*(tab_i_01234567+20), mm7);/* 7 ; w23 w21 w19 w17 */ - pmaddwd_r2r(mm5, mm1); /* x5*w22+x1*w20 x5*w18+x1*w16 */ - - paddd_m2r(*(r_inv_col), mm3);/* +rounder */ - pmaddwd_r2r(mm6, mm7); /* x7*w23+x3*w21 x7*w19+x3*w17 */ - - pmaddwd_m2r(*(tab_i_01234567+12), mm2);/* x6*w15+x2*w13 x6*w11+x2*w09 */ - paddd_r2r(mm4, mm3); /* 4 ; a1=sum(even1) a0=sum(even0) */ - - pmaddwd_m2r(*(tab_i_01234567+24), mm5);/* x5*w30+x1*w28 x5*w26+x1*w24 */ - movq_r2r(mm3, mm4); /* 4 ; a1 a0 */ - - pmaddwd_m2r(*(tab_i_01234567+28), mm6);/* x7*w31+x3*w29 x7*w27+x3*w25 */ - paddd_r2r(mm7, mm1); /* 7 ; b1=sum(odd1) b0=sum(odd0) */ - - paddd_m2r(*(r_inv_col), mm0);/* +rounder */ - psubd_r2r(mm1, mm3); /* a1-b1 a0-b0 */ - - psrad_i2r(SHIFT_INV_COL, mm3); /* y6=a1-b1 y7=a0-b0 */ - paddd_r2r(mm4, mm1); /* 4 ; a1+b1 a0+b0 */ - - paddd_r2r(mm2, mm0); /* 2 ; a3=sum(even3) a2=sum(even2) */ - psrad_i2r(SHIFT_INV_COL, mm1); /* y1=a1+b1 y0=a0+b0 */ - - paddd_r2r(mm6, mm5); /* 6 ; b3=sum(odd3) b2=sum(odd2) */ - movq_r2r(mm0, mm4); /* 4 ; a3 a2 */ - - paddd_r2r(mm5, mm0); /* a3+b3 a2+b2 */ - psubd_r2r(mm5, mm4); /* 5 ; a3-b3 a2-b2 */ - - - psrad_i2r(SHIFT_INV_COL, mm4); /* y4=a3-b3 y5=a2-b2 */ - psrad_i2r(SHIFT_INV_COL, mm0); /* y3=a3+b3 y2=a2+b2 */ - - packssdw_r2r(mm3, mm4); /* 3 ; y6 y7 y4 y5 */ - - packssdw_r2r(mm0, mm1); /* 0 ; y3 y2 y1 y0 */ - movq_r2r(mm4, mm7); /* 7 ; y6 y7 y4 y5 */ - - psrld_i2r(16, mm4); /* 0 y6 0 y4 */ - - movq_r2m(mm1, *(inptr)); /* 1 ; save y3 y2 y1 y0 */ - pslld_i2r(16, mm7); /* y7 0 y5 0 */ - - por_r2r(mm4, mm7); /* 4 ; y7 y6 y5 y4 */ - - /* begin processing row 1 */ - movq_r2m(mm7, *(inptr+4)); /* 7 ; save y7 y6 y5 y4 */ - - inptr += 8; - } - /* done with the iDCT column-transformation */ -} - + movq_r2r (mm0, mm5); /* 5 ; x5 x1 x4 x0 */ + punpckldq_r2r (mm0, mm0); /* x4 x0 x4 x0 */ + movq_m2r (*(tab_i_01234567 + 4), mm4); /* 4 ; w07 w05 w03 w01 */ + punpckhwd_r2r (mm1, mm2); /* 1 ; x7 x3 x6 x2 */ + pmaddwd_r2r (mm0, mm3); /* x4*w06+x0*w04 x4*w02+x0*w00 */ + movq_r2r (mm2, mm6); /* 6 ; x7 x3 x6 x2 */ + movq_m2r (*(tab_i_01234567 + 16), mm1); /* 1 ; w22 w20 w18 w16 */ + punpckldq_r2r (mm2, mm2); /* x6 x2 x6 x2 */ + pmaddwd_r2r (mm2, mm4); /* x6*w07+x2*w05 x6*w03+x2*w01 */ + punpckhdq_r2r (mm5, mm5); /* x5 x1 x5 x1 */ + pmaddwd_m2r (*(tab_i_01234567 + 8), mm0); /* x4*w14+x0*w12 x4*w10+x0*w08 */ + punpckhdq_r2r (mm6, mm6); /* x7 x3 x7 x3 */ + movq_m2r (*(tab_i_01234567 + 20), mm7); /* 7 ; w23 w21 w19 w17 */ + pmaddwd_r2r (mm5, mm1); /* x5*w22+x1*w20 x5*w18+x1*w16 */ + paddd_m2r (*(r_inv_col), mm3); /* +rounder */ + pmaddwd_r2r (mm6, mm7); /* x7*w23+x3*w21 x7*w19+x3*w17 */ + pmaddwd_m2r (*(tab_i_01234567 + 12), mm2); /* x6*w15+x2*w13 x6*w11+x2*w09 */ + paddd_r2r (mm4, mm3); /* 4 ; a1=sum(even1) a0=sum(even0) */ + pmaddwd_m2r (*(tab_i_01234567 + 24), mm5); /* x5*w30+x1*w28 x5*w26+x1*w24 */ + movq_r2r (mm3, mm4); /* 4 ; a1 a0 */ + pmaddwd_m2r (*(tab_i_01234567 + 28), mm6); /* x7*w31+x3*w29 x7*w27+x3*w25 */ + paddd_r2r (mm7, mm1); /* 7 ; b1=sum(odd1) b0=sum(odd0) */ + paddd_m2r (*(r_inv_col), mm0); /* +rounder */ + psubd_r2r (mm1, mm3); /* a1-b1 a0-b0 */ + psrad_i2r (SHIFT_INV_COL, mm3); /* y6=a1-b1 y7=a0-b0 */ + paddd_r2r (mm4, mm1); /* 4 ; a1+b1 a0+b0 */ + paddd_r2r (mm2, mm0); /* 2 ; a3=sum(even3) a2=sum(even2) */ + psrad_i2r (SHIFT_INV_COL, mm1); /* y1=a1+b1 y0=a0+b0 */ + paddd_r2r (mm6, mm5); /* 6 ; b3=sum(odd3) b2=sum(odd2) */ + movq_r2r (mm0, mm4); /* 4 ; a3 a2 */ + paddd_r2r (mm5, mm0); /* a3+b3 a2+b2 */ + psubd_r2r (mm5, mm4); /* 5 ; a3-b3 a2-b2 */ + psrad_i2r (SHIFT_INV_COL, mm4); /* y4=a3-b3 y5=a2-b2 */ + psrad_i2r (SHIFT_INV_COL, mm0); /* y3=a3+b3 y2=a2+b2 */ + packssdw_r2r (mm3, mm4); /* 3 ; y6 y7 y4 y5 */ + packssdw_r2r (mm0, mm1); /* 0 ; y3 y2 y1 y0 */ + movq_r2r (mm4, mm7); /* 7 ; y6 y7 y4 y5 */ + psrld_i2r (16, mm4); /* 0 y6 0 y4 */ + movq_r2m (mm1, *(inptr)); /* 1 ; save y3 y2 y1 y0 */ + pslld_i2r (16, mm7); /* y7 0 y5 0 */ + por_r2r (mm4, mm7); /* 4 ; y7 y6 y5 y4 */ + + /* begin processing row 1 */ + movq_r2m (mm7, *(inptr + 4)); /* 7 ; save y7 y6 y5 y4 */ + inptr += 8; + } + + /* done with the iDCT column-transformation */ +} + + /* */ /* public interface to MMX32 IDCT 8x8 operation */ /* */ -void -gst_idct_mmx32_idct( short *blk ) -{ - /* 1) iDCT row transformation */ - idct_mmx32_rows( blk ); /* 1) transform iDCT row, and transpose */ - - /* 2) iDCT column transformation */ - idct_mmx32_cols( blk ); /* 2) transform iDCT row, and transpose */ - - emms(); /* restore processor state */ - /* all done */ -} +void +gst_idct_mmx32_idct (short *blk) +{ + + /* 1) iDCT row transformation */ + idct_mmx32_rows (blk); /* 1) transform iDCT row, and transpose */ + + /* 2) iDCT column transformation */ + idct_mmx32_cols (blk); /* 2) transform iDCT row, and transpose */ + emms (); /* restore processor state */ + /* all done */ +} diff --git a/gst-libs/gst/media-info/media-info-priv.c b/gst-libs/gst/media-info/media-info-priv.c index 8f4a1f5684..fb0122093c 100644 --- a/gst-libs/gst/media-info/media-info-priv.c +++ b/gst-libs/gst/media-info/media-info-priv.c @@ -49,9 +49,10 @@ gmi_stream_new (void) } void -gmi_stream_free (GstMediaInfoStream *stream) +gmi_stream_free (GstMediaInfoStream * stream) { - if (stream->mime) g_free (stream->mime); + if (stream->mime) + g_free (stream->mime); /* FIXME: free tracks */ g_free (stream); } @@ -78,7 +79,8 @@ gmi_track_new (void) /* callbacks */ static void -have_type_callback (GstElement *typefind, guint probability, GstCaps *type, GstMediaInfoPriv *priv) +have_type_callback (GstElement * typefind, guint probability, GstCaps * type, + GstMediaInfoPriv * priv) { GstStructure *str; const gchar *mime; @@ -90,8 +92,7 @@ have_type_callback (GstElement *typefind, guint probability, GstCaps *type, GstM /* FIXME: this code doesn't yet work, test it later */ #ifdef DONTWORK - if (strcmp (mime, "application/x-id3") == 0) - { + if (strcmp (mime, "application/x-id3") == 0) { /* dig a little deeper */ GST_DEBUG ("dealing with id3, digging deeper"); gst_element_set_state (priv->pipeline, GST_STATE_READY); @@ -102,70 +103,72 @@ have_type_callback (GstElement *typefind, guint probability, GstCaps *type, GstM if (priv->decontainer == NULL) /* FIXME: signal error */ g_warning ("Couldn't create id3tag"); - if (!gst_element_link_many (priv->source, priv->decontainer, priv->typefind, NULL)); - g_warning ("Couldn't link in id3tag"); + if (!gst_element_link_many (priv->source, priv->decontainer, priv->typefind, + NULL)); + g_warning ("Couldn't link in id3tag"); if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING) - == GST_STATE_FAILURE) + == GST_STATE_FAILURE) g_warning ("Couldn't set to playing"); } #endif } void -deep_notify_callback (GObject *object, GstObject *origin, - GParamSpec *pspec, GstMediaInfoPriv *priv) +deep_notify_callback (GObject * object, GstObject * origin, + GParamSpec * pspec, GstMediaInfoPriv * priv) { GValue value = { 0, }; /* we only care about pad notifies */ - if (!GST_IS_PAD (origin)) return; + if (!GST_IS_PAD (origin)) + return; /* - GST_DEBUG ("DEBUG: deep_notify: have notify of %s from object %s:%s !", - pspec->name, gst_element_get_name (gst_pad_get_parent (GST_PAD (origin))), - gst_object_get_name (origin)); - */ - else if (strcmp (pspec->name, "caps") == 0) - { + GST_DEBUG ("DEBUG: deep_notify: have notify of %s from object %s:%s !", + pspec->name, gst_element_get_name (gst_pad_get_parent (GST_PAD (origin))), + gst_object_get_name (origin)); + */ + else if (strcmp (pspec->name, "caps") == 0) { /* check if we're getting it from fakesink */ - if (GST_IS_PAD (origin) && GST_PAD_PARENT (origin) == priv->fakesink) - { + if (GST_IS_PAD (origin) && GST_PAD_PARENT (origin) == priv->fakesink) { GST_DEBUG ("have caps on fakesink pad !"); g_value_init (&value, pspec->value_type); g_object_get_property (G_OBJECT (origin), pspec->name, &value); priv->format = g_value_peek_pointer (&value); GST_DEBUG ("caps: %" GST_PTR_FORMAT, priv->format); - } - else GST_DEBUG ("ignoring caps on object %s:%s", - gst_object_get_name (gst_object_get_parent (origin)), - gst_object_get_name (origin)); - } - else if (strcmp (pspec->name, "offset") == 0) - { + } else + GST_DEBUG ("ignoring caps on object %s:%s", + gst_object_get_name (gst_object_get_parent (origin)), + gst_object_get_name (origin)); + } else if (strcmp (pspec->name, "offset") == 0) { /* we REALLY ignore offsets, we hate them */ } - //else GST_DEBUG ("ignoring notify of %s", pspec->name); + //else GST_DEBUG ("ignoring notify of %s", pspec->name); } -typedef struct { +typedef struct +{ guint meta; guint encoded; } TagFlagScore; static void -tag_flag_score (const GstTagList *list, const gchar *tag, gpointer user_data) +tag_flag_score (const GstTagList * list, const gchar * tag, gpointer user_data) { TagFlagScore *score = (TagFlagScore *) user_data; GstTagFlag flag; flag = gst_tag_get_flag (tag); - if (flag == GST_TAG_FLAG_META) score->meta++; - if (flag == GST_TAG_FLAG_ENCODED) score->encoded++; + if (flag == GST_TAG_FLAG_META) + score->meta++; + if (flag == GST_TAG_FLAG_ENCODED) + score->encoded++; } void -found_tag_callback (GObject *pipeline, GstElement *source, GstTagList *tags, GstMediaInfoPriv *priv) +found_tag_callback (GObject * pipeline, GstElement * source, GstTagList * tags, + GstMediaInfoPriv * priv) { TagFlagScore score; @@ -179,20 +182,18 @@ found_tag_callback (GObject *pipeline, GstElement *source, GstTagList *tags, Gst gst_tag_list_foreach (tags, tag_flag_score, &score); - if (score.meta > score.encoded) - { + if (score.meta > score.encoded) { GST_DEBUG ("found tags from decoder, adding them as metadata"); priv->metadata = gst_tag_list_copy (tags); - } - else - { + } else { GST_DEBUG ("found tags, adding them as streaminfo"); priv->streaminfo = gst_tag_list_copy (tags); } } void -error_callback (GObject *element, GstElement *source, GError *error, gchar *debug, GstMediaInfoPriv *priv) +error_callback (GObject * element, GstElement * source, GError * error, + gchar * debug, GstMediaInfoPriv * priv) { g_print ("ERROR: %s\n", error->message); g_error_free (error); @@ -202,7 +203,7 @@ error_callback (GObject *element, GstElement *source, GError *error, gchar *debu /* General GError creation */ static void -gst_media_info_error_create (GError **error, const gchar *message) +gst_media_info_error_create (GError ** error, const gchar * message) { /* check if caller wanted an error reported */ if (error == NULL) @@ -214,15 +215,14 @@ gst_media_info_error_create (GError **error, const gchar *message) /* GError creation when element is missing */ static void -gst_media_info_error_element (const gchar *element, GError **error) +gst_media_info_error_element (const gchar * element, GError ** error) { gchar *message; message = g_strdup_printf ("The %s element could not be found. " - "This element is essential for reading. " - "Please install the right plug-in and verify " - "that it works by running 'gst-inspect %s'", - element, element); + "This element is essential for reading. " + "Please install the right plug-in and verify " + "that it works by running 'gst-inspect %s'", element, element); gst_media_info_error_create (error, message); g_free (message); return; @@ -230,7 +230,7 @@ gst_media_info_error_element (const gchar *element, GError **error) /* initialise priv; done the first time */ gboolean -gmip_init (GstMediaInfoPriv *priv, GError **error) +gmip_init (GstMediaInfoPriv * priv, GError ** error) { #define GST_MEDIA_INFO_MAKE_OR_ERROR(el, factory, name, error) \ G_STMT_START { \ @@ -257,7 +257,7 @@ G_STMT_START { \ /* called at the beginning of each use cycle */ /* reset info to a state where it can be used to query for media info */ void -gmip_reset (GstMediaInfoPriv *priv) +gmip_reset (GstMediaInfoPriv * priv) { #define STRING_RESET(string) \ @@ -266,8 +266,8 @@ G_STMT_START { \ string = NULL; \ } G_STMT_END - STRING_RESET(priv->pipeline_desc); - STRING_RESET(priv->location); + STRING_RESET (priv->pipeline_desc); + STRING_RESET (priv->location); #undef STRING_RESET #define CAPS_RESET(target) \ @@ -275,8 +275,8 @@ G_STMT_START { \ if (target) gst_caps_free (target); \ target = NULL; \ } G_STMT_END - CAPS_RESET(priv->type); - CAPS_RESET(priv->format); + CAPS_RESET (priv->type); + CAPS_RESET (priv->format); #undef CAPS_RESET #define TAGS_RESET(target) \ @@ -285,12 +285,11 @@ G_STMT_START { \ gst_tag_list_free (target); \ target = NULL; \ } G_STMT_END - TAGS_RESET(priv->metadata); - TAGS_RESET(priv->streaminfo); + TAGS_RESET (priv->metadata); + TAGS_RESET (priv->streaminfo); #undef TAGS_RESET - if (priv->stream) - { + if (priv->stream) { gmi_stream_free (priv->stream); priv->stream = NULL; } @@ -302,7 +301,7 @@ G_STMT_START { \ /* seek to a track and reset metadata and streaminfo structs */ gboolean -gmi_seek_to_track (GstMediaInfo *info, long track) +gmi_seek_to_track (GstMediaInfo * info, long track) { GstEvent *event; GstFormat track_format = 0; @@ -311,32 +310,28 @@ gmi_seek_to_track (GstMediaInfo *info, long track) /* FIXME: consider more nicks as "track" */ track_format = gst_format_get_by_nick ("logical_stream"); - if (track_format == 0) return FALSE; + if (track_format == 0) + return FALSE; GST_DEBUG ("Track format: %d", track_format); if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING) - == GST_STATE_FAILURE) + == GST_STATE_FAILURE) g_warning ("Couldn't set to play"); g_assert (GST_IS_PAD (info->priv->decoder_pad)); event = gst_event_new_seek (track_format | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, - track); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, track); res = gst_pad_send_event (info->priv->decoder_pad, event); - if (!res) - { + if (!res) { g_warning ("seek to logical track on pad %s:%s failed", - GST_DEBUG_PAD_NAME(info->priv->decoder_pad)); + GST_DEBUG_PAD_NAME (info->priv->decoder_pad)); return FALSE; } /* clear structs because of the seek */ - if (priv->metadata) - { + if (priv->metadata) { gst_tag_list_free (priv->metadata); priv->metadata = NULL; } - if (priv->streaminfo) - { + if (priv->streaminfo) { gst_tag_list_free (priv->streaminfo); priv->streaminfo = NULL; } @@ -345,7 +340,7 @@ gmi_seek_to_track (GstMediaInfo *info, long track) /* set the mime type on the media info getter */ gboolean -gmi_set_mime (GstMediaInfo *info, const char *mime) +gmi_set_mime (GstMediaInfo * info, const char *mime) { gchar *desc = NULL; GError *error = NULL; @@ -354,31 +349,45 @@ gmi_set_mime (GstMediaInfo *info, const char *mime) /* FIXME: please figure out proper mp3 mimetypes */ if ((strcmp (mime, "application/x-ogg") == 0) || (strcmp (mime, "application/ogg") == 0)) - desc = g_strdup_printf ("%s name=source ! oggdemux ! vorbisdec name=decoder ! fakesink name=sink", priv->source_name); - else if ((strcmp (mime, "audio/mpeg") == 0) || - (strcmp (mime, "audio/x-mp3") == 0) || - (strcmp (mime, "audio/mp3") == 0) || - (strcmp (mime, "application/x-id3") == 0) || - (strcmp (mime, "audio/x-id3") == 0)) - desc = g_strdup_printf ("%s name=source ! id3tag ! mad name=decoder ! audio/x-raw-int ! fakesink name=sink", priv->source_name); - else if ((strcmp (mime, "application/x-flac") == 0) || - (strcmp (mime, "audio/x-flac") == 0)) - desc = g_strdup_printf ("%s name=source ! flacdec name=decoder ! audio/x-raw-int ! fakesink name=sink", priv->source_name); - else if ((strcmp (mime, "audio/wav") == 0) || - (strcmp (mime, "audio/x-wav") == 0)) - desc = g_strdup_printf ("%s ! wavparse name=decoder ! audio/x-raw-int ! fakesink name=sink", priv->source_name); - else if (strcmp (mime, "audio/x-mod") == 0 || - strcmp (mime, "audio/x-s3m") == 0 || - strcmp (mime, "audio/x-xm") == 0 || - strcmp (mime, "audio/x-it") == 0) - desc = g_strdup_printf ("%s name=source ! modplug name=decoder ! audio/x-raw-int ! fakesink name=sink", priv->source_name); - else return FALSE; + desc = + g_strdup_printf + ("%s name=source ! oggdemux ! vorbisdec name=decoder ! fakesink name=sink", + priv->source_name); + else if ((strcmp (mime, "audio/mpeg") == 0) + || (strcmp (mime, "audio/x-mp3") == 0) + || (strcmp (mime, "audio/mp3") == 0) + || (strcmp (mime, "application/x-id3") == 0) + || (strcmp (mime, "audio/x-id3") == 0)) + desc = + g_strdup_printf + ("%s name=source ! id3tag ! mad name=decoder ! audio/x-raw-int ! fakesink name=sink", + priv->source_name); + else if ((strcmp (mime, "application/x-flac") == 0) + || (strcmp (mime, "audio/x-flac") == 0)) + desc = + g_strdup_printf + ("%s name=source ! flacdec name=decoder ! audio/x-raw-int ! fakesink name=sink", + priv->source_name); + else if ((strcmp (mime, "audio/wav") == 0) + || (strcmp (mime, "audio/x-wav") == 0)) + desc = + g_strdup_printf + ("%s ! wavparse name=decoder ! audio/x-raw-int ! fakesink name=sink", + priv->source_name); + else if (strcmp (mime, "audio/x-mod") == 0 + || strcmp (mime, "audio/x-s3m") == 0 || strcmp (mime, "audio/x-xm") == 0 + || strcmp (mime, "audio/x-it") == 0) + desc = + g_strdup_printf + ("%s name=source ! modplug name=decoder ! audio/x-raw-int ! fakesink name=sink", + priv->source_name); + else + return FALSE; GST_DEBUG ("using description %s", desc); priv->pipeline_desc = desc; priv->pipeline = gst_parse_launch (desc, &error); - if (error) - { + if (error) { g_warning ("Error parsing pipeline description: %s\n", error->message); g_error_free (error); return FALSE; @@ -398,25 +407,27 @@ gmi_set_mime (GstMediaInfo *info, const char *mime) /* get the "decoder" source pad */ priv->decoder_pad = gst_element_get_pad (priv->decoder, "src"); g_assert (GST_IS_PAD (priv->decoder_pad)); - GST_DEBUG ("decoder pad: %s:%s", gst_object_get_name (gst_object_get_parent (GST_OBJECT (priv->decoder_pad))), gst_pad_get_name (priv->decoder_pad)); + GST_DEBUG ("decoder pad: %s:%s", + gst_object_get_name (gst_object_get_parent (GST_OBJECT (priv-> + decoder_pad))), gst_pad_get_name (priv->decoder_pad)); /* attach notify handler */ g_signal_connect (G_OBJECT (info->priv->pipeline), "deep_notify", - G_CALLBACK (deep_notify_callback), info->priv); - g_signal_connect (G_OBJECT (info->priv->pipeline), "found-tag", G_CALLBACK (found_tag_callback), info->priv); + G_CALLBACK (deep_notify_callback), info->priv); + g_signal_connect (G_OBJECT (info->priv->pipeline), "found-tag", + G_CALLBACK (found_tag_callback), info->priv); g_signal_connect (G_OBJECT (info->priv->pipeline), "error", - G_CALLBACK (error_callback), info->priv); + G_CALLBACK (error_callback), info->priv); return TRUE; } /* clear the decoding pipeline */ void -gmi_clear_decoder (GstMediaInfo *info) +gmi_clear_decoder (GstMediaInfo * info) { - if (info->priv->pipeline) - { - GST_DEBUG("Unreffing pipeline"); + if (info->priv->pipeline) { + GST_DEBUG ("Unreffing pipeline"); gst_object_unref (GST_OBJECT (info->priv->pipeline)); } info->priv->pipeline = NULL; @@ -430,7 +441,7 @@ gmi_clear_decoder (GstMediaInfo *info) /* prepare for typefind, move from NULL to TYPEFIND */ gboolean -gmip_find_type_pre (GstMediaInfoPriv *priv, GError **error) +gmip_find_type_pre (GstMediaInfoPriv * priv, GError ** error) { g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -440,23 +451,21 @@ gmip_find_type_pre (GstMediaInfoPriv *priv, GError **error) * just use it through this function only */ priv->pipeline = gst_pipeline_new ("pipeline-typefind"); - if (!GST_IS_PIPELINE (priv->pipeline)) - { + if (!GST_IS_PIPELINE (priv->pipeline)) { gst_media_info_error_create (error, "Internal GStreamer error."); return FALSE; } gst_bin_add (GST_BIN (priv->pipeline), priv->typefind); GST_MEDIA_INFO_MAKE_OR_ERROR (priv->source, priv->source_name, "source", - error); + error); g_object_set (G_OBJECT (priv->source), "location", priv->location, NULL); gst_bin_add (GST_BIN (priv->pipeline), priv->source); if (!gst_element_link (priv->source, priv->typefind)) g_warning ("Couldn't connect source and typefind\n"); g_signal_connect (G_OBJECT (priv->typefind), "have-type", - G_CALLBACK (have_type_callback), priv); + G_CALLBACK (have_type_callback), priv); if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING) - == GST_STATE_FAILURE) - { + == GST_STATE_FAILURE) { g_warning ("Couldn't set to play"); return FALSE; } @@ -467,24 +476,20 @@ gmip_find_type_pre (GstMediaInfoPriv *priv, GError **error) /* finish off typefind */ gboolean -gmip_find_type_post (GstMediaInfoPriv *priv) +gmip_find_type_post (GstMediaInfoPriv * priv) { /*clear up typefind */ gst_element_set_state (priv->pipeline, GST_STATE_READY); - if (priv->decontainer) - { + if (priv->decontainer) { gst_element_unlink (priv->source, priv->decontainer); gst_element_unlink (priv->decontainer, priv->typefind); gst_bin_remove (GST_BIN (priv->pipeline), priv->decontainer); - } - else - { + } else { gst_element_unlink (priv->source, priv->typefind); } gst_bin_remove (GST_BIN (priv->pipeline), priv->typefind); - if (priv->type == NULL) - { + if (priv->type == NULL) { g_warning ("iteration ended, type not found !\n"); return FALSE; } @@ -495,25 +500,23 @@ gmip_find_type_post (GstMediaInfoPriv *priv) /* complete version */ gboolean -gmip_find_type (GstMediaInfoPriv *priv, GError ** error) +gmip_find_type (GstMediaInfoPriv * priv, GError ** error) { if (!gmip_find_type_pre (priv, error)) return FALSE; GST_DEBUG ("gmip_find_type: iterating"); - while ((priv->type == NULL) && - gst_bin_iterate (GST_BIN (priv->pipeline))) - GMI_DEBUG("+"); - GMI_DEBUG("\n"); + while ((priv->type == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline))) + GMI_DEBUG ("+"); + GMI_DEBUG ("\n"); return gmip_find_type_post (priv); } /* FIXME: why not have these functions work on priv types ? */ gboolean -gmip_find_stream_pre (GstMediaInfoPriv *priv) +gmip_find_stream_pre (GstMediaInfoPriv * priv) { if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING) - == GST_STATE_FAILURE) - { + == GST_STATE_FAILURE) { g_warning ("Couldn't set to play"); return FALSE; } @@ -522,7 +525,7 @@ gmip_find_stream_pre (GstMediaInfoPriv *priv) } gboolean -gmip_find_stream_post (GstMediaInfoPriv *priv) +gmip_find_stream_post (GstMediaInfoPriv * priv) { GstMediaInfoStream *stream = priv->stream; const GstFormat *formats; @@ -541,8 +544,7 @@ gmip_find_stream_post (GstMediaInfoPriv *priv) /* get supported formats on decoder pad */ formats = gst_pad_get_formats (priv->decoder_pad); - while (*formats) - { + while (*formats) { const GstFormatDefinition *definition; format = *formats; @@ -551,16 +553,13 @@ gmip_find_stream_post (GstMediaInfoPriv *priv) definition = gst_format_get_details (*formats); GST_DEBUG ("trying to figure out length for format %s", definition->nick); - res = gst_pad_query (priv->decoder_pad, GST_QUERY_TOTAL, - &format, &value); + res = gst_pad_query (priv->decoder_pad, GST_QUERY_TOTAL, &format, &value); - if (res) - { - switch (format) - { - case GST_FORMAT_TIME: - stream->length_time = value; - GST_DEBUG (" total %s: %lld", definition->nick, value); + if (res) { + switch (format) { + case GST_FORMAT_TIME: + stream->length_time = value; + GST_DEBUG (" total %s: %lld", definition->nick, value); break; case GST_FORMAT_DEFAULT: case GST_FORMAT_BYTES: @@ -568,35 +567,33 @@ gmip_find_stream_post (GstMediaInfoPriv *priv) default: /* separation is necessary because track_format doesn't resolve to * int */ - if (format == track_format) - { + if (format == track_format) { stream->length_tracks = value; - GST_DEBUG (" total %s: %lld", definition->nick, value); - } - else + GST_DEBUG (" total %s: %lld", definition->nick, value); + } else GST_DEBUG ("unhandled format %s", definition->nick); } - } - else + } else GST_DEBUG ("query didn't return result for %s", definition->nick); formats++; } - if (stream->length_tracks == 0) stream->length_tracks = 1; + if (stream->length_tracks == 0) + stream->length_tracks = 1; /* now get number of bytes from the sink pad to get the bitrate */ format = GST_FORMAT_BYTES; g_assert (GST_IS_PAD (priv->source_pad)); - res = gst_pad_query (priv->source_pad, GST_QUERY_TOTAL, - &format, &value); - if (!res) g_warning ("Failed to query on sink pad !"); + res = gst_pad_query (priv->source_pad, GST_QUERY_TOTAL, &format, &value); + if (!res) + g_warning ("Failed to query on sink pad !"); bytes = value; GST_DEBUG ("bitrate calc: bytes gotten: %ld", bytes); - if (bytes) - { + if (bytes) { double seconds = (double) stream->length_time / GST_SECOND; double bits = bytes * 8; + stream->bitrate = (long) (bits / seconds); } GST_DEBUG ("moving to STATE_METADATA\n"); @@ -607,7 +604,7 @@ gmip_find_stream_post (GstMediaInfoPriv *priv) /* get properties of complete physical stream * and return them in pre-alloced stream struct in priv->stream */ gboolean -gmip_find_stream (GstMediaInfoPriv *priv) +gmip_find_stream (GstMediaInfoPriv * priv) { GST_DEBUG ("mip_find_stream start"); @@ -615,16 +612,13 @@ gmip_find_stream (GstMediaInfoPriv *priv) /* iterate until caps are found */ /* FIXME: this should be done through the plugin sending some signal * that it is ready for queries */ - while (gst_bin_iterate (GST_BIN (priv->pipeline)) && - priv->format == NULL) - ; + while (gst_bin_iterate (GST_BIN (priv->pipeline)) && priv->format == NULL); if (gst_element_set_state (priv->pipeline, GST_STATE_PAUSED) - == GST_STATE_FAILURE) + == GST_STATE_FAILURE) g_warning ("Couldn't set to paused"); - if (priv->format == NULL) - { - GMI_DEBUG("gmip_find_stream: couldn't get caps !"); + if (priv->format == NULL) { + GMI_DEBUG ("gmip_find_stream: couldn't get caps !"); return FALSE; } return gmip_find_stream_post (priv); @@ -632,14 +626,13 @@ gmip_find_stream (GstMediaInfoPriv *priv) /* find metadata encoded in media and store in priv->metadata */ gboolean -gmip_find_track_metadata_pre (GstMediaInfoPriv *priv) +gmip_find_track_metadata_pre (GstMediaInfoPriv * priv) { /* FIXME: this is a hack to set max allowed iterations for metadata * querying - we should make gst smarter by itself instead */ priv->metadata_iters = 0; if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING) - == GST_STATE_FAILURE) - { + == GST_STATE_FAILURE) { g_warning ("Couldn't set to play"); return FALSE; } @@ -647,10 +640,10 @@ gmip_find_track_metadata_pre (GstMediaInfoPriv *priv) } gboolean -gmip_find_track_metadata_post (GstMediaInfoPriv *priv) +gmip_find_track_metadata_post (GstMediaInfoPriv * priv) { if (gst_element_set_state (priv->pipeline, GST_STATE_PAUSED) - == GST_STATE_FAILURE) + == GST_STATE_FAILURE) return FALSE; priv->current_track->metadata = priv->metadata; priv->metadata = NULL; @@ -658,14 +651,13 @@ gmip_find_track_metadata_post (GstMediaInfoPriv *priv) } gboolean -gmip_find_track_metadata (GstMediaInfoPriv *priv) +gmip_find_track_metadata (GstMediaInfoPriv * priv) { gmip_find_track_metadata_pre (priv); GST_DEBUG ("gmip_find_metadata: iterating"); - while ((priv->metadata == NULL) && - gst_bin_iterate (GST_BIN (priv->pipeline))) - GMI_DEBUG("+"); - GMI_DEBUG("\n"); + while ((priv->metadata == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline))) + GMI_DEBUG ("+"); + GMI_DEBUG ("\n"); gmip_find_track_metadata_post (priv); return TRUE; @@ -674,11 +666,10 @@ gmip_find_track_metadata (GstMediaInfoPriv *priv) /* find streaminfo found by decoder and store in priv->streaminfo */ /* FIXME: this is an exact copy, so reuse this function instead */ gboolean -gmip_find_track_streaminfo_pre (GstMediaInfoPriv *priv) +gmip_find_track_streaminfo_pre (GstMediaInfoPriv * priv) { if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING) - == GST_STATE_FAILURE) - { + == GST_STATE_FAILURE) { g_warning ("Couldn't set to play"); return FALSE; } @@ -686,7 +677,7 @@ gmip_find_track_streaminfo_pre (GstMediaInfoPriv *priv) } gboolean -gmip_find_track_streaminfo_post (GstMediaInfoPriv *priv) +gmip_find_track_streaminfo_post (GstMediaInfoPriv * priv) { GstFormat format, track_format; @@ -694,33 +685,26 @@ gmip_find_track_streaminfo_post (GstMediaInfoPriv *priv) /* now add total length to this, and maybe even bitrate ? FIXME */ track_format = gst_format_get_by_nick ("logical_stream"); - if (track_format == 0) - { + if (track_format == 0) { g_print ("FIXME: implement getting length of whole track\n"); - } - else - { + } else { /* which one are we at ? */ long track_num; gint64 value_start, value_end; gboolean res; res = gst_pad_query (priv->decoder_pad, GST_QUERY_POSITION, - &track_format, &value_start); - if (res) - { + &track_format, &value_start); + if (res) { format = GST_FORMAT_TIME; track_num = value_start; GST_DEBUG ("we are currently at %ld", track_num); - res = gst_pad_convert (priv->decoder_pad, - track_format, track_num, - &format, &value_start); + res = gst_pad_convert (priv->decoder_pad, + track_format, track_num, &format, &value_start); res &= gst_pad_convert (priv->decoder_pad, - track_format, track_num + 1, - &format, &value_end); - if (res) - { - /* substract to get the length */ + track_format, track_num + 1, &format, &value_end); + if (res) { + /* substract to get the length */ GST_DEBUG ("start %lld, end %lld", value_start, value_end); value_end -= value_start; /* FIXME: check units; this is in seconds */ @@ -737,14 +721,14 @@ gmip_find_track_streaminfo_post (GstMediaInfoPriv *priv) } gboolean -gmip_find_track_streaminfo (GstMediaInfoPriv *priv) +gmip_find_track_streaminfo (GstMediaInfoPriv * priv) { gmip_find_track_streaminfo_pre (priv); GST_DEBUG ("DEBUG: gmip_find_streaminfo: iterating"); while ((priv->streaminfo == NULL) && - gst_bin_iterate (GST_BIN (priv->pipeline))) - GMI_DEBUG("+"); - GMI_DEBUG("\n"); + gst_bin_iterate (GST_BIN (priv->pipeline))) + GMI_DEBUG ("+"); + GMI_DEBUG ("\n"); gmip_find_track_streaminfo_post (priv); return TRUE; @@ -752,11 +736,10 @@ gmip_find_track_streaminfo (GstMediaInfoPriv *priv) /* find format found by decoder and store in priv->format */ gboolean -gmip_find_track_format_pre (GstMediaInfoPriv *priv) +gmip_find_track_format_pre (GstMediaInfoPriv * priv) { if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING) - == GST_STATE_FAILURE) - { + == GST_STATE_FAILURE) { g_warning ("Couldn't set to play"); return FALSE; } @@ -764,10 +747,10 @@ gmip_find_track_format_pre (GstMediaInfoPriv *priv) } gboolean -gmip_find_track_format_post (GstMediaInfoPriv *priv) +gmip_find_track_format_post (GstMediaInfoPriv * priv) { if (gst_element_set_state (priv->pipeline, GST_STATE_PAUSED) - == GST_STATE_FAILURE) + == GST_STATE_FAILURE) return FALSE; priv->current_track->format = priv->format; priv->format = NULL; @@ -775,17 +758,14 @@ gmip_find_track_format_post (GstMediaInfoPriv *priv) } gboolean -gmip_find_track_format (GstMediaInfoPriv *priv) +gmip_find_track_format (GstMediaInfoPriv * priv) { gmip_find_track_format_pre (priv); GST_DEBUG ("DEBUG: gmip_find_format: iterating"); - while ((priv->format == NULL) && - gst_bin_iterate (GST_BIN (priv->pipeline))) - GMI_DEBUG("+"); - GMI_DEBUG("\n"); + while ((priv->format == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline))) + GMI_DEBUG ("+"); + GMI_DEBUG ("\n"); gmip_find_track_format_post (priv); return TRUE; } - - diff --git a/gst-libs/gst/media-info/media-info-priv.h b/gst-libs/gst/media-info/media-info-priv.h index 81ee24ab71..8f0f453fc9 100644 --- a/gst-libs/gst/media-info/media-info-priv.h +++ b/gst-libs/gst/media-info/media-info-priv.h @@ -72,69 +72,65 @@ struct GstMediaInfoPriv gint metadata_iters; GstTagList *streaminfo; - GstElement *pipeline; /* will be != NULL during collection */ - gchar *pipeline_desc; /* will be != NULL during collection */ - GstElement *fakesink; /* so we can get caps from the - decoder sink pad */ - gchar *source_name; /* type of element used as source */ + GstElement *pipeline; /* will be != NULL during collection */ + gchar *pipeline_desc; /* will be != NULL during collection */ + GstElement *fakesink; /* so we can get caps from the + decoder sink pad */ + gchar *source_name; /* type of element used as source */ GstElement *source; - GstPad *source_pad; /* pad for querying encoded caps */ + GstPad *source_pad; /* pad for querying encoded caps */ GstElement *decoder; - GstPad *decoder_pad; /* pad for querying decoded caps */ - GstElement *decontainer; /* element to typefind in containers */ + GstPad *decoder_pad; /* pad for querying decoded caps */ + GstElement *decontainer; /* element to typefind in containers */ - GstMediaInfoState state; /* current state of state machine */ - gchar *location; /* location set on the info object */ - guint16 flags; /* flags supplied for detection */ - GstMediaInfoTrack *current_track; /* track pointer under inspection */ - glong current_track_num; /* current track under inspection */ + GstMediaInfoState state; /* current state of state machine */ + gchar *location; /* location set on the info object */ + guint16 flags; /* flags supplied for detection */ + GstMediaInfoTrack *current_track; /* track pointer under inspection */ + glong current_track_num; /* current track under inspection */ - GstMediaInfoStream *stream; /* total stream properties */ - char *cache; /* location of cache */ + GstMediaInfoStream *stream; /* total stream properties */ + char *cache; /* location of cache */ - GError *error; /* error for creation problems */ + GError *error; /* error for creation problems */ }; /* declarations */ -GstMediaInfoStream * - gmi_stream_new (void); -void gmi_stream_free (GstMediaInfoStream *stream); +GstMediaInfoStream *gmi_stream_new (void); +void gmi_stream_free (GstMediaInfoStream * stream); -GstMediaInfoTrack * - gmi_track_new (void); +GstMediaInfoTrack *gmi_track_new (void); -void gmip_reset (GstMediaInfoPriv *priv); -gboolean gmip_init (GstMediaInfoPriv *priv, GError **error); +void gmip_reset (GstMediaInfoPriv * priv); +gboolean gmip_init (GstMediaInfoPriv * priv, GError ** error); -void gmi_clear_decoder (GstMediaInfo *info); +void gmi_clear_decoder (GstMediaInfo * info); -gboolean gmi_seek_to_track (GstMediaInfo *info, - long track); +gboolean gmi_seek_to_track (GstMediaInfo * info, long track); -gboolean gmi_set_mime (GstMediaInfo *info, - const char *mime); +gboolean gmi_set_mime (GstMediaInfo * info, const char *mime); -void deep_notify_callback (GObject *object, - GstObject *origin, - GParamSpec *pspec, - GstMediaInfoPriv *priv); -void found_tag_callback (GObject *pipeline, GstElement *source, GstTagList *tags, GstMediaInfoPriv *priv); -void error_callback (GObject *element, GstElement *source, GError *error, gchar *debug, GstMediaInfoPriv *priv); +void deep_notify_callback (GObject * object, + GstObject * origin, GParamSpec * pspec, GstMediaInfoPriv * priv); +void found_tag_callback (GObject * pipeline, GstElement * source, + GstTagList * tags, GstMediaInfoPriv * priv); +void error_callback (GObject * element, GstElement * source, GError * error, + gchar * debug, GstMediaInfoPriv * priv); -gboolean gmip_find_type_pre (GstMediaInfoPriv *priv, GError **error); -gboolean gmip_find_type_post (GstMediaInfoPriv *priv); -gboolean gmip_find_type (GstMediaInfoPriv *priv, GError **error); -gboolean gmip_find_stream_pre (GstMediaInfoPriv *priv); -gboolean gmip_find_stream_post (GstMediaInfoPriv *priv); -gboolean gmip_find_stream (GstMediaInfoPriv *priv); -gboolean gmip_find_track_metadata_pre (GstMediaInfoPriv *priv); -gboolean gmip_find_track_metadata_post (GstMediaInfoPriv *priv); -gboolean gmip_find_track_metadata (GstMediaInfoPriv *priv); -gboolean gmip_find_track_streaminfo_pre (GstMediaInfoPriv *priv); -gboolean gmip_find_track_streaminfo_post (GstMediaInfoPriv *priv); -gboolean gmip_find_track_streaminfo (GstMediaInfoPriv *priv); -gboolean gmip_find_track_format_pre (GstMediaInfoPriv *priv); -gboolean gmip_find_track_format_post (GstMediaInfoPriv *priv); -gboolean gmip_find_track_format (GstMediaInfoPriv *priv); +gboolean gmip_find_type_pre (GstMediaInfoPriv * priv, GError ** error); +gboolean gmip_find_type_post (GstMediaInfoPriv * priv); +gboolean gmip_find_type (GstMediaInfoPriv * priv, GError ** error); +gboolean gmip_find_stream_pre (GstMediaInfoPriv * priv); +gboolean gmip_find_stream_post (GstMediaInfoPriv * priv); +gboolean gmip_find_stream (GstMediaInfoPriv * priv); +gboolean gmip_find_track_metadata_pre (GstMediaInfoPriv * priv); +gboolean gmip_find_track_metadata_post (GstMediaInfoPriv * priv); +gboolean gmip_find_track_metadata (GstMediaInfoPriv * priv); +gboolean gmip_find_track_streaminfo_pre (GstMediaInfoPriv * priv); +gboolean gmip_find_track_streaminfo_post (GstMediaInfoPriv * priv); +gboolean gmip_find_track_streaminfo (GstMediaInfoPriv * priv); +gboolean gmip_find_track_format_pre (GstMediaInfoPriv * priv); +gboolean gmip_find_track_format_post (GstMediaInfoPriv * priv); +gboolean gmip_find_track_format (GstMediaInfoPriv * priv); #endif /* __GST_MEDIA_INFO_PRIV_H__ */ diff --git a/gst-libs/gst/media-info/media-info-test.c b/gst-libs/gst/media-info/media-info-test.c index 496267d953..67a16cdc23 100644 --- a/gst-libs/gst/media-info/media-info-test.c +++ b/gst-libs/gst/media-info/media-info-test.c @@ -5,7 +5,7 @@ #include "media-info.h" static void -print_tag (const GstTagList *list, const gchar *tag, gpointer unused) +print_tag (const GstTagList * list, const gchar * tag, gpointer unused) { gint i, count; @@ -17,8 +17,8 @@ print_tag (const GstTagList *list, const gchar *tag, gpointer unused) if (gst_tag_get_type (tag) == G_TYPE_STRING) { g_assert (gst_tag_list_get_string_index (list, tag, i, &str)); } else { - str = g_strdup_value_contents ( - gst_tag_list_get_value_index (list, tag, i)); + str = + g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i)); } if (i == 0) { @@ -32,7 +32,7 @@ print_tag (const GstTagList *list, const gchar *tag, gpointer unused) } static void -info_print (GstMediaInfoStream *stream) +info_print (GstMediaInfoStream * stream) { int i; GList *p; @@ -40,17 +40,15 @@ info_print (GstMediaInfoStream *stream) g_print ("- mime type: %s\n", stream->mime); g_print ("- length: %.3f seconds\n", - (gdouble) stream->length_time / GST_SECOND); + (gdouble) stream->length_time / GST_SECOND); g_print ("- bitrate: %.3f kbps\n", stream->bitrate / 1000.0); g_print ("- number of tracks: %ld\n", stream->length_tracks); p = stream->tracks; - if (p == NULL) - { + if (p == NULL) { g_print ("- no track information, probably an error\n"); return; } - for (i = 0; i < stream->length_tracks; ++i) - { + for (i = 0; i < stream->length_tracks; ++i) { g_print ("- track %d\n", i); track = (GstMediaInfoTrack *) p->data; g_print (" - metadata:\n"); @@ -80,16 +78,14 @@ main (int argc, char *argv[]) gst_init (&argc, &argv); info = gst_media_info_new (&error); - if (error != NULL) - { + if (error != NULL) { g_print ("Error creating media-info object: %s\n", error->message); g_error_free (error); return -1; } g_assert (G_IS_OBJECT (info)); - if (!gst_media_info_set_source (info, "gnomevfssrc", &error)) - { + if (!gst_media_info_set_source (info, "gnomevfssrc", &error)) { g_print ("Could not set gnomevfssrc as a source\n"); g_print ("reason: %s\n", error->message); g_error_free (error); @@ -97,19 +93,18 @@ main (int argc, char *argv[]) } g_print ("stream: %p, &stream: %p\n", stream, &stream); - for (i = 1; i < argc; ++i) - { + for (i = 1; i < argc; ++i) { /* - stream = gst_media_info_read (info, argv[i], GST_MEDIA_INFO_ALL); - */ + stream = gst_media_info_read (info, argv[i], GST_MEDIA_INFO_ALL); + */ gst_media_info_read_with_idler (info, argv[i], GST_MEDIA_INFO_ALL, &error); while (gst_media_info_read_idler (info, &stream, &error) && stream == NULL) - /* keep idling */ g_print ("+"); + /* keep idling */ + g_print ("+"); g_print ("\nFILE: %s\n", argv[i]); g_print ("stream: %p, &stream: %p\n", stream, &stream); - if (error) - { + if (error) { g_print ("Error reading media info: %s\n", error->message); g_error_free (error); } diff --git a/gst-libs/gst/media-info/media-info.c b/gst-libs/gst/media-info/media-info.c index 902b6cef01..4f99535945 100644 --- a/gst-libs/gst/media-info/media-info.c +++ b/gst-libs/gst/media-info/media-info.c @@ -26,12 +26,11 @@ #include "media-info.h" #include "media-info-priv.h" -static void gst_media_info_class_init (GstMediaInfoClass *klass); -static void gst_media_info_instance_init (GstMediaInfo *info); +static void gst_media_info_class_init (GstMediaInfoClass * klass); +static void gst_media_info_instance_init (GstMediaInfo * info); -static void gst_media_info_get_property (GObject *object, guint prop_id, - GValue *value, - GParamSpec *pspec); +static void gst_media_info_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); static gboolean _media_info_inited = FALSE; @@ -64,6 +63,7 @@ GQuark gst_media_info_error_quark (void) { static GQuark quark = 0; + if (quark == 0) quark = g_quark_from_static_string ("gst-media-info-error-quark"); return quark; @@ -86,11 +86,12 @@ GST_DEBUG_CATEGORY (gst_media_info_debug); void gst_media_info_init (void) { - if (_media_info_inited) return; + if (_media_info_inited) + return; /* register our debugging category */ GST_DEBUG_CATEGORY_INIT (gst_media_info_debug, "GST_MEDIA_INFO", 0, - "GStreamer media-info library"); + "GStreamer media-info library"); GST_DEBUG ("Initialized media-info library"); _media_info_inited = TRUE; } @@ -99,8 +100,8 @@ GType gst_media_info_get_type (void) { static GType gst_media_info_type = 0; - if (!gst_media_info_type) - { + + if (!gst_media_info_type) { static const GTypeInfo gst_media_info_info = { sizeof (GstMediaInfoClass), (GBaseInitFunc) NULL, @@ -113,14 +114,13 @@ gst_media_info_get_type (void) NULL }; gst_media_info_type = g_type_register_static (G_TYPE_OBJECT, - "GstMediaInfo", - &gst_media_info_info, 0); + "GstMediaInfo", &gst_media_info_info, 0); } return gst_media_info_type; } static void -gst_media_info_class_init (GstMediaInfoClass *klass) +gst_media_info_class_init (GstMediaInfoClass * klass) { GObjectClass *g_object_class = G_OBJECT_CLASS (klass); @@ -129,36 +129,36 @@ gst_media_info_class_init (GstMediaInfoClass *klass) /* - object_class->finalize = gst_media_info_finalize; - object_class->dispose = gst_media_info_dispose; - */ + object_class->finalize = gst_media_info_finalize; + object_class->dispose = gst_media_info_dispose; + */ /* - g_object_class->set_property = gst_media_info_set_property; - */ + g_object_class->set_property = gst_media_info_set_property; + */ g_object_class->get_property = gst_media_info_get_property; klass->media_info_signal = NULL; - gst_media_info_signals [MEDIA_INFO_SIGNAL] = - g_signal_new ("media-info", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstMediaInfoClass, media_info_signal), - NULL, NULL, - gst_marshal_VOID__VOID, - G_TYPE_NONE, 0); + gst_media_info_signals[MEDIA_INFO_SIGNAL] = + g_signal_new ("media-info", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstMediaInfoClass, media_info_signal), + NULL, NULL, gst_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void -gst_media_info_instance_init (GstMediaInfo *info) +gst_media_info_instance_init (GstMediaInfo * info) { GError **error; info->priv = g_new0 (GstMediaInfoPriv, 1); error = &info->priv->error; - if (!_media_info_inited) { gst_media_info_init (); } + if (!_media_info_inited) { + gst_media_info_init (); + } gmip_init (info->priv, error); gmip_reset (info->priv); @@ -166,13 +166,12 @@ gst_media_info_instance_init (GstMediaInfo *info) /* get/set */ static void -gst_media_info_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) +gst_media_info_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { GstMediaInfo *info = GST_MEDIA_INFO (object); - switch (prop_id) - { + switch (prop_id) { case PROP_SOURCE: g_value_set_string (value, info->priv->source_name); break; @@ -183,21 +182,17 @@ gst_media_info_get_property (GObject *object, guint prop_id, } GstMediaInfo * -gst_media_info_new (GError **error) +gst_media_info_new (GError ** error) { GstMediaInfo *info = g_object_new (GST_MEDIA_INFO_TYPE, NULL); - if (info->priv->error) - { - if (error) - { + if (info->priv->error) { + if (error) { *error = info->priv->error; info->priv->error = NULL; - } - else - { + } else { g_warning ("Error creating GstMediaInfo object.\n%s", - info->priv->error->message); + info->priv->error->message); g_error_free (info->priv->error); } } @@ -208,7 +203,8 @@ gst_media_info_new (GError **error) * public methods */ gboolean -gst_media_info_set_source (GstMediaInfo *info, const char *source, GError **error) +gst_media_info_set_source (GstMediaInfo * info, const char *source, + GError ** error) { info->priv->source_name = g_strdup (source); return TRUE; @@ -221,12 +217,12 @@ gst_media_info_set_source (GstMediaInfo *info, const char *source, GError **erro * previous one is done ? */ void -gst_media_info_read_with_idler (GstMediaInfo *info, const char *location, - guint16 flags, GError **error) +gst_media_info_read_with_idler (GstMediaInfo * info, const char *location, + guint16 flags, GError ** error) { GstMediaInfoPriv *priv = info->priv; - gmip_reset (info->priv); /* reset all structs */ + gmip_reset (info->priv); /* reset all structs */ priv->location = g_strdup (location); priv->flags = flags; } @@ -236,12 +232,14 @@ gst_media_info_read_with_idler (GstMediaInfo *info, const char *location, * returns: TRUE if it was able to idle, FALSE if there was an error */ gboolean -gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp, GError **error) +gst_media_info_read_idler (GstMediaInfo * info, GstMediaInfoStream ** streamp, + GError ** error) { GstMediaInfoPriv *priv; /* if it's NULL then we're sure something went wrong higher up) */ - if (info == NULL) return FALSE; + if (info == NULL) + return FALSE; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); priv = info->priv; @@ -249,15 +247,13 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp, GEr g_assert (streamp != NULL); g_assert (priv); - switch (priv->state) - { + switch (priv->state) { case GST_MEDIA_INFO_STATE_NULL: /* make sure we have a source */ - if (!priv->source_name) - { - *error = g_error_new (GST_MEDIA_INFO_ERROR, 0, - "No source set on media info."); - return FALSE; + if (!priv->source_name) { + *error = g_error_new (GST_MEDIA_INFO_ERROR, 0, + "No source set on media info."); + return FALSE; } /* need to find type */ @@ -269,29 +265,27 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp, GEr gchar *mime; GST_LOG ("STATE_TYPEFIND"); - if ((priv->type == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline))) - { + if ((priv->type == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline))) { GST_DEBUG ("iterating while in STATE_TYPEFIND"); - GMI_DEBUG("?"); - return TRUE; + GMI_DEBUG ("?"); + return TRUE; } - if (priv->type == NULL) - { - g_warning ("Couldn't find type\n"); + if (priv->type == NULL) { + g_warning ("Couldn't find type\n"); return FALSE; } /* do the state transition */ GST_DEBUG ("doing find_type_post"); gmip_find_type_post (priv); GST_DEBUG ("finding out mime type"); - mime = g_strdup (gst_structure_get_name ( - gst_caps_get_structure(priv->type, 0))); + mime = + g_strdup (gst_structure_get_name (gst_caps_get_structure (priv->type, + 0))); GST_DEBUG ("found out mime type: %s", mime); - if (!gmi_set_mime (info, mime)) - { - /* FIXME: pop up error */ - GST_DEBUG ("no decoder pipeline found for mime %s", mime); - return FALSE; + if (!gmi_set_mime (info, mime)) { + /* FIXME: pop up error */ + GST_DEBUG ("no decoder pipeline found for mime %s", mime); + return FALSE; } priv->stream = gmi_stream_new (); GST_DEBUG ("new stream: %p", priv->stream); @@ -303,14 +297,12 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp, GEr case GST_MEDIA_INFO_STATE_STREAM: { GST_LOG ("STATE_STREAM"); - if ((priv->format == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline))) - { - GMI_DEBUG("?"); - return TRUE; + if ((priv->format == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline))) { + GMI_DEBUG ("?"); + return TRUE; } - if (priv->format == NULL) - { - g_warning ("Couldn't find format\n"); + if (priv->format == NULL) { + g_warning ("Couldn't find format\n"); return FALSE; } /* do state transition; stream -> first track metadata */ @@ -320,26 +312,25 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp, GEr gmip_find_track_metadata_pre (priv); return TRUE; } - /* these ones are repeated per track */ + /* these ones are repeated per track */ case GST_MEDIA_INFO_STATE_METADATA: { if ((priv->metadata == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline)) && - priv->metadata_iters < MAX_METADATA_ITERS) - { - GMI_DEBUG("?"); + priv->metadata_iters < MAX_METADATA_ITERS) { + GMI_DEBUG ("?"); priv->metadata_iters++; - return TRUE; + return TRUE; } if (priv->metadata_iters == MAX_METADATA_ITERS) - g_print ("iterated a few times, didn't find metadata\n"); - if (priv->metadata == NULL) - { + g_print ("iterated a few times, didn't find metadata\n"); + if (priv->metadata == NULL) { /* this is not a permanent failure */ - GST_DEBUG ("Couldn't find metadata"); + GST_DEBUG ("Couldn't find metadata"); } GST_DEBUG ("found metadata of track %ld", priv->current_track_num); - if (!gmip_find_track_metadata_post (priv)) return FALSE; + if (!gmip_find_track_metadata_post (priv)) + return FALSE; GST_DEBUG ("METADATA: going to STREAMINFO\n"); priv->state = GST_MEDIA_INFO_STATE_STREAMINFO; return gmip_find_track_streaminfo_pre (priv); @@ -347,53 +338,47 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp, GEr case GST_MEDIA_INFO_STATE_STREAMINFO: { if ((priv->streaminfo == NULL) && - gst_bin_iterate (GST_BIN (priv->pipeline))) - { - GMI_DEBUG("?"); - return TRUE; + gst_bin_iterate (GST_BIN (priv->pipeline))) { + GMI_DEBUG ("?"); + return TRUE; } - if (priv->streaminfo == NULL) - { + if (priv->streaminfo == NULL) { /* this is not a permanent failure */ - GST_DEBUG ("Couldn't find streaminfo"); - } - else - GST_DEBUG ("found streaminfo of track %ld", priv->current_track_num); - if (!gmip_find_track_streaminfo_post (priv)) return FALSE; + GST_DEBUG ("Couldn't find streaminfo"); + } else + GST_DEBUG ("found streaminfo of track %ld", priv->current_track_num); + if (!gmip_find_track_streaminfo_post (priv)) + return FALSE; priv->state = GST_MEDIA_INFO_STATE_FORMAT; return gmip_find_track_format_pre (priv); } case GST_MEDIA_INFO_STATE_FORMAT: { - if ((priv->format == NULL) && - gst_bin_iterate (GST_BIN (priv->pipeline))) - { - GMI_DEBUG("?"); - return TRUE; + if ((priv->format == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline))) { + GMI_DEBUG ("?"); + return TRUE; } - if (priv->format == NULL) - { - g_warning ("Couldn't find format\n"); + if (priv->format == NULL) { + g_warning ("Couldn't find format\n"); return FALSE; } GST_DEBUG ("found format of track %ld", priv->current_track_num); - if (!gmip_find_track_format_post (priv)) return FALSE; + if (!gmip_find_track_format_post (priv)) + return FALSE; /* save the track info */ priv->stream->tracks = g_list_append (priv->stream->tracks, - priv->current_track); + priv->current_track); /* these alloc'd data types have been handed off */ priv->current_track = NULL; priv->location = NULL; /* now see if we need to seek to a next track or not */ priv->current_track_num++; - if (priv->current_track_num < priv->stream->length_tracks) - { - gmi_seek_to_track (info, priv->current_track_num); - priv->current_track = gmi_track_new (); - if (!gmip_find_track_metadata_pre (priv)) - { + if (priv->current_track_num < priv->stream->length_tracks) { + gmi_seek_to_track (info, priv->current_track_num); + priv->current_track = gmi_track_new (); + if (!gmip_find_track_metadata_pre (priv)) { g_free (priv->current_track); - return FALSE; + return FALSE; } priv->state = GST_MEDIA_INFO_STATE_METADATA; return TRUE; @@ -407,24 +392,26 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp, GEr } case GST_MEDIA_INFO_STATE_DONE: return TRUE; - default: + default: g_warning ("don't know what to do\n"); return FALSE; - } + } } /* main function * read all possible info from the file pointed to by location * use flags to limit the type of information searched for */ GstMediaInfoStream * -gst_media_info_read (GstMediaInfo *info, const char *location, guint16 flags, GError **error) +gst_media_info_read (GstMediaInfo * info, const char *location, guint16 flags, + GError ** error) { GstMediaInfoStream *stream = NULL; gst_media_info_read_with_idler (info, location, flags, error); - if (*error) return FALSE; + if (*error) + return FALSE; while (gst_media_info_read_idler (info, &stream, error) && stream == NULL) - /* keep looping */; + /* keep looping */ ; if (*error) return NULL; diff --git a/gst-libs/gst/media-info/media-info.h b/gst-libs/gst/media-info/media-info.h index c134999d06..bbbcce2b8d 100644 --- a/gst-libs/gst/media-info/media-info.h +++ b/gst-libs/gst/media-info/media-info.h @@ -23,11 +23,9 @@ #include -G_BEGIN_DECLS - -typedef struct GstMediaInfoPriv GstMediaInfoPriv; -typedef struct _GstMediaInfo GstMediaInfo; -typedef struct _GstMediaInfoClass GstMediaInfoClass; +G_BEGIN_DECLS typedef struct GstMediaInfoPriv GstMediaInfoPriv; +typedef struct _GstMediaInfo GstMediaInfo; +typedef struct _GstMediaInfoClass GstMediaInfoClass; struct _GstMediaInfo { @@ -43,8 +41,9 @@ struct _GstMediaInfoClass GObjectClass parent_class; /* signals */ - void (*media_info_signal) (GstMediaInfo *gst_media_info); - void (*error_signal) (GstMediaInfo *gst_media_info, GError *error, const gchar *debug); + void (*media_info_signal) (GstMediaInfo * gst_media_info); + void (*error_signal) (GstMediaInfo * gst_media_info, GError * error, + const gchar * debug); gpointer _gst_reserved[GST_PADDING]; }; @@ -100,34 +99,25 @@ typedef struct #define GST_MEDIA_INFO_FORMAT 1 << 5 #define GST_MEDIA_INFO_ALL ((1 << 6) - 1) -GQuark gst_media_info_error_quark (void); +GQuark gst_media_info_error_quark (void); -void gst_media_info_init (void); -GType gst_media_info_get_type (void); +void gst_media_info_init (void); +GType gst_media_info_get_type (void); -GstMediaInfo * gst_media_info_new (GError **error); +GstMediaInfo *gst_media_info_new (GError ** error); + +gboolean gst_media_info_set_source (GstMediaInfo * info, + const char *source, GError ** error); +void gst_media_info_read_with_idler (GstMediaInfo * media_info, + const char *location, guint16 GST_MEDIA_INFO_FLAGS, GError ** error); +gboolean gst_media_info_read_idler (GstMediaInfo * media_info, + GstMediaInfoStream ** streamp, GError ** error); +GstMediaInfoStream *gst_media_info_read (GstMediaInfo * media_info, + const char *location, guint16 GST_MEDIA_INFO_FLAGS, GError ** error); +gboolean gst_media_info_read_many (GstMediaInfo * media_info, + GList * locations, guint16 GST_MEDIA_INFO_FLAGS, GError ** error); +GstCaps *gst_media_info_get_next (GstMediaInfo * media_info, GError ** error); -gboolean gst_media_info_set_source (GstMediaInfo *info, - const char *source, - GError **error); -void gst_media_info_read_with_idler (GstMediaInfo *media_info, - const char *location, - guint16 GST_MEDIA_INFO_FLAGS, - GError **error); -gboolean gst_media_info_read_idler (GstMediaInfo *media_info, - GstMediaInfoStream **streamp, - GError **error); -GstMediaInfoStream * - gst_media_info_read (GstMediaInfo *media_info, - const char *location, - guint16 GST_MEDIA_INFO_FLAGS, - GError **error); -gboolean gst_media_info_read_many (GstMediaInfo *media_info, - GList *locations, - guint16 GST_MEDIA_INFO_FLAGS, - GError **error); -GstCaps * gst_media_info_get_next (GstMediaInfo *media_info, - GError **error); /* * FIXME: reset ? gboolean gst_media_info_write (GstMediaInfo *media_info, @@ -136,5 +126,4 @@ gboolean gst_media_info_write (GstMediaInfo *media_info, */ G_END_DECLS - #endif /* __GST_MEDIA_INFO_H__ */ diff --git a/gst-libs/gst/mixer/mixer.c b/gst-libs/gst/mixer/mixer.c index 0c1d6e0fbd..a9034f608c 100644 --- a/gst-libs/gst/mixer/mixer.c +++ b/gst-libs/gst/mixer/mixer.c @@ -26,14 +26,15 @@ #include "mixer.h" #include "mixer-marshal.h" -enum { +enum +{ MUTE_TOGGLED, RECORD_TOGGLED, VOLUME_CHANGED, LAST_SIGNAL }; -static void gst_mixer_class_init (GstMixerClass *klass); +static void gst_mixer_class_init (GstMixerClass * klass); static guint gst_mixer_signals[LAST_SIGNAL] = { 0 }; @@ -56,48 +57,47 @@ gst_mixer_get_type (void) }; gst_mixer_type = g_type_register_static (G_TYPE_INTERFACE, - "GstMixer", - &gst_mixer_info, 0); + "GstMixer", &gst_mixer_info, 0); g_type_interface_add_prerequisite (gst_mixer_type, - GST_TYPE_IMPLEMENTS_INTERFACE); + GST_TYPE_IMPLEMENTS_INTERFACE); } return gst_mixer_type; } static void -gst_mixer_class_init (GstMixerClass *klass) +gst_mixer_class_init (GstMixerClass * klass) { static gboolean initialized = FALSE; - + if (!initialized) { gst_mixer_signals[RECORD_TOGGLED] = - g_signal_new ("record-toggled", - GST_TYPE_MIXER, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstMixerClass, record_toggled), - NULL, NULL, - gst_mixer_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, - GST_TYPE_MIXER_TRACK, G_TYPE_BOOLEAN); + g_signal_new ("record-toggled", + GST_TYPE_MIXER, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstMixerClass, record_toggled), + NULL, NULL, + gst_mixer_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, + GST_TYPE_MIXER_TRACK, G_TYPE_BOOLEAN); gst_mixer_signals[MUTE_TOGGLED] = - g_signal_new ("mute-toggled", - GST_TYPE_MIXER, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstMixerClass, mute_toggled), - NULL, NULL, - gst_mixer_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, - GST_TYPE_MIXER_TRACK, G_TYPE_BOOLEAN); + g_signal_new ("mute-toggled", + GST_TYPE_MIXER, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstMixerClass, mute_toggled), + NULL, NULL, + gst_mixer_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, + GST_TYPE_MIXER_TRACK, G_TYPE_BOOLEAN); gst_mixer_signals[VOLUME_CHANGED] = - g_signal_new ("volume-changed", - GST_TYPE_MIXER, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstMixerClass, volume_changed), - NULL, NULL, - gst_mixer_marshal_VOID__OBJECT_POINTER, G_TYPE_NONE, 2, - GST_TYPE_MIXER_TRACK, G_TYPE_POINTER); - + g_signal_new ("volume-changed", + GST_TYPE_MIXER, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstMixerClass, volume_changed), + NULL, NULL, + gst_mixer_marshal_VOID__OBJECT_POINTER, G_TYPE_NONE, 2, + GST_TYPE_MIXER_TRACK, G_TYPE_POINTER); + initialized = TRUE; } klass->mixer_type = GST_MIXER_SOFTWARE; - + /* default virtual functions */ klass->list_tracks = NULL; klass->set_volume = NULL; @@ -119,7 +119,7 @@ gst_mixer_class_init (GstMixerClass *klass) */ const GList * -gst_mixer_list_tracks (GstMixer *mixer) +gst_mixer_list_tracks (GstMixer * mixer) { GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer); @@ -146,9 +146,7 @@ gst_mixer_list_tracks (GstMixer *mixer) */ void -gst_mixer_set_volume (GstMixer *mixer, - GstMixerTrack *track, - gint *volumes) +gst_mixer_set_volume (GstMixer * mixer, GstMixerTrack * track, gint * volumes) { GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer); @@ -169,9 +167,7 @@ gst_mixer_set_volume (GstMixer *mixer, */ void -gst_mixer_get_volume (GstMixer *mixer, - GstMixerTrack *track, - gint *volumes) +gst_mixer_get_volume (GstMixer * mixer, GstMixerTrack * track, gint * volumes) { GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer); @@ -198,9 +194,7 @@ gst_mixer_get_volume (GstMixer *mixer, */ void -gst_mixer_set_mute (GstMixer *mixer, - GstMixerTrack *track, - gboolean mute) +gst_mixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute) { GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer); @@ -223,9 +217,7 @@ gst_mixer_set_mute (GstMixer *mixer, */ void -gst_mixer_set_record (GstMixer *mixer, - GstMixerTrack *track, - gboolean record) +gst_mixer_set_record (GstMixer * mixer, GstMixerTrack * track, gboolean record) { GstMixerClass *klass = GST_MIXER_GET_CLASS (mixer); @@ -235,43 +227,30 @@ gst_mixer_set_record (GstMixer *mixer, } void -gst_mixer_mute_toggled (GstMixer *mixer, - GstMixerTrack *track, - gboolean mute) +gst_mixer_mute_toggled (GstMixer * mixer, GstMixerTrack * track, gboolean mute) { g_signal_emit (G_OBJECT (mixer), - gst_mixer_signals[MUTE_TOGGLED], 0, - track, mute); + gst_mixer_signals[MUTE_TOGGLED], 0, track, mute); - g_signal_emit_by_name (G_OBJECT (track), - "mute_toggled", - mute); + g_signal_emit_by_name (G_OBJECT (track), "mute_toggled", mute); } void -gst_mixer_record_toggled (GstMixer *mixer, - GstMixerTrack *track, - gboolean record) +gst_mixer_record_toggled (GstMixer * mixer, + GstMixerTrack * track, gboolean record) { g_signal_emit (G_OBJECT (mixer), - gst_mixer_signals[RECORD_TOGGLED], 0, - track, record); + gst_mixer_signals[RECORD_TOGGLED], 0, track, record); - g_signal_emit_by_name (G_OBJECT (track), - "record_toggled", - record); + g_signal_emit_by_name (G_OBJECT (track), "record_toggled", record); } void -gst_mixer_volume_changed (GstMixer *mixer, - GstMixerTrack *track, - gint *volumes) +gst_mixer_volume_changed (GstMixer * mixer, + GstMixerTrack * track, gint * volumes) { g_signal_emit (G_OBJECT (mixer), - gst_mixer_signals[VOLUME_CHANGED], 0, - track, volumes); + gst_mixer_signals[VOLUME_CHANGED], 0, track, volumes); - g_signal_emit_by_name (G_OBJECT (track), - "volume_changed", - volumes); + g_signal_emit_by_name (G_OBJECT (track), "volume_changed", volumes); } diff --git a/gst-libs/gst/mixer/mixer.h b/gst-libs/gst/mixer/mixer.h index 50ba3fd835..2caad1642e 100644 --- a/gst-libs/gst/mixer/mixer.h +++ b/gst-libs/gst/mixer/mixer.h @@ -27,7 +27,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_MIXER \ (gst_mixer_get_type ()) #define GST_MIXER(obj) \ @@ -40,9 +39,7 @@ G_BEGIN_DECLS (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MIXER)) #define GST_MIXER_GET_CLASS(inst) \ (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GST_TYPE_MIXER, GstMixerClass)) - #define GST_MIXER_TYPE(klass) (klass->mixer_type) - typedef struct _GstMixer GstMixer; typedef enum @@ -51,70 +48,52 @@ typedef enum GST_MIXER_SOFTWARE } GstMixerType; -typedef struct _GstMixerClass { +typedef struct _GstMixerClass +{ GTypeInterface klass; GstMixerType mixer_type; - + /* virtual functions */ - const GList * (* list_tracks) (GstMixer *mixer); + const GList *(*list_tracks) (GstMixer * mixer); - void (* set_volume) (GstMixer *mixer, - GstMixerTrack *track, - gint *volumes); - void (* get_volume) (GstMixer *mixer, - GstMixerTrack *track, - gint *volumes); + void (*set_volume) (GstMixer * mixer, GstMixerTrack * track, gint * volumes); + void (*get_volume) (GstMixer * mixer, GstMixerTrack * track, gint * volumes); - void (* set_mute) (GstMixer *mixer, - GstMixerTrack *track, - gboolean mute); - void (* set_record) (GstMixer *mixer, - GstMixerTrack *track, - gboolean record); + void (*set_mute) (GstMixer * mixer, GstMixerTrack * track, gboolean mute); + void (*set_record) (GstMixer * mixer, GstMixerTrack * track, gboolean record); /* signals */ - void (* mute_toggled) (GstMixer *mixer, - GstMixerTrack *channel, - gboolean mute); - void (* record_toggled) (GstMixer *mixer, - GstMixerTrack *channel, - gboolean record); - void (* volume_changed) (GstMixer *mixer, - GstMixerTrack *channel, - gint *volumes); + void (*mute_toggled) (GstMixer * mixer, + GstMixerTrack * channel, gboolean mute); + void (*record_toggled) (GstMixer * mixer, + GstMixerTrack * channel, gboolean record); + void (*volume_changed) (GstMixer * mixer, + GstMixerTrack * channel, gint * volumes); gpointer _gst_reserved[GST_PADDING]; } GstMixerClass; -GType gst_mixer_get_type (void); +GType gst_mixer_get_type (void); /* virtual class function wrappers */ -const GList * gst_mixer_list_tracks (GstMixer *mixer); -void gst_mixer_set_volume (GstMixer *mixer, - GstMixerTrack *track, - gint *volumes); -void gst_mixer_get_volume (GstMixer *mixer, - GstMixerTrack *track, - gint *volumes); -void gst_mixer_set_mute (GstMixer *mixer, - GstMixerTrack *track, - gboolean mute); -void gst_mixer_set_record (GstMixer *mixer, - GstMixerTrack *track, - gboolean record); +const GList *gst_mixer_list_tracks (GstMixer * mixer); +void gst_mixer_set_volume (GstMixer * mixer, + GstMixerTrack * track, gint * volumes); +void gst_mixer_get_volume (GstMixer * mixer, + GstMixerTrack * track, gint * volumes); +void gst_mixer_set_mute (GstMixer * mixer, + GstMixerTrack * track, gboolean mute); +void gst_mixer_set_record (GstMixer * mixer, + GstMixerTrack * track, gboolean record); /* trigger signals */ -void gst_mixer_mute_toggled (GstMixer *mixer, - GstMixerTrack *track, - gboolean mute); -void gst_mixer_record_toggled (GstMixer *mixer, - GstMixerTrack *track, - gboolean record); -void gst_mixer_volume_changed (GstMixer *mixer, - GstMixerTrack *track, - gint *volumes); +void gst_mixer_mute_toggled (GstMixer * mixer, + GstMixerTrack * track, gboolean mute); +void gst_mixer_record_toggled (GstMixer * mixer, + GstMixerTrack * track, gboolean record); +void gst_mixer_volume_changed (GstMixer * mixer, + GstMixerTrack * track, gint * volumes); G_END_DECLS - #endif /* __GST_MIXER_H__ */ diff --git a/gst-libs/gst/mixer/mixertrack.c b/gst-libs/gst/mixer/mixertrack.c index 242b5915ae..af52aec8cb 100644 --- a/gst-libs/gst/mixer/mixertrack.c +++ b/gst-libs/gst/mixer/mixertrack.c @@ -25,7 +25,8 @@ #include "mixertrack.h" -enum { +enum +{ /* FILL ME */ SIGNAL_VOLUME_CHANGED, SIGNAL_RECORD_TOGGLED, @@ -33,9 +34,9 @@ enum { LAST_SIGNAL }; -static void gst_mixer_track_class_init (GstMixerTrackClass *klass); -static void gst_mixer_track_init (GstMixerTrack *mixer); -static void gst_mixer_track_dispose (GObject *object); +static void gst_mixer_track_class_init (GstMixerTrackClass * klass); +static void gst_mixer_track_init (GstMixerTrack * mixer); +static void gst_mixer_track_dispose (GObject * object); static GObjectClass *parent_class = NULL; static guint signals[LAST_SIGNAL] = { 0 }; @@ -61,47 +62,46 @@ gst_mixer_track_get_type (void) gst_mixer_track_type = g_type_register_static (G_TYPE_OBJECT, - "GstMixerTrack", - &mixer_track_info, 0); + "GstMixerTrack", &mixer_track_info, 0); } return gst_mixer_track_type; } static void -gst_mixer_track_class_init (GstMixerTrackClass *klass) +gst_mixer_track_class_init (GstMixerTrackClass * klass) { GObjectClass *object_klass = (GObjectClass *) klass; parent_class = g_type_class_ref (G_TYPE_OBJECT); signals[SIGNAL_RECORD_TOGGLED] = - g_signal_new ("record_toggled", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstMixerTrackClass, - record_toggled), - NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + g_signal_new ("record_toggled", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstMixerTrackClass, + record_toggled), + NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); signals[SIGNAL_MUTE_TOGGLED] = - g_signal_new ("mute_toggled", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstMixerTrackClass, - mute_toggled), - NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + g_signal_new ("mute_toggled", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstMixerTrackClass, + mute_toggled), + NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); signals[SIGNAL_VOLUME_CHANGED] = - g_signal_new ("volume_changed", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstMixerTrackClass, - volume_changed), - NULL, NULL, g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); + g_signal_new ("volume_changed", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstMixerTrackClass, + volume_changed), + NULL, NULL, g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); object_klass->dispose = gst_mixer_track_dispose; } static void -gst_mixer_track_init (GstMixerTrack *channel) +gst_mixer_track_init (GstMixerTrack * channel) { channel->label = NULL; channel->min_volume = channel->max_volume = 0; @@ -110,7 +110,7 @@ gst_mixer_track_init (GstMixerTrack *channel) } static void -gst_mixer_track_dispose (GObject *object) +gst_mixer_track_dispose (GObject * object) { GstMixerTrack *channel = GST_MIXER_TRACK (object); diff --git a/gst-libs/gst/mixer/mixertrack.h b/gst-libs/gst/mixer/mixertrack.h index 0e05d9cba0..872b090442 100644 --- a/gst-libs/gst/mixer/mixertrack.h +++ b/gst-libs/gst/mixer/mixertrack.h @@ -25,7 +25,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_MIXER_TRACK \ (gst_mixer_track_get_type ()) #define GST_MIXER_TRACK(obj) \ @@ -38,7 +37,6 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MIXER_TRACK)) #define GST_IS_MIXER_TRACK_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MIXER_TRACK)) - /* * Naming: * @@ -54,45 +52,41 @@ G_BEGIN_DECLS * mixer, which means that setting this track will change * the hearable volume on any output. */ - -typedef enum { - GST_MIXER_TRACK_INPUT = (1<<0), - GST_MIXER_TRACK_OUTPUT = (1<<1), - GST_MIXER_TRACK_MUTE = (1<<2), - GST_MIXER_TRACK_RECORD = (1<<3), - GST_MIXER_TRACK_MASTER = (1<<4), - GST_MIXER_TRACK_SOFTWARE = (1<<5) + typedef enum +{ + GST_MIXER_TRACK_INPUT = (1 << 0), + GST_MIXER_TRACK_OUTPUT = (1 << 1), + GST_MIXER_TRACK_MUTE = (1 << 2), + GST_MIXER_TRACK_RECORD = (1 << 3), + GST_MIXER_TRACK_MASTER = (1 << 4), + GST_MIXER_TRACK_SOFTWARE = (1 << 5) } GstMixerTrackFlags; #define GST_MIXER_TRACK_HAS_FLAG(channel, flag) \ ((channel)->flags & flag) -typedef struct _GstMixerTrack { - GObject parent; +typedef struct _GstMixerTrack +{ + GObject parent; - gchar *label; + gchar *label; GstMixerTrackFlags flags; - gint num_channels, - min_volume, - max_volume; + gint num_channels, min_volume, max_volume; } GstMixerTrack; -typedef struct _GstMixerTrackClass { +typedef struct _GstMixerTrackClass +{ GObjectClass parent; /* signals */ - void (* mute_toggled) (GstMixerTrack *channel, - gboolean mute); - void (* record_toggled) (GstMixerTrack *channel, - gboolean record); - void (* volume_changed) (GstMixerTrack *channel, - gint *volumes); + void (*mute_toggled) (GstMixerTrack * channel, gboolean mute); + void (*record_toggled) (GstMixerTrack * channel, gboolean record); + void (*volume_changed) (GstMixerTrack * channel, gint * volumes); gpointer _gst_reserved[GST_PADDING]; } GstMixerTrackClass; -GType gst_mixer_track_get_type (void); +GType gst_mixer_track_get_type (void); G_END_DECLS - #endif /* __GST_MIXER_TRACK_H__ */ diff --git a/gst-libs/gst/navigation/navigation.c b/gst-libs/gst/navigation/navigation.c index e3333cbad3..35ae2ba5fe 100644 --- a/gst-libs/gst/navigation/navigation.c +++ b/gst-libs/gst/navigation/navigation.c @@ -25,7 +25,7 @@ #include -static void gst_navigation_class_init (GstNavigationInterface *iface); +static void gst_navigation_class_init (GstNavigationInterface * iface); GType gst_navigation_get_type (void) @@ -46,22 +46,21 @@ gst_navigation_get_type (void) }; gst_navigation_type = g_type_register_static (G_TYPE_INTERFACE, - "GstNavigation", - &gst_navigation_info, 0); + "GstNavigation", &gst_navigation_info, 0); } return gst_navigation_type; } static void -gst_navigation_class_init (GstNavigationInterface *iface) +gst_navigation_class_init (GstNavigationInterface * iface) { /* default virtual functions */ iface->send_event = NULL; } void -gst_navigation_send_event (GstNavigation *navigation, GstStructure *structure) +gst_navigation_send_event (GstNavigation * navigation, GstStructure * structure) { GstNavigationInterface *iface = GST_NAVIGATION_GET_IFACE (navigation); @@ -71,25 +70,20 @@ gst_navigation_send_event (GstNavigation *navigation, GstStructure *structure) } void -gst_navigation_send_key_event (GstNavigation *navigation, const char *event, - const char *key) +gst_navigation_send_key_event (GstNavigation * navigation, const char *event, + const char *key) { - gst_navigation_send_event (navigation, gst_structure_new ( - "application/x-gst-navigation", - "event", G_TYPE_STRING, event, - "key", G_TYPE_STRING, key, NULL)); + gst_navigation_send_event (navigation, + gst_structure_new ("application/x-gst-navigation", "event", G_TYPE_STRING, + event, "key", G_TYPE_STRING, key, NULL)); } void -gst_navigation_send_mouse_event (GstNavigation *navigation, const char *event, - int button, double x, double y) +gst_navigation_send_mouse_event (GstNavigation * navigation, const char *event, + int button, double x, double y) { - gst_navigation_send_event (navigation, gst_structure_new ( - "application/x-gst-navigation", - "event", G_TYPE_STRING, event, - "button", G_TYPE_INT, button, - "pointer_x", G_TYPE_DOUBLE, x, - "pointer_y", G_TYPE_DOUBLE, y, NULL)); + gst_navigation_send_event (navigation, + gst_structure_new ("application/x-gst-navigation", "event", G_TYPE_STRING, + event, "button", G_TYPE_INT, button, "pointer_x", G_TYPE_DOUBLE, x, + "pointer_y", G_TYPE_DOUBLE, y, NULL)); } - - diff --git a/gst-libs/gst/navigation/navigation.h b/gst-libs/gst/navigation/navigation.h index 5ccaf74898..342ff9af9c 100644 --- a/gst-libs/gst/navigation/navigation.h +++ b/gst-libs/gst/navigation/navigation.h @@ -26,7 +26,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_NAVIGATION \ (gst_navigation_get_type ()) #define GST_NAVIGATION(obj) \ @@ -35,28 +34,28 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_NAVIGATION)) #define GST_NAVIGATION_GET_IFACE(obj) \ (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GST_TYPE_NAVIGATION, GstNavigationInterface)) - typedef struct _GstNavigation GstNavigation; -typedef struct _GstNavigationInterface { +typedef struct _GstNavigationInterface +{ GTypeInterface g_iface; /* virtual functions */ - void (*send_event) (GstNavigation *navigation, GstStructure *structure); - + void (*send_event) (GstNavigation * navigation, GstStructure * structure); + gpointer _gst_reserved[GST_PADDING]; } GstNavigationInterface; -GType gst_navigation_get_type (void); +GType gst_navigation_get_type (void); /* virtual class function wrappers */ -void gst_navigation_send_event (GstNavigation *navigation, GstStructure *structure); +void gst_navigation_send_event (GstNavigation * navigation, + GstStructure * structure); -void gst_navigation_send_key_event (GstNavigation *navigation, - const char *event, const char *key); -void gst_navigation_send_mouse_event (GstNavigation *navigation, - const char *event, int button, double x, double y); +void gst_navigation_send_key_event (GstNavigation * navigation, + const char *event, const char *key); +void gst_navigation_send_mouse_event (GstNavigation * navigation, + const char *event, int button, double x, double y); G_END_DECLS - #endif /* __GST_NAVIGATION_H__ */ diff --git a/gst-libs/gst/play/play.c b/gst-libs/gst/play/play.c index f46fbabc7d..97ce306091 100644 --- a/gst-libs/gst/play/play.c +++ b/gst-libs/gst/play/play.c @@ -16,7 +16,7 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ - + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -34,22 +34,23 @@ enum LAST_SIGNAL }; -struct _GstPlayPrivate { +struct _GstPlayPrivate +{ char *location; - + GHashTable *elements; - + gint64 time_nanos; gint64 length_nanos; - + gint get_length_attempt; - - gint tick_unblock_remaining; /* how many msecs left - to unblock due to seeking */ + + gint tick_unblock_remaining; /* how many msecs left + to unblock due to seeking */ guint tick_id; guint length_id; - + gulong handoff_hid; /* error/debug handling */ @@ -67,13 +68,16 @@ static GstPipelineClass *parent_class = NULL; /* */ /* ======================================================= */ -static GstCaps * gst_play_video_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data); -static GstCaps * gst_play_audio_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data); +static GstCaps *gst_play_video_fixate (GstPad * pad, const GstCaps * caps, + gpointer user_data); +static GstCaps *gst_play_audio_fixate (GstPad * pad, const GstCaps * caps, + gpointer user_data); static GQuark gst_play_error_quark (void) { static GQuark quark = 0; + if (quark == 0) quark = g_quark_from_static_string ("gst-play-error-quark"); return quark; @@ -81,7 +85,7 @@ gst_play_error_quark (void) /* General GError creation */ static void -gst_play_error_create (GError ** error, const gchar *message) +gst_play_error_create (GError ** error, const gchar * message) { /* check if caller wanted an error reported */ if (error == NULL) @@ -95,15 +99,14 @@ gst_play_error_create (GError ** error, const gchar *message) /* FIXME: what if multiple elements could have been used and they're all * missing ? varargs ? */ static void -gst_play_error_plugin (const gchar *element, GError ** error) +gst_play_error_plugin (const gchar * element, GError ** error) { gchar *message; message = g_strdup_printf ("The %s element could not be found. " - "This element is essential for playback. " - "Please install the right plug-in and verify " - "that it works by running 'gst-inspect %s'", - element, element); + "This element is essential for playback. " + "Please install the right plug-in and verify " + "that it works by running 'gst-inspect %s'", element, element); gst_play_error_create (error, message); g_free (message); return; @@ -127,263 +130,273 @@ G_STMT_START { \ static gboolean -gst_play_pipeline_setup (GstPlay *play, GError **error) +gst_play_pipeline_setup (GstPlay * play, GError ** error) { /* Threads */ GstElement *work_thread, *audio_thread, *video_thread; + /* Main Thread elements */ GstElement *source, *autoplugger, *audioconvert, *volume, *tee, *identity; GstElement *identity_cs; + /* Visualization bin */ GstElement *vis_bin, *vis_queue, *vis_element, *vis_cs; + /* Video Thread elements */ GstElement *video_queue, *video_switch, *video_cs, *video_balance; GstElement *balance_cs, *video_scaler, *video_sink; + /* Audio Thread elements */ GstElement *audio_queue, *audio_sink; + /* Some useful pads */ GstPad *tee_pad1, *tee_pad2; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); - + /* Creating main thread and its elements */ { - GST_PLAY_MAKE_OR_ERROR (work_thread, "thread", "work_thread", error); - g_hash_table_insert (play->priv->elements, "work_thread", work_thread); - gst_bin_add (GST_BIN (play), work_thread); + GST_PLAY_MAKE_OR_ERROR (work_thread, "thread", "work_thread", error); + g_hash_table_insert (play->priv->elements, "work_thread", work_thread); + gst_bin_add (GST_BIN (play), work_thread); - /* Placeholder for datasrc */ - GST_PLAY_MAKE_OR_ERROR (source, "fakesrc", "source", error); - g_hash_table_insert (play->priv->elements, "source", source); - - /* Autoplugger */ - GST_PLAY_MAKE_OR_ERROR (autoplugger, "spider", "autoplugger", error); - g_hash_table_insert (play->priv->elements, "autoplugger", autoplugger); - - /* Make sure we convert audio to the needed format */ - GST_PLAY_MAKE_OR_ERROR (audioconvert, "audioconvert", "audioconvert", error); - g_hash_table_insert (play->priv->elements, "audioconvert", audioconvert); - - /* Duplicate audio signal to audio sink and visualization thread */ - GST_PLAY_MAKE_OR_ERROR (tee, "tee", "tee", error); - tee_pad1 = gst_element_get_request_pad (tee, "src%d"); - tee_pad2 = gst_element_get_request_pad (tee, "src%d"); - g_hash_table_insert (play->priv->elements, "tee_pad1", tee_pad1); - g_hash_table_insert (play->priv->elements, "tee_pad2", tee_pad2); - g_hash_table_insert (play->priv->elements, "tee", tee); - - gst_bin_add_many (GST_BIN (work_thread), source, autoplugger, audioconvert, tee, NULL); - if (!gst_element_link_many (source, autoplugger, audioconvert, tee, NULL)) - GST_PLAY_ERROR_RETURN (error, "Could not link source thread elements"); - - /* identity ! colorspace ! switch */ - GST_PLAY_MAKE_OR_ERROR (identity, "identity", "identity", error); - g_hash_table_insert (play->priv->elements, "identity", identity); - - identity_cs = gst_element_factory_make ("ffcolorspace", "identity_cs"); - if (!GST_IS_ELEMENT (identity_cs)) { - identity_cs = gst_element_factory_make ("colorspace", "identity_cs"); - if (!GST_IS_ELEMENT (identity_cs)) - { - gst_play_error_plugin ("colorspace", error); - return FALSE; + /* Placeholder for datasrc */ + GST_PLAY_MAKE_OR_ERROR (source, "fakesrc", "source", error); + g_hash_table_insert (play->priv->elements, "source", source); + + /* Autoplugger */ + GST_PLAY_MAKE_OR_ERROR (autoplugger, "spider", "autoplugger", error); + g_hash_table_insert (play->priv->elements, "autoplugger", autoplugger); + + /* Make sure we convert audio to the needed format */ + GST_PLAY_MAKE_OR_ERROR (audioconvert, "audioconvert", "audioconvert", + error); + g_hash_table_insert (play->priv->elements, "audioconvert", audioconvert); + + /* Duplicate audio signal to audio sink and visualization thread */ + GST_PLAY_MAKE_OR_ERROR (tee, "tee", "tee", error); + tee_pad1 = gst_element_get_request_pad (tee, "src%d"); + tee_pad2 = gst_element_get_request_pad (tee, "src%d"); + g_hash_table_insert (play->priv->elements, "tee_pad1", tee_pad1); + g_hash_table_insert (play->priv->elements, "tee_pad2", tee_pad2); + g_hash_table_insert (play->priv->elements, "tee", tee); + + gst_bin_add_many (GST_BIN (work_thread), source, autoplugger, audioconvert, + tee, NULL); + if (!gst_element_link_many (source, autoplugger, audioconvert, tee, NULL)) + GST_PLAY_ERROR_RETURN (error, "Could not link source thread elements"); + + /* identity ! colorspace ! switch */ + GST_PLAY_MAKE_OR_ERROR (identity, "identity", "identity", error); + g_hash_table_insert (play->priv->elements, "identity", identity); + + identity_cs = gst_element_factory_make ("ffcolorspace", "identity_cs"); + if (!GST_IS_ELEMENT (identity_cs)) { + identity_cs = gst_element_factory_make ("colorspace", "identity_cs"); + if (!GST_IS_ELEMENT (identity_cs)) { + gst_play_error_plugin ("colorspace", error); + return FALSE; + } } + g_hash_table_insert (play->priv->elements, "identity_cs", identity_cs); + gst_bin_add_many (GST_BIN (work_thread), identity, identity_cs, NULL); + if (!gst_element_link_many (autoplugger, identity, identity_cs, NULL)) + GST_PLAY_ERROR_RETURN (error, "Could not link work thread elements"); } - g_hash_table_insert (play->priv->elements, "identity_cs", identity_cs); - gst_bin_add_many (GST_BIN (work_thread), identity, identity_cs, NULL); - if (!gst_element_link_many (autoplugger, identity, identity_cs, NULL)) - GST_PLAY_ERROR_RETURN (error, "Could not link work thread elements"); - } - + /* Visualization bin (note: it s not added to the pipeline yet) */ { - vis_bin = gst_bin_new ("vis_bin"); - if (!GST_IS_ELEMENT (vis_bin)) - { - gst_play_error_plugin ("bin", error); - return FALSE; - } - - g_hash_table_insert (play->priv->elements, "vis_bin", vis_bin); - - /* Buffer queue for video data */ - GST_PLAY_MAKE_OR_ERROR (vis_queue, "queue", "vis_queue", error); - g_hash_table_insert (play->priv->elements, "vis_queue", vis_queue); - - /* Visualization element placeholder */ - GST_PLAY_MAKE_OR_ERROR (vis_element, "identity", "vis_element", error); - g_hash_table_insert (play->priv->elements, "vis_element", vis_element); - - /* Colorspace conversion */ - vis_cs = gst_element_factory_make ("ffcolorspace", "vis_cs"); - if (!GST_IS_ELEMENT (vis_cs)) { - vis_cs = gst_element_factory_make ("colorspace", "vis_cs"); - if (!GST_IS_ELEMENT (vis_cs)) - { - gst_play_error_plugin ("colorspace", error); + vis_bin = gst_bin_new ("vis_bin"); + if (!GST_IS_ELEMENT (vis_bin)) { + gst_play_error_plugin ("bin", error); return FALSE; } - } - - g_hash_table_insert (play->priv->elements, "vis_cs", vis_cs); - - gst_bin_add_many (GST_BIN (vis_bin), vis_queue, vis_element, vis_cs, NULL); - if (!gst_element_link_many (vis_queue, vis_element, vis_cs, NULL)) - GST_PLAY_ERROR_RETURN (error, "Could not link visualisation thread elements"); - gst_element_add_ghost_pad (vis_bin, - gst_element_get_pad (vis_cs, "src"), "src"); + + g_hash_table_insert (play->priv->elements, "vis_bin", vis_bin); + + /* Buffer queue for video data */ + GST_PLAY_MAKE_OR_ERROR (vis_queue, "queue", "vis_queue", error); + g_hash_table_insert (play->priv->elements, "vis_queue", vis_queue); + + /* Visualization element placeholder */ + GST_PLAY_MAKE_OR_ERROR (vis_element, "identity", "vis_element", error); + g_hash_table_insert (play->priv->elements, "vis_element", vis_element); + + /* Colorspace conversion */ + vis_cs = gst_element_factory_make ("ffcolorspace", "vis_cs"); + if (!GST_IS_ELEMENT (vis_cs)) { + vis_cs = gst_element_factory_make ("colorspace", "vis_cs"); + if (!GST_IS_ELEMENT (vis_cs)) { + gst_play_error_plugin ("colorspace", error); + return FALSE; + } + } + + g_hash_table_insert (play->priv->elements, "vis_cs", vis_cs); + + gst_bin_add_many (GST_BIN (vis_bin), vis_queue, vis_element, vis_cs, NULL); + if (!gst_element_link_many (vis_queue, vis_element, vis_cs, NULL)) + GST_PLAY_ERROR_RETURN (error, + "Could not link visualisation thread elements"); + gst_element_add_ghost_pad (vis_bin, gst_element_get_pad (vis_cs, "src"), + "src"); } /* Creating our video output bin */ { - GST_PLAY_MAKE_OR_ERROR (video_thread, "thread", "video_thread", error); - g_hash_table_insert (play->priv->elements, "video_thread", video_thread); - gst_bin_add (GST_BIN (work_thread), video_thread); - - /* Buffer queue for video data */ - GST_PLAY_MAKE_OR_ERROR (video_queue, "queue", "video_queue", error); - g_hash_table_insert (play->priv->elements, "video_queue", video_queue); - - GST_PLAY_MAKE_OR_ERROR (video_switch, "switch", "video_switch", error); - g_hash_table_insert (play->priv->elements, "video_switch", video_switch); - - /* Colorspace conversion */ - video_cs = gst_element_factory_make ("ffcolorspace", "video_cs"); - if (!GST_IS_ELEMENT (video_cs)) { - video_cs = gst_element_factory_make ("colorspace", "video_cs"); - if (!GST_IS_ELEMENT (video_cs)) - { - gst_play_error_plugin ("colorspace", error); - return FALSE; + GST_PLAY_MAKE_OR_ERROR (video_thread, "thread", "video_thread", error); + g_hash_table_insert (play->priv->elements, "video_thread", video_thread); + gst_bin_add (GST_BIN (work_thread), video_thread); + + /* Buffer queue for video data */ + GST_PLAY_MAKE_OR_ERROR (video_queue, "queue", "video_queue", error); + g_hash_table_insert (play->priv->elements, "video_queue", video_queue); + + GST_PLAY_MAKE_OR_ERROR (video_switch, "switch", "video_switch", error); + g_hash_table_insert (play->priv->elements, "video_switch", video_switch); + + /* Colorspace conversion */ + video_cs = gst_element_factory_make ("ffcolorspace", "video_cs"); + if (!GST_IS_ELEMENT (video_cs)) { + video_cs = gst_element_factory_make ("colorspace", "video_cs"); + if (!GST_IS_ELEMENT (video_cs)) { + gst_play_error_plugin ("colorspace", error); + return FALSE; + } } - } - g_hash_table_insert (play->priv->elements, "video_cs", video_cs); - - /* Software colorbalance */ - GST_PLAY_MAKE_OR_ERROR (video_balance, "videobalance", "video_balance", error); - g_hash_table_insert (play->priv->elements, "video_balance", video_balance); - - /* Colorspace conversion */ - balance_cs = gst_element_factory_make ("ffcolorspace", "balance_cs"); - if (!GST_IS_ELEMENT (balance_cs)) { - balance_cs = gst_element_factory_make ("colorspace", "balance_cs"); - if (!GST_IS_ELEMENT (balance_cs)) - { - gst_play_error_plugin ("colorspace", error); - return FALSE; + g_hash_table_insert (play->priv->elements, "video_cs", video_cs); + + /* Software colorbalance */ + GST_PLAY_MAKE_OR_ERROR (video_balance, "videobalance", "video_balance", + error); + g_hash_table_insert (play->priv->elements, "video_balance", video_balance); + + /* Colorspace conversion */ + balance_cs = gst_element_factory_make ("ffcolorspace", "balance_cs"); + if (!GST_IS_ELEMENT (balance_cs)) { + balance_cs = gst_element_factory_make ("colorspace", "balance_cs"); + if (!GST_IS_ELEMENT (balance_cs)) { + gst_play_error_plugin ("colorspace", error); + return FALSE; + } } - } - g_hash_table_insert (play->priv->elements, "balance_cs", balance_cs); - - /* Software scaling of video stream */ - GST_PLAY_MAKE_OR_ERROR (video_scaler, "videoscale", "video_scaler", error); - g_hash_table_insert (play->priv->elements, "video_scaler", video_scaler); - g_signal_connect (gst_element_get_pad(video_scaler, "src"), "fixate", - G_CALLBACK (gst_play_video_fixate), play); - - /* Placeholder for future video sink bin */ - GST_PLAY_MAKE_OR_ERROR (video_sink, "fakesink", "video_sink", error); - g_hash_table_insert (play->priv->elements, "video_sink", video_sink); - - gst_bin_add_many (GST_BIN (video_thread), video_queue, video_switch, video_cs, - video_balance, balance_cs, video_scaler, video_sink, NULL); - /* break down linking so we can figure out what might be failing */ - if (!gst_element_link (video_queue, video_switch)) - GST_PLAY_ERROR_RETURN (error, "Could not link video output thread (queue and switch)"); - if (!gst_element_link (video_switch, video_cs)) - GST_PLAY_ERROR_RETURN (error, "Could not link video output thread (switch and cs)"); - if (!gst_element_link (video_cs, video_balance)) - GST_PLAY_ERROR_RETURN (error, "Could not link video output thread (cs and balance)"); - if (!gst_element_link (video_balance, balance_cs)) - GST_PLAY_ERROR_RETURN (error, "Could not link video output thread (balance and balance_cs)"); - if (!gst_element_link (balance_cs, video_scaler)) - GST_PLAY_ERROR_RETURN (error, "Could not link video output thread (balance_cs and scaler)"); - if (!gst_element_link (video_scaler, video_sink)) - GST_PLAY_ERROR_RETURN (error, "Could not link video output thread (balance_cs and scaler)"); - gst_element_add_ghost_pad (video_thread, - gst_element_get_pad (video_queue, "sink"), - "sink"); - if (!gst_element_link (identity_cs, video_thread)) - GST_PLAY_ERROR_RETURN (error, "Could not link video output thread elements"); + g_hash_table_insert (play->priv->elements, "balance_cs", balance_cs); + + /* Software scaling of video stream */ + GST_PLAY_MAKE_OR_ERROR (video_scaler, "videoscale", "video_scaler", error); + g_hash_table_insert (play->priv->elements, "video_scaler", video_scaler); + g_signal_connect (gst_element_get_pad (video_scaler, "src"), "fixate", + G_CALLBACK (gst_play_video_fixate), play); + + /* Placeholder for future video sink bin */ + GST_PLAY_MAKE_OR_ERROR (video_sink, "fakesink", "video_sink", error); + g_hash_table_insert (play->priv->elements, "video_sink", video_sink); + + gst_bin_add_many (GST_BIN (video_thread), video_queue, video_switch, + video_cs, video_balance, balance_cs, video_scaler, video_sink, NULL); + /* break down linking so we can figure out what might be failing */ + if (!gst_element_link (video_queue, video_switch)) + GST_PLAY_ERROR_RETURN (error, + "Could not link video output thread (queue and switch)"); + if (!gst_element_link (video_switch, video_cs)) + GST_PLAY_ERROR_RETURN (error, + "Could not link video output thread (switch and cs)"); + if (!gst_element_link (video_cs, video_balance)) + GST_PLAY_ERROR_RETURN (error, + "Could not link video output thread (cs and balance)"); + if (!gst_element_link (video_balance, balance_cs)) + GST_PLAY_ERROR_RETURN (error, + "Could not link video output thread (balance and balance_cs)"); + if (!gst_element_link (balance_cs, video_scaler)) + GST_PLAY_ERROR_RETURN (error, + "Could not link video output thread (balance_cs and scaler)"); + if (!gst_element_link (video_scaler, video_sink)) + GST_PLAY_ERROR_RETURN (error, + "Could not link video output thread (balance_cs and scaler)"); + gst_element_add_ghost_pad (video_thread, gst_element_get_pad (video_queue, + "sink"), "sink"); + if (!gst_element_link (identity_cs, video_thread)) + GST_PLAY_ERROR_RETURN (error, + "Could not link video output thread elements"); } /* Creating our audio output bin { queue ! fakesink } */ { - GST_PLAY_MAKE_OR_ERROR (audio_thread, "thread", "audio_thread", error); - g_hash_table_insert (play->priv->elements, "audio_thread", audio_thread); - gst_bin_add (GST_BIN (work_thread), audio_thread); - - /* Buffer queue for our audio thread */ - GST_PLAY_MAKE_OR_ERROR (audio_queue, "queue", "audio_queue", error); - g_hash_table_insert (play->priv->elements, "audio_queue", audio_queue); - - /* Volume control */ - GST_PLAY_MAKE_OR_ERROR (volume, "volume", "volume", error); - g_hash_table_insert (play->priv->elements, "volume", volume); - g_signal_connect (gst_element_get_pad(volume, "src"), "fixate", - G_CALLBACK (gst_play_audio_fixate), play); - - /* Placeholder for future audio sink bin */ - GST_PLAY_MAKE_OR_ERROR (audio_sink, "fakesink", "audio_sink", error); - g_hash_table_insert (play->priv->elements, "audio_sink", audio_sink); - - gst_bin_add_many (GST_BIN (audio_thread), audio_queue, volume, audio_sink, NULL); - if (!gst_element_link_many (audio_queue, volume, audio_sink, NULL)) - GST_PLAY_ERROR_RETURN (error, "Could not link audio output thread elements"); - gst_element_add_ghost_pad (audio_thread, - gst_element_get_pad (audio_queue, "sink"), - "sink"); - gst_pad_link (tee_pad2, gst_element_get_pad (audio_queue, "sink")); + GST_PLAY_MAKE_OR_ERROR (audio_thread, "thread", "audio_thread", error); + g_hash_table_insert (play->priv->elements, "audio_thread", audio_thread); + gst_bin_add (GST_BIN (work_thread), audio_thread); + + /* Buffer queue for our audio thread */ + GST_PLAY_MAKE_OR_ERROR (audio_queue, "queue", "audio_queue", error); + g_hash_table_insert (play->priv->elements, "audio_queue", audio_queue); + + /* Volume control */ + GST_PLAY_MAKE_OR_ERROR (volume, "volume", "volume", error); + g_hash_table_insert (play->priv->elements, "volume", volume); + g_signal_connect (gst_element_get_pad (volume, "src"), "fixate", + G_CALLBACK (gst_play_audio_fixate), play); + + /* Placeholder for future audio sink bin */ + GST_PLAY_MAKE_OR_ERROR (audio_sink, "fakesink", "audio_sink", error); + g_hash_table_insert (play->priv->elements, "audio_sink", audio_sink); + + gst_bin_add_many (GST_BIN (audio_thread), audio_queue, volume, audio_sink, + NULL); + if (!gst_element_link_many (audio_queue, volume, audio_sink, NULL)) + GST_PLAY_ERROR_RETURN (error, + "Could not link audio output thread elements"); + gst_element_add_ghost_pad (audio_thread, gst_element_get_pad (audio_queue, + "sink"), "sink"); + gst_pad_link (tee_pad2, gst_element_get_pad (audio_queue, "sink")); } - + return TRUE; } static void -gst_play_have_video_size (GstElement *element, gint width, - gint height, GstPlay *play) +gst_play_have_video_size (GstElement * element, gint width, + gint height, GstPlay * play) { g_return_if_fail (play != NULL); g_return_if_fail (GST_IS_PLAY (play)); g_signal_emit (G_OBJECT (play), gst_play_signals[HAVE_VIDEO_SIZE], - 0, width, height); + 0, width, height); } static gboolean -gst_play_tick_callback (GstPlay *play) +gst_play_tick_callback (GstPlay * play) { GstFormat format = GST_FORMAT_TIME; gboolean q = FALSE; GstElement *audio_sink_element = NULL; - + g_return_val_if_fail (play != NULL, FALSE); /* just return without updating the UI when we are in the middle of seeking */ - if (play->priv->tick_unblock_remaining > 0) - { + if (play->priv->tick_unblock_remaining > 0) { play->priv->tick_unblock_remaining -= TICK_INTERVAL_MSEC; return TRUE; } - + if (!GST_IS_PLAY (play)) { play->priv->tick_id = 0; return FALSE; } - + audio_sink_element = g_hash_table_lookup (play->priv->elements, - "audio_sink_element"); - + "audio_sink_element"); + if (!GST_IS_ELEMENT (audio_sink_element)) { play->priv->tick_id = 0; return FALSE; } - + q = gst_element_query (audio_sink_element, GST_QUERY_POSITION, &format, - &(play->priv->time_nanos)); - + &(play->priv->time_nanos)); + if (q) g_signal_emit (G_OBJECT (play), gst_play_signals[TIME_TICK], - 0,play->priv->time_nanos); - + 0, play->priv->time_nanos); + if (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING) return TRUE; else { @@ -393,63 +406,63 @@ gst_play_tick_callback (GstPlay *play) } static gboolean -gst_play_get_length_callback (GstPlay *play) +gst_play_get_length_callback (GstPlay * play) { GstElement *audio_sink_element, *video_sink_element; GstFormat format = GST_FORMAT_TIME; gint64 value; gboolean q = FALSE; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); - + /* We try to get length from all real sink elements */ audio_sink_element = g_hash_table_lookup (play->priv->elements, - "audio_sink_element"); + "audio_sink_element"); video_sink_element = g_hash_table_lookup (play->priv->elements, - "video_sink_element"); + "video_sink_element"); if (!GST_IS_ELEMENT (audio_sink_element) && !GST_IS_ELEMENT (video_sink_element)) { play->priv->length_id = 0; return FALSE; } - + /* Audio first and then Video */ if (GST_IS_ELEMENT (audio_sink_element)) q = gst_element_query (audio_sink_element, GST_QUERY_TOTAL, &format, - &value); - if ( (!q) && (GST_IS_ELEMENT (video_sink_element)) ) + &value); + if ((!q) && (GST_IS_ELEMENT (video_sink_element))) q = gst_element_query (video_sink_element, GST_QUERY_TOTAL, &format, - &value); - + &value); + if (q) { play->priv->length_nanos = value; g_signal_emit (G_OBJECT (play), gst_play_signals[STREAM_LENGTH], - 0,play->priv->length_nanos); + 0, play->priv->length_nanos); play->priv->length_id = 0; return FALSE; } - + play->priv->get_length_attempt++; - + /* We try 16 times */ if (play->priv->get_length_attempt > 15) { play->priv->length_id = 0; return FALSE; - } - else + } else return TRUE; } static GstCaps * -gst_play_video_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data) +gst_play_video_fixate (GstPad * pad, const GstCaps * caps, gpointer user_data) { GstStructure *structure; GstCaps *newcaps; GST_DEBUG ("video fixate %p %" GST_PTR_FORMAT, pad, caps); - if (gst_caps_get_size (caps) > 1) return NULL; + if (gst_caps_get_size (caps) > 1) + return NULL; newcaps = gst_caps_copy (caps); structure = gst_caps_get_structure (newcaps, 0); @@ -461,7 +474,7 @@ gst_play_video_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data) return newcaps; } if (gst_caps_structure_fixate_field_nearest_double (structure, "framerate", - 30.0)) { + 30.0)) { return newcaps; } @@ -471,15 +484,16 @@ gst_play_video_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data) } static GstCaps * -gst_play_audio_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data) +gst_play_audio_fixate (GstPad * pad, const GstCaps * caps, gpointer user_data) { GstCaps *newcaps; GstStructure *structure; GST_DEBUG ("audio fixate %p %" GST_PTR_FORMAT, pad, caps); - newcaps = gst_caps_new_full (gst_structure_copy ( - gst_caps_get_structure (caps, 0)), NULL); + newcaps = + gst_caps_new_full (gst_structure_copy (gst_caps_get_structure (caps, 0)), + NULL); structure = gst_caps_get_structure (newcaps, 0); if (gst_caps_structure_fixate_field_nearest_int (structure, "rate", 44100)) { @@ -501,38 +515,35 @@ gst_play_audio_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data) } static void -gst_play_state_change (GstElement *element, GstElementState old, - GstElementState state) +gst_play_state_change (GstElement * element, GstElementState old, + GstElementState state) { GstPlay *play; - + g_return_if_fail (element != NULL); g_return_if_fail (GST_IS_PLAY (element)); - + play = GST_PLAY (element); - + if (state == GST_STATE_PLAYING) { if (play->priv->tick_id) { g_source_remove (play->priv->tick_id); play->priv->tick_id = 0; } - + play->priv->tick_id = g_timeout_add (TICK_INTERVAL_MSEC, - (GSourceFunc) gst_play_tick_callback, - play); - + (GSourceFunc) gst_play_tick_callback, play); + play->priv->get_length_attempt = 0; - + if (play->priv->length_id) { g_source_remove (play->priv->length_id); play->priv->length_id = 0; } - + play->priv->length_id = g_timeout_add (TICK_INTERVAL_MSEC, - (GSourceFunc) gst_play_get_length_callback, - play); - } - else { + (GSourceFunc) gst_play_get_length_callback, play); + } else { if (play->priv->tick_id) { g_source_remove (play->priv->tick_id); play->priv->tick_id = 0; @@ -542,13 +553,14 @@ gst_play_state_change (GstElement *element, GstElementState old, play->priv->length_id = 0; } } - + if (GST_ELEMENT_CLASS (parent_class)->state_change) GST_ELEMENT_CLASS (parent_class)->state_change (element, old, state); } static void -gst_play_identity_handoff (GstElement *identity, GstBuffer *buf, GstPlay *play) +gst_play_identity_handoff (GstElement * identity, GstBuffer * buf, + GstPlay * play) { g_signal_handler_disconnect (G_OBJECT (identity), play->priv->handoff_hid); play->priv->handoff_hid = 0; @@ -562,40 +574,40 @@ gst_play_identity_handoff (GstElement *identity, GstBuffer *buf, GstPlay *play) /* =========================================== */ static void -gst_play_dispose (GObject *object) +gst_play_dispose (GObject * object) { GstPlay *play; - + g_return_if_fail (object != NULL); g_return_if_fail (GST_IS_PLAY (object)); - + play = GST_PLAY (object); - + if (play->priv->length_id) { g_source_remove (play->priv->length_id); play->priv->length_id = 0; } - + if (play->priv->tick_id) { g_source_remove (play->priv->tick_id); play->priv->tick_id = 0; } - + if (play->priv->location) { g_free (play->priv->location); play->priv->location = NULL; } - + if (play->priv->elements) { g_hash_table_destroy (play->priv->elements); play->priv->elements = NULL; } - + G_OBJECT_CLASS (parent_class)->dispose (object); } static void -gst_play_init (GstPlay *play) +gst_play_init (GstPlay * play) { play->priv = g_new0 (GstPlayPrivate, 1); play->priv->location = NULL; @@ -604,41 +616,39 @@ gst_play_init (GstPlay *play) play->priv->elements = g_hash_table_new (g_str_hash, g_str_equal); play->priv->error = NULL; play->priv->debug = NULL; - - if (!gst_play_pipeline_setup (play, &play->priv->error)) - { + + if (!gst_play_pipeline_setup (play, &play->priv->error)) { g_warning ("libgstplay: failed initializing pipeline, error: %s", - play->priv->error->message); + play->priv->error->message); } } static void -gst_play_class_init (GstPlayClass *klass) +gst_play_class_init (GstPlayClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - + parent_class = g_type_class_peek_parent (klass); gobject_class->dispose = gst_play_dispose; element_class->state_change = gst_play_state_change; - + gst_play_signals[TIME_TICK] = - g_signal_new ("time-tick", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GstPlayClass, time_tick), NULL, NULL, - gst_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64); + g_signal_new ("time-tick", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GstPlayClass, time_tick), NULL, NULL, + gst_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64); gst_play_signals[STREAM_LENGTH] = - g_signal_new ("stream-length", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GstPlayClass, stream_length), NULL, NULL, - gst_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64); + g_signal_new ("stream-length", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GstPlayClass, stream_length), NULL, NULL, + gst_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64); gst_play_signals[HAVE_VIDEO_SIZE] = - g_signal_new ("have-video-size", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GstPlayClass, have_video_size), NULL, NULL, - gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, - G_TYPE_INT, G_TYPE_INT); + g_signal_new ("have-video-size", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GstPlayClass, have_video_size), NULL, NULL, + gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); } /* ======================================================= */ @@ -657,22 +667,22 @@ gst_play_class_init (GstPlayClass *klass) * Returns: TRUE if location was set successfully. */ gboolean -gst_play_set_location (GstPlay *play, const char *location) +gst_play_set_location (GstPlay * play, const char *location) { GstElement *work_thread, *source, *autoplugger; GstElement *audioconvert, *identity; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); - + if (play->priv->location) g_free (play->priv->location); - + play->priv->location = g_strdup (location); - + if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY) gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY); - + work_thread = g_hash_table_lookup (play->priv->elements, "work_thread"); if (!GST_IS_ELEMENT (work_thread)) return FALSE; @@ -688,34 +698,34 @@ gst_play_set_location (GstPlay *play, const char *location) identity = g_hash_table_lookup (play->priv->elements, "identity"); if (!GST_IS_ELEMENT (identity)) return FALSE; - + /* Spider can autoplugg only once. We remove the actual one and put a new autoplugger */ gst_element_unlink (source, autoplugger); gst_element_unlink (autoplugger, identity); gst_element_unlink (autoplugger, audioconvert); gst_bin_remove (GST_BIN (work_thread), autoplugger); - + autoplugger = gst_element_factory_make ("spider", "autoplugger"); if (!GST_IS_ELEMENT (autoplugger)) return FALSE; - + gst_bin_add (GST_BIN (work_thread), autoplugger); gst_element_link (source, autoplugger); gst_element_link (autoplugger, audioconvert); gst_element_link (autoplugger, identity); - + g_hash_table_replace (play->priv->elements, "autoplugger", autoplugger); - + /* FIXME: Why don't we have an interface to do that kind of stuff ? */ g_object_set (G_OBJECT (source), "location", play->priv->location, NULL); - + play->priv->length_nanos = 0LL; play->priv->time_nanos = 0LL; - + g_signal_emit (G_OBJECT (play), gst_play_signals[STREAM_LENGTH], 0, 0LL); g_signal_emit (G_OBJECT (play), gst_play_signals[TIME_TICK], 0, 0LL); - + return TRUE; } @@ -728,7 +738,7 @@ gst_play_set_location (GstPlay *play, const char *location) * Returns: a const #char* pointer to current location. */ char * -gst_play_get_location (GstPlay *play) +gst_play_get_location (GstPlay * play) { g_return_val_if_fail (play != NULL, NULL); g_return_val_if_fail (GST_IS_PLAY (play), NULL); @@ -746,52 +756,49 @@ gboolean gst_play_seek_to_time (GstPlay * play, gint64 time_nanos) { GstElement *audio_seek_element, *video_seek_element, *audio_sink_element; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); - + if (time_nanos < 0LL) time_nanos = 0LL; - + audio_seek_element = g_hash_table_lookup (play->priv->elements, - "audioconvert"); + "audioconvert"); audio_sink_element = g_hash_table_lookup (play->priv->elements, - "audio_sink_element"); - video_seek_element = g_hash_table_lookup (play->priv->elements, - "identity"); - + "audio_sink_element"); + video_seek_element = g_hash_table_lookup (play->priv->elements, "identity"); + if (GST_IS_ELEMENT (audio_seek_element) && GST_IS_ELEMENT (video_seek_element) && GST_IS_ELEMENT (audio_sink_element)) { gboolean s = FALSE; - + /* HACK: block tick signal from idler for 500 msec */ /* GStreamer can't currently report when seeking is finished, so we just chose a .5 sec default block time */ play->priv->tick_unblock_remaining = 500; - + s = gst_element_seek (video_seek_element, GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, - time_nanos); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, time_nanos); if (!s) { s = gst_element_seek (audio_seek_element, GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, - time_nanos); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, time_nanos); } - + if (s) { GstFormat format = GST_FORMAT_TIME; gboolean q = FALSE; - + q = gst_element_query (audio_sink_element, GST_QUERY_POSITION, &format, - &(play->priv->time_nanos)); + &(play->priv->time_nanos)); if (q) - g_signal_emit (G_OBJECT (play), gst_play_signals[TIME_TICK], - 0,play->priv->time_nanos); + g_signal_emit (G_OBJECT (play), gst_play_signals[TIME_TICK], + 0, play->priv->time_nanos); } } - + return TRUE; } @@ -805,17 +812,17 @@ gst_play_seek_to_time (GstPlay * play, gint64 time_nanos) * Returns: TRUE if call succeeded. */ gboolean -gst_play_set_data_src (GstPlay *play, GstElement *data_src) +gst_play_set_data_src (GstPlay * play, GstElement * data_src) { GstElement *work_thread, *old_data_src, *autoplugger; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); - + /* We bring back the pipeline to READY */ if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY) gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY); - + /* Getting needed objects */ work_thread = g_hash_table_lookup (play->priv->elements, "work_thread"); if (!GST_IS_ELEMENT (work_thread)) @@ -826,7 +833,7 @@ gst_play_set_data_src (GstPlay *play, GstElement *data_src) autoplugger = g_hash_table_lookup (play->priv->elements, "autoplugger"); if (!GST_IS_ELEMENT (autoplugger)) return FALSE; - + /* Unlinking old source from autoplugger, removing it from pipeline, adding the new one and connecting it to autoplugger FIXME: we should put a new autoplugger here as spider can autoplugg only once */ @@ -834,9 +841,9 @@ gst_play_set_data_src (GstPlay *play, GstElement *data_src) gst_bin_remove (GST_BIN (work_thread), old_data_src); gst_bin_add (GST_BIN (work_thread), data_src); gst_element_link (data_src, autoplugger); - + g_hash_table_replace (play->priv->elements, "source", data_src); - + return TRUE; } @@ -850,19 +857,19 @@ gst_play_set_data_src (GstPlay *play, GstElement *data_src) * Returns: TRUE if call succeeded. */ gboolean -gst_play_set_video_sink (GstPlay *play, GstElement *video_sink) +gst_play_set_video_sink (GstPlay * play, GstElement * video_sink) { GstElement *video_thread, *old_video_sink, *video_scaler, *video_sink_element; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); g_return_val_if_fail (video_sink != NULL, FALSE); g_return_val_if_fail (GST_IS_ELEMENT (video_sink), FALSE); - + /* We bring back the pipeline to READY */ if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY) gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY); - + /* Getting needed objects */ video_thread = g_hash_table_lookup (play->priv->elements, "video_thread"); if (!GST_IS_ELEMENT (video_thread)) @@ -873,30 +880,29 @@ gst_play_set_video_sink (GstPlay *play, GstElement *video_sink) video_scaler = g_hash_table_lookup (play->priv->elements, "video_scaler"); if (!GST_IS_ELEMENT (video_scaler)) return FALSE; - + /* Unlinking old video sink from video scaler, removing it from pipeline, adding the new one and linking it */ gst_element_unlink (video_scaler, old_video_sink); gst_bin_remove (GST_BIN (video_thread), old_video_sink); gst_bin_add (GST_BIN (video_thread), video_sink); gst_element_link (video_scaler, video_sink); - + g_hash_table_replace (play->priv->elements, "video_sink", video_sink); - + video_sink_element = gst_play_get_sink_element (play, video_sink, - GST_PLAY_SINK_TYPE_VIDEO); + GST_PLAY_SINK_TYPE_VIDEO); if (GST_IS_ELEMENT (video_sink_element)) { g_hash_table_replace (play->priv->elements, "video_sink_element", - video_sink_element); + video_sink_element); if (GST_IS_X_OVERLAY (video_sink_element)) { g_signal_connect (G_OBJECT (video_sink_element), - "desired_size_changed", - G_CALLBACK (gst_play_have_video_size), play); + "desired_size_changed", G_CALLBACK (gst_play_have_video_size), play); } - } - - gst_element_set_state (video_sink, GST_STATE (GST_ELEMENT(play))); - + } + + gst_element_set_state (video_sink, GST_STATE (GST_ELEMENT (play))); + return TRUE; } @@ -910,19 +916,19 @@ gst_play_set_video_sink (GstPlay *play, GstElement *video_sink) * Returns: TRUE if call succeeded. */ gboolean -gst_play_set_audio_sink (GstPlay *play, GstElement *audio_sink) +gst_play_set_audio_sink (GstPlay * play, GstElement * audio_sink) { GstElement *old_audio_sink, *audio_thread, *volume, *audio_sink_element; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); g_return_val_if_fail (audio_sink != NULL, FALSE); g_return_val_if_fail (GST_IS_ELEMENT (audio_sink), FALSE); - + /* We bring back the pipeline to READY */ if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY) gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY); - + /* Getting needed objects */ old_audio_sink = g_hash_table_lookup (play->priv->elements, "audio_sink"); if (!GST_IS_ELEMENT (old_audio_sink)) @@ -933,25 +939,25 @@ gst_play_set_audio_sink (GstPlay *play, GstElement *audio_sink) volume = g_hash_table_lookup (play->priv->elements, "volume"); if (!GST_IS_ELEMENT (volume)) return FALSE; - + /* Unlinking old audiosink, removing it from pipeline, putting the new one and linking it */ gst_element_unlink (volume, old_audio_sink); gst_bin_remove (GST_BIN (audio_thread), old_audio_sink); gst_bin_add (GST_BIN (audio_thread), audio_sink); gst_element_link (volume, audio_sink); - + g_hash_table_replace (play->priv->elements, "audio_sink", audio_sink); - + audio_sink_element = gst_play_get_sink_element (play, audio_sink, - GST_PLAY_SINK_TYPE_AUDIO); + GST_PLAY_SINK_TYPE_AUDIO); if (GST_IS_ELEMENT (audio_sink_element)) { g_hash_table_replace (play->priv->elements, "audio_sink_element", - audio_sink_element); + audio_sink_element); } - - gst_element_set_state (audio_sink, GST_STATE (GST_ELEMENT(play))); - + + gst_element_set_state (audio_sink, GST_STATE (GST_ELEMENT (play))); + return TRUE; } @@ -965,16 +971,16 @@ gst_play_set_audio_sink (GstPlay *play, GstElement *audio_sink) * Returns: TRUE if call succeeded. */ gboolean -gst_play_set_visualization (GstPlay *play, GstElement *vis_element) +gst_play_set_visualization (GstPlay * play, GstElement * vis_element) { GstElement *vis_bin, *vis_queue, *old_vis_element, *vis_cs; gboolean was_playing = FALSE; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); g_return_val_if_fail (vis_element != NULL, FALSE); g_return_val_if_fail (GST_IS_ELEMENT (vis_element), FALSE); - + /* Getting needed objects */ vis_bin = g_hash_table_lookup (play->priv->elements, "vis_bin"); if (!GST_IS_ELEMENT (vis_bin)) @@ -982,14 +988,13 @@ gst_play_set_visualization (GstPlay *play, GstElement *vis_element) vis_queue = g_hash_table_lookup (play->priv->elements, "vis_queue"); if (!GST_IS_ELEMENT (vis_queue)) return FALSE; - old_vis_element = g_hash_table_lookup (play->priv->elements, - "vis_element"); + old_vis_element = g_hash_table_lookup (play->priv->elements, "vis_element"); if (!GST_IS_ELEMENT (old_vis_element)) return FALSE; vis_cs = g_hash_table_lookup (play->priv->elements, "vis_cs"); if (!GST_IS_ELEMENT (vis_cs)) return FALSE; - + /* We bring back the pipeline to PAUSED */ if (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING) { gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED); @@ -1000,12 +1005,12 @@ gst_play_set_visualization (GstPlay *play, GstElement *vis_element) gst_bin_remove (GST_BIN (vis_bin), old_vis_element); gst_bin_add (GST_BIN (vis_bin), vis_element); gst_element_link_many (vis_queue, vis_element, vis_cs, NULL); - + g_hash_table_replace (play->priv->elements, "vis_element", vis_element); - + if (was_playing) gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING); - + return TRUE; } @@ -1025,13 +1030,13 @@ gst_play_connect_visualization (GstPlay * play, gboolean connect) GstElement *video_thread, *vis_queue, *vis_bin, *video_switch, *identity; GstPad *tee_pad1, *vis_queue_pad, *vis_bin_pad, *switch_pad; gboolean was_playing = FALSE; - + g_return_val_if_fail (play != NULL, FALSE); g_return_val_if_fail (GST_IS_PLAY (play), FALSE); - + /* Until i fix the switch */ return TRUE; - + /* Getting needed objects */ video_thread = g_hash_table_lookup (play->priv->elements, "video_thread"); if (!GST_IS_ELEMENT (video_thread)) @@ -1051,26 +1056,26 @@ gst_play_connect_visualization (GstPlay * play, gboolean connect) tee_pad1 = g_hash_table_lookup (play->priv->elements, "tee_pad1"); if (!GST_IS_PAD (tee_pad1)) return FALSE; - + vis_queue_pad = gst_element_get_pad (vis_queue, "sink"); - + /* Check if the vis element is in the pipeline. That means visualization is connected already */ if (gst_element_get_managing_bin (vis_bin)) { - + /* If we are supposed to connect then nothing to do we return */ if (connect) { return TRUE; } - + /* Disconnecting visualization */ - + /* We bring back the pipeline to PAUSED */ if (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING) { gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED); was_playing = TRUE; } - + /* Unlinking, removing */ gst_pad_unlink (tee_pad1, vis_queue_pad); vis_bin_pad = gst_element_get_pad (vis_bin, "src"); @@ -1079,26 +1084,24 @@ gst_play_connect_visualization (GstPlay * play, gboolean connect) gst_element_release_request_pad (video_switch, switch_pad); gst_object_ref (GST_OBJECT (vis_bin)); gst_bin_remove (GST_BIN (video_thread), vis_bin); - } - else { - + } else { + /* If we are supposed to disconnect then nothing to do we return */ if (!connect) { return TRUE; } - + /* Connecting visualization */ - + /* We bring back the pipeline to PAUSED */ if (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING) { gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED); was_playing = TRUE; } - + /* Adding, linking */ play->priv->handoff_hid = g_signal_connect (G_OBJECT (identity), - "handoff", - G_CALLBACK (gst_play_identity_handoff), play); + "handoff", G_CALLBACK (gst_play_identity_handoff), play); gst_bin_add (GST_BIN (video_thread), vis_bin); gst_pad_link (tee_pad1, vis_queue_pad); gst_element_link (vis_bin, video_switch); @@ -1106,7 +1109,7 @@ gst_play_connect_visualization (GstPlay * play, gboolean connect) if (was_playing) gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING); - + return TRUE; } @@ -1122,8 +1125,8 @@ gst_play_connect_visualization (GstPlay * play, gboolean connect) * Returns: the sink #GstElement of @element. */ GstElement * -gst_play_get_sink_element (GstPlay *play, - GstElement *element, GstPlaySinkType sink_type) +gst_play_get_sink_element (GstPlay * play, + GstElement * element, GstPlaySinkType sink_type) { GList *elements = NULL; const GList *pads = NULL; @@ -1152,91 +1155,86 @@ gst_play_get_sink_element (GstPlay *play, if (GST_IS_BIN (element)) { element = gst_play_get_sink_element (play, element, sink_type); if (GST_IS_ELEMENT (element)) - return element; - } - else { + return element; + } else { pads = gst_element_get_pad_list (element); has_src = FALSE; has_correct_type = FALSE; while (pads) { - /* check for src pad */ - if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == GST_PAD_SRC) { - has_src = TRUE; - break; - } - else { - /* If not a src pad checking caps */ - GstCaps *caps; - GstStructure *structure; - gboolean has_video_cap = FALSE; - gboolean has_audio_cap = FALSE; + /* check for src pad */ + if (GST_PAD_DIRECTION (GST_PAD (pads->data)) == GST_PAD_SRC) { + has_src = TRUE; + break; + } else { + /* If not a src pad checking caps */ + GstCaps *caps; + GstStructure *structure; + gboolean has_video_cap = FALSE; + gboolean has_audio_cap = FALSE; - caps = gst_pad_get_caps (GST_PAD (pads->data)); - structure = gst_caps_get_structure (caps, 0); - - if (strcmp (gst_structure_get_name (structure), - "audio/x-raw-int") == 0) { - has_audio_cap = TRUE; - } - - if (strcmp (gst_structure_get_name (structure), - "video/x-raw-yuv") == 0 || - strcmp (gst_structure_get_name (structure), - "video/x-raw-rgb") == 0) { - has_video_cap = TRUE; - } + caps = gst_pad_get_caps (GST_PAD (pads->data)); + structure = gst_caps_get_structure (caps, 0); + + if (strcmp (gst_structure_get_name (structure), + "audio/x-raw-int") == 0) { + has_audio_cap = TRUE; + } + + if (strcmp (gst_structure_get_name (structure), + "video/x-raw-yuv") == 0 || + strcmp (gst_structure_get_name (structure), + "video/x-raw-rgb") == 0) { + has_video_cap = TRUE; + } + + gst_caps_free (caps); + + switch (sink_type) { + case GST_PLAY_SINK_TYPE_AUDIO: + if (has_audio_cap) + has_correct_type = TRUE; + break; + case GST_PLAY_SINK_TYPE_VIDEO: + if (has_video_cap) + has_correct_type = TRUE; + break; + case GST_PLAY_SINK_TYPE_ANY: + if ((has_video_cap) || (has_audio_cap)) + has_correct_type = TRUE; + break; + default: + has_correct_type = FALSE; + } + } + + pads = g_list_next (pads); - gst_caps_free (caps); - - switch (sink_type) { - case GST_PLAY_SINK_TYPE_AUDIO: - if (has_audio_cap) - has_correct_type = TRUE; - break; - case GST_PLAY_SINK_TYPE_VIDEO: - if (has_video_cap) - has_correct_type = TRUE; - break; - case GST_PLAY_SINK_TYPE_ANY: - if ((has_video_cap) || (has_audio_cap)) - has_correct_type = TRUE; - break; - default: - has_correct_type = FALSE; - } - } - - pads = g_list_next (pads); - } - + if ((!has_src) && (has_correct_type)) - return element; + return element; } - + elements = g_list_next (elements); } - + /* we didn't find a sink element */ - + return NULL; } GstPlay * -gst_play_new (GError **error) +gst_play_new (GError ** error) { GstPlay *play = g_object_new (GST_TYPE_PLAY, NULL); - if (play->priv->error) - { - if (error) - { + if (play->priv->error) { + if (error) { *error = play->priv->error; play->priv->error = NULL; - } - else - { - g_warning ("Error creating GstPlay object.\n%s", play->priv->error->message); + } else { + g_warning ("Error creating GstPlay object.\n%s", + play->priv->error->message); g_error_free (play->priv->error); } } @@ -1267,9 +1265,9 @@ gst_play_get_type (void) (GInstanceInitFunc) gst_play_init, NULL }; - + play_type = g_type_register_static (GST_TYPE_PIPELINE, "GstPlay", - &play_info, 0); + &play_info, 0); } return play_type; diff --git a/gst-libs/gst/play/play.h b/gst-libs/gst/play/play.h index 8ccf827d79..36d8aca2f3 100644 --- a/gst-libs/gst/play/play.h +++ b/gst-libs/gst/play/play.h @@ -16,7 +16,7 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ - + #ifndef __GST_PLAY_H__ #define __GST_PLAY_H__ @@ -46,51 +46,43 @@ typedef enum typedef struct _GstPlay GstPlay; typedef struct _GstPlayClass GstPlayClass; typedef struct _GstPlayPrivate GstPlayPrivate; - + struct _GstPlay { GstPipeline pipeline; - + GstPlayPrivate *priv; - + gpointer _gst_reserved[GST_PADDING]; }; - + struct _GstPlayClass { GstPipelineClass parent_class; - - void (*time_tick) (GstPlay *play, gint64 time_nanos); - void (*stream_length) (GstPlay *play, gint64 length_nanos); - void (*have_video_size) (GstPlay *play, gint width, gint height); - + + void (*time_tick) (GstPlay * play, gint64 time_nanos); + void (*stream_length) (GstPlay * play, gint64 length_nanos); + void (*have_video_size) (GstPlay * play, gint width, gint height); + gpointer _gst_reserved[GST_PADDING]; }; -GType gst_play_get_type (void); -GstPlay * gst_play_new (GError **error); +GType gst_play_get_type (void); +GstPlay *gst_play_new (GError ** error); -gboolean gst_play_set_data_src (GstPlay *play, - GstElement *data_src); -gboolean gst_play_set_video_sink (GstPlay *play, - GstElement *video_sink); -gboolean gst_play_set_audio_sink (GstPlay *play, - GstElement *audio_sink); +gboolean gst_play_set_data_src (GstPlay * play, GstElement * data_src); +gboolean gst_play_set_video_sink (GstPlay * play, GstElement * video_sink); +gboolean gst_play_set_audio_sink (GstPlay * play, GstElement * audio_sink); -gboolean gst_play_set_visualization (GstPlay *play, - GstElement *element); -gboolean gst_play_connect_visualization (GstPlay *play, - gboolean connect); +gboolean gst_play_set_visualization (GstPlay * play, GstElement * element); +gboolean gst_play_connect_visualization (GstPlay * play, gboolean connect); -gboolean gst_play_set_location (GstPlay *play, - const char *location); -char * gst_play_get_location (GstPlay *play); +gboolean gst_play_set_location (GstPlay * play, const char *location); +char *gst_play_get_location (GstPlay * play); -gboolean gst_play_seek_to_time (GstPlay *play, - gint64 time_nanos); +gboolean gst_play_seek_to_time (GstPlay * play, gint64 time_nanos); -GstElement * gst_play_get_sink_element (GstPlay *play, - GstElement *element, - GstPlaySinkType sink_type); +GstElement *gst_play_get_sink_element (GstPlay * play, + GstElement * element, GstPlaySinkType sink_type); #endif /* __GST_PLAY_H__ */ diff --git a/gst-libs/gst/propertyprobe/propertyprobe.c b/gst-libs/gst/propertyprobe/propertyprobe.c index 85a989327a..05dd3f8fdc 100644 --- a/gst-libs/gst/propertyprobe/propertyprobe.c +++ b/gst-libs/gst/propertyprobe/propertyprobe.c @@ -27,12 +27,13 @@ #include "propertyprobe.h" -enum { +enum +{ SIGNAL_PROBE_NEEDED, LAST_SIGNAL }; -static void gst_property_probe_iface_init (GstPropertyProbeInterface *iface); +static void gst_property_probe_iface_init (GstPropertyProbeInterface * iface); static guint gst_property_probe_signals[LAST_SIGNAL] = { 0 }; @@ -56,30 +57,29 @@ gst_property_probe_get_type (void) gst_property_probe_type = g_type_register_static (G_TYPE_INTERFACE, - "GstPropertyProbe", - &gst_property_probe_info, 0); + "GstPropertyProbe", &gst_property_probe_info, 0); } return gst_property_probe_type; } static void -gst_property_probe_iface_init (GstPropertyProbeInterface *iface) +gst_property_probe_iface_init (GstPropertyProbeInterface * iface) { static gboolean initialized = FALSE; if (!initialized) { gst_property_probe_signals[SIGNAL_PROBE_NEEDED] = - g_signal_new ("probe-needed", G_TYPE_FROM_CLASS (iface), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstPropertyProbeInterface, probe_needed), - NULL, NULL, g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); + g_signal_new ("probe-needed", G_TYPE_FROM_CLASS (iface), + G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPropertyProbeInterface, + probe_needed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); initialized = TRUE; } /* default virtual functions */ iface->get_properties = NULL; - iface->get_values = NULL; + iface->get_values = NULL; } /** @@ -93,23 +93,22 @@ gst_property_probe_iface_init (GstPropertyProbeInterface *iface) */ const GList * -gst_property_probe_get_properties (GstPropertyProbe *probe) +gst_property_probe_get_properties (GstPropertyProbe * probe) { GstPropertyProbeInterface *iface; g_return_val_if_fail (probe != NULL, NULL); - + iface = GST_PROPERTY_PROBE_GET_IFACE (probe); - + if (iface->get_properties) return iface->get_properties (probe); - + return NULL; } const GParamSpec * -gst_property_probe_get_property (GstPropertyProbe *probe, - const gchar *name) +gst_property_probe_get_property (GstPropertyProbe * probe, const gchar * name) { const GList *pspecs = gst_property_probe_get_properties (probe); @@ -129,8 +128,8 @@ gst_property_probe_get_property (GstPropertyProbe *probe, } void -gst_property_probe_probe_property (GstPropertyProbe *probe, - const GParamSpec *pspec) +gst_property_probe_probe_property (GstPropertyProbe * probe, + const GParamSpec * pspec) { GstPropertyProbeInterface *iface; @@ -156,8 +155,8 @@ gst_property_probe_probe_property (GstPropertyProbe *probe, */ void -gst_property_probe_probe_property_name (GstPropertyProbe *probe, - const gchar *name) +gst_property_probe_probe_property_name (GstPropertyProbe * probe, + const gchar * name) { const GParamSpec *pspec; @@ -188,8 +187,8 @@ gst_property_probe_probe_property_name (GstPropertyProbe *probe, */ gboolean -gst_property_probe_needs_probe (GstPropertyProbe *probe, - const GParamSpec *pspec) +gst_property_probe_needs_probe (GstPropertyProbe * probe, + const GParamSpec * pspec) { GstPropertyProbeInterface *iface; @@ -215,8 +214,8 @@ gst_property_probe_needs_probe (GstPropertyProbe *probe, */ gboolean -gst_property_probe_needs_probe_name (GstPropertyProbe *probe, - const gchar *name) +gst_property_probe_needs_probe_name (GstPropertyProbe * probe, + const gchar * name) { const GParamSpec *pspec; @@ -242,10 +241,10 @@ gst_property_probe_needs_probe_name (GstPropertyProbe *probe, * * Returns: A list of valid values for the given property. */ - + GValueArray * -gst_property_probe_get_values (GstPropertyProbe *probe, - const GParamSpec *pspec) +gst_property_probe_get_values (GstPropertyProbe * probe, + const GParamSpec * pspec) { GstPropertyProbeInterface *iface; @@ -271,8 +270,8 @@ gst_property_probe_get_values (GstPropertyProbe *probe, */ GValueArray * -gst_property_probe_get_values_name (GstPropertyProbe *probe, - const gchar *name) +gst_property_probe_get_values_name (GstPropertyProbe * probe, + const gchar * name) { const GParamSpec *pspec; @@ -301,8 +300,8 @@ gst_property_probe_get_values_name (GstPropertyProbe *probe, */ GValueArray * -gst_property_probe_probe_and_get_values (GstPropertyProbe *probe, - const GParamSpec *pspec) +gst_property_probe_probe_and_get_values (GstPropertyProbe * probe, + const GParamSpec * pspec) { GstPropertyProbeInterface *iface; @@ -328,8 +327,8 @@ gst_property_probe_probe_and_get_values (GstPropertyProbe *probe, */ GValueArray * -gst_property_probe_probe_and_get_values_name (GstPropertyProbe *probe, - const gchar *name) +gst_property_probe_probe_and_get_values_name (GstPropertyProbe * probe, + const gchar * name) { const GParamSpec *pspec; diff --git a/gst-libs/gst/propertyprobe/propertyprobe.h b/gst-libs/gst/propertyprobe/propertyprobe.h index 695aa4daf8..39250a32a9 100644 --- a/gst-libs/gst/propertyprobe/propertyprobe.h +++ b/gst-libs/gst/propertyprobe/propertyprobe.h @@ -25,7 +25,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_PROPERTY_PROBE \ (gst_property_probe_get_type ()) #define GST_PROPERTY_PROBE(obj) \ @@ -34,64 +33,59 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PROPERTY_PROBE)) #define GST_PROPERTY_PROBE_GET_IFACE(obj) \ (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GST_TYPE_PROPERTY_PROBE, GstPropertyProbeInterface)) +typedef struct _GstPropertyProbe GstPropertyProbe; /* dummy typedef */ -typedef struct _GstPropertyProbe GstPropertyProbe; /* dummy typedef */ - -typedef struct _GstPropertyProbeInterface { +typedef struct _GstPropertyProbeInterface +{ GTypeInterface klass; /* signals */ - void (*probe_needed) (GstPropertyProbe *probe, - const GParamSpec *pspec); + void (*probe_needed) (GstPropertyProbe * probe, const GParamSpec * pspec); /* virtual functions */ - const GList * (*get_properties) (GstPropertyProbe *probe); - gboolean (*needs_probe) (GstPropertyProbe *probe, - guint prop_id, - const GParamSpec *pspec); - void (*probe_property) (GstPropertyProbe *probe, - guint prop_id, - const GParamSpec *pspec); - GValueArray * (*get_values) (GstPropertyProbe *probe, - guint prop_id, - const GParamSpec *pspec); + const GList *(*get_properties) (GstPropertyProbe * probe); + gboolean (*needs_probe) (GstPropertyProbe * probe, + guint prop_id, const GParamSpec * pspec); + void (*probe_property) (GstPropertyProbe * probe, + guint prop_id, const GParamSpec * pspec); + GValueArray *(*get_values) (GstPropertyProbe * probe, + guint prop_id, const GParamSpec * pspec); gpointer _gst_reserved[GST_PADDING]; } GstPropertyProbeInterface; -GType gst_property_probe_get_type (void); +GType gst_property_probe_get_type (void); /* virtual class function wrappers */ /* returns list of GParamSpecs */ -const GList * gst_property_probe_get_properties (GstPropertyProbe *probe); -const GParamSpec *gst_property_probe_get_property (GstPropertyProbe *probe, - const gchar *name); +const GList *gst_property_probe_get_properties (GstPropertyProbe * probe); +const GParamSpec *gst_property_probe_get_property (GstPropertyProbe * probe, + const gchar * name); /* probe one property */ -void gst_property_probe_probe_property (GstPropertyProbe *probe, - const GParamSpec *pspec); -void gst_property_probe_probe_property_name (GstPropertyProbe *probe, - const gchar *name); +void gst_property_probe_probe_property (GstPropertyProbe * probe, + const GParamSpec * pspec); +void gst_property_probe_probe_property_name (GstPropertyProbe * probe, + const gchar * name); /* do we need a probe? */ -gboolean gst_property_probe_needs_probe (GstPropertyProbe *probe, - const GParamSpec *pspec); -gboolean gst_property_probe_needs_probe_name (GstPropertyProbe *probe, - const gchar *name); +gboolean gst_property_probe_needs_probe (GstPropertyProbe * probe, + const GParamSpec * pspec); +gboolean gst_property_probe_needs_probe_name (GstPropertyProbe * probe, + const gchar * name); /* returns list of GValues */ -GValueArray * gst_property_probe_get_values (GstPropertyProbe *probe, - const GParamSpec *pspec); -GValueArray * gst_property_probe_get_values_name (GstPropertyProbe *probe, - const gchar *name); +GValueArray *gst_property_probe_get_values (GstPropertyProbe * probe, + const GParamSpec * pspec); +GValueArray *gst_property_probe_get_values_name (GstPropertyProbe * probe, + const gchar * name); /* sugar */ -GValueArray * gst_property_probe_probe_and_get_values (GstPropertyProbe *probe, - const GParamSpec *pspec); -GValueArray * gst_property_probe_probe_and_get_values_name (GstPropertyProbe *probe, - const gchar *name); +GValueArray *gst_property_probe_probe_and_get_values (GstPropertyProbe * probe, + const GParamSpec * pspec); +GValueArray *gst_property_probe_probe_and_get_values_name (GstPropertyProbe * + probe, const gchar * name); G_END_DECLS - #endif /* __GST_PROPERTY_PROBE_H__ */ diff --git a/gst-libs/gst/resample/dtof.c b/gst-libs/gst/resample/dtof.c index 7650453a28..835349273e 100644 --- a/gst-libs/gst/resample/dtof.c +++ b/gst-libs/gst/resample/dtof.c @@ -29,40 +29,46 @@ /*#include */ #include "private.h" -void conv_double_float_ref(double *dest, float *src, int n) +void +conv_double_float_ref (double *dest, float *src, int n) { - int i; - for(i=0;i>8)] + ints_low[(idx&0xff)]; - n-=1; - } - for(i=0;i>8)] + ints_low[(idx&0xff)]; - idx = (unsigned short)*src++; - *dest++ = ints_high[(idx>>8)] + ints_low[(idx&0xff)]; - } + if (!init) { + for (i = 0; i < 256; i++) { + ints_high[i] = 256.0 * ((i < 128) ? i : i - 256); + ints_low[i] = i; + } + init = 1; + } + + if (n & 1) { + idx = (unsigned short) *src++; + *dest++ = ints_high[(idx >> 8)] + ints_low[(idx & 0xff)]; + n -= 1; + } + for (i = 0; i < n; i += 2) { + idx = (unsigned short) *src++; + *dest++ = ints_high[(idx >> 8)] + ints_low[(idx & 0xff)]; + idx = (unsigned short) *src++; + *dest++ = ints_high[(idx >> 8)] + ints_low[(idx & 0xff)]; + } } #endif #ifdef short_to_double_unroll -void conv_double_short_unroll(double *dest, short *src, int n) +void +conv_double_short_unroll (double *dest, short *src, int n) { - if(n&1){ - *dest++ = *src++; - n--; - } - if(n&2){ - *dest++ = *src++; - *dest++ = *src++; - n-=2; - } - while(n>0){ - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - n-=4; - } + if (n & 1) { + *dest++ = *src++; + n--; + } + if (n & 2) { + *dest++ = *src++; + *dest++ = *src++; + n -= 2; + } + while (n > 0) { + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + n -= 4; + } } #endif -void conv_double_short_ref(double *dest, short *src, int n) +void +conv_double_short_ref (double *dest, short *src, int n) { - int i; - for(i=0;i32767.0)x=32767.0; - *dest++ = rint(x); - } + for (i = 0; i < n; i++) { + x = *src++; + if (x < -32768.0) + x = -32768.0; + if (x > 32767.0) + x = 32767.0; + *dest++ = rint (x); + } } /* #ifdef HAVE_CPU_PPC */ #if 0 -void conv_short_double_ppcasm(short *dest, double *src, int n) +void +conv_short_double_ppcasm (short *dest, double *src, int n) { - int tmp[2]; - double min = -32768.0; - double max = 32767.0; - double ftmp0, ftmp1; + int tmp[2]; + double min = -32768.0; + double max = 32767.0; + double ftmp0, ftmp1; - asm __volatile__( - "\taddic. %3,%3,-8\n" - "\taddic. %6,%6,-2\n" - "loop:\n" - "\tlfdu %0,8(%3)\n" - "\tfsub %1,%0,%4\n" - "\tfsel %0,%1,%0,%4\n" - "\tfsub %1,%0,%5\n" - "\tfsel %0,%1,%5,%0\n" - "\tfctiw %1,%0\n" - "\taddic. 5,5,-1\n" - "\tstfd %1,0(%2)\n" - "\tlhz 9,6(%2)\n" - "\tsthu 9,2(%6)\n" - "\tbne loop\n" - : "=&f" (ftmp0), "=&f" (ftmp1) - : "b" (tmp), "r" (src), "f" (min), "f" (max), "r" (dest) - : "r9", "r5" ); + asm __volatile__ ("\taddic. %3,%3,-8\n" + "\taddic. %6,%6,-2\n" + "loop:\n" + "\tlfdu %0,8(%3)\n" + "\tfsub %1,%0,%4\n" + "\tfsel %0,%1,%0,%4\n" + "\tfsub %1,%0,%5\n" + "\tfsel %0,%1,%5,%0\n" + "\tfctiw %1,%0\n" + "\taddic. 5,5,-1\n" + "\tstfd %1,0(%2)\n" + "\tlhz 9,6(%2)\n" + "\tsthu 9,2(%6)\n" "\tbne loop\n":"=&f" (ftmp0), "=&f" (ftmp1) + :"b" (tmp), "r" (src), "f" (min), "f" (max), "r" (dest) + :"r9", "r5"); } #endif -void conv_double_short_dstr(double *dest, short *src, int n, int dstr) +void +conv_double_short_dstr (double *dest, short *src, int n, int dstr) { - int i; - void *d = dest; - for(i=0;i32767.0)x=32767.0; - *dest++ = rint(x); - s += sstr; - } + for (i = 0; i < n; i++) { + x = *(double *) s; + if (x < -32768.0) + x = -32768.0; + if (x > 32767.0) + x = 32767.0; + *dest++ = rint (x); + s += sstr; + } } - diff --git a/gst-libs/gst/resample/functable.c b/gst-libs/gst/resample/functable.c index 75b81f366c..29ce041801 100644 --- a/gst-libs/gst/resample/functable.c +++ b/gst-libs/gst/resample/functable.c @@ -30,285 +30,293 @@ -double functable_sinc(void *p,double x) +double +functable_sinc (void *p, double x) { - if(x==0)return 1; - return sin(x)/x; + if (x == 0) + return 1; + return sin (x) / x; } -double functable_dsinc(void *p,double x) +double +functable_dsinc (void *p, double x) { - if(x==0)return 0; - return cos(x)/x - sin(x)/(x*x); + if (x == 0) + return 0; + return cos (x) / x - sin (x) / (x * x); } -double functable_window_boxcar(void *p,double x) +double +functable_window_boxcar (void *p, double x) { - if(x<-1 || x>1)return 0; - return 1; + if (x < -1 || x > 1) + return 0; + return 1; } -double functable_window_dboxcar(void *p,double x) +double +functable_window_dboxcar (void *p, double x) { - return 0; + return 0; } -double functable_window_std(void *p,double x) +double +functable_window_std (void *p, double x) { - if(x<-1 || x>1)return 0; - return (1-x*x)*(1-x*x); + if (x < -1 || x > 1) + return 0; + return (1 - x * x) * (1 - x * x); } -double functable_window_dstd(void *p,double x) +double +functable_window_dstd (void *p, double x) { - if(x<-1 || x>1)return 0; - return -4*x*(1-x*x); + if (x < -1 || x > 1) + return 0; + return -4 * x * (1 - x * x); } -void functable_init(functable_t *t) +void +functable_init (functable_t * t) { - int i; - double x; + int i; + double x; - t->fx = malloc(sizeof(double)*(t->len+1)); - t->fdx = malloc(sizeof(double)*(t->len+1)); + t->fx = malloc (sizeof (double) * (t->len + 1)); + t->fdx = malloc (sizeof (double) * (t->len + 1)); - t->invoffset = 1.0 / t->offset; + t->invoffset = 1.0 / t->offset; - for(i=0;ilen+1;i++){ - x = t->start + t->offset * i; - x *= t->scale; + for (i = 0; i < t->len + 1; i++) { + x = t->start + t->offset * i; + x *= t->scale; - t->fx[i] = t->func_x(t->priv,x); - t->fdx[i] = t->scale * t->func_dx(t->priv,x); - } - if(t->func2_x){ - double f1x,f1dx; - double f2x,f2dx; + t->fx[i] = t->func_x (t->priv, x); + t->fdx[i] = t->scale * t->func_dx (t->priv, x); + } + if (t->func2_x) { + double f1x, f1dx; + double f2x, f2dx; - for(i=0;ilen+1;i++){ - x = t->start + t->offset * i; - x *= t->scale2; + for (i = 0; i < t->len + 1; i++) { + x = t->start + t->offset * i; + x *= t->scale2; - f2x = t->func2_x(t->priv,x); - f2dx = t->scale2 * t->func2_dx(t->priv,x); + f2x = t->func2_x (t->priv, x); + f2dx = t->scale2 * t->func2_dx (t->priv, x); - f1x = t->fx[i]; - f1dx = t->fdx[i]; + f1x = t->fx[i]; + f1dx = t->fdx[i]; - t->fx[i] = f1x * f2x; - t->fdx[i] = f1x * f2dx + f1dx * f2x; - } - } + t->fx[i] = f1x * f2x; + t->fdx[i] = f1x * f2dx + f1dx * f2x; + } + } } -double functable_eval(functable_t *t,double x) +double +functable_eval (functable_t * t, double x) { - int i; - double f0, f1, w0, w1; - double x2, x3; - double w; + int i; + double f0, f1, w0, w1; + double x2, x3; + double w; - if(xstart || x>(t->start+(t->len+1)*t->offset)){ - printf("x out of range %g\n",x); - } - x -= t->start; - x /= t->offset; - i = floor(x); - x -= i; + if (x < t->start || x > (t->start + (t->len + 1) * t->offset)) { + printf ("x out of range %g\n", x); + } + x -= t->start; + x /= t->offset; + i = floor (x); + x -= i; - x2 = x * x; - x3 = x2 * x; + x2 = x * x; + x3 = x2 * x; - f1 = 3 * x2 - 2 * x3; - f0 = 1 - f1; - w0 = (x - 2 * x2 + x3) * t->offset; - w1 = (-x2 + x3) * t->offset; + f1 = 3 * x2 - 2 * x3; + f0 = 1 - f1; + w0 = (x - 2 * x2 + x3) * t->offset; + w1 = (-x2 + x3) * t->offset; - /*printf("i=%d x=%g f0=%g f1=%g w0=%g w1=%g\n",i,x,f0,f1,w0,w1); */ + /*printf("i=%d x=%g f0=%g f1=%g w0=%g w1=%g\n",i,x,f0,f1,w0,w1); */ - w = t->fx[i] * f0 + t->fx[i + 1] * f1 + - t->fdx[i] * w0 + t->fdx[i + 1] * w1; + w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->fdx[i] * w0 + t->fdx[i + 1] * w1; - /*w = t->fx[i] * (1-x) + t->fx[i+1] * x; */ + /*w = t->fx[i] * (1-x) + t->fx[i+1] * x; */ - return w; + return w; } -double functable_fir(functable_t *t, double x, int n, double *data, int len) +double +functable_fir (functable_t * t, double x, int n, double *data, int len) { - int i,j; - double f0, f1, w0, w1; - double x2, x3; - double w; - double sum; + int i, j; + double f0, f1, w0, w1; + double x2, x3; + double w; + double sum; - x -= t->start; - x /= t->offset; - i = floor(x); - x -= i; + x -= t->start; + x /= t->offset; + i = floor (x); + x -= i; - x2 = x * x; - x3 = x2 * x; + x2 = x * x; + x3 = x2 * x; - f1 = 3 * x2 - 2 * x3; - f0 = 1 - f1; - w0 = (x - 2 * x2 + x3) * t->offset; - w1 = (-x2 + x3) * t->offset; + f1 = 3 * x2 - 2 * x3; + f0 = 1 - f1; + w0 = (x - 2 * x2 + x3) * t->offset; + w1 = (-x2 + x3) * t->offset; - sum = 0; - for(j=0;jfx[i] * f0 + t->fx[i + 1] * f1 + - t->fdx[i] * w0 + t->fdx[i + 1] * w1; - sum += data[j*2] * w; - i += n; - } + sum = 0; + for (j = 0; j < len; j++) { + w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->fdx[i] * w0 + t->fdx[i + 1] * w1; + sum += data[j * 2] * w; + i += n; + } - return sum; + return sum; } -void functable_fir2(functable_t *t, double *r0, double *r1, double x, - int n, double *data, int len) +void +functable_fir2 (functable_t * t, double *r0, double *r1, double x, + int n, double *data, int len) { - int i,j; - double f0, f1, w0, w1; - double x2, x3; - double w; - double sum0, sum1; - double floor_x; + int i, j; + double f0, f1, w0, w1; + double x2, x3; + double w; + double sum0, sum1; + double floor_x; - x -= t->start; - x *= t->invoffset; - floor_x = floor(x); - i = floor_x; - x -= floor_x; + x -= t->start; + x *= t->invoffset; + floor_x = floor (x); + i = floor_x; + x -= floor_x; - x2 = x * x; - x3 = x2 * x; + x2 = x * x; + x3 = x2 * x; - f1 = 3 * x2 - 2 * x3; - f0 = 1 - f1; - w0 = (x - 2 * x2 + x3) * t->offset; - w1 = (-x2 + x3) * t->offset; + f1 = 3 * x2 - 2 * x3; + f0 = 1 - f1; + w0 = (x - 2 * x2 + x3) * t->offset; + w1 = (-x2 + x3) * t->offset; - sum0 = 0; - sum1 = 0; - for(j=0;jfx[i] * f0 + t->fx[i + 1] * f1 + - t->fdx[i] * w0 + t->fdx[i + 1] * w1; - sum0 += data[j*2] * w; - sum1 += data[j*2+1] * w; - i += n; + sum0 = 0; + sum1 = 0; + for (j = 0; j < len; j++) { + w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->fdx[i] * w0 + t->fdx[i + 1] * w1; + sum0 += data[j * 2] * w; + sum1 += data[j * 2 + 1] * w; + i += n; #define unroll2 #define unroll3 #define unroll4 #ifdef unroll2 - j++; + j++; - w = t->fx[i] * f0 + t->fx[i + 1] * f1 + - t->fdx[i] * w0 + t->fdx[i + 1] * w1; - sum0 += data[j*2] * w; - sum1 += data[j*2+1] * w; - i += n; + w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->fdx[i] * w0 + t->fdx[i + 1] * w1; + sum0 += data[j * 2] * w; + sum1 += data[j * 2 + 1] * w; + i += n; #endif #ifdef unroll3 - j++; + j++; - w = t->fx[i] * f0 + t->fx[i + 1] * f1 + - t->fdx[i] * w0 + t->fdx[i + 1] * w1; - sum0 += data[j*2] * w; - sum1 += data[j*2+1] * w; - i += n; + w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->fdx[i] * w0 + t->fdx[i + 1] * w1; + sum0 += data[j * 2] * w; + sum1 += data[j * 2 + 1] * w; + i += n; #endif #ifdef unroll4 - j++; + j++; - w = t->fx[i] * f0 + t->fx[i + 1] * f1 + - t->fdx[i] * w0 + t->fdx[i + 1] * w1; - sum0 += data[j*2] * w; - sum1 += data[j*2+1] * w; - i += n; + w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->fdx[i] * w0 + t->fdx[i + 1] * w1; + sum0 += data[j * 2] * w; + sum1 += data[j * 2 + 1] * w; + i += n; #endif - } + } - *r0 = sum0; - *r1 = sum1; + *r0 = sum0; + *r1 = sum1; } #ifdef unused -void functable_fir2_altivec(functable_t *t, float *r0, float *r1, - double x, int n, float *data, int len) +void +functable_fir2_altivec (functable_t * t, float *r0, float *r1, + double x, int n, float *data, int len) { - int i,j; - double f0, f1, w0, w1; - double x2, x3; - double w; - double sum0, sum1; - double floor_x; + int i, j; + double f0, f1, w0, w1; + double x2, x3; + double w; + double sum0, sum1; + double floor_x; - x -= t->start; - x *= t->invoffset; - floor_x = floor(x); - i = floor_x; - x -= floor_x; + x -= t->start; + x *= t->invoffset; + floor_x = floor (x); + i = floor_x; + x -= floor_x; - x2 = x * x; - x3 = x2 * x; + x2 = x * x; + x3 = x2 * x; - f1 = 3 * x2 - 2 * x3; - f0 = 1 - f1; - w0 = (x - 2 * x2 + x3) * t->offset; - w1 = (-x2 + x3) * t->offset; + f1 = 3 * x2 - 2 * x3; + f0 = 1 - f1; + w0 = (x - 2 * x2 + x3) * t->offset; + w1 = (-x2 + x3) * t->offset; - sum0 = 0; - sum1 = 0; - for(j=0;jfx, t->fdx needs to be multiplexed by n */ - /* we need 5 consecutive floats, which fit into 2 vecs */ - /* load v0, t->fx[i] */ - /* load v1, t->fx[i+n] */ - /* v2 = v0 (not correct) */ - /* v3 = (v0>>32) || (v1<<3*32) (not correct) */ - /* */ - /* load v4, t->dfx[i] */ - /* load v5, t->dfx[i+n] */ - /* v6 = v4 (not correct) */ - /* v7 = (v4>>32) || (v5<<3*32) (not correct) */ - /* */ - /* v8 = splat(f0) */ - /* v9 = splat(f1) */ - /* v10 = splat(w0) */ - /* v11 = splat(w1) */ - /* */ - /* v12 = v2 * v8 */ - /* v12 += v3 * v9 */ - /* v12 += v6 * v10 */ - /* v12 += v7 * v11 */ - - w = t->fx[i] * f0 + t->fx[i + 1] * f1 + - t->fdx[i] * w0 + t->fdx[i + 1] * w1; - - /* v13 = data[j*2] */ - /* v14 = data[j*2+4] */ - /* v15 = deinterlace_high(v13,v14) */ - /* v16 = deinterlace_low(v13,v14) */ - /* (sum0) v17 += multsum(v13,v15) */ - /* (sum1) v18 += multsum(v14,v16) */ - - sum0 += data[j*2] * w; - sum1 += data[j*2+1] * w; - i += n; + sum0 = 0; + sum1 = 0; + for (j = 0; j < len; j++) { + /* t->fx, t->fdx needs to be multiplexed by n */ + /* we need 5 consecutive floats, which fit into 2 vecs */ + /* load v0, t->fx[i] */ + /* load v1, t->fx[i+n] */ + /* v2 = v0 (not correct) */ + /* v3 = (v0>>32) || (v1<<3*32) (not correct) */ + /* */ + /* load v4, t->dfx[i] */ + /* load v5, t->dfx[i+n] */ + /* v6 = v4 (not correct) */ + /* v7 = (v4>>32) || (v5<<3*32) (not correct) */ + /* */ + /* v8 = splat(f0) */ + /* v9 = splat(f1) */ + /* v10 = splat(w0) */ + /* v11 = splat(w1) */ + /* */ + /* v12 = v2 * v8 */ + /* v12 += v3 * v9 */ + /* v12 += v6 * v10 */ + /* v12 += v7 * v11 */ - } + w = t->fx[i] * f0 + t->fx[i + 1] * f1 + t->fdx[i] * w0 + t->fdx[i + 1] * w1; - *r0 = sum0; - *r1 = sum1; + /* v13 = data[j*2] */ + /* v14 = data[j*2+4] */ + /* v15 = deinterlace_high(v13,v14) */ + /* v16 = deinterlace_low(v13,v14) */ + /* (sum0) v17 += multsum(v13,v15) */ + /* (sum1) v18 += multsum(v14,v16) */ + + sum0 += data[j * 2] * w; + sum1 += data[j * 2 + 1] * w; + i += n; + + } + + *r0 = sum0; + *r1 = sum1; } #endif - diff --git a/gst-libs/gst/resample/private.h b/gst-libs/gst/resample/private.h index 5791f5801f..a0d37f4112 100644 --- a/gst-libs/gst/resample/private.h +++ b/gst-libs/gst/resample/private.h @@ -23,68 +23,71 @@ #include "resample.h" -void gst_resample_nearest_s16(gst_resample_t *r); -void gst_resample_bilinear_s16(gst_resample_t *r); -void gst_resample_sinc_s16(gst_resample_t *r); -void gst_resample_sinc_slow_s16(gst_resample_t *r); -void gst_resample_sinc_ft_s16(gst_resample_t * r); +void gst_resample_nearest_s16 (gst_resample_t * r); +void gst_resample_bilinear_s16 (gst_resample_t * r); +void gst_resample_sinc_s16 (gst_resample_t * r); +void gst_resample_sinc_slow_s16 (gst_resample_t * r); +void gst_resample_sinc_ft_s16 (gst_resample_t * r); -void gst_resample_nearest_float(gst_resample_t *r); -void gst_resample_bilinear_float(gst_resample_t *r); -void gst_resample_sinc_float(gst_resample_t *r); -void gst_resample_sinc_slow_float(gst_resample_t *r); -void gst_resample_sinc_ft_float(gst_resample_t * r); +void gst_resample_nearest_float (gst_resample_t * r); +void gst_resample_bilinear_float (gst_resample_t * r); +void gst_resample_sinc_float (gst_resample_t * r); +void gst_resample_sinc_slow_float (gst_resample_t * r); +void gst_resample_sinc_ft_float (gst_resample_t * r); typedef struct functable_s functable_t; -struct functable_s { - double start; - double offset; - int len; +struct functable_s +{ + double start; + double offset; + int len; - double invoffset; + double invoffset; - double scale; - double scale2; + double scale; + double scale2; - double (*func_x)(void *,double x); - double (*func_dx)(void *,double x); + double (*func_x) (void *, double x); + double (*func_dx) (void *, double x); - double (*func2_x)(void *,double x); - double (*func2_dx)(void *,double x); + double (*func2_x) (void *, double x); + double (*func2_dx) (void *, double x); - double *fx; - double *fdx; + double *fx; + double *fdx; - void *priv; + void *priv; }; -void functable_init(functable_t *t); -double functable_eval(functable_t *t,double x); +void functable_init (functable_t * t); +double functable_eval (functable_t * t, double x); -double functable_fir(functable_t *t,double x0,int n,double *data,int len); -void functable_fir2(functable_t *t,double *r0, double *r1, double x0, - int n,double *data,int len); +double functable_fir (functable_t * t, double x0, int n, double *data, int len); +void functable_fir2 (functable_t * t, double *r0, double *r1, double x0, + int n, double *data, int len); -double functable_sinc(void *p, double x); -double functable_dsinc(void *p, double x); -double functable_window_std(void *p, double x); -double functable_window_dstd(void *p, double x); -double functable_window_boxcar(void *p, double x); -double functable_window_dboxcar(void *p, double x); +double functable_sinc (void *p, double x); +double functable_dsinc (void *p, double x); +double functable_window_std (void *p, double x); +double functable_window_dstd (void *p, double x); +double functable_window_boxcar (void *p, double x); +double functable_window_dboxcar (void *p, double x); /* math lib stuff */ -void conv_double_short_table(double *dest, short *src, int n); -void conv_double_short_unroll(double *dest, short *src, int n); -void conv_double_short_ref(double *dest, short *src, int n); +void conv_double_short_table (double *dest, short *src, int n); +void conv_double_short_unroll (double *dest, short *src, int n); +void conv_double_short_ref (double *dest, short *src, int n); + #ifdef HAVE_CPU_PPC -void conv_double_short_altivec(double *dest, short *src, int n); +void conv_double_short_altivec (double *dest, short *src, int n); #endif -void conv_short_double_ref(short *dest, double *src, int n); +void conv_short_double_ref (short *dest, double *src, int n); + #ifdef HAVE_CPU_PPC -void conv_short_double_ppcasm(short *dest, double *src, int n); +void conv_short_double_ppcasm (short *dest, double *src, int n); #endif #ifdef HAVE_CPU_PPC @@ -98,12 +101,12 @@ void conv_short_double_ppcasm(short *dest, double *src, int n); #define conv_double_float conv_double_float_ref #define conv_float_double conv_float_double_ref -void conv_double_short_dstr(double *dest, short *src, int n, int dstr); -void conv_short_double_sstr(short *dest, double *src, int n, int dstr); +void conv_double_short_dstr (double *dest, short *src, int n, int dstr); +void conv_short_double_sstr (short *dest, double *src, int n, int dstr); -void conv_double_float_ref(double *dest, float *src, int n); -void conv_float_double_ref(float *dest, double *src, int n); -void conv_double_float_dstr(double *dest, float *src, int n, int dstr); -void conv_float_double_sstr(float *dest, double *src, int n, int sstr); +void conv_double_float_ref (double *dest, float *src, int n); +void conv_float_double_ref (float *dest, double *src, int n); +void conv_double_float_dstr (double *dest, float *src, int n, int dstr); +void conv_float_double_sstr (float *dest, double *src, int n, int sstr); #endif /* __PRIVATE_H__ */ diff --git a/gst-libs/gst/resample/resample.c b/gst-libs/gst/resample/resample.c index 8cac9de681..cd409d239b 100644 --- a/gst-libs/gst/resample/resample.c +++ b/gst-libs/gst/resample/resample.c @@ -30,100 +30,107 @@ #include #include -inline double sinc(double x) +inline double +sinc (double x) { - if(x==0)return 1; - return sin(x) / x; + if (x == 0) + return 1; + return sin (x) / x; } -inline double window_func(double x) +inline double +window_func (double x) { - x = 1 - x*x; - return x*x; + x = 1 - x * x; + return x * x; } -signed short double_to_s16(double x) +signed short +double_to_s16 (double x) { - if(x<-32768){ - printf("clipped\n"); - return -32768; - } - if(x>32767){ - printf("clipped\n"); - return -32767; - } - return rint(x); + if (x < -32768) { + printf ("clipped\n"); + return -32768; + } + if (x > 32767) { + printf ("clipped\n"); + return -32767; + } + return rint (x); } -signed short double_to_s16_ppcasm(double x) +signed short +double_to_s16_ppcasm (double x) { - if(x<-32768){ - return -32768; - } - if(x>32767){ - return -32767; - } - return rint(x); + if (x < -32768) { + return -32768; + } + if (x > 32767) { + return -32767; + } + return rint (x); } -void gst_resample_init(gst_resample_t * r) +void +gst_resample_init (gst_resample_t * r) { - r->i_start = 0; - if(r->filter_length&1){ - r->o_start = 0; - }else{ - r->o_start = r->o_inc * 0.5; - } + r->i_start = 0; + if (r->filter_length & 1) { + r->o_start = 0; + } else { + r->o_start = r->o_inc * 0.5; + } - memset(r->acc, 0, sizeof(r->acc)); + memset (r->acc, 0, sizeof (r->acc)); - gst_resample_reinit(r); + gst_resample_reinit (r); } -void gst_resample_reinit(gst_resample_t * r) +void +gst_resample_reinit (gst_resample_t * r) { - /* i_inc is the number of samples that the output increments for - * each input sample. o_inc is the opposite. */ - r->i_inc = (double) r->o_rate / r->i_rate; - r->o_inc = (double) r->i_rate / r->o_rate; + /* i_inc is the number of samples that the output increments for + * each input sample. o_inc is the opposite. */ + r->i_inc = (double) r->o_rate / r->i_rate; + r->o_inc = (double) r->i_rate / r->o_rate; - r->halftaps = (r->filter_length - 1.0) * 0.5; + r->halftaps = (r->filter_length - 1.0) * 0.5; - if (r->format == GST_RESAMPLE_S16) { - switch (r->method) { - default: - case GST_RESAMPLE_NEAREST: - r->scale = gst_resample_nearest_s16; - break; - case GST_RESAMPLE_BILINEAR: - r->scale = gst_resample_bilinear_s16; - break; - case GST_RESAMPLE_SINC_SLOW: - r->scale = gst_resample_sinc_s16; - break; - case GST_RESAMPLE_SINC: - r->scale = gst_resample_sinc_ft_s16; - break; - } - } else if (r->format == GST_RESAMPLE_FLOAT) { - switch (r->method) { - default: - case GST_RESAMPLE_NEAREST: - r->scale = gst_resample_nearest_float; - break; - case GST_RESAMPLE_BILINEAR: - r->scale = gst_resample_bilinear_float; - break; - case GST_RESAMPLE_SINC_SLOW: - r->scale = gst_resample_sinc_float; - break; - case GST_RESAMPLE_SINC: - r->scale = gst_resample_sinc_ft_float; - break; - } - } else { - fprintf (stderr, "gst_resample: Unexpected format \"%d\"\n", r->format); - } + if (r->format == GST_RESAMPLE_S16) { + switch (r->method) { + default: + case GST_RESAMPLE_NEAREST: + r->scale = gst_resample_nearest_s16; + break; + case GST_RESAMPLE_BILINEAR: + r->scale = gst_resample_bilinear_s16; + break; + case GST_RESAMPLE_SINC_SLOW: + r->scale = gst_resample_sinc_s16; + break; + case GST_RESAMPLE_SINC: + r->scale = gst_resample_sinc_ft_s16; + break; + } + } else if (r->format == GST_RESAMPLE_FLOAT) { + switch (r->method) { + default: + case GST_RESAMPLE_NEAREST: + r->scale = gst_resample_nearest_float; + break; + case GST_RESAMPLE_BILINEAR: + r->scale = gst_resample_bilinear_float; + break; + case GST_RESAMPLE_SINC_SLOW: + r->scale = gst_resample_sinc_float; + break; + case GST_RESAMPLE_SINC: + r->scale = gst_resample_sinc_ft_float; + break; + } + } else { + fprintf (stderr, "gst_resample: Unexpected format \"%d\"\n", r->format); + } } /* @@ -140,94 +147,94 @@ void gst_resample_reinit(gst_resample_t * r) * i_start_buf is the time of the first sample in the temporary * buffer. */ -void gst_resample_scale(gst_resample_t * r, void *i_buf, unsigned int i_size) +void +gst_resample_scale (gst_resample_t * r, void *i_buf, unsigned int i_size) { - int o_size; + int o_size; - r->i_buf = i_buf; + r->i_buf = i_buf; - r->i_samples = i_size / 2 / r->channels; + r->i_samples = i_size / 2 / r->channels; - r->i_start_buf = r->i_start - r->filter_length * r->i_inc; + r->i_start_buf = r->i_start - r->filter_length * r->i_inc; - /* i_start is the offset (in a given output sample) that is the - * beginning of the current input buffer */ - r->i_end = r->i_start + r->i_inc * r->i_samples; + /* i_start is the offset (in a given output sample) that is the + * beginning of the current input buffer */ + r->i_end = r->i_start + r->i_inc * r->i_samples; - r->o_samples = floor(r->i_end - r->halftaps * r->i_inc); + r->o_samples = floor (r->i_end - r->halftaps * r->i_inc); - o_size = r->o_samples * r->channels * 2; - r->o_buf = r->get_buffer(r->priv, o_size); + o_size = r->o_samples * r->channels * 2; + r->o_buf = r->get_buffer (r->priv, o_size); - if(r->verbose){ - printf("gst_resample_scale: i_buf=%p i_size=%d\n", - i_buf,i_size); - printf("gst_resample_scale: i_samples=%d o_samples=%d i_inc=%g o_buf=%p\n", - r->i_samples, r->o_samples, r->i_inc, r->o_buf); - printf("gst_resample_scale: i_start=%g i_end=%g o_start=%g\n", - r->i_start, r->i_end, r->o_start); - } + if (r->verbose) { + printf ("gst_resample_scale: i_buf=%p i_size=%d\n", i_buf, i_size); + printf ("gst_resample_scale: i_samples=%d o_samples=%d i_inc=%g o_buf=%p\n", + r->i_samples, r->o_samples, r->i_inc, r->o_buf); + printf ("gst_resample_scale: i_start=%g i_end=%g o_start=%g\n", + r->i_start, r->i_end, r->o_start); + } - if ((r->filter_length + r->i_samples)*sizeof(double)*2 > r->buffer_len) { - int size = (r->filter_length + r->i_samples) * sizeof(double) * 2; + if ((r->filter_length + r->i_samples) * sizeof (double) * 2 > r->buffer_len) { + int size = (r->filter_length + r->i_samples) * sizeof (double) * 2; - if(r->verbose){ - printf("gst_resample temp buffer size=%d\n",size); - } - if(r->buffer)free(r->buffer); - r->buffer_len = size; - r->buffer = malloc(size); - memset(r->buffer, 0, size); - } + if (r->verbose) { + printf ("gst_resample temp buffer size=%d\n", size); + } + if (r->buffer) + free (r->buffer); + r->buffer_len = size; + r->buffer = malloc (size); + memset (r->buffer, 0, size); + } - if (r->format==GST_RESAMPLE_S16) { - if(r->channels==2){ - conv_double_short( - r->buffer + r->filter_length * sizeof(double) * 2, - r->i_buf, r->i_samples * 2); - } else { - conv_double_short_dstr( - r->buffer + r->filter_length * sizeof(double) * 2, - r->i_buf, r->i_samples, sizeof(double) * 2); - } - } else if (r->format==GST_RESAMPLE_FLOAT) { - if(r->channels==2){ - conv_double_float( - r->buffer + r->filter_length * sizeof(double) * 2, - r->i_buf, r->i_samples * 2); - } else { - conv_double_float_dstr( - r->buffer + r->filter_length * sizeof(double) * 2, - r->i_buf, r->i_samples, sizeof(double) * 2); - } - } + if (r->format == GST_RESAMPLE_S16) { + if (r->channels == 2) { + conv_double_short (r->buffer + r->filter_length * sizeof (double) * 2, + r->i_buf, r->i_samples * 2); + } else { + conv_double_short_dstr (r->buffer + + r->filter_length * sizeof (double) * 2, r->i_buf, r->i_samples, + sizeof (double) * 2); + } + } else if (r->format == GST_RESAMPLE_FLOAT) { + if (r->channels == 2) { + conv_double_float (r->buffer + r->filter_length * sizeof (double) * 2, + r->i_buf, r->i_samples * 2); + } else { + conv_double_float_dstr (r->buffer + + r->filter_length * sizeof (double) * 2, r->i_buf, r->i_samples, + sizeof (double) * 2); + } + } - r->scale(r); + r->scale (r); - memcpy(r->buffer, - r->buffer + r->i_samples * sizeof(double) * 2, - r->filter_length * sizeof(double) * 2); + memcpy (r->buffer, + r->buffer + r->i_samples * sizeof (double) * 2, + r->filter_length * sizeof (double) * 2); - /* updating times */ - r->i_start += r->i_samples * r->i_inc; - r->o_start += r->o_samples * r->o_inc - r->i_samples; - - /* adjusting timebase zero */ - r->i_start -= r->o_samples; + /* updating times */ + r->i_start += r->i_samples * r->i_inc; + r->o_start += r->o_samples * r->o_inc - r->i_samples; + + /* adjusting timebase zero */ + r->i_start -= r->o_samples; } -void gst_resample_nearest_s16(gst_resample_t * r) +void +gst_resample_nearest_s16 (gst_resample_t * r) { - signed short *i_ptr, *o_ptr; - int i_count = 0; - double a; - int i; + signed short *i_ptr, *o_ptr; + int i_count = 0; + double a; + int i; - i_ptr = (signed short *) r->i_buf; - o_ptr = (signed short *) r->o_buf; + i_ptr = (signed short *) r->i_buf; + o_ptr = (signed short *) r->o_buf; - a = r->o_start; - i_count = 0; + a = r->o_start; + i_count = 0; #define SCALE_LOOP(COPY,INC) \ for (i = 0; i < r->o_samples; i++) { \ COPY; \ @@ -240,191 +247,190 @@ void gst_resample_nearest_s16(gst_resample_t * r) o_ptr+=INC; \ } - switch (r->channels) { - case 1: - SCALE_LOOP(o_ptr[0] = i_ptr[0], 1); - break; - case 2: - SCALE_LOOP(o_ptr[0] = i_ptr[0]; - o_ptr[1] = i_ptr[1], 2); - break; - default: - { - int n, n_chan = r->channels; + switch (r->channels) { + case 1: + SCALE_LOOP (o_ptr[0] = i_ptr[0], 1); + break; + case 2: + SCALE_LOOP (o_ptr[0] = i_ptr[0]; o_ptr[1] = i_ptr[1], 2); + break; + default: + { + int n, n_chan = r->channels; - SCALE_LOOP(for (n = 0; n < n_chan; n++) o_ptr[n] = - i_ptr[n], n_chan); - } - } - if (i_count != r->i_samples) { - printf("handled %d in samples (expected %d)\n", i_count, - r->i_samples); - } + SCALE_LOOP (for (n = 0; n < n_chan; n++) o_ptr[n] = i_ptr[n], n_chan); + } + } + if (i_count != r->i_samples) { + printf ("handled %d in samples (expected %d)\n", i_count, r->i_samples); + } } -void gst_resample_bilinear_s16(gst_resample_t * r) +void +gst_resample_bilinear_s16 (gst_resample_t * r) { - signed short *i_ptr, *o_ptr; - int o_count = 0; - double b; - int i; - double acc0, acc1; + signed short *i_ptr, *o_ptr; + int o_count = 0; + double b; + int i; + double acc0, acc1; - i_ptr = (signed short *) r->i_buf; - o_ptr = (signed short *) r->o_buf; + i_ptr = (signed short *) r->i_buf; + o_ptr = (signed short *) r->o_buf; - acc0 = r->acc[0]; - acc1 = r->acc[1]; - b = r->i_start; - for (i = 0; i < r->i_samples; i++) { - b += r->i_inc; - /*printf("in %d\n",i_ptr[0]); */ - if(b>=2){ - printf("not expecting b>=2\n"); - } - if (b >= 1) { - acc0 += (1.0 - (b-r->i_inc)) * i_ptr[0]; - acc1 += (1.0 - (b-r->i_inc)) * i_ptr[1]; + acc0 = r->acc[0]; + acc1 = r->acc[1]; + b = r->i_start; + for (i = 0; i < r->i_samples; i++) { + b += r->i_inc; + /*printf("in %d\n",i_ptr[0]); */ + if (b >= 2) { + printf ("not expecting b>=2\n"); + } + if (b >= 1) { + acc0 += (1.0 - (b - r->i_inc)) * i_ptr[0]; + acc1 += (1.0 - (b - r->i_inc)) * i_ptr[1]; - o_ptr[0] = rint(acc0); - /*printf("out %d\n",o_ptr[0]); */ - o_ptr[1] = rint(acc1); - o_ptr += 2; - o_count++; + o_ptr[0] = rint (acc0); + /*printf("out %d\n",o_ptr[0]); */ + o_ptr[1] = rint (acc1); + o_ptr += 2; + o_count++; - b -= 1.0; + b -= 1.0; - acc0 = b * i_ptr[0]; - acc1 = b * i_ptr[1]; - } else { - acc0 += i_ptr[0] * r->i_inc; - acc1 += i_ptr[1] * r->i_inc; - } - i_ptr += 2; - } - r->acc[0] = acc0; - r->acc[1] = acc1; + acc0 = b * i_ptr[0]; + acc1 = b * i_ptr[1]; + } else { + acc0 += i_ptr[0] * r->i_inc; + acc1 += i_ptr[1] * r->i_inc; + } + i_ptr += 2; + } + r->acc[0] = acc0; + r->acc[1] = acc1; - if (o_count != r->o_samples) { - printf("handled %d out samples (expected %d)\n", o_count, - r->o_samples); - } + if (o_count != r->o_samples) { + printf ("handled %d out samples (expected %d)\n", o_count, r->o_samples); + } } -void gst_resample_sinc_slow_s16(gst_resample_t * r) +void +gst_resample_sinc_slow_s16 (gst_resample_t * r) { - signed short *i_ptr, *o_ptr; - int i, j; - double c0, c1; - double a; - int start; - double center; - double weight; + signed short *i_ptr, *o_ptr; + int i, j; + double c0, c1; + double a; + int start; + double center; + double weight; - if (!r->buffer) { - int size = r->filter_length * 2 * r->channels; + if (!r->buffer) { + int size = r->filter_length * 2 * r->channels; - printf("gst_resample temp buffer\n"); - r->buffer = malloc(size); - memset(r->buffer, 0, size); - } + printf ("gst_resample temp buffer\n"); + r->buffer = malloc (size); + memset (r->buffer, 0, size); + } - i_ptr = (signed short *) r->i_buf; - o_ptr = (signed short *) r->o_buf; + i_ptr = (signed short *) r->i_buf; + o_ptr = (signed short *) r->o_buf; - a = r->i_start; + a = r->i_start; #define GETBUF(index,chan) (((index)<0) \ ? ((short *)(r->buffer))[((index)+r->filter_length)*2+(chan)] \ : i_ptr[(index)*2+(chan)]) - { - double sinx, cosx, sind, cosd; - double x, d; - double t; + { + double sinx, cosx, sind, cosd; + double x, d; + double t; - for (i = 0; i < r->o_samples; i++) { - start = floor(a) - r->filter_length; - center = a - r->halftaps; - x = M_PI * (start - center) * r->o_inc; - sinx = sin(M_PI * (start - center) * r->o_inc); - cosx = cos(M_PI * (start - center) * r->o_inc); - d = M_PI * r->o_inc; - sind = sin(M_PI * r->o_inc); - cosd = cos(M_PI * r->o_inc); - c0 = 0; - c1 = 0; - for (j = 0; j < r->filter_length; j++) { - weight = (x==0)?1:(sinx/x); + for (i = 0; i < r->o_samples; i++) { + start = floor (a) - r->filter_length; + center = a - r->halftaps; + x = M_PI * (start - center) * r->o_inc; + sinx = sin (M_PI * (start - center) * r->o_inc); + cosx = cos (M_PI * (start - center) * r->o_inc); + d = M_PI * r->o_inc; + sind = sin (M_PI * r->o_inc); + cosd = cos (M_PI * r->o_inc); + c0 = 0; + c1 = 0; + for (j = 0; j < r->filter_length; j++) { + weight = (x == 0) ? 1 : (sinx / x); /*printf("j %d sin %g cos %g\n",j,sinx,cosx); */ /*printf("j %d sin %g x %g sinc %g\n",j,sinx,x,weight); */ - c0 += weight * GETBUF((start + j), 0); - c1 += weight * GETBUF((start + j), 1); - t = cosx * cosd - sinx * sind; - sinx = cosx * sind + sinx * cosd; - cosx = t; - x += d; - } - o_ptr[0] = rint(c0); - o_ptr[1] = rint(c1); - o_ptr += 2; - a += r->o_inc; - } - } + c0 += weight * GETBUF ((start + j), 0); + c1 += weight * GETBUF ((start + j), 1); + t = cosx * cosd - sinx * sind; + sinx = cosx * sind + sinx * cosd; + cosx = t; + x += d; + } + o_ptr[0] = rint (c0); + o_ptr[1] = rint (c1); + o_ptr += 2; + a += r->o_inc; + } + } #undef GETBUF - memcpy(r->buffer, - i_ptr + (r->i_samples - r->filter_length) * r->channels, - r->filter_length * 2 * r->channels); + memcpy (r->buffer, + i_ptr + (r->i_samples - r->filter_length) * r->channels, + r->filter_length * 2 * r->channels); } /* only works for channels == 2 ???? */ -void gst_resample_sinc_s16(gst_resample_t * r) +void +gst_resample_sinc_s16 (gst_resample_t * r) { - double *ptr; - signed short *o_ptr; - int i, j; - double c0, c1; - double a; - int start; - double center; - double weight; - double x0, x, d; - double scale; + double *ptr; + signed short *o_ptr; + int i, j; + double c0, c1; + double a; + int start; + double center; + double weight; + double x0, x, d; + double scale; - ptr = (double *) r->buffer; - o_ptr = (signed short *) r->o_buf; + ptr = (double *) r->buffer; + o_ptr = (signed short *) r->o_buf; - /* scale provides a cutoff frequency for the low - * pass filter aspects of sinc(). scale=M_PI - * will cut off at the input frequency, which is - * good for up-sampling, but will cause aliasing - * for downsampling. Downsampling needs to be - * cut off at o_rate, thus scale=M_PI*r->i_inc. */ - /* actually, it needs to be M_PI*r->i_inc*r->i_inc. - * Need to research why. */ - scale = M_PI*r->i_inc; - for (i = 0; i < r->o_samples; i++) { - a = r->o_start + i * r->o_inc; - start = floor(a - r->halftaps); + /* scale provides a cutoff frequency for the low + * pass filter aspects of sinc(). scale=M_PI + * will cut off at the input frequency, which is + * good for up-sampling, but will cause aliasing + * for downsampling. Downsampling needs to be + * cut off at o_rate, thus scale=M_PI*r->i_inc. */ + /* actually, it needs to be M_PI*r->i_inc*r->i_inc. + * Need to research why. */ + scale = M_PI * r->i_inc; + for (i = 0; i < r->o_samples; i++) { + a = r->o_start + i * r->o_inc; + start = floor (a - r->halftaps); /*printf("%d: a=%g start=%d end=%d\n",i,a,start,start+r->filter_length-1); */ - center = a; - /*x = M_PI * (start - center) * r->o_inc; */ - /*d = M_PI * r->o_inc; */ - /*x = (start - center) * r->o_inc; */ - x0 = (start - center) * r->o_inc; - d = r->o_inc; - c0 = 0; - c1 = 0; - for (j = 0; j < r->filter_length; j++) { - x = x0 + d * j; - weight = sinc(x*scale*r->i_inc)*scale/M_PI; - weight *= window_func(x/r->halftaps*r->i_inc); - c0 += weight * ptr[(start + j + r->filter_length)*2 + 0]; - c1 += weight * ptr[(start + j + r->filter_length)*2 + 1]; - } - o_ptr[0] = double_to_s16(c0); - o_ptr[1] = double_to_s16(c1); - o_ptr += 2; - } + center = a; + /*x = M_PI * (start - center) * r->o_inc; */ + /*d = M_PI * r->o_inc; */ + /*x = (start - center) * r->o_inc; */ + x0 = (start - center) * r->o_inc; + d = r->o_inc; + c0 = 0; + c1 = 0; + for (j = 0; j < r->filter_length; j++) { + x = x0 + d * j; + weight = sinc (x * scale * r->i_inc) * scale / M_PI; + weight *= window_func (x / r->halftaps * r->i_inc); + c0 += weight * ptr[(start + j + r->filter_length) * 2 + 0]; + c1 += weight * ptr[(start + j + r->filter_length) * 2 + 1]; + } + o_ptr[0] = double_to_s16 (c0); + o_ptr[1] = double_to_s16 (c1); + o_ptr += 2; + } } /* @@ -468,98 +474,100 @@ static functable_t *ft; double out_tmp[10000]; -void gst_resample_sinc_ft_s16(gst_resample_t * r) +void +gst_resample_sinc_ft_s16 (gst_resample_t * r) { - double *ptr; - signed short *o_ptr; - int i; - /*int j; */ - double c0, c1; - /*double a; */ - double start_f, start_x; - int start; - double center; - /*double weight; */ - double x, d; - double scale; - int n = 4; + double *ptr; + signed short *o_ptr; + int i; - scale = r->i_inc; /* cutoff at 22050 */ - /*scale = 1.0; // cutoff at 24000 */ - /*scale = r->i_inc * 0.5; // cutoff at 11025 */ + /*int j; */ + double c0, c1; - if(!ft){ - ft = malloc(sizeof(*ft)); - memset(ft,0,sizeof(*ft)); + /*double a; */ + double start_f, start_x; + int start; + double center; - ft->len = (r->filter_length + 2) * n; - ft->offset = 1.0 / n; - ft->start = - ft->len * 0.5 * ft->offset; + /*double weight; */ + double x, d; + double scale; + int n = 4; - ft->func_x = functable_sinc; - ft->func_dx = functable_dsinc; - ft->scale = M_PI * scale; + scale = r->i_inc; /* cutoff at 22050 */ + /*scale = 1.0; // cutoff at 24000 */ + /*scale = r->i_inc * 0.5; // cutoff at 11025 */ - ft->func2_x = functable_window_std; - ft->func2_dx = functable_window_dstd; - ft->scale2 = 1.0 / r->halftaps; - - functable_init(ft); + if (!ft) { + ft = malloc (sizeof (*ft)); + memset (ft, 0, sizeof (*ft)); - /*printf("len=%d offset=%g start=%g\n",ft->len,ft->offset,ft->start); */ - } + ft->len = (r->filter_length + 2) * n; + ft->offset = 1.0 / n; + ft->start = -ft->len * 0.5 * ft->offset; - ptr = r->buffer; - o_ptr = (signed short *) r->o_buf; + ft->func_x = functable_sinc; + ft->func_dx = functable_dsinc; + ft->scale = M_PI * scale; - center = r->o_start; - start_x = center - r->halftaps; - start_f = floor(start_x); - start_x -= start_f; - start = start_f; - for (i = 0; i < r->o_samples; i++) { - /*start_f = floor(center - r->halftaps); */ + ft->func2_x = functable_window_std; + ft->func2_dx = functable_window_dstd; + ft->scale2 = 1.0 / r->halftaps; + + functable_init (ft); + + /*printf("len=%d offset=%g start=%g\n",ft->len,ft->offset,ft->start); */ + } + + ptr = r->buffer; + o_ptr = (signed short *) r->o_buf; + + center = r->o_start; + start_x = center - r->halftaps; + start_f = floor (start_x); + start_x -= start_f; + start = start_f; + for (i = 0; i < r->o_samples; i++) { + /*start_f = floor(center - r->halftaps); */ /*printf("%d: a=%g start=%d end=%d\n",i,a,start,start+r->filter_length-1); */ - x = start_f - center; - d = 1; - c0 = 0; - c1 = 0; + x = start_f - center; + d = 1; + c0 = 0; + c1 = 0; /*#define slow */ #ifdef slow - for (j = 0; j < r->filter_length; j++) { - weight = functable_eval(ft,x)*scale; - /*weight = sinc(M_PI * scale * x)*scale*r->i_inc; */ - /*weight *= window_func(x / r->halftaps); */ - c0 += weight * ptr[(start + j + r->filter_length)*2 + 0]; - c1 += weight * ptr[(start + j + r->filter_length)*2 + 1]; - x += d; - } + for (j = 0; j < r->filter_length; j++) { + weight = functable_eval (ft, x) * scale; + /*weight = sinc(M_PI * scale * x)*scale*r->i_inc; */ + /*weight *= window_func(x / r->halftaps); */ + c0 += weight * ptr[(start + j + r->filter_length) * 2 + 0]; + c1 += weight * ptr[(start + j + r->filter_length) * 2 + 1]; + x += d; + } #else - functable_fir2(ft, - &c0,&c1, - x, n, - ptr+(start + r->filter_length)*2, - r->filter_length); - c0 *= scale; - c1 *= scale; + functable_fir2 (ft, + &c0, &c1, x, n, ptr + (start + r->filter_length) * 2, r->filter_length); + c0 *= scale; + c1 *= scale; #endif - out_tmp[2 * i + 0] = c0; - out_tmp[2 * i + 1] = c1; - center += r->o_inc; - start_x += r->o_inc; - while(start_x>=1.0){ - start_f++; - start_x -= 1.0; - start++; - } - } + out_tmp[2 * i + 0] = c0; + out_tmp[2 * i + 1] = c1; + center += r->o_inc; + start_x += r->o_inc; + while (start_x >= 1.0) { + start_f++; + start_x -= 1.0; + start++; + } + } - if(r->channels==2){ - conv_short_double(r->o_buf,out_tmp,2 * r->o_samples); - }else{ - conv_short_double_sstr(r->o_buf,out_tmp,r->o_samples,2 * sizeof(double)); - } + if (r->channels == 2) { + conv_short_double (r->o_buf, out_tmp, 2 * r->o_samples); + } else { + conv_short_double_sstr (r->o_buf, out_tmp, r->o_samples, + 2 * sizeof (double)); + } } /******** @@ -567,18 +575,19 @@ void gst_resample_sinc_ft_s16(gst_resample_t * r) ********/ -void gst_resample_nearest_float(gst_resample_t * r) +void +gst_resample_nearest_float (gst_resample_t * r) { - float *i_ptr, *o_ptr; - int i_count = 0; - double a; - int i; + float *i_ptr, *o_ptr; + int i_count = 0; + double a; + int i; - i_ptr = (float *) r->i_buf; - o_ptr = (float *) r->o_buf; + i_ptr = (float *) r->i_buf; + o_ptr = (float *) r->o_buf; - a = r->o_start; - i_count = 0; + a = r->o_start; + i_count = 0; #define SCALE_LOOP(COPY,INC) \ for (i = 0; i < r->o_samples; i++) { \ COPY; \ @@ -591,302 +600,296 @@ void gst_resample_nearest_float(gst_resample_t * r) o_ptr+=INC; \ } - switch (r->channels) { - case 1: - SCALE_LOOP(o_ptr[0] = i_ptr[0], 1); - break; - case 2: - SCALE_LOOP(o_ptr[0] = i_ptr[0]; - o_ptr[1] = i_ptr[1], 2); - break; - default: - { - int n, n_chan = r->channels; + switch (r->channels) { + case 1: + SCALE_LOOP (o_ptr[0] = i_ptr[0], 1); + break; + case 2: + SCALE_LOOP (o_ptr[0] = i_ptr[0]; o_ptr[1] = i_ptr[1], 2); + break; + default: + { + int n, n_chan = r->channels; - SCALE_LOOP(for (n = 0; n < n_chan; n++) o_ptr[n] = - i_ptr[n], n_chan); - } - } - if (i_count != r->i_samples) { - printf("handled %d in samples (expected %d)\n", i_count, - r->i_samples); - } + SCALE_LOOP (for (n = 0; n < n_chan; n++) o_ptr[n] = i_ptr[n], n_chan); + } + } + if (i_count != r->i_samples) { + printf ("handled %d in samples (expected %d)\n", i_count, r->i_samples); + } } -void gst_resample_bilinear_float(gst_resample_t * r) +void +gst_resample_bilinear_float (gst_resample_t * r) { - float *i_ptr, *o_ptr; - int o_count = 0; - double b; - int i; - double acc0, acc1; + float *i_ptr, *o_ptr; + int o_count = 0; + double b; + int i; + double acc0, acc1; - i_ptr = (float *) r->i_buf; - o_ptr = (float *) r->o_buf; + i_ptr = (float *) r->i_buf; + o_ptr = (float *) r->o_buf; - acc0 = r->acc[0]; - acc1 = r->acc[1]; - b = r->i_start; - for (i = 0; i < r->i_samples; i++) { - b += r->i_inc; - /*printf("in %d\n",i_ptr[0]); */ - if(b>=2){ - printf("not expecting b>=2\n"); - } - if (b >= 1) { - acc0 += (1.0 - (b-r->i_inc)) * i_ptr[0]; - acc1 += (1.0 - (b-r->i_inc)) * i_ptr[1]; + acc0 = r->acc[0]; + acc1 = r->acc[1]; + b = r->i_start; + for (i = 0; i < r->i_samples; i++) { + b += r->i_inc; + /*printf("in %d\n",i_ptr[0]); */ + if (b >= 2) { + printf ("not expecting b>=2\n"); + } + if (b >= 1) { + acc0 += (1.0 - (b - r->i_inc)) * i_ptr[0]; + acc1 += (1.0 - (b - r->i_inc)) * i_ptr[1]; - o_ptr[0] = acc0; - /*printf("out %d\n",o_ptr[0]); */ - o_ptr[1] = acc1; - o_ptr += 2; - o_count++; + o_ptr[0] = acc0; + /*printf("out %d\n",o_ptr[0]); */ + o_ptr[1] = acc1; + o_ptr += 2; + o_count++; - b -= 1.0; + b -= 1.0; - acc0 = b * i_ptr[0]; - acc1 = b * i_ptr[1]; - } else { - acc0 += i_ptr[0] * r->i_inc; - acc1 += i_ptr[1] * r->i_inc; - } - i_ptr += 2; - } - r->acc[0] = acc0; - r->acc[1] = acc1; + acc0 = b * i_ptr[0]; + acc1 = b * i_ptr[1]; + } else { + acc0 += i_ptr[0] * r->i_inc; + acc1 += i_ptr[1] * r->i_inc; + } + i_ptr += 2; + } + r->acc[0] = acc0; + r->acc[1] = acc1; - if (o_count != r->o_samples) { - printf("handled %d out samples (expected %d)\n", o_count, - r->o_samples); - } + if (o_count != r->o_samples) { + printf ("handled %d out samples (expected %d)\n", o_count, r->o_samples); + } } -void gst_resample_sinc_slow_float(gst_resample_t * r) +void +gst_resample_sinc_slow_float (gst_resample_t * r) { - float *i_ptr, *o_ptr; - int i, j; - double c0, c1; - double a; - int start; - double center; - double weight; + float *i_ptr, *o_ptr; + int i, j; + double c0, c1; + double a; + int start; + double center; + double weight; - if (!r->buffer) { - int size = r->filter_length * sizeof(float) * r->channels; + if (!r->buffer) { + int size = r->filter_length * sizeof (float) * r->channels; - printf("gst_resample temp buffer\n"); - r->buffer = malloc(size); - memset(r->buffer, 0, size); - } + printf ("gst_resample temp buffer\n"); + r->buffer = malloc (size); + memset (r->buffer, 0, size); + } - i_ptr = (float *) r->i_buf; - o_ptr = (float *) r->o_buf; + i_ptr = (float *) r->i_buf; + o_ptr = (float *) r->o_buf; - a = r->i_start; + a = r->i_start; #define GETBUF(index,chan) (((index)<0) \ ? ((float *)(r->buffer))[((index)+r->filter_length)*2+(chan)] \ : i_ptr[(index)*2+(chan)]) - { - double sinx, cosx, sind, cosd; - double x, d; - double t; + { + double sinx, cosx, sind, cosd; + double x, d; + double t; - for (i = 0; i < r->o_samples; i++) { - start = floor(a) - r->filter_length; - center = a - r->halftaps; - x = M_PI * (start - center) * r->o_inc; - sinx = sin(M_PI * (start - center) * r->o_inc); - cosx = cos(M_PI * (start - center) * r->o_inc); - d = M_PI * r->o_inc; - sind = sin(M_PI * r->o_inc); - cosd = cos(M_PI * r->o_inc); - c0 = 0; - c1 = 0; - for (j = 0; j < r->filter_length; j++) { - weight = (x==0)?1:(sinx/x); + for (i = 0; i < r->o_samples; i++) { + start = floor (a) - r->filter_length; + center = a - r->halftaps; + x = M_PI * (start - center) * r->o_inc; + sinx = sin (M_PI * (start - center) * r->o_inc); + cosx = cos (M_PI * (start - center) * r->o_inc); + d = M_PI * r->o_inc; + sind = sin (M_PI * r->o_inc); + cosd = cos (M_PI * r->o_inc); + c0 = 0; + c1 = 0; + for (j = 0; j < r->filter_length; j++) { + weight = (x == 0) ? 1 : (sinx / x); /*printf("j %d sin %g cos %g\n",j,sinx,cosx); */ /*printf("j %d sin %g x %g sinc %g\n",j,sinx,x,weight); */ - c0 += weight * GETBUF((start + j), 0); - c1 += weight * GETBUF((start + j), 1); - t = cosx * cosd - sinx * sind; - sinx = cosx * sind + sinx * cosd; - cosx = t; - x += d; - } - o_ptr[0] = c0; - o_ptr[1] = c1; - o_ptr += 2; - a += r->o_inc; - } - } + c0 += weight * GETBUF ((start + j), 0); + c1 += weight * GETBUF ((start + j), 1); + t = cosx * cosd - sinx * sind; + sinx = cosx * sind + sinx * cosd; + cosx = t; + x += d; + } + o_ptr[0] = c0; + o_ptr[1] = c1; + o_ptr += 2; + a += r->o_inc; + } + } #undef GETBUF - memcpy(r->buffer, - i_ptr + (r->i_samples - r->filter_length) * r->channels, - r->filter_length * sizeof(float) * r->channels); + memcpy (r->buffer, + i_ptr + (r->i_samples - r->filter_length) * r->channels, + r->filter_length * sizeof (float) * r->channels); } /* only works for channels == 2 ???? */ -void gst_resample_sinc_float(gst_resample_t * r) +void +gst_resample_sinc_float (gst_resample_t * r) { - double *ptr; - float *o_ptr; - int i, j; - double c0, c1; - double a; - int start; - double center; - double weight; - double x0, x, d; - double scale; + double *ptr; + float *o_ptr; + int i, j; + double c0, c1; + double a; + int start; + double center; + double weight; + double x0, x, d; + double scale; - ptr = (double *) r->buffer; - o_ptr = (float *) r->o_buf; + ptr = (double *) r->buffer; + o_ptr = (float *) r->o_buf; - /* scale provides a cutoff frequency for the low - * pass filter aspects of sinc(). scale=M_PI - * will cut off at the input frequency, which is - * good for up-sampling, but will cause aliasing - * for downsampling. Downsampling needs to be - * cut off at o_rate, thus scale=M_PI*r->i_inc. */ - /* actually, it needs to be M_PI*r->i_inc*r->i_inc. - * Need to research why. */ - scale = M_PI*r->i_inc; - for (i = 0; i < r->o_samples; i++) { - a = r->o_start + i * r->o_inc; - start = floor(a - r->halftaps); + /* scale provides a cutoff frequency for the low + * pass filter aspects of sinc(). scale=M_PI + * will cut off at the input frequency, which is + * good for up-sampling, but will cause aliasing + * for downsampling. Downsampling needs to be + * cut off at o_rate, thus scale=M_PI*r->i_inc. */ + /* actually, it needs to be M_PI*r->i_inc*r->i_inc. + * Need to research why. */ + scale = M_PI * r->i_inc; + for (i = 0; i < r->o_samples; i++) { + a = r->o_start + i * r->o_inc; + start = floor (a - r->halftaps); /*printf("%d: a=%g start=%d end=%d\n",i,a,start,start+r->filter_length-1); */ - center = a; - /*x = M_PI * (start - center) * r->o_inc; */ - /*d = M_PI * r->o_inc; */ - /*x = (start - center) * r->o_inc; */ - x0 = (start - center) * r->o_inc; - d = r->o_inc; - c0 = 0; - c1 = 0; - for (j = 0; j < r->filter_length; j++) { - x = x0 + d * j; - weight = sinc(x*scale*r->i_inc)*scale/M_PI; - weight *= window_func(x/r->halftaps*r->i_inc); - c0 += weight * ptr[(start + j + r->filter_length)*2 + 0]; - c1 += weight * ptr[(start + j + r->filter_length)*2 + 1]; - } - o_ptr[0] = c0; - o_ptr[1] = c1; - o_ptr += 2; - } + center = a; + /*x = M_PI * (start - center) * r->o_inc; */ + /*d = M_PI * r->o_inc; */ + /*x = (start - center) * r->o_inc; */ + x0 = (start - center) * r->o_inc; + d = r->o_inc; + c0 = 0; + c1 = 0; + for (j = 0; j < r->filter_length; j++) { + x = x0 + d * j; + weight = sinc (x * scale * r->i_inc) * scale / M_PI; + weight *= window_func (x / r->halftaps * r->i_inc); + c0 += weight * ptr[(start + j + r->filter_length) * 2 + 0]; + c1 += weight * ptr[(start + j + r->filter_length) * 2 + 1]; + } + o_ptr[0] = c0; + o_ptr[1] = c1; + o_ptr += 2; + } } -void gst_resample_sinc_ft_float(gst_resample_t * r) +void +gst_resample_sinc_ft_float (gst_resample_t * r) { - double *ptr; - float *o_ptr; - int i; - /*int j; */ - double c0, c1; - /*double a; */ - double start_f, start_x; - int start; - double center; - /*double weight; */ - double x, d; - double scale; - int n = 4; + double *ptr; + float *o_ptr; + int i; - scale = r->i_inc; /* cutoff at 22050 */ - /*scale = 1.0; // cutoff at 24000 */ - /*scale = r->i_inc * 0.5; // cutoff at 11025 */ + /*int j; */ + double c0, c1; - if(!ft){ - ft = malloc(sizeof(*ft)); - memset(ft,0,sizeof(*ft)); + /*double a; */ + double start_f, start_x; + int start; + double center; - ft->len = (r->filter_length + 2) * n; - ft->offset = 1.0 / n; - ft->start = - ft->len * 0.5 * ft->offset; + /*double weight; */ + double x, d; + double scale; + int n = 4; - ft->func_x = functable_sinc; - ft->func_dx = functable_dsinc; - ft->scale = M_PI * scale; + scale = r->i_inc; /* cutoff at 22050 */ + /*scale = 1.0; // cutoff at 24000 */ + /*scale = r->i_inc * 0.5; // cutoff at 11025 */ - ft->func2_x = functable_window_std; - ft->func2_dx = functable_window_dstd; - ft->scale2 = 1.0 / r->halftaps; - - functable_init(ft); + if (!ft) { + ft = malloc (sizeof (*ft)); + memset (ft, 0, sizeof (*ft)); - /*printf("len=%d offset=%g start=%g\n",ft->len,ft->offset,ft->start); */ - } + ft->len = (r->filter_length + 2) * n; + ft->offset = 1.0 / n; + ft->start = -ft->len * 0.5 * ft->offset; - ptr = r->buffer; - o_ptr = (float *) r->o_buf; + ft->func_x = functable_sinc; + ft->func_dx = functable_dsinc; + ft->scale = M_PI * scale; - center = r->o_start; - start_x = center - r->halftaps; - start_f = floor(start_x); - start_x -= start_f; - start = start_f; - for (i = 0; i < r->o_samples; i++) { - /*start_f = floor(center - r->halftaps); */ + ft->func2_x = functable_window_std; + ft->func2_dx = functable_window_dstd; + ft->scale2 = 1.0 / r->halftaps; + + functable_init (ft); + + /*printf("len=%d offset=%g start=%g\n",ft->len,ft->offset,ft->start); */ + } + + ptr = r->buffer; + o_ptr = (float *) r->o_buf; + + center = r->o_start; + start_x = center - r->halftaps; + start_f = floor (start_x); + start_x -= start_f; + start = start_f; + for (i = 0; i < r->o_samples; i++) { + /*start_f = floor(center - r->halftaps); */ /*printf("%d: a=%g start=%d end=%d\n",i,a,start,start+r->filter_length-1); */ - x = start_f - center; - d = 1; - c0 = 0; - c1 = 0; + x = start_f - center; + d = 1; + c0 = 0; + c1 = 0; /*#define slow */ #ifdef slow - for (j = 0; j < r->filter_length; j++) { - weight = functable_eval(ft,x)*scale; - /*weight = sinc(M_PI * scale * x)*scale*r->i_inc; */ - /*weight *= window_func(x / r->halftaps); */ - c0 += weight * ptr[(start + j + r->filter_length)*2 + 0]; - c1 += weight * ptr[(start + j + r->filter_length)*2 + 1]; - x += d; - } + for (j = 0; j < r->filter_length; j++) { + weight = functable_eval (ft, x) * scale; + /*weight = sinc(M_PI * scale * x)*scale*r->i_inc; */ + /*weight *= window_func(x / r->halftaps); */ + c0 += weight * ptr[(start + j + r->filter_length) * 2 + 0]; + c1 += weight * ptr[(start + j + r->filter_length) * 2 + 1]; + x += d; + } #else - functable_fir2(ft, - &c0,&c1, - x, n, - ptr+(start + r->filter_length)*2, - r->filter_length); - c0 *= scale; - c1 *= scale; + functable_fir2 (ft, + &c0, &c1, x, n, ptr + (start + r->filter_length) * 2, r->filter_length); + c0 *= scale; + c1 *= scale; #endif - out_tmp[2 * i + 0] = c0; - out_tmp[2 * i + 1] = c1; - center += r->o_inc; - start_x += r->o_inc; - while(start_x>=1.0){ - start_f++; - start_x -= 1.0; - start++; - } - } + out_tmp[2 * i + 0] = c0; + out_tmp[2 * i + 1] = c1; + center += r->o_inc; + start_x += r->o_inc; + while (start_x >= 1.0) { + start_f++; + start_x -= 1.0; + start++; + } + } - if(r->channels==2){ - conv_float_double(r->o_buf,out_tmp,2 * r->o_samples); - }else{ - conv_float_double_sstr(r->o_buf,out_tmp,r->o_samples,2 * sizeof(double)); - } + if (r->channels == 2) { + conv_float_double (r->o_buf, out_tmp, 2 * r->o_samples); + } else { + conv_float_double_sstr (r->o_buf, out_tmp, r->o_samples, + 2 * sizeof (double)); + } } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gstresample", - "Resampling routines for use in audio plugins", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -); - +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstresample", + "Resampling routines for use in audio plugins", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN); diff --git a/gst-libs/gst/resample/resample.h b/gst-libs/gst/resample/resample.h index 1c4216b3bf..699d7d3b00 100644 --- a/gst-libs/gst/resample/resample.h +++ b/gst-libs/gst/resample/resample.h @@ -21,76 +21,78 @@ #ifndef __GST_RESAMPLE_H__ #define __GST_RESAMPLE_H__ -typedef enum { - GST_RESAMPLE_NEAREST = 0, - GST_RESAMPLE_BILINEAR, - GST_RESAMPLE_SINC_SLOW, - GST_RESAMPLE_SINC, +typedef enum +{ + GST_RESAMPLE_NEAREST = 0, + GST_RESAMPLE_BILINEAR, + GST_RESAMPLE_SINC_SLOW, + GST_RESAMPLE_SINC, } gst_resample_method; -typedef enum { - GST_RESAMPLE_S16 = 0, - GST_RESAMPLE_FLOAT +typedef enum +{ + GST_RESAMPLE_S16 = 0, + GST_RESAMPLE_FLOAT } gst_resample_format; typedef struct gst_resample_s gst_resample_t; -struct gst_resample_s { - /* parameters */ +struct gst_resample_s +{ + /* parameters */ - gst_resample_method method; - int channels; - int verbose; - gst_resample_format format; + gst_resample_method method; + int channels; + int verbose; + gst_resample_format format; - int filter_length; + int filter_length; - double i_rate; - double o_rate; + double i_rate; + double o_rate; - void *priv; + void *priv; - void *(*get_buffer)(void *priv, unsigned int size); + void *(*get_buffer) (void *priv, unsigned int size); - /* internal parameters */ + /* internal parameters */ - double halftaps; + double halftaps; - /* filter state */ + /* filter state */ - void *buffer; - int buffer_len; + void *buffer; + int buffer_len; - double i_start; - double o_start; + double i_start; + double o_start; - double i_start_buf; - double i_end_buf; + double i_start_buf; + double i_end_buf; - double i_inc; - double o_inc; + double i_inc; + double o_inc; - double i_end; - double o_end; + double i_end; + double o_end; - int i_samples; - int o_samples; + int i_samples; + int o_samples; - void *i_buf, *o_buf; + void *i_buf, *o_buf; - double acc[10]; + double acc[10]; - /* methods */ - void (*scale)(gst_resample_t *r); + /* methods */ + void (*scale) (gst_resample_t * r); - double ack; + double ack; }; -void gst_resample_init(gst_resample_t *r); +void gst_resample_init (gst_resample_t * r); -void gst_resample_reinit(gst_resample_t *r); +void gst_resample_reinit (gst_resample_t * r); -void gst_resample_scale(gst_resample_t *r, void *i_buf, unsigned int size); +void gst_resample_scale (gst_resample_t * r, void *i_buf, unsigned int size); #endif /* __GST_RESAMPLE_H__ */ - diff --git a/gst-libs/gst/resample/test.c b/gst-libs/gst/resample/test.c index f268a59299..152d12a6f1 100644 --- a/gst-libs/gst/resample/test.c +++ b/gst-libs/gst/resample/test.c @@ -16,337 +16,360 @@ /*#define test_func(x) sin(2*M_PI*(x)*(x)*1000) */ #define test_func(x) sin(2*M_PI*(x)*(x)*12000) -short i_buf[I_RATE*2*2]; -short o_buf[O_RATE*2*2]; +short i_buf[I_RATE * 2 * 2]; +short o_buf[O_RATE * 2 * 2]; static int i_offset; static int o_offset; FILE *out; -void test_res1(void); -void test_res2(void); -void test_res3(void); -void test_res4(void); -void test_res5(void); -void test_res6(void); -void test_res7(void); +void test_res1 (void); +void test_res2 (void); +void test_res3 (void); +void test_res4 (void); +void test_res5 (void); +void test_res6 (void); +void test_res7 (void); -int main(int argc,char *argv[]) +int +main (int argc, char *argv[]) { - out = fopen("out","w"); + out = fopen ("out", "w"); - test_res7(); + test_res7 (); - return 0; + return 0; } -void *get_buffer(void *priv, unsigned int size) +void * +get_buffer (void *priv, unsigned int size) { - void *ret; - ret = ((void *)o_buf) + o_offset; - o_offset += size; - return ret; + void *ret; + + ret = ((void *) o_buf) + o_offset; + o_offset += size; + return ret; } struct timeval start_time; -void start_timer(void) +void +start_timer (void) { - gettimeofday(&start_time,NULL); - /*printf("start %ld.%06ld\n",start_time.tv_sec,start_time.tv_usec); */ + gettimeofday (&start_time, NULL); + /*printf("start %ld.%06ld\n",start_time.tv_sec,start_time.tv_usec); */ } -void end_timer(void) +void +end_timer (void) { - struct timeval end_time; - double diff; + struct timeval end_time; + double diff; - gettimeofday(&end_time,NULL); - /*printf("end %ld.%06ld\n",end_time.tv_sec,end_time.tv_usec); */ - diff = (end_time.tv_sec - start_time.tv_sec) + - 1e-6*(end_time.tv_usec - start_time.tv_usec); + gettimeofday (&end_time, NULL); + /*printf("end %ld.%06ld\n",end_time.tv_sec,end_time.tv_usec); */ + diff = (end_time.tv_sec - start_time.tv_sec) + + 1e-6 * (end_time.tv_usec - start_time.tv_usec); - printf("time %g\n",diff); + printf ("time %g\n", diff); } -void test_res1(void) +void +test_res1 (void) { - resample_t *r; - int i; - double sum10k,sum22k; - double f; - int n10k,n22k; - double x; + resample_t *r; + int i; + double sum10k, sum22k; + double f; + int n10k, n22k; + double x; - for(i=0;ii_rate = I_RATE; - r->o_rate = O_RATE; - /*r->method = RESAMPLE_SINC_SLOW; */ - r->method = RESAMPLE_SINC; - r->channels = 2; - /*r->verbose = 1; */ - r->filter_length = 64; - r->get_buffer = get_buffer; + r->i_rate = I_RATE; + r->o_rate = O_RATE; + /*r->method = RESAMPLE_SINC_SLOW; */ + r->method = RESAMPLE_SINC; + r->channels = 2; + /*r->verbose = 1; */ + r->filter_length = 64; + r->get_buffer = get_buffer; - resample_init(r); + resample_init (r); - start_timer(); + start_timer (); #define blocked #ifdef blocked - for(i=0;i+256start = -50.0; - t->offset = 1; - t->len = 100; + t->start = -50.0; + t->offset = 1; + t->len = 100; - t->func_x = functable_sinc; - t->func_dx = functable_dsinc; + t->func_x = functable_sinc; + t->func_dx = functable_dsinc; - functable_init(t); + functable_init (t); - for(i=0;i<1000;i++){ - x = -50.0 + 0.1 * i; - f1 = functable_sinc(NULL,x); - f2 = functable_eval(t,x); - fprintf(out,"%d %g %g %g\n",i,f1,f2,f1-f2); - } + for (i = 0; i < 1000; i++) { + x = -50.0 + 0.1 * i; + f1 = functable_sinc (NULL, x); + f2 = functable_eval (t, x); + fprintf (out, "%d %g %g %g\n", i, f1, f2, f1 - f2); + } } -void test_res3(void) +void +test_res3 (void) { - functable_t *t; - int i; - double x; - double f1,f2; - int n = 1; + functable_t *t; + int i; + double x; + double f1, f2; + int n = 1; - t = malloc(sizeof(*t)); - memset(t,0,sizeof(*t)); + t = malloc (sizeof (*t)); + memset (t, 0, sizeof (*t)); - t->start = -50.0; - t->offset = 1.0 / n; - t->len = 100 * n; + t->start = -50.0; + t->offset = 1.0 / n; + t->len = 100 * n; - t->func_x = functable_sinc; - t->func_dx = functable_dsinc; + t->func_x = functable_sinc; + t->func_dx = functable_dsinc; - t->func2_x = functable_window_std; - t->func2_dx = functable_window_dstd; + t->func2_x = functable_window_std; + t->func2_dx = functable_window_dstd; - t->scale = 1.0; - t->scale2 = 1.0 / (M_PI * 16); + t->scale = 1.0; + t->scale2 = 1.0 / (M_PI * 16); - functable_init(t); + functable_init (t); - for(i=0;i<1000 * n;i++){ - x = -50.0 + 0.1/n * i; - f1 = functable_sinc(NULL,t->scale * x) * - functable_window_std(NULL,t->scale2 * x); - f2 = functable_eval(t,x); - fprintf(out,"%d %g %g %g\n",i,f1,f2,f2-f1); - } + for (i = 0; i < 1000 * n; i++) { + x = -50.0 + 0.1 / n * i; + f1 = functable_sinc (NULL, t->scale * x) * + functable_window_std (NULL, t->scale2 * x); + f2 = functable_eval (t, x); + fprintf (out, "%d %g %g %g\n", i, f1, f2, f2 - f1); + } } -double sinc_poly(double x) +double +sinc_poly (double x) { #define INV3FAC 1.66666666666666666e-1 #define INV5FAC 8.33333333333333333e-3 #define INV7FAC 1.984126984e-4 #define INV9FAC 2.755731922e-6 #define INV11FAC 2.505210839e-8 - double x2 = x * x; + double x2 = x * x; - return 1 - - x2 * INV3FAC - + x2 * x2 * INV5FAC - - x2 * x2 * x2 * INV7FAC; - /*+ x2 * x2 * x2 * x2 * INV9FAC */ + return 1 - x2 * INV3FAC + x2 * x2 * INV5FAC - x2 * x2 * x2 * INV7FAC; + /*+ x2 * x2 * x2 * x2 * INV9FAC */ /*- x2 * x2 * x2 * x2 * x2 * INV11FAC; */ } -void test_res4(void) +void +test_res4 (void) { - int i; - double x,f1,f2; + int i; + double x, f1, f2; - for(i=1;i<100;i++){ - x = 0.01 * i; - f1 = 1 - sin(x)/x; - f2 = 1 - sinc_poly(x); - - fprintf(out,"%g %.20g %.20g %.20g\n",x,f1,f2,f2-f1); - } + for (i = 1; i < 100; i++) { + x = 0.01 * i; + f1 = 1 - sin (x) / x; + f2 = 1 - sinc_poly (x); + + fprintf (out, "%g %.20g %.20g %.20g\n", x, f1, f2, f2 - f1); + } } -void test_res5(void) +void +test_res5 (void) { - int i; - double sum; + int i; + double sum; - start_timer(); - sum = 0; - for(i=0;ii_rate = I_RATE; - r->o_rate = O_RATE; - /*r->method = RESAMPLE_SINC_SLOW; */ - r->method = RESAMPLE_SINC; - r->channels = 1; - /*r->verbose = 1; */ - r->filter_length = 64; - r->get_buffer = get_buffer; + r->i_rate = I_RATE; + r->o_rate = O_RATE; + /*r->method = RESAMPLE_SINC_SLOW; */ + r->method = RESAMPLE_SINC; + r->channels = 1; + /*r->verbose = 1; */ + r->filter_length = 64; + r->get_buffer = get_buffer; - resample_init(r); + resample_init (r); - start_timer(); + start_timer (); #define blocked #ifdef blocked - for(i=0;i+256width, - "height", G_TYPE_INT, strf->height, - NULL); + "width", G_TYPE_INT, strf->width, + "height", G_TYPE_INT, strf->height, NULL); } else { gst_caps_set_simple (caps, - "width", GST_TYPE_INT_RANGE, 16, 4096, - "height", GST_TYPE_INT_RANGE, 16, 4096, - NULL); + "width", GST_TYPE_INT_RANGE, 16, 4096, + "height", GST_TYPE_INT_RANGE, 16, 4096, NULL); } return caps; } GstCaps * -gst_riff_create_audio_caps (guint16 codec_id, - gst_riff_strh *strh, - gst_riff_strf_auds *strf, - char **codec_name) +gst_riff_create_audio_caps (guint16 codec_id, + gst_riff_strh * strh, gst_riff_strf_auds * strf, char **codec_name) { GstCaps *caps = NULL; switch (codec_id) { - case GST_RIFF_WAVE_FORMAT_MPEGL3: /* mp3 */ + case GST_RIFF_WAVE_FORMAT_MPEGL3: /* mp3 */ caps = gst_caps_new_simple ("audio/mpeg", - "mpegversion", G_TYPE_INT, 1, - "layer", G_TYPE_INT, 3, - NULL); + "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL); if (codec_name) - *codec_name = g_strdup ("MPEG 1 layer 3"); + *codec_name = g_strdup ("MPEG 1 layer 3"); break; - case GST_RIFF_WAVE_FORMAT_MPEGL12: /* mp1 or mp2 */ + case GST_RIFF_WAVE_FORMAT_MPEGL12: /* mp1 or mp2 */ caps = gst_caps_new_simple ("audio/mpeg", - "mpegversion", G_TYPE_INT, 1, - "layer", G_TYPE_INT, 2, - NULL); + "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL); if (codec_name) - *codec_name = g_strdup ("MPEG 1 layer 2"); + *codec_name = g_strdup ("MPEG 1 layer 2"); break; - case GST_RIFF_WAVE_FORMAT_PCM: /* PCM/wav */ + case GST_RIFF_WAVE_FORMAT_PCM: /* PCM/wav */ if (strf != NULL) { - gint ba = GUINT16_FROM_LE (strf->blockalign); - gint ch = GUINT16_FROM_LE (strf->channels); - gint ws = GUINT16_FROM_LE (strf->size); + gint ba = GUINT16_FROM_LE (strf->blockalign); + gint ch = GUINT16_FROM_LE (strf->channels); + gint ws = GUINT16_FROM_LE (strf->size); - caps = gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, - "width", G_TYPE_INT, (int)(ba * 8 / ch), - "depth", G_TYPE_INT, ws, - "signed", G_TYPE_BOOLEAN, ws != 8, - NULL); + caps = gst_caps_new_simple ("audio/x-raw-int", + "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, + "width", G_TYPE_INT, (int) (ba * 8 / ch), + "depth", G_TYPE_INT, ws, "signed", G_TYPE_BOOLEAN, ws != 8, NULL); } else { - caps = gst_caps_from_string ("audio/x-raw-int, " - "endianness = (int) LITTLE_ENDIAN, " - "signed = (boolean) { true, false }, " - "width = (int) { 8, 16 }, " - "height = (int) { 8, 16 }"); + caps = gst_caps_from_string ("audio/x-raw-int, " + "endianness = (int) LITTLE_ENDIAN, " + "signed = (boolean) { true, false }, " + "width = (int) { 8, 16 }, " "height = (int) { 8, 16 }"); } if (codec_name) - *codec_name = g_strdup ("PCM WAV"); + *codec_name = g_strdup ("PCM WAV"); break; case GST_RIFF_WAVE_FORMAT_MULAW: if (strf != NULL && strf->size != 8) { - GST_WARNING ("invalid depth (%d) of mulaw audio, overwriting.", - strf->size); + GST_WARNING ("invalid depth (%d) of mulaw audio, overwriting.", + strf->size); } caps = gst_caps_new_simple ("audio/x-mulaw", NULL); if (codec_name) - *codec_name = g_strdup ("Mulaw"); + *codec_name = g_strdup ("Mulaw"); break; case GST_RIFF_WAVE_FORMAT_ALAW: if (strf != NULL && strf->size != 8) { - GST_WARNING ("invalid depth (%d) of alaw audio, overwriting.", - strf->size); + GST_WARNING ("invalid depth (%d) of alaw audio, overwriting.", + strf->size); } caps = gst_caps_new_simple ("audio/x-alaw", NULL); if (codec_name) - *codec_name = g_strdup ("Alaw"); + *codec_name = g_strdup ("Alaw"); break; - case GST_RIFF_WAVE_FORMAT_VORBIS1: /* ogg/vorbis mode 1 */ - case GST_RIFF_WAVE_FORMAT_VORBIS2: /* ogg/vorbis mode 2 */ - case GST_RIFF_WAVE_FORMAT_VORBIS3: /* ogg/vorbis mode 3 */ - case GST_RIFF_WAVE_FORMAT_VORBIS1PLUS: /* ogg/vorbis mode 1+ */ - case GST_RIFF_WAVE_FORMAT_VORBIS2PLUS: /* ogg/vorbis mode 2+ */ - case GST_RIFF_WAVE_FORMAT_VORBIS3PLUS: /* ogg/vorbis mode 3+ */ + case GST_RIFF_WAVE_FORMAT_VORBIS1: /* ogg/vorbis mode 1 */ + case GST_RIFF_WAVE_FORMAT_VORBIS2: /* ogg/vorbis mode 2 */ + case GST_RIFF_WAVE_FORMAT_VORBIS3: /* ogg/vorbis mode 3 */ + case GST_RIFF_WAVE_FORMAT_VORBIS1PLUS: /* ogg/vorbis mode 1+ */ + case GST_RIFF_WAVE_FORMAT_VORBIS2PLUS: /* ogg/vorbis mode 2+ */ + case GST_RIFF_WAVE_FORMAT_VORBIS3PLUS: /* ogg/vorbis mode 3+ */ caps = gst_caps_new_simple ("audio/x-vorbis", NULL); if (codec_name) - *codec_name = g_strdup ("Vorbis"); + *codec_name = g_strdup ("Vorbis"); break; case GST_RIFF_WAVE_FORMAT_A52: caps = gst_caps_new_simple ("audio/x-ac3", NULL); if (codec_name) - *codec_name = g_strdup ("AC3"); + *codec_name = g_strdup ("AC3"); break; default: - GST_WARNING ("Unkown audio tag 0x%04x", - codec_id); + GST_WARNING ("Unkown audio tag 0x%04x", codec_id); break; } if (strf != NULL) { gst_caps_set_simple (caps, - "rate", G_TYPE_INT, strf->rate, - "channels", G_TYPE_INT, strf->channels, - NULL); + "rate", G_TYPE_INT, strf->rate, + "channels", G_TYPE_INT, strf->channels, NULL); } else { gst_caps_set_simple (caps, - "rate", GST_TYPE_INT_RANGE, 8000, 96000, - "channels", GST_TYPE_INT_RANGE, 1, 2, - NULL); + "rate", GST_TYPE_INT_RANGE, 8000, 96000, + "channels", GST_TYPE_INT_RANGE, 1, 2, NULL); } return caps; } GstCaps * -gst_riff_create_iavs_caps (guint32 codec_fcc, - gst_riff_strh *strh, - gst_riff_strf_iavs *strf, - char **codec_name) +gst_riff_create_iavs_caps (guint32 codec_fcc, + gst_riff_strh * strh, gst_riff_strf_iavs * strf, char **codec_name) { GstCaps *caps = NULL; switch (codec_fcc) { - /* is this correct? */ - case GST_MAKE_FOURCC ('D','V','S','D'): - case GST_MAKE_FOURCC ('d','v','s','d'): - caps = gst_caps_new_simple ("video/x-dv", - "systemstream", G_TYPE_BOOLEAN, TRUE, NULL); + /* is this correct? */ + case GST_MAKE_FOURCC ('D', 'V', 'S', 'D'): + case GST_MAKE_FOURCC ('d', 'v', 's', 'd'): + caps = gst_caps_new_simple ("video/x-dv", + "systemstream", G_TYPE_BOOLEAN, TRUE, NULL); if (codec_name) - *codec_name = g_strdup ("Generic DV"); + *codec_name = g_strdup ("Generic DV"); default: GST_WARNING ("Unkown IAVS fourcc " GST_FOURCC_FORMAT, - GST_FOURCC_ARGS (codec_fcc)); + GST_FOURCC_ARGS (codec_fcc)); return NULL; } @@ -389,22 +357,22 @@ GstCaps * gst_riff_create_video_template_caps (void) { guint32 tags[] = { - GST_MAKE_FOURCC ('I','4','2','0'), - GST_MAKE_FOURCC ('Y','U','Y','2'), - GST_MAKE_FOURCC ('M','J','P','G'), - GST_MAKE_FOURCC ('D','V','S','D'), - GST_MAKE_FOURCC ('W','M','V','1'), - GST_MAKE_FOURCC ('W','M','V','2'), - GST_MAKE_FOURCC ('M','P','G','4'), - GST_MAKE_FOURCC ('M','P','4','2'), - GST_MAKE_FOURCC ('M','P','4','3'), - GST_MAKE_FOURCC ('H','F','Y','U'), - GST_MAKE_FOURCC ('D','I','V','3'), - GST_MAKE_FOURCC ('M','P','E','G'), - GST_MAKE_FOURCC ('H','2','6','3'), - GST_MAKE_FOURCC ('D','I','V','X'), - GST_MAKE_FOURCC ('X','V','I','D'), - GST_MAKE_FOURCC ('3','I','V','1'), + GST_MAKE_FOURCC ('I', '4', '2', '0'), + GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'), + GST_MAKE_FOURCC ('M', 'J', 'P', 'G'), + GST_MAKE_FOURCC ('D', 'V', 'S', 'D'), + GST_MAKE_FOURCC ('W', 'M', 'V', '1'), + GST_MAKE_FOURCC ('W', 'M', 'V', '2'), + GST_MAKE_FOURCC ('M', 'P', 'G', '4'), + GST_MAKE_FOURCC ('M', 'P', '4', '2'), + GST_MAKE_FOURCC ('M', 'P', '4', '3'), + GST_MAKE_FOURCC ('H', 'F', 'Y', 'U'), + GST_MAKE_FOURCC ('D', 'I', 'V', '3'), + GST_MAKE_FOURCC ('M', 'P', 'E', 'G'), + GST_MAKE_FOURCC ('H', '2', '6', '3'), + GST_MAKE_FOURCC ('D', 'I', 'V', 'X'), + GST_MAKE_FOURCC ('X', 'V', 'I', 'D'), + GST_MAKE_FOURCC ('3', 'I', 'V', '1'), /* FILL ME */ 0 }; @@ -452,7 +420,7 @@ GstCaps * gst_riff_create_iavs_template_caps (void) { guint32 tags[] = { - GST_MAKE_FOURCC ('D','V','S','D'), + GST_MAKE_FOURCC ('D', 'V', 'S', 'D'), /* FILL ME */ 0 }; diff --git a/gst-libs/gst/riff/riff-media.h b/gst-libs/gst/riff/riff-media.h index 220671afb8..ca4a943434 100644 --- a/gst-libs/gst/riff/riff-media.h +++ b/gst-libs/gst/riff/riff-media.h @@ -27,23 +27,15 @@ #include "riff-ids.h" G_BEGIN_DECLS - /* * Create one caps. strh/strf can be NULL (for non-fixed caps). */ - -GstCaps *gst_riff_create_video_caps (guint32 codec_fcc, - gst_riff_strh *strh, - gst_riff_strf_vids *strf, - char **codec_name); -GstCaps *gst_riff_create_audio_caps (guint16 codec_id, - gst_riff_strh *strh, - gst_riff_strf_auds *strf, - char **codec_name); -GstCaps *gst_riff_create_iavs_caps (guint32 codec_fcc, - gst_riff_strh *strh, - gst_riff_strf_iavs *strf, - char **codec_name); + GstCaps * gst_riff_create_video_caps (guint32 codec_fcc, + gst_riff_strh * strh, gst_riff_strf_vids * strf, char **codec_name); +GstCaps *gst_riff_create_audio_caps (guint16 codec_id, + gst_riff_strh * strh, gst_riff_strf_auds * strf, char **codec_name); +GstCaps *gst_riff_create_iavs_caps (guint32 codec_fcc, + gst_riff_strh * strh, gst_riff_strf_iavs * strf, char **codec_name); /* * Create template caps (includes all known types). @@ -51,8 +43,7 @@ GstCaps *gst_riff_create_iavs_caps (guint32 codec_fcc, GstCaps *gst_riff_create_video_template_caps (void); GstCaps *gst_riff_create_audio_template_caps (void); -GstCaps *gst_riff_create_iavs_template_caps (void); +GstCaps *gst_riff_create_iavs_template_caps (void); G_END_DECLS - #endif /* __GST_RIFF_READ_H__ */ diff --git a/gst-libs/gst/riff/riff-read.c b/gst-libs/gst/riff/riff-read.c index 6f282c5171..c8c5b634ec 100644 --- a/gst-libs/gst/riff/riff-read.c +++ b/gst-libs/gst/riff/riff-read.c @@ -28,28 +28,28 @@ #include "riff-ids.h" #include "riff-read.h" -enum { +enum +{ ARG_0, ARG_METADATA - /* FILL ME */ + /* FILL ME */ }; -static void gst_riff_read_class_init (GstRiffReadClass *klass); -static void gst_riff_read_init (GstRiffRead *riff); +static void gst_riff_read_class_init (GstRiffReadClass * klass); +static void gst_riff_read_init (GstRiffRead * riff); -static GstElementStateReturn - gst_riff_read_change_state (GstElement *element); +static GstElementStateReturn gst_riff_read_change_state (GstElement * element); static GstElementClass *parent_class = NULL; GType -gst_riff_read_get_type (void) +gst_riff_read_get_type (void) { static GType gst_riff_read_type = 0; if (!gst_riff_read_type) { static const GTypeInfo gst_riff_read_info = { - sizeof (GstRiffReadClass), + sizeof (GstRiffReadClass), NULL, NULL, (GClassInitFunc) gst_riff_read_class_init, @@ -62,24 +62,24 @@ gst_riff_read_get_type (void) gst_riff_read_type = g_type_register_static (GST_TYPE_ELEMENT, "GstRiffRead", - &gst_riff_read_info, 0); + &gst_riff_read_info, 0); } return gst_riff_read_type; } static void -gst_riff_read_class_init (GstRiffReadClass *klass) +gst_riff_read_class_init (GstRiffReadClass * klass) { GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - + gstelement_class->change_state = gst_riff_read_change_state; } static void -gst_riff_read_init (GstRiffRead *riff) +gst_riff_read_init (GstRiffRead * riff) { riff->sinkpad = NULL; riff->bs = NULL; @@ -87,23 +87,23 @@ gst_riff_read_init (GstRiffRead *riff) } static GstElementStateReturn -gst_riff_read_change_state (GstElement *element) +gst_riff_read_change_state (GstElement * element) { GstRiffRead *riff = GST_RIFF_READ (element); switch (GST_STATE_TRANSITION (element)) { case GST_STATE_READY_TO_PAUSED: if (!riff->sinkpad) - return GST_STATE_FAILURE; + return GST_STATE_FAILURE; riff->bs = gst_bytestream_new (riff->sinkpad); break; case GST_STATE_PAUSED_TO_READY: gst_bytestream_destroy (riff->bs); while (riff->level) { - GstRiffLevel *level = riff->level->data; + GstRiffLevel *level = riff->level->data; - riff->level = g_list_remove (riff->level, level); - g_free (level); + riff->level = g_list_remove (riff->level, level); + g_free (level); } break; default: @@ -124,7 +124,7 @@ gst_riff_read_change_state (GstElement *element) */ static guint -gst_riff_read_element_level_up (GstRiffRead *riff) +gst_riff_read_element_level_up (GstRiffRead * riff) { guint num = 0; guint64 pos = gst_bytestream_tell (riff->bs); @@ -150,10 +150,8 @@ gst_riff_read_element_level_up (GstRiffRead *riff) */ static gboolean -gst_riff_peek_head (GstRiffRead *riff, - guint32 *tag, - guint32 *length, - guint *level_up) +gst_riff_peek_head (GstRiffRead * riff, + guint32 * tag, guint32 * length, guint * level_up) { guint8 *data; @@ -167,7 +165,7 @@ gst_riff_peek_head (GstRiffRead *riff, if (GST_IS_EVENT (event)) { gst_pad_event_default (riff->sinkpad, event); if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) - return FALSE; + return FALSE; } else { GST_ELEMENT_ERROR (riff, RESOURCE, READ, (NULL), (NULL)); return FALSE; @@ -192,8 +190,7 @@ gst_riff_peek_head (GstRiffRead *riff, */ static GstBuffer * -gst_riff_read_element_data (GstRiffRead *riff, - guint length) +gst_riff_read_element_data (GstRiffRead * riff, guint length) { GstBuffer *buf = NULL; @@ -218,8 +215,7 @@ gst_riff_read_element_data (GstRiffRead *riff, */ GstEvent * -gst_riff_read_seek (GstRiffRead *riff, - guint64 offset) +gst_riff_read_seek (GstRiffRead * riff, guint64 offset) { guint64 length = gst_bytestream_length (riff->bs); guint32 remaining; @@ -261,7 +257,7 @@ gst_riff_read_seek (GstRiffRead *riff, } else if (GST_EVENT_TYPE (event) != GST_EVENT_DISCONTINUOUS) { gst_pad_event_default (riff->sinkpad, event); if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) - return NULL; + return NULL; event = NULL; } } @@ -274,8 +270,7 @@ gst_riff_read_seek (GstRiffRead *riff, */ guint32 -gst_riff_peek_tag (GstRiffRead *riff, - guint *level_up) +gst_riff_peek_tag (GstRiffRead * riff, guint * level_up) { guint32 tag; @@ -290,7 +285,7 @@ gst_riff_peek_tag (GstRiffRead *riff, */ guint32 -gst_riff_peek_list (GstRiffRead *riff) +gst_riff_peek_list (GstRiffRead * riff) { guint32 lst; guint8 *data; @@ -315,7 +310,7 @@ gst_riff_peek_list (GstRiffRead *riff) */ gboolean -gst_riff_read_skip (GstRiffRead *riff) +gst_riff_read_skip (GstRiffRead * riff) { guint32 tag, length; GstEvent *event; @@ -346,7 +341,7 @@ gst_riff_read_skip (GstRiffRead *riff) /* no */ if (!(event = gst_riff_read_seek (riff, - gst_bytestream_tell (riff->bs) + length))) + gst_bytestream_tell (riff->bs) + length))) return FALSE; gst_event_unref (event); @@ -359,9 +354,7 @@ gst_riff_read_skip (GstRiffRead *riff) */ gboolean -gst_riff_read_data (GstRiffRead *riff, - guint32 *tag, - GstBuffer **buf) +gst_riff_read_data (GstRiffRead * riff, guint32 * tag, GstBuffer ** buf) { guint32 length; @@ -377,9 +370,7 @@ gst_riff_read_data (GstRiffRead *riff, */ gboolean -gst_riff_read_ascii (GstRiffRead *riff, - guint32 *tag, - gchar **str) +gst_riff_read_ascii (GstRiffRead * riff, guint32 * tag, gchar ** str) { GstBuffer *buf; @@ -400,8 +391,7 @@ gst_riff_read_ascii (GstRiffRead *riff, */ gboolean -gst_riff_read_strh (GstRiffRead *riff, - gst_riff_strh **header) +gst_riff_read_strh (GstRiffRead * riff, gst_riff_strh ** header) { guint32 tag; GstBuffer *buf; @@ -417,28 +407,27 @@ gst_riff_read_strh (GstRiffRead *riff, } if (GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strh)) { g_warning ("Too small strh (%d available, %d needed)", - GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strh)); + GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strh)); gst_buffer_unref (buf); return FALSE; } - strh = g_memdup (GST_BUFFER_DATA (buf), - GST_BUFFER_SIZE (buf)); + strh = g_memdup (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); gst_buffer_unref (buf); #if (G_BYTE_ORDER == G_BIG_ENDIAN) - strh->type = GUINT32_FROM_LE (strh->type); + strh->type = GUINT32_FROM_LE (strh->type); strh->fcc_handler = GUINT32_FROM_LE (strh->fcc_handler); - strh->flags = GUINT32_FROM_LE (strh->flags); - strh->priority = GUINT32_FROM_LE (strh->priority); + strh->flags = GUINT32_FROM_LE (strh->flags); + strh->priority = GUINT32_FROM_LE (strh->priority); strh->init_frames = GUINT32_FROM_LE (strh->init_frames); - strh->scale = GUINT32_FROM_LE (strh->scale); - strh->rate = GUINT32_FROM_LE (strh->rate); - strh->start = GUINT32_FROM_LE (strh->start); - strh->length = GUINT32_FROM_LE (strh->length); - strh->bufsize = GUINT32_FROM_LE (strh->bufsize); - strh->quality = GUINT32_FROM_LE (strh->quality); - strh->samplesize = GUINT32_FROM_LE (strh->samplesize); + strh->scale = GUINT32_FROM_LE (strh->scale); + strh->rate = GUINT32_FROM_LE (strh->rate); + strh->start = GUINT32_FROM_LE (strh->start); + strh->length = GUINT32_FROM_LE (strh->length); + strh->bufsize = GUINT32_FROM_LE (strh->bufsize); + strh->quality = GUINT32_FROM_LE (strh->quality); + strh->samplesize = GUINT32_FROM_LE (strh->samplesize); #endif /* avoid divisions by zero */ @@ -449,20 +438,19 @@ gst_riff_read_strh (GstRiffRead *riff, /* debug */ GST_INFO ("strh tag found"); - GST_INFO (" type " GST_FOURCC_FORMAT, - GST_FOURCC_ARGS (strh->type)); + GST_INFO (" type " GST_FOURCC_FORMAT, GST_FOURCC_ARGS (strh->type)); GST_INFO (" fcc_handler " GST_FOURCC_FORMAT, - GST_FOURCC_ARGS (strh->fcc_handler)); + GST_FOURCC_ARGS (strh->fcc_handler)); GST_INFO (" flags 0x%08x", strh->flags); - GST_INFO (" priority %d", strh->priority); - GST_INFO (" init_frames %d", strh->init_frames); - GST_INFO (" scale %d", strh->scale); - GST_INFO (" rate %d", strh->rate); - GST_INFO (" start %d", strh->start); - GST_INFO (" length %d", strh->length); - GST_INFO (" bufsize %d", strh->bufsize); - GST_INFO (" quality %d", strh->quality); - GST_INFO (" samplesize %d", strh->samplesize); + GST_INFO (" priority %d", strh->priority); + GST_INFO (" init_frames %d", strh->init_frames); + GST_INFO (" scale %d", strh->scale); + GST_INFO (" rate %d", strh->rate); + GST_INFO (" start %d", strh->start); + GST_INFO (" length %d", strh->length); + GST_INFO (" bufsize %d", strh->bufsize); + GST_INFO (" quality %d", strh->quality); + GST_INFO (" samplesize %d", strh->samplesize); *header = strh; @@ -470,8 +458,7 @@ gst_riff_read_strh (GstRiffRead *riff, } gboolean -gst_riff_read_strf_vids (GstRiffRead *riff, - gst_riff_strf_vids **header) +gst_riff_read_strf_vids (GstRiffRead * riff, gst_riff_strf_vids ** header) { guint32 tag; GstBuffer *buf; @@ -487,32 +474,31 @@ gst_riff_read_strf_vids (GstRiffRead *riff, } if (GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_vids)) { g_warning ("Too small strf_vids (%d available, %d needed)", - GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_vids)); + GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_vids)); gst_buffer_unref (buf); return FALSE; } - strf = g_memdup (GST_BUFFER_DATA (buf), - GST_BUFFER_SIZE (buf)); + strf = g_memdup (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); #if (G_BYTE_ORDER == G_BIG_ENDIAN) - strf->size = GUINT32_FROM_LE (strf->size); - strf->width = GUINT32_FROM_LE (strf->width); - strf->height = GUINT32_FROM_LE (strf->height); - strf->planes = GUINT16_FROM_LE (strf->planes); - strf->bit_cnt = GUINT16_FROM_LE (strf->bit_cnt); + strf->size = GUINT32_FROM_LE (strf->size); + strf->width = GUINT32_FROM_LE (strf->width); + strf->height = GUINT32_FROM_LE (strf->height); + strf->planes = GUINT16_FROM_LE (strf->planes); + strf->bit_cnt = GUINT16_FROM_LE (strf->bit_cnt); strf->compression = GUINT32_FROM_LE (strf->compression); - strf->image_size = GUINT32_FROM_LE (strf->image_size); + strf->image_size = GUINT32_FROM_LE (strf->image_size); strf->xpels_meter = GUINT32_FROM_LE (strf->xpels_meter); strf->ypels_meter = GUINT32_FROM_LE (strf->ypels_meter); - strf->num_colors = GUINT32_FROM_LE (strf->num_colors); - strf->imp_colors = GUINT32_FROM_LE (strf->imp_colors); + strf->num_colors = GUINT32_FROM_LE (strf->num_colors); + strf->imp_colors = GUINT32_FROM_LE (strf->imp_colors); #endif /* size checking */ if (strf->size > GST_BUFFER_SIZE (buf)) { g_warning ("strf_vids header gave %d bytes data, only %d available", - strf->size, GST_BUFFER_SIZE (buf)); + strf->size, GST_BUFFER_SIZE (buf)); strf->size = GST_BUFFER_SIZE (buf); } @@ -524,7 +510,7 @@ gst_riff_read_strf_vids (GstRiffRead *riff, GST_INFO (" planes %d", strf->planes); GST_INFO (" bit_cnt %d", strf->bit_cnt); GST_INFO (" compression " GST_FOURCC_FORMAT, - GST_FOURCC_ARGS (strf->compression)); + GST_FOURCC_ARGS (strf->compression)); GST_INFO (" image_size %d", strf->image_size); GST_INFO (" xpels_meter %d", strf->xpels_meter); GST_INFO (" ypels_meter %d", strf->ypels_meter); @@ -539,8 +525,7 @@ gst_riff_read_strf_vids (GstRiffRead *riff, } gboolean -gst_riff_read_strf_auds (GstRiffRead *riff, - gst_riff_strf_auds **header) +gst_riff_read_strf_auds (GstRiffRead * riff, gst_riff_strf_auds ** header) { guint32 tag; GstBuffer *buf; @@ -556,21 +541,20 @@ gst_riff_read_strf_auds (GstRiffRead *riff, } if (GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_auds)) { g_warning ("Too small strf_auds (%d available, %d needed)", - GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_auds)); + GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_auds)); gst_buffer_unref (buf); return FALSE; } - strf = g_memdup (GST_BUFFER_DATA (buf), - GST_BUFFER_SIZE (buf)); + strf = g_memdup (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); #if (G_BYTE_ORDER == G_BIG_ENDIAN) - strf->format = GUINT16_FROM_LE (strf->format); - strf->channels = GUINT16_FROM_LE (strf->channels); - strf->rate = GUINT32_FROM_LE (strf->rate); - strf->av_bps = GUINT32_FROM_LE (strf->av_bps); + strf->format = GUINT16_FROM_LE (strf->format); + strf->channels = GUINT16_FROM_LE (strf->channels); + strf->rate = GUINT32_FROM_LE (strf->rate); + strf->av_bps = GUINT32_FROM_LE (strf->av_bps); strf->blockalign = GUINT16_FROM_LE (strf->blockalign); - strf->size = GUINT16_FROM_LE (strf->size); + strf->size = GUINT16_FROM_LE (strf->size); #endif /* debug */ @@ -580,7 +564,7 @@ gst_riff_read_strf_auds (GstRiffRead *riff, GST_INFO (" rate %d", strf->rate); GST_INFO (" av_bps %d", strf->av_bps); GST_INFO (" blockalign %d", strf->blockalign); - GST_INFO (" size %d", strf->size); /* wordsize, not extrasize! */ + GST_INFO (" size %d", strf->size); /* wordsize, not extrasize! */ gst_buffer_unref (buf); @@ -590,8 +574,7 @@ gst_riff_read_strf_auds (GstRiffRead *riff, } gboolean -gst_riff_read_strf_iavs (GstRiffRead *riff, - gst_riff_strf_iavs **header) +gst_riff_read_strf_iavs (GstRiffRead * riff, gst_riff_strf_iavs ** header) { guint32 tag; GstBuffer *buf; @@ -607,22 +590,21 @@ gst_riff_read_strf_iavs (GstRiffRead *riff, } if (GST_BUFFER_SIZE (buf) < sizeof (gst_riff_strf_iavs)) { g_warning ("Too small strf_iavs (%d available, %d needed)", - GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_iavs)); + GST_BUFFER_SIZE (buf), (int) sizeof (gst_riff_strf_iavs)); gst_buffer_unref (buf); return FALSE; } - strf = g_memdup (GST_BUFFER_DATA (buf), - GST_BUFFER_SIZE (buf)); + strf = g_memdup (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); gst_buffer_unref (buf); #if (G_BYTE_ORDER == G_BIG_ENDIAN) - strf->DVAAuxSrc = GUINT32_FROM_LE (strf->DVAAuxSrc); - strf->DVAAuxCtl = GUINT32_FROM_LE (strf->DVAAuxCtl); - strf->DVAAuxSrc1 = GUINT32_FROM_LE (strf->DVAAuxSrc1); - strf->DVAAuxCtl1 = GUINT32_FROM_LE (strf->DVAAuxCtl1); - strf->DVVAuxSrc = GUINT32_FROM_LE (strf->DVVAuxSrc); - strf->DVVAuxCtl = GUINT32_FROM_LE (strf->DVVAuxCtl); + strf->DVAAuxSrc = GUINT32_FROM_LE (strf->DVAAuxSrc); + strf->DVAAuxCtl = GUINT32_FROM_LE (strf->DVAAuxCtl); + strf->DVAAuxSrc1 = GUINT32_FROM_LE (strf->DVAAuxSrc1); + strf->DVAAuxCtl1 = GUINT32_FROM_LE (strf->DVAAuxCtl1); + strf->DVVAuxSrc = GUINT32_FROM_LE (strf->DVVAuxSrc); + strf->DVVAuxCtl = GUINT32_FROM_LE (strf->DVVAuxCtl); strf->DVReserved1 = GUINT32_FROM_LE (strf->DVReserved1); strf->DVReserved2 = GUINT32_FROM_LE (strf->DVReserved2); #endif @@ -648,8 +630,7 @@ gst_riff_read_strf_iavs (GstRiffRead *riff, */ gboolean -gst_riff_read_list (GstRiffRead *riff, - guint32 *tag) +gst_riff_read_list (GstRiffRead * riff, guint32 * tag) { guint32 length, lst; GstRiffLevel *level; @@ -667,7 +648,7 @@ gst_riff_read_list (GstRiffRead *riff, return FALSE; } gst_bytestream_flush_fast (riff->bs, 4); - *tag = GUINT32_FROM_LE (* (guint32 *) data); + *tag = GUINT32_FROM_LE (*(guint32 *) data); /* remember level */ level = g_new (GstRiffLevel, 1); @@ -683,7 +664,7 @@ gst_riff_read_list (GstRiffRead *riff, */ gboolean -gst_riff_read_info (GstRiffRead *riff) +gst_riff_read_info (GstRiffRead * riff) { guint32 tag; guint64 end; @@ -713,100 +694,102 @@ gst_riff_read_info (GstRiffRead *riff) /* find out the type of metadata */ switch (tag) { case GST_RIFF_INFO_IARL: - type = GST_TAG_LOCATION; - break; + type = GST_TAG_LOCATION; + break; case GST_RIFF_INFO_IART: - type = GST_TAG_ARTIST; - break; + type = GST_TAG_ARTIST; + break; case GST_RIFF_INFO_ICMS: - type = NULL; /*"Commissioner";*/ - break; + type = NULL; /*"Commissioner"; */ + break; case GST_RIFF_INFO_ICMT: - type = GST_TAG_COMMENT; - break; + type = GST_TAG_COMMENT; + break; case GST_RIFF_INFO_ICOP: - type = GST_TAG_COPYRIGHT; - break; + type = GST_TAG_COPYRIGHT; + break; case GST_RIFF_INFO_ICRD: - type = GST_TAG_DATE; - break; + type = GST_TAG_DATE; + break; case GST_RIFF_INFO_ICRP: - type = NULL; /*"Cropped";*/ - break; + type = NULL; /*"Cropped"; */ + break; case GST_RIFF_INFO_IDIM: - type = NULL; /*"Dimensions";*/ - break; + type = NULL; /*"Dimensions"; */ + break; case GST_RIFF_INFO_IDPI: - type = NULL; /*"Dots per Inch";*/ - break; + type = NULL; /*"Dots per Inch"; */ + break; case GST_RIFF_INFO_IENG: - type = NULL; /*"Engineer";*/ - break; + type = NULL; /*"Engineer"; */ + break; case GST_RIFF_INFO_IGNR: - type = GST_TAG_GENRE; - break; + type = GST_TAG_GENRE; + break; case GST_RIFF_INFO_IKEY: - type = NULL; /*"Keywords";*/; - break; + type = NULL; /*"Keywords"; */ ; + break; case GST_RIFF_INFO_ILGT: - type = NULL; /*"Lightness";*/ - break; + type = NULL; /*"Lightness"; */ + break; case GST_RIFF_INFO_IMED: - type = NULL; /*"Medium";*/ - break; + type = NULL; /*"Medium"; */ + break; case GST_RIFF_INFO_INAM: - type = GST_TAG_TITLE; - break; + type = GST_TAG_TITLE; + break; case GST_RIFF_INFO_IPLT: - type = NULL; /*"Palette";*/ - break; + type = NULL; /*"Palette"; */ + break; case GST_RIFF_INFO_IPRD: - type = NULL; /*"Product";*/ - break; + type = NULL; /*"Product"; */ + break; case GST_RIFF_INFO_ISBJ: - type = NULL; /*"Subject";*/ - break; + type = NULL; /*"Subject"; */ + break; case GST_RIFF_INFO_ISFT: - type = GST_TAG_ENCODER; - break; + type = GST_TAG_ENCODER; + break; case GST_RIFF_INFO_ISHP: - type = NULL; /*"Sharpness";*/ - break; + type = NULL; /*"Sharpness"; */ + break; case GST_RIFF_INFO_ISRC: - type = GST_TAG_ISRC; - break; + type = GST_TAG_ISRC; + break; case GST_RIFF_INFO_ISRF: - type = NULL; /*"Source Form";*/ - break; + type = NULL; /*"Source Form"; */ + break; case GST_RIFF_INFO_ITCH: - type = NULL; /*"Technician";*/ - break; + type = NULL; /*"Technician"; */ + break; default: - type = NULL; - GST_WARNING ("Unknown INFO (metadata) tag entry " GST_FOURCC_FORMAT, - GST_FOURCC_ARGS (tag)); - break; + type = NULL; + GST_WARNING ("Unknown INFO (metadata) tag entry " GST_FOURCC_FORMAT, + GST_FOURCC_ARGS (tag)); + break; } if (type) { name = NULL; if (!gst_riff_read_ascii (riff, &tag, &name)) { - return FALSE; + return FALSE; } if (name && name[0] != '\0') { - GValue src = { 0 }, dest = { 0 }; - GType dest_type = gst_tag_get_type (type); + GValue src = { 0 } + , dest = { + 0}; + GType dest_type = gst_tag_get_type (type); - have_tags = TRUE; - g_value_init (&src, G_TYPE_STRING); - g_value_set_string (&src, name); - g_value_init (&dest, dest_type); - g_value_transform (&src, &dest); - g_value_unset (&src); - gst_tag_list_add_values (taglist, GST_TAG_MERGE_APPEND, - type, &dest, NULL); - g_value_unset (&dest); + have_tags = TRUE; + g_value_init (&src, G_TYPE_STRING); + g_value_set_string (&src, name); + g_value_init (&dest, dest_type); + g_value_transform (&src, &dest); + g_value_unset (&src); + gst_tag_list_add_values (taglist, GST_TAG_MERGE_APPEND, + type, &dest, NULL); + g_value_unset (&dest); } g_free (name); } else { @@ -821,10 +804,10 @@ gst_riff_read_info (GstRiffRead *riff) /* let the world know about this wonderful thing */ for (padlist = gst_element_get_pad_list (element); - padlist != NULL; padlist = padlist->next) { - if (GST_PAD_IS_SRC (padlist->data) && GST_PAD_IS_USABLE(padlist->data)) { - gst_event_ref (event); - gst_pad_push (GST_PAD (padlist->data), GST_DATA (event)); + padlist != NULL; padlist = padlist->next) { + if (GST_PAD_IS_SRC (padlist->data) && GST_PAD_IS_USABLE (padlist->data)) { + gst_event_ref (event); + gst_pad_push (GST_PAD (padlist->data), GST_DATA (event)); } } gst_event_unref (event); @@ -839,8 +822,7 @@ gst_riff_read_info (GstRiffRead *riff) */ gboolean -gst_riff_read_header (GstRiffRead *riff, - guint32 *doctype) +gst_riff_read_header (GstRiffRead * riff, guint32 * doctype) { GstRiffLevel *level; guint32 tag, length; @@ -861,7 +843,7 @@ gst_riff_read_header (GstRiffRead *riff, return FALSE; } gst_bytestream_flush_fast (riff->bs, 4); - *doctype = GUINT32_FROM_LE (* (guint32 *) data); + *doctype = GUINT32_FROM_LE (*(guint32 *) data); /* remember level */ level = g_new (GstRiffLevel, 1); diff --git a/gst-libs/gst/riff/riff-read.h b/gst-libs/gst/riff/riff-read.h index 9c663ccad0..41ae89e3a5 100644 --- a/gst-libs/gst/riff/riff-read.h +++ b/gst-libs/gst/riff/riff-read.h @@ -27,7 +27,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_RIFF_READ \ (gst_riff_read_get_type ()) #define GST_RIFF_READ(obj) \ @@ -40,13 +39,13 @@ G_BEGIN_DECLS (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RIFF_READ)) #define GST_RIFF_READ_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RIFF_READ, GstRiffReadClass)) - -typedef struct _GstRiffLevel { - guint64 start, - length; + typedef struct _GstRiffLevel +{ + guint64 start, length; } GstRiffLevel; -typedef struct _GstRiffRead { +typedef struct _GstRiffRead +{ GstElement parent; GstPad *sinkpad; @@ -55,43 +54,35 @@ typedef struct _GstRiffRead { GList *level; } GstRiffRead; -typedef struct _GstRiffReadClass { +typedef struct _GstRiffReadClass +{ GstElementClass parent; } GstRiffReadClass; -GType gst_riff_read_get_type (void); +GType gst_riff_read_get_type (void); -guint32 gst_riff_peek_tag (GstRiffRead *riff, - guint *level_up); -guint32 gst_riff_peek_list (GstRiffRead *riff); +guint32 gst_riff_peek_tag (GstRiffRead * riff, guint * level_up); +guint32 gst_riff_peek_list (GstRiffRead * riff); -GstEvent *gst_riff_read_seek (GstRiffRead *riff, - guint64 offset); -gboolean gst_riff_read_skip (GstRiffRead *riff); -gboolean gst_riff_read_data (GstRiffRead *riff, - guint32 *tag, - GstBuffer **buf); -gboolean gst_riff_read_ascii (GstRiffRead *riff, - guint32 *tag, - gchar **str); -gboolean gst_riff_read_list (GstRiffRead *riff, - guint32 *tag); -gboolean gst_riff_read_header (GstRiffRead *read, - guint32 *doctype); +GstEvent *gst_riff_read_seek (GstRiffRead * riff, guint64 offset); +gboolean gst_riff_read_skip (GstRiffRead * riff); +gboolean gst_riff_read_data (GstRiffRead * riff, + guint32 * tag, GstBuffer ** buf); +gboolean gst_riff_read_ascii (GstRiffRead * riff, guint32 * tag, gchar ** str); +gboolean gst_riff_read_list (GstRiffRead * riff, guint32 * tag); +gboolean gst_riff_read_header (GstRiffRead * read, guint32 * doctype); /* * Utility functions (including byteswapping). */ -gboolean gst_riff_read_strh (GstRiffRead *riff, - gst_riff_strh **header); -gboolean gst_riff_read_strf_vids (GstRiffRead *riff, - gst_riff_strf_vids **header); -gboolean gst_riff_read_strf_auds (GstRiffRead *riff, - gst_riff_strf_auds **header); -gboolean gst_riff_read_strf_iavs (GstRiffRead *riff, - gst_riff_strf_iavs **header); -gboolean gst_riff_read_info (GstRiffRead *riff); +gboolean gst_riff_read_strh (GstRiffRead * riff, gst_riff_strh ** header); +gboolean gst_riff_read_strf_vids (GstRiffRead * riff, + gst_riff_strf_vids ** header); +gboolean gst_riff_read_strf_auds (GstRiffRead * riff, + gst_riff_strf_auds ** header); +gboolean gst_riff_read_strf_iavs (GstRiffRead * riff, + gst_riff_strf_iavs ** header); +gboolean gst_riff_read_info (GstRiffRead * riff); G_END_DECLS - #endif /* __GST_RIFF_READ_H__ */ diff --git a/gst-libs/gst/riff/riff.c b/gst-libs/gst/riff/riff.c index 9c0ce2aeca..ab8d47b57f 100644 --- a/gst-libs/gst/riff/riff.c +++ b/gst-libs/gst/riff/riff.c @@ -26,19 +26,13 @@ #include static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return gst_library_load ("gstbytestream"); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "riff", - "RIFF I/O functions", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "riff", + "RIFF I/O functions", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) diff --git a/gst-libs/gst/tag/tag.h b/gst-libs/gst/tag/tag.h index 97eaf93618..bbab48c5b5 100644 --- a/gst-libs/gst/tag/tag.h +++ b/gst-libs/gst/tag/tag.h @@ -24,39 +24,30 @@ #include G_BEGIN_DECLS - - /* functions for vorbis comment manipulation */ + G_CONST_RETURN gchar * gst_tag_from_vorbis_tag (const gchar * vorbis_tag); +G_CONST_RETURN gchar *gst_tag_to_vorbis_tag (const gchar * gst_tag); +void gst_vorbis_tag_add (GstTagList * list, + const gchar * tag, const gchar * value); -G_CONST_RETURN gchar * gst_tag_from_vorbis_tag (const gchar * vorbis_tag); -G_CONST_RETURN gchar * gst_tag_to_vorbis_tag (const gchar * gst_tag); -void gst_vorbis_tag_add (GstTagList * list, - const gchar * tag, - const gchar * value); - -GList * gst_tag_to_vorbis_comments (const GstTagList * list, - const gchar * tag); +GList *gst_tag_to_vorbis_comments (const GstTagList * list, const gchar * tag); /* functions to convert GstBuffers with vorbiscomment contents to GstTagLists and back */ -GstTagList * gst_tag_list_from_vorbiscomment_buffer (const GstBuffer * buffer, - const guint8 * id_data, - const guint id_data_length, - gchar ** vendor_string); -GstBuffer * gst_tag_list_to_vorbiscomment_buffer (const GstTagList * list, - const guint8 * id_data, - const guint id_data_length, - const gchar * vendor_string); +GstTagList *gst_tag_list_from_vorbiscomment_buffer (const GstBuffer * buffer, + const guint8 * id_data, const guint id_data_length, gchar ** vendor_string); +GstBuffer *gst_tag_list_to_vorbiscomment_buffer (const GstTagList * list, + const guint8 * id_data, + const guint id_data_length, const gchar * vendor_string); /* functions for ID3 tag manipulation */ -guint gst_tag_id3_genre_count (void); -G_CONST_RETURN gchar * gst_tag_id3_genre_get (const guint id); -GstTagList * gst_tag_list_new_from_id3v1 (const guint8 * data); +guint gst_tag_id3_genre_count (void); +G_CONST_RETURN gchar *gst_tag_id3_genre_get (const guint id); +GstTagList *gst_tag_list_new_from_id3v1 (const guint8 * data); -G_CONST_RETURN gchar * gst_tag_from_id3_tag (const gchar * vorbis_tag); -G_CONST_RETURN gchar * gst_tag_to_id3_tag (const gchar * gst_tag); +G_CONST_RETURN gchar *gst_tag_from_id3_tag (const gchar * vorbis_tag); +G_CONST_RETURN gchar *gst_tag_to_id3_tag (const gchar * gst_tag); G_END_DECLS - #endif /* __GST_TAG_TAG_H__ */ diff --git a/gst-libs/gst/tuner/tuner.c b/gst-libs/gst/tuner/tuner.c index 1181bc137f..fd1c354f00 100644 --- a/gst-libs/gst/tuner/tuner.c +++ b/gst-libs/gst/tuner/tuner.c @@ -28,7 +28,8 @@ #include -enum { +enum +{ NORM_CHANGED, CHANNEL_CHANGED, FREQUENCY_CHANGED, @@ -36,7 +37,7 @@ enum { LAST_SIGNAL }; -static void gst_tuner_class_init (GstTunerClass *klass); +static void gst_tuner_class_init (GstTunerClass * klass); static guint gst_tuner_signals[LAST_SIGNAL] = { 0 }; @@ -59,49 +60,47 @@ gst_tuner_get_type (void) }; gst_tuner_type = g_type_register_static (G_TYPE_INTERFACE, - "GstTuner", - &gst_tuner_info, 0); + "GstTuner", &gst_tuner_info, 0); g_type_interface_add_prerequisite (gst_tuner_type, - GST_TYPE_IMPLEMENTS_INTERFACE); + GST_TYPE_IMPLEMENTS_INTERFACE); } return gst_tuner_type; } static void -gst_tuner_class_init (GstTunerClass *klass) +gst_tuner_class_init (GstTunerClass * klass) { static gboolean initialized = FALSE; if (!initialized) { gst_tuner_signals[NORM_CHANGED] = - g_signal_new ("norm-changed", - GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstTunerClass, norm_changed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - GST_TYPE_TUNER_NORM); + g_signal_new ("norm-changed", + GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstTunerClass, norm_changed), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_TUNER_NORM); gst_tuner_signals[CHANNEL_CHANGED] = - g_signal_new ("channel-changed", - GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstTunerClass, channel_changed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - GST_TYPE_TUNER_CHANNEL); + g_signal_new ("channel-changed", + GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstTunerClass, channel_changed), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, + GST_TYPE_TUNER_CHANNEL); gst_tuner_signals[FREQUENCY_CHANGED] = - g_signal_new ("frequency-changed", - GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstTunerClass, frequency_changed), - NULL, NULL, - gst_tuner_marshal_VOID__OBJECT_ULONG, G_TYPE_NONE, 2, - GST_TYPE_TUNER_CHANNEL, G_TYPE_ULONG); + g_signal_new ("frequency-changed", + GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstTunerClass, frequency_changed), + NULL, NULL, + gst_tuner_marshal_VOID__OBJECT_ULONG, G_TYPE_NONE, 2, + GST_TYPE_TUNER_CHANNEL, G_TYPE_ULONG); gst_tuner_signals[SIGNAL_CHANGED] = - g_signal_new ("signal-changed", - GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstTunerClass, signal_changed), - NULL, NULL, - gst_tuner_marshal_VOID__OBJECT_INT, G_TYPE_NONE, 2, - GST_TYPE_TUNER_CHANNEL, G_TYPE_INT); + g_signal_new ("signal-changed", + GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstTunerClass, signal_changed), + NULL, NULL, + gst_tuner_marshal_VOID__OBJECT_INT, G_TYPE_NONE, 2, + GST_TYPE_TUNER_CHANNEL, G_TYPE_INT); initialized = TRUE; } @@ -131,7 +130,7 @@ gst_tuner_class_init (GstTunerClass *klass) */ const GList * -gst_tuner_list_channels (GstTuner *tuner) +gst_tuner_list_channels (GstTuner * tuner) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); @@ -151,8 +150,7 @@ gst_tuner_list_channels (GstTuner *tuner) */ void -gst_tuner_set_channel (GstTuner *tuner, - GstTunerChannel *channel) +gst_tuner_set_channel (GstTuner * tuner, GstTunerChannel * channel) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); @@ -171,7 +169,7 @@ gst_tuner_set_channel (GstTuner *tuner, */ GstTunerChannel * -gst_tuner_get_channel (GstTuner *tuner) +gst_tuner_get_channel (GstTuner * tuner) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); @@ -194,7 +192,7 @@ gst_tuner_get_channel (GstTuner *tuner) */ const GList * -gst_tuner_list_norms (GstTuner *tuner) +gst_tuner_list_norms (GstTuner * tuner) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); @@ -214,8 +212,7 @@ gst_tuner_list_norms (GstTuner *tuner) */ void -gst_tuner_set_norm (GstTuner *tuner, - GstTunerNorm *norm) +gst_tuner_set_norm (GstTuner * tuner, GstTunerNorm * norm) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); @@ -235,7 +232,7 @@ gst_tuner_set_norm (GstTuner *tuner, */ GstTunerNorm * -gst_tuner_get_norm (GstTuner *tuner) +gst_tuner_get_norm (GstTuner * tuner) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); @@ -259,14 +256,13 @@ gst_tuner_get_norm (GstTuner *tuner) */ void -gst_tuner_set_frequency (GstTuner *tuner, - GstTunerChannel *channel, - gulong frequency) +gst_tuner_set_frequency (GstTuner * tuner, + GstTunerChannel * channel, gulong frequency) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); g_return_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel, - GST_TUNER_CHANNEL_FREQUENCY)); + GST_TUNER_CHANNEL_FREQUENCY)); if (klass->set_frequency) { klass->set_frequency (tuner, channel, frequency); @@ -285,13 +281,12 @@ gst_tuner_set_frequency (GstTuner *tuner, */ gulong -gst_tuner_get_frequency (GstTuner *tuner, - GstTunerChannel *channel) +gst_tuner_get_frequency (GstTuner * tuner, GstTunerChannel * channel) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel, - GST_TUNER_CHANNEL_FREQUENCY), 0); + GST_TUNER_CHANNEL_FREQUENCY), 0); if (klass->get_frequency) { return klass->get_frequency (tuner, channel); @@ -315,13 +310,12 @@ gst_tuner_get_frequency (GstTuner *tuner, */ gint -gst_tuner_signal_strength (GstTuner *tuner, - GstTunerChannel *channel) +gst_tuner_signal_strength (GstTuner * tuner, GstTunerChannel * channel) { GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner); g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel, - GST_TUNER_CHANNEL_FREQUENCY), 0); + GST_TUNER_CHANNEL_FREQUENCY), 0); if (klass->signal_strength) { return klass->signal_strength (tuner, channel); @@ -331,8 +325,7 @@ gst_tuner_signal_strength (GstTuner *tuner, } GstTunerNorm * -gst_tuner_find_norm_by_name (GstTuner *tuner, - gchar *norm) +gst_tuner_find_norm_by_name (GstTuner * tuner, gchar * norm) { GList *walk; @@ -349,8 +342,7 @@ gst_tuner_find_norm_by_name (GstTuner *tuner, } GstTunerChannel * -gst_tuner_find_channel_by_name (GstTuner *tuner, - gchar *channel) +gst_tuner_find_channel_by_name (GstTuner * tuner, gchar * channel) { GList *walk; @@ -367,59 +359,46 @@ gst_tuner_find_channel_by_name (GstTuner *tuner, } void -gst_tuner_channel_changed (GstTuner *tuner, - GstTunerChannel *channel) +gst_tuner_channel_changed (GstTuner * tuner, GstTunerChannel * channel) { g_return_if_fail (GST_IS_TUNER (tuner)); g_return_if_fail (GST_IS_TUNER_CHANNEL (channel)); g_signal_emit (G_OBJECT (tuner), - gst_tuner_signals[CHANNEL_CHANGED], 0, - channel); + gst_tuner_signals[CHANNEL_CHANGED], 0, channel); } void -gst_tuner_norm_changed (GstTuner *tuner, - GstTunerNorm *norm) +gst_tuner_norm_changed (GstTuner * tuner, GstTunerNorm * norm) { g_return_if_fail (GST_IS_TUNER (tuner)); g_return_if_fail (GST_IS_TUNER_NORM (norm)); - g_signal_emit (G_OBJECT (tuner), - gst_tuner_signals[NORM_CHANGED], 0, - norm); + g_signal_emit (G_OBJECT (tuner), gst_tuner_signals[NORM_CHANGED], 0, norm); } void -gst_tuner_frequency_changed (GstTuner *tuner, - GstTunerChannel *channel, - gulong frequency) +gst_tuner_frequency_changed (GstTuner * tuner, + GstTunerChannel * channel, gulong frequency) { g_return_if_fail (GST_IS_TUNER (tuner)); g_return_if_fail (GST_IS_TUNER_CHANNEL (channel)); g_signal_emit (G_OBJECT (tuner), - gst_tuner_signals[FREQUENCY_CHANGED], 0, - channel, frequency); + gst_tuner_signals[FREQUENCY_CHANGED], 0, channel, frequency); - g_signal_emit_by_name (G_OBJECT (channel), - "frequency_changed", - frequency); + g_signal_emit_by_name (G_OBJECT (channel), "frequency_changed", frequency); } void -gst_tuner_signal_changed (GstTuner *tuner, - GstTunerChannel *channel, - gint signal) +gst_tuner_signal_changed (GstTuner * tuner, + GstTunerChannel * channel, gint signal) { g_return_if_fail (GST_IS_TUNER (tuner)); g_return_if_fail (GST_IS_TUNER_CHANNEL (channel)); g_signal_emit (G_OBJECT (tuner), - gst_tuner_signals[SIGNAL_CHANGED], 0, - channel, signal); + gst_tuner_signals[SIGNAL_CHANGED], 0, channel, signal); - g_signal_emit_by_name (G_OBJECT (channel), - "signal_changed", - signal); + g_signal_emit_by_name (G_OBJECT (channel), "signal_changed", signal); } diff --git a/gst-libs/gst/tuner/tuner.h b/gst-libs/gst/tuner/tuner.h index 8c935389c9..cab3541d46 100644 --- a/gst-libs/gst/tuner/tuner.h +++ b/gst-libs/gst/tuner/tuner.h @@ -28,7 +28,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_TUNER \ (gst_tuner_get_type ()) #define GST_TUNER(obj) \ @@ -41,87 +40,65 @@ G_BEGIN_DECLS (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TUNER)) #define GST_TUNER_GET_CLASS(inst) \ (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GST_TYPE_TUNER, GstTunerClass)) - typedef struct _GstTuner GstTuner; -typedef struct _GstTunerClass { +typedef struct _GstTunerClass +{ GTypeInterface klass; /* virtual functions */ - const GList * (* list_channels) (GstTuner *tuner); - void (* set_channel) (GstTuner *tuner, - GstTunerChannel *channel); - GstTunerChannel * - (* get_channel) (GstTuner *tuner); + const GList *(*list_channels) (GstTuner * tuner); + void (*set_channel) (GstTuner * tuner, GstTunerChannel * channel); + GstTunerChannel *(*get_channel) (GstTuner * tuner); - const GList * (* list_norms) (GstTuner *tuner); - void (* set_norm) (GstTuner *tuner, - GstTunerNorm *norm); - GstTunerNorm *(* get_norm) (GstTuner *tuner); + const GList *(*list_norms) (GstTuner * tuner); + void (*set_norm) (GstTuner * tuner, GstTunerNorm * norm); + GstTunerNorm *(*get_norm) (GstTuner * tuner); - void (* set_frequency) (GstTuner *tuner, - GstTunerChannel *channel, - gulong frequency); - gulong (* get_frequency) (GstTuner *tuner, - GstTunerChannel *channel); - gint (* signal_strength) (GstTuner *tuner, - GstTunerChannel *channel); + void (*set_frequency) (GstTuner * tuner, + GstTunerChannel * channel, gulong frequency); + gulong (*get_frequency) (GstTuner * tuner, GstTunerChannel * channel); + gint (*signal_strength) (GstTuner * tuner, GstTunerChannel * channel); /* signals */ - void (*channel_changed) (GstTuner *tuner, - GstTunerChannel *channel); - void (*norm_changed) (GstTuner *tuner, - GstTunerNorm *norm); - void (*frequency_changed) (GstTuner *tuner, - GstTunerChannel *channel, - gulong frequency); - void (*signal_changed) (GstTuner *tuner, - GstTunerChannel *channel, - gint signal); + void (*channel_changed) (GstTuner * tuner, GstTunerChannel * channel); + void (*norm_changed) (GstTuner * tuner, GstTunerNorm * norm); + void (*frequency_changed) (GstTuner * tuner, + GstTunerChannel * channel, gulong frequency); + void (*signal_changed) (GstTuner * tuner, + GstTunerChannel * channel, gint signal); gpointer _gst_reserved[GST_PADDING]; } GstTunerClass; -GType gst_tuner_get_type (void); +GType gst_tuner_get_type (void); /* virtual class function wrappers */ -const GList * gst_tuner_list_channels (GstTuner *tuner); -void gst_tuner_set_channel (GstTuner *tuner, - GstTunerChannel *channel); -GstTunerChannel * - gst_tuner_get_channel (GstTuner *tuner); +const GList *gst_tuner_list_channels (GstTuner * tuner); +void gst_tuner_set_channel (GstTuner * tuner, GstTunerChannel * channel); +GstTunerChannel *gst_tuner_get_channel (GstTuner * tuner); -const GList * gst_tuner_list_norms (GstTuner *tuner); -void gst_tuner_set_norm (GstTuner *tuner, - GstTunerNorm *channel); -GstTunerNorm * gst_tuner_get_norm (GstTuner *tuner); +const GList *gst_tuner_list_norms (GstTuner * tuner); +void gst_tuner_set_norm (GstTuner * tuner, GstTunerNorm * channel); +GstTunerNorm *gst_tuner_get_norm (GstTuner * tuner); -void gst_tuner_set_frequency (GstTuner *tuner, - GstTunerChannel *channel, - gulong frequency); -gulong gst_tuner_get_frequency (GstTuner *tuner, - GstTunerChannel *channel); -gint gst_tuner_signal_strength (GstTuner *tuner, - GstTunerChannel *channel); +void gst_tuner_set_frequency (GstTuner * tuner, + GstTunerChannel * channel, gulong frequency); +gulong gst_tuner_get_frequency (GstTuner * tuner, GstTunerChannel * channel); +gint gst_tuner_signal_strength (GstTuner * tuner, GstTunerChannel * channel); /* helper functions */ -GstTunerNorm * gst_tuner_find_norm_by_name (GstTuner *tuner, - gchar *norm); -GstTunerChannel *gst_tuner_find_channel_by_name (GstTuner *tuner, - gchar *channel); +GstTunerNorm *gst_tuner_find_norm_by_name (GstTuner * tuner, gchar * norm); +GstTunerChannel *gst_tuner_find_channel_by_name (GstTuner * tuner, + gchar * channel); /* trigger signals */ -void gst_tuner_channel_changed (GstTuner *tuner, - GstTunerChannel *channel); -void gst_tuner_norm_changed (GstTuner *tuner, - GstTunerNorm *norm); -void gst_tuner_frequency_changed (GstTuner *tuner, - GstTunerChannel *channel, - gulong frequency); -void gst_tuner_signal_changed (GstTuner *tuner, - GstTunerChannel *channel, - gint signal); +void gst_tuner_channel_changed (GstTuner * tuner, GstTunerChannel * channel); +void gst_tuner_norm_changed (GstTuner * tuner, GstTunerNorm * norm); +void gst_tuner_frequency_changed (GstTuner * tuner, + GstTunerChannel * channel, gulong frequency); +void gst_tuner_signal_changed (GstTuner * tuner, + GstTunerChannel * channel, gint signal); G_END_DECLS - #endif /* __GST_TUNER_H__ */ diff --git a/gst-libs/gst/tuner/tunerchannel.c b/gst-libs/gst/tuner/tunerchannel.c index ffcfcd9df6..af93f56842 100644 --- a/gst-libs/gst/tuner/tunerchannel.c +++ b/gst-libs/gst/tuner/tunerchannel.c @@ -25,16 +25,17 @@ #include "tunerchannel.h" -enum { +enum +{ /* FILL ME */ SIGNAL_FREQUENCY_CHANGED, SIGNAL_SIGNAL_CHANGED, LAST_SIGNAL }; -static void gst_tuner_channel_class_init (GstTunerChannelClass *klass); -static void gst_tuner_channel_init (GstTunerChannel *channel); -static void gst_tuner_channel_dispose (GObject *object); +static void gst_tuner_channel_class_init (GstTunerChannelClass * klass); +static void gst_tuner_channel_init (GstTunerChannel * channel); +static void gst_tuner_channel_dispose (GObject * object); static GObjectClass *parent_class = NULL; static guint signals[LAST_SIGNAL] = { 0 }; @@ -60,40 +61,37 @@ gst_tuner_channel_get_type (void) gst_tuner_channel_type = g_type_register_static (G_TYPE_OBJECT, - "GstTunerChannel", - &tuner_channel_info, 0); + "GstTunerChannel", &tuner_channel_info, 0); } return gst_tuner_channel_type; } static void -gst_tuner_channel_class_init (GstTunerChannelClass *klass) +gst_tuner_channel_class_init (GstTunerChannelClass * klass) { GObjectClass *object_klass = (GObjectClass *) klass; parent_class = g_type_class_ref (G_TYPE_OBJECT); signals[SIGNAL_FREQUENCY_CHANGED] = - g_signal_new ("frequency-changed", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstTunerChannelClass, - frequency_changed), - NULL, NULL, g_cclosure_marshal_VOID__ULONG, - G_TYPE_NONE, 1, G_TYPE_ULONG); + g_signal_new ("frequency-changed", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstTunerChannelClass, + frequency_changed), + NULL, NULL, g_cclosure_marshal_VOID__ULONG, G_TYPE_NONE, 1, G_TYPE_ULONG); signals[SIGNAL_SIGNAL_CHANGED] = - g_signal_new ("signal-changed", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstTunerChannelClass, - signal_changed), - NULL, NULL, g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); + g_signal_new ("signal-changed", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstTunerChannelClass, + signal_changed), + NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); object_klass->dispose = gst_tuner_channel_dispose; } static void -gst_tuner_channel_init (GstTunerChannel *channel) +gst_tuner_channel_init (GstTunerChannel * channel) { channel->label = NULL; channel->flags = 0; @@ -102,7 +100,7 @@ gst_tuner_channel_init (GstTunerChannel *channel) } static void -gst_tuner_channel_dispose (GObject *object) +gst_tuner_channel_dispose (GObject * object) { GstTunerChannel *channel = GST_TUNER_CHANNEL (object); diff --git a/gst-libs/gst/tuner/tunerchannel.h b/gst-libs/gst/tuner/tunerchannel.h index ee5654d0fb..663d682d94 100644 --- a/gst-libs/gst/tuner/tunerchannel.h +++ b/gst-libs/gst/tuner/tunerchannel.h @@ -25,7 +25,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_TUNER_CHANNEL \ (gst_tuner_channel_get_type ()) #define GST_TUNER_CHANNEL(obj) \ @@ -38,42 +37,39 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TUNER_CHANNEL)) #define GST_IS_TUNER_CHANNEL_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TUNER_CHANNEL)) - -typedef enum { - GST_TUNER_CHANNEL_INPUT = (1<<0), - GST_TUNER_CHANNEL_OUTPUT = (1<<1), - GST_TUNER_CHANNEL_FREQUENCY = (1<<2), - GST_TUNER_CHANNEL_AUDIO = (1<<3), + typedef enum +{ + GST_TUNER_CHANNEL_INPUT = (1 << 0), + GST_TUNER_CHANNEL_OUTPUT = (1 << 1), + GST_TUNER_CHANNEL_FREQUENCY = (1 << 2), + GST_TUNER_CHANNEL_AUDIO = (1 << 3), } GstTunerChannelFlags; #define GST_TUNER_CHANNEL_HAS_FLAG(channel, flag) \ ((channel)->flags & flag) -typedef struct _GstTunerChannel { - GObject parent; +typedef struct _GstTunerChannel +{ + GObject parent; - gchar *label; + gchar *label; GstTunerChannelFlags flags; - gulong min_frequency, - max_frequency; - gint min_signal, - max_signal; + gulong min_frequency, max_frequency; + gint min_signal, max_signal; } GstTunerChannel; -typedef struct _GstTunerChannelClass { +typedef struct _GstTunerChannelClass +{ GObjectClass parent; /* signals */ - void (*frequency_changed) (GstTunerChannel *channel, - gulong frequency); - void (*signal_changed) (GstTunerChannel *channel, - gint signal); + void (*frequency_changed) (GstTunerChannel * channel, gulong frequency); + void (*signal_changed) (GstTunerChannel * channel, gint signal); gpointer _gst_reserved[GST_PADDING]; } GstTunerChannelClass; -GType gst_tuner_channel_get_type (void); +GType gst_tuner_channel_get_type (void); G_END_DECLS - #endif /* __GST_TUNER_CHANNEL_H__ */ diff --git a/gst-libs/gst/tuner/tunernorm.c b/gst-libs/gst/tuner/tunernorm.c index 48d75de265..41927d2b1e 100644 --- a/gst-libs/gst/tuner/tunernorm.c +++ b/gst-libs/gst/tuner/tunernorm.c @@ -25,16 +25,18 @@ #include "tunernorm.h" -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -static void gst_tuner_norm_class_init (GstTunerNormClass *klass); -static void gst_tuner_norm_init (GstTunerNorm *norm); -static void gst_tuner_norm_dispose (GObject *object); +static void gst_tuner_norm_class_init (GstTunerNormClass * klass); +static void gst_tuner_norm_init (GstTunerNorm * norm); +static void gst_tuner_norm_dispose (GObject * object); static GObjectClass *parent_class = NULL; + /*static guint signals[LAST_SIGNAL] = { 0 };*/ GType @@ -58,15 +60,14 @@ gst_tuner_norm_get_type (void) gst_tuner_norm_type = g_type_register_static (G_TYPE_OBJECT, - "GstTunerNorm", - &tuner_norm_info, 0); + "GstTunerNorm", &tuner_norm_info, 0); } return gst_tuner_norm_type; } static void -gst_tuner_norm_class_init (GstTunerNormClass *klass) +gst_tuner_norm_class_init (GstTunerNormClass * klass) { GObjectClass *object_klass = (GObjectClass *) klass; @@ -76,14 +77,14 @@ gst_tuner_norm_class_init (GstTunerNormClass *klass) } static void -gst_tuner_norm_init (GstTunerNorm *norm) +gst_tuner_norm_init (GstTunerNorm * norm) { norm->label = NULL; norm->fps = 0.; } static void -gst_tuner_norm_dispose (GObject *object) +gst_tuner_norm_dispose (GObject * object) { GstTunerNorm *norm = GST_TUNER_NORM (object); diff --git a/gst-libs/gst/tuner/tunernorm.h b/gst-libs/gst/tuner/tunernorm.h index cd89e1ee88..94267b6e35 100644 --- a/gst-libs/gst/tuner/tunernorm.h +++ b/gst-libs/gst/tuner/tunernorm.h @@ -25,7 +25,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_TUNER_NORM \ (gst_tuner_norm_get_type ()) #define GST_TUNER_NORM(obj) \ @@ -36,22 +35,22 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TUNER_NORM)) #define GST_IS_TUNER_NORM_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TUNER_NORM)) - -typedef struct _GstTunerNorm { + typedef struct _GstTunerNorm +{ GObject parent; - gchar *label; - gfloat fps; + gchar *label; + gfloat fps; } GstTunerNorm; -typedef struct _GstTunerNormClass { +typedef struct _GstTunerNormClass +{ GObjectClass parent; gpointer _gst_reserved[GST_PADDING]; } GstTunerNormClass; -GType gst_tuner_norm_get_type (void); +GType gst_tuner_norm_get_type (void); G_END_DECLS - #endif /* __GST_TUNER_NORM_H__ */ diff --git a/gst-libs/gst/video/gstvideosink.c b/gst-libs/gst/video/gstvideosink.c index 15f27c16ab..2acf7e573f 100644 --- a/gst-libs/gst/video/gstvideosink.c +++ b/gst-libs/gst/video/gstvideosink.c @@ -29,19 +29,19 @@ static GstElementClass *parent_class = NULL; /* Private methods */ static void -gst_videosink_set_clock (GstElement *element, GstClock *clock) +gst_videosink_set_clock (GstElement * element, GstClock * clock) { GstVideoSink *videosink; videosink = GST_VIDEOSINK (element); - + videosink->clock = clock; } /* Initing stuff */ static void -gst_videosink_init (GstVideoSink *videosink) +gst_videosink_init (GstVideoSink * videosink) { videosink->width = 0; videosink->height = 0; @@ -49,13 +49,13 @@ gst_videosink_init (GstVideoSink *videosink) } static void -gst_videosink_class_init (GstVideoSinkClass *klass) +gst_videosink_class_init (GstVideoSinkClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); @@ -69,24 +69,22 @@ gst_videosink_get_type (void) { static GType videosink_type = 0; - if (!videosink_type) - { - static const GTypeInfo videosink_info = { - sizeof (GstVideoSinkClass), - NULL, - NULL, - (GClassInitFunc) gst_videosink_class_init, - NULL, - NULL, - sizeof (GstVideoSink), - 0, - (GInstanceInitFunc) gst_videosink_init, - }; - - videosink_type = g_type_register_static (GST_TYPE_ELEMENT, - "GstVideoSink", - &videosink_info, 0); - } - + if (!videosink_type) { + static const GTypeInfo videosink_info = { + sizeof (GstVideoSinkClass), + NULL, + NULL, + (GClassInitFunc) gst_videosink_class_init, + NULL, + NULL, + sizeof (GstVideoSink), + 0, + (GInstanceInitFunc) gst_videosink_init, + }; + + videosink_type = g_type_register_static (GST_TYPE_ELEMENT, + "GstVideoSink", &videosink_info, 0); + } + return videosink_type; } diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c index 114b4bac3b..8fed1e76b7 100644 --- a/gst-libs/gst/video/video.c +++ b/gst-libs/gst/video/video.c @@ -27,7 +27,7 @@ /* This is simply a convenience function, nothing more or less */ gdouble -gst_video_frame_rate (GstPad *pad) +gst_video_frame_rate (GstPad * pad) { gdouble fps = 0.; const GstCaps *caps = NULL; @@ -37,30 +37,25 @@ gst_video_frame_rate (GstPad *pad) caps = GST_PAD_CAPS (pad); if (caps == NULL) { g_warning ("gstvideo: failed to get caps of pad %s:%s", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), - GST_PAD_NAME(pad)); + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); return 0.; } structure = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_double (structure, "framerate", &fps)){ + if (!gst_structure_get_double (structure, "framerate", &fps)) { g_warning ("gstvideo: failed to get framerate property of pad %s:%s", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), - GST_PAD_NAME (pad)); + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); return 0.; } GST_DEBUG ("Framerate request on pad %s:%s: %f", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), - GST_PAD_NAME(pad), fps); + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad), fps); return fps; } gboolean -gst_video_get_size (GstPad *pad, - gint *width, - gint *height) +gst_video_get_size (GstPad * pad, gint * width, gint * height) { const GstCaps *caps = NULL; GstStructure *structure; @@ -74,8 +69,7 @@ gst_video_get_size (GstPad *pad, if (caps == NULL) { g_warning ("gstvideo: failed to get caps of pad %s:%s", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), - GST_PAD_NAME(pad)); + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); return FALSE; } @@ -85,34 +79,25 @@ gst_video_get_size (GstPad *pad, if (!ret) { g_warning ("gstvideo: failed to get size properties on pad %s:%s", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), - GST_PAD_NAME(pad)); + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), GST_PAD_NAME (pad)); return FALSE; } GST_DEBUG ("size request on pad %s:%s: %dx%d", - GST_ELEMENT_NAME (gst_pad_get_parent (pad)), - GST_PAD_NAME (pad), - width ? *width : -1, - height ? *height : -1); + GST_ELEMENT_NAME (gst_pad_get_parent (pad)), + GST_PAD_NAME (pad), width ? *width : -1, height ? *height : -1); return TRUE; } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gstvideo", - "Convenience routines for video plugins", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstvideo", + "Convenience routines for video plugins", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) diff --git a/gst-libs/gst/video/video.h b/gst-libs/gst/video/video.h index cb8727a948..5ebe444f5a 100644 --- a/gst-libs/gst/video/video.h +++ b/gst-libs/gst/video/video.h @@ -98,31 +98,31 @@ #define GST_VIDEO_CAPS_RGBx \ __GST_VIDEO_CAPS_MAKE_32 (1, 2, 3) - + #define GST_VIDEO_CAPS_xRGB \ __GST_VIDEO_CAPS_MAKE_32 (2, 3, 4) - + #define GST_VIDEO_CAPS_BGRx \ __GST_VIDEO_CAPS_MAKE_32 (3, 2, 1) - + #define GST_VIDEO_CAPS_xBGR \ __GST_VIDEO_CAPS_MAKE_32 (4, 3, 2) /* note: the macro name uses the order on BE systems */ #if G_BYTE_ORDER == G_BIG_ENDIAN - #define GST_VIDEO_CAPS_xRGB_HOST_ENDIAN \ +#define GST_VIDEO_CAPS_xRGB_HOST_ENDIAN \ GST_VIDEO_CAPS_xRGB - #define GST_VIDEO_CAPS_BGRx_HOST_ENDIAN \ +#define GST_VIDEO_CAPS_BGRx_HOST_ENDIAN \ GST_VIDEO_CAPS_BGRx #else - #define GST_VIDEO_CAPS_xRGB_HOST_ENDIAN \ +#define GST_VIDEO_CAPS_xRGB_HOST_ENDIAN \ GST_VIDEO_CAPS_BGRx - #define GST_VIDEO_CAPS_BGRx_HOST_ENDIAN \ +#define GST_VIDEO_CAPS_BGRx_HOST_ENDIAN \ GST_VIDEO_CAPS_xRGB #endif - + /* 15/16 bit */ - + #define GST_VIDEO_CAPS_RGB_16 \ "video/x-raw-rgb, " \ "bpp = (int) 16, " \ @@ -155,9 +155,7 @@ "framerate = " GST_VIDEO_FPS_RANGE /* functions */ -gdouble gst_video_frame_rate (GstPad *pad); -gboolean gst_video_get_size (GstPad *pad, - gint *width, - gint *height); +gdouble gst_video_frame_rate (GstPad * pad); +gboolean gst_video_get_size (GstPad * pad, gint * width, gint * height); #endif /* __GST_VIDEO_H__ */ diff --git a/gst-libs/gst/video/videosink.h b/gst-libs/gst/video/videosink.h index 129a47d60a..68de26fa5b 100644 --- a/gst-libs/gst/video/videosink.h +++ b/gst-libs/gst/video/videosink.h @@ -17,16 +17,17 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + #ifndef __GST_VIDEOSINK_H__ #define __GST_VIDEOSINK_H__ #include #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - +extern "C" +{ +#endif /* __cplusplus */ + #define GST_TYPE_VIDEOSINK (gst_videosink_get_type()) #define GST_VIDEOSINK(obj) \ (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VIDEOSINK, GstVideoSink)) @@ -38,37 +39,39 @@ extern "C" { (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VIDEOSINK)) #define GST_VIDEOSINK_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VIDEOSINK, GstVideoSinkClass)) - + #define GST_VIDEOSINK_PAD(obj) (GST_VIDEOSINK (obj)->sinkpad) #define GST_VIDEOSINK_WIDTH(obj) (GST_VIDEOSINK (obj)->width) #define GST_VIDEOSINK_HEIGHT(obj) (GST_VIDEOSINK (obj)->height) #define GST_VIDEOSINK_CLOCK(obj) (GST_VIDEOSINK (obj)->clock) - -typedef struct _GstVideoSink GstVideoSink; -typedef struct _GstVideoSinkClass GstVideoSinkClass; -struct _GstVideoSink { - GstElement element; - - GstPad *sinkpad; - - gint width, height; - - GstClock *clock; - - gpointer _gst_reserved[GST_PADDING]; -}; + typedef struct _GstVideoSink GstVideoSink; + typedef struct _GstVideoSinkClass GstVideoSinkClass; -struct _GstVideoSinkClass { - GstElementClass parent_class; - - gpointer _gst_reserved[GST_PADDING]; -}; + struct _GstVideoSink + { + GstElement element; -GType gst_videosink_get_type (void); + GstPad *sinkpad; + + gint width, height; + + GstClock *clock; + + gpointer _gst_reserved[GST_PADDING]; + }; + + struct _GstVideoSinkClass + { + GstElementClass parent_class; + + gpointer _gst_reserved[GST_PADDING]; + }; + + GType gst_videosink_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_VIDEOSINK_H__ */ +#endif /* __GST_VIDEOSINK_H__ */ diff --git a/gst-libs/gst/xoverlay/xoverlay.c b/gst-libs/gst/xoverlay/xoverlay.c index 66af8d625f..c1014eb179 100644 --- a/gst-libs/gst/xoverlay/xoverlay.c +++ b/gst-libs/gst/xoverlay/xoverlay.c @@ -25,7 +25,8 @@ #include "xoverlay.h" -enum { +enum +{ HAVE_XWINDOW_ID, DESIRED_SIZE, LAST_SIGNAL @@ -54,44 +55,40 @@ gst_x_overlay_get_type (void) }; gst_x_overlay_type = g_type_register_static (G_TYPE_INTERFACE, - "GstXOverlay", - &gst_x_overlay_info, 0); + "GstXOverlay", &gst_x_overlay_info, 0); g_type_interface_add_prerequisite (gst_x_overlay_type, - GST_TYPE_IMPLEMENTS_INTERFACE); + GST_TYPE_IMPLEMENTS_INTERFACE); } return gst_x_overlay_type; } /* FIXME: evil hack, we should figure out our marshal handling in this interfaces some day */ -extern void gst_marshal_VOID__INT_INT (GClosure *closure, GValue *return_value, guint n_param_values, - const GValue *param_values, gpointer invocation_hint, gpointer marshal_data); +extern void gst_marshal_VOID__INT_INT (GClosure * closure, + GValue * return_value, guint n_param_values, const GValue * param_values, + gpointer invocation_hint, gpointer marshal_data); static void gst_x_overlay_base_init (gpointer g_class) { GstXOverlayClass *overlay_class = (GstXOverlayClass *) g_class; static gboolean initialized = FALSE; - - if (! initialized) - { - gst_x_overlay_signals[HAVE_XWINDOW_ID] = - g_signal_new ("have-xwindow-id", - GST_TYPE_X_OVERLAY, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstXOverlayClass, have_xwindow_id), - NULL, NULL, - g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, - G_TYPE_INT); - gst_x_overlay_signals[DESIRED_SIZE] = - g_signal_new ("desired-size-changed", - GST_TYPE_X_OVERLAY, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstXOverlayClass, desired_size), - NULL, NULL, - gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, - G_TYPE_INT, G_TYPE_INT); - - initialized = TRUE; - } + + if (!initialized) { + gst_x_overlay_signals[HAVE_XWINDOW_ID] = + g_signal_new ("have-xwindow-id", + GST_TYPE_X_OVERLAY, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstXOverlayClass, have_xwindow_id), + NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); + gst_x_overlay_signals[DESIRED_SIZE] = + g_signal_new ("desired-size-changed", + GST_TYPE_X_OVERLAY, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstXOverlayClass, desired_size), + NULL, NULL, + gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); + + initialized = TRUE; + } overlay_class->set_xwindow_id = NULL; } @@ -107,7 +104,7 @@ gst_x_overlay_base_init (gpointer g_class) * stop using that window and create an internal one. */ void -gst_x_overlay_set_xwindow_id (GstXOverlay *overlay, gulong xwindow_id) +gst_x_overlay_set_xwindow_id (GstXOverlay * overlay, gulong xwindow_id) { GstXOverlayClass *klass = GST_X_OVERLAY_GET_CLASS (overlay); @@ -126,13 +123,13 @@ gst_x_overlay_set_xwindow_id (GstXOverlay *overlay, gulong xwindow_id) * This function should be used by video overlay developpers. */ void -gst_x_overlay_got_xwindow_id (GstXOverlay *overlay, gulong xwindow_id) +gst_x_overlay_got_xwindow_id (GstXOverlay * overlay, gulong xwindow_id) { g_return_if_fail (overlay != NULL); g_return_if_fail (GST_IS_X_OVERLAY (overlay)); - + g_signal_emit (G_OBJECT (overlay), - gst_x_overlay_signals[HAVE_XWINDOW_ID], 0, (gint) xwindow_id); + gst_x_overlay_signals[HAVE_XWINDOW_ID], 0, (gint) xwindow_id); } /** @@ -145,18 +142,20 @@ gst_x_overlay_got_xwindow_id (GstXOverlay *overlay, gulong xwindow_id) * size, width and height are set to 0. */ void -gst_x_overlay_get_desired_size (GstXOverlay *overlay, guint *width, guint *height) +gst_x_overlay_get_desired_size (GstXOverlay * overlay, guint * width, + guint * height) { guint width_tmp, height_tmp; GstXOverlayClass *klass; - + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE ((overlay), GST_TYPE_X_OVERLAY)); - + klass = GST_X_OVERLAY_GET_CLASS (overlay); if (klass->get_desired_size && GST_IS_X_OVERLAY (overlay)) { /* this ensures that elements don't need to check width and height for NULL but apps may use NULL */ - klass->get_desired_size (overlay, width ? width : &width_tmp, height ? height : &height_tmp); + klass->get_desired_size (overlay, width ? width : &width_tmp, + height ? height : &height_tmp); } else { if (width) *width = 0; @@ -176,12 +175,13 @@ gst_x_overlay_get_desired_size (GstXOverlay *overlay, guint *width, guint *heigh * This function should be used by video overlay developpers. */ void -gst_x_overlay_got_desired_size (GstXOverlay *overlay, guint width, guint height) +gst_x_overlay_got_desired_size (GstXOverlay * overlay, guint width, + guint height) { g_return_if_fail (GST_IS_X_OVERLAY (overlay)); - + g_signal_emit (G_OBJECT (overlay), - gst_x_overlay_signals[DESIRED_SIZE], 0, width, height); + gst_x_overlay_signals[DESIRED_SIZE], 0, width, height); } /** @@ -192,7 +192,7 @@ gst_x_overlay_got_desired_size (GstXOverlay *overlay, guint width, guint height) * in the drawable even if the pipeline is PAUSED. */ void -gst_x_overlay_expose (GstXOverlay *overlay) +gst_x_overlay_expose (GstXOverlay * overlay) { GstXOverlayClass *klass = GST_X_OVERLAY_GET_CLASS (overlay); diff --git a/gst-libs/gst/xoverlay/xoverlay.h b/gst-libs/gst/xoverlay/xoverlay.h index 5318fef310..b1c9069058 100644 --- a/gst-libs/gst/xoverlay/xoverlay.h +++ b/gst-libs/gst/xoverlay/xoverlay.h @@ -26,7 +26,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_X_OVERLAY \ (gst_x_overlay_get_type ()) #define GST_X_OVERLAY(obj) \ @@ -40,42 +39,38 @@ G_BEGIN_DECLS (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_X_OVERLAY)) #define GST_X_OVERLAY_GET_CLASS(inst) \ (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GST_TYPE_X_OVERLAY, GstXOverlayClass)) - typedef struct _GstXOverlay GstXOverlay; -typedef struct _GstXOverlayClass { +typedef struct _GstXOverlayClass +{ GTypeInterface klass; /* virtual functions */ - void (* set_xwindow_id) (GstXOverlay *overlay, - gulong xwindow_id); + void (*set_xwindow_id) (GstXOverlay * overlay, gulong xwindow_id); /* optional virtual functions */ - void (* get_desired_size) (GstXOverlay *overlay, - guint *width, - guint *height); - void (* expose) (GstXOverlay *overlay); - + void (*get_desired_size) (GstXOverlay * overlay, + guint * width, guint * height); + void (*expose) (GstXOverlay * overlay); + /* signals */ - void (*have_xwindow_id) (GstXOverlay *overlay, - gulong xwindow_id); - void (* desired_size) (GstXOverlay *overlay, - guint width, - guint height); + void (*have_xwindow_id) (GstXOverlay * overlay, gulong xwindow_id); + void (*desired_size) (GstXOverlay * overlay, guint width, guint height); gpointer _gst_reserved[GST_PADDING]; } GstXOverlayClass; -GType gst_x_overlay_get_type (void); +GType gst_x_overlay_get_type (void); /* virtual class function wrappers */ -void gst_x_overlay_set_xwindow_id (GstXOverlay *overlay, gulong xwindow_id); -void gst_x_overlay_get_desired_size (GstXOverlay *overlay, guint *width, guint *height); -void gst_x_overlay_expose (GstXOverlay *overlay); +void gst_x_overlay_set_xwindow_id (GstXOverlay * overlay, gulong xwindow_id); +void gst_x_overlay_get_desired_size (GstXOverlay * overlay, guint * width, + guint * height); +void gst_x_overlay_expose (GstXOverlay * overlay); /* public methods to fire signals */ -void gst_x_overlay_got_xwindow_id (GstXOverlay *overlay, gulong xwindow_id); -void gst_x_overlay_got_desired_size (GstXOverlay *overlay, guint width, guint height); +void gst_x_overlay_got_xwindow_id (GstXOverlay * overlay, gulong xwindow_id); +void gst_x_overlay_got_desired_size (GstXOverlay * overlay, guint width, + guint height); G_END_DECLS - #endif /* __GST_X_OVERLAY_H__ */ diff --git a/gst-libs/gst/xwindowlistener/xwindowlistener.c b/gst-libs/gst/xwindowlistener/xwindowlistener.c index a2b769941c..dc289854d5 100644 --- a/gst-libs/gst/xwindowlistener/xwindowlistener.c +++ b/gst-libs/gst/xwindowlistener/xwindowlistener.c @@ -28,12 +28,12 @@ #define NUM_CLIPS 1024 -static void gst_x_window_listener_class_init (GstXWindowListenerClass *klass); -static void gst_x_window_listener_init (GstXWindowListener *xwin); -static void gst_x_window_listener_dispose (GObject *object); +static void gst_x_window_listener_class_init (GstXWindowListenerClass * klass); +static void gst_x_window_listener_init (GstXWindowListener * xwin); +static void gst_x_window_listener_dispose (GObject * object); -static void gst_xwin_start (GstXWindowListener *xwin); -static void gst_xwin_stop (GstXWindowListener *xwin); +static void gst_xwin_start (GstXWindowListener * xwin); +static void gst_xwin_stop (GstXWindowListener * xwin); static GObjectClass *parent_class = NULL; @@ -58,15 +58,14 @@ gst_x_window_listener_get_type (void) x_window_listener_type = g_type_register_static (G_TYPE_OBJECT, - "GstXWindowListener", - &x_window_listener_info, 0); + "GstXWindowListener", &x_window_listener_info, 0); } return x_window_listener_type; } static void -gst_x_window_listener_class_init (GstXWindowListenerClass *klass) +gst_x_window_listener_class_init (GstXWindowListenerClass * klass) { GObjectClass *object_klass = (GObjectClass *) klass; @@ -76,7 +75,7 @@ gst_x_window_listener_class_init (GstXWindowListenerClass *klass) } static void -gst_x_window_listener_init (GstXWindowListener *xwin) +gst_x_window_listener_init (GstXWindowListener * xwin) { xwin->xwindow_id = 0; xwin->display_name = NULL; @@ -88,7 +87,7 @@ gst_x_window_listener_init (GstXWindowListener *xwin) } static void -gst_x_window_listener_dispose (GObject *object) +gst_x_window_listener_dispose (GObject * object) { GstXWindowListener *xwin = GST_X_WINDOW_LISTENER (object); @@ -105,13 +104,11 @@ gst_x_window_listener_dispose (GObject *object) } GstXWindowListener * -gst_x_window_listener_new (gchar *display, - MapWindowFunc map_window_func, - SetWindowFunc set_window_func, - gpointer private_data) +gst_x_window_listener_new (gchar * display, + MapWindowFunc map_window_func, + SetWindowFunc set_window_func, gpointer private_data) { - GstXWindowListener *xwin = - g_object_new (GST_TYPE_X_WINDOW_LISTENER, NULL); + GstXWindowListener *xwin = g_object_new (GST_TYPE_X_WINDOW_LISTENER, NULL); xwin->display_name = g_strdup (display); xwin->map_window_func = map_window_func; @@ -122,8 +119,7 @@ gst_x_window_listener_new (gchar *display, } void -gst_x_window_listener_set_xid (GstXWindowListener *xwin, - XID id) +gst_x_window_listener_set_xid (GstXWindowListener * xwin, XID id) { g_return_if_fail (xwin != NULL); @@ -137,9 +133,7 @@ gst_x_window_listener_set_xid (GstXWindowListener *xwin, xwin->xwindow_id = id; - if (xwin->xwindow_id && - xwin->display_name && - xwin->display_name[0] == ':') { + if (xwin->xwindow_id && xwin->display_name && xwin->display_name[0] == ':') { g_return_if_fail (xwin->map_window_func != NULL); g_return_if_fail (xwin->set_window_func != NULL); @@ -163,8 +157,7 @@ gst_x_window_listener_set_xid (GstXWindowListener *xwin, GST_DEBUG ("XWL: " format, ##args) static void -gst_xwin_set_overlay (GstXWindowListener *xwin, - gboolean on) +gst_xwin_set_overlay (GstXWindowListener * xwin, gboolean on) { xwin->map_window_func (xwin->private_data, on); @@ -190,22 +183,20 @@ gst_xwin_refresh (gpointer data) if (!xwin->ov_move && xwin->ov_map && xwin->ov_visibility == VisibilityUnobscured) { g_mutex_unlock (xwin->main_lock); - return FALSE; /* skip */ + return FALSE; /* skip */ } - if (xwin->ov_map && - xwin->ov_visibility != VisibilityFullyObscured) { + if (xwin->ov_map && xwin->ov_visibility != VisibilityFullyObscured) { xwin->ov_refresh = TRUE; } xswa.override_redirect = True; xswa.backing_store = NotUseful; xswa.save_under = False; - tmp = XCreateWindow (xwin->main_display,win, 0, 0, - attr.width, attr.height, 0, - CopyFromParent, InputOutput, CopyFromParent, - (CWSaveUnder | CWBackingStore| CWOverrideRedirect ), - &xswa); + tmp = XCreateWindow (xwin->main_display, win, 0, 0, + attr.width, attr.height, 0, + CopyFromParent, InputOutput, CopyFromParent, + (CWSaveUnder | CWBackingStore | CWOverrideRedirect), &xswa); XMapWindow (xwin->main_display, tmp); XUnmapWindow (xwin->main_display, tmp); XDestroyWindow (xwin->main_display, tmp); @@ -218,10 +209,9 @@ gst_xwin_refresh (gpointer data) } static int -x11_error_dev_null (Display *display, - XErrorEvent *event) +x11_error_dev_null (Display * display, XErrorEvent * event) { - return 0; + return 0; } #define ADD_CLIP(_x, _y, _w, _h) \ @@ -235,7 +225,7 @@ x11_error_dev_null (Display *display, } while (0); static void -gst_xwin_set_clips (GstXWindowListener *xwin) +gst_xwin_set_clips (GstXWindowListener * xwin) { Window root, rroot, parent, *kids, me; XWindowAttributes attr; @@ -286,10 +276,9 @@ gst_xwin_set_clips (GstXWindowListener *xwin) y1 = attr.y - xwin->y; w1 = attr.width + 2 * attr.border_width; h1 = attr.height + 2 * attr.border_width; - if (((x1 + w1) < 0) || (x1 > xwin->w) || - ((y1 + h1) < 0) || (y1 > xwin->h)) + if (((x1 + w1) < 0) || (x1 > xwin->w) || ((y1 + h1) < 0) || (y1 > xwin->h)) continue; - + if (x1 < 0) x1 = 0; if (y1 < 0) @@ -306,7 +295,7 @@ gst_xwin_set_clips (GstXWindowListener *xwin) static gboolean -gst_xwin_window (GstXWindowListener *xwin) +gst_xwin_window (GstXWindowListener * xwin) { if (xwin->ov_map && xwin->ov_wmmap && xwin->ov_visibility != VisibilityFullyObscured) { @@ -318,20 +307,17 @@ gst_xwin_window (GstXWindowListener *xwin) if (xwin->ov_conf) { xwin->set_window_func (xwin->private_data, - xwin->x, xwin->y, - xwin->w, xwin->h, - xwin->clips, xwin->num_clips); + xwin->x, xwin->y, xwin->w, xwin->h, xwin->clips, xwin->num_clips); if (!xwin->ov_visible) - gst_xwin_set_overlay (xwin, TRUE); + gst_xwin_set_overlay (xwin, TRUE); g_mutex_lock (xwin->main_lock); if (xwin->ov_refresh_id) - g_source_remove (xwin->ov_refresh_id); + g_source_remove (xwin->ov_refresh_id); xwin->ov_refresh_id = - g_timeout_add (200, (GSourceFunc) gst_xwin_refresh, - (gpointer) xwin); + g_timeout_add (200, (GSourceFunc) gst_xwin_refresh, (gpointer) xwin); xwin->ov_conf = FALSE; @@ -345,10 +331,9 @@ gst_xwin_window (GstXWindowListener *xwin) g_mutex_lock (xwin->main_lock); if (xwin->ov_refresh_id) - g_source_remove (xwin->ov_refresh_id); + g_source_remove (xwin->ov_refresh_id); xwin->ov_refresh_id = - g_timeout_add (200, (GSourceFunc) gst_xwin_refresh, - (gpointer) xwin); + g_timeout_add (200, (GSourceFunc) gst_xwin_refresh, (gpointer) xwin); xwin->ov_conf = FALSE; @@ -363,31 +348,28 @@ gst_xwin_window (GstXWindowListener *xwin) } static void -gst_xwin_configure (GstXWindowListener *xwin) +gst_xwin_configure (GstXWindowListener * xwin) { #if 0 /* This part is disabled, because the idle task will be done * in the main thread instead of here. */ if (!xwin->ov_conf_id) xwin->ov_conf_id = - g_idle_add ((GSourceFunc) gst_rec_xoverlay_window, - (gpointer) xwin); + g_idle_add ((GSourceFunc) gst_rec_xoverlay_window, (gpointer) xwin); #endif gst_xwin_window ((gpointer) xwin); } static void -gst_xwin_resize (GstXWindowListener *xwin) +gst_xwin_resize (GstXWindowListener * xwin) { Drawable drawable, parent, *kids, root; guint numkids; XWindowAttributes attr; - XGetWindowAttributes (xwin->display, - xwin->xwindow_id, &attr); - XMoveResizeWindow (xwin->display, xwin->child, - 0, 0, attr.width, attr.height); + XGetWindowAttributes (xwin->display, xwin->xwindow_id, &attr); + XMoveResizeWindow (xwin->display, xwin->child, 0, 0, attr.width, attr.height); /* set the video window - the first clip is our own window */ xwin->x = 0; @@ -397,10 +379,9 @@ gst_xwin_resize (GstXWindowListener *xwin) drawable = xwin->child; while (1) { - XQueryTree (xwin->display, drawable, - &root, &parent, &kids, &numkids); + XQueryTree (xwin->display, drawable, &root, &parent, &kids, &numkids); if (numkids) - XFree(kids); + XFree (kids); drawable = parent; XGetWindowAttributes (xwin->display, drawable, &attr); xwin->x += attr.x; @@ -416,7 +397,7 @@ gst_xwin_resize (GstXWindowListener *xwin) } static void -gst_xwin_init_window (GstXWindowListener *xwin) +gst_xwin_init_window (GstXWindowListener * xwin) { XWindowAttributes attr; @@ -438,20 +419,16 @@ gst_xwin_init_window (GstXWindowListener *xwin) xwin->display = XOpenDisplay (xwin->display_name); /* window */ - XGetWindowAttributes (xwin->display, - xwin->xwindow_id, &attr); + XGetWindowAttributes (xwin->display, xwin->xwindow_id, &attr); xwin->child = XCreateSimpleWindow (xwin->display, - xwin->xwindow_id, 0, 0, - attr.width, attr.height, 0, 0, 0); + xwin->xwindow_id, 0, 0, attr.width, attr.height, 0, 0, 0); /* listen to certain X events */ - XSelectInput (xwin->display, xwin->xwindow_id, - StructureNotifyMask); + XSelectInput (xwin->display, xwin->xwindow_id, StructureNotifyMask); XSelectInput (xwin->display, xwin->child, - VisibilityChangeMask | StructureNotifyMask); + VisibilityChangeMask | StructureNotifyMask); XSelectInput (xwin->display, DefaultRootWindow (xwin->display), - VisibilityChangeMask | StructureNotifyMask | - SubstructureNotifyMask); + VisibilityChangeMask | StructureNotifyMask | SubstructureNotifyMask); /* show */ XMapWindow (xwin->display, xwin->child); @@ -460,7 +437,7 @@ gst_xwin_init_window (GstXWindowListener *xwin) } static void -gst_xwin_exit_window (GstXWindowListener *xwin) +gst_xwin_exit_window (GstXWindowListener * xwin) { /* disable overlay */ gst_xwin_set_overlay (xwin, FALSE); @@ -496,89 +473,89 @@ gst_xwin_thread (gpointer data) break; if ((event.type == ConfigureNotify && - event.xconfigure.window == xwin->xwindow_id) || - (event.type == MapNotify && - event.xmap.window == xwin->xwindow_id) || - (event.type == UnmapNotify && - event.xunmap.window == xwin->xwindow_id)) { + event.xconfigure.window == xwin->xwindow_id) || + (event.type == MapNotify && + event.xmap.window == xwin->xwindow_id) || + (event.type == UnmapNotify && + event.xunmap.window == xwin->xwindow_id)) { /* the 'parent' window, i.e. the widget provided by client */ switch (event.type) { - case MapNotify: - xwin->ov_map = TRUE; - xwin->ov_conf = TRUE; - gst_xwin_configure (xwin); - break; + case MapNotify: + xwin->ov_map = TRUE; + xwin->ov_conf = TRUE; + gst_xwin_configure (xwin); + break; - case UnmapNotify: - xwin->ov_map = FALSE; - xwin->ov_conf = TRUE; - gst_xwin_configure (xwin); - break; + case UnmapNotify: + xwin->ov_map = FALSE; + xwin->ov_conf = TRUE; + gst_xwin_configure (xwin); + break; - case ConfigureNotify: - gst_xwin_resize (xwin); - break; + case ConfigureNotify: + gst_xwin_resize (xwin); + break; - default: - /* nothing */ - break; + default: + /* nothing */ + break; } } else if (event.xany.window == xwin->child) { /* our own private window */ switch (event.type) { - case Expose: - if (!event.xexpose.count) { - if (xwin->ov_refresh) { - xwin->ov_refresh = FALSE; - } else { - xwin->ov_conf = TRUE; - gst_xwin_configure (xwin); - } - } - break; + case Expose: + if (!event.xexpose.count) { + if (xwin->ov_refresh) { + xwin->ov_refresh = FALSE; + } else { + xwin->ov_conf = TRUE; + gst_xwin_configure (xwin); + } + } + break; - case VisibilityNotify: - xwin->ov_visibility = event.xvisibility.state; - if (xwin->ov_refresh) { - if (event.xvisibility.state != VisibilityFullyObscured) - xwin->ov_refresh = FALSE; - } else { - xwin->ov_conf = TRUE; - gst_xwin_configure (xwin); - } - break; + case VisibilityNotify: + xwin->ov_visibility = event.xvisibility.state; + if (xwin->ov_refresh) { + if (event.xvisibility.state != VisibilityFullyObscured) + xwin->ov_refresh = FALSE; + } else { + xwin->ov_conf = TRUE; + gst_xwin_configure (xwin); + } + break; - default: - /* nothing */ - break; + default: + /* nothing */ + break; } } else { /* root window */ switch (event.type) { - case MapNotify: - case UnmapNotify: - /* are we still visible? */ - if (!xwin->ov_refresh) { - XWindowAttributes attr; - gboolean on; - XGetWindowAttributes (xwin->display, - xwin->xwindow_id, &attr); - on = (attr.map_state == IsViewable); - xwin->ov_wmmap = on; - xwin->ov_conf = TRUE; - gst_xwin_configure (xwin); - } - break; + case MapNotify: + case UnmapNotify: + /* are we still visible? */ + if (!xwin->ov_refresh) { + XWindowAttributes attr; + gboolean on; - case ConfigureNotify: - if (!xwin->ov_refresh) { - gst_xwin_resize (xwin); - } - break; + XGetWindowAttributes (xwin->display, xwin->xwindow_id, &attr); + on = (attr.map_state == IsViewable); + xwin->ov_wmmap = on; + xwin->ov_conf = TRUE; + gst_xwin_configure (xwin); + } + break; - default: - /* nothing */ - break; + case ConfigureNotify: + if (!xwin->ov_refresh) { + gst_xwin_resize (xwin); + } + break; + + default: + /* nothing */ + break; } } } @@ -592,7 +569,7 @@ gst_xwin_thread (gpointer data) } static void -gst_xwin_start (GstXWindowListener *xwin) +gst_xwin_start (GstXWindowListener * xwin) { DEBUG ("Starting XWindow listener"); @@ -603,15 +580,13 @@ gst_xwin_start (GstXWindowListener *xwin) * event handler after we've stopped it */ xwin->main_lock = g_mutex_new (); xwin->main_display = XOpenDisplay (xwin->display_name); - xwin->thread = g_thread_create (gst_xwin_thread, - (gpointer) xwin, - TRUE, NULL); + xwin->thread = g_thread_create (gst_xwin_thread, (gpointer) xwin, TRUE, NULL); DEBUG ("Started X-overlay"); } static void -gst_xwin_stop (GstXWindowListener *xwin) +gst_xwin_stop (GstXWindowListener * xwin) { DEBUG ("Stopping XWindow listener"); @@ -637,19 +612,13 @@ gst_xwin_stop (GstXWindowListener *xwin) */ static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "xwindowlistener", - "X11-based XWindow event/motion listener", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "xwindowlistener", + "X11-based XWindow event/motion listener", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) diff --git a/gst-libs/gst/xwindowlistener/xwindowlistener.h b/gst-libs/gst/xwindowlistener/xwindowlistener.h index 834be67cad..1d893640e7 100644 --- a/gst-libs/gst/xwindowlistener/xwindowlistener.h +++ b/gst-libs/gst/xwindowlistener/xwindowlistener.h @@ -26,7 +26,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_X_WINDOW_LISTENER \ (gst_x_window_listener_get_type()) #define GST_X_WINDOW_LISTENER(obj) \ @@ -39,28 +38,22 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_X_WINDOW_LISTENER)) #define GST_IS_X_WINDOW_LISTENER_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_X_WINDOW_LISTENER)) +typedef struct _GstXWindowListener GstXWindowListener; +typedef struct _GstXWindowListenerClass GstXWindowListenerClass; +typedef struct _GstXWindowClip GstXWindowClip; +typedef void (*MapWindowFunc) (gpointer your_data, gboolean visible); +typedef void (*SetWindowFunc) (gpointer your_data, + gint x, gint y, gint w, gint h, GstXWindowClip * clips, gint num_clips); -typedef struct _GstXWindowListener GstXWindowListener; -typedef struct _GstXWindowListenerClass GstXWindowListenerClass; -typedef struct _GstXWindowClip GstXWindowClip; -typedef void (* MapWindowFunc) (gpointer your_data, - gboolean visible); -typedef void (* SetWindowFunc) (gpointer your_data, - gint x, gint y, - gint w, gint h, - GstXWindowClip *clips, - gint num_clips); - -struct _GstXWindowClip { - gint32 x_offset, - y_offset, - width, - height; +struct _GstXWindowClip +{ + gint32 x_offset, y_offset, width, height; gpointer data; }; -struct _GstXWindowListener { - GObject parent; +struct _GstXWindowListener +{ + GObject parent; /* "per-instance virtual functions" */ MapWindowFunc map_window_func; @@ -70,12 +63,12 @@ struct _GstXWindowListener { gpointer private_data; /* general information of what we're doing */ - gchar *display_name; - XID xwindow_id; + gchar *display_name; + XID xwindow_id; /* one extra... */ Display *main_display; - GMutex *main_lock; + GMutex *main_lock; /* oh my g*d, this is going to be so horribly ugly */ GThread *thread; @@ -84,33 +77,24 @@ struct _GstXWindowListener { /* the overlay window + own thread */ Display *display; Drawable child; - gboolean ov_conf, - ov_map, - ov_visible, - ov_refresh, - ov_move, - ov_wmmap; - gint ov_visibility; - guint ov_conf_id, - ov_refresh_id; - gint x, y, w, h; + gboolean ov_conf, ov_map, ov_visible, ov_refresh, ov_move, ov_wmmap; + gint ov_visibility; + guint ov_conf_id, ov_refresh_id; + gint x, y, w, h; GstXWindowClip *clips; - gint num_clips; + gint num_clips; }; -struct _GstXWindowListenerClass { +struct _GstXWindowListenerClass +{ GObjectClass parent; }; -GType gst_x_window_listener_get_type (void); -GstXWindowListener * - gst_x_window_listener_new (gchar *display, - MapWindowFunc map_window_func, - SetWindowFunc set_window_func, - gpointer private_data); -void gst_x_window_listener_set_xid (GstXWindowListener *xwin, - XID id); +GType gst_x_window_listener_get_type (void); +GstXWindowListener *gst_x_window_listener_new (gchar * display, + MapWindowFunc map_window_func, + SetWindowFunc set_window_func, gpointer private_data); +void gst_x_window_listener_set_xid (GstXWindowListener * xwin, XID id); G_END_DECLS - #endif /* __X_WINDOW_LISTENER_H__ */ diff --git a/gst/ac3parse/gstac3parse.c b/gst/ac3parse/gstac3parse.c index b803983b74..143bf68541 100644 --- a/gst/ac3parse/gstac3parse.c +++ b/gst/ac3parse/gstac3parse.c @@ -28,110 +28,102 @@ #include /* struct and table stolen from ac3dec by Aaron Holtzman */ -struct frmsize_s { +struct frmsize_s +{ guint16 bit_rate; guint16 frm_size[3]; }; static struct frmsize_s frmsizecod_tbl[] = { - { 32 ,{64 ,69 ,96 } }, - { 32 ,{64 ,70 ,96 } }, - { 40 ,{80 ,87 ,120 } }, - { 40 ,{80 ,88 ,120 } }, - { 48 ,{96 ,104 ,144 } }, - { 48 ,{96 ,105 ,144 } }, - { 56 ,{112 ,121 ,168 } }, - { 56 ,{112 ,122 ,168 } }, - { 64 ,{128 ,139 ,192 } }, - { 64 ,{128 ,140 ,192 } }, - { 80 ,{160 ,174 ,240 } }, - { 80 ,{160 ,175 ,240 } }, - { 96 ,{192 ,208 ,288 } }, - { 96 ,{192 ,209 ,288 } }, - { 112 ,{224 ,243 ,336 } }, - { 112 ,{224 ,244 ,336 } }, - { 128 ,{256 ,278 ,384 } }, - { 128 ,{256 ,279 ,384 } }, - { 160 ,{320 ,348 ,480 } }, - { 160 ,{320 ,349 ,480 } }, - { 192 ,{384 ,417 ,576 } }, - { 192 ,{384 ,418 ,576 } }, - { 224 ,{448 ,487 ,672 } }, - { 224 ,{448 ,488 ,672 } }, - { 256 ,{512 ,557 ,768 } }, - { 256 ,{512 ,558 ,768 } }, - { 320 ,{640 ,696 ,960 } }, - { 320 ,{640 ,697 ,960 } }, - { 384 ,{768 ,835 ,1152 } }, - { 384 ,{768 ,836 ,1152 } }, - { 448 ,{896 ,975 ,1344 } }, - { 448 ,{896 ,976 ,1344 } }, - { 512 ,{1024 ,1114 ,1536 } }, - { 512 ,{1024 ,1115 ,1536 } }, - { 576 ,{1152 ,1253 ,1728 } }, - { 576 ,{1152 ,1254 ,1728 } }, - { 640 ,{1280 ,1393 ,1920 } }, - { 640 ,{1280 ,1394 ,1920 } }}; + {32, {64, 69, 96}}, + {32, {64, 70, 96}}, + {40, {80, 87, 120}}, + {40, {80, 88, 120}}, + {48, {96, 104, 144}}, + {48, {96, 105, 144}}, + {56, {112, 121, 168}}, + {56, {112, 122, 168}}, + {64, {128, 139, 192}}, + {64, {128, 140, 192}}, + {80, {160, 174, 240}}, + {80, {160, 175, 240}}, + {96, {192, 208, 288}}, + {96, {192, 209, 288}}, + {112, {224, 243, 336}}, + {112, {224, 244, 336}}, + {128, {256, 278, 384}}, + {128, {256, 279, 384}}, + {160, {320, 348, 480}}, + {160, {320, 349, 480}}, + {192, {384, 417, 576}}, + {192, {384, 418, 576}}, + {224, {448, 487, 672}}, + {224, {448, 488, 672}}, + {256, {512, 557, 768}}, + {256, {512, 558, 768}}, + {320, {640, 696, 960}}, + {320, {640, 697, 960}}, + {384, {768, 835, 1152}}, + {384, {768, 836, 1152}}, + {448, {896, 975, 1344}}, + {448, {896, 976, 1344}}, + {512, {1024, 1114, 1536}}, + {512, {1024, 1115, 1536}}, + {576, {1152, 1253, 1728}}, + {576, {1152, 1254, 1728}}, + {640, {1280, 1393, 1920}}, + {640, {1280, 1394, 1920}} +}; /* elementfactory information */ -static GstElementDetails ac3parse_details = GST_ELEMENT_DETAILS ( - "AC3 Parser", - "Codec/Parser/Audio", - "Parses and frames AC3 audio streams, provides seek", - "Erik Walthinsen " -); +static GstElementDetails ac3parse_details = GST_ELEMENT_DETAILS ("AC3 Parser", + "Codec/Parser/Audio", + "Parses and frames AC3 audio streams, provides seek", + "Erik Walthinsen "); /* GstAc3Parse signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_SKIP, /* FILL ME */ }; static GstStaticPadTemplate gst_ac3parse_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "audio/ac3, " - "channels = (int) [ 1, 6 ], " - "rate = (int) [ 32000, 48000 ]" - ) -); +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/ac3, " + "channels = (int) [ 1, 6 ], " "rate = (int) [ 32000, 48000 ]") + ); static GstStaticPadTemplate gst_ac3parse_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-ac3") -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-ac3") + ); -static void gst_ac3parse_class_init (gpointer g_class); -static void gst_ac3parse_init (GstAc3Parse *ac3parse); +static void gst_ac3parse_class_init (gpointer g_class); +static void gst_ac3parse_init (GstAc3Parse * ac3parse); -static void gst_ac3parse_chain (GstPad *pad, - GstData *data); +static void gst_ac3parse_chain (GstPad * pad, GstData * data); -static void gst_ac3parse_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void gst_ac3parse_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); +static void gst_ac3parse_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec); +static void gst_ac3parse_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); -static GstElementStateReturn - gst_ac3parse_change_state (GstElement *element); +static GstElementStateReturn gst_ac3parse_change_state (GstElement * element); static GstElementClass *parent_class = NULL; + /*static guint gst_ac3parse_signals[LAST_SIGNAL] = { 0 };*/ GType @@ -141,16 +133,18 @@ ac3parse_get_type (void) if (!ac3parse_type) { static const GTypeInfo ac3parse_info = { - sizeof(GstAc3ParseClass), NULL, + sizeof (GstAc3ParseClass), NULL, NULL, - (GClassInitFunc)gst_ac3parse_class_init, + (GClassInitFunc) gst_ac3parse_class_init, NULL, NULL, - sizeof(GstAc3Parse), + sizeof (GstAc3Parse), 0, - (GInstanceInitFunc)gst_ac3parse_init, + (GInstanceInitFunc) gst_ac3parse_init, }; - ac3parse_type = g_type_register_static(GST_TYPE_ELEMENT, "GstAc3Parse", &ac3parse_info, 0); + ac3parse_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstAc3Parse", &ac3parse_info, + 0); } return ac3parse_type; } @@ -162,22 +156,19 @@ gst_ac3parse_class_init (gpointer g_class) GstElementClass *gstelement_class; GstAc3ParseClass *klass; - klass = (GstAc3ParseClass *)g_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + klass = (GstAc3ParseClass *) g_class; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; gst_element_class_add_pad_template (gstelement_class, gst_static_pad_template_get (&gst_ac3parse_src_template)); gst_element_class_add_pad_template (gstelement_class, gst_static_pad_template_get (&gst_ac3parse_sink_template)); - gst_element_class_set_details (gstelement_class, - &ac3parse_details); + gst_element_class_set_details (gstelement_class, &ac3parse_details); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SKIP, - g_param_spec_int("skip","skip","skip", - G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SKIP, g_param_spec_int ("skip", "skip", "skip", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gobject_class->set_property = gst_ac3parse_set_property; gobject_class->get_property = gst_ac3parse_get_property; @@ -186,15 +177,17 @@ gst_ac3parse_class_init (gpointer g_class) } static void -gst_ac3parse_init (GstAc3Parse *ac3parse) +gst_ac3parse_init (GstAc3Parse * ac3parse) { - ac3parse->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_ac3parse_sink_template), "sink"); + ac3parse->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_ac3parse_sink_template), "sink"); gst_element_add_pad (GST_ELEMENT (ac3parse), ac3parse->sinkpad); gst_pad_set_chain_function (ac3parse->sinkpad, gst_ac3parse_chain); - ac3parse->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_ac3parse_src_template), "src"); + ac3parse->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_ac3parse_src_template), "src"); gst_pad_use_explicit_caps (ac3parse->srcpad); gst_element_add_pad (GST_ELEMENT (ac3parse), ac3parse->srcpad); @@ -205,40 +198,40 @@ gst_ac3parse_init (GstAc3Parse *ac3parse) } static void -gst_ac3parse_chain (GstPad *pad, GstData *_data) +gst_ac3parse_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstAc3Parse *ac3parse; guchar *data; - glong size,offset = 0; + glong size, offset = 0; guint16 header; guint8 channeldata, acmod, mask; GstBuffer *outbuf = NULL; gint bpf; guint sample_rate = -1, channels = -1; - g_return_if_fail(pad != NULL); - g_return_if_fail(GST_IS_PAD(pad)); - g_return_if_fail(buf != NULL); + g_return_if_fail (pad != NULL); + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (buf != NULL); /* g_return_if_fail(GST_IS_BUFFER(buf)); */ - ac3parse = GST_AC3PARSE(GST_OBJECT_PARENT (pad)); + ac3parse = GST_AC3PARSE (GST_OBJECT_PARENT (pad)); GST_DEBUG ("ac3parse: received buffer of %d bytes", GST_BUFFER_SIZE (buf)); /* deal with partial frame from previous buffer */ if (ac3parse->partialbuf) { GstBuffer *merge; - merge = gst_buffer_merge(ac3parse->partialbuf, buf); - gst_buffer_unref(buf); - gst_buffer_unref(ac3parse->partialbuf); + + merge = gst_buffer_merge (ac3parse->partialbuf, buf); + gst_buffer_unref (buf); + gst_buffer_unref (ac3parse->partialbuf); ac3parse->partialbuf = merge; - } - else { + } else { ac3parse->partialbuf = buf; } - data = GST_BUFFER_DATA(ac3parse->partialbuf); - size = GST_BUFFER_SIZE(ac3parse->partialbuf); + data = GST_BUFFER_DATA (ac3parse->partialbuf); + size = GST_BUFFER_SIZE (ac3parse->partialbuf); /* we're searching for at least 7 bytes. first the * syncinfo, where 2 bytes are for the syncword @@ -247,142 +240,151 @@ gst_ac3parse_chain (GstPad *pad, GstData *_data) * bitstreaminfo bsid (version), bsmod (data type) and * acmod (channel info, 3 bits). Then some "maybe" * bits, and then the LFE indicator (subwoofer bit) */ - while (offset < size-6) { + while (offset < size - 6) { int skipped = 0; - GST_DEBUG ("ac3parse: offset %ld, size %ld ",offset, size); + GST_DEBUG ("ac3parse: offset %ld, size %ld ", offset, size); /* search for a possible start byte */ - for (;((data[offset] != 0x0b) && (offset < size-6));offset++) skipped++ ; + for (; ((data[offset] != 0x0b) && (offset < size - 6)); offset++) + skipped++; if (skipped) { - fprintf(stderr, "ac3parse: **** now at %ld skipped %d bytes (FIXME?)\n",offset,skipped); + fprintf (stderr, "ac3parse: **** now at %ld skipped %d bytes (FIXME?)\n", + offset, skipped); } /* construct the header word */ - header = GUINT16_TO_BE(*((guint16 *)(data+offset))); + header = GUINT16_TO_BE (*((guint16 *) (data + offset))); /* g_print("AC3PARSE: sync word is 0x%02X\n",header); */ /* if it's a valid header, go ahead and send off the frame */ if (header == 0x0b77) { gint rate, fsize; + /* g_print("AC3PARSE: found sync at %d\n",offset); */ /* get the bits we're interested in */ - rate = (data[offset+4] >> 6) & 0x3; + rate = (data[offset + 4] >> 6) & 0x3; switch (rate) { - case 0x0: /* 00b */ - sample_rate = 48000; - break; - case 0x1: /* 01b */ - sample_rate = 44100; - break; - case 0x2: /* 10b */ - sample_rate = 32000; - break; - case 0x3: /* 11b */ - default: - /* reserved. if this happens, we're screwed */ - g_assert (0); - break; + case 0x0: /* 00b */ + sample_rate = 48000; + break; + case 0x1: /* 01b */ + sample_rate = 44100; + break; + case 0x2: /* 10b */ + sample_rate = 32000; + break; + case 0x3: /* 11b */ + default: + /* reserved. if this happens, we're screwed */ + g_assert (0); + break; } - fsize = data[offset+4] & 0x3f; + fsize = data[offset + 4] & 0x3f; /* calculate the bpf of the frame */ bpf = frmsizecod_tbl[fsize].frm_size[rate] * 2; /* calculate number of channels */ - channeldata = data[offset+6]; /* skip bsid/bsmod */ + channeldata = data[offset + 6]; /* skip bsid/bsmod */ acmod = (channeldata >> 5) & 0x7; switch (acmod) { - case 0x1: /* 001b = 1 channel */ - channels = 1; - break; - case 0x0: /* 000b = 2 independent channels*/ - case 0x2: /* 010b = 2x front (stereo) */ - channels = 2; - break; - case 0x3: /* 011b = 3 front */ - case 0x4: /* 100b = 2 front, 1 rear */ - channels = 3; - break; - case 0x5: /* 101b = 3 front, 1 rear */ - case 0x6: /* 110b = 2 front, 2 rear */ - channels = 4; - break; - case 0x7: /* 111b = 3 front, 2 rear */ - channels = 5; - break; - default: - /* whaaaaaaaaaaaaaa!!!!!!!!!!! */ - g_assert (0); + case 0x1: /* 001b = 1 channel */ + channels = 1; + break; + case 0x0: /* 000b = 2 independent channels */ + case 0x2: /* 010b = 2x front (stereo) */ + channels = 2; + break; + case 0x3: /* 011b = 3 front */ + case 0x4: /* 100b = 2 front, 1 rear */ + channels = 3; + break; + case 0x5: /* 101b = 3 front, 1 rear */ + case 0x6: /* 110b = 2 front, 2 rear */ + channels = 4; + break; + case 0x7: /* 111b = 3 front, 2 rear */ + channels = 5; + break; + default: + /* whaaaaaaaaaaaaaa!!!!!!!!!!! */ + g_assert (0); } /* fetch LFE bit (subwoofer) */ mask = 0x10; - if (acmod & 0x1 && acmod != 0x1) /* 3 front speakers? */ - mask >>= 2; - if (acmod & 0x4) /* surround channel? */ - mask >>= 2; - if (acmod == 0x2) /* 2/0 mode? */ - mask >>= 2; - if (channeldata & mask) /* LFE: do we have a subwoofer channel? */ - channels++; + if (acmod & 0x1 && acmod != 0x1) /* 3 front speakers? */ + mask >>= 2; + if (acmod & 0x4) /* surround channel? */ + mask >>= 2; + if (acmod == 0x2) /* 2/0 mode? */ + mask >>= 2; + if (channeldata & mask) /* LFE: do we have a subwoofer channel? */ + channels++; /* if we don't have the whole frame... */ if ((size - offset) < bpf) { - GST_DEBUG ("ac3parse: partial buffer needed %ld < %d ",size-offset, bpf); + GST_DEBUG ("ac3parse: partial buffer needed %ld < %d ", size - offset, + bpf); break; } else { - gboolean need_capsnego = FALSE; + gboolean need_capsnego = FALSE; - outbuf = gst_buffer_create_sub (ac3parse->partialbuf,offset,bpf); + outbuf = gst_buffer_create_sub (ac3parse->partialbuf, offset, bpf); - /* make sure our properties still match */ - if (channels > 0 && ac3parse->channels != channels) { - ac3parse->channels = channels; - need_capsnego = TRUE; - } - if (sample_rate > 0 && ac3parse->sample_rate != sample_rate) { - ac3parse->sample_rate = sample_rate; - need_capsnego = TRUE; - } - if (need_capsnego) { - GstCaps *newcaps; - newcaps = gst_caps_new_simple ("audio/x-ac3", + /* make sure our properties still match */ + if (channels > 0 && ac3parse->channels != channels) { + ac3parse->channels = channels; + need_capsnego = TRUE; + } + if (sample_rate > 0 && ac3parse->sample_rate != sample_rate) { + ac3parse->sample_rate = sample_rate; + need_capsnego = TRUE; + } + if (need_capsnego) { + GstCaps *newcaps; + + newcaps = gst_caps_new_simple ("audio/x-ac3", "channels", G_TYPE_INT, channels, - "rate", G_TYPE_INT, sample_rate, NULL); - gst_pad_set_explicit_caps (ac3parse->srcpad, newcaps); - } + "rate", G_TYPE_INT, sample_rate, NULL); + gst_pad_set_explicit_caps (ac3parse->srcpad, newcaps); + } offset += bpf; - if (ac3parse->skip == 0 && GST_PAD_IS_LINKED(ac3parse->srcpad)) { - GST_DEBUG ("ac3parse: pushing buffer of %d bytes",GST_BUFFER_SIZE(outbuf)); - gst_pad_push(ac3parse->srcpad,GST_DATA (outbuf)); - } - else { - GST_DEBUG ("ac3parse: skipping buffer of %d bytes",GST_BUFFER_SIZE(outbuf)); - gst_buffer_unref(outbuf); + if (ac3parse->skip == 0 && GST_PAD_IS_LINKED (ac3parse->srcpad)) { + GST_DEBUG ("ac3parse: pushing buffer of %d bytes", + GST_BUFFER_SIZE (outbuf)); + gst_pad_push (ac3parse->srcpad, GST_DATA (outbuf)); + } else { + GST_DEBUG ("ac3parse: skipping buffer of %d bytes", + GST_BUFFER_SIZE (outbuf)); + gst_buffer_unref (outbuf); ac3parse->skip--; } } } else { offset++; - fprintf(stderr, "ac3parse: *** wrong header, skipping byte (FIXME?)\n"); + fprintf (stderr, "ac3parse: *** wrong header, skipping byte (FIXME?)\n"); } } /* if we have processed this block and there are still */ /* bytes left not in a partial block, copy them over. */ - if (size-offset > 0) { + if (size - offset > 0) { gint remainder = (size - offset); - GST_DEBUG ("ac3parse: partial buffer needed %d for trailing bytes",remainder); - outbuf = gst_buffer_create_sub(ac3parse->partialbuf,offset,remainder); - gst_buffer_unref(ac3parse->partialbuf); + GST_DEBUG ("ac3parse: partial buffer needed %d for trailing bytes", + remainder); + + outbuf = gst_buffer_create_sub (ac3parse->partialbuf, offset, remainder); + gst_buffer_unref (ac3parse->partialbuf); ac3parse->partialbuf = outbuf; } } static void -gst_ac3parse_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_ac3parse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstAc3Parse *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_AC3PARSE(object)); - src = GST_AC3PARSE(object); + g_return_if_fail (GST_IS_AC3PARSE (object)); + src = GST_AC3PARSE (object); switch (prop_id) { case ARG_SKIP: @@ -394,13 +396,14 @@ gst_ac3parse_set_property (GObject *object, guint prop_id, const GValue *value, } static void -gst_ac3parse_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_ac3parse_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstAc3Parse *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_AC3PARSE(object)); - src = GST_AC3PARSE(object); + g_return_if_fail (GST_IS_AC3PARSE (object)); + src = GST_AC3PARSE (object); switch (prop_id) { case ARG_SKIP: @@ -412,9 +415,9 @@ gst_ac3parse_get_property (GObject *object, guint prop_id, GValue *value, GParam } static GstElementStateReturn -gst_ac3parse_change_state (GstElement *element) +gst_ac3parse_change_state (GstElement * element) { - GstAc3Parse *ac3parse = GST_AC3PARSE(element); + GstAc3Parse *ac3parse = GST_AC3PARSE (element); switch (GST_STATE_TRANSITION (element)) { case GST_STATE_PAUSED_TO_READY: @@ -430,25 +433,17 @@ gst_ac3parse_change_state (GstElement *element) } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if(!gst_element_register(plugin, "ac3parse", GST_RANK_SECONDARY, - GST_TYPE_AC3PARSE)){ + if (!gst_element_register (plugin, "ac3parse", GST_RANK_SECONDARY, + GST_TYPE_AC3PARSE)) { return FALSE; } return TRUE; } -GST_PLUGIN_DEFINE( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "ac3parse", - "ac3 parsing", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -) - +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "ac3parse", + "ac3 parsing", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/gst/ac3parse/gstac3parse.h b/gst/ac3parse/gstac3parse.h index e93746d22b..8c4ea5e5e5 100644 --- a/gst/ac3parse/gstac3parse.h +++ b/gst/ac3parse/gstac3parse.h @@ -26,8 +26,9 @@ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_AC3PARSE \ @@ -41,34 +42,36 @@ extern "C" { #define GST_IS_AC3PARSE_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AC3PARSE))) -typedef struct _GstAc3Parse GstAc3Parse; -typedef struct _GstAc3ParseClass GstAc3ParseClass; + typedef struct _GstAc3Parse GstAc3Parse; + typedef struct _GstAc3ParseClass GstAc3ParseClass; -struct _GstAc3Parse { - GstElement element; + struct _GstAc3Parse + { + GstElement element; - GstPad *sinkpad,*srcpad; + GstPad *sinkpad, *srcpad; - GstBuffer *partialbuf; /* previous buffer (if carryover) */ - guint lastframebytes; /* bytes in previous of last frame so far */ - guint lastframesize; /* total length of last frame */ - guint skip; /* number of frames to skip */ + GstBuffer *partialbuf; /* previous buffer (if carryover) */ + guint lastframebytes; /* bytes in previous of last frame so far */ + guint lastframesize; /* total length of last frame */ + guint skip; /* number of frames to skip */ - /* some stream parameters */ - gint sample_rate; - gint channels; -}; + /* some stream parameters */ + gint sample_rate; + gint channels; + }; -struct _GstAc3ParseClass { - GstElementClass parent_class; -}; + struct _GstAc3ParseClass + { + GstElementClass parent_class; + }; -GType gst_ac3parse_get_type(void); + GType gst_ac3parse_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __AC3PARSE_H__ */ +#endif /* __AC3PARSE_H__ */ diff --git a/gst/asfdemux/asfheaders.h b/gst/asfdemux/asfheaders.h index 0f8106ccb7..c0b22cf4ed 100644 --- a/gst/asfdemux/asfheaders.h +++ b/gst/asfdemux/asfheaders.h @@ -20,21 +20,24 @@ #ifndef ASFHEADERS_H #define ASFHEADERS_H -typedef struct { +typedef struct +{ guint32 v1; guint32 v2; guint32 v3; guint32 v4; } ASFGuid; - -typedef struct { - guint8 obj_id; + +typedef struct +{ + guint8 obj_id; ASFGuid guid; } ASFGuidHash; -enum { +enum +{ ASF_OBJ_UNDEFINED = 0, ASF_OBJ_STREAM, ASF_OBJ_DATA, @@ -53,40 +56,44 @@ enum { ASF_OBJ_BITRATE_MUTEX, }; -enum { +enum +{ ASF_STREAM_UNDEFINED = 0, ASF_STREAM_VIDEO, ASF_STREAM_AUDIO, }; -enum { +enum +{ ASF_CORRECTION_UNDEFINED = 0, ASF_CORRECTION_ON, ASF_CORRECTION_OFF, }; static ASFGuidHash asf_correction_guids[] = { - { ASF_CORRECTION_ON, { 0xBFC3CD50, 0x11CF618F, 0xAA00B28B, 0x20E2B400 }}, + {ASF_CORRECTION_ON, {0xBFC3CD50, 0x11CF618F, 0xAA00B28B, 0x20E2B400}}, /* { ASF_CORRECTION_OFF, { 0x20FB5700, 0x11CF5B55, 0x8000FDA8, 0x2B445C5F }},*/ - { ASF_CORRECTION_OFF, { 0x49F1A440, 0x11D04ECE, 0xA000ACA3, 0xF64803C9 }}, - { ASF_CORRECTION_UNDEFINED, { 0, 0, 0, 0 }}, + {ASF_CORRECTION_OFF, {0x49F1A440, 0x11D04ECE, 0xA000ACA3, 0xF64803C9}}, + {ASF_CORRECTION_UNDEFINED, {0, 0, 0, 0}}, }; static ASFGuidHash asf_stream_guids[] = { - { ASF_STREAM_VIDEO, { 0xBC19EFC0, 0x11CF5B4D, 0x8000FDA8, 0x2B445C5F }}, - { ASF_STREAM_AUDIO, { 0xF8699E40, 0x11CF5B4D, 0x8000FDA8, 0x2B445C5F }}, - { ASF_STREAM_UNDEFINED, { 0, 0, 0, 0 }}, + {ASF_STREAM_VIDEO, {0xBC19EFC0, 0x11CF5B4D, 0x8000FDA8, 0x2B445C5F}}, + {ASF_STREAM_AUDIO, {0xF8699E40, 0x11CF5B4D, 0x8000FDA8, 0x2B445C5F}}, + {ASF_STREAM_UNDEFINED, {0, 0, 0, 0}}, }; -struct _asf_obj_header { +struct _asf_obj_header +{ guint32 num_objects; - guint8 unknown1; - guint8 unknown2; + guint8 unknown1; + guint8 unknown2; }; typedef struct _asf_obj_header asf_obj_header; -struct _asf_obj_comment { +struct _asf_obj_comment +{ guint16 title_length; guint16 author_length; guint16 copyright_length; @@ -96,7 +103,8 @@ struct _asf_obj_comment { typedef struct _asf_obj_comment asf_obj_comment; -struct _asf_obj_file { +struct _asf_obj_file +{ ASFGuid file_id; guint64 file_size; guint64 creation_time; @@ -112,7 +120,8 @@ struct _asf_obj_file { typedef struct _asf_obj_file asf_obj_file; -struct _asf_obj_stream { +struct _asf_obj_stream +{ ASFGuid type; ASFGuid correction; guint64 unknown1; @@ -124,7 +133,8 @@ struct _asf_obj_stream { typedef struct _asf_obj_stream asf_obj_stream; -struct _asf_stream_audio { +struct _asf_stream_audio +{ guint16 codec_tag; guint16 channels; guint32 sample_rate; @@ -136,26 +146,29 @@ struct _asf_stream_audio { typedef struct _asf_stream_audio asf_stream_audio; -struct _asf_stream_correction { - guint8 span; +struct _asf_stream_correction +{ + guint8 span; guint16 packet_size; guint16 chunk_size; guint16 data_size; - guint8 silence_data; + guint8 silence_data; }; typedef struct _asf_stream_correction asf_stream_correction; -struct _asf_stream_video { +struct _asf_stream_video +{ guint32 width; guint32 height; - guint8 unknown; + guint8 unknown; guint16 size; }; typedef struct _asf_stream_video asf_stream_video; -struct _asf_stream_video_format { +struct _asf_stream_video_format +{ guint32 size; guint32 width; guint32 height; @@ -171,62 +184,69 @@ struct _asf_stream_video_format { typedef struct _asf_stream_video_format asf_stream_video_format; -struct _asf_obj_data { +struct _asf_obj_data +{ ASFGuid file_id; guint64 packets; - guint8 unknown1; + guint8 unknown1; /* guint8 unknown2; FIXME: this object is supposed to be 26 bytes?! */ - guint8 correction; + guint8 correction; }; typedef struct _asf_obj_data asf_obj_data; -struct _asf_obj_data_correction { +struct _asf_obj_data_correction +{ guint8 type; guint8 cycle; }; typedef struct _asf_obj_data_correction asf_obj_data_correction; -struct _asf_obj_data_packet { - guint8 flags; - guint8 property; +struct _asf_obj_data_packet +{ + guint8 flags; + guint8 property; }; typedef struct _asf_obj_data_packet asf_obj_data_packet; -struct _asf_packet_info { - guint32 padsize; - guint8 replicsizetype; - guint8 fragoffsettype; - guint8 seqtype; - guint8 segsizetype; +struct _asf_packet_info +{ + guint32 padsize; + guint8 replicsizetype; + guint8 fragoffsettype; + guint8 seqtype; + guint8 segsizetype; gboolean multiple; - guint32 size_left; + guint32 size_left; }; typedef struct _asf_packet_info asf_packet_info; -struct _asf_segment_info { - guint8 stream_number; - guint32 chunk_size; - guint32 frag_offset; - guint32 segment_size; - guint32 sequence; - guint32 frag_timestamp; +struct _asf_segment_info +{ + guint8 stream_number; + guint32 chunk_size; + guint32 frag_offset; + guint32 segment_size; + guint32 sequence; + guint32 frag_timestamp; gboolean compressed; }; typedef struct _asf_segment_info asf_segment_info; -struct _asf_replicated_data { +struct _asf_replicated_data +{ guint32 object_size; guint32 frag_timestamp; }; typedef struct _asf_replicated_data asf_replicated_data; -struct _asf_bitrate_record { +struct _asf_bitrate_record +{ guint16 stream_id; guint32 bitrate; }; @@ -234,22 +254,22 @@ struct _asf_bitrate_record { typedef struct _asf_bitrate_record asf_bitrate_record; static ASFGuidHash asf_object_guids[] = { - { ASF_OBJ_STREAM, { 0xB7DC0791, 0x11CFA9B7, 0xC000E68E, 0x6553200C }}, - { ASF_OBJ_DATA, { 0x75b22636, 0x11cf668e, 0xAA00D9a6, 0x6Cce6200 }}, - { ASF_OBJ_FILE, { 0x8CABDCA1, 0x11CFA947, 0xC000E48E, 0x6553200C }}, - { ASF_OBJ_HEADER, { 0x75B22630, 0x11CF668E, 0xAA00D9A6, 0x6CCE6200 }}, - { ASF_OBJ_CONCEAL_NONE, { 0x20fb5700, 0x11cf5b55, 0x8000FDa8, 0x2B445C5f }}, - { ASF_OBJ_COMMENT, { 0x75b22633, 0x11cf668e, 0xAA00D9a6, 0x6Cce6200 }}, - { ASF_OBJ_CODEC_COMMENT, { 0x86D15240, 0x11D0311D, 0xA000A4A3, 0xF64803C9 }}, - { ASF_OBJ_CODEC_COMMENT1, { 0x86d15241, 0x11d0311d, 0xA000A4a3, 0xF64803c9 }}, - { ASF_OBJ_INDEX, { 0x33000890, 0x11cfe5b1, 0xA000F489, 0xCB4903c9 }}, - { ASF_OBJ_HEAD1, { 0x5fbf03b5, 0x11cfa92e, 0xC000E38e, 0x6553200c }}, - { ASF_OBJ_HEAD2, { 0xabd3d211, 0x11cfa9ba, 0xC000E68e, 0x6553200c }}, - { ASF_OBJ_PADDING, { 0x1806D474, 0x4509CADF, 0xAB9ABAA4, 0xE8AA96CD }}, - { ASF_OBJ_BITRATE_PROPS, { 0x7bf875ce, 0x11d1468d, 0x6000828d, 0xb2a2c997 }}, - { ASF_OBJ_EXT_CONTENT_DESC, { 0xd2d0a440, 0x11d2e307, 0xa000f097, 0x50a85ec9 }}, - { ASF_OBJ_BITRATE_MUTEX, { 0xd6e229dc, 0x11d135da, 0xa0003490, 0xbe4903c9 }}, - { ASF_OBJ_UNDEFINED, { 0, 0, 0, 0 }}, + {ASF_OBJ_STREAM, {0xB7DC0791, 0x11CFA9B7, 0xC000E68E, 0x6553200C}}, + {ASF_OBJ_DATA, {0x75b22636, 0x11cf668e, 0xAA00D9a6, 0x6Cce6200}}, + {ASF_OBJ_FILE, {0x8CABDCA1, 0x11CFA947, 0xC000E48E, 0x6553200C}}, + {ASF_OBJ_HEADER, {0x75B22630, 0x11CF668E, 0xAA00D9A6, 0x6CCE6200}}, + {ASF_OBJ_CONCEAL_NONE, {0x20fb5700, 0x11cf5b55, 0x8000FDa8, 0x2B445C5f}}, + {ASF_OBJ_COMMENT, {0x75b22633, 0x11cf668e, 0xAA00D9a6, 0x6Cce6200}}, + {ASF_OBJ_CODEC_COMMENT, {0x86D15240, 0x11D0311D, 0xA000A4A3, 0xF64803C9}}, + {ASF_OBJ_CODEC_COMMENT1, {0x86d15241, 0x11d0311d, 0xA000A4a3, 0xF64803c9}}, + {ASF_OBJ_INDEX, {0x33000890, 0x11cfe5b1, 0xA000F489, 0xCB4903c9}}, + {ASF_OBJ_HEAD1, {0x5fbf03b5, 0x11cfa92e, 0xC000E38e, 0x6553200c}}, + {ASF_OBJ_HEAD2, {0xabd3d211, 0x11cfa9ba, 0xC000E68e, 0x6553200c}}, + {ASF_OBJ_PADDING, {0x1806D474, 0x4509CADF, 0xAB9ABAA4, 0xE8AA96CD}}, + {ASF_OBJ_BITRATE_PROPS, {0x7bf875ce, 0x11d1468d, 0x6000828d, 0xb2a2c997}}, + {ASF_OBJ_EXT_CONTENT_DESC, {0xd2d0a440, 0x11d2e307, 0xa000f097, 0x50a85ec9}}, + {ASF_OBJ_BITRATE_MUTEX, {0xd6e229dc, 0x11d135da, 0xa0003490, 0xbe4903c9}}, + {ASF_OBJ_UNDEFINED, {0, 0, 0, 0}}, }; diff --git a/gst/asfdemux/gstasfdemux.c b/gst/asfdemux/gstasfdemux.c index 8c298fc92e..8181fb01d1 100644 --- a/gst/asfdemux/gstasfdemux.c +++ b/gst/asfdemux/gstasfdemux.c @@ -23,7 +23,7 @@ #endif #include #include "gstasfdemux.h" -#include "gstasfmux.h" /* for the type registering */ +#include "gstasfmux.h" /* for the type registering */ #include "asfheaders.h" /* elementfactory information */ @@ -35,63 +35,48 @@ static GstElementDetails gst_asf_demux_details = { }; static GstStaticPadTemplate gst_asf_demux_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS("video/x-ms-asf") -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-ms-asf") + ); GST_DEBUG_CATEGORY_STATIC (asf_debug); #define GST_CAT_DEFAULT asf_debug - -static void gst_asf_demux_base_init (gpointer g_class); -static void gst_asf_demux_class_init (GstASFDemuxClass *klass); -static void gst_asf_demux_init (GstASFDemux *asf_demux); -static gboolean gst_asf_demux_send_event (GstElement *element, - GstEvent *event); -static void gst_asf_demux_loop (GstElement *element); -static gboolean gst_asf_demux_process_object (GstASFDemux *asf_demux); -static void gst_asf_demux_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static guint32 gst_asf_demux_identify_guid (GstASFDemux *asf_demux, - ASFGuidHash *guids, - ASFGuid *guid_raw); -static gboolean gst_asf_demux_process_chunk (GstASFDemux *asf_demux, - asf_packet_info *packet_info, - asf_segment_info *segment_info); -static const GstEventMask* gst_asf_demux_get_src_event_mask (GstPad *pad); -static gboolean gst_asf_demux_handle_sink_event (GstASFDemux *asf_demux, - GstEvent *event, - guint32 remaining); -static gboolean gst_asf_demux_handle_src_event (GstPad *pad, - GstEvent *event); -static const GstFormat* gst_asf_demux_get_src_formats (GstPad *pad); -static const GstQueryType* gst_asf_demux_get_src_query_types (GstPad *pad); -static gboolean gst_asf_demux_handle_src_query (GstPad *pad, - GstQueryType type, - GstFormat *format, gint64 *value); -static gboolean gst_asf_demux_add_video_stream (GstASFDemux *asf_demux, - asf_stream_video_format *video_format, - guint16 id); -static gboolean gst_asf_demux_add_audio_stream (GstASFDemux *asf_demux, - asf_stream_audio *audio, - guint16 id); -static gboolean gst_asf_demux_setup_pad (GstASFDemux *asf_demux, - GstPad *src_pad, - GstCaps *caps, - guint16 id); -static GstElementStateReturn gst_asf_demux_change_state (GstElement *element); -static GstCaps * gst_asf_demux_video_caps (guint32 codec_fcc, - asf_stream_video_format *video, - char **codec_name); -static GstCaps * gst_asf_demux_audio_caps (guint16 codec_id, - asf_stream_audio *audio, - guint8 *extradata, - char **codec_name); +static void gst_asf_demux_base_init (gpointer g_class); +static void gst_asf_demux_class_init (GstASFDemuxClass * klass); +static void gst_asf_demux_init (GstASFDemux * asf_demux); +static gboolean gst_asf_demux_send_event (GstElement * element, + GstEvent * event); +static void gst_asf_demux_loop (GstElement * element); +static gboolean gst_asf_demux_process_object (GstASFDemux * asf_demux); +static void gst_asf_demux_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); +static guint32 gst_asf_demux_identify_guid (GstASFDemux * asf_demux, + ASFGuidHash * guids, ASFGuid * guid_raw); +static gboolean gst_asf_demux_process_chunk (GstASFDemux * asf_demux, + asf_packet_info * packet_info, asf_segment_info * segment_info); +static const GstEventMask *gst_asf_demux_get_src_event_mask (GstPad * pad); +static gboolean gst_asf_demux_handle_sink_event (GstASFDemux * asf_demux, + GstEvent * event, guint32 remaining); +static gboolean gst_asf_demux_handle_src_event (GstPad * pad, GstEvent * event); +static const GstFormat *gst_asf_demux_get_src_formats (GstPad * pad); +static const GstQueryType *gst_asf_demux_get_src_query_types (GstPad * pad); +static gboolean gst_asf_demux_handle_src_query (GstPad * pad, + GstQueryType type, GstFormat * format, gint64 * value); +static gboolean gst_asf_demux_add_video_stream (GstASFDemux * asf_demux, + asf_stream_video_format * video_format, guint16 id); +static gboolean gst_asf_demux_add_audio_stream (GstASFDemux * asf_demux, + asf_stream_audio * audio, guint16 id); +static gboolean gst_asf_demux_setup_pad (GstASFDemux * asf_demux, + GstPad * src_pad, GstCaps * caps, guint16 id); + +static GstElementStateReturn gst_asf_demux_change_state (GstElement * element); +static GstCaps *gst_asf_demux_video_caps (guint32 codec_fcc, + asf_stream_video_format * video, char **codec_name); +static GstCaps *gst_asf_demux_audio_caps (guint16 codec_id, + asf_stream_audio * audio, guint8 * extradata, char **codec_name); static GstPadTemplate *videosrctempl, *audiosrctempl; static GstElementClass *parent_class = NULL; @@ -103,17 +88,19 @@ asf_demux_get_type (void) if (!asf_demux_type) { static const GTypeInfo asf_demux_info = { - sizeof(GstASFDemuxClass), + sizeof (GstASFDemuxClass), gst_asf_demux_base_init, NULL, - (GClassInitFunc)gst_asf_demux_class_init, + (GClassInitFunc) gst_asf_demux_class_init, NULL, NULL, - sizeof(GstASFDemux), + sizeof (GstASFDemux), 0, - (GInstanceInitFunc)gst_asf_demux_init, + (GInstanceInitFunc) gst_asf_demux_init, }; - asf_demux_type = g_type_register_static(GST_TYPE_ELEMENT, "GstASFDemux", &asf_demux_info, 0); + asf_demux_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstASFDemux", + &asf_demux_info, 0); } return asf_demux_type; } @@ -125,18 +112,18 @@ gst_asf_demux_base_init (gpointer g_class) int i; GstCaps *audcaps, *vidcaps, *temp; guint32 vid_list[] = { - GST_MAKE_FOURCC('I','4','2','0'), - GST_MAKE_FOURCC('Y','U','Y','2'), - GST_MAKE_FOURCC('M','J','P','G'), - GST_MAKE_FOURCC('D','V','S','D'), - GST_MAKE_FOURCC('W','M','V','1'), - GST_MAKE_FOURCC('W','M','V','2'), - GST_MAKE_FOURCC('M','P','G','4'), - GST_MAKE_FOURCC('M','P','4','2'), - GST_MAKE_FOURCC('M','P','4','3'), - GST_MAKE_FOURCC('D','I','V','3'), - GST_MAKE_FOURCC('D','X','5','0'), - 0 /* end */ + GST_MAKE_FOURCC ('I', '4', '2', '0'), + GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'), + GST_MAKE_FOURCC ('M', 'J', 'P', 'G'), + GST_MAKE_FOURCC ('D', 'V', 'S', 'D'), + GST_MAKE_FOURCC ('W', 'M', 'V', '1'), + GST_MAKE_FOURCC ('W', 'M', 'V', '2'), + GST_MAKE_FOURCC ('M', 'P', 'G', '4'), + GST_MAKE_FOURCC ('M', 'P', '4', '2'), + GST_MAKE_FOURCC ('M', 'P', '4', '3'), + GST_MAKE_FOURCC ('D', 'I', 'V', '3'), + GST_MAKE_FOURCC ('D', 'X', '5', '0'), + 0 /* end */ }; gint aud_list[] = { GST_RIFF_WAVE_FORMAT_MPEGL3, @@ -147,61 +134,58 @@ gst_asf_demux_base_init (gpointer g_class) GST_RIFF_WAVE_FORMAT_DIVX_WMAV1, GST_RIFF_WAVE_FORMAT_DIVX_WMAV2, GST_RIFF_WAVE_FORMAT_WMAV9, - -1 /* end */ + -1 /* end */ }; - audcaps = gst_caps_new_empty(); + audcaps = gst_caps_new_empty (); for (i = 0; aud_list[i] != -1; i++) { temp = gst_asf_demux_audio_caps (aud_list[i], NULL, NULL, NULL); gst_caps_append (audcaps, temp); } audiosrctempl = gst_pad_template_new ("audio_%02d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - audcaps); + GST_PAD_SRC, GST_PAD_SOMETIMES, audcaps); - vidcaps = gst_caps_new_empty(); + vidcaps = gst_caps_new_empty (); for (i = 0; vid_list[i] != 0; i++) { temp = gst_asf_demux_video_caps (vid_list[i], NULL, NULL); gst_caps_append (vidcaps, temp); } videosrctempl = gst_pad_template_new ("video_%02d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - vidcaps); + GST_PAD_SRC, GST_PAD_SOMETIMES, vidcaps); gst_element_class_add_pad_template (element_class, audiosrctempl); gst_element_class_add_pad_template (element_class, videosrctempl); - gst_element_class_add_pad_template (element_class, + gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_asf_demux_sink_template)); gst_element_class_set_details (element_class, &gst_asf_demux_details); } static void -gst_asf_demux_class_init (GstASFDemuxClass *klass) +gst_asf_demux_class_init (GstASFDemuxClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - + gobject_class->get_property = gst_asf_demux_get_property; - + gstelement_class->change_state = gst_asf_demux_change_state; gstelement_class->send_event = gst_asf_demux_send_event; } static void -gst_asf_demux_init (GstASFDemux *asf_demux) +gst_asf_demux_init (GstASFDemux * asf_demux) { guint i; - asf_demux->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&gst_asf_demux_sink_template), "sink"); + asf_demux->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_asf_demux_sink_template), "sink"); gst_element_add_pad (GST_ELEMENT (asf_demux), asf_demux->sinkpad); gst_element_set_loop_function (GST_ELEMENT (asf_demux), gst_asf_demux_loop); @@ -220,12 +204,12 @@ gst_asf_demux_init (GstASFDemux *asf_demux) asf_demux->num_audio_streams = 0; asf_demux->num_video_streams = 0; asf_demux->num_streams = 0; - + GST_FLAG_SET (asf_demux, GST_ELEMENT_EVENT_AWARE); } static gboolean -gst_asf_demux_send_event (GstElement *element, GstEvent *event) +gst_asf_demux_send_event (GstElement * element, GstEvent * event) { const GList *pads; @@ -243,16 +227,16 @@ gst_asf_demux_send_event (GstElement *element, GstEvent *event) return TRUE; } } - + pads = g_list_next (pads); } - + gst_event_unref (event); return FALSE; } static void -gst_asf_demux_loop (GstElement *element) +gst_asf_demux_loop (GstElement * element) { GstASFDemux *asf_demux; @@ -265,7 +249,8 @@ gst_asf_demux_loop (GstElement *element) gst_asf_demux_process_object (asf_demux); } -static guint32 _read_var_length (GstASFDemux *asf_demux, guint8 type, guint32 *rsize) +static guint32 +_read_var_length (GstASFDemux * asf_demux, guint8 type, guint32 * rsize) { guint32 got_bytes; guint8 *var; @@ -275,35 +260,35 @@ static guint32 _read_var_length (GstASFDemux *asf_demux, guint8 type, guint32 *r if (type == 0) { return 0; } - + got_bytes = gst_bytestream_peek_bytes (bs, &var, 4); while (got_bytes < 4) { guint32 remaining; GstEvent *event; - + gst_bytestream_get_status (bs, &remaining, &event); gst_event_unref (event); got_bytes = gst_bytestream_peek_bytes (bs, &var, 4); } - + switch (type) { - case 1: - ret = GUINT32_FROM_LE(*(guint32 *)var) & 0xff; - gst_bytestream_flush (bs, 1); - *rsize += 1; - break; - case 2: - ret = GUINT32_FROM_LE(*(guint32 *)var) & 0xffff; - gst_bytestream_flush (bs, 2); - *rsize += 2; - break; - case 3: - ret = GUINT32_FROM_LE(*(guint32 *)var); - gst_bytestream_flush (bs, 4); - *rsize += 4; - break; + case 1: + ret = GUINT32_FROM_LE (*(guint32 *) var) & 0xff; + gst_bytestream_flush (bs, 1); + *rsize += 1; + break; + case 2: + ret = GUINT32_FROM_LE (*(guint32 *) var) & 0xffff; + gst_bytestream_flush (bs, 2); + *rsize += 2; + break; + case 3: + ret = GUINT32_FROM_LE (*(guint32 *) var); + gst_bytestream_flush (bs, 4); + *rsize += 4; + break; } return ret; @@ -335,150 +320,150 @@ _read_uint ## bits (GstASFDemux *asf_demux, guint ## bits *ret) \ # define GUINT8_FROM_LE(x) (x) #endif READ_UINT_BITS_FUNCTION (8) -READ_UINT_BITS_FUNCTION (16) -READ_UINT_BITS_FUNCTION (32) -READ_UINT_BITS_FUNCTION (64) - + READ_UINT_BITS_FUNCTION (16) + READ_UINT_BITS_FUNCTION (32) + READ_UINT_BITS_FUNCTION (64) #define GET_UINT(a,b) - -static gboolean -_read_guid (GstASFDemux *asf_demux, ASFGuid *guid) + static gboolean _read_guid (GstASFDemux * asf_demux, ASFGuid * guid) { return (_read_uint32 (asf_demux, &guid->v1) && - _read_uint32 (asf_demux, &guid->v2) && - _read_uint32 (asf_demux, &guid->v3) && - _read_uint32 (asf_demux, &guid->v4)); + _read_uint32 (asf_demux, &guid->v2) && + _read_uint32 (asf_demux, &guid->v3) && + _read_uint32 (asf_demux, &guid->v4)); } static gboolean -_read_obj_file (GstASFDemux *asf_demux, asf_obj_file *object) +_read_obj_file (GstASFDemux * asf_demux, asf_obj_file * object) { return (_read_guid (asf_demux, &object->file_id) && - _read_uint64 (asf_demux, &object->file_size) && - _read_uint64 (asf_demux, &object->creation_time) && - _read_uint64 (asf_demux, &object->packets_count) && - _read_uint64 (asf_demux, &object->play_time) && - _read_uint64 (asf_demux, &object->send_time) && - _read_uint64 (asf_demux, &object->preroll) && - _read_uint32 (asf_demux, &object->flags) && - _read_uint32 (asf_demux, &object->min_pktsize) && - _read_uint32 (asf_demux, &object->max_pktsize) && - _read_uint32 (asf_demux, &object->min_bitrate)); + _read_uint64 (asf_demux, &object->file_size) && + _read_uint64 (asf_demux, &object->creation_time) && + _read_uint64 (asf_demux, &object->packets_count) && + _read_uint64 (asf_demux, &object->play_time) && + _read_uint64 (asf_demux, &object->send_time) && + _read_uint64 (asf_demux, &object->preroll) && + _read_uint32 (asf_demux, &object->flags) && + _read_uint32 (asf_demux, &object->min_pktsize) && + _read_uint32 (asf_demux, &object->max_pktsize) && + _read_uint32 (asf_demux, &object->min_bitrate)); } static gboolean -_read_bitrate_record (GstASFDemux *asf_demux, asf_bitrate_record *record) +_read_bitrate_record (GstASFDemux * asf_demux, asf_bitrate_record * record) { return (_read_uint16 (asf_demux, &record->stream_id) && - _read_uint32 (asf_demux, &record->bitrate)); + _read_uint32 (asf_demux, &record->bitrate)); } static gboolean -_read_obj_comment (GstASFDemux *asf_demux, asf_obj_comment *comment) +_read_obj_comment (GstASFDemux * asf_demux, asf_obj_comment * comment) { return (_read_uint16 (asf_demux, &comment->title_length) && - _read_uint16 (asf_demux, &comment->author_length) && - _read_uint16 (asf_demux, &comment->copyright_length) && - _read_uint16 (asf_demux, &comment->description_length) && - _read_uint16 (asf_demux, &comment->rating_length)); + _read_uint16 (asf_demux, &comment->author_length) && + _read_uint16 (asf_demux, &comment->copyright_length) && + _read_uint16 (asf_demux, &comment->description_length) && + _read_uint16 (asf_demux, &comment->rating_length)); } static gboolean -_read_obj_header (GstASFDemux *asf_demux, asf_obj_header *header) +_read_obj_header (GstASFDemux * asf_demux, asf_obj_header * header) { return (_read_uint32 (asf_demux, &header->num_objects) && - _read_uint8 (asf_demux, &header->unknown1) && - _read_uint8 (asf_demux, &header->unknown2)); + _read_uint8 (asf_demux, &header->unknown1) && + _read_uint8 (asf_demux, &header->unknown2)); } static gboolean -_read_obj_stream (GstASFDemux *asf_demux, asf_obj_stream *stream) +_read_obj_stream (GstASFDemux * asf_demux, asf_obj_stream * stream) { return (_read_guid (asf_demux, &stream->type) && - _read_guid (asf_demux, &stream->correction) && - _read_uint64 (asf_demux, &stream->unknown1) && - _read_uint32 (asf_demux, &stream->type_specific_size) && - _read_uint32 (asf_demux, &stream->stream_specific_size) && - _read_uint16 (asf_demux, &stream->id) && - _read_uint32 (asf_demux, &stream->unknown2)); + _read_guid (asf_demux, &stream->correction) && + _read_uint64 (asf_demux, &stream->unknown1) && + _read_uint32 (asf_demux, &stream->type_specific_size) && + _read_uint32 (asf_demux, &stream->stream_specific_size) && + _read_uint16 (asf_demux, &stream->id) && + _read_uint32 (asf_demux, &stream->unknown2)); } static gboolean -_read_replicated_data (GstASFDemux *asf_demux, asf_replicated_data *rep) +_read_replicated_data (GstASFDemux * asf_demux, asf_replicated_data * rep) { return (_read_uint32 (asf_demux, &rep->object_size) && - _read_uint32 (asf_demux, &rep->frag_timestamp)); + _read_uint32 (asf_demux, &rep->frag_timestamp)); } static gboolean -_read_obj_data (GstASFDemux *asf_demux, asf_obj_data *object) +_read_obj_data (GstASFDemux * asf_demux, asf_obj_data * object) { return (_read_guid (asf_demux, &object->file_id) && - _read_uint64 (asf_demux, &object->packets) && - _read_uint8 (asf_demux, &object->unknown1) && + _read_uint64 (asf_demux, &object->packets) && + _read_uint8 (asf_demux, &object->unknown1) && /*_read_uint8 (asf_demux, &object->unknown2) && */ - _read_uint8 (asf_demux, &object->correction)); + _read_uint8 (asf_demux, &object->correction)); } static gboolean -_read_obj_data_correction (GstASFDemux *asf_demux, asf_obj_data_correction *object) +_read_obj_data_correction (GstASFDemux * asf_demux, + asf_obj_data_correction * object) { return (_read_uint8 (asf_demux, &object->type) && - _read_uint8 (asf_demux, &object->cycle)); + _read_uint8 (asf_demux, &object->cycle)); } static gboolean -_read_obj_data_packet (GstASFDemux *asf_demux, asf_obj_data_packet *object) +_read_obj_data_packet (GstASFDemux * asf_demux, asf_obj_data_packet * object) { return (_read_uint8 (asf_demux, &object->flags) && - _read_uint8 (asf_demux, &object->property)); + _read_uint8 (asf_demux, &object->property)); } static gboolean -_read_stream_audio (GstASFDemux *asf_demux, asf_stream_audio *audio) +_read_stream_audio (GstASFDemux * asf_demux, asf_stream_audio * audio) { return (_read_uint16 (asf_demux, &audio->codec_tag) && - _read_uint16 (asf_demux, &audio->channels) && - _read_uint32 (asf_demux, &audio->sample_rate) && - _read_uint32 (asf_demux, &audio->byte_rate) && - _read_uint16 (asf_demux, &audio->block_align) && - _read_uint16 (asf_demux, &audio->word_size) && - _read_uint16 (asf_demux, &audio->size)); + _read_uint16 (asf_demux, &audio->channels) && + _read_uint32 (asf_demux, &audio->sample_rate) && + _read_uint32 (asf_demux, &audio->byte_rate) && + _read_uint16 (asf_demux, &audio->block_align) && + _read_uint16 (asf_demux, &audio->word_size) && + _read_uint16 (asf_demux, &audio->size)); } static gboolean -_read_stream_correction (GstASFDemux *asf_demux, asf_stream_correction *object) +_read_stream_correction (GstASFDemux * asf_demux, + asf_stream_correction * object) { return (_read_uint8 (asf_demux, &object->span) && - _read_uint16 (asf_demux, &object->packet_size) && - _read_uint16 (asf_demux, &object->chunk_size) && - _read_uint16 (asf_demux, &object->data_size) && - _read_uint8 (asf_demux, &object->silence_data)); + _read_uint16 (asf_demux, &object->packet_size) && + _read_uint16 (asf_demux, &object->chunk_size) && + _read_uint16 (asf_demux, &object->data_size) && + _read_uint8 (asf_demux, &object->silence_data)); } static gboolean -_read_stream_video (GstASFDemux *asf_demux, asf_stream_video *video) +_read_stream_video (GstASFDemux * asf_demux, asf_stream_video * video) { return (_read_uint32 (asf_demux, &video->width) && - _read_uint32 (asf_demux, &video->height) && - _read_uint8 (asf_demux, &video->unknown) && - _read_uint16 (asf_demux, &video->size)); + _read_uint32 (asf_demux, &video->height) && + _read_uint8 (asf_demux, &video->unknown) && + _read_uint16 (asf_demux, &video->size)); } static gboolean -_read_stream_video_format (GstASFDemux *asf_demux, asf_stream_video_format *fmt) +_read_stream_video_format (GstASFDemux * asf_demux, + asf_stream_video_format * fmt) { return (_read_uint32 (asf_demux, &fmt->size) && - _read_uint32 (asf_demux, &fmt->width) && - _read_uint32 (asf_demux, &fmt->height) && - _read_uint16 (asf_demux, &fmt->planes) && - _read_uint16 (asf_demux, &fmt->depth) && - _read_uint32 (asf_demux, &fmt->tag) && - _read_uint32 (asf_demux, &fmt->image_size) && - _read_uint32 (asf_demux, &fmt->xpels_meter) && - _read_uint32 (asf_demux, &fmt->ypels_meter) && - _read_uint32 (asf_demux, &fmt->num_colors) && - _read_uint32 (asf_demux, &fmt->imp_colors)); + _read_uint32 (asf_demux, &fmt->width) && + _read_uint32 (asf_demux, &fmt->height) && + _read_uint16 (asf_demux, &fmt->planes) && + _read_uint16 (asf_demux, &fmt->depth) && + _read_uint32 (asf_demux, &fmt->tag) && + _read_uint32 (asf_demux, &fmt->image_size) && + _read_uint32 (asf_demux, &fmt->xpels_meter) && + _read_uint32 (asf_demux, &fmt->ypels_meter) && + _read_uint32 (asf_demux, &fmt->num_colors) && + _read_uint32 (asf_demux, &fmt->imp_colors)); } @@ -488,33 +473,36 @@ _read_stream_video_format (GstASFDemux *asf_demux, asf_stream_video_format *fmt) static gboolean -gst_asf_demux_process_file (GstASFDemux *asf_demux, guint64 *obj_size) +gst_asf_demux_process_file (GstASFDemux * asf_demux, guint64 * obj_size) { asf_obj_file object; - + /* Get the rest of the header's header */ _read_obj_file (asf_demux, &object); asf_demux->packet_size = object.max_pktsize; asf_demux->play_time = (guint32) object.play_time / 10; asf_demux->preroll = object.preroll; - - GST_INFO ( "Object is a file with %" G_GUINT64_FORMAT " data packets", object.packets_count); + + GST_INFO ("Object is a file with %" G_GUINT64_FORMAT " data packets", + object.packets_count); return TRUE; } static gboolean -gst_asf_demux_process_bitrate_props_object (GstASFDemux *asf_demux, guint64 *obj_size) +gst_asf_demux_process_bitrate_props_object (GstASFDemux * asf_demux, + guint64 * obj_size) { - guint16 num_streams; - guint8 stream_id; - guint16 i; + guint16 num_streams; + guint8 stream_id; + guint16 i; asf_bitrate_record bitrate_record; if (!_read_uint16 (asf_demux, &num_streams)) return FALSE; - GST_INFO ( "Object is a bitrate properties object with %u streams.", num_streams); + GST_INFO ("Object is a bitrate properties object with %u streams.", + num_streams); for (i = 0; i < num_streams; i++) { _read_bitrate_record (asf_demux, &bitrate_record); @@ -526,17 +514,19 @@ gst_asf_demux_process_bitrate_props_object (GstASFDemux *asf_demux, guint64 *obj } static gboolean -gst_asf_demux_process_comment (GstASFDemux *asf_demux, guint64 *obj_size) +gst_asf_demux_process_comment (GstASFDemux * asf_demux, guint64 * obj_size) { asf_obj_comment object; GstByteStream *bs = asf_demux->bs; - GST_INFO ( "Object is a comment."); + GST_INFO ("Object is a comment."); /* Get the rest of the comment's header */ _read_obj_comment (asf_demux, &object); - GST_DEBUG ("Comment lengths: title=%d author=%d copyright=%d description=%d rating=%d", - object.title_length, object.author_length, object.copyright_length, object.description_length, object.rating_length); + GST_DEBUG + ("Comment lengths: title=%d author=%d copyright=%d description=%d rating=%d", + object.title_length, object.author_length, object.copyright_length, + object.description_length, object.rating_length); /* We don't do anything with them at the moment so just skip them */ gst_bytestream_flush (bs, object.title_length); @@ -550,7 +540,7 @@ gst_asf_demux_process_comment (GstASFDemux *asf_demux, guint64 *obj_size) static gboolean -gst_asf_demux_process_header (GstASFDemux *asf_demux, guint64 *obj_size) +gst_asf_demux_process_header (GstASFDemux * asf_demux, guint64 * obj_size) { asf_obj_header object; guint32 i; @@ -558,9 +548,9 @@ gst_asf_demux_process_header (GstASFDemux *asf_demux, guint64 *obj_size) /* Get the rest of the header's header */ _read_obj_header (asf_demux, &object); - GST_INFO ( "Object is a header with %u parts", object.num_objects); + GST_INFO ("Object is a header with %u parts", object.num_objects); - /* Loop through the header's objects, processing those */ + /* Loop through the header's objects, processing those */ for (i = 0; i < object.num_objects; i++) { if (!gst_asf_demux_process_object (asf_demux)) { return FALSE; @@ -571,36 +561,42 @@ gst_asf_demux_process_header (GstASFDemux *asf_demux, guint64 *obj_size) } static gboolean -gst_asf_demux_process_segment (GstASFDemux *asf_demux, - asf_packet_info *packet_info) +gst_asf_demux_process_segment (GstASFDemux * asf_demux, + asf_packet_info * packet_info) { - guint8 byte; + guint8 byte; gboolean key_frame; - guint32 replic_size; - guint8 time_delta; - guint32 time_start; - guint32 frag_size; - guint32 rsize; + guint32 replic_size; + guint8 time_delta; + guint32 time_start; + guint32 frag_size; + guint32 rsize; asf_segment_info segment_info; - _read_uint8 (asf_demux, &byte); rsize = 1; + _read_uint8 (asf_demux, &byte); + rsize = 1; segment_info.stream_number = byte & 0x7f; key_frame = (byte & 0x80) >> 7; - - GST_INFO ( "Processing segment for stream %u", segment_info.stream_number); - segment_info.sequence = _read_var_length (asf_demux, packet_info->seqtype, &rsize); - segment_info.frag_offset = _read_var_length (asf_demux, packet_info->fragoffsettype, &rsize); - replic_size = _read_var_length (asf_demux, packet_info->replicsizetype, &rsize); - GST_DEBUG ("sequence = %x, frag_offset = %x, replic_size = %x", segment_info.sequence, segment_info.frag_offset, replic_size); - + + GST_INFO ("Processing segment for stream %u", segment_info.stream_number); + segment_info.sequence = + _read_var_length (asf_demux, packet_info->seqtype, &rsize); + segment_info.frag_offset = + _read_var_length (asf_demux, packet_info->fragoffsettype, &rsize); + replic_size = + _read_var_length (asf_demux, packet_info->replicsizetype, &rsize); + GST_DEBUG ("sequence = %x, frag_offset = %x, replic_size = %x", + segment_info.sequence, segment_info.frag_offset, replic_size); + if (replic_size > 1) { asf_replicated_data replicated_data_header; segment_info.compressed = FALSE; - - /* It's uncompressed with replic data*/ + + /* It's uncompressed with replic data */ if (replic_size < 8) { - GST_ELEMENT_ERROR (asf_demux, STREAM, DEMUX, (NULL), ("The payload has replicated data but the size is less than 8")); + GST_ELEMENT_ERROR (asf_demux, STREAM, DEMUX, (NULL), + ("The payload has replicated data but the size is less than 8")); return FALSE; } _read_replicated_data (asf_demux, &replicated_data_header); @@ -616,18 +612,20 @@ gst_asf_demux_process_segment (GstASFDemux *asf_demux, if (replic_size == 1) { /* It's compressed */ segment_info.compressed = TRUE; - _read_uint8 (asf_demux, &time_delta); rsize++; + _read_uint8 (asf_demux, &time_delta); + rsize++; GST_DEBUG ("time_delta %u", time_delta); } else { segment_info.compressed = FALSE; } - + time_start = segment_info.frag_offset; segment_info.frag_offset = 0; segment_info.frag_timestamp = asf_demux->timestamp; } - GST_DEBUG ("multiple = %u compressed = %u", packet_info->multiple, segment_info.compressed); + GST_DEBUG ("multiple = %u compressed = %u", packet_info->multiple, + segment_info.compressed); if (packet_info->multiple) { frag_size = _read_var_length (asf_demux, packet_info->segsizetype, &rsize); @@ -636,18 +634,20 @@ gst_asf_demux_process_segment (GstASFDemux *asf_demux, } packet_info->size_left -= rsize; - - GST_DEBUG ("size left = %u frag size = %u rsize = %u", packet_info->size_left, frag_size, rsize); + + GST_DEBUG ("size left = %u frag size = %u rsize = %u", packet_info->size_left, + frag_size, rsize); if (segment_info.compressed) { while (frag_size > 0) { - _read_uint8 (asf_demux, &byte); + _read_uint8 (asf_demux, &byte); packet_info->size_left--; segment_info.chunk_size = byte; segment_info.segment_size = segment_info.chunk_size; if (segment_info.chunk_size > packet_info->size_left) { - GST_ELEMENT_ERROR (asf_demux, STREAM, DEMUX, (NULL), ("Payload chunk overruns packet size.")); + GST_ELEMENT_ERROR (asf_demux, STREAM, DEMUX, (NULL), + ("Payload chunk overruns packet size.")); return FALSE; } @@ -664,71 +664,74 @@ gst_asf_demux_process_segment (GstASFDemux *asf_demux, } static gboolean -gst_asf_demux_process_data (GstASFDemux *asf_demux, guint64 *obj_size) +gst_asf_demux_process_data (GstASFDemux * asf_demux, guint64 * obj_size) { - asf_obj_data object; + asf_obj_data object; asf_obj_data_packet packet_properties_object; - gboolean correction; - guint64 packets; - guint64 packet; - guint8 buf; - guint32 sequence; - guint32 packet_length; - guint16 duration; - guint8 segment; - guint8 segments; - guint8 flags; - guint8 property; - asf_packet_info packet_info; - guint32 rsize; - + gboolean correction; + guint64 packets; + guint64 packet; + guint8 buf; + guint32 sequence; + guint32 packet_length; + guint16 duration; + guint8 segment; + guint8 segments; + guint8 flags; + guint8 property; + asf_packet_info packet_info; + guint32 rsize; + /* Get the rest of the header */ _read_obj_data (asf_demux, &object); packets = object.packets; - GST_INFO ( "Object is data with %" G_GUINT64_FORMAT " packets", packets); + GST_INFO ("Object is data with %" G_GUINT64_FORMAT " packets", packets); for (packet = 0; packet < packets; packet++) { - GST_INFO ( "\n\nProcess packet %" G_GUINT64_FORMAT, packet); - - _read_uint8 (asf_demux, &buf); rsize=1; + GST_INFO ("\n\nProcess packet %" G_GUINT64_FORMAT, packet); + + _read_uint8 (asf_demux, &buf); + rsize = 1; if (buf & 0x80) { asf_obj_data_correction correction_object; - + /* Uses error correction */ correction = TRUE; GST_DEBUG ("Data has error correction (%x)", buf); - _read_obj_data_correction (asf_demux, &correction_object); rsize += 2; + _read_obj_data_correction (asf_demux, &correction_object); + rsize += 2; } - + /* Read the packet flags */ - _read_obj_data_packet (asf_demux, &packet_properties_object); rsize += 2; + _read_obj_data_packet (asf_demux, &packet_properties_object); + rsize += 2; flags = packet_properties_object.flags; property = packet_properties_object.property; - + packet_info.multiple = flags & 0x01; sequence = _read_var_length (asf_demux, (flags >> 1) & 0x03, &rsize); - packet_info.padsize = - _read_var_length (asf_demux, (flags >> 3) & 0x03, &rsize); - packet_length = - _read_var_length (asf_demux, (flags >> 5) & 0x03, &rsize); + packet_info.padsize = + _read_var_length (asf_demux, (flags >> 3) & 0x03, &rsize); + packet_length = _read_var_length (asf_demux, (flags >> 5) & 0x03, &rsize); if (packet_length == 0) packet_length = asf_demux->packet_size; - - GST_DEBUG ("Multiple = %u, Sequence = %u, Padsize = %u, Packet length = %u", packet_info.multiple, sequence, packet_info.padsize, packet_length); - + + GST_DEBUG ("Multiple = %u, Sequence = %u, Padsize = %u, Packet length = %u", + packet_info.multiple, sequence, packet_info.padsize, packet_length); + /* Read the property flags */ packet_info.replicsizetype = property & 0x03; packet_info.fragoffsettype = (property >> 2) & 0x03; packet_info.seqtype = (property >> 4) & 0x03; - + _read_uint32 (asf_demux, &asf_demux->timestamp); _read_uint16 (asf_demux, &duration); - + rsize += 6; - + GST_DEBUG ("Timestamp = %x, Duration = %x", asf_demux->timestamp, duration); - + if (packet_info.multiple) { /* There are multiple payloads */ _read_uint8 (asf_demux, &buf); @@ -739,11 +742,11 @@ gst_asf_demux_process_data (GstASFDemux *asf_demux, guint64 *obj_size) packet_info.segsizetype = 2; segments = 1; } - + packet_info.size_left = packet_length - packet_info.padsize - rsize; GST_DEBUG ("rsize: %u size left: %u", rsize, packet_info.size_left); - + for (segment = 0; segment < segments; segment++) { if (!gst_asf_demux_process_segment (asf_demux, &packet_info)) return FALSE; @@ -752,123 +755,135 @@ gst_asf_demux_process_data (GstASFDemux *asf_demux, guint64 *obj_size) /* Skip the padding */ if (packet_info.padsize > 0) gst_bytestream_flush (asf_demux->bs, packet_info.padsize); - + GST_DEBUG ("Remaining size left: %u", packet_info.size_left); - + if (packet_info.size_left > 0) gst_bytestream_flush (asf_demux->bs, packet_info.size_left); } - + return TRUE; } static gboolean -gst_asf_demux_process_stream (GstASFDemux *asf_demux, guint64 *obj_size) +gst_asf_demux_process_stream (GstASFDemux * asf_demux, guint64 * obj_size) { - asf_obj_stream object; - guint32 stream_id; - guint32 correction; - asf_stream_audio audio_object; - asf_stream_correction correction_object; - asf_stream_video video_object; + asf_obj_stream object; + guint32 stream_id; + guint32 correction; + asf_stream_audio audio_object; + asf_stream_correction correction_object; + asf_stream_video video_object; asf_stream_video_format video_format_object; - guint16 size; - GstBuffer *buf; - guint32 got_bytes; - guint16 id; + guint16 size; + GstBuffer *buf; + guint32 got_bytes; + guint16 id; /* Get the rest of the header's header */ _read_obj_stream (asf_demux, &object); /* Identify the stream type */ - stream_id = gst_asf_demux_identify_guid (asf_demux, asf_stream_guids, &(object.type)); - correction = gst_asf_demux_identify_guid (asf_demux, asf_correction_guids, &(object.correction)); + stream_id = + gst_asf_demux_identify_guid (asf_demux, asf_stream_guids, &(object.type)); + correction = + gst_asf_demux_identify_guid (asf_demux, asf_correction_guids, + &(object.correction)); id = object.id; switch (stream_id) { - case ASF_STREAM_AUDIO: - _read_stream_audio (asf_demux, &audio_object); - size = audio_object.size; + case ASF_STREAM_AUDIO: + _read_stream_audio (asf_demux, &audio_object); + size = audio_object.size; - GST_INFO ("Object is an audio stream with %u bytes of additional data.", size); + GST_INFO ("Object is an audio stream with %u bytes of additional data.", + size); - if (!gst_asf_demux_add_audio_stream (asf_demux, &audio_object, id)) - return FALSE; + if (!gst_asf_demux_add_audio_stream (asf_demux, &audio_object, id)) + return FALSE; - switch (correction) { - case ASF_CORRECTION_ON: - GST_INFO ( "Using error correction"); + switch (correction) { + case ASF_CORRECTION_ON: + GST_INFO ("Using error correction"); - _read_stream_correction (asf_demux, &correction_object); - asf_demux->span = correction_object.span; + _read_stream_correction (asf_demux, &correction_object); + asf_demux->span = correction_object.span; - GST_DEBUG ("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d", correction_object.packet_size, correction_object.chunk_size, - correction_object.data_size, (guint) correction_object.span, (guint) correction_object.silence_data); + GST_DEBUG ("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d", + correction_object.packet_size, correction_object.chunk_size, + correction_object.data_size, (guint) correction_object.span, + (guint) correction_object.silence_data); - if (asf_demux->span > 1) { - if (!correction_object.chunk_size || ((correction_object.packet_size / correction_object.chunk_size) <= 1)) - /* Disable descrambling */ - asf_demux->span = 0; - } else { - /* Descambling is enabled */ - asf_demux->ds_packet_size = correction_object.packet_size; - asf_demux->ds_chunk_size = correction_object.chunk_size; + if (asf_demux->span > 1) { + if (!correction_object.chunk_size + || ((correction_object.packet_size / + correction_object.chunk_size) <= 1)) + /* Disable descrambling */ + asf_demux->span = 0; + } else { + /* Descambling is enabled */ + asf_demux->ds_packet_size = correction_object.packet_size; + asf_demux->ds_chunk_size = correction_object.chunk_size; + } + + /* Now skip the rest of the silence data */ + if (correction_object.data_size > 1) + gst_bytestream_flush (asf_demux->bs, + correction_object.data_size - 1); + + break; + case ASF_CORRECTION_OFF: + GST_INFO ("Error correction off"); + gst_bytestream_flush (asf_demux->bs, object.stream_specific_size); + break; + default: + GST_ELEMENT_ERROR (asf_demux, STREAM, DEMUX, (NULL), + ("Audio stream using unknown error correction")); + return FALSE; } - /* Now skip the rest of the silence data */ - if (correction_object.data_size > 1) - gst_bytestream_flush (asf_demux->bs, correction_object.data_size - 1); - break; - case ASF_CORRECTION_OFF: - GST_INFO ( "Error correction off"); - gst_bytestream_flush (asf_demux->bs, object.stream_specific_size); + case ASF_STREAM_VIDEO: + _read_stream_video (asf_demux, &video_object); + size = video_object.size - 40; /* Byte order gets offset by single byte */ + GST_INFO ("Object is a video stream with %u bytes of additional data.", + size); + _read_stream_video_format (asf_demux, &video_format_object); + + if (!gst_asf_demux_add_video_stream (asf_demux, &video_format_object, id)) + return FALSE; + + /* Read any additional information */ + if (size) { + got_bytes = gst_bytestream_read (asf_demux->bs, &buf, size); + /* There is additional data */ + while (got_bytes < size) { + guint32 remaining; + GstEvent *event; + + gst_bytestream_get_status (asf_demux->bs, &remaining, &event); + gst_event_unref (event); + + got_bytes = gst_bytestream_read (asf_demux->bs, &buf, size); + } + } break; default: - GST_ELEMENT_ERROR (asf_demux, STREAM, DEMUX, (NULL), ("Audio stream using unknown error correction")); + GST_ELEMENT_ERROR (asf_demux, STREAM, WRONG_TYPE, (NULL), + ("unknown asf stream (id %08x)", (guint) stream_id)); return FALSE; - } - - break; - case ASF_STREAM_VIDEO: - _read_stream_video (asf_demux, &video_object); - size = video_object.size - 40; /* Byte order gets offset by single byte */ - GST_INFO ( "Object is a video stream with %u bytes of additional data.", size); - _read_stream_video_format (asf_demux, &video_format_object); - - if (!gst_asf_demux_add_video_stream (asf_demux, &video_format_object, id)) - return FALSE; - - /* Read any additional information */ - if (size) { - got_bytes = gst_bytestream_read (asf_demux->bs, &buf, size); - /* There is additional data */ - while (got_bytes < size) { - guint32 remaining; - GstEvent *event; - - gst_bytestream_get_status (asf_demux->bs, &remaining, &event); - gst_event_unref (event); - - got_bytes = gst_bytestream_read (asf_demux->bs, &buf, size); - } - } - break; - default: - GST_ELEMENT_ERROR (asf_demux, STREAM, WRONG_TYPE, (NULL), ("unknown asf stream (id %08x)", (guint) stream_id)); - return FALSE; } return TRUE; } static gboolean -gst_asf_demux_skip_object (GstASFDemux *asf_demux, guint64 *obj_size) +gst_asf_demux_skip_object (GstASFDemux * asf_demux, guint64 * obj_size) { GstByteStream *bs = asf_demux->bs; - GST_INFO ( "Skipping object..."); + GST_INFO ("Skipping object..."); gst_bytestream_flush (bs, *obj_size - 24); @@ -876,10 +891,11 @@ gst_asf_demux_skip_object (GstASFDemux *asf_demux, guint64 *obj_size) } static inline gboolean -_read_object_header (GstASFDemux *asf_demux, guint32 *obj_id, guint64 *obj_size) +_read_object_header (GstASFDemux * asf_demux, guint32 * obj_id, + guint64 * obj_size) { - ASFGuid guid; - + ASFGuid guid; + /* First get the GUID */ if (!_read_guid (asf_demux, &guid)) return FALSE; @@ -889,63 +905,67 @@ _read_object_header (GstASFDemux *asf_demux, guint32 *obj_id, guint64 *obj_size) return FALSE; if (*obj_id == ASF_OBJ_UNDEFINED) { - GST_WARNING_OBJECT (asf_demux, "Could not identify object (0x%08x/0x%08x/0x%08x/0x%08x) with size=%llu", + GST_WARNING_OBJECT (asf_demux, + "Could not identify object (0x%08x/0x%08x/0x%08x/0x%08x) with size=%llu", guid.v1, guid.v2, guid.v3, guid.v4, *obj_size); return TRUE; } - + return TRUE; } static gboolean -gst_asf_demux_process_object (GstASFDemux *asf_demux) { +gst_asf_demux_process_object (GstASFDemux * asf_demux) +{ guint32 obj_id; guint64 obj_size; if (!_read_object_header (asf_demux, &obj_id, &obj_size)) { - GST_DEBUG (" ***** Error reading object at filepos %" G_GUINT64_FORMAT " (EOS?)\n", /**filepos*/ gst_bytestream_tell (asf_demux->bs)); - gst_asf_demux_handle_sink_event (asf_demux, gst_event_new (GST_EVENT_EOS), 0); + GST_DEBUG (" ***** Error reading object at filepos %" G_GUINT64_FORMAT + " (EOS?)\n", /**filepos*/ gst_bytestream_tell (asf_demux->bs)); + gst_asf_demux_handle_sink_event (asf_demux, gst_event_new (GST_EVENT_EOS), + 0); return FALSE; } - GST_INFO ( "Found object %u with size %" G_GUINT64_FORMAT, obj_id, obj_size); + GST_INFO ("Found object %u with size %" G_GUINT64_FORMAT, obj_id, obj_size); switch (obj_id) { - case ASF_OBJ_STREAM: - return gst_asf_demux_process_stream (asf_demux, &obj_size); - case ASF_OBJ_DATA: - gst_asf_demux_process_data (asf_demux, &obj_size); - /* This is the last object */ - return FALSE; - case ASF_OBJ_FILE: - return gst_asf_demux_process_file (asf_demux, &obj_size); - case ASF_OBJ_HEADER: - return gst_asf_demux_process_header (asf_demux, &obj_size); - case ASF_OBJ_CONCEAL_NONE: - break; - case ASF_OBJ_COMMENT: - return gst_asf_demux_process_comment (asf_demux, &obj_size); - case ASF_OBJ_CODEC_COMMENT: - return gst_asf_demux_skip_object (asf_demux, &obj_size); - case ASF_OBJ_INDEX: - return gst_asf_demux_skip_object (asf_demux, &obj_size); - case ASF_OBJ_HEAD1: - return gst_asf_demux_skip_object (asf_demux, &obj_size); - case ASF_OBJ_HEAD2: - break; - case ASF_OBJ_PADDING: - return gst_asf_demux_skip_object (asf_demux, &obj_size); - case ASF_OBJ_EXT_CONTENT_DESC: - return gst_asf_demux_skip_object (asf_demux, &obj_size); - case ASF_OBJ_BITRATE_PROPS: - return gst_asf_demux_process_bitrate_props_object (asf_demux, &obj_size); - case ASF_OBJ_BITRATE_MUTEX: - return gst_asf_demux_skip_object (asf_demux, &obj_size); - case ASF_OBJ_UNDEFINED: - default: - /* unknown object read, just ignore it, we hate fatal errors */ - return gst_asf_demux_skip_object (asf_demux, &obj_size); + case ASF_OBJ_STREAM: + return gst_asf_demux_process_stream (asf_demux, &obj_size); + case ASF_OBJ_DATA: + gst_asf_demux_process_data (asf_demux, &obj_size); + /* This is the last object */ + return FALSE; + case ASF_OBJ_FILE: + return gst_asf_demux_process_file (asf_demux, &obj_size); + case ASF_OBJ_HEADER: + return gst_asf_demux_process_header (asf_demux, &obj_size); + case ASF_OBJ_CONCEAL_NONE: + break; + case ASF_OBJ_COMMENT: + return gst_asf_demux_process_comment (asf_demux, &obj_size); + case ASF_OBJ_CODEC_COMMENT: + return gst_asf_demux_skip_object (asf_demux, &obj_size); + case ASF_OBJ_INDEX: + return gst_asf_demux_skip_object (asf_demux, &obj_size); + case ASF_OBJ_HEAD1: + return gst_asf_demux_skip_object (asf_demux, &obj_size); + case ASF_OBJ_HEAD2: + break; + case ASF_OBJ_PADDING: + return gst_asf_demux_skip_object (asf_demux, &obj_size); + case ASF_OBJ_EXT_CONTENT_DESC: + return gst_asf_demux_skip_object (asf_demux, &obj_size); + case ASF_OBJ_BITRATE_PROPS: + return gst_asf_demux_process_bitrate_props_object (asf_demux, &obj_size); + case ASF_OBJ_BITRATE_MUTEX: + return gst_asf_demux_skip_object (asf_demux, &obj_size); + case ASF_OBJ_UNDEFINED: + default: + /* unknown object read, just ignore it, we hate fatal errors */ + return gst_asf_demux_skip_object (asf_demux, &obj_size); } return TRUE; @@ -953,8 +973,7 @@ gst_asf_demux_process_object (GstASFDemux *asf_demux) { static asf_stream_context * -gst_asf_demux_get_stream (GstASFDemux *asf_demux, - guint16 id) +gst_asf_demux_get_stream (GstASFDemux * asf_demux, guint16 id) { guint8 i; asf_stream_context *stream; @@ -968,36 +987,40 @@ gst_asf_demux_get_stream (GstASFDemux *asf_demux, } /* Base case if we haven't found one at all */ - GST_ELEMENT_ERROR (asf_demux, STREAM, DEMUX, (NULL), ("Segment found for undefined stream: (%d)", id)); + GST_ELEMENT_ERROR (asf_demux, STREAM, DEMUX, (NULL), + ("Segment found for undefined stream: (%d)", id)); return NULL; } static inline void -gst_asf_demux_descramble_segment (GstASFDemux *asf_demux, - asf_segment_info *segment_info, - asf_stream_context *stream) { +gst_asf_demux_descramble_segment (GstASFDemux * asf_demux, + asf_segment_info * segment_info, asf_stream_context * stream) +{ GstBuffer *scrambled_buffer; GstBuffer *descrambled_buffer; GstBuffer *sub_buffer; - guint offset; - guint off; - guint row; - guint col; - guint idx; - + guint offset; + guint off; + guint row; + guint col; + guint idx; + /* descrambled_buffer is initialised in the first iteration */ descrambled_buffer = NULL; scrambled_buffer = stream->payload; offset = 0; - for (offset = 0; offset < segment_info->segment_size; offset += asf_demux->ds_chunk_size) { + for (offset = 0; offset < segment_info->segment_size; + offset += asf_demux->ds_chunk_size) { off = offset / asf_demux->ds_chunk_size; row = off / asf_demux->span; col = off % asf_demux->span; idx = row + col * asf_demux->ds_packet_size / asf_demux->ds_chunk_size; - sub_buffer = gst_buffer_create_sub (scrambled_buffer, idx * asf_demux->ds_chunk_size, asf_demux->ds_chunk_size); + sub_buffer = + gst_buffer_create_sub (scrambled_buffer, idx * asf_demux->ds_chunk_size, + asf_demux->ds_chunk_size); if (!offset) { descrambled_buffer = sub_buffer; } else { @@ -1015,39 +1038,50 @@ gst_asf_demux_descramble_segment (GstASFDemux *asf_demux, gst_buffer_unref (scrambled_buffer); } -static gboolean -gst_asf_demux_process_chunk (GstASFDemux *asf_demux, - asf_packet_info *packet_info, - asf_segment_info *segment_info) +static gboolean +gst_asf_demux_process_chunk (GstASFDemux * asf_demux, + asf_packet_info * packet_info, asf_segment_info * segment_info) { asf_stream_context *stream; - guint32 got_bytes; - GstByteStream *bs = asf_demux->bs; - GstBuffer *buffer; + guint32 got_bytes; + GstByteStream *bs = asf_demux->bs; + GstBuffer *buffer; - if (!(stream = gst_asf_demux_get_stream (asf_demux, segment_info->stream_number))) + if (!(stream = + gst_asf_demux_get_stream (asf_demux, segment_info->stream_number))) return FALSE; - - GST_DEBUG ("Processing chunk of size %u (fo = %d)", segment_info->chunk_size, stream->frag_offset); - + + GST_DEBUG ("Processing chunk of size %u (fo = %d)", segment_info->chunk_size, + stream->frag_offset); + if (stream->frag_offset == 0) { /* new packet */ stream->sequence = segment_info->sequence; asf_demux->pts = segment_info->frag_timestamp - asf_demux->preroll; got_bytes = gst_bytestream_peek (bs, &buffer, segment_info->chunk_size); - GST_DEBUG ("BUFFER: Copied stream to buffer (%p - %d)", buffer, GST_BUFFER_REFCOUNT_VALUE(buffer)); + GST_DEBUG ("BUFFER: Copied stream to buffer (%p - %d)", buffer, + GST_BUFFER_REFCOUNT_VALUE (buffer)); stream->payload = buffer; } else { - GST_DEBUG ("segment_info->sequence = %d, stream->sequence = %d, segment_info->frag_offset = %d, stream->frag_offset = %d", segment_info->sequence, stream->sequence, segment_info->frag_offset, stream->frag_offset); - if (segment_info->sequence == stream->sequence && - segment_info->frag_offset == stream->frag_offset) { + GST_DEBUG + ("segment_info->sequence = %d, stream->sequence = %d, segment_info->frag_offset = %d, stream->frag_offset = %d", + segment_info->sequence, stream->sequence, segment_info->frag_offset, + stream->frag_offset); + if (segment_info->sequence == stream->sequence + && segment_info->frag_offset == stream->frag_offset) { GstBuffer *new_buffer; + /* continuing packet */ - GST_INFO ( "A continuation packet"); + GST_INFO ("A continuation packet"); got_bytes = gst_bytestream_peek (bs, &buffer, segment_info->chunk_size); - GST_DEBUG ("Copied stream to buffer (%p - %d)", buffer, GST_BUFFER_REFCOUNT_VALUE(buffer)); + GST_DEBUG ("Copied stream to buffer (%p - %d)", buffer, + GST_BUFFER_REFCOUNT_VALUE (buffer)); new_buffer = gst_buffer_merge (stream->payload, buffer); - GST_DEBUG ("BUFFER: Merged new_buffer (%p - %d) from stream->payload(%p - %d) and buffer (%p - %d)", new_buffer, GST_BUFFER_REFCOUNT_VALUE(new_buffer), stream->payload, GST_BUFFER_REFCOUNT_VALUE(stream->payload), buffer, GST_BUFFER_REFCOUNT_VALUE(buffer)); + GST_DEBUG + ("BUFFER: Merged new_buffer (%p - %d) from stream->payload(%p - %d) and buffer (%p - %d)", + new_buffer, GST_BUFFER_REFCOUNT_VALUE (new_buffer), stream->payload, + GST_BUFFER_REFCOUNT_VALUE (stream->payload), buffer, + GST_BUFFER_REFCOUNT_VALUE (buffer)); gst_buffer_unref (stream->payload); gst_buffer_unref (buffer); stream->payload = new_buffer; @@ -1068,9 +1102,10 @@ gst_asf_demux_process_chunk (GstASFDemux *asf_demux, } } - stream->frag_offset +=segment_info->chunk_size; + stream->frag_offset += segment_info->chunk_size; - GST_DEBUG ("frag_offset = %d segment_size = %d ", stream->frag_offset, segment_info->segment_size); + GST_DEBUG ("frag_offset = %d segment_size = %d ", stream->frag_offset, + segment_info->segment_size); if (stream->frag_offset < segment_info->segment_size) { /* We don't have the whole packet yet */ @@ -1083,21 +1118,24 @@ gst_asf_demux_process_chunk (GstASFDemux *asf_demux, } if (GST_PAD_IS_USABLE (stream->pad)) { - GST_DEBUG ("New buffer is at: %p size: %u", GST_BUFFER_DATA(stream->payload), GST_BUFFER_SIZE(stream->payload)); - - GST_BUFFER_TIMESTAMP (stream->payload) = (GST_SECOND / 1000) * asf_demux->pts; + GST_DEBUG ("New buffer is at: %p size: %u", + GST_BUFFER_DATA (stream->payload), GST_BUFFER_SIZE (stream->payload)); + + GST_BUFFER_TIMESTAMP (stream->payload) = + (GST_SECOND / 1000) * asf_demux->pts; /*!!! Should handle flush events here? */ - GST_DEBUG ("Sending strem %d of size %d", stream->id , segment_info->chunk_size); - - GST_INFO ( "Pushing pad"); + GST_DEBUG ("Sending strem %d of size %d", stream->id, + segment_info->chunk_size); + + GST_INFO ("Pushing pad"); gst_pad_push (stream->pad, GST_DATA (stream->payload)); } stream->frag_offset = 0; } - gst_bytestream_flush (bs, segment_info->chunk_size); + gst_bytestream_flush (bs, segment_info->chunk_size); packet_info->size_left -= segment_info->chunk_size; GST_DEBUG (" "); @@ -1110,9 +1148,8 @@ gst_asf_demux_process_chunk (GstASFDemux *asf_demux, */ static gboolean -gst_asf_demux_handle_sink_event (GstASFDemux *asf_demux, - GstEvent *event, - guint32 remaining) +gst_asf_demux_handle_sink_event (GstASFDemux * asf_demux, + GstEvent * event, guint32 remaining) { GstEventType type; gboolean ret = TRUE; @@ -1120,13 +1157,14 @@ gst_asf_demux_handle_sink_event (GstASFDemux *asf_demux, type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN; switch (type) { - case GST_EVENT_EOS: { + case GST_EVENT_EOS:{ asf_stream_context *stream; GstEvent *event = gst_event_new (GST_EVENT_EOS); gint n; + for (n = 0; n < asf_demux->num_streams; n++) { - stream = &asf_demux->stream[n]; - gst_pad_push (stream->pad, GST_DATA (gst_event_ref (event))); + stream = &asf_demux->stream[n]; + gst_pad_push (stream->pad, GST_DATA (gst_event_ref (event))); } gst_event_unref (event); gst_bytestream_flush (asf_demux->bs, remaining); @@ -1140,13 +1178,15 @@ gst_asf_demux_handle_sink_event (GstASFDemux *asf_demux, GstEvent *discont; for (i = 0; i < asf_demux->num_streams; i++) { - asf_stream_context *stream = &asf_demux->stream[i]; + asf_stream_context *stream = &asf_demux->stream[i]; if (GST_PAD_IS_USABLE (stream->pad)) { - GST_DEBUG ("sending discont on %d %" G_GINT64_FORMAT " + %" G_GINT64_FORMAT " = %" G_GINT64_FORMAT, i, - asf_demux->last_seek, stream->delay, asf_demux->last_seek + stream->delay); - discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, - asf_demux->last_seek + stream->delay , NULL); + GST_DEBUG ("sending discont on %d %" G_GINT64_FORMAT " + %" + G_GINT64_FORMAT " = %" G_GINT64_FORMAT, i, asf_demux->last_seek, + stream->delay, asf_demux->last_seek + stream->delay); + discont = + gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, + asf_demux->last_seek + stream->delay, NULL); gst_pad_push (stream->pad, GST_DATA (discont)); } } @@ -1166,24 +1206,26 @@ gst_asf_demux_handle_sink_event (GstASFDemux *asf_demux, } static gboolean -gst_asf_demux_handle_src_event (GstPad *pad, GstEvent *event) +gst_asf_demux_handle_src_event (GstPad * pad, GstEvent * event) { GST_DEBUG ("asfdemux: handle_src_event"); return FALSE; } -static const GstEventMask* -gst_asf_demux_get_src_event_mask (GstPad *pad) { +static const GstEventMask * +gst_asf_demux_get_src_event_mask (GstPad * pad) +{ static const GstEventMask masks[] = { - { GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_KEY_UNIT }, - { 0, } + {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_KEY_UNIT}, + {0,} }; return masks; } -static const GstFormat* -gst_asf_demux_get_src_formats (GstPad *pad) { +static const GstFormat * +gst_asf_demux_get_src_formats (GstPad * pad) +{ static const GstFormat formats[] = { GST_FORMAT_TIME, 0 @@ -1191,8 +1233,9 @@ gst_asf_demux_get_src_formats (GstPad *pad) { return formats; } -static const GstQueryType* -gst_asf_demux_get_src_query_types (GstPad *pad) { +static const GstQueryType * +gst_asf_demux_get_src_query_types (GstPad * pad) +{ static const GstQueryType types[] = { GST_QUERY_TOTAL, GST_QUERY_POSITION, @@ -1203,9 +1246,8 @@ gst_asf_demux_get_src_query_types (GstPad *pad) { } static gboolean -gst_asf_demux_handle_src_query (GstPad *pad, - GstQueryType type, - GstFormat *format, gint64 *value) +gst_asf_demux_handle_src_query (GstPad * pad, + GstQueryType type, GstFormat * format, gint64 * value) { GstASFDemux *asf_demux; gboolean res = TRUE; @@ -1213,32 +1255,32 @@ gst_asf_demux_handle_src_query (GstPad *pad, asf_demux = GST_ASF_DEMUX (gst_pad_get_parent (pad)); switch (type) { - case GST_QUERY_TOTAL: - switch (*format) { - case GST_FORMAT_DEFAULT: - *format = GST_FORMAT_TIME; - /* fall through */ - case GST_FORMAT_TIME: - *value = (GST_SECOND / 1000) * asf_demux->pts; + case GST_QUERY_TOTAL: + switch (*format) { + case GST_FORMAT_DEFAULT: + *format = GST_FORMAT_TIME; + /* fall through */ + case GST_FORMAT_TIME: + *value = (GST_SECOND / 1000) * asf_demux->pts; + break; + default: + res = FALSE; + } break; + case GST_QUERY_POSITION: + switch (*format) { + case GST_FORMAT_DEFAULT: + *format = GST_FORMAT_TIME; + /* fall through */ + case GST_FORMAT_TIME: + *value = (GST_SECOND / 1000) * asf_demux->timestamp; + break; + default: + res = FALSE; + } default: res = FALSE; - } - break; - case GST_QUERY_POSITION: - switch (*format) { - case GST_FORMAT_DEFAULT: - *format = GST_FORMAT_TIME; - /* fall through */ - case GST_FORMAT_TIME: - *value = (GST_SECOND / 1000) * asf_demux->timestamp; break; - default: - res = FALSE; - } - default: - res = FALSE; - break; } return res; @@ -1246,10 +1288,8 @@ gst_asf_demux_handle_src_query (GstPad *pad, static void -gst_asf_demux_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +gst_asf_demux_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec) { GstASFDemux *src; @@ -1264,11 +1304,11 @@ gst_asf_demux_get_property (GObject *object, } static GstElementStateReturn -gst_asf_demux_change_state (GstElement *element) -{ +gst_asf_demux_change_state (GstElement * element) +{ GstASFDemux *asf_demux = GST_ASF_DEMUX (element); gint i; - + switch (GST_STATE_TRANSITION (element)) { case GST_STATE_READY_TO_PAUSED: asf_demux->bs = gst_bytestream_new (asf_demux->sinkpad); @@ -1276,11 +1316,11 @@ gst_asf_demux_change_state (GstElement *element) break; case GST_STATE_PAUSED_TO_READY: gst_bytestream_destroy (asf_demux->bs); - for (i = 0 ; i < GST_ASF_DEMUX_NUM_VIDEO_PADS; i++) { - asf_demux->video_PTS[i] = 0; + for (i = 0; i < GST_ASF_DEMUX_NUM_VIDEO_PADS; i++) { + asf_demux->video_PTS[i] = 0; } - for (i = 0 ; i < GST_ASF_DEMUX_NUM_AUDIO_PADS;i++) { - asf_demux->audio_PTS[i] = 0; + for (i = 0; i < GST_ASF_DEMUX_NUM_AUDIO_PADS; i++) { + asf_demux->audio_PTS[i] = 0; } break; case GST_STATE_READY_TO_NULL: @@ -1293,24 +1333,23 @@ gst_asf_demux_change_state (GstElement *element) } static guint32 -gst_asf_demux_identify_guid (GstASFDemux *asf_demux, - ASFGuidHash *guids, - ASFGuid *guid) +gst_asf_demux_identify_guid (GstASFDemux * asf_demux, + ASFGuidHash * guids, ASFGuid * guid) { guint32 i; - GST_LOG_OBJECT (asf_demux, "identifying 0x%08x/0x%08x/0x%08x/0x%08x", guid->v1, guid->v2, guid->v3, guid->v4); + GST_LOG_OBJECT (asf_demux, "identifying 0x%08x/0x%08x/0x%08x/0x%08x", + guid->v1, guid->v2, guid->v3, guid->v4); i = 0; while (guids[i].obj_id != ASF_OBJ_UNDEFINED) { if (guids[i].guid.v1 == guid->v1 && guids[i].guid.v2 == guid->v2 && - guids[i].guid.v3 == guid->v3 && - guids[i].guid.v4 == guid->v4) { + guids[i].guid.v3 == guid->v3 && guids[i].guid.v4 == guid->v4) { return guids[i].obj_id; } i++; } - + /* The base case if none is found */ return ASF_OBJ_UNDEFINED; } @@ -1318,8 +1357,7 @@ gst_asf_demux_identify_guid (GstASFDemux *asf_demux, static GstCaps * gst_asf_demux_audio_caps (guint16 codec_id, - asf_stream_audio *audio, guint8 *extradata, - char **codec_name) + asf_stream_audio * audio, guint8 * extradata, char **codec_name) { GstCaps *caps; gint flags1, flags2; @@ -1328,119 +1366,110 @@ gst_asf_demux_audio_caps (guint16 codec_id, flags2 = 0; switch (codec_id) { - case GST_RIFF_WAVE_FORMAT_MPEGL3: /* mp3 */ + case GST_RIFF_WAVE_FORMAT_MPEGL3: /* mp3 */ caps = gst_caps_from_string ("audio/mpeg, mpegversion = (int) 1, " - "layer = (int) 3"); + "layer = (int) 3"); if (codec_name) - *codec_name = g_strdup ("MPEG 1 layer 3"); + *codec_name = g_strdup ("MPEG 1 layer 3"); break; - case GST_RIFF_WAVE_FORMAT_MPEGL12: /* mp1 or mp2 */ + case GST_RIFF_WAVE_FORMAT_MPEGL12: /* mp1 or mp2 */ caps = gst_caps_from_string ("audio/mpeg, mpegversion = (int) 1, " - "layer = (int) 2"); + "layer = (int) 2"); if (codec_name) - *codec_name = g_strdup ("MPEG 1 layer 2"); + *codec_name = g_strdup ("MPEG 1 layer 2"); break; - case GST_RIFF_WAVE_FORMAT_PCM: /* PCM/wav */ { + case GST_RIFF_WAVE_FORMAT_PCM: /* PCM/wav */ { caps = gst_caps_from_string ("audio/x-raw-int, " "endianness = (int) LITTLE_ENDIAN," "signed = (boolean) { true, false }, " - "width = (int) { 8, 16 }, " - "depth = (int) { 8, 16 }"); + "width = (int) { 8, 16 }, " "depth = (int) { 8, 16 }"); if (audio != NULL) { - gint ba = audio->block_align; - gint ch = audio->channels; - gint ws = audio->word_size; + gint ba = audio->block_align; + gint ch = audio->channels; + gint ws = audio->word_size; gst_caps_set_simple (caps, - "width", G_TYPE_INT, (int)(ba * 8 / ch), - "depth", G_TYPE_INT, ws, - "signed", G_TYPE_BOOLEAN, (ws != 8), - NULL); + "width", G_TYPE_INT, (int) (ba * 8 / ch), + "depth", G_TYPE_INT, ws, "signed", G_TYPE_BOOLEAN, (ws != 8), NULL); } if (codec_name) - *codec_name = g_strdup ("PCM WAV"); + *codec_name = g_strdup ("PCM WAV"); } break; - case GST_RIFF_WAVE_FORMAT_VORBIS1: /* vorbis mode 1 */ - case GST_RIFF_WAVE_FORMAT_VORBIS2: /* vorbis mode 2 */ - case GST_RIFF_WAVE_FORMAT_VORBIS3: /* vorbis mode 3 */ - case GST_RIFF_WAVE_FORMAT_VORBIS1PLUS: /* vorbis mode 1+ */ - case GST_RIFF_WAVE_FORMAT_VORBIS2PLUS: /* vorbis mode 2+ */ - case GST_RIFF_WAVE_FORMAT_VORBIS3PLUS: /* vorbis mode 3+ */ - caps = gst_caps_from_string("audio/x-vorbis"); + case GST_RIFF_WAVE_FORMAT_VORBIS1: /* vorbis mode 1 */ + case GST_RIFF_WAVE_FORMAT_VORBIS2: /* vorbis mode 2 */ + case GST_RIFF_WAVE_FORMAT_VORBIS3: /* vorbis mode 3 */ + case GST_RIFF_WAVE_FORMAT_VORBIS1PLUS: /* vorbis mode 1+ */ + case GST_RIFF_WAVE_FORMAT_VORBIS2PLUS: /* vorbis mode 2+ */ + case GST_RIFF_WAVE_FORMAT_VORBIS3PLUS: /* vorbis mode 3+ */ + caps = gst_caps_from_string ("audio/x-vorbis"); if (codec_name) - *codec_name = g_strdup ("Vorbis"); + *codec_name = g_strdup ("Vorbis"); break; case GST_RIFF_WAVE_FORMAT_A52: - caps = gst_caps_from_string("audio/x-ac3"); + caps = gst_caps_from_string ("audio/x-ac3"); if (codec_name) - *codec_name = g_strdup ("AC3"); + *codec_name = g_strdup ("AC3"); break; case GST_RIFF_WAVE_FORMAT_DIVX_WMAV1: /* get flags1 and flags2 ripped from ffmpeg (wmadec.c) */ if (audio && audio->size >= 4) { - flags1 = extradata[0] | (extradata[1] << 8); - flags2 = extradata[2] | (extradata[3] << 8); + flags1 = extradata[0] | (extradata[1] << 8); + flags2 = extradata[2] | (extradata[3] << 8); } - caps = gst_caps_from_string("audio/x-wma, " + caps = gst_caps_from_string ("audio/x-wma, " "wmaversion = (int) 1, " "flags1 = (int) [ MIN, MAX ], " "flags2 = (int) [ MIN, MAX ], " - "block_align = (int) [ 0, MAX ], " - "bitrate = (int) [ 0, MAX ]"); + "block_align = (int) [ 0, MAX ], " "bitrate = (int) [ 0, MAX ]"); if (audio != NULL) { gst_caps_set_simple (caps, "flags1", G_TYPE_INT, flags1, "flags2", G_TYPE_INT, flags2, "block_align", G_TYPE_INT, audio->block_align, - "bitrate", G_TYPE_INT, audio->byte_rate * 8, - NULL); + "bitrate", G_TYPE_INT, audio->byte_rate * 8, NULL); } if (codec_name) - *codec_name = g_strdup ("Microsoft WMA V1"); + *codec_name = g_strdup ("Microsoft WMA V1"); break; case GST_RIFF_WAVE_FORMAT_DIVX_WMAV2: /* get flags1 and flags2 ripped from ffmpeg (wmadec.c) */ if (audio && audio->size >= 6) { - flags1 = extradata[0] | (extradata[1] << 8) | - (extradata[2] << 16) | (extradata[3] << 24); - flags2 = extradata[4] | (extradata[5] << 8); + flags1 = extradata[0] | (extradata[1] << 8) | + (extradata[2] << 16) | (extradata[3] << 24); + flags2 = extradata[4] | (extradata[5] << 8); } - caps = gst_caps_from_string("audio/x-wma, " + caps = gst_caps_from_string ("audio/x-wma, " "wmaversion = (int) 2, " "flags1 = (int) [ MIN, MAX ], " "flags2 = (int) [ MIN, MAX ], " - "block_align = (int) [ 0, MAX ], " - "bitrate = (int) [ 0, MAX ]"); + "block_align = (int) [ 0, MAX ], " "bitrate = (int) [ 0, MAX ]"); if (audio != NULL) { gst_caps_set_simple (caps, "flags1", G_TYPE_INT, flags1, "flags2", G_TYPE_INT, flags2, "block_align", G_TYPE_INT, audio->block_align, - "bitrate", G_TYPE_INT, audio->byte_rate * 8, - NULL); + "bitrate", G_TYPE_INT, audio->byte_rate * 8, NULL); } if (codec_name) - *codec_name = g_strdup ("Microsoft WMA V2"); + *codec_name = g_strdup ("Microsoft WMA V2"); break; case GST_RIFF_WAVE_FORMAT_WMAV9: - caps = gst_caps_from_string("audio/x-wma, " - "wmaversion = (int) 9"); + caps = gst_caps_from_string ("audio/x-wma, " "wmaversion = (int) 9"); if (codec_name) - *codec_name = g_strdup ("Microsoft WMA V9"); + *codec_name = g_strdup ("Microsoft WMA V9"); break; default: - GST_WARNING ("asfdemux: unknown audio format 0x%04x", - codec_id); + GST_WARNING ("asfdemux: unknown audio format 0x%04x", codec_id); return GST_CAPS_ANY; break; } @@ -1448,22 +1477,19 @@ gst_asf_demux_audio_caps (guint16 codec_id, if (audio != NULL) { gst_caps_set_simple (caps, "rate", G_TYPE_INT, audio->sample_rate, - "channels", G_TYPE_INT, audio->channels, - NULL); - }else{ + "channels", G_TYPE_INT, audio->channels, NULL); + } else { gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 8000, 96000, - "channels", GST_TYPE_INT_RANGE, 1, 2, - NULL); + "channels", GST_TYPE_INT_RANGE, 1, 2, NULL); } return caps; } -static gboolean -gst_asf_demux_add_audio_stream (GstASFDemux *asf_demux, - asf_stream_audio *audio, - guint16 id) +static gboolean +gst_asf_demux_add_audio_stream (GstASFDemux * asf_demux, + asf_stream_audio * audio, guint16 id) { GstPad *src_pad; GstCaps *caps; @@ -1471,7 +1497,7 @@ gst_asf_demux_add_audio_stream (GstASFDemux *asf_demux, guint16 size_left = 0; char *codec_name = NULL; GstTagList *list = gst_tag_list_new (); - + size_left = audio->size; /* Create the audio pad */ @@ -1486,27 +1512,27 @@ gst_asf_demux_add_audio_stream (GstASFDemux *asf_demux, if (size_left) { guint8 *extradata; - GST_WARNING_OBJECT (asf_demux, "asfdemux: Audio header contains %d bytes of surplus data", size_left); - gst_bytestream_peek_bytes (asf_demux->bs, &extradata, size_left); + GST_WARNING_OBJECT (asf_demux, + "asfdemux: Audio header contains %d bytes of surplus data", size_left); + gst_bytestream_peek_bytes (asf_demux->bs, &extradata, size_left); caps = gst_asf_demux_audio_caps (audio->codec_tag, audio, extradata, - &codec_name); + &codec_name); gst_bytestream_flush (asf_demux->bs, size_left); } else { caps = gst_asf_demux_audio_caps (audio->codec_tag, audio, NULL, - &codec_name); + &codec_name); } - + /* Informing about that audio format we just added */ gst_tag_list_add (list, GST_TAG_MERGE_APPEND, GST_TAG_AUDIO_CODEC, - codec_name, NULL); + codec_name, NULL); gst_element_found_tags (GST_ELEMENT (asf_demux), list); gst_tag_list_free (list); - if (codec_name) g_free (codec_name); - + if (codec_name) + g_free (codec_name); + GST_INFO ("Adding audio stream %u codec %u (0x%x)", - asf_demux->num_video_streams, - audio->codec_tag, - audio->codec_tag); + asf_demux->num_video_streams, audio->codec_tag, audio->codec_tag); asf_demux->num_audio_streams++; @@ -1515,109 +1541,108 @@ gst_asf_demux_add_audio_stream (GstASFDemux *asf_demux, static GstCaps * gst_asf_demux_video_caps (guint32 codec_fcc, - asf_stream_video_format *video, - char **codec_name) + asf_stream_video_format * video, char **codec_name) { GstCaps *caps = NULL; gint width = 0, height = 0; - + if (video != NULL) { width = video->width; height = video->height; } switch (codec_fcc) { - case GST_MAKE_FOURCC('I','4','2','0'): + case GST_MAKE_FOURCC ('I', '4', '2', '0'): caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC, codec_fcc, NULL); if (codec_name) - *codec_name = g_strdup ("Raw, uncompressed I420"); - case GST_MAKE_FOURCC('Y','U','Y','2'): + *codec_name = g_strdup ("Raw, uncompressed I420"); + case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'): caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC, codec_fcc, NULL); if (codec_name) - *codec_name = g_strdup ("Raw, uncompressed YUV 4:2:2"); + *codec_name = g_strdup ("Raw, uncompressed YUV 4:2:2"); break; - case GST_MAKE_FOURCC('M','J','P','G'): + case GST_MAKE_FOURCC ('M', 'J', 'P', 'G'): caps = gst_caps_new_simple ("video/x-jpeg", NULL); if (codec_name) - *codec_name = g_strdup ("Motion JPEG"); - case GST_MAKE_FOURCC('J','P','E','G'): + *codec_name = g_strdup ("Motion JPEG"); + case GST_MAKE_FOURCC ('J', 'P', 'E', 'G'): caps = gst_caps_new_simple ("video/x-jpeg", NULL); if (codec_name) - *codec_name = g_strdup ("JPEG Still Image"); - case GST_MAKE_FOURCC('P','I','X','L'): - case GST_MAKE_FOURCC('V','I','X','L'): + *codec_name = g_strdup ("JPEG Still Image"); + case GST_MAKE_FOURCC ('P', 'I', 'X', 'L'): + case GST_MAKE_FOURCC ('V', 'I', 'X', 'L'): caps = gst_caps_new_simple ("video/x-jpeg", NULL); if (codec_name) - *codec_name = g_strdup ("Miro/Pinnacle Video XL"); + *codec_name = g_strdup ("Miro/Pinnacle Video XL"); break; - case GST_MAKE_FOURCC('D','V','S','D'): - case GST_MAKE_FOURCC('d','v','s','d'): + case GST_MAKE_FOURCC ('D', 'V', 'S', 'D'): + case GST_MAKE_FOURCC ('d', 'v', 's', 'd'): caps = gst_caps_new_simple ("video/x-dv", "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); if (codec_name) - *codec_name = g_strdup ("Generic DV"); + *codec_name = g_strdup ("Generic DV"); break; - case GST_MAKE_FOURCC('W','M','V','1'): + case GST_MAKE_FOURCC ('W', 'M', 'V', '1'): caps = gst_caps_new_simple ("video/x-wmv", "wmvversion", G_TYPE_INT, 1, NULL); if (codec_name) - *codec_name = g_strdup ("Windows Media Video 7"); + *codec_name = g_strdup ("Windows Media Video 7"); break; - case GST_MAKE_FOURCC('W','M','V','2'): + case GST_MAKE_FOURCC ('W', 'M', 'V', '2'): caps = gst_caps_new_simple ("video/x-wmv", "wmvversion", G_TYPE_INT, 2, NULL); if (codec_name) - *codec_name = g_strdup ("Windows Media Video 8"); + *codec_name = g_strdup ("Windows Media Video 8"); break; - case GST_MAKE_FOURCC('M','P','G','4'): + case GST_MAKE_FOURCC ('M', 'P', 'G', '4'): caps = gst_caps_new_simple ("video/x-msmpeg", "msmpegversion", G_TYPE_INT, 41, NULL); if (codec_name) - *codec_name = g_strdup ("Microsoft MPEG-4 4.1"); + *codec_name = g_strdup ("Microsoft MPEG-4 4.1"); break; - case GST_MAKE_FOURCC('M','P','4','2'): + case GST_MAKE_FOURCC ('M', 'P', '4', '2'): caps = gst_caps_new_simple ("video/x-msmpeg", "msmpegversion", G_TYPE_INT, 42, NULL); if (codec_name) - *codec_name = g_strdup ("Microsoft MPEG-4 4.2"); + *codec_name = g_strdup ("Microsoft MPEG-4 4.2"); break; - case GST_MAKE_FOURCC('M','P','4','3'): + case GST_MAKE_FOURCC ('M', 'P', '4', '3'): caps = gst_caps_new_simple ("video/x-msmpeg", "msmpegversion", G_TYPE_INT, 43, NULL); if (codec_name) - *codec_name = g_strdup ("Microsoft MPEG-4 4.3"); + *codec_name = g_strdup ("Microsoft MPEG-4 4.3"); break; - case GST_MAKE_FOURCC('D','I','V','3'): - case GST_MAKE_FOURCC('D','I','V','4'): - case GST_MAKE_FOURCC('D','I','V','5'): + case GST_MAKE_FOURCC ('D', 'I', 'V', '3'): + case GST_MAKE_FOURCC ('D', 'I', 'V', '4'): + case GST_MAKE_FOURCC ('D', 'I', 'V', '5'): caps = gst_caps_new_simple ("video/x-divx", "divxversion", G_TYPE_INT, 3, NULL); if (codec_name) - *codec_name = g_strdup ("DivX MPEG-4 Version 3"); + *codec_name = g_strdup ("DivX MPEG-4 Version 3"); break; - case GST_MAKE_FOURCC('D','I','V','X'): - case GST_MAKE_FOURCC('d','i','v','x'): - case GST_MAKE_FOURCC('D','X','5','0'): + case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'): + case GST_MAKE_FOURCC ('d', 'i', 'v', 'x'): + case GST_MAKE_FOURCC ('D', 'X', '5', '0'): caps = gst_caps_new_simple ("video/x-divx", "divxversion", G_TYPE_INT, 5, NULL); if (codec_name) - *codec_name = g_strdup ("DivX MPEG-4 Version 5"); + *codec_name = g_strdup ("DivX MPEG-4 Version 5"); break; default: - GST_WARNING ("asfdemux: unknown video format " GST_FOURCC_FORMAT "(0x%08x)", - GST_FOURCC_ARGS(codec_fcc), codec_fcc); + GST_WARNING ("asfdemux: unknown video format " GST_FOURCC_FORMAT + "(0x%08x)", GST_FOURCC_ARGS (codec_fcc), codec_fcc); return NULL; break; } @@ -1626,22 +1651,21 @@ gst_asf_demux_video_caps (guint32 codec_fcc, gst_caps_set_simple (caps, "width", G_TYPE_INT, video->width, "height", G_TYPE_INT, video->height, - "framerate", G_TYPE_DOUBLE, (double) 25, NULL); + "framerate", G_TYPE_DOUBLE, (double) 25, NULL); } else { gst_caps_set_simple (caps, "width", GST_TYPE_INT_RANGE, 1, G_MAXINT, "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, - "framerate", GST_TYPE_DOUBLE_RANGE, 25.0, G_MAXDOUBLE, - NULL); + "framerate", GST_TYPE_DOUBLE_RANGE, 25.0, G_MAXDOUBLE, NULL); } return caps; } static gboolean -gst_asf_demux_add_video_stream (GstASFDemux *asf_demux, - asf_stream_video_format *video, - guint16 id) { +gst_asf_demux_add_video_stream (GstASFDemux * asf_demux, + asf_stream_video_format * video, guint16 id) +{ GstPad *src_pad; GstCaps *caps; gchar *name = NULL; @@ -1656,15 +1680,14 @@ gst_asf_demux_add_video_stream (GstASFDemux *asf_demux, /* Now try some gstreamer formatted MIME types (from gst_avi_demux_strf_vids) */ caps = gst_asf_demux_video_caps (video->tag, video, &codec_name); gst_tag_list_add (list, GST_TAG_MERGE_APPEND, GST_TAG_VIDEO_CODEC, - codec_name, NULL); + codec_name, NULL); gst_element_found_tags (GST_ELEMENT (asf_demux), list); gst_tag_list_free (list); - if (codec_name) g_free (codec_name); + if (codec_name) + g_free (codec_name); GST_INFO ("Adding video stream %u codec " GST_FOURCC_FORMAT " (0x%08x)", - asf_demux->num_video_streams, - GST_FOURCC_ARGS(video->tag), - video->tag); - + asf_demux->num_video_streams, GST_FOURCC_ARGS (video->tag), video->tag); + asf_demux->num_video_streams++; return gst_asf_demux_setup_pad (asf_demux, src_pad, caps, id); @@ -1672,10 +1695,8 @@ gst_asf_demux_add_video_stream (GstASFDemux *asf_demux, static gboolean -gst_asf_demux_setup_pad (GstASFDemux *asf_demux, - GstPad *src_pad, - GstCaps *caps, - guint16 id) +gst_asf_demux_setup_pad (GstASFDemux * asf_demux, + GstPad * src_pad, GstCaps * caps, guint16 id) { asf_stream_context *stream; @@ -1686,7 +1707,7 @@ gst_asf_demux_setup_pad (GstASFDemux *asf_demux, gst_pad_set_event_function (src_pad, gst_asf_demux_handle_src_event); gst_pad_set_query_type_function (src_pad, gst_asf_demux_get_src_query_types); gst_pad_set_query_function (src_pad, gst_asf_demux_handle_src_query); - + stream = &asf_demux->stream[asf_demux->num_streams]; stream->pad = src_pad; stream->id = id; @@ -1696,41 +1717,36 @@ gst_asf_demux_setup_pad (GstASFDemux *asf_demux, gst_pad_set_element_private (src_pad, stream); - GST_INFO ("Adding pad for stream %u", - asf_demux->num_streams); + GST_INFO ("Adding pad for stream %u", asf_demux->num_streams); asf_demux->num_streams++; - + gst_element_add_pad (GST_ELEMENT (asf_demux), src_pad); - + return TRUE; } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { if (!gst_library_load ("gstbytestream")) return FALSE; /* create an elementfactory for the asf_demux element */ - if (!gst_element_register (plugin, "asfdemux", GST_RANK_PRIMARY, GST_TYPE_ASF_DEMUX) || - !gst_element_register (plugin, "asfmux", GST_RANK_NONE, GST_TYPE_ASFMUX)) + if (!gst_element_register (plugin, "asfdemux", GST_RANK_PRIMARY, + GST_TYPE_ASF_DEMUX) + || !gst_element_register (plugin, "asfmux", GST_RANK_NONE, + GST_TYPE_ASFMUX)) return FALSE; GST_DEBUG_CATEGORY_INIT (asf_debug, "asfdemux", 0, "asf demuxer element"); - + return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "asf", - "Demuxes and muxes audio and video in Microsofts ASF format", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "asf", + "Demuxes and muxes audio and video in Microsofts ASF format", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/gst/asfdemux/gstasfdemux.h b/gst/asfdemux/gstasfdemux.h index 3f11071f65..0fcd63025d 100644 --- a/gst/asfdemux/gstasfdemux.h +++ b/gst/asfdemux/gstasfdemux.h @@ -26,7 +26,6 @@ #include "asfheaders.h" G_BEGIN_DECLS - #define GST_TYPE_ASF_DEMUX \ (asf_demux_get_type()) #define GST_ASF_DEMUX(obj) \ @@ -37,11 +36,11 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ASF_DEMUX)) #define GST_IS_ASF_DEMUX_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ASF_DEMUX)) - typedef struct _GstASFDemux GstASFDemux; typedef struct _GstASFDemuxClass GstASFDemuxClass; -struct _GstASFStreamContext { +struct _GstASFStreamContext +{ GstPad *pad; guint64 pts; }; @@ -49,7 +48,7 @@ struct _GstASFStreamContext { typedef struct { - GstPad *pad; + GstPad *pad; guint16 id; guint32 frag_offset; guint32 sequence; @@ -57,11 +56,12 @@ typedef struct GstBuffer *payload; } asf_stream_context; -struct _GstASFDemux { - GstElement element; +struct _GstASFDemux +{ + GstElement element; /* pads */ - GstPad *sinkpad; + GstPad *sinkpad; GstByteStream *bs; @@ -77,7 +77,7 @@ struct _GstASFDemux { GstPad *audio_pad[GST_ASF_DEMUX_NUM_AUDIO_PADS]; gint64 audio_PTS[GST_ASF_DEMUX_NUM_AUDIO_PADS]; - guint64 last_seek; + guint64 last_seek; gboolean restart; guint32 bitrate[GST_ASF_DEMUX_NUM_STREAM_IDS]; @@ -96,23 +96,23 @@ struct _GstASFDemux { guint64 pts; /* Descrambler settings */ - guint8 span; + guint8 span; guint16 ds_packet_size; guint16 ds_chunk_size; guint16 ds_data_size; }; -struct _GstASFDemuxClass { +struct _GstASFDemuxClass +{ GstElementClass parent_class; }; -GType gst_asf_demux_get_type(void); +GType gst_asf_demux_get_type (void); -gboolean gst_asf_demux_plugin_init (GModule *module, GstPlugin *plugin); +gboolean gst_asf_demux_plugin_init (GModule * module, GstPlugin * plugin); G_END_DECLS - #endif /* __ASF_DEMUX_H__ */ diff --git a/gst/asfdemux/gstasfmux.c b/gst/asfdemux/gstasfmux.c index 2dca06ce87..e7b0d372eb 100644 --- a/gst/asfdemux/gstasfmux.c +++ b/gst/asfdemux/gstasfmux.c @@ -49,9 +49,7 @@ #include "gstasfmux.h" /* elementfactory information */ -static GstElementDetails -gst_asfmux_details = -{ +static GstElementDetails gst_asfmux_details = { "Asf multiplexer", "Codec/Muxer", "Muxes audio and video streams into an asf stream", @@ -59,122 +57,114 @@ gst_asfmux_details = }; /* AsfMux signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, }; static GstStaticPadTemplate gst_asfmux_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-ms-asf") -); - +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-ms-asf") + ); + static GstStaticPadTemplate gst_asfmux_videosink_template = -GST_STATIC_PAD_TEMPLATE ( - "video_%d", - GST_PAD_SINK, - GST_PAD_REQUEST, - GST_STATIC_CAPS ( - "video/x-raw-yuv, " - "format = (fourcc) { YUY2, I420 }, " - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]; " - "video/x-jpeg, " - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]; " - "video/x-divx, " - "divxversion = (int) [ 3, 5 ], " - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]; " - "video/x-xvid, " - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]; " - "video/x-3ivx, " - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]; " - "video/x-msmpeg, " - "msmpegversion = (int) [ 41, 43 ], " - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]; " - "video/mpeg, " - "mpegversion = (int) 1," - "systemstream = (boolean) false," - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]; " - "video/x-h263, " - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]; " - "video/x-dv, " - "systemstream = (boolean) false," - "width = (int) 720," - "height = (int) { 576, 480 };" - "video/x-huffyuv, " - "width = (int) [ 1, MAX], " - "height = (int) [ 1, MAX]" - ) -); - + GST_STATIC_PAD_TEMPLATE ("video_%d", + GST_PAD_SINK, + GST_PAD_REQUEST, + GST_STATIC_CAPS ("video/x-raw-yuv, " + "format = (fourcc) { YUY2, I420 }, " + "width = (int) [ 1, MAX], " + "height = (int) [ 1, MAX]; " + "video/x-jpeg, " + "width = (int) [ 1, MAX], " + "height = (int) [ 1, MAX]; " + "video/x-divx, " + "divxversion = (int) [ 3, 5 ], " + "width = (int) [ 1, MAX], " + "height = (int) [ 1, MAX]; " + "video/x-xvid, " + "width = (int) [ 1, MAX], " + "height = (int) [ 1, MAX]; " + "video/x-3ivx, " + "width = (int) [ 1, MAX], " + "height = (int) [ 1, MAX]; " + "video/x-msmpeg, " + "msmpegversion = (int) [ 41, 43 ], " + "width = (int) [ 1, MAX], " + "height = (int) [ 1, MAX]; " + "video/mpeg, " + "mpegversion = (int) 1," + "systemstream = (boolean) false," + "width = (int) [ 1, MAX], " + "height = (int) [ 1, MAX]; " + "video/x-h263, " + "width = (int) [ 1, MAX], " + "height = (int) [ 1, MAX]; " + "video/x-dv, " + "systemstream = (boolean) false," + "width = (int) 720," + "height = (int) { 576, 480 };" + "video/x-huffyuv, " + "width = (int) [ 1, MAX], " "height = (int) [ 1, MAX]") + ); + static GstStaticPadTemplate gst_asfmux_audiosink_template = -GST_STATIC_PAD_TEMPLATE ( - "audio_%d", - GST_PAD_SINK, - GST_PAD_REQUEST, - GST_STATIC_CAPS ( - "audio/x-raw-int, " - "endianness = (int) LITTLE_ENDIAN, " - "signed = (boolean) { true, false }, " - "width = (int) { 8, 16 }, " - "depth = (int) { 8, 16 }, " - "rate = (int) [ 1000, 96000 ], " - "channels = (int) [ 1, 2]; " - "audio/mpeg, " - "mpegversion = (int) 1, " - "layer = (int) { 1, 3 }, " - "rate = (int) [ 1000, 96000 ], " - "channels = (int) [ 1, 2]; " - "audio/x-vorbis, " - "rate = (int) [ 1000, 96000 ], " - "channels = (int) [ 1, 2]; " - "audio/x-ac3, " - "rate = (int) [ 1000, 96000 ], " - "channels = (int) [ 1, 2]" - ) -); - + GST_STATIC_PAD_TEMPLATE ("audio_%d", + GST_PAD_SINK, + GST_PAD_REQUEST, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) LITTLE_ENDIAN, " + "signed = (boolean) { true, false }, " + "width = (int) { 8, 16 }, " + "depth = (int) { 8, 16 }, " + "rate = (int) [ 1000, 96000 ], " + "channels = (int) [ 1, 2]; " + "audio/mpeg, " + "mpegversion = (int) 1, " + "layer = (int) { 1, 3 }, " + "rate = (int) [ 1000, 96000 ], " + "channels = (int) [ 1, 2]; " + "audio/x-vorbis, " + "rate = (int) [ 1000, 96000 ], " + "channels = (int) [ 1, 2]; " + "audio/x-ac3, " + "rate = (int) [ 1000, 96000 ], " "channels = (int) [ 1, 2]") + ); + #define GST_ASF_PACKET_SIZE 3200 #define GST_ASF_PACKET_HEADER_SIZE 12 #define GST_ASF_FRAME_HEADER_SIZE 17 -static void gst_asfmux_base_init (gpointer g_class); -static void gst_asfmux_class_init (GstAsfMuxClass *klass); -static void gst_asfmux_init (GstAsfMux *asfmux); +static void gst_asfmux_base_init (gpointer g_class); +static void gst_asfmux_class_init (GstAsfMuxClass * klass); +static void gst_asfmux_init (GstAsfMux * asfmux); -static void gst_asfmux_loop (GstElement *element); -static gboolean gst_asfmux_handle_event (GstPad *pad, - GstEvent *event); -static GstPad* gst_asfmux_request_new_pad (GstElement *element, - GstPadTemplate *templ, - const gchar *name); -static GstElementStateReturn gst_asfmux_change_state (GstElement *element); +static void gst_asfmux_loop (GstElement * element); +static gboolean gst_asfmux_handle_event (GstPad * pad, GstEvent * event); +static GstPad *gst_asfmux_request_new_pad (GstElement * element, + GstPadTemplate * templ, const gchar * name); +static GstElementStateReturn gst_asfmux_change_state (GstElement * element); static GstElementClass *parent_class = NULL; + /*static guint gst_asfmux_signals[LAST_SIGNAL] = { 0 }; */ GType -gst_asfmux_get_type (void) +gst_asfmux_get_type (void) { static GType asfmux_type = 0; if (!asfmux_type) { static const GTypeInfo asfmux_info = { - sizeof (GstAsfMuxClass), + sizeof (GstAsfMuxClass), gst_asfmux_base_init, NULL, (GClassInitFunc) gst_asfmux_class_init, @@ -185,8 +175,7 @@ gst_asfmux_get_type (void) (GInstanceInitFunc) gst_asfmux_init, }; asfmux_type = g_type_register_static (GST_TYPE_ELEMENT, - "GstAsfMux", - &asfmux_info, 0); + "GstAsfMux", &asfmux_info, 0); } return asfmux_type; } @@ -206,7 +195,7 @@ gst_asfmux_base_init (gpointer g_class) } static void -gst_asfmux_class_init (GstAsfMuxClass *klass) +gst_asfmux_class_init (GstAsfMuxClass * klass) { GstElementClass *gstelement_class; @@ -219,23 +208,24 @@ gst_asfmux_class_init (GstAsfMuxClass *klass) } static const GstEventMask * -gst_asfmux_get_event_masks (GstPad *pad) +gst_asfmux_get_event_masks (GstPad * pad) { static const GstEventMask gst_asfmux_sink_event_masks[] = { - { GST_EVENT_EOS, 0 }, - { 0, } + {GST_EVENT_EOS, 0}, + {0,} }; return gst_asfmux_sink_event_masks; } -static void -gst_asfmux_init (GstAsfMux *asfmux) +static void +gst_asfmux_init (GstAsfMux * asfmux) { gint n; - asfmux->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_asfmux_src_template), "src"); + asfmux->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_asfmux_src_template), "src"); gst_element_add_pad (GST_ELEMENT (asfmux), asfmux->srcpad); GST_FLAG_SET (GST_ELEMENT (asfmux), GST_ELEMENT_EVENT_AWARE); @@ -255,13 +245,13 @@ gst_asfmux_init (GstAsfMux *asfmux) } static GstPadLinkReturn -gst_asfmux_vidsink_link (GstPad *pad, const GstCaps *caps) +gst_asfmux_vidsink_link (GstPad * pad, const GstCaps * caps) { GstAsfMux *asfmux; GstAsfMuxStream *stream = NULL; GstStructure *structure; gint n; - const gchar* mimetype; + const gchar *mimetype; gint w, h; gboolean ret; @@ -278,7 +268,7 @@ gst_asfmux_vidsink_link (GstPad *pad, const GstCaps *caps) g_assert (stream->type == ASF_STREAM_VIDEO); GST_DEBUG ("asfmux: video sinkconnect triggered on %s", - gst_pad_get_name (pad)); + gst_pad_get_name (pad)); structure = gst_caps_get_structure (caps, 0); @@ -286,82 +276,92 @@ gst_asfmux_vidsink_link (GstPad *pad, const GstCaps *caps) ret = gst_structure_get_int (structure, "width", &w); ret &= gst_structure_get_int (structure, "height", &h); - if(!ret) return GST_PAD_LINK_REFUSED; + if (!ret) + return GST_PAD_LINK_REFUSED; stream->header.video.stream.width = w; stream->header.video.stream.height = h; stream->header.video.stream.unknown = 2; stream->header.video.stream.size = 40; - stream->bitrate = 0; /* TODO */ + stream->bitrate = 0; /* TODO */ mimetype = gst_structure_get_name (structure); if (!strcmp (mimetype, "video/x-raw-yuv")) { guint32 format; ret = gst_structure_get_fourcc (structure, "format", &format); - if(!ret) return GST_PAD_LINK_REFUSED; + if (!ret) + return GST_PAD_LINK_REFUSED; stream->header.video.format.tag = format; switch (format) { - case GST_MAKE_FOURCC ('Y','U','Y','2'): - stream->header.video.format.depth = 16; + case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'): + stream->header.video.format.depth = 16; stream->header.video.format.planes = 1; break; - case GST_MAKE_FOURCC ('I','4','2','0'): - stream->header.video.format.depth = 12; + case GST_MAKE_FOURCC ('I', '4', '2', '0'): + stream->header.video.format.depth = 12; stream->header.video.format.planes = 3; break; } goto done; } else { - stream->header.video.format.depth = 24; + stream->header.video.format.depth = 24; stream->header.video.format.planes = 1; - stream->header.video.format.tag = 0; + stream->header.video.format.tag = 0; /* find format */ if (!strcmp (mimetype, "video/x-huffyuv")) { - stream->header.video.format.tag = GST_MAKE_FOURCC ('H','F','Y','U'); + stream->header.video.format.tag = GST_MAKE_FOURCC ('H', 'F', 'Y', 'U'); } else if (!strcmp (mimetype, "video/x-jpeg")) { - stream->header.video.format.tag = GST_MAKE_FOURCC ('M','J','P','G'); + stream->header.video.format.tag = GST_MAKE_FOURCC ('M', 'J', 'P', 'G'); } else if (!strcmp (mimetype, "video/x-divx")) { gint divxversion; + gst_structure_get_int (structure, "divxversion", &divxversion); switch (divxversion) { case 3: - stream->header.video.format.tag = GST_MAKE_FOURCC ('D','I','V','3'); + stream->header.video.format.tag = + GST_MAKE_FOURCC ('D', 'I', 'V', '3'); break; case 4: - stream->header.video.format.tag = GST_MAKE_FOURCC ('D','I','V','X'); + stream->header.video.format.tag = + GST_MAKE_FOURCC ('D', 'I', 'V', 'X'); break; case 5: - stream->header.video.format.tag = GST_MAKE_FOURCC ('D','X','5','0'); + stream->header.video.format.tag = + GST_MAKE_FOURCC ('D', 'X', '5', '0'); break; } } else if (!strcmp (mimetype, "video/x-xvid")) { - stream->header.video.format.tag = GST_MAKE_FOURCC ('X','V','I','D'); + stream->header.video.format.tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D'); } else if (!strcmp (mimetype, "video/x-3ivx")) { - stream->header.video.format.tag = GST_MAKE_FOURCC ('3','I','V','2'); + stream->header.video.format.tag = GST_MAKE_FOURCC ('3', 'I', 'V', '2'); } else if (!strcmp (mimetype, "video/x-msmpeg")) { gint msmpegversion; + gst_structure_get_int (structure, "msmpegversion", &msmpegversion); switch (msmpegversion) { case 41: - stream->header.video.format.tag = GST_MAKE_FOURCC ('M','P','G','4'); + stream->header.video.format.tag = + GST_MAKE_FOURCC ('M', 'P', 'G', '4'); break; case 42: - stream->header.video.format.tag = GST_MAKE_FOURCC ('M','P','4','2'); + stream->header.video.format.tag = + GST_MAKE_FOURCC ('M', 'P', '4', '2'); break; case 43: - stream->header.video.format.tag = GST_MAKE_FOURCC ('M','P','4','3'); + stream->header.video.format.tag = + GST_MAKE_FOURCC ('M', 'P', '4', '3'); break; } } else if (!strcmp (mimetype, "video/x-dv")) { - stream->header.video.format.tag = GST_MAKE_FOURCC ('D','V','S','D'); + stream->header.video.format.tag = GST_MAKE_FOURCC ('D', 'V', 'S', 'D'); } else if (!strcmp (mimetype, "video/x-h263")) { - stream->header.video.format.tag = GST_MAKE_FOURCC ('H','2','6','3'); + stream->header.video.format.tag = GST_MAKE_FOURCC ('H', '2', '6', '3'); } else if (!strcmp (mimetype, "video/mpeg")) { - stream->header.video.format.tag = GST_MAKE_FOURCC ('M','P','E','G'); + stream->header.video.format.tag = GST_MAKE_FOURCC ('M', 'P', 'E', 'G'); } if (!stream->header.video.format.tag) { @@ -378,7 +378,7 @@ done: stream->header.video.format.width = stream->header.video.stream.width; stream->header.video.format.height = stream->header.video.stream.height; stream->header.video.format.image_size = stream->header.video.stream.width * - stream->header.video.stream.height; + stream->header.video.stream.height; stream->header.video.format.xpels_meter = 0; stream->header.video.format.ypels_meter = 0; stream->header.video.format.num_colors = 0; @@ -388,12 +388,12 @@ done: } static GstPadLinkReturn -gst_asfmux_audsink_link (GstPad *pad, const GstCaps *caps) +gst_asfmux_audsink_link (GstPad * pad, const GstCaps * caps) { GstAsfMux *asfmux; GstAsfMuxStream *stream = NULL; gint n; - const gchar* mimetype; + const gchar *mimetype; gint rate, channels; gboolean ret; GstStructure *structure; @@ -410,8 +410,7 @@ gst_asfmux_audsink_link (GstPad *pad, const GstCaps *caps) g_assert (stream != NULL); g_assert (stream->type == ASF_STREAM_AUDIO); - GST_DEBUG ("asfmux: audio sink_link triggered on %s", - gst_pad_get_name (pad)); + GST_DEBUG ("asfmux: audio sink_link triggered on %s", gst_pad_get_name (pad)); structure = gst_caps_get_structure (caps, 0); @@ -419,10 +418,11 @@ gst_asfmux_audsink_link (GstPad *pad, const GstCaps *caps) ret = gst_structure_get_int (structure, "channels", &channels); ret &= gst_structure_get_int (structure, "rate", &rate); - if (!ret) return GST_PAD_LINK_REFUSED; + if (!ret) + return GST_PAD_LINK_REFUSED; stream->header.audio.sample_rate = rate; - stream->header.audio.channels = channels; + stream->header.audio.channels = channels; mimetype = gst_structure_get_name (structure); if (!strcmp (mimetype, "audio/x-raw-int")) { @@ -434,26 +434,28 @@ gst_asfmux_audsink_link (GstPad *pad, const GstCaps *caps) gst_structure_get_int (structure, "depth", &size); stream->header.audio.block_align = block; - stream->header.audio.word_size = size; - stream->header.audio.size = 0; + stream->header.audio.word_size = size; + stream->header.audio.size = 0; /* set some more info straight */ stream->header.audio.block_align /= 8; stream->header.audio.block_align *= stream->header.audio.channels; stream->header.audio.byte_rate = stream->header.audio.block_align * - stream->header.audio.sample_rate; + stream->header.audio.sample_rate; goto done; } else { stream->header.audio.codec_tag = 0; if (!strcmp (mimetype, "audio/mpeg")) { gint layer = 3; - gst_structure_get_int(structure, "layer", &layer); + + gst_structure_get_int (structure, "layer", &layer); switch (layer) { case 3: stream->header.audio.codec_tag = GST_RIFF_WAVE_FORMAT_MPEGL3; break; - case 1: case 2: + case 1: + case 2: stream->header.audio.codec_tag = GST_RIFF_WAVE_FORMAT_MPEGL12; break; } @@ -464,9 +466,9 @@ gst_asfmux_audsink_link (GstPad *pad, const GstCaps *caps) } stream->header.audio.block_align = 1; - stream->header.audio.byte_rate = 8 * 1024; - stream->header.audio.word_size = 16; - stream->header.audio.size = 0; + stream->header.audio.byte_rate = 8 * 1024; + stream->header.audio.word_size = 16; + stream->header.audio.size = 0; if (!stream->header.audio.codec_tag) { return GST_PAD_LINK_REFUSED; @@ -482,9 +484,7 @@ done: } static void -gst_asfmux_pad_link (GstPad *pad, - GstPad *peer, - gpointer data) +gst_asfmux_pad_link (GstPad * pad, GstPad * peer, gpointer data) { GstAsfMux *asfmux; GstAsfMuxStream *stream = NULL; @@ -506,9 +506,7 @@ gst_asfmux_pad_link (GstPad *pad, } static void -gst_asfmux_pad_unlink (GstPad *pad, - GstPad *peer, - gpointer data) +gst_asfmux_pad_unlink (GstPad * pad, GstPad * peer, gpointer data) { GstAsfMux *asfmux; GstAsfMuxStream *stream = NULL; @@ -529,10 +527,9 @@ gst_asfmux_pad_unlink (GstPad *pad, stream->connected = FALSE; } -static GstPad* -gst_asfmux_request_new_pad (GstElement *element, - GstPadTemplate *templ, - const gchar *req_name) +static GstPad * +gst_asfmux_request_new_pad (GstElement * element, + GstPadTemplate * templ, const gchar * req_name) { GstAsfMux *asfmux; GstPad *newpad; @@ -572,23 +569,24 @@ gst_asfmux_request_new_pad (GstElement *element, g_free (padname); g_signal_connect (newpad, "linked", - G_CALLBACK (gst_asfmux_pad_link), (gpointer) asfmux); + G_CALLBACK (gst_asfmux_pad_link), (gpointer) asfmux); g_signal_connect (newpad, "unlinked", - G_CALLBACK (gst_asfmux_pad_unlink), (gpointer) asfmux); + G_CALLBACK (gst_asfmux_pad_unlink), (gpointer) asfmux); gst_pad_set_link_function (newpad, linkfunc); gst_element_add_pad (element, newpad); gst_pad_set_event_function (newpad, gst_asfmux_handle_event); gst_pad_set_event_mask_function (newpad, gst_asfmux_get_event_masks); - + return newpad; } /* can we seek? If not, we assume we're streamable */ static gboolean -gst_asfmux_can_seek (GstAsfMux *asfmux) +gst_asfmux_can_seek (GstAsfMux * asfmux) { #if 0 - const GstEventMask *masks = gst_pad_get_event_masks (GST_PAD_PEER (asfmux->srcpad)); + const GstEventMask *masks = + gst_pad_get_event_masks (GST_PAD_PEER (asfmux->srcpad)); /* this is for stream or file-storage */ while (masks != NULL && masks->type != 0) { @@ -605,35 +603,35 @@ gst_asfmux_can_seek (GstAsfMux *asfmux) } static gboolean -gst_asfmux_is_stream (GstAsfMux *asfmux) +gst_asfmux_is_stream (GstAsfMux * asfmux) { /* this is for RTP */ - return FALSE; /*!gst_asfmux_can_seek (asfmux)*/ + return FALSE; /*!gst_asfmux_can_seek (asfmux) */ } /* handle events (search) */ static gboolean -gst_asfmux_handle_event (GstPad *pad, GstEvent *event) +gst_asfmux_handle_event (GstPad * pad, GstEvent * event) { GstAsfMux *asfmux; GstEventType type; gint n; asfmux = GST_ASFMUX (gst_pad_get_parent (pad)); - + type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN; switch (type) { case GST_EVENT_EOS: /* is this allright? */ for (n = 0; n < asfmux->num_outputs; n++) { - if (asfmux->output[n].pad == pad) { - asfmux->output[n].eos = TRUE; - break; - } + if (asfmux->output[n].pad == pad) { + asfmux->output[n].eos = TRUE; + break; + } } if (n == asfmux->num_outputs) { - g_warning ("Unknown pad for EOS!"); + g_warning ("Unknown pad for EOS!"); } break; default: @@ -645,7 +643,7 @@ gst_asfmux_handle_event (GstPad *pad, GstEvent *event) /* fill the internal queue for each available pad */ static void -gst_asfmux_fill_queue (GstAsfMux *asfmux) +gst_asfmux_fill_queue (GstAsfMux * asfmux) { GstBuffer *buffer; gint n; @@ -654,22 +652,21 @@ gst_asfmux_fill_queue (GstAsfMux *asfmux) GstAsfMuxStream *stream = &asfmux->output[n]; while (stream->queue == NULL && - stream->pad != NULL && - stream->connected == TRUE && - GST_PAD_IS_USABLE (stream->pad) && - stream->eos == FALSE) { + stream->pad != NULL && + stream->connected == TRUE && + GST_PAD_IS_USABLE (stream->pad) && stream->eos == FALSE) { buffer = GST_BUFFER (gst_pad_pull (stream->pad)); if (GST_IS_EVENT (buffer)) { - gst_asfmux_handle_event (stream->pad, GST_EVENT (buffer)); + gst_asfmux_handle_event (stream->pad, GST_EVENT (buffer)); } else { - stream->queue = buffer; + stream->queue = buffer; } } } } static guint -gst_asfmux_packet_remaining (GstAsfMux *asfmux) +gst_asfmux_packet_remaining (GstAsfMux * asfmux) { guint position; @@ -683,12 +680,11 @@ gst_asfmux_packet_remaining (GstAsfMux *asfmux) } static void -gst_asfmux_put_buffer (GstBuffer *packet, - guint8 *data, - guint length) +gst_asfmux_put_buffer (GstBuffer * packet, guint8 * data, guint length) { if ((GST_BUFFER_MAXSIZE (packet) - GST_BUFFER_SIZE (packet)) >= length) { guint8 *pos = GST_BUFFER_DATA (packet) + GST_BUFFER_SIZE (packet); + memcpy (pos, data, length); GST_BUFFER_SIZE (packet) += length; } else { @@ -697,12 +693,12 @@ gst_asfmux_put_buffer (GstBuffer *packet, } static void -gst_asfmux_put_byte (GstBuffer *packet, - guint8 data) +gst_asfmux_put_byte (GstBuffer * packet, guint8 data) { if ((GST_BUFFER_MAXSIZE (packet) - GST_BUFFER_SIZE (packet)) >= sizeof (data)) { guint8 *pos = GST_BUFFER_DATA (packet) + GST_BUFFER_SIZE (packet); - * (guint8 *) pos = data; + + *(guint8 *) pos = data; GST_BUFFER_SIZE (packet) += 1; } else { g_warning ("Buffer too small"); @@ -710,12 +706,12 @@ gst_asfmux_put_byte (GstBuffer *packet, } static void -gst_asfmux_put_le16 (GstBuffer *packet, - guint16 data) +gst_asfmux_put_le16 (GstBuffer * packet, guint16 data) { if ((GST_BUFFER_MAXSIZE (packet) - GST_BUFFER_SIZE (packet)) >= sizeof (data)) { guint8 *pos = GST_BUFFER_DATA (packet) + GST_BUFFER_SIZE (packet); - * (guint16 *) pos = GUINT16_TO_LE (data); + + *(guint16 *) pos = GUINT16_TO_LE (data); GST_BUFFER_SIZE (packet) += 2; } else { g_warning ("Buffer too small"); @@ -723,12 +719,12 @@ gst_asfmux_put_le16 (GstBuffer *packet, } static void -gst_asfmux_put_le32 (GstBuffer *packet, - guint32 data) +gst_asfmux_put_le32 (GstBuffer * packet, guint32 data) { if ((GST_BUFFER_MAXSIZE (packet) - GST_BUFFER_SIZE (packet)) >= sizeof (data)) { guint8 *pos = GST_BUFFER_DATA (packet) + GST_BUFFER_SIZE (packet); - * (guint32 *) pos = GUINT32_TO_LE (data); + + *(guint32 *) pos = GUINT32_TO_LE (data); GST_BUFFER_SIZE (packet) += 4; } else { g_warning ("Buffer too small"); @@ -736,12 +732,12 @@ gst_asfmux_put_le32 (GstBuffer *packet, } static void -gst_asfmux_put_le64 (GstBuffer *packet, - guint64 data) +gst_asfmux_put_le64 (GstBuffer * packet, guint64 data) { if ((GST_BUFFER_MAXSIZE (packet) - GST_BUFFER_SIZE (packet)) >= sizeof (data)) { guint8 *pos = GST_BUFFER_DATA (packet) + GST_BUFFER_SIZE (packet); - * (guint64 *) pos = GUINT64_TO_LE (data); + + *(guint64 *) pos = GUINT64_TO_LE (data); GST_BUFFER_SIZE (packet) += 8; } else { g_warning ("Buffer too small"); @@ -749,23 +745,19 @@ gst_asfmux_put_le64 (GstBuffer *packet, } static void -gst_asfmux_put_time (GstBuffer *packet, - guint64 time) +gst_asfmux_put_time (GstBuffer * packet, guint64 time) { gst_asfmux_put_le64 (packet, time + 116444736000000000LLU); } static void -gst_asfmux_put_guid (GstBuffer *packet, - ASFGuidHash *hash, - guint8 id) +gst_asfmux_put_guid (GstBuffer * packet, ASFGuidHash * hash, guint8 id) { gint n = 0; ASFGuid *guid; /* find GUID */ - while (hash[n].obj_id != id && - hash[n].obj_id != ASF_OBJ_UNDEFINED) { + while (hash[n].obj_id != id && hash[n].obj_id != ASF_OBJ_UNDEFINED) { n++; } guid = &hash[n].guid; @@ -777,8 +769,7 @@ gst_asfmux_put_guid (GstBuffer *packet, } static void -gst_asfmux_put_string (GstBuffer *packet, - const gchar *str) +gst_asfmux_put_string (GstBuffer * packet, const gchar * str) { gunichar2 *utf16_str = g_utf8_to_utf16 (str, strlen (str), NULL, NULL, NULL); gint i, len = strlen (str); @@ -792,19 +783,15 @@ gst_asfmux_put_string (GstBuffer *packet, } static void -gst_asfmux_put_flush (GstAsfMux *asfmux) +gst_asfmux_put_flush (GstAsfMux * asfmux) { - gst_pad_push (asfmux->srcpad, - GST_DATA (gst_event_new_flush ())); + gst_pad_push (asfmux->srcpad, GST_DATA (gst_event_new_flush ())); } /* write an asf chunk (only used in streaming case) */ static void -gst_asfmux_put_chunk (GstBuffer *packet, - GstAsfMux *asfmux, - guint16 type, - guint length, - gint flags) +gst_asfmux_put_chunk (GstBuffer * packet, + GstAsfMux * asfmux, guint16 type, guint length, gint flags) { gst_asfmux_put_le16 (packet, type); gst_asfmux_put_le16 (packet, length + 8); @@ -814,8 +801,7 @@ gst_asfmux_put_chunk (GstBuffer *packet, } static void -gst_asfmux_put_wav_header (GstBuffer *packet, - asf_stream_audio *hdr) +gst_asfmux_put_wav_header (GstBuffer * packet, asf_stream_audio * hdr) { gst_asfmux_put_le16 (packet, hdr->codec_tag); gst_asfmux_put_le16 (packet, hdr->channels); @@ -827,8 +813,7 @@ gst_asfmux_put_wav_header (GstBuffer *packet, } static void -gst_asfmux_put_vid_header (GstBuffer *packet, - asf_stream_video *hdr) +gst_asfmux_put_vid_header (GstBuffer * packet, asf_stream_video * hdr) { gst_asfmux_put_le32 (packet, hdr->width); gst_asfmux_put_le32 (packet, hdr->height); @@ -837,8 +822,7 @@ gst_asfmux_put_vid_header (GstBuffer *packet, } static void -gst_asfmux_put_bmp_header (GstBuffer *packet, - asf_stream_video_format *hdr) +gst_asfmux_put_bmp_header (GstBuffer * packet, asf_stream_video_format * hdr) { gst_asfmux_put_le32 (packet, hdr->size); gst_asfmux_put_le32 (packet, hdr->width); @@ -855,11 +839,10 @@ gst_asfmux_put_bmp_header (GstBuffer *packet, /* init header */ static guint -gst_asfmux_put_header (GstBuffer *packet, - ASFGuidHash *hash, - guint8 id) +gst_asfmux_put_header (GstBuffer * packet, ASFGuidHash * hash, guint8 id) { guint pos = GST_BUFFER_SIZE (packet); + gst_asfmux_put_guid (packet, hash, id); gst_asfmux_put_le64 (packet, 24); return pos; @@ -867,19 +850,17 @@ gst_asfmux_put_header (GstBuffer *packet, /* update header size */ static void -gst_asfmux_end_header (GstBuffer *packet, - guint pos) +gst_asfmux_end_header (GstBuffer * packet, guint pos) { guint cur = GST_BUFFER_SIZE (packet); + GST_BUFFER_SIZE (packet) = pos + sizeof (ASFGuid); gst_asfmux_put_le64 (packet, cur - pos); GST_BUFFER_SIZE (packet) = cur; } static void -gst_asfmux_file_start (GstAsfMux *asfmux, - guint64 file_size, - guint64 data_size) +gst_asfmux_file_start (GstAsfMux * asfmux, guint64 file_size, guint64 data_size) { GstBuffer *header = gst_buffer_new_and_alloc (4096); guint bitrate; @@ -890,13 +871,14 @@ gst_asfmux_file_start (GstAsfMux *asfmux, bitrate = 0; for (n = 0; n < asfmux->num_outputs; n++) { GstAsfMuxStream *stream = &asfmux->output[n]; + bitrate += stream->bitrate; } GST_BUFFER_SIZE (header) = 0; if (asfmux->packet != NULL) { duration = GST_BUFFER_DURATION (asfmux->packet) + - GST_BUFFER_TIMESTAMP (asfmux->packet); + GST_BUFFER_TIMESTAMP (asfmux->packet); } else { duration = 0; } @@ -909,10 +891,10 @@ gst_asfmux_file_start (GstAsfMux *asfmux, gst_asfmux_put_guid (header, asf_object_guids, ASF_OBJ_HEADER); /* header length, will be patched after */ gst_asfmux_put_le64 (header, ~0); - /* number of chunks in header */ - gst_asfmux_put_le32 (header, 3 + /*has_title +*/ asfmux->num_outputs); - gst_asfmux_put_byte (header, 1); /* ??? */ - gst_asfmux_put_byte (header, 2); /* ??? */ + /* number of chunks in header */ + gst_asfmux_put_le32 (header, 3 + /*has_title + */ asfmux->num_outputs); + gst_asfmux_put_byte (header, 1); /* ??? */ + gst_asfmux_put_byte (header, 2); /* ??? */ /* file header */ header_offset = GST_BUFFER_SIZE (header); @@ -920,14 +902,14 @@ gst_asfmux_file_start (GstAsfMux *asfmux, gst_asfmux_put_guid (header, asf_object_guids, ASF_OBJ_UNDEFINED); gst_asfmux_put_le64 (header, file_size); gst_asfmux_put_time (header, 0); - gst_asfmux_put_le64 (header, asfmux->num_packets); /* number of packets */ - gst_asfmux_put_le64 (header, duration / (GST_SECOND / 10000000)); /* end time stamp (in 100ns units) */ - gst_asfmux_put_le64 (header, duration / (GST_SECOND / 10000000)); /* duration (in 100ns units) */ - gst_asfmux_put_le64 (header, 0); /* start time stamp */ - gst_asfmux_put_le32 (header, gst_asfmux_can_seek (asfmux) ? 0x02 : 0x01); /* seekable or streamable */ - gst_asfmux_put_le32 (header, GST_ASF_PACKET_SIZE); /* packet size */ - gst_asfmux_put_le32 (header, GST_ASF_PACKET_SIZE); /* packet size */ - gst_asfmux_put_le32 (header, bitrate); /* Nominal data rate in bps */ + gst_asfmux_put_le64 (header, asfmux->num_packets); /* number of packets */ + gst_asfmux_put_le64 (header, duration / (GST_SECOND / 10000000)); /* end time stamp (in 100ns units) */ + gst_asfmux_put_le64 (header, duration / (GST_SECOND / 10000000)); /* duration (in 100ns units) */ + gst_asfmux_put_le64 (header, 0); /* start time stamp */ + gst_asfmux_put_le32 (header, gst_asfmux_can_seek (asfmux) ? 0x02 : 0x01); /* seekable or streamable */ + gst_asfmux_put_le32 (header, GST_ASF_PACKET_SIZE); /* packet size */ + gst_asfmux_put_le32 (header, GST_ASF_PACKET_SIZE); /* packet size */ + gst_asfmux_put_le32 (header, bitrate); /* Nominal data rate in bps */ gst_asfmux_end_header (header, header_pos); /* unknown headers */ @@ -940,12 +922,13 @@ gst_asfmux_file_start (GstAsfMux *asfmux, /* title and other infos */ #if 0 if (has_title) { - header_pos = gst_asfmux_put_header (header, asf_object_guids, ASF_OBJ_COMMENT); - gst_asfmux_put_le16 (header, 2 * (strlen(title) + 1)); - gst_asfmux_put_le16 (header, 2 * (strlen(author) + 1)); - gst_asfmux_put_le16 (header, 2 * (strlen(copyright) + 1)); - gst_asfmux_put_le16 (header, 2 * (strlen(comment) + 1)); - gst_asfmux_put_le16 (header, 0); /* rating */ + header_pos = + gst_asfmux_put_header (header, asf_object_guids, ASF_OBJ_COMMENT); + gst_asfmux_put_le16 (header, 2 * (strlen (title) + 1)); + gst_asfmux_put_le16 (header, 2 * (strlen (author) + 1)); + gst_asfmux_put_le16 (header, 2 * (strlen (copyright) + 1)); + gst_asfmux_put_le16 (header, 2 * (strlen (comment) + 1)); + gst_asfmux_put_le16 (header, 0); /* rating */ gst_asfmux_put_string (header, title); gst_asfmux_put_string (header, author); gst_asfmux_put_string (header, copyright); @@ -960,44 +943,46 @@ gst_asfmux_file_start (GstAsfMux *asfmux, guint obj_size = 0; stream->seqnum = 0; - header_pos = gst_asfmux_put_header (header, asf_object_guids, ASF_OBJ_STREAM); + header_pos = + gst_asfmux_put_header (header, asf_object_guids, ASF_OBJ_STREAM); switch (stream->type) { case ASF_STREAM_AUDIO: - obj_size = 18; - gst_asfmux_put_guid (header, asf_stream_guids, ASF_STREAM_AUDIO); - gst_asfmux_put_guid (header, asf_correction_guids, ASF_CORRECTION_OFF); - break; + obj_size = 18; + gst_asfmux_put_guid (header, asf_stream_guids, ASF_STREAM_AUDIO); + gst_asfmux_put_guid (header, asf_correction_guids, ASF_CORRECTION_OFF); + break; case ASF_STREAM_VIDEO: - obj_size = 11 + 40; - gst_asfmux_put_guid (header, asf_stream_guids, ASF_STREAM_VIDEO); - gst_asfmux_put_guid (header, asf_correction_guids, ASF_CORRECTION_OFF); - break; + obj_size = 11 + 40; + gst_asfmux_put_guid (header, asf_stream_guids, ASF_STREAM_VIDEO); + gst_asfmux_put_guid (header, asf_correction_guids, ASF_CORRECTION_OFF); + break; default: - g_assert (0); + g_assert (0); } - gst_asfmux_put_le64 (header, 0); /* offset */ - gst_asfmux_put_le32 (header, obj_size); /* wav header len */ - gst_asfmux_put_le32 (header, 0); /* additional data len */ - gst_asfmux_put_le16 (header, n + 1); /* stream number */ - gst_asfmux_put_le32 (header, 0); /* ??? */ + gst_asfmux_put_le64 (header, 0); /* offset */ + gst_asfmux_put_le32 (header, obj_size); /* wav header len */ + gst_asfmux_put_le32 (header, 0); /* additional data len */ + gst_asfmux_put_le16 (header, n + 1); /* stream number */ + gst_asfmux_put_le32 (header, 0); /* ??? */ switch (stream->type) { case ASF_STREAM_AUDIO: - gst_asfmux_put_wav_header (header, &stream->header.audio); - break; + gst_asfmux_put_wav_header (header, &stream->header.audio); + break; case ASF_STREAM_VIDEO: - gst_asfmux_put_vid_header (header, &stream->header.video.stream); - gst_asfmux_put_bmp_header (header, &stream->header.video.format); - break; + gst_asfmux_put_vid_header (header, &stream->header.video.stream); + gst_asfmux_put_bmp_header (header, &stream->header.video.format); + break; } gst_asfmux_end_header (header, header_pos); } /* media comments */ - header_pos = gst_asfmux_put_header (header, asf_object_guids, ASF_OBJ_CODEC_COMMENT); + header_pos = + gst_asfmux_put_header (header, asf_object_guids, ASF_OBJ_CODEC_COMMENT); gst_asfmux_put_guid (header, asf_object_guids, ASF_OBJ_CODEC_COMMENT1); gst_asfmux_put_le32 (header, asfmux->num_outputs); for (n = 0; n < asfmux->num_outputs; n++) { @@ -1008,20 +993,20 @@ gst_asfmux_file_start (GstAsfMux *asfmux, /* Isn't this wrong? This is UTF16! */ gst_asfmux_put_le16 (header, strlen (codec) + 1); gst_asfmux_put_string (header, codec); - gst_asfmux_put_le16 (header, 0); /* no parameters */ + gst_asfmux_put_le16 (header, 0); /* no parameters */ /* id */ switch (stream->type) { case ASF_STREAM_AUDIO: - gst_asfmux_put_le16 (header, 2); - gst_asfmux_put_le16 (header, stream->header.audio.codec_tag); - break; + gst_asfmux_put_le16 (header, 2); + gst_asfmux_put_le16 (header, stream->header.audio.codec_tag); + break; case ASF_STREAM_VIDEO: - gst_asfmux_put_le16 (header, 4); - gst_asfmux_put_le32 (header, stream->header.video.format.tag); - break; + gst_asfmux_put_le16 (header, 4); + gst_asfmux_put_le32 (header, stream->header.video.format.tag); + break; default: - g_assert (0); + g_assert (0); } } gst_asfmux_end_header (header, header_pos); @@ -1049,34 +1034,36 @@ gst_asfmux_file_start (GstAsfMux *asfmux, gst_asfmux_put_guid (header, asf_object_guids, ASF_OBJ_DATA); gst_asfmux_put_le64 (header, data_size); gst_asfmux_put_guid (header, asf_object_guids, ASF_OBJ_UNDEFINED); - gst_asfmux_put_le64 (header, asfmux->num_packets); /* nb packets */ - gst_asfmux_put_byte (header, 1); /* ??? */ - gst_asfmux_put_byte (header, 1); /* ??? */ + gst_asfmux_put_le64 (header, asfmux->num_packets); /* nb packets */ + gst_asfmux_put_byte (header, 1); /* ??? */ + gst_asfmux_put_byte (header, 1); /* ??? */ gst_pad_push (asfmux->srcpad, GST_DATA (header)); asfmux->write_header = FALSE; } static void -gst_asfmux_file_stop (GstAsfMux *asfmux) +gst_asfmux_file_stop (GstAsfMux * asfmux) { if (gst_asfmux_is_stream (asfmux)) { /* send EOS chunk */ GstBuffer *footer = gst_buffer_new_and_alloc (16); + GST_BUFFER_SIZE (footer) = 0; - gst_asfmux_put_chunk (footer, asfmux, 0x4524, 0, 0); /* end of stream */ + gst_asfmux_put_chunk (footer, asfmux, 0x4524, 0, 0); /* end of stream */ gst_pad_push (asfmux->srcpad, GST_DATA (footer)); } else if (gst_asfmux_can_seek (asfmux)) { /* rewrite an updated header */ guint64 filesize; GstFormat fmt = GST_FORMAT_BYTES; GstEvent *event; - gst_pad_query (asfmux->srcpad, GST_QUERY_POSITION, - &fmt, &filesize); + + gst_pad_query (asfmux->srcpad, GST_QUERY_POSITION, &fmt, &filesize); event = gst_event_new_seek (GST_SEEK_METHOD_SET | GST_FORMAT_BYTES, 0); gst_pad_push (asfmux->srcpad, GST_DATA (event)); gst_asfmux_file_start (asfmux, filesize, filesize - asfmux->data_offset); - event = gst_event_new_seek (GST_SEEK_METHOD_SET | GST_FORMAT_BYTES, filesize); + event = + gst_event_new_seek (GST_SEEK_METHOD_SET | GST_FORMAT_BYTES, filesize); gst_pad_push (asfmux->srcpad, GST_DATA (event)); } @@ -1084,7 +1071,7 @@ gst_asfmux_file_stop (GstAsfMux *asfmux) } static GstBuffer * -gst_asfmux_packet_header (GstAsfMux *asfmux) +gst_asfmux_packet_header (GstAsfMux * asfmux) { GstBuffer *packet = asfmux->packet, *header; guint flags, padsize = gst_asfmux_packet_remaining (asfmux); @@ -1099,7 +1086,7 @@ gst_asfmux_packet_header (GstAsfMux *asfmux) gst_asfmux_put_byte (header, 0x82); gst_asfmux_put_le16 (header, 0); - flags = 0x01; /* nb segments present */ + flags = 0x01; /* nb segments present */ if (padsize > 0) { if (padsize < 256) { flags |= 0x08; @@ -1107,56 +1094,52 @@ gst_asfmux_packet_header (GstAsfMux *asfmux) flags |= 0x10; } } - gst_asfmux_put_byte (header, flags); /* flags */ + gst_asfmux_put_byte (header, flags); /* flags */ gst_asfmux_put_byte (header, 0x5d); if (flags & 0x10) { gst_asfmux_put_le16 (header, padsize - 2); } else if (flags & 0x08) { gst_asfmux_put_byte (header, padsize - 1); } - gst_asfmux_put_le32 (header, GST_BUFFER_TIMESTAMP (packet) / (GST_SECOND/1000)); - gst_asfmux_put_le16 (header, GST_BUFFER_DURATION (packet) / (GST_SECOND/1000)); + gst_asfmux_put_le32 (header, + GST_BUFFER_TIMESTAMP (packet) / (GST_SECOND / 1000)); + gst_asfmux_put_le16 (header, + GST_BUFFER_DURATION (packet) / (GST_SECOND / 1000)); gst_asfmux_put_byte (header, asfmux->packet_frames | 0x80); return header; } static void -gst_asfmux_frame_header (GstAsfMux *asfmux, - GstAsfMuxStream *stream, - guint position, - guint length, - guint total, - guint64 time, - gboolean key) +gst_asfmux_frame_header (GstAsfMux * asfmux, + GstAsfMuxStream * stream, + guint position, guint length, guint total, guint64 time, gboolean key) { /* fill in some values for the packet */ if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (asfmux->packet))) { GST_BUFFER_TIMESTAMP (asfmux->packet) = time; } GST_BUFFER_DURATION (asfmux->packet) = - time - GST_BUFFER_TIMESTAMP (asfmux->packet); + time - GST_BUFFER_TIMESTAMP (asfmux->packet); - gst_asfmux_put_byte (asfmux->packet, (stream->index + 1) | 0x80); //(key ? 0x80 : 0)); + gst_asfmux_put_byte (asfmux->packet, (stream->index + 1) | 0x80); //(key ? 0x80 : 0)); gst_asfmux_put_byte (asfmux->packet, stream->seqnum); gst_asfmux_put_le32 (asfmux->packet, position); gst_asfmux_put_byte (asfmux->packet, 0x08); gst_asfmux_put_le32 (asfmux->packet, total); - gst_asfmux_put_le32 (asfmux->packet, time / (GST_SECOND/1000)); /* time in ms */ + gst_asfmux_put_le32 (asfmux->packet, time / (GST_SECOND / 1000)); /* time in ms */ gst_asfmux_put_le16 (asfmux->packet, length); } static void -gst_asfmux_frame_buffer (GstAsfMux *asfmux, - guint8 *data, - guint length) +gst_asfmux_frame_buffer (GstAsfMux * asfmux, guint8 * data, guint length) { gst_asfmux_put_buffer (asfmux->packet, data, length); asfmux->packet_frames++; } static void -gst_asfmux_packet_flush (GstAsfMux *asfmux) +gst_asfmux_packet_flush (GstAsfMux * asfmux) { GstBuffer *header, *packet = asfmux->packet; guint header_size; @@ -1165,12 +1148,12 @@ gst_asfmux_packet_flush (GstAsfMux *asfmux) header = gst_asfmux_packet_header (asfmux); header_size = GST_BUFFER_SIZE (header); if (!gst_asfmux_can_seek (asfmux)) { - header_size -= 12; /* hack... bah */ + header_size -= 12; /* hack... bah */ } /* Clear out the padding bytes */ memset (GST_BUFFER_DATA (packet) + GST_BUFFER_SIZE (packet), 0, - GST_BUFFER_MAXSIZE (packet) - GST_BUFFER_SIZE (packet)); + GST_BUFFER_MAXSIZE (packet) - GST_BUFFER_SIZE (packet)); GST_BUFFER_SIZE (packet) = GST_ASF_PACKET_SIZE - header_size; /* send packet over */ @@ -1185,9 +1168,8 @@ gst_asfmux_packet_flush (GstAsfMux *asfmux) } static void -gst_asfmux_write_buffer (GstAsfMux *asfmux, - GstAsfMuxStream *stream, - GstBuffer *buffer) +gst_asfmux_write_buffer (GstAsfMux * asfmux, + GstAsfMuxStream * stream, GstBuffer * buffer) { guint position = 0, to_write, size = GST_BUFFER_SIZE (buffer), remaining; @@ -1210,9 +1192,10 @@ gst_asfmux_write_buffer (GstAsfMux *asfmux, /* write frame header plus data in this packet */ gst_asfmux_frame_header (asfmux, stream, position, to_write, size, - GST_BUFFER_TIMESTAMP (buffer), - GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_KEY_UNIT)); - gst_asfmux_frame_buffer (asfmux, GST_BUFFER_DATA (buffer) + position, to_write); + GST_BUFFER_TIMESTAMP (buffer), + GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_KEY_UNIT)); + gst_asfmux_frame_buffer (asfmux, GST_BUFFER_DATA (buffer) + position, + to_write); position += to_write; } @@ -1222,7 +1205,7 @@ gst_asfmux_write_buffer (GstAsfMux *asfmux, /* take the oldest buffer in our internal queue and push-it */ static gboolean -gst_asfmux_do_one_buffer (GstAsfMux *asfmux) +gst_asfmux_do_one_buffer (GstAsfMux * asfmux) { gint n, chosen = -1; @@ -1230,9 +1213,9 @@ gst_asfmux_do_one_buffer (GstAsfMux *asfmux) for (n = 0; n < asfmux->num_outputs; n++) { if (asfmux->output[n].queue != NULL) { if (chosen == -1 || - GST_BUFFER_TIMESTAMP (asfmux->output[n].queue) < - GST_BUFFER_TIMESTAMP (asfmux->output[chosen].queue)) { - chosen = n; + GST_BUFFER_TIMESTAMP (asfmux->output[n].queue) < + GST_BUFFER_TIMESTAMP (asfmux->output[chosen].queue)) { + chosen = n; } } } @@ -1240,26 +1223,26 @@ gst_asfmux_do_one_buffer (GstAsfMux *asfmux) if (chosen == -1) { /* simply finish off the file and send EOS */ gst_asfmux_file_stop (asfmux); - gst_pad_push (asfmux->srcpad, - GST_DATA (gst_event_new (GST_EVENT_EOS))); - gst_element_set_eos (GST_ELEMENT(asfmux)); + gst_pad_push (asfmux->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS))); + gst_element_set_eos (GST_ELEMENT (asfmux)); return FALSE; } /* do this buffer */ gst_asfmux_write_buffer (asfmux, &asfmux->output[chosen], - asfmux->output[chosen].queue); + asfmux->output[chosen].queue); /* update stream info after buffer push */ gst_buffer_unref (asfmux->output[chosen].queue); - asfmux->output[chosen].time = GST_BUFFER_TIMESTAMP (asfmux->output[chosen].queue); + asfmux->output[chosen].time = + GST_BUFFER_TIMESTAMP (asfmux->output[chosen].queue); asfmux->output[chosen].queue = NULL; return TRUE; } static void -gst_asfmux_loop (GstElement *element) +gst_asfmux_loop (GstElement * element) { GstAsfMux *asfmux; @@ -1268,7 +1251,7 @@ gst_asfmux_loop (GstElement *element) /* first fill queue (some elements only set caps when * flowing data), then write header */ gst_asfmux_fill_queue (asfmux); - + if (asfmux->write_header == TRUE) { /* indeed, these are fake values. We need this so that * players will read the file. Without these fake values, @@ -1280,19 +1263,19 @@ gst_asfmux_loop (GstElement *element) } static GstElementStateReturn -gst_asfmux_change_state (GstElement *element) +gst_asfmux_change_state (GstElement * element) { GstAsfMux *asfmux; gint transition = GST_STATE_TRANSITION (element), n; g_return_val_if_fail (GST_IS_ASFMUX (element), GST_STATE_FAILURE); - + asfmux = GST_ASFMUX (element); switch (transition) { case GST_STATE_PAUSED_TO_PLAYING: for (n = 0; n < asfmux->num_outputs; n++) { - asfmux->output[n].eos = FALSE; + asfmux->output[n].eos = FALSE; } break; } diff --git a/gst/asfdemux/gstasfmux.h b/gst/asfdemux/gstasfmux.h index 115261abc1..2a95ba17da 100644 --- a/gst/asfdemux/gstasfmux.h +++ b/gst/asfdemux/gstasfmux.h @@ -24,8 +24,9 @@ #include "asfheaders.h" #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_ASFMUX \ (gst_asfmux_get_type()) @@ -40,50 +41,55 @@ extern "C" { #define MAX_ASF_OUTPUTS 16 -typedef struct _GstAsfMuxStream { - guint index; + typedef struct _GstAsfMuxStream + { + guint index; - gint type; /* ASF_STREAM_VIDEO/AUDIO */ - GstPad *pad; - guint64 time; - GstBuffer *queue; - gboolean connected, eos; - guint seqnum; - guint bitrate; + gint type; /* ASF_STREAM_VIDEO/AUDIO */ + GstPad *pad; + guint64 time; + GstBuffer *queue; + gboolean connected, eos; + guint seqnum; + guint bitrate; - union { - asf_stream_audio audio; - struct { - asf_stream_video stream; - asf_stream_video_format format; - } video; - } header; -} GstAsfMuxStream; + union + { + asf_stream_audio audio; + struct + { + asf_stream_video stream; + asf_stream_video_format format; + } video; + } header; + } GstAsfMuxStream; -typedef struct _GstAsfMux { - GstElement element; + typedef struct _GstAsfMux + { + GstElement element; - /* pads */ - GstPad *srcpad; - GstAsfMuxStream output[MAX_ASF_OUTPUTS]; - guint num_outputs, num_video, num_audio; - gboolean write_header; + /* pads */ + GstPad *srcpad; + GstAsfMuxStream output[MAX_ASF_OUTPUTS]; + guint num_outputs, num_video, num_audio; + gboolean write_header; - /* packet */ - GstBuffer *packet; - guint num_packets, packet_frames; - guint sequence; - guint64 data_offset; -} GstAsfMux; + /* packet */ + GstBuffer *packet; + guint num_packets, packet_frames; + guint sequence; + guint64 data_offset; + } GstAsfMux; -typedef struct _GstAsfMuxClass { - GstElementClass parent_class; -} GstAsfMuxClass; + typedef struct _GstAsfMuxClass + { + GstElementClass parent_class; + } GstAsfMuxClass; -GType gst_asfmux_get_type(void); + GType gst_asfmux_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_ASFMUX_H__ */ +#endif /* __GST_ASFMUX_H__ */ diff --git a/gst/mpegaudioparse/gstmpegaudioparse.c b/gst/mpegaudioparse/gstmpegaudioparse.c index aeed48f137..1e77bf42f9 100644 --- a/gst/mpegaudioparse/gstmpegaudioparse.c +++ b/gst/mpegaudioparse/gstmpegaudioparse.c @@ -32,35 +32,30 @@ static GstElementDetails mp3parse_details = { "Erik Walthinsen " }; -static GstStaticPadTemplate mp3_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", +static GstStaticPadTemplate mp3_src_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/mpeg, " - "mpegversion = (int) 1, " - "layer = (int) [ 1, 3 ], " - "rate = (int) [ 8000, 48000], " - "channels = (int) [ 1, 2 ]") -); + "mpegversion = (int) 1, " + "layer = (int) [ 1, 3 ], " + "rate = (int) [ 8000, 48000], " "channels = (int) [ 1, 2 ]") + ); -static GstStaticPadTemplate mp3_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", +static GstStaticPadTemplate mp3_sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/mpeg, " - "mpegversion = (int) 1" - ) -); + GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 1") + ); /* GstMPEGAudioParse signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_SKIP, ARG_BIT_RATE, @@ -68,63 +63,64 @@ enum { }; -static void gst_mp3parse_class_init (GstMPEGAudioParseClass *klass); -static void gst_mp3parse_base_init (GstMPEGAudioParseClass *klass); -static void gst_mp3parse_init (GstMPEGAudioParse *mp3parse); +static void gst_mp3parse_class_init (GstMPEGAudioParseClass * klass); +static void gst_mp3parse_base_init (GstMPEGAudioParseClass * klass); +static void gst_mp3parse_init (GstMPEGAudioParse * mp3parse); -static void gst_mp3parse_chain (GstPad *pad,GstData *_data); -static long bpf_from_header (GstMPEGAudioParse *parse, unsigned long header); -static int head_check (unsigned long head); +static void gst_mp3parse_chain (GstPad * pad, GstData * _data); +static long bpf_from_header (GstMPEGAudioParse * parse, unsigned long header); +static int head_check (unsigned long head); -static void gst_mp3parse_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_mp3parse_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static GstElementStateReturn - gst_mp3parse_change_state (GstElement *element); +static void gst_mp3parse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_mp3parse_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static GstElementStateReturn gst_mp3parse_change_state (GstElement * element); static GstElementClass *parent_class = NULL; + /*static guint gst_mp3parse_signals[LAST_SIGNAL] = { 0 }; */ GType -gst_mp3parse_get_type(void) { +gst_mp3parse_get_type (void) +{ static GType mp3parse_type = 0; if (!mp3parse_type) { static const GTypeInfo mp3parse_info = { - sizeof(GstMPEGAudioParseClass), - (GBaseInitFunc)gst_mp3parse_base_init, + sizeof (GstMPEGAudioParseClass), + (GBaseInitFunc) gst_mp3parse_base_init, NULL, - (GClassInitFunc)gst_mp3parse_class_init, + (GClassInitFunc) gst_mp3parse_class_init, NULL, NULL, - sizeof(GstMPEGAudioParse), + sizeof (GstMPEGAudioParse), 0, - (GInstanceInitFunc)gst_mp3parse_init, + (GInstanceInitFunc) gst_mp3parse_init, }; mp3parse_type = g_type_register_static (GST_TYPE_ELEMENT, - "GstMPEGAudioParse", - &mp3parse_info, 0); + "GstMPEGAudioParse", &mp3parse_info, 0); } return mp3parse_type; } static guint mp3types_bitrates[2][3][16] = -{ { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, }, - {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, }, - {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, } }, - { {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, }, - {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, }, - {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, } }, + { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,}, + {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,}, + {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}}, +{{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,}, + {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}, + {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}}, }; -static guint mp3types_freqs[3][3] = -{ {44100, 48000, 32000}, - {22050, 24000, 16000}, - {11025, 12000, 8000}}; +static guint mp3types_freqs[3][3] = { {44100, 48000, 32000}, +{22050, 24000, 16000}, +{11025, 12000, 8000} +}; static inline guint -mp3_type_frame_length_from_header (guint32 header, guint *put_layer, - guint *put_channels, guint *put_bitrate, - guint *put_samplerate) +mp3_type_frame_length_from_header (guint32 header, guint * put_layer, + guint * put_channels, guint * put_bitrate, guint * put_samplerate) { guint length; gulong mode, samplerate, bitrate, layer, channels, padding; @@ -163,7 +159,7 @@ mp3_type_frame_length_from_header (guint32 header, guint *put_layer, GST_DEBUG ("Calculated mp3 frame length of %u bytes", length); GST_DEBUG ("samplerate = %lu, bitrate = %lu, layer = %lu, channels = %lu", - samplerate, bitrate, layer, channels); + samplerate, bitrate, layer, channels); if (put_layer) *put_layer = layer; @@ -204,8 +200,7 @@ mp3_type_frame_length_from_header (guint32 header, guint *put_layer, #define GST_MP3_TYPEFIND_MIN_DATA (1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3) static GstCaps * -mp3_caps_create (guint layer, guint channels, - guint bitrate, guint samplerate) +mp3_caps_create (guint layer, guint channels, guint bitrate, guint samplerate) { GstCaps *new; @@ -216,15 +211,14 @@ mp3_caps_create (guint layer, guint channels, new = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1, - "layer", G_TYPE_INT, layer, - "rate", G_TYPE_INT, samplerate, - "channels", G_TYPE_INT, channels, NULL); + "layer", G_TYPE_INT, layer, + "rate", G_TYPE_INT, samplerate, "channels", G_TYPE_INT, channels, NULL); return new; } static void -gst_mp3parse_base_init (GstMPEGAudioParseClass *klass) +gst_mp3parse_base_init (GstMPEGAudioParseClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); @@ -236,22 +230,18 @@ gst_mp3parse_base_init (GstMPEGAudioParseClass *klass) } static void -gst_mp3parse_class_init (GstMPEGAudioParseClass *klass) +gst_mp3parse_class_init (GstMPEGAudioParseClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SKIP, - g_param_spec_int("skip","skip","skip", - G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BIT_RATE, - g_param_spec_int("bitrate","Bitrate","Bit Rate", - G_MININT,G_MAXINT,0,G_PARAM_READABLE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SKIP, g_param_spec_int ("skip", "skip", "skip", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BIT_RATE, g_param_spec_int ("bitrate", "Bitrate", "Bit Rate", G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gobject_class->set_property = gst_mp3parse_set_property; gobject_class->get_property = gst_mp3parse_get_property; @@ -260,18 +250,20 @@ gst_mp3parse_class_init (GstMPEGAudioParseClass *klass) } static void -gst_mp3parse_init (GstMPEGAudioParse *mp3parse) +gst_mp3parse_init (GstMPEGAudioParse * mp3parse) { - mp3parse->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&mp3_sink_template), "sink"); - gst_element_add_pad(GST_ELEMENT(mp3parse),mp3parse->sinkpad); + mp3parse->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&mp3_sink_template), "sink"); + gst_element_add_pad (GST_ELEMENT (mp3parse), mp3parse->sinkpad); - gst_pad_set_chain_function(mp3parse->sinkpad,gst_mp3parse_chain); - gst_element_set_loop_function (GST_ELEMENT(mp3parse),NULL); + gst_pad_set_chain_function (mp3parse->sinkpad, gst_mp3parse_chain); + gst_element_set_loop_function (GST_ELEMENT (mp3parse), NULL); - mp3parse->srcpad = gst_pad_new_from_template( - gst_static_pad_template_get (&mp3_src_template), "src"); - gst_element_add_pad(GST_ELEMENT(mp3parse),mp3parse->srcpad); + mp3parse->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&mp3_src_template), "src"); + gst_element_add_pad (GST_ELEMENT (mp3parse), mp3parse->srcpad); gst_pad_use_explicit_caps (mp3parse->srcpad); /*gst_pad_set_type_id(mp3parse->srcpad, mp3frametype); */ @@ -283,71 +275,71 @@ gst_mp3parse_init (GstMPEGAudioParse *mp3parse) } static void -gst_mp3parse_chain (GstPad *pad, GstData *_data) +gst_mp3parse_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstMPEGAudioParse *mp3parse; guchar *data; - glong size,offset = 0; + glong size, offset = 0; guint32 header; int bpf; GstBuffer *outbuf; guint64 last_ts; - g_return_if_fail(pad != NULL); - g_return_if_fail(GST_IS_PAD(pad)); - g_return_if_fail(buf != NULL); + g_return_if_fail (pad != NULL); + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (buf != NULL); /* g_return_if_fail(GST_IS_BUFFER(buf)); */ mp3parse = GST_MP3PARSE (gst_pad_get_parent (pad)); - GST_DEBUG ("mp3parse: received buffer of %d bytes",GST_BUFFER_SIZE(buf)); + GST_DEBUG ("mp3parse: received buffer of %d bytes", GST_BUFFER_SIZE (buf)); - last_ts = GST_BUFFER_TIMESTAMP(buf); + last_ts = GST_BUFFER_TIMESTAMP (buf); /* FIXME, do flush */ /* - if (mp3parse->partialbuf) { - gst_buffer_unref(mp3parse->partialbuf); - mp3parse->partialbuf = NULL; - } - mp3parse->in_flush = TRUE; - */ + if (mp3parse->partialbuf) { + gst_buffer_unref(mp3parse->partialbuf); + mp3parse->partialbuf = NULL; + } + mp3parse->in_flush = TRUE; + */ /* if we have something left from the previous frame */ if (mp3parse->partialbuf) { GstBuffer *newbuf; - newbuf = gst_buffer_merge(mp3parse->partialbuf, buf); + newbuf = gst_buffer_merge (mp3parse->partialbuf, buf); /* and the one we received.. */ - gst_buffer_unref(buf); - gst_buffer_unref(mp3parse->partialbuf); + gst_buffer_unref (buf); + gst_buffer_unref (mp3parse->partialbuf); mp3parse->partialbuf = newbuf; - } - else { + } else { mp3parse->partialbuf = buf; } - size = GST_BUFFER_SIZE(mp3parse->partialbuf); - data = GST_BUFFER_DATA(mp3parse->partialbuf); + size = GST_BUFFER_SIZE (mp3parse->partialbuf); + data = GST_BUFFER_DATA (mp3parse->partialbuf); /* while we still have bytes left -4 for the header */ - while (offset < size-4) { + while (offset < size - 4) { int skipped = 0; - GST_DEBUG ("mp3parse: offset %ld, size %ld ",offset, size); + GST_DEBUG ("mp3parse: offset %ld, size %ld ", offset, size); /* search for a possible start byte */ - for (;((data[offset] != 0xff) && (offset < size));offset++) skipped++; + for (; ((data[offset] != 0xff) && (offset < size)); offset++) + skipped++; if (skipped && !mp3parse->in_flush) { - GST_DEBUG ("mp3parse: **** now at %ld skipped %d bytes",offset,skipped); + GST_DEBUG ("mp3parse: **** now at %ld skipped %d bytes", offset, skipped); } /* construct the header word */ - header = GUINT32_FROM_BE(*((guint32 *)(data+offset))); + header = GUINT32_FROM_BE (*((guint32 *) (data + offset))); /* if it's a valid header, go ahead and send off the frame */ - if (head_check(header)) { + if (head_check (header)) { /* calculate the bpf of the frame */ - bpf = bpf_from_header(mp3parse, header); + bpf = bpf_from_header (mp3parse, header); /******************************************************************************** * robust seek support @@ -361,107 +353,116 @@ gst_mp3parse_chain (GstPad *pad, GstData *_data) * from previous frames. In this case, seeking may be more complicated because * the frames are not independently coded. ********************************************************************************/ - if ( mp3parse->in_flush ) { - guint32 header2; + if (mp3parse->in_flush) { + guint32 header2; - if ((size-offset)<(bpf+4)) { if (mp3parse->in_flush) break; } /* wait until we have the the entire current frame as well as the next frame header */ - - header2 = GUINT32_FROM_BE(*((guint32 *)(data+offset+bpf))); - GST_DEBUG ("mp3parse: header=%08X, header2=%08X, bpf=%d", (unsigned int)header, (unsigned int)header2, bpf ); + if ((size - offset) < (bpf + 4)) { + if (mp3parse->in_flush) + break; + } + /* wait until we have the the entire current frame as well as the next frame header */ + header2 = GUINT32_FROM_BE (*((guint32 *) (data + offset + bpf))); + GST_DEBUG ("mp3parse: header=%08X, header2=%08X, bpf=%d", + (unsigned int) header, (unsigned int) header2, bpf); /* mask the bits which are allowed to differ between frames */ #define HDRMASK ~((0xF << 12) /* bitrate */ | \ (0x1 << 9) /* padding */ | \ - (0x3 << 4)) /*mode extension*/ + (0x3 << 4)) /*mode extension */ - if ( (header2&HDRMASK) != (header&HDRMASK) ) { /* require 2 matching headers in a row */ - GST_DEBUG ("mp3parse: next header doesn't match (header=%08X, header2=%08X, bpf=%d)", (unsigned int)header, (unsigned int)header2, bpf ); - offset++; /* This frame is invalid. Start looking for a valid frame at the next position in the stream */ - continue; - } + if ((header2 & HDRMASK) != (header & HDRMASK)) { /* require 2 matching headers in a row */ + GST_DEBUG + ("mp3parse: next header doesn't match (header=%08X, header2=%08X, bpf=%d)", + (unsigned int) header, (unsigned int) header2, bpf); + offset++; /* This frame is invalid. Start looking for a valid frame at the next position in the stream */ + continue; + } } /* if we don't have the whole frame... */ if ((size - offset) < bpf) { - GST_DEBUG ("mp3parse: partial buffer needed %ld < %d ",(size-offset), bpf); + GST_DEBUG ("mp3parse: partial buffer needed %ld < %d ", (size - offset), + bpf); break; } else { - guint bitrate, layer, rate, channels; + guint bitrate, layer, rate, channels; - if (!mp3_type_frame_length_from_header (header, &layer, - &channels, - &bitrate, &rate)) { - g_error("Header failed internal error"); - } - if (channels != mp3parse->channels || - rate != mp3parse->rate || - layer != mp3parse->layer || - bitrate != mp3parse->bit_rate) { - GstCaps *caps = mp3_caps_create (layer, channels, bitrate, rate); + if (!mp3_type_frame_length_from_header (header, &layer, + &channels, &bitrate, &rate)) { + g_error ("Header failed internal error"); + } + if (channels != mp3parse->channels || + rate != mp3parse->rate || + layer != mp3parse->layer || bitrate != mp3parse->bit_rate) { + GstCaps *caps = mp3_caps_create (layer, channels, bitrate, rate); - gst_pad_set_explicit_caps(mp3parse->srcpad, caps); + gst_pad_set_explicit_caps (mp3parse->srcpad, caps); - mp3parse->channels = channels; - mp3parse->layer = layer; - mp3parse->rate = rate; - mp3parse->bit_rate = bitrate; - } + mp3parse->channels = channels; + mp3parse->layer = layer; + mp3parse->rate = rate; + mp3parse->bit_rate = bitrate; + } - outbuf = gst_buffer_create_sub(mp3parse->partialbuf,offset,bpf); + outbuf = gst_buffer_create_sub (mp3parse->partialbuf, offset, bpf); - offset += bpf; + offset += bpf; if (mp3parse->skip == 0) { - GST_DEBUG ("mp3parse: pushing buffer of %d bytes",GST_BUFFER_SIZE(outbuf)); + GST_DEBUG ("mp3parse: pushing buffer of %d bytes", + GST_BUFFER_SIZE (outbuf)); if (mp3parse->in_flush) { /* FIXME do some sort of flush event */ mp3parse->in_flush = FALSE; } - GST_BUFFER_TIMESTAMP(outbuf) = last_ts; - GST_BUFFER_DURATION(outbuf) = 8 * (GST_SECOND/1000) * GST_BUFFER_SIZE(outbuf) / mp3parse->bit_rate; + GST_BUFFER_TIMESTAMP (outbuf) = last_ts; + GST_BUFFER_DURATION (outbuf) = + 8 * (GST_SECOND / 1000) * GST_BUFFER_SIZE (outbuf) / + mp3parse->bit_rate; - if (GST_PAD_CAPS (mp3parse->srcpad) != NULL) { - gst_pad_push(mp3parse->srcpad,GST_DATA (outbuf)); - } else { - GST_DEBUG ("No capsnego yet, delaying buffer push"); - gst_buffer_unref (outbuf); - } - } - else { - GST_DEBUG ("mp3parse: skipping buffer of %d bytes",GST_BUFFER_SIZE(outbuf)); - gst_buffer_unref(outbuf); + if (GST_PAD_CAPS (mp3parse->srcpad) != NULL) { + gst_pad_push (mp3parse->srcpad, GST_DATA (outbuf)); + } else { + GST_DEBUG ("No capsnego yet, delaying buffer push"); + gst_buffer_unref (outbuf); + } + } else { + GST_DEBUG ("mp3parse: skipping buffer of %d bytes", + GST_BUFFER_SIZE (outbuf)); + gst_buffer_unref (outbuf); mp3parse->skip--; } } } else { offset++; - if (!mp3parse->in_flush) GST_DEBUG ("mp3parse: *** wrong header, skipping byte (FIXME?)"); + if (!mp3parse->in_flush) + GST_DEBUG ("mp3parse: *** wrong header, skipping byte (FIXME?)"); } } /* if we have processed this block and there are still */ /* bytes left not in a partial block, copy them over. */ - if (size-offset > 0) { + if (size - offset > 0) { glong remainder = (size - offset); - GST_DEBUG ("mp3parse: partial buffer needed %ld for trailing bytes",remainder); - outbuf = gst_buffer_create_sub(mp3parse->partialbuf,offset,remainder); - gst_buffer_unref(mp3parse->partialbuf); + GST_DEBUG ("mp3parse: partial buffer needed %ld for trailing bytes", + remainder); + + outbuf = gst_buffer_create_sub (mp3parse->partialbuf, offset, remainder); + gst_buffer_unref (mp3parse->partialbuf); mp3parse->partialbuf = outbuf; - } - else { - gst_buffer_unref(mp3parse->partialbuf); + } else { + gst_buffer_unref (mp3parse->partialbuf); mp3parse->partialbuf = NULL; } } static long -bpf_from_header (GstMPEGAudioParse *parse, unsigned long header) +bpf_from_header (GstMPEGAudioParse * parse, unsigned long header) { guint bitrate, layer, rate, channels, length; if (!(length = mp3_type_frame_length_from_header (header, &layer, - &channels, - &bitrate, &rate))) { + &channels, &bitrate, &rate))) { return 0; } @@ -471,40 +472,57 @@ bpf_from_header (GstMPEGAudioParse *parse, unsigned long header) static gboolean head_check (unsigned long head) { - GST_DEBUG ("checking mp3 header 0x%08lx",head); + GST_DEBUG ("checking mp3 header 0x%08lx", head); /* if it's not a valid sync */ if ((head & 0xffe00000) != 0xffe00000) { - GST_DEBUG ("invalid sync");return FALSE; } + GST_DEBUG ("invalid sync"); + return FALSE; + } /* if it's an invalid MPEG version */ if (((head >> 19) & 3) == 0x1) { - GST_DEBUG ("invalid MPEG version");return FALSE; } + GST_DEBUG ("invalid MPEG version"); + return FALSE; + } /* if it's an invalid layer */ if (!((head >> 17) & 3)) { - GST_DEBUG ("invalid layer");return FALSE; } + GST_DEBUG ("invalid layer"); + return FALSE; + } /* if it's an invalid bitrate */ if (((head >> 12) & 0xf) == 0x0) { - GST_DEBUG ("invalid bitrate");return FALSE; } + GST_DEBUG ("invalid bitrate"); + return FALSE; + } if (((head >> 12) & 0xf) == 0xf) { - GST_DEBUG ("invalid bitrate");return FALSE; } + GST_DEBUG ("invalid bitrate"); + return FALSE; + } /* if it's an invalid samplerate */ if (((head >> 10) & 0x3) == 0x3) { - GST_DEBUG ("invalid samplerate");return FALSE; } - if ((head & 0xffff0000) == 0xfffe0000) { - GST_DEBUG ("invalid sync");return FALSE; } + GST_DEBUG ("invalid samplerate"); + return FALSE; + } + if ((head & 0xffff0000) == 0xfffe0000) { + GST_DEBUG ("invalid sync"); + return FALSE; + } if (head & 0x00000002) { - GST_DEBUG ("invalid emphasis");return FALSE; } + GST_DEBUG ("invalid emphasis"); + return FALSE; + } return TRUE; } static void -gst_mp3parse_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_mp3parse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstMPEGAudioParse *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_MP3PARSE(object)); - src = GST_MP3PARSE(object); + g_return_if_fail (GST_IS_MP3PARSE (object)); + src = GST_MP3PARSE (object); switch (prop_id) { case ARG_SKIP: @@ -516,13 +534,14 @@ gst_mp3parse_set_property (GObject *object, guint prop_id, const GValue *value, } static void -gst_mp3parse_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_mp3parse_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstMPEGAudioParse *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_MP3PARSE(object)); - src = GST_MP3PARSE(object); + g_return_if_fail (GST_IS_MP3PARSE (object)); + src = GST_MP3PARSE (object); switch (prop_id) { case ARG_SKIP: @@ -537,43 +556,39 @@ gst_mp3parse_get_property (GObject *object, guint prop_id, GValue *value, GParam } } -static GstElementStateReturn -gst_mp3parse_change_state (GstElement *element) +static GstElementStateReturn +gst_mp3parse_change_state (GstElement * element) { GstMPEGAudioParse *src; - g_return_val_if_fail(GST_IS_MP3PARSE(element), GST_STATE_FAILURE); - src = GST_MP3PARSE(element); + g_return_val_if_fail (GST_IS_MP3PARSE (element), GST_STATE_FAILURE); + src = GST_MP3PARSE (element); switch (GST_STATE_TRANSITION (element)) { case GST_STATE_PAUSED_TO_READY: - src->channels = -1; src->rate = -1; src->layer = -1; + src->channels = -1; + src->rate = -1; + src->layer = -1; break; default: break; } - if (GST_ELEMENT_CLASS(parent_class)->change_state) - return GST_ELEMENT_CLASS(parent_class)->change_state(element); + if (GST_ELEMENT_CLASS (parent_class)->change_state) + return GST_ELEMENT_CLASS (parent_class)->change_state (element); return GST_STATE_SUCCESS; } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return gst_element_register (plugin, "mp3parse", - GST_RANK_NONE, GST_TYPE_MP3PARSE); + GST_RANK_NONE, GST_TYPE_MP3PARSE); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "mpegaudioparse", - "MPEG-1 layer 1/2/3 audio parser", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mpegaudioparse", + "MPEG-1 layer 1/2/3 audio parser", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/gst/mpegaudioparse/gstmpegaudioparse.h b/gst/mpegaudioparse/gstmpegaudioparse.h index ce8121a032..812a6d56a6 100644 --- a/gst/mpegaudioparse/gstmpegaudioparse.h +++ b/gst/mpegaudioparse/gstmpegaudioparse.h @@ -26,8 +26,9 @@ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_MP3PARSE \ @@ -41,31 +42,33 @@ extern "C" { #define GST_IS_MP3PARSE_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MP3PARSE)) -typedef struct _GstMPEGAudioParse GstMPEGAudioParse; -typedef struct _GstMPEGAudioParseClass GstMPEGAudioParseClass; + typedef struct _GstMPEGAudioParse GstMPEGAudioParse; + typedef struct _GstMPEGAudioParseClass GstMPEGAudioParseClass; -struct _GstMPEGAudioParse { - GstElement element; + struct _GstMPEGAudioParse + { + GstElement element; - GstPad *sinkpad,*srcpad; + GstPad *sinkpad, *srcpad; - GstBuffer *partialbuf; /* previous buffer (if carryover) */ - guint skip; /* number of frames to skip */ - guint bit_rate; - gint channels, rate, layer; - gboolean in_flush; -}; + GstBuffer *partialbuf; /* previous buffer (if carryover) */ + guint skip; /* number of frames to skip */ + guint bit_rate; + gint channels, rate, layer; + gboolean in_flush; + }; -struct _GstMPEGAudioParseClass { - GstElementClass parent_class; -}; + struct _GstMPEGAudioParseClass + { + GstElementClass parent_class; + }; -GType gst_mp3parse_get_type(void); + GType gst_mp3parse_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __MP3PARSE_H__ */ +#endif /* __MP3PARSE_H__ */ diff --git a/gst/mpegstream/gstmpegclock.c b/gst/mpegstream/gstmpegclock.c index bad69a9f2c..2880e941bd 100644 --- a/gst/mpegstream/gstmpegclock.c +++ b/gst/mpegstream/gstmpegclock.c @@ -26,19 +26,20 @@ #include "gstmpegclock.h" -static void gst_mpeg_clock_class_init (GstMPEGClockClass *klass); -static void gst_mpeg_clock_init (GstMPEGClock *clock); +static void gst_mpeg_clock_class_init (GstMPEGClockClass * klass); +static void gst_mpeg_clock_init (GstMPEGClock * clock); -static GstClockTime gst_mpeg_clock_get_internal_time (GstClock *clock); +static GstClockTime gst_mpeg_clock_get_internal_time (GstClock * clock); static GstSystemClockClass *parent_class = NULL; + /* static guint gst_mpeg_clock_signals[LAST_SIGNAL] = { 0 }; */ - + GType gst_mpeg_clock_get_type (void) -{ +{ static GType clock_type = 0; - + if (!clock_type) { static const GTypeInfo clock_info = { sizeof (GstMPEGClockClass), @@ -53,38 +54,40 @@ gst_mpeg_clock_get_type (void) NULL }; clock_type = g_type_register_static (GST_TYPE_SYSTEM_CLOCK, "GstMPEGClock", - &clock_info, 0); + &clock_info, 0); } return clock_type; } static void -gst_mpeg_clock_class_init (GstMPEGClockClass *klass) +gst_mpeg_clock_class_init (GstMPEGClockClass * klass) { GObjectClass *gobject_class; GstObjectClass *gstobject_class; GstClockClass *gstclock_class; - gobject_class = (GObjectClass*) klass; - gstobject_class = (GstObjectClass*) klass; - gstclock_class = (GstClockClass*) klass; + gobject_class = (GObjectClass *) klass; + gstobject_class = (GstObjectClass *) klass; + gstclock_class = (GstClockClass *) klass; parent_class = g_type_class_ref (GST_TYPE_SYSTEM_CLOCK); - gstclock_class->get_internal_time = gst_mpeg_clock_get_internal_time; + gstclock_class->get_internal_time = gst_mpeg_clock_get_internal_time; } static void -gst_mpeg_clock_init (GstMPEGClock *clock) +gst_mpeg_clock_init (GstMPEGClock * clock) { gst_object_set_name (GST_OBJECT (clock), "GstMPEGClock"); } -GstClock* -gst_mpeg_clock_new (gchar *name, GstMPEGClockGetTimeFunc func, gpointer user_data) +GstClock * +gst_mpeg_clock_new (gchar * name, GstMPEGClockGetTimeFunc func, + gpointer user_data) { - GstMPEGClock *mpeg_clock = GST_MPEG_CLOCK (g_object_new (GST_TYPE_MPEG_CLOCK, NULL)); + GstMPEGClock *mpeg_clock = + GST_MPEG_CLOCK (g_object_new (GST_TYPE_MPEG_CLOCK, NULL)); mpeg_clock->func = func; mpeg_clock->user_data = user_data; @@ -93,10 +96,9 @@ gst_mpeg_clock_new (gchar *name, GstMPEGClockGetTimeFunc func, gpointer user_dat } static GstClockTime -gst_mpeg_clock_get_internal_time (GstClock *clock) +gst_mpeg_clock_get_internal_time (GstClock * clock) { GstMPEGClock *mpeg_clock = GST_MPEG_CLOCK (clock); return mpeg_clock->func (clock, mpeg_clock->user_data); } - diff --git a/gst/mpegstream/gstmpegclock.h b/gst/mpegstream/gstmpegclock.h index b7a4ae6fa3..ade19a970f 100644 --- a/gst/mpegstream/gstmpegclock.h +++ b/gst/mpegstream/gstmpegclock.h @@ -27,8 +27,9 @@ #include #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_MPEG_CLOCK \ @@ -42,30 +43,33 @@ extern "C" { #define GST_IS_MPEG_CLOCK_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MPEG_CLOCK)) -typedef struct _GstMPEGClock GstMPEGClock; -typedef struct _GstMPEGClockClass GstMPEGClockClass; + typedef struct _GstMPEGClock GstMPEGClock; + typedef struct _GstMPEGClockClass GstMPEGClockClass; -typedef GstClockTime (*GstMPEGClockGetTimeFunc) (GstClock *clock, gpointer user_data); + typedef GstClockTime (*GstMPEGClockGetTimeFunc) (GstClock * clock, + gpointer user_data); -struct _GstMPEGClock { - GstSystemClock clock; + struct _GstMPEGClock + { + GstSystemClock clock; - GstMPEGClockGetTimeFunc func; - gpointer user_data; -}; + GstMPEGClockGetTimeFunc func; + gpointer user_data; + }; -struct _GstMPEGClockClass { - GstSystemClockClass parent_class; -}; + struct _GstMPEGClockClass + { + GstSystemClockClass parent_class; + }; -GType gst_mpeg_clock_get_type (void); -GstClock* gst_mpeg_clock_new (gchar *name, GstMPEGClockGetTimeFunc func, - gpointer user_data); + GType gst_mpeg_clock_get_type (void); + GstClock *gst_mpeg_clock_new (gchar * name, GstMPEGClockGetTimeFunc func, + gpointer user_data); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_MPEG_CLOCK_H__ */ +#endif /* __GST_MPEG_CLOCK_H__ */ diff --git a/gst/mpegstream/gstmpegdemux.c b/gst/mpegstream/gstmpegdemux.c index 5295f56dd4..de5a76869b 100644 --- a/gst/mpegstream/gstmpegdemux.c +++ b/gst/mpegstream/gstmpegdemux.c @@ -31,120 +31,109 @@ static GstElementDetails mpeg_demux_details = { "MPEG Demuxer", "Codec/Demuxer", "Demultiplexes MPEG1 and MPEG2 System Streams", - "Erik Walthinsen \n" - "Wim Taymans " + "Erik Walthinsen \n" "Wim Taymans " }; /* MPEG2Demux signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_BIT_RATE, ARG_MPEG2, /* FILL ME */ }; -static GstStaticPadTemplate sink_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/mpeg, " - "mpegversion = (int) { 1, 2 }, " - "systemstream = (boolean) TRUE" - ) -); +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/mpeg, " + "mpegversion = (int) { 1, 2 }, " "systemstream = (boolean) TRUE") + ); static GstStaticPadTemplate audio_factory = -GST_STATIC_PAD_TEMPLATE ( - "audio_%02d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS ("audio/mpeg, " - "mpegversion = (int) 1, " - "layer = (int) { 1, 2 }" - ) -); +GST_STATIC_PAD_TEMPLATE ("audio_%02d", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS ("audio/mpeg, " + "mpegversion = (int) 1, " "layer = (int) { 1, 2 }") + ); static GstStaticPadTemplate video_src_factory = -GST_STATIC_PAD_TEMPLATE ( - "video_%02d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS ("video/mpeg, " - "mpegversion = (int) { 1, 2 }, " - "systemstream = (boolean) FALSE" - ) -); +GST_STATIC_PAD_TEMPLATE ("video_%02d", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS ("video/mpeg, " + "mpegversion = (int) { 1, 2 }, " "systemstream = (boolean) FALSE") + ); static GstStaticPadTemplate private1_factory = -GST_STATIC_PAD_TEMPLATE ( - "private_stream_1_%02d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS ("audio/x-ac3") -); +GST_STATIC_PAD_TEMPLATE ("private_stream_1_%02d", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS ("audio/x-ac3") + ); static GstStaticPadTemplate private2_factory = -GST_STATIC_PAD_TEMPLATE ( - "private_stream_2", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS_ANY -); +GST_STATIC_PAD_TEMPLATE ("private_stream_2", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS_ANY); static GstStaticPadTemplate pcm_factory = -GST_STATIC_PAD_TEMPLATE ( - "pcm_stream_%02d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS ("audio/x-raw-int, " - "endianness = (int) BIG_ENDIAN, " - "signed = (boolean) TRUE, " - "width = (int) { 16, 20, 24 }, " - "depth = (int) { 16, 20, 24 }, " - "rate = (int) { 48000, 96000 }, " - "channels = (int) [ 1, 8 ]" - ) -); +GST_STATIC_PAD_TEMPLATE ("pcm_stream_%02d", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) BIG_ENDIAN, " + "signed = (boolean) TRUE, " + "width = (int) { 16, 20, 24 }, " + "depth = (int) { 16, 20, 24 }, " + "rate = (int) { 48000, 96000 }, " "channels = (int) [ 1, 8 ]") + ); static GstStaticPadTemplate subtitle_factory = -GST_STATIC_PAD_TEMPLATE ( - "subtitle_stream_%d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS_ANY -); +GST_STATIC_PAD_TEMPLATE ("subtitle_stream_%d", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS_ANY); -static void gst_mpeg_demux_class_init (GstMPEGDemuxClass *klass); -static void gst_mpeg_demux_base_init (GstMPEGDemuxClass *klass); -static void gst_mpeg_demux_init (GstMPEGDemux *mpeg_demux); +static void gst_mpeg_demux_class_init (GstMPEGDemuxClass * klass); +static void gst_mpeg_demux_base_init (GstMPEGDemuxClass * klass); +static void gst_mpeg_demux_init (GstMPEGDemux * mpeg_demux); -static gboolean gst_mpeg_demux_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer); -static gboolean gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer); -static gboolean gst_mpeg_demux_parse_packet (GstMPEGParse *mpeg_parse, GstBuffer *buffer); -static gboolean gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer); -static void gst_mpeg_demux_send_data (GstMPEGParse *mpeg_parse, - GstData *data, GstClockTime time); +static gboolean gst_mpeg_demux_parse_packhead (GstMPEGParse * mpeg_parse, + GstBuffer * buffer); +static gboolean gst_mpeg_demux_parse_syshead (GstMPEGParse * mpeg_parse, + GstBuffer * buffer); +static gboolean gst_mpeg_demux_parse_packet (GstMPEGParse * mpeg_parse, + GstBuffer * buffer); +static gboolean gst_mpeg_demux_parse_pes (GstMPEGParse * mpeg_parse, + GstBuffer * buffer); +static void gst_mpeg_demux_send_data (GstMPEGParse * mpeg_parse, GstData * data, + GstClockTime time); -static void gst_mpeg_demux_lpcm_set_caps (GstPad *pad, guint8 sample_info); -static void gst_mpeg_demux_dvd_audio_clear (GstMPEGDemux *mpeg_demux, int channel); +static void gst_mpeg_demux_lpcm_set_caps (GstPad * pad, guint8 sample_info); +static void gst_mpeg_demux_dvd_audio_clear (GstMPEGDemux * mpeg_demux, + int channel); -static void gst_mpeg_demux_handle_discont (GstMPEGParse *mpeg_parse); -static gboolean gst_mpeg_demux_handle_src_event (GstPad *pad, GstEvent *event); +static void gst_mpeg_demux_handle_discont (GstMPEGParse * mpeg_parse); +static gboolean gst_mpeg_demux_handle_src_event (GstPad * pad, + GstEvent * event); -const GstFormat* gst_mpeg_demux_get_src_formats (GstPad *pad); -static void gst_mpeg_demux_set_index (GstElement *element, GstIndex *index); -static GstIndex* gst_mpeg_demux_get_index (GstElement *element); +const GstFormat *gst_mpeg_demux_get_src_formats (GstPad * pad); +static void gst_mpeg_demux_set_index (GstElement * element, GstIndex * index); +static GstIndex *gst_mpeg_demux_get_index (GstElement * element); -static GstElementStateReturn - gst_mpeg_demux_change_state (GstElement *element); +static GstElementStateReturn gst_mpeg_demux_change_state (GstElement * element); static GstMPEGParseClass *parent_class = NULL; + /*static guint gst_mpeg_demux_signals[LAST_SIGNAL] = { 0 };*/ GType @@ -154,46 +143,48 @@ mpeg_demux_get_type (void) if (!mpeg_demux_type) { static const GTypeInfo mpeg_demux_info = { - sizeof(GstMPEGDemuxClass), - (GBaseInitFunc)gst_mpeg_demux_base_init, + sizeof (GstMPEGDemuxClass), + (GBaseInitFunc) gst_mpeg_demux_base_init, NULL, - (GClassInitFunc)gst_mpeg_demux_class_init, + (GClassInitFunc) gst_mpeg_demux_class_init, NULL, NULL, - sizeof(GstMPEGDemux), + sizeof (GstMPEGDemux), 0, - (GInstanceInitFunc)gst_mpeg_demux_init, + (GInstanceInitFunc) gst_mpeg_demux_init, }; - mpeg_demux_type = g_type_register_static(GST_TYPE_MPEG_PARSE, "GstMPEGDemux", &mpeg_demux_info, 0); + mpeg_demux_type = + g_type_register_static (GST_TYPE_MPEG_PARSE, "GstMPEGDemux", + &mpeg_demux_info, 0); } return mpeg_demux_type; } static void -gst_mpeg_demux_base_init (GstMPEGDemuxClass *klass) +gst_mpeg_demux_base_init (GstMPEGDemuxClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_factory)); + gst_static_pad_template_get (&sink_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&video_src_factory)); + gst_static_pad_template_get (&video_src_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&private1_factory)); + gst_static_pad_template_get (&private1_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&private2_factory)); + gst_static_pad_template_get (&private2_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&pcm_factory)); + gst_static_pad_template_get (&pcm_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&subtitle_factory)); + gst_static_pad_template_get (&subtitle_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&audio_factory)); + gst_static_pad_template_get (&audio_factory)); gst_element_class_set_details (element_class, &mpeg_demux_details); } static void -gst_mpeg_demux_class_init (GstMPEGDemuxClass *klass) +gst_mpeg_demux_class_init (GstMPEGDemuxClass * klass) { GstMPEGParseClass *mpeg_parse_class; GstElementClass *gstelement_class; @@ -204,52 +195,53 @@ gst_mpeg_demux_class_init (GstMPEGDemuxClass *klass) gstelement_class = (GstElementClass *) klass; gstelement_class->change_state = gst_mpeg_demux_change_state; - gstelement_class->set_index = gst_mpeg_demux_set_index; - gstelement_class->get_index = gst_mpeg_demux_get_index; + gstelement_class->set_index = gst_mpeg_demux_set_index; + gstelement_class->get_index = gst_mpeg_demux_get_index; - mpeg_parse_class->parse_packhead = gst_mpeg_demux_parse_packhead; - mpeg_parse_class->parse_syshead = gst_mpeg_demux_parse_syshead; - mpeg_parse_class->parse_packet = gst_mpeg_demux_parse_packet; - mpeg_parse_class->parse_pes = gst_mpeg_demux_parse_pes; - mpeg_parse_class->send_data = gst_mpeg_demux_send_data; - mpeg_parse_class->handle_discont = gst_mpeg_demux_handle_discont; + mpeg_parse_class->parse_packhead = gst_mpeg_demux_parse_packhead; + mpeg_parse_class->parse_syshead = gst_mpeg_demux_parse_syshead; + mpeg_parse_class->parse_packet = gst_mpeg_demux_parse_packet; + mpeg_parse_class->parse_pes = gst_mpeg_demux_parse_pes; + mpeg_parse_class->send_data = gst_mpeg_demux_send_data; + mpeg_parse_class->handle_discont = gst_mpeg_demux_handle_discont; } static void -gst_mpeg_demux_init (GstMPEGDemux *mpeg_demux) +gst_mpeg_demux_init (GstMPEGDemux * mpeg_demux) { gint i; GstMPEGParse *mpeg_parse = GST_MPEG_PARSE (mpeg_demux); gst_element_remove_pad (GST_ELEMENT (mpeg_parse), mpeg_parse->sinkpad); - mpeg_parse->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&sink_factory), "sink"); + mpeg_parse->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get (&sink_factory), + "sink"); gst_element_add_pad (GST_ELEMENT (mpeg_parse), mpeg_parse->sinkpad); gst_element_remove_pad (GST_ELEMENT (mpeg_parse), mpeg_parse->srcpad); - /* i think everything is already zero'd, but oh well*/ - for (i=0;iprivate_1_stream[i] = NULL; } - for (i=0;ipcm_stream[i] = NULL; } - for (i=0;isubtitle_stream[i] = NULL; } mpeg_demux->private_2_stream = NULL; - for (i=0;ivideo_stream[i] = NULL; } - for (i=0;iaudio_stream[i] = NULL; } GST_FLAG_SET (mpeg_demux, GST_ELEMENT_EVENT_AWARE); } -static GstMPEGStream* +static GstMPEGStream * gst_mpeg_demux_new_stream (void) { GstMPEGStream *stream; @@ -260,25 +252,25 @@ gst_mpeg_demux_new_stream (void) } static void -gst_mpeg_demux_send_data (GstMPEGParse *mpeg_parse, GstData *data, GstClockTime time) +gst_mpeg_demux_send_data (GstMPEGParse * mpeg_parse, GstData * data, + GstClockTime time) { /* GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse); */ if (GST_IS_BUFFER (data)) { gst_buffer_unref (GST_BUFFER (data)); - } - else { + } else { GstEvent *event = GST_EVENT (data); switch (GST_EVENT_TYPE (event)) { default: - gst_pad_event_default (mpeg_parse->sinkpad, event); + gst_pad_event_default (mpeg_parse->sinkpad, event); break; } } } static void -gst_mpeg_demux_handle_discont (GstMPEGParse *mpeg_parse) +gst_mpeg_demux_handle_discont (GstMPEGParse * mpeg_parse) { GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse); gint64 current_time = MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr); @@ -286,24 +278,22 @@ gst_mpeg_demux_handle_discont (GstMPEGParse *mpeg_parse) GST_DEBUG ("discont %" G_GUINT64_FORMAT "\n", current_time); - for (i=0;ivideo_stream[i] && - GST_PAD_IS_USABLE (mpeg_demux->video_stream[i]->pad)) - { + for (i = 0; i < NUM_VIDEO_STREAMS; i++) { + if (mpeg_demux->video_stream[i] && + GST_PAD_IS_USABLE (mpeg_demux->video_stream[i]->pad)) { GstEvent *discont; - discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, - current_time, NULL); + discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, + current_time, NULL); gst_pad_push (mpeg_demux->video_stream[i]->pad, GST_DATA (discont)); } - if (mpeg_demux->audio_stream[i] && - GST_PAD_IS_USABLE (mpeg_demux->audio_stream[i]->pad)) - { + if (mpeg_demux->audio_stream[i] && + GST_PAD_IS_USABLE (mpeg_demux->audio_stream[i]->pad)) { GstEvent *discont; - discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, - current_time, NULL); + discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, + current_time, NULL); gst_pad_push (mpeg_demux->audio_stream[i]->pad, GST_DATA (discont)); } @@ -311,7 +301,7 @@ gst_mpeg_demux_handle_discont (GstMPEGParse *mpeg_parse) } static gboolean -gst_mpeg_demux_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) +gst_mpeg_demux_parse_packhead (GstMPEGParse * mpeg_parse, GstBuffer * buffer) { guint8 *buf; @@ -326,24 +316,23 @@ gst_mpeg_demux_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) } static gint -_demux_get_writer_id (GstIndex *index, GstPad *pad) +_demux_get_writer_id (GstIndex * index, GstPad * pad) { gint id; + if (!gst_index_get_writer_id (index, GST_OBJECT (pad), &id)) { GST_CAT_WARNING_OBJECT (GST_CAT_SEEK, index, - "can't get index id for %s:%s", - GST_DEBUG_PAD_NAME (pad)); + "can't get index id for %s:%s", GST_DEBUG_PAD_NAME (pad)); return -1; } else { GST_CAT_LOG_OBJECT (GST_CAT_SEEK, index, - "got index id %d for %s:%s", - id, GST_DEBUG_PAD_NAME (pad)); + "got index id %d for %s:%s", id, GST_DEBUG_PAD_NAME (pad)); return id; } } static gboolean -gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) +gst_mpeg_demux_parse_syshead (GstMPEGParse * mpeg_parse, GstBuffer * buffer) { GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse); guint16 header_length; @@ -358,10 +347,10 @@ gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) GST_DEBUG ("header_length %d", header_length); buf += 2; - /* marker:1==1 ! rate_bound:22 | marker:1==1*/ + /* marker:1==1 ! rate_bound:22 | marker:1==1 */ buf += 3; - /* audio_bound:6==1 ! fixed:1 | constrained:1*/ + /* audio_bound:6==1 ! fixed:1 | constrained:1 */ buf += 1; /* audio_lock:1 | video_lock:1 | marker:1==1 | video_bound:5 */ @@ -372,10 +361,9 @@ gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) if (!GST_MPEG_PARSE_IS_MPEG2 (mpeg_demux)) { gint stream_count = (header_length - 6) / 3; - gint i, j=0; + gint i, j = 0; - GST_DEBUG ("number of streams=%d ", - stream_count); + GST_DEBUG ("number of streams=%d ", stream_count); for (i = 0; i < stream_count; i++) { guint8 stream_id; @@ -400,44 +388,43 @@ gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) } STD_buffer_bound_scale = *buf & 0x20; - STD_buffer_size_bound = ((guint16)(*buf++ & 0x1F)) << 8; + STD_buffer_size_bound = ((guint16) (*buf++ & 0x1F)) << 8; STD_buffer_size_bound |= *buf++; if (STD_buffer_bound_scale == 0) { buf_byte_size_bound = STD_buffer_size_bound * 128; - } - else { + } else { buf_byte_size_bound = STD_buffer_size_bound * 1024; } if (stream_id == 0xBD) { - /* private_stream_1 */ + /* private_stream_1 */ name = NULL; outstream = NULL; } else if (stream_id == 0xBF) { - /* private_stream_2 */ + /* private_stream_2 */ name = g_strdup_printf ("private_stream_2"); outstream = &mpeg_demux->private_2_stream; newtemp = gst_static_pad_template_get (&private2_factory); } else if (stream_id >= 0xC0 && stream_id < 0xE0) { - /* Audio */ + /* Audio */ name = g_strdup_printf ("audio_%02d", stream_id & 0x1F); outstream = &mpeg_demux->audio_stream[stream_id & 0x1F]; newtemp = gst_static_pad_template_get (&audio_factory); } else if (stream_id >= 0xE0 && stream_id < 0xF0) { - /* Video */ + /* Video */ name = g_strdup_printf ("video_%02d", stream_id & 0x0F); outstream = &mpeg_demux->video_stream[stream_id & 0x0F]; - newtemp = gst_static_pad_template_get (&video_src_factory); + newtemp = gst_static_pad_template_get (&video_src_factory); if (!GST_MPEG_PARSE_IS_MPEG2 (mpeg_demux)) { caps = gst_caps_new_simple ("video/mpeg", - "mpegversion", G_TYPE_INT, 1, - "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); + "mpegversion", G_TYPE_INT, 1, + "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); } else { caps = gst_caps_new_simple ("video/mpeg", - "mpegversion", G_TYPE_INT, 2, - "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); - } + "mpegversion", G_TYPE_INT, 2, + "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); + } } else { GST_DEBUG ("unknown stream id %d", stream_id); } @@ -445,7 +432,7 @@ gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) GST_DEBUG ("stream ID 0x%02X (%s)", stream_id, name); GST_DEBUG ("STD_buffer_bound_scale %d", STD_buffer_bound_scale); GST_DEBUG ("STD_buffer_size_bound %d or %d bytes", - STD_buffer_size_bound, buf_byte_size_bound); + STD_buffer_size_bound, buf_byte_size_bound); /* create the pad and add it to self if it does not yet exist * this should trigger the NEW_PAD signal, which should be caught by @@ -455,25 +442,27 @@ gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) GstPad **outpad; *outstream = gst_mpeg_demux_new_stream (); - outpad = &((*outstream)->pad); - + outpad = &((*outstream)->pad); + *outpad = gst_pad_new_from_template (newtemp, name); gst_pad_set_formats_function (*outpad, gst_mpeg_demux_get_src_formats); gst_pad_set_convert_function (*outpad, gst_mpeg_parse_convert_src); - gst_pad_set_event_mask_function (*outpad, gst_mpeg_parse_get_src_event_masks); + gst_pad_set_event_mask_function (*outpad, + gst_mpeg_parse_get_src_event_masks); gst_pad_set_event_function (*outpad, gst_mpeg_demux_handle_src_event); - gst_pad_set_query_type_function (*outpad, gst_mpeg_parse_get_src_query_types); + gst_pad_set_query_type_function (*outpad, + gst_mpeg_parse_get_src_query_types); gst_pad_set_query_function (*outpad, gst_mpeg_parse_handle_src_query); if (caps && gst_caps_is_fixed (caps)) gst_pad_use_explicit_caps (*outpad); if (caps && gst_caps_is_fixed (caps)) - gst_pad_set_explicit_caps (*outpad, caps); + gst_pad_set_explicit_caps (*outpad, caps); else if (caps) gst_caps_free (caps); - gst_element_add_pad (GST_ELEMENT (mpeg_demux), (*outpad)); + gst_element_add_pad (GST_ELEMENT (mpeg_demux), (*outpad)); gst_pad_set_element_private (*outpad, *outstream); @@ -482,21 +471,20 @@ gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) if (mpeg_demux->index) (*outstream)->index_id = - _demux_get_writer_id (mpeg_demux->index, *outpad); + _demux_get_writer_id (mpeg_demux->index, *outpad); if (GST_PAD_IS_USABLE (*outpad)) { - GstEvent *event; + GstEvent *event; gint64 time; time = mpeg_parse->current_scr; - - event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, - MPEGTIME_TO_GSTTIME (time), NULL); + + event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, + MPEGTIME_TO_GSTTIME (time), NULL); gst_pad_push (*outpad, GST_DATA (event)); } - } - else { + } else { /* we won't be needing this. */ if (name) g_free (name); @@ -510,7 +498,7 @@ gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) } static gboolean -gst_mpeg_demux_parse_packet (GstMPEGParse *mpeg_parse, GstBuffer *buffer) +gst_mpeg_demux_parse_packet (GstMPEGParse * mpeg_parse, GstBuffer * buffer) { GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse); guint8 id; @@ -534,11 +522,11 @@ gst_mpeg_demux_parse_packet (GstMPEGParse *mpeg_parse, GstBuffer *buffer) GST_DEBUG ("in parse_packet"); basebuf = buf = GST_BUFFER_DATA (buffer); - id = *(buf+3); + id = *(buf + 3); buf += 4; /* start parsing */ - packet_length = GUINT16_FROM_BE (*((guint16 *)buf)); + packet_length = GUINT16_FROM_BE (*((guint16 *) buf)); GST_DEBUG ("got packet_length %d", packet_length); headerlen = 2; @@ -551,76 +539,76 @@ gst_mpeg_demux_parse_packet (GstMPEGParse *mpeg_parse, GstBuffer *buffer) /* stuffing bytes */ switch (bits & 0xC0) { case 0xC0: - if (bits == 0xff) { - GST_DEBUG ("have stuffing byte"); - } else { - GST_DEBUG ("expected stuffing byte"); - } - headerlen++; + if (bits == 0xff) { + GST_DEBUG ("have stuffing byte"); + } else { + GST_DEBUG ("expected stuffing byte"); + } + headerlen++; break; case 0x40: - GST_DEBUG ("have STD"); + GST_DEBUG ("have STD"); - STD_buffer_bound_scale = bits & 0x20; - STD_buffer_size_bound = ((guint16)(bits & 0x1F)) << 8; - STD_buffer_size_bound |= *buf++; + STD_buffer_bound_scale = bits & 0x20; + STD_buffer_size_bound = ((guint16) (bits & 0x1F)) << 8; + STD_buffer_size_bound |= *buf++; - headerlen += 2; + headerlen += 2; break; case 0x00: - switch (bits & 0x30) { + switch (bits & 0x30) { case 0x20: - /* pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */ - pts = ((guint64)(bits & 0x0E) ) << 29; - pts |= ((guint64) *buf++ ) << 22; - pts |= ((guint64)(*buf++ & 0xFE)) << 14; - pts |= ((guint64) *buf++ ) << 7; - pts |= ((guint64)(*buf++ & 0xFE)) >> 1; + /* pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */ + pts = ((guint64) (bits & 0x0E)) << 29; + pts |= ((guint64) * buf++) << 22; + pts |= ((guint64) (*buf++ & 0xFE)) << 14; + pts |= ((guint64) * buf++) << 7; + pts |= ((guint64) (*buf++ & 0xFE)) >> 1; - GST_DEBUG ("PTS = %" G_GUINT64_FORMAT, pts); - headerlen += 5; + GST_DEBUG ("PTS = %" G_GUINT64_FORMAT, pts); + headerlen += 5; goto done; case 0x30: - /* pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */ - pts = ((guint64)(bits & 0x0E) ) << 29; - pts |= ((guint64) *buf++ ) << 22; - pts |= ((guint64)(*buf++ & 0xFE)) << 14; - pts |= ((guint64) *buf++ ) << 7; - pts |= ((guint64)(*buf++ & 0xFE)) >> 1; + /* pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */ + pts = ((guint64) (bits & 0x0E)) << 29; + pts |= ((guint64) * buf++) << 22; + pts |= ((guint64) (*buf++ & 0xFE)) << 14; + pts |= ((guint64) * buf++) << 7; + pts |= ((guint64) (*buf++ & 0xFE)) >> 1; - /* sync:4 ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */ - dts = ((guint64)(*buf++ & 0x0E)) << 29; - dts |= ((guint64) *buf++ ) << 22; - dts |= ((guint64)(*buf++ & 0xFE)) << 14; - dts |= ((guint64) *buf++ ) << 7; - dts |= ((guint64)(*buf++ & 0xFE)) >> 1; + /* sync:4 ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */ + dts = ((guint64) (*buf++ & 0x0E)) << 29; + dts |= ((guint64) * buf++) << 22; + dts |= ((guint64) (*buf++ & 0xFE)) << 14; + dts |= ((guint64) * buf++) << 7; + dts |= ((guint64) (*buf++ & 0xFE)) >> 1; - GST_DEBUG ("PTS = %" G_GUINT64_FORMAT ", DTS = %" G_GUINT64_FORMAT, pts, dts); - headerlen += 10; + GST_DEBUG ("PTS = %" G_GUINT64_FORMAT ", DTS = %" G_GUINT64_FORMAT, + pts, dts); + headerlen += 10; goto done; case 0x00: - GST_DEBUG ("have no pts/dts"); - GST_DEBUG ("got trailer bits %x", (bits & 0x0f)); - if ((bits & 0x0f) != 0xf) { - GST_DEBUG ("not a valid packet time sequence"); - return FALSE; - } - headerlen++; - default: + GST_DEBUG ("have no pts/dts"); + GST_DEBUG ("got trailer bits %x", (bits & 0x0f)); + if ((bits & 0x0f) != 0xf) { + GST_DEBUG ("not a valid packet time sequence"); + return FALSE; + } + headerlen++; + default: goto done; } default: goto done; - } + } } while (1); GST_DEBUG ("done with header loop"); done: /* calculate the amount of real data in this packet */ - datalen = packet_length - headerlen+2; - GST_DEBUG ("headerlen is %d, datalen is %d", - headerlen,datalen); + datalen = packet_length - headerlen + 2; + GST_DEBUG ("headerlen is %d, datalen is %d", headerlen, datalen); if (id == 0xBD) { /* private_stream_1 */ @@ -630,7 +618,7 @@ done: if (ps_id_code >= 0x80 && ps_id_code <= 0x87) { /* make sure it's valid */ GST_DEBUG ("0x%02X: we have a private_stream_1 (AC3) packet, track %d", - id, ps_id_code - 0x80); + id, ps_id_code - 0x80); outstream = &mpeg_demux->private_1_stream[ps_id_code - 0x80]; /* scrap first 4 bytes (so-called "mystery AC3 tag") */ headerlen += 4; @@ -670,14 +658,12 @@ done: timestamp = MPEGTIME_TO_GSTTIME (pts); if (mpeg_demux->index) { - gst_index_add_association (mpeg_demux->index, - (*outstream)->index_id, 0, - GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buffer), - GST_FORMAT_TIME, timestamp, - 0); + gst_index_add_association (mpeg_demux->index, + (*outstream)->index_id, 0, + GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buffer), + GST_FORMAT_TIME, timestamp, 0); } - } - else { + } else { timestamp = GST_CLOCK_TIME_NONE; } @@ -691,8 +677,8 @@ done: GST_BUFFER_TIMESTAMP (outbuf) = timestamp; GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buffer) + headerlen + 4; - GST_DEBUG ("pushing buffer of len %d id %d, ts %" G_GINT64_FORMAT, - datalen, id, GST_BUFFER_TIMESTAMP (outbuf)); + GST_DEBUG ("pushing buffer of len %d id %d, ts %" G_GINT64_FORMAT, + datalen, id, GST_BUFFER_TIMESTAMP (outbuf)); gst_pad_push (outpad, GST_DATA (outbuf)); } @@ -701,7 +687,7 @@ done: } static gboolean -gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) +gst_mpeg_demux_parse_pes (GstMPEGParse * mpeg_parse, GstBuffer * buffer) { GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse); guint8 id; @@ -723,11 +709,11 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) GST_DEBUG ("in parse_pes"); basebuf = buf = GST_BUFFER_DATA (buffer); - id = *(buf+3); + id = *(buf + 3); buf += 4; /* start parsing */ - packet_length = GUINT16_FROM_BE (*((guint16 *)buf)); + packet_length = GUINT16_FROM_BE (*((guint16 *) buf)); GST_DEBUG ("got packet_length %d", packet_length); buf += 2; @@ -735,8 +721,7 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) /* we don't operate on: program_stream_map, padding_stream, */ /* private_stream_2, ECM, EMM, or program_stream_directory */ if ((id != 0xBC) && (id != 0xBE) && (id != 0xBF) && (id != 0xF0) && - (id != 0xF1) && (id != 0xFF)) - { + (id != 0xF1) && (id != 0xFF)) { guchar flags1 = *buf++; guchar flags2 = *buf++; @@ -746,19 +731,18 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) header_data_length = *buf++; - GST_DEBUG ("header_data_length is %d",header_data_length); + GST_DEBUG ("header_data_length is %d", header_data_length); /* check for PTS */ if ((flags2 & 0x80)) { - /*if ((flags2 & 0x80) && id == 0xe0) { */ - pts = ((guint64) (*buf++ & 0x0E)) << 29; - pts |= ((guint64) *buf++ ) << 22; + /*if ((flags2 & 0x80) && id == 0xe0) { */ + pts = ((guint64) (*buf++ & 0x0E)) << 29; + pts |= ((guint64) * buf++) << 22; pts |= ((guint64) (*buf++ & 0xFE)) << 14; - pts |= ((guint64) *buf++ ) << 7; - pts |= ((guint64) (*buf++ & 0xFE)) >> 1; + pts |= ((guint64) * buf++) << 7; + pts |= ((guint64) (*buf++ & 0xFE)) >> 1; - GST_DEBUG ("%x PTS = %" G_GUINT64_FORMAT, - id, MPEGTIME_TO_GSTTIME (pts)); + GST_DEBUG ("%x PTS = %" G_GUINT64_FORMAT, id, MPEGTIME_TO_GSTTIME (pts)); } if ((flags2 & 0x40)) { @@ -772,9 +756,9 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) if ((flags2 & 0x10)) { guint32 es_rate; - es_rate = ((guint32)(*buf++ & 0x07)) << 14; - es_rate |= ((guint32)(*buf++ )) << 7; - es_rate |= ((guint32)(*buf++ & 0xFE)) >> 1; + es_rate = ((guint32) (*buf++ & 0x07)) << 14; + es_rate |= ((guint32) (*buf++)) << 7; + es_rate |= ((guint32) (*buf++ & 0xFE)) >> 1; GST_DEBUG ("%x ES Rate found", id); } /* FIXME: lots of PES parsing missing here... */ @@ -786,8 +770,7 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) headerlen = 5 + header_data_length; /* constant is 2 bytes of bits, 1 byte header len */ datalen = packet_length - (3 + header_data_length); - GST_DEBUG ("headerlen is %d, datalen is %d", - headerlen, datalen); + GST_DEBUG ("headerlen is %d, datalen is %d", headerlen, datalen); if (id == 0xBD) { /* private_stream_1 */ @@ -796,40 +779,38 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) if (ps_id_code >= 0x80 && ps_id_code <= 0x87) { GST_DEBUG ("we have a private_stream_1 (AC3) packet, track %d", - ps_id_code - 0x80); + ps_id_code - 0x80); outstream = &mpeg_demux->private_1_stream[ps_id_code - 0x80]; /* scrap first 4 bytes (so-called "mystery AC3 tag") */ headerlen += 4; datalen -= 4; } else if (ps_id_code >= 0xA0 && ps_id_code <= 0xA7) { - GST_DEBUG ("we have a pcm_stream packet, track %d", - ps_id_code - 0xA0); + GST_DEBUG ("we have a pcm_stream packet, track %d", ps_id_code - 0xA0); outstream = &mpeg_demux->pcm_stream[ps_id_code - 0xA0]; /* Check for changes in the sample format. */ if (*outstream != NULL && - basebuf[headerlen + 9] != - mpeg_demux->lpcm_sample_info[ps_id_code - 0xA0]) { - /* Change the pad caps.*/ - gst_mpeg_demux_lpcm_set_caps((*outstream)->pad, basebuf[headerlen + 9]); + basebuf[headerlen + 9] != + mpeg_demux->lpcm_sample_info[ps_id_code - 0xA0]) { + /* Change the pad caps. */ + gst_mpeg_demux_lpcm_set_caps ((*outstream)->pad, + basebuf[headerlen + 9]); } /* Store the sample info. */ - mpeg_demux->lpcm_sample_info[ps_id_code - 0xA0] = - basebuf[headerlen + 9]; + mpeg_demux->lpcm_sample_info[ps_id_code - 0xA0] = basebuf[headerlen + 9]; /* Get rid of the LPCM header. */ headerlen += 7; datalen -= 7; } else if (ps_id_code >= 0x20 && ps_id_code <= 0x2F) { GST_DEBUG ("we have a subtitle_stream packet, track %d", - ps_id_code - 0x20); + ps_id_code - 0x20); outstream = &mpeg_demux->subtitle_stream[ps_id_code - 0x20]; headerlen += 1; datalen -= 1; } else { - GST_DEBUG ("0x%02X: unknown id %x", - id, ps_id_code); + GST_DEBUG ("0x%02X: unknown id %x", id, ps_id_code); } } else if (id == 0xBF) { /* private_stream_2 */ @@ -851,9 +832,9 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) if (outstream == NULL) return TRUE; - /* create the pad and add it if we don't already have one. */ - /* this should trigger the NEW_PAD signal, which should be caught by */ - /* the app and used to attach to desired streams. */ + /* create the pad and add it if we don't already have one. */ + /* this should trigger the NEW_PAD signal, which should be caught by */ + /* the app and used to attach to desired streams. */ if ((*outstream) == NULL) { gchar *name = NULL; GstCaps *caps = NULL; @@ -862,22 +843,22 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) if (id == 0xBD) { /* private_stream_1 */ if (ps_id_code >= 0x80 && ps_id_code <= 0x87) { - /* Erase any DVD audio pads. */ - gst_mpeg_demux_dvd_audio_clear (mpeg_demux, ps_id_code - 0x80); + /* Erase any DVD audio pads. */ + gst_mpeg_demux_dvd_audio_clear (mpeg_demux, ps_id_code - 0x80); - name = g_strdup_printf ("private_stream_1_%d",ps_id_code - 0x80); + name = g_strdup_printf ("private_stream_1_%d", ps_id_code - 0x80); newtemp = gst_static_pad_template_get (&private1_factory); } else if (ps_id_code >= 0xA0 && ps_id_code <= 0xA7) { - /* Erase any DVD audio pads. */ - gst_mpeg_demux_dvd_audio_clear (mpeg_demux, ps_id_code - 0xA0); + /* Erase any DVD audio pads. */ + gst_mpeg_demux_dvd_audio_clear (mpeg_demux, ps_id_code - 0xA0); - name = g_strdup_printf ("pcm_stream_%d", ps_id_code - 0xA0); + name = g_strdup_printf ("pcm_stream_%d", ps_id_code - 0xA0); newtemp = gst_static_pad_template_get (&pcm_factory); } else if (ps_id_code >= 0x20 && ps_id_code <= 0x2F) { - name = g_strdup_printf ("subtitle_stream_%d",ps_id_code - 0x20); - newtemp = gst_static_pad_template_get (&subtitle_factory); + name = g_strdup_printf ("subtitle_stream_%d", ps_id_code - 0x20); + newtemp = gst_static_pad_template_get (&subtitle_factory); } else { - name = g_strdup_printf ("unknown_stream_%d",ps_id_code); + name = g_strdup_printf ("unknown_stream_%d", ps_id_code); } } else if (id == 0xBF) { /* private_stream_2 */ @@ -892,20 +873,19 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) name = g_strdup_printf ("video_%02d", id - 0xE0); newtemp = gst_static_pad_template_get (&video_src_factory); if (!GST_MPEG_PARSE_IS_MPEG2 (mpeg_demux)) { - caps = gst_caps_new_simple ("video/mpeg", - "mpegversion", G_TYPE_INT, 1, - "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); - } - else { - caps = gst_caps_new_simple ("video/mpeg", - "mpegversion", G_TYPE_INT, 2, - "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); + caps = gst_caps_new_simple ("video/mpeg", + "mpegversion", G_TYPE_INT, 1, + "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); + } else { + caps = gst_caps_new_simple ("video/mpeg", + "mpegversion", G_TYPE_INT, 2, + "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); } } else { /* unknown */ name = g_strdup_printf ("unknown"); } - + if (newtemp) { *outstream = gst_mpeg_demux_new_stream (); @@ -913,32 +893,31 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) /* create the pad and add it to self */ *outpad = gst_pad_new_from_template (newtemp, name); - gst_element_add_pad(GST_ELEMENT(mpeg_demux), *outpad); + gst_element_add_pad (GST_ELEMENT (mpeg_demux), *outpad); gst_pad_set_formats_function (*outpad, gst_mpeg_demux_get_src_formats); gst_pad_set_convert_function (*outpad, gst_mpeg_parse_convert_src); - gst_pad_set_event_mask_function (*outpad, gst_mpeg_parse_get_src_event_masks); + gst_pad_set_event_mask_function (*outpad, + gst_mpeg_parse_get_src_event_masks); gst_pad_set_event_function (*outpad, gst_mpeg_demux_handle_src_event); - gst_pad_set_query_type_function (*outpad, gst_mpeg_parse_get_src_query_types); + gst_pad_set_query_type_function (*outpad, + gst_mpeg_parse_get_src_query_types); gst_pad_set_query_function (*outpad, gst_mpeg_parse_handle_src_query); gst_pad_use_explicit_caps (*outpad); if (ps_id_code < 0xA0 || ps_id_code > 0xA7) { - gst_pad_set_explicit_caps (*outpad, caps); - } - else { - gst_mpeg_demux_lpcm_set_caps(*outpad, - mpeg_demux->lpcm_sample_info[ps_id_code - - 0xA0]); + gst_pad_set_explicit_caps (*outpad, caps); + } else { + gst_mpeg_demux_lpcm_set_caps (*outpad, + mpeg_demux->lpcm_sample_info[ps_id_code - 0xA0]); } gst_pad_set_element_private (*outpad, *outstream); if (mpeg_demux->index) (*outstream)->index_id = - _demux_get_writer_id (mpeg_demux->index, *outpad); - } - else { + _demux_get_writer_id (mpeg_demux->index, *outpad); + } else { g_warning ("cannot create pad %s, no template for %02x", name, id); } if (name) @@ -956,28 +935,26 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) timestamp = MPEGTIME_TO_GSTTIME (pts); if (mpeg_demux->index) { - gst_index_add_association (mpeg_demux->index, - (*outstream)->index_id, 0, - GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buffer), - GST_FORMAT_TIME, timestamp, - 0); + gst_index_add_association (mpeg_demux->index, + (*outstream)->index_id, 0, + GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buffer), + GST_FORMAT_TIME, timestamp, 0); } - } - else { + } else { timestamp = GST_CLOCK_TIME_NONE; } /* create the buffer and send it off to the Other Side */ - if (*outpad && GST_PAD_IS_USABLE(*outpad)) { + if (*outpad && GST_PAD_IS_USABLE (*outpad)) { /* if this is part of the buffer, create a subbuffer */ GST_DEBUG ("creating subbuffer len %d", datalen); - outbuf = gst_buffer_create_sub (buffer, headerlen+4, datalen); + outbuf = gst_buffer_create_sub (buffer, headerlen + 4, datalen); GST_BUFFER_TIMESTAMP (outbuf) = timestamp; GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buffer) + headerlen + 4; - gst_pad_push(*outpad, GST_DATA (outbuf)); + gst_pad_push (*outpad, GST_DATA (outbuf)); } } @@ -989,22 +966,22 @@ gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer) * sample information. */ static void -gst_mpeg_demux_lpcm_set_caps (GstPad *pad, guint8 sample_info) +gst_mpeg_demux_lpcm_set_caps (GstPad * pad, guint8 sample_info) { gint width, rate, channels; GstCaps *caps; /* Determine the sample width. */ switch (sample_info & 0xC0) { - case 0x80: - width = 24; - break; - case 0x40: - width = 20; - break; - default: - width = 16; - break; + case 0x80: + width = 24; + break; + case 0x40: + width = 20; + break; + default: + width = 16; + break; } /* Determine the rate. */ @@ -1018,12 +995,11 @@ gst_mpeg_demux_lpcm_set_caps (GstPad *pad, guint8 sample_info) channels = (sample_info & 0x7) + 1; caps = gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_BIG_ENDIAN, - "signed", G_TYPE_BOOLEAN, TRUE, - "width", G_TYPE_INT, width, - "depth", G_TYPE_INT, width, - "rate", G_TYPE_INT, rate, - "channels", G_TYPE_INT, channels, NULL); + "endianness", G_TYPE_INT, G_BIG_ENDIAN, + "signed", G_TYPE_BOOLEAN, TRUE, + "width", G_TYPE_INT, width, + "depth", G_TYPE_INT, width, + "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL); gst_pad_set_explicit_caps (pad, caps); } @@ -1031,14 +1007,13 @@ gst_mpeg_demux_lpcm_set_caps (GstPad *pad, guint8 sample_info) * Erase the DVD audio pad (if any) associated to the given channel. */ static void -gst_mpeg_demux_dvd_audio_clear (GstMPEGDemux *mpeg_demux, int channel) +gst_mpeg_demux_dvd_audio_clear (GstMPEGDemux * mpeg_demux, int channel) { GstMPEGStream **stream = NULL; if (mpeg_demux->private_1_stream[channel] != NULL) { stream = &mpeg_demux->private_1_stream[channel]; - } - else if (mpeg_demux->pcm_stream[channel] != NULL) { + } else if (mpeg_demux->pcm_stream[channel] != NULL) { stream = &mpeg_demux->pcm_stream[channel]; } @@ -1046,7 +1021,7 @@ gst_mpeg_demux_dvd_audio_clear (GstMPEGDemux *mpeg_demux, int channel) return; } - gst_pad_unlink ((*stream)->pad, gst_pad_get_peer((*stream)->pad)); + gst_pad_unlink ((*stream)->pad, gst_pad_get_peer ((*stream)->pad)); gst_element_remove_pad (GST_ELEMENT (mpeg_demux), (*stream)->pad); g_free (*stream); @@ -1054,51 +1029,49 @@ gst_mpeg_demux_dvd_audio_clear (GstMPEGDemux *mpeg_demux, int channel) } -const GstFormat* -gst_mpeg_demux_get_src_formats (GstPad *pad) -{ +const GstFormat * +gst_mpeg_demux_get_src_formats (GstPad * pad) +{ static const GstFormat formats[] = { GST_FORMAT_TIME, /* we prefer seeking on time */ GST_FORMAT_BYTES, - 0 + 0 }; return formats; -} +} static gboolean -index_seek (GstPad *pad, GstEvent *event, gint64 *offset) +index_seek (GstPad * pad, GstEvent * event, gint64 * offset) { GstIndexEntry *entry; GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (gst_pad_get_parent (pad)); GstMPEGStream *stream = gst_pad_get_element_private (pad); entry = gst_index_get_assoc_entry (mpeg_demux->index, stream->index_id, - GST_INDEX_LOOKUP_BEFORE, 0, - GST_EVENT_SEEK_FORMAT (event), - GST_EVENT_SEEK_OFFSET (event)); + GST_INDEX_LOOKUP_BEFORE, 0, + GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event)); if (!entry) { GST_CAT_WARNING (GST_CAT_SEEK, "%s:%s index %s %" G_GINT64_FORMAT - " -> failed", - GST_DEBUG_PAD_NAME (pad), - gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, - GST_EVENT_SEEK_OFFSET (event)); + " -> failed", + GST_DEBUG_PAD_NAME (pad), + gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, + GST_EVENT_SEEK_OFFSET (event)); return FALSE; } if (gst_index_entry_assoc_map (entry, GST_FORMAT_BYTES, offset)) { GST_CAT_DEBUG (GST_CAT_SEEK, "%s:%s index %s %" G_GINT64_FORMAT - " -> %" G_GINT64_FORMAT " bytes", - GST_DEBUG_PAD_NAME (pad), - gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, - GST_EVENT_SEEK_OFFSET (event), - *offset); + " -> %" G_GINT64_FORMAT " bytes", + GST_DEBUG_PAD_NAME (pad), + gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, + GST_EVENT_SEEK_OFFSET (event), *offset); return TRUE; } return FALSE; } static gboolean -normal_seek (GstPad *pad, GstEvent *event, gint64 *offset) +normal_seek (GstPad * pad, GstEvent * event, gint64 * offset) { gboolean res = FALSE; gint64 adjust; @@ -1108,27 +1081,26 @@ normal_seek (GstPad *pad, GstEvent *event, gint64 *offset) format = GST_EVENT_SEEK_FORMAT (event); res = gst_pad_convert (pad, GST_FORMAT_BYTES, mpeg_demux->total_size_bound, - &format, &adjust); + &format, &adjust); if (res) { *offset = MAX (GST_EVENT_SEEK_OFFSET (event) - adjust, 0); GST_CAT_DEBUG (GST_CAT_SEEK, "%s:%s guestimate %" G_GINT64_FORMAT - " %s -> %" G_GINT64_FORMAT - " (total_size_bound = %" G_GINT64_FORMAT ")", - GST_DEBUG_PAD_NAME (pad), - GST_EVENT_SEEK_OFFSET (event), - gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, - *offset, - mpeg_demux->total_size_bound); + " %s -> %" G_GINT64_FORMAT + " (total_size_bound = %" G_GINT64_FORMAT ")", + GST_DEBUG_PAD_NAME (pad), + GST_EVENT_SEEK_OFFSET (event), + gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, + *offset, mpeg_demux->total_size_bound); } - return res; + return res; } static gboolean -gst_mpeg_demux_handle_src_event (GstPad *pad, GstEvent *event) -{ +gst_mpeg_demux_handle_src_event (GstPad * pad, GstEvent * event) +{ gboolean res = FALSE; GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (gst_pad_get_parent (pad)); @@ -1137,36 +1109,37 @@ gst_mpeg_demux_handle_src_event (GstPad *pad, GstEvent *event) { guint64 desired_offset; - if (mpeg_demux->index) + if (mpeg_demux->index) res = index_seek (pad, event, &desired_offset); if (!res) res = normal_seek (pad, event, &desired_offset); if (res) { - GstEvent *new_event; + GstEvent *new_event; - new_event = gst_event_new_seek (GST_EVENT_SEEK_TYPE (event), desired_offset); - res = gst_mpeg_parse_handle_src_event (pad, new_event); + new_event = + gst_event_new_seek (GST_EVENT_SEEK_TYPE (event), desired_offset); + res = gst_mpeg_parse_handle_src_event (pad, new_event); } gst_event_unref (event); break; } case GST_EVENT_NAVIGATION: - return gst_pad_send_event (GST_PAD_PEER (GST_MPEG_PARSE (mpeg_demux)->sinkpad), - event); - break; + return gst_pad_send_event (GST_PAD_PEER (GST_MPEG_PARSE (mpeg_demux)-> + sinkpad), event); + break; default: gst_event_unref (event); break; - } + } return res; } static GstElementStateReturn -gst_mpeg_demux_change_state (GstElement *element) -{ +gst_mpeg_demux_change_state (GstElement * element) +{ /* GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (element); */ - + switch (GST_STATE_TRANSITION (element)) { case GST_STATE_READY_TO_PAUSED: break; @@ -1182,7 +1155,7 @@ gst_mpeg_demux_change_state (GstElement *element) } static void -gst_mpeg_demux_set_index (GstElement *element, GstIndex *index) +gst_mpeg_demux_set_index (GstElement * element, GstIndex * index) { GstMPEGDemux *mpeg_demux; @@ -1193,8 +1166,8 @@ gst_mpeg_demux_set_index (GstElement *element, GstIndex *index) mpeg_demux->index = index; } -static GstIndex* -gst_mpeg_demux_get_index (GstElement *element) +static GstIndex * +gst_mpeg_demux_get_index (GstElement * element) { GstMPEGDemux *mpeg_demux; @@ -1205,8 +1178,8 @@ gst_mpeg_demux_get_index (GstElement *element) gboolean -gst_mpeg_demux_plugin_init (GstPlugin *plugin) +gst_mpeg_demux_plugin_init (GstPlugin * plugin) { return gst_element_register (plugin, "mpegdemux", - GST_RANK_PRIMARY, GST_TYPE_MPEG_DEMUX); + GST_RANK_PRIMARY, GST_TYPE_MPEG_DEMUX); } diff --git a/gst/mpegstream/gstmpegdemux.h b/gst/mpegstream/gstmpegdemux.h index 215c0d0f6e..b347bef2b7 100644 --- a/gst/mpegstream/gstmpegdemux.h +++ b/gst/mpegstream/gstmpegdemux.h @@ -27,8 +27,9 @@ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_MPEG_DEMUX \ @@ -42,37 +43,39 @@ extern "C" { #define GST_IS_MPEG_DEMUX_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MPEG_DEMUX)) -typedef struct _GstMPEGDemux GstMPEGDemux; -typedef struct _GstMPEGDemuxClass GstMPEGDemuxClass; + typedef struct _GstMPEGDemux GstMPEGDemux; + typedef struct _GstMPEGDemuxClass GstMPEGDemuxClass; -typedef struct _GstMPEGStream GstMPEGStream; + typedef struct _GstMPEGStream GstMPEGStream; -struct _GstMPEGStream { - gint8 STD_buffer_bound_scale; - gint16 STD_buffer_size_bound; - GstPad *pad; - guint64 pts; - gint index_id; - gint size_bound; -}; + struct _GstMPEGStream + { + gint8 STD_buffer_bound_scale; + gint16 STD_buffer_size_bound; + GstPad *pad; + guint64 pts; + gint index_id; + gint size_bound; + }; -struct _GstMPEGDemux { - GstMPEGParse parent; + struct _GstMPEGDemux + { + GstMPEGParse parent; - /* previous partial chunk and bytes remaining in it */ - gboolean in_flush; + /* previous partial chunk and bytes remaining in it */ + gboolean in_flush; - /* program stream header values */ - guint16 header_length; - guint32 rate_bound; - guint8 audio_bound; - gboolean fixed; - gboolean constrained; - gboolean audio_lock; - gboolean video_lock; - guint8 video_bound; - gboolean packet_rate_restriction; - gint64 total_size_bound; + /* program stream header values */ + guint16 header_length; + guint32 rate_bound; + guint8 audio_bound; + gboolean fixed; + gboolean constrained; + gboolean audio_lock; + gboolean video_lock; + guint8 video_bound; + gboolean packet_rate_restriction; + gint64 total_size_bound; #define NUM_PRIVATE_1_STREAMS 8 #define NUM_PCM_STREAMS 8 @@ -80,33 +83,34 @@ struct _GstMPEGDemux { #define NUM_VIDEO_STREAMS 16 #define NUM_AUDIO_STREAMS 32 - /* stream output */ - GstMPEGStream *private_1_stream[NUM_PRIVATE_1_STREAMS]; /* up to 8 ac3 audio tracks */ - GstMPEGStream *pcm_stream[NUM_PCM_STREAMS]; - GstMPEGStream *subtitle_stream[NUM_SUBTITLE_STREAMS]; - GstMPEGStream *private_2_stream; - GstMPEGStream *video_stream[NUM_VIDEO_STREAMS]; - GstMPEGStream *audio_stream[NUM_AUDIO_STREAMS]; + /* stream output */ + GstMPEGStream *private_1_stream[NUM_PRIVATE_1_STREAMS]; /* up to 8 ac3 audio tracks */ + GstMPEGStream *pcm_stream[NUM_PCM_STREAMS]; + GstMPEGStream *subtitle_stream[NUM_SUBTITLE_STREAMS]; + GstMPEGStream *private_2_stream; + GstMPEGStream *video_stream[NUM_VIDEO_STREAMS]; + GstMPEGStream *audio_stream[NUM_AUDIO_STREAMS]; - /* The type of linear PCM samples associated to each channel. The - values are bit fields with the same format of the sample_info - field in the linear PCM header. */ - guint8 lpcm_sample_info[NUM_PCM_STREAMS]; + /* The type of linear PCM samples associated to each channel. The + values are bit fields with the same format of the sample_info + field in the linear PCM header. */ + guint8 lpcm_sample_info[NUM_PCM_STREAMS]; - GstIndex *index; -}; + GstIndex *index; + }; -struct _GstMPEGDemuxClass { - GstMPEGParseClass parent_class; -}; + struct _GstMPEGDemuxClass + { + GstMPEGParseClass parent_class; + }; -GType gst_mpeg_demux_get_type(void); + GType gst_mpeg_demux_get_type (void); -gboolean gst_mpeg_demux_plugin_init (GstPlugin *plugin); + gboolean gst_mpeg_demux_plugin_init (GstPlugin * plugin); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __MPEG_DEMUX_H__ */ +#endif /* __MPEG_DEMUX_H__ */ diff --git a/gst/mpegstream/gstmpegpacketize.c b/gst/mpegstream/gstmpegpacketize.c index e5a4b37a84..b5abc70383 100644 --- a/gst/mpegstream/gstmpegpacketize.c +++ b/gst/mpegstream/gstmpegpacketize.c @@ -24,16 +24,16 @@ /*#define GST_DEBUG_ENABLED */ #include -GstMPEGPacketize* -gst_mpeg_packetize_new (GstPad *pad, GstMPEGPacketizeType type) +GstMPEGPacketize * +gst_mpeg_packetize_new (GstPad * pad, GstMPEGPacketizeType type) { GstMPEGPacketize *new; g_return_val_if_fail (pad != NULL, NULL); g_return_val_if_fail (GST_IS_PAD (pad), NULL); - + new = g_malloc (sizeof (GstMPEGPacketize)); - + gst_object_ref (GST_OBJECT (pad)); new->resync = TRUE; new->id = 0; @@ -46,7 +46,7 @@ gst_mpeg_packetize_new (GstPad *pad, GstMPEGPacketizeType type) } void -gst_mpeg_packetize_destroy (GstMPEGPacketize *packetize) +gst_mpeg_packetize_destroy (GstMPEGPacketize * packetize) { g_return_if_fail (packetize != NULL); @@ -56,8 +56,8 @@ gst_mpeg_packetize_destroy (GstMPEGPacketize *packetize) g_free (packetize); } -static GstData* -parse_packhead (GstMPEGPacketize *packetize) +static GstData * +parse_packhead (GstMPEGPacketize * packetize) { gint length = 8 + 4; guint8 *buf; @@ -82,8 +82,7 @@ parse_packhead (GstMPEGPacketize *packetize) got_bytes = gst_bytestream_peek_bytes (packetize->bs, &buf, length); if (got_bytes < length) return NULL; - } - else { + } else { GST_DEBUG ("packetize::parse_packhead setting mpeg1"); packetize->MPEG2 = FALSE; } @@ -95,8 +94,8 @@ parse_packhead (GstMPEGPacketize *packetize) return GST_DATA (outbuf); } -static GstData* -parse_end (GstMPEGPacketize *packetize) +static GstData * +parse_end (GstMPEGPacketize * packetize) { guint32 got_bytes; GstBuffer *outbuf; @@ -108,8 +107,8 @@ parse_end (GstMPEGPacketize *packetize) return GST_DATA (outbuf); } -static inline GstData* -parse_generic (GstMPEGPacketize *packetize) +static inline GstData * +parse_generic (GstMPEGPacketize * packetize) { GstByteStream *bs = packetize->bs; guchar *buf; @@ -119,8 +118,8 @@ parse_generic (GstMPEGPacketize *packetize) GST_DEBUG ("packetize: in parse_generic"); - got_bytes = gst_bytestream_peek_bytes (bs, (guint8**)&buf, length); - if (got_bytes < 6) + got_bytes = gst_bytestream_peek_bytes (bs, (guint8 **) & buf, length); + if (got_bytes < 6) return NULL; buf += 4; @@ -129,14 +128,14 @@ parse_generic (GstMPEGPacketize *packetize) GST_DEBUG ("packetize: header_length %d", length); got_bytes = gst_bytestream_read (packetize->bs, &outbuf, length); - if (got_bytes < length) + if (got_bytes < length) return NULL; return GST_DATA (outbuf); } -static inline GstData* -parse_chunk (GstMPEGPacketize *packetize) +static inline GstData * +parse_chunk (GstMPEGPacketize * packetize) { GstByteStream *bs = packetize->bs; guchar *buf; @@ -145,30 +144,31 @@ parse_chunk (GstMPEGPacketize *packetize) gint chunksize; GstBuffer *outbuf = NULL; - chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096); + chunksize = gst_bytestream_peek_bytes (bs, (guint8 **) & buf, 4096); if (chunksize == 0) return NULL; offset = 4; - code = GUINT32_FROM_BE (*((guint32 *)(buf+offset))); + code = GUINT32_FROM_BE (*((guint32 *) (buf + offset))); GST_DEBUG ("code = %08x", code); while ((code & 0xffffff00) != 0x100L) { code = (code << 8) | buf[offset++]; - + GST_DEBUG (" code = %08x", code); if (offset == chunksize) { - chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, offset + 4096); + chunksize = + gst_bytestream_peek_bytes (bs, (guint8 **) & buf, offset + 4096); if (chunksize == 0) return NULL; chunksize += offset; } } if (offset > 4) { - chunksize = gst_bytestream_read (bs, &outbuf, offset-4); + chunksize = gst_bytestream_read (bs, &outbuf, offset - 4); if (chunksize == 0) return NULL; } @@ -178,7 +178,7 @@ parse_chunk (GstMPEGPacketize *packetize) /* FIXME mmx-ify me */ static inline gboolean -find_start_code (GstMPEGPacketize *packetize) +find_start_code (GstMPEGPacketize * packetize) { GstByteStream *bs = packetize->bs; guchar *buf; @@ -186,25 +186,25 @@ find_start_code (GstMPEGPacketize *packetize) guint32 code; gint chunksize; - chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096); + chunksize = gst_bytestream_peek_bytes (bs, (guint8 **) & buf, 4096); if (chunksize < 5) return FALSE; offset = 4; - code = GUINT32_FROM_BE (*((guint32 *)(buf))); + code = GUINT32_FROM_BE (*((guint32 *) (buf))); GST_DEBUG ("code = %08x %p %08x", code, buf, chunksize); while ((code & 0xffffff00) != 0x100L) { code = (code << 8) | buf[offset++]; - + GST_DEBUG (" code = %08x %p %08x", code, buf, chunksize); if (offset == chunksize) { gst_bytestream_flush_fast (bs, offset); - chunksize = gst_bytestream_peek_bytes (bs, (guint8**)&buf, 4096); + chunksize = gst_bytestream_peek_bytes (bs, (guint8 **) & buf, 4096); if (chunksize == 0) return FALSE; @@ -218,8 +218,8 @@ find_start_code (GstMPEGPacketize *packetize) return TRUE; } -GstData* -gst_mpeg_packetize_read (GstMPEGPacketize *packetize) +GstData * +gst_mpeg_packetize_read (GstMPEGPacketize * packetize) { gboolean got_event = FALSE; GstData *outbuf = NULL; @@ -233,20 +233,20 @@ gst_mpeg_packetize_read (GstMPEGPacketize *packetize) GST_DEBUG ("packetize: have chunk 0x%02X", packetize->id); if (packetize->type == GST_MPEG_PACKETIZE_SYSTEM) { if (packetize->resync) { - if (packetize->id != PACK_START_CODE) { - gst_bytestream_flush_fast (packetize->bs, 4); + if (packetize->id != PACK_START_CODE) { + gst_bytestream_flush_fast (packetize->bs, 4); continue; } packetize->resync = FALSE; } - switch (packetize->id) { - case PACK_START_CODE: - outbuf = parse_packhead (packetize); + switch (packetize->id) { + case PACK_START_CODE: + outbuf = parse_packhead (packetize); if (!outbuf) got_event = TRUE; break; - case SYS_HEADER_START_CODE: + case SYS_HEADER_START_CODE: outbuf = parse_generic (packetize); if (!outbuf) got_event = TRUE; @@ -256,22 +256,21 @@ gst_mpeg_packetize_read (GstMPEGPacketize *packetize) if (!outbuf) got_event = TRUE; break; - default: - if (packetize->MPEG2 && ((packetize->id < 0xBD) || (packetize->id > 0xFE))) { - gst_bytestream_flush (packetize->bs, 4); - g_warning ("packetize: ******** unknown id 0x%02X",packetize->id); - } - else { + default: + if (packetize->MPEG2 && ((packetize->id < 0xBD) + || (packetize->id > 0xFE))) { + gst_bytestream_flush (packetize->bs, 4); + g_warning ("packetize: ******** unknown id 0x%02X", + packetize->id); + } else { outbuf = parse_generic (packetize); if (!outbuf) - got_event = TRUE; + got_event = TRUE; } - } - } - else if (packetize->type == GST_MPEG_PACKETIZE_VIDEO) { + } + } else if (packetize->type == GST_MPEG_PACKETIZE_VIDEO) { outbuf = parse_chunk (packetize); - } - else { + } else { g_assert_not_reached (); } } @@ -282,11 +281,11 @@ gst_mpeg_packetize_read (GstMPEGPacketize *packetize) gint etype; gst_bytestream_get_status (packetize->bs, &remaining, &event); - etype = event? GST_EVENT_TYPE (event) : GST_EVENT_EOS; + etype = event ? GST_EVENT_TYPE (event) : GST_EVENT_EOS; switch (etype) { - case GST_EVENT_DISCONTINUOUS: - GST_DEBUG ("packetize: discont\n"); + case GST_EVENT_DISCONTINUOUS: + GST_DEBUG ("packetize: discont\n"); gst_bytestream_flush_fast (packetize->bs, remaining); break; } diff --git a/gst/mpegstream/gstmpegpacketize.h b/gst/mpegstream/gstmpegpacketize.h index c632cc70ce..1ee50a01a4 100644 --- a/gst/mpegstream/gstmpegpacketize.h +++ b/gst/mpegstream/gstmpegpacketize.h @@ -27,8 +27,9 @@ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define PICTURE_START_CODE 0x00 #define SLICE_MIN_START_CODE 0x01 @@ -44,36 +45,39 @@ extern "C" { #define PACK_START_CODE 0xba #define SYS_HEADER_START_CODE 0xbb -typedef struct _GstMPEGPacketize GstMPEGPacketize; + typedef struct _GstMPEGPacketize GstMPEGPacketize; #define GST_MPEG_PACKETIZE_ID(pack) ((pack)->id) #define GST_MPEG_PACKETIZE_IS_MPEG2(pack) ((pack)->MPEG2) -typedef enum { - GST_MPEG_PACKETIZE_SYSTEM, - GST_MPEG_PACKETIZE_VIDEO, -} GstMPEGPacketizeType; + typedef enum + { + GST_MPEG_PACKETIZE_SYSTEM, + GST_MPEG_PACKETIZE_VIDEO, + } GstMPEGPacketizeType; -struct _GstMPEGPacketize { - /* current parse state */ - guchar id; + struct _GstMPEGPacketize + { + /* current parse state */ + guchar id; - GstPad *pad; - GstByteStream *bs; - GstMPEGPacketizeType type; + GstPad *pad; + GstByteStream *bs; + GstMPEGPacketizeType type; - gboolean MPEG2; - gboolean resync; -}; + gboolean MPEG2; + gboolean resync; + }; -GstMPEGPacketize* gst_mpeg_packetize_new (GstPad *pad, GstMPEGPacketizeType type); -void gst_mpeg_packetize_destroy (GstMPEGPacketize *packetize); + GstMPEGPacketize *gst_mpeg_packetize_new (GstPad * pad, + GstMPEGPacketizeType type); + void gst_mpeg_packetize_destroy (GstMPEGPacketize * packetize); -GstData* gst_mpeg_packetize_read (GstMPEGPacketize *packetize); + GstData *gst_mpeg_packetize_read (GstMPEGPacketize * packetize); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __MPEGPACKETIZE_H__ */ +#endif /* __MPEGPACKETIZE_H__ */ diff --git a/gst/mpegstream/gstmpegparse.c b/gst/mpegstream/gstmpegparse.c index 0924e1ac8e..5bfd375ac1 100644 --- a/gst/mpegstream/gstmpegparse.c +++ b/gst/mpegstream/gstmpegparse.c @@ -34,8 +34,7 @@ static GstElementDetails mpeg_parse_details = { "MPEG System Parser", "Codec/Parser", "Parses MPEG1 and MPEG2 System Streams", - "Erik Walthinsen \n" - "Wim Taymans " + "Erik Walthinsen \n" "Wim Taymans " }; #define CLASS(o) GST_MPEG_PARSE_CLASS (G_OBJECT_GET_CLASS (o)) @@ -43,12 +42,14 @@ static GstElementDetails mpeg_parse_details = { #define DEFAULT_MAX_DISCONT 10000 /* GstMPEGParse signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_SYNC, ARG_MAX_DISCONT, @@ -56,52 +57,46 @@ enum { /* FILL ME */ }; -static GstStaticPadTemplate sink_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/mpeg, " - "mpegversion = (int) [ 1, 2 ], " - "systemstream = (boolean) TRUE" - ) -); +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/mpeg, " + "mpegversion = (int) [ 1, 2 ], " "systemstream = (boolean) TRUE") + ); -static GstStaticPadTemplate src_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/mpeg, " - "mpegversion = (int) [ 1, 2 ], " - "systemstream = (boolean) TRUE" - ) -); +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/mpeg, " + "mpegversion = (int) [ 1, 2 ], " "systemstream = (boolean) TRUE") + ); -static void gst_mpeg_parse_class_init (GstMPEGParseClass *klass); -static void gst_mpeg_parse_base_init (GstMPEGParseClass *klass); -static void gst_mpeg_parse_init (GstMPEGParse *mpeg_parse); -static GstElementStateReturn - gst_mpeg_parse_change_state (GstElement *element); +static void gst_mpeg_parse_class_init (GstMPEGParseClass * klass); +static void gst_mpeg_parse_base_init (GstMPEGParseClass * klass); +static void gst_mpeg_parse_init (GstMPEGParse * mpeg_parse); +static GstElementStateReturn gst_mpeg_parse_change_state (GstElement * element); -static void gst_mpeg_parse_set_clock (GstElement *element, GstClock *clock); +static void gst_mpeg_parse_set_clock (GstElement * element, GstClock * clock); -static gboolean gst_mpeg_parse_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer); -static void gst_mpeg_parse_send_data (GstMPEGParse *mpeg_parse, GstData *data, GstClockTime time); -static void gst_mpeg_parse_handle_discont (GstMPEGParse *mpeg_parse); +static gboolean gst_mpeg_parse_parse_packhead (GstMPEGParse * mpeg_parse, + GstBuffer * buffer); +static void gst_mpeg_parse_send_data (GstMPEGParse * mpeg_parse, GstData * data, + GstClockTime time); +static void gst_mpeg_parse_handle_discont (GstMPEGParse * mpeg_parse); -static void gst_mpeg_parse_loop (GstElement *element); +static void gst_mpeg_parse_loop (GstElement * element); -static void gst_mpeg_parse_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); -static void gst_mpeg_parse_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_mpeg_parse_set_index (GstElement *element, GstIndex *index); -static GstIndex* gst_mpeg_parse_get_index (GstElement *element); +static void gst_mpeg_parse_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static void gst_mpeg_parse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_mpeg_parse_set_index (GstElement * element, GstIndex * index); +static GstIndex *gst_mpeg_parse_get_index (GstElement * element); -static gboolean gst_mpeg_parse_release_locks (GstElement *element); +static gboolean gst_mpeg_parse_release_locks (GstElement * element); static GstElementClass *parent_class = NULL; + /*static guint gst_mpeg_parse_signals[LAST_SIGNAL] = { 0 };*/ GType @@ -111,23 +106,25 @@ gst_mpeg_parse_get_type (void) if (!mpeg_parse_type) { static const GTypeInfo mpeg_parse_info = { - sizeof(GstMPEGParseClass), - (GBaseInitFunc)gst_mpeg_parse_base_init, + sizeof (GstMPEGParseClass), + (GBaseInitFunc) gst_mpeg_parse_base_init, NULL, - (GClassInitFunc)gst_mpeg_parse_class_init, + (GClassInitFunc) gst_mpeg_parse_class_init, NULL, NULL, - sizeof(GstMPEGParse), + sizeof (GstMPEGParse), 0, - (GInstanceInitFunc)gst_mpeg_parse_init, + (GInstanceInitFunc) gst_mpeg_parse_init, }; - mpeg_parse_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMPEGParse", &mpeg_parse_info, 0); + mpeg_parse_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstMPEGParse", + &mpeg_parse_info, 0); } return mpeg_parse_type; } static void -gst_mpeg_parse_base_init (GstMPEGParseClass *klass) +gst_mpeg_parse_base_init (GstMPEGParseClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); @@ -135,66 +132,76 @@ gst_mpeg_parse_base_init (GstMPEGParseClass *klass) } static void -gst_mpeg_parse_class_init (GstMPEGParseClass *klass) +gst_mpeg_parse_class_init (GstMPEGParseClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SYNC, - g_param_spec_boolean ("sync", "Sync", "Synchronize on the stream SCR", - FALSE, G_PARAM_READWRITE)); + g_param_spec_boolean ("sync", "Sync", "Synchronize on the stream SCR", + FALSE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_DISCONT, - g_param_spec_int ("max_discont", "Max Discont", "The maximun allowed SCR discontinuity", - 0, G_MAXINT, DEFAULT_MAX_DISCONT, G_PARAM_READWRITE)); + g_param_spec_int ("max_discont", "Max Discont", + "The maximun allowed SCR discontinuity", 0, G_MAXINT, + DEFAULT_MAX_DISCONT, G_PARAM_READWRITE)); gobject_class->get_property = gst_mpeg_parse_get_property; gobject_class->set_property = gst_mpeg_parse_set_property; - gstelement_class->change_state = gst_mpeg_parse_change_state; - gstelement_class->set_clock = gst_mpeg_parse_set_clock; - gstelement_class->get_index = gst_mpeg_parse_get_index; - gstelement_class->set_index = gst_mpeg_parse_set_index; + gstelement_class->change_state = gst_mpeg_parse_change_state; + gstelement_class->set_clock = gst_mpeg_parse_set_clock; + gstelement_class->get_index = gst_mpeg_parse_get_index; + gstelement_class->set_index = gst_mpeg_parse_set_index; gstelement_class->release_locks = gst_mpeg_parse_release_locks; klass->parse_packhead = gst_mpeg_parse_parse_packhead; - klass->parse_syshead = NULL; - klass->parse_packet = NULL; - klass->parse_pes = NULL; - klass->send_data = gst_mpeg_parse_send_data; - klass->handle_discont = gst_mpeg_parse_handle_discont; + klass->parse_syshead = NULL; + klass->parse_packet = NULL; + klass->parse_pes = NULL; + klass->send_data = gst_mpeg_parse_send_data; + klass->handle_discont = gst_mpeg_parse_handle_discont; /* FIXME: this is a hack. We add the pad templates here instead * in the base_init function, since the derived class (mpegdemux) * uses different pads. IMO, this is wrong. */ gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&src_factory)); + gst_static_pad_template_get (&src_factory)); gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&sink_factory)); + gst_static_pad_template_get (&sink_factory)); } static void -gst_mpeg_parse_init (GstMPEGParse *mpeg_parse) +gst_mpeg_parse_init (GstMPEGParse * mpeg_parse) { - mpeg_parse->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&sink_factory), "sink"); - gst_element_add_pad(GST_ELEMENT(mpeg_parse),mpeg_parse->sinkpad); - gst_pad_set_formats_function (mpeg_parse->sinkpad, gst_mpeg_parse_get_src_formats); - gst_pad_set_convert_function (mpeg_parse->sinkpad, gst_mpeg_parse_convert_src); + mpeg_parse->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get (&sink_factory), + "sink"); + gst_element_add_pad (GST_ELEMENT (mpeg_parse), mpeg_parse->sinkpad); + gst_pad_set_formats_function (mpeg_parse->sinkpad, + gst_mpeg_parse_get_src_formats); + gst_pad_set_convert_function (mpeg_parse->sinkpad, + gst_mpeg_parse_convert_src); - mpeg_parse->srcpad = gst_pad_new_from_template( - gst_static_pad_template_get (&src_factory), "src"); - gst_element_add_pad(GST_ELEMENT(mpeg_parse),mpeg_parse->srcpad); - gst_pad_set_formats_function (mpeg_parse->srcpad, gst_mpeg_parse_get_src_formats); + mpeg_parse->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get (&src_factory), + "src"); + gst_element_add_pad (GST_ELEMENT (mpeg_parse), mpeg_parse->srcpad); + gst_pad_set_formats_function (mpeg_parse->srcpad, + gst_mpeg_parse_get_src_formats); gst_pad_set_convert_function (mpeg_parse->srcpad, gst_mpeg_parse_convert_src); - gst_pad_set_event_mask_function (mpeg_parse->srcpad, gst_mpeg_parse_get_src_event_masks); - gst_pad_set_event_function (mpeg_parse->srcpad, gst_mpeg_parse_handle_src_event); - gst_pad_set_query_type_function (mpeg_parse->srcpad, gst_mpeg_parse_get_src_query_types); - gst_pad_set_query_function (mpeg_parse->srcpad, gst_mpeg_parse_handle_src_query); + gst_pad_set_event_mask_function (mpeg_parse->srcpad, + gst_mpeg_parse_get_src_event_masks); + gst_pad_set_event_function (mpeg_parse->srcpad, + gst_mpeg_parse_handle_src_event); + gst_pad_set_query_type_function (mpeg_parse->srcpad, + gst_mpeg_parse_get_src_query_types); + gst_pad_set_query_function (mpeg_parse->srcpad, + gst_mpeg_parse_handle_src_query); gst_pad_use_explicit_caps (mpeg_parse->srcpad); gst_element_set_loop_function (GST_ELEMENT (mpeg_parse), gst_mpeg_parse_loop); @@ -208,16 +215,16 @@ gst_mpeg_parse_init (GstMPEGParse *mpeg_parse) } static void -gst_mpeg_parse_set_clock (GstElement *element, GstClock *clock) -{ +gst_mpeg_parse_set_clock (GstElement * element, GstClock * clock) +{ GstMPEGParse *parse = GST_MPEG_PARSE (element); parse->clock = clock; -} +} #if 0 static void -gst_mpeg_parse_update_streaminfo (GstMPEGParse *mpeg_parse) +gst_mpeg_parse_update_streaminfo (GstMPEGParse * mpeg_parse) { GstProps *props; GstPropsEntry *entry; @@ -229,12 +236,12 @@ gst_mpeg_parse_update_streaminfo (GstMPEGParse *mpeg_parse) entry = gst_props_entry_new ("mpegversion", G_TYPE_INT (mpeg2 ? 2 : 1)); gst_props_add_entry (props, (GstPropsEntry *) entry); - entry = gst_props_entry_new ("bitrate", G_TYPE_INT (mpeg_parse->mux_rate * 400)); + entry = + gst_props_entry_new ("bitrate", G_TYPE_INT (mpeg_parse->mux_rate * 400)); gst_props_add_entry (props, (GstPropsEntry *) entry); caps = gst_caps_new ("mpeg_streaminfo", - "application/x-gst-streaminfo", - props); + "application/x-gst-streaminfo", props); gst_caps_replace_sink (&mpeg_parse->streaminfo, caps); g_object_notify (G_OBJECT (mpeg_parse), "streaminfo"); @@ -242,7 +249,8 @@ gst_mpeg_parse_update_streaminfo (GstMPEGParse *mpeg_parse) #endif static void -gst_mpeg_parse_send_data (GstMPEGParse *mpeg_parse, GstData *data, GstClockTime time) +gst_mpeg_parse_send_data (GstMPEGParse * mpeg_parse, GstData * data, + GstClockTime time) { if (GST_IS_EVENT (data)) { GstEvent *event = GST_EVENT (data); @@ -252,16 +260,15 @@ gst_mpeg_parse_send_data (GstMPEGParse *mpeg_parse, GstData *data, GstClockTime gst_pad_event_default (mpeg_parse->sinkpad, event); break; } - } - else { + } else { if (!GST_PAD_CAPS (mpeg_parse->srcpad)) { gboolean mpeg2 = GST_MPEG_PACKETIZE_IS_MPEG2 (mpeg_parse->packetize); gst_pad_set_explicit_caps (mpeg_parse->srcpad, gst_caps_new_simple ("video/mpeg", - "mpegversion", G_TYPE_INT, (mpeg2 ? 2 : 1), - "systemstream", G_TYPE_BOOLEAN, TRUE, - "parsed", G_TYPE_BOOLEAN, TRUE, NULL)); + "mpegversion", G_TYPE_INT, (mpeg2 ? 2 : 1), + "systemstream", G_TYPE_BOOLEAN, TRUE, + "parsed", G_TYPE_BOOLEAN, TRUE, NULL)); } GST_BUFFER_TIMESTAMP (data) = time; @@ -275,12 +282,12 @@ gst_mpeg_parse_send_data (GstMPEGParse *mpeg_parse, GstData *data, GstClockTime } static void -gst_mpeg_parse_handle_discont (GstMPEGParse *mpeg_parse) +gst_mpeg_parse_handle_discont (GstMPEGParse * mpeg_parse) { GstEvent *event; - event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, - MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr), NULL); + event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, + MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr), NULL); if (GST_PAD_IS_USABLE (mpeg_parse->srcpad)) gst_pad_push (mpeg_parse->srcpad, GST_DATA (event)); @@ -289,7 +296,7 @@ gst_mpeg_parse_handle_discont (GstMPEGParse *mpeg_parse) } static gboolean -gst_mpeg_parse_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) +gst_mpeg_parse_parse_packhead (GstMPEGParse * mpeg_parse, GstBuffer * buffer) { guint8 *buf; guint64 scr, scr_adj, scr_orig; @@ -301,14 +308,14 @@ gst_mpeg_parse_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) buf = GST_BUFFER_DATA (buffer); buf += 4; - scr1 = GUINT32_FROM_BE (*(guint32*) buf); - scr2 = GUINT32_FROM_BE (*(guint32*) (buf+4)); + scr1 = GUINT32_FROM_BE (*(guint32 *) buf); + scr2 = GUINT32_FROM_BE (*(guint32 *) (buf + 4)); if (GST_MPEG_PACKETIZE_IS_MPEG2 (mpeg_parse->packetize)) { guint32 scr_ext; /* :2=01 ! scr:3 ! marker:1==1 ! scr:15 ! marker:1==1 ! scr:15 */ - scr = ((guint64) scr1 & 0x38000000) << 3; + scr = ((guint64) scr1 & 0x38000000) << 3; scr |= ((guint64) scr1 & 0x03fff800) << 4; scr |= ((guint64) scr1 & 0x000003ff) << 5; scr |= ((guint64) scr2 & 0xf8000000) >> 27; @@ -317,15 +324,14 @@ gst_mpeg_parse_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) scr = (scr * 300 + scr_ext % 300) / 300; - GST_DEBUG ("%" G_GINT64_FORMAT " %d, %08x %08x %" G_GINT64_FORMAT " diff: %" G_GINT64_FORMAT, - scr, scr_ext, scr1, scr2, mpeg_parse->bytes_since_scr, - scr - mpeg_parse->current_scr); + GST_DEBUG ("%" G_GINT64_FORMAT " %d, %08x %08x %" G_GINT64_FORMAT " diff: %" + G_GINT64_FORMAT, scr, scr_ext, scr1, scr2, mpeg_parse->bytes_since_scr, + scr - mpeg_parse->current_scr); buf += 6; new_rate = (GUINT32_FROM_BE ((*(guint32 *) buf)) & 0xfffffc00) >> 10; - } - else { - scr = ((guint64) scr1 & 0x0e000000) << 5; + } else { + scr = ((guint64) scr1 & 0x0e000000) << 5; scr |= ((guint64) scr1 & 0x00fffe00) << 6; scr |= ((guint64) scr1 & 0x000000ff) << 7; scr |= ((guint64) scr2 & 0xfe000000) >> 25; @@ -333,9 +339,9 @@ gst_mpeg_parse_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) buf += 5; /* we do this byte by byte because buf[3] might be outside of buf's * memory space */ - new_rate = ((gint32) buf[0] & 0x7f) << 15; + new_rate = ((gint32) buf[0] & 0x7f) << 15; new_rate |= ((gint32) buf[1]) << 7; - new_rate |= buf[2] >> 1; + new_rate |= buf[2] >> 1; } scr_orig = scr; @@ -346,38 +352,36 @@ gst_mpeg_parse_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) mpeg_parse->next_scr = scr; } - GST_DEBUG ("SCR is %" G_GUINT64_FORMAT " (%" G_GUINT64_FORMAT ") next: %" - G_GINT64_FORMAT " (%" G_GINT64_FORMAT ") diff: %" G_GINT64_FORMAT " (%" - G_GINT64_FORMAT ")", - scr, - MPEGTIME_TO_GSTTIME (scr), - mpeg_parse->next_scr, - MPEGTIME_TO_GSTTIME (mpeg_parse->next_scr), - scr - mpeg_parse->next_scr, - MPEGTIME_TO_GSTTIME (scr) - - MPEGTIME_TO_GSTTIME (mpeg_parse->next_scr)); + GST_DEBUG ("SCR is %" G_GUINT64_FORMAT " (%" G_GUINT64_FORMAT ") next: %" + G_GINT64_FORMAT " (%" G_GINT64_FORMAT ") diff: %" G_GINT64_FORMAT " (%" + G_GINT64_FORMAT ")", + scr, + MPEGTIME_TO_GSTTIME (scr), + mpeg_parse->next_scr, + MPEGTIME_TO_GSTTIME (mpeg_parse->next_scr), + scr - mpeg_parse->next_scr, + MPEGTIME_TO_GSTTIME (scr) - MPEGTIME_TO_GSTTIME (mpeg_parse->next_scr)); - if (ABS ((gint64)mpeg_parse->next_scr - (gint64)(scr_adj)) > mpeg_parse->max_discont) { - GST_DEBUG ("discontinuity detected; expected: %" - G_GUINT64_FORMAT " got: %" G_GUINT64_FORMAT " real:%" - G_GINT64_FORMAT " adjust:%" G_GINT64_FORMAT, - mpeg_parse->next_scr, scr_adj, scr, mpeg_parse->adjust); + if (ABS ((gint64) mpeg_parse->next_scr - (gint64) (scr_adj)) > + mpeg_parse->max_discont) { + GST_DEBUG ("discontinuity detected; expected: %" G_GUINT64_FORMAT " got: %" + G_GUINT64_FORMAT " real:%" G_GINT64_FORMAT " adjust:%" G_GINT64_FORMAT, + mpeg_parse->next_scr, scr_adj, scr, mpeg_parse->adjust); mpeg_parse->adjust = mpeg_parse->next_scr - scr; scr = mpeg_parse->next_scr; GST_DEBUG ("new adjust: %" G_GINT64_FORMAT, mpeg_parse->adjust); - } - else { + } else { scr = scr_adj; } if (mpeg_parse->index && GST_INDEX_IS_WRITABLE (mpeg_parse->index)) { /* update index if any */ - gst_index_add_association (mpeg_parse->index, mpeg_parse->index_id, - GST_ASSOCIATION_FLAG_KEY_UNIT, - GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buffer), - GST_FORMAT_TIME, MPEGTIME_TO_GSTTIME (scr), 0); + gst_index_add_association (mpeg_parse->index, mpeg_parse->index_id, + GST_ASSOCIATION_FLAG_KEY_UNIT, + GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buffer), + GST_FORMAT_TIME, MPEGTIME_TO_GSTTIME (scr), 0); } mpeg_parse->current_scr = scr; @@ -394,7 +398,7 @@ gst_mpeg_parse_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer) } static void -gst_mpeg_parse_loop (GstElement *element) +gst_mpeg_parse_loop (GstElement * element) { GstMPEGParse *mpeg_parse = GST_MPEG_PARSE (element); GstData *data; @@ -408,7 +412,7 @@ gst_mpeg_parse_loop (GstElement *element) id = GST_MPEG_PACKETIZE_ID (mpeg_parse->packetize); mpeg2 = GST_MPEG_PACKETIZE_IS_MPEG2 (mpeg_parse->packetize); - + if (GST_IS_BUFFER (data)) { GstBuffer *buffer = GST_BUFFER (data); @@ -418,7 +422,7 @@ gst_mpeg_parse_loop (GstElement *element) case 0xb9: break; case 0xba: - if (CLASS (mpeg_parse)->parse_packhead) { + if (CLASS (mpeg_parse)->parse_packhead) { CLASS (mpeg_parse)->parse_packhead (mpeg_parse, buffer); } break; @@ -428,21 +432,19 @@ gst_mpeg_parse_loop (GstElement *element) } break; default: - if (mpeg2 && ((id < 0xBD) || (id > 0xFE))) { - g_warning ("******** unknown id 0x%02X", id); - } - else { + if (mpeg2 && ((id < 0xBD) || (id > 0xFE))) { + g_warning ("******** unknown id 0x%02X", id); + } else { if (mpeg2) { if (CLASS (mpeg_parse)->parse_pes) { CLASS (mpeg_parse)->parse_pes (mpeg_parse, buffer); } - } - else { + } else { if (CLASS (mpeg_parse)->parse_packet) { CLASS (mpeg_parse)->parse_packet (mpeg_parse, buffer); } } - } + } } } @@ -453,10 +455,10 @@ gst_mpeg_parse_loop (GstElement *element) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_DISCONTINUOUS: - GST_DEBUG ("event: %d\n", GST_EVENT_TYPE (data)); + GST_DEBUG ("event: %d\n", GST_EVENT_TYPE (data)); - mpeg_parse->discont_pending = TRUE; - mpeg_parse->packetize->resync = TRUE; + mpeg_parse->discont_pending = TRUE; + mpeg_parse->packetize->resync = TRUE; gst_event_unref (event); return; default: @@ -466,25 +468,24 @@ gst_mpeg_parse_loop (GstElement *element) CLASS (mpeg_parse)->send_data (mpeg_parse, data, time); else gst_event_unref (event); - } - else { + } else { guint64 size; - + /* we're not sending data as long as no new SCR was found */ if (mpeg_parse->discont_pending) { if (!mpeg_parse->scr_pending) { - if (mpeg_parse->clock && mpeg_parse->sync) { - gst_element_set_time (GST_ELEMENT (mpeg_parse), MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr)); - } + if (mpeg_parse->clock && mpeg_parse->sync) { + gst_element_set_time (GST_ELEMENT (mpeg_parse), + MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr)); + } if (CLASS (mpeg_parse)->handle_discont) { CLASS (mpeg_parse)->handle_discont (mpeg_parse); } - mpeg_parse->discont_pending = FALSE; - } - else { + mpeg_parse->discont_pending = FALSE; + } else { GST_DEBUG ("waiting for SCR"); - gst_buffer_unref (GST_BUFFER (data)); - return; + gst_buffer_unref (GST_BUFFER (data)); + return; } } @@ -495,11 +496,10 @@ gst_mpeg_parse_loop (GstElement *element) gboolean mpeg2 = GST_MPEG_PACKETIZE_IS_MPEG2 (mpeg_parse->packetize); if (gst_pad_try_set_caps (mpeg_parse->sinkpad, - gst_caps_new_simple ("video/mpeg", - "mpegversion", G_TYPE_INT, (mpeg2 ? 2 : 1), - "systemstream", G_TYPE_BOOLEAN, TRUE, - "parsed", G_TYPE_BOOLEAN, TRUE, NULL)) < 0) - { + gst_caps_new_simple ("video/mpeg", + "mpegversion", G_TYPE_INT, (mpeg2 ? 2 : 1), + "systemstream", G_TYPE_BOOLEAN, TRUE, + "parsed", G_TYPE_BOOLEAN, TRUE, NULL)) < 0) { GST_ELEMENT_ERROR (mpeg_parse, CORE, NEGOTIATION, (NULL), (NULL)); return; } @@ -513,53 +513,51 @@ gst_mpeg_parse_loop (GstElement *element) gst_element_wait (GST_ELEMENT (mpeg_parse), time); } - if (mpeg_parse->current_scr != -1) - { + if (mpeg_parse->current_scr != -1) { guint64 scr, bss, br; scr = mpeg_parse->current_scr; bss = mpeg_parse->bytes_since_scr; br = mpeg_parse->mux_rate * 50; - + if (br) { - if (GST_MPEG_PACKETIZE_IS_MPEG2 (mpeg_parse->packetize)) { - /* + if (GST_MPEG_PACKETIZE_IS_MPEG2 (mpeg_parse->packetize)) { + /* * The mpeg spec says something like this, but that doesn't really work: * * mpeg_parse->next_scr = (scr * br + bss * CLOCK_FREQ) / (CLOCK_FREQ + br); */ - mpeg_parse->next_scr = scr + (bss * CLOCK_FREQ) / br; - } - else { - /* we are interpolating the scr here */ - mpeg_parse->next_scr = scr + (bss * CLOCK_FREQ) / br; - } - } - else { + mpeg_parse->next_scr = scr + (bss * CLOCK_FREQ) / br; + } else { + /* we are interpolating the scr here */ + mpeg_parse->next_scr = scr + (bss * CLOCK_FREQ) / br; + } + } else { /* no bitrate known */ - mpeg_parse->next_scr = scr; + mpeg_parse->next_scr = scr; } - GST_DEBUG ("size: %" G_GINT64_FORMAT ", total since SCR: %" G_GINT64_FORMAT ", next SCR: %" G_GINT64_FORMAT, - size, bss, mpeg_parse->next_scr); + GST_DEBUG ("size: %" G_GINT64_FORMAT ", total since SCR: %" + G_GINT64_FORMAT ", next SCR: %" G_GINT64_FORMAT, size, bss, + mpeg_parse->next_scr); } } } -const GstFormat* -gst_mpeg_parse_get_src_formats (GstPad *pad) +const GstFormat * +gst_mpeg_parse_get_src_formats (GstPad * pad) { static const GstFormat formats[] = { GST_FORMAT_BYTES, - GST_FORMAT_TIME, - 0 + GST_FORMAT_TIME, + 0 }; return formats; } gboolean -gst_mpeg_parse_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value) +gst_mpeg_parse_convert_src (GstPad * pad, GstFormat src_format, + gint64 src_value, GstFormat * dest_format, gint64 * dest_value) { gboolean res = TRUE; GstMPEGParse *mpeg_parse = GST_MPEG_PARSE (gst_pad_get_parent (pad)); @@ -567,27 +565,27 @@ gst_mpeg_parse_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, switch (src_format) { case GST_FORMAT_BYTES: switch (*dest_format) { - case GST_FORMAT_DEFAULT: - *dest_format = GST_FORMAT_TIME; - case GST_FORMAT_TIME: + case GST_FORMAT_DEFAULT: + *dest_format = GST_FORMAT_TIME; + case GST_FORMAT_TIME: if (mpeg_parse->mux_rate == 0) res = FALSE; else - *dest_value = src_value * GST_SECOND / (mpeg_parse->mux_rate * 50); - break; - default: - res = FALSE; + *dest_value = src_value * GST_SECOND / (mpeg_parse->mux_rate * 50); + break; + default: + res = FALSE; } break; case GST_FORMAT_TIME: switch (*dest_format) { - case GST_FORMAT_DEFAULT: - *dest_format = GST_FORMAT_BYTES; - case GST_FORMAT_BYTES: - *dest_value = mpeg_parse->mux_rate * 50 * src_value / GST_SECOND; - break; - default: - res = FALSE; + case GST_FORMAT_DEFAULT: + *dest_format = GST_FORMAT_BYTES; + case GST_FORMAT_BYTES: + *dest_value = mpeg_parse->mux_rate * 50 * src_value / GST_SECOND; + break; + default: + res = FALSE; } break; default: @@ -597,20 +595,20 @@ gst_mpeg_parse_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, return res; } -const GstQueryType* -gst_mpeg_parse_get_src_query_types (GstPad *pad) +const GstQueryType * +gst_mpeg_parse_get_src_query_types (GstPad * pad) { static const GstQueryType types[] = { GST_QUERY_TOTAL, GST_QUERY_POSITION, - 0 + 0 }; return types; } gboolean -gst_mpeg_parse_handle_src_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value) +gst_mpeg_parse_handle_src_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value) { gboolean res = TRUE; GstMPEGParse *mpeg_parse = GST_MPEG_PARSE (gst_pad_get_parent (pad)); @@ -621,14 +619,13 @@ gst_mpeg_parse_handle_src_query (GstPad *pad, GstQueryType type, case GST_QUERY_TOTAL: { switch (*format) { - case GST_FORMAT_DEFAULT: - *format = GST_FORMAT_TIME; - /* fallthrough */ + case GST_FORMAT_DEFAULT: + *format = GST_FORMAT_TIME; + /* fallthrough */ default: src_format = GST_FORMAT_BYTES; if (!gst_pad_query (GST_PAD_PEER (mpeg_parse->sinkpad), - GST_QUERY_TOTAL, &src_format, &src_value)) - { + GST_QUERY_TOTAL, &src_format, &src_value)) { res = FALSE; } break; @@ -638,12 +635,12 @@ gst_mpeg_parse_handle_src_query (GstPad *pad, GstQueryType type, case GST_QUERY_POSITION: { switch (*format) { - case GST_FORMAT_DEFAULT: - *format = GST_FORMAT_TIME; - /* fallthrough */ + case GST_FORMAT_DEFAULT: + *format = GST_FORMAT_TIME; + /* fallthrough */ default: src_format = GST_FORMAT_TIME; - src_value = MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr); + src_value = MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr); break; } break; @@ -660,26 +657,25 @@ gst_mpeg_parse_handle_src_query (GstPad *pad, GstQueryType type, return res; } -const GstEventMask* -gst_mpeg_parse_get_src_event_masks (GstPad *pad) +const GstEventMask * +gst_mpeg_parse_get_src_event_masks (GstPad * pad) { static const GstEventMask masks[] = { - { GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH }, - { 0, } + {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH}, + {0,} }; return masks; } static gboolean -index_seek (GstPad *pad, GstEvent *event, guint64 *offset, gint64 *scr) +index_seek (GstPad * pad, GstEvent * event, guint64 * offset, gint64 * scr) { GstIndexEntry *entry; GstMPEGParse *mpeg_parse = GST_MPEG_PARSE (gst_pad_get_parent (pad)); entry = gst_index_get_assoc_entry (mpeg_parse->index, mpeg_parse->index_id, - GST_INDEX_LOOKUP_BEFORE, 0, - GST_EVENT_SEEK_FORMAT (event), - GST_EVENT_SEEK_OFFSET (event)); + GST_INDEX_LOOKUP_BEFORE, 0, + GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event)); if (!entry) return FALSE; @@ -690,18 +686,17 @@ index_seek (GstPad *pad, GstEvent *event, guint64 *offset, gint64 *scr) *scr = GSTTIME_TO_MPEGTIME (time); } GST_CAT_DEBUG (GST_CAT_SEEK, "%s:%s index %s %" G_GINT64_FORMAT - " -> %" G_GINT64_FORMAT " bytes, scr=%" G_GINT64_FORMAT, - GST_DEBUG_PAD_NAME (pad), - gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, - GST_EVENT_SEEK_OFFSET (event), - *offset, *scr); + " -> %" G_GINT64_FORMAT " bytes, scr=%" G_GINT64_FORMAT, + GST_DEBUG_PAD_NAME (pad), + gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick, + GST_EVENT_SEEK_OFFSET (event), *offset, *scr); return TRUE; } return FALSE; } static gboolean -normal_seek (GstPad *pad, GstEvent *event, guint64 *offset, gint64 *scr) +normal_seek (GstPad * pad, GstEvent * event, guint64 * offset, gint64 * scr) { gboolean res; GstFormat format; @@ -709,18 +704,14 @@ normal_seek (GstPad *pad, GstEvent *event, guint64 *offset, gint64 *scr) /* bring offset to bytes */ format = GST_FORMAT_BYTES; - res = gst_pad_convert (pad, - GST_EVENT_SEEK_FORMAT (event), - GST_EVENT_SEEK_OFFSET (event), - &format, - offset); + res = gst_pad_convert (pad, + GST_EVENT_SEEK_FORMAT (event), + GST_EVENT_SEEK_OFFSET (event), &format, offset); /* bring offset to time */ format = GST_FORMAT_TIME; - res &= gst_pad_convert (pad, - GST_EVENT_SEEK_FORMAT (event), - GST_EVENT_SEEK_OFFSET (event), - &format, - &time); + res &= gst_pad_convert (pad, + GST_EVENT_SEEK_FORMAT (event), + GST_EVENT_SEEK_OFFSET (event), &format, &time); /* convert to scr */ *scr = GSTTIME_TO_MPEGTIME (time); @@ -729,7 +720,7 @@ normal_seek (GstPad *pad, GstEvent *event, guint64 *offset, gint64 *scr) } gboolean -gst_mpeg_parse_handle_src_event (GstPad *pad, GstEvent *event) +gst_mpeg_parse_handle_src_event (GstPad * pad, GstEvent * event) { gboolean res = FALSE; GstMPEGParse *mpeg_parse = GST_MPEG_PARSE (gst_pad_get_parent (pad)); @@ -741,23 +732,24 @@ gst_mpeg_parse_handle_src_event (GstPad *pad, GstEvent *event) guint64 expected_scr; /* first to to use the index if we have one */ - if (mpeg_parse->index) - res = index_seek (pad, event, &desired_offset, &expected_scr); + if (mpeg_parse->index) + res = index_seek (pad, event, &desired_offset, &expected_scr); /* nothing found, try fuzzy seek */ - if (!res) - res = normal_seek (pad, event, &desired_offset, &expected_scr); + if (!res) + res = normal_seek (pad, event, &desired_offset, &expected_scr); if (!res) break; - + GST_DEBUG ("sending seek to %" G_GINT64_FORMAT, desired_offset); - if (gst_bytestream_seek (mpeg_parse->packetize->bs, desired_offset, GST_SEEK_METHOD_SET)) { - mpeg_parse->discont_pending = TRUE; - mpeg_parse->scr_pending = TRUE; - mpeg_parse->next_scr = expected_scr; - mpeg_parse->current_scr = -1; - mpeg_parse->adjust = 0; - res = TRUE; + if (gst_bytestream_seek (mpeg_parse->packetize->bs, desired_offset, + GST_SEEK_METHOD_SET)) { + mpeg_parse->discont_pending = TRUE; + mpeg_parse->scr_pending = TRUE; + mpeg_parse->next_scr = expected_scr; + mpeg_parse->current_scr = -1; + mpeg_parse->adjust = 0; + res = TRUE; } break; } @@ -769,14 +761,16 @@ gst_mpeg_parse_handle_src_event (GstPad *pad, GstEvent *event) } static GstElementStateReturn -gst_mpeg_parse_change_state (GstElement *element) +gst_mpeg_parse_change_state (GstElement * element) { GstMPEGParse *mpeg_parse = GST_MPEG_PARSE (element); switch (GST_STATE_TRANSITION (element)) { case GST_STATE_READY_TO_PAUSED: if (!mpeg_parse->packetize) { - mpeg_parse->packetize = gst_mpeg_packetize_new (mpeg_parse->sinkpad, GST_MPEG_PACKETIZE_SYSTEM); + mpeg_parse->packetize = + gst_mpeg_packetize_new (mpeg_parse->sinkpad, + GST_MPEG_PACKETIZE_SYSTEM); } /* initialize parser state */ mpeg_parse->current_scr = 0; @@ -791,8 +785,8 @@ gst_mpeg_parse_change_state (GstElement *element) break; case GST_STATE_PAUSED_TO_READY: if (mpeg_parse->packetize) { - gst_mpeg_packetize_destroy (mpeg_parse->packetize); - mpeg_parse->packetize = NULL; + gst_mpeg_packetize_destroy (mpeg_parse->packetize); + mpeg_parse->packetize = NULL; } //gst_caps_replace (&mpeg_parse->streaminfo, NULL); break; @@ -804,72 +798,73 @@ gst_mpeg_parse_change_state (GstElement *element) } static void -gst_mpeg_parse_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - GstMPEGParse *mpeg_parse; - - mpeg_parse = GST_MPEG_PARSE(object); - - switch (prop_id) { - case ARG_SYNC: - g_value_set_boolean (value, mpeg_parse->sync); - break; - case ARG_MAX_DISCONT: - g_value_set_int (value, mpeg_parse->max_discont); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gst_mpeg_parse_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) +gst_mpeg_parse_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstMPEGParse *mpeg_parse; mpeg_parse = GST_MPEG_PARSE (object); switch (prop_id) { - case ARG_SYNC: - mpeg_parse->sync = g_value_get_boolean (value); + case ARG_SYNC: + g_value_set_boolean (value, mpeg_parse->sync); break; - case ARG_MAX_DISCONT: - mpeg_parse->max_discont = g_value_get_int (value); + case ARG_MAX_DISCONT: + g_value_set_int (value, mpeg_parse->max_discont); break; - default: + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void -gst_mpeg_parse_set_index (GstElement *element, GstIndex *index) +gst_mpeg_parse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstMPEGParse *mpeg_parse; + + mpeg_parse = GST_MPEG_PARSE (object); + + switch (prop_id) { + case ARG_SYNC: + mpeg_parse->sync = g_value_get_boolean (value); + break; + case ARG_MAX_DISCONT: + mpeg_parse->max_discont = g_value_get_int (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_mpeg_parse_set_index (GstElement * element, GstIndex * index) { GstMPEGParse *mpeg_parse; mpeg_parse = GST_MPEG_PARSE (element); - + mpeg_parse->index = index; gst_index_get_writer_id (index, GST_OBJECT (mpeg_parse->sinkpad), - &mpeg_parse->index_id); + &mpeg_parse->index_id); gst_index_add_format (index, mpeg_parse->index_id, scr_format); } -static GstIndex* -gst_mpeg_parse_get_index (GstElement *element) +static GstIndex * +gst_mpeg_parse_get_index (GstElement * element) { GstMPEGParse *mpeg_parse; mpeg_parse = GST_MPEG_PARSE (element); - + return mpeg_parse->index; } static gboolean -gst_mpeg_parse_release_locks (GstElement *element) +gst_mpeg_parse_release_locks (GstElement * element) { GstMPEGParse *mpeg_parse; @@ -884,10 +879,11 @@ gst_mpeg_parse_release_locks (GstElement *element) } gboolean -gst_mpeg_parse_plugin_init (GstPlugin *plugin) +gst_mpeg_parse_plugin_init (GstPlugin * plugin) { - scr_format = gst_format_register ("scr", "The MPEG system clock reference time"); + scr_format = + gst_format_register ("scr", "The MPEG system clock reference time"); return gst_element_register (plugin, "mpegparse", - GST_RANK_NONE, GST_TYPE_MPEG_PARSE); + GST_RANK_NONE, GST_TYPE_MPEG_PARSE); } diff --git a/gst/mpegstream/gstmpegparse.h b/gst/mpegstream/gstmpegparse.h index a99bb33e36..f756391f33 100644 --- a/gst/mpegstream/gstmpegparse.h +++ b/gst/mpegstream/gstmpegparse.h @@ -26,8 +26,9 @@ #include "gstmpegpacketize.h" #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_MPEG_PARSE \ @@ -49,71 +50,70 @@ extern "C" { #define MPEGTIME_TO_GSTTIME(time) (((time) * (GST_MSECOND/10)) / CLOCK_BASE) #define GSTTIME_TO_MPEGTIME(time) (((time) * CLOCK_BASE) / (GST_MSECOND/10)) -typedef struct _GstMPEGParse GstMPEGParse; -typedef struct _GstMPEGParseClass GstMPEGParseClass; + typedef struct _GstMPEGParse GstMPEGParse; + typedef struct _GstMPEGParseClass GstMPEGParseClass; -struct _GstMPEGParse { - GstElement element; + struct _GstMPEGParse + { + GstElement element; - GstPad *sinkpad, *srcpad; + GstPad *sinkpad, *srcpad; - GstMPEGPacketize *packetize; + GstMPEGPacketize *packetize; - /* pack header values */ - guint32 mux_rate; - guint64 current_scr; - guint64 next_scr; - guint64 bytes_since_scr; + /* pack header values */ + guint32 mux_rate; + guint64 current_scr; + guint64 next_scr; + guint64 bytes_since_scr; - gint64 adjust; + gint64 adjust; - gboolean discont_pending; - gboolean scr_pending; - gint max_discont; + gboolean discont_pending; + gboolean scr_pending; + gint max_discont; - GstClock *clock; - gboolean sync; - GstClockID id; + GstClock *clock; + gboolean sync; + GstClockID id; - GstIndex *index; - gint index_id; -}; + GstIndex *index; + gint index_id; + }; -struct _GstMPEGParseClass { - GstElementClass parent_class; + struct _GstMPEGParseClass + { + GstElementClass parent_class; - /* process packet types */ - gboolean (*parse_packhead) (GstMPEGParse *parse, GstBuffer *buffer); - gboolean (*parse_syshead) (GstMPEGParse *parse, GstBuffer *buffer); - gboolean (*parse_packet) (GstMPEGParse *parse, GstBuffer *buffer); - gboolean (*parse_pes) (GstMPEGParse *parse, GstBuffer *buffer); + /* process packet types */ + gboolean (*parse_packhead) (GstMPEGParse * parse, GstBuffer * buffer); + gboolean (*parse_syshead) (GstMPEGParse * parse, GstBuffer * buffer); + gboolean (*parse_packet) (GstMPEGParse * parse, GstBuffer * buffer); + gboolean (*parse_pes) (GstMPEGParse * parse, GstBuffer * buffer); - /* optional method to send out the data */ - void (*send_data) (GstMPEGParse *parse, GstData *data, GstClockTime time); - void (*handle_discont) (GstMPEGParse *parse); -}; + /* optional method to send out the data */ + void (*send_data) (GstMPEGParse * parse, GstData * data, GstClockTime time); + void (*handle_discont) (GstMPEGParse * parse); + }; -GType gst_mpeg_parse_get_type(void); + GType gst_mpeg_parse_get_type (void); -gboolean gst_mpeg_parse_plugin_init (GstPlugin *plugin); + gboolean gst_mpeg_parse_plugin_init (GstPlugin * plugin); -const GstFormat* - gst_mpeg_parse_get_src_formats (GstPad *pad); - -gboolean gst_mpeg_parse_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value); -const GstEventMask* - gst_mpeg_parse_get_src_event_masks (GstPad *pad); -gboolean gst_mpeg_parse_handle_src_event (GstPad *pad, GstEvent *event); + const GstFormat *gst_mpeg_parse_get_src_formats (GstPad * pad); -const GstQueryType* - gst_mpeg_parse_get_src_query_types (GstPad *pad); -gboolean gst_mpeg_parse_handle_src_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value); + gboolean gst_mpeg_parse_convert_src (GstPad * pad, GstFormat src_format, + gint64 src_value, GstFormat * dest_format, gint64 * dest_value); + const GstEventMask *gst_mpeg_parse_get_src_event_masks (GstPad * pad); + gboolean gst_mpeg_parse_handle_src_event (GstPad * pad, GstEvent * event); + + const GstQueryType *gst_mpeg_parse_get_src_query_types (GstPad * pad); + gboolean gst_mpeg_parse_handle_src_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __MPEG_PARSE_H__ */ +#endif /* __MPEG_PARSE_H__ */ diff --git a/gst/mpegstream/gstmpegstream.c b/gst/mpegstream/gstmpegstream.c index 58866d2ece..ef1e609cef 100644 --- a/gst/mpegstream/gstmpegstream.c +++ b/gst/mpegstream/gstmpegstream.c @@ -26,13 +26,13 @@ #include "gstrfc2250enc.h" static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { /* short-circuit here; this is potentially dangerous since if the second * or third init fails then the whole plug-in will be placed on the register * stack again and the first _init will be called more than once * and wtay wants to use dlclose at some point in the future */ - + if (!gst_library_load ("gstbytestream")) return FALSE; @@ -44,14 +44,8 @@ plugin_init (GstPlugin *plugin) return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "mpegstream", - "MPEG system stream parser", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mpegstream", + "MPEG system stream parser", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/gst/mpegstream/gstrfc2250enc.c b/gst/mpegstream/gstrfc2250enc.c index a2f8de60e2..c7a0d259a2 100644 --- a/gst/mpegstream/gstrfc2250enc.c +++ b/gst/mpegstream/gstrfc2250enc.c @@ -35,52 +35,47 @@ static GstElementDetails rfc2250_enc_details = { #define CLASS(o) GST_RFC2250_ENC_CLASS (G_OBJECT_GET_CLASS (o)) /* GstRFC2250Enc signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_BIT_RATE, ARG_MPEG2, /* FILL ME */ }; -static GstStaticPadTemplate sink_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/mpeg, " - "mpegversion = (int) [ 1, 2 ], " - "systemstream = (boolean) FALSE" - ) -); +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/mpeg, " + "mpegversion = (int) [ 1, 2 ], " "systemstream = (boolean) FALSE") + ); -static GstStaticPadTemplate src_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/mpeg, " - "mpegversion = (int) [ 1, 2 ], " - "systemstream = (boolean) FALSE" - ) -); +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/mpeg, " + "mpegversion = (int) [ 1, 2 ], " "systemstream = (boolean) FALSE") + ); -static void gst_rfc2250_enc_class_init (GstRFC2250EncClass *klass); -static void gst_rfc2250_enc_base_init (GstRFC2250EncClass *klass); -static void gst_rfc2250_enc_init (GstRFC2250Enc *rfc2250_enc); +static void gst_rfc2250_enc_class_init (GstRFC2250EncClass * klass); +static void gst_rfc2250_enc_base_init (GstRFC2250EncClass * klass); +static void gst_rfc2250_enc_init (GstRFC2250Enc * rfc2250_enc); static GstElementStateReturn - gst_rfc2250_enc_change_state (GstElement *element); +gst_rfc2250_enc_change_state (GstElement * element); -static void gst_rfc2250_enc_loop (GstElement *element); +static void gst_rfc2250_enc_loop (GstElement * element); -static void gst_rfc2250_enc_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); +static void gst_rfc2250_enc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); static GstElementClass *parent_class = NULL; + /*static guint gst_rfc2250_enc_signals[LAST_SIGNAL] = { 0 };*/ GType @@ -90,50 +85,52 @@ gst_rfc2250_enc_get_type (void) if (!rfc2250_enc_type) { static const GTypeInfo rfc2250_enc_info = { - sizeof(GstRFC2250EncClass), - (GBaseInitFunc)gst_rfc2250_enc_base_init, + sizeof (GstRFC2250EncClass), + (GBaseInitFunc) gst_rfc2250_enc_base_init, NULL, - (GClassInitFunc)gst_rfc2250_enc_class_init, + (GClassInitFunc) gst_rfc2250_enc_class_init, NULL, NULL, - sizeof(GstRFC2250Enc), + sizeof (GstRFC2250Enc), 0, - (GInstanceInitFunc)gst_rfc2250_enc_init, + (GInstanceInitFunc) gst_rfc2250_enc_init, }; - rfc2250_enc_type = g_type_register_static(GST_TYPE_ELEMENT, "GstRFC2250Enc", &rfc2250_enc_info, 0); + rfc2250_enc_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstRFC2250Enc", + &rfc2250_enc_info, 0); } return rfc2250_enc_type; } static void -gst_rfc2250_enc_base_init (GstRFC2250EncClass *klass) +gst_rfc2250_enc_base_init (GstRFC2250EncClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_factory)); + gst_static_pad_template_get (&src_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_factory)); + gst_static_pad_template_get (&sink_factory)); gst_element_class_set_details (element_class, &rfc2250_enc_details); } static void -gst_rfc2250_enc_class_init (GstRFC2250EncClass *klass) +gst_rfc2250_enc_class_init (GstRFC2250EncClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BIT_RATE, - g_param_spec_uint("bit_rate","bit_rate","bit_rate", - 0, G_MAXUINT, 0, G_PARAM_READABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BIT_RATE, + g_param_spec_uint ("bit_rate", "bit_rate", "bit_rate", + 0, G_MAXUINT, 0, G_PARAM_READABLE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MPEG2, - g_param_spec_boolean ("mpeg2", "mpeg2", "is this an mpeg2 stream", - FALSE, G_PARAM_READABLE)); + g_param_spec_boolean ("mpeg2", "mpeg2", "is this an mpeg2 stream", + FALSE, G_PARAM_READABLE)); gobject_class->get_property = gst_rfc2250_enc_get_property; @@ -141,15 +138,18 @@ gst_rfc2250_enc_class_init (GstRFC2250EncClass *klass) } static void -gst_rfc2250_enc_init (GstRFC2250Enc *rfc2250_enc) +gst_rfc2250_enc_init (GstRFC2250Enc * rfc2250_enc) { - rfc2250_enc->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&sink_factory), "sink"); - gst_element_add_pad(GST_ELEMENT(rfc2250_enc),rfc2250_enc->sinkpad); - gst_element_set_loop_function (GST_ELEMENT (rfc2250_enc), gst_rfc2250_enc_loop); - rfc2250_enc->srcpad = gst_pad_new_from_template( - gst_static_pad_template_get (&src_factory), "src"); - gst_element_add_pad(GST_ELEMENT(rfc2250_enc),rfc2250_enc->srcpad); + rfc2250_enc->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get (&sink_factory), + "sink"); + gst_element_add_pad (GST_ELEMENT (rfc2250_enc), rfc2250_enc->sinkpad); + gst_element_set_loop_function (GST_ELEMENT (rfc2250_enc), + gst_rfc2250_enc_loop); + rfc2250_enc->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get (&src_factory), + "src"); + gst_element_add_pad (GST_ELEMENT (rfc2250_enc), rfc2250_enc->srcpad); /* initialize parser state */ rfc2250_enc->packetize = NULL; @@ -164,7 +164,7 @@ gst_rfc2250_enc_init (GstRFC2250Enc *rfc2250_enc) } static void -gst_rfc2250_enc_new_buffer (GstRFC2250Enc *enc) +gst_rfc2250_enc_new_buffer (GstRFC2250Enc * enc) { if (enc->packet) { gst_pad_push (enc->srcpad, GST_DATA (enc->packet)); @@ -175,7 +175,7 @@ gst_rfc2250_enc_new_buffer (GstRFC2250Enc *enc) } static void -gst_rfc2250_enc_add_slice (GstRFC2250Enc *enc, GstBuffer *buffer) +gst_rfc2250_enc_add_slice (GstRFC2250Enc * enc, GstBuffer * buffer) { gint slice_length = GST_BUFFER_SIZE (buffer); @@ -209,14 +209,17 @@ gst_rfc2250_enc_add_slice (GstRFC2250Enc *enc, GstBuffer *buffer) while (slice_length > 0) { GstBuffer *outbuf; GstBuffer *newbuf; - outbuf = gst_buffer_create_sub (buffer, offset, MIN (enc->remaining, slice_length)); - newbuf = gst_buffer_merge (enc->packet, outbuf); + + outbuf = + gst_buffer_create_sub (buffer, offset, MIN (enc->remaining, + slice_length)); + newbuf = gst_buffer_merge (enc->packet, outbuf); slice_length -= GST_BUFFER_SIZE (outbuf); offset += GST_BUFFER_SIZE (outbuf); gst_buffer_unref (outbuf); gst_buffer_unref (newbuf); enc->packet = newbuf; - gst_rfc2250_enc_new_buffer (enc); + gst_rfc2250_enc_new_buffer (enc); } gst_buffer_unref (buffer); } @@ -224,7 +227,7 @@ gst_rfc2250_enc_add_slice (GstRFC2250Enc *enc, GstBuffer *buffer) } static void -gst_rfc2250_enc_loop (GstElement *element) +gst_rfc2250_enc_loop (GstElement * element) { GstRFC2250Enc *enc = GST_RFC2250_ENC (element); GstData *data; @@ -235,7 +238,7 @@ gst_rfc2250_enc_loop (GstElement *element) id = GST_MPEG_PACKETIZE_ID (enc->packetize); mpeg2 = GST_MPEG_PACKETIZE_IS_MPEG2 (enc->packetize); - + if (GST_IS_BUFFER (data)) { GstBuffer *buffer = GST_BUFFER (data); @@ -264,8 +267,8 @@ gst_rfc2250_enc_loop (GstElement *element) case SEQUENCE_END_START_CODE: break; default: - /* do this here because of the long range */ - if (id >= SLICE_MIN_START_CODE && id <= SLICE_MAX_START_CODE) { + /* do this here because of the long range */ + if (id >= SLICE_MIN_START_CODE && id <= SLICE_MAX_START_CODE) { enc->flags |= ENC_HAVE_DATA; gst_rfc2250_enc_add_slice (enc, buffer); buffer = NULL; @@ -279,8 +282,7 @@ gst_rfc2250_enc_loop (GstElement *element) enc->remaining -= GST_BUFFER_SIZE (buffer); gst_buffer_unref (buffer); } - } - else { + } else { if (enc->packet) { gst_pad_push (enc->srcpad, GST_DATA (enc->packet)); enc->packet = NULL; @@ -292,20 +294,22 @@ gst_rfc2250_enc_loop (GstElement *element) } static GstElementStateReturn -gst_rfc2250_enc_change_state (GstElement *element) +gst_rfc2250_enc_change_state (GstElement * element) { GstRFC2250Enc *rfc2250_enc = GST_RFC2250_ENC (element); switch (GST_STATE_TRANSITION (element)) { case GST_STATE_NULL_TO_READY: if (!rfc2250_enc->packetize) { - rfc2250_enc->packetize = gst_mpeg_packetize_new (rfc2250_enc->sinkpad, GST_MPEG_PACKETIZE_VIDEO); + rfc2250_enc->packetize = + gst_mpeg_packetize_new (rfc2250_enc->sinkpad, + GST_MPEG_PACKETIZE_VIDEO); } break; case GST_STATE_READY_TO_NULL: if (rfc2250_enc->packetize) { - gst_mpeg_packetize_destroy (rfc2250_enc->packetize); - rfc2250_enc->packetize = NULL; + gst_mpeg_packetize_destroy (rfc2250_enc->packetize); + rfc2250_enc->packetize = NULL; } break; default: @@ -318,24 +322,26 @@ gst_rfc2250_enc_change_state (GstElement *element) } static void -gst_rfc2250_enc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_rfc2250_enc_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstRFC2250Enc *rfc2250_enc; /* it's not null if we got it, but it might not be ours */ - rfc2250_enc = GST_RFC2250_ENC(object); + rfc2250_enc = GST_RFC2250_ENC (object); switch (prop_id) { - case ARG_BIT_RATE: - g_value_set_uint (value, rfc2250_enc->bit_rate); + case ARG_BIT_RATE: + g_value_set_uint (value, rfc2250_enc->bit_rate); break; case ARG_MPEG2: if (rfc2250_enc->packetize) - g_value_set_boolean (value, GST_MPEG_PACKETIZE_IS_MPEG2 (rfc2250_enc->packetize)); + g_value_set_boolean (value, + GST_MPEG_PACKETIZE_IS_MPEG2 (rfc2250_enc->packetize)); else - g_value_set_boolean (value, FALSE); + g_value_set_boolean (value, FALSE); break; - default: + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } @@ -343,8 +349,8 @@ gst_rfc2250_enc_get_property (GObject *object, guint prop_id, GValue *value, GPa gboolean -gst_rfc2250_enc_plugin_init (GstPlugin *plugin) +gst_rfc2250_enc_plugin_init (GstPlugin * plugin) { return gst_element_register (plugin, "rfc2250enc", - GST_RANK_NONE, GST_TYPE_RFC2250_ENC); + GST_RANK_NONE, GST_TYPE_RFC2250_ENC); } diff --git a/gst/mpegstream/gstrfc2250enc.h b/gst/mpegstream/gstrfc2250enc.h index 1846baf7b4..403fe66c1a 100644 --- a/gst/mpegstream/gstrfc2250enc.h +++ b/gst/mpegstream/gstrfc2250enc.h @@ -28,8 +28,9 @@ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_RFC2250_ENC \ @@ -45,44 +46,47 @@ extern "C" { #define GST_RFC2250_ENC_IS_MPEG2(parse) (GST_MPEG_PACKETIZE_IS_MPEG2 (GST_RFC2250_ENC (parse)->packetize)) -typedef enum { - ENC_HAVE_SEQ = (1 << 0), - ENC_HAVE_GOP = (1 << 1), - ENC_HAVE_PIC = (1 << 2), - ENC_HAVE_DATA = (1 << 3), -} GstEncFlags; - -typedef struct _GstRFC2250Enc GstRFC2250Enc; -typedef struct _GstRFC2250EncClass GstRFC2250EncClass; + typedef enum + { + ENC_HAVE_SEQ = (1 << 0), + ENC_HAVE_GOP = (1 << 1), + ENC_HAVE_PIC = (1 << 2), + ENC_HAVE_DATA = (1 << 3), + } GstEncFlags; -struct _GstRFC2250Enc { - GstElement element; + typedef struct _GstRFC2250Enc GstRFC2250Enc; + typedef struct _GstRFC2250EncClass GstRFC2250EncClass; - GstPad *sinkpad, *srcpad; + struct _GstRFC2250Enc + { + GstElement element; - GstMPEGPacketize *packetize; + GstPad *sinkpad, *srcpad; - /* pack header values */ - guint32 bit_rate; - guint64 next_ts; - GstBuffer *packet; - GstEncFlags flags; - gint MTU; - gint remaining; -}; + GstMPEGPacketize *packetize; -struct _GstRFC2250EncClass { - GstElementClass parent_class; -}; + /* pack header values */ + guint32 bit_rate; + guint64 next_ts; + GstBuffer *packet; + GstEncFlags flags; + gint MTU; + gint remaining; + }; -GType gst_rfc2250_enc_get_type(void); + struct _GstRFC2250EncClass + { + GstElementClass parent_class; + }; -gboolean gst_rfc2250_enc_plugin_init (GstPlugin *plugin); + GType gst_rfc2250_enc_get_type (void); + + gboolean gst_rfc2250_enc_plugin_init (GstPlugin * plugin); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __RFC2250_ENC_H__ */ +#endif /* __RFC2250_ENC_H__ */ diff --git a/gst/realmedia/rmdemux.c b/gst/realmedia/rmdemux.c index e3e0365a3d..a9681c58d0 100644 --- a/gst/realmedia/rmdemux.c +++ b/gst/realmedia/rmdemux.c @@ -32,7 +32,8 @@ typedef struct _GstRMDemuxIndex GstRMDemuxIndex; -struct _GstRMDemuxStream { +struct _GstRMDemuxStream +{ guint32 subtype; guint32 fourcc; int id; @@ -51,14 +52,16 @@ struct _GstRMDemuxStream { int n_channels; }; -struct _GstRMDemuxIndex { +struct _GstRMDemuxIndex +{ int unknown; guint32 offset; int timestamp; int frame; }; -enum GstRMDemuxState { +enum GstRMDemuxState +{ RMDEMUX_STATE_NULL, RMDEMUX_STATE_HEADER, RMDEMUX_STATE_HEADER_SEEKING, @@ -68,101 +71,113 @@ enum GstRMDemuxState { RMDEMUX_STATE_EOS, }; -enum GstRMDemuxStreamType { +enum GstRMDemuxStreamType +{ GST_RMDEMUX_STREAM_UNKNOWN, GST_RMDEMUX_STREAM_VIDEO, GST_RMDEMUX_STREAM_AUDIO, GST_RMDEMUX_STREAM_FILEINFO, }; -static GstElementDetails -gst_rmdemux_details = -{ +static GstElementDetails gst_rmdemux_details = { "RealMedia Demuxer", "Codec/Demuxer", "Demultiplex a RealMedia file into audio and video streams", "David Schleef " }; -enum { +enum +{ LAST_SIGNAL }; -enum { +enum +{ ARG_0 }; static GstStaticPadTemplate gst_rmdemux_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-pn-realvideo") -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-pn-realvideo") + ); static GstStaticPadTemplate gst_rmdemux_videosrc_template = -GST_STATIC_PAD_TEMPLATE ( - "video_%02d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS_ANY -); +GST_STATIC_PAD_TEMPLATE ("video_%02d", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS_ANY); static GstStaticPadTemplate gst_rmdemux_audiosrc_template = -GST_STATIC_PAD_TEMPLATE ( - "audio_%02d", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS_ANY -); +GST_STATIC_PAD_TEMPLATE ("audio_%02d", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS_ANY); static GstElementClass *parent_class = NULL; -static void gst_rmdemux_class_init (GstRMDemuxClass *klass); -static void gst_rmdemux_base_init (GstRMDemuxClass *klass); -static void gst_rmdemux_init (GstRMDemux *rmdemux); -static GstElementStateReturn gst_rmdemux_change_state(GstElement *element); -static void gst_rmdemux_loop (GstElement *element); -static gboolean gst_rmdemux_handle_sink_event (GstRMDemux *rmdemux); +static void gst_rmdemux_class_init (GstRMDemuxClass * klass); +static void gst_rmdemux_base_init (GstRMDemuxClass * klass); +static void gst_rmdemux_init (GstRMDemux * rmdemux); +static GstElementStateReturn gst_rmdemux_change_state (GstElement * element); +static void gst_rmdemux_loop (GstElement * element); +static gboolean gst_rmdemux_handle_sink_event (GstRMDemux * rmdemux); //static GstCaps *gst_rmdemux_video_caps(GstRMDemux *rmdemux, guint32 fourcc); //static GstCaps *gst_rmdemux_audio_caps(GstRMDemux *rmdemux, guint32 fourcc); -static void gst_rmdemux_parse__rmf(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_parse_prop(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_parse_mdpr(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_parse_indx(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_parse_data(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_parse_cont(GstRMDemux *rmdemux, void *data, int length); +static void gst_rmdemux_parse__rmf (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_parse_prop (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_parse_mdpr (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_parse_indx (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_parse_data (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_parse_cont (GstRMDemux * rmdemux, void *data, + int length); -static void gst_rmdemux_dump__rmf(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_dump_prop(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_dump_mdpr(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_dump_indx(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_dump_data(GstRMDemux *rmdemux, void *data, int length); -static void gst_rmdemux_dump_cont(GstRMDemux *rmdemux, void *data, int length); +static void gst_rmdemux_dump__rmf (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_dump_prop (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_dump_mdpr (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_dump_indx (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_dump_data (GstRMDemux * rmdemux, void *data, + int length); +static void gst_rmdemux_dump_cont (GstRMDemux * rmdemux, void *data, + int length); -static GstRMDemuxStream *gst_rmdemux_get_stream_by_id(GstRMDemux *rmdemux, +static GstRMDemuxStream *gst_rmdemux_get_stream_by_id (GstRMDemux * rmdemux, int id); -static GType gst_rmdemux_get_type (void) +static GType +gst_rmdemux_get_type (void) { static GType rmdemux_type = 0; if (!rmdemux_type) { static const GTypeInfo rmdemux_info = { - sizeof(GstRMDemuxClass), - (GBaseInitFunc)gst_rmdemux_base_init, NULL, - (GClassInitFunc)gst_rmdemux_class_init, - NULL, NULL, sizeof(GstRMDemux), 0, - (GInstanceInitFunc)gst_rmdemux_init, + sizeof (GstRMDemuxClass), + (GBaseInitFunc) gst_rmdemux_base_init, NULL, + (GClassInitFunc) gst_rmdemux_class_init, + NULL, NULL, sizeof (GstRMDemux), 0, + (GInstanceInitFunc) gst_rmdemux_init, }; - rmdemux_type = g_type_register_static (GST_TYPE_ELEMENT, "GstRMDemux", &rmdemux_info, 0); + rmdemux_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstRMDemux", &rmdemux_info, + 0); } return rmdemux_type; } -static void gst_rmdemux_base_init (GstRMDemuxClass *klass) +static void +gst_rmdemux_base_init (GstRMDemuxClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); @@ -175,91 +190,88 @@ static void gst_rmdemux_base_init (GstRMDemuxClass *klass) gst_element_class_set_details (element_class, &gst_rmdemux_details); } -static void gst_rmdemux_class_init (GstRMDemuxClass *klass) +static void +gst_rmdemux_class_init (GstRMDemuxClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gstelement_class->change_state = gst_rmdemux_change_state; } -static void -gst_rmdemux_init (GstRMDemux *rmdemux) +static void +gst_rmdemux_init (GstRMDemux * rmdemux) { - rmdemux->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_rmdemux_sink_template), "sink"); + rmdemux->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_rmdemux_sink_template), "sink"); gst_element_set_loop_function (GST_ELEMENT (rmdemux), gst_rmdemux_loop); gst_element_add_pad (GST_ELEMENT (rmdemux), rmdemux->sinkpad); } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { if (!gst_library_load ("gstbytestream")) return FALSE; return gst_element_register (plugin, "rmdemux", - GST_RANK_PRIMARY, GST_TYPE_RMDEMUX); + GST_RANK_PRIMARY, GST_TYPE_RMDEMUX); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "rmdemux", - "Realmedia stream demuxer", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "rmdemux", + "Realmedia stream demuxer", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) -static gboolean gst_rmdemux_handle_sink_event (GstRMDemux *rmdemux) + static gboolean gst_rmdemux_handle_sink_event (GstRMDemux * rmdemux) { guint32 remaining; GstEvent *event; GstEventType type; - gst_bytestream_get_status(rmdemux->bs, &remaining, &event); + gst_bytestream_get_status (rmdemux->bs, &remaining, &event); - type = event ? GST_EVENT_TYPE(event) : GST_EVENT_UNKNOWN; + type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN; GST_DEBUG ("rmdemux: event %p %d", event, type); - switch(type){ + switch (type) { case GST_EVENT_EOS: - gst_bytestream_flush(rmdemux->bs, remaining); + gst_bytestream_flush (rmdemux->bs, remaining); //gst_pad_event_default(rmdemux->sinkpad, event); return FALSE; case GST_EVENT_FLUSH: - g_warning("flush event"); + g_warning ("flush event"); break; case GST_EVENT_DISCONTINUOUS: GST_DEBUG ("discontinuous event\n"); //gst_bytestream_flush_fast(rmdemux->bs, remaining); break; default: - g_warning("unhandled event %d",type); + g_warning ("unhandled event %d", type); break; } - gst_event_unref(event); + gst_event_unref (event); return TRUE; } -static GstElementStateReturn gst_rmdemux_change_state(GstElement *element) +static GstElementStateReturn +gst_rmdemux_change_state (GstElement * element) { - GstRMDemux *rmdemux = GST_RMDEMUX(element); + GstRMDemux *rmdemux = GST_RMDEMUX (element); - switch(GST_STATE_TRANSITION(element)){ + switch (GST_STATE_TRANSITION (element)) { case GST_STATE_NULL_TO_READY: break; case GST_STATE_READY_TO_PAUSED: - rmdemux->bs = gst_bytestream_new(rmdemux->sinkpad); + rmdemux->bs = gst_bytestream_new (rmdemux->sinkpad); rmdemux->state = RMDEMUX_STATE_HEADER; /* FIXME */ break; @@ -268,7 +280,7 @@ static GstElementStateReturn gst_rmdemux_change_state(GstElement *element) case GST_STATE_PLAYING_TO_PAUSED: break; case GST_STATE_PAUSED_TO_READY: - gst_bytestream_destroy(rmdemux->bs); + gst_bytestream_destroy (rmdemux->bs); break; case GST_STATE_READY_TO_NULL: break; @@ -276,18 +288,21 @@ static GstElementStateReturn gst_rmdemux_change_state(GstElement *element) break; } - return GST_ELEMENT_CLASS(parent_class)->change_state(element); + return GST_ELEMENT_CLASS (parent_class)->change_state (element); } -static void gst_rmdemux_loop (GstElement *element) +static void +gst_rmdemux_loop (GstElement * element) { - GstRMDemux *rmdemux = GST_RMDEMUX(element); + GstRMDemux *rmdemux = GST_RMDEMUX (element); guint8 *data; guint32 length; guint32 fourcc; GstBuffer *buf; + //int offset; int cur_offset; + //int size; int ret; int rlen; @@ -295,182 +310,189 @@ static void gst_rmdemux_loop (GstElement *element) /* FIXME _tell gets the offset wrong */ //cur_offset = gst_bytestream_tell(rmdemux->bs); - + cur_offset = rmdemux->offset; - GST_DEBUG ("loop at position %d, state %d",cur_offset, rmdemux->state); + GST_DEBUG ("loop at position %d, state %d", cur_offset, rmdemux->state); - if(rmdemux->length == 0){ - rmdemux->length = gst_bytestream_length(rmdemux->bs); + if (rmdemux->length == 0) { + rmdemux->length = gst_bytestream_length (rmdemux->bs); } - switch(rmdemux->state){ - case RMDEMUX_STATE_HEADER: - { - do{ - ret = gst_bytestream_peek_bytes(rmdemux->bs, &data, 16); - if(ret<16){ - if(!gst_rmdemux_handle_sink_event(rmdemux)){ - return; + switch (rmdemux->state) { + case RMDEMUX_STATE_HEADER: + { + do { + ret = gst_bytestream_peek_bytes (rmdemux->bs, &data, 16); + if (ret < 16) { + if (!gst_rmdemux_handle_sink_event (rmdemux)) { + return; + } + } else { + break; } - }else{ - break; + } while (1); + + fourcc = RMDEMUX_FOURCC_GET (data + 0); + length = RMDEMUX_GUINT32_GET (data + 4); + + g_print ("fourcc " GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fourcc)); + g_print ("length %08x\n", length); + + rlen = MIN (length, 4096); + + switch (fourcc) { + case GST_MAKE_FOURCC ('.', 'R', 'M', 'F'): + gst_bytestream_read (rmdemux->bs, &buf, length); + data = GST_BUFFER_DATA (buf); + if (debug) + gst_rmdemux_dump__rmf (rmdemux, data + 8, rlen); + gst_rmdemux_parse__rmf (rmdemux, data + 8, rlen); + break; + case GST_MAKE_FOURCC ('P', 'R', 'O', 'P'): + gst_bytestream_read (rmdemux->bs, &buf, length); + data = GST_BUFFER_DATA (buf); + if (debug) + gst_rmdemux_dump_prop (rmdemux, data + 8, rlen); + gst_rmdemux_parse_prop (rmdemux, data + 8, rlen); + break; + case GST_MAKE_FOURCC ('M', 'D', 'P', 'R'): + gst_bytestream_read (rmdemux->bs, &buf, length); + data = GST_BUFFER_DATA (buf); + if (debug) + gst_rmdemux_dump_mdpr (rmdemux, data + 8, rlen); + gst_rmdemux_parse_mdpr (rmdemux, data + 8, rlen); + break; + case GST_MAKE_FOURCC ('I', 'N', 'D', 'X'): + gst_bytestream_read (rmdemux->bs, &buf, length); + data = GST_BUFFER_DATA (buf); + if (debug) + gst_rmdemux_dump_indx (rmdemux, data + 8, rlen); + gst_rmdemux_parse_indx (rmdemux, data + 8, rlen); + break; + case GST_MAKE_FOURCC ('D', 'A', 'T', 'A'): + rmdemux->data_offset = rmdemux->offset + 10; + if (debug) + gst_rmdemux_dump_data (rmdemux, data + 8, rlen); + gst_rmdemux_parse_data (rmdemux, data + 8, rlen); + break; + case GST_MAKE_FOURCC ('C', 'O', 'N', 'T'): + gst_bytestream_read (rmdemux->bs, &buf, length); + data = GST_BUFFER_DATA (buf); + if (debug) + gst_rmdemux_dump_cont (rmdemux, data + 8, rlen); + gst_rmdemux_parse_cont (rmdemux, data + 8, rlen); + break; + default: + g_print ("unknown fourcc " GST_FOURCC_FORMAT "\n", + GST_FOURCC_ARGS (fourcc)); + break; } - }while(1); - fourcc = RMDEMUX_FOURCC_GET(data + 0); - length = RMDEMUX_GUINT32_GET(data + 4); - - g_print("fourcc " GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS(fourcc)); - g_print("length %08x\n",length); - - rlen = MIN(length, 4096); - - switch(fourcc){ - case GST_MAKE_FOURCC('.','R','M','F'): - gst_bytestream_read(rmdemux->bs, &buf, length); - data = GST_BUFFER_DATA(buf); - if(debug)gst_rmdemux_dump__rmf(rmdemux, data + 8, rlen); - gst_rmdemux_parse__rmf(rmdemux, data + 8, rlen); - break; - case GST_MAKE_FOURCC('P','R','O','P'): - gst_bytestream_read(rmdemux->bs, &buf, length); - data = GST_BUFFER_DATA(buf); - if(debug)gst_rmdemux_dump_prop(rmdemux, data + 8, rlen); - gst_rmdemux_parse_prop(rmdemux, data + 8, rlen); - break; - case GST_MAKE_FOURCC('M','D','P','R'): - gst_bytestream_read(rmdemux->bs, &buf, length); - data = GST_BUFFER_DATA(buf); - if(debug)gst_rmdemux_dump_mdpr(rmdemux, data + 8, rlen); - gst_rmdemux_parse_mdpr(rmdemux, data + 8, rlen); - break; - case GST_MAKE_FOURCC('I','N','D','X'): - gst_bytestream_read(rmdemux->bs, &buf, length); - data = GST_BUFFER_DATA(buf); - if(debug)gst_rmdemux_dump_indx(rmdemux, data + 8, rlen); - gst_rmdemux_parse_indx(rmdemux, data + 8, rlen); - break; - case GST_MAKE_FOURCC('D','A','T','A'): - rmdemux->data_offset = rmdemux->offset + 10; - if(debug)gst_rmdemux_dump_data(rmdemux, data + 8, rlen); - gst_rmdemux_parse_data(rmdemux, data + 8, rlen); - break; - case GST_MAKE_FOURCC('C','O','N','T'): - gst_bytestream_read(rmdemux->bs, &buf, length); - data = GST_BUFFER_DATA(buf); - if(debug)gst_rmdemux_dump_cont(rmdemux, data + 8, rlen); - gst_rmdemux_parse_cont(rmdemux, data + 8, rlen); - break; - default: - g_print("unknown fourcc " GST_FOURCC_FORMAT "\n", - GST_FOURCC_ARGS(fourcc)); - break; - } - - rmdemux->offset += length; - if(rmdemux->offset < rmdemux->length){ - ret = gst_bytestream_seek(rmdemux->bs, rmdemux->offset, - GST_SEEK_METHOD_SET); - }else{ - rmdemux->offset = rmdemux->data_offset + 8; - rmdemux->state = RMDEMUX_STATE_PLAYING; - ret = gst_bytestream_seek(rmdemux->bs, rmdemux->offset, - GST_SEEK_METHOD_SET); - } - - break; - } - case RMDEMUX_STATE_SEEKING_EOS: - { - guint8 *data; - int i; - - for(i=0;in_streams;i++){ - GstPad *pad = rmdemux->streams[i]->pad; - if(pad){ - gst_pad_push(pad, GST_DATA(gst_event_new(GST_EVENT_EOS))); - } - } - - ret = gst_bytestream_peek_bytes(rmdemux->bs, &data, 1); - if(ret<1){ - gst_rmdemux_handle_sink_event(rmdemux); - }else{ - /* didn't expect this */ - g_warning("expected EOS event"); - } - gst_element_set_eos(element); - - rmdemux->state = RMDEMUX_STATE_EOS; - return; - } - case RMDEMUX_STATE_EOS: - g_warning("spinning in EOS\n"); - return; - case RMDEMUX_STATE_PLAYING: - { - int id, timestamp, unknown1; - GstRMDemuxStream *stream; - GstBuffer *buffer; - - do{ - ret = gst_bytestream_peek_bytes(rmdemux->bs, &data, 10); - if(ret<10){ - if(!gst_rmdemux_handle_sink_event(rmdemux)){ - return; - } - }else{ - break; - } - }while(1); - - length = RMDEMUX_GUINT32_GET(data + 0); - id = RMDEMUX_GUINT16_GET(data + 4); - timestamp = RMDEMUX_GUINT32_GET(data + 6); - unknown1 = RMDEMUX_GUINT16_GET(data + 10); - g_print("length %d stream id %d timestamp %d unknown %d\n", - length,id,timestamp,unknown1); - - gst_bytestream_flush(rmdemux->bs, 12); - - gst_bytestream_read(rmdemux->bs, &buffer, length - 12); - stream = gst_rmdemux_get_stream_by_id(rmdemux, id); - - if(stream->pad){ - gst_pad_push(stream->pad, GST_DATA (buffer)); - } - - rmdemux->chunk_index++; - g_print("chunk_index %d n_chunks %d\n", rmdemux->chunk_index, - rmdemux->n_chunks); - if(rmdemux->chunk_index < rmdemux->n_chunks){ rmdemux->offset += length; - ret = gst_bytestream_seek(rmdemux->bs, rmdemux->offset, - GST_SEEK_METHOD_SET); - }else{ - ret = gst_bytestream_seek(rmdemux->bs, 0, GST_SEEK_METHOD_END); - g_print("seek to end returned %d\n",ret); - rmdemux->state = RMDEMUX_STATE_SEEKING_EOS; - } + if (rmdemux->offset < rmdemux->length) { + ret = gst_bytestream_seek (rmdemux->bs, rmdemux->offset, + GST_SEEK_METHOD_SET); + } else { + rmdemux->offset = rmdemux->data_offset + 8; + rmdemux->state = RMDEMUX_STATE_PLAYING; + ret = gst_bytestream_seek (rmdemux->bs, rmdemux->offset, + GST_SEEK_METHOD_SET); + } - break; - } - default: - /* unreached */ - g_assert(0); + break; + } + case RMDEMUX_STATE_SEEKING_EOS: + { + guint8 *data; + int i; + + for (i = 0; i < rmdemux->n_streams; i++) { + GstPad *pad = rmdemux->streams[i]->pad; + + if (pad) { + gst_pad_push (pad, GST_DATA (gst_event_new (GST_EVENT_EOS))); + } + } + + ret = gst_bytestream_peek_bytes (rmdemux->bs, &data, 1); + if (ret < 1) { + gst_rmdemux_handle_sink_event (rmdemux); + } else { + /* didn't expect this */ + g_warning ("expected EOS event"); + } + gst_element_set_eos (element); + + rmdemux->state = RMDEMUX_STATE_EOS; + return; + } + case RMDEMUX_STATE_EOS: + g_warning ("spinning in EOS\n"); + return; + case RMDEMUX_STATE_PLAYING: + { + int id, timestamp, unknown1; + GstRMDemuxStream *stream; + GstBuffer *buffer; + + do { + ret = gst_bytestream_peek_bytes (rmdemux->bs, &data, 10); + if (ret < 10) { + if (!gst_rmdemux_handle_sink_event (rmdemux)) { + return; + } + } else { + break; + } + } while (1); + + length = RMDEMUX_GUINT32_GET (data + 0); + id = RMDEMUX_GUINT16_GET (data + 4); + timestamp = RMDEMUX_GUINT32_GET (data + 6); + unknown1 = RMDEMUX_GUINT16_GET (data + 10); + g_print ("length %d stream id %d timestamp %d unknown %d\n", + length, id, timestamp, unknown1); + + gst_bytestream_flush (rmdemux->bs, 12); + + gst_bytestream_read (rmdemux->bs, &buffer, length - 12); + stream = gst_rmdemux_get_stream_by_id (rmdemux, id); + + if (stream->pad) { + gst_pad_push (stream->pad, GST_DATA (buffer)); + } + + rmdemux->chunk_index++; + g_print ("chunk_index %d n_chunks %d\n", rmdemux->chunk_index, + rmdemux->n_chunks); + if (rmdemux->chunk_index < rmdemux->n_chunks) { + rmdemux->offset += length; + ret = gst_bytestream_seek (rmdemux->bs, rmdemux->offset, + GST_SEEK_METHOD_SET); + } else { + ret = gst_bytestream_seek (rmdemux->bs, 0, GST_SEEK_METHOD_END); + g_print ("seek to end returned %d\n", ret); + rmdemux->state = RMDEMUX_STATE_SEEKING_EOS; + } + + break; + } + default: + /* unreached */ + g_assert (0); } } -static GstRMDemuxStream *gst_rmdemux_get_stream_by_id(GstRMDemux *rmdemux, - int id) +static GstRMDemuxStream * +gst_rmdemux_get_stream_by_id (GstRMDemux * rmdemux, int id) { int i; GstRMDemuxStream *stream; - for(i=0;in_streams;i++){ + for (i = 0; i < rmdemux->n_streams; i++) { stream = rmdemux->streams[i]; - if(stream->id == id){ + if (stream->id == id) { return stream; } } @@ -478,58 +500,62 @@ static GstRMDemuxStream *gst_rmdemux_get_stream_by_id(GstRMDemux *rmdemux, return NULL; } -void gst_rmdemux_add_stream(GstRMDemux *rmdemux, GstRMDemuxStream *stream) +void +gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream) { - if(stream->subtype == GST_RMDEMUX_STREAM_VIDEO){ - stream->pad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_rmdemux_videosrc_template), - g_strdup_printf ("video_%02d", rmdemux->n_video_streams)); - if(stream->caps) { + if (stream->subtype == GST_RMDEMUX_STREAM_VIDEO) { + stream->pad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_rmdemux_videosrc_template), g_strdup_printf ("video_%02d", + rmdemux->n_video_streams)); + if (stream->caps) { gst_caps_set_simple (stream->caps, "width", G_TYPE_INT, stream->width, "height", G_TYPE_INT, stream->height, NULL); } rmdemux->n_video_streams++; - }else - if(stream->subtype == GST_RMDEMUX_STREAM_AUDIO){ - stream->pad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_rmdemux_audiosrc_template), - g_strdup_printf ("audio_%02d", rmdemux->n_audio_streams)); - stream->caps = gst_caps_new_simple("audio/a52",NULL); + } else if (stream->subtype == GST_RMDEMUX_STREAM_AUDIO) { + stream->pad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_rmdemux_audiosrc_template), g_strdup_printf ("audio_%02d", + rmdemux->n_audio_streams)); + stream->caps = gst_caps_new_simple ("audio/a52", NULL); gst_caps_set_simple (stream->caps, - "rate", G_TYPE_INT, (int)stream->rate, + "rate", G_TYPE_INT, (int) stream->rate, "channels", G_TYPE_INT, stream->n_channels, NULL); rmdemux->n_audio_streams++; - }else{ - g_print("not adding stream of type %d\n",stream->subtype); + } else { + g_print ("not adding stream of type %d\n", stream->subtype); } GST_PAD_ELEMENT_PRIVATE (stream->pad) = stream; rmdemux->streams[rmdemux->n_streams] = stream; rmdemux->n_streams++; - g_print("n_streams is now %d\n", rmdemux->n_streams); + g_print ("n_streams is now %d\n", rmdemux->n_streams); - if(stream->pad){ + if (stream->pad) { gst_pad_use_explicit_caps (stream->pad); GST_DEBUG ("setting caps: " GST_PTR_FORMAT, stream->caps); - gst_pad_set_explicit_caps(stream->pad, stream->caps); + gst_pad_set_explicit_caps (stream->pad, stream->caps); GST_DEBUG ("adding pad %p to rmdemux %p", stream->pad, rmdemux); - gst_element_add_pad(GST_ELEMENT (rmdemux), stream->pad); + gst_element_add_pad (GST_ELEMENT (rmdemux), stream->pad); } } #if 0 -static GstCaps *gst_rmdemux_video_caps(GstRMDemux *rmdemux, guint32 fourcc) +static GstCaps * +gst_rmdemux_video_caps (GstRMDemux * rmdemux, guint32 fourcc) { return NULL; } -static GstCaps *gst_rmdemux_audio_caps(GstRMDemux *rmdemux, guint32 fourcc) +static GstCaps * +gst_rmdemux_audio_caps (GstRMDemux * rmdemux, guint32 fourcc) { return NULL; } @@ -538,54 +564,59 @@ static GstCaps *gst_rmdemux_audio_caps(GstRMDemux *rmdemux, guint32 fourcc) -static void re_hexdump_bytes(guint8 *ptr, int len, int offset) +static void +re_hexdump_bytes (guint8 * ptr, int len, int offset) { guint8 *end = ptr + len; int i; - while(1){ - if(ptr >= end)return; - g_print("%08x: ",offset); - for(i=0;i<16;i++){ - if(ptr + i >= end){ - g_print(" "); - }else{ - g_print("%02x ",ptr[i]); + while (1) { + if (ptr >= end) + return; + g_print ("%08x: ", offset); + for (i = 0; i < 16; i++) { + if (ptr + i >= end) { + g_print (" "); + } else { + g_print ("%02x ", ptr[i]); } } - for(i=0;i<16;i++){ - if(ptr + i >= end){ - g_print(" "); - }else{ - g_print("%c",g_ascii_isprint(ptr[i])?ptr[i]:'.'); + for (i = 0; i < 16; i++) { + if (ptr + i >= end) { + g_print (" "); + } else { + g_print ("%c", g_ascii_isprint (ptr[i]) ? ptr[i] : '.'); } } - g_print("\n"); + g_print ("\n"); ptr += 16; offset += 16; } } -static int re_dump_pascal_string(guint8 *ptr) +static int +re_dump_pascal_string (guint8 * ptr) { int length; length = ptr[0]; - g_print("string: %.*s\n",length,(char *)ptr + 1); + g_print ("string: %.*s\n", length, (char *) ptr + 1); return length + 1; } -static char * re_get_pascal_string(guint8 *ptr) +static char * +re_get_pascal_string (guint8 * ptr) { int length; length = ptr[0]; - return g_strndup(ptr+1, length); + return g_strndup (ptr + 1, length); } -static int re_skip_pascal_string(guint8 *ptr) +static int +re_skip_pascal_string (guint8 * ptr) { int length; @@ -595,43 +626,48 @@ static int re_skip_pascal_string(guint8 *ptr) } -static void gst_rmdemux_parse__rmf(GstRMDemux *rmdemux, void *data, int length) +static void +gst_rmdemux_parse__rmf (GstRMDemux * rmdemux, void *data, int length) { } -static void gst_rmdemux_dump__rmf(GstRMDemux *rmdemux, void *data, int length) +static void +gst_rmdemux_dump__rmf (GstRMDemux * rmdemux, void *data, int length) { - g_print("version: %d\n", RMDEMUX_GUINT16_GET(data + 0)); - g_print("unknown: %d\n", RMDEMUX_GUINT32_GET(data + 2)); - g_print("unknown: %d\n", RMDEMUX_GUINT32_GET(data + 6)); - g_print("\n"); + g_print ("version: %d\n", RMDEMUX_GUINT16_GET (data + 0)); + g_print ("unknown: %d\n", RMDEMUX_GUINT32_GET (data + 2)); + g_print ("unknown: %d\n", RMDEMUX_GUINT32_GET (data + 6)); + g_print ("\n"); } -static void gst_rmdemux_parse_prop(GstRMDemux *rmdemux, void *data, int length) +static void +gst_rmdemux_parse_prop (GstRMDemux * rmdemux, void *data, int length) { - rmdemux->duration = RMDEMUX_GUINT32_GET(data + 22); + rmdemux->duration = RMDEMUX_GUINT32_GET (data + 22); } -static void gst_rmdemux_dump_prop(GstRMDemux *rmdemux, void *data, int length) +static void +gst_rmdemux_dump_prop (GstRMDemux * rmdemux, void *data, int length) { - g_print("version: %d\n", RMDEMUX_GUINT16_GET(data + 0)); - g_print("max bitrate: %d\n", RMDEMUX_GUINT32_GET(data + 2)); - g_print("avg bitrate: %d\n", RMDEMUX_GUINT32_GET(data + 6)); - g_print("max packet size: %d\n", RMDEMUX_GUINT32_GET(data + 10)); - g_print("avg packet size: %d\n", RMDEMUX_GUINT32_GET(data + 14)); - g_print("number of packets: %d\n", RMDEMUX_GUINT32_GET(data + 18)); - g_print("duration: %d\n", RMDEMUX_GUINT32_GET(data + 22)); - g_print("preroll: %d\n", RMDEMUX_GUINT32_GET(data + 26)); - g_print("offset of INDX section: 0x%08x\n", RMDEMUX_GUINT32_GET(data + 30)); - g_print("offset of data section: 0x%08x\n", RMDEMUX_GUINT32_GET(data + 34)); - g_print("n streams: %d\n", RMDEMUX_GUINT16_GET(data + 38)); - g_print("flags: 0x%04x\n", RMDEMUX_GUINT16_GET(data + 40)); - g_print("\n"); + g_print ("version: %d\n", RMDEMUX_GUINT16_GET (data + 0)); + g_print ("max bitrate: %d\n", RMDEMUX_GUINT32_GET (data + 2)); + g_print ("avg bitrate: %d\n", RMDEMUX_GUINT32_GET (data + 6)); + g_print ("max packet size: %d\n", RMDEMUX_GUINT32_GET (data + 10)); + g_print ("avg packet size: %d\n", RMDEMUX_GUINT32_GET (data + 14)); + g_print ("number of packets: %d\n", RMDEMUX_GUINT32_GET (data + 18)); + g_print ("duration: %d\n", RMDEMUX_GUINT32_GET (data + 22)); + g_print ("preroll: %d\n", RMDEMUX_GUINT32_GET (data + 26)); + g_print ("offset of INDX section: 0x%08x\n", RMDEMUX_GUINT32_GET (data + 30)); + g_print ("offset of data section: 0x%08x\n", RMDEMUX_GUINT32_GET (data + 34)); + g_print ("n streams: %d\n", RMDEMUX_GUINT16_GET (data + 38)); + g_print ("flags: 0x%04x\n", RMDEMUX_GUINT16_GET (data + 40)); + g_print ("\n"); } -static void gst_rmdemux_parse_mdpr(GstRMDemux *rmdemux, void *data, int length) +static void +gst_rmdemux_parse_mdpr (GstRMDemux * rmdemux, void *data, int length) { GstRMDemuxStream *stream; char *stream1_type_string; @@ -639,146 +675,148 @@ static void gst_rmdemux_parse_mdpr(GstRMDemux *rmdemux, void *data, int length) int stream_type; int offset; - stream = g_new0(GstRMDemuxStream,1); + stream = g_new0 (GstRMDemuxStream, 1); - stream->id = RMDEMUX_GUINT16_GET(data + 2); + stream->id = RMDEMUX_GUINT16_GET (data + 2); offset = 32; stream_type = GST_RMDEMUX_STREAM_UNKNOWN; - stream1_type_string = re_get_pascal_string(data + offset); - offset += re_skip_pascal_string(data + offset); - stream2_type_string = re_get_pascal_string(data + offset); - offset += re_skip_pascal_string(data + offset); - if(strcmp(stream1_type_string, "Video Stream")==0){ + stream1_type_string = re_get_pascal_string (data + offset); + offset += re_skip_pascal_string (data + offset); + stream2_type_string = re_get_pascal_string (data + offset); + offset += re_skip_pascal_string (data + offset); + if (strcmp (stream1_type_string, "Video Stream") == 0) { stream_type = GST_RMDEMUX_STREAM_VIDEO; - }else if(strcmp(stream1_type_string, "Audio Stream")==0){ + } else if (strcmp (stream1_type_string, "Audio Stream") == 0) { stream_type = GST_RMDEMUX_STREAM_AUDIO; - }else if(strcmp(stream1_type_string, "")==0 && - strcmp(stream2_type_string, "logical-fileinfo")==0){ + } else if (strcmp (stream1_type_string, "") == 0 && + strcmp (stream2_type_string, "logical-fileinfo") == 0) { stream_type = GST_RMDEMUX_STREAM_FILEINFO; - }else{ + } else { stream_type = GST_RMDEMUX_STREAM_UNKNOWN; - g_print("unknown stream type \"%s\",\"%s\"\n",stream1_type_string, + g_print ("unknown stream type \"%s\",\"%s\"\n", stream1_type_string, stream2_type_string); } - g_free(stream1_type_string); - g_free(stream2_type_string); + g_free (stream1_type_string); + g_free (stream2_type_string); offset += 4; stream->subtype = stream_type; - switch(stream_type){ + switch (stream_type) { case GST_RMDEMUX_STREAM_VIDEO: - stream->fourcc = RMDEMUX_FOURCC_GET(data + offset + 8); - stream->width = RMDEMUX_GUINT16_GET(data + offset + 12); - stream->height = RMDEMUX_GUINT16_GET(data + offset + 14); - stream->rate = RMDEMUX_GUINT16_GET(data + offset + 16); + stream->fourcc = RMDEMUX_FOURCC_GET (data + offset + 8); + stream->width = RMDEMUX_GUINT16_GET (data + offset + 12); + stream->height = RMDEMUX_GUINT16_GET (data + offset + 14); + stream->rate = RMDEMUX_GUINT16_GET (data + offset + 16); break; case GST_RMDEMUX_STREAM_AUDIO: - stream->fourcc = RMDEMUX_FOURCC_GET(data + offset + 8); - stream->rate = RMDEMUX_GUINT32_GET(data + offset + 48); + stream->fourcc = RMDEMUX_FOURCC_GET (data + offset + 8); + stream->rate = RMDEMUX_GUINT32_GET (data + offset + 48); break; case GST_RMDEMUX_STREAM_FILEINFO: - { - int end; - int length; + { + int end; + int length; - length = RMDEMUX_GUINT32_GET(data + offset); - end = offset + length; - offset += 4; - //re_hexdump_bytes(data + offset,14,offset); - offset += 14; - offset += re_dump_pascal_string(data + offset); - //re_hexdump_bytes(data + offset,10,offset); - offset += 10; - while(offsetindex = index; stream->index_length = n; offset = 12; - for(i=0;in_chunks = RMDEMUX_GUINT32_GET(data + 2); + rmdemux->n_chunks = RMDEMUX_GUINT32_GET (data + 2); } -static void gst_rmdemux_dump_data(GstRMDemux *rmdemux, void *data, int length) +static void +gst_rmdemux_dump_data (GstRMDemux * rmdemux, void *data, int length) { int offset = 0; int n; - g_print("version: %d\n", RMDEMUX_GUINT16_GET(data + 0)); - g_print("n_chunks: %d\n", RMDEMUX_GUINT32_GET(data + offset + 2)); - g_print("unknown: 0x%08x\n", RMDEMUX_GUINT32_GET(data + offset + 6)); + g_print ("version: %d\n", RMDEMUX_GUINT16_GET (data + 0)); + g_print ("n_chunks: %d\n", RMDEMUX_GUINT32_GET (data + offset + 2)); + g_print ("unknown: 0x%08x\n", RMDEMUX_GUINT32_GET (data + offset + 6)); - re_hexdump_bytes(data + offset,10,offset); + re_hexdump_bytes (data + offset, 10, offset); offset += 10; - while(offset #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_RMDEMUX \ @@ -42,47 +43,49 @@ extern "C" { #define GST_RMDEMUX_MAX_STREAMS 8 -typedef struct _GstRMDemux GstRMDemux; -typedef struct _GstRMDemuxClass GstRMDemuxClass; -typedef struct _GstRMDemuxStream GstRMDemuxStream; + typedef struct _GstRMDemux GstRMDemux; + typedef struct _GstRMDemuxClass GstRMDemuxClass; + typedef struct _GstRMDemuxStream GstRMDemuxStream; -struct _GstRMDemux { - GstElement element; + struct _GstRMDemux + { + GstElement element; - /* pads */ - GstPad *sinkpad; + /* pads */ + GstPad *sinkpad; - GstRMDemuxStream *streams[GST_RMDEMUX_MAX_STREAMS]; - int n_streams; - int n_video_streams; - int n_audio_streams; + GstRMDemuxStream *streams[GST_RMDEMUX_MAX_STREAMS]; + int n_streams; + int n_video_streams; + int n_audio_streams; - GstByteStream *bs; + GstByteStream *bs; - GNode *moov_node; - GNode *moov_node_compressed; + GNode *moov_node; + GNode *moov_node_compressed; - guint32 timescale; - guint32 duration; + guint32 timescale; + guint32 duration; - int state; + int state; - int offset; - int data_offset; + int offset; + int data_offset; - int n_chunks; - int chunk_index; + int n_chunks; + int chunk_index; - guint64 length; + guint64 length; -}; + }; -struct _GstRMDemuxClass { - GstElementClass parent_class; -}; + struct _GstRMDemuxClass + { + GstElementClass parent_class; + }; #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_RMDEMUX_H__ */ +#endif /* __GST_RMDEMUX_H__ */ diff --git a/gst/synaesthesia/gstsynaesthesia.c b/gst/synaesthesia/gstsynaesthesia.c index 37f1a02766..5d103953be 100644 --- a/gst/synaesthesia/gstsynaesthesia.c +++ b/gst/synaesthesia/gstsynaesthesia.c @@ -35,11 +35,12 @@ typedef struct _GstSynaesthesia GstSynaesthesia; typedef struct _GstSynaesthesiaClass GstSynaesthesiaClass; -struct _GstSynaesthesia { +struct _GstSynaesthesia +{ GstElement element; /* pads */ - GstPad *sinkpad,*srcpad; + GstPad *sinkpad, *srcpad; /* the timestamp of the next frame */ guint64 next_time; @@ -52,28 +53,30 @@ struct _GstSynaesthesia { gboolean first_buffer; }; -struct _GstSynaesthesiaClass { +struct _GstSynaesthesiaClass +{ GstElementClass parent_class; }; -GType gst_synaesthesia_get_type(void); +GType gst_synaesthesia_get_type (void); /* elementfactory information */ -static GstElementDetails gst_synaesthesia_details = GST_ELEMENT_DETAILS ( - "Synaesthesia", - "Visualization", - "Creates video visualizations of audio input, using stereo and pitch information", - "Richard Boulton " -); +static GstElementDetails gst_synaesthesia_details = +GST_ELEMENT_DETAILS ("Synaesthesia", + "Visualization", + "Creates video visualizations of audio input, using stereo and pitch information", + "Richard Boulton "); /* signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_WIDTH, ARG_HEIGHT, @@ -82,38 +85,36 @@ enum { }; static GstStaticPadTemplate gst_synaesthesia_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN) -); +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN) + ); static GstStaticPadTemplate gst_synaesthesia_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS ) -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS) + ); -static void gst_synaesthesia_base_init (gpointer g_class); -static void gst_synaesthesia_class_init (GstSynaesthesiaClass *klass); -static void gst_synaesthesia_init (GstSynaesthesia *synaesthesia); +static void gst_synaesthesia_base_init (gpointer g_class); +static void gst_synaesthesia_class_init (GstSynaesthesiaClass * klass); +static void gst_synaesthesia_init (GstSynaesthesia * synaesthesia); -static void gst_synaesthesia_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_synaesthesia_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); +static void gst_synaesthesia_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_synaesthesia_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static void gst_synaesthesia_chain (GstPad *pad, GstData *_data); +static void gst_synaesthesia_chain (GstPad * pad, GstData * _data); static GstElementStateReturn - gst_synaesthesia_change_state (GstElement *element); +gst_synaesthesia_change_state (GstElement * element); -static GstPadLinkReturn - gst_synaesthesia_sink_link (GstPad *pad, const GstCaps *caps); +static GstPadLinkReturn +gst_synaesthesia_sink_link (GstPad * pad, const GstCaps * caps); static GstElementClass *parent_class = NULL; @@ -124,9 +125,9 @@ gst_synaesthesia_get_type (void) if (!type) { static const GTypeInfo info = { - sizeof (GstSynaesthesiaClass), - gst_synaesthesia_base_init, - NULL, + sizeof (GstSynaesthesiaClass), + gst_synaesthesia_base_init, + NULL, (GClassInitFunc) gst_synaesthesia_class_init, NULL, NULL, @@ -134,7 +135,8 @@ gst_synaesthesia_get_type (void) 0, (GInstanceInitFunc) gst_synaesthesia_init, }; - type = g_type_register_static (GST_TYPE_ELEMENT, "GstSynaesthesia", &info, 0); + type = + g_type_register_static (GST_TYPE_ELEMENT, "GstSynaesthesia", &info, 0); } return type; } @@ -147,31 +149,31 @@ gst_synaesthesia_base_init (gpointer g_class) gst_element_class_set_details (element_class, &gst_synaesthesia_details); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get(&gst_synaesthesia_src_template)); + gst_static_pad_template_get (&gst_synaesthesia_src_template)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get(&gst_synaesthesia_sink_template)); + gst_static_pad_template_get (&gst_synaesthesia_sink_template)); } static void -gst_synaesthesia_class_init(GstSynaesthesiaClass *klass) +gst_synaesthesia_class_init (GstSynaesthesiaClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*) klass; - gstelement_class = (GstElementClass*) klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WIDTH, - g_param_spec_int ("width","Width","The Width", - 1, 2048, 320, G_PARAM_READWRITE)); + g_param_spec_int ("width", "Width", "The Width", + 1, 2048, 320, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HEIGHT, - g_param_spec_int ("height","Height","The height", - 1, 2048, 320, G_PARAM_READWRITE)); + g_param_spec_int ("height", "Height", "The height", + 1, 2048, 320, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FPS, - g_param_spec_float ("fps","FPS","Frames per second", - 0., G_MAXFLOAT, 25., G_PARAM_READWRITE)); + g_param_spec_float ("fps", "FPS", "Frames per second", + 0., G_MAXFLOAT, 25., G_PARAM_READWRITE)); gobject_class->set_property = gst_synaesthesia_set_property; gobject_class->get_property = gst_synaesthesia_get_property; @@ -180,13 +182,15 @@ gst_synaesthesia_class_init(GstSynaesthesiaClass *klass) } static void -gst_synaesthesia_init (GstSynaesthesia *synaesthesia) +gst_synaesthesia_init (GstSynaesthesia * synaesthesia) { /* create the sink and src pads */ - synaesthesia->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get(&gst_synaesthesia_sink_template), "sink"); - synaesthesia->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get(&gst_synaesthesia_src_template), "src"); + synaesthesia->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_synaesthesia_sink_template), "sink"); + synaesthesia->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_synaesthesia_src_template), "src"); gst_element_add_pad (GST_ELEMENT (synaesthesia), synaesthesia->sinkpad); gst_element_add_pad (GST_ELEMENT (synaesthesia), synaesthesia->srcpad); @@ -198,21 +202,22 @@ gst_synaesthesia_init (GstSynaesthesia *synaesthesia) /* reset the initial video state */ synaesthesia->width = 320; synaesthesia->height = 200; - synaesthesia->fps = 25.; /* desired frame rate */ + synaesthesia->fps = 25.; /* desired frame rate */ } static GstPadLinkReturn -gst_synaesthesia_sink_link (GstPad *pad, const GstCaps *caps) +gst_synaesthesia_sink_link (GstPad * pad, const GstCaps * caps) { GstSynaesthesia *synaesthesia; + synaesthesia = GST_SYNAESTHESIA (gst_pad_get_parent (pad)); return GST_PAD_LINK_OK; } static void -gst_synaesthesia_chain (GstPad *pad, GstData *_data) +gst_synaesthesia_chain (GstPad * pad, GstData * _data) { GstBuffer *bufin = GST_BUFFER (_data); GstSynaesthesia *synaesthesia; @@ -231,15 +236,16 @@ gst_synaesthesia_chain (GstPad *pad, GstData *_data) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_DISCONTINUOUS: { - gint64 value = 0; - gst_event_discont_get_value (event, GST_FORMAT_TIME, &value); - synaesthesia->next_time = value; + gint64 value = 0; + + gst_event_discont_get_value (event, GST_FORMAT_TIME, &value); + synaesthesia->next_time = value; } default: - gst_pad_event_default (pad, event); - break; + gst_pad_event_default (pad, event); + break; } - return; + return; } samples_in = GST_BUFFER_SIZE (bufin) / sizeof (gint16); @@ -247,27 +253,30 @@ gst_synaesthesia_chain (GstPad *pad, GstData *_data) GST_DEBUG ("input buffer has %d samples", samples_in); /* FIXME: should really select the first 1024 samples after the timestamp. */ - if (GST_BUFFER_TIMESTAMP (bufin) < synaesthesia->next_time || samples_in < 1024) { - GST_DEBUG ("timestamp is %" G_GUINT64_FORMAT ": want >= %" G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (bufin), synaesthesia->next_time); + if (GST_BUFFER_TIMESTAMP (bufin) < synaesthesia->next_time + || samples_in < 1024) { + GST_DEBUG ("timestamp is %" G_GUINT64_FORMAT ": want >= %" G_GUINT64_FORMAT, + GST_BUFFER_TIMESTAMP (bufin), synaesthesia->next_time); gst_buffer_unref (bufin); return; } data = (gint16 *) GST_BUFFER_DATA (bufin); - for (i=0; i < 512; i++) { + for (i = 0; i < 512; i++) { synaesthesia->datain[0][i] = *data++; synaesthesia->datain[1][i] = *data++; } if (synaesthesia->first_buffer) { synaesthesia_init (synaesthesia->width, synaesthesia->height); - + synaesthesia->first_buffer = FALSE; } bufout = gst_buffer_new (); GST_BUFFER_SIZE (bufout) = synaesthesia->width * synaesthesia->height * 4; - GST_BUFFER_DATA (bufout) = (guchar *) synaesthesia_update (synaesthesia->datain); + GST_BUFFER_DATA (bufout) = + (guchar *) synaesthesia_update (synaesthesia->datain); GST_BUFFER_TIMESTAMP (bufout) = synaesthesia->next_time; GST_BUFFER_FLAG_SET (bufout, GST_BUFFER_DONTFREE); @@ -282,7 +291,8 @@ gst_synaesthesia_chain (GstPad *pad, GstData *_data) } static void -gst_synaesthesia_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_synaesthesia_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstSynaesthesia *synaesthesia; @@ -306,7 +316,8 @@ gst_synaesthesia_set_property (GObject *object, guint prop_id, const GValue *val } static void -gst_synaesthesia_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_synaesthesia_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstSynaesthesia *synaesthesia; @@ -330,7 +341,7 @@ gst_synaesthesia_get_property (GObject *object, guint prop_id, GValue *value, GP } static GstElementStateReturn -gst_synaesthesia_change_state (GstElement *element) +gst_synaesthesia_change_state (GstElement * element) { GstSynaesthesia *synaesthesia; @@ -351,19 +362,14 @@ gst_synaesthesia_change_state (GstElement *element) static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - return gst_element_register (plugin, "synaesthesia", GST_RANK_NONE, GST_TYPE_SYNAESTHESIA); + return gst_element_register (plugin, "synaesthesia", GST_RANK_NONE, + GST_TYPE_SYNAESTHESIA); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "synaesthesia", - "Creates video visualizations of audio input, using stereo and pitch information", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "synaesthesia", + "Creates video visualizations of audio input, using stereo and pitch information", + plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) diff --git a/gst/synaesthesia/synaescope.c b/gst/synaesthesia/synaescope.c index 7cb11611a5..ad3a6b44ea 100644 --- a/gst/synaesthesia/synaescope.c +++ b/gst/synaesthesia/synaescope.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,19 +41,19 @@ #define SCOPE_BG_GREEN 0 #define SCOPE_BG_BLUE 0 -#define FFT_BUFFER_SIZE_LOG 9 +#define FFT_BUFFER_SIZE_LOG 9 #define FFT_BUFFER_SIZE (1 << FFT_BUFFER_SIZE_LOG) #define syn_width 320 #define syn_height 200 #define brightMin 200 #define brightMax 2000 -#define brightDec 10 +#define brightDec 10 #define brightInc 6 #define brTotTargetLow 5000 #define brTotTargetHigh 15000 -static int autobrightness = 1; /* Whether to use automatic brightness adjust */ +static int autobrightness = 1; /* Whether to use automatic brightness adjust */ static unsigned int brightFactor = 400; static unsigned char output[syn_width * syn_height * 2]; static guint32 display[syn_width * syn_height]; @@ -66,14 +66,14 @@ static double fftout_r[FFT_BUFFER_SIZE]; static double fftmult[FFT_BUFFER_SIZE / 2 + 1]; static double corr_l[FFT_BUFFER_SIZE]; static double corr_r[FFT_BUFFER_SIZE]; -static int clarity[FFT_BUFFER_SIZE]; /* Surround sound */ +static int clarity[FFT_BUFFER_SIZE]; /* Surround sound */ static double cosTable[FFT_BUFFER_SIZE]; static double negSinTable[FFT_BUFFER_SIZE]; static int bitReverse[FFT_BUFFER_SIZE]; static int scaleDown[256]; -static void synaes_fft(double *x, double *y); -static void synaescope_coreGo(void); +static void synaes_fft (double *x, double *y); +static void synaescope_coreGo (void); #define SYNAESCOPE_DOLOOP() \ while (running) { \ @@ -98,22 +98,42 @@ while (running) { \ dosleep(SCOPE_SLEEP); \ } -static inline void addPixel(unsigned char *output, int x,int y,int br1,int br2) { +static inline void +addPixel (unsigned char *output, int x, int y, int br1, int br2) +{ unsigned char *p; - if (x < 0 || x >= syn_width || y < 0 || y >= syn_height) return; - + + if (x < 0 || x >= syn_width || y < 0 || y >= syn_height) + return; + p = output + x * 2 + y * syn_width * 2; - if (p[0] < 255 - br1) p[0] += br1; else p[0] = 255; - if (p[1] < 255 - br2) p[1] += br2; else p[1] = 255; + if (p[0] < 255 - br1) + p[0] += br1; + else + p[0] = 255; + if (p[1] < 255 - br2) + p[1] += br2; + else + p[1] = 255; } -static inline void addPixelFast(unsigned char *p,int br1,int br2) { - if (p[0] < 255 - br1) p[0] += br1; else p[0] = 255; - if (p[1] < 255 - br2) p[1] += br2; else p[1] = 255; +static inline void +addPixelFast (unsigned char *p, int br1, int br2) +{ + if (p[0] < 255 - br1) + p[0] += br1; + else + p[0] = 255; + if (p[1] < 255 - br2) + p[1] += br2; + else + p[1] = 255; } -static void synaescope_coreGo(void) { - int i,j; +static void +synaescope_coreGo (void) +{ + int i, j; register unsigned long *ptr; register unsigned long *end; int heightFactor; @@ -122,371 +142,401 @@ static void synaescope_coreGo(void) { double brightFactor2; long int brtot; - memcpy(pcm_l, pcmt_l, sizeof(pcm_l)); - memcpy(pcm_r, pcmt_r, sizeof(pcm_r)); + memcpy (pcm_l, pcmt_l, sizeof (pcm_l)); + memcpy (pcm_r, pcmt_r, sizeof (pcm_r)); - for(i = 0; i < FFT_BUFFER_SIZE; i++) { + for (i = 0; i < FFT_BUFFER_SIZE; i++) { fftout_l[i] = pcm_l[i]; fftout_r[i] = pcm_r[i]; } - synaes_fft(fftout_l,fftout_r); + synaes_fft (fftout_l, fftout_r); - for(i=0 +1;i>1)>>4; */ - if (*ptr) - { - if (*ptr & 0xf0f0f0f0) - { - *ptr = *ptr - ((*ptr & 0xf0f0f0f0) >> 4) - ((*ptr & 0xe0e0e0e0) >> 5); + if (*ptr) { + if (*ptr & 0xf0f0f0f0) { + *ptr = *ptr - ((*ptr & 0xf0f0f0f0) >> 4) - ((*ptr & 0xe0e0e0e0) >> 5); } else { - *ptr = (*ptr * 14 >> 4) & 0x0f0f0f0f; - /*Should be 29/32 to be consistent. Who cares. This is totally */ - /* hacked anyway. */ - /*unsigned char *subptr = (unsigned char*)(ptr++); */ - /*subptr[0] = (int)subptr[0] * 29 / 32; */ - /*subptr[1] = (int)subptr[0] * 29 / 32; */ - /*subptr[2] = (int)subptr[0] * 29 / 32; */ - /*subptr[3] = (int)subptr[0] * 29 / 32; */ + *ptr = (*ptr * 14 >> 4) & 0x0f0f0f0f; + /*Should be 29/32 to be consistent. Who cares. This is totally */ + /* hacked anyway. */ + /*unsigned char *subptr = (unsigned char*)(ptr++); */ + /*subptr[0] = (int)subptr[0] * 29 / 32; */ + /*subptr[1] = (int)subptr[0] * 29 / 32; */ + /*subptr[2] = (int)subptr[0] * 29 / 32; */ + /*subptr[3] = (int)subptr[0] * 29 / 32; */ } } ptr++; - } while(ptr < end); + } while (ptr < end); - heightFactor = FFT_BUFFER_SIZE/2 / syn_height + 1; - actualHeight = FFT_BUFFER_SIZE/2 / heightFactor; + heightFactor = FFT_BUFFER_SIZE / 2 / syn_height + 1; + actualHeight = FFT_BUFFER_SIZE / 2 / heightFactor; heightAdd = (syn_height + actualHeight) >> 1; /* Correct for window size */ - brightFactor2 = (brightFactor/65536.0/FFT_BUFFER_SIZE)* - sqrt(actualHeight * syn_width / (320.0*200.0)); + brightFactor2 = (brightFactor / 65536.0 / FFT_BUFFER_SIZE) * + sqrt (actualHeight * syn_width / (320.0 * 200.0)); brtot = 0; - for(i=1;i 0 || corr_r[i] > 0) { - int h = (int)( corr_r[i] * syn_width / (corr_l[i]+corr_r[i]) ); + int h = (int) (corr_r[i] * syn_width / (corr_l[i] + corr_r[i])); + /* int h = (int)( syn_width - 1 ); */ - int br1, br2, br = (int)( - (corr_l[i]+corr_r[i])*i*brightFactor2 ); - int px = h, - py = heightAdd - i / heightFactor; - brtot += br; - br1 = br*(clarity[i]+128)>>8; - br2 = br*(128-clarity[i])>>8; - if (br1 < 0) br1 = 0; else if (br1 > 255) br1 = 255; - if (br2 < 0) br2 = 0; else if (br2 > 255) br2 = 255; + int br1, br2, br = (int) ((corr_l[i] + corr_r[i]) * i * brightFactor2); + int px = h, py = heightAdd - i / heightFactor; + + brtot += br; + br1 = br * (clarity[i] + 128) >> 8; + br2 = br * (128 - clarity[i]) >> 8; + if (br1 < 0) + br1 = 0; + else if (br1 > 255) + br1 = 255; + if (br2 < 0) + br2 = 0; + else if (br2 > 255) + br2 = 255; /*unsigned char *p = output+ h*2+(164-((i<<8)>>FFT_BUFFER_SIZE_LOG))*(syn_width*2); */ - if (px < 30 || py < 30 || px > syn_width-30 || py > syn_height-30) { - addPixel(output, px,py,br1,br2); - for(j=1;br1>0||br2>0;j++,br1=scaleDown[br1],br2=scaleDown[br2]) { - addPixel(output, px+j,py,br1,br2); - addPixel(output, px,py+j,br1,br2); - addPixel(output, px-j,py,br1,br2); - addPixel(output, px,py-j,br1,br2); - } + if (px < 30 || py < 30 || px > syn_width - 30 || py > syn_height - 30) { + addPixel (output, px, py, br1, br2); + for (j = 1; br1 > 0 || br2 > 0; + j++, br1 = scaleDown[br1], br2 = scaleDown[br2]) { + addPixel (output, px + j, py, br1, br2); + addPixel (output, px, py + j, br1, br2); + addPixel (output, px - j, py, br1, br2); + addPixel (output, px, py - j, br1, br2); + } } else { - unsigned char *p = output+px*2+py*syn_width*2, *p1=p, *p2=p, *p3=p, *p4=p; - addPixelFast(p,br1,br2); - for(;br1>0||br2>0;br1=scaleDown[br1],br2=scaleDown[br2]) { - p1 += 2; - addPixelFast(p1,br1,br2); - p2 -= 2; - addPixelFast(p2,br1,br2); - p3 += syn_width * 2; - addPixelFast(p3,br1,br2); - p4 -= syn_width * 2; - addPixelFast(p4,br1,br2); - } + unsigned char *p = output + px * 2 + py * syn_width * 2, *p1 = p, *p2 = + p, *p3 = p, *p4 = p; + addPixelFast (p, br1, br2); + for (; br1 > 0 || br2 > 0; br1 = scaleDown[br1], br2 = scaleDown[br2]) { + p1 += 2; + addPixelFast (p1, br1, br2); + p2 -= 2; + addPixelFast (p2, br1, br2); + p3 += syn_width * 2; + addPixelFast (p3, br1, br2); + p4 -= syn_width * 2; + addPixelFast (p4, br1, br2); + } } } } - /* Apply autoscaling: makes quiet bits brighter, and loud bits - * darker, but still keeps loud bits brighter than quiet bits. */ - if(brtot != 0 && autobrightness) { - long int brTotTarget = brTotTargetHigh; - if(brightMax != brightMin) { - brTotTarget -= ((brTotTargetHigh - brTotTargetLow) * - (brightFactor - brightMin)) / - (brightMax - brightMin); - } - if(brtot < brTotTarget) { - brightFactor += brightInc; - if(brightFactor > brightMax) brightFactor = brightMax; - } else { - brightFactor -= brightDec; - if(brightFactor < brightMin) brightFactor = brightMin; - } - /* printf("brtot: %ld\tbrightFactor: %d\tbrTotTarget: %d\n", - brtot, brightFactor, brTotTarget); */ - } + /* Apply autoscaling: makes quiet bits brighter, and loud bits + * darker, but still keeps loud bits brighter than quiet bits. */ + if (brtot != 0 && autobrightness) { + long int brTotTarget = brTotTargetHigh; + + if (brightMax != brightMin) { + brTotTarget -= ((brTotTargetHigh - brTotTargetLow) * + (brightFactor - brightMin)) / (brightMax - brightMin); + } + if (brtot < brTotTarget) { + brightFactor += brightInc; + if (brightFactor > brightMax) + brightFactor = brightMax; + } else { + brightFactor -= brightDec; + if (brightFactor < brightMin) + brightFactor = brightMin; + } + /* printf("brtot: %ld\tbrightFactor: %d\tbrTotTarget: %d\n", + brtot, brightFactor, brTotTarget); */ + } } #define BOUND(x) ((x) > 255 ? 255 : (x)) #define PEAKIFY(x) BOUND((x) - (x)*(255-(x))/255/2) -static void synaescope32() +static void +synaescope32 () { - unsigned char *outptr; - guint32 colEq[256]; - int i; - guint32 bg_color; + unsigned char *outptr; + guint32 colEq[256]; + int i; + guint32 bg_color; - for (i = 0; i < 256; i++) { - int red = PEAKIFY((i&15*16)); - int green = PEAKIFY((i&15)*16+(i&15*16)/4); - int blue = PEAKIFY((i&15)*16); - colEq[i] = (red << 16) + (green << 8) + blue; - } - bg_color = (SCOPE_BG_RED << 16) + (SCOPE_BG_GREEN << 8) + SCOPE_BG_BLUE; + for (i = 0; i < 256; i++) { + int red = PEAKIFY ((i & 15 * 16)); + int green = PEAKIFY ((i & 15) * 16 + (i & 15 * 16) / 4); + int blue = PEAKIFY ((i & 15) * 16); - synaescope_coreGo(); + colEq[i] = (red << 16) + (green << 8) + blue; + } + bg_color = (SCOPE_BG_RED << 16) + (SCOPE_BG_GREEN << 8) + SCOPE_BG_BLUE; - outptr = output; - for (i=0; i < syn_width * syn_height; i++) { - display[i] = colEq[(outptr[0] >> 4) + (outptr[1] & 0xf0)]; - outptr += 2; - } + synaescope_coreGo (); + + outptr = output; + for (i = 0; i < syn_width * syn_height; i++) { + display[i] = colEq[(outptr[0] >> 4) + (outptr[1] & 0xf0)]; + outptr += 2; + } } #if 0 -static void synaescope16(void *data) +static void +synaescope16 (void *data) { - guint16 *bits; - guint16 colEq[256]; - int i; - GdkWindow *win; - GdkColormap *c; - GdkVisual *v; - GdkGC *gc; - GdkColor bg_color; + guint16 *bits; + guint16 colEq[256]; + int i; + GdkWindow *win; + GdkColormap *c; + GdkVisual *v; + GdkGC *gc; + GdkColor bg_color; - win = (GdkWindow *)data; - GDK_THREADS_ENTER(); - c = gdk_colormap_get_system(); - gc = gdk_gc_new(win); - v = gdk_window_get_visual(win); + win = (GdkWindow *) data; + GDK_THREADS_ENTER (); + c = gdk_colormap_get_system (); + gc = gdk_gc_new (win); + v = gdk_window_get_visual (win); - for (i = 0; i < 256; i++) { - GdkColor color; - color.red = PEAKIFY((i&15*16)) << 8; - color.green = PEAKIFY((i&15)*16+(i&15*16)/4) << 8; - color.blue = PEAKIFY((i&15)*16) << 8; - gdk_color_alloc(c, &color); - colEq[i] = color.pixel; - } + for (i = 0; i < 256; i++) { + GdkColor color; - /* Create render image */ - if (image) { - gdk_image_destroy(image); - image = NULL; - } - image = gdk_image_new(GDK_IMAGE_FASTEST, v, syn_width, syn_height); - bg_color.red = SCOPE_BG_RED << 8; - bg_color.green = SCOPE_BG_GREEN << 8; - bg_color.blue = SCOPE_BG_BLUE << 8; - gdk_color_alloc(c, &bg_color); - GDK_THREADS_LEAVE(); + color.red = PEAKIFY ((i & 15 * 16)) << 8; + color.green = PEAKIFY ((i & 15) * 16 + (i & 15 * 16) / 4) << 8; + color.blue = PEAKIFY ((i & 15) * 16) << 8; + gdk_color_alloc (c, &color); + colEq[i] = color.pixel; + } - assert(image); - assert(image->bpp == 2); + /* Create render image */ + if (image) { + gdk_image_destroy (image); + image = NULL; + } + image = gdk_image_new (GDK_IMAGE_FASTEST, v, syn_width, syn_height); + bg_color.red = SCOPE_BG_RED << 8; + bg_color.green = SCOPE_BG_GREEN << 8; + bg_color.blue = SCOPE_BG_BLUE << 8; + gdk_color_alloc (c, &bg_color); + GDK_THREADS_LEAVE (); - bits = (guint16 *)image->mem; + assert (image); + assert (image->bpp == 2); - running = 1; + bits = (guint16 *) image->mem; - SYNAESCOPE_DOLOOP(); + running = 1; + + SYNAESCOPE_DOLOOP (); } -static void synaescope8(void *data) +static void +synaescope8 (void *data) { - unsigned char *outptr; - guint8 *bits; - guint8 colEq[256]; - int i; - GdkWindow *win; - GdkColormap *c; - GdkVisual *v; - GdkGC *gc; - GdkColor bg_color; - - win = (GdkWindow *)data; - GDK_THREADS_ENTER(); - c = gdk_colormap_get_system(); - gc = gdk_gc_new(win); - v = gdk_window_get_visual(win); + unsigned char *outptr; + guint8 *bits; + guint8 colEq[256]; + int i; + GdkWindow *win; + GdkColormap *c; + GdkVisual *v; + GdkGC *gc; + GdkColor bg_color; - for (i = 0; i < 64; i++) { - GdkColor color; - color.red = PEAKIFY((i&7*8)*4) << 8; - color.green = PEAKIFY((i&7)*32+(i&7*8)*2) << 8; - color.blue = PEAKIFY((i&7)*32) << 8; - gdk_color_alloc(c, &color); - colEq[i * 4] = color.pixel; - colEq[i * 4 + 1] = color.pixel; - colEq[i * 4 + 2] = color.pixel; - colEq[i * 4 + 3] = color.pixel; - } + win = (GdkWindow *) data; + GDK_THREADS_ENTER (); + c = gdk_colormap_get_system (); + gc = gdk_gc_new (win); + v = gdk_window_get_visual (win); - /* Create render image */ - if (image) { - gdk_image_destroy(image); - image = NULL; - } - image = gdk_image_new(GDK_IMAGE_FASTEST, v, syn_width, syn_height); - bg_color.red = SCOPE_BG_RED << 8; - bg_color.green = SCOPE_BG_GREEN << 8; - bg_color.blue = SCOPE_BG_BLUE << 8; - gdk_color_alloc(c, &bg_color); - GDK_THREADS_LEAVE(); - - assert(image); - assert(image->bpp == 1); - - bits = (guint8 *)image->mem; + for (i = 0; i < 64; i++) { + GdkColor color; - running = 1; + color.red = PEAKIFY ((i & 7 * 8) * 4) << 8; + color.green = PEAKIFY ((i & 7) * 32 + (i & 7 * 8) * 2) << 8; + color.blue = PEAKIFY ((i & 7) * 32) << 8; + gdk_color_alloc (c, &color); + colEq[i * 4] = color.pixel; + colEq[i * 4 + 1] = color.pixel; + colEq[i * 4 + 2] = color.pixel; + colEq[i * 4 + 3] = color.pixel; + } - SYNAESCOPE_DOLOOP(); + /* Create render image */ + if (image) { + gdk_image_destroy (image); + image = NULL; + } + image = gdk_image_new (GDK_IMAGE_FASTEST, v, syn_width, syn_height); + bg_color.red = SCOPE_BG_RED << 8; + bg_color.green = SCOPE_BG_GREEN << 8; + bg_color.blue = SCOPE_BG_BLUE << 8; + gdk_color_alloc (c, &bg_color); + GDK_THREADS_LEAVE (); + + assert (image); + assert (image->bpp == 1); + + bits = (guint8 *) image->mem; + + running = 1; + + SYNAESCOPE_DOLOOP (); } #endif #if 0 -static void run_synaescope(void *data) +static void +run_synaescope (void *data) { - switch (depth) { - case 8: - synaescope8(win); - break; - case 16: - synaescope16(win); - break; - case 24: - case 32: - synaescope32(win); - break; + switch (depth) { + case 8: + synaescope8 (win); + break; + case 16: + synaescope16 (win); + break; + case 24: + case 32: + synaescope32 (win); + break; - } + } } -static void start_synaescope(void *data) +static void +start_synaescope (void *data) { - init_synaescope_window(); + init_synaescope_window (); } #endif -static int bitReverser(int i) { - int sum = 0; - int j; +static int +bitReverser (int i) +{ + int sum = 0; + int j; - for(j = 0; j < FFT_BUFFER_SIZE_LOG; j++) { - sum = (i & 1) + sum * 2; - i >>= 1; + for (j = 0; j < FFT_BUFFER_SIZE_LOG; j++) { + sum = (i & 1) + sum * 2; + i >>= 1; + } + + return sum; +} + +static void +init_synaescope () +{ + int i; + + for (i = 0; i <= FFT_BUFFER_SIZE / 2 + 1; i++) { + double mult = (double) 128 / ((FFT_BUFFER_SIZE * 16384) ^ 2); + + /* Result now guaranteed (well, almost) to be in range 0..128 */ + + /* Low values represent more frequencies, and thus get more */ + /* intensity - this helps correct for that. */ + mult *= log (i + 1) / log (2); + + mult *= 3; /* Adhoc parameter, looks about right for me. */ + + fftmult[i] = mult; + } + + for (i = 0; i < FFT_BUFFER_SIZE; i++) { + negSinTable[i] = -sin (M_PI * 2 / FFT_BUFFER_SIZE * i); + cosTable[i] = cos (M_PI * 2 / FFT_BUFFER_SIZE * i); + bitReverse[i] = bitReverser (i); + } + + for (i = 0; i < 256; i++) + scaleDown[i] = i * 200 >> 8; + + memset (output, 0, syn_width * syn_height * 2); +} + +static void +synaes_fft (double *x, double *y) +{ + int n2 = FFT_BUFFER_SIZE; + int n1; + int twoToTheK; + int j; + + for (twoToTheK = 1; twoToTheK < FFT_BUFFER_SIZE; twoToTheK *= 2) { + n1 = n2; + n2 /= 2; + for (j = 0; j < n2; j++) { + double c = cosTable[j * twoToTheK & (FFT_BUFFER_SIZE - 1)]; + double s = negSinTable[j * twoToTheK & (FFT_BUFFER_SIZE - 1)]; + int i; + + for (i = j; i < FFT_BUFFER_SIZE; i += n1) { + int l = i + n2; + double xt = x[i] - x[l]; + double yt = y[i] - y[l]; + + x[i] = (x[i] + x[l]); + y[i] = (y[i] + y[l]); + x[l] = xt * c - yt * s; + y[l] = xt * s + yt * c; + } } - - return sum; + } } -static void init_synaescope() +static void +synaescope_set_data (gint16 data[2][512]) { - int i; + int i; + gint16 *newset_l = pcmt_l; + gint16 *newset_r = pcmt_r; - for(i = 0; i <= FFT_BUFFER_SIZE / 2 + 1; i++) { - double mult = (double)128 / ((FFT_BUFFER_SIZE * 16384) ^ 2); - /* Result now guaranteed (well, almost) to be in range 0..128 */ - - /* Low values represent more frequencies, and thus get more */ - /* intensity - this helps correct for that. */ - mult *= log(i + 1) / log(2); - - mult *= 3; /* Adhoc parameter, looks about right for me. */ - - fftmult[i] = mult; - } - - for(i = 0; i < FFT_BUFFER_SIZE; i++) { - negSinTable[i] = -sin(M_PI * 2 / FFT_BUFFER_SIZE*i); - cosTable[i] = cos(M_PI * 2 / FFT_BUFFER_SIZE*i); - bitReverse[i] = bitReverser(i); - } - - for(i=0;i<256;i++) - scaleDown[i] = i*200>>8; - - memset(output, 0, syn_width * syn_height * 2); + for (i = 0; i < FFT_BUFFER_SIZE; i++) { + newset_l[i] = data[0][i]; + newset_r[i] = data[1][i]; + } } -static void synaes_fft(double *x, double *y) { - int n2 = FFT_BUFFER_SIZE; - int n1; - int twoToTheK; - int j; - for(twoToTheK = 1; twoToTheK < FFT_BUFFER_SIZE; twoToTheK *= 2) { - n1 = n2; - n2 /= 2; - for(j = 0; j < n2; j++) { - double c = cosTable[j * twoToTheK & (FFT_BUFFER_SIZE - 1)]; - double s = negSinTable[j * twoToTheK & (FFT_BUFFER_SIZE - 1)]; - int i; - for(i = j; i < FFT_BUFFER_SIZE; i += n1) { - int l = i + n2; - double xt = x[i] - x[l]; - double yt = y[i] - y[l]; - x[i] = (x[i] + x[l]); - y[i] = (y[i] + y[l]); - x[l] = xt * c - yt * s; - y[l] = xt * s + yt * c; - } - } - } -} - -static void synaescope_set_data(gint16 data [2][512]) +void +synaesthesia_init (guint32 resx, guint32 resy) { - int i; - gint16 *newset_l = pcmt_l; - gint16 *newset_r = pcmt_r; - for (i=0; i < FFT_BUFFER_SIZE; i++) { - newset_l[i] = data[0][i]; - newset_r[i] = data[1][i]; - } + init_synaescope (); } -void synaesthesia_init (guint32 resx, guint32 resy) +guint32 * +synaesthesia_update (gint16 data[2][512]) { - init_synaescope(); + synaescope_set_data (data); + synaescope32 (); + return display; } -guint32 * synaesthesia_update (gint16 data [2][512]) -{ - synaescope_set_data(data); - synaescope32(); - return display; -} - -void synaesthesia_close () +void +synaesthesia_close () { } - diff --git a/gst/synaesthesia/synaescope.h b/gst/synaesthesia/synaescope.h index 1392131c15..2233bb9e38 100644 --- a/gst/synaesthesia/synaescope.h +++ b/gst/synaesthesia/synaescope.h @@ -4,7 +4,7 @@ #include void synaesthesia_init (guint32 resx, guint32 resy); -guint32 * synaesthesia_update (gint16 data [2][512]); +guint32 *synaesthesia_update (gint16 data[2][512]); void synaesthesia_close (); #endif