Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_destination_host.h" | 5 #include "content/renderer/pepper/pepper_video_destination_host.h" |
| 6 | 6 |
| 7 #include <string> | |
|
bbudge
2014/10/08 17:23:23
nit: this is included in the header now.
perkj_chrome
2014/10/08 18:37:37
Done.
| |
| 8 | |
| 7 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 8 #include "content/public/renderer/renderer_ppapi_host.h" | 10 #include "content/public/renderer/renderer_ppapi_host.h" |
| 9 #include "content/renderer/pepper/ppb_image_data_impl.h" | 11 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 10 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/host/dispatch_host_message.h" | 13 #include "ppapi/host/dispatch_host_message.h" |
| 12 #include "ppapi/host/host_message_context.h" | 14 #include "ppapi/host/host_message_context.h" |
| 13 #include "ppapi/host/ppapi_host.h" | 15 #include "ppapi/host/ppapi_host.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/thunk/enter.h" | 17 #include "ppapi/thunk/enter.h" |
| 16 #include "ppapi/thunk/ppb_image_data_api.h" | 18 #include "ppapi/thunk/ppb_image_data_api.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 43 return PP_ERROR_FAILED; | 45 return PP_ERROR_FAILED; |
| 44 } | 46 } |
| 45 | 47 |
| 46 int32_t PepperVideoDestinationHost::OnHostMsgOpen( | 48 int32_t PepperVideoDestinationHost::OnHostMsgOpen( |
| 47 HostMessageContext* context, | 49 HostMessageContext* context, |
| 48 const std::string& stream_url) { | 50 const std::string& stream_url) { |
| 49 GURL gurl(stream_url); | 51 GURL gurl(stream_url); |
| 50 if (!gurl.is_valid()) | 52 if (!gurl.is_valid()) |
| 51 return PP_ERROR_BADARGUMENT; | 53 return PP_ERROR_BADARGUMENT; |
| 52 | 54 |
| 53 FrameWriterInterface* frame_writer = NULL; | |
| 54 if (!VideoDestinationHandler::Open( | 55 if (!VideoDestinationHandler::Open( |
| 55 NULL /* registry */, gurl.spec(), &frame_writer)) | 56 NULL /* registry */, gurl.spec(), &frame_writer_)) |
| 56 return PP_ERROR_FAILED; | 57 return PP_ERROR_FAILED; |
| 57 frame_writer_.reset(frame_writer); | |
| 58 | 58 |
| 59 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); | 59 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); |
| 60 reply_context.params.set_result(PP_OK); | 60 reply_context.params.set_result(PP_OK); |
| 61 host()->SendReply(reply_context, PpapiPluginMsg_VideoDestination_OpenReply()); | 61 host()->SendReply(reply_context, PpapiPluginMsg_VideoDestination_OpenReply()); |
| 62 return PP_OK_COMPLETIONPENDING; | 62 return PP_OK_COMPLETIONPENDING; |
| 63 } | 63 } |
| 64 | 64 |
| 65 int32_t PepperVideoDestinationHost::OnHostMsgPutFrame( | 65 int32_t PepperVideoDestinationHost::OnHostMsgPutFrame( |
| 66 HostMessageContext* context, | 66 HostMessageContext* context, |
| 67 const ppapi::HostResource& image_data_resource, | 67 const ppapi::HostResource& image_data_resource, |
| 68 PP_TimeTicks timestamp) { | 68 PP_TimeTicks timestamp) { |
| 69 TRACE_EVENT0("video", "PepperVideoDestinationHost::OnHostMsgPutFrame"); | |
| 69 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> enter( | 70 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> enter( |
| 70 image_data_resource.host_resource(), true); | 71 image_data_resource.host_resource(), true); |
| 71 if (enter.failed()) | 72 if (enter.failed()) |
| 72 return PP_ERROR_BADRESOURCE; | 73 return PP_ERROR_BADRESOURCE; |
| 73 PPB_ImageData_Impl* image_data_impl = | 74 PPB_ImageData_Impl* image_data_impl = |
| 74 static_cast<PPB_ImageData_Impl*>(enter.object()); | 75 static_cast<PPB_ImageData_Impl*>(enter.object()); |
| 75 | 76 |
| 76 if (!PPB_ImageData_Impl::IsImageDataFormatSupported( | 77 if (!PPB_ImageData_Impl::IsImageDataFormatSupported( |
| 77 image_data_impl->format())) | 78 image_data_impl->format())) |
| 78 return PP_ERROR_BADARGUMENT; | 79 return PP_ERROR_BADARGUMENT; |
| 79 | 80 |
| 80 if (!frame_writer_.get()) | 81 if (frame_writer_.is_null()) |
| 81 return PP_ERROR_FAILED; | 82 return PP_ERROR_FAILED; |
| 82 | 83 |
| 83 // Convert PP_TimeTicks (a double, in seconds) to a TimeDelta (int64, | 84 // Convert PP_TimeTicks (a double, in seconds) to a TimeDelta (int64, |
| 84 // microseconds) and then to a video timestamp (int64, nanoseconds). All times | 85 // microseconds) and then to a video timestamp (int64, nanoseconds). All times |
| 85 // are relative to the Unix Epoch so don't subtract it to get a delta. | 86 // are relative to the Unix Epoch so don't subtract it to get a delta. |
| 86 base::TimeDelta time_delta = | 87 base::TimeDelta time_delta = |
| 87 base::Time::FromDoubleT(timestamp) - base::Time(); | 88 base::Time::FromDoubleT(timestamp) - base::Time(); |
| 88 int64_t timestamp_ns = | 89 int64_t timestamp_ns = |
| 89 time_delta.InMicroseconds() * base::Time::kNanosecondsPerMicrosecond; | 90 time_delta.InMicroseconds() * base::Time::kNanosecondsPerMicrosecond; |
| 90 frame_writer_->PutFrame(image_data_impl, timestamp_ns); | 91 frame_writer_.Run(image_data_impl, timestamp_ns); |
| 91 | 92 |
| 92 return PP_OK; | 93 return PP_OK; |
| 93 } | 94 } |
| 94 | 95 |
| 95 int32_t PepperVideoDestinationHost::OnHostMsgClose( | 96 int32_t PepperVideoDestinationHost::OnHostMsgClose( |
| 96 HostMessageContext* context) { | 97 HostMessageContext* context) { |
| 97 frame_writer_.reset(NULL); | 98 frame_writer_.Reset(); |
| 98 return PP_OK; | 99 return PP_OK; |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace content | 102 } // namespace content |
| OLD | NEW |