changeset 34901:b2d8b97bf74c

Reduce some code duplication.
author reimar
date Sat, 09 Jun 2012 11:11:57 +0000
parents 9eb6592d9c3f
children 528cbb0076d0
files stream/tv.c
diffstat 1 files changed, 14 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/stream/tv.c	Sat Jun 09 06:46:00 2012 +0000
+++ b/stream/tv.c	Sat Jun 09 11:11:57 2012 +0000
@@ -403,6 +403,15 @@
    return 1;
 }
 
+static void set_norm_and_freq(tvi_handle_t *tvh, tv_channels_t *chan)
+{
+    float freq = (float)chan->freq/1000;
+    mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3, chan->number,
+           chan->name, freq);
+    tv_set_norm_i(tvh, chan->norm);
+    tv_set_freq(tvh, (unsigned long)(freq*16));
+}
+
 static int open_tv(tvi_handle_t *tvh)
 {
     int i;
@@ -589,10 +598,7 @@
 			tv_channel_current = tv_channel_current->next;
 	}
 
-	mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3, tv_channel_current->number,
-			tv_channel_current->name, (float)tv_channel_current->freq/1000);
-	tv_set_norm_i(tvh, tv_channel_current->norm);
-	tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
+	set_norm_and_freq(tvh, tv_channel_current);
 	tv_channel_last = tv_channel_current;
     } else {
     /* we need to set frequency */
@@ -1020,11 +1026,7 @@
 				tv_channel_current = tv_channel_current->next;
 			else
 				tv_channel_current = tv_channel_list;
-
-				tv_set_norm_i(tvh, tv_channel_current->norm);
-				tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
-				mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3,
-			tv_channel_current->number, tv_channel_current->name, (float)tv_channel_current->freq/1000);
+			set_norm_and_freq(tvh, tv_channel_current);
 		}
 		if (direction == TV_CHANNEL_LOWER) {
 			tv_channel_last = tv_channel_current;
@@ -1033,10 +1035,7 @@
 			else
 				while (tv_channel_current->next)
 					tv_channel_current = tv_channel_current->next;
-				tv_set_norm_i(tvh, tv_channel_current->norm);
-				tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
-				mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3,
-			tv_channel_current->number, tv_channel_current->name, (float)tv_channel_current->freq/1000);
+			set_norm_and_freq(tvh, tv_channel_current);
 		}
 	} else tv_step_channel_real(tvh, direction);
 	return 1;
@@ -1076,10 +1075,7 @@
 		for (i = 1; i < channel_int; i++)
 			if (tv_channel_current->next)
 				tv_channel_current = tv_channel_current->next;
-		mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3, tv_channel_current->number,
-				tv_channel_current->name, (float)tv_channel_current->freq/1000);
-		tv_set_norm_i(tvh, tv_channel_current->norm);
-		tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
+		set_norm_and_freq(tvh, tv_channel_current);
 	} else tv_set_channel_real(tvh, channel);
 	return 1;
 }
@@ -1094,10 +1090,7 @@
 		tv_channel_last = tv_channel_current;
 		tv_channel_current = tmp;
 
-		mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3, tv_channel_current->number,
-				tv_channel_current->name, (float)tv_channel_current->freq/1000);
-		tv_set_norm_i(tvh, tv_channel_current->norm);
-		tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
+		set_norm_and_freq(tvh, tv_channel_current);
 	} else {
 		int i;
 		struct CHANLIST cl;