Skip to content

Commit

Permalink
add an option to disable use of DoVi codecs in CodecDiscovery
Browse files Browse the repository at this point in the history
it does not work yet since native avos goes in exception trying to call CodecDiscovery (to be fixed)

See nova-video-player/aos-AVP#800
  • Loading branch information
courville committed Jan 14, 2023
1 parent 95ead6f commit bba1017
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 40 deletions.
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@
<string name="preference_tv_3d_automatic_switch_summary">Use this feature only if your 3D TV supports it</string>
<string name="preference_tv_refreshrate_switch">Enable automatic refresh rate switch</string>
<string name="preference_tv_refreshrate_switch_summary">Remove judder effect by adapting best screen refresh rate to video frame rate (device support may vary)</string>
<string name="preference_remove_dolby_vision">Disable dolby vision</string>
<string name="preference_remove_dolby_vision_summary">Use standard video codecs over dolby vision ones</string>
<string name="preference_cutout_short_edges">Fullscreen video with display cutouts</string>
<string name="preference_cutout_short_edges_summary">Allow landscape fullscreen video on display with cutouts</string>
<string name="category_languages">Subtitles</string>
Expand Down
49 changes: 28 additions & 21 deletions res/xml/preferences_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@
android:summary="@string/preferences_parser_sync_mode_summary"
android:title="@string/preferences_parser_sync_mode"
app:iconSpaceReserved="false"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="enable_downmix_androidtv"
android:persistent="true"
android:summary="@string/preferences_enable_downmix_androidtv_summary"
android:title="@string/preferences_enable_downmix_androidtv_title"
app:iconSpaceReserved="false"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="enable_tv_refreshrate_switch"
android:persistent="true"
android:summary="@string/preference_tv_refreshrate_switch_summary"
android:title="@string/preference_tv_refreshrate_switch"
app:iconSpaceReserved="false"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="disable_dolby_vision"
android:persistent="true"
android:summary="@string/preference_remove_dolby_vision_summary"
android:title="@string/preference_remove_dolby_vision"
app:iconSpaceReserved="false"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="activate_tv_switch"
android:persistent="true"
android:summary="@string/preference_tv_3d_automatic_switch_summary"
android:title="@string/preference_tv_3d_automatic_switch"
app:iconSpaceReserved="false"/>
<EditTextPreference
android:defaultValue="24"
android:title="@string/preferences_stream_buffer_size_title"
Expand All @@ -117,27 +145,6 @@
android:inputType="numberDecimal"
android:digits="0123456789"
app:iconSpaceReserved="false"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="enable_downmix_androidtv"
android:persistent="true"
android:summary="@string/preferences_enable_downmix_androidtv_summary"
android:title="@string/preferences_enable_downmix_androidtv_title"
app:iconSpaceReserved="false"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="enable_tv_refreshrate_switch"
android:persistent="true"
android:summary="@string/preference_tv_refreshrate_switch_summary"
android:title="@string/preference_tv_refreshrate_switch"
app:iconSpaceReserved="false"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="activate_tv_switch"
android:persistent="true"
android:summary="@string/preference_tv_3d_automatic_switch_summary"
android:title="@string/preference_tv_3d_automatic_switch"
app:iconSpaceReserved="false"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preferences_user_interface" android:key="category_user_interface"
app:iconSpaceReserved="false" >
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/archos/mediacenter/video/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.hardware.display.DisplayManager;
import android.media.AudioAttributes;
import android.media.AudioFocusRequest;
import android.media.AudioManager;
Expand All @@ -36,6 +35,7 @@
import android.view.WindowManager.LayoutParams;

import com.archos.mediacenter.video.R;
import com.archos.mediacenter.video.utils.CodecDiscovery;
import com.archos.mediacenter.video.utils.VideoMetadata;
import com.archos.mediacenter.video.utils.VideoPreferencesCommon;
import com.archos.medialib.IMediaPlayer;
Expand Down Expand Up @@ -108,6 +108,8 @@ public class Player implements IPlayerControl,
//| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
);

private static boolean dolbyVisionDisplay = false;

// All the stuff we need for playing and showing a video
private Context mContext = null;
private SurfaceController mSurfaceController;
Expand Down Expand Up @@ -567,7 +569,7 @@ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mVideoTexture = null;
stopPlayback();
if(mContext instanceof PlayerActivity)
((PlayerActivity) mContext).setUIExternalSurface(null);
((PlayerActivity) mContext).setUIExternalSurface(null);
if(mContext instanceof FloatingPlayerService)
((FloatingPlayerService) mContext).setUIExternalSurface(null);
if(mEffectRenderer!=null){
Expand All @@ -586,7 +588,7 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei
mVideoTexture = mEffectRenderer.getVideoTexture();
mUISurface = mEffectRenderer.getUISurface();
if(mContext instanceof PlayerActivity)
((PlayerActivity) mContext).setUIExternalSurface(mUISurface);
((PlayerActivity) mContext).setUIExternalSurface(mUISurface);
if(mContext instanceof FloatingPlayerService)
((FloatingPlayerService) mContext).setUIExternalSurface(mUISurface);
mSurfaceWidth = width;
Expand Down Expand Up @@ -978,6 +980,9 @@ public void onPrepared(IMediaPlayer mp) {
mResumeCtx.onPrepared();

boolean refreshRateSwitchEnabled = PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(VideoPreferencesCommon.KEY_ACTIVATE_REFRESHRATE_SWITCH, false);
boolean isDoViDisabled = PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(VideoPreferencesCommon.KEY_DISABLE_DOLBY_VISION, false);
CodecDiscovery.disableDoVi(isDoViDisabled); // could be an autoswitch based on HDR DoVi screen capability
CodecDiscovery.displaySupportsDoVi(dolbyVisionDisplay);
if (mWindow != null && refreshRateSwitchEnabled) {
VideoMetadata.VideoTrack video = mVideoMetadata.getVideoTrack();

Expand Down Expand Up @@ -1008,6 +1013,7 @@ public void onPrepared(IMediaPlayer mp) {
switch (hdrSupportedTypes[i]) {
case Display.HdrCapabilities.HDR_TYPE_DOLBY_VISION:
log.debug("CONFIG HDR dolby vision supported");
dolbyVisionDisplay = true;
break;
case Display.HdrCapabilities.HDR_TYPE_HDR10:
log.debug("CONFIG HDR10 supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,77 @@

package com.archos.mediacenter.video.utils;

import android.annotation.TargetApi;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.os.Build;
import android.util.Log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

public class CodecDiscovery {

private static final Logger log = LoggerFactory.getLogger(CodecDiscovery.class);

private static String TAG = "CodecDiscovery";
private static boolean DBG = false;
private static boolean isDoViDisabled = false;
private static boolean displaySupportsDovi = false; // could be used to auto disable DoVi codecs

public static boolean isCodecTypeSupported(String codecType, boolean allowSwCodec) {
return isCodecTypeSupported(codecType, allowSwCodec, MediaCodecList.REGULAR_CODECS);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void displaySupportsDoVi(boolean isSupported) {
displaySupportsDovi = isSupported;
}

public static void disableDoVi(boolean isDisabled) {
isDoViDisabled = isDisabled;
}

private static boolean isCodecTypeSupported(String codecType, boolean allowSwCodec, int kind) {
MediaCodecList codecList = new MediaCodecList(kind);
MediaCodecInfo[] codecInfos = codecList.getCodecInfos();

for (MediaCodecInfo codecInfo : codecInfos) {
if (DBG) Log.d(TAG, "isCodecTypeSupported: codecInfo.getName " + codecInfo.getName());
if (isCodecInfoSupported(codecInfo, codecType, allowSwCodec))
if (isCodecInfoSupported(codecInfo, codecType, allowSwCodec)) {
log.debug("isCodecTypeSupported: codecInfo.getName " + codecInfo.getName() + "supported");
return true;
} else {
log.debug("isCodecTypeSupported: codecInfo.getName " + codecInfo.getName() + "not supported");
}
}
return false;
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static boolean isSwCodec(MediaCodecInfo codecInfo) {
if (Build.VERSION.SDK_INT >= 29) {
return codecInfo.isSoftwareOnly();
} else {
return codecInfo.getName().startsWith("OMX.google") ||
codecInfo.getName().toLowerCase().contains("sw") ||
codecInfo.getName().toLowerCase().startsWith("c2.android");
}
}

private static boolean isCodecInfoSupported(MediaCodecInfo codecInfo, String codecType, boolean allowSwCodec) {
if (codecInfo.isEncoder()
|| (!allowSwCodec && ( codecInfo.getName().startsWith("OMX.google")
|| codecInfo.getName().toLowerCase().contains("sw")
|| codecInfo.getName().toLowerCase().startsWith("c2.android")
)))
if (codecInfo.isEncoder() || (!allowSwCodec && isSwCodec(codecInfo))) {
log.debug("isCodecTypeSupported: codecInfo.getName " + codecInfo.getName() + " not supported");
return false;

}
String[] types = codecInfo.getSupportedTypes();
log.trace("isCodecTypeSupported: looking for codecType " + codecType + ", codecInfo.getName " + codecInfo.getName() + ", supported types " + Arrays.toString(types));
for (String type : types) {
if (type.equalsIgnoreCase(codecType))
return true;
if (type.equalsIgnoreCase(codecType)) {
log.debug("isCodecTypeSupported: codecInfo.getName " + codecInfo.getName() + " not supported");
if (type.equalsIgnoreCase("video/dolby-vision") && isDoViDisabled) {
log.debug("isCodecTypeSupported: rejecting codecInfo.getName " + codecInfo.getName() + " because dolby vision disabled");
return false;
} else {
log.debug("isCodecTypeSupported: validating codecInfo.getName " + codecInfo.getName());
return true;
}
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class VideoPreferencesCommon implements OnSharedPreferenceChangeListener
public static final String KEY_FORCE_SW = "force_software_decoding";
public static final String KEY_FORCE_AUDIO_PASSTHROUGH = "force_passthrough";
public static final String KEY_PARSER_SYNC_MODE = "parser_sync_mode";
public static final String KEY_DISABLE_DOLBY_VISION = "disable_dolby_vision";
public static final String KEY_STREAM_BUFFER_SIZE = "stream_buffer_size";
public static final String KEY_STREAM_MAX_IFRAME_SIZE = "stream_max_iframe_size";
public static final String KEY_PLAYBACK_SPEED = "playback_speed";
Expand Down

0 comments on commit bba1017

Please sign in to comment.