AI: Fix naming issue for protocol module. v7.0.83 (#4482)

Co-authored-by: OSSRS-AI <winlinam@gmail.com>
This commit is contained in:
Winlin 2025-09-09 21:06:45 -04:00 committed by GitHub
parent 8f87d4092b
commit 3a29e5c550
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
67 changed files with 2872 additions and 2871 deletions

View File

@ -185,7 +185,7 @@ code_patterns:
public: public:
srs_error_t initialize(); srs_error_t initialize();
}; };
scope: "Applies ONLY to fields (member variables) in classes and structs - NOT to functions, methods, or parameters" scope: "Applies ONLY to fields (member variables) in classes and structs - NOT to functions, methods, comments, error messages, or parameters"
exceptions: "Only applies to SRS-defined classes/structs - do NOT change 3rd party code like llhttp" exceptions: "Only applies to SRS-defined classes/structs - do NOT change 3rd party code like llhttp"
rationale: "Consistent naming convention across SRS codebase for better code readability and maintenance - underscore distinguishes member variables from local variables and parameters" rationale: "Consistent naming convention across SRS codebase for better code readability and maintenance - underscore distinguishes member variables from local variables and parameters"

View File

@ -7,6 +7,7 @@ The changelog for SRS.
<a name="v7-changes"></a> <a name="v7-changes"></a>
## SRS 7.0 Changelog ## SRS 7.0 Changelog
* v7.0, 2025-09-09, Merge [#4482](https://github.com/ossrs/srs/pull/4482): AI: Fix naming issue for protocol module. v7.0.83 (#4482)
* v7.0, 2025-09-07, Merge [#4479](https://github.com/ossrs/srs/pull/4479): AI: Fix naming problem in kernel module. v7.0.82 (#4479) * v7.0, 2025-09-07, Merge [#4479](https://github.com/ossrs/srs/pull/4479): AI: Fix naming problem in kernel module. v7.0.82 (#4479)
* v7.0, 2025-09-06, Merge [#4478](https://github.com/ossrs/srs/pull/4478): AI: Add more utests for kernel module. v7.0.81 (#4478) * v7.0, 2025-09-06, Merge [#4478](https://github.com/ossrs/srs/pull/4478): AI: Add more utests for kernel module. v7.0.81 (#4478)
* v7.0, 2025-09-06, Merge [#4475](https://github.com/ossrs/srs/pull/4475): AI: Support anonymous coroutine with code block. v7.0.80 (#4475) * v7.0, 2025-09-06, Merge [#4475](https://github.com/ossrs/srs/pull/4475): AI: Support anonymous coroutine with code block. v7.0.80 (#4475)

View File

@ -355,7 +355,7 @@ bool srs_config_apply_filter(SrsConfDirective *dvr_apply, ISrsRequest *req)
return true; return true;
} }
string id = req->app + "/" + req->stream; string id = req->app_ + "/" + req->stream_;
if (std::find(args.begin(), args.end(), id) != args.end()) { if (std::find(args.begin(), args.end(), id) != args.end()) {
return true; return true;
} }

View File

@ -98,7 +98,7 @@ SrsJsonAny *SrsCoWorkers::dumps(string vhost, string coworker, string app, strin
return SrsJsonAny::object() return SrsJsonAny::object()
->set("ip", SrsJsonAny::str(service_ip.c_str())) ->set("ip", SrsJsonAny::str(service_ip.c_str()))
->set("port", SrsJsonAny::integer(listen_port)) ->set("port", SrsJsonAny::integer(listen_port))
->set("vhost", SrsJsonAny::str(r->vhost.c_str())) ->set("vhost", SrsJsonAny::str(r->vhost_.c_str()))
->set("api", SrsJsonAny::str(backend.c_str())) ->set("api", SrsJsonAny::str(backend.c_str()))
->set("routers", routers); ->set("routers", routers);
} }

View File

@ -91,7 +91,7 @@ srs_error_t SrsFragmentedMp4::initialize(ISrsRequest *r, bool video, int64_t tim
(uint32_t)sequence_number, file_home.c_str(), file_name.c_str()); (uint32_t)sequence_number, file_home.c_str(), file_name.c_str());
} }
string home = _srs_config->get_dash_path(r->vhost); string home = _srs_config->get_dash_path(r->vhost_);
set_path(home + "/" + file_home + "/" + file_name); set_path(home + "/" + file_home + "/" + file_name);
// Set number of the fragment, use in mpd SegmentTemplate@startNumber later. // Set number of the fragment, use in mpd SegmentTemplate@startNumber later.
set_number(sequence_number); set_number(sequence_number);
@ -177,7 +177,7 @@ SrsMpdWriter::~SrsMpdWriter()
void SrsMpdWriter::dispose() void SrsMpdWriter::dispose()
{ {
if (req) { if (req) {
string mpd_path = srs_path_build_stream(mpd_file, req->vhost, req->app, req->stream); string mpd_path = srs_path_build_stream(mpd_file, req->vhost_, req->app_, req->stream_);
string full_path = home + "/" + mpd_path; string full_path = home + "/" + mpd_path;
if (unlink(full_path.c_str()) < 0) { if (unlink(full_path.c_str()) < 0) {
srs_warn("ignore remove mpd failed, %s", full_path.c_str()); srs_warn("ignore remove mpd failed, %s", full_path.c_str());
@ -201,15 +201,15 @@ srs_error_t SrsMpdWriter::on_publish()
{ {
ISrsRequest *r = req; ISrsRequest *r = req;
fragment = _srs_config->get_dash_fragment(r->vhost); fragment = _srs_config->get_dash_fragment(r->vhost_);
update_period = _srs_config->get_dash_update_period(r->vhost); update_period = _srs_config->get_dash_update_period(r->vhost_);
timeshit = _srs_config->get_dash_timeshift(r->vhost); timeshit = _srs_config->get_dash_timeshift(r->vhost_);
home = _srs_config->get_dash_path(r->vhost); home = _srs_config->get_dash_path(r->vhost_);
mpd_file = _srs_config->get_dash_mpd_file(r->vhost); mpd_file = _srs_config->get_dash_mpd_file(r->vhost_);
string mpd_path = srs_path_build_stream(mpd_file, req->vhost, req->app, req->stream); string mpd_path = srs_path_build_stream(mpd_file, req->vhost_, req->app_, req->stream_);
fragment_home = srs_path_filepath_dir(mpd_path) + "/" + req->stream; fragment_home = srs_path_filepath_dir(mpd_path) + "/" + req->stream_;
window_size_ = _srs_config->get_dash_window_size(r->vhost); window_size_ = _srs_config->get_dash_window_size(r->vhost_);
srs_trace("DASH: Config fragment=%dms, period=%dms, window=%d, timeshit=%dms, home=%s, mpd=%s", srs_trace("DASH: Config fragment=%dms, period=%dms, window=%d, timeshit=%dms, home=%s, mpd=%s",
srsu2msi(fragment), srsu2msi(update_period), window_size_, srsu2msi(timeshit), home.c_str(), mpd_file.c_str()); srsu2msi(fragment), srsu2msi(update_period), window_size_, srsu2msi(timeshit), home.c_str(), mpd_file.c_str());
@ -230,11 +230,11 @@ srs_error_t SrsMpdWriter::write(SrsFormat *format, SrsFragmentWindow *afragments
return err; return err;
} }
string mpd_path = srs_path_build_stream(mpd_file, req->vhost, req->app, req->stream); string mpd_path = srs_path_build_stream(mpd_file, req->vhost_, req->app_, req->stream_);
string full_path = home + "/" + mpd_path; string full_path = home + "/" + mpd_path;
string full_home = srs_path_filepath_dir(full_path); string full_home = srs_path_filepath_dir(full_path);
fragment_home = srs_path_filepath_dir(mpd_path) + "/" + req->stream; fragment_home = srs_path_filepath_dir(mpd_path) + "/" + req->stream_;
if ((err = srs_os_mkdir_all(full_home)) != srs_success) { if ((err = srs_os_mkdir_all(full_home)) != srs_success) {
return srs_error_wrap(err, "Create MPD home failed, home=%s", full_home.c_str()); return srs_error_wrap(err, "Create MPD home failed, home=%s", full_home.c_str());
@ -254,7 +254,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat *format, SrsFragmentWindow *afragments
<< " publishTime=\"" << srs_time_to_utc_format_str(srs_time_now_cached()) << "\" " << endl << " publishTime=\"" << srs_time_to_utc_format_str(srs_time_now_cached()) << "\" " << endl
<< " minBufferTime=\"PT" << srs_fmt_sprintf("%.3f", 2 * last_duration) << "S\" >" << endl; << " minBufferTime=\"PT" << srs_fmt_sprintf("%.3f", 2 * last_duration) << "S\" >" << endl;
ss << " <BaseURL>" << req->stream << "/" << "</BaseURL>" << endl; ss << " <BaseURL>" << req->stream_ << "/" << "</BaseURL>" << endl;
ss << " <Period start=\"PT0S\">" << endl; ss << " <Period start=\"PT0S\">" << endl;
@ -425,8 +425,8 @@ srs_error_t SrsDashController::on_publish()
ISrsRequest *r = req; ISrsRequest *r = req;
fragment = _srs_config->get_dash_fragment(r->vhost); fragment = _srs_config->get_dash_fragment(r->vhost_);
home = _srs_config->get_dash_path(r->vhost); home = _srs_config->get_dash_path(r->vhost_);
if ((err = mpd->on_publish()) != srs_success) { if ((err = mpd->on_publish()) != srs_success) {
return srs_error_wrap(err, "mpd"); return srs_error_wrap(err, "mpd");
@ -531,8 +531,8 @@ srs_error_t SrsDashController::on_audio(SrsMediaPacket *shared_audio, SrsFormat
return srs_error_wrap(err, "Write audio to fragment failed"); return srs_error_wrap(err, "Write audio to fragment failed");
} }
srs_utime_t fragment = _srs_config->get_dash_fragment(req->vhost); srs_utime_t fragment = _srs_config->get_dash_fragment(req->vhost_);
int window_size = _srs_config->get_dash_window_size(req->vhost); int window_size = _srs_config->get_dash_window_size(req->vhost_);
int dash_window = 2 * window_size * fragment; int dash_window = 2 * window_size * fragment;
if (afragments->size() > window_size) { if (afragments->size() > window_size) {
int w = 0; int w = 0;
@ -545,7 +545,7 @@ srs_error_t SrsDashController::on_audio(SrsMediaPacket *shared_audio, SrsFormat
afragments->shrink(dash_window); afragments->shrink(dash_window);
} }
bool dash_cleanup = _srs_config->get_dash_cleanup(req->vhost); bool dash_cleanup = _srs_config->get_dash_cleanup(req->vhost_);
// remove the m4s file. // remove the m4s file.
afragments->clear_expired(dash_cleanup); afragments->clear_expired(dash_cleanup);
@ -604,8 +604,8 @@ srs_error_t SrsDashController::on_video(SrsMediaPacket *shared_video, SrsFormat
return srs_error_wrap(err, "Write video to fragment failed"); return srs_error_wrap(err, "Write video to fragment failed");
} }
srs_utime_t fragment = _srs_config->get_dash_fragment(req->vhost); srs_utime_t fragment = _srs_config->get_dash_fragment(req->vhost_);
int window_size = _srs_config->get_dash_window_size(req->vhost); int window_size = _srs_config->get_dash_window_size(req->vhost_);
int dash_window = 2 * window_size * fragment; int dash_window = 2 * window_size * fragment;
if (vfragments->size() > window_size) { if (vfragments->size() > window_size) {
int w = 0; int w = 0;
@ -618,7 +618,7 @@ srs_error_t SrsDashController::on_video(SrsMediaPacket *shared_video, SrsFormat
vfragments->shrink(dash_window); vfragments->shrink(dash_window);
} }
bool dash_cleanup = _srs_config->get_dash_cleanup(req->vhost); bool dash_cleanup = _srs_config->get_dash_cleanup(req->vhost_);
// remove the m4s file. // remove the m4s file.
vfragments->clear_expired(dash_cleanup); vfragments->clear_expired(dash_cleanup);
@ -650,7 +650,7 @@ srs_error_t SrsDashController::refresh_init_mp4(SrsMediaPacket *msg, SrsFormat *
return err; return err;
} }
string full_home = home + "/" + req->app + "/" + req->stream; string full_home = home + "/" + req->app_ + "/" + req->stream_;
if ((err = srs_os_mkdir_all(full_home)) != srs_success) { if ((err = srs_os_mkdir_all(full_home)) != srs_success) {
return srs_error_wrap(err, "Create media home failed, home=%s", full_home.c_str()); return srs_error_wrap(err, "Create media home failed, home=%s", full_home.c_str());
} }
@ -703,7 +703,7 @@ void SrsDash::dispose()
} }
// Ignore when dash_dispose disabled. // Ignore when dash_dispose disabled.
srs_utime_t dash_dispose = _srs_config->get_dash_dispose(req->vhost); srs_utime_t dash_dispose = _srs_config->get_dash_dispose(req->vhost_);
if (!dash_dispose) { if (!dash_dispose) {
return; return;
} }
@ -723,7 +723,7 @@ srs_error_t SrsDash::cycle()
return err; return err;
} }
srs_utime_t dash_dispose = _srs_config->get_dash_dispose(req->vhost); srs_utime_t dash_dispose = _srs_config->get_dash_dispose(req->vhost_);
if (dash_dispose <= 0) { if (dash_dispose <= 0) {
return err; return err;
} }
@ -746,7 +746,7 @@ srs_error_t SrsDash::cycle()
srs_utime_t SrsDash::cleanup_delay() srs_utime_t SrsDash::cleanup_delay()
{ {
// We use larger timeout to cleanup the HLS, after disposed it if required. // We use larger timeout to cleanup the HLS, after disposed it if required.
return _srs_config->get_dash_dispose(req->vhost) * 1.1; return _srs_config->get_dash_dispose(req->vhost_) * 1.1;
} }
// CRITICAL: This method is called AFTER the source has been added to the source pool // CRITICAL: This method is called AFTER the source has been added to the source pool
@ -778,7 +778,7 @@ srs_error_t SrsDash::on_publish()
return err; return err;
} }
if (!_srs_config->get_dash_enabled(req->vhost)) { if (!_srs_config->get_dash_enabled(req->vhost_)) {
return err; return err;
} }
enabled = true; enabled = true;

View File

@ -62,8 +62,8 @@ srs_error_t SrsDvrSegmenter::initialize(SrsDvrPlan *p, ISrsRequest *r)
req = r; req = r;
plan = p; plan = p;
jitter_algorithm = (SrsRtmpJitterAlgorithm)_srs_config->get_dvr_time_jitter(req->vhost); jitter_algorithm = (SrsRtmpJitterAlgorithm)_srs_config->get_dvr_time_jitter(req->vhost_);
wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost); wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost_);
return srs_success; return srs_success;
} }
@ -113,7 +113,7 @@ srs_error_t SrsDvrSegmenter::open()
return srs_error_wrap(err, "open encoder"); return srs_error_wrap(err, "open encoder");
} }
srs_trace("dvr stream %s to file %s", req->stream.c_str(), path.c_str()); srs_trace("dvr stream %s to file %s", req->stream_.c_str(), path.c_str());
return err; return err;
} }
@ -200,7 +200,7 @@ string SrsDvrSegmenter::generate_path()
{ {
// the path in config, for example, // the path in config, for example,
// /data/[vhost]/[app]/[stream]/[2006]/[01]/[02]/[15].[04].[05].[999].flv // /data/[vhost]/[app]/[stream]/[2006]/[01]/[02]/[15].[04].[05].[999].flv
std::string path_config = _srs_config->get_dvr_path(req->vhost); std::string path_config = _srs_config->get_dvr_path(req->vhost_);
// add [stream].[timestamp].flv as filename for dir // add [stream].[timestamp].flv as filename for dir
if (!srs_strings_ends_with(path_config, ".flv", ".mp4")) { if (!srs_strings_ends_with(path_config, ".flv", ".mp4")) {
@ -209,7 +209,7 @@ string SrsDvrSegmenter::generate_path()
// the flv file path // the flv file path
std::string flv_path = path_config; std::string flv_path = path_config;
flv_path = srs_path_build_stream(flv_path, req->vhost, req->app, req->stream); flv_path = srs_path_build_stream(flv_path, req->vhost_, req->app_, req->stream_);
flv_path = srs_path_build_timestamp(flv_path); flv_path = srs_path_build_timestamp(flv_path);
return flv_path; return flv_path;
@ -525,7 +525,7 @@ srs_error_t SrsDvrAsyncCallOnDvr::call()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -535,7 +535,7 @@ srs_error_t SrsDvrAsyncCallOnDvr::call()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_dvr(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_dvr(req->vhost_);
if (conf) { if (conf) {
hooks = conf->args; hooks = conf->args;
} }
@ -554,7 +554,7 @@ srs_error_t SrsDvrAsyncCallOnDvr::call()
string SrsDvrAsyncCallOnDvr::to_string() string SrsDvrAsyncCallOnDvr::to_string()
{ {
std::stringstream ss; std::stringstream ss;
ss << "vhost=" << req->vhost << ", file=" << path; ss << "vhost=" << req->vhost_ << ", file=" << path;
return ss.str(); return ss.str();
} }
@ -706,7 +706,7 @@ srs_error_t SrsDvrSessionPlan::on_publish(ISrsRequest *r)
return err; return err;
} }
if (!_srs_config->get_dvr_enabled(req->vhost)) { if (!_srs_config->get_dvr_enabled(req->vhost_)) {
return err; return err;
} }
@ -763,9 +763,9 @@ srs_error_t SrsDvrSegmentPlan::initialize(SrsOriginHub *h, SrsDvrSegmenter *s, I
return srs_error_wrap(err, "segment plan"); return srs_error_wrap(err, "segment plan");
} }
wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost); wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost_);
cduration = _srs_config->get_dvr_duration(req->vhost); cduration = _srs_config->get_dvr_duration(req->vhost_);
return srs_success; return srs_success;
} }
@ -783,7 +783,7 @@ srs_error_t SrsDvrSegmentPlan::on_publish(ISrsRequest *r)
return err; return err;
} }
if (!_srs_config->get_dvr_enabled(req->vhost)) { if (!_srs_config->get_dvr_enabled(req->vhost_)) {
return err; return err;
} }
@ -934,15 +934,15 @@ srs_error_t SrsDvr::initialize(SrsOriginHub *h, ISrsRequest *r)
req = r->copy(); req = r->copy();
hub = h; hub = h;
SrsConfDirective *conf = _srs_config->get_dvr_apply(r->vhost); SrsConfDirective *conf = _srs_config->get_dvr_apply(r->vhost_);
actived = srs_config_apply_filter(conf, r); actived = srs_config_apply_filter(conf, r);
srs_freep(plan); srs_freep(plan);
if ((err = SrsDvrPlan::create_plan(r->vhost, &plan)) != srs_success) { if ((err = SrsDvrPlan::create_plan(r->vhost_, &plan)) != srs_success) {
return srs_error_wrap(err, "create plan"); return srs_error_wrap(err, "create plan");
} }
std::string path = _srs_config->get_dvr_path(r->vhost); std::string path = _srs_config->get_dvr_path(r->vhost_);
SrsDvrSegmenter *segmenter = NULL; SrsDvrSegmenter *segmenter = NULL;
if (srs_strings_ends_with(path, ".mp4")) { if (srs_strings_ends_with(path, ".mp4")) {
segmenter = new SrsDvrMp4Segmenter(); segmenter = new SrsDvrMp4Segmenter();

View File

@ -70,12 +70,12 @@ srs_error_t SrsEdgeRtmpUpstream::connect(ISrsRequest *r, ISrsLbRoundRobin *lb)
std::string url; std::string url;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_edge_origin(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_edge_origin(req->vhost_);
// when origin is error, for instance, server is shutdown, // when origin is error, for instance, server is shutdown,
// then user remove the vhost then reload, the conf is empty. // then user remove the vhost then reload, the conf is empty.
if (!conf) { if (!conf) {
return srs_error_new(ERROR_EDGE_VHOST_REMOVED, "vhost %s removed", req->vhost.c_str()); return srs_error_new(ERROR_EDGE_VHOST_REMOVED, "vhost %s removed", req->vhost_.c_str());
} }
// select the origin. // select the origin.
@ -98,10 +98,10 @@ srs_error_t SrsEdgeRtmpUpstream::connect(ISrsRequest *r, ISrsLbRoundRobin *lb)
selected_port = port; selected_port = port;
// support vhost tranform for edge, // support vhost tranform for edge,
std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost); std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost_);
vhost = srs_strings_replace(vhost, "[vhost]", req->vhost); vhost = srs_strings_replace(vhost, "[vhost]", req->vhost_);
url = srs_net_url_encode_rtmp_url(server, port, req->host, vhost, req->app, req->stream, req->param); url = srs_net_url_encode_rtmp_url(server, port, req->host_, vhost, req->app_, req->stream_, req->param_);
} }
srs_freep(sdk); srs_freep(sdk);
@ -116,11 +116,11 @@ srs_error_t SrsEdgeRtmpUpstream::connect(ISrsRequest *r, ISrsLbRoundRobin *lb)
// For RTMP client, we pass the vhost in tcUrl when connecting, // For RTMP client, we pass the vhost in tcUrl when connecting,
// so we publish without vhost in stream. // so we publish without vhost in stream.
string stream; string stream;
if ((err = sdk->play(_srs_config->get_chunk_size(req->vhost), false, &stream)) != srs_success) { if ((err = sdk->play(_srs_config->get_chunk_size(req->vhost_), false, &stream)) != srs_success) {
return srs_error_wrap(err, "edge pull %s stream failed", url.c_str()); return srs_error_wrap(err, "edge pull %s stream failed", url.c_str());
} }
srs_trace("edge-pull publish url %s, stream=%s%s as %s", url.c_str(), req->stream.c_str(), req->param.c_str(), stream.c_str()); srs_trace("edge-pull publish url %s, stream=%s%s as %s", url.c_str(), req->stream_.c_str(), req->param_.c_str(), stream.c_str());
return err; return err;
} }
@ -192,12 +192,12 @@ srs_error_t SrsEdgeFlvUpstream::do_connect(ISrsRequest *r, ISrsLbRoundRobin *lb,
ISrsRequest *req = r; ISrsRequest *req = r;
if (redirect_depth == 0) { if (redirect_depth == 0) {
SrsConfDirective *conf = _srs_config->get_vhost_edge_origin(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_edge_origin(req->vhost_);
// when origin is error, for instance, server is shutdown, // when origin is error, for instance, server is shutdown,
// then user remove the vhost then reload, the conf is empty. // then user remove the vhost then reload, the conf is empty.
if (!conf) { if (!conf) {
return srs_error_new(ERROR_EDGE_VHOST_REMOVED, "vhost %s removed", req->vhost.c_str()); return srs_error_new(ERROR_EDGE_VHOST_REMOVED, "vhost %s removed", req->vhost_.c_str());
} }
// select the origin. // select the origin.
@ -213,20 +213,20 @@ srs_error_t SrsEdgeFlvUpstream::do_connect(ISrsRequest *r, ISrsLbRoundRobin *lb,
selected_port = port; selected_port = port;
} else { } else {
// If HTTP redirect, use the server in location. // If HTTP redirect, use the server in location.
schema_ = req->schema; schema_ = req->schema_;
selected_ip = req->host; selected_ip = req->host_;
selected_port = req->port; selected_port = req->port_;
} }
srs_freep(sdk_); srs_freep(sdk_);
sdk_ = new SrsHttpClient(); sdk_ = new SrsHttpClient();
string path = "/" + req->app + "/" + req->stream; string path = "/" + req->app_ + "/" + req->stream_;
if (!srs_strings_ends_with(req->stream, ".flv")) { if (!srs_strings_ends_with(req->stream_, ".flv")) {
path += ".flv"; path += ".flv";
} }
if (!req->param.empty()) { if (!req->param_.empty()) {
path += req->param; path += req->param_;
} }
string url = schema_ + "://" + selected_ip + ":" + srs_strconv_format_int(selected_port); string url = schema_ + "://" + selected_ip + ":" + srs_strconv_format_int(selected_port);
@ -267,12 +267,12 @@ srs_error_t SrsEdgeFlvUpstream::do_connect(ISrsRequest *r, ISrsLbRoundRobin *lb,
string schema, host, vhost, param; string schema, host, vhost, param;
srs_net_url_parse_tcurl(tcUrl, schema, host, vhost, app, stream_name, port, param); srs_net_url_parse_tcurl(tcUrl, schema, host, vhost, app, stream_name, port, param);
r->schema = schema; r->schema_ = schema;
r->host = host; r->host_ = host;
r->port = port; r->port_ = port;
r->app = app; r->app_ = app;
r->stream = stream_name; r->stream_ = stream_name;
r->param = param; r->param_ = param;
} }
return do_connect(r, lb, redirect_depth + 1); return do_connect(r, lb, redirect_depth + 1);
} }
@ -519,12 +519,12 @@ srs_error_t SrsEdgeIngester::do_cycle()
} }
// Use protocol in config. // Use protocol in config.
string edge_protocol = _srs_config->get_vhost_edge_protocol(req->vhost); string edge_protocol = _srs_config->get_vhost_edge_protocol(req->vhost_);
// If follow client protocol, change to protocol of client. // If follow client protocol, change to protocol of client.
bool follow_client = _srs_config->get_vhost_edge_follow_client(req->vhost); bool follow_client = _srs_config->get_vhost_edge_follow_client(req->vhost_);
if (follow_client && !req->protocol.empty()) { if (follow_client && !req->protocol_.empty()) {
edge_protocol = req->protocol; edge_protocol = req->protocol_;
} }
// Create object by protocol. // Create object by protocol.
@ -670,12 +670,12 @@ srs_error_t SrsEdgeIngester::process_publish_message(SrsRtmpCommonMessage *msg,
// RTMP 302 redirect // RTMP 302 redirect
if (dynamic_cast<SrsCallPacket *>(pkt.get())) { if (dynamic_cast<SrsCallPacket *>(pkt.get())) {
SrsCallPacket *call = dynamic_cast<SrsCallPacket *>(pkt.get()); SrsCallPacket *call = dynamic_cast<SrsCallPacket *>(pkt.get());
if (!call->arguments->is_object()) { if (!call->arguments_->is_object()) {
return err; return err;
} }
SrsAmf0Any *prop = NULL; SrsAmf0Any *prop = NULL;
SrsAmf0Object *evt = call->arguments->to_object(); SrsAmf0Object *evt = call->arguments_->to_object();
if ((prop = evt->ensure_property_string("level")) == NULL) { if ((prop = evt->ensure_property_string("level")) == NULL) {
return err; return err;
@ -758,7 +758,7 @@ srs_error_t SrsEdgeForwarder::start()
std::string url; std::string url;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_edge_origin(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_edge_origin(req->vhost_);
srs_assert(conf); srs_assert(conf);
// select the origin. // select the origin.
@ -767,10 +767,10 @@ srs_error_t SrsEdgeForwarder::start()
srs_net_split_hostport(server, server, port); srs_net_split_hostport(server, server, port);
// support vhost tranform for edge, // support vhost tranform for edge,
std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost); std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost_);
vhost = srs_strings_replace(vhost, "[vhost]", req->vhost); vhost = srs_strings_replace(vhost, "[vhost]", req->vhost_);
url = srs_net_url_encode_rtmp_url(server, port, req->host, vhost, req->app, req->stream, req->param); url = srs_net_url_encode_rtmp_url(server, port, req->host_, vhost, req->app_, req->stream_, req->param_);
} }
// We must stop the coroutine before disposing the sdk. // We must stop the coroutine before disposing the sdk.
@ -790,7 +790,7 @@ srs_error_t SrsEdgeForwarder::start()
// For RTMP client, we pass the vhost in tcUrl when connecting, // For RTMP client, we pass the vhost in tcUrl when connecting,
// so we publish without vhost in stream. // so we publish without vhost in stream.
string stream; string stream;
if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost), false, &stream)) != srs_success) { if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost_), false, &stream)) != srs_success) {
return srs_error_wrap(err, "sdk publish"); return srs_error_wrap(err, "sdk publish");
} }
@ -799,7 +799,7 @@ srs_error_t SrsEdgeForwarder::start()
return srs_error_wrap(err, "coroutine"); return srs_error_wrap(err, "coroutine");
} }
srs_trace("edge-fwr publish url %s, stream=%s%s as %s", url.c_str(), req->stream.c_str(), req->param.c_str(), stream.c_str()); srs_trace("edge-fwr publish url %s, stream=%s%s as %s", url.c_str(), req->stream_.c_str(), req->param_.c_str(), stream.c_str());
return err; return err;
} }
@ -881,9 +881,9 @@ srs_error_t SrsEdgeForwarder::do_cycle()
} }
// forward all messages. // forward all messages.
// each msg in msgs.msgs must be free, for the SrsMessageArray never free them. // each msg in msgs.msgs_ must be free, for the SrsMessageArray never free them.
int count = 0; int count = 0;
if ((err = queue->dump_packets(msgs.max, msgs.msgs, count)) != srs_success) { if ((err = queue->dump_packets(msgs.max_, msgs.msgs_, count)) != srs_success) {
return srs_error_wrap(err, "queue dumps packets"); return srs_error_wrap(err, "queue dumps packets");
} }
@ -901,7 +901,7 @@ srs_error_t SrsEdgeForwarder::do_cycle()
} }
// sendout messages, all messages are freed by send_and_free_messages(). // sendout messages, all messages are freed by send_and_free_messages().
if ((err = sdk->send_and_free_messages(msgs.msgs, count)) != srs_success) { if ((err = sdk->send_and_free_messages(msgs.msgs_, count)) != srs_success) {
return srs_error_wrap(err, "send messages"); return srs_error_wrap(err, "send messages");
} }
} }

View File

@ -164,22 +164,22 @@ srs_error_t SrsEncoder::parse_scope_engines(ISrsRequest *req)
// parse vhost scope engines // parse vhost scope engines
std::string scope = ""; std::string scope = "";
if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((conf = _srs_config->get_transcode(req->vhost_, scope)) != NULL) {
if ((err = parse_ffmpeg(req, conf)) != srs_success) { if ((err = parse_ffmpeg(req, conf)) != srs_success) {
return srs_error_wrap(err, "parse ffmpeg"); return srs_error_wrap(err, "parse ffmpeg");
} }
} }
// parse app scope engines // parse app scope engines
scope = req->app; scope = req->app_;
if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((conf = _srs_config->get_transcode(req->vhost_, scope)) != NULL) {
if ((err = parse_ffmpeg(req, conf)) != srs_success) { if ((err = parse_ffmpeg(req, conf)) != srs_success) {
return srs_error_wrap(err, "parse ffmpeg"); return srs_error_wrap(err, "parse ffmpeg");
} }
} }
// parse stream scope engines // parse stream scope engines
scope += "/"; scope += "/";
scope += req->stream; scope += req->stream_;
if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((conf = _srs_config->get_transcode(req->vhost_, scope)) != NULL) {
if ((err = parse_ffmpeg(req, conf)) != srs_success) { if ((err = parse_ffmpeg(req, conf)) != srs_success) {
return srs_error_wrap(err, "parse ffmpeg"); return srs_error_wrap(err, "parse ffmpeg");
} }
@ -244,29 +244,29 @@ srs_error_t SrsEncoder::initialize_ffmpeg(SrsFFMPEG *ffmpeg, ISrsRequest *req, S
input = "rtmp://"; input = "rtmp://";
input += SRS_CONSTS_LOCALHOST; input += SRS_CONSTS_LOCALHOST;
input += ":"; input += ":";
input += srs_strconv_format_int(req->port); input += srs_strconv_format_int(req->port_);
input += "/"; input += "/";
input += req->app; input += req->app_;
input += "/"; input += "/";
input += req->stream; input += req->stream_;
input += "?vhost="; input += "?vhost=";
input += req->vhost; input += req->vhost_;
// stream name: vhost/app/stream for print // stream name: vhost/app/stream for print
input_stream_name = req->vhost; input_stream_name = req->vhost_;
input_stream_name += "/"; input_stream_name += "/";
input_stream_name += req->app; input_stream_name += req->app_;
input_stream_name += "/"; input_stream_name += "/";
input_stream_name += req->stream; input_stream_name += req->stream_;
std::string output = _srs_config->get_engine_output(engine); std::string output = _srs_config->get_engine_output(engine);
// output stream, to other/self server // output stream, to other/self server
// ie. rtmp://localhost:1935/live/livestream_sd // ie. rtmp://localhost:1935/live/livestream_sd
output = srs_strings_replace(output, "[vhost]", req->vhost); output = srs_strings_replace(output, "[vhost]", req->vhost_);
output = srs_strings_replace(output, "[port]", srs_strconv_format_int(req->port)); output = srs_strings_replace(output, "[port]", srs_strconv_format_int(req->port_));
output = srs_strings_replace(output, "[app]", req->app); output = srs_strings_replace(output, "[app]", req->app_);
output = srs_strings_replace(output, "[stream]", req->stream); output = srs_strings_replace(output, "[stream]", req->stream_);
output = srs_strings_replace(output, "[param]", req->param); output = srs_strings_replace(output, "[param]", req->param_);
output = srs_strings_replace(output, "[engine]", engine->arg0()); output = srs_strings_replace(output, "[engine]", engine->arg0());
output = srs_path_build_timestamp(output); output = srs_path_build_timestamp(output);
@ -277,11 +277,11 @@ srs_error_t SrsEncoder::initialize_ffmpeg(SrsFFMPEG *ffmpeg, ISrsRequest *req, S
log_file += "/"; log_file += "/";
log_file += "ffmpeg-encoder"; log_file += "ffmpeg-encoder";
log_file += "-"; log_file += "-";
log_file += req->vhost; log_file += req->vhost_;
log_file += "-"; log_file += "-";
log_file += req->app; log_file += req->app_;
log_file += "-"; log_file += "-";
log_file += req->stream; log_file += req->stream_;
if (!engine->args.empty()) { if (!engine->args.empty()) {
log_file += "-"; log_file += "-";
log_file += engine->arg0(); log_file += engine->arg0();

View File

@ -209,7 +209,7 @@ srs_error_t SrsForwarder::do_cycle()
srs_net_split_hostport(ep_forward, server, port); srs_net_split_hostport(ep_forward, server, port);
// generate url // generate url
url = srs_net_url_encode_rtmp_url(server, port, req->host, req->vhost, req->app, req->stream, req->param); url = srs_net_url_encode_rtmp_url(server, port, req->host_, req->vhost_, req->app_, req->stream_, req->param_);
} }
srs_freep(sdk); srs_freep(sdk);
@ -224,7 +224,7 @@ srs_error_t SrsForwarder::do_cycle()
// For RTMP client, we pass the vhost in tcUrl when connecting, // For RTMP client, we pass the vhost in tcUrl when connecting,
// so we publish without vhost in stream. // so we publish without vhost in stream.
string stream; string stream;
if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost), false, &stream)) != srs_success) { if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost_), false, &stream)) != srs_success) {
return srs_error_wrap(err, "sdk publish"); return srs_error_wrap(err, "sdk publish");
} }
@ -236,7 +236,7 @@ srs_error_t SrsForwarder::do_cycle()
return srs_error_wrap(err, "forward"); return srs_error_wrap(err, "forward");
} }
srs_trace("forward publish url %s, stream=%s%s as %s", url.c_str(), req->stream.c_str(), req->param.c_str(), stream.c_str()); srs_trace("forward publish url %s, stream=%s%s as %s", url.c_str(), req->stream_.c_str(), req->param_.c_str(), stream.c_str());
return err; return err;
} }
@ -286,9 +286,9 @@ srs_error_t SrsForwarder::forward()
} }
// forward all messages. // forward all messages.
// each msg in msgs.msgs must be free, for the SrsMessageArray never free them. // each msg in msgs.msgs_ must be free, for the SrsMessageArray never free them.
int count = 0; int count = 0;
if ((err = queue->dump_packets(msgs.max, msgs.msgs, count)) != srs_success) { if ((err = queue->dump_packets(msgs.max_, msgs.msgs_, count)) != srs_success) {
return srs_error_wrap(err, "dump packets"); return srs_error_wrap(err, "dump packets");
} }
@ -303,7 +303,7 @@ srs_error_t SrsForwarder::forward()
} }
// sendout messages, all messages are freed by send_and_free_messages(). // sendout messages, all messages are freed by send_and_free_messages().
if ((err = sdk->send_and_free_messages(msgs.msgs, count)) != srs_success) { if ((err = sdk->send_and_free_messages(msgs.msgs_, count)) != srs_success) {
return srs_error_wrap(err, "send messages"); return srs_error_wrap(err, "send messages");
} }
} }

View File

@ -1180,7 +1180,7 @@ srs_error_t SrsGbMuxer::on_ts_audio(SrsTsMessage *msg, SrsBuffer *avs)
} }
aac_specific_config_ = sh; aac_specific_config_ = sh;
codec.aac_packet_type = 0; codec.aac_packet_type_ = 0;
if ((err = write_audio_raw_frame((char *)sh.data(), (int)sh.length(), &codec, dts)) != srs_success) { if ((err = write_audio_raw_frame((char *)sh.data(), (int)sh.length(), &codec, dts)) != srs_success) {
return srs_error_wrap(err, "write raw audio frame"); return srs_error_wrap(err, "write raw audio frame");
@ -1188,7 +1188,7 @@ srs_error_t SrsGbMuxer::on_ts_audio(SrsTsMessage *msg, SrsBuffer *avs)
} }
// audio raw data. // audio raw data.
codec.aac_packet_type = 1; codec.aac_packet_type_ = 1;
if ((err = write_audio_raw_frame(frame, frame_size, &codec, dts)) != srs_success) { if ((err = write_audio_raw_frame(frame, frame_size, &codec, dts)) != srs_success) {
return srs_error_wrap(err, "write audio raw frame"); return srs_error_wrap(err, "write audio raw frame");
} }

View File

@ -275,7 +275,7 @@ srs_error_t SrsDvrAsyncCallOnHls::call()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -285,7 +285,7 @@ srs_error_t SrsDvrAsyncCallOnHls::call()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_hls(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_hls(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -325,7 +325,7 @@ srs_error_t SrsDvrAsyncCallOnHlsNotify::call()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -335,7 +335,7 @@ srs_error_t SrsDvrAsyncCallOnHlsNotify::call()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_hls_notify(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_hls_notify(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -344,7 +344,7 @@ srs_error_t SrsDvrAsyncCallOnHlsNotify::call()
hooks = conf->args; hooks = conf->args;
} }
int nb_notify = _srs_config->get_vhost_hls_nb_notify(req->vhost); int nb_notify = _srs_config->get_vhost_hls_nb_notify(req->vhost_);
for (int i = 0; i < (int)hooks.size(); i++) { for (int i = 0; i < (int)hooks.size(); i++) {
std::string url = hooks.at(i); std::string url = hooks.at(i);
if ((err = _srs_hooks->on_hls_notify(cid, url, req, ts_url, nb_notify)) != srs_success) { if ((err = _srs_hooks->on_hls_notify(cid, url, req, ts_url, nb_notify)) != srs_success) {
@ -494,9 +494,9 @@ srs_error_t SrsHlsFmp4Muxer::write_init_mp4(SrsFormat *format, bool has_video, b
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
std::string vhost = req_->vhost; std::string vhost = req_->vhost_;
std::string stream = req_->stream; std::string stream = req_->stream_;
std::string app = req_->app; std::string app = req_->app_;
// Get init.mp4 file template from configuration // Get init.mp4 file template from configuration
std::string init_file = _srs_config->get_hls_init_file(vhost); std::string init_file = _srs_config->get_hls_init_file(vhost);
@ -645,9 +645,9 @@ srs_error_t SrsHlsFmp4Muxer::update_config(ISrsRequest *r)
srs_freep(req_); srs_freep(req_);
req_ = r->copy(); req_ = r->copy();
std::string vhost = req_->vhost; std::string vhost = req_->vhost_;
std::string stream = req_->stream; std::string stream = req_->stream_;
std::string app = req_->app; std::string app = req_->app_;
hls_fragment_ = _srs_config->get_hls_fragment(vhost); hls_fragment_ = _srs_config->get_hls_fragment(vhost);
double hls_td_ratio = _srs_config->get_hls_td_ratio(vhost); double hls_td_ratio = _srs_config->get_hls_td_ratio(vhost);
@ -722,7 +722,7 @@ srs_error_t SrsHlsFmp4Muxer::segment_open(srs_utime_t basetime)
// generate filename. // generate filename.
std::string m4s_file = hls_m4s_file_; std::string m4s_file = hls_m4s_file_;
m4s_file = srs_path_build_stream(m4s_file, req_->vhost, req_->app, req_->stream); m4s_file = srs_path_build_stream(m4s_file, req_->vhost_, req_->app_, req_->stream_);
if (hls_ts_floor_) { if (hls_ts_floor_) {
// accept the floor ts for the first piece. // accept the floor ts for the first piece.
int64_t current_floor_ts = srs_time_now_realtime() / hls_fragment_; int64_t current_floor_ts = srs_time_now_realtime() / hls_fragment_;
@ -903,7 +903,7 @@ srs_error_t SrsHlsFmp4Muxer::write_hls_key()
return srs_error_wrap(err, "rand iv failed."); return srs_error_wrap(err, "rand iv failed.");
} }
string key_file = srs_path_build_stream(hls_key_file_, req_->vhost, req_->app, req_->stream); string key_file = srs_path_build_stream(hls_key_file_, req_->vhost_, req_->app_, req_->stream_);
key_file = srs_strings_replace(key_file, "[seq]", srs_strconv_format_int(current_->sequence_no)); key_file = srs_strings_replace(key_file, "[seq]", srs_strconv_format_int(current_->sequence_no));
string key_url = hls_key_file_path_ + "/" + key_file; string key_url = hls_key_file_path_ + "/" + key_file;
@ -1016,7 +1016,7 @@ srs_error_t SrsHlsFmp4Muxer::_refresh_m3u8(std::string m3u8_file)
srs_hex_encode_to_string(hexiv, segment->iv, 16); srs_hex_encode_to_string(hexiv, segment->iv, 16);
hexiv[32] = '\0'; hexiv[32] = '\0';
string key_file = srs_path_build_stream(hls_key_file_, req_->vhost, req_->app, req_->stream); string key_file = srs_path_build_stream(hls_key_file_, req_->vhost_, req_->app_, req_->stream_);
key_file = srs_strings_replace(key_file, "[seq]", srs_strconv_format_int(segment->sequence_no)); key_file = srs_strings_replace(key_file, "[seq]", srs_strconv_format_int(segment->sequence_no));
string key_path = key_file; string key_path = key_file;
@ -1236,11 +1236,11 @@ srs_error_t SrsHlsMuxer::update_config(ISrsRequest *r, string entry_prefix,
hls_key_url = key_url; hls_key_url = key_url;
// generate the m3u8 dir and path. // generate the m3u8 dir and path.
m3u8_url = srs_path_build_stream(m3u8_file, req->vhost, req->app, req->stream); m3u8_url = srs_path_build_stream(m3u8_file, req->vhost_, req->app_, req->stream_);
m3u8 = path + "/" + m3u8_url; m3u8 = path + "/" + m3u8_url;
// when update config, reset the history target duration. // when update config, reset the history target duration.
max_td = fragment * _srs_config->get_hls_td_ratio(r->vhost); max_td = fragment * _srs_config->get_hls_td_ratio(r->vhost_);
// create m3u8 dir once. // create m3u8 dir once.
m3u8_dir = srs_path_filepath_dir(m3u8); m3u8_dir = srs_path_filepath_dir(m3u8);
@ -1249,7 +1249,7 @@ srs_error_t SrsHlsMuxer::update_config(ISrsRequest *r, string entry_prefix,
} }
if (hls_keys && (hls_path != hls_key_file_path)) { if (hls_keys && (hls_path != hls_key_file_path)) {
string key_file = srs_path_build_stream(hls_key_file, req->vhost, req->app, req->stream); string key_file = srs_path_build_stream(hls_key_file, req->vhost_, req->app_, req->stream_);
string key_url = hls_key_file_path + "/" + key_file; string key_url = hls_key_file_path + "/" + key_file;
string key_dir = srs_path_filepath_dir(key_url); string key_dir = srs_path_filepath_dir(key_url);
if ((err = srs_os_mkdir_all(key_dir)) != srs_success) { if ((err = srs_os_mkdir_all(key_dir)) != srs_success) {
@ -1382,7 +1382,7 @@ srs_error_t SrsHlsMuxer::recover_hls()
// new segment. // new segment.
SrsHlsSegment *seg = new SrsHlsSegment(context, default_acodec, default_vcodec, writer); SrsHlsSegment *seg = new SrsHlsSegment(context, default_acodec, default_vcodec, writer);
seg->sequence_no = _sequence_no++; seg->sequence_no = _sequence_no++;
seg->set_path(hls_path + "/" + req->app + "/" + ts_url); seg->set_path(hls_path + "/" + req->app_ + "/" + ts_url);
seg->uri = ts_url; seg->uri = ts_url;
seg->set_sequence_header(discon); seg->set_sequence_header(discon);
@ -1448,7 +1448,7 @@ srs_error_t SrsHlsMuxer::segment_open()
// generate filename. // generate filename.
std::string ts_file = hls_ts_file; std::string ts_file = hls_ts_file;
ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream); ts_file = srs_path_build_stream(ts_file, req->vhost_, req->app_, req->stream_);
if (hls_ts_floor) { if (hls_ts_floor) {
// accept the floor ts for the first piece. // accept the floor ts for the first piece.
int64_t current_floor_ts = srs_time_now_realtime() / hls_fragment; int64_t current_floor_ts = srs_time_now_realtime() / hls_fragment;
@ -1741,7 +1741,7 @@ srs_error_t SrsHlsMuxer::write_hls_key()
return srs_error_wrap(err, "rand iv failed."); return srs_error_wrap(err, "rand iv failed.");
} }
string key_file = srs_path_build_stream(hls_key_file, req->vhost, req->app, req->stream); string key_file = srs_path_build_stream(hls_key_file, req->vhost_, req->app_, req->stream_);
key_file = srs_strings_replace(key_file, "[seq]", srs_strconv_format_int(current->sequence_no)); key_file = srs_strings_replace(key_file, "[seq]", srs_strconv_format_int(current->sequence_no));
string key_url = hls_key_file_path + "/" + key_file; string key_url = hls_key_file_path + "/" + key_file;
@ -1852,7 +1852,7 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
srs_hex_encode_to_string(hexiv, segment->iv, 16); srs_hex_encode_to_string(hexiv, segment->iv, 16);
hexiv[32] = '\0'; hexiv[32] = '\0';
string key_file = srs_path_build_stream(hls_key_file, req->vhost, req->app, req->stream); string key_file = srs_path_build_stream(hls_key_file, req->vhost_, req->app_, req->stream_);
key_file = srs_strings_replace(key_file, "[seq]", srs_strconv_format_int(segment->sequence_no)); key_file = srs_strings_replace(key_file, "[seq]", srs_strconv_format_int(segment->sequence_no));
string key_path = key_file; string key_path = key_file;
@ -1957,9 +1957,9 @@ srs_error_t SrsHlsController::on_publish(ISrsRequest *req)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
std::string vhost = req->vhost; std::string vhost = req->vhost_;
std::string stream = req->stream; std::string stream = req->stream_;
std::string app = req->app; std::string app = req->app_;
srs_utime_t hls_fragment = _srs_config->get_hls_fragment(vhost); srs_utime_t hls_fragment = _srs_config->get_hls_fragment(vhost);
double hls_td_ratio = _srs_config->get_hls_td_ratio(vhost); double hls_td_ratio = _srs_config->get_hls_td_ratio(vhost);
@ -2011,7 +2011,7 @@ srs_error_t SrsHlsController::on_publish(ISrsRequest *req)
// This config item is used in SrsHls, we just log its value here. // This config item is used in SrsHls, we just log its value here.
// If enabled, directly turn FLV timestamp to TS DTS. // If enabled, directly turn FLV timestamp to TS DTS.
// @remark It'll be reloaded automatically, because the origin hub will republish while reloading. // @remark It'll be reloaded automatically, because the origin hub will republish while reloading.
hls_dts_directly = _srs_config->get_vhost_hls_dts_directly(req->vhost); hls_dts_directly = _srs_config->get_vhost_hls_dts_directly(req->vhost_);
srs_trace("hls: win=%dms, frag=%dms, prefix=%s, path=%s, m3u8=%s, ts=%s, tdr=%.2f, aof=%.2f, floor=%d, clean=%d, waitk=%d, dispose=%dms, dts_directly=%d", srs_trace("hls: win=%dms, frag=%dms, prefix=%s, path=%s, m3u8=%s, ts=%s, tdr=%.2f, aof=%.2f, floor=%d, clean=%d, waitk=%d, dispose=%dms, dts_directly=%d",
srsu2msi(hls_window), srsu2msi(hls_fragment), entry_prefix.c_str(), path.c_str(), m3u8_file.c_str(), ts_file.c_str(), srsu2msi(hls_window), srsu2msi(hls_fragment), entry_prefix.c_str(), path.c_str(), m3u8_file.c_str(), ts_file.c_str(),
@ -2268,9 +2268,9 @@ srs_error_t SrsHlsMp4Controller::on_publish(ISrsRequest *req)
srs_error_t err = srs_success; srs_error_t err = srs_success;
req_ = req; req_ = req;
std::string vhost = req->vhost; std::string vhost = req->vhost_;
std::string stream = req->stream; std::string stream = req->stream_;
std::string app = req->app; std::string app = req->app_;
// get the hls m3u8 ts list entry prefix config // get the hls m3u8 ts list entry prefix config
std::string entry_prefix = _srs_config->get_hls_entry_prefix(vhost); std::string entry_prefix = _srs_config->get_hls_entry_prefix(vhost);
@ -2483,7 +2483,7 @@ void SrsHls::dispose()
// Ignore when hls_dispose disabled. // Ignore when hls_dispose disabled.
// @see https://github.com/ossrs/srs/issues/865 // @see https://github.com/ossrs/srs/issues/865
srs_utime_t hls_dispose = _srs_config->get_hls_dispose(req->vhost); srs_utime_t hls_dispose = _srs_config->get_hls_dispose(req->vhost_);
if (!hls_dispose) { if (!hls_dispose) {
return; return;
} }
@ -2512,7 +2512,7 @@ srs_error_t SrsHls::cycle()
return err; return err;
// If not unpublishing and not reloading, try to dispose HLS stream. // If not unpublishing and not reloading, try to dispose HLS stream.
srs_utime_t hls_dispose = _srs_config->get_hls_dispose(req->vhost); srs_utime_t hls_dispose = _srs_config->get_hls_dispose(req->vhost_);
if (hls_dispose <= 0) { if (hls_dispose <= 0) {
return err; return err;
} }
@ -2535,7 +2535,7 @@ srs_error_t SrsHls::cycle()
srs_utime_t SrsHls::cleanup_delay() srs_utime_t SrsHls::cleanup_delay()
{ {
// We use larger timeout to cleanup the HLS, after disposed it if required. // We use larger timeout to cleanup the HLS, after disposed it if required.
return _srs_config->get_hls_dispose(req->vhost) * 1.1; return _srs_config->get_hls_dispose(req->vhost_) * 1.1;
} }
// CRITICAL: This method is called AFTER the source has been added to the source pool // CRITICAL: This method is called AFTER the source has been added to the source pool
@ -2551,7 +2551,7 @@ srs_error_t SrsHls::initialize(SrsOriginHub *h, ISrsRequest *r)
hub = h; hub = h;
req = r; req = r;
bool is_fmp4_enabled = _srs_config->get_hls_use_fmp4(r->vhost); bool is_fmp4_enabled = _srs_config->get_hls_use_fmp4(r->vhost_);
if (!controller) { if (!controller) {
if (is_fmp4_enabled) { if (is_fmp4_enabled) {
@ -2580,7 +2580,7 @@ srs_error_t SrsHls::on_publish()
return err; return err;
} }
if (!_srs_config->get_hls_enabled(req->vhost)) { if (!_srs_config->get_hls_enabled(req->vhost_)) {
return err; return err;
} }

View File

@ -64,13 +64,13 @@ srs_error_t SrsHttpHooks::on_connect(string url, ISrsRequest *req)
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("action", SrsJsonAny::str("on_connect")); obj->set("action", SrsJsonAny::str("on_connect"));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); obj->set("stream", SrsJsonAny::str(req->stream_.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str())); obj->set("param", SrsJsonAny::str(req->param_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("pageUrl", SrsJsonAny::str(req->pageUrl.c_str())); obj->set("pageUrl", SrsJsonAny::str(req->pageUrl_.c_str()));
std::string data = obj->dumps(); std::string data = obj->dumps();
std::string res; std::string res;
@ -100,9 +100,9 @@ void SrsHttpHooks::on_close(string url, ISrsRequest *req, int64_t send_bytes, in
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("action", SrsJsonAny::str("on_close")); obj->set("action", SrsJsonAny::str("on_close"));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("send_bytes", SrsJsonAny::integer(send_bytes)); obj->set("send_bytes", SrsJsonAny::integer(send_bytes));
obj->set("recv_bytes", SrsJsonAny::integer(recv_bytes)); obj->set("recv_bytes", SrsJsonAny::integer(recv_bytes));
@ -137,12 +137,12 @@ srs_error_t SrsHttpHooks::on_publish(string url, ISrsRequest *req)
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("action", SrsJsonAny::str("on_publish")); obj->set("action", SrsJsonAny::str("on_publish"));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); obj->set("stream", SrsJsonAny::str(req->stream_.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str())); obj->set("param", SrsJsonAny::str(req->param_.c_str()));
obj->set("stream_url", SrsJsonAny::str(req->get_stream_url().c_str())); obj->set("stream_url", SrsJsonAny::str(req->get_stream_url().c_str()));
SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url()); SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url());
@ -178,12 +178,12 @@ void SrsHttpHooks::on_unpublish(string url, ISrsRequest *req)
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("action", SrsJsonAny::str("on_unpublish")); obj->set("action", SrsJsonAny::str("on_unpublish"));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); obj->set("stream", SrsJsonAny::str(req->stream_.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str())); obj->set("param", SrsJsonAny::str(req->param_.c_str()));
obj->set("stream_url", SrsJsonAny::str(req->get_stream_url().c_str())); obj->set("stream_url", SrsJsonAny::str(req->get_stream_url().c_str()));
SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url()); SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url());
@ -222,13 +222,13 @@ srs_error_t SrsHttpHooks::on_play(string url, ISrsRequest *req)
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("action", SrsJsonAny::str("on_play")); obj->set("action", SrsJsonAny::str("on_play"));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); obj->set("stream", SrsJsonAny::str(req->stream_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str())); obj->set("param", SrsJsonAny::str(req->param_.c_str()));
obj->set("pageUrl", SrsJsonAny::str(req->pageUrl.c_str())); obj->set("pageUrl", SrsJsonAny::str(req->pageUrl_.c_str()));
obj->set("stream_url", SrsJsonAny::str(req->get_stream_url().c_str())); obj->set("stream_url", SrsJsonAny::str(req->get_stream_url().c_str()));
SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url()); SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url());
@ -264,12 +264,12 @@ void SrsHttpHooks::on_stop(string url, ISrsRequest *req)
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("action", SrsJsonAny::str("on_stop")); obj->set("action", SrsJsonAny::str("on_stop"));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); obj->set("stream", SrsJsonAny::str(req->stream_.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str())); obj->set("param", SrsJsonAny::str(req->param_.c_str()));
obj->set("stream_url", SrsJsonAny::str(req->get_stream_url().c_str())); obj->set("stream_url", SrsJsonAny::str(req->get_stream_url().c_str()));
SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url()); SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url());
@ -310,12 +310,12 @@ srs_error_t SrsHttpHooks::on_dvr(SrsContextId c, string url, ISrsRequest *req, s
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("action", SrsJsonAny::str("on_dvr")); obj->set("action", SrsJsonAny::str("on_dvr"));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); obj->set("stream", SrsJsonAny::str(req->stream_.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str())); obj->set("param", SrsJsonAny::str(req->param_.c_str()));
obj->set("cwd", SrsJsonAny::str(cwd.c_str())); obj->set("cwd", SrsJsonAny::str(cwd.c_str()));
obj->set("file", SrsJsonAny::str(file.c_str())); obj->set("file", SrsJsonAny::str(file.c_str()));
@ -361,12 +361,12 @@ srs_error_t SrsHttpHooks::on_hls(SrsContextId c, string url, ISrsRequest *req, s
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("action", SrsJsonAny::str("on_hls")); obj->set("action", SrsJsonAny::str("on_hls"));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); obj->set("stream", SrsJsonAny::str(req->stream_.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str())); obj->set("param", SrsJsonAny::str(req->param_.c_str()));
obj->set("duration", SrsJsonAny::number(srsu2ms(duration) / 1000.0)); obj->set("duration", SrsJsonAny::number(srsu2ms(duration) / 1000.0));
obj->set("cwd", SrsJsonAny::str(cwd.c_str())); obj->set("cwd", SrsJsonAny::str(cwd.c_str()));
obj->set("file", SrsJsonAny::str(file.c_str())); obj->set("file", SrsJsonAny::str(file.c_str()));
@ -411,10 +411,10 @@ srs_error_t SrsHttpHooks::on_hls_notify(SrsContextId c, std::string url, ISrsReq
url = srs_strings_replace(url, "[server_id]", stat->server_id().c_str()); url = srs_strings_replace(url, "[server_id]", stat->server_id().c_str());
url = srs_strings_replace(url, "[service_id]", stat->service_id().c_str()); url = srs_strings_replace(url, "[service_id]", stat->service_id().c_str());
url = srs_strings_replace(url, "[app]", req->app); url = srs_strings_replace(url, "[app]", req->app_);
url = srs_strings_replace(url, "[stream]", req->stream); url = srs_strings_replace(url, "[stream]", req->stream_);
url = srs_strings_replace(url, "[ts_url]", ts_url); url = srs_strings_replace(url, "[ts_url]", ts_url);
url = srs_strings_replace(url, "[param]", req->param); url = srs_strings_replace(url, "[param]", req->param_);
int64_t starttime = srsu2ms(srs_time_now_realtime()); int64_t starttime = srsu2ms(srs_time_now_realtime());
@ -533,12 +533,12 @@ srs_error_t SrsHttpHooks::on_forward_backend(string url, ISrsRequest *req, std::
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str())); obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
obj->set("client_id", SrsJsonAny::str(cid.c_str())); obj->set("client_id", SrsJsonAny::str(cid.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); obj->set("vhost", SrsJsonAny::str(req->vhost_.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str())); obj->set("app", SrsJsonAny::str(req->app_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); obj->set("stream", SrsJsonAny::str(req->stream_.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str())); obj->set("param", SrsJsonAny::str(req->param_.c_str()));
std::string data = obj->dumps(); std::string data = obj->dumps();
std::string res; std::string res;

View File

@ -85,14 +85,14 @@ srs_error_t SrsHlsStream::serve_m3u8_ctx(ISrsHttpResponseWriter *w, ISrsHttpMess
string ctx = r->query_get(SRS_CONTEXT_IN_HLS); string ctx = r->query_get(SRS_CONTEXT_IN_HLS);
// If HLS stream is disabled, use SrsHttpFileServer to serve HLS, which is normal file server. // If HLS stream is disabled, use SrsHttpFileServer to serve HLS, which is normal file server.
if (!_srs_config->get_hls_ctx_enabled(req->vhost)) { if (!_srs_config->get_hls_ctx_enabled(req->vhost_)) {
*served = false; *served = false;
return srs_success; return srs_success;
} }
// Correct the app and stream by path, which is created from template. // Correct the app and stream by path, which is created from template.
// @remark Be careful that the stream has extension now, might cause identify fail. // @remark Be careful that the stream has extension now, might cause identify fail.
req->stream = srs_path_filepath_base(r->path()); req->stream_ = srs_path_filepath_base(r->path());
// Served by us. // Served by us.
*served = true; *served = true;
@ -100,7 +100,7 @@ srs_error_t SrsHlsStream::serve_m3u8_ctx(ISrsHttpResponseWriter *w, ISrsHttpMess
// Already exists context, response with rebuilt m3u8 content. // Already exists context, response with rebuilt m3u8 content.
if (!ctx.empty() && ctx_is_exist(ctx)) { if (!ctx.empty() && ctx_is_exist(ctx)) {
// If HLS stream is disabled, use SrsHttpFileServer to serve HLS, which is normal file server. // If HLS stream is disabled, use SrsHttpFileServer to serve HLS, which is normal file server.
if (!_srs_config->get_hls_ts_ctx_enabled(req->vhost)) { if (!_srs_config->get_hls_ts_ctx_enabled(req->vhost_)) {
*served = false; *served = false;
return srs_success; return srs_success;
} }
@ -167,7 +167,7 @@ srs_error_t SrsHlsStream::serve_new_session(ISrsHttpResponseWriter *w, ISrsHttpM
return srs_error_wrap(err, "stat on client"); return srs_error_wrap(err, "stat on client");
} }
if ((err = security_->check(SrsHlsPlay, req->ip, req)) != srs_success) { if ((err = security_->check(SrsHlsPlay, req->ip_, req)) != srs_success) {
return srs_error_wrap(err, "HLS: security check"); return srs_error_wrap(err, "HLS: security check");
} }
@ -312,7 +312,7 @@ srs_error_t SrsHlsStream::http_hooks_on_play(ISrsRequest *req)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -322,7 +322,7 @@ srs_error_t SrsHlsStream::http_hooks_on_play(ISrsRequest *req)
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_play(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_play(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -343,7 +343,7 @@ srs_error_t SrsHlsStream::http_hooks_on_play(ISrsRequest *req)
void SrsHlsStream::http_hooks_on_stop(ISrsRequest *req) void SrsHlsStream::http_hooks_on_stop(ISrsRequest *req)
{ {
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return; return;
} }
@ -353,7 +353,7 @@ void SrsHlsStream::http_hooks_on_stop(ISrsRequest *req)
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_stop(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_stop(req->vhost_);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_stop"); srs_info("ignore the empty http callback: on_stop");
@ -380,7 +380,7 @@ srs_error_t SrsHlsStream::on_timer(srs_utime_t interval)
string ctx = it->first; string ctx = it->first;
SrsHlsVirtualConn *info = it->second; SrsHlsVirtualConn *info = it->second;
srs_utime_t hls_window = _srs_config->get_hls_window(info->req->vhost); srs_utime_t hls_window = _srs_config->get_hls_window(info->req->vhost_);
if (info->request_time + (2 * hls_window) < srs_time_now_cached()) { if (info->request_time + (2 * hls_window) < srs_time_now_cached()) {
SrsContextRestore(_srs_context->get_id()); SrsContextRestore(_srs_context->get_id());
_srs_context->set_id(SrsContextId().set_value(ctx)); _srs_context->set_id(SrsContextId().set_value(ctx));
@ -555,9 +555,9 @@ srs_error_t SrsVodStream::serve_m3u8_ctx(ISrsHttpResponseWriter *w, ISrsHttpMess
SrsUniquePtr<ISrsRequest> req(hr->to_request(hr->host())->as_http()); SrsUniquePtr<ISrsRequest> req(hr->to_request(hr->host())->as_http());
// discovery vhost, resolve the vhost from config // discovery vhost, resolve the vhost from config
SrsConfDirective *parsed_vhost = _srs_config->get_vhost(req->vhost); SrsConfDirective *parsed_vhost = _srs_config->get_vhost(req->vhost_);
if (parsed_vhost) { if (parsed_vhost) {
req->vhost = parsed_vhost->arg0(); req->vhost_ = parsed_vhost->arg0();
} }
// Try to serve by HLS streaming. // Try to serve by HLS streaming.

View File

@ -47,7 +47,7 @@ SrsBufferCache::SrsBufferCache(SrsServer *s, ISrsRequest *r)
trd = new SrsSTCoroutine("http-stream", this); trd = new SrsSTCoroutine("http-stream", this);
// TODO: FIXME: support reload. // TODO: FIXME: support reload.
fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost); fast_cache = _srs_config->get_vhost_http_remux_fast_cache(req->vhost_);
server_ = s; server_ = s;
} }
@ -188,7 +188,7 @@ srs_error_t SrsBufferCache::cycle()
// free the messages. // free the messages.
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
SrsMediaPacket *msg = msgs.msgs[i]; SrsMediaPacket *msg = msgs.msgs_[i];
queue->enqueue(msg); queue->enqueue(msg);
} }
} }
@ -655,12 +655,12 @@ srs_error_t SrsLiveStream::serve_http_impl(ISrsHttpResponseWriter *w, ISrsHttpMe
// Correct the app and stream by path, which is created from template. // Correct the app and stream by path, which is created from template.
// @remark Be careful that the stream has extension now, might cause identify fail. // @remark Be careful that the stream has extension now, might cause identify fail.
req->stream = srs_path_filepath_base(r->path()); req->stream_ = srs_path_filepath_base(r->path());
// remove the extension of stream if have. for instance, test.flv -> test // remove the extension of stream if have. for instance, test.flv -> test
req->stream = srs_path_filepath_filename(req->stream); req->stream_ = srs_path_filepath_filename(req->stream_);
// update client ip // update client ip
req->ip = hc->remote_ip(); req->ip_ = hc->remote_ip();
// We must do stat the client before hooks, because hooks depends on it. // We must do stat the client before hooks, because hooks depends on it.
SrsStatistic *stat = SrsStatistic::instance(); SrsStatistic *stat = SrsStatistic::instance();
@ -668,7 +668,7 @@ srs_error_t SrsLiveStream::serve_http_impl(ISrsHttpResponseWriter *w, ISrsHttpMe
return srs_error_wrap(err, "stat on client"); return srs_error_wrap(err, "stat on client");
} }
if ((err = security_->check(SrsFlvPlay, req->ip, req)) != srs_success) { if ((err = security_->check(SrsFlvPlay, req->ip_, req)) != srs_success) {
return srs_error_wrap(err, "flv: security check"); return srs_error_wrap(err, "flv: security check");
} }
@ -689,8 +689,8 @@ srs_error_t SrsLiveStream::serve_http_impl(ISrsHttpResponseWriter *w, ISrsHttpMe
} }
srs_assert(live_source.get() != NULL); srs_assert(live_source.get() != NULL);
bool enabled_cache = _srs_config->get_gop_cache(req->vhost); bool enabled_cache = _srs_config->get_gop_cache(req->vhost_);
int gcmf = _srs_config->get_gop_cache_max_frames(req->vhost); int gcmf = _srs_config->get_gop_cache_max_frames(req->vhost_);
live_source->set_cache(enabled_cache); live_source->set_cache(enabled_cache);
live_source->set_gop_cache_max_frames(gcmf); live_source->set_gop_cache_max_frames(gcmf);
@ -740,10 +740,10 @@ srs_error_t SrsLiveStream::do_serve_http(SrsLiveSource *source, SrsLiveConsumer
ISrsBufferEncoder *enc_raw = NULL; ISrsBufferEncoder *enc_raw = NULL;
srs_assert(entry); srs_assert(entry);
bool drop_if_not_match = _srs_config->get_vhost_http_remux_drop_if_not_match(req->vhost); bool drop_if_not_match = _srs_config->get_vhost_http_remux_drop_if_not_match(req->vhost_);
bool has_audio = _srs_config->get_vhost_http_remux_has_audio(req->vhost); bool has_audio = _srs_config->get_vhost_http_remux_has_audio(req->vhost_);
bool has_video = _srs_config->get_vhost_http_remux_has_video(req->vhost); bool has_video = _srs_config->get_vhost_http_remux_has_video(req->vhost_);
bool guess_has_av = _srs_config->get_vhost_http_remux_guess_has_av(req->vhost); bool guess_has_av = _srs_config->get_vhost_http_remux_guess_has_av(req->vhost_);
if (srs_strings_ends_with(entry->pattern, ".flv")) { if (srs_strings_ends_with(entry->pattern, ".flv")) {
w->header()->set_content_type("video/x-flv"); w->header()->set_content_type("video/x-flv");
@ -816,9 +816,9 @@ srs_error_t SrsLiveStream::do_serve_http(SrsLiveSource *source, SrsLiveConsumer
return srs_error_wrap(err, "start recv thread"); return srs_error_wrap(err, "start recv thread");
} }
srs_utime_t mw_sleep = _srs_config->get_mw_sleep(req->vhost); srs_utime_t mw_sleep = _srs_config->get_mw_sleep(req->vhost_);
srs_trace("FLV %s, encoder=%s, mw_sleep=%dms, cache=%d, msgs=%d, dinm=%d, guess_av=%d/%d/%d", srs_trace("FLV %s, encoder=%s, mw_sleep=%dms, cache=%d, msgs=%d, dinm=%d, guess_av=%d/%d/%d",
entry->pattern.c_str(), enc_desc.c_str(), srsu2msi(mw_sleep), enc->has_cache(), msgs.max, drop_if_not_match, entry->pattern.c_str(), enc_desc.c_str(), srsu2msi(mw_sleep), enc->has_cache(), msgs.max_, drop_if_not_match,
has_audio, has_video, guess_has_av); has_audio, has_video, guess_has_av);
// TODO: free and erase the disabled entry after all related connections is closed. // TODO: free and erase the disabled entry after all related connections is closed.
@ -853,16 +853,16 @@ srs_error_t SrsLiveStream::do_serve_http(SrsLiveSource *source, SrsLiveConsumer
// sendout all messages. // sendout all messages.
if (ffe) { if (ffe) {
err = ffe->write_tags(msgs.msgs, count); err = ffe->write_tags(msgs.msgs_, count);
} else { } else {
err = streaming_send_messages(enc.get(), msgs.msgs, count); err = streaming_send_messages(enc.get(), msgs.msgs_, count);
} }
// TODO: FIXME: Update the stat. // TODO: FIXME: Update the stat.
// free the messages. // free the messages.
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
SrsMediaPacket *msg = msgs.msgs[i]; SrsMediaPacket *msg = msgs.msgs_[i];
srs_freep(msg); srs_freep(msg);
} }
@ -881,13 +881,13 @@ srs_error_t SrsLiveStream::http_hooks_on_play(ISrsHttpMessage *r)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
// Create request to report for the specified connection. // Create request to report for the specified connection.
SrsHttpMessage *hr = dynamic_cast<SrsHttpMessage *>(r); SrsHttpMessage *hr = dynamic_cast<SrsHttpMessage *>(r);
SrsUniquePtr<ISrsRequest> nreq(hr->to_request(req->vhost)); SrsUniquePtr<ISrsRequest> nreq(hr->to_request(req->vhost_));
// the http hooks will cause context switch, // the http hooks will cause context switch,
// so we must copy all hooks for the on_connect may freed. // so we must copy all hooks for the on_connect may freed.
@ -895,7 +895,7 @@ srs_error_t SrsLiveStream::http_hooks_on_play(ISrsHttpMessage *r)
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_play(nreq->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_play(nreq->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -916,13 +916,13 @@ srs_error_t SrsLiveStream::http_hooks_on_play(ISrsHttpMessage *r)
void SrsLiveStream::http_hooks_on_stop(ISrsHttpMessage *r) void SrsLiveStream::http_hooks_on_stop(ISrsHttpMessage *r)
{ {
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return; return;
} }
// Create request to report for the specified connection. // Create request to report for the specified connection.
SrsHttpMessage *hr = dynamic_cast<SrsHttpMessage *>(r); SrsHttpMessage *hr = dynamic_cast<SrsHttpMessage *>(r);
SrsUniquePtr<ISrsRequest> nreq(hr->to_request(req->vhost)); SrsUniquePtr<ISrsRequest> nreq(hr->to_request(req->vhost_));
// the http hooks will cause context switch, // the http hooks will cause context switch,
// so we must copy all hooks for the on_connect may freed. // so we must copy all hooks for the on_connect may freed.
@ -930,7 +930,7 @@ void SrsLiveStream::http_hooks_on_stop(ISrsHttpMessage *r)
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_stop(nreq->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_stop(nreq->vhost_);
if (!conf) { if (!conf) {
srs_info("ignore the empty http callback: on_stop"); srs_info("ignore the empty http callback: on_stop");
@ -1077,18 +1077,18 @@ srs_error_t SrsHttpStreamServer::http_mount(ISrsRequest *r)
// create stream from template when not found. // create stream from template when not found.
if (streamHandlers.find(sid) == streamHandlers.end()) { if (streamHandlers.find(sid) == streamHandlers.end()) {
if (templateHandlers.find(r->vhost) == templateHandlers.end()) { if (templateHandlers.find(r->vhost_) == templateHandlers.end()) {
return err; return err;
} }
SrsLiveEntry *tmpl = templateHandlers[r->vhost]; SrsLiveEntry *tmpl = templateHandlers[r->vhost_];
std::string mount = tmpl->mount; std::string mount = tmpl->mount;
// replace the vhost variable // replace the vhost variable
mount = srs_strings_replace(mount, "[vhost]", r->vhost); mount = srs_strings_replace(mount, "[vhost]", r->vhost_);
mount = srs_strings_replace(mount, "[app]", r->app); mount = srs_strings_replace(mount, "[app]", r->app_);
mount = srs_strings_replace(mount, "[stream]", r->stream); mount = srs_strings_replace(mount, "[stream]", r->stream_);
// remove the default vhost mount // remove the default vhost mount
mount = srs_strings_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST "/", "/"); mount = srs_strings_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST "/", "/");
@ -1256,7 +1256,7 @@ srs_error_t SrsHttpStreamServer::dynamic_match(ISrsHttpMessage *request, ISrsHtt
// only when the http entry is disabled, check the config whether http flv disable, // only when the http entry is disabled, check the config whether http flv disable,
// for the http flv edge use match to trigger the edge ingester, we always mount it // for the http flv edge use match to trigger the edge ingester, we always mount it
// eventhough the origin does not exists the specified stream. // eventhough the origin does not exists the specified stream.
if (!_srs_config->get_vhost_http_remux_enabled(r->vhost)) { if (!_srs_config->get_vhost_http_remux_enabled(r->vhost_)) {
return srs_error_new(ERROR_HTTP_DYNAMIC_MATCH, "stream disabled"); return srs_error_new(ERROR_HTTP_DYNAMIC_MATCH, "stream disabled");
} }
} }

View File

@ -566,7 +566,7 @@ srs_error_t SrsMpegtsOverUdp::on_ts_audio(SrsTsMessage *msg, SrsBuffer *avs)
} }
aac_specific_config = sh; aac_specific_config = sh;
codec.aac_packet_type = 0; codec.aac_packet_type_ = 0;
if ((err = write_audio_raw_frame((char *)sh.data(), (int)sh.length(), &codec, dts)) != srs_success) { if ((err = write_audio_raw_frame((char *)sh.data(), (int)sh.length(), &codec, dts)) != srs_success) {
return srs_error_wrap(err, "write raw audio frame"); return srs_error_wrap(err, "write raw audio frame");
@ -574,7 +574,7 @@ srs_error_t SrsMpegtsOverUdp::on_ts_audio(SrsTsMessage *msg, SrsBuffer *avs)
} }
// audio raw data. // audio raw data.
codec.aac_packet_type = 1; codec.aac_packet_type_ = 1;
if ((err = write_audio_raw_frame(frame, frame_size, &codec, dts)) != srs_success) { if ((err = write_audio_raw_frame(frame, frame_size, &codec, dts)) != srs_success) {
return srs_error_wrap(err, "write audio raw frame"); return srs_error_wrap(err, "write audio raw frame");
} }

View File

@ -124,19 +124,19 @@ srs_error_t SrsNgExec::parse_exec_publish(ISrsRequest *req)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_exec_enabled(req->vhost)) { if (!_srs_config->get_exec_enabled(req->vhost_)) {
srs_trace("ignore disabled exec for vhost=%s", req->vhost.c_str()); srs_trace("ignore disabled exec for vhost=%s", req->vhost_.c_str());
return err; return err;
} }
// stream name: vhost/app/stream for print // stream name: vhost/app/stream for print
input_stream_name = req->vhost; input_stream_name = req->vhost_;
input_stream_name += "/"; input_stream_name += "/";
input_stream_name += req->app; input_stream_name += req->app_;
input_stream_name += "/"; input_stream_name += "/";
input_stream_name += req->stream; input_stream_name += req->stream_;
std::vector<SrsConfDirective *> eps = _srs_config->get_exec_publishs(req->vhost); std::vector<SrsConfDirective *> eps = _srs_config->get_exec_publishs(req->vhost_);
for (int i = 0; i < (int)eps.size(); i++) { for (int i = 0; i < (int)eps.size(); i++) {
SrsConfDirective *ep = eps.at(i); SrsConfDirective *ep = eps.at(i);
SrsProcess *process = new SrsProcess(); SrsProcess *process = new SrsProcess();
@ -162,7 +162,7 @@ srs_error_t SrsNgExec::parse_exec_publish(ISrsRequest *req)
if ((err = process->initialize(binary, argv)) != srs_success) { if ((err = process->initialize(binary, argv)) != srs_success) {
srs_freep(process); srs_freep(process);
return srs_error_wrap(err, "initialize process failed, binary=%s, vhost=%s", binary.c_str(), req->vhost.c_str()); return srs_error_wrap(err, "initialize process failed, binary=%s, vhost=%s", binary.c_str(), req->vhost_.c_str());
} }
exec_publishs.push_back(process); exec_publishs.push_back(process);
@ -197,19 +197,19 @@ string SrsNgExec::parse(ISrsRequest *req, string tmpl)
{ {
string output = tmpl; string output = tmpl;
output = srs_strings_replace(output, "[vhost]", req->vhost); output = srs_strings_replace(output, "[vhost]", req->vhost_);
output = srs_strings_replace(output, "[port]", srs_strconv_format_int(req->port)); output = srs_strings_replace(output, "[port]", srs_strconv_format_int(req->port_));
output = srs_strings_replace(output, "[app]", req->app); output = srs_strings_replace(output, "[app]", req->app_);
output = srs_strings_replace(output, "[stream]", req->stream); output = srs_strings_replace(output, "[stream]", req->stream_);
output = srs_strings_replace(output, "[tcUrl]", req->tcUrl); output = srs_strings_replace(output, "[tcUrl]", req->tcUrl_);
output = srs_strings_replace(output, "[swfUrl]", req->swfUrl); output = srs_strings_replace(output, "[swfUrl]", req->swfUrl_);
output = srs_strings_replace(output, "[pageUrl]", req->pageUrl); output = srs_strings_replace(output, "[pageUrl]", req->pageUrl_);
output = srs_path_build_timestamp(output); output = srs_path_build_timestamp(output);
if (output.find("[url]") != string::npos) { if (output.find("[url]") != string::npos) {
string url = srs_net_url_encode_rtmp_url(req->host, req->port, req->host, req->vhost, req->app, req->stream, req->param); string url = srs_net_url_encode_rtmp_url(req->host_, req->port_, req->host_, req->vhost_, req->app_, req->stream_, req->param_);
output = srs_strings_replace(output, "[url]", url); output = srs_strings_replace(output, "[url]", url);
} }

View File

@ -276,10 +276,10 @@ SrsPublishRecvThread::SrsPublishRecvThread(SrsRtmpServer *rtmp_sdk, ISrsRequest
mr_fd = mr_sock_fd; mr_fd = mr_sock_fd;
// the mr settings, // the mr settings,
mr = _srs_config->get_mr_enabled(req->vhost); mr = _srs_config->get_mr_enabled(req->vhost_);
mr_sleep = _srs_config->get_mr_sleep(req->vhost); mr_sleep = _srs_config->get_mr_sleep(req->vhost_);
realtime = _srs_config->get_realtime_enabled(req->vhost); realtime = _srs_config->get_realtime_enabled(req->vhost_);
_srs_config->subscribe(this); _srs_config->subscribe(this);
} }

View File

@ -126,18 +126,18 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter *w, ISrsHttpMe
// The RTC user config object. // The RTC user config object.
SrsRtcUserConfig ruc; SrsRtcUserConfig ruc;
ruc.req_->ip = clientip; ruc.req_->ip_ = clientip;
ruc.api_ = api; ruc.api_ = api;
srs_net_url_parse_rtmp_url(streamurl, ruc.req_->tcUrl, ruc.req_->stream); srs_net_url_parse_rtmp_url(streamurl, ruc.req_->tcUrl_, ruc.req_->stream_);
srs_net_url_parse_tcurl(ruc.req_->tcUrl, ruc.req_->schema, ruc.req_->host, ruc.req_->vhost, srs_net_url_parse_tcurl(ruc.req_->tcUrl_, ruc.req_->schema_, ruc.req_->host_, ruc.req_->vhost_,
ruc.req_->app, ruc.req_->stream, ruc.req_->port, ruc.req_->param); ruc.req_->app_, ruc.req_->stream_, ruc.req_->port_, ruc.req_->param_);
// discovery vhost, resolve the vhost from config // discovery vhost, resolve the vhost from config
SrsConfDirective *parsed_vhost = _srs_config->get_vhost(ruc.req_->vhost); SrsConfDirective *parsed_vhost = _srs_config->get_vhost(ruc.req_->vhost_);
if (parsed_vhost) { if (parsed_vhost) {
ruc.req_->vhost = parsed_vhost->arg0(); ruc.req_->vhost_ = parsed_vhost->arg0();
} }
// For client to specifies the candidate(EIP) of server. // For client to specifies the candidate(EIP) of server.
@ -152,8 +152,8 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter *w, ISrsHttpMe
srs_trace( srs_trace(
"RTC play %s, api=%s, tid=%s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s, srtp=%s, dtls=%s", "RTC play %s, api=%s, tid=%s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s, srtp=%s, dtls=%s",
streamurl.c_str(), api.c_str(), tid.c_str(), clientip.c_str(), ruc.req_->app.c_str(), streamurl.c_str(), api.c_str(), tid.c_str(), clientip.c_str(), ruc.req_->app_.c_str(),
ruc.req_->stream.c_str(), remote_sdp_str.length(), ruc.req_->stream_.c_str(), remote_sdp_str.length(),
eip.c_str(), codec.c_str(), srtp.c_str(), dtls.c_str()); eip.c_str(), codec.c_str(), srtp.c_str(), dtls.c_str());
ruc.eip_ = eip; ruc.eip_ = eip;
@ -200,18 +200,18 @@ srs_error_t SrsGoApiRtcPlay::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
SrsSdp local_sdp; SrsSdp local_sdp;
// Config for SDP and session. // Config for SDP and session.
local_sdp.session_config_.dtls_role = _srs_config->get_rtc_dtls_role(ruc->req_->vhost); local_sdp.session_config_.dtls_role = _srs_config->get_rtc_dtls_role(ruc->req_->vhost_);
local_sdp.session_config_.dtls_version = _srs_config->get_rtc_dtls_version(ruc->req_->vhost); local_sdp.session_config_.dtls_version = _srs_config->get_rtc_dtls_version(ruc->req_->vhost_);
// Whether enabled. // Whether enabled.
bool server_enabled = _srs_config->get_rtc_server_enabled(); bool server_enabled = _srs_config->get_rtc_server_enabled();
bool rtc_enabled = _srs_config->get_rtc_enabled(ruc->req_->vhost); bool rtc_enabled = _srs_config->get_rtc_enabled(ruc->req_->vhost_);
if (server_enabled && !rtc_enabled) { if (server_enabled && !rtc_enabled) {
srs_warn("RTC disabled in vhost %s", ruc->req_->vhost.c_str()); srs_warn("RTC disabled in vhost %s", ruc->req_->vhost_.c_str());
} }
if (!server_enabled || !rtc_enabled) { if (!server_enabled || !rtc_enabled) {
return srs_error_new(ERROR_RTC_DISABLED, "Disabled server=%d, rtc=%d, vhost=%s", return srs_error_new(ERROR_RTC_DISABLED, "Disabled server=%d, rtc=%d, vhost=%s",
server_enabled, rtc_enabled, ruc->req_->vhost.c_str()); server_enabled, rtc_enabled, ruc->req_->vhost_.c_str());
} }
// Whether RTC stream is active. // Whether RTC stream is active.
@ -222,14 +222,14 @@ srs_error_t SrsGoApiRtcPlay::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
} }
// For RTMP to RTC, fail if disabled and RTMP is active, see https://github.com/ossrs/srs/issues/2728 // For RTMP to RTC, fail if disabled and RTMP is active, see https://github.com/ossrs/srs/issues/2728
if (!is_rtc_stream_active && !_srs_config->get_rtc_from_rtmp(ruc->req_->vhost)) { if (!is_rtc_stream_active && !_srs_config->get_rtc_from_rtmp(ruc->req_->vhost_)) {
SrsSharedPtr<SrsLiveSource> live_source = _srs_sources->fetch(ruc->req_); SrsSharedPtr<SrsLiveSource> live_source = _srs_sources->fetch(ruc->req_);
if (live_source.get() && !live_source->inactive()) { if (live_source.get() && !live_source->inactive()) {
return srs_error_new(ERROR_RTC_DISABLED, "Disabled rtmp_to_rtc of %s, see #2728", ruc->req_->vhost.c_str()); return srs_error_new(ERROR_RTC_DISABLED, "Disabled rtmp_to_rtc of %s, see #2728", ruc->req_->vhost_.c_str());
} }
} }
if ((err = security_->check(SrsRtcConnPlay, ruc->req_->ip, ruc->req_)) != srs_success) { if ((err = security_->check(SrsRtcConnPlay, ruc->req_->ip_, ruc->req_)) != srs_success) {
return srs_error_wrap(err, "RTC: security check"); return srs_error_wrap(err, "RTC: security check");
} }
@ -297,7 +297,7 @@ srs_error_t SrsGoApiRtcPlay::http_hooks_on_play(ISrsRequest *req)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -307,7 +307,7 @@ srs_error_t SrsGoApiRtcPlay::http_hooks_on_play(ISrsRequest *req)
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_play(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_play(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -422,20 +422,20 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter *w, ISrsHtt
// The RTC user config object. // The RTC user config object.
SrsRtcUserConfig ruc; SrsRtcUserConfig ruc;
ruc.req_->ip = clientip; ruc.req_->ip_ = clientip;
ruc.api_ = api; ruc.api_ = api;
srs_net_url_parse_rtmp_url(streamurl, ruc.req_->tcUrl, ruc.req_->stream); srs_net_url_parse_rtmp_url(streamurl, ruc.req_->tcUrl_, ruc.req_->stream_);
srs_net_url_parse_tcurl(ruc.req_->tcUrl, ruc.req_->schema, ruc.req_->host, ruc.req_->vhost, srs_net_url_parse_tcurl(ruc.req_->tcUrl_, ruc.req_->schema_, ruc.req_->host_, ruc.req_->vhost_,
ruc.req_->app, ruc.req_->stream, ruc.req_->port, ruc.req_->param); ruc.req_->app_, ruc.req_->stream_, ruc.req_->port_, ruc.req_->param_);
// Identify WebRTC publisher by param upstream=rtc // Identify WebRTC publisher by param upstream=rtc
ruc.req_->param = srs_strings_trim_start(ruc.req_->param + "&upstream=rtc", "&"); ruc.req_->param_ = srs_strings_trim_start(ruc.req_->param_ + "&upstream=rtc", "&");
// discovery vhost, resolve the vhost from config // discovery vhost, resolve the vhost from config
SrsConfDirective *parsed_vhost = _srs_config->get_vhost(ruc.req_->vhost); SrsConfDirective *parsed_vhost = _srs_config->get_vhost(ruc.req_->vhost_);
if (parsed_vhost) { if (parsed_vhost) {
ruc.req_->vhost = parsed_vhost->arg0(); ruc.req_->vhost_ = parsed_vhost->arg0();
} }
// For client to specifies the candidate(EIP) of server. // For client to specifies the candidate(EIP) of server.
@ -446,7 +446,7 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter *w, ISrsHtt
string codec = r->query_get("codec"); string codec = r->query_get("codec");
srs_trace("RTC publish %s, api=%s, tid=%s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s", srs_trace("RTC publish %s, api=%s, tid=%s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s",
streamurl.c_str(), api.c_str(), tid.c_str(), clientip.c_str(), ruc.req_->app.c_str(), ruc.req_->stream.c_str(), streamurl.c_str(), api.c_str(), tid.c_str(), clientip.c_str(), ruc.req_->app_.c_str(), ruc.req_->stream_.c_str(),
remote_sdp_str.length(), eip.c_str(), codec.c_str()); remote_sdp_str.length(), eip.c_str(), codec.c_str());
ruc.eip_ = eip; ruc.eip_ = eip;
@ -488,18 +488,18 @@ srs_error_t SrsGoApiRtcPublish::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMe
// TODO: FIXME: move to create_session. // TODO: FIXME: move to create_session.
// Config for SDP and session. // Config for SDP and session.
local_sdp.session_config_.dtls_role = _srs_config->get_rtc_dtls_role(ruc->req_->vhost); local_sdp.session_config_.dtls_role = _srs_config->get_rtc_dtls_role(ruc->req_->vhost_);
local_sdp.session_config_.dtls_version = _srs_config->get_rtc_dtls_version(ruc->req_->vhost); local_sdp.session_config_.dtls_version = _srs_config->get_rtc_dtls_version(ruc->req_->vhost_);
// Whether enabled. // Whether enabled.
bool server_enabled = _srs_config->get_rtc_server_enabled(); bool server_enabled = _srs_config->get_rtc_server_enabled();
bool rtc_enabled = _srs_config->get_rtc_enabled(ruc->req_->vhost); bool rtc_enabled = _srs_config->get_rtc_enabled(ruc->req_->vhost_);
if (server_enabled && !rtc_enabled) { if (server_enabled && !rtc_enabled) {
srs_warn("RTC disabled in vhost %s", ruc->req_->vhost.c_str()); srs_warn("RTC disabled in vhost %s", ruc->req_->vhost_.c_str());
} }
if (!server_enabled || !rtc_enabled) { if (!server_enabled || !rtc_enabled) {
return srs_error_new(ERROR_RTC_DISABLED, "Disabled server=%d, rtc=%d, vhost=%s", return srs_error_new(ERROR_RTC_DISABLED, "Disabled server=%d, rtc=%d, vhost=%s",
server_enabled, rtc_enabled, ruc->req_->vhost.c_str()); server_enabled, rtc_enabled, ruc->req_->vhost_.c_str());
} }
// TODO: FIXME: When server enabled, but vhost disabled, should report error. // TODO: FIXME: When server enabled, but vhost disabled, should report error.
@ -509,7 +509,7 @@ srs_error_t SrsGoApiRtcPublish::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMe
return srs_error_wrap(err, "create session"); return srs_error_wrap(err, "create session");
} }
if ((err = security_->check(SrsRtcConnPublish, ruc->req_->ip, ruc->req_)) != srs_success) { if ((err = security_->check(SrsRtcConnPublish, ruc->req_->ip_, ruc->req_)) != srs_success) {
return srs_error_wrap(err, "RTC: security check"); return srs_error_wrap(err, "RTC: security check");
} }
@ -572,7 +572,7 @@ srs_error_t SrsGoApiRtcPublish::http_hooks_on_publish(ISrsRequest *req)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -582,7 +582,7 @@ srs_error_t SrsGoApiRtcPublish::http_hooks_on_publish(ISrsRequest *req)
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_publish(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_publish(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
} }
@ -657,7 +657,7 @@ srs_error_t SrsGoApiRtcWhip::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
w->header()->set("Content-Type", "application/sdp"); w->header()->set("Content-Type", "application/sdp");
// The location for DELETE resource, not required by SRS, but required by WHIP. // The location for DELETE resource, not required by SRS, but required by WHIP.
w->header()->set("Location", srs_fmt_sprintf("/rtc/v1/whip/?action=delete&token=%s&app=%s&stream=%s&session=%s", w->header()->set("Location", srs_fmt_sprintf("/rtc/v1/whip/?action=delete&token=%s&app=%s&stream=%s&session=%s",
ruc.token_.c_str(), ruc.req_->app.c_str(), ruc.req_->stream.c_str(), ruc.session_id_.c_str())); ruc.token_.c_str(), ruc.req_->app_.c_str(), ruc.req_->stream_.c_str(), ruc.session_id_.c_str()));
w->header()->set_content_length((int64_t)sdp.length()); w->header()->set_content_length((int64_t)sdp.length());
// Must be 201, see https://datatracker.ietf.org/doc/draft-ietf-wish-whip/ // Must be 201, see https://datatracker.ietf.org/doc/draft-ietf-wish-whip/
w->write_header(201); w->write_header(201);
@ -703,12 +703,12 @@ srs_error_t SrsGoApiRtcWhip::do_serve_http(ISrsHttpResponseWriter *w, ISrsHttpMe
} }
// The RTC user config object. // The RTC user config object.
ruc->req_->ip = clientip; ruc->req_->ip_ = clientip;
ruc->req_->host = r->host(); ruc->req_->host_ = r->host();
ruc->req_->vhost = ruc->req_->host; ruc->req_->vhost_ = ruc->req_->host_;
ruc->req_->app = app.empty() ? "live" : app; ruc->req_->app_ = app.empty() ? "live" : app;
ruc->req_->stream = stream.empty() ? "livestream" : stream; ruc->req_->stream_ = stream.empty() ? "livestream" : stream;
ruc->req_->param = r->query(); ruc->req_->param_ = r->query();
ruc->req_->ice_ufrag_ = r->query_get("ice-ufrag"); ruc->req_->ice_ufrag_ = r->query_get("ice-ufrag");
ruc->req_->ice_pwd_ = r->query_get("ice-pwd"); ruc->req_->ice_pwd_ = r->query_get("ice-pwd");
@ -720,9 +720,9 @@ srs_error_t SrsGoApiRtcWhip::do_serve_http(ISrsHttpResponseWriter *w, ISrsHttpMe
} }
// discovery vhost, resolve the vhost from config // discovery vhost, resolve the vhost from config
SrsConfDirective *parsed_vhost = _srs_config->get_vhost(ruc->req_->vhost); SrsConfDirective *parsed_vhost = _srs_config->get_vhost(ruc->req_->vhost_);
if (parsed_vhost) { if (parsed_vhost) {
ruc->req_->vhost = parsed_vhost->arg0(); ruc->req_->vhost_ = parsed_vhost->arg0();
} }
// For client to specifies whether encrypt by SRTP. // For client to specifies whether encrypt by SRTP.
@ -730,9 +730,9 @@ srs_error_t SrsGoApiRtcWhip::do_serve_http(ISrsHttpResponseWriter *w, ISrsHttpMe
string dtls = r->query_get("dtls"); string dtls = r->query_get("dtls");
srs_trace("RTC whip %s %s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s, srtp=%s, dtls=%s, ufrag=%s, pwd=%s, param=%s", srs_trace("RTC whip %s %s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, codec=%s, srtp=%s, dtls=%s, ufrag=%s, pwd=%s, param=%s",
action.c_str(), ruc->req_->get_stream_url().c_str(), clientip.c_str(), ruc->req_->app.c_str(), ruc->req_->stream.c_str(), action.c_str(), ruc->req_->get_stream_url().c_str(), clientip.c_str(), ruc->req_->app_.c_str(), ruc->req_->stream_.c_str(),
remote_sdp_str.length(), eip.c_str(), codec.c_str(), srtp.c_str(), dtls.c_str(), ruc->req_->ice_ufrag_.c_str(), remote_sdp_str.length(), eip.c_str(), codec.c_str(), srtp.c_str(), dtls.c_str(), ruc->req_->ice_ufrag_.c_str(),
ruc->req_->ice_pwd_.c_str(), ruc->req_->param.c_str()); ruc->req_->ice_pwd_.c_str(), ruc->req_->param_.c_str());
ruc->eip_ = eip; ruc->eip_ = eip;
ruc->codec_ = codec; ruc->codec_ = codec;

View File

@ -381,7 +381,7 @@ srs_error_t SrsRtcAsyncCallOnStop::call()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -391,7 +391,7 @@ srs_error_t SrsRtcAsyncCallOnStop::call()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_stop(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_stop(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -505,8 +505,8 @@ srs_error_t SrsRtcPlayStream::initialize(ISrsRequest *req, std::map<uint32_t, Sr
} }
// TODO: FIXME: Support reload. // TODO: FIXME: Support reload.
nack_enabled_ = _srs_config->get_rtc_nack_enabled(req->vhost); nack_enabled_ = _srs_config->get_rtc_nack_enabled(req->vhost_);
nack_no_copy_ = _srs_config->get_rtc_nack_no_copy(req->vhost); nack_no_copy_ = _srs_config->get_rtc_nack_no_copy(req->vhost_);
srs_trace("RTC player nack=%d, nnc=%d", nack_enabled_, nack_no_copy_); srs_trace("RTC player nack=%d, nnc=%d", nack_enabled_, nack_no_copy_);
// Setup tracks. // Setup tracks.
@ -642,8 +642,8 @@ srs_error_t SrsRtcPlayStream::cycle()
return srs_error_wrap(err, "dumps consumer, url=%s", req_->get_stream_url().c_str()); return srs_error_wrap(err, "dumps consumer, url=%s", req_->get_stream_url().c_str());
} }
realtime = _srs_config->get_realtime_enabled(req_->vhost, true); realtime = _srs_config->get_realtime_enabled(req_->vhost_, true);
mw_msgs = _srs_config->get_mw_msgs(req_->vhost, realtime, true); mw_msgs = _srs_config->get_mw_msgs(req_->vhost_, realtime, true);
// TODO: FIXME: Add cost in ms. // TODO: FIXME: Add cost in ms.
SrsContextId cid = source->source_id(); SrsContextId cid = source->source_id();
@ -1042,7 +1042,7 @@ srs_error_t SrsRtcAsyncCallOnUnpublish::call()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -1052,7 +1052,7 @@ srs_error_t SrsRtcAsyncCallOnUnpublish::call()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_unpublish(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_unpublish(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -1176,10 +1176,10 @@ srs_error_t SrsRtcPublishStream::initialize(ISrsRequest *r, SrsRtcSourceDescript
rtcp_twcc_.set_media_ssrc(media_ssrc); rtcp_twcc_.set_media_ssrc(media_ssrc);
} }
nack_enabled_ = _srs_config->get_rtc_nack_enabled(req_->vhost); nack_enabled_ = _srs_config->get_rtc_nack_enabled(req_->vhost_);
nack_no_copy_ = _srs_config->get_rtc_nack_no_copy(req_->vhost); nack_no_copy_ = _srs_config->get_rtc_nack_no_copy(req_->vhost_);
pt_to_drop_ = (uint16_t)_srs_config->get_rtc_drop_for_pt(req_->vhost); pt_to_drop_ = (uint16_t)_srs_config->get_rtc_drop_for_pt(req_->vhost_);
twcc_enabled_ = _srs_config->get_rtc_twcc_enabled(req_->vhost); twcc_enabled_ = _srs_config->get_rtc_twcc_enabled(req_->vhost_);
// No TWCC when negotiate, disable it. // No TWCC when negotiate, disable it.
if (twcc_id <= 0) { if (twcc_id <= 0) {
@ -1213,7 +1213,7 @@ srs_error_t SrsRtcPublishStream::initialize(ISrsRequest *r, SrsRtcSourceDescript
// Check whether SRT stream is busy. // Check whether SRT stream is busy.
bool srt_server_enabled = _srs_config->get_srt_enabled(); bool srt_server_enabled = _srs_config->get_srt_enabled();
bool srt_enabled = _srs_config->get_srt_enabled(r->vhost); bool srt_enabled = _srs_config->get_srt_enabled(r->vhost_);
if (srt_server_enabled && srt_enabled) { if (srt_server_enabled && srt_enabled) {
SrsSharedPtr<SrsSrtSource> srt; SrsSharedPtr<SrsSrtSource> srt;
if ((err = _srs_srt_sources->fetch_or_create(r, srt)) != srs_success) { if ((err = _srs_srt_sources->fetch_or_create(r, srt)) != srs_success) {
@ -1227,7 +1227,7 @@ srs_error_t SrsRtcPublishStream::initialize(ISrsRequest *r, SrsRtcSourceDescript
// Bridge to rtmp // Bridge to rtmp
#if defined(SRS_FFMPEG_FIT) #if defined(SRS_FFMPEG_FIT)
bool rtc_to_rtmp = _srs_config->get_rtc_to_rtmp(req_->vhost); bool rtc_to_rtmp = _srs_config->get_rtc_to_rtmp(req_->vhost_);
if (rtc_to_rtmp) { if (rtc_to_rtmp) {
if ((err = _srs_sources->fetch_or_create(r, live_source)) != srs_success) { if ((err = _srs_sources->fetch_or_create(r, live_source)) != srs_success) {
return srs_error_wrap(err, "create source"); return srs_error_wrap(err, "create source");
@ -2052,10 +2052,10 @@ srs_error_t SrsRtcConnection::initialize(ISrsRequest *r, bool dtls, bool srtp, s
} }
// TODO: FIXME: Support reload. // TODO: FIXME: Support reload.
session_timeout = _srs_config->get_rtc_stun_timeout(req_->vhost); session_timeout = _srs_config->get_rtc_stun_timeout(req_->vhost_);
last_stun_time = srs_time_now_cached(); last_stun_time = srs_time_now_cached();
nack_enabled_ = _srs_config->get_rtc_nack_enabled(req_->vhost); nack_enabled_ = _srs_config->get_rtc_nack_enabled(req_->vhost_);
srs_trace("RTC init session, user=%s, url=%s, encrypt=%u/%u, DTLS(role=%s, version=%s), timeout=%dms, nack=%d", srs_trace("RTC init session, user=%s, url=%s, encrypt=%u/%u, DTLS(role=%s, version=%s), timeout=%dms, nack=%d",
username.c_str(), r->get_stream_url().c_str(), dtls, srtp, cfg->dtls_role.c_str(), cfg->dtls_version.c_str(), username.c_str(), r->get_stream_url().c_str(), dtls, srtp, cfg->dtls_role.c_str(), cfg->dtls_version.c_str(),
@ -2564,7 +2564,7 @@ srs_error_t SrsRtcConnection::on_binding_request(SrsStunPacket *r, string &ice_p
++_srs_pps_sstuns->sugar_; ++_srs_pps_sstuns->sugar_;
bool strict_check = _srs_config->get_rtc_stun_strict_check(req_->vhost); bool strict_check = _srs_config->get_rtc_stun_strict_check(req_->vhost_);
if (strict_check && r->get_ice_controlled()) { if (strict_check && r->get_ice_controlled()) {
// @see: https://tools.ietf.org/html/draft-ietf-ice-rfc5245bis-00#section-6.1.3.1 // @see: https://tools.ietf.org/html/draft-ietf-ice-rfc5245bis-00#section-6.1.3.1
// TODO: Send 487 (Role Conflict) error response. // TODO: Send 487 (Role Conflict) error response.
@ -2679,8 +2679,8 @@ srs_error_t SrsRtcConnection::negotiate_publish_capability(SrsRtcUserConfig *ruc
ISrsRequest *req = ruc->req_; ISrsRequest *req = ruc->req_;
const SrsSdp &remote_sdp = ruc->remote_sdp_; const SrsSdp &remote_sdp = ruc->remote_sdp_;
bool nack_enabled = _srs_config->get_rtc_nack_enabled(req->vhost); bool nack_enabled = _srs_config->get_rtc_nack_enabled(req->vhost_);
bool twcc_enabled = _srs_config->get_rtc_twcc_enabled(req->vhost); bool twcc_enabled = _srs_config->get_rtc_twcc_enabled(req->vhost_);
// TODO: FIME: Should check packetization-mode=1 also. // TODO: FIME: Should check packetization-mode=1 also.
bool has_42e01f = srs_sdp_has_h264_profile(remote_sdp, "42e01f"); bool has_42e01f = srs_sdp_has_h264_profile(remote_sdp, "42e01f");
@ -2989,7 +2989,7 @@ srs_error_t SrsRtcConnection::generate_publish_local_sdp(ISrsRequest *req, SrsSd
local_sdp.session_name_ = "SRSPublishSession"; local_sdp.session_name_ = "SRSPublishSession";
local_sdp.msid_semantic_ = "WMS"; local_sdp.msid_semantic_ = "WMS";
std::string stream_id = req->app + "/" + req->stream; std::string stream_id = req->app_ + "/" + req->stream_;
local_sdp.msids_.push_back(stream_id); local_sdp.msids_.push_back(stream_id);
local_sdp.group_policy_ = "BUNDLE"; local_sdp.group_policy_ = "BUNDLE";
@ -3111,8 +3111,8 @@ srs_error_t SrsRtcConnection::negotiate_play_capability(SrsRtcUserConfig *ruc, s
ISrsRequest *req = ruc->req_; ISrsRequest *req = ruc->req_;
const SrsSdp &remote_sdp = ruc->remote_sdp_; const SrsSdp &remote_sdp = ruc->remote_sdp_;
bool nack_enabled = _srs_config->get_rtc_nack_enabled(req->vhost); bool nack_enabled = _srs_config->get_rtc_nack_enabled(req->vhost_);
bool twcc_enabled = _srs_config->get_rtc_twcc_enabled(req->vhost); bool twcc_enabled = _srs_config->get_rtc_twcc_enabled(req->vhost_);
SrsSharedPtr<SrsRtcSource> source; SrsSharedPtr<SrsRtcSource> source;
if ((err = _srs_rtc_sources->fetch_or_create(req, source)) != srs_success) { if ((err = _srs_rtc_sources->fetch_or_create(req, source)) != srs_success) {
@ -3367,7 +3367,7 @@ srs_error_t SrsRtcConnection::generate_play_local_sdp(ISrsRequest *req, SrsSdp &
local_sdp.session_name_ = "SRSPlaySession"; local_sdp.session_name_ = "SRSPlaySession";
local_sdp.msid_semantic_ = "WMS"; local_sdp.msid_semantic_ = "WMS";
std::string stream_id = req->app + "/" + req->stream; std::string stream_id = req->app_ + "/" + req->stream_;
local_sdp.msids_.push_back(stream_id); local_sdp.msids_.push_back(stream_id);
local_sdp.group_policy_ = "BUNDLE"; local_sdp.group_policy_ = "BUNDLE";

View File

@ -229,8 +229,8 @@ set<string> discover_candidates(SrsRtcUserConfig *ruc)
} }
// Try to discover from api of request, if api_as_candidates enabled. // Try to discover from api of request, if api_as_candidates enabled.
if ((err = api_server_as_candidates(ruc->req_->host, candidate_ips)) != srs_success) { if ((err = api_server_as_candidates(ruc->req_->host_, candidate_ips)) != srs_success) {
srs_warn("ignore discovering ip from api %s, err %s", ruc->req_->host.c_str(), srs_error_summary(err).c_str()); srs_warn("ignore discovering ip from api %s, err %s", ruc->req_->host_.c_str(), srs_error_summary(err).c_str());
srs_freep(err); srs_freep(err);
} }

View File

@ -689,7 +689,7 @@ srs_error_t SrsRtcSource::on_publish()
} }
// The PLI interval for RTC2RTMP. // The PLI interval for RTC2RTMP.
pli_for_rtmp_ = _srs_config->get_rtc_pli_for_rtmp(req->vhost); pli_for_rtmp_ = _srs_config->get_rtc_pli_for_rtmp(req->vhost_);
// @see SrsRtcSource::on_timer() // @see SrsRtcSource::on_timer()
_srs_shared_timer->timer100ms()->subscribe(this); _srs_shared_timer->timer100ms()->subscribe(this);
@ -975,10 +975,10 @@ srs_error_t SrsRtcRtpBuilder::initialize(ISrsRequest *r)
} }
// Setup the SPS/PPS parsing strategy. // Setup the SPS/PPS parsing strategy.
format->try_annexb_first_ = _srs_config->try_annexb_first(r->vhost); format->try_annexb_first_ = _srs_config->try_annexb_first(r->vhost_);
keep_bframe = _srs_config->get_rtc_keep_bframe(req->vhost); keep_bframe = _srs_config->get_rtc_keep_bframe(req->vhost_);
keep_avc_nalu_sei = _srs_config->get_rtc_keep_avc_nalu_sei(req->vhost); keep_avc_nalu_sei = _srs_config->get_rtc_keep_avc_nalu_sei(req->vhost_);
merge_nalus = _srs_config->get_rtc_server_merge_nalus(); merge_nalus = _srs_config->get_rtc_server_merge_nalus();
srs_trace("RTC bridge from RTMP, keep_bframe=%d, keep_avc_nalu_sei=%d, merge_nalus=%d", srs_trace("RTC bridge from RTMP, keep_bframe=%d, keep_avc_nalu_sei=%d, merge_nalus=%d",
keep_bframe, keep_avc_nalu_sei, merge_nalus); keep_bframe, keep_avc_nalu_sei, merge_nalus);
@ -1098,7 +1098,7 @@ srs_error_t SrsRtcRtpBuilder::init_codec(SrsAudioCodecId codec)
codec_ = new SrsAudioTranscoder(); codec_ = new SrsAudioTranscoder();
// Initialize the codec according to the codec in stream. // Initialize the codec according to the codec in stream.
int bitrate = _srs_config->get_rtc_opus_bitrate(req->vhost); // The output bitrate in bps. int bitrate = _srs_config->get_rtc_opus_bitrate(req->vhost_); // The output bitrate in bps.
if ((err = codec_->initialize(codec, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate, bitrate)) != srs_success) { if ((err = codec_->initialize(codec, SrsAudioCodecIdOpus, kAudioChannel, kAudioSamplerate, bitrate)) != srs_success) {
return srs_error_wrap(err, "init codec=%d", codec); return srs_error_wrap(err, "init codec=%d", codec);
} }
@ -1767,10 +1767,10 @@ srs_error_t SrsRtcFrameBuilder::initialize(ISrsRequest *r, SrsAudioCodecId audio
srs_freep(audio_transcoder_); srs_freep(audio_transcoder_);
audio_transcoder_ = new SrsAudioTranscoder(); audio_transcoder_ = new SrsAudioTranscoder();
SrsAudioCodecId to = SrsAudioCodecIdAAC; // The output audio codec. SrsAudioCodecId to = SrsAudioCodecIdAAC; // The output audio codec.
int channels = 2; // The output audio channels. int channels = 2; // The output audio channels.
int sample_rate = 48000; // The output audio sample rate in HZ. int sample_rate = 48000; // The output audio sample rate in HZ.
int bitrate = _srs_config->get_rtc_aac_bitrate(r->vhost); // The output audio bitrate in bps. int bitrate = _srs_config->get_rtc_aac_bitrate(r->vhost_); // The output audio bitrate in bps.
// TODO: FIXME: // TODO: FIXME:
// In the future, when we support enhanced-RTMP with Opus format, // In the future, when we support enhanced-RTMP with Opus format,

View File

@ -74,7 +74,7 @@ srs_error_t SrsSimpleRtmpClient::connect_app()
srs_assert(_srs_config->get_stats_network() < (int)ips.size()); srs_assert(_srs_config->get_stats_network() < (int)ips.size());
SrsIPAddress *local_ip = ips[_srs_config->get_stats_network()]; SrsIPAddress *local_ip = ips[_srs_config->get_stats_network()];
bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req->vhost); bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req_->vhost_);
return do_connect_app(local_ip->ip, debug_srs_upnode); return do_connect_app(local_ip->ip, debug_srs_upnode);
} }
@ -286,31 +286,31 @@ srs_error_t SrsRtmpConn::do_cycle()
} }
// set client ip to request. // set client ip to request.
req->ip = ip; req->ip_ = ip;
srs_trace("connect app, tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%d, app=%s, args=%s", srs_trace("connect app, tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%d, app=%s, args=%s",
req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(), req->tcUrl_.c_str(), req->pageUrl_.c_str(), req->swfUrl_.c_str(),
req->schema.c_str(), req->vhost.c_str(), req->port, req->schema_.c_str(), req->vhost_.c_str(), req->port_,
req->app.c_str(), (req->args ? "(obj)" : "null")); req->app_.c_str(), (req->args_ ? "(obj)" : "null"));
// show client identity // show client identity
if (req->args) { if (req->args_) {
std::string srs_version; std::string srs_version;
std::string srs_server_ip; std::string srs_server_ip;
int srs_pid = 0; int srs_pid = 0;
int srs_id = 0; int srs_id = 0;
SrsAmf0Any *prop = NULL; SrsAmf0Any *prop = NULL;
if ((prop = req->args->ensure_property_string("srs_version")) != NULL) { if ((prop = req->args_->ensure_property_string("srs_version")) != NULL) {
srs_version = prop->to_str(); srs_version = prop->to_str();
} }
if ((prop = req->args->ensure_property_string("srs_server_ip")) != NULL) { if ((prop = req->args_->ensure_property_string("srs_server_ip")) != NULL) {
srs_server_ip = prop->to_str(); srs_server_ip = prop->to_str();
} }
if ((prop = req->args->ensure_property_number("srs_pid")) != NULL) { if ((prop = req->args_->ensure_property_number("srs_pid")) != NULL) {
srs_pid = (int)prop->to_number(); srs_pid = (int)prop->to_number();
} }
if ((prop = req->args->ensure_property_number("srs_id")) != NULL) { if ((prop = req->args_->ensure_property_number("srs_id")) != NULL) {
srs_id = (int)prop->to_number(); srs_id = (int)prop->to_number();
} }
@ -349,12 +349,12 @@ srs_error_t SrsRtmpConn::service_cycle()
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
int out_ack_size = _srs_config->get_out_ack_size(req->vhost); int out_ack_size = _srs_config->get_out_ack_size(req->vhost_);
if (out_ack_size && (err = rtmp->set_window_ack_size(out_ack_size)) != srs_success) { if (out_ack_size && (err = rtmp->set_window_ack_size(out_ack_size)) != srs_success) {
return srs_error_wrap(err, "rtmp: set out window ack size"); return srs_error_wrap(err, "rtmp: set out window ack size");
} }
int in_ack_size = _srs_config->get_in_ack_size(req->vhost); int in_ack_size = _srs_config->get_in_ack_size(req->vhost_);
if (in_ack_size && (err = rtmp->set_in_window_ack_size(in_ack_size)) != srs_success) { if (in_ack_size && (err = rtmp->set_in_window_ack_size(in_ack_size)) != srs_success) {
return srs_error_wrap(err, "rtmp: set in window ack size"); return srs_error_wrap(err, "rtmp: set in window ack size");
} }
@ -369,7 +369,7 @@ srs_error_t SrsRtmpConn::service_cycle()
// set chunk size to larger. // set chunk size to larger.
// set the chunk size before any larger response greater than 128, // set the chunk size before any larger response greater than 128,
// to make OBS happy, @see https://github.com/ossrs/srs/issues/454 // to make OBS happy, @see https://github.com/ossrs/srs/issues/454
int chunk_size = _srs_config->get_chunk_size(req->vhost); int chunk_size = _srs_config->get_chunk_size(req->vhost_);
if ((err = rtmp->set_chunk_size(chunk_size)) != srs_success) { if ((err = rtmp->set_chunk_size(chunk_size)) != srs_success) {
return srs_error_wrap(err, "rtmp: set chunk size %d", chunk_size); return srs_error_wrap(err, "rtmp: set chunk size %d", chunk_size);
} }
@ -443,32 +443,32 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
srs_error_t err = srs_success; srs_error_t err = srs_success;
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if ((err = rtmp->identify_client(info->res->stream_id, info->type, req->stream, req->duration)) != srs_success) { if ((err = rtmp->identify_client(info->res->stream_id_, info->type, req->stream_, req->duration_)) != srs_success) {
return srs_error_wrap(err, "rtmp: identify client"); return srs_error_wrap(err, "rtmp: identify client");
} }
srs_net_url_parse_tcurl(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param); srs_net_url_parse_tcurl(req->tcUrl_, req->schema_, req->host_, req->vhost_, req->app_, req->stream_, req->port_, req->param_);
// guess stream name // guess stream name
if (req->stream.empty()) { if (req->stream_.empty()) {
string app = req->app, param = req->param; string app = req->app_, param = req->param_;
srs_net_url_guess_stream(req->app, req->param, req->stream); srs_net_url_guess_stream(req->app_, req->param_, req->stream_);
srs_trace("Guessing by app=%s, param=%s to app=%s, param=%s, stream=%s", app.c_str(), param.c_str(), req->app.c_str(), req->param.c_str(), req->stream.c_str()); srs_trace("Guessing by app=%s, param=%s to app=%s, param=%s, stream=%s", app.c_str(), param.c_str(), req->app_.c_str(), req->param_.c_str(), req->stream_.c_str());
} }
req->strip(); req->strip();
srs_trace("client identified, type=%s, vhost=%s, app=%s, stream=%s, param=%s, duration=%dms", srs_trace("client identified, type=%s, vhost=%s, app=%s, stream=%s, param=%s, duration=%dms",
srs_client_type_string(info->type).c_str(), req->vhost.c_str(), req->app.c_str(), req->stream.c_str(), req->param.c_str(), srsu2msi(req->duration)); srs_client_type_string(info->type).c_str(), req->vhost_.c_str(), req->app_.c_str(), req->stream_.c_str(), req->param_.c_str(), srsu2msi(req->duration_));
// discovery vhost, resolve the vhost from config // discovery vhost, resolve the vhost from config
SrsConfDirective *parsed_vhost = _srs_config->get_vhost(req->vhost); SrsConfDirective *parsed_vhost = _srs_config->get_vhost(req->vhost_);
if (parsed_vhost) { if (parsed_vhost) {
req->vhost = parsed_vhost->arg0(); req->vhost_ = parsed_vhost->arg0();
} }
if (req->schema.empty() || req->vhost.empty() || req->port == 0 || req->app.empty()) { if (req->schema_.empty() || req->vhost_.empty() || req->port_ == 0 || req->app_.empty()) {
return srs_error_new(ERROR_RTMP_REQ_TCURL, "discovery tcUrl failed, tcUrl=%s, schema=%s, vhost=%s, port=%d, app=%s", return srs_error_new(ERROR_RTMP_REQ_TCURL, "discovery tcUrl failed, tcUrl=%s, schema=%s, vhost=%s, port=%d, app=%s",
req->tcUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port, req->app.c_str()); req->tcUrl_.c_str(), req->schema_.c_str(), req->vhost_.c_str(), req->port_, req->app_.c_str());
} }
// check vhost, allow default vhost. // check vhost, allow default vhost.
@ -477,14 +477,14 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
} }
srs_trace("connected stream, tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%d, app=%s, stream=%s, param=%s, args=%s", srs_trace("connected stream, tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%d, app=%s, stream=%s, param=%s, args=%s",
req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port, req->tcUrl_.c_str(), req->pageUrl_.c_str(), req->swfUrl_.c_str(), req->schema_.c_str(), req->vhost_.c_str(), req->port_,
req->app.c_str(), req->stream.c_str(), req->param.c_str(), (req->args ? "(obj)" : "null")); req->app_.c_str(), req->stream_.c_str(), req->param_.c_str(), (req->args_ ? "(obj)" : "null"));
// do token traverse before serve it. // do token traverse before serve it.
// @see https://github.com/ossrs/srs/pull/239 // @see https://github.com/ossrs/srs/pull/239
if (true) { if (true) {
info->edge = _srs_config->get_vhost_is_edge(req->vhost); info->edge = _srs_config->get_vhost_is_edge(req->vhost_);
bool edge_traverse = _srs_config->get_vhost_edge_token_traverse(req->vhost); bool edge_traverse = _srs_config->get_vhost_edge_token_traverse(req->vhost_);
if (info->edge && edge_traverse) { if (info->edge && edge_traverse) {
if ((err = check_edge_token_traverse_auth()) != srs_success) { if ((err = check_edge_token_traverse_auth()) != srs_success) {
return srs_error_wrap(err, "rtmp: check token traverse"); return srs_error_wrap(err, "rtmp: check token traverse");
@ -499,7 +499,7 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
// Never allow the empty stream name, for HLS may write to a file with empty name. // Never allow the empty stream name, for HLS may write to a file with empty name.
// @see https://github.com/ossrs/srs/issues/834 // @see https://github.com/ossrs/srs/issues/834
if (req->stream.empty()) { if (req->stream_.empty()) {
return srs_error_new(ERROR_RTMP_STREAM_NAME_EMPTY, "rtmp: empty stream"); return srs_error_new(ERROR_RTMP_STREAM_NAME_EMPTY, "rtmp: empty stream");
} }
@ -525,8 +525,8 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
} }
srs_assert(live_source.get() != NULL); srs_assert(live_source.get() != NULL);
bool enabled_cache = _srs_config->get_gop_cache(req->vhost); bool enabled_cache = _srs_config->get_gop_cache(req->vhost_);
int gcmf = _srs_config->get_gop_cache_max_frames(req->vhost); int gcmf = _srs_config->get_gop_cache_max_frames(req->vhost_);
srs_trace("source url=%s, ip=%s, cache=%d/%d, is_edge=%d, source_id=%s/%s", srs_trace("source url=%s, ip=%s, cache=%d/%d, is_edge=%d, source_id=%s/%s",
req->get_stream_url().c_str(), ip.c_str(), enabled_cache, gcmf, info->edge, live_source->source_id().c_str(), req->get_stream_url().c_str(), ip.c_str(), enabled_cache, gcmf, info->edge, live_source->source_id().c_str(),
live_source->pre_source_id().c_str()); live_source->pre_source_id().c_str());
@ -536,7 +536,7 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
switch (info->type) { switch (info->type) {
case SrsRtmpConnPlay: { case SrsRtmpConnPlay: {
// response connection start play // response connection start play
if ((err = rtmp->start_play(info->res->stream_id)) != srs_success) { if ((err = rtmp->start_play(info->res->stream_id_)) != srs_success) {
return srs_error_wrap(err, "rtmp: start play"); return srs_error_wrap(err, "rtmp: start play");
} }
@ -564,7 +564,7 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
return err; return err;
} }
case SrsRtmpConnFMLEPublish: { case SrsRtmpConnFMLEPublish: {
if ((err = rtmp->start_fmle_publish(info->res->stream_id)) != srs_success) { if ((err = rtmp->start_fmle_publish(info->res->stream_id_)) != srs_success) {
return srs_error_wrap(err, "rtmp: start FMLE publish"); return srs_error_wrap(err, "rtmp: start FMLE publish");
} }
@ -578,7 +578,7 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
return publishing(live_source); return publishing(live_source);
} }
case SrsRtmpConnHaivisionPublish: { case SrsRtmpConnHaivisionPublish: {
if ((err = rtmp->start_haivision_publish(info->res->stream_id)) != srs_success) { if ((err = rtmp->start_haivision_publish(info->res->stream_id_)) != srs_success) {
return srs_error_wrap(err, "rtmp: start HAIVISION publish"); return srs_error_wrap(err, "rtmp: start HAIVISION publish");
} }
@ -592,7 +592,7 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
return publishing(live_source); return publishing(live_source);
} }
case SrsRtmpConnFlashPublish: { case SrsRtmpConnFlashPublish: {
if ((err = rtmp->start_flash_publish(info->res->stream_id)) != srs_success) { if ((err = rtmp->start_flash_publish(info->res->stream_id_)) != srs_success) {
return srs_error_wrap(err, "rtmp: start FLASH publish"); return srs_error_wrap(err, "rtmp: start FLASH publish");
} }
@ -620,22 +620,22 @@ srs_error_t SrsRtmpConn::check_vhost(bool try_default_vhost)
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
srs_assert(req != NULL); srs_assert(req != NULL);
SrsConfDirective *vhost = _srs_config->get_vhost(req->vhost, try_default_vhost); SrsConfDirective *vhost = _srs_config->get_vhost(req->vhost_, try_default_vhost);
if (vhost == NULL) { if (vhost == NULL) {
return srs_error_new(ERROR_RTMP_VHOST_NOT_FOUND, "rtmp: no vhost %s", req->vhost.c_str()); return srs_error_new(ERROR_RTMP_VHOST_NOT_FOUND, "rtmp: no vhost %s", req->vhost_.c_str());
} }
if (!_srs_config->get_vhost_enabled(req->vhost)) { if (!_srs_config->get_vhost_enabled(req->vhost_)) {
return srs_error_new(ERROR_RTMP_VHOST_NOT_FOUND, "rtmp: vhost %s disabled", req->vhost.c_str()); return srs_error_new(ERROR_RTMP_VHOST_NOT_FOUND, "rtmp: vhost %s disabled", req->vhost_.c_str());
} }
if (req->vhost != vhost->arg0()) { if (req->vhost_ != vhost->arg0()) {
srs_trace("vhost change from %s to %s", req->vhost.c_str(), vhost->arg0().c_str()); srs_trace("vhost change from %s to %s", req->vhost_.c_str(), vhost->arg0().c_str());
req->vhost = vhost->arg0(); req->vhost_ = vhost->arg0();
} }
if (_srs_config->get_refer_enabled(req->vhost)) { if (_srs_config->get_refer_enabled(req->vhost_)) {
if ((err = refer->check(req->pageUrl, _srs_config->get_refer_all(req->vhost))) != srs_success) { if ((err = refer->check(req->pageUrl_, _srs_config->get_refer_all(req->vhost_))) != srs_success) {
return srs_error_wrap(err, "rtmp: referer check"); return srs_error_wrap(err, "rtmp: referer check");
} }
} }
@ -653,23 +653,23 @@ srs_error_t SrsRtmpConn::playing(SrsSharedPtr<SrsLiveSource> source)
// Check page referer of player. // Check page referer of player.
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if (_srs_config->get_refer_enabled(req->vhost)) { if (_srs_config->get_refer_enabled(req->vhost_)) {
if ((err = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != srs_success) { if ((err = refer->check(req->pageUrl_, _srs_config->get_refer_play(req->vhost_))) != srs_success) {
return srs_error_wrap(err, "rtmp: referer check"); return srs_error_wrap(err, "rtmp: referer check");
} }
} }
// When origin cluster enabled, try to redirect to the origin which is active. // When origin cluster enabled, try to redirect to the origin which is active.
// A active origin is a server which is delivering stream. // A active origin is a server which is delivering stream.
if (!info->edge && _srs_config->get_vhost_origin_cluster(req->vhost) && source->inactive()) { if (!info->edge && _srs_config->get_vhost_origin_cluster(req->vhost_) && source->inactive()) {
vector<string> coworkers = _srs_config->get_vhost_coworkers(req->vhost); vector<string> coworkers = _srs_config->get_vhost_coworkers(req->vhost_);
for (int i = 0; i < (int)coworkers.size(); i++) { for (int i = 0; i < (int)coworkers.size(); i++) {
// TODO: FIXME: User may config the server itself as coworker, we must identify and ignore it. // TODO: FIXME: User may config the server itself as coworker, we must identify and ignore it.
string host; string host;
int port = 0; int port = 0;
string coworker = coworkers.at(i); string coworker = coworkers.at(i);
string url = "http://" + coworker + "/api/v1/clusters?" + "vhost=" + req->vhost + "&ip=" + req->host + "&app=" + req->app + "&stream=" + req->stream + "&coworker=" + coworker; string url = "http://" + coworker + "/api/v1/clusters?" + "vhost=" + req->vhost_ + "&ip=" + req->host_ + "&app=" + req->app_ + "&stream=" + req->stream_ + "&coworker=" + coworker;
if ((err = _srs_hooks->discover_co_workers(url, host, port)) != srs_success) { if ((err = _srs_hooks->discover_co_workers(url, host, port)) != srs_success) {
// If failed to discovery stream in this coworker, we should request the next one util the last. // If failed to discovery stream in this coworker, we should request the next one util the last.
// @see https://github.com/ossrs/srs/issues/1223 // @see https://github.com/ossrs/srs/issues/1223
@ -679,9 +679,9 @@ srs_error_t SrsRtmpConn::playing(SrsSharedPtr<SrsLiveSource> source)
return srs_error_wrap(err, "discover coworkers, url=%s", url.c_str()); return srs_error_wrap(err, "discover coworkers, url=%s", url.c_str());
} }
string rurl = srs_net_url_encode_rtmp_url(host, port, req->host, req->vhost, req->app, req->stream, req->param); string rurl = srs_net_url_encode_rtmp_url(host, port, req->host_, req->vhost_, req->app_, req->stream_, req->param_);
srs_trace("rtmp: redirect in cluster, from=%s:%d, target=%s:%d, url=%s, rurl=%s", srs_trace("rtmp: redirect in cluster, from=%s:%d, target=%s:%d, url=%s, rurl=%s",
req->host.c_str(), req->port, host.c_str(), port, url.c_str(), rurl.c_str()); req->host_.c_str(), req->port_, host.c_str(), port, url.c_str(), rurl.c_str());
// Ignore if host or port is invalid. // Ignore if host or port is invalid.
if (host.empty() || port == 0) { if (host.empty() || port == 0) {
@ -747,18 +747,18 @@ srs_error_t SrsRtmpConn::do_playing(SrsSharedPtr<SrsLiveSource> source, SrsLiveC
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_rtmp_play()); SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_rtmp_play());
SrsMessageArray msgs(SRS_PERF_MW_MSGS); SrsMessageArray msgs(SRS_PERF_MW_MSGS);
bool user_specified_duration_to_stop = (req->duration > 0); bool user_specified_duration_to_stop = (req->duration_ > 0);
int64_t starttime = -1; int64_t starttime = -1;
// setup the realtime. // setup the realtime.
realtime = _srs_config->get_realtime_enabled(req->vhost); realtime = _srs_config->get_realtime_enabled(req->vhost_);
// setup the mw config. // setup the mw config.
// when mw_sleep changed, resize the socket send buffer. // when mw_sleep changed, resize the socket send buffer.
mw_msgs = _srs_config->get_mw_msgs(req->vhost, realtime); mw_msgs = _srs_config->get_mw_msgs(req->vhost_, realtime);
mw_sleep = _srs_config->get_mw_sleep(req->vhost); mw_sleep = _srs_config->get_mw_sleep(req->vhost_);
transport_->set_socket_buffer(mw_sleep); transport_->set_socket_buffer(mw_sleep);
// initialize the send_min_interval // initialize the send_min_interval
send_min_interval = _srs_config->get_send_min_interval(req->vhost); send_min_interval = _srs_config->get_send_min_interval(req->vhost_);
srs_trace("start play smi=%dms, mw_sleep=%d, mw_msgs=%d, realtime=%d, tcp_nodelay=%d", srs_trace("start play smi=%dms, mw_sleep=%d, mw_msgs=%d, realtime=%d, tcp_nodelay=%d",
srsu2msi(send_min_interval), srsu2msi(mw_sleep), mw_msgs, realtime, tcp_nodelay); srsu2msi(send_min_interval), srsu2msi(mw_sleep), mw_msgs, realtime, tcp_nodelay);
@ -825,7 +825,7 @@ srs_error_t SrsRtmpConn::do_playing(SrsSharedPtr<SrsLiveSource> source, SrsLiveC
// we start to collect the durations for each message. // we start to collect the durations for each message.
if (user_specified_duration_to_stop) { if (user_specified_duration_to_stop) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
SrsMediaPacket *msg = msgs.msgs[i]; SrsMediaPacket *msg = msgs.msgs_[i];
// foreach msg, collect the duration. // foreach msg, collect the duration.
// @remark: never use msg when sent it, for the protocol sdk will free it. // @remark: never use msg when sent it, for the protocol sdk will free it.
@ -839,15 +839,15 @@ srs_error_t SrsRtmpConn::do_playing(SrsSharedPtr<SrsLiveSource> source, SrsLiveC
// sendout messages, all messages are freed by send_and_free_messages(). // sendout messages, all messages are freed by send_and_free_messages().
// no need to assert msg, for the rtmp will assert it. // no need to assert msg, for the rtmp will assert it.
if (count > 0 && (err = rtmp->send_and_free_messages(msgs.msgs, count, info->res->stream_id)) != srs_success) { if (count > 0 && (err = rtmp->send_and_free_messages(msgs.msgs_, count, info->res->stream_id_)) != srs_success) {
return srs_error_wrap(err, "rtmp: send %d messages", count); return srs_error_wrap(err, "rtmp: send %d messages", count);
} }
// if duration specified, and exceed it, stop play live. // if duration specified, and exceed it, stop play live.
// @see: https://github.com/ossrs/srs/issues/45 // @see: https://github.com/ossrs/srs/issues/45
if (user_specified_duration_to_stop) { if (user_specified_duration_to_stop) {
if (duration >= req->duration) { if (duration >= req->duration_) {
return srs_error_new(ERROR_RTMP_DURATION_EXCEED, "rtmp: time %d up %d", srsu2msi(duration), srsu2msi(req->duration)); return srs_error_new(ERROR_RTMP_DURATION_EXCEED, "rtmp: time %d up %d", srsu2msi(duration), srsu2msi(req->duration_));
} }
} }
@ -870,8 +870,8 @@ srs_error_t SrsRtmpConn::publishing(SrsSharedPtr<SrsLiveSource> source)
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if (_srs_config->get_refer_enabled(req->vhost)) { if (_srs_config->get_refer_enabled(req->vhost_)) {
if ((err = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != srs_success) { if ((err = refer->check(req->pageUrl_, _srs_config->get_refer_publish(req->vhost_))) != srs_success) {
return srs_error_wrap(err, "rtmp: referer check"); return srs_error_wrap(err, "rtmp: referer check");
} }
} }
@ -921,16 +921,16 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSharedPtr<SrsLiveSource> source, SrsPu
} }
// initialize the publish timeout. // initialize the publish timeout.
publish_1stpkt_timeout = _srs_config->get_publish_1stpkt_timeout(req->vhost); publish_1stpkt_timeout = _srs_config->get_publish_1stpkt_timeout(req->vhost_);
publish_normal_timeout = _srs_config->get_publish_normal_timeout(req->vhost); publish_normal_timeout = _srs_config->get_publish_normal_timeout(req->vhost_);
srs_utime_t publish_kickoff_for_idle = _srs_config->get_publish_kickoff_for_idle(req->vhost); srs_utime_t publish_kickoff_for_idle = _srs_config->get_publish_kickoff_for_idle(req->vhost_);
// set the sock options. // set the sock options.
set_sock_options(); set_sock_options();
if (true) { if (true) {
bool mr = _srs_config->get_mr_enabled(req->vhost); bool mr = _srs_config->get_mr_enabled(req->vhost_);
srs_utime_t mr_sleep = _srs_config->get_mr_sleep(req->vhost); srs_utime_t mr_sleep = _srs_config->get_mr_sleep(req->vhost_);
srs_trace("start publish mr=%d/%d, p1stpt=%d, pnt=%d, tcp_nodelay=%d", mr, srsu2msi(mr_sleep), srsu2msi(publish_1stpkt_timeout), srsu2msi(publish_normal_timeout), tcp_nodelay); srs_trace("start publish mr=%d/%d, p1stpt=%d, pnt=%d, tcp_nodelay=%d", mr, srsu2msi(mr_sleep), srsu2msi(publish_1stpkt_timeout), srsu2msi(publish_normal_timeout), tcp_nodelay);
} }
@ -939,7 +939,7 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSharedPtr<SrsLiveSource> source, SrsPu
#endif #endif
// Response the start publishing message, let client start to publish messages. // Response the start publishing message, let client start to publish messages.
if ((err = rtmp->start_publishing(info->res->stream_id)) != srs_success) { if ((err = rtmp->start_publishing(info->res->stream_id_)) != srs_success) {
return srs_error_wrap(err, "start publishing"); return srs_error_wrap(err, "start publishing");
} }
@ -952,7 +952,7 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSharedPtr<SrsLiveSource> source, SrsPu
// Kick off the publisher when idle for a period of timeout. // Kick off the publisher when idle for a period of timeout.
if (source->publisher_is_idle_for(publish_kickoff_for_idle)) { if (source->publisher_is_idle_for(publish_kickoff_for_idle)) {
return srs_error_new(ERROR_KICKOFF_FOR_IDLE, "kicked for idle, url=%s, timeout=%ds", req->tcUrl.c_str(), srsu2si(publish_kickoff_for_idle)); return srs_error_new(ERROR_KICKOFF_FOR_IDLE, "kicked for idle, url=%s, timeout=%ds", req->tcUrl_.c_str(), srsu2si(publish_kickoff_for_idle));
} }
pprint->elapse(); pprint->elapse();
@ -988,8 +988,8 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSharedPtr<SrsLiveSource> source, SrsPu
// reportable // reportable
if (pprint->can_print()) { if (pprint->can_print()) {
kbps->sample(); kbps->sample();
bool mr = _srs_config->get_mr_enabled(req->vhost); bool mr = _srs_config->get_mr_enabled(req->vhost_);
srs_utime_t mr_sleep = _srs_config->get_mr_sleep(req->vhost); srs_utime_t mr_sleep = _srs_config->get_mr_sleep(req->vhost_);
srs_trace("<- " SRS_CONSTS_LOG_CLIENT_PUBLISH " time=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d, mr=%d/%d, p1stpt=%d, pnt=%d", srs_trace("<- " SRS_CONSTS_LOG_CLIENT_PUBLISH " time=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d, mr=%d/%d, p1stpt=%d, pnt=%d",
(int)pprint->age(), kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), (int)pprint->age(), kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(),
kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m(), mr, srsu2msi(mr_sleep), kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m(), mr, srsu2msi(mr_sleep),
@ -1020,7 +1020,7 @@ srs_error_t SrsRtmpConn::acquire_publish(SrsSharedPtr<SrsLiveSource> source)
// Check whether RTC stream is busy. // Check whether RTC stream is busy.
SrsSharedPtr<SrsRtcSource> rtc; SrsSharedPtr<SrsRtcSource> rtc;
bool rtc_server_enabled = _srs_config->get_rtc_server_enabled(); bool rtc_server_enabled = _srs_config->get_rtc_server_enabled();
bool rtc_enabled = _srs_config->get_rtc_enabled(req->vhost); bool rtc_enabled = _srs_config->get_rtc_enabled(req->vhost_);
if (rtc_server_enabled && rtc_enabled && !info->edge) { if (rtc_server_enabled && rtc_enabled && !info->edge) {
if ((err = _srs_rtc_sources->fetch_or_create(req, rtc)) != srs_success) { if ((err = _srs_rtc_sources->fetch_or_create(req, rtc)) != srs_success) {
return srs_error_wrap(err, "create source"); return srs_error_wrap(err, "create source");
@ -1033,7 +1033,7 @@ srs_error_t SrsRtmpConn::acquire_publish(SrsSharedPtr<SrsLiveSource> source)
// Check whether SRT stream is busy. // Check whether SRT stream is busy.
bool srt_server_enabled = _srs_config->get_srt_enabled(); bool srt_server_enabled = _srs_config->get_srt_enabled();
bool srt_enabled = _srs_config->get_srt_enabled(req->vhost); bool srt_enabled = _srs_config->get_srt_enabled(req->vhost_);
if (srt_server_enabled && srt_enabled && !info->edge) { if (srt_server_enabled && srt_enabled && !info->edge) {
SrsSharedPtr<SrsSrtSource> srt; SrsSharedPtr<SrsSrtSource> srt;
if ((err = _srs_srt_sources->fetch_or_create(req, srt)) != srs_success) { if ((err = _srs_srt_sources->fetch_or_create(req, srt)) != srs_success) {
@ -1049,7 +1049,7 @@ srs_error_t SrsRtmpConn::acquire_publish(SrsSharedPtr<SrsLiveSource> source)
// RTSP only support viewer, so we don't need to check it. // RTSP only support viewer, so we don't need to check it.
SrsSharedPtr<SrsRtspSource> rtsp; SrsSharedPtr<SrsRtspSource> rtsp;
bool rtsp_server_enabled = _srs_config->get_rtsp_server_enabled(); bool rtsp_server_enabled = _srs_config->get_rtsp_server_enabled();
bool rtsp_enabled = _srs_config->get_rtsp_enabled(req->vhost); bool rtsp_enabled = _srs_config->get_rtsp_enabled(req->vhost_);
if (rtsp_server_enabled && rtsp_enabled && !info->edge) { if (rtsp_server_enabled && rtsp_enabled && !info->edge) {
if ((err = _srs_rtsp_sources->fetch_or_create(req, rtsp)) != srs_success) { if ((err = _srs_rtsp_sources->fetch_or_create(req, rtsp)) != srs_success) {
return srs_error_wrap(err, "create source"); return srs_error_wrap(err, "create source");
@ -1062,13 +1062,13 @@ srs_error_t SrsRtmpConn::acquire_publish(SrsSharedPtr<SrsLiveSource> source)
SrsCompositeBridge *bridge = new SrsCompositeBridge(); SrsCompositeBridge *bridge = new SrsCompositeBridge();
#if defined(SRS_FFMPEG_FIT) #if defined(SRS_FFMPEG_FIT)
if (rtc.get() && _srs_config->get_rtc_from_rtmp(req->vhost)) { if (rtc.get() && _srs_config->get_rtc_from_rtmp(req->vhost_)) {
bridge->append(new SrsFrameToRtcBridge(rtc)); bridge->append(new SrsFrameToRtcBridge(rtc));
} }
#endif #endif
#ifdef SRS_RTSP #ifdef SRS_RTSP
if (rtsp.get() && _srs_config->get_rtsp_from_rtmp(req->vhost)) { if (rtsp.get() && _srs_config->get_rtsp_from_rtmp(req->vhost_)) {
bridge->append(new SrsFrameToRtspBridge(rtsp)); bridge->append(new SrsFrameToRtspBridge(rtsp));
} }
#endif #endif
@ -1126,7 +1126,7 @@ srs_error_t SrsRtmpConn::handle_publish_message(SrsSharedPtr<SrsLiveSource> &sou
// for fmle, drop others except the fmle start packet. // for fmle, drop others except the fmle start packet.
if (dynamic_cast<SrsFMLEStartPacket *>(pkt.get())) { if (dynamic_cast<SrsFMLEStartPacket *>(pkt.get())) {
SrsFMLEStartPacket *unpublish = dynamic_cast<SrsFMLEStartPacket *>(pkt.get()); SrsFMLEStartPacket *unpublish = dynamic_cast<SrsFMLEStartPacket *>(pkt.get());
if ((err = rtmp->fmle_unpublish(info->res->stream_id, unpublish->transaction_id)) != srs_success) { if ((err = rtmp->fmle_unpublish(info->res->stream_id_, unpublish->transaction_id_)) != srs_success) {
return srs_error_wrap(err, "rtmp: republish"); return srs_error_wrap(err, "rtmp: republish");
} }
return srs_error_new(ERROR_CONTROL_REPUBLISH, "rtmp: republish"); return srs_error_new(ERROR_CONTROL_REPUBLISH, "rtmp: republish");
@ -1232,10 +1232,10 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsLiveConsumer *consumer, Srs
if (call) { if (call) {
// only response it when transaction id not zero, // only response it when transaction id not zero,
// for the zero means donot need response. // for the zero means donot need response.
if (call->transaction_id > 0) { if (call->transaction_id_ > 0) {
SrsCallResPacket *res = new SrsCallResPacket(call->transaction_id); SrsCallResPacket *res = new SrsCallResPacket(call->transaction_id_);
res->command_object = SrsAmf0Any::null(); res->command_object_ = SrsAmf0Any::null();
res->response = SrsAmf0Any::null(); res->response_ = SrsAmf0Any::null();
if ((err = rtmp->send_and_free_packet(res, 0)) != srs_success) { if ((err = rtmp->send_and_free_packet(res, 0)) != srs_success) {
return srs_error_wrap(err, "rtmp: send packets"); return srs_error_wrap(err, "rtmp: send packets");
} }
@ -1246,10 +1246,10 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsLiveConsumer *consumer, Srs
// pause // pause
SrsPausePacket *pause = dynamic_cast<SrsPausePacket *>(pkt.get()); SrsPausePacket *pause = dynamic_cast<SrsPausePacket *>(pkt.get());
if (pause) { if (pause) {
if ((err = rtmp->on_play_client_pause(info->res->stream_id, pause->is_pause)) != srs_success) { if ((err = rtmp->on_play_client_pause(info->res->stream_id_, pause->is_pause_)) != srs_success) {
return srs_error_wrap(err, "rtmp: pause"); return srs_error_wrap(err, "rtmp: pause");
} }
if ((err = consumer->on_play_client_pause(pause->is_pause)) != srs_success) { if ((err = consumer->on_play_client_pause(pause->is_pause_)) != srs_success) {
return srs_error_wrap(err, "rtmp: pause"); return srs_error_wrap(err, "rtmp: pause");
} }
return err; return err;
@ -1263,7 +1263,7 @@ void SrsRtmpConn::set_sock_options()
{ {
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
bool nvalue = _srs_config->get_tcp_nodelay(req->vhost); bool nvalue = _srs_config->get_tcp_nodelay(req->vhost_);
if (nvalue != tcp_nodelay) { if (nvalue != tcp_nodelay) {
tcp_nodelay = nvalue; tcp_nodelay = nvalue;
@ -1282,7 +1282,7 @@ srs_error_t SrsRtmpConn::check_edge_token_traverse_auth()
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
srs_assert(req); srs_assert(req);
vector<string> args = _srs_config->get_vhost_edge_origin(req->vhost)->args; vector<string> args = _srs_config->get_vhost_edge_origin(req->vhost_)->args;
if (args.empty()) { if (args.empty()) {
return err; return err;
} }
@ -1297,7 +1297,7 @@ srs_error_t SrsRtmpConn::check_edge_token_traverse_auth()
SrsUniquePtr<SrsTcpClient> transport(new SrsTcpClient(server, port, SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT)); SrsUniquePtr<SrsTcpClient> transport(new SrsTcpClient(server, port, SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT));
if ((err = transport->connect()) != srs_success) { if ((err = transport->connect()) != srs_success) {
srs_warn("Illegal edge token, tcUrl=%s, %s", req->tcUrl.c_str(), srs_error_desc(err).c_str()); srs_warn("Illegal edge token, tcUrl=%s, %s", req->tcUrl_.c_str(), srs_error_desc(err).c_str());
srs_freep(err); srs_freep(err);
continue; continue;
} }
@ -1325,11 +1325,11 @@ srs_error_t SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient *client)
// for token tranverse, always take the debug info(which carries token). // for token tranverse, always take the debug info(which carries token).
SrsServerInfo si; SrsServerInfo si;
if ((err = client->connect_app(req->app, req->tcUrl, req, true, &si)) != srs_success) { if ((err = client->connect_app(req->app_, req->tcUrl_, req, true, &si)) != srs_success) {
return srs_error_wrap(err, "rtmp: connect tcUrl"); return srs_error_wrap(err, "rtmp: connect tcUrl");
} }
srs_trace("edge token auth ok, tcUrl=%s", req->tcUrl.c_str()); srs_trace("edge token auth ok, tcUrl=%s", req->tcUrl_.c_str());
return err; return err;
} }
@ -1350,7 +1350,7 @@ srs_error_t SrsRtmpConn::http_hooks_on_connect()
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -1360,7 +1360,7 @@ srs_error_t SrsRtmpConn::http_hooks_on_connect()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_connect(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_connect(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -1383,7 +1383,7 @@ void SrsRtmpConn::http_hooks_on_close()
{ {
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return; return;
} }
@ -1393,7 +1393,7 @@ void SrsRtmpConn::http_hooks_on_close()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_close(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_close(req->vhost_);
if (!conf) { if (!conf) {
return; return;
@ -1414,7 +1414,7 @@ srs_error_t SrsRtmpConn::http_hooks_on_publish()
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -1424,7 +1424,7 @@ srs_error_t SrsRtmpConn::http_hooks_on_publish()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_publish(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_publish(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -1447,7 +1447,7 @@ void SrsRtmpConn::http_hooks_on_unpublish()
{ {
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return; return;
} }
@ -1457,7 +1457,7 @@ void SrsRtmpConn::http_hooks_on_unpublish()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_unpublish(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_unpublish(req->vhost_);
if (!conf) { if (!conf) {
return; return;
@ -1478,7 +1478,7 @@ srs_error_t SrsRtmpConn::http_hooks_on_play()
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -1488,7 +1488,7 @@ srs_error_t SrsRtmpConn::http_hooks_on_play()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_play(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_play(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -1511,7 +1511,7 @@ void SrsRtmpConn::http_hooks_on_stop()
{ {
ISrsRequest *req = info->req; ISrsRequest *req = info->req;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return; return;
} }
@ -1521,7 +1521,7 @@ void SrsRtmpConn::http_hooks_on_stop()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_stop(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_stop(req->vhost_);
if (!conf) { if (!conf) {
return; return;

View File

@ -359,7 +359,7 @@ SrsRtspConnection::SrsRtspConnection(ISrsResourceManager *cm, ISrsProtocolReadWr
disposing_ = false; disposing_ = false;
request_ = new SrsRequest(); request_ = new SrsRequest();
request_->ip = cip; request_->ip_ = cip;
ip_ = cip; ip_ = cip;
port_ = port; port_ = port;
rtsp_ = new SrsRtspStack(skt); rtsp_ = new SrsRtspStack(skt);
@ -683,15 +683,15 @@ void SrsRtspConnection::alive()
srs_error_t SrsRtspConnection::do_describe(SrsRtspRequest *req, std::string &sdp) srs_error_t SrsRtspConnection::do_describe(SrsRtspRequest *req, std::string &sdp)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_net_url_parse_rtmp_url(req->uri, request_->tcUrl, request_->stream); srs_net_url_parse_rtmp_url(req->uri, request_->tcUrl_, request_->stream_);
srs_net_url_parse_tcurl(request_->tcUrl, request_->schema, request_->host, request_->vhost, srs_net_url_parse_tcurl(request_->tcUrl_, request_->schema_, request_->host_, request_->vhost_,
request_->app, request_->stream, request_->port, request_->param); request_->app_, request_->stream_, request_->port_, request_->param_);
// discovery vhost, resolve the vhost from config // discovery vhost, resolve the vhost from config
SrsConfDirective *parsed_vhost = _srs_config->get_vhost(request_->vhost); SrsConfDirective *parsed_vhost = _srs_config->get_vhost(request_->vhost_);
if (parsed_vhost) { if (parsed_vhost) {
request_->vhost = parsed_vhost->arg0(); request_->vhost_ = parsed_vhost->arg0();
} }
if ((err = security_->check(SrsRtcConnPlay, ip_, request_)) != srs_success) { if ((err = security_->check(SrsRtcConnPlay, ip_, request_)) != srs_success) {
@ -854,7 +854,7 @@ srs_error_t SrsRtspConnection::http_hooks_on_play(ISrsRequest *req)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost_)) {
return err; return err;
} }
@ -864,7 +864,7 @@ srs_error_t SrsRtspConnection::http_hooks_on_play(ISrsRequest *req)
std::vector<std::string> hooks; std::vector<std::string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_play(req->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_play(req->vhost_);
if (!conf) { if (!conf) {
return err; return err;

View File

@ -666,7 +666,7 @@ srs_error_t SrsRtspRtpBuilder::initialize(ISrsRequest *r)
} }
// Setup the SPS/PPS parsing strategy. // Setup the SPS/PPS parsing strategy.
format->try_annexb_first_ = _srs_config->try_annexb_first(r->vhost); format->try_annexb_first_ = _srs_config->try_annexb_first(r->vhost_);
srs_trace("RTSP bridge from RTMP, try_annexb_first=%d", format->try_annexb_first_); srs_trace("RTSP bridge from RTMP, try_annexb_first=%d", format->try_annexb_first_);

View File

@ -24,12 +24,12 @@ srs_error_t SrsSecurity::check(SrsRtmpConnType type, string ip, ISrsRequest *req
srs_error_t err = srs_success; srs_error_t err = srs_success;
// allow all if security disabled. // allow all if security disabled.
if (!_srs_config->get_security_enabled(req->vhost)) { if (!_srs_config->get_security_enabled(req->vhost_)) {
return err; // OK return err; // OK
} }
// rules to apply // rules to apply
SrsConfDirective *rules = _srs_config->get_security_rules(req->vhost); SrsConfDirective *rules = _srs_config->get_security_rules(req->vhost_);
return do_check(rules, type, ip, req); return do_check(rules, type, ip, req);
} }

View File

@ -1342,7 +1342,7 @@ srs_error_t SrsServer::create_rtc_session(SrsRtcUserConfig *ruc, SrsSdp &local_s
// Security or system flow control check. For WebRTC, use 0 as fd and port, because for // Security or system flow control check. For WebRTC, use 0 as fd and port, because for
// the WebRTC HTTP API, it's not useful information. // the WebRTC HTTP API, it's not useful information.
if ((err = on_before_connection("RTC", (int)0, req->ip, 0)) != srs_success) { if ((err = on_before_connection("RTC", (int)0, req->ip_, 0)) != srs_success) {
return srs_error_wrap(err, "check"); return srs_error_wrap(err, "check");
} }

View File

@ -494,10 +494,10 @@ srs_error_t SrsLiveConsumer::dump_packets(SrsMessageArray *msgs, int &count)
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_assert(count >= 0); srs_assert(count >= 0);
srs_assert(msgs->max > 0); srs_assert(msgs->max_ > 0);
// the count used as input to reset the max if positive. // the count used as input to reset the max if positive.
int max = count ? srs_min(count, msgs->max) : msgs->max; int max = count ? srs_min(count, msgs->max_) : msgs->max_;
// the count specifies the max acceptable count, // the count specifies the max acceptable count,
// here maybe 1+, and we must set to 0 when got nothing. // here maybe 1+, and we must set to 0 when got nothing.
@ -514,7 +514,7 @@ srs_error_t SrsLiveConsumer::dump_packets(SrsMessageArray *msgs, int &count)
} }
// pump msgs from queue. // pump msgs from queue.
if ((err = queue->dump_packets(max, msgs->msgs, count)) != srs_success) { if ((err = queue->dump_packets(max, msgs->msgs_, count)) != srs_success) {
return srs_error_wrap(err, "dump packets"); return srs_error_wrap(err, "dump packets");
} }
@ -978,7 +978,7 @@ srs_error_t SrsOriginHub::on_audio(SrsMediaPacket *shared_audio)
if ((err = hls->on_audio(msg, format)) != srs_success) { if ((err = hls->on_audio(msg, format)) != srs_success) {
// apply the error strategy for hls. // apply the error strategy for hls.
std::string hls_error_strategy = _srs_config->get_hls_on_error(req_->vhost); std::string hls_error_strategy = _srs_config->get_hls_on_error(req_->vhost_);
if (srs_config_hls_is_on_error_ignore(hls_error_strategy)) { if (srs_config_hls_is_on_error_ignore(hls_error_strategy)) {
srs_warn("hls: ignore audio error %s", srs_error_desc(err).c_str()); srs_warn("hls: ignore audio error %s", srs_error_desc(err).c_str());
hls->on_unpublish(); hls->on_unpublish();
@ -1069,7 +1069,7 @@ srs_error_t SrsOriginHub::on_video(SrsMediaPacket *shared_video, bool is_sequenc
if ((err = hls->on_video(msg, format)) != srs_success) { if ((err = hls->on_video(msg, format)) != srs_success) {
// TODO: We should support more strategies. // TODO: We should support more strategies.
// apply the error strategy for hls. // apply the error strategy for hls.
std::string hls_error_strategy = _srs_config->get_hls_on_error(req_->vhost); std::string hls_error_strategy = _srs_config->get_hls_on_error(req_->vhost_);
if (srs_config_hls_is_on_error_ignore(hls_error_strategy)) { if (srs_config_hls_is_on_error_ignore(hls_error_strategy)) {
srs_warn("hls: ignore video error %s", srs_error_desc(err).c_str()); srs_warn("hls: ignore video error %s", srs_error_desc(err).c_str());
hls->on_unpublish(); hls->on_unpublish();
@ -1260,7 +1260,7 @@ srs_error_t SrsOriginHub::create_forwarders()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_forward_enabled(req_->vhost)) { if (!_srs_config->get_forward_enabled(req_->vhost_)) {
return err; return err;
} }
@ -1277,7 +1277,7 @@ srs_error_t SrsOriginHub::create_forwarders()
} }
// For destanition config // For destanition config
SrsConfDirective *conf = _srs_config->get_forwards(req_->vhost); SrsConfDirective *conf = _srs_config->get_forwards(req_->vhost_);
for (int i = 0; conf && i < (int)conf->args.size(); i++) { for (int i = 0; conf && i < (int)conf->args.size(); i++) {
std::string forward_server = conf->args.at(i); std::string forward_server = conf->args.at(i);
@ -1289,12 +1289,12 @@ srs_error_t SrsOriginHub::create_forwarders()
return srs_error_wrap(err, "init forwarder"); return srs_error_wrap(err, "init forwarder");
} }
srs_utime_t queue_size = _srs_config->get_queue_length(req_->vhost); srs_utime_t queue_size = _srs_config->get_queue_length(req_->vhost_);
forwarder->set_queue_size(queue_size); forwarder->set_queue_size(queue_size);
if ((err = forwarder->on_publish()) != srs_success) { if ((err = forwarder->on_publish()) != srs_success) {
return srs_error_wrap(err, "start forwarder failed, vhost=%s, app=%s, stream=%s, forward-to=%s", return srs_error_wrap(err, "start forwarder failed, vhost=%s, app=%s, stream=%s, forward-to=%s",
req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), forward_server.c_str()); req_->vhost_.c_str(), req_->app_.c_str(), req_->stream_.c_str(), forward_server.c_str());
} }
} }
@ -1308,7 +1308,7 @@ srs_error_t SrsOriginHub::create_backend_forwarders(bool &applied)
// default not configure backend service // default not configure backend service
applied = false; applied = false;
SrsConfDirective *conf = _srs_config->get_forward_backend(req_->vhost); SrsConfDirective *conf = _srs_config->get_forward_backend(req_->vhost_);
if (!conf || conf->arg0().empty()) { if (!conf || conf->arg0().empty()) {
return err; return err;
} }
@ -1332,27 +1332,27 @@ srs_error_t SrsOriginHub::create_backend_forwarders(bool &applied)
// create temp Request by url // create temp Request by url
SrsUniquePtr<ISrsRequest> req(new SrsRequest()); SrsUniquePtr<ISrsRequest> req(new SrsRequest());
srs_net_url_parse_rtmp_url(url, req->tcUrl, req->stream); srs_net_url_parse_rtmp_url(url, req->tcUrl_, req->stream_);
srs_net_url_parse_tcurl(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param); srs_net_url_parse_tcurl(req->tcUrl_, req->schema_, req->host_, req->vhost_, req->app_, req->stream_, req->port_, req->param_);
// create forwarder // create forwarder
SrsForwarder *forwarder = new SrsForwarder(this); SrsForwarder *forwarder = new SrsForwarder(this);
forwarders.push_back(forwarder); forwarders.push_back(forwarder);
std::stringstream forward_server; std::stringstream forward_server;
forward_server << req->host << ":" << req->port; forward_server << req->host_ << ":" << req->port_;
// initialize the forwarder with request. // initialize the forwarder with request.
if ((err = forwarder->initialize(req.get(), forward_server.str())) != srs_success) { if ((err = forwarder->initialize(req.get(), forward_server.str())) != srs_success) {
return srs_error_wrap(err, "init backend forwarder failed, forward-to=%s", forward_server.str().c_str()); return srs_error_wrap(err, "init backend forwarder failed, forward-to=%s", forward_server.str().c_str());
} }
srs_utime_t queue_size = _srs_config->get_queue_length(req_->vhost); srs_utime_t queue_size = _srs_config->get_queue_length(req_->vhost_);
forwarder->set_queue_size(queue_size); forwarder->set_queue_size(queue_size);
if ((err = forwarder->on_publish()) != srs_success) { if ((err = forwarder->on_publish()) != srs_success) {
return srs_error_wrap(err, "start backend forwarder failed, vhost=%s, app=%s, stream=%s, forward-to=%s", return srs_error_wrap(err, "start backend forwarder failed, vhost=%s, app=%s, stream=%s, forward-to=%s",
req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), forward_server.str().c_str()); req_->vhost_.c_str(), req_->app_.c_str(), req_->stream_.c_str(), forward_server.str().c_str());
} }
} }
@ -1479,32 +1479,32 @@ srs_error_t SrsMetaCache::update_data(SrsMessageHeader *header, SrsOnMetaDataPac
SrsAmf0Any *prop = NULL; SrsAmf0Any *prop = NULL;
// when exists the duration, remove it to make ExoPlayer happy. // when exists the duration, remove it to make ExoPlayer happy.
if (metadata->metadata->get_property("duration") != NULL) { if (metadata->metadata_->get_property("duration") != NULL) {
metadata->metadata->remove("duration"); metadata->metadata_->remove("duration");
} }
// generate metadata info to print // generate metadata info to print
std::stringstream ss; std::stringstream ss;
if ((prop = metadata->metadata->ensure_property_number("width")) != NULL) { if ((prop = metadata->metadata_->ensure_property_number("width")) != NULL) {
ss << ", width=" << (int)prop->to_number(); ss << ", width=" << (int)prop->to_number();
} }
if ((prop = metadata->metadata->ensure_property_number("height")) != NULL) { if ((prop = metadata->metadata_->ensure_property_number("height")) != NULL) {
ss << ", height=" << (int)prop->to_number(); ss << ", height=" << (int)prop->to_number();
} }
if ((prop = metadata->metadata->ensure_property_number("videocodecid")) != NULL) { if ((prop = metadata->metadata_->ensure_property_number("videocodecid")) != NULL) {
ss << ", vcodec=" << (int)prop->to_number(); ss << ", vcodec=" << (int)prop->to_number();
} }
if ((prop = metadata->metadata->ensure_property_number("audiocodecid")) != NULL) { if ((prop = metadata->metadata_->ensure_property_number("audiocodecid")) != NULL) {
ss << ", acodec=" << (int)prop->to_number(); ss << ", acodec=" << (int)prop->to_number();
} }
srs_trace("got metadata%s", ss.str().c_str()); srs_trace("got metadata%s", ss.str().c_str());
// add server info to metadata // add server info to metadata
metadata->metadata->set("server", SrsAmf0Any::str(RTMP_SIG_SRS_SERVER)); metadata->metadata_->set("server", SrsAmf0Any::str(RTMP_SIG_SRS_SERVER));
// version, for example, 1.0.0 // version, for example, 1.0.0
// add version to metadata, please donot remove it, for debug. // add version to metadata, please donot remove it, for debug.
metadata->metadata->set("server_version", SrsAmf0Any::str(RTMP_SIG_SRS_VERSION)); metadata->metadata_->set("server_version", SrsAmf0Any::str(RTMP_SIG_SRS_VERSION));
// encode the metadata to payload // encode the metadata to payload
int size = 0; int size = 0;
@ -1823,17 +1823,17 @@ srs_error_t SrsLiveSource::initialize(SrsSharedPtr<SrsLiveSource> wrapper, ISrsR
srs_assert(!req); srs_assert(!req);
req = r->copy(); req = r->copy();
atc = _srs_config->get_atc(req->vhost); atc = _srs_config->get_atc(req->vhost_);
jitter_algorithm = (SrsRtmpJitterAlgorithm)_srs_config->get_time_jitter(req->vhost); jitter_algorithm = (SrsRtmpJitterAlgorithm)_srs_config->get_time_jitter(req->vhost_);
mix_correct = _srs_config->get_mix_correct(req->vhost); mix_correct = _srs_config->get_mix_correct(req->vhost_);
if ((err = format_->initialize()) != srs_success) { if ((err = format_->initialize()) != srs_success) {
return srs_error_wrap(err, "format initialize"); return srs_error_wrap(err, "format initialize");
} }
// Setup the SPS/PPS parsing strategy. // Setup the SPS/PPS parsing strategy.
format_->try_annexb_first_ = _srs_config->try_annexb_first(r->vhost); format_->try_annexb_first_ = _srs_config->try_annexb_first(r->vhost_);
if ((err = play_edge->initialize(wrapper, req)) != srs_success) { if ((err = play_edge->initialize(wrapper, req)) != srs_success) {
return srs_error_wrap(err, "edge(play)"); return srs_error_wrap(err, "edge(play)");
@ -1842,7 +1842,7 @@ srs_error_t SrsLiveSource::initialize(SrsSharedPtr<SrsLiveSource> wrapper, ISrsR
return srs_error_wrap(err, "edge(publish)"); return srs_error_wrap(err, "edge(publish)");
} }
srs_utime_t queue_size = _srs_config->get_queue_length(req->vhost); srs_utime_t queue_size = _srs_config->get_queue_length(req->vhost_);
publish_edge->set_queue_size(queue_size); publish_edge->set_queue_size(queue_size);
if ((err = hub->initialize(wrapper, req)) != srs_success) { if ((err = hub->initialize(wrapper, req)) != srs_success) {
@ -1922,9 +1922,9 @@ srs_error_t SrsLiveSource::on_meta_data(SrsRtmpCommonMessage *msg, SrsOnMetaData
// if allow atc_auto and bravo-atc detected, open atc for vhost. // if allow atc_auto and bravo-atc detected, open atc for vhost.
SrsAmf0Any *prop = NULL; SrsAmf0Any *prop = NULL;
atc = _srs_config->get_atc(req->vhost); atc = _srs_config->get_atc(req->vhost_);
if (_srs_config->get_atc_auto(req->vhost)) { if (_srs_config->get_atc_auto(req->vhost_)) {
if ((prop = metadata->metadata->get_property("bravo_atc")) != NULL) { if ((prop = metadata->metadata_->get_property("bravo_atc")) != NULL) {
if (prop->is_string() && prop->to_str() == "true") { if (prop->is_string() && prop->to_str() == "true") {
atc = true; atc = true;
} }
@ -1942,7 +1942,7 @@ srs_error_t SrsLiveSource::on_meta_data(SrsRtmpCommonMessage *msg, SrsOnMetaData
// when already got metadata, drop when reduce sequence header. // when already got metadata, drop when reduce sequence header.
bool drop_for_reduce = false; bool drop_for_reduce = false;
if (meta->data() && _srs_config->get_reduce_sequence_header(req->vhost)) { if (meta->data() && _srs_config->get_reduce_sequence_header(req->vhost_)) {
drop_for_reduce = true; drop_for_reduce = true;
srs_warn("drop for reduce sh metadata, size=%d", msg->size()); srs_warn("drop for reduce sh metadata, size=%d", msg->size());
} }
@ -2036,7 +2036,7 @@ srs_error_t SrsLiveSource::on_audio_imp(SrsMediaPacket *msg)
// whether consumer should drop for the duplicated sequence header. // whether consumer should drop for the duplicated sequence header.
bool drop_for_reduce = false; bool drop_for_reduce = false;
if (is_sequence_header && meta->previous_ash() && _srs_config->get_reduce_sequence_header(req->vhost)) { if (is_sequence_header && meta->previous_ash() && _srs_config->get_reduce_sequence_header(req->vhost_)) {
if (meta->previous_ash()->size() == msg->size()) { if (meta->previous_ash()->size() == msg->size()) {
drop_for_reduce = srs_bytes_equal(meta->previous_ash()->payload(), msg->payload(), msg->size()); drop_for_reduce = srs_bytes_equal(meta->previous_ash()->payload(), msg->payload(), msg->size());
srs_warn("drop for reduce sh audio, size=%d", msg->size()); srs_warn("drop for reduce sh audio, size=%d", msg->size());
@ -2136,7 +2136,7 @@ srs_error_t SrsLiveSource::on_video_imp(SrsMediaPacket *msg)
// user can disable the sps parse to workaround when parse sps failed. // user can disable the sps parse to workaround when parse sps failed.
// @see https://github.com/ossrs/srs/issues/474 // @see https://github.com/ossrs/srs/issues/474
if (is_sequence_header) { if (is_sequence_header) {
format_->avc_parse_sps_ = _srs_config->get_parse_sps(req->vhost); format_->avc_parse_sps_ = _srs_config->get_parse_sps(req->vhost_);
} }
if ((err = format_->on_video(msg)) != srs_success) { if ((err = format_->on_video(msg)) != srs_success) {
@ -2151,7 +2151,7 @@ srs_error_t SrsLiveSource::on_video_imp(SrsMediaPacket *msg)
// whether consumer should drop for the duplicated sequence header. // whether consumer should drop for the duplicated sequence header.
bool drop_for_reduce = false; bool drop_for_reduce = false;
if (is_sequence_header && meta->previous_vsh() && _srs_config->get_reduce_sequence_header(req->vhost)) { if (is_sequence_header && meta->previous_vsh() && _srs_config->get_reduce_sequence_header(req->vhost_)) {
if (meta->previous_vsh()->size() == msg->size()) { if (meta->previous_vsh()->size() == msg->size()) {
drop_for_reduce = srs_bytes_equal(meta->previous_vsh()->payload(), msg->payload(), msg->size()); drop_for_reduce = srs_bytes_equal(meta->previous_vsh()->payload(), msg->payload(), msg->size());
srs_warn("drop for reduce sh video, size=%d", msg->size()); srs_warn("drop for reduce sh video, size=%d", msg->size());
@ -2404,7 +2404,7 @@ srs_error_t SrsLiveSource::create_consumer(SrsLiveConsumer *&consumer)
srs_error_t err = srs_success; srs_error_t err = srs_success;
// for edge, when play edge stream, check the state // for edge, when play edge stream, check the state
if (_srs_config->get_vhost_is_edge(req->vhost)) { if (_srs_config->get_vhost_is_edge(req->vhost_)) {
// notice edge to start for the first client. // notice edge to start for the first client.
if ((err = play_edge->on_client_play()) != srs_success) { if ((err = play_edge->on_client_play()) != srs_success) {
return srs_error_wrap(err, "play edge"); return srs_error_wrap(err, "play edge");
@ -2425,7 +2425,7 @@ srs_error_t SrsLiveSource::consumer_dumps(SrsLiveConsumer *consumer, bool ds, bo
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_utime_t queue_size = _srs_config->get_queue_length(req->vhost); srs_utime_t queue_size = _srs_config->get_queue_length(req->vhost_);
consumer->set_queue_size(queue_size); consumer->set_queue_size(queue_size);
// if atc, update the sequence header to gop cache time. // if atc, update the sequence header to gop cache time.
@ -2482,7 +2482,7 @@ void SrsLiveSource::on_consumer_destroy(SrsLiveConsumer *consumer)
// For edge server, the stream die when the last player quit, because the edge stream is created by player // For edge server, the stream die when the last player quit, because the edge stream is created by player
// activities, so it should die when all players quit. // activities, so it should die when all players quit.
if (_srs_config->get_vhost_is_edge(req->vhost)) { if (_srs_config->get_vhost_is_edge(req->vhost_)) {
stream_die_at_ = srs_time_now_cached(); stream_die_at_ = srs_time_now_cached();
} }

View File

@ -173,7 +173,7 @@ SrsMpegtsSrtConn::SrsMpegtsSrtConn(ISrsResourceManager *resource_manager, srs_sr
trd_ = new SrsSTCoroutine("ts-srt", this, _srs_context->get_id()); trd_ = new SrsSTCoroutine("ts-srt", this, _srs_context->get_id());
req_ = new SrsRequest(); req_ = new SrsRequest();
req_->ip = ip; req_->ip_ = ip;
security_ = new SrsSecurity(); security_ = new SrsSecurity();
} }
@ -273,17 +273,17 @@ srs_error_t SrsMpegtsSrtConn::do_cycle()
} }
// discovery vhost, resolve the vhost from config // discovery vhost, resolve the vhost from config
SrsConfDirective *parsed_vhost = _srs_config->get_vhost(req_->vhost); SrsConfDirective *parsed_vhost = _srs_config->get_vhost(req_->vhost_);
if (parsed_vhost) { if (parsed_vhost) {
req_->vhost = parsed_vhost->arg0(); req_->vhost_ = parsed_vhost->arg0();
} }
if (!_srs_config->get_srt_enabled(req_->vhost)) { if (!_srs_config->get_srt_enabled(req_->vhost_)) {
return srs_error_new(ERROR_SRT_CONN, "srt disabled, vhost=%s", req_->vhost.c_str()); return srs_error_new(ERROR_SRT_CONN, "srt disabled, vhost=%s", req_->vhost_.c_str());
} }
srs_trace("@srt, streamid=%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", srs_trace("@srt, streamid=%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s",
streamid.c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); streamid.c_str(), req_->get_stream_url().c_str(), req_->vhost_.c_str(), req_->app_.c_str(), req_->stream_.c_str(), req_->param_.c_str());
// Acquire stream publish token to prevent race conditions across all protocols. // Acquire stream publish token to prevent race conditions across all protocols.
SrsStreamPublishToken *publish_token_raw = NULL; SrsStreamPublishToken *publish_token_raw = NULL;
@ -390,8 +390,8 @@ srs_error_t SrsMpegtsSrtConn::acquire_publish()
srs_assert(live_source.get() != NULL); srs_assert(live_source.get() != NULL);
bool enabled_cache = _srs_config->get_gop_cache(req_->vhost); bool enabled_cache = _srs_config->get_gop_cache(req_->vhost_);
int gcmf = _srs_config->get_gop_cache_max_frames(req_->vhost); int gcmf = _srs_config->get_gop_cache_max_frames(req_->vhost_);
live_source->set_cache(enabled_cache); live_source->set_cache(enabled_cache);
live_source->set_gop_cache_max_frames(gcmf); live_source->set_gop_cache_max_frames(gcmf);
@ -401,8 +401,8 @@ srs_error_t SrsMpegtsSrtConn::acquire_publish()
// Check whether RTC stream is busy. // Check whether RTC stream is busy.
SrsSharedPtr<SrsRtcSource> rtc; SrsSharedPtr<SrsRtcSource> rtc;
bool rtc_server_enabled = _srs_config->get_rtc_server_enabled(); bool rtc_server_enabled = _srs_config->get_rtc_server_enabled();
bool rtc_enabled = _srs_config->get_rtc_enabled(req_->vhost); bool rtc_enabled = _srs_config->get_rtc_enabled(req_->vhost_);
bool edge = _srs_config->get_vhost_is_edge(req_->vhost); bool edge = _srs_config->get_vhost_is_edge(req_->vhost_);
if (rtc_server_enabled && rtc_enabled && !edge) { if (rtc_server_enabled && rtc_enabled && !edge) {
if ((err = _srs_rtc_sources->fetch_or_create(req_, rtc)) != srs_success) { if ((err = _srs_rtc_sources->fetch_or_create(req_, rtc)) != srs_success) {
return srs_error_wrap(err, "create source"); return srs_error_wrap(err, "create source");
@ -413,13 +413,13 @@ srs_error_t SrsMpegtsSrtConn::acquire_publish()
} }
} }
if (_srs_config->get_srt_to_rtmp(req_->vhost)) { if (_srs_config->get_srt_to_rtmp(req_->vhost_)) {
// Bridge to RTMP and RTC streaming. // Bridge to RTMP and RTC streaming.
SrsCompositeBridge *bridge = new SrsCompositeBridge(); SrsCompositeBridge *bridge = new SrsCompositeBridge();
bridge->append(new SrsFrameToRtmpBridge(live_source)); bridge->append(new SrsFrameToRtmpBridge(live_source));
#if defined(SRS_FFMPEG_FIT) #if defined(SRS_FFMPEG_FIT)
if (rtc.get() && _srs_config->get_rtc_from_rtmp(req_->vhost)) { if (rtc.get() && _srs_config->get_rtc_from_rtmp(req_->vhost_)) {
bridge->append(new SrsFrameToRtcBridge(rtc)); bridge->append(new SrsFrameToRtcBridge(rtc));
} }
#endif #endif
@ -605,7 +605,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_connect()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost_)) {
return err; return err;
} }
@ -615,7 +615,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_connect()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_connect(req_->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_connect(req_->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -636,7 +636,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_connect()
void SrsMpegtsSrtConn::http_hooks_on_close() void SrsMpegtsSrtConn::http_hooks_on_close()
{ {
if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost_)) {
return; return;
} }
@ -646,7 +646,7 @@ void SrsMpegtsSrtConn::http_hooks_on_close()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_close(req_->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_close(req_->vhost_);
if (!conf) { if (!conf) {
return; return;
@ -665,7 +665,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_publish()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost_)) {
return err; return err;
} }
@ -675,7 +675,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_publish()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_publish(req_->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_publish(req_->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -696,7 +696,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_publish()
void SrsMpegtsSrtConn::http_hooks_on_unpublish() void SrsMpegtsSrtConn::http_hooks_on_unpublish()
{ {
if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost_)) {
return; return;
} }
@ -706,7 +706,7 @@ void SrsMpegtsSrtConn::http_hooks_on_unpublish()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_unpublish(req_->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_unpublish(req_->vhost_);
if (!conf) { if (!conf) {
return; return;
@ -725,7 +725,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_play()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost_)) {
return err; return err;
} }
@ -735,7 +735,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_play()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_play(req_->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_play(req_->vhost_);
if (!conf) { if (!conf) {
return err; return err;
@ -756,7 +756,7 @@ srs_error_t SrsMpegtsSrtConn::http_hooks_on_play()
void SrsMpegtsSrtConn::http_hooks_on_stop() void SrsMpegtsSrtConn::http_hooks_on_stop()
{ {
if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost)) { if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost_)) {
return; return;
} }
@ -766,7 +766,7 @@ void SrsMpegtsSrtConn::http_hooks_on_stop()
vector<string> hooks; vector<string> hooks;
if (true) { if (true) {
SrsConfDirective *conf = _srs_config->get_vhost_on_stop(req_->vhost); SrsConfDirective *conf = _srs_config->get_vhost_on_stop(req_->vhost_);
if (!conf) { if (!conf) {
return; return;

View File

@ -808,7 +808,7 @@ srs_error_t SrsSrtFrameBuilder::on_ts_audio(SrsTsMessage *msg, SrsBuffer *avs)
// May have more than one aac frame in PES packet, and shared same timestamp, // May have more than one aac frame in PES packet, and shared same timestamp,
// so we must calculate each aac frame's timestamp. // so we must calculate each aac frame's timestamp.
int sample_rate = 44100; int sample_rate = 44100;
switch (codec.sound_rate) { switch (codec.sound_rate_) {
case SrsAudioSampleRate5512: case SrsAudioSampleRate5512:
sample_rate = 5512; sample_rate = 5512;
break; break;

View File

@ -115,7 +115,7 @@ bool srs_srt_streamid_info(const std::string &streamid, SrtMode &mode, std::stri
bool srs_srt_streamid_to_request(const std::string &streamid, SrtMode &mode, ISrsRequest *request) bool srs_srt_streamid_to_request(const std::string &streamid, SrtMode &mode, ISrsRequest *request)
{ {
string url_subpath = ""; string url_subpath = "";
bool ret = srs_srt_streamid_info(streamid, mode, request->vhost, url_subpath); bool ret = srs_srt_streamid_info(streamid, mode, request->vhost_, url_subpath);
if (!ret) { if (!ret) {
return ret; return ret;
} }
@ -123,25 +123,25 @@ bool srs_srt_streamid_to_request(const std::string &streamid, SrtMode &mode, ISr
size_t pos = url_subpath.find("/"); size_t pos = url_subpath.find("/");
string stream_with_params = ""; string stream_with_params = "";
if (pos == string::npos) { if (pos == string::npos) {
request->app = _srs_config->get_default_app_name(); request->app_ = _srs_config->get_default_app_name();
stream_with_params = url_subpath; stream_with_params = url_subpath;
} else { } else {
request->app = url_subpath.substr(0, pos); request->app_ = url_subpath.substr(0, pos);
stream_with_params = url_subpath.substr(pos + 1); stream_with_params = url_subpath.substr(pos + 1);
} }
pos = stream_with_params.find("?"); pos = stream_with_params.find("?");
if (pos == string::npos) { if (pos == string::npos) {
request->stream = stream_with_params; request->stream_ = stream_with_params;
} else { } else {
request->stream = stream_with_params.substr(0, pos); request->stream_ = stream_with_params.substr(0, pos);
request->param = stream_with_params.substr(pos + 1); request->param_ = stream_with_params.substr(pos + 1);
} }
request->host = srs_get_public_internet_address(); request->host_ = srs_get_public_internet_address();
if (request->vhost.empty()) if (request->vhost_.empty())
request->vhost = request->host; request->vhost_ = request->host_;
request->tcUrl = srs_net_url_encode_tcurl("srt", request->host, request->vhost, request->app, request->port); request->tcUrl_ = srs_net_url_encode_tcurl("srt", request->host_, request->vhost_, request->app_, request->port_);
return ret; return ret;
} }

View File

@ -225,12 +225,12 @@ srs_error_t SrsStatisticClient::dumps(SrsJsonObject *obj)
obj->set("id", SrsJsonAny::str(id.c_str())); obj->set("id", SrsJsonAny::str(id.c_str()));
obj->set("vhost", SrsJsonAny::str(stream->vhost->id.c_str())); obj->set("vhost", SrsJsonAny::str(stream->vhost->id.c_str()));
obj->set("stream", SrsJsonAny::str(stream->id.c_str())); obj->set("stream", SrsJsonAny::str(stream->id.c_str()));
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); obj->set("ip", SrsJsonAny::str(req->ip_.c_str()));
obj->set("pageUrl", SrsJsonAny::str(req->pageUrl.c_str())); obj->set("pageUrl", SrsJsonAny::str(req->pageUrl_.c_str()));
obj->set("swfUrl", SrsJsonAny::str(req->swfUrl.c_str())); obj->set("swfUrl", SrsJsonAny::str(req->swfUrl_.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); obj->set("tcUrl", SrsJsonAny::str(req->tcUrl_.c_str()));
obj->set("url", SrsJsonAny::str(req->get_stream_url().c_str())); obj->set("url", SrsJsonAny::str(req->get_stream_url().c_str()));
obj->set("name", SrsJsonAny::str(req->stream.c_str())); obj->set("name", SrsJsonAny::str(req->stream_.c_str()));
obj->set("type", SrsJsonAny::str(srs_client_type_string(type).c_str())); obj->set("type", SrsJsonAny::str(srs_client_type_string(type).c_str()));
obj->set("publish", SrsJsonAny::boolean(srs_client_type_is_publish(type))); obj->set("publish", SrsJsonAny::boolean(srs_client_type_is_publish(type)));
obj->set("alive", SrsJsonAny::number(srsu2ms(srs_time_now_cached() - create) / 1000.0)); obj->set("alive", SrsJsonAny::number(srsu2ms(srs_time_now_cached() - create) / 1000.0));
@ -739,15 +739,15 @@ SrsStatisticVhost *SrsStatistic::create_vhost(ISrsRequest *req)
SrsStatisticVhost *vhost = NULL; SrsStatisticVhost *vhost = NULL;
// create vhost if not exists. // create vhost if not exists.
if (rvhosts.find(req->vhost) == rvhosts.end()) { if (rvhosts.find(req->vhost_) == rvhosts.end()) {
vhost = new SrsStatisticVhost(); vhost = new SrsStatisticVhost();
vhost->vhost = req->vhost; vhost->vhost = req->vhost_;
rvhosts[req->vhost] = vhost; rvhosts[req->vhost_] = vhost;
vhosts[vhost->id] = vhost; vhosts[vhost->id] = vhost;
return vhost; return vhost;
} }
vhost = rvhosts[req->vhost]; vhost = rvhosts[req->vhost_];
return vhost; return vhost;
} }
@ -767,10 +767,10 @@ SrsStatisticStream *SrsStatistic::create_stream(SrsStatisticVhost *vhost, ISrsRe
if (rstreams.find(url) == rstreams.end()) { if (rstreams.find(url) == rstreams.end()) {
stream = new SrsStatisticStream(); stream = new SrsStatisticStream();
stream->vhost = vhost; stream->vhost = vhost;
stream->stream = req->stream; stream->stream = req->stream_;
stream->app = req->app; stream->app = req->app_;
stream->url = url; stream->url = url;
stream->tcUrl = req->tcUrl; stream->tcUrl = req->tcUrl_;
rstreams[url] = stream; rstreams[url] = stream;
streams[stream->id] = stream; streams[stream->id] = stream;
return stream; return stream;

View File

@ -9,6 +9,6 @@
#define VERSION_MAJOR 7 #define VERSION_MAJOR 7
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 82 #define VERSION_REVISION 83
#endif #endif

View File

@ -46,7 +46,7 @@ using namespace srs_internal;
SrsAmf0Any::SrsAmf0Any() SrsAmf0Any::SrsAmf0Any()
{ {
marker = RTMP_AMF0_Invalid; marker_ = RTMP_AMF0_Invalid;
} }
SrsAmf0Any::~SrsAmf0Any() SrsAmf0Any::~SrsAmf0Any()
@ -55,47 +55,47 @@ SrsAmf0Any::~SrsAmf0Any()
bool SrsAmf0Any::is_string() bool SrsAmf0Any::is_string()
{ {
return marker == RTMP_AMF0_String; return marker_ == RTMP_AMF0_String;
} }
bool SrsAmf0Any::is_boolean() bool SrsAmf0Any::is_boolean()
{ {
return marker == RTMP_AMF0_Boolean; return marker_ == RTMP_AMF0_Boolean;
} }
bool SrsAmf0Any::is_number() bool SrsAmf0Any::is_number()
{ {
return marker == RTMP_AMF0_Number; return marker_ == RTMP_AMF0_Number;
} }
bool SrsAmf0Any::is_null() bool SrsAmf0Any::is_null()
{ {
return marker == RTMP_AMF0_Null; return marker_ == RTMP_AMF0_Null;
} }
bool SrsAmf0Any::is_undefined() bool SrsAmf0Any::is_undefined()
{ {
return marker == RTMP_AMF0_Undefined; return marker_ == RTMP_AMF0_Undefined;
} }
bool SrsAmf0Any::is_object() bool SrsAmf0Any::is_object()
{ {
return marker == RTMP_AMF0_Object; return marker_ == RTMP_AMF0_Object;
} }
bool SrsAmf0Any::is_ecma_array() bool SrsAmf0Any::is_ecma_array()
{ {
return marker == RTMP_AMF0_EcmaArray; return marker_ == RTMP_AMF0_EcmaArray;
} }
bool SrsAmf0Any::is_strict_array() bool SrsAmf0Any::is_strict_array()
{ {
return marker == RTMP_AMF0_StrictArray; return marker_ == RTMP_AMF0_StrictArray;
} }
bool SrsAmf0Any::is_date() bool SrsAmf0Any::is_date()
{ {
return marker == RTMP_AMF0_Date; return marker_ == RTMP_AMF0_Date;
} }
bool SrsAmf0Any::is_complex_object() bool SrsAmf0Any::is_complex_object()
@ -107,28 +107,28 @@ string SrsAmf0Any::to_str()
{ {
SrsAmf0String *p = dynamic_cast<SrsAmf0String *>(this); SrsAmf0String *p = dynamic_cast<SrsAmf0String *>(this);
srs_assert(p != NULL); srs_assert(p != NULL);
return p->value; return p->value_;
} }
const char *SrsAmf0Any::to_str_raw() const char *SrsAmf0Any::to_str_raw()
{ {
SrsAmf0String *p = dynamic_cast<SrsAmf0String *>(this); SrsAmf0String *p = dynamic_cast<SrsAmf0String *>(this);
srs_assert(p != NULL); srs_assert(p != NULL);
return p->value.data(); return p->value_.data();
} }
bool SrsAmf0Any::to_boolean() bool SrsAmf0Any::to_boolean()
{ {
SrsAmf0Boolean *p = dynamic_cast<SrsAmf0Boolean *>(this); SrsAmf0Boolean *p = dynamic_cast<SrsAmf0Boolean *>(this);
srs_assert(p != NULL); srs_assert(p != NULL);
return p->value; return p->value_;
} }
double SrsAmf0Any::to_number() double SrsAmf0Any::to_number()
{ {
SrsAmf0Number *p = dynamic_cast<SrsAmf0Number *>(this); SrsAmf0Number *p = dynamic_cast<SrsAmf0Number *>(this);
srs_assert(p != NULL); srs_assert(p != NULL);
return p->value; return p->value_;
} }
int64_t SrsAmf0Any::to_date() int64_t SrsAmf0Any::to_date()
@ -170,12 +170,12 @@ void SrsAmf0Any::set_number(double value)
{ {
SrsAmf0Number *p = dynamic_cast<SrsAmf0Number *>(this); SrsAmf0Number *p = dynamic_cast<SrsAmf0Number *>(this);
srs_assert(p != NULL); srs_assert(p != NULL);
p->value = value; p->value_ = value;
} }
bool SrsAmf0Any::is_object_eof() bool SrsAmf0Any::is_object_eof()
{ {
return marker == RTMP_AMF0_ObjectEnd; return marker_ == RTMP_AMF0_ObjectEnd;
} }
void srs_fill_level_spaces(stringstream &ss, int level) void srs_fill_level_spaces(stringstream &ss, int level)
@ -273,7 +273,7 @@ char *SrsAmf0Any::human_print(char **pdata, int *psize)
SrsJsonAny *SrsAmf0Any::to_json() SrsJsonAny *SrsAmf0Any::to_json()
{ {
switch (marker) { switch (marker_) {
case RTMP_AMF0_String: { case RTMP_AMF0_String: {
return SrsJsonAny::str(to_str().c_str()); return SrsJsonAny::str(to_str().c_str());
} }
@ -442,38 +442,38 @@ SrsUnSortedHashtable::~SrsUnSortedHashtable()
int SrsUnSortedHashtable::count() int SrsUnSortedHashtable::count()
{ {
return (int)properties.size(); return (int)properties_.size();
} }
void SrsUnSortedHashtable::clear() void SrsUnSortedHashtable::clear()
{ {
std::vector<SrsAmf0ObjectPropertyType>::iterator it; std::vector<SrsAmf0ObjectPropertyType>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsAmf0ObjectPropertyType &elem = *it; SrsAmf0ObjectPropertyType &elem = *it;
SrsAmf0Any *any = elem.second; SrsAmf0Any *any = elem.second;
srs_freep(any); srs_freep(any);
} }
properties.clear(); properties_.clear();
} }
string SrsUnSortedHashtable::key_at(int index) string SrsUnSortedHashtable::key_at(int index)
{ {
srs_assert(index < count()); srs_assert(index < count());
SrsAmf0ObjectPropertyType &elem = properties[index]; SrsAmf0ObjectPropertyType &elem = properties_[index];
return elem.first; return elem.first;
} }
const char *SrsUnSortedHashtable::key_raw_at(int index) const char *SrsUnSortedHashtable::key_raw_at(int index)
{ {
srs_assert(index < count()); srs_assert(index < count());
SrsAmf0ObjectPropertyType &elem = properties[index]; SrsAmf0ObjectPropertyType &elem = properties_[index];
return elem.first.data(); return elem.first.data();
} }
SrsAmf0Any *SrsUnSortedHashtable::value_at(int index) SrsAmf0Any *SrsUnSortedHashtable::value_at(int index)
{ {
srs_assert(index < count()); srs_assert(index < count());
SrsAmf0ObjectPropertyType &elem = properties[index]; SrsAmf0ObjectPropertyType &elem = properties_[index];
return elem.second; return elem.second;
} }
@ -481,20 +481,20 @@ void SrsUnSortedHashtable::set(string key, SrsAmf0Any *value)
{ {
std::vector<SrsAmf0ObjectPropertyType>::iterator it; std::vector<SrsAmf0ObjectPropertyType>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsAmf0ObjectPropertyType &elem = *it; SrsAmf0ObjectPropertyType &elem = *it;
std::string name = elem.first; std::string name = elem.first;
SrsAmf0Any *any = elem.second; SrsAmf0Any *any = elem.second;
if (key == name) { if (key == name) {
srs_freep(any); srs_freep(any);
it = properties.erase(it); it = properties_.erase(it);
break; break;
} }
} }
if (value) { if (value) {
properties.push_back(std::make_pair(key, value)); properties_.push_back(std::make_pair(key, value));
} }
} }
@ -502,7 +502,7 @@ SrsAmf0Any *SrsUnSortedHashtable::get_property(string name)
{ {
std::vector<SrsAmf0ObjectPropertyType>::iterator it; std::vector<SrsAmf0ObjectPropertyType>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsAmf0ObjectPropertyType &elem = *it; SrsAmf0ObjectPropertyType &elem = *it;
std::string key = elem.first; std::string key = elem.first;
SrsAmf0Any *any = elem.second; SrsAmf0Any *any = elem.second;
@ -548,14 +548,14 @@ void SrsUnSortedHashtable::remove(string name)
{ {
std::vector<SrsAmf0ObjectPropertyType>::iterator it; std::vector<SrsAmf0ObjectPropertyType>::iterator it;
for (it = properties.begin(); it != properties.end();) { for (it = properties_.begin(); it != properties_.end();) {
std::string key = it->first; std::string key = it->first;
SrsAmf0Any *any = it->second; SrsAmf0Any *any = it->second;
if (key == name) { if (key == name) {
srs_freep(any); srs_freep(any);
it = properties.erase(it); it = properties_.erase(it);
} else { } else {
++it; ++it;
} }
@ -565,7 +565,7 @@ void SrsUnSortedHashtable::remove(string name)
void SrsUnSortedHashtable::copy(SrsUnSortedHashtable *src) void SrsUnSortedHashtable::copy(SrsUnSortedHashtable *src)
{ {
std::vector<SrsAmf0ObjectPropertyType>::iterator it; std::vector<SrsAmf0ObjectPropertyType>::iterator it;
for (it = src->properties.begin(); it != src->properties.end(); ++it) { for (it = src->properties_.begin(); it != src->properties_.end(); ++it) {
SrsAmf0ObjectPropertyType &elem = *it; SrsAmf0ObjectPropertyType &elem = *it;
std::string key = elem.first; std::string key = elem.first;
SrsAmf0Any *any = elem.second; SrsAmf0Any *any = elem.second;
@ -575,7 +575,7 @@ void SrsUnSortedHashtable::copy(SrsUnSortedHashtable *src)
SrsAmf0ObjectEOF::SrsAmf0ObjectEOF() SrsAmf0ObjectEOF::SrsAmf0ObjectEOF()
{ {
marker = RTMP_AMF0_ObjectEnd; marker_ = RTMP_AMF0_ObjectEnd;
} }
SrsAmf0ObjectEOF::~SrsAmf0ObjectEOF() SrsAmf0ObjectEOF::~SrsAmf0ObjectEOF()
@ -640,22 +640,22 @@ SrsAmf0Any *SrsAmf0ObjectEOF::copy()
SrsAmf0Object::SrsAmf0Object() SrsAmf0Object::SrsAmf0Object()
{ {
properties = new SrsUnSortedHashtable(); properties_ = new SrsUnSortedHashtable();
eof = new SrsAmf0ObjectEOF(); eof_ = new SrsAmf0ObjectEOF();
marker = RTMP_AMF0_Object; marker_ = RTMP_AMF0_Object;
} }
SrsAmf0Object::~SrsAmf0Object() SrsAmf0Object::~SrsAmf0Object()
{ {
srs_freep(properties); srs_freep(properties_);
srs_freep(eof); srs_freep(eof_);
} }
int SrsAmf0Object::total_size() int SrsAmf0Object::total_size()
{ {
int size = 1; int size = 1;
for (int i = 0; i < properties->count(); i++) { for (int i = 0; i < properties_->count(); i++) {
std::string name = key_at(i); std::string name = key_at(i);
SrsAmf0Any *value = value_at(i); SrsAmf0Any *value = value_at(i);
@ -724,7 +724,7 @@ srs_error_t SrsAmf0Object::write(SrsBuffer *stream)
stream->write_1bytes(RTMP_AMF0_Object); stream->write_1bytes(RTMP_AMF0_Object);
// value // value
for (int i = 0; i < properties->count(); i++) { for (int i = 0; i < properties_->count(); i++) {
std::string name = this->key_at(i); std::string name = this->key_at(i);
SrsAmf0Any *any = this->value_at(i); SrsAmf0Any *any = this->value_at(i);
@ -737,7 +737,7 @@ srs_error_t SrsAmf0Object::write(SrsBuffer *stream)
} }
} }
if ((err = eof->write(stream)) != srs_success) { if ((err = eof_->write(stream)) != srs_success) {
return srs_error_wrap(err, "write EOF"); return srs_error_wrap(err, "write EOF");
} }
@ -747,7 +747,7 @@ srs_error_t SrsAmf0Object::write(SrsBuffer *stream)
SrsAmf0Any *SrsAmf0Object::copy() SrsAmf0Any *SrsAmf0Object::copy()
{ {
SrsAmf0Object *copy = new SrsAmf0Object(); SrsAmf0Object *copy = new SrsAmf0Object();
copy->properties->copy(properties); copy->properties_->copy(properties_);
return copy; return copy;
} }
@ -755,7 +755,7 @@ SrsJsonAny *SrsAmf0Object::to_json()
{ {
SrsJsonObject *obj = SrsJsonAny::object(); SrsJsonObject *obj = SrsJsonAny::object();
for (int i = 0; i < properties->count(); i++) { for (int i = 0; i < properties_->count(); i++) {
std::string name = this->key_at(i); std::string name = this->key_at(i);
SrsAmf0Any *any = this->value_at(i); SrsAmf0Any *any = this->value_at(i);
@ -767,73 +767,73 @@ SrsJsonAny *SrsAmf0Object::to_json()
void SrsAmf0Object::clear() void SrsAmf0Object::clear()
{ {
properties->clear(); properties_->clear();
} }
int SrsAmf0Object::count() int SrsAmf0Object::count()
{ {
return properties->count(); return properties_->count();
} }
string SrsAmf0Object::key_at(int index) string SrsAmf0Object::key_at(int index)
{ {
return properties->key_at(index); return properties_->key_at(index);
} }
const char *SrsAmf0Object::key_raw_at(int index) const char *SrsAmf0Object::key_raw_at(int index)
{ {
return properties->key_raw_at(index); return properties_->key_raw_at(index);
} }
SrsAmf0Any *SrsAmf0Object::value_at(int index) SrsAmf0Any *SrsAmf0Object::value_at(int index)
{ {
return properties->value_at(index); return properties_->value_at(index);
} }
void SrsAmf0Object::set(string key, SrsAmf0Any *value) void SrsAmf0Object::set(string key, SrsAmf0Any *value)
{ {
properties->set(key, value); properties_->set(key, value);
} }
SrsAmf0Any *SrsAmf0Object::get_property(string name) SrsAmf0Any *SrsAmf0Object::get_property(string name)
{ {
return properties->get_property(name); return properties_->get_property(name);
} }
SrsAmf0Any *SrsAmf0Object::ensure_property_string(string name) SrsAmf0Any *SrsAmf0Object::ensure_property_string(string name)
{ {
return properties->ensure_property_string(name); return properties_->ensure_property_string(name);
} }
SrsAmf0Any *SrsAmf0Object::ensure_property_number(string name) SrsAmf0Any *SrsAmf0Object::ensure_property_number(string name)
{ {
return properties->ensure_property_number(name); return properties_->ensure_property_number(name);
} }
void SrsAmf0Object::remove(string name) void SrsAmf0Object::remove(string name)
{ {
properties->remove(name); properties_->remove(name);
} }
SrsAmf0EcmaArray::SrsAmf0EcmaArray() SrsAmf0EcmaArray::SrsAmf0EcmaArray()
{ {
_count = 0; _count = 0;
properties = new SrsUnSortedHashtable(); properties_ = new SrsUnSortedHashtable();
eof = new SrsAmf0ObjectEOF(); eof_ = new SrsAmf0ObjectEOF();
marker = RTMP_AMF0_EcmaArray; marker_ = RTMP_AMF0_EcmaArray;
} }
SrsAmf0EcmaArray::~SrsAmf0EcmaArray() SrsAmf0EcmaArray::~SrsAmf0EcmaArray()
{ {
srs_freep(properties); srs_freep(properties_);
srs_freep(eof); srs_freep(eof_);
} }
int SrsAmf0EcmaArray::total_size() int SrsAmf0EcmaArray::total_size()
{ {
int size = 1 + 4; int size = 1 + 4;
for (int i = 0; i < properties->count(); i++) { for (int i = 0; i < properties_->count(); i++) {
std::string name = key_at(i); std::string name = key_at(i);
SrsAmf0Any *value = value_at(i); SrsAmf0Any *value = value_at(i);
@ -917,7 +917,7 @@ srs_error_t SrsAmf0EcmaArray::write(SrsBuffer *stream)
stream->write_4bytes(this->_count); stream->write_4bytes(this->_count);
// value // value
for (int i = 0; i < properties->count(); i++) { for (int i = 0; i < properties_->count(); i++) {
std::string name = this->key_at(i); std::string name = this->key_at(i);
SrsAmf0Any *any = this->value_at(i); SrsAmf0Any *any = this->value_at(i);
@ -930,7 +930,7 @@ srs_error_t SrsAmf0EcmaArray::write(SrsBuffer *stream)
} }
} }
if ((err = eof->write(stream)) != srs_success) { if ((err = eof_->write(stream)) != srs_success) {
return srs_error_wrap(err, "write EOF"); return srs_error_wrap(err, "write EOF");
} }
@ -940,7 +940,7 @@ srs_error_t SrsAmf0EcmaArray::write(SrsBuffer *stream)
SrsAmf0Any *SrsAmf0EcmaArray::copy() SrsAmf0Any *SrsAmf0EcmaArray::copy()
{ {
SrsAmf0EcmaArray *copy = new SrsAmf0EcmaArray(); SrsAmf0EcmaArray *copy = new SrsAmf0EcmaArray();
copy->properties->copy(properties); copy->properties_->copy(properties_);
copy->_count = _count; copy->_count = _count;
return copy; return copy;
} }
@ -949,7 +949,7 @@ SrsJsonAny *SrsAmf0EcmaArray::to_json()
{ {
SrsJsonObject *obj = SrsJsonAny::object(); SrsJsonObject *obj = SrsJsonAny::object();
for (int i = 0; i < properties->count(); i++) { for (int i = 0; i < properties_->count(); i++) {
std::string name = this->key_at(i); std::string name = this->key_at(i);
SrsAmf0Any *any = this->value_at(i); SrsAmf0Any *any = this->value_at(i);
@ -961,52 +961,52 @@ SrsJsonAny *SrsAmf0EcmaArray::to_json()
void SrsAmf0EcmaArray::clear() void SrsAmf0EcmaArray::clear()
{ {
properties->clear(); properties_->clear();
} }
int SrsAmf0EcmaArray::count() int SrsAmf0EcmaArray::count()
{ {
return properties->count(); return properties_->count();
} }
string SrsAmf0EcmaArray::key_at(int index) string SrsAmf0EcmaArray::key_at(int index)
{ {
return properties->key_at(index); return properties_->key_at(index);
} }
const char *SrsAmf0EcmaArray::key_raw_at(int index) const char *SrsAmf0EcmaArray::key_raw_at(int index)
{ {
return properties->key_raw_at(index); return properties_->key_raw_at(index);
} }
SrsAmf0Any *SrsAmf0EcmaArray::value_at(int index) SrsAmf0Any *SrsAmf0EcmaArray::value_at(int index)
{ {
return properties->value_at(index); return properties_->value_at(index);
} }
void SrsAmf0EcmaArray::set(string key, SrsAmf0Any *value) void SrsAmf0EcmaArray::set(string key, SrsAmf0Any *value)
{ {
properties->set(key, value); properties_->set(key, value);
} }
SrsAmf0Any *SrsAmf0EcmaArray::get_property(string name) SrsAmf0Any *SrsAmf0EcmaArray::get_property(string name)
{ {
return properties->get_property(name); return properties_->get_property(name);
} }
SrsAmf0Any *SrsAmf0EcmaArray::ensure_property_string(string name) SrsAmf0Any *SrsAmf0EcmaArray::ensure_property_string(string name)
{ {
return properties->ensure_property_string(name); return properties_->ensure_property_string(name);
} }
SrsAmf0Any *SrsAmf0EcmaArray::ensure_property_number(string name) SrsAmf0Any *SrsAmf0EcmaArray::ensure_property_number(string name)
{ {
return properties->ensure_property_number(name); return properties_->ensure_property_number(name);
} }
SrsAmf0StrictArray::SrsAmf0StrictArray() SrsAmf0StrictArray::SrsAmf0StrictArray()
{ {
marker = RTMP_AMF0_StrictArray; marker_ = RTMP_AMF0_StrictArray;
_count = 0; _count = 0;
} }
@ -1019,8 +1019,8 @@ int SrsAmf0StrictArray::total_size()
{ {
int size = 1 + 4; int size = 1 + 4;
for (int i = 0; i < (int)properties.size(); i++) { for (int i = 0; i < (int)properties_.size(); i++) {
SrsAmf0Any *any = properties[i]; SrsAmf0Any *any = properties_[i];
size += any->total_size(); size += any->total_size();
} }
@ -1059,7 +1059,7 @@ srs_error_t SrsAmf0StrictArray::read(SrsBuffer *stream)
} }
// add property // add property
properties.push_back(elem); properties_.push_back(elem);
} }
return err; return err;
@ -1084,8 +1084,8 @@ srs_error_t SrsAmf0StrictArray::write(SrsBuffer *stream)
stream->write_4bytes(this->_count); stream->write_4bytes(this->_count);
// value // value
for (int i = 0; i < (int)properties.size(); i++) { for (int i = 0; i < (int)properties_.size(); i++) {
SrsAmf0Any *any = properties[i]; SrsAmf0Any *any = properties_[i];
if ((err = srs_amf0_write_any(stream, any)) != srs_success) { if ((err = srs_amf0_write_any(stream, any)) != srs_success) {
return srs_error_wrap(err, "write property"); return srs_error_wrap(err, "write property");
@ -1100,7 +1100,7 @@ SrsAmf0Any *SrsAmf0StrictArray::copy()
SrsAmf0StrictArray *copy = new SrsAmf0StrictArray(); SrsAmf0StrictArray *copy = new SrsAmf0StrictArray();
std::vector<SrsAmf0Any *>::iterator it; std::vector<SrsAmf0Any *>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsAmf0Any *any = *it; SrsAmf0Any *any = *it;
copy->append(any->copy()); copy->append(any->copy());
} }
@ -1113,8 +1113,8 @@ SrsJsonAny *SrsAmf0StrictArray::to_json()
{ {
SrsJsonArray *arr = SrsJsonAny::array(); SrsJsonArray *arr = SrsJsonAny::array();
for (int i = 0; i < (int)properties.size(); i++) { for (int i = 0; i < (int)properties_.size(); i++) {
SrsAmf0Any *any = properties[i]; SrsAmf0Any *any = properties_[i];
arr->append(any->to_json()); arr->append(any->to_json());
} }
@ -1125,28 +1125,28 @@ SrsJsonAny *SrsAmf0StrictArray::to_json()
void SrsAmf0StrictArray::clear() void SrsAmf0StrictArray::clear()
{ {
std::vector<SrsAmf0Any *>::iterator it; std::vector<SrsAmf0Any *>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsAmf0Any *any = *it; SrsAmf0Any *any = *it;
srs_freep(any); srs_freep(any);
} }
properties.clear(); properties_.clear();
} }
int SrsAmf0StrictArray::count() int SrsAmf0StrictArray::count()
{ {
return (int)properties.size(); return (int)properties_.size();
} }
SrsAmf0Any *SrsAmf0StrictArray::at(int index) SrsAmf0Any *SrsAmf0StrictArray::at(int index)
{ {
srs_assert(index < (int)properties.size()); srs_assert(index < (int)properties_.size());
return properties.at(index); return properties_.at(index);
} }
void SrsAmf0StrictArray::append(SrsAmf0Any *any) void SrsAmf0StrictArray::append(SrsAmf0Any *any)
{ {
properties.push_back(any); properties_.push_back(any);
_count = (int32_t)properties.size(); _count = (int32_t)properties_.size();
} }
int SrsAmf0Size::utf8(string value) int SrsAmf0Size::utf8(string value)
@ -1227,9 +1227,9 @@ int SrsAmf0Size::any(SrsAmf0Any *o)
SrsAmf0String::SrsAmf0String(const char *_value) SrsAmf0String::SrsAmf0String(const char *_value)
{ {
marker = RTMP_AMF0_String; marker_ = RTMP_AMF0_String;
if (_value) { if (_value) {
value = _value; value_ = _value;
} }
} }
@ -1239,29 +1239,29 @@ SrsAmf0String::~SrsAmf0String()
int SrsAmf0String::total_size() int SrsAmf0String::total_size()
{ {
return SrsAmf0Size::str(value); return SrsAmf0Size::str(value_);
} }
srs_error_t SrsAmf0String::read(SrsBuffer *stream) srs_error_t SrsAmf0String::read(SrsBuffer *stream)
{ {
return srs_amf0_read_string(stream, value); return srs_amf0_read_string(stream, value_);
} }
srs_error_t SrsAmf0String::write(SrsBuffer *stream) srs_error_t SrsAmf0String::write(SrsBuffer *stream)
{ {
return srs_amf0_write_string(stream, value); return srs_amf0_write_string(stream, value_);
} }
SrsAmf0Any *SrsAmf0String::copy() SrsAmf0Any *SrsAmf0String::copy()
{ {
SrsAmf0String *copy = new SrsAmf0String(value.c_str()); SrsAmf0String *copy = new SrsAmf0String(value_.c_str());
return copy; return copy;
} }
SrsAmf0Boolean::SrsAmf0Boolean(bool _value) SrsAmf0Boolean::SrsAmf0Boolean(bool _value)
{ {
marker = RTMP_AMF0_Boolean; marker_ = RTMP_AMF0_Boolean;
value = _value; value_ = _value;
} }
SrsAmf0Boolean::~SrsAmf0Boolean() SrsAmf0Boolean::~SrsAmf0Boolean()
@ -1275,24 +1275,24 @@ int SrsAmf0Boolean::total_size()
srs_error_t SrsAmf0Boolean::read(SrsBuffer *stream) srs_error_t SrsAmf0Boolean::read(SrsBuffer *stream)
{ {
return srs_amf0_read_boolean(stream, value); return srs_amf0_read_boolean(stream, value_);
} }
srs_error_t SrsAmf0Boolean::write(SrsBuffer *stream) srs_error_t SrsAmf0Boolean::write(SrsBuffer *stream)
{ {
return srs_amf0_write_boolean(stream, value); return srs_amf0_write_boolean(stream, value_);
} }
SrsAmf0Any *SrsAmf0Boolean::copy() SrsAmf0Any *SrsAmf0Boolean::copy()
{ {
SrsAmf0Boolean *copy = new SrsAmf0Boolean(value); SrsAmf0Boolean *copy = new SrsAmf0Boolean(value_);
return copy; return copy;
} }
SrsAmf0Number::SrsAmf0Number(double _value) SrsAmf0Number::SrsAmf0Number(double _value)
{ {
marker = RTMP_AMF0_Number; marker_ = RTMP_AMF0_Number;
value = _value; value_ = _value;
} }
SrsAmf0Number::~SrsAmf0Number() SrsAmf0Number::~SrsAmf0Number()
@ -1306,23 +1306,23 @@ int SrsAmf0Number::total_size()
srs_error_t SrsAmf0Number::read(SrsBuffer *stream) srs_error_t SrsAmf0Number::read(SrsBuffer *stream)
{ {
return srs_amf0_read_number(stream, value); return srs_amf0_read_number(stream, value_);
} }
srs_error_t SrsAmf0Number::write(SrsBuffer *stream) srs_error_t SrsAmf0Number::write(SrsBuffer *stream)
{ {
return srs_amf0_write_number(stream, value); return srs_amf0_write_number(stream, value_);
} }
SrsAmf0Any *SrsAmf0Number::copy() SrsAmf0Any *SrsAmf0Number::copy()
{ {
SrsAmf0Number *copy = new SrsAmf0Number(value); SrsAmf0Number *copy = new SrsAmf0Number(value_);
return copy; return copy;
} }
SrsAmf0Date::SrsAmf0Date(int64_t value) SrsAmf0Date::SrsAmf0Date(int64_t value)
{ {
marker = RTMP_AMF0_Date; marker_ = RTMP_AMF0_Date;
_date_value = value; _date_value = value;
_time_zone = 0; _time_zone = 0;
} }
@ -1424,7 +1424,7 @@ int16_t SrsAmf0Date::time_zone()
SrsAmf0Null::SrsAmf0Null() SrsAmf0Null::SrsAmf0Null()
{ {
marker = RTMP_AMF0_Null; marker_ = RTMP_AMF0_Null;
} }
SrsAmf0Null::~SrsAmf0Null() SrsAmf0Null::~SrsAmf0Null()
@ -1454,7 +1454,7 @@ SrsAmf0Any *SrsAmf0Null::copy()
SrsAmf0Undefined::SrsAmf0Undefined() SrsAmf0Undefined::SrsAmf0Undefined()
{ {
marker = RTMP_AMF0_Undefined; marker_ = RTMP_AMF0_Undefined;
} }
SrsAmf0Undefined::~SrsAmf0Undefined() SrsAmf0Undefined::~SrsAmf0Undefined()

View File

@ -108,7 +108,7 @@ class SrsAmf0Date;
class SrsAmf0Any class SrsAmf0Any
{ {
public: public:
char marker; char marker_;
public: public:
SrsAmf0Any(); SrsAmf0Any();
@ -319,8 +319,8 @@ public:
class SrsAmf0Object : public SrsAmf0Any class SrsAmf0Object : public SrsAmf0Any
{ {
private: private:
srs_internal::SrsUnSortedHashtable *properties; srs_internal::SrsUnSortedHashtable *properties_;
srs_internal::SrsAmf0ObjectEOF *eof; srs_internal::SrsAmf0ObjectEOF *eof_;
private: private:
friend class SrsAmf0Any; friend class SrsAmf0Any;
@ -411,8 +411,8 @@ public:
class SrsAmf0EcmaArray : public SrsAmf0Any class SrsAmf0EcmaArray : public SrsAmf0Any
{ {
private: private:
srs_internal::SrsUnSortedHashtable *properties; srs_internal::SrsUnSortedHashtable *properties_;
srs_internal::SrsAmf0ObjectEOF *eof; srs_internal::SrsAmf0ObjectEOF *eof_;
int32_t _count; int32_t _count;
private: private:
@ -499,7 +499,7 @@ public:
class SrsAmf0StrictArray : public SrsAmf0Any class SrsAmf0StrictArray : public SrsAmf0Any
{ {
private: private:
std::vector<SrsAmf0Any *> properties; std::vector<SrsAmf0Any *> properties_;
int32_t _count; int32_t _count;
private: private:
@ -628,7 +628,7 @@ namespace srs_internal
class SrsAmf0String : public SrsAmf0Any class SrsAmf0String : public SrsAmf0Any
{ {
public: public:
std::string value; std::string value_;
private: private:
friend class SrsAmf0Any; friend class SrsAmf0Any;
@ -658,7 +658,7 @@ public:
class SrsAmf0Boolean : public SrsAmf0Any class SrsAmf0Boolean : public SrsAmf0Any
{ {
public: public:
bool value; bool value_;
private: private:
friend class SrsAmf0Any; friend class SrsAmf0Any;
@ -687,7 +687,7 @@ public:
class SrsAmf0Number : public SrsAmf0Any class SrsAmf0Number : public SrsAmf0Any
{ {
public: public:
double value; double value_;
private: private:
friend class SrsAmf0Any; friend class SrsAmf0Any;
@ -807,7 +807,7 @@ class SrsUnSortedHashtable
{ {
private: private:
typedef std::pair<std::string, SrsAmf0Any *> SrsAmf0ObjectPropertyType; typedef std::pair<std::string, SrsAmf0Any *> SrsAmf0ObjectPropertyType;
std::vector<SrsAmf0ObjectPropertyType> properties; std::vector<SrsAmf0ObjectPropertyType> properties_;
public: public:
SrsUnSortedHashtable(); SrsUnSortedHashtable();

View File

@ -35,22 +35,22 @@ int srs_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
SrsSslClient::SrsSslClient(SrsTcpClient *tcp) SrsSslClient::SrsSslClient(SrsTcpClient *tcp)
{ {
transport = tcp; transport_ = tcp;
ssl_ctx = NULL; ssl_ctx_ = NULL;
ssl = NULL; ssl_ = NULL;
} }
SrsSslClient::~SrsSslClient() SrsSslClient::~SrsSslClient()
{ {
if (ssl) { if (ssl_) {
// this function will free bio_in and bio_out // this function will free bio_in_ and bio_out_
SSL_free(ssl); SSL_free(ssl_);
ssl = NULL; ssl_ = NULL;
} }
if (ssl_ctx) { if (ssl_ctx_) {
SSL_CTX_free(ssl_ctx); SSL_CTX_free(ssl_ctx_);
ssl_ctx = NULL; ssl_ctx_ = NULL;
} }
} }
@ -62,54 +62,54 @@ srs_error_t SrsSslClient::handshake(const std::string &host)
// For HTTPS, try to connect over security transport. // For HTTPS, try to connect over security transport.
#if (OPENSSL_VERSION_NUMBER < 0x10002000L) // v1.0.2 #if (OPENSSL_VERSION_NUMBER < 0x10002000L) // v1.0.2
ssl_ctx = SSL_CTX_new(TLS_method()); ssl_ctx_ = SSL_CTX_new(TLS_method());
#else #else
ssl_ctx = SSL_CTX_new(TLSv1_2_method()); ssl_ctx_ = SSL_CTX_new(TLSv1_2_method());
#endif #endif
SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, srs_verify_callback); SSL_CTX_set_verify(ssl_ctx_, SSL_VERIFY_PEER, srs_verify_callback);
srs_assert(SSL_CTX_set_cipher_list(ssl_ctx, "ALL") == 1); srs_assert(SSL_CTX_set_cipher_list(ssl_ctx_, "ALL") == 1);
// TODO: Setup callback, see SSL_set_ex_data and SSL_set_info_callback // TODO: Setup callback, see SSL_set_ex_data and SSL_set_info_callback
if ((ssl = SSL_new(ssl_ctx)) == NULL) { if ((ssl_ = SSL_new(ssl_ctx_)) == NULL) {
return srs_error_new(ERROR_TLS_HANDSHAKE, "SSL_new ssl"); return srs_error_new(ERROR_TLS_HANDSHAKE, "SSL_new ssl");
} }
if ((bio_in = BIO_new(BIO_s_mem())) == NULL) { if ((bio_in_ = BIO_new(BIO_s_mem())) == NULL) {
return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_new in"); return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_new in");
} }
if ((bio_out = BIO_new(BIO_s_mem())) == NULL) { if ((bio_out_ = BIO_new(BIO_s_mem())) == NULL) {
BIO_free(bio_in); BIO_free(bio_in_);
return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_new out"); return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_new out");
} }
SSL_set_bio(ssl, bio_in, bio_out); SSL_set_bio(ssl_, bio_in_, bio_out_);
// SSL setup active, as client role. // SSL setup active, as client role.
SSL_set_connect_state(ssl); SSL_set_connect_state(ssl_);
SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE); SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE);
// If the server address is not in IP address format, set the host in the Server Name Indication (SNI) field. // If the server address is not in IP address format, set the host in the Server Name Indication (SNI) field.
if (!srs_net_is_valid_ip(host)) { if (!srs_net_is_valid_ip(host)) {
SSL_set_tlsext_host_name(ssl, host.c_str()); SSL_set_tlsext_host_name(ssl_, host.c_str());
} }
// Send ClientHello. // Send ClientHello.
int r0 = SSL_do_handshake(ssl); int r0 = SSL_do_handshake(ssl_);
int r1 = SSL_get_error(ssl, r0); int r1 = SSL_get_error(ssl_, r0);
ERR_clear_error(); ERR_clear_error();
if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) { if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) {
return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1); return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1);
} }
uint8_t *data = NULL; uint8_t *data = NULL;
int size = BIO_get_mem_data(bio_out, &data); int size = BIO_get_mem_data(bio_out_, &data);
if (!data || size <= 0) { if (!data || size <= 0) {
return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake data=%p, size=%d", data, size); return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake data=%p, size=%d", data, size);
} }
if ((err = transport->write(data, size, NULL)) != srs_success) { if ((err = transport_->write(data, size, NULL)) != srs_success) {
return srs_error_wrap(err, "handshake: write data=%p, size=%d", data, size); return srs_error_wrap(err, "handshake: write data=%p, size=%d", data, size);
} }
if ((r0 = BIO_reset(bio_out)) != 1) { if ((r0 = BIO_reset(bio_out_)) != 1) {
return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0); return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0);
} }
@ -119,25 +119,25 @@ srs_error_t SrsSslClient::handshake(const std::string &host)
while (true) { while (true) {
char buf[512]; char buf[512];
ssize_t nn = 0; ssize_t nn = 0;
if ((err = transport->read(buf, sizeof(buf), &nn)) != srs_success) { if ((err = transport_->read(buf, sizeof(buf), &nn)) != srs_success) {
return srs_error_wrap(err, "handshake: read"); return srs_error_wrap(err, "handshake: read");
} }
if ((r0 = BIO_write(bio_in, buf, nn)) <= 0) { if ((r0 = BIO_write(bio_in_, buf, nn)) <= 0) {
// TODO: 0 or -1 maybe block, use BIO_should_retry to check. // TODO: 0 or -1 maybe block, use BIO_should_retry to check.
return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn); return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn);
} }
r0 = SSL_do_handshake(ssl); r0 = SSL_do_handshake(ssl_);
r1 = SSL_get_error(ssl, r0); r1 = SSL_get_error(ssl_, r0);
ERR_clear_error(); ERR_clear_error();
if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) { if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) {
return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1); return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1);
} }
if ((size = BIO_get_mem_data(bio_out, &data)) > 0) { if ((size = BIO_get_mem_data(bio_out_, &data)) > 0) {
// OK, reset it for the next write. // OK, reset it for the next write.
if ((r0 = BIO_reset(bio_in)) != 1) { if ((r0 = BIO_reset(bio_in_)) != 1) {
return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0); return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0);
} }
break; break;
@ -147,10 +147,10 @@ srs_error_t SrsSslClient::handshake(const std::string &host)
srs_info("tls: ServerHello done"); srs_info("tls: ServerHello done");
// Send Client Key Exchange, Change Cipher Spec, Encrypted Handshake Message // Send Client Key Exchange, Change Cipher Spec, Encrypted Handshake Message
if ((err = transport->write(data, size, NULL)) != srs_success) { if ((err = transport_->write(data, size, NULL)) != srs_success) {
return srs_error_wrap(err, "handshake: write data=%p, size=%d", data, size); return srs_error_wrap(err, "handshake: write data=%p, size=%d", data, size);
} }
if ((r0 = BIO_reset(bio_out)) != 1) { if ((r0 = BIO_reset(bio_out_)) != 1) {
return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0); return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0);
} }
@ -160,17 +160,17 @@ srs_error_t SrsSslClient::handshake(const std::string &host)
while (true) { while (true) {
char buf[128]; char buf[128];
ssize_t nn = 0; ssize_t nn = 0;
if ((err = transport->read(buf, sizeof(buf), &nn)) != srs_success) { if ((err = transport_->read(buf, sizeof(buf), &nn)) != srs_success) {
return srs_error_wrap(err, "handshake: read"); return srs_error_wrap(err, "handshake: read");
} }
if ((r0 = BIO_write(bio_in, buf, nn)) <= 0) { if ((r0 = BIO_write(bio_in_, buf, nn)) <= 0) {
// TODO: 0 or -1 maybe block, use BIO_should_retry to check. // TODO: 0 or -1 maybe block, use BIO_should_retry to check.
return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn); return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn);
} }
r0 = SSL_do_handshake(ssl); r0 = SSL_do_handshake(ssl_);
r1 = SSL_get_error(ssl, r0); r1 = SSL_get_error(ssl_, r0);
ERR_clear_error(); ERR_clear_error();
if (r0 == 1 && r1 == SSL_ERROR_NONE) { if (r0 == 1 && r1 == SSL_ERROR_NONE) {
break; break;
@ -192,11 +192,11 @@ srs_error_t SrsSslClient::read(void *plaintext, size_t nn_plaintext, ssize_t *nr
srs_error_t err = srs_success; srs_error_t err = srs_success;
while (true) { while (true) {
int r0 = SSL_read(ssl, plaintext, nn_plaintext); int r0 = SSL_read(ssl_, plaintext, nn_plaintext);
int r1 = SSL_get_error(ssl, r0); int r1 = SSL_get_error(ssl_, r0);
ERR_clear_error(); ERR_clear_error();
int r2 = BIO_ctrl_pending(bio_in); int r2 = BIO_ctrl_pending(bio_in_);
int r3 = SSL_is_init_finished(ssl); int r3 = SSL_is_init_finished(ssl_);
// OK, got data. // OK, got data.
if (r0 > 0) { if (r0 > 0) {
@ -215,11 +215,11 @@ srs_error_t SrsSslClient::read(void *plaintext, size_t nn_plaintext, ssize_t *nr
// Read the cipher from SSL. // Read the cipher from SSL.
ssize_t nn = 0; ssize_t nn = 0;
if ((err = transport->read(cipher.get(), nn_cipher, &nn)) != srs_success) { if ((err = transport_->read(cipher.get(), nn_cipher, &nn)) != srs_success) {
return srs_error_wrap(err, "https: read"); return srs_error_wrap(err, "https: read");
} }
int r0 = BIO_write(bio_in, cipher.get(), nn); int r0 = BIO_write(bio_in_, cipher.get(), nn);
if (r0 <= 0) { if (r0 <= 0) {
// TODO: 0 or -1 maybe block, use BIO_should_retry to check. // TODO: 0 or -1 maybe block, use BIO_should_retry to check.
return srs_error_new(ERROR_TLS_READ, "BIO_write r0=%d, cipher=%p, size=%d", r0, cipher.get(), nn); return srs_error_new(ERROR_TLS_READ, "BIO_write r0=%d, cipher=%p, size=%d", r0, cipher.get(), nn);
@ -241,8 +241,8 @@ srs_error_t SrsSslClient::write(void *plaintext, size_t nn_plaintext, ssize_t *n
for (char *p = (char *)plaintext; p < (char *)plaintext + nn_plaintext;) { for (char *p = (char *)plaintext; p < (char *)plaintext + nn_plaintext;) {
int left = (int)nn_plaintext - (p - (char *)plaintext); int left = (int)nn_plaintext - (p - (char *)plaintext);
int r0 = SSL_write(ssl, (const void *)p, left); int r0 = SSL_write(ssl_, (const void *)p, left);
int r1 = SSL_get_error(ssl, r0); int r1 = SSL_get_error(ssl_, r0);
ERR_clear_error(); ERR_clear_error();
if (r0 <= 0) { if (r0 <= 0) {
return srs_error_new(ERROR_TLS_WRITE, "tls: write data=%p, size=%d, r0=%d, r1=%d", p, left, r0, r1); return srs_error_new(ERROR_TLS_WRITE, "tls: write data=%p, size=%d, r0=%d, r1=%d", p, left, r0, r1);
@ -255,11 +255,11 @@ srs_error_t SrsSslClient::write(void *plaintext, size_t nn_plaintext, ssize_t *n
} }
uint8_t *data = NULL; uint8_t *data = NULL;
int size = BIO_get_mem_data(bio_out, &data); int size = BIO_get_mem_data(bio_out_, &data);
if ((err = transport->write(data, size, NULL)) != srs_success) { if ((err = transport_->write(data, size, NULL)) != srs_success) {
return srs_error_wrap(err, "tls: write data=%p, size=%d", data, size); return srs_error_wrap(err, "tls: write data=%p, size=%d", data, size);
} }
if ((r0 = BIO_reset(bio_out)) != 1) { if ((r0 = BIO_reset(bio_out_)) != 1) {
return srs_error_new(ERROR_TLS_WRITE, "BIO_reset r0=%d", r0); return srs_error_new(ERROR_TLS_WRITE, "BIO_reset r0=%d", r0);
} }
} }
@ -269,58 +269,58 @@ srs_error_t SrsSslClient::write(void *plaintext, size_t nn_plaintext, ssize_t *n
SrsHttpClient::SrsHttpClient() SrsHttpClient::SrsHttpClient()
{ {
transport = NULL; transport_ = NULL;
ssl_transport = NULL; ssl_transport_ = NULL;
kbps = new SrsNetworkKbps(); kbps_ = new SrsNetworkKbps();
parser = NULL; parser_ = NULL;
recv_timeout = timeout = SRS_UTIME_NO_TIMEOUT; recv_timeout_ = timeout_ = SRS_UTIME_NO_TIMEOUT;
port = 0; port_ = 0;
} }
SrsHttpClient::~SrsHttpClient() SrsHttpClient::~SrsHttpClient()
{ {
disconnect(); disconnect();
srs_freep(kbps); srs_freep(kbps_);
srs_freep(parser); srs_freep(parser_);
} }
srs_error_t SrsHttpClient::initialize(string schema, string h, int p, srs_utime_t tm) srs_error_t SrsHttpClient::initialize(string schema, string h, int p, srs_utime_t tm)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_freep(parser); srs_freep(parser_);
parser = new SrsHttpParser(); parser_ = new SrsHttpParser();
if ((err = parser->initialize(HTTP_RESPONSE)) != srs_success) { if ((err = parser_->initialize(HTTP_RESPONSE)) != srs_success) {
return srs_error_wrap(err, "http: init parser"); return srs_error_wrap(err, "http: init parser");
} }
// Always disconnect the transport. // Always disconnect the transport.
schema_ = schema; schema_ = schema;
host = h; host_ = h;
port = p; port_ = p;
recv_timeout = timeout = tm; recv_timeout_ = timeout_ = tm;
disconnect(); disconnect();
// ep used for host in header. // ep used for host in header.
string ep = host; string ep = host_;
if (port > 0 && port != SRS_CONSTS_HTTP_DEFAULT_PORT) { if (port_ > 0 && port_ != SRS_CONSTS_HTTP_DEFAULT_PORT) {
ep += ":" + srs_strconv_format_int(port); ep += ":" + srs_strconv_format_int(port_);
} }
// Set default value for headers. // Set default value for headers.
headers["Host"] = ep; headers_["Host"] = ep;
headers["Connection"] = "Keep-Alive"; headers_["Connection"] = "Keep-Alive";
headers["User-Agent"] = RTMP_SIG_SRS_SERVER; headers_["User-Agent"] = RTMP_SIG_SRS_SERVER;
headers["Content-Type"] = "application/json"; headers_["Content-Type"] = "application/json";
return err; return err;
} }
SrsHttpClient *SrsHttpClient::set_header(string k, string v) SrsHttpClient *SrsHttpClient::set_header(string k, string v)
{ {
headers[k] = v; headers_[k] = v;
return this; return this;
} }
@ -332,7 +332,7 @@ srs_error_t SrsHttpClient::post(string path, string req, ISrsHttpMessage **ppmsg
srs_error_t err = srs_success; srs_error_t err = srs_success;
// always set the content length. // always set the content length.
headers["Content-Length"] = srs_strconv_format_int(req.length()); headers_["Content-Length"] = srs_strconv_format_int(req.length());
if ((err = connect()) != srs_success) { if ((err = connect()) != srs_success) {
return srs_error_wrap(err, "http: connect server"); return srs_error_wrap(err, "http: connect server");
@ -342,12 +342,12 @@ srs_error_t SrsHttpClient::post(string path, string req, ISrsHttpMessage **ppmsg
path = "/"; path = "/";
} }
// TODO: FIXME: Use SrsHttpMessageWriter, never use stringstream and headers. // TODO: FIXME: Use SrsHttpMessageWriter, never use stringstream and headers_.
// send POST request to uri // send POST request to uri
// POST %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s // POST %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s
std::stringstream ss; std::stringstream ss;
ss << "POST " << path << " " << "HTTP/1.1" << SRS_HTTP_CRLF; ss << "POST " << path << " " << "HTTP/1.1" << SRS_HTTP_CRLF;
for (map<string, string>::iterator it = headers.begin(); it != headers.end(); ++it) { for (map<string, string>::iterator it = headers_.begin(); it != headers_.end(); ++it) {
string key = it->first; string key = it->first;
string value = it->second; string value = it->second;
ss << key << ": " << value << SRS_HTTP_CRLF; ss << key << ": " << value << SRS_HTTP_CRLF;
@ -362,7 +362,7 @@ srs_error_t SrsHttpClient::post(string path, string req, ISrsHttpMessage **ppmsg
} }
ISrsHttpMessage *msg = NULL; ISrsHttpMessage *msg = NULL;
if ((err = parser->parse_message(reader(), &msg)) != srs_success) { if ((err = parser_->parse_message(reader(), &msg)) != srs_success) {
return srs_error_wrap(err, "http: parse response"); return srs_error_wrap(err, "http: parse response");
} }
srs_assert(msg); srs_assert(msg);
@ -383,7 +383,7 @@ srs_error_t SrsHttpClient::get(string path, string req, ISrsHttpMessage **ppmsg)
srs_error_t err = srs_success; srs_error_t err = srs_success;
// always set the content length. // always set the content length.
headers["Content-Length"] = srs_strconv_format_int(req.length()); headers_["Content-Length"] = srs_strconv_format_int(req.length());
if ((err = connect()) != srs_success) { if ((err = connect()) != srs_success) {
return srs_error_wrap(err, "http: connect server"); return srs_error_wrap(err, "http: connect server");
@ -393,7 +393,7 @@ srs_error_t SrsHttpClient::get(string path, string req, ISrsHttpMessage **ppmsg)
// GET %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s // GET %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s
std::stringstream ss; std::stringstream ss;
ss << "GET " << path << " " << "HTTP/1.1" << SRS_HTTP_CRLF; ss << "GET " << path << " " << "HTTP/1.1" << SRS_HTTP_CRLF;
for (map<string, string>::iterator it = headers.begin(); it != headers.end(); ++it) { for (map<string, string>::iterator it = headers_.begin(); it != headers_.end(); ++it) {
string key = it->first; string key = it->first;
string value = it->second; string value = it->second;
ss << key << ": " << value << SRS_HTTP_CRLF; ss << key << ": " << value << SRS_HTTP_CRLF;
@ -408,7 +408,7 @@ srs_error_t SrsHttpClient::get(string path, string req, ISrsHttpMessage **ppmsg)
} }
ISrsHttpMessage *msg = NULL; ISrsHttpMessage *msg = NULL;
if ((err = parser->parse_message(reader(), &msg)) != srs_success) { if ((err = parser_->parse_message(reader(), &msg)) != srs_success) {
return srs_error_wrap(err, "http: parse response"); return srs_error_wrap(err, "http: parse response");
} }
srs_assert(msg); srs_assert(msg);
@ -424,28 +424,28 @@ srs_error_t SrsHttpClient::get(string path, string req, ISrsHttpMessage **ppmsg)
void SrsHttpClient::set_recv_timeout(srs_utime_t tm) void SrsHttpClient::set_recv_timeout(srs_utime_t tm)
{ {
recv_timeout = tm; recv_timeout_ = tm;
} }
void SrsHttpClient::kbps_sample(const char *label, srs_utime_t age) void SrsHttpClient::kbps_sample(const char *label, srs_utime_t age)
{ {
kbps->sample(); kbps_->sample();
int sr = kbps->get_send_kbps(); int sr = kbps_->get_send_kbps();
int sr30s = kbps->get_send_kbps_30s(); int sr30s = kbps_->get_send_kbps_30s();
int sr5m = kbps->get_send_kbps_5m(); int sr5m = kbps_->get_send_kbps_5m();
int rr = kbps->get_recv_kbps(); int rr = kbps_->get_recv_kbps();
int rr30s = kbps->get_recv_kbps_30s(); int rr30s = kbps_->get_recv_kbps_30s();
int rr5m = kbps->get_recv_kbps_5m(); int rr5m = kbps_->get_recv_kbps_5m();
srs_trace("<- %s time=%" PRId64 ", okbps=%d,%d,%d, ikbps=%d,%d,%d", label, srsu2ms(age), sr, sr30s, sr5m, rr, rr30s, rr5m); srs_trace("<- %s time=%" PRId64 ", okbps=%d,%d,%d, ikbps=%d,%d,%d", label, srsu2ms(age), sr, sr30s, sr5m, rr, rr30s, rr5m);
} }
void SrsHttpClient::disconnect() void SrsHttpClient::disconnect()
{ {
kbps->set_io(NULL, NULL); kbps_->set_io(NULL, NULL);
srs_freep(ssl_transport); srs_freep(ssl_transport_);
srs_freep(transport); srs_freep(transport_);
} }
srs_error_t SrsHttpClient::connect() srs_error_t SrsHttpClient::connect()
@ -453,22 +453,22 @@ srs_error_t SrsHttpClient::connect()
srs_error_t err = srs_success; srs_error_t err = srs_success;
// When transport connected, ignore. // When transport connected, ignore.
if (transport) { if (transport_) {
return err; return err;
} }
transport = new SrsTcpClient(host, port, timeout); transport_ = new SrsTcpClient(host_, port_, timeout_);
if ((err = transport->connect()) != srs_success) { if ((err = transport_->connect()) != srs_success) {
disconnect(); disconnect();
return srs_error_wrap(err, "http: tcp connect %s %s:%d to=%dms, rto=%dms", return srs_error_wrap(err, "http: tcp connect %s %s:%d to=%dms, rto=%dms",
schema_.c_str(), host.c_str(), port, srsu2msi(timeout), srsu2msi(recv_timeout)); schema_.c_str(), host_.c_str(), port_, srsu2msi(timeout_), srsu2msi(recv_timeout_));
} }
// Set the recv/send timeout in srs_utime_t. // Set the recv/send timeout in srs_utime_t.
transport->set_recv_timeout(recv_timeout); transport_->set_recv_timeout(recv_timeout_);
transport->set_send_timeout(timeout); transport_->set_send_timeout(timeout_);
kbps->set_io(transport, transport); kbps_->set_io(transport_, transport_);
if (schema_ != "https") { if (schema_ != "https") {
return err; return err;
@ -477,19 +477,19 @@ srs_error_t SrsHttpClient::connect()
#if !defined(SRS_HTTPS) #if !defined(SRS_HTTPS)
return srs_error_new(ERROR_HTTPS_NOT_SUPPORTED, "should configure with --https=on"); return srs_error_new(ERROR_HTTPS_NOT_SUPPORTED, "should configure with --https=on");
#else #else
srs_assert(!ssl_transport); srs_assert(!ssl_transport_);
ssl_transport = new SrsSslClient(transport); ssl_transport_ = new SrsSslClient(transport_);
srs_utime_t starttime = srs_time_now_realtime(); srs_utime_t starttime = srs_time_now_realtime();
if ((err = ssl_transport->handshake(host)) != srs_success) { if ((err = ssl_transport_->handshake(host_)) != srs_success) {
disconnect(); disconnect();
return srs_error_wrap(err, "http: ssl connect %s %s:%d to=%dms, rto=%dms", return srs_error_wrap(err, "http: ssl connect %s %s:%d to=%dms, rto=%dms",
schema_.c_str(), host.c_str(), port, srsu2msi(timeout), srsu2msi(recv_timeout)); schema_.c_str(), host_.c_str(), port_, srsu2msi(timeout_), srsu2msi(recv_timeout_));
} }
int cost = srsu2msi(srs_time_now_realtime() - starttime); int cost = srsu2msi(srs_time_now_realtime() - starttime);
srs_trace("https: connected to %s://%s:%d, cost=%dms", schema_.c_str(), host.c_str(), port, cost); srs_trace("https: connected to %s://%s:%d, cost=%dms", schema_.c_str(), host_.c_str(), port_, cost);
return err; return err;
#endif #endif
@ -497,16 +497,16 @@ srs_error_t SrsHttpClient::connect()
ISrsStreamWriter *SrsHttpClient::writer() ISrsStreamWriter *SrsHttpClient::writer()
{ {
if (ssl_transport) { if (ssl_transport_) {
return ssl_transport; return ssl_transport_;
} }
return transport; return transport_;
} }
ISrsReader *SrsHttpClient::reader() ISrsReader *SrsHttpClient::reader()
{ {
if (ssl_transport) { if (ssl_transport_) {
return ssl_transport; return ssl_transport_;
} }
return transport; return transport_;
} }

View File

@ -33,13 +33,13 @@ class SrsTcpClient;
class SrsSslClient : public ISrsReader, public ISrsStreamWriter class SrsSslClient : public ISrsReader, public ISrsStreamWriter
{ {
private: private:
SrsTcpClient *transport; SrsTcpClient *transport_;
private: private:
SSL_CTX *ssl_ctx; SSL_CTX *ssl_ctx_;
SSL *ssl; SSL *ssl_;
BIO *bio_in; BIO *bio_in_;
BIO *bio_out; BIO *bio_out_;
public: public:
SrsSslClient(SrsTcpClient *tcp); SrsSslClient(SrsTcpClient *tcp);
@ -65,22 +65,22 @@ class SrsHttpClient
private: private:
// The underlayer TCP transport, set to NULL when disconnect, or never not NULL when connected. // The underlayer TCP transport, set to NULL when disconnect, or never not NULL when connected.
// We will disconnect transport when initialize or channel error, such as send/recv error. // We will disconnect transport when initialize or channel error, such as send/recv error.
SrsTcpClient *transport; SrsTcpClient *transport_;
SrsHttpParser *parser; SrsHttpParser *parser_;
std::map<std::string, std::string> headers; std::map<std::string, std::string> headers_;
SrsNetworkKbps *kbps; SrsNetworkKbps *kbps_;
private: private:
// The timeout in srs_utime_t. // The timeout in srs_utime_t.
srs_utime_t timeout; srs_utime_t timeout_;
srs_utime_t recv_timeout; srs_utime_t recv_timeout_;
// The schema, host name or ip. // The schema, host name or ip.
std::string schema_; std::string schema_;
std::string host; std::string host_;
int port; int port_;
private: private:
SrsSslClient *ssl_transport; SrsSslClient *ssl_transport_;
public: public:
SrsHttpClient(); SrsHttpClient();

View File

@ -22,8 +22,8 @@ using namespace std;
SrsHttpParser::SrsHttpParser() SrsHttpParser::SrsHttpParser()
{ {
buffer = new SrsFastStream(); buffer_ = new SrsFastStream();
header = NULL; header_ = NULL;
type_ = HTTP_REQUEST; type_ = HTTP_REQUEST;
parsed_type_ = HTTP_BOTH; parsed_type_ = HTTP_BOTH;
@ -31,37 +31,37 @@ SrsHttpParser::SrsHttpParser()
SrsHttpParser::~SrsHttpParser() SrsHttpParser::~SrsHttpParser()
{ {
srs_freep(buffer); srs_freep(buffer_);
srs_freep(header); srs_freep(header_);
} }
srs_error_t SrsHttpParser::initialize(enum llhttp_type type) srs_error_t SrsHttpParser::initialize(enum llhttp_type type)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
jsonp = false; jsonp_ = false;
type_ = type; type_ = type;
// Initialize the settings first // Initialize the settings first
llhttp_settings_init(&settings); llhttp_settings_init(&settings_);
settings.on_message_begin = on_message_begin; settings_.on_message_begin = on_message_begin;
settings.on_url = on_url; settings_.on_url = on_url;
settings.on_header_field = on_header_field; settings_.on_header_field = on_header_field;
settings.on_header_value = on_header_value; settings_.on_header_value = on_header_value;
settings.on_headers_complete = on_headers_complete; settings_.on_headers_complete = on_headers_complete;
settings.on_body = on_body; settings_.on_body = on_body;
settings.on_message_complete = on_message_complete; settings_.on_message_complete = on_message_complete;
// Initialize the parser with settings // Initialize the parser with settings
llhttp_init(&parser, type_, &settings); llhttp_init(&parser_, type_, &settings_);
parser.data = (void *)this; parser_.data = (void *)this;
return err; return err;
} }
void SrsHttpParser::set_jsonp(bool allow_jsonp) void SrsHttpParser::set_jsonp(bool allow_jsonp)
{ {
jsonp = allow_jsonp; jsonp_ = allow_jsonp;
} }
srs_error_t SrsHttpParser::parse_message(ISrsReader *reader, ISrsHttpMessage **ppmsg) srs_error_t SrsHttpParser::parse_message(ISrsReader *reader, ISrsHttpMessage **ppmsg)
@ -71,15 +71,15 @@ srs_error_t SrsHttpParser::parse_message(ISrsReader *reader, ISrsHttpMessage **p
*ppmsg = NULL; *ppmsg = NULL;
// Reset parser data and state. // Reset parser data and state.
state = SrsHttpParseStateInit; state_ = SrsHttpParseStateInit;
memset(&hp_header, 0, sizeof(llhttp_t)); memset(&hp_header_, 0, sizeof(llhttp_t));
// We must reset the field name and value, because we may get a partial value in on_header_value. // We must reset the field name and value, because we may get a partial value in on_header_value.
field_name = field_value = ""; field_name_ = field_value_ = "";
// Reset the url. // Reset the url.
url = ""; url_ = "";
// The header of the request. // The header of the request.
srs_freep(header); srs_freep(header_);
header = new SrsHttpHeader(); header_ = new SrsHttpHeader();
// Reset parser for each message. // Reset parser for each message.
// If the request is large, such as the fifth message at @utest ProtocolHTTPTest.ParsingLargeMessages, // If the request is large, such as the fifth message at @utest ProtocolHTTPTest.ParsingLargeMessages,
@ -90,14 +90,14 @@ srs_error_t SrsHttpParser::parse_message(ISrsReader *reader, ISrsHttpMessage **p
// when got next message, the whole next message is parsed as the body of previous one, // when got next message, the whole next message is parsed as the body of previous one,
// and the message fail. // and the message fail.
// @note You can comment the bellow line, the utest will fail. // @note You can comment the bellow line, the utest will fail.
llhttp_reset(&parser); llhttp_reset(&parser_);
// Reset the parsed type. // Reset the parsed type.
parsed_type_ = HTTP_BOTH; parsed_type_ = HTTP_BOTH;
// callback object ptr. // callback object ptr.
parser.data = (void *)this; parser_.data = (void *)this;
// Always skip body, because we only want to parse the header. // Always skip body, because we only want to parse the header.
parser.flags |= F_SKIPBODY; parser_.flags |= F_SKIPBODY;
// do parse // do parse
if ((err = parse_message_imp(reader)) != srs_success) { if ((err = parse_message_imp(reader)) != srs_success) {
@ -105,15 +105,15 @@ srs_error_t SrsHttpParser::parse_message(ISrsReader *reader, ISrsHttpMessage **p
} }
// create msg // create msg
SrsHttpMessage *msg = new SrsHttpMessage(reader, buffer); SrsHttpMessage *msg = new SrsHttpMessage(reader, buffer_);
// Initialize the basic information. // Initialize the basic information.
msg->set_basic(hp_header.type, (llhttp_method_t)hp_header.method, (llhttp_status_t)hp_header.status_code, hp_header.content_length); msg->set_basic(hp_header_.type, (llhttp_method_t)hp_header_.method, (llhttp_status_t)hp_header_.status_code, hp_header_.content_length);
msg->set_header(header, llhttp_should_keep_alive(&hp_header)); msg->set_header(header_, llhttp_should_keep_alive(&hp_header_));
// For HTTP response, no url. // For HTTP response, no url.
if (parsed_type_ != HTTP_RESPONSE && (err = msg->set_url(url, jsonp)) != srs_success) { if (parsed_type_ != HTTP_RESPONSE && (err = msg->set_url(url_, jsonp_)) != srs_success) {
srs_freep(msg); srs_freep(msg);
return srs_error_wrap(err, "set url=%s, jsonp=%d", url.c_str(), jsonp); return srs_error_wrap(err, "set url=%s, jsonp=%d", url_.c_str(), jsonp_);
} }
// parse ok, return the msg. // parse ok, return the msg.
@ -127,17 +127,17 @@ srs_error_t SrsHttpParser::parse_message_imp(ISrsReader *reader)
srs_error_t err = srs_success; srs_error_t err = srs_success;
while (true) { while (true) {
if (buffer->size() > 0) { if (buffer_->size() > 0) {
const char *data_start = buffer->bytes(); const char *data_start = buffer_->bytes();
llhttp_errno_t code = llhttp_execute(&parser, data_start, buffer->size()); llhttp_errno_t code = llhttp_execute(&parser_, data_start, buffer_->size());
ssize_t consumed = 0; ssize_t consumed = 0;
if (code == HPE_OK) { if (code == HPE_OK) {
// No problem, all buffer should be consumed. // No problem, all buffer should be consumed.
consumed = buffer->size(); consumed = buffer_->size();
} else if (code == HPE_PAUSED) { } else if (code == HPE_PAUSED) {
// We only consume the header, not message or body. // We only consume the header, not message or body.
const char *error_pos = llhttp_get_error_pos(&parser); const char *error_pos = llhttp_get_error_pos(&parser_);
if (error_pos && error_pos < data_start) { if (error_pos && error_pos < data_start) {
return srs_error_new(ERROR_HTTP_PARSE_HEADER, "llhttp error_pos=%p < data_start=%p", error_pos, data_start); return srs_error_new(ERROR_HTTP_PARSE_HEADER, "llhttp error_pos=%p < data_start=%p", error_pos, data_start);
} }
@ -152,33 +152,33 @@ srs_error_t SrsHttpParser::parse_message_imp(ISrsReader *reader)
// HPE_PAUSED: we use to skip body // HPE_PAUSED: we use to skip body
if (code != HPE_OK && code != HPE_PAUSED) { if (code != HPE_OK && code != HPE_PAUSED) {
return srs_error_new(ERROR_HTTP_PARSE_HEADER, "parse %dB, nparsed=%d, err=%d/%s %s", return srs_error_new(ERROR_HTTP_PARSE_HEADER, "parse %dB, nparsed=%d, err=%d/%s %s",
buffer->size(), (int)consumed, code, llhttp_errno_name(code), buffer_->size(), (int)consumed, code, llhttp_errno_name(code),
llhttp_get_error_reason(&parser) ? llhttp_get_error_reason(&parser) : ""); llhttp_get_error_reason(&parser_) ? llhttp_get_error_reason(&parser_) : "");
} }
srs_info("size=%d, nparsed=%d", buffer->size(), (int)consumed); srs_info("size=%d, nparsed=%d", buffer_->size(), (int)consumed);
// Only consume the header bytes. // Only consume the header bytes.
if (consumed > 0) { if (consumed > 0) {
buffer->read_slice(consumed); buffer_->read_slice(consumed);
} }
// Done when header completed, never wait for body completed, because it maybe chunked. // Done when header completed, never wait for body completed, because it maybe chunked.
if (state >= SrsHttpParseStateHeaderComplete) { if (state_ >= SrsHttpParseStateHeaderComplete) {
break; break;
} }
} }
// when nothing parsed, read more to parse. // when nothing parsed, read more to parse.
// when requires more, only grow 1bytes, but the buffer will cache more. // when requires more, only grow 1bytes, but the buffer will cache more.
if ((err = buffer->grow(reader, buffer->size() + 1)) != srs_success) { if ((err = buffer_->grow(reader, buffer_->size() + 1)) != srs_success) {
return srs_error_wrap(err, "grow buffer"); return srs_error_wrap(err, "grow buffer");
} }
} }
SrsHttpParser *obj = this; SrsHttpParser *obj = this;
if (!obj->field_value.empty()) { if (!obj->field_value_.empty()) {
obj->header->set(obj->field_name, obj->field_value); obj->header_->set(obj->field_name_, obj->field_value_);
} }
return err; return err;
@ -190,7 +190,7 @@ int SrsHttpParser::on_message_begin(llhttp_t *parser)
srs_assert(obj); srs_assert(obj);
// Now, we start to parse HTTP message. // Now, we start to parse HTTP message.
obj->state = SrsHttpParseStateStart; obj->state_ = SrsHttpParseStateStart;
// If we set to HTTP_BOTH, the type is detected and speicifed by parser. // If we set to HTTP_BOTH, the type is detected and speicifed by parser.
obj->parsed_type_ = (llhttp_type)parser->type; obj->parsed_type_ = (llhttp_type)parser->type;
@ -205,9 +205,9 @@ int SrsHttpParser::on_headers_complete(llhttp_t *parser)
SrsHttpParser *obj = (SrsHttpParser *)parser->data; SrsHttpParser *obj = (SrsHttpParser *)parser->data;
srs_assert(obj); srs_assert(obj);
obj->hp_header = *parser; obj->hp_header_ = *parser;
// save the parser when header parse completed. // save the parser when header parse completed.
obj->state = SrsHttpParseStateHeaderComplete; obj->state_ = SrsHttpParseStateHeaderComplete;
srs_info("***HEADERS COMPLETE***"); srs_info("***HEADERS COMPLETE***");
@ -227,7 +227,7 @@ int SrsHttpParser::on_message_complete(llhttp_t *parser)
srs_assert(obj); srs_assert(obj);
// Note that we should never get here, because we always return HPE_PAUSED in on_headers_complete. // Note that we should never get here, because we always return HPE_PAUSED in on_headers_complete.
obj->state = SrsHttpParseStateMessageComplete; obj->state_ = SrsHttpParseStateMessageComplete;
srs_info("***MESSAGE COMPLETE***\n"); srs_info("***MESSAGE COMPLETE***\n");
@ -241,7 +241,7 @@ int SrsHttpParser::on_url(llhttp_t *parser, const char *at, size_t length)
if (length > 0) { if (length > 0) {
// Note that this function might be called for multiple times, and we got pieces of content. // Note that this function might be called for multiple times, and we got pieces of content.
obj->url.append(at, (int)length); obj->url_.append(at, (int)length);
} }
srs_info("Method: %d, Url: %.*s", parser->method, (int)length, at); srs_info("Method: %d, Url: %.*s", parser->method, (int)length, at);
@ -254,13 +254,13 @@ int SrsHttpParser::on_header_field(llhttp_t *parser, const char *at, size_t leng
SrsHttpParser *obj = (SrsHttpParser *)parser->data; SrsHttpParser *obj = (SrsHttpParser *)parser->data;
srs_assert(obj); srs_assert(obj);
if (!obj->field_value.empty()) { if (!obj->field_value_.empty()) {
obj->header->set(obj->field_name, obj->field_value); obj->header_->set(obj->field_name_, obj->field_value_);
obj->field_name = obj->field_value = ""; obj->field_name_ = obj->field_value_ = "";
} }
if (length > 0) { if (length > 0) {
obj->field_name.append(at, (int)length); obj->field_name_.append(at, (int)length);
} }
srs_info("Header field(%d bytes): %.*s", (int)length, (int)length, at); srs_info("Header field(%d bytes): %.*s", (int)length, (int)length, at);
@ -273,7 +273,7 @@ int SrsHttpParser::on_header_value(llhttp_t *parser, const char *at, size_t leng
srs_assert(obj); srs_assert(obj);
if (length > 0) { if (length > 0) {
obj->field_value.append(at, (int)length); obj->field_value_.append(at, (int)length);
} }
srs_info("Header value(%d bytes): %.*s", (int)length, (int)length, at); srs_info("Header value(%d bytes): %.*s", (int)length, (int)length, at);
@ -286,7 +286,7 @@ int SrsHttpParser::on_body(llhttp_t *parser, const char *at, size_t length)
srs_assert(obj); srs_assert(obj);
// save the parser when body parsed. // save the parser when body parsed.
obj->state = SrsHttpParseStateBody; obj->state_ = SrsHttpParseStateBody;
srs_info("Body: %.*s", (int)length, at); srs_info("Body: %.*s", (int)length, at);
@ -295,12 +295,12 @@ int SrsHttpParser::on_body(llhttp_t *parser, const char *at, size_t length)
SrsHttpMessage::SrsHttpMessage(ISrsReader *reader, SrsFastStream *buffer) : ISrsHttpMessage() SrsHttpMessage::SrsHttpMessage(ISrsReader *reader, SrsFastStream *buffer) : ISrsHttpMessage()
{ {
owner_conn = NULL; owner_conn_ = NULL;
chunked = false; chunked_ = false;
_uri = new SrsHttpUri(); _uri = new SrsHttpUri();
_body = new SrsHttpResponseReader(this, reader, buffer); _body = new SrsHttpResponseReader(this, reader, buffer);
jsonp = false; jsonp_ = false;
// As 0 is DELETE, so we use GET as default. // As 0 is DELETE, so we use GET as default.
_method = (llhttp_method_t)SRS_CONSTS_HTTP_GET; _method = (llhttp_method_t)SRS_CONSTS_HTTP_GET;
@ -340,7 +340,7 @@ void SrsHttpMessage::set_header(SrsHttpHeader *header, bool keep_alive)
_keep_alive = keep_alive; _keep_alive = keep_alive;
// whether chunked. // whether chunked.
chunked = (header->get("Transfer-Encoding") == "chunked"); chunked_ = (header->get("Transfer-Encoding") == "chunked");
// Update the content-length in header. // Update the content-length in header.
string clv = header->get("Content-Length"); string clv = header->get("Content-Length");
@ -350,7 +350,7 @@ void SrsHttpMessage::set_header(SrsHttpHeader *header, bool keep_alive)
// If no size(content-length or chunked), it's infinite chunked, // If no size(content-length or chunked), it's infinite chunked,
// it means there is no body, so we must close the body reader. // it means there is no body, so we must close the body reader.
if (!chunked && _content_length == -1) { if (!chunked_ && _content_length == -1) {
// The infinite chunked is only enabled for HTTP_RESPONSE, so we close the body for request. // The infinite chunked is only enabled for HTTP_RESPONSE, so we close the body for request.
if (type_ == HTTP_REQUEST) { if (type_ == HTTP_REQUEST) {
_body->close(); _body->close();
@ -414,10 +414,10 @@ srs_error_t SrsHttpMessage::set_url(string url, bool allow_jsonp)
// parse jsonp request message. // parse jsonp request message.
if (allow_jsonp) { if (allow_jsonp) {
string callback = query_get("callback"); string callback = query_get("callback");
jsonp = !callback.empty(); jsonp_ = !callback.empty();
if (jsonp) { if (jsonp_) {
jsonp_method = query_get("method"); jsonp_method_ = query_get("method");
} }
if (!srs_is_valid_jsonp_callback(callback)) { if (!srs_is_valid_jsonp_callback(callback)) {
@ -436,12 +436,12 @@ void SrsHttpMessage::set_https(bool v)
ISrsConnection *SrsHttpMessage::connection() ISrsConnection *SrsHttpMessage::connection()
{ {
return owner_conn; return owner_conn_;
} }
void SrsHttpMessage::set_connection(ISrsConnection *conn) void SrsHttpMessage::set_connection(ISrsConnection *conn)
{ {
owner_conn = conn; owner_conn_ = conn;
} }
string SrsHttpMessage::schema() string SrsHttpMessage::schema()
@ -456,14 +456,14 @@ uint8_t SrsHttpMessage::message_type()
uint8_t SrsHttpMessage::method() uint8_t SrsHttpMessage::method()
{ {
if (jsonp && !jsonp_method.empty()) { if (jsonp_ && !jsonp_method_.empty()) {
if (jsonp_method == "GET") { if (jsonp_method_ == "GET") {
return SRS_CONSTS_HTTP_GET; return SRS_CONSTS_HTTP_GET;
} else if (jsonp_method == "PUT") { } else if (jsonp_method_ == "PUT") {
return SRS_CONSTS_HTTP_PUT; return SRS_CONSTS_HTTP_PUT;
} else if (jsonp_method == "POST") { } else if (jsonp_method_ == "POST") {
return SRS_CONSTS_HTTP_POST; return SRS_CONSTS_HTTP_POST;
} else if (jsonp_method == "DELETE") { } else if (jsonp_method_ == "DELETE") {
return SRS_CONSTS_HTTP_DELETE; return SRS_CONSTS_HTTP_DELETE;
} }
} }
@ -478,8 +478,8 @@ uint16_t SrsHttpMessage::status_code()
string SrsHttpMessage::method_str() string SrsHttpMessage::method_str()
{ {
if (jsonp && !jsonp_method.empty()) { if (jsonp_ && !jsonp_method_.empty()) {
return jsonp_method; return jsonp_method_;
} }
return llhttp_method_name((llhttp_method_t)_method); return llhttp_method_name((llhttp_method_t)_method);
@ -512,7 +512,7 @@ bool SrsHttpMessage::is_http_options()
bool SrsHttpMessage::is_chunked() bool SrsHttpMessage::is_chunked()
{ {
return chunked; return chunked_;
} }
bool SrsHttpMessage::is_keep_alive() bool SrsHttpMessage::is_keep_alive()
@ -627,52 +627,52 @@ ISrsRequest *SrsHttpMessage::to_request(string vhost)
// http path, for instance, /live/livestream.flv, parse to // http path, for instance, /live/livestream.flv, parse to
// app: /live // app: /live
// stream: livestream.flv // stream: livestream.flv
srs_net_url_parse_rtmp_url(_uri->get_path(), req->app, req->stream); srs_net_url_parse_rtmp_url(_uri->get_path(), req->app_, req->stream_);
// trim the start slash, for instance, /live to live // trim the start slash, for instance, /live to live
req->app = srs_strings_trim_start(req->app, "/"); req->app_ = srs_strings_trim_start(req->app_, "/");
// remove the extension, for instance, livestream.flv to livestream // remove the extension, for instance, livestream.flv to livestream
req->stream = srs_path_filepath_filename(req->stream); req->stream_ = srs_path_filepath_filename(req->stream_);
// generate others. // generate others.
req->tcUrl = "rtmp://" + vhost + "/" + req->app; req->tcUrl_ = "rtmp://" + vhost + "/" + req->app_;
req->pageUrl = _header.get("Referer"); req->pageUrl_ = _header.get("Referer");
req->objectEncoding = 0; req->objectEncoding_ = 0;
std::string query = _uri->get_query(); std::string query = _uri->get_query();
if (!query.empty()) { if (!query.empty()) {
req->param = "?" + query; req->param_ = "?" + query;
} }
srs_net_url_parse_tcurl(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param); srs_net_url_parse_tcurl(req->tcUrl_, req->schema_, req->host_, req->vhost_, req->app_, req->stream_, req->port_, req->param_);
req->strip(); req->strip();
// reset the host to http request host. // reset the host to http request host.
if (req->host == SRS_CONSTS_RTMP_DEFAULT_VHOST) { if (req->host_ == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
req->host = _uri->get_host(); req->host_ = _uri->get_host();
} }
// Set ip by remote ip of connection. // Set ip by remote ip of connection.
if (owner_conn) { if (owner_conn_) {
req->ip = owner_conn->remote_ip(); req->ip_ = owner_conn_->remote_ip();
} }
// Overwrite by ip from proxy. // Overwrite by ip from proxy.
string oip = srs_get_original_ip(this); string oip = srs_get_original_ip(this);
if (!oip.empty()) { if (!oip.empty()) {
req->ip = oip; req->ip_ = oip;
} }
// The request streaming protocol. // The request streaming protocol.
req->protocol = (schema_ == "http") ? "flv" : "flvs"; req->protocol_ = (schema_ == "http") ? "flv" : "flvs";
return req; return req;
} }
bool SrsHttpMessage::is_jsonp() bool SrsHttpMessage::is_jsonp()
{ {
return jsonp; return jsonp_;
} }
ISrsHttpHeaderFilter::ISrsHttpHeaderFilter() ISrsHttpHeaderFilter::ISrsHttpHeaderFilter()
@ -693,22 +693,22 @@ ISrsHttpFirstLineWriter::~ISrsHttpFirstLineWriter()
SrsHttpMessageWriter::SrsHttpMessageWriter(ISrsProtocolReadWriter *io, ISrsHttpFirstLineWriter *flw) SrsHttpMessageWriter::SrsHttpMessageWriter(ISrsProtocolReadWriter *io, ISrsHttpFirstLineWriter *flw)
{ {
skt = io; skt_ = io;
hdr = new SrsHttpHeader(); hdr_ = new SrsHttpHeader();
header_wrote_ = false; header_wrote_ = false;
content_length = -1; content_length_ = -1;
written = 0; written_ = 0;
header_sent = false; header_sent_ = false;
nb_iovss_cache = 0; nb_iovss_cache_ = 0;
iovss_cache = NULL; iovss_cache_ = NULL;
hf_ = NULL; hf_ = NULL;
flw_ = flw; flw_ = flw;
} }
SrsHttpMessageWriter::~SrsHttpMessageWriter() SrsHttpMessageWriter::~SrsHttpMessageWriter()
{ {
srs_freep(hdr); srs_freep(hdr_);
srs_freepa(iovss_cache); srs_freepa(iovss_cache_);
} }
srs_error_t SrsHttpMessageWriter::final_request() srs_error_t SrsHttpMessageWriter::final_request()
@ -726,11 +726,11 @@ srs_error_t SrsHttpMessageWriter::final_request()
} }
// complete the chunked encoding. // complete the chunked encoding.
if (content_length == -1) { if (content_length_ == -1) {
std::stringstream ss; std::stringstream ss;
ss << 0 << SRS_HTTP_CRLF << SRS_HTTP_CRLF; ss << 0 << SRS_HTTP_CRLF << SRS_HTTP_CRLF;
std::string ch = ss.str(); std::string ch = ss.str();
return skt->write((void *)ch.data(), (int)ch.length(), NULL); return skt_->write((void *)ch.data(), (int)ch.length(), NULL);
} }
// flush when send with content length // flush when send with content length
@ -739,7 +739,7 @@ srs_error_t SrsHttpMessageWriter::final_request()
SrsHttpHeader *SrsHttpMessageWriter::header() SrsHttpHeader *SrsHttpMessageWriter::header()
{ {
return hdr; return hdr_;
} }
srs_error_t SrsHttpMessageWriter::write(char *data, int size) srs_error_t SrsHttpMessageWriter::write(char *data, int size)
@ -748,11 +748,11 @@ srs_error_t SrsHttpMessageWriter::write(char *data, int size)
// write the header data in memory. // write the header data in memory.
if (!header_wrote_) { if (!header_wrote_) {
if (hdr->content_type().empty()) { if (hdr_->content_type().empty()) {
hdr->set_content_type("text/plain; charset=utf-8"); hdr_->set_content_type("text/plain; charset=utf-8");
} }
if (hdr->content_length() == -1) { if (hdr_->content_length() == -1) {
hdr->set_content_length(size); hdr_->set_content_length(size);
} }
flw_->write_default_header(); flw_->write_default_header();
} }
@ -763,9 +763,9 @@ srs_error_t SrsHttpMessageWriter::write(char *data, int size)
} }
// check the bytes send and content length. // check the bytes send and content length.
written += size; written_ += size;
if (content_length != -1 && written > content_length) { if (content_length_ != -1 && written_ > content_length_) {
return srs_error_new(ERROR_HTTP_CONTENT_LENGTH, "overflow writen=%" PRId64 ", max=%" PRId64, written, content_length); return srs_error_new(ERROR_HTTP_CONTENT_LENGTH, "overflow writen=%" PRId64 ", max=%" PRId64, written_, content_length_);
} }
// ignore NULL content. // ignore NULL content.
@ -774,18 +774,18 @@ srs_error_t SrsHttpMessageWriter::write(char *data, int size)
} }
// directly send with content length // directly send with content length
if (content_length != -1) { if (content_length_ != -1) {
return skt->write((void *)data, size, NULL); return skt_->write((void *)data, size, NULL);
} }
// send in chunked encoding. // send in chunked encoding.
int nb_size = snprintf(header_cache, SRS_HTTP_HEADER_CACHE_SIZE, "%x", size); int nb_size = snprintf(header_cache_, SRS_HTTP_HEADER_CACHE_SIZE, "%x", size);
if (nb_size <= 0 || nb_size >= SRS_HTTP_HEADER_CACHE_SIZE) { if (nb_size <= 0 || nb_size >= SRS_HTTP_HEADER_CACHE_SIZE) {
return srs_error_new(ERROR_HTTP_CONTENT_LENGTH, "overflow size=%d, expect=%d", size, nb_size); return srs_error_new(ERROR_HTTP_CONTENT_LENGTH, "overflow size=%d, expect=%d", size, nb_size);
} }
iovec iovs[4]; iovec iovs[4];
iovs[0].iov_base = (char *)header_cache; iovs[0].iov_base = (char *)header_cache_;
iovs[0].iov_len = (int)nb_size; iovs[0].iov_len = (int)nb_size;
iovs[1].iov_base = (char *)SRS_HTTP_CRLF; iovs[1].iov_base = (char *)SRS_HTTP_CRLF;
iovs[1].iov_len = 2; iovs[1].iov_len = 2;
@ -795,7 +795,7 @@ srs_error_t SrsHttpMessageWriter::write(char *data, int size)
iovs[3].iov_len = 2; iovs[3].iov_len = 2;
ssize_t nwrite = 0; ssize_t nwrite = 0;
if ((err = skt->writev(iovs, 4, &nwrite)) != srs_success) { if ((err = skt_->writev(iovs, 4, &nwrite)) != srs_success) {
return srs_error_wrap(err, "write chunk"); return srs_error_wrap(err, "write chunk");
} }
@ -807,7 +807,7 @@ srs_error_t SrsHttpMessageWriter::writev(const iovec *iov, int iovcnt, ssize_t *
srs_error_t err = srs_success; srs_error_t err = srs_success;
// when header not ready, or not chunked, send one by one. // when header not ready, or not chunked, send one by one.
if (!header_wrote_ || content_length != -1) { if (!header_wrote_ || content_length_ != -1) {
ssize_t nwrite = 0; ssize_t nwrite = 0;
for (int i = 0; i < iovcnt; i++) { for (int i = 0; i < iovcnt; i++) {
nwrite += iov[i].iov_len; nwrite += iov[i].iov_len;
@ -835,11 +835,11 @@ srs_error_t SrsHttpMessageWriter::writev(const iovec *iov, int iovcnt, ssize_t *
// send in chunked encoding. // send in chunked encoding.
int nb_iovss = 3 + iovcnt; int nb_iovss = 3 + iovcnt;
iovec *iovss = iovss_cache; iovec *iovss = iovss_cache_;
if (nb_iovss_cache < nb_iovss) { if (nb_iovss_cache_ < nb_iovss) {
srs_freepa(iovss_cache); srs_freepa(iovss_cache_);
nb_iovss_cache = nb_iovss; nb_iovss_cache_ = nb_iovss;
iovss = iovss_cache = new iovec[nb_iovss]; iovss = iovss_cache_ = new iovec[nb_iovss];
} }
// Send all iovs in one chunk, the size is the total size of iovs. // Send all iovs in one chunk, the size is the total size of iovs.
@ -848,14 +848,14 @@ srs_error_t SrsHttpMessageWriter::writev(const iovec *iov, int iovcnt, ssize_t *
const iovec *data_iov = iov + i; const iovec *data_iov = iov + i;
size += data_iov->iov_len; size += data_iov->iov_len;
} }
written += size; written_ += size;
// chunk header // chunk header
int nb_size = snprintf(header_cache, SRS_HTTP_HEADER_CACHE_SIZE, "%x", size); int nb_size = snprintf(header_cache_, SRS_HTTP_HEADER_CACHE_SIZE, "%x", size);
if (nb_size <= 0 || nb_size >= SRS_HTTP_HEADER_CACHE_SIZE) { if (nb_size <= 0 || nb_size >= SRS_HTTP_HEADER_CACHE_SIZE) {
return srs_error_new(ERROR_HTTP_CONTENT_LENGTH, "overflow size=%d, expect=%d", size, nb_size); return srs_error_new(ERROR_HTTP_CONTENT_LENGTH, "overflow size=%d, expect=%d", size, nb_size);
} }
iovss[0].iov_base = (char *)header_cache; iovss[0].iov_base = (char *)header_cache_;
iovss[0].iov_len = (int)nb_size; iovss[0].iov_len = (int)nb_size;
// chunk header eof. // chunk header eof.
@ -874,7 +874,7 @@ srs_error_t SrsHttpMessageWriter::writev(const iovec *iov, int iovcnt, ssize_t *
// sendout all ioves. // sendout all ioves.
ssize_t nwrite = 0; ssize_t nwrite = 0;
if ((err = srs_write_large_iovs(skt, iovss, nb_iovss, &nwrite)) != srs_success) { if ((err = srs_write_large_iovs(skt_, iovss, nb_iovss, &nwrite)) != srs_success) {
return srs_error_wrap(err, "writev large iovs"); return srs_error_wrap(err, "writev large iovs");
} }
@ -892,17 +892,17 @@ void SrsHttpMessageWriter::write_header()
header_wrote_ = true; header_wrote_ = true;
// parse the content length from header. // parse the content length from header.
content_length = hdr->content_length(); content_length_ = hdr_->content_length();
} }
srs_error_t SrsHttpMessageWriter::send_header(char *data, int size) srs_error_t SrsHttpMessageWriter::send_header(char *data, int size)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (header_sent) { if (header_sent_) {
return err; return err;
} }
header_sent = true; header_sent_ = true;
std::stringstream ss; std::stringstream ss;
@ -912,33 +912,33 @@ srs_error_t SrsHttpMessageWriter::send_header(char *data, int size)
} }
// set server if not set. // set server if not set.
if (hdr->get("Server").empty()) { if (hdr_->get("Server").empty()) {
hdr->set("Server", RTMP_SIG_SRS_SERVER); hdr_->set("Server", RTMP_SIG_SRS_SERVER);
} }
// chunked encoding // chunked encoding
if (content_length == -1) { if (content_length_ == -1) {
hdr->set("Transfer-Encoding", "chunked"); hdr_->set("Transfer-Encoding", "chunked");
} }
// keep alive to make vlc happy. // keep alive to make vlc happy.
if (hdr->get("Connection").empty()) { if (hdr_->get("Connection").empty()) {
hdr->set("Connection", "Keep-Alive"); hdr_->set("Connection", "Keep-Alive");
} }
// Filter the header before writing it. // Filter the header before writing it.
if (hf_ && ((err = hf_->filter(hdr)) != srs_success)) { if (hf_ && ((err = hf_->filter(hdr_)) != srs_success)) {
return srs_error_wrap(err, "filter header"); return srs_error_wrap(err, "filter header");
} }
// write header // write header
hdr->write(ss); hdr_->write(ss);
// header_eof // header_eof
ss << SRS_HTTP_CRLF; ss << SRS_HTTP_CRLF;
std::string buf = ss.str(); std::string buf = ss.str();
return skt->write((void *)buf.c_str(), buf.length(), NULL); return skt_->write((void *)buf.c_str(), buf.length(), NULL);
} }
bool SrsHttpMessageWriter::header_wrote() bool SrsHttpMessageWriter::header_wrote()
@ -954,7 +954,7 @@ void SrsHttpMessageWriter::set_header_filter(ISrsHttpHeaderFilter *hf)
SrsHttpResponseWriter::SrsHttpResponseWriter(ISrsProtocolReadWriter *io) SrsHttpResponseWriter::SrsHttpResponseWriter(ISrsProtocolReadWriter *io)
{ {
writer_ = new SrsHttpMessageWriter(io, this); writer_ = new SrsHttpMessageWriter(io, this);
status = SRS_CONSTS_HTTP_OK; status_ = SRS_CONSTS_HTTP_OK;
} }
SrsHttpResponseWriter::~SrsHttpResponseWriter() SrsHttpResponseWriter::~SrsHttpResponseWriter()
@ -990,11 +990,11 @@ srs_error_t SrsHttpResponseWriter::writev(const iovec *iov, int iovcnt, ssize_t
void SrsHttpResponseWriter::write_header(int code) void SrsHttpResponseWriter::write_header(int code)
{ {
if (writer_->header_wrote()) { if (writer_->header_wrote()) {
srs_warn("http: multiple write_header calls, status=%d, code=%d", status, code); srs_warn("http: multiple write_header calls, status=%d, code=%d", status_, code);
return; return;
} }
status = code; status_ = code;
return writer_->write_header(); return writer_->write_header();
} }
@ -1003,11 +1003,11 @@ srs_error_t SrsHttpResponseWriter::build_first_line(std::stringstream &ss, char
srs_error_t err = srs_success; srs_error_t err = srs_success;
// Write status line for response. // Write status line for response.
ss << "HTTP/1.1 " << status << " " << srs_generate_http_status_text(status) << SRS_HTTP_CRLF; ss << "HTTP/1.1 " << status_ << " " << srs_generate_http_status_text(status_) << SRS_HTTP_CRLF;
// Try to detect content type from response body data. // Try to detect content type from response body data.
SrsHttpHeader *hdr = writer_->header(); SrsHttpHeader *hdr = writer_->header();
if (srs_go_http_body_allowd(status)) { if (srs_go_http_body_allowd(status_)) {
if (data && hdr->content_type().empty()) { if (data && hdr->content_type().empty()) {
hdr->set_content_type(srs_go_http_detect(data, size)); hdr->set_content_type(srs_go_http_detect(data, size));
} }
@ -1086,13 +1086,13 @@ void SrsHttpRequestWriter::write_default_header()
SrsHttpResponseReader::SrsHttpResponseReader(SrsHttpMessage *msg, ISrsReader *reader, SrsFastStream *body) SrsHttpResponseReader::SrsHttpResponseReader(SrsHttpMessage *msg, ISrsReader *reader, SrsFastStream *body)
{ {
skt = reader; skt_ = reader;
owner = msg; owner_ = msg;
is_eof = false; is_eof_ = false;
nb_total_read = 0; nb_total_read_ = 0;
nb_left_chunk = 0; nb_left_chunk_ = 0;
buffer = body; buffer_ = body;
nb_chunk = 0; nb_chunk_ = 0;
} }
SrsHttpResponseReader::~SrsHttpResponseReader() SrsHttpResponseReader::~SrsHttpResponseReader()
@ -1101,32 +1101,32 @@ SrsHttpResponseReader::~SrsHttpResponseReader()
void SrsHttpResponseReader::close() void SrsHttpResponseReader::close()
{ {
is_eof = true; is_eof_ = true;
} }
bool SrsHttpResponseReader::eof() bool SrsHttpResponseReader::eof()
{ {
return is_eof; return is_eof_;
} }
srs_error_t SrsHttpResponseReader::read(void *data, size_t nb_data, ssize_t *nb_read) srs_error_t SrsHttpResponseReader::read(void *data, size_t nb_data, ssize_t *nb_read)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (is_eof) { if (is_eof_) {
return srs_error_new(ERROR_HTTP_RESPONSE_EOF, "EOF"); return srs_error_new(ERROR_HTTP_RESPONSE_EOF, "EOF");
} }
// chunked encoding. // chunked encoding.
if (owner->is_chunked()) { if (owner_->is_chunked()) {
return read_chunked(data, nb_data, nb_read); return read_chunked(data, nb_data, nb_read);
} }
// read by specified content-length // read by specified content-length
if (owner->content_length() != -1) { if (owner_->content_length() != -1) {
size_t max = (size_t)owner->content_length() - (size_t)nb_total_read; size_t max = (size_t)owner_->content_length() - (size_t)nb_total_read_;
if (max <= 0) { if (max <= 0) {
is_eof = true; is_eof_ = true;
return err; return err;
} }
@ -1142,7 +1142,7 @@ srs_error_t SrsHttpResponseReader::read(void *data, size_t nb_data, ssize_t *nb_
// For infinite chunked, the socket close event is EOF. // For infinite chunked, the socket close event is EOF.
if (srs_error_code(err) == ERROR_SOCKET_READ) { if (srs_error_code(err) == ERROR_SOCKET_READ) {
srs_freep(err); srs_freep(err);
is_eof = true; is_eof_ = true;
return err; return err;
} }
} }
@ -1156,13 +1156,13 @@ srs_error_t SrsHttpResponseReader::read_chunked(void *data, size_t nb_data, ssiz
// when no bytes left in chunk, // when no bytes left in chunk,
// parse the chunk length first. // parse the chunk length first.
if (nb_left_chunk <= 0) { if (nb_left_chunk_ <= 0) {
char *at = NULL; char *at = NULL;
int length = 0; int length = 0;
while (!at) { while (!at) {
// find the CRLF of chunk header end. // find the CRLF of chunk header end.
char *start = buffer->bytes(); char *start = buffer_->bytes();
char *end = start + buffer->size(); char *end = start + buffer_->size();
for (char *p = start; p < end - 1; p++) { for (char *p = start; p < end - 1; p++) {
if (p[0] == SRS_HTTP_CR && p[1] == SRS_HTTP_LF) { if (p[0] == SRS_HTTP_CR && p[1] == SRS_HTTP_LF) {
@ -1171,7 +1171,7 @@ srs_error_t SrsHttpResponseReader::read_chunked(void *data, size_t nb_data, ssiz
return srs_error_new(ERROR_HTTP_INVALID_CHUNK_HEADER, "chunk header"); return srs_error_new(ERROR_HTTP_INVALID_CHUNK_HEADER, "chunk header");
} }
length = (int)(p - start + 2); length = (int)(p - start + 2);
at = buffer->read_slice(length); at = buffer_->read_slice(length);
break; break;
} }
} }
@ -1182,7 +1182,7 @@ srs_error_t SrsHttpResponseReader::read_chunked(void *data, size_t nb_data, ssiz
} }
// when empty, only grow 1bytes, but the buffer will cache more. // when empty, only grow 1bytes, but the buffer will cache more.
if ((err = buffer->grow(skt, buffer->size() + 1)) != srs_success) { if ((err = buffer_->grow(skt_, buffer_->size() + 1)) != srs_success) {
return srs_error_wrap(err, "grow buffer"); return srs_error_wrap(err, "grow buffer");
} }
} }
@ -1204,44 +1204,44 @@ srs_error_t SrsHttpResponseReader::read_chunked(void *data, size_t nb_data, ssiz
} }
// all bytes in chunk is left now. // all bytes in chunk is left now.
nb_chunk = nb_left_chunk = (size_t)ilength; nb_chunk_ = nb_left_chunk_ = (size_t)ilength;
} }
if (nb_chunk <= 0) { if (nb_chunk_ <= 0) {
// for the last chunk, eof. // for the last chunk, eof.
is_eof = true; is_eof_ = true;
if (nb_read) { if (nb_read) {
*nb_read = 0; *nb_read = 0;
} }
} else { } else {
// for not the last chunk, there must always exists bytes. // for not the last chunk, there must always exists bytes.
// left bytes in chunk, read some. // left bytes in chunk, read some.
srs_assert(nb_left_chunk); srs_assert(nb_left_chunk_);
size_t nb_bytes = srs_min(nb_left_chunk, nb_data); size_t nb_bytes = srs_min(nb_left_chunk_, nb_data);
err = read_specified(data, nb_bytes, (ssize_t *)&nb_bytes); err = read_specified(data, nb_bytes, (ssize_t *)&nb_bytes);
// the nb_bytes used for output already read size of bytes. // the nb_bytes used for output already read size of bytes.
if (nb_read) { if (nb_read) {
*nb_read = nb_bytes; *nb_read = nb_bytes;
} }
nb_left_chunk -= nb_bytes; nb_left_chunk_ -= nb_bytes;
if (err != srs_success) { if (err != srs_success) {
return srs_error_wrap(err, "read specified"); return srs_error_wrap(err, "read specified");
} }
// If still left bytes in chunk, ignore and read in future. // If still left bytes in chunk, ignore and read in future.
if (nb_left_chunk > 0) { if (nb_left_chunk_ > 0) {
return err; return err;
} }
} }
// for both the last or not, the CRLF of chunk payload end. // for both the last or not, the CRLF of chunk payload end.
if ((err = buffer->grow(skt, 2)) != srs_success) { if ((err = buffer_->grow(skt_, 2)) != srs_success) {
return srs_error_wrap(err, "grow buffer"); return srs_error_wrap(err, "grow buffer");
} }
buffer->read_slice(2); buffer_->read_slice(2);
return err; return err;
} }
@ -1250,31 +1250,31 @@ srs_error_t SrsHttpResponseReader::read_specified(void *data, size_t nb_data, ss
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (buffer->size() <= 0) { if (buffer_->size() <= 0) {
// when empty, only grow 1bytes, but the buffer will cache more. // when empty, only grow 1bytes, but the buffer will cache more.
if ((err = buffer->grow(skt, 1)) != srs_success) { if ((err = buffer_->grow(skt_, 1)) != srs_success) {
return srs_error_wrap(err, "grow buffer"); return srs_error_wrap(err, "grow buffer");
} }
} }
size_t nb_bytes = srs_min(nb_data, (size_t)buffer->size()); size_t nb_bytes = srs_min(nb_data, (size_t)buffer_->size());
// read data to buffer. // read data to buffer.
srs_assert(nb_bytes); srs_assert(nb_bytes);
char *p = buffer->read_slice(nb_bytes); char *p = buffer_->read_slice(nb_bytes);
memcpy(data, p, nb_bytes); memcpy(data, p, nb_bytes);
if (nb_read) { if (nb_read) {
*nb_read = nb_bytes; *nb_read = nb_bytes;
} }
// increase the total read to determine whether EOF. // increase the total read to determine whether EOF.
nb_total_read += nb_bytes; nb_total_read_ += nb_bytes;
// for not chunked and specified content length. // for not chunked and specified content length.
if (!owner->is_chunked() && owner->content_length() != -1) { if (!owner_->is_chunked() && owner_->content_length() != -1) {
// when read completed, eof. // when read completed, eof.
if (nb_total_read >= (int)owner->content_length()) { if (nb_total_read_ >= (int)owner_->content_length()) {
is_eof = true; is_eof_ = true;
} }
} }

View File

@ -26,20 +26,20 @@ class ISrsProtocolReadWriter;
class SrsHttpParser class SrsHttpParser
{ {
private: private:
llhttp_settings_t settings; llhttp_settings_t settings_;
llhttp_t parser; llhttp_t parser_;
// The global parse buffer. // The global parse buffer.
SrsFastStream *buffer; SrsFastStream *buffer_;
// Whether allow jsonp parse. // Whether allow jsonp parse.
bool jsonp; bool jsonp_;
private: private:
std::string field_name; std::string field_name_;
std::string field_value; std::string field_value_;
SrsHttpParseState state; SrsHttpParseState state_;
llhttp_t hp_header; llhttp_t hp_header_;
std::string url; std::string url_;
SrsHttpHeader *header; SrsHttpHeader *header_;
enum llhttp_type type_; enum llhttp_type type_;
enum llhttp_type parsed_type_; enum llhttp_type parsed_type_;
@ -88,7 +88,7 @@ private:
SrsHttpResponseReader *_body; SrsHttpResponseReader *_body;
// Use a buffer to read and send ts file. // Use a buffer to read and send ts file.
// The transport connection, can be NULL. // The transport connection, can be NULL.
ISrsConnection *owner_conn; ISrsConnection *owner_conn_;
private: private:
// The request type defined as // The request type defined as
@ -105,7 +105,7 @@ private:
// Whether the request indicates should keep alive for the http connection. // Whether the request indicates should keep alive for the http connection.
bool _keep_alive; bool _keep_alive;
// Whether the body is chunked. // Whether the body is chunked.
bool chunked; bool chunked_;
private: private:
std::string schema_; std::string schema_;
@ -120,9 +120,9 @@ private:
private: private:
// Whether request is jsonp. // Whether request is jsonp.
bool jsonp; bool jsonp_;
// The method in QueryString will override the HTTP method. // The method in QueryString will override the HTTP method.
std::string jsonp_method; std::string jsonp_method_;
public: public:
SrsHttpMessage(ISrsReader *reader = NULL, SrsFastStream *buffer = NULL); SrsHttpMessage(ISrsReader *reader = NULL, SrsFastStream *buffer = NULL);
@ -232,8 +232,8 @@ public:
class SrsHttpMessageWriter class SrsHttpMessageWriter
{ {
private: private:
ISrsProtocolReadWriter *skt; ISrsProtocolReadWriter *skt_;
SrsHttpHeader *hdr; SrsHttpHeader *hdr_;
// Before writing header, there is a chance to filter it, // Before writing header, there is a chance to filter it,
// such as remove some headers or inject new. // such as remove some headers or inject new.
ISrsHttpHeaderFilter *hf_; ISrsHttpHeaderFilter *hf_;
@ -241,9 +241,9 @@ private:
ISrsHttpFirstLineWriter *flw_; ISrsHttpFirstLineWriter *flw_;
private: private:
char header_cache[SRS_HTTP_HEADER_CACHE_SIZE]; char header_cache_[SRS_HTTP_HEADER_CACHE_SIZE];
iovec *iovss_cache; iovec *iovss_cache_;
int nb_iovss_cache; int nb_iovss_cache_;
private: private:
// Reply header has been (logically) written // Reply header has been (logically) written
@ -251,16 +251,16 @@ private:
private: private:
// The explicitly-declared Content-Length; or -1 // The explicitly-declared Content-Length; or -1
int64_t content_length; int64_t content_length_;
// The number of bytes written in body // The number of bytes written in body
int64_t written; int64_t written_;
private: private:
// The wroteHeader tells whether the header's been written to "the // The wroteHeader tells whether the header's been written to "the
// wire" (or rather: w.conn.buf). this is unlike // wire" (or rather: w.conn.buf). this is unlike
// (*response).wroteHeader, which tells only whether it was // (*response).wroteHeader, which tells only whether it was
// logically written. // logically written.
bool header_sent; bool header_sent_;
public: public:
SrsHttpMessageWriter(ISrsProtocolReadWriter *io, ISrsHttpFirstLineWriter *flw); SrsHttpMessageWriter(ISrsProtocolReadWriter *io, ISrsHttpFirstLineWriter *flw);
@ -285,7 +285,7 @@ class SrsHttpResponseWriter : public ISrsHttpResponseWriter, public ISrsHttpFirs
protected: protected:
SrsHttpMessageWriter *writer_; SrsHttpMessageWriter *writer_;
// The status code passed to WriteHeader, for response only. // The status code passed to WriteHeader, for response only.
int status; int status_;
public: public:
SrsHttpResponseWriter(ISrsProtocolReadWriter *io); SrsHttpResponseWriter(ISrsProtocolReadWriter *io);
@ -335,16 +335,16 @@ public:
class SrsHttpResponseReader : public ISrsHttpResponseReader class SrsHttpResponseReader : public ISrsHttpResponseReader
{ {
private: private:
ISrsReader *skt; ISrsReader *skt_;
SrsHttpMessage *owner; SrsHttpMessage *owner_;
SrsFastStream *buffer; SrsFastStream *buffer_;
bool is_eof; bool is_eof_;
// The left bytes in chunk. // The left bytes in chunk.
size_t nb_left_chunk; size_t nb_left_chunk_;
// The number of bytes of current chunk. // The number of bytes of current chunk.
size_t nb_chunk; size_t nb_chunk_;
// Already read total bytes. // Already read total bytes.
int64_t nb_total_read; int64_t nb_total_read_;
public: public:
// Generally the reader is the under-layer io such as socket, // Generally the reader is the under-layer io such as socket,

View File

@ -1205,7 +1205,7 @@ ISrsHttpMessage::~ISrsHttpMessage()
SrsHttpUri::SrsHttpUri() SrsHttpUri::SrsHttpUri()
{ {
port = 0; port_ = 0;
} }
SrsHttpUri::~SrsHttpUri() SrsHttpUri::~SrsHttpUri()
@ -1214,7 +1214,7 @@ SrsHttpUri::~SrsHttpUri()
srs_error_t SrsHttpUri::initialize(string url) srs_error_t SrsHttpUri::initialize(string url)
{ {
schema = host = path = query = fragment_ = ""; schema_ = host_ = path_ = query_ = fragment_ = "";
url_ = url; url_ = url;
// Replace the default vhost to a domain like string, or parse failed. // Replace the default vhost to a domain like string, or parse failed.
@ -1226,25 +1226,25 @@ srs_error_t SrsHttpUri::initialize(string url)
// Simple URL parser to replace http-parser URL parsing // Simple URL parser to replace http-parser URL parsing
srs_error_t err = srs_success; srs_error_t err = srs_success;
if ((err = parse_url_simple(parsing_url, schema, host, port, path, query, fragment_, username_, password_)) != srs_success) { if ((err = parse_url_simple(parsing_url, schema_, host_, port_, path_, query_, fragment_, username_, password_)) != srs_success) {
return srs_error_wrap(err, "parse url %s as %s failed", url.c_str(), parsing_url.c_str()); return srs_error_wrap(err, "parse url %s as %s failed", url.c_str(), parsing_url.c_str());
} }
// Restore the default vhost. // Restore the default vhost.
if (pos_default_vhost != string::npos) { if (pos_default_vhost != string::npos) {
host = SRS_CONSTS_RTMP_DEFAULT_VHOST; host_ = SRS_CONSTS_RTMP_DEFAULT_VHOST;
} }
// Set default ports if not specified // Set default ports if not specified
if (port <= 0) { if (port_ <= 0) {
if (schema == "https") { if (schema_ == "https") {
port = SRS_DEFAULT_HTTPS_PORT; port_ = SRS_DEFAULT_HTTPS_PORT;
} else if (schema == "rtmp") { } else if (schema_ == "rtmp") {
port = SRS_CONSTS_RTMP_DEFAULT_PORT; port_ = SRS_CONSTS_RTMP_DEFAULT_PORT;
} else if (schema == "redis") { } else if (schema_ == "redis") {
port = SRS_DEFAULT_REDIS_PORT; port_ = SRS_DEFAULT_REDIS_PORT;
} else { } else {
port = SRS_DEFAULT_HTTP_PORT; port_ = SRS_DEFAULT_HTTP_PORT;
} }
} }
@ -1253,12 +1253,12 @@ srs_error_t SrsHttpUri::initialize(string url)
void SrsHttpUri::set_schema(std::string v) void SrsHttpUri::set_schema(std::string v)
{ {
schema = v; schema_ = v;
// Update url with new schema. // Update url with new schema.
size_t pos = url_.find("://"); size_t pos = url_.find("://");
if (pos != string::npos) { if (pos != string::npos) {
url_ = schema + "://" + url_.substr(pos + 3); url_ = schema_ + "://" + url_.substr(pos + 3);
} }
} }
@ -1269,27 +1269,27 @@ string SrsHttpUri::get_url()
string SrsHttpUri::get_schema() string SrsHttpUri::get_schema()
{ {
return schema; return schema_;
} }
string SrsHttpUri::get_host() string SrsHttpUri::get_host()
{ {
return host; return host_;
} }
int SrsHttpUri::get_port() int SrsHttpUri::get_port()
{ {
return port; return port_;
} }
string SrsHttpUri::get_path() string SrsHttpUri::get_path()
{ {
return path; return path_;
} }
string SrsHttpUri::get_query() string SrsHttpUri::get_query()
{ {
return query; return query_;
} }
string SrsHttpUri::get_query_by_key(std::string key) string SrsHttpUri::get_query_by_key(std::string key)
@ -1416,17 +1416,17 @@ srs_error_t SrsHttpUri::parse_url_simple(const string &url, string &schema, stri
srs_error_t SrsHttpUri::parse_query() srs_error_t SrsHttpUri::parse_query()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
if (query.empty()) { if (query_.empty()) {
return err; return err;
} }
size_t begin = query.find("?"); size_t begin = query_.find("?");
if (string::npos != begin) { if (string::npos != begin) {
begin++; begin++;
} else { } else {
begin = 0; begin = 0;
} }
string query_str = query.substr(begin); string query_str = query_.substr(begin);
query_values_.clear(); query_values_.clear();
srs_net_url_parse_query(query_str, query_values_); srs_net_url_parse_query(query_str, query_values_);

View File

@ -637,11 +637,11 @@ class SrsHttpUri
{ {
private: private:
std::string url_; std::string url_;
std::string schema; std::string schema_;
std::string host; std::string host_;
int port; int port_;
std::string path; std::string path_;
std::string query; std::string query_;
std::string fragment_; std::string fragment_;
std::string username_; std::string username_;
std::string password_; std::string password_;

View File

@ -1309,14 +1309,14 @@ public:
SrsJsonString(const char *v) SrsJsonString(const char *v)
{ {
marker = SRS_JSON_String; marker_ = SRS_JSON_String;
if (v) { if (v) {
value = v; value = v;
} }
} }
SrsJsonString(const char *v, int s) SrsJsonString(const char *v, int s)
{ {
marker = SRS_JSON_String; marker_ = SRS_JSON_String;
if (v) { if (v) {
value.append(v, s); value.append(v, s);
} }
@ -1333,7 +1333,7 @@ public:
SrsJsonBoolean(bool v) SrsJsonBoolean(bool v)
{ {
marker = SRS_JSON_Boolean; marker_ = SRS_JSON_Boolean;
value = v; value = v;
} }
virtual ~SrsJsonBoolean() virtual ~SrsJsonBoolean()
@ -1348,7 +1348,7 @@ public:
SrsJsonInteger(int64_t v) SrsJsonInteger(int64_t v)
{ {
marker = SRS_JSON_Integer; marker_ = SRS_JSON_Integer;
value = v; value = v;
} }
virtual ~SrsJsonInteger() virtual ~SrsJsonInteger()
@ -1363,7 +1363,7 @@ public:
SrsJsonNumber(double v) SrsJsonNumber(double v)
{ {
marker = SRS_JSON_Number; marker_ = SRS_JSON_Number;
value = v; value = v;
} }
virtual ~SrsJsonNumber() virtual ~SrsJsonNumber()
@ -1376,7 +1376,7 @@ class SrsJsonNull : public SrsJsonAny
public: public:
SrsJsonNull() SrsJsonNull()
{ {
marker = SRS_JSON_Null; marker_ = SRS_JSON_Null;
} }
virtual ~SrsJsonNull() virtual ~SrsJsonNull()
{ {
@ -1385,7 +1385,7 @@ public:
SrsJsonAny::SrsJsonAny() SrsJsonAny::SrsJsonAny()
{ {
marker = 0; marker_ = 0;
} }
SrsJsonAny::~SrsJsonAny() SrsJsonAny::~SrsJsonAny()
@ -1394,37 +1394,37 @@ SrsJsonAny::~SrsJsonAny()
bool SrsJsonAny::is_string() bool SrsJsonAny::is_string()
{ {
return marker == SRS_JSON_String; return marker_ == SRS_JSON_String;
} }
bool SrsJsonAny::is_boolean() bool SrsJsonAny::is_boolean()
{ {
return marker == SRS_JSON_Boolean; return marker_ == SRS_JSON_Boolean;
} }
bool SrsJsonAny::is_number() bool SrsJsonAny::is_number()
{ {
return marker == SRS_JSON_Number; return marker_ == SRS_JSON_Number;
} }
bool SrsJsonAny::is_integer() bool SrsJsonAny::is_integer()
{ {
return marker == SRS_JSON_Integer; return marker_ == SRS_JSON_Integer;
} }
bool SrsJsonAny::is_object() bool SrsJsonAny::is_object()
{ {
return marker == SRS_JSON_Object; return marker_ == SRS_JSON_Object;
} }
bool SrsJsonAny::is_array() bool SrsJsonAny::is_array()
{ {
return marker == SRS_JSON_Array; return marker_ == SRS_JSON_Array;
} }
bool SrsJsonAny::is_null() bool SrsJsonAny::is_null()
{ {
return marker == SRS_JSON_Null; return marker_ == SRS_JSON_Null;
} }
string SrsJsonAny::to_str() string SrsJsonAny::to_str()
@ -1514,7 +1514,7 @@ string json_serialize_string(const string &v)
string SrsJsonAny::dumps() string SrsJsonAny::dumps()
{ {
switch (marker) { switch (marker_) {
case SRS_JSON_String: { case SRS_JSON_String: {
SrsJsonString *p = dynamic_cast<SrsJsonString *>(this); SrsJsonString *p = dynamic_cast<SrsJsonString *>(this);
srs_assert(p != NULL); srs_assert(p != NULL);
@ -1551,7 +1551,7 @@ string SrsJsonAny::dumps()
SrsAmf0Any *SrsJsonAny::to_amf0() SrsAmf0Any *SrsJsonAny::to_amf0()
{ {
switch (marker) { switch (marker_) {
case SRS_JSON_String: { case SRS_JSON_String: {
return SrsAmf0Any::str(to_str().c_str()); return SrsAmf0Any::str(to_str().c_str());
} }
@ -1688,36 +1688,36 @@ SrsJsonAny *SrsJsonAny::loads(string str)
SrsJsonObject::SrsJsonObject() SrsJsonObject::SrsJsonObject()
{ {
marker = SRS_JSON_Object; marker_ = SRS_JSON_Object;
} }
SrsJsonObject::~SrsJsonObject() SrsJsonObject::~SrsJsonObject()
{ {
std::vector<SrsJsonObjectPropertyType>::iterator it; std::vector<SrsJsonObjectPropertyType>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsJsonObjectPropertyType item = *it; SrsJsonObjectPropertyType item = *it;
SrsJsonAny *obj = item.second; SrsJsonAny *obj = item.second;
srs_freep(obj); srs_freep(obj);
} }
properties.clear(); properties_.clear();
} }
int SrsJsonObject::count() int SrsJsonObject::count()
{ {
return (int)properties.size(); return (int)properties_.size();
} }
string SrsJsonObject::key_at(int index) string SrsJsonObject::key_at(int index)
{ {
srs_assert(index < count()); srs_assert(index < count());
SrsJsonObjectPropertyType &elem = properties[index]; SrsJsonObjectPropertyType &elem = properties_[index];
return elem.first; return elem.first;
} }
SrsJsonAny *SrsJsonObject::value_at(int index) SrsJsonAny *SrsJsonObject::value_at(int index)
{ {
srs_assert(index < count()); srs_assert(index < count());
SrsJsonObjectPropertyType &elem = properties[index]; SrsJsonObjectPropertyType &elem = properties_[index];
return elem.second; return elem.second;
} }
@ -1727,12 +1727,12 @@ string SrsJsonObject::dumps()
ss << SRS_JOBJECT_START; ss << SRS_JOBJECT_START;
for (int i = 0; i < (int)properties.size(); i++) { for (int i = 0; i < (int)properties_.size(); i++) {
std::string name = this->key_at(i); std::string name = this->key_at(i);
SrsJsonAny *any = this->value_at(i); SrsJsonAny *any = this->value_at(i);
ss << SRS_JFIELD_NAME(name) << any->dumps(); ss << SRS_JFIELD_NAME(name) << any->dumps();
if (i < (int)properties.size() - 1) { if (i < (int)properties_.size() - 1) {
ss << SRS_JFIELD_CONT; ss << SRS_JFIELD_CONT;
} }
} }
@ -1746,7 +1746,7 @@ SrsAmf0Any *SrsJsonObject::to_amf0()
{ {
SrsAmf0Object *obj = SrsAmf0Any::object(); SrsAmf0Object *obj = SrsAmf0Any::object();
for (int i = 0; i < (int)properties.size(); i++) { for (int i = 0; i < (int)properties_.size(); i++) {
std::string name = this->key_at(i); std::string name = this->key_at(i);
SrsJsonAny *any = this->value_at(i); SrsJsonAny *any = this->value_at(i);
@ -1765,19 +1765,19 @@ SrsJsonObject *SrsJsonObject::set(string key, SrsJsonAny *value)
std::vector<SrsJsonObjectPropertyType>::iterator it; std::vector<SrsJsonObjectPropertyType>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsJsonObjectPropertyType &elem = *it; SrsJsonObjectPropertyType &elem = *it;
std::string name = elem.first; std::string name = elem.first;
SrsJsonAny *any = elem.second; SrsJsonAny *any = elem.second;
if (key == name) { if (key == name) {
srs_freep(any); srs_freep(any);
it = properties.erase(it); it = properties_.erase(it);
break; break;
} }
} }
properties.push_back(std::make_pair(key, value)); properties_.push_back(std::make_pair(key, value));
return this; return this;
} }
@ -1785,7 +1785,7 @@ SrsJsonAny *SrsJsonObject::get_property(string name)
{ {
std::vector<SrsJsonObjectPropertyType>::iterator it; std::vector<SrsJsonObjectPropertyType>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsJsonObjectPropertyType &elem = *it; SrsJsonObjectPropertyType &elem = *it;
std::string key = elem.first; std::string key = elem.first;
SrsJsonAny *any = elem.second; SrsJsonAny *any = elem.second;
@ -1889,34 +1889,34 @@ SrsJsonAny *SrsJsonObject::ensure_property_array(string name)
SrsJsonArray::SrsJsonArray() SrsJsonArray::SrsJsonArray()
{ {
marker = SRS_JSON_Array; marker_ = SRS_JSON_Array;
} }
SrsJsonArray::~SrsJsonArray() SrsJsonArray::~SrsJsonArray()
{ {
std::vector<SrsJsonAny *>::iterator it; std::vector<SrsJsonAny *>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) { for (it = properties_.begin(); it != properties_.end(); ++it) {
SrsJsonAny *item = *it; SrsJsonAny *item = *it;
srs_freep(item); srs_freep(item);
} }
properties.clear(); properties_.clear();
} }
int SrsJsonArray::count() int SrsJsonArray::count()
{ {
return (int)properties.size(); return (int)properties_.size();
} }
SrsJsonAny *SrsJsonArray::at(int index) SrsJsonAny *SrsJsonArray::at(int index)
{ {
srs_assert(index < count()); srs_assert(index < count());
SrsJsonAny *elem = properties[index]; SrsJsonAny *elem = properties_[index];
return elem; return elem;
} }
SrsJsonArray *SrsJsonArray::add(SrsJsonAny *value) SrsJsonArray *SrsJsonArray::add(SrsJsonAny *value)
{ {
properties.push_back(value); properties_.push_back(value);
return this; return this;
} }
@ -1932,12 +1932,12 @@ string SrsJsonArray::dumps()
ss << SRS_JARRAY_START; ss << SRS_JARRAY_START;
for (int i = 0; i < (int)properties.size(); i++) { for (int i = 0; i < (int)properties_.size(); i++) {
SrsJsonAny *any = properties[i]; SrsJsonAny *any = properties_[i];
ss << any->dumps(); ss << any->dumps();
if (i < (int)properties.size() - 1) { if (i < (int)properties_.size() - 1) {
ss << SRS_JFIELD_CONT; ss << SRS_JFIELD_CONT;
} }
} }
@ -1951,8 +1951,8 @@ SrsAmf0Any *SrsJsonArray::to_amf0()
{ {
SrsAmf0StrictArray *arr = SrsAmf0Any::strict_array(); SrsAmf0StrictArray *arr = SrsAmf0Any::strict_array();
for (int i = 0; i < (int)properties.size(); i++) { for (int i = 0; i < (int)properties_.size(); i++) {
SrsJsonAny *any = properties[i]; SrsJsonAny *any = properties_[i];
arr->append(any->to_amf0()); arr->append(any->to_amf0());
} }

View File

@ -41,7 +41,7 @@ class SrsJsonObject;
class SrsJsonAny class SrsJsonAny
{ {
public: public:
char marker; char marker_;
// Don't directly create this object, // Don't directly create this object,
// please use SrsJsonAny::str() to create a concreated one. // please use SrsJsonAny::str() to create a concreated one.
protected: protected:
@ -103,7 +103,7 @@ class SrsJsonObject : public SrsJsonAny
{ {
private: private:
typedef std::pair<std::string, SrsJsonAny *> SrsJsonObjectPropertyType; typedef std::pair<std::string, SrsJsonAny *> SrsJsonObjectPropertyType;
std::vector<SrsJsonObjectPropertyType> properties; std::vector<SrsJsonObjectPropertyType> properties_;
private: private:
// Use SrsJsonAny::object() to create it. // Use SrsJsonAny::object() to create it.
@ -138,7 +138,7 @@ public:
class SrsJsonArray : public SrsJsonAny class SrsJsonArray : public SrsJsonAny
{ {
private: private:
std::vector<SrsJsonAny *> properties; std::vector<SrsJsonAny *> properties_;
private: private:
// Use SrsJsonAny::array() to create it. // Use SrsJsonAny::array() to create it.

View File

@ -10,9 +10,9 @@
SrsKbpsSlice::SrsKbpsSlice(SrsWallClock *c) SrsKbpsSlice::SrsKbpsSlice(SrsWallClock *c)
{ {
clk = c; clk_ = c;
starttime = 0; starttime_ = 0;
bytes = 0; bytes_ = 0;
} }
SrsKbpsSlice::~SrsKbpsSlice() SrsKbpsSlice::~SrsKbpsSlice()
@ -21,36 +21,36 @@ SrsKbpsSlice::~SrsKbpsSlice()
void SrsKbpsSlice::sample() void SrsKbpsSlice::sample()
{ {
srs_utime_t now = clk->now(); srs_utime_t now = clk_->now();
if (sample_30s.time_ < 0) { if (sample_30s_.time_ < 0) {
sample_30s.update(bytes, now, 0); sample_30s_.update(bytes_, now, 0);
} }
if (sample_1m.time_ < 0) { if (sample_1m_.time_ < 0) {
sample_1m.update(bytes, now, 0); sample_1m_.update(bytes_, now, 0);
} }
if (sample_5m.time_ < 0) { if (sample_5m_.time_ < 0) {
sample_5m.update(bytes, now, 0); sample_5m_.update(bytes_, now, 0);
} }
if (sample_60m.time_ < 0) { if (sample_60m_.time_ < 0) {
sample_60m.update(bytes, now, 0); sample_60m_.update(bytes_, now, 0);
} }
if (now - sample_30s.time_ >= 30 * SRS_UTIME_SECONDS) { if (now - sample_30s_.time_ >= 30 * SRS_UTIME_SECONDS) {
int kbps = (int)((bytes - sample_30s.total_) * 8 / srsu2ms(now - sample_30s.time_)); int kbps = (int)((bytes_ - sample_30s_.total_) * 8 / srsu2ms(now - sample_30s_.time_));
sample_30s.update(bytes, now, kbps); sample_30s_.update(bytes_, now, kbps);
} }
if (now - sample_1m.time_ >= 60 * SRS_UTIME_SECONDS) { if (now - sample_1m_.time_ >= 60 * SRS_UTIME_SECONDS) {
int kbps = (int)((bytes - sample_1m.total_) * 8 / srsu2ms(now - sample_1m.time_)); int kbps = (int)((bytes_ - sample_1m_.total_) * 8 / srsu2ms(now - sample_1m_.time_));
sample_1m.update(bytes, now, kbps); sample_1m_.update(bytes_, now, kbps);
} }
if (now - sample_5m.time_ >= 300 * SRS_UTIME_SECONDS) { if (now - sample_5m_.time_ >= 300 * SRS_UTIME_SECONDS) {
int kbps = (int)((bytes - sample_5m.total_) * 8 / srsu2ms(now - sample_5m.time_)); int kbps = (int)((bytes_ - sample_5m_.total_) * 8 / srsu2ms(now - sample_5m_.time_));
sample_5m.update(bytes, now, kbps); sample_5m_.update(bytes_, now, kbps);
} }
if (now - sample_60m.time_ >= 3600 * SRS_UTIME_SECONDS) { if (now - sample_60m_.time_ >= 3600 * SRS_UTIME_SECONDS) {
int kbps = (int)((bytes - sample_60m.total_) * 8 / srsu2ms(now - sample_60m.time_)); int kbps = (int)((bytes_ - sample_60m_.total_) * 8 / srsu2ms(now - sample_60m_.time_));
sample_60m.update(bytes, now, kbps); sample_60m_.update(bytes_, now, kbps);
} }
} }
@ -136,20 +136,20 @@ void SrsNetworkDelta::remark(int64_t *in, int64_t *out)
SrsKbps::SrsKbps(SrsWallClock *c) SrsKbps::SrsKbps(SrsWallClock *c)
{ {
clk = c ? c : _srs_clock; clk_ = c ? c : _srs_clock;
is = new SrsKbpsSlice(clk); is_ = new SrsKbpsSlice(clk_);
os = new SrsKbpsSlice(clk); os_ = new SrsKbpsSlice(clk_);
} }
SrsKbps::~SrsKbps() SrsKbps::~SrsKbps()
{ {
srs_freep(is); srs_freep(is_);
srs_freep(os); srs_freep(os_);
} }
int SrsKbps::get_send_kbps() int SrsKbps::get_send_kbps()
{ {
int duration = srsu2ms(clk->now() - is->starttime); int duration = srsu2ms(clk_->now() - is_->starttime_);
if (duration <= 0) { if (duration <= 0) {
return 0; return 0;
} }
@ -160,7 +160,7 @@ int SrsKbps::get_send_kbps()
int SrsKbps::get_recv_kbps() int SrsKbps::get_recv_kbps()
{ {
int duration = srsu2ms(clk->now() - os->starttime); int duration = srsu2ms(clk_->now() - os_->starttime_);
if (duration <= 0) { if (duration <= 0) {
return 0; return 0;
} }
@ -171,22 +171,22 @@ int SrsKbps::get_recv_kbps()
int SrsKbps::get_send_kbps_30s() int SrsKbps::get_send_kbps_30s()
{ {
return os->sample_30s.rate_; return os_->sample_30s_.rate_;
} }
int SrsKbps::get_recv_kbps_30s() int SrsKbps::get_recv_kbps_30s()
{ {
return is->sample_30s.rate_; return is_->sample_30s_.rate_;
} }
int SrsKbps::get_send_kbps_5m() int SrsKbps::get_send_kbps_5m()
{ {
return os->sample_5m.rate_; return os_->sample_5m_.rate_;
} }
int SrsKbps::get_recv_kbps_5m() int SrsKbps::get_recv_kbps_5m()
{ {
return is->sample_5m.rate_; return is_->sample_5m_.rate_;
} }
void SrsKbps::add_delta(ISrsKbpsDelta *delta) void SrsKbps::add_delta(ISrsKbpsDelta *delta)
@ -202,26 +202,26 @@ void SrsKbps::add_delta(ISrsKbpsDelta *delta)
void SrsKbps::add_delta(int64_t in, int64_t out) void SrsKbps::add_delta(int64_t in, int64_t out)
{ {
// update the total bytes // update the total bytes
is->bytes += in; is_->bytes_ += in;
os->bytes += out; os_->bytes_ += out;
// we donot sample, please use sample() to do resample. // we donot sample, please use sample() to do resample.
} }
void SrsKbps::sample() void SrsKbps::sample()
{ {
is->sample(); is_->sample();
os->sample(); os_->sample();
} }
int64_t SrsKbps::get_send_bytes() int64_t SrsKbps::get_send_bytes()
{ {
return os->bytes; return os_->bytes_;
} }
int64_t SrsKbps::get_recv_bytes() int64_t SrsKbps::get_recv_bytes()
{ {
return is->bytes; return is_->bytes_;
} }
SrsNetworkKbps::SrsNetworkKbps(SrsWallClock *clock) SrsNetworkKbps::SrsNetworkKbps(SrsWallClock *clock)

View File

@ -18,22 +18,22 @@
class SrsKbpsSlice class SrsKbpsSlice
{ {
private: private:
SrsWallClock *clk; SrsWallClock *clk_;
public: public:
// session startup bytes // session startup bytes
// @remark, use total_bytes() to get the total bytes of slice. // @remark, use total_bytes() to get the total bytes of slice.
int64_t bytes; int64_t bytes_;
// slice starttime, the first time to record bytes. // slice starttime, the first time to record bytes.
srs_utime_t starttime; srs_utime_t starttime_;
// samples // samples
SrsRateSample sample_30s; SrsRateSample sample_30s_;
SrsRateSample sample_1m; SrsRateSample sample_1m_;
SrsRateSample sample_5m; SrsRateSample sample_5m_;
SrsRateSample sample_60m; SrsRateSample sample_60m_;
public: public:
SrsKbpsSlice(SrsWallClock *clk); SrsKbpsSlice(SrsWallClock *c);
virtual ~SrsKbpsSlice(); virtual ~SrsKbpsSlice();
public: public:
@ -119,9 +119,9 @@ public:
class SrsKbps class SrsKbps
{ {
private: private:
SrsKbpsSlice *is; SrsKbpsSlice *is_;
SrsKbpsSlice *os; SrsKbpsSlice *os_;
SrsWallClock *clk; SrsWallClock *clk_;
public: public:
// Note that we won't free the clock c. // Note that we won't free the clock c.

View File

@ -107,14 +107,14 @@ impl_SrsContextRestore::~impl_SrsContextRestore()
SrsConsoleLog::SrsConsoleLog(SrsLogLevel l, bool u) SrsConsoleLog::SrsConsoleLog(SrsLogLevel l, bool u)
{ {
level_ = l; level_ = l;
utc = u; utc_ = u;
buffer = new char[SRS_BASIC_LOG_SIZE]; buffer_ = new char[SRS_BASIC_LOG_SIZE];
} }
SrsConsoleLog::~SrsConsoleLog() SrsConsoleLog::~SrsConsoleLog()
{ {
srs_freepa(buffer); srs_freepa(buffer_);
} }
srs_error_t SrsConsoleLog::initialize() srs_error_t SrsConsoleLog::initialize()
@ -133,12 +133,12 @@ void SrsConsoleLog::log(SrsLogLevel level, const char *tag, const SrsContextId &
} }
int size = 0; int size = 0;
if (!srs_log_header(buffer, SRS_BASIC_LOG_SIZE, utc, level >= SrsLogLevelWarn, tag, context_id, srs_log_level_strings[level], &size)) { if (!srs_log_header(buffer_, SRS_BASIC_LOG_SIZE, utc_, level >= SrsLogLevelWarn, tag, context_id, srs_log_level_strings[level], &size)) {
return; return;
} }
// Something not expected, drop the log. // Something not expected, drop the log.
int r0 = vsnprintf(buffer + size, SRS_BASIC_LOG_SIZE - size, fmt, args); int r0 = vsnprintf(buffer_ + size, SRS_BASIC_LOG_SIZE - size, fmt, args);
if (r0 <= 0 || r0 >= SRS_BASIC_LOG_SIZE - size) { if (r0 <= 0 || r0 >= SRS_BASIC_LOG_SIZE - size) {
return; return;
} }
@ -146,7 +146,7 @@ void SrsConsoleLog::log(SrsLogLevel level, const char *tag, const SrsContextId &
// Add errno and strerror() if error. // Add errno and strerror() if error.
if (level == SrsLogLevelError && errno != 0) { if (level == SrsLogLevelError && errno != 0) {
r0 = snprintf(buffer + size, SRS_BASIC_LOG_SIZE - size, "(%s)", strerror(errno)); r0 = snprintf(buffer_ + size, SRS_BASIC_LOG_SIZE - size, "(%s)", strerror(errno));
// Something not expected, drop the log. // Something not expected, drop the log.
if (r0 <= 0 || r0 >= SRS_BASIC_LOG_SIZE - size) { if (r0 <= 0 || r0 >= SRS_BASIC_LOG_SIZE - size) {
@ -156,9 +156,9 @@ void SrsConsoleLog::log(SrsLogLevel level, const char *tag, const SrsContextId &
} }
if (level >= SrsLogLevelWarn) { if (level >= SrsLogLevelWarn) {
fprintf(stderr, "%s\n", buffer); fprintf(stderr, "%s\n", buffer_);
} else { } else {
fprintf(stdout, "%s\n", buffer); fprintf(stdout, "%s\n", buffer_);
} }
} }

View File

@ -20,7 +20,7 @@
class SrsThreadContext : public ISrsContext class SrsThreadContext : public ISrsContext
{ {
private: private:
std::map<srs_thread_t, SrsContextId> cache; std::map<srs_thread_t, SrsContextId> cache_;
public: public:
SrsThreadContext(); SrsThreadContext();
@ -57,10 +57,10 @@ class SrsConsoleLog : public ISrsLog
{ {
private: private:
SrsLogLevel level_; SrsLogLevel level_;
bool utc; bool utc_;
private: private:
char *buffer; char *buffer_;
public: public:
SrsConsoleLog(SrsLogLevel l, bool u); SrsConsoleLog(SrsLogLevel l, bool u);

View File

@ -755,30 +755,30 @@ srs_error_t SrsRawAacStream::adts_demux(SrsBuffer *stream, char **pframe, int *p
} }
// the codec info. // the codec info.
codec.protection_absent = protection_absent; codec.protection_absent_ = protection_absent;
codec.aac_object = srs_aac_ts2rtmp((SrsAacProfile)profile); codec.aac_object_ = srs_aac_ts2rtmp((SrsAacProfile)profile);
codec.sampling_frequency_index = sampling_frequency_index; codec.sampling_frequency_index_ = sampling_frequency_index;
codec.channel_configuration = channel_configuration; codec.channel_configuration_ = channel_configuration;
codec.frame_length = frame_length; codec.frame_length_ = frame_length;
// The aac sampleing rate defined in srs_aac_srates. // The aac sampleing rate defined in srs_aac_srates.
// TODO: FIXME: maybe need to resample audio. // TODO: FIXME: maybe need to resample audio.
codec.sound_format = 10; // AAC codec.sound_format_ = 10; // AAC
if (sampling_frequency_index <= 0x0c && sampling_frequency_index > 0x0a) { if (sampling_frequency_index <= 0x0c && sampling_frequency_index > 0x0a) {
codec.sound_rate = SrsAudioSampleRate5512; codec.sound_rate_ = SrsAudioSampleRate5512;
} else if (sampling_frequency_index <= 0x0a && sampling_frequency_index > 0x07) { } else if (sampling_frequency_index <= 0x0a && sampling_frequency_index > 0x07) {
codec.sound_rate = SrsAudioSampleRate11025; codec.sound_rate_ = SrsAudioSampleRate11025;
} else if (sampling_frequency_index <= 0x07 && sampling_frequency_index > 0x04) { } else if (sampling_frequency_index <= 0x07 && sampling_frequency_index > 0x04) {
codec.sound_rate = SrsAudioSampleRate22050; codec.sound_rate_ = SrsAudioSampleRate22050;
} else if (sampling_frequency_index <= 0x04) { } else if (sampling_frequency_index <= 0x04) {
codec.sound_rate = SrsAudioSampleRate44100; codec.sound_rate_ = SrsAudioSampleRate44100;
} else { } else {
codec.sound_rate = SrsAudioSampleRate44100; codec.sound_rate_ = SrsAudioSampleRate44100;
srs_warn("adts invalid sample rate for flv, rate=%#x", sampling_frequency_index); srs_warn("adts invalid sample rate for flv, rate=%#x", sampling_frequency_index);
} }
codec.sound_type = srs_max(0, srs_min(1, channel_configuration - 1)); codec.sound_type_ = srs_max(0, srs_min(1, channel_configuration - 1));
// TODO: FIXME: finger it out the sound size by adts. // TODO: FIXME: finger it out the sound size by adts.
codec.sound_size = 1; // 0(8bits) or 1(16bits). codec.sound_size_ = 1; // 0(8bits) or 1(16bits).
// frame data. // frame data.
*pframe = stream->data() + stream->pos(); *pframe = stream->data() + stream->pos();
@ -796,12 +796,12 @@ srs_error_t SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec *codec, st
srs_error_t err = srs_success; srs_error_t err = srs_success;
// only support aac profile 1-4. // only support aac profile 1-4.
if (codec->aac_object == SrsAacObjectTypeReserved) { if (codec->aac_object_ == SrsAacObjectTypeReserved) {
return srs_error_new(ERROR_AAC_DATA_INVALID, "invalid aac object"); return srs_error_new(ERROR_AAC_DATA_INVALID, "invalid aac object");
} }
SrsAacObjectType audioObjectType = codec->aac_object; SrsAacObjectType audioObjectType = codec->aac_object_;
char channelConfiguration = codec->channel_configuration; char channelConfiguration = codec->channel_configuration_;
// Here we are generating AAC sequence header, the ASC structure, // Here we are generating AAC sequence header, the ASC structure,
// because we have already parsed the sampling rate from AAC codec, // because we have already parsed the sampling rate from AAC codec,
@ -810,9 +810,9 @@ srs_error_t SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec *codec, st
// For example, AAC sampling_frequency_index is 3(48000HZ) or 4(44100HZ), // For example, AAC sampling_frequency_index is 3(48000HZ) or 4(44100HZ),
// the sound_rate is always 3(44100HZ), if we covert sound_rate to // the sound_rate is always 3(44100HZ), if we covert sound_rate to
// sampling_frequency_index, we may make mistake. // sampling_frequency_index, we may make mistake.
uint8_t samplingFrequencyIndex = (uint8_t)codec->sampling_frequency_index; uint8_t samplingFrequencyIndex = (uint8_t)codec->sampling_frequency_index_;
if (samplingFrequencyIndex >= SrsAacSampleRateUnset) { if (samplingFrequencyIndex >= SrsAacSampleRateUnset) {
switch (codec->sound_rate) { switch (codec->sound_rate_) {
case SrsAudioSampleRate5512: case SrsAudioSampleRate5512:
samplingFrequencyIndex = 0x0c; samplingFrequencyIndex = 0x0c;
break; break;
@ -864,11 +864,11 @@ srs_error_t SrsRawAacStream::mux_aac2flv(char *frame, int nb_frame, SrsRawAacStr
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
char sound_format = codec->sound_format; char sound_format = codec->sound_format_;
char sound_type = codec->sound_type; char sound_type = codec->sound_type_;
char sound_size = codec->sound_size; char sound_size = codec->sound_size_;
char sound_rate = codec->sound_rate; char sound_rate = codec->sound_rate_;
char aac_packet_type = codec->aac_packet_type; char aac_packet_type = codec->aac_packet_type_;
// for audio frame, there is 1 or 2 bytes header: // for audio frame, there is 1 or 2 bytes header:
// 1bytes, SoundFormat|SoundRate|SoundSize|SoundType // 1bytes, SoundFormat|SoundRate|SoundSize|SoundType

View File

@ -110,19 +110,19 @@ public:
// The header of adts sample. // The header of adts sample.
struct SrsRawAacStreamCodec { struct SrsRawAacStreamCodec {
// Codec level informations. // Codec level informations.
int8_t protection_absent; int8_t protection_absent_;
SrsAacObjectType aac_object; SrsAacObjectType aac_object_;
int8_t sampling_frequency_index; int8_t sampling_frequency_index_;
int8_t channel_configuration; int8_t channel_configuration_;
int16_t frame_length; int16_t frame_length_;
// Format level, RTMP as such, informations. // Format level, RTMP as such, informations.
char sound_format; char sound_format_;
char sound_rate; char sound_rate_;
char sound_size; char sound_size_;
char sound_type; char sound_type_;
// 0 for sh; 1 for raw data. // 0 for sh; 1 for raw data.
int8_t aac_packet_type; int8_t aac_packet_type_;
}; };
// The raw aac stream, in adts. // The raw aac stream, in adts.

View File

@ -109,14 +109,14 @@ static srs_error_t hmac_encode(const std::string &algo, const char *key, const i
SrsStunPacket::SrsStunPacket() SrsStunPacket::SrsStunPacket()
{ {
message_type = 0; message_type_ = 0;
local_ufrag = ""; local_ufrag_ = "";
remote_ufrag = ""; remote_ufrag_ = "";
use_candidate = false; use_candidate_ = false;
ice_controlled = false; ice_controlled_ = false;
ice_controlling = false; ice_controlling_ = false;
mapped_port = 0; mapped_port_ = 0;
mapped_address = 0; mapped_address_ = 0;
} }
SrsStunPacket::~SrsStunPacket() SrsStunPacket::~SrsStunPacket()
@ -125,92 +125,92 @@ SrsStunPacket::~SrsStunPacket()
bool SrsStunPacket::is_binding_request() const bool SrsStunPacket::is_binding_request() const
{ {
return message_type == BindingRequest; return message_type_ == BindingRequest;
} }
bool SrsStunPacket::is_binding_response() const bool SrsStunPacket::is_binding_response() const
{ {
return message_type == BindingResponse; return message_type_ == BindingResponse;
} }
uint16_t SrsStunPacket::get_message_type() const uint16_t SrsStunPacket::get_message_type() const
{ {
return message_type; return message_type_;
} }
std::string SrsStunPacket::get_username() const std::string SrsStunPacket::get_username() const
{ {
return username; return username_;
} }
std::string SrsStunPacket::get_local_ufrag() const std::string SrsStunPacket::get_local_ufrag() const
{ {
return local_ufrag; return local_ufrag_;
} }
std::string SrsStunPacket::get_remote_ufrag() const std::string SrsStunPacket::get_remote_ufrag() const
{ {
return remote_ufrag; return remote_ufrag_;
} }
std::string SrsStunPacket::get_transcation_id() const std::string SrsStunPacket::get_transcation_id() const
{ {
return transcation_id; return transcation_id_;
} }
uint32_t SrsStunPacket::get_mapped_address() const uint32_t SrsStunPacket::get_mapped_address() const
{ {
return mapped_address; return mapped_address_;
} }
uint16_t SrsStunPacket::get_mapped_port() const uint16_t SrsStunPacket::get_mapped_port() const
{ {
return mapped_port; return mapped_port_;
} }
bool SrsStunPacket::get_ice_controlled() const bool SrsStunPacket::get_ice_controlled() const
{ {
return ice_controlled; return ice_controlled_;
} }
bool SrsStunPacket::get_ice_controlling() const bool SrsStunPacket::get_ice_controlling() const
{ {
return ice_controlling; return ice_controlling_;
} }
bool SrsStunPacket::get_use_candidate() const bool SrsStunPacket::get_use_candidate() const
{ {
return use_candidate; return use_candidate_;
} }
void SrsStunPacket::set_message_type(const uint16_t &m) void SrsStunPacket::set_message_type(const uint16_t &m)
{ {
message_type = m; message_type_ = m;
} }
void SrsStunPacket::set_local_ufrag(const std::string &u) void SrsStunPacket::set_local_ufrag(const std::string &u)
{ {
local_ufrag = u; local_ufrag_ = u;
} }
void SrsStunPacket::set_remote_ufrag(const std::string &u) void SrsStunPacket::set_remote_ufrag(const std::string &u)
{ {
remote_ufrag = u; remote_ufrag_ = u;
} }
void SrsStunPacket::set_transcation_id(const std::string &t) void SrsStunPacket::set_transcation_id(const std::string &t)
{ {
transcation_id = t; transcation_id_ = t;
} }
void SrsStunPacket::set_mapped_address(const uint32_t &addr) void SrsStunPacket::set_mapped_address(const uint32_t &addr)
{ {
mapped_address = addr; mapped_address_ = addr;
} }
void SrsStunPacket::set_mapped_port(const uint32_t &port) void SrsStunPacket::set_mapped_port(const uint32_t &port)
{ {
mapped_port = port; mapped_port_ = port;
} }
srs_error_t SrsStunPacket::decode(const char *buf, const int nb_buf) srs_error_t SrsStunPacket::decode(const char *buf, const int nb_buf)
@ -223,10 +223,10 @@ srs_error_t SrsStunPacket::decode(const char *buf, const int nb_buf)
return srs_error_new(ERROR_RTC_STUN, "invalid stun packet, size=%d", stream->size()); return srs_error_new(ERROR_RTC_STUN, "invalid stun packet, size=%d", stream->size());
} }
message_type = stream->read_2bytes(); message_type_ = stream->read_2bytes();
uint16_t message_len = stream->read_2bytes(); uint16_t message_len = stream->read_2bytes();
string magic_cookie = stream->read_string(4); string magic_cookie = stream->read_string(4);
transcation_id = stream->read_string(12); transcation_id_ = stream->read_string(12);
if (nb_buf != 20 + message_len) { if (nb_buf != 20 + message_len) {
return srs_error_new(ERROR_RTC_STUN, "invalid stun packet, message_len=%d, nb_buf=%d", message_len, nb_buf); return srs_error_new(ERROR_RTC_STUN, "invalid stun packet, message_len=%d, nb_buf=%d", message_len, nb_buf);
@ -248,18 +248,18 @@ srs_error_t SrsStunPacket::decode(const char *buf, const int nb_buf)
switch (type) { switch (type) {
case Username: { case Username: {
username = val; username_ = val;
size_t p = val.find(":"); size_t p = val.find(":");
if (p != string::npos) { if (p != string::npos) {
local_ufrag = val.substr(0, p); local_ufrag_ = val.substr(0, p);
remote_ufrag = val.substr(p + 1); remote_ufrag_ = val.substr(p + 1);
srs_verbose("stun packet local_ufrag=%s, remote_ufrag=%s", local_ufrag.c_str(), remote_ufrag.c_str()); srs_verbose("stun packet local_ufrag=%s, remote_ufrag=%s", local_ufrag_.c_str(), remote_ufrag_.c_str());
} }
break; break;
} }
case UseCandidate: { case UseCandidate: {
use_candidate = true; use_candidate_ = true;
srs_verbose("stun use-candidate"); srs_verbose("stun use-candidate");
break; break;
} }
@ -270,13 +270,13 @@ srs_error_t SrsStunPacket::decode(const char *buf, const int nb_buf)
// agent will form check lists, run the ICE state machines, and // agent will form check lists, run the ICE state machines, and
// generate connectivity checks. // generate connectivity checks.
case IceControlled: { case IceControlled: {
ice_controlled = true; ice_controlled_ = true;
srs_verbose("stun ice-controlled"); srs_verbose("stun ice-controlled");
break; break;
} }
case IceControlling: { case IceControlling: {
ice_controlling = true; ice_controlling_ = true;
srs_verbose("stun ice-controlling"); srs_verbose("stun ice-controlling");
break; break;
} }
@ -311,7 +311,7 @@ srs_error_t SrsStunPacket::encode_binding_response(const string &pwd, SrsBuffer
stream->write_2bytes(BindingResponse); stream->write_2bytes(BindingResponse);
stream->write_2bytes(property_username.size() + mapped_address.size()); stream->write_2bytes(property_username.size() + mapped_address.size());
stream->write_4bytes(kStunMagicCookie); stream->write_4bytes(kStunMagicCookie);
stream->write_string(transcation_id); stream->write_string(transcation_id_);
stream->write_string(property_username); stream->write_string(property_username);
stream->write_string(mapped_address); stream->write_string(mapped_address);
@ -347,7 +347,7 @@ string SrsStunPacket::encode_username()
char buf[1460]; char buf[1460];
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(buf, sizeof(buf))); SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(buf, sizeof(buf)));
string username = remote_ufrag + ":" + local_ufrag; string username = remote_ufrag_ + ":" + local_ufrag_;
stream->write_2bytes(Username); stream->write_2bytes(Username);
stream->write_2bytes(username.size()); stream->write_2bytes(username.size());
@ -370,8 +370,8 @@ string SrsStunPacket::encode_mapped_address()
stream->write_2bytes(8); stream->write_2bytes(8);
stream->write_1bytes(0); // ignore this bytes stream->write_1bytes(0); // ignore this bytes
stream->write_1bytes(1); // ipv4 family stream->write_1bytes(1); // ipv4 family
stream->write_2bytes(mapped_port ^ (kStunMagicCookie >> 16)); stream->write_2bytes(mapped_port_ ^ (kStunMagicCookie >> 16));
stream->write_4bytes(mapped_address ^ kStunMagicCookie); stream->write_4bytes(mapped_address_ ^ kStunMagicCookie);
return string(stream->data(), stream->pos()); return string(stream->data(), stream->pos());
} }

View File

@ -60,16 +60,16 @@ enum SrsStunMessageAttribute {
class SrsStunPacket class SrsStunPacket
{ {
private: private:
uint16_t message_type; uint16_t message_type_;
std::string username; std::string username_;
std::string local_ufrag; std::string local_ufrag_;
std::string remote_ufrag; std::string remote_ufrag_;
std::string transcation_id; std::string transcation_id_;
uint32_t mapped_address; uint32_t mapped_address_;
uint16_t mapped_port; uint16_t mapped_port_;
bool use_candidate; bool use_candidate_;
bool ice_controlled; bool ice_controlled_;
bool ice_controlling; bool ice_controlling_;
public: public:
SrsStunPacket(); SrsStunPacket();

View File

@ -17,35 +17,35 @@ using namespace std;
SrsBasicRtmpClient::SrsBasicRtmpClient(string r, srs_utime_t ctm, srs_utime_t stm) SrsBasicRtmpClient::SrsBasicRtmpClient(string r, srs_utime_t ctm, srs_utime_t stm)
{ {
kbps = new SrsNetworkKbps(); kbps_ = new SrsNetworkKbps();
url = r; url_ = r;
connect_timeout = ctm; connect_timeout_ = ctm;
stream_timeout = stm; stream_timeout_ = stm;
req = new SrsRequest(); req_ = new SrsRequest();
srs_net_url_parse_rtmp_url(url, req->tcUrl, req->stream); srs_net_url_parse_rtmp_url(url_, req_->tcUrl_, req_->stream_);
srs_net_url_parse_tcurl(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param); srs_net_url_parse_tcurl(req_->tcUrl_, req_->schema_, req_->host_, req_->vhost_, req_->app_, req_->stream_, req_->port_, req_->param_);
transport = NULL; transport_ = NULL;
client = NULL; client_ = NULL;
stream_id = 0; stream_id_ = 0;
} }
SrsBasicRtmpClient::~SrsBasicRtmpClient() SrsBasicRtmpClient::~SrsBasicRtmpClient()
{ {
close(); close();
srs_freep(kbps); srs_freep(kbps_);
srs_freep(req); srs_freep(req_);
} }
SrsAmf0Object *SrsBasicRtmpClient::extra_args() SrsAmf0Object *SrsBasicRtmpClient::extra_args()
{ {
if (req->args == NULL) { if (req_->args_ == NULL) {
req->args = SrsAmf0Any::object(); req_->args_ = SrsAmf0Any::object();
} }
return req->args; return req_->args_;
} }
srs_error_t SrsBasicRtmpClient::connect() srs_error_t SrsBasicRtmpClient::connect()
@ -54,27 +54,27 @@ srs_error_t SrsBasicRtmpClient::connect()
close(); close();
transport = new SrsTcpClient(req->host, req->port, srs_utime_t(connect_timeout)); transport_ = new SrsTcpClient(req_->host_, req_->port_, srs_utime_t(connect_timeout_));
client = new SrsRtmpClient(transport); client_ = new SrsRtmpClient(transport_);
kbps->set_io(transport, transport); kbps_->set_io(transport_, transport_);
if ((err = transport->connect()) != srs_success) { if ((err = transport_->connect()) != srs_success) {
close(); close();
return srs_error_wrap(err, "connect"); return srs_error_wrap(err, "connect");
} }
client->set_recv_timeout(stream_timeout); client_->set_recv_timeout(stream_timeout_);
client->set_send_timeout(stream_timeout); client_->set_send_timeout(stream_timeout_);
// connect to vhost/app // connect to vhost/app
if ((err = client->handshake()) != srs_success) { if ((err = client_->handshake()) != srs_success) {
return srs_error_wrap(err, "handshake"); return srs_error_wrap(err, "handshake");
} }
if ((err = connect_app()) != srs_success) { if ((err = connect_app()) != srs_success) {
return srs_error_wrap(err, "connect app"); return srs_error_wrap(err, "connect app");
} }
if ((err = client->create_stream(stream_id)) != srs_success) { if ((err = client_->create_stream(stream_id_)) != srs_success) {
return srs_error_wrap(err, "create stream_id=%d", stream_id); return srs_error_wrap(err, "create stream_id=%d", stream_id_);
} }
return err; return err;
@ -82,9 +82,9 @@ srs_error_t SrsBasicRtmpClient::connect()
void SrsBasicRtmpClient::close() void SrsBasicRtmpClient::close()
{ {
kbps->set_io(NULL, NULL); kbps_->set_io(NULL, NULL);
srs_freep(client); srs_freep(client_);
srs_freep(transport); srs_freep(transport_);
} }
srs_error_t SrsBasicRtmpClient::connect_app() srs_error_t SrsBasicRtmpClient::connect_app()
@ -112,17 +112,17 @@ srs_error_t SrsBasicRtmpClient::do_connect_app(string local_ip, bool debug)
// generate the tcUrl // generate the tcUrl
std::string param = ""; std::string param = "";
std::string target_vhost = req->vhost; std::string target_vhost = req_->vhost_;
std::string tc_url = srs_net_url_encode_tcurl("rtmp", req->host, req->vhost, req->app, req->port); std::string tc_url = srs_net_url_encode_tcurl("rtmp", req_->host_, req_->vhost_, req_->app_, req_->port_);
// replace the tcUrl in request, // replace the tcUrl in request,
// which will replace the tc_url in client.connect_app(). // which will replace the tc_url in client.connect_app().
req->tcUrl = tc_url; req_->tcUrl_ = tc_url;
// upnode server identity will show in the connect_app of client. // upnode server identity will show in the connect_app of client.
// the debug_srs_upnode is config in vhost and default to true. // the debug_srs_upnode is config in vhost and default to true.
SrsServerInfo si; SrsServerInfo si;
if ((err = client->connect_app(req->app, tc_url, req, debug, &si)) != srs_success) { if ((err = client_->connect_app(req_->app_, tc_url, req_, debug, &si)) != srs_success) {
return srs_error_wrap(err, "connect app tcUrl=%s, debug=%d", tc_url.c_str(), debug); return srs_error_wrap(err, "connect app tcUrl=%s, debug=%d", tc_url.c_str(), debug);
} }
@ -134,7 +134,7 @@ srs_error_t SrsBasicRtmpClient::publish(int chunk_size, bool with_vhost, std::st
srs_error_t err = srs_success; srs_error_t err = srs_success;
// Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733 // Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733
string stream = srs_net_url_encode_stream(req->host, req->vhost, req->stream, req->param, with_vhost); string stream = srs_net_url_encode_stream(req_->host_, req_->vhost_, req_->stream_, req_->param_, with_vhost);
// Return the generated stream. // Return the generated stream.
if (pstream) { if (pstream) {
@ -142,8 +142,8 @@ srs_error_t SrsBasicRtmpClient::publish(int chunk_size, bool with_vhost, std::st
} }
// publish. // publish.
if ((err = client->publish(stream, stream_id, chunk_size)) != srs_success) { if ((err = client_->publish(stream, stream_id_, chunk_size)) != srs_success) {
return srs_error_wrap(err, "publish failed, stream=%s, stream_id=%d", stream.c_str(), stream_id); return srs_error_wrap(err, "publish failed, stream=%s, stream_id=%d", stream.c_str(), stream_id_);
} }
return err; return err;
@ -154,15 +154,15 @@ srs_error_t SrsBasicRtmpClient::play(int chunk_size, bool with_vhost, std::strin
srs_error_t err = srs_success; srs_error_t err = srs_success;
// Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733 // Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733
string stream = srs_net_url_encode_stream(req->host, req->vhost, req->stream, req->param, with_vhost); string stream = srs_net_url_encode_stream(req_->host_, req_->vhost_, req_->stream_, req_->param_, with_vhost);
// Return the generated stream. // Return the generated stream.
if (pstream) { if (pstream) {
*pstream = stream; *pstream = stream;
} }
if ((err = client->play(stream, stream_id, chunk_size)) != srs_success) { if ((err = client_->play(stream, stream_id_, chunk_size)) != srs_success) {
return srs_error_wrap(err, "connect with server failed, stream=%s, stream_id=%d", stream.c_str(), stream_id); return srs_error_wrap(err, "connect with server failed, stream=%s, stream_id=%d", stream.c_str(), stream_id_);
} }
return err; return err;
@ -170,58 +170,58 @@ srs_error_t SrsBasicRtmpClient::play(int chunk_size, bool with_vhost, std::strin
void SrsBasicRtmpClient::kbps_sample(const char *label, srs_utime_t age) void SrsBasicRtmpClient::kbps_sample(const char *label, srs_utime_t age)
{ {
kbps->sample(); kbps_->sample();
int sr = kbps->get_send_kbps(); int sr = kbps_->get_send_kbps();
int sr30s = kbps->get_send_kbps_30s(); int sr30s = kbps_->get_send_kbps_30s();
int sr5m = kbps->get_send_kbps_5m(); int sr5m = kbps_->get_send_kbps_5m();
int rr = kbps->get_recv_kbps(); int rr = kbps_->get_recv_kbps();
int rr30s = kbps->get_recv_kbps_30s(); int rr30s = kbps_->get_recv_kbps_30s();
int rr5m = kbps->get_recv_kbps_5m(); int rr5m = kbps_->get_recv_kbps_5m();
srs_trace("<- %s time=%" PRId64 ", okbps=%d,%d,%d, ikbps=%d,%d,%d", label, srsu2ms(age), sr, sr30s, sr5m, rr, rr30s, rr5m); srs_trace("<- %s time=%" PRId64 ", okbps=%d,%d,%d, ikbps=%d,%d,%d", label, srsu2ms(age), sr, sr30s, sr5m, rr, rr30s, rr5m);
} }
void SrsBasicRtmpClient::kbps_sample(const char *label, srs_utime_t age, int msgs) void SrsBasicRtmpClient::kbps_sample(const char *label, srs_utime_t age, int msgs)
{ {
kbps->sample(); kbps_->sample();
int sr = kbps->get_send_kbps(); int sr = kbps_->get_send_kbps();
int sr30s = kbps->get_send_kbps_30s(); int sr30s = kbps_->get_send_kbps_30s();
int sr5m = kbps->get_send_kbps_5m(); int sr5m = kbps_->get_send_kbps_5m();
int rr = kbps->get_recv_kbps(); int rr = kbps_->get_recv_kbps();
int rr30s = kbps->get_recv_kbps_30s(); int rr30s = kbps_->get_recv_kbps_30s();
int rr5m = kbps->get_recv_kbps_5m(); int rr5m = kbps_->get_recv_kbps_5m();
srs_trace("<- %s time=%" PRId64 ", msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d", label, srsu2ms(age), msgs, sr, sr30s, sr5m, rr, rr30s, rr5m); srs_trace("<- %s time=%" PRId64 ", msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d", label, srsu2ms(age), msgs, sr, sr30s, sr5m, rr, rr30s, rr5m);
} }
int SrsBasicRtmpClient::sid() int SrsBasicRtmpClient::sid()
{ {
return stream_id; return stream_id_;
} }
srs_error_t SrsBasicRtmpClient::recv_message(SrsRtmpCommonMessage **pmsg) srs_error_t SrsBasicRtmpClient::recv_message(SrsRtmpCommonMessage **pmsg)
{ {
return client->recv_message(pmsg); return client_->recv_message(pmsg);
} }
srs_error_t SrsBasicRtmpClient::decode_message(SrsRtmpCommonMessage *msg, SrsRtmpCommand **ppacket) srs_error_t SrsBasicRtmpClient::decode_message(SrsRtmpCommonMessage *msg, SrsRtmpCommand **ppacket)
{ {
return client->decode_message(msg, ppacket); return client_->decode_message(msg, ppacket);
} }
srs_error_t SrsBasicRtmpClient::send_and_free_messages(SrsMediaPacket **msgs, int nb_msgs) srs_error_t SrsBasicRtmpClient::send_and_free_messages(SrsMediaPacket **msgs, int nb_msgs)
{ {
return client->send_and_free_messages(msgs, nb_msgs, stream_id); return client_->send_and_free_messages(msgs, nb_msgs, stream_id_);
} }
srs_error_t SrsBasicRtmpClient::send_and_free_message(SrsMediaPacket *msg) srs_error_t SrsBasicRtmpClient::send_and_free_message(SrsMediaPacket *msg)
{ {
return client->send_and_free_message(msg, stream_id); return client_->send_and_free_message(msg, stream_id_);
} }
void SrsBasicRtmpClient::set_recv_timeout(srs_utime_t timeout) void SrsBasicRtmpClient::set_recv_timeout(srs_utime_t timeout)
{ {
transport->set_recv_timeout(timeout); transport_->set_recv_timeout(timeout);
} }

View File

@ -31,18 +31,18 @@ class SrsAmf0Object;
class SrsBasicRtmpClient class SrsBasicRtmpClient
{ {
private: private:
std::string url; std::string url_;
srs_utime_t connect_timeout; srs_utime_t connect_timeout_;
srs_utime_t stream_timeout; srs_utime_t stream_timeout_;
protected: protected:
ISrsRequest *req; ISrsRequest *req_;
private: private:
SrsTcpClient *transport; SrsTcpClient *transport_;
SrsRtmpClient *client; SrsRtmpClient *client_;
SrsNetworkKbps *kbps; SrsNetworkKbps *kbps_;
int stream_id; int stream_id_;
public: public:
// Constructor. // Constructor.

View File

@ -331,39 +331,39 @@ srs_error_t SrsDH::do_initialize()
return err; return err;
} }
key_block::key_block() SrsKeyBlock::SrsKeyBlock()
{ {
offset = (int32_t)srs_rand_integer(); offset_ = (int32_t)srs_rand_integer();
random0 = NULL; random0_ = NULL;
random1 = NULL; random1_ = NULL;
int valid_offset = calc_valid_offset(); int valid_offset = calc_valid_offset();
srs_assert(valid_offset >= 0); srs_assert(valid_offset >= 0);
random0_size = valid_offset; random0_size_ = valid_offset;
if (random0_size > 0) { if (random0_size_ > 0) {
random0 = new char[random0_size]; random0_ = new char[random0_size_];
srs_rand_gen_bytes(random0, random0_size); srs_rand_gen_bytes(random0_, random0_size_);
snprintf(random0, random0_size, "%s", RTMP_SIG_SRS_HANDSHAKE); snprintf(random0_, random0_size_, "%s", RTMP_SIG_SRS_HANDSHAKE);
} }
srs_rand_gen_bytes(key, sizeof(key)); srs_rand_gen_bytes(key_, sizeof(key_));
random1_size = 764 - valid_offset - 128 - 4; random1_size_ = 764 - valid_offset - 128 - 4;
if (random1_size > 0) { if (random1_size_ > 0) {
random1 = new char[random1_size]; random1_ = new char[random1_size_];
srs_rand_gen_bytes(random1, random1_size); srs_rand_gen_bytes(random1_, random1_size_);
snprintf(random1, random1_size, "%s", RTMP_SIG_SRS_HANDSHAKE); snprintf(random1_, random1_size_, "%s", RTMP_SIG_SRS_HANDSHAKE);
} }
} }
key_block::~key_block() SrsKeyBlock::~SrsKeyBlock()
{ {
srs_freepa(random0); srs_freepa(random0_);
srs_freepa(random1); srs_freepa(random1_);
} }
srs_error_t key_block::parse(SrsBuffer *stream) srs_error_t SrsKeyBlock::parse(SrsBuffer *stream)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -372,7 +372,7 @@ srs_error_t key_block::parse(SrsBuffer *stream)
// read the last offset first, 760-763 // read the last offset first, 760-763
stream->skip(764 - sizeof(int32_t)); stream->skip(764 - sizeof(int32_t));
offset = stream->read_4bytes(); offset_ = stream->read_4bytes();
// reset stream to read others. // reset stream to read others.
stream->skip(-764); stream->skip(-764);
@ -380,31 +380,31 @@ srs_error_t key_block::parse(SrsBuffer *stream)
int valid_offset = calc_valid_offset(); int valid_offset = calc_valid_offset();
srs_assert(valid_offset >= 0); srs_assert(valid_offset >= 0);
random0_size = valid_offset; random0_size_ = valid_offset;
if (random0_size > 0) { if (random0_size_ > 0) {
srs_freepa(random0); srs_freepa(random0_);
random0 = new char[random0_size]; random0_ = new char[random0_size_];
stream->read_bytes(random0, random0_size); stream->read_bytes(random0_, random0_size_);
} }
stream->read_bytes(key, 128); stream->read_bytes(key_, 128);
random1_size = 764 - valid_offset - 128 - 4; random1_size_ = 764 - valid_offset - 128 - 4;
if (random1_size > 0) { if (random1_size_ > 0) {
srs_freepa(random1); srs_freepa(random1_);
random1 = new char[random1_size]; random1_ = new char[random1_size_];
stream->read_bytes(random1, random1_size); stream->read_bytes(random1_, random1_size_);
} }
return err; return err;
} }
int key_block::calc_valid_offset() int SrsKeyBlock::calc_valid_offset()
{ {
int max_offset_size = 764 - 128 - 4; int max_offset_size = 764 - 128 - 4;
int valid_offset = 0; int valid_offset = 0;
uint8_t *pp = (uint8_t *)&offset; uint8_t *pp = (uint8_t *)&offset_;
valid_offset += *pp++; valid_offset += *pp++;
valid_offset += *pp++; valid_offset += *pp++;
valid_offset += *pp++; valid_offset += *pp++;
@ -413,75 +413,75 @@ int key_block::calc_valid_offset()
return valid_offset % max_offset_size; return valid_offset % max_offset_size;
} }
digest_block::digest_block() SrsDigestBlock::SrsDigestBlock()
{ {
offset = (int32_t)srs_rand_integer(); offset_ = (int32_t)srs_rand_integer();
random0 = NULL; random0_ = NULL;
random1 = NULL; random1_ = NULL;
int valid_offset = calc_valid_offset(); int valid_offset = calc_valid_offset();
srs_assert(valid_offset >= 0); srs_assert(valid_offset >= 0);
random0_size = valid_offset; random0_size_ = valid_offset;
if (random0_size > 0) { if (random0_size_ > 0) {
random0 = new char[random0_size]; random0_ = new char[random0_size_];
srs_rand_gen_bytes(random0, random0_size); srs_rand_gen_bytes(random0_, random0_size_);
snprintf(random0, random0_size, "%s", RTMP_SIG_SRS_HANDSHAKE); snprintf(random0_, random0_size_, "%s", RTMP_SIG_SRS_HANDSHAKE);
} }
srs_rand_gen_bytes(digest, sizeof(digest)); srs_rand_gen_bytes(digest_, sizeof(digest_));
random1_size = 764 - 4 - valid_offset - 32; random1_size_ = 764 - 4 - valid_offset - 32;
if (random1_size > 0) { if (random1_size_ > 0) {
random1 = new char[random1_size]; random1_ = new char[random1_size_];
srs_rand_gen_bytes(random1, random1_size); srs_rand_gen_bytes(random1_, random1_size_);
snprintf(random1, random1_size, "%s", RTMP_SIG_SRS_HANDSHAKE); snprintf(random1_, random1_size_, "%s", RTMP_SIG_SRS_HANDSHAKE);
} }
} }
digest_block::~digest_block() SrsDigestBlock::~SrsDigestBlock()
{ {
srs_freepa(random0); srs_freepa(random0_);
srs_freepa(random1); srs_freepa(random1_);
} }
srs_error_t digest_block::parse(SrsBuffer *stream) srs_error_t SrsDigestBlock::parse(SrsBuffer *stream)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
// the digest must be 764 bytes. // the digest must be 764 bytes.
srs_assert(stream->require(764)); srs_assert(stream->require(764));
offset = stream->read_4bytes(); offset_ = stream->read_4bytes();
int valid_offset = calc_valid_offset(); int valid_offset = calc_valid_offset();
srs_assert(valid_offset >= 0); srs_assert(valid_offset >= 0);
random0_size = valid_offset; random0_size_ = valid_offset;
if (random0_size > 0) { if (random0_size_ > 0) {
srs_freepa(random0); srs_freepa(random0_);
random0 = new char[random0_size]; random0_ = new char[random0_size_];
stream->read_bytes(random0, random0_size); stream->read_bytes(random0_, random0_size_);
} }
stream->read_bytes(digest, 32); stream->read_bytes(digest_, 32);
random1_size = 764 - 4 - valid_offset - 32; random1_size_ = 764 - 4 - valid_offset - 32;
if (random1_size > 0) { if (random1_size_ > 0) {
srs_freepa(random1); srs_freepa(random1_);
random1 = new char[random1_size]; random1_ = new char[random1_size_];
stream->read_bytes(random1, random1_size); stream->read_bytes(random1_, random1_size_);
} }
return err; return err;
} }
int digest_block::calc_valid_offset() int SrsDigestBlock::calc_valid_offset()
{ {
int max_offset_size = 764 - 32 - 4; int max_offset_size = 764 - 32 - 4;
int valid_offset = 0; int valid_offset = 0;
uint8_t *pp = (uint8_t *)&offset; uint8_t *pp = (uint8_t *)&offset_;
valid_offset += *pp++; valid_offset += *pp++;
valid_offset += *pp++; valid_offset += *pp++;
valid_offset += *pp++; valid_offset += *pp++;
@ -490,31 +490,31 @@ int digest_block::calc_valid_offset()
return valid_offset % max_offset_size; return valid_offset % max_offset_size;
} }
c1s1_strategy::c1s1_strategy() SrsC1S1Strategy::SrsC1S1Strategy()
{ {
} }
c1s1_strategy::~c1s1_strategy() SrsC1S1Strategy::~SrsC1S1Strategy()
{ {
} }
char *c1s1_strategy::get_digest() char *SrsC1S1Strategy::get_digest()
{ {
return digest.digest; return digest_.digest_;
} }
char *c1s1_strategy::get_key() char *SrsC1S1Strategy::get_key()
{ {
return key.key; return key_.key_;
} }
srs_error_t c1s1_strategy::dump(c1s1 *owner, char *_c1s1, int size) srs_error_t SrsC1S1Strategy::dump(SrsC1S1 *owner, char *_c1s1, int size)
{ {
srs_assert(size == 1536); srs_assert(size == 1536);
return copy_to(owner, _c1s1, size, true); return copy_to(owner, _c1s1, size, true);
} }
srs_error_t c1s1_strategy::c1_create(c1s1 *owner) srs_error_t SrsC1S1Strategy::c1_create(SrsC1S1 *owner)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -528,12 +528,12 @@ srs_error_t c1s1_strategy::c1_create(c1s1 *owner)
srs_assert(c1_digest_raw != NULL); srs_assert(c1_digest_raw != NULL);
SrsUniquePtr<char[]> c1_digest(c1_digest_raw); SrsUniquePtr<char[]> c1_digest(c1_digest_raw);
memcpy(digest.digest, c1_digest.get(), 32); memcpy(digest_.digest_, c1_digest.get(), 32);
return err; return err;
} }
srs_error_t c1s1_strategy::c1_validate_digest(c1s1 *owner, bool &is_valid) srs_error_t SrsC1S1Strategy::c1_validate_digest(SrsC1S1 *owner, bool &is_valid)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -546,12 +546,12 @@ srs_error_t c1s1_strategy::c1_validate_digest(c1s1 *owner, bool &is_valid)
srs_assert(c1_digest_raw != NULL); srs_assert(c1_digest_raw != NULL);
SrsUniquePtr<char[]> c1_digest(c1_digest_raw); SrsUniquePtr<char[]> c1_digest(c1_digest_raw);
is_valid = srs_bytes_equal(digest.digest, c1_digest.get(), 32); is_valid = srs_bytes_equal(digest_.digest_, c1_digest.get(), 32);
return err; return err;
} }
srs_error_t c1s1_strategy::s1_create(c1s1 *owner, c1s1 *c1) srs_error_t SrsC1S1Strategy::s1_create(SrsC1S1 *owner, SrsC1S1 *c1)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -564,7 +564,7 @@ srs_error_t c1s1_strategy::s1_create(c1s1 *owner, c1s1 *c1)
// directly generate the public key. // directly generate the public key.
int pkey_size = 128; int pkey_size = 128;
if ((err = dh.copy_shared_key(c1->get_key(), 128, key.key, pkey_size)) != srs_success) { if ((err = dh.copy_shared_key(c1->get_key(), 128, key_.key_, pkey_size)) != srs_success) {
return srs_error_wrap(err, "copy shared key"); return srs_error_wrap(err, "copy shared key");
} }
@ -581,12 +581,12 @@ srs_error_t c1s1_strategy::s1_create(c1s1 *owner, c1s1 *c1)
srs_assert(s1_digest_raw != NULL); srs_assert(s1_digest_raw != NULL);
SrsUniquePtr<char[]> s1_digest(s1_digest_raw); SrsUniquePtr<char[]> s1_digest(s1_digest_raw);
memcpy(digest.digest, s1_digest.get(), 32); memcpy(digest_.digest_, s1_digest.get(), 32);
return err; return err;
} }
srs_error_t c1s1_strategy::s1_validate_digest(c1s1 *owner, bool &is_valid) srs_error_t SrsC1S1Strategy::s1_validate_digest(SrsC1S1 *owner, bool &is_valid)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -599,12 +599,12 @@ srs_error_t c1s1_strategy::s1_validate_digest(c1s1 *owner, bool &is_valid)
srs_assert(s1_digest_raw != NULL); srs_assert(s1_digest_raw != NULL);
SrsUniquePtr<char[]> s1_digest(s1_digest_raw); SrsUniquePtr<char[]> s1_digest(s1_digest_raw);
is_valid = srs_bytes_equal(digest.digest, s1_digest.get(), 32); is_valid = srs_bytes_equal(digest_.digest_, s1_digest.get(), 32);
return err; return err;
} }
srs_error_t c1s1_strategy::calc_c1_digest(c1s1 *owner, char *&c1_digest) srs_error_t SrsC1S1Strategy::calc_c1_digest(SrsC1S1 *owner, char *&c1_digest)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -627,7 +627,7 @@ srs_error_t c1s1_strategy::calc_c1_digest(c1s1 *owner, char *&c1_digest)
return err; return err;
} }
srs_error_t c1s1_strategy::calc_s1_digest(c1s1 *owner, char *&s1_digest) srs_error_t SrsC1S1Strategy::calc_s1_digest(SrsC1S1 *owner, char *&s1_digest)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -650,43 +650,43 @@ srs_error_t c1s1_strategy::calc_s1_digest(c1s1 *owner, char *&s1_digest)
return err; return err;
} }
void c1s1_strategy::copy_time_version(SrsBuffer *stream, c1s1 *owner) void SrsC1S1Strategy::copy_time_version(SrsBuffer *stream, SrsC1S1 *owner)
{ {
srs_assert(stream->require(8)); srs_assert(stream->require(8));
// 4bytes time // 4bytes time
stream->write_4bytes(owner->time); stream->write_4bytes(owner->time_);
// 4bytes version // 4bytes version
stream->write_4bytes(owner->version); stream->write_4bytes(owner->version_);
} }
void c1s1_strategy::copy_key(SrsBuffer *stream) void SrsC1S1Strategy::copy_key(SrsBuffer *stream)
{ {
srs_assert(key.random0_size >= 0); srs_assert(key_.random0_size_ >= 0);
srs_assert(key.random1_size >= 0); srs_assert(key_.random1_size_ >= 0);
int total = key.random0_size + 128 + key.random1_size + 4; int total = key_.random0_size_ + 128 + key_.random1_size_ + 4;
srs_assert(stream->require(total)); srs_assert(stream->require(total));
// 764bytes key block // 764bytes key block
if (key.random0_size > 0) { if (key_.random0_size_ > 0) {
stream->write_bytes(key.random0, key.random0_size); stream->write_bytes(key_.random0_, key_.random0_size_);
} }
stream->write_bytes(key.key, 128); stream->write_bytes(key_.key_, 128);
if (key.random1_size > 0) { if (key_.random1_size_ > 0) {
stream->write_bytes(key.random1, key.random1_size); stream->write_bytes(key_.random1_, key_.random1_size_);
} }
stream->write_4bytes(key.offset); stream->write_4bytes(key_.offset_);
} }
void c1s1_strategy::copy_digest(SrsBuffer *stream, bool with_digest) void SrsC1S1Strategy::copy_digest(SrsBuffer *stream, bool with_digest)
{ {
srs_assert(key.random0_size >= 0); srs_assert(key_.random0_size_ >= 0);
srs_assert(key.random1_size >= 0); srs_assert(key_.random1_size_ >= 0);
int total = 4 + digest.random0_size + digest.random1_size; int total = 4 + digest_.random0_size_ + digest_.random1_size_;
if (with_digest) { if (with_digest) {
total += 32; total += 32;
} }
@ -694,38 +694,38 @@ void c1s1_strategy::copy_digest(SrsBuffer *stream, bool with_digest)
// 732bytes digest block without the 32bytes digest-data // 732bytes digest block without the 32bytes digest-data
// nbytes digest block part1 // nbytes digest block part1
stream->write_4bytes(digest.offset); stream->write_4bytes(digest_.offset_);
// digest random padding. // digest random padding.
if (digest.random0_size > 0) { if (digest_.random0_size_ > 0) {
stream->write_bytes(digest.random0, digest.random0_size); stream->write_bytes(digest_.random0_, digest_.random0_size_);
} }
// digest // digest
if (with_digest) { if (with_digest) {
stream->write_bytes(digest.digest, 32); stream->write_bytes(digest_.digest_, 32);
} }
// nbytes digest block part2 // nbytes digest block part2
if (digest.random1_size > 0) { if (digest_.random1_size_ > 0) {
stream->write_bytes(digest.random1, digest.random1_size); stream->write_bytes(digest_.random1_, digest_.random1_size_);
} }
} }
c1s1_strategy_schema0::c1s1_strategy_schema0() SrsC1S1StrategySchema0::SrsC1S1StrategySchema0()
{ {
} }
c1s1_strategy_schema0::~c1s1_strategy_schema0() SrsC1S1StrategySchema0::~SrsC1S1StrategySchema0()
{ {
} }
srs_schema_type c1s1_strategy_schema0::schema() srs_schema_type SrsC1S1StrategySchema0::schema()
{ {
return srs_schema0; return srs_schema0;
} }
srs_error_t c1s1_strategy_schema0::parse(char *_c1s1, int size) srs_error_t SrsC1S1StrategySchema0::parse(char *_c1s1, int size)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -734,7 +734,7 @@ srs_error_t c1s1_strategy_schema0::parse(char *_c1s1, int size)
if (true) { if (true) {
SrsBuffer stream(_c1s1 + 8, 764); SrsBuffer stream(_c1s1 + 8, 764);
if ((err = key.parse(&stream)) != srs_success) { if ((err = key_.parse(&stream)) != srs_success) {
return srs_error_wrap(err, "parse the c1 key"); return srs_error_wrap(err, "parse the c1 key");
} }
} }
@ -742,7 +742,7 @@ srs_error_t c1s1_strategy_schema0::parse(char *_c1s1, int size)
if (true) { if (true) {
SrsBuffer stream(_c1s1 + 8 + 764, 764); SrsBuffer stream(_c1s1 + 8 + 764, 764);
if ((err = digest.parse(&stream)) != srs_success) { if ((err = digest_.parse(&stream)) != srs_success) {
return srs_error_wrap(err, "parse the c1 digest"); return srs_error_wrap(err, "parse the c1 digest");
} }
} }
@ -750,7 +750,7 @@ srs_error_t c1s1_strategy_schema0::parse(char *_c1s1, int size)
return err; return err;
} }
srs_error_t c1s1_strategy_schema0::copy_to(c1s1 *owner, char *bytes, int size, bool with_digest) srs_error_t SrsC1S1StrategySchema0::copy_to(SrsC1S1 *owner, char *bytes, int size, bool with_digest)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -771,20 +771,20 @@ srs_error_t c1s1_strategy_schema0::copy_to(c1s1 *owner, char *bytes, int size, b
return err; return err;
} }
c1s1_strategy_schema1::c1s1_strategy_schema1() SrsC1S1StrategySchema1::SrsC1S1StrategySchema1()
{ {
} }
c1s1_strategy_schema1::~c1s1_strategy_schema1() SrsC1S1StrategySchema1::~SrsC1S1StrategySchema1()
{ {
} }
srs_schema_type c1s1_strategy_schema1::schema() srs_schema_type SrsC1S1StrategySchema1::schema()
{ {
return srs_schema1; return srs_schema1;
} }
srs_error_t c1s1_strategy_schema1::parse(char *_c1s1, int size) srs_error_t SrsC1S1StrategySchema1::parse(char *_c1s1, int size)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -793,7 +793,7 @@ srs_error_t c1s1_strategy_schema1::parse(char *_c1s1, int size)
if (true) { if (true) {
SrsBuffer stream(_c1s1 + 8, 764); SrsBuffer stream(_c1s1 + 8, 764);
if ((err = digest.parse(&stream)) != srs_success) { if ((err = digest_.parse(&stream)) != srs_success) {
return srs_error_wrap(err, "parse c1 digest"); return srs_error_wrap(err, "parse c1 digest");
} }
} }
@ -801,7 +801,7 @@ srs_error_t c1s1_strategy_schema1::parse(char *_c1s1, int size)
if (true) { if (true) {
SrsBuffer stream(_c1s1 + 8 + 764, 764); SrsBuffer stream(_c1s1 + 8 + 764, 764);
if ((err = key.parse(&stream)) != srs_success) { if ((err = key_.parse(&stream)) != srs_success) {
return srs_error_wrap(err, "parse c1 key"); return srs_error_wrap(err, "parse c1 key");
} }
} }
@ -809,7 +809,7 @@ srs_error_t c1s1_strategy_schema1::parse(char *_c1s1, int size)
return err; return err;
} }
srs_error_t c1s1_strategy_schema1::copy_to(c1s1 *owner, char *bytes, int size, bool with_digest) srs_error_t SrsC1S1StrategySchema1::copy_to(SrsC1S1 *owner, char *bytes, int size, bool with_digest)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -830,43 +830,43 @@ srs_error_t c1s1_strategy_schema1::copy_to(c1s1 *owner, char *bytes, int size, b
return err; return err;
} }
c1s1::c1s1() SrsC1S1::SrsC1S1()
{ {
payload = NULL; payload_ = NULL;
version = 0; version_ = 0;
time = 0; time_ = 0;
} }
c1s1::~c1s1() SrsC1S1::~SrsC1S1()
{ {
srs_freep(payload); srs_freep(payload_);
} }
srs_schema_type c1s1::schema() srs_schema_type SrsC1S1::schema()
{ {
srs_assert(payload != NULL); srs_assert(payload_ != NULL);
return payload->schema(); return payload_->schema();
} }
char *c1s1::get_digest() char *SrsC1S1::get_digest()
{ {
srs_assert(payload != NULL); srs_assert(payload_ != NULL);
return payload->get_digest(); return payload_->get_digest();
} }
char *c1s1::get_key() char *SrsC1S1::get_key()
{ {
srs_assert(payload != NULL); srs_assert(payload_ != NULL);
return payload->get_key(); return payload_->get_key();
} }
srs_error_t c1s1::dump(char *_c1s1, int size) srs_error_t SrsC1S1::dump(char *_c1s1, int size)
{ {
srs_assert(size == 1536); srs_assert(size == 1536);
srs_assert(payload != NULL); srs_assert(payload_ != NULL);
return payload->dump(this, _c1s1, size); return payload_->dump(this, _c1s1, size);
} }
srs_error_t c1s1::parse(char *_c1s1, int size, srs_schema_type schema) srs_error_t SrsC1S1::parse(char *_c1s1, int size, srs_schema_type schema)
{ {
srs_assert(size == 1536); srs_assert(size == 1536);
@ -876,109 +876,109 @@ srs_error_t c1s1::parse(char *_c1s1, int size, srs_schema_type schema)
SrsBuffer stream(_c1s1, size); SrsBuffer stream(_c1s1, size);
time = stream.read_4bytes(); time_ = stream.read_4bytes();
version = stream.read_4bytes(); // client c1 version version_ = stream.read_4bytes(); // client c1 version
srs_freep(payload); srs_freep(payload_);
if (schema == srs_schema0) { if (schema == srs_schema0) {
payload = new c1s1_strategy_schema0(); payload_ = new SrsC1S1StrategySchema0();
} else { } else {
payload = new c1s1_strategy_schema1(); payload_ = new SrsC1S1StrategySchema1();
} }
return payload->parse(_c1s1, size); return payload_->parse(_c1s1, size);
} }
srs_error_t c1s1::c1_create(srs_schema_type schema) srs_error_t SrsC1S1::c1_create(srs_schema_type schema)
{ {
if (schema != srs_schema0 && schema != srs_schema1) { if (schema != srs_schema0 && schema != srs_schema1) {
return srs_error_new(ERROR_RTMP_CH_SCHEMA, "create c1 failed. invalid schema=%d", schema); return srs_error_new(ERROR_RTMP_CH_SCHEMA, "create c1 failed. invalid schema=%d", schema);
} }
// client c1 time and version // client c1 time and version
time = (int32_t)::time(NULL); time_ = (int32_t)::time(NULL);
version = 0x80000702; // client c1 version version_ = 0x80000702; // client c1 version
// generate signature by schema // generate signature by schema
srs_freep(payload); srs_freep(payload_);
if (schema == srs_schema0) { if (schema == srs_schema0) {
payload = new c1s1_strategy_schema0(); payload_ = new SrsC1S1StrategySchema0();
} else { } else {
payload = new c1s1_strategy_schema1(); payload_ = new SrsC1S1StrategySchema1();
} }
return payload->c1_create(this); return payload_->c1_create(this);
} }
srs_error_t c1s1::c1_validate_digest(bool &is_valid) srs_error_t SrsC1S1::c1_validate_digest(bool &is_valid)
{ {
is_valid = false; is_valid = false;
srs_assert(payload); srs_assert(payload_);
return payload->c1_validate_digest(this, is_valid); return payload_->c1_validate_digest(this, is_valid);
} }
srs_error_t c1s1::s1_create(c1s1 *c1) srs_error_t SrsC1S1::s1_create(SrsC1S1 *c1)
{ {
if (c1->schema() != srs_schema0 && c1->schema() != srs_schema1) { if (c1->schema() != srs_schema0 && c1->schema() != srs_schema1) {
return srs_error_new(ERROR_RTMP_CH_SCHEMA, "create s1 failed. invalid schema=%d", c1->schema()); return srs_error_new(ERROR_RTMP_CH_SCHEMA, "create s1 failed. invalid schema=%d", c1->schema());
} }
time = ::time(NULL); time_ = ::time(NULL);
version = 0x01000504; // server s1 version version_ = 0x01000504; // server s1 version
srs_freep(payload); srs_freep(payload_);
if (c1->schema() == srs_schema0) { if (c1->schema() == srs_schema0) {
payload = new c1s1_strategy_schema0(); payload_ = new SrsC1S1StrategySchema0();
} else { } else {
payload = new c1s1_strategy_schema1(); payload_ = new SrsC1S1StrategySchema1();
} }
return payload->s1_create(this, c1); return payload_->s1_create(this, c1);
} }
srs_error_t c1s1::s1_validate_digest(bool &is_valid) srs_error_t SrsC1S1::s1_validate_digest(bool &is_valid)
{ {
is_valid = false; is_valid = false;
srs_assert(payload); srs_assert(payload_);
return payload->s1_validate_digest(this, is_valid); return payload_->s1_validate_digest(this, is_valid);
} }
c2s2::c2s2() SrsC2S2::SrsC2S2()
{ {
srs_rand_gen_bytes(random, 1504); srs_rand_gen_bytes(random_, 1504);
int size = snprintf(random, 1504, "%s", RTMP_SIG_SRS_HANDSHAKE); int size = snprintf(random_, 1504, "%s", RTMP_SIG_SRS_HANDSHAKE);
srs_assert(size > 0 && size < 1504); srs_assert(size > 0 && size < 1504);
snprintf(random + 1504 - size, size, "%s", RTMP_SIG_SRS_HANDSHAKE); snprintf(random_ + 1504 - size, size, "%s", RTMP_SIG_SRS_HANDSHAKE);
srs_rand_gen_bytes(digest, 32); srs_rand_gen_bytes(digest_, 32);
} }
c2s2::~c2s2() SrsC2S2::~SrsC2S2()
{ {
} }
srs_error_t c2s2::dump(char *_c2s2, int size) srs_error_t SrsC2S2::dump(char *_c2s2, int size)
{ {
srs_assert(size == 1536); srs_assert(size == 1536);
memcpy(_c2s2, random, 1504); memcpy(_c2s2, random_, 1504);
memcpy(_c2s2 + 1504, digest, 32); memcpy(_c2s2 + 1504, digest_, 32);
return srs_success; return srs_success;
} }
srs_error_t c2s2::parse(char *_c2s2, int size) srs_error_t SrsC2S2::parse(char *_c2s2, int size)
{ {
srs_assert(size == 1536); srs_assert(size == 1536);
memcpy(random, _c2s2, 1504); memcpy(random_, _c2s2, 1504);
memcpy(digest, _c2s2 + 1504, 32); memcpy(digest_, _c2s2 + 1504, 32);
return srs_success; return srs_success;
} }
srs_error_t c2s2::c2_create(c1s1 *s1) srs_error_t SrsC2S2::c2_create(SrsC1S1 *s1)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -988,16 +988,16 @@ srs_error_t c2s2::c2_create(c1s1 *s1)
} }
char _digest[SRS_OpensslHashSize]; char _digest[SRS_OpensslHashSize];
if ((err = openssl_HMACsha256(temp_key, 32, random, 1504, _digest)) != srs_success) { if ((err = openssl_HMACsha256(temp_key, 32, random_, 1504, _digest)) != srs_success) {
return srs_error_wrap(err, "create c2 digest"); return srs_error_wrap(err, "create c2 digest");
} }
memcpy(digest, _digest, 32); memcpy(digest_, _digest, 32);
return err; return err;
} }
srs_error_t c2s2::c2_validate(c1s1 *s1, bool &is_valid) srs_error_t SrsC2S2::c2_validate(SrsC1S1 *s1, bool &is_valid)
{ {
is_valid = false; is_valid = false;
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -1008,16 +1008,16 @@ srs_error_t c2s2::c2_validate(c1s1 *s1, bool &is_valid)
} }
char _digest[SRS_OpensslHashSize]; char _digest[SRS_OpensslHashSize];
if ((err = openssl_HMACsha256(temp_key, 32, random, 1504, _digest)) != srs_success) { if ((err = openssl_HMACsha256(temp_key, 32, random_, 1504, _digest)) != srs_success) {
return srs_error_wrap(err, "create c2 digest"); return srs_error_wrap(err, "create c2 digest");
} }
is_valid = srs_bytes_equal(digest, _digest, 32); is_valid = srs_bytes_equal(digest_, _digest, 32);
return err; return err;
} }
srs_error_t c2s2::s2_create(c1s1 *c1) srs_error_t SrsC2S2::s2_create(SrsC1S1 *c1)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -1027,16 +1027,16 @@ srs_error_t c2s2::s2_create(c1s1 *c1)
} }
char _digest[SRS_OpensslHashSize]; char _digest[SRS_OpensslHashSize];
if ((err = openssl_HMACsha256(temp_key, 32, random, 1504, _digest)) != srs_success) { if ((err = openssl_HMACsha256(temp_key, 32, random_, 1504, _digest)) != srs_success) {
return srs_error_wrap(err, "create s2 digest"); return srs_error_wrap(err, "create s2 digest");
} }
memcpy(digest, _digest, 32); memcpy(digest_, _digest, 32);
return err; return err;
} }
srs_error_t c2s2::s2_validate(c1s1 *c1, bool &is_valid) srs_error_t SrsC2S2::s2_validate(SrsC1S1 *c1, bool &is_valid)
{ {
is_valid = false; is_valid = false;
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -1047,11 +1047,11 @@ srs_error_t c2s2::s2_validate(c1s1 *c1, bool &is_valid)
} }
char _digest[SRS_OpensslHashSize]; char _digest[SRS_OpensslHashSize];
if ((err = openssl_HMACsha256(temp_key, 32, random, 1504, _digest)) != srs_success) { if ((err = openssl_HMACsha256(temp_key, 32, random_, 1504, _digest)) != srs_success) {
return srs_error_wrap(err, "create s2 digest"); return srs_error_wrap(err, "create s2 digest");
} }
is_valid = srs_bytes_equal(digest, _digest, 32); is_valid = srs_bytes_equal(digest_, _digest, 32);
return err; return err;
} }
@ -1076,15 +1076,15 @@ srs_error_t SrsSimpleHandshake::handshake_with_client(SrsHandshakeBytes *hs_byte
} }
// plain text required. // plain text required.
if (hs_bytes->c0c1[0] != 0x03) { if (hs_bytes->c0c1_[0] != 0x03) {
return srs_error_new(ERROR_RTMP_PLAIN_REQUIRED, "only support rtmp plain text, version=%X", (uint8_t)hs_bytes->c0c1[0]); return srs_error_new(ERROR_RTMP_PLAIN_REQUIRED, "only support rtmp plain text, version=%X", (uint8_t)hs_bytes->c0c1_[0]);
} }
if ((err = hs_bytes->create_s0s1s2(hs_bytes->c0c1 + 1)) != srs_success) { if ((err = hs_bytes->create_s0s1s2(hs_bytes->c0c1_ + 1)) != srs_success) {
return srs_error_wrap(err, "create s0s1s2"); return srs_error_wrap(err, "create s0s1s2");
} }
if ((err = io->write(hs_bytes->s0s1s2, 3073, &nsize)) != srs_success) { if ((err = io->write(hs_bytes->s0s1s2_, 3073, &nsize)) != srs_success) {
return srs_error_wrap(err, "write s0s1s2"); return srs_error_wrap(err, "write s0s1s2");
} }
@ -1108,7 +1108,7 @@ srs_error_t SrsSimpleHandshake::handshake_with_server(SrsHandshakeBytes *hs_byte
return srs_error_wrap(err, "create c0c1"); return srs_error_wrap(err, "create c0c1");
} }
if ((err = io->write(hs_bytes->c0c1, 1537, &nsize)) != srs_success) { if ((err = io->write(hs_bytes->c0c1_, 1537, &nsize)) != srs_success) {
return srs_error_wrap(err, "write c0c1"); return srs_error_wrap(err, "write c0c1");
} }
@ -1117,8 +1117,8 @@ srs_error_t SrsSimpleHandshake::handshake_with_server(SrsHandshakeBytes *hs_byte
} }
// plain text required. // plain text required.
if (hs_bytes->s0s1s2[0] != 0x03) { if (hs_bytes->s0s1s2_[0] != 0x03) {
return srs_error_new(ERROR_RTMP_HANDSHAKE, "handshake failed, plain text required, version=%X", (uint8_t)hs_bytes->s0s1s2[0]); return srs_error_new(ERROR_RTMP_HANDSHAKE, "handshake failed, plain text required, version=%X", (uint8_t)hs_bytes->s0s1s2_[0]);
} }
if ((err = hs_bytes->create_c2()) != srs_success) { if ((err = hs_bytes->create_c2()) != srs_success) {
@ -1127,9 +1127,9 @@ srs_error_t SrsSimpleHandshake::handshake_with_server(SrsHandshakeBytes *hs_byte
// for simple handshake, copy s1 to c2. // for simple handshake, copy s1 to c2.
// @see https://github.com/ossrs/srs/issues/418 // @see https://github.com/ossrs/srs/issues/418
memcpy(hs_bytes->c2, hs_bytes->s0s1s2 + 1, 1536); memcpy(hs_bytes->c2_, hs_bytes->s0s1s2_ + 1, 1536);
if ((err = io->write(hs_bytes->c2, 1536, &nsize)) != srs_success) { if ((err = io->write(hs_bytes->c2_, 1536, &nsize)) != srs_success) {
return srs_error_wrap(err, "write c2"); return srs_error_wrap(err, "write c2");
} }
@ -1157,10 +1157,10 @@ srs_error_t SrsComplexHandshake::handshake_with_client(SrsHandshakeBytes *hs_byt
} }
// decode c1 // decode c1
c1s1 c1; SrsC1S1 c1;
// try schema0. // try schema0.
// @remark, use schema0 to make flash player happy. // @remark, use schema0 to make flash player happy.
if ((err = c1.parse(hs_bytes->c0c1 + 1, 1536, srs_schema0)) != srs_success) { if ((err = c1.parse(hs_bytes->c0c1_ + 1, 1536, srs_schema0)) != srs_success) {
return srs_error_wrap(err, "parse c1, schema=%d", srs_schema0); return srs_error_wrap(err, "parse c1, schema=%d", srs_schema0);
} }
// try schema1 // try schema1
@ -1168,7 +1168,7 @@ srs_error_t SrsComplexHandshake::handshake_with_client(SrsHandshakeBytes *hs_byt
if ((err = c1.c1_validate_digest(is_valid)) != srs_success || !is_valid) { if ((err = c1.c1_validate_digest(is_valid)) != srs_success || !is_valid) {
srs_freep(err); srs_freep(err);
if ((err = c1.parse(hs_bytes->c0c1 + 1, 1536, srs_schema1)) != srs_success) { if ((err = c1.parse(hs_bytes->c0c1_ + 1, 1536, srs_schema1)) != srs_success) {
return srs_error_wrap(err, "parse c0c1, schame=%d", srs_schema1); return srs_error_wrap(err, "parse c0c1, schame=%d", srs_schema1);
} }
@ -1179,7 +1179,7 @@ srs_error_t SrsComplexHandshake::handshake_with_client(SrsHandshakeBytes *hs_byt
} }
// encode s1 // encode s1
c1s1 s1; SrsC1S1 s1;
if ((err = s1.s1_create(&c1)) != srs_success) { if ((err = s1.s1_create(&c1)) != srs_success) {
return srs_error_wrap(err, "create s1 from c1"); return srs_error_wrap(err, "create s1 from c1");
} }
@ -1189,7 +1189,7 @@ srs_error_t SrsComplexHandshake::handshake_with_client(SrsHandshakeBytes *hs_byt
return srs_error_new(ERROR_RTMP_TRY_SIMPLE_HS, "verify s1 failed, try simple handshake"); return srs_error_new(ERROR_RTMP_TRY_SIMPLE_HS, "verify s1 failed, try simple handshake");
} }
c2s2 s2; SrsC2S2 s2;
if ((err = s2.s2_create(&c1)) != srs_success) { if ((err = s2.s2_create(&c1)) != srs_success) {
return srs_error_wrap(err, "create s2 from c1"); return srs_error_wrap(err, "create s2 from c1");
} }
@ -1203,13 +1203,13 @@ srs_error_t SrsComplexHandshake::handshake_with_client(SrsHandshakeBytes *hs_byt
if ((err = hs_bytes->create_s0s1s2()) != srs_success) { if ((err = hs_bytes->create_s0s1s2()) != srs_success) {
return srs_error_wrap(err, "create s0s1s2"); return srs_error_wrap(err, "create s0s1s2");
} }
if ((err = s1.dump(hs_bytes->s0s1s2 + 1, 1536)) != srs_success) { if ((err = s1.dump(hs_bytes->s0s1s2_ + 1, 1536)) != srs_success) {
return srs_error_wrap(err, "dump s1"); return srs_error_wrap(err, "dump s1");
} }
if ((err = s2.dump(hs_bytes->s0s1s2 + 1537, 1536)) != srs_success) { if ((err = s2.dump(hs_bytes->s0s1s2_ + 1537, 1536)) != srs_success) {
return srs_error_wrap(err, "dump s2"); return srs_error_wrap(err, "dump s2");
} }
if ((err = io->write(hs_bytes->s0s1s2, 3073, &nsize)) != srs_success) { if ((err = io->write(hs_bytes->s0s1s2_, 3073, &nsize)) != srs_success) {
return srs_error_wrap(err, "write s0s1s2"); return srs_error_wrap(err, "write s0s1s2");
} }
@ -1217,8 +1217,8 @@ srs_error_t SrsComplexHandshake::handshake_with_client(SrsHandshakeBytes *hs_byt
if ((err = hs_bytes->read_c2(io)) != srs_success) { if ((err = hs_bytes->read_c2(io)) != srs_success) {
return srs_error_wrap(err, "read c2"); return srs_error_wrap(err, "read c2");
} }
c2s2 c2; SrsC2S2 c2;
if ((err = c2.parse(hs_bytes->c2, 1536)) != srs_success) { if ((err = c2.parse(hs_bytes->c2_, 1536)) != srs_success) {
return srs_error_wrap(err, "parse c2"); return srs_error_wrap(err, "parse c2");
} }
@ -1243,12 +1243,12 @@ srs_error_t SrsComplexHandshake::handshake_with_server(SrsHandshakeBytes *hs_byt
} }
// sign c1 // sign c1
c1s1 c1; SrsC1S1 c1;
// @remark, FMS requires the schema1(digest-key), or connect failed. // @remark, FMS requires the schema1(digest-key), or connect failed.
if ((err = c1.c1_create(srs_schema1)) != srs_success) { if ((err = c1.c1_create(srs_schema1)) != srs_success) {
return srs_error_wrap(err, "create c1"); return srs_error_wrap(err, "create c1");
} }
if ((err = c1.dump(hs_bytes->c0c1 + 1, 1536)) != srs_success) { if ((err = c1.dump(hs_bytes->c0c1_ + 1, 1536)) != srs_success) {
return srs_error_wrap(err, "dump c1"); return srs_error_wrap(err, "dump c1");
} }
@ -1259,7 +1259,7 @@ srs_error_t SrsComplexHandshake::handshake_with_server(SrsHandshakeBytes *hs_byt
return srs_error_new(ERROR_RTMP_TRY_SIMPLE_HS, "try simple handshake"); return srs_error_new(ERROR_RTMP_TRY_SIMPLE_HS, "try simple handshake");
} }
if ((err = io->write(hs_bytes->c0c1, 1537, &nsize)) != srs_success) { if ((err = io->write(hs_bytes->c0c1_, 1537, &nsize)) != srs_success) {
return srs_error_wrap(err, "write c0c1"); return srs_error_wrap(err, "write c0c1");
} }
@ -1269,13 +1269,13 @@ srs_error_t SrsComplexHandshake::handshake_with_server(SrsHandshakeBytes *hs_byt
} }
// plain text required. // plain text required.
if (hs_bytes->s0s1s2[0] != 0x03) { if (hs_bytes->s0s1s2_[0] != 0x03) {
return srs_error_new(ERROR_RTMP_HANDSHAKE, "handshake failed, plain text required, version=%X", (uint8_t)hs_bytes->s0s1s2[0]); return srs_error_new(ERROR_RTMP_HANDSHAKE, "handshake failed, plain text required, version=%X", (uint8_t)hs_bytes->s0s1s2_[0]);
} }
// verify s1s2 // verify s1s2
c1s1 s1; SrsC1S1 s1;
if ((err = s1.parse(hs_bytes->s0s1s2 + 1, 1536, c1.schema())) != srs_success) { if ((err = s1.parse(hs_bytes->s0s1s2_ + 1, 1536, c1.schema())) != srs_success) {
return srs_error_wrap(err, "parse s1"); return srs_error_wrap(err, "parse s1");
} }
@ -1288,15 +1288,15 @@ srs_error_t SrsComplexHandshake::handshake_with_server(SrsHandshakeBytes *hs_byt
return srs_error_wrap(err, "create c2"); return srs_error_wrap(err, "create c2");
} }
c2s2 c2; SrsC2S2 c2;
if ((err = c2.c2_create(&s1)) != srs_success) { if ((err = c2.c2_create(&s1)) != srs_success) {
return srs_error_wrap(err, "create c2"); return srs_error_wrap(err, "create c2");
} }
if ((err = c2.dump(hs_bytes->c2, 1536)) != srs_success) { if ((err = c2.dump(hs_bytes->c2_, 1536)) != srs_success) {
return srs_error_wrap(err, "dump c2"); return srs_error_wrap(err, "dump c2");
} }
if ((err = io->write(hs_bytes->c2, 1536, &nsize)) != srs_success) { if ((err = io->write(hs_bytes->c2_, 1536, &nsize)) != srs_success) {
return srs_error_wrap(err, "write c2"); return srs_error_wrap(err, "write c2");
} }

View File

@ -88,26 +88,26 @@ enum srs_schema_type {
// random-data: (764-offset-128-4)bytes // random-data: (764-offset-128-4)bytes
// offset: 4bytes // offset: 4bytes
// @see also: http://blog.csdn.net/win_lin/article/details/13006803 // @see also: http://blog.csdn.net/win_lin/article/details/13006803
class key_block class SrsKeyBlock
{ {
public: public:
// (offset)bytes // (offset)bytes
char *random0; char *random0_;
int random0_size; int random0_size_;
// 128bytes // 128bytes
char key[128]; char key_[128];
// (764-offset-128-4)bytes // (764-offset-128-4)bytes
char *random1; char *random1_;
int random1_size; int random1_size_;
// 4bytes // 4bytes
int32_t offset; int32_t offset_;
public: public:
key_block(); SrsKeyBlock();
virtual ~key_block(); virtual ~SrsKeyBlock();
public: public:
// Parse key block from c1s1. // Parse key block from c1s1.
@ -127,26 +127,26 @@ private:
// digest-data: 32bytes // digest-data: 32bytes
// random-data: (764-4-offset-32)bytes // random-data: (764-4-offset-32)bytes
// @see also: http://blog.csdn.net/win_lin/article/details/13006803 // @see also: http://blog.csdn.net/win_lin/article/details/13006803
class digest_block class SrsDigestBlock
{ {
public: public:
// 4bytes // 4bytes
int32_t offset; int32_t offset_;
// (offset)bytes // (offset)bytes
char *random0; char *random0_;
int random0_size; int random0_size_;
// 32bytes // 32bytes
char digest[32]; char digest_[32];
// (764-4-offset-32)bytes // (764-4-offset-32)bytes
char *random1; char *random1_;
int random1_size; int random1_size_;
public: public:
digest_block(); SrsDigestBlock();
virtual ~digest_block(); virtual ~SrsDigestBlock();
public: public:
// Parse digest block from c1s1. // Parse digest block from c1s1.
@ -160,20 +160,20 @@ private:
int calc_valid_offset(); int calc_valid_offset();
}; };
class c1s1; class SrsC1S1;
// The c1s1 strategy, use schema0 or schema1. // The c1s1 strategy, use schema0 or schema1.
// The template method class to defines common behaviors, // The template method class to defines common behaviors,
// while the concrete class to implements in schema0 or schema1. // while the concrete class to implements in schema0 or schema1.
class c1s1_strategy class SrsC1S1Strategy
{ {
protected: protected:
key_block key; SrsKeyBlock key_;
digest_block digest; SrsDigestBlock digest_;
public: public:
c1s1_strategy(); SrsC1S1Strategy();
virtual ~c1s1_strategy(); virtual ~SrsC1S1Strategy();
public: public:
// Get the scema. // Get the scema.
@ -184,7 +184,7 @@ public:
virtual char *get_key(); virtual char *get_key();
// Copy to bytes. // Copy to bytes.
// @param size must be 1536. // @param size must be 1536.
virtual srs_error_t dump(c1s1 *owner, char *_c1s1, int size); virtual srs_error_t dump(SrsC1S1 *owner, char *_c1s1, int size);
// For server: parse the c1s1, discovery the key and digest by schema. // For server: parse the c1s1, discovery the key and digest by schema.
// use the c1_validate_digest() to valid the digest of c1. // use the c1_validate_digest() to valid the digest of c1.
virtual srs_error_t parse(char *_c1s1, int size) = 0; virtual srs_error_t parse(char *_c1s1, int size) = 0;
@ -203,9 +203,9 @@ public:
// schema = choose schema0 or schema1 // schema = choose schema0 or schema1
// digest-data = calc_c1_digest(c1, schema) // digest-data = calc_c1_digest(c1, schema)
// copy digest-data to c1 // copy digest-data to c1
virtual srs_error_t c1_create(c1s1 *owner); virtual srs_error_t c1_create(SrsC1S1 *owner);
// For server: validate the parsed c1 schema // For server: validate the parsed c1 schema
virtual srs_error_t c1_validate_digest(c1s1 *owner, bool &is_valid); virtual srs_error_t c1_validate_digest(SrsC1S1 *owner, bool &is_valid);
// For server: create and sign the s1 from c1. // For server: create and sign the s1 from c1.
// // decode c1 try schema0 then schema1 // // decode c1 try schema0 then schema1
// c1-digest-data = get-c1-digest-data(schema0) // c1-digest-data = get-c1-digest-data(schema0)
@ -231,20 +231,20 @@ public:
// s1-digest-data = HMACsha256(c1s1-joined, FMSKey, 36) // s1-digest-data = HMACsha256(c1s1-joined, FMSKey, 36)
// copy s1-digest-data and s1-key-data to s1. // copy s1-digest-data and s1-key-data to s1.
// @param c1, to get the peer_pub_key of client. // @param c1, to get the peer_pub_key of client.
virtual srs_error_t s1_create(c1s1 *owner, c1s1 *c1); virtual srs_error_t s1_create(SrsC1S1 *owner, SrsC1S1 *c1);
// For server: validate the parsed s1 schema // For server: validate the parsed s1 schema
virtual srs_error_t s1_validate_digest(c1s1 *owner, bool &is_valid); virtual srs_error_t s1_validate_digest(SrsC1S1 *owner, bool &is_valid);
public: public:
// Calculate the digest for c1 // Calculate the digest for c1
virtual srs_error_t calc_c1_digest(c1s1 *owner, char *&c1_digest); virtual srs_error_t calc_c1_digest(SrsC1S1 *owner, char *&c1_digest);
// Calculate the digest for s1 // Calculate the digest for s1
virtual srs_error_t calc_s1_digest(c1s1 *owner, char *&s1_digest); virtual srs_error_t calc_s1_digest(SrsC1S1 *owner, char *&s1_digest);
// Copy whole c1s1 to bytes. // Copy whole c1s1 to bytes.
// @param size must always be 1536 with digest, and 1504 without digest. // @param size must always be 1536 with digest, and 1504 without digest.
virtual srs_error_t copy_to(c1s1 *owner, char *bytes, int size, bool with_digest) = 0; virtual srs_error_t copy_to(SrsC1S1 *owner, char *bytes, int size, bool with_digest) = 0;
// Copy time and version to stream. // Copy time and version to stream.
virtual void copy_time_version(SrsBuffer *stream, c1s1 *owner); virtual void copy_time_version(SrsBuffer *stream, SrsC1S1 *owner);
// Copy key to stream. // Copy key to stream.
virtual void copy_key(SrsBuffer *stream); virtual void copy_key(SrsBuffer *stream);
// Copy digest to stream. // Copy digest to stream.
@ -254,35 +254,35 @@ public:
// The c1s1 schema0 // The c1s1 schema0
// key: 764bytes // key: 764bytes
// digest: 764bytes // digest: 764bytes
class c1s1_strategy_schema0 : public c1s1_strategy class SrsC1S1StrategySchema0 : public SrsC1S1Strategy
{ {
public: public:
c1s1_strategy_schema0(); SrsC1S1StrategySchema0();
virtual ~c1s1_strategy_schema0(); virtual ~SrsC1S1StrategySchema0();
public: public:
virtual srs_schema_type schema(); virtual srs_schema_type schema();
virtual srs_error_t parse(char *_c1s1, int size); virtual srs_error_t parse(char *_c1s1, int size);
public: public:
virtual srs_error_t copy_to(c1s1 *owner, char *bytes, int size, bool with_digest); virtual srs_error_t copy_to(SrsC1S1 *owner, char *bytes, int size, bool with_digest);
}; };
// The c1s1 schema1 // The c1s1 schema1
// digest: 764bytes // digest: 764bytes
// key: 764bytes // key: 764bytes
class c1s1_strategy_schema1 : public c1s1_strategy class SrsC1S1StrategySchema1 : public SrsC1S1Strategy
{ {
public: public:
c1s1_strategy_schema1(); SrsC1S1StrategySchema1();
virtual ~c1s1_strategy_schema1(); virtual ~SrsC1S1StrategySchema1();
public: public:
virtual srs_schema_type schema(); virtual srs_schema_type schema();
virtual srs_error_t parse(char *_c1s1, int size); virtual srs_error_t parse(char *_c1s1, int size);
public: public:
virtual srs_error_t copy_to(c1s1 *owner, char *bytes, int size, bool with_digest); virtual srs_error_t copy_to(SrsC1S1 *owner, char *bytes, int size, bool with_digest);
}; };
// The c1s1 schema0 // The c1s1 schema0
@ -296,19 +296,19 @@ public:
// digest: 764bytes // digest: 764bytes
// key: 764bytes // key: 764bytes
// @see also: http://blog.csdn.net/win_lin/article/details/13006803 // @see also: http://blog.csdn.net/win_lin/article/details/13006803
class c1s1 class SrsC1S1
{ {
public: public:
// 4bytes // 4bytes
int32_t time; int32_t time_;
// 4bytes // 4bytes
int32_t version; int32_t version_;
// 764bytes+764bytes // 764bytes+764bytes
c1s1_strategy *payload; SrsC1S1Strategy *payload_;
public: public:
c1s1(); SrsC1S1();
virtual ~c1s1(); virtual ~SrsC1S1();
public: public:
// Get the scema. // Get the scema.
@ -371,7 +371,7 @@ public:
// get c1s1-joined by specified schema // get c1s1-joined by specified schema
// s1-digest-data = HMACsha256(c1s1-joined, FMSKey, 36) // s1-digest-data = HMACsha256(c1s1-joined, FMSKey, 36)
// copy s1-digest-data and s1-key-data to s1. // copy s1-digest-data and s1-key-data to s1.
virtual srs_error_t s1_create(c1s1 *c1); virtual srs_error_t s1_create(SrsC1S1 *c1);
// For server: validate the parsed s1 schema // For server: validate the parsed s1 schema
virtual srs_error_t s1_validate_digest(bool &is_valid); virtual srs_error_t s1_validate_digest(bool &is_valid);
}; };
@ -380,15 +380,15 @@ public:
// random-data: 1504bytes // random-data: 1504bytes
// digest-data: 32bytes // digest-data: 32bytes
// @see also: http://blog.csdn.net/win_lin/article/details/13006803 // @see also: http://blog.csdn.net/win_lin/article/details/13006803
class c2s2 class SrsC2S2
{ {
public: public:
char random[1504]; char random_[1504];
char digest[32]; char digest_[32];
public: public:
c2s2(); SrsC2S2();
virtual ~c2s2(); virtual ~SrsC2S2();
public: public:
// Copy to bytes. // Copy to bytes.
@ -405,10 +405,10 @@ public:
// // client generate C2, or server valid C2 // // client generate C2, or server valid C2
// temp-key = HMACsha256(s1-digest, FPKey, 62) // temp-key = HMACsha256(s1-digest, FPKey, 62)
// c2-digest-data = HMACsha256(c2-random-data, temp-key, 32) // c2-digest-data = HMACsha256(c2-random-data, temp-key, 32)
virtual srs_error_t c2_create(c1s1 *s1); virtual srs_error_t c2_create(SrsC1S1 *s1);
// Validate the c2 from client. // Validate the c2 from client.
virtual srs_error_t c2_validate(c1s1 *s1, bool &is_valid); virtual srs_error_t c2_validate(SrsC1S1 *s1, bool &is_valid);
public: public:
// Create s2. // Create s2.
@ -417,10 +417,10 @@ public:
// For server generate S2, or client valid S2 // For server generate S2, or client valid S2
// temp-key = HMACsha256(c1-digest, FMSKey, 68) // temp-key = HMACsha256(c1-digest, FMSKey, 68)
// s2-digest-data = HMACsha256(s2-random-data, temp-key, 32) // s2-digest-data = HMACsha256(s2-random-data, temp-key, 32)
virtual srs_error_t s2_create(c1s1 *c1); virtual srs_error_t s2_create(SrsC1S1 *c1);
// Validate the s2 from server. // Validate the s2 from server.
virtual srs_error_t s2_validate(c1s1 *c1, bool &is_valid); virtual srs_error_t s2_validate(SrsC1S1 *c1, bool &is_valid);
}; };
} // namespace srs_internal } // namespace srs_internal

View File

@ -12,8 +12,8 @@ SrsMessageArray::SrsMessageArray(int max_msgs)
{ {
srs_assert(max_msgs > 0); srs_assert(max_msgs > 0);
msgs = new SrsMediaPacket *[max_msgs]; msgs_ = new SrsMediaPacket *[max_msgs];
max = max_msgs; max_ = max_msgs;
zero(max_msgs); zero(max_msgs);
} }
@ -23,17 +23,17 @@ SrsMessageArray::~SrsMessageArray()
// we just free the msgs itself, // we just free the msgs itself,
// both delete and delete[] is ok, // both delete and delete[] is ok,
// for all msgs is already freed by send_and_free_messages. // for all msgs is already freed by send_and_free_messages.
srs_freepa(msgs); srs_freepa(msgs_);
} }
void SrsMessageArray::free(int count) void SrsMessageArray::free(int count)
{ {
// initialize // initialize
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
SrsMediaPacket *msg = msgs[i]; SrsMediaPacket *msg = msgs_[i];
srs_freep(msg); srs_freep(msg);
msgs[i] = NULL; msgs_[i] = NULL;
} }
} }
@ -41,6 +41,6 @@ void SrsMessageArray::zero(int count)
{ {
// initialize // initialize
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
msgs[i] = NULL; msgs_[i] = NULL;
} }
} }

View File

@ -22,10 +22,10 @@ class SrsMessageArray
{ {
public: public:
// When user already send all msgs, please set to NULL, // When user already send all msgs, please set to NULL,
// for instance, msg= msgs.msgs[i], msgs.msgs[i]=NULL, send(msg), // for instance, msg= msgs.msgs_[i], msgs.msgs_[i]=NULL, send(msg),
// where send(msg) will always send and free it. // where send(msg) will always send and free it.
SrsMediaPacket **msgs; SrsMediaPacket **msgs_;
int max; int max_;
public: public:
// Create msg array, initialize array to NULL ptrs. // Create msg array, initialize array to NULL ptrs.

File diff suppressed because it is too large Load Diff

View File

@ -136,55 +136,55 @@ private:
class AckWindowSize class AckWindowSize
{ {
public: public:
uint32_t window; uint32_t window_;
// number of received bytes. // number of received bytes.
int64_t nb_recv_bytes; int64_t nb_recv_bytes_;
// previous responsed sequence number. // previous responsed sequence number.
uint32_t sequence_number; uint32_t sequence_number_;
AckWindowSize(); AckWindowSize();
}; };
// For peer in/out // For peer in/out
private: private:
// The underlayer socket object, send/recv bytes. // The underlayer socket object, send/recv bytes.
ISrsProtocolReadWriter *skt; ISrsProtocolReadWriter *skt_;
// The requests sent out, used to build the response. // The requests sent out, used to build the response.
// key: transactionId // key: transactionId
// value: the request command name // value: the request command name
std::map<double, std::string> requests; std::map<double, std::string> requests_;
// For peer in // For peer in
private: private:
// The chunk stream to decode RTMP messages. // The chunk stream to decode RTMP messages.
std::map<int, SrsChunkStream *> chunk_streams; std::map<int, SrsChunkStream *> chunk_streams_;
// Cache some frequently used chunk header. // Cache some frequently used chunk header.
// cs_cache, the chunk stream cache. // cs_cache, the chunk stream cache.
SrsChunkStream **cs_cache; SrsChunkStream **cs_cache_;
// The bytes buffer cache, recv from skt, provide services for stream. // The bytes buffer cache, recv from skt, provide services for stream.
SrsFastStream *in_buffer; SrsFastStream *in_buffer_;
// The input chunk size, default to 128, set by peer packet. // The input chunk size, default to 128, set by peer packet.
int32_t in_chunk_size; int32_t in_chunk_size_;
// The input ack window, to response acknowledge to peer, // The input ack window, to response acknowledge to peer,
// For example, to respose the encoder, for server got lots of packets. // For example, to respose the encoder, for server got lots of packets.
AckWindowSize in_ack_size; AckWindowSize in_ack_size_;
// The output ack window, to require peer to response the ack. // The output ack window, to require peer to response the ack.
AckWindowSize out_ack_size; AckWindowSize out_ack_size_;
// The buffer length set by peer. // The buffer length set by peer.
int32_t in_buffer_length; int32_t in_buffer_length_;
// Whether print the protocol level debug info. // Whether print the protocol level debug info.
// Generally we print the debug info when got or send first A/V packet. // Generally we print the debug info when got or send first A/V packet.
bool show_debug_info; bool show_debug_info_;
// Whether auto response when recv messages. // Whether auto response when recv messages.
// default to true for it's very easy to use the protocol stack. // default to true for it's very easy to use the protocol stack.
bool auto_response_when_recv; bool auto_response_when_recv_;
// When not auto response message, manual flush the messages in queue. // When not auto response message, manual flush the messages in queue.
std::vector<SrsRtmpCommand *> manual_response_queue; std::vector<SrsRtmpCommand *> manual_response_queue_;
// For peer out // For peer out
private: private:
// Cache for multiple messages send, // Cache for multiple messages send,
// initialize to iovec[SRS_CONSTS_IOVS_MAX] and realloc when consumed, // initialize to iovec[SRS_CONSTS_IOVS_MAX] and realloc when consumed,
// it's ok to realloc the iovs cache, for all ptr is ok. // it's ok to realloc the iovs cache, for all ptr is ok.
iovec *out_iovs; iovec *out_iovs_;
int nb_out_iovs; int nb_out_iovs_;
// The output header cache. // The output header cache.
// used for type0, 11bytes(or 15bytes with extended timestamp) header. // used for type0, 11bytes(or 15bytes with extended timestamp) header.
// or for type3, 1bytes(or 5bytes with extended timestamp) header. // or for type3, 1bytes(or 5bytes with extended timestamp) header.
@ -192,11 +192,11 @@ private:
// //
// @remark, the c0c3 cache cannot be realloc. // @remark, the c0c3 cache cannot be realloc.
// To allocate it in heap to make VS2015 happy. // To allocate it in heap to make VS2015 happy.
char *out_c0c3_caches; char *out_c0c3_caches_;
// Whether warned user to increase the c0c3 header cache. // Whether warned user to increase the c0c3 header cache.
bool warned_c0c3_cache_dry; bool warned_c0c3_cache_dry_;
// The output chunk size, default to 128, set by config. // The output chunk size, default to 128, set by config.
int32_t out_chunk_size; int32_t out_chunk_size_;
public: public:
SrsProtocol(ISrsProtocolReadWriter *io); SrsProtocol(ISrsProtocolReadWriter *io);
@ -380,25 +380,25 @@ class SrsChunkStream
public: public:
// Represents the basic header fmt, // Represents the basic header fmt,
// which used to identify the variant message header type. // which used to identify the variant message header type.
char fmt; char fmt_;
// Represents the basic header cid, // Represents the basic header cid,
// which is the chunk stream id. // which is the chunk stream id.
int cid; int cid_;
// Cached message header // Cached message header
SrsMessageHeader header; SrsMessageHeader header_;
// Whether the chunk message header has extended timestamp. // Whether the chunk message header has extended timestamp.
bool has_extended_timestamp; bool has_extended_timestamp_;
// The partially read message. // The partially read message.
SrsRtmpCommonMessage *msg; SrsRtmpCommonMessage *msg_;
// Current writing position of message. // Current writing position of message.
char *writing_pos_; char *writing_pos_;
// Decoded msg count, to identify whether the chunk stream is fresh. // Decoded msg count, to identify whether the chunk stream is fresh.
int64_t msg_count; int64_t msg_count_;
// Because the extended timestamp may be a delta timestamp, it can differ // Because the extended timestamp may be a delta timestamp, it can differ
// from the timestamp in the header, so it should be stored as a distinct field // from the timestamp in the header, so it should be stored as a distinct field
// for comparison with the extended timestamp of subsequent chunks. // for comparison with the extended timestamp of subsequent chunks.
// See https://github.com/ossrs/srs/pull/4356 for details. // See https://github.com/ossrs/srs/pull/4356 for details.
int32_t extended_timestamp; int32_t extended_timestamp_;
public: public:
SrsChunkStream(int _cid); SrsChunkStream(int _cid);
@ -409,7 +409,7 @@ class ISrsRequest
{ {
public: public:
// The client ip. // The client ip.
std::string ip; std::string ip_;
public: public:
// Support pass vhost in RTMP URL, such as: // Support pass vhost in RTMP URL, such as:
@ -418,28 +418,28 @@ public:
// rtmp://ip:port/app?vhost=VHOST/stream // rtmp://ip:port/app?vhost=VHOST/stream
// rtmp://ip:port/app...vhost...VHOST/stream // rtmp://ip:port/app...vhost...VHOST/stream
// While tcUrl is url without stream. // While tcUrl is url without stream.
std::string tcUrl; std::string tcUrl_;
public: public:
std::string pageUrl; std::string pageUrl_;
std::string swfUrl; std::string swfUrl_;
double objectEncoding; double objectEncoding_;
// The data discovery from request. // The data discovery from request.
public: public:
// Discovery from tcUrl and play/publish. // Discovery from tcUrl and play/publish.
std::string schema; std::string schema_;
// The vhost in tcUrl. // The vhost in tcUrl.
std::string vhost; std::string vhost_;
// The host in tcUrl. // The host in tcUrl.
std::string host; std::string host_;
// The port in tcUrl. // The port in tcUrl.
int port; int port_;
// The app in tcUrl, without param. // The app in tcUrl, without param.
std::string app; std::string app_;
// The param in tcUrl(app). // The param in tcUrl(app).
std::string param; std::string param_;
// The stream in play/publish // The stream in play/publish
std::string stream; std::string stream_;
// User specify the ice-ufrag, the username of ice, for test only. // User specify the ice-ufrag, the username of ice, for test only.
std::string ice_ufrag_; std::string ice_ufrag_;
// User specify the ice-pwd, the password of ice, for test only. // User specify the ice-pwd, the password of ice, for test only.
@ -447,18 +447,18 @@ public:
// For play live stream, // For play live stream,
// used to specified the stop when exceed the duration. // used to specified the stop when exceed the duration.
// in srs_utime_t. // in srs_utime_t.
srs_utime_t duration; srs_utime_t duration_;
// The token in the connect request, // The token in the connect request,
// used for edge traverse to origin authentication, // used for edge traverse to origin authentication,
// @see https://github.com/ossrs/srs/issues/104 // @see https://github.com/ossrs/srs/issues/104
SrsAmf0Object *args; SrsAmf0Object *args_;
public: public:
// The protocol of client: // The protocol of client:
// rtmp, Adobe RTMP protocol. // rtmp, Adobe RTMP protocol.
// flv, HTTP-FLV protocol. // flv, HTTP-FLV protocol.
// flvs, HTTPS-FLV protocol. // flvs, HTTPS-FLV protocol.
std::string protocol; std::string protocol_;
public: public:
ISrsRequest(); ISrsRequest();
@ -509,7 +509,7 @@ class SrsResponse
{ {
public: public:
// The stream id to response client createStream. // The stream id to response client createStream.
int stream_id; int stream_id_;
public: public:
SrsResponse(); SrsResponse();
@ -541,13 +541,13 @@ class SrsHandshakeBytes
{ {
public: public:
// For RTMP proxy, the real IP. // For RTMP proxy, the real IP.
uint32_t proxy_real_ip; uint32_t proxy_real_ip_;
// [1+1536] // [1+1536]
char *c0c1; char *c0c1_;
// [1+1536+1536] // [1+1536+1536]
char *s0s1s2; char *s0s1s2_;
// [1536] // [1536]
char *c2; char *c2_;
public: public:
SrsHandshakeBytes(); SrsHandshakeBytes();
@ -567,14 +567,14 @@ public:
// The information return from RTMP server. // The information return from RTMP server.
struct SrsServerInfo { struct SrsServerInfo {
std::string ip; std::string ip_;
std::string sig; std::string sig_;
int pid; int pid_;
int cid; int cid_;
int major; int major_;
int minor; int minor_;
int revision; int revision_;
int build; int build_;
SrsServerInfo(); SrsServerInfo();
}; };
@ -583,11 +583,11 @@ struct SrsServerInfo {
class SrsRtmpClient class SrsRtmpClient
{ {
private: private:
SrsHandshakeBytes *hs_bytes; SrsHandshakeBytes *hs_bytes_;
protected: protected:
SrsProtocol *protocol; SrsProtocol *protocol_;
ISrsProtocolReadWriter *io; ISrsProtocolReadWriter *io_;
public: public:
SrsRtmpClient(ISrsProtocolReadWriter *skt); SrsRtmpClient(ISrsProtocolReadWriter *skt);
@ -649,7 +649,7 @@ public:
template <class T> template <class T>
srs_error_t expect_message(SrsRtmpCommonMessage **pmsg, T **ppacket) srs_error_t expect_message(SrsRtmpCommonMessage **pmsg, T **ppacket)
{ {
return protocol->expect_message<T>(pmsg, ppacket); return protocol_->expect_message<T>(pmsg, ppacket);
} }
}; };
@ -659,9 +659,9 @@ public:
class SrsRtmpServer class SrsRtmpServer
{ {
private: private:
SrsHandshakeBytes *hs_bytes; SrsHandshakeBytes *hs_bytes_;
SrsProtocol *protocol; SrsProtocol *protocol_;
ISrsProtocolReadWriter *io; ISrsProtocolReadWriter *io_;
public: public:
SrsRtmpServer(ISrsProtocolReadWriter *skt); SrsRtmpServer(ISrsProtocolReadWriter *skt);
@ -821,7 +821,7 @@ public:
template <class T> template <class T>
srs_error_t expect_message(SrsRtmpCommonMessage **pmsg, T **ppacket) srs_error_t expect_message(SrsRtmpCommonMessage **pmsg, T **ppacket)
{ {
return protocol->expect_message<T>(pmsg, ppacket); return protocol_->expect_message<T>(pmsg, ppacket);
} }
private: private:
@ -841,17 +841,17 @@ class SrsConnectAppPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command. Set to "connect". // Name of the command. Set to "connect".
std::string command_name; std::string command_name_;
// Always set to 1. // Always set to 1.
double transaction_id; double transaction_id_;
// Command information object which has the name-value pairs. // Command information object which has the name-value pairs.
// @remark: alloc in packet constructor, user can directly use it, // @remark: alloc in packet constructor, user can directly use it,
// user should never alloc it again which will cause memory leak. // user should never alloc it again which will cause memory leak.
// @remark, never be NULL. // @remark, never be NULL.
SrsAmf0Object *command_object; SrsAmf0Object *command_object_;
// Any optional information // Any optional information
// @remark, optional, init to and maybe NULL. // @remark, optional, init to and maybe NULL.
SrsAmf0Object *args; SrsAmf0Object *args_;
public: public:
SrsConnectAppPacket(); SrsConnectAppPacket();
@ -872,16 +872,16 @@ class SrsConnectAppResPacket : public SrsRtmpCommand
{ {
public: public:
// The _result or _error; indicates whether the response is result or error. // The _result or _error; indicates whether the response is result or error.
std::string command_name; std::string command_name_;
// Transaction ID is 1 for call connect responses // Transaction ID is 1 for call connect responses
double transaction_id; double transaction_id_;
// Name-value pairs that describe the properties(fmsver etc.) of the connection. // Name-value pairs that describe the properties(fmsver etc.) of the connection.
// @remark, never be NULL. // @remark, never be NULL.
SrsAmf0Object *props; SrsAmf0Object *props_;
// Name-value pairs that describe the response from|the server. 'code', // Name-value pairs that describe the response from|the server. 'code',
// 'level', 'description' are names of few among such information. // 'level', 'description' are names of few among such information.
// @remark, never be NULL. // @remark, never be NULL.
SrsAmf0Object *info; SrsAmf0Object *info_;
public: public:
SrsConnectAppResPacket(); SrsConnectAppResPacket();
@ -906,16 +906,16 @@ class SrsCallPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the remote procedure that is called. // Name of the remote procedure that is called.
std::string command_name; std::string command_name_;
// If a response is expected we give a transaction Id. Else we pass a value of 0 // If a response is expected we give a transaction Id. Else we pass a value of 0
double transaction_id; double transaction_id_;
// If there exists any command info this // If there exists any command info this
// is set, else this is set to null type. // is set, else this is set to null type.
// @remark, optional, init to and maybe NULL. // @remark, optional, init to and maybe NULL.
SrsAmf0Any *command_object; SrsAmf0Any *command_object_;
// Any optional arguments to be provided // Any optional arguments to be provided
// @remark, optional, init to and maybe NULL. // @remark, optional, init to and maybe NULL.
SrsAmf0Any *arguments; SrsAmf0Any *arguments_;
public: public:
SrsCallPacket(); SrsCallPacket();
@ -936,15 +936,15 @@ class SrsCallResPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command. // Name of the command.
std::string command_name; std::string command_name_;
// ID of the command, to which the response belongs to // ID of the command, to which the response belongs to
double transaction_id; double transaction_id_;
// If there exists any command info this is set, else this is set to null type. // If there exists any command info this is set, else this is set to null type.
// @remark, optional, init to and maybe NULL. // @remark, optional, init to and maybe NULL.
SrsAmf0Any *command_object; SrsAmf0Any *command_object_;
// Response from the method that was called. // Response from the method that was called.
// @remark, optional, init to and maybe NULL. // @remark, optional, init to and maybe NULL.
SrsAmf0Any *response; SrsAmf0Any *response_;
public: public:
SrsCallResPacket(double _transaction_id); SrsCallResPacket(double _transaction_id);
@ -967,12 +967,12 @@ class SrsCreateStreamPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command. Set to "createStream". // Name of the command. Set to "createStream".
std::string command_name; std::string command_name_;
// Transaction ID of the command. // Transaction ID of the command.
double transaction_id; double transaction_id_;
// If there exists any command info this is set, else this is set to null type. // If there exists any command info this is set, else this is set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
public: public:
SrsCreateStreamPacket(); SrsCreateStreamPacket();
virtual ~SrsCreateStreamPacket(); virtual ~SrsCreateStreamPacket();
@ -995,14 +995,14 @@ class SrsCreateStreamResPacket : public SrsRtmpCommand
{ {
public: public:
// The _result or _error; indicates whether the response is result or error. // The _result or _error; indicates whether the response is result or error.
std::string command_name; std::string command_name_;
// ID of the command that response belongs to. // ID of the command that response belongs to.
double transaction_id; double transaction_id_;
// If there exists any command info this is set, else this is set to null type. // If there exists any command info this is set, else this is set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
// The return value is either a stream ID or an error information object. // The return value is either a stream ID or an error information object.
double stream_id; double stream_id_;
public: public:
SrsCreateStreamResPacket(double _transaction_id, double _stream_id); SrsCreateStreamResPacket(double _transaction_id, double _stream_id);
@ -1024,12 +1024,12 @@ class SrsCloseStreamPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command, set to "closeStream". // Name of the command, set to "closeStream".
std::string command_name; std::string command_name_;
// Transaction ID set to 0. // Transaction ID set to 0.
double transaction_id; double transaction_id_;
// Command information object does not exist. Set to null type. // Command information object does not exist. Set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
public: public:
SrsCloseStreamPacket(); SrsCloseStreamPacket();
virtual ~SrsCloseStreamPacket(); virtual ~SrsCloseStreamPacket();
@ -1043,14 +1043,14 @@ class SrsFMLEStartPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command // Name of the command
std::string command_name; std::string command_name_;
// The transaction ID to get the response. // The transaction ID to get the response.
double transaction_id; double transaction_id_;
// If there exists any command info this is set, else this is set to null type. // If there exists any command info this is set, else this is set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
// The stream name to start publish or release. // The stream name to start publish or release.
std::string stream_name; std::string stream_name_;
public: public:
SrsFMLEStartPacket(); SrsFMLEStartPacket();
@ -1078,15 +1078,15 @@ class SrsFMLEStartResPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command // Name of the command
std::string command_name; std::string command_name_;
// The transaction ID to get the response. // The transaction ID to get the response.
double transaction_id; double transaction_id_;
// If there exists any command info this is set, else this is set to null type. // If there exists any command info this is set, else this is set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
// The optional args, set to undefined. // The optional args, set to undefined.
// @remark, never be NULL, an AMF0 undefined instance. // @remark, never be NULL, an AMF0 undefined instance.
SrsAmf0Any *args; // undefined SrsAmf0Any *args_; // undefined
public: public:
SrsFMLEStartResPacket(double _transaction_id); SrsFMLEStartResPacket(double _transaction_id);
virtual ~SrsFMLEStartResPacket(); virtual ~SrsFMLEStartResPacket();
@ -1115,14 +1115,14 @@ class SrsPublishPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command, set to "publish". // Name of the command, set to "publish".
std::string command_name; std::string command_name_;
// Transaction ID set to 0. // Transaction ID set to 0.
double transaction_id; double transaction_id_;
// Command information object does not exist. Set to null type. // Command information object does not exist. Set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
// Name with which the stream is published. // Name with which the stream is published.
std::string stream_name; std::string stream_name_;
// Type of publishing. Set to "live", "record", or "append". // Type of publishing. Set to "live", "record", or "append".
// record: The stream is published and the data is recorded to a new file.The file // record: The stream is published and the data is recorded to a new file.The file
// is stored on the server in a subdirectory within the directory that // is stored on the server in a subdirectory within the directory that
@ -1133,7 +1133,7 @@ public:
// live: Live data is published without recording it in a file. // live: Live data is published without recording it in a file.
// @remark, SRS only support live. // @remark, SRS only support live.
// @remark, optional, default to live. // @remark, optional, default to live.
std::string type; std::string type_;
public: public:
SrsPublishPacket(); SrsPublishPacket();
@ -1160,19 +1160,19 @@ class SrsPausePacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command, set to "pause". // Name of the command, set to "pause".
std::string command_name; std::string command_name_;
// There is no transaction ID for this command. Set to 0. // There is no transaction ID for this command. Set to 0.
double transaction_id; double transaction_id_;
// Command information object does not exist. Set to null type. // Command information object does not exist. Set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
// true or false, to indicate pausing or resuming play // true or false, to indicate pausing or resuming play
bool is_pause; bool is_pause_;
// Number of milliseconds at which the the stream is paused or play resumed. // Number of milliseconds at which the the stream is paused or play resumed.
// This is the current stream time at the Client when stream was paused. When the // This is the current stream time at the Client when stream was paused. When the
// playback is resumed, the server will only send messages with timestamps // playback is resumed, the server will only send messages with timestamps
// greater than this value. // greater than this value.
double time_ms; double time_ms_;
public: public:
SrsPausePacket(); SrsPausePacket();
@ -1188,12 +1188,12 @@ class SrsPlayPacket : public SrsRtmpCommand
{ {
public: public:
// Name of the command. Set to "play". // Name of the command. Set to "play".
std::string command_name; std::string command_name_;
// Transaction ID set to 0. // Transaction ID set to 0.
double transaction_id; double transaction_id_;
// Command information does not exist. Set to null type. // Command information does not exist. Set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
// Name of the stream to play. // Name of the stream to play.
// To play video (FLV) files, specify the name of the stream without a file // To play video (FLV) files, specify the name of the stream without a file
// extension (for example, "sample"). // extension (for example, "sample").
@ -1202,7 +1202,7 @@ public:
// To play H.264/AAC files, you must precede the stream name with mp4: and specify the // To play H.264/AAC files, you must precede the stream name with mp4: and specify the
// file extension. For example, to play the file sample.m4v, specify // file extension. For example, to play the file sample.m4v, specify
// "mp4:sample.m4v" // "mp4:sample.m4v"
std::string stream_name; std::string stream_name_;
// An optional parameter that specifies the start time in seconds. // An optional parameter that specifies the start time in seconds.
// The default value is -2, which means the subscriber first tries to play the live // The default value is -2, which means the subscriber first tries to play the live
// stream specified in the Stream Name field. If a live stream of that name is // stream specified in the Stream Name field. If a live stream of that name is
@ -1213,7 +1213,7 @@ public:
// in the Stream Name field is played beginning from the time specified in the // in the Stream Name field is played beginning from the time specified in the
// Start field. // Start field.
// If no recorded stream is found, the next item in the playlist is played. // If no recorded stream is found, the next item in the playlist is played.
double start; double start_;
// An optional parameter that specifies the duration of playback in seconds. // An optional parameter that specifies the duration of playback in seconds.
// The default value is -1. The -1 value means a live stream is played until it is no // The default value is -1. The -1 value means a live stream is played until it is no
// longer available or a recorded stream is played until it ends. // longer available or a recorded stream is played until it ends.
@ -1226,10 +1226,10 @@ public:
// time specified in the Duration field, playback ends when the stream ends.) // time specified in the Duration field, playback ends when the stream ends.)
// If you pass a negative number other than -1 in the Duration field, it interprets the // If you pass a negative number other than -1 in the Duration field, it interprets the
// value as if it were -1. // value as if it were -1.
double duration; double duration_;
// An optional Boolean value or number that specifies whether to flush any // An optional Boolean value or number that specifies whether to flush any
// previous playlist. // previous playlist.
bool reset; bool reset_;
public: public:
SrsPlayPacket(); SrsPlayPacket();
@ -1253,17 +1253,17 @@ class SrsPlayResPacket : public SrsRtmpCommand
public: public:
// Name of the command. If the play command is successful, the command // Name of the command. If the play command is successful, the command
// name is set to onStatus. // name is set to onStatus.
std::string command_name; std::string command_name_;
// Transaction ID set to 0. // Transaction ID set to 0.
double transaction_id; double transaction_id_;
// Command information does not exist. Set to null type. // Command information does not exist. Set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *command_object; // null SrsAmf0Any *command_object_; // null
// If the play command is successful, the client receives OnStatus message from // If the play command is successful, the client receives OnStatus message from
// server which is NetStream.Play.Start. If the specified stream is not found, // server which is NetStream.Play.Start. If the specified stream is not found,
// NetStream.Play.StreamNotFound is received. // NetStream.Play.StreamNotFound is received.
// @remark, never be NULL, an AMF0 object instance. // @remark, never be NULL, an AMF0 object instance.
SrsAmf0Object *desc; SrsAmf0Object *desc_;
public: public:
SrsPlayResPacket(); SrsPlayResPacket();
@ -1286,12 +1286,12 @@ class SrsOnBWDonePacket : public SrsRtmpCommand
{ {
public: public:
// Name of command. Set to "onBWDone" // Name of command. Set to "onBWDone"
std::string command_name; std::string command_name_;
// Transaction ID set to 0. // Transaction ID set to 0.
double transaction_id; double transaction_id_;
// Command information does not exist. Set to null type. // Command information does not exist. Set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *args; // null SrsAmf0Any *args_; // null
public: public:
SrsOnBWDonePacket(); SrsOnBWDonePacket();
virtual ~SrsOnBWDonePacket(); virtual ~SrsOnBWDonePacket();
@ -1313,16 +1313,16 @@ class SrsOnStatusCallPacket : public SrsRtmpCommand
{ {
public: public:
// Name of command. Set to "onStatus" // Name of command. Set to "onStatus"
std::string command_name; std::string command_name_;
// Transaction ID set to 0. // Transaction ID set to 0.
double transaction_id; double transaction_id_;
// Command information does not exist. Set to null type. // Command information does not exist. Set to null type.
// @remark, never be NULL, an AMF0 null instance. // @remark, never be NULL, an AMF0 null instance.
SrsAmf0Any *args; // null SrsAmf0Any *args_; // null
// Name-value pairs that describe the response from the server. // Name-value pairs that describe the response from the server.
// 'code','level', 'description' are names of few among such information. // 'code','level', 'description' are names of few among such information.
// @remark, never be NULL, an AMF0 object instance. // @remark, never be NULL, an AMF0 object instance.
SrsAmf0Object *data; SrsAmf0Object *data_;
public: public:
SrsOnStatusCallPacket(); SrsOnStatusCallPacket();
@ -1346,11 +1346,11 @@ class SrsOnStatusDataPacket : public SrsRtmpCommand
{ {
public: public:
// Name of command. Set to "onStatus" // Name of command. Set to "onStatus"
std::string command_name; std::string command_name_;
// Name-value pairs that describe the response from the server. // Name-value pairs that describe the response from the server.
// 'code', are names of few among such information. // 'code', are names of few among such information.
// @remark, never be NULL, an AMF0 object instance. // @remark, never be NULL, an AMF0 object instance.
SrsAmf0Object *data; SrsAmf0Object *data_;
public: public:
SrsOnStatusDataPacket(); SrsOnStatusDataPacket();
@ -1374,13 +1374,13 @@ class SrsNaluSampleAccessPacket : public SrsRtmpCommand
{ {
public: public:
// Name of command. Set to "|RtmpSampleAccess". // Name of command. Set to "|RtmpSampleAccess".
std::string command_name; std::string command_name_;
// Whether allow access the sample of video. // Whether allow access the sample of video.
// @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#videoSampleAccess // @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#videoSampleAccess
bool video_sample_access; bool video_sample_access_;
// Whether allow access the sample of audio. // Whether allow access the sample of audio.
// @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#audioSampleAccess // @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#audioSampleAccess
bool audio_sample_access; bool audio_sample_access_;
public: public:
SrsNaluSampleAccessPacket(); SrsNaluSampleAccessPacket();
@ -1401,10 +1401,10 @@ class SrsOnMetaDataPacket : public SrsRtmpCommand
{ {
public: public:
// Name of metadata. Set to "onMetaData" // Name of metadata. Set to "onMetaData"
std::string name; std::string name_;
// Metadata of stream. // Metadata of stream.
// @remark, never be NULL, an AMF0 object instance. // @remark, never be NULL, an AMF0 object instance.
SrsAmf0Object *metadata; SrsAmf0Object *metadata_;
public: public:
SrsOnMetaDataPacket(); SrsOnMetaDataPacket();
@ -1430,7 +1430,7 @@ protected:
class SrsSetWindowAckSizePacket : public SrsRtmpCommand class SrsSetWindowAckSizePacket : public SrsRtmpCommand
{ {
public: public:
int32_t ackowledgement_window_size; int32_t ackowledgement_window_size_;
public: public:
SrsSetWindowAckSizePacket(); SrsSetWindowAckSizePacket();
@ -1453,7 +1453,7 @@ protected:
class SrsAcknowledgementPacket : public SrsRtmpCommand class SrsAcknowledgementPacket : public SrsRtmpCommand
{ {
public: public:
uint32_t sequence_number; uint32_t sequence_number_;
public: public:
SrsAcknowledgementPacket(); SrsAcknowledgementPacket();
@ -1478,7 +1478,7 @@ class SrsSetChunkSizePacket : public SrsRtmpCommand
public: public:
// The maximum chunk size can be 65536 bytes. The chunk size is // The maximum chunk size can be 65536 bytes. The chunk size is
// maintained independently for each direction. // maintained independently for each direction.
int32_t chunk_size; int32_t chunk_size_;
public: public:
SrsSetChunkSizePacket(); SrsSetChunkSizePacket();
@ -1510,9 +1510,9 @@ enum SrsPeerBandwidthType {
class SrsSetPeerBandwidthPacket : public SrsRtmpCommand class SrsSetPeerBandwidthPacket : public SrsRtmpCommand
{ {
public: public:
int32_t bandwidth; int32_t bandwidth_;
// @see: SrsPeerBandwidthType // @see: SrsPeerBandwidthType
int8_t type; int8_t type_;
public: public:
SrsSetPeerBandwidthPacket(); SrsSetPeerBandwidthPacket();
@ -1614,13 +1614,13 @@ class SrsUserControlPacket : public SrsRtmpCommand
public: public:
// Event type is followed by Event data. // Event type is followed by Event data.
// @see: SrcPCUCEventType // @see: SrcPCUCEventType
int16_t event_type; int16_t event_type_;
// The event data generally in 4bytes. // The event data generally in 4bytes.
// @remark for event type is 0x001a, only 1bytes. // @remark for event type is 0x001a, only 1bytes.
// @see SrsPCUCFmsEvent0 // @see SrsPCUCFmsEvent0
int32_t event_data; int32_t event_data_;
// 4bytes if event_type is SetBufferLength; otherwise 0. // 4bytes if event_type is SetBufferLength; otherwise 0.
int32_t extra_data; int32_t extra_data_;
public: public:
SrsUserControlPacket(); SrsUserControlPacket();

View File

@ -324,16 +324,16 @@ VOID TEST(SrsAVCTest, AACDemuxADTS)
uint8_t b[] = {0xff, 0xf9, 0x2c, 0x40, 0, 0xe0, 0}; uint8_t b[] = {0xff, 0xf9, 0x2c, 0x40, 0, 0xe0, 0};
SrsBuffer buf((char *)b, sizeof(b)); SrsBuffer buf((char *)b, sizeof(b));
HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec)); HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec));
EXPECT_EQ(1, codec.protection_absent); // b[1] EXPECT_EQ(1, codec.protection_absent_); // b[1]
EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object); // b[2] EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object_); // b[2]
EXPECT_EQ(0xb, codec.sampling_frequency_index); // b[2] EXPECT_EQ(0xb, codec.sampling_frequency_index_); // b[2]
EXPECT_EQ(1, codec.channel_configuration); // b[3] EXPECT_EQ(1, codec.channel_configuration_); // b[3]
EXPECT_EQ(7, codec.frame_length); // b[5] EXPECT_EQ(7, codec.frame_length_); // b[5]
EXPECT_EQ(0, nb_frame); EXPECT_EQ(0, nb_frame);
EXPECT_EQ(SrsAudioSampleRate5512, codec.sound_rate); EXPECT_EQ(SrsAudioSampleRate5512, codec.sound_rate_);
EXPECT_EQ(0, codec.sound_type); EXPECT_EQ(0, codec.sound_type_);
EXPECT_EQ(1, codec.sound_size); EXPECT_EQ(1, codec.sound_size_);
} }
// For lower sampling rate, such as 22050HZ. // For lower sampling rate, such as 22050HZ.
@ -345,16 +345,16 @@ VOID TEST(SrsAVCTest, AACDemuxADTS)
uint8_t b[] = {0xff, 0xf9, 0x18, 0x40, 0, 0xe0, 0}; uint8_t b[] = {0xff, 0xf9, 0x18, 0x40, 0, 0xe0, 0};
SrsBuffer buf((char *)b, sizeof(b)); SrsBuffer buf((char *)b, sizeof(b));
HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec)); HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec));
EXPECT_EQ(1, codec.protection_absent); // b[1] EXPECT_EQ(1, codec.protection_absent_); // b[1]
EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object); // b[2] EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object_); // b[2]
EXPECT_EQ(6, codec.sampling_frequency_index); // b[2] EXPECT_EQ(6, codec.sampling_frequency_index_); // b[2]
EXPECT_EQ(1, codec.channel_configuration); // b[3] EXPECT_EQ(1, codec.channel_configuration_); // b[3]
EXPECT_EQ(7, codec.frame_length); // b[5] EXPECT_EQ(7, codec.frame_length_); // b[5]
EXPECT_EQ(0, nb_frame); EXPECT_EQ(0, nb_frame);
EXPECT_EQ(SrsAudioSampleRate22050, codec.sound_rate); EXPECT_EQ(SrsAudioSampleRate22050, codec.sound_rate_);
EXPECT_EQ(0, codec.sound_type); EXPECT_EQ(0, codec.sound_type_);
EXPECT_EQ(1, codec.sound_size); EXPECT_EQ(1, codec.sound_size_);
} }
// For higher sampling rate, use 44100HZ. // For higher sampling rate, use 44100HZ.
@ -366,16 +366,16 @@ VOID TEST(SrsAVCTest, AACDemuxADTS)
uint8_t b[] = {0xff, 0xf9, 0x04, 0x40, 0, 0xe0, 0}; uint8_t b[] = {0xff, 0xf9, 0x04, 0x40, 0, 0xe0, 0};
SrsBuffer buf((char *)b, sizeof(b)); SrsBuffer buf((char *)b, sizeof(b));
HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec)); HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec));
EXPECT_EQ(1, codec.protection_absent); // b[1] EXPECT_EQ(1, codec.protection_absent_); // b[1]
EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object); // b[2] EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object_); // b[2]
EXPECT_EQ(1, codec.sampling_frequency_index); // b[2] EXPECT_EQ(1, codec.sampling_frequency_index_); // b[2]
EXPECT_EQ(1, codec.channel_configuration); // b[3] EXPECT_EQ(1, codec.channel_configuration_); // b[3]
EXPECT_EQ(7, codec.frame_length); // b[5] EXPECT_EQ(7, codec.frame_length_); // b[5]
EXPECT_EQ(0, nb_frame); EXPECT_EQ(0, nb_frame);
EXPECT_EQ(SrsAudioSampleRate44100, codec.sound_rate); EXPECT_EQ(SrsAudioSampleRate44100, codec.sound_rate_);
EXPECT_EQ(0, codec.sound_type); EXPECT_EQ(0, codec.sound_type_);
EXPECT_EQ(1, codec.sound_size); EXPECT_EQ(1, codec.sound_size_);
} }
// If protected, there are 2B signature. // If protected, there are 2B signature.
@ -387,17 +387,17 @@ VOID TEST(SrsAVCTest, AACDemuxADTS)
uint8_t b[] = {0xff, 0xf0, 0x10, 0x40, 0x01, 0x40, 0, 0, 0, 1}; uint8_t b[] = {0xff, 0xf0, 0x10, 0x40, 0x01, 0x40, 0, 0, 0, 1};
SrsBuffer buf((char *)b, sizeof(b)); SrsBuffer buf((char *)b, sizeof(b));
HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec)); HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec));
EXPECT_EQ(0, codec.protection_absent); // b[1] EXPECT_EQ(0, codec.protection_absent_); // b[1]
EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object); // b[2] EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object_); // b[2]
EXPECT_EQ(4, codec.sampling_frequency_index); // b[2] EXPECT_EQ(4, codec.sampling_frequency_index_); // b[2]
EXPECT_EQ(1, codec.channel_configuration); // b[3] EXPECT_EQ(1, codec.channel_configuration_); // b[3]
EXPECT_EQ(10, codec.frame_length); // b[4,5] EXPECT_EQ(10, codec.frame_length_); // b[4,5]
ASSERT_EQ(1, nb_frame); ASSERT_EQ(1, nb_frame);
EXPECT_EQ(1, (uint8_t)frame[0]); EXPECT_EQ(1, (uint8_t)frame[0]);
EXPECT_EQ(SrsAudioSampleRate44100, codec.sound_rate); EXPECT_EQ(SrsAudioSampleRate44100, codec.sound_rate_);
EXPECT_EQ(0, codec.sound_type); EXPECT_EQ(0, codec.sound_type_);
EXPECT_EQ(1, codec.sound_size); EXPECT_EQ(1, codec.sound_size_);
} }
// Fail if not enough data. // Fail if not enough data.
@ -442,17 +442,17 @@ VOID TEST(SrsAVCTest, AACDemuxADTS)
uint8_t b[] = {0xff, 0xf9, 0x10, 0x40, 0x01, 0, 0, 1}; uint8_t b[] = {0xff, 0xf9, 0x10, 0x40, 0x01, 0, 0, 1};
SrsBuffer buf((char *)b, sizeof(b)); SrsBuffer buf((char *)b, sizeof(b));
HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec)); HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec));
EXPECT_EQ(1, codec.protection_absent); // b[1] EXPECT_EQ(1, codec.protection_absent_); // b[1]
EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object); // b[2] EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object_); // b[2]
EXPECT_EQ(4, codec.sampling_frequency_index); // b[2] EXPECT_EQ(4, codec.sampling_frequency_index_); // b[2]
EXPECT_EQ(1, codec.channel_configuration); // b[3] EXPECT_EQ(1, codec.channel_configuration_); // b[3]
EXPECT_EQ(8, codec.frame_length); // b[4] EXPECT_EQ(8, codec.frame_length_); // b[4]
ASSERT_EQ(1, nb_frame); ASSERT_EQ(1, nb_frame);
EXPECT_EQ(1, (uint8_t)frame[0]); EXPECT_EQ(1, (uint8_t)frame[0]);
EXPECT_EQ(SrsAudioSampleRate44100, codec.sound_rate); EXPECT_EQ(SrsAudioSampleRate44100, codec.sound_rate_);
EXPECT_EQ(0, codec.sound_type); EXPECT_EQ(0, codec.sound_type_);
EXPECT_EQ(1, codec.sound_size); EXPECT_EQ(1, codec.sound_size_);
} }
// Minimum AAC frame, no raw data. // Minimum AAC frame, no raw data.
@ -464,16 +464,16 @@ VOID TEST(SrsAVCTest, AACDemuxADTS)
uint8_t b[] = {0xff, 0xf9, 0x10, 0x40, 0, 0xe0, 0}; uint8_t b[] = {0xff, 0xf9, 0x10, 0x40, 0, 0xe0, 0};
SrsBuffer buf((char *)b, sizeof(b)); SrsBuffer buf((char *)b, sizeof(b));
HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec)); HELPER_ASSERT_SUCCESS(h.adts_demux(&buf, &frame, &nb_frame, codec));
EXPECT_EQ(1, codec.protection_absent); // b[1] EXPECT_EQ(1, codec.protection_absent_); // b[1]
EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object); // b[2] EXPECT_EQ(SrsAacObjectTypeAacMain, codec.aac_object_); // b[2]
EXPECT_EQ(4, codec.sampling_frequency_index); // b[2] EXPECT_EQ(4, codec.sampling_frequency_index_); // b[2]
EXPECT_EQ(1, codec.channel_configuration); // b[3] EXPECT_EQ(1, codec.channel_configuration_); // b[3]
EXPECT_EQ(7, codec.frame_length); // b[5] EXPECT_EQ(7, codec.frame_length_); // b[5]
EXPECT_EQ(0, nb_frame); EXPECT_EQ(0, nb_frame);
EXPECT_EQ(SrsAudioSampleRate44100, codec.sound_rate); EXPECT_EQ(SrsAudioSampleRate44100, codec.sound_rate_);
EXPECT_EQ(0, codec.sound_type); EXPECT_EQ(0, codec.sound_type_);
EXPECT_EQ(1, codec.sound_size); EXPECT_EQ(1, codec.sound_size_);
} }
} }
@ -486,10 +486,10 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
SrsRawAacStream h; SrsRawAacStream h;
string sh; string sh;
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
codec.aac_object = SrsAacObjectTypeAacMain; codec.aac_object_ = SrsAacObjectTypeAacMain;
codec.channel_configuration = 1; codec.channel_configuration_ = 1;
codec.sound_rate = SrsAudioSampleRate22050; codec.sound_rate_ = SrsAudioSampleRate22050;
codec.sampling_frequency_index = 7; codec.sampling_frequency_index_ = 7;
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh)); HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
EXPECT_EQ(2, (int)sh.length()); EXPECT_EQ(2, (int)sh.length());
EXPECT_EQ(0x0b, (uint8_t)sh.at(0)); EXPECT_EQ(0x0b, (uint8_t)sh.at(0));
@ -501,10 +501,10 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
SrsRawAacStream h; SrsRawAacStream h;
string sh; string sh;
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
codec.aac_object = SrsAacObjectTypeAacMain; codec.aac_object_ = SrsAacObjectTypeAacMain;
codec.channel_configuration = 1; codec.channel_configuration_ = 1;
codec.sound_rate = SrsAudioSampleRate11025; codec.sound_rate_ = SrsAudioSampleRate11025;
codec.sampling_frequency_index = 0xa; codec.sampling_frequency_index_ = 0xa;
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh)); HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
EXPECT_EQ(2, (int)sh.length()); EXPECT_EQ(2, (int)sh.length());
EXPECT_EQ(0x0d, (uint8_t)sh.at(0)); EXPECT_EQ(0x0d, (uint8_t)sh.at(0));
@ -516,9 +516,9 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
SrsRawAacStream h; SrsRawAacStream h;
string sh; string sh;
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
codec.aac_object = SrsAacObjectTypeAacMain; codec.aac_object_ = SrsAacObjectTypeAacMain;
codec.sampling_frequency_index = SrsAacSampleRateUnset; codec.sampling_frequency_index_ = SrsAacSampleRateUnset;
codec.sound_rate = SrsAudioSampleRateReserved; codec.sound_rate_ = SrsAudioSampleRateReserved;
HELPER_EXPECT_FAILED(h.mux_sequence_header(&codec, sh)); HELPER_EXPECT_FAILED(h.mux_sequence_header(&codec, sh));
} }
@ -527,10 +527,10 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
SrsRawAacStream h; SrsRawAacStream h;
string sh; string sh;
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
codec.aac_object = SrsAacObjectTypeAacMain; codec.aac_object_ = SrsAacObjectTypeAacMain;
codec.channel_configuration = 1; codec.channel_configuration_ = 1;
codec.sampling_frequency_index = 4; codec.sampling_frequency_index_ = 4;
codec.sound_rate = SrsAudioSampleRateReserved; codec.sound_rate_ = SrsAudioSampleRateReserved;
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh)); HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
EXPECT_EQ(2, (int)sh.length()); EXPECT_EQ(2, (int)sh.length());
EXPECT_EQ(0x0a, (uint8_t)sh.at(0)); EXPECT_EQ(0x0a, (uint8_t)sh.at(0));
@ -542,7 +542,7 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
SrsRawAacStream h; SrsRawAacStream h;
string sh; string sh;
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
codec.aac_object = SrsAacObjectTypeReserved; codec.aac_object_ = SrsAacObjectTypeReserved;
HELPER_EXPECT_FAILED(h.mux_sequence_header(&codec, sh)); HELPER_EXPECT_FAILED(h.mux_sequence_header(&codec, sh));
} }
@ -551,10 +551,10 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
SrsRawAacStream h; SrsRawAacStream h;
string sh; string sh;
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
codec.aac_object = SrsAacObjectTypeAacMain; codec.aac_object_ = SrsAacObjectTypeAacMain;
codec.channel_configuration = 1; codec.channel_configuration_ = 1;
codec.sound_rate = SrsAudioSampleRate44100; codec.sound_rate_ = SrsAudioSampleRate44100;
codec.sampling_frequency_index = 4; codec.sampling_frequency_index_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh)); HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
EXPECT_EQ(2, (int)sh.length()); EXPECT_EQ(2, (int)sh.length());
EXPECT_EQ(0x0a, (uint8_t)sh.at(0)); EXPECT_EQ(0x0a, (uint8_t)sh.at(0));
@ -566,10 +566,10 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
SrsRawAacStream h; SrsRawAacStream h;
string sh; string sh;
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
codec.aac_object = SrsAacObjectTypeAacMain; codec.aac_object_ = SrsAacObjectTypeAacMain;
codec.channel_configuration = 1; codec.channel_configuration_ = 1;
codec.sound_rate = SrsAudioSampleRate22050; codec.sound_rate_ = SrsAudioSampleRate22050;
codec.sampling_frequency_index = 4; codec.sampling_frequency_index_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh)); HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
EXPECT_EQ(2, (int)sh.length()); EXPECT_EQ(2, (int)sh.length());
EXPECT_EQ(0x0a, (uint8_t)sh.at(0)); EXPECT_EQ(0x0a, (uint8_t)sh.at(0));
@ -581,10 +581,10 @@ VOID TEST(SrsAVCTest, AACMuxSequenceHeader)
SrsRawAacStream h; SrsRawAacStream h;
string sh; string sh;
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
codec.aac_object = SrsAacObjectTypeAacMain; codec.aac_object_ = SrsAacObjectTypeAacMain;
codec.channel_configuration = 1; codec.channel_configuration_ = 1;
codec.sound_rate = SrsAudioSampleRate44100; codec.sound_rate_ = SrsAudioSampleRate44100;
codec.sampling_frequency_index = SrsAacSampleRateUnset; codec.sampling_frequency_index_ = SrsAacSampleRateUnset;
HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh)); HELPER_ASSERT_SUCCESS(h.mux_sequence_header(&codec, sh));
EXPECT_EQ(2, (int)sh.length()); EXPECT_EQ(2, (int)sh.length());
EXPECT_EQ(0x0a, (uint8_t)sh.at(0)); EXPECT_EQ(0x0a, (uint8_t)sh.at(0));
@ -603,11 +603,11 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
char *flv = NULL; char *flv = NULL;
int nb_flv = 0; int nb_flv = 0;
codec.sound_format = SrsAudioCodecIdMP3; codec.sound_format_ = SrsAudioCodecIdMP3;
codec.sound_rate = 0; codec.sound_rate_ = 0;
codec.sound_size = 1; codec.sound_size_ = 1;
codec.sound_type = 1; codec.sound_type_ = 1;
codec.aac_packet_type = 4; codec.aac_packet_type_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv)); HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv));
EXPECT_EQ(6, nb_flv); EXPECT_EQ(6, nb_flv);
EXPECT_EQ(0x23, (uint8_t)flv[0]); EXPECT_EQ(0x23, (uint8_t)flv[0]);
@ -622,11 +622,11 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
char *flv = NULL; char *flv = NULL;
int nb_flv = 0; int nb_flv = 0;
codec.sound_format = SrsAudioCodecIdOpus; codec.sound_format_ = SrsAudioCodecIdOpus;
codec.sound_rate = 0; codec.sound_rate_ = 0;
codec.sound_size = 1; codec.sound_size_ = 1;
codec.sound_type = 1; codec.sound_type_ = 1;
codec.aac_packet_type = 4; codec.aac_packet_type_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv)); HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv));
EXPECT_EQ(6, nb_flv); EXPECT_EQ(6, nb_flv);
EXPECT_EQ(0xd3, (uint8_t)flv[0]); EXPECT_EQ(0xd3, (uint8_t)flv[0]);
@ -641,11 +641,11 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
char *flv = NULL; char *flv = NULL;
int nb_flv = 0; int nb_flv = 0;
codec.sound_format = SrsAudioCodecIdSpeex; codec.sound_format_ = SrsAudioCodecIdSpeex;
codec.sound_rate = 0; codec.sound_rate_ = 0;
codec.sound_size = 1; codec.sound_size_ = 1;
codec.sound_type = 1; codec.sound_type_ = 1;
codec.aac_packet_type = 4; codec.aac_packet_type_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv)); HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv));
EXPECT_EQ(6, nb_flv); EXPECT_EQ(6, nb_flv);
EXPECT_EQ(0xb3, (uint8_t)flv[0]); EXPECT_EQ(0xb3, (uint8_t)flv[0]);
@ -660,11 +660,11 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
char *flv = NULL; char *flv = NULL;
int nb_flv = 0; int nb_flv = 0;
codec.sound_format = SrsAudioCodecIdAAC; codec.sound_format_ = SrsAudioCodecIdAAC;
codec.sound_rate = 0; codec.sound_rate_ = 0;
codec.sound_size = 1; codec.sound_size_ = 1;
codec.sound_type = 1; codec.sound_type_ = 1;
codec.aac_packet_type = 4; codec.aac_packet_type_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv)); HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv));
EXPECT_EQ(7, nb_flv); EXPECT_EQ(7, nb_flv);
EXPECT_EQ(0xa3, (uint8_t)flv[0]); EXPECT_EQ(0xa3, (uint8_t)flv[0]);
@ -678,11 +678,11 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
char *flv = NULL; char *flv = NULL;
int nb_flv = 0; int nb_flv = 0;
codec.sound_format = SrsAudioCodecIdAAC; codec.sound_format_ = SrsAudioCodecIdAAC;
codec.sound_rate = 1; codec.sound_rate_ = 1;
codec.sound_size = 1; codec.sound_size_ = 1;
codec.sound_type = 0; codec.sound_type_ = 0;
codec.aac_packet_type = 4; codec.aac_packet_type_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv)); HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv));
EXPECT_EQ(7, nb_flv); EXPECT_EQ(7, nb_flv);
EXPECT_EQ(0xa6, (uint8_t)flv[0]); EXPECT_EQ(0xa6, (uint8_t)flv[0]);
@ -696,11 +696,11 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
char *flv = NULL; char *flv = NULL;
int nb_flv = 0; int nb_flv = 0;
codec.sound_format = SrsAudioCodecIdAAC; codec.sound_format_ = SrsAudioCodecIdAAC;
codec.sound_rate = 1; codec.sound_rate_ = 1;
codec.sound_size = 0; codec.sound_size_ = 0;
codec.sound_type = 1; codec.sound_type_ = 1;
codec.aac_packet_type = 4; codec.aac_packet_type_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv)); HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv));
EXPECT_EQ(7, nb_flv); EXPECT_EQ(7, nb_flv);
EXPECT_EQ(0xa5, (uint8_t)flv[0]); EXPECT_EQ(0xa5, (uint8_t)flv[0]);
@ -714,11 +714,11 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
char *flv = NULL; char *flv = NULL;
int nb_flv = 0; int nb_flv = 0;
codec.sound_format = SrsAudioCodecIdAAC; codec.sound_format_ = SrsAudioCodecIdAAC;
codec.sound_rate = 1; codec.sound_rate_ = 1;
codec.sound_size = 1; codec.sound_size_ = 1;
codec.sound_type = 1; codec.sound_type_ = 1;
codec.aac_packet_type = 4; codec.aac_packet_type_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv)); HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv));
EXPECT_EQ(7, nb_flv); EXPECT_EQ(7, nb_flv);
EXPECT_EQ(0xa7, (uint8_t)flv[0]); EXPECT_EQ(0xa7, (uint8_t)flv[0]);
@ -732,11 +732,11 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
SrsRawAacStreamCodec codec; SrsRawAacStreamCodec codec;
char *flv = NULL; char *flv = NULL;
int nb_flv = 0; int nb_flv = 0;
codec.sound_format = SrsAudioCodecIdAAC; codec.sound_format_ = SrsAudioCodecIdAAC;
codec.sound_rate = 3; codec.sound_rate_ = 3;
codec.sound_size = 1; codec.sound_size_ = 1;
codec.sound_type = 1; codec.sound_type_ = 1;
codec.aac_packet_type = 4; codec.aac_packet_type_ = 4;
HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv)); HELPER_ASSERT_SUCCESS(h.mux_aac2flv((char *)frame.data(), frame.length(), &codec, 0, &flv, &nb_flv));
EXPECT_EQ(7, nb_flv); EXPECT_EQ(7, nb_flv);
EXPECT_EQ(0xaf, (uint8_t)flv[0]); EXPECT_EQ(0xaf, (uint8_t)flv[0]);

View File

@ -2488,8 +2488,8 @@ VOID TEST(ConfigUnitTest, ApplyFilter)
if (true) { if (true) {
SrsConfDirective d; SrsConfDirective d;
SrsRequest r; SrsRequest r;
r.app = "live"; r.app_ = "live";
r.stream = "stream"; r.stream_ = "stream";
d.args.push_back("live/stream"); d.args.push_back("live/stream");
EXPECT_TRUE(srs_config_apply_filter(&d, &r)); EXPECT_TRUE(srs_config_apply_filter(&d, &r));
} }

View File

@ -24,9 +24,9 @@ class MockSrsRequest : public SrsRequest
public: public:
MockSrsRequest() MockSrsRequest()
{ {
vhost = "__defaultVhost__"; vhost_ = "__defaultVhost__";
app = "live"; app_ = "live";
stream = "livestream"; stream_ = "livestream";
} }
virtual ~MockSrsRequest() {} virtual ~MockSrsRequest() {}
}; };

View File

@ -1236,7 +1236,7 @@ VOID TEST(ProtocolHTTPTest, HTTPServerMuxerAuth)
HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "123456")); HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "123456"));
HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r)); HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r));
EXPECT_EQ(401, w.w->status); EXPECT_EQ(401, w.w->status_);
} }
// incorrect token, duplicate Basic // incorrect token, duplicate Basic
@ -1261,7 +1261,7 @@ VOID TEST(ProtocolHTTPTest, HTTPServerMuxerAuth)
HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "admin")); HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "admin"));
HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r)); HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r));
EXPECT_EQ(401, w.w->status); EXPECT_EQ(401, w.w->status_);
} }
// Authorization NOT start with 'Basic ' // Authorization NOT start with 'Basic '
@ -1286,7 +1286,7 @@ VOID TEST(ProtocolHTTPTest, HTTPServerMuxerAuth)
HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "admin")); HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "admin"));
HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r)); HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r));
EXPECT_EQ(401, w.w->status); EXPECT_EQ(401, w.w->status_);
} }
// NOT base64 // NOT base64
@ -1311,7 +1311,7 @@ VOID TEST(ProtocolHTTPTest, HTTPServerMuxerAuth)
HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "admin")); HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "admin"));
HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r)); HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r));
EXPECT_EQ(401, w.w->status); EXPECT_EQ(401, w.w->status_);
} }
// empty Authorization // empty Authorization
@ -1331,7 +1331,7 @@ VOID TEST(ProtocolHTTPTest, HTTPServerMuxerAuth)
HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "admin")); HELPER_ASSERT_SUCCESS(auth.initialize(true, "admin", "admin"));
HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r)); HELPER_ASSERT_SUCCESS(auth.serve_http(&w, &r));
EXPECT_EQ(401, w.w->status); EXPECT_EQ(401, w.w->status_);
} }
// auth disabled, response with 200 ok, even though empty Authorization // auth disabled, response with 200 ok, even though empty Authorization

View File

@ -663,18 +663,18 @@ VOID TEST(ProtocolHandshakeTest, VerifyFPC0C1)
EXPECT_EQ(0x03, c0c1[0]); EXPECT_EQ(0x03, c0c1[0]);
// c1 // c1
c1s1 c1; SrsC1S1 c1;
// the schema of data must be schema0: key-digest. // the schema of data must be schema0: key-digest.
HELPER_ASSERT_SUCCESS(c1.parse((char *)c0c1 + 1, 1536, srs_schema0)); HELPER_ASSERT_SUCCESS(c1.parse((char *)c0c1 + 1, 1536, srs_schema0));
EXPECT_EQ((int32_t)0x000f64d0, c1.time); EXPECT_EQ((int32_t)0x000f64d0, c1.time_);
EXPECT_EQ((int32_t)0x80000702, c1.version); EXPECT_EQ((int32_t)0x80000702, c1.version_);
// manually validate the c1 // manually validate the c1
// @see: calc_c1_digest // @see: calc_c1_digest
char *c1s1_joined_bytes = new char[1536 - 32]; char *c1s1_joined_bytes = new char[1536 - 32];
SrsUniquePtr<char[]> cp_uptr(c1s1_joined_bytes); SrsUniquePtr<char[]> cp_uptr(c1s1_joined_bytes);
HELPER_ASSERT_SUCCESS(c1.payload->copy_to(&c1, c1s1_joined_bytes, 1536 - 32, false)); HELPER_ASSERT_SUCCESS(c1.payload_->copy_to(&c1, c1s1_joined_bytes, 1536 - 32, false));
bool is_valid; bool is_valid;
HELPER_ASSERT_SUCCESS(c1.c1_validate_digest(is_valid)); HELPER_ASSERT_SUCCESS(c1.c1_validate_digest(is_valid));
@ -713,34 +713,34 @@ VOID TEST(ProtocolHandshakeTest, ComplexHandshake)
SrsHandshakeBytes bytes; SrsHandshakeBytes bytes;
if (true) { if (true) {
HELPER_ASSERT_SUCCESS(bytes.create_c0c1()); HELPER_ASSERT_SUCCESS(bytes.create_c0c1());
memcpy(bytes.c0c1, c0c1, 1537); memcpy(bytes.c0c1_, c0c1, 1537);
HELPER_ASSERT_SUCCESS(bytes.create_s0s1s2()); HELPER_ASSERT_SUCCESS(bytes.create_s0s1s2());
memcpy(bytes.s0s1s2, s0s1s2, 3073); memcpy(bytes.s0s1s2_, s0s1s2, 3073);
HELPER_ASSERT_SUCCESS(bytes.create_c2()); HELPER_ASSERT_SUCCESS(bytes.create_c2());
memcpy(bytes.c2, c2, 1536); memcpy(bytes.c2_, c2, 1536);
} }
SrsHandshakeBytes *hs_bytes = &bytes; SrsHandshakeBytes *hs_bytes = &bytes;
if (true) { if (true) {
bool is_valid; bool is_valid;
c1s1 c1; SrsC1S1 c1;
HELPER_ASSERT_SUCCESS(c1.parse(hs_bytes->c0c1 + 1, 1536, srs_schema0)); HELPER_ASSERT_SUCCESS(c1.parse(hs_bytes->c0c1_ + 1, 1536, srs_schema0));
HELPER_ASSERT_SUCCESS(c1.c1_validate_digest(is_valid)); HELPER_ASSERT_SUCCESS(c1.c1_validate_digest(is_valid));
ASSERT_TRUE(is_valid); ASSERT_TRUE(is_valid);
c1s1 s1; SrsC1S1 s1;
HELPER_ASSERT_SUCCESS(s1.parse(hs_bytes->s0s1s2 + 1, 1536, c1.schema())); HELPER_ASSERT_SUCCESS(s1.parse(hs_bytes->s0s1s2_ + 1, 1536, c1.schema()));
HELPER_ASSERT_SUCCESS(s1.s1_validate_digest(is_valid)); HELPER_ASSERT_SUCCESS(s1.s1_validate_digest(is_valid));
ASSERT_TRUE(is_valid); ASSERT_TRUE(is_valid);
c2s2 c2; SrsC2S2 c2;
c2.parse(hs_bytes->c2, 1536); c2.parse(hs_bytes->c2_, 1536);
HELPER_ASSERT_SUCCESS(c2.c2_validate(&s1, is_valid)); HELPER_ASSERT_SUCCESS(c2.c2_validate(&s1, is_valid));
ASSERT_TRUE(is_valid); ASSERT_TRUE(is_valid);
c2s2 s2; SrsC2S2 s2;
s2.parse(hs_bytes->s0s1s2 + 1 + 1536, 1536); s2.parse(hs_bytes->s0s1s2_ + 1 + 1536, 1536);
HELPER_ASSERT_SUCCESS(s2.s2_validate(&c1, is_valid)); HELPER_ASSERT_SUCCESS(s2.s2_validate(&c1, is_valid));
ASSERT_TRUE(is_valid); ASSERT_TRUE(is_valid);
} }
@ -790,11 +790,11 @@ VOID TEST(ProtocolHandshakeTest, SimpleHandshake)
if (true) { if (true) {
SrsHandshakeBytes bytes; SrsHandshakeBytes bytes;
HELPER_ASSERT_SUCCESS(bytes.create_c0c1()); HELPER_ASSERT_SUCCESS(bytes.create_c0c1());
memcpy(bytes.c0c1, c0c1, 1537); memcpy(bytes.c0c1_, c0c1, 1537);
HELPER_ASSERT_SUCCESS(bytes.create_s0s1s2()); HELPER_ASSERT_SUCCESS(bytes.create_s0s1s2());
memcpy(bytes.s0s1s2, s0s1s2, 3073); memcpy(bytes.s0s1s2_, s0s1s2, 3073);
HELPER_ASSERT_SUCCESS(bytes.create_c2()); HELPER_ASSERT_SUCCESS(bytes.create_c2());
memcpy(bytes.c2, c2, 1536); memcpy(bytes.c2_, c2, 1536);
MockEmptyIO eio; MockEmptyIO eio;
SrsSimpleHandshake hs; SrsSimpleHandshake hs;
@ -883,8 +883,8 @@ VOID TEST(ProtocolUtilityTest, GenerateTcUrl)
void srs_utest_free_message_array(SrsMessageArray *arr) void srs_utest_free_message_array(SrsMessageArray *arr)
{ {
for (int i = 0; i < arr->max; i++) { for (int i = 0; i < arr->max_; i++) {
srs_freep(arr->msgs[i]); srs_freep(arr->msgs_[i]);
} }
} }
@ -908,11 +908,11 @@ VOID TEST(ProtocolMsgArrayTest, MessageArray)
SrsMessageArray *parr = &arr; SrsMessageArray *parr = &arr;
SrsUniquePtr<SrsMessageArray> parr2(parr, srs_utest_free_message_array); SrsUniquePtr<SrsMessageArray> parr2(parr, srs_utest_free_message_array);
arr.msgs[0] = msg.copy(); arr.msgs_[0] = msg.copy();
arr.msgs[1] = msg.copy(); arr.msgs_[1] = msg.copy();
arr.msgs[2] = msg.copy(); arr.msgs_[2] = msg.copy();
} }
if (true) { if (true) {
@ -921,9 +921,9 @@ VOID TEST(ProtocolMsgArrayTest, MessageArray)
SrsMessageArray *parr = &arr; SrsMessageArray *parr = &arr;
SrsUniquePtr<SrsMessageArray> parr2(parr, srs_utest_free_message_array); SrsUniquePtr<SrsMessageArray> parr2(parr, srs_utest_free_message_array);
arr.msgs[0] = msg.copy(); arr.msgs_[0] = msg.copy();
arr.msgs[2] = msg.copy(); arr.msgs_[2] = msg.copy();
} }
} }
@ -1057,8 +1057,8 @@ VOID TEST(ProtocolStackTest, ProtocolRecvMessageBug98)
SrsUserControlPacket *spkt = dynamic_cast<SrsUserControlPacket *>(pkt); SrsUserControlPacket *spkt = dynamic_cast<SrsUserControlPacket *>(pkt);
ASSERT_TRUE(NULL != spkt); ASSERT_TRUE(NULL != spkt);
EXPECT_EQ(SrcPCUCPingRequest, spkt->event_type); EXPECT_EQ(SrcPCUCPingRequest, spkt->event_type_);
EXPECT_EQ(0x0d0f, spkt->event_data); EXPECT_EQ(0x0d0f, spkt->event_data_);
} }
/** /**
@ -1093,7 +1093,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvAckSizeMessage)
SrsSetWindowAckSizePacket *spkt = dynamic_cast<SrsSetWindowAckSizePacket *>(pkt); SrsSetWindowAckSizePacket *spkt = dynamic_cast<SrsSetWindowAckSizePacket *>(pkt);
ASSERT_TRUE(NULL != spkt); ASSERT_TRUE(NULL != spkt);
EXPECT_EQ(0x0763, spkt->ackowledgement_window_size); EXPECT_EQ(0x0763, spkt->ackowledgement_window_size_);
} }
/** /**
@ -4395,9 +4395,9 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsCallPacket)
SrsAmf0Object *args = SrsAmf0Any::object(); SrsAmf0Object *args = SrsAmf0Any::object();
SrsCallPacket *pkt = new SrsCallPacket(); SrsCallPacket *pkt = new SrsCallPacket();
pkt->command_name = "my_call"; pkt->command_name_ = "my_call";
pkt->command_object = SrsAmf0Any::null(); pkt->command_object_ = SrsAmf0Any::null();
pkt->arguments = args; pkt->arguments_ = args;
args->set("video_id", SrsAmf0Any::number(100)); args->set("video_id", SrsAmf0Any::number(100));
args->set("url", SrsAmf0Any::str("http://ossrs.net/api/v1/videos/100")); args->set("url", SrsAmf0Any::str("http://ossrs.net/api/v1/videos/100"));
@ -4438,9 +4438,9 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsCallResPacket)
SrsAmf0Object *args = SrsAmf0Any::object(); SrsAmf0Object *args = SrsAmf0Any::object();
SrsCallResPacket *pkt = new SrsCallResPacket(0); SrsCallResPacket *pkt = new SrsCallResPacket(0);
pkt->command_name = "_result"; pkt->command_name_ = "_result";
pkt->command_object = SrsAmf0Any::null(); pkt->command_object_ = SrsAmf0Any::null();
pkt->response = args; pkt->response_ = args;
args->set("video_id", SrsAmf0Any::number(100)); args->set("video_id", SrsAmf0Any::number(100));
args->set("url", SrsAmf0Any::str("http://ossrs.net/api/v1/videos/100")); args->set("url", SrsAmf0Any::str("http://ossrs.net/api/v1/videos/100"));
@ -4502,9 +4502,9 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartPacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsFMLEStartPacket *pkt = new SrsFMLEStartPacket(); SrsFMLEStartPacket *pkt = new SrsFMLEStartPacket();
pkt->command_name = "FMLEStart"; pkt->command_name_ = "FMLEStart";
pkt->set_command_object(SrsAmf0Any::null()); pkt->set_command_object(SrsAmf0Any::null());
pkt->stream_name = "livestream"; pkt->stream_name_ = "livestream";
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -4530,7 +4530,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartResPacket)
SrsAmf0Object *args = SrsAmf0Any::object(); SrsAmf0Object *args = SrsAmf0Any::object();
SrsFMLEStartResPacket *pkt = new SrsFMLEStartResPacket(1); SrsFMLEStartResPacket *pkt = new SrsFMLEStartResPacket(1);
pkt->command_name = "FMLEStart"; pkt->command_name_ = "FMLEStart";
pkt->set_command_object(SrsAmf0Any::null()); pkt->set_command_object(SrsAmf0Any::null());
pkt->set_args(args); pkt->set_args(args);
@ -4558,10 +4558,10 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsPublishPacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsPublishPacket *pkt = new SrsPublishPacket(); SrsPublishPacket *pkt = new SrsPublishPacket();
pkt->command_name = "publish"; pkt->command_name_ = "publish";
pkt->set_command_object(SrsAmf0Any::null()); pkt->set_command_object(SrsAmf0Any::null());
pkt->stream_name = "livestream"; pkt->stream_name_ = "livestream";
pkt->type = "live"; pkt->type_ = "live";
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
uint8_t buf[] = { uint8_t buf[] = {
@ -4588,7 +4588,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsPlayResPacket)
SrsAmf0Object *args = SrsAmf0Any::object(); SrsAmf0Object *args = SrsAmf0Any::object();
SrsPlayResPacket *pkt = new SrsPlayResPacket(); SrsPlayResPacket *pkt = new SrsPlayResPacket();
pkt->command_name = "_result"; pkt->command_name_ = "_result";
pkt->set_command_object(SrsAmf0Any::null()); pkt->set_command_object(SrsAmf0Any::null());
pkt->set_desc(args); pkt->set_desc(args);
@ -4621,7 +4621,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnBWDonePacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsOnBWDonePacket *pkt = new SrsOnBWDonePacket(); SrsOnBWDonePacket *pkt = new SrsOnBWDonePacket();
pkt->command_name = "onBWDone"; pkt->command_name_ = "onBWDone";
pkt->set_args(SrsAmf0Any::null()); pkt->set_args(SrsAmf0Any::null());
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
@ -4650,7 +4650,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusCallPacket)
args->set("start", SrsAmf0Any::number(0)); args->set("start", SrsAmf0Any::number(0));
SrsOnStatusCallPacket *pkt = new SrsOnStatusCallPacket(); SrsOnStatusCallPacket *pkt = new SrsOnStatusCallPacket();
pkt->command_name = "onStatus"; pkt->command_name_ = "onStatus";
pkt->set_args(SrsAmf0Any::null()); pkt->set_args(SrsAmf0Any::null());
pkt->set_data(args); pkt->set_data(args);
@ -4685,7 +4685,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusDataPacket)
args->set("start", SrsAmf0Any::number(0)); args->set("start", SrsAmf0Any::number(0));
SrsOnStatusDataPacket *pkt = new SrsOnStatusDataPacket(); SrsOnStatusDataPacket *pkt = new SrsOnStatusDataPacket();
pkt->command_name = "onData"; pkt->command_name_ = "onData";
pkt->set_data(args); pkt->set_data(args);
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
@ -4712,9 +4712,9 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsNaluSampleAccessPacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsNaluSampleAccessPacket *pkt = new SrsNaluSampleAccessPacket(); SrsNaluSampleAccessPacket *pkt = new SrsNaluSampleAccessPacket();
pkt->command_name = "|RtmpSampleAccess"; pkt->command_name_ = "|RtmpSampleAccess";
pkt->video_sample_access = true; pkt->video_sample_access_ = true;
pkt->audio_sample_access = true; pkt->audio_sample_access_ = true;
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -4742,7 +4742,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnMetaDataPacket)
args->set("height", SrsAmf0Any::number(576)); args->set("height", SrsAmf0Any::number(576));
SrsOnMetaDataPacket *pkt = new SrsOnMetaDataPacket(); SrsOnMetaDataPacket *pkt = new SrsOnMetaDataPacket();
pkt->name = "onMetaData"; pkt->name_ = "onMetaData";
pkt->set_metadata(args); pkt->set_metadata(args);
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
@ -4769,7 +4769,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsSetWindowAckSizePacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsSetWindowAckSizePacket *pkt = new SrsSetWindowAckSizePacket(); SrsSetWindowAckSizePacket *pkt = new SrsSetWindowAckSizePacket();
pkt->ackowledgement_window_size = 102400; pkt->ackowledgement_window_size_ = 102400;
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
uint8_t buf[] = { uint8_t buf[] = {
@ -4789,7 +4789,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsAcknowledgementPacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsAcknowledgementPacket *pkt = new SrsAcknowledgementPacket(); SrsAcknowledgementPacket *pkt = new SrsAcknowledgementPacket();
pkt->sequence_number = 1024; pkt->sequence_number_ = 1024;
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -4809,7 +4809,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsSetChunkSizePacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsSetChunkSizePacket *pkt = new SrsSetChunkSizePacket(); SrsSetChunkSizePacket *pkt = new SrsSetChunkSizePacket();
pkt->chunk_size = 1024; pkt->chunk_size_ = 1024;
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -4829,8 +4829,8 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsSetPeerBandwidthPacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsSetPeerBandwidthPacket *pkt = new SrsSetPeerBandwidthPacket(); SrsSetPeerBandwidthPacket *pkt = new SrsSetPeerBandwidthPacket();
pkt->type = SrsPeerBandwidthSoft; pkt->type_ = SrsPeerBandwidthSoft;
pkt->bandwidth = 1024; pkt->bandwidth_ = 1024;
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -4851,9 +4851,9 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsUserControlPacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsUserControlPacket *pkt = new SrsUserControlPacket(); SrsUserControlPacket *pkt = new SrsUserControlPacket();
pkt->event_type = SrcPCUCSetBufferLength; pkt->event_type_ = SrcPCUCSetBufferLength;
pkt->event_data = 0x01; pkt->event_data_ = 0x01;
pkt->extra_data = 0x10; pkt->extra_data_ = 0x10;
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -4925,7 +4925,7 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow)
if (true) { if (true) {
SrsSetWindowAckSizePacket *pkt = new SrsSetWindowAckSizePacket(); SrsSetWindowAckSizePacket *pkt = new SrsSetWindowAckSizePacket();
pkt->ackowledgement_window_size = 512; pkt->ackowledgement_window_size_ = 512;
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
} }
@ -5034,8 +5034,8 @@ VOID TEST(ProtocolStackTest, ProtocolPingFlow)
// ping request // ping request
if (true) { if (true) {
SrsUserControlPacket *pkt = new SrsUserControlPacket(); SrsUserControlPacket *pkt = new SrsUserControlPacket();
pkt->event_type = SrcPCUCPingRequest; pkt->event_type_ = SrcPCUCPingRequest;
pkt->event_data = 0x3456; pkt->event_data_ = 0x3456;
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
} }
// copy output to input // copy output to input
@ -5071,8 +5071,8 @@ VOID TEST(ProtocolStackTest, ProtocolPingFlow)
SrsUserControlPacket *spkt = dynamic_cast<SrsUserControlPacket *>(pkt); SrsUserControlPacket *spkt = dynamic_cast<SrsUserControlPacket *>(pkt);
ASSERT_TRUE(spkt != NULL); ASSERT_TRUE(spkt != NULL);
EXPECT_TRUE(SrcPCUCPingResponse == spkt->event_type); EXPECT_TRUE(SrcPCUCPingResponse == spkt->event_type_);
EXPECT_TRUE(0x3456 == spkt->event_data); EXPECT_TRUE(0x3456 == spkt->event_data_);
} }
} }
@ -5136,78 +5136,78 @@ VOID TEST(ProtocolRTMPTest, RTMPRequest)
SrsRequest req; SrsRequest req;
std::string param; std::string param;
req.stream = "livestream"; req.stream_ = "livestream";
srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live", srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
req.strip(); req.strip();
EXPECT_STREQ("rtmp", req.schema.c_str()); EXPECT_STREQ("rtmp", req.schema_.c_str());
EXPECT_STREQ("std.ossrs.net", req.host.c_str()); EXPECT_STREQ("std.ossrs.net", req.host_.c_str());
EXPECT_STREQ("std.ossrs.net", req.vhost.c_str()); EXPECT_STREQ("std.ossrs.net", req.vhost_.c_str());
EXPECT_STREQ("live", req.app.c_str()); EXPECT_STREQ("live", req.app_.c_str());
EXPECT_EQ(1935, req.port); EXPECT_EQ(1935, req.port_);
req.stream = "livestream"; req.stream_ = "livestream";
srs_net_url_parse_tcurl("rtmp://s td.os srs.n et/li v e", srs_net_url_parse_tcurl("rtmp://s td.os srs.n et/li v e",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
req.strip(); req.strip();
EXPECT_STREQ("rtmp", req.schema.c_str()); EXPECT_STREQ("rtmp", req.schema_.c_str());
EXPECT_STREQ("std.ossrs.net", req.host.c_str()); EXPECT_STREQ("std.ossrs.net", req.host_.c_str());
EXPECT_STREQ("std.ossrs.net", req.vhost.c_str()); EXPECT_STREQ("std.ossrs.net", req.vhost_.c_str());
EXPECT_STREQ("live", req.app.c_str()); EXPECT_STREQ("live", req.app_.c_str());
EXPECT_EQ(1935, req.port); EXPECT_EQ(1935, req.port_);
req.stream = "livestream"; req.stream_ = "livestream";
srs_net_url_parse_tcurl("rtmp://s\ntd.o\rssrs.ne\nt/li\nve", srs_net_url_parse_tcurl("rtmp://s\ntd.o\rssrs.ne\nt/li\nve",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
req.strip(); req.strip();
EXPECT_STREQ("rtmp", req.schema.c_str()); EXPECT_STREQ("rtmp", req.schema_.c_str());
EXPECT_STREQ("std.ossrs.net", req.host.c_str()); EXPECT_STREQ("std.ossrs.net", req.host_.c_str());
EXPECT_STREQ("std.ossrs.net", req.vhost.c_str()); EXPECT_STREQ("std.ossrs.net", req.vhost_.c_str());
EXPECT_STREQ("live", req.app.c_str()); EXPECT_STREQ("live", req.app_.c_str());
EXPECT_EQ(1935, req.port); EXPECT_EQ(1935, req.port_);
req.stream = "livestream"; req.stream_ = "livestream";
srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live ", srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live ",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
req.strip(); req.strip();
EXPECT_STREQ("rtmp", req.schema.c_str()); EXPECT_STREQ("rtmp", req.schema_.c_str());
EXPECT_STREQ("std.ossrs.net", req.host.c_str()); EXPECT_STREQ("std.ossrs.net", req.host_.c_str());
EXPECT_STREQ("std.ossrs.net", req.vhost.c_str()); EXPECT_STREQ("std.ossrs.net", req.vhost_.c_str());
EXPECT_STREQ("live", req.app.c_str()); EXPECT_STREQ("live", req.app_.c_str());
EXPECT_EQ(1935, req.port); EXPECT_EQ(1935, req.port_);
EXPECT_TRUE(NULL == req.args); EXPECT_TRUE(NULL == req.args_);
SrsRequest req1; SrsRequest req1;
req1.args = SrsAmf0Any::object(); req1.args_ = SrsAmf0Any::object();
req.update_auth(&req1); req.update_auth(&req1);
EXPECT_TRUE(NULL != req.args); EXPECT_TRUE(NULL != req.args_);
EXPECT_TRUE(req1.args != req.args); EXPECT_TRUE(req1.args_ != req.args_);
param = ""; param = "";
req.stream = "livestream"; req.stream_ = "livestream";
srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live#b=2", srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live#b=2",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
EXPECT_STREQ("#b=2/livestream", param.c_str()); EXPECT_STREQ("#b=2/livestream", param.c_str());
param = ""; param = "";
req.stream = "livestream"; req.stream_ = "livestream";
srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live?a=1#b=2", srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live?a=1#b=2",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
EXPECT_STREQ("?a=1#b=2", param.c_str()); EXPECT_STREQ("?a=1#b=2", param.c_str());
param = ""; param = "";
srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live?a=1&c=3#b=2", srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live?a=1&c=3#b=2",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
EXPECT_STREQ("?a=1&c=3#b=2", param.c_str()); EXPECT_STREQ("?a=1&c=3#b=2", param.c_str());
param = ""; param = "";
srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live?a=1&c=3#b=2#d=4", srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live?a=1&c=3#b=2#d=4",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
EXPECT_STREQ("?a=1&c=3#b=2#d=4", param.c_str()); EXPECT_STREQ("?a=1&c=3#b=2#d=4", param.c_str());
param = ""; param = "";
srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live?a=1#e=5&c=3#b=2#d=4", srs_net_url_parse_tcurl("rtmp://std.ossrs.net/live?a=1#e=5&c=3#b=2#d=4",
req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); req.schema_, req.host_, req.vhost_, req.app_, req.stream_, req.port_, param);
EXPECT_STREQ("?a=1#e=5&c=3#b=2#d=4", param.c_str()); EXPECT_STREQ("?a=1#e=5&c=3#b=2#d=4", param.c_str());
} }
@ -5223,13 +5223,13 @@ VOID TEST(ProtocolRTMPTest, RTMPHandshakeBytes)
bio.in_buffer.append(hs, sizeof(hs)); bio.in_buffer.append(hs, sizeof(hs));
HELPER_EXPECT_SUCCESS(bytes.read_c0c1(&bio)); HELPER_EXPECT_SUCCESS(bytes.read_c0c1(&bio));
EXPECT_TRUE(bytes.c0c1 != NULL); EXPECT_TRUE(bytes.c0c1_ != NULL);
HELPER_EXPECT_SUCCESS(bytes.read_c2(&bio)); HELPER_EXPECT_SUCCESS(bytes.read_c2(&bio));
EXPECT_TRUE(bytes.c2 != NULL); EXPECT_TRUE(bytes.c2_ != NULL);
HELPER_EXPECT_SUCCESS(bytes.read_s0s1s2(&bio)); HELPER_EXPECT_SUCCESS(bytes.read_s0s1s2(&bio));
EXPECT_TRUE(bytes.s0s1s2 != NULL); EXPECT_TRUE(bytes.s0s1s2_ != NULL);
} }
#ifdef SRS_RTSP #ifdef SRS_RTSP

View File

@ -138,7 +138,7 @@ VOID TEST(ProtocolRTMPTest, ManualFlush)
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1)); HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
p.set_auto_response(true); p.set_auto_response(true);
HELPER_EXPECT_SUCCESS(p.protocol->response_acknowledgement_message()); HELPER_EXPECT_SUCCESS(p.protocol_->response_acknowledgement_message());
EXPECT_EQ(12 + 4, io.out_buffer.length()); EXPECT_EQ(12 + 4, io.out_buffer.length());
} }
@ -424,7 +424,7 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsSetChunkSizePacket *pkt = new SrsSetChunkSizePacket(); SrsSetChunkSizePacket *pkt = new SrsSetChunkSizePacket();
pkt->chunk_size = 0; pkt->chunk_size_ = 0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 1)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 1));
bytes.append(&io.out_buffer); bytes.append(&io.out_buffer);
@ -471,7 +471,7 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages2)
SrsUniquePtr<SrsRtmpCommand> pkt_uptr(pkt); SrsUniquePtr<SrsRtmpCommand> pkt_uptr(pkt);
SrsCallPacket *call = (SrsCallPacket *)pkt; SrsCallPacket *call = (SrsCallPacket *)pkt;
EXPECT_STREQ("s", call->command_name.c_str()); EXPECT_STREQ("s", call->command_name_.c_str());
} }
if (true) { if (true) {
@ -571,7 +571,7 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsConnectAppPacket *request = new SrsConnectAppPacket(); SrsConnectAppPacket *request = new SrsConnectAppPacket();
request->transaction_id = 0.0; request->transaction_id_ = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0};
@ -589,7 +589,7 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsCreateStreamPacket *request = new SrsCreateStreamPacket(); SrsCreateStreamPacket *request = new SrsCreateStreamPacket();
request->transaction_id = 0.0; request->transaction_id_ = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0};
@ -607,7 +607,7 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsFMLEStartPacket *request = SrsFMLEStartPacket::create_FC_publish("livestream"); SrsFMLEStartPacket *request = SrsFMLEStartPacket::create_FC_publish("livestream");
request->transaction_id = 0.0; request->transaction_id_ = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0};
@ -625,7 +625,7 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsFMLEStartPacket *request = SrsFMLEStartPacket::create_release_stream("livestream"); SrsFMLEStartPacket *request = SrsFMLEStartPacket::create_release_stream("livestream");
request->transaction_id = 0.0; request->transaction_id_ = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0};
@ -643,8 +643,8 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsFMLEStartPacket *request = SrsFMLEStartPacket::create_release_stream("livestream"); SrsFMLEStartPacket *request = SrsFMLEStartPacket::create_release_stream("livestream");
request->command_name = RTMP_AMF0_COMMAND_UNPUBLISH; request->command_name_ = RTMP_AMF0_COMMAND_UNPUBLISH;
request->transaction_id = 0.0; request->transaction_id_ = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0};
@ -662,8 +662,8 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsFMLEStartPacket *request = new SrsFMLEStartPacket(); SrsFMLEStartPacket *request = new SrsFMLEStartPacket();
request->command_name = "srs"; request->command_name_ = "srs";
request->transaction_id = 0.0; request->transaction_id_ = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t bytes[] = {0x02, 0x00, 0x07, '_', 'r', 'e', 's', 'u', 'l', 't', 0x00, 0, 0, 0, 0, 0, 0, 0, 0};
@ -920,7 +920,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
MockBufferIO io; MockBufferIO io;
SrsProtocol p(&io); SrsProtocol p(&io);
p.in_chunk_size = 3; p.in_chunk_size_ = 3;
uint8_t bytes[] = {0x03, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 2, 3}; uint8_t bytes[] = {0x03, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 2, 3};
io.in_buffer.append((char *)bytes, sizeof(bytes)); io.in_buffer.append((char *)bytes, sizeof(bytes));
@ -967,25 +967,25 @@ VOID TEST(ProtocolRTMPTest, RecvMessage3)
{ {
if (true) { if (true) {
SrsRequest req; SrsRequest req;
req.ip = "10.11.12.13"; req.ip_ = "10.11.12.13";
ISrsRequest *cp = req.copy(); ISrsRequest *cp = req.copy();
EXPECT_STREQ("10.11.12.13", cp->ip.c_str()); EXPECT_STREQ("10.11.12.13", cp->ip_.c_str());
srs_freep(cp); srs_freep(cp);
} }
if (true) { if (true) {
SrsRequest req; SrsRequest req;
req.ip = "10.11.12.13"; req.ip_ = "10.11.12.13";
SrsAmf0Object *obj = SrsAmf0Any::object(); SrsAmf0Object *obj = SrsAmf0Any::object();
obj->set("id", SrsAmf0Any::str("srs")); obj->set("id", SrsAmf0Any::str("srs"));
req.args = obj; req.args_ = obj;
ISrsRequest *cp = req.copy(); ISrsRequest *cp = req.copy();
EXPECT_STREQ("10.11.12.13", cp->ip.c_str()); EXPECT_STREQ("10.11.12.13", cp->ip_.c_str());
SrsAmf0Object *cpa = dynamic_cast<SrsAmf0Object *>(cp->args); SrsAmf0Object *cpa = dynamic_cast<SrsAmf0Object *>(cp->args_);
SrsAmf0Any *cps = cpa->ensure_property_string("id"); SrsAmf0Any *cps = cpa->ensure_property_string("id");
EXPECT_STREQ("srs", cps->to_str().c_str()); EXPECT_STREQ("srs", cps->to_str().c_str());
srs_freep(cp); srs_freep(cp);
@ -998,15 +998,15 @@ VOID TEST(ProtocolRTMPTest, RecvMessage3)
if (true) { if (true) {
SrsRequest req; SrsRequest req;
EXPECT_STREQ("", req.schema.c_str()); EXPECT_STREQ("", req.schema_.c_str());
req.as_http(); req.as_http();
EXPECT_STREQ("http", req.schema.c_str()); EXPECT_STREQ("http", req.schema_.c_str());
} }
if (true) { if (true) {
SrsResponse res; SrsResponse res;
EXPECT_EQ(1, res.stream_id); EXPECT_EQ(1, res.stream_id_);
} }
if (true) { if (true) {
@ -1036,7 +1036,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsSetChunkSizePacket *pkt = new SrsSetChunkSizePacket(); SrsSetChunkSizePacket *pkt = new SrsSetChunkSizePacket();
pkt->chunk_size = 256; pkt->chunk_size_ = 256;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 0));
io.in_buffer.append(&io.out_buffer); io.in_buffer.append(&io.out_buffer);
@ -1045,7 +1045,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4)
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
SrsUniquePtr<SrsRtmpCommonMessage> msg_uptr(msg); SrsUniquePtr<SrsRtmpCommonMessage> msg_uptr(msg);
EXPECT_EQ(256, p.out_chunk_size); EXPECT_EQ(256, p.out_chunk_size_);
} }
if (true) { if (true) {
@ -1053,8 +1053,8 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4)
SrsProtocol p(&io); SrsProtocol p(&io);
SrsUserControlPacket *pkt = new SrsUserControlPacket(); SrsUserControlPacket *pkt = new SrsUserControlPacket();
pkt->event_type = SrcPCUCSetBufferLength; pkt->event_type_ = SrcPCUCSetBufferLength;
pkt->extra_data = 256; pkt->extra_data_ = 256;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 0));
io.in_buffer.append(&io.out_buffer); io.in_buffer.append(&io.out_buffer);
@ -1063,7 +1063,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4)
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
SrsUniquePtr<SrsRtmpCommonMessage> msg_uptr(msg); SrsUniquePtr<SrsRtmpCommonMessage> msg_uptr(msg);
EXPECT_EQ(256, p.in_buffer_length); EXPECT_EQ(256, p.in_buffer_length_);
} }
} }
@ -1108,7 +1108,7 @@ VOID TEST(ProtocolRTMPTest, HandshakeC0C1)
SrsHandshakeBytes hs; SrsHandshakeBytes hs;
HELPER_EXPECT_SUCCESS(hs.read_c0c1(&io)); HELPER_EXPECT_SUCCESS(hs.read_c0c1(&io));
EXPECT_EQ((uint32_t)0x01020304, (uint32_t)hs.proxy_real_ip); EXPECT_EQ((uint32_t)0x01020304, (uint32_t)hs.proxy_real_ip_);
} }
// It's extended c0c1 prefixed with ip, which should be ok. // It's extended c0c1 prefixed with ip, which should be ok.
@ -1128,7 +1128,7 @@ VOID TEST(ProtocolRTMPTest, HandshakeC0C1)
io.append(buf, sizeof(buf)); io.append(buf, sizeof(buf));
SrsRtmpServer r(&io); SrsRtmpServer r(&io);
HELPER_EXPECT_SUCCESS(r.hs_bytes->read_c0c1(&io)); HELPER_EXPECT_SUCCESS(r.hs_bytes_->read_c0c1(&io));
EXPECT_EQ((uint32_t)0x01020304, (uint32_t)r.proxy_real_ip()); EXPECT_EQ((uint32_t)0x01020304, (uint32_t)r.proxy_real_ip());
} }
@ -1280,12 +1280,12 @@ VOID TEST(ProtocolRTMPTest, HandshakeC2)
VOID TEST(ProtocolRTMPTest, ServerInfo) VOID TEST(ProtocolRTMPTest, ServerInfo)
{ {
SrsServerInfo si; SrsServerInfo si;
EXPECT_EQ(0, si.pid); EXPECT_EQ(0, si.pid_);
EXPECT_EQ(0, si.cid); EXPECT_EQ(0, si.cid_);
EXPECT_EQ(0, si.major); EXPECT_EQ(0, si.major_);
EXPECT_EQ(0, si.minor); EXPECT_EQ(0, si.minor_);
EXPECT_EQ(0, si.revision); EXPECT_EQ(0, si.revision_);
EXPECT_EQ(0, si.build); EXPECT_EQ(0, si.build_);
} }
VOID TEST(ProtocolRTMPTest, ClientCommandMessage) VOID TEST(ProtocolRTMPTest, ClientCommandMessage)
@ -1300,7 +1300,7 @@ VOID TEST(ProtocolRTMPTest, ClientCommandMessage)
SrsConnectAppResPacket *res = new SrsConnectAppResPacket(); SrsConnectAppResPacket *res = new SrsConnectAppResPacket();
SrsAmf0EcmaArray *data = SrsAmf0Any::ecma_array(); SrsAmf0EcmaArray *data = SrsAmf0Any::ecma_array();
res->info->set("data", data); res->info_->set("data", data);
data->set("srs_server_ip", SrsAmf0Any::str("1.2.3.4")); data->set("srs_server_ip", SrsAmf0Any::str("1.2.3.4"));
data->set("srs_server", SrsAmf0Any::str("srs")); data->set("srs_server", SrsAmf0Any::str("srs"));
@ -1320,14 +1320,14 @@ VOID TEST(ProtocolRTMPTest, ClientCommandMessage)
SrsServerInfo si; SrsServerInfo si;
HELPER_EXPECT_SUCCESS(r.connect_app("live", "rtmp://127.0.0.1/live", &req, true, &si)); HELPER_EXPECT_SUCCESS(r.connect_app("live", "rtmp://127.0.0.1/live", &req, true, &si));
EXPECT_STREQ("1.2.3.4", si.ip.c_str()); EXPECT_STREQ("1.2.3.4", si.ip_.c_str());
EXPECT_STREQ("srs", si.sig.c_str()); EXPECT_STREQ("srs", si.sig_.c_str());
EXPECT_EQ(100, si.cid); EXPECT_EQ(100, si.cid_);
EXPECT_EQ(200, si.pid); EXPECT_EQ(200, si.pid_);
EXPECT_EQ(3, si.major); EXPECT_EQ(3, si.major_);
EXPECT_EQ(4, si.minor); EXPECT_EQ(4, si.minor_);
EXPECT_EQ(5, si.revision); EXPECT_EQ(5, si.revision_);
EXPECT_EQ(678, si.build); EXPECT_EQ(678, si.build_);
} }
// CreateStream. // CreateStream.
@ -1399,7 +1399,7 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
if (true) { if (true) {
SrsConnectAppPacket *res = new SrsConnectAppPacket(); SrsConnectAppPacket *res = new SrsConnectAppPacket();
res->command_object->set("tcUrl", SrsAmf0Any::str("rtmp://127.0.0.1/live")); res->command_object_->set("tcUrl", SrsAmf0Any::str("rtmp://127.0.0.1/live"));
MockBufferIO tio; MockBufferIO tio;
SrsProtocol p(&tio); SrsProtocol p(&tio);
@ -1412,10 +1412,10 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
SrsRequest req; SrsRequest req;
HELPER_EXPECT_SUCCESS(r.connect_app(&req)); HELPER_EXPECT_SUCCESS(r.connect_app(&req));
EXPECT_STREQ("rtmp", req.schema.c_str()); EXPECT_STREQ("rtmp", req.schema_.c_str());
EXPECT_STREQ("127.0.0.1", req.host.c_str()); EXPECT_STREQ("127.0.0.1", req.host_.c_str());
EXPECT_STREQ("127.0.0.1", req.vhost.c_str()); EXPECT_STREQ("127.0.0.1", req.vhost_.c_str());
EXPECT_STREQ("live", req.app.c_str()); EXPECT_STREQ("live", req.app_.c_str());
} }
// Window ACK size. // Window ACK size.
@ -1433,7 +1433,7 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
SrsRtmpCommonMessage *msg = NULL; SrsRtmpCommonMessage *msg = NULL;
SrsSetWindowAckSizePacket *pkt = NULL; SrsSetWindowAckSizePacket *pkt = NULL;
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt)); HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
EXPECT_EQ(1024, pkt->ackowledgement_window_size); EXPECT_EQ(1024, pkt->ackowledgement_window_size_);
srs_freep(msg); srs_freep(msg);
srs_freep(pkt); srs_freep(pkt);
@ -1446,7 +1446,7 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
SrsRtmpServer r(&io); SrsRtmpServer r(&io);
SrsRequest req; SrsRequest req;
req.objectEncoding = 3.0; req.objectEncoding_ = 3.0;
const char *ip = "1.2.3.4"; const char *ip = "1.2.3.4";
HELPER_EXPECT_SUCCESS(r.response_connect_app(&req, ip)); HELPER_EXPECT_SUCCESS(r.response_connect_app(&req, ip));
@ -1468,11 +1468,11 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
SrsConnectAppResPacket *pkt = NULL; SrsConnectAppResPacket *pkt = NULL;
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt)); HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
SrsAmf0Any *prop = pkt->info->get_property("objectEncoding"); SrsAmf0Any *prop = pkt->info_->get_property("objectEncoding");
ASSERT_TRUE(prop && prop->is_number()); ASSERT_TRUE(prop && prop->is_number());
EXPECT_EQ(3.0, prop->to_number()); EXPECT_EQ(3.0, prop->to_number());
prop = pkt->info->get_property("data"); prop = pkt->info_->get_property("data");
ASSERT_TRUE(prop && prop->is_ecma_array()); ASSERT_TRUE(prop && prop->is_ecma_array());
SrsAmf0EcmaArray *arr = prop->to_ecma_array(); SrsAmf0EcmaArray *arr = prop->to_ecma_array();
@ -1503,7 +1503,7 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
SrsCallPacket *pkt = NULL; SrsCallPacket *pkt = NULL;
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt)); HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
SrsAmf0Any *prop = pkt->arguments; SrsAmf0Any *prop = pkt->arguments_;
ASSERT_TRUE(prop && prop->is_object()); ASSERT_TRUE(prop && prop->is_object());
prop = prop->to_object()->get_property(StatusDescription); prop = prop->to_object()->get_property(StatusDescription);
@ -1539,7 +1539,7 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
SrsUniquePtr<SrsRtmpCommonMessage> msg_uptr(msg); SrsUniquePtr<SrsRtmpCommonMessage> msg_uptr(msg);
EXPECT_EQ(1024, p.in_chunk_size); EXPECT_EQ(1024, p.in_chunk_size_);
} }
} }
} }
@ -1554,13 +1554,13 @@ VOID TEST(ProtocolRTMPTest, ServerRedirect)
SrsRtmpServer r(&io); SrsRtmpServer r(&io);
SrsRequest req; SrsRequest req;
req.app = "live"; req.app_ = "live";
req.stream = "livestream"; req.stream_ = "livestream";
string host = "target.net"; string host = "target.net";
int port = 8888; int port = 8888;
bool accepted = false; bool accepted = false;
string rurl = srs_net_url_encode_rtmp_url(host, port, req.host, req.vhost, req.app, req.stream, req.param); string rurl = srs_net_url_encode_rtmp_url(host, port, req.host_, req.vhost_, req.app_, req.stream_, req.param_);
HELPER_EXPECT_SUCCESS(r.redirect(&req, rurl, accepted)); HELPER_EXPECT_SUCCESS(r.redirect(&req, rurl, accepted));
if (true) { if (true) {
@ -1573,7 +1573,7 @@ VOID TEST(ProtocolRTMPTest, ServerRedirect)
SrsCallPacket *pkt = NULL; SrsCallPacket *pkt = NULL;
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt)); HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
SrsAmf0Any *prop = pkt->arguments; SrsAmf0Any *prop = pkt->arguments_;
ASSERT_TRUE(prop && prop->is_object()); ASSERT_TRUE(prop && prop->is_object());
prop = prop->to_object()->get_property("ex"); prop = prop->to_object()->get_property("ex");
@ -1611,22 +1611,22 @@ VOID TEST(ProtocolRTMPTest, ServerRedirect)
SrsProtocol p(&tio); SrsProtocol p(&tio);
SrsCallPacket *call = new SrsCallPacket(); SrsCallPacket *call = new SrsCallPacket();
call->command_name = "redirected"; call->command_name_ = "redirected";
call->command_object = SrsAmf0Any::object(); call->command_object_ = SrsAmf0Any::object();
call->arguments = SrsAmf0Any::str("OK"); call->arguments_ = SrsAmf0Any::str("OK");
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
} }
SrsRequest req; SrsRequest req;
req.app = "live"; req.app_ = "live";
req.stream = "livestream"; req.stream_ = "livestream";
string host = "target.net"; string host = "target.net";
int port = 8888; int port = 8888;
bool accepted = false; bool accepted = false;
string rurl = srs_net_url_encode_rtmp_url(host, port, req.host, req.vhost, req.app, req.stream, req.param); string rurl = srs_net_url_encode_rtmp_url(host, port, req.host_, req.vhost_, req.app_, req.stream_, req.param_);
HELPER_EXPECT_SUCCESS(r.redirect(&req, rurl, accepted)); HELPER_EXPECT_SUCCESS(r.redirect(&req, rurl, accepted));
EXPECT_TRUE(accepted); EXPECT_TRUE(accepted);
@ -1640,7 +1640,7 @@ VOID TEST(ProtocolRTMPTest, ServerRedirect)
SrsCallPacket *pkt = NULL; SrsCallPacket *pkt = NULL;
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt)); HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
SrsAmf0Any *prop = pkt->arguments; SrsAmf0Any *prop = pkt->arguments_;
ASSERT_TRUE(prop && prop->is_object()); ASSERT_TRUE(prop && prop->is_object());
prop = prop->to_object()->get_property("ex"); prop = prop->to_object()->get_property("ex");
@ -1697,8 +1697,8 @@ VOID TEST(ProtocolRTMPTest, ServerIdentify)
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0));
SrsPlayPacket *play = new SrsPlayPacket(); SrsPlayPacket *play = new SrsPlayPacket();
play->stream_name = "livestream"; play->stream_name_ = "livestream";
play->duration = 100; play->duration_ = 100;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(play, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(play, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -1728,8 +1728,8 @@ VOID TEST(ProtocolRTMPTest, ServerIdentify)
} }
SrsPlayPacket *play = new SrsPlayPacket(); SrsPlayPacket *play = new SrsPlayPacket();
play->stream_name = "livestream"; play->stream_name_ = "livestream";
play->duration = 100; play->duration_ = 100;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(play, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(play, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -1757,7 +1757,7 @@ VOID TEST(ProtocolRTMPTest, ServerIdentify)
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0));
SrsPublishPacket *publish = new SrsPublishPacket(); SrsPublishPacket *publish = new SrsPublishPacket();
publish->stream_name = "livestream"; publish->stream_name_ = "livestream";
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(publish, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(publish, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -1784,7 +1784,7 @@ VOID TEST(ProtocolRTMPTest, ServerIdentify)
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0));
SrsFMLEStartPacket *fmle = new SrsFMLEStartPacket(); SrsFMLEStartPacket *fmle = new SrsFMLEStartPacket();
fmle->stream_name = "livestream"; fmle->stream_name_ = "livestream";
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(fmle, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(fmle, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -1808,8 +1808,8 @@ VOID TEST(ProtocolRTMPTest, ServerIdentify)
SrsProtocol p(&tio); SrsProtocol p(&tio);
SrsPlayPacket *play = new SrsPlayPacket(); SrsPlayPacket *play = new SrsPlayPacket();
play->stream_name = "livestream"; play->stream_name_ = "livestream";
play->duration = 100; play->duration_ = 100;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(play, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(play, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -1834,7 +1834,7 @@ VOID TEST(ProtocolRTMPTest, ServerIdentify)
SrsProtocol p(&tio); SrsProtocol p(&tio);
SrsFMLEStartPacket *fmle = new SrsFMLEStartPacket(); SrsFMLEStartPacket *fmle = new SrsFMLEStartPacket();
fmle->stream_name = "livestream"; fmle->stream_name_ = "livestream";
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(fmle, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(fmle, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -1862,14 +1862,14 @@ VOID TEST(ProtocolRTMPTest, ServerFMLEStart)
SrsProtocol p(&tio); SrsProtocol p(&tio);
if (true) { if (true) {
SrsFMLEStartPacket *fmle = new SrsFMLEStartPacket(); SrsFMLEStartPacket *fmle = new SrsFMLEStartPacket();
fmle->stream_name = "livestream"; fmle->stream_name_ = "livestream";
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(fmle, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(fmle, 0));
SrsCreateStreamPacket *cs = new SrsCreateStreamPacket(); SrsCreateStreamPacket *cs = new SrsCreateStreamPacket();
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(cs, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(cs, 0));
SrsPublishPacket *publish = new SrsPublishPacket(); SrsPublishPacket *publish = new SrsPublishPacket();
publish->stream_name = "livestream"; publish->stream_name_ = "livestream";
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(publish, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(publish, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -1894,7 +1894,7 @@ VOID TEST(ProtocolRTMPTest, ServerFMLEStart)
SrsRtmpCommonMessage *msg = NULL; SrsRtmpCommonMessage *msg = NULL;
SrsCreateStreamResPacket *pkt = NULL; SrsCreateStreamResPacket *pkt = NULL;
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt)); HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
EXPECT_EQ(1, pkt->stream_id); EXPECT_EQ(1, pkt->stream_id_);
srs_freep(msg); srs_freep(msg);
srs_freep(pkt); srs_freep(pkt);
} }
@ -1935,7 +1935,7 @@ VOID TEST(ProtocolRTMPTest, ServerHaivisionPublish)
SrsProtocol p(&tio); SrsProtocol p(&tio);
if (true) { if (true) {
SrsPublishPacket *publish = new SrsPublishPacket(); SrsPublishPacket *publish = new SrsPublishPacket();
publish->stream_name = "livestream"; publish->stream_name_ = "livestream";
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(publish, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(publish, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -1982,8 +1982,8 @@ VOID TEST(ProtocolRTMPTest, ServerFMLEUnpublish)
SrsProtocol p(&tio); SrsProtocol p(&tio);
if (true) { if (true) {
SrsFMLEStartPacket *fmle = new SrsFMLEStartPacket(); SrsFMLEStartPacket *fmle = new SrsFMLEStartPacket();
fmle->transaction_id = 3.0; fmle->transaction_id_ = 3.0;
fmle->stream_name = "livestream"; fmle->stream_name_ = "livestream";
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(fmle, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(fmle, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -2194,21 +2194,21 @@ VOID TEST(ProtocolRTMPTest, ServerResponseCommands)
SrsProtocol p(&tio); SrsProtocol p(&tio);
SrsCallPacket *call = new SrsCallPacket(); SrsCallPacket *call = new SrsCallPacket();
call->command_name = "_checkbw"; call->command_name_ = "_checkbw";
call->transaction_id = 5.0; call->transaction_id_ = 5.0;
call->command_object = SrsAmf0Any::object(); call->command_object_ = SrsAmf0Any::object();
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(call, 0));
SrsOnStatusDataPacket *data = new SrsOnStatusDataPacket(); SrsOnStatusDataPacket *data = new SrsOnStatusDataPacket();
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(data, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(data, 0));
SrsSetChunkSizePacket *scs = new SrsSetChunkSizePacket(); SrsSetChunkSizePacket *scs = new SrsSetChunkSizePacket();
scs->chunk_size = 1024; scs->chunk_size_ = 1024;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(scs, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(scs, 0));
SrsPlayPacket *play = new SrsPlayPacket(); SrsPlayPacket *play = new SrsPlayPacket();
play->stream_name = "livestream"; play->stream_name_ = "livestream";
play->duration = 100; play->duration_ = 100;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(play, 0)); HELPER_EXPECT_SUCCESS(p.send_and_free_packet(play, 0));
io.in_buffer.append(&tio.out_buffer); io.in_buffer.append(&tio.out_buffer);
@ -2276,7 +2276,7 @@ VOID TEST(ProtocolRTMPTest, CoverAll)
EXPECT_EQ(100 * SRS_UTIME_MILLISECONDS, r.get_send_timeout()); EXPECT_EQ(100 * SRS_UTIME_MILLISECONDS, r.get_send_timeout());
r.set_recv_buffer(SRS_DEFAULT_RECV_BUFFER_SIZE + 10); r.set_recv_buffer(SRS_DEFAULT_RECV_BUFFER_SIZE + 10);
EXPECT_EQ(SRS_DEFAULT_RECV_BUFFER_SIZE + 10, r.protocol->in_buffer->nb_buffer); EXPECT_EQ(SRS_DEFAULT_RECV_BUFFER_SIZE + 10, r.protocol_->in_buffer_->nb_buffer);
EXPECT_EQ(0, r.get_recv_bytes()); EXPECT_EQ(0, r.get_recv_bytes());
EXPECT_EQ(0, r.get_send_bytes()); EXPECT_EQ(0, r.get_send_bytes());
@ -2316,14 +2316,14 @@ VOID TEST(ProtocolRTMPTest, CoverAll)
SrsRtmpClient r(&io); SrsRtmpClient r(&io);
SrsAcknowledgementPacket *ack = new SrsAcknowledgementPacket(); SrsAcknowledgementPacket *ack = new SrsAcknowledgementPacket();
ack->sequence_number = 1024; ack->sequence_number_ = 1024;
HELPER_ASSERT_SUCCESS(r.send_and_free_packet(ack, 0)); HELPER_ASSERT_SUCCESS(r.send_and_free_packet(ack, 0));
io.in_buffer.append(&io.out_buffer); io.in_buffer.append(&io.out_buffer);
SrsRtmpCommonMessage *msg = NULL; SrsRtmpCommonMessage *msg = NULL;
SrsAcknowledgementPacket *pkt = NULL; SrsAcknowledgementPacket *pkt = NULL;
HELPER_ASSERT_SUCCESS(r.expect_message(&msg, &pkt)); HELPER_ASSERT_SUCCESS(r.expect_message(&msg, &pkt));
EXPECT_EQ(1024, (int)pkt->sequence_number); EXPECT_EQ(1024, (int)pkt->sequence_number_);
srs_freep(msg); srs_freep(msg);
srs_freep(pkt); srs_freep(pkt);
} }
@ -2355,7 +2355,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
buf.skip(-1 * buf.pos()); buf.skip(-1 * buf.pos());
HELPER_ASSERT_SUCCESS(p->decode(&buf)); HELPER_ASSERT_SUCCESS(p->decode(&buf));
SrsAmf0Any *prop = p->metadata->get_property("license"); SrsAmf0Any *prop = p->metadata_->get_property("license");
ASSERT_TRUE(prop && prop->is_string()); ASSERT_TRUE(prop && prop->is_string());
EXPECT_STREQ("MIT", prop->to_str().c_str()); EXPECT_STREQ("MIT", prop->to_str().c_str());
} }
@ -2366,13 +2366,13 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
if (true) { if (true) {
SrsConnectAppPacket *pkt = new SrsConnectAppPacket(); SrsConnectAppPacket *pkt = new SrsConnectAppPacket();
pkt->command_object->set("tcUrl", SrsAmf0Any::str("rtmp://127.0.0.1/live")); pkt->command_object_->set("tcUrl", SrsAmf0Any::str("rtmp://127.0.0.1/live"));
pkt->command_object->set("pageUrl", SrsAmf0Any::str("http://ossrs.net")); pkt->command_object_->set("pageUrl", SrsAmf0Any::str("http://ossrs.net"));
pkt->command_object->set("swfUrl", SrsAmf0Any::str("http://ossrs.net/index.swf")); pkt->command_object_->set("swfUrl", SrsAmf0Any::str("http://ossrs.net/index.swf"));
pkt->command_object->set("objectEncoding", SrsAmf0Any::number(5.0)); pkt->command_object_->set("objectEncoding", SrsAmf0Any::number(5.0));
pkt->args = SrsAmf0Any::object(); pkt->args_ = SrsAmf0Any::object();
pkt->args->set("license", SrsAmf0Any::str("MIT")); pkt->args_->set("license", SrsAmf0Any::str("MIT"));
HELPER_EXPECT_SUCCESS(r.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(r.send_and_free_packet(pkt, 0));
io.in_buffer.append(&io.out_buffer); io.in_buffer.append(&io.out_buffer);
@ -2381,16 +2381,16 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
SrsRequest req; SrsRequest req;
HELPER_EXPECT_SUCCESS(r.connect_app(&req)); HELPER_EXPECT_SUCCESS(r.connect_app(&req));
EXPECT_STREQ("rtmp", req.schema.c_str()); EXPECT_STREQ("rtmp", req.schema_.c_str());
EXPECT_STREQ("127.0.0.1", req.host.c_str()); EXPECT_STREQ("127.0.0.1", req.host_.c_str());
EXPECT_STREQ("127.0.0.1", req.vhost.c_str()); EXPECT_STREQ("127.0.0.1", req.vhost_.c_str());
EXPECT_STREQ("live", req.app.c_str()); EXPECT_STREQ("live", req.app_.c_str());
EXPECT_STREQ("http://ossrs.net", req.pageUrl.c_str()); EXPECT_STREQ("http://ossrs.net", req.pageUrl_.c_str());
EXPECT_STREQ("http://ossrs.net/index.swf", req.swfUrl.c_str()); EXPECT_STREQ("http://ossrs.net/index.swf", req.swfUrl_.c_str());
EXPECT_EQ(5.0, req.objectEncoding); EXPECT_EQ(5.0, req.objectEncoding_);
ASSERT_TRUE(req.args && req.args->is_object()); ASSERT_TRUE(req.args_ && req.args_->is_object());
SrsAmf0Any *prop = req.args->get_property("license"); SrsAmf0Any *prop = req.args_->get_property("license");
ASSERT_TRUE(prop && prop->is_string()); ASSERT_TRUE(prop && prop->is_string());
EXPECT_STREQ("MIT", prop->to_str().c_str()); EXPECT_STREQ("MIT", prop->to_str().c_str());
} }
@ -2401,7 +2401,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
if (true) { if (true) {
SrsConnectAppPacket *pkt = new SrsConnectAppPacket(); SrsConnectAppPacket *pkt = new SrsConnectAppPacket();
pkt->command_object->set("tcUrl", SrsAmf0Any::number(3.0)); pkt->command_object_->set("tcUrl", SrsAmf0Any::number(3.0));
HELPER_EXPECT_SUCCESS(r.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(r.send_and_free_packet(pkt, 0));
io.in_buffer.append(&io.out_buffer); io.in_buffer.append(&io.out_buffer);
} }
@ -2438,8 +2438,8 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
buf.skip(-1 * buf.pos()); buf.skip(-1 * buf.pos());
HELPER_ASSERT_SUCCESS(p->decode(&buf)); HELPER_ASSERT_SUCCESS(p->decode(&buf));
EXPECT_TRUE(p->is_pause); EXPECT_TRUE(p->is_pause_);
EXPECT_EQ(30.0, p->time_ms); EXPECT_EQ(30.0, p->time_ms_);
} }
if (true) { if (true) {
@ -2476,10 +2476,10 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
buf.skip(-1 * buf.pos()); buf.skip(-1 * buf.pos());
HELPER_ASSERT_SUCCESS(p->decode(&buf)); HELPER_ASSERT_SUCCESS(p->decode(&buf));
EXPECT_STREQ("livestream", p->stream_name.c_str()); EXPECT_STREQ("livestream", p->stream_name_.c_str());
EXPECT_EQ(20.0, p->start); EXPECT_EQ(20.0, p->start_);
EXPECT_EQ(30.0, p->duration); EXPECT_EQ(30.0, p->duration_);
EXPECT_TRUE(p->reset); EXPECT_TRUE(p->reset_);
} }
if (true) { if (true) {
@ -2516,10 +2516,10 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
buf.skip(-1 * buf.pos()); buf.skip(-1 * buf.pos());
HELPER_ASSERT_SUCCESS(p->decode(&buf)); HELPER_ASSERT_SUCCESS(p->decode(&buf));
EXPECT_STREQ("livestream", p->stream_name.c_str()); EXPECT_STREQ("livestream", p->stream_name_.c_str());
EXPECT_EQ(20.0, p->start); EXPECT_EQ(20.0, p->start_);
EXPECT_EQ(30.0, p->duration); EXPECT_EQ(30.0, p->duration_);
EXPECT_TRUE(p->reset); EXPECT_TRUE(p->reset_);
} }
if (true) { if (true) {
@ -2594,7 +2594,7 @@ VOID TEST(ProtocolRTMPTest, ConnectAppWithArgs)
SrsConnectAppResPacket *res = new SrsConnectAppResPacket(); SrsConnectAppResPacket *res = new SrsConnectAppResPacket();
SrsAmf0EcmaArray *data = SrsAmf0Any::ecma_array(); SrsAmf0EcmaArray *data = SrsAmf0Any::ecma_array();
res->info->set("data", data); res->info_->set("data", data);
data->set("srs_server_ip", SrsAmf0Any::str("1.2.3.4")); data->set("srs_server_ip", SrsAmf0Any::str("1.2.3.4"));
data->set("srs_server", SrsAmf0Any::str("srs")); data->set("srs_server", SrsAmf0Any::str("srs"));
@ -2608,21 +2608,21 @@ VOID TEST(ProtocolRTMPTest, ConnectAppWithArgs)
} }
SrsRequest req; SrsRequest req;
req.args = SrsAmf0Any::object(); req.args_ = SrsAmf0Any::object();
req.args->set("license", SrsAmf0Any::str("MIT")); req.args_->set("license", SrsAmf0Any::str("MIT"));
SrsRtmpClient r(&io); SrsRtmpClient r(&io);
SrsServerInfo si; SrsServerInfo si;
HELPER_EXPECT_SUCCESS(r.connect_app("live", "rtmp://127.0.0.1/live", &req, true, &si)); HELPER_EXPECT_SUCCESS(r.connect_app("live", "rtmp://127.0.0.1/live", &req, true, &si));
EXPECT_STREQ("1.2.3.4", si.ip.c_str()); EXPECT_STREQ("1.2.3.4", si.ip_.c_str());
EXPECT_STREQ("srs", si.sig.c_str()); EXPECT_STREQ("srs", si.sig_.c_str());
EXPECT_EQ(100, si.cid); EXPECT_EQ(100, si.cid_);
EXPECT_EQ(200, si.pid); EXPECT_EQ(200, si.pid_);
EXPECT_EQ(3, si.major); EXPECT_EQ(3, si.major_);
EXPECT_EQ(4, si.minor); EXPECT_EQ(4, si.minor_);
EXPECT_EQ(5, si.revision); EXPECT_EQ(5, si.revision_);
EXPECT_EQ(678, si.build); EXPECT_EQ(678, si.build_);
if (true) { if (true) {
tio.in_buffer.append(&io.out_buffer); tio.in_buffer.append(&io.out_buffer);
@ -2633,12 +2633,12 @@ VOID TEST(ProtocolRTMPTest, ConnectAppWithArgs)
SrsUniquePtr<SrsRtmpCommonMessage> msg_uptr(msg); SrsUniquePtr<SrsRtmpCommonMessage> msg_uptr(msg);
SrsUniquePtr<SrsConnectAppPacket> pkt_uptr(pkt); SrsUniquePtr<SrsConnectAppPacket> pkt_uptr(pkt);
SrsAmf0Any *prop = pkt->command_object->get_property("tcUrl"); SrsAmf0Any *prop = pkt->command_object_->get_property("tcUrl");
ASSERT_TRUE(prop && prop->is_string()); ASSERT_TRUE(prop && prop->is_string());
EXPECT_STREQ("rtmp://127.0.0.1/live", prop->to_str().c_str()); EXPECT_STREQ("rtmp://127.0.0.1/live", prop->to_str().c_str());
ASSERT_TRUE(pkt->args); ASSERT_TRUE(pkt->args_);
prop = pkt->args->get_property("license"); prop = pkt->args_->get_property("license");
ASSERT_TRUE(prop && prop->is_string()); ASSERT_TRUE(prop && prop->is_string());
EXPECT_STREQ("MIT", prop->to_str().c_str()); EXPECT_STREQ("MIT", prop->to_str().c_str());
} }
@ -3043,18 +3043,18 @@ VOID TEST(ProtocolRTMPTest, OthersAll)
SrsMessageArray *parr = &h; SrsMessageArray *parr = &h;
SrsUniquePtr<SrsMessageArray> parr2(parr, srs_utest_free_message_array); SrsUniquePtr<SrsMessageArray> parr2(parr, srs_utest_free_message_array);
h.msgs[0] = new SrsMediaPacket(); h.msgs_[0] = new SrsMediaPacket();
h.msgs[1] = new SrsMediaPacket(); h.msgs_[1] = new SrsMediaPacket();
EXPECT_TRUE(NULL != h.msgs[0]); EXPECT_TRUE(NULL != h.msgs_[0]);
EXPECT_TRUE(NULL != h.msgs[1]); EXPECT_TRUE(NULL != h.msgs_[1]);
h.free(1); h.free(1);
EXPECT_TRUE(NULL == h.msgs[0]); EXPECT_TRUE(NULL == h.msgs_[0]);
EXPECT_TRUE(NULL != h.msgs[1]); EXPECT_TRUE(NULL != h.msgs_[1]);
h.free(2); h.free(2);
EXPECT_TRUE(NULL == h.msgs[0]); EXPECT_TRUE(NULL == h.msgs_[0]);
EXPECT_TRUE(NULL == h.msgs[1]); EXPECT_TRUE(NULL == h.msgs_[1]);
} }
} }

View File

@ -509,8 +509,8 @@ VOID TEST(HTTPServerTest, MessageConnection)
if (true) { if (true) {
SrsHttpMessage m; SrsHttpMessage m;
HELPER_EXPECT_SUCCESS(m.set_url("http://127.0.0.1/live/livestream.flv?callback=fn&method=POST", true)); HELPER_EXPECT_SUCCESS(m.set_url("http://127.0.0.1/live/livestream.flv?callback=fn&method=POST", true));
EXPECT_TRUE(m.jsonp); EXPECT_TRUE(m.jsonp_);
EXPECT_STREQ("POST", m.jsonp_method.c_str()); EXPECT_STREQ("POST", m.jsonp_method_.c_str());
EXPECT_TRUE(m.is_jsonp()); EXPECT_TRUE(m.is_jsonp());
} }
@ -635,9 +635,9 @@ VOID TEST(HTTPServerTest, MessageTurnRequest)
SrsHttpMessage m; SrsHttpMessage m;
HELPER_ASSERT_SUCCESS(m.set_url("http://127.0.0.1/live/livestream.flv", false)); HELPER_ASSERT_SUCCESS(m.set_url("http://127.0.0.1/live/livestream.flv", false));
ISrsRequest *r = m.to_request("ossrs.net"); ISrsRequest *r = m.to_request("ossrs.net");
EXPECT_STREQ("live", r->app.c_str()); EXPECT_STREQ("live", r->app_.c_str());
EXPECT_STREQ("livestream", r->stream.c_str()); EXPECT_STREQ("livestream", r->stream_.c_str());
EXPECT_STREQ("rtmp://ossrs.net/live", r->tcUrl.c_str()); EXPECT_STREQ("rtmp://ossrs.net/live", r->tcUrl_.c_str());
srs_freep(r); srs_freep(r);
} }
@ -645,8 +645,8 @@ VOID TEST(HTTPServerTest, MessageTurnRequest)
SrsHttpMessage m; SrsHttpMessage m;
HELPER_ASSERT_SUCCESS(m.set_url("http://127.0.0.1/live/livestream.flv?token=key", false)); HELPER_ASSERT_SUCCESS(m.set_url("http://127.0.0.1/live/livestream.flv?token=key", false));
ISrsRequest *r = m.to_request("ossrs.net"); ISrsRequest *r = m.to_request("ossrs.net");
EXPECT_STREQ("rtmp://ossrs.net/live", r->tcUrl.c_str()); EXPECT_STREQ("rtmp://ossrs.net/live", r->tcUrl_.c_str());
EXPECT_STREQ("?token=key", r->param.c_str()); EXPECT_STREQ("?token=key", r->param_.c_str());
srs_freep(r); srs_freep(r);
} }
@ -656,7 +656,7 @@ VOID TEST(HTTPServerTest, MessageTurnRequest)
m.set_connection(&conn); m.set_connection(&conn);
ISrsRequest *r = m.to_request("ossrs.net"); ISrsRequest *r = m.to_request("ossrs.net");
EXPECT_STREQ("127.0.0.1", r->ip.c_str()); EXPECT_STREQ("127.0.0.1", r->ip_.c_str());
srs_freep(r); srs_freep(r);
} }
@ -670,7 +670,7 @@ VOID TEST(HTTPServerTest, MessageTurnRequest)
m.set_header(&hdr, false); m.set_header(&hdr, false);
ISrsRequest *r = m.to_request("ossrs.net"); ISrsRequest *r = m.to_request("ossrs.net");
EXPECT_STREQ("10.11.12.13", r->ip.c_str()); EXPECT_STREQ("10.11.12.13", r->ip_.c_str());
srs_freep(r); srs_freep(r);
} }
} }

View File

@ -47,29 +47,29 @@ public:
enable_context_switch = context_switch; enable_context_switch = context_switch;
// Initialize all ISrsRequest members to safe defaults // Initialize all ISrsRequest members to safe defaults
objectEncoding = RTMP_SIG_AMF0_VER; objectEncoding_ = RTMP_SIG_AMF0_VER;
duration = -1; duration_ = -1;
port = SRS_CONSTS_RTMP_DEFAULT_PORT; port_ = SRS_CONSTS_RTMP_DEFAULT_PORT;
args = NULL; // Initialize to NULL to prevent crashes args_ = NULL; // Initialize to NULL to prevent crashes
protocol = "rtmp"; protocol_ = "rtmp";
// Parse the URL to set vhost, app, stream // Parse the URL to set vhost, app, stream
size_t app_pos = url.find('/', 1); // Find second slash size_t app_pos = url.find('/', 1); // Find second slash
if (app_pos != string::npos) { if (app_pos != string::npos) {
size_t stream_pos = url.find('/', app_pos + 1); // Find third slash size_t stream_pos = url.find('/', app_pos + 1); // Find third slash
if (stream_pos != string::npos) { if (stream_pos != string::npos) {
app = url.substr(app_pos + 1, stream_pos - app_pos - 1); app_ = url.substr(app_pos + 1, stream_pos - app_pos - 1);
stream = url.substr(stream_pos + 1); stream_ = url.substr(stream_pos + 1);
} else { } else {
app = url.substr(app_pos + 1); app_ = url.substr(app_pos + 1);
stream = "livestream"; stream_ = "livestream";
} }
} else { } else {
app = "live"; app_ = "live";
stream = "livestream"; stream_ = "livestream";
} }
vhost = "localhost"; vhost_ = "localhost";
} }
virtual string get_stream_url() virtual string get_stream_url()
@ -93,8 +93,8 @@ public:
MockAsyncSrsRequest *cp = new MockAsyncSrsRequest(mock_stream_url, enable_context_switch); MockAsyncSrsRequest *cp = new MockAsyncSrsRequest(mock_stream_url, enable_context_switch);
*cp = *this; *cp = *this;
if (args) { if (args_) {
cp->args = args->copy()->to_object(); cp->args_ = args_->copy()->to_object();
} }
return cp; return cp;

View File

@ -462,10 +462,10 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest)
SrsRequest req; SrsRequest req;
EXPECT_TRUE(srs_srt_streamid_to_request("#!::r=live/livestream?key1=val1,key2=val2", mode, &req)); EXPECT_TRUE(srs_srt_streamid_to_request("#!::r=live/livestream?key1=val1,key2=val2", mode, &req));
EXPECT_EQ(mode, SrtModePull); EXPECT_EQ(mode, SrtModePull);
EXPECT_STREQ(req.vhost.c_str(), srs_get_public_internet_address().c_str()); EXPECT_STREQ(req.vhost_.c_str(), srs_get_public_internet_address().c_str());
EXPECT_STREQ(req.app.c_str(), "live"); EXPECT_STREQ(req.app_.c_str(), "live");
EXPECT_STREQ(req.stream.c_str(), "livestream"); EXPECT_STREQ(req.stream_.c_str(), "livestream");
EXPECT_STREQ(req.param.c_str(), "key1=val1&key2=val2"); EXPECT_STREQ(req.param_.c_str(), "key1=val1&key2=val2");
} }
if (true) { if (true) {
@ -473,10 +473,10 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest)
SrsRequest req; SrsRequest req;
EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=srs.srt.com.cn,r=live/livestream?key1=val1,key2=val2", mode, &req)); EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=srs.srt.com.cn,r=live/livestream?key1=val1,key2=val2", mode, &req));
EXPECT_EQ(mode, SrtModePull); EXPECT_EQ(mode, SrtModePull);
EXPECT_STREQ(req.vhost.c_str(), "srs.srt.com.cn"); EXPECT_STREQ(req.vhost_.c_str(), "srs.srt.com.cn");
EXPECT_STREQ(req.app.c_str(), "live"); EXPECT_STREQ(req.app_.c_str(), "live");
EXPECT_STREQ(req.stream.c_str(), "livestream"); EXPECT_STREQ(req.stream_.c_str(), "livestream");
EXPECT_STREQ(req.param.c_str(), "vhost=srs.srt.com.cn&key1=val1&key2=val2"); EXPECT_STREQ(req.param_.c_str(), "vhost=srs.srt.com.cn&key1=val1&key2=val2");
} }
if (true) { if (true) {
@ -484,10 +484,10 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest)
SrsRequest req; SrsRequest req;
EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=live/livestream?key1=val1,key2=val2", mode, &req)); EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=live/livestream?key1=val1,key2=val2", mode, &req));
EXPECT_EQ(mode, SrtModePull); EXPECT_EQ(mode, SrtModePull);
EXPECT_STREQ(req.vhost.c_str(), srs_get_public_internet_address().c_str()); EXPECT_STREQ(req.vhost_.c_str(), srs_get_public_internet_address().c_str());
EXPECT_STREQ(req.app.c_str(), "live"); EXPECT_STREQ(req.app_.c_str(), "live");
EXPECT_STREQ(req.stream.c_str(), "livestream"); EXPECT_STREQ(req.stream_.c_str(), "livestream");
EXPECT_STREQ(req.param.c_str(), "key1=val1&key2=val2"); EXPECT_STREQ(req.param_.c_str(), "key1=val1&key2=val2");
} }
if (true) { if (true) {
@ -495,10 +495,10 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest)
SrsRequest req; SrsRequest req;
EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=srs.srt.com.cn/live/livestream?key1=val1,key2=val2", mode, &req)); EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=srs.srt.com.cn/live/livestream?key1=val1,key2=val2", mode, &req));
EXPECT_EQ(mode, SrtModePull); EXPECT_EQ(mode, SrtModePull);
EXPECT_STREQ(req.vhost.c_str(), "srs.srt.com.cn"); EXPECT_STREQ(req.vhost_.c_str(), "srs.srt.com.cn");
EXPECT_STREQ(req.app.c_str(), "live"); EXPECT_STREQ(req.app_.c_str(), "live");
EXPECT_STREQ(req.stream.c_str(), "livestream"); EXPECT_STREQ(req.stream_.c_str(), "livestream");
EXPECT_STREQ(req.param.c_str(), "vhost=srs.srt.com.cn&key1=val1&key2=val2"); EXPECT_STREQ(req.param_.c_str(), "vhost=srs.srt.com.cn&key1=val1&key2=val2");
} }
} }