1 /* 2 * Copyright 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media; 18 19 /** 20 * An immutable object that represents the linear correlation between the media time 21 * and the system time. It contains the media clock rate, together with the media timestamp 22 * of an anchor frame and the system time when that frame was presented or is committed 23 * to be presented. 24 * <p> 25 * The phrase "present" means that audio/video produced on device is detectable by an external 26 * observer off device. 27 * The time is based on the implementation's best effort, using whatever knowledge 28 * is available to the system, but cannot account for any delay unknown to the implementation. 29 * The anchor frame could be any frame, including a just-rendered frame, or even a theoretical 30 * or in-between frame, based on the source of the MediaTimestamp. 31 * When the anchor frame is a just-rendered one, the media time stands for 32 * current position of the playback or recording. 33 * 34 * @see MediaSync#getTimestamp 35 * @see MediaPlayer#getTimestamp 36 */ 37 public final class MediaTimestamp 38 { 39 /** 40 * Get the media time of the anchor in microseconds. 41 */ getAnchorMediaTimeUs()42 public long getAnchorMediaTimeUs() { 43 return mediaTimeUs; 44 } 45 46 /** 47 * Get the {@link java.lang.System#nanoTime system time} corresponding to the media time 48 * in nanoseconds. 49 */ getAnchorSytemNanoTime()50 public long getAnchorSytemNanoTime() { 51 return nanoTime; 52 } 53 54 /** 55 * Get the rate of the media clock in relation to the system time. 56 * <p> 57 * It is 1.0 if media clock advances in sync with the system clock; 58 * greater than 1.0 if media clock is faster than the system clock; 59 * less than 1.0 if media clock is slower than the system clock. 60 */ getMediaClockRate()61 public float getMediaClockRate() { 62 return clockRate; 63 } 64 65 /** @hide - accessor shorthand */ 66 public final long mediaTimeUs; 67 /** @hide - accessor shorthand */ 68 public final long nanoTime; 69 /** @hide - accessor shorthand */ 70 public final float clockRate; 71 72 /** @hide */ MediaTimestamp(long mediaUs, long systemNs, float rate)73 MediaTimestamp(long mediaUs, long systemNs, float rate) { 74 mediaTimeUs = mediaUs; 75 nanoTime = systemNs; 76 clockRate = rate; 77 } 78 79 /** @hide */ MediaTimestamp()80 MediaTimestamp() { 81 mediaTimeUs = 0; 82 nanoTime = 0; 83 clockRate = 1.0f; 84 } 85 } 86