-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPKScheduledDataSlice.h
157 lines (134 loc) · 5.25 KB
/
PKScheduledDataSlice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* PKScheduledDataSlice.h
* PlayerKit
*
* Created by Peter MacWhinnie on 9/22/09.
* Copyright 2009 Roundabout Software. All rights reserved.
*
*/
#ifndef PKScheduledDataSlice_h
#define PKScheduledDataSlice_h 1
#include <AudioToolbox/AudioToolbox.h>
#include "RBObject.h"
#include "RBAtomic.h"
#include "PKAudioPlayerEngine.h"
/*!
@class
@abstract This class is used to represent the state of a slice in PKAudioPlayerEngine's scheduled audio player system.
@discussion The PKScheduledDataSlice class is more or less designed to be used like a struct.
It is expected that code that uses it will read and write to its members directly.
However, it is important to 'Acquire' (that is, lock) a PKScheduledDataSlice object
before reading or writing from it, and to 'Relinquish' (unlock) it after you are finished.
*/
PK_FINAL class PK_VISIBILITY_HIDDEN PKScheduledDataSlice : public RBLockableObject
{
public:
#pragma mark -
#pragma mark • Public
/*!
@abstract The owner of the processing data.
*/
/* weak */ PKAudioPlayerEngine *mOwner;
/*!
@abstract The atomic AtomicCounter that indicates the number of active slices currently
in use. When this value reaches zero, playback is considered to be finished..
@discussion This value is shared between many processing data objects.
*/
/* owner */ RBAtomicCounter *mNumberOfActiveSlicesAtomicCounter;
/*!
@abstract The number of the processing data. Multiple processing data
objects often exist in parallel, and this number indicates
which of a number of datas the 'receiver' is.
*/
/* n/a */ UInt32 mDataSliceProgressionNumber;
/*!
@abstract The scheduled audio slice of the processing data.
*/
/* owner */ ScheduledAudioSlice mScheduledAudioSlice;
/*!
@abstract The format of the buffers of the scheduled data slice.
*/
/* n/a */ AudioStreamBasicDescription mBuffersStreamFormat;
/*!
@abstract The number of frames to read when scheduling a slice.
*/
/* n/a */ UInt32 mNumberOfFramesToRead;
/*!
@abstract Whether or not the processing data has been invalidated.
@discussion The processing loop will release a processing data object if it has been invalidated,
thereby completing its lifecycle.
*/
/* n/a */ bool mInvalidated;
/*!
@abstract Whether or not this processing data has been populated with data.
*/
/* owner */ RBAtomicBool mBuffersHaveData;
/*!
@abstract Create a new scheduled data slice instance.
@discussion This is the designated 'constructor' for PKAudioPlayerEngine.
*/
static PKScheduledDataSlice *New(PKAudioPlayerEngine *owner,
RBAtomicCounter *atomicCounter,
AudioBufferList *bufferList,
UInt32 numberOfFrames,
const AudioStreamBasicDescription &streamFormat)
{
return (new PKScheduledDataSlice(owner, atomicCounter, bufferList, numberOfFrames, streamFormat));
}
/*!
@abstract The destructor.
@discussion The destructor will release any of its shared data and destroy its internal buffers.
*/
~PKScheduledDataSlice();
#pragma mark -
#pragma mark Utility Methods
/*!
@abstract Calculate the offset in the receiver's buffers relative to [global] sample time.
@param sampleTime A sample time relative to the slice's owners playback-start-time.
@result -1 if the passed in sample time is not contained in the receiver; The offset of the buffers otherwise.
*/
long CalculateBufferOffsetInFramesFromSampleTime(Float64 sampleTime) const;
/*!
@abstract A comparator that sorts an array based on the scheduled location of slices.
*/
static CFComparisonResult Comparator(PKScheduledDataSlice *left, PKScheduledDataSlice *right, PKAudioPlayerEngine *self);
/*!
@abstract This static method is provided for use with PKTaskQueue. The data slice instance
passed in as the first parameter is scheduled in the data slice's owner.
*/
static void ScheduleSliceTaskProxy(PKScheduledDataSlice *self) throw(RBException);
/*!
@abstract Reset the scheduled data slice's state.
*/
void Reset();
private:
#pragma mark -
#pragma mark • Private
/*!
@abstract The default constructor.
@param owner The owner of this processing data object. The owner of this object will
ensure that it is properly released when the time comes.
@param atomicCounter The AtomicCounter to use to communicate the number of active samples between
several DataSlice objects.
@param bufferList The buffers the DataSlice object is to use to schedule samples for
playback. It takes over ownership of the buffers and will destroy them
when it is destructed.
@param numberOfFrames The number of frames of data to write into the buffer list when scheduling
a sample for playback.
@param streamFormat The audio stream format of the bufferList.
*/
explicit PKScheduledDataSlice(PKAudioPlayerEngine *owner,
RBAtomicCounter *atomicCounter,
AudioBufferList *bufferList,
UInt32 numberOfFrames,
const AudioStreamBasicDescription &streamFormat);
/*!
@abstract PKScheduledDataSlice cannot be copied.
*/
PKScheduledDataSlice(PKScheduledDataSlice &slice);
/*!
@abstract PKScheduledDataSlice cannot be copied.
*/
PKScheduledDataSlice &operator=(PKScheduledDataSlice &slice);
};
#endif /* PKScheduledDataSlice_h */