1217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia/* 2217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * Copyright 2015 The Android Open Source Project 3217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * 4217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * Licensed under the Apache License, Version 2.0 (the "License"); 5217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * you may not use this file except in compliance with the License. 6217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * You may obtain a copy of the License at 7217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * 8217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * http://www.apache.org/licenses/LICENSE-2.0 9217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * 10217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * Unless required by applicable law or agreed to in writing, software 11217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * distributed under the License is distributed on an "AS IS" BASIS, 12217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * See the License for the specific language governing permissions and 14217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * limitations under the License. 15217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia */ 16217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia 17217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jiapackage android.media; 18217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia 19217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia/** 207f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * An immutable object that represents the linear correlation between the media time 217f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * and the system time. It contains the media clock rate, together with the media timestamp 22217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * of an anchor frame and the system time when that frame was presented or is committed 23217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * to be presented. 247f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * <p> 257f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * The phrase "present" means that audio/video produced on device is detectable by an external 26217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * observer off device. 27217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * The time is based on the implementation's best effort, using whatever knowledge 28217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * is available to the system, but cannot account for any delay unknown to the implementation. 297f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * The anchor frame could be any frame, including a just-rendered frame, or even a theoretical 307f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * or in-between frame, based on the source of the MediaTimestamp. 317f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * When the anchor frame is a just-rendered one, the media time stands for 327f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * current position of the playback or recording. 33217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * 34217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * @see MediaSync#getTimestamp 357f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * @see MediaPlayer#getTimestamp 36217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia */ 37217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jiapublic final class MediaTimestamp 38217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia{ 39217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia /** 4005a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar * Get the media time of the anchor in microseconds. 41217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia */ 4205a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar public long getAnchorMediaTimeUs() { 4305a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar return mediaTimeUs; 4405a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar } 45217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia 46217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia /** 4705a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar * Get the {@link java.lang.System#nanoTime system time} corresponding to the media time 487f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * in nanoseconds. 49217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia */ 5005a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar public long getAnchorSytemNanoTime() { 5105a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar return nanoTime; 5205a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar } 53217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia 54217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia /** 5505a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar * Get the rate of the media clock in relation to the system time. 5605a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar * <p> 577f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar * It is 1.0 if media clock advances in sync with the system clock; 58217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * greater than 1.0 if media clock is faster than the system clock; 59217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia * less than 1.0 if media clock is slower than the system clock. 60217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia */ 6105a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar public float getMediaClockRate() { 6205a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar return clockRate; 6305a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar } 6405a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar 6505a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar /** @hide - accessor shorthand */ 6605a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar public final long mediaTimeUs; 6705a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar /** @hide - accessor shorthand */ 6805a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar public final long nanoTime; 6905a822161fe0296b01f573192adf306c0ce38c9cLajos Molnar /** @hide - accessor shorthand */ 707f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar public final float clockRate; 717f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar 727f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar /** @hide */ 737f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar MediaTimestamp(long mediaUs, long systemNs, float rate) { 747f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar mediaTimeUs = mediaUs; 757f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar nanoTime = systemNs; 767f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar clockRate = rate; 777f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar } 787f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar 797f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar /** @hide */ 807f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar MediaTimestamp() { 817f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar mediaTimeUs = 0; 827f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar nanoTime = 0; 837f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar clockRate = 1.0f; 847f08763f4140822c30d0e18d4d3939488c8d26f8Lajos Molnar } 85217ec0adfc35302a6cc6b04bc78bf8fd82ffc8a5Wei Jia} 86