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