2002-11-06 23:53:46 +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.
|
|
|
|
*/
|
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2002-11-26 14:50:05 +00:00
|
|
|
#include "config.h"
|
2003-06-08 13:31:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
2002-11-26 14:50:05 +00:00
|
|
|
#ifdef HAVE_FFMPEG_UNINSTALLED
|
|
|
|
#include <avformat.h>
|
|
|
|
#include <avi.h>
|
|
|
|
#else
|
|
|
|
#include <ffmpeg/avformat.h>
|
|
|
|
#include <ffmpeg/avi.h>
|
|
|
|
#endif
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
#include "gstffmpegcodecmap.h"
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
typedef struct _GstFFMpegDemux GstFFMpegDemux;
|
|
|
|
|
|
|
|
struct _GstFFMpegDemux {
|
|
|
|
GstElement element;
|
|
|
|
|
|
|
|
/* We need to keep track of our pads, so we do so here. */
|
|
|
|
GstPad *sinkpad;
|
|
|
|
|
|
|
|
AVFormatContext *context;
|
2003-06-08 13:31:53 +00:00
|
|
|
gboolean opened;
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
GstPad *srcpads[MAX_STREAMS];
|
2003-06-08 13:31:53 +00:00
|
|
|
gint videopads, audiopads;
|
2002-11-06 23:53:46 +00:00
|
|
|
};
|
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
typedef struct _GstFFMpegDemuxClassParams {
|
|
|
|
AVInputFormat *in_plugin;
|
2003-11-02 13:12:14 +00:00
|
|
|
GstCaps *sinkcaps, *videosrccaps, *audiosrccaps;
|
2003-06-08 13:31:53 +00:00
|
|
|
} GstFFMpegDemuxClassParams;
|
|
|
|
|
2002-11-06 23:53:46 +00:00
|
|
|
typedef struct _GstFFMpegDemuxClass GstFFMpegDemuxClass;
|
|
|
|
|
|
|
|
struct _GstFFMpegDemuxClass {
|
|
|
|
GstElementClass parent_class;
|
|
|
|
|
|
|
|
AVInputFormat *in_plugin;
|
2003-06-08 13:31:53 +00:00
|
|
|
GstPadTemplate *sinktempl;
|
|
|
|
GstPadTemplate *videosrctempl;
|
|
|
|
GstPadTemplate *audiosrctempl;
|
2002-11-06 23:53:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_TYPE_FFMPEGDEC \
|
|
|
|
(gst_ffmpegdec_get_type())
|
|
|
|
#define GST_FFMPEGDEC(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FFMPEGDEC,GstFFMpegDemux))
|
|
|
|
#define GST_FFMPEGDEC_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FFMPEGDEC,GstFFMpegDemuxClass))
|
|
|
|
#define GST_IS_FFMPEGDEC(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FFMPEGDEC))
|
|
|
|
#define GST_IS_FFMPEGDEC_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FFMPEGDEC))
|
|
|
|
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2003-10-28 20:52:31 +00:00
|
|
|
static GHashTable *global_plugins;
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
/* A number of functon prototypes are given so we can refer to them later. */
|
|
|
|
static void gst_ffmpegdemux_class_init (GstFFMpegDemuxClass *klass);
|
2003-11-02 13:12:14 +00:00
|
|
|
static void gst_ffmpegdemux_base_init (GstFFMpegDemuxClass *klass);
|
2002-11-06 23:53:46 +00:00
|
|
|
static void gst_ffmpegdemux_init (GstFFMpegDemux *ffmpegdemux);
|
2003-06-08 13:31:53 +00:00
|
|
|
static void gst_ffmpegdemux_dispose (GObject *object);
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
static void gst_ffmpegdemux_loop (GstElement *element);
|
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_ffmpegdemux_change_state (GstElement *element);
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
/*static guint gst_ffmpegdemux_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
2003-11-02 13:12:14 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegdemux_base_init (GstFFMpegDemuxClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
GstFFMpegDemuxClassParams *params;
|
2004-02-11 08:38:26 +00:00
|
|
|
GstElementDetails details;
|
2003-11-02 13:12:14 +00:00
|
|
|
GstPadTemplate *sinktempl, *audiosrctempl, *videosrctempl;
|
|
|
|
|
|
|
|
params = g_hash_table_lookup (global_plugins,
|
|
|
|
GINT_TO_POINTER (G_OBJECT_CLASS_TYPE (gobject_class)));
|
2003-11-02 19:07:41 +00:00
|
|
|
if (!params)
|
|
|
|
params = g_hash_table_lookup (global_plugins,
|
|
|
|
GINT_TO_POINTER (0));
|
|
|
|
g_assert (params);
|
2003-11-02 13:12:14 +00:00
|
|
|
|
|
|
|
/* construct the element details struct */
|
2004-02-11 08:38:26 +00:00
|
|
|
details.longname = g_strdup_printf("FFMPEG %s demuxer",
|
2003-11-02 13:12:14 +00:00
|
|
|
params->in_plugin->name);
|
2004-02-11 08:38:26 +00:00
|
|
|
details.klass = g_strdup("Codec/Demuxer");
|
|
|
|
details.description = g_strdup_printf("FFMPEG %s decoder",
|
2003-11-02 13:12:14 +00:00
|
|
|
params->in_plugin->name);
|
2004-02-11 08:38:26 +00:00
|
|
|
details.author = "Wim Taymans <wim.taymans@chello.be>, "
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>";
|
|
|
|
gst_element_class_set_details (element_class, &details);
|
|
|
|
g_free (details.longname);
|
|
|
|
g_free (details.klass);
|
|
|
|
g_free (details.description);
|
2003-11-02 13:12:14 +00:00
|
|
|
|
|
|
|
/* pad templates */
|
|
|
|
sinktempl = gst_pad_template_new ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2003-12-22 01:46:58 +00:00
|
|
|
params->sinkcaps);
|
2003-11-02 13:12:14 +00:00
|
|
|
videosrctempl = gst_pad_template_new ("video_%02d",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
2003-12-22 01:46:58 +00:00
|
|
|
params->videosrccaps);
|
2003-11-02 13:12:14 +00:00
|
|
|
audiosrctempl = gst_pad_template_new ("audio_%02d",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
2003-12-22 01:46:58 +00:00
|
|
|
params->audiosrccaps);
|
2003-11-02 13:12:14 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class, videosrctempl);
|
|
|
|
gst_element_class_add_pad_template (element_class, audiosrctempl);
|
|
|
|
gst_element_class_add_pad_template (element_class, sinktempl);
|
|
|
|
|
|
|
|
klass->in_plugin = params->in_plugin;
|
|
|
|
klass->videosrctempl = videosrctempl;
|
|
|
|
klass->audiosrctempl = audiosrctempl;
|
|
|
|
klass->sinktempl = sinktempl;
|
|
|
|
}
|
|
|
|
|
2002-11-06 23:53:46 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegdemux_class_init (GstFFMpegDemuxClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
gstelement_class->change_state = gst_ffmpegdemux_change_state;
|
|
|
|
gobject_class->dispose = gst_ffmpegdemux_dispose;
|
2002-11-06 23:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ffmpegdemux_init(GstFFMpegDemux *ffmpegdemux)
|
|
|
|
{
|
2003-06-08 13:31:53 +00:00
|
|
|
GstFFMpegDemuxClass *oclass = (GstFFMpegDemuxClass*)(G_OBJECT_GET_CLASS (ffmpegdemux));
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
ffmpegdemux->sinkpad = gst_pad_new_from_template (oclass->sinktempl,
|
|
|
|
"sink");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (ffmpegdemux),
|
|
|
|
ffmpegdemux->sinkpad);
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (ffmpegdemux),
|
|
|
|
gst_ffmpegdemux_loop);
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
ffmpegdemux->opened = FALSE;
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
ffmpegdemux->videopads = 0;
|
|
|
|
ffmpegdemux->audiopads = 0;
|
2002-11-06 23:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-08 13:31:53 +00:00
|
|
|
gst_ffmpegdemux_dispose (GObject *object)
|
2002-11-06 23:53:46 +00:00
|
|
|
{
|
2003-06-08 13:31:53 +00:00
|
|
|
GstFFMpegDemux *ffmpegdemux = (GstFFMpegDemux *) object;
|
|
|
|
|
|
|
|
if (ffmpegdemux->opened) {
|
|
|
|
av_close_input_file (ffmpegdemux->context);
|
|
|
|
ffmpegdemux->opened = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-28 20:52:31 +00:00
|
|
|
#define GST_FFMPEG_TYPE_FIND_SIZE 4096
|
|
|
|
static void
|
|
|
|
gst_ffmpegdemux_type_find (GstTypeFind *tf, gpointer priv)
|
2003-06-08 13:31:53 +00:00
|
|
|
{
|
2003-10-28 20:52:31 +00:00
|
|
|
guint8 *data;
|
|
|
|
GstFFMpegDemuxClassParams *params = (GstFFMpegDemuxClassParams *) priv;
|
|
|
|
AVInputFormat *in_plugin = params->in_plugin;
|
2002-11-06 23:53:46 +00:00
|
|
|
gint res = 0;
|
2003-06-08 13:31:53 +00:00
|
|
|
|
2003-10-01 13:14:43 +00:00
|
|
|
if (in_plugin->read_probe &&
|
2003-10-28 20:52:31 +00:00
|
|
|
(data = gst_type_find_peek (tf, 0, GST_FFMPEG_TYPE_FIND_SIZE)) != NULL) {
|
2003-06-08 13:31:53 +00:00
|
|
|
AVProbeData probe_data;
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
probe_data.filename = "";
|
2003-10-28 20:52:31 +00:00
|
|
|
probe_data.buf = data;
|
|
|
|
probe_data.buf_size = GST_FFMPEG_TYPE_FIND_SIZE;
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
res = in_plugin->read_probe (&probe_data);
|
2003-10-28 20:52:31 +00:00
|
|
|
res = res * GST_TYPE_FIND_MAXIMUM / AVPROBE_SCORE_MAX;
|
2003-12-22 01:46:58 +00:00
|
|
|
if (res > 0)
|
|
|
|
gst_type_find_suggest (tf, res, params->sinkcaps);
|
2003-06-08 13:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegdemux_loop (GstElement *element)
|
|
|
|
{
|
|
|
|
GstFFMpegDemux *ffmpegdemux = (GstFFMpegDemux *)(element);
|
|
|
|
GstFFMpegDemuxClass *oclass = (GstFFMpegDemuxClass*)(G_OBJECT_GET_CLASS (ffmpegdemux));
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
gint res;
|
|
|
|
AVPacket pkt;
|
|
|
|
AVFormatContext *ct;
|
|
|
|
AVStream *st;
|
|
|
|
GstPad *pad;
|
|
|
|
|
|
|
|
/* open file if we didn't so already */
|
|
|
|
if (!ffmpegdemux->opened) {
|
|
|
|
res = av_open_input_file (&ffmpegdemux->context,
|
2003-06-08 14:35:32 +00:00
|
|
|
g_strdup_printf ("gstreamer://%p",
|
2003-06-08 13:31:53 +00:00
|
|
|
ffmpegdemux->sinkpad),
|
|
|
|
oclass->in_plugin, 0, NULL);
|
|
|
|
if (res < 0) {
|
2004-02-02 17:23:27 +00:00
|
|
|
GST_ELEMENT_ERROR (ffmpegdemux, LIBRARY, TOO_LAZY, (NULL),
|
2004-01-18 21:46:52 +00:00
|
|
|
("Failed to open demuxer/file context"));
|
2003-06-08 13:31:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-11-25 21:37:26 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
ffmpegdemux->opened = TRUE;
|
|
|
|
}
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
/* shortcut to context */
|
|
|
|
ct = ffmpegdemux->context;
|
|
|
|
|
|
|
|
/* read a package */
|
|
|
|
res = av_read_packet (ct, &pkt);
|
|
|
|
if (res < 0) {
|
|
|
|
if (url_feof (&ct->pb)) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* we're at the end of file - send an EOS to
|
|
|
|
* each stream that we opened so far */
|
|
|
|
for (i = 0; i < ct->nb_streams; i++) {
|
|
|
|
GstPad *pad;
|
|
|
|
GstEvent *event = gst_event_new (GST_EVENT_EOS);
|
|
|
|
|
|
|
|
pad = ffmpegdemux->srcpads[i];
|
|
|
|
if (GST_PAD_IS_USABLE (pad)) {
|
|
|
|
gst_data_ref (GST_DATA (event));
|
2003-10-08 16:07:38 +00:00
|
|
|
gst_pad_push (pad, GST_DATA (event));
|
2003-06-08 13:31:53 +00:00
|
|
|
}
|
|
|
|
gst_data_unref (GST_DATA (event));
|
2002-11-06 23:53:46 +00:00
|
|
|
}
|
|
|
|
gst_element_set_eos (element);
|
2003-06-08 13:31:53 +00:00
|
|
|
|
|
|
|
/* FIXME: should we go into
|
|
|
|
* should we close the context here?
|
|
|
|
* either way, a new media stream needs an
|
|
|
|
* event too */
|
|
|
|
}
|
|
|
|
return;
|
2002-11-06 23:53:46 +00:00
|
|
|
}
|
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
/* shortcut to stream */
|
|
|
|
st = ct->streams[pkt.stream_index];
|
|
|
|
|
|
|
|
/* create the pad/stream if we didn't do so already */
|
|
|
|
if (st->codec_info_state == 0) {
|
|
|
|
GstPadTemplate *templ = NULL;
|
|
|
|
GstCaps *caps;
|
|
|
|
gchar *padname;
|
|
|
|
gint num;
|
|
|
|
|
|
|
|
/* mark as handled */
|
|
|
|
st->codec_info_state = 1;
|
|
|
|
|
|
|
|
/* find template */
|
|
|
|
switch (st->codec.codec_type) {
|
|
|
|
case CODEC_TYPE_VIDEO:
|
|
|
|
templ = oclass->videosrctempl;
|
|
|
|
num = ffmpegdemux->videopads++;
|
|
|
|
break;
|
|
|
|
case CODEC_TYPE_AUDIO:
|
|
|
|
templ = oclass->audiosrctempl;
|
|
|
|
num = ffmpegdemux->audiopads++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("Unknown pad type %d",
|
|
|
|
st->codec.codec_type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create new pad for this stream */
|
|
|
|
padname = g_strdup_printf (GST_PAD_TEMPLATE_NAME_TEMPLATE(templ),
|
|
|
|
num);
|
|
|
|
pad = gst_pad_new_from_template (templ, padname);
|
|
|
|
g_free (padname);
|
|
|
|
|
2004-01-02 07:09:20 +00:00
|
|
|
gst_pad_use_explicit_caps (pad);
|
2003-06-08 13:31:53 +00:00
|
|
|
/* FIXME: convert() and query() functions for pad */
|
|
|
|
|
|
|
|
/* store pad internally */
|
|
|
|
ffmpegdemux->srcpads[pkt.stream_index] = pad;
|
|
|
|
|
|
|
|
/* get caps that belongs to this stream */
|
|
|
|
caps = gst_ffmpeg_codecid_to_caps (st->codec.codec_id,
|
|
|
|
&st->codec);
|
2004-01-02 07:09:20 +00:00
|
|
|
gst_pad_set_explicit_caps (pad, caps);
|
2004-02-04 21:40:49 +00:00
|
|
|
|
|
|
|
gst_element_add_pad (GST_ELEMENT (ffmpegdemux), pad);
|
|
|
|
|
2004-01-02 07:09:20 +00:00
|
|
|
/* we continue here, in the next pad-is-usable check,
|
|
|
|
* we'll return nonetheless */
|
2003-06-08 13:31:53 +00:00
|
|
|
}
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
/* shortcut to pad belonging to this stream */
|
|
|
|
pad = ffmpegdemux->srcpads[pkt.stream_index];
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
/* and handle the data by pushing it forward... */
|
|
|
|
if (GST_PAD_IS_USABLE (pad)) {
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
|
|
|
outbuf = gst_buffer_new_and_alloc (pkt.size);
|
|
|
|
memcpy (GST_BUFFER_DATA (outbuf), pkt.data, pkt.size);
|
|
|
|
GST_BUFFER_SIZE (outbuf) = pkt.size;
|
|
|
|
|
|
|
|
if (pkt.pts != AV_NOPTS_VALUE && ct->pts_den) {
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = pkt.pts * GST_SECOND *
|
|
|
|
ct->pts_num / ct->pts_den;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pkt.flags & PKT_FLAG_KEY) {
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT);
|
|
|
|
}
|
|
|
|
|
2003-10-08 16:07:38 +00:00
|
|
|
gst_pad_push (pad, GST_DATA (outbuf));
|
2003-06-08 13:31:53 +00:00
|
|
|
pkt.destruct (&pkt);
|
2002-11-06 23:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_ffmpegdemux_change_state (GstElement *element)
|
2002-11-06 23:53:46 +00:00
|
|
|
{
|
2003-06-08 13:31:53 +00:00
|
|
|
GstFFMpegDemux *ffmpegdemux = (GstFFMpegDemux *)(element);
|
|
|
|
gint transition = GST_STATE_TRANSITION (element);
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
if (ffmpegdemux->opened) {
|
|
|
|
av_close_input_file (ffmpegdemux->context);
|
|
|
|
ffmpegdemux->opened = FALSE;
|
|
|
|
}
|
2002-11-06 23:53:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-06-08 13:31:53 +00:00
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
2002-11-06 23:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_ffmpegdemux_register (GstPlugin *plugin)
|
|
|
|
{
|
2003-12-22 01:46:58 +00:00
|
|
|
GType type;
|
|
|
|
AVInputFormat *in_plugin;
|
|
|
|
GstFFMpegDemuxClassParams *params;
|
|
|
|
AVCodec *in_codec;
|
|
|
|
gchar **extensions;
|
2002-11-06 23:53:46 +00:00
|
|
|
GTypeInfo typeinfo = {
|
|
|
|
sizeof(GstFFMpegDemuxClass),
|
2003-11-02 13:12:14 +00:00
|
|
|
(GBaseInitFunc)gst_ffmpegdemux_base_init,
|
2002-11-06 23:53:46 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_ffmpegdemux_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstFFMpegDemux),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_ffmpegdemux_init,
|
|
|
|
};
|
2003-12-22 01:46:58 +00:00
|
|
|
GstCaps *any_caps = gst_caps_new_any ();
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
in_plugin = first_iformat;
|
|
|
|
|
|
|
|
global_plugins = g_hash_table_new (NULL, NULL);
|
|
|
|
|
|
|
|
while (in_plugin) {
|
2003-11-02 13:12:14 +00:00
|
|
|
gchar *type_name, *typefind_name;
|
2002-11-06 23:53:46 +00:00
|
|
|
gchar *p;
|
2003-06-08 13:31:53 +00:00
|
|
|
GstCaps *sinkcaps, *audiosrccaps, *videosrccaps;
|
|
|
|
|
|
|
|
/* Try to find the caps that belongs here */
|
|
|
|
sinkcaps = gst_ffmpeg_formatid_to_caps (in_plugin->name);
|
|
|
|
if (!sinkcaps) {
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
/* This is a bit ugly, but we just take all formats
|
|
|
|
* for the pad template. We'll get an exact match
|
|
|
|
* when we open the stream */
|
|
|
|
audiosrccaps = NULL;
|
|
|
|
videosrccaps = NULL;
|
|
|
|
for (in_codec = first_avcodec; in_codec != NULL;
|
|
|
|
in_codec = in_codec->next) {
|
|
|
|
GstCaps *temp = gst_ffmpeg_codecid_to_caps (in_codec->id, NULL);
|
|
|
|
if (!temp) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (in_codec->type) {
|
|
|
|
case CODEC_TYPE_VIDEO:
|
2003-12-22 01:46:58 +00:00
|
|
|
gst_caps_append (videosrccaps, temp);
|
2003-06-08 13:31:53 +00:00
|
|
|
break;
|
|
|
|
case CODEC_TYPE_AUDIO:
|
2003-12-22 01:46:58 +00:00
|
|
|
gst_caps_append (audiosrccaps, temp);
|
2003-06-08 13:31:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-12-22 01:46:58 +00:00
|
|
|
gst_caps_free (temp);
|
2003-06-08 13:31:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
/* construct the type */
|
|
|
|
type_name = g_strdup_printf("ffdemux_%s", in_plugin->name);
|
2003-11-02 13:12:14 +00:00
|
|
|
typefind_name = g_strdup_printf("fftype_%s", in_plugin->name);
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
p = type_name;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
if (*p == '.') *p = '_';
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if it's already registered, drop it */
|
|
|
|
if (g_type_from_name(type_name)) {
|
|
|
|
g_free(type_name);
|
|
|
|
goto next;
|
|
|
|
}
|
2003-11-02 19:07:41 +00:00
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
/* create a cache for these properties */
|
|
|
|
params = g_new0 (GstFFMpegDemuxClassParams, 1);
|
|
|
|
params->in_plugin = in_plugin;
|
2003-11-02 13:12:14 +00:00
|
|
|
params->sinkcaps = sinkcaps;
|
|
|
|
params->videosrccaps = videosrccaps;
|
|
|
|
params->audiosrccaps = audiosrccaps;
|
2003-10-28 20:52:31 +00:00
|
|
|
|
2003-11-02 19:07:41 +00:00
|
|
|
g_hash_table_insert (global_plugins,
|
|
|
|
GINT_TO_POINTER (0),
|
|
|
|
(gpointer) params);
|
|
|
|
|
|
|
|
/* create the type now */
|
|
|
|
type = g_type_register_static(GST_TYPE_ELEMENT, type_name , &typeinfo, 0);
|
|
|
|
|
2003-06-08 13:31:53 +00:00
|
|
|
g_hash_table_insert (global_plugins,
|
|
|
|
GINT_TO_POINTER (type),
|
|
|
|
(gpointer) params);
|
2002-11-06 23:53:46 +00:00
|
|
|
|
2003-11-02 13:12:14 +00:00
|
|
|
extensions = g_strsplit (in_plugin->extensions, " ", 0);
|
|
|
|
if (!gst_element_register (plugin, type_name, GST_RANK_MARGINAL, type) ||
|
|
|
|
!gst_type_find_register (plugin, typefind_name, GST_RANK_MARGINAL,
|
|
|
|
gst_ffmpegdemux_type_find,
|
2003-12-22 01:46:58 +00:00
|
|
|
extensions, any_caps, params))
|
2003-11-02 13:12:14 +00:00
|
|
|
return FALSE;
|
|
|
|
g_strfreev (extensions);
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
next:
|
|
|
|
in_plugin = in_plugin->next;
|
|
|
|
}
|
2003-12-22 01:46:58 +00:00
|
|
|
gst_caps_free (any_caps);
|
2003-11-02 19:07:41 +00:00
|
|
|
g_hash_table_remove (global_plugins, GINT_TO_POINTER (0));
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|