Exemplo n.º 1
0
        private void RefreshBitrateChoices()
        {
            if (this.SelectedAudioEncoder == null || this.SelectedMixdown == null)
            {
                return;
            }

            int oldBitrate = 0;

            if (this.SelectedBitrate != null)
            {
                oldBitrate = this.SelectedBitrate.Bitrate;
            }

            this.bitrateChoices = new List <BitrateChoiceViewModel>();
            BitrateLimits bitrateLimits = null;

            // Determine if we should gray out "out of range" bitrates
            // Can only do this if a source is loaded
            if (this.main.HasVideoSource)
            {
                // Find if we're encoding a single track
                var track = this.GetTargetAudioTrack();

                // Can only gray out bitrates if we're encoding exactly one track
                if (track != null)
                {
                    int sampleRateLimits = this.SampleRate;
                    if (sampleRateLimits == 0)
                    {
                        sampleRateLimits = track.SampleRate;
                    }

                    HBMixdown mixdownLimits = this.SelectedMixdown.Mixdown;
                    if (mixdownLimits.ShortName == "none" || string.IsNullOrEmpty(mixdownLimits.ShortName))
                    {
                        mixdownLimits = Encoders.SanitizeMixdown(mixdownLimits, this.HBAudioEncoder, track.ChannelLayout);
                    }

                    bitrateLimits = Encoders.GetBitrateLimits(this.HBAudioEncoder, sampleRateLimits, mixdownLimits);
                }
            }

            BitrateLimits encoderBitrateLimits = CodecUtilities.GetAudioEncoderLimits(this.HBAudioEncoder);

            this.bitrateChoices.Add(new BitrateChoiceViewModel
            {
                Bitrate      = 0,
                IsCompatible = true
            });

            foreach (int bitrateChoice in Encoders.AudioBitrates)
            {
                if (bitrateChoice >= encoderBitrateLimits.Low && bitrateChoice <= encoderBitrateLimits.High)
                {
                    bool isCompatible = bitrateLimits == null || bitrateChoice >= bitrateLimits.Low && bitrateChoice <= bitrateLimits.High;

                    this.bitrateChoices.Add(new BitrateChoiceViewModel
                    {
                        Bitrate      = bitrateChoice,
                        IsCompatible = isCompatible
                    });
                }
            }

            this.RaisePropertyChanged(() => this.BitrateChoices);

            this.selectedBitrate = this.BitrateChoices.SingleOrDefault(b => b.Bitrate == oldBitrate);
            if (this.selectedBitrate == null)
            {
                this.selectedBitrate = this.BitrateChoices[0];
            }

            //this.selectedBitrate = this.BitrateChoices.Single(b => b.Bitrate == oldBitrate);
            this.RaisePropertyChanged(() => this.SelectedBitrate);
        }
Exemplo n.º 2
0
        Element ImportElement_internal(Element foreign_element, ImportJob job)
        {
            if (foreign_element == null)
            {
                return(null);
            }
            if (foreign_element.Owner == this)
            {
                return(foreign_element);
            }

            Element local_element;

            // don't import the same Element twice
            if (job.ImportMap.TryGetValue(foreign_element, out local_element))
            {
                return(local_element);
            }

            lock (foreign_element.SyncRoot)
            {
                // Claim an unowned Element
                if (foreign_element.Owner == null && AllElements[foreign_element.ID] == null)
                {
                    foreign_element.Owner = this;
                    foreach (var attr in foreign_element)
                    {
                        var elem = attr.Value as Element;
                        if (elem != null)
                        {
                            foreign_element[attr.Key] = ImportElement_internal(elem, job);
                        }

                        var elem_array = attr.Value as ElementArray;
                        if (elem_array != null)
                        {
                            elem_array.Owner = foreign_element;
                            for (int i = 0; i < elem_array.Count; i++)
                            {
                                var item = elem_array[i];
                                if (item != null && item.Owner != null)
                                {
                                    elem_array[i] = ImportElement_internal(item, job);
                                }
                            }
                        }
                    }
                    return(foreign_element);
                }

                // find a local element with the same ID and either return or stub it
                local_element = AllElements[foreign_element.ID];
                if (local_element != null)
                {
                    if (!foreign_element.Stub && (job.OverwriteMode == ImportOverwriteMode.All || (job.OverwriteMode == ImportOverwriteMode.Stubs && local_element.Stub)))
                    {
                        local_element.Name      = foreign_element.Name;
                        local_element.ClassName = foreign_element.ClassName;
                        local_element.Stub      = false;
                    }
                    else
                    {
                        return(local_element);
                    }
                }
                else
                {
                    // Create a new local Element
                    if (foreign_element.Stub || (job.ImportMode == ImportRecursionMode.Stubs && job.Depth > 0))
                    {
                        local_element = new Element(this, foreign_element.ID);
                    }
                    else if (job.ImportMode == ImportRecursionMode.Recursive || job.Depth == 0)
                    {
                        local_element = new Element(this, foreign_element.Name, foreign_element.ID, foreign_element.ClassName);
                    }
                    else
                    {
                        local_element = null;
                    }
                }
                job.ImportMap.Add(foreign_element, local_element);

                // Copy attributes
                if (local_element != null && !local_element.Stub)
                {
                    local_element.Clear();
                    foreach (var attr in foreign_element)
                    {
                        if (attr.Value == null)
                        {
                            local_element[attr.Key] = null;
                        }
                        else if (IsDatamodelArrayType(attr.Value.GetType()))
                        {
                            var list       = (System.Collections.ICollection)attr.Value;
                            var inner_type = GetArrayInnerType(list.GetType());

                            var copied_array = CodecUtilities.MakeList(inner_type, list.Count);
                            foreach (var item in list)
                            {
                                copied_array.Add(CopyValue(item, job));
                            }

                            local_element[attr.Key] = copied_array;
                        }
                        else
                        {
                            local_element[attr.Key] = CopyValue(attr.Value, job);
                        }
                    }
                }
                return(local_element);
            }
        }