Skip to content
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

解决ijk第一次初始化时异步线程调用主线程造成的线程卡顿问题 #4683

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

poholo
Copy link

@poholo poholo commented Apr 10, 2019

  1. 修正IJKSDLGLView view调用方式
  2. 编译方式去除armv7 armv7s
  3. 编译方式用openssl

@poholo
Copy link
Author

poholo commented Apr 10, 2019

#4681

@heelin
Copy link

heelin commented Apr 18, 2019

it works! Thanks.

@AlekseiR
Copy link

AlekseiR commented May 3, 2019

Does it fix the memory leak?

@poholo
Copy link
Author

poholo commented May 7, 2019

It hasn't happened yet.

Does it fix the memory leak?

It hasn't happened yet.

@FxDepths
Copy link

FxDepths commented May 9, 2019

能说的详细一下吗?谢谢

@poholo
Copy link
Author

poholo commented May 13, 2019

能说的详细一下吗?谢谢

这个问题,主要原因是xcode版本升级导致的,UIKit以前非必须主线程调用的(比如.layer ), 现在必须主线程调用,异步线程调用会导致线程检查等待,故本次的修改主要是对IJKSDLGLView中被检查到的UIKit调用全部用主线程调用。

@a20727740
Copy link

  1. 修正IJKSDLGLView视图调用方式
  2. 编译方式去除armv7 armv7s
  3. 编译方式用的OpenSSL

观看的时候 快速seek多次会崩溃 , ...我用官方的没事

@poholo
Copy link
Author

poholo commented Jul 17, 2019

  1. 修正IJKSDLGLView视图调用方式
  2. 编译方式去除armv7 armv7s
  3. 编译方式用的OpenSSL

观看的时候 快速seek多次会崩溃 , ...我用官方的没事

什么机型? 用我编译好的framework看看呢 ?

MCIJKPlayer

@a20727740
Copy link

  1. 修正IJKSDLGLView视图调用方式
  2. 编译方式去除armv7 armv7s
  3. 编译方式用的OpenSSL的

观看的时候快速寻求多次会崩溃,...我用官方的没事

什么机型?用我编译好的框架看看呢?

MCIJKPlayer

...用不了. 你确认没发错?IJKMediaFramework.framework

@poholo
Copy link
Author

poholo commented Jul 17, 2019

  1. 修正IJKSDLGLView视图调用方式
  2. 编译方式去除armv7 armv7s
  3. 编译方式用的OpenSSL的

观看的时候快速寻求多次会崩溃,...我用官方的没事

什么机型?用我编译好的框架看看呢?
MCIJKPlayer

...用不了. 你确认没发错?IJKMediaFramework.framework

https://dev.tencent.com/u/lp_mr/p/MCIJKPlayer/git

@a20727740
Copy link

  1. 修正IJKSDLGLView视图调用方式
  2. 编译方式去除armv7 armv7s
  3. 编译方式用的OpenSSL的的

观看的时候快速寻求多次会崩溃,...我用官方的没事

什么机型?用我编译好的框架看看呢?
MCIJKPlayer

......用不了。你确认没发错?IJKMediaFramework.framework

https://dev.tencent.com/u/lp_mr/p/MCIJKPlayer/git

100%复现了, ....

Copy link

@SamPan1988 SamPan1988 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope this will help someone

// do not lock AudioQueueStop, or may be run into deadlock
AudioQueueStop(_audioQueueRef, true);
AudioQueueDispose(_audioQueueRef, true);
IJKMainThredExecute(^{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里会导致野指针崩溃,因AudioQuueueDispose 在主队列的执行时间不确定,可能IJKSDLAudioQueueController的实例已经被释放,但AudioQueueDispose还没执行,导致IJKSDLAudioQueueOuptutCallback回调时访问已释放的IJKSDLAudioQueueController的实例,引起崩溃;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试场景:
播放资源切换,因为ijkffmoviecontroller的设计,实际上每次播放一个新的资源都是创建一个新的ijkffmoviecontroller的实例

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

试一试

    [self.player stop];
    [self.player shutdown];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我也遇到这个问题了,请问解决了么

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我今天遇到了这个问题,有解决的吗?

@a20727740
Copy link

@a20727740
Copy link

是的, 我是两个 url 之间切换 循环, 创建 释放 ijk......

希望这会对某人有所帮助

是的, 我是两个 url 之间切换 循环, 创建 释放 ijk......

@poholo
Copy link
Author

poholo commented Aug 2, 2019

https://git.dev.tencent.com/lp_mr/MCIJKPlayer.git
已做优化,看看是否还是有同样的问题。

@wning13
Copy link

wning13 commented Aug 2, 2019

我这边遇到一个问题是播放本地的视频时没有声音,播放进度一直是0

@poholo
Copy link
Author

poholo commented Aug 2, 2019

多找几个视频地址试一下(看看你手机的媒体音量设置模式等。。),我没发现这个问题。

@a20727740
Copy link

多找几个视频地址试一下(看看你手机的媒体音量设置模式等。),我没发现这个问题。

https://i.loli.net/2019/08/03/dTqfU9hI6riv1Bg.png 显示模式改了?上面是你的 下面的默认的

@YelCode
Copy link

YelCode commented Aug 28, 2019

多找几个视频地址试一下(看看你手机的媒体音量设置模式等。。),我没发现这个问题。

你好 你这个显示模式有问题啊 视频变得很小

@poholo
Copy link
Author

poholo commented Aug 30, 2019

图片看不到了,不确定你们是什么问题。
IJKMPMovieScalingModeAspectFit
IJKMPMovieScalingModeAspectFit
IJKMPMovieScalingModeAspectFit

默认也是 IJKMPMovieScalingModeAspectFit

 _scalingMode = IJKMPMovieScalingModeAspectFit;
        _shouldAutoplay = YES;
        memset(&_asyncStat, 0, sizeof(_asyncStat));
        memset(&_cacheStat, 0, sizeof(_cacheStat));
        _monitor = [[IJKFFMonitor alloc] init];

@YelCode
Copy link

YelCode commented Aug 31, 2019

github2
github1
图1是默认框架的IJKMPMovieScalingModeAspectFit 会延伸到屏幕宽度
图2是你的框架IJKMPMovieScalingModeAspectFit 视频缩小了

@poholo
Copy link
Author

poholo commented Aug 31, 2019 via email

@YelCode
Copy link

YelCode commented Aug 31, 2019

随便一个点播的地址 都是这样
http://5815.liveplay.myqcloud.com/live/5815_89aad37e06ff11e892905cb9018cf0d4.flv
image

@chaocharleswang
Copy link

chaocharleswang commented Sep 1, 2019

我的也存在视频图像很小这个问题,测试的所有视频都这样
原版本不存在这个问题
用的scalingMode是.aspectFit

IMG_1155

@poholo
Copy link
Author

poholo commented Sep 2, 2019

这块的问题是子view没有随着父view的frame变化而自适应,源码是demo层做了autoresizingMask,现在我把这句直接提到IJKFFMovieController中。命中语句

self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

@YellBinn @chaocharleswang
辛苦可以看一下是否解决,不愿重新打包的话可以调用这么一句试试呢 ?

当然也可以直接用我打的pod

pod 'MCIJKPlayer'

https://git.dev.tencent.com/lp_mr/MCIJKPlayer.git

@poholo
Copy link
Author

poholo commented Sep 2, 2019

@chaocharleswang 麻烦贴一下视频地址

@chaocharleswang
Copy link

@poholo 将才测试时替换出现错误,问题解决了,谢谢!

@chaocharleswang
Copy link

chaocharleswang commented Sep 2, 2019

@poholo 我观察到另外一个问题:视图变小的版本在xcode 10和xcode 11都能正常运行。
而修改后的版本在xcode 11出现下列错误:

-[MTLDebugBuffer newTextureWithDescriptor:offset:bytesPerRow:]:326: failed assertion `resourceOptions (0x0) must match backing buffer resource options (0x20).'

或者

validateNewTexture:89: failed assertion `BytesPerRow of a buffer-backed texture with pixelFormat(MTLPixelFormatBGRA8Unorm) must be aligned to 64 bytes, found bytesPerRow(4512)'

错误都出现在下面的语句:

[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *) self.weakLayer];

错误出现的操作是缩放移动视频播放界面,操作都是在iPhone X上进行的

@poholo
Copy link
Author

poholo commented Sep 2, 2019

@chaocharleswang 你试试把IJKSDLGLView中304行注释掉看看

_isRenderBufferInvalidated = YES;

其他我没有变动什么

@chaocharleswang
Copy link

@poholo 注释后问题确实消失了,只不过视图又变回小视图了

@poholo
Copy link
Author

poholo commented Sep 3, 2019

@chaocharleswang 帮忙验证一下,感谢!

@chaocharleswang
Copy link

@poholo 视图正常,移动播放窗口xcode 11还是会出现同样的错误,而xcode 10却一切正常

@poholo
Copy link
Author

poholo commented Sep 3, 2019

@chaocharleswang 我去下个测试版的xcode

@chaocharleswang
Copy link

chaocharleswang commented Sep 5, 2019

@poholo 我把你改过的code整合到我的项目中,用户反馈最多的crash是下面这一个:

Thread 21 name:
Thread 21 Crashed:
0   libGPUSupportMercury.dylib    	0x0000000212b0ffe4 gpus_ReturnNotPermittedKillClient + 12 (gpui_client_io.c:78)
1   AGXGLDriver                   	0x00000002171bced8 glrKillClient + 468 (agxu_kill_client.cpp:175)
2   libGPUSupportMercury.dylib    	0x0000000212b10fac gpusSubmitDataBuffers + 176 (gpui_context.c:0)
3   AGXGLDriver                   	0x00000002171be404 SubmitPackets(AGXContextRec*) + 292 (agxu_gl_command.cpp:93)
4   GLEngine                      	0x00000002183cd234 gliPresentViewES_Exec + 184 (gli_drawable_es.c:526)
5   OpenGLES                      	0x00000001f9d10aa4 -[EAGLContext presentRenderbuffer:] + 80 (eagl_context.m:594)
6   TubePlayer                     	0x0000000100a5da20 -[IJKSDLGLView displayInternal:] + 456 (IJKSDLGLView.m:378)
7   TubePlayer                     	0x0000000100a5d7c0 -[IJKSDLGLView display:] + 204 (IJKSDLGLView.m:340)
8   TubePlayer                     	0x0000000100a6e9b8 vout_display_overlay + 300 (ijksdl_vout_ios_gles2.m:0)
9   TubePlayer                     	0x0000000100a58d30 video_display2 + 348 (ff_ffplay.c:911)
10  TubePlayer                     	0x0000000100a56ec4 video_refresh_thread + 1868 (ff_ffplay.c:1416)
11  TubePlayer                     	0x0000000100a5b130 SDL_RunThread + 40 (ijksdl_thread_ios.m:32)
12  libsystem_pthread.dylib       	0x00000001f67242c0 _pthread_body + 128 (pthread.c:857)
13  libsystem_pthread.dylib       	0x00000001f6724220 _pthread_start + 44 (pthread.c:884)
14  libsystem_pthread.dylib       	0x00000001f6727cdc thread_start + 4

这是通过xcode 10提交的,和xcode 11无关
还有一个crash是下面这一个,这一个反馈的少一些:

Thread 0 Crashed:
0   libsystem_kernel.dylib        	0x00000002355590cc __pthread_kill + 8
1   libsystem_c.dylib             	0x00000002354b214c abort + 144 (abort.c:94)
2   libsystem_c.dylib             	0x000000023547f2d0 __assert_rtn + 316 (assert.c:91)
3   TubePlayer                     	0x0000000101262c0c ffp_prepare_async_l + 2016 (ff_ffplay.c:4252)
4   TubePlayer                     	0x0000000101271174 ijkmp_prepare_async + 332 (ijkplayer.c:413)
5   TubePlayer                     	0x000000010113609c thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:0)
6   libdispatch.dylib             	0x00000002353d4308 _dispatch_call_block_and_release + 32 (init.c:1372)
7   libdispatch.dylib             	0x00000002353d5888 _dispatch_client_callout + 20 (object.m:511)
8   libdispatch.dylib             	0x00000002353e173c _dispatch_main_queue_callback_4CF + 1012 (inline_internal.h:2441)
9   CoreFoundation                	0x0000000235956734 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1813)
10  CoreFoundation                	0x00000002359513e4 __CFRunLoopRun + 1888 (CFRunLoop.c:3113)
11  CoreFoundation                	0x0000000235950964 CFRunLoopRunSpecific + 452 (CFRunLoop.c:3247)
12  GraphicsServices              	0x0000000237b91d8c GSEventRunModal + 108 (GSEvent.c:2245)
13  UIKitCore                     	0x0000000262ded758 UIApplicationMain + 216 (UIApplication.m:4353)
14  TubePlayer                     	0x0000000100f24134 main + 68 (FilterViewController.swift:18)
15  libdyld.dylib                 	0x000000023540cfd8 start + 4

@poholo
Copy link
Author

poholo commented Sep 6, 2019 via email

@chaocharleswang
Copy link

@poholo 现在有的数据是前者和后者之间相比为15:1

@mengzhe360
Copy link

https://git.dev.tencent.com/lp_mr/MCIJKPlayer.git
已做优化,看看是否还是有同样的问题。

请问作者 这个能支持播放https 和MP4格式的么

@poholo
Copy link
Author

poholo commented Sep 6, 2019 via email

@mengzhe360
Copy link

mengzhe360 commented Sep 6, 2019 via email

@mengzhe360
Copy link

mengzhe360 commented Sep 6, 2019 via email

Copy link

@panzhenAlex panzhenAlex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更改player的frame 会crash

@poholo
Copy link
Author

poholo commented Dec 3, 2019

https://github.com/poholo/MCPlayerKit 用这个测试一下

@mengzhe360
Copy link

mengzhe360 commented Dec 5, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.