| 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 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 mkvmuxer::int64 GetWebmMuxerPosition() const { | 42 mkvmuxer::int64 GetWebmMuxerPosition() const { |
| 43 return webm_muxer_.Position(); | 43 return webm_muxer_.Position(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 mkvmuxer::Segment::Mode GetWebmSegmentMode() const { | 46 mkvmuxer::Segment::Mode GetWebmSegmentMode() const { |
| 47 return webm_muxer_.segment_.mode(); | 47 return webm_muxer_.segment_.mode(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool HasTrack(int track_index) const { |
| 51 return webm_muxer_.segment_.GetTrackByNumber( |
| 52 webm_muxer_.video_muxer_args_[track_index].track_number) != NULL; |
| 53 } |
| 54 |
| 50 mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) { | 55 mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) { |
| 51 return webm_muxer_.Write(buf, len); | 56 return webm_muxer_.Write(buf, len); |
| 52 } | 57 } |
| 53 | 58 |
| 54 WebmMuxer webm_muxer_; | 59 WebmMuxer webm_muxer_; |
| 55 | 60 |
| 56 size_t last_encoded_length_; | 61 size_t last_encoded_length_; |
| 57 int64_t accumulated_position_; | 62 int64_t accumulated_position_; |
| 58 | 63 |
| 59 private: | 64 private: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size())); | 76 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size())); |
| 72 } | 77 } |
| 73 | 78 |
| 74 // This test sends two frames and checks that the WriteCallback is called with | 79 // This test sends two frames and checks that the WriteCallback is called with |
| 75 // appropriate params in both cases. | 80 // appropriate params in both cases. |
| 76 TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) { | 81 TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) { |
| 77 const gfx::Size frame_size(160, 80); | 82 const gfx::Size frame_size(160, 80); |
| 78 const scoped_refptr<VideoFrame> video_frame = | 83 const scoped_refptr<VideoFrame> video_frame = |
| 79 VideoFrame::CreateBlackFrame(frame_size); | 84 VideoFrame::CreateBlackFrame(frame_size); |
| 80 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); | 85 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); |
| 86 int track_index = webm_muxer_.GetNextVideoTrackIndex(); |
| 81 | 87 |
| 82 EXPECT_CALL(*this, WriteCallback(_)) | 88 EXPECT_CALL(*this, WriteCallback(_)) |
| 83 .Times(AtLeast(1)) | 89 .Times(AtLeast(1)) |
| 84 .WillRepeatedly(WithArgs<0>( | 90 .WillRepeatedly(WithArgs<0>( |
| 85 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 91 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
| 86 webm_muxer_.OnEncodedVideo(video_frame, | 92 webm_muxer_.OnEncodedVideo(track_index, |
| 93 video_frame, |
| 87 make_scoped_ptr(new std::string(encoded_data)), | 94 make_scoped_ptr(new std::string(encoded_data)), |
| 88 base::TimeTicks::Now(), | 95 base::TimeTicks::Now(), |
| 89 false /* keyframe */); | 96 false /* keyframe */); |
| 90 | 97 |
| 91 // First time around WriteCallback() is pinged a number of times to write the | 98 // First time around WriteCallback() is pinged a number of times to write the |
| 92 // Matroska header, but at the end it dumps |encoded_data|. | 99 // Matroska header, but at the end it dumps |encoded_data|. |
| 93 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 100 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
| 94 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 101 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
| 95 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); | 102 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); |
| 96 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); | 103 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); |
| 97 | 104 |
| 98 const int64_t begin_of_second_block = accumulated_position_; | 105 const int64_t begin_of_second_block = accumulated_position_; |
| 99 EXPECT_CALL(*this, WriteCallback(_)) | 106 EXPECT_CALL(*this, WriteCallback(_)) |
| 100 .Times(AtLeast(1)) | 107 .Times(AtLeast(1)) |
| 101 .WillRepeatedly(WithArgs<0>( | 108 .WillRepeatedly(WithArgs<0>( |
| 102 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 109 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
| 103 webm_muxer_.OnEncodedVideo(video_frame, | 110 webm_muxer_.OnEncodedVideo(track_index, |
| 111 video_frame, |
| 104 make_scoped_ptr(new std::string(encoded_data)), | 112 make_scoped_ptr(new std::string(encoded_data)), |
| 105 base::TimeTicks::Now(), | 113 base::TimeTicks::Now(), |
| 106 false /* keyframe */); | 114 false /* keyframe */); |
| 115 |
| 116 // The second time around the callbacks should include a SimpleBlock header, |
| 117 // namely the track index, a timestamp and a flags byte, for a total of 6B. |
| 118 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
| 119 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
| 120 const uint32_t kSimpleBlockSize = 6u; |
| 121 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
| 122 encoded_data.size()), |
| 123 accumulated_position_); |
| 124 } |
| 125 |
| 126 TEST_F(WebmMuxerTest, OnEncodedVideoTwoTracks) { |
| 127 const gfx::Size frame_size(160, 80); |
| 128 const scoped_refptr<VideoFrame> video_frame = |
| 129 VideoFrame::CreateBlackFrame(frame_size); |
| 130 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); |
| 131 int track_index_1 = webm_muxer_.GetNextVideoTrackIndex(); |
| 132 EXPECT_CALL(*this, WriteCallback(_)) |
| 133 .Times(AtLeast(1)) |
| 134 .WillRepeatedly(WithArgs<0>( |
| 135 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
| 136 webm_muxer_.OnEncodedVideo(track_index_1, |
| 137 video_frame, |
| 138 make_scoped_ptr(new std::string(encoded_data)), |
| 139 base::TimeTicks::Now(), |
| 140 false /* keyframe */); |
| 141 |
| 142 // First time around WriteCallback() is pinged a number of times to write the |
| 143 // Matroska header, but at the end it dumps |encoded_data|. |
| 144 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
| 145 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
| 146 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); |
| 147 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); |
| 148 |
| 149 int track_index_2 = webm_muxer_.GetNextVideoTrackIndex(); |
| 150 |
| 151 const int64_t begin_of_second_block = accumulated_position_; |
| 152 EXPECT_CALL(*this, WriteCallback(_)) |
| 153 .Times(AtLeast(1)) |
| 154 .WillRepeatedly(WithArgs<0>( |
| 155 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
| 156 webm_muxer_.OnEncodedVideo(track_index_2, |
| 157 video_frame, |
| 158 make_scoped_ptr(new std::string(encoded_data)), |
| 159 base::TimeTicks::Now(), |
| 160 false /* keyframe */); |
| 107 | 161 |
| 108 // The second time around the callbacks should include a SimpleBlock header, | 162 // 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. | 163 // namely the track index, a timestamp and a flags byte, for a total of 6B. |
| 110 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 164 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
| 111 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 165 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
| 112 const uint32_t kSimpleBlockSize = 6u; | 166 const uint32_t kSimpleBlockSize = 6u; |
| 113 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + | 167 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
| 114 encoded_data.size()), | 168 encoded_data.size()), |
| 115 accumulated_position_); | 169 accumulated_position_); |
| 170 EXPECT_TRUE(HasTrack(track_index_1)); |
| 171 EXPECT_TRUE(HasTrack(track_index_2)); |
| 116 } | 172 } |
| 117 | 173 |
| 118 } // namespace media | 174 } // namespace media |
| OLD | NEW |