mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
add and update
This commit is contained in:
parent
03ed2886cb
commit
bda4d33012
109 changed files with 73065 additions and 85 deletions
|
@ -71,10 +71,10 @@
|
|||
#include "freertos/inic_intf.h"
|
||||
#endif
|
||||
|
||||
#define netifMTU (1500)
|
||||
#define netifMTU (1500)
|
||||
#define netifINTERFACE_TASK_STACK_SIZE ( 350 )
|
||||
#define netifINTERFACE_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
|
||||
#define netifGUARD_BLOCK_TIME ( 250 )
|
||||
#define netifGUARD_BLOCK_TIME ( 250 )
|
||||
/* The time to block waiting for input. */
|
||||
#define emacBLOCK_TIME_WAITING_FOR_INPUT ( ( portTickType ) 100 )
|
||||
|
||||
|
|
134
RTL00_SDKV35a/component/common/network/rtsp/rtp_api.h
Normal file
134
RTL00_SDKV35a/component/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
|
100
RTL00_SDKV35a/component/common/network/rtsp/src2rtsp.h
Normal file
100
RTL00_SDKV35a/component/common/network/rtsp/src2rtsp.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
#ifndef _SRC2RTSP_H_
|
||||
#define _SRC2RTSP_H_
|
||||
|
||||
/* Add by Ian -- This file contains parts used for rtsp to access lower layer stream src information*/
|
||||
|
||||
#include "dlist.h"
|
||||
#include "basic_types.h"
|
||||
#include "osdep_service.h"
|
||||
//#include "osdep_api.h"
|
||||
#include "rtsp/rtp_api.h"
|
||||
#include "avcodec.h"
|
||||
|
||||
#define SRC_FROM_UVC
|
||||
//#define SRC_FROM_UAC
|
||||
//#define SRC_FROM_SPI
|
||||
#define SRC_FROM_I2S
|
||||
#define SRC_FROM_STA
|
||||
|
||||
#define SRC_TYPE_NUL 0
|
||||
#define SRC_TYPE_UVC 1
|
||||
#define SRC_TYPE_SPI 2
|
||||
#define SRC_TYPE_UAC 3
|
||||
#define SRC_TYPE_I2S 4
|
||||
#define SRC_TYPE_STA 7
|
||||
|
||||
struct FormatInfo
|
||||
{
|
||||
struct codec_info codec;
|
||||
u8 framerate;
|
||||
u32 bitrate;
|
||||
u32 height;
|
||||
u32 width;
|
||||
};
|
||||
|
||||
struct stream_flow
|
||||
{
|
||||
int id;
|
||||
void *prot_hook; //transport protocol hook
|
||||
void *src;
|
||||
int src_type;
|
||||
struct FormatInfo currentFormatInfo;
|
||||
int (*src_handler) (void *src, struct rtp_object *payload);
|
||||
struct list_head input_queue;
|
||||
_mutex input_lock;
|
||||
struct list_head output_queue;
|
||||
_mutex output_lock;
|
||||
u8 is_src2rtsp_init;
|
||||
u8 is_src2rtsp_start;
|
||||
_sema start_src2rtsp_sema;
|
||||
struct stream_flow *next;
|
||||
};
|
||||
|
||||
|
||||
#ifdef SRC_FROM_UVC
|
||||
#include "v4l2_intf.h"
|
||||
struct uvc_streaming;
|
||||
struct uvcManager
|
||||
{
|
||||
struct uvc_streaming *stream;
|
||||
streaming_state state;
|
||||
struct FormatInfo currentFormatInfo;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef SRC_FROM_SPI
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SRC_FROM_UAC
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SRC_FROM_I2S
|
||||
struct i2sManager{
|
||||
struct FormatInfo currentFormatInfo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SRC_FROM_STA
|
||||
struct rtsp_static_source_manager
|
||||
{
|
||||
struct FormatInfo currentFormatInfo;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct stream_flow* rtsp_stream_flow_create(void);
|
||||
void rtsp_stream_flow_free(struct stream_flow *stream);
|
||||
void rtsp_register_src_handler(struct stream_flow *stream, int (*src_handler) (void *stream_src, struct rtp_object *payload));
|
||||
int rtsp_get_src_currentFormatInfo(struct stream_flow *stream);
|
||||
int rtsp_set_src_FormatInfo(struct stream_flow *stream, int codec_id, u8 framerate, u32 height, u32 width, u32 bitrate);
|
||||
extern int rtsp_set_src_extra(struct stream_flow, void *param);
|
||||
int rtsp_stream_flow_set(struct stream_flow *stream, void *source, int src_type);
|
||||
int rtsp_stream_flow_update(struct stream_flow *stream);
|
||||
int rtsp_stream_flow_concat(struct stream_flow *stream, struct stream_flow *stream_next);
|
||||
void rtp_object_in_src_queue(struct rtp_object *payload, struct stream_flow *stream);
|
||||
struct rtp_object *rtp_object_out_src_queue(struct stream_flow *stream);
|
||||
|
||||
|
||||
#endif
|
120
RTL00_SDKV35a/component/common/network/websocket/libwsclient.h
Normal file
120
RTL00_SDKV35a/component/common/network/websocket/libwsclient.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
#ifndef EASYWSCLIENT_H
|
||||
#define EASYWSCLIENT_H
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
/****************Define the debug message level*********************/
|
||||
#define DEBUG_WSCLIENT 1
|
||||
|
||||
#define WSCLIENT_LOG(level, fmt, ...) printf("\n\r[WSCLIENT %s] %s: " fmt "\n", level, __FUNCTION__, ##__VA_ARGS__)
|
||||
#if DEBUG_WSCLIENT == 2
|
||||
#define WSCLIENT_DEBUG(fmt, ...) WSCLIENT_LOG("DEBUG", fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define WSCLIENT_DEBUG(fmt, ...)
|
||||
#endif
|
||||
#if DEBUG_WSCLIENT
|
||||
#define WSCLIENT_ERROR(fmt, ...) WSCLIENT_LOG("ERROR", fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define WSCLIENT_ERROR(fmt, ...)
|
||||
#endif
|
||||
/*******************************************************************/
|
||||
|
||||
/****************Define the structures used*************************/
|
||||
typedef enum{
|
||||
CLOSING,
|
||||
CLOSED,
|
||||
CONNECTING,
|
||||
OPEN
|
||||
} readyStateValues;
|
||||
|
||||
struct wsheader_type{
|
||||
unsigned header_size;
|
||||
int fin;
|
||||
int mask;
|
||||
enum opcode_type {
|
||||
CONTINUATION = 0x0,
|
||||
TEXT_FRAME = 0x1,
|
||||
BINARY_FRAME = 0x2,
|
||||
CLOSE = 8,
|
||||
PING = 9,
|
||||
PONG = 0xa,
|
||||
} opcode;
|
||||
int N0;
|
||||
uint64_t N;
|
||||
uint8_t masking_key[4];
|
||||
};
|
||||
|
||||
struct _wsclient_context;
|
||||
struct _ssl_context;
|
||||
|
||||
struct ssl_fun_ops{
|
||||
int (*memory_set_own)( void * (*malloc_func)( size_t ),void (*free_func)( void * ) );
|
||||
int (*net_connect)( int *fd, const char *host, int port );
|
||||
int (*ssl_init)( struct _ssl_context *ssl );
|
||||
void (*ssl_set_endpoint)( struct _ssl_context *ssl, int endpoint );
|
||||
void (*ssl_set_authmode)( struct _ssl_context *ssl, int authmode );
|
||||
void (*ssl_set_rng)( struct _ssl_context *ssl,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
void (*ssl_set_bio)( struct _ssl_context *ssl,
|
||||
int (*f_recv)(void *, unsigned char *, size_t), void *p_recv,
|
||||
int (*f_send)(void *, const unsigned char *, size_t), void *p_send );
|
||||
int (*ssl_handshake)( struct _ssl_context *ssl );
|
||||
void (*net_close)( int fd );
|
||||
void (*ssl_free)( struct _ssl_context *ssl );
|
||||
int (*ssl_read)( struct _ssl_context *ssl, unsigned char *buf, size_t len );
|
||||
int (*ssl_write)( struct _ssl_context *ssl, const unsigned char *buf, size_t len );
|
||||
const char *(*ssl_get_ciphersuite)( const struct _ssl_context *ssl );
|
||||
int (*net_recv)( void *ctx, unsigned char *buf, size_t len );
|
||||
int (*net_send)( void *ctx, const unsigned char *buf, size_t len );
|
||||
};
|
||||
|
||||
struct ws_fun_ops{
|
||||
int (*hostname_connect)(struct _wsclient_context *wsclient);
|
||||
void (*client_close)(struct _wsclient_context *wsclient);
|
||||
int (*client_send)(struct _wsclient_context *wsclient, unsigned char *data, size_t data_len);
|
||||
int (*client_read)(struct _wsclient_context *wsclient, unsigned char *data, size_t data_len);
|
||||
struct ssl_fun_ops ssl_fun_ops;
|
||||
};
|
||||
|
||||
typedef struct _wsclient_context{
|
||||
char host[128];
|
||||
char path[128];
|
||||
char origin[200];
|
||||
int port;
|
||||
uint8_t use_ssl;
|
||||
int sockfd;
|
||||
readyStateValues readyState;
|
||||
int tx_len;
|
||||
void *ssl;
|
||||
uint8_t *txbuf;
|
||||
uint8_t *rxbuf;
|
||||
uint8_t *receivedData;
|
||||
struct ws_fun_ops fun_ops;
|
||||
}wsclient_context;
|
||||
/*******************************************************************/
|
||||
|
||||
/****************General functions used by wsclient*****************/
|
||||
void ws_get_random_bytes(void *buf, size_t len);
|
||||
void* ws_malloc(unsigned int size);
|
||||
void ws_free(void *buf);
|
||||
int ws_client_handshake(wsclient_context *wsclient);
|
||||
int ws_check_handshake(wsclient_context *wsclient);
|
||||
void ws_sendData(uint8_t type, size_t message_size, uint8_t* message, int useMask, wsclient_context *wsclient);
|
||||
/*******************************************************************/
|
||||
|
||||
/*************Functions used by wsclient without SSL****************/
|
||||
|
||||
int ws_hostname_connect(wsclient_context *wsclient);
|
||||
int ws_client_read(wsclient_context *wsclient, unsigned char *data, size_t data_len);
|
||||
int ws_client_send(wsclient_context *wsclient, unsigned char *data, size_t data_len);
|
||||
void ws_client_close(wsclient_context *wsclient);
|
||||
/*******************************************************************/
|
||||
|
||||
/***************Functions used by wsclient with SSL*****************/
|
||||
int wss_hostname_connect(wsclient_context *wsclient);
|
||||
int wss_client_read(wsclient_context *wsclient, unsigned char *data, size_t data_len);
|
||||
int wss_client_send(wsclient_context *wsclient, unsigned char *data, size_t data_len);
|
||||
void wss_client_close(wsclient_context *wsclient);
|
||||
/*******************************************************************/
|
||||
|
||||
#endif
|
108
RTL00_SDKV35a/component/common/network/websocket/wsclient_api.h
Normal file
108
RTL00_SDKV35a/component/common/network/websocket/wsclient_api.h
Normal file
|
@ -0,0 +1,108 @@
|
|||
#ifndef WSCLIENT_H
|
||||
#define WSCLIENT_H
|
||||
#include <websocket/libwsclient.h>
|
||||
|
||||
|
||||
/******Define the maximum bytes of data send and receive********/
|
||||
#define MAX_DATA_LEN 1500
|
||||
/****************Define if using the polarssl*******************/
|
||||
#define USING_SSL
|
||||
|
||||
|
||||
/******************Define the function used*********************/
|
||||
#ifdef USING_SSL
|
||||
int wss_set_fun_ops(wsclient_context *wsclient);
|
||||
#define wsclient_set_fun_ops(wsclient) wss_set_fun_ops(wsclient)
|
||||
#else
|
||||
int ws_set_fun_ops(wsclient_context *wsclient);
|
||||
#define wsclient_set_fun_ops(wsclient) ws_set_fun_ops(wsclient)
|
||||
#endif
|
||||
/***************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : create_wsclient
|
||||
** Description : Creating the websocket client context structure
|
||||
** Input : url:websocket server's url
|
||||
** port:websocket server's port, if not given, default 80 for "ws", 443 for "wss"
|
||||
** origin: the address or url of your self
|
||||
** Return : Created: websocket client context structure
|
||||
** Failed: NULL
|
||||
**************************************************************************************************/
|
||||
wsclient_context *create_wsclient(char *url, int port,char *path, char* origin);
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : ws_connect_url
|
||||
** Description : Connecting to the websocket server
|
||||
** Input : wsclient: the websocket client context created by create_wsclientfunction
|
||||
** Return : Connected: the socket value
|
||||
** Failed: -1
|
||||
**************************************************************************************************/
|
||||
int ws_connect_url(wsclient_context *wsclient);
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : ws_send
|
||||
** Description : Create the sending string data and copy to tx_buf
|
||||
** Input : message: the string that send to server(cannot exceeding the MAX_DATA_LEN
|
||||
** message_len: the length of the string
|
||||
** use_mask: 0/1; 1 means using mask for bynary
|
||||
** wsclient: the websocket client context
|
||||
** Return : None
|
||||
**************************************************************************************************/
|
||||
void ws_send(char* message, int message_len, int use_mask, wsclient_context *wsclient);
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : ws_sendBinary
|
||||
** Description : Create the sending binary data and copy to tx_buf
|
||||
** Input : message: the binary that send to server(cannot exceeding the MAX_DATA_LEN
|
||||
** message_len: the length of the binary
|
||||
** use_mask: 0/1; 1 means using mask for bynary
|
||||
** wsclient: the websocket client context
|
||||
** Return : None
|
||||
**************************************************************************************************/
|
||||
void ws_sendBinary(uint8_t* message, int message_len, int use_mask, wsclient_context *wsclient);
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : ws_sendPing
|
||||
** Description : Sending Ping to websocket server
|
||||
** Input : wsclient: the websocket client context
|
||||
** Return : None
|
||||
**************************************************************************************************/
|
||||
void ws_sendPing(wsclient_context *wsclient);
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : ws_poll
|
||||
** Description : Receicing data from server and send the data in tx_buf
|
||||
** Input : timeout(in milliseconds)
|
||||
wsclient: the websocket client context
|
||||
** Return : None
|
||||
**************************************************************************************************/
|
||||
void ws_poll(int timeout, wsclient_context *wsclient);
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : ws_dispatch
|
||||
** Description : callback function when getting message from server
|
||||
** Input : function that resolve the message received and the message length
|
||||
** Return : None
|
||||
**************************************************************************************************/
|
||||
void ws_dispatch(void (*callback)(wsclient_context *, int)) ;
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : ws_getReadyState
|
||||
** Description : Getting the connection status
|
||||
** Input : wsclient: the websocket client context
|
||||
** Return : readyStateValues(4 types:CLOSING, CLOSED, CONNECTING, OPEN)
|
||||
**************************************************************************************************/
|
||||
readyStateValues ws_getReadyState(wsclient_context *wsclient);
|
||||
|
||||
/*************************************************************************************************
|
||||
** Function Name : ws_close
|
||||
** Description : Closing the connection with websocket server
|
||||
** Input : wsclient: the websocket client context
|
||||
** Return : None
|
||||
**************************************************************************************************/
|
||||
void ws_close(wsclient_context *wsclient);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue