diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2010-07-07 14:45:23 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2010-07-07 14:45:23 +0800 |
commit | dc4013c9c9850d61b31f837a9841dfe683e575d3 (patch) | |
tree | 8f50879b32e334da363614c72271813b6f851950 /src/device_nexus.cpp | |
parent | 92b0faf5546673c172a0d4b46ee28f41af1da34a (diff) |
nexus: use the nexus common library
Diffstat (limited to 'src/device_nexus.cpp')
-rw-r--r-- | src/device_nexus.cpp | 100 |
1 files changed, 57 insertions, 43 deletions
diff --git a/src/device_nexus.cpp b/src/device_nexus.cpp index 7e4838a..18fad38 100644 --- a/src/device_nexus.cpp +++ b/src/device_nexus.cpp @@ -1,6 +1,7 @@ #include <algorithm> #include <string> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> #include <fcntl.h> @@ -23,6 +24,8 @@ #include "device_nexus.h" #include "debug.h" +using Nexus::RESOURCE_AUDIO_PLAYBACK; + namespace audiere { @@ -31,46 +34,37 @@ namespace audiere { NEXUS_PlatformConfiguration config; NEXUS_AudioPlaybackHandle playback; NEXUS_AudioMixerHandle mixer; - NexusAudioDevice *device; - - NEXUS_Platform_Init(NULL); - NEXUS_Platform_GetConfiguration(&config); + Nexus::Platform *platform = Nexus::Platform::getPlatform(); - playback = NEXUS_AudioPlayback_Open(0, NULL); - if (!playback) { - ADR_LOG("Unable to open playback channel\n"); + if (!platform) return 0; - } - mixer = NEXUS_AudioMixer_Open(NULL); - if (!mixer) { - ADR_LOG("Unable to open audio mixer\n"); - NEXUS_AudioPlayback_Close(playback); + if (!platform->getDisplay()) { + platform->release(); return 0; } - NEXUS_AudioMixer_AddInput(mixer, - NEXUS_AudioPlayback_GetConnector(playback)); - - /* Connect DAC to mixer */ - NEXUS_AudioOutput_AddInput(NEXUS_AudioDac_GetConnector(config.outputs.audioDacs[0]), - NEXUS_AudioMixer_GetConnector(mixer)); + NEXUS_Platform_GetConfiguration(&config); - /* Connect SPDIF to mixer */ - NEXUS_AudioOutput_AddInput(NEXUS_SpdifOutput_GetConnector(config.outputs.spdif[0]), - NEXUS_AudioMixer_GetConnector(mixer)); + int playback_id = platform->allocResourceId(RESOURCE_AUDIO_PLAYBACK); + if (playback_id < 0) { + platform->release(); + return 0; + } - device = new NexusAudioDevice(playback, mixer, 44100, 4096); + playback = NEXUS_AudioPlayback_Open(playback_id, NULL); + if (!playback) { + ADR_LOG("Unable to open playback channel\n"); + platform->freeResourceId(RESOURCE_AUDIO_PLAYBACK, playback_id); + platform->release(); + return 0; + } - char buf[64]; + Nexus::Audio* audio = platform->getAudio(); + mixer = (NEXUS_AudioMixerHandle)audio->getNexusAudioMixer(); - snprintf(buf, sizeof(buf), "%ld", (unsigned long)playback); - setenv ("AUDIERE_NEXUS_PLAYBACK", buf, 1); - snprintf(buf, sizeof(buf), "%ld", (unsigned long)&device->m_playbackSettings); - setenv ("AUDIERE_NEXUS_PLAYBACK_SETTINGS", buf, 1); - snprintf(buf, sizeof(buf), "%ld", (unsigned long)mixer); - setenv ("AUDIERE_NEXUS_MIXER", buf, 1); - return device; + return new NexusAudioDevice(platform, playback_id, playback, + mixer, 44100, 4096); } void NexusAudioDevice::DataCallback(void *pParam1, int param2) @@ -83,15 +77,20 @@ namespace audiere { BKNI_SetEvent(device->m_event); } - NexusAudioDevice::NexusAudioDevice(NEXUS_AudioPlaybackHandle playback, + NexusAudioDevice::NexusAudioDevice(Nexus::Platform *platform, + int playback_id, + NEXUS_AudioPlaybackHandle playback, NEXUS_AudioMixerHandle mixer, int rate, int buffer_size) - : MixerDevice(rate), m_playback(playback), m_mixer(mixer), m_rate(rate) + : MixerDevice(rate), m_platform(platform), m_playback_id(playback_id), + m_playback(playback), m_mixer(mixer), m_rate(rate) { + m_display = platform->getDisplay(); m_buffer_size = buffer_size; m_buffer = new char [buffer_size]; + BKNI_CreateEvent(&m_event); NEXUS_AudioPlayback_GetDefaultStartSettings(&m_playbackSettings); m_playbackSettings.sampleRate = 44100; m_playbackSettings.bitsPerSample = 16; @@ -101,38 +100,53 @@ namespace audiere { m_playbackSettings.dataCallback.param = 0; m_playbackSettings.dataCallback.context = this; - BKNI_CreateEvent(&m_event); + NEXUS_AudioMixer_AddInput(mixer, + NEXUS_AudioPlayback_GetConnector(playback)); + NEXUS_AudioPlayback_Start(playback, &m_playbackSettings); + m_display->registerHotplugCallback(this); } NexusAudioDevice::~NexusAudioDevice() { ADR_GUARD("NexusAudioDevice::~NexusAudioDevice"); + printf("audiere: closing audio device...\n"); NEXUS_PlatformConfiguration config; NEXUS_Platform_GetConfiguration(&config); - unsetenv ("AUDIERE_NEXUS_PLAYBACK"); - unsetenv ("AUDIERE_NEXUS_MIXER"); + m_display->unregisterHotplugCallback(this); NEXUS_AudioPlayback_Stop(m_playback); -#if NEXUS_NUM_HDMI_OUTPUTS - NEXUS_AudioOutput_RemoveAllInputs(NEXUS_HdmiOutput_GetAudioConnector(config.outputs.hdmi[0])); -#endif - NEXUS_AudioOutput_RemoveAllInputs(NEXUS_SpdifOutput_GetConnector(config.outputs.spdif[0])); - NEXUS_AudioOutput_RemoveAllInputs(NEXUS_AudioDac_GetConnector(config.outputs.audioDacs[0])); - NEXUS_AudioMixer_RemoveAllInputs(m_mixer); + + NEXUS_AudioMixer_RemoveInput(m_mixer, + NEXUS_AudioPlayback_GetConnector(m_playback)); NEXUS_AudioInput_Shutdown(NEXUS_AudioPlayback_GetConnector(m_playback)); - NEXUS_AudioInput_Shutdown(NEXUS_AudioMixer_GetConnector(m_mixer)); NEXUS_AudioPlayback_Close(m_playback); - NEXUS_AudioMixer_Close(m_mixer); BKNI_DestroyEvent(m_event); + delete [] m_buffer; + + m_platform->freeResourceId(RESOURCE_AUDIO_PLAYBACK, m_playback_id); + m_platform->release(); + //delete [] m_buffer; } + void NexusAudioDevice::preHotplug(Nexus::HotplugStatus status) + { + printf("audiere: stopping audio playback.\n"); + NEXUS_AudioPlayback_Stop(m_playback); + } + + void NexusAudioDevice::postHotplug(Nexus::HotplugStatus status) + { + printf("audiere: starting audio playback.\n"); + NEXUS_AudioPlayback_Start(m_playback, &m_playbackSettings); + } + void ADR_CALL NexusAudioDevice::update() { int sample_len; |