Comments (4)
You can only do that if a single MediaCodec instance can be safely accessed from multiple threads simultaneously. The documentation is silent on whether or not this is allowed, so the default assumption is "don't". (None of the CTS tests work this way, and if you've spent some time with MediaCodec you know that anything that isn't explicitly exercised by CTS is unlikely to work across devices.)
As of the Android 5.0 "Lollipop" (API 21) release, you can use MediaCodec in asynchronous mode by providing a callback (http://developer.android.com/reference/android/media/MediaCodec.Callback.html). This is the preferred solution for avoiding the wait loops.
from grafika.
In libstagefright, MediaCodec has serialized all operations on a message queue. MediaCodec should be safe if only dequeue/enqueue operations are concurrent. And there is nothing different for the low-level vendor codec implement,
I have did some work here:
feedInputBuffer
https://github.com/bbcallen/ijkplayer/blob/master/ijkmedia/ijkplayer/android/pipeline/ffpipenode_android_mediacodec_vdec.c#L368
drain_output_buffer
https://github.com/bbcallen/ijkplayer/blob/master/ijkmedia/ijkplayer/android/pipeline/ffpipenode_android_mediacodec_vdec.c#L630
These two functions work on different threads.
And MediaCodec works fine on all these devices:
https://github.com/bbcallen/ijkplayer/blob/master/android/ijkmediaplayer/src/tv/danmaku/ijk/media/player/IjkMediaCodecInfo.java#L31
BTW:
Regarding so many devices including some nexus devices won't get "Lollipop" upgrade, asynchronous mode is not a good option for application developers in real world for now, not to mention lack support in NDK.
from grafika.
The problem is that you can't write code against an API according to how it is currently implemented, because the implementation can be changed freely so long as the documented constraints are maintained. I've seen a lot of apps (and vendor-supplied system binaries) break because they depended on details that they shouldn't have. If the developers of the API aren't willing to state, "you may freely use these objects from multiple threads simultaneously", then you must assume that thread safety is not guaranteed.
Thread safety is especially tricky because the consequences can be subtle and hard to reproduce -- very nasty when failures start happening to users on the other side of the world. Given the broad range of devices and software versions, a slight increase in efficiency isn't worth the risk.
If you want to write code that makes assumptions about the internal structure, you are free to do so, with the understanding that even if it's working well today it might break in the future (or have been broken in the past). Grafika is expected to be an example that others will follow, so it needs to follow the API carefully... bad code in Grafika will turn into bad code in a large number of apps.
(See also http://developer.android.com/training/articles/smp.html )
from grafika.
Got it, thanks for your reply.
from grafika.
Related Issues (20)
- Extend encode/decode test example with asynchronous API
- Sound not available in Video using CameraCaptureActivity HOT 1
- how can i remove shape HOT 1
- how can i add shapes in texture view using open gl
- glReadPixels returns a blank image on disabling blend
- Decoding four video streams simultaneous on Google Pixel 2 phone
- seconds of video in Continuous Capture mode becomes double after keeping it on for a while. HOT 3
- If you want to record mp4 with sound, use this one https://github.com/moo611/OpenCamera
- Memory leak of Texture2dProgram
- Continuous capture bug(Android5.1.1) HOT 1
- Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x38 in tid 9379, pid 9379
- Some OpenGL stuff doesn't work on some devices: eglMakeCurrent failed and glDrawArrays: glError 0x505 HOT 4
- How to show front and back camera simultaneously? HOT 5
- Can we play scene.json in grafika?
- Test HOT 1
- Doesn't build on Flamingo and Giraffe HOT 2
- fun fact HOT 1
- Camera2 Pass Images from ImageReader to MediaRecorder HOT 2
- Camera2 pipeline; synchronously get PRIVATE/YUV/RGB Image data from a Frame HOT 4
- Website
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grafika.