summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-12-28 20:03:18 +0100
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-01-25 17:00:15 +0900
commita2f4391ca15b257411d3e92b65c6197975d47b04 (patch)
tree86efa59590d24edf89ac39dfd94628fc00a66b70
parent4971ad9e17b7c37ce74628e4f765a0d858b48633 (diff)
downloadmpv-a2f4391ca15b257411d3e92b65c6197975d47b04.tar.bz2
mpv-a2f4391ca15b257411d3e92b65c6197975d47b04.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. Conflicts: stream/stream_pvr.c
-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 7acac4a6f5..d55c419b67 100644
--- a/stream/stream_pvr.c
+++ b/stream/stream_pvr.c
@@ -118,6 +118,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 {
@@ -313,7 +314,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;
@@ -353,6 +354,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, "%s Set user station channel: %8s - freq: %8d - station: %s\n",
LOG_LEVEL_V4L2, pvr->stationlist.list[i].name,
pvr->stationlist.list[i].freq,
@@ -395,6 +398,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)
@@ -414,6 +418,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
@@ -477,6 +493,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++);
@@ -501,12 +521,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, "%s Unable to set user station channel: %8s - freq: %8d - station: %s\n", LOG_LEVEL_V4L2,
channel, freq, station);
}
}
+
+ qsort(pvr->stationlist.list, pvr->stationlist.total,
+ sizeof(station_elem_t), compare_priority);
}
return print_all_stations (pvr);