summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2013-10-13 16:17:30 +0200
committerBtbN <btbn@btbn.de>2013-10-13 16:40:15 +0200
commit5bc25609041f135ad6b9d757295b665e2f84b955 (patch)
tree59006e5c5e3386df46c0376eb418c1a5e3a85b44
parentda727875ac954b13ecb16521d255499511bb7424 (diff)
tox A/V: integration of A/V code into tox
Also-by: Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
-rw-r--r--.travis.yml25
-rw-r--r--Makefile.am2
-rw-r--r--build/Makefile.am3
-rw-r--r--configure.ac120
-rw-r--r--docs/av_api.md156
-rw-r--r--m4/ax_pthread.m4317
-rw-r--r--testing/misc_tools.c1
-rw-r--r--testing/nToxAudio.h55
-rw-r--r--tools/astylerc20
-rw-r--r--toxcore/Makefile.inc5
-rw-r--r--toxcore/misc_tools.h57
-rw-r--r--toxcore/network.c3
-rw-r--r--toxcore/network.h2
-rw-r--r--toxcore/util.c2
14 files changed, 748 insertions, 20 deletions
diff --git a/.travis.yml b/.travis.yml
index 06f1e4fb..a3710f0c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,6 +19,31 @@ before_script:
19 - ./configure && make -j3 19 - ./configure && make -j3
20 - sudo make install 20 - sudo make install
21 - cd .. 21 - cd ..
22# installing libopus, needed for audio encoding/decoding
23 - wget http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz
24 - tar xzvf opus-1.0.3.tar.gz
25 - cd opus-1.0.3
26 - ./configure && make -j3
27 - sudo make install
28 - cd ..
29# installing libsdl1.2, needed for displaying video frames
30 - wget http://www.libsdl.org/release/SDL-1.2.15.tar.gz
31 - tar -xvzf SDL-1.2.15.tar.gz
32 - cd SDL-1.2.15
33 - ./configure && make -j3
34 - sudo make install
35 - cd ..
36# installing libopenal, needed for audio capture/playback
37 - sudo apt-get install libopenal-dev
38# installing yasm, needed for compiling ffmpeg
39 - sudo apt-get install yasm
40# installing ffmpeg, needed for capturing and encoding/decoding video
41 - wget https://www.ffmpeg.org/releases/ffmpeg-2.0.2.tar.gz
42 - tar -xvzf ffmpeg-2.0.2.tar.gz
43 - cd ffmpeg-2.0.2
44 - ./configure && make -j3
45 - sudo make install
46 - cd ..
22# creating librarys' links and updating cache 47# creating librarys' links and updating cache
23 - sudo ldconfig 48 - sudo ldconfig
24# installing check, needed for unit tests 49# installing check, needed for unit tests
diff --git a/Makefile.am b/Makefile.am
index ac24c6b7..9c44ea96 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,7 +10,7 @@ CLEANFILES = $(top_builddir)/libtoxcore.pc
10 10
11 11
12EXTRA_DIST = \ 12EXTRA_DIST = \
13 $(top_srcdir)/libtoxcore.pc.in \ 13 libtoxcore.pc.in \
14 $(top_srcdir)/docs/updates/Crypto.md \ 14 $(top_srcdir)/docs/updates/Crypto.md \
15 $(top_srcdir)/docs/updates/Spam-Prevention.md \ 15 $(top_srcdir)/docs/updates/Spam-Prevention.md \
16 $(top_srcdir)/docs/updates/Symmetric-NAT-Transversal.md \ 16 $(top_srcdir)/docs/updates/Symmetric-NAT-Transversal.md \
diff --git a/build/Makefile.am b/build/Makefile.am
index 631ec111..9530e1a7 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -1,9 +1,12 @@
1bin_PROGRAMS = 1bin_PROGRAMS =
2noinst_PROGRAMS = 2noinst_PROGRAMS =
3lib_LTLIBRARIES =
3noinst_bindir = $(top_builddir)/build 4noinst_bindir = $(top_builddir)/build
4EXTRA_DIST= 5EXTRA_DIST=
5 6
6include ../toxcore/Makefile.inc 7include ../toxcore/Makefile.inc
8include ../toxrtp/Makefile.inc
9include ../toxmsi/Makefile.inc
7include ../other/Makefile.inc 10include ../other/Makefile.inc
8include ../testing/Makefile.inc 11include ../testing/Makefile.inc
9include ../other/bootstrap_serverdaemon/Makefile.inc 12include ../other/bootstrap_serverdaemon/Makefile.inc
diff --git a/configure.ac b/configure.ac
index 81f15eca..dba051c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -10,7 +10,11 @@ AM_INIT_AUTOMAKE([1.10 -Wall subdir-objects])
10m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 10m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
11AC_CONFIG_MACRO_DIR([m4]) 11AC_CONFIG_MACRO_DIR([m4])
12 12
13EXTRA_LT_LDFLAGS=
14
13LIBTOXCORE_LT_VERSION=0:0:0 15LIBTOXCORE_LT_VERSION=0:0:0
16LIBTOXMSI_LT_VERSION=0:0:0
17LIBTOXRTP_LT_VERSION=0:0:0
14dnl 18dnl
15dnl current:revision:age 19dnl current:revision:age
16dnl 20dnl
@@ -19,7 +23,13 @@ dnl revision: increment if source code has changed, set to zero if current is
19dnl incremented 23dnl incremented
20dnl age: increment if interfaces have been added, set to zero if 24dnl age: increment if interfaces have been added, set to zero if
21dnl interfaces have been removed or changed 25dnl interfaces have been removed or changed
22EXTRA_LT_LDFLAGS="-version-info $LIBTOXCORE_LT_VERSION" 26TOXCORE_LT_LDFLAGS="-version-info $LIBTOXCORE_LT_VERSION"
27TOXMSI_LT_LDFLAGS="-version-info $LIBTOXMSI_LT_VERSION"
28TOXRTP_LT_LDFLAGS="-version-info $LIBTOXMSI_LT_VERSION"
29
30AC_SUBST(TOXCORE_LT_LDFLAGS)
31AC_SUBST(TOXMSI_LT_LDFLAGS)
32AC_SUBST(TOXRTP_LT_LDFLAGS)
23 33
24if test "x${prefix}" = "xNONE"; then 34if test "x${prefix}" = "xNONE"; then
25 prefix="${ac_default_prefix}" 35 prefix="${ac_default_prefix}"
@@ -28,6 +38,7 @@ fi
28BUILD_DHT_BOOTSTRAP_DAEMON="yes" 38BUILD_DHT_BOOTSTRAP_DAEMON="yes"
29BUILD_NTOX="yes" 39BUILD_NTOX="yes"
30BUILD_TESTS="yes" 40BUILD_TESTS="yes"
41BUILD_AV="yes"
31BUILD_TESTING="yes" 42BUILD_TESTING="yes"
32 43
33NCURSES_FOUND="no" 44NCURSES_FOUND="no"
@@ -46,6 +57,19 @@ AC_ARG_ENABLE([nacl],
46 ] 57 ]
47) 58)
48 59
60PKG_PROG_PKG_CONFIG
61
62AC_ARG_ENABLE([av],
63 [AC_HELP_STRING([--disable-av], [build AV support libraries (default: auto)]) ],
64 [
65 if test "x$enableval" = "xno"; then
66 BUILD_AV="no"
67 elif test "x$enableval" = "xyes"; then
68 BUILD_AV="yes"
69 fi
70 ]
71)
72
49AC_ARG_ENABLE([tests], 73AC_ARG_ENABLE([tests],
50 [AC_HELP_STRING([--disable-tests], [build unit tests (default: auto)]) ], 74 [AC_HELP_STRING([--disable-tests], [build unit tests (default: auto)]) ],
51 [ 75 [
@@ -314,8 +338,95 @@ AC_TYPE_UINT8_T
314AC_FUNC_FORK 338AC_FUNC_FORK
315AC_CHECK_FUNCS([gettimeofday memset socket strchr malloc]) 339AC_CHECK_FUNCS([gettimeofday memset socket strchr malloc])
316 340
317# pkg-config based tests 341if test "x$BUILD_AV" = "xyes"; then
318PKG_PROG_PKG_CONFIG 342 AX_PTHREAD(
343 [],
344 [
345 AC_MSG_WARN([disabling AV support: required pthread library not found])
346 BUILD_AV="no"
347 ]
348 )
349fi
350
351if test "x$BUILD_AV" = "xyes"; then
352 PKG_CHECK_MODULES([AVFORMAT], [libavformat],
353 [],
354 [
355 AC_MSG_WARN([disabling AV support $AVFORMAT_PKG_ERRORS])
356 BUILD_AV="no"
357 ]
358 )
359fi
360
361if test "x$BUILD_AV" = "xyes"; then
362 PKG_CHECK_MODULES([AVCODEC], [libavcodec],
363 [],
364 [
365 AC_MSG_WARN([disabling AV support $AVCODEC_PKG_ERRORS])
366 BUILD_AV="no"
367 ]
368 )
369fi
370
371if test "x$BUILD_AV" = "xyes"; then
372 PKG_CHECK_MODULES([AVUTIL], [libavutil],
373 [],
374 [
375 AC_MSG_WARN([disabling AV support $AVUTIL_PKG_ERRORS])
376 BUILD_AV="no"
377 ]
378 )
379fi
380
381if test "x$BUILD_AV" = "xyes"; then
382 PKG_CHECK_MODULES([AVDEVICE], [libavdevice],
383 [],
384 [
385 AC_MSG_WARN([disabling AV support $AVDEVICE_PKG_ERRORS])
386 BUILD_AV="no"
387 ]
388 )
389fi
390
391if test "x$BUILD_AV" = "xyes"; then
392 PKG_CHECK_MODULES([SWSCALE], [libswscale],
393 [],
394 [
395 AC_MSG_WARN([disabling AV support $SWSCALE_PKG_ERRORS])
396 BUILD_AV="no"
397 ]
398 )
399fi
400
401if test "x$BUILD_AV" = "xyes"; then
402 PKG_CHECK_MODULES([SDL], [sdl],
403 [],
404 [
405 AC_MSG_WARN([disabling AV support $SDL_PKG_ERRORS])
406 BUILD_AV="no"
407 ]
408 )
409fi
410
411if test "x$BUILD_AV" = "xyes"; then
412 PKG_CHECK_MODULES([OPENAL], [openal],
413 [],
414 [
415 AC_MSG_WARN([disabling AV support $OPENAL_PKG_ERRORS])
416 BUILD_AV="no"
417 ]
418 )
419fi
420
421if test "x$BUILD_AV" = "xyes"; then
422 PKG_CHECK_MODULES([OPUS], [opus],
423 [],
424 [
425 AC_MSG_WARN([disabling AV support $OPUS_PKG_ERRORS])
426 BUILD_AV="no"
427 ]
428 )
429fi
319 430
320if test -n "$PKG_CONFIG"; then 431if test -n "$PKG_CONFIG"; then
321 if test "x$BUILD_TESTS" = "xyes"; then 432 if test "x$BUILD_TESTS" = "xyes"; then
@@ -351,7 +462,7 @@ if test -n "$PKG_CONFIG"; then
351 ]) 462 ])
352 fi 463 fi
353else 464else
354 AC_MSG_WARN([pkg-config was not found on your system]) 465 AC_MSG_WARN([pkg-config was not found on your system, will search for libraries manually])
355fi 466fi
356 467
357if (test "x$BUILD_NTOX" = "xyes") && (test "x$NCURSES_FOUND" != "xyes"); then 468if (test "x$BUILD_NTOX" = "xyes") && (test "x$NCURSES_FOUND" != "xyes"); then
@@ -474,6 +585,7 @@ fi
474AM_CONDITIONAL(BUILD_DHT_BOOTSTRAP_DAEMON, test "x$BUILD_DHT_BOOTSTRAP_DAEMON" = "xyes") 585AM_CONDITIONAL(BUILD_DHT_BOOTSTRAP_DAEMON, test "x$BUILD_DHT_BOOTSTRAP_DAEMON" = "xyes")
475AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes") 586AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes")
476AM_CONDITIONAL(BUILD_NTOX, test "x$BUILD_NTOX" = "xyes") 587AM_CONDITIONAL(BUILD_NTOX, test "x$BUILD_NTOX" = "xyes")
588AM_CONDITIONAL(BUILD_AV, test "x$BUILD_AV" = "xyes")
477AM_CONDITIONAL(BUILD_TESTING, test "x$BUILD_TESTING" = "xyes") 589AM_CONDITIONAL(BUILD_TESTING, test "x$BUILD_TESTING" = "xyes")
478 590
479AC_CONFIG_FILES([Makefile 591AC_CONFIG_FILES([Makefile
diff --git a/docs/av_api.md b/docs/av_api.md
new file mode 100644
index 00000000..08e05a6d
--- /dev/null
+++ b/docs/av_api.md
@@ -0,0 +1,156 @@
1A/V API reference
2
3Take toxmsi/phone.c as a reference
4
5Initialization:
6
7phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port);
8function initializes sample phone. _listen_port and _send_port are variables only meant
9for local testing. You will not have to do anything regarding to that since
10everything will be started within a mesenger.
11
12
13Phone requires one msi session and two rtp sessions ( one for audio and one for
14video ).
15
16msi_session_t* msi_init_session( void* _core_handler, const uint8_t* _user_agent );
17
18initializes msi session.
19Params:
20void* _core_handler - pointer to an object handling networking,
21const uint8_t* _user_agent - string describing phone client version.
22
23Return value:
24msi_session_t* - pointer to a newly created msi session handler.
25
26msi_session_t reference:
27
28How to handle msi session:
29Controling is done via callbacks and action handlers.
30First register callbacks for every state/action received and make sure
31NOT TO PLACE SOMETHING LIKE LOOPS THAT TAKES A LOT OF TIME TO EXECUTE; every callback is being called
32directly from event loop. You can find examples in phone.c.
33
34Register callbacks:
35void msi_register_callback_call_started ( MCALLBACK );
36void msi_register_callback_call_canceled ( MCALLBACK );
37void msi_register_callback_call_rejected ( MCALLBACK );
38void msi_register_callback_call_ended ( MCALLBACK );
39
40void msi_register_callback_recv_invite ( MCALLBACK );
41void msi_register_callback_recv_ringing ( MCALLBACK );
42void msi_register_callback_recv_starting ( MCALLBACK );
43void msi_register_callback_recv_ending ( MCALLBACK );
44void msi_register_callback_recv_error ( MCALLBACK );
45
46void msi_register_callback_requ_timeout ( MCALLBACK );
47
48MCALLBACK is defined as: void (*callback) (void* _arg)
49msi_session_t* handler is being thrown as _arg so you can use that and _agent_handler to get to your own phone handler
50directly from callback.
51
52
53Actions:
54int msi_invite ( msi_session_t* _session, call_type _call_type, uint32_t _timeoutms );
55Sends call invite. Before calling/sending invite msi_session_t::_friend_id is needed to be set or else
56it will not work. _call_type is type of the call ( Audio/Video ) and _timeoutms is how long
57will poll wait until request is terminated.
58
59int msi_hangup ( msi_session_t* _session );
60Hangs up active call
61
62int msi_answer ( msi_session_t* _session, call_type _call_type );
63Answer incomming call. _call_type set's callee call type.
64
65int msi_cancel ( msi_session_t* _session );
66Cancel current request.
67
68int msi_reject ( msi_session_t* _session );
69Reject incomming call.
70
71
72
73
74Now for rtp:
75You will need 2 sessions; one for audio one for video.
76You start them with:
77
78rtp_session_t* rtp_init_session ( int _max_users, int _multi_session );
79
80Params:
81int _max_users - max users. -1 if undefined
82int _multi_session - any positive number means uses multi session; -1 if not.
83
84Return value:
85rtp_session_t* - pointer to a newly created rtp session handler.
86
87How to handle rtp session:
88Take a look at
89void* phone_handle_media_transport_poll ( void* _hmtc_args_p ) in phone.c
90on example. Basically what you do is just receive a message via:
91
92struct rtp_msg_s* rtp_recv_msg ( rtp_session_t* _session );
93
94and then you use payload within the rtp_msg_s struct. Don't forget to deallocate it with:
95void rtp_free_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg );
96Receiving should be thread safe so don't worry about that.
97
98When you capture and encode a payload you want to send it ( obviously ).
99
100first create a new message with:
101struct rtp_msg_s* rtp_msg_new ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length );
102
103and then send it with:
104int rtp_send_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg, void* _core_handler );
105
106_core_handler is the same network handler as in msi_session_s struct.
107
108
109
110A/V initialization:
111
112int init_receive_audio(codec_state *cs);
113int init_receive_video(codec_state *cs);
114Initialises the A/V decoders. On failure it will print the reason and return 0. On success it will return 1.
115
116int init_send_audio(codec_state *cs);
117int init_send_video(codec_state *cs);
118Initialises the A/V encoders. On failure it will print the reason and return 0. On success it will return 1.
119init_send_audio will also let the user select an input device. init_send_video will determine the webcam's output codec and initialise the appropriate decoder.
120
121int video_encoder_refresh(codec_state *cs, int bps);
122Reinitialises the video encoder with a new bitrate. ffmpeg does not expose the needed VP8 feature to change the bitrate on the fly, so this serves as a workaround.
123In the future, VP8 should be used directly and ffmpeg should be dropped from the dependencies.
124The variable bps is the required bitrate in bits per second.
125
126
127
128A/V encoding/decoding:
129
130void *encode_video_thread(void *arg);
131Spawns the video encoding thread. The argument should hold a pointer to a codec_state.
132This function should only be called if video encoding is supported (when init_send_video returns 1).
133Each video frame gets encoded into a packet, which is sent via RTP. Every 60 frames a new bidirectional interframe is encoded.
134
135void *encode_audio_thread(void *arg);
136Spawns the audio encoding thread. The argument should hold a pointer to a codec_state.
137This function should only be called if audio encoding is supported (when init_send_audio returns 1).
138Audio frames are read from the selected audio capture device during intitialisation. This audio capturing can be rerouted to a different device on the fly.
139Each audio frame is encoded into a packet, and sent via RTP. All audio frames have the same amount of samples, which is defined in AV_codec.h.
140
141int video_decoder_refresh(codec_state *cs, int width, int height);
142Sets the SDL window dimensions and creates a pixel buffer with the requested size. It also creates a scaling context, which will be used to convert the input image format to YUV420P.
143
144void *decode_video_thread(void *arg);
145Spawns a video decoding thread. The argument should hold a pointer to a codec_state. The codec_state is assumed to contain a successfully initialised video decoder.
146This function reads video packets and feeds them to the video decoder. If the video frame's resolution has changed, video_decoder_refresh() is called. Afterwards, the frame is displayed on the SDL window.
147
148void *decode_audio_thread(void *arg);
149Spawns an audio decoding thread. The argument should hold a pointer to a codec_state. The codec_state is assumed to contain a successfully initialised audio decoder.
150All received audio packets are pushed into a jitter buffer and are reordered. If there is a missing packet, or a packet has arrived too late, it is treated as a lost packet and the audio decoder is informed of the packet loss. The audio decoder will then try to reconstruct the lost packet, based on information from previous packets.
151Audio is played on the default OpenAL output device.
152
153
154If you have any more qustions/bug reports/feature request contact the following users on the irc channel #tox-dev on irc.freenode.net:
155For RTP and MSI: mannol
156For audio and video: Martijnvdc \ No newline at end of file
diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4
new file mode 100644
index 00000000..6d400ed4
--- /dev/null
+++ b/m4/ax_pthread.m4
@@ -0,0 +1,317 @@
1# ===========================================================================
2# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
8#
9# DESCRIPTION
10#
11# This macro figures out how to build C programs using POSIX threads. It
12# sets the PTHREAD_LIBS output variable to the threads library and linker
13# flags, and the PTHREAD_CFLAGS output variable to any special C compiler
14# flags that are needed. (The user can also force certain compiler
15# flags/libs to be tested by setting these environment variables.)
16#
17# Also sets PTHREAD_CC to any special C compiler that is needed for
18# multi-threaded programs (defaults to the value of CC otherwise). (This
19# is necessary on AIX to use the special cc_r compiler alias.)
20#
21# NOTE: You are assumed to not only compile your program with these flags,
22# but also link it with them as well. e.g. you should link with
23# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
24#
25# If you are only building threads programs, you may wish to use these
26# variables in your default LIBS, CFLAGS, and CC:
27#
28# LIBS="$PTHREAD_LIBS $LIBS"
29# CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
30# CC="$PTHREAD_CC"
31#
32# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
33# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
34# (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
35#
36# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
37# PTHREAD_PRIO_INHERIT symbol is defined when compiling with
38# PTHREAD_CFLAGS.
39#
40# ACTION-IF-FOUND is a list of shell commands to run if a threads library
41# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
42# is not found. If ACTION-IF-FOUND is not specified, the default action
43# will define HAVE_PTHREAD.
44#
45# Please let the authors know if this macro fails on any platform, or if
46# you have any other suggestions or comments. This macro was based on work
47# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
48# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
49# Alejandro Forero Cuervo to the autoconf macro repository. We are also
50# grateful for the helpful feedback of numerous users.
51#
52# Updated for Autoconf 2.68 by Daniel Richard G.
53#
54# LICENSE
55#
56# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
57# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
58#
59# This program is free software: you can redistribute it and/or modify it
60# under the terms of the GNU General Public License as published by the
61# Free Software Foundation, either version 3 of the License, or (at your
62# option) any later version.
63#
64# This program is distributed in the hope that it will be useful, but
65# WITHOUT ANY WARRANTY; without even the implied warranty of
66# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
67# Public License for more details.
68#
69# You should have received a copy of the GNU General Public License along
70# with this program. If not, see <http://www.gnu.org/licenses/>.
71#
72# As a special exception, the respective Autoconf Macro's copyright owner
73# gives unlimited permission to copy, distribute and modify the configure
74# scripts that are the output of Autoconf when processing the Macro. You
75# need not follow the terms of the GNU General Public License when using
76# or distributing such scripts, even though portions of the text of the
77# Macro appear in them. The GNU General Public License (GPL) does govern
78# all other use of the material that constitutes the Autoconf Macro.
79#
80# This special exception to the GPL applies to versions of the Autoconf
81# Macro released by the Autoconf Archive. When you make and distribute a
82# modified version of the Autoconf Macro, you may extend this special
83# exception to the GPL to apply to your modified version as well.
84
85#serial 20
86
87AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
88AC_DEFUN([AX_PTHREAD], [
89AC_REQUIRE([AC_CANONICAL_HOST])
90AC_LANG_PUSH([C])
91ax_pthread_ok=no
92
93# We used to check for pthread.h first, but this fails if pthread.h
94# requires special compiler flags (e.g. on True64 or Sequent).
95# It gets checked for in the link test anyway.
96
97# First of all, check if the user has set any of the PTHREAD_LIBS,
98# etcetera environment variables, and if threads linking works using
99# them:
100if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
101 save_CFLAGS="$CFLAGS"
102 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
103 save_LIBS="$LIBS"
104 LIBS="$PTHREAD_LIBS $LIBS"
105 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
106 AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes)
107 AC_MSG_RESULT($ax_pthread_ok)
108 if test x"$ax_pthread_ok" = xno; then
109 PTHREAD_LIBS=""
110 PTHREAD_CFLAGS=""
111 fi
112 LIBS="$save_LIBS"
113 CFLAGS="$save_CFLAGS"
114fi
115
116# We must check for the threads library under a number of different
117# names; the ordering is very important because some systems
118# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
119# libraries is broken (non-POSIX).
120
121# Create a list of thread flags to try. Items starting with a "-" are
122# C compiler flags, and other items are library names, except for "none"
123# which indicates that we try without any flags at all, and "pthread-config"
124# which is a program returning the flags for the Pth emulation library.
125
126ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
127
128# The ordering *is* (sometimes) important. Some notes on the
129# individual items follow:
130
131# pthreads: AIX (must check this before -lpthread)
132# none: in case threads are in libc; should be tried before -Kthread and
133# other compiler flags to prevent continual compiler warnings
134# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
135# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
136# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
137# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
138# -pthreads: Solaris/gcc
139# -mthreads: Mingw32/gcc, Lynx/gcc
140# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
141# doesn't hurt to check since this sometimes defines pthreads too;
142# also defines -D_REENTRANT)
143# ... -mt is also the pthreads flag for HP/aCC
144# pthread: Linux, etcetera
145# --thread-safe: KAI C++
146# pthread-config: use pthread-config program (for GNU Pth library)
147
148case ${host_os} in
149 solaris*)
150
151 # On Solaris (at least, for some versions), libc contains stubbed
152 # (non-functional) versions of the pthreads routines, so link-based
153 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
154 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
155 # a function called by this macro, so we could check for that, but
156 # who knows whether they'll stub that too in a future libc.) So,
157 # we'll just look for -pthreads and -lpthread first:
158
159 ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
160 ;;
161
162 darwin*)
163 ax_pthread_flags="-pthread $ax_pthread_flags"
164 ;;
165esac
166
167if test x"$ax_pthread_ok" = xno; then
168for flag in $ax_pthread_flags; do
169
170 case $flag in
171 none)
172 AC_MSG_CHECKING([whether pthreads work without any flags])
173 ;;
174
175 -*)
176 AC_MSG_CHECKING([whether pthreads work with $flag])
177 PTHREAD_CFLAGS="$flag"
178 ;;
179
180 pthread-config)
181 AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no)
182 if test x"$ax_pthread_config" = xno; then continue; fi
183 PTHREAD_CFLAGS="`pthread-config --cflags`"
184 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
185 ;;
186
187 *)
188 AC_MSG_CHECKING([for the pthreads library -l$flag])
189 PTHREAD_LIBS="-l$flag"
190 ;;
191 esac
192
193 save_LIBS="$LIBS"
194 save_CFLAGS="$CFLAGS"
195 LIBS="$PTHREAD_LIBS $LIBS"
196 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
197
198 # Check for various functions. We must include pthread.h,
199 # since some functions may be macros. (On the Sequent, we
200 # need a special flag -Kthread to make this header compile.)
201 # We check for pthread_join because it is in -lpthread on IRIX
202 # while pthread_create is in libc. We check for pthread_attr_init
203 # due to DEC craziness with -lpthreads. We check for
204 # pthread_cleanup_push because it is one of the few pthread
205 # functions on Solaris that doesn't have a non-functional libc stub.
206 # We try pthread_create on general principles.
207 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
208 static void routine(void *a) { a = 0; }
209 static void *start_routine(void *a) { return a; }],
210 [pthread_t th; pthread_attr_t attr;
211 pthread_create(&th, 0, start_routine, 0);
212 pthread_join(th, 0);
213 pthread_attr_init(&attr);
214 pthread_cleanup_push(routine, 0);
215 pthread_cleanup_pop(0) /* ; */])],
216 [ax_pthread_ok=yes],
217 [])
218
219 LIBS="$save_LIBS"
220 CFLAGS="$save_CFLAGS"
221
222 AC_MSG_RESULT($ax_pthread_ok)
223 if test "x$ax_pthread_ok" = xyes; then
224 break;
225 fi
226
227 PTHREAD_LIBS=""
228 PTHREAD_CFLAGS=""
229done
230fi
231
232# Various other checks:
233if test "x$ax_pthread_ok" = xyes; then
234 save_LIBS="$LIBS"
235 LIBS="$PTHREAD_LIBS $LIBS"
236 save_CFLAGS="$CFLAGS"
237 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
238
239 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
240 AC_MSG_CHECKING([for joinable pthread attribute])
241 attr_name=unknown
242 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
243 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
244 [int attr = $attr; return attr /* ; */])],
245 [attr_name=$attr; break],
246 [])
247 done
248 AC_MSG_RESULT($attr_name)
249 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
250 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
251 [Define to necessary symbol if this constant
252 uses a non-standard name on your system.])
253 fi
254
255 AC_MSG_CHECKING([if more special flags are required for pthreads])
256 flag=no
257 case ${host_os} in
258 aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";;
259 osf* | hpux*) flag="-D_REENTRANT";;
260 solaris*)
261 if test "$GCC" = "yes"; then
262 flag="-D_REENTRANT"
263 else
264 flag="-mt -D_REENTRANT"
265 fi
266 ;;
267 esac
268 AC_MSG_RESULT(${flag})
269 if test "x$flag" != xno; then
270 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
271 fi
272
273 AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
274 ax_cv_PTHREAD_PRIO_INHERIT, [
275 AC_LINK_IFELSE([
276 AC_LANG_PROGRAM([[#include <pthread.h>]], [[int i = PTHREAD_PRIO_INHERIT;]])],
277 [ax_cv_PTHREAD_PRIO_INHERIT=yes],
278 [ax_cv_PTHREAD_PRIO_INHERIT=no])
279 ])
280 AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"],
281 AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], 1, [Have PTHREAD_PRIO_INHERIT.]))
282
283 LIBS="$save_LIBS"
284 CFLAGS="$save_CFLAGS"
285
286 # More AIX lossage: compile with *_r variant
287 if test "x$GCC" != xyes; then
288 case $host_os in
289 aix*)
290 AS_CASE(["x/$CC"],
291 [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
292 [#handle absolute path differently from PATH based program lookup
293 AS_CASE(["x$CC"],
294 [x/*],
295 [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
296 [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
297 ;;
298 esac
299 fi
300fi
301
302test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
303
304AC_SUBST(PTHREAD_LIBS)
305AC_SUBST(PTHREAD_CFLAGS)
306AC_SUBST(PTHREAD_CC)
307
308# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
309if test x"$ax_pthread_ok" = xyes; then
310 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
311 :
312else
313 ax_pthread_ok=no
314 $2
315fi
316AC_LANG_POP
317])dnl AX_PTHREAD
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index d05c88f6..efe1a555 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -46,7 +46,6 @@ unsigned char *hex_string_to_bin(char hex_string[])
46 return val; 46 return val;
47} 47}
48 48
49
50int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) 49int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
51{ 50{
52 int argvoffset = 0, argi; 51 int argvoffset = 0, argi;
diff --git a/testing/nToxAudio.h b/testing/nToxAudio.h
new file mode 100644
index 00000000..19b31f8b
--- /dev/null
+++ b/testing/nToxAudio.h
@@ -0,0 +1,55 @@
1/* nTox.h
2 *
3 *Textual frontend for Tox.
4 *
5 * Copyright (C) 2013 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#ifndef NTOX_H
25#define NTOX_H
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <ncurses.h>
31#include <curses.h>
32#include <ctype.h>
33#include <sys/socket.h>
34#include <netinet/in.h>
35#include <arpa/inet.h>
36#include <sys/types.h>
37#include <netdb.h>
38#include "../core/Messenger.h"
39#include "../core/network.h"
40
41#define STRING_LENGTH 256
42#define HISTORY 50
43#define PUB_KEY_BYTES 32
44
45void new_lines(char *line);
46void line_eval(char *line);
47void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ;
48int count_lines(char *string) ;
49char *appender(char *str, const char c);
50void do_refresh();
51
52
53
54
55#endif
diff --git a/tools/astylerc b/tools/astylerc
index a2f05160..dd738b74 100644
--- a/tools/astylerc
+++ b/tools/astylerc
@@ -1,11 +1,11 @@
1--style=kr 1--style=kr
2--pad-header 2 --pad-header
3--max-code-length=120 3 --max-code-length=120
4--convert-tabs 4 --convert-tabs
5--indent-switches 5 --indent-switches
6--pad-oper 6 --pad-oper
7--align-pointer=name 7 --align-pointer=name
8--align-reference=name 8 --align-reference=name
9--preserve-date 9 --preserve-date
10--lineend=linux 10 --lineend=linux
11--break-blocks \ No newline at end of file 11 --break-blocks \ No newline at end of file
diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc
index 025f23c8..116a3e29 100644
--- a/toxcore/Makefile.inc
+++ b/toxcore/Makefile.inc
@@ -1,4 +1,4 @@
1lib_LTLIBRARIES = libtoxcore.la 1lib_LTLIBRARIES += libtoxcore.la
2 2
3libtoxcore_la_include_HEADERS = \ 3libtoxcore_la_include_HEADERS = \
4 ../toxcore/tox.h 4 ../toxcore/tox.h
@@ -34,7 +34,8 @@ libtoxcore_la_CFLAGS = -I$(top_srcdir) \
34 $(LIBSODIUM_CFLAGS) \ 34 $(LIBSODIUM_CFLAGS) \
35 $(NACL_CFLAGS) 35 $(NACL_CFLAGS)
36 36
37libtoxcore_la_LDFLAGS = $(EXTRA_LT_LDFLAGS) \ 37libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \
38 $(EXTRA_LT_LDFLAGS) \
38 $(LIBSODIUM_LDFLAGS) \ 39 $(LIBSODIUM_LDFLAGS) \
39 $(NACL_LDFLAGS) \ 40 $(NACL_LDFLAGS) \
40 $(WINSOCK2_LIBS) 41 $(WINSOCK2_LIBS)
diff --git a/toxcore/misc_tools.h b/toxcore/misc_tools.h
index 448c1cbd..5fd0cb7a 100644
--- a/toxcore/misc_tools.h
+++ b/toxcore/misc_tools.h
@@ -69,6 +69,63 @@
69 * TODO: Update wiki. 69 * TODO: Update wiki.
70 **********************************************************/ 70 **********************************************************/
71 71
72/* Example usage
73
74This sample program makes a new struct which contains a
75character and a tox_list_t. It then prompts a user for
76input until he enters q or e. It then adds each character
77to the list, and uses a special for loop to print them.
78It then removes all the 'z' characters, and prints the list
79again.
80
81//Notice that the data to be put in the list *contains* tox_list_t;
82//usually, this is the other way around!
83typedef struct tox_string {
84 char c;
85 tox_list_t tox_lst; //Notice that tox_lst is *NOT* a pointer.
86} tox_string_t;
87
88int main()
89{
90 tox_list_t head;
91 tox_list_new(&head); //initialize head
92
93 //input a new character, until user enters q or e
94 char c = '\0';
95 while (c != 'q' && c != 'e') {
96 scanf("%c", &c);
97 tox_string_t* tmp = malloc(sizeof(tox_string_t));
98 tmp->c = c;
99 tox_list_add(&head, &tmp->tox_lst); //add it to the list
100 }
101
102TOX_LIST_FOR_EACH() takes a struct tox_list and a name for a temporary pointer to use in the loop.
103
104TOX_LIST_GET_VALUE() uses magic to return an instance of a structure that contains tox_list_t.
105You have to give it a temporary tox_string_t, name of tox_list_t member inside our structure (tox_lst),
106and the type of structure to return.
107
108 TOX_LIST_FOR_EACH(head, tmp)
109 printf("%c", TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c);
110
111 TOX_LIST_FOR_EACH(head, tmp) {
112 if (TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c == 'z') {
113 //If you delete tmp, you have to quit the loop, or it will go on infinitly.
114 //This will be fixed later on.
115 tox_list_remove(tmp);
116 break;
117 }
118 }
119
120 printf("\n");
121 TOX_LIST_FOR_EACH(head, tmp)
122 printf("%c", TOX_LIST_GET_VALUE(*tmp, tox_lst, tox_string_t).c);
123
124
125 return 0;
126}
127*/
128
72#define MEMBER_OFFSET(var_name_in_parent, parent_type) \ 129#define MEMBER_OFFSET(var_name_in_parent, parent_type) \
73 (&(((parent_type*)0)->var_name_in_parent)) 130 (&(((parent_type*)0)->var_name_in_parent))
74 131
diff --git a/toxcore/network.c b/toxcore/network.c
index 38adc179..5d695b81 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -227,7 +227,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, uint8_t *data, uint32_t le
227 * Packet length is put into length. 227 * Packet length is put into length.
228 * Dump all empty packets. 228 * Dump all empty packets.
229 */ 229 */
230static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t *length) 230int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t *length)
231{ 231{
232 struct sockaddr_storage addr; 232 struct sockaddr_storage addr;
233#ifdef WIN32 233#ifdef WIN32
@@ -667,6 +667,7 @@ void kill_networking(Networking_Core *net)
667 return; 667 return;
668} 668}
669 669
670
670/* ip_equal 671/* ip_equal
671 * compares two IPAny structures 672 * compares two IPAny structures
672 * unset means unequal 673 * unset means unequal
diff --git a/toxcore/network.h b/toxcore/network.h
index 8a0e20dc..0ce1f34d 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -285,4 +285,6 @@ Networking_Core *new_networking(IP ip, uint16_t port);
285/* Function to cleanup networking stuff (doesn't do much right now). */ 285/* Function to cleanup networking stuff (doesn't do much right now). */
286void kill_networking(Networking_Core *net); 286void kill_networking(Networking_Core *net);
287 287
288int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t *length);
289
288#endif 290#endif
diff --git a/toxcore/util.c b/toxcore/util.c
index e307bad6..8fc6806e 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -25,7 +25,7 @@ uint64_t random_64b()
25{ 25{
26 uint64_t r; 26 uint64_t r;
27 27
28 // This is probably not random enough? 28 /* This is probably not random enough? */
29 r = random_int(); 29 r = random_int();
30 r <<= 32; 30 r <<= 32;
31 r |= random_int(); 31 r |= random_int();