mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 18:05:37 +00:00
cache -> index
Original commit message from CVS: cache -> index
This commit is contained in:
parent
0820b958ef
commit
d96e951b4d
3 changed files with 133 additions and 34 deletions
|
@ -17,29 +17,30 @@
|
||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
entry_added (GstCache *tc, GstCacheEntry *entry)
|
entry_added (GstIndex *index, GstIndexEntry *entry)
|
||||||
{
|
{
|
||||||
switch (entry->type) {
|
switch (entry->type) {
|
||||||
case GST_CACHE_ENTRY_ID:
|
case GST_INDEX_ENTRY_ID:
|
||||||
g_print ("id %d describes writer %s\n", entry->id,
|
g_print ("id %d describes writer %s\n", entry->id,
|
||||||
GST_CACHE_ID_DESCRIPTION (entry));
|
GST_INDEX_ID_DESCRIPTION (entry));
|
||||||
break;
|
break;
|
||||||
case GST_CACHE_ENTRY_FORMAT:
|
case GST_INDEX_ENTRY_FORMAT:
|
||||||
g_print ("%d: registered format %d for %s\n", entry->id,
|
g_print ("%d: registered format %d for %s\n", entry->id,
|
||||||
GST_CACHE_FORMAT_FORMAT (entry),
|
GST_INDEX_FORMAT_FORMAT (entry),
|
||||||
GST_CACHE_FORMAT_KEY (entry));
|
GST_INDEX_FORMAT_KEY (entry));
|
||||||
break;
|
break;
|
||||||
case GST_CACHE_ENTRY_ASSOCIATION:
|
case GST_INDEX_ENTRY_ASSOCIATION:
|
||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
g_print ("%d: %08x ", entry->id, GST_CACHE_ASSOC_FLAGS (entry));
|
g_print ("%d: %08x ", entry->id, GST_INDEX_ASSOC_FLAGS (entry));
|
||||||
for (i = 0; i < GST_CACHE_NASSOCS (entry); i++) {
|
for (i = 0; i < GST_INDEX_NASSOCS (entry); i++) {
|
||||||
g_print ("%d %lld ", GST_CACHE_ASSOC_FORMAT (entry, i),
|
g_print ("%d %lld ", GST_INDEX_ASSOC_FORMAT (entry, i),
|
||||||
GST_CACHE_ASSOC_VALUE (entry, i));
|
GST_INDEX_ASSOC_VALUE (entry, i));
|
||||||
}
|
}
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
break;
|
break;
|
||||||
|
@ -49,12 +50,51 @@ entry_added (GstCache *tc, GstCacheEntry *entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
const gchar *padname;
|
||||||
|
GstPad *target;
|
||||||
|
GstElement *bin;
|
||||||
|
GstElement *pipeline;
|
||||||
|
} dyn_connect;
|
||||||
|
|
||||||
|
static void
|
||||||
|
dynamic_connect (GstPadTemplate *templ, GstPad *newpad, gpointer data)
|
||||||
|
{
|
||||||
|
dyn_connect *connect = (dyn_connect *) data;
|
||||||
|
|
||||||
|
if (!strcmp (gst_pad_get_name (newpad), connect->padname)) {
|
||||||
|
gst_element_set_state (connect->pipeline, GST_STATE_PAUSED);
|
||||||
|
gst_bin_add (GST_BIN (connect->pipeline), connect->bin);
|
||||||
|
gst_pad_connect (newpad, connect->target);
|
||||||
|
gst_element_set_state (connect->pipeline, GST_STATE_PLAYING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
setup_dynamic_connection (GstElement *pipeline,
|
||||||
|
GstElement *element,
|
||||||
|
const gchar *padname,
|
||||||
|
GstPad *target,
|
||||||
|
GstElement *bin)
|
||||||
|
{
|
||||||
|
dyn_connect *connect;
|
||||||
|
|
||||||
|
connect = g_new0 (dyn_connect, 1);
|
||||||
|
connect->padname = g_strdup (padname);
|
||||||
|
connect->target = target;
|
||||||
|
connect->bin = bin;
|
||||||
|
connect->pipeline = pipeline;
|
||||||
|
|
||||||
|
g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_connect), connect);
|
||||||
|
}
|
||||||
|
|
||||||
static GstElement*
|
static GstElement*
|
||||||
make_mpeg_pipeline (const gchar *path)
|
make_mpeg_systems_pipeline (const gchar *path)
|
||||||
{
|
{
|
||||||
GstElement *pipeline;
|
GstElement *pipeline;
|
||||||
GstElement *src, *demux;
|
GstElement *src, *demux;
|
||||||
GstCache *cache;
|
GstIndex *index;
|
||||||
|
|
||||||
pipeline = gst_pipeline_new ("pipeline");
|
pipeline = gst_pipeline_new ("pipeline");
|
||||||
|
|
||||||
|
@ -66,15 +106,58 @@ make_mpeg_pipeline (const gchar *path)
|
||||||
gst_bin_add (GST_BIN (pipeline), src);
|
gst_bin_add (GST_BIN (pipeline), src);
|
||||||
gst_bin_add (GST_BIN (pipeline), demux);
|
gst_bin_add (GST_BIN (pipeline), demux);
|
||||||
|
|
||||||
cache = gst_cache_new ();
|
index = gst_index_factory_make ("memindex");
|
||||||
g_signal_connect (G_OBJECT (cache), "entry_added", G_CALLBACK (entry_added), NULL);
|
g_signal_connect (G_OBJECT (index), "entry_added", G_CALLBACK (entry_added), NULL);
|
||||||
gst_element_set_cache (demux, cache);
|
gst_element_set_index (demux, index);
|
||||||
|
|
||||||
gst_element_connect_pads (src, "src", demux, "sink");
|
gst_element_connect_pads (src, "src", demux, "sink");
|
||||||
|
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstElement*
|
||||||
|
make_mpeg_decoder_pipeline (const gchar *path)
|
||||||
|
{
|
||||||
|
GstElement *pipeline;
|
||||||
|
GstElement *src, *demux;
|
||||||
|
GstIndex *index;
|
||||||
|
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);
|
||||||
|
|
||||||
|
gst_element_connect_pads (src, "src", demux, "sink");
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
setup_dynamic_connection (pipeline, demux, "video_00",
|
||||||
|
gst_element_get_pad (video_decoder, "sink"),
|
||||||
|
video_bin);
|
||||||
|
|
||||||
|
audio_bin = gst_bin_new ("audio_bin");
|
||||||
|
audio_decoder = gst_element_factory_make ("mad", "audio_decoder");
|
||||||
|
|
||||||
|
gst_bin_add (GST_BIN (audio_bin), audio_decoder);
|
||||||
|
|
||||||
|
index = gst_index_factory_make ("memindex");
|
||||||
|
g_signal_connect (G_OBJECT (index), "entry_added", G_CALLBACK (entry_added), NULL);
|
||||||
|
gst_element_set_index (demux, index);
|
||||||
|
gst_element_set_index (video_decoder, index);
|
||||||
|
|
||||||
|
return pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
gint
|
gint
|
||||||
main (gint argc, gchar *argv[])
|
main (gint argc, gchar *argv[])
|
||||||
{
|
{
|
||||||
|
@ -82,13 +165,29 @@ main (gint argc, gchar *argv[])
|
||||||
|
|
||||||
gst_init (&argc, &argv);
|
gst_init (&argc, &argv);
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 3) {
|
||||||
g_print ("usage: %s <filename>\n", argv[0]);
|
g_print ("usage: %s <type> <filename> \n"
|
||||||
|
" type can be: 0 mpeg_systems\n"
|
||||||
|
" 1 mpeg_decoder\n", argv[0]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pipeline = make_mpeg_pipeline (argv[1]);
|
switch (atoi (argv[1])) {
|
||||||
|
case 0:
|
||||||
|
pipeline = make_mpeg_systems_pipeline (argv[2]);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
pipeline = make_mpeg_decoder_pipeline (argv[2]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_print ("unkown type %d\n", atoi (argv[1]));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,8 @@ static void gst_mpeg2dec_set_property (GObject *object, guint prop_id,
|
||||||
const GValue *value, GParamSpec *pspec);
|
const GValue *value, GParamSpec *pspec);
|
||||||
static void gst_mpeg2dec_get_property (GObject *object, guint prop_id,
|
static void gst_mpeg2dec_get_property (GObject *object, guint prop_id,
|
||||||
GValue *value, GParamSpec *pspec);
|
GValue *value, GParamSpec *pspec);
|
||||||
static void gst_mpeg2dec_set_cache (GstElement *element, GstCache *cache);
|
static void gst_mpeg2dec_set_index (GstElement *element, GstIndex *index);
|
||||||
static GstCache* gst_mpeg2dec_get_cache (GstElement *element);
|
static GstIndex* gst_mpeg2dec_get_index (GstElement *element);
|
||||||
|
|
||||||
static const GstFormat*
|
static const GstFormat*
|
||||||
gst_mpeg2dec_get_src_formats (GstPad *pad);
|
gst_mpeg2dec_get_src_formats (GstPad *pad);
|
||||||
|
@ -162,8 +162,8 @@ gst_mpeg2dec_class_init(GstMpeg2decClass *klass)
|
||||||
gobject_class->dispose = gst_mpeg2dec_dispose;
|
gobject_class->dispose = gst_mpeg2dec_dispose;
|
||||||
|
|
||||||
gstelement_class->change_state = gst_mpeg2dec_change_state;
|
gstelement_class->change_state = gst_mpeg2dec_change_state;
|
||||||
gstelement_class->set_cache = gst_mpeg2dec_set_cache;
|
gstelement_class->set_index = gst_mpeg2dec_set_index;
|
||||||
gstelement_class->get_cache = gst_mpeg2dec_get_cache;
|
gstelement_class->get_index = gst_mpeg2dec_get_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -205,21 +205,21 @@ gst_mpeg2dec_dispose (GObject *object)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_mpeg2dec_set_cache (GstElement *element, GstCache *cache)
|
gst_mpeg2dec_set_index (GstElement *element, GstIndex *index)
|
||||||
{
|
{
|
||||||
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element);
|
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element);
|
||||||
|
|
||||||
mpeg2dec->cache = cache;
|
mpeg2dec->index = index;
|
||||||
|
|
||||||
gst_cache_get_writer_id (cache, GST_OBJECT (element), &mpeg2dec->cache_id);
|
gst_index_get_writer_id (index, GST_OBJECT (element), &mpeg2dec->index_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstCache*
|
static GstIndex*
|
||||||
gst_mpeg2dec_get_cache (GstElement *element)
|
gst_mpeg2dec_get_index (GstElement *element)
|
||||||
{
|
{
|
||||||
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element);
|
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element);
|
||||||
|
|
||||||
return mpeg2dec->cache;
|
return mpeg2dec->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -428,8 +428,8 @@ gst_mpeg2dec_chain (GstPad *pad, GstBuffer *buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mpeg2dec->cache && pts != GST_CLOCK_TIME_NONE) {
|
if (mpeg2dec->index && pts != GST_CLOCK_TIME_NONE) {
|
||||||
gst_cache_add_association (mpeg2dec->cache, mpeg2dec->cache_id,
|
gst_index_add_association (mpeg2dec->index, mpeg2dec->index_id,
|
||||||
(key_frame ? GST_ACCOCIATION_FLAG_KEY_UNIT : 0),
|
(key_frame ? GST_ACCOCIATION_FLAG_KEY_UNIT : 0),
|
||||||
GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buf),
|
GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buf),
|
||||||
GST_FORMAT_TIME, pts, 0);
|
GST_FORMAT_TIME, pts, 0);
|
||||||
|
|
|
@ -84,8 +84,8 @@ struct _GstMpeg2dec {
|
||||||
gint64 total_frames;
|
gint64 total_frames;
|
||||||
gint64 frame_period;
|
gint64 frame_period;
|
||||||
|
|
||||||
GstCache *cache;
|
GstIndex *index;
|
||||||
gint cache_id;
|
gint index_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstMpeg2decClass {
|
struct _GstMpeg2decClass {
|
||||||
|
|
Loading…
Reference in a new issue