Commit 4996d4c7 authored by Wim Taymans's avatar Wim Taymans

Release early.. try to wrap more ffmpeg stuff, like muxers and demuxers.

Original commit message from CVS:
Release early.. try to wrap more ffmpeg stuff, like muxers and demuxers.
This thing needs a fix in ffmpeg (which I will send to the ffmpeg authors
eventually)
parent 4af5086d
common @ 1ca7d9a2
Subproject commit 2f6d9cfdaaa83ab454d263d6eba88046debadc2d
Subproject commit 1ca7d9a20180cab830f4383cde5ba932338e50b1
......@@ -2,9 +2,16 @@ plugindir = $(libdir)/gst
plugin_LTLIBRARIES = libgstffmpeg.la
libgstffmpeg_la_SOURCES = gstffmpeg.c gstffmpegenc.c gstffmpegdec.c
libgstffmpeg_la_CFLAGS = $(GST_CFLAGS) -I/opt/src/sourceforge/ffmpeg/
libgstffmpeg_la_SOURCES = gstffmpeg.c \
gstffmpegenc.c \
gstffmpegdec.c \
gstffmpegdemux.c \
gstffmpegmux.c \
gstffmpegprotocol.c \
gstffmpegcodecmap.c
libgstffmpeg_la_CFLAGS = $(GST_CFLAGS) -I/opt/src/sourceforge/ffmpeg/ -I/opt/src/sourceforge/ffmpeg/libavcodec/
libgstffmpeg_la_LIBADD =
libgstffmpeg_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -L/opt/src/sourceforge/ffmpeg/libavcodec -lavcodec -L/opt/src/sourceforge/ffmpeg/libav -lavformat
noinst_HEADERS = gstffmpegenc.h gstffmpegdec.h
noinst_HEADERS =
......@@ -20,17 +20,29 @@
/* First, include the header file for the plugin, to bring in the
* object definition and other useful things.
*/
#include "gstffmpegdec.h"
#include "gstffmpegenc.h"
#include <libavcodec/avcodec.h>
#include <libav/avformat.h>
#include <gst/gst.h>
extern gboolean gst_ffmpegdemux_register (GstPlugin *plugin);
extern gboolean gst_ffmpegdec_register (GstPlugin *plugin);
extern gboolean gst_ffmpegenc_register (GstPlugin *plugin);
static gboolean
plugin_init (GModule *module, GstPlugin *plugin)
{
avcodec_init ();
avcodec_register_all ();
av_register_all ();
if (!gst_library_load ("gstbytestream"))
return FALSE;
gst_ffmpegenc_register (plugin);
gst_ffmpegdec_register (plugin);
gst_ffmpegdemux_register (plugin);
/* Now we can return the pointer to the newly created Plugin object. */
return TRUE;
......
/* 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.
*/
#include <libavcodec/avcodec.h>
#include <gst/gst.h>
GstCaps *
gst_ffmpegcodec_codec_context_to_caps (AVCodecContext *context)
{
switch (context->codec_id) {
case CODEC_ID_NONE:
return GST_CAPS_NEW ("ffmpeg_none",
"unkown/unkown",
NULL);
break;
case CODEC_ID_MPEG1VIDEO:
return GST_CAPS_NEW ("ffmpeg_mpeg1video",
"video/mpeg",
"mpegversion", GST_PROPS_INT (1),
"systemstream", GST_PROPS_BOOLEAN (FALSE)
);
break;
case CODEC_ID_H263:
return GST_CAPS_NEW ("ffmpeg_h263",
"video/H263",
NULL);
break;
case CODEC_ID_RV10:
return GST_CAPS_NEW ("ffmpeg_rv10",
"video/x-rv10",
NULL);
break;
case CODEC_ID_MP2:
return GST_CAPS_NEW ("ffmpeg_mp2",
"audio/mp3",
NULL);
break;
case CODEC_ID_MP3LAME:
return GST_CAPS_NEW ("ffmpeg_mp3",
"audio/mp3",
NULL);
break;
case CODEC_ID_VORBIS:
return GST_CAPS_NEW ("ffmpeg_vorbis",
"application/x-ogg",
NULL);
break;
case CODEC_ID_AC3:
return GST_CAPS_NEW ("ffmpeg_ac3",
"audio/ac3",
NULL);
break;
case CODEC_ID_MJPEG:
return GST_CAPS_NEW ("ffmpeg_mjpeg",
"video/x-mjpeg",
NULL);
break;
case CODEC_ID_MPEG4:
return GST_CAPS_NEW ("ffmpeg_mpeg4",
"video/avi",
"format", GST_PROPS_STRING ("strf_vids"),
"fourcc", GST_PROPS_FOURCC (context->fourcc),
"width", GST_PROPS_INT (context->width),
"height", GST_PROPS_INT (context->height)
);
break;
case CODEC_ID_RAWVIDEO:
return GST_CAPS_NEW ("ffmpeg_rawvideo",
"video/raw",
NULL);
break;
case CODEC_ID_MSMPEG4V1:
return GST_CAPS_NEW ("ffmpeg_msmpeg4v1",
"video/avi",
"format", GST_PROPS_STRING ("strf_vids"),
"fourcc", GST_PROPS_FOURCC (context->fourcc),
"width", GST_PROPS_INT (context->width),
"height", GST_PROPS_INT (context->height)
);
break;
case CODEC_ID_MSMPEG4V2:
return GST_CAPS_NEW ("ffmpeg_msmpeg4v2",
"video/avi",
"format", GST_PROPS_STRING ("strf_vids"),
"fourcc", GST_PROPS_FOURCC (context->fourcc),
"width", GST_PROPS_INT (context->width),
"height", GST_PROPS_INT (context->height)
);
break;
case CODEC_ID_MSMPEG4V3:
return GST_CAPS_NEW ("ffmpeg_msmpeg4v3",
"video/avi",
"format", GST_PROPS_STRING ("strf_vids"),
"fourcc", GST_PROPS_FOURCC (context->fourcc),
"width", GST_PROPS_INT (context->width),
"height", GST_PROPS_INT (context->height)
);
break;
case CODEC_ID_WMV1:
return GST_CAPS_NEW ("ffmpeg_wmv1",
"video/avi",
"format", GST_PROPS_STRING ("strf_vids"),
"fourcc", GST_PROPS_FOURCC (GST_STR_FOURCC ("WMV1")),
"width", GST_PROPS_INT (context->width),
"height", GST_PROPS_INT (context->height)
);
break;
case CODEC_ID_WMV2:
return GST_CAPS_NEW ("ffmpeg_wmv2",
"unkown/unkown",
NULL);
break;
case CODEC_ID_H263P:
return GST_CAPS_NEW ("ffmpeg_h263p",
"unkown/unkown",
NULL);
break;
case CODEC_ID_H263I:
return GST_CAPS_NEW ("ffmpeg_h263i",
"unkown/unkown",
NULL);
break;
case CODEC_ID_SVQ1:
return GST_CAPS_NEW ("ffmpeg_svq1",
"unkown/unkown",
NULL);
break;
case CODEC_ID_DVVIDEO:
return GST_CAPS_NEW ("ffmpeg_dvvideo",
"unkown/unkown",
NULL);
break;
case CODEC_ID_DVAUDIO:
return GST_CAPS_NEW ("ffmpeg_dvaudio",
"unkown/unkown",
NULL);
break;
case CODEC_ID_WMAV1:
return GST_CAPS_NEW ("ffmpeg_wmav1",
"unkown/unkown",
NULL);
break;
case CODEC_ID_WMAV2:
return GST_CAPS_NEW ("ffmpeg_wmav2",
"unkown/unkown",
NULL);
break;
case CODEC_ID_MACE3:
return GST_CAPS_NEW ("ffmpeg_mace3",
"unkown/unkown",
NULL);
break;
case CODEC_ID_MACE6:
return GST_CAPS_NEW ("ffmpeg_mace6",
"unkown/unkown",
NULL);
break;
/* various pcm "codecs" */
case CODEC_ID_PCM_S16LE:
return GST_CAPS_NEW ("ffmpeg_s16le",
"unkown/unkown",
NULL);
break;
case CODEC_ID_PCM_S16BE:
return GST_CAPS_NEW ("ffmpeg_s16be",
"unkown/unkown",
NULL);
break;
case CODEC_ID_PCM_U16LE:
return GST_CAPS_NEW ("ffmpeg_u16le",
"unkown/unkown",
NULL);
break;
case CODEC_ID_PCM_U16BE:
return GST_CAPS_NEW ("ffmpeg_u16be",
"unkown/unkown",
NULL);
break;
case CODEC_ID_PCM_S8:
return GST_CAPS_NEW ("ffmpeg_s8",
"unkown/unkown",
NULL);
break;
case CODEC_ID_PCM_U8:
return GST_CAPS_NEW ("ffmpeg_u8",
"unkown/unkown",
NULL);
break;
case CODEC_ID_PCM_MULAW:
return GST_CAPS_NEW ("ffmpeg_mulaw",
"unkown/unkown",
NULL);
break;
case CODEC_ID_PCM_ALAW:
return GST_CAPS_NEW ("ffmpeg_alaw",
"unkown/unkown",
NULL);
break;
/* various adpcm codecs */
case CODEC_ID_ADPCM_IMA_QT:
return GST_CAPS_NEW ("ffmpeg_adpcm_ima_qt",
"unkown/unkown",
NULL);
break;
case CODEC_ID_ADPCM_IMA_WAV:
return GST_CAPS_NEW ("ffmpeg_adpcm_ima_wav",
"unkown/unkown",
NULL);
break;
case CODEC_ID_ADPCM_MS:
return GST_CAPS_NEW ("ffmpeg_adpcm_ms",
"unkown/unkown",
NULL);
break;
default:
g_warning ("no caps found for codec id %d\n", context->codec_id);
break;
}
return NULL;
}
......@@ -17,9 +17,43 @@
* Boston, MA 02111-1307, USA.
*/
#include "gstffmpegdec.h"
#include <assert.h>
#include <string.h>
#include <libavcodec/avcodec.h>
#include <gst/gst.h>
typedef struct _GstFFMpegDec GstFFMpegDec;
struct _GstFFMpegDec {
GstElement element;
/* We need to keep track of our pads, so we do so here. */
GstPad *srcpad;
GstPad *sinkpad;
AVCodecContext *context;
AVPicture *picture;
};
typedef struct _GstFFMpegDecClass GstFFMpegDecClass;
struct _GstFFMpegDecClass {
GstElementClass parent_class;
AVCodec *in_plugin;
};
#define GST_TYPE_FFMPEGDEC \
(gst_ffmpegdec_get_type())
#define GST_FFMPEGDEC(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FFMPEGDEC,GstFFMpegDec))
#define GST_FFMPEGDEC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FFMPEGDEC,GstFFMpegDecClass))
#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 */
......@@ -341,7 +375,7 @@ gst_ffmpegdec_register (GstPlugin *plugin)
goto next;
}
/* construct the type */
type_name = g_strdup_printf("ffmpeg%s_%s", codec_type, in_plugin->name);
type_name = g_strdup_printf("ff%s_%s", codec_type, in_plugin->name);
/* if it's already registered, drop it */
if (g_type_from_name(type_name)) {
......@@ -370,6 +404,8 @@ gst_ffmpegdec_register (GstPlugin *plugin)
factory = gst_element_factory_new(type_name,type,details);
g_return_val_if_fail(factory != NULL, FALSE);
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_NONE);
gst_element_factory_add_pad_template (factory,
GST_PAD_TEMPLATE_GET (gst_ffmpegdec_sink_factory));
......
/* 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.
*/
#ifndef __GST_FFMPEGDEC_H__
#define __GST_FFMPEGDEC_H__
#include <gst/gst.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifndef __GST_FFMPEG_AV_H__
#define __GST_FFMPEG_AV_H__
#undef ABS
#undef MAX
#undef MIN
#include <assert.h>
#include <libavcodec/avcodec.h>
#endif /* __GST_FFMPEG_AV_H__ */
/* This is the definition of the element's object structure. */
typedef struct _GstFFMpegDec GstFFMpegDec;
/* The structure itself is derived from GstElement, as can be seen by the
* fact that there's a complete instance of the GstElement structure at
* the beginning of the object. This allows the element to be cast to
* an Element or even an Object.
*/
struct _GstFFMpegDec {
GstElement element;
/* We need to keep track of our pads, so we do so here. */
GstPad *srcpad;
GstPad *sinkpad;
AVCodecContext *context;
AVPicture *picture;
};
/* The other half of the object is its class. The class also derives from
* the same parent, though it must be the class structure this time.
* Function pointers for polymophic methods and signals are placed in this
* structure. */
typedef struct _GstFFMpegDecClass GstFFMpegDecClass;
struct _GstFFMpegDecClass {
GstElementClass parent_class;
AVCodec *in_plugin;
};
/* Five standard preprocessing macros are used in the Gtk+ object system.
* The first uses the object's _get_type function to return the GType
* of the object.
*/
#define GST_TYPE_FFMPEGDEC \
(gst_ffmpegdec_get_type())
/* The second is a checking cast to the correct type. If the object passed
* is not the right type, a warning will be generated on stderr.
*/
#define GST_FFMPEGDEC(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FFMPEGDEC,GstFFMpegDec))
/* The third is a checking cast of the class instead of the object. */
#define GST_FFMPEGDEC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FFMPEGDEC,GstFFMpegDec))
/* The last two simply check to see if the passed pointer is an object or
* class of the correct type. */
#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))
gboolean gst_ffmpegdec_register (GstPlugin *plugin);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GST_FFMPEGDEC_H__ */
/* 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.
*/
#include <string.h>
#include <libav/avformat.h>
#include <libav/avi.h>
#include <gst/gst.h>
extern URLProtocol gstreamer_protocol;
typedef enum {
STATE_OPEN,
STATE_STREAM_INFO,
STATE_DEMUX,
STATE_END,
} DemuxState;
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;
DemuxState state;
GstPad *srcpads[MAX_STREAMS];
};
typedef struct _GstFFMpegDemuxClass GstFFMpegDemuxClass;
struct _GstFFMpegDemuxClass {
GstElementClass parent_class;
AVInputFormat *in_plugin;
};
#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 */
};
/* This factory is much simpler, and defines the source pad. */
GST_PAD_TEMPLATE_FACTORY (gst_ffmpegdemux_sink_factory,
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
NULL
)
/* This factory is much simpler, and defines the source pad. */
GST_PAD_TEMPLATE_FACTORY (gst_ffmpegdemux_audio_src_factory,
"audio_%02d",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
NULL
)
/* This factory is much simpler, and defines the source pad. */
GST_PAD_TEMPLATE_FACTORY (gst_ffmpegdemux_video_src_factory,
"video_%02d",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
NULL
)
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_init (GstFFMpegDemux *ffmpegdemux);
static void gst_ffmpegdemux_loop (GstElement *element);
static void gst_ffmpegdemux_set_property (GObject *object, guint prop_id, const GValue *value,
GParamSpec *pspec);
static void gst_ffmpegdemux_get_property (GObject *object, guint prop_id, GValue *value,
GParamSpec *pspec);
static GstElementClass *parent_class = NULL;
/*static guint gst_ffmpegdemux_signals[LAST_SIGNAL] = { 0 }; */
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);
klass->in_plugin = g_hash_table_lookup (global_plugins,
GINT_TO_POINTER (G_OBJECT_CLASS_TYPE (gobject_class)));
gobject_class->set_property = gst_ffmpegdemux_set_property;
gobject_class->get_property = gst_ffmpegdemux_get_property;
}
static void
gst_ffmpegdemux_init(GstFFMpegDemux *ffmpegdemux)
{
//GstFFMpegDemuxClass *oclass = (GstFFMpegDemuxClass*)(G_OBJECT_GET_CLASS (ffmpegdemux));
ffmpegdemux->sinkpad = gst_pad_new_from_template (
GST_PAD_TEMPLATE_GET (gst_ffmpegdemux_sink_factory), "sink");
gst_element_add_pad (GST_ELEMENT (ffmpegdemux), ffmpegdemux->sinkpad);
gst_element_set_loop_function (GST_ELEMENT (ffmpegdemux), gst_ffmpegdemux_loop);
ffmpegdemux->state = STATE_OPEN;
}
static void
gst_ffmpegdemux_loop (GstElement *element)
{
GstFFMpegDemux *ffmpegdemux = (GstFFMpegDemux *)(element);
GstFFMpegDemuxClass *oclass = (GstFFMpegDemuxClass*)(G_OBJECT_GET_CLASS (ffmpegdemux));
gint res = 0;
switch (ffmpegdemux->state) {
case STATE_OPEN:
{
res = av_open_input_file (&ffmpegdemux->context,
g_strdup_printf ("gstreamer://%p", ffmpegdemux->sinkpad),
oclass->in_plugin,
0,
NULL);
/* this doesn't work */
av_set_pts_info (ffmpegdemux->context, 33, 1, 100000);
ffmpegdemux->state = STATE_DEMUX;
break;
}
case STATE_DEMUX:
{
gint res;
AVPacket p