Added build system

This commit is contained in:
mannol 2014-01-25 14:41:04 +01:00
parent 81097ffe25
commit 142340aa63
8 changed files with 188 additions and 61 deletions

View File

@ -5,8 +5,7 @@ noinst_bindir = $(top_builddir)/build
EXTRA_DIST= EXTRA_DIST=
include ../toxcore/Makefile.inc include ../toxcore/Makefile.inc
include ../toxrtp/Makefile.inc include ../toxav/Makefile.inc
include ../toxmsi/Makefile.inc
include ../other/Makefile.inc include ../other/Makefile.inc
include ../testing/Makefile.inc include ../testing/Makefile.inc
include ../other/bootstrap_serverdaemon/Makefile.inc include ../other/bootstrap_serverdaemon/Makefile.inc

137
toxav/Makefile.inc Normal file
View File

@ -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

View File

@ -35,7 +35,6 @@
#endif /* HAVE_CONFIG_H */ #endif /* HAVE_CONFIG_H */
#define _BSD_SOURCE #define _BSD_SOURCE
#define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -671,7 +670,6 @@ int print_help ( const char* _name )
"\t[IP] (DHT ip)\n" "\t[IP] (DHT ip)\n"
"\t[PORT] (DHT port)\n" "\t[PORT] (DHT port)\n"
"\t[KEY] (DHT public key)\n" "\t[KEY] (DHT public key)\n"
"P.S. Friends and key are stored in ./tox_phone.conf\n"
,_name ); ,_name );
return 1; return 1;
} }

View File

@ -42,10 +42,7 @@
#include <opus/opus.h> #include <opus/opus.h>
#include "toxmsi.h" #include "toxmsi.h"
#include "toxmsi_message.h" #include "toxrtp.h"
#include "../toxrtp/toxrtp_message.h"
#include "../toxrtp/tests/test_helper.h"
#include "phone.h"
#include "toxmedia.h" #include "toxmedia.h"
SDL_Surface *screen; SDL_Surface *screen;
@ -77,7 +74,7 @@ int display_received_frame(codec_state *cs, AVFrame *r_video_frame)
} }
struct jitter_buffer { struct jitter_buffer {
rtp_msg_t **queue; RTPMessage **queue;
uint16_t capacity; uint16_t capacity;
uint16_t size; uint16_t size;
uint16_t front; uint16_t front;
@ -92,7 +89,7 @@ struct jitter_buffer *create_queue(int capacity)
{ {
struct jitter_buffer *q; struct jitter_buffer *q;
q = (struct jitter_buffer *)calloc(sizeof(struct jitter_buffer),1); 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; int i = 0;
for (i = 0; i < capacity; ++i) { 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) 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 */ /* 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); 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 */ /* 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) { if (q->size == 0 || q->queue_ready == 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; int front = q->front;
if (q->id_set == 0) { if (q->id_set == 0) {
q->current_id = q->queue[front]->_header->_sequence_number; q->current_id = q->queue[front]->header->sequnum;
q->current_ts = q->queue[front]->_header->_timestamp; q->current_ts = q->queue[front]->header->timestamp;
q->id_set = 1; q->id_set = 1;
} else { } else {
int next_id = q->queue[front]->_header->_sequence_number; int next_id = q->queue[front]->header->sequnum;
int next_ts = q->queue[front]->_header->_timestamp; int next_ts = q->queue[front]->header->timestamp;
/* if this packet is indeed the expected packet */ /* 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_id = next_id;
q->current_ts = next_ts; q->current_ts = next_ts;
} else { } else {
if (sequence_number_older(next_id, q->current_id, next_ts, q->current_ts)) { 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); 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 */ *success = 2; /* tell the decoder the packet is lost */
return NULL; return NULL;
} else { } else {
@ -162,8 +163,8 @@ rtp_msg_t *dequeue(struct jitter_buffer *q, int *success)
q->front = 0; q->front = 0;
*success = 1; *success = 1;
q->current_id = q->queue[front]->_header->_sequence_number; q->current_id = q->queue[front]->header->sequnum;
q->current_ts = q->queue[front]->_header->_timestamp; q->current_ts = q->queue[front]->header->timestamp;
return q->queue[front]; return q->queue[front];
} }
@ -184,7 +185,7 @@ int empty_queue(struct jitter_buffer *q)
return 0; 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) { if (q->size == q->capacity) {
printf("buffer full, emptying buffer...\n"); printf("buffer full, emptying buffer...\n");
@ -214,9 +215,9 @@ int queue(struct jitter_buffer *q, rtp_msg_t *pk)
if (b < 0) if (b < 0)
b += q->capacity; b += q->capacity;
if (sequence_number_older(q->queue[b]->_header->_sequence_number, q->queue[a]->_header->_sequence_number, if (sequence_number_older(q->queue[b]->header->sequnum, q->queue[a]->header->sequnum,
q->queue[b]->_header->_timestamp, q->queue[a]->_header->_timestamp)) { q->queue[b]->header->timestamp, q->queue[a]->header->timestamp)) {
rtp_msg_t *temp; RTPMessage *temp;
temp = q->queue[a]; temp = q->queue[a];
q->queue[a] = q->queue[b]; q->queue[a] = q->queue[b];
q->queue[b] = temp; q->queue[b] = temp;
@ -487,7 +488,7 @@ void *encode_video_thread(void *arg)
int p = 0; int p = 0;
int err; int err;
int got_packet; int got_packet;
rtp_msg_t *s_video_msg; RTPMessage *s_video_msg;
int video_frame_finished; int video_frame_finished;
AVFrame *s_video_frame; AVFrame *s_video_frame;
AVFrame *webcam_frame; AVFrame *webcam_frame;
@ -552,18 +553,13 @@ void *encode_video_thread(void *arg)
} }
pthread_mutex_lock(&cs->rtp_msg_mutex_lock); pthread_mutex_lock(&cs->rtp_msg_mutex_lock);
THREADLOCK()
if (!enc_video_packet.data) fprintf(stderr, "video packet data is NULL\n"); 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 ( 0 > rtp_send_msg ( cs->_rtp_video, cs->_messenger, enc_video_packet.data, enc_video_packet.size) ) {
if (!s_video_msg) {
printf("invalid message\n"); printf("invalid message\n");
} }
rtp_send_msg ( cs->_rtp_video, s_video_msg, cs->_networking );
THREADUNLOCK()
pthread_mutex_unlock(&cs->rtp_msg_mutex_lock); pthread_mutex_unlock(&cs->rtp_msg_mutex_lock);
av_free_packet(&enc_video_packet); av_free_packet(&enc_video_packet);
} }
@ -587,7 +583,7 @@ void *encode_video_thread(void *arg)
void *encode_audio_thread(void *arg) void *encode_audio_thread(void *arg)
{ {
codec_state *cs = (codec_state *)arg; codec_state *cs = (codec_state *)arg;
rtp_msg_t *s_audio_msg; RTPMessage *s_audio_msg;
unsigned char encoded_data[4096]; unsigned char encoded_data[4096];
int encoded_size = 0; int encoded_size = 0;
int16_t frame[4096]; int16_t frame[4096];
@ -606,12 +602,11 @@ void *encode_audio_thread(void *arg)
printf("Could not encode audio packet\n"); printf("Could not encode audio packet\n");
} else { } else {
pthread_mutex_lock(&cs->rtp_msg_mutex_lock); pthread_mutex_lock(&cs->rtp_msg_mutex_lock);
THREADLOCK()
rtp_set_payload_type(cs->_rtp_audio, 96); rtp_send_msg ( cs->_rtp_audio, cs->_messenger, encoded_data, encoded_size );
s_audio_msg = rtp_msg_new (cs->_rtp_audio, encoded_data, encoded_size) ;
rtp_send_msg ( cs->_rtp_audio, s_audio_msg, cs->_networking );
pthread_mutex_unlock(&cs->rtp_msg_mutex_lock); pthread_mutex_unlock(&cs->rtp_msg_mutex_lock);
THREADUNLOCK()
} }
} else { } else {
usleep(1000); usleep(1000);
@ -646,7 +641,7 @@ void *decode_video_thread(void *arg)
{ {
codec_state *cs = (codec_state *)arg; codec_state *cs = (codec_state *)arg;
cs->video_stream = 0; cs->video_stream = 0;
rtp_msg_t *r_msg; RTPMessage *r_msg;
int dec_frame_finished; int dec_frame_finished;
AVFrame *r_video_frame; AVFrame *r_video_frame;
r_video_frame = avcodec_alloc_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 ); r_msg = rtp_recv_msg ( cs->_rtp_video );
if (r_msg) { if (r_msg) {
memcpy(dec_video_packet.data, r_msg->_data, r_msg->_length); memcpy(dec_video_packet.data, r_msg->data, r_msg->length);
dec_video_packet.size = 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); avcodec_decode_video2(cs->video_decoder_ctx, r_video_frame, &dec_frame_finished, &dec_video_packet);
if (dec_frame_finished) { if (dec_frame_finished) {
@ -695,7 +690,7 @@ void *decode_video_thread(void *arg)
void *decode_audio_thread(void *arg) void *decode_audio_thread(void *arg)
{ {
codec_state *cs = (codec_state *)arg; codec_state *cs = (codec_state *)arg;
rtp_msg_t *r_msg; RTPMessage *r_msg;
int frame_size = AUDIO_FRAME_SIZE; int frame_size = AUDIO_FRAME_SIZE;
int data_size; int data_size;
@ -747,7 +742,7 @@ void *decode_audio_thread(void *arg)
opus_int16 PCM[frame_size]; opus_int16 PCM[frame_size];
while (!cs->quit && cs->receive_audio) { while (!cs->quit && cs->receive_audio) {
THREADLOCK()
r_msg = rtp_recv_msg ( cs->_rtp_audio ); r_msg = rtp_recv_msg ( cs->_rtp_audio );
if (r_msg) { if (r_msg) {
@ -765,7 +760,7 @@ void *decode_audio_thread(void *arg)
if (success > 0) { if (success > 0) {
/* good packet */ /* good packet */
if (success == 1) { 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); rtp_free_msg(cs->_rtp_audio, r_msg);
} }
@ -807,7 +802,6 @@ void *decode_audio_thread(void *arg)
} }
} }
THREADUNLOCK()
usleep(1000); usleep(1000);
} }

View File

@ -70,7 +70,7 @@
#define DEFAULT_WEBCAM "/dev/video0" #define DEFAULT_WEBCAM "/dev/video0"
#endif #endif
#ifdef defined(_WIN32) || defined(__WIN32__) || defined (WIN32) #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
#define VIDEO_DRIVER "vfwcap" #define VIDEO_DRIVER "vfwcap"
#define DEFAULT_WEBCAM "0" #define DEFAULT_WEBCAM "0"
#endif #endif
@ -126,10 +126,10 @@ typedef struct {
/* rendered video picture, ready for display */ /* rendered video picture, ready for display */
VideoPicture video_picture; VideoPicture video_picture;
rtp_session_t *_rtp_video; RTPSession *_rtp_video;
rtp_session_t *_rtp_audio; RTPSession *_rtp_audio;
int socket;
Networking_Core *_networking; Tox* _messenger;
pthread_t encode_audio_thread; pthread_t encode_audio_thread;
pthread_t encode_video_thread; pthread_t encode_video_thread;
@ -143,11 +143,8 @@ typedef struct {
uint8_t quit; uint8_t quit;
SDL_Event SDL_event; SDL_Event SDL_event;
msi_session_t *_msi; MSISession *_msi;
uint32_t _frame_rate; uint32_t _frame_rate;
uint16_t _send_port, _recv_port;
int _tox_sock;
//pthread_id _medialoop_id;
} codec_state; } codec_state;
@ -161,7 +158,7 @@ int video_encoder_refresh(codec_state *cs, int bps);
void *encode_video_thread(void *arg); void *encode_video_thread(void *arg);
void *encode_audio_thread(void *arg); void *encode_audio_thread(void *arg);
int video_decoder_refresh(codec_state *cs, int width, int height); 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_video_thread(void *arg);
void *decode_audio_thread(void *arg); void *decode_audio_thread(void *arg);

View File

@ -39,8 +39,6 @@
#define PAYLOAD_ID_VALUE_OPUS 1 #define PAYLOAD_ID_VALUE_OPUS 1
#define PAYLOAD_ID_VALUE_VP8 2 #define PAYLOAD_ID_VALUE_VP8 2
#define MAX_SEQU_NUM 65535
#define size_32 4 #define size_32 4
#define inline__ inline __attribute__((always_inline)) #define inline__ inline __attribute__((always_inline))

View File

@ -29,6 +29,8 @@
#include <inttypes.h> #include <inttypes.h>
#include "../toxcore/tox.h" #include "../toxcore/tox.h"
#define MAX_SEQU_NUM 65535
/** /**
* Standard rtp header * Standard rtp header
*/ */

View File

@ -29,8 +29,8 @@ libtoxcore_la_SOURCES = ../toxcore/DHT.h \
../toxcore/group_chats.c \ ../toxcore/group_chats.c \
../toxcore/assoc.h \ ../toxcore/assoc.h \
../toxcore/assoc.c \ ../toxcore/assoc.c \
../toxcore/event.h \ ../toxcore/event.h \
../toxcore/event.c \ ../toxcore/event.c \
../toxcore/onion.h \ ../toxcore/onion.h \
../toxcore/onion.c \ ../toxcore/onion.c \
../toxcore/onion_announce.h \ ../toxcore/onion_announce.h \
@ -42,7 +42,8 @@ libtoxcore_la_SOURCES = ../toxcore/DHT.h \
libtoxcore_la_CFLAGS = -I$(top_srcdir) \ libtoxcore_la_CFLAGS = -I$(top_srcdir) \
-I$(top_srcdir)/toxcore \ -I$(top_srcdir)/toxcore \
$(LIBSODIUM_CFLAGS) \ $(LIBSODIUM_CFLAGS) \
$(NACL_CFLAGS) $(NACL_CFLAGS) \
$(PTHREAD_CFLAGS)
libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \
$(EXTRA_LT_LDFLAGS) \ $(EXTRA_LT_LDFLAGS) \
@ -51,4 +52,5 @@ libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \
$(WINSOCK2_LIBS) $(WINSOCK2_LIBS)
libtoxcore_la_LIBS = $(LIBSODIUM_LIBS) \ libtoxcore_la_LIBS = $(LIBSODIUM_LIBS) \
$(NAC_LIBS) $(NAC_LIBS) \
$(PTHREAD_LIBS)