This class acts as an allocation pool meant to minimize GC churn caused by frame allocation & disposal. The public API comprises of just two methods: copyFrame(), which allocates as necessary and copies, and returnFrame(), which returns frame ownership to the pool for use by a later call to copyFrame(). This class is thread-safe; calls to copyFrame() and returnFrame() are allowed to happen on any thread.
コード例 #1
0
        /// <summary>
        /// Queue |frame| to be uploaded. </summary>
        public virtual void queueFrame(Endpoint stream, Org.Webrtc.VideoRenderer.I420Frame frame)
        {
            // Paying for the copy of the YUV data here allows CSC and painting time
            // to get spent on the render thread instead of the UI thread.
            abortUnless(FramePool.validateDimensions(frame), "Frame too large!");
            VideoRenderer.I420Frame frameCopy = framePool.takeFrame(frame).CopyFrom(frame);
            bool needToScheduleRender;

            lock (framesToRender)
            {
                // A new render needs to be scheduled (via updateFrames()) iff there isn't
                // already a render scheduled, which is true iff framesToRender is empty.
                needToScheduleRender = framesToRender.Count == 0;
                VideoRenderer.I420Frame frameToDrop;
                framesToRender.TryGetValue(stream, out frameToDrop);
                framesToRender[stream] = frameCopy;
                if (frameToDrop != null)
                {
                    framePool.returnFrame(frameToDrop);
                }
            }
            if (needToScheduleRender)
            {
                QueueEvent(updateFrames);
            }
        }