?? gstsbcenc.c
字號:
/* * * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2004-2008 Marcel Holtmann <marcel@holtmann.org> * * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <string.h>#include "gstsbcenc.h"#include "gstsbcutil.h"#define SBC_ENC_DEFAULT_MODE SBC_MODE_AUTO#define SBC_ENC_DEFAULT_BLOCKS 0#define SBC_ENC_DEFAULT_SUB_BANDS 0#define SBC_ENC_DEFAULT_ALLOCATION SBC_AM_AUTO#define SBC_ENC_DEFAULT_RATE 0#define SBC_ENC_DEFAULT_CHANNELS 0#define SBC_ENC_BITPOOL_AUTO 1#define SBC_ENC_BITPOOL_MIN 2#define SBC_ENC_BITPOOL_MIN_STR "2"#define SBC_ENC_BITPOOL_MAX 64#define SBC_ENC_BITPOOL_MAX_STR "64"GST_DEBUG_CATEGORY_STATIC(sbc_enc_debug);#define GST_CAT_DEFAULT sbc_enc_debug#define GST_TYPE_SBC_MODE (gst_sbc_mode_get_type())static GType gst_sbc_mode_get_type(void){ static GType sbc_mode_type = 0; static GEnumValue sbc_modes[] = { { SBC_MODE_MONO, "Mono", "mono" }, { SBC_MODE_DUAL_CHANNEL, "Dual Channel", "dual" }, { SBC_MODE_STEREO, "Stereo", "stereo"}, { SBC_MODE_JOINT_STEREO, "Joint Stereo", "joint" }, { SBC_MODE_AUTO, "Auto", "auto" }, { -1, NULL, NULL} }; if (!sbc_mode_type) sbc_mode_type = g_enum_register_static("GstSbcMode", sbc_modes); return sbc_mode_type;}#define GST_TYPE_SBC_ALLOCATION (gst_sbc_allocation_get_type())static GType gst_sbc_allocation_get_type(void){ static GType sbc_allocation_type = 0; static GEnumValue sbc_allocations[] = { { SBC_AM_LOUDNESS, "Loudness", "loudness" }, { SBC_AM_SNR, "SNR", "snr" }, { SBC_AM_AUTO, "Auto", "auto" }, { -1, NULL, NULL} }; if (!sbc_allocation_type) sbc_allocation_type = g_enum_register_static( "GstSbcAllocation", sbc_allocations); return sbc_allocation_type;}#define GST_TYPE_SBC_BLOCKS (gst_sbc_blocks_get_type())static GType gst_sbc_blocks_get_type(void){ static GType sbc_blocks_type = 0; static GEnumValue sbc_blocks[] = { { 0, "Auto", "auto" }, { 4, "4", "4" }, { 8, "8", "8" }, { 12, "12", "12" }, { 16, "16", "16" }, { -1, NULL, NULL} }; if (!sbc_blocks_type) sbc_blocks_type = g_enum_register_static( "GstSbcBlocks", sbc_blocks); return sbc_blocks_type;}#define GST_TYPE_SBC_SUBBANDS (gst_sbc_subbands_get_type())static GType gst_sbc_subbands_get_type(void){ static GType sbc_subbands_type = 0; static GEnumValue sbc_subbands[] = { { 0, "Auto", "auto" }, { 4, "4 subbands", "4" }, { 8, "8 subbands", "8" }, { -1, NULL, NULL} }; if (!sbc_subbands_type) sbc_subbands_type = g_enum_register_static( "GstSbcSubbands", sbc_subbands); return sbc_subbands_type;}enum { PROP_0, PROP_MODE, PROP_ALLOCATION, PROP_BLOCKS, PROP_SUBBANDS, PROP_BITPOOL};GST_BOILERPLATE(GstSbcEnc, gst_sbc_enc, GstElement, GST_TYPE_ELEMENT);static const GstElementDetails sbc_enc_details = GST_ELEMENT_DETAILS("Bluetooth SBC encoder", "Codec/Encoder/Audio", "Encode a SBC audio stream", "Marcel Holtmann <marcel@holtmann.org>");static GstStaticPadTemplate sbc_enc_sink_factory = GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS("audio/x-raw-int, " "rate = (int) { 16000, 32000, 44100, 48000 }, " "channels = (int) [ 1, 2 ], " "endianness = (int) LITTLE_ENDIAN, " "signed = (boolean) true, " "width = (int) 16, " "depth = (int) 16"));static GstStaticPadTemplate sbc_enc_src_factory = GST_STATIC_PAD_TEMPLATE("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS("audio/x-sbc, " "rate = (int) { 16000, 32000, 44100, 48000 }, " "channels = (int) [ 1, 2 ], " "mode = (string) { \"mono\", \"dual\", \"stereo\", \"joint\" }, " "blocks = (int) { 4, 8, 12, 16 }, " "subbands = (int) { 4, 8 }, " "allocation = (string) { \"snr\", \"loudness\" }, " "bitpool = (int) [ " SBC_ENC_BITPOOL_MIN_STR ", " SBC_ENC_BITPOOL_MAX_STR " ]"));gboolean gst_sbc_enc_fill_sbc_params(GstSbcEnc *enc, GstCaps *caps);static GstCaps* sbc_enc_generate_srcpad_caps(GstSbcEnc *enc){ GstCaps* src_caps; GstStructure *structure; GEnumValue *enum_value; GEnumClass *enum_class; GValue *value; src_caps = gst_caps_copy(gst_pad_get_pad_template_caps(enc->srcpad)); structure = gst_caps_get_structure(src_caps, 0); value = g_new0(GValue, 1); if (enc->rate != 0) gst_sbc_util_set_structure_int_param(structure, "rate", enc->rate, value); if (enc->channels != 0) gst_sbc_util_set_structure_int_param(structure, "channels", enc->channels, value); if (enc->subbands != 0) gst_sbc_util_set_structure_int_param(structure, "subbands", enc->subbands, value); if (enc->blocks != 0) gst_sbc_util_set_structure_int_param(structure, "blocks", enc->blocks, value); if (enc->bitpool != SBC_ENC_BITPOOL_AUTO) gst_sbc_util_set_structure_int_param(structure, "bitpool", enc->bitpool, value); if (enc->mode != SBC_ENC_DEFAULT_MODE) { enum_class = g_type_class_ref(GST_TYPE_SBC_MODE); enum_value = g_enum_get_value(enum_class, enc->mode); gst_sbc_util_set_structure_string_param(structure, "mode", enum_value->value_nick, value); g_type_class_unref(enum_class); } if (enc->allocation != SBC_AM_AUTO) { enum_class = g_type_class_ref(GST_TYPE_SBC_ALLOCATION); enum_value = g_enum_get_value(enum_class, enc->allocation); gst_sbc_util_set_structure_string_param(structure, "allocation", enum_value->value_nick, value); g_type_class_unref(enum_class); } g_free(value); return src_caps;}static GstCaps* sbc_enc_src_getcaps (GstPad * pad){ GstSbcEnc *enc; enc = GST_SBC_ENC(GST_PAD_PARENT(pad)); return sbc_enc_generate_srcpad_caps(enc);}static gboolean sbc_enc_src_setcaps (GstPad *pad, GstCaps *caps){ GstSbcEnc *enc = GST_SBC_ENC(GST_PAD_PARENT(pad)); GST_LOG_OBJECT(enc, "setting srcpad caps"); return gst_sbc_enc_fill_sbc_params(enc, caps);}static GstCaps* sbc_enc_src_caps_fixate(GstSbcEnc *enc, GstCaps *caps){ gchar *error_message = NULL; GstCaps* result; result = gst_sbc_util_caps_fixate(caps, &error_message); if (!result) { GST_WARNING_OBJECT (enc, "Invalid input caps caused parsing " "error: %s", error_message); g_free(error_message); return NULL; } return result;}static GstCaps* sbc_enc_get_fixed_srcpad_caps(GstSbcEnc *enc){ GstCaps *caps; gboolean res = TRUE; GstCaps *result_caps = NULL; caps = gst_pad_get_allowed_caps(enc->srcpad); if (caps == NULL) caps = sbc_enc_src_getcaps(enc->srcpad); if (caps == GST_CAPS_NONE || gst_caps_is_empty(caps)) { res = FALSE; goto done; } result_caps = sbc_enc_src_caps_fixate(enc, caps);done: gst_caps_unref(caps); if (!res) return NULL; return result_caps;}static gboolean sbc_enc_sink_setcaps (GstPad * pad, GstCaps * caps){ GstSbcEnc *enc; GstStructure *structure; GstCaps *src_caps; gint rate, channels; gboolean res; enc = GST_SBC_ENC(GST_PAD_PARENT (pad)); structure = gst_caps_get_structure(caps, 0); if (!gst_structure_get_int(structure, "rate", &rate)) return FALSE; if (!gst_structure_get_int(structure, "channels", &channels)) return FALSE; enc->rate = rate; enc->channels = channels;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -