What is mediaserverd actually responsible for?

I'm working on an app that uses the Video Toolbox for 264 decoding and uses OpenGL for presentation of the frames. Most of the time, everything works fine. But occassionally, the app will get killed for being out of memory. Watching the app in Instruments, it's pretty clear that the memory usage of the app itself is fine (around 10MB, pretty consistently). In fact, everything looks fine up until everything being jetisoned. In the crash log, the app itself looks okay memory wise (still around 10MB), but mediaserverd has jumped from it's normal 5-6MB of RAM to almost 100MB. According to the report, it has the largest footprint in memory. If I then reconnect Instruments afterwards, mediaserverd has dropped back down to it's normal 5-6MB range again.


So what I'm wondering is this -- is there some connection between my usage of Video Toolbox, OpenGL or some other API and the memory usage in mediaserverd? Is there some error condition that I might not be handling correctly that would lead to something like this? What tasks does mediaserverd actually handle on the system?

Warning, Im not from Apple, nor do I have any insight other than what ive gleaned from working with AVF on desktop and on iOS.


My understanding is that mediaserverd handles vending and recieveing IOSurface backed pixel buffers from the camera, video encoder and video decoder, audio, jpeg encoder and png encoder. mediaserverd also handles setting up your camera controls, playing movies and what not.


This is why there is asynchronous key value loading and latency, and threading concerns because of the IPC mechanisms being employed for AVFoundation to talk to mediaserverd on your behalf (and to send respondes from mediaserverd back).


Ive had issues where ive done stupid things, or maybe found a weird bug in medaiserver accidentally, and had jpeg decoding in my app die because, well, we crashed the hardware decoder, etc.


Basically, mediaserverd asyncrhonously conducts media on the device and negotiates between multiple app's encoding, playback and what not sessions.

Oh and in regard to mediaserverd memory and things, you can do stuff like retain pixel buffers vended to you by the camera, or movie playback indefinitely and watch mediaserver d try to cope by making its internal pixel buffer pool larger to accomodate, etc.


There is a 1:1 correlation between hammering on media services and what medaiserverd is doing, cpu and memory wise.

So after a few weeks of not being able to work on this, I finally found the root cause of my particular issue. In my case, it turned out not to be mediaserverd -- my app had it's own memory leak as well (just a few OpenGL contexts 😉), which was causing the OOM crash. My theory as to why mediaserverd showed a lot of memory usage is that the pipeline of images from the 264 decoder and my app was stalled while my app was being killed.


Thanks for the explanation about mediaserverd, though. It was still very helpful in rulling out what wasn't going wrong in my app.

What is mediaserverd actually responsible for?
 
 
Q