forked from CyanogenMod/android_external_opencore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid_audio_mio.h
354 lines (268 loc) · 10.8 KB
/
android_audio_mio.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#ifndef ANDROID_AUDIO_MIO_H
#define ANDROID_AUDIO_MIO_H
#ifndef PVMI_MIO_CONTROL_H_INCLUDED
#include "pvmi_mio_control.h"
#endif
#ifndef PVMI_MEDIA_TRANSFER_H_INCLUDED
#include "pvmi_media_transfer.h"
#endif
#ifndef OSCL_SCHEDULER_AO_H_INCLUDED
#include "oscl_scheduler_ao.h"
#endif
#ifndef PVMI_MEDIA_IO_OBSERVER_H_INCLUDED
#include "pvmi_media_io_observer.h"
#endif
#ifndef OSCL_FILE_IO_H_INCLUDED
#include "oscl_file_io.h"
#endif
#ifndef PVMI_CONFIG_AND_CAPABILITY_H_INCLUDED
#include "pvmi_config_and_capability.h"
#endif
#ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
#include "oscl_string_containers.h"
#endif
#ifndef PVMI_MEDIA_IO_CLOCK_EXTENSION_H_INCLUDED
#include "pvmi_media_io_clock_extension.h"
#endif
#ifndef ANDROID_AUDIO_OUTPUT_THREADSAFE_CALLBACK_AO_H_INCLUDED
#include "android_audio_output_threadsafe_callbacks.h"
#endif
#ifndef PVMF_MEDIA_CLOCK_H_INCLUDED
#include "pvmf_media_clock.h"
#endif
#ifdef PERFORMANCE_MEASUREMENTS_ENABLED
#ifndef _PVPROFILE_H
#include "pvprofile.h"
#endif
#endif
#include <media/MediaPlayerInterface.h>
class PVLogger;
class PVMFMediaClock;
using namespace android;
// Write command handling
// the audio output thread queues the responses, this mio dequeues and processes them
class WriteResponse
{
public:
WriteResponse(PVMFStatus s, PVMFCommandId id, const OsclAny* ctx, const PVMFTimestamp& ts) :
iStatus(s), iCmdId(id), iContext(ctx), iTimestamp(ts)
{}
PVMFStatus iStatus;
PVMFCommandId iCmdId;
const OsclAny* iContext;
PVMFTimestamp iTimestamp;
};
// Active timing support
class AndroidAudioMIOActiveTimingSupport :
public PvmiClockExtensionInterface, public PVMFMediaClockStateObserver
{
public:
AndroidAudioMIOActiveTimingSupport(int32 minCorrection=0, int32 maxCorrection=0) :
iClock(NULL),
iClockNotificationsInf(NULL),
iClockState(PVMFMediaClock::STOPPED),
iAudioThreadSem(0),
iStartTime(0),
iFrameCount(0),
iMsecsPerFrame(25),
iDriverLatency(0),
iUpdateClock(true),
iMinCorrection(minCorrection),
iMaxCorrection(maxCorrection)
{
}
~AndroidAudioMIOActiveTimingSupport()
{
if (iClock && iClockNotificationsInf)
{
iClockNotificationsInf->RemoveClockStateObserver(*this);
iClock->DestroyMediaClockNotificationsInterface(iClockNotificationsInf);
iClockNotificationsInf = NULL;
}
}
//from PvmiClockExtensionInterface
OSCL_IMPORT_REF PVMFStatus SetClock(PVMFMediaClock* clockVal);
// from PVMFMediaClockStateObserver
void ClockStateUpdated();
//from PVInterface
OSCL_IMPORT_REF void addRef() {}
OSCL_IMPORT_REF void removeRef() {}
OSCL_IMPORT_REF bool queryInterface(const PVUuid& uuid, PVInterface*& iface);
void NotificationsInterfaceDestroyed();
void queryUuid(PVUuid& uuid);
void ForceClockUpdate() { iUpdateClock = true; }
void UpdateClock();
PVMFMediaClock::PVMFMediaClockState clockState() { return iClockState; }
void setThreadSemaphore(OsclSemaphore* s) { iAudioThreadSem = s; }
void setDriverLatency(uint32 latency);
void incFrameCount(uint32_t numFrames) { iFrameCount += numFrames; }
void setFrameRate(float msecsPerFrame) { iMsecsPerFrame = msecsPerFrame; }
float msecsPerFrame() { return iMsecsPerFrame; }
private:
PVMFMediaClock* iClock;
PVMFMediaClockNotificationsInterface *iClockNotificationsInf;
PVMFMediaClock::PVMFMediaClockState iClockState;
OsclSemaphore* iAudioThreadSem;
uint32 iStartTime;
uint32 iFrameCount;
float iMsecsPerFrame;
uint32 iDriverLatency;
bool iUpdateClock;
int32 iMinCorrection;
int32 iMaxCorrection;
};
// Audio MIO component
class AndroidAudioMIO : public OsclTimerObject,
public PvmiMIOControl,
public PvmiMediaTransfer,
public PvmiCapabilityAndConfig
{
public:
OSCL_IMPORT_REF AndroidAudioMIO(const char* name);
OSCL_IMPORT_REF ~AndroidAudioMIO();
// APIs from PvmiMIOControl
PVMFStatus connect(PvmiMIOSession& aSession, PvmiMIOObserver* aObserver);
PVMFStatus disconnect(PvmiMIOSession aSession);
virtual PVMFCommandId QueryUUID(const PvmfMimeString& aMimeType,
Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids,
bool aExactUuidsOnly=false, const OsclAny* aContext=NULL);
virtual PVMFCommandId QueryInterface(const PVUuid& aUuid, PVInterface*& aInterfacePtr, const OsclAny* aContext=NULL);
PvmiMediaTransfer* createMediaTransfer(PvmiMIOSession& aSession, PvmiKvp* read_formats=NULL, int32 read_flags=0,
PvmiKvp* write_formats=NULL, int32 write_flags=0);
void deleteMediaTransfer(PvmiMIOSession& aSession, PvmiMediaTransfer* media_transfer) {}
PVMFCommandId Init(const OsclAny* aContext=NULL);
PVMFCommandId Reset(const OsclAny* aContext=NULL);
PVMFCommandId Start(const OsclAny* aContext=NULL);
PVMFCommandId Pause(const OsclAny* aContext=NULL);
PVMFCommandId Flush(const OsclAny* aContext=NULL);
virtual PVMFCommandId DiscardData(const OsclAny* aContext=NULL);
virtual PVMFCommandId DiscardData(PVMFTimestamp aTimestamp=0, const OsclAny* aContext=NULL);
virtual PVMFCommandId Stop(const OsclAny* aContext=NULL);
virtual PVMFCommandId CancelAllCommands(const OsclAny* aContext=NULL);
virtual PVMFCommandId CancelCommand(PVMFCommandId aCmdId, const OsclAny* aContext=NULL);
virtual void cancelCommand(PVMFCommandId aCmdId) {}
void ThreadLogon();
void ThreadLogoff();
// APIs from PvmiMediaTransfer
void setPeer(PvmiMediaTransfer* aPeer);
void useMemoryAllocators(OsclMemAllocator* write_alloc=NULL) {}
PVMFCommandId writeAsync(uint8 format_type, int32 format_index,
uint8* data, uint32 data_len,
const PvmiMediaXferHeader& data_header_info,
OsclAny* aContext=NULL);
void writeComplete(PVMFStatus aStatus, PVMFCommandId write_cmd_id, OsclAny* aContext) {}
PVMFCommandId readAsync(uint8* data, uint32 max_data_len, OsclAny* aContext=NULL,
int32* formats=NULL, uint16 num_formats=0) {
OsclError::Leave(OsclErrNotSupported);
return -1;
}
void readComplete(PVMFStatus aStatus, PVMFCommandId read_cmd_id, int32 format_index,
const PvmiMediaXferHeader& data_header_info, OsclAny* aContext) {}
void statusUpdate(uint32 status_flags) {}
virtual void cancelAllCommands() { returnAllBuffers(); }
// Pure virtuals from PvmiCapabilityAndConfig
void setObserver (PvmiConfigAndCapabilityCmdObserver* aObserver) { OSCL_UNUSED_ARG(aObserver); }
PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier,
PvmiKvp*& aParameters, int& num_parameter_elements, PvmiCapabilityContext aContext);
PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext) {
OsclError::Leave(OsclErrNotSupported);
}
void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext,
PvmiKvp* aParameters, int num_parameter_elements) {
OsclError::Leave(OsclErrNotSupported);
}
void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext) {
OsclError::Leave(OsclErrNotSupported);
}
virtual void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters,
int num_elements, PvmiKvp * & aRet_kvp);
PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters,
int num_elements, PvmiKvp*& aRet_kvp, OsclAny* context=NULL) {
OsclError::Leave(OsclErrNotSupported);
return -1;
}
uint32 getCapabilityMetric (PvmiMIOSession aSession) { return 0; }
PVMFStatus verifyParametersSync (PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
// Functions specific to this MIO
void setAudioSink(const sp<MediaPlayerInterface::AudioSink>& audioSink);
virtual void writeAudioBuffer(uint8* aData, uint32 aDataLen, PVMFCommandId cmdId,
OsclAny* aContext, PVMFTimestamp aTimestamp) {}
protected:
// From OsclTimerObject
void Run();
void sendResponse(PVMFCommandId cmdid, const OsclAny* context, PVMFTimestamp timestamp);
// Specific to this MIO
void initData();
void Cleanup();
virtual void returnAllBuffers() {}
void ResetData();
// request active object which the audio output thread uses to schedule this timer object to run
AndroidAudioOutputThreadSafeCallbackAO *iWriteCompleteAO;
// write response queue, needs to use lock mechanism to access
Oscl_Vector<WriteResponse,OsclMemAllocator> iWriteResponseQueue;
// lock used to access the write response queue
OsclMutex iWriteResponseQueueLock;
// From setPeer
PvmiMediaTransfer* iPeer;
// The PvmiMIOControl class observer.
PvmiMIOObserver* iObserver;
// for generating command IDs
uint32 iCommandCounter;
//State
enum PVAudioMIOState
{
STATE_MIO_IDLE
,STATE_MIO_LOGGED_ON
,STATE_MIO_INITIALIZED
,STATE_MIO_STARTED
,STATE_MIO_PAUSED
};
PVAudioMIOState iState;
// Control command handling.
class CommandResponse
{
public:
CommandResponse(PVMFStatus s,PVMFCommandId id,const OsclAny* ctx)
:iStatus(s),iCmdId(id),iContext(ctx)
{}
PVMFStatus iStatus;
PVMFCommandId iCmdId;
const OsclAny* iContext;
};
Oscl_Vector<CommandResponse,OsclMemAllocator> iCommandResponseQueue;
PVMFCommandId QueueCmdResponse(PVMFStatus status, const OsclAny* aContext);
void ProcessWriteResponseQueue();
// Audio parameters.
PVMFFormatType iAudioFormat;
int32 iAudioNumChannels;
bool iAudioNumChannelsValid;
int32 iAudioSamplingRate;
bool iAudioSamplingRateValid;
bool iAudioThreadCreatedAndMIOConfigured;
// For logging
PVLogger* iLogger;
// For implementing the write flow control
bool iWriteBusy;
bool CheckWriteBusy(uint32);
bool iFlushPending;
uint32 iDataQueued;
sp<MediaPlayerInterface::AudioSink> mAudioSink;
};
#endif // ANDROID_AUDIO_MIO_H