/** * @brief Receive RTP payload. * * @param av Handler. * @param type Type of the payload. * @param dest Storage. * @return int * @retval ToxAvError On Error. * @retval >=0 Size of received payload. */ inline__ int toxav_recv_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallType type, uint8_t *dest ) { if ( !dest ) return ErrorInternal; if (cii(call_index, av->msi_session)) return ErrorNoCall; CallSpecific *call = &av->calls[call_index]; if ( !call->crtps[type - TypeAudio] ) return ErrorNoRtpSession; RTPMessage *message; if ( type == TypeAudio ) { do { message = rtp_recv_msg(call->crtps[audio_index]); if (message) { /* push the packet into the queue */ queue(call->j_buf, message); } } while (message); int success = 0; message = dequeue(call->j_buf, &success); if ( success == 2) return ErrorAudioPacketLost; } else { message = rtp_recv_msg(call->crtps[video_index]); } if ( message ) { memcpy(dest, message->data, message->length); int length = message->length; rtp_free_msg(NULL, message); return length; } return 0; }
int main ( int argc, char* argv[] ) { arg_t* _list = parse_args ( argc, argv ); if ( _list == NULL ) { /* failed */ return print_help(); } pthread_mutex_init ( &_mutex, NULL ); int status; IP_Port Ip_port; const char* ip; uint16_t port; const uint8_t* test_bytes [300]; memset(test_bytes, 'a', 300); rtp_session_t* _m_session; rtp_msg_t* _m_msg; if ( find_arg_simple ( _list, "-r" ) != FAILURE ) { /* Server mode */ IP_Port LOCAL_IP; /* since you need at least 1 recv-er */ LOCAL_IP.ip.i = htonl(INADDR_ANY); LOCAL_IP.port = RTP_PORT; LOCAL_IP.padding = -1; _m_session = rtp_init_session ( -1, -1 ); Networking_Core* _networking = new_networking(LOCAL_IP.ip, RTP_PORT_LISTEN); _socket = _networking->sock; if ( !_networking ){ pthread_mutex_destroy ( &_mutex ); return FAILURE; } int _socket = _networking->sock; if ( status < 0 ) { pthread_mutex_destroy ( &_mutex ); return FAILURE; } /* -- start in recv mode, get 1 message and then analyze it -- */ pthread_t _tid; RUN_IN_THREAD(receivepacket_callback, _tid, _m_session) for ( ; ; ) { /* Recv for x seconds */ _m_msg = rtp_recv_msg ( _m_session ); /* _m_msg = rtp_session_get_message_queded ( _m_session ); DEPRECATED */ if ( _m_msg ) { /*rtp_free_msg(_m_session, _m_msg); _m_msg = NULL;*/ printf("Timestamp: %d\n", _m_msg->_header->_timestamp); } usleep ( 10000 ); } if ( _m_msg->_header ) { rtp_header_print ( _m_msg->_header ); } if ( _m_msg->_ext_header ){ print_ext_header_info(_m_msg->_ext_header); } //print_session_stats ( _m_session ); //printf ( "Payload: ( %d ) \n%s\n", _m_msg->_length, _m_msg->_data ); } else if ( find_arg_simple ( _list, "-s" ) != FAILURE ) {
int main( int argc, char* argv[] ) { int status; tox_IP_Port Ip_port; const char* ip, *psend, *plisten; uint16_t port_send, port_listen; const uint8_t* test_bytes = "0123456789012345678901234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345678901234567890123456789"; rtp_session_t* _m_session; rtp_msg_t *_m_msg_R, *_m_msg_S; arg_t* _list = parse_args ( argc, argv ); ip = find_arg_duble(_list, "-d"); psend = find_arg_duble(_list, "-p"); plisten = find_arg_duble(_list, "-l"); if ( !ip || !plisten || !psend ) return _print_help(argv[0]); port_send = atoi(psend); port_listen = atoi(plisten); IP_Port local, remote; /* * This is the Local ip. We initiate networking on * this value for it's the local one. To make stuff simpler we receive over this value * and send on the other one ( see remote ) */ local.ip.i = htonl(INADDR_ANY); local.port = port_listen; Networking_Core* _networking = new_networking(local.ip, port_listen); if ( !_networking ) return FAILURE; int _socket = _networking->sock; /* * Now this is the remote. It's used by rtp_session_t to determine the receivers ip etc. */ t_setipport ( ip, port_send, &remote ); _m_session = rtp_init_session(-1, -1); rtp_add_receiver( _m_session, &remote ); /* Now let's start our main loop in both recv and send mode */ for ( ;; ) { /* * This part checks for received messages and if gotten one * display 'Received msg!' indicator and free message */ _m_msg_R = rtp_recv_msg ( _m_session ); if ( _m_msg_R ) { puts ( "Received msg!" ); rtp_free_msg(_m_session, _m_msg_R); } /* -------------------- */ /* * This one makes a test msg and sends that message to the 'remote' */ _m_msg_S = rtp_msg_new ( _m_session, test_bytes, 280 ) ; rtp_send_msg ( _m_session, _m_msg_S, _socket ); usleep ( 10000 ); /* -------------------- */ } return SUCCESS; }