Exemple #1
0
        public void ReleaseToken(VideoEncoder encoder, Guid?unlockKey)
        {
            if (unlockKey == null)
            {
                return;
            }

            lock (this.lockObj)
            {
                if (this.totalInstances.Contains(unlockKey.Value))
                {
                    this.totalInstances.Remove(unlockKey.Value);
                }

                if (VideoEncoderHelpers.IsQuickSync(encoder))
                {
                    if (this.qsvInstances.Contains(unlockKey.Value))
                    {
                        this.qsvInstances.Remove(unlockKey.Value);
                    }
                }
                else if (VideoEncoderHelpers.IsNVEnc(encoder))
                {
                    if (this.nvencInstances.Contains(unlockKey.Value))
                    {
                        this.nvencInstances.Remove(unlockKey.Value);
                    }
                }
                else if (VideoEncoderHelpers.IsVCN(encoder))
                {
                    if (this.vceInstances.Contains(unlockKey.Value))
                    {
                        this.vceInstances.Remove(unlockKey.Value);
                    }
                }
                else if (VideoEncoderHelpers.IsMediaFoundation(encoder))
                {
                    if (this.mfInstances.Contains(unlockKey.Value))
                    {
                        this.mfInstances.Remove(unlockKey.Value);
                    }
                }
            }
        }
Exemple #2
0
        public Guid?GetToken(EncodeTask task)
        {
            lock (this.lockObj)
            {
                if (VideoEncoderHelpers.IsQuickSync(task.VideoEncoder))
                {
                    if (this.qsvInstances.Count < this.totalQsvInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        this.AllocateIntelGPU(task);

                        Guid guid = Guid.NewGuid();
                        this.qsvInstances.Add(guid);
                        this.totalInstances.Add(guid);
                        return(guid);
                    }

                    return(Guid.Empty); // Busy
                }
                else if (VideoEncoderHelpers.IsNVEnc(task.VideoEncoder))
                {
                    if (this.nvencInstances.Count < this.totalNvidiaInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        Guid guid = Guid.NewGuid();
                        this.nvencInstances.Add(guid);
                        this.totalInstances.Add(guid);
                        return(guid);
                    }

                    return(Guid.Empty); // Busy
                }
                else if (VideoEncoderHelpers.IsVCN(task.VideoEncoder))
                {
                    if (this.vceInstances.Count < this.totalVceInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        Guid guid = Guid.NewGuid();
                        this.vceInstances.Add(guid);
                        this.totalInstances.Add(guid);
                        return(guid);
                    }

                    return(Guid.Empty); // Busy
                }
                else if (VideoEncoderHelpers.IsMediaFoundation(task.VideoEncoder))
                {
                    if (this.mfInstances.Count < this.totalMfInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        Guid guid = Guid.NewGuid();
                        this.mfInstances.Add(guid);
                        this.totalInstances.Add(guid);
                        return(guid);
                    }

                    return(Guid.Empty); // Busy
                }
                else
                {
                    if (this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        Guid guid = Guid.NewGuid();
                        this.totalInstances.Add(guid);
                        return(guid);
                    }
                    else
                    {
                        return(Guid.Empty); // Busy
                    }
                }
            }
        }