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 "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "content/common/gpu/client/gpu_channel_host.h" | 9 #include "content/common/gpu/client/gpu_channel_host.h" |
10 #include "content/common/gpu/gpu_messages.h" | 10 #include "content/common/gpu/gpu_messages.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 << ", input_coded_size=" << input_coded_size.ToString() | 170 << ", input_coded_size=" << input_coded_size.ToString() |
171 << ", output_buffer_size=" << output_buffer_size; | 171 << ", output_buffer_size=" << output_buffer_size; |
172 if (client_) { | 172 if (client_) { |
173 client_->RequireBitstreamBuffers( | 173 client_->RequireBitstreamBuffers( |
174 input_count, input_coded_size, output_buffer_size); | 174 input_count, input_coded_size, output_buffer_size); |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 void GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(int32 frame_id) { | 178 void GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(int32 frame_id) { |
179 DVLOG(3) << "OnNotifyInputDone(): frame_id=" << frame_id; | 179 DVLOG(3) << "OnNotifyInputDone(): frame_id=" << frame_id; |
| 180 // Fun-fact: std::hash_map is not spec'd to be re-entrant; since freeing a |
| 181 // frame can trigger a further encode to be kicked off and thus an .insert() |
| 182 // back into the map, we separate the frame's dtor running from the .erase() |
| 183 // running by holding on to the frame temporarily. This isn't "just |
| 184 // theoretical" - Android's std::hash_map crashes if we don't do this. |
| 185 scoped_refptr<media::VideoFrame> frame = frame_map_[frame_id]; |
180 if (!frame_map_.erase(frame_id)) { | 186 if (!frame_map_.erase(frame_id)) { |
181 DLOG(ERROR) << "OnNotifyInputDone(): " | 187 DLOG(ERROR) << "OnNotifyInputDone(): " |
182 "invalid frame_id=" << frame_id; | 188 "invalid frame_id=" << frame_id; |
183 // See OnNotifyError for why this needs to be the last thing in this | 189 // See OnNotifyError for why this needs to be the last thing in this |
184 // function. | 190 // function. |
185 OnNotifyError(kPlatformFailureError); | 191 OnNotifyError(kPlatformFailureError); |
186 return; | 192 return; |
187 } | 193 } |
| 194 frame = NULL; // Not necessary but nice to be explicit; see fun-fact above. |
188 } | 195 } |
189 | 196 |
190 void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady( | 197 void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady( |
191 int32 bitstream_buffer_id, | 198 int32 bitstream_buffer_id, |
192 uint32 payload_size, | 199 uint32 payload_size, |
193 bool key_frame) { | 200 bool key_frame) { |
194 DVLOG(3) << "OnBitstreamBufferReady(): " | 201 DVLOG(3) << "OnBitstreamBufferReady(): " |
195 "bitstream_buffer_id=" << bitstream_buffer_id | 202 "bitstream_buffer_id=" << bitstream_buffer_id |
196 << ", payload_size=" << payload_size | 203 << ", payload_size=" << payload_size |
197 << ", key_frame=" << key_frame; | 204 << ", key_frame=" << key_frame; |
(...skipping 20 matching lines...) Expand all Loading... |
218 delete message; | 225 delete message; |
219 NotifyError(kPlatformFailureError); | 226 NotifyError(kPlatformFailureError); |
220 } else if (!channel_->Send(message)) { | 227 } else if (!channel_->Send(message)) { |
221 DLOG(ERROR) << "Send(): sending failed: message->type()=" | 228 DLOG(ERROR) << "Send(): sending failed: message->type()=" |
222 << message->type(); | 229 << message->type(); |
223 NotifyError(kPlatformFailureError); | 230 NotifyError(kPlatformFailureError); |
224 } | 231 } |
225 } | 232 } |
226 | 233 |
227 } // namespace content | 234 } // namespace content |
OLD | NEW |