Skip to content

Commit

Permalink
WIP: Add DVBSUB Support
Browse files Browse the repository at this point in the history
This is based on an open pull request to ExoPlayer, and can't be merged
before ExoPlayer merges and ships a release. Also, it doesn't - ya know
- actually work yet :)

Fixes #101
  • Loading branch information
kiall committed Mar 16, 2017
1 parent c429b11 commit 0e5d986
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ dependencies {
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:leanback-v17:25.2.0'
compile 'com.android.support:preference-leanback-v17:25.2.0'
compile 'com.google.android.exoplayer:exoplayer:r2.2.0k1'
compile 'com.google.android.exoplayer:extension-ffmpeg:r2.2.0k1'
// compile 'com.google.android.exoplayer:exoplayer:r2.2.0k1'
// compile 'com.google.android.exoplayer:extension-ffmpeg:r2.2.0k1'
// Used for testing local exoplayer builds
// compile(name: 'library-release', ext: 'aar')
compile(name: 'library-debug', ext: 'aar')
// Used for testing local exoplayer-ffmpeg builds
// compile(name: 'extension-ffmpeg-release', ext: 'aar')
compile(name: 'extension-ffmpeg-debug', ext: 'aar')
compile 'ch.acra:acra:4.9.2'

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static TvTrackInfo buildTvTrackInfo(Format format) {
break;

default:
Log.w(TAG, "Unsupported track type: " + format.sampleMimeType + " / " + trackName);
Log.w(TAG, "Unsupported track type: " + format.sampleMimeType + " / " + trackName + " / " + trackType);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.audio.AudioCapabilities;
import com.google.android.exoplayer2.audio.AudioProcessor;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer;
import com.google.android.exoplayer2.drm.DrmSessionManager;
Expand Down Expand Up @@ -54,7 +55,7 @@ public SimpleTvheadendPlayer(Context context, TrackSelector trackSelector, LoadC

@Override
protected void buildAudioRenderers(Context context, Handler mainHandler, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
int extensionRendererMode, AudioRendererEventListener eventListener, ArrayList<Renderer> out) {
int extensionRendererMode, AudioRendererEventListener eventListener, AudioProcessor[] audioProcessors, ArrayList<Renderer> out) {
AudioCapabilities audioCapabilities = AudioCapabilities.getCapabilities(context);

SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.PREFERENCE_TVHEADEND, Context.MODE_PRIVATE);
Expand All @@ -66,7 +67,7 @@ protected void buildAudioRenderers(Context context, Handler mainHandler, DrmSess
// FFMpeg Audio Decoder
if (sharedPreferences.getBoolean(Constants.KEY_FFMPEG_AUDIO_ENABLED, true)) {
Log.d(TAG, "Adding FfmpegAudioRenderer");
out.add(new FfmpegAudioRenderer(mainHandler, eventListener, audioCapabilities));
out.add(new FfmpegAudioRenderer(mainHandler, eventListener, audioProcessors));
}

// Native Audio Decoders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,24 @@ protected TrackSelection[] selectTracks(RendererCapabilities[] rendererCapabilit
return trackSelections;
}

protected TrackSelection selectVideoTrack(
RendererCapabilities rendererCapabilities, TrackGroupArray groups, int[][] formatSupport,
int maxVideoWidth, int maxVideoHeight, boolean allowNonSeamlessAdaptiveness,
boolean allowMixedMimeAdaptiveness, int viewportWidth, int viewportHeight,
boolean orientationMayChange, TrackSelection.Factory adaptiveVideoTrackSelectionFactory,
boolean exceedConstraintsIfNecessary, boolean exceedRendererCapabilitiesIfNecessary)
@Override
protected TrackSelection selectVideoTrack(RendererCapabilities rendererCapabilities, TrackGroupArray groups,
int[][] formatSupport, int maxVideoWidth, int maxVideoHeight,
int maxVideoBitrate, boolean allowNonSeamlessAdaptiveness,
boolean allowMixedMimeAdaptiveness, int viewportWidth,
int viewportHeight, boolean orientationMayChange,
TrackSelection.Factory adaptiveVideoTrackSelectionFactory,
boolean exceedConstraintsIfNecessary,
boolean exceedRendererCapabilitiesIfNecessary)
throws ExoPlaybackException {
Log.d(TAG, "TrackSelector selectVideoTrack");

// If we haven't explicitly chosen a track, defer to the DefaultTrackSelector implementation.
if (mVideoTrackId == null) {
return super.selectVideoTrack(rendererCapabilities, groups, formatSupport, maxVideoWidth, maxVideoHeight,
allowNonSeamlessAdaptiveness, allowMixedMimeAdaptiveness, viewportWidth, viewportHeight,
orientationMayChange, adaptiveVideoTrackSelectionFactory, exceedConstraintsIfNecessary,
exceedRendererCapabilitiesIfNecessary);
maxVideoBitrate, allowNonSeamlessAdaptiveness, allowMixedMimeAdaptiveness, viewportWidth,
viewportHeight, orientationMayChange, adaptiveVideoTrackSelectionFactory,
exceedConstraintsIfNecessary, exceedRendererCapabilitiesIfNecessary);
} else {
for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
TrackGroup trackGroup = groups.get(groupIndex);
Expand All @@ -136,6 +139,7 @@ protected TrackSelection selectVideoTrack(
}
}

@Override
protected TrackSelection selectAudioTrack(
TrackGroupArray groups, int[][] formatSupport, String preferredAudioLanguage,
boolean exceedRendererCapabilitiesIfNecessary) {
Expand Down Expand Up @@ -165,6 +169,7 @@ protected TrackSelection selectAudioTrack(
}
}

@Override
protected TrackSelection selectTextTrack(
TrackGroupArray groups, int[][] formatSupport, String preferredTextLanguage,
String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream) {
stream.getString("language", "und")
);
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_AUDIO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream) {
stream.getString("language", "und")
);
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_AUDIO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2017 Kiall Mac Innes <kiall@macinnes.ie>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ie.macinnes.tvheadend.player.reader;

import android.content.Context;
import android.support.annotation.NonNull;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MimeTypes;

import ie.macinnes.htsp.HtspMessage;

public class DvbsubStreamReader extends PlainStreamReader {

public DvbsubStreamReader(Context context) {
super(context);
}

@NonNull
@Override
protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream) {
return Format.createImageSampleFormat(
Integer.toString(streamIndex),
MimeTypes.APPLICATION_DVBSUBS,
null,
Format.NO_VALUE,
null,
stream.getString("language", "und"),
null);
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_TEXT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream) {
stream.getString("language", "und")
);
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_AUDIO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.support.annotation.NonNull;
import android.util.Log;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.util.MimeTypes;
Expand Down Expand Up @@ -63,4 +64,10 @@ protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream) {
initializationData,
null);
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_VIDEO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.support.annotation.NonNull;
import android.util.Log;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.util.MimeTypes;
Expand Down Expand Up @@ -63,4 +64,10 @@ protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream) {
initializationData,
null);
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_VIDEO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream) {
stream.getString("language", "und")
);
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_AUDIO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Context;
import android.support.annotation.NonNull;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MimeTypes;

Expand All @@ -45,4 +46,10 @@ protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream) {
null,
null);
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_VIDEO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public PlainStreamReader(Context context) {
@Override
public final void createTracks(@NonNull HtspMessage stream, @NonNull ExtractorOutput output) {
final int streamIndex = stream.getInteger("index");
mTrackOutput = output.track(streamIndex);

mTrackOutput = output.track(streamIndex, getTrackType());
mTrackOutput.format(buildFormat(streamIndex, stream));
}

Expand All @@ -67,4 +68,7 @@ public void release() {

@NonNull
abstract protected Format buildFormat(int streamIndex, @NonNull HtspMessage stream);

@NonNull
abstract protected int getTrackType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public StreamReader createStreamReader(String streamType) {
// Text Stream Types
case "TEXTSUB":
return new TextsubStreamReader(mContext);
case "DVBSUB":
return new DvbsubStreamReader(mContext);
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public TextsubStreamReader(Context context) {
@Override
public final void createTracks(@NonNull HtspMessage stream, @NonNull ExtractorOutput output) {
final int streamIndex = stream.getInteger("index");
mTrackOutput = output.track(streamIndex);
mTrackOutput = output.track(streamIndex, getTrackType());
mTrackOutput.format(buildFormat(streamIndex, stream));
}

Expand Down Expand Up @@ -138,4 +138,9 @@ private static void setSubripSampleEndTimecode(byte[] subripSample, long timeUs)
System.arraycopy(timeCodeData, 0, subripSample, SUBRIP_PREFIX_END_TIMECODE_OFFSET,
SUBRIP_TIMECODE_LENGTH);
}

@NonNull
protected int getTrackType() {
return C.TRACK_TYPE_TEXT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@ private static List<byte[]> parseVorbisCodecPrivate(byte[] codecPrivate)
}
}

@NonNull
@Override
protected int getTrackType() {
return C.TRACK_TYPE_AUDIO;
}
}

0 comments on commit 0e5d986

Please sign in to comment.