Esempio n. 1
0
MediaSource* MediaSource::Open(PCWSTR url)
{
  MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;

  IMFSourceResolver* mfSourceResolver = nullptr;
  IMFMediaSource* mfMediaSource = nullptr;
  IUnknown* pSource = nullptr;

  // Create the source resolver.
  HRESULT hr = MFCreateSourceResolver(&mfSourceResolver);

  // Use the source resolver to create the media source.

  hr = mfSourceResolver->CreateObjectFromURL(
    url,                       // URL of the source.
    MF_RESOLUTION_MEDIASOURCE,  // Create a source object.
    nullptr,                       // Optional property store.
    &ObjectType,        // Receives the created object type. 
    &pSource            // Receives a pointer to the media source.
  );

  // Get the IMFMediaSource interface from the media source.
  hr = pSource->QueryInterface(IID_PPV_ARGS(&mfMediaSource));

  if (pSource) pSource->Release();
  if (mfSourceResolver) mfSourceResolver->Release();

  return new MediaSource(mfMediaSource);
}
HRESULT CreateMediaSource(
    const WCHAR *sURL,  // The URL of the file to open.
    IMFMediaSource** ppMediaSource // Receives a pointer to the media source.
    )
{
    if (!sURL)
    {
        return E_INVALIDARG;
    }

    if (!ppMediaSource)
    {
        return E_POINTER;
    }

    HRESULT hr = S_OK;
    
    MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;

    IMFSourceResolver* pSourceResolver = NULL;
    IUnknown* pUnkSource = NULL;

    // Create the source resolver.
    hr = MFCreateSourceResolver(&pSourceResolver);


    // Use the source resolver to create the media source.
    
    if (SUCCEEDED(hr))
    {
        hr = pSourceResolver->CreateObjectFromURL(
            sURL,                       // URL of the source.
            MF_RESOLUTION_MEDIASOURCE,  // Create a source object.
            NULL,                       // Optional property store.
            &ObjectType,                // Receives the created object type. 
            &pUnkSource                 // Receives a pointer to the media source.
            );
    }

    // Get the IMFMediaSource from the IUnknown pointer.
    if (SUCCEEDED(hr))
    {
        hr = pUnkSource->QueryInterface(IID_PPV_ARGS(ppMediaSource));
    }

    SafeRelease(&pSourceResolver);
    SafeRelease(&pUnkSource);
    return hr;
}
Esempio n. 3
0
/**
 * Creates a Media Source.
 *
 * @param env JNI env
 * @param path path
 * @param ppMediaSrc media source
 * @return HRESULT
 */
HRESULT mf_createMediaSource(JNIEnv *env, jstring path, IMFMediaSource **ppMediaSrc) {

    HRESULT res = S_OK;
    const LPWSTR pwszFilePath = (LPWSTR)env->GetStringChars(path, NULL);
    IUnknown *pUnk = NULL;
    IMFSourceResolver *pResolver = NULL;
    MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;


    *ppMediaSrc = NULL;
    res = MFCreateSourceResolver(&pResolver);
    if (res != S_OK || pResolver == NULL) {
        throwUnsupportedAudioFileExceptionIfError(env, res, "Failed to create source resolver");
        goto bail;
    }
        // File format may not match its extension so we ignore the extension
        res = pResolver->CreateObjectFromURL(
            pwszFilePath, 
            MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_READ | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE, 
            NULL, 
            &ObjectType, 
            &pUnk);
    if (res != S_OK || pUnk == NULL) {
        throwUnsupportedAudioFileExceptionIfError(env, res, "Failed to create object from url");
        goto bail;
    }
    res = pUnk->QueryInterface(
            IID_IMFMediaSource, 
            (void**)(ppMediaSrc));
    if (res != S_OK) {
        throwUnsupportedAudioFileExceptionIfError(env, res, "Failed get media source interface");
        goto bail;
    }

bail:

    SAFE_RELEASE(pResolver)
    SAFE_RELEASE(pUnk)
    env->ReleaseStringChars(path, (jchar *)pwszFilePath);

    return res;
}
Esempio n. 4
0
HRESULT CPlayer::CreateMediaSource(const WCHAR *sURL)
{
    TRACE((L"CPlayer::CreateMediaSource\n"));

    HRESULT hr = S_OK;
    MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;

    IMFSourceResolver* pSourceResolver = NULL;
    IUnknown* pSource = NULL;

    SAFE_RELEASE(m_pSource);

    // Create the source resolver.
    CHECK_HR(hr = MFCreateSourceResolver(&pSourceResolver));

    // Use the source resolver to create the media source.

    // Note: For simplicity this sample uses the synchronous method on
    // IMFSourceResolver to create the media source. However, creating a 
    // media source can take a noticeable amount of time, especially for
    // a network source. For a more responsive UI, use the asynchronous
    // BeginCreateObjectFromURL method.

    CHECK_HR(hr = pSourceResolver->CreateObjectFromURL(
                sURL,                       // URL of the source.
                MF_RESOLUTION_MEDIASOURCE,  // Create a source object.
                NULL,                       // Optional property store.
                &ObjectType,                // Receives the created object type. 
                &pSource                    // Receives a pointer to the media source.
            ));

    // Get the IMFMediaSource interface from the media source.
    CHECK_HR(hr = pSource->QueryInterface(__uuidof(IMFMediaSource), (void**)&m_pSource));

done:
    SAFE_RELEASE(pSourceResolver);
    SAFE_RELEASE(pSource);
    return hr;
}
/** Opens file from memory */
FIntPoint FImfVideoPlayer::OpenFile( void* FileSource, int32 Size, ECodecMovie::Type CodecType, FImfSampleGrabberCallback* SampleGrabberCallback )
{
	FIntPoint OutDimensions = FIntPoint::ZeroValue;
	HRESULT HResult = S_OK;

	/* Create Media Session */
	HResult = MFCreateMediaSession( NULL, &MediaSession );
	check( SUCCEEDED( HResult ) );

	/* Begin Get Event */
	HResult = MediaSession->BeginGetEvent( this, NULL );
	check( SUCCEEDED( HResult ) );

	IMFSourceResolver* SourceResolver = NULL;
	IUnknown* Source = NULL;

	/* Create Source Resolver */
	HResult = MFCreateSourceResolver( &SourceResolver );
	check( SUCCEEDED( HResult ) );

	/* Determine codec type */
	FString Ext = ".null";
	switch( CodecType )
	{
	case ECodecMovie::CodecMovie_Wmv:
		Ext = ".wmv";
		break;

	/* Currently not working */
	case ECodecMovie::CodecMovie_Mp4:
		Ext = ".mp4";
		break;

	case ECodecMovie::CodecMovie_Avi:
		Ext = ".avi";
		break;
	}

	/* Create custom ByteStream */
	FImfByteStream* NewByteStream = new FImfByteStream( FileSource, Size );

	/* Create Media Source */
	MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;
	HResult = SourceResolver->CreateObjectFromByteStream( NewByteStream, *Ext, MF_RESOLUTION_MEDIASOURCE, NULL, &ObjectType, &Source );
	SourceResolver->Release( );

	if( SUCCEEDED( HResult ) )
	{
		HResult = Source->QueryInterface( IID_PPV_ARGS( &MediaSource ) );
		Source->Release( );

		/* Set Playback Topology */
		OutDimensions = SetPlaybackTopology( SampleGrabberCallback );
	}
	else
	{
		/* Failed */
		MovieIsFinished.Set( 1 );
	}

	return OutDimensions;
}