Chromium Code Reviews| Index: media/base/android/media_codec_loop.cc |
| diff --git a/media/base/android/media_codec_loop.cc b/media/base/android/media_codec_loop.cc |
| index 96c525118dc57e48248769d310bf8907312db5be..de615cf4eec23538b4829de30fac3a45fd318a39 100644 |
| --- a/media/base/android/media_codec_loop.cc |
| +++ b/media/base/android/media_codec_loop.cc |
| @@ -4,14 +4,9 @@ |
| #include "media/base/android/media_codec_loop.h" |
| -#include "base/android/build_info.h" |
| #include "base/bind.h" |
| #include "base/callback_helpers.h" |
| #include "base/logging.h" |
| -#include "base/threading/thread_task_runner_handle.h" |
| -#include "media/base/android/sdk_media_codec_bridge.h" |
| -#include "media/base/audio_buffer.h" |
| -#include "media/base/audio_timestamp_helper.h" |
| #include "media/base/bind_to_current_loop.h" |
| #include "media/base/timestamp_constants.h" |
| @@ -22,13 +17,6 @@ constexpr base::TimeDelta kDecodePollDelay = |
| constexpr base::TimeDelta kNoWaitTimeout = base::TimeDelta::FromMicroseconds(0); |
| constexpr base::TimeDelta kIdleTimerTimeout = base::TimeDelta::FromSeconds(1); |
| -static inline bool codec_flush_requires_destruction() { |
| - // Return true if and only if Flush() isn't supported / doesn't work. |
| - // Prior to JellyBean-MR2, flush() had several bugs (b/8125974, b/8347958) so |
| - // we have to completely destroy and recreate the codec there. |
| - return base::android::BuildInfo::GetInstance()->sdk_int() < 18; |
| -} |
| - |
| MediaCodecLoop::InputData::InputData() {} |
| MediaCodecLoop::InputData::InputData(const InputData& other) |
| @@ -43,13 +31,19 @@ MediaCodecLoop::InputData::InputData(const InputData& other) |
| MediaCodecLoop::InputData::~InputData() {} |
| -MediaCodecLoop::MediaCodecLoop(Client* client, |
| - std::unique_ptr<MediaCodecBridge> media_codec) |
| +MediaCodecLoop::MediaCodecLoop( |
| + int sdk_int, |
| + Client* client, |
| + std::unique_ptr<MediaCodecBridge> media_codec, |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| : state_(STATE_READY), |
| client_(client), |
| media_codec_(std::move(media_codec)), |
| pending_input_buf_index_(kInvalidBufferIndex), |
| + sdk_int_(sdk_int), |
| weak_factory_(this) { |
| + if (task_runner) |
| + io_timer_.SetTaskRunner(task_runner); |
| // TODO(liberato): should this DCHECK? |
| if (media_codec_ == nullptr) |
| SetState(STATE_ERROR); |
| @@ -59,6 +53,10 @@ MediaCodecLoop::~MediaCodecLoop() { |
| io_timer_.Stop(); |
| } |
| +void MediaCodecLoop::SetTestTickClock(base::TickClock* test_tick_clock) { |
| + test_tick_clock_ = test_tick_clock; |
| +} |
| + |
| void MediaCodecLoop::OnKeyAdded() { |
| if (state_ == STATE_WAITING_FOR_KEY) |
| SetState(STATE_READY); |
| @@ -76,7 +74,7 @@ bool MediaCodecLoop::TryFlush() { |
| if (state_ == STATE_ERROR || state_ == STATE_DRAINED) |
| return false; |
| - if (codec_flush_requires_destruction()) |
| + if (DoesCodecFlushRequireDestruction()) |
| return false; |
| // Actually try to flush! |
| @@ -310,7 +308,9 @@ bool MediaCodecLoop::ProcessOneOutputBuffer() { |
| void MediaCodecLoop::ManageTimer(bool did_work) { |
| bool should_be_running = true; |
| - base::TimeTicks now = base::TimeTicks::Now(); |
| + // One might also use DefaultTickClock, but then ownership becomes harder. |
| + base::TimeTicks now = (test_tick_clock_ ? test_tick_clock_->NowTicks() |
|
DaleCurtis
2016/08/01 18:23:16
Instead of doing this, always create tick_clock_.
|
| + : base::TimeTicks::Now()); |
| if (did_work || idle_time_begin_ == base::TimeTicks()) { |
| idle_time_begin_ = now; |
| } else { |
| @@ -338,6 +338,13 @@ MediaCodecBridge* MediaCodecLoop::GetCodec() const { |
| return media_codec_.get(); |
| } |
| +bool MediaCodecLoop::DoesCodecFlushRequireDestruction() const { |
| + // Return true if and only if Flush() isn't supported / doesn't work. |
| + // Prior to JellyBean-MR2, flush() had several bugs (b/8125974, b/8347958) so |
| + // we have to completely destroy and recreate the codec there. |
| + return sdk_int_ < 18; |
| +} |
| + |
| // static |
| const char* MediaCodecLoop::AsString(State state) { |
| #define RETURN_STRING(x) \ |