sles_allinclusive.h revision 5b09aa864215690580b18eb802927e8cc7eb4861
1/* 2 * Copyright (C) 2010 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/** \file sles_allinclusive.h Everything including the kitchen sink */ 18 19#include "SLES/OpenSLES.h" 20#include <stddef.h> // offsetof 21#include <stdlib.h> // malloc 22#include <string.h> // memcmp 23#include <stdio.h> // debugging 24#include <assert.h> // debugging 25#include <pthread.h> 26#include <unistd.h> // usleep 27#include <errno.h> 28 29#ifndef __cplusplus 30typedef int bool; 31#ifndef false 32#define false 0 33#endif 34#ifndef true 35#define true 1 36#endif 37#endif 38 39#include "MPH.h" 40#include "MPH_to.h" 41#include "devices.h" 42#include "OpenSLESUT.h" 43#include "ThreadPool.h" 44 45typedef struct CAudioPlayer_struct CAudioPlayer; 46typedef struct CAudioRecorder_struct CAudioRecorder; 47typedef struct C3DGroup_struct C3DGroup; 48typedef struct COutputMix_struct COutputMix; 49 50#ifdef USE_SNDFILE 51#include <sndfile.h> 52#include "SLSndFile.h" 53#endif // USE_SNDFILE 54 55#ifdef USE_SDL 56#include <SDL/SDL_audio.h> 57#endif // USE_SDL 58 59#ifdef ANDROID 60#include <utils/Log.h> 61#include <utils/KeyedVector.h> 62#include "SLES/OpenSLES_Android.h" 63#include "media/AudioSystem.h" 64#include "media/mediarecorder.h" 65#include "media/AudioRecord.h" 66#include "media/AudioTrack.h" 67#include "media/mediaplayer.h" 68#ifndef USE_BACKPORT 69#include "media/AudioEffect.h" 70#include "media/EffectApi.h" 71#include "media/EffectEqualizerApi.h" 72#include "media/EffectBassBoostApi.h" 73#include "media/EffectVirtualizerApi.h" 74#include "media/EffectPresetReverbApi.h" 75#endif 76#include <utils/String8.h> 77#define ANDROID_SL_MILLIBEL_MAX 0 78#include <binder/ProcessState.h> 79#include "android_sles_conversions.h" 80#ifndef USE_BACKPORT 81#include "android_SfPlayer.h" 82#include "android_OutputMix.h" 83#endif 84#include "android_AudioRecorder.h" 85#endif 86 87#define STEREO_CHANNELS 2 88 89#ifdef USE_OUTPUTMIXEXT 90#include "OutputMixExt.h" 91#endif 92 93// Hook functions 94 95typedef void (*VoidHook)(void *self); 96typedef SLresult (*StatusHook)(void *self); 97typedef SLresult (*AsyncHook)(void *self, SLboolean async); 98 99// Describes how an interface is related to a given class 100 101#define INTERFACE_IMPLICIT 0 102#define INTERFACE_EXPLICIT 1 103#define INTERFACE_DYNAMIC 2 104#define INTERFACE_UNAVAILABLE 3 105// note that INTERFACE_OPTIONAL is always re-mapped to one of the above 106 107// Profile-specific interfaces 108 109#ifdef USE_BASE 110#define INTERFACE_IMPLICIT_BASE INTERFACE_IMPLICIT 111#define INTERFACE_EXPLICIT_BASE INTERFACE_EXPLICIT 112#else 113#define INTERFACE_IMPLICIT_BASE INTERFACE_UNAVAILABLE 114#define INTERFACE_EXPLICIT_BASE INTERFACE_UNAVAILABLE 115#endif 116 117#ifdef USE_GAME 118#define INTERFACE_DYNAMIC_GAME INTERFACE_DYNAMIC 119#define INTERFACE_EXPLICIT_GAME INTERFACE_EXPLICIT 120#else 121#define INTERFACE_DYNAMIC_GAME INTERFACE_OPTIONAL 122#define INTERFACE_EXPLICIT_GAME INTERFACE_OPTIONAL 123#endif 124 125#ifdef USE_MUSIC 126#define INTERFACE_DYNAMIC_MUSIC INTERFACE_DYNAMIC 127#else 128#define INTERFACE_DYNAMIC_MUSIC INTERFACE_OPTIONAL 129#endif 130 131#if defined(USE_GAME) || defined(USE_MUSIC) 132#define INTERFACE_DYNAMIC_GAME_MUSIC INTERFACE_DYNAMIC 133#define INTERFACE_EXPLICIT_GAME_MUSIC INTERFACE_EXPLICIT 134#else 135#define INTERFACE_DYNAMIC_GAME_MUSIC INTERFACE_OPTIONAL 136#define INTERFACE_EXPLICIT_GAME_MUSIC INTERFACE_OPTIONAL 137#endif 138 139#if defined(USE_GAME) || defined(USE_PHONE) 140#define INTERFACE_EXPLICIT_GAME_PHONE INTERFACE_EXPLICIT 141#else 142#define INTERFACE_EXPLICIT_GAME_PHONE INTERFACE_OPTIONAL 143#endif 144 145#ifdef USE_OPTIONAL 146#define INTERFACE_OPTIONAL INTERFACE_EXPLICIT 147#define INTERFACE_DYNAMIC_OPTIONAL INTERFACE_DYNAMIC 148#else 149#define INTERFACE_OPTIONAL INTERFACE_UNAVAILABLE 150#define INTERFACE_DYNAMIC_OPTIONAL INTERFACE_UNAVAILABLE 151#endif 152 153// Describes how an interface is related to a given object 154 155#define INTERFACE_UNINITIALIZED 1 ///< /not requested at object creation time 156#define INTERFACE_EXPOSED 2 ///< /requested at object creation time 157#define INTERFACE_ADDING_1 3 ///< /part 1 of asynchronous AddInterface, pending 158#define INTERFACE_ADDING_2 4 ///< /synchronous AddInterface, or part 2 of asynchronous 159#define INTERFACE_ADDED 5 ///< /AddInterface has completed 160#define INTERFACE_REMOVING 6 ///< /unlocked phase of (synchronous) RemoveInterface 161#define INTERFACE_SUSPENDING 7 ///< /suspend in progress 162#define INTERFACE_SUSPENDED 8 ///< /suspend has completed 163#define INTERFACE_RESUMING_1 9 ///< /part 1 of asynchronous ResumeInterface, pending 164#define INTERFACE_RESUMING_2 10 ///< /synchronous ResumeInterface, or part 2 of asynchronous 165#define INTERFACE_ADDING_1A 11 ///< /part 1 of asynchronous AddInterface, aborted 166#define INTERFACE_RESUMING_1A 12 ///< /part 1 of asynchronous ResumeInterface, aborted 167 168// Maps an interface ID to its offset within the class that exposes it 169 170struct iid_vtable { 171 unsigned char mMPH; 172 unsigned char mInterface; // relationship 173 /*size_t*/ unsigned short mOffset; 174}; 175 176// Per-class const data shared by all instances of the same class 177 178typedef struct { 179 const struct iid_vtable *mInterfaces; 180 SLuint32 mInterfaceCount; // number of possible interfaces 181 const signed char *mMPH_to_index; 182 const char * const mName; 183 size_t mSize; 184 SLuint32 mObjectID; 185 // hooks 186 AsyncHook mRealize; 187 AsyncHook mResume; 188 VoidHook mDestroy; 189} ClassTable; 190 191// BufferHeader describes each element of a BufferQueue, other than the data 192 193typedef struct { 194 const void *mBuffer; 195 SLuint32 mSize; 196} BufferHeader; 197 198#ifdef USE_OUTPUTMIXEXT 199 200// stereo is a frame consisting of a pair of 16-bit PCM samples 201 202typedef struct { 203 short left; 204 short right; 205} stereo; 206 207#endif 208 209#ifdef __cplusplus 210#define this this_ 211#endif 212 213#ifdef USE_SNDFILE 214 215#define SndFile_BUFSIZE 512 // in 16-bit samples 216#define SndFile_NUMBUFS 2 217 218struct SndFile { 219 // save URI also? 220 SLchar *mPathname; 221 SNDFILE *mSNDFILE; 222 SF_INFO mSfInfo; 223 pthread_mutex_t mMutex; // protects mSNDFILE only 224 SLboolean mEOF; // sf_read returned zero sample frames 225 SLuint32 mWhich; // which buffer to use next 226 short mBuffer[SndFile_BUFSIZE * SndFile_NUMBUFS]; 227}; 228 229#endif // USE_SNDFILE 230 231/* Our own merged version of SLDataSource and SLDataSink */ 232 233typedef union { 234 SLuint32 mLocatorType; 235 SLDataLocator_Address mAddress; 236 SLDataLocator_BufferQueue mBufferQueue; 237 SLDataLocator_IODevice mIODevice; 238 SLDataLocator_MIDIBufferQueue mMIDIBufferQueue; 239 SLDataLocator_OutputMix mOutputMix; 240 SLDataLocator_URI mURI; 241#ifdef ANDROID 242 SLDataLocator_AndroidFD mFD; 243#endif 244} DataLocator; 245 246typedef union { 247 SLuint32 mFormatType; 248 SLDataFormat_PCM mPCM; 249 SLDataFormat_MIME mMIME; 250} DataFormat; 251 252typedef struct { 253 union { 254 SLDataSource mSource; 255 SLDataSink mSink; 256 struct { 257 DataLocator *pLocator; 258 DataFormat *pFormat; 259 } mNeutral; 260 } u; 261 DataLocator mLocator; 262 DataFormat mFormat; 263} DataLocatorFormat; 264 265/* Interface structures */ 266 267typedef struct Object_interface { 268 const struct SLObjectItf_ *mItf; // const 269 // field mThis would be redundant within an IObject, so we substitute mEngine 270 struct Engine_interface *mEngine; // const 271 const ClassTable *mClass; // const 272 SLuint32 mInstanceID; // const for debugger and for RPC 273 slObjectCallback mCallback; 274 void *mContext; 275 unsigned mGottenMask; ///< bit-mask of interfaces exposed or added, then gotten 276 unsigned mLossOfControlMask; // interfaces with loss of control enabled 277 unsigned mAttributesMask; // attributes which have changed since last sync 278#ifdef USE_BASE 279 SLint32 mPriority; 280#endif 281 pthread_mutex_t mMutex; 282#ifdef USE_DEBUG 283 pthread_t mOwner; 284 const char *mFile; 285 int mLine; 286#endif 287 pthread_cond_t mCond; 288 SLuint8 mState; // really SLuint32, but SLuint8 to save space 289#ifdef USE_BASE 290 SLuint8 mPreemptable; // really SLboolean, but SLuint8 to save space 291#else 292 SLuint8 mPadding; 293#endif 294 // for best alignment, do not add any fields here 295#define INTERFACES_Default 2 296 SLuint8 mInterfaceStates[INTERFACES_Default]; // state of each of interface 297 // do not add any fields here 298} IObject; 299 300#include "locks.h" 301 302typedef struct { 303 const struct SL3DCommitItf_ *mItf; 304 IObject *mThis; 305 SLboolean mDeferred; 306 SLuint32 mGeneration; // incremented each master clock cycle 307 SLuint32 mWaiting; // number of threads waiting in Commit 308} I3DCommit; 309 310enum CartesianSphericalActive { 311 CARTESIAN_COMPUTED_SPHERICAL_SET, 312 CARTESIAN_REQUESTED_SPHERICAL_SET, 313 CARTESIAN_UNKNOWN_SPHERICAL_SET, 314 CARTESIAN_SET_SPHERICAL_COMPUTED, // not in 1.0.1 315 CARTESIAN_SET_SPHERICAL_REQUESTED, // not in 1.0.1 316 CARTESIAN_SET_SPHERICAL_UNKNOWN 317}; 318 319typedef struct { 320 const struct SL3DDopplerItf_ *mItf; 321 IObject *mThis; 322 // The API allows client to specify either Cartesian and spherical velocities. 323 // But an implementation will likely prefer one or the other. So for 324 // maximum portablity, we maintain both units and an indication of which 325 // unit was set most recently. In addition, we keep a flag saying whether 326 // the other unit has been derived yet. It can take significant time 327 // to compute the other unit, so this may be deferred to another thread. 328 // For this reason we also keep an indication of whether the secondary 329 // has been computed yet, and its accuracy. 330 // Though only one unit is primary at a time, a union is inappropriate: 331 // the application might read in both units (not in 1.0.1), 332 // and due to multi-threading concerns. 333 SLVec3D mVelocityCartesian; 334 struct { 335 SLmillidegree mAzimuth; 336 SLmillidegree mElevation; 337 SLmillidegree mSpeed; 338 } mVelocitySpherical; 339 enum CartesianSphericalActive mVelocityActive; 340 SLpermille mDopplerFactor; 341} I3DDoppler; 342 343typedef struct { 344 const struct SL3DGroupingItf_ *mItf; 345 IObject *mThis; 346 C3DGroup *mGroup; // link to associated group or NULL 347} I3DGrouping; 348 349enum AnglesVectorsActive { 350 ANGLES_COMPUTED_VECTORS_SET, // not in 1.0.1 351 ANGLES_REQUESTED_VECTORS_SET, // not in 1.0.1 352 ANGLES_UNKNOWN_VECTORS_SET, 353 ANGLES_SET_VECTORS_COMPUTED, 354 ANGLES_SET_VECTORS_REQUESTED, 355 ANGLES_SET_VECTORS_UNKNOWN 356}; 357 358typedef struct { 359 const struct SL3DLocationItf_ *mItf; 360 IObject *mThis; 361 SLVec3D mLocationCartesian; 362 struct { 363 SLmillidegree mAzimuth; 364 SLmillidegree mElevation; 365 SLmillimeter mDistance; 366 } mLocationSpherical; 367 enum CartesianSphericalActive mLocationActive; 368 struct { 369 SLmillidegree mHeading; 370 SLmillidegree mPitch; 371 SLmillidegree mRoll; 372 } mOrientationAngles; 373 struct { 374 SLVec3D mFront; 375 SLVec3D mAbove; 376 SLVec3D mUp; 377 } mOrientationVectors; 378 enum AnglesVectorsActive mOrientationActive; 379 // Rotations can be slow, so are deferred. 380 SLmillidegree mTheta; 381 SLVec3D mAxis; 382 SLboolean mRotatePending; 383} I3DLocation; 384 385typedef struct { 386 const struct SL3DMacroscopicItf_ *mItf; 387 IObject *mThis; 388 struct { 389 SLmillimeter mWidth; 390 SLmillimeter mHeight; 391 SLmillimeter mDepth; 392 } mSize; 393 struct { 394 SLmillimeter mHeading; 395 SLmillimeter mPitch; 396 SLmillimeter mRoll; 397 } mOrientationAngles; 398 struct { 399 SLVec3D mFront; 400 SLVec3D mAbove; 401 SLVec3D mUp; 402 } mOrientationVectors; 403 enum AnglesVectorsActive mOrientationActive; 404 // Rotations can be slow, so are deferred. 405 SLmillidegree mTheta; 406 SLVec3D mAxis; 407 SLboolean mRotatePending; 408} I3DMacroscopic; 409 410typedef struct { 411 const struct SL3DSourceItf_ *mItf; 412 IObject *mThis; 413 SLboolean mHeadRelative; 414 SLboolean mRolloffMaxDistanceMute; 415 SLmillimeter mMaxDistance; 416 SLmillimeter mMinDistance; 417 SLmillidegree mConeInnerAngle; 418 SLmillidegree mConeOuterAngle; 419 SLmillibel mConeOuterLevel; 420 SLpermille mRolloffFactor; 421 SLpermille mRoomRolloffFactor; 422 SLuint8 mDistanceModel; 423} I3DSource; 424 425typedef struct { 426 const struct SLAudioDecoderCapabilitiesItf_ *mItf; 427 IObject *mThis; 428} IAudioDecoderCapabilities; 429 430typedef struct { 431 const struct SLAudioEncoderItf_ *mItf; 432 IObject *mThis; 433 SLAudioEncoderSettings mSettings; 434} IAudioEncoder; 435 436typedef struct { 437 const struct SLAudioEncoderCapabilitiesItf_ *mItf; 438 IObject *mThis; 439} IAudioEncoderCapabilities; 440 441typedef struct { 442 const struct SLAudioIODeviceCapabilitiesItf_ *mItf; 443 IObject *mThis; 444 slAvailableAudioInputsChangedCallback mAvailableAudioInputsChangedCallback; 445 void *mAvailableAudioInputsChangedContext; 446 slAvailableAudioOutputsChangedCallback mAvailableAudioOutputsChangedCallback; 447 void *mAvailableAudioOutputsChangedContext; 448 slDefaultDeviceIDMapChangedCallback mDefaultDeviceIDMapChangedCallback; 449 void *mDefaultDeviceIDMapChangedContext; 450} IAudioIODeviceCapabilities; 451 452typedef struct { 453 const struct SLBassBoostItf_ *mItf; 454 IObject *mThis; 455 SLboolean mEnabled; 456 SLpermille mStrength; 457#if defined(ANDROID) && !defined(USE_BACKPORT) 458 effect_descriptor_t mBassBoostDescriptor; 459 android::sp<android::AudioEffect> mBassBoostEffect; 460#endif 461} IBassBoost; 462 463typedef struct BufferQueue_interface { 464 const struct SLBufferQueueItf_ *mItf; 465 IObject *mThis; 466 SLBufferQueueState mState; 467 slBufferQueueCallback mCallback; 468 void *mContext; 469 // originally SLuint32, but range-checked down to SLuint16 470 SLuint16 mNumBuffers; 471 /*SLboolean*/ SLuint16 mClearRequested; 472 BufferHeader *mArray; 473 BufferHeader *mFront, *mRear; 474#ifdef ANDROID 475 SLuint32 mSizeConsumed; 476#endif 477 // saves a malloc in the typical case 478#define BUFFER_HEADER_TYPICAL 4 479 BufferHeader mTypical[BUFFER_HEADER_TYPICAL+1]; 480} IBufferQueue; 481 482#define MAX_DEVICE 2 483 484typedef struct { 485 const struct SLDeviceVolumeItf_ *mItf; 486 IObject *mThis; 487 SLint32 mVolume[MAX_DEVICE]; 488} IDeviceVolume; 489 490typedef struct { 491 const struct SLDynamicInterfaceManagementItf_ *mItf; 492 IObject *mThis; 493 slDynamicInterfaceManagementCallback mCallback; 494 void *mContext; 495} IDynamicInterfaceManagement; 496 497typedef struct { 498 const struct SLDynamicSourceItf_ *mItf; 499 IObject *mThis; 500 SLDataSource *mDataSource; 501} IDynamicSource; 502 503// private 504 505struct EnableLevel { 506 SLboolean mEnable; 507 SLmillibel mSendLevel; 508}; 509 510// indexes into IEffectSend.mEnableLevels 511 512#define AUX_ENVIRONMENTALREVERB 0 513#define AUX_PRESETREVERB 1 514#define AUX_MAX 2 515 516typedef struct { 517 const struct SLEffectSendItf_ *mItf; 518 IObject *mThis; 519 SLmillibel mDirectLevel; // dry volume 520 struct EnableLevel mEnableLevels[AUX_MAX]; // wet enable and volume per effect type 521} IEffectSend; 522 523typedef struct Engine_interface { 524 const struct SLEngineItf_ *mItf; 525 IObject *mThis; 526 SLboolean mLossOfControlGlobal; 527#ifdef USE_SDL 528 COutputMix *mOutputMix; // SDL pulls PCM from an arbitrary IOutputMixExt 529#endif 530 // Each engine is its own universe. 531 SLuint32 mInstanceCount; 532 unsigned mInstanceMask; // 1 bit per active object 533 unsigned mChangedMask; // objects which have changed since last sync 534#define MAX_INSTANCE 32 // see mInstanceMask 535 IObject *mInstances[MAX_INSTANCE]; 536 SLboolean mShutdown; 537 SLboolean mShutdownAck; 538 ThreadPool mThreadPool; // for asynchronous operations 539#if defined(ANDROID) && !defined(USE_BACKPORT) 540 // FIXME number of presets will only be saved in IEqualizer, preset names will not be stored 541 SLuint32 mEqNumPresets; 542 char** mEqPresetNames; 543#endif 544} IEngine; 545 546typedef struct { 547 const struct SLEngineCapabilitiesItf_ *mItf; 548 IObject *mThis; 549 SLboolean mThreadSafe; 550 // const 551 SLuint32 mMaxIndexLED; 552 SLuint32 mMaxIndexVibra; 553} IEngineCapabilities; 554 555typedef struct { 556 const struct SLEnvironmentalReverbItf_ *mItf; 557 IObject *mThis; 558 SLEnvironmentalReverbSettings mProperties; 559#if defined(ANDROID) && !defined(USE_BACKPORT) 560 effect_descriptor_t mEnvironmentalReverbDescriptor; 561 android::sp<android::AudioEffect> mEnvironmentalReverbEffect; 562#endif 563} IEnvironmentalReverb; 564 565struct EqualizerBand { 566 SLmilliHertz mMin; 567 SLmilliHertz mCenter; 568 SLmilliHertz mMax; 569}; 570 571#if defined(ANDROID) && !defined(USE_BACKPORT) 572#define MAX_EQ_BANDS 0 573#else 574#define MAX_EQ_BANDS 4 // compile-time limit, runtime limit may be smaller 575#endif 576 577typedef struct { 578 const struct SLEqualizerItf_ *mItf; 579 IObject *mThis; 580 SLboolean mEnabled; 581 SLuint16 mPreset; 582 SLmillibel mLevels[MAX_EQ_BANDS]; 583 // const to end of struct 584 SLuint16 mNumPresets; 585 SLuint16 mNumBands; 586 const struct EqualizerBand *mBands; 587 const struct EqualizerPreset *mPresets; 588 SLmillibel mBandLevelRangeMin; 589 SLmillibel mBandLevelRangeMax; 590#if defined(ANDROID) && !defined(USE_BACKPORT) 591 effect_descriptor_t mEqDescriptor; 592 android::sp<android::AudioEffect> mEqEffect; 593#endif 594} IEqualizer; 595 596#define MAX_LED_COUNT 32 597 598typedef struct { 599 const struct SLLEDArrayItf_ *mItf; 600 IObject *mThis; 601 SLuint32 mLightMask; 602 SLHSL mColors[MAX_LED_COUNT]; 603 // const 604 SLuint8 mCount; 605} ILEDArray; 606 607typedef struct { 608 const struct SLMetadataExtractionItf_ *mItf; 609 IObject *mThis; 610 SLuint32 mKeySize; 611 const void *mKey; 612 SLuint32 mKeyEncoding; 613 const SLchar *mValueLangCountry; 614 SLuint32 mValueEncoding; 615 SLuint8 mFilterMask; 616 int mKeyFilter; 617} IMetadataExtraction; 618 619typedef struct { 620 const struct SLMetadataTraversalItf_ *mItf; 621 IObject *mThis; 622 SLuint32 mIndex; 623 SLuint32 mMode; 624 SLuint32 mCount; 625 SLuint32 mSize; 626} IMetadataTraversal; 627 628typedef struct { 629 const struct SLMIDIMessageItf_ *mItf; 630 IObject *mThis; 631 slMetaEventCallback mMetaEventCallback; 632 void *mMetaEventContext; 633 slMIDIMessageCallback mMessageCallback; 634 void *mMessageContext; 635 SLuint8 mMessageTypes; 636} IMIDIMessage; 637 638typedef struct { 639 const struct SLMIDIMuteSoloItf_ *mItf; 640 IObject *mThis; 641 SLuint16 mChannelMuteMask; 642 SLuint16 mChannelSoloMask; 643 SLuint32 mTrackMuteMask; 644 SLuint32 mTrackSoloMask; 645 // const 646 SLuint16 mTrackCount; 647} IMIDIMuteSolo; 648 649typedef struct { 650 const struct SLMIDITempoItf_ *mItf; 651 IObject *mThis; 652 SLuint32 mTicksPerQuarterNote; 653 SLuint32 mMicrosecondsPerQuarterNote; 654} IMIDITempo; 655 656typedef struct { 657 const struct SLMIDITimeItf_ *mItf; 658 IObject *mThis; 659 SLuint32 mDuration; 660 SLuint32 mPosition; 661 SLuint32 mStartTick; 662 SLuint32 mNumTicks; 663} IMIDITime; 664 665typedef struct { 666 const struct SLMuteSoloItf_ *mItf; 667 IObject *mThis; 668 // fields that were formerly here are now at CAudioPlayer 669} IMuteSolo; 670 671#define MAX_TRACK 32 // see mActiveMask 672 673typedef struct { 674 const struct SLOutputMixItf_ *mItf; 675 IObject *mThis; 676 slMixDeviceChangeCallback mCallback; 677 void *mContext; 678#ifdef USE_OUTPUTMIXEXT 679 unsigned mActiveMask; // 1 bit per active track 680 Track mTracks[MAX_TRACK]; 681#endif 682} IOutputMix; 683 684#ifdef USE_OUTPUTMIXEXT 685typedef struct { 686 const struct SLOutputMixExtItf_ *mItf; 687 IObject *mThis; 688} IOutputMixExt; 689#endif 690 691typedef struct { 692 const struct SLPitchItf_ *mItf; 693 IObject *mThis; 694 SLpermille mPitch; 695 // const 696 SLpermille mMinPitch; 697 SLpermille mMaxPitch; 698} IPitch; 699 700typedef struct Play_interface { 701 const struct SLPlayItf_ *mItf; 702 IObject *mThis; 703 SLuint32 mState; 704 // next 2 fields are read-only to application 705 SLmillisecond mDuration; 706 SLmillisecond mPosition; 707 slPlayCallback mCallback; 708 void *mContext; 709 SLuint32 mEventFlags; 710 // the ISeek trick of using a distinct value doesn't work here because it's readable by app 711 SLmillisecond mMarkerPosition; 712 SLboolean mMarkerIsSet; 713 SLmillisecond mPositionUpdatePeriod; // Zero means do not do position updates (FIXME ~0) 714#ifdef USE_OUTPUTMIXEXT 715 SLuint32 mFrameUpdatePeriod; // mPositionUpdatePeriod in frame units 716 SLmillisecond mLastSeekPosition; // Last known accurate position, set at Seek 717 SLuint32 mFramesSinceLastSeek; // Frames mixed since last known accurate position 718 SLuint32 mFramesSincePositionUpdate; // Frames mixed since last position update callback 719#endif 720} IPlay; 721 722typedef struct { 723 const struct SLPlaybackRateItf_ *mItf; 724 IObject *mThis; 725 SLpermille mRate; 726 SLuint32 mProperties; 727 // const 728 SLpermille mMinRate; 729 SLpermille mMaxRate; 730 SLpermille mStepSize; 731 SLuint32 mCapabilities; 732} IPlaybackRate; 733 734typedef struct { 735 const struct SLPrefetchStatusItf_ *mItf; 736 IObject *mThis; 737 SLuint32 mStatus; 738 SLpermille mLevel; 739 slPrefetchCallback mCallback; 740 void *mContext; 741 SLuint32 mCallbackEventsMask; 742 SLpermille mFillUpdatePeriod; 743} IPrefetchStatus; 744 745typedef struct { 746 const struct SLPresetReverbItf_ *mItf; 747 IObject *mThis; 748 SLuint16 mPreset; 749#if defined(ANDROID) && !defined(USE_BACKPORT) 750 effect_descriptor_t mPresetReverbDescriptor; 751 android::sp<android::AudioEffect> mPresetReverbEffect; 752#endif 753} IPresetReverb; 754 755typedef struct { 756 const struct SLRatePitchItf_ *mItf; 757 IObject *mThis; 758 SLpermille mRate; 759 // const 760 SLpermille mMinRate; 761 SLpermille mMaxRate; 762} IRatePitch; 763 764typedef struct { 765 const struct SLRecordItf_ *mItf; 766 IObject *mThis; 767 SLuint32 mState; 768 SLmillisecond mDurationLimit; 769 SLmillisecond mPosition; 770 slRecordCallback mCallback; 771 void *mContext; 772 SLuint32 mCallbackEventsMask; 773 SLmillisecond mMarkerPosition; 774 SLmillisecond mPositionUpdatePeriod; 775} IRecord; 776 777typedef struct { 778 const struct SLSeekItf_ *mItf; 779 IObject *mThis; 780 SLmillisecond mPos; // mPos != SL_TIME_UNKNOWN means pending seek request 781 SLboolean mLoopEnabled; 782 SLmillisecond mStartPos; 783 SLmillisecond mEndPos; 784} ISeek; 785 786typedef struct { 787 const struct SLThreadSyncItf_ *mItf; 788 IObject *mThis; 789 SLboolean mInCriticalSection; 790 SLuint32 mWaiting; // number of threads waiting 791 pthread_t mOwner; 792} IThreadSync; 793 794typedef struct { 795 const struct SLVibraItf_ *mItf; 796 IObject *mThis; 797 SLboolean mVibrate; 798 SLmilliHertz mFrequency; 799 SLpermille mIntensity; 800} IVibra; 801 802typedef struct { 803 const struct SLVirtualizerItf_ *mItf; 804 IObject *mThis; 805 SLboolean mEnabled; 806 SLpermille mStrength; 807#if defined(ANDROID) && !defined(USE_BACKPORT) 808 effect_descriptor_t mVirtualizerDescriptor; 809 android::sp<android::AudioEffect> mVirtualizerEffect; 810#endif 811} IVirtualizer; 812 813 814typedef struct { 815 const struct SLVisualizationItf_ *mItf; 816 IObject *mThis; 817 slVisualizationCallback mCallback; 818 void *mContext; 819 SLmilliHertz mRate; 820} IVisualization; 821 822typedef struct /*Volume_interface*/ { 823 const struct SLVolumeItf_ *mItf; 824 IObject *mThis; 825 // Values as specified by the application 826 SLmillibel mLevel; 827 SLpermille mStereoPosition; 828 SLuint8 /*SLboolean*/ mMute; 829 SLuint8 /*SLboolean*/ mEnableStereoPosition; 830} IVolume; 831 832/* Class structures */ 833 834/*typedef*/ struct C3DGroup_struct { 835 IObject mObject; 836#define INTERFACES_3DGroup 6 // see MPH_to_3DGroup in MPH_to.c for list of interfaces 837 SLuint8 mInterfaceStates2[INTERFACES_3DGroup - INTERFACES_Default]; 838 IDynamicInterfaceManagement mDynamicInterfaceManagement; 839 I3DLocation m3DLocation; 840 I3DDoppler m3DDoppler; 841 I3DSource m3DSource; 842 I3DMacroscopic m3DMacroscopic; 843 unsigned mMemberMask; // set of member objects 844} /*C3DGroup*/; 845 846#ifdef ANDROID 847typedef struct { 848 const struct SLAndroidStreamTypeItf_ *mItf; 849 IObject *mThis; 850 SLuint32 mStreamType; 851} IAndroidStreamType; 852 853typedef struct { 854 const struct SLAndroidEffectItf_ *mItf; 855 IObject *mThis; 856 android::KeyedVector<SLuint32, android::AudioEffect* > mEffects; 857} IAndroidEffect; 858 859typedef struct { 860 const struct SLAndroidEffectCapabilitiesItf_ *mItf; 861 IObject *mThis; 862 SLuint32 mNumFx; 863 effect_descriptor_t* mFxDescriptors; 864} IAndroidEffectCapabilities; 865 866#if defined(ANDROID) && !defined(USE_BACKPORT) 867// FIXME this include is done here so the effect structures have been defined. Messy. 868#include "android_Effect.h" 869#endif 870 871 872/* 873 * Used to define the mapping from an OpenSL ES audio player to an Android 874 * media framework object 875 */ 876enum AndroidObject_type { 877 INVALID_TYPE =-1, 878 MEDIAPLAYER = 0, 879 AUDIOTRACK_PUSH = 1, 880 AUDIOTRACK_PULL = 2, 881 NUM_AUDIOPLAYER_MAP_TYPES 882}; 883 884enum AndroidObject_state { 885 ANDROID_UNINITIALIZED = -1, 886 ANDROID_PREPARING, 887 ANDROID_PREPARED, 888 ANDROID_PREFETCHING, 889 ANDROID_READY, 890 NUM_ANDROID_STATES 891}; 892#endif //ifdef ANDROID 893 894 895/*typedef*/ struct CAudioPlayer_struct { 896 IObject mObject; 897#ifdef ANDROID 898#define INTERFACES_AudioPlayer 28 // see MPH_to_AudioPlayer in MPH_to.c for list of interfaces 899#else 900#define INTERFACES_AudioPlayer 26 // see MPH_to_AudioPlayer in MPH_to.c for list of interfaces 901#endif 902 SLuint8 mInterfaceStates2[INTERFACES_AudioPlayer - INTERFACES_Default]; 903 IDynamicInterfaceManagement mDynamicInterfaceManagement; 904 IPlay mPlay; 905 I3DDoppler m3DDoppler; 906 I3DGrouping m3DGrouping; 907 I3DLocation m3DLocation; 908 I3DSource m3DSource; 909 IBufferQueue mBufferQueue; 910 IEffectSend mEffectSend; 911 IMetadataExtraction mMetadataExtraction; 912 IMetadataTraversal mMetadataTraversal; 913 IPrefetchStatus mPrefetchStatus; 914 IRatePitch mRatePitch; 915 ISeek mSeek; 916 IVolume mVolume; 917 IMuteSolo mMuteSolo; 918#ifdef ANDROID 919 IAndroidStreamType mAndroidStreamType; 920 IAndroidEffect mAndroidEffect; 921#endif 922 // optional interfaces 923 I3DMacroscopic m3DMacroscopic; 924 IBassBoost mBassBoost; 925 IDynamicSource mDynamicSource; 926 IEnvironmentalReverb mEnvironmentalReverb; 927 IEqualizer mEqualizer; 928 IPitch mPitch; 929 IPresetReverb mPresetReverb; 930 IPlaybackRate mPlaybackRate; 931 IVirtualizer mVirtualizer; 932 IVisualization mVisualization; 933 // rest of fields are not related to the interfaces 934 DataLocatorFormat mDataSource; 935 DataLocatorFormat mDataSink; 936 COutputMix *mOutputMix; // output mix this audio player is attached to, for effect send 937 // cached data for this instance 938 SLuint8 /*SLboolean*/ mMute; 939 // Formerly at IMuteSolo 940 SLuint8 mMuteMask; // Mask for which channels are muted: bit 0=left, 1=right 941 SLuint8 mSoloMask; // Mask for which channels are soloed: bit 0=left, 1=right 942 SLuint8 mNumChannels; // 0 means unknown, then const once it is known, range 1 <= x <= 8 943 SLuint32 mSampleRateMilliHz;// 0 means unknown, then const once it is known 944 // implementation-specific data for this instance 945#ifdef USE_OUTPUTMIXEXT 946 Track *mTrack; 947#endif 948#ifdef USE_SNDFILE 949 struct SndFile mSndFile; 950#endif // USE_SNDFILE 951#ifdef ANDROID 952 android::Mutex *mpLock; 953 enum AndroidObject_type mAndroidObjType; 954 enum AndroidObject_state mAndroidObjState; 955 android::AudioTrack *mAudioTrack; 956#ifndef USE_BACKPORT 957 android::sp<android::SfPlayer> mSfPlayer; 958 android::sp<android::ALooper> mRenderLooper; 959#endif 960 /** 961 * Amplification (can be attenuation) factor derived for the VolumeLevel 962 */ 963 float mAmplFromVolLevel; 964 /** 965 * Left/right amplification (can be attenuations) factors derived for the StereoPosition 966 */ 967 float mAmplFromStereoPos[STEREO_CHANNELS]; 968 /** 969 * Attenuation factor derived from direct level in EffectSend 970 */ 971 float mAmplFromDirectLevel; 972#endif 973} /*CAudioPlayer*/; 974 975 976/*typedef*/ struct CAudioRecorder_struct { 977 // mandated interfaces 978 IObject mObject; 979#ifdef ANDROID 980#define INTERFACES_AudioRecorder 10 // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces 981#else 982#define INTERFACES_AudioRecorder 9 // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces 983#endif 984 SLuint8 mInterfaceContinued[INTERFACES_AudioRecorder - INTERFACES_Default]; 985 IDynamicInterfaceManagement mDynamicInterfaceManagement; 986 IRecord mRecord; 987 IAudioEncoder mAudioEncoder; 988 // optional interfaces 989 IBassBoost mBassBoost; 990 IDynamicSource mDynamicSource; 991 IEqualizer mEqualizer; 992 IVisualization mVisualization; 993 IVolume mVolume; 994#ifdef ANDROID 995 IBufferQueue mBufferQueue; 996#endif 997 // rest of fields are not related to the interfaces 998 DataLocatorFormat mDataSource; 999 DataLocatorFormat mDataSink; 1000 // cached data for this instance 1001 SLuint8 mNumChannels; // 0 means unknown, then const once it is known, range 1 <= x <= 8 1002 SLuint32 mSampleRateMilliHz;// 0 means unknown, then const once it is known 1003 // implementation-specific data for this instance 1004#ifdef ANDROID 1005 android::AudioRecord *mAudioRecord; 1006#endif 1007} /*CAudioRecorder*/; 1008 1009 1010typedef struct { 1011 // mandated implicit interfaces 1012 IObject mObject; 1013#ifdef ANDROID 1014#define INTERFACES_Engine 11 // see MPH_to_Engine in MPH_to.c for list of interfaces 1015#else 1016#define INTERFACES_Engine 10 // see MPH_to_Engine in MPH_to.c for list of interfaces 1017#endif 1018 SLuint8 mInterfaceStates2[INTERFACES_Engine - INTERFACES_Default]; 1019 IDynamicInterfaceManagement mDynamicInterfaceManagement; 1020 IEngine mEngine; 1021 IEngineCapabilities mEngineCapabilities; 1022 IThreadSync mThreadSync; 1023 // mandated explicit interfaces 1024 IAudioIODeviceCapabilities mAudioIODeviceCapabilities; 1025 IAudioDecoderCapabilities mAudioDecoderCapabilities; 1026 IAudioEncoderCapabilities mAudioEncoderCapabilities; 1027 I3DCommit m3DCommit; 1028 IAndroidEffectCapabilities mAndroidEffectCapabilities; 1029 // optional interfaces 1030 IDeviceVolume mDeviceVolume; 1031 // rest of fields are not related to the interfaces 1032 pthread_t mSyncThread; 1033} CEngine; 1034 1035typedef struct { 1036 // mandated interfaces 1037 IObject mObject; 1038#define INTERFACES_LEDDevice 3 // see MPH_to_LEDDevice in MPH_to.c for list of interfaces 1039 SLuint8 mInterfaceStates2[INTERFACES_LEDDevice - INTERFACES_Default]; 1040 IDynamicInterfaceManagement mDynamicInterfaceManagement; 1041 ILEDArray mLEDArray; 1042 SLuint32 mDeviceID; 1043} CLEDDevice; 1044 1045typedef struct { 1046 // mandated interfaces 1047 IObject mObject; 1048#define INTERFACES_Listener 4 // see MPH_to_Listener in MPH_to.c for list of interfaces 1049 SLuint8 mInterfaceStates2[INTERFACES_Listener - INTERFACES_Default]; 1050 IDynamicInterfaceManagement mDynamicInterfaceManagement; 1051 I3DDoppler m3DDoppler; 1052 I3DLocation m3DLocation; 1053} CListener; 1054 1055typedef struct { 1056 // mandated interfaces 1057 IObject mObject; 1058#define INTERFACES_MetadataExtractor 5 // see MPH_to_MetadataExtractor in MPH_to.c for list of 1059 // interfaces 1060 SLuint8 mInterfaceStates2[INTERFACES_MetadataExtractor - INTERFACES_Default]; 1061 IDynamicInterfaceManagement mDynamicInterfaceManagement; 1062 IDynamicSource mDynamicSource; 1063 IMetadataExtraction mMetadataExtraction; 1064 IMetadataTraversal mMetadataTraversal; 1065} CMetadataExtractor; 1066 1067typedef struct { 1068 // mandated interfaces 1069 IObject mObject; 1070#ifdef ANDROID 1071#define INTERFACES_MidiPlayer 30 // see MPH_to_MidiPlayer in MPH_to.c for list of interfaces 1072#else 1073#define INTERFACES_MidiPlayer 29 // see MPH_to_MidiPlayer in MPH_to.c for list of interfaces 1074#endif 1075 SLuint8 mInterfaceStates2[INTERFACES_MidiPlayer - INTERFACES_Default]; 1076 IDynamicInterfaceManagement mDynamicInterfaceManagement; 1077 IPlay mPlay; 1078 I3DDoppler m3DDoppler; 1079 I3DGrouping m3DGrouping; 1080 I3DLocation m3DLocation; 1081 I3DSource m3DSource; 1082 IBufferQueue mBufferQueue; 1083 IEffectSend mEffectSend; 1084 IMetadataExtraction mMetadataExtraction; 1085 IMetadataTraversal mMetadataTraversal; 1086 IMIDIMessage mMIDIMessage; 1087 IMIDITime mMIDITime; 1088 IMIDITempo mMIDITempo; 1089 IMIDIMuteSolo mMIDIMuteSolo; 1090 IPrefetchStatus mPrefetchStatus; 1091 ISeek mSeek; 1092 IVolume mVolume; 1093 IMuteSolo mMuteSolo; 1094#ifdef ANDROID 1095 IAndroidStreamType mAndroidStreamType; 1096#endif 1097 // optional interfaces 1098 I3DMacroscopic m3DMacroscopic; 1099 IBassBoost mBassBoost; 1100 IDynamicSource mDynamicSource; 1101 IEnvironmentalReverb mEnvironmentalReverb; 1102 IEqualizer mEqualizer; 1103 IPitch mPitch; 1104 IPresetReverb mPresetReverb; 1105 IPlaybackRate mPlaybackRate; 1106 IVirtualizer mVirtualizer; 1107 IVisualization mVisualization; 1108} CMidiPlayer; 1109 1110/*typedef*/ struct COutputMix_struct { 1111 // mandated interfaces 1112 IObject mObject; 1113#define INTERFACES_OutputMix 11 // see MPH_to_OutputMix in MPH_to.c for list of interfaces 1114 SLuint8 mInterfaceStates2[INTERFACES_OutputMix - INTERFACES_Default]; 1115 IDynamicInterfaceManagement mDynamicInterfaceManagement; 1116 IOutputMix mOutputMix; 1117#ifdef USE_OUTPUTMIXEXT 1118 IOutputMixExt mOutputMixExt; 1119#endif 1120 IEnvironmentalReverb mEnvironmentalReverb; 1121 IEqualizer mEqualizer; 1122 IPresetReverb mPresetReverb; 1123 IVirtualizer mVirtualizer; 1124 IVolume mVolume; 1125 // optional interfaces 1126 IBassBoost mBassBoost; 1127 IVisualization mVisualization; 1128 // implementation-specific data for this instance 1129#ifdef ANDROID 1130#endif 1131} /*COutputMix*/; 1132 1133typedef struct { 1134 // mandated interfaces 1135 IObject mObject; 1136#define INTERFACES_VibraDevice 3 // see MPH_to_VibraDevice in MPH_to.c for list of interfaces 1137 SLuint8 mInterfaceStates2[INTERFACES_VibraDevice - INTERFACES_Default]; 1138 IDynamicInterfaceManagement mDynamicInterfaceManagement; 1139 IVibra mVibra; 1140 // 1141 SLuint32 mDeviceID; 1142} CVibraDevice; 1143 1144struct MPH_init { 1145 // unsigned char mMPH; 1146 VoidHook mInit; 1147 VoidHook mResume; 1148 VoidHook mDeinit; 1149}; 1150 1151extern /*static*/ int IID_to_MPH(const SLInterfaceID iid); 1152extern /*static*/ const struct MPH_init MPH_init_table[MPH_MAX]; 1153extern SLresult checkInterfaces(const ClassTable *class__, 1154 SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, 1155 const SLboolean *pInterfaceRequired, unsigned *pExposedMask); 1156extern IObject *construct(const ClassTable *class__, 1157 unsigned exposedMask, SLEngineItf engine); 1158extern const ClassTable *objectIDtoClass(SLuint32 objectID); 1159extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX]; 1160extern SLuint32 IObjectToObjectID(IObject *object); 1161 1162// Map an interface to it's "object ID" (which is really a class ID). 1163// Note: this operation is undefined on IObject, as it lacks an mThis. 1164// If you have an IObject, then use IObjectToObjectID directly. 1165 1166#define InterfaceToObjectID(this) IObjectToObjectID((this)->mThis) 1167 1168// Map an interface to it's corresponding IObject. 1169// Note: this operation is undefined on IObject, as it lacks an mThis. 1170// If you have an IObject, then you're done -- you already have what you need. 1171 1172#define InterfaceToIObject(this) ((this)->mThis) 1173 1174#define InterfaceToCAudioPlayer(this) (((CAudioPlayer*)InterfaceToIObject(this))) 1175 1176#define InterfaceToCAudioRecorder(this) (((CAudioRecorder*)InterfaceToIObject(this))) 1177 1178#ifdef ANDROID 1179#include "android_AudioPlayer.h" 1180#endif 1181 1182extern SLresult checkDataSource(const SLDataSource *pDataSrc, 1183 DataLocatorFormat *myDataSourceLocator); 1184extern SLresult checkDataSink(const SLDataSink *pDataSink, DataLocatorFormat *myDataSinkLocator, 1185 SLuint32 objType); 1186extern SLresult checkSourceFormatVsInterfacesCompatibility( 1187 const DataLocatorFormat *pDataLocatorFormat, 1188 SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, 1189 const SLboolean *pInterfaceRequired); 1190extern void freeDataLocatorFormat(DataLocatorFormat *dlf); 1191 1192extern SLresult CAudioPlayer_Realize(void *self, SLboolean async); 1193extern void CAudioPlayer_Destroy(void *self); 1194 1195extern SLresult CAudioRecorder_Realize(void *self, SLboolean async); 1196extern SLresult CAudioRecorder_Resume(void *self, SLboolean async); 1197extern void CAudioRecorder_Destroy(void *self); 1198 1199extern SLresult CEngine_Realize(void *self, SLboolean async); 1200extern void CEngine_Destroy(void *self); 1201 1202extern SLresult COutputMix_Realize(void *self, SLboolean async); 1203extern SLresult COutputMix_Resume(void *self, SLboolean async); 1204extern void COutputMix_Destroy(void *self); 1205 1206#ifdef USE_SDL 1207extern void SDL_open(IEngine *thisEngine); 1208extern void SDL_close(void); 1209#endif 1210#define SL_OBJECT_STATE_REALIZING_1 ((SLuint32) 0x4) // async realize on work queue 1211#define SL_OBJECT_STATE_REALIZING_2 ((SLuint32) 0x5) // sync realize, or async realize hook 1212#define SL_OBJECT_STATE_RESUMING_1 ((SLuint32) 0x6) // async resume on work queue 1213#define SL_OBJECT_STATE_RESUMING_2 ((SLuint32) 0x7) // sync resume, or async resume hook 1214#define SL_OBJECT_STATE_SUSPENDING ((SLuint32) 0x8) // suspend in progress 1215#define SL_OBJECT_STATE_REALIZING_1A ((SLuint32) 0x9) // abort while async realize on work queue 1216#define SL_OBJECT_STATE_RESUMING_1A ((SLuint32) 0xA) // abort while async resume on work queue 1217extern void *sync_start(void *arg); 1218extern SLresult err_to_result(int err); 1219 1220#ifdef __GNUC__ 1221#define ctz __builtin_ctz 1222#else 1223extern unsigned ctz(unsigned); 1224#endif 1225extern const char * const interface_names[MPH_MAX]; 1226#include "platform.h" 1227 1228// Attributes 1229 1230#define ATTR_NONE ((unsigned) 0x0) // none 1231#define ATTR_GAIN ((unsigned) 0x1 << 0) // player volume, channel mute, channel solo, 1232 // player stereo position, player mute 1233#define ATTR_TRANSPORT ((unsigned) 0x1 << 1) // play state, looping 1234#define ATTR_POSITION ((unsigned) 0x1 << 2) // requested position (a.k.a. seek position) 1235#define ATTR_ENQUEUE ((unsigned) 0x1 << 3) // buffer queue became non-empty and in playing state 1236 1237#define SL_DATALOCATOR_NULL 0 // application specified a NULL value for pLocator 1238#define SL_DATAFORMAT_NULL 0 // application specified a NULL or undefined value for pFormat 1239 1240// Trace debugging 1241 1242// Always defined, but may be a no-op if trace support is disabled at compile-time 1243extern void slTraceSetEnabled(unsigned enabled); 1244 1245#define SL_TRACE_ENTER 0x1 1246#define SL_TRACE_LEAVE_FAILURE 0x2 1247#define SL_TRACE_LEAVE_VOID 0x4 1248#define SL_TRACE_LEAVE_SUCCESS 0x8 1249#define SL_TRACE_LEAVE (SL_TRACE_LEAVE_FAILURE | SL_TRACE_LEAVE_VOID | \ 1250 SL_TRACE_LEAVE_SUCCESS) 1251#define SL_TRACE_ALL (SL_TRACE_ENTER | SL_TRACE_LEAVE) 1252#define SL_TRACE_DEFAULT (SL_TRACE_LEAVE_FAILURE) 1253 1254#ifndef USE_TRACE 1255 1256#define SL_ENTER_GLOBAL SLresult result; 1257#define SL_LEAVE_GLOBAL return result; 1258#define SL_ENTER_INTERFACE SLresult result; 1259#define SL_LEAVE_INTERFACE return result; 1260#define SL_ENTER_INTERFACE_VOID 1261#define SL_LEAVE_INTERFACE_VOID return; 1262 1263#else 1264 1265extern void slTraceEnterGlobal(const char *function); 1266extern void slTraceLeaveGlobal(const char *function, SLresult result); 1267extern void slTraceEnterInterface(const char *function); 1268extern void slTraceLeaveInterface(const char *function, SLresult result); 1269extern void slTraceEnterInterfaceVoid(const char *function); 1270extern void slTraceLeaveInterfaceVoid(const char *function); 1271#define SL_ENTER_GLOBAL SLresult result; slTraceEnterGlobal(__FUNCTION__); 1272#define SL_LEAVE_GLOBAL slTraceLeaveGlobal(__FUNCTION__, result); return result; 1273#define SL_ENTER_INTERFACE SLresult result; slTraceEnterInterface(__FUNCTION__); 1274#define SL_LEAVE_INTERFACE slTraceLeaveInterface(__FUNCTION__, result); return result; 1275#define SL_ENTER_INTERFACE_VOID slTraceEnterInterfaceVoid(__FUNCTION__); 1276#define SL_LEAVE_INTERFACE_VOID slTraceLeaveInterfaceVoid(__FUNCTION__); return; 1277 1278#endif 1279 1280#ifdef USE_DEBUG 1281#define SL_LOGE(...) do { fprintf(stderr, "ERROR: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ 1282 fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) 1283#define SL_LOGV(...) do { fprintf(stderr, "VERBOSE: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ 1284 fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) 1285#else 1286#define SL_LOGE(...) do { } while (0) 1287#define SL_LOGV(...) do { } while (0) 1288#endif 1289 1290#ifdef USE_OUTPUTMIXEXT 1291 1292#define SL_PLAYSTATE_STOPPING ((SLuint32) 0x4) // Play::Stop while PLAYING 1293// If we needed it, could have PLAYING mean mixer is currently reading from front buffer, 1294// while PLAYABLE would mean application requested PLAYING, but buffer queue is empty 1295 1296#endif 1297 1298#ifdef USE_SNDFILE 1299extern void audioPlayerTransportUpdate(CAudioPlayer *audioPlayer); 1300#endif 1301#ifdef ANDROID 1302extern SLresult android_audioPlayerClear(CAudioPlayer *pAudioPlayer); 1303#endif 1304 1305extern SLresult IBufferQueue_Enqueue(SLBufferQueueItf self, const void *pBuffer, SLuint32 size); 1306extern SLresult IBufferQueue_Clear(SLBufferQueueItf self); 1307extern SLresult IBufferQueue_RegisterCallback(SLBufferQueueItf self, 1308 slBufferQueueCallback callback, void *pContext); 1309 1310extern bool IsInterfaceInitialized(IObject *this, unsigned MPH); 1311