Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download (stream) not raising events / closing file #344

Closed
fabricedupre opened this issue Sep 5, 2023 · 24 comments
Closed

Download (stream) not raising events / closing file #344

fabricedupre opened this issue Sep 5, 2023 · 24 comments

Comments

@fabricedupre
Copy link

fabricedupre commented Sep 5, 2023

Hello,

Only event I receive is PropertyChanged with Duration.
I never get any PropertyChanged with DownloadPercentage or CurTime, or any DownloadCompleted.
And BTW, target file is created but not closed until I close the window.

@SuRGeoNix
Copy link
Owner

@fabricedupre I cannot help without seeing your code. Did you check the downloader sample which works fine?

@fabricedupre
Copy link
Author

Here it is... Please note that Videostream is similar to the one I use (without issue) in Player.OpenAsync(Videostream);

    private async void mnuSave_Click(object sender, System.EventArgs e)
    {
        Config Config = new Config();
        Config.Demuxer.BufferDuration = 60 * 1000 * 10000;  // 60 seconds should be enough to allow max download speed
        Config.Demuxer.ReadTimeout = 60 * 1000 * 10000;     // 60 seconds to retry or fail
        Config.Video.MaxVerticalResolutionCustom = 1080;    // Default Plugins Suggest based on this

        Downloader Downloader = new Downloader(Config);

        Downloader.DownloadCompleted += (_sender, _e) =>
        {
            System.Diagnostics.Trace.WriteLine(!_e ? "Download Failed" : (Downloader.DownloadPercentage == 100 ? "Download Completed" : "Download Completed (Partial)"));
        };

        Downloader.PropertyChanged += (_sender, _e) =>
        {
            switch (_e.PropertyName)
            {
                case "Duration":
                case "CurTime":
                    System.Diagnostics.Trace.WriteLine($"{(new TimeSpan(Downloader.CurTime)).ToString(@"hh\:mm\:ss")}/{(new TimeSpan(Downloader.Duration).ToString(@"hh\:mm\:ss"))}");
                    break;
                case "DownloadPercentage":
                    System.Diagnostics.Trace.WriteLine($"{(int)Downloader.DownloadPercentage}%");
                    break;
            }
        };

        Downloader.Open(Videostream);

        SaveFileDialog sfd = new SaveFileDialog()
        {
            Filter = "Media files (*.avi)|*.avi|All files (*.*)|*.*",
            RestoreDirectory = true,
            FileName = "test.avi",
        };
        if (sfd.ShowDialog() != DialogResult.OK)
            return;

        string filename = sfd.FileName;
        Downloader.Download(ref filename, false);
    }
}

@SuRGeoNix
Copy link
Owner

SuRGeoNix commented Sep 6, 2023

What about logs? Do you see anything there? (What is the Videostream? oh the new System.IO.Stream you asked ok)
Update: Just tested and worked fine with System.IO.Stream

try to use this:-

string filename = "test1";
Downloader.Download(ref filename, true); 

Does the Videostream contain valid media data? You will need to manually close it at the end.

@fabricedupre
Copy link
Author

1- trying with
string filename = @"c:\test"; // sfd.FileName;
Downloader.Download(ref filename, true);
=> same

2- debug content
11.46.24.626 | Info | [FlyleafEngine] Audio Devices
{0.0.0.00000000}.{8031cf08-78bf-4b5d-9348-a19f9d5d68cf} | U28D590 (NVIDIA High Definition Audio)
{0.0.0.00000000}.{85430695-fcd9-486d-a25e-1dd65a406d0a} | Headphone (Plantronics Savi 8200 Office Series) *
{0.0.0.00000000}.{a5442a95-9990-4208-88b5-e5202c9bf058} | U32J59x (NVIDIA High Definition Audio)
{0.0.0.00000000}.{cfcd250a-e33b-4cd7-a6cb-60ea062a665e} | Speakers (Realtek(R) Audio)
{0.0.0.00000000}.{d345656a-a47e-4826-b872-183ab1ed54e2} | Headphones (Realtek(R) Audio)

11.46.24.650 | Info | [FlyleafEngine] FlyleafLib 3.7.22
11.46.24.744 | Info | [FlyleafEngine] Loading FFmpeg libraries from ':FFmpeg'
11.46.25.233 | Info | [FlyleafEngine] FFmpeg Loaded (Location: C:\PE\Dev CY\CYManager\FFmpeg, Ver: 59.27.100) [Devices: no, Filters: yes]
11.46.25.354 | Info | [FlyleafEngine] GPU Adapters
[#1] Intel Intel(R) UHD Graphics [ID: 18056 , LUID: 149847, DVM: 128 MB , DSM: 0 B , SSM: 31.8 GB]
[#2] NVIDIA NVIDIA RTX A3000 12GB Laptop GPU [ID: 9401 , LUID: 151759, DVM: 11.85 GB, DSM: 0 B , SSM: 31.8 GB]
[#3] Unknown Microsoft Basic Render Driver [ID: 140 , LUID: 151705, DVM: 0 B , DSM: 0 B , SSM: 31.8 GB]

11.46.25.492 | Info | [FlyleafEngine] Plugin loaded (OpenDefault - 3.7.22.0)
11.46.25.492 | Info | [FlyleafEngine] Plugin loaded (OpenSubtitles - 3.7.22.0)
11.46.25.492 | Info | [FlyleafEngine] Plugin loaded (StreamSuggester - 3.7.22.0)
11.46.25.492 | Info | [FlyleafEngine] [PluginHandler] No external plugins found
11.46.25.497 | Info | [FlyleafEngine] Thread started
11.48.08.033 | Debug | [#1] [Downloader] Stopped -> Opening
11.48.08.040 | Info | [#1] [PluginHandler ] [OpenDefault] Open Success
11.48.08.040 | Info | [#1] [PluginHandler ] SuggestItem #0 - Custom IO Stream
11.48.08.042 | Info | [#1] [PluginHandler ] [OpenDefault] Open Item (0) Success
11.48.08.060 | Debug | [#1] [Demuxer: Main] Stopped -> Opening
11.48.08.068 | Debug | [#1] [Demuxer: Main] Ignoring format option reconnect
11.48.08.068 | Debug | [#1] [Demuxer: Main] Ignoring format option reconnect_streamed
11.48.08.068 | Debug | [#1] [Demuxer: Main] Ignoring format option reconnect_delay_max
11.48.08.068 | Debug | [#1] [Demuxer: Main] Ignoring format option user_agent
11.48.08.068 | Debug | [#1] [Demuxer: Main] Ignoring format option rtsp_transport
11.48.08.121 | Info | [#1] [Demuxer: Main] Format Context Info
[Format ] AVI (Audio Video Interleaved)/avi | avi | 00:00:00/00:08:02.5000000 | 00:00:00/00:08:02.5000000
[Video #0] scpr bgr0 1920x1080 @ 4 | [Color: BT709] [BR: 23468] | 00:00:00/00:08:02.5000000 | 00:00:00/00:08:02.5000000

3- I can only close the stream when I get the DownloadCompleted event :-)

@SuRGeoNix
Copy link
Owner

For some reason it seems that it does not open/add the stream(s).

Try this, before Downloader.Download:-

Downloader.DecCtx.VideoDemuxer.EnableStream(Downloader.DecCtx.VideoDemuxer.VideoStreams[0]);

@fabricedupre
Copy link
Author

Not any better:
12.28.19.075 | Info | [FlyleafEngine] Audio Devices
{0.0.0.00000000}.{8031cf08-78bf-4b5d-9348-a19f9d5d68cf} | U28D590 (NVIDIA High Definition Audio)
{0.0.0.00000000}.{85430695-fcd9-486d-a25e-1dd65a406d0a} | Headphone (Plantronics Savi 8200 Office Series) *
{0.0.0.00000000}.{a5442a95-9990-4208-88b5-e5202c9bf058} | U32J59x (NVIDIA High Definition Audio)
{0.0.0.00000000}.{cfcd250a-e33b-4cd7-a6cb-60ea062a665e} | Speakers (Realtek(R) Audio)
{0.0.0.00000000}.{d345656a-a47e-4826-b872-183ab1ed54e2} | Headphones (Realtek(R) Audio)

12.28.19.133 | Info | [FlyleafEngine] FlyleafLib 3.7.22
12.28.19.154 | Info | [FlyleafEngine] Loading FFmpeg libraries from ':FFmpeg'
12.28.19.250 | Info | [FlyleafEngine] FFmpeg Loaded (Location: C:\PE\Dev CY\CYManager\FFmpeg, Ver: 59.27.100) [Devices: no, Filters: yes]
12.28.19.310 | Info | [FlyleafEngine] GPU Adapters
[#1] Intel Intel(R) UHD Graphics [ID: 18056 , LUID: 149847, DVM: 128 MB , DSM: 0 B , SSM: 31.8 GB]
[#2] NVIDIA NVIDIA RTX A3000 12GB Laptop GPU [ID: 9401 , LUID: 151759, DVM: 11.85 GB, DSM: 0 B , SSM: 31.8 GB]
[#3] Unknown Microsoft Basic Render Driver [ID: 140 , LUID: 151705, DVM: 0 B , DSM: 0 B , SSM: 31.8 GB]

12.28.19.513 | Info | [FlyleafEngine] Plugin loaded (OpenDefault - 3.7.22.0)
12.28.19.513 | Info | [FlyleafEngine] Plugin loaded (OpenSubtitles - 3.7.22.0)
12.28.19.513 | Info | [FlyleafEngine] Plugin loaded (StreamSuggester - 3.7.22.0)
12.28.19.513 | Info | [FlyleafEngine] [PluginHandler] No external plugins found
12.28.19.522 | Info | [FlyleafEngine] Thread started
12.29.21.922 | Debug | [#1] [Downloader] Stopped -> Opening
12.29.21.928 | Info | [#1] [PluginHandler ] [OpenDefault] Open Success
12.29.21.928 | Info | [#1] [PluginHandler ] SuggestItem #0 - Custom IO Stream
12.29.21.930 | Info | [#1] [PluginHandler ] [OpenDefault] Open Item (0) Success
12.29.21.941 | Debug | [#1] [Demuxer: Main] Stopped -> Opening
12.29.21.947 | Debug | [#1] [Demuxer: Main] Ignoring format option reconnect
12.29.21.947 | Debug | [#1] [Demuxer: Main] Ignoring format option reconnect_streamed
12.29.21.947 | Debug | [#1] [Demuxer: Main] Ignoring format option reconnect_delay_max
12.29.21.948 | Debug | [#1] [Demuxer: Main] Ignoring format option user_agent
12.29.21.948 | Debug | [#1] [Demuxer: Main] Ignoring format option rtsp_transport
12.29.22.008 | Info | [#1] [Demuxer: Main] Format Context Info
[Format ] AVI (Audio Video Interleaved)/avi | avi | 00:00:00/00:04:54.7500000 | 00:00:00/00:04:54.7500000
[Video #0] scpr bgr0 1024x768 @ 4 | [Color: BT709] [BR: 42000] | 00:00:00/00:04:54.7500000 | 00:00:00/00:04:54.7500000

12.29.22.008 | Debug | [#1] [Demuxer: Main] Opening -> Stopped

@fabricedupre
Copy link
Author

Forgot to mention that file is created and video properly exported, only events are not raised

@SuRGeoNix
Copy link
Owner

SuRGeoNix commented Sep 6, 2023

The problem seems to be the bgr0 which is raw format (this is not an avi). The downloader currently works only with proper formats (no raw data) as it will require to transcode/transmux which is not currently implemented.

@fabricedupre
Copy link
Author

But file is properly generated, only it is not properly closed and no event is sent.
That's weird !? Any workaround until transcode/transmux is implemented ?

@SuRGeoNix
Copy link
Owner

SuRGeoNix commented Sep 6, 2023

The file that it creates is just the file with the headers and not the data as it does not enable any stream and does not write any packets. Unfortunately there is no workaround for that, input format should be able to transmux to output format (so codecs should be supported by the output format). Maybe you could try with .raw extension or check FFmpeg which format supports bgr0 (if any). Still not sure why you don't see any errors though.

You should also see that the demuxer opens the video stream (0) ... you will need to debug it. Maybe something else is the issue.

@fabricedupre
Copy link
Author

fabricedupre commented Sep 6, 2023

Then, how can it be that I can play the file properly ?

@SuRGeoNix
Copy link
Owner

SuRGeoNix commented Sep 6, 2023

which file, the output file? Can you give me anydesk access to debug it quickly? :) Try trace log

@fabricedupre
Copy link
Author

Couple things:
a/ I cannot play the file anymore (I can swear I could before)
b/ I am using NuGet package so can not debug, will switch to local version
c/ not sure anydesk will pass the firewall
d/ video is using SCPR codec

@SuRGeoNix
Copy link
Owner

@fabricedupre No worries, probably is the reason that I've mention already. But if you want to debug it you could download the code from here and include FlyleafLib project to your solution and instead of pointing the NuGet you can point the project.

@fabricedupre
Copy link
Author

Here is what I managed to achieve by breaking on Downloader.cs line 307 and pressing F5 couple times:
00:01:00/00:10:02
10%
00:01:35/00:10:02
15%
00:01:35/00:10:02
15%
00:01:35/00:10:02
15%
00:01:36/00:10:02
15%
00:01:36/00:10:02
16%
00:01:37/00:10:02
16%
00:01:38/00:10:02
16%
00:01:38/00:10:02
16%
00:01:39/00:10:02
16%
00:01:40/00:10:02
16%
00:01:41/00:10:02
16%
00:01:42/00:10:02
17%
00:01:43/00:10:02
17%
00:01:44/00:10:02
17%
00:01:46/00:10:02
17%
00:01:47/00:10:02
17%
00:01:48/00:10:02
18%
00:01:49/00:10:02
18%
00:01:51/00:10:02
18%
00:01:52/00:10:02
18%
00:01:53/00:10:02
18%
00:01:54/00:10:02
19%
00:01:55/00:10:02
19%
00:01:57/00:10:02
19%
00:01:58/00:10:02
19%
00:01:59/00:10:02
19%
00:02:00/00:10:02
20%
00:02:01/00:10:02
20%
00:02:03/00:10:02
20%
00:02:04/00:10:02
etc...

As soon as I remove the breakpoint on line 307 and set it on line 309... nothing happens anymore !
Getting the below output:
The thread '.NET ThreadPool Worker' (0x2ae0) has exited with code 0 (0x0).
The thread '.NET ThreadPool Worker' (0x10158) has exited with code 0 (0x0).
The thread '.NET ThreadPool Worker' (0xf90c) has exited with code 0 (0x0).
The thread '.NET ThreadPool Worker' (0x168e0) has exited with code 0 (0x0).

And log file:
log.txt

Repository owner deleted a comment from fabricedupre Sep 6, 2023
Repository owner deleted a comment from fabricedupre Sep 6, 2023
@SuRGeoNix
Copy link
Owner

sry @fabricedupre, that does not really help

@fabricedupre
Copy link
Author

In fact, once Demuxer.Packets.Count == 0, the while loop at line 207 never ends
By forcing Demuxer.Status = Status.Ended, aka going to line 211, everything works !
File created, closed and playable.
Now the question is why is Demuxer not entering Status.Ended state ?

@SuRGeoNix
Copy link
Owner

Check the threads (and mainly the Demuxer) when it freezes to see why the demuxer waits

@SuRGeoNix
Copy link
Owner

SuRGeoNix commented Sep 6, 2023

@fabricedupre Just had another look, trying to guess your issue... Try to replace in this line the AVERROR_EXIT with AVERROR_EOF

Update: Actually more important change the < 0 to <= 0 (I will do more testing tomorrow as I think that this is indeed an issue with the custom IO streams)

@fabricedupre
Copy link
Author

Same behavior :-(
What is the purpose of #if NETFRAMEWORK ? Actually it is not defined...

SuRGeoNix added a commit that referenced this issue Sep 7, 2023
…tical flipping

CustomIOContext: Fixes a critical issue with the EOF (read bytes = 0) which could cause the demuxer to freeze (Fixes #344)
@SuRGeoNix
Copy link
Owner

@fabricedupre it should be fixed with master now, I was able to find a SCPR sample and reproduce the issue. Found also another one with negative linesizes which could crash the player. If you can't tested from master I will have soon an update NuGet package.

@fabricedupre
Copy link
Author

Great !
Works like a charm (both Master / NuGet pkg)
Do you have any plan/timeframe when you gonna release transcode/transmux ?

@SuRGeoNix
Copy link
Owner

I've some progress with FlyleafLib v4 which will support those but to be honest I was planning it by the end of the year, not sure if I will manage this.

@fabricedupre
Copy link
Author

Good luck !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants