blob: 041e432cdfe874e2e233ab4f3ebdfb6869201c4d [file] [log] [blame]
Phil Burkdec33ab2017-01-17 14:48:16 -08001/*
2 * Copyright (C) 2016 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 OBOE_TIMESTAMP_SCHEDULER_H
18#define OBOE_TIMESTAMP_SCHEDULER_H
19
20//#include <stdlib.h> // random()
21
22#include "IOboeAudioService.h"
23#include "OboeService.h"
24#include "AudioStream.h"
25#include "fifo/FifoBuffer.h"
26#include "SharedRingBuffer.h"
27#include "AudioEndpointParcelable.h"
28
29namespace oboe {
30
31/**
32 * Schedule wakeup time for monitoring the position
33 * of an MMAP/NOIRQ buffer.
34 *
35 * Note that this object is not thread safe. Only call it from a single thread.
36 */
37class TimestampScheduler
38{
39public:
40 TimestampScheduler() {};
41 virtual ~TimestampScheduler() = default;
42
43 /**
44 * Start the schedule at the given time.
45 */
46 void start(oboe_nanoseconds_t startTime);
47
48 /**
49 * Calculate the next time that the read position should be
50 * measured.
51 */
52 oboe_nanoseconds_t nextAbsoluteTime();
53
54 void setBurstPeriod(oboe_nanoseconds_t burstPeriod) {
55 mBurstPeriod = burstPeriod;
56 }
57
58 void setBurstPeriod(oboe_size_frames_t framesPerBurst,
59 oboe_sample_rate_t sampleRate) {
60 mBurstPeriod = OBOE_NANOS_PER_SECOND * framesPerBurst / sampleRate;
61 }
62
63 oboe_nanoseconds_t getBurstPeriod() {
64 return mBurstPeriod;
65 }
66
67private:
68 // Start with an arbitrary default so we do not divide by zero.
69 oboe_nanoseconds_t mBurstPeriod = OBOE_NANOS_PER_MILLISECOND;
70 oboe_nanoseconds_t mStartTime;
71 oboe_nanoseconds_t mLastTime;
72};
73
74} /* namespace oboe */
75
76#endif /* OBOE_TIMESTAMP_SCHEDULER_H */