mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Some progress
This commit is contained in:
parent
a4fae8ffd4
commit
62af82705a
|
@ -39,6 +39,7 @@
|
|||
typedef struct {
|
||||
bool incoming;
|
||||
uint32_t state;
|
||||
uint32_t output_source;
|
||||
} CallControl;
|
||||
|
||||
const char* stringify_state(TOXAV_CALL_STATE s)
|
||||
|
@ -58,6 +59,8 @@ const char* stringify_state(TOXAV_CALL_STATE s)
|
|||
};
|
||||
|
||||
|
||||
int device_play_frame(uint32_t source, const int16_t* PCM, size_t size);
|
||||
|
||||
/**
|
||||
* Callbacks
|
||||
*/
|
||||
|
@ -86,7 +89,7 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
|
|||
uint32_t sampling_rate,
|
||||
void *user_data)
|
||||
{
|
||||
printf("Handling AUDIO FRAME callback\n");
|
||||
device_play_frame(((CallControl*)user_data)->output_source, pcm, sample_count);
|
||||
}
|
||||
void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
||||
{
|
||||
|
@ -173,7 +176,7 @@ int device_read_frame(ALCdevice* device, int32_t frame_dur, int16_t* PCM, size_t
|
|||
return f_size;
|
||||
}
|
||||
|
||||
int device_play_frame(uint32_t source, int16_t* PCM, size_t size)
|
||||
int device_play_frame(uint32_t source, const int16_t* PCM, size_t size)
|
||||
{
|
||||
uint32_t bufid;
|
||||
int32_t processed, queued;
|
||||
|
@ -604,17 +607,67 @@ int main (int argc, char** argv)
|
|||
if (TEST_TRANSFER_A) { /* Audio encoding/decoding and transfer */
|
||||
printf("\nTrying audio enc/dec...\n");
|
||||
|
||||
memset(&AliceCC, 0, sizeof(CallControl));
|
||||
memset(&BobCC, 0, sizeof(CallControl));
|
||||
|
||||
AliceCC.output_source = BobCC.output_source = source;
|
||||
|
||||
{
|
||||
TOXAV_ERR_CALL rc;
|
||||
toxav_call(AliceAV, 0, 48, 0, &rc);
|
||||
|
||||
if (rc != TOXAV_ERR_CALL_OK) {
|
||||
printf("toxav_call failed: %d\n", rc);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
while (!BobCC.incoming)
|
||||
iterate(Bsn, AliceAV, BobAV);
|
||||
|
||||
{
|
||||
TOXAV_ERR_ANSWER rc;
|
||||
toxav_answer(BobAV, 0, 48, 0, &rc);
|
||||
|
||||
if (rc != TOXAV_ERR_ANSWER_OK) {
|
||||
printf("toxav_answer failed: %d\n", rc);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
iterate(Bsn, AliceAV, BobAV);
|
||||
|
||||
int16_t PCM[10000];
|
||||
time_t start_time = time(NULL);
|
||||
|
||||
/* Run for 5 seconds */
|
||||
while ( start_time + 10 > time(NULL) ) {
|
||||
int frame_size = device_read_frame(in_device, 20, PCM, sizeof(PCM));
|
||||
if (frame_size > 0)
|
||||
device_play_frame(source, PCM, frame_size);
|
||||
if (frame_size > 0) {
|
||||
TOXAV_ERR_SEND_FRAME rc;
|
||||
if (toxav_send_audio_frame(AliceAV, 0, PCM, frame_size, 2, 48000, &rc) == false) {
|
||||
printf("Error sending frame of size %d: %d\n", frame_size, rc);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
iterate(Bsn, AliceAV, BobAV);
|
||||
// c_sleep(20);
|
||||
}
|
||||
|
||||
{
|
||||
TOXAV_ERR_CALL_CONTROL rc;
|
||||
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
|
||||
if (rc != TOXAV_ERR_CALL_CONTROL_OK) {
|
||||
printf("toxav_call_control failed: %d\n", rc);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
iterate(Bsn, AliceAV, BobAV);
|
||||
assert(BobCC.state == TOXAV_CALL_STATE_END);
|
||||
|
||||
printf("Success!");
|
||||
}
|
||||
|
||||
|
|
|
@ -245,7 +245,7 @@ void cs_do(CSSession *cs)
|
|||
/* Codec session should always be protected by call mutex so no need to check for cs validity
|
||||
*/
|
||||
|
||||
if (!cs)
|
||||
if (!cs)
|
||||
return;
|
||||
|
||||
Payload *p;
|
||||
|
@ -258,7 +258,7 @@ void cs_do(CSSession *cs)
|
|||
if (cs->audio_decoder) { /* If receiving enabled */
|
||||
RTPMessage *msg;
|
||||
|
||||
uint16_t fsize = 5760; /* Max frame size for 48 kHz */
|
||||
uint16_t fsize = 16000; /* Max frame size for 48 kHz */
|
||||
int16_t tmp[fsize * 2];
|
||||
|
||||
while ((msg = jbuf_read(cs->j_buf, &success)) || success == 2) {
|
||||
|
@ -284,6 +284,7 @@ void cs_do(CSSession *cs)
|
|||
continue;
|
||||
}
|
||||
|
||||
LOGGER_DEBUG("Decoding packet of length: %d", msg->length);
|
||||
rc = opus_decode(cs->audio_decoder, msg->data, msg->length, tmp, fsize, 0);
|
||||
rtp_free_msg(NULL, msg);
|
||||
}
|
||||
|
@ -741,8 +742,9 @@ void queue_message(RTPSession *session, RTPMessage *msg)
|
|||
*/
|
||||
CSSession *cs = session->cs;
|
||||
|
||||
if (!cs) return;
|
||||
|
||||
if (!cs)
|
||||
return;
|
||||
|
||||
/* Audio */
|
||||
if (session->payload_type == rtp_TypeAudio % 128) {
|
||||
pthread_mutex_lock(cs->queue_mutex);
|
||||
|
|
|
@ -363,7 +363,6 @@ int rtp_handle_packet ( Messenger *m, int32_t friendnumber, const uint8_t *data,
|
|||
}
|
||||
|
||||
queue_message(session, msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -427,8 +426,6 @@ RTPSession *rtp_new ( int payload_type, Messenger *messenger, int friend_num )
|
|||
return NULL;
|
||||
}
|
||||
|
||||
LOGGER_DEBUG("Registered packet handler: pt: %d; fid: %d", payload_type, friend_num);
|
||||
|
||||
retu->version = RTP_VERSION; /* It's always 2 */
|
||||
retu->padding = 0; /* If some additional data is needed about the packet */
|
||||
retu->extension = 0; /* If extension to header is needed */
|
||||
|
@ -467,7 +464,7 @@ void rtp_kill ( RTPSession *session )
|
|||
{
|
||||
if ( !session ) return;
|
||||
|
||||
custom_lossy_packet_registerhandler(session->m, session->dest, session->prefix, NULL, NULL);
|
||||
rtp_stop_receiving (session);
|
||||
|
||||
free ( session->ext_header );
|
||||
free ( session->csrc );
|
||||
|
@ -483,6 +480,7 @@ int rtp_start_receiving(RTPSession* session)
|
|||
if (session == NULL)
|
||||
return 0;
|
||||
|
||||
LOGGER_DEBUG("Registering packet handler: pt: %d; friend: %d", session->prefix, session->dest);
|
||||
return custom_lossy_packet_registerhandler(session->m, session->dest, session->prefix,
|
||||
rtp_handle_packet, session);
|
||||
}
|
||||
|
@ -492,6 +490,7 @@ int rtp_stop_receiving(RTPSession* session)
|
|||
if (session == NULL)
|
||||
return 0;
|
||||
|
||||
LOGGER_DEBUG("Unregistering packet handler: pt: %d; friend: %d", session->prefix, session->dest);
|
||||
return custom_lossy_packet_registerhandler(session->m, session->dest, session->prefix,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
|
|
@ -215,13 +215,6 @@ void toxav_iteration(ToxAV* av)
|
|||
for (; i; i = i->next) {
|
||||
if (i->active) {
|
||||
pthread_mutex_lock(i->mutex_decoding);
|
||||
|
||||
/* TODO make AV synchronisation */
|
||||
if (av->racb.first)
|
||||
av->racb.first(av, i->friend_id, av->racb.second);
|
||||
if (av->rvcb.first)
|
||||
av->rvcb.first(av, i->friend_id, av->rvcb.second);
|
||||
|
||||
pthread_mutex_unlock(av->mutex);
|
||||
cs_do(i->cs);
|
||||
rc = MIN(i->cs->last_packet_frame_duration, rc);
|
||||
|
@ -304,6 +297,11 @@ bool toxav_answer(ToxAV* av, uint32_t friend_number, uint32_t audio_bit_rate, ui
|
|||
goto END;
|
||||
}
|
||||
|
||||
if (!call_prepare_transmission(call)) {
|
||||
rc = TOXAV_ERR_ANSWER_MALLOC;
|
||||
goto END;
|
||||
}
|
||||
|
||||
call->s_audio_b = audio_bit_rate;
|
||||
call->s_video_b = video_bit_rate;
|
||||
|
||||
|
@ -645,7 +643,7 @@ bool toxav_send_audio_frame(ToxAV* av, uint32_t friend_number, const int16_t* pc
|
|||
goto END;
|
||||
}
|
||||
|
||||
if ( channels != 1 || channels != 2 ) {
|
||||
if ( channels != 1 && channels != 2 ) {
|
||||
pthread_mutex_unlock(call->mutex_audio_sending);
|
||||
rc = TOXAV_ERR_SEND_FRAME_INVALID;
|
||||
goto END;
|
||||
|
@ -666,8 +664,12 @@ bool toxav_send_audio_frame(ToxAV* av, uint32_t friend_number, const int16_t* pc
|
|||
goto END;
|
||||
}
|
||||
|
||||
vrc = rtp_send_msg(call->rtps[audio_index], dest, vrc);
|
||||
/* TODO check for error? */
|
||||
if (rtp_send_msg(call->rtps[audio_index], dest, vrc) != 0) {
|
||||
LOGGER_WARNING("Failed to send audio packet");
|
||||
rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED;
|
||||
}
|
||||
|
||||
LOGGER_DEBUG("Sent packet of size: %d (o %d)", vrc, sample_count);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(call->mutex_audio_sending);
|
||||
|
@ -965,7 +967,10 @@ bool call_prepare_transmission(ToxAVCall* call)
|
|||
goto FAILURE;
|
||||
}
|
||||
|
||||
rtp_start_receiving(call->rtps[audio_index]);
|
||||
if (rtp_start_receiving(call->rtps[audio_index]) != 0) {
|
||||
LOGGER_WARNING("Failed to enable audio receiving!");
|
||||
goto FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
{ /* Prepare video */
|
||||
|
@ -984,13 +989,15 @@ bool call_prepare_transmission(ToxAVCall* call)
|
|||
goto FAILURE;
|
||||
}
|
||||
|
||||
|
||||
if (cs_enable_video_receiving(call->cs) != 0) {
|
||||
LOGGER_WARNING("Failed to enable video receiving!");
|
||||
goto FAILURE;
|
||||
}
|
||||
|
||||
rtp_start_receiving(call->rtps[audio_index]);
|
||||
if (rtp_start_receiving(call->rtps[video_index]) != 0) {
|
||||
LOGGER_WARNING("Failed to enable audio receiving!");
|
||||
goto FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
call->active = 1;
|
||||
|
|
|
@ -380,7 +380,11 @@ typedef enum TOXAV_ERR_SEND_FRAME {
|
|||
* One of the frame parameters was invalid. E.g. the resolution may be too
|
||||
* small or too large, or the audio sampling rate may be unsupported.
|
||||
*/
|
||||
TOXAV_ERR_SEND_FRAME_INVALID
|
||||
TOXAV_ERR_SEND_FRAME_INVALID,
|
||||
/**
|
||||
* Failed to push frame through rtp interface.
|
||||
*/
|
||||
TOXAV_ERR_SEND_FRAME_RTP_FAILED
|
||||
} TOXAV_ERR_SEND_FRAME;
|
||||
/**
|
||||
* The function type for the `request_video_frame` callback.
|
||||
|
|
Loading…
Reference in New Issue
Block a user