blob: d005993b2bb8be7045c88ff5b06b8e1d653f1671 [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();
35 // It's highly recommended to use timestamp of just rendered frame as
36 // anchor time, especially in paused state. Such restriction will be
37 // required when dynamic playback rate is supported in the future.
38 void updateAnchor(
39 int64_t anchorTimeMediaUs,
40 int64_t anchorTimeRealUs,
41 int64_t maxTimeMediaUs = INT64_MAX);
42
43 void updateMaxTimeMedia(int64_t maxTimeMediaUs);
44
45 void pause();
46 void resume();
47
48 int64_t getTimeMedia(int64_t realUs, bool allowPastMaxTime = false);
49
50protected:
51 virtual ~MediaClock();
52
53private:
54 Mutex mLock;
55
56 int64_t mAnchorTimeMediaUs;
57 int64_t mAnchorTimeRealUs;
58 int64_t mMaxTimeMediaUs;
59 int64_t mStartingTimeMediaUs;
60
61 bool mPaused;
62
63 DISALLOW_EVIL_CONSTRUCTORS(MediaClock);
64};
65
66} // namespace android
67
68#endif // MEDIA_CLOCK_H_