Ejemplo n.º 1
0
        private async Task <ClipEntry> CompileDocumentClip(CompilingProgressManager reporter, DocumentClipDescriptor clip, DirectoryInfo pesDir)
        {
            byte tId          = 0;
            var  tPgsTaskList = new List <Task <PgsEntryDescriptor> >();

            foreach (var iTrack in clip.Tracks)
            {
                tPgsTaskList.Add(Task.Run(
                                     () => CompileTrack(reporter, clip, iTrack, pesDir, Muxer.GetPgsPid(tId++))
                                     ));
            }
            await Task.WhenAll(tPgsTaskList);

            TimeSpan  tMaxLength = tPgsTaskList.Max(xPgsTask => xPgsTask.Result.Length);
            ClipEntry tClipEntry = new ClipEntry(clip.ClipId, clip.InTimeOffset, clip.InTimeOffset + tMaxLength);

            foreach (var iPgsTask in tPgsTaskList)
            {
                var tPgsDesc = iPgsTask.Result;
                var tPgs     = new PgsEntry(tPgsDesc.Pid, tPgsDesc.PesFile, tPgsDesc.Lang);
                tClipEntry.AddPgs(tPgs);
            }

            return(tClipEntry);
        }
Ejemplo n.º 2
0
        private PgsEntryDescriptor CompileTrack(CompilingProgressManager reporter, DocumentClipDescriptor clip, EsTrackDescriptor track, DirectoryInfo pesDir, ushort pid)
        {
            const string PesFileNameFmt = "{0:00000}.{1:x4}.pes";

            using (var tPgsStreamServer = new AnonymousPipeServerStream(PipeDirection.Out))
                using (var tPgsStream = new AnonymousPipeClientStream(PipeDirection.In, tPgsStreamServer.ClientSafePipeHandle))
                    using (var tReporter = reporter.CreatePgsProgressReporter())
                    {
                        Func <int> tEncodeTaskAction = () =>
                        {
                            using (tPgsStreamServer)
                            {
                                return(EncodePgs(clip, track, tPgsStreamServer, tReporter));
                            }
                        };

                        var tEncodeTask = Task.Run(tEncodeTaskAction);

                        var      tPesFileName = string.Format(PesFileNameFmt, clip.ClipId, pid);
                        FileInfo tPesFile     = pesDir.PickFile(tPesFileName);
                        Pgs2Pes(tPgsStream, tPesFile);

                        return(new PgsEntryDescriptor(
                                   pid,
                                   tPesFile.FullName,
                                   TimeFromFrameCount(tEncodeTask.Result, clip.Rate),
                                   track.Track.Lang
                                   ));
                    }
        }
Ejemplo n.º 3
0
        public async Task <bool> Compile(ICompilingProgressReporter reporter, Guid projectId, DirectoryInfo outputDir, params DocumentClipDescriptor[] clips)
        {
            AssertNotDisposed();

            var tPgsNum          = clips.Sum(xClip => xClip.Tracks.Count);
            var tProgressManager = new CompilingProgressManager(reporter, tPgsNum);

            ProjectSettings tProjSettings = new ProjectSettings()
            {
                OutputDir = outputDir,
                TempDir   = settings.TempDir.NavigateTo(string.Format(PesMuxOutputPath, projectId))
            };
            Project tProj = new Project(tProjSettings);

            var tPesDir    = settings.TempDir.NavigateTo(string.Format(PesEncOutputPath, projectId)).SafeCreate(string.Empty);
            var tClipTasks =
                (from iClip in clips select CompileDocumentClip(tProgressManager, iClip, tPesDir)).ToArray();

            var tPgsEncTask = Task.WhenAll(tClipTasks);

            try { await tPgsEncTask; } catch { }

            if (tPgsEncTask.Exception != null || reporter.IsCanceled)
            {
                ReportSummary(reporter, tPgsEncTask.Exception);
                return(false);
            }

            tProj.AddClipList(tClipTasks.Select(xClipTask => xClipTask.Result));
            var tPesMuxTask = this.GetPesMuxer().Mux(tProj, tProgressManager);

            try { await tPesMuxTask; } catch { }

            if (tPesMuxTask.Exception != null || reporter.IsCanceled)
            {
                ReportSummary(reporter, tPesMuxTask.Exception);
                return(false);
            }

            ReportSummary(reporter, null);
            return(true);
        }