Files
UnrealEngineUWP/Engine/Source/Runtime/Android/AndroidAudio/Public/AndroidAudioDevice.h
Matthew Griffin 27ea06992a Merging //UE4/Release-4.11 to //UE4/Main (Up to CL#2909747)
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2898120 on 2016/03/07 by Chris.Babcock

	Disable NvTimerQuery on Nexus 9 before Android 6.0 to fix slow frame updates
	#jira UE-28013
	#ue4
	#android

Change 2898539 on 2016/03/08 by Matthew.Griffin

	Merging //UE4/Dev-Build to //UE4/Release-4.11

	Change 2887414 on 2016/03/01 by Ben.Marsh

		Dump all the *.crash files produced while running commandlets, to make it easier to diagnose build system crashes cooking on Mac.

Change 2898788 on 2016/03/08 by Keith.Judge

	Latest DX12.x integration from Microsoft. Brings XB1 up to PC level of functionality and improved perf.

	#jira UEPLAT-325

Change 2898836 on 2016/03/08 by Taizyd.Korambayil

	#jira UE-27990 Reimported River_Basin_02 Mesh with Adjacency Buffer

Change 2898897 on 2016/03/08 by Sean.Gribbin

	#Jira UE-26550

	Adding name to credits of Match 3

Change 2898938 on 2016/03/08 by Taizyd.Korambayil

	#jira UE-26284 Fixed Up Some Materials and BP errors

Change 2898967 on 2016/03/08 by Benjamin.Hyder

	Updating Qa_Materials map
	#jira UE-24473

Change 2899032 on 2016/03/08 by Zachary.Wilson

	Fixing broken assets in QA-LightsStationary and eliminating log errors. Fixing mispelling and player start height in QA-LightsStationary.
	#jira UE-24473

Change 2899244 on 2016/03/08 by Peter.Sauerbrei

	addition of launch images for iPad Pro
	#jira UE-24793

Change 2899335 on 2016/03/08 by Richard.Hinckley

	#jira UE-27356
	Fixing code for VR headsets so that the camera starts inside the vehicle if the user has an active HMD. Found that the C++ templates never had HMD support, so mirroring the BP templates for that functionality. Works in my testing, but a proper QA pass should be performed.

Change 2899402 on 2016/03/08 by Michael.Schoell

	Macro instance nodes now have a hard dependency to any object class or structs their pins reference.

	Expanded UK2Node_MacroInstance::HasExternalDependencies to iterate over all pins and add their struct or object's class.

	#jira UE-27795 - Split Pins on a referenced Macro Library will crash the editor on restart

Change 2899424 on 2016/03/08 by Dmitry.Rekman

	Fix CrossCompilerTool on Linux (UE-28056).

	#jira UE-28056

Change 2899445 on 2016/03/08 by Dmitry.Rekman

	Fix CrossCompilerTool invocation in debug scripts.

	#jira UE-28056

Change 2899488 on 2016/03/08 by Ryan.Vance

	#jira UE-28000
	We can't test how many views are in the view family when initializing a view. There's no guaruntee that the family is setup yet. We'll need to move this test to the calling code.

Change 2899546 on 2016/03/08 by Zachary.Wilson

	Updating QA-PostProcessing to match the 4.12 Main version of the map.
	#jira UE-24473

Change 2899553 on 2016/03/08 by Michael.Schoell

	Reinstancer will no longer queue BPs to be saved when compiling skeleton class dependencies and will no longer process all queued BPs to save when it is complete.

	#jira UE-27509 - Save on compile set to always causes a crash on compile
	#jira UE-27856 - "Always" Save on Compile does not save the Blueprint

Change 2899558 on 2016/03/08 by Benjamin.Hyder

	building Lighting for QA-Materials
	#jira UE-24473

Change 2899597 on 2016/03/08 by Chris.Babcock

	Change reporting level of audio buffer decompression type logging
	#jira UE-28058
	#ue4
	#android

Change 2899704 on 2016/03/08 by Benjamin.Hyder

	Updating Qa-Materials map
	#Jira UE-24473

Change 2899736 on 2016/03/08 by Benjamin.Hyder

	Updating TM-LPV map
	#Jira UE-24473

Change 2899810 on 2016/03/08 by Lauren.Ridge

	#jira UE-27995 UE-27987

	Final UM3 UI Tweaks, + bug fix

Change 2899876 on 2016/03/08 by Peter.Sauerbrei

[CL 2913181 by Matthew Griffin in Main branch]
2016-03-17 11:10:14 -04:00

326 lines
8.6 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#pragma once
/*------------------------------------------------------------------------------------
Dependencies, helpers & forward declarations.
------------------------------------------------------------------------------------*/
class FSLESAudioDevice;
#include "Core.h"
#include "Engine.h"
#include "SoundDefinitions.h"
#include "AudioDecompress.h"
#include "AudioEffect.h"
#include <SLES/OpenSLES.h>
#include "SLES/OpenSLES_Android.h"
DECLARE_LOG_CATEGORY_EXTERN(LogAndroidAudio,Log,VeryVerbose);
enum ESoundFormat
{
SoundFormat_Invalid,
SoundFormat_PCM,
SoundFormat_PCMRT
};
struct SLESAudioBuffer
{
uint8 *AudioData;
int32 AudioDataSize;
int32 ReadCursor;
};
/**
* OpenSLES implementation of FSoundBuffer, containing the wave data and format information.
*/
class FSLESSoundBuffer : public FSoundBuffer
{
public:
/**
* Constructor
*
* @param AudioDevice audio device this sound buffer is going to be attached to.
*/
FSLESSoundBuffer( FSLESAudioDevice* AudioDevice );
/**
* Destructor
*
* Frees wave data and detaches itself from audio device.
*/
~FSLESSoundBuffer( void );
/**
* Static function used to create a buffer and dynamically upload decompressed ogg vorbis data to.
*
* @param InWave USoundWave to use as template and wave source
* @param AudioDevice audio device to attach created buffer to
* @return FSLESSoundBuffer pointer if buffer creation succeeded, NULL otherwise
*/
static FSLESSoundBuffer* CreateQueuedBuffer( FSLESAudioDevice* AudioDevice, USoundWave* Wave );
/**
* Static function used to create an Audio buffer and upload decompressed ogg vorbis data to.
*
* @param Wave USoundWave to use as template and wave source
* @param AudioDevice audio device to attach created buffer to
* @return FSLESSoundBuffer pointer if buffer creation succeeded, NULL otherwise
*/
static FSLESSoundBuffer* CreateNativeBuffer( FSLESAudioDevice* AudioDevice, USoundWave* Wave );
/**
* Static function used to create an Audio buffer and dynamically upload procedural data to.
*
* @param InWave USoundWave to use as template and wave source
* @param AudioDevice audio device to attach created buffer to
* @return FSLESSoundBuffer pointer if buffer creation succeeded, NULL otherwise
*/
static FSLESSoundBuffer* CreateProceduralBuffer(FSLESAudioDevice* AudioDevice, USoundWave* Wave);
/**
* Static function used to create a buffer.
*
* @param InWave USoundWave to use as template and wave source
* @param AudioDevice Audio device to attach created buffer to
* @return FSLESSoundBuffer pointer if buffer creation succeeded, NULL otherwise
*/
static FSLESSoundBuffer* Init( FSLESAudioDevice* ,USoundWave* );
/**
* Decompresses a chunk of compressed audio to the destination memory
*
* @param Destination Memory to decompress to
* @param bLooping Whether to loop the sound seamlessly, or pad with zeroes
* @return Whether the sound looped or not
*/
bool ReadCompressedData( uint8* Destination, bool bLooping );
/**
* Sets the point in time within the buffer to the specified time
* If the time specified is beyond the end of the sound, it will be set to the end
*
* @param SeekTime Time in seconds from the beginning of sound to seek to
*/
void Seek(const float SeekTime);
/**
* Returns the size of this buffer in bytes.
*
* @return Size in bytes
*/
int GetSize( void )
{
return( BufferSize );
}
/**
* Returns the size for a real time/streaming buffer based on decompressor
*/
int GetRTBufferSize(void);
/** Audio device this buffer is attached to */
FSLESAudioDevice* AudioDevice;
/** Data */
uint8* AudioData;
/** Number of bytes stored in OpenAL, or the size of the ogg vorbis data */
int BufferSize;
/** Sample rate of the ogg vorbis data - typically 44100 or 22050 */
int SampleRate;
/** Wrapper to handle the decompression of audio codecs */
class ICompressedAudioInfo* DecompressionState;
/** Format of data to be received by the source */
ESoundFormat Format;
};
typedef FAsyncTask<FAsyncRealtimeAudioTaskWorker<FSLESSoundBuffer>> FAsyncRealtimeAudioTask;
/**
* OpenSLES implementation of FSoundSource, the interface used to play, stop and update sources
*/
class FSLESSoundSource : public FSoundSource
{
public:
/**
* Constructor
*
* @param InAudioDevice audio device this source is attached to
*/
FSLESSoundSource( class FAudioDevice* InAudioDevice );
/**
* Destructor
*/
~FSLESSoundSource( void );
/**
* Initializes a source with a given wave instance and prepares it for playback.
*
* @param WaveInstance wave instance being primed for playback
* @return TRUE if initialization was successful, FALSE otherwise
*/
virtual bool Init( FWaveInstance* WaveInstance );
/**
* Updates the source specific parameter like e.g. volume and pitch based on the associated
* wave instance.
*/
virtual void Update( void );
/**
* Plays the current wave instance.
*/
virtual void Play( void );
/**
* Stops the current wave instance and detaches it from the source.
*/
virtual void Stop( void );
/**
* Pauses playback of current wave instance.
*/
virtual void Pause( void );
/**
* Queries the status of the currently associated wave instance.
*
* @return TRUE if the wave instance/ source has finished playback and FALSE if it is
* currently playing or paused.
*/
virtual bool IsFinished( void );
/**
* Returns TRUE if source has finished playing
*/
bool IsSourceFinished( void );
/**
* Used to requeue a looping sound when the completion callback fires.
*
*/
void OnRequeueBufferCallback( SLAndroidSimpleBufferQueueItf InQueueInterface );
protected:
enum class EDataReadMode : uint8
{
Synchronous,
Asynchronous,
AsynchronousSkipFirstFrame
};
friend class FSLESAudioDevice;
FSLESSoundBuffer* Buffer;
FSLESAudioDevice* Device;
// OpenSL interface objects
SLObjectItf SL_PlayerObject;
SLPlayItf SL_PlayerPlayInterface;
SLAndroidSimpleBufferQueueItf SL_PlayerBufferQueue;
SLVolumeItf SL_VolumeInterface;
FAsyncRealtimeAudioTask* RealtimeAsyncTask;
/** Which sound buffer should be written to next - used for double buffering. */
bool bStreamedSound;
/** A pair of sound buffers for real-time decoding */
SLESAudioBuffer AudioBuffers[2];
/** Set when we wish to let the buffers play themselves out */
bool bBuffersToFlush;
uint32 BufferSize;
int32 BufferInUse;
float VolumePreviousUpdate;
bool bHasLooped;
bool CreatePlayer();
void DestroyPlayer();
void ReleaseResources();
bool EnqueuePCMBuffer( bool bLoop);
bool EnqueuePCMRTBuffer( bool bLoop);
/** Decompress through FSLESSoundBuffer, or call USoundWave procedure to generate more PCM data. Returns true/false: did audio loop? */
bool ReadMorePCMData( const int32 BufferIndex, EDataReadMode DataReadMode );
};
/**
* OpenSLES implementation of an Unreal audio device.
*/
class FSLESAudioDevice : public FAudioDevice
{
public:
FSLESAudioDevice() {}
virtual ~FSLESAudioDevice() {}
virtual FName GetRuntimeFormat(USoundWave* SoundWave) override
{
if (SoundWave->CompressionName.IsNone())
{
#if WITH_OGGVORBIS
static FName NAME_OGG(TEXT("OGG")); //@todo android: probably not ogg
return NAME_OGG;
#else
static FName NAME_ADPCM(TEXT("ADPCM"));
return NAME_ADPCM;
#endif
}
return SoundWave->CompressionName;
}
virtual bool HasCompressedAudioInfoClass(USoundWave* SoundWave) override;
virtual bool SupportsRealtimeDecompression() const override
{
return true;
}
virtual class ICompressedAudioInfo* CreateCompressedAudioInfo(USoundWave* SoundWave) override;
/** Starts up any platform specific hardware/APIs */
virtual bool InitializeHardware() override;
/** Check if any background music or sound is playing through the audio device */
virtual bool IsExernalBackgroundSoundActive() override;
protected:
virtual FSoundSource* CreateSoundSource() override;
/**
* Tears down audio device by stopping all sounds, removing all buffers, destroying all sources, ... Called by both Destroy and ShutdownAfterError
* to perform the actual tear down.
*/
void Teardown( void );
// Variables.
/** The name of the OpenSL Device to open - defaults to "Generic Software" */
FString DeviceName;
// SL specific
// engine interfaces
SLObjectItf SL_EngineObject;
SLEngineItf SL_EngineEngine;
SLObjectItf SL_OutputMixObject;
SLint32 SL_VolumeMax;
SLint32 SL_VolumeMin;
friend class FSLESSoundBuffer;
friend class FSLESSoundSource;
};