| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
| 14 #include "media/base/channel_layout.h" | 14 #include "media/base/channel_layout.h" |
| 15 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 16 #include "media/capture/webm_muxer.h" | 16 #include "media/muxers/webm_muxer.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 using ::testing::_; | 20 using ::testing::_; |
| 21 using ::testing::AllOf; | 21 using ::testing::AllOf; |
| 22 using ::testing::AnyNumber; | 22 using ::testing::AnyNumber; |
| 23 using ::testing::AtLeast; | 23 using ::testing::AtLeast; |
| 24 using ::testing::Eq; | 24 using ::testing::Eq; |
| 25 using ::testing::InSequence; | 25 using ::testing::InSequence; |
| 26 using ::testing::Mock; | 26 using ::testing::Mock; |
| 27 using ::testing::Not; | 27 using ::testing::Not; |
| 28 using ::testing::Sequence; | 28 using ::testing::Sequence; |
| 29 using ::testing::TestWithParam; | 29 using ::testing::TestWithParam; |
| 30 using ::testing::ValuesIn; | 30 using ::testing::ValuesIn; |
| 31 using ::testing::WithArgs; | 31 using ::testing::WithArgs; |
| 32 | 32 |
| 33 namespace media { | 33 namespace media { |
| 34 | 34 |
| 35 struct kTestParams { | 35 struct kTestParams { |
| 36 VideoCodec codec; | 36 VideoCodec codec; |
| 37 size_t num_video_tracks; | 37 size_t num_video_tracks; |
| 38 size_t num_audio_tracks; | 38 size_t num_audio_tracks; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 class WebmMuxerTest : public TestWithParam<kTestParams> { | 41 class WebmMuxerTest : public TestWithParam<kTestParams> { |
| 42 public: | 42 public: |
| 43 WebmMuxerTest() | 43 WebmMuxerTest() |
| 44 : webm_muxer_(GetParam().codec, | 44 : webm_muxer_( |
| 45 GetParam().num_video_tracks, | 45 GetParam().codec, |
| 46 GetParam().num_audio_tracks, | 46 GetParam().num_video_tracks, |
| 47 base::Bind(&WebmMuxerTest::WriteCallback, | 47 GetParam().num_audio_tracks, |
| 48 base::Unretained(this))), | 48 base::Bind(&WebmMuxerTest::WriteCallback, base::Unretained(this))), |
| 49 last_encoded_length_(0), | 49 last_encoded_length_(0), |
| 50 accumulated_position_(0) { | 50 accumulated_position_(0) { |
| 51 EXPECT_EQ(webm_muxer_.Position(), 0); | 51 EXPECT_EQ(webm_muxer_.Position(), 0); |
| 52 const mkvmuxer::int64 kRandomNewPosition = 333; | 52 const mkvmuxer::int64 kRandomNewPosition = 333; |
| 53 EXPECT_EQ(webm_muxer_.Position(kRandomNewPosition), -1); | 53 EXPECT_EQ(webm_muxer_.Position(kRandomNewPosition), -1); |
| 54 EXPECT_FALSE(webm_muxer_.Seekable()); | 54 EXPECT_FALSE(webm_muxer_.Seekable()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 MOCK_METHOD1(WriteCallback, void(base::StringPiece)); | 57 MOCK_METHOD1(WriteCallback, void(base::StringPiece)); |
| 58 | 58 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 const scoped_refptr<VideoFrame> video_frame = | 103 const scoped_refptr<VideoFrame> video_frame = |
| 104 VideoFrame::CreateBlackFrame(frame_size); | 104 VideoFrame::CreateBlackFrame(frame_size); |
| 105 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); | 105 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); |
| 106 | 106 |
| 107 EXPECT_CALL(*this, WriteCallback(_)) | 107 EXPECT_CALL(*this, WriteCallback(_)) |
| 108 .Times(AtLeast(1)) | 108 .Times(AtLeast(1)) |
| 109 .WillRepeatedly( | 109 .WillRepeatedly( |
| 110 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 110 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
| 111 webm_muxer_.OnEncodedVideo(video_frame, | 111 webm_muxer_.OnEncodedVideo(video_frame, |
| 112 make_scoped_ptr(new std::string(encoded_data)), | 112 make_scoped_ptr(new std::string(encoded_data)), |
| 113 base::TimeTicks::Now(), | 113 base::TimeTicks::Now(), false /* keyframe */); |
| 114 false /* keyframe */); | |
| 115 | 114 |
| 116 // First time around WriteCallback() is pinged a number of times to write the | 115 // First time around WriteCallback() is pinged a number of times to write the |
| 117 // Matroska header, but at the end it dumps |encoded_data|. | 116 // Matroska header, but at the end it dumps |encoded_data|. |
| 118 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 117 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
| 119 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 118 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
| 120 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); | 119 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); |
| 121 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); | 120 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); |
| 122 | 121 |
| 123 const int64_t begin_of_second_block = accumulated_position_; | 122 const int64_t begin_of_second_block = accumulated_position_; |
| 124 EXPECT_CALL(*this, WriteCallback(_)) | 123 EXPECT_CALL(*this, WriteCallback(_)) |
| 125 .Times(AtLeast(1)) | 124 .Times(AtLeast(1)) |
| 126 .WillRepeatedly( | 125 .WillRepeatedly( |
| 127 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 126 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
| 128 webm_muxer_.OnEncodedVideo(video_frame, | 127 webm_muxer_.OnEncodedVideo(video_frame, |
| 129 make_scoped_ptr(new std::string(encoded_data)), | 128 make_scoped_ptr(new std::string(encoded_data)), |
| 130 base::TimeTicks::Now(), | 129 base::TimeTicks::Now(), false /* keyframe */); |
| 131 false /* keyframe */); | |
| 132 | 130 |
| 133 // The second time around the callbacks should include a SimpleBlock header, | 131 // The second time around the callbacks should include a SimpleBlock header, |
| 134 // namely the track index, a timestamp and a flags byte, for a total of 6B. | 132 // namely the track index, a timestamp and a flags byte, for a total of 6B. |
| 135 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 133 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
| 136 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 134 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
| 137 const uint32_t kSimpleBlockSize = 6u; | 135 const uint32_t kSimpleBlockSize = 6u; |
| 138 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + | 136 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
| 139 encoded_data.size()), | 137 encoded_data.size()), |
| 140 accumulated_position_); | 138 accumulated_position_); |
| 141 } | 139 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 {kCodecVP8, 0, 1}, | 241 {kCodecVP8, 0, 1}, |
| 244 {kCodecVP8, 1, 1}, | 242 {kCodecVP8, 1, 1}, |
| 245 {kCodecVP9, 1, 0}, | 243 {kCodecVP9, 1, 0}, |
| 246 {kCodecVP9, 0, 1}, | 244 {kCodecVP9, 0, 1}, |
| 247 {kCodecVP9, 1, 1}, | 245 {kCodecVP9, 1, 1}, |
| 248 }; | 246 }; |
| 249 | 247 |
| 250 INSTANTIATE_TEST_CASE_P(, WebmMuxerTest, ValuesIn(kTestCases)); | 248 INSTANTIATE_TEST_CASE_P(, WebmMuxerTest, ValuesIn(kTestCases)); |
| 251 | 249 |
| 252 } // namespace media | 250 } // namespace media |
| OLD | NEW |