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