コード例 #1
0
        public HResult BeginCreateObject(
            IMFByteStream pByteStream,
            string pwszURL,
            MFResolution dwFlags,
            IPropertyStore pProps,             // Can be NULL.
            out object ppIUnknownCancelCookie, // Can be NULL.
            IMFAsyncCallback pCallback,
            object punkState                   // Can be NULL
            )
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                HResult hr;
                m_Log.WriteLine("BeginCreateObject");

                ppIUnknownCancelCookie = null; // We don't return a cancellation cookie.

                if ((pByteStream == null) || (pwszURL == null) || (pCallback == null))
                {
                    throw new COMException("bad stream, url, or callback", (int)HResult.E_INVALIDARG);
                }

                IMFAsyncResult pResult = null;

                WavSource pSource = new WavSource();

                pSource.Open(pByteStream);

                hr = MFExtern.MFCreateAsyncResult(pSource as IMFMediaSource, pCallback, punkState, out pResult);
                MFError.ThrowExceptionForHR(hr);

                hr = MFExtern.MFInvokeCallback(pResult);
                MFError.ThrowExceptionForHR(hr);

                if (pResult != null)
                {
                    Marshal.ReleaseComObject(pResult);
                }
                return(HResult.S_OK);
            }
            catch (Exception e)
            {
                ppIUnknownCancelCookie = null;
                return((HResult)Marshal.GetHRForException(e));
            }
        }
コード例 #2
0
    public HResult BeginCreateObject(string pwszURL,
                                     MFResolution dwFlags,
                                     IPropertyStore pProps,
                                     out object ppIUnknownCancelCookie,
                                     IMFAsyncCallback pCallback,
                                     object pUnkState)
    {
        // The constructor launches an async connect to the url.
        IcyScheme ice = new IcyScheme(pwszURL);

        IMFAsyncResult pResult;
        MFError        hrthrowonerror = MFExtern.MFCreateAsyncResult(
            ice, pCallback, pUnkState, out pResult);

        ppIUnknownCancelCookie = ice;

        hrthrowonerror = MFExtern.MFInvokeCallback(pResult);

        return(HResult.S_OK);
    }
コード例 #3
0
        /// <summary>
        /// Creates a byte stream from a URL.
        /// </summary>
        /// <param name="sourceResolver">A valid IMFSourceResolver instance.</param>
        /// <param name="url">A string that contains the URL to resolve.</param>
        /// <param name="flags">One or more members of the MFResolution enumeration.</param>
        /// <param name="properties">An instance of the IPropertyStore interface of a property store. The method passes the property store to the scheme handler or byte-stream handler that creates the object.</param>
        /// <param name="byteStream">Receives a byte stream that can handle the media file targeted by <paramref name="url"/>.</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 CreateObjectFromURL(this IMFSourceResolver sourceResolver, string url, MFResolution flags, IPropertyStore properties, out IMFByteStream byteStream)
        {
            if (sourceResolver == null)
            {
                throw new ArgumentNullException("sourceResolver");
            }

            flags &= ~MFResolution.MediaSource;
            flags |= MFResolution.ByteStream;

            MFObjectType objectType;
            object       tmp;

            HResult hr = sourceResolver.CreateObjectFromURL(url, flags, properties, out objectType, out tmp);

            byteStream = hr.Succeeded() ? tmp as IMFByteStream : null;

            return(hr);
        }
コード例 #4
0
 /// <summary>
 /// Creates a media source from a Uri.
 /// </summary>
 /// <param name="sourceResolver">A valid IMFSourceResolver instance.</param>
 /// <param name="url">A Uri that contains the URL to resolve.</param>
 /// <param name="flags">One or more members of the MFResolution enumeration.</param>
 /// <param name="properties">An instance of the IPropertyStore interface of a property store. The method passes the property store to the scheme handler or byte-stream handler that creates the object.</param>
 /// <param name="mediaSource">Receives a media source that can handle the media file targeted by <paramref name="url"/>.</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 CreateObjectFromURL(this IMFSourceResolver sourceResolver, Uri url, MFResolution flags, IPropertyStore properties, out IMFMediaSource mediaSource)
 {
     return(CreateObjectFromURL(sourceResolver, url.ToString(), flags, properties, out mediaSource));
 }
コード例 #5
0
 /// <summary>
 /// Creates a media source from a byte stream.
 /// </summary>
 /// <param name="sourceResolver">A valid IMFSourceResolver instance.</param>
 /// <param name="byteStream">An instance of the byte stream's IMFByteStream interface.</param>
 /// <param name="flags">One or more members of the MFResolution enumeration.</param>
 /// <param name="properties">An instance of the IPropertyStore interface of a property store. The method passes the property store to the scheme handler or byte-stream handler that creates the object.</param>
 /// <param name="mediaSource">Receives a media source that can handle the provided byte stream.</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 CreateObjectFromByteStream(this IMFSourceResolver sourceResolver, IMFByteStream byteStream, MFResolution flags, IPropertyStore properties, out IMFMediaSource mediaSource)
 {
     return(CreateObjectFromByteStream(sourceResolver, byteStream, (string)null, flags, properties, out mediaSource));
 }
コード例 #6
0
        public int BeginCreateObject(
            IMFByteStream pByteStream,
            string pwszURL,
            MFResolution dwFlags,
            IPropertyStore pProps,              // Can be NULL.
            out object ppIUnknownCancelCookie,  // Can be NULL.
            IMFAsyncCallback pCallback,
            object punkState                  // Can be NULL
        )
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                int hr;
                m_Log.WriteLine("BeginCreateObject");

                ppIUnknownCancelCookie = null; // We don't return a cancellation cookie.

                if ((pByteStream == null) || (pwszURL == null) || (pCallback == null))
                {
                    throw new COMException("bad stream, url, or callback", E_InvalidArgument);
                }

                IMFAsyncResult pResult = null;

                WavSource pSource = new WavSource();

                pSource.Open(pByteStream);

                hr = MFExtern.MFCreateAsyncResult(pSource as IMFMediaSource, pCallback, punkState, out pResult);
                MFError.ThrowExceptionForHR(hr);

                hr = MFExtern.MFInvokeCallback(pResult);
                MFError.ThrowExceptionForHR(hr);

                if (pResult != null)
                {
                    Marshal.ReleaseComObject(pResult);
                }
                return S_Ok;
            }
            catch (Exception e)
            {
                ppIUnknownCancelCookie = null;
                return Marshal.GetHRForException(e);
            }
        }