简体   繁体   English

Android MediaCodec解码h264原始数据延迟问题

[英]Android MediaCodec decode h264 raw data latency issue

I have tried to use MediaCodec to decode 1080p h264 raw data. 我尝试使用MediaCodec解码1080p h264原始数据。 But I found the latency is between 45ms~65ms with my SONY Z3(5.1.1). 但是我发现SONY Z3(5.1.1)的延迟在45ms〜65ms之间。 Is possible to reduce the latency? 可以减少延迟吗? My frame is IPPP and GOP is 15, Have any h264 sps flag will effect the latency? 我的帧是IPPP,GOP是15,是否有任何h264 sps标志会影响延迟?

And I have another question, how to change the orientation of surface let the frame show in 90,180 or 270 degree. 我还有一个问题,如何改变表面的方向让框架以90,180或270度显示。

I put my test project source in following google drive link. 我把我的测试项目源放在下面的谷歌驱动器链接。 And the h264 raw data is in test_code\\res\\raw . 并且h264原始数据在test_code \\ res \\ raw中。

https://drive.google.com/file/d/0B688fdS1LxF4REtra0YteDh6TkE/view?usp=sharing https://drive.google.com/file/d/0B688fdS1LxF4REtra0YteDh6TkE/view?usp=sharing

02-16 18:05:52.804: I/Process(10590): Sending signal. PID: 10590 SIG: 9
02-16 18:05:54.618: W/ResourceType(10706): Found multiple library tables, ignoring...
02-16 18:05:54.677: D/OpenGLRenderer(10706): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-16 18:05:54.684: D/Atlas(10706): Validating map...
02-16 18:05:54.717: I/Adreno-EGL(10706): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.01.00.042.030_msm8974_LA.BF.1.1.1_RB1__release_AU ()
02-16 18:05:54.717: I/Adreno-EGL(10706): OpenGL ES Shader Compiler Version: E031.25.03.06
02-16 18:05:54.717: I/Adreno-EGL(10706): Build Date: 07/13/15 Mon
02-16 18:05:54.717: I/Adreno-EGL(10706): Local Branch: mybranch11906725
02-16 18:05:54.717: I/Adreno-EGL(10706): Remote Branch: quic/LA.BF.1.1.1_rb1.26
02-16 18:05:54.717: I/Adreno-EGL(10706): Local Patches: NONE
02-16 18:05:54.717: I/Adreno-EGL(10706): Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.01.00.042.030 + 6151be1 + a1e0343 + 002d7d6 + 7d0e3f7 +  NOTHING
02-16 18:05:54.718: I/OpenGLRenderer(10706): Initialized EGL, version 1.4
02-16 18:05:54.733: D/OpenGLRenderer(10706): Enabling debug mode 0
02-16 18:05:54.800: I/Timeline(10706): Timeline: Activity_idle id: android.os.BinderProxy@1970952c time:27341192
02-16 18:05:56.804: I/OMXClient(10706): Using client-side OMX mux.
02-16 18:05:56.819: D/MediaCodec(10706): MediaCodec[kWhatConfigure]: video-output-protection: 00000000, audio-output-protection: 00000000
02-16 18:05:56.821: I/ACodec(10706): [OMX.qcom.video.decoder.avc] DRC Mode: Dynamic Buffer Mode
02-16 18:05:56.827: I/ExtendedCodec(10706): Decoder will be in frame by frame mode
02-16 18:05:56.830: D/ACodec(10706): Found video-output-protection flags set to 00000000
02-16 18:05:56.845: E/(10706): inputBuffers.size:4
02-16 18:05:56.845: E/(10706): outputBuffers.size:23
02-16 18:05:56.858: E/DecodeActivity(10706): dequeueOutputBuffer timed out!
02-16 18:05:56.870: E/DecodeActivity(10706): dequeueOutputBuffer timed out!
02-16 18:05:56.883: E/DecodeActivity(10706): dequeueOutputBuffer timed out!
02-16 18:05:56.884: E/DecodeActivity(10706): INFO_OUTPUT_BUFFERS_CHANGED
02-16 18:05:56.892: E/DecodeActivity(10706): New format {mime=video/raw, crop-top=0, crop-right=1919, slice-height=1088, color-format=2141391876, height=1088, width=1920, what=1869968451, crop-bottom=1079, crop-left=0, stride=1920}
02-16 18:05:56.898: E/DecodeActivity(10706): Receive first decode frame after 51 ms

I see in your code that you set 10000 uS as the timeout to receive input data. 我在您的代码中看到您将10000 uS设置为接收输入数据的超时。 That's a short amount of time. 那是很短的时间。

while (!Thread.interrupted()) {
            if (!isEOS) {
                int inIndex = decoder.dequeueInputBuffer(10000);

In dequeueInputBuffer , put a very long timeout, like ten seconds (10000000). dequeueInputBuffer ,放置一个很长的超时,例如十秒(10000000)。 It will allow waiting longer. 这样可以等待更长的时间。 Setting -1 as the timeout will block until data is received. 将-1设置为超时将阻塞,直到接收到数据为止。

You should maybe handle connectivity problems outside of your feeding loop, and have your own helper to buffer the initial data before launching the feeding loop. 您可能应该在馈送循环之外处理连接问题,并在启动馈送循环之前让自己的助手来缓冲初始数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM