Commit 3f2672fc authored by Simon Morlat's avatar Simon Morlat
Browse files

add new API for concealment but using timestamp units rather than time in ms.

parent 47483a49
......@@ -55,9 +55,47 @@ MS2_PUBLIC unsigned int ms_concealer_context_is_concealement_required(MSConceale
**/
MS2_PUBLIC int ms_concealer_inc_sample_time(MSConcealerContext* obj, uint64_t current_time, int time_increment, int got_packet);
MS2_PUBLIC unsigned long ms_concealer_context_get_total_number_of_plc(MSConcealerContext* obj);
/**
* Helper object for audio decoders to determine whether PLC (packet loss concealment is needed), based on timestamp information.
**/
typedef struct _MSConcealerTsContext MSConcealerTsContext;
/**
* Creates a new concealer object.
* @param max_plc_count maximum duration of PLC allowed, expressed in timestamp units.
**/
MS2_PUBLIC MSConcealerTsContext* ms_concealer_ts_context_new(unsigned int max_plc_ts);
/**
* Destroys a concealer object.
**/
MS2_PUBLIC void ms_concealer_ts_context_destroy(MSConcealerTsContext* context);
/**
* Returns 1 when PLC is needed, 0 otherwise.
* @param obj the concealer object
* @param current_ts the current time converted in timestamp units, usually (f->ticker->time*clock_rate)/1000 .
**/
MS2_PUBLIC unsigned int ms_concealer_ts_context_is_concealement_required(MSConcealerTsContext* obj,uint64_t current_ts);
/**
* Call this function whenever you decoded a packet, for true or in PLC mode, to inform the concealer
* of how the audio stream is going.
* @param obj the concealer object
* @param current_ts the current time converted in timestamp units, usually (f->ticker->time*clock_rate)/1000
* @param ts_increment the duration of audio decoded expressed in timestamp units
* @param got_packet set to 1 if a real frame was decoded, 0 if it was a PLC frame.
* @returns if a PLC period terminates, returns the duration of this PLC period in timestamp units, 0 otherwise.
**/
MS2_PUBLIC int ms_concealer_ts_context_inc_sample_ts(MSConcealerTsContext* obj, uint64_t current_ts, int ts_increment, int got_packet);
MS2_PUBLIC unsigned long ms_concealer_ts_context_get_total_number_of_plc(MSConcealerTsContext* obj);
/*FEC API*/
typedef struct _MSRtpPayloadPickerContext MSRtpPayloadPickerContext;
typedef mblk_t* (*RtpPayloadPicker)(MSRtpPayloadPickerContext* context,unsigned int sequence_number);
......
......@@ -565,7 +565,7 @@ unsigned long ms_concealer_context_get_total_number_of_plc(MSConcealerContext* o
}
MSConcealerContext* ms_concealer_context_new(unsigned int max_plc_time){
MSConcealerContext *obj=(MSConcealerContext *) ms_new(MSConcealerContext,1);
MSConcealerContext *obj=(MSConcealerContext *) ms_new(MSConcealerContext,1);
obj->sample_time=-1;
obj->plc_start_time=-1;
obj->total_number_for_plc=0;
......@@ -612,4 +612,64 @@ unsigned int ms_concealer_context_is_concealement_required(MSConcealerContext* o
return 0;
}
struct _MSConcealerTsContext {
int64_t sample_ts;
int64_t plc_start_ts;
unsigned long total_number_for_plc;
unsigned int max_plc_ts;
};
/*** plc context begin***/
unsigned long ms_concealer_ts_context_get_total_number_of_plc(MSConcealerTsContext* obj) {
return obj->total_number_for_plc;
}
MSConcealerTsContext* ms_concealer_ts_context_new(unsigned int max_plc_ts){
MSConcealerTsContext *obj=(MSConcealerTsContext *) ms_new(MSConcealerTsContext,1);
obj->sample_ts=-1;
obj->plc_start_ts=-1;
obj->total_number_for_plc=0;
obj->max_plc_ts=max_plc_ts;
return obj;
}
void ms_concealer_ts_context_destroy(MSConcealerTsContext* context) {
ms_free(context);
}
int ms_concealer_ts_context_inc_sample_ts(MSConcealerTsContext* obj, uint64_t current_ts, int ts_increment, int got_packet){
int plc_duration=0;
if (obj->sample_ts==-1){
obj->sample_ts=(int64_t)current_ts;
}
obj->sample_ts+=ts_increment;
if (obj->plc_start_ts!=-1 && got_packet){
plc_duration=current_ts-obj->plc_start_ts;
obj->plc_start_ts=-1;
if (plc_duration>obj->max_plc_ts) plc_duration=obj->max_plc_ts;
}
return plc_duration;
}
unsigned int ms_concealer_ts_context_is_concealement_required(MSConcealerTsContext* obj, uint64_t current_ts) {
if(obj->sample_ts == -1) return 0; /*no valid value*/
if (obj->sample_ts < current_ts){
int plc_duration;
if (obj->plc_start_ts==-1)
obj->plc_start_ts=obj->sample_ts;
plc_duration=current_ts-obj->plc_start_ts;
if (plc_duration<obj->plc_start_ts) {
obj->total_number_for_plc++;
return 1;
}else{
/*reset sample time, so that we don't do PLC anymore and can resync properly when the stream restarts*/
obj->sample_ts=-1;
return 0;
}
}
return 0;
}
/*** plc context end***/
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