Example #1
1
 public static MFSinkWriter CreateSinkWriterFromMFByteStream(IMFByteStream byteStream, IMFAttributes attributes)
 {
     IntPtr p;
     int result = MFInterops.ExternMFCreateSinkWriterFromURL(null, byteStream, attributes, out p);
     MediaFoundationException.Try(result, "Interops", "MFCreateSinkWriterFromURL");
     return new MFSinkWriter(p);
 }
Example #2
0
            internal PropertySet GetAttributes()
            {
                IMFAttributes attributes = null;

                _mft.GetAttributes(out attributes);
                return(PropSetFromAttributes(attributes));
            }
Example #3
0
        public HRESULT CopyAllItems(IMFAttributes pDest)
        {
            var hr = _type.CopyAllItems(pDest);

            Trace("hr: " + hr);
            return(hr);
        }
Example #4
0
            internal PropertySet GetOutputStreamAttributes()
            {
                IMFAttributes attributes = null;

                _mft.GetOutputStreamAttributes(0, out attributes);
                return(null);
            }
        /// <summary>
        /// Retrieves a string 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 string.</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 GetString(this IMFAttributes attributes, Guid guidKey, out string value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            value = null;

            int stringLength;

            HResult hr = attributes.GetStringLength(guidKey, out stringLength);

            if (hr.Failed())
            {
                return(hr);
            }

            StringBuilder sb = new StringBuilder(stringLength + 1);

            hr = attributes.GetString(guidKey, sb, sb.Capacity, out stringLength);
            if (hr.Failed())
            {
                return(hr);
            }

            value = sb.ToString();

            return(hr);
        }
Example #6
0
        public static string TraceValue(this IMFAttributes input, Guid key)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var value = GetValue(input, key);

            if (value == null)
            {
                return("<null>");
            }

            if (value is byte[] bytes)
            {
                return(Conversions.ToHexa(bytes, 64));
            }

            if (value is Guid guid)
            {
                return(guid.ToName());
            }

            if (value is string s)
            {
                return("`" + s + "`");
            }

            return(string.Format(CultureInfo.InvariantCulture, "{0}", value));
        }
        /// <summary>
        /// Converts the attribute store's contents to a byte array.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="buffer">Receives a byte array filled with attribute data.</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 GetAttributesAsBlob(this IMFAttributes attributes, out byte[] buffer)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            buffer = null;
            int sizeInBytes;

            HResult hr = MFExtern.MFGetAttributesAsBlobSize(attributes, out sizeInBytes);

            if (hr.Succeeded())
            {
                byte[] result = new byte[sizeInBytes];

                using (GCPin pin = new GCPin(result))
                {
                    hr = MFExtern.MFGetAttributesAsBlob(attributes, pin.PinnedAddress, result.Length);
                    if (hr.Succeeded())
                    {
                        buffer = result;
                    }
                }
            }

            return(hr);
        }
Example #8
0
        // Token: 0x06000942 RID: 2370 RVA: 0x0001AFC4 File Offset: 0x000191C4
        private static IMFSinkWriter CreateSinkWriter(string outputFile)
        {
            IMFAttributes imfattributes = MediaFoundationApi.CreateAttributes(1);

            imfattributes.SetUINT32(MediaFoundationAttributes.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1);
            IMFSinkWriter result;

            try
            {
                MediaFoundationInterop.MFCreateSinkWriterFromURL(outputFile, null, imfattributes, out result);
            }
            catch (COMException exception)
            {
                if (exception.GetHResult() == -1072875819)
                {
                    throw new ArgumentException("Was not able to create a sink writer for this file extension");
                }
                throw;
            }
            finally
            {
                Marshal.ReleaseComObject(imfattributes);
            }
            return(result);
        }
Example #9
0
        public HRESULT Compare(IMFAttributes pTheirs, _MF_ATTRIBUTES_MATCH_TYPE MatchType, out bool pbResult)
        {
            var hr = _type.Compare(pTheirs, MatchType, out pbResult);

            Trace("theirs: " + pTheirs.Trace() + " type: " + MatchType + " result: " + pbResult + " hr: " + hr);
            return(hr);
        }
        /// <summary>
        /// Retrieves a byte array 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 byte array.</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 GetAllocatedBlob(this IMFAttributes attributes, Guid guidKey, out byte[] value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            IntPtr resultPtr;
            int    resultLength;

            HResult hr = attributes.GetAllocatedBlob(guidKey, out resultPtr, out resultLength);

            if (hr.Succeeded())
            {
                try
                {
                    value = new byte[resultLength];
                    Marshal.Copy(resultPtr, value, 0, resultLength);
                }
                finally
                {
                    Marshal.FreeCoTaskMem(resultPtr);
                }
            }
            else
            {
                value = null;
            }

            return(hr);
        }
Example #11
0
 public static unsafe IMFActivateCollection MFEnumAudioDeviceSources()
 {
     using IMFAttributes attributes = MFCreateAttributes(1);
     attributes.SourceType          = CaptureDeviceAttributeKeys.SourceTypeAudcap;
     MFEnumDeviceSources(attributes, out IntPtr pSourceActivate, out int count).CheckError();
     return(new(pSourceActivate, count));
 }
Example #12
0
        // The '1' indicates there should only be 1 processing thread.
        // AudioDelayAsync doesn't support more than 1 thread.
        public AudioDelayAsync()
            : base(1)
        {
            Trace("AudioDelayAsync Constructor");

            m_pbDelayBuffer = IntPtr.Zero;
            m_cbDelayBuffer = 0;
            m_pbDelayPtr    = IntPtr.Zero;
            m_dwDelay       = DEFAULT_DELAY;
            m_cbTailSamples = 0;
            m_rtTimestamp   = -1;

            // Add some attributes to the MFTs attribute list.
            IMFAttributes ia = Attributes;
            MFError       throwonhr;

            throwonhr = ia.SetUINT32(MF_AUDIODELAY_WET_DRY_MIX, DEFAULT_WET_DRY_MIX);
            throwonhr = ia.SetUINT32(MF_AUDIODELAY_DELAY_LENGTH, DEFAULT_DELAY);

            m_Alignment      = 0;
            m_AvgBytesPerSec = 0;
            m_SamplesPerSec  = 0;
            m_BitsPerSample  = 0;
            m_NumChannels    = 0;
        }
Example #13
0
        public HResult GetOutputStreamAttributes(
            int dwOutputStreamID,
            out IMFAttributes pAttributes
            )
        {
            pAttributes = null;

            HResult hr = HResult.S_OK;

            try
            {
                // Trace("GetOutputStreamAttributes"); not interesting

                CheckValidStream(dwOutputStreamID);

                lock (m_TransformLockObject)
                {
                    hr = HResult.E_NOTIMPL;
                }
            }
            catch (Exception e)
            {
                hr = (HResult)Marshal.GetHRForException(e);
            }

            return(hr); // CheckReturn(hr);
        }
Example #14
0
        public static void MFGetBlob(IMFAttributes p, Guid g, object obj)
        {
            HResult hr;
            int     iSize;
            int     i;

            // Get the blob into a byte array
            hr = p.GetBlobSize(g, out iSize);
            MFError.ThrowExceptionForHR(hr);

            byte[] b = new byte[iSize];
            hr = p.GetBlob(g, b, iSize, out i);
            MFError.ThrowExceptionForHR(hr);

            GCHandle h = GCHandle.Alloc(b, GCHandleType.Pinned);

            try
            {
                IntPtr ip = h.AddrOfPinnedObject();

                // Convert the byte array to an IntPtr
                Marshal.PtrToStructure(ip, obj);
            }
            finally
            {
                h.Free();
            }
        }
        private static IMFTranscodeProfile CreateProfile(AudioFormat audioOutput, VideoFormat videoOutput, Guid containerType)
        {
            IMFTranscodeProfile profile = null;

            // Create a transcode profile
            MFHelper.MFCreateTranscodeProfile(out profile);

            // Create and set the audio attributes
            profile.SetAudioAttributes(SimpleFastEncode.CreateAudioAttributes(audioOutput));

            // Create and set the video attributes
            profile.SetVideoAttributes(SimpleFastEncode.CreateVideoAttributes(videoOutput));

            // Create the container attributes
            IMFAttributes containerAttributes = null;

            MFHelper.MFCreateAttributes(out containerAttributes, 2);
            containerAttributes.SetUINT32(new Guid(Consts.MF_TRANSCODE_TOPOLOGYMODE), 1);
            containerAttributes.SetGUID(new Guid(Consts.MF_TRANSCODE_CONTAINERTYPE), containerType);

            // Set them in the transcoding profile
            profile.SetContainerAttributes(containerAttributes);

            return(profile);
        }
Example #16
0
    public IMFAttributes GetVideoAttributes()
    {
        IMFAttributes ia = null;

        if (m_VideoNode != null)
        {
            HResult hr;

            object o;
            hr = m_VideoNode.GetObject(out o);

            if (Succeeded(hr) && o != null)
            {
                IMFTransform t = o as IMFTransform;

                if (t != null)
                {
                    hr = t.GetAttributes(out ia);
                    //SafeRelease(t);
                }
                //SafeRelease(o);
            }
        }

        return(ia);
    }
Example #17
0
        private void CreateVideoCaptureSource()
        {
            try
            {
                if (VideoCaptureDevice == null)
                {
                    Trace.WriteLine("Error no videocapturedevice set");
                    return;
                }
                //VideoCaptureSource
                IMFAttributes pAttributes = null;
                int           hr          = MFExtern.MFCreateAttributes(out pAttributes, 2);

                hr = pAttributes.SetGUID(MFAttributesClsid.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, CLSID.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
                MFError.ThrowExceptionForHR(hr);

                hr = pAttributes.SetString(MFAttributesClsid.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, VideoCaptureDevice.DevicePath);
                MFError.ThrowExceptionForHR(hr);

                IMFMediaSource ppMediaSource = null;
                hr = MFExtern.MFCreateDeviceSource(pAttributes, out ppMediaSource);
                MFError.ThrowExceptionForHR(hr);

                m_pSource = ppMediaSource;
                //GetCaptureFormats(m_pSource);
            }
            catch (Exception e)
            {
                Marshal.GetHRForException(e);
                Trace.WriteLine("SetupGraph Exception " + e.ToString());
            }
        }
Example #18
0
        private HResult OpenMediaSource(IMFMediaSource pSource)
        {
            HResult hr = HResult.S_OK;

            IMFAttributes pAttributes = null;

            hr = MFExtern.MFCreateAttributes(out pAttributes, 2);

            if (Succeeded(hr))
            {
                hr = pAttributes.SetUnknown(MFAttributesClsid.MF_SOURCE_READER_ASYNC_CALLBACK, this);
            }

            if (Succeeded(hr))
            {
                IMFSourceReader pReader;

                hr = MFExtern.MFCreateSourceReaderFromMediaSource(
                    pSource,
                    pAttributes,
                    out pReader
                    );
                m_pReader = (IMFSourceReaderAsync)pReader;
            }

            SafeRelease(pAttributes);

            return(hr);
        }
        /// <summary>
        /// Converts the attribute store's contents to a memory buffer.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="buffer">Receives a memory buffer filled with attribute data.</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 GetAttributesAsBlob(this IMFAttributes attributes, out MemoryBuffer buffer)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            buffer = null;
            int sizeInBytes;

            HResult hr = MFExtern.MFGetAttributesAsBlobSize(attributes, out sizeInBytes);

            if (hr.Succeeded())
            {
                MemoryBuffer result = new MemoryBuffer((uint)sizeInBytes);

                hr = MFExtern.MFGetAttributesAsBlob(attributes, result.BufferPointer, (int)result.ByteLength);
                if (hr.Succeeded())
                {
                    buffer = result;
                }
                else
                {
                    result.Dispose();
                }
            }

            return(hr);
        }
        /// <summary>
        /// Retrieves an attribute at the specified index.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="index">The index to retrieve.</param>
        /// <param name="guidKey">The key of this attribute.</param>
        /// <param name="value">The value of this attribute.</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 GetItemByIndex(this IMFAttributes attributes, int index, out Guid guidKey, out object value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            HResult hr = 0;

            value = null;

            using (PropVariant variant = new PropVariant())
            {
                hr = attributes.GetItemByIndex(index, out guidKey, variant);
                if (hr.Succeeded())
                {
                    value = variant.GetObject();
                }
            }

            return(hr);
        }
Example #21
0
 public static unsafe IMFActivateCollection MFEnumVideoDeviceSources(Guid videoDeviceCategory)
 {
     using IMFAttributes attributes = MFCreateAttributes(2);
     attributes.SourceType          = CaptureDeviceAttributeKeys.SourceTypeVidcap;
     attributes.VideoDeviceCategory = videoDeviceCategory;
     MFEnumDeviceSources(attributes, out IntPtr pSourceActivate, out int count).CheckError();
     return(new(pSourceActivate, count));
 }
Example #22
0
        public static void MFCreateMediaSession(IMFAttributes configuration, out IMFMediaSession mediaSession)
        {
            int result = ExternMFCreateMediaSession(configuration, out mediaSession);

            if (result < 0)
            {
                throw new COMException("Exception from HRESULT: 0x" + result.ToString("X", System.Globalization.NumberFormatInfo.InvariantInfo) + " (MFCreateMediaSession)", result);
            }
        }
Example #23
0
        public static void MFCreateAttributes(out IMFAttributes attributes, uint initialSize)
        {
            int result = ExternMFCreateAttributes(out attributes, initialSize);

            if (result < 0)
            {
                throw new COMException("Exception from HRESULT: 0x" + result.ToString("X", System.Globalization.NumberFormatInfo.InvariantInfo) + " (MFCreateAttributes)", result);
            }
        }
Example #24
0
        public static string Trace(this IMFAttributes input)
        {
            if (input == null)
            {
                return("<null>");
            }

            return(string.Join("|", Enumerate(input).Select(kv => kv.Key.ToName() + "=" + TraceValue(input, kv.Key))));
        }
Example #25
0
 public static HResult MFGetAttributeRatio(
     IMFAttributes pAttributes,
     Guid guidKey,
     out int punNumerator,
     out int punDenominator
     )
 {
     return(MFGetAttribute2UINT32asUINT64(pAttributes, guidKey, out punNumerator, out punDenominator));
 }
        /// <summary>
        /// Associates a Ratio value with a key.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="guidKey">Guid that identifies the value to set.</param>
        /// <param name="width">The width part of the size.</param>
        /// <param name="height">The height part of the size.</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>Width and height values are stored packed as 64-bits value.</remarks>
        public static HResult SetSize(this IMFAttributes attributes, Guid guidKey, uint width, uint height)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            return(attributes.SetUINT64(guidKey, ((ulong)width << 32) | height));
        }
        /// <summary>
        /// Associates an address location value with a key.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="guidKey">Guid that identifies the value to set.</param>
        /// <param name="value">New value for this key as a IntPtr.</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 natively support pointer values. This method store them as a 64-bits unsigned integer.</remarks>
        public static HResult SetPointer(this IMFAttributes attributes, Guid guidKey, IntPtr value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            return(attributes.SetUINT64(guidKey, value.ToInt64()));
        }
        /// <summary>
        /// Associates a ratio value (numerator and denominator) with a key.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="guidKey">Guid that identifies the value to set.</param>
        /// <param name="numerator">The numerator part of the ratio.</param>
        /// <param name="denominator">The denominator part of the ratio.</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>Numerator and denominator values are stored packed as 64-bits value.</remarks>
        public static HResult SetRatio(this IMFAttributes attributes, Guid guidKey, uint numerator, uint denominator)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            return(attributes.SetUINT64(guidKey, ((ulong)numerator << 32) | denominator));
        }
Example #29
0
        public static T Get <T>(this IMFAttributes obj, Guid key, T defaultValue = default(T), IFormatProvider provider = null)
        {
            if (!TryGet(obj, key, provider, out T value))
            {
                return(defaultValue);
            }

            return(value);
        }
Example #30
0
        public static KeyValuePair <Guid, object>[] ToValues(this IMFAttributes obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            return(Enumerate(obj).Select(kv => new KeyValuePair <Guid, object>(kv.Key, GetValue(obj, kv.Key))).ToArray());
        }
        /// <summary>
        /// Associates a UInt64 value with a key.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="guidKey">Guid that identifies the value to set.</param>
        /// <param name="value">New value for this key.</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 SetUINT64(this IMFAttributes attributes, Guid guidKey, ulong value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            return(attributes.SetUINT64(guidKey, unchecked ((long)value)));
        }
Example #32
0
        public static void MFGetAttribute2UINT32asUINT64(IMFAttributes pAttributes, Guid g, out int nNumerator, out int nDenominator)
        {
            long ul;
            int hr;

            hr = pAttributes.GetUINT64(g, out ul);
            MFError.ThrowExceptionForHR(hr);

            nDenominator = (int)ul;
            nNumerator = (int)(ul >> 32);
        }
Example #33
0
        public static void MFGetBlob(IMFAttributes p, Guid g, object obj)
        {
            int hr;
            int iSize;
            int i;

            // Get the blob into a byte array
            hr = p.GetBlobSize(g, out iSize);
            MFError.ThrowExceptionForHR(hr);

            byte[] b = new byte[iSize];
            hr = p.GetBlob(g, b, iSize, out i);
            MFError.ThrowExceptionForHR(hr);

            GCHandle h = GCHandle.Alloc(b, GCHandleType.Pinned);

            try
            {
                IntPtr ip = h.AddrOfPinnedObject();

                // Convert the byte array to an IntPtr
                Marshal.PtrToStructure(ip, obj);
            }
            finally
            {
                h.Free();
            }
        }
Example #34
0
        public static void MFSetAttribute2UINT32asUINT64(IMFAttributes pAttributes, Guid g, int nNumerator, int nDenominator)
        {
            int hr;
            long ul = nNumerator;

            ul <<= 32;
            ul |= (UInt32)nDenominator;

            hr = pAttributes.SetUINT64(g, ul);
            MFError.ThrowExceptionForHR(hr);
        }
Example #35
0
        protected static int MFGetAttributeUINT32Alt(
            IMFAttributes pAttributes,
            Guid guidKey,
            int unDefault
            )
        {
            int unRet;

            IHack h = new Hack() as IHack;

            try
            {
                IntPtr ip = Marshal.GetIUnknownForObject(pAttributes);

                h.Set(ip, typeof(IMFAttributes).GUID, false);

                IMFAttributes a = (IMFAttributes)h;

                try
                {
                    int hr = a.GetUINT32(guidKey, out unRet);
                    MFError.ThrowExceptionForHR(hr);
                }
                catch
                {
                    unRet = unDefault;
                }
            }
            finally
            {
                Marshal.ReleaseComObject(h);
            }

            return unRet;
        }
Example #36
0
        int CopyAttribute(IMFAttributes pSrc, IMFAttributes pDest, Guid key)
        {
            PropVariant var = new PropVariant();

            int hr = S_Ok;

            hr = pSrc.GetItem(key, var);
            if (Succeeded(hr))
            {
                hr = pDest.SetItem(key, var);
            }

            return hr;
        }
Example #37
0
 public static void MFCreateSourceReaderFromMediaSource(
     IMFMediaSource mediaSource,
     IMFAttributes attributes,
     out IMFSourceReader sourceReader)
 {
     int result = ExternMFCreateSourceReaderFromMediaSource(mediaSource, attributes, out sourceReader);
     if (result < 0)
     {
         throw new COMException("Exception from HRESULT: 0x" + result.ToString("X", System.Globalization.NumberFormatInfo.InvariantInfo) + " (MFCreateTranscodeTopology failed)", result);
     }
 }
Example #38
0
 public static void MFCreateMediaSession(IMFAttributes configuration, out IMFMediaSession mediaSession)
 {
     int result = ExternMFCreateMediaSession(configuration, out mediaSession);
     if (result < 0)
     {
         throw new COMException("Exception from HRESULT: 0x" + result.ToString("X", System.Globalization.NumberFormatInfo.InvariantInfo) + " (MFCreateMediaSession)", result);
     }
 }
Example #39
0
 public static void MFCreateAttributes(out IMFAttributes attributes, uint initialSize)
 {
     int result = ExternMFCreateAttributes(out attributes, initialSize);
     if (result < 0)
     {
         throw new COMException("Exception from HRESULT: 0x" + result.ToString("X", System.Globalization.NumberFormatInfo.InvariantInfo) + " (MFCreateAttributes)", result);
     }
 }
Example #40
0
        private static int CopyAttribute(IMFAttributes pSrc, IMFAttributes pDest, Guid key)
        {
            var variant = new PropVariant();

            var hr = pSrc.GetItem(key, variant);
            if (Succeeded(hr))
                hr = pDest.SetItem(key, variant);
            return hr;
        }
Example #41
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 #42
0
        public static void MFSetBlob(IMFAttributes p, Guid g, object o)
        {
            int hr;
            int iSize = Marshal.SizeOf(o);
            byte[] b = new byte[iSize];

            GCHandle h = GCHandle.Alloc(b, GCHandleType.Pinned);
            try
            {
                IntPtr ip = h.AddrOfPinnedObject();

                Marshal.StructureToPtr(o, ip, false);
            }
            finally
            {
                h.Free();
            }
            hr = p.SetBlob(g, b, iSize);
            MFError.ThrowExceptionForHR(hr);
        }