/// <summary>
 /// Retrieves the characteristics of the byte stream.
 /// </summary>
 /// <param name="capabilities">Receives a bitwise OR of zero or more flags.</param>
 /// <returns>HRESULT</returns>
 /// <remarks>Use the <see cref="Capabilities"/> property for easier usage with automated error handling.</remarks>
 public unsafe int GetCapabilitiesNative(out MFByteStreamCapsFlags capabilities)
 {
     fixed(void *p = &capabilities)
     {
         return(InteropCalls.CalliMethodPtr(UnsafeBasePtr, p, ((void **)(*(void **)UnsafeBasePtr))[3]));
     }
 }
Exemple #2
0
        protected void SetTargetStream(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType)
        {
            IMFAttributes attributes = null;

            try
            {
                _targetStream = MediaFoundationCore.IStreamToByteStream(new ComStream(stream));

                MFByteStreamCapsFlags flags = MFByteStreamCapsFlags.None;
                int result = _targetStream.GetCapabilities(ref flags);

                attributes = MediaFoundationCore.CreateEmptyAttributes(2);
                attributes.SetUINT32(MediaFoundationAttributes.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1);
                attributes.SetGUID(MediaFoundationAttributes.MF_TRANSCODE_CONTAINERTYPE, containerType);

                _sinkWriter = MediaFoundationCore.CreateSinkWriterFromMFByteStream(_targetStream, attributes);

                _streamIndex = _sinkWriter.AddStream(targetMediaType);
                _sinkWriter.SetInputMediaType(_streamIndex, inputMediaType, null);

                _inputMediaType       = inputMediaType;
                _targetMediaType      = targetMediaType;
                _sourceBytesPerSecond = inputMediaType.AverageBytesPerSecond;

                //initialize the sinkwriter
                _sinkWriter.BeginWriting();
            }
            catch (Exception)
            {
                if (_sinkWriter != null)
                {
                    _sinkWriter.Dispose();
                    _sinkWriter = null;
                }
                if (_targetStream != null)
                {
                    _targetStream.Close();
                    Marshal.ReleaseComObject(_targetStream);
                    _targetStream = null;
                }
                throw;
            }
            finally
            {
                if (attributes != null)
                {
                    Marshal.ReleaseComObject(attributes);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Retrieves the characteristics of the byte stream.
 /// </summary>
 /// <param name="capabilities">Receives a bitwise OR of zero or more flags.</param>
 /// <returns>HRESULT</returns>
 /// <remarks>Use the <see cref="Capabilities"/> property for easier usage with automated error handling.</remarks>
 public unsafe int GetCapabilitiesNative(out MFByteStreamCapsFlags capabilities)
 {
     fixed (void* p = &capabilities)
     {
         return InteropCalls.CalliMethodPtr(UnsafeBasePtr, p, ((void**) (*(void**) UnsafeBasePtr))[3]);
     }
 }