Repository: ossrs/srs
File: trunk/src/utest/srs_utest_protocol2.cpp (C++)

Code before:
            // chunk #2
            0xC3,
            /*next chunk.*/
            0x2e, 0x73, 0x77, 0x66, 0x3f, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x31, 0x2e
    };
    bio.in_buffer.append((char*)data, sizeof(data));

    SrsCommonMessage* msg_raw = NULL;
    HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
    SrsUniquePtr<SrsCommonMessage> msg(msg_raw);

    EXPECT_TRUE(msg->header.is_video());
    // 0xCX without extended timestamp.
    EXPECT_EQ(0x00010203, msg->header.timestamp);
}

/**
* 2 audio and video packet, fmt 1/2
* first video packet:  dts:10000
* first audio packet:  dts:11000
* second video packet:  dts : 16787216   delta: 16777216
* second audio packet:  dts : 16787216   delta: 16776216
* and subsequent data packets pts is normal....
*/
// FFMPEG/librtmp, RTMP specification standard protocol.
VOID TEST(ProtocolStackTest, ProtocolRecvAVExtTimedelta)
{
    srs_error_t err = srs_success;

    MockBufferIO bio;
    SrsProtocol proto(&bio);

    // audio message
    uint8_t audio_data1[] = {
            // 12bytes header, 1byts chunk header, 11bytes msg heder
            0x03, // fmt 0
            0x00, 0x27, 0x10, // timestamp 10000
            0x00, 0x00, 0x80, // length, 128
            0x08, // message_type
            0x00, 0x00, 0x00, 0x00, // stream_id
            // msg payload start
            0x02, 0x00, 0x07, 0x63,
            0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
            0x00, 0x03, 0x61, 0x70, 0x70, 0x02, 0x00, 0x04, 0x6c, 0x69, 0x76, 0x65, 0x00, 0x08, 0x66, 0x6c,
            0x61, 0x73, 0x68, 0x56, 0x65, 0x72, 0x02, 0x00, 0x0d, 0x57, 0x49, 0x4e, 0x20, 0x31, 0x32, 0x2c,
            0x30, 0x2c, 0x30, 0x2c, 0x34, 0x31, 0x00, 0x06, 0x73, 0x77, 0x66, 0x55, 0x72, 0x6c, 0x02, 0x00,
            0x51, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x6f, 0x73, 0x73, 0x72,
            0x73, 0x2e, 0x6e, 0x65, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x35, 0x2f, 0x70, 0x6c, 0x61, 0x79, 0x65,
            0x72, 0x73, 0x2f, 0x73, 0x72, 0x73, 0x5f, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x2f, 0x72, 0x65,
            0x6c, 0x65, 0x61, 0x73, 0x65, 0x2f, 0x73, 0x72, 0x73, 0x5f, 0x70, 0x6c,
    };

Review comment (refactor):
Please split this utest to 3 cases, which makes the context clearer:

```cpp
/**
* 2 audio and video packets, fmt 1/2
* first audio packet:   fmt:0, dts:10000
* first video packet:   fmt:0, dts:11000
* second audio packet:  fmt:1, dts:16787216   delta:16776216
* second video packet:  fmt:1, dts:16787216   delta:16777216
* and subsequent data packets pts is normal....
*/
VOID TEST(ProtocolStackTest, ProtocolRecvAVExtTimedeltaStream)
{
}

/**
* 2 audio packets, fmt 1/2
* first audio packet:   fmt:0, dts:10000
* second audio packet:  fmt:1, dts:16787216   delta:16776216
* and subsequent data packets pts is normal....
*/
VOID TEST(ProtocolStackTest, ProtocolRecvAVExtTimedeltaAudio)
{
}

/**
* 2 video packets, fmt 1/2
* first video packet:   fmt:0, dts:11000
* second video packet:  fmt:1, dts:16787216   delta:16777216
* and subsequent data packets pts is normal....
*/
VOID TEST(ProtocolStackTest, ProtocolRecvAVExtTimedeltaVideo)
{
}
```

Code after:
            // chunk #2
            0xC3,
            /*next chunk.*/
            0x2e, 0x73, 0x77, 0x66, 0x3f, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x31, 0x2e
    };
    bio.in_buffer.append((char*)data, sizeof(data));

    SrsCommonMessage* msg_raw = NULL;
    HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
    SrsUniquePtr<SrsCommonMessage> msg(msg_raw);

    EXPECT_TRUE(msg->header.is_video());
    // 0xCX without extended timestamp.
    EXPECT_EQ(0x00010203, msg->header.timestamp);
}

/**
* 2 audio and video packet, fmt 1/2
* first audio packet:  dts:10000
* first video packet:  dts:11000
* second audio packet:  dts : 16787216   delta: 16777216
* second video packet:  dts : 16787216   delta: 16776216
*/
VOID TEST(ProtocolStackTest, ProtocolRecvAVExtTimedeltaStream)
{
    srs_error_t err = srs_success;

    MockBufferIO bio;
    SrsProtocol proto(&bio);

    // audio message
    uint8_t audio_data1[] = {
            // 12bytes header, 1byts chunk header, 11bytes msg heder
            0x03, // fmt 0
            0x00, 0x27, 0x10, // timestamp 10000
            0x00, 0x00, 0x80, // length, 128
            0x08, // message_type
            0x00, 0x00, 0x00, 0x00, // stream_id
            // msg payload start
            0x02, 0x00, 0x07, 0x63,
            0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
            0x00, 0x03, 0x61, 0x70, 0x70, 0x02, 0x00, 0x04, 0x6c, 0x69, 0x76, 0x65, 0x00, 0x08, 0x66, 0x6c,
            0x61, 0x73, 0x68, 0x56, 0x65, 0x72, 0x02, 0x00, 0x0d, 0x57, 0x49, 0x4e, 0x20, 0x31, 0x32, 0x2c,
            0x30, 0x2c, 0x30, 0x2c, 0x34, 0x31, 0x00, 0x06, 0x73, 0x77, 0x66, 0x55, 0x72, 0x6c, 0x02, 0x00,
            0x51, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x6f, 0x73, 0x73, 0x72,
            0x73, 0x2e, 0x6e, 0x65, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x35, 0x2f, 0x70, 0x6c, 0x61, 0x79, 0x65,
            0x72, 0x73, 0x2f, 0x73, 0x72, 0x73, 0x5f, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x2f, 0x72, 0x65,
            0x6c, 0x65, 0x61, 0x73, 0x65, 0x2f, 0x73, 0x72, 0x73, 0x5f, 0x70, 0x6c,
    };

    uint8_t audio_data2[] = {