Commit b0f341d2 authored by Mickaël Turnel's avatar Mickaël Turnel

Add a function to allow mediastreamer2 to stop the async rtp thread in case of a video call pause

parent 11c91f79
......@@ -619,6 +619,9 @@ ORTP_PUBLIC int rtp_session_recvfrom(RtpSession *session, bool_t is_rtp, mblk_t
ORTP_PUBLIC int rtp_session_recv_with_ts(RtpSession *session, uint8_t *buffer, int len, uint32_t ts, int *have_more);
ORTP_PUBLIC int rtp_session_send_with_ts(RtpSession *session, const uint8_t *buffer, int len, uint32_t userts);
/* Specific function only called in Windows environment */
ORTP_PUBLIC void rtp_session_stop_async_recvfrom(RtpSession *session);
/* event API*/
ORTP_PUBLIC void rtp_session_register_event_queue(RtpSession *session, OrtpEvQueue *q);
ORTP_PUBLIC void rtp_session_unregister_event_queue(RtpSession *session, OrtpEvQueue *q);
......
......@@ -2507,3 +2507,9 @@ bool_t ortp_stream_is_ipv6(OrtpStream *os) {
}
return FALSE;
}
void rtp_session_stop_async_recvfrom(RtpSession *session) {
session->rtp.is_win_thread_running = FALSE;
ortp_thread_join(session->rtp.win_t, NULL);
flushq(&session->rtp.winrq, FLUSHALL);
}
......@@ -1661,7 +1661,7 @@ void* rtp_session_recvfrom_async(void* obj) {
int ret = WSAPoll(&fdarray, 1, 10);
if (ret == SOCKET_ERROR) {
ortp_warning("Error rtp recv sync thread for windows: error while polling [%i]", WSAGetLastError());
ortp_warning("Error rtp recv async thread for windows: error while polling [%i]", WSAGetLastError());
} else if (ret > 0) {
#endif
bool_t sock_connected=!!(session->flags & RTP_SOCKET_CONNECTED);
......
......@@ -22,6 +22,8 @@
#include <math.h>
#include <ortp/rtpsession.h>
#define MIN_DIFFTIME 0.00001f
OrtpVideoBandwidthEstimator * ortp_video_bandwidth_estimator_new(RtpSession *session) {
OrtpVideoBandwidthEstimator *vbe = (OrtpVideoBandwidthEstimator*)ortp_malloc0(sizeof(OrtpVideoBandwidthEstimator));
vbe->session = session;
......@@ -94,23 +96,25 @@ static void compute_bitrate_add_to_list_and_remove_oldest_value(OrtpVideoBandwid
float difftime = (float)(packet->recv_last_timestamp.tv_sec - packet->recv_first_timestamp.tv_sec)
+ 1e-6f*(packet->recv_last_timestamp.tv_usec - packet->recv_first_timestamp.tv_usec);
packet->bitrate = (packet->bytes * 8 / difftime);
ortp_debug("[VBE] Bitrate is %f kbits/s computed using %f timedif and %u size", packet->bitrate / 1000, difftime, packet->bytes);
if (difftime > MIN_DIFFTIME) {
packet->bitrate = (packet->bytes * 8 / difftime);
ortp_debug("[VBE] Bitrate is %f kbits/s computed using %f timedif and %u size", packet->bitrate / 1000, difftime, packet->bytes);
vbe->nb_packets_computed += 1;
vbe->packets = bctbx_list_prepend(vbe->packets, packet);
vbe->nb_packets_computed += 1;
vbe->packets = bctbx_list_prepend(vbe->packets, packet);
if (bctbx_list_size(vbe->packets) > vbe->packets_size_max) {
void *old_data = bctbx_list_nth_data(vbe->packets, vbe->packets_size_max);
vbe->packets = bctbx_list_remove(vbe->packets, old_data);
}
if (bctbx_list_size(vbe->packets) > vbe->packets_size_max) {
void *old_data = bctbx_list_nth_data(vbe->packets, vbe->packets_size_max);
vbe->packets = bctbx_list_remove(vbe->packets, old_data);
}
if (vbe->nb_packets_computed % vbe->packets_size_max == 0) {
OrtpEvent *ev = ortp_event_new(ORTP_EVENT_NEW_VIDEO_BANDWIDTH_ESTIMATION_AVAILABLE);
OrtpEventData *ed = ortp_event_get_data(ev);
ed->info.video_bandwidth_available = ortp_video_bandwidth_estimator_get_estimated_available_bandwidth(vbe);
ortp_debug("[VBE] Dispatching event ORTP_EVENT_NEW_VIDEO_BANDWIDTH_ESTIMATION_AVAILABLE with value %f kbits/s", ed->info.video_bandwidth_available / 1000);
rtp_session_dispatch_event(vbe->session, ev);
if (vbe->nb_packets_computed % vbe->packets_size_max == 0) {
OrtpEvent *ev = ortp_event_new(ORTP_EVENT_NEW_VIDEO_BANDWIDTH_ESTIMATION_AVAILABLE);
OrtpEventData *ed = ortp_event_get_data(ev);
ed->info.video_bandwidth_available = ortp_video_bandwidth_estimator_get_estimated_available_bandwidth(vbe);
ortp_debug("[VBE] Dispatching event ORTP_EVENT_NEW_VIDEO_BANDWIDTH_ESTIMATION_AVAILABLE with value %f kbits/s", ed->info.video_bandwidth_available / 1000);
rtp_session_dispatch_event(vbe->session, ev);
}
}
}
......
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