Repository: ossrs/srs
File: trunk/src/protocol/srs_protocol_rtmp_stack.cpp (C++)

Code before:
    SrsSharedPtrMessage* shared_msg = new SrsSharedPtrMessage();
    if ((err = shared_msg->create(msg)) != srs_success) {
        srs_freep(shared_msg);
        return srs_error_wrap(err, "create message");
    }

    if ((err = send_and_free_message(shared_msg, stream_id)) != srs_success) {
        return srs_error_wrap(err, "send packet");
    }
    
    if ((err = on_send_packet(&msg->header, packet)) != srs_success) {
        return srs_error_wrap(err, "on send packet");
    }
    
    return err;
}

srs_error_t SrsProtocol::do_decode_message(SrsMessageHeader& header, SrsBuffer* stream, SrsPacket** ppacket)
{
    srs_error_t err = srs_success;
    
    SrsPacket* packet = NULL;
    
    // decode specified packet type
    if (header.is_amf0_command() || header.is_amf3_command() || header.is_amf0_data() || header.is_amf3_data()) {
        // Ignore FFmpeg timecode, see https://github.com/ossrs/srs/issues/3803
        if (stream->left() == 4 && (uint8_t)*stream->head() == 0x00) {
            srs_warn("Ignore FFmpeg timecode, data=[%s]", srs_string_dumps_hex(stream->head(), 4).c_str());
            return err;
        }

        // skip 1bytes to decode the amf3 command.
        if (header.is_amf3_command() && stream->require(1)) {
            stream->skip(1);
        }
        
        // amf0 command message.
        // need to read the command name.
        std::string command;
        if ((err = srs_amf0_read_string(stream, command)) != srs_success) {
            return srs_error_wrap(err, "decode command name");
        }
        
        // result/error packet
        if (command == RTMP_AMF0_COMMAND_RESULT || command == RTMP_AMF0_COMMAND_ERROR) {
            double transactionId = 0.0;
            if ((err = srs_amf0_read_number(stream, transactionId)) != srs_success) {
                return srs_error_wrap(err, "decode tid for %s", command.c_str());
            }
            
            // reset stream, for header read completed.

Review comment (suggestion):
If the first byte is not 0x00, an error will be judged here

`TRANS_BY_GPT4`

Code after:
    if ((err = shared_msg->create(msg)) != srs_success) {
        srs_freep(shared_msg);
        return srs_error_wrap(err, "create message");
    }

    if ((err = send_and_free_message(shared_msg, stream_id)) != srs_success) {
        return srs_error_wrap(err, "send packet");
    }
    
    if ((err = on_send_packet(&msg->header, packet)) != srs_success) {
        return srs_error_wrap(err, "on send packet");
    }
    
    return err;
}

srs_error_t SrsProtocol::do_decode_message(SrsMessageHeader& header, SrsBuffer* stream, SrsPacket** ppacket)
{
    srs_error_t err = srs_success;
    
    SrsPacket* packet = NULL;
    
    // decode specified packet type
    if (header.is_amf0_command() || header.is_amf3_command() || header.is_amf0_data() || header.is_amf3_data()) {
        // Ignore FFmpeg timecode, see https://github.com/ossrs/srs/issues/3803
        if (stream->left() == 4 && (uint8_t)*stream->head() == 0x00) {
            srs_warn("Ignore FFmpeg timecode, data=[%s]", srs_string_dumps_hex(stream->head(), 4).c_str());
            return err;
        }

        // skip 1bytes to decode the amf3 command.
        if (header.is_amf3_command() && stream->require(1)) {
            stream->skip(1);
        }
        
        // amf0 command message.
        // need to read the command name.
        std::string command;
        if ((err = srs_amf0_read_string(stream, command)) != srs_success) {
            return srs_error_wrap(err, "decode command name");
        }
        
        // result/error packet
        if (command == RTMP_AMF0_COMMAND_RESULT || command == RTMP_AMF0_COMMAND_ERROR) {
            double transactionId = 0.0;
            if ((err = srs_amf0_read_number(stream, transactionId)) != srs_success) {
                return srs_error_wrap(err, "decode tid for %s", command.c_str());
            }
            
            // reset stream, for header read completed.
            stream->skip(-1 * stream->pos());