Commit 97d99184 authored by Stephane Letz's avatar Stephane Letz
Browse files

Code more of less complete.

parent 993363a9
......@@ -250,7 +250,7 @@ void JackAC3Encoder::sample_move_dS_s16_24ph(jack_default_audio_sample_t* dst, c
}
}
void JackAC3Encoder::GetChannelName(char* name, int channel)
void JackAC3Encoder::GetChannelName(const char* name, const char* alias, char* portname, int channel)
{
/*
* 2 channels = L, R
......@@ -260,39 +260,41 @@ void JackAC3Encoder::GetChannelName(char* name, int channel)
* 6 ch = L, C, R, LS, RS, LFE
*/
const char* AC3_name = "";
switch (channel) {
case 0:
strcpy(name, "AC3_1_Left");
AC3_name = "AC3_1_Left";
break;
case 1:
if (fAftenContext.channels == 2 || fAftenContext.channels == 4) {
strcpy(name, "AC3_2_Right");
AC3_name = "AC3_2_Right";
} else {
strcpy(name, "AC3_2_Center");
AC3_name = "AC3_2_Center";
}
break;
case 2:
if (fAftenContext.channels == 4) {
strcpy(name, "AC3_3_LeftSurround");
AC3_name = "AC3_3_LeftSurround";
} else {
strcpy(name, "AC3_3_Right");
AC3_name = "AC3_3_Right";
}
break;
case 3:
if (fAftenContext.channels == 4) {
strcpy(name, "AC3_4_RightSurround");
AC3_name = "AC3_4_RightSurround";
} else {
strcpy(name, "AC3_4_LeftSurround");
AC3_name = "AC3_4_LeftSurround";
}
break;
case 4:
if (fAftenContext.channels > 4) {
strcpy(name, "AC3_5_RightSurround");
AC3_name = "AC3_5_RightSurround";
}
break;
......@@ -302,9 +304,10 @@ void JackAC3Encoder::GetChannelName(char* name, int channel)
// Last channel
if (fAftenContext.lfe && (channel == fAftenContext.channels - 1)) {
sprintf(name, "AC3_%d_LFE", fAftenContext.channels + 1);
sprintf(portname, "%s:%s:AC3_%d_LFE", name, alias, fAftenContext.channels);
} else {
sprintf(portname, "%s:%s:%s", name, alias, AC3_name);
}
}
} // end of namespace
\ No newline at end of file
......@@ -80,7 +80,7 @@ class JackAC3Encoder
bool Init(jack_nframes_t sample_rate);
void Process(float** inputs, float** outputs, int nframes);
void GetChannelName(char* name, int channel);
void GetChannelName(const char* name, const char* alias, char* portname, int channel);
};
typedef JackAC3Encoder * JackAC3EncoderPtr;
......
......@@ -707,6 +707,78 @@ OSStatus JackCoreAudioDriver::GetStreamLatencies(AudioDeviceID device, bool isIn
return err;
}
bool JackCoreAudioDriver::IsDigitalDevice(AudioDeviceID device)
{
OSStatus err = noErr;
UInt32 outSize1;
bool is_digital = false;
/* Get a list of all the streams on this device */
AudioObjectPropertyAddress streamsAddress = { kAudioDevicePropertyStreams, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
err = AudioObjectGetPropertyDataSize(device, &streamsAddress, 0, NULL, &outSize1);
if (err != noErr) {
jack_error("IsDigitalDevice kAudioDevicePropertyStreams err = %d", err);
return false;
}
int stream_count = outSize1 / sizeof(AudioStreamID);
AudioStreamID streamIDs[stream_count];
err = AudioObjectGetPropertyData(device, &streamsAddress, 0, NULL, &outSize1, streamIDs);
if (err != noErr) {
jack_error("IsDigitalDevice kAudioDevicePropertyStreams list err = %d", err);
return false;
}
AudioObjectPropertyAddress physicalFormatsAddress = { kAudioStreamPropertyAvailablePhysicalFormats, kAudioObjectPropertyScopeGlobal, 0 };
for (int i = 0; i < stream_count ; i++) {
/* Find a stream with a cac3 stream */
int format_num = 0;
/* Retrieve all the stream formats supported by each output stream */
err = AudioObjectGetPropertyDataSize(streamIDs[i], &physicalFormatsAddress, 0, NULL, &outSize1);
if (err != noErr) {
jack_error("IsDigitalDevice kAudioStreamPropertyAvailablePhysicalFormats err = %d", err);
return false;
}
format_num = outSize1 / sizeof(AudioStreamRangedDescription);
AudioStreamRangedDescription format_list[format_num];
err = AudioObjectGetPropertyData(streamIDs[i], &physicalFormatsAddress, 0, NULL, &outSize1, format_list);
if (err != noErr) {
jack_error("IsDigitalDevice could not get the list of streamformats err = %d", err);
return false;
}
/* Check if one of the supported formats is a digital format */
for (int j = 0; j < format_num; j++) {
if (format_list[j].mFormat.mFormatID == 'IAC3' ||
format_list[j].mFormat.mFormatID == 'iac3' ||
format_list[j].mFormat.mFormatID == kAudioFormat60958AC3 ||
format_list[j].mFormat.mFormatID == kAudioFormatAC3 )
{
is_digital = true;
break;
}
}
}
return is_digital;
}
bool JackCoreAudioDriver::IsDigitalDeviceStream(AudioDeviceID device, AudioStreamID streamID)
{
// TODO
return true;
}
JackCoreAudioDriver::JackCoreAudioDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
: JackAudioDriver(name, alias, engine, table),
fAC3Encoder(NULL),
......@@ -1921,7 +1993,7 @@ int JackCoreAudioDriver::Open(jack_nframes_t buffer_size,
printError(osErr);
}
}
if (SetupDevices(capture_driver_uid, playback_driver_uid, capture_driver_name, playback_driver_name, sample_rate) < 0) {
goto error;
}
......@@ -1938,7 +2010,7 @@ int JackCoreAudioDriver::Open(jack_nframes_t buffer_size,
goto error;
}
if (SetupChannels(capturing, playing, inchannels, outchannels, in_nChannels, out_nChannels, true) < 0) {
if (SetupChannels(capturing, playing, inchannels, outchannels, in_nChannels, out_nChannels, !ac3_encoding) < 0) {
goto error;
}
......@@ -1951,6 +2023,18 @@ int JackCoreAudioDriver::Open(jack_nframes_t buffer_size,
}
if (ac3_encoding) {
if (!IsDigitalDevice(fDeviceID)) {
jack_error("AC3 encoding can only be used with a digital device");
goto error;
}
// Force hogged mode
fHogged = true;
if (TakeHog()) {
jack_info("Device = %ld has been hogged", fDeviceID);
}
JackAC3EncoderParams params;
memset(&params, 0, sizeof(JackAC3EncoderParams));
params.bitrate = ac3_bitrate;
......@@ -1958,11 +2042,27 @@ int JackCoreAudioDriver::Open(jack_nframes_t buffer_size,
params.sample_rate = sample_rate;
params.lfe = ac3_lfe;
fAC3Encoder = new JackAC3Encoder(params);
if (!fAC3Encoder || !fAC3Encoder->Init(sample_rate)) {
jack_error("Cannot allocate of init AC3 encoder");
goto error;
}
// Setup AC3 channel number
fPlaybackChannels = outchannels;
if (ac3_lfe) {
fPlaybackChannels++;
}
// Force real output channel number to 2
outchannels = out_nChannels = 2;
} else {
fPlaybackChannels = outchannels;
}
// Core driver may have changed the in/out values
fCaptureChannels = inchannels;
if (OpenAUHAL(capturing, playing, inchannels, outchannels, in_nChannels, out_nChannels, parsed_chan_in_list, parsed_chan_out_list, buffer_size, sample_rate) < 0) {
goto error;
......@@ -1977,10 +2077,7 @@ int JackCoreAudioDriver::Open(jack_nframes_t buffer_size,
if (AddListeners() < 0) {
goto error;
}
// Core driver may have changed the in/out values
fCaptureChannels = inchannels;
fPlaybackChannels = outchannels;
return noErr;
error:
......@@ -2157,8 +2254,8 @@ int JackCoreAudioDriver::Attach()
if (fAC3Encoder) {
// Setup specific AC3 channels names
for (int i = 0; i < fPlaybackChannels; i++) {
fAC3Encoder->GetChannelName(alias, i);
port = fGraphManager->GetPort(port_index);
fAC3Encoder->GetChannelName("coreaudio", "", alias, i);
port = fGraphManager->GetPort(fPlaybackPortList[i]);
port->SetAlias(alias);
}
}
......
......@@ -162,6 +162,9 @@ class JackCoreAudioDriver : public JackAudioDriver
bool TakeHog();
void UpdateLatencies();
bool IsDigitalDevice(AudioDeviceID device);
bool IsDigitalDeviceStream(AudioDeviceID device, AudioStreamID streamID);
public:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment