mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 03:20:57 +00:00
Add pass through support for Opus and VP8; Opus format attribute negotiation
This patch adds pass through support for Opus and VP8. That includes: * Format attribute negotiation for Opus. Note that unlike some other codecs, the draft RFC specifies having spaces delimiting the attributes in addition to ';', so you have "attra=X; attrb=Y". This broke the attribute parsing in chan_sip, so a small tweak was also included in this patch for that. * A format attribute negotiation module for Opus, res_format_attr_opus * Fast picture update for VP8. Since VP8 uses a different RTCP packet number than FIR, this really is specific to VP8 at this time. Note that the format attribute negotiation in res_pjsip_sdp_rtp was written by mjordan. The rest of this patch was written completely by Lorenzo Miniero. Review: https://reviewboard.asterisk.org/r/2723/ (closes issue ASTERISK-21981) Reported by: Tzafrir Cohen patches: asterisk_opus+vp8_passthrough_20130718.patch uploaded by lminiero (License 6518) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397526 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1168,11 +1168,26 @@ static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const voi
|
||||
case AST_CONTROL_VIDUPDATE:
|
||||
media = pvt->media[SIP_MEDIA_VIDEO];
|
||||
if (media && media->rtp) {
|
||||
/* FIXME: Only use this for VP8. Additional work would have to be done to
|
||||
* fully support other video codecs */
|
||||
struct ast_format_cap *fcap = ast_channel_nativeformats(ast);
|
||||
struct ast_format vp8;
|
||||
ast_format_set(&vp8, AST_FORMAT_VP8, 0);
|
||||
if (ast_format_cap_iscompatible(fcap, &vp8)) {
|
||||
/* FIXME Fake RTP write, this will be sent as an RTCP packet. Ideally the
|
||||
* RTP engine would provide a way to externally write/schedule RTCP
|
||||
* packets */
|
||||
struct ast_frame fr;
|
||||
fr.frametype = AST_FRAME_CONTROL;
|
||||
fr.subclass.integer = AST_CONTROL_VIDUPDATE;
|
||||
res = ast_rtp_instance_write(media->rtp, &fr);
|
||||
} else {
|
||||
ao2_ref(channel->session, +1);
|
||||
|
||||
if (ast_sip_push_task(channel->session->serializer, transmit_info_with_vidupdate, channel->session)) {
|
||||
ao2_cleanup(channel->session);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = -1;
|
||||
}
|
||||
|
@@ -1269,7 +1269,7 @@ static void add_dtls_to_sdp(struct ast_rtp_instance *instance, struct ast_str **
|
||||
static void start_ice(struct ast_rtp_instance *instance);
|
||||
static void add_codec_to_sdp(const struct sip_pvt *p, struct ast_format *codec,
|
||||
struct ast_str **m_buf, struct ast_str **a_buf,
|
||||
int debug, int *min_packet_size);
|
||||
int debug, int *min_packet_size, int *max_packet_size);
|
||||
static void add_noncodec_to_sdp(const struct sip_pvt *p, int format,
|
||||
struct ast_str **m_buf, struct ast_str **a_buf,
|
||||
int debug);
|
||||
@@ -7945,10 +7945,25 @@ static int sip_indicate(struct ast_channel *ast, int condition, const void *data
|
||||
break;
|
||||
case AST_CONTROL_VIDUPDATE: /* Request a video frame update */
|
||||
if (p->vrtp && !p->novideo) {
|
||||
/* FIXME: Only use this for VP8. Additional work would have to be done to
|
||||
* fully support other video codecs */
|
||||
struct ast_format_cap *fcap = ast_channel_nativeformats(ast);
|
||||
struct ast_format vp8;
|
||||
ast_format_set(&vp8, AST_FORMAT_VP8, 0);
|
||||
if (ast_format_cap_iscompatible(fcap, &vp8)) {
|
||||
/* FIXME Fake RTP write, this will be sent as an RTCP packet. Ideally the
|
||||
* RTP engine would provide a way to externally write/schedule RTCP
|
||||
* packets */
|
||||
struct ast_frame fr;
|
||||
fr.frametype = AST_FRAME_CONTROL;
|
||||
fr.subclass.integer = AST_CONTROL_VIDUPDATE;
|
||||
res = ast_rtp_instance_write(p->vrtp, &fr);
|
||||
} else {
|
||||
transmit_info_with_vidupdate(p);
|
||||
/* ast_rtcp_send_h261fur(p->vrtp); */
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
res = -1;
|
||||
}
|
||||
break;
|
||||
case AST_CONTROL_T38_PARAMETERS:
|
||||
res = -1;
|
||||
@@ -11167,7 +11182,7 @@ static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_
|
||||
if (debug)
|
||||
ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec);
|
||||
}
|
||||
} else if (sscanf(a, "fmtp: %30u %255s", &codec, fmtp_string) == 2) {
|
||||
} else if (sscanf(a, "fmtp: %30u %255[^\t\n]", &codec, fmtp_string) == 2) {
|
||||
struct ast_format *format;
|
||||
|
||||
if ((format = ast_rtp_codecs_get_payload_format(newaudiortp, codec))) {
|
||||
@@ -11230,7 +11245,8 @@ static int process_sdp_a_video(const char *a, struct sip_pvt *p, struct ast_rtp_
|
||||
/* We have a rtpmap to handle */
|
||||
if (*last_rtpmap_codec < SDP_MAX_RTPMAP_CODECS) {
|
||||
/* Note: should really look at the '#chans' params too */
|
||||
if (!strncasecmp(mimeSubtype, "H26", 3) || !strncasecmp(mimeSubtype, "MP4", 3)) {
|
||||
if (!strncasecmp(mimeSubtype, "H26", 3) || !strncasecmp(mimeSubtype, "MP4", 3)
|
||||
|| !strncasecmp(mimeSubtype, "VP8", 3)) {
|
||||
if (!(ast_rtp_codecs_payloads_set_rtpmap_type_rate(newvideortp, NULL, codec, "video", mimeSubtype, 0, sample_rate))) {
|
||||
if (debug)
|
||||
ast_verbose("Found video description format %s for ID %d\n", mimeSubtype, codec);
|
||||
@@ -12799,7 +12815,8 @@ static void add_codec_to_sdp(const struct sip_pvt *p,
|
||||
struct ast_str **m_buf,
|
||||
struct ast_str **a_buf,
|
||||
int debug,
|
||||
int *min_packet_size)
|
||||
int *min_packet_size,
|
||||
int *max_packet_size)
|
||||
{
|
||||
int rtp_code;
|
||||
struct ast_format_list fmt;
|
||||
@@ -12821,7 +12838,12 @@ static void add_codec_to_sdp(const struct sip_pvt *p,
|
||||
} else /* I don't see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */
|
||||
return;
|
||||
ast_str_append(m_buf, 0, " %d", rtp_code);
|
||||
/* Opus mandates 2 channels in rtpmap */
|
||||
if ((int)format->id == AST_FORMAT_OPUS) {
|
||||
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d/2\r\n", rtp_code, mime, rate);
|
||||
} else {
|
||||
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, mime, rate);
|
||||
}
|
||||
|
||||
ast_format_sdp_generate(format, rtp_code, a_buf);
|
||||
|
||||
@@ -12852,12 +12874,22 @@ static void add_codec_to_sdp(const struct sip_pvt *p,
|
||||
break;
|
||||
}
|
||||
|
||||
if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size))
|
||||
if (max_packet_size && fmt.max_ms && (fmt.max_ms < *max_packet_size)) {
|
||||
*max_packet_size = fmt.max_ms;
|
||||
}
|
||||
|
||||
if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size)) {
|
||||
*min_packet_size = fmt.cur_ms;
|
||||
}
|
||||
|
||||
/* Our first codec packetization processed cannot be zero */
|
||||
if ((*min_packet_size)==0 && fmt.cur_ms)
|
||||
if ((*min_packet_size) == 0 && fmt.cur_ms) {
|
||||
*min_packet_size = fmt.cur_ms;
|
||||
}
|
||||
|
||||
if ((*max_packet_size) == 0 && fmt.max_ms) {
|
||||
*max_packet_size = fmt.max_ms;
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Add video codec offer to SDP offer/answer body in INVITE or 200 OK */
|
||||
@@ -12884,6 +12916,10 @@ static void add_vcodec_to_sdp(const struct sip_pvt *p, struct ast_format *format
|
||||
|
||||
ast_str_append(m_buf, 0, " %d", rtp_code);
|
||||
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, subtype, rate);
|
||||
/* VP8: add RTCP FIR support */
|
||||
if ((int)format->id == AST_FORMAT_VP8) {
|
||||
ast_str_append(a_buf, 0, "a=rtcp-fb:* ccm fir\r\n");
|
||||
}
|
||||
|
||||
ast_format_sdp_generate(format, rtp_code, a_buf);
|
||||
}
|
||||
@@ -13128,6 +13164,7 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int
|
||||
int needtext = FALSE;
|
||||
int debug = sip_debug_test_pvt(p);
|
||||
int min_audio_packet_size = 0;
|
||||
int max_audio_packet_size = 0;
|
||||
int min_video_packet_size = 0;
|
||||
int min_text_packet_size = 0;
|
||||
|
||||
@@ -13309,7 +13346,7 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int
|
||||
if (AST_FORMAT_GET_TYPE(tmp_fmt.id) != AST_FORMAT_TYPE_AUDIO) {
|
||||
continue;
|
||||
}
|
||||
add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size);
|
||||
add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size, &max_audio_packet_size);
|
||||
ast_format_cap_add(alreadysent, &tmp_fmt);
|
||||
}
|
||||
ast_format_cap_iter_end(p->prefcaps);
|
||||
@@ -13329,7 +13366,7 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int
|
||||
continue;
|
||||
|
||||
if (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_AUDIO) {
|
||||
add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size);
|
||||
add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size, &max_audio_packet_size);
|
||||
} else if (needvideo && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_VIDEO)) {
|
||||
add_vcodec_to_sdp(p, &tmp_fmt, &m_video, &a_video, debug, &min_video_packet_size);
|
||||
} else if (needtext && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_TEXT)) {
|
||||
@@ -13346,7 +13383,7 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int
|
||||
continue;
|
||||
|
||||
if (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_AUDIO) {
|
||||
add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size);
|
||||
add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size, &max_audio_packet_size);
|
||||
} else if (needvideo && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_VIDEO)) {
|
||||
add_vcodec_to_sdp(p, &tmp_fmt, &m_video, &a_video, debug, &min_video_packet_size);
|
||||
} else if (needtext && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_TEXT)) {
|
||||
@@ -13365,19 +13402,27 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int
|
||||
|
||||
ast_debug(3, "-- Done with adding codecs to SDP\n");
|
||||
|
||||
if (!p->owner || !ast_internal_timing_enabled(p->owner))
|
||||
if (!p->owner || !ast_internal_timing_enabled(p->owner)) {
|
||||
ast_str_append(&a_audio, 0, "a=silenceSupp:off - - - -\r\n");
|
||||
}
|
||||
|
||||
if (min_audio_packet_size)
|
||||
if (min_audio_packet_size) {
|
||||
ast_str_append(&a_audio, 0, "a=ptime:%d\r\n", min_audio_packet_size);
|
||||
}
|
||||
|
||||
/* XXX don't think you can have ptime for video */
|
||||
if (min_video_packet_size)
|
||||
if (min_video_packet_size) {
|
||||
ast_str_append(&a_video, 0, "a=ptime:%d\r\n", min_video_packet_size);
|
||||
}
|
||||
|
||||
/* XXX don't think you can have ptime for text */
|
||||
if (min_text_packet_size)
|
||||
if (min_text_packet_size) {
|
||||
ast_str_append(&a_text, 0, "a=ptime:%d\r\n", min_text_packet_size);
|
||||
}
|
||||
|
||||
if (max_audio_packet_size) {
|
||||
ast_str_append(&a_text, 0, "a=maxptime:%d\r\n", max_audio_packet_size);
|
||||
}
|
||||
|
||||
if (!doing_directmedia) {
|
||||
if (ast_test_flag(&p->flags[2], SIP_PAGE3_ICE_SUPPORT)) {
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "asterisk/astobj2.h"
|
||||
#include "asterisk/silk.h"
|
||||
#include "asterisk/celt.h"
|
||||
#include "asterisk/opus.h"
|
||||
#define AST_FORMAT_ATTR_SIZE 64
|
||||
#define AST_FORMAT_INC 100000
|
||||
|
||||
@@ -101,6 +102,8 @@ enum ast_format_id {
|
||||
AST_FORMAT_SLINEAR192 = 27 + AST_FORMAT_TYPE_AUDIO,
|
||||
AST_FORMAT_SPEEX32 = 28 + AST_FORMAT_TYPE_AUDIO,
|
||||
AST_FORMAT_CELT = 29 + AST_FORMAT_TYPE_AUDIO,
|
||||
/*! Opus */
|
||||
AST_FORMAT_OPUS = 30 + AST_FORMAT_TYPE_AUDIO,
|
||||
|
||||
/*! H.261 Video */
|
||||
AST_FORMAT_H261 = 1 + AST_FORMAT_TYPE_VIDEO,
|
||||
@@ -112,6 +115,8 @@ enum ast_format_id {
|
||||
AST_FORMAT_H264 = 4 + AST_FORMAT_TYPE_VIDEO,
|
||||
/*! MPEG4 Video */
|
||||
AST_FORMAT_MP4_VIDEO = 5 + AST_FORMAT_TYPE_VIDEO,
|
||||
/*! VP8 */
|
||||
AST_FORMAT_VP8 = 6 + AST_FORMAT_TYPE_VIDEO,
|
||||
|
||||
/*! JPEG Images */
|
||||
AST_FORMAT_JPEG = 1 + AST_FORMAT_TYPE_IMAGE,
|
||||
|
41
include/asterisk/opus.h
Normal file
41
include/asterisk/opus.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2013, Digium, Inc.
|
||||
*
|
||||
* Lorenzo Miniero <lorenzo@meetecho.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \file
|
||||
* \brief Opus Format Attributes (http://tools.ietf.org/html/draft-ietf-payload-rtp-opus)
|
||||
*
|
||||
* \author Lorenzo Miniero <lorenzo@meetecho.com>
|
||||
*/
|
||||
#ifndef _AST_FORMAT_OPUS_H_
|
||||
#define _AST_FORMAT_OPUS_H_
|
||||
|
||||
/*! Opus format attribute key value pairs, all are accessible through ast_format_get_value()*/
|
||||
enum opus_attr_keys {
|
||||
OPUS_ATTR_KEY_MAX_BITRATE, /*! value is an int (6000-510000 in spec). */
|
||||
OPUS_ATTR_KEY_MAX_PLAYRATE, /*! value is an int (8000-48000), maximum output rate the receiver can render. */
|
||||
OPUS_ATTR_KEY_MINPTIME, /*! value is an int (3-120 in spec, 10-60 in format.c), decoder's minimum length of time in milliseconds. */
|
||||
OPUS_ATTR_KEY_STEREO, /*! value is an int, 1 prefer receiving stereo, 0 prefer mono. */
|
||||
OPUS_ATTR_KEY_CBR, /*! value is an int, 1 use constant bitrate, 0 use variable bitrate. */
|
||||
OPUS_ATTR_KEY_FEC, /*! value is an int, 1 encode with FEC, 0 do not use FEC. */
|
||||
OPUS_ATTR_KEY_DTX, /*! value is an int, 1 dtx is enabled, 0 dtx not enabled. */
|
||||
OPUS_ATTR_KEY_SPROP_CAPTURE_RATE, /*! value is an int (8000-48000), likely input rate we're going to produce. */
|
||||
OPUS_ATTR_KEY_SPROP_STEREO, /*! value is an int, 1 likely to send stereo, 0 likely to send mono. */
|
||||
};
|
||||
|
||||
#endif /* _AST_FORMAT_OPUS_H */
|
@@ -802,6 +802,8 @@ struct ast_format *ast_best_codec(struct ast_format_cap *cap, struct ast_format
|
||||
AST_FORMAT_SPEEX32,
|
||||
AST_FORMAT_SPEEX16,
|
||||
AST_FORMAT_SPEEX,
|
||||
/*! Opus */
|
||||
AST_FORMAT_OPUS,
|
||||
/*! SILK is pretty awesome. */
|
||||
AST_FORMAT_SILK,
|
||||
/*! CELT supports crazy high sample rates */
|
||||
|
@@ -430,6 +430,9 @@ uint64_t ast_format_id_to_old_bitfield(enum ast_format_id id)
|
||||
/*! SpeeX Wideband (16kHz) Free Compression */
|
||||
case AST_FORMAT_SPEEX16:
|
||||
return (1ULL << 33);
|
||||
/*! Opus audio (8kHz, 16kHz, 24kHz, 48Khz) */
|
||||
case AST_FORMAT_OPUS:
|
||||
return (1ULL << 34);
|
||||
/*! Raw mu-law data (G.711) */
|
||||
case AST_FORMAT_TESTLAW:
|
||||
return (1ULL << 47);
|
||||
@@ -449,6 +452,9 @@ uint64_t ast_format_id_to_old_bitfield(enum ast_format_id id)
|
||||
/*! MPEG4 Video */
|
||||
case AST_FORMAT_MP4_VIDEO:
|
||||
return (1ULL << 22);
|
||||
/*! VP8 Video */
|
||||
case AST_FORMAT_VP8:
|
||||
return (1ULL << 23);
|
||||
|
||||
/*! JPEG Images */
|
||||
case AST_FORMAT_JPEG:
|
||||
@@ -532,6 +538,9 @@ struct ast_format *ast_format_from_old_bitfield(struct ast_format *dst, uint64_t
|
||||
/*! SpeeX Wideband (16kHz) Free Compression */
|
||||
case (1ULL << 33):
|
||||
return ast_format_set(dst, AST_FORMAT_SPEEX16, 0);
|
||||
/*! Opus audio (8kHz, 16kHz, 24kHz, 48Khz) */
|
||||
case (1ULL << 34):
|
||||
return ast_format_set(dst, AST_FORMAT_OPUS, 0);
|
||||
/*! Raw mu-law data (G.711) */
|
||||
case (1ULL << 47):
|
||||
return ast_format_set(dst, AST_FORMAT_TESTLAW, 0);
|
||||
@@ -551,6 +560,9 @@ struct ast_format *ast_format_from_old_bitfield(struct ast_format *dst, uint64_t
|
||||
/*! MPEG4 Video */
|
||||
case (1ULL << 22):
|
||||
return ast_format_set(dst, AST_FORMAT_MP4_VIDEO, 0);
|
||||
/*! VP8 Video */
|
||||
case (1ULL << 23):
|
||||
return ast_format_set(dst, AST_FORMAT_VP8, 0);
|
||||
|
||||
/*! JPEG Images */
|
||||
case (1ULL << 16):
|
||||
@@ -782,6 +794,9 @@ int ast_format_rate(const struct ast_format *format)
|
||||
return samplerate;
|
||||
}
|
||||
}
|
||||
/* Opus */
|
||||
case AST_FORMAT_OPUS:
|
||||
return 48000;
|
||||
default:
|
||||
return 8000;
|
||||
}
|
||||
@@ -1067,6 +1082,10 @@ static int format_list_init(void)
|
||||
format_list_add_static(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR48, 0), "slin48", 48000, "16 bit Signed Linear PCM (48kHz)", 960, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE, 0);/*!< Signed linear (48kHz) */
|
||||
format_list_add_static(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR96, 0), "slin96", 96000, "16 bit Signed Linear PCM (96kHz)", 1920, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE, 0);/*!< Signed linear (96kHz) */
|
||||
format_list_add_static(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR192, 0), "slin192", 192000, "16 bit Signed Linear PCM (192kHz)", 3840, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE, 0);/*!< Signed linear (192kHz) */
|
||||
/* Opus (FIXME: real min is 3/5/10, real max is 120...) */
|
||||
format_list_add_static(ast_format_set(&tmpfmt, AST_FORMAT_OPUS, 0), "opus", 48000, "Opus Codec", 10, 20, 60, 20, 20, 0, 0); /*!< codec_opus.c */
|
||||
/* VP8 (passthrough) */
|
||||
format_list_add_static(ast_format_set(&tmpfmt, AST_FORMAT_VP8, 0), "vp8", 0, "VP8 Video", 0, 0, 0, 0 ,0 ,0, 0); /*!< Passthrough support, see format_h263.c */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1097,9 +1097,13 @@ int ast_codec_get_samples(struct ast_frame *f)
|
||||
return 160;
|
||||
}
|
||||
case AST_FORMAT_CELT:
|
||||
/* TODO The assumes 20ms delivery right now, which is incorrect */
|
||||
/* TODO This assumes 20ms delivery right now, which is incorrect */
|
||||
samples = ast_format_rate(&f->subclass.format) / 50;
|
||||
break;
|
||||
case AST_FORMAT_OPUS:
|
||||
/* TODO This assumes 20ms delivery right now, which is incorrect */
|
||||
samples = 960;
|
||||
break;
|
||||
default:
|
||||
ast_log(LOG_WARNING, "Unable to calculate samples for format %s\n", ast_getformatname(&f->subclass.format));
|
||||
}
|
||||
|
@@ -1977,6 +1977,9 @@ int ast_rtp_engine_init()
|
||||
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SIREN7, 0), 0, "audio", "G7221", 16000);
|
||||
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SIREN14, 0), 0, "audio", "G7221", 32000);
|
||||
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G719, 0), 0, "audio", "G719", 48000);
|
||||
/* Opus and VP8 */
|
||||
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_OPUS, 0), 0, "audio", "opus", 48000);
|
||||
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_VP8, 0), 0, "video", "VP8", 90000);
|
||||
|
||||
/* Define the static rtp payload mappings */
|
||||
add_static_payload(0, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0), 0);
|
||||
@@ -2018,6 +2021,9 @@ int ast_rtp_engine_init()
|
||||
add_static_payload(118, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0), 0); /* 16 Khz signed linear */
|
||||
add_static_payload(119, ast_format_set(&tmpfmt, AST_FORMAT_SPEEX32, 0), 0);
|
||||
add_static_payload(121, NULL, AST_RTP_CISCO_DTMF); /* Must be type 121 */
|
||||
/* Opus and VP8 */
|
||||
add_static_payload(100, ast_format_set(&tmpfmt, AST_FORMAT_VP8, 0), 0);
|
||||
add_static_payload(107, ast_format_set(&tmpfmt, AST_FORMAT_OPUS, 0), 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
321
res/res_format_attr_opus.c
Normal file
321
res/res_format_attr_opus.c
Normal file
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2013, Digium, Inc.
|
||||
*
|
||||
* Lorenzo Miniero <lorenzo@meetecho.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \file
|
||||
* \brief Opus format attribute interface
|
||||
*
|
||||
* \author Lorenzo Miniero <lorenzo@meetecho.com>
|
||||
*/
|
||||
|
||||
/*** MODULEINFO
|
||||
<support_level>core</support_level>
|
||||
***/
|
||||
|
||||
#include "asterisk.h"
|
||||
|
||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
|
||||
#include "asterisk/module.h"
|
||||
#include "asterisk/format.h"
|
||||
|
||||
/*!
|
||||
* \brief Opus attribute structure.
|
||||
*
|
||||
* \note http://tools.ietf.org/html/draft-ietf-payload-rtp-opus-00.
|
||||
*/
|
||||
struct opus_attr {
|
||||
unsigned int maxbitrate; /* Default 64-128 kb/s for FB stereo music */
|
||||
unsigned int maxplayrate /* Default 48000 */;
|
||||
unsigned int minptime; /* Default 3, but it's 10 in format.c */
|
||||
unsigned int stereo; /* Default 0 */
|
||||
unsigned int cbr; /* Default 0 */
|
||||
unsigned int fec; /* Default 0 */
|
||||
unsigned int dtx; /* Default 0 */
|
||||
unsigned int spropmaxcapturerate; /* Default 48000 */
|
||||
unsigned int spropstereo; /* Default 0 */
|
||||
};
|
||||
|
||||
static int opus_sdp_parse(struct ast_format_attr *format_attr, const char *attributes)
|
||||
{
|
||||
struct opus_attr *attr = (struct opus_attr *) format_attr;
|
||||
const char *kvp;
|
||||
unsigned int val;
|
||||
|
||||
if ((kvp = strstr(attributes, "maxplaybackrate")) && sscanf(kvp, "maxplaybackrate=%30u", &val) == 1) {
|
||||
attr->maxplayrate = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, "sprop-maxcapturerate")) && sscanf(kvp, "sprop-maxcapturerate=%30u", &val) == 1) {
|
||||
attr->spropmaxcapturerate = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, "minptime")) && sscanf(kvp, "minptime=%30u", &val) == 1) {
|
||||
attr->minptime = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, "maxaveragebitrate")) && sscanf(kvp, "maxaveragebitrate=%30u", &val) == 1) {
|
||||
attr->maxbitrate = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, " stereo")) && sscanf(kvp, " stereo=%30u", &val) == 1) {
|
||||
attr->stereo = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, ";stereo")) && sscanf(kvp, ";stereo=%30u", &val) == 1) {
|
||||
attr->stereo = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, "sprop-stereo")) && sscanf(kvp, "sprop-stereo=%30u", &val) == 1) {
|
||||
attr->spropstereo = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, "cbr")) && sscanf(kvp, "cbr=%30u", &val) == 1) {
|
||||
attr->cbr = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, "useinbandfec")) && sscanf(kvp, "useinbandfec=%30u", &val) == 1) {
|
||||
attr->fec = val;
|
||||
}
|
||||
if ((kvp = strstr(attributes, "usedtx")) && sscanf(kvp, "usedtx=%30u", &val) == 1) {
|
||||
attr->dtx = val;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void opus_sdp_generate(const struct ast_format_attr *format_attr, unsigned int payload, struct ast_str **str)
|
||||
{
|
||||
struct opus_attr *attr = (struct opus_attr *) format_attr;
|
||||
|
||||
/* FIXME should we only generate attributes that were explicitly set? */
|
||||
ast_str_append(str, 0,
|
||||
"a=fmtp:%d "
|
||||
"maxplaybackrate=%d;"
|
||||
"sprop-maxcapturerate=%d;"
|
||||
"minptime=%d;"
|
||||
"maxaveragebitrate=%d;"
|
||||
"stereo=%d;"
|
||||
"sprop-stereo=%d;"
|
||||
"cbr=%d;"
|
||||
"useinbandfec=%d;"
|
||||
"usedtx=%d\r\n",
|
||||
payload,
|
||||
attr->maxplayrate ? attr->maxplayrate : 48000, /* maxplaybackrate */
|
||||
attr->spropmaxcapturerate ? attr->spropmaxcapturerate : 48000, /* sprop-maxcapturerate */
|
||||
attr->minptime > 10 ? attr->minptime : 10, /* minptime */
|
||||
attr->maxbitrate ? attr->maxbitrate : 20000, /* maxaveragebitrate */
|
||||
attr->stereo ? 1 : 0, /* stereo */
|
||||
attr->spropstereo ? 1 : 0, /* sprop-stereo */
|
||||
attr->cbr ? 1 : 0, /* cbr */
|
||||
attr->fec ? 1 : 0, /* useinbandfec */
|
||||
attr->dtx ? 1 : 0 /* usedtx */
|
||||
);
|
||||
}
|
||||
|
||||
static int opus_get_val(const struct ast_format_attr *fattr, int key, void *result)
|
||||
{
|
||||
const struct opus_attr *attr = (struct opus_attr *) fattr;
|
||||
int *val = result;
|
||||
|
||||
switch (key) {
|
||||
case OPUS_ATTR_KEY_MAX_BITRATE:
|
||||
*val = attr->maxbitrate;
|
||||
break;
|
||||
case OPUS_ATTR_KEY_MAX_PLAYRATE:
|
||||
*val = attr->maxplayrate;
|
||||
break;
|
||||
case OPUS_ATTR_KEY_MINPTIME:
|
||||
*val = attr->minptime;
|
||||
break;
|
||||
case OPUS_ATTR_KEY_STEREO:
|
||||
*val = attr->stereo;
|
||||
break;
|
||||
case OPUS_ATTR_KEY_CBR:
|
||||
*val = attr->cbr;
|
||||
break;
|
||||
case OPUS_ATTR_KEY_FEC:
|
||||
*val = attr->fec;
|
||||
break;
|
||||
case OPUS_ATTR_KEY_DTX:
|
||||
*val = attr->dtx;
|
||||
break;
|
||||
case OPUS_ATTR_KEY_SPROP_CAPTURE_RATE:
|
||||
*val = attr->spropmaxcapturerate;
|
||||
break;
|
||||
case OPUS_ATTR_KEY_SPROP_STEREO:
|
||||
*val = attr->spropstereo;
|
||||
break;
|
||||
default:
|
||||
ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int opus_isset(const struct ast_format_attr *fattr, va_list ap)
|
||||
{
|
||||
enum opus_attr_keys key;
|
||||
const struct opus_attr *attr = (struct opus_attr *) fattr;
|
||||
|
||||
for (key = va_arg(ap, int);
|
||||
key != AST_FORMAT_ATTR_END;
|
||||
key = va_arg(ap, int))
|
||||
{
|
||||
switch (key) {
|
||||
case OPUS_ATTR_KEY_MAX_BITRATE:
|
||||
if (attr->maxbitrate != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case OPUS_ATTR_KEY_MAX_PLAYRATE:
|
||||
if (attr->maxplayrate != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case OPUS_ATTR_KEY_MINPTIME:
|
||||
if (attr->minptime != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case OPUS_ATTR_KEY_STEREO:
|
||||
if (attr->stereo != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case OPUS_ATTR_KEY_CBR:
|
||||
if (attr->cbr != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case OPUS_ATTR_KEY_FEC:
|
||||
if (attr->fec != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case OPUS_ATTR_KEY_DTX:
|
||||
if (attr->dtx != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case OPUS_ATTR_KEY_SPROP_CAPTURE_RATE:
|
||||
if (attr->spropmaxcapturerate != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case OPUS_ATTR_KEY_SPROP_STEREO:
|
||||
if (attr->spropstereo != (va_arg(ap, int))) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int opus_getjoint(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2, struct ast_format_attr *result)
|
||||
{
|
||||
struct opus_attr *attr1 = (struct opus_attr *) fattr1;
|
||||
struct opus_attr *attr2 = (struct opus_attr *) fattr2;
|
||||
struct opus_attr *attr_res = (struct opus_attr *) result;
|
||||
int joint = 0;
|
||||
|
||||
/* Only do dtx if both sides want it. DTX is a trade off between
|
||||
* computational complexity and bandwidth. */
|
||||
attr_res->dtx = attr1->dtx && attr2->dtx ? 1 : 0;
|
||||
|
||||
/* Only do FEC if both sides want it. If a peer specifically requests not
|
||||
* to receive with FEC, it may be a waste of bandwidth. */
|
||||
attr_res->fec = attr1->fec && attr2->fec ? 1 : 0;
|
||||
|
||||
/* Only do stereo if both sides want it. If a peer specifically requests not
|
||||
* to receive stereo signals, it may be a waste of bandwidth. */
|
||||
attr_res->stereo = attr1->stereo && attr2->stereo ? 1 : 0;
|
||||
|
||||
/* FIXME: do we need to join other attributes as well, e.g., minptime, cbr, etc.? */
|
||||
|
||||
return joint;
|
||||
}
|
||||
|
||||
static void opus_set(struct ast_format_attr *fattr, va_list ap)
|
||||
{
|
||||
enum opus_attr_keys key;
|
||||
struct opus_attr *attr = (struct opus_attr *) fattr;
|
||||
|
||||
for (key = va_arg(ap, int);
|
||||
key != AST_FORMAT_ATTR_END;
|
||||
key = va_arg(ap, int))
|
||||
{
|
||||
switch (key) {
|
||||
case OPUS_ATTR_KEY_MAX_BITRATE:
|
||||
attr->maxbitrate = (va_arg(ap, int));
|
||||
break;
|
||||
case OPUS_ATTR_KEY_MAX_PLAYRATE:
|
||||
attr->maxplayrate = (va_arg(ap, int));
|
||||
break;
|
||||
case OPUS_ATTR_KEY_MINPTIME:
|
||||
attr->minptime = (va_arg(ap, int));
|
||||
break;
|
||||
case OPUS_ATTR_KEY_STEREO:
|
||||
attr->stereo = (va_arg(ap, int));
|
||||
break;
|
||||
case OPUS_ATTR_KEY_CBR:
|
||||
attr->cbr = (va_arg(ap, int));
|
||||
break;
|
||||
case OPUS_ATTR_KEY_FEC:
|
||||
attr->fec = (va_arg(ap, int));
|
||||
break;
|
||||
case OPUS_ATTR_KEY_DTX:
|
||||
attr->dtx = (va_arg(ap, int));
|
||||
break;
|
||||
case OPUS_ATTR_KEY_SPROP_CAPTURE_RATE:
|
||||
attr->spropmaxcapturerate = (va_arg(ap, int));
|
||||
break;
|
||||
case OPUS_ATTR_KEY_SPROP_STEREO:
|
||||
attr->spropstereo = (va_arg(ap, int));
|
||||
break;
|
||||
default:
|
||||
ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct ast_format_attr_interface opus_interface = {
|
||||
.id = AST_FORMAT_OPUS,
|
||||
.format_attr_get_joint = opus_getjoint,
|
||||
.format_attr_set = opus_set,
|
||||
.format_attr_isset = opus_isset,
|
||||
.format_attr_get_val = opus_get_val,
|
||||
.format_attr_sdp_parse = opus_sdp_parse,
|
||||
.format_attr_sdp_generate = opus_sdp_generate,
|
||||
};
|
||||
|
||||
static int load_module(void)
|
||||
{
|
||||
if (ast_format_attr_reg_interface(&opus_interface)) {
|
||||
return AST_MODULE_LOAD_DECLINE;
|
||||
}
|
||||
|
||||
return AST_MODULE_LOAD_SUCCESS;
|
||||
}
|
||||
|
||||
static int unload_module(void)
|
||||
{
|
||||
ast_format_attr_unreg_interface(&opus_interface);
|
||||
return 0;
|
||||
}
|
||||
|
||||
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Opus Format Attribute Module",
|
||||
.load = load_module,
|
||||
.unload = unload_module,
|
||||
.load_pri = AST_MODPRI_CHANNEL_DEPEND,
|
||||
);
|
@@ -849,7 +849,9 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
||||
char tmp[512];
|
||||
pj_str_t stmp;
|
||||
pjmedia_sdp_attr *attr;
|
||||
int index = 0, min_packet_size = 0, noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) ? AST_RTP_DTMF : 0;
|
||||
int index = 0;
|
||||
int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) ? AST_RTP_DTMF : 0;
|
||||
int min_packet_size = 0, max_packet_size = 0;
|
||||
int rtp_code;
|
||||
struct ast_format format;
|
||||
RAII_VAR(struct ast_format_cap *, caps, NULL, ast_format_cap_destroy);
|
||||
@@ -951,6 +953,10 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
||||
if (fmt.cur_ms && ((fmt.cur_ms < min_packet_size) || !min_packet_size)) {
|
||||
min_packet_size = fmt.cur_ms;
|
||||
}
|
||||
|
||||
if (fmt.max_ms && ((fmt.max_ms < max_packet_size) || !max_packet_size)) {
|
||||
max_packet_size = fmt.max_ms;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -983,6 +989,12 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
||||
media->attr[media->attr_count++] = attr;
|
||||
}
|
||||
|
||||
if (max_packet_size) {
|
||||
snprintf(tmp, sizeof(tmp), "%d", max_packet_size);
|
||||
attr = pjmedia_sdp_attr_create(pool, "maxptime", pj_cstr(&stmp, tmp));
|
||||
media->attr[media->attr_count++] = attr;
|
||||
}
|
||||
|
||||
/* Add the sendrecv attribute - we purposely don't keep track because pjmedia-sdp will automatically change our offer for us */
|
||||
attr = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_attr);
|
||||
attr->name = STR_SENDRECV;
|
||||
|
@@ -90,6 +90,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#define RTCP_PT_SDES 202
|
||||
#define RTCP_PT_BYE 203
|
||||
#define RTCP_PT_APP 204
|
||||
/* VP8: RTCP Feedback */
|
||||
#define RTCP_PT_PSFB 206
|
||||
|
||||
#define RTP_MTU 1200
|
||||
|
||||
@@ -350,6 +352,9 @@ struct ast_rtcp {
|
||||
double normdevrtt;
|
||||
double stdevrtt;
|
||||
unsigned int rtt_count;
|
||||
|
||||
/* VP8: sequence number for the RTCP FIR FCI */
|
||||
int firseq;
|
||||
};
|
||||
|
||||
struct rtp_red {
|
||||
@@ -2609,6 +2614,45 @@ static int ast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *fr
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* VP8: is this a request to send a RTCP FIR? */
|
||||
if (frame->frametype == AST_FRAME_CONTROL && frame->subclass.integer == AST_CONTROL_VIDUPDATE) {
|
||||
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
|
||||
unsigned int *rtcpheader;
|
||||
char bdata[1024];
|
||||
int len = 20;
|
||||
int ice;
|
||||
int res;
|
||||
|
||||
if (!rtp || !rtp->rtcp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ast_sockaddr_isnull(&rtp->rtcp->them)) {
|
||||
/*
|
||||
* RTCP was stopped.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Prepare RTCP FIR (PT=206, FMT=4) */
|
||||
rtp->rtcp->firseq++;
|
||||
if(rtp->rtcp->firseq == 256) {
|
||||
rtp->rtcp->firseq = 0;
|
||||
}
|
||||
|
||||
rtcpheader = (unsigned int *)bdata;
|
||||
rtcpheader[0] = htonl((2 << 30) | (4 << 24) | (RTCP_PT_PSFB << 16) | ((len/4)-1));
|
||||
rtcpheader[1] = htonl(rtp->ssrc);
|
||||
rtcpheader[2] = htonl(rtp->themssrc);
|
||||
rtcpheader[3] = htonl(rtp->themssrc); /* FCI: SSRC */
|
||||
rtcpheader[4] = htonl(rtp->rtcp->firseq << 24); /* FCI: Sequence number */
|
||||
res = rtcp_sendto(instance, (unsigned int *)rtcpheader, len, 0, &rtp->rtcp->them, &ice);
|
||||
if (res < 0) {
|
||||
ast_log(LOG_ERROR, "RTCP FIR transmission error: %s\n", strerror(errno));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If there is no data length we can't very well send the packet */
|
||||
if (!frame->datalen) {
|
||||
ast_debug(1, "Received frame with no data for RTP instance '%p' so dropping frame\n", instance);
|
||||
@@ -2660,6 +2704,8 @@ static int ast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *fr
|
||||
case AST_FORMAT_SIREN7:
|
||||
case AST_FORMAT_SIREN14:
|
||||
case AST_FORMAT_G719:
|
||||
/* Opus */
|
||||
case AST_FORMAT_OPUS:
|
||||
/* these are all frame-based codecs and cannot be safely run through
|
||||
a smoother */
|
||||
break;
|
||||
@@ -3353,6 +3399,8 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
|
||||
message_blob);
|
||||
break;
|
||||
case RTCP_PT_FUR:
|
||||
/* Handle RTCP FIR as FUR */
|
||||
case RTCP_PT_PSFB:
|
||||
if (rtcp_debug_test_addr(&addr)) {
|
||||
ast_verbose("Received an RTCP Fast Update Request\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user