From 90fb19dcd1f6df2dd54b6502d0a9dd75abaa5ea2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 23 Jul 2014 18:19:00 -0600 Subject: NxWM: Beginning integration of NxPlayer into Nxwm::MediaPlayer. Gets handle, sets device, and releases handle. Lots more to be done --- NxWidgets/Kconfig | 16 ++++- NxWidgets/nxwm/include/cmediaplayer.hxx | 17 ++++- NxWidgets/nxwm/include/nxwmconfig.hxx | 4 ++ NxWidgets/nxwm/src/cmediaplayer.cxx | 112 +++++++++++++++++++++++++++++++- 4 files changed, 144 insertions(+), 5 deletions(-) (limited to 'NxWidgets') diff --git a/NxWidgets/Kconfig b/NxWidgets/Kconfig index 8bd5ef26d..6608d7a56 100644 --- a/NxWidgets/Kconfig +++ b/NxWidgets/Kconfig @@ -1130,6 +1130,20 @@ config NXWM_MEDIAPLAYER if NXWM_MEDIAPLAYER +menu "NxPlayer Integration" + +config NXWM_MEDIAPLAYER_PREFERRED_DEVICE + string "Preferred audio device" + default "pcm0" + depends on NXPLAYER_INCLUDE_PREFERRED_DEVICE + ---help--- + NxPlayer expects us to specify a preferred audio device. This + selection allows us to identify that preferred audio device. This + device is identified by a simple name string that corresponds to an + audio device that can be found under /dev/audio. + +endmenu # NxPlayer Integration + menu "Media File Configuration" config NXWM_MEDIAPLAYER_MEDIAPATH @@ -1166,7 +1180,7 @@ config NXWM_MEDIAPLAYER_FILTER_WAV config NXWM_MEDIAPLAYER_FILTER_PCM bool "Accept .pcm extension" - default y + default n select NXWM_MEDIAPLAYER_FILTER config NXWM_MEDIAPLAYER_FILTER_MP3 diff --git a/NxWidgets/nxwm/include/cmediaplayer.hxx b/NxWidgets/nxwm/include/cmediaplayer.hxx index 0584429a4..b2f5072f6 100644 --- a/NxWidgets/nxwm/include/cmediaplayer.hxx +++ b/NxWidgets/nxwm/include/cmediaplayer.hxx @@ -115,6 +115,7 @@ namespace NxWM * Media player state data. */ + FAR struct nxplayer_s *m_player; /**< NxPlayer handle */ enum EMediaPlayerState m_state; /**< Media player current state */ enum EMediaPlayerState m_prevState; /**< Media player previous state */ enum EPendingRelease m_pending; /**< Pending image release event */ @@ -184,7 +185,21 @@ namespace NxWM * Load media files into the list box. */ - inline bool showMediaFiles(const char *mediaPath); + inline bool showMediaFiles(FAR const char *mediaPath); + +#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE + /** + * Set the preferred audio device for playback + */ + + inline bool setDevice(FAR const char *devPath); +#endif + + /** + * Configure the NxPlayer. + */ + + inline bool configureNxPlayer(void); /** * Create the Media Player controls. Only start as part of the application diff --git a/NxWidgets/nxwm/include/nxwmconfig.hxx b/NxWidgets/nxwm/include/nxwmconfig.hxx index 75f860c9d..b2c3f4c54 100644 --- a/NxWidgets/nxwm/include/nxwmconfig.hxx +++ b/NxWidgets/nxwm/include/nxwmconfig.hxx @@ -632,6 +632,10 @@ * Default: CONFIG_NXWM_DEFAULT_FONTID */ +#ifndef CONFIG_NXWM_MEDIAPLAYER_PREFERRED_DEVICE +# define CONFIG_NXWM_MEDIAPLAYER_PREFERRED_DEVICE "pcm0" +#endif + #ifndef CONFIG_NXWM_MEDIAPLAYER_MEDIAPATH # define CONFIG_NXWM_MEDIAPLAYER_MEDIAPATH "/mnt/sdcard" #endif diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx index d94b57369..f31a4567a 100644 --- a/NxWidgets/nxwm/src/cmediaplayer.cxx +++ b/NxWidgets/nxwm/src/cmediaplayer.cxx @@ -42,9 +42,12 @@ #include #include +#include #include #include +#include + #include "cwidgetcontrol.hxx" #include "nxwmconfig.hxx" @@ -108,6 +111,7 @@ CMediaPlayer::CMediaPlayer(CTaskbar *taskbar, CApplicationWindow *window) // Initial state is stopped + m_player = (FAR struct nxplayer_s *)0; m_state = MPLAYER_STOPPED; m_prevState = MPLAYER_STOPPED; m_pending = PENDING_NONE; @@ -199,6 +203,13 @@ CMediaPlayer::~CMediaPlayer(void) delete m_volumeBitmap; } + // Release the NxPlayer + + if (m_player) + { + nxplayer_release(m_player); + } + // Although we didn't create it, we are responsible for deleting the // application window @@ -250,10 +261,19 @@ NXWidgets::CNxString CMediaPlayer::getName(void) bool CMediaPlayer::run(void) { - // Create the widgets (if we have not already done so) + // Configure the NxPlayer and create the widgets (if we have not already + // done so) - if (!m_listbox) + if (!m_player) { + // Configure the NxPlayer library and player thread + + if (!configureNxPlayer()) + { + gdbg("ERROR: Failed to configure NxPlayer\n"); + return false; + } + // Create the widgets if (!createPlayer()) @@ -485,6 +505,92 @@ inline bool CMediaPlayer::showMediaFiles(const char *mediaPath) return true; } +/** + * Set the preferred audio device for playback + */ + +#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE +bool CMediaPlayer::setDevice(FAR const char *devPath) +{ + // First try to open the file using the device name as provided + + int ret = nxplayer_setdevice(m_player, devPath); + if (ret == -ENOENT) + { + char path[32]; + + // Append the device path and try again + +#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH +#ifdef CONFIG_AUDIO_DEV_ROOT + std::snprintf(path, sizeof(path), "/dev/%s", devPath); +#else + std::snprintf(path, sizeof(path), CONFIG_AUDIO_DEV_PATH "/%s", devPath); +#endif +#else + std::snprintf(path, sizeof(path), "/dev/audio/%s", devPath); +#endif + ret = nxplayer_setdevice(m_player, path); + } + + // Test if the device file exists + + if (ret == -ENOENT) + { + // Device doesn't exit. Report an error + + gdbg("ERROR: Device %s not found\n", devPath); + return false; + } + + // Test if is is an audio device + + if (ret == -ENODEV) + { + gdbg("ERROR: Device %s is not an audio device\n", devPath); + return false; + } + + if (ret < 0) + { + gdbg("ERROR: Error selecting device %s\n", devPath); + return false; + } + + // Device set successfully + + return true; +} +#endif + +/** + * Configure the NxPlayer. + */ + +bool CMediaPlayer::configureNxPlayer(void) +{ + // Get the NxPlayer handle + + m_player = nxplayer_create(); + if (!m_player) + { + gdbg("ERROR: Failed get NxPlayer handle\n"); + return false; + } + +#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE + // Set the NxPlayer audio device + + if (!setDevice(CONFIG_NXWM_MEDIAPLAYER_PREFERRED_DEVICE)) + { + gdbg("ERROR: Failed select NxPlayer audio device\n"); + return false; + } +#endif + + return true; +} + /** * Create the media player widgets. Only start as part of the application * start method. @@ -499,7 +605,7 @@ bool CMediaPlayer::createPlayer(void) CONFIG_NXWM_TRANSPARENT_COLOR); if (!m_font) { - gdbg("ERROR failed to create font\n"); + gdbg("ERROR: Failed to create font\n"); return false; } -- cgit v1.2.3