Home | History | Annotate | Download | only in primitives
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/video_engine/test/auto_test/primitives/framedrop_primitives.h"
     12 
     13 #include <stdio.h>
     14 
     15 #include <vector>
     16 
     17 #include "testing/gtest/include/gtest/gtest.h"
     18 #include "webrtc/test/testsupport/fileutils.h"
     19 #include "webrtc/test/testsupport/frame_reader.h"
     20 #include "webrtc/test/testsupport/frame_writer.h"
     21 
     22 namespace webrtc {
     23 
     24 const std::string kOutputFilename = "temp_outputfile.tmp";
     25 const int kFrameLength = 1000;
     26 
     27 class FrameDropPrimitivesTest: public testing::Test {
     28  protected:
     29   FrameDropPrimitivesTest() {}
     30   virtual ~FrameDropPrimitivesTest() {}
     31   void SetUp() {
     32     // Cleanup any previous output file.
     33     remove(kOutputFilename.c_str());
     34   }
     35   void TearDown() {
     36     // Cleanup the temporary file.
     37     remove(kOutputFilename.c_str());
     38   }
     39 };
     40 
     41 TEST_F(FrameDropPrimitivesTest, FixOutputFileForComparison) {
     42   // Create test frame objects, where the second and fourth frame is marked
     43   // as dropped at rendering.
     44   std::vector<Frame*> frames;
     45   Frame first_frame(0, kFrameLength);
     46   Frame second_frame(0, kFrameLength);
     47   Frame third_frame(0, kFrameLength);
     48   Frame fourth_frame(0, kFrameLength);
     49 
     50   second_frame.dropped_at_render = true;
     51   fourth_frame.dropped_at_render = true;
     52 
     53   frames.push_back(&first_frame);
     54   frames.push_back(&second_frame);
     55   frames.push_back(&third_frame);
     56   frames.push_back(&fourth_frame);
     57 
     58   // Prepare data for the first and third frames:
     59   uint8_t first_frame_data[kFrameLength];
     60   memset(first_frame_data, 5, kFrameLength);  // Fill it with 5's to identify.
     61   uint8_t third_frame_data[kFrameLength];
     62   memset(third_frame_data, 7, kFrameLength);  // Fill it with 7's to identify.
     63 
     64   // Write the first and third frames to the temporary file. This means the fix
     65   // method should add two frames of data by filling the file with data from
     66   // the first and third frames after executing.
     67   webrtc::test::FrameWriterImpl frame_writer(kOutputFilename, kFrameLength);
     68   EXPECT_TRUE(frame_writer.Init());
     69   EXPECT_TRUE(frame_writer.WriteFrame(first_frame_data));
     70   EXPECT_TRUE(frame_writer.WriteFrame(third_frame_data));
     71   frame_writer.Close();
     72   EXPECT_EQ(2 * kFrameLength,
     73             static_cast<int>(webrtc::test::GetFileSize(kOutputFilename)));
     74 
     75   FixOutputFileForComparison(kOutputFilename, kFrameLength, frames);
     76 
     77   // Verify that the output file has correct size.
     78   EXPECT_EQ(4 * kFrameLength,
     79             static_cast<int>(webrtc::test::GetFileSize(kOutputFilename)));
     80 
     81   webrtc::test::FrameReaderImpl frame_reader(kOutputFilename, kFrameLength);
     82   frame_reader.Init();
     83   uint8_t read_buffer[kFrameLength];
     84   EXPECT_TRUE(frame_reader.ReadFrame(read_buffer));
     85   EXPECT_EQ(0, memcmp(read_buffer, first_frame_data, kFrameLength));
     86   EXPECT_TRUE(frame_reader.ReadFrame(read_buffer));
     87   EXPECT_EQ(0, memcmp(read_buffer, first_frame_data, kFrameLength));
     88 
     89   EXPECT_TRUE(frame_reader.ReadFrame(read_buffer));
     90   EXPECT_EQ(0, memcmp(read_buffer, third_frame_data, kFrameLength));
     91   EXPECT_TRUE(frame_reader.ReadFrame(read_buffer));
     92   EXPECT_EQ(0, memcmp(read_buffer, third_frame_data, kFrameLength));
     93 
     94   frame_reader.Close();
     95 }
     96 
     97 }  // namespace webrtc
     98