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

Refine srs-librtmp, set the schema, rather that connect app3

This commit is contained in:
winlin 2017-02-28 14:07:14 +08:00
parent 4e96c443d8
commit 89a5fa69d1
5 changed files with 65 additions and 61 deletions

View file

@ -72,6 +72,7 @@ struct Context
std::string app;
std::string stream;
std::string param;
srs_url_schema schema;
// extra request object for connect to server, NULL to ignore.
SrsRequest* req;
@ -122,6 +123,7 @@ struct Context
h264_sps_changed = false;
h264_pps_changed = false;
rtimeout = stimeout = SRS_CONSTS_NO_TMMS;
schema = srs_url_schema_forbidden;
}
virtual ~Context() {
srs_freep(req);
@ -741,11 +743,22 @@ int srs_rtmp_connect_app(srs_rtmp_t rtmp)
srs_assert(rtmp != NULL);
Context* context = (Context*)rtmp;
string tcUrl = srs_generate_tc_url(
context->ip, context->vhost, context->app, context->port,
context->param
);
string tcUrl;
switch(context->schema) {
case srs_url_schema_normal:
tcUrl=srs_generate_normal_tc_url(context->ip, context->vhost, context->app, context->port);
break;
case srs_url_schema_via:
tcUrl=srs_generate_via_tc_url(context->ip, context->vhost, context->app, context->port);
break;
case srs_url_schema_vis:
case srs_url_schema_vis2:
tcUrl=srs_generate_vis_tc_url(context->ip, context->vhost, context->app, context->port);
break;
default:
break;
}
if ((ret = context->rtmp->connect_app(
context->app, tcUrl, context->req, true)) != ERROR_SUCCESS)
@ -774,10 +787,21 @@ int srs_rtmp_connect_app2(srs_rtmp_t rtmp,
srs_assert(rtmp != NULL);
Context* context = (Context*)rtmp;
string tcUrl = srs_generate_tc_url(
context->ip, context->vhost, context->app, context->port,
context->param
);
string tcUrl;
switch(context->schema) {
case srs_url_schema_normal:
tcUrl=srs_generate_normal_tc_url(context->ip, context->vhost, context->app, context->port);
break;
case srs_url_schema_via:
tcUrl=srs_generate_via_tc_url(context->ip, context->vhost, context->app, context->port);
break;
case srs_url_schema_vis:
case srs_url_schema_vis2:
tcUrl=srs_generate_vis_tc_url(context->ip, context->vhost, context->app, context->port);
break;
default:
break;
}
std::string sip, sserver, sprimary, sauthors, sversion;
@ -795,34 +819,14 @@ int srs_rtmp_connect_app2(srs_rtmp_t rtmp,
return ret;
}
int srs_rtmp_connect_app3(srs_rtmp_t rtmp, enum srs_url_schema sus)
int srs_rtmp_set_schema(srs_rtmp_t rtmp, enum srs_url_schema schema)
{
int ret = ERROR_SUCCESS;
srs_assert(rtmp != NULL);
Context* context = (Context*)rtmp;
string tcUrl;
switch(sus) {
case srs_url_schema_normal:
tcUrl=srs_generate_normal_tc_url(context->ip, context->vhost, context->app, context->port);
break;
case srs_url_schema_via:
tcUrl=srs_generate_via_tc_url(context->ip, context->vhost, context->app, context->port);
break;
case srs_url_schema_vis:
case srs_url_schema_vis2:
tcUrl=srs_generate_vis_tc_url(context->ip, context->vhost, context->app, context->port);
break;
default:
break;
}
if ((ret = context->rtmp->connect_app(
context->app, tcUrl, context->req, true)) != ERROR_SUCCESS)
{
return ret;
}
context->schema = schema;
return ret;
}

View file

@ -79,10 +79,13 @@ extern "C"{
* srs_url_schema_vis : rtmp://ip:port/app/stream?vhost=xxx
* srs_url_schema_vis2 : rtmp://ip:port/app/stream?domain=xxx
*/
enum srs_url_schema{
enum srs_url_schema
{
// Forbidden.
srs_url_schema_forbidden = 0,
// Normal RTMP URL, the vhost put in host field, using DNS to resolve the server ip.
// For example, rtmp://vhost:port/app/stream
srs_url_schema_normal = 0,
srs_url_schema_normal,
// VIA(vhost in app), the vhost put in app field.
// For example, rtmp://ip:port/vhost/app/stream
srs_url_schema_via,
@ -225,16 +228,13 @@ extern int srs_rtmp_connect_app2(srs_rtmp_t rtmp,
char srs_primary[128], char srs_authors[128],
char srs_version[32], int* srs_id, int* srs_pid
);
/**
* connect to rtmp vhost/app
* category: publish/play
* previous: handshake
* next: publish or play
*
* @return 0, success; otherswise, failed.
*/
extern int srs_rtmp_connect_app3(srs_rtmp_t rtmp, enum srs_url_schema sus);
* Set the schema of URL when connect to server.
* @param schema, The schema of URL, @see srs_url_schema.
* @return 0, success; otherswise, failed.
*/
extern int srs_rtmp_set_schema(srs_rtmp_t rtmp, enum srs_url_schema schema);
/**
* play a live/vod stream.