2003-11-22 12:25:48 +00:00
|
|
|
/* GStreamer FAAC (Free AAC Encoder) plugin
|
|
|
|
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstfaac.h"
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/mpeg, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"mpegversion = (int) { 4, 2 }, "
|
|
|
|
"channels = (int) [ 1, 6 ], " "rate = (int) [ 8000, 96000 ]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, " "endianness = (int) BYTE_ORDER, " "signed = (boolean) TRUE, " "width = (int) 16, " "depth = (int) 16, " "rate = (int) [ 8000, 96000 ], " "channels = (int) [ 1, 6]; " "audio/x-raw-int, " "endianness = (int) BYTE_ORDER, " "signed = (boolean) TRUE, " "width = (int) 32, " "depth = (int) 24, " "rate = (int) [ 8000, 96000], " "channels = (int) [ 1, 6]; " "audio/x-raw-float, " "endianness = (int) BYTE_ORDER, " "depth = (int) 32, " /* sizeof (gfloat) */
|
|
|
|
"rate = (int) [ 8000, 96000], " "channels = (int) [ 1, 6]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2003-11-22 12:25:48 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_BITRATE,
|
|
|
|
ARG_PROFILE,
|
|
|
|
ARG_TNS,
|
|
|
|
ARG_MIDSIDE,
|
|
|
|
ARG_SHORTCTL
|
2004-03-14 22:34:33 +00:00
|
|
|
/* FILL ME */
|
2003-11-22 12:25:48 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_faac_base_init (GstFaacClass * klass);
|
|
|
|
static void gst_faac_class_init (GstFaacClass * klass);
|
|
|
|
static void gst_faac_init (GstFaac * faac);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_faac_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_faac_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_sinkconnect (GstPad * pad, const GstCaps * caps);
|
2003-11-22 12:25:48 +00:00
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_srcconnect (GstPad * pad, const GstCaps * caps);
|
|
|
|
static void gst_faac_chain (GstPad * pad, GstData * data);
|
|
|
|
static GstElementStateReturn gst_faac_change_state (GstElement * element);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
/* static guint gst_faac_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_faac_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gst_faac_type = 0;
|
|
|
|
|
|
|
|
if (!gst_faac_type) {
|
|
|
|
static const GTypeInfo gst_faac_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstFaacClass),
|
2003-11-22 12:25:48 +00:00
|
|
|
(GBaseInitFunc) gst_faac_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_faac_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstFaac),
|
2003-11-22 12:25:48 +00:00
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_faac_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
gst_faac_type = g_type_register_static (GST_TYPE_ELEMENT,
|
2004-03-15 19:32:27 +00:00
|
|
|
"GstFaac", &gst_faac_info, 0);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gst_faac_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_base_init (GstFaacClass * klass)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstElementDetails gst_faac_details = {
|
|
|
|
"Free AAC Encoder (FAAC)",
|
|
|
|
"Codec/Audio/Encoder",
|
|
|
|
"Free MPEG-2/4 AAC encoder",
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>",
|
|
|
|
};
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&src_template));
|
2003-11-22 12:25:48 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&sink_template));
|
2003-11-22 12:25:48 +00:00
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_faac_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_TYPE_FAAC_PROFILE (gst_faac_profile_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_faac_profile_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gst_faac_profile_type = 0;
|
|
|
|
|
|
|
|
if (!gst_faac_profile_type) {
|
|
|
|
static GEnumValue gst_faac_profile[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
{MAIN, "MAIN", "Main profile"},
|
|
|
|
{LOW, "LOW", "Low complexity profile"},
|
|
|
|
{SSR, "SSR", "Scalable sampling rate profile"},
|
|
|
|
{LTP, "LTP", "Long term prediction profile"},
|
|
|
|
{0, NULL, NULL},
|
2003-11-22 12:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gst_faac_profile_type = g_enum_register_static ("GstFaacProfile",
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_faac_profile);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gst_faac_profile_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_TYPE_FAAC_SHORTCTL (gst_faac_shortctl_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_faac_shortctl_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gst_faac_shortctl_type = 0;
|
|
|
|
|
|
|
|
if (!gst_faac_shortctl_type) {
|
|
|
|
static GEnumValue gst_faac_shortctl[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
{SHORTCTL_NORMAL, "SHORTCTL_NORMAL", "Normal block type"},
|
|
|
|
{SHORTCTL_NOSHORT, "SHORTCTL_NOSHORT", "No short blocks"},
|
|
|
|
{SHORTCTL_NOLONG, "SHORTCTL_NOLONG", "No long blocks"},
|
|
|
|
{0, NULL, NULL},
|
2003-11-22 12:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gst_faac_shortctl_type = g_enum_register_static ("GstFaacShortCtl",
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_faac_shortctl);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gst_faac_shortctl_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_class_init (GstFaacClass * klass)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
g_object_class_install_property (gobject_class, ARG_BITRATE,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_int ("bitrate", "Bitrate (bps)", "Bitrate in bits/sec",
|
2004-03-15 19:32:27 +00:00
|
|
|
8 * 1024, 320 * 1024, 128 * 1024, G_PARAM_READWRITE));
|
2003-11-22 12:25:48 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_PROFILE,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_enum ("profile", "Profile", "MPEG/AAC encoding profile",
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_FAAC_PROFILE, MAIN, G_PARAM_READWRITE));
|
2003-11-22 12:25:48 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_TNS,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_boolean ("tns", "TNS", "Use temporal noise shaping",
|
2004-03-15 19:32:27 +00:00
|
|
|
FALSE, G_PARAM_READWRITE));
|
2003-11-22 12:25:48 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_MIDSIDE,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_boolean ("midside", "Midside", "Allow mid/side encoding",
|
2004-03-15 19:32:27 +00:00
|
|
|
TRUE, G_PARAM_READWRITE));
|
2003-11-22 12:25:48 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_SHORTCTL,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_enum ("shortctl", "Block type",
|
2004-03-15 19:32:27 +00:00
|
|
|
"Block type encorcing",
|
|
|
|
GST_TYPE_FAAC_SHORTCTL, MAIN, G_PARAM_READWRITE));
|
2003-11-22 12:25:48 +00:00
|
|
|
|
|
|
|
/* virtual functions */
|
|
|
|
gstelement_class->change_state = gst_faac_change_state;
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_faac_set_property;
|
|
|
|
gobject_class->get_property = gst_faac_get_property;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_init (GstFaac * faac)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
faac->handle = NULL;
|
|
|
|
faac->samplerate = -1;
|
|
|
|
faac->channels = -1;
|
|
|
|
faac->cache = NULL;
|
|
|
|
faac->cache_time = GST_CLOCK_TIME_NONE;
|
|
|
|
faac->cache_duration = 0;
|
|
|
|
|
|
|
|
GST_FLAG_SET (faac, GST_ELEMENT_EVENT_AWARE);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
faac->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
|
|
|
|
"sink");
|
2003-11-22 12:25:48 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (faac), faac->sinkpad);
|
|
|
|
gst_pad_set_chain_function (faac->sinkpad, gst_faac_chain);
|
|
|
|
gst_pad_set_link_function (faac->sinkpad, gst_faac_sinkconnect);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
faac->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
|
|
|
|
"src");
|
2003-11-22 12:25:48 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (faac), faac->srcpad);
|
|
|
|
gst_pad_set_link_function (faac->srcpad, gst_faac_srcconnect);
|
|
|
|
|
|
|
|
/* default properties */
|
|
|
|
faac->bitrate = 1024 * 128;
|
|
|
|
faac->profile = MAIN;
|
|
|
|
faac->shortctl = SHORTCTL_NORMAL;
|
|
|
|
faac->tns = FALSE;
|
|
|
|
faac->midside = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_sinkconnect (GstPad * pad, const GstCaps * caps)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad));
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
|
|
|
faacEncHandle *handle;
|
|
|
|
gint channels, samplerate, depth;
|
|
|
|
gulong samples, bytes, fmt = 0, bps = 0;
|
2003-11-22 12:25:48 +00:00
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
if (!gst_caps_is_fixed (caps))
|
2003-11-22 12:25:48 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
|
|
|
|
|
|
|
if (faac->handle) {
|
|
|
|
faacEncClose (faac->handle);
|
|
|
|
faac->handle = NULL;
|
|
|
|
}
|
|
|
|
if (faac->cache) {
|
|
|
|
gst_buffer_unref (faac->cache);
|
|
|
|
faac->cache = NULL;
|
|
|
|
}
|
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
gst_structure_get_int (structure, "channels", &channels);
|
|
|
|
gst_structure_get_int (structure, "rate", &samplerate);
|
|
|
|
gst_structure_get_int (structure, "depth", &depth);
|
|
|
|
|
|
|
|
/* open a new handle to the encoder */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!(handle = faacEncOpen (samplerate, channels, &samples, &bytes)))
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
|
|
|
|
switch (depth) {
|
|
|
|
case 16:
|
|
|
|
fmt = FAAC_INPUT_16BIT;
|
|
|
|
bps = 2;
|
|
|
|
break;
|
|
|
|
case 24:
|
2004-03-15 19:32:27 +00:00
|
|
|
fmt = FAAC_INPUT_32BIT; /* 24-in-32, actually */
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
bps = 4;
|
|
|
|
break;
|
|
|
|
case 32:
|
2004-03-15 19:32:27 +00:00
|
|
|
fmt = FAAC_INPUT_FLOAT; /* see template, this is right */
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
bps = 4;
|
|
|
|
break;
|
|
|
|
}
|
2003-11-22 12:25:48 +00:00
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
if (!fmt) {
|
|
|
|
faacEncClose (handle);
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
faac->format = fmt;
|
|
|
|
faac->bps = bps;
|
|
|
|
faac->handle = handle;
|
|
|
|
faac->bytes = bytes;
|
|
|
|
faac->samples = samples;
|
|
|
|
faac->channels = channels;
|
|
|
|
faac->samplerate = samplerate;
|
|
|
|
|
|
|
|
/* if the other side was already set-up, redo that */
|
|
|
|
if (GST_PAD_CAPS (faac->srcpad))
|
|
|
|
return gst_faac_srcconnect (faac->srcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_pad_get_allowed_caps (faac->srcpad));
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
|
|
|
|
/* else, that'll be done later */
|
|
|
|
return GST_PAD_LINK_OK;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_srcconnect (GstPad * pad, const GstCaps * caps)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad));
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
gint n;
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!faac->handle || (faac->samplerate == -1 || faac->channels == -1)) {
|
2003-11-22 12:25:48 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we do samplerate/channels ourselves */
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
for (n = 0; n < gst_caps_get_size (caps); n++) {
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, n);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
gst_structure_remove_field (structure, "rate");
|
|
|
|
gst_structure_remove_field (structure, "channels");
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* go through list */
|
|
|
|
caps = gst_caps_normalize (caps);
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
for (n = 0; n < gst_caps_get_size (caps); n++) {
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, n);
|
2003-11-22 12:25:48 +00:00
|
|
|
faacEncConfiguration *conf;
|
|
|
|
gint mpegversion = 0;
|
|
|
|
GstCaps *newcaps;
|
|
|
|
GstPadLinkReturn ret;
|
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
gst_structure_get_int (structure, "mpegversion", &mpegversion);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
|
|
|
/* new conf */
|
|
|
|
conf = faacEncGetCurrentConfiguration (faac->handle);
|
|
|
|
conf->mpegVersion = (mpegversion == 4) ? MPEG4 : MPEG2;
|
|
|
|
conf->aacObjectType = faac->profile;
|
|
|
|
conf->allowMidside = faac->midside;
|
|
|
|
conf->useLfe = 0;
|
|
|
|
conf->useTns = faac->tns;
|
|
|
|
conf->bitRate = faac->bitrate;
|
|
|
|
conf->inputFormat = faac->format;
|
|
|
|
|
|
|
|
/* FIXME: this one here means that we do not support direct
|
|
|
|
* "MPEG audio file" output (like mp3). This means we can
|
|
|
|
* only mux this into mov/qt (mp4a) or matroska or so. If
|
|
|
|
* we want to support direct AAC file output, we need ADTS
|
|
|
|
* headers, and we need to find a way in the caps to detect
|
|
|
|
* that (that the next element is filesink or any element
|
|
|
|
* that does want ADTS headers). */
|
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
conf->outputFormat = 0; /* raw, no ADTS headers */
|
2003-11-22 12:25:48 +00:00
|
|
|
conf->shortctl = faac->shortctl;
|
|
|
|
if (!faacEncSetConfiguration (faac->handle, conf)) {
|
|
|
|
GST_WARNING ("Faac doesn't support the current conf");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
newcaps = gst_caps_new_simple ("audio/mpeg",
|
2004-03-15 19:32:27 +00:00
|
|
|
"mpegversion", G_TYPE_INT, mpegversion,
|
|
|
|
"channels", G_TYPE_INT, faac->channels,
|
|
|
|
"rate", G_TYPE_INT, faac->samplerate, NULL);
|
2003-11-22 12:25:48 +00:00
|
|
|
ret = gst_pad_try_set_caps (faac->srcpad, newcaps);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case GST_PAD_LINK_OK:
|
|
|
|
case GST_PAD_LINK_DONE:
|
2004-03-15 19:32:27 +00:00
|
|
|
return GST_PAD_LINK_DONE;
|
2003-11-22 12:25:48 +00:00
|
|
|
case GST_PAD_LINK_DELAYED:
|
2004-03-15 19:32:27 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
2003-11-22 12:25:48 +00:00
|
|
|
default:
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_chain (GstPad * pad, GstData * data)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad));
|
|
|
|
GstBuffer *inbuf, *outbuf, *subbuf;
|
|
|
|
guint size, ret_size, in_size, frame_size;
|
|
|
|
|
|
|
|
if (GST_IS_EVENT (data)) {
|
|
|
|
GstEvent *event = GST_EVENT (data);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_EOS:
|
2004-03-15 19:32:27 +00:00
|
|
|
/* flush first */
|
|
|
|
while (1) {
|
|
|
|
outbuf = gst_buffer_new_and_alloc (faac->bytes);
|
|
|
|
if ((ret_size = faacEncEncode (faac->handle,
|
|
|
|
NULL, 0, GST_BUFFER_DATA (outbuf), faac->bytes)) < 0) {
|
|
|
|
GST_ELEMENT_ERROR (faac, LIBRARY, ENCODE, (NULL), (NULL));
|
|
|
|
gst_event_unref (event);
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret_size > 0) {
|
|
|
|
GST_BUFFER_SIZE (outbuf) = ret_size;
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = 0;
|
|
|
|
GST_BUFFER_DURATION (outbuf) = 0;
|
|
|
|
gst_pad_push (faac->srcpad, GST_DATA (outbuf));
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_eos (GST_ELEMENT (faac));
|
|
|
|
gst_pad_push (faac->srcpad, data);
|
|
|
|
return;
|
2003-11-22 12:25:48 +00:00
|
|
|
default:
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_pad_event_default (pad, event);
|
|
|
|
return;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inbuf = GST_BUFFER (data);
|
|
|
|
|
|
|
|
if (!faac->handle) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (faac, CORE, NEGOTIATION, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("format wasn't negotiated before chain function"));
|
2003-11-22 12:25:48 +00:00
|
|
|
gst_buffer_unref (inbuf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GST_PAD_CAPS (faac->srcpad)) {
|
|
|
|
if (gst_faac_srcconnect (faac->srcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_pad_get_allowed_caps (faac->srcpad)) <= 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (faac, CORE, NEGOTIATION, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("failed to negotiate MPEG/AAC format with next element"));
|
2003-11-22 12:25:48 +00:00
|
|
|
gst_buffer_unref (inbuf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size = GST_BUFFER_SIZE (inbuf);
|
|
|
|
in_size = size;
|
|
|
|
if (faac->cache)
|
|
|
|
in_size += GST_BUFFER_SIZE (faac->cache);
|
|
|
|
frame_size = faac->samples * faac->bps;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/* do we have enough data for one frame? */
|
|
|
|
if (in_size / faac->bps < faac->samples) {
|
|
|
|
if (in_size > size) {
|
2004-03-15 19:32:27 +00:00
|
|
|
GstBuffer *merge;
|
|
|
|
|
|
|
|
/* this is panic! we got a buffer, but still don't have enough
|
|
|
|
* data. Merge them and retry in the next cycle... */
|
|
|
|
merge = gst_buffer_merge (faac->cache, inbuf);
|
|
|
|
gst_buffer_unref (faac->cache);
|
|
|
|
gst_buffer_unref (inbuf);
|
|
|
|
faac->cache = merge;
|
2003-11-22 12:25:48 +00:00
|
|
|
} else if (in_size == size) {
|
2004-03-15 19:32:27 +00:00
|
|
|
/* this shouldn't happen, but still... */
|
|
|
|
faac->cache = inbuf;
|
2003-11-22 12:25:48 +00:00
|
|
|
} else if (in_size > 0) {
|
2004-03-15 19:32:27 +00:00
|
|
|
faac->cache = gst_buffer_create_sub (inbuf, size - in_size, in_size);
|
|
|
|
GST_BUFFER_DURATION (faac->cache) =
|
|
|
|
GST_BUFFER_DURATION (inbuf) * GST_BUFFER_SIZE (faac->cache) / size;
|
|
|
|
GST_BUFFER_TIMESTAMP (faac->cache) =
|
|
|
|
GST_BUFFER_TIMESTAMP (inbuf) + (GST_BUFFER_DURATION (inbuf) *
|
|
|
|
(size - in_size) / size);
|
|
|
|
gst_buffer_unref (inbuf);
|
2003-11-22 12:25:48 +00:00
|
|
|
} else {
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_buffer_unref (inbuf);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the frame */
|
|
|
|
if (in_size > size) {
|
2004-03-06 20:56:28 +00:00
|
|
|
GstBuffer *merge;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
/* merge */
|
|
|
|
subbuf = gst_buffer_create_sub (inbuf, 0, frame_size - (in_size - size));
|
|
|
|
GST_BUFFER_DURATION (subbuf) =
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_DURATION (inbuf) * GST_BUFFER_SIZE (subbuf) / size;
|
2004-03-06 20:56:28 +00:00
|
|
|
merge = gst_buffer_merge (faac->cache, subbuf);
|
|
|
|
gst_buffer_unref (faac->cache);
|
|
|
|
gst_buffer_unref (subbuf);
|
|
|
|
subbuf = merge;
|
2003-11-22 12:25:48 +00:00
|
|
|
faac->cache = NULL;
|
|
|
|
} else {
|
|
|
|
subbuf = gst_buffer_create_sub (inbuf, size - in_size, frame_size);
|
|
|
|
GST_BUFFER_DURATION (subbuf) =
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_DURATION (inbuf) * GST_BUFFER_SIZE (subbuf) / size;
|
2003-11-22 12:25:48 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (subbuf) =
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (inbuf) + (GST_BUFFER_DURATION (inbuf) *
|
|
|
|
(size - in_size) / size);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
outbuf = gst_buffer_new_and_alloc (faac->bytes);
|
|
|
|
if ((ret_size = faacEncEncode (faac->handle,
|
2004-03-15 19:32:27 +00:00
|
|
|
(gint32 *) GST_BUFFER_DATA (subbuf),
|
|
|
|
GST_BUFFER_SIZE (subbuf) / faac->bps,
|
|
|
|
GST_BUFFER_DATA (outbuf), faac->bytes)) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (faac, LIBRARY, ENCODE, (NULL), (NULL));
|
2003-11-22 12:25:48 +00:00
|
|
|
gst_buffer_unref (inbuf);
|
|
|
|
gst_buffer_unref (subbuf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret_size > 0) {
|
|
|
|
GST_BUFFER_SIZE (outbuf) = ret_size;
|
|
|
|
if (faac->cache_time != GST_CLOCK_TIME_NONE) {
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = faac->cache_time;
|
|
|
|
faac->cache_time = GST_CLOCK_TIME_NONE;
|
2003-11-22 12:25:48 +00:00
|
|
|
} else
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (subbuf);
|
2003-11-22 12:25:48 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (subbuf);
|
|
|
|
if (faac->cache_duration) {
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) += faac->cache_duration;
|
|
|
|
faac->cache_duration = 0;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
gst_pad_push (faac->srcpad, GST_DATA (outbuf));
|
|
|
|
} else {
|
|
|
|
/* FIXME: what I'm doing here isn't fully correct, but there
|
|
|
|
* really isn't a better way yet.
|
|
|
|
* Problem is that libfaac caches buffers (for encoding
|
|
|
|
* purposes), so the timestamp of the outgoing buffer isn't
|
|
|
|
* the same as the timestamp of the data that I pushed in.
|
|
|
|
* However, I don't know the delay between those two so I
|
|
|
|
* cannot really say aything about it. This is a bad guess. */
|
|
|
|
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
if (faac->cache_time != GST_CLOCK_TIME_NONE)
|
2004-03-15 19:32:27 +00:00
|
|
|
faac->cache_time = GST_BUFFER_TIMESTAMP (subbuf);
|
2003-11-22 12:25:48 +00:00
|
|
|
faac->cache_duration += GST_BUFFER_DURATION (subbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
in_size -= frame_size;
|
|
|
|
gst_buffer_unref (subbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_BITRATE:
|
|
|
|
faac->bitrate = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_PROFILE:
|
|
|
|
faac->profile = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case ARG_TNS:
|
|
|
|
faac->tns = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_MIDSIDE:
|
|
|
|
faac->midside = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_SHORTCTL:
|
|
|
|
faac->shortctl = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_BITRATE:
|
|
|
|
g_value_set_int (value, faac->bitrate);
|
|
|
|
break;
|
|
|
|
case ARG_PROFILE:
|
|
|
|
g_value_set_enum (value, faac->profile);
|
|
|
|
break;
|
|
|
|
case ARG_TNS:
|
|
|
|
g_value_set_boolean (value, faac->tns);
|
|
|
|
break;
|
|
|
|
case ARG_MIDSIDE:
|
|
|
|
g_value_set_boolean (value, faac->midside);
|
|
|
|
break;
|
|
|
|
case ARG_SHORTCTL:
|
|
|
|
g_value_set_enum (value, faac->shortctl);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_change_state (GstElement * element)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
if (faac->handle) {
|
2004-03-15 19:32:27 +00:00
|
|
|
faacEncClose (faac->handle);
|
|
|
|
faac->handle = NULL;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
if (faac->cache) {
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_buffer_unref (faac->cache);
|
|
|
|
faac->cache = NULL;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
faac->cache_time = GST_CLOCK_TIME_NONE;
|
|
|
|
faac->cache_duration = 0;
|
|
|
|
faac->samplerate = -1;
|
|
|
|
faac->channels = -1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
return gst_element_register (plugin, "faac", GST_RANK_NONE, GST_TYPE_FAAC);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"faac",
|
|
|
|
"Free AAC Encoder (FAAC)",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|