2018-08-27 16:20:11 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/system/nxrecorder/nxrecorder_main.c
|
|
|
|
*
|
2020-08-22 18:45:58 +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
|
2018-08-27 16:20:11 +02:00
|
|
|
*
|
2020-08-22 18:45:58 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-08-27 16:20:11 +02:00
|
|
|
*
|
2020-08-22 18:45:58 +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.
|
2018-08-27 16:20:11 +02: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>
|
|
|
|
|
|
|
|
#include "system/readline.h"
|
|
|
|
#include "system/nxrecorder.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define NXRECORDER_VER "1.00"
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXRECORDER_INCLUDE_HELP
|
2020-08-22 19:22:41 +02:00
|
|
|
# define NXRECORDER_HELP_TEXT(x) x
|
2018-08-27 16:20:11 +02:00
|
|
|
#else
|
|
|
|
# define NXRECORDER_HELP_TEXT(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Declarations
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct mp_cmd_s
|
|
|
|
{
|
|
|
|
const char *cmd; /* The command text */
|
|
|
|
const char *arghelp; /* Text describing the args */
|
2020-04-21 17:32:44 +02:00
|
|
|
nxrecorder_func pfunc; /* Pointer to command handler */
|
2018-08-27 16:20:11 +02:00
|
|
|
const char *help; /* The help text */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_quit(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg);
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_recordraw(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg);
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_device(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_pause(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg);
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_resume(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg);
|
2018-08-27 16:20:11 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_stop(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg);
|
2018-08-27 16:20:11 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXRECORDER_INCLUDE_HELP
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_help(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg);
|
2018-08-27 16:20:11 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const struct mp_cmd_s g_nxrecorder_cmds[] =
|
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"device",
|
|
|
|
"devfile",
|
|
|
|
nxrecorder_cmd_device,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Specify a preferred audio device")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2018-08-27 16:20:11 +02:00
|
|
|
#ifdef CONFIG_NXRECORDER_INCLUDE_HELP
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"h",
|
|
|
|
"",
|
|
|
|
nxrecorder_cmd_help,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Display help for commands")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"help",
|
|
|
|
"",
|
|
|
|
nxrecorder_cmd_help,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Display help for commands")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2018-08-27 16:20:11 +02:00
|
|
|
#endif
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"recordraw",
|
|
|
|
"filename",
|
|
|
|
nxrecorder_cmd_recordraw,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Record a pcm raw file")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2018-08-27 16:20:11 +02:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"pause",
|
|
|
|
"",
|
|
|
|
nxrecorder_cmd_pause,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Pause record")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"resume",
|
|
|
|
"",
|
|
|
|
nxrecorder_cmd_resume,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Resume record")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2018-08-27 16:20:11 +02:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"stop",
|
|
|
|
"",
|
|
|
|
nxrecorder_cmd_stop,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Stop record")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2018-08-27 16:20:11 +02:00
|
|
|
#endif
|
2020-04-21 17:32:44 +02:00
|
|
|
{
|
|
|
|
"q",
|
|
|
|
"",
|
|
|
|
nxrecorder_cmd_quit,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Exit NxRecorder")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"quit",
|
|
|
|
"",
|
|
|
|
nxrecorder_cmd_quit,
|
2020-08-22 19:22:41 +02:00
|
|
|
NXRECORDER_HELP_TEXT("Exit NxRecorder")
|
2020-04-21 17:32:44 +02:00
|
|
|
},
|
2018-08-27 16:20:11 +02:00
|
|
|
};
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static const int g_nxrecorder_cmd_count = sizeof(g_nxrecorder_cmds) /
|
|
|
|
sizeof(struct mp_cmd_s);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxrecorder_cmd_recordraw
|
|
|
|
*
|
2020-04-21 17:32:44 +02:00
|
|
|
* nxrecorder_cmd_recordraw() records the raw data file using the
|
|
|
|
* nxrecorder context.
|
2018-08-27 16:20:11 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_recordraw(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg)
|
2018-08-27 16:20:11 +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:20:11 +02:00
|
|
|
char filename[128];
|
|
|
|
|
2020-09-12 09:19:01 +02:00
|
|
|
sscanf(parg, "%s %d %d %d %d", filename, &channels, &bpsamp,
|
|
|
|
&samprate, &chmap);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
/* Try to record the file specified */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxrecorder_recordraw(precorder,
|
|
|
|
filename,
|
|
|
|
channels,
|
|
|
|
bpsamp,
|
2020-09-12 09:19:01 +02:00
|
|
|
samprate,
|
|
|
|
chmap);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
/* nxrecorder_recordfile returned values:
|
|
|
|
*
|
|
|
|
* OK File is being recorded
|
|
|
|
* -EBUSY The media device is busy
|
|
|
|
* -ENOSYS The media file is an unsupported type
|
|
|
|
* -ENODEV No audio device suitable to record 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 recording file: %d\n", -ret);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxrecorder_cmd_stop
|
|
|
|
*
|
|
|
|
* nxrecorder_cmd_stop() stops record of currently recording file
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_stop(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg)
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
|
|
|
/* Stop the record */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
nxrecorder_stop(precorder);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxrecorder_cmd_pause
|
|
|
|
*
|
|
|
|
* nxrecorder_cmd_pause() pauses record of currently recording file
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_pause(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg)
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
|
|
|
/* Pause the record */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
nxrecorder_pause(precorder);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxrecorder_cmd_resume
|
|
|
|
*
|
|
|
|
* nxrecorder_cmd_resume() resumes record of currently recording file
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_resume(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg)
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
|
|
|
/* Resume the record */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
nxrecorder_resume(precorder);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxrecorder_cmd_device
|
|
|
|
*
|
|
|
|
* nxrecorder_cmd_device() sets the preferred audio device for record
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_device(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg)
|
2018-08-27 16:20:11 +02: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];
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
/* First try to open the file directly */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxrecorder_setdevice(precorder, parg);
|
2018-08-27 16:20:11 +02: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 = nxrecorder_setdevice(precorder, path);
|
2018-08-27 16:20:11 +02: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)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Device set successfully */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxrecorder_cmd_quit
|
|
|
|
*
|
|
|
|
* nxrecorder_cmd_quit() terminates the application
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_quit(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg)
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
|
|
|
/* Stop the record if any */
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2020-04-21 17:32:44 +02:00
|
|
|
nxrecorder_stop(precorder);
|
2018-08-27 16:20:11 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxrecorder_cmd_help
|
|
|
|
*
|
|
|
|
* nxrecorder_cmd_help() display the application's help information on
|
|
|
|
* supported commands and command syntax.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXRECORDER_INCLUDE_HELP
|
2020-04-21 17:32:44 +02:00
|
|
|
static int nxrecorder_cmd_help(FAR struct nxrecorder_s *precorder,
|
2019-11-20 14:41:05 +01:00
|
|
|
FAR char *parg)
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
int len;
|
|
|
|
int maxlen = 0;
|
|
|
|
int x;
|
2018-08-27 16:20:11 +02:00
|
|
|
int c;
|
|
|
|
|
|
|
|
/* Calculate length of longest cmd + arghelp */
|
|
|
|
|
|
|
|
for (x = 0; x < g_nxrecorder_cmd_count; x++)
|
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
len = strlen(g_nxrecorder_cmds[x].cmd) +
|
|
|
|
strlen(g_nxrecorder_cmds[x].arghelp);
|
2018-08-27 16:20:11 +02:00
|
|
|
if (len > maxlen)
|
|
|
|
{
|
|
|
|
maxlen = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("NxRecorder commands\n================\n");
|
|
|
|
for (x = 0; x < g_nxrecorder_cmd_count; x++)
|
|
|
|
{
|
|
|
|
/* Print the command and it's arguments */
|
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
printf(" %s %s",
|
|
|
|
g_nxrecorder_cmds[x].cmd, g_nxrecorder_cmds[x].arghelp);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
/* Calculate number of spaces to print before the help text */
|
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
len = maxlen - (strlen(g_nxrecorder_cmds[x].cmd) +
|
|
|
|
strlen(g_nxrecorder_cmds[x].arghelp));
|
2018-08-27 16:20:11 +02:00
|
|
|
for (c = 0; c < len; c++)
|
|
|
|
{
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" : %s\n", g_nxrecorder_cmds[x].help);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxrecorder
|
|
|
|
*
|
|
|
|
* nxrecorder() reads in commands from the console using the readline
|
2020-02-23 05:51:44 +01:00
|
|
|
* system add-in and implements a command-line based pcm raw data recorder
|
2018-08-27 16:20:11 +02:00
|
|
|
* that uses the NuttX audio system to record pcm raw data files read in
|
2019-11-20 14:41:05 +01:00
|
|
|
* from the audio device. Commands are provided for setting volume, base
|
|
|
|
* and other audio features, as well as for pausing and stopping the
|
2018-08-27 16:20:11 +02:00
|
|
|
* record.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
char buffer[CONFIG_NSH_LINELEN];
|
|
|
|
int len;
|
|
|
|
int x;
|
|
|
|
int running;
|
|
|
|
char *cmd;
|
|
|
|
char *arg;
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR struct nxrecorder_s *precorder;
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
printf("NxRecorder version " NXRECORDER_VER "\n");
|
|
|
|
printf("h for commands, q to exit\n");
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* Initialize our NxRecorder context */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
precorder = nxrecorder_create();
|
|
|
|
if (precorder == NULL)
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
|
|
|
printf("Error: Out of RAM\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop until the user exits */
|
|
|
|
|
|
|
|
running = TRUE;
|
|
|
|
while (running)
|
|
|
|
{
|
|
|
|
/* Print a prompt */
|
|
|
|
|
|
|
|
printf("nxrecorder> ");
|
|
|
|
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)
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
/* nxrecorder command */
|
2018-08-27 16:20:11 +02:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
if (buffer[len - 1] == '\n')
|
|
|
|
{
|
|
|
|
buffer[len - 1] = '\0';
|
|
|
|
}
|
2018-08-27 16:20:11 +02:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
/* Parse the command from the argument */
|
2018-08-27 16:20:11 +02:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
cmd = strtok_r(buffer, " \n", &arg);
|
|
|
|
if (cmd == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-27 16:20:11 +02:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
/* Remove leading spaces from arg */
|
2018-08-27 16:20:11 +02:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
while (*arg == ' ')
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the command in our cmd array */
|
2018-08-27 16:20:11 +02:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
for (x = 0; x < g_nxrecorder_cmd_count; x++)
|
|
|
|
{
|
|
|
|
if (strcmp(cmd, g_nxrecorder_cmds[x].cmd) == 0)
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
/* Command found. Call it's handler if not NULL */
|
2018-08-27 16:20:11 +02:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (g_nxrecorder_cmds[x].pfunc != NULL)
|
2019-11-20 14:41:05 +01:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
g_nxrecorder_cmds[x].pfunc(precorder, arg);
|
2019-11-20 14:41:05 +01:00
|
|
|
}
|
2018-08-27 16:20:11 +02: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_nxrecorder_cmds[x].pfunc == nxrecorder_cmd_quit)
|
2019-11-20 14:41:05 +01:00
|
|
|
{
|
|
|
|
running = FALSE;
|
|
|
|
}
|
2018-08-27 16:20:11 +02:00
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-08-27 16:20:11 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-20 14:41:05 +01:00
|
|
|
else
|
2018-08-27 16:20:11 +02:00
|
|
|
{
|
2019-11-20 14:41:05 +01:00
|
|
|
#ifdef CONFIG_SYSTEM_SYSTEM
|
|
|
|
/* Transfer nuttx shell */
|
|
|
|
|
|
|
|
system(buffer + 1);
|
|
|
|
#else
|
|
|
|
printf("%s: unknown nxplayer command\n", buffer);
|
|
|
|
#endif
|
2018-08-27 16:20:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the NxRecorder context */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
nxrecorder_release(precorder);
|
2018-08-27 16:20:11 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|