Commit 28c3383b authored by Simon Morlat's avatar Simon Morlat

add new MSAudioEncoderInterface with two new methods:

MS_AUDIO_ENCODER_SET_PTIME
MS_AUDIO_ENCODER_GET_PTIME

in the purpose of allowing easy access of ptime for bitrate driver (adaptive rate control algorithm).

Encoders are no longer required to parse "ptime" parameter from fmtp, but instead they should implement these new methods.
parent 06e50570
......@@ -578,10 +578,11 @@ enum _MSFilterInterfaceId{
MSFilterEchoCancellerInterface,/**Echo canceller interface, used to control echo canceller implementations.*/
MSFilterVideoDecoderInterface,/**<Video decoder interface*/
MSFilterVideoCaptureInterface,/**<Video capture interface*/
MSFilterDecoderInterface,/**<Decoder interface*/
MSFilterAudioDecoderInterface,/**<Audio Decoder interface*/
MSFilterVideoEncoderInterface,/**<Video encoder interface*/
MSFilterAudioCaptureInterface,/**<Interface for audio capture filters*/
MSFilterAudioPlaybackInterface,/**Interface for audio playback filters.*/
MSFilterAudioEncoderInterface,/**<Video encoder interface*/
};
/**
......
......@@ -171,9 +171,12 @@ typedef enum _MSRecorderState MSRecorderState;
#define MS_VIDEO_CAPTURE_SET_DEVICE_ORIENTATION \
MS_FILTER_METHOD(MSFilterVideoCaptureInterface,0,int)
/** Interface definitions for decoder */
#define MS_DECODER_HAVE_PLC \
MS_FILTER_METHOD(MSFilterDecoderInterface,0,int)
/** Interface definitions for audio decoder */
#define MS_AUDIO_DECODER_HAVE_PLC \
MS_FILTER_METHOD(MSFilterAudioDecoderInterface,0,int)
#define MS_DECODER_HAVE_PLC MS_AUDIO_DECODER_HAVE_PLC /*for backward compatibility*/
/** Interface definitions for video encoders */
#define MS_VIDEO_ENCODER_HAS_BUILTIN_CONVERTER \
......@@ -187,4 +190,12 @@ typedef enum _MSRecorderState MSRecorderState;
#define MS_AUDIO_CAPTURE_FORCE_SPEAKER_STATE \
MS_FILTER_METHOD(MSFilterAudioCaptureInterface, 255, bool_t)
/** Interface definitions for audio encoder */
#define MS_AUDIO_ENCODER_SET_PTIME \
MS_FILTER_METHOD(MSFilterAudioEncoderInterface,0,int)
#define MS_AUDIO_ENCODER_GET_PTIME \
MS_FILTER_METHOD(MSFilterAudioEncoderInterface,1,int)
#endif
......@@ -312,6 +312,22 @@ static int enc_get_br(MSFilter *f, void *arg){
return 0;
}
static int enc_set_ptime(MSFilter *f, void *arg){
SpeexEncState *s=(SpeexEncState*)f->data;
s->ptime=*(int*)arg;
/*if the ptime is not a mulptiple of 20, go to the next multiple*/
if (s->ptime%20)
s->ptime = s->ptime - s->ptime%20 + 20;
ms_message("MSSpeexEnc: got ptime=%i",s->ptime);
return 0;
}
static int enc_get_ptime(MSFilter *f, void *arg){
SpeexEncState *s=(SpeexEncState*)f->data;
*(int*)arg=s->ptime;
return 0;
}
static int enc_add_fmtp(MSFilter *f, void *arg){
char buf[64];
const char *fmtp=(const char *)arg;
......@@ -360,11 +376,8 @@ static int enc_add_fmtp(MSFilter *f, void *arg){
}
memset(buf, '\0', sizeof(buf));
if (fmtp_get_value(fmtp,"ptime",buf,sizeof(buf))){
s->ptime=atoi(buf);
//if the ptime is not a mulptiple of 20, go to the next multiple
if (s->ptime%20)
s->ptime = s->ptime - s->ptime%20 + 20;
ms_message("MSSpeexEnc: got ptime=%i",s->ptime);
int val=atoi(buf);
enc_set_ptime(f,&val);
}
return 0;
......@@ -410,8 +423,10 @@ static MSFilterMethod enc_methods[]={
{ MS_FILTER_GET_SAMPLE_RATE , enc_get_sr },
{ MS_FILTER_SET_BITRATE , enc_set_br },
{ MS_FILTER_GET_BITRATE , enc_get_br },
{ MS_FILTER_ADD_FMTP , enc_add_fmtp },
{ MS_FILTER_ADD_ATTR , enc_add_attr},
{ MS_FILTER_ADD_FMTP , enc_add_fmtp },
{ MS_FILTER_ADD_ATTR , enc_add_attr },
{ MS_AUDIO_ENCODER_SET_PTIME , enc_set_ptime },
{ MS_AUDIO_ENCODER_GET_PTIME , enc_get_ptime },
{ 0 , NULL }
};
......
......@@ -400,7 +400,17 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
ms_filter_call_method(stream->ms.decoder,MS_FILTER_SET_SAMPLE_RATE,&sample_rate);
ms_filter_call_method(stream->ms.decoder,MS_FILTER_SET_NCHANNELS,&pt->channels);
if (pt->send_fmtp!=NULL) ms_filter_call_method(stream->ms.encoder,MS_FILTER_ADD_FMTP, (void*)pt->send_fmtp);
if (pt->send_fmtp!=NULL) {
char value[16]={0};
int ptime;
if (ms_filter_has_method(stream->ms.encoder,MS_AUDIO_ENCODER_SET_PTIME)){
if (fmtp_get_value(pt->send_fmtp,"ptime",value,sizeof(value)-1)){
ptime=atoi(value);
ms_filter_call_method(stream->ms.encoder,MS_AUDIO_ENCODER_SET_PTIME,&ptime);
}
ms_filter_call_method(stream->ms.encoder,MS_FILTER_ADD_FMTP, (void*)pt->send_fmtp);
}
}
if (pt->recv_fmtp!=NULL) ms_filter_call_method(stream->ms.decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp);
/*create the equalizer*/
......@@ -433,9 +443,9 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
/* Create PLC */
if ((stream->features & AUDIO_STREAM_FEATURE_PLC) != 0) {
int decoder_have_plc = 0;
if (ms_filter_has_method(stream->ms.decoder, MS_DECODER_HAVE_PLC)) {
if (ms_filter_call_method(stream->ms.decoder, MS_DECODER_HAVE_PLC, &decoder_have_plc) != 0) {
ms_warning("MS_DECODER_HAVE_PLC function error: enable default plc");
if (ms_filter_has_method(stream->ms.decoder, MS_AUDIO_DECODER_HAVE_PLC)) {
if (ms_filter_call_method(stream->ms.decoder, MS_AUDIO_DECODER_HAVE_PLC, &decoder_have_plc) != 0) {
ms_warning("MS_AUDIO_DECODER_HAVE_PLC function error: enable default plc");
}
} else {
ms_warning("MS_DECODER_HAVE_PLC function not implemented by the decoder: enable default plc");
......
......@@ -81,10 +81,17 @@ static int audio_bitrate_driver_execute_action(MSBitrateDriver *objbase, const M
if (obj->nom_bitrate==0){
ms_filter_call_method(obj->encoder,MS_FILTER_GET_BITRATE,&obj->nom_bitrate);
if (obj->nom_bitrate==0){
ms_warning("MSAVBitrateDriver: Not doing adaptive rate control on audio encoder, it does not seem to support that.");
ms_warning("MSAudioBitrateDriver: Not doing bitrate control on audio encoder, it does not seem to support that. Controlling ptime only.");
obj->nom_bitrate=-1;
}
}
if (obj->cur_ptime==0){
ms_filter_call_method(obj->encoder,MS_AUDIO_ENCODER_GET_PTIME,&obj->cur_ptime);
if (obj->cur_ptime==0){
ms_warning("MSAudioBitrateDriver: encoder %s does not implement MS_AUDIO_ENCODER_GET_PTIME. Consider to implement this method for better accuracy of rate control.",obj->encoder->desc->name);
obj->cur_ptime=obj->min_ptime;
}
}
if (action->type==MSRateControlActionDecreaseBitrate){
/*reducing bitrate of the codec isn't sufficient. Increasing ptime is much more efficient*/
......@@ -149,7 +156,8 @@ MSBitrateDriver *ms_audio_bitrate_driver_new(MSFilter *encoder){
MSAudioBitrateDriver *obj=ms_new0(MSAudioBitrateDriver,1);
obj->parent.desc=&audio_bitrate_driver;
obj->encoder=encoder;
obj->cur_ptime=obj->min_ptime=20;
obj->min_ptime=20;
obj->cur_ptime=0;
obj->cur_bitrate=obj->nom_bitrate=0;
return (MSBitrateDriver*)obj;
}
......
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