Home | History | Annotate | Download | only in framer
      1 // Copyright 2013 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/framer/frame_buffer.h"
      6 #include "testing/gtest/include/gtest/gtest.h"
      7 
      8 namespace media {
      9 namespace cast {
     10 
     11 class FrameBufferTest : public ::testing::Test {
     12  protected:
     13   FrameBufferTest() {}
     14 
     15   virtual ~FrameBufferTest() {}
     16 
     17   virtual void SetUp() {
     18     payload_.assign(kIpPacketSize, 0);
     19 
     20     // Build a default one packet frame - populate webrtc header.
     21     rtp_header_.is_key_frame = false;
     22     rtp_header_.frame_id = 0;
     23     rtp_header_.packet_id = 0;
     24     rtp_header_.max_packet_id = 0;
     25     rtp_header_.is_reference = false;
     26     rtp_header_.reference_frame_id = 0;
     27   }
     28 
     29   FrameBuffer buffer_;
     30   std::vector<uint8> payload_;
     31   RtpCastHeader rtp_header_;
     32 };
     33 
     34 TEST_F(FrameBufferTest, EmptyBuffer) {
     35   EXPECT_FALSE(buffer_.Complete());
     36   EXPECT_FALSE(buffer_.is_key_frame());
     37   EncodedVideoFrame frame;
     38   uint32 rtp_timestamp;
     39   EXPECT_FALSE(buffer_.GetEncodedVideoFrame(&frame, &rtp_timestamp));
     40 }
     41 
     42 TEST_F(FrameBufferTest, DefaultOnePacketFrame) {
     43   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     44   EXPECT_TRUE(buffer_.Complete());
     45   EXPECT_FALSE(buffer_.is_key_frame());
     46   EncodedVideoFrame frame;
     47   uint32 rtp_timestamp;
     48   EXPECT_TRUE(buffer_.GetEncodedVideoFrame(&frame, &rtp_timestamp));
     49   EXPECT_EQ(payload_.size(), frame.data.size());
     50 }
     51 
     52 TEST_F(FrameBufferTest, MultiplePacketFrame) {
     53   rtp_header_.is_key_frame = true;
     54   rtp_header_.max_packet_id = 2;
     55   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     56   ++rtp_header_.packet_id;
     57   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     58   ++rtp_header_.packet_id;
     59   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     60   ++rtp_header_.packet_id;
     61   EXPECT_TRUE(buffer_.Complete());
     62   EXPECT_TRUE(buffer_.is_key_frame());
     63   EncodedVideoFrame frame;
     64   uint32 rtp_timestamp;
     65   EXPECT_TRUE(buffer_.GetEncodedVideoFrame(&frame, &rtp_timestamp));
     66   EXPECT_EQ(3 * payload_.size(), frame.data.size());
     67 }
     68 
     69 TEST_F(FrameBufferTest, InCompleteFrame) {
     70   rtp_header_.max_packet_id = 4;
     71   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     72   ++rtp_header_.packet_id;
     73   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     74   ++rtp_header_.packet_id;
     75   // Increment again - skip packet #2.
     76   ++rtp_header_.packet_id;
     77   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     78   ++rtp_header_.packet_id;
     79   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     80   EXPECT_FALSE(buffer_.Complete());
     81   // Insert missing packet.
     82   rtp_header_.packet_id = 2;
     83   buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
     84   EXPECT_TRUE(buffer_.Complete());
     85 }
     86 
     87 }  // namespace media
     88 }  // namespace cast
     89