Example #1
0
        static bool PullPush(Options opt)
        {
            bool result = false;

            opt.Status            = Options.TheadStatus.Running;
            opt.ThreadStartTime   = DateTime.Now;
            opt.ThreadCounterTime = DateTime.Now;


            opt.LogInformation("\r\nPullPush " + opt.Name + "\r\n Pulling from : " + opt.InputUri + "\r\n Pushing to : " + opt.OutputUri);

            SmoothLiveOutput d = new SmoothLiveOutput();

            if (d != null)
            {
                var t = d.Initialize(opt);
                t.Wait();
                if (t.Result == true)
                {
                    ManifestManager mc = ManifestManager.CreateManifestCache(new Uri(opt.InputUri), (ulong)opt.MinBitrate, (ulong)opt.MaxBitrate, opt.AudioTrackName, opt.TextTrackName, opt.MaxDuration, (ulong)opt.BufferSize, opt.LiveOffset);
                    if (mc != null)
                    {
                        if (mc.SetManifestOutput(d) == true)
                        {
                            t = mc.DownloadManifest();
                            t.Wait();
                            result = t.Result;
                            if (result == true)
                            {
                                var tt = mc.StartDownloadChunks();
                                tt.Wait();
                                result = tt.Result;
                                while (mc.GetAssetStatus() != AssetStatus.ChunksDownloaded)
                                {
                                    System.Threading.Tasks.Task.Delay(5000).Wait();
                                    if ((opt.ListCounters == null) || (opt.ListCounters.Count == 0))
                                    {
                                        CreatePullPushCounters(opt, mc);
                                    }
                                    else
                                    {
                                        UpdatePullPushCounters(opt, mc);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            opt.LogInformation("PullPush " + opt.Name + " done");
            opt.Status = Options.TheadStatus.Stopped;
            return(result);
        }
Example #2
0
        static bool PullPush(Options opt)
        {
            bool result = false;

            opt.Status            = Options.TheadStatus.Running;
            opt.ThreadStartTime   = DateTime.Now;
            opt.ThreadCounterTime = DateTime.Now;


            opt.LogInformation("\r\nPullPush " + opt.Name + "\r\n Pulling from : " + opt.InputUri + "\r\n Pushing to : " + opt.OutputUri);

            SmoothLiveOutput d = new SmoothLiveOutput();

            if (d != null)
            {
                bool InitResult = d.Initialize(opt);
                if (InitResult == true)
                {
                    ManifestManager mc = ManifestManager.CreateManifestCache(new Uri(opt.InputUri), (ulong)opt.MinBitrate, (ulong)opt.MaxBitrate, opt.AudioTrackName, opt.TextTrackName, opt.MaxDuration, (ulong)opt.BufferSize, opt.LiveOffset, opt);
                    if (mc != null)
                    {
                        if (mc.SetManifestOutput(d) == true)
                        {
                            var t = mc.DownloadManifest();
                            t.Wait();
                            result = t.Result;
                            if (result == true)
                            {
                                var tt = mc.StartDownloadChunks();
                                tt.Wait();
                                result = tt.Result;
                                DateTime startTime   = DateTime.Now;
                                DateTime currentTime = DateTime.Now;
                                while (mc.GetAssetStatus() != AssetStatus.ChunksDownloaded)
                                {
                                    if (opt.CounterPeriod > 0)
                                    {
                                        System.Threading.Tasks.Task.Delay(opt.CounterPeriod * 1000 / 10).Wait();
                                        if ((opt.ListCounters == null) || (opt.ListCounters.Count == 0))
                                        {
                                            CreatePullPushCounters(opt, mc);
                                        }
                                        else
                                        {
                                            UpdatePullPushCounters(opt, mc);
                                        }
                                    }
                                    else
                                    {
                                        System.Threading.Tasks.Task.Delay(1000).Wait();
                                    }



                                    // Force Garbage Collection in Container
                                    currentTime = DateTime.Now;
                                    if ((currentTime - startTime).TotalSeconds > 300)
                                    {
                                        startTime = currentTime;
                                        if (InDocker)
                                        {
                                            opt.LogInformation("\r\nCalling Garbage Collection " + opt.Name + "\r\n Pulling from : " + opt.InputUri + "\r\n Pushing to : " + opt.OutputUri);
                                            GC.Collect();
                                            GC.WaitForPendingFinalizers();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            opt.LogInformation("PullPush " + opt.Name + " done");
            opt.Status = Options.TheadStatus.Stopped;
            return(result);
        }