blob: 660764ff861a920f8c2c5690c41ccabe846c01f4 [file] [log] [blame]
Wei Jia7b15cb32015-02-03 17:46:06 -08001/*
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
25namespace android {
26
27struct AMessage;
28
29struct MediaClock : public RefBase {
30 MediaClock();
31
32 void setStartingTimeMedia(int64_t startingTimeMediaUs);
33
34 void clearAnchor();
Wei Jia98160162015-02-04 17:01:11 -080035 // It's required to use timestamp of just rendered frame as
36 // anchor time in paused state.
Wei Jia7b15cb32015-02-03 17:46:06 -080037 void updateAnchor(
38 int64_t anchorTimeMediaUs,
39 int64_t anchorTimeRealUs,
40 int64_t maxTimeMediaUs = INT64_MAX);
41
42 void updateMaxTimeMedia(int64_t maxTimeMediaUs);
43
Wei Jia98160162015-02-04 17:01:11 -080044 void setPlaybackRate(float rate);
Wei Jia7b15cb32015-02-03 17:46:06 -080045
Wei Jia98160162015-02-04 17:01:11 -080046 // query media time corresponding to real time |realUs|, and save the
47 // result in |outMediaUs|.
48 status_t getMediaTime(int64_t realUs,
49 int64_t *outMediaUs,
50 bool allowPastMaxTime = false);
51 // query real time corresponding to media time |targetMediaUs|.
52 // The result is saved in |outRealUs|.
53 status_t getRealTimeFor(int64_t targetMediaUs, int64_t *outRealUs);
Wei Jia7b15cb32015-02-03 17:46:06 -080054
55protected:
56 virtual ~MediaClock();
57
58private:
Wei Jia98160162015-02-04 17:01:11 -080059 status_t getMediaTime_l(int64_t realUs,
60 int64_t *outMediaUs,
61 bool allowPastMaxTime);
62
Wei Jia7b15cb32015-02-03 17:46:06 -080063 Mutex mLock;
64
65 int64_t mAnchorTimeMediaUs;
66 int64_t mAnchorTimeRealUs;
67 int64_t mMaxTimeMediaUs;
68 int64_t mStartingTimeMediaUs;
69
Wei Jia98160162015-02-04 17:01:11 -080070 float mPlaybackRate;
Wei Jia7b15cb32015-02-03 17:46:06 -080071
72 DISALLOW_EVIL_CONSTRUCTORS(MediaClock);
73};
74
75} // namespace android
76
77#endif // MEDIA_CLOCK_H_