Files
2026-08-24 10:03:24 +08:00

200 lines
6.1 KiB
C

#define LOG_MODULE_TAG "TV"
#define LOG_CLASS_TAG "TvTest-c"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <TvClientWrapper.h>
#include <CTvLog.h>
tv_source_input_t CurrentSource;
tv_source_input_t CurrentPipSource;
static int WriteSysfs(const char *path, const char *cmd)
{
int fd;
fd = open(path, O_CREAT|O_RDWR | O_TRUNC, 0777);
if (fd >= 0) {
write(fd, cmd, strlen(cmd));
close(fd);
return 0;
}
return -1;
}
static void Signalhandler(int sig){ // handler ctrl + C operation
StopTv(CurrentSource);
WriteSysfs("/sys/class/graphics/fb0/blank", "0");
WriteSysfs("/sys/kernel/debug/dri/0/vpu/blank", "0");
exit(0);
}
static int DisplayInit()
{
WriteSysfs("/sys/class/graphics/fb0/osd_display_debug", "1");
WriteSysfs("/sys/class/graphics/fb0/blank", "1");
WriteSysfs("/sys/kernel/debug/dri/0/vpu/blank", "1");
return 0;
}
static void TvEventCallback(event_type_t eventType, void *eventData)
{
if (eventType == TV_EVENT_TYPE_SIGNAL_DETECT) {
SignalDetectCallback_t *signalDetectEvent = (SignalDetectCallback_t *)(eventData);
printf("%s: source: %d, signalFmt: %d, transFmt: %d, status: %d, isDVI: %d, Hdrinfo: %ud.\n", __FUNCTION__,
signalDetectEvent->SourceInput,
signalDetectEvent->SignalFmt,
signalDetectEvent->TransFmt,
signalDetectEvent->SignalStatus,
signalDetectEvent->isDviSignal,
signalDetectEvent->Hdrinfo);
} else if (eventType == TV_EVENT_TYPE_SOURCE_CONNECT) {
SourceConnectCallback_t *sourceConnectEvent = (SourceConnectCallback_t *)(eventData);
printf("%s: source: %d, connectStatus: %d\n", __FUNCTION__,
sourceConnectEvent->SourceInput, sourceConnectEvent->ConnectionState);
} else {
printf("%s: invalid event.\n", __FUNCTION__);
}
}
static int SwitchPiPsource()
{
char Command[1];
int Source = SOURCE_INVALID;
int id = 0;
printf("##########################\n");
printf("#### please set PIP parms ####\n");
printf("#### only HDMI 1/2 support pip ####\n");
printf("#### source can set 1/2 ####\n");
printf("#### audio id need greater than 0 ####\n");
printf("#### set source && audio id (e.g. 1 2) ####\n");
printf("##########################\n");
if (scanf("%d %d", &Source, &id) != 2 || id <= 0) {
printf("Error reading id\n");
while (getchar() != '\n');
return SOURCE_INVALID;
}
if (Source == 1) {
Source = SOURCE_HDMI1;
} else if (Source == 2) {
Source = SOURCE_HDMI2;
}
SetAudioDecoderId(1, id);
return Source;
}
int main(int argc, char **argv) {
setTvEventCallback(TvEventCallback);
signal(SIGINT, Signalhandler);
char Command[2];
int run = 1;
CurrentSource = SOURCE_HDMI1;
CurrentPipSource = SOURCE_INVALID;
DisplayInit();
printf("#### please select cmd####\n");
printf("#### select 1 to hdmi 1 ####\n");
printf("#### select 2 to hdmi 2 ####\n");
printf("#### select 3 to hdmi 3 ####\n");
printf("#### select 4 to edid 1.4 (this is default) ####\n");
printf("#### select 5 to edid 2.0 ####\n");
printf("#### select 6 to edid auto ####\n");
printf("#### select 7 to AV1 ####\n");
printf("#### select 8 to AV2 ####\n");
printf("#### select 9 to PIP ####\n");
printf("#### select q to stop####\n");
printf("##########################\n");
while (run) {
if ((scanf("%1s", Command)) != 1) {
printf("Error reading command.\n");
continue;
}
switch (Command[0]) {
case 'q': {
StopTv(CurrentSource);
StopTvInPIP(CurrentPipSource);
WriteSysfs("/sys/class/graphics/fb0/blank", "0");
WriteSysfs("/sys/kernel/debug/dri/0/vpu/blank", "0");
run = 0;
break;
}
case '1': {
StopTv(CurrentSource);
CurrentSource = SOURCE_HDMI1;
WriteSysfs("/sys/class/graphics/fb0/blank", "0");
StartTv(CurrentSource);
break;
}
case '2': {
StopTv(CurrentSource);
CurrentSource = SOURCE_HDMI2;
WriteSysfs("/sys/class/graphics/fb0/blank", "0");
StartTv(CurrentSource);
break;
}
case '3': {
StopTv(CurrentSource);
CurrentSource = SOURCE_HDMI3;
WriteSysfs("/sys/class/graphics/fb0/blank", "0");
StartTv(CurrentSource);
break;
}
case '4': {
SetEdidVersion(CurrentSource, 0);
break;
}
case '5': {
SetEdidVersion(CurrentSource, 1);
break;
}
case '6': {
SetEdidVersion(CurrentSource, 2);
break;
}
case '7': {
StopTv(CurrentSource);
CurrentSource = SOURCE_AV1;
WriteSysfs("/sys/class/graphics/fb0/blank", "0");
StartTv(CurrentSource);
break;
}
case '8': {
StopTv(CurrentSource);
CurrentSource = SOURCE_AV2;
WriteSysfs("/sys/class/graphics/fb0/blank", "0");
StartTv(CurrentSource);
break;
}
case '9': {
StopTvInPIP(CurrentPipSource);
CurrentPipSource = SwitchPiPsource();
if (CurrentPipSource == SOURCE_INVALID) break;
WriteSysfs("/sys/class/graphics/fb0/blank", "0");
StartTvInPIP(CurrentPipSource);
break;
}
default: {
printf("invalid cmd.\n");
break;
}
}
fflush (stdout);
}
return 0;
}