public void Enqueue(Data <Frame> data)
        {
            lock (this)
            {
                if (_queues.Length == 0)
                {
                    _pool.Back(data.Payload);
                    return;
                }

                for (int q = 0; q < _queues.Length - 1; q++)
                {
                    if (data.Payload != null)
                    {
                        var frame = _pool.Rent();
                        frame.CopyContentFrom(data.Payload);
                        _queues[q].Enqueue(new Data <Frame>(frame, data.Version, data.SequenceNumber, data.Trace?.Clone()));
                    }
                    else
                    {
                        _queues[q].Enqueue(new Data <Frame>(null, data.Version, data.SequenceNumber, data.Trace?.Clone()));
                    }
                }
                _queues[_queues.Length - 1].Enqueue(data);
            }
        }
Exemple #2
0
        private void PushFrame(int sourceId, AudioMixingQueueInput input, int version, long pts)
        {
            var frame = _payloadPool.Rent();

            frame.GenerateSilence(pts);

            var data = new Data <Frame>(frame, version, 0, null);

            data.SourceId = sourceId;
            _payloads.Enqueue(data);

            input.LastPacketPts    = pts;
            input.LastPacketEndPts = pts + 441;
            input.Silence++;

            //Core.LogWarning($"Silence {Core.FormatTicks(ToTime(input.LastPacketPts))} ({_payloads.Count})");
        }
        private bool RenderFFMpeg(Frame resultPayload, out PayloadTrace trace)
        {
            bool first = true;

            trace = null;

            var frames = _inputRuntimesSorted.Where(s => s.Description.Visible).
                         Select(s => new { runtime = s, frameData = GetRuntimeOrFixedFrame(s) }).
                         Where(s => s.frameData != null).ToList();

            if (frames.Count == 1)
            {
                resultPayload.CopyContentFromAndSetPts(frames[0].frameData.Payload, _currentFpsTicks);
            }
            else if (frames.Count > 1)
            {
                Frame frameMainCopy = null;
                foreach (var s in frames)
                {
                    var frameData = s.frameData;
                    var runtime   = s.runtime;
                    var frame     = frameData.Payload;
                    UpdateTrace(frameData, ref trace);

                    if (first)
                    {
                        frameMainCopy = _framePool.Rent();
                        frameMainCopy.CopyContentFrom(frame);
                        _helper.Init(frameMainCopy, _setup.WeakOptions.PixelFormatGroup.BlendType);
                        first = false;
                    }
                    else
                    {
                        if (frame.Properties.Height != runtime.SlicesHeight)
                        {
                            runtime.SlicesHeight = frame.Properties.Height;
                            runtime.Slices       = GetSlices(runtime, frame.Properties.Height);
                        }

                        int x = (int)(runtime.Description.Rect.Left * _setup.Width);
                        int y = (int)(runtime.Description.Rect.Top * _setup.Height);

                        if (runtime.Slices == null)
                        {
                            _helper.Add(frame, x, y, 0, frame.Properties.Height);
                        }
                        else
                        {
                            Task.WhenAll(runtime.Slices.Select(s => Task.Run(() => _helper.Add(frame, x, y, s.yOffset, s.yCount))).ToArray()).Wait();
                        }
                    }
                }
                _helper.Get(resultPayload, _currentFpsTicks);
                _framePool.Back(frameMainCopy);
            }

            if (frames.Count > 0)
            {
                if (trace != null)
                {
                    trace = PayloadTrace.Create(_name, trace);
                }

                if (resultPayload.Properties.Width != _setup.Width ||
                    resultPayload.Properties.Height != _setup.Height ||
                    resultPayload.Properties.Format != _setup.OutputPixelFormat)
                {
                    Core.LogWarning($"Ignoring wrongly blended packet " +
                                    $"{resultPayload.Properties.Width}x{resultPayload.Properties.Height}x{resultPayload.Properties.Format} != Setup({_setup.Width}x{_setup.Height}x{_setup.OutputPixelFormat})");
                    return(false);
                }
                return(true);
            }
            return(false);
        }