Commit 918bcfab authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Code cleanup, added constants and enum for better readability.

parent 79c47725
/*
constants.h
Copyright (C) 2013 Belledonne Communications, Grenoble, France
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef CONSTANTS_H
#define CONSTANTS_H
/* Define codec specific settings */
#define ISAC_SAMPLE_RATE 16000
/* (10 / 1000) * SAMPLE_RATE, the number of samples to pass at each
* WebRtcIsacFix_Encode() call */
#define ISAC_SAMPLES_PER_ENCODE 160
typedef enum {
ISAC_60MS_SAMPLE_COUNT = 960,
ISAC_30MS_SAMPLE_COUNT = 480
} isac_sample_count_e;
/* This enum is to be used in WebRtcIsacfix_EncoderInit() */
typedef enum {
/* In this mode, the bitrate and ptime are adjusted according to statistics
provided by the user through the WebRtcIsacfix_UpdateBwEstimate*() functions */
CODING_AUTOMATIC,
/* Setup the encoder so that bitrate and ptime are controlled by calls to
WebRtcIsacFix_Encode(). This means the user is in charge of evaluating
the correct set of parameters for optimal call quality. */
CODING_USERDEFINED
} isac_codingmode_e;
#define ISAC_BITRATE_MAX 32000
#define ISAC_BITRATE_MIN 10000
#endif // CONSTANTS_H
......@@ -24,7 +24,7 @@
#include "mediastreamer2/msticker.h"
#include "ortp/rtp.h"
#include <stdint.h>
#include "constants.h"
/*filter common method*/
struct _isac_decoder_struct_t {
......@@ -84,7 +84,7 @@ static void decode(MSFilter *f, mblk_t *im) {
mblk_t *om = allocb(samples_nb*2, 0);
mblk_meta_copy(im, om);
obj->ptime = (samples_nb == 480) ? 30 : 60; // update ptime
obj->ptime = (samples_nb == ISAC_30MS_SAMPLE_COUNT) ? 30 : 60; // update ptime
// ms_message("DECODED om datap @%p", om->b_datap);
ret = WebRtcIsacfix_Decode(obj->isac,
......@@ -123,7 +123,8 @@ static void filter_process(MSFilter *f){
if( ms_concealer_context_is_concealement_required(obj->plc_ctx, f->ticker->time) ) {
WebRtc_Word16 flen = obj->ptime == 30 ? 480 : 960;
WebRtc_Word16 flen = (obj->ptime == 30) ? ISAC_30MS_SAMPLE_COUNT
: ISAC_60MS_SAMPLE_COUNT;
mblk_t* plc_blk = allocb(flen*2, 0 );
// ms_message("PLC om datap @%p, nb samples %d", plc_blk->b_datap, flen);
......@@ -171,14 +172,15 @@ static void filter_uninit(MSFilter *f){
/*filter specific method*/
static int filter_set_sample_rate(MSFilter *f, void *arg) {
if( *(int*)arg != 16000) {
ms_error("iSAC doesn't support sampling rate %d, only 16000", *(int*)arg);
if( *(int*)arg != ISAC_SAMPLE_RATE) {
ms_error("iSAC doesn't support sampling rate %d, only %d",
*(int*)arg, ISAC_SAMPLE_RATE);
}
return 0;
}
static int filter_get_sample_rate(MSFilter *f, void *arg) {
*(int*)arg = 16000;
*(int*)arg = ISAC_SAMPLE_RATE;
return 0;
}
......
......@@ -20,27 +20,23 @@
#include "isacfix.h"
#include "signal_processing_library.h"
#include "constants.h"
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/mscodecutils.h"
/* Define codec specific settings */
#define ISAC_SAMPLE_RATE 16000
#define ISAC_SAMPLES_PER_ENCODE 160 /* (10 / 1000) * SAMPLE_RATE */
/*filter common method*/
struct _isac_encoder_struct_t {
ISACFIX_MainStruct* isac;
MSBufferizer *bufferizer;
unsigned int ptime;
unsigned int bitrate;
unsigned int totalSize;
};
typedef struct _isac_encoder_struct_t isac_encoder_struct_t;
enum _isac_codingmode {
CODING_AUTOMATIC,
CODING_USERDEFINED
};
static void filter_init ( MSFilter *f ) {
ISACFIX_MainStruct* isac_mainstruct = NULL;
......@@ -64,12 +60,20 @@ static void filter_init ( MSFilter *f ) {
}
// TODO: AUTO or USER coding mode?
ret = WebRtcIsacfix_EncoderInit(obj->isac, CODING_AUTOMATIC);
ret = WebRtcIsacfix_EncoderInit(obj->isac, CODING_USERDEFINED);
if( ret ) {
ms_error("WebRtcIsacfix_EncoderInit failed (%d)", ret);
ms_error("WebRtcIsacfix_EncoderInit failed (%d)", WebRtcIsacfix_GetErrorCode(obj->isac));
}
obj->ptime = 30; // iSAC allows 30 or 60ms per packet
obj->bitrate = ISAC_BITRATE_MAX;
ret = WebRtcIsacfix_Control(obj->isac, obj->bitrate, obj->ptime);
if( ret ) {
ms_error("WebRtcIsacfix_Control failed: %d", WebRtcIsacfix_GetErrorCode(obj->isac));
}
obj->ptime = 30; // iSAC allows 30 or 60ms per packet
obj->bufferizer = ms_bufferizer_new();
}
......@@ -178,8 +182,23 @@ static int filter_set_ptime(MSFilter *f, void *arg){
static int filter_set_bitrate ( MSFilter *f, void *arg ) {
isac_encoder_struct_t *obj = (isac_encoder_struct_t*)f->data;
int max_bitrate = MIN(32000, * (int*)arg );
return WebRtcIsacfix_SetMaxRate(obj->isac, max_bitrate);
int wanted_bitrate = *(int*)arg;
if( wanted_bitrate > ISAC_BITRATE_MAX ) {
ms_warning("iSAC doesn't handle bitrate > %d (wanted: %d)",
ISAC_BITRATE_MAX, wanted_bitrate );
wanted_bitrate = ISAC_BITRATE_MAX;
} else if( wanted_bitrate < ISAC_BITRATE_MIN) {
ms_warning("iSAC doesn't handle bitrate < %d (wanted: %d)",
ISAC_BITRATE_MIN, wanted_bitrate );
wanted_bitrate = ISAC_BITRATE_MIN;
}
return WebRtcIsacfix_SetMaxRate(obj->isac, wanted_bitrate);
}
static int filter_get_bitrate ( MSFilter *f, void *arg ) {
......@@ -187,15 +206,6 @@ static int filter_get_bitrate ( MSFilter *f, void *arg ) {
*(int*)arg = (int)WebRtcIsacfix_GetUplinkBw(obj->isac);
return 0;
}
//#ifdef MS_AUDIO_ENCODER_SET_PACKET_LOSS
//static int filter_set_packetloss(MSFilter *f, void *arg){
// return 0;
//}
//static int filter_enable_inband_fec(MSFilter *f, void *arg){
// return 0;
//}
//#endif /*MS_AUDIO_ENCODER_SET_PACKET_LOSS*/
static MSFilterMethod filter_methods[]= {
{MS_FILTER_GET_SAMPLE_RATE, filter_get_sample_rate },
......@@ -205,10 +215,6 @@ static MSFilterMethod filter_methods[]= {
{MS_AUDIO_ENCODER_SET_PTIME, filter_set_ptime },
{MS_AUDIO_ENCODER_GET_PTIME, filter_get_ptime },
#endif
//#ifdef MS_AUDIO_ENCODER_SET_PACKET_LOSS
// {MS_AUDIO_ENCODER_SET_PACKET_LOSS, filter_set_packetloss },
// {MS_AUDIO_ENCODER_ENABLE_FEC, filter_enable_inband_fec },
//#endif
{0, NULL}
};
......@@ -267,10 +273,16 @@ extern MSFilterDesc ms_isac_dec_desc;
#endif
MS_PLUGIN_DECLARE ( void ) libmsisac_init() {
char isac_version[64];
isac_version[0] = 0;
WebRtcSpl_Init();
WebRtcIsacfix_version(isac_version);
ms_filter_register ( &ms_isac_enc_desc );
ms_filter_register ( &ms_isac_dec_desc );
ms_message ( " libmsisac " VERSION " plugin loaded" );
ms_message ( " libmsisac " VERSION " plugin loaded, iSAC codec version %s", isac_version );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment