OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/common/gpu/client/gpu_video_encode_accelerator_host.h" | 5 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/gpu/client/gpu_channel_host.h" | 8 #include "content/common/gpu/client/gpu_channel_host.h" |
9 #include "content/common/gpu/gpu_messages.h" | 9 #include "content/common/gpu/gpu_messages.h" |
10 #include "content/common/gpu/media/gpu_video_accelerator_util.h" | 10 #include "content/common/gpu/media/gpu_video_accelerator_util.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return true; | 110 return true; |
111 } | 111 } |
112 | 112 |
113 void GpuVideoEncodeAcceleratorHost::Encode( | 113 void GpuVideoEncodeAcceleratorHost::Encode( |
114 const scoped_refptr<media::VideoFrame>& frame, | 114 const scoped_refptr<media::VideoFrame>& frame, |
115 bool force_keyframe) { | 115 bool force_keyframe) { |
116 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
117 if (!channel_) | 117 if (!channel_) |
118 return; | 118 return; |
119 | 119 |
120 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { | 120 AcceleratedVideoEncoderMsg_Encode_Params params; |
121 NOTIFY_ERROR(kPlatformFailureError) | 121 params.frame_id = next_frame_id_; |
122 << "Encode(): cannot encode frame not backed by shared memory"; | 122 params.force_keyframe = force_keyframe; |
123 return; | 123 params.storage_type = frame->storage_type(); |
124 } | 124 params.pixel_format = frame->format(); |
125 base::SharedMemoryHandle handle = | 125 |
126 channel_->ShareToGpuProcess(frame->shared_memory_handle()); | 126 if (frame->storage_type() == media::VideoFrame::STORAGE_SHMEM) { |
127 if (!base::SharedMemory::IsHandleValid(handle)) { | 127 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { |
128 NOTIFY_ERROR(kPlatformFailureError) | 128 NOTIFY_ERROR(kPlatformFailureError) << "EncodeSharedMemory(): cannot " |
129 << "Encode(): failed to duplicate buffer handle for GPU process"; | 129 "encode frame with invalid shared " |
130 return; | 130 "memory handle"; |
| 131 return; |
| 132 } |
| 133 params.buffer_handle = |
| 134 channel_->ShareToGpuProcess(frame->shared_memory_handle()); |
| 135 if (!base::SharedMemory::IsHandleValid(params.buffer_handle)) { |
| 136 NOTIFY_ERROR(kPlatformFailureError) << "EncodeSharedMemory(): failed to " |
| 137 "duplicate buffer handle for GPU " |
| 138 "process"; |
| 139 return; |
| 140 } |
| 141 // We assume that planar frame data passed here is packed and contiguous. |
| 142 params.buffer_size = 0; |
| 143 const size_t plane_count = media::VideoFrame::NumPlanes(frame->format()); |
| 144 for (size_t i = 0; i < plane_count; ++i) { |
| 145 // Cast DCHECK parameters to void* to avoid printing uint8* as a string. |
| 146 DCHECK_EQ(reinterpret_cast<void*>(frame->data(i)), |
| 147 reinterpret_cast<void*>((frame->data(0) + params.buffer_size))) |
| 148 << "plane=" << i; |
| 149 params.buffer_size += frame->stride(i) * frame->rows(i); |
| 150 } |
| 151 params.buffer_offset = frame->shared_memory_offset(); |
131 } | 152 } |
132 | 153 |
133 // We assume that planar frame data passed here is packed and contiguous. | 154 Send(new AcceleratedVideoEncoderMsg_Encode(encoder_route_id_, params)); |
134 const size_t plane_count = media::VideoFrame::NumPlanes(frame->format()); | |
135 size_t frame_size = 0; | |
136 for (size_t i = 0; i < plane_count; ++i) { | |
137 // Cast DCHECK parameters to void* to avoid printing uint8* as a string. | |
138 DCHECK_EQ(reinterpret_cast<void*>(frame->data(i)), | |
139 reinterpret_cast<void*>((frame->data(0) + frame_size))) | |
140 << "plane=" << i; | |
141 frame_size += frame->stride(i) * frame->rows(i); | |
142 } | |
143 | |
144 Send(new AcceleratedVideoEncoderMsg_Encode( | |
145 encoder_route_id_, next_frame_id_, handle, frame->shared_memory_offset(), | |
146 frame_size, force_keyframe)); | |
147 frame_map_[next_frame_id_] = frame; | 155 frame_map_[next_frame_id_] = frame; |
148 | 156 |
149 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. | 157 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. |
150 next_frame_id_ = (next_frame_id_ + 1) & 0x3FFFFFFF; | 158 next_frame_id_ = (next_frame_id_ + 1) & 0x3FFFFFFF; |
151 } | 159 } |
152 | 160 |
153 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( | 161 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( |
154 const media::BitstreamBuffer& buffer) { | 162 const media::BitstreamBuffer& buffer) { |
155 DCHECK(CalledOnValidThread()); | 163 DCHECK(CalledOnValidThread()); |
156 if (!channel_) | 164 if (!channel_) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 weak_this_factory_.InvalidateWeakPtrs(); | 276 weak_this_factory_.InvalidateWeakPtrs(); |
269 | 277 |
270 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the | 278 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the |
271 // last thing done on this stack! | 279 // last thing done on this stack! |
272 media::VideoEncodeAccelerator::Client* client = NULL; | 280 media::VideoEncodeAccelerator::Client* client = NULL; |
273 std::swap(client_, client); | 281 std::swap(client_, client); |
274 client->NotifyError(error); | 282 client->NotifyError(error); |
275 } | 283 } |
276 | 284 |
277 } // namespace content | 285 } // namespace content |
OLD | NEW |