2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/system/nxplayer/nxplayer_main.c
|
|
|
|
*
|
2021-06-10 13:17:16 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
2021-06-10 13:17:16 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
2021-06-10 13:17:16 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/audio/audio.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2016-07-11 18:11:18 +02:00
|
|
|
#include "system/readline.h"
|
|
|
|
#include "system/nxplayer.h"
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2013-10-27 14:45:16 +01:00
|
|
|
* Pre-processor Definitions
|
2013-10-27 14:23:01 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
#define NXPLAYER_VER "1.05"
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_HELP
|
2020-08-22 19:22:41 +02:00
|
|
|
# define NXPLAYER_HELP_TEXT(x) x
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
|
|
|
# define NXPLAYER_HELP_TEXT(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Declarations
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
struct mp_cmd_s
|
|
|
|
{
|
2013-10-27 14:23:01 +01:00
|
|
|
const char *cmd; /* The command text */
|
|
|
|
const char *arghelp; /* Text describing the args */
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_func pfunc; /* Pointer to command handler */
|
2013-10-27 14:23:01 +01:00
|
|
|
const char *help; /* The help text */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
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_playraw(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_SYSTEM_RESET
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_reset(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_device(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_pause(FAR struct nxplayer_s *pplayer, char *parg);
|
|
|
|
static int nxplayer_cmd_resume(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_mediadir(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_stop(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_volume(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_balance(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_bass(FAR struct nxplayer_s *pplayer, char *parg);
|
|
|
|
static int nxplayer_cmd_treble(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_HELP
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_help(FAR struct nxplayer_s *pplayer, char *parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-10-27 14:45:16 +01:00
|
|
|
static struct mp_cmd_s g_nxplayer_cmds[] =
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"balance",
|
|
|
|
"d%",
|
|
|
|
nxplayer_cmd_balance,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Set balance percentage (< 50% means more left)")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"bass",
|
|
|
|
"d%",
|
|
|
|
nxplayer_cmd_bass,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Set bass level percentage")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"device",
|
|
|
|
"devfile",
|
|
|
|
nxplayer_cmd_device,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Specify a preferred audio device")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_HELP
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"h",
|
|
|
|
"",
|
|
|
|
nxplayer_cmd_help,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Display help for commands")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"help",
|
|
|
|
"",
|
|
|
|
nxplayer_cmd_help,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Display help for commands")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"mediadir",
|
|
|
|
"path",
|
|
|
|
nxplayer_cmd_mediadir,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Change the media directory")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
"play",
|
|
|
|
"filename",
|
|
|
|
nxplayer_cmd_play,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Play a media file")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"playraw",
|
|
|
|
"filename",
|
|
|
|
nxplayer_cmd_playraw,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Play a raw data file")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"pause",
|
|
|
|
"",
|
|
|
|
nxplayer_cmd_pause,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Pause playback")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_SYSTEM_RESET
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"reset",
|
|
|
|
"",
|
|
|
|
nxplayer_cmd_reset,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Perform a HW reset")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"resume",
|
|
|
|
"",
|
|
|
|
nxplayer_cmd_resume,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Resume playback")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"stop",
|
|
|
|
"",
|
|
|
|
nxplayer_cmd_stop,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Stop playback")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
"tone",
|
|
|
|
"freq secs",
|
|
|
|
NULL,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Produce a pure tone")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"treble",
|
|
|
|
"d%",
|
|
|
|
nxplayer_cmd_treble,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Set treble level percentage")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
"q",
|
|
|
|
"",
|
|
|
|
nxplayer_cmd_quit,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Exit NxPlayer")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"quit",
|
|
|
|
"",
|
|
|
|
nxplayer_cmd_quit,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Exit NxPlayer")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"volume",
|
|
|
|
"d%",
|
|
|
|
nxplayer_cmd_volume,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXPLAYER_HELP_TEXT("Set volume to level specified")
|
2020-04-21 17:32:44 +02:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static const int g_nxplayer_cmd_count = sizeof(g_nxplayer_cmds) /
|
|
|
|
sizeof(struct mp_cmd_s);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_play
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_play() plays the specified media file using the nxplayer
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_play(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Try to play the file specified */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxplayer_playfile(pplayer, parg, AUDIO_FMT_UNDEF, AUDIO_FMT_UNDEF);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-07-22 17:27:24 +02:00
|
|
|
/* 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
|
|
|
|
*/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:03 +02:00
|
|
|
switch (-ret)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2014-08-05 18:04:03 +02:00
|
|
|
case OK:
|
|
|
|
break;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:03 +02:00
|
|
|
case ENODEV:
|
|
|
|
printf("No suitable Audio Device found\n");
|
|
|
|
break;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:03 +02:00
|
|
|
case EBUSY:
|
|
|
|
printf("Audio device busy\n");
|
|
|
|
break;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:03 +02:00
|
|
|
case ENOENT:
|
|
|
|
printf("File %s not found\n", parg);
|
|
|
|
break;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:03 +02:00
|
|
|
case ENOSYS:
|
|
|
|
printf("Unknown audio format\n");
|
|
|
|
break;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:03 +02:00
|
|
|
default:
|
|
|
|
printf("Error playing file: %d\n", -ret);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:03 +02:00
|
|
|
return ret;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
2018-08-27 16:04:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_playraw
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_play() plays the raw data file using the nxplayer
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_playraw(FAR struct nxplayer_s *pplayer, char *parg)
|
2018-08-27 16:04:48 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int channels = 0;
|
|
|
|
int bpsamp = 0;
|
|
|
|
int samprate = 0;
|
2020-09-12 09:19:01 +02:00
|
|
|
int chmap = 0;
|
2018-08-27 16:04:48 +02:00
|
|
|
char filename[128];
|
|
|
|
|
2020-09-27 09:48:28 +02:00
|
|
|
sscanf(parg, "%s %d %d %d %d", filename, &channels, &bpsamp,
|
|
|
|
&samprate, &chmap);
|
2018-08-27 16:04:48 +02:00
|
|
|
|
|
|
|
/* Try to play the file specified */
|
|
|
|
|
2020-09-12 09:19:01 +02:00
|
|
|
ret = nxplayer_playraw(pplayer, filename, channels,
|
|
|
|
bpsamp, samprate, chmap);
|
2018-08-27 16:04:48 +02:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_volume
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_volume() sets the volume level.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_volume(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
uint16_t percent;
|
|
|
|
|
|
|
|
/* If no arg given, then print current volume */
|
|
|
|
|
|
|
|
if (parg == NULL || *parg == '\0')
|
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
printf("volume: %d\n", pplayer->volume / 10);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the percentage value from the argument */
|
|
|
|
|
|
|
|
percent = (uint16_t) (atof(parg) * 10.0);
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_setvolume(pplayer, percent);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_bass
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_bass() sets the bass level and range.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_bass(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
uint8_t level_percent;
|
|
|
|
|
|
|
|
/* If no arg given, then print current bass */
|
|
|
|
|
|
|
|
if (parg == NULL || *parg == '\0')
|
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
printf("bass: %d\n", pplayer->bass);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the level and range percentage value from the argument */
|
|
|
|
|
|
|
|
level_percent = (uint8_t) atoi(parg);
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_setbass(pplayer, level_percent);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_treble
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_treble() sets the treble level and range.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_treble(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
uint8_t level_percent;
|
|
|
|
|
|
|
|
/* If no arg given, then print current bass */
|
|
|
|
|
|
|
|
if (parg == NULL || *parg == '\0')
|
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
printf("treble: %d\n", pplayer->treble);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the level and range percentage value from the argument */
|
|
|
|
|
|
|
|
level_percent = (uint8_t) atoi(parg);
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_settreble(pplayer, level_percent);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_balance
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_balance() sets the balance level.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_balance(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
uint16_t percent;
|
|
|
|
|
2022-04-10 19:39:32 +02:00
|
|
|
/* If no arg given, then print current balance */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
if (parg == NULL || *parg == '\0')
|
|
|
|
{
|
2022-04-10 19:39:32 +02:00
|
|
|
printf("balance: %d\n", pplayer->balance / 10);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the percentage value from the argument */
|
|
|
|
|
|
|
|
percent = (uint16_t) (atof(parg) * 10.0);
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_setbalance(pplayer, percent);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_reset
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_reset() performs a HW reset of all the audio devices.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_SYSTEM_RESET
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_reset(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_systemreset(pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_mediadir
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_mediadir() displays or changes the media directory
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_mediadir(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* If no arg given, then print current media dir */
|
|
|
|
|
|
|
|
if (parg == NULL || *parg == '\0')
|
2020-04-21 17:32:44 +02:00
|
|
|
printf("%s\n", pplayer->mediadir);
|
2013-10-27 14:23:01 +01:00
|
|
|
else
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_setmediadir(pplayer, parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_stop
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_stop() stops playback of currently playing file
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_stop(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Stop the playback */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_stop(pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_pause
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_pause() pauses playback of currently playing file
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_pause(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Pause the playback */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_pause(pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_resume
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_resume() resumes playback of currently playing file
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_resume(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Resume the playback */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_resume(pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_device
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_device() sets the preferred audio device for playback
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_device(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
system: Fix nx[looper|player|recorder] warning
nxlooper.c:879:7: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
879 | strncpy(plooper->recorddev, pdevice, sizeof(plooper->playdev));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxlooper.c:875:7: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
875 | strncpy(plooper->playdev, pdevice, sizeof(plooper->playdev));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxlooper.c: In function 'nxlooper_loopraw':
nxlooper.c:165:52: warning: '%s' directive output may be truncated writing up to 96 bytes into a region of size 53 [-Wformat-truncation=]
165 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~
nxlooper.c:165:11: note: 'snprintf' output between 12 and 108 bytes into a destination of size 64
165 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxplayer.c: In function 'nxplayer_playinternal':
nxplayer.c:359:53: warning: '%s' directive output may be truncated writing up to 96 bytes into a region of size 53 [-Wformat-truncation=]
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~
nxplayer.c:359:11: note: 'snprintf' output between 12 and 108 bytes into a destination of size 64
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxrecorder.c: In function 'nxrecorder_setdevice':
nxrecorder.c:695:3: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
695 | strncpy(precorder->device, pdevice, sizeof(precorder->device));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxplayer.c: In function 'nxplayer_setdevice':
nxplayer.c:1686:3: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
1686 | strncpy(pplayer->prefdevice, pdevice, sizeof(pplayer->prefdevice));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC: nxrecorder_main.c
nxplayer.c: In function 'nxplayer_setmediadir':
nxplayer.c:2090:3: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
2090 | strncpy(pplayer->mediadir, mediadir, sizeof(pplayer->mediadir));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-21 19:09:07 +01:00
|
|
|
int ret;
|
|
|
|
char path[PATH_MAX];
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* First try to open the file directly */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxplayer_setdevice(pplayer, parg);
|
2013-10-27 14:23:01 +01:00
|
|
|
if (ret == -ENOENT)
|
|
|
|
{
|
|
|
|
/* Append the /dev/audio path and try again */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH
|
|
|
|
#ifdef CONFIG_AUDIO_DEV_ROOT
|
|
|
|
snprintf(path, sizeof(path), "/dev/%s", parg);
|
|
|
|
#else
|
|
|
|
snprintf(path, sizeof(path), CONFIG_AUDIO_DEV_PATH "/%s", parg);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
snprintf(path, sizeof(path), "/dev/audio/%s", parg);
|
|
|
|
#endif
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxplayer_setdevice(pplayer, path);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test if the device file exists */
|
|
|
|
|
|
|
|
if (ret == -ENOENT)
|
|
|
|
{
|
|
|
|
/* Device doesn't exit. Report error */
|
|
|
|
|
|
|
|
printf("Device %s not found\n", parg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test if is is an audio device */
|
|
|
|
|
|
|
|
if (ret == -ENODEV)
|
|
|
|
{
|
|
|
|
printf("Device %s is not an audio device\n", parg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2013-10-27 14:45:16 +01:00
|
|
|
return ret;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Device set successfully */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_quit
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_quit() terminates the application
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_quit(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2013-10-28 19:11:52 +01:00
|
|
|
/* Stop the playback if any */
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_stop(pplayer);
|
2013-10-28 19:11:52 +01:00
|
|
|
#endif
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cmd_help
|
|
|
|
*
|
|
|
|
* nxplayer_cmd_help() displays the application's help information on
|
|
|
|
* supported commands and command syntax.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_HELP
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxplayer_cmd_help(FAR struct nxplayer_s *pplayer, char *parg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
int len;
|
|
|
|
int maxlen = 0;
|
|
|
|
int x;
|
2013-10-27 14:23:01 +01:00
|
|
|
int c;
|
|
|
|
|
|
|
|
/* Calculate length of longest cmd + arghelp */
|
|
|
|
|
|
|
|
for (x = 0; x < g_nxplayer_cmd_count; x++)
|
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
len = strlen(g_nxplayer_cmds[x].cmd) +
|
|
|
|
strlen(g_nxplayer_cmds[x].arghelp);
|
2013-10-27 14:23:01 +01:00
|
|
|
if (len > maxlen)
|
2019-11-20 14:41:05 +01:00
|
|
|
{
|
|
|
|
maxlen = len;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("NxPlayer commands\n================\n");
|
|
|
|
for (x = 0; x < g_nxplayer_cmd_count; x++)
|
|
|
|
{
|
|
|
|
/* Print the command and it's arguments */
|
|
|
|
|
|
|
|
printf(" %s %s", g_nxplayer_cmds[x].cmd, g_nxplayer_cmds[x].arghelp);
|
|
|
|
|
|
|
|
/* Calculate number of spaces to print before the help text */
|
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
len = maxlen - (strlen(g_nxplayer_cmds[x].cmd) +
|
|
|
|
strlen(g_nxplayer_cmds[x].arghelp));
|
2013-10-27 14:23:01 +01:00
|
|
|
for (c = 0; c < len; c++)
|
2019-11-20 14:41:05 +01:00
|
|
|
{
|
|
|
|
printf(" ");
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
printf(" : %s\n", g_nxplayer_cmds[x].help);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer
|
|
|
|
*
|
|
|
|
* nxplayer() reads in commands from the console using the readline
|
2019-11-20 14:41:05 +01:00
|
|
|
* system add-in and impalements a command-line based media player that
|
2013-10-27 14:23:01 +01:00
|
|
|
* uses the NuttX audio system to play media files read in from the
|
2013-10-27 14:45:16 +01:00
|
|
|
* file system. Commands are provided for setting volume, base and
|
2019-11-20 14:41:05 +01:00
|
|
|
* other audio features, as well as for pausing and stopping the
|
2013-10-27 14:23:01 +01:00
|
|
|
* playback.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* buf - The user allocated buffer to be filled.
|
|
|
|
* buflen - the size of the buffer.
|
|
|
|
* instream - The stream to read characters from
|
|
|
|
* outstream - The stream to each characters to.
|
|
|
|
*
|
|
|
|
* Returned values:
|
|
|
|
* On success, the (positive) number of bytes transferred is returned.
|
|
|
|
* EOF is returned to indicate either an end of file condition or a
|
|
|
|
* failure.
|
|
|
|
*
|
2015-10-03 01:33:30 +02:00
|
|
|
****************************************************************************/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
char buffer[CONFIG_NSH_LINELEN];
|
system: Fix nx[looper|player|recorder] warning
nxlooper.c:879:7: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
879 | strncpy(plooper->recorddev, pdevice, sizeof(plooper->playdev));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxlooper.c:875:7: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
875 | strncpy(plooper->playdev, pdevice, sizeof(plooper->playdev));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxlooper.c: In function 'nxlooper_loopraw':
nxlooper.c:165:52: warning: '%s' directive output may be truncated writing up to 96 bytes into a region of size 53 [-Wformat-truncation=]
165 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~
nxlooper.c:165:11: note: 'snprintf' output between 12 and 108 bytes into a destination of size 64
165 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxplayer.c: In function 'nxplayer_playinternal':
nxplayer.c:359:53: warning: '%s' directive output may be truncated writing up to 96 bytes into a region of size 53 [-Wformat-truncation=]
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~
nxplayer.c:359:11: note: 'snprintf' output between 12 and 108 bytes into a destination of size 64
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxrecorder.c: In function 'nxrecorder_setdevice':
nxrecorder.c:695:3: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
695 | strncpy(precorder->device, pdevice, sizeof(precorder->device));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nxplayer.c: In function 'nxplayer_setdevice':
nxplayer.c:1686:3: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
1686 | strncpy(pplayer->prefdevice, pdevice, sizeof(pplayer->prefdevice));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC: nxrecorder_main.c
nxplayer.c: In function 'nxplayer_setmediadir':
nxplayer.c:2090:3: warning: 'strncpy' specified bound 96 equals destination size [-Wstringop-truncation]
2090 | strncpy(pplayer->mediadir, mediadir, sizeof(pplayer->mediadir));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-21 19:09:07 +01:00
|
|
|
int len;
|
|
|
|
int x;
|
|
|
|
int running;
|
|
|
|
char *cmd;
|
|
|
|
char *arg;
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR struct nxplayer_s *pplayer;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
printf("NxPlayer version " NXPLAYER_VER "\n");
|
|
|
|
printf("h for commands, q to exit\n");
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* Initialize our NxPlayer context */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
pplayer = nxplayer_create();
|
|
|
|
if (pplayer == NULL)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
printf("Error: Out of RAM\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop until the user exits */
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
running = TRUE;
|
|
|
|
while (running)
|
|
|
|
{
|
|
|
|
/* Print a prompt */
|
|
|
|
|
|
|
|
printf("nxplayer> ");
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
/* Read a line from the terminal */
|
|
|
|
|
|
|
|
len = readline(buffer, sizeof(buffer), stdin, stdout);
|
|
|
|
buffer[len] = '\0';
|
|
|
|
if (len > 0)
|
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
if (strncmp(buffer, "!", 1) != 0)
|
|
|
|
{
|
|
|
|
/* nxplayer command */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
if (buffer[len - 1] == '\n')
|
|
|
|
{
|
|
|
|
buffer[len - 1] = '\0';
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
/* Parse the command from the argument */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
cmd = strtok_r(buffer, " \n", &arg);
|
|
|
|
if (cmd == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
/* Remove leading spaces from arg */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
while (*arg == ' ')
|
|
|
|
{
|
|
|
|
arg++;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
/* Find the command in our cmd array */
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
for (x = 0; x < g_nxplayer_cmd_count; x++)
|
|
|
|
{
|
|
|
|
if (strcmp(cmd, g_nxplayer_cmds[x].cmd) == 0)
|
|
|
|
{
|
|
|
|
/* Command found. Call it's handler if not NULL */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (g_nxplayer_cmds[x].pfunc != NULL)
|
2019-11-20 14:41:05 +01:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
g_nxplayer_cmds[x].pfunc(pplayer, arg);
|
2019-11-20 14:41:05 +01:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
/* Test if it is a quit command */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (g_nxplayer_cmds[x].pfunc == nxplayer_cmd_quit)
|
2019-11-20 14:41:05 +01:00
|
|
|
{
|
|
|
|
running = FALSE;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYSTEM_SYSTEM
|
|
|
|
/* Transfer nuttx shell */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
system(buffer + 1);
|
|
|
|
#else
|
|
|
|
printf("%s: unknown nxplayer command\n", buffer);
|
|
|
|
#endif
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the NxPlayer context */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
/* nxplayer_detach(pplayer); */
|
2019-11-20 14:41:05 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
nxplayer_release(pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|