Skip to content

Commit d4b63d9

Browse files
committed
nxplayer: add more error messages
nxplayer currently only returns directly '-ENOENT', which makes it impossible to know the specific reason for the failure when testing audio with nxplayer. Therefore, I modified this part of the logic to print out the error as much as possible. Signed-off-by: Tang Meng <v-tangmeng@xiaomi.com>
1 parent 971a737 commit d4b63d9

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

system/nxplayer/nxplayer.c

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ static int _open_with_http(const char *fullurl)
199199
n = netlib_parsehttpurl(fullurl, &port,
200200
hostname, sizeof(hostname) - 1,
201201
relurl, sizeof(relurl) - 1);
202-
203202
if (OK != n)
204203
{
205204
printf("netlib_parsehttpurl() returned %d\n", n);
@@ -221,18 +220,28 @@ static int _open_with_http(const char *fullurl)
221220

222221
FAR struct hostent *he;
223222
he = gethostbyname(hostname);
223+
if (!he)
224+
{
225+
close(s);
226+
return -ENETUNREACH; /* DNS resolution failed */
227+
}
224228

225229
memcpy(&server.sin_addr.s_addr,
226230
he->h_addr, sizeof(in_addr_t));
227-
228231
n = connect(s,
229232
(struct sockaddr *)&server,
230233
sizeof(struct sockaddr_in));
231-
232234
if (-1 == n)
233235
{
236+
int err = errno;
234237
close(s);
235-
return -1;
238+
switch (err)
239+
{
240+
case ETIMEDOUT: return -ETIMEDOUT;
241+
case ECONNREFUSED: return -ECONNREFUSED;
242+
case ENETUNREACH: return -ENETUNREACH;
243+
default: return -1;
244+
}
236245
}
237246

238247
/* Send GET request */
@@ -250,8 +259,16 @@ static int _open_with_http(const char *fullurl)
250259

251260
if (200 != n)
252261
{
262+
int err = errno;
253263
close(s);
254-
return -1;
264+
switch (err)
265+
{
266+
case 401: return -EACCES; /* No Access */
267+
case 403: return -EACCES; /* No Access */
268+
case 404: return -ENOENT;
269+
case 500: return -EREMOTEIO; /* Server internal error */
270+
default: return -EPROTO; /* Other protocol error */
271+
}
255272
}
256273

257274
/* Skip response header */
@@ -1809,11 +1826,15 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
18091826
/* Test that the specified file exists */
18101827

18111828
#ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT
1812-
if ((pplayer->fd = _open_with_http(pfilename)) == -1)
1829+
pplayer->fd = _open_with_http(pfilename);
1830+
if (pplayer->fd < 0)
18131831
#else
1814-
if ((pplayer->fd = open(pfilename, O_RDONLY)) == -1)
1832+
pplayer->fd = open(pfilename, O_RDONLY);
1833+
if (pplayer->fd == -1)
18151834
#endif
18161835
{
1836+
int err = errno;
1837+
18171838
/* File not found. Test if its in the mediadir */
18181839

18191840
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
@@ -1827,19 +1848,21 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
18271848
if (nxplayer_mediasearch(pplayer, pfilename, path,
18281849
sizeof(path)) != OK)
18291850
{
1830-
auderr("ERROR: Could not find file\n");
1831-
return -ENOENT;
1851+
auderr("ERROR: Media search failed for %s: %s\n",
1852+
pfilename, strerror(err));
1853+
return -err;
18321854
}
18331855
#else
1834-
auderr("ERROR: Could not open %s or %s\n", pfilename, path);
1835-
return -ENOENT;
1856+
auderr("ERROR: Could not open %s or %s: %s\n",
1857+
pfilename, path, strerror(err));
1858+
return -err;
18361859
#endif /* CONFIG_NXPLAYER_MEDIA_SEARCH */
18371860
}
18381861

18391862
#else /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
18401863

1841-
auderr("ERROR: Could not open %s\n", pfilename);
1842-
return -ENOENT;
1864+
auderr("ERROR: Could not open %s: %s\n", pfilename, strerror(err));
1865+
return -err;
18431866
#endif /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
18441867
}
18451868

system/nxplayer/nxplayer_main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,22 @@ static int nxplayer_cmd_play(FAR struct nxplayer_s *pplayer, char *parg)
290290
printf("File %s not found\n", parg);
291291
break;
292292

293+
case ENETUNREACH:
294+
printf("DNS resolution failed\n");
295+
break;
296+
297+
case ETIMEDOUT:
298+
printf("Timeout\n");
299+
break;
300+
301+
case EACCES:
302+
printf("No access\n");
303+
break;
304+
305+
case ECONNREFUSED:
306+
printf("Connect refused\n");
307+
break;
308+
293309
case ENOSYS:
294310
printf("Unknown audio format\n");
295311
break;

0 commit comments

Comments
 (0)