OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The bulk of this file is support code; sorry about that. Here's an overview | 5 // The bulk of this file is support code; sorry about that. Here's an overview |
6 // to hopefully help readers of this code: | 6 // to hopefully help readers of this code: |
7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or | 7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or |
8 // Win/EGL. | 8 // Win/EGL. |
9 // - ClientState is an enum for the state of the decode client used by the test. | 9 // - ClientState is an enum for the state of the decode client used by the test. |
10 // - ClientStateNotification is a barrier abstraction that allows the test code | 10 // - ClientStateNotification is a barrier abstraction that allows the test code |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 CS_RESET = 6, | 186 CS_RESET = 6, |
187 CS_ERROR = 7, | 187 CS_ERROR = 7, |
188 CS_DESTROYED = 8, | 188 CS_DESTROYED = 8, |
189 CS_MAX, // Must be last entry. | 189 CS_MAX, // Must be last entry. |
190 }; | 190 }; |
191 | 191 |
192 // Client that can accept callbacks from a VideoDecodeAccelerator and is used by | 192 // Client that can accept callbacks from a VideoDecodeAccelerator and is used by |
193 // the TESTs below. | 193 // the TESTs below. |
194 class GLRenderingVDAClient | 194 class GLRenderingVDAClient |
195 : public VideoDecodeAccelerator::Client, | 195 : public VideoDecodeAccelerator::Client, |
196 public RenderingHelper::Client, | |
197 public base::SupportsWeakPtr<GLRenderingVDAClient> { | 196 public base::SupportsWeakPtr<GLRenderingVDAClient> { |
198 public: | 197 public: |
| 198 // |window_id| the window_id of the client, which is used to identify the |
| 199 // rendering area in the |rendering_helper|. |
199 // Doesn't take ownership of |rendering_helper| or |note|, which must outlive | 200 // Doesn't take ownership of |rendering_helper| or |note|, which must outlive |
200 // |*this|. | 201 // |*this|. |
201 // |num_play_throughs| indicates how many times to play through the video. | 202 // |num_play_throughs| indicates how many times to play through the video. |
202 // |reset_after_frame_num| can be a frame number >=0 indicating a mid-stream | 203 // |reset_after_frame_num| can be a frame number >=0 indicating a mid-stream |
203 // Reset() should be done after that frame number is delivered, or | 204 // Reset() should be done after that frame number is delivered, or |
204 // END_OF_STREAM_RESET to indicate no mid-stream Reset(). | 205 // END_OF_STREAM_RESET to indicate no mid-stream Reset(). |
205 // |delete_decoder_state| indicates when the underlying decoder should be | 206 // |delete_decoder_state| indicates when the underlying decoder should be |
206 // Destroy()'d and deleted and can take values: N<0: delete after -N Decode() | 207 // Destroy()'d and deleted and can take values: N<0: delete after -N Decode() |
207 // calls have been made, N>=0 means interpret as ClientState. | 208 // calls have been made, N>=0 means interpret as ClientState. |
208 // Both |reset_after_frame_num| & |delete_decoder_state| apply only to the | 209 // Both |reset_after_frame_num| & |delete_decoder_state| apply only to the |
209 // last play-through (governed by |num_play_throughs|). | 210 // last play-through (governed by |num_play_throughs|). |
210 // |suppress_rendering| indicates GL rendering is supressed or not. | 211 // |suppress_rendering| indicates GL rendering is supressed or not. |
211 // After |delay_reuse_after_frame_num| frame has been delivered, the client | 212 // After |delay_reuse_after_frame_num| frame has been delivered, the client |
212 // will start delaying the call to ReusePictureBuffer() for kReuseDelay. | 213 // will start delaying the call to ReusePictureBuffer() for kReuseDelay. |
213 // |decode_calls_per_second| is the number of VDA::Decode calls per second. | 214 // |decode_calls_per_second| is the number of VDA::Decode calls per second. |
214 // If |decode_calls_per_second| > 0, |num_in_flight_decodes| must be 1. | 215 // If |decode_calls_per_second| > 0, |num_in_flight_decodes| must be 1. |
215 GLRenderingVDAClient(RenderingHelper* rendering_helper, | 216 GLRenderingVDAClient(size_t window_id, |
| 217 RenderingHelper* rendering_helper, |
216 ClientStateNotification<ClientState>* note, | 218 ClientStateNotification<ClientState>* note, |
217 const std::string& encoded_data, | 219 const std::string& encoded_data, |
218 int num_in_flight_decodes, | 220 int num_in_flight_decodes, |
219 int num_play_throughs, | 221 int num_play_throughs, |
220 int reset_after_frame_num, | 222 int reset_after_frame_num, |
221 int delete_decoder_state, | 223 int delete_decoder_state, |
222 int frame_width, | 224 int frame_width, |
223 int frame_height, | 225 int frame_height, |
224 media::VideoCodecProfile profile, | 226 media::VideoCodecProfile profile, |
225 bool suppress_rendering, | 227 bool suppress_rendering, |
226 int delay_reuse_after_frame_num, | 228 int delay_reuse_after_frame_num, |
227 int decode_calls_per_second, | 229 int decode_calls_per_second, |
228 bool render_as_thumbnails); | 230 bool render_as_thumbnails); |
229 virtual ~GLRenderingVDAClient(); | 231 virtual ~GLRenderingVDAClient(); |
230 void CreateAndStartDecoder(); | 232 void CreateAndStartDecoder(); |
231 | 233 |
232 // VideoDecodeAccelerator::Client implementation. | 234 // VideoDecodeAccelerator::Client implementation. |
233 // The heart of the Client. | 235 // The heart of the Client. |
234 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers, | 236 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers, |
235 const gfx::Size& dimensions, | 237 const gfx::Size& dimensions, |
236 uint32 texture_target) OVERRIDE; | 238 uint32 texture_target) OVERRIDE; |
237 virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE; | 239 virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE; |
238 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | 240 virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
239 // Simple state changes. | 241 // Simple state changes. |
240 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE; | 242 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE; |
241 virtual void NotifyFlushDone() OVERRIDE; | 243 virtual void NotifyFlushDone() OVERRIDE; |
242 virtual void NotifyResetDone() OVERRIDE; | 244 virtual void NotifyResetDone() OVERRIDE; |
243 virtual void NotifyError(VideoDecodeAccelerator::Error error) OVERRIDE; | 245 virtual void NotifyError(VideoDecodeAccelerator::Error error) OVERRIDE; |
244 | 246 |
245 // RenderingHelper::Client implementation. | |
246 virtual void RenderContent(RenderingHelper*) OVERRIDE; | |
247 virtual const gfx::Size& GetWindowSize() OVERRIDE; | |
248 | |
249 void OutputFrameDeliveryTimes(base::File* output); | 247 void OutputFrameDeliveryTimes(base::File* output); |
250 | 248 |
251 void NotifyFrameDropped(int32 picture_buffer_id); | |
252 | |
253 // Simple getters for inspecting the state of the Client. | 249 // Simple getters for inspecting the state of the Client. |
254 int num_done_bitstream_buffers() { return num_done_bitstream_buffers_; } | 250 int num_done_bitstream_buffers() { return num_done_bitstream_buffers_; } |
255 int num_skipped_fragments() { return num_skipped_fragments_; } | 251 int num_skipped_fragments() { return num_skipped_fragments_; } |
256 int num_queued_fragments() { return num_queued_fragments_; } | 252 int num_queued_fragments() { return num_queued_fragments_; } |
257 int num_decoded_frames() { return num_decoded_frames_; } | 253 int num_decoded_frames() { return num_decoded_frames_; } |
258 double frames_per_second(); | 254 double frames_per_second(); |
259 // Return the median of the decode time of all decoded frames. | 255 // Return the median of the decode time of all decoded frames. |
260 base::TimeDelta decode_time_median(); | 256 base::TimeDelta decode_time_median(); |
261 bool decoder_deleted() { return !decoder_.get(); } | 257 bool decoder_deleted() { return !decoder_.get(); } |
262 | 258 |
(...skipping 15 matching lines...) Expand all Loading... |
278 // (based on |start_pos|). | 274 // (based on |start_pos|). |
279 std::string GetBytesForNextFragment(size_t start_pos, size_t* end_pos); | 275 std::string GetBytesForNextFragment(size_t start_pos, size_t* end_pos); |
280 // Helpers for GetBytesForNextFragment above. | 276 // Helpers for GetBytesForNextFragment above. |
281 void GetBytesForNextNALU(size_t start_pos, size_t* end_pos); // For h.264. | 277 void GetBytesForNextNALU(size_t start_pos, size_t* end_pos); // For h.264. |
282 std::string GetBytesForNextFrame( | 278 std::string GetBytesForNextFrame( |
283 size_t start_pos, size_t* end_pos); // For VP8. | 279 size_t start_pos, size_t* end_pos); // For VP8. |
284 | 280 |
285 // Request decode of the next fragment in the encoded data. | 281 // Request decode of the next fragment in the encoded data. |
286 void DecodeNextFragment(); | 282 void DecodeNextFragment(); |
287 | 283 |
| 284 size_t window_id_; |
288 RenderingHelper* rendering_helper_; | 285 RenderingHelper* rendering_helper_; |
289 gfx::Size frame_size_; | 286 gfx::Size frame_size_; |
290 std::string encoded_data_; | 287 std::string encoded_data_; |
291 const int num_in_flight_decodes_; | 288 const int num_in_flight_decodes_; |
292 int outstanding_decodes_; | 289 int outstanding_decodes_; |
293 size_t encoded_data_next_pos_to_decode_; | 290 size_t encoded_data_next_pos_to_decode_; |
294 int next_bitstream_buffer_id_; | 291 int next_bitstream_buffer_id_; |
295 ClientStateNotification<ClientState>* note_; | 292 ClientStateNotification<ClientState>* note_; |
296 scoped_ptr<VideoDecodeAccelerator> decoder_; | 293 scoped_ptr<VideoDecodeAccelerator> decoder_; |
297 scoped_ptr<base::WeakPtrFactory<VideoDecodeAccelerator> > | 294 scoped_ptr<base::WeakPtrFactory<VideoDecodeAccelerator> > |
(...skipping 14 matching lines...) Expand all Loading... |
312 bool suppress_rendering_; | 309 bool suppress_rendering_; |
313 std::vector<base::TimeTicks> frame_delivery_times_; | 310 std::vector<base::TimeTicks> frame_delivery_times_; |
314 int delay_reuse_after_frame_num_; | 311 int delay_reuse_after_frame_num_; |
315 // A map from bitstream buffer id to the decode start time of the buffer. | 312 // A map from bitstream buffer id to the decode start time of the buffer. |
316 std::map<int, base::TimeTicks> decode_start_time_; | 313 std::map<int, base::TimeTicks> decode_start_time_; |
317 // The decode time of all decoded frames. | 314 // The decode time of all decoded frames. |
318 std::vector<base::TimeDelta> decode_time_; | 315 std::vector<base::TimeDelta> decode_time_; |
319 // The number of VDA::Decode calls per second. This is to simulate webrtc. | 316 // The number of VDA::Decode calls per second. This is to simulate webrtc. |
320 int decode_calls_per_second_; | 317 int decode_calls_per_second_; |
321 bool render_as_thumbnails_; | 318 bool render_as_thumbnails_; |
322 bool pending_picture_updated_; | |
323 std::deque<int32> pending_picture_buffer_ids_; | |
324 | 319 |
325 DISALLOW_IMPLICIT_CONSTRUCTORS(GLRenderingVDAClient); | 320 DISALLOW_IMPLICIT_CONSTRUCTORS(GLRenderingVDAClient); |
326 }; | 321 }; |
327 | 322 |
328 GLRenderingVDAClient::GLRenderingVDAClient( | 323 GLRenderingVDAClient::GLRenderingVDAClient( |
| 324 size_t window_id, |
329 RenderingHelper* rendering_helper, | 325 RenderingHelper* rendering_helper, |
330 ClientStateNotification<ClientState>* note, | 326 ClientStateNotification<ClientState>* note, |
331 const std::string& encoded_data, | 327 const std::string& encoded_data, |
332 int num_in_flight_decodes, | 328 int num_in_flight_decodes, |
333 int num_play_throughs, | 329 int num_play_throughs, |
334 int reset_after_frame_num, | 330 int reset_after_frame_num, |
335 int delete_decoder_state, | 331 int delete_decoder_state, |
336 int frame_width, | 332 int frame_width, |
337 int frame_height, | 333 int frame_height, |
338 media::VideoCodecProfile profile, | 334 media::VideoCodecProfile profile, |
339 bool suppress_rendering, | 335 bool suppress_rendering, |
340 int delay_reuse_after_frame_num, | 336 int delay_reuse_after_frame_num, |
341 int decode_calls_per_second, | 337 int decode_calls_per_second, |
342 bool render_as_thumbnails) | 338 bool render_as_thumbnails) |
343 : rendering_helper_(rendering_helper), | 339 : window_id_(window_id), |
| 340 rendering_helper_(rendering_helper), |
344 frame_size_(frame_width, frame_height), | 341 frame_size_(frame_width, frame_height), |
345 encoded_data_(encoded_data), | 342 encoded_data_(encoded_data), |
346 num_in_flight_decodes_(num_in_flight_decodes), | 343 num_in_flight_decodes_(num_in_flight_decodes), |
347 outstanding_decodes_(0), | 344 outstanding_decodes_(0), |
348 encoded_data_next_pos_to_decode_(0), | 345 encoded_data_next_pos_to_decode_(0), |
349 next_bitstream_buffer_id_(0), | 346 next_bitstream_buffer_id_(0), |
350 note_(note), | 347 note_(note), |
351 remaining_play_throughs_(num_play_throughs), | 348 remaining_play_throughs_(num_play_throughs), |
352 reset_after_frame_num_(reset_after_frame_num), | 349 reset_after_frame_num_(reset_after_frame_num), |
353 delete_decoder_state_(delete_decoder_state), | 350 delete_decoder_state_(delete_decoder_state), |
354 state_(CS_CREATED), | 351 state_(CS_CREATED), |
355 num_skipped_fragments_(0), | 352 num_skipped_fragments_(0), |
356 num_queued_fragments_(0), | 353 num_queued_fragments_(0), |
357 num_decoded_frames_(0), | 354 num_decoded_frames_(0), |
358 num_done_bitstream_buffers_(0), | 355 num_done_bitstream_buffers_(0), |
359 texture_target_(0), | 356 texture_target_(0), |
360 suppress_rendering_(suppress_rendering), | 357 suppress_rendering_(suppress_rendering), |
361 delay_reuse_after_frame_num_(delay_reuse_after_frame_num), | 358 delay_reuse_after_frame_num_(delay_reuse_after_frame_num), |
362 decode_calls_per_second_(decode_calls_per_second), | 359 decode_calls_per_second_(decode_calls_per_second), |
363 render_as_thumbnails_(render_as_thumbnails), | 360 render_as_thumbnails_(render_as_thumbnails) { |
364 pending_picture_updated_(true) { | |
365 CHECK_GT(num_in_flight_decodes, 0); | 361 CHECK_GT(num_in_flight_decodes, 0); |
366 CHECK_GT(num_play_throughs, 0); | 362 CHECK_GT(num_play_throughs, 0); |
367 // |num_in_flight_decodes_| is unsupported if |decode_calls_per_second_| > 0. | 363 // |num_in_flight_decodes_| is unsupported if |decode_calls_per_second_| > 0. |
368 if (decode_calls_per_second_ > 0) | 364 if (decode_calls_per_second_ > 0) |
369 CHECK_EQ(1, num_in_flight_decodes_); | 365 CHECK_EQ(1, num_in_flight_decodes_); |
370 | 366 |
371 // Default to H264 baseline if no profile provided. | 367 // Default to H264 baseline if no profile provided. |
372 profile_ = (profile != media::VIDEO_CODEC_PROFILE_UNKNOWN | 368 profile_ = (profile != media::VIDEO_CODEC_PROFILE_UNKNOWN |
373 ? profile | 369 ? profile |
374 : media::H264PROFILE_BASELINE); | 370 : media::H264PROFILE_BASELINE); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 void GLRenderingVDAClient::DismissPictureBuffer(int32 picture_buffer_id) { | 448 void GLRenderingVDAClient::DismissPictureBuffer(int32 picture_buffer_id) { |
453 PictureBufferById::iterator it = | 449 PictureBufferById::iterator it = |
454 picture_buffers_by_id_.find(picture_buffer_id); | 450 picture_buffers_by_id_.find(picture_buffer_id); |
455 CHECK(it != picture_buffers_by_id_.end()); | 451 CHECK(it != picture_buffers_by_id_.end()); |
456 CHECK_EQ(outstanding_texture_ids_.erase(it->second->texture_id()), 1U); | 452 CHECK_EQ(outstanding_texture_ids_.erase(it->second->texture_id()), 1U); |
457 rendering_helper_->DeleteTexture(it->second->texture_id()); | 453 rendering_helper_->DeleteTexture(it->second->texture_id()); |
458 delete it->second; | 454 delete it->second; |
459 picture_buffers_by_id_.erase(it); | 455 picture_buffers_by_id_.erase(it); |
460 } | 456 } |
461 | 457 |
462 void GLRenderingVDAClient::RenderContent(RenderingHelper*) { | |
463 CHECK(!render_as_thumbnails_); | |
464 | |
465 // No decoded texture for rendering yet, just skip. | |
466 if (pending_picture_buffer_ids_.size() == 0) | |
467 return; | |
468 | |
469 int32 buffer_id = pending_picture_buffer_ids_.front(); | |
470 media::PictureBuffer* picture_buffer = picture_buffers_by_id_[buffer_id]; | |
471 | |
472 CHECK(picture_buffer); | |
473 if (!pending_picture_updated_) { | |
474 // Frame dropped, just redraw the last texture. | |
475 rendering_helper_->RenderTexture(texture_target_, | |
476 picture_buffer->texture_id()); | |
477 return; | |
478 } | |
479 | |
480 base::TimeTicks now = base::TimeTicks::Now(); | |
481 frame_delivery_times_.push_back(now); | |
482 | |
483 rendering_helper_->RenderTexture(texture_target_, | |
484 picture_buffer->texture_id()); | |
485 | |
486 if (pending_picture_buffer_ids_.size() == 1) { | |
487 pending_picture_updated_ = false; | |
488 } else { | |
489 pending_picture_buffer_ids_.pop_front(); | |
490 ReturnPicture(buffer_id); | |
491 } | |
492 } | |
493 | |
494 const gfx::Size& GLRenderingVDAClient::GetWindowSize() { | |
495 return render_as_thumbnails_ ? kThumbnailsPageSize : frame_size_; | |
496 } | |
497 | |
498 void GLRenderingVDAClient::PictureReady(const media::Picture& picture) { | 458 void GLRenderingVDAClient::PictureReady(const media::Picture& picture) { |
499 // We shouldn't be getting pictures delivered after Reset has completed. | 459 // We shouldn't be getting pictures delivered after Reset has completed. |
500 CHECK_LT(state_, CS_RESET); | 460 CHECK_LT(state_, CS_RESET); |
501 | 461 |
502 if (decoder_deleted()) | 462 if (decoder_deleted()) |
503 return; | 463 return; |
504 | 464 |
505 base::TimeTicks now = base::TimeTicks::Now(); | 465 base::TimeTicks now = base::TimeTicks::Now(); |
| 466 |
| 467 frame_delivery_times_.push_back(now); |
| 468 |
506 // Save the decode time of this picture. | 469 // Save the decode time of this picture. |
507 std::map<int, base::TimeTicks>::iterator it = | 470 std::map<int, base::TimeTicks>::iterator it = |
508 decode_start_time_.find(picture.bitstream_buffer_id()); | 471 decode_start_time_.find(picture.bitstream_buffer_id()); |
509 ASSERT_NE(decode_start_time_.end(), it); | 472 ASSERT_NE(decode_start_time_.end(), it); |
510 decode_time_.push_back(now - it->second); | 473 decode_time_.push_back(now - it->second); |
511 decode_start_time_.erase(it); | 474 decode_start_time_.erase(it); |
512 | 475 |
513 CHECK_LE(picture.bitstream_buffer_id(), next_bitstream_buffer_id_); | 476 CHECK_LE(picture.bitstream_buffer_id(), next_bitstream_buffer_id_); |
514 ++num_decoded_frames_; | 477 ++num_decoded_frames_; |
515 | 478 |
516 // Mid-stream reset applies only to the last play-through per constructor | 479 // Mid-stream reset applies only to the last play-through per constructor |
517 // comment. | 480 // comment. |
518 if (remaining_play_throughs_ == 1 && | 481 if (remaining_play_throughs_ == 1 && |
519 reset_after_frame_num_ == num_decoded_frames_) { | 482 reset_after_frame_num_ == num_decoded_frames_) { |
520 reset_after_frame_num_ = MID_STREAM_RESET; | 483 reset_after_frame_num_ = MID_STREAM_RESET; |
521 decoder_->Reset(); | 484 decoder_->Reset(); |
522 // Re-start decoding from the beginning of the stream to avoid needing to | 485 // Re-start decoding from the beginning of the stream to avoid needing to |
523 // know how to find I-frames and so on in this test. | 486 // know how to find I-frames and so on in this test. |
524 encoded_data_next_pos_to_decode_ = 0; | 487 encoded_data_next_pos_to_decode_ = 0; |
525 } | 488 } |
526 | 489 |
| 490 media::PictureBuffer* picture_buffer = |
| 491 picture_buffers_by_id_[picture.picture_buffer_id()]; |
| 492 CHECK(picture_buffer); |
| 493 |
| 494 scoped_refptr<VideoFrameTexture> video_frame = |
| 495 new VideoFrameTexture(texture_target_, |
| 496 picture_buffer->texture_id(), |
| 497 base::Bind(&GLRenderingVDAClient::ReturnPicture, |
| 498 AsWeakPtr(), |
| 499 picture.picture_buffer_id())); |
| 500 |
527 if (render_as_thumbnails_) { | 501 if (render_as_thumbnails_) { |
528 frame_delivery_times_.push_back(now); | 502 rendering_helper_->RenderThumbnail(video_frame->texture_target(), |
529 media::PictureBuffer* picture_buffer = | 503 video_frame->texture_id()); |
530 picture_buffers_by_id_[picture.picture_buffer_id()]; | |
531 CHECK(picture_buffer); | |
532 rendering_helper_->RenderThumbnail(texture_target_, | |
533 picture_buffer->texture_id()); | |
534 ReturnPicture(picture.picture_buffer_id()); | |
535 } else if (!suppress_rendering_) { | 504 } else if (!suppress_rendering_) { |
536 // Keep the picture for rendering. | 505 rendering_helper_->QueueVideoFrame(window_id_, video_frame); |
537 pending_picture_buffer_ids_.push_back(picture.picture_buffer_id()); | |
538 if (pending_picture_buffer_ids_.size() > 1 && !pending_picture_updated_) { | |
539 ReturnPicture(pending_picture_buffer_ids_.front()); | |
540 pending_picture_buffer_ids_.pop_front(); | |
541 pending_picture_updated_ = true; | |
542 } | |
543 } else { | |
544 frame_delivery_times_.push_back(now); | |
545 ReturnPicture(picture.picture_buffer_id()); | |
546 } | 506 } |
547 } | 507 } |
548 | 508 |
549 void GLRenderingVDAClient::ReturnPicture(int32 picture_buffer_id) { | 509 void GLRenderingVDAClient::ReturnPicture(int32 picture_buffer_id) { |
550 if (decoder_deleted()) | 510 if (decoder_deleted()) |
551 return; | 511 return; |
552 if (num_decoded_frames_ > delay_reuse_after_frame_num_) { | 512 if (num_decoded_frames_ > delay_reuse_after_frame_num_) { |
553 base::MessageLoop::current()->PostDelayedTask( | 513 base::MessageLoop::current()->PostDelayedTask( |
554 FROM_HERE, | 514 FROM_HERE, |
555 base::Bind(&VideoDecodeAccelerator::ReusePictureBuffer, | 515 base::Bind(&VideoDecodeAccelerator::ReusePictureBuffer, |
(...skipping 27 matching lines...) Expand all Loading... |
583 if (decoder_deleted()) | 543 if (decoder_deleted()) |
584 return; | 544 return; |
585 decoder_->Reset(); | 545 decoder_->Reset(); |
586 SetState(CS_RESETTING); | 546 SetState(CS_RESETTING); |
587 } | 547 } |
588 | 548 |
589 void GLRenderingVDAClient::NotifyResetDone() { | 549 void GLRenderingVDAClient::NotifyResetDone() { |
590 if (decoder_deleted()) | 550 if (decoder_deleted()) |
591 return; | 551 return; |
592 | 552 |
593 // Clear pending_pictures and reuse them. | 553 rendering_helper_->DropPendingFrames(window_id_); |
594 while (!pending_picture_buffer_ids_.empty()) { | |
595 decoder_->ReusePictureBuffer(pending_picture_buffer_ids_.front()); | |
596 pending_picture_buffer_ids_.pop_front(); | |
597 } | |
598 pending_picture_updated_ = true; | |
599 | 554 |
600 if (reset_after_frame_num_ == MID_STREAM_RESET) { | 555 if (reset_after_frame_num_ == MID_STREAM_RESET) { |
601 reset_after_frame_num_ = END_OF_STREAM_RESET; | 556 reset_after_frame_num_ = END_OF_STREAM_RESET; |
602 DecodeNextFragment(); | 557 DecodeNextFragment(); |
603 return; | 558 return; |
604 } else if (reset_after_frame_num_ == START_OF_STREAM_RESET) { | 559 } else if (reset_after_frame_num_ == START_OF_STREAM_RESET) { |
605 reset_after_frame_num_ = END_OF_STREAM_RESET; | 560 reset_after_frame_num_ = END_OF_STREAM_RESET; |
606 for (int i = 0; i < num_in_flight_decodes_; ++i) | 561 for (int i = 0; i < num_in_flight_decodes_; ++i) |
607 DecodeNextFragment(); | 562 DecodeNextFragment(); |
608 return; | 563 return; |
(...skipping 21 matching lines...) Expand all Loading... |
630 base::TimeTicks t0 = initialize_done_ticks_; | 585 base::TimeTicks t0 = initialize_done_ticks_; |
631 for (size_t i = 0; i < frame_delivery_times_.size(); ++i) { | 586 for (size_t i = 0; i < frame_delivery_times_.size(); ++i) { |
632 s = base::StringPrintf("frame %04" PRIuS ": %" PRId64 " us\n", | 587 s = base::StringPrintf("frame %04" PRIuS ": %" PRId64 " us\n", |
633 i, | 588 i, |
634 (frame_delivery_times_[i] - t0).InMicroseconds()); | 589 (frame_delivery_times_[i] - t0).InMicroseconds()); |
635 t0 = frame_delivery_times_[i]; | 590 t0 = frame_delivery_times_[i]; |
636 output->WriteAtCurrentPos(s.data(), s.length()); | 591 output->WriteAtCurrentPos(s.data(), s.length()); |
637 } | 592 } |
638 } | 593 } |
639 | 594 |
640 void GLRenderingVDAClient::NotifyFrameDropped(int32 picture_buffer_id) { | |
641 decoder_->ReusePictureBuffer(picture_buffer_id); | |
642 } | |
643 | |
644 static bool LookingAtNAL(const std::string& encoded, size_t pos) { | 595 static bool LookingAtNAL(const std::string& encoded, size_t pos) { |
645 return encoded[pos] == 0 && encoded[pos + 1] == 0 && | 596 return encoded[pos] == 0 && encoded[pos + 1] == 0 && |
646 encoded[pos + 2] == 0 && encoded[pos + 3] == 1; | 597 encoded[pos + 2] == 0 && encoded[pos + 3] == 1; |
647 } | 598 } |
648 | 599 |
649 void GLRenderingVDAClient::SetState(ClientState new_state) { | 600 void GLRenderingVDAClient::SetState(ClientState new_state) { |
650 note_->Notify(new_state); | 601 note_->Notify(new_state); |
651 state_ = new_state; | 602 state_ = new_state; |
652 if (!remaining_play_throughs_ && new_state == delete_decoder_state_) { | 603 if (!remaining_play_throughs_ && new_state == delete_decoder_state_) { |
653 CHECK(!decoder_deleted()); | 604 CHECK(!decoder_deleted()); |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 new ClientStateNotification<ClientState>(); | 1071 new ClientStateNotification<ClientState>(); |
1121 notes[index] = note; | 1072 notes[index] = note; |
1122 | 1073 |
1123 int delay_after_frame_num = std::numeric_limits<int>::max(); | 1074 int delay_after_frame_num = std::numeric_limits<int>::max(); |
1124 if (test_reuse_delay && | 1075 if (test_reuse_delay && |
1125 kMaxFramesToDelayReuse * 2 < video_file->num_frames) { | 1076 kMaxFramesToDelayReuse * 2 < video_file->num_frames) { |
1126 delay_after_frame_num = video_file->num_frames - kMaxFramesToDelayReuse; | 1077 delay_after_frame_num = video_file->num_frames - kMaxFramesToDelayReuse; |
1127 } | 1078 } |
1128 | 1079 |
1129 GLRenderingVDAClient* client = | 1080 GLRenderingVDAClient* client = |
1130 new GLRenderingVDAClient(&rendering_helper_, | 1081 new GLRenderingVDAClient(index, |
| 1082 &rendering_helper_, |
1131 note, | 1083 note, |
1132 video_file->data_str, | 1084 video_file->data_str, |
1133 num_in_flight_decodes, | 1085 num_in_flight_decodes, |
1134 num_play_throughs, | 1086 num_play_throughs, |
1135 video_file->reset_after_frame_num, | 1087 video_file->reset_after_frame_num, |
1136 delete_decoder_state, | 1088 delete_decoder_state, |
1137 video_file->width, | 1089 video_file->width, |
1138 video_file->height, | 1090 video_file->height, |
1139 video_file->profile, | 1091 video_file->profile, |
1140 suppress_rendering, | 1092 suppress_rendering, |
1141 delay_after_frame_num, | 1093 delay_after_frame_num, |
1142 0, | 1094 0, |
1143 render_as_thumbnails); | 1095 render_as_thumbnails); |
1144 | 1096 |
1145 clients[index] = client; | 1097 clients[index] = client; |
1146 helper_params.clients.push_back(client->AsWeakPtr()); | 1098 helper_params.window_sizes.push_back( |
| 1099 render_as_thumbnails |
| 1100 ? kThumbnailsPageSize |
| 1101 : gfx::Size(video_file->width, video_file->height)); |
1147 } | 1102 } |
1148 | 1103 |
1149 InitializeRenderingHelper(helper_params); | 1104 InitializeRenderingHelper(helper_params); |
1150 | 1105 |
1151 for (size_t index = 0; index < num_concurrent_decoders; ++index) { | 1106 for (size_t index = 0; index < num_concurrent_decoders; ++index) { |
1152 CreateAndStartDecoder(clients[index], notes[index]); | 1107 CreateAndStartDecoder(clients[index], notes[index]); |
1153 } | 1108 } |
1154 | 1109 |
1155 // Then wait for all the decodes to finish. | 1110 // Then wait for all the decodes to finish. |
1156 // Only check performance & correctness later if we play through only once. | 1111 // Only check performance & correctness later if we play through only once. |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 TEST_F(VideoDecodeAcceleratorTest, TestDecodeTimeMedian) { | 1324 TEST_F(VideoDecodeAcceleratorTest, TestDecodeTimeMedian) { |
1370 RenderingHelperParams helper_params; | 1325 RenderingHelperParams helper_params; |
1371 | 1326 |
1372 // Disable rendering by setting the rendering_fps = 0. | 1327 // Disable rendering by setting the rendering_fps = 0. |
1373 helper_params.rendering_fps = 0; | 1328 helper_params.rendering_fps = 0; |
1374 helper_params.render_as_thumbnails = false; | 1329 helper_params.render_as_thumbnails = false; |
1375 | 1330 |
1376 ClientStateNotification<ClientState>* note = | 1331 ClientStateNotification<ClientState>* note = |
1377 new ClientStateNotification<ClientState>(); | 1332 new ClientStateNotification<ClientState>(); |
1378 GLRenderingVDAClient* client = | 1333 GLRenderingVDAClient* client = |
1379 new GLRenderingVDAClient(&rendering_helper_, | 1334 new GLRenderingVDAClient(0, |
| 1335 &rendering_helper_, |
1380 note, | 1336 note, |
1381 test_video_files_[0]->data_str, | 1337 test_video_files_[0]->data_str, |
1382 1, | 1338 1, |
1383 1, | 1339 1, |
1384 test_video_files_[0]->reset_after_frame_num, | 1340 test_video_files_[0]->reset_after_frame_num, |
1385 CS_RESET, | 1341 CS_RESET, |
1386 test_video_files_[0]->width, | 1342 test_video_files_[0]->width, |
1387 test_video_files_[0]->height, | 1343 test_video_files_[0]->height, |
1388 test_video_files_[0]->profile, | 1344 test_video_files_[0]->profile, |
1389 true, | 1345 true, |
1390 std::numeric_limits<int>::max(), | 1346 std::numeric_limits<int>::max(), |
1391 kWebRtcDecodeCallsPerSecond, | 1347 kWebRtcDecodeCallsPerSecond, |
1392 false /* render_as_thumbnail */); | 1348 false /* render_as_thumbnail */); |
1393 helper_params.clients.push_back(client->AsWeakPtr()); | 1349 helper_params.window_sizes.push_back( |
| 1350 gfx::Size(test_video_files_[0]->width, test_video_files_[0]->height)); |
1394 InitializeRenderingHelper(helper_params); | 1351 InitializeRenderingHelper(helper_params); |
1395 CreateAndStartDecoder(client, note); | 1352 CreateAndStartDecoder(client, note); |
1396 WaitUntilDecodeFinish(note); | 1353 WaitUntilDecodeFinish(note); |
1397 | 1354 |
1398 base::TimeDelta decode_time_median = client->decode_time_median(); | 1355 base::TimeDelta decode_time_median = client->decode_time_median(); |
1399 std::string output_string = | 1356 std::string output_string = |
1400 base::StringPrintf("Decode time median: %" PRId64 " us", | 1357 base::StringPrintf("Decode time median: %" PRId64 " us", |
1401 decode_time_median.InMicroseconds()); | 1358 decode_time_median.InMicroseconds()); |
1402 LOG(INFO) << output_string; | 1359 LOG(INFO) << output_string; |
1403 | 1360 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 if (it->first == "v" || it->first == "vmodule") | 1414 if (it->first == "v" || it->first == "vmodule") |
1458 continue; | 1415 continue; |
1459 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1416 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1460 } | 1417 } |
1461 | 1418 |
1462 base::ShadowingAtExitManager at_exit_manager; | 1419 base::ShadowingAtExitManager at_exit_manager; |
1463 content::RenderingHelper::InitializeOneOff(); | 1420 content::RenderingHelper::InitializeOneOff(); |
1464 | 1421 |
1465 return RUN_ALL_TESTS(); | 1422 return RUN_ALL_TESTS(); |
1466 } | 1423 } |
OLD | NEW |