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 | |
parent | 92b0faf5546673c172a0d4b46ee28f41af1da34a (diff) |
nexus: use the nexus common library
-rw-r--r-- | src/device_nexus.cpp | 100 | ||||
-rw-r--r-- | src/device_nexus.h | 19 |
2 files changed, 74 insertions, 45 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; diff --git a/src/device_nexus.h b/src/device_nexus.h index 2ff3a14..75bfe67 100644 --- a/src/device_nexus.h +++ b/src/device_nexus.h @@ -15,20 +15,27 @@ #include "nexus_audio_input.h" #include "nexus_audio_decoder.h" #include "nexus_audio_mixer.h" +#include "nexus_spdif_output.h" #include "nexus_stc_channel.h" #include "nexus_pid_channel.h" #include "nexus_parser_band.h" #include "nexus_hdmi_output.h" +#include <nexuscommon/nexuscommon.h> +#include <nexuscommon/nexusdisplay.h> +#include <nexuscommon/nexusaudio.h> namespace audiere { - class NexusAudioDevice : public MixerDevice { + class NexusAudioDevice : public MixerDevice, public Nexus::HotplugCallback { public: static NexusAudioDevice* create(const ParameterList& parameters); private: - NexusAudioDevice(NEXUS_AudioPlaybackHandle playback, + NexusAudioDevice(Nexus::Platform *platform, + int playback_id, + NEXUS_AudioPlaybackHandle playback, + NEXUS_AudioMixerHandle mixer, int rate, int buffer_size); ~NexusAudioDevice(); @@ -37,10 +44,18 @@ namespace audiere { void ADR_CALL update(); const char* ADR_CALL getName(); + public: + virtual void preHotplug(Nexus::HotplugStatus status); + virtual void postHotplug(Nexus::HotplugStatus status); + private: + Nexus::Platform* m_platform; + Nexus::Display* m_display; + int m_playback_id; BKNI_EventHandle m_event; NEXUS_AudioPlaybackHandle m_playback; NEXUS_AudioPlaybackStartSettings m_playbackSettings; + NEXUS_AudioMixerHandle m_mixer; int m_buffer_size; char* m_buffer; |