-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Using multiple exo-players simultaneously #273
Comments
Seems complicated to me.... Maybe you can try to fallback to software decoding. See https://github.com/google/ExoPlayer/blob/master/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java#L289 for the place where the codec are created. You can try to add a fallback there that uses a software codec. As far as I can remember, they should be OMX.google.XXX. But you wont have the same level of performance and battery life of course... |
There will be a limit on the maximum number of hardware decoders that you can instantiate, which you're hitting. Note that 4 is pretty generous. I believe some devices only allow 2. Your best bet is doing as Martin suggests, and modifying the code to use software decoders. You could implement this as a fallback (e.g. try and obtain the qcom one first, and use the google one if instantiation fails). Whether this works well enough really depends on your use case. If you're trying to decode 5+ HD streams, that's likely just beyond the performance limitations of existing devices. If they're low resolution thumbnail-style videos, you might have more luck. |
Thank you for your help - this is also what I had in mind. The strange thing is that on some devices (LG G2, HTC, Nexus 5) using a simple MediaPlayer + TextureView I have no problem rendering even 10+ videos simultaneously. I guess that to emulate this kind of behaviour in ExoPlayer would require a significant amount of non-trivial coding that would need to decode byte buffers from multiple videos using an available decoder and timing everything very tightly - I guess that this is beyond the scope of ExoPlayer but would make an interesting direction to explore :) Please let me know what you think. Thanks. |
What's your point ? MediaPlayer can decode 10+ videos and Exoplayer cannot ? If this is really the case, I don't believe too much in the 'sharing' thing. I would rather think that Exoplayer allocates bigger instances by default (since resolution could potentially change). That is just a blind guess though... |
Yeah, it's highly unlikely that there's any kind of clever sharing of decoders underneath MediaPlayer. Either the devices you mention also grant 10+ hardware decoders to ExoPlayer, or fewer are granted because ExoPlayer is allocating bigger instances as Martin says (if this is demonstrably the case, it's worth us investigating to see if we can allow more instances), or MediaPlayer is using software decoders and it just happens that they perform well. Note that the term "hardware decoder" is used very loosely, and what it means varies from device to device. In general it's not true that a "hardware decoder instance" directly maps onto an actual dedicated physical piece of hardware. I guess "hardware accelerated decoder" would be a better term, where the actual hardware used, and the way it's used, can vary from chipset to chipset. For example a hardware accelerated decoder may require an allocation of GPU memory, and it's things like this that explain why allocating smaller instances may allow more instances to be granted. |
Martin, my point is very clear - I'm trying to understand how to utilize ExoPlayer for displaying 10+ videos while using "hardware accelerated decoding" (better term indeed!) since ExoPlayer is much more flexible to work than the (very) bad MediaPlayer. ojw28, on the same device (LG G2) using MediaPlayer + TextureView allows rendering 10+ videos while ExoPlayer fails after 4 - so I guess it should be related to the size of instance allocation that you both mentioned - but where exactly do you control that? I see that the codec is instantiated only by its name. |
|
|
Btw - the solution of falling back to software decoding if the decoder allocation fails is not really feasible since the failure is not always reported. So I guess I'll need to force software rendering on all H264 video decoding in advance for ExoPlayer. (I already did it and works nicely - if you think it could help someone I can add it in a pull-request). |
|
The problems starts on devices where MediaCodec.createDecoderByType attempts to create more hardware accelerated decoders than what's available on the device. Looks like it depends on how the ACodec.cpp was implemented or it might also be related to the Android version (I saw this behaviour only on API < 19) but I can't really say until I investigate this issue further. Maybe you can consider allowing ExoPlayer to use MediaCodec.createDecoderByType instead of MediaCodec.createDecoderByName? |
@dnutcracker reading the issue, did you write your own MediaCodecTrackRenderer using a software decoder? If possible, can you describe the main parts, components, and maybe post the source ? |
No - I simply forced MediaCodecUtils.getDecoderInfo() to return a software decoder back to the ExoPlayer. |
@dnutcracker how did you find the software decoder name ? |
Just print all the available decoders and look for all that start with OMX.google |
I am facing the same problem with stream of .mp3 files on a Samsung Galaxy S2, what I have read from all the comments here the problem seems to be the hardware decoding that s2 doesn't have and maybe other devices too. I already tried to use the mp3Extractor from dev-branch but nothing changed. One solution would be to change the hardware decoding into software but I need to do this change only on devices that don't support hardware. Is there a good approach to achieve this ? I will come back with logcat from S2 and with some parts of my code. |
I have the same problem on Nexus7 with multiple ExoPlayers. The VIDC_MAX_NUM_CLIENTS constant is 4. |
How well does software decoding work? I have a similar requirement where I have to display 5 videos simultaneously. My videos are fairly small / low quality so it should theoretically play back ok. I tried adding OMX.google. instead of OMX and it returns the OMX.google.h264.decoder Only problem is it won't play any videos... |
Well I have an issue with an android box where I am playing one full screen video and before the end of this video I am trying to prepare the next one that is hidden so to swap the videos to achieve gapless playback. On my Galaxy Note 2 it works good, on the android box I have the codec error: Unable to instantiate decoder 'OMX.amlogic.avc.decoder.awesome'. |
I've been playing on the Nexus 7 and I can't get two of them to play simultaneously. I can only assume it is a hardware limitation that is being imposed. Specifically attempting ad overlays over content player. If I hide the |
I have try software decoder. It is really a terrible option. Never think about it, guys.
Before your video decoder name |
@huyn - Note that many low end devices only have the software decoder and it actually performs quite well (easily well enough for this to be a viable option for shipping a low end device). So your statement seems a bit over the top. If you're going to advise people to not even think about using it, I think you need to back up your statement with some solid facts and figures ;)... |
Question:
I've been experimenting with playing multiple videos simultaneously but quickly got to the maximum of 4.
Using more than 4 resulted in failure to create a new MediaCodec (OMX.qcom.video.decoder.avc) - "Failed to allocate component instance".
Is there any way to bypass this limitation?
Thanks.
The text was updated successfully, but these errors were encountered: