Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: media/capture/webm_muxer_unittest.cc

Issue 1233033002: MediaStream: Adding VideoTrackRecorder class and unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dalecurtis@ comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/capture/webm_muxer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/capture/webm_muxer.h" 11 #include "media/capture/webm_muxer.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 using ::testing::_; 15 using ::testing::_;
15 using ::testing::AtLeast; 16 using ::testing::AtLeast;
16 using ::testing::Mock; 17 using ::testing::Mock;
17 using ::testing::WithArgs; 18 using ::testing::WithArgs;
18 19
19 namespace media { 20 namespace media {
(...skipping 21 matching lines...) Expand all
41 42
42 void SaveEncodedDataLen(const base::StringPiece& encoded_data) { 43 void SaveEncodedDataLen(const base::StringPiece& encoded_data) {
43 last_encoded_length_ = encoded_data.size(); 44 last_encoded_length_ = encoded_data.size();
44 accumulated_position_ += encoded_data.size(); 45 accumulated_position_ += encoded_data.size();
45 } 46 }
46 47
47 mkvmuxer::int64 GetWebmMuxerPosition() const { 48 mkvmuxer::int64 GetWebmMuxerPosition() const {
48 return webm_muxer_.Position(); 49 return webm_muxer_.Position();
49 } 50 }
50 51
51 const mkvmuxer::Segment& GetWebmMuxerSegment() const {
52 return webm_muxer_.segment_;
53 }
54
55 mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) { 52 mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) {
56 return webm_muxer_.Write(buf, len); 53 return webm_muxer_.Write(buf, len);
57 } 54 }
58 55
59 WebmMuxer webm_muxer_; 56 WebmMuxer webm_muxer_;
60 57
61 size_t last_encoded_length_; 58 size_t last_encoded_length_;
62 int64_t accumulated_position_; 59 int64_t accumulated_position_;
63 60
64 private: 61 private:
65 DISALLOW_COPY_AND_ASSIGN(WebmMuxerTest); 62 DISALLOW_COPY_AND_ASSIGN(WebmMuxerTest);
66 }; 63 };
67 64
68 // Checks that AddVideoTrack adds a Track.
69 TEST_F(WebmMuxerTest, AddVideoTrack) {
70 const uint64_t track_number = webm_muxer_.AddVideoTrack(gfx::Size(320, 240),
71 30.0f);
72 EXPECT_TRUE(GetWebmMuxerSegment().GetTrackByNumber(track_number));
73 }
74
75 // Checks that the WriteCallback is called with appropriate params when 65 // Checks that the WriteCallback is called with appropriate params when
76 // WebmMuxer::Write() method is called. 66 // WebmMuxer::Write() method is called.
77 TEST_F(WebmMuxerTest, Write) { 67 TEST_F(WebmMuxerTest, Write) {
78 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz"); 68 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz");
79 69
80 EXPECT_CALL(*this, WriteCallback(encoded_data)); 70 EXPECT_CALL(*this, WriteCallback(encoded_data));
81 WebmMuxerWrite(encoded_data.data(), encoded_data.size()); 71 WebmMuxerWrite(encoded_data.data(), encoded_data.size());
82 72
83 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size())); 73 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size()));
84 } 74 }
85 75
86 // This test sends two frames and checks that the WriteCallback is called with 76 // This test sends two frames and checks that the WriteCallback is called with
87 // appropriate params in both cases. 77 // appropriate params in both cases.
88 TEST_F(WebmMuxerTest, OnEncodedVideoNormalFrames) { 78 TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) {
79 const gfx::Size frame_size(160, 80);
80 const scoped_refptr<VideoFrame> video_frame =
81 VideoFrame::CreateBlackFrame(frame_size);
89 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz"); 82 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz");
90 const uint64_t track_number = webm_muxer_.AddVideoTrack(gfx::Size(320, 240),
91 30.0f);
92 83
93 EXPECT_CALL(*this, WriteCallback(_)) 84 EXPECT_CALL(*this, WriteCallback(_))
94 .Times(AtLeast(1)) 85 .Times(AtLeast(1))
95 .WillRepeatedly(WithArgs<0>( 86 .WillRepeatedly(WithArgs<0>(
96 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); 87 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
97 webm_muxer_.OnEncodedVideo(track_number, 88 webm_muxer_.OnEncodedVideo(video_frame,
98 encoded_data, 89 encoded_data,
99 base::TimeDelta::FromMicroseconds(0), 90 base::TimeTicks::Now(),
100 false /* keyframe */); 91 false /* keyframe */);
101 92
102 // First time around WriteCallback() is pinged a number of times to write the 93 // First time around WriteCallback() is pinged a number of times to write the
103 // Matroska header, but at the end it dumps |encoded_data|. 94 // Matroska header, but at the end it dumps |encoded_data|.
104 EXPECT_EQ(last_encoded_length_, encoded_data.size()); 95 EXPECT_EQ(last_encoded_length_, encoded_data.size());
105 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); 96 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_);
106 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); 97 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_));
107 98
108 const int64_t begin_of_second_block = accumulated_position_; 99 const int64_t begin_of_second_block = accumulated_position_;
109 EXPECT_CALL(*this, WriteCallback(_)) 100 EXPECT_CALL(*this, WriteCallback(_))
110 .Times(AtLeast(1)) 101 .Times(AtLeast(1))
111 .WillRepeatedly(WithArgs<0>( 102 .WillRepeatedly(WithArgs<0>(
112 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); 103 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
113 webm_muxer_.OnEncodedVideo(track_number, 104 webm_muxer_.OnEncodedVideo(video_frame,
114 encoded_data, 105 encoded_data,
115 base::TimeDelta::FromMicroseconds(1), 106 base::TimeTicks::Now(),
116 false /* keyframe */); 107 false /* keyframe */);
117 108
118 // The second time around the callbacks should include a SimpleBlock header, 109 // The second time around the callbacks should include a SimpleBlock header,
119 // namely the track index, a timestamp and a flags byte, for a total of 6B. 110 // namely the track index, a timestamp and a flags byte, for a total of 6B.
120 EXPECT_EQ(last_encoded_length_, encoded_data.size()); 111 EXPECT_EQ(last_encoded_length_, encoded_data.size());
121 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); 112 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_);
122 const uint32_t kSimpleBlockSize = 6u; 113 const uint32_t kSimpleBlockSize = 6u;
123 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + 114 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize +
124 encoded_data.size()), 115 encoded_data.size()),
125 accumulated_position_); 116 accumulated_position_);
126 } 117 }
127 118
128 } // namespace media 119 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/webm_muxer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698