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: content/renderer/media/video_destination_handler_unittest.cc

Issue 14312015: Effects Pepper Plugin and MediaStream Glue. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/utf_string_conversions.h"
8 #include "content/renderer/media/media_stream_extra_data.h"
9 #include "content/renderer/media/mock_media_stream_dependency_factory.h"
10 #include "content/renderer/media/mock_media_stream_registry.h"
11 #include "content/renderer/media/video_destination_handler.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack .h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
16
17 using cricket::CapturedFrame;
18 using cricket::CaptureState;
19 using cricket::VideoCapturer;
20 using cricket::VideoFormat;
21 using cricket::VideoFormatPod;
22
23 namespace content {
24
25 static const std::string kTestStreamUrl = "stream_url";
26 static const std::string kUnknownStreamUrl = "unknown_stream_url";
27 static const VideoFormatPod kTestFormat = {
28 640, 360, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY
29 };
30
31 class PpFrameWriterTest
32 : public ::testing::Test,
33 public sigslot::has_slots<> {
34 public:
35 PpFrameWriterTest()
36 : last_capture_state_(cricket::CS_FAILED),
37 captured_frame_count_(0),
38 captured_frame_(NULL) {
39 writer_.SignalStateChange.connect(this, &PpFrameWriterTest::OnStateChange);
40 writer_.SignalFrameCaptured.connect(
41 this, &PpFrameWriterTest::OnFrameCaptured);
42 }
43
44 void OnStateChange(VideoCapturer* capturer, CaptureState state) {
45 last_capture_state_ = state;
46 }
47
48 void OnFrameCaptured(VideoCapturer* capturer, const CapturedFrame* frame) {
49 ++captured_frame_count_;
50 captured_frame_ = const_cast<CapturedFrame*>(frame);
51 }
52
53 protected:
54 PpFrameWriter writer_;
55 CaptureState last_capture_state_;
56 int captured_frame_count_;
57 CapturedFrame* captured_frame_;
58 };
59
60 class VideoDestinationHandlerTest : public ::testing::Test {
61 public:
62 VideoDestinationHandlerTest() : registry_(&dependency_factory_) {
63 handler_.reset(new VideoDestinationHandler(&dependency_factory_,
64 &registry_));
65 dependency_factory_.EnsurePeerConnectionFactory();
66 registry_.Init(kTestStreamUrl);
67 }
68
69 protected:
70 scoped_ptr<VideoDestinationHandler> handler_;
71 MockMediaStreamDependencyFactory dependency_factory_;
72 MockMediaStreamRegistry registry_;
73 };
74
75 TEST_F(PpFrameWriterTest, StartStop) {
76 EXPECT_FALSE(writer_.IsRunning());
77 EXPECT_EQ(cricket::CS_STARTING, writer_.Start(VideoFormat(kTestFormat)));
78 EXPECT_TRUE(writer_.IsRunning());
79 EXPECT_EQ(cricket::CS_FAILED, writer_.Start(VideoFormat(kTestFormat)));
80 writer_.Stop();
81 EXPECT_EQ(cricket::CS_STOPPED, last_capture_state_);
82 }
83
84 TEST_F(PpFrameWriterTest, GetPreferredFourccs) {
85 std::vector<uint32> fourccs;
86 EXPECT_TRUE(writer_.GetPreferredFourccs(&fourccs));
87 EXPECT_EQ(1u, fourccs.size());
88 EXPECT_EQ(cricket::FOURCC_BGRA, fourccs[0]);
89 }
90
91 TEST_F(PpFrameWriterTest, GetBestCaptureFormat) {
92 VideoFormat desired(kTestFormat);
93 VideoFormat best_format;
94 EXPECT_FALSE(writer_.GetBestCaptureFormat(desired, NULL));
95 EXPECT_TRUE(writer_.GetBestCaptureFormat(desired, &best_format));
96 EXPECT_EQ(cricket::FOURCC_BGRA, best_format.fourcc);
97
98 desired.fourcc = best_format.fourcc;
99 EXPECT_EQ(desired, best_format);
100 }
101
102 TEST_F(PpFrameWriterTest, PutFrame) {
103 // Init a test frame.
104 CapturedFrame test_frame1;
105 CapturedFrame test_frame2;
106 writer_.PutFrame(&test_frame1);
107 EXPECT_EQ(cricket::CS_STARTING, writer_.Start(VideoFormat(kTestFormat)));
108 EXPECT_EQ(0, captured_frame_count_);
109 writer_.PutFrame(&test_frame1);
110 EXPECT_EQ(1, captured_frame_count_);
111 EXPECT_EQ(&test_frame1, captured_frame_);
112 writer_.PutFrame(&test_frame2);
113 EXPECT_EQ(2, captured_frame_count_);
114 EXPECT_EQ(&test_frame2, captured_frame_);
115 }
116
117 TEST_F(VideoDestinationHandlerTest, Open) {
118 FrameWriterInterface* frame_writer = NULL;
119 // Unknow url will return false.
120 EXPECT_FALSE(handler_->Open(kUnknownStreamUrl, &frame_writer));
121 EXPECT_TRUE(handler_->Open(kTestStreamUrl, &frame_writer));
122 EXPECT_TRUE(frame_writer);
123
124 // Verify the video track has been added.
125 const WebKit::WebMediaStream test_stream = registry_.test_stream();
126 WebKit::WebVector<WebKit::WebMediaStreamTrack> video_tracks;
127 test_stream.videoSources(video_tracks);
128 EXPECT_EQ(1u, video_tracks.size());
129
130 // Verify the |frame_writer| has been set to the capturer of the video track.
131 MediaStreamExtraData* extra_data =
132 static_cast<MediaStreamExtraData*>(test_stream.extraData());
133 DCHECK(extra_data);
134 webrtc::MediaStreamInterface* native_stream = extra_data->stream();
135 DCHECK(native_stream);
136 webrtc::VideoTrackVector native_video_tracks =
137 native_stream->GetVideoTracks();
138 EXPECT_EQ(1u, native_video_tracks.size());
139 cricket::VideoCapturer* capturer =
140 native_video_tracks[0]->GetSource()->GetVideoCapturer();
141 EXPECT_EQ(static_cast<PpFrameWriter*>(capturer),
142 static_cast<PpFrameWriter*>(frame_writer));
143 }
144
145 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698