-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
ExoPlayer: Only allow hardware-accelerated video codecs in DirectPlay #1135
base: master
Are you sure you want to change the base?
Conversation
f2e9cad
to
df4bcd1
Compare
I fixed the detection of |
Thanks for investigating this and your contribution!
This would definitely be ideal, but I think I could look into it myself later. Except for some code style tweaks, this should be mergeable as is. I'll see if I find some time to look into it in the next few days. |
@RequiresApi(Build.VERSION_CODES.Q) | ||
fun canHardwareDecode(codec: String): Boolean { | ||
val parsedCodec = when (codec) { | ||
"mpeg4" -> "avc1" |
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.
mpeg4
might not be the same as h264
, so this line might need to go
"mpeg4" -> "avc1" |
i weren't really sure about this, there's a lot of conflicting information out there about how mpeg4
and h264
relate 🤔
I refactored your code so that it doesn't have to re-read the supported However, I also talked to @nielsvanvelzen, and we agreed that completely disallowing software decoding by default is quite extreme. There should also exist a few software-only decoders that perform reasonably well. Instead, Niels suggested detecting choppy playback and switching the transcoding if applicable. Thus, I'd like to keep this PR open for now while I think about the feasibility of that suggestion. |
Why not just do it straightaway like i proposed intially?
So by default chose hardware decoding with transcoding (if its required), but just always use the software decoder in direct play when the user switches to software decoding. Alternatively maybe an additional setting would work, something like "Force hardware decoding even if it requires transcoding". |
c753c14
to
43e69db
Compare
(everything here relates to ExoPlayer and the experience of selecting "
Integrated player
" in the client settings)background
When streaming video, ExoPlayer automatically chooses software decoding if there is no hardware decoder available.
However, depending on the codec this may result in an unpleasant experience.
In my case, streaming
AV1
on the devicegts4lv
resulted in significant stutter when the picture was moving quickly.Currently there exists an toggle in the player to change between hardware and software encoding.
Software decoding always works (i assume), however hardware encoding will result in an black image if the hardware doesnt support decoding this codec.
best possible solution
The best situation (in my opinion) would be, that video is transcoded by default if the hardware doesn't support it (especially on android, where the device is usually run on battery).
So when choosing software decoding, DirectPlay is fine, but when choosing hardware decoding, transcoding should automatically be applied if the hardware doesn't support this codec.
current solution
Sadly due to limited experience with kotlin and the situation I were not able to implement exactly as I would like it to.
This solution here just filters out all codecs from DirectPlay which can't be hardware decoded.
In my situation this forced transcoding of
AV1
video and results in a smooth playback experience.This solution does also prevent direct-streaming the
AV1
stream completely,but I do think that this should generally lead to a better user experience overall.
code explaination
I do know this solution might not be the best.
The ExoPlayer API seems to give hardware decoder feedback based on MIME-Types.
The function
MimeTypes.getMediaMimeType(String)
can only interpretav01
but notav1
, hence the extra additional rewrite ofav1
toav01
.The rest of the codecs seem to be fine, I had some logging in there and it did detect hardware decoding support for
vp8
andvp9
correctly. (i think alsoh264
andh265
if i remember correctly)But there definitely is a better solution for this container list to MIME-Type conversion.