From 142340aa632335952948119c42bab399abc6c960 Mon Sep 17 00:00:00 2001 From: mannol Date: Sat, 25 Jan 2014 14:41:04 +0100 Subject: Added build system --- build/Makefile.am | 3 +- toxav/Makefile.inc | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ toxav/phone.c | 2 - toxav/toxmedia.c | 76 +++++++++++++--------------- toxav/toxmedia.h | 17 +++---- toxav/toxrtp.c | 2 - toxav/toxrtp.h | 2 + toxcore/Makefile.inc | 10 ++-- 8 files changed, 188 insertions(+), 61 deletions(-) create mode 100644 toxav/Makefile.inc diff --git a/build/Makefile.am b/build/Makefile.am index 9530e1a7..5514a4d5 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -5,8 +5,7 @@ noinst_bindir = $(top_builddir)/build EXTRA_DIST= include ../toxcore/Makefile.inc -include ../toxrtp/Makefile.inc -include ../toxmsi/Makefile.inc +include ../toxav/Makefile.inc include ../other/Makefile.inc include ../testing/Makefile.inc include ../other/bootstrap_serverdaemon/Makefile.inc diff --git a/toxav/Makefile.inc b/toxav/Makefile.inc new file mode 100644 index 00000000..203d8a07 --- /dev/null +++ b/toxav/Makefile.inc @@ -0,0 +1,137 @@ +if BUILD_AV + +lib_LTLIBRARIES += libtoxrtp.la \ + libtoxmsi.la \ + libtoxmedia.la + + +# ****** RTP ****** # + +libtoxrtp_la_include_HEADERS = \ + ../toxav/toxrtp.h + +libtoxrtp_la_includedir = $(includedir)/tox + +libtoxrtp_la_SOURCES = ../toxav/toxrtp.h \ + ../toxav/toxrtp.c + +libtoxrtp_la_CFLAGS = -I../toxcore \ + -I../toxav \ + $(NACL_CFLAGS) + +libtoxrtp_la_LDFLAGS = $(TOXRTP_LT_LDFLAGS) \ + $(NACL_LDFLAGS) \ + $(EXTRA_LT_LDFLAGS) + +libtoxrtp_la_LIBS = libtoxcore.la \ + $(NACL_LIBS) + + + + + +# ****** MSI ****** # + +libtoxmsi_la_include_HEADERS = \ + ../toxav/toxmsi.h + +libtoxmsi_la_includedir = $(includedir)/tox + +libtoxmsi_la_SOURCES = ../toxav/toxmsi.h \ + ../toxav/toxmsi.c + +libtoxmsi_la_CFLAGS = -I../toxcore \ + -I../toxav \ + $(NACL_CFLAGS) + +libtoxmsi_la_LDFLAGS = $(TOXMSI_LT_LDFLAGS) \ + $(EXTRA_LT_LDFLAGS) \ + $(NACL_LDFLAGS) + +libtoxmsi_la_LIBS = libtoxcore.la \ + $(NACL_LIBS) + + + + + +# ****** MEDIA ****** # + +libtoxmedia_la_include_HEADERS = \ + ../toxav/toxmedia.h + +libtoxmedia_la_includedir = $(includedir)/tox + +libtoxmedia_la_SOURCES = ../toxav/toxmedia.h \ + ../toxav/toxmedia.c + +libtoxmedia_la_CFLAGS = -I../toxcore \ + -I../toxav \ + $(AVFORMAT_CFLAGS) \ + $(AVCODEC_CFLAGS) \ + $(AVUTIL_CFLAGS) \ + $(AVDEVICE_CFLAGS) \ + $(SWSCALE_CFLAGS) \ + $(SDL_CFLAGS) \ + $(OPENAL_CFLAGS) \ + $(NACL_CFLAGS) \ + $(OPUS_CFLAGS) + + +libtoxmedia_la_LDFLAGS = $(TOXMSI_LT_LDFLAGS) \ + $(TOXRTP_LT_LDFLAGS) \ + $(EXTRA_LT_LDFLAGS) \ + $(NACL_LDFLAGS) + + +libtoxmedia_la_LIBS = libtoxcore.la \ + $(NACL_LDFLAGS) \ + $(AVFORMAT_LIBS) \ + $(AVCODEC_LIBS) \ + $(AVUTIL_LIBS) \ + $(AVDEVICE_LIBS) \ + $(SWSCALE_LIBS) \ + $(SDL_LIBS) \ + $(OPENAL_LIBS) \ + $(NACL_LIBS) \ + $(OPUS_LIBS) + + + + +# ***** PHONE ***** # + +noinst_PROGRAMS += phone + +phone_SOURCES = ../toxav/phone.c + +phone_CFLAGS = -I../toxcore \ + -I../toxav \ + $(AVFORMAT_CFLAGS) \ + $(AVCODEC_CFLAGS) \ + $(AVUTIL_CFLAGS) \ + $(AVDEVICE_CFLAGS) \ + $(SWSCALE_CFLAGS) \ + $(SDL_CFLAGS) \ + $(OPENAL_CFLAGS) \ + $(NACL_CFLAGS) \ + $(OPUS_CFLAGS) + + +phone_LDADD = libtoxrtp.la \ + libtoxmsi.la \ + libtoxmedia.la \ + libtoxcore.la \ + $(NACL_LDFLAGS) \ + $(AVFORMAT_LIBS) \ + $(AVCODEC_LIBS) \ + $(AVUTIL_LIBS) \ + $(AVDEVICE_LIBS) \ + $(SWSCALE_LIBS) \ + $(SDL_LIBS) \ + $(OPENAL_LIBS) \ + $(NACL_LIBS) \ + $(OPUS_LIBS) + + +endif \ No newline at end of file diff --git a/toxav/phone.c b/toxav/phone.c index b55a072c..6d4b5e6b 100755 --- a/toxav/phone.c +++ b/toxav/phone.c @@ -35,7 +35,6 @@ #endif /* HAVE_CONFIG_H */ #define _BSD_SOURCE -#define _GNU_SOURCE #include #include @@ -671,7 +670,6 @@ int print_help ( const char* _name ) "\t[IP] (DHT ip)\n" "\t[PORT] (DHT port)\n" "\t[KEY] (DHT public key)\n" - "P.S. Friends and key are stored in ./tox_phone.conf\n" ,_name ); return 1; } diff --git a/toxav/toxmedia.c b/toxav/toxmedia.c index 4c9f5261..aff3cf8c 100644 --- a/toxav/toxmedia.c +++ b/toxav/toxmedia.c @@ -42,10 +42,7 @@ #include #include "toxmsi.h" -#include "toxmsi_message.h" -#include "../toxrtp/toxrtp_message.h" -#include "../toxrtp/tests/test_helper.h" -#include "phone.h" +#include "toxrtp.h" #include "toxmedia.h" SDL_Surface *screen; @@ -77,7 +74,7 @@ int display_received_frame(codec_state *cs, AVFrame *r_video_frame) } struct jitter_buffer { - rtp_msg_t **queue; + RTPMessage **queue; uint16_t capacity; uint16_t size; uint16_t front; @@ -92,7 +89,7 @@ struct jitter_buffer *create_queue(int capacity) { struct jitter_buffer *q; q = (struct jitter_buffer *)calloc(sizeof(struct jitter_buffer),1); - q->queue = (rtp_msg_t **)calloc((sizeof(rtp_msg_t) * capacity),1); + q->queue = (RTPMessage **)calloc((sizeof(RTPMessage) * capacity),1); int i = 0; for (i = 0; i < capacity; ++i) { @@ -114,11 +111,15 @@ struct jitter_buffer *create_queue(int capacity) uint8_t sequence_number_older(uint16_t sn_a, uint16_t sn_b, uint32_t ts_a, uint32_t ts_b) { /* should be stable enough */ + + /* TODO: There is already this kind of function in toxrtp.c. + * Maybe merge? + */ return (sn_a > sn_b || ts_a > ts_b); } /* success is 0 when there is nothing to dequeue, 1 when there's a good packet, 2 when there's a lost packet */ -rtp_msg_t *dequeue(struct jitter_buffer *q, int *success) +RTPMessage *dequeue(struct jitter_buffer *q, int *success) { if (q->size == 0 || q->queue_ready == 0) { q->queue_ready = 0; @@ -129,21 +130,21 @@ rtp_msg_t *dequeue(struct jitter_buffer *q, int *success) int front = q->front; if (q->id_set == 0) { - q->current_id = q->queue[front]->_header->_sequence_number; - q->current_ts = q->queue[front]->_header->_timestamp; + q->current_id = q->queue[front]->header->sequnum; + q->current_ts = q->queue[front]->header->timestamp; q->id_set = 1; } else { - int next_id = q->queue[front]->_header->_sequence_number; - int next_ts = q->queue[front]->_header->_timestamp; + int next_id = q->queue[front]->header->sequnum; + int next_ts = q->queue[front]->header->timestamp; /* if this packet is indeed the expected packet */ - if (next_id == (q->current_id + 1) % _MAX_SEQU_NUM) { + if (next_id == (q->current_id + 1) % MAX_SEQU_NUM) { q->current_id = next_id; q->current_ts = next_ts; } else { if (sequence_number_older(next_id, q->current_id, next_ts, q->current_ts)) { printf("nextid: %d current: %d\n", next_id, q->current_id); - q->current_id = (q->current_id + 1) % _MAX_SEQU_NUM; + q->current_id = (q->current_id + 1) % MAX_SEQU_NUM; *success = 2; /* tell the decoder the packet is lost */ return NULL; } else { @@ -162,8 +163,8 @@ rtp_msg_t *dequeue(struct jitter_buffer *q, int *success) q->front = 0; *success = 1; - q->current_id = q->queue[front]->_header->_sequence_number; - q->current_ts = q->queue[front]->_header->_timestamp; + q->current_id = q->queue[front]->header->sequnum; + q->current_ts = q->queue[front]->header->timestamp; return q->queue[front]; } @@ -184,7 +185,7 @@ int empty_queue(struct jitter_buffer *q) return 0; } -int queue(struct jitter_buffer *q, rtp_msg_t *pk) +int queue(struct jitter_buffer *q, RTPMessage *pk) { if (q->size == q->capacity) { printf("buffer full, emptying buffer...\n"); @@ -214,9 +215,9 @@ int queue(struct jitter_buffer *q, rtp_msg_t *pk) if (b < 0) b += q->capacity; - if (sequence_number_older(q->queue[b]->_header->_sequence_number, q->queue[a]->_header->_sequence_number, - q->queue[b]->_header->_timestamp, q->queue[a]->_header->_timestamp)) { - rtp_msg_t *temp; + if (sequence_number_older(q->queue[b]->header->sequnum, q->queue[a]->header->sequnum, + q->queue[b]->header->timestamp, q->queue[a]->header->timestamp)) { + RTPMessage *temp; temp = q->queue[a]; q->queue[a] = q->queue[b]; q->queue[b] = temp; @@ -487,7 +488,7 @@ void *encode_video_thread(void *arg) int p = 0; int err; int got_packet; - rtp_msg_t *s_video_msg; + RTPMessage *s_video_msg; int video_frame_finished; AVFrame *s_video_frame; AVFrame *webcam_frame; @@ -552,18 +553,13 @@ void *encode_video_thread(void *arg) } pthread_mutex_lock(&cs->rtp_msg_mutex_lock); - THREADLOCK() if (!enc_video_packet.data) fprintf(stderr, "video packet data is NULL\n"); - s_video_msg = rtp_msg_new ( cs->_rtp_video, enc_video_packet.data, enc_video_packet.size ) ; - - if (!s_video_msg) { + if ( 0 > rtp_send_msg ( cs->_rtp_video, cs->_messenger, enc_video_packet.data, enc_video_packet.size) ) { printf("invalid message\n"); } - - rtp_send_msg ( cs->_rtp_video, s_video_msg, cs->_networking ); - THREADUNLOCK() + pthread_mutex_unlock(&cs->rtp_msg_mutex_lock); av_free_packet(&enc_video_packet); } @@ -587,7 +583,7 @@ void *encode_video_thread(void *arg) void *encode_audio_thread(void *arg) { codec_state *cs = (codec_state *)arg; - rtp_msg_t *s_audio_msg; + RTPMessage *s_audio_msg; unsigned char encoded_data[4096]; int encoded_size = 0; int16_t frame[4096]; @@ -606,12 +602,11 @@ void *encode_audio_thread(void *arg) printf("Could not encode audio packet\n"); } else { pthread_mutex_lock(&cs->rtp_msg_mutex_lock); - THREADLOCK() - rtp_set_payload_type(cs->_rtp_audio, 96); - s_audio_msg = rtp_msg_new (cs->_rtp_audio, encoded_data, encoded_size) ; - rtp_send_msg ( cs->_rtp_audio, s_audio_msg, cs->_networking ); + + rtp_send_msg ( cs->_rtp_audio, cs->_messenger, encoded_data, encoded_size ); + pthread_mutex_unlock(&cs->rtp_msg_mutex_lock); - THREADUNLOCK() + } } else { usleep(1000); @@ -646,7 +641,7 @@ void *decode_video_thread(void *arg) { codec_state *cs = (codec_state *)arg; cs->video_stream = 0; - rtp_msg_t *r_msg; + RTPMessage *r_msg; int dec_frame_finished; AVFrame *r_video_frame; r_video_frame = avcodec_alloc_frame(); @@ -659,8 +654,8 @@ void *decode_video_thread(void *arg) r_msg = rtp_recv_msg ( cs->_rtp_video ); if (r_msg) { - memcpy(dec_video_packet.data, r_msg->_data, r_msg->_length); - dec_video_packet.size = r_msg->_length; + memcpy(dec_video_packet.data, r_msg->data, r_msg->length); + dec_video_packet.size = r_msg->length; avcodec_decode_video2(cs->video_decoder_ctx, r_video_frame, &dec_frame_finished, &dec_video_packet); if (dec_frame_finished) { @@ -695,7 +690,7 @@ void *decode_video_thread(void *arg) void *decode_audio_thread(void *arg) { codec_state *cs = (codec_state *)arg; - rtp_msg_t *r_msg; + RTPMessage *r_msg; int frame_size = AUDIO_FRAME_SIZE; int data_size; @@ -747,7 +742,7 @@ void *decode_audio_thread(void *arg) opus_int16 PCM[frame_size]; while (!cs->quit && cs->receive_audio) { - THREADLOCK() + r_msg = rtp_recv_msg ( cs->_rtp_audio ); if (r_msg) { @@ -765,7 +760,7 @@ void *decode_audio_thread(void *arg) if (success > 0) { /* good packet */ if (success == 1) { - dec_frame_len = opus_decode(cs->audio_decoder, r_msg->_data, r_msg->_length, PCM, frame_size, 0); + dec_frame_len = opus_decode(cs->audio_decoder, r_msg->data, r_msg->length, PCM, frame_size, 0); rtp_free_msg(cs->_rtp_audio, r_msg); } @@ -806,8 +801,7 @@ void *decode_audio_thread(void *arg) } } - - THREADUNLOCK() + usleep(1000); } diff --git a/toxav/toxmedia.h b/toxav/toxmedia.h index 5037365c..aad299bb 100644 --- a/toxav/toxmedia.h +++ b/toxav/toxmedia.h @@ -70,7 +70,7 @@ #define DEFAULT_WEBCAM "/dev/video0" #endif -#ifdef defined(_WIN32) || defined(__WIN32__) || defined (WIN32) +#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) #define VIDEO_DRIVER "vfwcap" #define DEFAULT_WEBCAM "0" #endif @@ -126,11 +126,11 @@ typedef struct { /* rendered video picture, ready for display */ VideoPicture video_picture; - rtp_session_t *_rtp_video; - rtp_session_t *_rtp_audio; - int socket; - Networking_Core *_networking; + RTPSession *_rtp_video; + RTPSession *_rtp_audio; + Tox* _messenger; + pthread_t encode_audio_thread; pthread_t encode_video_thread; @@ -143,11 +143,8 @@ typedef struct { uint8_t quit; SDL_Event SDL_event; - msi_session_t *_msi; + MSISession *_msi; uint32_t _frame_rate; - uint16_t _send_port, _recv_port; - int _tox_sock; - //pthread_id _medialoop_id; } codec_state; @@ -161,7 +158,7 @@ int video_encoder_refresh(codec_state *cs, int bps); void *encode_video_thread(void *arg); void *encode_audio_thread(void *arg); int video_decoder_refresh(codec_state *cs, int width, int height); -int handle_rtp_video_packet(codec_state *cs, rtp_msg_t *r_msg); +int handle_rtp_video_packet(codec_state *cs, RTPMessage *r_msg); void *decode_video_thread(void *arg); void *decode_audio_thread(void *arg); diff --git a/toxav/toxrtp.c b/toxav/toxrtp.c index 2363deea..03d20363 100755 --- a/toxav/toxrtp.c +++ b/toxav/toxrtp.c @@ -39,8 +39,6 @@ #define PAYLOAD_ID_VALUE_OPUS 1 #define PAYLOAD_ID_VALUE_VP8 2 -#define MAX_SEQU_NUM 65535 - #define size_32 4 #define inline__ inline __attribute__((always_inline)) diff --git a/toxav/toxrtp.h b/toxav/toxrtp.h index b4275aba..bb40f343 100755 --- a/toxav/toxrtp.h +++ b/toxav/toxrtp.h @@ -29,6 +29,8 @@ #include #include "../toxcore/tox.h" +#define MAX_SEQU_NUM 65535 + /** * Standard rtp header */ diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc index 6c4e297f..c9e94911 100644 --- a/toxcore/Makefile.inc +++ b/toxcore/Makefile.inc @@ -29,8 +29,8 @@ libtoxcore_la_SOURCES = ../toxcore/DHT.h \ ../toxcore/group_chats.c \ ../toxcore/assoc.h \ ../toxcore/assoc.c \ - ../toxcore/event.h \ - ../toxcore/event.c \ + ../toxcore/event.h \ + ../toxcore/event.c \ ../toxcore/onion.h \ ../toxcore/onion.c \ ../toxcore/onion_announce.h \ @@ -42,7 +42,8 @@ libtoxcore_la_SOURCES = ../toxcore/DHT.h \ libtoxcore_la_CFLAGS = -I$(top_srcdir) \ -I$(top_srcdir)/toxcore \ $(LIBSODIUM_CFLAGS) \ - $(NACL_CFLAGS) + $(NACL_CFLAGS) \ + $(PTHREAD_CFLAGS) libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ $(EXTRA_LT_LDFLAGS) \ @@ -51,4 +52,5 @@ libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ $(WINSOCK2_LIBS) libtoxcore_la_LIBS = $(LIBSODIUM_LIBS) \ - $(NAC_LIBS) + $(NAC_LIBS) \ + $(PTHREAD_LIBS) -- cgit v1.2.3