Example #1
0
        private void FinalAnalysis()
        {
            //some quick checks:
            if (OUT_CompiledCueFiles.Count == 0)
            {
                Error("Cue file doesn't specify any input files!");
            }

            //we can't reliably analyze the length of files here, because we might have to be decoding to get lengths (VBR mp3s)
            //REMINDER: we could actually scan the mp3 frames in software
            //So, it's not really worth the trouble. We'll cope with lengths later
            //we could check the format of the wav file here, though

            //score the cost of loading the file
            bool needsCodec = false;

            OUT_LoadTime = 0;
            foreach (var cfi in OUT_CompiledCueFiles)
            {
                if (cfi == null)
                {
                    continue;
                }
                if (cfi.Type == CompiledCueFileType.DecodeAudio)
                {
                    needsCodec   = true;
                    OUT_LoadTime = Math.Max(OUT_LoadTime, 10);
                }
                if (cfi.Type == CompiledCueFileType.SeekAudio)
                {
                    needsCodec = true;
                }
                if (cfi.Type == CompiledCueFileType.ECM)
                {
                    OUT_LoadTime = Math.Max(OUT_LoadTime, 1);
                }
            }

            //check whether processing was available
            if (needsCodec)
            {
                FFmpegService ffmpeg = new FFmpegService();
                if (!ffmpeg.QueryServiceAvailable())
                {
                    Warn("Decoding service will be required for further processing, but is not available");
                }
            }
        }
Example #2
0
        private void MountBlobs()
        {
            IBlob file_blob = null;

            BlobInfos = new List <BlobInfo>();
            foreach (var ccf in IN_CompileJob.OUT_CompiledCueFiles)
            {
                var bi = new BlobInfo();
                BlobInfos.Add(bi);

                switch (ccf.Type)
                {
                case CompiledCueFileType.BIN:
                case CompiledCueFileType.Unknown:
                {
                    //raw files:
                    var blob = new Disc.Blob_RawFile {
                        PhysicalPath = ccf.FullPath
                    };
                    OUT_Disc.DisposableResources.Add(file_blob = blob);
                    bi.Length = blob.Length;
                    break;
                }

                case CompiledCueFileType.ECM:
                {
                    var blob = new Disc.Blob_ECM();
                    OUT_Disc.DisposableResources.Add(file_blob = blob);
                    blob.Load(ccf.FullPath);
                    bi.Length = blob.Length;
                    break;
                }

                case CompiledCueFileType.WAVE:
                {
                    var blob = new Disc.Blob_WaveFile();
                    OUT_Disc.DisposableResources.Add(file_blob = blob);
                    blob.Load(ccf.FullPath);
                    bi.Length = blob.Length;
                    break;
                }

                case CompiledCueFileType.DecodeAudio:
                {
                    FFmpegService ffmpeg = new FFmpegService();
                    if (!ffmpeg.QueryServiceAvailable())
                    {
                        throw new DiscReferenceException(ccf.FullPath, "No decoding service was available (make sure ffmpeg.exe is available. Even though this may be a wav, ffmpeg is used to load oddly formatted wave files. If you object to this, please send us a note and we'll see what we can do. It shouldn't be too hard.)");
                    }
                    AudioDecoder dec  = new AudioDecoder();
                    byte[]       buf  = dec.AcquireWaveData(ccf.FullPath);
                    var          blob = new Disc.Blob_WaveFile();
                    OUT_Disc.DisposableResources.Add(file_blob = blob);
                    blob.Load(new MemoryStream(buf));
                    bi.Length = buf.Length;
                    break;
                }

                default:
                    throw new InvalidOperationException();
                }                 //switch(file type)

                //wrap all the blobs with zero padding
                bi.Blob = new Disc.Blob_ZeroPadAdapter(file_blob, bi.Length);
            }
        }
Example #3
0
        private void Download()
        {
            //the temp file is owned by this thread
            var fn = TempFileManager.GetTempFilename("ffmpeg_download", ".7z", false);

            try
            {
                using (var evt = new ManualResetEvent(false))
                {
                    using (var client = new System.Net.WebClient())
                    {
                        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                        client.DownloadFileAsync(new Uri(FFmpegService.Url), fn);
                        client.DownloadProgressChanged += (object sender, System.Net.DownloadProgressChangedEventArgs e) =>
                        {
                            pct = e.ProgressPercentage;
                        };
                        client.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
                        {
                            //we don't really need a status. we'll just try to unzip it when it's done
                            evt.Set();
                        };

                        for (; ;)
                        {
                            if (evt.WaitOne(10))
                            {
                                break;
                            }

                            //if the gui thread ordered an exit, cancel the download and wait for it to acknowledge
                            if (exiting)
                            {
                                client.CancelAsync();
                                evt.WaitOne();
                                break;
                            }
                        }
                    }
                }

                //throw new Exception("test of download failure");

                //if we were ordered to exit, bail without wasting any more time
                if (exiting)
                {
                    return;
                }

                //try acquiring file
                using (var hf = new HawkFile(fn))
                {
                    using (var exe = OSTailoredCode.IsUnixHost ? hf.BindArchiveMember("ffmpeg") : hf.BindFirstOf(".exe"))
                    {
                        var data = exe !.ReadAllBytes();

                        //last chance. exiting, don't dump the new ffmpeg file
                        if (exiting)
                        {
                            return;
                        }

                        DirectoryInfo parentDir = new(Path.GetDirectoryName(FFmpegService.FFmpegPath) !);
                        if (!parentDir.Exists)
                        {
                            parentDir.Create();
                        }
                        File.WriteAllBytes(FFmpegService.FFmpegPath, data);
                        if (OSTailoredCode.IsUnixHost)
                        {
                            OSTailoredCode.ConstructSubshell("chmod", $"+x {FFmpegService.FFmpegPath}", checkStdout: false).Start();
                            Thread.Sleep(50);                             // Linux I/O flush idk
                        }
                    }
                }

                //make sure it worked
                if (!FFmpegService.QueryServiceAvailable())
                {
                    throw new Exception("download failed");
                }

                succeeded = true;
            }
            catch
            {
                failed = true;
            }
            finally
            {
                try { File.Delete(fn); }
                catch { }
            }
        }
        private void Download()
        {
            //the temp file is owned by this thread
            var fn = TempFileManager.GetTempFilename("ffmpeg_download", ".7z", false);

            try
            {
                using (var evt = new ManualResetEvent(false))
                {
                    using (var client = new System.Net.WebClient())
                    {
                        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                        client.DownloadFileAsync(new Uri(FFmpegService.Url), fn);
                        client.DownloadProgressChanged += (object sender, System.Net.DownloadProgressChangedEventArgs e) =>
                        {
                            pct = e.ProgressPercentage;
                        };
                        client.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
                        {
                            //we don't really need a status. we'll just try to unzip it when it's done
                            evt.Set();
                        };

                        for (; ;)
                        {
                            if (evt.WaitOne(10))
                            {
                                break;
                            }

                            //if the gui thread ordered an exit, cancel the download and wait for it to acknowledge
                            if (exiting)
                            {
                                client.CancelAsync();
                                evt.WaitOne();
                                break;
                            }
                        }
                    }
                }

                //throw new Exception("test of download failure");

                //if we were ordered to exit, bail without wasting any more time
                if (exiting)
                {
                    return;
                }

                //try acquiring file
                using (var hf = new HawkFile(fn))
                {
                    using (var exe = hf.BindFirstOf(".exe"))
                    {
                        var data = exe.ReadAllBytes();

                        //last chance. exiting, don't dump the new ffmpeg file
                        if (exiting)
                        {
                            return;
                        }

                        File.WriteAllBytes(FFmpegService.FFmpegPath, data);
                    }
                }

                //make sure it worked
                if (!FFmpegService.QueryServiceAvailable())
                {
                    throw new Exception("download failed");
                }

                succeeded = true;
            }
            catch
            {
                failed = true;
            }
            finally
            {
                try { File.Delete(fn); }
                catch { }
            }
        }