[Asterisk-code-review] codec opus: Fix warning when Opus negotiated but codec opus ... (asterisk[master])
Richard Mudgett
asteriskteam at digium.com
Tue Nov 15 16:34:11 CST 2016
Richard Mudgett has uploaded a new change for review. ( https://gerrit.asterisk.org/4456 )
Change subject: codec_opus: Fix warning when Opus negotiated but codec_opus not loaded.
......................................................................
codec_opus: Fix warning when Opus negotiated but codec_opus not loaded.
When Opus is negotiated but not loaded, the log is spammed with messages
because the system does not know how to calculate the number of samples in
a frame.
* Copy the number of samples in a frame calculation code from codec_opus
to allow passthrough to not spam the log with messages when the codec is
not installed.
ASTERISK-26605 #close
Change-Id: Icf2273692f040dc2c45b01e72a790d11092f9e0f
---
M main/codec_builtin.c
1 file changed, 75 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/56/4456/1
diff --git a/main/codec_builtin.c b/main/codec_builtin.c
index cc4edd2..92fb962 100644
--- a/main/codec_builtin.c
+++ b/main/codec_builtin.c
@@ -729,6 +729,80 @@
.get_length = g719_length,
};
+/* Code lifted from opus library with formatting and name changes. */
+static int opus_get_nb_frames(const unsigned char packet[], int len)
+{
+ int count;
+
+ if (len < 1) {
+ return -1;
+ }
+ count = packet[0] & 0x3;
+ if (count == 0) {
+ return 1;
+ } else if (count != 3) {
+ return 2;
+ } else if (len < 2) {
+ return -1;
+ } else {
+ return packet[1] & 0x3F;
+ }
+}
+
+/* Code lifted from opus library with formatting and name changes. */
+static int opus_get_samples_per_frame(const unsigned char *data, int Fs)
+{
+ int audiosize;
+
+ if (data[0] & 0x80) {
+ audiosize = ((data[0] >> 3) & 0x3);
+ audiosize = (Fs << audiosize) / 400;
+ } else if ((data[0] & 0x60) == 0x60) {
+ audiosize = (data[0] & 0x08) ? Fs / 50 : Fs / 100;
+ } else {
+ audiosize = ((data[0] >> 3) & 0x3);
+ if (audiosize == 3) {
+ audiosize = Fs * 60 / 1000;
+ } else {
+ audiosize = (Fs << audiosize) / 100;
+ }
+ }
+ return audiosize;
+}
+
+/* Code lifted from opus library with formatting and name changes. */
+static int opus_get_nb_samples(const unsigned char packet[], int len, int Fs)
+{
+ int samples;
+ int count;
+
+ count = opus_get_nb_frames(packet, len);
+ if (count < 0) {
+ return count;
+ }
+
+ samples = count * opus_get_samples_per_frame(packet, Fs);
+ /* Can't have more than 120 ms */
+ if (samples * 25 > Fs * 3) {
+ return -1;
+ } else {
+ return samples;
+ }
+}
+
+static int opus_samples(struct ast_frame *frame)
+{
+ int samples;
+
+ samples = opus_get_nb_samples(frame->data.ptr, frame->datalen,
+ ast_format_get_sample_rate(frame->subclass.format));
+ if (samples < 0) {
+ ast_log(LOG_WARNING, "Invalid Opus packet\n");
+ samples = 0;
+ }
+ return samples;
+}
+
static struct ast_codec opus = {
.name = "opus",
.description = "Opus Codec",
@@ -737,6 +811,7 @@
.minimum_ms = 20,
.maximum_ms = 60,
.default_ms = 20,
+ .samples_count = opus_samples,
.minimum_bytes = 10,
};
--
To view, visit https://gerrit.asterisk.org/4456
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf2273692f040dc2c45b01e72a790d11092f9e0f
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
More information about the asterisk-code-review
mailing list