ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
|
2012-03-07 11:22:14 +00:00
|
|
|
* Copyright (c) 2012 Collabora Ltd.
|
|
|
|
* Author : Edward Hervey <edward@collabora.com>
|
|
|
|
* Author : Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
*/
|
|
|
|
|
2005-09-14 21:36:02 +00:00
|
|
|
/**
|
2005-09-14 21:53:06 +00:00
|
|
|
* SECTION:element-theoraenc
|
2017-01-23 19:36:11 +00:00
|
|
|
* @title: theoraenc
|
2005-09-14 21:36:02 +00:00
|
|
|
* @see_also: theoradec, oggmux
|
|
|
|
*
|
|
|
|
* This element encodes raw video into a Theora stream.
|
2019-08-23 16:28:16 +00:00
|
|
|
* [Theora](http://www.theora.org/) is a royalty-free
|
|
|
|
* video codec maintained by the [Xiph.org Foundation](http://www.xiph.org/),
|
|
|
|
* based on the VP3 codec.
|
2008-07-10 21:06:06 +00:00
|
|
|
*
|
2006-03-01 16:24:37 +00:00
|
|
|
* The theora codec internally only supports encoding of images that are a
|
2006-04-10 14:52:10 +00:00
|
|
|
* multiple of 16 pixels in both X and Y direction. It is however perfectly
|
|
|
|
* possible to encode images with other dimensions because an arbitrary
|
|
|
|
* rectangular cropping region can be set up. This element will automatically
|
|
|
|
* set up a correct cropping region if the dimensions are not multiples of 16
|
2009-09-08 11:18:26 +00:00
|
|
|
* pixels.
|
2008-07-10 21:06:06 +00:00
|
|
|
*
|
2018-10-22 06:17:24 +00:00
|
|
|
* To control the quality of the encoding, the #GstTheoraEnc:bitrate and
|
|
|
|
* #GstTheoraEnc:quality properties can be used. These two properties are
|
2008-07-10 21:06:06 +00:00
|
|
|
* mutualy exclusive. Setting the bitrate property will produce a constant
|
|
|
|
* bitrate (CBR) stream while setting the quality property will produce a
|
|
|
|
* variable bitrate (VBR) stream.
|
|
|
|
*
|
2015-08-11 14:09:10 +00:00
|
|
|
* A videorate element is often required in front of theoraenc, especially
|
|
|
|
* when transcoding and when putting Theora into the Ogg container.
|
|
|
|
*
|
2017-01-23 19:36:11 +00:00
|
|
|
* ## Example pipeline
|
2008-07-10 21:06:06 +00:00
|
|
|
* |[
|
2015-05-09 21:33:26 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc num-buffers=500 ! video/x-raw,width=1280,height=720 ! queue ! progressreport ! theoraenc ! oggmux ! filesink location=videotestsrc.ogg
|
2017-01-23 19:36:11 +00:00
|
|
|
* ]|
|
|
|
|
* This example pipeline will encode a test video source to theora muxed in an
|
2006-04-10 14:52:10 +00:00
|
|
|
* ogg container. Refer to the theoradec documentation to decode the create
|
|
|
|
* stream.
|
2017-01-23 19:36:11 +00:00
|
|
|
*
|
2005-09-14 21:36:02 +00:00
|
|
|
*/
|
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-09-21 22:57:42 +00:00
|
|
|
#include "config.h"
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
2006-04-29 09:48:16 +00:00
|
|
|
#include <stdlib.h> /* free */
|
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2009-09-09 21:44:36 +00:00
|
|
|
#include <gst/video/video.h>
|
2012-04-25 10:43:28 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2012-12-12 17:22:31 +00:00
|
|
|
#include "gsttheoraenc.h"
|
|
|
|
|
2004-07-14 13:42:23 +00:00
|
|
|
#define GST_CAT_DEFAULT theoraenc_debug
|
2006-05-23 20:38:56 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2010-07-04 18:29:53 +00:00
|
|
|
#define GST_TYPE_MULTIPASS_MODE (gst_multipass_mode_get_type())
|
|
|
|
static GType
|
|
|
|
gst_multipass_mode_get_type (void)
|
|
|
|
{
|
|
|
|
static GType multipass_mode_type = 0;
|
|
|
|
static const GEnumValue multipass_mode[] = {
|
|
|
|
{MULTIPASS_MODE_SINGLE_PASS, "Single pass", "single-pass"},
|
|
|
|
{MULTIPASS_MODE_FIRST_PASS, "First pass", "first-pass"},
|
|
|
|
{MULTIPASS_MODE_SECOND_PASS, "Second pass", "second-pass"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!multipass_mode_type) {
|
|
|
|
multipass_mode_type =
|
|
|
|
g_enum_register_static ("GstTheoraEncMultipassMode", multipass_mode);
|
|
|
|
}
|
|
|
|
return multipass_mode_type;
|
|
|
|
}
|
|
|
|
|
2006-01-30 19:21:07 +00:00
|
|
|
/* taken from theora/lib/toplevel.c */
|
|
|
|
static int
|
|
|
|
_ilog (unsigned int v)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
while (v) {
|
|
|
|
ret++;
|
|
|
|
v >>= 1;
|
|
|
|
}
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2006-03-01 16:24:37 +00:00
|
|
|
#define THEORA_DEF_BITRATE 0
|
2009-10-07 14:56:28 +00:00
|
|
|
#define THEORA_DEF_QUALITY 48
|
2006-03-01 16:24:37 +00:00
|
|
|
#define THEORA_DEF_KEYFRAME_AUTO TRUE
|
|
|
|
#define THEORA_DEF_KEYFRAME_FREQ 64
|
|
|
|
#define THEORA_DEF_KEYFRAME_FREQ_FORCE 64
|
2009-02-19 20:18:29 +00:00
|
|
|
#define THEORA_DEF_SPEEDLEVEL 1
|
2009-12-21 01:34:46 +00:00
|
|
|
#define THEORA_DEF_VP3_COMPATIBLE FALSE
|
|
|
|
#define THEORA_DEF_DROP_FRAMES TRUE
|
|
|
|
#define THEORA_DEF_CAP_OVERFLOW TRUE
|
|
|
|
#define THEORA_DEF_CAP_UNDERFLOW FALSE
|
|
|
|
#define THEORA_DEF_RATE_BUFFER 0
|
2010-07-04 18:29:53 +00:00
|
|
|
#define THEORA_DEF_MULTIPASS_CACHE_FILE NULL
|
|
|
|
#define THEORA_DEF_MULTIPASS_MODE MULTIPASS_MODE_SINGLE_PASS
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
enum
|
|
|
|
{
|
2010-07-04 18:08:25 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_BITRATE,
|
|
|
|
PROP_QUALITY,
|
|
|
|
PROP_KEYFRAME_AUTO,
|
|
|
|
PROP_KEYFRAME_FREQ,
|
|
|
|
PROP_KEYFRAME_FREQ_FORCE,
|
|
|
|
PROP_SPEEDLEVEL,
|
|
|
|
PROP_VP3_COMPATIBLE,
|
|
|
|
PROP_DROP_FRAMES,
|
|
|
|
PROP_CAP_OVERFLOW,
|
|
|
|
PROP_CAP_UNDERFLOW,
|
|
|
|
PROP_RATE_BUFFER,
|
2010-07-04 18:29:53 +00:00
|
|
|
PROP_MULTIPASS_CACHE_FILE,
|
2012-03-07 11:22:14 +00:00
|
|
|
PROP_MULTIPASS_MODE
|
2010-07-04 18:29:53 +00:00
|
|
|
/* FILL ME */
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +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 (GstTheoraEnc * theoraenc, ogg_int64_t granulepos)
|
|
|
|
{
|
|
|
|
guint64 iframe, pframe;
|
2009-09-09 21:44:36 +00:00
|
|
|
int shift = theoraenc->info.keyframe_granule_shift;
|
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
|
|
|
|
|
|
|
if (granulepos < 0)
|
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
iframe = granulepos >> shift;
|
|
|
|
pframe = granulepos - (iframe << shift);
|
|
|
|
|
|
|
|
/* num and den are 32 bit, so we can safely multiply with GST_SECOND */
|
|
|
|
return gst_util_uint64_scale ((guint64) (iframe + pframe),
|
|
|
|
GST_SECOND * theoraenc->info.fps_denominator,
|
|
|
|
theoraenc->info.fps_numerator);
|
|
|
|
}
|
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
static GstStaticPadTemplate theora_enc_sink_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-04-24 19:32:28 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-raw, "
|
|
|
|
"format = (string) { I420, Y42B, Y444 }, "
|
2010-03-08 20:57:03 +00:00
|
|
|
"framerate = (fraction) [1/MAX, MAX], "
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
"width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate theora_enc_src_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-04-24 19:32:28 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-theora, "
|
|
|
|
"framerate = (fraction) [1/MAX, MAX], "
|
|
|
|
"width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]")
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
);
|
|
|
|
|
2012-04-24 19:32:28 +00:00
|
|
|
#define gst_theora_enc_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstTheoraEnc, gst_theora_enc, GST_TYPE_VIDEO_ENCODER);
|
2009-05-14 09:43:07 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
static gboolean theora_enc_start (GstVideoEncoder * enc);
|
|
|
|
static gboolean theora_enc_stop (GstVideoEncoder * enc);
|
2013-08-15 11:15:05 +00:00
|
|
|
static gboolean theora_enc_flush (GstVideoEncoder * enc);
|
2012-03-07 11:22:14 +00:00
|
|
|
static gboolean theora_enc_set_format (GstVideoEncoder * enc,
|
|
|
|
GstVideoCodecState * state);
|
|
|
|
static GstFlowReturn theora_enc_handle_frame (GstVideoEncoder * enc,
|
|
|
|
GstVideoCodecFrame * frame);
|
|
|
|
static GstFlowReturn theora_enc_pre_push (GstVideoEncoder * benc,
|
|
|
|
GstVideoCodecFrame * frame);
|
|
|
|
static GstFlowReturn theora_enc_finish (GstVideoEncoder * enc);
|
2012-04-25 10:43:28 +00:00
|
|
|
static gboolean theora_enc_propose_allocation (GstVideoEncoder * encoder,
|
|
|
|
GstQuery * query);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2012-04-24 19:32:28 +00:00
|
|
|
static GstCaps *theora_enc_getcaps (GstVideoEncoder * encoder,
|
|
|
|
GstCaps * filter);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
static void theora_enc_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void theora_enc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2006-02-05 23:31:05 +00:00
|
|
|
static void theora_enc_finalize (GObject * object);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2011-03-25 15:59:51 +00:00
|
|
|
static gboolean theora_enc_write_multipass_cache (GstTheoraEnc * enc,
|
|
|
|
gboolean begin, gboolean eos);
|
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
static void
|
2012-04-24 19:32:28 +00:00
|
|
|
gst_theora_enc_class_init (GstTheoraEncClass * klass)
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
{
|
2012-04-24 19:32:28 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *element_class = (GstElementClass *) klass;
|
|
|
|
GstVideoEncoderClass *gstvideo_encoder_class =
|
|
|
|
GST_VIDEO_ENCODER_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property = theora_enc_set_property;
|
|
|
|
gobject_class->get_property = theora_enc_get_property;
|
|
|
|
gobject_class->finalize = theora_enc_finalize;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2016-03-03 07:46:24 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&theora_enc_src_factory);
|
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&theora_enc_sink_factory);
|
|
|
|
gst_element_class_set_static_metadata (element_class, "Theora video encoder",
|
|
|
|
"Codec/Encoder/Video", "encode raw YUV video to a theora stream",
|
2010-03-16 14:45:23 +00:00
|
|
|
"Wim Taymans <wim@fluendo.com>");
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
gstvideo_encoder_class->start = GST_DEBUG_FUNCPTR (theora_enc_start);
|
|
|
|
gstvideo_encoder_class->stop = GST_DEBUG_FUNCPTR (theora_enc_stop);
|
2013-08-15 11:15:05 +00:00
|
|
|
gstvideo_encoder_class->flush = GST_DEBUG_FUNCPTR (theora_enc_flush);
|
2012-03-07 11:22:14 +00:00
|
|
|
gstvideo_encoder_class->set_format =
|
|
|
|
GST_DEBUG_FUNCPTR (theora_enc_set_format);
|
|
|
|
gstvideo_encoder_class->handle_frame =
|
|
|
|
GST_DEBUG_FUNCPTR (theora_enc_handle_frame);
|
|
|
|
gstvideo_encoder_class->pre_push = GST_DEBUG_FUNCPTR (theora_enc_pre_push);
|
|
|
|
gstvideo_encoder_class->finish = GST_DEBUG_FUNCPTR (theora_enc_finish);
|
2012-04-24 19:32:28 +00:00
|
|
|
gstvideo_encoder_class->getcaps = GST_DEBUG_FUNCPTR (theora_enc_getcaps);
|
2012-04-25 10:43:28 +00:00
|
|
|
gstvideo_encoder_class->propose_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (theora_enc_propose_allocation);
|
2012-03-07 11:22:14 +00:00
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
/* general encoding stream options */
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BITRATE,
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
g_param_spec_int ("bitrate", "Bitrate", "Compressed video bitrate (kbps)",
|
2008-08-13 00:59:07 +00:00
|
|
|
0, (1 << 24) - 1, THEORA_DEF_BITRATE,
|
2010-09-21 22:57:42 +00:00
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
|
|
|
GST_PARAM_MUTABLE_PLAYING));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_QUALITY,
|
2008-03-22 15:00:53 +00:00
|
|
|
g_param_spec_int ("quality", "Quality", "Video quality", 0, 63,
|
|
|
|
THEORA_DEF_QUALITY,
|
2010-09-21 22:57:42 +00:00
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
|
|
|
GST_PARAM_MUTABLE_PLAYING));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_KEYFRAME_AUTO,
|
2004-06-10 14:59:17 +00:00
|
|
|
g_param_spec_boolean ("keyframe-auto", "Keyframe Auto",
|
|
|
|
"Automatic keyframe detection", THEORA_DEF_KEYFRAME_AUTO,
|
2008-03-22 15:00:53 +00:00
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_KEYFRAME_FREQ,
|
2004-06-10 14:59:17 +00:00
|
|
|
g_param_spec_int ("keyframe-freq", "Keyframe frequency",
|
|
|
|
"Keyframe frequency", 1, 32768, THEORA_DEF_KEYFRAME_FREQ,
|
2008-03-22 15:00:53 +00:00
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_KEYFRAME_FREQ_FORCE,
|
2004-06-10 14:59:17 +00:00
|
|
|
g_param_spec_int ("keyframe-force", "Keyframe force",
|
|
|
|
"Force keyframe every N frames", 1, 32768,
|
2008-03-22 15:00:53 +00:00
|
|
|
THEORA_DEF_KEYFRAME_FREQ_FORCE,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SPEEDLEVEL,
|
2009-02-19 20:18:29 +00:00
|
|
|
g_param_spec_int ("speed-level", "Speed level",
|
2012-06-28 21:59:14 +00:00
|
|
|
"Controls the amount of motion vector searching done while encoding",
|
2012-03-07 11:22:14 +00:00
|
|
|
0, 3, THEORA_DEF_SPEEDLEVEL,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_VP3_COMPATIBLE,
|
2012-06-28 21:59:14 +00:00
|
|
|
g_param_spec_boolean ("vp3-compatible", "VP3 compatible",
|
|
|
|
"Disables non-VP3 compatible features",
|
2009-12-21 01:34:46 +00:00
|
|
|
THEORA_DEF_VP3_COMPATIBLE,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DROP_FRAMES,
|
2012-06-28 21:59:14 +00:00
|
|
|
g_param_spec_boolean ("drop-frames", "Drop frames",
|
|
|
|
"Allow or disallow frame dropping",
|
2009-12-21 01:34:46 +00:00
|
|
|
THEORA_DEF_DROP_FRAMES,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CAP_OVERFLOW,
|
2012-06-28 21:59:14 +00:00
|
|
|
g_param_spec_boolean ("cap-overflow", "Cap overflow",
|
|
|
|
"Enable capping of bit reservoir overflows",
|
2009-12-21 01:34:46 +00:00
|
|
|
THEORA_DEF_CAP_OVERFLOW,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CAP_UNDERFLOW,
|
2012-06-28 21:59:14 +00:00
|
|
|
g_param_spec_boolean ("cap-underflow", "Cap underflow",
|
|
|
|
"Enable capping of bit reservoir underflows",
|
2009-12-21 01:34:46 +00:00
|
|
|
THEORA_DEF_CAP_UNDERFLOW,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:08:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RATE_BUFFER,
|
2009-12-21 01:34:46 +00:00
|
|
|
g_param_spec_int ("rate-buffer", "Rate Control Buffer",
|
|
|
|
"Sets the size of the rate control buffer, in units of frames. "
|
|
|
|
"The default value of 0 instructs the encoder to automatically "
|
2012-06-28 21:59:14 +00:00
|
|
|
"select an appropriate value",
|
2009-12-21 01:34:46 +00:00
|
|
|
0, 1000, THEORA_DEF_RATE_BUFFER,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-07-04 18:29:53 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MULTIPASS_CACHE_FILE,
|
|
|
|
g_param_spec_string ("multipass-cache-file", "Multipass Cache File",
|
|
|
|
"Multipass cache file", THEORA_DEF_MULTIPASS_CACHE_FILE,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MULTIPASS_MODE,
|
|
|
|
g_param_spec_enum ("multipass-mode", "Multipass mode",
|
|
|
|
"Single pass or first/second pass", GST_TYPE_MULTIPASS_MODE,
|
|
|
|
THEORA_DEF_MULTIPASS_MODE,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-06-02 15:29:53 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (theoraenc_debug, "theoraenc", 0, "Theora encoder");
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-24 19:32:28 +00:00
|
|
|
gst_theora_enc_init (GstTheoraEnc * enc)
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
{
|
2015-08-16 01:22:41 +00:00
|
|
|
GST_PAD_SET_ACCEPT_TEMPLATE (GST_VIDEO_ENCODER_SINK_PAD (enc));
|
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
enc->video_bitrate = THEORA_DEF_BITRATE;
|
|
|
|
enc->video_quality = THEORA_DEF_QUALITY;
|
2004-06-10 14:59:17 +00:00
|
|
|
enc->keyframe_auto = THEORA_DEF_KEYFRAME_AUTO;
|
|
|
|
enc->keyframe_freq = THEORA_DEF_KEYFRAME_FREQ;
|
|
|
|
enc->keyframe_force = THEORA_DEF_KEYFRAME_FREQ_FORCE;
|
2006-01-30 19:21:07 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
enc->speed_level = THEORA_DEF_SPEEDLEVEL;
|
2009-12-21 01:34:46 +00:00
|
|
|
enc->vp3_compatible = THEORA_DEF_VP3_COMPATIBLE;
|
|
|
|
enc->drop_frames = THEORA_DEF_DROP_FRAMES;
|
|
|
|
enc->cap_overflow = THEORA_DEF_CAP_OVERFLOW;
|
|
|
|
enc->cap_underflow = THEORA_DEF_CAP_UNDERFLOW;
|
|
|
|
enc->rate_buffer = THEORA_DEF_RATE_BUFFER;
|
2010-07-04 18:29:53 +00:00
|
|
|
|
|
|
|
enc->multipass_mode = THEORA_DEF_MULTIPASS_MODE;
|
|
|
|
enc->multipass_cache_file = THEORA_DEF_MULTIPASS_CACHE_FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
theora_enc_clear_multipass_cache (GstTheoraEnc * enc)
|
|
|
|
{
|
|
|
|
if (enc->multipass_cache_fd) {
|
|
|
|
g_io_channel_shutdown (enc->multipass_cache_fd, TRUE, NULL);
|
|
|
|
g_io_channel_unref (enc->multipass_cache_fd);
|
|
|
|
enc->multipass_cache_fd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enc->multipass_cache_adapter) {
|
|
|
|
gst_object_unref (enc->multipass_cache_adapter);
|
|
|
|
enc->multipass_cache_adapter = NULL;
|
|
|
|
}
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 23:31:05 +00:00
|
|
|
static void
|
|
|
|
theora_enc_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstTheoraEnc *enc = GST_THEORA_ENC (object);
|
|
|
|
|
2006-02-06 12:38:48 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "Finalizing");
|
2009-09-09 21:44:36 +00:00
|
|
|
if (enc->encoder)
|
|
|
|
th_encode_free (enc->encoder);
|
|
|
|
th_comment_clear (&enc->comment);
|
|
|
|
th_info_clear (&enc->info);
|
2010-07-04 18:29:53 +00:00
|
|
|
g_free (enc->multipass_cache_file);
|
|
|
|
|
|
|
|
theora_enc_clear_multipass_cache (enc);
|
2006-02-06 12:38:48 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
if (enc->input_state)
|
|
|
|
gst_video_codec_state_unref (enc->input_state);
|
|
|
|
|
2006-02-06 12:38:48 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2006-02-05 23:31:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 11:31:07 +00:00
|
|
|
static gboolean
|
2013-08-15 11:15:05 +00:00
|
|
|
theora_enc_flush (GstVideoEncoder * encoder)
|
ext/theora/: Mark discontinuities of > 3/4 of a frame, reinit encoder.
Original commit message from CVS:
* ext/theora/gsttheoraenc.h:
* ext/theora/theoraenc.c: (gst_theora_enc_init),
(theora_enc_reset), (theora_enc_clear), (theora_enc_sink_setcaps),
(theora_buffer_from_packet), (theora_enc_is_discontinuous),
(theora_enc_chain), (theora_enc_change_state):
Mark discontinuities of > 3/4 of a frame, reinit encoder.
* tests/check/pipelines/theoraenc.c: (check_buffer_granulepos),
(GST_START_TEST), (theoraenc_suite):
Enable discontinuity test, fix it.
2006-11-22 14:34:03 +00:00
|
|
|
{
|
2013-07-25 11:31:07 +00:00
|
|
|
GstTheoraEnc *enc = GST_THEORA_ENC (encoder);
|
2009-09-09 21:44:36 +00:00
|
|
|
ogg_uint32_t keyframe_force;
|
2009-12-21 01:34:46 +00:00
|
|
|
int rate_flags;
|
2009-09-04 12:06:09 +00:00
|
|
|
|
2013-10-10 18:56:32 +00:00
|
|
|
|
|
|
|
if (enc->input_state == NULL) {
|
|
|
|
GST_INFO_OBJECT (enc, "Not configured yet, returning FALSE");
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-21 22:57:42 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
|
|
|
enc->info.target_bitrate = enc->video_bitrate;
|
2012-03-07 11:22:14 +00:00
|
|
|
enc->info.quality = enc->video_quality;
|
2010-09-21 22:57:42 +00:00
|
|
|
enc->bitrate_changed = FALSE;
|
|
|
|
enc->quality_changed = FALSE;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
2009-09-09 21:44:36 +00:00
|
|
|
if (enc->encoder)
|
|
|
|
th_encode_free (enc->encoder);
|
2013-07-25 11:31:07 +00:00
|
|
|
|
2013-08-15 11:15:05 +00:00
|
|
|
enc->encoder = th_encode_alloc (&enc->info);
|
|
|
|
/* We ensure this function cannot fail. */
|
|
|
|
g_assert (enc->encoder != NULL);
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_SPLEVEL, &enc->speed_level,
|
|
|
|
sizeof (enc->speed_level));
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_VP3_COMPATIBLE,
|
|
|
|
&enc->vp3_compatible, sizeof (enc->vp3_compatible));
|
|
|
|
|
|
|
|
rate_flags = 0;
|
|
|
|
if (enc->drop_frames)
|
|
|
|
rate_flags |= TH_RATECTL_DROP_FRAMES;
|
|
|
|
if (enc->drop_frames)
|
|
|
|
rate_flags |= TH_RATECTL_CAP_OVERFLOW;
|
|
|
|
if (enc->drop_frames)
|
|
|
|
rate_flags |= TH_RATECTL_CAP_UNDERFLOW;
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_RATE_FLAGS,
|
|
|
|
&rate_flags, sizeof (rate_flags));
|
|
|
|
|
|
|
|
if (enc->rate_buffer) {
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_RATE_BUFFER,
|
|
|
|
&enc->rate_buffer, sizeof (enc->rate_buffer));
|
2009-12-21 01:34:46 +00:00
|
|
|
} else {
|
2013-08-15 11:15:05 +00:00
|
|
|
/* FIXME */
|
|
|
|
}
|
2009-09-09 21:44:36 +00:00
|
|
|
|
2013-08-15 11:15:05 +00:00
|
|
|
keyframe_force = enc->keyframe_auto ?
|
|
|
|
enc->keyframe_force : enc->keyframe_freq;
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
|
|
|
|
&keyframe_force, sizeof (keyframe_force));
|
2013-07-25 11:31:07 +00:00
|
|
|
|
2013-08-15 11:15:05 +00:00
|
|
|
/* Get placeholder data */
|
|
|
|
if (enc->multipass_cache_fd
|
|
|
|
&& enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS)
|
|
|
|
theora_enc_write_multipass_cache (enc, TRUE, FALSE);
|
2010-07-04 18:29:53 +00:00
|
|
|
|
2013-07-25 11:31:07 +00:00
|
|
|
return TRUE;
|
ext/theora/: Mark discontinuities of > 3/4 of a frame, reinit encoder.
Original commit message from CVS:
* ext/theora/gsttheoraenc.h:
* ext/theora/theoraenc.c: (gst_theora_enc_init),
(theora_enc_reset), (theora_enc_clear), (theora_enc_sink_setcaps),
(theora_buffer_from_packet), (theora_enc_is_discontinuous),
(theora_enc_chain), (theora_enc_change_state):
Mark discontinuities of > 3/4 of a frame, reinit encoder.
* tests/check/pipelines/theoraenc.c: (check_buffer_granulepos),
(GST_START_TEST), (theoraenc_suite):
Enable discontinuity test, fix it.
2006-11-22 14:34:03 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
static gboolean
|
|
|
|
theora_enc_start (GstVideoEncoder * benc)
|
ext/theora/: Mark discontinuities of > 3/4 of a frame, reinit encoder.
Original commit message from CVS:
* ext/theora/gsttheoraenc.h:
* ext/theora/theoraenc.c: (gst_theora_enc_init),
(theora_enc_reset), (theora_enc_clear), (theora_enc_sink_setcaps),
(theora_buffer_from_packet), (theora_enc_is_discontinuous),
(theora_enc_chain), (theora_enc_change_state):
Mark discontinuities of > 3/4 of a frame, reinit encoder.
* tests/check/pipelines/theoraenc.c: (check_buffer_granulepos),
(GST_START_TEST), (theoraenc_suite):
Enable discontinuity test, fix it.
2006-11-22 14:34:03 +00:00
|
|
|
{
|
2012-03-07 11:22:14 +00:00
|
|
|
GstTheoraEnc *enc;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (benc, "start: init theora");
|
|
|
|
enc = GST_THEORA_ENC (benc);
|
|
|
|
|
|
|
|
if (enc->multipass_mode >= MULTIPASS_MODE_FIRST_PASS) {
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
if (!enc->multipass_cache_file) {
|
|
|
|
GST_ELEMENT_ERROR (enc, LIBRARY, SETTINGS, (NULL), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
enc->multipass_cache_fd =
|
|
|
|
g_io_channel_new_file (enc->multipass_cache_file,
|
|
|
|
(enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS ? "w" : "r"), &err);
|
|
|
|
|
|
|
|
if (enc->multipass_mode == MULTIPASS_MODE_SECOND_PASS)
|
|
|
|
enc->multipass_cache_adapter = gst_adapter_new ();
|
2011-12-19 16:41:23 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
if (!enc->multipass_cache_fd) {
|
|
|
|
GST_ELEMENT_ERROR (enc, RESOURCE, OPEN_READ, (NULL),
|
|
|
|
("Failed to open multipass cache file: %s", err->message));
|
|
|
|
g_error_free (err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_io_channel_set_encoding (enc->multipass_cache_fd, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2013-08-15 11:15:05 +00:00
|
|
|
enc->packetno = 0;
|
|
|
|
enc->initialised = FALSE;
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
theora_enc_stop (GstVideoEncoder * benc)
|
|
|
|
{
|
|
|
|
GstTheoraEnc *enc;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (benc, "stop: clearing theora state");
|
|
|
|
enc = GST_THEORA_ENC (benc);
|
|
|
|
|
2013-08-15 11:15:05 +00:00
|
|
|
if (enc->encoder)
|
|
|
|
th_encode_free (enc->encoder);
|
|
|
|
enc->encoder = NULL;
|
|
|
|
th_comment_clear (&enc->comment);
|
|
|
|
th_info_clear (&enc->info);
|
|
|
|
|
|
|
|
if (enc->input_state)
|
|
|
|
gst_video_codec_state_unref (enc->input_state);
|
|
|
|
enc->input_state = NULL;
|
|
|
|
|
2013-07-25 11:31:07 +00:00
|
|
|
/* Everything else is handled in reset() */
|
|
|
|
theora_enc_clear_multipass_cache (enc);
|
2012-03-07 11:22:14 +00:00
|
|
|
|
|
|
|
return TRUE;
|
ext/theora/: Mark discontinuities of > 3/4 of a frame, reinit encoder.
Original commit message from CVS:
* ext/theora/gsttheoraenc.h:
* ext/theora/theoraenc.c: (gst_theora_enc_init),
(theora_enc_reset), (theora_enc_clear), (theora_enc_sink_setcaps),
(theora_buffer_from_packet), (theora_enc_is_discontinuous),
(theora_enc_chain), (theora_enc_change_state):
Mark discontinuities of > 3/4 of a frame, reinit encoder.
* tests/check/pipelines/theoraenc.c: (check_buffer_granulepos),
(GST_START_TEST), (theoraenc_suite):
Enable discontinuity test, fix it.
2006-11-22 14:34:03 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 15:29:38 +00:00
|
|
|
static char *
|
|
|
|
theora_enc_get_supported_formats (void)
|
|
|
|
{
|
2009-09-09 21:44:36 +00:00
|
|
|
th_enc_ctx *encoder;
|
|
|
|
th_info info;
|
2012-03-07 11:22:14 +00:00
|
|
|
struct
|
2009-09-07 15:29:38 +00:00
|
|
|
{
|
2009-09-09 21:44:36 +00:00
|
|
|
th_pixel_fmt pixelformat;
|
2012-03-07 11:22:14 +00:00
|
|
|
const char *fourcc;
|
2009-09-07 15:29:38 +00:00
|
|
|
} formats[] = {
|
|
|
|
{
|
2009-09-09 21:44:36 +00:00
|
|
|
TH_PF_420, "I420"}, {
|
|
|
|
TH_PF_422, "Y42B"}, {
|
|
|
|
TH_PF_444, "Y444"}
|
2009-09-07 15:29:38 +00:00
|
|
|
};
|
|
|
|
GString *string = NULL;
|
|
|
|
guint i;
|
|
|
|
|
2009-09-09 21:44:36 +00:00
|
|
|
th_info_init (&info);
|
|
|
|
info.frame_width = 16;
|
|
|
|
info.frame_height = 16;
|
2009-09-07 15:29:38 +00:00
|
|
|
info.fps_numerator = 25;
|
|
|
|
info.fps_denominator = 1;
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (formats); i++) {
|
2009-09-09 21:44:36 +00:00
|
|
|
info.pixel_fmt = formats[i].pixelformat;
|
2009-09-07 15:29:38 +00:00
|
|
|
|
2009-09-09 21:44:36 +00:00
|
|
|
encoder = th_encode_alloc (&info);
|
|
|
|
if (encoder == NULL)
|
2009-09-07 15:29:38 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
GST_LOG ("format %s is supported", formats[i].fourcc);
|
2009-09-09 21:44:36 +00:00
|
|
|
th_encode_free (encoder);
|
2009-09-07 15:29:38 +00:00
|
|
|
|
|
|
|
if (string == NULL) {
|
|
|
|
string = g_string_new (formats[i].fourcc);
|
|
|
|
} else {
|
|
|
|
g_string_append (string, ", ");
|
|
|
|
g_string_append (string, formats[i].fourcc);
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 21:44:36 +00:00
|
|
|
th_info_clear (&info);
|
2009-09-07 15:29:38 +00:00
|
|
|
|
|
|
|
return string == NULL ? NULL : g_string_free (string, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2012-04-24 19:32:28 +00:00
|
|
|
theora_enc_getcaps (GstVideoEncoder * encoder, GstCaps * filter)
|
2009-09-07 15:29:38 +00:00
|
|
|
{
|
2012-04-24 19:32:28 +00:00
|
|
|
GstCaps *caps, *ret;
|
2012-03-07 11:22:14 +00:00
|
|
|
char *supported_formats, *caps_string;
|
2009-09-07 15:29:38 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
supported_formats = theora_enc_get_supported_formats ();
|
|
|
|
if (!supported_formats) {
|
|
|
|
GST_WARNING ("no supported formats found. Encoder disabled?");
|
2009-09-07 15:29:38 +00:00
|
|
|
return gst_caps_new_empty ();
|
|
|
|
}
|
|
|
|
|
2012-04-24 19:32:28 +00:00
|
|
|
caps_string = g_strdup_printf ("video/x-raw, "
|
|
|
|
"format = (string) { %s }, "
|
2012-03-07 11:22:14 +00:00
|
|
|
"framerate = (fraction) [1/MAX, MAX], "
|
|
|
|
"width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]",
|
|
|
|
supported_formats);
|
|
|
|
caps = gst_caps_from_string (caps_string);
|
|
|
|
g_free (caps_string);
|
|
|
|
g_free (supported_formats);
|
|
|
|
GST_DEBUG ("Supported caps: %" GST_PTR_FORMAT, caps);
|
2009-09-07 15:29:38 +00:00
|
|
|
|
2012-04-24 19:32:28 +00:00
|
|
|
ret = gst_video_encoder_proxy_getcaps (encoder, caps, filter);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
return ret;
|
2009-09-07 15:29:38 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
static gboolean
|
2012-03-07 11:22:14 +00:00
|
|
|
theora_enc_set_format (GstVideoEncoder * benc, GstVideoCodecState * state)
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
{
|
2012-03-07 11:22:14 +00:00
|
|
|
GstTheoraEnc *enc = GST_THEORA_ENC (benc);
|
|
|
|
GstVideoInfo *info = &state->info;
|
|
|
|
|
|
|
|
enc->width = GST_VIDEO_INFO_WIDTH (info);
|
|
|
|
enc->height = GST_VIDEO_INFO_HEIGHT (info);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2009-09-09 21:44:36 +00:00
|
|
|
th_info_clear (&enc->info);
|
|
|
|
th_info_init (&enc->info);
|
2004-07-30 08:14:36 +00:00
|
|
|
/* Theora has a divisible-by-sixteen restriction for the encoded video size but
|
2009-09-09 21:44:36 +00:00
|
|
|
* we can define a picture area using pic_width/pic_height */
|
|
|
|
enc->info.frame_width = GST_ROUND_UP_16 (enc->width);
|
|
|
|
enc->info.frame_height = GST_ROUND_UP_16 (enc->height);
|
|
|
|
enc->info.pic_width = enc->width;
|
|
|
|
enc->info.pic_height = enc->height;
|
2012-03-07 11:22:14 +00:00
|
|
|
switch (GST_VIDEO_INFO_FORMAT (info)) {
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
2009-09-09 21:44:36 +00:00
|
|
|
enc->info.pixel_fmt = TH_PF_420;
|
2009-09-04 19:37:04 +00:00
|
|
|
break;
|
2012-03-07 11:22:14 +00:00
|
|
|
case GST_VIDEO_FORMAT_Y42B:
|
2009-09-09 21:44:36 +00:00
|
|
|
enc->info.pixel_fmt = TH_PF_422;
|
2009-09-04 19:37:04 +00:00
|
|
|
break;
|
2012-03-07 11:22:14 +00:00
|
|
|
case GST_VIDEO_FORMAT_Y444:
|
2009-09-09 21:44:36 +00:00
|
|
|
enc->info.pixel_fmt = TH_PF_444;
|
2009-09-04 19:37:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
enc->info.fps_numerator = enc->fps_n = GST_VIDEO_INFO_FPS_N (info);
|
|
|
|
enc->info.fps_denominator = enc->fps_d = GST_VIDEO_INFO_FPS_D (info);
|
|
|
|
enc->info.aspect_numerator = GST_VIDEO_INFO_PAR_N (info);
|
|
|
|
enc->info.aspect_denominator = GST_VIDEO_INFO_PAR_D (info);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2009-09-09 21:44:36 +00:00
|
|
|
enc->info.colorspace = TH_CS_UNSPECIFIED;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
/* Save input state */
|
|
|
|
if (enc->input_state)
|
|
|
|
gst_video_codec_state_unref (enc->input_state);
|
|
|
|
enc->input_state = gst_video_codec_state_ref (state);
|
|
|
|
|
2006-01-30 19:21:07 +00:00
|
|
|
/* as done in theora */
|
2009-09-09 21:44:36 +00:00
|
|
|
enc->info.keyframe_granule_shift = _ilog (enc->keyframe_force - 1);
|
2006-01-30 19:21:07 +00:00
|
|
|
GST_DEBUG_OBJECT (enc,
|
|
|
|
"keyframe_frequency_force is %d, granule shift is %d",
|
2009-09-09 21:44:36 +00:00
|
|
|
enc->keyframe_force, enc->info.keyframe_granule_shift);
|
2006-01-30 19:21:07 +00:00
|
|
|
|
2013-08-15 11:15:05 +00:00
|
|
|
theora_enc_flush (benc);
|
2007-04-19 16:58:53 +00:00
|
|
|
enc->initialised = TRUE;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
return TRUE;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
theora_enc_pre_push (GstVideoEncoder * benc, GstVideoCodecFrame * frame)
|
2006-01-30 19:21:07 +00:00
|
|
|
{
|
2012-03-07 11:22:14 +00:00
|
|
|
GstTheoraEnc *enc = GST_THEORA_ENC (benc);
|
|
|
|
guint64 pfn;
|
2006-01-30 19:21:07 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
/* see ext/ogg/README; OFFSET_END takes "our" granulepos, OFFSET its
|
|
|
|
* time representation */
|
|
|
|
/* granulepos from sync frame */
|
|
|
|
pfn = frame->presentation_frame_number - frame->distance_from_sync;
|
|
|
|
/* correct to correspond to linear running time */
|
|
|
|
pfn -= enc->pfn_offset;
|
|
|
|
pfn += enc->granulepos_offset + 1;
|
|
|
|
/* granulepos */
|
|
|
|
GST_BUFFER_OFFSET_END (frame->output_buffer) =
|
|
|
|
(pfn << enc->info.keyframe_granule_shift) + frame->distance_from_sync;
|
|
|
|
GST_BUFFER_OFFSET (frame->output_buffer) = granulepos_to_timestamp (enc,
|
|
|
|
GST_BUFFER_OFFSET_END (frame->output_buffer));
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
2006-01-30 19:21:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-17 13:42:38 +00:00
|
|
|
static GstFlowReturn
|
2012-03-07 11:22:14 +00:00
|
|
|
theora_push_packet (GstTheoraEnc * enc, ogg_packet * packet)
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
{
|
2012-03-07 11:22:14 +00:00
|
|
|
GstVideoEncoder *benc;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
GstVideoCodecFrame *frame;
|
|
|
|
|
|
|
|
benc = GST_VIDEO_ENCODER (enc);
|
Cleanups and buffer alloc.
Original commit message from CVS:
* ext/ogg/README:
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_submit_packet),
(gst_ogg_demux_activate_chain), (gst_ogg_demux_clear_chains):
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page):
* ext/theora/theoradec.c: (theora_dec_src_query),
(theora_handle_data_packet):
* ext/theora/theoraenc.c: (theora_buffer_from_packet),
(theora_enc_chain):
* ext/vorbis/vorbisdec.c: (vorbis_dec_sink_event),
(vorbis_handle_data_packet):
* gst/audioconvert/bufferframesconvert.c:
(buffer_frames_convert_chain):
* gst/ffmpegcolorspace/gstffmpegcolorspace.c:
(gst_ffmpegcsp_getcaps), (gst_ffmpegcsp_configure_context),
(gst_ffmpegcsp_setcaps), (gst_ffmpegcsp_bufferalloc),
(gst_ffmpegcsp_chain):
* gst/videorate/gstvideorate.c: (gst_videorate_transformcaps),
(gst_videorate_getcaps), (gst_videorate_setcaps),
(gst_videorate_event), (gst_videorate_chain):
* gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_activate),
(gst_videotestsrc_src_query), (gst_videotestsrc_loop):
* sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new),
(gst_ximagesink_setcaps), (gst_ximagesink_buffer_alloc):
* sys/xvimage/xvimagesink.c: (gst_xvimage_buffer_destroy),
(gst_xvimage_buffer_finalize), (gst_xvimage_buffer_free),
(gst_xvimage_buffer_class_init), (gst_xvimage_buffer_get_type),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_put),
(gst_xvimagesink_show_frame), (gst_xvimagesink_buffer_alloc):
Cleanups and buffer alloc.
2005-06-02 09:46:40 +00:00
|
|
|
|
2012-07-23 07:45:11 +00:00
|
|
|
frame = gst_video_encoder_get_oldest_frame (benc);
|
2012-07-23 08:19:16 +00:00
|
|
|
if (gst_video_encoder_allocate_output_frame (benc, frame,
|
2012-07-23 07:45:11 +00:00
|
|
|
packet->bytes) != GST_FLOW_OK) {
|
2007-04-15 14:35:53 +00:00
|
|
|
GST_WARNING_OBJECT (enc, "Could not allocate buffer");
|
2012-07-23 07:45:11 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2007-04-15 14:35:53 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2013-05-07 08:16:48 +00:00
|
|
|
if (packet->bytes > 0)
|
|
|
|
gst_buffer_fill (frame->output_buffer, 0, packet->packet, packet->bytes);
|
2012-03-07 11:22:14 +00:00
|
|
|
|
|
|
|
/* the second most significant bit of the first data byte is cleared
|
|
|
|
* for keyframes */
|
|
|
|
if (packet->bytes > 0 && (packet->packet[0] & 0x40) == 0) {
|
|
|
|
GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame);
|
2004-08-16 10:19:39 +00:00
|
|
|
} else {
|
2012-03-07 11:22:14 +00:00
|
|
|
GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame);
|
2004-07-07 15:57:48 +00:00
|
|
|
}
|
2004-05-06 14:32:14 +00:00
|
|
|
enc->packetno++;
|
2004-06-08 16:41:42 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
ret = gst_video_encoder_finish_frame (benc, frame);
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
done:
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
return ret;
|
2004-06-08 16:41:42 +00:00
|
|
|
}
|
|
|
|
|
2005-04-20 09:42:56 +00:00
|
|
|
static GstCaps *
|
2012-03-07 11:22:14 +00:00
|
|
|
theora_set_header_on_caps (GstCaps * caps, GList * buffers)
|
2004-06-08 16:41:42 +00:00
|
|
|
{
|
2005-04-20 09:42:56 +00:00
|
|
|
GstStructure *structure;
|
2005-11-21 12:36:22 +00:00
|
|
|
GValue array = { 0 };
|
2004-06-08 16:41:42 +00:00
|
|
|
GValue value = { 0 };
|
2009-09-09 21:44:36 +00:00
|
|
|
GstBuffer *buffer;
|
2012-03-07 11:22:14 +00:00
|
|
|
GList *walk;
|
2004-06-08 16:41:42 +00:00
|
|
|
|
2005-04-20 09:42:56 +00:00
|
|
|
caps = gst_caps_make_writable (caps);
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2006-02-06 12:38:48 +00:00
|
|
|
/* put copies of the buffers in a fixed list */
|
2005-11-21 12:36:22 +00:00
|
|
|
g_value_init (&array, GST_TYPE_ARRAY);
|
2006-02-06 12:38:48 +00:00
|
|
|
|
2009-09-09 21:44:36 +00:00
|
|
|
for (walk = buffers; walk; walk = walk->next) {
|
|
|
|
buffer = walk->data;
|
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
|
|
|
gst_value_set_buffer (&value, buffer);
|
|
|
|
gst_value_array_append_value (&array, &value);
|
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
2006-02-06 12:38:48 +00:00
|
|
|
|
2013-03-03 17:41:34 +00:00
|
|
|
gst_structure_take_value (structure, "streamheader", &array);
|
2005-04-20 09:42:56 +00:00
|
|
|
|
|
|
|
return caps;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 14:59:49 +00:00
|
|
|
static void
|
2012-04-24 19:32:28 +00:00
|
|
|
theora_enc_init_buffer (th_ycbcr_buffer buf, GstVideoFrame * frame)
|
2009-09-04 14:59:49 +00:00
|
|
|
{
|
2012-04-24 19:32:28 +00:00
|
|
|
GstVideoInfo vinfo;
|
2009-09-09 21:44:36 +00:00
|
|
|
guint i;
|
|
|
|
|
2018-10-22 06:17:24 +00:00
|
|
|
/* According to Theora developer Timothy Terriberry, the Theora
|
2009-09-09 21:44:36 +00:00
|
|
|
* encoder will not use memory outside of pic_width/height, even when
|
|
|
|
* the frame size is bigger. The values outside this region will be encoded
|
|
|
|
* to default values.
|
|
|
|
* Due to this, setting the frame's width/height as the buffer width/height
|
|
|
|
* is perfectly ok, even though it does not strictly look ok.
|
|
|
|
*/
|
2012-04-24 19:32:28 +00:00
|
|
|
|
|
|
|
gst_video_info_init (&vinfo);
|
|
|
|
gst_video_info_set_format (&vinfo, GST_VIDEO_FRAME_FORMAT (frame),
|
|
|
|
GST_ROUND_UP_16 (GST_VIDEO_FRAME_WIDTH (frame)),
|
|
|
|
GST_ROUND_UP_16 (GST_VIDEO_FRAME_HEIGHT (frame)));
|
|
|
|
|
2009-09-09 21:44:36 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2012-04-24 19:32:28 +00:00
|
|
|
buf[i].width = GST_VIDEO_INFO_COMP_WIDTH (&vinfo, i);
|
|
|
|
buf[i].height = GST_VIDEO_INFO_COMP_HEIGHT (&vinfo, i);
|
|
|
|
buf[i].data = GST_VIDEO_FRAME_COMP_DATA (frame, i);
|
|
|
|
buf[i].stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, i);
|
2009-09-04 14:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-04 18:29:53 +00:00
|
|
|
static gboolean
|
|
|
|
theora_enc_read_multipass_cache (GstTheoraEnc * enc)
|
|
|
|
{
|
|
|
|
GstBuffer *cache_buf;
|
|
|
|
const guint8 *cache_data;
|
2012-04-24 19:32:28 +00:00
|
|
|
gsize bytes_read = 0;
|
|
|
|
gssize bytes_consumed = 0;
|
2010-07-04 18:29:53 +00:00
|
|
|
GIOStatus stat = G_IO_STATUS_NORMAL;
|
|
|
|
gboolean done = FALSE;
|
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
if (gst_adapter_available (enc->multipass_cache_adapter) == 0) {
|
2012-04-24 19:32:28 +00:00
|
|
|
GstMapInfo minfo;
|
|
|
|
|
|
|
|
cache_buf = gst_buffer_new_allocate (NULL, 512, NULL);
|
|
|
|
|
|
|
|
gst_buffer_map (cache_buf, &minfo, GST_MAP_WRITE);
|
|
|
|
|
2010-07-04 18:29:53 +00:00
|
|
|
stat = g_io_channel_read_chars (enc->multipass_cache_fd,
|
2012-04-24 19:32:28 +00:00
|
|
|
(gchar *) minfo.data, minfo.size, &bytes_read, NULL);
|
2010-07-04 18:29:53 +00:00
|
|
|
|
|
|
|
if (bytes_read <= 0) {
|
2012-04-24 19:32:28 +00:00
|
|
|
gst_buffer_unmap (cache_buf, &minfo);
|
2010-07-04 18:29:53 +00:00
|
|
|
gst_buffer_unref (cache_buf);
|
|
|
|
break;
|
|
|
|
} else {
|
2012-04-24 19:32:28 +00:00
|
|
|
gst_buffer_unmap (cache_buf, &minfo);
|
|
|
|
gst_buffer_resize (cache_buf, 0, bytes_read);
|
2010-07-04 18:29:53 +00:00
|
|
|
|
|
|
|
gst_adapter_push (enc->multipass_cache_adapter, cache_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gst_adapter_available (enc->multipass_cache_adapter) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bytes_read =
|
|
|
|
MIN (gst_adapter_available (enc->multipass_cache_adapter), 512);
|
|
|
|
|
2012-04-24 19:32:28 +00:00
|
|
|
cache_data = gst_adapter_map (enc->multipass_cache_adapter, bytes_read);
|
2010-07-04 18:29:53 +00:00
|
|
|
|
|
|
|
bytes_consumed =
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_IN, (guint8 *) cache_data,
|
|
|
|
bytes_read);
|
2012-04-24 19:32:28 +00:00
|
|
|
gst_adapter_unmap (enc->multipass_cache_adapter);
|
|
|
|
|
2010-07-04 18:29:53 +00:00
|
|
|
done = bytes_consumed <= 0;
|
|
|
|
if (bytes_consumed > 0)
|
|
|
|
gst_adapter_flush (enc->multipass_cache_adapter, bytes_consumed);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat == G_IO_STATUS_ERROR || (stat == G_IO_STATUS_EOF && bytes_read == 0)
|
|
|
|
|| bytes_consumed < 0) {
|
|
|
|
GST_ELEMENT_ERROR (enc, RESOURCE, READ, (NULL),
|
|
|
|
("Failed to read multipass cache file"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-03-25 15:59:51 +00:00
|
|
|
theora_enc_write_multipass_cache (GstTheoraEnc * enc, gboolean begin,
|
|
|
|
gboolean eos)
|
2010-07-04 18:29:53 +00:00
|
|
|
{
|
2011-03-25 15:59:51 +00:00
|
|
|
GError *err = NULL;
|
|
|
|
GIOStatus stat = G_IO_STATUS_NORMAL;
|
|
|
|
gint bytes_read = 0;
|
2010-07-04 18:29:53 +00:00
|
|
|
gsize bytes_written = 0;
|
2011-03-25 15:59:51 +00:00
|
|
|
gchar *buf;
|
|
|
|
|
2013-05-07 08:13:18 +00:00
|
|
|
if (begin) {
|
2011-03-25 15:59:51 +00:00
|
|
|
stat = g_io_channel_seek_position (enc->multipass_cache_fd, 0, G_SEEK_SET,
|
|
|
|
&err);
|
|
|
|
|
2013-05-07 08:13:18 +00:00
|
|
|
if (stat == G_IO_STATUS_ERROR) {
|
2011-03-25 15:59:51 +00:00
|
|
|
if (eos)
|
|
|
|
GST_ELEMENT_WARNING (enc, RESOURCE, WRITE, (NULL),
|
|
|
|
("Failed to seek to beginning of multipass cache file: %s",
|
|
|
|
err->message));
|
|
|
|
else
|
|
|
|
GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL),
|
|
|
|
("Failed to seek to beginning of multipass cache file: %s",
|
|
|
|
err->message));
|
2013-05-07 08:13:18 +00:00
|
|
|
g_error_free (err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
bytes_read =
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_OUT, &buf, sizeof (buf));
|
|
|
|
if (bytes_read > 0)
|
|
|
|
g_io_channel_write_chars (enc->multipass_cache_fd, buf, bytes_read,
|
|
|
|
&bytes_written, &err);
|
|
|
|
} while (bytes_read > 0 && bytes_written > 0 && !err);
|
|
|
|
|
|
|
|
if (bytes_read < 0 || err) {
|
|
|
|
if (bytes_read < 0) {
|
|
|
|
GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL),
|
|
|
|
("Failed to read multipass cache data: %d", bytes_read));
|
2011-03-25 15:59:51 +00:00
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL),
|
2013-05-07 08:13:18 +00:00
|
|
|
("Failed to write multipass cache file: %s", err->message));
|
2011-03-25 15:59:51 +00:00
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
g_error_free (err);
|
2010-07-04 18:29:53 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-05-07 08:13:18 +00:00
|
|
|
|
2010-07-04 18:29:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-19 16:41:23 +00:00
|
|
|
static void
|
2012-03-07 11:22:14 +00:00
|
|
|
theora_enc_reset_ts (GstTheoraEnc * enc, GstClockTime running_time, gint pfn)
|
2011-12-19 16:41:23 +00:00
|
|
|
{
|
2012-03-07 11:22:14 +00:00
|
|
|
enc->granulepos_offset =
|
|
|
|
gst_util_uint64_scale (running_time, enc->fps_n, GST_SECOND * enc->fps_d);
|
|
|
|
enc->timestamp_offset = running_time;
|
|
|
|
enc->pfn_offset = pfn;
|
2011-12-19 16:41:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
static GstBuffer *
|
|
|
|
theora_enc_buffer_from_header_packet (GstTheoraEnc * enc, ogg_packet * packet)
|
2011-06-03 14:29:00 +00:00
|
|
|
{
|
2012-03-07 11:22:14 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
2012-07-23 07:45:11 +00:00
|
|
|
outbuf =
|
2012-07-23 08:19:16 +00:00
|
|
|
gst_video_encoder_allocate_output_buffer (GST_VIDEO_ENCODER (enc),
|
2012-07-23 07:45:11 +00:00
|
|
|
packet->bytes);
|
2012-04-24 19:32:28 +00:00
|
|
|
gst_buffer_fill (outbuf, 0, packet->packet, packet->bytes);
|
2012-03-07 11:22:14 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = 0;
|
|
|
|
GST_BUFFER_OFFSET_END (outbuf) = 0;
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
|
2013-03-03 17:41:34 +00:00
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_HEADER);
|
2012-03-07 11:22:14 +00:00
|
|
|
|
2012-05-31 21:55:32 +00:00
|
|
|
GST_DEBUG ("created header packet buffer, %u bytes",
|
|
|
|
(guint) gst_buffer_get_size (outbuf));
|
2012-03-07 11:22:14 +00:00
|
|
|
return outbuf;
|
2011-06-03 14:29:00 +00:00
|
|
|
}
|
|
|
|
|
2005-03-31 09:43:49 +00:00
|
|
|
static GstFlowReturn
|
2012-03-07 11:22:14 +00:00
|
|
|
theora_enc_handle_frame (GstVideoEncoder * benc, GstVideoCodecFrame * frame)
|
2005-03-31 09:43:49 +00:00
|
|
|
{
|
|
|
|
GstTheoraEnc *enc;
|
|
|
|
ogg_packet op;
|
2012-03-07 11:22:14 +00:00
|
|
|
GstClockTime timestamp, running_time;
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
GstFlowReturn ret;
|
2009-04-14 16:16:37 +00:00
|
|
|
gboolean force_keyframe;
|
2005-03-31 09:43:49 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
enc = GST_THEORA_ENC (benc);
|
2005-03-31 09:43:49 +00:00
|
|
|
|
2008-11-25 15:14:30 +00:00
|
|
|
/* we keep track of two timelines.
|
2019-08-29 17:42:39 +00:00
|
|
|
* - The timestamps from the incoming buffers, which we copy to the outgoing
|
2008-11-25 15:14:30 +00:00
|
|
|
* encoded buffers as-is. We need to do this as we simply forward the
|
|
|
|
* newsegment events.
|
|
|
|
* - The running_time of the buffers, which we use to construct the granulepos
|
|
|
|
* in the packets.
|
|
|
|
*/
|
2012-03-07 11:22:14 +00:00
|
|
|
timestamp = frame->pts;
|
2009-04-14 16:16:37 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
/* incoming buffers are clipped, so this should be positive */
|
2008-11-25 15:14:30 +00:00
|
|
|
running_time =
|
2012-03-07 11:22:14 +00:00
|
|
|
gst_segment_to_running_time (&GST_VIDEO_ENCODER_INPUT_SEGMENT (enc),
|
|
|
|
GST_FORMAT_TIME, timestamp);
|
2008-11-25 15:14:30 +00:00
|
|
|
|
2009-04-14 16:16:37 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2010-09-21 22:57:42 +00:00
|
|
|
if (enc->bitrate_changed) {
|
|
|
|
long int bitrate = enc->video_bitrate;
|
|
|
|
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_BITRATE, &bitrate,
|
|
|
|
sizeof (long int));
|
|
|
|
enc->bitrate_changed = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enc->quality_changed) {
|
|
|
|
long int quality = enc->video_quality;
|
|
|
|
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_QUALITY, &quality,
|
|
|
|
sizeof (long int));
|
|
|
|
enc->quality_changed = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* see if we need to schedule a keyframe */
|
2012-03-07 11:22:14 +00:00
|
|
|
force_keyframe = GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame);
|
2009-04-14 16:16:37 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
if (enc->packetno == 0) {
|
2007-04-15 14:35:53 +00:00
|
|
|
/* no packets written yet, setup headers */
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
GstCaps *caps;
|
2009-09-09 21:44:36 +00:00
|
|
|
GstBuffer *buf;
|
2012-03-07 11:22:14 +00:00
|
|
|
GList *buffers = NULL;
|
2009-09-09 21:44:36 +00:00
|
|
|
int result;
|
2012-03-07 11:22:14 +00:00
|
|
|
GstVideoCodecState *state;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2006-01-30 17:01:54 +00:00
|
|
|
enc->granulepos_offset = 0;
|
|
|
|
enc->timestamp_offset = 0;
|
|
|
|
|
2007-04-15 14:35:53 +00:00
|
|
|
GST_DEBUG_OBJECT (enc, "output headers");
|
2004-08-16 10:19:39 +00:00
|
|
|
/* Theora 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 libtheora one at a time;
|
|
|
|
libtheora handles the additional Ogg bitstream constraints */
|
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
/* create the remaining theora headers */
|
2009-09-09 21:44:36 +00:00
|
|
|
th_comment_clear (&enc->comment);
|
|
|
|
th_comment_init (&enc->comment);
|
2007-01-29 18:14:25 +00:00
|
|
|
|
2009-09-09 21:44:36 +00:00
|
|
|
while ((result =
|
|
|
|
th_encode_flushheader (enc->encoder, &enc->comment, &op)) > 0) {
|
2012-03-07 11:22:14 +00:00
|
|
|
buf = theora_enc_buffer_from_header_packet (enc, &op);
|
|
|
|
buffers = g_list_prepend (buffers, buf);
|
2005-10-17 13:42:38 +00:00
|
|
|
}
|
2009-09-09 21:44:36 +00:00
|
|
|
if (result < 0) {
|
2012-03-07 11:22:14 +00:00
|
|
|
g_list_foreach (buffers, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_list_free (buffers);
|
2007-01-29 18:14:25 +00:00
|
|
|
goto encoder_disabled;
|
2005-10-17 13:42:38 +00:00
|
|
|
}
|
2004-06-08 16:41:42 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
buffers = g_list_reverse (buffers);
|
2009-09-09 21:44:36 +00:00
|
|
|
|
2004-06-08 16:41:42 +00:00
|
|
|
/* mark buffers and put on caps */
|
2012-04-24 19:32:28 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("video/x-theora");
|
2009-09-09 21:44:36 +00:00
|
|
|
caps = theora_set_header_on_caps (caps, buffers);
|
2012-03-07 11:22:14 +00:00
|
|
|
state = gst_video_encoder_set_output_state (benc, caps, enc->input_state);
|
2004-06-08 16:41:42 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
GST_DEBUG ("here are the caps: %" GST_PTR_FORMAT, state->caps);
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
gst_video_codec_state_unref (state);
|
2006-02-06 12:38:48 +00:00
|
|
|
|
2012-07-24 18:02:08 +00:00
|
|
|
gst_video_encoder_negotiate (GST_VIDEO_ENCODER (enc));
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
gst_video_encoder_set_headers (benc, buffers);
|
2006-01-30 17:01:54 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
theora_enc_reset_ts (enc, running_time, frame->presentation_frame_number);
|
2004-05-06 14:32:14 +00:00
|
|
|
}
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
{
|
|
|
|
th_ycbcr_buffer ycbcr;
|
2013-02-25 10:49:19 +00:00
|
|
|
gint res, keyframe_interval;
|
2012-04-24 19:32:28 +00:00
|
|
|
GstVideoFrame vframe;
|
2011-12-19 16:41:23 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
if (force_keyframe) {
|
2013-02-25 10:49:19 +00:00
|
|
|
/* if we want a keyframe, temporarily reset the max keyframe interval
|
|
|
|
* to 1, which will cause libtheora to emit one. There is no API to
|
|
|
|
* request a keyframe at the moment. */
|
|
|
|
keyframe_interval = 1;
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
|
|
|
|
&keyframe_interval, sizeof (keyframe_interval));
|
2012-03-07 11:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (enc->multipass_cache_fd
|
|
|
|
&& enc->multipass_mode == MULTIPASS_MODE_SECOND_PASS) {
|
|
|
|
if (!theora_enc_read_multipass_cache (enc)) {
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto multipass_read_failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 19:32:28 +00:00
|
|
|
gst_video_frame_map (&vframe, &enc->input_state->info, frame->input_buffer,
|
|
|
|
GST_MAP_READ);
|
|
|
|
theora_enc_init_buffer (ycbcr, &vframe);
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
res = th_encode_ycbcr_in (enc->encoder, ycbcr);
|
2012-04-24 19:32:28 +00:00
|
|
|
gst_video_frame_unmap (&vframe);
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
/* none of the failure cases can happen here */
|
|
|
|
g_assert (res == 0);
|
|
|
|
|
|
|
|
if (enc->multipass_cache_fd
|
|
|
|
&& enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) {
|
|
|
|
if (!theora_enc_write_multipass_cache (enc, FALSE, FALSE)) {
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto multipass_write_failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
while (th_encode_packetout (enc->encoder, 0, &op)) {
|
2013-02-25 10:49:19 +00:00
|
|
|
/* Reset the max keyframe interval to its original state, and reset
|
|
|
|
* the flag so we don't create more keyframes if we loop */
|
|
|
|
if (force_keyframe) {
|
|
|
|
keyframe_interval =
|
|
|
|
enc->keyframe_auto ? enc->keyframe_force : enc->keyframe_freq;
|
|
|
|
th_encode_ctl (enc->encoder, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,
|
|
|
|
&keyframe_interval, sizeof (keyframe_interval));
|
|
|
|
force_keyframe = FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
ret = theora_push_packet (enc, &op);
|
|
|
|
if (ret != GST_FLOW_OK)
|
2012-05-14 15:53:59 +00:00
|
|
|
goto beach;
|
2012-03-07 11:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
|
2012-05-14 15:53:59 +00:00
|
|
|
beach:
|
|
|
|
gst_video_codec_frame_unref (frame);
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
return ret;
|
2005-03-31 09:43:49 +00:00
|
|
|
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
/* ERRORS */
|
2012-03-07 11:22:14 +00:00
|
|
|
multipass_read_failed:
|
2005-10-17 13:42:38 +00:00
|
|
|
{
|
2012-05-14 15:53:59 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2005-10-17 13:42:38 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-03-07 11:22:14 +00:00
|
|
|
multipass_write_failed:
|
|
|
|
{
|
2012-05-14 15:53:59 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
Cleanups and buffer alloc.
Original commit message from CVS:
* ext/ogg/README:
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_submit_packet),
(gst_ogg_demux_activate_chain), (gst_ogg_demux_clear_chains):
* ext/ogg/gstoggmux.c: (gst_ogg_mux_buffer_from_page):
* ext/theora/theoradec.c: (theora_dec_src_query),
(theora_handle_data_packet):
* ext/theora/theoraenc.c: (theora_buffer_from_packet),
(theora_enc_chain):
* ext/vorbis/vorbisdec.c: (vorbis_dec_sink_event),
(vorbis_handle_data_packet):
* gst/audioconvert/bufferframesconvert.c:
(buffer_frames_convert_chain):
* gst/ffmpegcolorspace/gstffmpegcolorspace.c:
(gst_ffmpegcsp_getcaps), (gst_ffmpegcsp_configure_context),
(gst_ffmpegcsp_setcaps), (gst_ffmpegcsp_bufferalloc),
(gst_ffmpegcsp_chain):
* gst/videorate/gstvideorate.c: (gst_videorate_transformcaps),
(gst_videorate_getcaps), (gst_videorate_setcaps),
(gst_videorate_event), (gst_videorate_chain):
* gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_activate),
(gst_videotestsrc_src_query), (gst_videotestsrc_loop):
* sys/ximage/ximagesink.c: (gst_ximagesink_ximage_new),
(gst_ximagesink_setcaps), (gst_ximagesink_buffer_alloc):
* sys/xvimage/xvimagesink.c: (gst_xvimage_buffer_destroy),
(gst_xvimage_buffer_finalize), (gst_xvimage_buffer_free),
(gst_xvimage_buffer_class_init), (gst_xvimage_buffer_get_type),
(gst_xvimagesink_xvimage_new), (gst_xvimagesink_xvimage_put),
(gst_xvimagesink_show_frame), (gst_xvimagesink_buffer_alloc):
Cleanups and buffer alloc.
2005-06-02 09:46:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-01-29 18:14:25 +00:00
|
|
|
encoder_disabled:
|
|
|
|
{
|
2012-05-14 15:53:59 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2007-01-29 18:14:25 +00:00
|
|
|
GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL),
|
|
|
|
("libtheora has been compiled with the encoder disabled"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
static gboolean
|
|
|
|
theora_enc_finish (GstVideoEncoder * benc)
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
{
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
GstTheoraEnc *enc;
|
2012-03-07 11:22:14 +00:00
|
|
|
ogg_packet op;
|
ext/theora/: Added stream lock to decoder so that we can serialize the discont event.
Original commit message from CVS:
* ext/theora/theoradec.c: (_inc_granulepos),
(theora_dec_src_event), (theora_dec_sink_event),
(theora_handle_comment_packet), (theora_handle_type_packet),
(theora_handle_header_packet), (theora_handle_data_packet),
(theora_dec_chain):
* ext/theora/theoraenc.c: (gst_theora_enc_class_init),
(gst_theora_enc_init), (theora_enc_sink_setcaps),
(theora_push_buffer), (theora_push_packet),
(theora_enc_sink_event), (theora_enc_chain),
(theora_enc_change_state), (theora_enc_set_property),
(theora_enc_get_property):
Added stream lock to decoder so that we can serialize
the discont event.
More theoraenc porting, recover from errors, do clean
shutdown.
2005-05-05 09:44:01 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
enc = GST_THEORA_ENC (benc);
|
ext/theora/: Mark discontinuities of > 3/4 of a frame, reinit encoder.
Original commit message from CVS:
* ext/theora/gsttheoraenc.h:
* ext/theora/theoraenc.c: (gst_theora_enc_init),
(theora_enc_reset), (theora_enc_clear), (theora_enc_sink_setcaps),
(theora_buffer_from_packet), (theora_enc_is_discontinuous),
(theora_enc_chain), (theora_enc_change_state):
Mark discontinuities of > 3/4 of a frame, reinit encoder.
* tests/check/pipelines/theoraenc.c: (check_buffer_granulepos),
(GST_START_TEST), (theoraenc_suite):
Enable discontinuity test, fix it.
2006-11-22 14:34:03 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
if (enc->initialised) {
|
|
|
|
/* push last packet with eos flag, should not be called */
|
|
|
|
while (th_encode_packetout (enc->encoder, 1, &op)) {
|
|
|
|
theora_push_packet (enc, &op);
|
|
|
|
}
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
}
|
2012-03-07 11:22:14 +00:00
|
|
|
if (enc->initialised && enc->multipass_cache_fd
|
|
|
|
&& enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS)
|
|
|
|
theora_enc_write_multipass_cache (enc, TRUE, TRUE);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
|
2012-03-07 11:22:14 +00:00
|
|
|
theora_enc_clear_multipass_cache (enc);
|
|
|
|
|
|
|
|
return TRUE;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
}
|
|
|
|
|
2012-04-25 10:43:28 +00:00
|
|
|
static gboolean
|
|
|
|
theora_enc_propose_allocation (GstVideoEncoder * encoder, GstQuery * query)
|
|
|
|
{
|
2012-07-06 09:50:44 +00:00
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
2012-04-25 10:43:28 +00:00
|
|
|
|
|
|
|
return GST_VIDEO_ENCODER_CLASS (parent_class)->propose_allocation (encoder,
|
|
|
|
query);
|
|
|
|
}
|
|
|
|
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
static void
|
|
|
|
theora_enc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstTheoraEnc *enc = GST_THEORA_ENC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_BITRATE:
|
2010-09-21 22:57:42 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
enc->video_bitrate = g_value_get_int (value) * 1000;
|
2012-03-07 11:22:14 +00:00
|
|
|
enc->video_quality = 0;
|
2010-09-21 22:57:42 +00:00
|
|
|
enc->bitrate_changed = TRUE;
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_QUALITY:
|
2010-09-21 22:57:42 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2012-03-07 11:22:14 +00:00
|
|
|
if (GST_STATE (enc) >= GST_STATE_PAUSED && enc->video_quality == 0) {
|
2010-09-21 22:57:42 +00:00
|
|
|
GST_WARNING_OBJECT (object, "Can't change from bitrate to quality mode"
|
|
|
|
" while playing");
|
|
|
|
} else {
|
|
|
|
enc->video_quality = g_value_get_int (value);
|
|
|
|
enc->video_bitrate = 0;
|
|
|
|
enc->quality_changed = TRUE;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (enc);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_KEYFRAME_AUTO:
|
2004-06-10 14:59:17 +00:00
|
|
|
enc->keyframe_auto = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_KEYFRAME_FREQ:
|
2004-06-10 14:59:17 +00:00
|
|
|
enc->keyframe_freq = g_value_get_int (value);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_KEYFRAME_FREQ_FORCE:
|
2004-06-10 14:59:17 +00:00
|
|
|
enc->keyframe_force = g_value_get_int (value);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_SPEEDLEVEL:
|
2009-02-19 20:18:29 +00:00
|
|
|
enc->speed_level = g_value_get_int (value);
|
2009-12-21 01:34:46 +00:00
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_VP3_COMPATIBLE:
|
2009-12-21 01:34:46 +00:00
|
|
|
enc->vp3_compatible = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_DROP_FRAMES:
|
2009-12-21 01:34:46 +00:00
|
|
|
enc->drop_frames = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_CAP_OVERFLOW:
|
2009-12-21 01:34:46 +00:00
|
|
|
enc->cap_overflow = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_CAP_UNDERFLOW:
|
2009-12-21 01:34:46 +00:00
|
|
|
enc->cap_underflow = g_value_get_boolean (value);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_RATE_BUFFER:
|
2009-12-21 01:34:46 +00:00
|
|
|
enc->rate_buffer = g_value_get_int (value);
|
2009-02-19 20:18:29 +00:00
|
|
|
break;
|
2010-07-04 18:29:53 +00:00
|
|
|
case PROP_MULTIPASS_CACHE_FILE:
|
|
|
|
enc->multipass_cache_file = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_MULTIPASS_MODE:
|
|
|
|
enc->multipass_mode = g_value_get_enum (value);
|
|
|
|
break;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
theora_enc_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstTheoraEnc *enc = GST_THEORA_ENC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_BITRATE:
|
2010-09-21 22:57:42 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
2004-05-15 12:09:11 +00:00
|
|
|
g_value_set_int (value, enc->video_bitrate / 1000);
|
2010-09-21 22:57:42 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_QUALITY:
|
2010-09-21 22:57:42 +00:00
|
|
|
GST_OBJECT_LOCK (enc);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
g_value_set_int (value, enc->video_quality);
|
2010-09-21 22:57:42 +00:00
|
|
|
GST_OBJECT_UNLOCK (enc);
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_KEYFRAME_AUTO:
|
2004-06-10 14:59:17 +00:00
|
|
|
g_value_set_boolean (value, enc->keyframe_auto);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_KEYFRAME_FREQ:
|
2004-06-10 14:59:17 +00:00
|
|
|
g_value_set_int (value, enc->keyframe_freq);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_KEYFRAME_FREQ_FORCE:
|
2004-06-10 14:59:17 +00:00
|
|
|
g_value_set_int (value, enc->keyframe_force);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_SPEEDLEVEL:
|
2009-02-19 20:18:29 +00:00
|
|
|
g_value_set_int (value, enc->speed_level);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_VP3_COMPATIBLE:
|
2009-12-21 01:34:46 +00:00
|
|
|
g_value_set_boolean (value, enc->vp3_compatible);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_DROP_FRAMES:
|
2009-12-21 01:34:46 +00:00
|
|
|
g_value_set_boolean (value, enc->drop_frames);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_CAP_OVERFLOW:
|
2009-12-21 01:34:46 +00:00
|
|
|
g_value_set_boolean (value, enc->cap_overflow);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_CAP_UNDERFLOW:
|
2009-12-21 01:34:46 +00:00
|
|
|
g_value_set_boolean (value, enc->cap_underflow);
|
|
|
|
break;
|
2010-07-04 18:08:25 +00:00
|
|
|
case PROP_RATE_BUFFER:
|
2009-12-21 01:34:46 +00:00
|
|
|
g_value_set_int (value, enc->rate_buffer);
|
|
|
|
break;
|
2010-07-04 18:29:53 +00:00
|
|
|
case PROP_MULTIPASS_CACHE_FILE:
|
|
|
|
g_value_set_string (value, enc->multipass_cache_file);
|
|
|
|
break;
|
|
|
|
case PROP_MULTIPASS_MODE:
|
|
|
|
g_value_set_enum (value, enc->multipass_mode);
|
|
|
|
break;
|
ext/theora/: Added a theora encoder, grouped the encoder and decoder into the same plugin.
Original commit message from CVS:
* ext/theora/Makefile.am:
* ext/theora/theora.c: (plugin_init):
* ext/theora/theoradec.c: (theora_dec_change_state):
* ext/theora/theoraenc.c: (gst_theora_enc_base_init),
(gst_theora_enc_class_init), (gst_theora_enc_init),
(theora_enc_sink_link), (theora_enc_event), (theora_push_packet),
(theora_enc_chain), (theora_enc_change_state),
(theora_enc_set_property), (theora_enc_get_property):
Added a theora encoder, grouped the encoder and decoder into the
same plugin.
2004-05-06 09:10:31 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|