blob: 1c127e40736c7dbc6fe67fb5af105e3a6b5b54d1 [file] [log] [blame]
Wonsik Kimab34ed62019-01-31 15:28:46 -08001/*
2 * Copyright 2019 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 PIPELINE_WATCHER_H_
18#define PIPELINE_WATCHER_H_
19
20#include <chrono>
21#include <map>
22#include <memory>
23
24#include <C2Work.h>
25
26namespace android {
27
28/**
29 * PipelineWatcher watches the status of the work.
30 */
31class PipelineWatcher {
32public:
33 typedef std::chrono::steady_clock Clock;
34
35 PipelineWatcher()
36 : mInputDelay(0),
37 mPipelineDelay(0),
38 mOutputDelay(0),
39 mSmoothnessFactor(0) {}
40 ~PipelineWatcher() = default;
41
42 PipelineWatcher &inputDelay(uint32_t value);
43 PipelineWatcher &pipelineDelay(uint32_t value);
44 PipelineWatcher &outputDelay(uint32_t value);
45 PipelineWatcher &smoothnessFactor(uint32_t value);
46
47 void onWorkQueued(
48 uint64_t frameIndex,
49 std::vector<std::shared_ptr<C2Buffer>> &&buffers,
50 const Clock::time_point &queuedAt);
51 std::shared_ptr<C2Buffer> onInputBufferReleased(
52 uint64_t frameIndex, size_t arrayIndex);
53 void onWorkDone(uint64_t frameIndex);
54 void flush();
55
56 bool pipelineFull() const;
Wonsik Kim4fa4f2b2019-02-13 11:02:58 -080057 Clock::duration elapsed(const Clock::time_point &now, size_t n) const;
Wonsik Kimab34ed62019-01-31 15:28:46 -080058
59private:
60 uint32_t mInputDelay;
61 uint32_t mPipelineDelay;
62 uint32_t mOutputDelay;
63 uint32_t mSmoothnessFactor;
64
65 struct Frame {
66 Frame(std::vector<std::shared_ptr<C2Buffer>> &&b,
67 const Clock::time_point &q)
68 : buffers(b),
69 queuedAt(q) {}
70 std::vector<std::shared_ptr<C2Buffer>> buffers;
71 const Clock::time_point queuedAt;
72 };
73 std::map<uint64_t, Frame> mFramesInPipeline;
74};
75
76} // namespace android
77
78#endif // PIPELINE_WATCHER_H_