Commit 9bb17e2c authored by braveyao's avatar braveyao Committed by Commit bot

Android: Fix random crash in HW encode accelerator

There are reports of random Chrome crash due to HW encode accelerator
on Android.
Possible reason may be: currently we'll reset client factory at
encoding error and notify client. But before client stops encoding
(calling Destroy() here), if there is any pending frame delivered to
encoder, it will fail to get the pointer of client factory.
Here we try to leave the client factory life managment to client and
only notify the encoding error to client in error handling.

BUG=676987
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2601003002
Cr-Commit-Position: refs/heads/master@{#440864}
parent fa9f92fc
......@@ -47,9 +47,9 @@ enum PixelFormat {
do { \
if (!(result)) { \
DLOG(ERROR) << log; \
if (client_ptr_factory_->GetWeakPtr()) { \
if (!error_occurred_) { \
client_ptr_factory_->GetWeakPtr()->NotifyError(error); \
client_ptr_factory_.reset(); \
error_occurred_ = true; \
} \
return; \
} \
......@@ -94,7 +94,7 @@ static bool GetSupportedColorFormatForMime(const std::string& mime,
}
AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator()
: num_buffers_at_codec_(0), last_set_bitrate_(0) {}
: num_buffers_at_codec_(0), last_set_bitrate_(0), error_occurred_(false) {}
AndroidVideoEncodeAccelerator::~AndroidVideoEncodeAccelerator() {
DCHECK(thread_checker_.CalledOnValidThread());
......@@ -150,6 +150,7 @@ bool AndroidVideoEncodeAccelerator::Initialize(
<< ", initial_bitrate: " << initial_bitrate;
DCHECK(!media_codec_);
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(client);
client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client));
......@@ -301,7 +302,7 @@ void AndroidVideoEncodeAccelerator::DoIOTask() {
}
void AndroidVideoEncodeAccelerator::QueueInput() {
if (!client_ptr_factory_->GetWeakPtr() || pending_frames_.empty())
if (error_occurred_ || pending_frames_.empty())
return;
int input_buf_index = 0;
......@@ -368,8 +369,8 @@ void AndroidVideoEncodeAccelerator::QueueInput() {
}
void AndroidVideoEncodeAccelerator::DequeueOutput() {
if (!client_ptr_factory_->GetWeakPtr() ||
available_bitstream_buffers_.empty() || num_buffers_at_codec_ == 0) {
if (error_occurred_ || available_bitstream_buffers_.empty() ||
num_buffers_at_codec_ == 0) {
return;
}
......
......@@ -104,6 +104,9 @@ class MEDIA_GPU_EXPORT AndroidVideoEncodeAccelerator
uint32_t last_set_bitrate_; // In bps.
// True if there is encoder error.
bool error_occurred_;
DISALLOW_COPY_AND_ASSIGN(AndroidVideoEncodeAccelerator);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment