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.
|
|
|
|
*/
|
|
|
|
|
2005-09-15 15:28:36 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-vorbisenc
|
2006-03-01 17:39:28 +00:00
|
|
|
* @short_description: an encoder that encodes audio to Vorbis
|
2005-09-15 15:28:36 +00:00
|
|
|
* @see_also: vorbisdec, oggmux
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <para>
|
|
|
|
* This element encodes raw float audio into a Vorbis stream.
|
|
|
|
* <ulink url="http://www.vorbis.com/">Vorbis</ulink> is a royalty-free
|
|
|
|
* audio codec maintained by the <ulink url="http://www.xiph.org/">Xiph.org
|
|
|
|
* Foundation</ulink>.
|
|
|
|
* </para>
|
|
|
|
* <title>Example pipelines</title>
|
|
|
|
* <para>
|
|
|
|
* Encode a test sine signal to Ogg/Vorbis. Note that the resulting file
|
|
|
|
* will be really small because a sine signal compresses very well.
|
|
|
|
* </para>
|
|
|
|
* <programlisting>
|
2005-11-23 15:36:58 +00:00
|
|
|
* gst-launch -v audiotestsrc wave=sine num-buffers=100 ! audioconvert ! vorbisenc ! oggmux ! filesink location=sine.ogg
|
2005-09-15 15:28:36 +00:00
|
|
|
* </programlisting>
|
|
|
|
* <para>
|
|
|
|
* Record from a sound card using ALSA and encode to Ogg/Vorbis.
|
|
|
|
* </para>
|
|
|
|
* <programlisting>
|
|
|
|
* gst-launch -v alsasrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=alsasrc.ogg
|
|
|
|
* </programlisting>
|
2006-03-01 17:39:28 +00:00
|
|
|
* </refsect2>
|
2005-08-20 20:40:25 +00:00
|
|
|
*
|
2006-03-01 17:39:28 +00:00
|
|
|
* Last reviewed on 2006-03-01 (0.10.4)
|
2005-08-20 20:40:25 +00:00
|
|
|
*/
|
|
|
|
|
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>
|
|
|
|
|
2005-09-07 13:55:08 +00:00
|
|
|
#include <gst/gsttagsetter.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 */
|
2006-03-29 14:00:08 +00:00
|
|
|
GstElementDetails vorbisenc_details =
|
|
|
|
GST_ELEMENT_DETAILS ("Vorbis audio encoder",
|
2006-03-24 10:42:11 +00:00
|
|
|
"Codec/Encoder/Audio",
|
|
|
|
"Encodes audio in Vorbis format",
|
|
|
|
"Monty <monty@xiph.org>, " "Wim Taymans <wim@fluendo.com>");
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2005-08-20 20:40:25 +00:00
|
|
|
/* GstVorbisEnc 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
|
|
|
};
|
|
|
|
|
2005-11-21 10:09:16 +00:00
|
|
|
static GstFlowReturn gst_vorbisenc_output_buffers (GstVorbisEnc * vorbisenc);
|
2005-09-15 19:59:50 +00:00
|
|
|
|
ogg muxing of vorbis and theora now has pages ordered correctly again, even with delays.
Original commit message from CVS:
ogg muxing of vorbis and theora now has pages ordered correctly again,
even with delays.
* ext/ogg/README:
updated with some examples
* ext/theora/theoraenc.c: (granulepos_to_timestamp),
(granulepos_add), (theora_buffer_from_packet):
* ext/vorbis/vorbisenc.c: (granulepos_to_timestamp_offset),
(granulepos_to_timestamp), (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_chain):
implement strategy from ext/ogg/README
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_compare_pads),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_collected):
Fix muxer so that oggz-validate is happy with all streams;
except for no eos mark, and the BOS page ordering
* tests/check/pipelines/theoraenc.c: (check_buffer_is_header),
(check_buffer_granulepos):
* tests/check/pipelines/vorbisenc.c: (check_buffer_granulepos):
update tests to check for OFFSET being set as requested
fixed type of granulepos, it's not a ClockTime
2006-03-05 22:57:58 +00:00
|
|
|
/* this function takes into account the granulepos_offset and the subgranule
|
|
|
|
* time offset */
|
2006-01-30 15:01:28 +00:00
|
|
|
static GstClockTime
|
ogg muxing of vorbis and theora now has pages ordered correctly again, even with delays.
Original commit message from CVS:
ogg muxing of vorbis and theora now has pages ordered correctly again,
even with delays.
* ext/ogg/README:
updated with some examples
* ext/theora/theoraenc.c: (granulepos_to_timestamp),
(granulepos_add), (theora_buffer_from_packet):
* ext/vorbis/vorbisenc.c: (granulepos_to_timestamp_offset),
(granulepos_to_timestamp), (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_chain):
implement strategy from ext/ogg/README
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_compare_pads),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_collected):
Fix muxer so that oggz-validate is happy with all streams;
except for no eos mark, and the BOS page ordering
* tests/check/pipelines/theoraenc.c: (check_buffer_is_header),
(check_buffer_granulepos):
* tests/check/pipelines/vorbisenc.c: (check_buffer_granulepos):
update tests to check for OFFSET being set as requested
fixed type of granulepos, it's not a ClockTime
2006-03-05 22:57:58 +00:00
|
|
|
granulepos_to_timestamp_offset (GstVorbisEnc * vorbisenc,
|
|
|
|
ogg_int64_t granulepos)
|
2004-05-12 07:18:03 +00:00
|
|
|
{
|
|
|
|
if (granulepos >= 0)
|
2006-01-30 15:01:28 +00:00
|
|
|
return gst_util_uint64_scale ((guint64) granulepos
|
|
|
|
+ vorbisenc->granulepos_offset, GST_SECOND, vorbisenc->frequency)
|
|
|
|
+ vorbisenc->subgranule_offset;
|
|
|
|
return GST_CLOCK_TIME_NONE;
|
2004-05-12 07:18:03 +00:00
|
|
|
}
|
|
|
|
|
ogg muxing of vorbis and theora now has pages ordered correctly again, even with delays.
Original commit message from CVS:
ogg muxing of vorbis and theora now has pages ordered correctly again,
even with delays.
* ext/ogg/README:
updated with some examples
* ext/theora/theoraenc.c: (granulepos_to_timestamp),
(granulepos_add), (theora_buffer_from_packet):
* ext/vorbis/vorbisenc.c: (granulepos_to_timestamp_offset),
(granulepos_to_timestamp), (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_chain):
implement strategy from ext/ogg/README
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_compare_pads),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_collected):
Fix muxer so that oggz-validate is happy with all streams;
except for no eos mark, and the BOS page ordering
* tests/check/pipelines/theoraenc.c: (check_buffer_is_header),
(check_buffer_granulepos):
* tests/check/pipelines/vorbisenc.c: (check_buffer_granulepos):
update tests to check for OFFSET being set as requested
fixed type of granulepos, it's not a ClockTime
2006-03-05 22:57:58 +00:00
|
|
|
/* this function does a straight granulepos -> timestamp conversion */
|
|
|
|
static GstClockTime
|
|
|
|
granulepos_to_timestamp (GstVorbisEnc * vorbisenc, ogg_int64_t granulepos)
|
|
|
|
{
|
|
|
|
if (granulepos >= 0)
|
|
|
|
return gst_util_uint64_scale ((guint64) granulepos,
|
|
|
|
GST_SECOND, vorbisenc->frequency);
|
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
2005-05-09 10:56:13 +00:00
|
|
|
#if 0
|
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
|
|
|
}
|
2005-05-09 10:56:13 +00:00
|
|
|
#endif
|
2002-10-20 17:11:10 +00:00
|
|
|
|
2005-12-06 19:42:02 +00:00
|
|
|
#define MAX_BITRATE_DEFAULT -1
|
|
|
|
#define BITRATE_DEFAULT -1
|
|
|
|
#define MIN_BITRATE_DEFAULT -1
|
|
|
|
#define QUALITY_DEFAULT 0.3
|
|
|
|
#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);
|
2005-08-20 20:40:25 +00:00
|
|
|
static void gst_vorbisenc_class_init (GstVorbisEncClass * klass);
|
|
|
|
static void gst_vorbisenc_init (GstVorbisEnc * vorbisenc);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
static gboolean gst_vorbisenc_sink_event (GstPad * pad, GstEvent * event);
|
|
|
|
static GstFlowReturn gst_vorbisenc_chain (GstPad * pad, GstBuffer * buffer);
|
2005-08-20 20:40:25 +00:00
|
|
|
static gboolean gst_vorbisenc_setup (GstVorbisEnc * 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);
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn gst_vorbisenc_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
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 = {
|
2005-08-20 20:40:25 +00:00
|
|
|
sizeof (GstVorbisEncClass),
|
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,
|
2005-08-20 20:40:25 +00:00
|
|
|
sizeof (GstVorbisEnc),
|
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 =
|
2005-08-20 20:40:25 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstVorbisEnc",
|
|
|
|
&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,
|
2004-11-06 22:50:09 +00:00
|
|
|
"channels", GST_TYPE_INT_RANGE, 1, 2,
|
2005-10-19 17:02:46 +00:00
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
|
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
|
2005-08-20 20:40:25 +00:00
|
|
|
gst_vorbisenc_class_init (GstVorbisEncClass * 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
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
gobject_class->set_property = gst_vorbisenc_set_property;
|
|
|
|
gobject_class->get_property = gst_vorbisenc_get_property;
|
|
|
|
|
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.",
|
2005-09-05 11:21:49 +00:00
|
|
|
-0.1, 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
|
|
|
|
2002-10-19 16:57:08 +00:00
|
|
|
gstelement_class->change_state = gst_vorbisenc_change_state;
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vorbisenc_sink_setcaps (GstPad * pad, GstCaps * caps)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
Make caps writable before writing to it.
Original commit message from CVS:
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_sink_setcaps),
(gst_vorbisenc_src_query), (gst_vorbisenc_sink_query),
(gst_vorbisenc_set_header_on_caps), (gst_vorbisenc_sink_event),
(gst_vorbisenc_chain):
* gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_chain),
(gst_audio_convert_caps_remove_format_info),
(gst_audio_convert_getcaps), (gst_audio_convert_setcaps),
(gst_audio_convert_fixate), (gst_audio_convert_channels):
Make caps writable before writing to it.
Fix negotiation in audioconvert some more.
2005-05-09 17:07:27 +00:00
|
|
|
vorbisenc = GST_VORBISENC (GST_PAD_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)
|
2005-03-31 09:43:49 +00:00
|
|
|
return TRUE;
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
return FALSE;
|
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;
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2002-10-20 17:11:10 +00:00
|
|
|
gint64 avg;
|
|
|
|
|
|
|
|
vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (vorbisenc->samples_in == 0 ||
|
2006-03-07 12:49:03 +00:00
|
|
|
vorbisenc->bytes_out == 0 || vorbisenc->frequency == 0) {
|
|
|
|
gst_object_unref (vorbisenc);
|
2002-10-20 17:11:10 +00:00
|
|
|
return FALSE;
|
2006-03-07 12:49:03 +00:00
|
|
|
}
|
2002-10-20 17:11:10 +00:00
|
|
|
|
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:
|
2006-02-17 19:31:12 +00:00
|
|
|
*dest_value = gst_util_uint64_scale_int (src_value, GST_SECOND, avg);
|
2004-03-15 19:32:28 +00:00
|
|
|
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:
|
2006-02-17 19:31:12 +00:00
|
|
|
*dest_value = gst_util_uint64_scale_int (src_value, avg, GST_SECOND);
|
2004-03-15 19:32:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
2006-03-07 12:49:03 +00:00
|
|
|
gst_object_unref (vorbisenc);
|
2002-10-20 17:11:10 +00:00
|
|
|
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;
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2002-10-20 17:11:10 +00:00
|
|
|
|
|
|
|
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;
|
2006-02-17 19:31:12 +00:00
|
|
|
*dest_value =
|
|
|
|
gst_util_uint64_scale_int (src_value, GST_SECOND, byterate);
|
2004-03-15 19:32:28 +00:00
|
|
|
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;
|
2006-02-17 19:31:12 +00:00
|
|
|
*dest_value =
|
|
|
|
gst_util_uint64_scale_int (src_value, GST_SECOND,
|
|
|
|
vorbisenc->frequency);
|
2004-03-15 19:32:28 +00:00
|
|
|
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:
|
2006-02-17 19:31:12 +00:00
|
|
|
*dest_value =
|
|
|
|
gst_util_uint64_scale_int (src_value,
|
|
|
|
scale * vorbisenc->frequency, GST_SECOND);
|
2004-03-15 19:32:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
2006-03-07 12:49:03 +00:00
|
|
|
gst_object_unref (vorbisenc);
|
2002-10-20 17:11:10 +00:00
|
|
|
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_POSITION,
|
2005-10-20 19:06:43 +00:00
|
|
|
GST_QUERY_DURATION,
|
|
|
|
GST_QUERY_CONVERT,
|
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
|
2005-05-09 10:56:13 +00:00
|
|
|
gst_vorbisenc_src_query (GstPad * pad, GstQuery * query)
|
2002-10-20 17:11:10 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2005-10-20 19:06:43 +00:00
|
|
|
GstPad *peerpad;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2005-10-20 19:06:43 +00:00
|
|
|
vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
|
|
|
|
peerpad = gst_pad_get_peer (GST_PAD (vorbisenc->sinkpad));
|
2002-10-20 17:11:10 +00:00
|
|
|
|
2005-05-09 10:56:13 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
2002-10-20 17:11:10 +00:00
|
|
|
{
|
2005-10-20 19:06:43 +00:00
|
|
|
GstFormat fmt, req_fmt;
|
|
|
|
gint64 pos, val;
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2005-10-20 19:06:43 +00:00
|
|
|
gst_query_parse_position (query, &req_fmt, NULL);
|
|
|
|
if ((res = gst_pad_query_position (peerpad, &req_fmt, &val))) {
|
|
|
|
gst_query_set_position (query, req_fmt, val);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2005-10-20 19:06:43 +00:00
|
|
|
fmt = GST_FORMAT_TIME;
|
|
|
|
if (!(res = gst_pad_query_position (peerpad, &fmt, &pos)))
|
|
|
|
break;
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2005-10-20 19:06:43 +00:00
|
|
|
if ((res = gst_pad_query_convert (peerpad, fmt, pos, &req_fmt, &val))) {
|
|
|
|
gst_query_set_position (query, req_fmt, val);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
|
|
|
GstFormat fmt, req_fmt;
|
|
|
|
gint64 dur, val;
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2005-10-20 19:06:43 +00:00
|
|
|
gst_query_parse_duration (query, &req_fmt, NULL);
|
|
|
|
if ((res = gst_pad_query_duration (peerpad, &req_fmt, &val))) {
|
|
|
|
gst_query_set_duration (query, req_fmt, val);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2005-10-20 19:06:43 +00:00
|
|
|
fmt = GST_FORMAT_TIME;
|
|
|
|
if (!(res = gst_pad_query_duration (peerpad, &fmt, &dur)))
|
|
|
|
break;
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2005-10-20 19:06:43 +00:00
|
|
|
if ((res = gst_pad_query_convert (peerpad, fmt, dur, &req_fmt, &val))) {
|
|
|
|
gst_query_set_duration (query, req_fmt, val);
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-05-09 10:56:13 +00:00
|
|
|
case GST_QUERY_CONVERT:
|
|
|
|
{
|
|
|
|
GstFormat src_fmt, dest_fmt;
|
|
|
|
gint64 src_val, dest_val;
|
|
|
|
|
|
|
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
|
|
|
if (!(res =
|
|
|
|
gst_vorbisenc_convert_src (pad, src_fmt, src_val, &dest_fmt,
|
|
|
|
&dest_val)))
|
|
|
|
goto error;
|
|
|
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2006-02-01 11:56:11 +00:00
|
|
|
res = gst_pad_query_default (pad, query);
|
2005-05-09 10:56:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
2005-10-20 19:06:43 +00:00
|
|
|
gst_object_unref (peerpad);
|
|
|
|
gst_object_unref (vorbisenc);
|
2005-05-09 10:56:13 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vorbisenc_sink_query (GstPad * pad, GstQuery * query)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2005-05-09 10:56:13 +00:00
|
|
|
|
|
|
|
vorbisenc = GST_VORBISENC (GST_PAD_PARENT (pad));
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CONVERT:
|
|
|
|
{
|
|
|
|
GstFormat src_fmt, dest_fmt;
|
|
|
|
gint64 src_val, dest_val;
|
|
|
|
|
|
|
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
|
|
|
if (!(res =
|
|
|
|
gst_vorbisenc_convert_sink (pad, src_fmt, src_val, &dest_fmt,
|
|
|
|
&dest_val)))
|
|
|
|
goto error;
|
|
|
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
2002-10-20 17:11:10 +00:00
|
|
|
break;
|
2005-05-09 10:56:13 +00:00
|
|
|
}
|
2002-10-20 17:11:10 +00:00
|
|
|
default:
|
2006-02-01 11:56:11 +00:00
|
|
|
res = gst_pad_query_default (pad, query);
|
2002-10-20 17:11:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-05-09 10:56:13 +00:00
|
|
|
|
|
|
|
error:
|
2002-10-20 17:11:10 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-12-20 22:30:14 +00:00
|
|
|
static void
|
2005-08-20 20:40:25 +00:00
|
|
|
gst_vorbisenc_init (GstVorbisEnc * 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);
|
2005-03-31 09:43:49 +00:00
|
|
|
gst_pad_set_event_function (vorbisenc->sinkpad, gst_vorbisenc_sink_event);
|
2001-12-21 01:14:21 +00:00
|
|
|
gst_pad_set_chain_function (vorbisenc->sinkpad, gst_vorbisenc_chain);
|
2005-03-31 09:43:49 +00:00
|
|
|
gst_pad_set_setcaps_function (vorbisenc->sinkpad, gst_vorbisenc_sink_setcaps);
|
2005-05-09 10:56:13 +00:00
|
|
|
gst_pad_set_query_function (vorbisenc->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vorbisenc_sink_query));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
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));
|
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;
|
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
|
|
|
{
|
2005-10-13 15:34:02 +00:00
|
|
|
GType tag_type;
|
2004-02-22 15:14:25 +00:00
|
|
|
gchar *vorbisvalue = NULL;
|
|
|
|
|
2005-10-13 15:34:02 +00:00
|
|
|
if (tag == NULL)
|
2004-02-22 15:14:25 +00:00
|
|
|
return NULL;
|
2005-10-13 15:34:02 +00:00
|
|
|
|
|
|
|
tag_type = gst_tag_get_type (tag);
|
2004-02-22 15:14:25 +00:00
|
|
|
|
|
|
|
/* 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))
|
2005-10-13 15:34:02 +00:00
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
|
2004-02-22 15:14:25 +00:00
|
|
|
vorbisvalue = g_strdup_printf ("%u", track_no);
|
2005-10-13 15:34:02 +00:00
|
|
|
} else if (tag_type == GST_TYPE_DATE) {
|
2004-02-22 15:14:25 +00:00
|
|
|
GDate *date;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2005-10-13 15:34:02 +00:00
|
|
|
if (!gst_tag_list_get_date_index (list, tag, index, &date))
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
|
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);
|
2005-10-13 15:34:02 +00:00
|
|
|
} else if (tag_type == G_TYPE_STRING) {
|
2004-08-03 14:28:12 +00:00
|
|
|
if (!gst_tag_list_get_string_index (list, tag, index, &vorbisvalue))
|
2005-10-13 15:34:02 +00:00
|
|
|
g_return_val_if_reached (NULL);
|
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;
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *enc = GST_VORBISENC (vorbisenc);
|
2003-11-24 04:08:48 +00:00
|
|
|
|
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) {
|
2006-02-05 22:44:55 +00:00
|
|
|
gchar *tmptag = g_strdup (vorbistag);
|
|
|
|
|
|
|
|
vorbis_comment_add_tag (&enc->vc, tmptag, vorbisvalue);
|
|
|
|
g_free (tmptag);
|
2006-02-05 23:31:05 +00:00
|
|
|
g_free (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
|
2005-08-20 20:40:25 +00:00
|
|
|
gst_vorbisenc_set_metadata (GstVorbisEnc * 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
|
|
|
|
2005-11-22 12:34:27 +00:00
|
|
|
user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (vorbisenc));
|
2003-11-24 04:08:48 +00:00
|
|
|
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,
|
2005-11-22 12:34:27 +00:00
|
|
|
gst_tag_setter_get_tag_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 *
|
2005-08-20 20:40:25 +00:00
|
|
|
get_constraints_string (GstVorbisEnc * 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
|
2005-08-20 20:40:25 +00:00
|
|
|
update_start_message (GstVorbisEnc * 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
|
2005-08-20 20:40:25 +00:00
|
|
|
gst_vorbisenc_setup (GstVorbisEnc * 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);
|
|
|
|
|
2005-11-21 15:16:29 +00:00
|
|
|
ai.bitrate_hard_min = vorbisenc->min_bitrate;
|
|
|
|
ai.bitrate_hard_max = vorbisenc->max_bitrate;
|
2002-10-20 01:55:28 +00:00
|
|
|
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
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
vorbisenc->next_ts = 0;
|
2005-11-11 16:35:39 +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
|
|
|
}
|
|
|
|
|
2005-11-21 10:09:16 +00:00
|
|
|
static GstFlowReturn
|
2005-09-22 14:35:57 +00:00
|
|
|
gst_vorbisenc_clear (GstVorbisEnc * vorbisenc)
|
|
|
|
{
|
2005-11-21 10:09:16 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
2005-09-22 14:35:57 +00:00
|
|
|
if (vorbisenc->setup) {
|
|
|
|
vorbis_analysis_wrote (&vorbisenc->vd, 0);
|
2005-11-21 10:09:16 +00:00
|
|
|
ret = gst_vorbisenc_output_buffers (vorbisenc);
|
2005-09-22 14:35:57 +00:00
|
|
|
|
|
|
|
vorbisenc->setup = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clean up and exit. vorbis_info_clear() must be called last */
|
|
|
|
vorbis_block_clear (&vorbisenc->vb);
|
|
|
|
vorbis_dsp_clear (&vorbisenc->vd);
|
|
|
|
vorbis_info_clear (&vorbisenc->vi);
|
|
|
|
|
|
|
|
vorbisenc->header_sent = FALSE;
|
2005-11-21 10:09:16 +00:00
|
|
|
|
|
|
|
return ret;
|
2005-09-22 14:35:57 +00:00
|
|
|
}
|
|
|
|
|
2004-05-20 14:45:57 +00:00
|
|
|
/* prepare a buffer for transmission by passing data through libvorbis */
|
|
|
|
static GstBuffer *
|
2005-08-20 20:40:25 +00:00
|
|
|
gst_vorbisenc_buffer_from_packet (GstVorbisEnc * 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);
|
ogg muxing of vorbis and theora now has pages ordered correctly again, even with delays.
Original commit message from CVS:
ogg muxing of vorbis and theora now has pages ordered correctly again,
even with delays.
* ext/ogg/README:
updated with some examples
* ext/theora/theoraenc.c: (granulepos_to_timestamp),
(granulepos_add), (theora_buffer_from_packet):
* ext/vorbis/vorbisenc.c: (granulepos_to_timestamp_offset),
(granulepos_to_timestamp), (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_chain):
implement strategy from ext/ogg/README
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_compare_pads),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_collected):
Fix muxer so that oggz-validate is happy with all streams;
except for no eos mark, and the BOS page ordering
* tests/check/pipelines/theoraenc.c: (check_buffer_is_header),
(check_buffer_granulepos):
* tests/check/pipelines/vorbisenc.c: (check_buffer_granulepos):
update tests to check for OFFSET being set as requested
fixed type of granulepos, it's not a ClockTime
2006-03-05 22:57:58 +00:00
|
|
|
/* see ext/ogg/README; OFFSET_END takes "our" granulepos, OFFSET its
|
|
|
|
* time representation */
|
2006-01-30 15:01:28 +00:00
|
|
|
GST_BUFFER_OFFSET_END (outbuf) = packet->granulepos +
|
|
|
|
vorbisenc->granulepos_offset;
|
ogg muxing of vorbis and theora now has pages ordered correctly again, even with delays.
Original commit message from CVS:
ogg muxing of vorbis and theora now has pages ordered correctly again,
even with delays.
* ext/ogg/README:
updated with some examples
* ext/theora/theoraenc.c: (granulepos_to_timestamp),
(granulepos_add), (theora_buffer_from_packet):
* ext/vorbis/vorbisenc.c: (granulepos_to_timestamp_offset),
(granulepos_to_timestamp), (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_chain):
implement strategy from ext/ogg/README
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_compare_pads),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_collected):
Fix muxer so that oggz-validate is happy with all streams;
except for no eos mark, and the BOS page ordering
* tests/check/pipelines/theoraenc.c: (check_buffer_is_header),
(check_buffer_granulepos):
* tests/check/pipelines/vorbisenc.c: (check_buffer_granulepos):
update tests to check for OFFSET being set as requested
fixed type of granulepos, it's not a ClockTime
2006-03-05 22:57:58 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = granulepos_to_timestamp (vorbisenc,
|
|
|
|
GST_BUFFER_OFFSET_END (outbuf));
|
2006-01-30 15:01:28 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = vorbisenc->next_ts;
|
|
|
|
|
ogg muxing of vorbis and theora now has pages ordered correctly again, even with delays.
Original commit message from CVS:
ogg muxing of vorbis and theora now has pages ordered correctly again,
even with delays.
* ext/ogg/README:
updated with some examples
* ext/theora/theoraenc.c: (granulepos_to_timestamp),
(granulepos_add), (theora_buffer_from_packet):
* ext/vorbis/vorbisenc.c: (granulepos_to_timestamp_offset),
(granulepos_to_timestamp), (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_chain):
implement strategy from ext/ogg/README
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_compare_pads),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_collected):
Fix muxer so that oggz-validate is happy with all streams;
except for no eos mark, and the BOS page ordering
* tests/check/pipelines/theoraenc.c: (check_buffer_is_header),
(check_buffer_granulepos):
* tests/check/pipelines/vorbisenc.c: (check_buffer_granulepos):
update tests to check for OFFSET being set as requested
fixed type of granulepos, it's not a ClockTime
2006-03-05 22:57:58 +00:00
|
|
|
/* update the next timestamp, taking granulepos_offset and subgranule offset
|
|
|
|
* into account */
|
|
|
|
vorbisenc->next_ts =
|
|
|
|
granulepos_to_timestamp_offset (vorbisenc, packet->granulepos);
|
2005-11-11 16:35:39 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) =
|
2006-01-30 15:01:28 +00:00
|
|
|
vorbisenc->next_ts - GST_BUFFER_TIMESTAMP (outbuf);
|
2002-10-20 22:27:53 +00:00
|
|
|
|
ogg muxing of vorbis and theora now has pages ordered correctly again, even with delays.
Original commit message from CVS:
ogg muxing of vorbis and theora now has pages ordered correctly again,
even with delays.
* ext/ogg/README:
updated with some examples
* ext/theora/theoraenc.c: (granulepos_to_timestamp),
(granulepos_add), (theora_buffer_from_packet):
* ext/vorbis/vorbisenc.c: (granulepos_to_timestamp_offset),
(granulepos_to_timestamp), (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_chain):
implement strategy from ext/ogg/README
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_compare_pads),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_collected):
Fix muxer so that oggz-validate is happy with all streams;
except for no eos mark, and the BOS page ordering
* tests/check/pipelines/theoraenc.c: (check_buffer_is_header),
(check_buffer_granulepos):
* tests/check/pipelines/vorbisenc.c: (check_buffer_granulepos):
update tests to check for OFFSET being set as requested
fixed type of granulepos, it's not a ClockTime
2006-03-05 22:57:58 +00:00
|
|
|
GST_LOG_OBJECT (vorbisenc, "encoded buffer of %d bytes",
|
|
|
|
GST_BUFFER_SIZE (outbuf));
|
2004-05-20 14:45:57 +00:00
|
|
|
return outbuf;
|
|
|
|
}
|
2002-10-20 22:27:53 +00:00
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
/* the same as above, but different logic for setting timestamp and granulepos
|
|
|
|
* */
|
|
|
|
static GstBuffer *
|
|
|
|
gst_vorbisenc_buffer_from_header_packet (GstVorbisEnc * vorbisenc,
|
|
|
|
ogg_packet * packet)
|
|
|
|
{
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
|
|
|
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) = 0;
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
GST_DEBUG ("created header packet buffer, %d bytes",
|
|
|
|
GST_BUFFER_SIZE (outbuf));
|
|
|
|
return outbuf;
|
|
|
|
}
|
|
|
|
|
2004-05-20 14:45:57 +00:00
|
|
|
/* push out the buffer and do internal bookkeeping */
|
2005-11-20 14:09:40 +00:00
|
|
|
static GstFlowReturn
|
2005-08-20 20:40:25 +00:00
|
|
|
gst_vorbisenc_push_buffer (GstVorbisEnc * vorbisenc, GstBuffer * buffer)
|
2004-05-20 14:45:57 +00:00
|
|
|
{
|
|
|
|
vorbisenc->bytes_out += GST_BUFFER_SIZE (buffer);
|
2002-10-20 22:27:53 +00:00
|
|
|
|
2005-11-20 14:09:40 +00:00
|
|
|
return gst_pad_push (vorbisenc->srcpad, buffer);
|
2002-10-20 22:27:53 +00:00
|
|
|
}
|
|
|
|
|
2005-11-20 14:09:40 +00:00
|
|
|
static GstFlowReturn
|
2005-08-20 20:40:25 +00:00
|
|
|
gst_vorbisenc_push_packet (GstVorbisEnc * vorbisenc, ogg_packet * packet)
|
2004-05-20 14:45:57 +00:00
|
|
|
{
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
|
|
|
outbuf = gst_vorbisenc_buffer_from_packet (vorbisenc, packet);
|
2005-11-20 14:09:40 +00:00
|
|
|
return gst_vorbisenc_push_buffer (vorbisenc, outbuf);
|
2004-05-20 14:45:57 +00:00
|
|
|
}
|
2004-06-16 09:54:18 +00:00
|
|
|
|
Make caps writable before writing to it.
Original commit message from CVS:
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_sink_setcaps),
(gst_vorbisenc_src_query), (gst_vorbisenc_sink_query),
(gst_vorbisenc_set_header_on_caps), (gst_vorbisenc_sink_event),
(gst_vorbisenc_chain):
* gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_chain),
(gst_audio_convert_caps_remove_format_info),
(gst_audio_convert_getcaps), (gst_audio_convert_setcaps),
(gst_audio_convert_fixate), (gst_audio_convert_channels):
Make caps writable before writing to it.
Fix negotiation in audioconvert some more.
2005-05-09 17:07:27 +00:00
|
|
|
static GstCaps *
|
2004-05-20 17:26:53 +00:00
|
|
|
gst_vorbisenc_set_header_on_caps (GstCaps * caps, GstBuffer * buf1,
|
|
|
|
GstBuffer * buf2, GstBuffer * buf3)
|
|
|
|
{
|
Make caps writable before writing to it.
Original commit message from CVS:
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_sink_setcaps),
(gst_vorbisenc_src_query), (gst_vorbisenc_sink_query),
(gst_vorbisenc_set_header_on_caps), (gst_vorbisenc_sink_event),
(gst_vorbisenc_chain):
* gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_chain),
(gst_audio_convert_caps_remove_format_info),
(gst_audio_convert_getcaps), (gst_audio_convert_setcaps),
(gst_audio_convert_fixate), (gst_audio_convert_channels):
Make caps writable before writing to it.
Fix negotiation in audioconvert some more.
2005-05-09 17:07:27 +00:00
|
|
|
GstStructure *structure;
|
2005-11-21 12:36:22 +00:00
|
|
|
GValue array = { 0 };
|
2004-05-20 17:26:53 +00:00
|
|
|
GValue value = { 0 };
|
|
|
|
|
Make caps writable before writing to it.
Original commit message from CVS:
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_sink_setcaps),
(gst_vorbisenc_src_query), (gst_vorbisenc_sink_query),
(gst_vorbisenc_set_header_on_caps), (gst_vorbisenc_sink_event),
(gst_vorbisenc_chain):
* gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_chain),
(gst_audio_convert_caps_remove_format_info),
(gst_audio_convert_getcaps), (gst_audio_convert_setcaps),
(gst_audio_convert_fixate), (gst_audio_convert_channels):
Make caps writable before writing to it.
Fix negotiation in audioconvert some more.
2005-05-09 17:07:27 +00:00
|
|
|
caps = gst_caps_make_writable (caps);
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2004-05-20 17:26:53 +00:00
|
|
|
/* mark buffers */
|
Port from GstData to GstMiniObject.
Original commit message from CVS:
Port from GstData to GstMiniObject.
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_dispose):
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_set_header_on_caps),
(gst_ogg_mux_collected):
* ext/ogg/gstogmparse.c: (gst_ogm_parse_chain):
* ext/theora/theoradec.c: (theora_handle_comment_packet),
(theora_handle_data_packet):
* ext/theora/theoraenc.c: (theora_buffer_from_packet),
(theora_set_header_on_caps), (theora_enc_chain):
* ext/vorbis/vorbisdec.c: (vorbis_dec_sink_event),
(vorbis_handle_comment_packet):
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_set_header_on_caps):
* ext/vorbis/vorbisparse.c: (vorbis_parse_set_header_on_caps):
* gst-libs/gst/audio/gstaudiofilter.c: (gst_audiofilter_chain):
* gst-libs/gst/tag/gstvorbistag.c: (gst_vorbis_tag_chain):
* gst/audioconvert/gstaudioconvert.c:
(gst_audio_convert_get_buffer):
* gst/playback/gstdecodebin.c: (gst_decode_bin_class_init):
* gst/playback/gstplaybasebin.c: (check_queue), (probe_triggered),
(mute_stream), (silence_stream):
* gst/playback/gstplaybin.c: (gst_play_bin_class_init):
* gst/volume/gstvolume.c: (volume_transform):
* sys/ximage/ximagesink.c: (gst_ximage_buffer_finalize),
(gst_ximage_buffer_init), (gst_ximage_buffer_class_init),
(gst_ximage_buffer_get_type), (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new), (gst_ximagesink_ximage_destroy),
(gst_ximagesink_ximage_put), (gst_ximagesink_imagepool_clear),
(gst_ximagesink_show_frame), (gst_ximagesink_buffer_free),
(gst_ximagesink_buffer_alloc):
* sys/ximage/ximagesink.h:
2005-05-16 15:35:52 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buf1, GST_BUFFER_FLAG_IN_CAPS);
|
|
|
|
GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_FLAG_IN_CAPS);
|
|
|
|
GST_BUFFER_FLAG_SET (buf3, GST_BUFFER_FLAG_IN_CAPS);
|
2004-05-20 17:26:53 +00:00
|
|
|
|
|
|
|
/* put buffers in a fixed list */
|
2005-11-21 12:36:22 +00:00
|
|
|
g_value_init (&array, GST_TYPE_ARRAY);
|
2004-05-20 17:26:53 +00:00
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
2005-06-22 09:57:59 +00:00
|
|
|
gst_value_set_buffer (&value, buf1);
|
2005-11-21 12:36:22 +00:00
|
|
|
gst_value_array_append_value (&array, &value);
|
2004-05-20 17:26:53 +00:00
|
|
|
g_value_unset (&value);
|
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
2005-06-22 09:57:59 +00:00
|
|
|
gst_value_set_buffer (&value, buf2);
|
2005-11-21 12:36:22 +00:00
|
|
|
gst_value_array_append_value (&array, &value);
|
2004-05-20 17:26:53 +00:00
|
|
|
g_value_unset (&value);
|
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
2005-06-22 09:57:59 +00:00
|
|
|
gst_value_set_buffer (&value, buf3);
|
2005-11-21 12:36:22 +00:00
|
|
|
gst_value_array_append_value (&array, &value);
|
|
|
|
gst_structure_set_value (structure, "streamheader", &array);
|
2004-05-20 17:26:53 +00:00
|
|
|
g_value_unset (&value);
|
2005-11-21 12:36:22 +00:00
|
|
|
g_value_unset (&array);
|
Make caps writable before writing to it.
Original commit message from CVS:
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_sink_setcaps),
(gst_vorbisenc_src_query), (gst_vorbisenc_sink_query),
(gst_vorbisenc_set_header_on_caps), (gst_vorbisenc_sink_event),
(gst_vorbisenc_chain):
* gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_chain),
(gst_audio_convert_caps_remove_format_info),
(gst_audio_convert_getcaps), (gst_audio_convert_setcaps),
(gst_audio_convert_fixate), (gst_audio_convert_channels):
Make caps writable before writing to it.
Fix negotiation in audioconvert some more.
2005-05-09 17:07:27 +00:00
|
|
|
|
|
|
|
return caps;
|
2004-05-20 17:26:53 +00:00
|
|
|
}
|
2004-05-20 14:45:57 +00:00
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vorbisenc_sink_event (GstPad * pad, GstEvent * event)
|
2001-12-20 22:30:14 +00:00
|
|
|
{
|
2005-03-31 09:43:49 +00:00
|
|
|
gboolean res = TRUE;
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
vorbisenc = GST_VORBISENC (GST_PAD_PARENT (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_EOS:
|
2005-09-15 19:59:50 +00:00
|
|
|
/* 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 */
|
|
|
|
GST_DEBUG_OBJECT (vorbisenc, "EOS, clearing state and sending event on");
|
2005-09-22 14:35:57 +00:00
|
|
|
gst_vorbisenc_clear (vorbisenc);
|
2005-09-15 19:59:50 +00:00
|
|
|
|
2005-10-27 11:33:09 +00:00
|
|
|
res = gst_pad_push_event (vorbisenc->srcpad, event);
|
2005-03-31 09:43:49 +00:00
|
|
|
break;
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
if (vorbisenc->tags) {
|
examples/seeking/seek.c: Update seek example.
Original commit message from CVS:
* examples/seeking/seek.c: (setup_dynamic_link),
(make_dv_pipeline), (make_vorbis_theora_pipeline), (query_rates),
(query_positions_elems), (query_positions_pads), (do_seek):
Update seek example.
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_event),
(gst_ogg_pad_typefind), (gst_ogg_demux_chain_elem_pad),
(gst_ogg_demux_queue_data), (gst_ogg_demux_chain_peer),
(gst_ogg_pad_submit_packet), (gst_ogg_pad_submit_page),
(gst_ogg_demux_handle_event),
(gst_ogg_demux_deactivate_current_chain),
(gst_ogg_demux_activate_chain), (gst_ogg_demux_perform_seek),
(gst_ogg_demux_collect_chain_info), (gst_ogg_demux_collect_info),
(gst_ogg_demux_chain), (gst_ogg_demux_send_event),
(gst_ogg_demux_loop):
* ext/ogg/gstoggmux.c: (gst_ogg_mux_collected):
* ext/theora/theoradec.c: (theora_dec_src_event),
(theora_dec_src_getcaps), (theora_dec_sink_event),
(theora_dec_push), (theora_dec_chain):
* ext/vorbis/Makefile.am:
* ext/vorbis/vorbisdec.c: (vorbis_dec_src_event),
(vorbis_dec_sink_event), (vorbis_dec_push),
(vorbis_handle_data_packet):
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_sink_event),
(gst_vorbisenc_chain):
* gst/playback/gststreaminfo.c: (cb_probe):
* gst/subparse/gstsubparse.c: (gst_subparse_src_event):
* gst/videorate/gstvideorate.c: (gst_videorate_event):
* gst/videoscale/gstvideoscale.c:
(gst_videoscale_handle_src_event):
* gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_event):
* sys/ximage/ximagesink.c: (gst_ximagesink_show_frame),
(gst_ximagesink_navigation_send_event):
* sys/xvimage/xvimagesink.c:
(gst_xvimagesink_navigation_send_event):
Various event updates and cleanups
2005-07-27 18:34:29 +00:00
|
|
|
GstTagList *list;
|
|
|
|
|
|
|
|
gst_event_parse_tag (event, &list);
|
|
|
|
gst_tag_list_insert (vorbisenc->tags, list,
|
2005-11-22 12:34:27 +00:00
|
|
|
gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (vorbisenc)));
|
2005-03-31 09:43:49 +00:00
|
|
|
} else {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2005-10-27 11:33:09 +00:00
|
|
|
res = gst_pad_push_event (vorbisenc->srcpad, event);
|
2005-03-31 09:43:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
2005-10-27 11:33:09 +00:00
|
|
|
res = gst_pad_push_event (vorbisenc->srcpad, event);
|
2005-03-31 09:43:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_vorbisenc_chain (GstPad * pad, GstBuffer * buffer)
|
|
|
|
{
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2005-11-21 10:09:16 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2006-01-30 15:01:28 +00:00
|
|
|
gfloat *data;
|
|
|
|
gulong size;
|
|
|
|
gulong i, j;
|
|
|
|
float **vorbis_buffer;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
vorbisenc = GST_VORBISENC (GST_PAD_PARENT (pad));
|
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
if (!vorbisenc->setup)
|
|
|
|
goto not_setup;
|
|
|
|
|
|
|
|
if (!vorbisenc->header_sent) {
|
|
|
|
/* Vorbis streams begin with three headers; the initial header (with
|
|
|
|
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 */
|
|
|
|
ogg_packet header;
|
|
|
|
ogg_packet header_comm;
|
|
|
|
ogg_packet header_code;
|
|
|
|
GstBuffer *buf1, *buf2, *buf3;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
/* first, make sure header buffers get timestamp == 0 */
|
|
|
|
vorbisenc->next_ts = 0;
|
|
|
|
vorbisenc->granulepos_offset = 0;
|
|
|
|
vorbisenc->subgranule_offset = 0;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (vorbisenc, "creating and sending header packets");
|
|
|
|
gst_vorbisenc_set_metadata (vorbisenc);
|
|
|
|
vorbis_analysis_headerout (&vorbisenc->vd, &vorbisenc->vc, &header,
|
|
|
|
&header_comm, &header_code);
|
2006-02-05 23:31:05 +00:00
|
|
|
vorbis_comment_clear (&vorbisenc->vc);
|
2006-01-30 15:01:28 +00:00
|
|
|
|
|
|
|
/* create header buffers */
|
|
|
|
buf1 = gst_vorbisenc_buffer_from_header_packet (vorbisenc, &header);
|
|
|
|
buf2 = gst_vorbisenc_buffer_from_header_packet (vorbisenc, &header_comm);
|
|
|
|
buf3 = gst_vorbisenc_buffer_from_header_packet (vorbisenc, &header_code);
|
|
|
|
|
|
|
|
/* mark and put on caps */
|
|
|
|
caps = gst_pad_get_caps (vorbisenc->srcpad);
|
|
|
|
caps = 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_set_caps (vorbisenc->srcpad, caps);
|
|
|
|
|
|
|
|
gst_buffer_set_caps (buf1, caps);
|
|
|
|
gst_buffer_set_caps (buf2, caps);
|
|
|
|
gst_buffer_set_caps (buf3, caps);
|
|
|
|
|
|
|
|
/* push out buffers */
|
|
|
|
if ((ret = gst_vorbisenc_push_buffer (vorbisenc, buf1)) != GST_FLOW_OK)
|
|
|
|
goto failed_header_push;
|
|
|
|
if ((ret = gst_vorbisenc_push_buffer (vorbisenc, buf2)) != GST_FLOW_OK)
|
|
|
|
goto failed_header_push;
|
|
|
|
if ((ret = gst_vorbisenc_push_buffer (vorbisenc, buf3)) != GST_FLOW_OK)
|
|
|
|
goto failed_header_push;
|
|
|
|
|
|
|
|
|
|
|
|
/* now adjust starting granulepos accordingly if the buffer's timestamp is
|
|
|
|
nonzero */
|
|
|
|
vorbisenc->next_ts = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
vorbisenc->granulepos_offset = gst_util_uint64_scale
|
|
|
|
(GST_BUFFER_TIMESTAMP (buffer), vorbisenc->frequency, GST_SECOND);
|
|
|
|
vorbisenc->subgranule_offset = 0;
|
|
|
|
vorbisenc->subgranule_offset =
|
ogg muxing of vorbis and theora now has pages ordered correctly again, even with delays.
Original commit message from CVS:
ogg muxing of vorbis and theora now has pages ordered correctly again,
even with delays.
* ext/ogg/README:
updated with some examples
* ext/theora/theoraenc.c: (granulepos_to_timestamp),
(granulepos_add), (theora_buffer_from_packet):
* ext/vorbis/vorbisenc.c: (granulepos_to_timestamp_offset),
(granulepos_to_timestamp), (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_chain):
implement strategy from ext/ogg/README
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_compare_pads),
(gst_ogg_mux_queue_pads), (gst_ogg_mux_collected):
Fix muxer so that oggz-validate is happy with all streams;
except for no eos mark, and the BOS page ordering
* tests/check/pipelines/theoraenc.c: (check_buffer_is_header),
(check_buffer_granulepos):
* tests/check/pipelines/vorbisenc.c: (check_buffer_granulepos):
update tests to check for OFFSET being set as requested
fixed type of granulepos, it's not a ClockTime
2006-03-05 22:57:58 +00:00
|
|
|
vorbisenc->next_ts - granulepos_to_timestamp_offset (vorbisenc, 0);
|
2006-01-30 15:01:28 +00:00
|
|
|
|
|
|
|
vorbisenc->header_sent = TRUE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
/* data to encode */
|
|
|
|
data = (gfloat *) GST_BUFFER_DATA (buffer);
|
|
|
|
size = GST_BUFFER_SIZE (buffer) / (vorbisenc->channels * sizeof (float));
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
/* expose the buffer to submit data */
|
|
|
|
vorbis_buffer = vorbis_analysis_buffer (&vorbisenc->vd, size);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
/* deinterleave samples, write the buffer data */
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
for (j = 0; j < vorbisenc->channels; j++) {
|
|
|
|
vorbis_buffer[j][i] = *data++;
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
2006-01-30 15:01:28 +00:00
|
|
|
}
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
/* tell the library how much we actually submitted */
|
|
|
|
vorbis_analysis_wrote (&vorbisenc->vd, size);
|
2002-10-20 17:11:10 +00:00
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
vorbisenc->samples_in += size;
|
2001-12-21 01:14:21 +00:00
|
|
|
|
2006-01-30 15:01:28 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2001-12-20 22:30:14 +00:00
|
|
|
|
2005-11-21 10:09:16 +00:00
|
|
|
ret = gst_vorbisenc_output_buffers (vorbisenc);
|
2005-09-15 19:59:50 +00:00
|
|
|
|
2005-11-21 10:09:16 +00:00
|
|
|
return ret;
|
2006-01-30 15:01:28 +00:00
|
|
|
|
|
|
|
/* error cases */
|
|
|
|
not_setup:
|
|
|
|
{
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
GST_ELEMENT_ERROR (vorbisenc, CORE, NEGOTIATION, (NULL),
|
|
|
|
("encoder not initialized (input is not audio?)"));
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
}
|
|
|
|
failed_header_push:
|
|
|
|
{
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return ret;
|
|
|
|
}
|
2005-09-15 19:59:50 +00:00
|
|
|
}
|
|
|
|
|
2005-11-21 10:09:16 +00:00
|
|
|
static GstFlowReturn
|
2005-09-15 19:59:50 +00:00
|
|
|
gst_vorbisenc_output_buffers (GstVorbisEnc * vorbisenc)
|
|
|
|
{
|
2005-11-21 10:09:16 +00:00
|
|
|
GstFlowReturn ret;
|
|
|
|
|
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
|
|
|
|
2005-08-20 20:40:25 +00:00
|
|
|
GST_LOG_OBJECT (vorbisenc, "analysed to a block");
|
|
|
|
|
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)) {
|
2005-08-20 20:40:25 +00:00
|
|
|
GST_LOG_OBJECT (vorbisenc, "pushing out a data packet");
|
2005-11-21 10:09:16 +00:00
|
|
|
ret = gst_vorbisenc_push_packet (vorbisenc, &op);
|
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
2001-12-20 22:30:14 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-21 10:09:16 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
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
|
|
|
{
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc;
|
2001-12-20 22:30:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_vorbisenc_change_state (GstElement * element, GstStateChange transition)
|
2002-10-19 16:57:08 +00:00
|
|
|
{
|
2005-08-20 20:40:25 +00:00
|
|
|
GstVorbisEnc *vorbisenc = GST_VORBISENC (element);
|
2005-09-02 15:43:18 +00:00
|
|
|
GstStateChangeReturn res;
|
2005-03-31 09:43:49 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
switch (transition) {
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2005-08-24 21:03:32 +00:00
|
|
|
vorbisenc->tags = gst_tag_list_new ();
|
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2005-10-27 11:33:09 +00:00
|
|
|
vorbisenc->setup = FALSE;
|
|
|
|
vorbisenc->header_sent = FALSE;
|
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2005-10-27 11:33:09 +00:00
|
|
|
break;
|
2005-03-31 09:43:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2005-03-31 09:43:49 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
2002-10-19 16:57:08 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2005-10-27 11:33:09 +00:00
|
|
|
vorbis_block_clear (&vorbisenc->vb);
|
|
|
|
vorbis_dsp_clear (&vorbisenc->vd);
|
|
|
|
vorbis_info_clear (&vorbisenc->vi);
|
ext/: Fix a small memory leak in vorbisenc.
Original commit message from CVS:
* ext/ogg/gstoggmux.c: (gst_ogg_mux_clear), (gst_ogg_mux_init),
(gst_ogg_mux_sinkconnect), (gst_ogg_mux_request_new_pad),
(gst_ogg_mux_push_buffer), (gst_ogg_mux_dequeue_page),
(gst_ogg_mux_pad_queue_page), (gst_ogg_mux_queue_pads),
(gst_ogg_mux_set_header_on_caps), (gst_ogg_mux_collected),
(gst_ogg_mux_clear_collectpads), (gst_ogg_mux_change_state):
* ext/vorbis/vorbisenc.c: (gst_vorbisenc_buffer_from_packet),
(gst_vorbisenc_change_state):
Fix a small memory leak in vorbisenc.
Fix large memory leaks in oggmux, also fix lots of state change
bugs in oggmux.
2005-11-14 16:11:53 +00:00
|
|
|
g_free (vorbisenc->last_message);
|
|
|
|
vorbisenc->last_message = NULL;
|
2002-10-19 16:57:08 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2005-08-24 21:03:32 +00:00
|
|
|
gst_tag_list_free (vorbisenc->tags);
|
|
|
|
vorbisenc->tags = NULL;
|
2002-10-19 16:57:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
return res;
|
2002-10-19 16:57:08 +00:00
|
|
|
}
|