Esempio 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);
        }