int start_transmission(ToxWindow *self) { if ( !ASettins.av || self->call_idx == -1 ) return -1; /* Don't provide support for video */ if ( 0 != toxav_prepare_transmission(ASettins.av, self->call_idx, av_jbufdc * 2, av_VADd, 0) ) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Could not prepare transmission"); } if ( !toxav_capability_supported(ASettins.av, self->call_idx, AudioDecoding) || !toxav_capability_supported(ASettins.av, self->call_idx, AudioEncoding) ) return -1; set_call(&ASettins.calls[self->call_idx], _True); ToxAvCSettings csettings; toxav_get_peer_csettings(ASettins.av, self->call_idx, 0, &csettings); if ( open_primary_device(input, &ASettins.calls[self->call_idx].in_idx, csettings.audio_sample_rate, csettings.audio_frame_duration, csettings.audio_channels) != de_None ) line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open input device!"); if ( register_device_callback(self->call_idx, ASettins.calls[self->call_idx].in_idx, read_device_callback, &self->call_idx, _True) != de_None) /* Set VAD as true for all; TODO: Make it more dynamic */ line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to register input handler!"); if ( open_primary_device(output, &ASettins.calls[self->call_idx].out_idx, csettings.audio_sample_rate, csettings.audio_frame_duration, csettings.audio_channels) != de_None ) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open output device!"); ASettins.calls[self->call_idx].has_output = 0; } return 0; }
void Core::onAvMediaChange(void* toxav, int32_t callId, void* core) { int friendId; int cap = toxav_capability_supported((ToxAv*)toxav, callId, (ToxAvCapabilities)(av_VideoEncoding|av_VideoDecoding)); if (!cap) goto fail; friendId = toxav_get_peer_id((ToxAv*)toxav, callId, 0); if (friendId < 0) goto fail; qDebug() << "Core: Received media change from friend "<<friendId; if (cap == (av_VideoEncoding|av_VideoDecoding)) // Video call { Camera::getInstance()->subscribe(); calls[callId].videoEnabled = true; calls[callId].sendVideoTimer->start(); emit ((Core*)core)->avMediaChange(friendId, callId, true); } else // Audio call { calls[callId].videoEnabled = false; calls[callId].sendVideoTimer->stop(); Camera::getInstance()->unsubscribe(); emit ((Core*)core)->avMediaChange(friendId, callId, false); } return; fail: // Centralized error handling qWarning() << "Core: Toxcore error while receiving media change on call "<<callId; return; }
int start_transmission(ToxWindow *self) { if ( !ASettins.av || self->call_idx == -1 ) return -1; /* Don't provide support for video */ if ( 0 != toxav_prepare_transmission(ASettins.av, self->call_idx, &ASettins.cs, 0) ) { line_info_add(self, NULL, NULL, NULL, "Could not prepare transmission", SYS_MSG, 0, 0); } if ( !toxav_capability_supported(ASettins.av, self->call_idx, AudioDecoding) || !toxav_capability_supported(ASettins.av, self->call_idx, AudioEncoding) ) return -1; set_call(&ASettins.calls[self->call_idx], _True); if ( 0 != pthread_create(&ASettins.calls[self->call_idx].ttid, NULL, transmission, self ) && 0 != pthread_detach(ASettins.calls[self->call_idx].ttid) ) { return -1; } return 0; }