Commit db012167 authored by Sandrine Avakian's avatar Sandrine Avakian

Cleaning audiostream.c .

First integrating step in vp8 .
TODO : fix ugly temporary fix in mkv.c .
parent 8680e3a0
......@@ -139,6 +139,7 @@ typedef struct _MSList MSList;
typedef int (*MSCompareFunc)(const void *a, const void *b);
typedef void (*MSIterateFunc)(void *a);
typedef void (*MSIterate2Func)(void *a, void *b);
typedef void (*MSIterate3Func)(void *a, void *b, void *c);
#ifdef __cplusplus
extern "C"{
......@@ -227,8 +228,11 @@ MS2_PUBLIC void ms_list_for_each(const MSList *list, MSIterateFunc iterate_func)
* @param list List object
* @param iterate_func Function to invoke on each element.
* @param user_data User data to pass to iterate_func function.
*
**/
MS2_PUBLIC void ms_list_for_each2(const MSList *list, MSIterate2Func iterate_func, void *user_data);
MS2_PUBLIC void ms_list_for_each3(const MSList *list, MSIterate3Func iterate_func, void *user_data, void *factory);
/** Finds and remove given element in list.
* @param list List in which element must be removed
......
......@@ -143,12 +143,18 @@ void ms_list_for_each(const MSList *list, void (*func)(void *)){
}
}
void ms_list_for_each2(const MSList *list, void (*func)(void *, void *), void *user_data){
void ms_list_for_each2(const MSList *list, void (*func)(void *, void *y), void *user_data){
for(;list!=NULL;list=list->next){
func(list->data,user_data);
}
}
void ms_list_for_each3(const MSList *list, void (*func)(void *, void *, void*), void *user_data, void* factory){
for(;list!=NULL;list=list->next){
func(list->data,user_data, factory);
}
}
MSList *ms_list_remove_link(MSList *list, MSList *elem){
MSList *ret;
if (elem==list){
......
......@@ -481,7 +481,7 @@ static void vp8_module_reverse(void *obj, mblk_t *input, MSQueue *output, ms_boo
packet->pd->pid = 0;
mblk_set_marker_info(packet->m, TRUE);
packer_input = ms_list_append(packer_input, packet);
vp8rtpfmt_packer_process(&mod->packer, packer_input, &q);
vp8rtpfmt_packer_process(&mod->packer, packer_input, &q, NULL);
while((m = ms_queue_get(&q))) {
mblk_set_cseq(m, mod->cseq++);
......
......@@ -544,7 +544,7 @@ static void enc_process(MSFilter *f) {
(flags & VP8_EFLAG_NO_REF_LAST) ? "NOREFLAST" : " ");
#endif
vp8rtpfmt_packer_process(&s->packer, list, f->outputs[0]);
vp8rtpfmt_packer_process(&s->packer, list, f->outputs[0], f->factory);
/* Handle video starter if AVPF is not enabled. */
s->frame_count++;
......
......@@ -237,7 +237,6 @@ bool_t audio_stream_started(AudioStream *stream){
void audio_stream_prepare_sound(AudioStream *stream, MSSndCard *playcard, MSSndCard *captcard){
audio_stream_unprepare_sound(stream);
stream->dummy=ms_factory_create_filter(stream->ms.factory, MS_RTP_RECV_ID);
// stream->dummy=ms_filter_new(MS_RTP_RECV_ID);
rtp_session_set_payload_type(stream->ms.sessions.rtp_session,0);
rtp_session_enable_rtcp(stream->ms.sessions.rtp_session, FALSE);
ms_filter_call_method(stream->dummy,MS_RTP_RECV_SET_SESSION,stream->ms.sessions.rtp_session);
......@@ -248,12 +247,10 @@ void audio_stream_prepare_sound(AudioStream *stream, MSSndCard *playcard, MSSndC
stream->soundwrite=ms_snd_card_create_writer(playcard);
ms_filter_link(stream->dummy,0,stream->soundwrite,0);
#else
//stream->ms.voidsink=ms_filter_new(MS_VOID_SINK_ID);
stream->ms.voidsink=ms_factory_create_filter(stream->ms.factory, MS_VOID_SINK_ID);
ms_filter_link(stream->dummy,0,stream->ms.voidsink,0);
#endif
} else {
//stream->ms.voidsink=ms_filter_new(MS_VOID_SINK_ID);
stream->ms.voidsink=ms_factory_create_filter(stream->ms.factory, MS_VOID_SINK_ID);
ms_filter_link(stream->dummy,0,stream->ms.voidsink,0);
......@@ -304,8 +301,7 @@ static void setup_local_player(AudioStream *stream, int samplerate, int channels
MSConnectionHelper cnx;
int master=0;
/* stream->local_player=ms_filter_new(MS_FILE_PLAYER_ID);
stream->local_player_resampler=ms_filter_new(MS_RESAMPLE_ID);*/
stream->local_player=ms_factory_create_filter(stream->ms.factory, MS_FILE_PLAYER_ID);
stream->local_player_resampler=ms_factory_create_filter(stream->ms.factory, MS_RESAMPLE_ID);
......@@ -383,10 +379,8 @@ static bool_t ci_ends_with(const char *filename, const char*suffix){
MSFilter *_ms_create_av_player(const char *filename, MSFactory* factory){
if (ci_ends_with(filename,".mkv"))
//return ms_filter_new(MS_MKV_PLAYER_ID);
return ms_factory_create_filter(factory, MS_MKV_PLAYER_ID);
else if (ci_ends_with(filename,".wav"))
//return ms_filter_new(MS_FILE_PLAYER_ID);
return ms_factory_create_filter(factory, MS_FILE_PLAYER_ID);
return NULL;
}
......@@ -545,7 +539,6 @@ static int open_av_player(AudioStream *stream, const char *filename){
}
}
if (audiofmt && audiofmt->fmt && strcasecmp(audiofmt->fmt->encoding,"pcm")!=0){
// player->decoder=ms_filter_create_decoder(audiofmt->fmt->encoding);
player->decoder=ms_factory_create_decoder(stream->ms.factory, audiofmt->fmt->encoding);
if (player->decoder==NULL){
......@@ -554,9 +547,7 @@ static int open_av_player(AudioStream *stream, const char *filename){
return -1;
}
}
//player->resampler=ms_filter_new(MS_RESAMPLE_ID);
player->resampler=ms_factory_create_filter(stream->ms.factory, MS_RESAMPLE_ID);
// if (videofmt && videofmt->fmt) player->video_output=ms_filter_new(MS_ITC_SINK_ID);
if (videofmt && videofmt->fmt) player->video_output=ms_factory_create_filter(stream->videostream->ms.factory,MS_ITC_SINK_ID);
else player->videopin=-1;
......@@ -608,23 +599,17 @@ static void av_recorder_handle_event(void *userdata, MSFilter *recorder, unsigne
}
static void setup_av_recorder(AudioStream *stream, int sample_rate, int nchannels){
//stream->av_recorder.recorder=ms_filter_new(MS_MKV_RECORDER_ID);
stream->av_recorder.recorder=ms_factory_create_filter(stream->ms.factory, MS_MKV_RECORDER_ID);
if (stream->av_recorder.recorder){
MSPinFormat pinfmt={0};
// stream->av_recorder.video_input=ms_filter_new(MS_ITC_SOURCE_ID);
// stream->av_recorder.resampler=ms_filter_new(MS_RESAMPLE_ID);
// stream->av_recorder.encoder=ms_filter_new(MS_OPUS_ENC_ID);
stream->av_recorder.video_input=ms_factory_create_filter(stream->videostream->ms.factory, MS_ITC_SOURCE_ID);
stream->av_recorder.resampler=ms_factory_create_filter(stream->videostream->ms.factory,MS_RESAMPLE_ID);
stream->av_recorder.encoder=ms_factory_create_filter(stream->videostream->ms.factory,MS_OPUS_ENC_ID);
if (stream->av_recorder.encoder==NULL){
int g711_rate=8000;
int g711_nchannels=1;
//stream->av_recorder.encoder=ms_filter_new(MS_ULAW_ENC_ID);
stream->av_recorder.encoder=ms_factory_create_filter(stream->ms.factory, MS_ULAW_ENC_ID);
ms_filter_call_method(stream->av_recorder.resampler,MS_FILTER_SET_SAMPLE_RATE,&sample_rate);
ms_filter_call_method(stream->av_recorder.resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&g711_rate);
......@@ -685,9 +670,6 @@ static void setup_recorder(AudioStream *stream, int sample_rate, int nchannels){
int pin=1;
MSAudioMixerCtl mctl={0};
// stream->recorder=ms_filter_new(MS_FILE_REC_ID);
// stream->recorder_mixer=ms_filter_new(MS_AUDIO_MIXER_ID);
// stream->recv_tee=ms_filter_new(MS_TEE_ID);
stream->recorder=ms_factory_create_filter(stream->ms.factory, MS_FILE_REC_ID);
stream->recorder_mixer=ms_factory_create_filter(stream->ms.factory, MS_AUDIO_MIXER_ID);
stream->recv_tee=ms_factory_create_filter(stream->ms.factory, MS_TEE_ID);
......@@ -737,7 +719,6 @@ static void setup_generic_confort_noise(AudioStream *stream){
if (cn && pt && pt->channels==1 && pt->clock_rate==8000){
/* RFC3389 CN can be used*/
//stream->vaddtx=ms_filter_new(MS_VAD_DTX_ID);
stream->vaddtx=ms_factory_create_filter(stream->ms.factory, MS_VAD_DTX_ID);
if (stream->vaddtx) {
ms_filter_add_notify_callback(stream->vaddtx, on_silence_detected, stream, TRUE);
......@@ -806,12 +787,10 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
if (rem_rtp_port>0)
ms_filter_call_method(stream->ms.rtpsend,MS_RTP_SEND_SET_SESSION,rtps);
stream->ms.rtprecv=ms_factory_create_filter(stream->ms.factory,MS_RTP_RECV_ID);
//stream->ms.rtprecv=ms_filter_new(MS_RTP_RECV_ID);
ms_filter_call_method(stream->ms.rtprecv,MS_RTP_RECV_SET_SESSION,rtps);
stream->ms.sessions.rtp_session=rtps;
if((stream->features & AUDIO_STREAM_FEATURE_DTMF_ECHO) != 0)
//stream->dtmfgen=ms_filter_new(MS_DTMF_GEN_ID);
stream->dtmfgen=ms_factory_create_filter(stream->ms.factory, MS_DTMF_GEN_ID);
else
stream->dtmfgen=NULL;
......@@ -832,14 +811,10 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
stream->rtp_io_session = io->input.session;
pt = rtp_profile_get_payload(rtp_session_get_profile(stream->rtp_io_session),
rtp_session_get_recv_payload_type(stream->rtp_io_session));
//stream->soundread = ms_filter_new(MS_RTP_RECV_ID);
stream->soundread = ms_factory_create_filter(stream->ms.factory, MS_RTP_RECV_ID);
ms_filter_call_method(stream->soundread, MS_RTP_RECV_SET_SESSION, stream->rtp_io_session);
//stream->read_decoder = ms_filter_create_decoder(pt->mime_type);
stream->read_decoder = ms_factory_create_decoder(stream->ms.factory, pt->mime_type);
} else {
// stream->soundread=ms_filter_new(MS_FILE_PLAYER_ID);
// stream->read_resampler=ms_filter_new(MS_RESAMPLE_ID);
stream->soundread=ms_factory_create_filter(stream->ms.factory, MS_FILE_PLAYER_ID);
stream->read_resampler=ms_factory_create_filter(stream->ms.factory, MS_RESAMPLE_ID);
......@@ -851,15 +826,13 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
stream->rtp_io_session = io->output.session;
pt = rtp_profile_get_payload(rtp_session_get_profile(stream->rtp_io_session),
rtp_session_get_send_payload_type(stream->rtp_io_session));
// stream->soundwrite = ms_filter_new(MS_RTP_SEND_ID);
stream->soundwrite = ms_factory_create_filter(stream->ms.factory, MS_RTP_SEND_ID);
ms_filter_call_method(stream->soundwrite, MS_RTP_SEND_SET_SESSION, stream->rtp_io_session);
//stream->write_encoder = ms_filter_create_encoder(pt->mime_type);
stream->write_encoder = ms_factory_create_decoder(stream->ms.factory,pt->mime_type);
} else {
// stream->soundwrite=ms_filter_new(MS_FILE_REC_ID);
stream->soundwrite=ms_factory_create_filter(stream->ms.factory, MS_FILE_REC_ID);
}
......@@ -878,7 +851,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
&& ( strcasecmp(pt->mime_type,"pcmu")==0 || strcasecmp(pt->mime_type,"pcma")==0)){
/*if no telephone-event payload is usable and pcma or pcmu is used, we will generate
inband dtmf*/
// stream->dtmfgen_rtp=ms_filter_new (MS_DTMF_GEN_ID);
stream->dtmfgen_rtp=ms_factory_create_filter (stream->ms.factory, MS_DTMF_GEN_ID);
} else {
......@@ -949,12 +921,10 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
if ((stream->features & AUDIO_STREAM_FEATURE_VOL_SND) != 0)
stream->volsend=ms_factory_create_filter(stream->ms.factory, MS_VOLUME_ID);
//stream->volsend=ms_filter_new(MS_VOLUME_ID);
else
stream->volsend=NULL;
if ((stream->features & AUDIO_STREAM_FEATURE_VOL_RCV) != 0)
stream->volrecv=ms_factory_create_filter(stream->ms.factory, MS_VOLUME_ID);
//stream->volrecv=ms_filter_new(MS_VOLUME_ID);
else
stream->volrecv=NULL;
......@@ -973,7 +943,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
int tmp=1;
if (stream->volsend==NULL)
stream->volsend=ms_factory_create_filter(stream->ms.factory, MS_VOLUME_ID);
// stream->volsend=ms_filter_new(MS_VOLUME_ID);
ms_filter_call_method(stream->volsend,MS_VOLUME_ENABLE_AGC,&tmp);
}
......@@ -992,7 +961,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
/* give the sound filters some properties */
if (err1 != 0 || err2 != 0){
/* need to add resampler*/
// if (stream->read_resampler == NULL) stream->read_resampler = ms_filter_new(MS_RESAMPLE_ID);
if (stream->read_resampler == NULL) stream->read_resampler = ms_factory_create_filter(stream->ms.factory, MS_RESAMPLE_ID);
}
......@@ -1001,7 +969,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
err2 = ms_filter_call_method(stream->soundwrite, MS_FILTER_SET_NCHANNELS, &nchannels);
if (err1 !=0 || err2 != 0){
/* need to add resampler*/
// if (stream->write_resampler == NULL) stream->write_resampler = ms_filter_new(MS_RESAMPLE_ID);
if (stream->write_resampler == NULL) stream->write_resampler = ms_factory_create_filter(stream->ms.factory, MS_RESAMPLE_ID);
}
......@@ -1017,7 +984,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
}
if (stream->features & AUDIO_STREAM_FEATURE_MIXED_RECORDING || stream->features & AUDIO_STREAM_FEATURE_REMOTE_PLAYING){
// stream->outbound_mixer=ms_filter_new(MS_AUDIO_MIXER_ID);
stream->outbound_mixer=ms_factory_create_filter(stream->ms.factory, MS_AUDIO_MIXER_ID);
}
......@@ -1052,7 +1018,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
/*create the equalizer*/
if ((stream->features & AUDIO_STREAM_FEATURE_EQUALIZER) != 0){
stream->equalizer=ms_factory_create_filter(stream->ms.factory, MS_EQUALIZER_ID);
//stream->equalizer=ms_filter_new(MS_EQUALIZER_ID);
if(stream->equalizer) {
tmp=stream->eq_active;
ms_filter_call_method(stream->equalizer,MS_EQUALIZER_SET_ACTIVE,&tmp);
......@@ -1115,7 +1080,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
ms_warning("MS_DECODER_HAVE_PLC function not implemented by the decoder: enable default plc");
}
if (decoder_have_plc == 0) {
//stream->plc = ms_filter_new(MS_GENERIC_PLC_ID);
stream->plc = ms_factory_create_filter(stream->ms.factory, MS_GENERIC_PLC_ID);
}
......@@ -1131,7 +1095,6 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
}
if (stream->features & AUDIO_STREAM_FEATURE_LOCAL_PLAYING){
//stream->local_mixer=ms_filter_new(MS_AUDIO_MIXER_ID);
stream->local_mixer=ms_factory_create_filter(stream->ms.factory, MS_AUDIO_MIXER_ID);
}
......@@ -1404,7 +1367,6 @@ void audio_stream_set_features(AudioStream *st, uint32_t features){
AudioStream *audio_stream_new_with_sessions(const MSMediaStreamSessions *sessions, MSFactory *factory){
AudioStream *stream=(AudioStream *)ms_new0(AudioStream,1);
// MSFilterDesc *ec_desc=ms_filter_lookup_by_name("MSWebRTCAEC");
MSFilterDesc *ec_desc=ms_factory_lookup_filter_by_name(factory, "MSWebRTAEC");
const OrtpRtcpXrMediaCallbacks rtcp_xr_media_cbs = {
audio_stream_get_rtcp_xr_plc_status,
......@@ -1418,13 +1380,9 @@ AudioStream *audio_stream_new_with_sessions(const MSMediaStreamSessions *session
stream->ms.type = MSAudio;
stream->ms.sessions = *sessions;
media_stream_init(&stream->ms,factory);
// media_stream_init(&stream->ms, ms_factory_get_fallback());
ms_factory_enable_statistics(factory, TRUE);
ms_factory_reset_statistics(factory);
// ms_filter_enable_statistics(TRUE);
//ms_filter_reset_statistics();
if (sessions->zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(sessions->zrtp_context, &(stream->ms.sessions));
......@@ -1434,17 +1392,14 @@ AudioStream *audio_stream_new_with_sessions(const MSMediaStreamSessions *session
}
rtp_session_resync(stream->ms.sessions.rtp_session);
/*some filters are created right now to allow configuration by the application before start() */
// stream->ms.rtpsend=ms_filter_new(MS_RTP_SEND_ID);
stream->ms.rtpsend=ms_factory_create_filter(factory, MS_RTP_SEND_ID);
stream->ms.ice_check_list=NULL;
stream->ms.qi=ms_quality_indicator_new(stream->ms.sessions.rtp_session);
ms_quality_indicator_set_label(stream->ms.qi,"audio");
stream->ms.process_rtcp=audio_stream_process_rtcp;
if (ec_desc!=NULL){
//stream->ec=ms_filter_new_from_desc(ec_desc);
stream->ec=ms_factory_create_filter_from_desc(factory, ec_desc);
}else{
//stream->ec=ms_filter_new(MS_SPEEX_EC_ID);
stream->ec=ms_factory_create_filter(factory, MS_SPEEX_EC_ID );
}
stream->play_dtmfs=TRUE;
......
......@@ -964,14 +964,15 @@ int vp8rtpfmt_unpacker_get_frame(Vp8RtpFmtUnpackerCtx *ctx, MSQueue *out, Vp8Rtp
}
static void packer_process_frame_part(void *p, void *c) {
static void packer_process_frame_part(void *p, void *c, void *f) {
Vp8RtpFmtPacket *packet = (Vp8RtpFmtPacket *)p;
Vp8RtpFmtPackerCtx *ctx = (Vp8RtpFmtPackerCtx *)c;
MSFactory* factory = (MSFactory*) f;
mblk_t *pdm = NULL;
mblk_t *dm = NULL;
uint8_t *rptr;
uint8_t pdsize = 1;
int max_size = ms_get_payload_max_size();
int max_size = ms_factory_get_payload_max_size(factory);
int dlen;
bool_t marker_info = mblk_get_marker_info(packet->m);
......@@ -1058,9 +1059,9 @@ void vp8rtpfmt_packer_init(Vp8RtpFmtPackerCtx *ctx) {
void vp8rtpfmt_packer_uninit(Vp8RtpFmtPackerCtx *ctx) {
}
void vp8rtpfmt_packer_process(Vp8RtpFmtPackerCtx *ctx, MSList *in, MSQueue *out) {
void vp8rtpfmt_packer_process(Vp8RtpFmtPackerCtx *ctx, MSList *in, MSQueue *out, MSFactory *f) {
ctx->output_queue = out;
ms_list_for_each2(in, packer_process_frame_part, ctx);
ms_list_for_each3(in, packer_process_frame_part, ctx, f);
ms_list_for_each(in, free_packet);
ms_list_free(in);
}
......@@ -124,7 +124,7 @@ extern "C"{
void vp8rtpfmt_packer_init(Vp8RtpFmtPackerCtx *ctx);
void vp8rtpfmt_packer_uninit(Vp8RtpFmtPackerCtx *ctx);
void vp8rtpfmt_packer_process(Vp8RtpFmtPackerCtx *ctx, MSList *in, MSQueue *out);
void vp8rtpfmt_packer_process(Vp8RtpFmtPackerCtx *ctx, MSList *in, MSQueue *out, MSFactory *f);
void vp8rtpfmt_unpacker_init(Vp8RtpFmtUnpackerCtx *ctx, MSFilter *f, bool_t avpf_enabled, bool_t freeze_on_error, bool_t output_partitions);
void vp8rtpfmt_unpacker_uninit(Vp8RtpFmtUnpackerCtx *ctx);
......
......@@ -38,14 +38,19 @@ static void tone_sent_cb(void *data, MSFilter *f, unsigned int event_id, MSDtmfG
int main(int argc, char *argv[]){
MSFilter *src, *gen, *det, *rec;
MSTicker *ticker;
MSFactory *factory ;
//ms_base_init();
ms_base_init();
factory = ms_factory_new();
ms_factory_init_voip(factory);
ms_factory_init_plugins(factory);
ortp_set_log_level_mask (ORTP_LOG_DOMAIN, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
src=ms_filter_new(MS_FILE_PLAYER_ID);
rec=ms_filter_new(MS_FILE_REC_ID);
gen=ms_filter_new(MS_DTMF_GEN_ID);
det=ms_filter_new(MS_TONE_DETECTOR_ID);
src=ms_factory_create_filter(factory,MS_FILE_PLAYER_ID);
rec=ms_factory_create_filter(factory,MS_FILE_REC_ID);
gen=ms_factory_create_filter(factory,MS_DTMF_GEN_ID);
det=ms_factory_create_filter(factory,MS_TONE_DETECTOR_ID);
ms_filter_link(src,0,gen,0);
ms_filter_link(gen,0,det,0);
......
......@@ -34,11 +34,17 @@ int main(int argc, char *argv[]){
VideoStream *vs;
MSWebCam *cam;
MSVideoSize vsize;
MSFactory* factory;
int i;
vsize.width=MS_VIDEO_SIZE_CIF_W;
vsize.height=MS_VIDEO_SIZE_CIF_H;
factory = ms_factory_new();
ms_factory_init_voip(factory);
ms_factory_init_plugins(factory);
ortp_init();
ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
ms_init();
......@@ -50,6 +56,7 @@ int main(int argc, char *argv[]){
for(i=0;i<1;++i){
int n;
vs=video_preview_new();
vs->factory=factory;
/*video_preview_set_display_filter_name(vs,"MSVideoOut");*/
video_preview_set_size(vs,vsize);
video_preview_start(vs, cam);
......
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