-
Notifications
You must be signed in to change notification settings - Fork 649
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -221,18 +220,35 @@ static int _open_with_http(const char *fullurl) | |
|
||
FAR struct hostent *he; | ||
he = gethostbyname(hostname); | ||
if (!he) | ||
{ | ||
close(s); | ||
return -ENETUNREACH; /* DNS resolution failed */ | ||
} | ||
|
||
memcpy(&server.sin_addr.s_addr, | ||
he->h_addr, sizeof(in_addr_t)); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please take a look what switch format is preferred https://nuttx.apache.org/docs/latest/contributing/coding_style.html#switch-statement |
||
{ | ||
case ETIMEDOUT: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 */ | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
he == NULL
?