2005-08-26 13:28:01 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2003 Thomas Vander Stichele <thomas@apestaart.org>
|
|
|
|
* 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
|
|
|
* 2005 Andy Wingo <wingo@pobox.com>
|
|
|
|
* 2005 Jan Schmidt <thaytan@mad.scientist.com>
|
|
|
|
*
|
|
|
|
* gst-metadata.c: Use GStreamer to display metadata within files.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* gst/gstconfig.h.in:
* libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer):
* libs/gst/check/gstcheck.c: (gst_check_log_message_func),
(gst_check_log_critical_func), (gst_check_drop_buffers),
(gst_check_element_push_buffer_list):
* libs/gst/controller/gstcontroller.c: (gst_controller_get),
(gst_controller_get_type):
* libs/gst/controller/gsthelper.c: (gst_object_control_properties),
(gst_object_get_controller), (gst_object_get_control_source):
* libs/gst/controller/gstinterpolationcontrolsource.c:
(gst_interpolation_control_source_new):
* libs/gst/controller/gstlfocontrolsource.c:
(gst_lfo_control_source_new):
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_event_from_packet_0_2):
* plugins/elements/gstfdsrc.c:
* plugins/elements/gstmultiqueue.c:
* plugins/elements/gsttee.c:
* plugins/elements/gsttypefindelement.c:
* plugins/indexers/gstfileindex.c: (_file_index_id_save_xml),
(gst_file_index_add_association):
* plugins/indexers/gstmemindex.c:
* tests/benchmarks/gstpollstress.c: (mess_some_more):
* tests/check/elements/queue.c: (setup_queue):
* tests/check/gst/gstpipeline.c:
* tests/check/libs/collectpads.c: (setup), (teardown),
(gst_collect_pads_suite):
* tests/examples/adapter/adapter_test.c:
* tests/examples/metadata/read-metadata.c: (make_pipeline):
* tests/examples/xml/createxml.c:
* tests/examples/xml/runxml.c:
* tools/gst-inspect.c:
* tools/gst-run.c:
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers, not using variable sized arrays
on the stack, moving variable declarations to the beginning of
a block and using "foo (void)" instead of "foo ()" for declarations.
2008-02-29 12:41:33 +00:00
|
|
|
static char *filename = NULL;
|
|
|
|
static GstElement *pipeline = NULL;
|
|
|
|
static GstElement *source = NULL;
|
2005-08-26 13:28:01 +00:00
|
|
|
|
|
|
|
#define NEW_PIPE_PER_FILE
|
|
|
|
|
2005-11-20 17:12:49 +00:00
|
|
|
static gboolean
|
2005-08-26 13:28:01 +00:00
|
|
|
message_loop (GstElement * element, GstTagList ** tags)
|
|
|
|
{
|
|
|
|
GstBus *bus;
|
|
|
|
gboolean done = FALSE;
|
|
|
|
|
|
|
|
bus = gst_element_get_bus (element);
|
2005-11-20 17:12:49 +00:00
|
|
|
g_return_val_if_fail (bus != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (tags != NULL, FALSE);
|
2005-08-26 13:28:01 +00:00
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
GstMessage *message;
|
|
|
|
|
2005-12-14 10:09:35 +00:00
|
|
|
message = gst_bus_pop (bus);
|
2005-08-26 13:28:01 +00:00
|
|
|
if (message == NULL)
|
2005-11-20 17:12:49 +00:00
|
|
|
/* All messages read, we're done */
|
|
|
|
break;
|
2005-08-26 13:28:01 +00:00
|
|
|
|
|
|
|
switch (GST_MESSAGE_TYPE (message)) {
|
|
|
|
case GST_MESSAGE_ERROR:
|
2005-11-20 17:12:49 +00:00
|
|
|
case GST_MESSAGE_EOS:
|
|
|
|
gst_message_unref (message);
|
|
|
|
return TRUE;
|
2005-08-26 13:28:01 +00:00
|
|
|
case GST_MESSAGE_TAG:
|
|
|
|
{
|
|
|
|
GstTagList *new_tags;
|
|
|
|
|
|
|
|
gst_message_parse_tag (message, &new_tags);
|
2005-11-20 17:12:49 +00:00
|
|
|
if (*tags)
|
2007-10-31 18:08:21 +00:00
|
|
|
*tags = gst_tag_list_merge (*tags, new_tags, GST_TAG_MERGE_KEEP);
|
2005-11-20 17:12:49 +00:00
|
|
|
else
|
|
|
|
*tags = new_tags;
|
2005-08-26 13:28:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_message_unref (message);
|
|
|
|
}
|
|
|
|
gst_object_unref (bus);
|
2005-11-20 17:12:49 +00:00
|
|
|
return TRUE;
|
2005-08-26 13:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* gst/gstconfig.h.in:
* libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer):
* libs/gst/check/gstcheck.c: (gst_check_log_message_func),
(gst_check_log_critical_func), (gst_check_drop_buffers),
(gst_check_element_push_buffer_list):
* libs/gst/controller/gstcontroller.c: (gst_controller_get),
(gst_controller_get_type):
* libs/gst/controller/gsthelper.c: (gst_object_control_properties),
(gst_object_get_controller), (gst_object_get_control_source):
* libs/gst/controller/gstinterpolationcontrolsource.c:
(gst_interpolation_control_source_new):
* libs/gst/controller/gstlfocontrolsource.c:
(gst_lfo_control_source_new):
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_event_from_packet_0_2):
* plugins/elements/gstfdsrc.c:
* plugins/elements/gstmultiqueue.c:
* plugins/elements/gsttee.c:
* plugins/elements/gsttypefindelement.c:
* plugins/indexers/gstfileindex.c: (_file_index_id_save_xml),
(gst_file_index_add_association):
* plugins/indexers/gstmemindex.c:
* tests/benchmarks/gstpollstress.c: (mess_some_more):
* tests/check/elements/queue.c: (setup_queue):
* tests/check/gst/gstpipeline.c:
* tests/check/libs/collectpads.c: (setup), (teardown),
(gst_collect_pads_suite):
* tests/examples/adapter/adapter_test.c:
* tests/examples/metadata/read-metadata.c: (make_pipeline):
* tests/examples/xml/createxml.c:
* tests/examples/xml/runxml.c:
* tools/gst-inspect.c:
* tools/gst-run.c:
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers, not using variable sized arrays
on the stack, moving variable declarations to the beginning of
a block and using "foo (void)" instead of "foo ()" for declarations.
2008-02-29 12:41:33 +00:00
|
|
|
make_pipeline (void)
|
2005-08-26 13:28:01 +00:00
|
|
|
{
|
2005-11-20 17:12:49 +00:00
|
|
|
GstElement *decodebin;
|
2005-08-26 13:28:01 +00:00
|
|
|
|
|
|
|
if (pipeline != NULL)
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
|
|
|
|
pipeline = gst_pipeline_new (NULL);
|
|
|
|
|
|
|
|
source = gst_element_factory_make ("filesrc", "source");
|
|
|
|
g_assert (GST_IS_ELEMENT (source));
|
|
|
|
decodebin = gst_element_factory_make ("decodebin", "decodebin");
|
|
|
|
g_assert (GST_IS_ELEMENT (decodebin));
|
|
|
|
|
2005-11-20 17:12:49 +00:00
|
|
|
gst_bin_add_many (GST_BIN (pipeline), source, decodebin, NULL);
|
2005-08-26 13:28:01 +00:00
|
|
|
gst_element_link (source, decodebin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
|
|
|
|
{
|
|
|
|
gint i, count;
|
|
|
|
|
|
|
|
count = gst_tag_list_get_tag_size (list, tag);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
if (gst_tag_get_type (tag) == G_TYPE_STRING) {
|
|
|
|
if (!gst_tag_list_get_string_index (list, tag, i, &str))
|
|
|
|
g_assert_not_reached ();
|
|
|
|
} else {
|
|
|
|
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 {
|
|
|
|
g_print (" : %s\n", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
guint i = 1;
|
|
|
|
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
g_print ("Please give filenames to read metadata from\n\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
make_pipeline ();
|
|
|
|
while (i < argc) {
|
2005-09-02 15:42:00 +00:00
|
|
|
GstStateChangeReturn sret;
|
|
|
|
GstState state;
|
2005-11-20 17:12:49 +00:00
|
|
|
GstTagList *tags = NULL;
|
2005-08-26 13:28:01 +00:00
|
|
|
|
|
|
|
filename = argv[i];
|
|
|
|
g_object_set (source, "location", filename, NULL);
|
|
|
|
|
|
|
|
GST_DEBUG ("Starting reading for %s", filename);
|
|
|
|
|
|
|
|
/* Decodebin will only commit to PAUSED if it actually finds a type;
|
|
|
|
* otherwise the state change fails */
|
|
|
|
sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
|
|
|
|
|
2005-09-02 15:42:00 +00:00
|
|
|
if (GST_STATE_CHANGE_ASYNC == sret) {
|
2005-11-20 17:12:49 +00:00
|
|
|
if (GST_STATE_CHANGE_SUCCESS !=
|
|
|
|
gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
|
|
|
|
5 * GST_SECOND)) {
|
|
|
|
g_print ("State change failed for %s. Aborting\n", filename);
|
2005-08-26 13:28:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-09-02 15:42:00 +00:00
|
|
|
} else if (sret != GST_STATE_CHANGE_SUCCESS) {
|
2005-11-20 17:12:49 +00:00
|
|
|
g_print ("%s - Could not read file\n", filename);
|
|
|
|
goto next_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!message_loop (GST_ELEMENT (pipeline), &tags)) {
|
|
|
|
g_print ("Failed in message reading for %s\n", argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tags) {
|
|
|
|
g_print ("Metadata for %s:\n", argv[i]);
|
|
|
|
gst_tag_list_foreach (tags, print_tag, NULL);
|
|
|
|
gst_tag_list_free (tags);
|
|
|
|
tags = NULL;
|
|
|
|
} else
|
|
|
|
g_print ("No metadata found for %s\n", argv[i]);
|
2005-08-26 13:28:01 +00:00
|
|
|
|
2005-11-20 17:12:49 +00:00
|
|
|
sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
|
|
|
#ifndef NEW_PIPE_PER_FILE
|
|
|
|
if (GST_STATE_CHANGE_ASYNC == sret) {
|
|
|
|
if (GST_STATE_CHANGE_FAILURE ==
|
|
|
|
gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
|
|
|
|
GST_CLOCK_TIME_NONE)) {
|
|
|
|
g_print ("State change failed. Aborting");
|
|
|
|
break;
|
2005-08-26 13:28:01 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-20 17:12:49 +00:00
|
|
|
#endif
|
2005-08-26 13:28:01 +00:00
|
|
|
|
2005-11-20 17:12:49 +00:00
|
|
|
next_file:
|
2005-08-26 13:28:01 +00:00
|
|
|
i++;
|
|
|
|
|
|
|
|
#ifdef NEW_PIPE_PER_FILE
|
|
|
|
make_pipeline ();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pipeline)
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
return 0;
|
|
|
|
}
|