Skip to content

Commit d3bebeb

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 d3bebeb

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

system/nxplayer/nxplayer.c

Lines changed: 46 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,30 @@ 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+
227+
// DNS resolution failed
228+
return -ENETUNREACH;
229+
}
224230

225231
memcpy(&server.sin_addr.s_addr,
226232
he->h_addr, sizeof(in_addr_t));
227-
228233
n = connect(s,
229234
(struct sockaddr *)&server,
230235
sizeof(struct sockaddr_in));
231-
232236
if (-1 == n)
233237
{
238+
int err = errno;
234239
close(s);
235-
return -1;
240+
switch (err)
241+
{
242+
case ETIMEDOUT: return -ETIMEDOUT;
243+
case ECONNREFUSED: return -ECONNREFUSED;
244+
case ENETUNREACH: return -ENETUNREACH;
245+
default: return -1;
246+
}
236247
}
237248

238249
/* Send GET request */
@@ -250,8 +261,24 @@ static int _open_with_http(const char *fullurl)
250261

251262
if (200 != n)
252263
{
264+
int err = errno;
253265
close(s);
254-
return -1;
266+
switch (err)
267+
{
268+
// Unauthorized
269+
case 401: return -EACCES;
270+
271+
// No access
272+
case 403: return -EACCES;
273+
274+
case 404: return -ENOENT;
275+
276+
// Server internal error
277+
case 500: return -EREMOTEIO;
278+
279+
// Other protocol errors
280+
default: return -EPROTO;
281+
}
255282
}
256283

257284
/* Skip response header */
@@ -1809,11 +1836,15 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
18091836
/* Test that the specified file exists */
18101837

18111838
#ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT
1812-
if ((pplayer->fd = _open_with_http(pfilename)) == -1)
1839+
pplayer->fd = _open_with_http(pfilename);
1840+
if (pplayer->fd < 0)
18131841
#else
1814-
if ((pplayer->fd = open(pfilename, O_RDONLY)) == -1)
1842+
pplayer->fd = open(pfilename, O_RDONLY);
1843+
if (pplayer->fd == -1)
18151844
#endif
18161845
{
1846+
int err = errno;
1847+
18171848
/* File not found. Test if its in the mediadir */
18181849

18191850
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
@@ -1827,19 +1858,21 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
18271858
if (nxplayer_mediasearch(pplayer, pfilename, path,
18281859
sizeof(path)) != OK)
18291860
{
1830-
auderr("ERROR: Could not find file\n");
1831-
return -ENOENT;
1861+
auderr("ERROR: Media search failed for %s: %s\n",
1862+
pfilename, strerror(err));
1863+
return -err;
18321864
}
18331865
#else
1834-
auderr("ERROR: Could not open %s or %s\n", pfilename, path);
1835-
return -ENOENT;
1866+
auderr("ERROR: Could not open %s or %s: %s\n",
1867+
pfilename, path, strerror(err));
1868+
return -err;
18361869
#endif /* CONFIG_NXPLAYER_MEDIA_SEARCH */
18371870
}
18381871

18391872
#else /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
18401873

1841-
auderr("ERROR: Could not open %s\n", pfilename);
1842-
return -ENOENT;
1874+
auderr("ERROR: Could not open %s: %s\n", pfilename, strerror(err));
1875+
return -err;
18431876
#endif /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
18441877
}
18451878

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)