Repository: ossrs/srs
File: trunk/src/app/srs_app_source.cpp (C++)

Code before:
                SrsForwarder* forwarder = new SrsForwarder(this);
                forwarders.push_back(forwarder);

                std::stringstream forward_server;
                forward_server << freq->host << ":" << freq->port;

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

                forwarder->set_queue_size(queue_size);

                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",
                        req->vhost.c_str(), req->app.c_str(), req->stream.c_str(), forward_server.str().c_str());
                }
            }

            // if backend is configured and normal, return directly
            return err;
        }
    }

    // For destanition config
    SrsConfDirective* conf = _srs_config->get_forwards(req->vhost);
    for (int i = 0; conf && i < (int)conf->args.size(); i++) {
        std::string forward_server = conf->args.at(i);
        
        SrsForwarder* forwarder = new SrsForwarder(this);
        forwarders.push_back(forwarder);
        
        // initialize the forwarder with request.
        if ((err = forwarder->initialize(req, forward_server)) != srs_success) {
            return srs_error_wrap(err, "init forwarder");
        }

        forwarder->set_queue_size(queue_size);
        
        if ((err = forwarder->on_publish()) != srs_success) {
            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());
        }
    }
    
    return err;
}

void SrsOriginHub::destroy_forwarders()
{
    std::vector<SrsForwarder*>::iterator it;

Review comment (suggestion):
Translate to English:
'Change the member variable to `req_`'

Make sure to maintain the markdown structure.

`TRANS_BY_GPT3`

Code after:
        
        if ((err = forwarder->on_publish()) != srs_success) {
            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());
        }
    }
    
    return err;
}

srs_error_t SrsOriginHub::create_backend_forwarders(bool& applied)
{
    srs_error_t err = srs_success;

    // default not configure backend service
    applied = false;

    SrsConfDirective* conf = _srs_config->get_forward_backend(req_->vhost);
    if (!conf || conf->arg0().empty()) {
        return err;
    }

    // configure backend service
    applied = true;

    // only get first backend url
    std::string backend_url = conf->arg0();

    // 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, backend=%s", backend_url.c_str());
    }

    // create forwarders by urls
    std::vector<std::string>::iterator it;
    for (it = urls.begin(); it != urls.end(); ++it) {
        std::string url = *it;

        // create temp Request by url
        SrsRequest* req = new SrsRequest();
        SrsAutoFree(SrsRequest, req);
        srs_parse_rtmp_url(url, req->tcUrl, req->stream);
        srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param);

        // create forwarder
        SrsForwarder* forwarder = new SrsForwarder(this);
        forwarders.push_back(forwarder);

        std::stringstream forward_server;
        forward_server << req->host << ":" << req->port;