Skip to content
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
merged 6 commits into from
Feb 16, 2022

Conversation

chundonglinlin
Copy link
Member

@chundonglinlin chundonglinlin commented Dec 17, 2021

You can specify livestream forward the full rtmp address to other server, for example:

    forward {
        enabled on;
        destination 127.0.0.1:1936 127.0.0.1:1937;
        backend http://127.0.0.1:8085/api/v1/forward;
    }

Scene: client publish url carry forward=

forward url has domain and port

rtmp://ossrs.net/live/livestream?forward=aliyuncdn.com:1936&token=xxxxxx

forward url is full rtmp address

rtmp://ossrs.net/live/livestream?token=xxxxxx&forward=rtmp://cdn.com/myapp/mystream

Scene: backend server configure forward address

class RESTForward(object):
    def __init__(self):
        self.__forwards = []

        self.__forwards.append({
            "vhost":"ossrs.net",
            "app":"live",
            "stream":"livestream",
            "url":"push.ossrs.com",
        })

        self.__forwards.append({
            "app":"live",
            "stream":"livestream",
            "url":"rtmp://push.ossrs.com/test/teststream?auth_token=123456",
        })

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2021

Codecov Report

Merging #2799 (66af013) into develop (acf0af6) will increase coverage by 0.84%.
The diff coverage is 11.86%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2799      +/-   ##
===========================================
+ Coverage    60.09%   60.94%   +0.84%     
===========================================
  Files          121      121              
  Lines        51332    53546    +2214     
===========================================
+ Hits         30850    32634    +1784     
- Misses       20482    20912     +430     

| Impacted Files | Coverage Δ | |'

Translated to English while maintaining the markdown structure:

'| Impacted Files | Coverage Δ | |
|---|---|---|
| trunk/src/app/srs_app_config.hpp | 100.00% <ø> (ø) | |
| trunk/src/app/srs_app_forward.cpp | 0.00% <0.00%> (ø) | |
| trunk/src/app/srs_app_http_hooks.cpp | 0.00% <0.00%> (ø) | |'

Translated to English while maintaining the markdown structure:

'| trunk/src/app/srs_app_config.hpp | 100.00% <ø> (ø) | |
| trunk/src/app/srs_app_forward.cpp | 0.00% <0.00%> (ø) | |
| trunk/src/app/srs_app_http_hooks.cpp | 0.00% <0.00%> (ø) | |
| trunk/src/app/srs_app_source.cpp | 0.64% <0.00%> (-0.02%) | ⬇️ |
| trunk/src/app/srs_app_config.cpp | 68.10% <100.00%> (+2.82%) | ⬆️ |
| trunk/src/utest/srs_utest_config.cpp | 99.88% <100.00%> (+0.09%) | ⬆️ |


Continue to review full report at Codecov.

Legend - Click here to learn more
| Δ = absolute <relative> (impact), ø = not affected, ? = missing data'

Translated to English while maintaining the markdown structure:

'| Δ = absolute <relative> (impact), ø = not affected, ? = missing data

Powered by Codecov. Last update acf0af6...66af013. Read the comment docs.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 17, 2021

First of all, thank you for submitting the PR. 👍
Make sure to maintain the markdown structure.

Then, for comments and explanations, remember to use markdown, don't force adding spaces, for example:
Make sure to maintain the markdown structure.

markdown
  markdown

Finally, please take a look at these issues, as they mention some specific scenarios.

Forwarding improvements need to consider these scenarios and require a more comprehensive solution.

TRANS_BY_GPT3

@chundonglinlin
Copy link
Member Author

chundonglinlin commented Dec 18, 2021

Okay, I will take a look at these issues and consider how to improve them better. Previously, I also had the idea of writing an API interface to send forward relay tasks support API to send forward relay to other servers. If Mr. Yang is available, please ask him to help check if it is feasible.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 20, 2021

Reference

You gave me a bunch of code, but I can't figure out the specific idea behind it. Could you please refine it for me?

Also, please don't mention it in this PR. Please create a separate PR for it. Let's resolve this PR first before simultaneously raising another one. PR is not just about code, it also involves aligning everyone's way of working and thinking.

TRANS_BY_GPT3

@chundonglinlin
Copy link
Member Author

chundonglinlin commented Dec 20, 2021

I was given a bunch of code, but I can't figure out the specific idea behind it. Could you please summarize it for me?

Based on issues and actual usage online, the following application scenarios have been summarized:

Scenario 1: Domain-level forwarding configuration (supported feature)

vhost __defaultVhost__ {
  forward {
    destination ossrs.net:1936;
  }
}

Scenario 2: Flow-level forwarding configuration

vhost __defaultVhost__ {   
  forward live/livestream {   
    destination rtmp://ossrs.net/live01/test001 rtmp://ossrs.net/live02/test002;
  }
  forward live1/livestream1 {   
    destination rtmp://ossrs.net/live03/test003 rtmp://ossrs.net/live04/test004;
  }
}

Scenario 3: Specify forward forwarding for push stream URL

rtmp://ossrs.net/live/livestream?token=262953&forward_url=alicdn.com:1936

The parameter forward_url represents the receiving address of the secondary node (format: domain:port).

Scenario 4: 302 forwarding, on_publish returns the forwarding address

vhost __defaultVhost__ {
    http_hooks {
        on_publish      http://127.0.0.1:8085/api/v1/publish_start;
    }
}

server.py can implement the example of the publish_start interface, returning a 302 status code and the configured forwarding address. At the same time, on_publish parses the corresponding HTTP code, and if it is 302, it parses the body and creates a forwarder.

Scenario 5: Support API for forwarding configuration

http_api {
    enabled         on;
    listen          1985;
}
vhost ossrs.net {
}

After a successful streaming, forwarding can be configured through the API.

curl http://127.0.0.1:1985/api/v1/forward/live/livestream?vhost=ossrs.net&forward_url=rtmp://alicdn.com/live01/livestream01

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 20, 2021

These five scenarios can be covered by one solution. I have made a note of it here: link.

Consider whether it is feasible or not, or reply to that issue. Generally, pull requests do not discuss solutions, but rather discuss suitable code implementations.

TRANS_BY_GPT3

@chundonglinlin chundonglinlin force-pushed the feature/multi-forward branch 4 times, most recently from 2b0da1a to 26835b1 Compare December 28, 2021 13:55
@chundonglinlin
Copy link
Member Author

chundonglinlin commented Dec 29, 2021

forward backend configuration has been updated to implement the logic. The backend server can refer to server.py for implementation. When users push the stream, they can parse it in conjunction with the backend backend service through the custom push stream forward= keyword. However, the rtmp_url returned by the backend service must conform to a fixed format, for example:

Push stream address:

rtmp://ossrs.net/live/livestream?forward=rtmp://cdn.com/myapp/mystream?token=xxxxxx

backend Response format:

{
   "code": 0,
   "data": {
       "forwards":[{
           "url": "rtmp://cdn.com/myapp/mystream?token=xxxxxx"
        }]
   }
}

TRANS_BY_GPT3

@winlinvip winlinvip force-pushed the 4.0release branch 6 times, most recently from 6ac5da9 to 623ca78 Compare January 6, 2022 13:59
@phusinh

This comment has been minimized.

@chundonglinlin
Copy link
Member Author

chundonglinlin commented Jan 7, 2022

You should go to issue #1342 to discuss question. @phusinh
and you need a dispatch service(like server.py, it can get slave's load value) to schedule to different slaves.

@chundonglinlin chundonglinlin changed the base branch from 4.0release to develop January 28, 2022 16:04
@winlinvip winlinvip self-requested a review January 28, 2022 22:41
@winlinvip winlinvip added this to the 5.0 milestone Jan 28, 2022
@@ -482,6 +482,100 @@ srs_error_t SrsHttpHooks::discover_co_workers(string url, string& host, int& por
return err;
}

// Request:
Copy link
Member

@winlinvip winlinvip Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put it in full.conf

TRANS_BY_GPT3

}
}

conf = _srs_config->get_forwards(req->vhost);
Copy link
Member

@winlinvip winlinvip Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a backend, the destination will no longer be used.

TRANS_BY_GPT3

SrsConfDirective* conf = _srs_config->get_forward_backend(req->vhost);
if (conf) {
int count = conf->args.size();
for (int i = 0; i < count; i++) {
Copy link
Member

@winlinvip winlinvip Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not currently supporting multiple.

TRANS_BY_GPT3

// "code": 0,
// "data": {
// "forwards":[{
// "url": "rtmp://ossrs.net:1935/live/livestream?auth_token=xxx"
Copy link
Member

@winlinvip winlinvip Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data: {
  urls: ["rtmp://xxx", "rtmp://xxx"]
}

If you want to expand:

data {
   forwards: xxx
}

TRANS_BY_GPT3


// For backend config
if (true) {
SrsConfDirective* conf = _srs_config->get_forward_backend(req->vhost);
Copy link
Member

@winlinvip winlinvip Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translate to English:
'Change it into a function.'
Make sure to maintain the markdown structure.

TRANS_BY_GPT3

}
}

// For destanition config
SrsConfDirective* conf = _srs_config->get_forwards(req->vhost);
Copy link
Member

@winlinvip winlinvip Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translate to English:
'Change the member variable to req_'

Make sure to maintain the markdown structure.

TRANS_BY_GPT3


// create temp SrsRequest by url
SrsRequest* freq = new SrsRequest();
SrsAutoFree(SrsRequest, freq);
Copy link
Member

@winlinvip winlinvip Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to req.

TRANS_BY_GPT3


# match vhost+app+stream to forward url
self.__forwards.append({
"vhost":"ossrs.net",
Copy link
Member

@winlinvip winlinvip Feb 15, 2022

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

# "code": 0,
# "data": {
# "urls":[
# "rtmp://ossrs.net:1935/live/livestream?auth_token=xxx",
Copy link
Member

@winlinvip winlinvip Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to slave.

TRANS_BY_GPT3

// For backend config
// If you configure backend service, return backend status(default: false)
bool backend_status = false;
if (((err = create_backend_forwarders(backend_status)) != srs_success) || backend_status) {
Copy link
Member

@winlinvip winlinvip Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied_backend_server

// If the user has enabled the backend and the application is successful, ignore the destination.
// If backend is enabled and applied, ignore destination.
bool applied_backend_server = false;
if (((err = create_backend_forwarders(applied_backend_server)) != srs_success)) {
    return err; // srs_error_wrap(err, "create backend applied=%d", applied_backend_server);
}

// If the backend has already been applied, ignore the destination.
// Already applied backend server, ignore destination.
if (applied_backend_server) {
    return err;
}

TRANS_BY_GPT3

// get urls on forward backend
std::vector<std::string> urls;
if ((err = SrsHttpHooks::on_forward_backend(backend_url, req_, urls)) != srs_success) {
return srs_error_wrap(err, "get forward backend failed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return srs_error_wrap(err, "get forward backend failed, backend=%s", backend_url.c_str());

// get urls on forward backend
std::vector<std::string> urls;
if ((err = SrsHttpHooks::on_forward_backend(backend_url, req_, urls)) != srs_success) {
return srs_error_wrap(err, "get forward backend failed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return srs_error_wrap(err, "get forward backend failed, backend=%s", backend_url.c_str());


// initialize the forwarder with request.
if ((err = forwarder->initialize(req, forward_server.str())) != srs_success) {
return srs_error_wrap(err, "init forwarder");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forward_server

@winlinvip winlinvip merged commit 03cf93f into ossrs:develop Feb 16, 2022
@ossrs ossrs locked as resolved and limited conversation to collaborators Feb 16, 2022
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forward: Fetch the URL to forward from a backend, dynamic forwarding, on-demand forwarding, forwarding Hook.
4 participants