2002-11-27 21:01:41 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-12-12 22:15:39 +00:00
|
|
|
#include <string.h>
|
2002-11-27 21:01:41 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
static gboolean verbose = FALSE;
|
|
|
|
static gboolean quiet = FALSE;
|
|
|
|
|
2002-11-27 21:01:41 +00:00
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
entry_added (GstIndex * index, GstIndexEntry * entry)
|
2002-11-27 21:01:41 +00:00
|
|
|
{
|
|
|
|
switch (entry->type) {
|
2002-12-12 22:15:39 +00:00
|
|
|
case GST_INDEX_ENTRY_ID:
|
2004-03-14 22:34:30 +00:00
|
|
|
g_print ("id %d describes writer %s\n", entry->id,
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_INDEX_ID_DESCRIPTION (entry));
|
2002-11-27 21:01:41 +00:00
|
|
|
break;
|
2002-12-12 22:15:39 +00:00
|
|
|
case GST_INDEX_ENTRY_FORMAT:
|
2004-03-14 22:34:30 +00:00
|
|
|
g_print ("%d: registered format %d for %s\n", entry->id,
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_INDEX_FORMAT_FORMAT (entry), GST_INDEX_FORMAT_KEY (entry));
|
2002-11-27 21:01:41 +00:00
|
|
|
break;
|
2002-12-12 22:15:39 +00:00
|
|
|
case GST_INDEX_ENTRY_ASSOCIATION:
|
2002-11-27 21:01:41 +00:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
g_print ("%p, %d: %08x ", entry, entry->id,
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_INDEX_ASSOC_FLAGS (entry));
|
2002-12-12 22:15:39 +00:00
|
|
|
for (i = 0; i < GST_INDEX_NASSOCS (entry); i++) {
|
Fixes: #151879, #151881, #151882, #151883, #151884, #151886, #151887, #152102, #152247.
Original commit message from CVS:
Fixes: #151879, #151881, #151882, #151883, #151884, #151886,
#151887, #152102, #152247.
* examples/indexing/indexmpeg.c: 64-bit warning fixes.
* examples/seeking/cdparanoia.c: same
* examples/seeking/cdplayer.c: same
* examples/seeking/seek.c: same
* examples/seeking/spider_seek.c: same
* examples/seeking/vorbisfile.c: same
* examples/stats/mp2ogg.c: same
* ext/esd/esdsink.c: (gst_esdsink_class_init),
(gst_esdsink_dispose): Dispose of element properly.
* ext/ivorbis/vorbisfile.c: (gst_ivorbisfile_seek): 64-bit warning
fixes.
* ext/nas/nassink.c: (gst_nassink_class_init),
(gst_nassink_dispose): Dispose of element correctly.
* gst/wavenc/gstwavenc.c: (gst_wavenc_chain): Fix leak.
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new), (gst_ximagesink_ximage_destroy):
Fix 64-bit warning.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_destroy):
Fix 64-bit warning.
2004-09-12 22:57:26 +00:00
|
|
|
g_print ("%d %" G_GINT64_FORMAT " ", GST_INDEX_ASSOC_FORMAT (entry, i),
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_INDEX_ASSOC_VALUE (entry, i));
|
2002-11-27 21:01:41 +00:00
|
|
|
}
|
|
|
|
g_print ("\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-12 22:15:39 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2004-03-14 22:34:30 +00:00
|
|
|
const gchar *padname;
|
|
|
|
GstPad *target;
|
|
|
|
GstElement *bin;
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstIndex *index;
|
2004-03-15 19:32:25 +00:00
|
|
|
}
|
|
|
|
dyn_link;
|
2002-12-12 22:15:39 +00:00
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data)
|
2002-12-12 22:15:39 +00:00
|
|
|
{
|
2003-01-12 13:17:41 +00:00
|
|
|
dyn_link *link = (dyn_link *) data;
|
|
|
|
|
|
|
|
if (!strcmp (gst_pad_get_name (newpad), link->padname)) {
|
|
|
|
gst_element_set_state (link->pipeline, GST_STATE_PAUSED);
|
|
|
|
gst_bin_add (GST_BIN (link->pipeline), link->bin);
|
|
|
|
gst_pad_link (newpad, link->target);
|
|
|
|
gst_element_set_index (link->bin, link->index);
|
|
|
|
gst_element_set_state (link->pipeline, GST_STATE_PLAYING);
|
2002-12-12 22:15:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
setup_dynamic_linking (GstElement * pipeline,
|
|
|
|
GstElement * element,
|
|
|
|
const gchar * padname, GstPad * target, GstElement * bin, GstIndex * index)
|
2002-12-12 22:15:39 +00:00
|
|
|
{
|
2003-01-12 13:17:41 +00:00
|
|
|
dyn_link *link;
|
2002-12-12 22:15:39 +00:00
|
|
|
|
2003-01-12 13:17:41 +00:00
|
|
|
link = g_new0 (dyn_link, 1);
|
2004-03-14 22:34:30 +00:00
|
|
|
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);
|
2002-12-12 22:15:39 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static GstElement *
|
|
|
|
make_mpeg_systems_pipeline (const gchar * path, GstIndex * index)
|
2002-11-27 21:01:41 +00:00
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *src, *demux;
|
|
|
|
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
|
|
|
|
src = gst_element_factory_make ("filesrc", "src");
|
|
|
|
g_object_set (G_OBJECT (src), "location", path, NULL);
|
|
|
|
|
|
|
|
demux = gst_element_factory_make ("mpegdemux", "demux");
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (pipeline), src);
|
|
|
|
gst_bin_add (GST_BIN (pipeline), demux);
|
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
if (index) {
|
|
|
|
gst_element_set_index (pipeline, index);
|
|
|
|
}
|
2002-11-27 21:01:41 +00:00
|
|
|
|
2003-01-12 13:17:41 +00:00
|
|
|
gst_element_link_pads (src, "src", demux, "sink");
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2002-11-27 21:01:41 +00:00
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static GstElement *
|
|
|
|
make_mpeg_decoder_pipeline (const gchar * path, GstIndex * index)
|
2002-12-12 22:15:39 +00:00
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *src, *demux;
|
|
|
|
GstElement *video_bin, *audio_bin;
|
|
|
|
GstElement *video_decoder, *audio_decoder;
|
|
|
|
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
|
|
|
|
src = gst_element_factory_make ("filesrc", "src");
|
|
|
|
g_object_set (G_OBJECT (src), "location", path, NULL);
|
|
|
|
|
|
|
|
demux = gst_element_factory_make ("mpegdemux", "demux");
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (pipeline), src);
|
|
|
|
gst_bin_add (GST_BIN (pipeline), demux);
|
|
|
|
|
2003-01-12 13:17:41 +00:00
|
|
|
gst_element_link_pads (src, "src", demux, "sink");
|
2002-12-12 22:15:39 +00:00
|
|
|
|
|
|
|
video_bin = gst_bin_new ("video_bin");
|
|
|
|
video_decoder = gst_element_factory_make ("mpeg2dec", "video_decoder");
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (video_bin), video_decoder);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
|
|
|
setup_dynamic_linking (pipeline, demux, "video_00",
|
|
|
|
gst_element_get_pad (video_decoder, "sink"), video_bin, index);
|
2002-12-12 22:15:39 +00:00
|
|
|
|
|
|
|
audio_bin = gst_bin_new ("audio_bin");
|
|
|
|
audio_decoder = gst_element_factory_make ("mad", "audio_decoder");
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
setup_dynamic_linking (pipeline, demux, "audio_00",
|
|
|
|
gst_element_get_pad (audio_decoder, "sink"), audio_bin, index);
|
2003-01-20 19:36:46 +00:00
|
|
|
|
2002-12-12 22:15:39 +00:00
|
|
|
gst_bin_add (GST_BIN (audio_bin), audio_decoder);
|
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
if (index) {
|
|
|
|
gst_element_set_index (pipeline, index);
|
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2002-12-12 22:15:39 +00:00
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
print_progress (GstPad * pad)
|
2002-12-23 00:38:04 +00:00
|
|
|
{
|
|
|
|
gint i = 0;
|
|
|
|
gchar status[53];
|
|
|
|
GstFormat format;
|
|
|
|
gboolean res;
|
|
|
|
gint64 value;
|
|
|
|
gint percent = 0;
|
|
|
|
|
|
|
|
status[0] = '|';
|
|
|
|
|
|
|
|
format = GST_FORMAT_PERCENT;
|
2002-12-30 17:53:18 +00:00
|
|
|
res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &value);
|
2002-12-23 00:38:04 +00:00
|
|
|
if (res) {
|
2004-03-14 22:34:30 +00:00
|
|
|
percent = value / (2 * GST_FORMAT_PERCENT_SCALE);
|
2002-12-23 00:38:04 +00:00
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
for (i = 0; i < percent; i++) {
|
2004-03-14 22:34:30 +00:00
|
|
|
status[i + 1] = '=';
|
2002-12-23 00:38:04 +00:00
|
|
|
}
|
|
|
|
for (i = percent; i < 50; i++) {
|
2004-03-14 22:34:30 +00:00
|
|
|
status[i + 1] = ' ';
|
2002-12-23 00:38:04 +00:00
|
|
|
}
|
|
|
|
status[51] = '|';
|
|
|
|
status[52] = 0;
|
|
|
|
|
|
|
|
g_print ("%s\r", status);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
gint
|
|
|
|
main (gint argc, gchar * argv[])
|
2002-11-27 21:01:41 +00:00
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
2002-12-23 00:38:04 +00:00
|
|
|
GstElement *src;
|
|
|
|
GstPad *pad;
|
|
|
|
GstIndex *index;
|
|
|
|
gint count = 0;
|
|
|
|
GstEvent *event;
|
|
|
|
gboolean res;
|
2002-12-26 22:53:36 +00:00
|
|
|
GstElement *sink;
|
2002-12-23 00:38:04 +00:00
|
|
|
struct poptOption options[] = {
|
2004-03-14 22:34:30 +00:00
|
|
|
{"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0,
|
2004-03-15 19:32:25 +00:00
|
|
|
"Print index entries", NULL},
|
2004-03-14 22:34:30 +00:00
|
|
|
{"quiet", 'q', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &quiet, 0,
|
2004-03-15 19:32:25 +00:00
|
|
|
"don't print progress bar", NULL},
|
2004-03-14 22:34:30 +00:00
|
|
|
POPT_TABLEEND
|
|
|
|
};
|
2002-12-23 00:38:04 +00:00
|
|
|
|
2003-07-26 04:23:32 +00:00
|
|
|
if (!gst_init_check_with_popt_table (&argc, &argv, options) || argc < 3) {
|
2004-03-14 22:34:30 +00:00
|
|
|
g_print ("usage: %s [-v] <type> <filename> \n"
|
2004-03-15 19:32:25 +00:00
|
|
|
" 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]);
|
2002-11-27 21:01:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
/* create index that elements can fill */
|
|
|
|
index = gst_index_factory_make ("memindex");
|
2003-01-12 13:17:41 +00:00
|
|
|
if (index) {
|
2004-03-14 22:34:30 +00:00
|
|
|
if (verbose)
|
|
|
|
g_signal_connect (G_OBJECT (index), "entry_added",
|
2004-03-15 19:32:25 +00:00
|
|
|
G_CALLBACK (entry_added), NULL);
|
2003-01-12 13:17:41 +00:00
|
|
|
|
|
|
|
g_object_set (G_OBJECT (index), "resolver", 1, NULL);
|
|
|
|
}
|
2002-12-23 00:38:04 +00:00
|
|
|
|
|
|
|
/* construct pipeline */
|
2002-12-12 22:15:39 +00:00
|
|
|
switch (atoi (argv[1])) {
|
|
|
|
case 0:
|
2002-12-23 00:38:04 +00:00
|
|
|
pipeline = make_mpeg_systems_pipeline (argv[2], index);
|
2002-12-12 22:15:39 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2002-12-23 00:38:04 +00:00
|
|
|
pipeline = make_mpeg_decoder_pipeline (argv[2], index);
|
2002-12-12 22:15:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-02-16 17:09:18 +00:00
|
|
|
g_print ("unknown type %d\n", atoi (argv[1]));
|
2002-12-12 22:15:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
/* setup some default info/error handlers */
|
2004-03-14 22:34:30 +00:00
|
|
|
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);
|
2002-11-27 21:01:41 +00:00
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
/* get a pad to perform progress reporting on */
|
|
|
|
src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
|
|
|
|
pad = gst_element_get_pad (src, "src");
|
|
|
|
|
|
|
|
/* prepare for iteration */
|
2002-11-27 21:01:41 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
g_print ("indexing %s...\n", argv[2]);
|
2002-12-23 00:38:04 +00:00
|
|
|
/* run through the complete stream to let it generate an index */
|
|
|
|
while (gst_bin_iterate (GST_BIN (pipeline))) {
|
|
|
|
if (!quiet && (count % 1000 == 0)) {
|
|
|
|
print_progress (pad);
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
g_print ("\n");
|
|
|
|
|
|
|
|
/* bring to ready to restart the pipeline */
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_READY);
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
|
2002-12-26 22:53:36 +00:00
|
|
|
if (index)
|
renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition
Original commit message from CVS:
* examples/indexing/indexmpeg.c: (main):
* ext/a52dec/gsta52dec.c: (gst_a52dec_init):
* ext/dvdnav/dvdnavsrc.c: (dvdnavsrc_is_open),
(dvdnavsrc_set_property), (dvdnavsrc_open), (dvdnavsrc_close),
(dvdnavsrc_event), (dvdnavsrc_convert), (dvdnavsrc_query):
* ext/dvdread/dvdreadsrc.c: (dvdreadsrc_set_property),
(dvdreadsrc_srcpad_query), (dvdreadsrc_get),
(dvdreadsrc_open_file), (dvdreadsrc_close_file):
* ext/dvdread/dvdreadsrc.h:
* ext/lame/gstlame.h:
* gst/asfdemux/gstasfdemux.c: (gst_asf_demux_init):
* gst/asfdemux/gstasfmux.c: (gst_asfmux_init):
* gst/iec958/ac3iec.h:
* gst/mpegstream/gstdvddemux.c: (gst_dvd_demux_init):
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_init):
* gst/mpegstream/gstmpegparse.c: (gst_mpeg_parse_init):
* gst/mpegstream/gstrfc2250enc.c: (gst_rfc2250_enc_init):
* gst/synaesthesia/gstsynaesthesia.c: (gst_synaesthesia_init):
renamed GST_FLAGS macros to GST_OBJECT_FLAGS
moved bitshift from macro to enum definition
2005-10-12 14:30:36 +00:00
|
|
|
GST_OBJECT_FLAG_UNSET (index, GST_INDEX_WRITABLE);
|
2002-12-23 00:38:04 +00:00
|
|
|
|
|
|
|
src = gst_bin_get_by_name (GST_BIN (pipeline), "video_decoder");
|
2003-01-12 13:17:41 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
gint id;
|
|
|
|
GstIndexEntry *entry;
|
|
|
|
gint64 result;
|
|
|
|
gint total_tm;
|
|
|
|
|
|
|
|
gst_index_get_writer_id (index, GST_OBJECT (src), &id);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2003-01-12 13:17:41 +00:00
|
|
|
entry = gst_index_get_assoc_entry (index, id, GST_INDEX_LOOKUP_BEFORE, 0,
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_FORMAT_TIME, G_MAXINT64);
|
2003-01-12 13:17:41 +00:00
|
|
|
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);
|
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2002-12-23 00:38:04 +00:00
|
|
|
pad = gst_element_get_pad (src, "src");
|
2002-12-26 22:53:36 +00:00
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
2003-01-12 13:17:41 +00:00
|
|
|
gst_element_link_pads (src, "src", sink, "sink");
|
2002-12-26 22:53:36 +00:00
|
|
|
gst_bin_add (GST_BIN (pipeline), sink);
|
2002-12-23 00:38:04 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
g_print ("seeking %s...\n", argv[2]);
|
2002-12-23 00:38:04 +00:00
|
|
|
event = gst_event_new_seek (GST_FORMAT_TIME |
|
2004-03-14 22:34:30 +00:00
|
|
|
GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 5 * GST_SECOND);
|
2002-12-23 00:38:04 +00:00
|
|
|
|
|
|
|
res = gst_pad_send_event (pad, event);
|
|
|
|
if (!res) {
|
|
|
|
g_warning ("seek failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2002-12-26 22:53:36 +00:00
|
|
|
count = 0;
|
|
|
|
while (gst_bin_iterate (GST_BIN (pipeline))) {
|
|
|
|
if (!quiet && (count % 1000 == 0)) {
|
|
|
|
print_progress (pad);
|
|
|
|
}
|
|
|
|
count++;
|
2002-12-23 00:38:04 +00:00
|
|
|
}
|
2002-11-27 21:01:41 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|