2014-03-01 11:15:36 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
|
|
|
Copyright (c) 2013-2014 winlin
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRS_LIB_RTMP_HPP
|
|
|
|
#define SRS_LIB_RTMP_HPP
|
|
|
|
|
|
|
|
/*
|
2014-03-01 15:24:53 +00:00
|
|
|
#include <srs_librtmp.h>
|
2014-03-01 11:15:36 +00:00
|
|
|
*/
|
|
|
|
|
2014-03-02 09:47:53 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2014-03-01 16:15:09 +00:00
|
|
|
/**
|
|
|
|
* srs-librtmp is a librtmp like library,
|
|
|
|
* used to play/publish rtmp stream from/to rtmp server.
|
|
|
|
* socket: use sync and block socket to connect/recv/send data with server.
|
|
|
|
* depends: no need other libraries; depends on ssl if use srs_complex_handshake.
|
|
|
|
* thread-safe: no
|
|
|
|
*/
|
|
|
|
|
2014-03-01 15:24:53 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"{
|
|
|
|
#endif
|
|
|
|
|
2014-11-07 14:06:30 +00:00
|
|
|
/*************************************************************
|
|
|
|
**************************************************************
|
|
|
|
* RTMP protocol context
|
|
|
|
**************************************************************
|
|
|
|
*************************************************************/
|
2014-07-13 05:31:24 +00:00
|
|
|
// the RTMP handler.
|
2014-03-01 15:24:53 +00:00
|
|
|
typedef void* srs_rtmp_t;
|
|
|
|
|
|
|
|
/**
|
2014-03-01 16:05:59 +00:00
|
|
|
* create/destroy a rtmp protocol stack.
|
|
|
|
* @url rtmp url, for example:
|
2014-07-20 05:04:48 +00:00
|
|
|
* rtmp://localhost/live/livestream
|
2014-11-07 14:36:25 +00:00
|
|
|
*
|
2014-03-01 15:24:53 +00:00
|
|
|
* @return a rtmp handler, or NULL if error occured.
|
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern srs_rtmp_t srs_rtmp_create(const char* url);
|
2014-07-13 08:10:06 +00:00
|
|
|
/**
|
|
|
|
* create rtmp with url, used for connection specified application.
|
|
|
|
* @param url the tcUrl, for exmple:
|
2014-07-20 05:04:48 +00:00
|
|
|
* rtmp://localhost/live
|
2014-07-13 08:10:06 +00:00
|
|
|
* @remark this is used to create application connection-oriented,
|
|
|
|
* for example, the bandwidth client used this, no stream specified.
|
2014-11-07 14:36:25 +00:00
|
|
|
*
|
|
|
|
* @return a rtmp handler, or NULL if error occured.
|
2014-07-13 08:10:06 +00:00
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern srs_rtmp_t srs_rtmp_create2(const char* url);
|
2014-07-13 08:10:06 +00:00
|
|
|
/**
|
|
|
|
* close and destroy the rtmp stack.
|
|
|
|
* @remark, user should use the rtmp again.
|
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern void srs_rtmp_destroy(srs_rtmp_t rtmp);
|
2014-03-01 15:24:53 +00:00
|
|
|
|
2014-11-07 14:06:30 +00:00
|
|
|
/*************************************************************
|
|
|
|
**************************************************************
|
|
|
|
* RTMP protocol stack
|
|
|
|
**************************************************************
|
|
|
|
*************************************************************/
|
2014-03-01 15:24:53 +00:00
|
|
|
/**
|
2014-06-10 03:34:35 +00:00
|
|
|
* connect and handshake with server
|
2014-03-01 16:05:59 +00:00
|
|
|
* category: publish/play
|
|
|
|
* previous: rtmp-create
|
|
|
|
* next: connect-app
|
2014-11-07 14:36:25 +00:00
|
|
|
*
|
|
|
|
* @return 0, success; otherswise, failed.
|
2014-03-01 15:24:53 +00:00
|
|
|
*/
|
2014-03-01 16:05:59 +00:00
|
|
|
/**
|
|
|
|
* simple handshake specifies in rtmp 1.0,
|
|
|
|
* not depends on ssl.
|
|
|
|
*/
|
2014-06-10 03:34:35 +00:00
|
|
|
/**
|
|
|
|
* srs_simple_handshake equals to invoke:
|
|
|
|
* __srs_dns_resolve()
|
|
|
|
* __srs_connect_server()
|
|
|
|
* __srs_do_simple_handshake()
|
|
|
|
* user can use these functions if needed.
|
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_simple_handshake(srs_rtmp_t rtmp);
|
2014-06-10 03:34:35 +00:00
|
|
|
// parse uri, create socket, resolve host
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int __srs_dns_resolve(srs_rtmp_t rtmp);
|
2014-06-10 03:34:35 +00:00
|
|
|
// connect socket to server
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int __srs_connect_server(srs_rtmp_t rtmp);
|
2014-06-10 03:34:35 +00:00
|
|
|
// do simple handshake over socket.
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int __srs_do_simple_handshake(srs_rtmp_t rtmp);
|
2014-03-01 16:05:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* connect to rtmp vhost/app
|
|
|
|
* category: publish/play
|
|
|
|
* previous: handshake
|
|
|
|
* next: publish or play
|
2014-11-07 14:36:25 +00:00
|
|
|
*
|
|
|
|
* @return 0, success; otherswise, failed.
|
2014-03-01 16:05:59 +00:00
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_connect_app(srs_rtmp_t rtmp);
|
2014-03-01 16:05:59 +00:00
|
|
|
|
2014-07-13 11:16:18 +00:00
|
|
|
/**
|
|
|
|
* connect to server, get the debug srs info.
|
|
|
|
*
|
|
|
|
* SRS debug info:
|
|
|
|
* @param srs_server_ip, 128bytes, debug info, server ip client connected at.
|
|
|
|
* @param srs_server, 128bytes, server info.
|
|
|
|
* @param srs_primary_authors, 128bytes, primary authors.
|
|
|
|
* @param srs_version, 32bytes, server version.
|
|
|
|
* @param srs_id, int, debug info, client id in server log.
|
|
|
|
* @param srs_pid, int, debug info, server pid in log.
|
2014-11-07 14:36:25 +00:00
|
|
|
*
|
|
|
|
* @return 0, success; otherswise, failed.
|
2014-07-13 11:16:18 +00:00
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_connect_app2(srs_rtmp_t rtmp,
|
2014-07-13 11:16:18 +00:00
|
|
|
char srs_server_ip[128], char srs_server[128], char srs_primary_authors[128],
|
|
|
|
char srs_version[32], int* srs_id, int* srs_pid
|
|
|
|
);
|
|
|
|
|
2014-03-01 16:05:59 +00:00
|
|
|
/**
|
|
|
|
* play a live/vod stream.
|
|
|
|
* category: play
|
|
|
|
* previous: connect-app
|
|
|
|
* next: destroy
|
|
|
|
* @return 0, success; otherwise, failed.
|
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_play_stream(srs_rtmp_t rtmp);
|
2014-03-01 16:05:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* publish a live stream.
|
|
|
|
* category: publish
|
|
|
|
* previous: connect-app
|
|
|
|
* next: destroy
|
|
|
|
* @return 0, success; otherwise, failed.
|
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_publish_stream(srs_rtmp_t rtmp);
|
2014-03-01 15:24:53 +00:00
|
|
|
|
2014-07-13 08:10:06 +00:00
|
|
|
/**
|
|
|
|
* do bandwidth check with srs server.
|
|
|
|
*
|
|
|
|
* bandwidth info:
|
|
|
|
* @param start_time, output the start time, in ms.
|
|
|
|
* @param end_time, output the end time, in ms.
|
|
|
|
* @param play_kbps, output the play/download kbps.
|
|
|
|
* @param publish_kbps, output the publish/upload kbps.
|
|
|
|
* @param play_bytes, output the play/download bytes.
|
|
|
|
* @param publish_bytes, output the publish/upload bytes.
|
|
|
|
* @param play_duration, output the play/download test duration, in ms.
|
|
|
|
* @param publish_duration, output the publish/upload test duration, in ms.
|
2014-11-07 14:36:25 +00:00
|
|
|
*
|
|
|
|
* @return 0, success; otherswise, failed.
|
2014-07-13 08:10:06 +00:00
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_bandwidth_check(srs_rtmp_t rtmp,
|
2014-07-13 08:10:06 +00:00
|
|
|
int64_t* start_time, int64_t* end_time,
|
|
|
|
int* play_kbps, int* publish_kbps,
|
|
|
|
int* play_bytes, int* publish_bytes,
|
|
|
|
int* play_duration, int* publish_duration
|
|
|
|
);
|
|
|
|
|
2014-03-02 09:47:53 +00:00
|
|
|
/**
|
|
|
|
* E.4.1 FLV Tag, page 75
|
|
|
|
*/
|
|
|
|
// 8 = audio
|
|
|
|
#define SRS_RTMP_TYPE_AUDIO 8
|
|
|
|
// 9 = video
|
|
|
|
#define SRS_RTMP_TYPE_VIDEO 9
|
|
|
|
// 18 = script data
|
|
|
|
#define SRS_RTMP_TYPE_SCRIPT 18
|
|
|
|
/**
|
|
|
|
* convert the flv tag type to string.
|
2014-03-18 03:32:58 +00:00
|
|
|
* SRS_RTMP_TYPE_AUDIO to "Audio"
|
|
|
|
* SRS_RTMP_TYPE_VIDEO to "Video"
|
|
|
|
* SRS_RTMP_TYPE_SCRIPT to "Data"
|
|
|
|
* otherwise, "Unknown"
|
2014-06-07 05:44:46 +00:00
|
|
|
* @remark user never free the return char*,
|
|
|
|
* it's static shared const string.
|
2014-03-02 09:47:53 +00:00
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern const char* srs_type2string(int type);
|
2014-03-02 09:47:53 +00:00
|
|
|
/**
|
|
|
|
* read a audio/video/script-data packet from rtmp stream.
|
|
|
|
* @param type, output the packet type, macros:
|
2014-03-18 03:32:58 +00:00
|
|
|
* SRS_RTMP_TYPE_AUDIO, FlvTagAudio
|
|
|
|
* SRS_RTMP_TYPE_VIDEO, FlvTagVideo
|
|
|
|
* SRS_RTMP_TYPE_SCRIPT, FlvTagScript
|
2014-03-02 09:47:53 +00:00
|
|
|
* @param timestamp, in ms, overflow in 50days
|
|
|
|
* @param data, the packet data, according to type:
|
2014-03-18 03:32:58 +00:00
|
|
|
* FlvTagAudio, @see "E.4.2.1 AUDIODATA"
|
|
|
|
* FlvTagVideo, @see "E.4.3.1 VIDEODATA"
|
|
|
|
* FlvTagScript, @see "E.4.4.1 SCRIPTDATA"
|
2014-03-02 09:47:53 +00:00
|
|
|
* @param size, size of packet.
|
|
|
|
* @return the error code. 0 for success; otherwise, error.
|
|
|
|
*
|
|
|
|
* @remark: for read, user must free the data.
|
|
|
|
* @remark: for write, user should never free the data, even if error.
|
2014-11-08 05:16:56 +00:00
|
|
|
* @example /trunk/research/librtmp/srs_play.c
|
|
|
|
* @example /trunk/research/librtmp/srs_publish.c
|
2014-11-07 14:36:25 +00:00
|
|
|
*
|
|
|
|
* @return 0, success; otherswise, failed.
|
2014-03-02 09:47:53 +00:00
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_read_packet(srs_rtmp_t rtmp,
|
|
|
|
int* type, u_int32_t* timestamp, char** data, int* size
|
|
|
|
);
|
|
|
|
extern int srs_write_packet(srs_rtmp_t rtmp,
|
|
|
|
int type, u_int32_t timestamp, char* data, int size
|
|
|
|
);
|
2014-03-02 09:47:53 +00:00
|
|
|
|
2014-11-07 14:06:30 +00:00
|
|
|
// get protocol stack version
|
|
|
|
extern int srs_version_major();
|
|
|
|
extern int srs_version_minor();
|
|
|
|
extern int srs_version_revision();
|
2014-03-01 15:24:53 +00:00
|
|
|
|
2014-11-07 14:06:30 +00:00
|
|
|
/*************************************************************
|
|
|
|
**************************************************************
|
2014-05-20 10:11:33 +00:00
|
|
|
* utilities
|
2014-11-07 14:06:30 +00:00
|
|
|
**************************************************************
|
|
|
|
*************************************************************/
|
|
|
|
extern int64_t srs_get_time_ms();
|
|
|
|
extern int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp);
|
|
|
|
extern int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp);
|
2014-11-08 05:41:47 +00:00
|
|
|
|
|
|
|
// log to console, for use srs-librtmp application.
|
2014-11-08 05:35:38 +00:00
|
|
|
extern const char* srs_format_time();
|
2014-11-08 10:37:15 +00:00
|
|
|
#define srs_lib_trace(msg, ...) printf("[%s] ", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
|
|
|
|
#define srs_lib_verbose(msg, ...) printf("[%s] ", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
|
2014-11-07 14:06:30 +00:00
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
**************************************************************
|
2014-05-28 07:37:06 +00:00
|
|
|
* flv codec
|
2014-11-08 05:16:56 +00:00
|
|
|
* @example /trunk/research/librtmp/srs_flv_injecter.c
|
|
|
|
* @example /trunk/research/librtmp/srs_flv_parser.c
|
|
|
|
* @example /trunk/research/librtmp/srs_ingest_flv.c
|
|
|
|
* @example /trunk/research/librtmp/srs_ingest_rtmp.c
|
2014-11-07 14:06:30 +00:00
|
|
|
**************************************************************
|
|
|
|
*************************************************************/
|
2014-05-28 07:37:06 +00:00
|
|
|
typedef void* srs_flv_t;
|
|
|
|
typedef int flv_bool;
|
2014-06-29 09:12:10 +00:00
|
|
|
/* open flv file for both read/write. */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern srs_flv_t srs_flv_open_read(const char* file);
|
|
|
|
extern srs_flv_t srs_flv_open_write(const char* file);
|
|
|
|
extern void srs_flv_close(srs_flv_t flv);
|
2014-05-28 07:37:06 +00:00
|
|
|
/* read the flv header. 9bytes header. drop the 4bytes zero previous tag size */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_flv_read_header(srs_flv_t flv, char header[9]);
|
2014-05-28 07:37:06 +00:00
|
|
|
/* read the flv tag header, 1bytes tag, 3bytes data_size, 4bytes time, 3bytes stream id. */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_flv_read_tag_header(srs_flv_t flv,
|
|
|
|
char* ptype, int32_t* pdata_size, u_int32_t* ptime
|
|
|
|
);
|
2014-05-28 07:37:06 +00:00
|
|
|
/* read the tag data. drop the 4bytes previous tag size */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_flv_read_tag_data(srs_flv_t flv, char* data, int32_t size);
|
2014-05-28 11:01:47 +00:00
|
|
|
/* write flv header to file, auto write the 4bytes zero previous tag size. */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_flv_write_header(srs_flv_t flv, char header[9]);
|
2014-05-28 11:01:47 +00:00
|
|
|
/* write flv tag to file, auto write the 4bytes previous tag size */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_flv_write_tag(srs_flv_t flv, char type, int32_t time, char* data, int size);
|
2014-05-29 04:09:26 +00:00
|
|
|
/* get the tag size, for flv injecter to adjust offset, size=tag_header+data+previous_tag */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_flv_size_tag(int data_size);
|
2014-05-28 11:01:47 +00:00
|
|
|
/* file stream */
|
2014-05-28 07:37:06 +00:00
|
|
|
/* file stream tellg to get offset */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int64_t srs_flv_tellg(srs_flv_t flv);
|
2014-05-28 09:37:15 +00:00
|
|
|
/* seek file stream, offset is form the start of file */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern void srs_flv_lseek(srs_flv_t flv, int64_t offset);
|
2014-05-28 11:01:47 +00:00
|
|
|
/* error code */
|
2014-05-28 07:37:06 +00:00
|
|
|
/* whether the error code indicates EOF */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern flv_bool srs_flv_is_eof(int error_code);
|
2014-05-28 11:01:47 +00:00
|
|
|
/* media codec */
|
|
|
|
/* whether the video body is sequence header */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern flv_bool srs_flv_is_sequence_header(char* data, int32_t size);
|
2014-05-28 11:01:47 +00:00
|
|
|
/* whether the video body is keyframe */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern flv_bool srs_flv_is_keyframe(char* data, int32_t size);
|
2014-05-28 07:37:06 +00:00
|
|
|
|
2014-11-07 14:06:30 +00:00
|
|
|
/*************************************************************
|
|
|
|
**************************************************************
|
2014-05-21 10:30:58 +00:00
|
|
|
* amf0 codec
|
2014-11-08 05:16:56 +00:00
|
|
|
* @example /trunk/research/librtmp/srs_ingest_flv.c
|
|
|
|
* @example /trunk/research/librtmp/srs_ingest_rtmp.c
|
2014-11-07 14:06:30 +00:00
|
|
|
**************************************************************
|
|
|
|
*************************************************************/
|
2014-05-22 03:39:10 +00:00
|
|
|
/* the output handler. */
|
2014-05-21 10:30:58 +00:00
|
|
|
typedef void* srs_amf0_t;
|
2014-11-07 14:15:56 +00:00
|
|
|
typedef int srs_amf0_bool;
|
|
|
|
typedef double srs_amf0_number;
|
2014-11-07 14:06:30 +00:00
|
|
|
extern srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed);
|
2014-11-07 14:15:56 +00:00
|
|
|
extern srs_amf0_t srs_amf0_create_number(srs_amf0_number value);
|
2014-11-07 14:06:30 +00:00
|
|
|
extern srs_amf0_t srs_amf0_create_ecma_array();
|
|
|
|
extern srs_amf0_t srs_amf0_create_strict_array();
|
|
|
|
extern srs_amf0_t srs_amf0_create_object();
|
|
|
|
extern void srs_amf0_free(srs_amf0_t amf0);
|
|
|
|
extern void srs_amf0_free_bytes(char* data);
|
2014-05-28 11:01:47 +00:00
|
|
|
/* size and to bytes */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_amf0_size(srs_amf0_t amf0);
|
|
|
|
extern int srs_amf0_serialize(srs_amf0_t amf0, char* data, int size);
|
2014-05-22 03:39:10 +00:00
|
|
|
/* type detecter */
|
2014-11-07 14:15:56 +00:00
|
|
|
extern srs_amf0_bool srs_amf0_is_string(srs_amf0_t amf0);
|
|
|
|
extern srs_amf0_bool srs_amf0_is_boolean(srs_amf0_t amf0);
|
|
|
|
extern srs_amf0_bool srs_amf0_is_number(srs_amf0_t amf0);
|
|
|
|
extern srs_amf0_bool srs_amf0_is_null(srs_amf0_t amf0);
|
|
|
|
extern srs_amf0_bool srs_amf0_is_object(srs_amf0_t amf0);
|
|
|
|
extern srs_amf0_bool srs_amf0_is_ecma_array(srs_amf0_t amf0);
|
|
|
|
extern srs_amf0_bool srs_amf0_is_strict_array(srs_amf0_t amf0);
|
2014-05-22 03:39:10 +00:00
|
|
|
/* value converter */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern const char* srs_amf0_to_string(srs_amf0_t amf0);
|
2014-11-07 14:15:56 +00:00
|
|
|
extern srs_amf0_bool srs_amf0_to_boolean(srs_amf0_t amf0);
|
|
|
|
extern srs_amf0_number srs_amf0_to_number(srs_amf0_t amf0);
|
2014-05-29 04:09:26 +00:00
|
|
|
/* value setter */
|
2014-11-07 14:15:56 +00:00
|
|
|
extern void srs_amf0_set_number(srs_amf0_t amf0, srs_amf0_number value);
|
2014-05-22 07:08:25 +00:00
|
|
|
/* object value converter */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_amf0_object_property_count(srs_amf0_t amf0);
|
|
|
|
extern const char* srs_amf0_object_property_name_at(srs_amf0_t amf0, int index);
|
|
|
|
extern srs_amf0_t srs_amf0_object_property_value_at(srs_amf0_t amf0, int index);
|
|
|
|
extern srs_amf0_t srs_amf0_object_property(srs_amf0_t amf0, const char* name);
|
|
|
|
extern void srs_amf0_object_property_set(srs_amf0_t amf0, const char* name, srs_amf0_t value);
|
|
|
|
extern void srs_amf0_object_clear(srs_amf0_t amf0);
|
2014-05-22 08:29:42 +00:00
|
|
|
/* ecma array value converter */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_amf0_ecma_array_property_count(srs_amf0_t amf0);
|
|
|
|
extern const char* srs_amf0_ecma_array_property_name_at(srs_amf0_t amf0, int index);
|
|
|
|
extern srs_amf0_t srs_amf0_ecma_array_property_value_at(srs_amf0_t amf0, int index);
|
|
|
|
extern srs_amf0_t srs_amf0_ecma_array_property(srs_amf0_t amf0, const char* name);
|
|
|
|
extern void srs_amf0_ecma_array_property_set(srs_amf0_t amf0, const char* name, srs_amf0_t value);
|
2014-05-22 08:29:42 +00:00
|
|
|
/* strict array value converter */
|
2014-11-07 14:06:30 +00:00
|
|
|
extern int srs_amf0_strict_array_property_count(srs_amf0_t amf0);
|
|
|
|
extern srs_amf0_t srs_amf0_strict_array_property_at(srs_amf0_t amf0, int index);
|
|
|
|
extern void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value);
|
2014-05-28 07:37:06 +00:00
|
|
|
/**
|
|
|
|
* human readable print
|
2014-06-21 03:41:00 +00:00
|
|
|
* @param pdata, output the heap data, NULL to ignore.
|
2014-11-08 06:00:59 +00:00
|
|
|
* user must use srs_amf0_free_bytes to free it.
|
2014-06-21 03:41:00 +00:00
|
|
|
* @return return the *pdata for print. NULL to ignore.
|
2014-05-28 07:37:06 +00:00
|
|
|
*/
|
2014-11-07 14:06:30 +00:00
|
|
|
extern char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize);
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
**************************************************************
|
|
|
|
* h264 raw codec
|
|
|
|
**************************************************************
|
|
|
|
*************************************************************/
|
|
|
|
/**
|
2014-11-08 01:21:09 +00:00
|
|
|
* write h.264 raw frame over RTMP to rtmp server.
|
2014-11-08 02:28:59 +00:00
|
|
|
* @param frames the input h264 raw data, encoded h.264 I/P/B frames data.
|
|
|
|
* frames can be one or more than one frame,
|
|
|
|
* each frame prefixed h.264 annexb header, by N[00] 00 00 01, where N>=0,
|
|
|
|
* for instance, frame = header(00 00 00 01) + payload(67 42 80 29 95 A0 14 01 6E 40)
|
2014-11-08 02:44:00 +00:00
|
|
|
* about annexb, @see H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
|
2014-11-08 02:28:59 +00:00
|
|
|
* @paam frames_size the size of h264 raw data.
|
2014-11-08 04:36:00 +00:00
|
|
|
* assert frames_size > 0, at least has 1 bytes header.
|
2014-11-07 15:07:31 +00:00
|
|
|
* @param dts the dts of h.264 raw data.
|
|
|
|
* @param pts the pts of h.264 raw data.
|
2014-11-07 15:55:00 +00:00
|
|
|
*
|
2014-11-08 02:28:59 +00:00
|
|
|
* @remark, user should free the frames.
|
2014-11-07 15:55:00 +00:00
|
|
|
* @remark, the tbn of dts/pts is 1/1000 for RTMP, that is, in ms.
|
2014-11-08 04:36:00 +00:00
|
|
|
* @remark, cts = pts - dts
|
2014-11-08 05:16:56 +00:00
|
|
|
* @remark, use srs_h264_startswith_annexb to check whether frame is annexb format.
|
|
|
|
* @example /trunk/research/librtmp/srs_h264_raw_publish.c
|
2014-11-07 15:07:31 +00:00
|
|
|
*
|
|
|
|
* @return 0, success; otherswise, failed.
|
2014-11-07 14:06:30 +00:00
|
|
|
*/
|
2014-11-08 02:28:59 +00:00
|
|
|
/**
|
|
|
|
For the example file:
|
|
|
|
http://winlinvip.github.io/srs.release/3rdparty/720p.h264.raw
|
|
|
|
The data sequence is:
|
|
|
|
// SPS
|
|
|
|
000000016742802995A014016E40
|
|
|
|
// PPS
|
|
|
|
0000000168CE3880
|
|
|
|
// IFrame
|
|
|
|
0000000165B8041014C038008B0D0D3A071.....
|
|
|
|
// PFrame
|
|
|
|
0000000141E02041F8CDDC562BBDEFAD2F.....
|
|
|
|
User can send the SPS+PPS, then each frame:
|
|
|
|
// SPS+PPS
|
|
|
|
srs_write_h264_raw_frame('000000016742802995A014016E400000000168CE3880', size, dts, pts)
|
|
|
|
// IFrame
|
|
|
|
srs_write_h264_raw_frame('0000000165B8041014C038008B0D0D3A071......', size, dts, pts)
|
|
|
|
// PFrame
|
|
|
|
srs_write_h264_raw_frame('0000000141E02041F8CDDC562BBDEFAD2F......', size, dts, pts)
|
|
|
|
User also can send one by one:
|
|
|
|
// SPS
|
|
|
|
srs_write_h264_raw_frame('000000016742802995A014016E4', size, dts, pts)
|
|
|
|
// PPS
|
|
|
|
srs_write_h264_raw_frame('00000000168CE3880', size, dts, pts)
|
|
|
|
// IFrame
|
|
|
|
srs_write_h264_raw_frame('0000000165B8041014C038008B0D0D3A071......', size, dts, pts)
|
|
|
|
// PFrame
|
|
|
|
srs_write_h264_raw_frame('0000000141E02041F8CDDC562BBDEFAD2F......', size, dts, pts)
|
|
|
|
*/
|
|
|
|
extern int srs_write_h264_raw_frames(srs_rtmp_t rtmp,
|
|
|
|
char* frames, int frames_size, u_int32_t dts, u_int32_t pts
|
2014-11-07 14:06:30 +00:00
|
|
|
);
|
2014-11-07 15:07:31 +00:00
|
|
|
/**
|
|
|
|
* whether h264 raw data starts with the annexb,
|
|
|
|
* which bytes sequence matches N[00] 00 00 01, where N>=0.
|
|
|
|
* @param h264_raw_data the input h264 raw data, a encoded h.264 I/P/B frame data.
|
|
|
|
* @paam h264_raw_size the size of h264 raw data.
|
|
|
|
* @param pnb_start_code output the size of start code, must >=3.
|
|
|
|
* NULL to ignore.
|
|
|
|
*
|
2014-11-08 05:16:56 +00:00
|
|
|
* @reamrk used to check whether current frame is in annexb format.
|
|
|
|
* @example /trunk/research/librtmp/srs_h264_raw_publish.c
|
|
|
|
*
|
2014-11-07 15:07:31 +00:00
|
|
|
* @return 0 false; otherwise, true.
|
|
|
|
*/
|
|
|
|
extern int srs_h264_startswith_annexb(
|
|
|
|
char* h264_raw_data, int h264_raw_size,
|
|
|
|
int* pnb_start_code
|
|
|
|
);
|
2014-05-20 10:11:33 +00:00
|
|
|
|
2014-03-01 15:24:53 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-01 11:15:36 +00:00
|
|
|
#endif
|
2014-08-02 14:18:39 +00:00
|
|
|
|