PlayerFramwork and Memory

Jan 24, 2015 at 3:27 PM
Hi,
I decided to Update my apps to universal. I had been using the available version on 26/07/2014. I published Apps on December and I have received a lot of messages with problems of memory. So I did a diagnostic of RAM and I saw a lot of objects that weren't deleted when I did "frame.goback()". I thought that it may be the old version of your library, so I have updated to the published version of yesterday. And now I have two problems:
-The video is interrupted because of ¿? I think the buffer is enough. How do I solve it?
-The objects aren't destroyed when I go back.
Could you help me with those problems?
Thank you again.
Coordinator
Jan 25, 2015 at 1:40 AM
Edited Jan 29, 2015 at 2:48 PM
Are you doing something based on HlsView or SamplePlayer?

The reason your video is interrupted was garbled (I'm just seeing an upside down question mark). Could you clarify what that was supposed to be?

The buffering is controlled by IBufferingPolicy. There is some more information about the DefaultBufferingPolicy implementation in my first post in this thread.

Do you have something like HlsView's OnNavigatedFrom handler?

Thanks.
Jan 26, 2015 at 10:11 PM
Hi Henric,
Sorry by my bad explication. I have too things on my head those days. My apps are based on SamplePlayer. When I update your library to the last versión, I use the default configuration so It behaviours as you explain on the post of the thread that you have commented me. Ok, I try to solve it as you have described. But my main problem is the memory. I'm going to explain my App at general level in order to know as I have made it and you can help me easily.
The users navigate between two frames mainly: the main and the player. There are a list channels (90 approximately), so users click on the first channel, and when they are boring of watching it, they go back and select other channel. On summary, they do "zapping" (does this word exist on English?).
So I have revised the objects that are on memory (alt+f2) after that I have watched for example 15 channels and there are 15 autofac, 15 playerFramework, 15 SM.... If you need a screenshot of the diagnosis, said me. Then, I thought that I have done bad something, I checked your sample and I have introduce the code for clean:
playerframework.stop();
playerframwork.source=null;
playerframwork.source=uri_for_stop;
playerframwork.source=null;
But it don't solve it. what should I do more in order to liberate it of memory? do you need more information?
Thank you again
Coordinator
Jan 26, 2015 at 11:34 PM
To change streams, it should be enough to do what is in MainPage's UpdateSource() (set player.Source to null and then the next URL, to avoid a quirk in Player Framework). Since you are navigating away, the stop is probably a good idea (setting the "stop url" is mean to block until the previous stream has finished cleaning up).

It has been a while since I've checked for object leaks here. Do you happen to know the GC root that is keeping these instances alive? Since you are seeing multiple instances of player framework, are you also seeing multiple instances of your page object? There might be something useful in the PF samples.

Another thing you might try: when changing channels, do everything but actually starting playback (e.g., use "null" for all the URLs). Are there still leaks?
Jan 27, 2015 at 9:47 PM
About the objects on memory, I have searched examples in the “PF samples” website and I have found "playerframework.dispose();" and now the objects of player, itempage, SM, autofac,... have disappeared. I have to call it in “OnNavigatedFrom”. I have to test more deeply but it seems that sounds good. :)
I have tried to implement the new policy buffer but I haven't know where I should set my new object of type "defaultBufferingPolicy" on SM. Could you give a clue, please?
Thank you again.
Coordinator
Jan 27, 2015 at 10:55 PM
Ok, good to know about the .Dispose().

With regard to IBufferingPolicy, take a look at how _bufferingPolicy is used in SM.Media.BackgroundAudio.WP81's MediaPlayerManager::
        void InitializeMediaStream()
        {
            if (null != _mediaStreamFacade)
                return;

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

            _mediaStreamFacade.SetParameter(_bufferingPolicy);

            _mediaStreamFacade.SetParameter(_mediaManagerParameters);

            _mediaStreamFacade.StateChange += MediaStreamFacadeOnStateChange;
        }
Jan 29, 2015 at 11:22 AM
Hi again,
Then I had understood correctly your other thread. But I can't get the function "create()" on MediaStreamFacadeSettings.Parameters; there are available the following functions:
-Equals
-Factory
-GetHasCode
-GetType
-ToString
-UseHttpConection
What have I made bad?
In addition, I test 20 channels approximately and the problem of buffering is in some channels. And those channels usually stop of playing at 19 or 49 seconds and wait for 10 seconds approximately and continue without stopping. I have selected two channels in order to find the difference and one doesn't say the bandwidth and the other contents this information. So, the problem is that the IBufferingPolicy can't know at the begging what is the bandwidth of stream so it produce this problems.
Then, does this problem solve with a new BufferingPolicy?
I have tested more deeply the app and now it works correctly without objects on memory.
Thank you again
Coordinator
Jan 29, 2015 at 2:47 PM
The Create() method is implemented in the platform-specific code as an extension method. It is the thing that actually creates the platform-specific MediaStreamFacade instance. Note that MediaStreamFacade.Builder is the DI container (see IMediaStreamFacadeBase), so it is not available to create a MediaStreamFacade factory (a "chicken or egg" problem).

The actual implementation of the "Create()" is in DefaultMediaStreamFacadeParameters and looks like this:
    public static class DefaultMediaStreamFacadeParameters
    {
        public static Func<IMediaStreamFacadeBase> Factory =
            () =>
            {
                var mediaStreamFacade = new MediaStreamFacade();

                return mediaStreamFacade;
            };

        public static IMediaStreamFacade Create(this MediaStreamFacadeParameters parameters)
        {
            var factory = parameters.Factory ?? Factory;

            return (IMediaStreamFacade)factory();
        }
    }
While the same SM.Media.Platform.WP7/DefaultMediaStreamFacadeParameters.cs source file is used on all the platforms, both IMediaStreamFacade and MediaStreamFacade are defined at the platform level.

For finding the implementation of the "Create()", I would put my cursor on the name where it is used and hit F12 to jump right to it (this may be a ReSharper thing).

With regard to the stream problem:

From your earlier posts, I assume this something along the lines of SamplePlayer.Win81/WP81? Does this behave the same on phone and desktop/tablet? Which version of phonesm are you using? Are you using HttpConnection or HttpClIent (the UseHttpConnection parameter changes the default)?

The exact bandwidth isn't terribly important, but the default parameters assume around 64kbit (IIRC), so if you are playing 4Mbit video streams, the buffering manager will not allow enough memory to be used and there will be a flood of buffering-related messages in the debug output window.

The symptoms you describe remind me of something I was looking at earlier this week related to how the HLS playlist is refreshed and where in the playlist playback should start: if you are playing live HLS streams, then you might want to take a look at 16ee994eb012.

You might also try increasing DefaultBufferingPolicy's DurationStartingDone.
Feb 2, 2015 at 3:02 PM
Hi henric,
As you said me that had been working it recently, I updated again from 23/01/15 to 29/01/15 available version and I has been testing those days and it works correctly on both platforms with parameters by default.
Thank you again