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

Side by Side Diff: webrtc/api/videotrack_unittest.cc

Issue 1790633002: Propagate MediaStreamSource state to video tracks the same way as audio. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@refactor_track
Patch Set: Fix bug with wrong enum values. Created 4 years, 9 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 | « webrtc/api/videotrack.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 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "webrtc/api/test/fakevideotrackrenderer.h" 13 #include "webrtc/api/test/fakevideotrackrenderer.h"
14 #include "webrtc/api/videocapturertracksource.h" 14 #include "webrtc/api/videocapturertracksource.h"
15 #include "webrtc/api/videotrack.h" 15 #include "webrtc/api/videotrack.h"
16 #include "webrtc/base/gunit.h" 16 #include "webrtc/base/gunit.h"
17 #include "webrtc/base/scoped_ptr.h" 17 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/media/base/fakevideocapturer.h" 18 #include "webrtc/media/base/fakevideocapturer.h"
19 #include "webrtc/media/base/fakemediaengine.h" 19 #include "webrtc/media/base/fakemediaengine.h"
20 #include "webrtc/media/engine/webrtcvideoframe.h" 20 #include "webrtc/media/engine/webrtcvideoframe.h"
21 21
22 using webrtc::FakeVideoTrackRenderer; 22 using webrtc::FakeVideoTrackRenderer;
23 using webrtc::FakeVideoTrackRendererOld; 23 using webrtc::FakeVideoTrackRendererOld;
24 using webrtc::MediaSourceInterface;
25 using webrtc::MediaStreamTrackInterface;
24 using webrtc::VideoTrackSource; 26 using webrtc::VideoTrackSource;
25 using webrtc::VideoTrack; 27 using webrtc::VideoTrack;
26 using webrtc::VideoTrackInterface; 28 using webrtc::VideoTrackInterface;
27 29
28
29 class VideoTrackTest : public testing::Test { 30 class VideoTrackTest : public testing::Test {
30 public: 31 public:
31 VideoTrackTest() { 32 VideoTrackTest() {
32 static const char kVideoTrackId[] = "track_id"; 33 static const char kVideoTrackId[] = "track_id";
33 video_track_ = VideoTrack::Create( 34 video_track_source_ = new rtc::RefCountedObject<VideoTrackSource>(
34 kVideoTrackId, 35 &capturer_, rtc::Thread::Current(), true /* remote */);
35 new rtc::RefCountedObject<VideoTrackSource>( 36 video_track_ = VideoTrack::Create(kVideoTrackId, video_track_source_);
36 &capturer_, rtc::Thread::Current(), true /* remote */));
37 capturer_.Start( 37 capturer_.Start(
38 cricket::VideoFormat(640, 480, cricket::VideoFormat::FpsToInterval(30), 38 cricket::VideoFormat(640, 480, cricket::VideoFormat::FpsToInterval(30),
39 cricket::FOURCC_I420)); 39 cricket::FOURCC_I420));
40 } 40 }
41 41
42 protected: 42 protected:
43 cricket::FakeVideoCapturer capturer_; 43 cricket::FakeVideoCapturer capturer_;
44 rtc::scoped_refptr<VideoTrackSource> video_track_source_;
44 rtc::scoped_refptr<VideoTrackInterface> video_track_; 45 rtc::scoped_refptr<VideoTrackInterface> video_track_;
45 }; 46 };
46 47
48 // Test changing the source state also changes the track state.
49 TEST_F(VideoTrackTest, SourceStateChangeTrackState) {
50 EXPECT_EQ(MediaStreamTrackInterface::kLive, video_track_->state());
51 video_track_source_->SetState(MediaSourceInterface::kEnded);
52 EXPECT_EQ(MediaStreamTrackInterface::kEnded, video_track_->state());
53 }
54
47 // Test adding renderers to a video track and render to them by providing 55 // Test adding renderers to a video track and render to them by providing
48 // frames to the source. 56 // frames to the source.
49 TEST_F(VideoTrackTest, RenderVideo) { 57 TEST_F(VideoTrackTest, RenderVideo) {
50 // FakeVideoTrackRenderer register itself to |video_track_| 58 // FakeVideoTrackRenderer register itself to |video_track_|
51 rtc::scoped_ptr<FakeVideoTrackRenderer> renderer_1( 59 rtc::scoped_ptr<FakeVideoTrackRenderer> renderer_1(
52 new FakeVideoTrackRenderer(video_track_.get())); 60 new FakeVideoTrackRenderer(video_track_.get()));
53 61
54 capturer_.CaptureFrame(); 62 capturer_.CaptureFrame();
55 EXPECT_EQ(1, renderer_1->num_rendered_frames()); 63 EXPECT_EQ(1, renderer_1->num_rendered_frames());
56 64
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 video_track_->set_enabled(false); 110 video_track_->set_enabled(false);
103 capturer_.CaptureFrame(); 111 capturer_.CaptureFrame();
104 EXPECT_EQ(2, renderer->num_rendered_frames()); 112 EXPECT_EQ(2, renderer->num_rendered_frames());
105 EXPECT_TRUE(renderer->black_frame()); 113 EXPECT_TRUE(renderer->black_frame());
106 114
107 video_track_->set_enabled(true); 115 video_track_->set_enabled(true);
108 capturer_.CaptureFrame(); 116 capturer_.CaptureFrame();
109 EXPECT_EQ(3, renderer->num_rendered_frames()); 117 EXPECT_EQ(3, renderer->num_rendered_frames());
110 EXPECT_FALSE(renderer->black_frame()); 118 EXPECT_FALSE(renderer->black_frame());
111 } 119 }
OLDNEW
« no previous file with comments | « webrtc/api/videotrack.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698