| 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/media/android_video_encode_accelerator.h" | 5 #include "content/common/gpu/media/android_video_encode_accelerator.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 profile.max_framerate_denominator = kMaxFramerateDenominator; | 138 profile.max_framerate_denominator = kMaxFramerateDenominator; |
| 139 profiles.push_back(profile); | 139 profiles.push_back(profile); |
| 140 } | 140 } |
| 141 return profiles; | 141 return profiles; |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool AndroidVideoEncodeAccelerator::Initialize( | 144 bool AndroidVideoEncodeAccelerator::Initialize( |
| 145 media::VideoPixelFormat format, | 145 media::VideoPixelFormat format, |
| 146 const gfx::Size& input_visible_size, | 146 const gfx::Size& input_visible_size, |
| 147 media::VideoCodecProfile output_profile, | 147 media::VideoCodecProfile output_profile, |
| 148 uint32 initial_bitrate, | 148 uint32_t initial_bitrate, |
| 149 Client* client) { | 149 Client* client) { |
| 150 DVLOG(3) << __PRETTY_FUNCTION__ << " format: " << format | 150 DVLOG(3) << __PRETTY_FUNCTION__ << " format: " << format |
| 151 << ", input_visible_size: " << input_visible_size.ToString() | 151 << ", input_visible_size: " << input_visible_size.ToString() |
| 152 << ", output_profile: " << output_profile | 152 << ", output_profile: " << output_profile |
| 153 << ", initial_bitrate: " << initial_bitrate; | 153 << ", initial_bitrate: " << initial_bitrate; |
| 154 DCHECK(!media_codec_); | 154 DCHECK(!media_codec_); |
| 155 DCHECK(thread_checker_.CalledOnValidThread()); | 155 DCHECK(thread_checker_.CalledOnValidThread()); |
| 156 | 156 |
| 157 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 157 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
| 158 | 158 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 DVLOG(3) << __PRETTY_FUNCTION__ << ": bitstream_buffer_id=" << buffer.id(); | 261 DVLOG(3) << __PRETTY_FUNCTION__ << ": bitstream_buffer_id=" << buffer.id(); |
| 262 DCHECK(thread_checker_.CalledOnValidThread()); | 262 DCHECK(thread_checker_.CalledOnValidThread()); |
| 263 RETURN_ON_FAILURE(buffer.size() >= media_codec_->GetOutputBuffersCapacity(), | 263 RETURN_ON_FAILURE(buffer.size() >= media_codec_->GetOutputBuffersCapacity(), |
| 264 "Output buffers too small!", | 264 "Output buffers too small!", |
| 265 kInvalidArgumentError); | 265 kInvalidArgumentError); |
| 266 available_bitstream_buffers_.push_back(buffer); | 266 available_bitstream_buffers_.push_back(buffer); |
| 267 DoIOTask(); | 267 DoIOTask(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void AndroidVideoEncodeAccelerator::RequestEncodingParametersChange( | 270 void AndroidVideoEncodeAccelerator::RequestEncodingParametersChange( |
| 271 uint32 bitrate, | 271 uint32_t bitrate, |
| 272 uint32 framerate) { | 272 uint32_t framerate) { |
| 273 DVLOG(3) << __PRETTY_FUNCTION__ << ": bitrate: " << bitrate | 273 DVLOG(3) << __PRETTY_FUNCTION__ << ": bitrate: " << bitrate |
| 274 << ", framerate: " << framerate; | 274 << ", framerate: " << framerate; |
| 275 DCHECK(thread_checker_.CalledOnValidThread()); | 275 DCHECK(thread_checker_.CalledOnValidThread()); |
| 276 if (bitrate != last_set_bitrate_) { | 276 if (bitrate != last_set_bitrate_) { |
| 277 last_set_bitrate_ = bitrate; | 277 last_set_bitrate_ = bitrate; |
| 278 media_codec_->SetVideoBitrate(bitrate); | 278 media_codec_->SetVideoBitrate(bitrate); |
| 279 } | 279 } |
| 280 // Note: Android's MediaCodec doesn't allow mid-stream adjustments to | 280 // Note: Android's MediaCodec doesn't allow mid-stream adjustments to |
| 281 // framerate, so we ignore that here. This is OK because Android only uses | 281 // framerate, so we ignore that here. This is OK because Android only uses |
| 282 // the framerate value from MediaFormat during configure() as a proxy for | 282 // the framerate value from MediaFormat during configure() as a proxy for |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 UMA_HISTOGRAM_BOOLEAN("Media.AVEA.OutputBuffersSuffice", ret); | 386 UMA_HISTOGRAM_BOOLEAN("Media.AVEA.OutputBuffersSuffice", ret); |
| 387 return ret; | 387 return ret; |
| 388 } | 388 } |
| 389 | 389 |
| 390 void AndroidVideoEncodeAccelerator::DequeueOutput() { | 390 void AndroidVideoEncodeAccelerator::DequeueOutput() { |
| 391 if (!client_ptr_factory_->GetWeakPtr() || | 391 if (!client_ptr_factory_->GetWeakPtr() || |
| 392 available_bitstream_buffers_.empty() || num_buffers_at_codec_ == 0) { | 392 available_bitstream_buffers_.empty() || num_buffers_at_codec_ == 0) { |
| 393 return; | 393 return; |
| 394 } | 394 } |
| 395 | 395 |
| 396 int32 buf_index = 0; | 396 int32_t buf_index = 0; |
| 397 size_t offset = 0; | 397 size_t offset = 0; |
| 398 size_t size = 0; | 398 size_t size = 0; |
| 399 bool key_frame = false; | 399 bool key_frame = false; |
| 400 do { | 400 do { |
| 401 media::MediaCodecStatus status = media_codec_->DequeueOutputBuffer( | 401 media::MediaCodecStatus status = media_codec_->DequeueOutputBuffer( |
| 402 NoWaitTimeOut(), &buf_index, &offset, &size, NULL, NULL, &key_frame); | 402 NoWaitTimeOut(), &buf_index, &offset, &size, NULL, NULL, &key_frame); |
| 403 switch (status) { | 403 switch (status) { |
| 404 case media::MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: | 404 case media::MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: |
| 405 return; | 405 return; |
| 406 | 406 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 base::MessageLoop::current()->PostTask( | 446 base::MessageLoop::current()->PostTask( |
| 447 FROM_HERE, | 447 FROM_HERE, |
| 448 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, | 448 base::Bind(&VideoEncodeAccelerator::Client::BitstreamBufferReady, |
| 449 client_ptr_factory_->GetWeakPtr(), | 449 client_ptr_factory_->GetWeakPtr(), |
| 450 bitstream_buffer.id(), | 450 bitstream_buffer.id(), |
| 451 size, | 451 size, |
| 452 key_frame)); | 452 key_frame)); |
| 453 } | 453 } |
| 454 | 454 |
| 455 } // namespace content | 455 } // namespace content |
| OLD | NEW |