Code Monkey home page Code Monkey logo

Comments (17)

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

I will try to create a proper stop even if flyleaf does not use it currently. In the meantime, have a look at MediaRouter.cs to free the queue frames (ClearVideoFrames). also in case of sws maybe you should also clean some buffers there in MediaDecoder.cs (outBufferPtr something). - Or just try to initialize both MediaRouter.cs and MediaDecoder/DecoderContexts -

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

I'm closing this, let me know if the new code done the job for you. In any case I'll not stop at the end for now, I will let the user choose whether to close it or re-seek / play

from flyleaf.

synologic avatar synologic commented on July 26, 2024

Any progress on this ?

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

@synologic That's an old thread. What is your issue? If you want to release the memory at the end of a video you need to call Player.Stop()

from flyleaf.

synologic avatar synologic commented on July 26, 2024

It is an old one yes :)
I am calling Player.Stop() however the memory is not freed and last frame remains on the player surface.
I'm using 3.4.7 from Nuget

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

Just tested again and it works fine (Sample on WinForms - Form1.cs)

using FlyleafLib;
using FlyleafLib.MediaPlayer;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        Player Player { get; set; }
        public Form1()
        {
            Engine.Start(new EngineConfig()
            {
                FFmpegPath = @"c:\root\projects\Flyleaf\FFmpeg"
            });

            InitializeComponent();
            Player = new Player();
            Player.Control = flyleaf1;

            Player.Open(@"C:\root\dev\flyleaf\videosamples\0.mp4");
            Player.PlaybackCompleted += (o, e) =>
            {
                Player.Stop();
            };
        }
    }
}

from flyleaf.

synologic avatar synologic commented on July 26, 2024

Maybe i should have mentioned, if it makes any difference. I'm playing a live RTSP stream, not a file and not waiting for completion.

I just call .Stop() in order to stop video or load another live stream.

Not sure if that changes anything :)

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

Yes, that makes a lot of difference :)

There is already an investigation from one of my users that has issues (memory leaks - not video memory). It could be an ffmpeg bug (with udp protocol). However, I was not able to reproduce it yet. I just tried this one https://www.wowza.com/developer/rtsp-stream-test. Does this leak for you?

from flyleaf.

synologic avatar synologic commented on July 26, 2024

I just upgraded to 3.4.9 and the memory gets freed once GC runs after .Stop() so that's that :)

The last frame still stays on the screen, for both Wowza's and my stream.

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

There is no difference between 3.4.7 and 3.4.9. Additionally, on my side I don't need to call GC to clear the memory.
Player.Stop clears the frame (leaves a black frame) and the memory, not sure what are you doing.

from flyleaf.

synologic avatar synologic commented on July 26, 2024

Not doing anything fancy:
public Form1()
{
InitializeComponent();

        Engine.Start(new EngineConfig()
        {
            FFmpegPath = ":",
            UIRefresh = true,
            UIRefreshInterval = 250
        });

        // Prepares Player's Configuration
        Config = new Config();
        Config.Player.KeyBindings.Enabled = false;

        Player = new Player(Config);

        Player.Control = flyleaf1;
        Player.Tag = "player1";

        Player.PropertyChanged += playerPropertyChanged;
    }

Then i just call OpenAsync("RTSP_STREAM") and when i'm done i just call .Stop().

The only other difference, between the wowza and my stream, is that i'm using H265

What i meant about the GC is that, once i call Stop() i see the memory being freed after a few seconds, so i assumed is the GC that frees it :)

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

Is it possible that you call Player.Stop before it actually Player.OpenAsync completes?
Do you see any difference between wowza and your stream and you mention the different codec?
I don't force GC on Player.Stop it's true. I do this only on Dispose. But I guess it is not required there.

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

You can try the same code that I use to see if we have any difference:
Opens/Plays/Stops check if you see the black frame in between

using FlyleafLib;
using FlyleafLib.MediaPlayer;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        Player Player { get; set; }
        public Form1()
        {
            Engine.Start(new EngineConfig()
            {
                FFmpegPath = @"c:\root\projects\Flyleaf\FFmpeg"
            });

            Player = new Player();
            InitializeComponent();
            Player.Control = flyleaf1;

            Task.Run(() =>
            {
                while (true)
                {
                    Player.Open(@"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4");
                    Thread.Sleep(5000);
                    Player.Stop();
                    Thread.Sleep(5000);
                }
            });
        }
    }
}

from flyleaf.

synologic avatar synologic commented on July 26, 2024

I'm sorry, but still the same thing.
I even upgraded to VS 2022 and migrated the solution to .NET 6, however it's the same thing, the last frame stays on screen after .Stop() is called

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

Well reviewing the code it could be possible, however not sure why it happens to you every time and it never happens to me. I will fix it with the next update ;)

from flyleaf.

synologic avatar synologic commented on July 26, 2024

Not sure, may be Windows 11 related issue, i can live with it, or maybe there's a way i can directly paint something on the surface after stop ? :)

from flyleaf.

SuRGeoNix avatar SuRGeoNix commented on July 26, 2024

Possible, with Player.Control you could mess with the background refresh/paint etc. But, I think I found the problem and it will be fixed with the next update. I'm disposing the lastframe after I refresh the renderer and it just happens to be null most of the times (for me).

from flyleaf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.