We are currently experiencing downtime impacting viewing & cloning the Mesa repo, and some GitLab pages returning 503. Please see #freedesktop on IRC for more updates.

Commit 7b63c14e authored by Ronald S. Bultje's avatar Ronald S. Bultje

HACKING: Add some basic documentation on how our wrapping works.

Original commit message from CVS:
* HACKING:
Add some basic documentation on how our wrapping works.
* TODO:
Add a list of things that could be worked on or that need doing.
* configure.ac:
Update snapshot.
* ext/ffmpeg/Makefile.am:
Changne .la links. See below (autotools patch).
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
Enable demuxers. See below (gstffmpegdemux.c).
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_formatid_to_caps):
Realmedia caused a crash - fix that.
* ext/ffmpeg/gstffmpegdemux.c: (gst_ffmpegdemux_averror),
(gst_ffmpegdemux_base_init), (gst_ffmpegdemux_init),
(gst_ffmpegdemux_close), (gst_ffmpegdemux_dispose),
(gst_ffmpegdemux_stream_from_pad),
(gst_ffmpegdemux_src_event_mask), (gst_ffmpegdemux_src_event),
(gst_ffmpegdemux_src_format_list),
(gst_ffmpegdemux_src_query_list), (gst_ffmpegdemux_src_query),
(gst_ffmpegdemux_src_convert), (gst_ffmpegdemux_add),
(gst_ffmpegdemux_open), (gst_ffmpegdemux_loop),
(gst_ffmpegdemux_change_state), (gst_ffmpegdemux_register):
Right. OK, so I fixed up the demuxing and have it basically-working,
and the best way to get some more people to test it is to actually
enable it. I'm not sure if we want this for 0.8.0, but we can at
least give it a try. I've tested avi, matroska and mpeg, all appear
to work. The cool thing is that this gives us instant support for
several exotic formats that we'd never care about ourselves. Again,
this needs more testing for it to still be enabled in 0.8.0, but I
want to give it a try...
* ext/ffmpeg/gstffmpegmux.c: (gst_ffmpegmux_base_init),
(gst_ffmpegmux_init), (gst_ffmpegmux_request_new_pad),
(gst_ffmpegmux_connect), (gst_ffmpegmux_loop),
(gst_ffmpegmux_register):
Add some fixups that I use locally. Make it work in the case of
MPEG encoding, but the muxer is still not in shape to be enabled.
* ext/ffmpeg/gstffmpegprotocol.c: (gst_ffmpegdata_open),
(gst_ffmpegdata_read), (gst_ffmpegdata_write),
(gst_ffmpegdata_seek), (gst_ffmpegdata_close):
Some small fixups that crept into it while it was disabled for the
last few years. Basically works.
* gst-libs/ext/ffmpeg/Makefile.am:
Instead of having our local-autotoolized version, I patch the ffmpeg
source to be fully autotoolized. That means a simple SUBDIRS here
is now enough.
* gst-libs/ext/ffmpeg/Tag:
Version update.
* gst-libs/ext/ffmpeg/patch/autotools.diff:
Autotoolize ffmpeg. Needs to be sent to ffmpeg-devel@...
* gst-libs/ext/ffmpeg/patch/disableinstalllibs.diff:
Don't install their libs.
* gst-libs/ext/ffmpeg/patch/disablemmx.diff:
Don't use MMX. It cannot ocmpile using PIC.
* gst-libs/ext/ffmpeg/patch/disabletools.diff:
Don't compile/install their tools, we don't use them.
* gst-libs/ext/ffmpeg/patch/functions.diff:
Prevent symbol conflicts.
* gst-libs/ext/ffmpeg/patch/matroska.diff:
Add a matroska demuxer. Needs to be sent to ffmpeg-devel@...
parent db029240
=== gst-ffmpeg ===
2004-02-29 Ronald Bultje <rbultje@ronald.bitfreak.net>
* HACKING:
Add some basic documentation on how our wrapping works.
* TODO:
Add a list of things that could be worked on or that need doing.
* configure.ac:
Update snapshot.
* ext/ffmpeg/Makefile.am:
Changne .la links. See below (autotools patch).
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
Enable demuxers. See below (gstffmpegdemux.c).
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_formatid_to_caps):
Realmedia caused a crash - fix that.
* ext/ffmpeg/gstffmpegdemux.c: (gst_ffmpegdemux_averror),
(gst_ffmpegdemux_base_init), (gst_ffmpegdemux_init),
(gst_ffmpegdemux_close), (gst_ffmpegdemux_dispose),
(gst_ffmpegdemux_stream_from_pad),
(gst_ffmpegdemux_src_event_mask), (gst_ffmpegdemux_src_event),
(gst_ffmpegdemux_src_format_list),
(gst_ffmpegdemux_src_query_list), (gst_ffmpegdemux_src_query),
(gst_ffmpegdemux_src_convert), (gst_ffmpegdemux_add),
(gst_ffmpegdemux_open), (gst_ffmpegdemux_loop),
(gst_ffmpegdemux_change_state), (gst_ffmpegdemux_register):
Right. OK, so I fixed up the demuxing and have it basically-working,
and the best way to get some more people to test it is to actually
enable it. I'm not sure if we want this for 0.8.0, but we can at
least give it a try. I've tested avi, matroska and mpeg, all appear
to work. The cool thing is that this gives us instant support for
several exotic formats that we'd never care about ourselves. Again,
this needs more testing for it to still be enabled in 0.8.0, but I
want to give it a try...
* ext/ffmpeg/gstffmpegmux.c: (gst_ffmpegmux_base_init),
(gst_ffmpegmux_init), (gst_ffmpegmux_request_new_pad),
(gst_ffmpegmux_connect), (gst_ffmpegmux_loop),
(gst_ffmpegmux_register):
Add some fixups that I use locally. Make it work in the case of
MPEG encoding, but the muxer is still not in shape to be enabled.
* ext/ffmpeg/gstffmpegprotocol.c: (gst_ffmpegdata_open),
(gst_ffmpegdata_read), (gst_ffmpegdata_write),
(gst_ffmpegdata_seek), (gst_ffmpegdata_close):
Some small fixups that crept into it while it was disabled for the
last few years. Basically works.
* gst-libs/ext/ffmpeg/Makefile.am:
Instead of having our local-autotoolized version, I patch the ffmpeg
source to be fully autotoolized. That means a simple SUBDIRS here
is now enough.
* gst-libs/ext/ffmpeg/Tag:
Version update.
* gst-libs/ext/ffmpeg/patch/autotools.diff:
Autotoolize ffmpeg. Needs to be sent to ffmpeg-devel@...
* gst-libs/ext/ffmpeg/patch/disableinstalllibs.diff:
Don't install their libs.
* gst-libs/ext/ffmpeg/patch/disablemmx.diff:
Don't use MMX. It cannot ocmpile using PIC.
* gst-libs/ext/ffmpeg/patch/disabletools.diff:
Don't compile/install their tools, we don't use them.
* gst-libs/ext/ffmpeg/patch/functions.diff:
Prevent symbol conflicts.
* gst-libs/ext/ffmpeg/patch/matroska.diff:
Add a matroska demuxer. Needs to be sent to ffmpeg-devel@...
2004-02-26 Thomas Vander Stichele <thomas at apestaart dot org>
......
......@@ -34,3 +34,65 @@ Axioms under which we work:
- it would be very nice if, on update of either the Tag file or the patch set,
make would know exactly what to do with it.
Some notes on how ffmpeg wrapping inside GStreamer currently works:
* gstffmpeg{dec,enc,demux,mux}.c are wrappers for specific element types from
their ffmpeg counterpart. If you want to wrap a new type of element in
ffmpeg (e.g. the URLProtocol things), then you'd need to write a new
wrapper file.
* gstffmpegcolorspace.c is a wrapper for one specific function in ffmpeg:
colorspace conversion. This works different from the previously mentioned
ones, and we'll come to that in the next item. If you want to wrap one
specific function, then that, too, belongs in a new wrapper file.
* the important difference between all those is that the colorspace element
contains one element, so there is a 1<->1 mapping. This makes for a fairly
basic element implementation. gstffmpegcolorspace.c, therefore, doesn't
differ much from other colorspace elements. The ffmpeg element types,
however, define a whole *list* of elements (in GStreamer, each decoder etc.
needs to be its own element). We use a set of tricks for that to keep
coding simple: codec mapping and dynamic type creation.
* ffmpeg uses CODEC_ID_* enumerations for their codecs. GStreamer uses caps,
which consists of a mimetype and a defined set of properties. In ffmpeg,
these properties live in a AVCodecContext struct, which contains anything
that could configure any codec (which makes it rather messy, but ohwell).
To convert from one to the other, we use codec mapping, which is done in
gstffmpegcodecmap.[ch]. This is the most important file in the whole
ffmpeg wrapping process! It contains functions to go from a codec type
(video or audio - used as the output format for decoding or the input
format for encoding), a codec id (to identify each format) or a format id
(a string identifying a file format - usually the file format extension)
to a GstCaps, and the other way around.
* to define multiple elements in one source file (which all behave similarly),
we dynamically create types for each plugin and let all of them operate on
the same struct (GstFFMpegDec, GstFFMpegEnc, ...). The functions in
gstffmpeg{dec,enc,demux,mux}.c called gst_ffmpeg*_register() do this.
The magic is as follows: for each codec or format, ffmpeg has a single
AVCodec or AV{Input,Output}Format, which are packed together in a list of
supported codecs/formats. We simply walk through the list, for each of
those, we check whether gstffmpegcodecmap.c knows about this single one.
If it does, we get the GstCaps for each pad template that belongs to it,
and register a type for all of those together. We also leave this inside
a caching struct, that will later be used by the base_init() function to
fill in information about this specific codec in the class struct of this
element (pad templates and codec/format information). Since the actual
codec information is the only thing that really makes each codec/format
different (they all behave the same through the ffmpeg API), we don't
really need to do anything else that is codec-specific, so all other
functions are rather simple.
* one particular thing that needs mention is how gstffmpeg{mux,demux}.c and
gstffmpegprotocol.c interoperate. ffmpeg uses URLProtocols for data input
and output. Now, of course, we want to use the *GStreamer* way of doing
input and output (filesrc, ...) rather than the ffmpeg way. Therefore, we
wrap up a GstPad as a URLProtocol and register this with ffmpeg. This is
what gstffmpegprotocol.c does. The URL is called gstreamer://%p, where %p
is the address of a GstPad. gstffmpeg{mux,demux}.c then open a file called
gstreamer://%p, with %p being their source/sink pad, respectively. This
way, we use GStreamer for data input/output through the ffmpeg API. It's
rather ugly, but it has worked quite well so far.
* there's lots of things that still need doing. See the TODO file for more
information.
The never-ending story of new features:
* add more codecs into our codec map
* encoding/decoding support lacks:
- event handling (particularly discont/flush and EOS)
- prevent data copying
* demux/mux support lacks:
- good testing of exotic formats
- correct caps sets on the pad templates
- event handling in the loop function (mux)
- prevent data copying
* some sort of codectype-fallback, so that we still register a codec plus its
mimetype even if we don't have a defined gst-type for it
* ffvideoscale && other filter elements
* can we wrap URLProtocol as a source/sink?
* propagate options like --disable-ffplay (and server and ffmpeg) to ffmpeg
source tree build directly in AC_CONFIG_SUBDIRS instead of the
'disabletools.diff' patch
If you have cool ideas, add them here or contact the mailinglist:
<gstreamer-devel@lists.sf.net>
......@@ -83,7 +83,7 @@ GST_CHECK_FEATURE(FFMPEG, [ffmpeg plug-ins], ffmpeg, [
# prerelease and release should get it disted
if test "x$GST_PLUGINS_VERSION_NANO" = x1; then
AC_MSG_NOTICE(slurping FFmpeg CVS source)
AS_SLURP_FFMPEG(gst-libs/ext/ffmpeg, 2003-10-26 10:00 GMT,
AS_SLURP_FFMPEG(gst-libs/ext/ffmpeg, 2004-02-29 20:00 GMT,
HAVE_FFMPEG=yes, HAVE_FFMPEG=no)
else
AC_MSG_NOTICE(FFmpeg CVS code should be included already)
......@@ -100,7 +100,7 @@ GST_ARCH()
dnl ###########################
dnl # Configure external libs #
dnl ###########################
if test "x$HAVE_FFMPEG" = xyes; then
if test "x$HAVE_FFMPEG" = "xyes"; then
AC_CONFIG_SUBDIRS(gst-libs/ext/ffmpeg/ffmpeg)
fi
......
......@@ -14,8 +14,8 @@ libgstffmpeg_la_CFLAGS = $(GST_CFLAGS) \
-I $(top_srcdir)/gst-libs/ext/ffmpeg/ffmpeg/libavcodec \
-I $(top_srcdir)/gst-libs/ext/ffmpeg/ffmpeg/libavformat
libgstffmpeg_la_LIBADD = \
$(top_builddir)/gst-libs/ext/ffmpeg/libavcodec.la \
$(top_builddir)/gst-libs/ext/ffmpeg/libavformat.la
$(top_builddir)/gst-libs/ext/ffmpeg/ffmpeg/libavcodec/libavcodec.la \
$(top_builddir)/gst-libs/ext/ffmpeg/ffmpeg/libavformat/libavformat.la
libgstffmpeg_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
......
......@@ -53,11 +53,11 @@ plugin_init (GstPlugin *plugin)
gst_ffmpegenc_register (plugin);
gst_ffmpegdec_register (plugin);
/*gst_ffmpegdemux_register (plugin);*/
gst_ffmpegdemux_register (plugin);
/*gst_ffmpegmux_register (plugin);*/
gst_ffmpegcsp_register (plugin);
/*register_protocol (&gstreamer_protocol);*/
register_protocol (&gstreamer_protocol);
/* Now we can return the pointer to the newly created Plugin object. */
return TRUE;
......
......@@ -890,7 +890,7 @@ gst_ffmpeg_formatid_to_caps (const gchar *format_name)
"systemstream", G_TYPE_BOOLEAN, TRUE,
NULL);
} else if (!strcmp (format_name, "rm")) {
caps = gst_caps_new_simple ("ffmpeg_rm", "audio/x-pn-realvideo",
caps = gst_caps_new_simple ("application/x-pn-realmedia",
"systemstream", G_TYPE_BOOLEAN, TRUE,
NULL);
} else if (!strcmp (format_name, "asf")) {
......@@ -919,7 +919,12 @@ gst_ffmpeg_formatid_to_caps (const gchar *format_name)
caps = gst_caps_new_simple ("video/x-4xm",
NULL);
} else {
/* unknown! */
gchar *name;
GST_WARNING ("Could not create stream format caps for %s", format_name);
name = g_strdup_printf ("application/x-gst_ff-%s", format_name);
caps = gst_caps_new_simple (name, NULL);
g_free (name);
}
return caps;
......
......@@ -46,6 +46,8 @@ struct _GstFFMpegDemux {
gboolean opened;
GstPad *srcpads[MAX_STREAMS];
gboolean handled[MAX_STREAMS];
guint64 last_ts[MAX_STREAMS];
gint videopads, audiopads;
};
......@@ -91,8 +93,8 @@ static GHashTable *global_plugins;
/* A number of functon prototypes are given so we can refer to them later. */
static void gst_ffmpegdemux_class_init (GstFFMpegDemuxClass *klass);
static void gst_ffmpegdemux_base_init (GstFFMpegDemuxClass *klass);
static void gst_ffmpegdemux_init (GstFFMpegDemux *ffmpegdemux);
static void gst_ffmpegdemux_dispose (GObject *object);
static void gst_ffmpegdemux_init (GstFFMpegDemux *demux);
static void gst_ffmpegdemux_dispose (GObject *object);
static void gst_ffmpegdemux_loop (GstElement *element);
......@@ -103,6 +105,39 @@ static GstElementClass *parent_class = NULL;
/*static guint gst_ffmpegdemux_signals[LAST_SIGNAL] = { 0 }; */
static const gchar *
gst_ffmpegdemux_averror (gint av_errno)
{
const gchar *message = NULL;
switch (av_errno) {
default:
case AVERROR_UNKNOWN:
message = "Unknown error";
break;
case AVERROR_IO:
message = "Input/output error";
break;
case AVERROR_NUMEXPECTED:
message = "Number syntax expected in filename";
break;
case AVERROR_INVALIDDATA:
message = "Invalid data found";
break;
case AVERROR_NOMEM:
message = "Not enough memory";
break;
case AVERROR_NOFMT:
message = "Unknown format";
break;
case AVERROR_NOTSUPP:
message = "Operation not supported";
break;
}
return message;
}
static void
gst_ffmpegdemux_base_init (GstFFMpegDemuxClass *klass)
{
......@@ -121,15 +156,14 @@ gst_ffmpegdemux_base_init (GstFFMpegDemuxClass *klass)
/* construct the element details struct */
details.longname = g_strdup_printf("FFMPEG %s demuxer",
params->in_plugin->name);
details.klass = g_strdup("Codec/Demuxer");
params->in_plugin->long_name);
details.klass = "Codec/Demuxer";
details.description = g_strdup_printf("FFMPEG %s decoder",
params->in_plugin->name);
params->in_plugin->long_name);
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);
/* pad templates */
......@@ -172,32 +206,338 @@ gst_ffmpegdemux_class_init (GstFFMpegDemuxClass *klass)
}
static void
gst_ffmpegdemux_init(GstFFMpegDemux *ffmpegdemux)
gst_ffmpegdemux_init (GstFFMpegDemux *demux)
{
GstFFMpegDemuxClass *oclass = (GstFFMpegDemuxClass*)(G_OBJECT_GET_CLASS (ffmpegdemux));
GstFFMpegDemuxClass *oclass = (GstFFMpegDemuxClass *) (G_OBJECT_GET_CLASS (demux));
ffmpegdemux->sinkpad = gst_pad_new_from_template (oclass->sinktempl,
demux->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_element_add_pad (GST_ELEMENT (demux), demux->sinkpad);
gst_element_set_loop_function (GST_ELEMENT (demux),
gst_ffmpegdemux_loop);
ffmpegdemux->opened = FALSE;
demux->opened = FALSE;
memset (demux->srcpads, 0, sizeof (demux->srcpads));
memset (demux->handled, FALSE, sizeof (demux->handled));
memset (demux->last_ts, 0, sizeof (demux->last_ts));
demux->videopads = 0;
demux->audiopads = 0;
}
static void
gst_ffmpegdemux_close (GstFFMpegDemux *demux)
{
gint n;
if (!demux->opened)
return;
/* remove pads from ourselves */
for (n = 0; n < MAX_STREAMS; n++) {
if (demux->srcpads[n]) {
gst_element_remove_pad (GST_ELEMENT (demux), demux->srcpads[n]);
demux->srcpads[n] = NULL;
}
demux->handled[n] = FALSE;
demux->last_ts[n] = 0;
}
demux->videopads = 0;
demux->audiopads = 0;
/* close demuxer context from ffmpeg */
av_close_input_file (demux->context);
ffmpegdemux->videopads = 0;
ffmpegdemux->audiopads = 0;
demux->opened = FALSE;
}
static void
gst_ffmpegdemux_dispose (GObject *object)
{
GstFFMpegDemux *ffmpegdemux = (GstFFMpegDemux *) object;
GstFFMpegDemux *demux = (GstFFMpegDemux *) demux;
gst_ffmpegdemux_close (demux);
}
static AVStream *
gst_ffmpegdemux_stream_from_pad (GstPad *pad)
{
GstFFMpegDemux *demux = (GstFFMpegDemux *) gst_pad_get_parent (pad);
AVStream *stream = NULL;
gint n;
for (n = 0; n < MAX_STREAMS; n++) {
if (demux->srcpads[n] == pad) {
stream = demux->context->streams[n];
break;
}
}
return stream;
}
static const GstEventMask *
gst_ffmpegdemux_src_event_mask (GstPad *pad)
{
static const GstEventMask masks[] = {
{ GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_KEY_UNIT },
{ 0, }
};
return masks;
}
static gboolean
gst_ffmpegdemux_src_event (GstPad *pad,
GstEvent *event)
{
GstFFMpegDemux *demux = (GstFFMpegDemux *) gst_pad_get_parent (pad);
AVStream *stream = gst_ffmpegdemux_stream_from_pad (pad);
gboolean res = TRUE;
gint64 offset;
if (!stream)
return;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_SEEK:
offset = GST_EVENT_SEEK_OFFSET (event);
switch (GST_EVENT_SEEK_FORMAT (event)) {
case GST_FORMAT_DEFAULT:
if (stream->codec.codec_type != CODEC_TYPE_VIDEO) {
res = FALSE;
break;
} else {
GstFormat fmt = GST_FORMAT_TIME;
if (!(res = gst_pad_convert (pad, GST_FORMAT_DEFAULT, offset,
&fmt, &offset)))
break;
}
/* fall-through */
case GST_FORMAT_TIME:
if (av_seek_frame (demux->context, stream->index,
offset / (GST_SECOND / AV_TIME_BASE)))
res = FALSE;
break;
default:
res = FALSE;
break;
}
break;
default:
res = FALSE;
break;
}
return res;
}
static const GstFormat *
gst_ffmpegdemux_src_format_list (GstPad *pad)
{
AVStream *stream = gst_ffmpegdemux_stream_from_pad (pad);
static const GstFormat src_v_formats[] = {
GST_FORMAT_TIME,
GST_FORMAT_DEFAULT,
0
}, src_a_formats[] = {
GST_FORMAT_TIME,
0
};
return (stream->codec.codec_type == CODEC_TYPE_VIDEO) ?
src_v_formats : src_a_formats;
}
static const GstQueryType *
gst_ffmpegdemux_src_query_list (GstPad *pad)
{
static const GstQueryType src_types[] = {
GST_QUERY_TOTAL,
GST_QUERY_POSITION,
0
};
return src_types;
}
static gboolean
gst_ffmpegdemux_src_query (GstPad *pad,
GstQueryType type,
GstFormat *fmt,
gint64 *value)
{
GstFFMpegDemux *demux = (GstFFMpegDemux *) gst_pad_get_parent (pad);
AVStream *stream = gst_ffmpegdemux_stream_from_pad (pad);
gboolean res = TRUE;
gint n;
if (!stream || (*fmt == GST_FORMAT_DEFAULT &&
stream->codec.codec_type != CODEC_TYPE_VIDEO))
return FALSE;
switch (type) {
case GST_QUERY_TOTAL:
switch (*fmt) {
case GST_FORMAT_TIME:
*value = stream->duration * (GST_SECOND / AV_TIME_BASE);
break;
case GST_FORMAT_DEFAULT:
if (stream->codec_info_nb_frames) {
*value = stream->codec_info_nb_frames;
break;
} /* else fall-through */
default:
res = FALSE;
break;
}
break;
case GST_QUERY_POSITION:
switch (*fmt) {
case GST_FORMAT_TIME:
*value = demux->last_ts[stream->index];
break;
case GST_FORMAT_DEFAULT:
res = gst_pad_convert (pad, GST_FORMAT_TIME,
demux->last_ts[stream->index],
fmt, value);
break;
default:
res = FALSE;
break;
}
break;
default:
res = FALSE;
break;
}
return res;
}
static gboolean
gst_ffmpegdemux_src_convert (GstPad *pad,
GstFormat src_fmt,
gint64 src_value,
GstFormat *dest_fmt,
gint64 *dest_value)
{
GstFFMpegDemux *demux = (GstFFMpegDemux *) gst_pad_get_parent (pad);
AVStream *stream = gst_ffmpegdemux_stream_from_pad (pad);
gboolean res = TRUE;
if (!stream || stream->codec.codec_type != CODEC_TYPE_VIDEO)
return FALSE;
switch (src_fmt) {
case GST_FORMAT_TIME:
switch (*dest_fmt) {
case GST_FORMAT_DEFAULT:
*dest_value = src_value * stream->r_frame_rate /
(GST_SECOND * stream->r_frame_rate_base);
break;
default:
res = FALSE;
break;
}
break;
case GST_FORMAT_DEFAULT:
switch (*dest_fmt) {
case GST_FORMAT_TIME:
*dest_value = src_value * GST_SECOND * stream->r_frame_rate_base /
stream->r_frame_rate;
break;
default:
res = FALSE;
break;
}
break;
default:
res = FALSE;
break;
}
return res;
}
if (ffmpegdemux->opened) {
av_close_input_file (ffmpegdemux->context);
ffmpegdemux->opened = FALSE;
static gboolean
gst_ffmpegdemux_add (GstFFMpegDemux *demux,
AVStream *stream)
{
GstFFMpegDemuxClass *oclass = (GstFFMpegDemuxClass *) G_OBJECT_GET_CLASS (demux);
GstPadTemplate *templ = NULL;
GstPad *pad;
GstCaps *caps;
gint num;
gchar *padname;
switch (stream->codec.codec_type) {
case CODEC_TYPE_VIDEO:
templ = oclass->videosrctempl;
num = demux->videopads++;
break;
case CODEC_TYPE_AUDIO:
templ = oclass->audiosrctempl;
num = demux->audiopads++;
break;
default:
GST_WARNING ("Unknown pad type %d", stream->codec.codec_type);
break;
}
if (!templ)
return FALSE;
/* 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);
gst_pad_use_explicit_caps (pad);
/* FIXME: srcevent(), convert() and query() functions for pad */
/* store pad internally */
demux->srcpads[stream->index] = pad;
/* get caps that belongs to this stream */
caps = gst_ffmpeg_codecid_to_caps (stream->codec.codec_id, &stream->codec);
gst_pad_set_explicit_caps (pad, caps);
gst_element_add_pad (GST_ELEMENT (demux), pad);
return TRUE;
}
static gboolean
gst_ffmpegdemux_open (GstFFMpegDemux *demux)
{
GstFFMpegDemuxClass *oclass = (GstFFMpegDemuxClass *) G_OBJECT_GET_CLASS (demux);
gchar *location;
gint res;
/* to be sure... */
gst_ffmpegdemux_close (demux);
/* open via our input protocol hack */
location = g_strdup_printf ("gstreamer://%p", demux->sinkpad);
res = av_open_input_file (&demux->context, location,
oclass->in_plugin, 0, NULL);
g_free (location);
if (res < 0) {
GST_ELEMENT_ERROR (demux, LIBRARY, FAILED, (NULL),
(gst_ffmpegdemux_averror (res)));
return FALSE;
}
/* open_input_file() automatically reads the header. We can now map each
* created AVStream to a GstPad to make GStreamer handle it. */
for (res = 0; res < demux->context->nb_streams; res++) {
gst_ffmpegdemux_add (demux, demux->context->streams[res]);
demux->handled[res] = TRUE;
}
demux->opened = TRUE;
return TRUE;
}
#define GST_FFMPEG_TYPE_FIND_SIZE 4096
......@@ -227,151 +567,70 @@ gst_ffmpegdemux_type_find (GstTypeFind *tf, gpointer priv)
static void
gst_ffmpegdemux_loop (GstElement *element)