Fix issue 261 (Adds support for Opus audio codec)

Fix issue 262, issue 263 and issue 264
This commit is contained in:
bossiel 2013-05-07 04:55:21 +00:00
parent a37f9a619f
commit c6ea8f7fab
82 changed files with 5182 additions and 1513 deletions

View File

@ -499,4 +499,11 @@ unsigned MediaSessionMgr::defaultsGetRtpBuffSize(){
bool MediaSessionMgr::defaultsSetAvpfTail(unsigned tail_min, unsigned tail_max){
return (tmedia_defaults_set_avpf_tail(tail_min, tail_max) == 0);
}
bool MediaSessionMgr::defaultsSetOpusMaxCaptureRate(uint32_t opus_maxcapturerate){
return (tmedia_defaults_set_opus_maxcapturerate(opus_maxcapturerate) == 0);
}
bool MediaSessionMgr::defaultsSetOpusMaxPlaybackRate(uint32_t opus_maxplaybackrate){
return (tmedia_defaults_set_opus_maxplaybackrate(opus_maxplaybackrate) == 0);
}

View File

@ -145,6 +145,9 @@ public:
static bool defaultsSetRtpBuffSize(unsigned buffSize);
static unsigned defaultsGetRtpBuffSize();
static bool defaultsSetAvpfTail(unsigned tail_min, unsigned tail_max);
static bool defaultsSetOpusMaxCaptureRate(uint32_t opus_maxcapturerate);
static bool defaultsSetOpusMaxPlaybackRate(uint32_t opus_maxplaybackrate);
private:
tmedia_session_mgr_t* m_pWrappedMgr;

View File

@ -67,10 +67,11 @@ int twrap_consumer_proxy_audio_prepare(tmedia_consumer_t* self, const tmedia_cod
int ret = -1;
if(codec && (manager = ProxyPluginMgr::getInstance())){
if((audio->pcConsumer = manager->findAudioConsumer(audio->id)) && audio->pcConsumer->getCallback()){
self->audio.ptime = codec->plugin->audio.ptime;
self->audio.in.channels = codec->plugin->audio.channels;
self->audio.in.rate = codec->plugin->rate;
ret = audio->pcConsumer->getCallback()->prepare((int)codec->plugin->audio.ptime, codec->plugin->rate, codec->plugin->audio.channels);
self->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec);
self->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec);
self->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec);
ret = audio->pcConsumer->getCallback()->prepare((int)self->audio.ptime, self->audio.in.rate, self->audio.in.channels);
}
}

View File

@ -63,10 +63,10 @@ static int twrap_producer_proxy_audio_prepare(tmedia_producer_t* self, const tme
if(codec && (manager = ProxyPluginMgr::getInstance())){
const ProxyAudioProducer* audioProducer;
if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()){
self->audio.channels = codec->plugin->audio.channels;
self->audio.rate = codec->plugin->rate;
self->audio.ptime = codec->plugin->audio.ptime;
ret = audioProducer->getCallback()->prepare((int)codec->plugin->audio.ptime, codec->plugin->rate, codec->plugin->audio.channels);
self->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
self->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
self->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
ret = audioProducer->getCallback()->prepare((int)self->audio.ptime, self->audio.rate, self->audio.channels);
}
}
return ret;
@ -206,6 +206,19 @@ ProxyAudioProducer::~ProxyAudioProducer()
stopPushCallback();
}
// Use this function to request resampling when your sound card can't honor negotaited record parameters
bool ProxyAudioProducer::setActualSndCardRecordParams(int nPtime, int nRate, int nChannels)
{
TSK_DEBUG_INFO("setActualSndCardRecordParams(ptime=%d, rate=%d, channels=%d)", nPtime, nRate, nChannels);
if(m_pWrappedPlugin){
TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.ptime = nPtime;
TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.rate = nRate;
TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.channels = nChannels;
return true;
}
return false;
}
bool ProxyAudioProducer::setPushBuffer(const void* pPushBufferPtr, unsigned nPushBufferSize, bool bUsePushCallback/*=false*/)
{
m_PushBuffer.pPushBufferPtr = pPushBufferPtr;

View File

@ -62,6 +62,7 @@ public:
#endif
virtual ~ProxyAudioProducer();
bool setActualSndCardRecordParams(int nPtime, int nRate, int nChannels);
bool setPushBuffer(const void* pPushBufferPtr, unsigned nPushBufferSize, bool bUsePushCallback=false);
int push(const void* pBuffer=tsk_null, unsigned nSize=0);
bool setGain(unsigned nGain);

View File

@ -359,6 +359,16 @@ public class MediaSessionMgr : IDisposable {
return ret;
}
public static bool defaultsSetOpusMaxCaptureRate(uint opus_maxcapturerate) {
bool ret = tinyWRAPPINVOKE.MediaSessionMgr_defaultsSetOpusMaxCaptureRate(opus_maxcapturerate);
return ret;
}
public static bool defaultsSetOpusMaxPlaybackRate(uint opus_maxplaybackrate) {
bool ret = tinyWRAPPINVOKE.MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(opus_maxplaybackrate);
return ret;
}
}
}

View File

@ -40,6 +40,11 @@ public class ProxyAudioProducer : ProxyPlugin {
}
}
public bool setActualSndCardRecordParams(int nPtime, int nRate, int nChannels) {
bool ret = tinyWRAPPINVOKE.ProxyAudioProducer_setActualSndCardRecordParams(swigCPtr, nPtime, nRate, nChannels);
return ret;
}
public bool setPushBuffer(IntPtr pPushBufferPtr, uint nPushBufferSize, bool bUsePushCallback) {
bool ret = tinyWRAPPINVOKE.ProxyAudioProducer_setPushBuffer__SWIG_0(swigCPtr, pPushBufferPtr, nPushBufferSize, bUsePushCallback);
return ret;

View File

@ -480,6 +480,12 @@ class tinyWRAPPINVOKE {
[DllImport("tinyWRAP", EntryPoint="CSharp_MediaSessionMgr_defaultsSetAvpfTail")]
public static extern bool MediaSessionMgr_defaultsSetAvpfTail(uint jarg1, uint jarg2);
[DllImport("tinyWRAP", EntryPoint="CSharp_MediaSessionMgr_defaultsSetOpusMaxCaptureRate")]
public static extern bool MediaSessionMgr_defaultsSetOpusMaxCaptureRate(uint jarg1);
[DllImport("tinyWRAP", EntryPoint="CSharp_MediaSessionMgr_defaultsSetOpusMaxPlaybackRate")]
public static extern bool MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(uint jarg1);
[DllImport("tinyWRAP", EntryPoint="CSharp_delete_MediaContent")]
public static extern void delete_MediaContent(HandleRef jarg1);
@ -1389,6 +1395,9 @@ class tinyWRAPPINVOKE {
[DllImport("tinyWRAP", EntryPoint="CSharp_delete_ProxyAudioProducer")]
public static extern void delete_ProxyAudioProducer(HandleRef jarg1);
[DllImport("tinyWRAP", EntryPoint="CSharp_ProxyAudioProducer_setActualSndCardRecordParams")]
public static extern bool ProxyAudioProducer_setActualSndCardRecordParams(HandleRef jarg1, int jarg2, int jarg3, int jarg4);
[DllImport("tinyWRAP", EntryPoint="CSharp_ProxyAudioProducer_setPushBuffer__SWIG_0")]
public static extern bool ProxyAudioProducer_setPushBuffer__SWIG_0(HandleRef jarg1, IntPtr jarg2, uint jarg3, bool jarg4);

View File

@ -2356,6 +2356,30 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_MediaSessionMgr_defaultsSetAvpfTail(u
}
SWIGEXPORT unsigned int SWIGSTDCALL CSharp_MediaSessionMgr_defaultsSetOpusMaxCaptureRate(unsigned int jarg1) {
unsigned int jresult ;
uint32_t arg1 ;
bool result;
arg1 = (uint32_t)jarg1;
result = (bool)MediaSessionMgr::defaultsSetOpusMaxCaptureRate(arg1);
jresult = result;
return jresult;
}
SWIGEXPORT unsigned int SWIGSTDCALL CSharp_MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(unsigned int jarg1) {
unsigned int jresult ;
uint32_t arg1 ;
bool result;
arg1 = (uint32_t)jarg1;
result = (bool)MediaSessionMgr::defaultsSetOpusMaxPlaybackRate(arg1);
jresult = result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_delete_MediaContent(void * jarg1) {
MediaContent *arg1 = (MediaContent *) 0 ;
@ -6210,6 +6234,24 @@ SWIGEXPORT void SWIGSTDCALL CSharp_delete_ProxyAudioProducer(void * jarg1) {
}
SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ProxyAudioProducer_setActualSndCardRecordParams(void * jarg1, int jarg2, int jarg3, int jarg4) {
unsigned int jresult ;
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;
int arg2 ;
int arg3 ;
int arg4 ;
bool result;
arg1 = (ProxyAudioProducer *)jarg1;
arg2 = (int)jarg2;
arg3 = (int)jarg3;
arg4 = (int)jarg4;
result = (bool)(arg1)->setActualSndCardRecordParams(arg2,arg3,arg4);
jresult = result;
return jresult;
}
SWIGEXPORT unsigned int SWIGSTDCALL CSharp_ProxyAudioProducer_setPushBuffer__SWIG_0(void * jarg1, void * jarg2, unsigned int jarg3, unsigned int jarg4) {
unsigned int jresult ;
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;

View File

@ -290,4 +290,12 @@ public class MediaSessionMgr {
return tinyWRAPJNI.MediaSessionMgr_defaultsSetAvpfTail(tail_min, tail_max);
}
public static boolean defaultsSetOpusMaxCaptureRate(long opus_maxcapturerate) {
return tinyWRAPJNI.MediaSessionMgr_defaultsSetOpusMaxCaptureRate(opus_maxcapturerate);
}
public static boolean defaultsSetOpusMaxPlaybackRate(long opus_maxplaybackrate) {
return tinyWRAPJNI.MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(opus_maxplaybackrate);
}
}

View File

@ -35,6 +35,10 @@ public class ProxyAudioProducer extends ProxyPlugin {
super.delete();
}
public boolean setActualSndCardRecordParams(int nPtime, int nRate, int nChannels) {
return tinyWRAPJNI.ProxyAudioProducer_setActualSndCardRecordParams(swigCPtr, this, nPtime, nRate, nChannels);
}
public boolean setPushBuffer(java.nio.ByteBuffer pPushBufferPtr, long nPushBufferSize, boolean bUsePushCallback) {
return tinyWRAPJNI.ProxyAudioProducer_setPushBuffer__SWIG_0(swigCPtr, this, pPushBufferPtr, nPushBufferSize, bUsePushCallback);
}

View File

@ -290,4 +290,12 @@ public class MediaSessionMgr {
return tinyWRAPJNI.MediaSessionMgr_defaultsSetAvpfTail(tail_min, tail_max);
}
public static boolean defaultsSetOpusMaxCaptureRate(long opus_maxcapturerate) {
return tinyWRAPJNI.MediaSessionMgr_defaultsSetOpusMaxCaptureRate(opus_maxcapturerate);
}
public static boolean defaultsSetOpusMaxPlaybackRate(long opus_maxplaybackrate) {
return tinyWRAPJNI.MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(opus_maxplaybackrate);
}
}

View File

@ -35,6 +35,10 @@ public class ProxyAudioProducer extends ProxyPlugin {
super.delete();
}
public boolean setActualSndCardRecordParams(int nPtime, int nRate, int nChannels) {
return tinyWRAPJNI.ProxyAudioProducer_setActualSndCardRecordParams(swigCPtr, this, nPtime, nRate, nChannels);
}
public boolean setPushBuffer(java.nio.ByteBuffer pPushBufferPtr, long nPushBufferSize, boolean bUsePushCallback) {
return tinyWRAPJNI.ProxyAudioProducer_setPushBuffer__SWIG_0(swigCPtr, this, pPushBufferPtr, nPushBufferSize, bUsePushCallback);
}

View File

@ -2,7 +2,7 @@
# Build tinyWRAP for Google Android Systems
for project in tinySAK tinyNET tinyHTTP tinyXCAP tinyIPSec tinySMS tinySIGCOMP tinySDP tinyMSRP tinyMEDIA tinyRTP tinyDAV tinySIP
#for project in
#for project in tinyDAV
do
echo -e building "$project with parameters=$@\n"
make PROJECT=$project clean

View File

@ -8,6 +8,7 @@ LIBYUV=yes \
VPX=yes \
H264=no \
THEORA=yes \
OPUS=yes \
OPENCORE_AMR=no \
SPEEX_DSP=yes \
SPEEX_JB=yes \

View File

@ -38,6 +38,10 @@ ifeq ($(VPX),yes)
VPX_LDLAGS := -lvpx_$(MARCH)
endif
ifneq ($(OPUS), no)
OPUS_LDFLAGS := -lopus
endif
ifneq ($(OPENCORE_AMR), no)
OPENCORE_ARM_LDFLAGS := -lopencore-amrnb
endif
@ -88,7 +92,7 @@ else
_LT=Bstatic
endif
LDFLAGS := $(LDFLAGS_LIB) -L$(THIRDPARTIES_LIB) -L$(THIRDPARTIES_MARCH_LIB) $(FFMPEG_LDFLAGS) $(LIBYUV_LDLAGS) $(VPX_LDLAGS) $(WEBRTC_LDFLAGS) $(SPEEX_DSP_LDFLAGS) $(SPEEX_LDFLAGS) $(OPENCORE_ARM_LDFLAGS) $(BV16_LDFLAGS) $(ILBC_LDFLAGS) $(LIBGSM_LDFLAGS) $(G729_LDFLAGS) \
LDFLAGS := $(LDFLAGS_LIB) -L$(THIRDPARTIES_LIB) -L$(THIRDPARTIES_MARCH_LIB) $(FFMPEG_LDFLAGS) $(LIBYUV_LDLAGS) $(VPX_LDLAGS) $(WEBRTC_LDFLAGS) $(SPEEX_DSP_LDFLAGS) $(SPEEX_LDFLAGS) $(OPUS_LDFLAGS) $(OPENCORE_ARM_LDFLAGS) $(BV16_LDFLAGS) $(ILBC_LDFLAGS) $(LIBGSM_LDFLAGS) $(G729_LDFLAGS) \
$(LIBSRTP_LDFLAGS) $(TLS_LDFLAGS) \
-Wl,-Bdynamic -lm -lstdc++ -lgnustl_static -lgcc -llog -ldl \
-Wl,-$(_LT) -ltinySAK_$(MARCH) -ltinyHTTP_$(MARCH) -ltinyXCAP_$(MARCH) -ltinyIPSec_$(MARCH) -ltinySIGCOMP_$(MARCH) -ltinySMS_$(MARCH) -ltinyNET_$(MARCH) -ltinySDP_$(MARCH) -ltinyRTP_$(MARCH) -ltinyMEDIA_$(MARCH) -ltinyMSRP_$(MARCH) -ltinyDAV_$(MARCH) -ltinySIP_$(MARCH)

View File

@ -9,6 +9,7 @@ LIBYUV=yes \
VPX=yes \
H264=yes \
THEORA=yes \
OPUS=yes \
OPENCORE_AMR=yes \
SPEEX_DSP=yes \
SPEEX_JB=yes \

View File

@ -8,6 +8,7 @@ LIBYUV=yes \
VPX=yes \
H264=no \
THEORA=yes \
OPUS=yes \
OPENCORE_AMR=yes \
SPEEX_DSP=yes \
SPEEX_JB=yes \

View File

@ -8,6 +8,7 @@ LIBYUV=yes \
VPX=yes \
H264=no \
THEORA=no \
OPUS=no \
OPENCORE_AMR=no \
SPEEX_DSP=yes \
SPEEX_JB=yes \

View File

@ -107,6 +107,8 @@ public class tinyWRAPJNI {
public final static native boolean MediaSessionMgr_defaultsSetRtpBuffSize(long jarg1);
public final static native long MediaSessionMgr_defaultsGetRtpBuffSize();
public final static native boolean MediaSessionMgr_defaultsSetAvpfTail(long jarg1, long jarg2);
public final static native boolean MediaSessionMgr_defaultsSetOpusMaxCaptureRate(long jarg1);
public final static native boolean MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(long jarg1);
public final static native void delete_MediaContent(long jarg1);
public final static native String MediaContent_getType(long jarg1, MediaContent jarg1_);
public final static native long MediaContent_getDataLength(long jarg1, MediaContent jarg1_);
@ -415,6 +417,7 @@ public class tinyWRAPJNI {
public final static native void ProxyAudioProducerCallback_director_connect(ProxyAudioProducerCallback obj, long cptr, boolean mem_own, boolean weak_global);
public final static native void ProxyAudioProducerCallback_change_ownership(ProxyAudioProducerCallback obj, long cptr, boolean take_or_release);
public final static native void delete_ProxyAudioProducer(long jarg1);
public final static native boolean ProxyAudioProducer_setActualSndCardRecordParams(long jarg1, ProxyAudioProducer jarg1_, int jarg2, int jarg3, int jarg4);
public final static native boolean ProxyAudioProducer_setPushBuffer__SWIG_0(long jarg1, ProxyAudioProducer jarg1_, java.nio.ByteBuffer jarg2, long jarg3, boolean jarg4);
public final static native boolean ProxyAudioProducer_setPushBuffer__SWIG_1(long jarg1, ProxyAudioProducer jarg1_, java.nio.ByteBuffer jarg2, long jarg3);
public final static native int ProxyAudioProducer_push__SWIG_0(long jarg1, ProxyAudioProducer jarg1_, java.nio.ByteBuffer jarg2, long jarg3);

View File

@ -3492,6 +3492,34 @@ SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_MediaSessionM
}
SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_MediaSessionMgr_1defaultsSetOpusMaxCaptureRate(JNIEnv *jenv, jclass jcls, jlong jarg1) {
jboolean jresult = 0 ;
uint32_t arg1 ;
bool result;
(void)jenv;
(void)jcls;
arg1 = (uint32_t)jarg1;
result = (bool)MediaSessionMgr::defaultsSetOpusMaxCaptureRate(arg1);
jresult = (jboolean)result;
return jresult;
}
SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_MediaSessionMgr_1defaultsSetOpusMaxPlaybackRate(JNIEnv *jenv, jclass jcls, jlong jarg1) {
jboolean jresult = 0 ;
uint32_t arg1 ;
bool result;
(void)jenv;
(void)jcls;
arg1 = (uint32_t)jarg1;
result = (bool)MediaSessionMgr::defaultsSetOpusMaxPlaybackRate(arg1);
jresult = (jboolean)result;
return jresult;
}
SWIGEXPORT void JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_delete_1MediaContent(JNIEnv *jenv, jclass jcls, jlong jarg1) {
MediaContent *arg1 = (MediaContent *) 0 ;
@ -8799,6 +8827,27 @@ SWIGEXPORT void JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_delete_1ProxyAudi
}
SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_ProxyAudioProducer_1setActualSndCardRecordParams(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jint jarg3, jint jarg4) {
jboolean jresult = 0 ;
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;
int arg2 ;
int arg3 ;
int arg4 ;
bool result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(ProxyAudioProducer **)&jarg1;
arg2 = (int)jarg2;
arg3 = (int)jarg3;
arg4 = (int)jarg4;
result = (bool)(arg1)->setActualSndCardRecordParams(arg2,arg3,arg4);
jresult = (jboolean)result;
return jresult;
}
SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_ProxyAudioProducer_1setPushBuffer_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2, jlong jarg3, jboolean jarg4) {
jboolean jresult = 0 ;
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;

View File

@ -107,6 +107,8 @@ public class tinyWRAPJNI {
public final static native boolean MediaSessionMgr_defaultsSetRtpBuffSize(long jarg1);
public final static native long MediaSessionMgr_defaultsGetRtpBuffSize();
public final static native boolean MediaSessionMgr_defaultsSetAvpfTail(long jarg1, long jarg2);
public final static native boolean MediaSessionMgr_defaultsSetOpusMaxCaptureRate(long jarg1);
public final static native boolean MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(long jarg1);
public final static native void delete_MediaContent(long jarg1);
public final static native String MediaContent_getType(long jarg1, MediaContent jarg1_);
public final static native long MediaContent_getDataLength(long jarg1, MediaContent jarg1_);
@ -415,6 +417,7 @@ public class tinyWRAPJNI {
public final static native void ProxyAudioProducerCallback_director_connect(ProxyAudioProducerCallback obj, long cptr, boolean mem_own, boolean weak_global);
public final static native void ProxyAudioProducerCallback_change_ownership(ProxyAudioProducerCallback obj, long cptr, boolean take_or_release);
public final static native void delete_ProxyAudioProducer(long jarg1);
public final static native boolean ProxyAudioProducer_setActualSndCardRecordParams(long jarg1, ProxyAudioProducer jarg1_, int jarg2, int jarg3, int jarg4);
public final static native boolean ProxyAudioProducer_setPushBuffer__SWIG_0(long jarg1, ProxyAudioProducer jarg1_, java.nio.ByteBuffer jarg2, long jarg3, boolean jarg4);
public final static native boolean ProxyAudioProducer_setPushBuffer__SWIG_1(long jarg1, ProxyAudioProducer jarg1_, java.nio.ByteBuffer jarg2, long jarg3);
public final static native int ProxyAudioProducer_push__SWIG_0(long jarg1, ProxyAudioProducer jarg1_, java.nio.ByteBuffer jarg2, long jarg3);

View File

@ -3492,6 +3492,34 @@ SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_MediaSessionM
}
SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_MediaSessionMgr_1defaultsSetOpusMaxCaptureRate(JNIEnv *jenv, jclass jcls, jlong jarg1) {
jboolean jresult = 0 ;
uint32_t arg1 ;
bool result;
(void)jenv;
(void)jcls;
arg1 = (uint32_t)jarg1;
result = (bool)MediaSessionMgr::defaultsSetOpusMaxCaptureRate(arg1);
jresult = (jboolean)result;
return jresult;
}
SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_MediaSessionMgr_1defaultsSetOpusMaxPlaybackRate(JNIEnv *jenv, jclass jcls, jlong jarg1) {
jboolean jresult = 0 ;
uint32_t arg1 ;
bool result;
(void)jenv;
(void)jcls;
arg1 = (uint32_t)jarg1;
result = (bool)MediaSessionMgr::defaultsSetOpusMaxPlaybackRate(arg1);
jresult = (jboolean)result;
return jresult;
}
SWIGEXPORT void JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_delete_1MediaContent(JNIEnv *jenv, jclass jcls, jlong jarg1) {
MediaContent *arg1 = (MediaContent *) 0 ;
@ -8799,6 +8827,27 @@ SWIGEXPORT void JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_delete_1ProxyAudi
}
SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_ProxyAudioProducer_1setActualSndCardRecordParams(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jint jarg3, jint jarg4) {
jboolean jresult = 0 ;
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;
int arg2 ;
int arg3 ;
int arg4 ;
bool result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(ProxyAudioProducer **)&jarg1;
arg2 = (int)jarg2;
arg3 = (int)jarg3;
arg4 = (int)jarg4;
result = (bool)(arg1)->setActualSndCardRecordParams(arg2,arg3,arg4);
jresult = (jboolean)result;
return jresult;
}
SWIGEXPORT jboolean JNICALL Java_org_doubango_tinyWRAP_tinyWRAPJNI_ProxyAudioProducer_1setPushBuffer_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2, jlong jarg3, jboolean jarg4) {
jboolean jresult = 0 ;
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;

View File

@ -294,6 +294,8 @@ sub DESTROY {
*defaultsSetRtpBuffSize = *tinyWRAPc::MediaSessionMgr_defaultsSetRtpBuffSize;
*defaultsGetRtpBuffSize = *tinyWRAPc::MediaSessionMgr_defaultsGetRtpBuffSize;
*defaultsSetAvpfTail = *tinyWRAPc::MediaSessionMgr_defaultsSetAvpfTail;
*defaultsSetOpusMaxCaptureRate = *tinyWRAPc::MediaSessionMgr_defaultsSetOpusMaxCaptureRate;
*defaultsSetOpusMaxPlaybackRate = *tinyWRAPc::MediaSessionMgr_defaultsSetOpusMaxPlaybackRate;
sub DISOWN {
my $self = shift;
my $ptr = tied(%$self);
@ -1720,6 +1722,7 @@ sub DESTROY {
}
}
*setActualSndCardRecordParams = *tinyWRAPc::ProxyAudioProducer_setActualSndCardRecordParams;
*setPushBuffer = *tinyWRAPc::ProxyAudioProducer_setPushBuffer;
*push = *tinyWRAPc::ProxyAudioProducer_push;
*setGain = *tinyWRAPc::ProxyAudioProducer_setGain;

View File

@ -5191,6 +5191,62 @@ XS(_wrap_MediaSessionMgr_defaultsSetAvpfTail) {
}
XS(_wrap_MediaSessionMgr_defaultsSetOpusMaxCaptureRate) {
{
uint32_t arg1 ;
unsigned int val1 ;
int ecode1 = 0 ;
int argvi = 0;
bool result;
dXSARGS;
if ((items < 1) || (items > 1)) {
SWIG_croak("Usage: MediaSessionMgr_defaultsSetOpusMaxCaptureRate(opus_maxcapturerate);");
}
ecode1 = SWIG_AsVal_unsigned_SS_int SWIG_PERL_CALL_ARGS_2(ST(0), &val1);
if (!SWIG_IsOK(ecode1)) {
SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "MediaSessionMgr_defaultsSetOpusMaxCaptureRate" "', argument " "1"" of type '" "uint32_t""'");
}
arg1 = static_cast< uint32_t >(val1);
result = (bool)MediaSessionMgr::defaultsSetOpusMaxCaptureRate(arg1);
ST(argvi) = SWIG_From_bool SWIG_PERL_CALL_ARGS_1(static_cast< bool >(result)); argvi++ ;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_MediaSessionMgr_defaultsSetOpusMaxPlaybackRate) {
{
uint32_t arg1 ;
unsigned int val1 ;
int ecode1 = 0 ;
int argvi = 0;
bool result;
dXSARGS;
if ((items < 1) || (items > 1)) {
SWIG_croak("Usage: MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(opus_maxplaybackrate);");
}
ecode1 = SWIG_AsVal_unsigned_SS_int SWIG_PERL_CALL_ARGS_2(ST(0), &val1);
if (!SWIG_IsOK(ecode1)) {
SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "MediaSessionMgr_defaultsSetOpusMaxPlaybackRate" "', argument " "1"" of type '" "uint32_t""'");
}
arg1 = static_cast< uint32_t >(val1);
result = (bool)MediaSessionMgr::defaultsSetOpusMaxPlaybackRate(arg1);
ST(argvi) = SWIG_From_bool SWIG_PERL_CALL_ARGS_1(static_cast< bool >(result)); argvi++ ;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_delete_MediaContent) {
{
MediaContent *arg1 = (MediaContent *) 0 ;
@ -18698,6 +18754,64 @@ XS(_wrap_delete_ProxyAudioProducer) {
}
XS(_wrap_ProxyAudioProducer_setActualSndCardRecordParams) {
{
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;
int arg2 ;
int arg3 ;
int arg4 ;
void *argp1 = 0 ;
int res1 = 0 ;
int val2 ;
int ecode2 = 0 ;
int val3 ;
int ecode3 = 0 ;
int val4 ;
int ecode4 = 0 ;
int argvi = 0;
bool result;
dXSARGS;
if ((items < 4) || (items > 4)) {
SWIG_croak("Usage: ProxyAudioProducer_setActualSndCardRecordParams(self,nPtime,nRate,nChannels);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_ProxyAudioProducer, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ProxyAudioProducer_setActualSndCardRecordParams" "', argument " "1"" of type '" "ProxyAudioProducer *""'");
}
arg1 = reinterpret_cast< ProxyAudioProducer * >(argp1);
ecode2 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "ProxyAudioProducer_setActualSndCardRecordParams" "', argument " "2"" of type '" "int""'");
}
arg2 = static_cast< int >(val2);
ecode3 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "ProxyAudioProducer_setActualSndCardRecordParams" "', argument " "3"" of type '" "int""'");
}
arg3 = static_cast< int >(val3);
ecode4 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(3), &val4);
if (!SWIG_IsOK(ecode4)) {
SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "ProxyAudioProducer_setActualSndCardRecordParams" "', argument " "4"" of type '" "int""'");
}
arg4 = static_cast< int >(val4);
result = (bool)(arg1)->setActualSndCardRecordParams(arg2,arg3,arg4);
ST(argvi) = SWIG_From_bool SWIG_PERL_CALL_ARGS_1(static_cast< bool >(result)); argvi++ ;
XSRETURN(argvi);
fail:
SWIG_croak_null();
}
}
XS(_wrap_ProxyAudioProducer_setPushBuffer__SWIG_0) {
{
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;
@ -26786,6 +26900,8 @@ static swig_command_info swig_commands[] = {
{"tinyWRAPc::MediaSessionMgr_defaultsSetRtpBuffSize", _wrap_MediaSessionMgr_defaultsSetRtpBuffSize},
{"tinyWRAPc::MediaSessionMgr_defaultsGetRtpBuffSize", _wrap_MediaSessionMgr_defaultsGetRtpBuffSize},
{"tinyWRAPc::MediaSessionMgr_defaultsSetAvpfTail", _wrap_MediaSessionMgr_defaultsSetAvpfTail},
{"tinyWRAPc::MediaSessionMgr_defaultsSetOpusMaxCaptureRate", _wrap_MediaSessionMgr_defaultsSetOpusMaxCaptureRate},
{"tinyWRAPc::MediaSessionMgr_defaultsSetOpusMaxPlaybackRate", _wrap_MediaSessionMgr_defaultsSetOpusMaxPlaybackRate},
{"tinyWRAPc::delete_MediaContent", _wrap_delete_MediaContent},
{"tinyWRAPc::MediaContent_getType", _wrap_MediaContent_getType},
{"tinyWRAPc::MediaContent_getDataLength", _wrap_MediaContent_getDataLength},
@ -27012,6 +27128,7 @@ static swig_command_info swig_commands[] = {
{"tinyWRAPc::ProxyAudioProducerCallback_stop", _wrap_ProxyAudioProducerCallback_stop},
{"tinyWRAPc::ProxyAudioProducerCallback_fillPushBuffer", _wrap_ProxyAudioProducerCallback_fillPushBuffer},
{"tinyWRAPc::delete_ProxyAudioProducer", _wrap_delete_ProxyAudioProducer},
{"tinyWRAPc::ProxyAudioProducer_setActualSndCardRecordParams", _wrap_ProxyAudioProducer_setActualSndCardRecordParams},
{"tinyWRAPc::ProxyAudioProducer_setPushBuffer", _wrap_ProxyAudioProducer_setPushBuffer},
{"tinyWRAPc::ProxyAudioProducer_push", _wrap_ProxyAudioProducer_push},
{"tinyWRAPc::ProxyAudioProducer_setGain", _wrap_ProxyAudioProducer_setGain},

View File

@ -295,6 +295,10 @@ class MediaSessionMgr(_object):
if _newclass:defaultsGetRtpBuffSize = staticmethod(_tinyWRAP.MediaSessionMgr_defaultsGetRtpBuffSize)
__swig_getmethods__["defaultsSetAvpfTail"] = lambda x: _tinyWRAP.MediaSessionMgr_defaultsSetAvpfTail
if _newclass:defaultsSetAvpfTail = staticmethod(_tinyWRAP.MediaSessionMgr_defaultsSetAvpfTail)
__swig_getmethods__["defaultsSetOpusMaxCaptureRate"] = lambda x: _tinyWRAP.MediaSessionMgr_defaultsSetOpusMaxCaptureRate
if _newclass:defaultsSetOpusMaxCaptureRate = staticmethod(_tinyWRAP.MediaSessionMgr_defaultsSetOpusMaxCaptureRate)
__swig_getmethods__["defaultsSetOpusMaxPlaybackRate"] = lambda x: _tinyWRAP.MediaSessionMgr_defaultsSetOpusMaxPlaybackRate
if _newclass:defaultsSetOpusMaxPlaybackRate = staticmethod(_tinyWRAP.MediaSessionMgr_defaultsSetOpusMaxPlaybackRate)
MediaSessionMgr_swigregister = _tinyWRAP.MediaSessionMgr_swigregister
MediaSessionMgr_swigregister(MediaSessionMgr)
@ -510,6 +514,14 @@ def MediaSessionMgr_defaultsSetAvpfTail(*args):
return _tinyWRAP.MediaSessionMgr_defaultsSetAvpfTail(*args)
MediaSessionMgr_defaultsSetAvpfTail = _tinyWRAP.MediaSessionMgr_defaultsSetAvpfTail
def MediaSessionMgr_defaultsSetOpusMaxCaptureRate(*args):
return _tinyWRAP.MediaSessionMgr_defaultsSetOpusMaxCaptureRate(*args)
MediaSessionMgr_defaultsSetOpusMaxCaptureRate = _tinyWRAP.MediaSessionMgr_defaultsSetOpusMaxCaptureRate
def MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(*args):
return _tinyWRAP.MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(*args)
MediaSessionMgr_defaultsSetOpusMaxPlaybackRate = _tinyWRAP.MediaSessionMgr_defaultsSetOpusMaxPlaybackRate
class MediaContent(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, MediaContent, name, value)
@ -1299,6 +1311,7 @@ class ProxyAudioProducer(ProxyPlugin):
__repr__ = _swig_repr
__swig_destroy__ = _tinyWRAP.delete_ProxyAudioProducer
__del__ = lambda self : None;
def setActualSndCardRecordParams(self, *args): return _tinyWRAP.ProxyAudioProducer_setActualSndCardRecordParams(self, *args)
def setPushBuffer(self, *args): return _tinyWRAP.ProxyAudioProducer_setPushBuffer(self, *args)
def push(self, *args): return _tinyWRAP.ProxyAudioProducer_push(self, *args)
def setGain(self, *args): return _tinyWRAP.ProxyAudioProducer_setGain(self, *args)

View File

@ -7935,6 +7935,50 @@ fail:
}
SWIGINTERN PyObject *_wrap_MediaSessionMgr_defaultsSetOpusMaxCaptureRate(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
uint32_t arg1 ;
unsigned int val1 ;
int ecode1 = 0 ;
PyObject * obj0 = 0 ;
bool result;
if (!PyArg_ParseTuple(args,(char *)"O:MediaSessionMgr_defaultsSetOpusMaxCaptureRate",&obj0)) SWIG_fail;
ecode1 = SWIG_AsVal_unsigned_SS_int(obj0, &val1);
if (!SWIG_IsOK(ecode1)) {
SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "MediaSessionMgr_defaultsSetOpusMaxCaptureRate" "', argument " "1"" of type '" "uint32_t""'");
}
arg1 = static_cast< uint32_t >(val1);
result = (bool)MediaSessionMgr::defaultsSetOpusMaxCaptureRate(arg1);
resultobj = SWIG_From_bool(static_cast< bool >(result));
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_MediaSessionMgr_defaultsSetOpusMaxPlaybackRate(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
uint32_t arg1 ;
unsigned int val1 ;
int ecode1 = 0 ;
PyObject * obj0 = 0 ;
bool result;
if (!PyArg_ParseTuple(args,(char *)"O:MediaSessionMgr_defaultsSetOpusMaxPlaybackRate",&obj0)) SWIG_fail;
ecode1 = SWIG_AsVal_unsigned_SS_int(obj0, &val1);
if (!SWIG_IsOK(ecode1)) {
SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "MediaSessionMgr_defaultsSetOpusMaxPlaybackRate" "', argument " "1"" of type '" "uint32_t""'");
}
arg1 = static_cast< uint32_t >(val1);
result = (bool)MediaSessionMgr::defaultsSetOpusMaxPlaybackRate(arg1);
resultobj = SWIG_From_bool(static_cast< bool >(result));
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *MediaSessionMgr_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *obj;
if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL;
@ -18685,6 +18729,55 @@ fail:
}
SWIGINTERN PyObject *_wrap_ProxyAudioProducer_setActualSndCardRecordParams(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;
int arg2 ;
int arg3 ;
int arg4 ;
void *argp1 = 0 ;
int res1 = 0 ;
int val2 ;
int ecode2 = 0 ;
int val3 ;
int ecode3 = 0 ;
int val4 ;
int ecode4 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
PyObject * obj3 = 0 ;
bool result;
if (!PyArg_ParseTuple(args,(char *)"OOOO:ProxyAudioProducer_setActualSndCardRecordParams",&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ProxyAudioProducer, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ProxyAudioProducer_setActualSndCardRecordParams" "', argument " "1"" of type '" "ProxyAudioProducer *""'");
}
arg1 = reinterpret_cast< ProxyAudioProducer * >(argp1);
ecode2 = SWIG_AsVal_int(obj1, &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "ProxyAudioProducer_setActualSndCardRecordParams" "', argument " "2"" of type '" "int""'");
}
arg2 = static_cast< int >(val2);
ecode3 = SWIG_AsVal_int(obj2, &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "ProxyAudioProducer_setActualSndCardRecordParams" "', argument " "3"" of type '" "int""'");
}
arg3 = static_cast< int >(val3);
ecode4 = SWIG_AsVal_int(obj3, &val4);
if (!SWIG_IsOK(ecode4)) {
SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "ProxyAudioProducer_setActualSndCardRecordParams" "', argument " "4"" of type '" "int""'");
}
arg4 = static_cast< int >(val4);
result = (bool)(arg1)->setActualSndCardRecordParams(arg2,arg3,arg4);
resultobj = SWIG_From_bool(static_cast< bool >(result));
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_ProxyAudioProducer_setPushBuffer__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
ProxyAudioProducer *arg1 = (ProxyAudioProducer *) 0 ;
@ -25362,6 +25455,8 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"MediaSessionMgr_defaultsSetRtpBuffSize", _wrap_MediaSessionMgr_defaultsSetRtpBuffSize, METH_VARARGS, NULL},
{ (char *)"MediaSessionMgr_defaultsGetRtpBuffSize", _wrap_MediaSessionMgr_defaultsGetRtpBuffSize, METH_VARARGS, NULL},
{ (char *)"MediaSessionMgr_defaultsSetAvpfTail", _wrap_MediaSessionMgr_defaultsSetAvpfTail, METH_VARARGS, NULL},
{ (char *)"MediaSessionMgr_defaultsSetOpusMaxCaptureRate", _wrap_MediaSessionMgr_defaultsSetOpusMaxCaptureRate, METH_VARARGS, NULL},
{ (char *)"MediaSessionMgr_defaultsSetOpusMaxPlaybackRate", _wrap_MediaSessionMgr_defaultsSetOpusMaxPlaybackRate, METH_VARARGS, NULL},
{ (char *)"MediaSessionMgr_swigregister", MediaSessionMgr_swigregister, METH_VARARGS, NULL},
{ (char *)"delete_MediaContent", _wrap_delete_MediaContent, METH_VARARGS, NULL},
{ (char *)"MediaContent_getType", _wrap_MediaContent_getType, METH_VARARGS, NULL},
@ -25630,6 +25725,7 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"disown_ProxyAudioProducerCallback", _wrap_disown_ProxyAudioProducerCallback, METH_VARARGS, NULL},
{ (char *)"ProxyAudioProducerCallback_swigregister", ProxyAudioProducerCallback_swigregister, METH_VARARGS, NULL},
{ (char *)"delete_ProxyAudioProducer", _wrap_delete_ProxyAudioProducer, METH_VARARGS, NULL},
{ (char *)"ProxyAudioProducer_setActualSndCardRecordParams", _wrap_ProxyAudioProducer_setActualSndCardRecordParams, METH_VARARGS, NULL},
{ (char *)"ProxyAudioProducer_setPushBuffer", _wrap_ProxyAudioProducer_setPushBuffer, METH_VARARGS, NULL},
{ (char *)"ProxyAudioProducer_push", _wrap_ProxyAudioProducer_push, METH_VARARGS, NULL},
{ (char *)"ProxyAudioProducer_setGain", _wrap_ProxyAudioProducer_setGain, METH_VARARGS, NULL},

View File

@ -208,6 +208,14 @@ AC_ARG_WITH(amr,
AC_SUBST(LIBAMR_LIBADD, "-lopencore-amrnb")
AM_CONDITIONAL(USE_AMR, true)],
[ AC_SUBST(LIBAMR_LIBADD, "")])
AM_CONDITIONAL(USE_OPUS, false)
AC_ARG_WITH(opus,
[ --with-opus Link against libopus library],
[AC_DEFINE_UNQUOTED(HAVE_LIBOPUS, 1, HAVE_LIBOPUS)
AC_SUBST(LIBAMR_LIBADD, "-lopus")
AM_CONDITIONAL(USE_OPUS, true)],
[ AC_SUBST(LIBOPUS_LIBADD, "")])
AM_CONDITIONAL(USE_SPEEX, false)
AC_ARG_WITH(speex,

View File

@ -129,9 +129,9 @@ static int audio_consumer_opensles_prepare(tmedia_consumer_t* _self, const tmedi
}
// initialize input parameters from the codec information
TMEDIA_CONSUMER(self)->audio.ptime = codec->plugin->audio.ptime;
TMEDIA_CONSUMER(self)->audio.in.channels = codec->plugin->audio.channels;
TMEDIA_CONSUMER(self)->audio.in.rate = codec->plugin->rate;
TMEDIA_CONSUMER(self)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec);
TMEDIA_CONSUMER(self)->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec);
TMEDIA_CONSUMER(self)->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec);
AUDIO_OPENSLES_DEBUG_INFO("audio_consumer_opensles_prepare(channels=%d, rate=%d, ptime=%d)", codec->plugin->audio.channels, codec->plugin->rate, codec->plugin->audio.ptime);

View File

@ -125,9 +125,9 @@ static int audio_producer_opensles_prepare(tmedia_producer_t* _self, const tmedi
}
// init input parameters from the codec
TMEDIA_PRODUCER(self)->audio.channels = codec->plugin->audio.channels;
TMEDIA_PRODUCER(self)->audio.rate = codec->plugin->rate;
TMEDIA_PRODUCER(self)->audio.ptime = codec->plugin->audio.ptime;
TMEDIA_PRODUCER(self)->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
TMEDIA_PRODUCER(self)->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
TMEDIA_PRODUCER(self)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
AUDIO_OPENSLES_DEBUG_INFO("audio_producer_opensles_prepare(channels=%d, rate=%d, ptime=%d)", codec->plugin->audio.channels, codec->plugin->rate, codec->plugin->audio.ptime);

View File

@ -0,0 +1,903 @@
/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
Written by Jean-Marc Valin and Koen Vos */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file opus.h
* @brief Opus reference implementation API
*/
#ifndef OPUS_H
#define OPUS_H
#include "opus_types.h"
#include "opus_defines.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @mainpage Opus
*
* The Opus codec is designed for interactive speech and audio transmission over the Internet.
* It is designed by the IETF Codec Working Group and incorporates technology from
* Skype's SILK codec and Xiph.Org's CELT codec.
*
* The Opus codec is designed to handle a wide range of interactive audio applications,
* including Voice over IP, videoconferencing, in-game chat, and even remote live music
* performances. It can scale from low bit-rate narrowband speech to very high quality
* stereo music. Its main features are:
* @li Sampling rates from 8 to 48 kHz
* @li Bit-rates from 6 kb/s to 510 kb/s
* @li Support for both constant bit-rate (CBR) and variable bit-rate (VBR)
* @li Audio bandwidth from narrowband to full-band
* @li Support for speech and music
* @li Support for mono and stereo
* @li Support for multichannel (up to 255 channels)
* @li Frame sizes from 2.5 ms to 60 ms
* @li Good loss robustness and packet loss concealment (PLC)
* @li Floating point and fixed-point implementation
*
* Documentation sections:
* @li @ref opus_encoder
* @li @ref opus_decoder
* @li @ref opus_repacketizer
* @li @ref opus_multistream
* @li @ref opus_libinfo
* @li @ref opus_custom
*/
/** @defgroup opus_encoder Opus Encoder
* @{
*
* @brief This page describes the process and functions used to encode Opus.
*
* Since Opus is a stateful codec, the encoding process starts with creating an encoder
* state. This can be done with:
*
* @code
* int error;
* OpusEncoder *enc;
* enc = opus_encoder_create(Fs, channels, application, &error);
* @endcode
*
* From this point, @c enc can be used for encoding an audio stream. An encoder state
* @b must @b not be used for more than one stream at the same time. Similarly, the encoder
* state @b must @b not be re-initialized for each frame.
*
* While opus_encoder_create() allocates memory for the state, it's also possible
* to initialize pre-allocated memory:
*
* @code
* int size;
* int error;
* OpusEncoder *enc;
* size = opus_encoder_get_size(channels);
* enc = malloc(size);
* error = opus_encoder_init(enc, Fs, channels, application);
* @endcode
*
* where opus_encoder_get_size() returns the required size for the encoder state. Note that
* future versions of this code may change the size, so no assuptions should be made about it.
*
* The encoder state is always continuous in memory and only a shallow copy is sufficient
* to copy it (e.g. memcpy())
*
* It is possible to change some of the encoder's settings using the opus_encoder_ctl()
* interface. All these settings already default to the recommended value, so they should
* only be changed when necessary. The most common settings one may want to change are:
*
* @code
* opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate));
* opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity));
* opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type));
* @endcode
*
* where
*
* @arg bitrate is in bits per second (b/s)
* @arg complexity is a value from 1 to 10, where 1 is the lowest complexity and 10 is the highest
* @arg signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_SIGNAL_MUSIC
*
* See @ref opus_encoderctls and @ref opus_genericctls for a complete list of parameters that can be set or queried. Most parameters can be set or changed at any time during a stream.
*
* To encode a frame, opus_encode() or opus_encode_float() must be called with exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data:
* @code
* len = opus_encode(enc, audio_frame, frame_size, packet, max_packet);
* @endcode
*
* where
* <ul>
* <li>audio_frame is the audio data in opus_int16 (or float for opus_encode_float())</li>
* <li>frame_size is the duration of the frame in samples (per channel)</li>
* <li>packet is the byte array to which the compressed data is written</li>
* <li>max_packet is the maximum number of bytes that can be written in the packet (4000 bytes is recommended).
* Do not use max_packet to control VBR target bitrate, instead use the #OPUS_SET_BITRATE CTL.</li>
* </ul>
*
* opus_encode() and opus_encode_float() return the number of bytes actually written to the packet.
* The return value <b>can be negative</b>, which indicates that an error has occurred. If the return value
* is 1 byte, then the packet does not need to be transmitted (DTX).
*
* Once the encoder state if no longer needed, it can be destroyed with
*
* @code
* opus_encoder_destroy(enc);
* @endcode
*
* If the encoder was created with opus_encoder_init() rather than opus_encoder_create(),
* then no action is required aside from potentially freeing the memory that was manually
* allocated for it (calling free(enc) for the example above)
*
*/
/** Opus encoder state.
* This contains the complete state of an Opus encoder.
* It is position independent and can be freely copied.
* @see opus_encoder_create,opus_encoder_init
*/
typedef struct OpusEncoder OpusEncoder;
/** Gets the size of an <code>OpusEncoder</code> structure.
* @param[in] channels <tt>int</tt>: Number of channels.
* This must be 1 or 2.
* @returns The size in bytes.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels);
/**
*/
/** Allocates and initializes an encoder state.
* There are three coding modes:
*
* @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice
* signals. It enhances the input signal by high-pass filtering and
* emphasizing formants and harmonics. Optionally it includes in-band
* forward error correction to protect against packet loss. Use this
* mode for typical VoIP applications. Because of the enhancement,
* even at high bitrates the output may sound different from the input.
*
* @ref OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most
* non-voice signals like music. Use this mode for music and mixed
* (music/voice) content, broadcast, and applications requiring less
* than 15 ms of coding delay.
*
* @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that
* disables the speech-optimized mode in exchange for slightly reduced delay.
* This mode can only be set on an newly initialized or freshly reset encoder
* because it changes the codec delay.
*
* This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution).
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) in input signal
* @param [in] application <tt>int</tt>: Coding mode (@ref OPUS_APPLICATION_VOIP/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY)
* @param [out] error <tt>int*</tt>: @ref opus_errorcodes
* @note Regardless of the sampling rate and number channels selected, the Opus encoder
* can switch to a lower audio bandwidth or number of channels if the bitrate
* selected is too low. This also means that it is safe to always use 48 kHz stereo input
* and let the encoder optimize the encoding.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create(
opus_int32 Fs,
int channels,
int application,
int *error
);
/** Initializes a previously allocated encoder state
* The memory pointed to by st must be at least the size returned by opus_encoder_get_size().
* This is intended for applications which use their own allocator instead of malloc.
* @see opus_encoder_create(),opus_encoder_get_size()
* To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
* @param [in] st <tt>OpusEncoder*</tt>: Encoder state
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) in input signal
* @param [in] application <tt>int</tt>: Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY)
* @retval #OPUS_OK Success or @ref opus_errorcodes
*/
OPUS_EXPORT int opus_encoder_init(
OpusEncoder *st,
opus_int32 Fs,
int channels,
int application
) OPUS_ARG_NONNULL(1);
/** Encodes an Opus frame.
* @param [in] st <tt>OpusEncoder*</tt>: Encoder state
* @param [in] pcm <tt>opus_int16*</tt>: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(opus_int16)
* @param [in] frame_size <tt>int</tt>: Number of samples per channel in the
* input signal.
* This must be an Opus frame size for
* the encoder's sampling rate.
* For example, at 48 kHz the permitted
* values are 120, 240, 480, 960, 1920,
* and 2880.
* Passing in a duration of less than
* 10 ms (480 samples at 48 kHz) will
* prevent the encoder from using the LPC
* or hybrid modes.
* @param [out] data <tt>unsigned char*</tt>: Output payload.
* This must contain storage for at
* least \a max_data_bytes.
* @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
* memory for the output
* payload. This may be
* used to impose an upper limit on
* the instant bitrate, but should
* not be used as the only bitrate
* control. Use #OPUS_SET_BITRATE to
* control the bitrate.
* @returns The length of the encoded packet (in bytes) on success or a
* negative error code (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode(
OpusEncoder *st,
const opus_int16 *pcm,
int frame_size,
unsigned char *data,
opus_int32 max_data_bytes
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
/** Encodes an Opus frame from floating point input.
* @param [in] st <tt>OpusEncoder*</tt>: Encoder state
* @param [in] pcm <tt>float*</tt>: Input in float format (interleaved if 2 channels), with a normal range of +/-1.0.
* Samples with a range beyond +/-1.0 are supported but will
* be clipped by decoders using the integer API and should
* only be used if it is known that the far end supports
* extended dynamic range.
* length is frame_size*channels*sizeof(float)
* @param [in] frame_size <tt>int</tt>: Number of samples per channel in the
* input signal.
* This must be an Opus frame size for
* the encoder's sampling rate.
* For example, at 48 kHz the permitted
* values are 120, 240, 480, 960, 1920,
* and 2880.
* Passing in a duration of less than
* 10 ms (480 samples at 48 kHz) will
* prevent the encoder from using the LPC
* or hybrid modes.
* @param [out] data <tt>unsigned char*</tt>: Output payload.
* This must contain storage for at
* least \a max_data_bytes.
* @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
* memory for the output
* payload. This may be
* used to impose an upper limit on
* the instant bitrate, but should
* not be used as the only bitrate
* control. Use #OPUS_SET_BITRATE to
* control the bitrate.
* @returns The length of the encoded packet (in bytes) on success or a
* negative error code (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float(
OpusEncoder *st,
const float *pcm,
int frame_size,
unsigned char *data,
opus_int32 max_data_bytes
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
/** Frees an <code>OpusEncoder</code> allocated by opus_encoder_create().
* @param[in] st <tt>OpusEncoder*</tt>: State to be freed.
*/
OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st);
/** Perform a CTL function on an Opus encoder.
*
* Generally the request and subsequent arguments are generated
* by a convenience macro.
* @param st <tt>OpusEncoder*</tt>: Encoder state.
* @param request This and all remaining parameters should be replaced by one
* of the convenience macros in @ref opus_genericctls or
* @ref opus_encoderctls.
* @see opus_genericctls
* @see opus_encoderctls
*/
OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
/**@}*/
/** @defgroup opus_decoder Opus Decoder
* @{
*
* @brief This page describes the process and functions used to decode Opus.
*
* The decoding process also starts with creating a decoder
* state. This can be done with:
* @code
* int error;
* OpusDecoder *dec;
* dec = opus_decoder_create(Fs, channels, &error);
* @endcode
* where
* @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000
* @li channels is the number of channels (1 or 2)
* @li error will hold the error code in case of failure (or #OPUS_OK on success)
* @li the return value is a newly created decoder state to be used for decoding
*
* While opus_decoder_create() allocates memory for the state, it's also possible
* to initialize pre-allocated memory:
* @code
* int size;
* int error;
* OpusDecoder *dec;
* size = opus_decoder_get_size(channels);
* dec = malloc(size);
* error = opus_decoder_init(dec, Fs, channels);
* @endcode
* where opus_decoder_get_size() returns the required size for the decoder state. Note that
* future versions of this code may change the size, so no assuptions should be made about it.
*
* The decoder state is always continuous in memory and only a shallow copy is sufficient
* to copy it (e.g. memcpy())
*
* To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data:
* @code
* frame_size = opus_decode(dec, packet, len, decoded, max_size, 0);
* @endcode
* where
*
* @li packet is the byte array containing the compressed data
* @li len is the exact number of bytes contained in the packet
* @li decoded is the decoded audio data in opus_int16 (or float for opus_decode_float())
* @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array
*
* opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet.
* If that value is negative, then an error has occurred. This can occur if the packet is corrupted or if the audio
* buffer is too small to hold the decoded audio.
*
* Opus is a stateful codec with overlapping blocks and as a result Opus
* packets are not coded independently of each other. Packets must be
* passed into the decoder serially and in the correct order for a correct
* decode. Lost packets can be replaced with loss concealment by calling
* the decoder with a null pointer and zero length for the missing packet.
*
* A single codec state may only be accessed from a single thread at
* a time and any required locking must be performed by the caller. Separate
* streams must be decoded with separate decoder states and can be decoded
* in parallel unless the library was compiled with NONTHREADSAFE_PSEUDOSTACK
* defined.
*
*/
/** Opus decoder state.
* This contains the complete state of an Opus decoder.
* It is position independent and can be freely copied.
* @see opus_decoder_create,opus_decoder_init
*/
typedef struct OpusDecoder OpusDecoder;
/** Gets the size of an <code>OpusDecoder</code> structure.
* @param [in] channels <tt>int</tt>: Number of channels.
* This must be 1 or 2.
* @returns The size in bytes.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels);
/** Allocates and initializes a decoder state.
* @param [in] Fs <tt>opus_int32</tt>: Sample rate to decode at (Hz).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) to decode
* @param [out] error <tt>int*</tt>: #OPUS_OK Success or @ref opus_errorcodes
*
* Internally Opus stores data at 48000 Hz, so that should be the default
* value for Fs. However, the decoder can efficiently decode to buffers
* at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use
* data at the full sample rate, or knows the compressed data doesn't
* use the full frequency range, it can request decoding at a reduced
* rate. Likewise, the decoder is capable of filling in either mono or
* interleaved stereo pcm buffers, at the caller's request.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create(
opus_int32 Fs,
int channels,
int *error
);
/** Initializes a previously allocated decoder state.
* The state must be at least the size returned by opus_decoder_get_size().
* This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size
* To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state.
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate to decode to (Hz).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) to decode
* @retval #OPUS_OK Success or @ref opus_errorcodes
*/
OPUS_EXPORT int opus_decoder_init(
OpusDecoder *st,
opus_int32 Fs,
int channels
) OPUS_ARG_NONNULL(1);
/** Decode an Opus packet.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state
* @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indicate packet loss
* @param [in] len <tt>opus_int32</tt>: Number of bytes in payload*
* @param [out] pcm <tt>opus_int16*</tt>: Output signal (interleaved if 2 channels). length
* is frame_size*channels*sizeof(opus_int16)
* @param [in] frame_size Number of samples per channel of available space in \a pcm.
* If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will
* not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1),
* then frame_size needs to be exactly the duration of audio that is missing, otherwise the
* decoder will not be in the optimal state to decode the next incoming packet. For the PLC and
* FEC cases, frame_size <b>must</b> be a multiple of 2.5 ms.
* @param [in] decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band forward error correction data be
* decoded. If no such data is available, the frame is decoded as if it were lost.
* @returns Number of decoded samples or @ref opus_errorcodes
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(
OpusDecoder *st,
const unsigned char *data,
opus_int32 len,
opus_int16 *pcm,
int frame_size,
int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Decode an Opus packet with floating point output.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state
* @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indicate packet loss
* @param [in] len <tt>opus_int32</tt>: Number of bytes in payload
* @param [out] pcm <tt>float*</tt>: Output signal (interleaved if 2 channels). length
* is frame_size*channels*sizeof(float)
* @param [in] frame_size Number of samples per channel of available space in \a pcm.
* If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will
* not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1),
* then frame_size needs to be exactly the duration of audio that is missing, otherwise the
* decoder will not be in the optimal state to decode the next incoming packet. For the PLC and
* FEC cases, frame_size <b>must</b> be a multiple of 2.5 ms.
* @param [in] decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band forward error correction data be
* decoded. If no such data is available the frame is decoded as if it were lost.
* @returns Number of decoded samples or @ref opus_errorcodes
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float(
OpusDecoder *st,
const unsigned char *data,
opus_int32 len,
float *pcm,
int frame_size,
int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Perform a CTL function on an Opus decoder.
*
* Generally the request and subsequent arguments are generated
* by a convenience macro.
* @param st <tt>OpusDecoder*</tt>: Decoder state.
* @param request This and all remaining parameters should be replaced by one
* of the convenience macros in @ref opus_genericctls or
* @ref opus_decoderctls.
* @see opus_genericctls
* @see opus_decoderctls
*/
OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
/** Frees an <code>OpusDecoder</code> allocated by opus_decoder_create().
* @param[in] st <tt>OpusDecoder*</tt>: State to be freed.
*/
OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
/** Parse an opus packet into one or more frames.
* Opus_decode will perform this operation internally so most applications do
* not need to use this function.
* This function does not copy the frames, the returned pointers are pointers into
* the input packet.
* @param [in] data <tt>char*</tt>: Opus packet to be parsed
* @param [in] len <tt>opus_int32</tt>: size of data
* @param [out] out_toc <tt>char*</tt>: TOC pointer
* @param [out] frames <tt>char*[48]</tt> encapsulated frames
* @param [out] size <tt>short[48]</tt> sizes of the encapsulated frames
* @param [out] payload_offset <tt>int*</tt>: returns the position of the payload within the packet (in bytes)
* @returns number of frames
*/
OPUS_EXPORT int opus_packet_parse(
const unsigned char *data,
opus_int32 len,
unsigned char *out_toc,
const unsigned char *frames[48],
short size[48],
int *payload_offset
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Gets the bandwidth of an Opus packet.
* @param [in] data <tt>char*</tt>: Opus packet
* @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass)
* @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass)
* @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass)
* @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass)
* @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass)
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1);
/** Gets the number of samples per frame from an Opus packet.
* @param [in] data <tt>char*</tt>: Opus packet.
* This must contain at least one byte of
* data.
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate in Hz.
* This must be a multiple of 400, or
* inaccurate results will be returned.
* @returns Number of samples per frame.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1);
/** Gets the number of channels from an Opus packet.
* @param [in] data <tt>char*</tt>: Opus packet
* @returns Number of channels
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1);
/** Gets the number of frames in an Opus packet.
* @param [in] packet <tt>char*</tt>: Opus packet
* @param [in] len <tt>opus_int32</tt>: Length of packet
* @returns Number of frames
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1);
/** Gets the number of samples of an Opus packet.
* @param [in] packet <tt>char*</tt>: Opus packet
* @param [in] len <tt>opus_int32</tt>: Length of packet
* @param [in] Fs <tt>opus_int32</tt>: Sampling rate in Hz.
* This must be a multiple of 400, or
* inaccurate results will be returned.
* @returns Number of samples
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1);
/** Gets the number of samples of an Opus packet.
* @param [in] dec <tt>OpusDecoder*</tt>: Decoder state
* @param [in] packet <tt>char*</tt>: Opus packet
* @param [in] len <tt>opus_int32</tt>: Length of packet
* @returns Number of samples
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
/**@}*/
/** @defgroup opus_repacketizer Repacketizer
* @{
*
* The repacketizer can be used to merge multiple Opus packets into a single
* packet or alternatively to split Opus packets that have previously been
* merged. Splitting valid Opus packets is always guaranteed to succeed,
* whereas merging valid packets only succeeds if all frames have the same
* mode, bandwidth, and frame size, and when the total duration of the merged
* packet is no more than 120 ms.
* The repacketizer currently only operates on elementary Opus
* streams. It will not manipualte multistream packets successfully, except in
* the degenerate case where they consist of data from a single stream.
*
* The repacketizing process starts with creating a repacketizer state, either
* by calling opus_repacketizer_create() or by allocating the memory yourself,
* e.g.,
* @code
* OpusRepacketizer *rp;
* rp = (OpusRepacketizer*)malloc(opus_repacketizer_get_size());
* if (rp != NULL)
* opus_repacketizer_init(rp);
* @endcode
*
* Then the application should submit packets with opus_repacketizer_cat(),
* extract new packets with opus_repacketizer_out() or
* opus_repacketizer_out_range(), and then reset the state for the next set of
* input packets via opus_repacketizer_init().
*
* For example, to split a sequence of packets into individual frames:
* @code
* unsigned char *data;
* int len;
* while (get_next_packet(&data, &len))
* {
* unsigned char out[1276];
* opus_int32 out_len;
* int nb_frames;
* int err;
* int i;
* err = opus_repacketizer_cat(rp, data, len);
* if (err != OPUS_OK)
* {
* release_packet(data);
* return err;
* }
* nb_frames = opus_repacketizer_get_nb_frames(rp);
* for (i = 0; i < nb_frames; i++)
* {
* out_len = opus_repacketizer_out_range(rp, i, i+1, out, sizeof(out));
* if (out_len < 0)
* {
* release_packet(data);
* return (int)out_len;
* }
* output_next_packet(out, out_len);
* }
* opus_repacketizer_init(rp);
* release_packet(data);
* }
* @endcode
*
* Alternatively, to combine a sequence of frames into packets that each
* contain up to <code>TARGET_DURATION_MS</code> milliseconds of data:
* @code
* // The maximum number of packets with duration TARGET_DURATION_MS occurs
* // when the frame size is 2.5 ms, for a total of (TARGET_DURATION_MS*2/5)
* // packets.
* unsigned char *data[(TARGET_DURATION_MS*2/5)+1];
* opus_int32 len[(TARGET_DURATION_MS*2/5)+1];
* int nb_packets;
* unsigned char out[1277*(TARGET_DURATION_MS*2/2)];
* opus_int32 out_len;
* int prev_toc;
* nb_packets = 0;
* while (get_next_packet(data+nb_packets, len+nb_packets))
* {
* int nb_frames;
* int err;
* nb_frames = opus_packet_get_nb_frames(data[nb_packets], len[nb_packets]);
* if (nb_frames < 1)
* {
* release_packets(data, nb_packets+1);
* return nb_frames;
* }
* nb_frames += opus_repacketizer_get_nb_frames(rp);
* // If adding the next packet would exceed our target, or it has an
* // incompatible TOC sequence, output the packets we already have before
* // submitting it.
* // N.B., The nb_packets > 0 check ensures we've submitted at least one
* // packet since the last call to opus_repacketizer_init(). Otherwise a
* // single packet longer than TARGET_DURATION_MS would cause us to try to
* // output an (invalid) empty packet. It also ensures that prev_toc has
* // been set to a valid value. Additionally, len[nb_packets] > 0 is
* // guaranteed by the call to opus_packet_get_nb_frames() above, so the
* // reference to data[nb_packets][0] should be valid.
* if (nb_packets > 0 && (
* ((prev_toc & 0xFC) != (data[nb_packets][0] & 0xFC)) ||
* opus_packet_get_samples_per_frame(data[nb_packets], 48000)*nb_frames >
* TARGET_DURATION_MS*48))
* {
* out_len = opus_repacketizer_out(rp, out, sizeof(out));
* if (out_len < 0)
* {
* release_packets(data, nb_packets+1);
* return (int)out_len;
* }
* output_next_packet(out, out_len);
* opus_repacketizer_init(rp);
* release_packets(data, nb_packets);
* data[0] = data[nb_packets];
* len[0] = len[nb_packets];
* nb_packets = 0;
* }
* err = opus_repacketizer_cat(rp, data[nb_packets], len[nb_packets]);
* if (err != OPUS_OK)
* {
* release_packets(data, nb_packets+1);
* return err;
* }
* prev_toc = data[nb_packets][0];
* nb_packets++;
* }
* // Output the final, partial packet.
* if (nb_packets > 0)
* {
* out_len = opus_repacketizer_out(rp, out, sizeof(out));
* release_packets(data, nb_packets);
* if (out_len < 0)
* return (int)out_len;
* output_next_packet(out, out_len);
* }
* @endcode
*
* An alternate way of merging packets is to simply call opus_repacketizer_cat()
* unconditionally until it fails. At that point, the merged packet can be
* obtained with opus_repacketizer_out() and the input packet for which
* opus_repacketizer_cat() needs to be re-added to a newly reinitialized
* repacketizer state.
*/
typedef struct OpusRepacketizer OpusRepacketizer;
/** Gets the size of an <code>OpusRepacketizer</code> structure.
* @returns The size in bytes.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void);
/** (Re)initializes a previously allocated repacketizer state.
* The state must be at least the size returned by opus_repacketizer_get_size().
* This can be used for applications which use their own allocator instead of
* malloc().
* It must also be called to reset the queue of packets waiting to be
* repacketized, which is necessary if the maximum packet duration of 120 ms
* is reached or if you wish to submit packets with a different Opus
* configuration (coding mode, audio bandwidth, frame size, or channel count).
* Failure to do so will prevent a new packet from being added with
* opus_repacketizer_cat().
* @see opus_repacketizer_create
* @see opus_repacketizer_get_size
* @see opus_repacketizer_cat
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state to
* (re)initialize.
* @returns A pointer to the same repacketizer state that was passed in.
*/
OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
/** Allocates memory and initializes the new repacketizer with
* opus_repacketizer_init().
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void);
/** Frees an <code>OpusRepacketizer</code> allocated by
* opus_repacketizer_create().
* @param[in] rp <tt>OpusRepacketizer*</tt>: State to be freed.
*/
OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp);
/** Add a packet to the current repacketizer state.
* This packet must match the configuration of any packets already submitted
* for repacketization since the last call to opus_repacketizer_init().
* This means that it must have the same coding mode, audio bandwidth, frame
* size, and channel count.
* This can be checked in advance by examining the top 6 bits of the first
* byte of the packet, and ensuring they match the top 6 bits of the first
* byte of any previously submitted packet.
* The total duration of audio in the repacketizer state also must not exceed
* 120 ms, the maximum duration of a single packet, after adding this packet.
*
* The contents of the current repacketizer state can be extracted into new
* packets using opus_repacketizer_out() or opus_repacketizer_out_range().
*
* In order to add a packet with a different configuration or to add more
* audio beyond 120 ms, you must clear the repacketizer state by calling
* opus_repacketizer_init().
* If a packet is too large to add to the current repacketizer state, no part
* of it is added, even if it contains multiple frames, some of which might
* fit.
* If you wish to be able to add parts of such packets, you should first use
* another repacketizer to split the packet into pieces and add them
* individually.
* @see opus_repacketizer_out_range
* @see opus_repacketizer_out
* @see opus_repacketizer_init
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state to which to
* add the packet.
* @param[in] data <tt>const unsigned char*</tt>: The packet data.
* The application must ensure
* this pointer remains valid
* until the next call to
* opus_repacketizer_init() or
* opus_repacketizer_destroy().
* @param len <tt>opus_int32</tt>: The number of bytes in the packet data.
* @returns An error code indicating whether or not the operation succeeded.
* @retval #OPUS_OK The packet's contents have been added to the repacketizer
* state.
* @retval #OPUS_INVALID_PACKET The packet did not have a valid TOC sequence,
* the packet's TOC sequence was not compatible
* with previously submitted packets (because
* the coding mode, audio bandwidth, frame size,
* or channel count did not match), or adding
* this packet would increase the total amount of
* audio stored in the repacketizer state to more
* than 120 ms.
*/
OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
/** Construct a new packet from data previously submitted to the repacketizer
* state via opus_repacketizer_cat().
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state from which to
* construct the new packet.
* @param begin <tt>int</tt>: The index of the first frame in the current
* repacketizer state to include in the output.
* @param end <tt>int</tt>: One past the index of the last frame in the
* current repacketizer state to include in the
* output.
* @param[out] data <tt>const unsigned char*</tt>: The buffer in which to
* store the output packet.
* @param maxlen <tt>opus_int32</tt>: The maximum number of bytes to store in
* the output buffer. In order to guarantee
* success, this should be at least
* <code>1276</code> for a single frame,
* or for multiple frames,
* <code>1277*(end-begin)</code>.
* However, <code>1*(end-begin)</code> plus
* the size of all packet data submitted to
* the repacketizer since the last call to
* opus_repacketizer_init() or
* opus_repacketizer_create() is also
* sufficient, and possibly much smaller.
* @returns The total size of the output packet on success, or an error code
* on failure.
* @retval #OPUS_BAD_ARG <code>[begin,end)</code> was an invalid range of
* frames (begin < 0, begin >= end, or end >
* opus_repacketizer_get_nb_frames()).
* @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the
* complete output packet.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Return the total number of frames contained in packet data submitted to
* the repacketizer state so far via opus_repacketizer_cat() since the last
* call to opus_repacketizer_init() or opus_repacketizer_create().
* This defines the valid range of packets that can be extracted with
* opus_repacketizer_out_range() or opus_repacketizer_out().
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state containing the
* frames.
* @returns The total number of frames contained in the packet data submitted
* to the repacketizer state.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
/** Construct a new packet from data previously submitted to the repacketizer
* state via opus_repacketizer_cat().
* This is a convenience routine that returns all the data submitted so far
* in a single packet.
* It is equivalent to calling
* @code
* opus_repacketizer_out_range(rp, 0, opus_repacketizer_get_nb_frames(rp),
* data, maxlen)
* @endcode
* @param rp <tt>OpusRepacketizer*</tt>: The repacketizer state from which to
* construct the new packet.
* @param[out] data <tt>const unsigned char*</tt>: The buffer in which to
* store the output packet.
* @param maxlen <tt>opus_int32</tt>: The maximum number of bytes to store in
* the output buffer. In order to guarantee
* success, this should be at least
* <code>1277*opus_repacketizer_get_nb_frames(rp)</code>.
* However,
* <code>1*opus_repacketizer_get_nb_frames(rp)</code>
* plus the size of all packet data
* submitted to the repacketizer since the
* last call to opus_repacketizer_init() or
* opus_repacketizer_create() is also
* sufficient, and possibly much smaller.
* @returns The total size of the output packet on success, or an error code
* on failure.
* @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the
* complete output packet.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1);
/**@}*/
#ifdef __cplusplus
}
#endif
#endif /* OPUS_H */

View File

@ -0,0 +1,655 @@
/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
Written by Jean-Marc Valin and Koen Vos */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file opus_defines.h
* @brief Opus reference implementation constants
*/
#ifndef OPUS_DEFINES_H
#define OPUS_DEFINES_H
#include "opus_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup opus_errorcodes Error codes
* @{
*/
/** No error @hideinitializer*/
#define OPUS_OK 0
/** One or more invalid/out of range arguments @hideinitializer*/
#define OPUS_BAD_ARG -1
/** The mode struct passed is invalid @hideinitializer*/
#define OPUS_BUFFER_TOO_SMALL -2
/** An internal error was detected @hideinitializer*/
#define OPUS_INTERNAL_ERROR -3
/** The compressed data passed is corrupted @hideinitializer*/
#define OPUS_INVALID_PACKET -4
/** Invalid/unsupported request number @hideinitializer*/
#define OPUS_UNIMPLEMENTED -5
/** An encoder or decoder structure is invalid or already freed @hideinitializer*/
#define OPUS_INVALID_STATE -6
/** Memory allocation has failed @hideinitializer*/
#define OPUS_ALLOC_FAIL -7
/**@}*/
/** @cond OPUS_INTERNAL_DOC */
/**Export control for opus functions */
#ifndef OPUS_EXPORT
# if defined(__GNUC__) && defined(OPUS_BUILD)
# define OPUS_EXPORT __attribute__ ((visibility ("default")))
# elif defined(WIN32) && !defined(__MINGW32__)
# ifdef OPUS_BUILD
# define OPUS_EXPORT __declspec(dllexport)
# else
# define OPUS_EXPORT
# endif
# else
# define OPUS_EXPORT
# endif
#endif
# if !defined(OPUS_GNUC_PREREQ)
# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
# define OPUS_GNUC_PREREQ(_maj,_min) \
((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
# else
# define OPUS_GNUC_PREREQ(_maj,_min) 0
# endif
# endif
#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
# if OPUS_GNUC_PREREQ(3,0)
# define OPUS_RESTRICT __restrict__
# elif (defined(_MSC_VER) && _MSC_VER >= 1400)
# define OPUS_RESTRICT __restrict
# else
# define OPUS_RESTRICT
# endif
#else
# define OPUS_RESTRICT restrict
#endif
/**Warning attributes for opus functions
* NONNULL is not used in OPUS_BUILD to avoid the compiler optimizing out
* some paranoid null checks. */
#if defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4)
# define OPUS_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
#else
# define OPUS_WARN_UNUSED_RESULT
#endif
#if !defined(OPUS_BUILD) && defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4)
# define OPUS_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x)))
#else
# define OPUS_ARG_NONNULL(_x)
#endif
/** These are the actual Encoder CTL ID numbers.
* They should not be used directly by applications.
* In general, SETs should be even and GETs should be odd.*/
#define OPUS_SET_APPLICATION_REQUEST 4000
#define OPUS_GET_APPLICATION_REQUEST 4001
#define OPUS_SET_BITRATE_REQUEST 4002
#define OPUS_GET_BITRATE_REQUEST 4003
#define OPUS_SET_MAX_BANDWIDTH_REQUEST 4004
#define OPUS_GET_MAX_BANDWIDTH_REQUEST 4005
#define OPUS_SET_VBR_REQUEST 4006
#define OPUS_GET_VBR_REQUEST 4007
#define OPUS_SET_BANDWIDTH_REQUEST 4008
#define OPUS_GET_BANDWIDTH_REQUEST 4009
#define OPUS_SET_COMPLEXITY_REQUEST 4010
#define OPUS_GET_COMPLEXITY_REQUEST 4011
#define OPUS_SET_INBAND_FEC_REQUEST 4012
#define OPUS_GET_INBAND_FEC_REQUEST 4013
#define OPUS_SET_PACKET_LOSS_PERC_REQUEST 4014
#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 4015
#define OPUS_SET_DTX_REQUEST 4016
#define OPUS_GET_DTX_REQUEST 4017
#define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020
#define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021
#define OPUS_SET_FORCE_CHANNELS_REQUEST 4022
#define OPUS_GET_FORCE_CHANNELS_REQUEST 4023
#define OPUS_SET_SIGNAL_REQUEST 4024
#define OPUS_GET_SIGNAL_REQUEST 4025
#define OPUS_GET_LOOKAHEAD_REQUEST 4027
/* #define OPUS_RESET_STATE 4028 */
#define OPUS_GET_SAMPLE_RATE_REQUEST 4029
#define OPUS_GET_FINAL_RANGE_REQUEST 4031
#define OPUS_GET_PITCH_REQUEST 4033
#define OPUS_SET_GAIN_REQUEST 4034
#define OPUS_GET_GAIN_REQUEST 4045 /* Should have been 4035 */
#define OPUS_SET_LSB_DEPTH_REQUEST 4036
#define OPUS_GET_LSB_DEPTH_REQUEST 4037
#define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039
/* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */
/* Macros to trigger compilation errors when the wrong types are provided to a CTL */
#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
/** @endcond */
/** @defgroup opus_ctlvalues Pre-defined values for CTL interface
* @see opus_genericctls, opus_encoderctls
* @{
*/
/* Values for the various encoder CTLs */
#define OPUS_AUTO -1000 /**<Auto/default setting @hideinitializer*/
#define OPUS_BITRATE_MAX -1 /**<Maximum bitrate @hideinitializer*/
/** Best for most VoIP/videoconference applications where listening quality and intelligibility matter most
* @hideinitializer */
#define OPUS_APPLICATION_VOIP 2048
/** Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input
* @hideinitializer */
#define OPUS_APPLICATION_AUDIO 2049
/** Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used.
* @hideinitializer */
#define OPUS_APPLICATION_RESTRICTED_LOWDELAY 2051
#define OPUS_SIGNAL_VOICE 3001 /**< Signal being encoded is voice */
#define OPUS_SIGNAL_MUSIC 3002 /**< Signal being encoded is music */
#define OPUS_BANDWIDTH_NARROWBAND 1101 /**< 4 kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_MEDIUMBAND 1102 /**< 6 kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_WIDEBAND 1103 /**< 8 kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_SUPERWIDEBAND 1104 /**<12 kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_FULLBAND 1105 /**<20 kHz bandpass @hideinitializer*/
/**@}*/
/** @defgroup opus_encoderctls Encoder related CTLs
*
* These are convenience macros for use with the \c opus_encode_ctl
* interface. They are used to generate the appropriate series of
* arguments for that call, passing the correct type, size and so
* on as expected for each particular request.
*
* Some usage examples:
*
* @code
* int ret;
* ret = opus_encoder_ctl(enc_ctx, OPUS_SET_BANDWIDTH(OPUS_AUTO));
* if (ret != OPUS_OK) return ret;
*
* opus_int32 rate;
* opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&rate));
*
* opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE);
* @endcode
*
* @see opus_genericctls, opus_encoder
* @{
*/
/** Configures the encoder's computational complexity.
* The supported range is 0-10 inclusive with 10 representing the highest complexity.
* @see OPUS_GET_COMPLEXITY
* @param[in] x <tt>opus_int32</tt>: Allowed values: 0-10, inclusive.
*
* @hideinitializer */
#define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x)
/** Gets the encoder's complexity configuration.
* @see OPUS_SET_COMPLEXITY
* @param[out] x <tt>opus_int32 *</tt>: Returns a value in the range 0-10,
* inclusive.
* @hideinitializer */
#define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x)
/** Configures the bitrate in the encoder.
* Rates from 500 to 512000 bits per second are meaningful, as well as the
* special values #OPUS_AUTO and #OPUS_BITRATE_MAX.
* The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much
* rate as it can, which is useful for controlling the rate by adjusting the
* output buffer size.
* @see OPUS_GET_BITRATE
* @param[in] x <tt>opus_int32</tt>: Bitrate in bits per second. The default
* is determined based on the number of
* channels and the input sampling rate.
* @hideinitializer */
#define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x)
/** Gets the encoder's bitrate configuration.
* @see OPUS_SET_BITRATE
* @param[out] x <tt>opus_int32 *</tt>: Returns the bitrate in bits per second.
* The default is determined based on the
* number of channels and the input
* sampling rate.
* @hideinitializer */
#define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x)
/** Enables or disables variable bitrate (VBR) in the encoder.
* The configured bitrate may not be met exactly because frames must
* be an integer number of bytes in length.
* @warning Only the MDCT mode of Opus can provide hard CBR behavior.
* @see OPUS_GET_VBR
* @see OPUS_SET_VBR_CONSTRAINT
* @param[in] x <tt>opus_int32</tt>: Allowed values:
* <dl>
* <dt>0</dt><dd>Hard CBR. For LPC/hybrid modes at very low bit-rate, this can
* cause noticeable quality degradation.</dd>
* <dt>1</dt><dd>VBR (default). The exact type of VBR is controlled by
* #OPUS_SET_VBR_CONSTRAINT.</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x)
/** Determine if variable bitrate (VBR) is enabled in the encoder.
* @see OPUS_SET_VBR
* @see OPUS_GET_VBR_CONSTRAINT
* @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
* <dl>
* <dt>0</dt><dd>Hard CBR.</dd>
* <dt>1</dt><dd>VBR (default). The exact type of VBR may be retrieved via
* #OPUS_GET_VBR_CONSTRAINT.</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x)
/** Enables or disables constrained VBR in the encoder.
* This setting is ignored when the encoder is in CBR mode.
* @warning Only the MDCT mode of Opus currently heeds the constraint.
* Speech mode ignores it completely, hybrid mode may fail to obey it
* if the LPC layer uses more bitrate than the constraint would have
* permitted.
* @see OPUS_GET_VBR_CONSTRAINT
* @see OPUS_SET_VBR
* @param[in] x <tt>opus_int32</tt>: Allowed values:
* <dl>
* <dt>0</dt><dd>Unconstrained VBR.</dd>
* <dt>1</dt><dd>Constrained VBR (default). This creates a maximum of one
* frame of buffering delay assuming a transport with a
* serialization speed of the nominal bitrate.</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x)
/** Determine if constrained VBR is enabled in the encoder.
* @see OPUS_SET_VBR_CONSTRAINT
* @see OPUS_GET_VBR
* @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
* <dl>
* <dt>0</dt><dd>Unconstrained VBR.</dd>
* <dt>1</dt><dd>Constrained VBR (default).</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x)
/** Configures mono/stereo forcing in the encoder.
* This can force the encoder to produce packets encoded as either mono or
* stereo, regardless of the format of the input audio. This is useful when
* the caller knows that the input signal is currently a mono source embedded
* in a stereo stream.
* @see OPUS_GET_FORCE_CHANNELS
* @param[in] x <tt>opus_int32</tt>: Allowed values:
* <dl>
* <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd>
* <dt>1</dt> <dd>Forced mono</dd>
* <dt>2</dt> <dd>Forced stereo</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x)
/** Gets the encoder's forced channel configuration.
* @see OPUS_SET_FORCE_CHANNELS
* @param[out] x <tt>opus_int32 *</tt>:
* <dl>
* <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd>
* <dt>1</dt> <dd>Forced mono</dd>
* <dt>2</dt> <dd>Forced stereo</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x)
/** Configures the maximum bandpass that the encoder will select automatically.
* Applications should normally use this instead of #OPUS_SET_BANDWIDTH
* (leaving that set to the default, #OPUS_AUTO). This allows the
* application to set an upper bound based on the type of input it is
* providing, but still gives the encoder the freedom to reduce the bandpass
* when the bitrate becomes too low, for better overall quality.
* @see OPUS_GET_MAX_BANDWIDTH
* @param[in] x <tt>opus_int32</tt>: Allowed values:
* <dl>
* <dt>OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd>
* <dt>OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd>
* <dt>OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd>
* <dt>OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
* <dt>OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband (default)</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x)
/** Gets the encoder's configured maximum allowed bandpass.
* @see OPUS_SET_MAX_BANDWIDTH
* @param[out] x <tt>opus_int32 *</tt>: Allowed values:
* <dl>
* <dt>#OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband (default)</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
/** Sets the encoder's bandpass to a specific value.
* This prevents the encoder from automatically selecting the bandpass based
* on the available bitrate. If an application knows the bandpass of the input
* audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH
* instead, which still gives the encoder the freedom to reduce the bandpass
* when the bitrate becomes too low, for better overall quality.
* @see OPUS_GET_BANDWIDTH
* @param[in] x <tt>opus_int32</tt>: Allowed values:
* <dl>
* <dt>#OPUS_AUTO</dt> <dd>(default)</dd>
* <dt>#OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x)
/** Configures the type of signal being encoded.
* This is a hint which helps the encoder's mode selection.
* @see OPUS_GET_SIGNAL
* @param[in] x <tt>opus_int32</tt>: Allowed values:
* <dl>
* <dt>#OPUS_AUTO</dt> <dd>(default)</dd>
* <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd>
* <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x)
/** Gets the encoder's configured signal type.
* @see OPUS_SET_SIGNAL
* @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
* <dl>
* <dt>#OPUS_AUTO</dt> <dd>(default)</dd>
* <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd>
* <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x)
/** Configures the encoder's intended application.
* The initial value is a mandatory argument to the encoder_create function.
* @see OPUS_GET_APPLICATION
* @param[in] x <tt>opus_int32</tt>: Returns one of the following values:
* <dl>
* <dt>#OPUS_APPLICATION_VOIP</dt>
* <dd>Process signal for improved speech intelligibility.</dd>
* <dt>#OPUS_APPLICATION_AUDIO</dt>
* <dd>Favor faithfulness to the original input.</dd>
* <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
* <dd>Configure the minimum possible coding delay by disabling certain modes
* of operation.</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x)
/** Gets the encoder's configured application.
* @see OPUS_SET_APPLICATION
* @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
* <dl>
* <dt>#OPUS_APPLICATION_VOIP</dt>
* <dd>Process signal for improved speech intelligibility.</dd>
* <dt>#OPUS_APPLICATION_AUDIO</dt>
* <dd>Favor faithfulness to the original input.</dd>
* <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
* <dd>Configure the minimum possible coding delay by disabling certain modes
* of operation.</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x)
/** Gets the sampling rate the encoder or decoder was initialized with.
* This simply returns the <code>Fs</code> value passed to opus_encoder_init()
* or opus_decoder_init().
* @param[out] x <tt>opus_int32 *</tt>: Sampling rate of encoder or decoder.
* @hideinitializer
*/
#define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x)
/** Gets the total samples of delay added by the entire codec.
* This can be queried by the encoder and then the provided number of samples can be
* skipped on from the start of the decoder's output to provide time aligned input
* and output. From the perspective of a decoding application the real data begins this many
* samples late.
*
* The decoder contribution to this delay is identical for all decoders, but the
* encoder portion of the delay may vary from implementation to implementation,
* version to version, or even depend on the encoder's initial configuration.
* Applications needing delay compensation should call this CTL rather than
* hard-coding a value.
* @param[out] x <tt>opus_int32 *</tt>: Number of lookahead samples
* @hideinitializer */
#define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x)
/** Configures the encoder's use of inband forward error correction (FEC).
* @note This is only applicable to the LPC layer
* @see OPUS_GET_INBAND_FEC
* @param[in] x <tt>opus_int32</tt>: Allowed values:
* <dl>
* <dt>0</dt><dd>Disable inband FEC (default).</dd>
* <dt>1</dt><dd>Enable inband FEC.</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x)
/** Gets encoder's configured use of inband forward error correction.
* @see OPUS_SET_INBAND_FEC
* @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
* <dl>
* <dt>0</dt><dd>Inband FEC disabled (default).</dd>
* <dt>1</dt><dd>Inband FEC enabled.</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x)
/** Configures the encoder's expected packet loss percentage.
* Higher values with trigger progressively more loss resistant behavior in the encoder
* at the expense of quality at a given bitrate in the lossless case, but greater quality
* under loss.
* @see OPUS_GET_PACKET_LOSS_PERC
* @param[in] x <tt>opus_int32</tt>: Loss percentage in the range 0-100, inclusive (default: 0).
* @hideinitializer */
#define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x)
/** Gets the encoder's configured packet loss percentage.
* @see OPUS_SET_PACKET_LOSS_PERC
* @param[out] x <tt>opus_int32 *</tt>: Returns the configured loss percentage
* in the range 0-100, inclusive (default: 0).
* @hideinitializer */
#define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x)
/** Configures the encoder's use of discontinuous transmission (DTX).
* @note This is only applicable to the LPC layer
* @see OPUS_GET_DTX
* @param[in] x <tt>opus_int32</tt>: Allowed values:
* <dl>
* <dt>0</dt><dd>Disable DTX (default).</dd>
* <dt>1</dt><dd>Enabled DTX.</dd>
* </dl>
* @hideinitializer */
#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x)
/** Gets encoder's configured use of discontinuous transmission.
* @see OPUS_SET_DTX
* @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
* <dl>
* <dt>0</dt><dd>DTX disabled (default).</dd>
* <dt>1</dt><dd>DTX enabled.</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x)
/** Configures the depth of signal being encoded.
* This is a hint which helps the encoder identify silence and near-silence.
* @see OPUS_GET_LSB_DEPTH
* @param[in] x <tt>opus_int32</tt>: Input precision in bits, between 8 and 24
* (default: 24).
* @hideinitializer */
#define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x)
/** Gets the encoder's configured signal depth.
* @see OPUS_SET_LSB_DEPTH
* @param[out] x <tt>opus_int32 *</tt>: Input precision in bits, between 8 and
* 24 (default: 24).
* @hideinitializer */
#define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x)
/** Gets the duration (in samples) of the last packet successfully decoded or concealed.
* @param[out] x <tt>opus_int32 *</tt>: Number of samples (at current sampling rate).
* @hideinitializer */
#define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x)
/**@}*/
/** @defgroup opus_genericctls Generic CTLs
*
* These macros are used with the \c opus_decoder_ctl and
* \c opus_encoder_ctl calls to generate a particular
* request.
*
* When called on an \c OpusDecoder they apply to that
* particular decoder instance. When called on an
* \c OpusEncoder they apply to the corresponding setting
* on that encoder instance, if present.
*
* Some usage examples:
*
* @code
* int ret;
* opus_int32 pitch;
* ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch));
* if (ret == OPUS_OK) return ret;
*
* opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE);
* opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE);
*
* opus_int32 enc_bw, dec_bw;
* opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw));
* opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw));
* if (enc_bw != dec_bw) {
* printf("packet bandwidth mismatch!\n");
* }
* @endcode
*
* @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls
* @{
*/
/** Resets the codec state to be equivalent to a freshly initialized state.
* This should be called when switching streams in order to prevent
* the back to back decoding from giving different results from
* one at a time decoding.
* @hideinitializer */
#define OPUS_RESET_STATE 4028
/** Gets the final state of the codec's entropy coder.
* This is used for testing purposes,
* The encoder and decoder state should be identical after coding a payload
* (assuming no data corruption or software bugs)
*
* @param[out] x <tt>opus_uint32 *</tt>: Entropy coder state
*
* @hideinitializer */
#define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x)
/** Gets the pitch of the last decoded frame, if available.
* This can be used for any post-processing algorithm requiring the use of pitch,
* e.g. time stretching/shortening. If the last frame was not voiced, or if the
* pitch was not coded in the frame, then zero is returned.
*
* This CTL is only implemented for decoder instances.
*
* @param[out] x <tt>opus_int32 *</tt>: pitch period at 48 kHz (or 0 if not available)
*
* @hideinitializer */
#define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x)
/** Gets the encoder's configured bandpass or the decoder's last bandpass.
* @see OPUS_SET_BANDWIDTH
* @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
* <dl>
* <dt>#OPUS_AUTO</dt> <dd>(default)</dd>
* <dt>#OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
* <dt>#OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband</dd>
* </dl>
* @hideinitializer */
#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
/**@}*/
/** @defgroup opus_decoderctls Decoder related CTLs
* @see opus_genericctls, opus_encoderctls, opus_decoder
* @{
*/
/** Configures decoder gain adjustment.
* Scales the decoded output by a factor specified in Q8 dB units.
* This has a maximum range of -32768 to 32767 inclusive, and returns
* OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment.
* This setting survives decoder reset.
*
* gain = pow(10, x/(20.0*256))
*
* @param[in] x <tt>opus_int32</tt>: Amount to scale PCM signal by in Q8 dB units.
* @hideinitializer */
#define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x)
/** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN
*
* @param[out] x <tt>opus_int32 *</tt>: Amount to scale PCM signal by in Q8 dB units.
* @hideinitializer */
#define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x)
/**@}*/
/** @defgroup opus_libinfo Opus library information functions
* @{
*/
/** Converts an opus error code into a human readable string.
*
* @param[in] error <tt>int</tt>: Error number
* @returns Error string
*/
OPUS_EXPORT const char *opus_strerror(int error);
/** Gets the libopus version string.
*
* @returns Version string
*/
OPUS_EXPORT const char *opus_get_version_string(void);
/**@}*/
#ifdef __cplusplus
}
#endif
#endif /* OPUS_DEFINES_H */

View File

@ -0,0 +1,632 @@
/* Copyright (c) 2011 Xiph.Org Foundation
Written by Jean-Marc Valin */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file opus_multistream.h
* @brief Opus reference implementation multistream API
*/
#ifndef OPUS_MULTISTREAM_H
#define OPUS_MULTISTREAM_H
#include "opus.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @cond OPUS_INTERNAL_DOC */
/** Macros to trigger compilation errors when the wrong types are provided to a
* CTL. */
/**@{*/
#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr)))
#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr)))
/**@}*/
/** These are the actual encoder and decoder CTL ID numbers.
* They should not be used directly by applications.
* In general, SETs should be even and GETs should be odd.*/
/**@{*/
#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120
#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122
/**@}*/
/** @endcond */
/** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs
*
* These are convenience macros that are specific to the
* opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl()
* interface.
* The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and
* @ref opus_decoderctls may be applied to a multistream encoder or decoder as
* well.
* In addition, you may retrieve the encoder or decoder state for an specific
* stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or
* #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually.
*/
/**@{*/
/** Gets the encoder state for an individual stream of a multistream encoder.
* @param[in] x <tt>opus_int32</tt>: The index of the stream whose encoder you
* wish to retrieve.
* This must be non-negative and less than
* the <code>streams</code> parameter used
* to initialize the encoder.
* @param[out] y <tt>OpusEncoder**</tt>: Returns a pointer to the given
* encoder state.
* @retval OPUS_BAD_ARG The index of the requested stream was out of range.
* @hideinitializer
*/
#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y)
/** Gets the decoder state for an individual stream of a multistream decoder.
* @param[in] x <tt>opus_int32</tt>: The index of the stream whose decoder you
* wish to retrieve.
* This must be non-negative and less than
* the <code>streams</code> parameter used
* to initialize the decoder.
* @param[out] y <tt>OpusDecoder**</tt>: Returns a pointer to the given
* decoder state.
* @retval OPUS_BAD_ARG The index of the requested stream was out of range.
* @hideinitializer
*/
#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y)
/**@}*/
/** @defgroup opus_multistream Opus Multistream API
* @{
*
* The multistream API allows individual Opus streams to be combined into a
* single packet, enabling support for up to 255 channels. Unlike an
* elementary Opus stream, the encoder and decoder must negotiate the channel
* configuration before the decoder can successfully interpret the data in the
* packets produced by the encoder. Some basic information, such as packet
* duration, can be computed without any special negotiation.
*
* The format for multistream Opus packets is defined in the
* <a href="http://tools.ietf.org/html/draft-terriberry-oggopus">Ogg
* encapsulation specification</a> and is based on the self-delimited Opus
* framing described in Appendix B of <a href="http://tools.ietf.org/html/rfc6716">RFC 6716</a>.
* Normal Opus packets are just a degenerate case of multistream Opus packets,
* and can be encoded or decoded with the multistream API by setting
* <code>streams</code> to <code>1</code> when initializing the encoder or
* decoder.
*
* Multistream Opus streams can contain up to 255 elementary Opus streams.
* These may be either "uncoupled" or "coupled", indicating that the decoder
* is configured to decode them to either 1 or 2 channels, respectively.
* The streams are ordered so that all coupled streams appear at the
* beginning.
*
* A <code>mapping</code> table defines which decoded channel <code>i</code>
* should be used for each input/output (I/O) channel <code>j</code>. This table is
* typically provided as an unsigned char array.
* Let <code>i = mapping[j]</code> be the index for I/O channel <code>j</code>.
* If <code>i < 2*coupled_streams</code>, then I/O channel <code>j</code> is
* encoded as the left channel of stream <code>(i/2)</code> if <code>i</code>
* is even, or as the right channel of stream <code>(i/2)</code> if
* <code>i</code> is odd. Otherwise, I/O channel <code>j</code> is encoded as
* mono in stream <code>(i - coupled_streams)</code>, unless it has the special
* value 255, in which case it is omitted from the encoding entirely (the
* decoder will reproduce it as silence). Each value <code>i</code> must either
* be the special value 255 or be less than <code>streams + coupled_streams</code>.
*
* The output channels specified by the encoder
* should use the
* <a href="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.9">Vorbis
* channel ordering</a>. A decoder may wish to apply an additional permutation
* to the mapping the encoder used to achieve a different output channel
* order (e.g. for outputing in WAV order).
*
* Each multistream packet contains an Opus packet for each stream, and all of
* the Opus packets in a single multistream packet must have the same
* duration. Therefore the duration of a multistream packet can be extracted
* from the TOC sequence of the first stream, which is located at the
* beginning of the packet, just like an elementary Opus stream:
*
* @code
* int nb_samples;
* int nb_frames;
* nb_frames = opus_packet_get_nb_frames(data, len);
* if (nb_frames < 1)
* return nb_frames;
* nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames;
* @endcode
*
* The general encoding and decoding process proceeds exactly the same as in
* the normal @ref opus_encoder and @ref opus_decoder APIs.
* See their documentation for an overview of how to use the corresponding
* multistream functions.
*/
/** Opus multistream encoder state.
* This contains the complete state of a multistream Opus encoder.
* It is position independent and can be freely copied.
* @see opus_multistream_encoder_create
* @see opus_multistream_encoder_init
*/
typedef struct OpusMSEncoder OpusMSEncoder;
/** Opus multistream decoder state.
* This contains the complete state of a multistream Opus decoder.
* It is position independent and can be freely copied.
* @see opus_multistream_decoder_create
* @see opus_multistream_decoder_init
*/
typedef struct OpusMSDecoder OpusMSDecoder;
/**\name Multistream encoder functions */
/**@{*/
/** Gets the size of an OpusMSEncoder structure.
* @param streams <tt>int</tt>: The total number of streams to encode from the
* input.
* This must be no more than 255.
* @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
* to encode.
* This must be no larger than the total
* number of streams.
* Additionally, The total number of
* encoded channels (<code>streams +
* coupled_streams</code>) must be no
* more than 255.
* @returns The size in bytes on success, or a negative error code
* (see @ref opus_errorcodes) on error.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size(
int streams,
int coupled_streams
);
/** Allocates and initializes a multistream encoder state.
* Call opus_multistream_encoder_destroy() to release
* this object when finished.
* @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param channels <tt>int</tt>: Number of channels in the input signal.
* This must be at most 255.
* It may be greater than the number of
* coded channels (<code>streams +
* coupled_streams</code>).
* @param streams <tt>int</tt>: The total number of streams to encode from the
* input.
* This must be no more than the number of channels.
* @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
* to encode.
* This must be no larger than the total
* number of streams.
* Additionally, The total number of
* encoded channels (<code>streams +
* coupled_streams</code>) must be no
* more than the number of input channels.
* @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
* encoded channels to input channels, as described in
* @ref opus_multistream. As an extra constraint, the
* multistream encoder does not allow encoding coupled
* streams for which one channel is unused since this
* is never a good idea.
* @param application <tt>int</tt>: The target encoder application.
* This must be one of the following:
* <dl>
* <dt>#OPUS_APPLICATION_VOIP</dt>
* <dd>Process signal for improved speech intelligibility.</dd>
* <dt>#OPUS_APPLICATION_AUDIO</dt>
* <dd>Favor faithfulness to the original input.</dd>
* <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
* <dd>Configure the minimum possible coding delay by disabling certain modes
* of operation.</dd>
* </dl>
* @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
* code (see @ref opus_errorcodes) on
* failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create(
opus_int32 Fs,
int channels,
int streams,
int coupled_streams,
const unsigned char *mapping,
int application,
int *error
) OPUS_ARG_NONNULL(5);
/** Initialize a previously allocated multistream encoder state.
* The memory pointed to by \a st must be at least the size returned by
* opus_multistream_encoder_get_size().
* This is intended for applications which use their own allocator instead of
* malloc.
* To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
* @see opus_multistream_encoder_create
* @see opus_multistream_encoder_get_size
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
* @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param channels <tt>int</tt>: Number of channels in the input signal.
* This must be at most 255.
* It may be greater than the number of
* coded channels (<code>streams +
* coupled_streams</code>).
* @param streams <tt>int</tt>: The total number of streams to encode from the
* input.
* This must be no more than the number of channels.
* @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
* to encode.
* This must be no larger than the total
* number of streams.
* Additionally, The total number of
* encoded channels (<code>streams +
* coupled_streams</code>) must be no
* more than the number of input channels.
* @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
* encoded channels to input channels, as described in
* @ref opus_multistream. As an extra constraint, the
* multistream encoder does not allow encoding coupled
* streams for which one channel is unused since this
* is never a good idea.
* @param application <tt>int</tt>: The target encoder application.
* This must be one of the following:
* <dl>
* <dt>#OPUS_APPLICATION_VOIP</dt>
* <dd>Process signal for improved speech intelligibility.</dd>
* <dt>#OPUS_APPLICATION_AUDIO</dt>
* <dd>Favor faithfulness to the original input.</dd>
* <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
* <dd>Configure the minimum possible coding delay by disabling certain modes
* of operation.</dd>
* </dl>
* @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
* on failure.
*/
OPUS_EXPORT int opus_multistream_encoder_init(
OpusMSEncoder *st,
opus_int32 Fs,
int channels,
int streams,
int coupled_streams,
const unsigned char *mapping,
int application
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
/** Encodes a multistream Opus frame.
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
* @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interleaved
* samples.
* This must contain
* <code>frame_size*channels</code>
* samples.
* @param frame_size <tt>int</tt>: Number of samples per channel in the input
* signal.
* This must be an Opus frame size for the
* encoder's sampling rate.
* For example, at 48 kHz the permitted values
* are 120, 240, 480, 960, 1920, and 2880.
* Passing in a duration of less than 10 ms
* (480 samples at 48 kHz) will prevent the
* encoder from using the LPC or hybrid modes.
* @param[out] data <tt>unsigned char*</tt>: Output payload.
* This must contain storage for at
* least \a max_data_bytes.
* @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
* memory for the output
* payload. This may be
* used to impose an upper limit on
* the instant bitrate, but should
* not be used as the only bitrate
* control. Use #OPUS_SET_BITRATE to
* control the bitrate.
* @returns The length of the encoded packet (in bytes) on success or a
* negative error code (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
OpusMSEncoder *st,
const opus_int16 *pcm,
int frame_size,
unsigned char *data,
opus_int32 max_data_bytes
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
/** Encodes a multistream Opus frame from floating point input.
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
* @param[in] pcm <tt>const float*</tt>: The input signal as interleaved
* samples with a normal range of
* +/-1.0.
* Samples with a range beyond +/-1.0
* are supported but will be clipped by
* decoders using the integer API and
* should only be used if it is known
* that the far end supports extended
* dynamic range.
* This must contain
* <code>frame_size*channels</code>
* samples.
* @param frame_size <tt>int</tt>: Number of samples per channel in the input
* signal.
* This must be an Opus frame size for the
* encoder's sampling rate.
* For example, at 48 kHz the permitted values
* are 120, 240, 480, 960, 1920, and 2880.
* Passing in a duration of less than 10 ms
* (480 samples at 48 kHz) will prevent the
* encoder from using the LPC or hybrid modes.
* @param[out] data <tt>unsigned char*</tt>: Output payload.
* This must contain storage for at
* least \a max_data_bytes.
* @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
* memory for the output
* payload. This may be
* used to impose an upper limit on
* the instant bitrate, but should
* not be used as the only bitrate
* control. Use #OPUS_SET_BITRATE to
* control the bitrate.
* @returns The length of the encoded packet (in bytes) on success or a
* negative error code (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
OpusMSEncoder *st,
const float *pcm,
int frame_size,
unsigned char *data,
opus_int32 max_data_bytes
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
/** Frees an <code>OpusMSEncoder</code> allocated by
* opus_multistream_encoder_create().
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be freed.
*/
OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
/** Perform a CTL function on a multistream Opus encoder.
*
* Generally the request and subsequent arguments are generated by a
* convenience macro.
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
* @param request This and all remaining parameters should be replaced by one
* of the convenience macros in @ref opus_genericctls,
* @ref opus_encoderctls, or @ref opus_multistream_ctls.
* @see opus_genericctls
* @see opus_encoderctls
* @see opus_multistream_ctls
*/
OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
/**@}*/
/**\name Multistream decoder functions */
/**@{*/
/** Gets the size of an <code>OpusMSDecoder</code> structure.
* @param streams <tt>int</tt>: The total number of streams coded in the
* input.
* This must be no more than 255.
* @param coupled_streams <tt>int</tt>: Number streams to decode as coupled
* (2 channel) streams.
* This must be no larger than the total
* number of streams.
* Additionally, The total number of
* coded channels (<code>streams +
* coupled_streams</code>) must be no
* more than 255.
* @returns The size in bytes on success, or a negative error code
* (see @ref opus_errorcodes) on error.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size(
int streams,
int coupled_streams
);
/** Allocates and initializes a multistream decoder state.
* Call opus_multistream_decoder_destroy() to release
* this object when finished.
* @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param channels <tt>int</tt>: Number of channels to output.
* This must be at most 255.
* It may be different from the number of coded
* channels (<code>streams +
* coupled_streams</code>).
* @param streams <tt>int</tt>: The total number of streams coded in the
* input.
* This must be no more than 255.
* @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
* (2 channel) streams.
* This must be no larger than the total
* number of streams.
* Additionally, The total number of
* coded channels (<code>streams +
* coupled_streams</code>) must be no
* more than 255.
* @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
* coded channels to output channels, as described in
* @ref opus_multistream.
* @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
* code (see @ref opus_errorcodes) on
* failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create(
opus_int32 Fs,
int channels,
int streams,
int coupled_streams,
const unsigned char *mapping,
int *error
) OPUS_ARG_NONNULL(5);
/** Intialize a previously allocated decoder state object.
* The memory pointed to by \a st must be at least the size returned by
* opus_multistream_encoder_get_size().
* This is intended for applications which use their own allocator instead of
* malloc.
* To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
* @see opus_multistream_decoder_create
* @see opus_multistream_deocder_get_size
* @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
* @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param channels <tt>int</tt>: Number of channels to output.
* This must be at most 255.
* It may be different from the number of coded
* channels (<code>streams +
* coupled_streams</code>).
* @param streams <tt>int</tt>: The total number of streams coded in the
* input.
* This must be no more than 255.
* @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
* (2 channel) streams.
* This must be no larger than the total
* number of streams.
* Additionally, The total number of
* coded channels (<code>streams +
* coupled_streams</code>) must be no
* more than 255.
* @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
* coded channels to output channels, as described in
* @ref opus_multistream.
* @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
* on failure.
*/
OPUS_EXPORT int opus_multistream_decoder_init(
OpusMSDecoder *st,
opus_int32 Fs,
int channels,
int streams,
int coupled_streams,
const unsigned char *mapping
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
/** Decode a multistream Opus packet.
* @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
* @param[in] data <tt>const unsigned char*</tt>: Input payload.
* Use a <code>NULL</code>
* pointer to indicate packet
* loss.
* @param len <tt>opus_int32</tt>: Number of bytes in payload.
* @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
* samples.
* This must contain room for
* <code>frame_size*channels</code>
* samples.
* @param frame_size <tt>int</tt>: The number of samples per channel of
* available space in \a pcm.
* If this is less than the maximum packet duration
* (120 ms; 5760 for 48kHz), this function will not be capable
* of decoding some packets. In the case of PLC (data==NULL)
* or FEC (decode_fec=1), then frame_size needs to be exactly
* the duration of audio that is missing, otherwise the
* decoder will not be in the optimal state to decode the
* next incoming packet. For the PLC and FEC cases, frame_size
* <b>must</b> be a multiple of 2.5 ms.
* @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
* forward error correction data be decoded.
* If no such data is available, the frame is
* decoded as if it were lost.
* @returns Number of samples decoded on success or a negative error code
* (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
OpusMSDecoder *st,
const unsigned char *data,
opus_int32 len,
opus_int16 *pcm,
int frame_size,
int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Decode a multistream Opus packet with floating point output.
* @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
* @param[in] data <tt>const unsigned char*</tt>: Input payload.
* Use a <code>NULL</code>
* pointer to indicate packet
* loss.
* @param len <tt>opus_int32</tt>: Number of bytes in payload.
* @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
* samples.
* This must contain room for
* <code>frame_size*channels</code>
* samples.
* @param frame_size <tt>int</tt>: The number of samples per channel of
* available space in \a pcm.
* If this is less than the maximum packet duration
* (120 ms; 5760 for 48kHz), this function will not be capable
* of decoding some packets. In the case of PLC (data==NULL)
* or FEC (decode_fec=1), then frame_size needs to be exactly
* the duration of audio that is missing, otherwise the
* decoder will not be in the optimal state to decode the
* next incoming packet. For the PLC and FEC cases, frame_size
* <b>must</b> be a multiple of 2.5 ms.
* @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
* forward error correction data be decoded.
* If no such data is available, the frame is
* decoded as if it were lost.
* @returns Number of samples decoded on success or a negative error code
* (see @ref opus_errorcodes) on failure.
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
OpusMSDecoder *st,
const unsigned char *data,
opus_int32 len,
float *pcm,
int frame_size,
int decode_fec
) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
/** Perform a CTL function on a multistream Opus decoder.
*
* Generally the request and subsequent arguments are generated by a
* convenience macro.
* @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
* @param request This and all remaining parameters should be replaced by one
* of the convenience macros in @ref opus_genericctls,
* @ref opus_decoderctls, or @ref opus_multistream_ctls.
* @see opus_genericctls
* @see opus_decoderctls
* @see opus_multistream_ctls
*/
OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
/** Frees an <code>OpusMSDecoder</code> allocated by
* opus_multistream_decoder_create().
* @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed.
*/
OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
/**@}*/
/**@}*/
#ifdef __cplusplus
}
#endif
#endif /* OPUS_MULTISTREAM_H */

View File

@ -0,0 +1,159 @@
/* (C) COPYRIGHT 1994-2002 Xiph.Org Foundation */
/* Modified by Jean-Marc Valin */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* opus_types.h based on ogg_types.h from libogg */
/**
@file opus_types.h
@brief Opus reference implementation types
*/
#ifndef OPUS_TYPES_H
#define OPUS_TYPES_H
/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */
#if (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H))
#include <stdint.h>
typedef int16_t opus_int16;
typedef uint16_t opus_uint16;
typedef int32_t opus_int32;
typedef uint32_t opus_uint32;
#elif defined(_WIN32)
# if defined(__CYGWIN__)
# include <_G_config.h>
typedef _G_int32_t opus_int32;
typedef _G_uint32_t opus_uint32;
typedef _G_int16 opus_int16;
typedef _G_uint16 opus_uint16;
# elif defined(__MINGW32__)
typedef short opus_int16;
typedef unsigned short opus_uint16;
typedef int opus_int32;
typedef unsigned int opus_uint32;
# elif defined(__MWERKS__)
typedef int opus_int32;
typedef unsigned int opus_uint32;
typedef short opus_int16;
typedef unsigned short opus_uint16;
# else
/* MSVC/Borland */
typedef __int32 opus_int32;
typedef unsigned __int32 opus_uint32;
typedef __int16 opus_int16;
typedef unsigned __int16 opus_uint16;
# endif
#elif defined(__MACOS__)
# include <sys/types.h>
typedef SInt16 opus_int16;
typedef UInt16 opus_uint16;
typedef SInt32 opus_int32;
typedef UInt32 opus_uint32;
#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */
# include <sys/types.h>
typedef int16_t opus_int16;
typedef u_int16_t opus_uint16;
typedef int32_t opus_int32;
typedef u_int32_t opus_uint32;
#elif defined(__BEOS__)
/* Be */
# include <inttypes.h>
typedef int16 opus_int16;
typedef u_int16 opus_uint16;
typedef int32_t opus_int32;
typedef u_int32_t opus_uint32;
#elif defined (__EMX__)
/* OS/2 GCC */
typedef short opus_int16;
typedef unsigned short opus_uint16;
typedef int opus_int32;
typedef unsigned int opus_uint32;
#elif defined (DJGPP)
/* DJGPP */
typedef short opus_int16;
typedef unsigned short opus_uint16;
typedef int opus_int32;
typedef unsigned int opus_uint32;
#elif defined(R5900)
/* PS2 EE */
typedef int opus_int32;
typedef unsigned opus_uint32;
typedef short opus_int16;
typedef unsigned short opus_uint16;
#elif defined(__SYMBIAN32__)
/* Symbian GCC */
typedef signed short opus_int16;
typedef unsigned short opus_uint16;
typedef signed int opus_int32;
typedef unsigned int opus_uint32;
#elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
typedef short opus_int16;
typedef unsigned short opus_uint16;
typedef long opus_int32;
typedef unsigned long opus_uint32;
#elif defined(CONFIG_TI_C6X)
typedef short opus_int16;
typedef unsigned short opus_uint16;
typedef int opus_int32;
typedef unsigned int opus_uint32;
#else
/* Give up, take a reasonable guess */
typedef short opus_int16;
typedef unsigned short opus_uint16;
typedef int opus_int32;
typedef unsigned int opus_uint32;
#endif
#define opus_int int /* used for counters etc; at least 16 bits */
#define opus_int64 long long
#define opus_int8 signed char
#define opus_uint unsigned int /* used for counters etc; at least 16 bits */
#define opus_uint64 unsigned long long
#define opus_uint8 unsigned char
#endif /* OPUS_TYPES_H */

View File

@ -32,6 +32,10 @@ libtinyDAV_la_LIBADD += -lyuv
libtinyDAV_la_CPPFLAGS += -I${LIBYUV_INCLUDE} -I${LIBYUV_INCLUDE}/libyuv
endif
if USE_OPUS
libtinyDAV_la_LIBADD += ${LIBOPUS_LIBADD}
endif
if USE_AMR
libtinyDAV_la_LIBADD += ${LIBAMR_LIBADD}
endif
@ -87,6 +91,8 @@ libtinyDAV_la_SOURCES += src/msrp/tdav_consumer_msrp.c \
libtinyDAV_la_SOURCES += src/codecs/amr/tdav_codec_amr.c
libtinyDAV_la_SOURCES += src/codecs/opus/tdav_codec_opus.c
libtinyDAV_la_SOURCES += src/codecs/g711/g711.c \
src/codecs/g711/tdav_codec_g711.c

View File

@ -57,6 +57,14 @@ else
VPX_CFLAGS := -DHAVE_LIBVPX=0
endif
# OPUS (Default: enabled)
ifeq ($(OPUS), no)
OPUS_CFLAGS := -DHAVE_LIBOPUS=0
else
OPUS_CFLAGS := -DHAVE_LIBOPUS=1
OPUS_LDFLAGS := -lopus
endif
# AMR (Default: enabled)
ifeq ($(OPENCORE_AMR), no)
OPENCORE_AMR_CFLAGS := -DHAVE_OPENCORE_AMR=0
@ -159,13 +167,13 @@ endif
################################
CFLAGS := $(CFLAGS_LIB) -I$(THIRDPARTIES_INC) -I$(THIRDPARTIES_INC_COMMON) $(ILBC_CFLAGS) $(LIBGSM_CFLAGS) \
$(FFMPEG_CFLAGS) $(LIBYUV_CFLAGS) $(VPX_CFLAGS) $(SPEEX_CFLAGS) $(SPEEX_DSP_CFLAGS) $(WEBRTC_CFLAGS) $(OPENCORE_AMR_CFLAGS) $(BV16_CFLAGS) $(G729_CFLAGS) \
$(FFMPEG_CFLAGS) $(LIBYUV_CFLAGS) $(VPX_CFLAGS) $(SPEEX_CFLAGS) $(SPEEX_DSP_CFLAGS) $(WEBRTC_CFLAGS) $(OPUS_CFLAGS) $(OPENCORE_AMR_CFLAGS) $(BV16_CFLAGS) $(G729_CFLAGS) \
$(LIBSRTP_CFLAGS) \
-I../tinySAK/src -I../tinyNET/src -I../tinySDP/include -I../tinyRTP/include -I../tinyMEDIA/include -I../tinyMSRP/include -I./include \
-DJB_HISTORY_SIZE=500
LDFLAGS := $(LDFLAGS_LIB) -L$(THIRDPARTIES_LIB) -L$(THIRDPARTIES_MARCH_LIB) \
$(FFMPEG_LDFLAGS) $(LIBYUV_LDFLAGS) $(VPX_LDFLAGS) $(SPEEX_LDFLAGS) $(SPEEX_DSP_LDFLAGS) $(WEBRTC_LDFLAGS) $(OPENCORE_AMR_LDFLAGS) $(ILBC_LDFLAGS) $(LIBGSM_LDFLAGS) $(BV16_LDFLAGS) $(G729_LDFLAGS) \
$(FFMPEG_LDFLAGS) $(LIBYUV_LDFLAGS) $(VPX_LDFLAGS) $(SPEEX_LDFLAGS) $(SPEEX_DSP_LDFLAGS) $(WEBRTC_LDFLAGS) $(OPUS_LDFLAGS) $(OPENCORE_AMR_LDFLAGS) $(ILBC_LDFLAGS) $(LIBGSM_LDFLAGS) $(BV16_LDFLAGS) $(G729_LDFLAGS) \
$(LIBSRTP_LDFLAGS) \
-ltinySAK_$(MARCH) -ltinyNET_$(MARCH) -ltinySDP_$(MARCH) -ltinyRTP_$(MARCH) -ltinyMEDIA_$(MARCH) -ltinyMSRP_$(MARCH) -lm -lgcc
@ -204,7 +212,9 @@ OBJS += src/msrp/tdav_consumer_msrp.o \
src/msrp/tdav_producer_msrp.o \
src/msrp/tdav_session_msrp.o
### codecs (OPUS)
OBJS += src/codecs/opus/tdav_codec_opus.o
### codecs (AMR)
OBJS += src/codecs/amr/tdav_codec_amr.o

View File

@ -37,14 +37,6 @@
TDAV_BEGIN_DECLS
typedef struct tdav_codec_g722_s
{
TMEDIA_DECLARE_CODEC_AUDIO;
g722_encode_state_t *enc_state;
g722_decode_state_t *dec_state;
}
tdav_codec_g722_t;
TINYDAV_GEXTERN const tmedia_codec_plugin_def_t *tdav_codec_g722_plugin_def_t;
TDAV_END_DECLS

View File

@ -26,7 +26,6 @@
*
* @author Mamadou Diop <diopmamadou(at)doubango.org>
*
*/
#ifndef TINYDAV_CODEC_G729_H
#define TINYDAV_CODEC_G729_H

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2010-2013 Doubango Telecom <http://www.doubango.org>.
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
/**@file tdav_codec_opus.h
* @brief OPUS audio codec.
*/
#ifndef TINYDAV_CODEC_OPUS_H
#define TINYDAV_CODEC_OPUS_H
#include "tinydav_config.h"
#if HAVE_LIBOPUS
#include "tinymedia/tmedia_codec.h"
TINYDAV_GEXTERN const tmedia_codec_plugin_def_t *tdav_codec_opus_plugin_def_t;
#endif /* HAVE_LIBOPUS */
#endif /* TINYDAV_CODEC_OPUS_H */

View File

@ -60,7 +60,7 @@ struct tdav_video_frame_s* tdav_video_frame_create(struct trtp_rtp_packet_s* rtp
int tdav_video_frame_put(struct tdav_video_frame_s* self, struct trtp_rtp_packet_s* rtp_pkt);
const struct trtp_rtp_packet_s* tdav_video_frame_find_by_seq_num(const struct tdav_video_frame_s* self, uint16_t seq_num);
tsk_size_t tdav_video_frame_write(struct tdav_video_frame_s* self, void** buffer_ptr, tsk_size_t* buffer_size);
tsk_bool_t tdav_video_frame_is_complete(const struct tdav_video_frame_s* self, int32_t last_seq_num_with_mark, uint16_t* missing_seq_num);
tsk_bool_t tdav_video_frame_is_complete(const struct tdav_video_frame_s* self, int32_t last_seq_num_with_mark, uint16_t* missing_seq_num_start, tsk_size_t* missing_seq_num_count);
TDAV_END_DECLS

View File

@ -71,10 +71,10 @@ int tdav_consumer_audioqueue_prepare(tmedia_consumer_t* self, const tmedia_codec
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
TMEDIA_CONSUMER(consumer)->audio.ptime = codec->plugin->audio.ptime;
TMEDIA_CONSUMER(consumer)->audio.in.channels = codec->plugin->audio.channels;
TMEDIA_CONSUMER(consumer)->audio.in.rate = codec->plugin->rate;
TMEDIA_CONSUMER(consumer)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec);
TMEDIA_CONSUMER(consumer)->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec);
TMEDIA_CONSUMER(consumer)->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec);
/* codec should have ptime */
// Set audio category

View File

@ -169,10 +169,10 @@ static int tdav_consumer_audiounit_prepare(tmedia_consumer_t* self, const tmedia
}
#endif
TMEDIA_CONSUMER(consumer)->audio.ptime = codec->plugin->audio.ptime;
TMEDIA_CONSUMER(consumer)->audio.in.channels = codec->plugin->audio.channels;
TMEDIA_CONSUMER(consumer)->audio.in.rate = codec->plugin->rate;
TMEDIA_CONSUMER(consumer)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec);
TMEDIA_CONSUMER(consumer)->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec);
TMEDIA_CONSUMER(consumer)->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec);
audioFormat.mSampleRate = TMEDIA_CONSUMER(consumer)->audio.out.rate ? TMEDIA_CONSUMER(consumer)->audio.out.rate : TMEDIA_CONSUMER(consumer)->audio.in.rate;
audioFormat.mFormatID = kAudioFormatLinearPCM;

View File

@ -70,10 +70,10 @@ static int tdav_producer_audioqueue_prepare(tmedia_producer_t* self, const tmedi
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
TMEDIA_PRODUCER(producer)->audio.channels = codec->plugin->audio.channels;
TMEDIA_PRODUCER(producer)->audio.rate = codec->plugin->rate;
TMEDIA_PRODUCER(producer)->audio.ptime = codec->plugin->audio.ptime;
TMEDIA_PRODUCER(producer)->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
TMEDIA_PRODUCER(producer)->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
TMEDIA_PRODUCER(producer)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
/* codec should have ptime */

View File

@ -163,9 +163,10 @@ static int tdav_producer_audiounit_prepare(tmedia_producer_t* self, const tmedia
#endif /* TARGET_OS_MAC */
/* codec should have ptime */
TMEDIA_PRODUCER(producer)->audio.channels = codec->plugin->audio.channels;
TMEDIA_PRODUCER(producer)->audio.rate = codec->plugin->rate;
TMEDIA_PRODUCER(producer)->audio.ptime = codec->plugin->audio.ptime;
TMEDIA_PRODUCER(producer)->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
TMEDIA_PRODUCER(producer)->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
TMEDIA_PRODUCER(producer)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
// get device format
param = sizeof(AudioStreamBasicDescription);

View File

@ -174,9 +174,9 @@ static int tdav_consumer_dsound_prepare(tmedia_consumer_t* self, const tmedia_co
return -2;
}
TMEDIA_CONSUMER(dsound)->audio.ptime = codec->plugin->audio.ptime;
TMEDIA_CONSUMER(dsound)->audio.in.channels = codec->plugin->audio.channels;
TMEDIA_CONSUMER(dsound)->audio.in.rate = codec->plugin->rate;
TMEDIA_CONSUMER(dsound)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_DECODING(codec);
TMEDIA_CONSUMER(dsound)->audio.in.channels = TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(codec);
TMEDIA_CONSUMER(dsound)->audio.in.rate = TMEDIA_CODEC_RATE_DECODING(codec);
/* Create sound device */
if((hr = DirectSoundCreate(NULL, &dsound->device, NULL) != DS_OK)){

View File

@ -170,9 +170,9 @@ static int tdav_producer_dsound_prepare(tmedia_producer_t* self, const tmedia_co
return -2;
}
TMEDIA_PRODUCER(dsound)->audio.channels = codec->plugin->audio.channels;
TMEDIA_PRODUCER(dsound)->audio.rate = codec->plugin->rate;
TMEDIA_PRODUCER(dsound)->audio.ptime = codec->plugin->audio.ptime;
TMEDIA_PRODUCER(dsound)->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
TMEDIA_PRODUCER(dsound)->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
TMEDIA_PRODUCER(dsound)->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
/* Create capture device */
if((hr = DirectSoundCaptureCreate(NULL, &dsound->device, NULL) != DS_OK)){

View File

@ -97,8 +97,8 @@ static int tdav_session_audio_rtp_cb(const void* callback_data, const struct trt
tsk_safeobj_lock(base);
if((ret = tmedia_codec_open(audio->decoder.codec))){
tsk_safeobj_unlock(base);
TSK_OBJECT_SAFE_FREE(audio->decoder.codec);
TSK_DEBUG_ERROR("Failed to open [%s] codec", audio->decoder.codec->plugin->desc);
TSK_OBJECT_SAFE_FREE(audio->decoder.codec);
return ret;
}
tsk_safeobj_unlock(base);
@ -110,12 +110,13 @@ static int tdav_session_audio_rtp_cb(const void* callback_data, const struct trt
tsk_size_t size = out_size;
// resample if needed
if(audio->decoder.codec->plugin->rate != base->consumer->audio.out.rate && base->consumer->audio.out.rate){
if(audio->decoder.codec->in.rate != base->consumer->audio.out.rate && base->consumer->audio.out.rate){
tsk_size_t resampler_result_size = 0;
int bytesPerSample = (base->consumer->audio.bits_per_sample >> 3);
if(!audio->decoder.resampler.instance){
audio->decoder.resampler.instance = _tdav_session_audio_resampler_create(bytesPerSample, audio->decoder.codec->plugin->rate, base->consumer->audio.out.rate, base->consumer->audio.ptime, base->consumer->audio.in.channels, base->consumer->audio.out.channels, TDAV_AUDIO_RESAMPLER_DEFAULT_QUALITY, &audio->decoder.resampler.buffer, &audio->decoder.resampler.buffer_size);
TSK_DEBUG_INFO("Create audio resampler(%s): consumer->audio.out.rate=%d, codec->in.rate=%d", base->consumer->audio.out.rate, audio->decoder.codec->in.rate);
audio->decoder.resampler.instance = _tdav_session_audio_resampler_create(bytesPerSample, audio->decoder.codec->in.rate, base->consumer->audio.out.rate, base->consumer->audio.ptime, base->consumer->audio.in.channels, base->consumer->audio.out.channels, TDAV_AUDIO_RESAMPLER_DEFAULT_QUALITY, &audio->decoder.resampler.buffer, &audio->decoder.resampler.buffer_size);
}
if(!audio->decoder.resampler.instance){
TSK_DEBUG_ERROR("No resampler to handle data");
@ -195,20 +196,20 @@ static int tdav_session_audio_producer_enc_cb(const void* callback_data, const v
if(audio->is_sending_dtmf_events){
if(base->rtp_manager){
// increment the timestamp
base->rtp_manager->rtp.timestamp += TMEDIA_CODEC_PCM_FRAME_SIZE(audio->encoder.codec)/*duration*/;
base->rtp_manager->rtp.timestamp += TMEDIA_CODEC_PCM_FRAME_SIZE_AUDIO_ENCODING(audio->encoder.codec)/*duration*/;
}
TSK_DEBUG_INFO("Skiping audio frame as we're sending DTMF...");
return 0;
}
// resample if needed
if(base->producer->audio.rate != audio->encoder.codec->plugin->rate){
if(base->producer->audio.rate != audio->encoder.codec->out.rate){
tsk_size_t resampler_result_size = 0;
int bytesPerSample = (base->producer->audio.bits_per_sample >> 3);
if(!audio->encoder.resampler.instance){
TSK_DEBUG_INFO("Create audio resampler(%s): producer->audio.rate=%d, encoder.codec->plugin->rate=%d, bytesPerSample=%d", audio->encoder.codec->plugin->desc, base->producer->audio.rate, audio->encoder.codec->plugin->rate, bytesPerSample);
audio->encoder.resampler.instance = _tdav_session_audio_resampler_create(bytesPerSample, base->producer->audio.rate, audio->encoder.codec->plugin->rate,base->producer->audio.ptime, base->producer->audio.channels, base->producer->audio.channels, TDAV_AUDIO_RESAMPLER_DEFAULT_QUALITY, &audio->encoder.resampler.buffer, &audio->encoder.resampler.buffer_size);
TSK_DEBUG_INFO("Create audio resampler(%s): producer->audio.rate=%d, encoder.codec->plugin->rate=%d, bytesPerSample=%d", audio->encoder.codec->plugin->desc, base->producer->audio.rate, audio->encoder.codec->out.rate, bytesPerSample);
audio->encoder.resampler.instance = _tdav_session_audio_resampler_create(bytesPerSample, base->producer->audio.rate, audio->encoder.codec->out.rate, base->producer->audio.ptime, base->producer->audio.channels, base->producer->audio.channels, TDAV_AUDIO_RESAMPLER_DEFAULT_QUALITY, &audio->encoder.resampler.buffer, &audio->encoder.resampler.buffer_size);
}
if(!audio->encoder.resampler.instance){
TSK_DEBUG_ERROR("No resampler to handle data");
@ -243,7 +244,7 @@ static int tdav_session_audio_producer_enc_cb(const void* callback_data, const v
if((audio->encoder.codec = tsk_object_ref(audio->encoder.codec))){ /* Thread safeness (SIP reINVITE or UPDATE could update the encoder) */
out_size = audio->encoder.codec->plugin->encode(audio->encoder.codec, buffer, size, &audio->encoder.buffer, &audio->encoder.buffer_size);
if(out_size){
trtp_manager_send_rtp(base->rtp_manager, audio->encoder.buffer, out_size, TMEDIA_CODEC_PCM_FRAME_SIZE(audio->encoder.codec), tsk_false/*Marker*/, tsk_true/*lastPacket*/);
trtp_manager_send_rtp(base->rtp_manager, audio->encoder.buffer, out_size, TMEDIA_CODEC_FRAME_DURATION_AUDIO_ENCODING(audio->encoder.codec), tsk_false/*Marker*/, tsk_true/*lastPacket*/);
}
tsk_object_unref(audio->encoder.codec);
}
@ -379,7 +380,7 @@ static int tdav_session_audio_start(tmedia_session_t* self)
/* Denoise (AEC, Noise Suppression, AGC) */
if(audio->denoise){
tmedia_denoise_close(audio->denoise);
tmedia_denoise_open(audio->denoise, TMEDIA_CODEC_PCM_FRAME_SIZE(audio->encoder.codec), TMEDIA_CODEC_RATE(audio->encoder.codec));
tmedia_denoise_open(audio->denoise, TMEDIA_CODEC_PCM_FRAME_SIZE_AUDIO_ENCODING(audio->encoder.codec), TMEDIA_CODEC_RATE_ENCODING(audio->encoder.codec));
}
}
@ -418,7 +419,7 @@ static int tdav_session_audio_send_dtmf(tmedia_session_t* self, uint8_t event)
// Find the DTMF codec to use to use the RTP payload
if((codec = tmedia_codec_find_by_format(TMEDIA_SESSION(audio)->codecs, TMEDIA_CODEC_FORMAT_DTMF))){
rate = (int)codec->plugin->rate;
rate = (int)codec->out.rate;
format = atoi(codec->neg_format ? codec->neg_format : codec->format);
TSK_OBJECT_SAFE_FREE(codec);
}

View File

@ -31,6 +31,14 @@
#include "tsk_memory.h"
#include "tsk_debug.h"
typedef struct tdav_codec_g722_s
{
TMEDIA_DECLARE_CODEC_AUDIO;
g722_encode_state_t *enc_state;
g722_decode_state_t *dec_state;
}
tdav_codec_g722_t;
static int tdav_codec_g722_open(tmedia_codec_t* self)
{

View File

@ -83,7 +83,7 @@ tsk_size_t tdav_codec_gsm_encode(tmedia_codec_t* self, const void* in_data, tsk_
return 0;
}
out_size = ((in_size / (TMEDIA_CODEC_PCM_FRAME_SIZE(self) * sizeof(short))) * TDAV_GSM_FRAME_SIZE);
out_size = ((in_size / (TMEDIA_CODEC_PCM_FRAME_SIZE_AUDIO_ENCODING(self) * sizeof(short))) * TDAV_GSM_FRAME_SIZE);
/* allocate new buffer if needed */
if(*out_max_size <out_size){
@ -111,7 +111,7 @@ tsk_size_t tdav_codec_gsm_decode(tmedia_codec_t* self, const void* in_data, tsk_
return 0;
}
out_size = (in_size / TDAV_GSM_FRAME_SIZE) * (TMEDIA_CODEC_PCM_FRAME_SIZE(self) * sizeof(short));
out_size = (in_size / TDAV_GSM_FRAME_SIZE) * (TMEDIA_CODEC_PCM_FRAME_SIZE_AUDIO_DECODING(self) * sizeof(short));
/* allocate new buffer if needed */
if(*out_max_size <out_size){

View File

@ -415,7 +415,7 @@ static tsk_size_t tdav_codec_h263_decode(tmedia_codec_t* self, const void* in_da
//TSK_DEBUG_INFO("Packet duplicated, seq_num=%d", rtp_hdr->seq_num);
return 0;
}
TSK_DEBUG_INFO("Packet lost, seq_num=%d", rtp_hdr->seq_num);
TSK_DEBUG_INFO("[H.263] Packet loss, seq_num=%d", rtp_hdr->seq_num);
}
h263->decoder.last_seq = rtp_hdr->seq_num;
@ -707,7 +707,7 @@ static tsk_size_t tdav_codec_h263p_decode(tmedia_codec_t* self, const void* in_d
//TSK_DEBUG_INFO("Packet duplicated, seq_num=%d", rtp_hdr->seq_num);
return 0;
}
TSK_DEBUG_INFO("Packet lost, seq_num=%d", rtp_hdr->seq_num);
TSK_DEBUG_INFO("[H.263+] Packet loss, seq_num=%d", rtp_hdr->seq_num);
}
h263->decoder.last_seq = rtp_hdr->seq_num;

View File

@ -317,7 +317,7 @@ static tsk_size_t tdav_codec_h264_decode(tmedia_codec_t* self, const void* in_da
/* Packet lost? */
if((h264->decoder.last_seq + 1) != rtp_hdr->seq_num && h264->decoder.last_seq){
TSK_DEBUG_INFO("Packet lost, seq_num=%d", (h264->decoder.last_seq + 1));
TSK_DEBUG_INFO("[H.264] Packet loss, seq_num=%d", (h264->decoder.last_seq + 1));
}
h264->decoder.last_seq = rtp_hdr->seq_num;
@ -461,7 +461,7 @@ static tsk_bool_t tdav_codec_h264_sdp_att_match(const tmedia_codec_t* codec, con
return tsk_false;
}
TSK_DEBUG_INFO("Trying to match [%s:%s]", att_name, att_value);
TSK_DEBUG_INFO("[H.264] Trying to match [%s:%s]", att_name, att_value);
if(tsk_striequals(att_name, "fmtp")){
int val_int;

View File

@ -0,0 +1,362 @@
/*
* Copyright (C) 2010-2013 Doubango Telecom <http://www.doubango.org>.
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
/**@file tdav_codec_opus.c
* @brief OPUS audio codec.
* SDP: http://tools.ietf.org/html/draft-spittka-payload-rtp-opus-03
*/
#include "tinydav/codecs/opus/tdav_codec_opus.h"
#if HAVE_LIBOPUS
#include <opus/opus.h>
#include "tinymedia/tmedia_defaults.h"
#include "tinyrtp/rtp/trtp_rtp_packet.h"
#include "tsk_params.h"
#include "tsk_memory.h"
#include "tsk_string.h"
#include "tsk_debug.h"
#if !defined(TDAV_OPUS_MAX_FRAME_SIZE_IN_SAMPLES)
# define TDAV_OPUS_MAX_FRAME_SIZE_IN_SAMPLES (5760) /* 120ms@48kHz */
#endif
#if !defined(TDAV_OPUS_MAX_FRAME_SIZE_IN_BYTES)
# define TDAV_OPUS_MAX_FRAME_SIZE_IN_BYTES (TDAV_OPUS_MAX_FRAME_SIZE_IN_SAMPLES << 1) /* 120ms@48kHz */
#endif
#if !defined(TDAV_OPUS_FEC_ENABLED)
# define TDAV_OPUS_FEC_ENABLED 0
#endif
#if !defined(TDAV_OPUS_DTX_ENABLED)
# define TDAV_OPUS_DTX_ENABLED 0
#endif
typedef struct tdav_codec_opus_s
{
TMEDIA_DECLARE_CODEC_AUDIO;
struct {
OpusEncoder *inst;
} encoder;
struct {
OpusDecoder *inst;
opus_int16 buff[TDAV_OPUS_MAX_FRAME_SIZE_IN_SAMPLES];
tsk_bool_t fec_enabled;
tsk_bool_t dtx_enabled;
uint16_t last_seq;
} decoder;
}
tdav_codec_opus_t;
static tsk_bool_t _tdav_codec_opus_rate_is_valid(const int32_t rate)
{
switch(rate){
case 8000: case 12000: case 16000: case 24000: case 48000: return tsk_true;
default: return tsk_false;
}
}
static int tdav_codec_opus_open(tmedia_codec_t* self)
{
tdav_codec_opus_t* opus = (tdav_codec_opus_t*)self;
int opus_err;
if(!opus){
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
// Initialize the decoder
if(!opus->decoder.inst){
TSK_DEBUG_INFO("[OPUS] Open decoder: rate=%d, channels=%d", (int)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels);
if(!(opus->decoder.inst = opus_decoder_create((opus_int32)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels, &opus_err)) || opus_err != OPUS_OK){
TSK_DEBUG_ERROR("Failed to create Opus decoder(rate=%d, channels=%d) instance with error code=%d.", (int)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels, opus_err);
return -2;
}
}
// Initialize the encoder
if(!opus->encoder.inst){
TSK_DEBUG_INFO("[OPUS] Open encoder: rate=%d, channels=%d", (int)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels);
if(!(opus->encoder.inst = opus_encoder_create((opus_int32)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels, OPUS_APPLICATION_VOIP, &opus_err)) || opus_err != OPUS_OK){
TSK_DEBUG_ERROR("Failed to create Opus decoder(rate=%d, channels=%d) instance with error code=%d.", (int)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels, opus_err);
return -2;
}
}
#if TDAV_UNDER_MOBILE /* iOS, Android and WP8 */
opus_encoder_ctl(opus->encoder.inst, OPUS_SET_COMPLEXITY(3));
#endif
opus_encoder_ctl(opus->encoder.inst, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));
return 0;
}
static int tdav_codec_opus_close(tmedia_codec_t* self)
{
tdav_codec_opus_t* opus = (tdav_codec_opus_t*)self;
(void)(opus);
/* resources will be freed by the dctor() */
return 0;
}
static tsk_size_t tdav_codec_opus_encode(tmedia_codec_t* self, const void* in_data, tsk_size_t in_size, void** out_data, tsk_size_t* out_max_size)
{
tdav_codec_opus_t* opus = (tdav_codec_opus_t*)self;
opus_int32 ret;
if(!self || !in_data || !in_size || !out_data){
TSK_DEBUG_ERROR("Invalid parameter");
return 0;
}
if(!opus->encoder.inst){
TSK_DEBUG_ERROR("Encoder not ready");
return 0;
}
// we're sure that the output (encoded) size cannot be higher than the input (raw)
if(*out_max_size < in_size){
if(!(*out_data = tsk_realloc(*out_data, in_size))){
TSK_DEBUG_ERROR("Failed to allocate buffer with size = %u", in_size);
*out_max_size = 0;
return 0;
}
*out_max_size = in_size;
}
ret = opus_encode(opus->encoder.inst,
(const opus_int16 *)in_data, (int)(in_size >> 1),
(unsigned char *)*out_data, (opus_int32)*out_max_size);
if(ret < 0){
TSK_DEBUG_ERROR("opus_encode() failed with error code = %d", ret);
return 0;
}
return (tsk_size_t)ret;
}
static tsk_size_t tdav_codec_opus_decode(tmedia_codec_t* self, const void* in_data, tsk_size_t in_size, void** out_data, tsk_size_t* out_max_size, const tsk_object_t* proto_hdr)
{
tdav_codec_opus_t* opus = (tdav_codec_opus_t*)self;
int frame_size;
const trtp_rtp_header_t* rtp_hdr = proto_hdr;
if(!self || !in_data || !in_size || !out_data){
TSK_DEBUG_ERROR("Invalid parameter");
return 0;
}
if(!opus->decoder.inst){
TSK_DEBUG_ERROR("Decoder not ready");
return 0;
}
/* Packet loss? */
if(opus->decoder.last_seq != (rtp_hdr->seq_num - 1) && opus->decoder.last_seq){
if(opus->decoder.last_seq == rtp_hdr->seq_num){
// Could happen on some stupid emulators
//TSK_DEBUG_INFO("Packet duplicated, seq_num=%d", rtp_hdr->seq_num);
return 0;
}
TSK_DEBUG_INFO("[Opus] Packet loss, seq_num=%d", rtp_hdr->seq_num);
opus_decode(opus->decoder.inst, tsk_null/*packet loss*/, (opus_int32)0, opus->decoder.buff, TDAV_OPUS_MAX_FRAME_SIZE_IN_SAMPLES, opus->decoder.fec_enabled);
}
opus->decoder.last_seq = rtp_hdr->seq_num;
frame_size = opus_decode(opus->decoder.inst, (const unsigned char *)in_data, (opus_int32)in_size, opus->decoder.buff, TDAV_OPUS_MAX_FRAME_SIZE_IN_SAMPLES, opus->decoder.fec_enabled ? 1 : 0);
if(frame_size > 0){
tsk_size_t frame_size_inbytes = (frame_size << 1);
if(*out_max_size < frame_size_inbytes){
if(!(*out_data = tsk_realloc(*out_data, frame_size_inbytes))){
TSK_DEBUG_ERROR("Failed to allocate new buffer");
*out_max_size = 0;
return 0;
}
*out_max_size = frame_size_inbytes;
}
memcpy(*out_data, opus->decoder.buff, frame_size_inbytes);
return frame_size_inbytes;
}
else{
return 0;
}
}
static tsk_bool_t tdav_codec_opus_sdp_att_match(const tmedia_codec_t* codec, const char* att_name, const char* att_value)
{
tdav_codec_opus_t* opus = (tdav_codec_opus_t*)codec;
if(!opus){
TSK_DEBUG_ERROR("Invalid parameter");
return tsk_false;
}
TSK_DEBUG_INFO("[OPUS] Trying to match [%s:%s]", att_name, att_value);
if(tsk_striequals(att_name, "fmtp")){
int val_int;
tsk_params_L_t* params;
/* e.g. FIXME */
if((params = tsk_params_fromstring(att_value, ";", tsk_true))){
tsk_bool_t ret = tsk_false;
/* === maxplaybackrate ===*/
if((val_int = tsk_params_get_param_value_as_int(params, "maxplaybackrate")) != -1){
if(!_tdav_codec_opus_rate_is_valid(val_int)){
TSK_DEBUG_ERROR("[OPUS] %d not valid as maxplaybackrate value", val_int);
goto done;
}
TMEDIA_CODEC(opus)->out.rate = TSK_MIN((int32_t)TMEDIA_CODEC(opus)->out.rate, val_int);
TMEDIA_CODEC_AUDIO(opus)->out.timestamp_multiplier = tmedia_codec_audio_get_timestamp_multiplier(codec->id, codec->out.rate);
}
/* === sprop-maxcapturerate ===*/
if((val_int = tsk_params_get_param_value_as_int(params, "sprop-maxcapturerate")) != -1){
if(!_tdav_codec_opus_rate_is_valid(val_int)){
TSK_DEBUG_ERROR("[OPUS] %d not valid as sprop-maxcapturerate value", val_int);
goto done;
}
TMEDIA_CODEC(opus)->in.rate = TSK_MIN((int32_t)TMEDIA_CODEC(opus)->in.rate, val_int);
TMEDIA_CODEC_AUDIO(opus)->in.timestamp_multiplier = tmedia_codec_audio_get_timestamp_multiplier(codec->id, codec->in.rate);
}
ret = tsk_true;
done:
TSK_OBJECT_SAFE_FREE(params);
return ret;
}
}
return tsk_true;
}
static char* tdav_codec_opus_sdp_att_get(const tmedia_codec_t* codec, const char* att_name)
{
tdav_codec_opus_t* opus = (tdav_codec_opus_t*)codec;
if(!opus){
TSK_DEBUG_ERROR("Invalid parameter");
return tsk_null;
}
if(tsk_striequals(att_name, "fmtp")){
char* fmtp = tsk_null;
tsk_sprintf(&fmtp, "maxplaybackrate=%d; sprop-maxcapturerate=%d; stereo=%d; sprop-stereo=%d; useinbandfec=%d; usedtx=%d",
TMEDIA_CODEC(opus)->in.rate,
TMEDIA_CODEC(opus)->out.rate,
(TMEDIA_CODEC_AUDIO(opus)->in.channels == 2) ? 1 : 0,
(TMEDIA_CODEC_AUDIO(opus)->out.channels == 2) ? 1 : 0,
opus->decoder.fec_enabled ? 1 : 0,
opus->decoder.dtx_enabled ? 1 : 0
);
return fmtp;
}
return tsk_null;
}
//
// OPUS Plugin definition
//
/* constructor */
static tsk_object_t* tdav_codec_opus_ctor(tsk_object_t * self, va_list * app)
{
tdav_codec_opus_t *opus = self;
if(opus){
/* init base: called by tmedia_codec_create() */
/* init self */
TMEDIA_CODEC(opus)->in.rate = tmedia_defaults_get_opus_maxplaybackrate();
TMEDIA_CODEC(opus)->out.rate = tmedia_defaults_get_opus_maxcapturerate();
TMEDIA_CODEC_AUDIO(opus)->in.channels = 1;
TMEDIA_CODEC_AUDIO(opus)->out.channels = 1;
#if TDAV_OPUS_FEC_ENABLED
opus->decoder.fec_enabled = tsk_true;
#endif
#if TDAV_OPUS_DTX_ENABLED
opus->decoder.dtx_enabled = tsk_true;
#endif
}
return self;
}
/* destructor */
static tsk_object_t* tdav_codec_opus_dtor(tsk_object_t * self)
{
tdav_codec_opus_t *opus = self;
if(opus){
/* deinit base */
tmedia_codec_audio_deinit(opus);
/* deinit self */
if(opus->decoder.inst){
opus_decoder_destroy(opus->decoder.inst), opus->decoder.inst = tsk_null;
}
if(opus->encoder.inst){
opus_encoder_destroy(opus->encoder.inst), opus->encoder.inst = tsk_null;
}
}
return self;
}
/* object definition */
static const tsk_object_def_t tdav_codec_opus_def_s =
{
sizeof(tdav_codec_opus_t),
tdav_codec_opus_ctor,
tdav_codec_opus_dtor,
tmedia_codec_cmp,
};
/* plugin definition*/
static const tmedia_codec_plugin_def_t tdav_codec_opus_plugin_def_s =
{
&tdav_codec_opus_def_s,
tmedia_audio,
tmedia_codec_id_opus,
"opus",
"opus Codec",
TMEDIA_CODEC_FORMAT_OPUS,
tsk_true,
48000, // this is the default sample rate
{ /* audio */
2, // channels
20 // ptime
},
/* video */
{0},
tsk_null, // set()
tdav_codec_opus_open,
tdav_codec_opus_close,
tdav_codec_opus_encode,
tdav_codec_opus_decode,
tdav_codec_opus_sdp_att_match,
tdav_codec_opus_sdp_att_get
};
const tmedia_codec_plugin_def_t *tdav_codec_opus_plugin_def_t = &tdav_codec_opus_plugin_def_s;
#endif /* HAVE_LIBOPUS */

View File

@ -41,7 +41,7 @@
int tdav_codec_speex_init(tdav_codec_speex_t* self, tdav_codec_speex_type_t type);
int tdav_codec_speex_deinit(tdav_codec_speex_t* self);
/* ============ iLBC Plugin interface ================= */
/* ============ Speex Plugin interface ================= */
int tdav_codec_speex_open(tmedia_codec_t* self)
{
@ -117,7 +117,7 @@ tsk_size_t tdav_codec_speex_encode(tmedia_codec_t* self, const void* in_data, ts
}
}
outsize = speex_bits_write(&speex->encoder.bits, *out_data, speex->encoder.size/2);
outsize = speex_bits_write(&speex->encoder.bits, *out_data, (speex->encoder.size >> 1));
return outsize;
}

View File

@ -397,7 +397,7 @@ static tsk_size_t tdav_codec_vp8_decode(tmedia_codec_t* self, const void* in_dat
// Packet lost?
if(vp8->decoder.last_seq && (vp8->decoder.last_seq + 1) != rtp_hdr->seq_num){
TSK_DEBUG_INFO("Packet lost, seq_num=%d", (vp8->decoder.last_seq + 1));
TSK_DEBUG_INFO("[VP8] Packet loss, seq_num=%d", (vp8->decoder.last_seq + 1));
}
vp8->decoder.last_seq = rtp_hdr->seq_num;
@ -688,7 +688,7 @@ int tdav_codec_vp8_open_encoder(tdav_codec_vp8_t* self)
self->encoder.cfg.rc_end_usage = VPX_CBR;
self->encoder.cfg.g_pass = VPX_RC_ONE_PASS;
self->encoder.cfg.rc_resize_allowed = 0;
self->encoder.cfg.rc_min_quantizer = 8;
self->encoder.cfg.rc_min_quantizer = 2;
self->encoder.cfg.rc_max_quantizer = 56;
self->encoder.cfg.rc_undershoot_pct = 100;
self->encoder.cfg.rc_overshoot_pct = 15;

View File

@ -64,6 +64,7 @@
#include "tinydav/codecs/g729/tdav_codec_g729.h"
#include "tinydav/codecs/g722/tdav_codec_g722.h"
#include "tinydav/codecs/speex/tdav_codec_speex.h"
#include "tinydav/codecs/opus/tdav_codec_opus.h"
#include "tinydav/codecs/h261/tdav_codec_h261.h"
#include "tinydav/codecs/h263/tdav_codec_h263.h"
#include "tinydav/codecs/h264/tdav_codec_h264.h"
@ -198,6 +199,9 @@ int tdav_init()
tmedia_codec_plugin_register(tdav_codec_speex_wb_plugin_def_t);
tmedia_codec_plugin_register(tdav_codec_speex_uwb_plugin_def_t);
#endif
#if HAVE_LIBOPUS
tmedia_codec_plugin_register(tdav_codec_opus_plugin_def_t);
#endif
#if HAVE_G729
tmedia_codec_plugin_register(tdav_codec_g729ab_plugin_def_t);
#endif
@ -339,6 +343,9 @@ static tdav_codec_decl_t __codecs[] = {
{ tdav_codec_id_speex_wb, &tdav_codec_speex_wb_plugin_def_t },
{ tdav_codec_id_speex_uwb, &tdav_codec_speex_uwb_plugin_def_t },
#endif
#if HAVE_LIBOPUS
{ tdav_codec_id_opus, &tdav_codec_opus_plugin_def_t },
#endif
#if HAVE_G729
{ tdav_codec_id_g729ab, &tdav_codec_g729ab_plugin_def_t },
#endif
@ -464,6 +471,12 @@ tsk_bool_t _tdav_codec_is_supported(tdav_codec_id_t codec, const tmedia_codec_pl
#else
return tsk_false;
#endif
case tdav_codec_id_opus:
#if HAVE_LIBOPUS
return tsk_true;
#else
return tsk_false;
#endif
case tdav_codec_id_bv16:
#if HAVE_BV16
@ -593,6 +606,9 @@ int tdav_deinit()
tmedia_codec_plugin_unregister(tdav_codec_speex_wb_plugin_def_t);
tmedia_codec_plugin_unregister(tdav_codec_speex_uwb_plugin_def_t);
#endif
#if HAVE_LIBOPUS
tmedia_codec_plugin_unregister(tdav_codec_opus_plugin_def_t);
#endif
#if HAVE_G729
tmedia_codec_plugin_unregister(tdav_codec_g729ab_plugin_def_t);
#endif

View File

@ -694,10 +694,19 @@ const tsdp_header_M_t* tdav_session_av_get_lo(tdav_session_av_t* self, tsk_bool_
if(self->media_type == tmedia_audio){
tsdp_header_M_add_headers(base->M.lo,
TSDP_HEADER_A_VA_ARGS("ptime", "20"),
TSDP_HEADER_A_VA_ARGS("minptime", "20"),
TSDP_HEADER_A_VA_ARGS("maxptime", "20"),
TSDP_HEADER_A_VA_ARGS("silenceSupp", "off - - - -"),
tsk_null);
// the "telephone-event" fmt/rtpmap is added below
}
else if(self->media_type == tmedia_video){
// https://code.google.com/p/webrtc2sip/issues/detail?id=81
tsdp_header_M_add_headers(base->M.lo,
TSDP_HEADER_A_VA_ARGS("rtcp-fb", "* nack pli"),
TSDP_HEADER_A_VA_ARGS("rtcp-fb", "* ccm fir"),
tsk_null);
}
}
else{
TSK_DEBUG_ERROR("Failed to create lo");

View File

@ -202,14 +202,14 @@ IMPORTANT: This function assume that the RTP packets use the marker bit to signa
*@param missing_seq_num A missing seq num if any. This value is set only if the function returns False.
*@return True if the frame is complete and False otherwise. If False is returned then, missing_seq_num is set.
*/
tsk_bool_t tdav_video_frame_is_complete(const tdav_video_frame_t* self, int32_t last_seq_num_with_mark, uint16_t* missing_seq_num)
tsk_bool_t tdav_video_frame_is_complete(const tdav_video_frame_t* self, int32_t last_seq_num_with_mark, uint16_t* missing_seq_num_start, tsk_size_t* missing_seq_num_count)
{
const trtp_rtp_packet_t* pkt;
const tsk_list_item_t *item;
uint16_t i;
tsk_bool_t is_complete = tsk_false;
if(!self || !missing_seq_num){
if(!self || !missing_seq_num_start || !missing_seq_num_count){
TSK_DEBUG_ERROR("Invalid parameter");
return tsk_false;
}
@ -221,12 +221,14 @@ tsk_bool_t tdav_video_frame_is_complete(const tdav_video_frame_t* self, int32_t
continue;
}
if(last_seq_num_with_mark >= 0 && pkt->header->seq_num != (last_seq_num_with_mark + ++i)){
*missing_seq_num = (pkt->header->seq_num - 1);
*missing_seq_num_start = (last_seq_num_with_mark + i);
*missing_seq_num_count = pkt->header->seq_num - (*missing_seq_num_start);
break;
}
if(item == self->pkts->tail){
if(!(is_complete = (pkt->header->marker))){
*missing_seq_num = (pkt->header->seq_num + 1);
*missing_seq_num_start = (pkt->header->seq_num + 1);
*missing_seq_num_count = 1;
}
}
}

View File

@ -40,37 +40,29 @@
# include <windows.h>
#endif
#define TDAV_VIDEO_JB_DISABLE 0
// default frame rate
// the corret fps will be computed using the RTP timestamps
#define TDAV_VIDEO_JB_FPS TDAV_VIDEO_JB_FPS_MAX
#define TDAV_VIDEO_JB_FPS_MIN 15
#define TDAV_VIDEO_JB_FPS_MIN 10
#define TDAV_VIDEO_JB_FPS_MAX 60
// Number of correct consecutive RTP packets to receive before computing the FPS
#define TDAV_VIDEO_JB_FPS_PROB (TDAV_VIDEO_JB_FPS >> 1)
// Max number of frames to allow in jitter buffer
//#define TDAV_VIDEO_JB_TAIL_MAX /*FIXME:(TDAV_VIDEO_JB_FPS << 2)*/100
// Min number of frames required before requesting a full decode
// This is required because of the FEC and NACK functions
// Will be updated using the RTT value from RTCP and probation
#define TDAV_VIDEO_JB_TAIL_MIN_MIN 10
#define TDAV_VIDEO_JB_TAIL_MIN_MAX 20
#define TDAV_VIDEO_JB_TAIL_MIN_PROB (TDAV_VIDEO_JB_FPS >> 2)
// Number of correct consecutive video frames to receive before computing the FPS
#define TDAV_VIDEO_JB_FPS_PROB (TDAV_VIDEO_JB_FPS << 1)
// Maximum gap allowed (used to detect seqnum wrpping)
#define TDAV_VIDEO_JB_MAX_DROPOUT 0xFD9B
#define TDAV_VIDEO_JB_DISABLE 0
#define TDAV_VIDEO_JB_TAIL_MAX_LOG2 1
#if TDAV_UNDER_MOBILE /* to avoid too high memory usage */
# define TDAV_VIDEO_JB_TAIL_MAX (TDAV_VIDEO_JB_FPS_MIN << TDAV_VIDEO_JB_TAIL_MAX_LOG2)
# define TDAV_VIDEO_JB_TAIL_MAX (TDAV_VIDEO_JB_FPS_MIN << TDAV_VIDEO_JB_TAIL_MAX_LOG2)
#else
# define TDAV_VIDEO_JB_TAIL_MAX (TDAV_VIDEO_JB_FPS_MAX << TDAV_VIDEO_JB_TAIL_MAX_LOG2)
# define TDAV_VIDEO_JB_TAIL_MAX (TDAV_VIDEO_JB_FPS_MAX << TDAV_VIDEO_JB_TAIL_MAX_LOG2)
#endif
#define TDAV_VIDEO_JB_RATE 90 /* KHz */
#define TDAV_VIDEO_JB_LATENCY_MIN 2 /* Must be > 0 */
#define TDAV_VIDEO_JB_LATENCY_MAX 10
#define TDAV_VIDEO_JB_LATENCY_MAX 15 /* Default, will be updated using fps */
static const tdav_video_frame_t* _tdav_video_jb_get_frame(struct tdav_video_jb_s* self, uint32_t timestamp, uint8_t pt, tsk_bool_t *pt_matched);
static void* TSK_STDCALL _tdav_video_jb_decode_thread_func(void *arg);
@ -87,8 +79,6 @@ typedef struct tdav_video_jb_s
uint32_t last_timestamp;
int32_t conseq_frame_drop;
int32_t tail_max;
int32_t tail_min;
int32_t tail_prob;
tdav_video_frames_L_t *frames;
int64_t frames_count;
@ -181,8 +171,6 @@ tdav_video_jb_t* tdav_video_jb_create()
jb->fps = TDAV_VIDEO_JB_FPS;
jb->fps_prob = TDAV_VIDEO_JB_FPS_PROB;
jb->tail_max = TDAV_VIDEO_JB_TAIL_MAX;
jb->tail_min = TDAV_VIDEO_JB_TAIL_MIN_MIN;
jb->tail_prob = TDAV_VIDEO_JB_TAIL_MIN_PROB;
}
return jb;
}
@ -276,8 +264,7 @@ int tdav_video_jb_put(tdav_video_jb_t* self, trtp_rtp_packet_t* rtp_pkt)
is_restarted = (TSK_ABS(diff) > TDAV_VIDEO_JB_MAX_DROPOUT);
is_frame_late_or_dup = !is_frame_loss;
tdav_video_jb_reset_fps_prob(self);
tdav_video_jb_reset_tail_min_prob(self);
TSK_DEBUG_INFO("Packet %s (from JB) [%u - %u]", is_frame_loss ? "loss" : "late/duplicated/nack", *seq_num, rtp_pkt->header->seq_num);
TSK_DEBUG_INFO("Packet %s (from JB) [%hu - %hu]", is_frame_loss ? "loss" : "late/duplicated/nack", *seq_num, rtp_pkt->header->seq_num);
if(is_frame_loss && !is_restarted){
if(self->callback){
@ -289,10 +276,6 @@ int tdav_video_jb_put(tdav_video_jb_t* self, trtp_rtp_packet_t* rtp_pkt)
}
}
}
else{
--self->tail_prob;
}
self->tail_min = self->tail_prob <= 0 ? TDAV_VIDEO_JB_TAIL_MIN_MIN : TDAV_VIDEO_JB_TAIL_MIN_MAX;
if(!old_frame){
tdav_video_frame_t* new_frame;
@ -323,6 +306,7 @@ int tdav_video_jb_put(tdav_video_jb_t* self, trtp_rtp_packet_t* rtp_pkt)
}
}
else{
TSK_DEBUG_INFO("Dropping video frame because frames_count(%lld)>=tail_max(%d)", self->frames_count, self->tail_max);
tsk_list_remove_first_item(self->frames);
}
tdav_video_jb_reset_fps_prob(self);
@ -338,7 +322,8 @@ int tdav_video_jb_put(tdav_video_jb_t* self, trtp_rtp_packet_t* rtp_pkt)
int32_t fps = (1000 / self->avg_duration);
self->fps = TSK_CLAMP(TDAV_VIDEO_JB_FPS_MIN, fps, TDAV_VIDEO_JB_FPS_MAX);
self->tail_max = (self->fps << TDAV_VIDEO_JB_TAIL_MAX_LOG2); // maximum delay = 2 seconds
TSK_DEBUG_INFO("According to rtp-timestamps ...FPS = %d (clipped to %d) and max jb tail will be = %d", fps, self->fps, self->tail_max);
self->latency_max = self->fps; // maximum = 1 second
TSK_DEBUG_INFO("According to rtp-timestamps ...FPS = %d (clipped to %d) tail_max=%d, latency_max=%u", fps, self->fps, self->tail_max, self->latency_max);
tdav_video_jb_reset_fps_prob(self);
}
}
@ -407,7 +392,8 @@ static void* TSK_STDCALL _tdav_video_jb_decode_thread_func(void *arg)
{
tdav_video_jb_t* jb = (tdav_video_jb_t*)arg;
uint64_t delay;
uint16_t missing_seq_num;
uint16_t missing_seq_num_start = 0, prev_missing_seq_num_start = 0;
tsk_size_t missing_seq_num_count = 0, prev_lasted_missing_seq_num_count;
const tdav_video_frame_t* frame;
tsk_list_item_t* item;
uint64_t next_decode_duration = (1000 / jb->fps), now;
@ -443,20 +429,24 @@ static void* TSK_STDCALL _tdav_video_jb_decode_thread_func(void *arg)
// is it still acceptable to wait for missing packets?
if(jb->frames_count < jb->latency_max){
frame = (const tdav_video_frame_t*)jb->frames->head->data;
if(!tdav_video_frame_is_complete(frame, jb->decode_last_seq_num_with_mark, &missing_seq_num)){
TSK_DEBUG_INFO("Time to decode frame...but some RTP packets are missing (seqnum=%u). Postpone :(", missing_seq_num);
if(!tdav_video_frame_is_complete(frame, jb->decode_last_seq_num_with_mark, &missing_seq_num_start, &missing_seq_num_count)){
TSK_DEBUG_INFO("Time to decode frame...but some RTP packets are missing (missing_seq_num_start=%hu, missing_seq_num_count=%u, last_seq_num_with_mark=%d). Postpone :(", missing_seq_num_start, missing_seq_num_count, jb->decode_last_seq_num_with_mark);
// signal to the session that a sequence number is missing (will send a NACK)
if(jb->callback){
jb->cb_data_any.type = tdav_video_jb_cb_data_type_fl;
jb->cb_data_any.ssrc = frame->ssrc;
jb->cb_data_any.fl.seq_num = missing_seq_num;
jb->cb_data_any.fl.count = 1;
jb->callback(&jb->cb_data_any);
// the missing seqnum has been already requested in jb_put() and here we request it again only ONE time
if(jb->callback){
if(prev_missing_seq_num_start != missing_seq_num_start || prev_lasted_missing_seq_num_count != missing_seq_num_count){ // guard to request it only once
jb->cb_data_any.type = tdav_video_jb_cb_data_type_fl;
jb->cb_data_any.ssrc = frame->ssrc;
jb->cb_data_any.fl.seq_num = prev_missing_seq_num_start = missing_seq_num_start;
jb->cb_data_any.fl.count = prev_lasted_missing_seq_num_count = missing_seq_num_count;
jb->callback(&jb->cb_data_any);
}
postpone = tsk_true;
}
}
}
else{
TSK_DEBUG_INFO("frames_count(%lld)>=latency_max(%u)...decoding video frame even if pkts are missing :(", jb->frames_count, jb->latency_max);
jb->decode_last_seq_num_with_mark = -1; // unset()
}
if(!postpone){
@ -492,18 +482,29 @@ static void* TSK_STDCALL _tdav_video_jb_decode_thread_func(void *arg)
#if 1
now = tsk_time_now();
// comparison used as guard against time wrapping
delay = (now - x_decode_time);//(now > x_decode_time) ? (now - x_decode_time) : x_decode_duration/* do not use zero to avoid endless loop when there is no frame to display */;
if(delay > __toomuch_delay_to_be_valid){
TSK_DEBUG_INFO("Too much delay (%llu) in video jb. Reseting...", delay);
if(jb->frames_count > jb->latency_max){
x_decode_time = now;
next_decode_duration = 0;
}
else{
delay = ( (now > x_decode_time) ? (now - x_decode_time) : (x_decode_duration >> 1)/* do not use zero to avoid endless loop when there is no frame to display */ );
next_decode_duration = (delay > x_decode_duration) ? 0 : (x_decode_duration - delay);
x_decode_duration = (1000 / jb->fps);
x_decode_time += x_decode_duration;
}
//delay = /*(now - x_decode_time);*/(now > x_decode_time) ? (now - x_decode_time) : ( (jb->frames_count >= jb->latency_max) ? 0 : (x_decode_duration >> 1) )/* do not use zero to avoid endless loop when there is no frame to display */;
// delay = (jb->frames_count > jb->latency_max) ? 0 : ( (now > x_decode_time) ? (now - x_decode_time) : (x_decode_duration >> 1)/* do not use zero to avoid endless loop when there is no frame to display */ );
// comparison used as guard against time wrapping
/*if(delay > __toomuch_delay_to_be_valid){
TSK_DEBUG_INFO("Too much delay (%llu) in video jb. Reseting...", delay);
x_decode_time = now;
next_decode_duration = 0;
}
else*/{
//next_decode_duration = (delay > x_decode_duration) ? 0 : (x_decode_duration - delay);
//x_decode_duration = (1000 / jb->fps);
//x_decode_time += x_decode_duration;
}
//TSK_DEBUG_INFO("next_decode_timeout=%llu, delay = %llu", next_decode_duration, delay);

View File

@ -165,22 +165,28 @@ static int tdav_session_video_raw_cb(const tmedia_video_encode_result_xt* result
if(packet ){
tsk_size_t rtp_hdr_size;
if(!video->encoder.last_frame_time){
video->encoder.last_frame_time = tsk_time_now();
}
if(result->last_chunck){
#if 0
#if 0
#if 1
#if 1
/* http://www.cs.columbia.edu/~hgs/rtp/faq.html#timestamp-computed
For video, time clock rate is fixed at 90 kHz. The timestamps generated depend on whether the application can determine the frame number or not.
If it can or it can be sure that it is transmitting every frame with a fixed frame rate, the timestamp is governed by the nominal frame rate. Thus, for a 30 f/s video, timestamps would increase by 3,000 for each frame, for a 25 f/s video by 3,600 for each frame.
If a frame is transmitted as several RTP packets, these packets would all bear the same timestamp.
If the frame number cannot be determined or if frames are sampled aperiodically, as is typically the case for software codecs, the timestamp has to be computed from the system clock (e.g., gettimeofday())
*/
uint64_t now = tsk_time_now();
uint32_t duration = (uint32_t)(now - video->encoder.last_frame_time);
base->rtp_manager->rtp.timestamp += (duration * 90/* 90KHz */);
video->encoder.last_frame_time = now;
if(!video->encoder.last_frame_time){
// For the first frame it's not possible to compute the duration as there is no previous one.
// In this case, we trust the duration from the result (computed based on the codec fps and rate).
video->encoder.last_frame_time = tsk_time_now();
base->rtp_manager->rtp.timestamp += result->duration;
}
else{
uint64_t now = tsk_time_now();
uint32_t duration = (uint32_t)(now - video->encoder.last_frame_time);
base->rtp_manager->rtp.timestamp += (duration * 90/* 90KHz */);
video->encoder.last_frame_time = now;
}
#else
base->rtp_manager->rtp.timestamp = (uint32_t)(tsk_gettimeofday_ms() * 90/* 90KHz */);
#endif
@ -544,16 +550,18 @@ static int tdav_session_video_rtcp_cb(const void* callback_data, const trtp_rtcp
switch(psfb->fci_type){
case trtp_rtcp_psfb_fci_type_fir:
{
TSK_DEBUG_INFO("Receving RTCP-FIR (%u)", ((const trtp_rtcp_report_fb_t*)psfb)->ssrc_media);
TSK_DEBUG_INFO("Receiving RTCP-FIR (%u)", ((const trtp_rtcp_report_fb_t*)psfb)->ssrc_media);
_tdav_session_video_remote_requested_idr(video, ((const trtp_rtcp_report_fb_t*)psfb)->ssrc_media);
break;
}
case trtp_rtcp_psfb_fci_type_pli:
{
uint64_t now;
TSK_DEBUG_INFO("Receving RTCP-PLI (%u)", ((const trtp_rtcp_report_fb_t*)psfb)->ssrc_media);
TSK_DEBUG_INFO("Receiving RTCP-PLI (%u)", ((const trtp_rtcp_report_fb_t*)psfb)->ssrc_media);
now = tsk_time_now();
if((now - video->avpf.last_pli_time) < 500){ // more than one PLI in 500ms
// more than one PLI in 500ms ?
// "if" removed because PLI really means codec prediction chain is broken
/*if((now - video->avpf.last_pli_time) < 500)*/{
_tdav_session_video_remote_requested_idr(video, ((const trtp_rtcp_report_fb_t*)psfb)->ssrc_media);
}
video->avpf.last_pli_time = now;
@ -782,7 +790,7 @@ static int _tdav_session_video_decode(tdav_session_video_t* self, const trtp_rtp
// Convert decoded data to the consumer chroma and size
#define CONSUMER_NEED_DECODER (base->consumer->decoder.codec_id == tmedia_codec_id_none) // Otherwise, the consumer requires encoded frames
#define CONSUMER_IN_N_DISPLAY_MISMATCH (base->consumer->video.in.width != base->consumer->video.display.width || base->consumer->video.in.height != base->consumer->video.display.height)
#define CONSUMER_IN_N_DISPLAY_MISMATCH (!base->consumer->video.display.auto_resize && (base->consumer->video.in.width != base->consumer->video.display.width || base->consumer->video.in.height != base->consumer->video.display.height))
#define CONSUMER_DISPLAY_N_CODEC_MISMATCH (base->consumer->video.display.width != TMEDIA_CODEC_VIDEO(self->decoder.codec)->in.width || base->consumer->video.display.height != TMEDIA_CODEC_VIDEO(self->decoder.codec)->in.height)
#define CONSUMER_DISPLAY_N_CONVERTER_MISMATCH ( (self->conv.fromYUV420 && self->conv.fromYUV420->dstWidth != base->consumer->video.display.width) || (self->conv.fromYUV420 && self->conv.fromYUV420->dstHeight != base->consumer->video.display.height) )
#define CONSUMER_CHROMA_MISMATCH (base->consumer->video.display.chroma != TMEDIA_CODEC_VIDEO(self->decoder.codec)->in.chroma)
@ -805,7 +813,7 @@ static int _tdav_session_video_decode(tdav_session_video_t* self, const trtp_rtp
}
// update consumer size using the codec decoded values
// must be done here to avoid fooling "CONSUMER_INSIZE_MISMATCH"
// must be done here to avoid fooling "CONSUMER_IN_N_DISPLAY_MISMATCH" unless "auto_resize" option is enabled
base->consumer->video.in.width = TMEDIA_CODEC_VIDEO(self->decoder.codec)->in.width;//decoded width
base->consumer->video.in.height = TMEDIA_CODEC_VIDEO(self->decoder.codec)->in.height;//decoded height

View File

@ -42,7 +42,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(PSDK_DIR)include&quot;;&quot;$(DXSDK_DIR)include&quot;;..\thirdparties\common\include;..\thirdparties\win32\include;include;..\tinyMSRP\include;..\tinyRTP\include;..\tinyMEDIA\include;..\tinySDP\include;..\tinyNET\src;..\tinyDSHOW\include;..\tinySAK\src;..\thirdparties\win32\include\BroadVoice16\bvcommon;..\thirdparties\win32\include\BroadVoice16\bv16"
PreprocessorDefinitions="HAVE_SRTP=1;HAVE_CUDA=0;HAVE_G729=0;HAVE_BV16=0;HAVE_OPENCORE_AMR=1;HAVE_H264=1;HAVE_ILBC=0;HAVE_LIBGSM=1;HAVE_TINYDSHOW=1;HAVE_DSOUND_H=1;HAVE_WAVE_API=0;HAVE_FFMPEG=1;HAVE_SPEEX_DSP=1;HAVE_WEBRTC=1;HAVE_SPEEX_JB=1;HAVE_LIB_SPEEX=1;HAVE_LIBVPX=1;HAVE_LIBYUV=1;G192BITSTREAM=0;DEBUG_LEVEL=DEBUG_LEVEL_INFO;WIN32;_DEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;TINYDAV_EXPORTS"
PreprocessorDefinitions="HAVE_SRTP=1;HAVE_CUDA=0;HAVE_G729=0;HAVE_BV16=0;HAVE_OPENCORE_AMR=1;HAVE_H264=1;HAVE_ILBC=0;HAVE_LIBGSM=1;HAVE_LIBOPUS=1;HAVE_TINYDSHOW=1;HAVE_DSOUND_H=1;HAVE_WAVE_API=0;HAVE_FFMPEG=1;HAVE_SPEEX_DSP=1;HAVE_WEBRTC=1;HAVE_SPEEX_JB=1;HAVE_LIB_SPEEX=1;HAVE_LIBVPX=1;HAVE_LIBYUV=1;G192BITSTREAM=0;DEBUG_LEVEL=DEBUG_LEVEL_INFO;WIN32;_DEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;TINYDAV_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@ -64,7 +64,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="Winmm.lib &quot;$(OutDir)\tinySAK.lib&quot; &quot;$(OutDir)\tinyNET.lib&quot; &quot;$(OutDir)\tinyRTP.lib&quot; &quot;$(OutDir)\tinyMSRP.lib&quot; &quot;$(OutDir)\tinySDP.lib&quot; &quot;$(OutDir)\tinyMEDIA.lib&quot; &quot;$(OutDir)\tinyDSHOW.lib&quot; &quot;..\thirdparties\win32\lib\gsm\libgsm.a&quot; &quot;..\thirdparties\win32\lib\ilbc\libiLBC.a&quot; &quot;..\thirdparties\win32\lib\speex\libspeex.a&quot; &quot;..\thirdparties\win32\lib\speex\libspeexdsp.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavcodec.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavutil.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavcore.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libswscale.a&quot; &quot;..\thirdparties\win32\lib\libgcc.a&quot; &quot;..\thirdparties\win32\lib\libmingwex.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libx264.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libtheora.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libogg.a&quot; &quot;..\thirdparties\win32\lib\webrtc\aec.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\aec_sse2.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\apm_util.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\system_wrappers.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\spl.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\ns.lib&quot; &quot;..\thirdparties\win32\lib\libyuv\libyuv.lib&quot; &quot;..\thirdparties\win32\lib\vpx\vpxmt.lib&quot;"
AdditionalDependencies="Winmm.lib &quot;$(OutDir)\tinySAK.lib&quot; &quot;$(OutDir)\tinyNET.lib&quot; &quot;$(OutDir)\tinyRTP.lib&quot; &quot;$(OutDir)\tinyMSRP.lib&quot; &quot;$(OutDir)\tinySDP.lib&quot; &quot;$(OutDir)\tinyMEDIA.lib&quot; &quot;$(OutDir)\tinyDSHOW.lib&quot; &quot;..\thirdparties\win32\lib\opus\libopus.a&quot; &quot;..\thirdparties\win32\lib\gsm\libgsm.a&quot; &quot;..\thirdparties\win32\lib\ilbc\libiLBC.a&quot; &quot;..\thirdparties\win32\lib\speex\libspeex.a&quot; &quot;..\thirdparties\win32\lib\speex\libspeexdsp.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavcodec.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavutil.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavcore.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libswscale.a&quot; &quot;..\thirdparties\win32\lib\libgcc.a&quot; &quot;..\thirdparties\win32\lib\libmingwex.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libx264.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libtheora.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libogg.a&quot; &quot;..\thirdparties\win32\lib\webrtc\aec.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\aec_sse2.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\apm_util.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\system_wrappers.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\spl.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\ns.lib&quot; &quot;..\thirdparties\win32\lib\libyuv\libyuv.lib&quot; &quot;..\thirdparties\win32\lib\vpx\vpxmt.lib&quot;"
LinkIncremental="2"
IgnoreDefaultLibraryNames="MSVCRT;LIBCMTD;LIBCMT"
GenerateDebugInformation="true"
@ -122,7 +122,7 @@
Name="VCCLCompilerTool"
EnableIntrinsicFunctions="false"
AdditionalIncludeDirectories="&quot;$(PSDK_DIR)include&quot;;&quot;$(DXSDK_DIR)include&quot;;..\thirdparties\common\include;..\thirdparties\win32\include;include;..\tinyMSRP\include;..\tinyRTP\include;..\tinyMEDIA\include;..\tinySDP\include;..\tinyNET\src;..\tinyDSHOW\include;..\tinySAK\src;..\thirdparties\win32\include\BroadVoice16\bvcommon;..\thirdparties\win32\include\BroadVoice16\bv16"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;TINYDAV_EXPORTS;DEBUG_LEVEL=DEBUG_LEVEL_INFOS;HAVE_SRTP=1;HAVE_CUDA=0;HAVE_G729=0;HAVE_BV16=0;HAVE_H264=1;HAVE_OPENCORE_AMR=1;HAVE_ILBC=0;HAVE_LIBGSM=1;HAVE_TINYDSHOW=1;HAVE_DSOUND_H=1;HAVE_WAVE_API=0;HAVE_FFMPEG=1;HAVE_WEBRTC=1;HAVE_SPEEX_DSP=1;HAVE_SPEEX_JB=1;HAVE_LIB_SPEEX=1;HAVE_LIBVPX=1;HAVE_LIBYUV=1;G192BITSTREAM=0;_WIN32_WINNT=0x0501"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;TINYDAV_EXPORTS;DEBUG_LEVEL=DEBUG_LEVEL_INFOS;HAVE_SRTP=1;HAVE_CUDA=0;HAVE_G729=0;HAVE_BV16=0;HAVE_H264=1;HAVE_OPENCORE_AMR=1;HAVE_ILBC=0;HAVE_LIBGSM=1;HAVE_LIBOPUS=1;HAVE_TINYDSHOW=1;HAVE_DSOUND_H=1;HAVE_WAVE_API=0;HAVE_FFMPEG=1;HAVE_WEBRTC=1;HAVE_SPEEX_DSP=1;HAVE_SPEEX_JB=1;HAVE_LIB_SPEEX=1;HAVE_LIBVPX=1;HAVE_LIBYUV=1;G192BITSTREAM=0;_WIN32_WINNT=0x0501"
RuntimeLibrary="2"
EnableFunctionLevelLinking="false"
UsePrecompiledHeader="0"
@ -143,7 +143,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="Winmm.lib $(OutDir)\tinySAK.lib $(OutDir)\tinyNET.lib $(OutDir)\tinyRTP.lib $(OutDir)\tinyMSRP.lib $(OutDir)\tinySDP.lib $(OutDir)\tinyMEDIA.lib $(OutDir)\tinyDSHOW.lib &quot;..\thirdparties\win32\lib\gsm\libgsm.a&quot; &quot;..\thirdparties\win32\lib\ilbc\libiLBC.a&quot; &quot;..\thirdparties\win32\lib\speex\libspeex.a&quot; &quot;..\thirdparties\win32\lib\speex\libspeexdsp.a&quot; ..\thirdparties\win32\lib\libgcc.a ..\thirdparties\win32\lib\libmingwex.a &quot;..\thirdparties\win32\lib\ffmpeg\libavcodec.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavutil.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libswscale.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavcore.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libx264.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libtheora.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libogg.a&quot; &quot;..\thirdparties\win32\lib\BroadVoice16\libbv16.a&quot; &quot;..\thirdparties\win32\lib\webrtc\aec.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\aec_sse2.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\apm_util.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\system_wrappers.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\spl.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\ns.lib&quot; &quot;..\thirdparties\win32\lib\libyuv\libyuv.lib&quot; &quot;..\thirdparties\win32\lib\vpx\vpxmt.lib&quot;"
AdditionalDependencies="Winmm.lib $(OutDir)\tinySAK.lib $(OutDir)\tinyNET.lib $(OutDir)\tinyRTP.lib $(OutDir)\tinyMSRP.lib $(OutDir)\tinySDP.lib $(OutDir)\tinyMEDIA.lib $(OutDir)\tinyDSHOW.lib &quot;..\thirdparties\win32\lib\opus\libopus.a&quot; &quot;..\thirdparties\win32\lib\gsm\libgsm.a&quot; &quot;..\thirdparties\win32\lib\ilbc\libiLBC.a&quot; &quot;..\thirdparties\win32\lib\speex\libspeex.a&quot; &quot;..\thirdparties\win32\lib\speex\libspeexdsp.a&quot; ..\thirdparties\win32\lib\libgcc.a ..\thirdparties\win32\lib\libmingwex.a &quot;..\thirdparties\win32\lib\ffmpeg\libavcodec.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavutil.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libswscale.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libavcore.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libx264.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libtheora.a&quot; &quot;..\thirdparties\win32\lib\ffmpeg\libogg.a&quot; &quot;..\thirdparties\win32\lib\BroadVoice16\libbv16.a&quot; &quot;..\thirdparties\win32\lib\webrtc\aec.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\aec_sse2.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\apm_util.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\system_wrappers.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\spl.lib&quot; &quot;..\thirdparties\win32\lib\webrtc\ns.lib&quot; &quot;..\thirdparties\win32\lib\libyuv\libyuv.lib&quot; &quot;..\thirdparties\win32\lib\vpx\vpxmt.lib&quot;"
LinkIncremental="1"
IgnoreDefaultLibraryNames="MSVCRTD;LIBCMT"
GenerateDebugInformation="false"
@ -382,6 +382,14 @@
>
</File>
</Filter>
<Filter
Name="opus"
>
<File
RelativePath=".\include\tinydav\codecs\opus\tdav_codec_opus.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="audio"
@ -750,6 +758,14 @@
>
</File>
</Filter>
<Filter
Name="opus"
>
<File
RelativePath=".\src\codecs\opus\tdav_codec_opus.c"
>
</File>
</Filter>
</Filter>
<Filter
Name="audio"

View File

@ -95,12 +95,14 @@ Must starts at 96 to be conform to RFC 5761 (rtcp-mux)
#define TMEDIA_CODEC_FORMAT_AAC "109"
#define TMEDIA_CODEC_FORMAT_AACPLUS "110"
#define TMEDIA_CODEC_FORMAT_AMR_NB_BE "111"
#define TMEDIA_CODEC_FORMAT_AMR_NB_OA "112"
#define TMEDIA_CODEC_FORMAT_AMR_WB_BE "113"
#define TMEDIA_CODEC_FORMAT_AMR_WB_OA "114"
#define TMEDIA_CODEC_FORMAT_OPUS "111"
#define TMEDIA_CODEC_FORMAT_BV16 "115"
#define TMEDIA_CODEC_FORMAT_AMR_NB_BE "112"
#define TMEDIA_CODEC_FORMAT_AMR_NB_OA "113"
#define TMEDIA_CODEC_FORMAT_AMR_WB_BE "114"
#define TMEDIA_CODEC_FORMAT_AMR_WB_OA "115"
#define TMEDIA_CODEC_FORMAT_BV16 "116"
#define TMEDIA_CODEC_FORMAT_MP4V_ES "121"
@ -172,9 +174,20 @@ tmedia_codec_id_t;
/** cast any pointer to @ref tmedia_codec_t* object */
#define TMEDIA_CODEC(self) ((tmedia_codec_t*)(self))
#define TMEDIA_CODEC_PCM_FRAME_SIZE(self) ((TMEDIA_CODEC((self))->plugin->audio.ptime * TMEDIA_CODEC((self))->plugin->rate)/1000)
#define TMEDIA_CODEC_RATE(self) (TMEDIA_CODEC((self))->plugin->rate)
//#define TMEDIA_CODEC_FRAMES_COUNT(buff_size) (((buff_size))/TMEDIA_CODEC_FRAME_SIZE(self))
#define TMEDIA_CODEC_RATE_DECODING(self) (TMEDIA_CODEC((self))->in.rate)
#define TMEDIA_CODEC_RATE_ENCODING(self) (TMEDIA_CODEC((self))->out.rate)
#define TMEDIA_CODEC_PTIME_AUDIO_DECODING(self) (TMEDIA_CODEC_AUDIO((self))->in.ptime)
#define TMEDIA_CODEC_PTIME_AUDIO_ENCODING(self) (TMEDIA_CODEC_AUDIO((self))->out.ptime)
#define TMEDIA_CODEC_CHANNELS_AUDIO_DECODING(self) (TMEDIA_CODEC_AUDIO((self))->in.channels)
#define TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(self) (TMEDIA_CODEC_AUDIO((self))->out.channels)
#define TMEDIA_CODEC_PCM_FRAME_SIZE_AUDIO_DECODING(self) ((TMEDIA_CODEC_PTIME_AUDIO_DECODING((self)) * TMEDIA_CODEC_RATE_DECODING((self)))/1000)
#define TMEDIA_CODEC_PCM_FRAME_SIZE_AUDIO_ENCODING(self) ((TMEDIA_CODEC_PTIME_AUDIO_ENCODING((self)) * TMEDIA_CODEC_RATE_ENCODING((self)))/1000)
#define TMEDIA_CODEC_FRAME_DURATION_AUDIO_ENCODING(self) (TMEDIA_CODEC_PCM_FRAME_SIZE_AUDIO_ENCODING(self) * TMEDIA_CODEC_AUDIO((self))->out.timestamp_multiplier)
/** callbacks for video codecs */
typedef int (*tmedia_codec_video_enc_cb_f)(const tmedia_video_encode_result_xt* result);
@ -217,6 +230,15 @@ typedef struct tmedia_codec_s
char* neg_format;
//! whether this is a passthrough codec
tsk_bool_t passthrough;
struct{
// !negotiated decoding rate (for codecs with dynamic rate, e.g. opus)
uint32_t rate;
} in; //decoding direction
struct{
// !negotiated encoding rate (for codecs with dynamic rate, e.g. opus)
uint32_t rate;
} out; //encoding direction
//! plugin used to create the codec
const struct tmedia_codec_plugin_def_s* plugin;
@ -304,6 +326,23 @@ TINYMEDIA_API int tmedia_codec_deinit(tmedia_codec_t* self);
typedef struct tmedia_codec_audio_s
{
TMEDIA_DECLARE_CODEC;
struct{
// !negotiated decoding ptime
uint8_t ptime;
// !negotiated decoding channels
int8_t channels;
// ! timestamp multiplier
int8_t timestamp_multiplier;
} in; //decoding direction
struct{
// !negotiated decoding ptime
uint8_t ptime;
// !negotiated encoding channels
int8_t channels;
// ! timestamp multiplier
int8_t timestamp_multiplier;
} out; //encoding direction
}
tmedia_codec_audio_t;
@ -323,6 +362,7 @@ tmedia_codec_audio_t;
#define TMEDIA_CODEC_AUDIO(self) ((tmedia_codec_audio_t*)(self))
#define tmedia_codec_audio_init(self, name, desc, format) tmedia_codec_init(TMEDIA_CODEC(self), tmedia_audio, name, desc, format)
#define tmedia_codec_audio_deinit(self) tmedia_codec_deinit(TMEDIA_CODEC(self))
TINYMEDIA_API int8_t tmedia_codec_audio_get_timestamp_multiplier(tmedia_codec_id_t id, uint32_t sample_rate);
/** Video codec */
typedef struct tmedia_codec_video_s

View File

@ -100,6 +100,10 @@ TINYMEDIA_API tsk_size_t tmedia_defaults_get_rtpbuff_size();
TINYMEDIA_API int tmedia_defaults_set_avpf_tail(tsk_size_t tail_min, tsk_size_t tail_max);
TINYMEDIA_API tsk_size_t tmedia_defaults_get_avpf_tail_min();
TINYMEDIA_API tsk_size_t tmedia_defaults_get_avpf_tail_max();
TINYMEDIA_API int tmedia_defaults_set_opus_maxcapturerate(uint32_t opus_maxcapturerate);
TINYMEDIA_API uint32_t tmedia_defaults_get_opus_maxcapturerate();
TINYMEDIA_API int tmedia_defaults_set_opus_maxplaybackrate(uint32_t opus_maxplaybackrate);
TINYMEDIA_API uint32_t tmedia_defaults_get_opus_maxplaybackrate();
TMEDIA_END_DECLS

View File

@ -80,11 +80,22 @@ int tmedia_codec_init(tmedia_codec_t* self, tmedia_type_t type, const char* name
tsk_strupdate(&self->name, name);
tsk_strupdate(&self->desc,desc);
tsk_strupdate(&self->format, format);
if(!self->in.rate) self->in.rate = self->plugin->rate;
if(!self->out.rate) self->out.rate = self->plugin->rate;
if(type & tmedia_audio){
tmedia_codec_audio_t* audio = TMEDIA_CODEC_AUDIO(self);
if(!audio->in.ptime) audio->in.ptime = self->plugin->audio.ptime;
if(!audio->out.ptime) audio->out.ptime = self->plugin->audio.ptime;
if(!audio->in.channels) audio->in.channels = self->plugin->audio.channels;
if(!audio->out.channels) audio->out.channels = self->plugin->audio.channels;
if(!audio->in.timestamp_multiplier) audio->in.timestamp_multiplier = tmedia_codec_audio_get_timestamp_multiplier(self->id, self->in.rate);
if(!audio->out.timestamp_multiplier) audio->out.timestamp_multiplier = tmedia_codec_audio_get_timestamp_multiplier(self->id, self->out.rate);
}
// Video flipping: For backward compatibility we have to initialize the default values
// according to the CFLAGS: 'FLIP_ENCODED_PICT' and 'FLIP_DECODED_PICT'. At any time you
// can update thse values (e.g. when the device switch from landscape to portrait) using video_session->set();
if(type & tmedia_video){
else if(type & tmedia_video){
tmedia_codec_video_t* video = TMEDIA_CODEC_VIDEO(self);
#if FLIP_ENCODED_PICT
video->out.flip = tsk_true;
@ -722,4 +733,26 @@ int tmedia_codec_video_set_dec_callback(tmedia_codec_video_t *self, tmedia_codec
self->in.callback = callback;
self->in.result.usr_data = callback_data;
return 0;
}
int8_t tmedia_codec_audio_get_timestamp_multiplier(tmedia_codec_id_t id, uint32_t sample_rate)
{
switch(id){
case tmedia_codec_id_opus:
{
// draft-spittka-payload-rtp-opus-03 - 4.1. RTP Header Usage
switch(sample_rate){
case 8000: return 6;
case 12000: return 4;
case 16000: return 3;
case 24000: return 2;
default: case 48000: return 1;
}
break;
}
default:
{
return 1;
}
}
}

View File

@ -63,6 +63,8 @@ static tsk_bool_t __video_zeroartifacts_enabled = tsk_false; // Requires from re
static tsk_size_t __rtpbuff_size = 0x1FFFE; // Network buffer size use for RTP (SO_RCVBUF, SO_SNDBUF)
static tsk_size_t __avpf_tail_min = 20; // Min size for tail used to honor RTCP-NACK requests
static tsk_size_t __avpf_tail_max = 160; // Max size for tail used to honor RTCP-NACK requests
static uint32_t __opus_maxcapturerate = 16000; // supported: 8k,12k,16k,24k,48k. IMPORTANT: only 8k and 16k will work with WebRTC AEC
static uint32_t __opus_maxplaybackrate = 48000; // supported: 8k,12k,16k,24k,48k
int tmedia_defaults_set_profile(tmedia_profile_t profile){
__profile = profile;
@ -371,3 +373,24 @@ tsk_size_t tmedia_defaults_get_avpf_tail_min(){
tsk_size_t tmedia_defaults_get_avpf_tail_max(){
return __avpf_tail_max;
}
int tmedia_defaults_set_opus_maxcapturerate(uint32_t opus_maxcapturerate){
switch(opus_maxcapturerate){
case 8000: case 12000: case 16000: case 24000: case 48000: __opus_maxcapturerate = opus_maxcapturerate; return 0;
default: TSK_DEBUG_ERROR("%u not valid for opus_maxcapturerate", opus_maxcapturerate); return -1;
}
}
uint32_t tmedia_defaults_get_opus_maxcapturerate(){
return __opus_maxcapturerate;
}
int tmedia_defaults_set_opus_maxplaybackrate(uint32_t opus_maxplaybackrate){
switch(opus_maxplaybackrate){
case 8000: case 12000: case 16000: case 24000: case 48000: __opus_maxplaybackrate = opus_maxplaybackrate; return 0;
default: TSK_DEBUG_ERROR("%u not valid for opus_maxplaybackrate", opus_maxplaybackrate); return -1;
}
}
uint32_t tmedia_defaults_get_opus_maxplaybackrate(){
return __opus_maxplaybackrate;
}

View File

@ -51,6 +51,10 @@
# define LONG_MAX 2147483647L
#endif
#if !defined(TNET_ICE_DEBUG_STATE_MACHINE)
# define TNET_ICE_DEBUG_STATE_MACHINE 1
#endif
/**@ingroup tnet_nat_group
* Estimate of the round-trip time (RTT) in millisecond.
*/
@ -312,6 +316,7 @@ tnet_ice_ctx_t* tnet_ice_ctx_create(tsk_bool_t is_ice_jingle, tsk_bool_t use_ipv
tnet_ice_utils_set_ufrag(&ctx->ufrag);
tnet_ice_utils_set_pwd(&ctx->pwd);
ctx->fsm->debug = TNET_ICE_DEBUG_STATE_MACHINE;
tsk_fsm_set_callback_terminated(ctx->fsm, TSK_FSM_ONTERMINATED_F(_tnet_ice_ctx_fsm_OnTerminated), (const void*)ctx);
tsk_fsm_set(ctx->fsm,
// (Started) -> (GatherHostCandidates) -> (GatheringHostCandidates)
@ -960,11 +965,12 @@ static int _tnet_ice_ctx_fsm_GatheringHostCandidatesDone_2_GatheringReflexiveCan
tnet_stun_response_t *response = tsk_null;
const tsk_list_item_t *item;
tnet_ice_candidate_t* candidate;
tnet_fd_t fds[40] = { -1 };
tnet_fd_t fds[40] = { TNET_INVALID_FD }; // -1, then zeros
tnet_fd_t fds_skipped[40] = { TNET_INVALID_FD }; // -1, then zeros
uint16_t fds_count = 0;
tnet_fd_t fd_max = -1;
fd_set set;
tsk_size_t srflx_addr_count = 0, host_addr_count = 0;
tsk_size_t srflx_addr_count_added = 0, srflx_addr_count_skipped = 0, host_addr_count = 0;
long tv_sec, tv_usec; //very important to save these values as timeval could be modified by select() - happens on iOS -
self = va_arg(*app, tnet_ice_ctx_t *);
@ -976,6 +982,11 @@ static int _tnet_ice_ctx_fsm_GatheringHostCandidatesDone_2_GatheringReflexiveCan
goto bail;
}
// set all default values to -1
// = {{ -1 }} will only set the first element
for(i = 0; i < sizeof(fds)/sizeof(fds[0]); ++i) fds[i] = TNET_INVALID_FD;
for(i = 0; i < sizeof(fds_skipped)/sizeof(fds_skipped[0]); ++i) fds_skipped[i] = TNET_INVALID_FD;
rto = self->RTO;
rc = self->Rc;
tv.tv_sec = tv_sec = 0;
@ -1004,14 +1015,14 @@ static int _tnet_ice_ctx_fsm_GatheringHostCandidatesDone_2_GatheringReflexiveCan
e.g. 0 ms, 500 ms, 1500 ms, 3500 ms, 7500ms, 15500 ms, and 31500 ms
*/
for(i = 0; (i < rc && self->is_started && srflx_addr_count < host_addr_count); ++i){
for(i = 0; (i < rc && self->is_started && ((srflx_addr_count_added + srflx_addr_count_skipped) < host_addr_count)); ++i){
tv_sec += rto/1000;
tv_usec += (rto % 1000) * 1000;
if(tv_usec >= 1000000){ // > 1000000 is invalid and produce EINVAL when passed to select(iOS)
tv_usec -= 1000000;
tv_sec++;
}
// retore values for new select
// restore values for new select
tv.tv_sec = tv_sec;
tv.tv_usec = tv_usec;
@ -1038,7 +1049,7 @@ static int _tnet_ice_ctx_fsm_GatheringHostCandidatesDone_2_GatheringReflexiveCan
}
else if(ret == 0){
// timeout
TSK_DEBUG_INFO("STUN request timedout at %d", i);
TSK_DEBUG_INFO("STUN request timedout at %d/%d", i, rc-1);
rto <<= 1;
continue;
}
@ -1082,6 +1093,8 @@ static int _tnet_ice_ctx_fsm_GatheringHostCandidatesDone_2_GatheringReflexiveCan
ret = tnet_ice_candidate_process_stun_response((tnet_ice_candidate_t*)candidate_curr, response, fd);
if(!tsk_strnullORempty(candidate_curr->stun.srflx_addr)){
if(tsk_striequals(candidate_curr->connection_addr, candidate_curr->stun.srflx_addr) && candidate_curr->port == candidate_curr->stun.srflx_port){
tsk_size_t j;
tsk_bool_t already_skipped = tsk_false;
/* refc 5245- 4.1.3. Eliminating Redundant Candidates
Next, the agent eliminates redundant candidates. A candidate is
@ -1092,7 +1105,22 @@ static int _tnet_ice_ctx_fsm_GatheringHostCandidatesDone_2_GatheringReflexiveCan
server reflexive candidate and a host candidate will be redundant
when the agent is not behind a NAT. The agent SHOULD eliminate the
redundant candidate with the lower priority. */
TSK_DEBUG_INFO("Skipping redundant candidate address=%s and port=%d", candidate_curr->stun.srflx_addr, candidate_curr->stun.srflx_port);
for(j = 0; (fds_skipped[j] != TNET_INVALID_FD && j < (sizeof(fds_skipped)/sizeof(fds_skipped[0]))); ++j){
if(fds_skipped[j] == fd){
already_skipped = tsk_true;
break;
}
}
if(!already_skipped){
++srflx_addr_count_skipped;
fds_skipped[j] = fd;
}
TSK_DEBUG_INFO("Skipping redundant candidate address=%s and port=%d, fd=%d, already_skipped(%u)=%s",
candidate_curr->stun.srflx_addr,
candidate_curr->stun.srflx_port,
fd,
j, already_skipped ? "yes" : "no");
}
else{
char* foundation = tsk_strdup("srflx");
@ -1101,7 +1129,7 @@ static int _tnet_ice_ctx_fsm_GatheringHostCandidatesDone_2_GatheringReflexiveCan
new_cand = tnet_ice_candidate_create(tnet_ice_cand_type_srflx, candidate_curr->socket, candidate_curr->is_ice_jingle, candidate_curr->is_rtp, self->is_video, self->ufrag, self->pwd, foundation);
TSK_FREE(foundation);
if(new_cand){
++srflx_addr_count;
++srflx_addr_count_added;
tsk_list_lock(self->candidates_local);
tnet_ice_candidate_set_rflx_addr(new_cand, candidate_curr->stun.srflx_addr, candidate_curr->stun.srflx_port);
tsk_list_push_back_data(self->candidates_local, (void**)&new_cand);
@ -1125,7 +1153,8 @@ static int _tnet_ice_ctx_fsm_GatheringHostCandidatesDone_2_GatheringReflexiveCan
bail:
if(srflx_addr_count > 0) ret = 0; // Hack the returned value if we have at least one success (happens when timeouts)
TSK_DEBUG_INFO("srflx_addr_count_added=%u, srflx_addr_count_skipped=%u", srflx_addr_count_added, srflx_addr_count_skipped);
if((srflx_addr_count_added + srflx_addr_count_skipped) > 0) ret = 0; // Hack the returned value if we have at least one success (happens when timeouts)
if(self->is_started){
if(ret == 0){
ret = _tnet_ice_ctx_fsm_act_async(self, _fsm_action_Success);

View File

@ -602,7 +602,7 @@ const tnet_ice_pair_t* tnet_ice_pairs_find_by_response(tnet_ice_pairs_L_t* pairs
tnet_ice_utils_stun_address_tostring(xmapped_addr ? xmapped_addr->xaddress : mapped_addr->address, xmapped_addr ? xmapped_addr->family : mapped_addr->family, &mapped_addr_str);
mapped_port = xmapped_addr ? xmapped_addr->xport : mapped_addr->port;
if((mapped_port != pair->candidate_offer->port || !tsk_striequals(mapped_addr_str, pair->candidate_offer->connection_addr))){
TSK_DEBUG_INFO("Mapped address different than local connection address...probably symetric NAT: %s#%s and %u#%u",
TSK_DEBUG_INFO("Mapped address different than local connection address...probably symetric NAT: %s#%s or %u#%u",
pair->candidate_offer->connection_addr, mapped_addr_str,
pair->candidate_offer->port, mapped_port);
// do we really need to add new local candidate?

View File

@ -48,6 +48,7 @@ typedef enum tnet_transport_event_type_e
event_data,
event_closed,
event_error,
event_removed,
event_connected,
event_accepted,

View File

@ -145,7 +145,7 @@ int tnet_transport_remove_socket(const tnet_transport_handle_t *handle, tnet_fd_
int ret = -1;
tsk_size_t i;
tsk_bool_t found = tsk_false;
tnet_fd_t fd = *pfd;
tnet_fd_t fd = *pfd;
TSK_DEBUG_INFO("Removing socket %d", fd);
@ -166,8 +166,9 @@ int tnet_transport_remove_socket(const tnet_transport_handle_t *handle, tnet_fd_
tsk_bool_t self_ref = (&context->sockets[i]->fd == pfd);
removeSocket(i, context); // sockets[i] will be destroyed
found = tsk_true;
TSK_RUNNABLE_ENQUEUE(transport, event_removed, transport->callback_data, fd);
if(!self_ref){ // if self_ref then, pfd no longer valid after removeSocket()
*pfd = TNET_INVALID_FD;
*pfd = TNET_INVALID_FD;
}
break;
}

View File

@ -204,6 +204,7 @@ int tnet_transport_remove_socket(const tnet_transport_handle_t *handle, tnet_fd_
if(context->sockets[i]->fd == *fd){
removeSocket(i, context);
found = tsk_true;
TSK_RUNNABLE_ENQUEUE(transport, event_removed, transport->callback_data, *fd);
*fd = TNET_INVALID_FD;
break;
}

View File

@ -68,8 +68,8 @@ int trtp_srtp_ctx_internal_init(struct trtp_srtp_ctx_internal_xs* ctx, int32_t t
ctx->policy.key = (unsigned char*)ctx->key_bin;
ctx->policy.ssrc.type = ssrc_any_outbound;
ctx->policy.ssrc.value = ssrc;
ctx->policy.window_size = 1024;
ctx->policy.allow_repeat_tx = 0;
ctx->policy.window_size = 2048;
ctx->policy.allow_repeat_tx = 1;
if((srtp_err = srtp_create(&ctx->session, &ctx->policy)) != err_status_ok){
TSK_DEBUG_ERROR("srtp_create() failed");
return -3;
@ -238,8 +238,8 @@ int trtp_srtp_set_crypto(struct trtp_manager_s* rtp_mgr, const char* crypto_line
tsk_base64_decode((const uint8_t*)srtp_ctx->rtp.key_str, tsk_strlen(srtp_ctx->rtp.key_str), (char**)&key_bin);
srtp_ctx->rtp.policy.key = key_bin;
srtp_ctx->rtp.policy.ssrc.type = idx == TRTP_SRTP_LINE_IDX_REMOTE ? ssrc_any_inbound : ssrc_any_outbound;
srtp_ctx->rtp.policy.window_size = 1024;
srtp_ctx->rtp.policy.allow_repeat_tx = 0;
srtp_ctx->rtp.policy.window_size = 2048;
srtp_ctx->rtp.policy.allow_repeat_tx = 1;
if((srtp_err = srtp_create(&srtp_ctx->rtp.session, &srtp_ctx->rtp.policy)) != err_status_ok){
TSK_DEBUG_ERROR("srtp_create() failed: %d", srtp_err);
return -3;
@ -288,8 +288,8 @@ int trtp_srtp_set_key_and_salt(trtp_manager_t* rtp_mgr, trtp_srtp_crypto_type_t
srtp_ctx->policy.key = (unsigned char *)srtp_ctx->key_bin;
srtp_ctx->policy.ssrc.type = idx == TRTP_SRTP_LINE_IDX_REMOTE ? ssrc_any_inbound : ssrc_any_outbound;
srtp_ctx->policy.window_size = 1024;
srtp_ctx->policy.allow_repeat_tx = 0;
srtp_ctx->policy.window_size = 2048;
srtp_ctx->policy.allow_repeat_tx = 1;
if((srtp_err = srtp_create(&srtp_ctx->session, &srtp_ctx->policy)) != err_status_ok){
TSK_DEBUG_ERROR("srtp_create() failed: %d", srtp_err);
return -3;

View File

@ -61,11 +61,9 @@ TSK_BEGIN_DECLS
#define TSK_PARSER_SET_STRING(string) \
{ \
int len = (int)(p - tag_start); \
TSK_FREE(string); \
if(len && tag_start){ \
if(string){ \
TSK_FREE(string); \
} \
string = tsk_calloc(len+1, sizeof(char)), memcpy(string, tag_start, len); \
string = (char*)tsk_calloc(len+1, sizeof(char)), memcpy(string, tag_start, len); \
} \
}

View File

@ -69,7 +69,15 @@ TSIP_BEGIN_DECLS
#define TSIP_DIALOG_SIGNAL_2(self, code, phrase, message) \
tsip_event_signal_2(tsip_event_dialog, TSIP_DIALOG(self)->ss, code, phrase, message)
#define TSIP_DIALOG_SHUTDOWN_TIMEOUT 2000 /* miliseconds. */
#if !defined(TSIP_DIALOG_SHUTDOWN_TIMEOUT)
# define TSIP_DIALOG_SHUTDOWN_TIMEOUT 2000 /* miliseconds. */
#endif
#if !defined(TSIP_DIALOG_INVALID_ID)
# define TSIP_DIALOG_INVALID_ID 0
#endif
typedef uint64_t tsip_dialog_id_t;
typedef enum tsip_dialog_state_e
{
@ -116,6 +124,7 @@ typedef struct tsip_dialog_s
TSK_DECLARE_OBJECT;
tsip_dialog_type_t type;
tsip_dialog_id_t id;
tsk_fsm_t* fsm;
@ -127,6 +136,8 @@ typedef struct tsip_dialog_s
tsk_bool_t initialized;
tsk_bool_t running;
tnet_fd_t connected_fd;
struct{
char* phrase;
short code;
@ -178,6 +189,7 @@ int tsip_dialog_getCKIK(tsip_dialog_t *self, AKA_CK_T *ck, AKA_IK_T *ik);
int tsip_dialog_init(tsip_dialog_t *self, tsip_dialog_type_t type, const char* call_id, tsip_ssession_t* ss, tsk_fsm_state_id curr, tsk_fsm_state_id term);
int tsip_dialog_fsm_act(tsip_dialog_t* self, tsk_fsm_action_id , const tsip_message_t* , const tsip_action_handle_t*);
tsk_bool_t tsip_dialog_keep_action(const tsip_dialog_t* self, const tsip_response_t *response);
int tsip_dialog_set_connected_fd(tsip_dialog_t* self, tnet_fd_t fd);
int tsip_dialog_set_curr_action(tsip_dialog_t* self, const tsip_action_t* action);
int tsip_dialog_set_lasterror(tsip_dialog_t* self, const char* phrase, short code);
int tsip_dialog_set_lasterror_2(tsip_dialog_t* self, const char* phrase, short code, const tsip_message_t *message);

View File

@ -66,9 +66,13 @@ tsip_dialog_layer_t* tsip_dialog_layer_create(tsip_stack_t* stack);
TINYSIP_API tsip_dialog_t* tsip_dialog_layer_find_by_ss(tsip_dialog_layer_t *self, const tsip_ssession_handle_t *ss);
tsip_dialog_t* tsip_dialog_layer_find_by_ssid(tsip_dialog_layer_t *self, tsip_ssession_id_t ssid);
tsip_dialog_t* tsip_dialog_layer_find_by_callid(tsip_dialog_layer_t *self, const char* callid);
tsk_bool_t tsip_dialog_layer_have_dialog_with_callid(const tsip_dialog_layer_t *self, const char* callid);
TINYSIP_API int tsip_dialog_layer_shutdownAll(tsip_dialog_layer_t *self);
int tsip_dialog_layer_signal_transport_error(tsip_dialog_layer_t *self);
int tsip_dialog_layer_signal_stack_disconnected(tsip_dialog_layer_t *self);
int tsip_dialog_layer_signal_peer_disconnected(tsip_dialog_layer_t *self, const struct tsip_transport_stream_peer_s* peer);
int tsip_dialog_layer_remove_callid_from_stream_peers(tsip_dialog_layer_t *self, const char* callid);
tsip_dialog_t* tsip_dialog_layer_new(tsip_dialog_layer_t *self, tsip_dialog_type_t type, const tsip_ssession_t *ss);
int tsip_dialog_layer_remove(tsip_dialog_layer_t *self, const tsip_dialog_t *dialog);

View File

@ -38,6 +38,7 @@
#include "tsk_object.h"
#include "tsk_list.h"
#include "tsk_string.h"
TSIP_BEGIN_DECLS
@ -78,6 +79,9 @@ typedef struct tsip_transport_stream_peer_s
tsk_buffer_t *rcv_buff_stream;
tsk_buffer_t *snd_buff_stream;
// list of dialogs managed by this peer
tsk_strings_L_t *dialogs_cids;
// temp buffers used to send/recv websocket data before (un)masking
struct{
void* rcv_buffer;
@ -125,17 +129,22 @@ int tsip_transport_deinit(tsip_transport_t* self);
int tsip_transport_tls_set_certs(tsip_transport_t *self, const char* ca, const char* pbk, const char* pvk);
tsk_size_t tsip_transport_send(const tsip_transport_t* self, const char *branch, tsip_message_t *msg, const char* destIP, int32_t destPort);
tsk_size_t tsip_transport_send_raw(const tsip_transport_t* self, const char* dst_host, tnet_port_t dst_port, const void* data, tsk_size_t size);
tsk_size_t tsip_transport_send_raw_ws(const tsip_transport_t* self, tnet_fd_t local_fd, const void* data, tsk_size_t size);
tsk_size_t tsip_transport_send_raw(const tsip_transport_t* self, const char* dst_host, tnet_port_t dst_port, const void* data, tsk_size_t size, const char* callid);
tsk_size_t tsip_transport_send_raw_ws(const tsip_transport_t* self, tnet_fd_t local_fd, const void* data, tsk_size_t size, const char* callid);
tsip_uri_t* tsip_transport_get_uri(const tsip_transport_t *self, int lr);
int tsip_transport_add_stream_peer_2(tsip_transport_t *self, tnet_fd_t local_fd, enum tnet_socket_type_e type, tsk_bool_t connected, const char* remote_host, tnet_port_t remote_port);
#define tsip_transport_add_stream_peer(self, local_fd, type, connected) tsip_transport_add_stream_peer_2((self), (local_fd), (type), (connected), tsk_null, 0)
tsip_transport_stream_peer_t* tsip_transport_find_stream_peer_by_local_fd(tsip_transport_t *self, tnet_fd_t local_fd);
tsip_transport_stream_peer_t* tsip_transport_pop_stream_peer_by_local_fd(tsip_transport_t *self, tnet_fd_t local_fd);
tsip_transport_stream_peer_t* tsip_transport_find_stream_peer_by_remote_ip(tsip_transport_t *self, const char* remote_ip, tnet_port_t remote_port, enum tnet_socket_type_e type);
tsk_bool_t tsip_transport_have_stream_peer_with_remote_ip(tsip_transport_t *self, const char* remote_ip, tnet_port_t remote_port, enum tnet_socket_type_e type);
tsk_bool_t tsip_transport_have_stream_peer_with_local_fd(tsip_transport_t *self, tnet_fd_t local_fd);
int tsip_transport_remove_stream_peer_by_local_fd(tsip_transport_t *self, tnet_fd_t local_fd);
int tsip_transport_remove_callid_from_stream_peers(tsip_transport_t *self, const char* callid, tsk_bool_t* removed);
tsk_bool_t tsip_transport_stream_peer_have_callid(const tsip_transport_stream_peer_t* self, const char* callid);
int tsip_transport_stream_peer_add_callid(tsip_transport_stream_peer_t* self, const char* callid);
int tsip_transport_stream_peer_remove_callid(tsip_transport_stream_peer_t* self, const char* callid, tsk_bool_t *removed);
#define tsip_transport_tls_set_certs(transport, ca, pbk, pvk, verify) (transport ? tnet_transport_tls_set_certs(transport->net_transport, ca, pbk, pvk, verify) : -1)
#define tsip_transport_start(transport) (transport ? tnet_transport_start(transport->net_transport) : -1)

View File

@ -65,6 +65,7 @@ int tsip_transport_ensureTempSAs(const tsip_transport_layer_t *self, const tsip_
int tsip_transport_startSAs(const tsip_transport_layer_t* self, const void* ik, const void* ck);
int tsip_transport_cleanupSAs(const tsip_transport_layer_t *self);
int tsip_transport_layer_remove_callid_from_stream_peers(tsip_transport_layer_t *self, const char* callid);
tsk_bool_t tsip_transport_layer_have_stream_peer_with_remote_ip(const tsip_transport_layer_t *self, const char* remote_ip, tnet_port_t remote_port);
int tsip_transport_layer_start(tsip_transport_layer_t* self);

File diff suppressed because it is too large Load Diff

View File

@ -336,7 +336,9 @@ int s0000_Started_2_Ringing_X_iINVITE(va_list *app)
tsip_dialog_update_2(TSIP_DIALOG(self), request);
/* send Ringing */
send_RESPONSE(self, request, 180, "Ringing", tsk_false);
/*if(TSIP_DIALOG_GET_STACK(self)->network.mode != tsip_stack_mode_webrtc2sip)*/{
send_RESPONSE(self, request, 180, "Ringing", tsk_false);
}
/* alert the user (session) */
TSIP_DIALOG_INVITE_SIGNAL(self, tsip_i_newcall,
@ -455,7 +457,9 @@ int s0000_InProgress_2_Ringing_X_iPRACK(va_list *app)
}
/* Send Ringing */
ret = send_RESPONSE(self, self->last_iInvite, 180, "Ringing", tsk_false);
/*if(TSIP_DIALOG_GET_STACK(self)->network.mode != tsip_stack_mode_webrtc2sip)*/{
ret = send_RESPONSE(self, self->last_iInvite, 180, "Ringing", tsk_false);
}
/* Alert the user (session) */
TSIP_DIALOG_INVITE_SIGNAL(self, tsip_i_newcall,
@ -509,7 +513,9 @@ int s0000_InProgress_2_Ringing_X_iUPDATE(va_list *app)
(self->msession_mgr && (force_sdp || self->msession_mgr->ro_changed || self->msession_mgr->state_changed)));
/* Send Ringing */
ret = send_RESPONSE(self, self->last_iInvite, 180, "Ringing", tsk_false);
/*if(TSIP_DIALOG_GET_STACK(self)->network.mode != tsip_stack_mode_webrtc2sip)*/{
ret = send_RESPONSE(self, self->last_iInvite, 180, "Ringing", tsk_false);
}
/* alert the user */
TSIP_DIALOG_INVITE_SIGNAL(self, tsip_i_newcall,
@ -615,7 +621,7 @@ int s0000_Ringing_2_Connected_X_Accept(va_list *app)
*/
// FIXME: (chrome) <-RTCWeb Breaker-> (chrome) do not work if media session is not started on i200
// http://code.google.com/p/webrtc2sip/issues/detail?id=45
if(TSIP_DIALOG_GET_STACK(self)->network.mode == tsip_stack_mode_webrtc2sip){
/*if(TSIP_DIALOG_GET_STACK(self)->network.mode == tsip_stack_mode_webrtc2sip)*/{
ret = tsip_dialog_invite_msession_start(self);
}

View File

@ -66,6 +66,15 @@ static int pred_find_dialog_by_not_type(const tsk_list_item_t *item, const void
return -1;
}
/*== Predicate function to find dialog by callid */
static int pred_find_dialog_by_callid(const tsk_list_item_t *item, const void *callid)
{
if(item && item->data && callid){
return tsk_strcmp(((tsip_dialog_t*)item->data)->callid, ((const char*)callid));
}
return -1;
}
tsip_dialog_layer_t* tsip_dialog_layer_create(tsip_stack_t* stack)
{
return tsk_object_new(tsip_dialog_layer_def_t, stack);
@ -121,6 +130,19 @@ tsip_dialog_t* tsip_dialog_layer_find_by_callid(tsip_dialog_layer_t *self, const
}
}
tsk_bool_t tsip_dialog_layer_have_dialog_with_callid(const tsip_dialog_layer_t *self, const char* callid)
{
tsk_bool_t found = tsk_false;
if(self){
tsk_safeobj_lock(self);
if(tsk_list_find_item_by_pred(self->dialogs, pred_find_dialog_by_callid, callid) != tsk_null){
found = tsk_true;
}
tsk_safeobj_unlock(self);
}
return found;
}
// it's up to the caller to release the returned object
tsip_dialog_t* tsip_dialog_layer_find(const tsip_dialog_layer_t *self, const char* callid, const char* to_tag, const char* from_tag, tsip_request_type_t type, tsk_bool_t *cid_matched)
{
@ -280,7 +302,7 @@ done:
return -1;
}
int tsip_dialog_layer_signal_transport_error(tsip_dialog_layer_t *self)
int tsip_dialog_layer_signal_stack_disconnected(tsip_dialog_layer_t *self)
{
tsk_list_item_t *item;
int dialogs_count;
@ -294,7 +316,7 @@ int tsip_dialog_layer_signal_transport_error(tsip_dialog_layer_t *self)
again:
tsk_list_foreach(item, self->dialogs){
if(item->data){
// if "tsip_dialog_signal_transport_error()" remove the dialog, then
// if "tsip_dialog_signal_transport_error()" removes the dialog, then
// "self->dialogs" will became unsafe while looping
tsip_dialog_signal_transport_error(TSIP_DIALOG(item->data));
if(--dialogs_count <= 0){ // guard against endless loops
@ -309,6 +331,46 @@ again:
return 0;
}
int tsip_dialog_layer_signal_peer_disconnected(tsip_dialog_layer_t *self, const struct tsip_transport_stream_peer_s* peer)
{
tsip_dialog_t *dialog;
const tsk_list_item_t *item;
if(!self || !peer){
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
tsk_safeobj_lock(self);
tsk_list_lock(peer->dialogs_cids);
tsk_list_foreach(item, peer->dialogs_cids){
if((dialog = tsip_dialog_layer_find_by_callid(self, TSK_STRING_STR(item->data)))){
tsip_dialog_signal_transport_error(dialog);
TSK_OBJECT_SAFE_FREE(dialog);
}
else{
// To avoid this WARN, you should call tsip_dialog_layer_have_dialog_with_callid() before adding a callid to a peer
TSK_DEBUG_WARN("Stream peer holds call-id='%s' but the dialog layer doesn't know it", TSK_STRING_STR(item->data));
}
}
tsk_list_unlock(peer->dialogs_cids);
tsk_safeobj_unlock(self);
return 0;
}
int tsip_dialog_layer_remove_callid_from_stream_peers(tsip_dialog_layer_t *self, const char* callid)
{
if(self){
return tsip_transport_layer_remove_callid_from_stream_peers(self->stack->layer_transport, callid);
}
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
/* the caller of this function must unref() the returned object */
tsip_dialog_t* tsip_dialog_layer_new(tsip_dialog_layer_t *self, tsip_dialog_type_t type, const tsip_ssession_t *ss)
{

View File

@ -26,6 +26,7 @@
#include "tinysip/transports/tsip_transport.h"
#include "tinysip/transports/tsip_transport_ipsec.h"
#include "tinysip/dialogs/tsip_dialog_layer.h"
#include "tinysip/transports/tsip_transport_layer.h"
#include "tinysip/transactions/tsip_transac.h" /* TSIP_TRANSAC_MAGIC_COOKIE */
@ -36,6 +37,7 @@
#include "tsk_buffer.h"
#include "tsk_debug.h"
static const char* __null_callid = tsk_null;
static const tsip_transport_idx_xt _tsip_transport_idxs_xs[TSIP_TRANSPORT_IDX_MAX] =
{
@ -71,7 +73,7 @@ enum tnet_socket_type_e tsip_transport_get_type_by_name(const char* name)
return t_idx ? t_idx->type : tnet_socket_type_invalid;
}
/*== Predicate function to find a compartment by id */
/*== Predicate function to find a peer by local id */
static int _pred_find_stream_peer_by_local_fd(const tsk_list_item_t *item, const void *local_fd)
{
if(item && item->data){
@ -283,7 +285,7 @@ int tsip_transport_msg_update(const tsip_transport_t* self, tsip_message_t *msg)
}
// "udp", "tcp" or "tls"
tsk_size_t tsip_transport_send_raw(const tsip_transport_t* self, const char* dst_host, tnet_port_t dst_port, const void* data, tsk_size_t size)
tsk_size_t tsip_transport_send_raw(const tsip_transport_t* self, const char* dst_host, tnet_port_t dst_port, const void* data, tsk_size_t size, const char* callid)
{
tsk_size_t ret = 0;
@ -338,6 +340,11 @@ tsk_size_t tsip_transport_send_raw(const tsip_transport_t* self, const char* dst
return 0;
}
}
// store call-id
if(callid != __null_callid && tsip_dialog_layer_have_dialog_with_callid(self->stack->layer_dialog, callid)){
ret = tsip_transport_stream_peer_add_callid(peer, callid);
}
// send() data
if(peer->connected){
ret = tnet_transport_send(self->net_transport, peer->local_fd, data, size);
}
@ -353,7 +360,7 @@ tsk_size_t tsip_transport_send_raw(const tsip_transport_t* self, const char* dst
}
// "ws" or "wss"
tsk_size_t tsip_transport_send_raw_ws(const tsip_transport_t* self, tnet_fd_t local_fd, const void* data, tsk_size_t size)
tsk_size_t tsip_transport_send_raw_ws(const tsip_transport_t* self, tnet_fd_t local_fd, const void* data, tsk_size_t size, const char* callid)
{
/*static const uint8_t __ws_first_byte = 0x82;*/
const uint8_t* pdata = (const uint8_t*)data;
@ -411,6 +418,11 @@ tsk_size_t tsip_transport_send_raw_ws(const tsip_transport_t* self, tnet_fd_t lo
memcpy(pws_snd_buffer, pdata, (size_t)lsize);
// store call-id
if(callid != __null_callid && tsip_dialog_layer_have_dialog_with_callid(self->stack->layer_dialog, callid)){
ret = tsip_transport_stream_peer_add_callid(peer, callid);
}
// send() data
ret = tnet_transport_send(self->net_transport, local_fd, peer->ws.snd_buffer, (tsk_size_t)data_size);
TSK_OBJECT_SAFE_FREE(peer);
@ -426,6 +438,7 @@ tsk_size_t tsip_transport_send(const tsip_transport_t* self, const char *branch,
tsk_size_t ret = 0;
if(self){
tsk_buffer_t *buffer = tsk_null;
const char* callid = msg->Call_ID ? msg->Call_ID->value : __null_callid;
/* Add Via and update AOR, IPSec headers, SigComp ...
* ACK sent from the transaction layer will contains a Via header and should not be updated
@ -507,13 +520,13 @@ tsk_size_t tsip_transport_send(const tsip_transport_t* self, const char *branch,
// message not received over WS/WS tranport but have to be sent over WS/WS
tsip_transport_stream_peer_t* peer = tsip_transport_find_stream_peer_by_remote_ip(TSIP_TRANSPORT(self), destIP, destPort, self->type);
if(peer){
ret = tsip_transport_send_raw_ws(self, peer->local_fd, buffer->data, buffer->size);
ret = tsip_transport_send_raw_ws(self, peer->local_fd, buffer->data, buffer->size, callid);
TSK_OBJECT_SAFE_FREE(peer);
}
else if(msg->local_fd > 0)
//}
//else{
ret = tsip_transport_send_raw_ws(self, msg->local_fd, buffer->data, buffer->size);
ret = tsip_transport_send_raw_ws(self, msg->local_fd, buffer->data, buffer->size, callid);
//}
}
else if(TNET_SOCKET_TYPE_IS_IPSEC(self->type)){
@ -527,7 +540,7 @@ tsk_size_t tsip_transport_send(const tsip_transport_t* self, const char *branch,
}
}
else{
ret = tsip_transport_send_raw(self, destIP, destPort, buffer->data, buffer->size);
ret = tsip_transport_send_raw(self, destIP, destPort, buffer->data, buffer->size, callid);
}
//bail:
@ -647,6 +660,24 @@ tsip_transport_stream_peer_t* tsip_transport_find_stream_peer_by_local_fd(tsip_t
return peer;
}
// up to the caller to release the returned object
// calling this function will remove the peer from the list
tsip_transport_stream_peer_t* tsip_transport_pop_stream_peer_by_local_fd(tsip_transport_t *self, tnet_fd_t local_fd)
{
if(self){
tsip_transport_stream_peer_t* peer = tsk_null;
tsk_list_item_t *item;
tsk_list_lock(self->stream_peers);
if((item = tsk_list_pop_item_by_pred(self->stream_peers, _pred_find_stream_peer_by_local_fd, &local_fd))){
peer = tsk_object_ref(item->data);
TSK_OBJECT_SAFE_FREE(item);
}
tsk_list_unlock(self->stream_peers);
return peer;
}
return tsk_null;
}
// up to the caller to release the returned object
tsip_transport_stream_peer_t* tsip_transport_find_stream_peer_by_remote_ip(tsip_transport_t *self, const char* remote_ip, tnet_port_t remote_port, enum tnet_socket_type_e type)
{
@ -702,6 +733,80 @@ int tsip_transport_remove_stream_peer_by_local_fd(tsip_transport_t *self, tnet_f
return 0;
}
int tsip_transport_remove_callid_from_stream_peers(tsip_transport_t *self, const char* callid, tsk_bool_t* removed)
{
if(!self || !removed){
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
*removed = tsk_false;
if(TNET_SOCKET_TYPE_IS_STREAM(self->type)){
tsk_list_item_t *item;
tsk_list_lock(self->stream_peers);
tsk_list_foreach(item, self->stream_peers){
if(tsip_transport_stream_peer_remove_callid((tsip_transport_stream_peer_t*)item->data, callid, removed) == 0 && *removed){
TSK_DEBUG_INFO("[Transport] Removed call-id = '%s' from transport with type = %d", callid, self->type);
break;
}
}
tsk_list_unlock(self->stream_peers);
}
return 0;
}
tsk_bool_t tsip_transport_stream_peer_have_callid(const tsip_transport_stream_peer_t* self, const char* callid)
{
tsk_bool_t have_cid = tsk_false;
if(self){
const tsk_list_item_t* item;
tsk_list_lock(self->dialogs_cids);
tsk_list_foreach(item, self->dialogs_cids){
if(tsk_strequals(TSK_STRING_STR(item->data), callid)){
have_cid = tsk_true;
break;
}
}
tsk_list_unlock(self->dialogs_cids);
}
return have_cid;
}
int tsip_transport_stream_peer_add_callid(tsip_transport_stream_peer_t* self, const char* callid)
{
if(self && !tsk_strnullORempty(callid)){
tsk_list_lock(self->dialogs_cids);
if(!tsip_transport_stream_peer_have_callid(self, callid)){
tsk_string_t* cid = tsk_string_create(callid);
if(cid){
TSK_DEBUG_INFO("Add call-id = '%s' to peer with local fd = %d", callid, self->local_fd);
tsk_list_push_back_data(self->dialogs_cids, &cid);
TSK_OBJECT_SAFE_FREE(cid);
}
}
tsk_list_unlock(self->dialogs_cids);
return 0;
}
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
int tsip_transport_stream_peer_remove_callid(tsip_transport_stream_peer_t* self, const char* callid, tsk_bool_t *removed)
{
if(self && removed){
*removed = tsk_false;
tsk_list_lock(self->dialogs_cids);
if((*removed = tsk_list_remove_item_by_pred(self->dialogs_cids, tsk_string_pred_cmp, callid)) == tsk_true){
TSK_DEBUG_INFO("[Stream] Removed call-id = '%s' from peer with local fd = %d", callid, self->local_fd);
}
tsk_list_unlock(self->dialogs_cids);
return 0;
}
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
int tsip_transport_init(tsip_transport_t* self, tnet_socket_type_t type, const struct tsip_stack_s *stack, const char *host, tnet_port_t port, const char* description)
{
if(!self || self->initialized){
@ -843,6 +948,7 @@ static tsk_object_t* tsip_transport_stream_peer_ctor(tsk_object_t * self, va_lis
if(peer){
peer->rcv_buff_stream = tsk_buffer_create_null();
peer->snd_buff_stream = tsk_buffer_create_null();
peer->dialogs_cids = tsk_list_create();
}
return self;
}
@ -851,6 +957,7 @@ static tsk_object_t* tsip_transport_stream_peer_dtor(tsk_object_t * self)
{
tsip_transport_stream_peer_t *peer = self;
if(peer){
TSK_DEBUG_INFO("*** Stream Peer destroyed ***");
TSK_OBJECT_SAFE_FREE(peer->rcv_buff_stream);
TSK_OBJECT_SAFE_FREE(peer->snd_buff_stream);
@ -858,6 +965,8 @@ static tsk_object_t* tsip_transport_stream_peer_dtor(tsk_object_t * self)
peer->ws.rcv_buffer_size = 0;
TSK_SAFE_FREE(peer->ws.snd_buffer);
peer->ws.snd_buffer_size = 0;
TSK_OBJECT_SAFE_FREE(peer->dialogs_cids);
}
return self;
}

View File

@ -43,6 +43,8 @@
#include "tsk_thread.h"
#include "tsk_debug.h"
static const char* __null_callid = tsk_null;
/* max size of a chunck to form a valid SIP message */
#define TSIP_MAX_STREAM_CHUNCK_SIZE 0xFFFF
/* min size of a chunck to form a valid SIP message
@ -142,21 +144,27 @@ static int tsip_transport_layer_stream_cb(const tnet_transport_event_t* e)
}
case event_closed:
case event_error:
case event_removed:
{
tsip_transport_stream_peer_t* peer;
TSK_DEBUG_INFO("Stream Peer closed - %d", e->local_fd);
if(transport->connectedFD == e->local_fd){
TSK_DEBUG_INFO("SIP socket closed");
if(transport->stack){
tsip_event_t* e;
// signal to all dialogs that transport error raised
tsip_dialog_layer_signal_transport_error(TSIP_STACK(transport->stack)->layer_dialog);
tsip_dialog_layer_signal_stack_disconnected(TSIP_STACK(transport->stack)->layer_dialog);
// signal to the end-user that the stack is disconnected
if((e = tsip_event_create(tsk_null, tsip_event_code_stack_disconnected, "Stack disconnected", tsk_null, tsip_event_stack))){
TSK_RUNNABLE_ENQUEUE_OBJECT(TSK_RUNNABLE(transport->stack), e);
}
}
}
return tsip_transport_remove_stream_peer_by_local_fd(transport, e->local_fd);
if((peer = tsip_transport_pop_stream_peer_by_local_fd(transport, e->local_fd))){
tsip_dialog_layer_signal_peer_disconnected(TSIP_STACK(transport->stack)->layer_dialog, peer);
TSK_OBJECT_SAFE_FREE(peer);
}
return 0;
}
case event_connected:
case event_accepted:
@ -231,7 +239,7 @@ static int tsip_transport_layer_stream_cb(const tnet_transport_event_t* e)
if(data_size){
if(is_nack){
tsip_transport_send_raw(transport, tsk_null, 0, SigCompBuffer, data_size);
tsip_transport_send_raw(transport, tsk_null, 0, SigCompBuffer, data_size, __null_callid);
}
else{
// append result
@ -245,7 +253,7 @@ static int tsip_transport_layer_stream_cb(const tnet_transport_event_t* e)
// Query for all other chuncks
while((next_size = tsip_sigcomp_handler_uncompress_next(transport->stack->sigcomp.handle, comp_id, &nack_data, &is_nack)) || nack_data){
if(is_nack){
tsip_transport_send_raw(transport, tsk_null, 0, nack_data, next_size);
tsip_transport_send_raw(transport, tsk_null, 0, nack_data, next_size, __null_callid);
TSK_FREE(nack_data);
}
else{
@ -278,7 +286,7 @@ parse_buffer:
}
else{ /* There is a content */
if((endOfheaders + 4/*2CRLF*/ + clen) > TSK_BUFFER_SIZE(peer->rcv_buff_stream)){ /* There is content but not all the content. */
TSK_DEBUG_INFO("No all SIP content in the TCP buffer.");
TSK_DEBUG_INFO("No all SIP content in the TCP buffer (clen=%u and %u > %u).", clen, (endOfheaders + 4/*2CRLF*/ + clen), TSK_BUFFER_SIZE(peer->rcv_buff_stream));
goto bail;
}
else{
@ -334,9 +342,16 @@ static int tsip_transport_layer_ws_cb(const tnet_transport_event_t* e)
break;
}
case event_closed:
case event_error:
case event_removed:
{
tsip_transport_stream_peer_t* peer;
TSK_DEBUG_INFO("WebSocket Peer closed with fd = %d", e->local_fd);
return tsip_transport_remove_stream_peer_by_local_fd(transport, e->local_fd);
if((peer = tsip_transport_pop_stream_peer_by_local_fd(transport, e->local_fd))){
tsip_dialog_layer_signal_peer_disconnected(TSIP_STACK(transport->stack)->layer_dialog, peer);
TSK_OBJECT_SAFE_FREE(peer);
}
return 0;
}
case event_accepted:
case event_connected:
@ -614,7 +629,7 @@ static int tsip_transport_layer_dgram_cb(const tnet_transport_event_t* e)
data_ptr = SigCompBuffer;
if(data_size){
if(is_nack){
tsip_transport_send_raw(transport, tsk_null, 0, data_ptr, data_size);
tsip_transport_send_raw(transport, tsk_null, 0, data_ptr, data_size, __null_callid);
return 0;
}
}
@ -1096,6 +1111,30 @@ bail:
return ret;
}
int tsip_transport_layer_remove_callid_from_stream_peers(tsip_transport_layer_t *self, const char* callid)
{
if(self && callid){
int ret = 0;
tsk_bool_t removed = tsk_false;
tsip_transport_t* transport;
tsk_list_item_t* item;
tsk_list_lock(self->transports);
tsk_list_foreach(item, self->transports){
if(!(transport = TSIP_TRANSPORT(item->data)) || !TNET_SOCKET_TYPE_IS_STREAM(transport->type)){
continue;
}
if((ret = tsip_transport_remove_callid_from_stream_peers(transport, callid, &removed)) == 0 && removed){
TSK_DEBUG_INFO("[Transport Layer] Removed call-id = '%s' from transport layer", callid);
break;
}
}
tsk_list_unlock(self->transports);
return ret;
}
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
tsk_bool_t tsip_transport_layer_have_stream_peer_with_remote_ip(const tsip_transport_layer_t *self, const char* remote_ip, tnet_port_t remote_port)
{
if(self && remote_ip){