Example #1
0
        public static uint GetUInt32(this IMFAttributes obj, Guid key, uint defaultValue = 0)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            if (obj.GetUINT32(key, out var value).IsError)
            {
                return(defaultValue);
            }

            return(value);
        }
Example #2
0
        public static int GetInt32(this IMFAttributes input, Guid key, int defaultValue = 0)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (input.GetUINT32(key, out var value).IsError)
            {
                return(defaultValue);
            }

            return((int)value);
        }
Example #3
0
        public static bool GetBoolean(this IMFAttributes obj, Guid key, bool defaultValue = false)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            if (obj.GetUINT32(key, out var value).IsError)
            {
                return(defaultValue);
            }

            return(value != 0);
        }
        /// <summary>
        /// Retrieves a UInt32 value associated with a key.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="guidKey">Guid that identifies which value to retrieve.</param>
        /// <param name="value">Receives the requested value.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult GetUINT32(this IMFAttributes attributes, Guid guidKey, out uint value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            int result = 0;

            HResult hr = attributes.GetUINT32(guidKey, out result);

            value = hr.Succeeded() ? (uint)result : default(uint);

            return(hr);
        }
        /// <summary>
        /// Retrieves a Boolean value associated with a key.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="guidKey">Guid that identifies which value to retrieve.</param>
        /// <param name="value">Receives the requested value.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        /// <remarks>Media Foundation attributes don't support boolean values. This method get them as a 32-bits unsigned integer and return true for any non-zero value and false otherwise.</remarks>
        public static HResult GetBoolean(this IMFAttributes attributes, Guid guidKey, out bool value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            uint result;

            HResult hr = attributes.GetUINT32(guidKey, out result);

            value = hr.Succeeded() ? (result != 0) : default(bool);

            return(hr);
        }
        private static IMFAttributes CreateAudioAttributes(AudioFormat audioOutput)
        {
            uint   codecConfig         = 0;
            object supportedAttributes = null;

            // Create the audio attributes
            IMFAttributes audioAttributes = null;

            // Generate the audio media type
            uint elementsNumber   = 0;
            uint selectedType     = 0;
            int  avgBitrateDiff   = int.MaxValue;
            uint avgBytePerSecond = uint.MaxValue;

            // Get the available audio ouput types for the required sub type
            IMFCollection availableTypes = null;

            MFHelper.MFTranscodeGetAudioOutputAvailableTypes(audioOutput.Subtype, (uint)Enums.MFT_ENUM_FLAG.MFT_ENUM_FLAG_ALL, codecConfig, out availableTypes);

            // Get the number of types
            availableTypes.GetElementCount(out elementsNumber);

            // Find the best match for our needs
            for (uint elementIndex = 0; elementIndex < elementsNumber; elementIndex++)
            {
                // Get the next element
                availableTypes.GetElement(elementIndex, out supportedAttributes);
                audioAttributes = (IMFAttributes)supportedAttributes;

                // Get the byte per second
                audioAttributes.GetUINT32(new Guid(Consts.MF_MT_AUDIO_AVG_BYTES_PER_SECOND), out avgBytePerSecond);

                // If this is better than the last one found remember the index
                if (Math.Abs((int)avgBytePerSecond - (int)audioOutput.AvgBytePerSecond) < avgBitrateDiff)
                {
                    selectedType   = elementIndex;
                    avgBitrateDiff = Math.Abs((int)avgBytePerSecond - (int)audioOutput.AvgBytePerSecond);
                }

                audioAttributes = null;
            }

            // Get the best audio type found
            availableTypes.GetElement(selectedType, out supportedAttributes);
            audioAttributes = (IMFAttributes)supportedAttributes;

            return(audioAttributes);
        }
Example #7
0
        MFGetAttributeUINT32(
            IMFAttributes pAttributes,
            Guid guidKey,
            int unDefault
            )
        {
            HResult hr;
            int     unRet;

            try
            {
                hr = pAttributes.GetUINT32(guidKey, out unRet);
                MFError.ThrowExceptionForHR(hr);
            }
            catch
            {
                unRet = unDefault;
            }

            return(unRet);
        }
Example #8
0
        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
            // Space key toggles between running and paused
            case ' ':
                e.Handled = true;
                if (g_pPlayer.GetState() == CPlayer.PlayerState.Started)
                {
                    g_pPlayer.Pause();
                }
                else if (g_pPlayer.GetState() == CPlayer.PlayerState.Paused)
                {
                    g_pPlayer.Play();
                }
                break;

            case 'r':
                e.Handled = true;
                if (rotateAsyncToolStripMenuItem.Checked)
                {
                    IMFAttributes ia = g_pPlayer.GetVideoAttributes();
                    if (ia != null)
                    {
                        Guid    ClsidRotate = new Guid("AC776FB5-858F-4891-A5DC-FD01E79B5AD6");
                        int     i;
                        HResult hr;
                        hr = ia.GetUINT32(ClsidRotate, out i);
                        if (hr >= 0)
                        {
                            i  = i < 7 ? i + 1 : 0;
                            hr = ia.SetUINT32(ClsidRotate, i);
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(ia);
                    }
                }
                break;
            }
        }
Example #9
0
        public static int MFGetAttributeUINT32(
            IMFAttributes pAttributes,
            Guid guidKey,
            int unDefault
            )
        {
            int hr;
            int unRet;

            try
            {
                hr = pAttributes.GetUINT32(guidKey, out unRet);
                MFError.ThrowExceptionForHR(hr);
            }
            catch
            {
                unRet = unDefault;
            }

            return unRet;
        }
Example #10
0
 public HResult GetUINT32(Guid guidKey, out int punValue)
 {
     return(m_Attribs.GetUINT32(guidKey, out punValue));
 }