From 38fef3bf253578f518d1bc727da4afb263194398 Mon Sep 17 00:00:00 2001 From: Nick Chalko Date: Wed, 17 Jan 2018 11:15:16 -0800 Subject: Fix broken build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts c9889d1 Update aosp build to use a snapshot of exoplyer. by nchalko · 5 hours ago master 8952aa7 Clean format by nchalko · 20 hours ago ba3fb16 Merge "Use a snapshot of exoplayer" by TreeHugger Robot · 18 hours ago ff75e39 Project import generated by Copybara. by Live Channels Team · 22 hours ago 9737fc2 Use a snapshot of exoplayer by Nick Chalko · 20 hours ago 4a5144a Project import generated by Copybara. by Live Channels Team · 6 days ago Bug: 72092981 Bug: 69474774 Change-Id: Ie756857c10bf052c60b6442c3d61252f65b49143 --- .../tv/tuner/exoplayer/audio/AudioClock.java | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/com/android/tv/tuner/exoplayer/audio/AudioClock.java (limited to 'src/com/android/tv/tuner/exoplayer/audio/AudioClock.java') diff --git a/src/com/android/tv/tuner/exoplayer/audio/AudioClock.java b/src/com/android/tv/tuner/exoplayer/audio/AudioClock.java new file mode 100644 index 00000000..13eabc3a --- /dev/null +++ b/src/com/android/tv/tuner/exoplayer/audio/AudioClock.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.tv.tuner.exoplayer.audio; + +import android.os.SystemClock; +import com.android.tv.common.SoftPreconditions; + +/** + * Copy of {@link com.google.android.exoplayer.MediaClock}. + * + *

A simple clock for tracking the progression of media time. The clock can be started, stopped + * and its time can be set and retrieved. When started, this clock is based on {@link + * SystemClock#elapsedRealtime()}. + */ +/* package */ class AudioClock { + private boolean mStarted; + + /** The media time when the clock was last set or stopped. */ + private long mPositionUs; + + /** + * The difference between {@link SystemClock#elapsedRealtime()} and {@link #mPositionUs} when + * the clock was last set or mStarted. + */ + private long mDeltaUs; + + private float mPlaybackSpeed = 1.0f; + private long mDeltaUpdatedTimeUs; + + /** Starts the clock. Does nothing if the clock is already started. */ + public void start() { + if (!mStarted) { + mStarted = true; + mDeltaUs = elapsedRealtimeMinus(mPositionUs); + mDeltaUpdatedTimeUs = SystemClock.elapsedRealtime() * 1000; + } + } + + /** Stops the clock. Does nothing if the clock is already stopped. */ + public void stop() { + if (mStarted) { + mPositionUs = elapsedRealtimeMinus(mDeltaUs); + mStarted = false; + } + } + + /** @param timeUs The position to set in microseconds. */ + public void setPositionUs(long timeUs) { + this.mPositionUs = timeUs; + mDeltaUs = elapsedRealtimeMinus(timeUs); + mDeltaUpdatedTimeUs = SystemClock.elapsedRealtime() * 1000; + } + + /** @return The current position in microseconds. */ + public long getPositionUs() { + if (!mStarted) { + return mPositionUs; + } + if (mPlaybackSpeed != 1.0f) { + long elapsedTimeFromPlaybackSpeedChanged = + SystemClock.elapsedRealtime() * 1000 - mDeltaUpdatedTimeUs; + return elapsedRealtimeMinus(mDeltaUs) + + (long) ((mPlaybackSpeed - 1.0f) * elapsedTimeFromPlaybackSpeedChanged); + } else { + return elapsedRealtimeMinus(mDeltaUs); + } + } + + /** Sets playback speed. {@code speed} should be positive. */ + public void setPlaybackSpeed(float speed) { + SoftPreconditions.checkState(speed > 0); + mDeltaUs = elapsedRealtimeMinus(getPositionUs()); + mDeltaUpdatedTimeUs = SystemClock.elapsedRealtime() * 1000; + mPlaybackSpeed = speed; + } + + private long elapsedRealtimeMinus(long toSubtractUs) { + return SystemClock.elapsedRealtime() * 1000 - toSubtractUs; + } +} -- cgit v1.2.3