OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_media_stream_track_host_base.h" | 5 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/numerics/safe_math.h" | |
8 #include "content/public/renderer/render_thread.h" | 9 #include "content/public/renderer/render_thread.h" |
9 #include "content/public/renderer/renderer_ppapi_host.h" | 10 #include "content/public/renderer/renderer_ppapi_host.h" |
10 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/host/dispatch_host_message.h" | 12 #include "ppapi/host/dispatch_host_message.h" |
12 #include "ppapi/host/host_message_context.h" | 13 #include "ppapi/host/host_message_context.h" |
13 #include "ppapi/host/ppapi_host.h" | 14 #include "ppapi/host/ppapi_host.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
15 #include "ppapi/shared_impl/media_stream_buffer.h" | 16 #include "ppapi/shared_impl/media_stream_buffer.h" |
16 | 17 |
17 using ppapi::host::HostMessageContext; | 18 using ppapi::host::HostMessageContext; |
(...skipping 11 matching lines...) Expand all Loading... | |
29 | 30 |
30 PepperMediaStreamTrackHostBase::~PepperMediaStreamTrackHostBase() {} | 31 PepperMediaStreamTrackHostBase::~PepperMediaStreamTrackHostBase() {} |
31 | 32 |
32 bool PepperMediaStreamTrackHostBase::InitBuffers(int32_t number_of_buffers, | 33 bool PepperMediaStreamTrackHostBase::InitBuffers(int32_t number_of_buffers, |
33 int32_t buffer_size, | 34 int32_t buffer_size, |
34 TrackType track_type) { | 35 TrackType track_type) { |
35 DCHECK_GT(number_of_buffers, 0); | 36 DCHECK_GT(number_of_buffers, 0); |
36 DCHECK_GT(buffer_size, | 37 DCHECK_GT(buffer_size, |
37 static_cast<int32_t>(sizeof(ppapi::MediaStreamBuffer::Header))); | 38 static_cast<int32_t>(sizeof(ppapi::MediaStreamBuffer::Header))); |
38 // Make each buffer 4 byte aligned. | 39 // Make each buffer 4 byte aligned. |
39 buffer_size = (buffer_size + 3) & ~0x3; | 40 base::CheckedNumeric<int32_t> buffer_size_aligned = buffer_size; |
41 buffer_size_aligned += (4 - buffer_size % 4); | |
40 | 42 |
41 // TODO(penghuang): |HostAllocateSharedMemoryBuffer| uses sync IPC. We should | 43 // TODO(penghuang): |HostAllocateSharedMemoryBuffer| uses sync IPC. We should |
42 // avoid it. | 44 // avoid it. |
43 int32_t size = number_of_buffers * buffer_size; | 45 base::CheckedNumeric<int32_t> size = number_of_buffers * buffer_size_aligned; |
46 if (!buffer_size_aligned.IsValid() || !size.IsValid()) | |
dcheng
2014/06/02 21:57:23
Nit: you only need to check size.IsValid() -- the
| |
47 return false; | |
48 | |
44 content::RenderThread* render_thread = content::RenderThread::Get(); | 49 content::RenderThread* render_thread = content::RenderThread::Get(); |
45 scoped_ptr<base::SharedMemory> shm( | 50 scoped_ptr<base::SharedMemory> shm( |
46 render_thread->HostAllocateSharedMemoryBuffer(size).Pass()); | 51 render_thread->HostAllocateSharedMemoryBuffer(size.ValueOrDie()).Pass()); |
47 if (!shm) | 52 if (!shm) |
48 return false; | 53 return false; |
49 | 54 |
50 base::SharedMemoryHandle shm_handle = shm->handle(); | 55 base::SharedMemoryHandle shm_handle = shm->handle(); |
51 if (!buffer_manager_.SetBuffers( | 56 if (!buffer_manager_.SetBuffers(number_of_buffers, |
52 number_of_buffers, buffer_size, shm.Pass(), true)) { | 57 buffer_size_aligned.ValueOrDie(), |
58 shm.Pass(), | |
59 true)) { | |
53 return false; | 60 return false; |
54 } | 61 } |
55 | 62 |
56 base::PlatformFile platform_file = | 63 base::PlatformFile platform_file = |
57 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
58 shm_handle; | 65 shm_handle; |
59 #elif defined(OS_POSIX) | 66 #elif defined(OS_POSIX) |
60 shm_handle.fd; | 67 shm_handle.fd; |
61 #else | 68 #else |
62 #error Not implemented. | 69 #error Not implemented. |
63 #endif | 70 #endif |
64 SerializedHandle handle(host_->ShareHandleWithRemote(platform_file, false), | 71 SerializedHandle handle(host_->ShareHandleWithRemote(platform_file, false), |
65 size); | 72 size.ValueOrDie()); |
66 bool readonly = (track_type == kRead); | 73 bool readonly = (track_type == kRead); |
67 host()->SendUnsolicitedReplyWithHandles( | 74 host()->SendUnsolicitedReplyWithHandles( |
68 pp_resource(), | 75 pp_resource(), |
69 PpapiPluginMsg_MediaStreamTrack_InitBuffers(number_of_buffers, | 76 PpapiPluginMsg_MediaStreamTrack_InitBuffers( |
70 buffer_size, | 77 number_of_buffers, |
71 readonly), | 78 buffer_size_aligned.ValueOrDie(), |
79 readonly), | |
72 std::vector<SerializedHandle>(1, handle)); | 80 std::vector<SerializedHandle>(1, handle)); |
73 return true; | 81 return true; |
74 } | 82 } |
75 | 83 |
76 void PepperMediaStreamTrackHostBase::SendEnqueueBufferMessageToPlugin( | 84 void PepperMediaStreamTrackHostBase::SendEnqueueBufferMessageToPlugin( |
77 int32_t index) { | 85 int32_t index) { |
78 DCHECK_GE(index, 0); | 86 DCHECK_GE(index, 0); |
79 DCHECK_LT(index, buffer_manager_.number_of_buffers()); | 87 DCHECK_LT(index, buffer_manager_.number_of_buffers()); |
80 host()->SendUnsolicitedReply( | 88 host()->SendUnsolicitedReply( |
81 pp_resource(), PpapiPluginMsg_MediaStreamTrack_EnqueueBuffer(index)); | 89 pp_resource(), PpapiPluginMsg_MediaStreamTrack_EnqueueBuffer(index)); |
(...skipping 25 matching lines...) Expand all Loading... | |
107 return PP_OK; | 115 return PP_OK; |
108 } | 116 } |
109 | 117 |
110 int32_t PepperMediaStreamTrackHostBase::OnHostMsgClose( | 118 int32_t PepperMediaStreamTrackHostBase::OnHostMsgClose( |
111 HostMessageContext* context) { | 119 HostMessageContext* context) { |
112 OnClose(); | 120 OnClose(); |
113 return PP_OK; | 121 return PP_OK; |
114 } | 122 } |
115 | 123 |
116 } // namespace content | 124 } // namespace content |
OLD | NEW |