1 /*
2  * Copyright (C) 2018 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 ANDROID_MEDIA_NBLOG_TIMELINE_H
18 #define ANDROID_MEDIA_NBLOG_TIMELINE_H
19 
20 #include <stddef.h>
21 
22 #include <audio_utils/fifo_index.h>
23 #include <utils/RefBase.h>
24 
25 namespace android {
26 namespace NBLog {
27 
28 // Located in shared memory, must be POD.
29 // Exactly one process must explicitly call the constructor or use placement new.
30 // Since this is a POD, the destructor is empty and unnecessary to call it explicitly.
31 struct Shared {
SharedShared32     Shared() /* mRear initialized via default constructor */ {}
~SharedShared33     ~Shared() {}
34 
35     audio_utils_fifo_index  mRear;  // index one byte past the end of most recent Entry
36     char    mBuffer[0];             // circular buffer for entries
37 };
38 
39 // FIXME Timeline was intended to wrap Writer and Reader, but isn't actually used yet.
40 // For now it is just a namespace for sharedSize().
41 class Timeline : public RefBase {
42 public:
43 #if 0
44     Timeline(size_t size, void *shared = NULL);
45     virtual ~Timeline();
46 #endif
47 
48     // Input parameter 'size' is the desired size of the timeline in byte units.
49     // Returns the size rounded up to a power-of-2, plus the constant size overhead for indices.
50     static size_t sharedSize(size_t size);
51 
52 #if 0
53 private:
54     friend class    Writer;
55     friend class    Reader;
56 
57     const size_t    mSize;      // circular buffer size in bytes, must be a power of 2
58     bool            mOwn;       // whether I own the memory at mShared
59     Shared* const   mShared;    // pointer to shared memory
60 #endif
61 };
62 
63 }   // namespace NBLog
64 }   // namespace android
65 
66 #endif  // ANDROID_MEDIA_NBLOG_TIMELINE_H
67