1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-12 01:46:16 +00:00

stream_dvb: Extend token-list for pid-parsing, magically allows to parse VDR-style PID-lists.

I also added a comment explaining the potentially occuring structures for future reference.

For tokenization, a custom strtok_r implementation is used,
inspired by strtok_r as implemented in musl and ffmpeg,
hopefully slightly more readable (av_strtok_r is not available in libav,
and strtok_r is not available everywhere).
This commit is contained in:
Oliver Freyermuth 2014-12-31 03:27:33 +01:00 committed by wm4
parent 02e6cf7a0a
commit ef463aa103

View File

@ -138,12 +138,42 @@ static void parse_vdr_par_string(const char* vdr_par_str, dvb_channel_t* ptr) {
} }
} }
static char* dvb_strtok_r(char* s, const char* sep, char** p) {
if (!s && !(s = *p)) {
return NULL;
}
/* Skip leading separators. */
s += strspn(s, sep);
/* s points at first non-separator, or end of string. */
if (!*s) {
return (*p = 0);
}
/* Move *p to next separator. */
*p = s + strcspn(s, sep);
if (**p) {
*(*p)++ = 0;
} else {
*p = 0;
}
return s;
}
static bool parse_pid_string(struct mp_log *log, char* pid_string, dvb_channel_t* ptr) { static bool parse_pid_string(struct mp_log *log, char* pid_string, dvb_channel_t* ptr) {
if (pid_string[0]) { if (pid_string[0]) {
int pcnt = 0; int pcnt = 0;
const char* tokens = "+"; /** These tokens also catch vdr-style PID lists.
* They can contain 123=deu@3,124=eng+jap@4;125
* 3 and 4 are codes for codec type, =langLeft+langRight is allowed,
* and ; may separate a dolby channel.
* With the numChars-test and the full token-list, all is handled gracefully.
*/
const char* tokens = "+,;";
char* pidPart; char* pidPart;
pidPart = strtok(pid_string, tokens); char* savePtr;
pidPart = dvb_strtok_r(pid_string, tokens, &savePtr);
while (pidPart != NULL) { while (pidPart != NULL) {
if (ptr->pids_cnt >= DMX_FILTER_SIZE-1) { if (ptr->pids_cnt >= DMX_FILTER_SIZE-1) {
mp_verbose(log, "Maximum number of PIDs for one channel reached, ignoring further ones!\n"); mp_verbose(log, "Maximum number of PIDs for one channel reached, ignoring further ones!\n");
@ -156,7 +186,7 @@ static bool parse_pid_string(struct mp_log *log, char* pid_string, dvb_channel_t
ptr->pids[ptr->pids_cnt] = pid; ptr->pids[ptr->pids_cnt] = pid;
ptr->pids_cnt++; ptr->pids_cnt++;
} }
pidPart = strtok(NULL, tokens); pidPart = dvb_strtok_r(NULL, tokens, &savePtr);
} }
if (pcnt > 0) { if (pcnt > 0) {
return true; return true;