[Slim-Checkins] r10276 - in /trunk/server: Slim/Player/Source.pm Slim/Player/Squeezebox.pm strings.txt

andy at svn.slimdevices.com andy at svn.slimdevices.com
Tue Oct 10 14:08:09 PDT 2006


Author: andy
Date: Tue Oct 10 14:08:07 2006
New Revision: 10276

URL: http://svn.slimdevices.com?rev=10276&view=rev
Log:
Stream rebuffering: If a stream drops to 1% buffer fullness, pause and wait for the stream to rebuffer instead of letting the audio stutter

Modified:
    trunk/server/Slim/Player/Source.pm
    trunk/server/Slim/Player/Squeezebox.pm
    trunk/server/strings.txt

Modified: trunk/server/Slim/Player/Source.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Player/Source.pm?rev=10276&r1=10275&r2=10276&view=diff
==============================================================================
--- trunk/server/Slim/Player/Source.pm (original)
+++ trunk/server/Slim/Player/Source.pm Tue Oct 10 14:08:07 2006
@@ -47,6 +47,7 @@
 	Slim::Networking::Slimproto::setEventCallback('STMu', \&underrun);
 	Slim::Networking::Slimproto::setEventCallback('STMd', \&decoderUnderrun);
 	Slim::Networking::Slimproto::setEventCallback('STMs', \&trackStartEvent);
+	Slim::Networking::Slimproto::setEventCallback('STMt', \&checkFullness);
 	Slim::Networking::Slimproto::setEventCallback('STMn', \&notSupported);
 }
 
@@ -609,6 +610,30 @@
 		$client->update();
 		
 		Slim::Control::Request::notifyFromArray($client, ['stop']);
+	}
+}
+
+sub checkFullness {
+	my $client = shift || return;
+	
+	# If a stream falls to below 1% buffer fullness and we 
+	# have played at least 10 seconds, rebuffer the stream
+	my $fullness = int( Slim::Networking::Slimproto::fullness($client) / $client->bufferSize() * 100);
+	
+	my $songTime = songTime($client);
+	
+	if ( $fullness <= 1 && $songTime > 10 ) {
+		$::d_source && msg("Buffer fullness dropped to $fullness%, pausing to rebuffer\n");
+		
+		$client->pause();
+		
+		# Use the quickstart timer to wait until we've rebuffered enough
+		Slim::Utils::Timers::setTimer( 
+			$client, 
+			Time::HiRes::time() + 0.125, 
+			\&Slim::Player::Squeezebox::quickstart, 
+			5, # signals quickstart what percentage to rebuffer to
+		);
 	}
 }
 

Modified: trunk/server/Slim/Player/Squeezebox.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Player/Squeezebox.pm?rev=10276&r1=10275&r2=10276&view=diff
==============================================================================
--- trunk/server/Slim/Player/Squeezebox.pm (original)
+++ trunk/server/Slim/Player/Squeezebox.pm Tue Oct 10 14:08:07 2006
@@ -222,7 +222,8 @@
 }
 
 sub quickstart {
-	my $client = shift;
+	my $client   = shift;
+	my $rebuffer = shift || 0; # Are we rebuffering an existing stream?
 	
 	my $url = Slim::Player::Playlist::url( $client, Slim::Player::Source::streamingSongIndex($client) );
 	
@@ -237,6 +238,15 @@
 	if ( my $bitrate = Slim::Music::Info::getBitrate($url) ) {
 		my $bufferSecs = Slim::Utils::Prefs::get('bufferSecs') || 3;
 		$threshold     = int($bitrate / 8) * $bufferSecs;
+	}
+	
+	if ( $rebuffer ) {
+		# Change the threshold to a precentage of buffer size
+		$threshold = int( $client->bufferSize() * ( $rebuffer / 100 ) );
+		$::d_source && msg("Quickstart: Rebuffering to $rebuffer%... $fullness / $threshold\n");
+	}
+	else {	
+		$::d_source && msg("Quickstart: Buffering... $fullness / $threshold\n");
 	}
 
 	# Resume if we've hit the threshold, unless synced (sync unpauses all clients together)
@@ -265,7 +275,8 @@
 				$status = $client->string('WAITING_TO_SYNC');
 			}
 			else {
-				$status = $client->string('BUFFERING') . ' ' . $percent . '%';
+				my $string = $rebuffer ? 'REBUFFERING' : 'BUFFERING';
+				$status = $client->string($string) . ' ' . $percent . '%';
 			}
 			
 			$line1 = $client->string('NOW_PLAYING') . ' (' . $status . ')';
@@ -289,7 +300,7 @@
 			$client->showBriefly( $line1, $line2, 0.5 ) unless $client->display->sbName();
 		}
 		
-		Slim::Utils::Timers::setTimer( $client, Time::HiRes::time() + 0.125, \&quickstart );
+		Slim::Utils::Timers::setTimer( $client, Time::HiRes::time() + 0.125, \&quickstart, $rebuffer );
 	}
 }
 

Modified: trunk/server/strings.txt
URL: http://svn.slimdevices.com/trunk/server/strings.txt?rev=10276&r1=10275&r2=10276&view=diff
==============================================================================
--- trunk/server/strings.txt (original)
+++ trunk/server/strings.txt Tue Oct 10 14:08:07 2006
@@ -1546,6 +1546,9 @@
 	ES	Llenando el buffer...
 	NL	Bufferen
 	ZH_CN	缓冲è£
载中
+
+REBUFFERING
+	EN	Rebuffering...
 
 WAITING_TO_SYNC
 	DE	Warte auf Synchronisierung...



More information about the checkins mailing list