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

Side by Side Diff: content/renderer/media/video_destination_handler.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 "content/renderer/media/video_destination_handler.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "content/renderer/media/media_stream_dependency_factory.h"
11 #include "content/renderer/media/media_stream_registry_interface.h"
12 #include "content/renderer/render_thread_impl.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h"
14 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
15
16 using cricket::CaptureState;
17 using cricket::VideoFormat;
18 using webkit::ppapi::PPB_ImageData_Impl;
19
20 static const cricket::FourCC kEffectColorFormat = cricket::FOURCC_BGRA;
21
22 namespace content {
23
24 PpFrameWriter::PpFrameWriter()
25 : started_(false) {}
26
27 PpFrameWriter::~PpFrameWriter() {}
28
29 CaptureState PpFrameWriter::Start(const VideoFormat& capture_format) {
30 if (started_) {
31 LOG(ERROR) << "PpFrameWriter::Start - "
32 << "Got a StartCapture when already started!";
33 return cricket::CS_FAILED;
34 }
35 started_ = true;
36 return cricket::CS_STARTING;
37 }
38
39 void PpFrameWriter::Stop() {
40 started_ = false;
41 SignalStateChange(this, cricket::CS_STOPPED);
42 }
43
44 bool PpFrameWriter::IsRunning() {
45 return started_;
46 }
47
48 bool PpFrameWriter::GetPreferredFourccs(std::vector<uint32>* fourccs) {
49 if (!fourccs) {
50 LOG(ERROR) << "PpFrameWriter::GetPreferredFourccs - "
51 << "fourccs is NULL.";
52 return false;
53 }
54 // The effects plugin output BGRA.
55 fourccs->push_back(kEffectColorFormat);
56 return true;
57 }
58
59 bool PpFrameWriter::GetBestCaptureFormat(const VideoFormat& desired,
60 VideoFormat* best_format) {
61 if (!best_format) {
62 LOG(ERROR) << "PpFrameWriter::GetBestCaptureFormat - "
63 << "best_format is NULL.";
64 return false;
65 }
66
67 // Use the desired format as the best format.
68 best_format->width = desired.width;
69 best_format->height = desired.height;
70 best_format->fourcc = kEffectColorFormat;
71 best_format->interval = desired.interval;
72 return true;
73 }
74
75 bool PpFrameWriter::IsScreencast() const {
76 return false;
77 }
78
79 void PpFrameWriter::PutFrame(PPB_ImageData_Impl* image_data,
80 int64 time_stamp_ns) {
81 ASSERT(image_data != NULL);
82 webkit::ppapi::ImageDataAutoMapper mapper(image_data);
83 if (!mapper.is_valid()) {
84 LOG(ERROR) << "PpFrameWriter::PutFrame - "
85 << "The image could not be mapped and is unusable.";
86 return;
87 }
88 const SkBitmap* bitmap = image_data->GetMappedBitmap();
89 ASSERT(bitmap != NULL);
90
91 cricket::CapturedFrame frame;
92 frame.elapsed_time = 0;
93 frame.time_stamp = time_stamp_ns;
94 frame.pixel_height = 1;
95 frame.pixel_width = 1;
96 frame.width = bitmap->width();
97 frame.height = bitmap->height();
98 if (image_data->format() == PP_IMAGEDATAFORMAT_BGRA_PREMUL) {
99 frame.fourcc = cricket::FOURCC_BGRA;
100 } else {
101 LOG(ERROR) << "PpFrameWriter::PutFrame - Got RGBA which is not supported.";
wjia(left Chromium) 2013/05/03 02:00:38 Is this technically impossible or just it just can
Ronghua Wu (Left Chromium) 2013/05/03 05:37:28 RGBA is not supported by the libjingle video frame
102 ASSERT(false);
103 return;
104 }
105 frame.data_size = bitmap->getSize();
106 frame.data = bitmap->getPixels();
107
108 // This signals to libJingle that a new VideoFrame is available.
109 // libJingle have no assumptions on what thread this signal come from.
110 SignalFrameCaptured(this, &frame);
111 }
112
113 VideoDestinationHandler::VideoDestinationHandler(
114 MediaStreamDependencyFactory* factory,
115 MediaStreamRegistryInterface* registry)
116 : factory_(factory),
117 registry_(registry) {
118 ASSERT(factory_ != NULL);
119 }
120
121 bool VideoDestinationHandler::Open(
122 const std::string& url, FrameWriterInterface** frame_writer) {
123 WebKit::WebMediaStream stream;
124 if (registry_) {
125 stream = registry_->GetMediaStream(url);
126 } else {
127 stream =
128 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(GURL(url));
129 }
130 if (stream.isNull() || !stream.extraData()) {
131 LOG(ERROR) << "VideoDestinationHandler::Open - invalid url: " << url;
132 return false;
133 }
134
135 // Create a new native video track and add it to |stream|.
136 std::string track_id = talk_base::ToString(talk_base::CreateRandomId64());
137 PpFrameWriter* capturer = new PpFrameWriter();
138 if (!factory_->AddNativeVideoMediaTrack(track_id, &stream, capturer)) {
139 delete capturer;
140 return false;
141 }
142
143 *frame_writer = capturer;
144 return true;
145 }
146
147 VideoDestinationHandler::~VideoDestinationHandler() {
148 }
149
150 } // namespace content
151
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698