static void stream_manager_delete(stream_manager_t * mgr) { if (mgr->type==MSAudio){ if( mgr->user_data){ unlink((char*)mgr->user_data); // don't reset user_data, it is up to the user to free() it } audio_stream_stop(mgr->audio_stream); }else{ #if VIDEO_ENABLED video_stream_stop(mgr->video_stream); #else ms_fatal("Unsupported stream type [%s]",ms_format_type_to_string(mgr->type)); #endif } ms_free(mgr); }
stream_manager_t * stream_manager_new(MSFormatType type) { stream_manager_t * mgr = ms_new0(stream_manager_t,1); mgr->type=type; mgr->local_rtp=(rand() % ((2^16)-1024) + 1024) & ~0x1; mgr->local_rtcp=mgr->local_rtp+1; mgr->user_data = 0; if (mgr->type==MSAudio){ mgr->audio_stream=audio_stream_new (mgr->local_rtp, mgr->local_rtcp,FALSE); }else{ #if VIDEO_ENABLED mgr->video_stream=video_stream_new (mgr->local_rtp, mgr->local_rtcp,FALSE); #else ms_fatal("Unsupported stream type [%s]",ms_format_type_to_string(mgr->type)); #endif } return mgr; }
const char * media_stream_type_str(MediaStream *stream) { return ms_format_type_to_string(stream->type); }
void start_adaptive_stream(MSFormatType type, stream_manager_t ** pmarielle, stream_manager_t ** pmargaux, int payload, int initial_bitrate, int max_bw, float loss_rate, int latency, float dup_ratio) { int pause_time=0; PayloadType* pt; MediaStream *marielle_ms,*margaux_ms; OrtpNetworkSimulatorParams params={0}; #if VIDEO_ENABLED MSWebCam * marielle_webcam=ms_web_cam_manager_get_default_cam (ms_web_cam_manager_get()); #endif stream_manager_t *marielle=*pmarielle=stream_manager_new(type); stream_manager_t *margaux=*pmargaux=stream_manager_new(type); char* file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_16K_1S_FILE); char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_16K_1S_FILE); marielle->user_data = recorded_file; params.enabled=TRUE; params.loss_rate=loss_rate; params.max_bandwidth=max_bw; params.latency=latency; if (type == MSAudio){ marielle_ms=&marielle->audio_stream->ms; margaux_ms=&margaux->audio_stream->ms; }else{ marielle_ms=&marielle->video_stream->ms; margaux_ms=&margaux->video_stream->ms; } /* Disable avpf. */ pt = rtp_profile_get_payload(&rtp_profile, VP8_PAYLOAD_TYPE); CU_ASSERT_PTR_NOT_NULL_FATAL(pt); payload_type_unset_flag(pt, PAYLOAD_TYPE_RTCP_FEEDBACK_ENABLED); media_stream_enable_adaptive_bitrate_control(marielle_ms,TRUE); media_stream_set_adaptive_bitrate_algorithm(marielle_ms, MSQosAnalyzerAlgorithmStateful); rtp_session_set_duplication_ratio(marielle_ms->sessions.rtp_session, dup_ratio); if (marielle->type == MSAudio){ audio_manager_start(marielle,payload,margaux->local_rtp,initial_bitrate,file,NULL); ms_filter_call_method(marielle->audio_stream->soundread,MS_FILE_PLAYER_LOOP,&pause_time); audio_manager_start(margaux,payload,marielle->local_rtp,0,NULL,recorded_file); }else{ #if VIDEO_ENABLED video_manager_start(marielle,payload,margaux->local_rtp,0,marielle_webcam); video_stream_set_direction(margaux->video_stream,VideoStreamRecvOnly); video_manager_start(margaux,payload,marielle->local_rtp,0,NULL); #else ms_fatal("Unsupported stream type [%s]",ms_format_type_to_string(marielle->type)); #endif } ms_qos_analyzer_set_on_action_suggested(ms_bitrate_controller_get_qos_analyzer(marielle_ms->rc), qos_analyzer_on_action_suggested, *pmarielle); rtp_session_enable_network_simulation(margaux_ms->sessions.rtp_session,¶ms); ms_free(recorded_file); ms_free(file); }