Home | History | Annotate | Download | only in rtp
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "media/cast/net/rtp/frame_buffer.h"
      6 #include "media/cast/net/cast_transport_defines.h"
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 
      9 namespace media {
     10 namespace cast {
     11 
     12 class FrameBufferTest : public ::testing::Test {
     13  protected:
     14   FrameBufferTest() {
     15     payload_.assign(kMaxIpPacketSize, 0);
     16   }
     17 
     18   virtual ~FrameBufferTest() {}
     19 
     20   FrameBuffer buffer_;
     21   std::vector<uint8> payload_;
     22   RtpCastHeader rtp_header_;
     23 
     24   DISALLOW_COPY_AND_ASSIGN(FrameBufferTest);
     25 };
     26 
     27 TEST_F(FrameBufferTest, OnePacketInsertSanity) {
     28   rtp_header_.rtp_timestamp = 3000;
     29   rtp_header_.is_key_frame = true;
     30   rtp_header_.frame_id = 5;
     31   rtp_header_.reference_frame_id = 5;
     32   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     33   EncodedFrame frame;
     34   EXPECT_TRUE(buffer_.AssembleEncodedFrame(&frame));
     35   EXPECT_EQ(EncodedFrame::KEY, frame.dependency);
     36   EXPECT_EQ(5u, frame.frame_id);
     37   EXPECT_EQ(5u, frame.referenced_frame_id);
     38   EXPECT_EQ(3000u, frame.rtp_timestamp);
     39 }
     40 
     41 TEST_F(FrameBufferTest, EmptyBuffer) {
     42   EXPECT_FALSE(buffer_.Complete());
     43   EncodedFrame frame;
     44   EXPECT_FALSE(buffer_.AssembleEncodedFrame(&frame));
     45 }
     46 
     47 TEST_F(FrameBufferTest, DefaultOnePacketFrame) {
     48   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     49   EXPECT_TRUE(buffer_.Complete());
     50   EXPECT_FALSE(buffer_.is_key_frame());
     51   EncodedFrame frame;
     52   EXPECT_TRUE(buffer_.AssembleEncodedFrame(&frame));
     53   EXPECT_EQ(payload_.size(), frame.data.size());
     54 }
     55 
     56 TEST_F(FrameBufferTest, MultiplePacketFrame) {
     57   rtp_header_.is_key_frame = true;
     58   rtp_header_.max_packet_id = 2;
     59   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     60   ++rtp_header_.packet_id;
     61   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     62   ++rtp_header_.packet_id;
     63   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     64   ++rtp_header_.packet_id;
     65   EXPECT_TRUE(buffer_.Complete());
     66   EXPECT_TRUE(buffer_.is_key_frame());
     67   EncodedFrame frame;
     68   EXPECT_TRUE(buffer_.AssembleEncodedFrame(&frame));
     69   EXPECT_EQ(3 * payload_.size(), frame.data.size());
     70 }
     71 
     72 TEST_F(FrameBufferTest, IncompleteFrame) {
     73   rtp_header_.max_packet_id = 4;
     74   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     75   ++rtp_header_.packet_id;
     76   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     77   ++rtp_header_.packet_id;
     78   // Increment again - skip packet #2.
     79   ++rtp_header_.packet_id;
     80   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     81   ++rtp_header_.packet_id;
     82   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     83   EXPECT_FALSE(buffer_.Complete());
     84   // Insert missing packet.
     85   rtp_header_.packet_id = 2;
     86   buffer_.InsertPacket(&payload_[0], payload_.size(), rtp_header_);
     87   EXPECT_TRUE(buffer_.Complete());
     88 }
     89 
     90 }  // namespace media
     91 }  // namespace cast
     92