retitle 786972 asterisk: please apply unofficial Opus transcoding patch
thanks
Quoting Jonas Smedegaard (2015-05-27 15:13:50)
> Quoting Tzafrir Cohen (2015-05-27 13:13:05)
>> On Wed, May 27, 2015 at 12:06:13PM +0200, Jonas Smedegaard wrote:
>>> Recent Asterisk supports the Opus audio codec, either as only
>>> identifier when negotiating a pass-through connection,
>>
>> Right,
>>
>>> or decoding/encoding when mixing audio.
>>
>> Are you sure?
>
> No I am guessing, based on a) my undertanding that pass-through codec
> negotiation reequire no library linking, and b) noticing that autoconf
> checks not just library existence but for opus_encoder_create
> function.
...and I guessed wrong: Simply adding build-dependency makes autotools
detect it but isn't really used for anything, apparently.
A patch exist to implement Opus transcoding support. That patch is not
adopted upstream due to fear of patent trolls.
Please apply it for Debian redistribution, where we evidently do not
have same concerns¹ (we distribute Opus encoders already).
Patch attached. Patch also attached from same source (but can be
applied independently) for read/write support for vp8 codec.
- Jonas
¹ Please do *not* publicly discuss Debian position regarding patents -
if needed then ask lea...@debian.org or bring it up somewhere else more
private.
--
* Jonas Smedegaard - idealist & Internet-arkitekt
* Tlf.: +45 40843136 Website: http://dr.jones.dk/
[x] quote me freely [ ] ask before reusing [ ] keep private
Description: Add Opus codec module supporting transcoding
Origin: https://github.com/seanbright/asterisk-opus
Author: Lorenzo Miniero
Forwarded: yes
Bug-Debian: http://bugs.debian.org/786972
Last-Update: 2015-10-12
--- a/main/Makefile
+++ b/main/Makefile
@@ -40,6 +40,7 @@
AST_LIBS+=$(URIPARSER_LIB)
AST_LIBS+=$(UUID_LIB)
AST_LIBS+=$(CRYPT_LIB)
+AST_LIBS+=$(OPUS_LIB)
ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc kfreebsd-gnu),)
ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
@@ -159,6 +160,7 @@
bucket.o: _ASTCFLAGS+=$(URIPARSER_INCLUDE)
crypt.o: _ASTCFLAGS+=$(CRYPT_INCLUDE)
uuid.o: _ASTCFLAGS+=$(UUID_INCLUDE)
+codec_builtin.o: _ASTCFLAGS+=$(OPUS_INCLUDE)
ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
http.o: _ASTCFLAGS+=$(GMIME_INCLUDE)
--- a/main/codec_builtin.c
+++ b/main/codec_builtin.c
@@ -38,6 +38,8 @@
#include "asterisk/format_cache.h"
#include "asterisk/frame.h"
+#include
+
enum frame_type {
TYPE_HIGH, /* 0x0 */
TYPE_LOW, /* 0x1 */
@@ -698,6 +700,11 @@
.get_length = g719_length,
};
+static int opus_samples(struct ast_frame *frame)
+{
+ return opus_packet_get_nb_samples(frame->data.ptr, frame->datalen, 48000);
+}
+
static struct ast_codec opus = {
.name = "opus",
.description = "Opus Codec",
@@ -707,6 +714,7 @@
.maximum_ms = 60,
.default_ms = 20,
.minimum_bytes = 10,
+ .samples_count = opus_samples,
};
static struct ast_codec jpeg = {
--- a/res/res_format_attr_opus.c
+++ b/res/res_format_attr_opus.c
@@ -51,6 +51,12 @@
unsigned int spropstereo; /* Default 0 */
};
+static struct opus_attr default_opus_attr = {
+ .fec= 0,
+ .dtx= 0,
+ .stereo = 0,
+};
+
static void opus_destroy(struct ast_format *format)
{
struct opus_attr *attr = ast_format_get_attribute_data(format);
@@ -120,7 +126,7 @@
attr->dtx = val;
}
- return 0;
+ return cloned;
}
static void opus_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
@@ -163,6 +169,14 @@
struct ast_format *jointformat;
struct opus_attr *attr_res;
+ if (!attr1) {
+ attr1 = _opus_attr;
+ }
+
+ if (!attr2) {
+ attr2 = _opus_attr;
+ }
+
jointformat = ast_format_clone(format1);
if (!jointformat) {
return NULL;
--- /dev/null
+++ b/codecs/ex_opus.h
@@ -0,0 +1,35 @@
+/*! \file
+ * \brief 8-bit data
+ *
+ * Copyright (C) 2014, Lorenzo Miniero
+ *
+ * Distributed under the terms of the GNU General Public License
+ *
+ */
+
+/* Opus, a 20ms sample */
+static uint8_t ex_opus[] = {
+ 0x4b, 0x41, 0x25, 0x0b, 0xe4, 0x55, 0xc6, 0x74,
+ 0xda, 0xbb, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static struct ast_frame *opus_sample(void)
+{
+ static struct ast_frame f = {
+ .frametype = AST_FRAME_VOICE,
+ .datalen = sizeof(ex_opus),
+ .samples = 960, // ARRAY_LEN(ex_opus),
+ .mallocd = 0,
+ .offset = 0,
+ .src = __PRETTY_FUNCTION__,
+ .data.ptr = ex_opus,
+ };
+
+ f.subclass.format = ast_format_opus;
+
+ return
+}
--- /dev/null
+++ b/codecs/codec_opus.c
@@ -0,0 +1,587 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Lorenzo Miniero
+ *
+ * Lorenzo Miniero
+ *
+ * See http://www.asterisk.org for more information about
+ *