예제 #1
0
        /// <summary>
        /// Retrieves the length of a string value associated with a key.
        /// </summary>
        public int GetStringLength(Guid key)
        {
            int result;

            MediaFoundationException.Try(GetStringLength(key, out result), c, "GetStringLength");
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Retrieves a GUID value associated with a key.
        /// </summary>
        public Guid GetGuid(Guid key)
        {
            Guid result;

            MediaFoundationException.Try(GetGuid(key, out result), c, "GetGuid");
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Retrieves a double value associated with a key.
        /// </summary>
        public double GetDouble(Guid key)
        {
            double result;

            MediaFoundationException.Try(GetDouble(key, out result), c, "GetDouble");
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Retrieves a UINT64 value associated with a key.
        /// </summary>
        public long GetUINT64(Guid key)
        {
            long result;

            MediaFoundationException.Try(GetUINT64(key, out result), c, "GetUINT64");
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Retrieves the length of a byte array associated with a key.
        /// </summary>
        public int GetBlobSize(Guid key)
        {
            int result;

            MediaFoundationException.Try(GetBlobSize(key, out result), c, "GetBlobSize");
            return(result);
        }
예제 #6
0
파일: MFSample.cs 프로젝트: yazici/AudioLab
        /// <summary>
        /// Currently no flags are defined. Instead, metadata for samples is defined using
        /// attributes. To get attibutes from a sample, use the IMFAttributes interface, which
        /// IMFSample inherits.
        /// </summary>
        public MFSampleFlags GetSampleFlags()
        {
            MFSampleFlags flags;

            MediaFoundationException.Try(GetSampleFlagsNative(out flags), c, "GetSampleFlags");
            return(flags);
        }
예제 #7
0
        /// <summary>
        /// Retrieves the data type of the value associated with a key.
        /// </summary>
        /// <returns>HRESULT</returns>
        public MFAttributeType GetItemType(Guid key)
        {
            MFAttributeType type;

            MediaFoundationException.Try(GetItemType(key, out type), c, "GetItemType");
            return(type);
        }
예제 #8
0
파일: MFSample.cs 프로젝트: yazici/AudioLab
        public int GetTotalLength()
        {
            int res;

            MediaFoundationException.Try(GetTotalLengthNative(out res), c, "GetTotalLength");
            return(res);
        }
예제 #9
0
        /// <summary>
        /// Retrieves a UINT32 value associated with a key.
        /// </summary>
        public int GetUINT32(Guid key)
        {
            int result;

            MediaFoundationException.Try(GetUINT32(key, out result), c, "GetUINT32");
            return(result);
        }
예제 #10
0
파일: MFSample.cs 프로젝트: yazici/AudioLab
        public MFMediaBuffer GetBufferByIndex(int index)
        {
            MFMediaBuffer buffer;

            MediaFoundationException.Try(GetBufferByIndexNative(index, out buffer), c, "GetBufferByIndex");
            return(buffer);
        }
예제 #11
0
파일: MFSample.cs 프로젝트: yazici/AudioLab
        public MFMediaBuffer ConvertToContinousBuffer()
        {
            MFMediaBuffer buffer;

            MediaFoundationException.Try(ConvertToContinousBufferNative(out buffer), c, "ConvertToContinousBuffer");
            return(buffer);
        }
예제 #12
0
파일: MFSample.cs 프로젝트: yazici/AudioLab
        public int GetBufferCount()
        {
            int res;

            MediaFoundationException.Try(GetBufferCountNative(out res), c, "GetBufferCount");
            return(res);
        }
예제 #13
0
파일: MFSample.cs 프로젝트: yazici/AudioLab
        public long GetSampleDuration()
        {
            long res;

            MediaFoundationException.Try(GetSampleDurationNative(out res), c, "GetSampleDuration");
            return(res);
        }
예제 #14
0
        /// <summary>
        /// Retrieves an attribute at the specified index.
        /// </summary>
        public unsafe PropertyVariant GetItemByIndex(int index, out Guid key)
        {
            PropertyVariant value = default(PropertyVariant);

            MediaFoundationException.Try(GetItemByIndexNative(index, out key, new IntPtr(&value)), c, "GetItemByIndex");
            return(value);
        }
예제 #15
0
파일: MFSample.cs 프로젝트: yazici/AudioLab
        /// <summary>
        /// Retrieves the presentation time of the sample.
        /// </summary>
        /// <returns>Presentation time, in 100-nanosecond units.</returns>
        public long GetSampleTime()
        {
            long res;

            MediaFoundationException.Try(GetSampleTimeNative(out res), c, "GetSampleTime");
            return(res);
        }
예제 #16
0
        /// <summary>
        /// Enumerates Mediafoundation-Transforms that match the specified search criteria.
        /// </summary>
        /// <param name="category">A <see cref="Guid" /> that specifies the category of MFTs to enumerate.
        /// For a list of MFT categories, see <see cref="MFTCategories" />.</param>
        /// <param name="flags">The bitwise OR of zero or more flags from the <see cref="MFTEnumFlags" /> enumeration.</param>
        /// <param name="inputType">Specifies an input media type to match. This parameter can be <c>null</c>. If <c>null</c>, all input types are matched.</param>
        /// <param name="outputType">Specifies an output media type to match. This parameter can be <c>null</c>. If <c>null</c>, all output types are matched.</param>
        /// <returns> A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the MFTs.</returns>
        public static IEnumerable <MFActivate> EnumerateTransformsEx(Guid category, MFTEnumFlags flags, MFTRegisterTypeInfo inputType = null, MFTRegisterTypeInfo outputType = null)
        {
            if (!(Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1))
            {
                throw new PlatformNotSupportedException("The EnumerateTransformsEx method requires Windows 7/Windows Server 2008 R2 or above.");
            }

            IntPtr ptr;
            int    count;
            int    res = NativeMethods.MFTEnumEx(category, flags, inputType, outputType, out ptr, out count);

            try
            {
                MediaFoundationException.Try(res, "Interops", "MFTEnumEx");
                for (int i = 0; i < count; i++)
                {
                    var ptr0 = ptr;
                    var ptr1 = Marshal.ReadIntPtr(new IntPtr(ptr0.ToInt64() + i * Marshal.SizeOf(ptr0)));
                    yield return(new MFActivate(ptr1));
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(ptr);
            }
        }
예제 #17
0
        /// <summary>
        /// Reads data from the stream.
        /// </summary>
        /// <param name="buffer">The buffer that receives the data.</param>
        /// <param name="count">The number of bytes to read.</param>
        /// <returns>HRESULT</returns>
        /// <exception cref="ArgumentNullException">buffer is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">count is bigger than the length of the buffer.</exception>
        public unsafe int Read(byte[] buffer, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (count > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            if (count == 0)
            {
                return(0);
            }

            int read;

            fixed(void *pBuffer = &buffer[0])
            {
                int result = ReadNative((IntPtr)pBuffer, count, out read);

                MediaFoundationException.Try(result, InterfaceName, "Read");
            }

            return(read);
        }
예제 #18
0
        public IntPtr Lock(out int maxLength, out int currentLength)
        {
            IntPtr p = IntPtr.Zero;

            MediaFoundationException.Try(LockNative(out p, out maxLength, out currentLength), c, "Lock");
            return(p);
        }
예제 #19
0
        /// <summary>
        /// Writes data to the stream.
        /// </summary>
        /// <param name="buffer">Buffer that contains the data to write.</param>
        /// <param name="count">The number of bytes to write.</param>
        /// <returns>The number of bytes that were written.</returns>
        /// <exception cref="ArgumentNullException">buffer is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">count is bigger than the length of the buffer.</exception>
        public unsafe int Write(byte[] buffer, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (count > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            if (count == 0)
            {
                return(0);
            }

            int written;

            fixed(void *p = &buffer[0])
            {
                int result = WriteNative((IntPtr)p, count, out written);

                MediaFoundationException.Try(result, InterfaceName, "Write");
            }

            return(written);
        }
예제 #20
0
        /// <summary>
        /// Retrieves the number of attributes that are set on this object.
        /// </summary>
        public int GetCount()
        {
            int count;

            MediaFoundationException.Try(GetCountNative(out count), c, "GetCount");
            return(count);
        }
예제 #21
0
 public static void Shutdown()
 {
     if (_isstarted)
     {
         MediaFoundationException.Try(NativeMethods.MFShutdown(), "Interops", "MFShutdown");
         _isstarted = false;
     }
 }
예제 #22
0
 public static void Startup()
 {
     if (!_isstarted)
     {
         MediaFoundationException.Try(NativeMethods.MFStartup(NativeMethods.MF_VERSION, 0), "Interops", "MFStartup");
         _isstarted = true;
     }
 }
예제 #23
0
        public static IntPtr CreateSourceReaderFromUrlNative(string url)
        {
            IntPtr ptr    = IntPtr.Zero;
            int    result = NativeMethods.MFCreateSourceReaderFromURL(url, IntPtr.Zero, out ptr);

            MediaFoundationException.Try(result, "Interops", "MFCreateSourceReaderFromURL");
            return(ptr);
        }
예제 #24
0
        /// <summary>
        /// Moves the current position in the stream by a specified offset.
        /// </summary>
        /// <param name="seekOrigin">Specifies the origin of the seek as a member of the <see cref="MFByteStreamSeekOrigin"/> enumeration. The offset is calculated relative to this position.</param>
        /// <param name="seekOffset">Specifies the new position, as a byte offset from the seek origin.</param>
        /// <param name="cancelPendingIO">Specifies whether all pending I/O requests are canceled after the seek request completes successfully.</param>
        /// <returns>The new position after the seek.</returns>
        public long Seek(MFByteStreamSeekOrigin seekOrigin, long seekOffset, bool cancelPendingIO)
        {
            long v;

            MediaFoundationException.Try(SeekNative(seekOrigin, seekOffset, cancelPendingIO, out v), InterfaceName,
                                         "Seek");
            return(v);
        }
예제 #25
0
        public static MFSourceReader CreateSourceReaderFromUrl(string url)
        {
            IntPtr ptr    = IntPtr.Zero;
            int    result = MFInterops.MFCreateSourceReaderFromURL(url, IntPtr.Zero, out ptr);

            MediaFoundationException.Try(result, "Interops", "MFCreateSourceReaderFromURL");
            return(new MFSourceReader(ptr));
        }
예제 #26
0
        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));
        }
예제 #27
0
        /// <summary>
        /// Gets statistics about the performance of the sink writer.
        /// </summary>
        /// <param name="streamIndex">The zero-based index of a stream to query, or <see cref="MF_SINK_WRITER_ALL_STREAMS"/> to query the media sink itself.</param>
        /// <returns>Statistics about the performance of the sink writer.</returns>
        public MFSinkWriterStatistics GetStatistics(int streamIndex)
        {
            MFSinkWriterStatistics s;

            s.Cb = Marshal.SizeOf(typeof(MFSinkWriterStatistics));
            MediaFoundationException.Try(GetStatisticsNative(streamIndex, out s), InterfaceName, "GetStatistics");
            return(s);
        }
예제 #28
0
        public static MFMediaType MediaTypeFromWaveFormat(WaveFormat waveFormat)
        {
            var mediaType = MFMediaType.CreateEmpty();
            int result    = NativeMethods.MFInitMediaTypeFromWaveFormatEx(mediaType.BasePtr, waveFormat, Marshal.SizeOf(waveFormat));

            MediaFoundationException.Try(result, "Interops", "MFInitMediaTypeFromWaveFormatEx");
            return(mediaType);
        }
예제 #29
0
        public static IntPtr CreateSinkWriterFromMFByteStreamNative(MFByteStream byteStream, MFAttributes attributes)
        {
            IntPtr p;
            int    result = NativeMethods.ExternMFCreateSinkWriterFromURL(null, byteStream.BasePtr, attributes.BasePtr, out p);

            MediaFoundationException.Try(result, "Interops", "MFCreateSinkWriterFromURL");
            return(p);
        }
예제 #30
0
        public unsafe MFAttributes(int initialSize)
        {
            IntPtr zero   = IntPtr.Zero;
            int    result = MFCreateAttributes_(new IntPtr((void *)(&zero)), initialSize);

            MediaFoundationException.Try(result, "interop", "MFCreateAttributes");
            _basePtr = zero.ToPointer();
        }