2002-03-20 21:44:42 +00:00
|
|
|
/* GStreamer
|
2001-12-23 13:25:04 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2004-01-12 04:15:46 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2002-11-26 14:50:05 +00:00
|
|
|
#include "config.h"
|
2004-01-12 04:15:46 +00:00
|
|
|
#endif
|
2003-06-07 00:41:32 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
/* for stats file handling */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
#include <errno.h>
|
2003-06-07 00:41:32 +00:00
|
|
|
|
2012-04-12 17:41:52 +00:00
|
|
|
#ifdef HAVE_LIBAV_UNINSTALLED
|
2002-11-26 14:50:05 +00:00
|
|
|
#include <avcodec.h>
|
|
|
|
#else
|
2008-10-30 12:05:45 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
2002-11-26 14:50:05 +00:00
|
|
|
#endif
|
2002-11-06 23:53:46 +00:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2004-12-18 20:53:55 +00:00
|
|
|
#include "gstffmpeg.h"
|
2003-06-07 00:41:32 +00:00
|
|
|
#include "gstffmpegcodecmap.h"
|
2009-04-15 20:33:16 +00:00
|
|
|
#include "gstffmpegutils.h"
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
#include "gstffmpegenc.h"
|
2003-06-07 00:41:32 +00:00
|
|
|
|
2006-02-11 12:04:31 +00:00
|
|
|
#define DEFAULT_AUDIO_BITRATE 128000
|
|
|
|
|
2004-03-29 16:39:18 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-23 13:25:04 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-29 16:39:18 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-23 13:25:04 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_BIT_RATE,
|
2005-11-28 17:12:13 +00:00
|
|
|
ARG_BUFSIZE,
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
ARG_RTP_PAYLOAD_SIZE,
|
2001-12-23 13:25:04 +00:00
|
|
|
};
|
|
|
|
|
2007-02-16 11:48:15 +00:00
|
|
|
/* A number of function prototypes are given so we can refer to them later. */
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegaudenc_class_init (GstFFMpegAudEncClass * klass);
|
|
|
|
static void gst_ffmpegaudenc_base_init (GstFFMpegAudEncClass * klass);
|
|
|
|
static void gst_ffmpegaudenc_init (GstFFMpegAudEnc * ffmpegaudenc);
|
|
|
|
static void gst_ffmpegaudenc_finalize (GObject * object);
|
2003-06-07 20:46:24 +00:00
|
|
|
|
2012-06-14 10:41:34 +00:00
|
|
|
static gboolean gst_ffmpegaudenc_setcaps (GstFFMpegAudEnc * ffmpegenc,
|
2011-06-08 16:04:07 +00:00
|
|
|
GstCaps * caps);
|
2012-06-14 10:41:34 +00:00
|
|
|
static GstCaps *gst_ffmpegaudenc_getcaps (GstFFMpegAudEnc * ffmpegenc,
|
|
|
|
GstCaps * filter);
|
2012-04-07 09:14:45 +00:00
|
|
|
static GstFlowReturn gst_ffmpegaudenc_chain_audio (GstPad * pad,
|
2011-11-17 11:49:33 +00:00
|
|
|
GstObject * parent, GstBuffer * buffer);
|
2012-06-14 10:41:34 +00:00
|
|
|
static gboolean gst_ffmpegaudenc_query_sink (GstPad * pad, GstObject * parent,
|
2011-11-16 16:29:22 +00:00
|
|
|
GstQuery * query);
|
2012-06-14 10:41:34 +00:00
|
|
|
static gboolean gst_ffmpegaudenc_event_sink (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegaudenc_set_property (GObject * object,
|
2004-03-29 16:39:18 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegaudenc_get_property (GObject * object,
|
2004-03-29 16:39:18 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
static GstStateChangeReturn gst_ffmpegaudenc_change_state (GstElement * element,
|
2005-09-05 14:06:29 +00:00
|
|
|
GstStateChange transition);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2012-04-12 17:41:52 +00:00
|
|
|
#define GST_FFENC_PARAMS_QDATA g_quark_from_static_string("avenc-params")
|
2007-02-16 11:48:15 +00:00
|
|
|
|
2001-12-23 13:25:04 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
/*static guint gst_ffmpegaudenc_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2003-11-02 13:12:14 +00:00
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_base_init (GstFFMpegAudEncClass * klass)
|
2003-11-02 13:12:14 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2009-11-02 07:43:17 +00:00
|
|
|
AVCodec *in_plugin;
|
|
|
|
GstPadTemplate *srctempl = NULL, *sinktempl = NULL;
|
|
|
|
GstCaps *srccaps = NULL, *sinkcaps = NULL;
|
2012-04-07 09:14:45 +00:00
|
|
|
gchar *longname, *description;
|
2003-11-02 13:12:14 +00:00
|
|
|
|
2009-11-02 07:43:17 +00:00
|
|
|
in_plugin =
|
|
|
|
(AVCodec *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
|
2007-02-16 11:48:15 +00:00
|
|
|
GST_FFENC_PARAMS_QDATA);
|
2009-11-02 07:43:17 +00:00
|
|
|
g_assert (in_plugin != NULL);
|
2003-11-02 13:12:14 +00:00
|
|
|
|
|
|
|
/* construct the element details struct */
|
2012-04-12 17:41:52 +00:00
|
|
|
longname = g_strdup_printf ("libav %s encoder", in_plugin->long_name);
|
|
|
|
description = g_strdup_printf ("libav %s encoder", in_plugin->name);
|
2012-04-09 23:59:24 +00:00
|
|
|
gst_element_class_set_metadata (element_class, longname,
|
2012-04-07 09:14:45 +00:00
|
|
|
"Codec/Encoder/Audio", description,
|
2010-03-24 10:51:26 +00:00
|
|
|
"Wim Taymans <wim.taymans@gmail.com>, "
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
|
|
|
g_free (longname);
|
|
|
|
g_free (description);
|
2003-11-02 13:12:14 +00:00
|
|
|
|
2009-11-02 07:43:17 +00:00
|
|
|
if (!(srccaps = gst_ffmpeg_codecid_to_caps (in_plugin->id, NULL, TRUE))) {
|
|
|
|
GST_DEBUG ("Couldn't get source caps for encoder '%s'", in_plugin->name);
|
2011-10-28 14:35:54 +00:00
|
|
|
srccaps = gst_caps_new_empty_simple ("unknown/unknown");
|
2009-11-02 07:43:17 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
sinkcaps = gst_ffmpeg_codectype_to_audio_caps (NULL,
|
|
|
|
in_plugin->id, TRUE, in_plugin);
|
2009-11-02 07:43:17 +00:00
|
|
|
if (!sinkcaps) {
|
|
|
|
GST_DEBUG ("Couldn't get sink caps for encoder '%s'", in_plugin->name);
|
2011-10-28 14:35:54 +00:00
|
|
|
sinkcaps = gst_caps_new_empty_simple ("unknown/unknown");
|
2009-11-02 07:43:17 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 13:12:14 +00:00
|
|
|
/* pad templates */
|
|
|
|
sinktempl = gst_pad_template_new ("sink", GST_PAD_SINK,
|
2009-11-02 07:43:17 +00:00
|
|
|
GST_PAD_ALWAYS, sinkcaps);
|
|
|
|
srctempl = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, srccaps);
|
2003-11-02 13:12:14 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class, srctempl);
|
|
|
|
gst_element_class_add_pad_template (element_class, sinktempl);
|
|
|
|
|
2009-11-02 07:43:17 +00:00
|
|
|
klass->in_plugin = in_plugin;
|
2003-11-02 13:12:14 +00:00
|
|
|
klass->srctempl = srctempl;
|
|
|
|
klass->sinktempl = sinktempl;
|
2004-12-17 11:32:45 +00:00
|
|
|
klass->sinkcaps = NULL;
|
2009-11-02 07:43:17 +00:00
|
|
|
|
|
|
|
return;
|
2003-11-02 13:12:14 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 13:25:04 +00:00
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_class_init (GstFFMpegAudEncClass * klass)
|
2001-12-23 13:25:04 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-29 16:39:18 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2006-04-08 21:55:22 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
gobject_class->set_property = gst_ffmpegaudenc_set_property;
|
|
|
|
gobject_class->get_property = gst_ffmpegaudenc_get_property;
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
|
2012-06-14 10:41:34 +00:00
|
|
|
/* FIXME: could use -1 for a sensible per-codec defaults */
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BIT_RATE,
|
|
|
|
g_param_spec_int ("bitrate", "Bit Rate",
|
|
|
|
"Target Audio Bitrate", 0, G_MAXINT, DEFAULT_AUDIO_BITRATE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
gstelement_class->change_state = gst_ffmpegaudenc_change_state;
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
gobject_class->finalize = gst_ffmpegaudenc_finalize;
|
2001-12-23 13:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_init (GstFFMpegAudEnc * ffmpegaudenc)
|
2001-12-23 13:25:04 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegAudEncClass *oclass =
|
|
|
|
(GstFFMpegAudEncClass *) (G_OBJECT_GET_CLASS (ffmpegaudenc));
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* setup pads */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->sinkpad = gst_pad_new_from_template (oclass->sinktempl, "sink");
|
2012-06-14 10:41:34 +00:00
|
|
|
gst_pad_set_event_function (ffmpegaudenc->sinkpad,
|
|
|
|
gst_ffmpegaudenc_event_sink);
|
|
|
|
gst_pad_set_query_function (ffmpegaudenc->sinkpad,
|
|
|
|
gst_ffmpegaudenc_query_sink);
|
|
|
|
gst_pad_set_chain_function (ffmpegaudenc->sinkpad,
|
|
|
|
gst_ffmpegaudenc_chain_audio);
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->srcpad = gst_pad_new_from_template (oclass->srctempl, "src");
|
|
|
|
gst_pad_use_fixed_caps (ffmpegaudenc->srcpad);
|
2006-10-06 14:46:48 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* ffmpeg objects */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->context = avcodec_alloc_context ();
|
|
|
|
ffmpegaudenc->opened = FALSE;
|
2004-10-11 08:21:16 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (ffmpegaudenc), ffmpegaudenc->sinkpad);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (ffmpegaudenc), ffmpegaudenc->srcpad);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->adapter = gst_adapter_new ();
|
2001-12-23 13:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_finalize (GObject * object)
|
2001-12-23 13:25:04 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegAudEnc *ffmpegaudenc = (GstFFMpegAudEnc *) object;
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2007-08-01 17:43:39 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* close old session */
|
2012-04-07 09:14:45 +00:00
|
|
|
if (ffmpegaudenc->opened) {
|
|
|
|
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
|
|
|
ffmpegaudenc->opened = FALSE;
|
2003-06-07 20:46:24 +00:00
|
|
|
}
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* clean up remaining allocated data */
|
2012-04-07 09:14:45 +00:00
|
|
|
av_free (ffmpegaudenc->context);
|
2005-01-09 21:47:26 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
g_object_unref (ffmpegaudenc->adapter);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
2007-01-03 17:00:08 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2003-06-07 20:46:24 +00:00
|
|
|
}
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2009-03-06 18:47:05 +00:00
|
|
|
static GstCaps *
|
2012-06-14 10:41:34 +00:00
|
|
|
gst_ffmpegaudenc_getcaps (GstFFMpegAudEnc * ffmpegaudenc, GstCaps * filter)
|
2004-12-17 11:32:45 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc, "getting caps");
|
2008-05-26 09:19:53 +00:00
|
|
|
|
2004-12-17 11:32:45 +00:00
|
|
|
/* audio needs no special care */
|
2012-06-14 10:41:34 +00:00
|
|
|
caps = gst_pad_get_pad_template_caps (ffmpegaudenc->sinkpad);
|
2009-03-06 18:47:05 +00:00
|
|
|
|
2011-06-30 07:21:31 +00:00
|
|
|
if (filter) {
|
2012-06-14 10:41:34 +00:00
|
|
|
GstCaps *tmp;
|
|
|
|
tmp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
|
2011-06-30 07:21:31 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-06-14 10:41:34 +00:00
|
|
|
caps = tmp;
|
2011-06-30 07:21:31 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc,
|
|
|
|
"audio caps, return template %" GST_PTR_FORMAT, caps);
|
2009-03-06 18:47:05 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
return caps;
|
2004-12-17 11:32:45 +00:00
|
|
|
}
|
|
|
|
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
static gboolean
|
2012-06-14 10:41:34 +00:00
|
|
|
gst_ffmpegaudenc_setcaps (GstFFMpegAudEnc * ffmpegaudenc, GstCaps * caps)
|
2003-06-07 20:46:24 +00:00
|
|
|
{
|
2003-12-22 01:46:58 +00:00
|
|
|
GstCaps *other_caps;
|
2004-01-09 01:53:31 +00:00
|
|
|
GstCaps *allowed_caps;
|
|
|
|
GstCaps *icaps;
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegAudEncClass *oclass =
|
|
|
|
(GstFFMpegAudEncClass *) G_OBJECT_GET_CLASS (ffmpegaudenc);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* close old session */
|
2012-04-07 09:14:45 +00:00
|
|
|
if (ffmpegaudenc->opened) {
|
|
|
|
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
|
|
|
ffmpegaudenc->opened = FALSE;
|
2010-10-25 10:14:42 +00:00
|
|
|
/* fixed src caps;
|
|
|
|
* so clear src caps for proper (re-)negotiation */
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_pad_set_caps (ffmpegaudenc->srcpad, NULL);
|
2003-06-07 20:46:24 +00:00
|
|
|
}
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* set defaults */
|
2012-04-07 09:14:45 +00:00
|
|
|
avcodec_get_context_defaults (ffmpegaudenc->context);
|
2003-06-07 20:46:24 +00:00
|
|
|
|
2005-01-16 11:29:28 +00:00
|
|
|
/* if we set it in _getcaps we should set it also in _link */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->context->strict_std_compliance = -1;
|
2005-01-16 11:29:28 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* user defined properties */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->context->bit_rate = ffmpegaudenc->bitrate;
|
|
|
|
ffmpegaudenc->context->bit_rate_tolerance = ffmpegaudenc->bitrate;
|
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc, "Setting avcontext to bitrate %lu",
|
|
|
|
ffmpegaudenc->bitrate);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2005-11-28 17:12:13 +00:00
|
|
|
/* RTP payload used for GOB production (for Asterisk) */
|
2012-04-07 09:14:45 +00:00
|
|
|
if (ffmpegaudenc->rtp_payload_size) {
|
|
|
|
ffmpegaudenc->context->rtp_payload_size = ffmpegaudenc->rtp_payload_size;
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* some other defaults */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->context->rc_strategy = 2;
|
|
|
|
ffmpegaudenc->context->b_frame_strategy = 0;
|
|
|
|
ffmpegaudenc->context->coder_type = 0;
|
|
|
|
ffmpegaudenc->context->context_model = 0;
|
|
|
|
ffmpegaudenc->context->scenechange_threshold = 0;
|
|
|
|
ffmpegaudenc->context->inter_threshold = 0;
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2003-12-22 01:46:58 +00:00
|
|
|
/* fetch pix_fmt and so on */
|
ext/ffmpeg/gstffmpegcodecmap.*: Change some function names to reflect that they don't really _return_ something, but ...
Original commit message from CVS:
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_get_palette),
(gst_ffmpeg_set_palette), (gst_ffmpeg_codecid_to_caps),
(gst_ffmpeg_pixfmt_to_caps), (gst_ffmpeg_caps_to_smpfmt),
(gst_ffmpeg_caps_to_pixfmt), (gst_ffmpeg_caps_with_codectype),
(gst_ffmpeg_caps_with_codecid), (gst_ffmpeg_caps_to_codecid):
* ext/ffmpeg/gstffmpegcodecmap.h:
Change some function names to reflect that they don't really
_return_ something, but rather _use_ something to fill a
AVCodecContext. s/to/with/. Restructure the extradata handling,
it's now not picking up the type from the caps but rather
using the type as provided in the function. This is a lot
cleaner. Implement MS RLE palette pickup.
* ext/ffmpeg/gstffmpegcolorspace.c: (gst_ffmpegcsp_pad_link):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_connect):
Sync with the above function name changes.
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_close),
(gst_ffmpegdec_open), (gst_ffmpegdec_connect),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state):
Add some hacks to convert palette-based raw image formats to
RGBA32. Ugly, but I don't know how else to handle palette-based
RGB, since img_convert() (and thus ffcolorspace) doesn't accept
a palette as argument.
2004-04-16 01:28:36 +00:00
|
|
|
gst_ffmpeg_caps_with_codectype (oclass->in_plugin->type,
|
2012-04-07 09:14:45 +00:00
|
|
|
caps, ffmpegaudenc->context);
|
|
|
|
if (!ffmpegaudenc->context->time_base.den) {
|
|
|
|
ffmpegaudenc->context->time_base.den = 25;
|
|
|
|
ffmpegaudenc->context->time_base.num = 1;
|
|
|
|
ffmpegaudenc->context->ticks_per_frame = 1;
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
}
|
|
|
|
|
2003-12-22 01:46:58 +00:00
|
|
|
/* open codec */
|
2012-04-07 09:14:45 +00:00
|
|
|
if (gst_ffmpeg_avcodec_open (ffmpegaudenc->context, oclass->in_plugin) < 0) {
|
|
|
|
if (ffmpegaudenc->context->priv_data)
|
|
|
|
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
|
|
|
if (ffmpegaudenc->context->stats_in)
|
|
|
|
g_free (ffmpegaudenc->context->stats_in);
|
2012-06-14 10:41:34 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc, "avenc_%s: Failed to open FFMPEG codec",
|
2004-03-29 16:39:18 +00:00
|
|
|
oclass->in_plugin->name);
|
2005-08-19 15:23:39 +00:00
|
|
|
return FALSE;
|
2003-06-07 21:06:05 +00:00
|
|
|
}
|
|
|
|
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
/* second pass stats buffer no longer needed */
|
2012-04-07 09:14:45 +00:00
|
|
|
if (ffmpegaudenc->context->stats_in)
|
|
|
|
g_free (ffmpegaudenc->context->stats_in);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2004-10-25 11:56:52 +00:00
|
|
|
/* some codecs support more than one format, first auto-choose one */
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc, "picking an output format ...");
|
|
|
|
allowed_caps = gst_pad_get_allowed_caps (ffmpegaudenc->srcpad);
|
2005-09-30 09:29:22 +00:00
|
|
|
if (!allowed_caps) {
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc, "... but no peer, using template caps");
|
2005-10-05 17:53:00 +00:00
|
|
|
/* we need to copy because get_allowed_caps returns a ref, and
|
|
|
|
* get_pad_template_caps doesn't */
|
2012-06-14 10:41:34 +00:00
|
|
|
allowed_caps = gst_pad_get_pad_template_caps (ffmpegaudenc->srcpad);
|
2005-09-30 09:29:22 +00:00
|
|
|
}
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc, "chose caps %" GST_PTR_FORMAT, allowed_caps);
|
2004-10-25 11:56:52 +00:00
|
|
|
gst_ffmpeg_caps_with_codecid (oclass->in_plugin->id,
|
2012-04-07 09:14:45 +00:00
|
|
|
oclass->in_plugin->type, allowed_caps, ffmpegaudenc->context);
|
2004-10-25 11:56:52 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* try to set this caps on the other side */
|
2003-12-22 01:46:58 +00:00
|
|
|
other_caps = gst_ffmpeg_codecid_to_caps (oclass->in_plugin->id,
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->context, TRUE);
|
2004-10-25 11:56:52 +00:00
|
|
|
|
2003-12-22 01:46:58 +00:00
|
|
|
if (!other_caps) {
|
2012-03-27 14:39:09 +00:00
|
|
|
gst_caps_unref (allowed_caps);
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
GST_DEBUG ("Unsupported codec - no caps found");
|
2005-08-19 15:23:39 +00:00
|
|
|
return FALSE;
|
2001-12-23 13:25:04 +00:00
|
|
|
}
|
2003-06-07 20:46:24 +00:00
|
|
|
|
2004-01-09 01:53:31 +00:00
|
|
|
icaps = gst_caps_intersect (allowed_caps, other_caps);
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
gst_caps_unref (allowed_caps);
|
|
|
|
gst_caps_unref (other_caps);
|
2004-01-09 01:53:31 +00:00
|
|
|
if (gst_caps_is_empty (icaps)) {
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
gst_caps_unref (icaps);
|
2005-08-19 15:23:39 +00:00
|
|
|
return FALSE;
|
2004-01-09 01:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_caps_get_size (icaps) > 1) {
|
|
|
|
GstCaps *newcaps;
|
|
|
|
|
2004-03-29 16:39:18 +00:00
|
|
|
newcaps =
|
|
|
|
gst_caps_new_full (gst_structure_copy (gst_caps_get_structure (icaps,
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
0)), NULL);
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
gst_caps_unref (icaps);
|
2004-01-09 01:53:31 +00:00
|
|
|
icaps = newcaps;
|
|
|
|
}
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
if (!gst_pad_set_caps (ffmpegaudenc->srcpad, icaps)) {
|
|
|
|
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
gst_caps_unref (icaps);
|
2005-08-19 15:23:39 +00:00
|
|
|
return FALSE;
|
2001-12-23 13:25:04 +00:00
|
|
|
}
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
gst_caps_unref (icaps);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2003-06-07 20:46:24 +00:00
|
|
|
/* success! */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->opened = TRUE;
|
2003-06-07 20:46:24 +00:00
|
|
|
|
2005-08-19 15:23:39 +00:00
|
|
|
return TRUE;
|
2001-12-23 13:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-12 23:04:30 +00:00
|
|
|
static GstFlowReturn
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_encode_audio (GstFFMpegAudEnc * ffmpegaudenc,
|
|
|
|
guint8 * audio_in, guint in_size, guint max_size, GstClockTime timestamp,
|
2010-10-05 17:22:28 +00:00
|
|
|
GstClockTime duration, gboolean discont)
|
2009-05-12 23:04:30 +00:00
|
|
|
{
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
AVCodecContext *ctx;
|
2012-01-24 13:40:37 +00:00
|
|
|
GstMapInfo map;
|
2009-05-12 23:04:30 +00:00
|
|
|
gint res;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
ctx = ffmpegaudenc->context;
|
2009-05-12 23:04:30 +00:00
|
|
|
|
2010-10-05 17:22:28 +00:00
|
|
|
/* We need to provide at least ffmpegs minimal buffer size */
|
|
|
|
outbuf = gst_buffer_new_and_alloc (max_size + FF_MIN_BUFFER_SIZE);
|
2012-01-24 13:40:37 +00:00
|
|
|
gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "encoding buffer of max size %d", max_size);
|
|
|
|
if (ffmpegaudenc->buffer_size != max_size)
|
|
|
|
ffmpegaudenc->buffer_size = max_size;
|
2009-05-12 23:04:30 +00:00
|
|
|
|
2012-01-24 13:40:37 +00:00
|
|
|
res = avcodec_encode_audio (ctx, map.data, max_size, (short *) audio_in);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
|
|
|
if (res < 0) {
|
2012-01-24 13:40:37 +00:00
|
|
|
gst_buffer_unmap (outbuf, &map);
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_ERROR_OBJECT (ffmpegaudenc, "Failed to encode buffer: %d", res);
|
2009-05-12 23:04:30 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "got output size %d", res);
|
2012-01-24 13:40:37 +00:00
|
|
|
gst_buffer_unmap (outbuf, &map);
|
|
|
|
gst_buffer_resize (outbuf, 0, res);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
|
|
|
|
GST_BUFFER_DURATION (outbuf) = duration;
|
|
|
|
if (discont)
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "pushing size %d, timestamp %" GST_TIME_FORMAT,
|
2009-05-12 23:04:30 +00:00
|
|
|
res, GST_TIME_ARGS (timestamp));
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
ret = gst_pad_push (ffmpegaudenc->srcpad, outbuf);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
static GstFlowReturn
|
2012-06-14 10:41:34 +00:00
|
|
|
gst_ffmpegaudenc_chain_audio (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * inbuf)
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegAudEnc *ffmpegaudenc;
|
|
|
|
GstFFMpegAudEncClass *oclass;
|
2009-05-12 23:04:30 +00:00
|
|
|
AVCodecContext *ctx;
|
|
|
|
GstClockTime timestamp, duration;
|
2011-04-04 10:23:05 +00:00
|
|
|
gsize size, frame_size;
|
2009-05-12 23:04:30 +00:00
|
|
|
gint osize;
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
GstFlowReturn ret;
|
2009-05-12 23:04:30 +00:00
|
|
|
gint out_size;
|
|
|
|
gboolean discont;
|
2009-05-13 21:18:50 +00:00
|
|
|
guint8 *in_data;
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
|
2012-06-14 10:41:34 +00:00
|
|
|
ffmpegaudenc = (GstFFMpegAudEnc *) parent;
|
2012-04-07 09:14:45 +00:00
|
|
|
oclass = (GstFFMpegAudEncClass *) G_OBJECT_GET_CLASS (ffmpegaudenc);
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
|
2012-06-14 10:41:34 +00:00
|
|
|
if (G_UNLIKELY (!ffmpegaudenc->opened))
|
2011-06-30 07:18:42 +00:00
|
|
|
goto not_negotiated;
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
ctx = ffmpegaudenc->context;
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
|
2011-04-04 10:23:05 +00:00
|
|
|
size = gst_buffer_get_size (inbuf);
|
2009-05-12 23:04:30 +00:00
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (inbuf);
|
|
|
|
duration = GST_BUFFER_DURATION (inbuf);
|
|
|
|
discont = GST_BUFFER_IS_DISCONT (inbuf);
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc,
|
2009-05-12 23:04:30 +00:00
|
|
|
"Received time %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT
|
2012-02-27 05:26:02 +00:00
|
|
|
", size %" G_GSIZE_FORMAT, GST_TIME_ARGS (timestamp),
|
|
|
|
GST_TIME_ARGS (duration), size);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
|
|
|
frame_size = ctx->frame_size;
|
|
|
|
osize = av_get_bits_per_sample_format (ctx->sample_fmt) / 8;
|
|
|
|
|
|
|
|
if (frame_size > 1) {
|
|
|
|
/* we have a frame_size, feed the encoder multiples of this frame size */
|
|
|
|
guint avail, frame_bytes;
|
|
|
|
|
|
|
|
if (discont) {
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "DISCONT, clear adapter");
|
|
|
|
gst_adapter_clear (ffmpegaudenc->adapter);
|
|
|
|
ffmpegaudenc->discont = TRUE;
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
if (gst_adapter_available (ffmpegaudenc->adapter) == 0) {
|
2009-05-12 23:04:30 +00:00
|
|
|
/* lock on to new timestamp */
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "taking buffer timestamp %" GST_TIME_FORMAT,
|
2009-05-12 23:04:30 +00:00
|
|
|
GST_TIME_ARGS (timestamp));
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->adapter_ts = timestamp;
|
|
|
|
ffmpegaudenc->adapter_consumed = 0;
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
} else {
|
2009-12-14 20:20:53 +00:00
|
|
|
GstClockTime upstream_time;
|
2010-07-02 21:38:06 +00:00
|
|
|
GstClockTime consumed_time;
|
2009-12-14 20:20:53 +00:00
|
|
|
guint64 bytes;
|
|
|
|
|
2009-05-12 23:04:30 +00:00
|
|
|
/* use timestamp at head of the adapter */
|
2010-07-02 21:38:06 +00:00
|
|
|
consumed_time =
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_util_uint64_scale (ffmpegaudenc->adapter_consumed, GST_SECOND,
|
2009-05-12 23:04:30 +00:00
|
|
|
ctx->sample_rate);
|
2012-04-07 09:14:45 +00:00
|
|
|
timestamp = ffmpegaudenc->adapter_ts + consumed_time;
|
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "taking adapter timestamp %" GST_TIME_FORMAT
|
2010-07-02 21:38:06 +00:00
|
|
|
" and adding consumed time %" GST_TIME_FORMAT,
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_TIME_ARGS (ffmpegaudenc->adapter_ts),
|
|
|
|
GST_TIME_ARGS (consumed_time));
|
2010-07-02 21:38:06 +00:00
|
|
|
|
2009-12-14 20:20:53 +00:00
|
|
|
/* check with upstream timestamps, if too much deviation,
|
|
|
|
* forego some timestamp perfection in favour of upstream syncing
|
|
|
|
* (particularly in case these do not happen to come in multiple
|
|
|
|
* of frame size) */
|
2012-04-07 09:14:45 +00:00
|
|
|
upstream_time =
|
|
|
|
gst_adapter_prev_timestamp (ffmpegaudenc->adapter, &bytes);
|
2009-12-14 20:20:53 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (upstream_time)) {
|
|
|
|
GstClockTimeDiff diff;
|
|
|
|
|
|
|
|
upstream_time +=
|
2010-07-02 21:38:06 +00:00
|
|
|
gst_util_uint64_scale (bytes, GST_SECOND,
|
|
|
|
ctx->sample_rate * osize * ctx->channels);
|
2009-12-14 20:20:53 +00:00
|
|
|
diff = upstream_time - timestamp;
|
|
|
|
/* relaxed difference, rather than half a sample or so ... */
|
|
|
|
if (diff > GST_SECOND / 10 || diff < -GST_SECOND / 10) {
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc, "adapter timestamp drifting, "
|
2009-12-14 20:20:53 +00:00
|
|
|
"taking upstream timestamp %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (upstream_time));
|
|
|
|
timestamp = upstream_time;
|
2010-07-05 08:32:42 +00:00
|
|
|
/* samples corresponding to bytes */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->adapter_consumed = bytes / (osize * ctx->channels);
|
|
|
|
ffmpegaudenc->adapter_ts = upstream_time -
|
|
|
|
gst_util_uint64_scale (ffmpegaudenc->adapter_consumed, GST_SECOND,
|
2010-07-05 08:32:42 +00:00
|
|
|
ctx->sample_rate);
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->discont = TRUE;
|
2009-12-14 20:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "pushing buffer in adapter");
|
|
|
|
gst_adapter_push (ffmpegaudenc->adapter, inbuf);
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
|
2009-05-12 23:04:30 +00:00
|
|
|
/* first see how many bytes we need to feed to the decoder. */
|
|
|
|
frame_bytes = frame_size * osize * ctx->channels;
|
2012-04-07 09:14:45 +00:00
|
|
|
avail = gst_adapter_available (ffmpegaudenc->adapter);
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "frame_bytes %u, avail %u", frame_bytes,
|
|
|
|
avail);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
|
|
|
/* while there is more than a frame size in the adapter, consume it */
|
|
|
|
while (avail >= frame_bytes) {
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "taking %u bytes from the adapter",
|
2009-05-12 23:04:30 +00:00
|
|
|
frame_bytes);
|
|
|
|
|
2010-07-02 21:38:06 +00:00
|
|
|
/* Note that we take frame_bytes and add frame_size.
|
|
|
|
* Makes sense when resyncing because you don't have to count channels
|
|
|
|
* or samplesize to divide by the samplerate */
|
|
|
|
|
2009-05-12 23:04:30 +00:00
|
|
|
/* take an audio buffer out of the adapter */
|
2012-06-14 10:41:34 +00:00
|
|
|
in_data = (guint8 *) gst_adapter_map (ffmpegaudenc->adapter, frame_bytes);
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->adapter_consumed += frame_size;
|
2009-05-12 23:04:30 +00:00
|
|
|
|
|
|
|
/* calculate timestamp and duration relative to start of adapter and to
|
|
|
|
* the amount of samples we consumed */
|
|
|
|
duration =
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_util_uint64_scale (ffmpegaudenc->adapter_consumed, GST_SECOND,
|
2009-05-12 23:04:30 +00:00
|
|
|
ctx->sample_rate);
|
2012-04-07 09:14:45 +00:00
|
|
|
duration -= (timestamp - ffmpegaudenc->adapter_ts);
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
|
2010-10-05 17:22:28 +00:00
|
|
|
/* 4 times the input size should be big enough... */
|
|
|
|
out_size = frame_bytes * 4;
|
2009-05-12 23:04:30 +00:00
|
|
|
|
2010-10-05 17:22:28 +00:00
|
|
|
ret =
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_encode_audio (ffmpegaudenc, in_data, frame_bytes,
|
|
|
|
out_size, timestamp, duration, ffmpegaudenc->discont);
|
2009-05-13 21:18:50 +00:00
|
|
|
|
2012-06-14 10:41:34 +00:00
|
|
|
gst_adapter_unmap (ffmpegaudenc->adapter);
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_adapter_flush (ffmpegaudenc->adapter, frame_bytes);
|
2009-05-13 21:18:50 +00:00
|
|
|
|
2009-05-12 23:04:30 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto push_failed;
|
|
|
|
|
2009-05-13 21:18:50 +00:00
|
|
|
/* advance the adapter timestamp with the duration */
|
|
|
|
timestamp += duration;
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc->discont = FALSE;
|
|
|
|
avail = gst_adapter_available (ffmpegaudenc->adapter);
|
2009-04-23 17:35:10 +00:00
|
|
|
}
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "%u bytes left in the adapter", avail);
|
2009-05-12 23:04:30 +00:00
|
|
|
} else {
|
2012-01-24 13:40:37 +00:00
|
|
|
GstMapInfo map;
|
2009-05-12 23:04:30 +00:00
|
|
|
/* we have no frame_size, feed the encoder all the data and expect a fixed
|
|
|
|
* output size */
|
2010-10-05 17:22:28 +00:00
|
|
|
int coded_bps = av_get_bits_per_sample (oclass->in_plugin->id);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegaudenc, "coded bps %d, osize %d", coded_bps, osize);
|
2009-05-12 23:04:30 +00:00
|
|
|
|
|
|
|
out_size = size / osize;
|
|
|
|
if (coded_bps)
|
2010-10-05 17:22:28 +00:00
|
|
|
out_size = (out_size * coded_bps) / 8;
|
2009-10-01 14:44:22 +00:00
|
|
|
|
2012-01-24 13:40:37 +00:00
|
|
|
gst_buffer_map (inbuf, &map, GST_MAP_READ);
|
|
|
|
in_data = map.data;
|
|
|
|
size = map.size;
|
2012-04-07 09:14:45 +00:00
|
|
|
ret = gst_ffmpegaudenc_encode_audio (ffmpegaudenc, in_data, size, out_size,
|
2009-05-13 21:18:50 +00:00
|
|
|
timestamp, duration, discont);
|
2012-01-24 13:40:37 +00:00
|
|
|
gst_buffer_unmap (inbuf, &map);
|
2009-05-13 21:18:50 +00:00
|
|
|
gst_buffer_unref (inbuf);
|
|
|
|
|
2009-05-12 23:04:30 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto push_failed;
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
}
|
Backport BRANCH-THREADED to HEAD, fix a bit.
Original commit message from CVS:
* configure.ac:
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpeg.c: (plugin_init):
* ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_caps_with_codecid):
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_class_init),
(gst_ffmpegdec_init), (gst_ffmpegdec_query), (gst_ffmpegdec_event),
(gst_ffmpegdec_open), (gst_ffmpegdec_setcaps),
(gst_ffmpegdec_get_buffer), (gst_ffmpegdec_negotiate),
(gst_ffmpegdec_frame), (gst_ffmpegdec_sink_event),
(gst_ffmpegdec_chain), (gst_ffmpegdec_change_state),
(gst_ffmpegdec_register):
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_getcaps),
(gst_ffmpegenc_setcaps), (gst_ffmpegenc_chain_video),
(gst_ffmpegenc_chain_audio):
* ext/libpostproc/Makefile.am:
Backport BRANCH-THREADED to HEAD, fix a bit.
2005-08-05 15:29:56 +00:00
|
|
|
|
2009-05-12 23:04:30 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2011-06-30 07:18:42 +00:00
|
|
|
not_negotiated:
|
|
|
|
{
|
2012-06-14 10:41:34 +00:00
|
|
|
GST_ELEMENT_ERROR (ffmpegaudenc, CORE, NEGOTIATION, (NULL),
|
2011-06-30 07:18:42 +00:00
|
|
|
("not configured to input format before data start"));
|
|
|
|
gst_buffer_unref (inbuf);
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
2009-05-12 23:04:30 +00:00
|
|
|
push_failed:
|
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to push buffer %d (%s)", ret,
|
2009-05-12 23:04:30 +00:00
|
|
|
gst_flow_get_name (ret));
|
|
|
|
return ret;
|
|
|
|
}
|
Several encoding changes: for video, double check the pix_fmt after opening the AVCodec. The pix_fmt will be changed ...
Original commit message from CVS:
Several encoding changes:
* for video, double check the pix_fmt after opening the AVCodec. The pix_fmt
will be changed to the preferred pix_fmt instead of that opening the
codec fails. We fail when it has changed (then, ffmpeg doesn't like it).
* for video, set the correct timestamp.
* for audio, do *not* set the frame_size: most codecs don't like it. Instead,
keep a cache of buffers and always give data of size "frame_size". Maybe
I should have used bytestream here, I'm not sure. This works, though.
I can now create mpeg1 video, mp2 and ac3 audio. I didn't test any others yet.
I also didn't start working on integration with any of the muxers yet, that's
all one big TODO. One thing at a time, please. :).
2003-11-12 10:42:36 +00:00
|
|
|
}
|
|
|
|
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
static gboolean
|
2012-06-14 10:41:34 +00:00
|
|
|
gst_ffmpegaudenc_event_sink (GstPad * pad, GstObject * parent, GstEvent * event)
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
{
|
2012-06-14 10:41:34 +00:00
|
|
|
GstFFMpegAudEnc *ffmpegaudenc = (GstFFMpegAudEnc *) parent;
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-11-15 15:35:17 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
2011-06-08 16:04:07 +00:00
|
|
|
GstCaps *caps;
|
2011-06-30 07:20:11 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2011-06-08 16:04:07 +00:00
|
|
|
gst_event_parse_caps (event, &caps);
|
2012-06-14 10:41:34 +00:00
|
|
|
ret = gst_ffmpegaudenc_setcaps (ffmpegaudenc, caps);
|
2011-06-30 07:20:11 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
return ret;
|
2011-06-08 16:04:07 +00:00
|
|
|
}
|
ext/ffmpeg/: Added helper object to handle extra properties.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* ext/ffmpeg/Makefile.am:
* ext/ffmpeg/gstffmpegcfg.c: (gst_ffmpeg_pass_get_type),
(gst_ffmpeg_lim_pass_get_type), (gst_ffmpeg_mb_decision_get_type),
(gst_ffmpeg_mb_cmp_get_type), (gst_ffmpeg_dct_algo_get_type),
(gst_ffmpeg_idct_algo_get_type), (gst_ffmpeg_quant_type_get_type),
(gst_ffmpeg_pre_me_get_type), (gst_ffmpeg_pred_method_get_type),
(gst_ffmpeg_flags_get_type), (gst_ffmpeg_cfg_init),
(gst_ffmpeg_cfg_codec_has_pspec),
(gst_ffmpeg_cfg_install_property), (gst_ffmpeg_cfg_set_property),
(gst_ffmpeg_cfg_get_property), (gst_ffmpeg_cfg_set_defaults),
(gst_ffmpeg_cfg_fill_context):
* ext/ffmpeg/gstffmpegcfg.h:
Added helper object to handle extra properties.
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_class_init),
(gst_ffmpegenc_init), (gst_ffmpegenc_dispose),
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
(gst_ffmpegenc_chain_video), (gst_ffmpegenc_chain_audio),
(gst_ffmpegenc_flush_buffers), (gst_ffmpegenc_event_video),
(gst_ffmpegenc_set_property), (gst_ffmpegenc_get_property),
(gst_ffmpegenc_change_state), (gst_ffmpegenc_register):
* ext/ffmpeg/gstffmpegenc.h:
Exposes (quite some of) the AVCodecContext configurable
settings, as well as some additional (though simple) logic for b-frame
delay handling.
Most of the properties are only enabled for mpeg4-like codecs.
Fixes #344583.
2006-09-06 14:51:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-14 10:41:34 +00:00
|
|
|
return gst_pad_event_default (pad, parent, event);
|
2009-03-25 11:51:55 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 15:35:17 +00:00
|
|
|
static gboolean
|
2012-06-14 10:41:34 +00:00
|
|
|
gst_ffmpegaudenc_query_sink (GstPad * pad, GstObject * parent, GstQuery * query)
|
2011-11-15 15:35:17 +00:00
|
|
|
{
|
2012-06-14 10:41:34 +00:00
|
|
|
GstFFMpegAudEnc *ffmpegaudenc = (GstFFMpegAudEnc *) parent;
|
2011-11-15 15:35:17 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *filter, *caps;
|
|
|
|
|
|
|
|
gst_query_parse_caps (query, &filter);
|
2012-06-14 10:41:34 +00:00
|
|
|
caps = gst_ffmpegaudenc_getcaps (ffmpegaudenc, filter);
|
2011-11-15 15:35:17 +00:00
|
|
|
gst_query_set_caps_result (query, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2011-11-16 16:29:22 +00:00
|
|
|
res = gst_pad_query_default (pad, parent, query);
|
2011-11-15 15:35:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-12-23 13:25:04 +00:00
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_set_property (GObject * object,
|
2004-03-29 16:39:18 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
2001-12-23 13:25:04 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegAudEnc *ffmpegaudenc;
|
2001-12-23 13:25:04 +00:00
|
|
|
|
|
|
|
/* Get a pointer of the right type. */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc = (GstFFMpegAudEnc *) (object);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
if (ffmpegaudenc->opened) {
|
|
|
|
GST_WARNING_OBJECT (ffmpegaudenc,
|
2009-04-21 16:38:03 +00:00
|
|
|
"Can't change properties once decoder is setup !");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-23 13:25:04 +00:00
|
|
|
/* Check the argument id to see which argument we're setting. */
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_BIT_RATE:
|
2012-06-14 10:41:34 +00:00
|
|
|
ffmpegaudenc->bitrate = g_value_get_int (value);
|
2003-06-07 20:46:24 +00:00
|
|
|
break;
|
2009-10-08 11:52:22 +00:00
|
|
|
case ARG_BUFSIZE:
|
|
|
|
break;
|
2005-11-28 17:12:13 +00:00
|
|
|
case ARG_RTP_PAYLOAD_SIZE:
|
2012-06-14 10:41:34 +00:00
|
|
|
ffmpegaudenc->rtp_payload_size = g_value_get_int (value);
|
2005-11-28 17:12:13 +00:00
|
|
|
break;
|
2001-12-23 13:25:04 +00:00
|
|
|
default:
|
2012-04-07 09:14:45 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-23 13:25:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The set function is simply the inverse of the get fuction. */
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_get_property (GObject * object,
|
2004-03-29 16:39:18 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
2001-12-23 13:25:04 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegAudEnc *ffmpegaudenc;
|
2001-12-23 13:25:04 +00:00
|
|
|
|
|
|
|
/* It's not null if we got it, but it might not be ours */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegaudenc = (GstFFMpegAudEnc *) (object);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_BIT_RATE:
|
2012-06-14 10:41:34 +00:00
|
|
|
g_value_set_int (value, ffmpegaudenc->bitrate);
|
2001-12-23 13:25:04 +00:00
|
|
|
break;
|
2003-06-07 20:46:24 +00:00
|
|
|
break;
|
|
|
|
case ARG_BUFSIZE:
|
2012-06-14 10:41:34 +00:00
|
|
|
g_value_set_int (value, ffmpegaudenc->buffer_size);
|
2001-12-23 13:25:04 +00:00
|
|
|
break;
|
2005-11-28 17:12:13 +00:00
|
|
|
case ARG_RTP_PAYLOAD_SIZE:
|
2012-06-14 10:41:34 +00:00
|
|
|
g_value_set_int (value, ffmpegaudenc->rtp_payload_size);
|
2005-11-28 17:12:13 +00:00
|
|
|
break;
|
2001-12-23 13:25:04 +00:00
|
|
|
default:
|
2012-04-07 09:14:45 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-23 13:25:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-05 14:06:29 +00:00
|
|
|
static GstStateChangeReturn
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_change_state (GstElement * element, GstStateChange transition)
|
2003-06-07 20:46:24 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegAudEnc *ffmpegaudenc = (GstFFMpegAudEnc *) element;
|
2005-09-05 14:06:29 +00:00
|
|
|
GstStateChangeReturn result;
|
2005-08-19 15:23:39 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-09-05 14:06:29 +00:00
|
|
|
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2003-06-07 20:46:24 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-05 14:06:29 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2012-04-07 09:14:45 +00:00
|
|
|
if (ffmpegaudenc->opened) {
|
|
|
|
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
|
|
|
ffmpegaudenc->opened = FALSE;
|
2007-06-22 12:13:18 +00:00
|
|
|
}
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_adapter_clear (ffmpegaudenc->adapter);
|
2003-06-07 20:46:24 +00:00
|
|
|
break;
|
2005-08-19 15:23:39 +00:00
|
|
|
default:
|
|
|
|
break;
|
2003-06-07 20:46:24 +00:00
|
|
|
}
|
2005-08-19 15:23:39 +00:00
|
|
|
return result;
|
2003-06-07 20:46:24 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 13:25:04 +00:00
|
|
|
gboolean
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegaudenc_register (GstPlugin * plugin)
|
2001-12-23 13:25:04 +00:00
|
|
|
{
|
|
|
|
GTypeInfo typeinfo = {
|
2012-04-07 09:14:45 +00:00
|
|
|
sizeof (GstFFMpegAudEncClass),
|
|
|
|
(GBaseInitFunc) gst_ffmpegaudenc_base_init,
|
2001-12-23 13:25:04 +00:00
|
|
|
NULL,
|
2012-04-07 09:14:45 +00:00
|
|
|
(GClassInitFunc) gst_ffmpegaudenc_class_init,
|
2001-12-23 13:25:04 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2012-04-07 09:14:45 +00:00
|
|
|
sizeof (GstFFMpegAudEnc),
|
2001-12-23 13:25:04 +00:00
|
|
|
0,
|
2012-04-07 09:14:45 +00:00
|
|
|
(GInstanceInitFunc) gst_ffmpegaudenc_init,
|
2001-12-23 13:25:04 +00:00
|
|
|
};
|
|
|
|
GType type;
|
|
|
|
AVCodec *in_plugin;
|
2004-03-29 16:39:18 +00:00
|
|
|
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2007-12-17 12:43:06 +00:00
|
|
|
GST_LOG ("Registering encoders");
|
|
|
|
|
2008-10-30 12:05:45 +00:00
|
|
|
in_plugin = av_codec_next (NULL);
|
2001-12-23 13:25:04 +00:00
|
|
|
while (in_plugin) {
|
|
|
|
gchar *type_name;
|
|
|
|
|
2011-01-03 10:45:04 +00:00
|
|
|
/* Skip non-AV codecs */
|
2012-04-07 09:14:45 +00:00
|
|
|
if (in_plugin->type != AVMEDIA_TYPE_AUDIO)
|
2011-01-03 10:45:04 +00:00
|
|
|
goto next;
|
|
|
|
|
2003-06-17 11:44:38 +00:00
|
|
|
/* no quasi codecs, please */
|
2012-06-14 10:41:34 +00:00
|
|
|
if ((in_plugin->id >= CODEC_ID_PCM_S16LE &&
|
2010-05-31 16:44:02 +00:00
|
|
|
in_plugin->id <= CODEC_ID_PCM_BLURAY)) {
|
2003-06-17 11:44:38 +00:00
|
|
|
goto next;
|
2009-03-10 20:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No encoders depending on external libraries (we don't build them, but
|
|
|
|
* people who build against an external ffmpeg might have them.
|
|
|
|
* We have native gstreamer plugins for all of those libraries anyway. */
|
|
|
|
if (!strncmp (in_plugin->name, "lib", 3)) {
|
|
|
|
GST_DEBUG
|
|
|
|
("Not using external library encoder %s. Use the gstreamer-native ones instead.",
|
|
|
|
in_plugin->name);
|
|
|
|
goto next;
|
2001-12-23 13:25:04 +00:00
|
|
|
}
|
2003-06-17 11:44:38 +00:00
|
|
|
|
|
|
|
/* only encoders */
|
|
|
|
if (!in_plugin->encode) {
|
2001-12-23 13:25:04 +00:00
|
|
|
goto next;
|
|
|
|
}
|
2003-06-07 20:46:24 +00:00
|
|
|
|
2009-11-02 07:43:17 +00:00
|
|
|
/* FIXME : We should have a method to know cheaply whether we have a mapping
|
|
|
|
* for the given plugin or not */
|
|
|
|
|
2008-10-30 12:05:45 +00:00
|
|
|
GST_DEBUG ("Trying plugin %s [%s]", in_plugin->name, in_plugin->long_name);
|
2008-06-13 17:06:55 +00:00
|
|
|
|
2007-12-17 12:43:06 +00:00
|
|
|
/* no codecs for which we're GUARANTEED to have better alternatives */
|
2012-06-14 10:41:34 +00:00
|
|
|
if (!strcmp (in_plugin->name, "vorbis")
|
|
|
|
|| !strcmp (in_plugin->name, "flac")) {
|
2007-12-17 12:43:06 +00:00
|
|
|
GST_LOG ("Ignoring encoder %s", in_plugin->name);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2002-03-19 04:09:41 +00:00
|
|
|
/* construct the type */
|
2012-04-12 17:41:52 +00:00
|
|
|
type_name = g_strdup_printf ("avenc_%s", in_plugin->name);
|
2001-12-23 13:25:04 +00:00
|
|
|
|
2009-06-05 11:19:03 +00:00
|
|
|
type = g_type_from_name (type_name);
|
|
|
|
|
|
|
|
if (!type) {
|
|
|
|
|
|
|
|
/* create the glib type now */
|
|
|
|
type = g_type_register_static (GST_TYPE_ELEMENT, type_name, &typeinfo, 0);
|
2009-11-02 07:43:17 +00:00
|
|
|
g_type_set_qdata (type, GST_FFENC_PARAMS_QDATA, (gpointer) in_plugin);
|
2009-06-05 11:19:03 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
static const GInterfaceInfo preset_info = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
g_type_add_interface_static (type, GST_TYPE_PRESET, &preset_info);
|
|
|
|
}
|
2009-05-04 11:00:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 16:36:48 +00:00
|
|
|
if (!gst_element_register (plugin, type_name, GST_RANK_SECONDARY, type)) {
|
2004-02-02 20:27:13 +00:00
|
|
|
g_free (type_name);
|
2003-11-02 19:07:41 +00:00
|
|
|
return FALSE;
|
2004-02-02 20:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (type_name);
|
2003-11-02 19:07:41 +00:00
|
|
|
|
2004-03-29 16:39:18 +00:00
|
|
|
next:
|
2008-10-30 12:05:45 +00:00
|
|
|
in_plugin = av_codec_next (in_plugin);
|
2001-12-23 13:25:04 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 12:43:06 +00:00
|
|
|
GST_LOG ("Finished registering encoders");
|
|
|
|
|
2001-12-23 13:25:04 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|