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

Side by Side Diff: content/renderer/media/video_track_recorder_unittest.cc

Issue 1351473006: WebmMuxer-MediaRecorderHandler: thread hopping and data ownership (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: StringPiece passed by value 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 | « content/renderer/media/video_track_recorder.cc ('k') | media/capture/webm_muxer.h » ('j') | 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 "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 19 matching lines...) Expand all
30 30
31 ACTION_P(RunClosure, closure) { 31 ACTION_P(RunClosure, closure) {
32 closure.Run(); 32 closure.Run();
33 } 33 }
34 34
35 // Dummy interface class to be able to MOCK its methods. 35 // Dummy interface class to be able to MOCK its methods.
36 class EncodedVideoHandlerInterface { 36 class EncodedVideoHandlerInterface {
37 public: 37 public:
38 virtual void OnEncodedVideo( 38 virtual void OnEncodedVideo(
39 const scoped_refptr<media::VideoFrame>& video_frame, 39 const scoped_refptr<media::VideoFrame>& video_frame,
40 const base::StringPiece& encoded_data, 40 scoped_ptr<std::string> encoded_data,
41 base::TimeTicks timestamp, 41 base::TimeTicks timestamp,
42 bool is_key_frame) = 0; 42 bool is_key_frame) = 0;
43 virtual ~EncodedVideoHandlerInterface() {} 43 virtual ~EncodedVideoHandlerInterface() {}
44 }; 44 };
45 45
46 class VideoTrackRecorderTest : public testing::Test, 46 class VideoTrackRecorderTest : public testing::Test,
47 public EncodedVideoHandlerInterface { 47 public EncodedVideoHandlerInterface {
48 public: 48 public:
49 VideoTrackRecorderTest() 49 VideoTrackRecorderTest()
50 : mock_source_(new MockMediaStreamVideoSource(false)) { 50 : mock_source_(new MockMediaStreamVideoSource(false)) {
(...skipping 14 matching lines...) Expand all
65 video_track_recorder_.reset(new VideoTrackRecorder( 65 video_track_recorder_.reset(new VideoTrackRecorder(
66 blink_track_, 66 blink_track_,
67 base::Bind(&VideoTrackRecorderTest::OnEncodedVideo, 67 base::Bind(&VideoTrackRecorderTest::OnEncodedVideo,
68 base::Unretained(this)))); 68 base::Unretained(this))));
69 69
70 // Paranoia checks. 70 // Paranoia checks.
71 EXPECT_EQ(blink_track_.source().extraData(), blink_source_.extraData()); 71 EXPECT_EQ(blink_track_.source().extraData(), blink_source_.extraData());
72 EXPECT_TRUE(message_loop_.IsCurrent()); 72 EXPECT_TRUE(message_loop_.IsCurrent());
73 } 73 }
74 74
75 MOCK_METHOD4(OnEncodedVideo, 75 MOCK_METHOD4(DoOnEncodedVideo,
76 void(const scoped_refptr<media::VideoFrame>& frame, 76 void(const scoped_refptr<media::VideoFrame>& frame,
77 const base::StringPiece& encoded_data, 77 std::string encoded_data,
78 base::TimeTicks timestamp, 78 base::TimeTicks timestamp,
79 bool keyframe)); 79 bool keyframe));
80 void OnEncodedVideo(
81 const scoped_refptr<media::VideoFrame>& video_frame,
82 scoped_ptr<std::string> encoded_data,
83 base::TimeTicks timestamp,
84 bool is_key_frame) override {
85 DoOnEncodedVideo(video_frame, *encoded_data, timestamp, is_key_frame);
86 }
80 87
81 void Encode(const scoped_refptr<media::VideoFrame>& frame, 88 void Encode(const scoped_refptr<media::VideoFrame>& frame,
82 base::TimeTicks capture_time) { 89 base::TimeTicks capture_time) {
83 EXPECT_TRUE(message_loop_.IsCurrent()); 90 EXPECT_TRUE(message_loop_.IsCurrent());
84 video_track_recorder_->OnVideoFrameForTesting(frame, capture_time); 91 video_track_recorder_->OnVideoFrameForTesting(frame, capture_time);
85 } 92 }
86 93
87 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks 94 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks
88 // and Sources below into believing they are on the right threads. 95 // and Sources below into believing they are on the right threads.
89 const base::MessageLoopForUI message_loop_; 96 const base::MessageLoopForUI message_loop_;
(...skipping 24 matching lines...) Expand all
114 const gfx::Size frame_size(160, 80); 121 const gfx::Size frame_size(160, 80);
115 const scoped_refptr<media::VideoFrame> video_frame = 122 const scoped_refptr<media::VideoFrame> video_frame =
116 media::VideoFrame::CreateBlackFrame(frame_size); 123 media::VideoFrame::CreateBlackFrame(frame_size);
117 const double kFrameRate = 60.0f; 124 const double kFrameRate = 60.0f;
118 video_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 125 video_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE,
119 kFrameRate); 126 kFrameRate);
120 127
121 InSequence s; 128 InSequence s;
122 const base::TimeTicks timeticks_now = base::TimeTicks::Now(); 129 const base::TimeTicks timeticks_now = base::TimeTicks::Now();
123 base::StringPiece first_frame_encoded_data; 130 base::StringPiece first_frame_encoded_data;
124 EXPECT_CALL(*this, OnEncodedVideo(video_frame, _, timeticks_now, true)) 131 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_now, true))
125 .Times(1) 132 .Times(1)
126 .WillOnce(SaveArg<1>(&first_frame_encoded_data)); 133 .WillOnce(SaveArg<1>(&first_frame_encoded_data));
127 Encode(video_frame, timeticks_now); 134 Encode(video_frame, timeticks_now);
128 135
129 // Send another Video Frame. 136 // Send another Video Frame.
130 const base::TimeTicks timeticks_later = base::TimeTicks::Now(); 137 const base::TimeTicks timeticks_later = base::TimeTicks::Now();
131 base::StringPiece second_frame_encoded_data; 138 base::StringPiece second_frame_encoded_data;
132 EXPECT_CALL(*this, OnEncodedVideo(video_frame, _, timeticks_later, false)) 139 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_later, false))
133 .Times(1) 140 .Times(1)
134 .WillOnce(SaveArg<1>(&second_frame_encoded_data)); 141 .WillOnce(SaveArg<1>(&second_frame_encoded_data));
135 Encode(video_frame, timeticks_later); 142 Encode(video_frame, timeticks_later);
136 143
137 // Send another Video Frame and expect only an OnEncodedVideo() callback. 144 // Send another Video Frame and expect only an DoOnEncodedVideo() callback.
138 const gfx::Size frame_size2(180, 80); 145 const gfx::Size frame_size2(180, 80);
139 const scoped_refptr<media::VideoFrame> video_frame2 = 146 const scoped_refptr<media::VideoFrame> video_frame2 =
140 media::VideoFrame::CreateBlackFrame(frame_size2); 147 media::VideoFrame::CreateBlackFrame(frame_size2);
141 148
142 base::RunLoop run_loop; 149 base::RunLoop run_loop;
143 base::Closure quit_closure = run_loop.QuitClosure(); 150 base::Closure quit_closure = run_loop.QuitClosure();
144 151
145 base::StringPiece third_frame_encoded_data; 152 base::StringPiece third_frame_encoded_data;
146 EXPECT_CALL(*this, OnEncodedVideo(video_frame2, _, _, true)) 153 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame2, _, _, true))
147 .Times(1) 154 .Times(1)
148 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data), 155 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data),
149 RunClosure(quit_closure))); 156 RunClosure(quit_closure)));
150 Encode(video_frame2, base::TimeTicks::Now()); 157 Encode(video_frame2, base::TimeTicks::Now());
151 158
152 run_loop.Run(); 159 run_loop.Run();
153 160
154 const size_t kFirstEncodedDataSize = 52; 161 const size_t kFirstEncodedDataSize = 52;
155 EXPECT_EQ(first_frame_encoded_data.size(), kFirstEncodedDataSize); 162 EXPECT_EQ(first_frame_encoded_data.size(), kFirstEncodedDataSize);
156 const size_t kSecondEncodedDataSize = 32; 163 const size_t kSecondEncodedDataSize = 32;
157 EXPECT_EQ(second_frame_encoded_data.size(), kSecondEncodedDataSize); 164 EXPECT_EQ(second_frame_encoded_data.size(), kSecondEncodedDataSize);
158 const size_t kThirdEncodedDataSize = 57; 165 const size_t kThirdEncodedDataSize = 57;
159 EXPECT_EQ(third_frame_encoded_data.size(), kThirdEncodedDataSize); 166 EXPECT_EQ(third_frame_encoded_data.size(), kThirdEncodedDataSize);
160 167
161 Mock::VerifyAndClearExpectations(this); 168 Mock::VerifyAndClearExpectations(this);
162 } 169 }
163 170
164 } // namespace content 171 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_track_recorder.cc ('k') | media/capture/webm_muxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698