2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/system/nxplayer/nxplayer.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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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 <sys/types.h>
|
2014-07-27 19:05:25 +02:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2017-12-19 06:57:36 +01:00
|
|
|
#ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <sys/socket.h>
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
# include <netdb.h>
|
|
|
|
#endif
|
|
|
|
|
2014-08-05 18:04:24 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2013-10-27 14:23:01 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2017-02-27 16:25:35 +01:00
|
|
|
#include <strings.h>
|
2013-10-27 14:23:01 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
2021-05-24 11:41:49 +02:00
|
|
|
#include <assert.h>
|
2013-10-27 14:23:01 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <dirent.h>
|
2014-07-27 19:05:25 +02:00
|
|
|
#include <debug.h>
|
2023-02-04 14:56:06 +01:00
|
|
|
#include <unistd.h>
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2018-07-31 14:16:31 +02:00
|
|
|
#include <netutils/netlib.h>
|
2014-07-27 19:05:25 +02:00
|
|
|
#include <nuttx/audio/audio.h>
|
2019-11-20 14:41:05 +01:00
|
|
|
|
2016-07-11 18:11:18 +02:00
|
|
|
#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
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define NXPLAYER_STATE_IDLE 0
|
|
|
|
#define NXPLAYER_STATE_PLAYING 1
|
|
|
|
#define NXPLAYER_STATE_PAUSED 2
|
|
|
|
|
|
|
|
#ifndef CONFIG_NXPLAYER_MSG_PRIO
|
|
|
|
# define CONFIG_NXPLAYER_MSG_PRIO 1
|
|
|
|
#endif
|
|
|
|
|
2013-11-10 17:58:14 +01:00
|
|
|
#ifndef CONFIG_NXPLAYER_PLAYTHREAD_STACKSIZE
|
|
|
|
# define CONFIG_NXPLAYER_PLAYTHREAD_STACKSIZE 1500
|
|
|
|
#endif
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Declarations
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_FMT_FROM_EXT
|
|
|
|
struct nxplayer_ext_fmt_s
|
|
|
|
{
|
2022-10-08 10:31:21 +02:00
|
|
|
FAR const char *ext;
|
|
|
|
uint16_t format;
|
|
|
|
CODE int (*getsubformat)(int fd);
|
2013-10-27 14:23:01 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-10-28 19:11:52 +01:00
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_MIDI
|
2017-12-19 06:57:36 +01:00
|
|
|
int nxplayer_getmidisubformat(int fd);
|
2013-10-28 19:11:52 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-30 02:27:36 +01:00
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_MP3
|
|
|
|
int nxplayer_getmp3subformat(int fd);
|
|
|
|
#endif
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_FMT_FROM_EXT
|
2019-11-20 14:41:05 +01:00
|
|
|
static const struct nxplayer_ext_fmt_s g_known_ext[] =
|
|
|
|
{
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_AC3
|
2013-10-28 19:11:52 +01:00
|
|
|
{ "ac3", AUDIO_FMT_AC3, NULL },
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_MP3
|
2022-11-30 02:27:36 +01:00
|
|
|
{ "mp3", AUDIO_FMT_MP3, nxplayer_getmp3subformat },
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_DTS
|
2013-10-28 19:11:52 +01:00
|
|
|
{ "dts", AUDIO_FMT_DTS, NULL },
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_WMA
|
2013-10-28 19:11:52 +01:00
|
|
|
{ "wma", AUDIO_FMT_WMA, NULL },
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_PCM
|
2013-10-28 19:11:52 +01:00
|
|
|
{ "wav", AUDIO_FMT_PCM, NULL },
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_MIDI
|
2013-10-28 19:11:52 +01:00
|
|
|
{ "mid", AUDIO_FMT_MIDI, nxplayer_getmidisubformat },
|
|
|
|
{ "midi", AUDIO_FMT_MIDI, nxplayer_getmidisubformat },
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_OGG_VORBIS
|
2013-10-28 19:11:52 +01:00
|
|
|
{ "ogg", AUDIO_FMT_OGG_VORBIS, NULL }
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
};
|
2019-11-20 14:41:05 +01:00
|
|
|
|
2013-10-27 14:45:16 +01:00
|
|
|
static const int g_known_ext_count = sizeof(g_known_ext) /
|
2013-10-27 14:23:01 +01:00
|
|
|
sizeof(struct nxplayer_ext_fmt_s);
|
2022-11-30 02:27:36 +01:00
|
|
|
|
|
|
|
static const struct nxplayer_dec_ops_s g_dec_ops[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AUDIO_FMT_MP3,
|
|
|
|
nxplayer_parse_mp3,
|
2023-01-16 04:37:18 +01:00
|
|
|
nxplayer_fill_common
|
2022-11-30 02:27:36 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
AUDIO_FMT_PCM,
|
|
|
|
NULL,
|
2023-01-16 04:37:18 +01:00
|
|
|
nxplayer_fill_common
|
2022-11-30 02:27:36 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif /* CONFIG_NXPLAYER_FMT_FROM_EXT */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-12-19 06:57:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: _open_with_http
|
|
|
|
*
|
|
|
|
* _open_with_http() opens specified fullurl which is http:// or local file
|
|
|
|
* path and returns a file descriptor.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int _open_with_http(const char *fullurl)
|
|
|
|
{
|
2020-05-21 04:29:45 +02:00
|
|
|
char relurl[CONFIG_NXPLAYER_HTTP_MAXFILENAME];
|
|
|
|
char hostname[CONFIG_NXPLAYER_HTTP_MAXHOSTNAME];
|
2017-12-19 06:57:36 +01:00
|
|
|
int resp_chk = 0;
|
|
|
|
char resp_msg[] = "\r\n\r\n";
|
|
|
|
struct timeval tv;
|
2018-07-31 14:16:31 +02:00
|
|
|
uint16_t port = 80;
|
system/nxplayer: Fix the compiler warning
nxplayer.c: In function 'nxplayer_playinternal':
Error: nxplayer.c:209:36: error: '%s' directive output may be truncated writing up to 99 bytes into a region of size 59 [-Werror=format-truncation=]
209 | snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", relurl);
| ^~ ~~~~~~
nxplayer.c:209:3: note: 'snprintf' output between 19 and 118 bytes into a destination of size 64
209 | snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", relurl);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: nxplayer.c:1809:42: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
1809 | snprintf(path, sizeof(path), "%s/%s", pplayer->mediadir, pfilename);
| ^
nxplayer.c:1809:7: note: 'snprintf' output 2 or more bytes (assuming 129) into a destination of size 128
1809 | snprintf(path, sizeof(path), "%s/%s", pplayer->mediadir, pfilename);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: nxplayer.c:359:53: error: '%s' directive output may be truncated writing up to 128 bytes into a region of size 53 [-Werror=format-truncation=]
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~
nxplayer.c:359:11: note: 'snprintf' output between 12 and 140 bytes into a destination of size 64
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-06 10:58:50 +01:00
|
|
|
char buf[PATH_MAX];
|
2017-12-19 06:57:36 +01:00
|
|
|
int s;
|
|
|
|
int n;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (NULL == strstr(fullurl, "http://"))
|
|
|
|
{
|
|
|
|
/* assumes local file specified */
|
|
|
|
|
|
|
|
s = open(fullurl, O_RDONLY);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-07-31 14:16:31 +02:00
|
|
|
memset(relurl, 0, sizeof(relurl));
|
2017-12-19 06:57:36 +01:00
|
|
|
|
2018-07-31 14:16:31 +02:00
|
|
|
n = netlib_parsehttpurl(fullurl, &port,
|
|
|
|
hostname, sizeof(hostname) - 1,
|
|
|
|
relurl, sizeof(relurl) - 1);
|
2017-12-19 06:57:36 +01:00
|
|
|
|
2018-07-31 14:16:31 +02:00
|
|
|
if (OK != n)
|
2017-12-19 06:57:36 +01:00
|
|
|
{
|
2021-12-26 23:10:48 +01:00
|
|
|
printf("netlib_parsehttpurl() returned %d\n", n);
|
2018-07-31 14:16:31 +02:00
|
|
|
return n;
|
2017-12-19 06:57:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
2018-08-24 14:19:35 +02:00
|
|
|
DEBUGASSERT(s != -1);
|
2017-12-19 06:57:36 +01:00
|
|
|
|
|
|
|
tv.tv_sec = 10; /* TODO */
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
2022-10-08 10:31:21 +02:00
|
|
|
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval));
|
|
|
|
setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval));
|
2017-12-19 06:57:36 +01:00
|
|
|
|
|
|
|
struct sockaddr_in server;
|
|
|
|
server.sin_family = AF_INET;
|
|
|
|
server.sin_port = htons(port);
|
|
|
|
|
|
|
|
FAR struct hostent *he;
|
|
|
|
he = gethostbyname(hostname);
|
|
|
|
|
|
|
|
memcpy(&server.sin_addr.s_addr,
|
|
|
|
he->h_addr, sizeof(in_addr_t));
|
|
|
|
|
|
|
|
n = connect(s,
|
|
|
|
(struct sockaddr *)&server,
|
|
|
|
sizeof(struct sockaddr_in));
|
|
|
|
|
|
|
|
if (-1 == n)
|
|
|
|
{
|
|
|
|
close(s);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send GET request */
|
|
|
|
|
2018-07-31 14:16:31 +02:00
|
|
|
snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", relurl);
|
2017-12-19 06:57:36 +01:00
|
|
|
n = write(s, buf, strlen(buf));
|
|
|
|
|
|
|
|
usleep(100 * 1000); /* TODO */
|
|
|
|
|
|
|
|
/* Check status line : e.g. "HTTP/1.x XXX" */
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
read(s, buf, 12);
|
|
|
|
n = atoi(buf + 9);
|
|
|
|
|
|
|
|
if (200 != n)
|
|
|
|
{
|
|
|
|
close(s);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip response header */
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
n = read(s, &c, 1);
|
|
|
|
|
|
|
|
if (1 == n)
|
|
|
|
{
|
|
|
|
if (resp_msg[resp_chk] == c)
|
|
|
|
{
|
|
|
|
resp_chk++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resp_chk = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resp_chk == 4)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_opendevice
|
|
|
|
*
|
|
|
|
* nxplayer_opendevice() either searches the Audio system for a device
|
|
|
|
* that is compatible with the specified audio format and opens it, or
|
2020-02-22 19:52:12 +01:00
|
|
|
* tries to open the preferred device if specified and validates that
|
2013-10-27 14:23:01 +01:00
|
|
|
* it supports the requested format.
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* OK if compatible device opened (searched or preferred)
|
|
|
|
* -ENODEV if no compatible device opened.
|
|
|
|
* -ENOENT if preferred device couldn't be opened.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
static int nxplayer_opendevice(FAR struct nxplayer_s *pplayer, int format,
|
2014-07-22 17:27:24 +02:00
|
|
|
int subfmt)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* If we have a preferred device, then open it */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->prefdevice[0] != '\0')
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Use the saved prefformat to test if the requested
|
|
|
|
* format is specified by the device
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if ((pplayer->prefformat & (1 << (format - 1))) == 0 ||
|
|
|
|
(pplayer->preftype & AUDIO_TYPE_OUTPUT) == 0)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Format not supported by the device */
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: Format not supported by device: %d\n", format);
|
2013-10-27 14:23:01 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Device supports the format. Open the device file. */
|
|
|
|
|
2020-12-17 13:14:08 +01:00
|
|
|
pplayer->dev_fd = open(pplayer->prefdevice, O_RDWR | O_CLOEXEC);
|
2020-04-21 17:32:44 +02:00
|
|
|
if (pplayer->dev_fd == -1)
|
2014-07-22 17:27:24 +02:00
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2020-11-27 06:11:31 +01:00
|
|
|
auderr("ERROR: Failed to open %s: %d\n",
|
|
|
|
pplayer->prefdevice, -errcode);
|
2014-07-22 17:27:24 +02:00
|
|
|
UNUSED(errcode);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE) && \
|
|
|
|
defined(CONFIG_NXPLAYER_INCLUDE_DEVICE_SEARCH)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_DEVICE_SEARCH
|
|
|
|
{
|
2022-03-18 13:59:40 +01:00
|
|
|
struct audio_caps_s cap;
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR struct dirent *pdevice;
|
2014-07-20 17:17:36 +02:00
|
|
|
FAR DIR *dirp;
|
system/nxplayer: Fix the compiler warning
nxplayer.c: In function 'nxplayer_playinternal':
Error: nxplayer.c:209:36: error: '%s' directive output may be truncated writing up to 99 bytes into a region of size 59 [-Werror=format-truncation=]
209 | snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", relurl);
| ^~ ~~~~~~
nxplayer.c:209:3: note: 'snprintf' output between 19 and 118 bytes into a destination of size 64
209 | snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", relurl);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: nxplayer.c:1809:42: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
1809 | snprintf(path, sizeof(path), "%s/%s", pplayer->mediadir, pfilename);
| ^
nxplayer.c:1809:7: note: 'snprintf' output 2 or more bytes (assuming 129) into a destination of size 128
1809 | snprintf(path, sizeof(path), "%s/%s", pplayer->mediadir, pfilename);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: nxplayer.c:359:53: error: '%s' directive output may be truncated writing up to 128 bytes into a region of size 53 [-Werror=format-truncation=]
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~
nxplayer.c:359:11: note: 'snprintf' output between 12 and 140 bytes into a destination of size 64
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-06 10:58:50 +01:00
|
|
|
char path[PATH_MAX];
|
2014-07-23 03:23:05 +02:00
|
|
|
uint8_t supported = true;
|
2014-07-20 17:17:36 +02:00
|
|
|
uint8_t x;
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Search for a device in the audio device directory */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH
|
|
|
|
#ifdef CONFIG_AUDIO_DEV_ROOT
|
|
|
|
dirp = opendir("/dev");
|
|
|
|
#else
|
|
|
|
dirp = opendir(CONFIG_AUDIO_DEV_PATH);
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_AUDIO_DEV_ROOT */
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
|
|
|
dirp = opendir("/dev/audio");
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_AUDIO_CUSTOM_DEV_PATH */
|
2013-10-27 14:23:01 +01:00
|
|
|
if (dirp == NULL)
|
|
|
|
{
|
2014-07-22 17:27:24 +02:00
|
|
|
int errcode = errno;
|
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: Failed to open /dev/audio: %d\n", -errcode);
|
2014-07-22 17:27:24 +02:00
|
|
|
UNUSED(errcode);
|
2013-10-27 14:23:01 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
while ((pdevice = readdir(dirp)) != NULL)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* We found the next device. Try to open it and
|
|
|
|
* get its audio capabilities.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH
|
|
|
|
#ifdef CONFIG_AUDIO_DEV_ROOT
|
2020-04-21 17:32:44 +02:00
|
|
|
snprintf(path, sizeof(path), "/dev/%s", pdevice->d_name);
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2019-11-20 14:41:05 +01:00
|
|
|
snprintf(path, sizeof(path), CONFIG_AUDIO_DEV_PATH "/%s",
|
2020-04-21 17:32:44 +02:00
|
|
|
pdevice->d_name);
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_AUDIO_DEV_ROOT */
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_AUDIO_CUSTOM_DEV_PATH */
|
2014-07-22 17:27:24 +02:00
|
|
|
|
2020-12-17 13:14:08 +01:00
|
|
|
if ((pplayer->dev_fd = open(path, O_RDWR | O_CLOEXEC)) != -1)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2014-07-22 17:27:24 +02:00
|
|
|
/* We have the device file open. Now issue an AUDIO ioctls to
|
|
|
|
* get the capabilities
|
2013-10-27 14:23:01 +01:00
|
|
|
*/
|
|
|
|
|
2022-03-18 13:59:40 +01:00
|
|
|
cap.ac_len = sizeof(cap);
|
|
|
|
cap.ac_type = AUDIO_TYPE_QUERY;
|
|
|
|
cap.ac_subtype = AUDIO_TYPE_QUERY;
|
2013-10-28 19:11:52 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (ioctl(pplayer->dev_fd, AUDIOIOC_GETCAPS,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)&cap) == cap.ac_len)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Test if this device supports the format we want */
|
|
|
|
|
2022-03-18 13:59:40 +01:00
|
|
|
if (((cap.ac_format.hw & (1 << (format - 1))) != 0) &&
|
|
|
|
(cap.ac_controls.b[0] & AUDIO_TYPE_OUTPUT))
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2013-10-28 19:11:52 +01:00
|
|
|
/* Do subformat detection */
|
|
|
|
|
|
|
|
if (subfmt != AUDIO_FMT_UNDEF)
|
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
/* Prepare to get sub-formats for
|
|
|
|
* this main format
|
|
|
|
*/
|
2013-10-28 19:11:52 +01:00
|
|
|
|
2022-03-18 13:59:40 +01:00
|
|
|
cap.ac_subtype = format;
|
|
|
|
cap.ac_format.b[0] = 0;
|
2014-07-23 03:23:05 +02:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
while (ioctl(pplayer->dev_fd, AUDIOIOC_GETCAPS,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)&cap) == cap.ac_len)
|
2013-10-28 19:11:52 +01:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
/* Check the next set of 4 controls
|
|
|
|
* to find the subformat
|
|
|
|
*/
|
2014-07-20 17:17:36 +02:00
|
|
|
|
2022-03-18 13:59:40 +01:00
|
|
|
for (x = 0; x < sizeof(cap.ac_controls.b); x++)
|
2013-10-28 19:11:52 +01:00
|
|
|
{
|
2022-03-18 13:59:40 +01:00
|
|
|
if (cap.ac_controls.b[x] == subfmt)
|
2013-10-28 19:11:52 +01:00
|
|
|
{
|
|
|
|
/* Sub format supported! */
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2022-03-18 13:59:40 +01:00
|
|
|
else if (cap.ac_controls.b[x] ==
|
2020-04-21 17:32:44 +02:00
|
|
|
AUDIO_SUBFMT_END)
|
2013-10-28 19:11:52 +01:00
|
|
|
{
|
|
|
|
/* Sub format not supported */
|
|
|
|
|
2014-07-23 03:23:05 +02:00
|
|
|
supported = false;
|
2013-10-28 19:11:52 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-20 14:41:05 +01:00
|
|
|
/* If we reached the end of the subformat list,
|
|
|
|
* then break out of the loop.
|
2013-10-28 19:11:52 +01:00
|
|
|
*/
|
|
|
|
|
2022-03-18 13:59:40 +01:00
|
|
|
if (x != sizeof(cap.ac_controls))
|
2013-10-28 19:11:52 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
/* Increment ac_format.b[0] to get next
|
|
|
|
* set of subformats
|
|
|
|
*/
|
2013-10-28 19:11:52 +01:00
|
|
|
|
2022-03-18 13:59:40 +01:00
|
|
|
cap.ac_format.b[0]++;
|
2013-10-28 19:11:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test if subformat needed and detected */
|
|
|
|
|
|
|
|
if (supported)
|
|
|
|
{
|
|
|
|
/* Yes, it supports this format. Use this device */
|
|
|
|
|
|
|
|
closedir(dirp);
|
|
|
|
return OK;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not this device! */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
close(pplayer->dev_fd);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
}
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Close the directory */
|
|
|
|
|
|
|
|
closedir(dirp);
|
|
|
|
}
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_NXPLAYER_INCLUDE_DEVICE_SEARCH */
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Device not found */
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: Device not found\n");
|
2020-04-21 17:32:44 +02:00
|
|
|
pplayer->dev_fd = -1;
|
2013-10-27 14:23:01 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:11:52 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_getmidisubformat
|
|
|
|
*
|
2020-02-23 05:51:44 +01:00
|
|
|
* nxplayer_getmidisubformat() reads the MIDI header and determines the
|
2013-10-28 19:11:52 +01:00
|
|
|
* MIDI format of the file.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_MIDI
|
2017-12-19 06:57:36 +01:00
|
|
|
int nxplayer_getmidisubformat(int fd)
|
2013-10-28 19:11:52 +01:00
|
|
|
{
|
2022-10-08 10:31:21 +02:00
|
|
|
char type[2];
|
|
|
|
int ret;
|
2013-10-28 19:11:52 +01:00
|
|
|
|
|
|
|
/* Seek to location 8 in the file (the format type) */
|
|
|
|
|
2017-12-19 06:57:36 +01:00
|
|
|
lseek(fd, 8, SEEK_SET);
|
|
|
|
read(fd, type, sizeof(type));
|
2013-10-28 19:11:52 +01:00
|
|
|
|
|
|
|
/* Set return value based on type */
|
|
|
|
|
|
|
|
switch (type[1])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
ret = AUDIO_SUBFMT_MIDI_0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
ret = AUDIO_SUBFMT_MIDI_1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
ret = AUDIO_SUBFMT_MIDI_2;
|
|
|
|
break;
|
|
|
|
}
|
2019-11-20 14:41:05 +01:00
|
|
|
|
2017-12-19 06:57:36 +01:00
|
|
|
lseek(fd, 0, SEEK_SET);
|
2013-10-28 19:11:52 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-31 04:36:02 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_getmp3subformat
|
|
|
|
*
|
|
|
|
* nxplayer_getmp3subformat() just return AUDIO_SUBFMT_PCM_MP3
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_FORMAT_MP3
|
2022-11-30 02:27:36 +01:00
|
|
|
int nxplayer_getmp3subformat(int fd)
|
|
|
|
{
|
|
|
|
return AUDIO_SUBFMT_PCM_MP3;
|
|
|
|
}
|
2023-01-31 04:36:02 +01:00
|
|
|
#endif
|
2022-11-30 02:27:36 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_fmtfromextension
|
|
|
|
*
|
|
|
|
* nxplayer_fmtfromextension() tries to determine the file format based
|
|
|
|
* on the extension of the supplied filename.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_FMT_FROM_EXT
|
2019-02-16 02:25:01 +01:00
|
|
|
static inline int nxplayer_fmtfromextension(FAR struct nxplayer_s *pplayer,
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR const char *pfilename,
|
2014-07-24 23:06:54 +02:00
|
|
|
FAR int *subfmt)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2022-10-08 10:31:21 +02:00
|
|
|
FAR const char *pext;
|
|
|
|
uint8_t x;
|
|
|
|
uint8_t c;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Find the file extension, if any */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
x = strlen(pfilename) - 1;
|
2013-10-27 14:23:01 +01:00
|
|
|
while (x > 0)
|
|
|
|
{
|
2020-02-22 19:52:12 +01:00
|
|
|
/* Search backward for the first '.' */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (pfilename[x] == '.')
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* First '.' found. Now compare with known extensions */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
pext = &pfilename[x + 1];
|
2013-10-27 14:23:01 +01:00
|
|
|
for (c = 0; c < g_known_ext_count; c++)
|
|
|
|
{
|
|
|
|
/* Test for extension match */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (strcasecmp(pext, g_known_ext[c].ext) == 0)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2013-10-28 19:11:52 +01:00
|
|
|
/* Test if we have a sub-format detection routine */
|
|
|
|
|
|
|
|
if (subfmt && g_known_ext[c].getsubformat)
|
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
*subfmt = g_known_ext[c].getsubformat(pplayer->fd);
|
2013-10-28 19:11:52 +01:00
|
|
|
}
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Return the format for this extension */
|
|
|
|
|
|
|
|
return g_known_ext[c].format;
|
|
|
|
}
|
2013-10-27 14:45:16 +01:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop if we find a '/' */
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (pfilename[x] == '/')
|
2014-07-24 23:06:54 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
x--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AUDIO_FMT_UNDEF;
|
|
|
|
}
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_NXPLAYER_FMT_FROM_EXT */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_fmtfromheader
|
|
|
|
*
|
|
|
|
* nxplayer_fmtfromheader() tries to determine the file format by checking
|
|
|
|
* the file header for known file types.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_FMT_FROM_HEADER
|
2019-02-16 02:25:01 +01:00
|
|
|
static int nxplayer_fmtfromheader(FAR struct nxplayer_s *pplayer)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
return AUDIO_FMT_UNDEF;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NXPLAYER_FMT_FROM_HEADER */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_mediasearch
|
|
|
|
*
|
|
|
|
* nxplayer_mediasearch() searches the subdirectories in the mediadir
|
|
|
|
* for the specified media file. We borrow the caller's path stack
|
|
|
|
* variable (playfile) to conserve stack space.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NXPLAYER_MEDIA_SEARCH) && defined(CONFIG_NXPLAYER_INCLUDE_MEDIADIR)
|
2019-02-16 02:25:01 +01:00
|
|
|
static int nxplayer_mediasearch(FAR struct nxplayer_s *pplayer,
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR const char *pfilename,
|
2014-07-24 23:06:54 +02:00
|
|
|
FAR const char *path, int pathmax)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-08-05 18:04:24 +02:00
|
|
|
* Name: nxplayer_readbuffer
|
2013-10-27 14:45:16 +01:00
|
|
|
*
|
2014-08-05 18:04:24 +02:00
|
|
|
* Read the next block of data from the media file into the specified
|
|
|
|
* buffer.
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
static int nxplayer_readbuffer(FAR struct nxplayer_s *pplayer,
|
2017-12-19 07:06:11 +01:00
|
|
|
FAR struct ap_buffer_s *apb)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2022-11-30 02:27:36 +01:00
|
|
|
int ret;
|
|
|
|
|
2014-07-31 22:59:51 +02:00
|
|
|
/* Validate the file is still open. It will be closed automatically when
|
|
|
|
* we encounter the end of file (or, perhaps, a read error that we cannot
|
|
|
|
* handle.
|
|
|
|
*/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->fd == -1)
|
2014-07-23 15:46:49 +02:00
|
|
|
{
|
2014-07-31 22:59:51 +02:00
|
|
|
/* Return -ENODATA to indicate that there is nothing more to read from
|
|
|
|
* the file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return -ENODATA;
|
2014-07-23 15:46:49 +02:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2022-11-30 02:27:36 +01:00
|
|
|
ret = pplayer->ops->fill_data(pplayer->fd, apb);
|
|
|
|
if (ret < 0)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2014-07-23 15:46:49 +02:00
|
|
|
/* End of file or read error.. We are finished with this file in any
|
|
|
|
* event.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
close(pplayer->fd);
|
|
|
|
pplayer->fd = -1;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
2014-08-05 18:04:24 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_enqueuebuffer
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enqueue the audio buffer in the downstream device. Normally we are
|
|
|
|
* called with a buffer of data to be enqueued in the audio stream.
|
|
|
|
*
|
|
|
|
* Be we may also receive an empty length buffer (with only the
|
2019-11-20 14:41:05 +01:00
|
|
|
* AUDIO_APB_FINAL set) in the event of certain read error occurs or in the
|
2014-08-05 18:04:24 +02:00
|
|
|
* event that the file was an exact multiple of the nmaxbytes size of the
|
|
|
|
* audio buffer. In that latter case, we have an end of file with no bytes
|
|
|
|
* read.
|
|
|
|
*
|
|
|
|
* These infrequent zero length buffers have to be passed through because
|
|
|
|
* the include the AUDIO_APB_FINAL flag that is needed to terminate the
|
|
|
|
* audio stream.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pplayer,
|
2017-12-19 07:06:11 +01:00
|
|
|
FAR struct ap_buffer_s *apb)
|
2014-08-05 18:04:24 +02:00
|
|
|
{
|
|
|
|
struct audio_buf_desc_s bufdesc;
|
|
|
|
int ret;
|
|
|
|
|
2014-08-01 15:00:02 +02:00
|
|
|
/* Now enqueue the buffer with the audio device. If the number of
|
|
|
|
* bytes in the file happens to be an exact multiple of the audio
|
|
|
|
* buffer size, then we will receive the last buffer size = 0. We
|
|
|
|
* encode this buffer also so the audio system knows its the end of
|
|
|
|
* the file and can do proper clean-up.
|
|
|
|
*/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
bufdesc.session = pplayer->session;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-08-01 15:00:02 +02:00
|
|
|
bufdesc.numbytes = apb->nbytes;
|
2020-04-21 17:32:44 +02:00
|
|
|
bufdesc.u.buffer = apb;
|
2014-07-23 15:46:49 +02:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_ENQUEUEBUFFER,
|
2014-08-01 15:00:02 +02:00
|
|
|
(unsigned long)&bufdesc);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
DEBUGASSERT(errcode > 0);
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: AUDIOIOC_ENQUEUEBUFFER ioctl failed: %d\n", errcode);
|
2014-08-01 15:00:02 +02:00
|
|
|
return -errcode;
|
2014-07-23 15:46:49 +02:00
|
|
|
}
|
|
|
|
|
2014-08-01 15:00:02 +02:00
|
|
|
/* Return OK to indicate that we successfully read data from the file
|
|
|
|
* (and we are not yet at the end of file)
|
|
|
|
*/
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2014-08-01 15:00:02 +02:00
|
|
|
return OK;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
2023-01-03 13:35:46 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_jointhread
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void nxplayer_jointhread(FAR struct nxplayer_s *pplayer)
|
|
|
|
{
|
|
|
|
FAR void *value;
|
|
|
|
int id = 0;
|
|
|
|
|
|
|
|
if (gettid() == pplayer->play_id)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
|
|
|
|
|
|
|
if (pplayer->play_id > 0)
|
|
|
|
{
|
|
|
|
id = pplayer->play_id;
|
|
|
|
pplayer->play_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
|
|
|
|
|
|
|
if (id > 0)
|
|
|
|
{
|
|
|
|
pthread_join(id, &value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_thread_playthread
|
2013-10-27 14:45:16 +01:00
|
|
|
*
|
2014-07-23 15:46:49 +02:00
|
|
|
* This is the thread that reads the audio file file and enqueues /
|
2013-10-27 14:23:01 +01:00
|
|
|
* dequeues buffers to the selected and opened audio device.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-10-08 10:31:21 +02:00
|
|
|
static FAR void *nxplayer_playthread(pthread_addr_t pvarg)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2022-10-08 10:31:21 +02:00
|
|
|
FAR struct nxplayer_s *pplayer = (FAR struct nxplayer_s *)pvarg;
|
|
|
|
struct audio_msg_s msg;
|
|
|
|
struct audio_buf_desc_s buf_desc;
|
|
|
|
ssize_t size;
|
|
|
|
bool running = true;
|
|
|
|
bool streaming = true;
|
|
|
|
bool failed = false;
|
|
|
|
struct ap_buffer_info_s buf_info;
|
|
|
|
FAR struct ap_buffer_s **buffers;
|
|
|
|
unsigned int prio;
|
2016-06-11 22:13:39 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2022-10-08 10:31:21 +02:00
|
|
|
int outstanding = 0;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2022-10-08 10:31:21 +02:00
|
|
|
int x;
|
|
|
|
int ret;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("Entry\n");
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2020-12-14 11:13:54 +01:00
|
|
|
/* Query the audio device for its preferred buffer size / qty */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if ((ret = ioctl(pplayer->dev_fd, AUDIOIOC_GETBUFFERINFO,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)&buf_info)) != OK)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2020-12-14 11:13:54 +01:00
|
|
|
/* Driver doesn't report its buffer size. Use our default. */
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
buf_info.buffer_size = CONFIG_AUDIO_BUFFER_NUMBYTES;
|
|
|
|
buf_info.nbuffers = CONFIG_AUDIO_NUM_BUFFERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create array of pointers to buffers */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
buffers = (FAR struct ap_buffer_s **)
|
2019-11-20 14:41:05 +01:00
|
|
|
malloc(buf_info.nbuffers * sizeof(FAR void *));
|
2020-04-21 17:32:44 +02:00
|
|
|
if (buffers == NULL)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Error allocating memory for buffer storage! */
|
|
|
|
|
|
|
|
ret = -ENOMEM;
|
2014-07-23 03:23:05 +02:00
|
|
|
running = false;
|
2013-10-27 14:23:01 +01:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create our audio pipeline buffers to use for queueing up data */
|
|
|
|
|
|
|
|
for (x = 0; x < buf_info.nbuffers; x++)
|
2014-07-24 23:10:12 +02:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
buffers[x] = NULL;
|
2014-07-24 23:10:12 +02:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
for (x = 0; x < buf_info.nbuffers; x++)
|
|
|
|
{
|
|
|
|
/* Fill in the buffer descriptor struct to issue an alloc request */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
buf_desc.session = pplayer->session;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2020-06-05 07:16:15 +02:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
buf_desc.numbytes = buf_info.buffer_size;
|
2020-04-21 17:32:44 +02:00
|
|
|
buf_desc.u.pbuffer = &buffers[x];
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_ALLOCBUFFER,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)&buf_desc);
|
2013-10-27 14:23:01 +01:00
|
|
|
if (ret != sizeof(buf_desc))
|
|
|
|
{
|
|
|
|
/* Buffer alloc Operation not supported or error allocating! */
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: Could not allocate buffer %d\n", x);
|
2014-07-23 03:23:05 +02:00
|
|
|
running = false;
|
2013-10-27 14:23:01 +01:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill up the pipeline with enqueued buffers */
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
for (x = 0; x < buf_info.nbuffers; x++)
|
|
|
|
{
|
2014-08-05 18:04:24 +02:00
|
|
|
/* Read the next buffer of data */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxplayer_readbuffer(pplayer, buffers[x]);
|
2013-10-27 14:23:01 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2014-08-05 18:04:24 +02:00
|
|
|
/* nxplayer_readbuffer will return an error if there is no further
|
|
|
|
* data to be read from the file. This can happen normally if the
|
|
|
|
* file is very small (less than will fit in
|
|
|
|
* CONFIG_AUDIO_NUM_BUFFERS) or if an error occurs trying to read
|
|
|
|
* from the file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* We are no longer streaming data from the file */
|
|
|
|
|
|
|
|
streaming = false;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
if (x == 0)
|
2014-07-23 15:46:49 +02:00
|
|
|
{
|
2014-08-05 18:04:24 +02:00
|
|
|
/* No buffers read? Should never really happen. Even in the
|
|
|
|
* case of a read failure, one empty buffer containing the
|
|
|
|
* AUDIO_APB_FINAL indication will be returned.
|
|
|
|
*/
|
|
|
|
|
2014-07-23 15:46:49 +02:00
|
|
|
running = false;
|
|
|
|
}
|
2014-08-05 18:04:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enqueue buffer by sending it to the audio driver */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxplayer_enqueuebuffer(pplayer, buffers[x]);
|
2014-08-05 18:04:24 +02:00
|
|
|
if (ret != OK)
|
2014-07-23 15:46:49 +02:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
/* Failed to enqueue the buffer.
|
|
|
|
* The driver is not happy with the buffer.
|
|
|
|
* Perhaps a decoder has detected something that it
|
|
|
|
* does not like in the stream and has stopped streaming.
|
|
|
|
* This would happen normally if we send a file in the
|
|
|
|
* incorrect format to an audio decoder.
|
2014-08-05 18:04:24 +02:00
|
|
|
*
|
|
|
|
* We must stop streaming as gracefully as possible. Close the
|
|
|
|
* file so that no further data is read.
|
|
|
|
*/
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
close(pplayer->fd);
|
|
|
|
pplayer->fd = -1;
|
2014-08-05 18:04:24 +02:00
|
|
|
|
|
|
|
/* We are no longer streaming data from the file. Be we will
|
2020-04-21 17:32:44 +02:00
|
|
|
* need to wait for any outstanding buffers to be recovered.
|
|
|
|
* We also still expect the audio driver to send a
|
2019-11-20 14:41:05 +01:00
|
|
|
* AUDIO_MSG_COMPLETE message after all queued buffers have
|
|
|
|
* been returned.
|
2014-08-05 18:04:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
streaming = false;
|
|
|
|
failed = true;
|
|
|
|
break;
|
2014-07-23 15:46:49 +02:00
|
|
|
}
|
2016-06-11 22:13:39 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2014-08-05 18:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The audio driver has one more buffer */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:24 +02:00
|
|
|
outstanding++;
|
|
|
|
}
|
|
|
|
#endif
|
2013-10-27 14:45:16 +01:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("%d buffers queued, running=%d streaming=%d\n",
|
2014-07-31 22:59:51 +02:00
|
|
|
x, running, streaming);
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Start the audio device */
|
|
|
|
|
2014-08-05 18:04:24 +02:00
|
|
|
if (running && !failed)
|
|
|
|
{
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_START,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)pplayer->session);
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_START, 0);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2014-08-05 18:04:24 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Error starting the audio stream! We need to continue running
|
|
|
|
* in order to recover the audio buffers that have already been
|
|
|
|
* queued.
|
|
|
|
*/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:24 +02:00
|
|
|
failed = true;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
2014-08-05 18:04:24 +02:00
|
|
|
if (running && !failed)
|
|
|
|
{
|
|
|
|
/* Indicate we are playing a file */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->state = NXPLAYER_STATE_PLAYING;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-08-05 18:04:24 +02:00
|
|
|
/* Set initial parameters such as volume, bass, etc.
|
|
|
|
* REVISIT: Shouldn't this actually be done BEFORE we start playing?
|
|
|
|
*/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
2020-01-02 13:09:50 +01:00
|
|
|
nxplayer_setvolume(pplayer, pplayer->volume);
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
|
2019-02-16 02:25:01 +01:00
|
|
|
nxplayer_setbalance(pplayer, pplayer->balance);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2019-01-27 14:31:40 +01:00
|
|
|
#endif
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2019-02-16 02:25:01 +01:00
|
|
|
nxplayer_setbass(pplayer, pplayer->bass);
|
|
|
|
nxplayer_settreble(pplayer, pplayer->treble);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-08-05 18:04:24 +02:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-07-31 22:59:51 +02:00
|
|
|
/* Loop until we specifically break. running == true means that we are
|
|
|
|
* still looping waiting for the playback to complete. All of the file
|
|
|
|
* data may have been sent (if streaming == false), but the playback is
|
|
|
|
* not complete until we get the AUDIO_MSG_COMPLETE (or AUDIO_MSG_STOP)
|
|
|
|
* message
|
2014-08-05 18:04:24 +02:00
|
|
|
*
|
|
|
|
* The normal protocol for streaming errors detected by the audio driver
|
|
|
|
* is as follows:
|
|
|
|
*
|
|
|
|
* (1) The audio driver will indicated the error by returning a negated
|
|
|
|
* error value when the next buffer is enqueued. The upper level
|
|
|
|
* then knows that this buffer was not queue.
|
|
|
|
* (2) The audio driver must return all queued buffers using the
|
|
|
|
* AUDIO_MSG_DEQUEUE message, and
|
|
|
|
* (3) Terminate playing by sending the AUDIO_MSG_COMPLETE message.
|
2014-07-31 22:59:51 +02:00
|
|
|
*/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2020-02-22 19:52:12 +01:00
|
|
|
audinfo("%s\n", running ? "Playing..." : "Not running");
|
2013-10-27 14:23:01 +01:00
|
|
|
while (running)
|
|
|
|
{
|
|
|
|
/* Wait for a signal either from the Audio driver that it needs
|
|
|
|
* additional buffer data, or from a user-space signal to pause,
|
|
|
|
* stop, etc.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
size = mq_receive(pplayer->mq, (FAR char *)&msg, sizeof(msg), &prio);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Validate a message was received */
|
|
|
|
|
|
|
|
if (size != sizeof(msg))
|
|
|
|
{
|
|
|
|
/* Interrupted by a signal? What to do? */
|
|
|
|
|
2014-07-31 22:59:51 +02:00
|
|
|
continue;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform operation based on message id */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
switch (msg.msg_id)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* An audio buffer is being dequeued by the driver */
|
|
|
|
|
|
|
|
case AUDIO_MSG_DEQUEUE:
|
2019-11-20 14:41:05 +01:00
|
|
|
|
2016-06-11 22:13:39 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2014-08-05 18:04:24 +02:00
|
|
|
/* Make sure that we believe that the audio driver has at
|
|
|
|
* least one buffer.
|
|
|
|
*/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
DEBUGASSERT(msg.u.ptr && outstanding > 0);
|
2014-08-05 18:04:24 +02:00
|
|
|
outstanding--;
|
|
|
|
#endif
|
|
|
|
|
2014-07-31 22:59:51 +02:00
|
|
|
/* Read data from the file directly into this buffer and
|
|
|
|
* re-enqueue it. streaming == true means that we have
|
|
|
|
* not yet hit the end-of-file.
|
2013-10-27 14:23:01 +01:00
|
|
|
*/
|
|
|
|
|
2014-07-31 22:59:51 +02:00
|
|
|
if (streaming)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2014-08-05 18:04:24 +02:00
|
|
|
/* Read the next buffer of data */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxplayer_readbuffer(pplayer, msg.u.ptr);
|
2013-10-27 14:23:01 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2014-07-31 22:59:51 +02:00
|
|
|
/* Out of data. Stay in the loop until the device sends
|
|
|
|
* us a COMPLETE message, but stop trying to play more
|
|
|
|
* data.
|
2013-10-27 14:23:01 +01:00
|
|
|
*/
|
|
|
|
|
2014-07-31 22:59:51 +02:00
|
|
|
streaming = false;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
2014-08-05 18:04:24 +02:00
|
|
|
|
|
|
|
/* Enqueue buffer by sending it to the audio driver */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = nxplayer_enqueuebuffer(pplayer, msg.u.ptr);
|
2014-08-05 18:04:24 +02:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
/* There is some issue from the audio driver.
|
|
|
|
* Perhaps a problem in the file format?
|
|
|
|
*
|
|
|
|
* We must stop streaming as gracefully as possible.
|
|
|
|
* Close the file so that no further data is read.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
close(pplayer->fd);
|
|
|
|
pplayer->fd = -1;
|
2014-08-05 18:04:24 +02:00
|
|
|
|
|
|
|
/* Stop streaming and wait for buffers to be
|
|
|
|
* returned and to receive the AUDIO_MSG_COMPLETE
|
|
|
|
* indication.
|
|
|
|
*/
|
|
|
|
|
|
|
|
streaming = false;
|
|
|
|
failed = true;
|
|
|
|
}
|
2016-06-11 22:13:39 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2014-08-05 18:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The audio driver has one more buffer */
|
|
|
|
|
|
|
|
outstanding++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Someone wants to stop the playback. */
|
|
|
|
|
|
|
|
case AUDIO_MSG_STOP:
|
2019-11-20 14:41:05 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Send a stop message to the device */
|
|
|
|
|
2020-11-27 06:11:17 +01:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("Stopping! outstanding=%d\n", outstanding);
|
2020-11-27 06:11:17 +01:00
|
|
|
#endif
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2020-04-21 17:32:44 +02:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_STOP,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)pplayer->session);
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_STOP, 0);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-08-05 18:04:24 +02:00
|
|
|
/* Stay in the running loop (without sending more data).
|
|
|
|
* we will need to recover our audio buffers. We will
|
|
|
|
* loop until AUDIO_MSG_COMPLETE is received.
|
|
|
|
*/
|
|
|
|
|
2014-07-31 22:59:51 +02:00
|
|
|
streaming = false;
|
2013-10-27 14:23:01 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Message indicating the playback is complete */
|
|
|
|
|
|
|
|
case AUDIO_MSG_COMPLETE:
|
2020-11-27 06:11:17 +01:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("Play complete. outstanding=%d\n", outstanding);
|
2014-08-05 18:04:24 +02:00
|
|
|
DEBUGASSERT(outstanding == 0);
|
2021-03-29 09:29:23 +02:00
|
|
|
#endif
|
2014-07-23 03:23:05 +02:00
|
|
|
running = false;
|
2013-10-27 14:23:01 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Unknown / unsupported message ID */
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release our audio buffers and unregister / release the device */
|
|
|
|
|
|
|
|
err_out:
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("Clean-up and exit\n");
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (buffers != NULL)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("Freeing buffers\n");
|
2013-10-27 14:23:01 +01:00
|
|
|
for (x = 0; x < buf_info.nbuffers; x++)
|
|
|
|
{
|
|
|
|
/* Fill in the buffer descriptor struct to issue a free request */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (buffers[x] != NULL)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2018-08-27 15:52:04 +02:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
buf_desc.session = pplayer->session;
|
2018-08-27 15:52:04 +02:00
|
|
|
#endif
|
2020-04-21 17:32:44 +02:00
|
|
|
buf_desc.u.buffer = buffers[x];
|
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_FREEBUFFER,
|
2019-11-20 14:41:05 +01:00
|
|
|
(unsigned long)&buf_desc);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the pointers to the buffers */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
free(buffers);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
2018-08-27 15:52:04 +02:00
|
|
|
/* Unregister the message queue and release the session */
|
|
|
|
|
2022-03-18 13:59:40 +01:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_UNREGISTERMQ, (unsigned long)pplayer->mq);
|
2018-08-27 15:52:04 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2022-03-18 13:59:40 +01:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_RELEASE, (unsigned long)pplayer->session);
|
2018-08-27 15:52:04 +02:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_RELEASE, 0);
|
2018-08-27 15:52:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
2018-08-27 15:52:04 +02:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Close the files */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (0 < pplayer->fd)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
close(pplayer->fd); /* Close the file */
|
|
|
|
pplayer->fd = -1; /* Clear out the FD */
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
2014-08-05 18:04:24 +02:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
close(pplayer->dev_fd); /* Close the device */
|
|
|
|
pplayer->dev_fd = -1; /* Mark device as closed */
|
2019-02-16 02:25:01 +01:00
|
|
|
mq_close(pplayer->mq); /* Close the message queue */
|
|
|
|
mq_unlink(pplayer->mqname); /* Unlink the message queue */
|
2022-11-30 02:27:36 +01:00
|
|
|
pplayer->ops = NULL; /* Clear offload parser */
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->state = NXPLAYER_STATE_IDLE; /* Go to IDLE */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* The playthread is done with the context. Release it, which may
|
|
|
|
* actually cause the context to be freed if the creator has already
|
|
|
|
* abandoned (released) the context too.
|
|
|
|
*/
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
nxplayer_release(pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("Exit\n");
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_setvolume
|
|
|
|
*
|
|
|
|
* nxplayer_setvolume() sets the volume.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_setvolume(FAR struct nxplayer_s *pplayer, uint16_t volume)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
struct audio_caps_desc_s cap_desc;
|
2014-07-24 23:06:54 +02:00
|
|
|
int ret;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* If we are currently playing, then we need to post a message to
|
|
|
|
* the playthread to perform the volume change operation. If we
|
|
|
|
* are not playing, then just store the volume setting and it will
|
|
|
|
* be applied before the next playback begins.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->state == NXPLAYER_STATE_PLAYING)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Send a CONFIGURE ioctl to the device to set the volume */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
cap_desc.session = pplayer->session;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-07-24 18:21:04 +02:00
|
|
|
cap_desc.caps.ac_len = sizeof(struct audio_caps_s);
|
|
|
|
cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE;
|
|
|
|
cap_desc.caps.ac_format.hw = AUDIO_FU_VOLUME;
|
|
|
|
cap_desc.caps.ac_controls.hw[0] = volume;
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_CONFIGURE,
|
2019-11-20 14:41:05 +01:00
|
|
|
(unsigned long)&cap_desc);
|
2014-07-24 23:06:54 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: AUDIOIOC_CONFIGURE ioctl failed: %d\n", errcode);
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2014-07-24 23:06:54 +02:00
|
|
|
return -errcode;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the volume setting */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->volume = volume;
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-07-24 23:06:54 +02:00
|
|
|
return OK;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-07-24 16:28:10 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_setequalization
|
|
|
|
*
|
|
|
|
* Sets the level on each band of an equalizer. Each band setting is
|
|
|
|
* represented in one percent increments, so the range is 0-100.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer - Pointer to the context to initialize
|
2014-07-24 16:28:10 +02:00
|
|
|
* equalization - Pointer to array of equalizer settings of size
|
|
|
|
* CONFIG_AUDIO_EQUALIZER_NBANDS bytes. Each byte
|
|
|
|
* represents the setting for one band in the range of
|
|
|
|
* 0-100.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK if equalization was set correctly.
|
|
|
|
*
|
2015-10-03 01:33:30 +02:00
|
|
|
****************************************************************************/
|
2014-07-24 16:28:10 +02:00
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_EQUALIZER
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_setequalization(FAR struct nxplayer_s *pplayer,
|
2014-07-24 16:28:10 +02:00
|
|
|
FAR uint8_t *equalization)
|
|
|
|
{
|
|
|
|
#warning Missing logic
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_setbass
|
|
|
|
*
|
|
|
|
* nxplayer_setbass() sets the bass level and range.
|
|
|
|
*
|
|
|
|
* Input:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer - Pointer to the nxplayer context
|
2013-10-27 14:23:01 +01:00
|
|
|
* level - Bass level in percentage (0-100)
|
|
|
|
* range - Bass range in percentage (0-100)
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_setbass(FAR struct nxplayer_s *pplayer, uint8_t level)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
struct audio_caps_desc_s cap_desc;
|
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* If we are currently playing, then we need to post a message to
|
|
|
|
* the playthread to perform the volume change operation. If we
|
|
|
|
* are not playing, then just store the bass setting and it will
|
|
|
|
* be applied before the next playback begins.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->state == NXPLAYER_STATE_PLAYING)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Send a CONFIGURE ioctl to the device to set the volume */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
cap_desc.session = pplayer->session;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-07-24 18:21:04 +02:00
|
|
|
cap_desc.caps.ac_len = sizeof(struct audio_caps_s);
|
|
|
|
cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE;
|
|
|
|
cap_desc.caps.ac_format.hw = AUDIO_FU_BASS;
|
|
|
|
cap_desc.caps.ac_controls.b[0] = level;
|
2022-03-18 13:59:40 +01:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_CONFIGURE, (unsigned long)&cap_desc);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the volume setting */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->bass = level;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_AUDIO_EXCLUDE_TONE */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_settreble
|
|
|
|
*
|
|
|
|
* nxplayer_settreble() sets the treble level and range.
|
|
|
|
*
|
|
|
|
* Input:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer - Pointer to the nxplayer context
|
2013-10-27 14:23:01 +01:00
|
|
|
* level - Treble level in percentage (0-100)
|
|
|
|
* range - Treble range in percentage (0-100)
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_settreble(FAR struct nxplayer_s *pplayer, uint8_t level)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
struct audio_caps_desc_s cap_desc;
|
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* If we are currently playing, then we need to post a message to
|
|
|
|
* the playthread to perform the volume change operation. If we
|
|
|
|
* are not playing, then just store the treble setting and it will
|
|
|
|
* be applied before the next playback begins.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->state == NXPLAYER_STATE_PLAYING)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Send a CONFIGURE ioctl to the device to set the volume */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
cap_desc.session = pplayer->session;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-07-24 18:21:04 +02:00
|
|
|
cap_desc.caps.ac_len = sizeof(struct audio_caps_s);
|
|
|
|
cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE;
|
|
|
|
cap_desc.caps.ac_format.hw = AUDIO_FU_TREBLE;
|
|
|
|
cap_desc.caps.ac_controls.b[0] = level;
|
2022-03-18 13:59:40 +01:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_CONFIGURE, (unsigned long)&cap_desc);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the volume setting */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->treble = level;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_AUDIO_EXCLUDE_TONE */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_setbalance
|
|
|
|
*
|
|
|
|
* nxplayer_setbalance() sets the volume.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-01-27 14:31:40 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_setbalance(FAR struct nxplayer_s *pplayer, uint16_t balance)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2014-07-27 20:26:03 +02:00
|
|
|
struct audio_caps_desc_s cap_desc;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* If we are currently playing, then we need to post a message to
|
|
|
|
* the playthread to perform the volume change operation. If we
|
|
|
|
* are not playing, then just store the volume setting and it will
|
|
|
|
* be applied before the next playback begins.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->state == NXPLAYER_STATE_PLAYING)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Send a CONFIGURE ioctl to the device to set the volume */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
cap_desc.session = pplayer->session;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-07-24 18:21:04 +02:00
|
|
|
cap_desc.caps.ac_len = sizeof(struct audio_caps_s);
|
|
|
|
cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE;
|
|
|
|
cap_desc.caps.ac_format.hw = AUDIO_FU_BALANCE;
|
|
|
|
cap_desc.caps.ac_controls.hw[0] = balance;
|
2022-03-18 13:59:40 +01:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_CONFIGURE, (unsigned long)&cap_desc);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the volume setting */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->balance = balance;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
#endif
|
2019-01-27 14:31:40 +01:00
|
|
|
#endif
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_pause
|
|
|
|
*
|
|
|
|
* nxplayer_pause() pauses playback without cancelling it.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_pause(FAR struct nxplayer_s *pplayer)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2022-10-08 10:31:21 +02:00
|
|
|
int ret = OK;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->state == NXPLAYER_STATE_PLAYING)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_PAUSE,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)pplayer->session);
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_PAUSE, 0);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
if (ret == OK)
|
2014-07-27 20:26:03 +02:00
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->state = NXPLAYER_STATE_PAUSED;
|
2014-07-27 20:26:03 +02:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_resume
|
|
|
|
*
|
|
|
|
* nxplayer_resume() resumes playback after a pause operation.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_resume(FAR struct nxplayer_s *pplayer)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2014-07-27 20:26:03 +02:00
|
|
|
int ret = OK;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->state == NXPLAYER_STATE_PAUSED)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_RESUME,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)pplayer->session);
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_RESUME, 0);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
if (ret == OK)
|
2014-07-27 20:26:03 +02:00
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->state = NXPLAYER_STATE_PLAYING;
|
2014-07-27 20:26:03 +02:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-07-24 16:28:10 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_fforward
|
|
|
|
*
|
|
|
|
* Selects to fast forward in the audio data stream. The fast forward
|
2019-11-20 14:41:05 +01:00
|
|
|
* operation can be canceled by simply selected no sub-sampling with
|
2014-07-27 20:26:03 +02:00
|
|
|
* the AUDIO_SUBSAMPLE_NONE argument returning to normal 1x forward play.
|
|
|
|
* This function may be called multiple times to change fast forward rate.
|
2014-07-24 16:28:10 +02:00
|
|
|
*
|
|
|
|
* The preferred way to cancel a fast forward operation is via
|
|
|
|
* nxplayer_cancel_motion() that provides the option to also return to
|
|
|
|
* paused, non-playing state.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer - Pointer to the context to initialize
|
2014-07-24 16:28:10 +02:00
|
|
|
* subsample - Identifies the fast forward rate (in terms of sub-sampling,
|
2014-07-27 20:26:03 +02:00
|
|
|
* but does not explicitly require sub-sampling). See
|
|
|
|
* AUDIO_SUBSAMPLE_* definitions.
|
2014-07-24 16:28:10 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK if fast forward operation successful.
|
|
|
|
*
|
2015-10-03 01:33:30 +02:00
|
|
|
****************************************************************************/
|
2014-07-24 16:28:10 +02:00
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_FFORWARD
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_fforward(FAR struct nxplayer_s *pplayer, uint8_t subsample)
|
2014-07-24 16:28:10 +02:00
|
|
|
{
|
2014-07-27 20:26:03 +02:00
|
|
|
struct audio_caps_desc_s cap_desc;
|
|
|
|
int ret;
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
DEBUGASSERT(pplayer && subsample >= AUDIO_SUBSAMPLE_NONE &&
|
2014-07-27 20:26:03 +02:00
|
|
|
subsample <= AUDIO_SUBSAMPLE_MAX);
|
|
|
|
|
|
|
|
/* Send a CONFIGURE ioctl to the device to set the forward rate */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
cap_desc.session = pplayer->session;
|
2014-07-27 20:26:03 +02:00
|
|
|
#endif
|
|
|
|
cap_desc.caps.ac_len = sizeof(struct audio_caps_s);
|
|
|
|
cap_desc.caps.ac_type = AUDIO_TYPE_PROCESSING;
|
|
|
|
cap_desc.caps.ac_format.hw = AUDIO_PU_SUBSAMPLE_FORWARD;
|
|
|
|
cap_desc.caps.ac_controls.b[0] = subsample;
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd,
|
|
|
|
AUDIOIOC_CONFIGURE,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)&cap_desc);
|
2014-07-27 20:26:03 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: ioctl AUDIOIOC_CONFIGURE failed: %d\n", errcode);
|
2014-07-27 20:26:03 +02:00
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2014-07-24 16:28:10 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_rewind
|
|
|
|
*
|
|
|
|
* Selects to rewind in the audio data stream. The rewind operation must
|
2014-07-27 20:26:03 +02:00
|
|
|
* be cancelled with nxplayer_cancel_motion. This function may be called
|
|
|
|
* multiple times to change rewind rate.
|
2014-07-24 16:28:10 +02:00
|
|
|
*
|
|
|
|
* NOTE that cancellation of the rewind operation differs from
|
|
|
|
* cancellation of the fast forward operation because we must both restore
|
|
|
|
* the sub-sampling rate to 1x and also return to forward play.
|
2014-07-27 20:26:03 +02:00
|
|
|
* AUDIO_SUBSAMPLE_NONE is not a valid argument to this function.
|
2014-07-24 16:28:10 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer - Pointer to the context to initialize
|
2014-07-24 16:28:10 +02:00
|
|
|
* subsample - Identifies the rewind rate (in terms of sub-sampling, but
|
2014-07-27 20:26:03 +02:00
|
|
|
* does not explicitly require sub-sampling). See
|
|
|
|
* AUDIO_SUBSAMPLE_* definitions.
|
2014-07-24 16:28:10 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK if rewind operation successfully initiated.
|
|
|
|
*
|
2015-10-03 01:33:30 +02:00
|
|
|
****************************************************************************/
|
2014-07-24 16:28:10 +02:00
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_REWIND
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_rewind(FAR struct nxplayer_s *pplayer, uint8_t subsample)
|
2014-07-24 16:28:10 +02:00
|
|
|
{
|
2014-07-27 20:26:03 +02:00
|
|
|
struct audio_caps_desc_s cap_desc;
|
|
|
|
int ret;
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
DEBUGASSERT(pplayer && subsample >= AUDIO_SUBSAMPLE_MIN &&
|
2014-07-27 20:26:03 +02:00
|
|
|
subsample <= AUDIO_SUBSAMPLE_MAX);
|
|
|
|
|
|
|
|
/* Send a CONFIGURE ioctl to the device to set the forward rate */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
cap_desc.session = pplayer->session;
|
2014-07-27 20:26:03 +02:00
|
|
|
#endif
|
|
|
|
cap_desc.caps.ac_len = sizeof(struct audio_caps_s);
|
|
|
|
cap_desc.caps.ac_type = AUDIO_TYPE_PROCESSING;
|
|
|
|
cap_desc.caps.ac_format.hw = AUDIO_PU_SUBSAMPLE_REWIND;
|
|
|
|
cap_desc.caps.ac_controls.b[0] = subsample;
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd,
|
|
|
|
AUDIOIOC_CONFIGURE,
|
2022-03-18 13:59:40 +01:00
|
|
|
(unsigned long)&cap_desc);
|
2014-07-27 20:26:03 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: ioctl AUDIOIOC_CONFIGURE failed: %d\n", errcode);
|
2014-07-27 20:26:03 +02:00
|
|
|
ret = -errcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2014-07-24 16:28:10 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_cancel_motion
|
|
|
|
*
|
|
|
|
* Cancel a rewind or fast forward operation and return to either the
|
|
|
|
* paused state or to the normal, forward play state.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer - Pointer to the context to initialize
|
2014-07-24 16:28:10 +02:00
|
|
|
* paused - True: return to the paused state, False: return to the 1X
|
|
|
|
* forward play state.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK if rewind operation successfully cancelled.
|
|
|
|
*
|
2015-10-03 01:33:30 +02:00
|
|
|
****************************************************************************/
|
2014-07-24 16:28:10 +02:00
|
|
|
|
|
|
|
#if !defined(CONFIG_AUDIO_EXCLUDE_FFORWARD) || !defined(CONFIG_AUDIO_EXCLUDE_REWIND)
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_cancel_motion(FAR struct nxplayer_s *pplayer, bool paused)
|
2014-07-24 16:28:10 +02:00
|
|
|
{
|
2014-07-27 20:26:03 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* I think this is equivalent to calling nxplayer_fforward with the
|
|
|
|
* argument AUDIO_SUBSAMPLE_NONE: Forward motion with no sub-sampling.
|
|
|
|
*
|
|
|
|
* REVISIT: There is no way at present to cancel sub-sampling and return
|
|
|
|
* to pause atomically.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
ret = nxplayer_fforward(pplayer, AUDIO_SUBSAMPLE_NONE);
|
2014-07-27 20:26:03 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: nxplayer_fforward failed: %d\n", ret);
|
2014-07-27 20:26:03 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
|
|
|
if (paused)
|
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
ret = nxplayer_pause(pplayer);
|
2014-07-27 20:26:03 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: nxplayer_pause failed: %d\n", ret);
|
2014-07-27 20:26:03 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return OK;
|
2014-07-24 16:28:10 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_setdevice
|
|
|
|
*
|
2020-02-23 05:51:44 +01:00
|
|
|
* nxplayer_setdevice() sets the preferred audio device to use with the
|
2013-10-27 14:45:16 +01:00
|
|
|
* provided nxplayer context.
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
|
2019-11-20 14:41:05 +01:00
|
|
|
int nxplayer_setdevice(FAR struct nxplayer_s *pplayer,
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR const char *pdevice)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
int temp_fd;
|
2013-10-27 14:23:01 +01:00
|
|
|
struct audio_caps_s caps;
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
DEBUGASSERT(pplayer != NULL);
|
2020-04-21 17:32:44 +02:00
|
|
|
DEBUGASSERT(pdevice != NULL);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Try to open the device */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
temp_fd = open(pdevice, O_RDWR);
|
|
|
|
if (temp_fd == -1)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Error opening the device */
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Validate it's an Audio device by issuing an AUDIOIOC_GETCAPS ioctl */
|
|
|
|
|
2014-07-27 20:26:03 +02:00
|
|
|
caps.ac_len = sizeof(caps);
|
|
|
|
caps.ac_type = AUDIO_TYPE_QUERY;
|
2013-10-27 14:23:01 +01:00
|
|
|
caps.ac_subtype = AUDIO_TYPE_QUERY;
|
2022-03-18 13:59:40 +01:00
|
|
|
if (ioctl(temp_fd, AUDIOIOC_GETCAPS, (unsigned long)&caps) != caps.ac_len)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Not an Audio device! */
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
close(temp_fd);
|
2013-10-27 14:23:01 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the file */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
close(temp_fd);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Save the path and format capabilities of the preferred device */
|
|
|
|
|
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
|
|
|
strlcpy(pplayer->prefdevice, pdevice, sizeof(pplayer->prefdevice));
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->prefformat = caps.ac_format.b[0] | (caps.ac_format.b[1] << 8);
|
|
|
|
pplayer->preftype = caps.ac_controls.b[0];
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
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_stop
|
|
|
|
*
|
|
|
|
* nxplayer_stop() stops the current playback and closes the file and
|
|
|
|
* the associated device.
|
|
|
|
*
|
|
|
|
* Input:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer Pointer to the initialized MPlayer context
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_stop(FAR struct nxplayer_s *pplayer)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2022-10-08 10:31:21 +02:00
|
|
|
struct audio_msg_s term_msg;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
DEBUGASSERT(pplayer != NULL);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Validate we are not in IDLE state */
|
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->state == NXPLAYER_STATE_IDLE)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
return OK;
|
|
|
|
}
|
2013-10-28 19:11:52 +01:00
|
|
|
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Notify the playback thread that it needs to cancel the playback */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
term_msg.msg_id = AUDIO_MSG_STOP;
|
2013-10-27 14:23:01 +01:00
|
|
|
term_msg.u.data = 0;
|
2019-02-16 02:25:01 +01:00
|
|
|
mq_send(pplayer->mq, (FAR const char *)&term_msg, sizeof(term_msg),
|
2015-02-09 19:50:04 +01:00
|
|
|
CONFIG_NXPLAYER_MSG_PRIO);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Join the thread. The thread will do all the cleanup. */
|
|
|
|
|
2023-01-03 13:35:46 +01:00
|
|
|
nxplayer_jointhread(pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_AUDIO_EXCLUDE_STOP */
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2018-08-27 16:04:48 +02:00
|
|
|
* Name: nxplayer_playinternal
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
2018-08-27 16:04:48 +02:00
|
|
|
* nxplayer_playinternal() tries to play the specified file/raw data
|
|
|
|
* 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.
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
|
|
|
* Input:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer Pointer to the initialized MPlayer context
|
2020-04-21 17:32:44 +02:00
|
|
|
* pfilename Pointer to the filename to play
|
2013-10-27 14:23:01 +01:00
|
|
|
* filefmt Format of the file or AUD_FMT_UNDEF if unknown / to be
|
|
|
|
* determined by nxplayer_playfile()
|
2018-08-27 16:04:48 +02:00
|
|
|
* nchannels channels num (raw data playback needed)
|
|
|
|
* bpsamp bits pre sample (raw data playback needed)
|
2020-09-12 09:19:01 +02:00
|
|
|
* samprate samplre rate (raw data playback needed)
|
|
|
|
* chmap channel map (raw data playback needed)
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2018-08-27 16:04:48 +02:00
|
|
|
*
|
2013-10-27 14:23:01 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR const char *pfilename, int filefmt,
|
2018-08-27 16:04:48 +02:00
|
|
|
int subfmt, uint8_t nchannels,
|
2020-09-12 09:19:01 +02:00
|
|
|
uint8_t bpsamp, uint32_t samprate,
|
|
|
|
uint8_t chmap)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
struct mq_attr attr;
|
|
|
|
struct sched_param sparam;
|
|
|
|
pthread_attr_t tattr;
|
2018-08-27 16:04:48 +02:00
|
|
|
struct audio_caps_desc_s cap_desc;
|
2020-12-14 11:13:54 +01:00
|
|
|
struct ap_buffer_info_s buf_info;
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
system/nxplayer: Fix the compiler warning
nxplayer.c: In function 'nxplayer_playinternal':
Error: nxplayer.c:209:36: error: '%s' directive output may be truncated writing up to 99 bytes into a region of size 59 [-Werror=format-truncation=]
209 | snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", relurl);
| ^~ ~~~~~~
nxplayer.c:209:3: note: 'snprintf' output between 19 and 118 bytes into a destination of size 64
209 | snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", relurl);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: nxplayer.c:1809:42: error: 'snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
1809 | snprintf(path, sizeof(path), "%s/%s", pplayer->mediadir, pfilename);
| ^
nxplayer.c:1809:7: note: 'snprintf' output 2 or more bytes (assuming 129) into a destination of size 128
1809 | snprintf(path, sizeof(path), "%s/%s", pplayer->mediadir, pfilename);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: nxplayer.c:359:53: error: '%s' directive output may be truncated writing up to 128 bytes into a region of size 53 [-Werror=format-truncation=]
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~
nxplayer.c:359:11: note: 'snprintf' output between 12 and 140 bytes into a destination of size 64
359 | snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-06 10:58:50 +01:00
|
|
|
char path[PATH_MAX];
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2014-07-24 23:06:54 +02:00
|
|
|
int tmpsubfmt = AUDIO_FMT_UNDEF;
|
|
|
|
int ret;
|
2022-11-30 02:27:36 +01:00
|
|
|
int c;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
DEBUGASSERT(pplayer != NULL);
|
2020-04-21 17:32:44 +02:00
|
|
|
DEBUGASSERT(pfilename != NULL);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer->state != NXPLAYER_STATE_IDLE)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("==============================\n");
|
2020-04-21 17:32:44 +02:00
|
|
|
audinfo("Playing file %s\n", pfilename);
|
2016-06-11 19:55:38 +02:00
|
|
|
audinfo("==============================\n");
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Test that the specified file exists */
|
|
|
|
|
2017-12-19 06:57:36 +01:00
|
|
|
#ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT
|
2020-04-21 17:32:44 +02:00
|
|
|
if ((pplayer->fd = _open_with_http(pfilename)) == -1)
|
2017-12-19 06:57:36 +01:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
if ((pplayer->fd = open(pfilename, O_RDONLY)) == -1)
|
2017-12-19 06:57:36 +01:00
|
|
|
#endif
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* File not found. Test if its in the mediadir */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
2020-04-21 17:32:44 +02:00
|
|
|
snprintf(path, sizeof(path), "%s/%s", pplayer->mediadir, pfilename);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
if ((pplayer->fd = open(path, O_RDONLY)) == -1)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_NXPLAYER_MEDIA_SEARCH
|
|
|
|
/* File not found in the media dir. Do a search */
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
if (nxplayer_mediasearch(pplayer, pfilename, path,
|
2019-11-20 14:41:05 +01:00
|
|
|
sizeof(path)) != OK)
|
2013-10-28 19:11:52 +01:00
|
|
|
{
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: Could not find file\n");
|
2013-10-28 19:11:52 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
auderr("ERROR: Could not open %s or %s\n", pfilename, path);
|
2013-10-27 14:23:01 +01:00
|
|
|
return -ENOENT;
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_NXPLAYER_MEDIA_SEARCH */
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
|
2014-07-22 17:27:24 +02:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
auderr("ERROR: Could not open %s\n", pfilename);
|
2019-11-20 14:41:05 +01:00
|
|
|
return -ENOENT;
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
|
2013-10-27 14:45:16 +01:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2014-07-22 17:27:24 +02:00
|
|
|
#ifdef CONFIG_NXPLAYER_FMT_FROM_EXT
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Try to determine the format of audio file based on the extension */
|
|
|
|
|
|
|
|
if (filefmt == AUDIO_FMT_UNDEF)
|
2014-07-22 17:27:24 +02:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
filefmt = nxplayer_fmtfromextension(pplayer, pfilename, &tmpsubfmt);
|
2014-07-22 17:27:24 +02:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
2014-07-22 17:27:24 +02:00
|
|
|
#ifdef CONFIG_NXPLAYER_FMT_FROM_HEADER
|
2013-10-27 14:23:01 +01:00
|
|
|
/* If type not identified, then test for known header types */
|
|
|
|
|
|
|
|
if (filefmt == AUDIO_FMT_UNDEF)
|
2014-07-22 17:27:24 +02:00
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
filefmt = nxplayer_fmtfromheader(pplayer, &subfmt, &tmpsubfmt);
|
2014-07-22 17:27:24 +02:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Test if we determined the file format */
|
|
|
|
|
|
|
|
if (filefmt == AUDIO_FMT_UNDEF)
|
|
|
|
{
|
|
|
|
/* Hmmm, it's some unknown / unsupported type */
|
|
|
|
|
2021-12-26 23:10:48 +01:00
|
|
|
auderr("ERROR: Unsupported format: %d\n", filefmt);
|
2013-10-27 14:23:01 +01:00
|
|
|
ret = -ENOSYS;
|
|
|
|
goto err_out_nodev;
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:11:52 +01:00
|
|
|
/* Test if we have a sub format assignment from above */
|
|
|
|
|
|
|
|
if (subfmt == AUDIO_FMT_UNDEF)
|
|
|
|
{
|
|
|
|
subfmt = tmpsubfmt;
|
|
|
|
}
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Try to open the device */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
ret = nxplayer_opendevice(pplayer, filefmt, subfmt);
|
2013-10-27 14:23:01 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Error opening the device */
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: nxplayer_opendevice failed: %d\n", ret);
|
2013-10-27 14:23:01 +01:00
|
|
|
goto err_out_nodev;
|
|
|
|
}
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2022-11-30 02:27:36 +01:00
|
|
|
for (c = 0; c < sizeof(g_dec_ops) / sizeof(g_dec_ops[0]); c++)
|
|
|
|
{
|
|
|
|
if (g_dec_ops[c].format == filefmt)
|
|
|
|
{
|
|
|
|
pplayer->ops = &g_dec_ops[c];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pplayer->ops)
|
|
|
|
{
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pplayer->ops->pre_parse)
|
|
|
|
{
|
|
|
|
ret = pplayer->ops->pre_parse(pplayer->fd, &samprate,
|
|
|
|
&nchannels, &bpsamp);
|
|
|
|
}
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Try to reserve the device */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_RESERVE,
|
2019-02-16 02:25:01 +01:00
|
|
|
(unsigned long)&pplayer->session);
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = ioctl(pplayer->dev_fd, AUDIOIOC_RESERVE, 0);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Device is busy or error */
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: Failed to reserve device: %d\n", ret);
|
2013-10-27 14:23:01 +01:00
|
|
|
ret = -errno;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2018-08-27 16:04:48 +02:00
|
|
|
if (nchannels && samprate && bpsamp)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
cap_desc.session = pplayer->session;
|
2018-08-27 16:04:48 +02:00
|
|
|
#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;
|
2020-09-12 09:19:01 +02:00
|
|
|
cap_desc.caps.ac_chmap = chmap;
|
2018-08-27 16:04:48 +02:00
|
|
|
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;
|
2022-11-30 02:27:36 +01:00
|
|
|
cap_desc.caps.ac_subtype = filefmt;
|
2018-08-27 16:04:48 +02:00
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_CONFIGURE, (unsigned long)&cap_desc);
|
2018-08-27 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2020-12-14 11:13:54 +01:00
|
|
|
/* Query the audio device for its preferred buffer count */
|
|
|
|
|
|
|
|
if (ioctl(pplayer->dev_fd, AUDIOIOC_GETBUFFERINFO,
|
|
|
|
(unsigned long)&buf_info) != OK)
|
|
|
|
{
|
|
|
|
/* Driver doesn't report its buffer size. Use our default. */
|
|
|
|
|
|
|
|
buf_info.nbuffers = CONFIG_AUDIO_NUM_BUFFERS;
|
|
|
|
}
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Create a message queue for the playthread */
|
|
|
|
|
2020-12-14 11:13:54 +01:00
|
|
|
attr.mq_maxmsg = buf_info.nbuffers + 8;
|
2013-10-27 14:23:01 +01:00
|
|
|
attr.mq_msgsize = sizeof(struct audio_msg_s);
|
|
|
|
attr.mq_curmsgs = 0;
|
2014-07-22 17:27:24 +02:00
|
|
|
attr.mq_flags = 0;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
snprintf(pplayer->mqname, sizeof(pplayer->mqname), "/tmp/%0lx",
|
|
|
|
(unsigned long)((uintptr_t)pplayer));
|
2014-11-25 22:41:34 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->mq = mq_open(pplayer->mqname, O_RDWR | O_CREAT, 0644, &attr);
|
2021-01-03 15:14:49 +01:00
|
|
|
if (pplayer->mq == (mqd_t) -1)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* Unable to open message queue! */
|
|
|
|
|
|
|
|
ret = -errno;
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: mq_open failed: %d\n", ret);
|
2013-10-27 14:23:01 +01:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register our message queue with the audio device */
|
|
|
|
|
2022-03-18 13:59:40 +01:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_REGISTERMQ, (unsigned long)pplayer->mq);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Check if there was a previous thread and join it if there was
|
2014-07-22 17:27:24 +02:00
|
|
|
* to perform clean-up.
|
2013-10-27 14:23:01 +01:00
|
|
|
*/
|
|
|
|
|
2023-01-03 13:35:46 +01:00
|
|
|
nxplayer_jointhread(pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2013-10-27 14:45:16 +01:00
|
|
|
/* Start the playfile thread to stream the media file to the
|
2013-10-27 14:23:01 +01:00
|
|
|
* audio device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
pthread_attr_init(&tattr);
|
|
|
|
sparam.sched_priority = sched_get_priority_max(SCHED_FIFO) - 9;
|
2020-01-02 13:09:50 +01:00
|
|
|
pthread_attr_setschedparam(&tattr, &sparam);
|
|
|
|
pthread_attr_setstacksize(&tattr,
|
|
|
|
CONFIG_NXPLAYER_PLAYTHREAD_STACKSIZE);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2013-10-27 14:45:16 +01:00
|
|
|
/* Add a reference count to the player for the thread and start the
|
2013-10-27 14:23:01 +01:00
|
|
|
* thread. We increment for the thread to avoid thread start-up
|
|
|
|
* race conditions.
|
|
|
|
*/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
nxplayer_reference(pplayer);
|
2020-04-21 17:32:44 +02:00
|
|
|
ret = pthread_create(&pplayer->play_id, &tattr, nxplayer_playthread,
|
2019-02-16 02:25:01 +01:00
|
|
|
(pthread_addr_t) pplayer);
|
2013-10-27 14:23:01 +01:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2016-06-11 23:51:27 +02:00
|
|
|
auderr("ERROR: Failed to create playthread: %d\n", ret);
|
2013-10-27 14:23:01 +01:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2013-11-10 17:58:14 +01:00
|
|
|
/* Name the thread */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
pthread_setname_np(pplayer->play_id, "playthread");
|
2013-10-27 14:23:01 +01:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
err_out:
|
2020-04-21 17:32:44 +02:00
|
|
|
close(pplayer->dev_fd);
|
|
|
|
pplayer->dev_fd = -1;
|
2013-10-28 19:11:52 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
err_out_nodev:
|
2019-02-16 02:25:01 +01:00
|
|
|
if (0 < pplayer->fd)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
close(pplayer->fd);
|
|
|
|
pplayer->fd = -1;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
2013-10-28 19:11:52 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-27 16:04:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer Pointer to the initialized MPlayer context
|
2020-04-21 17:32:44 +02:00
|
|
|
* pfilename Pointer to the filename to play
|
2018-08-27 16:04:48 +02:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_playfile(FAR struct nxplayer_s *pplayer,
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR const char *pfilename, int filefmt, int subfmt)
|
2018-08-27 16:04:48 +02:00
|
|
|
{
|
2020-09-12 09:19:01 +02:00
|
|
|
return nxplayer_playinternal(pplayer, pfilename, filefmt,
|
|
|
|
subfmt, 0, 0, 0, 0);
|
2018-08-27 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer Pointer to the initialized MPlayer context
|
2020-04-21 17:32:44 +02:00
|
|
|
* pfilename Pointer to the filename to play
|
2018-08-27 16:04:48 +02:00
|
|
|
* nchannels channel num
|
|
|
|
* bpsampe bit width
|
|
|
|
* samprate sample rate
|
2020-09-12 09:19:01 +02:00
|
|
|
* chmap channel map
|
2018-08-27 16:04:48 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_playraw(FAR struct nxplayer_s *pplayer,
|
2020-04-21 17:32:44 +02:00
|
|
|
FAR const char *pfilename, uint8_t nchannels,
|
2020-09-12 09:19:01 +02:00
|
|
|
uint8_t bpsamp, uint32_t samprate, uint8_t chmap)
|
2018-08-27 16:04:48 +02:00
|
|
|
{
|
|
|
|
if (nchannels == 0)
|
|
|
|
{
|
|
|
|
nchannels = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bpsamp == 0)
|
|
|
|
{
|
|
|
|
bpsamp = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (samprate == 0)
|
|
|
|
{
|
|
|
|
samprate = 48000;
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
return nxplayer_playinternal(pplayer, pfilename, AUDIO_FMT_PCM, 0,
|
2020-09-12 09:19:01 +02:00
|
|
|
nchannels, bpsamp, samprate, chmap);
|
2018-08-27 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_setmediadir
|
|
|
|
*
|
|
|
|
* nxplayer_setmediadir() sets the root path for media searches.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
2019-02-16 02:25:01 +01:00
|
|
|
void nxplayer_setmediadir(FAR struct nxplayer_s *pplayer,
|
2014-07-24 23:06:54 +02:00
|
|
|
FAR const char *mediadir)
|
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
|
|
|
strlcpy(pplayer->mediadir, mediadir, sizeof(pplayer->mediadir));
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_create
|
|
|
|
*
|
2013-10-27 14:45:16 +01:00
|
|
|
* nxplayer_create() allocates and initializes a nxplayer context for
|
|
|
|
* use by further nxplayer operations. This routine must be called before
|
2013-10-27 14:23:01 +01:00
|
|
|
* to perform the create for proper reference counting.
|
|
|
|
*
|
|
|
|
* Input Parameters: None
|
|
|
|
*
|
|
|
|
* Returned values:
|
|
|
|
* Pointer to the created context or NULL if there was an error.
|
|
|
|
*
|
2015-10-03 01:33:30 +02:00
|
|
|
****************************************************************************/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
FAR struct nxplayer_s *nxplayer_create(void)
|
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
FAR struct nxplayer_s *pplayer;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Allocate the memory */
|
|
|
|
|
2022-10-08 10:31:21 +02:00
|
|
|
pplayer = (FAR struct nxplayer_s *)malloc(sizeof(struct nxplayer_s));
|
2019-02-16 02:25:01 +01:00
|
|
|
if (pplayer == NULL)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the context data */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->state = NXPLAYER_STATE_IDLE;
|
2020-04-21 17:32:44 +02:00
|
|
|
pplayer->dev_fd = -1;
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->fd = -1;
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->prefdevice[0] = '\0';
|
|
|
|
pplayer->prefformat = 0;
|
|
|
|
pplayer->preftype = 0;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2021-01-03 15:14:49 +01:00
|
|
|
pplayer->mq = 0;
|
2020-04-21 17:32:44 +02:00
|
|
|
pplayer->play_id = 0;
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->crefs = 1;
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->bass = 50;
|
|
|
|
pplayer->treble = 50;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-27 14:31:40 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->volume = 400;
|
2013-10-27 14:23:01 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_BALANCE
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->balance = 500;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->session = NULL;
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
|
2019-02-16 02:25:01 +01:00
|
|
|
strncpy(pplayer->mediadir, CONFIG_NXPLAYER_DEFAULT_MEDIADIR,
|
|
|
|
sizeof(pplayer->mediadir));
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2023-01-03 12:28:25 +01:00
|
|
|
|
|
|
|
pthread_mutex_init(&pplayer->mutex, NULL);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
return pplayer;
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_release
|
|
|
|
*
|
2013-10-27 14:45:16 +01:00
|
|
|
* nxplayer_release() reduces the reference count by one and if it
|
2013-10-27 14:23:01 +01:00
|
|
|
* reaches zero, frees the context.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer Pointer to the NxPlayer context
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
|
|
|
* Returned values: None
|
|
|
|
*
|
2015-10-03 01:33:30 +02:00
|
|
|
****************************************************************************/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
void nxplayer_release(FAR struct nxplayer_s *pplayer)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2014-11-25 22:41:34 +01:00
|
|
|
int refcount;
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Check if there was a previous thread and join it if there was */
|
|
|
|
|
2023-01-03 13:35:46 +01:00
|
|
|
nxplayer_jointhread(pplayer);
|
2014-07-31 22:59:51 +02:00
|
|
|
|
2023-01-03 13:35:46 +01:00
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Reduce the reference count */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
refcount = pplayer->crefs--;
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* If the ref count *was* one, then free the context */
|
|
|
|
|
|
|
|
if (refcount == 1)
|
2014-11-25 22:41:34 +01:00
|
|
|
{
|
2019-02-16 02:25:01 +01:00
|
|
|
free(pplayer);
|
2014-11-25 22:41:34 +01:00
|
|
|
}
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_reference
|
|
|
|
*
|
|
|
|
* nxplayer_reference() increments the reference count by one.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2019-02-16 02:25:01 +01:00
|
|
|
* pplayer Pointer to the NxPlayer context
|
2013-10-27 14:23:01 +01:00
|
|
|
*
|
|
|
|
* Returned values: None
|
|
|
|
*
|
2015-10-03 01:33:30 +02:00
|
|
|
****************************************************************************/
|
2013-10-27 14:23:01 +01:00
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
void nxplayer_reference(FAR struct nxplayer_s *pplayer)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_lock(&pplayer->mutex);
|
2013-10-27 14:45:16 +01:00
|
|
|
|
2013-10-27 14:23:01 +01:00
|
|
|
/* Increment the reference count */
|
|
|
|
|
2019-02-16 02:25:01 +01:00
|
|
|
pplayer->crefs++;
|
2023-01-03 12:28:25 +01:00
|
|
|
pthread_mutex_unlock(&pplayer->mutex);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxplayer_systemreset
|
|
|
|
*
|
|
|
|
* nxplayer_systemreset() performs a HW reset on all registered
|
|
|
|
* audio devices.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXPLAYER_INCLUDE_SYSTEM_RESET
|
2019-02-16 02:25:01 +01:00
|
|
|
int nxplayer_systemreset(FAR struct nxplayer_s *pplayer)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
2020-04-21 17:32:44 +02:00
|
|
|
struct dirent *pdevice;
|
2014-07-22 17:27:24 +02:00
|
|
|
DIR *dirp;
|
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
|
|
|
char path[PATH_MAX];
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Search for a device in the audio device directory */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH
|
|
|
|
#ifdef CONFIG_AUDIO_DEV_ROOT
|
|
|
|
dirp = opendir("/dev");
|
|
|
|
#else
|
|
|
|
dirp = opendir(CONFIG_AUDIO_DEV_PATH);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
dirp = opendir("/dev/audio");
|
|
|
|
#endif
|
|
|
|
if (dirp == NULL)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
while ((pdevice = readdir(dirp)) != NULL)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* We found the next device. Try to open it and
|
|
|
|
* get its audio capabilities.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH
|
|
|
|
#ifdef CONFIG_AUDIO_DEV_ROOT
|
2020-04-21 17:32:44 +02:00
|
|
|
snprintf(path, sizeof(path), "/dev/%s", pdevice->d_name);
|
2013-10-27 14:23:01 +01:00
|
|
|
#else
|
2019-11-20 14:41:05 +01:00
|
|
|
snprintf(path, sizeof(path), CONFIG_AUDIO_DEV_PATH "/%s",
|
2020-04-21 17:32:44 +02:00
|
|
|
pdevice->d_name);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
|
|
|
#else
|
2020-04-21 17:32:44 +02:00
|
|
|
snprintf(path, sizeof(path), "/dev/audio/%s", pdevice->d_name);
|
2013-10-27 14:23:01 +01:00
|
|
|
#endif
|
2020-12-17 13:14:08 +01:00
|
|
|
if ((pplayer->dev_fd = open(path, O_RDWR | O_CLOEXEC)) != -1)
|
2013-10-27 14:23:01 +01:00
|
|
|
{
|
|
|
|
/* We have the device file open. Now issue an
|
|
|
|
* AUDIO ioctls to perform a HW reset
|
|
|
|
*/
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
ioctl(pplayer->dev_fd, AUDIOIOC_HWRESET, 0);
|
2013-10-27 14:23:01 +01:00
|
|
|
|
|
|
|
/* Now close the device */
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
close(pplayer->dev_fd);
|
2013-10-27 14:23:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:32:44 +02:00
|
|
|
pplayer->dev_fd = -1;
|
2013-10-27 14:23:01 +01:00
|
|
|
return OK;
|
|
|
|
}
|
2020-01-31 16:18:05 +01:00
|
|
|
#endif /* CONFIG_NXPLAYER_INCLUDE_SYSTEM_RESET */
|