BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.21k stars 4.61k forks source link

Always crash when play movie by using GPUImageMovie on iphone 5s 10.1.1 #2571

Open suixinsam opened 6 years ago

suixinsam commented 6 years ago

In my case, I play movie when app on foreground, when app switch to background mode, I need to stop playing. So when the movie is going to be played, switch to background mode immediately, then it crashed.

I played movie by url.

I debug the code, found it crashed in the function startProcessing :

[inputAsset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler: ^{
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSError *error = nil;
            AVKeyValueStatus tracksStatus = [inputAsset statusOfValueForKey:@"tracks" error:&error];
            if (tracksStatus != AVKeyValueStatusLoaded)
            {
                return;
            }
            blockSelf.asset = inputAsset;
            [blockSelf processAsset];
            blockSelf = nil;
        });
    }];

I figured out that the loadValuesAsynchronouslyForKeys too slow cause this kind of crash. In my case, I already called the endProcessing to stop playing, but the loading for asset is too slow on iPhone 5s 10.1.1, the completionHandler of loading is delayed.

In my opinion, there should create a mechanism to stop processing immediately to avoid this case. such as a reversible atomic process to stop processing immediately.

Cause this issue only occurred on old device on its highest os version, maybe this issue is unnecessary to be fix, just a reminder for someone who encounter same issue with me.

I used subclass with method swizzling for processAsset and readNextVideoFrameFromOutput methods to resolve this issue temporarily.

Hope this clue will help to solve the bad performance caused issue on iphone 5/5s/5c of its 10.1.1+ os version