Skip to content

Commit

Permalink
Allow customization of buffer size
Browse files Browse the repository at this point in the history
This allows for faster channel changes, assuming your wifi
is up to it.
  • Loading branch information
kiall committed Apr 7, 2017
1 parent c8df72c commit 5b26177
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/java/ie/macinnes/tvheadend/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Constants {
public static final String KEY_HTSP_STREAM_PROFILE = "htsp_stream_profile";

// Audio and Video Preferences Keys and Values
public static final String KEY_BUFFER_PLAYBACK_MS = "buffer_playback_ms";
public static final String KEY_AUDIO_PASSTHROUGH_DECODER_ENABLED = "audio_passthrough_decodeder_enabled";
public static final String KEY_FFMPEG_AUDIO_ENABLED = "ffmpeg_audio_enabled";
public static final String KEY_CAPTIONS_APPLY_EMBEDDED_STYLES = "captions_apply_embedded_styles";
Expand Down
28 changes: 27 additions & 1 deletion app/src/main/java/ie/macinnes/tvheadend/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.ui.SubtitleView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultAllocator;
import com.google.android.exoplayer2.util.MimeTypes;

import java.util.ArrayList;
Expand Down Expand Up @@ -198,7 +199,7 @@ private void buildExoPlayer() {

mTrackSelector = new TvheadendTrackSelector(trackSelectionFactory);

LoadControl loadControl = new DefaultLoadControl();
LoadControl loadControl = buildLoadControl();

int extensionRendererMode = SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER;

Expand Down Expand Up @@ -229,6 +230,31 @@ private void buildExoPlayer() {
mExtractorsFactory = new HtspExtractor.Factory(mContext);
}

private LoadControl buildLoadControl() {
SharedPreferences sharedPreferences = mContext.getSharedPreferences(
Constants.PREFERENCE_TVHEADEND, Context.MODE_PRIVATE);

TrackSelection.Factory trackSelectionFactory =
new AdaptiveTrackSelection.Factory(null);

mTrackSelector = new TvheadendTrackSelector(trackSelectionFactory);

int bufferForPlaybackMs = Integer.parseInt(
sharedPreferences.getString(
Constants.KEY_BUFFER_PLAYBACK_MS,
mContext.getResources().getString(R.string.pref_default_buffer_playback_ms)
)
);

return new DefaultLoadControl(
new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE),
DefaultLoadControl.DEFAULT_MIN_BUFFER_MS,
DefaultLoadControl.DEFAULT_MAX_BUFFER_MS,
bufferForPlaybackMs,
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS
);
}

private void buildHtspMediaSource(Uri channelUri) {
// This is the MediaSource representing the media to be played.
mMediaSource = new ExtractorMediaSource(channelUri,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<dimen name="subtitle_minimum_font_size">13sp</dimen>

<!-- Default Preference values -->
<string name="pref_default_buffer_playback_ms">500</string>
<bool name="pref_default_audio_passthrough_decodeder_enabled">false</bool>
<bool name="pref_default_audio_ffmpeg_audio_enabled">true</bool>
<bool name="pref_default_shield_workaround_enabled">true</bool>
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/res/values/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,28 @@
<item>604800</item>
<item>691200</item>
</string-array>

<string-array name="buffer_playback_ms_names">
<item>No Buffer</item>
<item>0.5 Seconds</item>
<item>1 Second</item>
<item>1.5 Seconds</item>
<item>2 Seconds</item>
<item>2.5 Seconds</item>
<item>3 Seconds</item>
<item>4 Seconds</item>
<item>5 Seconds</item>
</string-array>

<string-array name="buffer_playback_ms_values">
<item>0</item>
<item>500</item>
<item>1000</item>
<item>1500</item>
<item>2000</item>
<item>2500</item>
<item>3000</item>
<item>4000</item>
<item>5000</item>
</string-array>
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
android:title="TVHeadend Settings">

<PreferenceCategory android:title="Audio and Video">
<ListPreference
android:key="buffer_playback_ms"
android:title="Buffer Duration"
android:dialogTitle="Buffer Seconds"
android:entries="@array/buffer_playback_ms_names"
android:entryValues="@array/buffer_playback_ms_values"
android:defaultValue="@string/pref_default_buffer_playback_ms"
android:summary="How many seconds to buffer before starting playback"/>

<CheckBoxPreference
android:key="audio_passthrough_decodeder_enabled"
android:title="Enable Audio Passthrough"
Expand Down

0 comments on commit 5b26177

Please sign in to comment.