#define DEFAULT_BITRATE 64
#define DEFAULT_FRAMESIZE 256
+#define DEFAULT_CBR TRUE
+#define DEFAULT_COMPLEXITY 9
+#define DEFAULT_MAX_BITRATE 64
enum
{
PROP_0,
PROP_BITRATE,
- PROP_FRAMESIZE
+ PROP_FRAMESIZE,
+ PROP_CBR,
+ PROP_COMPLEXITY,
+ PROP_MAX_BITRATE
};
static void gst_celt_enc_finalize (GObject * object);
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BITRATE,
g_param_spec_int ("bitrate", "Encoding Bit-rate",
- "Specify an encoding bit-rate (in Kbps). (0 = automatic)",
+ "Specify an encoding bit-rate (in Kbps).",
10, 320, DEFAULT_BITRATE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_FRAMESIZE,
g_param_spec_int ("framesize", "Frame Size",
"The number of samples per frame", 64, 512, DEFAULT_FRAMESIZE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_CBR,
+ g_param_spec_boolean ("cbr", "Constant bit rate",
+ "Constant bit rate", DEFAULT_CBR,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_COMPLEXITY,
+ g_param_spec_int ("complexity", "Complexity",
+ "Complexity", 0, 10, DEFAULT_COMPLEXITY,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_BITRATE,
+ g_param_spec_int ("max-bitrate", "Maximum Encoding Bit-rate",
+ "Specify a maximum encoding bit rate (in Kbps) for variable bit rate encoding.",
+ 10, 320, DEFAULT_MAX_BITRATE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_celt_enc_finalize);
enc->bitrate = DEFAULT_BITRATE;
enc->frame_size = DEFAULT_FRAMESIZE;
+ enc->cbr = DEFAULT_CBR;
+ enc->complexity = DEFAULT_COMPLEXITY;
+ enc->max_bitrate = DEFAULT_MAX_BITRATE;
enc->setup = FALSE;
enc->header_sent = FALSE;
gst_celt_enc_setup (GstCeltEnc * enc)
{
gint error = CELT_OK;
- gint bytes_per_packet;
enc->setup = FALSE;
celt_mode_info (enc->mode, CELT_GET_FRAME_SIZE, &enc->frame_size);
- bytes_per_packet =
- (enc->bitrate * 1000 * enc->frame_size / enc->rate + 4) / 8;
-
celt_header_init (&enc->header, enc->mode);
enc->header.nb_channels = enc->channels;
if (!enc->state)
goto encoder_creation_failed;
+ if (!enc->cbr) {
+ GST_ERROR ("setting vbr");
+ celt_encoder_ctl (enc->state, CELT_SET_VBR_RATE (enc->bitrate), 0);
+ }
+ celt_encoder_ctl (enc->state, CELT_SET_COMPLEXITY (enc->complexity), 0);
+
GST_LOG_OBJECT (enc, "we have frame size %d", enc->frame_size);
enc->setup = TRUE;
GstFlowReturn ret = GST_FLOW_OK;
gint frame_size = enc->frame_size;
gint bytes = frame_size * 2 * enc->channels;
- gint bytes_per_packet =
- (enc->bitrate * 1000 * enc->frame_size / enc->rate + 4) / 8;
+ gint bytes_per_packet;
+
+ if (enc->cbr) {
+ bytes_per_packet =
+ (enc->bitrate * 1000 * enc->frame_size / enc->rate + 4) / 8;
+ } else {
+ bytes_per_packet =
+ (enc->max_bitrate * 1000 * enc->frame_size / enc->rate + 4) / 8;
+ }
if (flush && gst_adapter_available (enc->adapter) % bytes != 0) {
guint diff = gst_adapter_available (enc->adapter) % bytes;
case PROP_FRAMESIZE:
g_value_set_int (value, enc->frame_size);
break;
+ case PROP_CBR:
+ g_value_set_boolean (value, enc->cbr);
+ break;
+ case PROP_COMPLEXITY:
+ g_value_set_int (value, enc->complexity);
+ break;
+ case PROP_MAX_BITRATE:
+ g_value_set_int (value, enc->max_bitrate);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_FRAMESIZE:
enc->frame_size = g_value_get_int (value);
break;
+ case PROP_CBR:
+ enc->cbr = g_value_get_boolean (value);
+ break;
+ case PROP_COMPLEXITY:
+ enc->complexity = g_value_get_int (value);
+ break;
+ case PROP_MAX_BITRATE:
+ enc->max_bitrate = g_value_get_int (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;