cec volume switch audiosystem/tv

This commit is contained in:
TangoCash
2021-01-31 18:16:08 +01:00
committed by Thilo Graf
parent 0329b7b783
commit 91a546d082
8 changed files with 118 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
/*
Copyright (C) 2018-2020 TangoCash
Copyright (C) 2018-2021 TangoCash
License: GPLv2
@@ -85,6 +85,7 @@ hdmi_cec::hdmi_cec()
fallback = false;
tv_off = true;
deviceType = CEC_LOG_ADDR_TYPE_UNREGISTERED;
audio_destination = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
}
hdmi_cec::~hdmi_cec()
@@ -812,7 +813,7 @@ void hdmi_cec::send_key(unsigned char key, unsigned char destination)
void hdmi_cec::request_audio_status()
{
struct cec_message txmessage;
txmessage.destination = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
txmessage.destination = audio_destination;
txmessage.initiator = logicalAddress;
txmessage.data[0] = CEC_OPCODE_GIVE_AUDIO_STATUS;
txmessage.length = 1;
@@ -821,16 +822,31 @@ void hdmi_cec::request_audio_status()
void hdmi_cec::vol_up()
{
send_key(CEC_USER_CONTROL_CODE_VOLUME_UP, CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM);
send_key(CEC_USER_CONTROL_CODE_VOLUME_UP, audio_destination);
request_audio_status();
}
void hdmi_cec::vol_down()
{
send_key(CEC_USER_CONTROL_CODE_VOLUME_DOWN, CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM);
send_key(CEC_USER_CONTROL_CODE_VOLUME_DOWN, audio_destination);
request_audio_status();
}
void hdmi_cec::toggle_mute()
{
send_key(CEC_USER_CONTROL_CODE_MUTE, CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM);
send_key(CEC_USER_CONTROL_CODE_MUTE, audio_destination);
request_audio_status();
}
void hdmi_cec::SetAudioDestination(int audio_dest)
{
switch(audio_dest)
{
case 2:
audio_destination = CEC_OP_PRIM_DEVTYPE_TV;
break;
case 1:
default:
audio_destination = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
break;
}
}

View File

@@ -2,7 +2,7 @@
#define __HDMI_CEC_H__
/*
Copyright (C) 2018-2020 TangoCash
Copyright (C) 2018-2021 TangoCash
License: GPLv2
@@ -79,6 +79,7 @@ private:
int volume;
bool fallback;
bool tv_off;
unsigned char audio_destination;
protected:
bool running;
public:
@@ -103,6 +104,11 @@ public:
{
return muted;
};
int GetAudioDestination()
{
return (int)audio_destination;
}
void SetAudioDestination(int audio_dest);
};
#endif // __HDMI_CEC_H__

View File

@@ -1303,3 +1303,13 @@ void cVideo::SetCECAutoView(bool state)
{
hdmi_cec::getInstance()->SetCECAutoView(state);
}
int cVideo::GetAudioDestination()
{
return (int)hdmi_cec::getInstance()->GetAudioDestination();
}
void cVideo::SetAudioDestination(int audio_dest)
{
hdmi_cec::getInstance()->SetAudioDestination(audio_dest);
}

View File

@@ -130,6 +130,12 @@ typedef enum {
VIDEO_HDMI_CEC_MODE_RECORDER = 1
} VIDEO_HDMI_CEC_MODE;
typedef enum {
VIDEO_HDMI_CEC_VOL_OFF = 0,
VIDEO_HDMI_CEC_VOL_AUDIOSYSTEM = 1,
VIDEO_HDMI_CEC_VOL_TV = 2
} VIDEO_HDMI_CEC_VOL;
typedef enum
{
VIDEO_CONTROL_BRIGHTNESS = 0,
@@ -238,6 +244,8 @@ class cVideo
bool SetCECMode(VIDEO_HDMI_CEC_MODE);
void SetCECAutoView(bool);
void SetCECAutoStandby(bool);
int GetAudioDestination();
void SetAudioDestination(int audio_dest);
bool ShowPicture(const char * fname);
void StopPicture();
void Standby(unsigned int bOn);

View File

@@ -1,5 +1,5 @@
/*
Copyright (C) 2018-2020 TangoCash
Copyright (C) 2018-2021 TangoCash
License: GPLv2
@@ -85,6 +85,7 @@ hdmi_cec::hdmi_cec()
fallback = false;
tv_off = true;
deviceType = CEC_LOG_ADDR_TYPE_UNREGISTERED;
audio_destination = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
}
hdmi_cec::~hdmi_cec()
@@ -593,9 +594,15 @@ void hdmi_cec::run()
struct epoll_event event;
event.data.fd = hdmiFd;
event.events = EPOLLIN;
<<<<<<< HEAD
epoll_ctl(epollfd, EPOLL_CTL_ADD, hdmiFd, &event);
=======
epoll_ctl(epollfd, EPOLL_CTL_ADD, hdmiFd, &event);
>>>>>>> e24aae1... cec volume switch audiosystem/tv
std::array<struct epoll_event, EPOLL_MAX_EVENTS> events;
while (running)
@@ -812,7 +819,7 @@ void hdmi_cec::send_key(unsigned char key, unsigned char destination)
void hdmi_cec::request_audio_status()
{
struct cec_message txmessage;
txmessage.destination = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
txmessage.destination = audio_destination;
txmessage.initiator = logicalAddress;
txmessage.data[0] = CEC_OPCODE_GIVE_AUDIO_STATUS;
txmessage.length = 1;
@@ -821,16 +828,31 @@ void hdmi_cec::request_audio_status()
void hdmi_cec::vol_up()
{
send_key(CEC_USER_CONTROL_CODE_VOLUME_UP, CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM);
send_key(CEC_USER_CONTROL_CODE_VOLUME_UP, audio_destination);
request_audio_status();
}
void hdmi_cec::vol_down()
{
send_key(CEC_USER_CONTROL_CODE_VOLUME_DOWN, CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM);
send_key(CEC_USER_CONTROL_CODE_VOLUME_DOWN, audio_destination);
request_audio_status();
}
void hdmi_cec::toggle_mute()
{
send_key(CEC_USER_CONTROL_CODE_MUTE, CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM);
send_key(CEC_USER_CONTROL_CODE_MUTE, audio_destination);
request_audio_status();
}
void hdmi_cec::SetAudioDestination(int audio_dest)
{
switch(audio_dest)
{
case 2:
audio_destination = CEC_OP_PRIM_DEVTYPE_TV;
break;
case 1:
default:
audio_destination = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
break;
}
}

View File

@@ -2,7 +2,7 @@
#define __HDMI_CEC_H__
/*
Copyright (C) 2018-2020 TangoCash
Copyright (C) 2018-2021 TangoCash
License: GPLv2
@@ -79,6 +79,7 @@ private:
int volume;
bool fallback;
bool tv_off;
unsigned char audio_destination;
protected:
bool running;
public:
@@ -103,6 +104,11 @@ public:
{
return muted;
};
int GetAudioDestination()
{
return (int)audio_destination;
}
void SetAudioDestination(int audio_dest);
};
#endif // __HDMI_CEC_H__

View File

@@ -1278,3 +1278,13 @@ void cVideo::SetCECAutoView(bool state)
{
hdmi_cec::getInstance()->SetCECAutoView(state);
}
int cVideo::GetAudioDestination()
{
return (int)hdmi_cec::getInstance()->GetAudioDestination();
}
void cVideo::SetAudioDestination(int audio_dest)
{
hdmi_cec::getInstance()->SetAudioDestination(audio_dest);
}

View File

@@ -126,6 +126,12 @@ typedef enum {
VIDEO_HDMI_CEC_MODE_RECORDER = 1
} VIDEO_HDMI_CEC_MODE;
typedef enum {
VIDEO_HDMI_CEC_VOL_OFF = 0,
VIDEO_HDMI_CEC_VOL_AUDIOSYSTEM = 1,
VIDEO_HDMI_CEC_VOL_TV = 2
} VIDEO_HDMI_CEC_VOL;
typedef enum
{
VIDEO_CONTROL_BRIGHTNESS = 0,
@@ -234,7 +240,8 @@ class cVideo
bool SetCECMode(VIDEO_HDMI_CEC_MODE);
void SetCECAutoView(bool);
void SetCECAutoStandby(bool);
void ShowPicture(const char * fname);
int GetAudioDestination();
void SetAudioDestination(int audio_dest);
void StopPicture();
void Standby(unsigned int bOn);
void Pig(int x, int y, int w, int h, int osd_w = 1064, int osd_h = 600, int startx = 0, int starty = 0, int endx = 1279, int endy = 719);