2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-20 22:30:14 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-20 22:30:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-11-02 08:07:22 +00:00
|
|
|
#include <time.h>
|
2001-12-20 22:30:14 +00:00
|
|
|
#include <vorbis/vorbisenc.h>
|
|
|
|
|
2003-11-24 04:08:48 +00:00
|
|
|
#include <gst/gsttaginterface.h>
|
2004-02-22 15:14:25 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2001-12-20 22:30:14 +00:00
|
|
|
#include "vorbisenc.h"
|
|
|
|
|
ext/: remove explicit newmedia support from oggmux and vorbisenc add debug category to vorbisenc
Original commit message from CVS:
2004-09-22 Zaheer Abbas Merali <zaheerabbas at merali dot org>
* ext/ogg/gstoggmux.c: (gst_ogg_mux_init),
(gst_ogg_mux_next_buffer), (gst_ogg_mux_loop):
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_init),
(gst_vorbisenc_chain):
* ext/vorbis/vorbisenc.h:
remove explicit newmedia support from oggmux and vorbisenc
add debug category to vorbisenc
* gst/multifilesink/gstmultifilesink.c:
(gst_multifilesink_class_init), (gst_multifilesink_init),
(gst_multifilesink_dispose), (gst_multifilesink_set_location),
(gst_multifilesink_set_property), (gst_multifilesink_next_file),
(gst_multifilesink_handle_event), (gst_multifilesink_chain),
(plugin_init):
* gst/multifilesink/gstmultifilesink.h:
add support for streamheader in multifilesink
2004-09-22 14:35:13 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (vorbisenc_debug);
|
|
|
|
#define GST_CAT_DEFAULT vorbisenc_debug
|
|
|
|
|
2003-11-02 02:20:36 +00:00
|
|
|
static GstPadTemplate *gst_vorbisenc_src_template, *gst_vorbisenc_sink_template;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
|
|
|
GstElementDetails vorbisenc_details = {
|
|
|
|
"Ogg Vorbis encoder",
|
2003-11-16 22:02:21 +00:00
|
|
|
"Codec/Encoder/Audio",
|
2001-12-20 22:30:14 +00:00
|
|
|
"Encodes audio in OGG Vorbis format",
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
"Monty <monty@xiph.org>, " "Wim Taymans <wim@fluendo.com>",
|
2001-12-20 22:30:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* VorbisEnc signals and args */
|
2001-12-21 01:14:21 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-20 22:30:14 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-12-21 01:14:21 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-20 22:30:14 +00:00
|
|
|
ARG_0,
|
2002-10-20 01:55:28 +00:00
|
|
|
ARG_MAX_BITRATE,
|
2001-12-20 22:30:14 +00:00
|
|
|
ARG_BITRATE,
|
2002-10-20 01:55:28 +00:00
|
|
|
ARG_MIN_BITRATE,
|
|
|
|
ARG_QUALITY,
|
|
|
|
ARG_MANAGED,
|
2004-05-21 23:28:57 +00:00
|
|
|
ARG_LAST_MESSAGE
|
2001-12-20 22:30:14 +00:00
|
|
|
};
|
|
|
|
|
2004-05-12 07:18:03 +00:00
|
|
|
/* FIXME:
|
|
|
|
* vorbis_granule_time was added between 1.0 and 1.0.1; it's too silly
|
|
|
|
* to require a new version for such a simple function, but once we move
|
|
|
|
* beyond 1.0 for other reasons we can remove this copy */
|
|
|
|
|
|
|
|
static double
|
|
|
|
vorbis_granule_time_copy (vorbis_dsp_state * v, ogg_int64_t granulepos)
|
|
|
|
{
|
|
|
|
if (granulepos >= 0)
|
|
|
|
return ((double) granulepos / v->vi->rate);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static const GstFormat *
|
|
|
|
gst_vorbisenc_get_formats (GstPad * pad)
|
2002-10-20 17:11:10 +00:00
|
|
|
{
|
|
|
|
static const GstFormat src_formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
static const GstFormat sink_formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
2003-05-24 10:41:58 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_FORMAT_TIME,
|
2002-10-20 17:11:10 +00:00
|
|
|
0
|
|
|
|
};
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-20 17:11:10 +00:00
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
2002-10-20 17:11:10 +00:00
|
|
|
|
2002-10-20 01:55:28 +00:00
|
|
|
#define MAX_BITRATE_DEFAULT -1
|
|
|
|
#define BITRATE_DEFAULT -1
|
|
|
|
#define MIN_BITRATE_DEFAULT -1
|
|
|
|
#define QUALITY_DEFAULT 0.3
|
2004-10-18 13:55:48 +00:00
|
|
|
#define LOWEST_BITRATE 6000 /* lowest allowed for a 8 kHz stream */
|
|
|
|
#define HIGHEST_BITRATE 250001 /* highest allowed for a 44 kHz stream */
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_vorbisenc_base_init (gpointer g_class);
|
|
|
|
static void gst_vorbisenc_class_init (VorbisEncClass * klass);
|
|
|
|
static void gst_vorbisenc_init (VorbisEnc * vorbisenc);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_vorbisenc_chain (GstPad * pad, GstData * _data);
|
|
|
|
static gboolean gst_vorbisenc_setup (VorbisEnc * vorbisenc);
|
2002-10-20 01:55:28 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_vorbisenc_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_vorbisenc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static GstElementStateReturn gst_vorbisenc_change_state (GstElement * element);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
/*static guint gst_vorbisenc_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
|
|
|
vorbisenc_get_type (void)
|
|
|
|
{
|
|
|
|
static GType vorbisenc_type = 0;
|
|
|
|
|
|
|
|
if (!vorbisenc_type) {
|
|
|
|
static const GTypeInfo vorbisenc_info = {
|
2004-03-14 22:34:34 +00:00
|
|
|
sizeof (VorbisEncClass),
|
2003-11-02 02:20:36 +00:00
|
|
|
gst_vorbisenc_base_init,
|
2001-12-20 22:30:14 +00:00
|
|
|
NULL,
|
2001-12-21 01:14:21 +00:00
|
|
|
(GClassInitFunc) gst_vorbisenc_class_init,
|
2001-12-20 22:30:14 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2001-12-21 01:14:21 +00:00
|
|
|
sizeof (VorbisEnc),
|
2001-12-20 22:30:14 +00:00
|
|
|
0,
|
2001-12-21 01:14:21 +00:00
|
|
|
(GInstanceInitFunc) gst_vorbisenc_init,
|
2001-12-20 22:30:14 +00:00
|
|
|
};
|
2003-11-24 04:08:48 +00:00
|
|
|
static const GInterfaceInfo tag_setter_info = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
vorbisenc_type =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "VorbisEnc", &vorbisenc_info,
|
|
|
|
0);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
g_type_add_interface_static (vorbisenc_type, GST_TYPE_TAG_SETTER,
|
2004-03-15 19:32:28 +00:00
|
|
|
&tag_setter_info);
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
return vorbisenc_type;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstCaps *
|
2003-11-02 02:20:36 +00:00
|
|
|
vorbis_caps_factory (void)
|
|
|
|
{
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
return gst_caps_new_simple ("audio/x-vorbis", NULL);
|
2003-11-02 02:20:36 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstCaps *
|
2003-11-02 02:20:36 +00:00
|
|
|
raw_caps_factory (void)
|
|
|
|
{
|
2004-06-24 15:44:53 +00:00
|
|
|
/* lowest sample rate is in vorbis/lib/modes/setup_8.h, 8000 Hz
|
|
|
|
* highest sample rate is in vorbis/lib/modes/setup_44.h, 50000 Hz */
|
2003-11-02 02:20:36 +00:00
|
|
|
return
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
gst_caps_new_simple ("audio/x-raw-float",
|
2004-06-24 15:44:53 +00:00
|
|
|
"rate", GST_TYPE_INT_RANGE, 8000, 50000,
|
|
|
|
"channels", GST_TYPE_INT_RANGE, 1, 2, NULL,
|
2004-03-14 22:34:34 +00:00
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
2004-06-24 15:44:53 +00:00
|
|
|
"width", G_TYPE_INT, 32, "buffer-frames", G_TYPE_INT, 0);
|
2003-11-02 02:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vorbisenc_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
GstCaps *raw_caps, *vorbis_caps;
|
|
|
|
|
|
|
|
raw_caps = raw_caps_factory ();
|
|
|
|
vorbis_caps = vorbis_caps_factory ();
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS, raw_caps);
|
|
|
|
gst_vorbisenc_src_template = gst_pad_template_new ("src", GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS, vorbis_caps);
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_vorbisenc_sink_template);
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_vorbisenc_src_template);
|
2003-11-02 02:20:36 +00:00
|
|
|
gst_element_class_set_details (element_class, &vorbisenc_details);
|
|
|
|
}
|
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
static void
|
2001-12-21 01:14:21 +00:00
|
|
|
gst_vorbisenc_class_init (VorbisEncClass * klass)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2001-12-21 01:14:21 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_BITRATE,
|
2004-06-24 14:56:21 +00:00
|
|
|
g_param_spec_int ("max-bitrate", "Maximum Bitrate",
|
2004-10-18 13:55:48 +00:00
|
|
|
"Specify a maximum bitrate (in bps). Useful for streaming "
|
|
|
|
"applications. (-1 == disabled)",
|
|
|
|
-1, HIGHEST_BITRATE, MAX_BITRATE_DEFAULT, G_PARAM_READWRITE));
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BITRATE,
|
2004-06-24 14:56:21 +00:00
|
|
|
g_param_spec_int ("bitrate", "Target Bitrate",
|
2004-10-18 13:55:48 +00:00
|
|
|
"Attempt to encode at a bitrate averaging this (in bps). "
|
|
|
|
"This uses the bitrate management engine, and is not recommended for most users. "
|
|
|
|
"Quality is a better alternative. (-1 == disabled)",
|
|
|
|
-1, HIGHEST_BITRATE, BITRATE_DEFAULT, G_PARAM_READWRITE));
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MIN_BITRATE,
|
2004-06-24 14:56:21 +00:00
|
|
|
g_param_spec_int ("min_bitrate", "Minimum Bitrate",
|
2004-10-18 13:55:48 +00:00
|
|
|
"Specify a minimum bitrate (in bps). Useful for encoding for a "
|
|
|
|
"fixed-size channel. (-1 == disabled)",
|
|
|
|
-1, HIGHEST_BITRATE, MIN_BITRATE_DEFAULT, G_PARAM_READWRITE));
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
|
|
|
|
g_param_spec_float ("quality", "Quality",
|
2004-03-15 19:32:28 +00:00
|
|
|
"Specify quality instead of specifying a particular bitrate.",
|
|
|
|
0.0, 1.0, QUALITY_DEFAULT, G_PARAM_READWRITE));
|
2004-03-14 22:34:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MANAGED,
|
|
|
|
g_param_spec_boolean ("managed", "Managed",
|
2004-03-15 19:32:28 +00:00
|
|
|
"Enable bitrate management engine", FALSE, G_PARAM_READWRITE));
|
2002-10-20 01:55:28 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_string ("last-message", "last-message",
|
2004-03-15 19:32:28 +00:00
|
|
|
"The last status message", NULL, G_PARAM_READABLE));
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2001-12-21 01:14:21 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_vorbisenc_set_property;
|
|
|
|
gobject_class->get_property = gst_vorbisenc_get_property;
|
2002-10-19 16:57:08 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_vorbisenc_change_state;
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_vorbisenc_sinkconnect (GstPad * pad, const GstCaps * caps)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
|
|
|
VorbisEnc *vorbisenc;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
|
2004-05-24 19:19:29 +00:00
|
|
|
vorbisenc->setup = FALSE;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_get_int (structure, "channels", &vorbisenc->channels);
|
|
|
|
gst_structure_get_int (structure, "rate", &vorbisenc->frequency);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
gst_vorbisenc_setup (vorbisenc);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
if (vorbisenc->setup)
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 17:11:10 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_convert_src (GstPad * pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2002-10-20 17:11:10 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
VorbisEnc *vorbisenc;
|
|
|
|
gint64 avg;
|
|
|
|
|
|
|
|
vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (vorbisenc->samples_in == 0 ||
|
|
|
|
vorbisenc->bytes_out == 0 || vorbisenc->frequency == 0)
|
2002-10-20 17:11:10 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
avg = (vorbisenc->bytes_out * vorbisenc->frequency) / (vorbisenc->samples_in);
|
2002-10-20 17:11:10 +00:00
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = src_value * GST_SECOND / avg;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * avg / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_convert_sink (GstPad * pad, GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat * dest_format, gint64 * dest_value)
|
2002-10-20 17:11:10 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
guint scale = 1;
|
|
|
|
gint bytes_per_sample;
|
|
|
|
VorbisEnc *vorbisenc;
|
|
|
|
|
|
|
|
vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-20 17:11:10 +00:00
|
|
|
bytes_per_sample = vorbisenc->channels * 2;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-20 17:11:10 +00:00
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
if (bytes_per_sample == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value / bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
gint byterate = bytes_per_sample * vorbisenc->frequency;
|
|
|
|
|
|
|
|
if (byterate == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value * GST_SECOND / byterate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-10-20 17:11:10 +00:00
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
if (vorbisenc->frequency == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value * GST_SECOND / vorbisenc->frequency;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
scale = bytes_per_sample;
|
|
|
|
/* fallthrough */
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_value = src_value * scale * vorbisenc->frequency / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
gst_vorbisenc_get_query_types (GstPad * pad)
|
2002-10-20 17:11:10 +00:00
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType gst_vorbisenc_src_query_types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
2002-10-20 17:11:10 +00:00
|
|
|
0
|
|
|
|
};
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2002-10-20 17:11:10 +00:00
|
|
|
return gst_vorbisenc_src_query_types;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value)
|
2002-10-20 17:11:10 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
VorbisEnc *vorbisenc;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-20 17:11:10 +00:00
|
|
|
vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-10-20 17:11:10 +00:00
|
|
|
{
|
|
|
|
switch (*format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
gint64 peer_value;
|
|
|
|
const GstFormat *peer_formats;
|
|
|
|
|
|
|
|
res = FALSE;
|
|
|
|
|
|
|
|
peer_formats =
|
|
|
|
gst_pad_get_formats (GST_PAD_PEER (vorbisenc->sinkpad));
|
|
|
|
|
|
|
|
while (peer_formats && *peer_formats && !res) {
|
|
|
|
|
|
|
|
GstFormat peer_format = *peer_formats;
|
|
|
|
|
|
|
|
/* do the probe */
|
|
|
|
if (gst_pad_query (GST_PAD_PEER (vorbisenc->sinkpad),
|
|
|
|
GST_QUERY_TOTAL, &peer_format, &peer_value)) {
|
|
|
|
GstFormat conv_format;
|
|
|
|
|
|
|
|
/* convert to TIME */
|
|
|
|
conv_format = GST_FORMAT_TIME;
|
|
|
|
res = gst_pad_convert (vorbisenc->sinkpad,
|
|
|
|
peer_format, peer_value, &conv_format, value);
|
|
|
|
/* and to final format */
|
|
|
|
res &= gst_pad_convert (pad,
|
|
|
|
GST_FORMAT_TIME, *value, format, value);
|
|
|
|
}
|
|
|
|
peer_formats++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-10-20 17:11:10 +00:00
|
|
|
switch (*format) {
|
2004-03-15 19:32:28 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
/* we only know about our samples, convert to requested format */
|
|
|
|
res = gst_pad_convert (pad,
|
|
|
|
GST_FORMAT_BYTES, vorbisenc->bytes_out, format, value);
|
|
|
|
break;
|
|
|
|
}
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
static void
|
2001-12-21 01:14:21 +00:00
|
|
|
gst_vorbisenc_init (VorbisEnc * vorbisenc)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbisenc->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_vorbisenc_sink_template, "sink");
|
2001-12-21 01:14:21 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (vorbisenc), vorbisenc->sinkpad);
|
|
|
|
gst_pad_set_chain_function (vorbisenc->sinkpad, gst_vorbisenc_chain);
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (vorbisenc->sinkpad, gst_vorbisenc_sinkconnect);
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_pad_set_convert_function (vorbisenc->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vorbisenc_convert_sink));
|
|
|
|
gst_pad_set_formats_function (vorbisenc->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vorbisenc_get_formats));
|
|
|
|
|
|
|
|
vorbisenc->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_vorbisenc_src_template, "src");
|
|
|
|
gst_pad_set_query_function (vorbisenc->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vorbisenc_src_query));
|
|
|
|
gst_pad_set_query_type_function (vorbisenc->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vorbisenc_get_query_types));
|
|
|
|
gst_pad_set_convert_function (vorbisenc->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vorbisenc_convert_src));
|
|
|
|
gst_pad_set_formats_function (vorbisenc->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vorbisenc_get_formats));
|
2001-12-21 01:14:21 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (vorbisenc), vorbisenc->srcpad);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2002-10-19 16:57:08 +00:00
|
|
|
vorbisenc->channels = -1;
|
|
|
|
vorbisenc->frequency = -1;
|
2002-10-20 01:55:28 +00:00
|
|
|
|
|
|
|
vorbisenc->managed = FALSE;
|
|
|
|
vorbisenc->max_bitrate = MAX_BITRATE_DEFAULT;
|
|
|
|
vorbisenc->bitrate = BITRATE_DEFAULT;
|
|
|
|
vorbisenc->min_bitrate = MIN_BITRATE_DEFAULT;
|
|
|
|
vorbisenc->quality = QUALITY_DEFAULT;
|
|
|
|
vorbisenc->quality_set = FALSE;
|
|
|
|
vorbisenc->last_message = NULL;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2001-12-21 01:14:21 +00:00
|
|
|
vorbisenc->setup = FALSE;
|
2002-10-19 16:57:08 +00:00
|
|
|
vorbisenc->eos = FALSE;
|
2003-11-24 04:08:48 +00:00
|
|
|
vorbisenc->header_sent = FALSE;
|
2001-12-21 01:14:21 +00:00
|
|
|
|
2003-11-24 04:08:48 +00:00
|
|
|
vorbisenc->tags = gst_tag_list_new ();
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2001-12-21 01:14:21 +00:00
|
|
|
/* we're chained and we can deal with events */
|
|
|
|
GST_FLAG_SET (vorbisenc, GST_ELEMENT_EVENT_AWARE);
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
|
2004-02-22 15:14:25 +00:00
|
|
|
|
|
|
|
static gchar *
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_get_tag_value (const GstTagList * list, const gchar * tag,
|
|
|
|
int index)
|
2004-02-22 15:14:25 +00:00
|
|
|
{
|
|
|
|
gchar *vorbisvalue = NULL;
|
|
|
|
|
|
|
|
if (tag == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get tag name right */
|
2004-03-14 22:34:34 +00:00
|
|
|
if ((strcmp (tag, GST_TAG_TRACK_NUMBER) == 0)
|
|
|
|
|| (strcmp (tag, GST_TAG_ALBUM_VOLUME_NUMBER) == 0)
|
|
|
|
|| (strcmp (tag, GST_TAG_TRACK_COUNT) == 0)
|
2004-02-22 15:14:25 +00:00
|
|
|
|| (strcmp (tag, GST_TAG_ALBUM_VOLUME_COUNT) == 0)) {
|
|
|
|
guint track_no;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-08-03 14:28:12 +00:00
|
|
|
if (!gst_tag_list_get_uint_index (list, tag, index, &track_no))
|
|
|
|
g_assert_not_reached ();
|
2004-02-22 15:14:25 +00:00
|
|
|
vorbisvalue = g_strdup_printf ("%u", track_no);
|
|
|
|
} else if (strcmp (tag, GST_TAG_DATE) == 0) {
|
|
|
|
/* FIXME: how are dates represented in vorbis files? */
|
|
|
|
GDate *date;
|
|
|
|
guint u;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-08-03 14:28:12 +00:00
|
|
|
if (!gst_tag_list_get_uint_index (list, tag, index, &u))
|
|
|
|
g_assert_not_reached ();
|
2004-02-22 15:14:25 +00:00
|
|
|
date = g_date_new_julian (u);
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbisvalue =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_strdup_printf ("%04d-%02d-%02d", (gint) g_date_get_year (date),
|
|
|
|
(gint) g_date_get_month (date), (gint) g_date_get_day (date));
|
2004-02-22 15:14:25 +00:00
|
|
|
g_date_free (date);
|
|
|
|
} else if (gst_tag_get_type (tag) == G_TYPE_STRING) {
|
2004-08-03 14:28:12 +00:00
|
|
|
if (!gst_tag_list_get_string_index (list, tag, index, &vorbisvalue))
|
|
|
|
g_assert_not_reached ();
|
2004-02-22 15:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return vorbisvalue;
|
|
|
|
}
|
|
|
|
|
2003-11-24 04:08:48 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_metadata_set1 (const GstTagList * list, const gchar * tag,
|
|
|
|
gpointer vorbisenc)
|
2002-10-20 01:55:28 +00:00
|
|
|
{
|
2004-02-22 15:14:25 +00:00
|
|
|
const gchar *vorbistag = NULL;
|
2003-11-26 12:15:57 +00:00
|
|
|
gchar *vorbisvalue = NULL;
|
2003-11-24 04:08:48 +00:00
|
|
|
guint i, count;
|
|
|
|
VorbisEnc *enc = GST_VORBISENC (vorbisenc);
|
|
|
|
|
2004-02-22 15:14:25 +00:00
|
|
|
vorbistag = gst_tag_to_vorbis_tag (tag);
|
|
|
|
if (vorbistag == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-24 04:08:48 +00:00
|
|
|
count = gst_tag_list_get_tag_size (list, tag);
|
|
|
|
for (i = 0; i < count; i++) {
|
2004-02-22 15:14:25 +00:00
|
|
|
vorbisvalue = gst_vorbisenc_get_tag_value (list, tag, i);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-02-22 15:14:25 +00:00
|
|
|
if (vorbisvalue != NULL) {
|
|
|
|
vorbis_comment_add_tag (&enc->vc, g_strdup (vorbistag), vorbisvalue);
|
2003-11-24 04:08:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-02-22 15:14:25 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void
|
|
|
|
gst_vorbisenc_set_metadata (VorbisEnc * vorbisenc)
|
2003-11-24 04:08:48 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
GstTagList *copy;
|
2003-11-24 04:08:48 +00:00
|
|
|
const GstTagList *user_tags;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-11-24 04:08:48 +00:00
|
|
|
user_tags = gst_tag_setter_get_list (GST_TAG_SETTER (vorbisenc));
|
|
|
|
if (!(vorbisenc->tags || user_tags))
|
2002-10-20 01:55:28 +00:00
|
|
|
return;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
copy =
|
|
|
|
gst_tag_list_merge (user_tags, vorbisenc->tags,
|
|
|
|
gst_tag_setter_get_merge_mode (GST_TAG_SETTER (vorbisenc)));
|
2002-10-20 01:55:28 +00:00
|
|
|
vorbis_comment_init (&vorbisenc->vc);
|
2003-11-24 04:08:48 +00:00
|
|
|
gst_tag_list_foreach (copy, gst_vorbisenc_metadata_set1, vorbisenc);
|
|
|
|
gst_tag_list_free (copy);
|
2002-10-20 01:55:28 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static gchar *
|
|
|
|
get_constraints_string (VorbisEnc * vorbisenc)
|
2002-10-20 01:55:28 +00:00
|
|
|
{
|
|
|
|
gint min = vorbisenc->min_bitrate;
|
|
|
|
gint max = vorbisenc->max_bitrate;
|
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
if (min > 0 && max > 0)
|
2004-03-14 22:34:34 +00:00
|
|
|
result = g_strdup_printf ("(min %d bps, max %d bps)", min, max);
|
2002-10-20 01:55:28 +00:00
|
|
|
else if (min > 0)
|
|
|
|
result = g_strdup_printf ("(min %d bps, no max)", min);
|
|
|
|
else if (max > 0)
|
|
|
|
result = g_strdup_printf ("(no min, max %d bps)", max);
|
|
|
|
else
|
|
|
|
result = g_strdup_printf ("(no min or max)");
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
update_start_message (VorbisEnc * vorbisenc)
|
2002-10-20 01:55:28 +00:00
|
|
|
{
|
|
|
|
gchar *constraints;
|
|
|
|
|
|
|
|
g_free (vorbisenc->last_message);
|
|
|
|
|
|
|
|
if (vorbisenc->bitrate > 0) {
|
|
|
|
if (vorbisenc->managed) {
|
|
|
|
constraints = get_constraints_string (vorbisenc);
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbisenc->last_message =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_strdup_printf ("encoding at average bitrate %d bps %s",
|
|
|
|
vorbisenc->bitrate, constraints);
|
2002-10-20 01:55:28 +00:00
|
|
|
g_free (constraints);
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
|
|
|
vorbisenc->last_message =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_strdup_printf
|
|
|
|
("encoding at approximate bitrate %d bps (VBR encoding enabled)",
|
|
|
|
vorbisenc->bitrate);
|
2002-10-20 01:55:28 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2002-10-20 01:55:28 +00:00
|
|
|
if (vorbisenc->quality_set) {
|
|
|
|
if (vorbisenc->managed) {
|
2004-03-15 19:32:28 +00:00
|
|
|
constraints = get_constraints_string (vorbisenc);
|
|
|
|
vorbisenc->last_message =
|
|
|
|
g_strdup_printf
|
|
|
|
("encoding at quality level %2.2f using constrained VBR %s",
|
|
|
|
vorbisenc->quality, constraints);
|
|
|
|
g_free (constraints);
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2004-03-15 19:32:28 +00:00
|
|
|
vorbisenc->last_message =
|
|
|
|
g_strdup_printf ("encoding at quality level %2.2f",
|
|
|
|
vorbisenc->quality);
|
2002-10-20 01:55:28 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2002-10-20 01:55:28 +00:00
|
|
|
constraints = get_constraints_string (vorbisenc);
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbisenc->last_message =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_strdup_printf ("encoding using bitrate management %s", constraints);
|
2002-10-20 01:55:28 +00:00
|
|
|
g_free (constraints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (vorbisenc), "last_message");
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_setup (VorbisEnc * vorbisenc)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
2004-05-24 19:19:29 +00:00
|
|
|
vorbisenc->setup = FALSE;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (vorbisenc->bitrate < 0 && vorbisenc->min_bitrate < 0
|
|
|
|
&& vorbisenc->max_bitrate < 0) {
|
2002-10-20 01:55:28 +00:00
|
|
|
vorbisenc->quality_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
update_start_message (vorbisenc);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
/* choose an encoding mode */
|
|
|
|
/* (mode 0: 44kHz stereo uncoupled, roughly 128kbps VBR) */
|
2001-12-21 01:14:21 +00:00
|
|
|
vorbis_info_init (&vorbisenc->vi);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (vorbisenc->quality_set) {
|
|
|
|
if (vorbis_encode_setup_vbr (&vorbisenc->vi,
|
2004-05-24 19:19:29 +00:00
|
|
|
vorbisenc->channels, vorbisenc->frequency,
|
|
|
|
vorbisenc->quality) != 0) {
|
|
|
|
GST_ERROR_OBJECT (vorbisenc,
|
|
|
|
"vorbisenc: initialisation failed: invalid parameters for quality");
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbis_info_clear (&vorbisenc->vi);
|
|
|
|
return FALSE;
|
2002-10-20 01:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* do we have optional hard quality restrictions? */
|
2004-03-14 22:34:34 +00:00
|
|
|
if (vorbisenc->max_bitrate > 0 || vorbisenc->min_bitrate > 0) {
|
2002-10-20 01:55:28 +00:00
|
|
|
struct ovectl_ratemanage_arg ai;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-20 01:55:28 +00:00
|
|
|
vorbis_encode_ctl (&vorbisenc->vi, OV_ECTL_RATEMANAGE_GET, &ai);
|
|
|
|
|
2004-06-24 14:56:21 +00:00
|
|
|
/* the bitrates used by libvorbisenc are in kbit/sec, ours in bit/sec
|
|
|
|
* also remember that in telecom kbit/sec is 1000 bit/sec */
|
2002-10-20 01:55:28 +00:00
|
|
|
ai.bitrate_hard_min = vorbisenc->min_bitrate / 1000;
|
|
|
|
ai.bitrate_hard_max = vorbisenc->max_bitrate / 1000;
|
|
|
|
ai.management_active = 1;
|
|
|
|
|
|
|
|
vorbis_encode_ctl (&vorbisenc->vi, OV_ECTL_RATEMANAGE_SET, &ai);
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2004-06-24 15:44:53 +00:00
|
|
|
long min_bitrate, max_bitrate;
|
|
|
|
|
|
|
|
min_bitrate = vorbisenc->min_bitrate > 0 ? vorbisenc->min_bitrate : -1;
|
|
|
|
max_bitrate = vorbisenc->max_bitrate > 0 ? vorbisenc->max_bitrate : -1;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (vorbis_encode_setup_managed (&vorbisenc->vi,
|
2004-03-15 19:32:28 +00:00
|
|
|
vorbisenc->channels,
|
|
|
|
vorbisenc->frequency,
|
2004-06-24 15:44:53 +00:00
|
|
|
max_bitrate, vorbisenc->bitrate, min_bitrate) != 0) {
|
2004-05-24 19:19:29 +00:00
|
|
|
GST_ERROR_OBJECT (vorbisenc,
|
2004-06-24 15:44:53 +00:00
|
|
|
"vorbis_encode_setup_managed "
|
|
|
|
"(c %d, rate %d, max br %ld, br %ld, min br %ld) failed",
|
|
|
|
vorbisenc->channels, vorbisenc->frequency, max_bitrate,
|
|
|
|
vorbisenc->bitrate, min_bitrate);
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbis_info_clear (&vorbisenc->vi);
|
2002-10-20 01:55:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (vorbisenc->managed && vorbisenc->bitrate < 0) {
|
|
|
|
vorbis_encode_ctl (&vorbisenc->vi, OV_ECTL_RATEMANAGE_AVG, NULL);
|
|
|
|
} else if (!vorbisenc->managed) {
|
2002-10-20 01:55:28 +00:00
|
|
|
/* Turn off management entirely (if it was turned on). */
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbis_encode_ctl (&vorbisenc->vi, OV_ECTL_RATEMANAGE_SET, NULL);
|
2002-10-20 01:55:28 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbis_encode_setup_init (&vorbisenc->vi);
|
2002-10-20 01:55:28 +00:00
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
/* set up the analysis state and auxiliary encoding storage */
|
2001-12-21 01:14:21 +00:00
|
|
|
vorbis_analysis_init (&vorbisenc->vd, &vorbisenc->vi);
|
|
|
|
vorbis_block_init (&vorbisenc->vd, &vorbisenc->vb);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2001-12-21 01:14:21 +00:00
|
|
|
vorbisenc->setup = TRUE;
|
2002-10-20 01:55:28 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
|
2004-05-20 14:45:57 +00:00
|
|
|
/* prepare a buffer for transmission by passing data through libvorbis */
|
|
|
|
static GstBuffer *
|
|
|
|
gst_vorbisenc_buffer_from_packet (VorbisEnc * vorbisenc, ogg_packet * packet)
|
2002-10-20 22:27:53 +00:00
|
|
|
{
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
outbuf = gst_buffer_new_and_alloc (packet->bytes);
|
|
|
|
memcpy (GST_BUFFER_DATA (outbuf), packet->packet, packet->bytes);
|
|
|
|
GST_BUFFER_OFFSET (outbuf) = vorbisenc->bytes_out;
|
|
|
|
GST_BUFFER_OFFSET_END (outbuf) = packet->granulepos;
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) =
|
2004-05-12 07:18:03 +00:00
|
|
|
vorbis_granule_time_copy (&vorbisenc->vd,
|
|
|
|
packet->granulepos) * GST_SECOND;
|
2002-10-20 22:27:53 +00:00
|
|
|
|
2004-05-20 14:45:57 +00:00
|
|
|
GST_DEBUG ("encoded buffer of %d bytes", GST_BUFFER_SIZE (outbuf));
|
|
|
|
return outbuf;
|
|
|
|
}
|
2002-10-20 22:27:53 +00:00
|
|
|
|
2004-05-20 14:45:57 +00:00
|
|
|
/* push out the buffer and do internal bookkeeping */
|
|
|
|
static void
|
|
|
|
gst_vorbisenc_push_buffer (VorbisEnc * vorbisenc, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
vorbisenc->bytes_out += GST_BUFFER_SIZE (buffer);
|
2002-10-20 22:27:53 +00:00
|
|
|
|
|
|
|
if (GST_PAD_IS_USABLE (vorbisenc->srcpad)) {
|
2004-05-20 14:45:57 +00:00
|
|
|
gst_pad_push (vorbisenc->srcpad, GST_DATA (buffer));
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2004-05-20 14:45:57 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2002-10-20 22:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-20 14:45:57 +00:00
|
|
|
static void
|
|
|
|
gst_vorbisenc_push_packet (VorbisEnc * vorbisenc, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
|
|
|
outbuf = gst_vorbisenc_buffer_from_packet (vorbisenc, packet);
|
|
|
|
gst_vorbisenc_push_buffer (vorbisenc, outbuf);
|
|
|
|
}
|
2004-06-16 09:54:18 +00:00
|
|
|
|
2004-05-20 17:26:53 +00:00
|
|
|
static void
|
|
|
|
gst_vorbisenc_set_header_on_caps (GstCaps * caps, GstBuffer * buf1,
|
|
|
|
GstBuffer * buf2, GstBuffer * buf3)
|
|
|
|
{
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
|
|
|
GValue list = { 0 };
|
|
|
|
GValue value = { 0 };
|
|
|
|
|
|
|
|
/* mark buffers */
|
|
|
|
GST_BUFFER_FLAG_SET (buf1, GST_BUFFER_IN_CAPS);
|
|
|
|
GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_IN_CAPS);
|
|
|
|
GST_BUFFER_FLAG_SET (buf3, GST_BUFFER_IN_CAPS);
|
|
|
|
|
|
|
|
/* put buffers in a fixed list */
|
|
|
|
g_value_init (&list, GST_TYPE_FIXED_LIST);
|
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
|
|
|
g_value_set_boxed (&value, buf1);
|
|
|
|
gst_value_list_append_value (&list, &value);
|
|
|
|
g_value_unset (&value);
|
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
|
|
|
g_value_set_boxed (&value, buf2);
|
|
|
|
gst_value_list_append_value (&list, &value);
|
|
|
|
g_value_unset (&value);
|
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
|
|
|
g_value_set_boxed (&value, buf3);
|
|
|
|
gst_value_list_append_value (&list, &value);
|
|
|
|
gst_structure_set_value (structure, "streamheader", &list);
|
|
|
|
g_value_unset (&value);
|
|
|
|
g_value_unset (&list);
|
|
|
|
}
|
2004-05-20 14:45:57 +00:00
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_chain (GstPad * pad, GstData * _data)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
2003-10-08 16:08:22 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-20 22:30:14 +00:00
|
|
|
VorbisEnc *vorbisenc;
|
|
|
|
|
2001-12-21 01:14:21 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
|
|
|
|
|
2001-12-21 01:14:21 +00:00
|
|
|
if (GST_IS_EVENT (buf)) {
|
2002-10-19 16:57:08 +00:00
|
|
|
GstEvent *event = GST_EVENT (buf);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2001-12-21 01:14:21 +00:00
|
|
|
case GST_EVENT_EOS:
|
2004-03-15 19:32:28 +00:00
|
|
|
/* end of file. this can be done implicitly in the mainline,
|
|
|
|
but it's easier to see here in non-clever fashion.
|
|
|
|
Tell the library we're at end of stream so that it can handle
|
|
|
|
the last frame and mark end of stream in the output properly */
|
|
|
|
vorbis_analysis_wrote (&vorbisenc->vd, 0);
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
vorbisenc->eos = TRUE;
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
2003-11-24 04:08:48 +00:00
|
|
|
case GST_EVENT_TAG:
|
2004-03-15 19:32:28 +00:00
|
|
|
if (vorbisenc->tags) {
|
|
|
|
gst_tag_list_insert (vorbisenc->tags, gst_event_tag_get_list (event),
|
|
|
|
gst_tag_setter_get_merge_mode (GST_TAG_SETTER (vorbisenc)));
|
|
|
|
} else {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
gst_pad_event_default (pad, event);
|
|
|
|
return;
|
2001-12-21 01:14:21 +00:00
|
|
|
default:
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_pad_event_default (pad, event);
|
|
|
|
return;
|
2001-12-21 01:14:21 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
gfloat *data;
|
2001-12-21 01:14:21 +00:00
|
|
|
gulong size;
|
|
|
|
gulong i, j;
|
|
|
|
float **buffer;
|
2002-10-19 16:57:08 +00:00
|
|
|
|
|
|
|
if (!vorbisenc->setup) {
|
|
|
|
gst_buffer_unref (buf);
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_ELEMENT_ERROR (vorbisenc, CORE, NEGOTIATION, (NULL),
|
2004-03-15 19:32:28 +00:00
|
|
|
("encoder not initialized (input is not audio?)"));
|
2002-10-19 16:57:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-10-20 22:27:53 +00:00
|
|
|
|
2003-11-24 04:08:48 +00:00
|
|
|
if (!vorbisenc->header_sent) {
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
//gint result;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-11-24 04:08:48 +00:00
|
|
|
/* Vorbis streams begin with three headers; the initial header (with
|
2004-03-14 22:34:34 +00:00
|
|
|
most of the codec setup parameters) which is mandated by the Ogg
|
|
|
|
bitstream spec. The second header holds any comment fields. The
|
|
|
|
third header holds the bitstream codebook. We merely need to
|
|
|
|
make the headers, then pass them to libvorbis one at a time;
|
|
|
|
libvorbis handles the additional Ogg bitstream constraints */
|
2003-11-24 04:08:48 +00:00
|
|
|
ogg_packet header;
|
|
|
|
ogg_packet header_comm;
|
|
|
|
ogg_packet header_code;
|
2004-05-20 17:26:53 +00:00
|
|
|
GstBuffer *buf1, *buf2, *buf3;
|
|
|
|
GstCaps *caps;
|
2003-11-24 04:08:48 +00:00
|
|
|
|
|
|
|
gst_vorbisenc_set_metadata (vorbisenc);
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbis_analysis_headerout (&vorbisenc->vd, &vorbisenc->vc, &header,
|
2004-03-15 19:32:28 +00:00
|
|
|
&header_comm, &header_code);
|
2004-05-20 17:26:53 +00:00
|
|
|
|
|
|
|
/* create header buffers */
|
|
|
|
buf1 = gst_vorbisenc_buffer_from_packet (vorbisenc, &header);
|
|
|
|
buf2 = gst_vorbisenc_buffer_from_packet (vorbisenc, &header_comm);
|
|
|
|
buf3 = gst_vorbisenc_buffer_from_packet (vorbisenc, &header_code);
|
|
|
|
|
|
|
|
/* mark and put on caps */
|
|
|
|
caps = gst_pad_get_caps (vorbisenc->srcpad);
|
|
|
|
gst_vorbisenc_set_header_on_caps (caps, buf1, buf2, buf3);
|
|
|
|
|
|
|
|
/* negotiate with these caps */
|
|
|
|
GST_DEBUG ("here are the caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
gst_pad_try_set_caps (vorbisenc->srcpad, caps);
|
|
|
|
|
|
|
|
/* push out buffers */
|
|
|
|
gst_vorbisenc_push_buffer (vorbisenc, buf1);
|
|
|
|
gst_vorbisenc_push_buffer (vorbisenc, buf2);
|
|
|
|
gst_vorbisenc_push_buffer (vorbisenc, buf3);
|
2002-10-20 22:27:53 +00:00
|
|
|
|
2003-11-24 04:08:48 +00:00
|
|
|
vorbisenc->header_sent = TRUE;
|
2002-10-20 22:27:53 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
/* data to encode */
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
data = (gfloat *) GST_BUFFER_DATA (buf);
|
|
|
|
size = GST_BUFFER_SIZE (buf) / (vorbisenc->channels * sizeof (float));
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
/* expose the buffer to submit data */
|
2002-10-20 17:11:10 +00:00
|
|
|
buffer = vorbis_analysis_buffer (&vorbisenc->vd, size);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
/* uninterleave samples */
|
2002-10-20 17:11:10 +00:00
|
|
|
for (i = 0; i < size; i++) {
|
2002-10-19 16:57:08 +00:00
|
|
|
for (j = 0; j < vorbisenc->channels; j++) {
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
buffer[j][i] = *data++;
|
2002-10-19 16:57:08 +00:00
|
|
|
}
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tell the library how much we actually submitted */
|
2002-10-20 17:11:10 +00:00
|
|
|
vorbis_analysis_wrote (&vorbisenc->vd, size);
|
|
|
|
|
|
|
|
vorbisenc->samples_in += size;
|
2001-12-21 01:14:21 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
/* vorbis does some data preanalysis, then divides up blocks for
|
2001-12-20 22:30:14 +00:00
|
|
|
more involved (potentially parallel) processing. Get a single
|
|
|
|
block for encoding now */
|
2001-12-21 01:14:21 +00:00
|
|
|
while (vorbis_analysis_blockout (&vorbisenc->vd, &vorbisenc->vb) == 1) {
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
ogg_packet op;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
/* analysis */
|
2002-04-15 09:27:03 +00:00
|
|
|
vorbis_analysis (&vorbisenc->vb, NULL);
|
2004-03-14 22:34:34 +00:00
|
|
|
vorbis_bitrate_addblock (&vorbisenc->vb);
|
|
|
|
|
ext/vorbis/: Added a raw vorbis encoder to be used with the oggmuxer.
Original commit message from CVS:
* ext/vorbis/Makefile.am:
* ext/vorbis/README:
* ext/vorbis/oggvorbisenc.c: (gst_oggvorbisenc_get_formats),
(oggvorbisenc_get_type), (vorbis_caps_factory), (raw_caps_factory),
(gst_oggvorbisenc_base_init), (gst_oggvorbisenc_class_init),
(gst_oggvorbisenc_sinkconnect), (gst_oggvorbisenc_convert_src),
(gst_oggvorbisenc_convert_sink),
(gst_oggvorbisenc_get_query_types), (gst_oggvorbisenc_src_query),
(gst_oggvorbisenc_init), (gst_oggvorbisenc_get_tag_value),
(gst_oggvorbisenc_metadata_set1), (gst_oggvorbisenc_set_metadata),
(get_constraints_string), (update_start_message),
(gst_oggvorbisenc_setup), (gst_oggvorbisenc_write_page),
(gst_oggvorbisenc_chain), (gst_oggvorbisenc_get_property),
(gst_oggvorbisenc_set_property), (gst_oggvorbisenc_change_state):
* ext/vorbis/oggvorbisenc.h:
* ext/vorbis/vorbis.c: (plugin_init):
* ext/vorbis/vorbisenc.c: (vorbis_caps_factory),
(raw_caps_factory), (gst_vorbisenc_class_init),
(gst_vorbisenc_init), (gst_vorbisenc_setup),
(gst_vorbisenc_push_packet), (gst_vorbisenc_chain),
(gst_vorbisenc_get_property), (gst_vorbisenc_set_property):
* ext/vorbis/vorbisenc.h:
Added a raw vorbis encoder to be used with the oggmuxer.
We still need the old encoder for some gnome applications,
read the README to find out how that works.
The raw encoder is called "rawvorbisenc" until 0.9.
2004-05-10 17:44:07 +00:00
|
|
|
while (vorbis_bitrate_flushpacket (&vorbisenc->vd, &op)) {
|
|
|
|
gst_vorbisenc_push_packet (vorbisenc, &op);
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vorbisenc->eos) {
|
|
|
|
/* clean up and exit. vorbis_info_clear() must be called last */
|
2001-12-21 01:14:21 +00:00
|
|
|
vorbis_block_clear (&vorbisenc->vb);
|
|
|
|
vorbis_dsp_clear (&vorbisenc->vd);
|
|
|
|
vorbis_info_clear (&vorbisenc->vi);
|
2003-10-08 16:08:22 +00:00
|
|
|
gst_pad_push (vorbisenc->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS)));
|
2002-09-11 21:41:53 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (vorbisenc));
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
|
|
|
VorbisEnc *vorbisenc;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_VORBISENC (object));
|
|
|
|
|
|
|
|
vorbisenc = GST_VORBISENC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-10-20 01:55:28 +00:00
|
|
|
case ARG_MAX_BITRATE:
|
|
|
|
g_value_set_int (value, vorbisenc->max_bitrate);
|
|
|
|
break;
|
2001-12-20 22:30:14 +00:00
|
|
|
case ARG_BITRATE:
|
|
|
|
g_value_set_int (value, vorbisenc->bitrate);
|
|
|
|
break;
|
2002-10-20 01:55:28 +00:00
|
|
|
case ARG_MIN_BITRATE:
|
|
|
|
g_value_set_int (value, vorbisenc->min_bitrate);
|
|
|
|
break;
|
|
|
|
case ARG_QUALITY:
|
|
|
|
g_value_set_float (value, vorbisenc->quality);
|
|
|
|
break;
|
|
|
|
case ARG_MANAGED:
|
|
|
|
g_value_set_boolean (value, vorbisenc->managed);
|
|
|
|
break;
|
|
|
|
case ARG_LAST_MESSAGE:
|
|
|
|
g_value_set_string (value, vorbisenc->last_message);
|
|
|
|
break;
|
2001-12-20 22:30:14 +00:00
|
|
|
default:
|
2002-10-20 17:11:10 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-20 22:30:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
|
|
|
VorbisEnc *vorbisenc;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_VORBISENC (object));
|
|
|
|
|
|
|
|
vorbisenc = GST_VORBISENC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-10-20 01:55:28 +00:00
|
|
|
case ARG_MAX_BITRATE:
|
|
|
|
{
|
|
|
|
gboolean old_value = vorbisenc->managed;
|
|
|
|
|
|
|
|
vorbisenc->max_bitrate = g_value_get_int (value);
|
2004-06-24 15:51:24 +00:00
|
|
|
if (vorbisenc->max_bitrate >= 0
|
|
|
|
&& vorbisenc->max_bitrate < LOWEST_BITRATE) {
|
|
|
|
g_warning ("Lowest allowed bitrate is %d", LOWEST_BITRATE);
|
|
|
|
vorbisenc->max_bitrate = LOWEST_BITRATE;
|
|
|
|
}
|
2002-10-20 01:55:28 +00:00
|
|
|
if (vorbisenc->min_bitrate > 0 && vorbisenc->max_bitrate > 0)
|
2004-03-15 19:32:28 +00:00
|
|
|
vorbisenc->managed = TRUE;
|
2002-10-20 01:55:28 +00:00
|
|
|
else
|
2004-03-15 19:32:28 +00:00
|
|
|
vorbisenc->managed = FALSE;
|
2002-10-20 01:55:28 +00:00
|
|
|
|
|
|
|
if (old_value != vorbisenc->managed)
|
2004-03-15 19:32:28 +00:00
|
|
|
g_object_notify (object, "managed");
|
2002-10-20 01:55:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-12-20 22:30:14 +00:00
|
|
|
case ARG_BITRATE:
|
|
|
|
vorbisenc->bitrate = g_value_get_int (value);
|
2004-06-24 15:51:24 +00:00
|
|
|
if (vorbisenc->bitrate >= 0 && vorbisenc->bitrate < LOWEST_BITRATE) {
|
|
|
|
g_warning ("Lowest allowed bitrate is %d", LOWEST_BITRATE);
|
|
|
|
vorbisenc->bitrate = LOWEST_BITRATE;
|
|
|
|
}
|
2001-12-20 22:30:14 +00:00
|
|
|
break;
|
2002-10-20 01:55:28 +00:00
|
|
|
case ARG_MIN_BITRATE:
|
|
|
|
{
|
|
|
|
gboolean old_value = vorbisenc->managed;
|
|
|
|
|
|
|
|
vorbisenc->min_bitrate = g_value_get_int (value);
|
2004-06-24 15:51:24 +00:00
|
|
|
if (vorbisenc->min_bitrate >= 0
|
|
|
|
&& vorbisenc->min_bitrate < LOWEST_BITRATE) {
|
|
|
|
g_warning ("Lowest allowed bitrate is %d", LOWEST_BITRATE);
|
|
|
|
vorbisenc->min_bitrate = LOWEST_BITRATE;
|
|
|
|
}
|
2002-10-20 01:55:28 +00:00
|
|
|
if (vorbisenc->min_bitrate > 0 && vorbisenc->max_bitrate > 0)
|
2004-03-15 19:32:28 +00:00
|
|
|
vorbisenc->managed = TRUE;
|
2002-10-20 01:55:28 +00:00
|
|
|
else
|
2004-03-15 19:32:28 +00:00
|
|
|
vorbisenc->managed = FALSE;
|
2002-10-20 01:55:28 +00:00
|
|
|
|
|
|
|
if (old_value != vorbisenc->managed)
|
2004-03-15 19:32:28 +00:00
|
|
|
g_object_notify (object, "managed");
|
2002-10-20 01:55:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ARG_QUALITY:
|
|
|
|
vorbisenc->quality = g_value_get_float (value);
|
|
|
|
if (vorbisenc->quality >= 0.0)
|
2004-03-15 19:32:28 +00:00
|
|
|
vorbisenc->quality_set = TRUE;
|
2002-10-20 01:55:28 +00:00
|
|
|
else
|
2004-03-15 19:32:28 +00:00
|
|
|
vorbisenc->quality_set = FALSE;
|
2002-10-20 01:55:28 +00:00
|
|
|
break;
|
|
|
|
case ARG_MANAGED:
|
|
|
|
vorbisenc->managed = g_value_get_boolean (value);
|
|
|
|
break;
|
2001-12-20 22:30:14 +00:00
|
|
|
default:
|
2002-10-20 17:11:10 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-20 22:30:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-10-19 16:57:08 +00:00
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_vorbisenc_change_state (GstElement * element)
|
2002-10-19 16:57:08 +00:00
|
|
|
{
|
|
|
|
VorbisEnc *vorbisenc = GST_VORBISENC (element);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2002-10-19 16:57:08 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
vorbisenc->eos = FALSE;
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2002-11-20 22:56:26 +00:00
|
|
|
vorbisenc->setup = FALSE;
|
2003-11-24 04:08:48 +00:00
|
|
|
vorbisenc->header_sent = FALSE;
|
|
|
|
gst_tag_list_free (vorbisenc->tags);
|
|
|
|
vorbisenc->tags = gst_tag_list_new ();
|
2002-10-19 16:57:08 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|