Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KUX-1761: Upgrade exoplayer to Media 3 #816

Merged
merged 13 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- name: Checkout repo and clone to CI workspace
uses: actions/checkout@v3

- name: Setup JDK 11
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'adopt'
cache: 'gradle'

Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ jobs:
mkdir $PWD/.kltrenv && echo "${{ secrets.SIGNING_KEY }}" > $PWD/.kltrenv/secring.gpg.b64
base64 -d $PWD/.kltrenv/secring.gpg.b64 > $PWD/.kltrenv/secring.gpg

- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: 'gradle'

- name: Run publish Script
run: |
RELEASE_TYPE=${RELEASE_TYPE} NEW_VERSION=${NEW_VERSION}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ ext["signingKeyId"] = System.getenv('SIGNING_KEYID')
ext["signingPassword"] = System.getenv('SIGNING_PASSWORD')

buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.8.0'
repositories {
google()
mavenCentral()
maven { url "https://maven.google.com" }
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.android.tools.build:gradle:8.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 01 20:52:25 IDT 2020
#Thu Jul 11 16:22:33 IDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jdk:
- openjdk11
- openjdk17
before_install:
- curl https://kaltura.github.io/fe-tools/android/license.sh | sh
28 changes: 19 additions & 9 deletions playkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ apply plugin: 'kotlin-android'
apply from: 'version.gradle'

android {
compileSdkVersion 33
namespace 'com.kaltura.playkit'
compileSdk 34
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 33
minSdkVersion 21
targetSdkVersion 34
versionName playkitVersion // defined in version.gradle
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String","VERSION_NAME","\"${playkitVersion}\"")
Expand All @@ -28,10 +29,19 @@ android {

lintOptions {
lintConfig file("lint.xml")
disable 'UnsafeOptInUsageError'
}
buildFeatures {
buildConfig = true
}
publishing {
publishing {
singleVariant('release') {
}
}
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
}

Expand All @@ -41,8 +51,8 @@ tasks.withType(Javadoc) {

dependencies {

def exoPlayerVersion = '2.18.4'
api "com.kaltura.playkit:kexoplayer:$exoPlayerVersion"
def media3ExoPlayerVersion = '1.4.1'
api "com.kaltura.playkit:mediakexoplayer:$media3ExoPlayerVersion"

api 'com.google.code.gson:gson:2.8.6'
implementation 'androidx.annotation:annotation:1.2.0'
Expand Down
4 changes: 2 additions & 2 deletions playkit/gradle-mvn-local.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'maven-publish'

task androidSourcesJar(type: Jar) {
classifier 'sources'
archiveClassifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}

project.afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
from components.release
from components.findByName('release')
}
}
repositories {
Expand Down
6 changes: 3 additions & 3 deletions playkit/gradle-mvn-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ afterEvaluate { project ->
publishing {
publications {
mavenJava(MavenPublication) {
from components.release
from components.findByName('release')
groupId = GROUP
artifactId = POM_ARTIFACT_ID

Expand Down Expand Up @@ -98,12 +98,12 @@ afterEvaluate { project ->
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier 'javadoc'
archiveClassifier = 'javadoc'
from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier 'sources'
archiveClassifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}

Expand Down
3 changes: 1 addition & 2 deletions playkit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest package="com.kaltura.playkit"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.kaltura.android.exoplayer2.upstream;

import com.kaltura.androidx.media3.exoplayer.upstream.BandwidthMeter;

public interface KBandwidthMeter extends BandwidthMeter {
void resetBitrateEstimate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import androidx.annotation.Nullable;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.kaltura.android.exoplayer2.util.Clock;
import com.kaltura.androidx.media3.common.util.Clock;
import com.kaltura.androidx.media3.datasource.DataSource;
import com.kaltura.androidx.media3.datasource.DataSpec;
import com.kaltura.androidx.media3.datasource.TransferListener;
import com.kaltura.androidx.media3.exoplayer.upstream.DefaultBandwidthMeter;


public class KDefaultBandwidthMeter implements KBandwidthMeter, TransferListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kaltura.android.exoplayer2.audio;
package com.kaltura.androidx.media3.exoplayer.audio;

import static com.kaltura.android.exoplayer2.audio.DefaultAudioSink.DEFAULT_PLAYBACK_SPEED;
import static com.kaltura.androidx.media3.exoplayer.audio.DefaultAudioSink.DEFAULT_PLAYBACK_SPEED;
import static java.lang.Math.max;
import static java.lang.Math.min;

Expand All @@ -10,12 +10,12 @@

import androidx.annotation.Nullable;

import com.kaltura.android.exoplayer2.ExoPlaybackException;
import com.kaltura.android.exoplayer2.Format;
import com.kaltura.android.exoplayer2.PlaybackParameters;
import com.kaltura.android.exoplayer2.decoder.DecoderInputBuffer;
import com.kaltura.android.exoplayer2.mediacodec.MediaCodecAdapter;
import com.kaltura.android.exoplayer2.mediacodec.MediaCodecSelector;
import com.kaltura.androidx.media3.exoplayer.ExoPlaybackException;
import com.kaltura.androidx.media3.common.Format;
import com.kaltura.androidx.media3.common.PlaybackParameters;
import com.kaltura.androidx.media3.decoder.DecoderInputBuffer;
import com.kaltura.androidx.media3.exoplayer.mediacodec.MediaCodecAdapter;
import com.kaltura.androidx.media3.exoplayer.mediacodec.MediaCodecSelector;
import com.kaltura.playkit.PKLog;

import java.lang.reflect.Field;
Expand All @@ -24,14 +24,8 @@

public class KMediaCodecAudioRenderer extends MediaCodecAudioRenderer {

private static final String ALLOW_FIRST_BUFFER_POSITION_DISCONTINUITY_FIELD_NAME = "allowFirstBufferPositionDiscontinuity";

private static final String CURRENT_POSITION_US_FIELD_NAME = "currentPositionUs";

private static final String DECRYPT_ONLY_CODEC_FORMAT_FIELD_NAME = "decryptOnlyCodecFormat";

private static final long DEFAULT_MAX_AUDIO_GAP_THRESHOLD = 3_000_000L;

private static final boolean DEFAULT_USE_CONTINUOUS_SPEED_ADJUSTMENT = false;

private static final float DEFAULT_MAX_SPEED_FACTOR = 4.0f;
Expand All @@ -40,8 +34,6 @@ public class KMediaCodecAudioRenderer extends MediaCodecAudioRenderer {

private static final long DEFAULT_MAX_AV_GAP = 600_000L;

private final long maxAudioGapThreshold;

private final boolean useContinuousSpeedAdjustment;

private final float maxSpeedFactor;
Expand All @@ -68,7 +60,6 @@ public KMediaCodecAudioRenderer(Context context,
eventHandler,
eventListener,
audioSink,
DEFAULT_MAX_AUDIO_GAP_THRESHOLD,
DEFAULT_MAX_SPEED_FACTOR,
DEFAULT_SPEED_STEP,
DEFAULT_MAX_AV_GAP,
Expand All @@ -82,13 +73,11 @@ public KMediaCodecAudioRenderer(Context context,
@Nullable Handler eventHandler,
@Nullable AudioRendererEventListener eventListener,
AudioSink audioSink,
long maxAudioGapThreshold,
float maxSpeedFactor,
float speedStep,
long maxAVGap,
boolean useContinuousSpeedAdjustment) {
super(context, codecAdapterFactory, mediaCodecSelector, enableDecoderFallback, eventHandler, eventListener, audioSink);
this.maxAudioGapThreshold = maxAudioGapThreshold;
this.maxSpeedFactor = maxSpeedFactor;
this.speedStep = speedStep;
this.maxAVGap = maxAVGap;
Expand All @@ -99,10 +88,6 @@ public KMediaCodecAudioRenderer(Context context,
", continuousSpeedAdjustment=" + getContinuousSpeedAdjustment());
}

protected long getMaxAudioGapThreshold() {
return maxAudioGapThreshold;
}

protected float getMaxSpeedFactor() {
return maxSpeedFactor;
}
Expand All @@ -125,32 +110,6 @@ protected void onPositionReset(long positionUs, boolean joining) throws ExoPlayb
speedAdjustedAfterPositionReset = false;
}

@Override
protected void onQueueInputBuffer(DecoderInputBuffer buffer) {
try {
Field allowFirstBufferPositionDiscontinuityField = Objects.requireNonNull(
getClass().getSuperclass())
.getDeclaredField(ALLOW_FIRST_BUFFER_POSITION_DISCONTINUITY_FIELD_NAME);
allowFirstBufferPositionDiscontinuityField.setAccessible(true);
Field currentPositionUsField = Objects.requireNonNull(
getClass().getSuperclass())
.getDeclaredField(CURRENT_POSITION_US_FIELD_NAME);
currentPositionUsField.setAccessible(true);
if (allowFirstBufferPositionDiscontinuityField.getBoolean(this) && !buffer.isDecodeOnly()) {
log.d("KMediaCodecAudioRenderer", "A/V start buffers gap measured: "
+ Math.abs(buffer.timeUs - currentPositionUsField.getLong(this)) + " uS");
if (Math.abs(buffer.timeUs - currentPositionUsField.getLong(this)) > getMaxAudioGapThreshold()) {
currentPositionUsField.setLong(this, buffer.timeUs);
}
allowFirstBufferPositionDiscontinuityField.setBoolean(this, false);
}
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException | NullPointerException e) {
log.e("KMediaCodecAudioRenderer", "Error subclassing audio renderer: " + e.getMessage());
// Fallback to superclass in case something goes wrong
super.onQueueInputBuffer(buffer);
}
}

@Override
protected boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs, @Nullable MediaCodecAdapter codec, @Nullable ByteBuffer buffer, int bufferIndex, int bufferFlags, int sampleCount, long bufferPresentationTimeUs, boolean isDecodeOnlyBuffer, boolean isLastBuffer, Format format) throws ExoPlaybackException {
Format decryptOnlyCodecFormat = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kaltura.android.exoplayer2.source.dash.manifest;
package com.kaltura.androidx.media3.exoplayer.dash.manifest;

import android.net.Uri;
import android.text.TextUtils;
Expand All @@ -12,24 +12,37 @@
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.kaltura.android.exoplayer2.C;
import com.kaltura.android.exoplayer2.Format;
import com.kaltura.android.exoplayer2.ParserException;
import com.kaltura.android.exoplayer2.drm.DrmInitData;
import com.kaltura.android.exoplayer2.drm.DrmInitData.SchemeData;
import com.kaltura.android.exoplayer2.extractor.mp4.PsshAtomUtil;
import com.kaltura.android.exoplayer2.metadata.emsg.EventMessage;
import com.kaltura.android.exoplayer2.source.dash.manifest.SegmentBase.SegmentList;
import com.kaltura.android.exoplayer2.source.dash.manifest.SegmentBase.SegmentTemplate;
import com.kaltura.android.exoplayer2.source.dash.manifest.SegmentBase.SegmentTimelineElement;
import com.kaltura.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase;
import com.kaltura.android.exoplayer2.upstream.ParsingLoadable;
import com.kaltura.android.exoplayer2.util.Assertions;
import com.kaltura.android.exoplayer2.util.Log;
import com.kaltura.android.exoplayer2.util.MimeTypes;
import com.kaltura.android.exoplayer2.util.UriUtil;
import com.kaltura.android.exoplayer2.util.Util;
import com.kaltura.android.exoplayer2.util.XmlPullParserUtil;
import com.kaltura.androidx.media3.common.C;
import com.kaltura.androidx.media3.common.Format;
import com.kaltura.androidx.media3.common.ParserException;
import com.kaltura.androidx.media3.common.DrmInitData;
import com.kaltura.androidx.media3.common.DrmInitData.SchemeData;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.AdaptationSet;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.BaseUrl;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.DashManifest;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.Descriptor;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.EventStream;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.Period;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.ProgramInformation;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.RangedUri;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.Representation;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.SegmentBase;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.ServiceDescriptionElement;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.UrlTemplate;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.UtcTimingElement;
import com.kaltura.androidx.media3.extractor.mp4.PsshAtomUtil;
import com.kaltura.androidx.media3.extractor.metadata.emsg.EventMessage;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.SegmentBase.SegmentList;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.SegmentBase.SegmentTemplate;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.SegmentBase.SegmentTimelineElement;
import com.kaltura.androidx.media3.exoplayer.dash.manifest.SegmentBase.SingleSegmentBase;
import com.kaltura.androidx.media3.exoplayer.upstream.ParsingLoadable;
import com.kaltura.androidx.media3.common.util.Assertions;
import com.kaltura.androidx.media3.common.util.Log;
import com.kaltura.androidx.media3.common.MimeTypes;
import com.kaltura.androidx.media3.common.util.UriUtil;
import com.kaltura.androidx.media3.common.util.Util;
import com.kaltura.androidx.media3.common.util.XmlPullParserUtil;

import org.checkerframework.checker.nullness.compatqual.NullableType;
import org.xml.sax.helpers.DefaultHandler;
Expand All @@ -47,9 +60,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.kaltura.android.exoplayer2.source.dash.manifest.BaseUrl.DEFAULT_DVB_PRIORITY;
import static com.kaltura.android.exoplayer2.source.dash.manifest.BaseUrl.DEFAULT_WEIGHT;
import static com.kaltura.android.exoplayer2.source.dash.manifest.BaseUrl.PRIORITY_UNSET;
import static com.kaltura.androidx.media3.exoplayer.dash.manifest.BaseUrl.DEFAULT_DVB_PRIORITY;
import static com.kaltura.androidx.media3.exoplayer.dash.manifest.BaseUrl.DEFAULT_WEIGHT;
import static com.kaltura.androidx.media3.exoplayer.dash.manifest.BaseUrl.PRIORITY_UNSET;

/**
* A parser of media presentation description files.
Expand Down Expand Up @@ -382,7 +395,7 @@ protected AdaptationSet parseAdaptationSet(
long timeShiftBufferDepthMs,
boolean dvbProfileDeclared)
throws XmlPullParserException, IOException {
int id = parseInt(xpp, "id", AdaptationSet.ID_UNSET);
long id = parseLong(xpp, "id", AdaptationSet.ID_UNSET);
@C.TrackType int contentType = parseContentType(xpp);

String mimeType = xpp.getAttributeValue(null, "mimeType");
Expand Down Expand Up @@ -521,7 +534,7 @@ protected AdaptationSet parseAdaptationSet(
}

protected AdaptationSet buildAdaptationSet(
int id,
long id,
@C.TrackType int contentType,
List<Representation> representations,
List<Descriptor> accessibilityDescriptors,
Expand Down
Loading