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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/location.h" | 6 #include "base/location.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 // This test sends two frames and checks that the WriteCallback is called with | 74 // This test sends two frames and checks that the WriteCallback is called with |
75 // appropriate params in both cases. | 75 // appropriate params in both cases. |
76 TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) { | 76 TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) { |
77 const gfx::Size frame_size(160, 80); | 77 const gfx::Size frame_size(160, 80); |
78 const scoped_refptr<VideoFrame> video_frame = | 78 const scoped_refptr<VideoFrame> video_frame = |
79 VideoFrame::CreateBlackFrame(frame_size); | 79 VideoFrame::CreateBlackFrame(frame_size); |
80 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); | 80 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); |
81 | 81 |
| 82 WebmMuxer::EncodedVideoCB encoded_video_cb = |
| 83 webm_muxer_.GenerateOnEncodedVideoCallback(); |
| 84 |
82 EXPECT_CALL(*this, WriteCallback(_)) | 85 EXPECT_CALL(*this, WriteCallback(_)) |
83 .Times(AtLeast(1)) | 86 .Times(AtLeast(1)) |
84 .WillRepeatedly(WithArgs<0>( | 87 .WillRepeatedly(WithArgs<0>( |
85 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 88 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
86 webm_muxer_.OnEncodedVideo(video_frame, | 89 |
87 make_scoped_ptr(new std::string(encoded_data)), | 90 encoded_video_cb.Run(video_frame, |
88 base::TimeTicks::Now(), | 91 make_scoped_ptr(new std::string(encoded_data)), |
89 false /* keyframe */); | 92 base::TimeTicks::Now(), |
| 93 false /* keyframe */); |
90 | 94 |
91 // First time around WriteCallback() is pinged a number of times to write the | 95 // First time around WriteCallback() is pinged a number of times to write the |
92 // Matroska header, but at the end it dumps |encoded_data|. | 96 // Matroska header, but at the end it dumps |encoded_data|. |
| 97 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
| 98 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
| 99 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); |
| 100 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); |
| 101 |
| 102 const int64_t begin_of_second_block = accumulated_position_; |
| 103 EXPECT_CALL(*this, WriteCallback(_)) |
| 104 .Times(AtLeast(1)) |
| 105 .WillRepeatedly(WithArgs<0>( |
| 106 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
| 107 encoded_video_cb.Run(video_frame, |
| 108 make_scoped_ptr(new std::string(encoded_data)), |
| 109 base::TimeTicks::Now(), |
| 110 false /* keyframe */); |
| 111 |
| 112 // The second time around the callbacks should include a SimpleBlock header, |
| 113 // namely the track index, a timestamp and a flags byte, for a total of 6B. |
| 114 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
| 115 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
| 116 const uint32_t kSimpleBlockSize = 6u; |
| 117 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
| 118 encoded_data.size()), |
| 119 accumulated_position_); |
| 120 } |
| 121 |
| 122 TEST_F(WebmMuxerTest, OnEncodedVideoTwoTracks) { |
| 123 const gfx::Size frame_size(160, 80); |
| 124 const scoped_refptr<VideoFrame> video_frame = |
| 125 VideoFrame::CreateBlackFrame(frame_size); |
| 126 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); |
| 127 WebmMuxer::EncodedVideoCB encoded_video_cb_1 = |
| 128 webm_muxer_.GenerateOnEncodedVideoCallback(); |
| 129 WebmMuxer::EncodedVideoCB encoded_video_cb_2 = |
| 130 webm_muxer_.GenerateOnEncodedVideoCallback(); |
| 131 EXPECT_CALL(*this, WriteCallback(_)) |
| 132 .Times(AtLeast(1)) |
| 133 .WillRepeatedly(WithArgs<0>( |
| 134 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
| 135 encoded_video_cb_1.Run(video_frame, |
| 136 make_scoped_ptr(new std::string(encoded_data)), |
| 137 base::TimeTicks::Now(), |
| 138 false /* keyframe */); |
| 139 |
| 140 // First time around WriteCallback() is pinged a number of times to write the |
| 141 // Matroska header, but at the end it dumps |encoded_data|. |
93 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 142 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
94 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 143 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
95 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); | 144 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); |
96 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); | 145 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); |
97 | 146 |
98 const int64_t begin_of_second_block = accumulated_position_; | 147 const int64_t begin_of_second_block = accumulated_position_; |
99 EXPECT_CALL(*this, WriteCallback(_)) | 148 EXPECT_CALL(*this, WriteCallback(_)) |
100 .Times(AtLeast(1)) | 149 .Times(AtLeast(1)) |
101 .WillRepeatedly(WithArgs<0>( | 150 .WillRepeatedly(WithArgs<0>( |
102 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 151 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
103 webm_muxer_.OnEncodedVideo(video_frame, | 152 encoded_video_cb_2.Run(video_frame, |
104 make_scoped_ptr(new std::string(encoded_data)), | 153 make_scoped_ptr(new std::string(encoded_data)), |
105 base::TimeTicks::Now(), | 154 base::TimeTicks::Now(), |
106 false /* keyframe */); | 155 false /* keyframe */); |
107 | 156 |
108 // The second time around the callbacks should include a SimpleBlock header, | 157 // The second time around the callbacks should include a SimpleBlock header, |
109 // namely the track index, a timestamp and a flags byte, for a total of 6B. | 158 // namely the track index, a timestamp and a flags byte, for a total of 6B. |
110 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 159 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
111 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 160 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
112 const uint32_t kSimpleBlockSize = 6u; | 161 const uint32_t kSimpleBlockSize = 6u; |
113 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + | 162 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
114 encoded_data.size()), | 163 encoded_data.size()), |
115 accumulated_position_); | 164 accumulated_position_); |
116 } | 165 } |
117 | 166 |
118 } // namespace media | 167 } // namespace media |
OLD | NEW |