MediaClock.h revision 5833b6aad2c46ba516bdc8262f4fc4667e8018ed
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
25namespace android {
26
27struct AMessage;
28
29struct 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
46    // 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);
54
55protected:
56    virtual ~MediaClock();
57
58private:
59    status_t getMediaTime_l(int64_t realUs,
60                            int64_t *outMediaUs,
61                            bool allowPastMaxTime);
62
63    Mutex mLock;
64
65    int64_t mAnchorTimeMediaUs;
66    int64_t mAnchorTimeRealUs;
67    int64_t mMaxTimeMediaUs;
68    int64_t mStartingTimeMediaUs;
69
70    float mPlaybackRate;
71
72    DISALLOW_EVIL_CONSTRUCTORS(MediaClock);
73};
74
75}  // namespace android
76
77#endif  // MEDIA_CLOCK_H_
78