system/nxplayer/nxplayer.c: Add playraw command
This commit is contained in:
parent
7eacf7daa2
commit
09a3bc44b4
@ -207,6 +207,30 @@ int nxplayer_setdevice(FAR struct nxplayer_s *pPlayer,
|
|||||||
int nxplayer_playfile(FAR struct nxplayer_s *pPlayer,
|
int nxplayer_playfile(FAR struct nxplayer_s *pPlayer,
|
||||||
FAR const char *filename, int filefmt, int subfmt);
|
FAR const char *filename, int filefmt, int subfmt);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxplayer_playraw
|
||||||
|
*
|
||||||
|
* Plays the specified media file (from the filesystem) using the
|
||||||
|
* Audio system. If a preferred device has been set, that device
|
||||||
|
* will be used for the playback, otherwise the first suitable device
|
||||||
|
* found in the /dev/audio directory will be used.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* pPlayer - Pointer to the context to initialize
|
||||||
|
* filename - Pointer to pathname of the file to play
|
||||||
|
* nchannels channel num
|
||||||
|
* bpsampe bit width
|
||||||
|
* samprate sample rate
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* OK if file found, device found, and playback started.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int nxplayer_playraw(FAR struct nxplayer_s *pPlayer,
|
||||||
|
FAR const char *filename, uint8_t nchannels,
|
||||||
|
uint8_t bpsamp, uint32_t samprate);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: nxplayer_stop
|
* Name: nxplayer_stop
|
||||||
*
|
*
|
||||||
|
@ -1775,18 +1775,21 @@ int nxplayer_stop(FAR struct nxplayer_s *pPlayer)
|
|||||||
#endif /* CONFIG_AUDIO_EXCLUDE_STOP */
|
#endif /* CONFIG_AUDIO_EXCLUDE_STOP */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: nxplayer_playfile
|
* Name: nxplayer_playinternal
|
||||||
*
|
*
|
||||||
* nxplayer_playfile() tries to play the specified file using the Audio
|
* nxplayer_playinternal() tries to play the specified file/raw data
|
||||||
* system. If a preferred device is specified, it will try to use that
|
* using the Audio system. If a preferred device is specified, it will
|
||||||
* device otherwise it will perform a search of the Audio device files
|
* try to use that device otherwise it will perform a search of the Audio
|
||||||
* to find a suitable device.
|
* device files to find a suitable device.
|
||||||
*
|
*
|
||||||
* Input:
|
* Input:
|
||||||
* pPlayer Pointer to the initialized MPlayer context
|
* pPlayer Pointer to the initialized MPlayer context
|
||||||
* pFilename Pointer to the filename to play
|
* pFilename Pointer to the filename to play
|
||||||
* filefmt Format of the file or AUD_FMT_UNDEF if unknown / to be
|
* filefmt Format of the file or AUD_FMT_UNDEF if unknown / to be
|
||||||
* determined by nxplayer_playfile()
|
* determined by nxplayer_playfile()
|
||||||
|
* nchannels channels num (raw data playback needed)
|
||||||
|
* bpsamp bits pre sample (raw data playback needed)
|
||||||
|
* samplrate samplre rate (raw data playback needed)
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* OK File is being played
|
* OK File is being played
|
||||||
@ -1795,15 +1798,19 @@ int nxplayer_stop(FAR struct nxplayer_s *pPlayer)
|
|||||||
* -ENODEV No audio device suitable to play the media type
|
* -ENODEV No audio device suitable to play the media type
|
||||||
* -ENOENT The media file was not found
|
* -ENOENT The media file was not found
|
||||||
*
|
*
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int nxplayer_playfile(FAR struct nxplayer_s *pPlayer,
|
static int nxplayer_playinternal(FAR struct nxplayer_s *pPlayer,
|
||||||
FAR const char *pFilename, int filefmt, int subfmt)
|
FAR const char *pFilename, int filefmt,
|
||||||
|
int subfmt, uint8_t nchannels,
|
||||||
|
uint8_t bpsamp, uint32_t samprate)
|
||||||
{
|
{
|
||||||
struct mq_attr attr;
|
struct mq_attr attr;
|
||||||
struct sched_param sparam;
|
struct sched_param sparam;
|
||||||
pthread_attr_t tattr;
|
pthread_attr_t tattr;
|
||||||
void *value;
|
FAR void *value;
|
||||||
|
struct audio_caps_desc_s cap_desc;
|
||||||
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
||||||
char path[128];
|
char path[128];
|
||||||
#endif
|
#endif
|
||||||
@ -1922,6 +1929,21 @@ int nxplayer_playfile(FAR struct nxplayer_s *pPlayer,
|
|||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nchannels && samprate && bpsamp)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||||
|
cap_desc.session = pPlayer->session;
|
||||||
|
#endif
|
||||||
|
cap_desc.caps.ac_len = sizeof(struct audio_caps_s);
|
||||||
|
cap_desc.caps.ac_type = AUDIO_TYPE_OUTPUT;
|
||||||
|
cap_desc.caps.ac_channels = nchannels;
|
||||||
|
cap_desc.caps.ac_controls.hw[0] = samprate;
|
||||||
|
cap_desc.caps.ac_controls.b[3] = samprate >> 16;
|
||||||
|
cap_desc.caps.ac_controls.b[2] = bpsamp;
|
||||||
|
|
||||||
|
ioctl(pPlayer->devFd, AUDIOIOC_CONFIGURE, (unsigned long)&cap_desc);
|
||||||
|
}
|
||||||
|
|
||||||
/* Create a message queue for the playthread */
|
/* Create a message queue for the playthread */
|
||||||
|
|
||||||
attr.mq_maxmsg = 16;
|
attr.mq_maxmsg = 16;
|
||||||
@ -1997,6 +2019,82 @@ err_out_nodev:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxplayer_playfile
|
||||||
|
*
|
||||||
|
* nxplayer_playfile() tries to play the specified file using the Audio
|
||||||
|
* system. If a preferred device is specified, it will try to use that
|
||||||
|
* device otherwise it will perform a search of the Audio device files
|
||||||
|
* to find a suitable device.
|
||||||
|
*
|
||||||
|
* Input:
|
||||||
|
* pPlayer Pointer to the initialized MPlayer context
|
||||||
|
* pFilename Pointer to the filename to play
|
||||||
|
* filefmt Format of the file or AUD_FMT_UNDEF if unknown / to be
|
||||||
|
* determined by nxplayer_playfile()
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* OK File is being played
|
||||||
|
* -EBUSY The media device is busy
|
||||||
|
* -ENOSYS The media file is an unsupported type
|
||||||
|
* -ENODEV No audio device suitable to play the media type
|
||||||
|
* -ENOENT The media file was not found
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int nxplayer_playfile(FAR struct nxplayer_s *pPlayer,
|
||||||
|
FAR const char *pFilename, int filefmt, int subfmt)
|
||||||
|
{
|
||||||
|
return nxplayer_playinternal(pPlayer, pFilename, filefmt, subfmt, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxplayer_playraw
|
||||||
|
*
|
||||||
|
* nxplayer_playraw() tries to play the raw data file using the Audio
|
||||||
|
* system. If a preferred device is specified, it will try to use that
|
||||||
|
* device otherwise it will perform a search of the Audio device files
|
||||||
|
* to find a suitable device.
|
||||||
|
*
|
||||||
|
* Input:
|
||||||
|
* pPlayer Pointer to the initialized MPlayer context
|
||||||
|
* pFilename Pointer to the filename to play
|
||||||
|
* nchannels channel num
|
||||||
|
* bpsampe bit width
|
||||||
|
* samprate sample rate
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* OK File is being played
|
||||||
|
* -EBUSY The media device is busy
|
||||||
|
* -ENOSYS The media file is an unsupported type
|
||||||
|
* -ENODEV No audio device suitable to play the media type
|
||||||
|
* -ENOENT The media file was not found
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int nxplayer_playraw(FAR struct nxplayer_s *pPlayer,
|
||||||
|
FAR const char *pFilename, uint8_t nchannels,
|
||||||
|
uint8_t bpsamp, uint32_t samprate)
|
||||||
|
{
|
||||||
|
if (nchannels == 0)
|
||||||
|
{
|
||||||
|
nchannels = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bpsamp == 0)
|
||||||
|
{
|
||||||
|
bpsamp = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (samprate == 0)
|
||||||
|
{
|
||||||
|
samprate = 48000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nxplayer_playinternal(pPlayer, pFilename, AUDIO_FMT_PCM, 0,
|
||||||
|
nchannels, bpsamp, samprate);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: nxplayer_setmediadir
|
* Name: nxplayer_setmediadir
|
||||||
*
|
*
|
||||||
|
@ -81,6 +81,7 @@ struct mp_cmd_s {
|
|||||||
|
|
||||||
static int nxplayer_cmd_quit(FAR struct nxplayer_s *pPlayer, char *parg);
|
static int nxplayer_cmd_quit(FAR struct nxplayer_s *pPlayer, char *parg);
|
||||||
static int nxplayer_cmd_play(FAR struct nxplayer_s *pPlayer, char *parg);
|
static int nxplayer_cmd_play(FAR struct nxplayer_s *pPlayer, char *parg);
|
||||||
|
static int nxplayer_cmd_playraw(FAR struct nxplayer_s *pPlayer, char *parg);
|
||||||
|
|
||||||
#ifdef CONFIG_NXPLAYER_INCLUDE_SYSTEM_RESET
|
#ifdef CONFIG_NXPLAYER_INCLUDE_SYSTEM_RESET
|
||||||
static int nxplayer_cmd_reset(FAR struct nxplayer_s *pPlayer, char *parg);
|
static int nxplayer_cmd_reset(FAR struct nxplayer_s *pPlayer, char *parg);
|
||||||
@ -144,6 +145,7 @@ static struct mp_cmd_s g_nxplayer_cmds[] =
|
|||||||
{ "mediadir", "path", nxplayer_cmd_mediadir, NXPLAYER_HELP_TEXT(Change the media directory) },
|
{ "mediadir", "path", nxplayer_cmd_mediadir, NXPLAYER_HELP_TEXT(Change the media directory) },
|
||||||
#endif
|
#endif
|
||||||
{ "play", "filename", nxplayer_cmd_play, NXPLAYER_HELP_TEXT(Play a media file) },
|
{ "play", "filename", nxplayer_cmd_play, NXPLAYER_HELP_TEXT(Play a media file) },
|
||||||
|
{ "playraw", "filename", nxplayer_cmd_playraw, NXPLAYER_HELP_TEXT(Play a raw data file) },
|
||||||
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
||||||
{ "pause", "", nxplayer_cmd_pause, NXPLAYER_HELP_TEXT(Pause playback) },
|
{ "pause", "", nxplayer_cmd_pause, NXPLAYER_HELP_TEXT(Pause playback) },
|
||||||
#endif
|
#endif
|
||||||
@ -227,6 +229,66 @@ static int nxplayer_cmd_play(FAR struct nxplayer_s *pPlayer, char *parg)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxplayer_cmd_playraw
|
||||||
|
*
|
||||||
|
* nxplayer_cmd_play() plays the raw data file using the nxplayer
|
||||||
|
* context.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int nxplayer_cmd_playraw(FAR struct nxplayer_s *pPlayer, char *parg)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int channels = 0;
|
||||||
|
int bpsamp = 0;
|
||||||
|
int samprate = 0;
|
||||||
|
char filename[128];
|
||||||
|
|
||||||
|
sscanf(parg, "%s %d %d %d", filename, &channels, &bpsamp, &samprate);
|
||||||
|
|
||||||
|
/* Try to play the file specified */
|
||||||
|
|
||||||
|
ret = nxplayer_playraw(pPlayer, filename, channels, bpsamp, samprate);
|
||||||
|
|
||||||
|
/* nxplayer_playfile returned values:
|
||||||
|
*
|
||||||
|
* OK File is being played
|
||||||
|
* -EBUSY The media device is busy
|
||||||
|
* -ENOSYS The media file is an unsupported type
|
||||||
|
* -ENODEV No audio device suitable to play the media type
|
||||||
|
* -ENOENT The media file was not found
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch (-ret)
|
||||||
|
{
|
||||||
|
case OK:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENODEV:
|
||||||
|
printf("No suitable Audio Device found\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EBUSY:
|
||||||
|
printf("Audio device busy\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENOENT:
|
||||||
|
printf("File %s not found\n", filename);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENOSYS:
|
||||||
|
printf("Unknown audio format\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("Error playing file: %d\n", -ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: nxplayer_cmd_volume
|
* Name: nxplayer_cmd_volume
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user