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

Code before:
        for (it = rtp_pool.begin(); it != rtp_pool.end(); ++it) {
            SrsPsRtpListener* listener = it->second;
            srs_freep(listener);
        }
        rtp_pool.clear();
    }

    //destory gb28181 muxer
    std::map<std::string, SrsGb28181RtmpMuxer*>::iterator it;
    for (it = rtmpmuxers.begin(); it != rtmpmuxers.end(); ++it) {
        SrsGb28181RtmpMuxer* muxer = it->second;
        SrsGb28181StreamChannel sess = muxer->get_channel();
        rtmpmuxer_unmap_by_ssrc(sess.get_ssrc());
        manager->remove(muxer);
    }
    rtmpmuxers.clear();
}

void SrsGb28181Manger::remove(SrsGb28181RtmpMuxer* muxer)
{
    std::string id = muxer->get_channel_id();
  
    map<std::string, SrsGb28181RtmpMuxer*>::iterator it = rtmpmuxers.find(id);
    if (it != rtmpmuxers.end()) {
        SrsGb28181RtmpMuxer* muxer = it->second;
        SrsGb28181StreamChannel sess = muxer->get_channel();
        rtmpmuxer_unmap_by_ssrc(sess.get_ssrc());
        rtmpmuxers.erase(it);
    }
    manager->remove(muxer);
}

void SrsGb28181Manger::remove_sip_session(SrsGb28181SipSession* sess)
{
    manager->remove(sess);
}

srs_error_t SrsGb28181Manger::start_ps_rtp_listen(std::string id, int port)
{
    srs_error_t err = srs_success;
    if (port == config->rtp_mux_port) {
        return srs_error_wrap(err, "start rtp listen port is mux port"); 
    }

    /* delete by xbpeng 20201222 should not check rtmpmuxers, becasue it always not find*/
    // map<std::string, SrsGb28181RtmpMuxer*>::iterator key = rtmpmuxers.find(id);
    // if (key == rtmpmuxers.end()){
    //     srs_warn("start rtp listen port rtmp muxer is null. id=%s,port=%d", id.c_str(),port); 
    //     return srs_error_wrap(err, "start rtp listen port rtmp muxer is null"); 
    // }


Review comment (suggestion):
I don't know why you commented out this.
Why can't it be found? There is no such line in my log at all?

I feel like you made a mistake somewhere.

`TRANS_BY_GPT3`

Code after:
{
    std::string id = muxer->get_channel_id();
  
    map<std::string, SrsGb28181RtmpMuxer*>::iterator it = rtmpmuxers.find(id);
    if (it != rtmpmuxers.end()) {
        SrsGb28181RtmpMuxer* muxer = it->second;
        SrsGb28181StreamChannel sess = muxer->get_channel();
        rtmpmuxer_unmap_by_ssrc(sess.get_ssrc());
        rtmpmuxers.erase(it);
    }
    manager->remove(muxer);
}

void SrsGb28181Manger::remove_sip_session(SrsGb28181SipSession* sess)
{
    manager->remove(sess);
}

srs_error_t SrsGb28181Manger::start_ps_rtp_listen(std::string id, int port)
{
    srs_error_t err = srs_success;
    if (port == config->rtp_mux_port) {
        return srs_error_wrap(err, "start rtp listen port is mux port"); 
    }

    /* delete by xbpeng 20201222 should not check rtmpmuxers, becasue it always not find*/
    // map<std::string, SrsGb28181RtmpMuxer*>::iterator key = rtmpmuxers.find(id);
    // if (key == rtmpmuxers.end()){
    //     srs_warn("start rtp listen port rtmp muxer is null. id=%s,port=%d", id.c_str(),port); 
    //     return srs_error_wrap(err, "start rtp listen port rtmp muxer is null"); 
    // }

    if (!config->rtp_mux_tcp_enable) {
        if (rtp_pool.find(port) == rtp_pool.end())
        {
            SrsPsRtpListener* rtp = new SrsPsRtpListener(this->config, port, id);
            rtp_pool[port] = rtp;
            if ((err = rtp_pool[port]->listen()) != srs_success) {
                stop_rtp_listen(id);
                return srs_error_wrap(err, "rtp listen");
            }

            srs_trace("gb28181: start rtp ps stream over server-port=%d", port);
        }
    }

    return err;
}

void SrsGb28181Manger::stop_rtp_listen(std::string id)
{