| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "media/cast/cast_config.h" | 11 #include "media/cast/cast_config.h" |
| 12 #include "media/cast/receiver/video_decoder.h" | 12 #include "media/cast/receiver/video_decoder.h" |
| 13 #include "media/cast/sender/sender_encoded_frame.h" | 13 #include "media/cast/sender/sender_encoded_frame.h" |
| 14 #include "media/cast/sender/vp8_encoder.h" | 14 #include "media/cast/sender/vp8_encoder.h" |
| 15 #include "media/cast/sender/vp8_quantizer_parser.h" | 15 #include "media/cast/sender/vp8_quantizer_parser.h" |
| 16 #include "media/cast/test/utility/default_config.h" | 16 #include "media/cast/test/utility/default_config.h" |
| 17 #include "media/cast/test/utility/video_utility.h" | 17 #include "media/cast/test/utility/video_utility.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 namespace cast { | 21 namespace cast { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 const int kWidth = 32; | 24 const int kWidth = 32; |
| 25 const int kHeight = 32; | 25 const int kHeight = 32; |
| 26 const int kFrameRate = 10; | 26 const int kFrameRate = 10; |
| 27 const int kQp = 20; | 27 const int kQp = 20; |
| 28 | 28 |
| 29 FrameSenderConfig GetVideoConfigForTest() { | 29 VideoSenderConfig GetVideoConfigForTest() { |
| 30 FrameSenderConfig config = GetDefaultVideoSenderConfig(); | 30 VideoSenderConfig config = GetDefaultVideoSenderConfig(); |
| 31 config.codec = CODEC_VIDEO_VP8; | 31 config.codec = CODEC_VIDEO_VP8; |
| 32 config.use_external_encoder = false; | 32 config.use_external_encoder = false; |
| 33 config.max_frame_rate = kFrameRate; | 33 config.max_frame_rate = kFrameRate; |
| 34 config.video_codec_params.min_qp = kQp; | 34 config.min_qp = kQp; |
| 35 config.video_codec_params.max_qp = kQp; | 35 config.max_qp = kQp; |
| 36 config.video_codec_params.max_cpu_saver_qp = kQp; | 36 config.max_cpu_saver_qp = kQp; |
| 37 return config; | 37 return config; |
| 38 } | 38 } |
| 39 } // unnamed namespace | 39 } // unnamed namespace |
| 40 | 40 |
| 41 class Vp8QuantizerParserTest : public ::testing::Test { | 41 class Vp8QuantizerParserTest : public ::testing::Test { |
| 42 public: | 42 public: |
| 43 Vp8QuantizerParserTest() : video_config_(GetVideoConfigForTest()) {} | 43 Vp8QuantizerParserTest() : video_config_(GetVideoConfigForTest()) {} |
| 44 | 44 |
| 45 // Call vp8 software encoder to encode one randomly generated frame. | 45 // Call vp8 software encoder to encode one randomly generated frame. |
| 46 void EncodeOneFrame(SenderEncodedFrame* encoded_frame) { | 46 void EncodeOneFrame(SenderEncodedFrame* encoded_frame) { |
| 47 const gfx::Size frame_size = gfx::Size(kWidth, kHeight); | 47 const gfx::Size frame_size = gfx::Size(kWidth, kHeight); |
| 48 const scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateFrame( | 48 const scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateFrame( |
| 49 PIXEL_FORMAT_YV12, frame_size, gfx::Rect(frame_size), frame_size, | 49 PIXEL_FORMAT_YV12, frame_size, gfx::Rect(frame_size), frame_size, |
| 50 next_frame_timestamp_); | 50 next_frame_timestamp_); |
| 51 const base::TimeTicks reference_time = | 51 const base::TimeTicks reference_time = |
| 52 base::TimeTicks::UnixEpoch() + next_frame_timestamp_; | 52 base::TimeTicks::UnixEpoch() + next_frame_timestamp_; |
| 53 next_frame_timestamp_ += base::TimeDelta::FromSeconds(1) / kFrameRate; | 53 next_frame_timestamp_ += base::TimeDelta::FromSeconds(1) / kFrameRate; |
| 54 PopulateVideoFrameWithNoise(video_frame.get()); | 54 PopulateVideoFrameWithNoise(video_frame.get()); |
| 55 vp8_encoder_->Encode(video_frame, reference_time, encoded_frame); | 55 vp8_encoder_->Encode(video_frame, reference_time, encoded_frame); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Update the vp8 encoder with the new quantizer. | 58 // Update the vp8 encoder with the new quantizer. |
| 59 void UpdateQuantizer(int qp) { | 59 void UpdateQuantizer(int qp) { |
| 60 DCHECK((qp > 3) && (qp < 64)); | 60 DCHECK((qp > 3) && (qp < 64)); |
| 61 video_config_.video_codec_params.min_qp = qp; | 61 video_config_.min_qp = qp; |
| 62 video_config_.video_codec_params.max_qp = qp; | 62 video_config_.max_qp = qp; |
| 63 video_config_.video_codec_params.max_cpu_saver_qp = qp; | 63 video_config_.max_cpu_saver_qp = qp; |
| 64 RecreateVp8Encoder(); | 64 RecreateVp8Encoder(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 protected: | 67 protected: |
| 68 void SetUp() final { | 68 void SetUp() final { |
| 69 next_frame_timestamp_ = base::TimeDelta(); | 69 next_frame_timestamp_ = base::TimeDelta(); |
| 70 RecreateVp8Encoder(); | 70 RecreateVp8Encoder(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 // Reconstruct a vp8 encoder with new config since the Vp8Encoder | 74 // Reconstruct a vp8 encoder with new config since the Vp8Encoder |
| 75 // class has no interface to update the config. | 75 // class has no interface to update the config. |
| 76 void RecreateVp8Encoder() { | 76 void RecreateVp8Encoder() { |
| 77 vp8_encoder_.reset(new Vp8Encoder(video_config_)); | 77 vp8_encoder_.reset(new Vp8Encoder(video_config_)); |
| 78 vp8_encoder_->Initialize(); | 78 vp8_encoder_->Initialize(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 base::TimeDelta next_frame_timestamp_; | 81 base::TimeDelta next_frame_timestamp_; |
| 82 FrameSenderConfig video_config_; | 82 VideoSenderConfig video_config_; |
| 83 std::unique_ptr<Vp8Encoder> vp8_encoder_; | 83 std::unique_ptr<Vp8Encoder> vp8_encoder_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(Vp8QuantizerParserTest); | 85 DISALLOW_COPY_AND_ASSIGN(Vp8QuantizerParserTest); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 // Encode 3 frames to test the cases with insufficient data input. | 88 // Encode 3 frames to test the cases with insufficient data input. |
| 89 TEST_F(Vp8QuantizerParserTest, InsufficientData) { | 89 TEST_F(Vp8QuantizerParserTest, InsufficientData) { |
| 90 for (int i = 0; i < 3; ++i) { | 90 for (int i = 0; i < 3; ++i) { |
| 91 std::unique_ptr<SenderEncodedFrame> encoded_frame(new SenderEncodedFrame()); | 91 std::unique_ptr<SenderEncodedFrame> encoded_frame(new SenderEncodedFrame()); |
| 92 const uint8_t* encoded_data = | 92 const uint8_t* encoded_data = |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 decoded_quantizer = ParseVp8HeaderQuantizer( | 144 decoded_quantizer = ParseVp8HeaderQuantizer( |
| 145 reinterpret_cast<const uint8_t*>(encoded_frame->data.data()), | 145 reinterpret_cast<const uint8_t*>(encoded_frame->data.data()), |
| 146 encoded_frame->data.size()); | 146 encoded_frame->data.size()); |
| 147 EXPECT_EQ(qp, decoded_quantizer); | 147 EXPECT_EQ(qp, decoded_quantizer); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 } // namespace cast | 152 } // namespace cast |
| 153 } // namespace media | 153 } // namespace media |
| OLD | NEW |