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 memory_handle; | 129 base::SharedMemoryHandle memory_handle; |
131 size_t memory_size = 0; | 130 size_t memory_size = 0; |
132 bool read_only_flag = false; | 131 bool read_only_flag = false; |
133 const MojoResult result = mojo::UnwrapSharedMemoryHandle( | 132 const MojoResult result = mojo::UnwrapSharedMemoryHandle( |
134 out_buffer.handle_provider->GetHandleForInterProcessTransit(), | 133 out_buffer.handle_provider->GetHandleForInterProcessTransit(), |
135 &memory_handle, &memory_size, &read_only_flag); | 134 &memory_handle, &memory_size, &read_only_flag); |
136 DCHECK_EQ(MOJO_RESULT_OK, result); | 135 DCHECK_EQ(MOJO_RESULT_OK, result); |
(...skipping 14 matching lines...) Expand all Loading... |
151 decoder_status_ = FAILED; | 150 decoder_status_ = FAILED; |
152 LOG(ERROR) << "DecodeCapturedData: WrapExternalSharedMemory failed"; | 151 LOG(ERROR) << "DecodeCapturedData: WrapExternalSharedMemory failed"; |
153 return; | 152 return; |
154 } | 153 } |
155 out_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, | 154 out_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, |
156 frame_format.frame_rate); | 155 frame_format.frame_rate); |
157 | 156 |
158 out_frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, | 157 out_frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, |
159 reference_time); | 158 reference_time); |
160 | 159 |
| 160 media::mojom::VideoFrameInfoPtr out_frame_info = |
| 161 media::mojom::VideoFrameInfo::New(); |
| 162 out_frame_info->timestamp = timestamp; |
| 163 out_frame_info->pixel_format = media::PIXEL_FORMAT_I420; |
| 164 out_frame_info->storage_type = media::PIXEL_STORAGE_CPU; |
| 165 out_frame_info->coded_size = dimensions; |
| 166 out_frame_info->visible_rect = gfx::Rect(dimensions); |
| 167 auto metadata_values = out_frame->metadata()->CopyInternalValues(); |
| 168 out_frame_info->metadata->MergeDictionary(metadata_values.get()); |
| 169 |
161 { | 170 { |
162 base::AutoLock lock(lock_); | 171 base::AutoLock lock(lock_); |
163 decode_done_closure_ = | 172 decode_done_closure_ = base::Bind( |
164 base::Bind(decode_done_cb_, base::Passed(&out_buffer), out_frame); | 173 decode_done_cb_, out_buffer.id(), out_buffer.frame_feedback_id(), |
| 174 base::Passed(&out_buffer.buffer_read_write_permission), |
| 175 base::Passed(&out_frame_info)); |
165 } | 176 } |
166 decoder_->Decode(in_buffer, std::move(out_frame)); | 177 decoder_->Decode(in_buffer, std::move(out_frame)); |
167 } | 178 } |
168 | 179 |
169 void VideoCaptureGpuJpegDecoder::VideoFrameReady(int32_t bitstream_buffer_id) { | 180 void VideoCaptureGpuJpegDecoder::VideoFrameReady(int32_t bitstream_buffer_id) { |
170 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 181 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
171 TRACE_EVENT0("jpeg", "VideoCaptureGpuJpegDecoder::VideoFrameReady"); | 182 TRACE_EVENT0("jpeg", "VideoCaptureGpuJpegDecoder::VideoFrameReady"); |
172 base::AutoLock lock(lock_); | 183 base::AutoLock lock(lock_); |
173 | 184 |
174 if (!IsDecoding_Locked()) { | 185 if (!IsDecoding_Locked()) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 lock_.AssertAcquired(); | 269 lock_.AssertAcquired(); |
259 return !decode_done_closure_.is_null(); | 270 return !decode_done_closure_.is_null(); |
260 } | 271 } |
261 | 272 |
262 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { | 273 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { |
263 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", | 274 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", |
264 decoder_status_ == INIT_PASSED); | 275 decoder_status_ == INIT_PASSED); |
265 } | 276 } |
266 | 277 |
267 } // namespace content | 278 } // namespace content |
OLD | NEW |