Skip to content

nxplayer: add more error messages #3117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions system/nxplayer/nxplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ static int _open_with_http(const char *fullurl)
n = netlib_parsehttpurl(fullurl, &port,
hostname, sizeof(hostname) - 1,
relurl, sizeof(relurl) - 1);

if (OK != n)
{
printf("netlib_parsehttpurl() returned %d\n", n);
Expand All @@ -221,18 +220,35 @@ static int _open_with_http(const char *fullurl)

FAR struct hostent *he;
he = gethostbyname(hostname);
if (!he)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

he == NULL ?

{
close(s);
return -ENETUNREACH; /* DNS resolution failed */
}

memcpy(&server.sin_addr.s_addr,
he->h_addr, sizeof(in_addr_t));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these blank lines increase readability we can leave them untouched :-)

n = connect(s,
(struct sockaddr *)&server,
sizeof(struct sockaddr_in));

if (-1 == n)
{
int err = errno;
close(s);
return -1;
switch (err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
case ETIMEDOUT:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not return -err

return -ETIMEDOUT;

case ECONNREFUSED:
return -ECONNREFUSED;

case ENETUNREACH:
return -ENETUNREACH;

default:
return -1;
}
}

/* Send GET request */
Expand All @@ -250,8 +266,25 @@ static int _open_with_http(const char *fullurl)

if (200 != n)
{
int err = errno;
close(s);
return -1;
switch (err)
{
case 401:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you think errno contain 401/403?

return -EACCES; /* No Access */

case 403:
return -EACCES; /* No Access */

case 404:
return -ENOENT;

case 500:
return -EREMOTEIO; /* Server internal error */

default:
return -EPROTO; /* Other protocol error */
}
}

/* Skip response header */
Expand Down Expand Up @@ -1809,11 +1842,15 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
/* Test that the specified file exists */

#ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT
if ((pplayer->fd = _open_with_http(pfilename)) == -1)
pplayer->fd = _open_with_http(pfilename);
if (pplayer->fd < 0)
#else
if ((pplayer->fd = open(pfilename, O_RDONLY)) == -1)
pplayer->fd = open(pfilename, O_RDONLY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When splitting here please also update other places (i.e. line 1859).

if (pplayer->fd == -1)
#endif
{
int err = errno;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why catch errno


/* File not found. Test if its in the mediadir */

#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
Expand All @@ -1827,19 +1864,21 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
if (nxplayer_mediasearch(pplayer, pfilename, path,
sizeof(path)) != OK)
{
auderr("ERROR: Could not find file\n");
return -ENOENT;
auderr("ERROR: Media search failed for %s: %s\n",
pfilename, strerror(err));
return -err;
}
#else
auderr("ERROR: Could not open %s or %s\n", pfilename, path);
return -ENOENT;
auderr("ERROR: Could not open %s or %s: %s\n",
pfilename, path, strerror(err));
return -err;
#endif /* CONFIG_NXPLAYER_MEDIA_SEARCH */
}

#else /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */

auderr("ERROR: Could not open %s\n", pfilename);
return -ENOENT;
auderr("ERROR: Could not open %s: %s\n", pfilename, strerror(err));
return -err;
#endif /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
}

Expand Down
16 changes: 16 additions & 0 deletions system/nxplayer/nxplayer_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@ static int nxplayer_cmd_play(FAR struct nxplayer_s *pplayer, char *parg)
printf("File %s not found\n", parg);
break;

case ENETUNREACH:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printf("DNS resolution failed\n");
break;

case ETIMEDOUT:
printf("Timeout\n");
break;

case EACCES:
printf("No access\n");
break;

case ECONNREFUSED:
printf("Connect refused\n");
break;

case ENOSYS:
printf("Unknown audio format\n");
break;
Expand Down
Loading