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

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 "ppapi/c/ppb_image_data.h"
13 #include "ppapi/c/ppb_instance.h"
14 #include "ppapi/c/pp_size.h"
15 #include "ppapi/shared_impl/test_globals.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack .h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
20 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
21
22 using cricket::CapturedFrame;
23 using cricket::CaptureState;
24 using cricket::VideoCapturer;
25 using cricket::VideoFormat;
26 using cricket::VideoFormatPod;
27 using ppapi::TestGlobals;
28 using webkit::ppapi::PPB_ImageData_Impl;
29
30 namespace content {
31
32 static const std::string kTestStreamUrl = "stream_url";
33 static const std::string kUnknownStreamUrl = "unknown_stream_url";
34 static const VideoFormatPod kTestFormat = {
35 640, 360, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY
36 };
37
38 class PpFrameWriterTest
39 : public ::testing::Test,
40 public sigslot::has_slots<> {
41 public:
42 PpFrameWriterTest()
43 : last_capture_state_(cricket::CS_FAILED),
44 captured_frame_count_(0),
45 captured_frame_(NULL) {
46 writer_.SignalStateChange.connect(this, &PpFrameWriterTest::OnStateChange);
47 writer_.SignalFrameCaptured.connect(
48 this, &PpFrameWriterTest::OnFrameCaptured);
49 }
50
51 void OnStateChange(VideoCapturer* capturer, CaptureState state) {
52 last_capture_state_ = state;
53 }
54
55 void OnFrameCaptured(VideoCapturer* capturer, const CapturedFrame* frame) {
56 ++captured_frame_count_;
57 captured_frame_ = const_cast<CapturedFrame*>(frame);
58 }
59
60 protected:
61 PpFrameWriter writer_;
62 CaptureState last_capture_state_;
63 int captured_frame_count_;
64 CapturedFrame* captured_frame_;
65 TestGlobals globals_;
66 };
67
68 class VideoDestinationHandlerTest : public ::testing::Test {
69 public:
70 VideoDestinationHandlerTest() : registry_(&dependency_factory_) {
71 handler_.reset(new VideoDestinationHandler(&dependency_factory_,
72 &registry_));
73 dependency_factory_.EnsurePeerConnectionFactory();
74 registry_.Init(kTestStreamUrl);
75 }
76
77 protected:
78 scoped_ptr<VideoDestinationHandler> handler_;
79 MockMediaStreamDependencyFactory dependency_factory_;
80 MockMediaStreamRegistry registry_;
81 };
82
83 TEST_F(PpFrameWriterTest, StartStop) {
84 EXPECT_FALSE(writer_.IsRunning());
85 EXPECT_EQ(cricket::CS_STARTING, writer_.Start(VideoFormat(kTestFormat)));
86 EXPECT_TRUE(writer_.IsRunning());
87 EXPECT_EQ(cricket::CS_FAILED, writer_.Start(VideoFormat(kTestFormat)));
88 writer_.Stop();
89 EXPECT_EQ(cricket::CS_STOPPED, last_capture_state_);
90 }
91
92 TEST_F(PpFrameWriterTest, GetPreferredFourccs) {
93 std::vector<uint32> fourccs;
94 EXPECT_TRUE(writer_.GetPreferredFourccs(&fourccs));
95 EXPECT_EQ(1u, fourccs.size());
96 EXPECT_EQ(cricket::FOURCC_BGRA, fourccs[0]);
97 }
98
99 TEST_F(PpFrameWriterTest, GetBestCaptureFormat) {
100 VideoFormat desired(kTestFormat);
101 VideoFormat best_format;
102 EXPECT_FALSE(writer_.GetBestCaptureFormat(desired, NULL));
103 EXPECT_TRUE(writer_.GetBestCaptureFormat(desired, &best_format));
104 EXPECT_EQ(cricket::FOURCC_BGRA, best_format.fourcc);
105
106 desired.fourcc = best_format.fourcc;
107 EXPECT_EQ(desired, best_format);
108 }
109
110 TEST_F(PpFrameWriterTest, PutFrame) {
111 // TODO(ronghuawu): Figure out how to mock PPB_ImageData_Impl and enable
112 // this test.
113 // PP_Instance instance = 0x1234561;
114 // globals_.GetResourceTracker()->DidCreateInstance(instance);
115 // PP_Size size = {640, 480};
116 // PP_Bool init_to_zero = PP_TRUE;
117 // PP_ImageDataFormat format = PP_IMAGEDATAFORMAT_BGRA_PREMUL;
118 // scoped_refptr<PPB_ImageData_Impl>
119 // data(new PPB_ImageData_Impl(instance, PPB_ImageData_Impl::NACL));
120 // EXPECT_TRUE(data->Init(format, size.width, size.height, init_to_zero));
121 // int64 ts_ns = 345678;
122 //
123 // EXPECT_EQ(cricket::CS_STARTING, writer_.Start(VideoFormat(kTestFormat)));
124 // EXPECT_EQ(0, captured_frame_count_);
125 // writer_.PutFrame(data.get(), ts_ns);
126 // EXPECT_EQ(1, captured_frame_count_);
127 }
128
129 TEST_F(VideoDestinationHandlerTest, Open) {
130 FrameWriterInterface* frame_writer = NULL;
131 // Unknow url will return false.
132 EXPECT_FALSE(handler_->Open(kUnknownStreamUrl, &frame_writer));
133 EXPECT_TRUE(handler_->Open(kTestStreamUrl, &frame_writer));
134 EXPECT_TRUE(frame_writer);
135
136 // Verify the video track has been added.
137 const WebKit::WebMediaStream test_stream = registry_.test_stream();
138 WebKit::WebVector<WebKit::WebMediaStreamTrack> video_tracks;
139 test_stream.videoSources(video_tracks);
140 EXPECT_EQ(1u, video_tracks.size());
141
142 // Verify the |frame_writer| has been set to the capturer of the video track.
143 MediaStreamExtraData* extra_data =
144 static_cast<MediaStreamExtraData*>(test_stream.extraData());
145 DCHECK(extra_data);
146 webrtc::MediaStreamInterface* native_stream = extra_data->stream();
147 DCHECK(native_stream);
148 webrtc::VideoTrackVector native_video_tracks =
149 native_stream->GetVideoTracks();
150 EXPECT_EQ(1u, native_video_tracks.size());
151 cricket::VideoCapturer* capturer =
152 native_video_tracks[0]->GetSource()->GetVideoCapturer();
153 EXPECT_EQ(static_cast<PpFrameWriter*>(capturer),
154 static_cast<PpFrameWriter*>(frame_writer));
155 }
156
157 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698