1 /* 2 * Copyright (C) 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 #ifndef MEDIA_CLOCK_H_ 18 19 #define MEDIA_CLOCK_H_ 20 21 #include <media/stagefright/foundation/ABase.h> 22 #include <utils/Mutex.h> 23 #include <utils/RefBase.h> 24 25 namespace android { 26 27 struct AMessage; 28 29 struct MediaClock : public RefBase { 30 MediaClock(); 31 32 void setStartingTimeMedia(int64_t startingTimeMediaUs); 33 34 void clearAnchor(); 35 // It's required to use timestamp of just rendered frame as 36 // anchor time in paused state. 37 void updateAnchor( 38 int64_t anchorTimeMediaUs, 39 int64_t anchorTimeRealUs, 40 int64_t maxTimeMediaUs = INT64_MAX); 41 42 void updateMaxTimeMedia(int64_t maxTimeMediaUs); 43 44 void setPlaybackRate(float rate); 45 float getPlaybackRate() const; 46 47 // query media time corresponding to real time |realUs|, and save the 48 // result in |outMediaUs|. 49 status_t getMediaTime( 50 int64_t realUs, 51 int64_t *outMediaUs, 52 bool allowPastMaxTime = false) const; 53 // query real time corresponding to media time |targetMediaUs|. 54 // The result is saved in |outRealUs|. 55 status_t getRealTimeFor(int64_t targetMediaUs, int64_t *outRealUs) const; 56 57 protected: 58 virtual ~MediaClock(); 59 60 private: 61 status_t getMediaTime_l( 62 int64_t realUs, 63 int64_t *outMediaUs, 64 bool allowPastMaxTime) const; 65 66 mutable Mutex mLock; 67 68 int64_t mAnchorTimeMediaUs; 69 int64_t mAnchorTimeRealUs; 70 int64_t mMaxTimeMediaUs; 71 int64_t mStartingTimeMediaUs; 72 73 float mPlaybackRate; 74 75 DISALLOW_EVIL_CONSTRUCTORS(MediaClock); 76 }; 77 78 } // namespace android 79 80 #endif // MEDIA_CLOCK_H_ 81