| 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 "content/public/renderer/renderer_ppapi_host.h" | 7 #include "content/public/renderer/renderer_ppapi_host.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/host/dispatch_host_message.h" | 9 #include "ppapi/host/dispatch_host_message.h" |
| 10 #include "ppapi/host/host_message_context.h" | 10 #include "ppapi/host/host_message_context.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 IPC_END_MESSAGE_MAP() | 44 IPC_END_MESSAGE_MAP() |
| 45 return PP_ERROR_FAILED; | 45 return PP_ERROR_FAILED; |
| 46 } | 46 } |
| 47 | 47 |
| 48 int32_t PepperVideoDestinationHost::OnHostMsgOpen( | 48 int32_t PepperVideoDestinationHost::OnHostMsgOpen( |
| 49 HostMessageContext* context, | 49 HostMessageContext* context, |
| 50 const std::string& stream_url) { | 50 const std::string& stream_url) { |
| 51 GURL gurl(stream_url); | 51 GURL gurl(stream_url); |
| 52 if (!gurl.is_valid()) | 52 if (!gurl.is_valid()) |
| 53 return PP_ERROR_BADARGUMENT; | 53 return PP_ERROR_BADARGUMENT; |
| 54 // TODO(ronghuawu) Check that gurl is a valid MediaStream video track URL. | 54 |
| 55 // TODO(ronghuawu) Open a MediaStream video track. | 55 content::FrameWriterInterface* frame_writer = NULL; |
| 56 if (!VideoDestinationHandler::Open(NULL /* factory */, |
| 57 NULL /* registry */, |
| 58 gurl.spec(), |
| 59 &frame_writer)) |
| 60 return PP_ERROR_FAILED; |
| 61 frame_writer_.reset(frame_writer); |
| 62 |
| 56 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); | 63 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); |
| 57 reply_context.params.set_result(PP_OK); | 64 reply_context.params.set_result(PP_OK); |
| 58 host()->SendReply(reply_context, | 65 host()->SendReply(reply_context, |
| 59 PpapiPluginMsg_VideoDestination_OpenReply()); | 66 PpapiPluginMsg_VideoDestination_OpenReply()); |
| 60 return PP_OK_COMPLETIONPENDING; | 67 return PP_OK_COMPLETIONPENDING; |
| 61 } | 68 } |
| 62 | 69 |
| 63 int32_t PepperVideoDestinationHost::OnHostMsgPutFrame( | 70 int32_t PepperVideoDestinationHost::OnHostMsgPutFrame( |
| 64 HostMessageContext* context, | 71 HostMessageContext* context, |
| 65 const ppapi::HostResource& image_data, | 72 const ppapi::HostResource& image_data_resource, |
| 66 PP_TimeTicks timestamp) { | 73 PP_TimeTicks timestamp) { |
| 67 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> enter( | 74 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> enter( |
| 68 image_data.host_resource(), true); | 75 image_data_resource.host_resource(), true); |
| 69 if (enter.failed()) | 76 if (enter.failed()) |
| 70 return PP_ERROR_BADRESOURCE; | 77 return PP_ERROR_BADRESOURCE; |
| 71 webkit::ppapi::PPB_ImageData_Impl* image_resource = | 78 webkit::ppapi::PPB_ImageData_Impl* image_data_impl = |
| 72 static_cast<webkit::ppapi::PPB_ImageData_Impl*>(enter.object()); | 79 static_cast<webkit::ppapi::PPB_ImageData_Impl*>(enter.object()); |
| 73 | 80 |
| 74 if (!webkit::ppapi::PPB_ImageData_Impl::IsImageDataFormatSupported( | 81 if (!webkit::ppapi::PPB_ImageData_Impl::IsImageDataFormatSupported( |
| 75 image_resource->format())) | 82 image_data_impl->format())) |
| 76 return PP_ERROR_BADARGUMENT; | 83 return PP_ERROR_BADARGUMENT; |
| 77 | 84 |
| 78 // TODO(ronghuawu) write image data to MediaStream video track. | 85 if (!frame_writer_.get()) |
| 86 return PP_ERROR_FAILED; |
| 87 |
| 88 // Convert PP_TimeTicks (a double, in seconds) to time delta in microseconds, |
| 89 // and then to a timestamp in nanoseconds. |
| 90 base::TimeDelta time(base::Time::FromDoubleT(timestamp) - base::Time()); |
| 91 int64_t timestamp_ns = |
| 92 time.InMicroseconds() * base::Time::kNanosecondsPerMicrosecond; |
| 93 frame_writer_->PutFrame(image_data_impl, timestamp_ns); |
| 94 |
| 79 return PP_OK; | 95 return PP_OK; |
| 80 } | 96 } |
| 81 | 97 |
| 82 int32_t PepperVideoDestinationHost::OnHostMsgClose( | 98 int32_t PepperVideoDestinationHost::OnHostMsgClose( |
| 83 HostMessageContext* context) { | 99 HostMessageContext* context) { |
| 84 // TODO(ronghuawu) Close the video stream. | 100 frame_writer_.reset(NULL); |
| 85 return PP_OK; | 101 return PP_OK; |
| 86 } | 102 } |
| 87 | 103 |
| 88 } // namespace content | 104 } // namespace content |
| OLD | NEW |