2010-05-13 08:04:04 +00:00
|
|
|
/* VP8
|
|
|
|
* Copyright (C) 2006 David Schleef <ds@schleef.org>
|
|
|
|
* Copyright (C) 2010 Entropy Wave Inc
|
2010-05-14 08:30:18 +00:00
|
|
|
* Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
2010-05-13 08:04:04 +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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
2010-07-03 15:47:29 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-vp8enc
|
|
|
|
* @see_also: vp8dec, webmmux, oggmux
|
|
|
|
*
|
|
|
|
* This element encodes raw video into a VP8 stream.
|
|
|
|
* <ulink url="http://www.webmproject.org">VP8</ulink> is a royalty-free
|
|
|
|
* video codec maintained by <ulink url="http://www.google.com/">Google
|
|
|
|
* </ulink>. It's the successor of On2 VP3, which was the base of the
|
|
|
|
* Theora video codec.
|
|
|
|
*
|
|
|
|
* To control the quality of the encoding, the #GstVP8Enc::bitrate and
|
|
|
|
* #GstVP8Enc::quality properties can be used. These two properties are
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example pipeline</title>
|
|
|
|
* |[
|
|
|
|
* gst-launch -v videotestsrc num-buffers=1000 ! vp8enc ! webmmux ! filesink location=videotestsrc.webm
|
|
|
|
* ]| This example pipeline will encode a test video source to VP8 muxed in an
|
|
|
|
* WebM container.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-21 06:13:06 +00:00
|
|
|
#ifdef HAVE_VP8_ENCODER
|
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2010-05-13 08:04:04 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
#include "gstvp8utils.h"
|
2010-07-03 15:34:58 +00:00
|
|
|
#include "gstvp8enc.h"
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
|
|
|
|
2010-05-20 08:19:54 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vp8enc_debug);
|
2010-05-13 08:04:04 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_vp8enc_debug
|
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
vpx_image_t *image;
|
|
|
|
GList *invisible;
|
2012-05-16 12:04:28 +00:00
|
|
|
} GstVP8EncUserData;
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2011-07-09 09:31:02 +00:00
|
|
|
static void
|
|
|
|
_gst_mini_object_unref0 (GstMiniObject * obj)
|
|
|
|
{
|
|
|
|
if (obj)
|
|
|
|
gst_mini_object_unref (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 12:04:28 +00:00
|
|
|
gst_vp8_enc_user_data_free (GstVP8EncUserData * user_data)
|
2011-07-09 09:31:02 +00:00
|
|
|
{
|
2012-05-16 12:04:28 +00:00
|
|
|
if (user_data->image)
|
|
|
|
g_slice_free (vpx_image_t, user_data->image);
|
2011-07-09 09:31:02 +00:00
|
|
|
|
2012-05-16 12:04:28 +00:00
|
|
|
g_list_foreach (user_data->invisible, (GFunc) _gst_mini_object_unref0, NULL);
|
|
|
|
g_list_free (user_data->invisible);
|
|
|
|
g_slice_free (GstVP8EncUserData, user_data);
|
2011-07-09 09:31:02 +00:00
|
|
|
}
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
/* From vp8/vp8_cx_iface.c */
|
|
|
|
#define DEFAULT_PROFILE 0
|
|
|
|
|
|
|
|
#define DEFAULT_RC_END_USAGE VPX_VBR
|
|
|
|
#define DEFAULT_RC_TARGET_BITRATE 256000
|
|
|
|
#define DEFAULT_RC_MIN_QUANTIZER 4
|
|
|
|
#define DEFAULT_RC_MAX_QUANTIZER 63
|
|
|
|
|
|
|
|
#define DEFAULT_RC_DROPFRAME_THRESH 0
|
|
|
|
#define DEFAULT_RC_RESIZE_ALLOWED 0
|
|
|
|
#define DEFAULT_RC_RESIZE_UP_THRESH 30
|
|
|
|
#define DEFAULT_RC_RESIZE_DOWN_THRESH 60
|
|
|
|
#define DEFAULT_RC_UNDERSHOOT_PCT 100
|
|
|
|
#define DEFAULT_RC_OVERSHOOT_PCT 100
|
|
|
|
#define DEFAULT_RC_BUF_SZ 6000
|
|
|
|
#define DEFAULT_RC_BUF_INITIAL_SZ 4000
|
|
|
|
#define DEFAULT_RC_BUF_OPTIMAL_SZ 5000
|
|
|
|
#define DEFAULT_RC_2PASS_VBR_BIAS_PCT 50
|
|
|
|
#define DEFAULT_RC_2PASS_VBR_MINSECTION_PCT 0
|
|
|
|
#define DEFAULT_RC_2PASS_VBR_MAXSECTION_PCT 400
|
|
|
|
|
|
|
|
#define DEFAULT_KF_MODE VPX_KF_AUTO
|
|
|
|
#define DEFAULT_KF_MAX_DIST 128
|
|
|
|
|
2010-06-12 07:02:29 +00:00
|
|
|
#define DEFAULT_MULTIPASS_MODE VPX_RC_ONE_PASS
|
2011-06-19 05:16:57 +00:00
|
|
|
#define DEFAULT_MULTIPASS_CACHE_FILE "multipass.cache"
|
2012-09-08 13:38:40 +00:00
|
|
|
|
|
|
|
#define DEFAULT_TS_NUMBER_LAYERS 1
|
|
|
|
#define DEFAULT_TS_TARGET_BITRATE NULL
|
|
|
|
#define DEFAULT_TS_RATE_DECIMATOR NULL
|
|
|
|
#define DEFAULT_TS_PERIODICITY 0
|
|
|
|
#define DEFAULT_TS_LAYER_ID NULL
|
|
|
|
|
|
|
|
#define DEFAULT_ERROR_RESILIENT 0
|
2011-06-19 09:05:36 +00:00
|
|
|
#define DEFAULT_LAG_IN_FRAMES 0
|
2012-09-08 13:38:40 +00:00
|
|
|
|
|
|
|
#define DEFAULT_THREADS 0
|
|
|
|
|
|
|
|
#define DEFAULT_H_SCALING_MODE VP8E_NORMAL
|
|
|
|
#define DEFAULT_V_SCALING_MODE VP8E_NORMAL
|
|
|
|
#define DEFAULT_CPU_USED 0
|
|
|
|
#define DEFAULT_ENABLE_AUTO_ALT_REF FALSE
|
|
|
|
#define DEFAULT_DEADLINE VPX_DL_BEST_QUALITY
|
2011-07-10 01:53:24 +00:00
|
|
|
#define DEFAULT_NOISE_SENSITIVITY 0
|
2012-09-08 13:38:40 +00:00
|
|
|
#define DEFAULT_SHARPNESS 0
|
2011-07-10 01:53:24 +00:00
|
|
|
#define DEFAULT_STATIC_THRESHOLD 0
|
2012-09-08 13:38:40 +00:00
|
|
|
#define DEFAULT_TOKEN_PARTITIONS 0
|
|
|
|
#define DEFAULT_ARNR_MAXFRAMES 0
|
|
|
|
#define DEFAULT_ARNR_STRENGTH 3
|
|
|
|
#define DEFAULT_ARNR_TYPE 3
|
|
|
|
#define DEFAULT_TUNING VP8_TUNE_PSNR
|
|
|
|
#define DEFAULT_CQ_LEVEL 10
|
|
|
|
#define DEFAULT_MAX_INTRA_BITRATE_PCT 0
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2012-09-08 13:38:40 +00:00
|
|
|
PROP_RC_END_USAGE,
|
|
|
|
PROP_RC_TARGET_BITRATE,
|
|
|
|
PROP_RC_MIN_QUANTIZER,
|
|
|
|
PROP_RC_MAX_QUANTIZER,
|
|
|
|
PROP_RC_DROPFRAME_THRESH,
|
|
|
|
PROP_RC_RESIZE_ALLOWED,
|
|
|
|
PROP_RC_RESIZE_UP_THRESH,
|
|
|
|
PROP_RC_RESIZE_DOWN_THRESH,
|
|
|
|
PROP_RC_UNDERSHOOT_PCT,
|
|
|
|
PROP_RC_OVERSHOOT_PCT,
|
|
|
|
PROP_RC_BUF_SZ,
|
|
|
|
PROP_RC_BUF_INITIAL_SZ,
|
|
|
|
PROP_RC_BUF_OPTIMAL_SZ,
|
|
|
|
PROP_RC_2PASS_VBR_BIAS_PCT,
|
|
|
|
PROP_RC_2PASS_VBR_MINSECTION_PCT,
|
|
|
|
PROP_RC_2PASS_VBR_MAXSECTION_PCT,
|
|
|
|
PROP_KF_MODE,
|
|
|
|
PROP_KF_MAX_DIST,
|
|
|
|
PROP_TS_NUMBER_LAYERS,
|
|
|
|
PROP_TS_TARGET_BITRATE,
|
|
|
|
PROP_TS_RATE_DECIMATOR,
|
|
|
|
PROP_TS_PERIODICITY,
|
|
|
|
PROP_TS_LAYER_ID,
|
2010-06-12 07:02:29 +00:00
|
|
|
PROP_MULTIPASS_MODE,
|
2010-07-10 14:52:10 +00:00
|
|
|
PROP_MULTIPASS_CACHE_FILE,
|
2012-09-08 13:38:40 +00:00
|
|
|
PROP_ERROR_RESILIENT,
|
2011-07-10 01:53:24 +00:00
|
|
|
PROP_LAG_IN_FRAMES,
|
2012-09-08 13:38:40 +00:00
|
|
|
PROP_THREADS,
|
|
|
|
PROP_DEADLINE,
|
|
|
|
PROP_H_SCALING_MODE,
|
|
|
|
PROP_V_SCALING_MODE,
|
|
|
|
PROP_CPU_USED,
|
|
|
|
PROP_ENABLE_AUTO_ALT_REF,
|
2011-07-10 01:53:24 +00:00
|
|
|
PROP_NOISE_SENSITIVITY,
|
2012-09-08 13:38:40 +00:00
|
|
|
PROP_SHARPNESS,
|
2011-07-10 01:53:24 +00:00
|
|
|
PROP_STATIC_THRESHOLD,
|
2012-09-08 13:38:40 +00:00
|
|
|
PROP_TOKEN_PARTITIONS,
|
|
|
|
PROP_ARNR_MAXFRAMES,
|
|
|
|
PROP_ARNR_STRENGTH,
|
|
|
|
PROP_ARNR_TYPE,
|
|
|
|
PROP_TUNING,
|
|
|
|
PROP_CQ_LEVEL,
|
|
|
|
PROP_MAX_INTRA_BITRATE_PCT
|
2010-05-13 08:04:04 +00:00
|
|
|
};
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
#define GST_VP8_ENC_END_USAGE_TYPE (gst_vp8_enc_end_usage_get_type())
|
2010-05-21 13:17:46 +00:00
|
|
|
static GType
|
2012-09-08 13:38:40 +00:00
|
|
|
gst_vp8_enc_end_usage_get_type (void)
|
2010-05-21 13:17:46 +00:00
|
|
|
{
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{VPX_VBR, "Variable Bit Rate (VBR) mode", "vbr"},
|
|
|
|
{VPX_CBR, "Constant Bit Rate (CBR) mode", "cbr"},
|
2012-09-08 13:38:40 +00:00
|
|
|
{VPX_CQ, "Constant Quality Mode (CQ) mode", "cq"},
|
2010-05-21 13:17:46 +00:00
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
static volatile GType id = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
_id = g_enum_register_static ("GstVP8EncEndUsage", values);
|
2010-05-21 13:17:46 +00:00
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2010-06-12 07:02:29 +00:00
|
|
|
#define GST_VP8_ENC_MULTIPASS_MODE_TYPE (gst_vp8_enc_multipass_mode_get_type())
|
|
|
|
static GType
|
|
|
|
gst_vp8_enc_multipass_mode_get_type (void)
|
|
|
|
{
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{VPX_RC_ONE_PASS, "One pass encoding (default)", "one-pass"},
|
|
|
|
{VPX_RC_FIRST_PASS, "First pass of multipass encoding", "first-pass"},
|
|
|
|
{VPX_RC_LAST_PASS, "Last pass of multipass encoding", "last-pass"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
static volatile GType id = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
|
|
|
_id = g_enum_register_static ("GstVP8EncMultipassMode", values);
|
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
#define GST_VP8_ENC_KF_MODE_TYPE (gst_vp8_enc_kf_mode_get_type())
|
2011-07-10 01:53:24 +00:00
|
|
|
static GType
|
2012-09-08 13:38:40 +00:00
|
|
|
gst_vp8_enc_kf_mode_get_type (void)
|
|
|
|
{
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{VPX_KF_AUTO, "Determine optimal placement automatically", "auto"},
|
|
|
|
{VPX_KF_DISABLED, "Don't automatically place keyframes", "disabled"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
static volatile GType id = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
|
|
|
_id = g_enum_register_static ("GstVP8EncKfMode", values);
|
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_VP8_ENC_TUNING_TYPE (gst_vp8_enc_tuning_get_type())
|
|
|
|
static GType
|
|
|
|
gst_vp8_enc_tuning_get_type (void)
|
2011-07-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{VP8_TUNE_PSNR, "Tune for PSNR", "psnr"},
|
|
|
|
{VP8_TUNE_SSIM, "Tune for SSIM", "ssim"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
static volatile GType id = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
_id = g_enum_register_static ("GstVP8EncTuning", values);
|
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_VP8_ENC_SCALING_MODE_TYPE (gst_vp8_enc_scaling_mode_get_type())
|
|
|
|
static GType
|
|
|
|
gst_vp8_enc_scaling_mode_get_type (void)
|
|
|
|
{
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{VP8E_NORMAL, "Normal", "normal"},
|
|
|
|
{VP8E_FOURFIVE, "4:5", "4:5"},
|
|
|
|
{VP8E_THREEFIVE, "3:5", "3:5"},
|
|
|
|
{VP8E_ONETWO, "1:2", "1:2"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
static volatile GType id = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
|
|
|
_id = g_enum_register_static ("GstVP8EncScalingMode", values);
|
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_VP8_ENC_TOKEN_PARTITIONS_TYPE (gst_vp8_enc_token_partitions_get_type())
|
|
|
|
static GType
|
|
|
|
gst_vp8_enc_token_partitions_get_type (void)
|
|
|
|
{
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{VP8_ONE_TOKENPARTITION, "One token partition", "1"},
|
|
|
|
{VP8_TWO_TOKENPARTITION, "Two token partitions", "2"},
|
|
|
|
{VP8_FOUR_TOKENPARTITION, "Four token partitions", "4"},
|
|
|
|
{VP8_EIGHT_TOKENPARTITION, "Eight token partitions", "8"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
static volatile GType id = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
|
|
|
_id = g_enum_register_static ("GstVP8EncTokenPartitions", values);
|
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_VP8_ENC_ER_FLAGS_TYPE (gst_vp8_enc_er_flags_get_type())
|
|
|
|
static GType
|
|
|
|
gst_vp8_enc_er_flags_get_type (void)
|
|
|
|
{
|
|
|
|
static const GFlagsValue values[] = {
|
|
|
|
{VPX_ERROR_RESILIENT_DEFAULT, "Default error resilience", "default"},
|
|
|
|
{VPX_ERROR_RESILIENT_PARTITIONS,
|
|
|
|
"Allow partitions to be decoded independently", "partitions"},
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
static volatile GType id = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter ((gsize *) & id)) {
|
|
|
|
GType _id;
|
|
|
|
|
|
|
|
_id = g_flags_register_static ("GstVP8EncErFlags", values);
|
2011-07-10 01:53:24 +00:00
|
|
|
|
|
|
|
g_once_init_leave ((gsize *) & id, _id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
static void gst_vp8_enc_finalize (GObject * object);
|
|
|
|
static void gst_vp8_enc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_vp8_enc_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
static gboolean gst_vp8_enc_start (GstVideoEncoder * encoder);
|
|
|
|
static gboolean gst_vp8_enc_stop (GstVideoEncoder * encoder);
|
|
|
|
static gboolean gst_vp8_enc_set_format (GstVideoEncoder *
|
|
|
|
video_encoder, GstVideoCodecState * state);
|
|
|
|
static gboolean gst_vp8_enc_finish (GstVideoEncoder * video_encoder);
|
|
|
|
static GstFlowReturn gst_vp8_enc_handle_frame (GstVideoEncoder *
|
|
|
|
video_encoder, GstVideoCodecFrame * frame);
|
|
|
|
static GstFlowReturn gst_vp8_enc_pre_push (GstVideoEncoder * encoder,
|
|
|
|
GstVideoCodecFrame * frame);
|
|
|
|
static gboolean gst_vp8_enc_sink_event (GstVideoEncoder *
|
|
|
|
video_encoder, GstEvent * event);
|
2012-05-28 14:05:21 +00:00
|
|
|
static gboolean gst_vp8_enc_propose_allocation (GstVideoEncoder * encoder,
|
|
|
|
GstQuery * query);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vp8_enc_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-05-28 14:05:21 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420"))
|
2010-05-13 08:04:04 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vp8_enc_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-09-08 13:38:40 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-vp8, " "profile = (int) {0, 1, 2, 3}")
|
2010-05-13 08:04:04 +00:00
|
|
|
);
|
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
<<<<<<<
|
2012-04-24 09:08:41 +00:00
|
|
|
static void
|
|
|
|
do_init (GType vp8enc_type)
|
|
|
|
{
|
|
|
|
static const GInterfaceInfo tag_setter_info = { NULL, NULL, NULL };
|
|
|
|
const GInterfaceInfo preset_interface_info = {
|
|
|
|
NULL, /* interface_init */
|
|
|
|
NULL, /* interface_finalize */
|
|
|
|
NULL /* interface_data */
|
|
|
|
};
|
|
|
|
|
|
|
|
g_type_add_interface_static (vp8enc_type, GST_TYPE_TAG_SETTER,
|
|
|
|
&tag_setter_info);
|
|
|
|
g_type_add_interface_static (vp8enc_type, GST_TYPE_PRESET,
|
|
|
|
&preset_interface_info);
|
|
|
|
}
|
2011-11-03 13:01:41 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstVP8Enc, gst_vp8_enc, GstVideoEncoder,
|
|
|
|
GST_TYPE_VIDEO_ENCODER, do_init);
|
2012-05-28 14:05:21 +00:00
|
|
|
=======
|
|
|
|
#define parent_class gst_vp8_enc_parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVP8Enc, gst_vp8_enc, GST_TYPE_VIDEO_ENCODER,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL);
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL););
|
|
|
|
>>>>>>>
|
2011-11-03 13:01:41 +00:00
|
|
|
|
2010-05-18 12:47:54 +00:00
|
|
|
static void
|
2011-11-03 13:01:41 +00:00
|
|
|
gst_vp8_enc_class_init (GstVP8EncClass * klass)
|
2010-05-18 12:47:54 +00:00
|
|
|
{
|
2011-11-03 13:01:41 +00:00
|
|
|
GObjectClass *gobject_class;
|
2012-05-28 14:05:21 +00:00
|
|
|
GstElementClass *element_class;
|
2012-04-24 09:08:41 +00:00
|
|
|
GstVideoEncoderClass *video_encoder_class;
|
2010-05-18 12:47:54 +00:00
|
|
|
|
2011-11-03 13:01:41 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2012-05-28 14:05:21 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2012-04-24 09:08:41 +00:00
|
|
|
video_encoder_class = GST_VIDEO_ENCODER_CLASS (klass);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2011-11-03 13:01:41 +00:00
|
|
|
gobject_class->set_property = gst_vp8_enc_set_property;
|
|
|
|
gobject_class->get_property = gst_vp8_enc_get_property;
|
|
|
|
gobject_class->finalize = gst_vp8_enc_finalize;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2011-11-28 13:08:27 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_vp8_enc_src_template);
|
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_vp8_enc_sink_template);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-09-14 15:08:49 +00:00
|
|
|
gst_element_class_set_metadata (element_class,
|
2010-05-13 08:04:04 +00:00
|
|
|
"On2 VP8 Encoder",
|
|
|
|
"Codec/Encoder/Video",
|
|
|
|
"Encode VP8 video streams", "David Schleef <ds@entropywave.com>");
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
video_encoder_class->start = gst_vp8_enc_start;
|
|
|
|
video_encoder_class->stop = gst_vp8_enc_stop;
|
|
|
|
video_encoder_class->handle_frame = gst_vp8_enc_handle_frame;
|
|
|
|
video_encoder_class->set_format = gst_vp8_enc_set_format;
|
|
|
|
video_encoder_class->finish = gst_vp8_enc_finish;
|
|
|
|
video_encoder_class->pre_push = gst_vp8_enc_pre_push;
|
|
|
|
video_encoder_class->sink_event = gst_vp8_enc_sink_event;
|
2012-05-28 14:05:21 +00:00
|
|
|
video_encoder_class->propose_allocation = gst_vp8_enc_propose_allocation;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_END_USAGE,
|
|
|
|
g_param_spec_enum ("end-usage", "Rate control mode",
|
|
|
|
"Rate control mode",
|
|
|
|
GST_VP8_ENC_END_USAGE_TYPE, DEFAULT_RC_END_USAGE,
|
2010-05-13 08:04:04 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_TARGET_BITRATE,
|
|
|
|
g_param_spec_int ("target-bitrate", "Target bitrate",
|
|
|
|
"Target bitrate (in bits/sec)",
|
|
|
|
0, G_MAXINT, DEFAULT_RC_TARGET_BITRATE,
|
2010-05-21 13:17:46 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_MIN_QUANTIZER,
|
|
|
|
g_param_spec_int ("min-quantizer", "Minimum Quantizer",
|
|
|
|
"Minimum Quantizer (best)",
|
|
|
|
0, 63, DEFAULT_RC_MIN_QUANTIZER,
|
2011-06-19 14:06:46 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_MAX_QUANTIZER,
|
|
|
|
g_param_spec_int ("max-quantizer", "Maximum Quantizer",
|
|
|
|
"Maximum Quantizer (worst)",
|
|
|
|
0, 63, DEFAULT_RC_MAX_QUANTIZER,
|
2011-06-19 14:06:46 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_DROPFRAME_THRESH,
|
|
|
|
g_param_spec_int ("dropframe-threshold", "Drop Frame Threshold",
|
|
|
|
"Temporal resampling threshold (buf %)",
|
|
|
|
0, 100, DEFAULT_RC_DROPFRAME_THRESH,
|
2011-05-18 11:26:23 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_RESIZE_ALLOWED,
|
|
|
|
g_param_spec_boolean ("resize-allowed", "Resize Allowed",
|
|
|
|
"Allow spatial resampling",
|
|
|
|
DEFAULT_RC_RESIZE_ALLOWED,
|
2011-05-18 11:26:23 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_RESIZE_UP_THRESH,
|
|
|
|
g_param_spec_int ("resize-up-threshold", "Resize Up Threshold",
|
|
|
|
"Upscale threshold (buf %)",
|
|
|
|
0, 100, DEFAULT_RC_RESIZE_UP_THRESH,
|
2010-05-13 08:04:04 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_RESIZE_DOWN_THRESH,
|
|
|
|
g_param_spec_int ("resize-down-threshold", "Resize Down Threshold",
|
|
|
|
"Downscale threshold (buf %)",
|
|
|
|
0, 100, DEFAULT_RC_RESIZE_DOWN_THRESH,
|
2010-05-13 08:04:04 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_UNDERSHOOT_PCT,
|
|
|
|
g_param_spec_int ("undershoot-pct", "Undershoot PCT",
|
|
|
|
"Datarate undershoot (min) target (%)",
|
|
|
|
0, 1000, DEFAULT_RC_UNDERSHOOT_PCT,
|
2010-05-13 08:04:04 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_OVERSHOOT_PCT,
|
|
|
|
g_param_spec_int ("overshoot-pct", "Overshoot PCT",
|
|
|
|
"Datarate overshoot (max) target (%)",
|
|
|
|
0, 1000, DEFAULT_RC_OVERSHOOT_PCT,
|
2010-05-13 08:04:04 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_BUF_SZ,
|
|
|
|
g_param_spec_int ("buffer-size", "Buffer size",
|
|
|
|
"Client buffer size (ms)",
|
|
|
|
0, G_MAXINT, DEFAULT_RC_BUF_SZ,
|
2010-05-13 08:04:04 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
2010-05-20 08:19:54 +00:00
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_BUF_INITIAL_SZ,
|
|
|
|
g_param_spec_int ("buffer-initial-size", "Buffer initial size",
|
|
|
|
"Initial client buffer size (ms)",
|
|
|
|
0, G_MAXINT, DEFAULT_RC_BUF_INITIAL_SZ,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_BUF_OPTIMAL_SZ,
|
|
|
|
g_param_spec_int ("buffer-optimal-size", "Buffer optimal size",
|
|
|
|
"Optimal client buffer size (ms)",
|
|
|
|
0, G_MAXINT, DEFAULT_RC_BUF_OPTIMAL_SZ,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_RC_2PASS_VBR_BIAS_PCT,
|
|
|
|
g_param_spec_int ("twopass-vbr-bias-pct", "2-pass VBR bias",
|
|
|
|
"CBR/VBR bias (0=CBR, 100=VBR)",
|
|
|
|
0, 100, DEFAULT_RC_2PASS_VBR_BIAS_PCT,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_RC_2PASS_VBR_MINSECTION_PCT,
|
|
|
|
g_param_spec_int ("twopass-vbr-minsection-pct", "2-pass GOP min bitrate",
|
|
|
|
"GOP minimum bitrate (% target)", 0, G_MAXINT,
|
|
|
|
DEFAULT_RC_2PASS_VBR_MINSECTION_PCT,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_RC_2PASS_VBR_MAXSECTION_PCT,
|
|
|
|
g_param_spec_int ("twopass-vbr-maxsection-pct", "2-pass GOP max bitrate",
|
|
|
|
"GOP maximum bitrate (% target)", 0, G_MAXINT,
|
|
|
|
DEFAULT_RC_2PASS_VBR_MINSECTION_PCT,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_KF_MODE,
|
|
|
|
g_param_spec_enum ("kf-mode", "Keyframe Mode",
|
|
|
|
"Keyframe placement",
|
|
|
|
GST_VP8_ENC_KF_MODE_TYPE, DEFAULT_KF_MODE,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_KF_MAX_DIST,
|
|
|
|
g_param_spec_int ("kf-max-dist", "Keyframe max distance",
|
|
|
|
"Maximum distance between keyframes (number of frames)",
|
|
|
|
0, G_MAXINT, DEFAULT_KF_MAX_DIST,
|
2010-05-21 19:28:29 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2010-06-12 07:02:29 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MULTIPASS_MODE,
|
|
|
|
g_param_spec_enum ("multipass-mode", "Multipass Mode",
|
|
|
|
"Multipass encode mode",
|
|
|
|
GST_VP8_ENC_MULTIPASS_MODE_TYPE, DEFAULT_MULTIPASS_MODE,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MULTIPASS_CACHE_FILE,
|
|
|
|
g_param_spec_string ("multipass-cache-file", "Multipass Cache File",
|
|
|
|
"Multipass cache file",
|
|
|
|
DEFAULT_MULTIPASS_CACHE_FILE,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_TS_NUMBER_LAYERS,
|
|
|
|
g_param_spec_int ("ts-number-layers", "Number of coding layers",
|
|
|
|
"Number of coding layers to use",
|
|
|
|
1, 5, DEFAULT_TS_NUMBER_LAYERS,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TS_TARGET_BITRATE,
|
|
|
|
g_param_spec_value_array ("ts-target-bitrate",
|
|
|
|
"Coding layer target bitrates",
|
|
|
|
"Target bitrates for coding layers (one per layer, decreasing)",
|
|
|
|
g_param_spec_int ("target-bitrate", "Target bitrate",
|
|
|
|
"Target bitrate", 0, G_MAXINT, DEFAULT_RC_TARGET_BITRATE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS),
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TS_RATE_DECIMATOR,
|
|
|
|
g_param_spec_value_array ("ts-rate-decimator",
|
|
|
|
"Coding layer rate decimator",
|
|
|
|
"Rate decimation factors for each layer",
|
|
|
|
g_param_spec_int ("rate-decimator", "Rate decimator",
|
|
|
|
"Rate decimator", 0, 1000000000, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS),
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TS_PERIODICITY,
|
|
|
|
g_param_spec_int ("ts-periodicity", "Layer periodicity",
|
|
|
|
"Length of sequence that defines layer membership periodicity",
|
|
|
|
0, 16, DEFAULT_TS_PERIODICITY,
|
2010-07-10 14:52:10 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_TS_LAYER_ID,
|
|
|
|
g_param_spec_value_array ("ts-layer-id", "Coding layer identification",
|
|
|
|
"Sequence defining coding layer membership",
|
|
|
|
g_param_spec_int ("layer-id", "Layer ID",
|
|
|
|
"Layer ID", 0, 4, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS),
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-06-19 09:05:36 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LAG_IN_FRAMES,
|
2012-09-08 13:38:40 +00:00
|
|
|
g_param_spec_int ("lag-in-frames", "Lag in frames",
|
|
|
|
"Maximum number of frames to lag",
|
|
|
|
0, 25, DEFAULT_LAG_IN_FRAMES,
|
2011-06-19 09:05:36 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
2010-07-10 14:52:10 +00:00
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ERROR_RESILIENT,
|
|
|
|
g_param_spec_flags ("error-resilient", "Error resilient",
|
|
|
|
"Error resilience flags",
|
|
|
|
GST_VP8_ENC_ER_FLAGS_TYPE, DEFAULT_ERROR_RESILIENT,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_THREADS,
|
|
|
|
g_param_spec_int ("threads", "Threads",
|
|
|
|
"Number of threads to use",
|
|
|
|
0, 64, DEFAULT_THREADS,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DEADLINE,
|
|
|
|
g_param_spec_int64 ("deadline", "Deadline",
|
|
|
|
"Deadline per frame (usec, 0=disabled)",
|
|
|
|
0, G_MAXINT64, DEFAULT_DEADLINE,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_H_SCALING_MODE,
|
|
|
|
g_param_spec_enum ("h-scaling-mode", "Horizontal scaling mode",
|
|
|
|
"Horizontal scaling mode",
|
|
|
|
GST_VP8_ENC_SCALING_MODE_TYPE, DEFAULT_H_SCALING_MODE,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_V_SCALING_MODE,
|
|
|
|
g_param_spec_enum ("v-scaling-mode", "Vertical scaling mode",
|
|
|
|
"Vertical scaling mode",
|
|
|
|
GST_VP8_ENC_SCALING_MODE_TYPE, DEFAULT_V_SCALING_MODE,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CPU_USED,
|
|
|
|
g_param_spec_int ("cpu-used", "CPU used",
|
|
|
|
"CPU used",
|
|
|
|
-16, 16, DEFAULT_CPU_USED,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ENABLE_AUTO_ALT_REF,
|
|
|
|
g_param_spec_boolean ("auto-alt-ref", "Auto alt reference frames",
|
|
|
|
"Automatically generate alt reference frames",
|
|
|
|
DEFAULT_ENABLE_AUTO_ALT_REF,
|
2011-07-10 01:53:24 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_NOISE_SENSITIVITY,
|
2012-09-08 13:38:40 +00:00
|
|
|
g_param_spec_int ("noise-sensitivity", "Noise sensitivity",
|
|
|
|
"Noise sensisivity (frames to blur)",
|
2011-07-10 01:53:24 +00:00
|
|
|
0, 6, DEFAULT_NOISE_SENSITIVITY,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SHARPNESS,
|
|
|
|
g_param_spec_int ("sharpness", "Sharpness",
|
|
|
|
"Filter sharpness",
|
|
|
|
0, 7, DEFAULT_SHARPNESS,
|
2011-07-10 01:53:24 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_STATIC_THRESHOLD,
|
|
|
|
g_param_spec_int ("static-threshold", "Static Threshold",
|
2012-09-08 13:38:40 +00:00
|
|
|
"Motion detection threshold",
|
|
|
|
0, G_MAXINT, DEFAULT_STATIC_THRESHOLD,
|
2011-07-10 01:53:24 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_TOKEN_PARTITIONS,
|
|
|
|
g_param_spec_enum ("token-partitions", "Token partitions",
|
|
|
|
"Number of token partitions",
|
|
|
|
GST_VP8_ENC_TOKEN_PARTITIONS_TYPE, DEFAULT_TOKEN_PARTITIONS,
|
2011-07-10 01:53:24 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ARNR_MAXFRAMES,
|
|
|
|
g_param_spec_int ("arnr-maxframes", "AltRef max frames",
|
|
|
|
"AltRef maximum number of frames",
|
|
|
|
0, 15, DEFAULT_ARNR_MAXFRAMES,
|
2011-07-10 01:53:24 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ARNR_STRENGTH,
|
|
|
|
g_param_spec_int ("arnr-strength", "AltRef strength",
|
|
|
|
"AltRef strength",
|
|
|
|
0, 6, DEFAULT_ARNR_STRENGTH,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ARNR_TYPE,
|
|
|
|
g_param_spec_int ("arnr-type", "AltRef type",
|
|
|
|
"AltRef type",
|
|
|
|
1, 3, DEFAULT_ARNR_TYPE,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TUNING,
|
|
|
|
g_param_spec_enum ("tuning", "Tuning",
|
|
|
|
"Tuning",
|
|
|
|
GST_VP8_ENC_TUNING_TYPE, DEFAULT_TUNING,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CQ_LEVEL,
|
|
|
|
g_param_spec_int ("cq-level", "Constrained quality level",
|
|
|
|
"Constrained quality level",
|
|
|
|
0, 63, DEFAULT_CQ_LEVEL,
|
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_INTRA_BITRATE_PCT,
|
|
|
|
g_param_spec_int ("max-intra-bitrate-pct", "Max Intra bitrate",
|
|
|
|
"Maximum Intra frame bitrate",
|
|
|
|
0, G_MAXINT, DEFAULT_MAX_INTRA_BITRATE_PCT,
|
2011-07-10 01:53:24 +00:00
|
|
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
|
|
|
|
2010-05-20 08:19:54 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vp8enc_debug, "vp8enc", 0, "VP8 Encoder");
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-28 14:05:21 +00:00
|
|
|
gst_vp8_enc_init (GstVP8Enc * gst_vp8_enc)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (gst_vp8_enc, "init");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
gst_vp8_enc->rc_end_usage = DEFAULT_RC_END_USAGE;
|
|
|
|
gst_vp8_enc->rc_target_bitrate = DEFAULT_RC_TARGET_BITRATE;
|
|
|
|
gst_vp8_enc->rc_target_bitrate_set = FALSE;
|
|
|
|
gst_vp8_enc->rc_min_quantizer = DEFAULT_RC_MIN_QUANTIZER;
|
|
|
|
gst_vp8_enc->rc_max_quantizer = DEFAULT_RC_MAX_QUANTIZER;
|
|
|
|
gst_vp8_enc->rc_dropframe_thresh = DEFAULT_RC_DROPFRAME_THRESH;
|
|
|
|
gst_vp8_enc->rc_resize_allowed = DEFAULT_RC_RESIZE_ALLOWED;
|
|
|
|
gst_vp8_enc->rc_resize_up_thresh = DEFAULT_RC_RESIZE_UP_THRESH;
|
|
|
|
gst_vp8_enc->rc_resize_down_thresh = DEFAULT_RC_RESIZE_DOWN_THRESH;
|
|
|
|
gst_vp8_enc->rc_undershoot_pct = DEFAULT_RC_UNDERSHOOT_PCT;
|
|
|
|
gst_vp8_enc->rc_overshoot_pct = DEFAULT_RC_OVERSHOOT_PCT;
|
|
|
|
gst_vp8_enc->rc_buf_sz = DEFAULT_RC_BUF_SZ;
|
|
|
|
gst_vp8_enc->rc_buf_initial_sz = DEFAULT_RC_BUF_INITIAL_SZ;
|
|
|
|
gst_vp8_enc->rc_buf_optimal_sz = DEFAULT_RC_BUF_OPTIMAL_SZ;
|
|
|
|
gst_vp8_enc->rc_2pass_vbr_bias_pct = DEFAULT_RC_2PASS_VBR_BIAS_PCT;
|
|
|
|
gst_vp8_enc->rc_2pass_vbr_minsection_pct =
|
|
|
|
DEFAULT_RC_2PASS_VBR_MINSECTION_PCT;
|
|
|
|
gst_vp8_enc->rc_2pass_vbr_maxsection_pct =
|
|
|
|
DEFAULT_RC_2PASS_VBR_MAXSECTION_PCT;
|
|
|
|
gst_vp8_enc->kf_mode = DEFAULT_KF_MODE;
|
|
|
|
gst_vp8_enc->kf_max_dist = DEFAULT_KF_MAX_DIST;
|
2010-06-12 07:02:29 +00:00
|
|
|
gst_vp8_enc->multipass_mode = DEFAULT_MULTIPASS_MODE;
|
2011-06-19 05:16:57 +00:00
|
|
|
gst_vp8_enc->multipass_cache_file = g_strdup (DEFAULT_MULTIPASS_CACHE_FILE);
|
2012-09-08 13:38:40 +00:00
|
|
|
gst_vp8_enc->ts_number_layers = DEFAULT_TS_NUMBER_LAYERS;
|
|
|
|
gst_vp8_enc->n_ts_target_bitrate = 0;
|
|
|
|
gst_vp8_enc->n_ts_rate_decimator = 0;
|
|
|
|
gst_vp8_enc->ts_periodicity = DEFAULT_TS_PERIODICITY;
|
|
|
|
gst_vp8_enc->n_ts_layer_id = 0;
|
|
|
|
gst_vp8_enc->error_resilient = DEFAULT_ERROR_RESILIENT;
|
2011-06-19 09:05:36 +00:00
|
|
|
gst_vp8_enc->lag_in_frames = DEFAULT_LAG_IN_FRAMES;
|
2012-09-08 13:38:40 +00:00
|
|
|
gst_vp8_enc->threads = DEFAULT_THREADS;
|
|
|
|
gst_vp8_enc->deadline = DEFAULT_DEADLINE;
|
|
|
|
gst_vp8_enc->h_scaling_mode = DEFAULT_H_SCALING_MODE;
|
|
|
|
gst_vp8_enc->v_scaling_mode = DEFAULT_V_SCALING_MODE;
|
|
|
|
gst_vp8_enc->cpu_used = DEFAULT_CPU_USED;
|
|
|
|
gst_vp8_enc->enable_auto_alt_ref = DEFAULT_ENABLE_AUTO_ALT_REF;
|
|
|
|
gst_vp8_enc->noise_sensitivity = DEFAULT_NOISE_SENSITIVITY;
|
|
|
|
gst_vp8_enc->sharpness = DEFAULT_SHARPNESS;
|
|
|
|
gst_vp8_enc->static_threshold = DEFAULT_STATIC_THRESHOLD;
|
|
|
|
gst_vp8_enc->token_partitions = DEFAULT_TOKEN_PARTITIONS;
|
|
|
|
gst_vp8_enc->arnr_maxframes = DEFAULT_ARNR_MAXFRAMES;
|
|
|
|
gst_vp8_enc->arnr_strength = DEFAULT_ARNR_STRENGTH;
|
|
|
|
gst_vp8_enc->arnr_type = DEFAULT_ARNR_TYPE;
|
|
|
|
gst_vp8_enc->tuning = DEFAULT_TUNING;
|
|
|
|
gst_vp8_enc->cq_level = DEFAULT_CQ_LEVEL;
|
|
|
|
gst_vp8_enc->max_intra_bitrate_pct = DEFAULT_MAX_INTRA_BITRATE_PCT;
|
|
|
|
|
|
|
|
gst_vp8_enc->profile = DEFAULT_PROFILE;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_enc_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstVP8Enc *gst_vp8_enc;
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (object, "finalize");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-07-03 15:47:29 +00:00
|
|
|
g_return_if_fail (GST_IS_VP8_ENC (object));
|
2010-05-13 08:04:04 +00:00
|
|
|
gst_vp8_enc = GST_VP8_ENC (object);
|
|
|
|
|
2010-06-12 07:02:29 +00:00
|
|
|
g_free (gst_vp8_enc->multipass_cache_file);
|
|
|
|
gst_vp8_enc->multipass_cache_file = NULL;
|
|
|
|
|
2012-06-07 11:33:31 +00:00
|
|
|
if (gst_vp8_enc->input_state)
|
|
|
|
gst_video_codec_state_unref (gst_vp8_enc->input_state);
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_enc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVP8Enc *gst_vp8_enc;
|
|
|
|
|
2010-07-03 15:47:29 +00:00
|
|
|
g_return_if_fail (GST_IS_VP8_ENC (object));
|
2010-05-13 08:04:04 +00:00
|
|
|
gst_vp8_enc = GST_VP8_ENC (object);
|
|
|
|
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_DEBUG_OBJECT (object, "gst_vp8_enc_set_property");
|
2010-05-13 08:04:04 +00:00
|
|
|
switch (prop_id) {
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_END_USAGE:
|
|
|
|
gst_vp8_enc->rc_end_usage = g_value_get_enum (value);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_TARGET_BITRATE:
|
|
|
|
gst_vp8_enc->rc_target_bitrate = g_value_get_int (value);
|
|
|
|
gst_vp8_enc->rc_target_bitrate_set = TRUE;
|
2010-05-21 13:17:46 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_MIN_QUANTIZER:
|
|
|
|
gst_vp8_enc->rc_min_quantizer = g_value_get_int (value);
|
2011-06-19 14:06:46 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_MAX_QUANTIZER:
|
|
|
|
gst_vp8_enc->rc_max_quantizer = g_value_get_int (value);
|
2011-06-19 14:06:46 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_DROPFRAME_THRESH:
|
|
|
|
gst_vp8_enc->rc_dropframe_thresh = g_value_get_int (value);
|
2011-05-18 11:26:23 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_RESIZE_ALLOWED:
|
|
|
|
gst_vp8_enc->rc_resize_allowed = g_value_get_boolean (value);
|
2011-05-18 11:26:23 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_RESIZE_UP_THRESH:
|
|
|
|
gst_vp8_enc->rc_resize_up_thresh = g_value_get_int (value);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_RESIZE_DOWN_THRESH:
|
|
|
|
gst_vp8_enc->rc_resize_down_thresh = g_value_get_int (value);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_UNDERSHOOT_PCT:
|
|
|
|
gst_vp8_enc->rc_undershoot_pct = g_value_get_int (value);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_OVERSHOOT_PCT:
|
|
|
|
gst_vp8_enc->rc_overshoot_pct = g_value_get_int (value);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_BUF_SZ:
|
|
|
|
gst_vp8_enc->rc_buf_sz = g_value_get_int (value);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_BUF_INITIAL_SZ:
|
|
|
|
gst_vp8_enc->rc_buf_initial_sz = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_RC_BUF_OPTIMAL_SZ:
|
|
|
|
gst_vp8_enc->rc_buf_optimal_sz = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_RC_2PASS_VBR_BIAS_PCT:
|
|
|
|
gst_vp8_enc->rc_2pass_vbr_bias_pct = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_RC_2PASS_VBR_MINSECTION_PCT:
|
|
|
|
gst_vp8_enc->rc_2pass_vbr_minsection_pct = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_RC_2PASS_VBR_MAXSECTION_PCT:
|
|
|
|
gst_vp8_enc->rc_2pass_vbr_maxsection_pct = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_KF_MODE:
|
|
|
|
gst_vp8_enc->kf_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_KF_MAX_DIST:
|
|
|
|
gst_vp8_enc->kf_max_dist = g_value_get_int (value);
|
2010-05-21 19:28:29 +00:00
|
|
|
break;
|
2010-06-12 07:02:29 +00:00
|
|
|
case PROP_MULTIPASS_MODE:
|
|
|
|
gst_vp8_enc->multipass_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_MULTIPASS_CACHE_FILE:
|
|
|
|
if (gst_vp8_enc->multipass_cache_file)
|
|
|
|
g_free (gst_vp8_enc->multipass_cache_file);
|
|
|
|
gst_vp8_enc->multipass_cache_file = g_value_dup_string (value);
|
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_TS_NUMBER_LAYERS:
|
|
|
|
gst_vp8_enc->ts_number_layers = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_TS_TARGET_BITRATE:{
|
|
|
|
GValueArray *va = g_value_get_boxed (value);
|
|
|
|
|
|
|
|
if (va->n_values > VPX_TS_MAX_LAYERS) {
|
|
|
|
g_warning ("%s: Only %d layers allowed at maximum",
|
|
|
|
GST_ELEMENT_NAME (gst_vp8_enc), VPX_TS_MAX_LAYERS);
|
|
|
|
} else if (va) {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < va->n_values; i++)
|
|
|
|
gst_vp8_enc->ts_target_bitrate[i] =
|
|
|
|
g_value_get_int (g_value_array_get_nth (va, i));
|
|
|
|
gst_vp8_enc->n_ts_target_bitrate = va->n_values;
|
|
|
|
} else {
|
|
|
|
gst_vp8_enc->n_ts_target_bitrate = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_TS_RATE_DECIMATOR:{
|
|
|
|
GValueArray *va = g_value_get_boxed (value);
|
|
|
|
|
|
|
|
if (va->n_values > VPX_TS_MAX_LAYERS) {
|
|
|
|
g_warning ("%s: Only %d layers allowed at maximum",
|
|
|
|
GST_ELEMENT_NAME (gst_vp8_enc), VPX_TS_MAX_LAYERS);
|
|
|
|
} else if (va) {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < va->n_values; i++)
|
|
|
|
gst_vp8_enc->ts_rate_decimator[i] =
|
|
|
|
g_value_get_int (g_value_array_get_nth (va, i));
|
|
|
|
gst_vp8_enc->n_ts_rate_decimator = va->n_values;
|
|
|
|
} else {
|
|
|
|
gst_vp8_enc->n_ts_rate_decimator = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_TS_PERIODICITY:
|
|
|
|
gst_vp8_enc->ts_periodicity = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_TS_LAYER_ID:{
|
|
|
|
GValueArray *va = g_value_get_boxed (value);
|
|
|
|
|
|
|
|
if (va->n_values > VPX_TS_MAX_PERIODICITY) {
|
|
|
|
g_warning ("%s: Only %d sized layer sequences allowed at maximum",
|
|
|
|
GST_ELEMENT_NAME (gst_vp8_enc), VPX_TS_MAX_PERIODICITY);
|
|
|
|
} else if (va) {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < va->n_values; i++)
|
|
|
|
gst_vp8_enc->ts_layer_id[i] =
|
|
|
|
g_value_get_int (g_value_array_get_nth (va, i));
|
|
|
|
gst_vp8_enc->n_ts_layer_id = va->n_values;
|
|
|
|
} else {
|
|
|
|
gst_vp8_enc->n_ts_layer_id = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_ERROR_RESILIENT:
|
|
|
|
gst_vp8_enc->error_resilient = g_value_get_flags (value);
|
2010-07-10 14:52:10 +00:00
|
|
|
break;
|
2011-06-19 09:05:36 +00:00
|
|
|
case PROP_LAG_IN_FRAMES:
|
2012-09-08 13:38:40 +00:00
|
|
|
gst_vp8_enc->lag_in_frames = g_value_get_int (value);
|
2011-06-19 09:05:36 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_THREADS:
|
|
|
|
gst_vp8_enc->threads = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_DEADLINE:
|
|
|
|
gst_vp8_enc->deadline = g_value_get_int64 (value);
|
|
|
|
break;
|
|
|
|
case PROP_H_SCALING_MODE:
|
|
|
|
gst_vp8_enc->h_scaling_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_V_SCALING_MODE:
|
|
|
|
gst_vp8_enc->v_scaling_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_CPU_USED:
|
|
|
|
gst_vp8_enc->cpu_used = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_ENABLE_AUTO_ALT_REF:
|
|
|
|
gst_vp8_enc->enable_auto_alt_ref = g_value_get_boolean (value);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
|
|
|
case PROP_NOISE_SENSITIVITY:
|
|
|
|
gst_vp8_enc->noise_sensitivity = g_value_get_int (value);
|
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_SHARPNESS:
|
|
|
|
gst_vp8_enc->sharpness = g_value_get_int (value);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
|
|
|
case PROP_STATIC_THRESHOLD:
|
|
|
|
gst_vp8_enc->static_threshold = g_value_get_int (value);
|
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_TOKEN_PARTITIONS:
|
|
|
|
gst_vp8_enc->token_partitions = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_ARNR_MAXFRAMES:
|
|
|
|
gst_vp8_enc->arnr_maxframes = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_ARNR_STRENGTH:
|
|
|
|
gst_vp8_enc->arnr_strength = g_value_get_int (value);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_ARNR_TYPE:
|
|
|
|
gst_vp8_enc->arnr_type = g_value_get_int (value);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_TUNING:
|
|
|
|
gst_vp8_enc->tuning = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_CQ_LEVEL:
|
|
|
|
gst_vp8_enc->cq_level = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_MAX_INTRA_BITRATE_PCT:
|
|
|
|
gst_vp8_enc->max_intra_bitrate_pct = g_value_get_int (value);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
2010-05-13 08:04:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vp8_enc_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVP8Enc *gst_vp8_enc;
|
|
|
|
|
2010-07-03 15:47:29 +00:00
|
|
|
g_return_if_fail (GST_IS_VP8_ENC (object));
|
2010-05-13 08:04:04 +00:00
|
|
|
gst_vp8_enc = GST_VP8_ENC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_END_USAGE:
|
|
|
|
g_value_set_enum (value, gst_vp8_enc->rc_end_usage);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_TARGET_BITRATE:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_target_bitrate);
|
2010-05-21 13:17:46 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_MIN_QUANTIZER:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_min_quantizer);
|
2011-06-19 14:06:46 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_MAX_QUANTIZER:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_max_quantizer);
|
2011-06-19 14:06:46 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_DROPFRAME_THRESH:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_dropframe_thresh);
|
2011-05-18 11:26:23 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_RESIZE_ALLOWED:
|
|
|
|
g_value_set_boolean (value, gst_vp8_enc->rc_resize_allowed);
|
2011-05-18 11:26:23 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_RESIZE_UP_THRESH:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_resize_up_thresh);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_RESIZE_DOWN_THRESH:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_resize_down_thresh);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_UNDERSHOOT_PCT:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_undershoot_pct);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_OVERSHOOT_PCT:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_overshoot_pct);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_BUF_SZ:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_buf_sz);
|
2010-05-13 08:04:04 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_RC_BUF_INITIAL_SZ:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_buf_initial_sz);
|
|
|
|
break;
|
|
|
|
case PROP_RC_BUF_OPTIMAL_SZ:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_buf_optimal_sz);
|
|
|
|
break;
|
|
|
|
case PROP_RC_2PASS_VBR_BIAS_PCT:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_2pass_vbr_bias_pct);
|
|
|
|
break;
|
|
|
|
case PROP_RC_2PASS_VBR_MINSECTION_PCT:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_2pass_vbr_minsection_pct);
|
|
|
|
break;
|
|
|
|
case PROP_RC_2PASS_VBR_MAXSECTION_PCT:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->rc_2pass_vbr_maxsection_pct);
|
|
|
|
break;
|
|
|
|
case PROP_KF_MODE:
|
|
|
|
g_value_set_enum (value, gst_vp8_enc->kf_mode);
|
|
|
|
break;
|
|
|
|
case PROP_KF_MAX_DIST:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->kf_max_dist);
|
2010-05-21 19:28:29 +00:00
|
|
|
break;
|
2010-06-12 07:02:29 +00:00
|
|
|
case PROP_MULTIPASS_MODE:
|
|
|
|
g_value_set_enum (value, gst_vp8_enc->multipass_mode);
|
|
|
|
break;
|
|
|
|
case PROP_MULTIPASS_CACHE_FILE:
|
|
|
|
g_value_set_string (value, gst_vp8_enc->multipass_cache_file);
|
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_TS_NUMBER_LAYERS:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->ts_number_layers);
|
|
|
|
break;
|
|
|
|
case PROP_TS_TARGET_BITRATE:{
|
|
|
|
GValueArray *va;
|
|
|
|
|
|
|
|
if (gst_vp8_enc->n_ts_target_bitrate == 0) {
|
|
|
|
g_value_set_boxed (value, NULL);
|
|
|
|
} else {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
va = g_value_array_new (gst_vp8_enc->n_ts_target_bitrate);
|
|
|
|
for (i = 0; i < gst_vp8_enc->n_ts_target_bitrate; i++) {
|
|
|
|
GValue v = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&v, G_TYPE_INT);
|
|
|
|
g_value_set_int (&v, gst_vp8_enc->ts_target_bitrate[i]);
|
|
|
|
g_value_array_append (va, &v);
|
|
|
|
g_value_unset (&v);
|
|
|
|
}
|
|
|
|
g_value_set_boxed (value, va);
|
|
|
|
g_value_array_free (va);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_TS_RATE_DECIMATOR:{
|
|
|
|
GValueArray *va;
|
|
|
|
|
|
|
|
if (gst_vp8_enc->n_ts_rate_decimator == 0) {
|
|
|
|
g_value_set_boxed (value, NULL);
|
|
|
|
} else {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
va = g_value_array_new (gst_vp8_enc->n_ts_rate_decimator);
|
|
|
|
for (i = 0; i < gst_vp8_enc->n_ts_rate_decimator; i++) {
|
|
|
|
GValue v = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&v, G_TYPE_INT);
|
|
|
|
g_value_set_int (&v, gst_vp8_enc->ts_rate_decimator[i]);
|
|
|
|
g_value_array_append (va, &v);
|
|
|
|
g_value_unset (&v);
|
|
|
|
}
|
|
|
|
g_value_set_boxed (value, va);
|
|
|
|
g_value_array_free (va);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_TS_PERIODICITY:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->ts_periodicity);
|
|
|
|
break;
|
|
|
|
case PROP_TS_LAYER_ID:{
|
|
|
|
GValueArray *va;
|
|
|
|
|
|
|
|
if (gst_vp8_enc->n_ts_layer_id == 0) {
|
|
|
|
g_value_set_boxed (value, NULL);
|
|
|
|
} else {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
va = g_value_array_new (gst_vp8_enc->n_ts_layer_id);
|
|
|
|
for (i = 0; i < gst_vp8_enc->n_ts_layer_id; i++) {
|
|
|
|
GValue v = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&v, G_TYPE_INT);
|
|
|
|
g_value_set_int (&v, gst_vp8_enc->ts_layer_id[i]);
|
|
|
|
g_value_array_append (va, &v);
|
|
|
|
g_value_unset (&v);
|
|
|
|
}
|
|
|
|
g_value_set_boxed (value, va);
|
|
|
|
g_value_array_free (va);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_ERROR_RESILIENT:
|
|
|
|
g_value_set_flags (value, gst_vp8_enc->error_resilient);
|
2010-07-10 14:52:10 +00:00
|
|
|
break;
|
2011-06-19 09:05:36 +00:00
|
|
|
case PROP_LAG_IN_FRAMES:
|
2012-09-08 13:38:40 +00:00
|
|
|
g_value_set_int (value, gst_vp8_enc->lag_in_frames);
|
2011-06-19 09:05:36 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_THREADS:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->threads);
|
|
|
|
break;
|
|
|
|
case PROP_DEADLINE:
|
|
|
|
g_value_set_int64 (value, gst_vp8_enc->deadline);
|
|
|
|
break;
|
|
|
|
case PROP_H_SCALING_MODE:
|
|
|
|
g_value_set_enum (value, gst_vp8_enc->h_scaling_mode);
|
|
|
|
break;
|
|
|
|
case PROP_V_SCALING_MODE:
|
|
|
|
g_value_set_enum (value, gst_vp8_enc->v_scaling_mode);
|
|
|
|
break;
|
|
|
|
case PROP_CPU_USED:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->cpu_used);
|
|
|
|
break;
|
|
|
|
case PROP_ENABLE_AUTO_ALT_REF:
|
|
|
|
g_value_set_boolean (value, gst_vp8_enc->enable_auto_alt_ref);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
|
|
|
case PROP_NOISE_SENSITIVITY:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->noise_sensitivity);
|
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_SHARPNESS:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->sharpness);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
|
|
|
case PROP_STATIC_THRESHOLD:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->static_threshold);
|
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_TOKEN_PARTITIONS:
|
|
|
|
g_value_set_enum (value, gst_vp8_enc->token_partitions);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_ARNR_MAXFRAMES:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->arnr_maxframes);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
2012-09-08 13:38:40 +00:00
|
|
|
case PROP_ARNR_STRENGTH:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->arnr_strength);
|
|
|
|
break;
|
|
|
|
case PROP_ARNR_TYPE:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->arnr_type);
|
|
|
|
break;
|
|
|
|
case PROP_TUNING:
|
|
|
|
g_value_set_enum (value, gst_vp8_enc->tuning);
|
|
|
|
break;
|
|
|
|
case PROP_CQ_LEVEL:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->cq_level);
|
|
|
|
break;
|
|
|
|
case PROP_MAX_INTRA_BITRATE_PCT:
|
|
|
|
g_value_set_int (value, gst_vp8_enc->max_intra_bitrate_pct);
|
2011-07-10 01:53:24 +00:00
|
|
|
break;
|
2010-05-13 08:04:04 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_vp8_enc_start (GstVideoEncoder * video_encoder)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_DEBUG_OBJECT (video_encoder, "start");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_vp8_enc_stop (GstVideoEncoder * video_encoder)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
|
|
|
GstVP8Enc *encoder;
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_DEBUG_OBJECT (video_encoder, "stop");
|
2010-05-19 15:13:17 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
encoder = GST_VP8_ENC (video_encoder);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
if (encoder->inited) {
|
|
|
|
vpx_codec_destroy (&encoder->encoder);
|
|
|
|
encoder->inited = FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-12 07:02:29 +00:00
|
|
|
if (encoder->first_pass_cache_content) {
|
|
|
|
g_byte_array_free (encoder->first_pass_cache_content, TRUE);
|
|
|
|
encoder->first_pass_cache_content = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoder->last_pass_cache_content.buf) {
|
|
|
|
g_free (encoder->last_pass_cache_content.buf);
|
|
|
|
encoder->last_pass_cache_content.buf = NULL;
|
|
|
|
encoder->last_pass_cache_content.sz = 0;
|
|
|
|
}
|
|
|
|
|
2010-05-18 12:47:54 +00:00
|
|
|
gst_tag_setter_reset_tags (GST_TAG_SETTER (encoder));
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
static gint
|
|
|
|
gst_vp8_enc_get_downstream_profile (GstVP8Enc * encoder)
|
|
|
|
{
|
|
|
|
GstCaps *allowed;
|
|
|
|
GstStructure *s;
|
|
|
|
gint profile = DEFAULT_PROFILE;
|
|
|
|
|
|
|
|
allowed = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder));
|
|
|
|
if (allowed) {
|
|
|
|
allowed = gst_caps_truncate (allowed);
|
|
|
|
s = gst_caps_get_structure (allowed, 0);
|
|
|
|
if (gst_structure_has_field (s, "profile")) {
|
|
|
|
const GValue *v = gst_structure_get_value (s, "profile");
|
|
|
|
|
|
|
|
if (GST_VALUE_HOLDS_LIST (v) && gst_value_list_get_size (v) > 0) {
|
|
|
|
profile = g_value_get_int (gst_value_list_get_value (v, 0));
|
|
|
|
} else if (G_VALUE_HOLDS_INT (v)) {
|
|
|
|
profile = g_value_get_int (v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_caps_unref (allowed);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (encoder, "Using profile %d", profile);
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
static gboolean
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_vp8_enc_set_format (GstVideoEncoder * video_encoder,
|
|
|
|
GstVideoCodecState * state)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
2011-03-24 10:55:41 +00:00
|
|
|
GstVP8Enc *encoder;
|
|
|
|
vpx_codec_enc_cfg_t cfg;
|
|
|
|
vpx_codec_err_t status;
|
2011-03-24 12:59:35 +00:00
|
|
|
vpx_image_t *image;
|
|
|
|
guint8 *data = NULL;
|
2011-08-12 10:08:08 +00:00
|
|
|
GstCaps *caps;
|
2012-04-24 09:08:41 +00:00
|
|
|
gboolean ret = TRUE;
|
|
|
|
GstVideoInfo *info = &state->info;
|
|
|
|
GstVideoCodecState *output_state;
|
2011-03-24 10:55:41 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
encoder = GST_VP8_ENC (video_encoder);
|
|
|
|
GST_DEBUG_OBJECT (video_encoder, "set_format");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2011-03-24 10:55:41 +00:00
|
|
|
if (encoder->inited) {
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_DEBUG_OBJECT (video_encoder, "refusing renegotiation");
|
2011-03-24 10:55:41 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = vpx_codec_enc_config_default (&vpx_codec_vp8_cx_algo, &cfg, 0);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_ELEMENT_ERROR (encoder, LIBRARY, INIT,
|
|
|
|
("Failed to get default encoder configuration"), ("%s",
|
|
|
|
gst_vpx_error_name (status)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
encoder->profile = gst_vp8_enc_get_downstream_profile (encoder);
|
|
|
|
|
2012-05-18 11:46:55 +00:00
|
|
|
/* Scale default bitrate to our size */
|
|
|
|
cfg.rc_target_bitrate = gst_util_uint64_scale (cfg.rc_target_bitrate,
|
|
|
|
GST_VIDEO_INFO_WIDTH (info) * GST_VIDEO_INFO_HEIGHT (info),
|
|
|
|
cfg.g_w * cfg.g_h);
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
cfg.g_w = GST_VIDEO_INFO_WIDTH (info);
|
|
|
|
cfg.g_h = GST_VIDEO_INFO_HEIGHT (info);
|
|
|
|
cfg.g_timebase.num = GST_VIDEO_INFO_FPS_D (info);
|
|
|
|
cfg.g_timebase.den = GST_VIDEO_INFO_FPS_N (info);
|
2011-03-24 10:55:41 +00:00
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
cfg.rc_end_usage = encoder->rc_end_usage;
|
|
|
|
if (encoder->rc_target_bitrate_set)
|
|
|
|
cfg.rc_target_bitrate = encoder->rc_target_bitrate / 1000;
|
|
|
|
cfg.rc_min_quantizer = encoder->rc_min_quantizer;
|
|
|
|
cfg.rc_max_quantizer = encoder->rc_max_quantizer;
|
|
|
|
cfg.rc_dropframe_thresh = encoder->rc_dropframe_thresh;
|
|
|
|
cfg.rc_resize_allowed = encoder->rc_resize_allowed;
|
|
|
|
cfg.rc_resize_up_thresh = encoder->rc_resize_up_thresh;
|
|
|
|
cfg.rc_resize_down_thresh = encoder->rc_resize_down_thresh;
|
|
|
|
cfg.rc_undershoot_pct = encoder->rc_undershoot_pct;
|
|
|
|
cfg.rc_overshoot_pct = encoder->rc_overshoot_pct;
|
|
|
|
cfg.rc_buf_sz = encoder->rc_buf_sz;
|
|
|
|
cfg.rc_buf_initial_sz = encoder->rc_buf_initial_sz;
|
|
|
|
cfg.rc_buf_optimal_sz = encoder->rc_buf_optimal_sz;
|
|
|
|
cfg.rc_2pass_vbr_bias_pct = encoder->rc_2pass_vbr_bias_pct;
|
|
|
|
cfg.rc_2pass_vbr_minsection_pct = encoder->rc_2pass_vbr_minsection_pct;
|
|
|
|
cfg.rc_2pass_vbr_maxsection_pct = encoder->rc_2pass_vbr_maxsection_pct;
|
|
|
|
cfg.kf_mode = encoder->kf_mode;
|
|
|
|
cfg.kf_max_dist = encoder->kf_max_dist;
|
|
|
|
cfg.ts_number_layers = encoder->ts_number_layers;
|
|
|
|
memcpy (cfg.ts_target_bitrate, encoder->ts_target_bitrate,
|
|
|
|
sizeof (encoder->ts_target_bitrate));
|
|
|
|
memcpy (cfg.ts_rate_decimator, encoder->ts_rate_decimator,
|
|
|
|
sizeof (encoder->ts_rate_decimator));
|
|
|
|
cfg.ts_periodicity = encoder->ts_periodicity;
|
|
|
|
memcpy (cfg.ts_layer_id, encoder->ts_layer_id, sizeof (encoder->ts_layer_id));
|
2011-03-24 10:55:41 +00:00
|
|
|
cfg.g_error_resilient = encoder->error_resilient;
|
2012-09-08 13:38:40 +00:00
|
|
|
cfg.g_lag_in_frames = encoder->lag_in_frames;
|
2011-03-24 10:55:41 +00:00
|
|
|
cfg.g_threads = encoder->threads;
|
|
|
|
|
|
|
|
cfg.g_pass = encoder->multipass_mode;
|
|
|
|
if (encoder->multipass_mode == VPX_RC_FIRST_PASS) {
|
|
|
|
encoder->first_pass_cache_content = g_byte_array_sized_new (4096);
|
|
|
|
} else if (encoder->multipass_mode == VPX_RC_LAST_PASS) {
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
if (!encoder->multipass_cache_file) {
|
|
|
|
GST_ELEMENT_ERROR (encoder, RESOURCE, OPEN_READ,
|
|
|
|
("No multipass cache file provided"), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_file_get_contents (encoder->multipass_cache_file,
|
|
|
|
(gchar **) & encoder->last_pass_cache_content.buf,
|
|
|
|
&encoder->last_pass_cache_content.sz, &err)) {
|
|
|
|
GST_ELEMENT_ERROR (encoder, RESOURCE, OPEN_READ,
|
|
|
|
("Failed to read multipass cache file provided"), ("%s",
|
|
|
|
err->message));
|
|
|
|
g_error_free (err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
cfg.rc_twopass_stats_in = encoder->last_pass_cache_content;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = vpx_codec_enc_init (&encoder->encoder, &vpx_codec_vp8_cx_algo,
|
|
|
|
&cfg, 0);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_ELEMENT_ERROR (encoder, LIBRARY, INIT,
|
|
|
|
("Failed to initialize encoder"), ("%s", gst_vpx_error_name (status)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
{
|
|
|
|
vpx_scaling_mode_t sm;
|
|
|
|
|
|
|
|
sm.h_scaling_mode = encoder->h_scaling_mode;
|
|
|
|
sm.v_scaling_mode = encoder->v_scaling_mode;
|
|
|
|
|
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_SCALEMODE, &sm);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder, "Failed to set VP8E_SET_SCALEMODE: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status =
|
|
|
|
vpx_codec_control (&encoder->encoder, VP8E_SET_CPUUSED,
|
|
|
|
encoder->cpu_used);
|
2011-03-24 10:55:41 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
2012-09-08 13:38:40 +00:00
|
|
|
GST_WARNING_OBJECT (encoder, "Failed to set VP8E_SET_CPUUSED: %s",
|
2011-03-24 10:55:41 +00:00
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
|
2012-09-08 13:38:40 +00:00
|
|
|
status =
|
|
|
|
vpx_codec_control (&encoder->encoder, VP8E_SET_ENABLEAUTOALTREF,
|
|
|
|
(encoder->enable_auto_alt_ref ? 1 : 0));
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_ENABLEAUTOALTREF: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
2011-07-10 01:53:24 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_NOISE_SENSITIVITY,
|
|
|
|
encoder->noise_sensitivity);
|
2012-09-08 13:38:40 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_NOISE_SENSITIVITY: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
2011-07-10 01:53:24 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_SHARPNESS,
|
|
|
|
encoder->sharpness);
|
2012-09-08 13:38:40 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_SHARPNESS: %s", gst_vpx_error_name (status));
|
|
|
|
}
|
2011-07-10 01:53:24 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_STATIC_THRESHOLD,
|
|
|
|
encoder->static_threshold);
|
2012-09-08 13:38:40 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_STATIC_THRESHOLD: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
2011-07-10 01:53:24 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_TOKEN_PARTITIONS,
|
2012-09-08 13:38:40 +00:00
|
|
|
encoder->token_partitions);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_TOKEN_PARTIONS: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
2011-07-10 01:53:24 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_ARNR_MAXFRAMES,
|
|
|
|
encoder->arnr_maxframes);
|
2012-09-08 13:38:40 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_ARNR_MAXFRAMES: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
2011-07-10 01:53:24 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_ARNR_STRENGTH,
|
|
|
|
encoder->arnr_strength);
|
2012-09-08 13:38:40 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_ARNR_STRENGTH: %s",
|
|
|
|
gst_vpx_error_name (status));
|
|
|
|
}
|
2011-07-10 01:53:24 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_ARNR_TYPE,
|
|
|
|
encoder->arnr_type);
|
2012-09-08 13:38:40 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_ARNR_TYPE: %s", gst_vpx_error_name (status));
|
|
|
|
}
|
2011-07-10 01:53:24 +00:00
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_TUNING,
|
|
|
|
encoder->tuning);
|
2011-03-24 10:55:41 +00:00
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
2012-09-08 13:38:40 +00:00
|
|
|
"Failed to set VP8E_SET_TUNING: %s", gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_CQ_LEVEL,
|
|
|
|
encoder->cq_level);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_CQ_LEVEL: %s", gst_vpx_error_name (status));
|
|
|
|
}
|
|
|
|
status = vpx_codec_control (&encoder->encoder, VP8E_SET_MAX_INTRA_BITRATE_PCT,
|
|
|
|
encoder->max_intra_bitrate_pct);
|
|
|
|
if (status != VPX_CODEC_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder,
|
|
|
|
"Failed to set VP8E_SET_MAX_INTRA_BITRATE_PCT: %s",
|
|
|
|
gst_vpx_error_name (status));
|
2011-03-24 10:55:41 +00:00
|
|
|
}
|
2011-06-19 09:05:36 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_video_encoder_set_latency (video_encoder, 0,
|
2012-09-08 13:38:40 +00:00
|
|
|
gst_util_uint64_scale (encoder->lag_in_frames,
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_VIDEO_INFO_FPS_D (info) * GST_SECOND,
|
|
|
|
GST_VIDEO_INFO_FPS_N (info)));
|
2011-03-24 10:55:41 +00:00
|
|
|
encoder->inited = TRUE;
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
/* Store input state */
|
|
|
|
if (encoder->input_state)
|
|
|
|
gst_video_codec_state_unref (encoder->input_state);
|
|
|
|
encoder->input_state = gst_video_codec_state_ref (state);
|
|
|
|
|
2011-03-24 12:59:35 +00:00
|
|
|
/* prepare cached image buffer setup */
|
|
|
|
image = &encoder->image;
|
2012-03-06 14:21:17 +00:00
|
|
|
memset (image, 0, sizeof (*image));
|
2011-03-24 12:59:35 +00:00
|
|
|
|
|
|
|
image->fmt = VPX_IMG_FMT_I420;
|
|
|
|
image->bps = 12;
|
|
|
|
image->x_chroma_shift = image->y_chroma_shift = 1;
|
2012-04-24 09:08:41 +00:00
|
|
|
image->w = image->d_w = GST_VIDEO_INFO_WIDTH (info);
|
|
|
|
image->h = image->d_h = GST_VIDEO_INFO_HEIGHT (info);
|
2011-03-24 12:59:35 +00:00
|
|
|
|
2011-11-03 13:01:41 +00:00
|
|
|
image->stride[VPX_PLANE_Y] = GST_VIDEO_INFO_COMP_STRIDE (info, 0);
|
|
|
|
image->stride[VPX_PLANE_U] = GST_VIDEO_INFO_COMP_STRIDE (info, 1);
|
|
|
|
image->stride[VPX_PLANE_V] = GST_VIDEO_INFO_COMP_STRIDE (info, 2);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("video/x-vp8");
|
2011-08-12 10:08:08 +00:00
|
|
|
{
|
|
|
|
GstStructure *s;
|
|
|
|
GstBuffer *stream_hdr, *vorbiscomment;
|
|
|
|
const GstTagList *iface_tags;
|
|
|
|
GValue array = { 0, };
|
|
|
|
GValue value = { 0, };
|
2012-05-28 14:05:21 +00:00
|
|
|
GstMapInfo map;
|
|
|
|
|
2011-08-12 10:08:08 +00:00
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
/* put buffers in a fixed list */
|
|
|
|
g_value_init (&array, GST_TYPE_ARRAY);
|
2010-05-19 19:34:42 +00:00
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
2011-08-12 10:08:08 +00:00
|
|
|
|
|
|
|
/* Create Ogg stream-info */
|
|
|
|
stream_hdr = gst_buffer_new_and_alloc (26);
|
2012-05-28 14:05:21 +00:00
|
|
|
gst_buffer_map (stream_hdr, &map, GST_MAP_WRITE);
|
|
|
|
data = map.data;
|
2011-08-12 10:08:08 +00:00
|
|
|
|
|
|
|
GST_WRITE_UINT8 (data, 0x4F);
|
|
|
|
GST_WRITE_UINT32_BE (data + 1, 0x56503830); /* "VP80" */
|
|
|
|
GST_WRITE_UINT8 (data + 5, 0x01); /* stream info header */
|
|
|
|
GST_WRITE_UINT8 (data + 6, 1); /* Major version 1 */
|
|
|
|
GST_WRITE_UINT8 (data + 7, 0); /* Minor version 0 */
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_WRITE_UINT16_BE (data + 8, GST_VIDEO_INFO_WIDTH (info));
|
|
|
|
GST_WRITE_UINT16_BE (data + 10, GST_VIDEO_INFO_HEIGHT (info));
|
|
|
|
GST_WRITE_UINT24_BE (data + 12, GST_VIDEO_INFO_PAR_N (info));
|
|
|
|
GST_WRITE_UINT24_BE (data + 15, GST_VIDEO_INFO_PAR_D (info));
|
|
|
|
GST_WRITE_UINT32_BE (data + 18, GST_VIDEO_INFO_FPS_N (info));
|
|
|
|
GST_WRITE_UINT32_BE (data + 22, GST_VIDEO_INFO_FPS_D (info));
|
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
gst_buffer_unmap (stream_hdr, &map);
|
|
|
|
|
|
|
|
GST_BUFFER_FLAG_SET (stream_hdr, GST_BUFFER_FLAG_HEADER);
|
2011-08-12 10:08:08 +00:00
|
|
|
gst_value_set_buffer (&value, stream_hdr);
|
2010-05-19 19:34:42 +00:00
|
|
|
gst_value_array_append_value (&array, &value);
|
|
|
|
g_value_unset (&value);
|
2011-08-12 10:08:08 +00:00
|
|
|
gst_buffer_unref (stream_hdr);
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
iface_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (video_encoder));
|
2011-08-12 10:08:08 +00:00
|
|
|
if (iface_tags) {
|
|
|
|
vorbiscomment =
|
2011-08-18 08:39:26 +00:00
|
|
|
gst_tag_list_to_vorbiscomment_buffer (iface_tags,
|
|
|
|
(const guint8 *) "OVP80\2 ", 7,
|
2011-08-12 10:08:08 +00:00
|
|
|
"Encoded with GStreamer vp8enc " PACKAGE_VERSION);
|
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
GST_BUFFER_FLAG_SET (vorbiscomment, GST_BUFFER_FLAG_HEADER);
|
2011-08-12 10:08:08 +00:00
|
|
|
|
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
|
|
|
gst_value_set_buffer (&value, vorbiscomment);
|
|
|
|
gst_value_array_append_value (&array, &value);
|
|
|
|
g_value_unset (&value);
|
|
|
|
gst_buffer_unref (vorbiscomment);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_structure_set_value (s, "streamheader", &array);
|
|
|
|
g_value_unset (&array);
|
2010-05-19 19:34:42 +00:00
|
|
|
}
|
2012-04-24 09:08:41 +00:00
|
|
|
output_state =
|
|
|
|
gst_video_encoder_set_output_state (video_encoder, caps, state);
|
|
|
|
gst_video_codec_state_unref (output_state);
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2012-07-26 17:31:14 +00:00
|
|
|
gst_video_encoder_negotiate (GST_VIDEO_ENCODER (encoder));
|
|
|
|
|
2011-08-12 10:08:08 +00:00
|
|
|
return ret;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-24 13:10:07 +00:00
|
|
|
static GstFlowReturn
|
2011-03-24 11:50:23 +00:00
|
|
|
gst_vp8_enc_process (GstVP8Enc * encoder)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
|
|
|
vpx_codec_iter_t iter = NULL;
|
2010-05-13 19:18:08 +00:00
|
|
|
const vpx_codec_cx_pkt_t *pkt;
|
2012-04-24 09:08:41 +00:00
|
|
|
GstVideoEncoder *video_encoder;
|
2012-05-16 12:04:28 +00:00
|
|
|
GstVP8EncUserData *user_data;
|
2012-04-24 09:08:41 +00:00
|
|
|
GstVideoCodecFrame *frame;
|
2011-03-24 13:10:07 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
video_encoder = GST_VIDEO_ENCODER (encoder);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-05-13 19:18:08 +00:00
|
|
|
pkt = vpx_codec_get_cx_data (&encoder->encoder, &iter);
|
|
|
|
while (pkt != NULL) {
|
2010-05-14 08:30:18 +00:00
|
|
|
GstBuffer *buffer;
|
2011-03-24 11:50:23 +00:00
|
|
|
gboolean invisible;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-06-03 09:49:40 +00:00
|
|
|
GST_DEBUG_OBJECT (encoder, "packet %u type %d", (guint) pkt->data.frame.sz,
|
2010-05-19 15:13:17 +00:00
|
|
|
pkt->kind);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-06-12 07:02:29 +00:00
|
|
|
if (pkt->kind == VPX_CODEC_STATS_PKT
|
|
|
|
&& encoder->multipass_mode == VPX_RC_FIRST_PASS) {
|
|
|
|
GST_LOG_OBJECT (encoder, "handling STATS packet");
|
|
|
|
|
|
|
|
g_byte_array_append (encoder->first_pass_cache_content,
|
|
|
|
pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
frame = gst_video_encoder_get_oldest_frame (video_encoder);
|
2010-06-12 07:02:29 +00:00
|
|
|
if (frame != NULL) {
|
|
|
|
buffer = gst_buffer_new ();
|
2012-05-28 14:05:21 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_LIVE);
|
2012-04-24 09:08:41 +00:00
|
|
|
frame->output_buffer = buffer;
|
|
|
|
gst_video_encoder_finish_frame (video_encoder, frame);
|
2010-06-12 07:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pkt = vpx_codec_get_cx_data (&encoder->encoder, &iter);
|
|
|
|
continue;
|
|
|
|
} else if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) {
|
2010-05-28 13:53:30 +00:00
|
|
|
GST_LOG_OBJECT (encoder, "non frame pkt: %d", pkt->kind);
|
2010-05-28 14:35:12 +00:00
|
|
|
pkt = vpx_codec_get_cx_data (&encoder->encoder, &iter);
|
2010-05-13 19:18:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-05-13 19:18:08 +00:00
|
|
|
invisible = (pkt->data.frame.flags & VPX_FRAME_IS_INVISIBLE) != 0;
|
2012-04-24 09:08:41 +00:00
|
|
|
frame = gst_video_encoder_get_oldest_frame (video_encoder);
|
2010-05-19 15:13:17 +00:00
|
|
|
g_assert (frame != NULL);
|
2012-04-24 09:08:41 +00:00
|
|
|
if ((pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0)
|
|
|
|
GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame);
|
|
|
|
else
|
|
|
|
GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame);
|
2012-05-16 12:04:28 +00:00
|
|
|
|
|
|
|
user_data = gst_video_codec_frame_get_user_data (frame);
|
2010-05-13 18:20:32 +00:00
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
/* FIXME : It would be nice to avoid the memory copy ... */
|
|
|
|
buffer =
|
|
|
|
gst_buffer_new_wrapped (g_memdup (pkt->data.frame.buf,
|
|
|
|
pkt->data.frame.sz), pkt->data.frame.sz);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-05-16 12:04:28 +00:00
|
|
|
if (user_data->image)
|
|
|
|
g_slice_free (vpx_image_t, user_data->image);
|
|
|
|
user_data->image = NULL;
|
2010-05-13 19:18:08 +00:00
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
if (invisible) {
|
2012-05-16 12:04:28 +00:00
|
|
|
user_data->invisible = g_list_append (user_data->invisible, buffer);
|
2010-05-14 08:30:18 +00:00
|
|
|
} else {
|
2012-04-24 09:08:41 +00:00
|
|
|
frame->output_buffer = buffer;
|
|
|
|
ret = gst_video_encoder_finish_frame (video_encoder, frame);
|
2010-05-14 08:30:18 +00:00
|
|
|
}
|
2010-05-13 19:18:08 +00:00
|
|
|
|
|
|
|
pkt = vpx_codec_get_cx_data (&encoder->encoder, &iter);
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
2011-03-24 13:10:07 +00:00
|
|
|
|
|
|
|
return ret;
|
2011-03-24 11:50:23 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 06:03:51 +00:00
|
|
|
static GstFlowReturn
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_vp8_enc_finish (GstVideoEncoder * video_encoder)
|
2011-03-24 11:50:23 +00:00
|
|
|
{
|
|
|
|
GstVP8Enc *encoder;
|
|
|
|
int flags = 0;
|
|
|
|
vpx_codec_err_t status;
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_DEBUG_OBJECT (video_encoder, "finish");
|
2011-03-24 11:50:23 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
encoder = GST_VP8_ENC (video_encoder);
|
2011-03-24 11:50:23 +00:00
|
|
|
|
|
|
|
status =
|
|
|
|
vpx_codec_encode (&encoder->encoder, NULL, encoder->n_frames, 1, flags,
|
2012-09-08 13:38:40 +00:00
|
|
|
encoder->deadline);
|
2011-03-24 11:50:23 +00:00
|
|
|
if (status != 0) {
|
|
|
|
GST_ERROR_OBJECT (encoder, "encode returned %d %s", status,
|
|
|
|
gst_vpx_error_name (status));
|
2011-07-21 06:03:51 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2011-03-24 11:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* dispatch remaining frames */
|
|
|
|
gst_vp8_enc_process (encoder);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2010-06-12 07:02:29 +00:00
|
|
|
if (encoder->multipass_mode == VPX_RC_FIRST_PASS
|
|
|
|
&& encoder->multipass_cache_file) {
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
if (!g_file_set_contents (encoder->multipass_cache_file,
|
|
|
|
(const gchar *) encoder->first_pass_cache_content->data,
|
|
|
|
encoder->first_pass_cache_content->len, &err)) {
|
|
|
|
GST_ELEMENT_ERROR (encoder, RESOURCE, WRITE, (NULL),
|
|
|
|
("Failed to write multipass cache file: %s", err->message));
|
|
|
|
g_error_free (err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-21 06:03:51 +00:00
|
|
|
return GST_FLOW_OK;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 12:46:48 +00:00
|
|
|
static vpx_image_t *
|
2012-05-28 14:05:21 +00:00
|
|
|
gst_vp8_enc_buffer_to_image (GstVP8Enc * enc, GstVideoFrame * frame)
|
2010-05-19 12:46:48 +00:00
|
|
|
{
|
2011-03-24 12:59:35 +00:00
|
|
|
vpx_image_t *image = g_slice_new (vpx_image_t);
|
2010-05-19 12:46:48 +00:00
|
|
|
|
2011-03-24 12:59:35 +00:00
|
|
|
memcpy (image, &enc->image, sizeof (*image));
|
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
image->planes[VPX_PLANE_Y] = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
|
|
|
|
image->planes[VPX_PLANE_U] = GST_VIDEO_FRAME_COMP_DATA (frame, 1);
|
|
|
|
image->planes[VPX_PLANE_V] = GST_VIDEO_FRAME_COMP_DATA (frame, 2);
|
2010-05-19 12:46:48 +00:00
|
|
|
|
2012-08-08 15:06:20 +00:00
|
|
|
image->stride[VPX_PLANE_Y] = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0);
|
|
|
|
image->stride[VPX_PLANE_U] = GST_VIDEO_FRAME_COMP_STRIDE (frame, 1);
|
|
|
|
image->stride[VPX_PLANE_V] = GST_VIDEO_FRAME_COMP_STRIDE (frame, 2);
|
|
|
|
|
2010-05-19 12:46:48 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2011-03-24 13:10:07 +00:00
|
|
|
static GstFlowReturn
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_vp8_enc_handle_frame (GstVideoEncoder * video_encoder,
|
|
|
|
GstVideoCodecFrame * frame)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
|
|
|
GstVP8Enc *encoder;
|
2010-05-19 15:13:17 +00:00
|
|
|
vpx_codec_err_t status;
|
2010-05-13 08:04:04 +00:00
|
|
|
int flags = 0;
|
|
|
|
vpx_image_t *image;
|
2012-05-16 12:04:28 +00:00
|
|
|
GstVP8EncUserData *user_data;
|
2012-05-28 14:05:21 +00:00
|
|
|
GstVideoFrame vframe;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_DEBUG_OBJECT (video_encoder, "handle_frame");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
encoder = GST_VP8_ENC (video_encoder);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
|
|
|
encoder->n_frames++;
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_DEBUG_OBJECT (video_encoder, "size %d %d",
|
|
|
|
GST_VIDEO_INFO_WIDTH (&encoder->input_state->info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&encoder->input_state->info));
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-05-28 14:05:21 +00:00
|
|
|
gst_video_frame_map (&vframe, &encoder->input_state->info,
|
|
|
|
frame->input_buffer, GST_MAP_READ);
|
|
|
|
image = gst_vp8_enc_buffer_to_image (encoder, &vframe);
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2012-05-16 12:04:28 +00:00
|
|
|
user_data = g_slice_new0 (GstVP8EncUserData);
|
|
|
|
user_data->image = image;
|
|
|
|
gst_video_codec_frame_set_user_data (frame, user_data,
|
|
|
|
(GDestroyNotify) gst_vp8_enc_user_data_free);
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame)) {
|
2010-05-13 08:04:04 +00:00
|
|
|
flags |= VPX_EFLAG_FORCE_KF;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = vpx_codec_encode (&encoder->encoder, image,
|
2012-09-08 13:38:40 +00:00
|
|
|
encoder->n_frames, 1, flags, encoder->deadline);
|
2012-05-28 14:05:21 +00:00
|
|
|
gst_video_frame_unmap (&vframe);
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
if (status != 0) {
|
2010-05-19 15:13:17 +00:00
|
|
|
GST_ELEMENT_ERROR (encoder, LIBRARY, ENCODE,
|
|
|
|
("Failed to encode frame"), ("%s", gst_vpx_error_name (status)));
|
2012-05-16 12:04:28 +00:00
|
|
|
gst_video_codec_frame_set_user_data (frame, NULL, NULL);
|
2010-05-19 15:13:17 +00:00
|
|
|
return FALSE;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
2012-07-21 17:59:21 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2011-03-24 13:10:07 +00:00
|
|
|
return gst_vp8_enc_process (encoder);
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
static guint64
|
|
|
|
_to_granulepos (guint64 frame_end_number, guint inv_count, guint keyframe_dist)
|
|
|
|
{
|
|
|
|
guint64 granulepos;
|
|
|
|
guint inv;
|
|
|
|
|
|
|
|
inv = (inv_count == 0) ? 0x3 : inv_count - 1;
|
|
|
|
|
|
|
|
granulepos = (frame_end_number << 32) | (inv << 30) | (keyframe_dist << 3);
|
|
|
|
return granulepos;
|
|
|
|
}
|
|
|
|
|
2010-05-13 08:04:04 +00:00
|
|
|
static GstFlowReturn
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_vp8_enc_pre_push (GstVideoEncoder * video_encoder,
|
|
|
|
GstVideoCodecFrame * frame)
|
2010-05-13 08:04:04 +00:00
|
|
|
{
|
2010-05-14 08:30:18 +00:00
|
|
|
GstVP8Enc *encoder;
|
|
|
|
GstBuffer *buf;
|
2012-04-24 09:08:41 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2012-05-16 12:04:28 +00:00
|
|
|
GstVP8EncUserData *user_data = gst_video_codec_frame_get_user_data (frame);
|
2010-05-14 08:30:18 +00:00
|
|
|
GList *l;
|
|
|
|
gint inv_count;
|
2012-04-24 09:08:41 +00:00
|
|
|
GstVideoInfo *info;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_DEBUG_OBJECT (video_encoder, "pre_push");
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
encoder = GST_VP8_ENC (video_encoder);
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
info = &encoder->input_state->info;
|
2010-05-13 08:04:04 +00:00
|
|
|
|
2012-05-16 12:04:28 +00:00
|
|
|
g_assert (user_data != NULL);
|
2010-06-12 07:02:29 +00:00
|
|
|
|
2012-05-16 12:04:28 +00:00
|
|
|
for (inv_count = 0, l = user_data->invisible; l; inv_count++, l = l->next) {
|
2010-07-10 14:51:53 +00:00
|
|
|
buf = l->data;
|
|
|
|
l->data = NULL;
|
2010-05-14 08:30:18 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
/* FIXME : All of this should have already been handled by base classes, no ? */
|
2012-05-16 12:04:28 +00:00
|
|
|
if (l == user_data->invisible
|
|
|
|
&& GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) {
|
2010-05-14 08:30:18 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
encoder->keyframe_distance = 0;
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
encoder->keyframe_distance++;
|
|
|
|
}
|
2010-07-10 14:51:53 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buf) = GST_BUFFER_TIMESTAMP (frame->output_buffer);
|
2011-06-26 13:15:54 +00:00
|
|
|
GST_BUFFER_DURATION (buf) = 0;
|
2010-07-10 14:51:53 +00:00
|
|
|
GST_BUFFER_OFFSET_END (buf) =
|
|
|
|
_to_granulepos (frame->presentation_frame_number + 1,
|
|
|
|
inv_count, encoder->keyframe_distance);
|
|
|
|
GST_BUFFER_OFFSET (buf) =
|
|
|
|
gst_util_uint64_scale (frame->presentation_frame_number + 1,
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_SECOND * GST_VIDEO_INFO_FPS_D (info), GST_VIDEO_INFO_FPS_N (info));
|
2010-07-10 14:51:53 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
ret = gst_pad_push (GST_VIDEO_ENCODER_SRC_PAD (video_encoder), buf);
|
2010-07-10 14:51:53 +00:00
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
GST_WARNING_OBJECT (encoder, "flow error %d", ret);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
buf = frame->output_buffer;
|
2010-07-10 14:51:53 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
/* FIXME : All of this should have already been handled by base classes, no ? */
|
2012-05-16 12:04:28 +00:00
|
|
|
if (!user_data->invisible && GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) {
|
2010-07-10 14:51:53 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
encoder->keyframe_distance = 0;
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
encoder->keyframe_distance++;
|
2010-05-13 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 02:43:24 +00:00
|
|
|
GST_BUFFER_OFFSET_END (buf) =
|
|
|
|
_to_granulepos (frame->presentation_frame_number + 1, 0,
|
|
|
|
encoder->keyframe_distance);
|
|
|
|
GST_BUFFER_OFFSET (buf) =
|
|
|
|
gst_util_uint64_scale (frame->presentation_frame_number + 1,
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_SECOND * GST_VIDEO_INFO_FPS_D (info), GST_VIDEO_INFO_FPS_N (info));
|
2010-12-01 02:43:24 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
GST_LOG_OBJECT (video_encoder, "src ts: %" GST_TIME_FORMAT,
|
2012-01-24 10:22:46 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
|
|
|
|
|
2010-05-14 08:30:18 +00:00
|
|
|
done:
|
2010-05-13 08:04:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2010-05-18 12:47:54 +00:00
|
|
|
|
|
|
|
static gboolean
|
2012-04-24 09:08:41 +00:00
|
|
|
gst_vp8_enc_sink_event (GstVideoEncoder * benc, GstEvent * event)
|
2010-05-18 12:47:54 +00:00
|
|
|
{
|
2011-03-23 07:50:31 +00:00
|
|
|
GstVP8Enc *enc = GST_VP8_ENC (benc);
|
2010-05-18 12:47:54 +00:00
|
|
|
|
2012-04-24 09:08:41 +00:00
|
|
|
/* FIXME : Move this to base encoder class */
|
|
|
|
|
2010-05-18 12:47:54 +00:00
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_TAG) {
|
|
|
|
GstTagList *list;
|
|
|
|
GstTagSetter *setter = GST_TAG_SETTER (enc);
|
|
|
|
const GstTagMergeMode mode = gst_tag_setter_get_tag_merge_mode (setter);
|
|
|
|
|
|
|
|
gst_event_parse_tag (event, &list);
|
|
|
|
gst_tag_setter_merge_tags (setter, list, mode);
|
|
|
|
}
|
|
|
|
|
2011-03-23 07:50:31 +00:00
|
|
|
/* just peeked, baseclass handles the rest */
|
2012-05-28 14:05:21 +00:00
|
|
|
return GST_VIDEO_ENCODER_CLASS (parent_class)->sink_event (benc, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vp8_enc_propose_allocation (GstVideoEncoder * encoder, GstQuery * query)
|
|
|
|
{
|
2012-07-06 09:50:53 +00:00
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
2012-05-28 14:05:21 +00:00
|
|
|
|
|
|
|
return GST_VIDEO_ENCODER_CLASS (parent_class)->propose_allocation (encoder,
|
|
|
|
query);
|
2010-05-18 12:47:54 +00:00
|
|
|
}
|
2010-05-20 08:19:54 +00:00
|
|
|
|
2010-05-20 14:49:03 +00:00
|
|
|
#endif /* HAVE_VP8_ENCODER */
|