1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#include "setup.h"
#include "display.h"
#include <vdr/tools.h>
#include <vdr/menuitems.h>
#include <bcm_host.h>
#include "interface/vchiq_arm/vchiq_if.h"
#include "interface/vmcs_host/vc_tvservice.h"
/* ------------------------------------------------------------------------- */
class cRpiSetupPage : public cMenuSetupPage
{
public:
cRpiSetupPage(
cRpiSetup::AudioParameters audio,
cRpiSetup::VideoParameters video) :
m_audio(audio),
m_video(video)
{
Setup();
}
eOSState ProcessKey(eKeys Key)
{
int newAudioPort = m_audio.port;
int newPassthrough = m_audio.passthrough;
eOSState state = cMenuSetupPage::ProcessKey(Key);
if (Key != kNone)
{
if ((newAudioPort != m_audio.port) ||
(newPassthrough != m_audio.passthrough))
Setup();
}
return state;
}
protected:
virtual void Store(void)
{
SetupStore("AudioPort", m_audio.port);
SetupStore("PassThrough", m_audio.passthrough);
SetupStore("IgnoreAudioEDID", m_audio.ignoreEDID);
SetupStore("VideoFraming", m_video.framing);
SetupStore("Resolution", m_video.resolution);
SetupStore("FrameRate", m_video.frameRate);
cRpiSetup::GetInstance()->Set(m_audio, m_video);
}
private:
void Setup(void)
{
int current = Current();
Clear();
if (cRpiDisplay::GetVideoPort() == cRpiVideoPort::eHDMI)
{
Add(new cMenuEditStraItem(
tr("Resolution"), &m_video.resolution, 6, s_videoResolution));
Add(new cMenuEditStraItem(
tr("Frame Rate"), &m_video.frameRate, 9, s_videoFrameRate));
}
Add(new cMenuEditStraItem(
tr("Video Framing"), &m_video.framing, 3, s_videoFraming));
Add(new cMenuEditStraItem(
tr("Audio Port"), &m_audio.port, 2, s_audioport));
if (m_audio.port == 1)
{
Add(new cMenuEditBoolItem(
tr("Digital Audio Pass-Through"), &m_audio.passthrough));
if (m_audio.passthrough)
Add(new cMenuEditBoolItem(
tr("Ignore Audio EDID"), &m_audio.ignoreEDID));
}
SetCurrent(Get(current));
Display();
}
cRpiSetup::AudioParameters m_audio;
cRpiSetup::VideoParameters m_video;
static const char *const s_audioport[2];
static const char *const s_videoFraming[3];
static const char *const s_videoResolution[6];
static const char *const s_videoFrameRate[9];
};
const char *const cRpiSetupPage::s_audioport[] =
{ tr("analog"), tr("HDMI") };
const char *const cRpiSetupPage::s_videoFraming[] =
{ tr("box"), tr("crop"), tr("stretch") };
const char *const cRpiSetupPage::s_videoResolution[] =
{ tr("don't change"), tr("follow video"),
"720x480", "720x576", "1280x720", "1920x1080" };
const char *const cRpiSetupPage::s_videoFrameRate[] =
{ tr("don't change"), tr("follow video"),
"24p", "25p", "30p", "50i", "50p", "60i", "60p" };
/* ------------------------------------------------------------------------- */
cRpiSetup* cRpiSetup::s_instance = 0;
cRpiSetup* cRpiSetup::GetInstance(void)
{
if (!s_instance)
s_instance = new cRpiSetup();
return s_instance;
}
void cRpiSetup::DropInstance(void)
{
delete s_instance;
s_instance = 0;
bcm_host_deinit();
}
bool cRpiSetup::HwInit(void)
{
cRpiSetup* instance = GetInstance();
if (!instance)
return false;
bcm_host_init();
if (!vc_gencmd_send("codec_enabled MPG2"))
{
char buffer[1024];
if (!vc_gencmd_read_response(buffer, sizeof(buffer)))
{
if (!strcasecmp(buffer,"MPG2=enabled"))
GetInstance()->m_mpeg2Enabled = true;
}
}
int width, height;
if (!cRpiDisplay::GetSize(width, height))
{
ILOG("HwInit() done, using %s video out at %dx%d",
cRpiVideoPort::Str(cRpiDisplay::GetVideoPort()), width, height);
}
else
ELOG("failed to get video port information!");
return true;
}
void cRpiSetup::SetAudioSetupChangedCallback(void (*callback)(void*), void* data)
{
GetInstance()->m_onAudioSetupChanged = callback;
GetInstance()->m_onAudioSetupChangedData = data;
}
void cRpiSetup::SetVideoSetupChangedCallback(void (*callback)(void*), void* data)
{
GetInstance()->m_onVideoSetupChanged = callback;
GetInstance()->m_onVideoSetupChangedData = data;
}
bool cRpiSetup::IsAudioFormatSupported(cAudioCodec::eCodec codec,
int channels, int samplingRate)
{
// MPEG-1 layer 2 audio pass-through not supported by audio render
// and AAC audio pass-through not yet working
if (codec == cAudioCodec::eMPG || codec == cAudioCodec::eAAC)
return false;
if (GetInstance()->m_audio.ignoreEDID)
return true;
if (vc_tv_hdmi_audio_supported(
codec == cAudioCodec::eMPG ? EDID_AudioFormat_eMPEG1 :
codec == cAudioCodec::eAC3 ? EDID_AudioFormat_eAC3 :
codec == cAudioCodec::eEAC3 ? EDID_AudioFormat_eEAC3 :
codec == cAudioCodec::eAAC ? EDID_AudioFormat_eAAC :
EDID_AudioFormat_ePCM, channels,
samplingRate == 32000 ? EDID_AudioSampleRate_e32KHz :
samplingRate == 44100 ? EDID_AudioSampleRate_e44KHz :
samplingRate == 88200 ? EDID_AudioSampleRate_e88KHz :
samplingRate == 96000 ? EDID_AudioSampleRate_e96KHz :
samplingRate == 176000 ? EDID_AudioSampleRate_e176KHz :
samplingRate == 192000 ? EDID_AudioSampleRate_e192KHz :
EDID_AudioSampleRate_e48KHz,
EDID_AudioSampleSize_16bit) == 0)
return true;
DLOG("%dch %s, %d.%dkHz not supported by HDMI device",
channels, cAudioCodec::Str(codec),
samplingRate / 1000, (samplingRate % 1000) / 100);
return false;
}
void cRpiSetup::SetHDMIChannelMapping(bool passthrough, int channels)
{
char command[80], response[80];
sprintf(command, "hdmi_stream_channels %d", passthrough ? 1 : 0);
vc_gencmd(response, sizeof response, command);
uint32_t channel_map = 0;
if (!passthrough && channels > 0 && channels <= 6)
{
const unsigned char ch_mapping[6][8] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0 }, // not supported
{ 1, 2, 0, 0, 0, 0, 0, 0 }, // 2.0
{ 1, 2, 4, 0, 0, 0, 0, 0 }, // 2.1
{ 0, 0, 0, 0, 0, 0, 0, 0 }, // not supported
{ 0, 0, 0, 0, 0, 0, 0, 0 }, // not supported
{ 1, 2, 4, 3, 5, 6, 0, 0 }, // 5.1
};
// speaker layout according CEA 861, Table 28: Audio InfoFrame, byte 4
const unsigned char cea_map[] =
{
0xff, // not supported
0x00, // 2.0
0x01, // 2.1
0xff, // not supported
0xff, // not supported
0x0b // 5.1
};
for (int ch = 0; ch < channels; ch++)
if (ch_mapping[channels - 1][ch])
channel_map |= (ch_mapping[channels - 1][ch] - 1) << (3 * ch);
channel_map |= cea_map[channels - 1] << 24;
}
sprintf(command, "hdmi_channel_map 0x%08x", channel_map);
vc_gencmd(response, sizeof response, command);
}
cMenuSetupPage* cRpiSetup::GetSetupPage(void)
{
return new cRpiSetupPage(m_audio, m_video);
}
bool cRpiSetup::Parse(const char *name, const char *value)
{
if (!strcasecmp(name, "AudioPort"))
m_audio.port = atoi(value);
else if (!strcasecmp(name, "PassThrough"))
m_audio.passthrough = atoi(value);
else if (!strcasecmp(name, "IgnoreAudioEDID"))
m_audio.ignoreEDID = atoi(value);
else if (!strcasecmp(name, "VideoFraming"))
m_video.framing = atoi(value);
else if (!strcasecmp(name, "Resolution"))
m_video.resolution = atoi(value);
else if (!strcasecmp(name, "FrameRate"))
m_video.frameRate = atoi(value);
else return false;
return true;
}
void cRpiSetup::Set(AudioParameters audio, VideoParameters video)
{
if (audio != m_audio)
{
m_audio = audio;
if (m_onAudioSetupChanged)
m_onAudioSetupChanged(m_onAudioSetupChangedData);
}
if (video != m_video)
{
m_video = video;
if (m_onVideoSetupChanged)
m_onVideoSetupChanged(m_onVideoSetupChangedData);
}
}
|