-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forward: support config full rtmp url forward to other server #2799
Merged
winlinvip
merged 6 commits into
ossrs:develop
from
chundonglinlin:feature/multi-forward
Feb 16, 2022
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
931d19e
Forward: add backend config and demo server for dynamic create forwar…
chundonglinlin 6458e37
Forward: if call forward backend failed, then return directly.
chundonglinlin d1894c3
Forward: add API description and change return value format.
chundonglinlin 45c27bb
Forward: add backend conf file and wrapper function for backend service.
chundonglinlin 66af013
Forward: add backend comment in full.conf and update forward.backend.…
chundonglinlin 77a14e1
Forward: rename backend param and add comment tips.
chundonglinlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -482,6 +482,100 @@ srs_error_t SrsHttpHooks::discover_co_workers(string url, string& host, int& por | |
return err; | ||
} | ||
|
||
// Request: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put it in
|
||
// POST /api/v1/forward | ||
// { | ||
// "action": "on_forward", | ||
// "server_id": "vid-k21d7y2", | ||
// "client_id": "9o7g1330", | ||
// "ip": "127.0.0.1", | ||
// "vhost": "__defaultVhost__", | ||
// "app": "live", | ||
// "tcUrl": "rtmp://127.0.0.1:1935/live", | ||
// "stream": "livestream", | ||
// "param": "?forward=rtmp://ossrs.net/live/livestream" | ||
// } | ||
// Response: | ||
// { | ||
// "code": 0, | ||
// "data": { | ||
// "forwards":[{ | ||
// "url": "rtmp://ossrs.net:1935/live/livestream?auth_token=xxx" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If you want to expand:
|
||
// },{ | ||
// "url": "rtmp://aliyuncdn.com:1935/live/livestream?auth_token=xxx" | ||
// }] | ||
// } | ||
// } | ||
srs_error_t SrsHttpHooks::on_forward_backend(string url, SrsRequest* req, std::vector<std::string>& rtmp_urls) | ||
{ | ||
srs_error_t err = srs_success; | ||
|
||
SrsContextId cid = _srs_context->get_id(); | ||
|
||
SrsStatistic* stat = SrsStatistic::instance(); | ||
|
||
SrsJsonObject* obj = SrsJsonAny::object(); | ||
SrsAutoFree(SrsJsonObject, obj); | ||
|
||
obj->set("action", SrsJsonAny::str("on_forward")); | ||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str())); | ||
obj->set("client_id", SrsJsonAny::str(cid.c_str())); | ||
obj->set("ip", SrsJsonAny::str(req->ip.c_str())); | ||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str())); | ||
obj->set("app", SrsJsonAny::str(req->app.c_str())); | ||
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str())); | ||
obj->set("stream", SrsJsonAny::str(req->stream.c_str())); | ||
obj->set("param", SrsJsonAny::str(req->param.c_str())); | ||
|
||
std::string data = obj->dumps(); | ||
std::string res; | ||
int status_code; | ||
|
||
SrsHttpClient http; | ||
if ((err = do_post(&http, url, data, status_code, res)) != srs_success) { | ||
return srs_error_wrap(err, "http: on_forward_backend failed, client_id=%s, url=%s, request=%s, response=%s, code=%d", | ||
cid.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code); | ||
} | ||
|
||
// parse string res to json. | ||
SrsJsonAny* info = SrsJsonAny::loads(res); | ||
if (!info) { | ||
return srs_error_new(ERROR_SYSTEM_FORWARD_LOOP, "load json from %s", res.c_str()); | ||
} | ||
SrsAutoFree(SrsJsonAny, info); | ||
|
||
// response error code in string. | ||
if (!info->is_object()) { | ||
return srs_error_new(ERROR_SYSTEM_FORWARD_LOOP, "response %s", res.c_str()); | ||
} | ||
|
||
SrsJsonAny* prop = NULL; | ||
// response standard object, format in json: {} | ||
SrsJsonObject* res_info = info->to_object(); | ||
if ((prop = res_info->ensure_property_object("data")) == NULL) { | ||
return srs_error_new(ERROR_SYSTEM_FORWARD_LOOP, "parse data %s", res.c_str()); | ||
} | ||
|
||
SrsJsonObject* p = prop->to_object(); | ||
if ((prop = p->ensure_property_array("forwards")) == NULL) { | ||
return srs_error_new(ERROR_SYSTEM_FORWARD_LOOP, "parse forwards %s", res.c_str()); | ||
} | ||
|
||
SrsJsonArray* forwards = prop->to_array(); | ||
for (int i = 0; i < forwards->count(); i++) { | ||
prop = forwards->at(i); | ||
SrsJsonObject* forward = prop->to_object(); | ||
if ((prop = forward->ensure_property_string("url")) != NULL) { | ||
rtmp_urls.push_back(prop->to_str()); | ||
} | ||
} | ||
|
||
srs_trace("http: on_forward_backend ok, client_id=%s, url=%s, request=%s, response=%s", | ||
cid.c_str(), url.c_str(), data.c_str(), res.c_str()); | ||
|
||
return err; | ||
} | ||
|
||
srs_error_t SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::string req, int& code, string& res) | ||
{ | ||
srs_error_t err = srs_success; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to slave,
TRANS_BY_GPT3