Theme kills the OS

I am currently programming an application that extracts frames from a clip. I designed it so that the extraction is done in a separate thread to prevent the application from freezing. The extraction process itself takes up a lot of resources, but works great when used in a simulator. However, there are problems creating the iPad for the iPad. When I perform another action (I say that my AV player plays while I extract frames), the stream unexpectedly stops working, and I believe that it is killed.

I guess this is because I use a lot of resources, but not quite sure.

Here are my questions: 1. How can I tell if / why my thread stops? 2. If it is really due to processing, what should I do? I really need this action to be implemented.

Here is the code used: To create a stream:

[NSThread detachNewThreadSelector:@selector(startReading) toTarget:self withObject:nil];

I will send you any information, Thank you very much!

Update Now I am using GCD, and it fills topics for me. However, the OS still kills threads.

I know exactly when this happens. when I talk about my [game AVplayer]; he kills the stream.

This problem occurs only on a real iPad, not on a simulator.

+6
source share
3 answers

It seems to me that you are trying to simultaneously decode two video clips. Due to the hardware-decoding nature of the iPad, it can only support one decoding process at a time. When you play a new item, the old one will be canceled. This explains why it works in the simulator, but not on the device.

As for the solution, you can switch to a clean software decoder like libav (GPL) or CoreAVC SDK (commercial). This way you will not interfere with the HW decoder for playback.

+1
source

When something works in the simulator and does not work on the device, one obvious explanation is the problem of resource limitations. But sometimes the simulator cannot accurately simulate other aspects of the device. So I wondered if there could be any other interpretation of the situation. It seemed to me that this could be a competition for limited access to AV Asset assets - this means that when you start playing it, it is no longer available for processing (and for some reason, an error in the simulator does not display this restriction.)

In the AV Foundation's Programming Assets Play section, Apple states:

Although you ultimately want to play the asset, you are not providing assets directly to the AVPlayer object. Instead, you provide an instance of AVPlayerItem. A player element controls the state of the presentation of the object with which it is associated. A player element contains player tracks — instances of AVPlayerItemTrack that correspond to tracks in the asset.

This abstraction means that you can play a given asset using different players at the same time, but each player can play them differently. Using element tracks, you can, for example, turn off a specific track during playback (you may not want to play the audio component).

So, I thought: are you using AVPlayerItems to access your assets, which would allow both operations at the same time? If so, then at least that particular direction is excluded. But if not, it may be worth exploring to fix the problem.

May be clutching at a straw. But maybe somewhere ahead.

0
source

The "Adjusting the thread stack size" section of the Apple Threading Programming Guide on page 27 says:

On iOS and Mac OS X v10.5 and later, allocate and initialize an NSThread Object (do not use the detachNewThreadSelector: toTarget: withObject: method)

Despite the fact that on page 22 it says that detachNewThreadSelector is one way to create threads using NSThread.

And he gives this example on page 23 on how to start your thread:

 NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(myThreadMainMethod:) object:nil]; [myThread start]; 

According to the manual, which will create a separate file in your application. Try creating a stream this way and see if the OS stops killing your stream.

For reference: reference to manual

http://developer.apple.com/library/ios/iPad/#documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/10000057i-CH15-SW2

Page 29 also mentions that if your application uses the managed memory model that you seem to have, creating an autostart pool in your thread input routine should be the first thing you do and similarly destroy that last one that your thread does. sure that this will not destroy your thread, but make sure you do it.

Having a try / catch block in your thread input routine may not solve the killing problem, but you will avoid your application exit if an error occurs in your thread.

I forgot to mention this other design tip that can help you with resource constraints, as Duncan noted. According to the manual p. 18:

Avoid common data structures

The easiest and easiest way to avoid conflicts associated with a resource stream is to give each stream in your program its own copy of any data that it needs. Parallel code works best when you minimize communication and resources among your threads.

Which, I think, you can do it in your application. In addition to what Duncan mentioned, “do not provide assets directly to the AVPlayer object, but instead provide an instance of AVPlayerItem”, do this by creating separate instances for each of your streams, one instance of AVPlayerItem for the player’s stream and one instance of AVPlayerItem for the extraction stream .

0
source

Source: https://habr.com/ru/post/900974/


All Articles