mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-12 09:54:36 +01:00
Refactor HDA_OUTPUTS as a class and AudioList as a XObjArray.
This commit is contained in:
parent
823e0efc9f
commit
e7d14cc70e
@ -56,8 +56,6 @@ CONST CHAR8 *gColors[HDA_CONFIG_DEFAULT_COLOR_OTHER + 1] = {
|
||||
|
||||
CONST CHAR8 hdcID[4] = HDC_ID;
|
||||
|
||||
extern UINTN AudioNum;
|
||||
extern HDA_OUTPUTS AudioList[20];
|
||||
extern EFI_AUDIO_IO_PROTOCOL *AudioIo;
|
||||
extern XStringW OEMPath;
|
||||
|
||||
@ -280,7 +278,7 @@ EFI_STATUS SaveHdaDumpTxt()
|
||||
UINTN MemLogStartLen;
|
||||
|
||||
// Print each codec found.
|
||||
for (UINTN i = 0; i < AudioNum; i++) {
|
||||
for (UINTN i = 0; i < AudioList.size(); i++) {
|
||||
MemLogStartLen = GetMemLogLen();
|
||||
MemLogStart = GetMemLogBuffer() + MemLogStartLen;
|
||||
|
||||
@ -354,7 +352,7 @@ EFI_STATUS SaveHdaDumpBin()
|
||||
EFI_HDA_IO_PROTOCOL *HdaIo;
|
||||
XStringW MiscPath = SWPrintf("%ls\\misc", OEMPath.wc_str());
|
||||
|
||||
for (UINTN i = 0; i < AudioNum; i++) {
|
||||
for (UINTN i = 0; i < AudioList.size(); i++) {
|
||||
HDA_WIDGET_DEV *Widgets;
|
||||
UINTN WidgetCount;
|
||||
UINT32 HdaCodecDataSize;
|
||||
|
@ -101,8 +101,7 @@ UINTN ConfigsNum;
|
||||
CHAR16 *ConfigsList[20];
|
||||
UINTN DsdtsNum = 0;
|
||||
CHAR16 *DsdtsList[20];
|
||||
UINTN AudioNum;
|
||||
HDA_OUTPUTS AudioList[20];
|
||||
XObjArray<HDA_OUTPUTS> AudioList;
|
||||
XObjArray<RT_VARIABLES> BlockRtVariableArray;
|
||||
|
||||
// firmware
|
||||
@ -6538,7 +6537,7 @@ GetDevices ()
|
||||
|
||||
NGFX = 0;
|
||||
NHDA = 0;
|
||||
AudioNum = 0;
|
||||
AudioList.setEmpty();
|
||||
//Arpt.Valid = FALSE; //global variables initialized by 0 - c-language
|
||||
XStringW GopDevicePathStr;
|
||||
XStringW DevicePathStr;
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include "../gui/menu_items/menu_items.h"
|
||||
#include "../Platform/plist/plist.h"
|
||||
//class TagStruct;
|
||||
|
||||
//// SysVariables
|
||||
//typedef struct SYSVARIABLES SYSVARIABLES;
|
||||
@ -17,13 +16,20 @@
|
||||
// INPUT_ITEM MenuItem;
|
||||
//};
|
||||
|
||||
typedef struct {
|
||||
CHAR16 *Name;
|
||||
class HDA_OUTPUTS
|
||||
{
|
||||
public:
|
||||
XStringW Name;
|
||||
// CHAR8 *LineName;
|
||||
INTN Index;
|
||||
UINT8 Index;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_AUDIO_IO_PROTOCOL_DEVICE Device;
|
||||
} HDA_OUTPUTS;
|
||||
|
||||
HDA_OUTPUTS() : Name(), Index(0), Handle(0), Device(EfiAudioIoDeviceOther) {}
|
||||
HDA_OUTPUTS(const HDA_OUTPUTS& other) = delete; // Can be defined if needed
|
||||
const HDA_OUTPUTS& operator = ( const HDA_OUTPUTS & ) = delete; // Can be defined if needed
|
||||
~HDA_OUTPUTS() {}
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
Unknown,
|
||||
@ -717,9 +723,7 @@ RT_VARIABLES() : Name(), VarGuid{0} {};
|
||||
|
||||
|
||||
extern XObjArray<RT_VARIABLES> BlockRtVariableArray;
|
||||
|
||||
extern UINTN AudioNum;
|
||||
extern HDA_OUTPUTS AudioList[20];
|
||||
extern XObjArray<HDA_OUTPUTS> AudioList;
|
||||
|
||||
extern CONST CHAR16* ThemesList[100]; //no more then 100 themes?
|
||||
extern CHAR16* ConfigsList[20];
|
||||
|
@ -34,8 +34,6 @@
|
||||
#include "Settings.h"
|
||||
#include "Nvram.h"
|
||||
|
||||
extern UINTN AudioNum;
|
||||
extern HDA_OUTPUTS AudioList[20];
|
||||
extern UINT8 EmbeddedSound[];
|
||||
extern UINTN EmbeddedSoundLength;
|
||||
|
||||
@ -67,15 +65,14 @@ StartupSoundPlay(EFI_FILE *Dir, CONST CHAR16* SoundFile)
|
||||
UINT8 *FileData = NULL;
|
||||
UINTN FileDataLength = 0U;
|
||||
WAVE_FILE_DATA WaveData;
|
||||
UINT8 OutputIndex;
|
||||
UINT8 OutputVolume = DefaultAudioVolume;
|
||||
UINT16 *TempData = NULL;
|
||||
UINTN Len;
|
||||
|
||||
if (OldChosenAudio > AudioNum) {
|
||||
if (OldChosenAudio >= AudioList.size()) {
|
||||
OldChosenAudio = 0; //security correction
|
||||
}
|
||||
OutputIndex = (OldChosenAudio & 0xFF);
|
||||
size_t OutputIndex = (OldChosenAudio & 0xFF);
|
||||
|
||||
WaveData.Samples = NULL;
|
||||
WaveData.SamplesLength = 0;
|
||||
@ -164,7 +161,7 @@ StartupSoundPlay(EFI_FILE *Dir, CONST CHAR16* SoundFile)
|
||||
goto DONE_ERROR;
|
||||
}
|
||||
|
||||
DBG("output to channel %d with volume %d, len=%d\n", OutputIndex, OutputVolume, WaveData.SamplesLength);
|
||||
DBG("output to channel %zu with volume %d, len=%d\n", OutputIndex, OutputVolume, WaveData.SamplesLength);
|
||||
DBG(" sound channels=%d bits=%d freq=%d\n", WaveData.Format->Channels, WaveData.Format->BitsPerSample, WaveData.Format->SamplesPerSec);
|
||||
|
||||
if (!WaveData.SamplesLength || !OutputVolume) {
|
||||
@ -206,11 +203,11 @@ StartupSoundPlay(EFI_FILE *Dir, CONST CHAR16* SoundFile)
|
||||
}
|
||||
|
||||
// Setup playback.
|
||||
if (OutputIndex > AudioNum) {
|
||||
if (OutputIndex >= AudioList.size()) {
|
||||
OutputIndex = 0;
|
||||
DBG("wrong index for Audio output\n");
|
||||
}
|
||||
Status = AudioIo->SetupPlayback(AudioIo, (UINT8)(AudioList[OutputIndex].Index), OutputVolume,
|
||||
Status = AudioIo->SetupPlayback(AudioIo, AudioList[OutputIndex].Index, OutputVolume,
|
||||
freq, bits, (UINT8)(WaveData.Format->Channels));
|
||||
if (EFI_ERROR(Status)) {
|
||||
MsgLog("StartupSound: Error setting up playback: %s\n", efiStrError(Status));
|
||||
@ -341,8 +338,8 @@ GetStoredOutput()
|
||||
}
|
||||
OutputPortIndex &= 0x2F;
|
||||
DBG("got index=%llu\n", OutputPortIndex);
|
||||
if (OutputPortIndex > AudioNum) {
|
||||
DBG("... but max=%llu, so reset to 0\n", AudioNum);
|
||||
if (OutputPortIndex >= AudioList.size()) {
|
||||
DBG("... but max=%zu, so reset to 0\n", AudioList.size());
|
||||
OutputPortIndex = 0;
|
||||
}
|
||||
// Get stored volume. If this fails, just use the max.
|
||||
@ -419,7 +416,7 @@ VOID GetOutputs()
|
||||
|
||||
UINTN h;
|
||||
|
||||
AudioNum = 0;
|
||||
AudioList.setEmpty();
|
||||
|
||||
// Get Audio I/O protocols.
|
||||
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiAudioIoProtocolGuid, NULL, &AudioIoHandleCount, &AudioIoHandles);
|
||||
@ -440,17 +437,25 @@ VOID GetOutputs()
|
||||
if (EFI_ERROR(Status)) {
|
||||
continue;
|
||||
}
|
||||
if ( OutputPortsCount > 255 ) {
|
||||
// SetupPlayback cannot handle index > 255 because parameter is UINT8
|
||||
DBG("GetOutputs() : OutputPortsCount > 255.\n");
|
||||
OutputPortsCount = 255;
|
||||
}
|
||||
AudioIoPrivateData = AUDIO_IO_PRIVATE_DATA_FROM_THIS(AudioIoTmp);
|
||||
if (!AudioIoPrivateData) {
|
||||
continue;
|
||||
}
|
||||
HdaCodecDev = AudioIoPrivateData->HdaCodecDev;
|
||||
for (i = 0; i < OutputPortsCount; i++) {
|
||||
HDA_OUTPUTS* hdaOutputPtr = new HDA_OUTPUTS();
|
||||
HDA_OUTPUTS& hdaOutput = *hdaOutputPtr;
|
||||
// HdaCodecDev->OutputPorts[i];
|
||||
AudioList[AudioNum].Name = HdaCodecDev->Name;
|
||||
AudioList[AudioNum].Handle = AudioIoHandles[h];
|
||||
AudioList[AudioNum].Device = HdaOutputPorts[i].Device;
|
||||
AudioList[AudioNum++].Index = i;
|
||||
hdaOutput.Name.takeValueFrom(HdaCodecDev->Name);
|
||||
hdaOutput.Handle = AudioIoHandles[h];
|
||||
hdaOutput.Device = HdaOutputPorts[i].Device;
|
||||
hdaOutput.Index = (UINT8)i; // safe cast : OutputPortsCount is <= 255.
|
||||
AudioList.AddReference(hdaOutputPtr, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -995,7 +995,7 @@ UINTN REFIT_MENU_SCREEN::RunGenericMenu(IN MENU_STYLE_FUNC StyleFunc, IN OUT INT
|
||||
break;
|
||||
*/
|
||||
case SCAN_F7:
|
||||
if (OldChosenAudio > AudioNum) {
|
||||
if (OldChosenAudio >= AudioList.size()) {
|
||||
OldChosenAudio = 0; //security correction
|
||||
}
|
||||
Status = gBS->HandleProtocol(AudioList[OldChosenAudio].Handle, &gEfiAudioIoProtocolGuid, (VOID**)&AudioIo);
|
||||
|
@ -131,8 +131,6 @@ extern UINTN ConfigsNum;
|
||||
extern CHAR16 *ConfigsList[];
|
||||
extern UINTN DsdtsNum;
|
||||
extern CHAR16 *DsdtsList[];
|
||||
extern UINTN AudioNum;
|
||||
extern HDA_OUTPUTS AudioList[20];
|
||||
extern EFI_AUDIO_IO_PROTOCOL *AudioIo;
|
||||
|
||||
extern EFI_DXE_SERVICES *gDS;
|
||||
@ -2282,10 +2280,10 @@ RefitMain (IN EFI_HANDLE ImageHandle,
|
||||
|
||||
// log Audio devices in boot-log. This is for clients like Clover.app
|
||||
GetOutputs();
|
||||
for (i = 0; i < AudioNum; i++) {
|
||||
if (AudioList[i].Name) {
|
||||
for (i = 0; i < AudioList.size(); i++) {
|
||||
if (AudioList[i].Name.notEmpty()) {
|
||||
// Never change this log, otherwise clients will stop interprete the output.
|
||||
MsgLog("Found Audio Device %ls (%s) at index %llu\n", AudioList[i].Name, AudioOutputNames[AudioList[i].Device], i);
|
||||
MsgLog("Found Audio Device %ls (%s) at index %llu\n", AudioList[i].Name.wc_str(), AudioOutputNames[AudioList[i].Device], i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1029,8 +1029,8 @@ VOID ApplyInputs(VOID)
|
||||
i++; //119
|
||||
if (InputItems[i].Valid) {
|
||||
EFI_DEVICE_PATH_PROTOCOL* DevicePath = NULL;
|
||||
UINT8 TmpIndex;
|
||||
if (OldChosenAudio > AudioNum) {
|
||||
int TmpIndex;
|
||||
if (OldChosenAudio >= AudioList.size()) {
|
||||
// DBG("crasy OldChosenAudio = %lld\n", OldChosenAudio);
|
||||
OldChosenAudio = 0;
|
||||
}
|
||||
@ -2226,9 +2226,9 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuAudioPort()
|
||||
SubScreen->AddMenuInfoLine_f("Select an audio output, press F7 to test");
|
||||
SubScreen->AddMenuItemInput(120, "Volume:", TRUE);
|
||||
|
||||
for (i = 0; i < AudioNum; i++) {
|
||||
for (i = 0; i < AudioList.size(); i++) {
|
||||
InputBootArgs = new REFIT_MENU_SWITCH;
|
||||
InputBootArgs->Title.SWPrintf("%ls_%s", AudioList[i].Name, AudioOutputNames[AudioList[i].Device]);
|
||||
InputBootArgs->Title.SWPrintf("%ls_%s", AudioList[i].Name.wc_str(), AudioOutputNames[AudioList[i].Device]);
|
||||
// InputBootArgs->Tag = TAG_SWITCH_OLD;
|
||||
InputBootArgs->Row = i;
|
||||
InputBootArgs->Item = &InputItems[119];
|
||||
|
Loading…
Reference in New Issue
Block a user