toxcore/toxrtp/toxrtp.h

189 lines
6.8 KiB
C
Raw Normal View History

2013-10-13 22:16:47 +08:00
/* rtp_impl.h
*
* Rtp implementation includes rtp_session_s struct which is a session identifier.
* It contains session information and it's a must for every session.
* It's best if you don't touch any variable directly but use callbacks to do so. !Red!
*
*
* Copyright (C) 2013 Tox project All Rights Reserved.
*
* This file is part of Tox.
*
* Tox is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _RTP__IMPL_H_
#define _RTP__IMPL_H_
#define RTP_VERSION 2
#include <inttypes.h>
#include "../toxcore/tox.h"
2013-10-17 20:09:06 +08:00
#include <pthread.h>
2013-10-13 22:16:47 +08:00
/* Extension header flags */
#define RTP_EXT_TYPE_RESOLUTION 0x01
#define RTP_EXT_TYPE_FRAMERATE 0x02
/* Some defines */
#define RTP_PACKET 70
/* Payload identifiers */
/* Audio */
#define _PAYLOAD_OPUS 96
/* Video */
#define _PAYLOAD_VP8 106
/* End of Payload identifiers */
/* End of defines */
/* Our main session descriptor.
* It measures the session variables and controls
* the entire session. There are functions for manipulating
* the session so tend to use those instead of directly accessing
* session parameters.
*/
typedef struct rtp_session_s {
uint8_t _version;
uint8_t _padding;
uint8_t _extension;
uint8_t _cc;
uint8_t _marker;
uint8_t _payload_type;
uint16_t _sequence_number; /* Set when sending */
uint16_t _last_sequence_number; /* Check when recving msg */
uint32_t _initial_time;
uint32_t _time_elapsed;
uint32_t _current_timestamp;
uint32_t _ssrc;
2013-10-17 20:09:06 +08:00
uint32_t *_csrc;
2013-10-13 22:16:47 +08:00
/* If some additional data must be sent via message
* apply it here. Only by allocating this member you will be
* automatically placing it within a message.
*/
2013-10-17 20:09:06 +08:00
struct rtp_ext_header_s *_ext_header;
2013-10-13 22:16:47 +08:00
/* External header identifiers */
int _exthdr_resolution;
int _exthdr_framerate;
int _max_users; /* -1 undefined */
uint64_t _packets_sent; /* measure packets */
uint64_t _packets_recv;
uint64_t _bytes_sent;
uint64_t _bytes_recv;
uint64_t _packet_loss;
2013-10-17 20:09:06 +08:00
const char *_last_error;
2013-10-13 22:16:47 +08:00
2013-10-17 20:09:06 +08:00
struct rtp_dest_list_s *_dest_list;
struct rtp_dest_list_s *_last_user; /* a tail for faster appending */
2013-10-13 22:16:47 +08:00
2013-10-17 20:09:06 +08:00
struct rtp_msg_s *_oldest_msg;
struct rtp_msg_s *_last_msg; /* tail */
2013-10-13 22:16:47 +08:00
uint16_t _prefix_length;
2013-10-17 20:09:06 +08:00
uint8_t *_prefix;
2013-10-13 22:16:47 +08:00
/* Specifies multiple session use.
* When using one session it uses default value ( -1 )
* Otherwise it's set to 1 and rtp_register_msg () is required
*/
int _multi_session;
uint32_t _current_framerate;
pthread_mutex_t _mutex;
} rtp_session_t;
/*
* Now i don't believe we need to store this _from thing every time
* since we have csrc table but will leave it like this for a while
*/
2013-10-17 20:09:06 +08:00
void rtp_free_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg );
int rtp_release_session_recv ( rtp_session_t *_session );
2013-10-13 22:16:47 +08:00
/* Functions handling receiving */
2013-10-17 20:09:06 +08:00
struct rtp_msg_s *rtp_recv_msg ( rtp_session_t *_session );
void rtp_store_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg );
2013-10-13 22:16:47 +08:00
/*
* rtp_msg_parse() stores headers separately from the payload data
* and so the _length variable is set accordingly
*/
2013-10-17 20:09:06 +08:00
struct rtp_msg_s *rtp_msg_parse ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length );
2013-10-13 22:16:47 +08:00
2013-10-17 20:09:06 +08:00
int rtp_check_late_message (rtp_session_t *_session, struct rtp_msg_s *_msg);
void rtp_register_msg ( rtp_session_t *_session, struct rtp_msg_s * );
2013-10-13 22:16:47 +08:00
/* Functions handling sending */
2013-10-17 20:09:06 +08:00
int rtp_send_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg, void *_core_handler );
2013-10-13 22:16:47 +08:00
/*
* rtp_msg_new() stores headers and payload data in one container ( _data )
* and the _length is set accordingly. Returned message is used for sending only
* so there is not much use of the headers there
*/
2013-10-17 20:09:06 +08:00
struct rtp_msg_s *rtp_msg_new ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length );
2013-10-13 22:16:47 +08:00
/* Convenient functions for creating a header */
2013-10-17 20:09:06 +08:00
struct rtp_header_s *rtp_build_header ( rtp_session_t *_session );
2013-10-13 22:16:47 +08:00
/* Functions handling session control */
/* Handling an rtp packet */
/* int rtp_handlepacket(uint8_t * packet, uint32_t length, IP_Port source); */
/* Session initiation and termination.
* Set _multi_session to -1 if not using multiple sessions
*/
2013-10-17 20:09:06 +08:00
rtp_session_t *rtp_init_session ( int _max_users, int _multi_session );
int rtp_terminate_session ( rtp_session_t *_session );
2013-10-13 22:16:47 +08:00
/* Adding receiver */
2013-10-17 20:09:06 +08:00
int rtp_add_receiver ( rtp_session_t *_session, tox_IP_Port *_dest );
2013-10-13 22:16:47 +08:00
/* Convenient functions for marking the resolution */
2013-10-17 20:09:06 +08:00
int rtp_add_resolution_marking ( rtp_session_t *_session, uint16_t _width, uint16_t _height );
int rtp_remove_resolution_marking ( rtp_session_t *_session );
uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s *_header, uint32_t _position );
uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s *_header, uint32_t _position );
int rtp_add_framerate_marking ( rtp_session_t *_session, uint32_t _value );
int rtp_remove_framerate_marking ( rtp_session_t *_session );
uint32_t rtp_get_framerate_marking ( struct rtp_ext_header_s *_header );
2013-10-13 22:16:47 +08:00
/* Convenient functions for marking the payload */
2013-10-17 20:09:06 +08:00
void rtp_set_payload_type ( rtp_session_t *_session, uint8_t _payload_value );
uint32_t rtp_get_payload_type ( rtp_session_t *_session );
2013-10-13 22:16:47 +08:00
/* When using RTP in core be sure to set prefix when sending via rtp_send_msg */
2013-10-17 20:09:06 +08:00
int rtp_set_prefix ( rtp_session_t *_session, uint8_t *_prefix, uint16_t _prefix_length );
2013-10-13 22:16:47 +08:00
#endif /* _RTP__IMPL_H_ */