mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
bluez5: add additional aac encoder options, and implement optional vbr
This commit is contained in:
parent
bd7dba617f
commit
54e06d9df0
2 changed files with 53 additions and 0 deletions
|
|
@ -38,6 +38,10 @@
|
||||||
#define DEFAULT_AAC_BITRATE 320000
|
#define DEFAULT_AAC_BITRATE 320000
|
||||||
#define MIN_AAC_BITRATE 64000
|
#define MIN_AAC_BITRATE 64000
|
||||||
|
|
||||||
|
struct props {
|
||||||
|
int bitratemode;
|
||||||
|
};
|
||||||
|
|
||||||
struct impl {
|
struct impl {
|
||||||
HANDLE_AACENCODER aacenc;
|
HANDLE_AACENCODER aacenc;
|
||||||
|
|
||||||
|
|
@ -233,12 +237,34 @@ static int codec_enum_config(const struct a2dp_codec *codec,
|
||||||
return *param == NULL ? -EIO : 1;
|
return *param == NULL ? -EIO : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *codec_init_props(const struct a2dp_codec *codec, const struct spa_dict *settings)
|
||||||
|
{
|
||||||
|
struct props *p = calloc(1, sizeof(struct props));
|
||||||
|
const char *str;
|
||||||
|
|
||||||
|
if (p == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (settings == NULL || (str = spa_dict_lookup(settings, "bluez5.a2dp.aac.bitratemode")) == NULL)
|
||||||
|
str = "0";
|
||||||
|
|
||||||
|
p->bitratemode = SPA_CLAMP(atoi(str), 0, 5);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void codec_clear_props(void *props)
|
||||||
|
{
|
||||||
|
free(props);
|
||||||
|
}
|
||||||
|
|
||||||
static void *codec_init(const struct a2dp_codec *codec, uint32_t flags,
|
static void *codec_init(const struct a2dp_codec *codec, uint32_t flags,
|
||||||
void *config, size_t config_len, const struct spa_audio_info *info,
|
void *config, size_t config_len, const struct spa_audio_info *info,
|
||||||
void *props, size_t mtu)
|
void *props, size_t mtu)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
a2dp_aac_t *conf = config;
|
a2dp_aac_t *conf = config;
|
||||||
|
struct props *p = props;
|
||||||
|
UINT bitratemode;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
this = calloc(1, sizeof(struct impl));
|
this = calloc(1, sizeof(struct impl));
|
||||||
|
|
@ -258,6 +284,8 @@ static void *codec_init(const struct a2dp_codec *codec, uint32_t flags,
|
||||||
}
|
}
|
||||||
this->samplesize = 2;
|
this->samplesize = 2;
|
||||||
|
|
||||||
|
bitratemode = p ? p->bitratemode : 0;
|
||||||
|
|
||||||
res = aacEncOpen(&this->aacenc, 0, this->channels);
|
res = aacEncOpen(&this->aacenc, 0, this->channels);
|
||||||
if (res != AACENC_OK)
|
if (res != AACENC_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -279,6 +307,21 @@ static void *codec_init(const struct a2dp_codec *codec, uint32_t flags,
|
||||||
if (res != AACENC_OK)
|
if (res != AACENC_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (conf->vbr) {
|
||||||
|
res = aacEncoder_SetParam(this->aacenc, AACENC_BITRATEMODE,
|
||||||
|
bitratemode);
|
||||||
|
if (res != AACENC_OK)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = aacEncoder_SetParam(this->aacenc, AACENC_AUDIOMUXVER, 2);
|
||||||
|
if (res != AACENC_OK)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
res = aacEncoder_SetParam(this->aacenc, AACENC_SIGNALING_MODE, 1);
|
||||||
|
if (res != AACENC_OK)
|
||||||
|
goto error;
|
||||||
|
|
||||||
// Fragmentation is not implemented yet,
|
// Fragmentation is not implemented yet,
|
||||||
// so make sure every encoded AAC frame fits in (mtu - header)
|
// so make sure every encoded AAC frame fits in (mtu - header)
|
||||||
this->max_bitrate = ((this->mtu - sizeof(struct rtp_header)) * 8 * this->rate) / 1024;
|
this->max_bitrate = ((this->mtu - sizeof(struct rtp_header)) * 8 * this->rate) / 1024;
|
||||||
|
|
@ -297,6 +340,10 @@ static void *codec_init(const struct a2dp_codec *codec, uint32_t flags,
|
||||||
if (res != AACENC_OK)
|
if (res != AACENC_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
res = aacEncoder_SetParam(this->aacenc, AACENC_HEADER_PERIOD, 1);
|
||||||
|
if (res != AACENC_OK)
|
||||||
|
goto error;
|
||||||
|
|
||||||
res = aacEncoder_SetParam(this->aacenc, AACENC_AFTERBURNER, 1);
|
res = aacEncoder_SetParam(this->aacenc, AACENC_AFTERBURNER, 1);
|
||||||
if (res != AACENC_OK)
|
if (res != AACENC_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -446,6 +493,8 @@ const struct a2dp_codec a2dp_codec_aac = {
|
||||||
.fill_caps = codec_fill_caps,
|
.fill_caps = codec_fill_caps,
|
||||||
.select_config = codec_select_config,
|
.select_config = codec_select_config,
|
||||||
.enum_config = codec_enum_config,
|
.enum_config = codec_enum_config,
|
||||||
|
.init_props = codec_init_props,
|
||||||
|
.clear_props = codec_clear_props,
|
||||||
.init = codec_init,
|
.init = codec_init,
|
||||||
.deinit = codec_deinit,
|
.deinit = codec_deinit,
|
||||||
.get_block_size = codec_get_block_size,
|
.get_block_size = codec_get_block_size,
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,10 @@ rules = [
|
||||||
# sq (Standard Quality, 660/606kbps)
|
# sq (Standard Quality, 660/606kbps)
|
||||||
# mq (Mobile use Quality, 330/303kbps)
|
# mq (Mobile use Quality, 330/303kbps)
|
||||||
#bluez5.a2dp.ldac.quality = auto
|
#bluez5.a2dp.ldac.quality = auto
|
||||||
|
|
||||||
|
# AAC variable bitrate mode
|
||||||
|
# Available values: 0 (cbr, default), 1-5 (quality level)
|
||||||
|
#bluez5.a2dp.aac.bitratemode = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue