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

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: miu@s comment on OnFirstFrameCB and OnEncodedVideoCB Created 5 years, 4 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
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/capture/webm_muxer.h" 10 #include "media/capture/webm_muxer.h"
(...skipping 30 matching lines...) Expand all
41 41
42 void SaveEncodedDataLen(const base::StringPiece& encoded_data) { 42 void SaveEncodedDataLen(const base::StringPiece& encoded_data) {
43 last_encoded_length_ = encoded_data.size(); 43 last_encoded_length_ = encoded_data.size();
44 accumulated_position_ += encoded_data.size(); 44 accumulated_position_ += encoded_data.size();
45 } 45 }
46 46
47 mkvmuxer::int64 GetWebmMuxerPosition() const { 47 mkvmuxer::int64 GetWebmMuxerPosition() const {
48 return webm_muxer_.Position(); 48 return webm_muxer_.Position();
49 } 49 }
50 50
51 const mkvmuxer::Segment& GetWebmMuxerSegment() const {
52 return webm_muxer_.segment_;
53 }
54
55 mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) { 51 mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) {
56 return webm_muxer_.Write(buf, len); 52 return webm_muxer_.Write(buf, len);
57 } 53 }
58 54
59 WebmMuxer webm_muxer_; 55 WebmMuxer webm_muxer_;
60 56
61 size_t last_encoded_length_; 57 size_t last_encoded_length_;
62 int64_t accumulated_position_; 58 int64_t accumulated_position_;
63 59
64 private: 60 private:
65 DISALLOW_COPY_AND_ASSIGN(WebmMuxerTest); 61 DISALLOW_COPY_AND_ASSIGN(WebmMuxerTest);
66 }; 62 };
67 63
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 64 // Checks that the WriteCallback is called with appropriate params when
76 // WebmMuxer::Write() method is called. 65 // WebmMuxer::Write() method is called.
77 TEST_F(WebmMuxerTest, Write) { 66 TEST_F(WebmMuxerTest, Write) {
78 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz"); 67 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz");
79 68
80 EXPECT_CALL(*this, WriteCallback(encoded_data)); 69 EXPECT_CALL(*this, WriteCallback(encoded_data));
81 WebmMuxerWrite(encoded_data.data(), encoded_data.size()); 70 WebmMuxerWrite(encoded_data.data(), encoded_data.size());
82 71
83 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size())); 72 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size()));
84 } 73 }
85 74
86 // This test sends two frames and checks that the WriteCallback is called with 75 // This test sends two frames and checks that the WriteCallback is called with
87 // appropriate params in both cases. 76 // appropriate params in both cases.
88 TEST_F(WebmMuxerTest, OnEncodedVideoNormalFrames) { 77 TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) {
89 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz"); 78 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz");
90 const uint64_t track_number = webm_muxer_.AddVideoTrack(gfx::Size(320, 240), 79 const WebmMuxer::OnEncodedVideoCB on_encoded_video_callback =
91 30.0f); 80 webm_muxer_.AddVideoTrack(gfx::Size(320, 240), 30.0f);
81 EXPECT_FALSE(on_encoded_video_callback.is_null());
92 82
93 EXPECT_CALL(*this, WriteCallback(_)) 83 EXPECT_CALL(*this, WriteCallback(_))
94 .Times(AtLeast(1)) 84 .Times(AtLeast(1))
95 .WillRepeatedly(WithArgs<0>( 85 .WillRepeatedly(WithArgs<0>(
96 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); 86 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
97 webm_muxer_.OnEncodedVideo(track_number, 87 on_encoded_video_callback.Run(encoded_data,
98 encoded_data, 88 base::TimeDelta::FromMicroseconds(0),
99 base::TimeDelta::FromMicroseconds(0), 89 false /* keyframe */);
100 false /* keyframe */);
101 90
102 // First time around WriteCallback() is pinged a number of times to write the 91 // First time around WriteCallback() is pinged a number of times to write the
103 // Matroska header, but at the end it dumps |encoded_data|. 92 // Matroska header, but at the end it dumps |encoded_data|.
104 EXPECT_EQ(last_encoded_length_, encoded_data.size()); 93 EXPECT_EQ(last_encoded_length_, encoded_data.size());
105 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); 94 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_);
106 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); 95 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_));
107 96
108 const int64_t begin_of_second_block = accumulated_position_; 97 const int64_t begin_of_second_block = accumulated_position_;
109 EXPECT_CALL(*this, WriteCallback(_)) 98 EXPECT_CALL(*this, WriteCallback(_))
110 .Times(AtLeast(1)) 99 .Times(AtLeast(1))
111 .WillRepeatedly(WithArgs<0>( 100 .WillRepeatedly(WithArgs<0>(
112 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); 101 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
113 webm_muxer_.OnEncodedVideo(track_number, 102 on_encoded_video_callback.Run(encoded_data,
114 encoded_data, 103 base::TimeDelta::FromMicroseconds(1),
115 base::TimeDelta::FromMicroseconds(1), 104 false /* keyframe */);
116 false /* keyframe */);
117 105
118 // The second time around the callbacks should include a SimpleBlock header, 106 // 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. 107 // namely the track index, a timestamp and a flags byte, for a total of 6B.
120 EXPECT_EQ(last_encoded_length_, encoded_data.size()); 108 EXPECT_EQ(last_encoded_length_, encoded_data.size());
121 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); 109 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_);
122 const uint32_t kSimpleBlockSize = 6u; 110 const uint32_t kSimpleBlockSize = 6u;
123 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + 111 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize +
124 encoded_data.size()), 112 encoded_data.size()),
125 accumulated_position_); 113 accumulated_position_);
126 } 114 }
127 115
128 } // namespace media 116 } // namespace media
OLDNEW
« content/renderer/media/video_track_recorder.h ('K') | « media/capture/webm_muxer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698