Esempio n. 1
0
        /// <summary>
        /// Gives the caller access to the memory in the buffer, for reading or writing.
        /// </summary>
        /// <param name="maxLength">Receives the maximum amount of data that can be written to the buffer. The same value is returned by the <see cref="GetMaxLength"/> method.</param>
        /// <param name="currentLength">Receives the length of the valid data in the buffer, in bytes. The same value is returned by the <see cref="GetCurrentLength"/> method.</param>
        /// <returns>A pointer to the start of the buffer.</returns>
        /// <remarks>When you are done accessing the buffer, call <see cref="Unlock"/> to unlock the buffer. You must call <see cref="Unlock"/> once for each call to <see cref="Lock()"/>.</remarks>
        public IntPtr Lock(out int maxLength, out int currentLength)
        {
            IntPtr p;

            MediaFoundationException.Try(LockNative(out p, out maxLength, out currentLength), InterfaceName, "Lock");
            return(p);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the major type of the format.
        /// </summary>
        public Guid GetMajorType()
        {
            Guid result;

            MediaFoundationException.Try(GetMajorType(out result), c, "GetMajorType");
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Compares two media types and determines whether they are identical. If they are not
        /// identical, the method indicates how the two formats differ.
        /// </summary>
        public MediaTypeEqualFlags IsEqual(MFMediaType mediaType)
        {
            MediaTypeEqualFlags flags;

            MediaFoundationException.Try(IsEqual(mediaType, out flags), c, "IsEqual");
            return(flags);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public static MFMediaType CreateMediaType()
        {
            IntPtr mediaType;

            MediaFoundationException.Try(NativeMethods.MFCreateMediaType(out mediaType), "Interops", "MFCreateMediaType");
            return(new MFMediaType(mediaType));
        }
Esempio n. 6
0
        /// <summary>
        /// Gets a format that is supported natively by the media source.
        /// </summary>
        /// <returns>HRESULT</returns>
        public MFMediaType GetNativeMediaType(int streamIndex, int mediatypeIndex)
        {
            MFMediaType res;

            MediaFoundationException.Try(GetNativeMediaTypeNative(streamIndex, mediatypeIndex, out res), c, "GetNativeMediaType");
            return(res);
        }
Esempio n. 7
0
        public static IntPtr CreateMemoryBuffer(int length)
        {
            IntPtr ptr;

            MediaFoundationException.Try(MFInterops.MFCreateMemoryBuffer(length, out ptr), "Interops", "MFCreateMemoryBuffer");
            return(ptr);
        }
Esempio n. 8
0
        /// <summary>
        /// Converts a sample with multiple buffers into a sample with a single buffer.
        /// </summary>
        /// <returns>A <see cref="MFMediaBuffer"/> instance. The caller must release the instance.</returns>
        public MFMediaBuffer ConvertToContiguousBuffer()
        {
            MFMediaBuffer buffer;

            MediaFoundationException.Try(ConvertToContiguousBufferNative(out buffer), InterfaceName, "ConvertToContiguousBuffer");
            return(buffer);
        }
Esempio n. 9
0
        /// <summary>
        /// Retrieves the total length of the valid data in all of the buffers in the sample. The length is calculated as the sum of the values retrieved by the <see cref="MFMediaBuffer.GetCurrentLength"/> method.
        /// </summary>
        /// <returns>The total length of the valid data, in bytes.</returns>
        public int GetTotalLength()
        {
            int res;

            MediaFoundationException.Try(GetTotalLengthNative(out res), InterfaceName, "GetTotalLength");
            return(res);
        }
Esempio n. 10
0
        /// <summary>
        /// Retrieves the number of buffers in the sample.
        /// </summary>
        /// <returns>The number of buffers in the sample. A sample might contain zero buffers.</returns>
        public int GetBufferCount()
        {
            int res;

            MediaFoundationException.Try(GetBufferCountNative(out res), InterfaceName, "GetBufferCount");
            return(res);
        }
Esempio n. 11
0
        /// <summary>
        /// Gets a buffer from the sample, by index.
        /// </summary>
        /// <param name="index">Index of the buffer. To find the number of buffers in the sample, call <see cref="GetBufferCount"/>. Buffers are indexed from zero. </param>
        /// <returns>The <see cref="MFMediaBuffer"/> instance. The caller must release the object.</returns>
        /// <remarks>
        /// Note: In most cases, it is safer to use the <see cref="ConvertToContiguousBuffer"/> method.
        /// If the sample contains more than one buffer, the <see cref="ConvertToContiguousBuffer"/> method replaces them with a single buffer, copies the original data into that buffer, and returns the new buffer to the caller.
        /// The copy operation occurs at most once. On subsequent calls, no data is copied.
        /// </remarks>
        public MFMediaBuffer GetBufferByIndex(int index)
        {
            MFMediaBuffer buffer;

            MediaFoundationException.Try(GetBufferByIndexNative(index, out buffer), InterfaceName, "GetBufferByIndex");
            return(buffer);
        }
Esempio n. 12
0
        /// <summary>
        /// Retrieves an alternative representation of the media type. Currently only the DirectShow
        /// AM_MEDIA_TYPE structure is supported.
        /// </summary>
        /// <param name="guidRepresentation"><see cref="Guid"/> that specifies the representation to retrieve. The following values are defined.</param>
        /// <returns>A pointer to a structure that contains the representation. The method allocates the memory for the structure. The caller must release the memory by calling <see cref="FreeRepresentation"/>.</returns>
        /// <remarks>For more information, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms695248(v=vs.85).aspx"/>.</remarks>
        public IntPtr GetRepresentation(Guid guidRepresentation)
        {
            IntPtr result;

            MediaFoundationException.Try(GetRepresentationNative(guidRepresentation, out result), InterfaceName, "GetRepresentation");
            return(result);
        }
Esempio n. 13
0
        /// <summary>
        /// Compares two media types and determines whether they are identical. If they are not
        /// identical, the method indicates how the two formats differ.
        /// </summary>
        /// <param name="mediaType">The <see cref="MFMediaType"/> to compare.</param>
        /// <returns>A bitwise OR of zero or more flags, indicating the degree of similarity between the two media types.</returns>
        public MediaTypeEqualFlags IsEqual(MFMediaType mediaType)
        {
            MediaTypeEqualFlags flags;

            MediaFoundationException.Try(IsEqualNative(mediaType, out flags), InterfaceName, "IsEqual");
            return(flags);
        }
Esempio n. 14
0
        /// <summary>
        /// Gets the major type of the format.
        /// </summary>
        /// <returns>The major type <see cref="Guid"/>. The major type describes the broad category of the format, such as audio or video. For a list of possible values, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa367377(v=vs.85).aspx"/>.</returns>
        public Guid GetMajorType()
        {
            Guid result;

            MediaFoundationException.Try(GetMajorTypeNative(out result), InterfaceName, "GetMajorType");
            return(result);
        }
Esempio n. 15
0
        /// <summary>
        /// Gets an attribute from the underlying media source.
        /// </summary>
        public PropertyVariant GetPresentationAttribute(int streamIndex, Guid guidAttribute)
        {
            PropertyVariant res;

            MediaFoundationException.Try(GetPresentationAttributeNative(streamIndex, guidAttribute, out res), c, "GetPresentationAttribute");
            return(res);
        }
Esempio n. 16
0
        /// <summary>
        /// Currently no flags are defined. Instead, metadata for samples is defined using
        /// attributes. To get attibutes from a sample, use the <see cref="MFAttributes"/> object, which
        /// <see cref="MFSample"/> inherits.
        /// </summary>
        /// <returns>Returns the <see cref="MFSampleFlags.None"/>.</returns>
        public MFSampleFlags GetSampleFlags()
        {
            MFSampleFlags flags;

            MediaFoundationException.Try(GetSampleFlagsNative(out flags), InterfaceName, "GetSampleFlags");
            return(flags);
        }
Esempio n. 17
0
        /// <summary>
        /// Queries whether a stream is selected.
        /// </summary>
        public NativeBool GetStreamSelection(int streamIndex)
        {
            NativeBool result;

            MediaFoundationException.Try(GetStreamSelectionNative(streamIndex, out result), c, "GetStreamSelection");
            return(result);
        }
Esempio n. 18
0
        /// <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), InterfaceName, "GetSampleTime");
            return(res);
        }
Esempio n. 19
0
        /// <summary>
        /// Creates the object associated with this activation object.
        /// </summary>
        /// <param name="riid">Interface identifier (IID) of the requested interface.</param>
        /// <returns>A pointer to the requested interface. The caller must release the interface.</returns>
        public IntPtr ActivateObject(Guid riid)
        {
            IntPtr ptr;

            MediaFoundationException.Try(ActivateObjectNative(riid, out ptr), InterfaceName, "ActivateObject");
            return(ptr);
        }
Esempio n. 20
0
        /// <summary>
        /// Queries the underlying media sink or encoder for an interface.
        /// </summary>
        /// <param name="streamIndex">The zero-based index of a stream to query, or <see cref="MF_SINK_WRITER_MEDIASINK"/> to query the media sink itself.</param>
        /// <param name="guidService">A service identifier GUID, or <see cref="Guid.Empty"/>. If the value is <see cref="Guid.Empty"/>, the method calls QueryInterface to get the requested interface. Otherwise, the method calls IMFGetService::GetService.
        /// For a list of service identifiers, see <see href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms695350(v=vs.85).aspx"/>.</param>
        /// <param name="riid">The interface identifier (IID) of the interface being requested.</param>
        /// <returns>A pointer to the requested interface. The caller must release the interface.</returns>
        public IntPtr GetServiceForStream(int streamIndex, Guid guidService, Guid riid)
        {
            IntPtr t;

            MediaFoundationException.Try(GetServiceForStreamNative(streamIndex, guidService, riid, out t), InterfaceName, "GetServiceForStream");
            return(t);
        }
Esempio n. 21
0
        public static MFMediaType[] GetEncoderMediaTypes(Guid audioSubType)
        {
            IMFCollection collection;

            try
            {
                MediaFoundationException.Try(MFInterops.MFTranscodeGetAudioOutputAvailableTypes(audioSubType, MFTEnumFlags.All, null, out collection),
                                             "Interops",
                                             "MFTranscodeGetAudioOutputAvailableTypes");

                int count;
                MediaFoundationException.Try(collection.GetElementCount(out count), "IMFCollection", "GetElementCount");
                MFMediaType[] mediaTypes = new MFMediaType[count];
                for (int i = 0; i < count; i++)
                {
                    IntPtr ptr;
                    MediaFoundationException.Try(collection.GetElement(i, out ptr), "IMFCollection", "GetElement");

                    mediaTypes[i] = new MFMediaType(ptr);
                }

                Marshal.ReleaseComObject(collection);

                return(mediaTypes);
            }
            catch (MediaFoundationException ex)
            {
                if (ex.ErrorCode == unchecked ((int)0xC00D36D5)) // MF_E_NOT_FOUND
                {
                    return(Enumerable.Empty <MFMediaType>().ToArray());
                }

                throw;
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Adds a stream to the sink writer.
        /// </summary>
        /// <param name="targetMediaType">The target mediatype which specifies the format of the samples that will be written to the file. It does not need to match the input format. To set the input format, call <see cref="SetInputMediaType"/>.</param>
        /// <returns>The zero-based index of the new stream.</returns>
        public int AddStream(MFMediaType targetMediaType)
        {
            int t;

            MediaFoundationException.Try(AddStreamNative(targetMediaType, out t), InterfaceName, "AddStream");
            return(t);
        }
Esempio n. 23
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);
        }
Esempio n. 24
0
        /// <summary>
        /// Gets the current media type for a stream.
        /// </summary>
        public MFMediaType GetCurrentMediaType(int streamIndex)
        {
            MFMediaType res;

            MediaFoundationException.Try(GetCurrentMediaType(streamIndex, out res), c, "GetCurrentMediaType");
            return(res);
        }
Esempio n. 25
0
        public static IntPtr CreateEmptySample()
        {
            IntPtr ptr;

            MediaFoundationException.Try(NativeMethods.MFCreateSample(out ptr), "Interops", "MFCreateSample");
            return(ptr);
        }
Esempio n. 26
0
        /// <summary>
        /// Reads the next sample from the media source.
        /// </summary>
        public MFSample ReadSample(int streamIndex, int controlFlags, out int actualStreamIndex, out MFSourceReaderFlag streamFlags, out long timestamp)
        {
            MFSample sample;

            MediaFoundationException.Try(ReadSampleNative(streamIndex, controlFlags, out actualStreamIndex, out streamFlags, out timestamp, out sample), c, "ReadSample");
            return(sample);
        }
Esempio n. 27
0
        /// <summary>
        /// Queries whether the media type is a temporally compressed format. Temporal compression
        /// uses information from previously decoded samples when decompressing the current sample.
        /// </summary>
        public NativeBool IsCompressedFormat()
        {
            NativeBool result;

            MediaFoundationException.Try(IsCompressedFormat(out result), c, "IsCompressedFormat");
            return(result);
        }
Esempio n. 28
0
        /// <summary>
        /// Queries the underlying media source or decoder for an interface.
        /// </summary>
        public IntPtr GetServiceForStream(int streamIndex, Guid guidService, Guid riid)
        {
            IntPtr ptr = IntPtr.Zero;

            MediaFoundationException.Try(GetServiceForStreamNative(streamIndex, guidService, riid, out ptr), c, "GetServiceForStream");
            return(ptr);
        }
Esempio n. 29
0
        /// <summary>
        /// Retrieves an alternative representation of the media type. Currently only the DirectShow
        /// AM_MEDIA_TYPE structure is supported.
        /// </summary>
        public IntPtr GetRepresentation(Guid guidRepresentation)
        {
            IntPtr result;

            MediaFoundationException.Try(GetRepresentation(guidRepresentation, out result), c, "GetRepresentation");
            return(result);
        }
Esempio n. 30
0
        /// <summary>
        /// Retrieves the allocated size of the buffer.
        /// <seealso cref="MaxLength"/>
        /// </summary>
        /// <returns>The allocated size of the buffer, in bytes.</returns>
        public int GetMaxLength()
        {
            int maxlength;

            MediaFoundationException.Try(GetMaxLengthNative(out maxlength), InterfaceName, "GetMaxLength");
            return(maxlength);
        }