-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add an ExoPlayer settings page #8875
Changes from all commits
a4a9957
41da8fc
a6ff85a
a02b92f
787758a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.schabi.newpipe.player.helper; | ||
|
||
import android.content.Context; | ||
import android.os.Handler; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.google.android.exoplayer2.mediacodec.MediaCodecAdapter; | ||
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector; | ||
import com.google.android.exoplayer2.video.MediaCodecVideoRenderer; | ||
import com.google.android.exoplayer2.video.VideoRendererEventListener; | ||
|
||
/** | ||
* A {@link MediaCodecVideoRenderer} which always enable the output surface workaround that | ||
* ExoPlayer enables on several devices which are known to implement | ||
* {@link android.media.MediaCodec#setOutputSurface(android.view.Surface) | ||
* MediaCodec.setOutputSurface(Surface)} incorrectly. | ||
* | ||
* <p> | ||
* See {@link MediaCodecVideoRenderer#codecNeedsSetOutputSurfaceWorkaround(String)} for more | ||
* details. | ||
* </p> | ||
* | ||
* <p> | ||
* This custom {@link MediaCodecVideoRenderer} may be useful in the case a device is affected by | ||
* this issue but is not present in ExoPlayer's list. | ||
* </p> | ||
* | ||
* <p> | ||
* This class has only effect on devices with Android 6 and higher, as the {@code setOutputSurface} | ||
* method is only implemented in these Android versions and the method used as a workaround is | ||
* always applied on older Android versions (releasing and re-instantiating video codec instances). | ||
* </p> | ||
*/ | ||
public final class CustomMediaCodecVideoRenderer extends MediaCodecVideoRenderer { | ||
|
||
@SuppressWarnings({"checkstyle:ParameterNumber", "squid:S107"}) | ||
public CustomMediaCodecVideoRenderer(final Context context, | ||
final MediaCodecAdapter.Factory codecAdapterFactory, | ||
final MediaCodecSelector mediaCodecSelector, | ||
final long allowedJoiningTimeMs, | ||
final boolean enableDecoderFallback, | ||
@Nullable final Handler eventHandler, | ||
@Nullable final VideoRendererEventListener eventListener, | ||
final int maxDroppedFramesToNotify) { | ||
super(context, codecAdapterFactory, mediaCodecSelector, allowedJoiningTimeMs, | ||
enableDecoderFallback, eventHandler, eventListener, maxDroppedFramesToNotify); | ||
} | ||
|
||
@Override | ||
protected boolean codecNeedsSetOutputSurfaceWorkaround(final String name) { | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.schabi.newpipe.player.helper; | ||
|
||
import android.content.Context; | ||
import android.os.Handler; | ||
|
||
import com.google.android.exoplayer2.DefaultRenderersFactory; | ||
import com.google.android.exoplayer2.Renderer; | ||
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector; | ||
import com.google.android.exoplayer2.video.VideoRendererEventListener; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* A {@link DefaultRenderersFactory} which only uses {@link CustomMediaCodecVideoRenderer} as an | ||
* implementation of video codec renders. | ||
* | ||
* <p> | ||
* As no ExoPlayer extension is currently used, the reflection code used by ExoPlayer to try to | ||
* load video extension libraries is not needed in our case and has been removed. This should be | ||
* changed in the case an extension is shipped with the app, such as the AV1 one. | ||
* </p> | ||
*/ | ||
public final class CustomRenderersFactory extends DefaultRenderersFactory { | ||
|
||
public CustomRenderersFactory(final Context context) { | ||
super(context); | ||
} | ||
|
||
@SuppressWarnings("checkstyle:ParameterNumber") | ||
@Override | ||
protected void buildVideoRenderers(final Context context, | ||
@ExtensionRendererMode final int extensionRendererMode, | ||
final MediaCodecSelector mediaCodecSelector, | ||
final boolean enableDecoderFallback, | ||
final Handler eventHandler, | ||
final VideoRendererEventListener eventListener, | ||
final long allowedVideoJoiningTimeMs, | ||
final ArrayList<Renderer> out) { | ||
out.add(new CustomMediaCodecVideoRenderer(context, getCodecAdapterFactory(), | ||
mediaCodecSelector, allowedVideoJoiningTimeMs, enableDecoderFallback, eventHandler, | ||
eventListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.schabi.newpipe.settings; | ||
|
||
import android.os.Bundle; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
public class ExoPlayerSettingsFragment extends BasePreferenceFragment { | ||
|
||
@Override | ||
public void onCreatePreferences(@Nullable final Bundle savedInstanceState, | ||
@Nullable final String rootKey) { | ||
addPreferencesFromResourceRegistry(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,22 +36,6 @@ public final class DeviceUtils { | |
private static Boolean isTV = null; | ||
private static Boolean isFireTV = null; | ||
|
||
/* | ||
* Devices that do not support media tunneling | ||
*/ | ||
// Formuler Z8 Pro, Z8, CC, Z Alpha, Z+ Neo | ||
private static final boolean HI3798MV200 = Build.VERSION.SDK_INT == 24 | ||
&& Build.DEVICE.equals("Hi3798MV200"); | ||
// Zephir TS43UHD-2 | ||
private static final boolean CVT_MT5886_EU_1G = Build.VERSION.SDK_INT == 24 | ||
&& Build.DEVICE.equals("cvt_mt5886_eu_1g"); | ||
// Hilife TV | ||
private static final boolean REALTEKATV = Build.VERSION.SDK_INT == 25 | ||
&& Build.DEVICE.equals("RealtekATV"); | ||
// Philips QM16XE | ||
private static final boolean QM16XE_U = Build.VERSION.SDK_INT == 23 | ||
&& Build.DEVICE.equals("QM16XE_U"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmh, why are you removing this list completely? We know all these TVs don't work, so by default on such devices tunneling should be disabled. Then the user can go into settings and enable it, but at least it should be off by default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Someone needs to write a methid that sets a default value depeding on the device. Otherwise, NewPipe is going to stop working for some users and they certainly not search for a solution in the settings. |
||
|
||
private DeviceUtils() { | ||
} | ||
|
||
|
@@ -211,18 +195,6 @@ public static int spToPx(@Dimension(unit = Dimension.SP) final int sp, | |
context.getResources().getDisplayMetrics()); | ||
} | ||
|
||
/** | ||
* Some devices have broken tunneled video playback but claim to support it. | ||
* See https://github.com/TeamNewPipe/NewPipe/issues/5911 | ||
* @return false if affected device | ||
*/ | ||
public static boolean shouldSupportMediaTunneling() { | ||
return !HI3798MV200 | ||
&& !CVT_MT5886_EU_1G | ||
&& !REALTEKATV | ||
&& !QM16XE_U; | ||
} | ||
|
||
public static boolean isLandscape(final Context context) { | ||
return context.getResources().getDisplayMetrics().heightPixels < context.getResources() | ||
.getDisplayMetrics().widthPixels; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I would make sure the preference does not get auto-created, and then use
!DeviceUtils.shouldSupportMediaTunneling()
instead offalse
as the value to use when the preference is not set.