1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for bug #215, srs rtmp dump support conn args. 2.0.90

This commit is contained in:
winlin 2015-01-07 13:29:30 +08:00
parent 4c18234678
commit 0e03d019a8
6 changed files with 296 additions and 41 deletions

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 89
#define VERSION_REVISION 90
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
#define RTMP_SIG_SRS_ROLE "origin/edge server"

View file

@ -66,6 +66,9 @@ struct Context
std::string app;
std::string stream;
std::string param;
// extra request object for connect to server, NULL to ignore.
SrsRequest* req;
SrsRtmpClient* rtmp;
SimpleSocketStream* skt;
@ -93,12 +96,14 @@ struct Context
Context() {
rtmp = NULL;
skt = NULL;
req = NULL;
stream_id = 0;
h264_sps_pps_sent = false;
h264_sps_changed = false;
h264_pps_changed = false;
}
virtual ~Context() {
srs_freep(req);
srs_freep(rtmp);
srs_freep(skt);
}
@ -595,6 +600,53 @@ int __srs_rtmp_connect_server(srs_rtmp_t rtmp)
return ret;
}
int __srs_rtmp_do_complex_handshake(srs_rtmp_t rtmp)
{
int ret = ERROR_SUCCESS;
srs_assert(rtmp != NULL);
Context* context = (Context*)rtmp;
srs_assert(context->skt != NULL);
// simple handshake
srs_freep(context->rtmp);
context->rtmp = new SrsRtmpClient(context->skt);
if ((ret = context->rtmp->complex_handshake()) != ERROR_SUCCESS) {
return ret;
}
return ret;
}
int srs_rtmp_set_connect_args(srs_rtmp_t rtmp,
const char* tcUrl, const char* swfUrl, const char* pageUrl, srs_amf0_t args
) {
int ret = ERROR_SUCCESS;
srs_assert(rtmp != NULL);
Context* context = (Context*)rtmp;
srs_freep(context->req);
context->req = new SrsRequest();
if (args) {
context->req->args = (SrsAmf0Object*)args;
}
if (tcUrl) {
context->req->tcUrl = tcUrl;
}
if (swfUrl) {
context->req->swfUrl = swfUrl;
}
if (pageUrl) {
context->req->pageUrl = pageUrl;
}
return ret;
}
int __srs_rtmp_do_simple_handshake(srs_rtmp_t rtmp)
{
int ret = ERROR_SUCCESS;
@ -628,7 +680,7 @@ int srs_rtmp_connect_app(srs_rtmp_t rtmp)
);
if ((ret = context->rtmp->connect_app(
context->app, tcUrl, NULL, true)) != ERROR_SUCCESS)
context->app, tcUrl, context->req, true)) != ERROR_SUCCESS)
{
return ret;
}
@ -1725,6 +1777,11 @@ srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed)
return amf0;
}
srs_amf0_t srs_amf0_create_string(const char* value)
{
return SrsAmf0Any::str(value);
}
srs_amf0_t srs_amf0_create_number(srs_amf0_number value)
{
return SrsAmf0Any::number(value);
@ -2374,6 +2431,9 @@ int srs_human_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int
u_int32_t pts;
if (srs_utils_parse_timestamp(timestamp, type, data, size, &pts) != 0) {
srs_human_trace("Video packet type=%s, dts=%d, pts=%d, size=%d, DecodeError",
srs_human_flv_tag_type2string(type), timestamp, pts, size
);
return ret;
}

View file

@ -86,6 +86,7 @@ extern int srs_version_revision();
*************************************************************/
// the RTMP handler.
typedef void* srs_rtmp_t;
typedef void* srs_amf0_t;
/**
* create/destroy a rtmp protocol stack.
@ -142,6 +143,18 @@ extern int __srs_rtmp_dns_resolve(srs_rtmp_t rtmp);
extern int __srs_rtmp_connect_server(srs_rtmp_t rtmp);
// do simple handshake over socket.
extern int __srs_rtmp_do_simple_handshake(srs_rtmp_t rtmp);
// do complex handshake over socket.
extern int __srs_rtmp_do_complex_handshake(srs_rtmp_t rtmp);
/**
* set the args of connect packet for rtmp.
* @param args, the extra amf0 object args.
* @remark, all params can be NULL to ignore.
* @remark, user should never free the args for we directly use it.
*/
extern int srs_rtmp_set_connect_args(srs_rtmp_t rtmp,
const char* tcUrl, const char* swfUrl, const char* pageUrl, srs_amf0_t args
);
/**
* connect to rtmp vhost/app
@ -546,7 +559,6 @@ extern srs_bool srs_flv_is_keyframe(char* data, int32_t size);
**************************************************************
*************************************************************/
/* the output handler. */
typedef void* srs_amf0_t;
typedef double srs_amf0_number;
/**
* parse amf0 from data.
@ -555,6 +567,7 @@ typedef double srs_amf0_number;
* @remark user must free the parsed or created object by srs_amf0_free.
*/
extern srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed);
extern srs_amf0_t srs_amf0_create_string(const char* value);
extern srs_amf0_t srs_amf0_create_number(srs_amf0_number value);
extern srs_amf0_t srs_amf0_create_ecma_array();
extern srs_amf0_t srs_amf0_create_strict_array();

View file

@ -469,13 +469,17 @@ int SrsRtmpClient::connect_app2(
SrsConnectAppPacket* pkt = new SrsConnectAppPacket();
pkt->command_object->set("app", SrsAmf0Any::str(app.c_str()));
pkt->command_object->set("flashVer", SrsAmf0Any::str("WIN 12,0,0,41"));
pkt->command_object->set("flashVer", SrsAmf0Any::str("WIN 15,0,0,239"));
if (req) {
pkt->command_object->set("swfUrl", SrsAmf0Any::str(req->swfUrl.c_str()));
} else {
pkt->command_object->set("swfUrl", SrsAmf0Any::str());
}
pkt->command_object->set("tcUrl", SrsAmf0Any::str(tc_url.c_str()));
if (req && req->tcUrl != "") {
pkt->command_object->set("tcUrl", SrsAmf0Any::str(req->tcUrl.c_str()));
} else {
pkt->command_object->set("tcUrl", SrsAmf0Any::str(tc_url.c_str()));
}
pkt->command_object->set("fpad", SrsAmf0Any::boolean(false));
pkt->command_object->set("capabilities", SrsAmf0Any::number(239));
pkt->command_object->set("audioCodecs", SrsAmf0Any::number(3575));

View file

@ -31,7 +31,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_buffer.hpp>
#include <srs_protocol_utility.hpp>
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#ifndef _WIN32
#include <unistd.h>
#endif
#include <stdlib.h>
using namespace std;
@ -868,9 +872,14 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs)
int SrsProtocol::do_iovs_send(iovec* iovs, int size)
{
int ret = ERROR_SUCCESS;
// the limits of writev iovs.
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#ifndef _WIN32
static int limits = sysconf(_SC_IOV_MAX);
#else
static int limits = 1024;
#endif
// send in a time.
if (size < limits) {