summaryrefslogtreecommitdiff
path: root/docs/av_api.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/av_api.md')
-rw-r--r--docs/av_api.md156
1 files changed, 156 insertions, 0 deletions
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