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