initial commit
This commit is contained in:
134
lib/amb1_sdk/common/network/rtsp/rtp_api.h
Normal file
134
lib/amb1_sdk/common/network/rtsp/rtp_api.h
Normal file
@@ -0,0 +1,134 @@
|
||||
#ifndef _RTP_API_H_
|
||||
#define _RTP_API_H_
|
||||
|
||||
#include "dlist.h"
|
||||
#include "basic_types.h"
|
||||
#include "osdep_service.h"
|
||||
//#include "osdep_api.h"
|
||||
#include "avcodec.h"
|
||||
#include <lwip/def.h> //for host network byte order convertion
|
||||
|
||||
/* from error_base.h */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* Out of memory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
|
||||
#define RTP_BIG_ENDIAN 0
|
||||
#define RTP_HDR_SZ 12
|
||||
|
||||
#define RTP_SERVER_PORT_BASE 55608
|
||||
#define RTP_PORT_BASE 50020
|
||||
#define RTP_CLIENT_PORT_BASE 51020
|
||||
/*
|
||||
* RTP data header from RFC1889
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* The RTP header has the following format:
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |V=2|P|X| CC |M| PT | sequence number |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | timestamp |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | synchronization source (SSRC) identifier |
|
||||
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||||
* | contributing source (CSRC) identifiers |
|
||||
* | .... |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* RTP data header
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
#if RTP_BIG_ENDIAN
|
||||
u16 version:2; /* protocol version */
|
||||
u16 p:1; /* padding flag */
|
||||
u16 x:1; /* header extension flag */
|
||||
u16 cc:4; /* CSRC count */
|
||||
u16 m:1; /* marker bit */
|
||||
u16 pt:7; /* payload type */
|
||||
#else /*RTP_LITTLE_ENDIAN*/
|
||||
u16 cc:4; /* CSRC count */
|
||||
u16 x:1; /* header extension flag */
|
||||
u16 p:1; /* padding flag */
|
||||
u16 version:2; /* protocol version */
|
||||
u16 pt:7; /* payload type */
|
||||
u16 m:1; /* marker bit */
|
||||
#endif
|
||||
u16 seq; /* sequence number */
|
||||
u32 ts; /* timestamp */
|
||||
u32 ssrc; /* synchronization source */
|
||||
u32 *csrc; /* optional CSRC list, skip if cc is set to 0 here*/
|
||||
} rtp_hdr_t;
|
||||
|
||||
/*sturcture to hold connect info*/
|
||||
struct connect_context
|
||||
{
|
||||
int socket_id;
|
||||
u8 *server_ip;
|
||||
u16 server_port;
|
||||
u8 *remote_ip;
|
||||
u16 remote_port;
|
||||
};
|
||||
|
||||
struct rtp_statistics
|
||||
{
|
||||
u32 rtp_tick;
|
||||
u32 rtp_tick_inc;
|
||||
u32 base_timestamp;
|
||||
/*for flow control*/
|
||||
u32 delay_threshold; //in ms
|
||||
u32 timer1; //time before send
|
||||
u32 timer2; //time after sent
|
||||
u32 delta_timer;
|
||||
u8 do_start_check; //indicate if start check need to be done
|
||||
u32 sent_packet;
|
||||
u32 drop_packet;
|
||||
};
|
||||
|
||||
enum rtp_object_state
|
||||
{
|
||||
RTP_OBJECT_IDLE = 0,
|
||||
RTP_OBJECT_READY,
|
||||
RTP_OBJECT_INUSE,
|
||||
RTP_OBJECT_USED,
|
||||
};
|
||||
|
||||
struct stream_context;
|
||||
struct rtp_object;
|
||||
|
||||
struct rtp_object
|
||||
{
|
||||
struct list_head rtp_list;
|
||||
_mutex list_lock;
|
||||
rtp_hdr_t *rtphdr;
|
||||
void *extra; //pointer to type specific structure
|
||||
int index; //respective internal buffer index
|
||||
u8 *data; // respective internal buffer data addr
|
||||
int len; //one complete frame data length
|
||||
u32 timestamp; //timestamp
|
||||
u32 fs:1; //fragment start
|
||||
u32 fe:1; //fragment end
|
||||
u32 fk:1; //fragment keep indicator so that cannot avoid sending by flow control
|
||||
u32 fd:29; //fragment data size (max size of 2^29-1)
|
||||
enum rtp_object_state state;
|
||||
struct connect_context connect_ctx;
|
||||
int (*rtp_object_handler)(struct stream_context *stream_ctx, struct rtp_object *payload);
|
||||
};
|
||||
|
||||
void rtp_object_init(struct rtp_object *payload);
|
||||
void rtp_object_deinit(struct rtp_object *payload);
|
||||
void rtp_object_set_fs(struct rtp_object *payload, int flag);
|
||||
void rtp_object_set_fe(struct rtp_object *payload, int flag);
|
||||
void rtp_object_set_fk(struct rtp_object *payload, int flag);
|
||||
void rtp_object_set_fd(struct rtp_object *payload, int size);
|
||||
void rtp_load_o_handler_by_codec_id(struct rtp_object *payload, int id);
|
||||
void rtp_fill_header(rtp_hdr_t *rtphdr, int version, int padding, int extension, int cc, int marker, int pt, u16 seq, u32 ts, u32 ssrc);
|
||||
int rtp_parse_header(u8 *src, rtp_hdr_t *rtphdr, int is_nbo);
|
||||
void rtp_dump_header(rtp_hdr_t *rtphdr, int is_nbo);
|
||||
#endif
|
||||
164
lib/amb1_sdk/common/network/rtsp/rtsp_api.h
Normal file
164
lib/amb1_sdk/common/network/rtsp/rtsp_api.h
Normal file
@@ -0,0 +1,164 @@
|
||||
#ifndef _RTSP_API_H_
|
||||
#define _RTSP_API_H_
|
||||
|
||||
#include "dlist.h"
|
||||
#include "basic_types.h"
|
||||
#include "osdep_service.h"
|
||||
//#include "osdep_api.h"
|
||||
#include "rtsp/rtp_api.h"
|
||||
#include "avcodec.h"
|
||||
#include "rtsp/sdp.h"
|
||||
|
||||
#define RTSP_DEBUG 0
|
||||
|
||||
#if RTSP_DEBUG
|
||||
#define RTSP_PRINTF(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#define RTSP_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#else
|
||||
#define RTSP_PRINTF(fmt, args...)
|
||||
#define RTSP_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
|
||||
#endif
|
||||
|
||||
/* clock usage */
|
||||
#define RTSP_DEPEND_CLK_HZ configTICK_RATE_HZ
|
||||
|
||||
#define RTSP_SERVICE_PRIORITY 2
|
||||
#define RTSP_MAX_STREAM_NUM 2
|
||||
#define RTSP_REQUEST_BUF_SIZE 512
|
||||
#define RTSP_RESPONSE_BUF_SIZE MAX_SDP_SIZE //max size for response buffer
|
||||
#define DEF_RTSP_PORT 554
|
||||
#define DEF_HTTP_PORT 5008
|
||||
|
||||
#define RTSP_SELECT_SOCK 8
|
||||
|
||||
/*rtsp request type list*/
|
||||
#define REQUEST_OPTIONS 1
|
||||
#define REQUEST_DESCRIBE 2
|
||||
#define REQUEST_SETUP 3
|
||||
#define REQUEST_TEARDOWN 4
|
||||
#define REQUEST_PLAY 5
|
||||
#define REQUEST_PAUSE 6
|
||||
#define REQUEST_GET_PARAM 7
|
||||
|
||||
/*rtsp cast mode list*/
|
||||
#define UNICAST_UDP_MODE 1
|
||||
#define UNICAST_TCP_MODE 2
|
||||
#define MULTICAST_MODE 3
|
||||
|
||||
#define BOUNDARY "amebaimagetest"
|
||||
|
||||
/*RTSP KEEPALIVE TIMEOUT ENABLE*/
|
||||
#define KEEPALIVE_TIMEOUT_ENABLE
|
||||
|
||||
|
||||
enum _rtsp_state {
|
||||
RTSP_INIT = 0,
|
||||
RTSP_READY = 1,
|
||||
RTSP_PLAYING = 2,
|
||||
};
|
||||
typedef enum _rtsp_state rtsp_state;
|
||||
|
||||
struct rtsp_session
|
||||
{
|
||||
u32 id;
|
||||
u8 version;
|
||||
u32 start_time;
|
||||
u32 end_time;
|
||||
u8 *user;
|
||||
u8 *name;
|
||||
};
|
||||
|
||||
struct rtsp_transport
|
||||
{
|
||||
u8 isRtp; //transport protocol
|
||||
u8 isTcp; //lower transport protocol
|
||||
u8 castMode; //unicast UDP(1) or unicast TCP(2) or multicast(3)
|
||||
int port_low;
|
||||
int port_high;
|
||||
int clientport_low;
|
||||
int clientport_high;
|
||||
int serverport_low;
|
||||
int serverport_high;
|
||||
u8 ttl; //multicast time to live
|
||||
//to be added if necessary
|
||||
};
|
||||
|
||||
struct stream_context
|
||||
{
|
||||
struct rtsp_context *parent;
|
||||
int stream_id; //sync with stream_flow id
|
||||
struct list_head input_queue;
|
||||
_mutex input_lock;
|
||||
struct list_head output_queue;
|
||||
_mutex output_lock;
|
||||
struct codec_info *codec;
|
||||
u8 media_type;
|
||||
u8 framerate;
|
||||
u32 bitrate;
|
||||
u32 samplerate;
|
||||
u32 channel;
|
||||
struct rtp_statistics statistics;
|
||||
};
|
||||
|
||||
struct rtsp_context
|
||||
{
|
||||
int id;
|
||||
u8 allow_stream;
|
||||
rtsp_state state;
|
||||
u8 request_type;
|
||||
u32 CSeq;
|
||||
u8 *response;
|
||||
struct connect_context connect_ctx;
|
||||
struct rtsp_transport transport[RTSP_MAX_STREAM_NUM];
|
||||
struct rtsp_session session;
|
||||
u16 rtpseq[RTSP_MAX_STREAM_NUM];
|
||||
u8 is_rtsp_start;
|
||||
_sema start_rtsp_sema;
|
||||
u8 is_rtp_start;
|
||||
_sema start_rtp_sema;
|
||||
void (* rtp_service_handle) (struct rtsp_context* rtsp_ctx);
|
||||
#ifdef SUPPORT_RTCP
|
||||
u8 is_rtcp_start;
|
||||
_sema start_rtcp_sema;
|
||||
void (* rtcp_service_handle) (struct rtsp_context* rtsp_ctx);
|
||||
#endif
|
||||
#ifdef SUPPORT_HTTP
|
||||
//to be added
|
||||
#endif
|
||||
u8 nb_streams_setup;
|
||||
u8 nb_streams;
|
||||
struct stream_context *stream_ctx;
|
||||
u32 pre_filter_packet;
|
||||
// callback
|
||||
int (*cb_start)(void*); // play
|
||||
int (*cb_stop)(void*); // teardown
|
||||
int (*cb_pause)(void*); // pause
|
||||
int (*cb_custom)(void*); // setparam
|
||||
};
|
||||
|
||||
int rtsp_clock_init(u32 clock_hz);
|
||||
void rtsp_clock_deinit();
|
||||
u32 rtsp_get_current_tick();
|
||||
|
||||
int rtsp_get_number(int number_base, u32 *number_bitmap, _mutex *bitmap_lock);
|
||||
void rtsp_put_number(int number, int number_base, u32 *number_bitmap, _mutex *bitmap_lock);
|
||||
struct rtsp_context *rtsp_context_create(u8 nb_streams);
|
||||
void rtsp_context_free(struct rtsp_context *rtsp_ctx);
|
||||
int rtsp_is_stream_enabled(struct rtsp_context *rtsp_ctx);
|
||||
int rtsp_is_service_enabled(struct rtsp_context *rtsp_ctx);
|
||||
int rtsp_open(struct rtsp_context *rtsp_ctx);
|
||||
void rtsp_close(struct rtsp_context *rtsp_ctx);
|
||||
void rtsp_start(struct rtsp_context *rtsp_ctx);
|
||||
void rtsp_stop(struct rtsp_context *rtsp_ctx);
|
||||
void rtp_object_in_stream_queue(struct rtp_object *payload, struct stream_context *stream_ctx);
|
||||
struct rtp_object *rtp_object_out_stream_queue(struct stream_context *stream_ctx);
|
||||
|
||||
void set_profile_lv_string(char * plid);
|
||||
void set_sps_string(char * sps);
|
||||
void set_pps_string(char * pps);
|
||||
int rtsp_parse_stream_media_type(struct codec_info *codec);
|
||||
void rtsp_stream_context_init(struct rtsp_context *rtsp_ctx, struct stream_context *stream_ctx);
|
||||
void set_prefilter_packet(struct rtsp_context *rtsp_ctx,u32 num);
|
||||
void time_sync_disable(void);
|
||||
void time_sync_enable(void);
|
||||
#endif
|
||||
26
lib/amb1_sdk/common/network/rtsp/sdp.h
Normal file
26
lib/amb1_sdk/common/network/rtsp/sdp.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _SDP_H_
|
||||
#define _SDP_H_
|
||||
|
||||
#include "avcodec.h"
|
||||
|
||||
#define CRLF "\r\n"
|
||||
#define MAX_SDP_SIZE (512+256)
|
||||
#define SDP_LINE_LEN (128+256)
|
||||
|
||||
#define SDP_BWTYPE_CT 0
|
||||
#define SDP_BWTYPE_AS 1
|
||||
|
||||
void sdp_strcat(unsigned char *buf1, int size, unsigned char *buf2);
|
||||
void sdp_fill_o_field(unsigned char *sdp_buf, int size, u8 *username, u32 session_id, u8 session_version, u8* nettype, u8* addrtype, u8* unicast_addr);
|
||||
void sdp_fill_s_field(unsigned char *sdp_buf, int size, u8 * session_name);
|
||||
void sdp_fill_i_field(unsigned char *sdp_buf, int size, u8 * session_info);
|
||||
void sdp_fill_u_field(unsigned char * sdp_buf, int size, u8 *uri);
|
||||
void sdp_fill_c_field(unsigned char *sdp_buf, int size, u8 *nettype, u8 *addrtype, u8 *connection_addr, u8 ttl);
|
||||
void sdp_fill_b_field(unsigned char *sdp_buf, int size, int bwtype, int bw);
|
||||
void sdp_fill_t_field(unsigned char *sdp_buf, int size, u32 start_time, u32 end_time);
|
||||
void sdp_fill_m_field(unsigned char *sdp_buf, int size, int media_type, u16 port, int fmt);
|
||||
void sdp_fill_a_string(unsigned char *sdp_buf, int size, u8 *string);
|
||||
void sdp_fill_a_rtpmap(unsigned char *sdp_buf, int size, struct codec_info *codec);
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user