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

Code before:
        }

        if (pprint->can_print()) {
            srs_trace("<- " SRS_CONSTS_LOG_GB28181_CASTER " gb28181: client_id %s, peer(%s, %d) ps rtp packet %dB, age=%d, vt=%d/%u, sts=%u/%u/%#x, paylod=%dB",
                        channel_id.c_str(),  address_string, peer_port, nb_buf, pprint->age(), pkt.version, 
                        pkt.payload_type, pkt.sequence_number, pkt.timestamp, pkt.ssrc,
                        pkt.payload->length()
                        );
        }

        //current packet becomes previous packet
        srs_freep(pre_packet[pre_pkt_key]);
        pre_packet[pre_pkt_key] = new SrsPsRtpPacket();
        pre_packet[pre_pkt_key]->copy(&pkt);;

        if (!completed){
            return err;
        }
        //process completed frame data
        //clear processed one ps frame
        //on completed frame data rtp packet in muxer enqueue
        map<std::string, SrsPsRtpPacket*>::iterator key = cache_ps_rtp_packet.find(pkt_key);
        if(key != cache_ps_rtp_packet.end())
        {
            SrsGb28181RtmpMuxer* muxer = NULL;
            // //First, search according to the channel_id. Otherwise, search according to the SSRC. 
            // //Some channel_id are created by RTP pool, which are different ports. 
            // //No channel_id are created by multiplexing ports, which are the same port
            // if (!channel_id.empty()){
            //     muxer = _srs_gb28181->fetch_rtmpmuxer(channel_id);
            // }else {
            //     muxer = _srs_gb28181->fetch_rtmpmuxer_by_ssrc(pkt.ssrc);
            // }

            // //auto crate channel
            // if (!muxer && config->auto_create_channel){
            //     //auto create channel generated id
            //     std::stringstream ss, ss1;
            //     ss << "chid" << pkt.ssrc;
            //     std::string tmp_id = ss.str();

            //     SrsGb28181StreamChannel channel;
            //     channel.set_channel_id(tmp_id);
            //     // channel.set_port_mode(RTP_PORT_MODE_FIXED); 
            //     if (!config->sip_invite_port_fixed) {
            //         channel.set_port_mode(RTP_PORT_MODE_RANDOM);
            //     }else
            //     {
            //         channel.set_port_mode(RTP_PORT_MODE_FIXED);
            //     }
            //     channel.set_ssrc(pkt.ssrc);

Review comment (bug):
Why do you want to comment it out? Debugging code? Or is there any problem?

`TRANS_BY_GPT3`

Code after:
            ss << pkt.ssrc << ":" << pre_timestamp << ":" << port_string;
            pkt_key = ss.str();
            if (cache_ps_rtp_packet.find(pkt_key) != cache_ps_rtp_packet.end()) {
                completed = true;
            }
        }

        if (pprint->can_print()) {
            srs_trace("<- " SRS_CONSTS_LOG_GB28181_CASTER " gb28181: client_id %s, peer(%s, %d) ps rtp packet %dB, age=%d, vt=%d/%u, sts=%u/%u/%#x, paylod=%dB",
                        channel_id.c_str(),  address_string, peer_port, nb_buf, pprint->age(), pkt.version, 
                        pkt.payload_type, pkt.sequence_number, pkt.timestamp, pkt.ssrc,
                        pkt.payload->length()
                        );
        }

        //current packet becomes previous packet
        srs_freep(pre_packet[pre_pkt_key]);
        pre_packet[pre_pkt_key] = new SrsPsRtpPacket();
        pre_packet[pre_pkt_key]->copy(&pkt);;

        if (!completed){
            return err;
        }
        //process completed frame data
        //clear processed one ps frame
        //on completed frame data rtp packet in muxer enqueue
        map<std::string, SrsPsRtpPacket*>::iterator key = cache_ps_rtp_packet.find(pkt_key);
        if(key != cache_ps_rtp_packet.end())
        {
            SrsGb28181RtmpMuxer* muxer = NULL;
            muxer = fetch_rtmpmuxer(channel_id,pkt.ssrc);       
          
            if (muxer){
                //TODO: fixme: the same device uses the same SSRC to send with different local ports
                //record the first peer port
                muxer->set_channel_peer_port(peer_port);
                muxer->set_channel_peer_ip(address_string);
                //not the first peer port's non processing
                if (muxer->channel_peer_port() != peer_port){
                    srs_warn("<- " SRS_CONSTS_LOG_GB28181_CASTER " gb28181: client_id %s, ssrc=%#x, first peer_port=%d cur peer_port=%d",
                        muxer->get_channel_id().c_str(), pkt.ssrc, muxer->channel_peer_port(), peer_port);
                    srs_freep(key->second);
                }else {
                    //put it in queue, wait for consumer to process, and then free
                    muxer->ps_packet_enqueue(key->second);
                }
            }else{
                //no consumer process it, discarded
                srs_freep(key->second);
            }
            cache_ps_rtp_packet.erase(pkt_key);