static gboolean audio_receive_rt_msg()

in chime/chime-call-audio.c [39:124]


static gboolean audio_receive_rt_msg(ChimeCallAudio *audio, gconstpointer pkt, gsize len)
{
	RTMessage *msg = rtmessage__unpack(NULL, len, pkt);
	if (!msg)
		return FALSE;
	gint64 now = g_get_monotonic_time();

	if (msg->client_status) {
		/* This never seems to happen in practice. We just get a Juggernaut message
		 * about the call roster, with a 'muter' node in our own participant information. */
		if (msg->client_status->has_remote_muted && msg->client_status->remote_muted) {
			chime_call_audio_local_mute(audio, TRUE);

			audio->rt_msg.client_status = &audio->client_status_msg;
			audio->client_status_msg.has_remote_mute_ack = TRUE;
			audio->client_status_msg.remote_mute_ack = TRUE;
		} else {
			audio->rt_msg.client_status = NULL;
		}

	}
	if (msg->audio) {
		if (msg->audio->has_server_time) {
			audio->last_server_time_offset = msg->audio->server_time - now;
			audio->echo_server_time = TRUE;
		}
		if (msg->audio->has_audio && audio->audio_src && audio->appsrc_need_data) {
			GstBuffer *buffer = gst_rtp_buffer_new_allocate(msg->audio->audio.len, 0, 0);
			GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
			if (gst_rtp_buffer_map(buffer, GST_MAP_WRITE, &rtp)) {

				chime_debug("Audio RX seq %d ts %u\n", msg->audio->seq, msg->audio->sample_time);

				gst_rtp_buffer_set_ssrc(&rtp, audio->recv_ssrc);
				gst_rtp_buffer_set_payload_type(&rtp, 97);
				gst_rtp_buffer_set_seq(&rtp, msg->audio->seq);
				gst_rtp_buffer_set_timestamp(&rtp, msg->audio->sample_time);
				gst_rtp_buffer_unmap(&rtp);

				gst_buffer_fill(buffer, gst_rtp_buffer_calc_header_len(0),
						msg->audio->audio.data, msg->audio->audio.len);

				gst_app_src_push_buffer(GST_APP_SRC(audio->audio_src), buffer);
			}
		} else if (msg->audio->has_audio && msg->audio->audio.len) {
			chime_debug("Audio drop (%p %d) seq %d ts %u\n",
				    audio->audio_src, audio->appsrc_need_data,
				    msg->audio->seq, msg->audio->sample_time);
		}

	}
	gboolean send_sig = FALSE;
	int i;
	for (i=0; i < msg->n_profiles; i++) {
		if (!msg->profiles[i]->has_stream_id)
			continue;

		const gchar *profile_id = g_hash_table_lookup(audio->profiles,
							      GUINT_TO_POINTER(msg->profiles[i]->stream_id));
		if (!profile_id) {
			chime_debug("no profile for stream id %d\n",
			       msg->profiles[i]->stream_id);
			continue;
		}

		int vol;
		if (msg->profiles[i]->has_muted && msg->profiles[i]->muted)
			vol = -128;
		else if (msg->profiles[i]->has_volume)
			vol = - msg->profiles[i]->volume;
		else /* We should have one or the other */
			continue;

		int signal_strength = -1;
		if (msg->profiles[i]->has_signal_strength)
			signal_strength = msg->profiles[i]->signal_strength;
		chime_debug("Participant %s vol %d\n", profile_id, vol);
		if (chime_call_participant_audio_stats(audio->call, profile_id, vol, signal_strength))
			send_sig = TRUE;
	}
	if (send_sig)
		chime_call_emit_participants(audio->call);

	rtmessage__free_unpacked(msg, NULL);
	return TRUE;
}