summaryrefslogtreecommitdiffstats
path: root/stream/stream_dvb.c
diff options
context:
space:
mode:
authorOliver Freyermuth <o.freyermuth@googlemail.com>2014-12-31 03:27:33 +0100
committerwm4 <wm4@nowhere>2015-01-06 19:52:27 +0100
commitef463aa1038eec1bf01216f87b1681fdf4973793 (patch)
treee9732771e196e591fce644245ca36b575d1d6444 /stream/stream_dvb.c
parent02e6cf7a0af01acb2321514a8a19b37d93298b55 (diff)
downloadmpv-ef463aa1038eec1bf01216f87b1681fdf4973793.tar.bz2
mpv-ef463aa1038eec1bf01216f87b1681fdf4973793.tar.xz
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).
Diffstat (limited to 'stream/stream_dvb.c')
-rw-r--r--stream/stream_dvb.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/stream/stream_dvb.c b/stream/stream_dvb.c
index 13356c5cf2..7ebcd8fc1b 100644
--- a/stream/stream_dvb.c
+++ b/stream/stream_dvb.c
@@ -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) {
if (pid_string[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;
- pidPart = strtok(pid_string, tokens);
+ char* savePtr;
+ pidPart = dvb_strtok_r(pid_string, tokens, &savePtr);
while (pidPart != NULL) {
if (ptr->pids_cnt >= DMX_FILTER_SIZE-1) {
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_cnt++;
}
- pidPart = strtok(NULL, tokens);
+ pidPart = dvb_strtok_r(NULL, tokens, &savePtr);
}
if (pcnt > 0) {
return true;