Skip to content

Instantly share code, notes, and snippets.

@calebccff
Created September 21, 2021 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calebccff/14abf94679dd42525c8bd573ae229fde to your computer and use it in GitHub Desktop.
Save calebccff/14abf94679dd42525c8bd573ae229fde to your computer and use it in GitHub Desktop.
Very basic edid parse to check for audio support
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#define HDMI_EDID_PATH "edid.bin"
#define ALOGE(...) (printf(__VA_ARGS__))
struct edid_extension {
unsigned char tag;
unsigned char rev;
unsigned char dtd_offset;
unsigned char info;
unsigned char blocks[124];
};
struct edid {
unsigned char stuff[126];
unsigned char num_extensions;
unsigned char checksum;
struct edid_extension extensions[4]; // i guess there could be more but it's unlikely
};
static bool hdmi_supports_audio() {
FILE *file;
struct edid edid_data;
int block_count, i;
file = fopen(HDMI_EDID_PATH, "rb");
if (file == NULL) {
ALOGE("Unable to open EDID '%d'", HDMI_EDID_PATH);
return false; // or should we fall back to true ?
}
fread(&edid_data, 1, sizeof(edid_data), file);
fclose(file);
ALOGE("NUM EXTENSIONS: %d\n", edid_data.num_extensions);
for (i = 0; i < edid_data.num_extensions < 4 ? edid_data.num_extensions : 4; i++)
{
struct edid_extension *ext = &edid_data.extensions[i];
ALOGE("extension tag: %u\n", ext->tag);
if (ext->tag != 2)
continue;
if (ext->info & 0b01000000) // Bit 6 "display supports basic audio"
return true;
}
return 0;
}
int main(int argc, char **argv) {
bool supported = hdmi_supports_audio();
ALOGE("supports audio: %d\n", supported);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment