⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gstsbcenc.c

📁 Linux的蓝牙操作工具。配合bluez-lib使用
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * *  BlueZ - Bluetooth protocol stack for Linux * *  Copyright (C) 2004-2007  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 "ipc.h"#include "gstsbcenc.h"#include "gstsbcutil.h"#define SBC_ENC_DEFAULT_MODE BT_A2DP_CHANNEL_MODE_AUTO#define SBC_ENC_DEFAULT_BLOCKS 0#define SBC_ENC_DEFAULT_SUB_BANDS 0#define SBC_ENC_DEFAULT_BITPOOL 0#define SBC_ENC_DEFAULT_ALLOCATION BT_A2DP_ALLOCATION_AUTO#define SBC_ENC_DEFAULT_RATE 0#define SBC_ENC_DEFAULT_CHANNELS 0GST_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[] = {		{  0, "Auto",		"auto"		},		{  1, "Mono",		"mono"		},		{  2, "Dual Channel",	"dual"		},		{  3, "Stereo",		"stereo"	},		{  4, "Joint Stereo",	"joint"		},		{ -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[] = {		{ BT_A2DP_ALLOCATION_AUTO,	"Auto",		"auto" },		{ BT_A2DP_ALLOCATION_LOUDNESS,	"Loudness",	"loudness" },		{ BT_A2DP_ALLOCATION_SNR,	"SNR",		"snr" },		{ -1, NULL, NULL}	};	if (!sbc_allocation_type)		sbc_allocation_type = g_enum_register_static(				"GstSbcAllocation", sbc_allocations);	return sbc_allocation_type;}enum {	PROP_0,	PROP_MODE,	PROP_ALLOCATION,	PROP_BLOCKS,	PROP_SUBBANDS};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) [ 2, 64 ]"));gboolean gst_sbc_enc_fill_sbc_params(GstSbcEnc *enc, GstCaps *caps);static void sbc_enc_set_structure_int_param(GstSbcEnc *enc,			GstStructure *structure, const gchar* field,			gint field_value){	GValue *value;	value = g_new0(GValue,1);	value = g_value_init(value, G_TYPE_INT);	g_value_set_int(value, field_value);	gst_structure_set_value(structure, field, value);	g_free(value);}static void sbc_enc_set_structure_string_param(GstSbcEnc *enc,			GstStructure *structure, const gchar* field,			const gchar* field_value){	GValue *value;	value = g_new0(GValue,1);	value = g_value_init(value, G_TYPE_STRING);	g_value_set_string(value, field_value);	gst_structure_set_value(structure, field, value);	g_free(value);}static GstCaps* sbc_enc_generate_srcpad_caps(GstSbcEnc *enc){	GstCaps* src_caps;	GstStructure *structure;	GEnumValue *enum_value;	GEnumClass *enum_class;	gchar* temp;	src_caps = gst_caps_copy(gst_pad_get_pad_template_caps(enc->srcpad));	structure = gst_caps_get_structure(src_caps, 0);	if (enc->rate != 0)		sbc_enc_set_structure_int_param(enc, structure, "rate",			enc->rate);	if (enc->channels != 0)		sbc_enc_set_structure_int_param(enc, structure, "channels",			enc->channels);	if (enc->subbands != 0)		sbc_enc_set_structure_int_param(enc, structure, "subbands",			enc->subbands);	if (enc->blocks != 0)		sbc_enc_set_structure_int_param(enc, structure, "blocks",			enc->blocks);	if (enc->mode != BT_A2DP_CHANNEL_MODE_AUTO) {		enum_class = g_type_class_ref(GST_TYPE_SBC_MODE);		enum_value = g_enum_get_value(enum_class, enc->mode);		sbc_enc_set_structure_string_param(enc, structure, "mode",			enum_value->value_nick);		g_type_class_unref(enum_class);	}	if (enc->allocation != BT_A2DP_ALLOCATION_AUTO) {		enum_class = g_type_class_ref(GST_TYPE_SBC_ALLOCATION);		enum_value = g_enum_get_value(enum_class, enc->allocation);		sbc_enc_set_structure_string_param(enc, structure, "allocation",			enum_value->value_nick);		g_type_class_unref(enum_class);	}	temp = gst_caps_to_string(src_caps);	GST_DEBUG_OBJECT(enc, "Srcpad caps: %s", temp);	g_free(temp);	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){	GstCaps* srcpad_caps;	GstCaps* temp_caps;	gboolean res = TRUE;	GstSbcEnc *enc = GST_SBC_ENC(GST_PAD_PARENT(pad));	GST_LOG_OBJECT(enc, "setting srcpad caps");	srcpad_caps = sbc_enc_generate_srcpad_caps(enc);	temp_caps = gst_caps_intersect(srcpad_caps, caps);	if (temp_caps == GST_CAPS_NONE)		res = FALSE;	gst_caps_unref(temp_caps);	gst_caps_unref(srcpad_caps);	g_return_val_if_fail(res, FALSE);	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_ERROR_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 *peer_caps;	GstCaps *src_caps;	GstCaps *caps;	gboolean res = TRUE;	GstCaps *result_caps = NULL;	peer_caps = gst_pad_peer_get_caps(enc->srcpad);	if (!peer_caps)		return NULL;	src_caps = sbc_enc_generate_srcpad_caps(enc);	caps = gst_caps_intersect(src_caps, peer_caps);	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(src_caps);	gst_caps_unref(peer_caps);	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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -