19#include <Guid/GlobalVariable.h>
22#include <Library/BaseLib.h>
23#include <Library/DebugLib.h>
24#include <Library/DevicePathLib.h>
25#include <Library/MemoryAllocationLib.h>
45#include <Library/PrintLib.h>
46#include <Library/UefiBootServicesTableLib.h>
47#include <Library/UefiLib.h>
48#include <Library/UefiRuntimeServicesTableLib.h>
61 IN CONST CHAR8 *BasePath,
62 IN CONST CHAR8 *BaseType,
64 IN CONST CHAR8 *Extension,
66 OUT UINT32 *BufferSize
83 ASSERT_EFI_ERROR (Status);
95 ASSERT_EFI_ERROR (Status);
110 ASSERT_EFI_ERROR (Status);
138 IN CONST CHAR8 *BasePath,
139 IN CONST CHAR8 *BaseType,
140 IN BOOLEAN Localised,
143 OUT UINT32 *BufferSize,
152 UINT32 FileBufferSize;
154 if ((BasePath == NULL) || (BaseType == NULL) || (
Buffer == NULL) || (*
Buffer == NULL)) {
155 DEBUG ((DEBUG_ERROR,
"OC: Illegal wave parameters\n"));
156 return EFI_INVALID_PARAMETER;
170 if (FileBuffer == NULL) {
182 if (FileBuffer == NULL) {
183 DEBUG ((DEBUG_INFO,
"OC: Wave %a %a cannot be found!\n", BaseType, BasePath));
184 return EFI_NOT_FOUND;
200 FreePool (FileBuffer);
202 if (EFI_ERROR (Status)) {
203 DEBUG ((DEBUG_INFO,
"OC: Wave %a %a cannot be decoded - %r!\n", BaseType, BasePath, Status));
204 return EFI_UNSUPPORTED;
225 IN CONST CHAR8 *Control
232 if ((Control[0] ==
'\0') || (AsciiStrCmp (Control,
"Auto") == 0)) {
234 Size =
sizeof (Muted);
235 Status =
gRT->GetVariable (
242 DEBUG ((DEBUG_INFO,
"OC: Using StartupMute %d for chime - %r\n", Muted, Status));
246 if (AsciiStrCmp (Control,
"Enabled") == 0) {
270 IN OC_GLOBAL_CONFIG *Config
274 CHAR8 *AsciiDevicePath;
275 CHAR16 *UnicodeDevicePath;
276 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
281 BOOLEAN TryConversion;
283 if (Config->Uefi.Audio.ResetTrafficClass) {
287 if (!Config->Uefi.Audio.AudioSupport) {
288 DEBUG ((DEBUG_INFO,
"OC: Requested not to use audio\n"));
292 Status =
gBS->LocateProtocol (
297 if (EFI_ERROR (Status)) {
298 DEBUG ((DEBUG_INFO,
"OC: Cannot locate audio decoder protocol - %r\n", Status));
303 AsciiDevicePath =
OC_BLOB_GET (&Config->Uefi.Audio.AudioDevice);
304 if (AsciiDevicePath[0] !=
'\0') {
306 if (UnicodeDevicePath != NULL) {
307 DevicePath = ConvertTextToDevicePath (UnicodeDevicePath);
308 FreePool (UnicodeDevicePath);
311 if (DevicePath == NULL) {
312 DEBUG ((DEBUG_INFO,
"OC: Requested to use invalid audio device\n"));
322 if (OcAudio == NULL) {
323 DEBUG ((DEBUG_INFO,
"OC: Cannot locate OcAudio protocol\n"));
324 if (DevicePath != NULL) {
325 FreePool (DevicePath);
334 Config->Uefi.Audio.AudioCodec,
335 Config->Uefi.Audio.AudioOutMask
338 if (DevicePath != NULL) {
339 FreePool (DevicePath);
342 if (EFI_ERROR (Status)) {
343 DEBUG ((DEBUG_INFO,
"OC: Audio connection failed - %r\n", Status));
365 if (DecibelGain > Config->Uefi.Audio.MaximumGain) {
368 "OC: Limiting gain %d dB -> %d dB\n",
370 Config->Uefi.Audio.MaximumGain
372 DecibelGain = Config->Uefi.Audio.MaximumGain;
380 DecibelGain < Config->Uefi.Audio.MinimumAssistGain
381 ? Config->Uefi.Audio.MinimumAssistGain : DecibelGain
390 if (EFI_ERROR (Status)) {
391 DEBUG ((DEBUG_INFO,
"OC: Audio cannot set storage provider - %r\n", Status));
397 Config->Uefi.Audio.SetupDelay
403 && (DecibelGain >= Config->Uefi.Audio.MinimumAudibleGain)
406 DEBUG ((DEBUG_INFO,
"OC: Starting to play chime...\n"));
416 DEBUG ((DEBUG_INFO,
"OC: Play chime started - %r\n", Status));
EFI_GUID gAppleBootVariableGuid
#define APPLE_STARTUP_MUTE_VARIABLE_NAME
APPLE_VOICE_OVER_LANGUAGE_CODE
@ AppleVoiceOverLanguageEn
en
EFI_GUID gEfiAudioDecodeProtocolGuid
EFI_AUDIO_IO_PROTOCOL_FREQ
EFI_AUDIO_IO_PROTOCOL_BITS
DMG_FILEPATH_DEVICE_PATH FilePath
DMG_SIZE_DEVICE_PATH Size
#define OC_VOICE_OVER_AUDIO_FILE_VOICE_OVER_BOOT
#define OC_VOICE_OVER_AUDIO_BASE_TYPE_OPEN_CORE
VOID OcGetAmplifierGain(OUT UINT8 *RawGain, OUT INT8 *DecibelGain, OUT BOOLEAN *Muted, OUT BOOLEAN *TryConversion)
CONST CHAR8 * OcLanguageCodeToString(IN APPLE_VOICE_OVER_LANGUAGE_CODE LanguageCode)
OC_AUDIO_PROTOCOL * OcAudioInstallProtocols(IN BOOLEAN Reinstall, IN BOOLEAN DisconnectHda)
EFI_STATUS OcSetVoiceOverLanguage(CONST CHAR8 *Language OPTIONAL)
#define OPEN_CORE_AUDIO_PATH
VOID ResetAudioTrafficClass(VOID)
VOID OcScheduleExitBootServices(IN EFI_EVENT_NOTIFY Handler, IN VOID *Context)
BOOLEAN OcStorageExistsFileUnicode(IN OC_STORAGE_CONTEXT *Context, IN CONST CHAR16 *FilePath)
VOID * OcStorageReadFileUnicode(IN OC_STORAGE_CONTEXT *Context, IN CONST CHAR16 *FilePath, OUT UINT32 *FileSize OPTIONAL)
#define OC_STORAGE_SAFE_PATH_MAX
CHAR16 * AsciiStrCopyToUnicode(IN CONST CHAR8 *String, IN UINTN Length)
EFI_STATUS EFIAPI OcUnicodeSafeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
#define OC_BLOB_GET(Blob)
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
STATIC EFI_STATUS EFIAPI OcAudioAcquireFile(IN VOID *Context, IN CONST CHAR8 *BasePath, IN CONST CHAR8 *BaseType, IN BOOLEAN Localised, IN APPLE_VOICE_OVER_LANGUAGE_CODE LanguageCode, OUT UINT8 **Buffer, OUT UINT32 *BufferSize, OUT EFI_AUDIO_IO_PROTOCOL_FREQ *Frequency, OUT EFI_AUDIO_IO_PROTOCOL_BITS *Bits, OUT UINT8 *Channels)
STATIC VOID EFIAPI OcAudioExitBootServices(IN EFI_EVENT Event, IN VOID *Context)
STATIC BOOLEAN OcShouldPlayChime(IN CONST CHAR8 *Control)
VOID OcLoadUefiAudioSupport(IN OC_STORAGE_CONTEXT *Storage, IN OC_GLOBAL_CONFIG *Config)
STATIC EFI_STATUS EFIAPI OcAudioReleaseFile(IN VOID *Context, IN UINT8 *Buffer)
STATIC VOID * OcAudioGetFileContents(IN OC_STORAGE_CONTEXT *Storage, IN CONST CHAR8 *BasePath, IN CONST CHAR8 *BaseType, IN BOOLEAN Localised, IN CONST CHAR8 *Extension, IN APPLE_VOICE_OVER_LANGUAGE_CODE LanguageCode, OUT UINT32 *BufferSize)
STATIC EFI_AUDIO_DECODE_PROTOCOL * mAudioDecodeProtocol
struct OC_AUDIO_FILE_ OC_AUDIO_FILE
EFI_RUNTIME_SERVICES * gRT
EFI_AUDIO_DECODE_ANY DecodeAny
OC_AUDIO_SET_DELAY SetDelay
OC_AUDIO_STOP_PLAYBACK StopPlayback
OC_AUDIO_RAW_GAIN_TO_DECIBELS RawGainToDecibels
OC_AUDIO_PLAY_FILE PlayFile
OC_AUDIO_SET_DEFAULT_GAIN SetDefaultGain
OC_AUDIO_SET_PROVIDER SetProvider