OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" | 5 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 memcpy(in_shared_memory_->memory(), data, in_buffer_size); | 116 memcpy(in_shared_memory_->memory(), data, in_buffer_size); |
117 | 117 |
118 // No need to lock for |in_buffer_id_| since IsDecoding_Locked() is false. | 118 // No need to lock for |in_buffer_id_| since IsDecoding_Locked() is false. |
119 in_buffer_id_ = next_bitstream_buffer_id_; | 119 in_buffer_id_ = next_bitstream_buffer_id_; |
120 media::BitstreamBuffer in_buffer(in_buffer_id_, in_shared_memory_->handle(), | 120 media::BitstreamBuffer in_buffer(in_buffer_id_, in_shared_memory_->handle(), |
121 in_buffer_size); | 121 in_buffer_size); |
122 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. | 122 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. |
123 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; | 123 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; |
124 | 124 |
125 // The APIs of |decoder_| and |decode_done_cb_| require us to wrap the | 125 // The API of |decoder_| requires us to wrap the |out_buffer| in a VideoFrame. |
126 // |out_buffer| in a VideoFrame. | |
127 const gfx::Size dimensions = frame_format.frame_size; | 126 const gfx::Size dimensions = frame_format.frame_size; |
128 std::unique_ptr<media::VideoCaptureBufferHandle> out_buffer_access = | 127 std::unique_ptr<media::VideoCaptureBufferHandle> out_buffer_access = |
129 out_buffer.handle_provider()->GetHandleForInProcessAccess(); | 128 out_buffer.handle_provider->GetHandleForInProcessAccess(); |
130 base::SharedMemoryHandle out_handle = | 129 base::SharedMemoryHandle out_handle = |
131 out_buffer.handle_provider()->GetNonOwnedSharedMemoryHandleForLegacyIPC(); | 130 out_buffer.handle_provider->GetNonOwnedSharedMemoryHandleForLegacyIPC(); |
132 scoped_refptr<media::VideoFrame> out_frame = | 131 scoped_refptr<media::VideoFrame> out_frame = |
133 media::VideoFrame::WrapExternalSharedMemory( | 132 media::VideoFrame::WrapExternalSharedMemory( |
134 media::PIXEL_FORMAT_I420, // format | 133 media::PIXEL_FORMAT_I420, // format |
135 dimensions, // coded_size | 134 dimensions, // coded_size |
136 gfx::Rect(dimensions), // visible_rect | 135 gfx::Rect(dimensions), // visible_rect |
137 dimensions, // natural_size | 136 dimensions, // natural_size |
138 out_buffer_access->data(), // data | 137 out_buffer_access->data(), // data |
139 out_buffer_access->mapped_size(), // data_size | 138 out_buffer_access->mapped_size(), // data_size |
140 out_handle, // handle | 139 out_handle, // handle |
141 0, // shared_memory_offset | 140 0, // shared_memory_offset |
142 timestamp); // timestamp | 141 timestamp); // timestamp |
143 if (!out_frame) { | 142 if (!out_frame) { |
144 base::AutoLock lock(lock_); | 143 base::AutoLock lock(lock_); |
145 decoder_status_ = FAILED; | 144 decoder_status_ = FAILED; |
146 LOG(ERROR) << "DecodeCapturedData: WrapExternalSharedMemory failed"; | 145 LOG(ERROR) << "DecodeCapturedData: WrapExternalSharedMemory failed"; |
147 return; | 146 return; |
148 } | 147 } |
149 out_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, | 148 out_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, |
150 frame_format.frame_rate); | 149 frame_format.frame_rate); |
151 | 150 |
152 out_frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, | 151 out_frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, |
153 reference_time); | 152 reference_time); |
154 | 153 |
| 154 media::mojom::VideoFrameInfoPtr out_frame_info = |
| 155 media::mojom::VideoFrameInfo::New(); |
| 156 out_frame_info->timestamp = timestamp; |
| 157 out_frame_info->pixel_format = media::PIXEL_FORMAT_I420; |
| 158 out_frame_info->storage_type = media::PIXEL_STORAGE_CPU; |
| 159 out_frame_info->coded_size = dimensions; |
| 160 out_frame_info->visible_rect = gfx::Rect(dimensions); |
| 161 out_frame_info->metadata = out_frame->metadata()->CopyInternalValues(); |
| 162 |
155 { | 163 { |
156 base::AutoLock lock(lock_); | 164 base::AutoLock lock(lock_); |
157 decode_done_closure_ = | 165 decode_done_closure_ = |
158 base::Bind(decode_done_cb_, base::Passed(&out_buffer), out_frame); | 166 base::Bind(decode_done_cb_, out_buffer.id, out_buffer.frame_feedback_id, |
| 167 base::Passed(&out_buffer.access_permission), |
| 168 base::Passed(&out_frame_info)); |
159 } | 169 } |
160 decoder_->Decode(in_buffer, std::move(out_frame)); | 170 decoder_->Decode(in_buffer, std::move(out_frame)); |
161 } | 171 } |
162 | 172 |
163 void VideoCaptureGpuJpegDecoder::VideoFrameReady(int32_t bitstream_buffer_id) { | 173 void VideoCaptureGpuJpegDecoder::VideoFrameReady(int32_t bitstream_buffer_id) { |
164 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 174 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
165 TRACE_EVENT0("jpeg", "VideoCaptureGpuJpegDecoder::VideoFrameReady"); | 175 TRACE_EVENT0("jpeg", "VideoCaptureGpuJpegDecoder::VideoFrameReady"); |
166 base::AutoLock lock(lock_); | 176 base::AutoLock lock(lock_); |
167 | 177 |
168 if (!IsDecoding_Locked()) { | 178 if (!IsDecoding_Locked()) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 lock_.AssertAcquired(); | 262 lock_.AssertAcquired(); |
253 return !decode_done_closure_.is_null(); | 263 return !decode_done_closure_.is_null(); |
254 } | 264 } |
255 | 265 |
256 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { | 266 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { |
257 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", | 267 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", |
258 decoder_status_ == INIT_PASSED); | 268 decoder_status_ == INIT_PASSED); |
259 } | 269 } |
260 | 270 |
261 } // namespace content | 271 } // namespace content |
OLD | NEW |