microsoft / FFmpegInterop

This is a code sample to make it easier to use FFmpeg in Windows applications.
Apache License 2.0
1.27k stars 308 forks source link

MSFT: 50055829 - FFmpegInteropByteStreamHandler is closing the byte stream on failure preventing source resolver rollover #310

Closed brbeec closed 2 months ago

brbeec commented 2 months ago

Why is this change being made?

FFmpegInteropByteStreamHandler is closing the byte stream on failure which prevents the source resolver from rolling over and attempting other byte stream handlers when the MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE flag is set for source resolution.

What changed?

I added ByteStreamProxy which can be used to wrap a byte stream and prevent it from being closed unless permitted. It forwards all IMFByteStream calls to the underlying byte stream.

FFmpegInteropByteStreamHandler::CreateMediaSource() uses ByteStreamProxy to wrap the byte stream provided to FFmpegInteropByteStreamHandler::BeginCreateObject() and prevent it from being closed unless the MSS is successfully created and initialized, after which the byte stream will be allowed to close when the media source shuts down.

How was the change tested?

With in-proc WME:

patnels commented 2 months ago

I don't understand why we need this. MSS can be used with non ffmpeg bytestreams, do all bytestreams need this code?

brbeec commented 2 months ago

I don't understand why we need this. MSS can be used with non ffmpeg bytestreams, do all bytestreams need this code?

It's because we use MFCreateStreamOnMFByteStreamEx(); the IRandomAccessStream it returns will close its underlying byte stream when it's destroyed.

Internally MF has similar protections to prevent the byte stream from being closed in various scenarios: