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.
5 // Joint encoder and decoder testing.
6 // These tests operate directly on the VP8 encoder and decoder, not the
7 // transport layer, and are targeted at validating the bit stream.
9 #include <gtest/gtest.h>
11 #include "base/memory/scoped_ptr.h"
12 #include "media/cast/test/video_utility.h"
13 #include "media/cast/video_receiver/codecs/vp8/vp8_decoder.h"
14 #include "media/cast/video_sender/codecs/vp8/vp8_encoder.h"
20 const int kWidth
= 1280;
21 const int kHeight
= 720;
22 const int kStartbitrate
= 4000000;
23 const int kMaxQp
= 54;
25 const int kMaxFrameRate
= 30;
28 class EncodeDecodeTest
: public ::testing::Test
{
31 encoder_config_
.max_number_of_video_buffers_used
= 1;
32 encoder_config_
.number_of_cores
= 1;
33 encoder_config_
.width
= kWidth
;
34 encoder_config_
.height
= kHeight
;
35 encoder_config_
.start_bitrate
= kStartbitrate
;
36 encoder_config_
.min_qp
= kMaxQp
;
37 encoder_config_
.min_qp
= kMinQp
;
38 encoder_config_
.max_frame_rate
= kMaxFrameRate
;
39 int max_unacked_frames
= 1;
40 encoder_
.reset(new Vp8Encoder(encoder_config_
, max_unacked_frames
));
41 // Initialize to use one core.
42 decoder_
.reset(new Vp8Decoder(1));
45 virtual void SetUp() {
47 int start_value
= 10; // Random value to start from.
48 video_frame_
.reset(new I420VideoFrame());
49 video_frame_
->width
= encoder_config_
.width
;
50 video_frame_
->height
= encoder_config_
.height
;
51 PopulateVideoFrame(video_frame_
.get(), start_value
);
54 virtual void TearDown() {
55 delete [] video_frame_
->y_plane
.data
;
56 delete [] video_frame_
->u_plane
.data
;
57 delete [] video_frame_
->v_plane
.data
;
60 void Compare(const I420VideoFrame
& original_image
,
61 const I420VideoFrame
& decoded_image
) {
62 // Compare resolution.
63 EXPECT_EQ(original_image
.width
, decoded_image
.width
);
64 EXPECT_EQ(original_image
.height
, decoded_image
.height
);
66 EXPECT_GT(I420PSNR(original_image
, decoded_image
), 40.0);
69 VideoSenderConfig encoder_config_
;
70 scoped_ptr
<Vp8Encoder
> encoder_
;
71 scoped_ptr
<Vp8Decoder
> decoder_
;
72 scoped_ptr
<I420VideoFrame
> video_frame_
;
75 TEST_F(EncodeDecodeTest
, BasicEncodeDecode
) {
76 EncodedVideoFrame encoded_frame
;
77 I420VideoFrame decoded_frame
;
79 encoder_
->Encode(*(video_frame_
.get()), &encoded_frame
);
81 decoder_
->Decode(encoded_frame
, &decoded_frame
);
83 Compare(*(video_frame_
.get()), decoded_frame
);