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

Side by Side Diff: content/renderer/pepper/pepper_video_source_host.cc

Issue 225903006: PPAPI: Run clang_format.py on content/renderer/pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 "content/renderer/pepper/pepper_video_source_host.h" 5 #include "content/renderer/pepper/pepper_video_source_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/numerics/safe_conversions.h" 8 #include "base/numerics/safe_conversions.h"
9 #include "content/public/renderer/renderer_ppapi_host.h" 9 #include "content/public/renderer/renderer_ppapi_host.h"
10 #include "content/renderer/pepper/ppb_image_data_impl.h" 10 #include "content/renderer/pepper/ppb_image_data_impl.h"
(...skipping 11 matching lines...) Expand all
22 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
23 23
24 using ppapi::host::HostMessageContext; 24 using ppapi::host::HostMessageContext;
25 using ppapi::host::ReplyMessageContext; 25 using ppapi::host::ReplyMessageContext;
26 26
27 namespace content { 27 namespace content {
28 28
29 PepperVideoSourceHost::FrameReceiver::FrameReceiver( 29 PepperVideoSourceHost::FrameReceiver::FrameReceiver(
30 const base::WeakPtr<PepperVideoSourceHost>& host) 30 const base::WeakPtr<PepperVideoSourceHost>& host)
31 : host_(host), 31 : host_(host),
32 main_message_loop_proxy_(base::MessageLoopProxy::current()) { 32 main_message_loop_proxy_(base::MessageLoopProxy::current()) {}
33 }
34 33
35 PepperVideoSourceHost::FrameReceiver::~FrameReceiver() { 34 PepperVideoSourceHost::FrameReceiver::~FrameReceiver() {}
36 }
37 35
38 bool PepperVideoSourceHost::FrameReceiver::GotFrame( 36 bool PepperVideoSourceHost::FrameReceiver::GotFrame(
39 cricket::VideoFrame* frame) { 37 cricket::VideoFrame* frame) {
40 // It's not safe to access the host from this thread, so post a task to our 38 // It's not safe to access the host from this thread, so post a task to our
41 // main thread to transfer the new frame. 39 // main thread to transfer the new frame.
42 main_message_loop_proxy_->PostTask( 40 main_message_loop_proxy_->PostTask(
43 FROM_HERE, 41 FROM_HERE,
44 base::Bind(&FrameReceiver::OnGotFrame, 42 base::Bind(&FrameReceiver::OnGotFrame,
45 this, 43 this,
46 base::Passed(scoped_ptr<cricket::VideoFrame>(frame)))); 44 base::Passed(scoped_ptr<cricket::VideoFrame>(frame))));
47 45
48 return true; 46 return true;
49 } 47 }
50 48
51 void PepperVideoSourceHost::FrameReceiver::OnGotFrame( 49 void PepperVideoSourceHost::FrameReceiver::OnGotFrame(
52 scoped_ptr<cricket::VideoFrame> frame) { 50 scoped_ptr<cricket::VideoFrame> frame) {
53 if (host_.get()) { 51 if (host_.get()) {
54 // Take ownership of the new frame, and possibly delete any unsent one. 52 // Take ownership of the new frame, and possibly delete any unsent one.
55 host_->last_frame_.swap(frame); 53 host_->last_frame_.swap(frame);
56 54
57 if (host_->get_frame_pending_) 55 if (host_->get_frame_pending_)
58 host_->SendGetFrameReply(); 56 host_->SendGetFrameReply();
59 } 57 }
60 } 58 }
61 59
62 PepperVideoSourceHost::PepperVideoSourceHost( 60 PepperVideoSourceHost::PepperVideoSourceHost(RendererPpapiHost* host,
63 RendererPpapiHost* host, 61 PP_Instance instance,
64 PP_Instance instance, 62 PP_Resource resource)
65 PP_Resource resource)
66 : ResourceHost(host->GetPpapiHost(), instance, resource), 63 : ResourceHost(host->GetPpapiHost(), instance, resource),
67 renderer_ppapi_host_(host), 64 renderer_ppapi_host_(host),
68 source_handler_(new VideoSourceHandler(NULL)), 65 source_handler_(new VideoSourceHandler(NULL)),
69 get_frame_pending_(false), 66 get_frame_pending_(false),
70 weak_factory_(this) { 67 weak_factory_(this) {
71 frame_receiver_ = new FrameReceiver(weak_factory_.GetWeakPtr()); 68 frame_receiver_ = new FrameReceiver(weak_factory_.GetWeakPtr());
72 } 69 }
73 70
74 PepperVideoSourceHost::~PepperVideoSourceHost() { 71 PepperVideoSourceHost::~PepperVideoSourceHost() { Close(); }
75 Close();
76 }
77 72
78 int32_t PepperVideoSourceHost::OnResourceMessageReceived( 73 int32_t PepperVideoSourceHost::OnResourceMessageReceived(
79 const IPC::Message& msg, 74 const IPC::Message& msg,
80 HostMessageContext* context) { 75 HostMessageContext* context) {
81 IPC_BEGIN_MESSAGE_MAP(PepperVideoSourceHost, msg) 76 IPC_BEGIN_MESSAGE_MAP(PepperVideoSourceHost, msg)
82 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_VideoSource_Open, 77 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_VideoSource_Open,
83 OnHostMsgOpen) 78 OnHostMsgOpen)
84 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoSource_GetFrame, 79 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoSource_GetFrame,
85 OnHostMsgGetFrame) 80 OnHostMsgGetFrame)
86 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoSource_Close, 81 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoSource_Close,
87 OnHostMsgClose) 82 OnHostMsgClose)
88 IPC_END_MESSAGE_MAP() 83 IPC_END_MESSAGE_MAP()
89 return PP_ERROR_FAILED; 84 return PP_ERROR_FAILED;
90 } 85 }
91 86
92 int32_t PepperVideoSourceHost::OnHostMsgOpen(HostMessageContext* context, 87 int32_t PepperVideoSourceHost::OnHostMsgOpen(HostMessageContext* context,
93 const std::string& stream_url) { 88 const std::string& stream_url) {
94 GURL gurl(stream_url); 89 GURL gurl(stream_url);
95 if (!gurl.is_valid()) 90 if (!gurl.is_valid())
96 return PP_ERROR_BADARGUMENT; 91 return PP_ERROR_BADARGUMENT;
97 92
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 IPC::PlatformFileForTransit image_handle; 135 IPC::PlatformFileForTransit image_handle;
141 uint32_t byte_count; 136 uint32_t byte_count;
142 ppapi::ScopedPPResource resource( 137 ppapi::ScopedPPResource resource(
143 ppapi::ScopedPPResource::PassRef(), 138 ppapi::ScopedPPResource::PassRef(),
144 ppapi::proxy::PPB_ImageData_Proxy::CreateImageData( 139 ppapi::proxy::PPB_ImageData_Proxy::CreateImageData(
145 pp_instance(), 140 pp_instance(),
146 ppapi::PPB_ImageData_Shared::SIMPLE, 141 ppapi::PPB_ImageData_Shared::SIMPLE,
147 PP_IMAGEDATAFORMAT_BGRA_PREMUL, 142 PP_IMAGEDATAFORMAT_BGRA_PREMUL,
148 PP_MakeSize(width, height), 143 PP_MakeSize(width, height),
149 false /* init_to_zero */, 144 false /* init_to_zero */,
150 &image_desc, &image_handle, &byte_count)); 145 &image_desc,
146 &image_handle,
147 &byte_count));
151 if (!resource.get()) { 148 if (!resource.get()) {
152 SendGetFrameErrorReply(PP_ERROR_FAILED); 149 SendGetFrameErrorReply(PP_ERROR_FAILED);
153 return; 150 return;
154 } 151 }
155 152
156 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> 153 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API>
157 enter_resource(resource, false); 154 enter_resource(resource, false);
158 if (enter_resource.failed()) { 155 if (enter_resource.failed()) {
159 SendGetFrameErrorReply(PP_ERROR_FAILED); 156 SendGetFrameErrorReply(PP_ERROR_FAILED);
160 return; 157 return;
(...skipping 12 matching lines...) Expand all
173 SendGetFrameErrorReply(PP_ERROR_FAILED); 170 SendGetFrameErrorReply(PP_ERROR_FAILED);
174 return; 171 return;
175 } 172 }
176 uint8_t* bitmap_pixels = static_cast<uint8_t*>(bitmap->getPixels()); 173 uint8_t* bitmap_pixels = static_cast<uint8_t*>(bitmap->getPixels());
177 if (!bitmap_pixels) { 174 if (!bitmap_pixels) {
178 SendGetFrameErrorReply(PP_ERROR_FAILED); 175 SendGetFrameErrorReply(PP_ERROR_FAILED);
179 return; 176 return;
180 } 177 }
181 178
182 size_t bitmap_size = bitmap->getSize(); 179 size_t bitmap_size = bitmap->getSize();
183 frame->ConvertToRgbBuffer(cricket::FOURCC_BGRA, 180 frame->ConvertToRgbBuffer(
184 bitmap_pixels, 181 cricket::FOURCC_BGRA, bitmap_pixels, bitmap_size, bitmap->rowBytes());
185 bitmap_size,
186 bitmap->rowBytes());
187 182
188 ppapi::HostResource host_resource; 183 ppapi::HostResource host_resource;
189 host_resource.SetHostResource(pp_instance(), resource.get()); 184 host_resource.SetHostResource(pp_instance(), resource.get());
190 185
191 // Convert a video timestamp (int64, in nanoseconds) to a time delta (int64, 186 // Convert a video timestamp (int64, in nanoseconds) to a time delta (int64,
192 // microseconds) and then to a PP_TimeTicks (a double, in seconds). All times 187 // microseconds) and then to a PP_TimeTicks (a double, in seconds). All times
193 // are relative to the Unix Epoch. 188 // are relative to the Unix Epoch.
194 base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds( 189 base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds(
195 frame->GetTimeStamp() / base::Time::kNanosecondsPerMicrosecond); 190 frame->GetTimeStamp() / base::Time::kNanosecondsPerMicrosecond);
196 PP_TimeTicks timestamp = time_delta.InSecondsF(); 191 PP_TimeTicks timestamp = time_delta.InSecondsF();
197 192
198 ppapi::proxy::SerializedHandle serialized_handle; 193 ppapi::proxy::SerializedHandle serialized_handle;
199 serialized_handle.set_shmem(image_handle, byte_count); 194 serialized_handle.set_shmem(image_handle, byte_count);
200 reply_context_.params.AppendHandle(serialized_handle); 195 reply_context_.params.AppendHandle(serialized_handle);
201 196
202 host()->SendReply(reply_context_, 197 host()->SendReply(reply_context_,
203 PpapiPluginMsg_VideoSource_GetFrameReply(host_resource, 198 PpapiPluginMsg_VideoSource_GetFrameReply(
204 image_desc, 199 host_resource, image_desc, timestamp));
205 timestamp));
206 200
207 reply_context_ = ppapi::host::ReplyMessageContext(); 201 reply_context_ = ppapi::host::ReplyMessageContext();
208 202
209 // Keep a reference once we know this method succeeds. 203 // Keep a reference once we know this method succeeds.
210 resource.Release(); 204 resource.Release();
211 } 205 }
212 206
213 void PepperVideoSourceHost::SendGetFrameErrorReply(int32_t error) { 207 void PepperVideoSourceHost::SendGetFrameErrorReply(int32_t error) {
214 reply_context_.params.set_result(error); 208 reply_context_.params.set_result(error);
215 host()->SendReply( 209 host()->SendReply(
216 reply_context_, 210 reply_context_,
217 PpapiPluginMsg_VideoSource_GetFrameReply(ppapi::HostResource(), 211 PpapiPluginMsg_VideoSource_GetFrameReply(
218 PP_ImageDataDesc(), 212 ppapi::HostResource(), PP_ImageDataDesc(), 0.0 /* timestamp */));
219 0.0 /* timestamp */));
220 reply_context_ = ppapi::host::ReplyMessageContext(); 213 reply_context_ = ppapi::host::ReplyMessageContext();
221 } 214 }
222 215
223 void PepperVideoSourceHost::Close() { 216 void PepperVideoSourceHost::Close() {
224 if (source_handler_.get() && !stream_url_.empty()) 217 if (source_handler_.get() && !stream_url_.empty())
225 source_handler_->Close(frame_receiver_.get()); 218 source_handler_->Close(frame_receiver_.get());
226 219
227 source_handler_.reset(NULL); 220 source_handler_.reset(NULL);
228 stream_url_.clear(); 221 stream_url_.clear();
229 } 222 }
230 223
231 } // namespace content 224 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698