| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/media/vaapi_video_encode_accelerator.h" | 5 #include "media/gpu/vaapi_video_encode_accelerator.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/numerics/safe_conversions.h" | 16 #include "base/numerics/safe_conversions.h" |
| 17 #include "content/common/gpu/media/h264_dpb.h" | |
| 18 #include "content/common/gpu/media/shared_memory_region.h" | |
| 19 #include "media/base/bind_to_current_loop.h" | 17 #include "media/base/bind_to_current_loop.h" |
| 18 #include "media/gpu/h264_dpb.h" |
| 19 #include "media/gpu/shared_memory_region.h" |
| 20 #include "third_party/libva/va/va_enc_h264.h" | 20 #include "third_party/libva/va/va_enc_h264.h" |
| 21 | 21 |
| 22 #define DVLOGF(level) DVLOG(level) << __FUNCTION__ << "(): " | 22 #define DVLOGF(level) DVLOG(level) << __FUNCTION__ << "(): " |
| 23 | 23 |
| 24 #define NOTIFY_ERROR(error, msg) \ | 24 #define NOTIFY_ERROR(error, msg) \ |
| 25 do { \ | 25 do { \ |
| 26 SetState(kError); \ | 26 SetState(kError); \ |
| 27 LOG(ERROR) << msg; \ | 27 LOG(ERROR) << msg; \ |
| 28 LOG(ERROR) << "Calling NotifyError(" << error << ")";\ | 28 LOG(ERROR) << "Calling NotifyError(" << error << ")"; \ |
| 29 NotifyError(error); \ | 29 NotifyError(error); \ |
| 30 } while (0) | 30 } while (0) |
| 31 | 31 |
| 32 namespace content { | 32 namespace media { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 // Need 2 surfaces for each frame: one for input data and one for | 35 // Need 2 surfaces for each frame: one for input data and one for |
| 36 // reconstructed picture, which is later used for reference. | 36 // reconstructed picture, which is later used for reference. |
| 37 const size_t kMinSurfacesToEncode = 2; | 37 const size_t kMinSurfacesToEncode = 2; |
| 38 | 38 |
| 39 // Subjectively chosen. | 39 // Subjectively chosen. |
| 40 const size_t kNumInputBuffers = 4; | 40 const size_t kNumInputBuffers = 4; |
| 41 const size_t kMaxNumReferenceFrames = 4; | 41 const size_t kMaxNumReferenceFrames = 4; |
| 42 | 42 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 67 // All Intel codecs can do at least 4.1. | 67 // All Intel codecs can do at least 4.1. |
| 68 const int kDefaultLevelIDC = 41; | 68 const int kDefaultLevelIDC = 41; |
| 69 const int kChromaFormatIDC = 1; // 4:2:0 | 69 const int kChromaFormatIDC = 1; // 4:2:0 |
| 70 | 70 |
| 71 // Arbitrarily chosen bitrate window size for rate control, in ms. | 71 // Arbitrarily chosen bitrate window size for rate control, in ms. |
| 72 const int kCPBWindowSizeMs = 1500; | 72 const int kCPBWindowSizeMs = 1500; |
| 73 | 73 |
| 74 // UMA errors that the VaapiVideoEncodeAccelerator class reports. | 74 // UMA errors that the VaapiVideoEncodeAccelerator class reports. |
| 75 enum VAVEAEncoderFailure { | 75 enum VAVEAEncoderFailure { |
| 76 VAAPI_ERROR = 0, | 76 VAAPI_ERROR = 0, |
| 77 // UMA requires that max must be greater than 1. | 77 VAVEA_ENCODER_FAILURES_MAX, |
| 78 VAVEA_ENCODER_FAILURES_MAX = 2, | |
| 79 }; | 78 }; |
| 80 | |
| 81 } | 79 } |
| 82 | 80 |
| 83 // Round |value| up to |alignment|, which must be a power of 2. | 81 // Round |value| up to |alignment|, which must be a power of 2. |
| 84 static inline size_t RoundUpToPowerOf2(size_t value, size_t alignment) { | 82 static inline size_t RoundUpToPowerOf2(size_t value, size_t alignment) { |
| 85 // Check that |alignment| is a power of 2. | 83 // Check that |alignment| is a power of 2. |
| 86 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); | 84 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); |
| 87 return ((value + (alignment - 1)) & ~(alignment - 1)); | 85 return ((value + (alignment - 1)) & ~(alignment - 1)); |
| 88 } | 86 } |
| 89 | 87 |
| 90 static void ReportToUMA(VAVEAEncoderFailure failure) { | 88 static void ReportToUMA(VAVEAEncoderFailure failure) { |
| 91 UMA_HISTOGRAM_ENUMERATION( | 89 UMA_HISTOGRAM_ENUMERATION("Media.VAVEA.EncoderFailure", failure, |
| 92 "Media.VAVEA.EncoderFailure", | 90 VAVEA_ENCODER_FAILURES_MAX + 1); |
| 93 failure, | |
| 94 VAVEA_ENCODER_FAILURES_MAX); | |
| 95 } | 91 } |
| 96 | 92 |
| 97 struct VaapiVideoEncodeAccelerator::InputFrameRef { | 93 struct VaapiVideoEncodeAccelerator::InputFrameRef { |
| 98 InputFrameRef(const scoped_refptr<media::VideoFrame>& frame, | 94 InputFrameRef(const scoped_refptr<media::VideoFrame>& frame, |
| 99 bool force_keyframe) | 95 bool force_keyframe) |
| 100 : frame(frame), force_keyframe(force_keyframe) {} | 96 : frame(frame), force_keyframe(force_keyframe) {} |
| 101 const scoped_refptr<media::VideoFrame> frame; | 97 const scoped_refptr<media::VideoFrame> frame; |
| 102 const bool force_keyframe; | 98 const bool force_keyframe; |
| 103 }; | 99 }; |
| 104 | 100 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 << media::VideoPixelFormatToString(format) | 167 << media::VideoPixelFormatToString(format) |
| 172 << ", input_visible_size: " << input_visible_size.ToString() | 168 << ", input_visible_size: " << input_visible_size.ToString() |
| 173 << ", output_profile: " << output_profile | 169 << ", output_profile: " << output_profile |
| 174 << ", initial_bitrate: " << initial_bitrate; | 170 << ", initial_bitrate: " << initial_bitrate; |
| 175 | 171 |
| 176 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 172 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
| 177 client_ = client_ptr_factory_->GetWeakPtr(); | 173 client_ = client_ptr_factory_->GetWeakPtr(); |
| 178 | 174 |
| 179 const SupportedProfiles& profiles = GetSupportedProfiles(); | 175 const SupportedProfiles& profiles = GetSupportedProfiles(); |
| 180 auto profile = find_if(profiles.begin(), profiles.end(), | 176 auto profile = find_if(profiles.begin(), profiles.end(), |
| 181 [output_profile](const SupportedProfile& profile) { | 177 [output_profile](const SupportedProfile& profile) { |
| 182 return profile.profile == output_profile; | 178 return profile.profile == output_profile; |
| 183 }); | 179 }); |
| 184 if (profile == profiles.end()) { | 180 if (profile == profiles.end()) { |
| 185 DVLOGF(1) << "Unsupported output profile " << output_profile; | 181 DVLOGF(1) << "Unsupported output profile " << output_profile; |
| 186 return false; | 182 return false; |
| 187 } | 183 } |
| 188 if (input_visible_size.width() > profile->max_resolution.width() || | 184 if (input_visible_size.width() > profile->max_resolution.width() || |
| 189 input_visible_size.height() > profile->max_resolution.height()) { | 185 input_visible_size.height() > profile->max_resolution.height()) { |
| 190 DVLOGF(1) << "Input size too big: " << input_visible_size.ToString() | 186 DVLOGF(1) << "Input size too big: " << input_visible_size.ToString() |
| 191 << ", max supported size: " << profile->max_resolution.ToString(); | 187 << ", max supported size: " << profile->max_resolution.ToString(); |
| 192 return false; | 188 return false; |
| 193 } | 189 } |
| 194 | 190 |
| 195 if (format != media::PIXEL_FORMAT_I420) { | 191 if (format != media::PIXEL_FORMAT_I420) { |
| 196 DVLOGF(1) << "Unsupported input format: " | 192 DVLOGF(1) << "Unsupported input format: " |
| 197 << media::VideoPixelFormatToString(format); | 193 << media::VideoPixelFormatToString(format); |
| 198 return false; | 194 return false; |
| 199 } | 195 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 364 |
| 369 SPS_TO_SP(vui_parameters_present_flag); | 365 SPS_TO_SP(vui_parameters_present_flag); |
| 370 #define SPS_TO_SP_VF(a) seq_param.vui_fields.bits.a = current_sps_.a; | 366 #define SPS_TO_SP_VF(a) seq_param.vui_fields.bits.a = current_sps_.a; |
| 371 SPS_TO_SP_VF(timing_info_present_flag); | 367 SPS_TO_SP_VF(timing_info_present_flag); |
| 372 #undef SPS_TO_SP_VF | 368 #undef SPS_TO_SP_VF |
| 373 SPS_TO_SP(num_units_in_tick); | 369 SPS_TO_SP(num_units_in_tick); |
| 374 SPS_TO_SP(time_scale); | 370 SPS_TO_SP(time_scale); |
| 375 #undef SPS_TO_SP | 371 #undef SPS_TO_SP |
| 376 | 372 |
| 377 if (!vaapi_wrapper_->SubmitBuffer(VAEncSequenceParameterBufferType, | 373 if (!vaapi_wrapper_->SubmitBuffer(VAEncSequenceParameterBufferType, |
| 378 sizeof(seq_param), | 374 sizeof(seq_param), &seq_param)) |
| 379 &seq_param)) | |
| 380 return false; | 375 return false; |
| 381 | 376 |
| 382 VAEncPictureParameterBufferH264 pic_param; | 377 VAEncPictureParameterBufferH264 pic_param; |
| 383 memset(&pic_param, 0, sizeof(pic_param)); | 378 memset(&pic_param, 0, sizeof(pic_param)); |
| 384 | 379 |
| 385 pic_param.CurrPic.picture_id = current_encode_job_->recon_surface->id(); | 380 pic_param.CurrPic.picture_id = current_encode_job_->recon_surface->id(); |
| 386 pic_param.CurrPic.TopFieldOrderCnt = current_pic_->top_field_order_cnt; | 381 pic_param.CurrPic.TopFieldOrderCnt = current_pic_->top_field_order_cnt; |
| 387 pic_param.CurrPic.BottomFieldOrderCnt = current_pic_->bottom_field_order_cnt; | 382 pic_param.CurrPic.BottomFieldOrderCnt = current_pic_->bottom_field_order_cnt; |
| 388 pic_param.CurrPic.flags = 0; | 383 pic_param.CurrPic.flags = 0; |
| 389 | 384 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 407 pic_param.num_ref_idx_l0_active_minus1 = max_ref_idx_l0_size_ - 1; | 402 pic_param.num_ref_idx_l0_active_minus1 = max_ref_idx_l0_size_ - 1; |
| 408 pic_param.pic_fields.bits.idr_pic_flag = current_pic_->idr; | 403 pic_param.pic_fields.bits.idr_pic_flag = current_pic_->idr; |
| 409 pic_param.pic_fields.bits.reference_pic_flag = current_pic_->ref; | 404 pic_param.pic_fields.bits.reference_pic_flag = current_pic_->ref; |
| 410 #define PPS_TO_PP_PF(a) pic_param.pic_fields.bits.a = current_pps_.a; | 405 #define PPS_TO_PP_PF(a) pic_param.pic_fields.bits.a = current_pps_.a; |
| 411 PPS_TO_PP_PF(entropy_coding_mode_flag); | 406 PPS_TO_PP_PF(entropy_coding_mode_flag); |
| 412 PPS_TO_PP_PF(transform_8x8_mode_flag); | 407 PPS_TO_PP_PF(transform_8x8_mode_flag); |
| 413 PPS_TO_PP_PF(deblocking_filter_control_present_flag); | 408 PPS_TO_PP_PF(deblocking_filter_control_present_flag); |
| 414 #undef PPS_TO_PP_PF | 409 #undef PPS_TO_PP_PF |
| 415 | 410 |
| 416 if (!vaapi_wrapper_->SubmitBuffer(VAEncPictureParameterBufferType, | 411 if (!vaapi_wrapper_->SubmitBuffer(VAEncPictureParameterBufferType, |
| 417 sizeof(pic_param), | 412 sizeof(pic_param), &pic_param)) |
| 418 &pic_param)) | |
| 419 return false; | 413 return false; |
| 420 | 414 |
| 421 VAEncSliceParameterBufferH264 slice_param; | 415 VAEncSliceParameterBufferH264 slice_param; |
| 422 memset(&slice_param, 0, sizeof(slice_param)); | 416 memset(&slice_param, 0, sizeof(slice_param)); |
| 423 | 417 |
| 424 slice_param.num_macroblocks = mb_width_ * mb_height_; | 418 slice_param.num_macroblocks = mb_width_ * mb_height_; |
| 425 slice_param.macroblock_info = VA_INVALID_ID; | 419 slice_param.macroblock_info = VA_INVALID_ID; |
| 426 slice_param.slice_type = current_pic_->type; | 420 slice_param.slice_type = current_pic_->type; |
| 427 slice_param.pic_parameter_set_id = current_pps_.pic_parameter_set_id; | 421 slice_param.pic_parameter_set_id = current_pps_.pic_parameter_set_id; |
| 428 slice_param.idr_pic_id = idr_pic_id_; | 422 slice_param.idr_pic_id = idr_pic_id_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 439 iter = ref_pic_list0_.begin(); | 433 iter = ref_pic_list0_.begin(); |
| 440 for (size_t i = 0; | 434 for (size_t i = 0; |
| 441 i < arraysize(slice_param.RefPicList0) && iter != ref_pic_list0_.end(); | 435 i < arraysize(slice_param.RefPicList0) && iter != ref_pic_list0_.end(); |
| 442 ++iter, ++i) { | 436 ++iter, ++i) { |
| 443 InitVAPicture(&slice_param.RefPicList0[i]); | 437 InitVAPicture(&slice_param.RefPicList0[i]); |
| 444 slice_param.RefPicList0[i].picture_id = (*iter)->id(); | 438 slice_param.RefPicList0[i].picture_id = (*iter)->id(); |
| 445 slice_param.RefPicList0[i].flags = 0; | 439 slice_param.RefPicList0[i].flags = 0; |
| 446 } | 440 } |
| 447 | 441 |
| 448 if (!vaapi_wrapper_->SubmitBuffer(VAEncSliceParameterBufferType, | 442 if (!vaapi_wrapper_->SubmitBuffer(VAEncSliceParameterBufferType, |
| 449 sizeof(slice_param), | 443 sizeof(slice_param), &slice_param)) |
| 450 &slice_param)) | |
| 451 return false; | 444 return false; |
| 452 | 445 |
| 453 VAEncMiscParameterRateControl rate_control_param; | 446 VAEncMiscParameterRateControl rate_control_param; |
| 454 memset(&rate_control_param, 0, sizeof(rate_control_param)); | 447 memset(&rate_control_param, 0, sizeof(rate_control_param)); |
| 455 rate_control_param.bits_per_second = bitrate_; | 448 rate_control_param.bits_per_second = bitrate_; |
| 456 rate_control_param.target_percentage = 90; | 449 rate_control_param.target_percentage = 90; |
| 457 rate_control_param.window_size = kCPBWindowSizeMs; | 450 rate_control_param.window_size = kCPBWindowSizeMs; |
| 458 rate_control_param.initial_qp = qp_; | 451 rate_control_param.initial_qp = qp_; |
| 459 rate_control_param.rc_flags.bits.disable_frame_skip = true; | 452 rate_control_param.rc_flags.bits.disable_frame_skip = true; |
| 460 | 453 |
| 461 if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer( | 454 if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer( |
| 462 VAEncMiscParameterTypeRateControl, | 455 VAEncMiscParameterTypeRateControl, sizeof(rate_control_param), |
| 463 sizeof(rate_control_param), | |
| 464 &rate_control_param)) | 456 &rate_control_param)) |
| 465 return false; | 457 return false; |
| 466 | 458 |
| 467 VAEncMiscParameterFrameRate framerate_param; | 459 VAEncMiscParameterFrameRate framerate_param; |
| 468 memset(&framerate_param, 0, sizeof(framerate_param)); | 460 memset(&framerate_param, 0, sizeof(framerate_param)); |
| 469 framerate_param.framerate = framerate_; | 461 framerate_param.framerate = framerate_; |
| 470 if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer( | 462 if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer( |
| 471 VAEncMiscParameterTypeFrameRate, | 463 VAEncMiscParameterTypeFrameRate, sizeof(framerate_param), |
| 472 sizeof(framerate_param), | |
| 473 &framerate_param)) | 464 &framerate_param)) |
| 474 return false; | 465 return false; |
| 475 | 466 |
| 476 VAEncMiscParameterHRD hrd_param; | 467 VAEncMiscParameterHRD hrd_param; |
| 477 memset(&hrd_param, 0, sizeof(hrd_param)); | 468 memset(&hrd_param, 0, sizeof(hrd_param)); |
| 478 hrd_param.buffer_size = cpb_size_; | 469 hrd_param.buffer_size = cpb_size_; |
| 479 hrd_param.initial_buffer_fullness = cpb_size_ / 2; | 470 hrd_param.initial_buffer_fullness = cpb_size_ / 2; |
| 480 if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer(VAEncMiscParameterTypeHRD, | 471 if (!vaapi_wrapper_->SubmitVAEncMiscParamBuffer( |
| 481 sizeof(hrd_param), | 472 VAEncMiscParameterTypeHRD, sizeof(hrd_param), &hrd_param)) |
| 482 &hrd_param)) | |
| 483 return false; | 473 return false; |
| 484 | 474 |
| 485 return true; | 475 return true; |
| 486 } | 476 } |
| 487 | 477 |
| 488 bool VaapiVideoEncodeAccelerator::SubmitHeadersIfNeeded() { | 478 bool VaapiVideoEncodeAccelerator::SubmitHeadersIfNeeded() { |
| 489 DCHECK(current_pic_); | 479 DCHECK(current_pic_); |
| 490 if (current_pic_->type != media::H264SliceHeader::kISlice) | 480 if (current_pic_->type != media::H264SliceHeader::kISlice) |
| 491 return true; | 481 return true; |
| 492 | 482 |
| 493 // Submit PPS. | 483 // Submit PPS. |
| 494 VAEncPackedHeaderParameterBuffer par_buffer; | 484 VAEncPackedHeaderParameterBuffer par_buffer; |
| 495 memset(&par_buffer, 0, sizeof(par_buffer)); | 485 memset(&par_buffer, 0, sizeof(par_buffer)); |
| 496 par_buffer.type = VAEncPackedHeaderSequence; | 486 par_buffer.type = VAEncPackedHeaderSequence; |
| 497 par_buffer.bit_length = packed_sps_.BytesInBuffer() * 8; | 487 par_buffer.bit_length = packed_sps_.BytesInBuffer() * 8; |
| 498 | 488 |
| 499 if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderParameterBufferType, | 489 if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderParameterBufferType, |
| 500 sizeof(par_buffer), | 490 sizeof(par_buffer), &par_buffer)) |
| 501 &par_buffer)) | |
| 502 return false; | 491 return false; |
| 503 | 492 |
| 504 if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderDataBufferType, | 493 if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderDataBufferType, |
| 505 packed_sps_.BytesInBuffer(), | 494 packed_sps_.BytesInBuffer(), |
| 506 packed_sps_.data())) | 495 packed_sps_.data())) |
| 507 return false; | 496 return false; |
| 508 | 497 |
| 509 // Submit PPS. | 498 // Submit PPS. |
| 510 memset(&par_buffer, 0, sizeof(par_buffer)); | 499 memset(&par_buffer, 0, sizeof(par_buffer)); |
| 511 par_buffer.type = VAEncPackedHeaderPicture; | 500 par_buffer.type = VAEncPackedHeaderPicture; |
| 512 par_buffer.bit_length = packed_pps_.BytesInBuffer() * 8; | 501 par_buffer.bit_length = packed_pps_.BytesInBuffer() * 8; |
| 513 | 502 |
| 514 if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderParameterBufferType, | 503 if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderParameterBufferType, |
| 515 sizeof(par_buffer), | 504 sizeof(par_buffer), &par_buffer)) |
| 516 &par_buffer)) | |
| 517 return false; | 505 return false; |
| 518 | 506 |
| 519 if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderDataBufferType, | 507 if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderDataBufferType, |
| 520 packed_pps_.BytesInBuffer(), | 508 packed_pps_.BytesInBuffer(), |
| 521 packed_pps_.data())) | 509 packed_pps_.data())) |
| 522 return false; | 510 return false; |
| 523 | 511 |
| 524 return true; | 512 return true; |
| 525 } | 513 } |
| 526 | 514 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 void VaapiVideoEncodeAccelerator::Destroy() { | 745 void VaapiVideoEncodeAccelerator::Destroy() { |
| 758 DCHECK(child_task_runner_->BelongsToCurrentThread()); | 746 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
| 759 | 747 |
| 760 // Can't call client anymore after Destroy() returns. | 748 // Can't call client anymore after Destroy() returns. |
| 761 client_ptr_factory_.reset(); | 749 client_ptr_factory_.reset(); |
| 762 weak_this_ptr_factory_.InvalidateWeakPtrs(); | 750 weak_this_ptr_factory_.InvalidateWeakPtrs(); |
| 763 | 751 |
| 764 // Early-exit encoder tasks if they are running and join the thread. | 752 // Early-exit encoder tasks if they are running and join the thread. |
| 765 if (encoder_thread_.IsRunning()) { | 753 if (encoder_thread_.IsRunning()) { |
| 766 encoder_thread_.message_loop()->PostTask( | 754 encoder_thread_.message_loop()->PostTask( |
| 767 FROM_HERE, | 755 FROM_HERE, base::Bind(&VaapiVideoEncodeAccelerator::DestroyTask, |
| 768 base::Bind(&VaapiVideoEncodeAccelerator::DestroyTask, | 756 base::Unretained(this))); |
| 769 base::Unretained(this))); | |
| 770 encoder_thread_.Stop(); | 757 encoder_thread_.Stop(); |
| 771 } | 758 } |
| 772 | 759 |
| 773 delete this; | 760 delete this; |
| 774 } | 761 } |
| 775 | 762 |
| 776 void VaapiVideoEncodeAccelerator::DestroyTask() { | 763 void VaapiVideoEncodeAccelerator::DestroyTask() { |
| 777 DVLOGF(2); | 764 DVLOGF(2); |
| 778 DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); | 765 DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); |
| 779 SetState(kError); | 766 SetState(kError); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 current_sps_.time_scale = framerate_ * 2; // See equation D-2 in spec. | 833 current_sps_.time_scale = framerate_ * 2; // See equation D-2 in spec. |
| 847 current_sps_.fixed_frame_rate_flag = true; | 834 current_sps_.fixed_frame_rate_flag = true; |
| 848 | 835 |
| 849 current_sps_.nal_hrd_parameters_present_flag = true; | 836 current_sps_.nal_hrd_parameters_present_flag = true; |
| 850 // H.264 spec ch. E.2.2. | 837 // H.264 spec ch. E.2.2. |
| 851 current_sps_.cpb_cnt_minus1 = 0; | 838 current_sps_.cpb_cnt_minus1 = 0; |
| 852 current_sps_.bit_rate_scale = kBitRateScale; | 839 current_sps_.bit_rate_scale = kBitRateScale; |
| 853 current_sps_.cpb_size_scale = kCPBSizeScale; | 840 current_sps_.cpb_size_scale = kCPBSizeScale; |
| 854 current_sps_.bit_rate_value_minus1[0] = | 841 current_sps_.bit_rate_value_minus1[0] = |
| 855 (bitrate_ >> | 842 (bitrate_ >> |
| 856 (kBitRateScale + media::H264SPS::kBitRateScaleConstantTerm)) - 1; | 843 (kBitRateScale + media::H264SPS::kBitRateScaleConstantTerm)) - |
| 844 1; |
| 857 current_sps_.cpb_size_value_minus1[0] = | 845 current_sps_.cpb_size_value_minus1[0] = |
| 858 (cpb_size_ >> | 846 (cpb_size_ >> |
| 859 (kCPBSizeScale + media::H264SPS::kCPBSizeScaleConstantTerm)) - 1; | 847 (kCPBSizeScale + media::H264SPS::kCPBSizeScaleConstantTerm)) - |
| 848 1; |
| 860 current_sps_.cbr_flag[0] = true; | 849 current_sps_.cbr_flag[0] = true; |
| 861 current_sps_.initial_cpb_removal_delay_length_minus_1 = | 850 current_sps_.initial_cpb_removal_delay_length_minus_1 = |
| 862 media::H264SPS::kDefaultInitialCPBRemovalDelayLength - 1; | 851 media::H264SPS::kDefaultInitialCPBRemovalDelayLength - 1; |
| 863 current_sps_.cpb_removal_delay_length_minus1 = | 852 current_sps_.cpb_removal_delay_length_minus1 = |
| 864 media::H264SPS::kDefaultInitialCPBRemovalDelayLength - 1; | 853 media::H264SPS::kDefaultInitialCPBRemovalDelayLength - 1; |
| 865 current_sps_.dpb_output_delay_length_minus1 = | 854 current_sps_.dpb_output_delay_length_minus1 = |
| 866 media::H264SPS::kDefaultDPBOutputDelayLength - 1; | 855 media::H264SPS::kDefaultDPBOutputDelayLength - 1; |
| 867 current_sps_.time_offset_length = media::H264SPS::kDefaultTimeOffsetLength; | 856 current_sps_.time_offset_length = media::H264SPS::kDefaultTimeOffsetLength; |
| 868 current_sps_.low_delay_hrd_flag = false; | 857 current_sps_.low_delay_hrd_flag = false; |
| 869 } | 858 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 packed_sps_.AppendBits(5, current_sps_.cpb_removal_delay_length_minus1); | 942 packed_sps_.AppendBits(5, current_sps_.cpb_removal_delay_length_minus1); |
| 954 packed_sps_.AppendBits(5, current_sps_.dpb_output_delay_length_minus1); | 943 packed_sps_.AppendBits(5, current_sps_.dpb_output_delay_length_minus1); |
| 955 packed_sps_.AppendBits(5, current_sps_.time_offset_length); | 944 packed_sps_.AppendBits(5, current_sps_.time_offset_length); |
| 956 } | 945 } |
| 957 | 946 |
| 958 packed_sps_.AppendBool(false); // vcl_hrd_parameters_flag | 947 packed_sps_.AppendBool(false); // vcl_hrd_parameters_flag |
| 959 if (current_sps_.nal_hrd_parameters_present_flag) | 948 if (current_sps_.nal_hrd_parameters_present_flag) |
| 960 packed_sps_.AppendBool(current_sps_.low_delay_hrd_flag); | 949 packed_sps_.AppendBool(current_sps_.low_delay_hrd_flag); |
| 961 | 950 |
| 962 packed_sps_.AppendBool(false); // pic_struct_present_flag | 951 packed_sps_.AppendBool(false); // pic_struct_present_flag |
| 963 packed_sps_.AppendBool(true); // bitstream_restriction_flag | 952 packed_sps_.AppendBool(true); // bitstream_restriction_flag |
| 964 | 953 |
| 965 packed_sps_.AppendBool(false); // motion_vectors_over_pic_boundaries_flag | 954 packed_sps_.AppendBool(false); // motion_vectors_over_pic_boundaries_flag |
| 966 packed_sps_.AppendUE(2); // max_bytes_per_pic_denom | 955 packed_sps_.AppendUE(2); // max_bytes_per_pic_denom |
| 967 packed_sps_.AppendUE(1); // max_bits_per_mb_denom | 956 packed_sps_.AppendUE(1); // max_bits_per_mb_denom |
| 968 packed_sps_.AppendUE(16); // log2_max_mv_length_horizontal | 957 packed_sps_.AppendUE(16); // log2_max_mv_length_horizontal |
| 969 packed_sps_.AppendUE(16); // log2_max_mv_length_vertical | 958 packed_sps_.AppendUE(16); // log2_max_mv_length_vertical |
| 970 | 959 |
| 971 // Explicitly set max_num_reorder_frames to 0 to allow the decoder to | 960 // Explicitly set max_num_reorder_frames to 0 to allow the decoder to |
| 972 // output pictures early. | 961 // output pictures early. |
| 973 packed_sps_.AppendUE(0); // max_num_reorder_frames | 962 packed_sps_.AppendUE(0); // max_num_reorder_frames |
| 974 | 963 |
| 975 // The value of max_dec_frame_buffering shall be greater than or equal to | 964 // The value of max_dec_frame_buffering shall be greater than or equal to |
| 976 // max_num_ref_frames. | 965 // max_num_ref_frames. |
| 977 const unsigned int max_dec_frame_buffering = | 966 const unsigned int max_dec_frame_buffering = |
| 978 current_sps_.max_num_ref_frames; | 967 current_sps_.max_num_ref_frames; |
| 979 packed_sps_.AppendUE(max_dec_frame_buffering); | 968 packed_sps_.AppendUE(max_dec_frame_buffering); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 return; | 1047 return; |
| 1059 } | 1048 } |
| 1060 | 1049 |
| 1061 if (client_) { | 1050 if (client_) { |
| 1062 client_->NotifyError(error); | 1051 client_->NotifyError(error); |
| 1063 client_ptr_factory_.reset(); | 1052 client_ptr_factory_.reset(); |
| 1064 } | 1053 } |
| 1065 } | 1054 } |
| 1066 | 1055 |
| 1067 VaapiVideoEncodeAccelerator::EncodeJob::EncodeJob() | 1056 VaapiVideoEncodeAccelerator::EncodeJob::EncodeJob() |
| 1068 : coded_buffer(VA_INVALID_ID), keyframe(false) { | 1057 : coded_buffer(VA_INVALID_ID), keyframe(false) {} |
| 1069 } | |
| 1070 | 1058 |
| 1071 VaapiVideoEncodeAccelerator::EncodeJob::~EncodeJob() { | 1059 VaapiVideoEncodeAccelerator::EncodeJob::~EncodeJob() {} |
| 1072 } | |
| 1073 | 1060 |
| 1074 } // namespace content | 1061 } // namespace media |
| OLD | NEW |