summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-12-28 20:03:18 +0100
committerwm4 <wm4@nowhere>2014-12-28 20:04:25 +0100
commit1a6dc9ae44cd7ddd9ee12578b5167d689a810ef7 (patch)
treef5c8421dc8dd2f617fcd73a11d68336f9fba2b23
parentf987625d5a84546b564bd15635c4051af5dc7113 (diff)
downloadmpv-1a6dc9ae44cd7ddd9ee12578b5167d689a810ef7.tar.bz2
mpv-1a6dc9ae44cd7ddd9ee12578b5167d689a810ef7.tar.xz
stream_pvr: sort channel list by --tv-channels order
Apparently this is what users would expect. Going the way of least resistance (in terms of messing with this old, rarely used code), sorting them by some kind of addition timestamp (called priority in the patch) is the easiest. Fixes #1390.
-rw-r--r--stream/stream_pvr.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/stream/stream_pvr.c b/stream/stream_pvr.c
index 225ba084dc..829151ba28 100644
--- a/stream/stream_pvr.c
+++ b/stream/stream_pvr.c
@@ -113,6 +113,7 @@ typedef struct station_elem_s {
int freq;
char station[PVR_STATION_NAME_SIZE];
int enabled;
+ int priority;
} station_elem_t;
typedef struct stationlist_s {
@@ -307,7 +308,7 @@ disable_all_stations (struct pvr_t *pvr)
*/
static int
set_station (struct pvr_t *pvr, const char *station,
- const char *channel, int freq)
+ const char *channel, int freq, int priority)
{
int i;
@@ -347,6 +348,8 @@ set_station (struct pvr_t *pvr, const char *station,
else
BUFPRINTF(pvr->stationlist.list[i].station, "F %d", freq);
+ pvr->stationlist.list[i].priority = priority;
+
MP_DBG(pvr, "Set user station channel: %8s - freq: %8d - station: %s\n",
pvr->stationlist.list[i].name,
pvr->stationlist.list[i].freq,
@@ -387,6 +390,7 @@ set_station (struct pvr_t *pvr, const char *station,
/* here we go, our actual new entry */
pvr->stationlist.used++;
pvr->stationlist.list[i].enabled = 1;
+ pvr->stationlist.list[i].priority = priority;
pvr->stationlist.enabled++;
if (station)
@@ -406,6 +410,18 @@ set_station (struct pvr_t *pvr, const char *station,
return 0;
}
+static int compare_priority(const void *pa, const void *pb)
+{
+ const station_elem_t *a = pa;
+ const station_elem_t *b = pb;
+
+ if (a->priority < b->priority)
+ return -1;
+ if (a->priority > b->priority)
+ return 1;
+ return 0;
+}
+
/**
* Here we set our stationlist, as follow
* - choose the frequency channel table, e.g. ntsc-cable
@@ -468,6 +484,10 @@ parse_setup_stationlist (struct pvr_t *pvr)
disable_all_stations (pvr);
+ int prio = 0;
+ for (i = 0; i < pvr->stationlist.total; i++)
+ pvr->stationlist.list[i].priority = ++prio;
+
while (*channels)
{
char *tmp = *(channels++);
@@ -492,12 +512,15 @@ parse_setup_stationlist (struct pvr_t *pvr)
if ((freq = atoi (channel)) <= 1000)
freq = -1;
- if (set_station (pvr, station, (freq <= 0) ? channel : NULL, freq) < 0)
+ if (set_station (pvr, station, (freq <= 0) ? channel : NULL, freq, ++prio) < 0)
{
MP_ERR(pvr, "Unable to set user station channel: %8s - freq: %8d - station: %s\n",
channel, freq, station);
}
}
+
+ qsort(pvr->stationlist.list, pvr->stationlist.total,
+ sizeof(station_elem_t), compare_priority);
}
return print_all_stations (pvr);