Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1063)

Unified Diff: content/common/gpu/media/android_video_encode_accelerator.cc

Issue 170843004: Pass Client pointer in Initialize() for VDA/VEA (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 50e826de Rebase. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/android_video_encode_accelerator.cc
diff --git a/content/common/gpu/media/android_video_encode_accelerator.cc b/content/common/gpu/media/android_video_encode_accelerator.cc
index 05f18b6b12513c318a1753885b416710447f41ca..9e0aefcad3b1f8ff83e0e303cd79895e309280b0 100644
--- a/content/common/gpu/media/android_video_encode_accelerator.cc
+++ b/content/common/gpu/media/android_video_encode_accelerator.cc
@@ -33,16 +33,16 @@ enum {
// Helper macros for dealing with failure. If |result| evaluates false, emit
// |log| to DLOG(ERROR), register |error| with the client, and return.
-#define RETURN_ON_FAILURE(result, log, error) \
- do { \
- if (!(result)) { \
- DLOG(ERROR) << log; \
- if (client_ptr_factory_.GetWeakPtr()) { \
- client_ptr_factory_.GetWeakPtr()->NotifyError(error); \
- client_ptr_factory_.InvalidateWeakPtrs(); \
- } \
- return; \
- } \
+#define RETURN_ON_FAILURE(result, log, error) \
+ do { \
+ if (!(result)) { \
+ DLOG(ERROR) << log; \
+ if (client_ptr_factory_->GetWeakPtr()) { \
+ client_ptr_factory_->GetWeakPtr()->NotifyError(error); \
+ client_ptr_factory_.reset(); \
+ } \
+ return; \
+ } \
} while (0)
// Because MediaCodec is thread-hostile (must be poked on a single thread) and
@@ -67,10 +67,8 @@ static inline const base::TimeDelta NoWaitTimeOut() {
return base::TimeDelta::FromMicroseconds(0);
}
-AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator(
- media::VideoEncodeAccelerator::Client* client)
- : client_ptr_factory_(client),
- num_buffers_at_codec_(0),
+AndroidVideoEncodeAccelerator::AndroidVideoEncodeAccelerator()
+ : num_buffers_at_codec_(0),
num_output_buffers_(-1),
output_buffers_capacity_(0),
last_set_bitrate_(0) {}
@@ -118,7 +116,8 @@ void AndroidVideoEncodeAccelerator::Initialize(
VideoFrame::Format format,
const gfx::Size& input_visible_size,
media::VideoCodecProfile output_profile,
- uint32 initial_bitrate) {
+ uint32 initial_bitrate,
+ Client* client) {
DVLOG(3) << __PRETTY_FUNCTION__ << " format: " << format
<< ", input_visible_size: " << input_visible_size.ToString()
<< ", output_profile: " << output_profile
@@ -126,6 +125,8 @@ void AndroidVideoEncodeAccelerator::Initialize(
DCHECK(!media_codec_);
DCHECK(thread_checker_.CalledOnValidThread());
+ client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client));
+
RETURN_ON_FAILURE(media::MediaCodecBridge::IsAvailable() &&
media::MediaCodecBridge::SupportsSetParameters() &&
format == VideoFrame::I420 &&
@@ -161,14 +162,14 @@ void AndroidVideoEncodeAccelerator::Initialize(
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&VideoEncodeAccelerator::Client::NotifyInitializeDone,
- client_ptr_factory_.GetWeakPtr()));
+ client_ptr_factory_->GetWeakPtr()));
num_output_buffers_ = media_codec_->GetOutputBuffersCount();
output_buffers_capacity_ = media_codec_->GetOutputBuffersCapacity();
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&VideoEncodeAccelerator::Client::RequireBitstreamBuffers,
- client_ptr_factory_.GetWeakPtr(),
+ client_ptr_factory_->GetWeakPtr(),
num_output_buffers_,
input_visible_size,
output_buffers_capacity_));
@@ -246,7 +247,7 @@ void AndroidVideoEncodeAccelerator::RequestEncodingParametersChange(
void AndroidVideoEncodeAccelerator::Destroy() {
DVLOG(3) << __PRETTY_FUNCTION__;
DCHECK(thread_checker_.CalledOnValidThread());
- client_ptr_factory_.InvalidateWeakPtrs();
+ client_ptr_factory_.reset();
if (media_codec_) {
if (io_timer_.IsRunning())
io_timer_.Stop();
@@ -263,7 +264,7 @@ void AndroidVideoEncodeAccelerator::DoIOTask() {
}
void AndroidVideoEncodeAccelerator::QueueInput() {
- if (!client_ptr_factory_.GetWeakPtr() || pending_frames_.empty())
+ if (!client_ptr_factory_->GetWeakPtr() || pending_frames_.empty())
return;
int input_buf_index = 0;
@@ -347,7 +348,7 @@ bool AndroidVideoEncodeAccelerator::DoOutputBuffersSuffice() {
}
void AndroidVideoEncodeAccelerator::DequeueOutput() {
- if (!client_ptr_factory_.GetWeakPtr() ||
+ if (!client_ptr_factory_->GetWeakPtr() ||
available_bitstream_buffers_.empty() || num_buffers_at_codec_ == 0) {
return;
}
@@ -405,7 +406,7 @@ void AndroidVideoEncodeAccelerator::DequeueOutput() {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady,
- client_ptr_factory_.GetWeakPtr(),
+ client_ptr_factory_->GetWeakPtr(),
bitstream_buffer.id(),
size,
key_frame));
« no previous file with comments | « content/common/gpu/media/android_video_encode_accelerator.h ('k') | content/common/gpu/media/dxva_video_decode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698