gstreamer/sys/mediafoundation
Seungha Yang 6195fcf857 mfvideoenc: Improve latency performance for hardware encoder
Unlike software MFT (Media Foundation Transform) which is synchronous
in terms of processing input and output data, hardware MFT works
in asynchronous mode. output data might not be available right after
we pushed one input data into MFT.
Note that async MFT will fire two events, one is "METransformNeedInput"
which happens when MFT can accept more input data,
and the other is "METransformHaveOutput", that's for signaling
there's pending data which can be outputted immediately.

To listen the events, we can wait synchronously via
IMFMediaEventGenerator::GetEvent() or make use of IMFAsyncCallback
object which is asynchronous way and the event will be notified
from Media Foundation's internal worker queue thread.

To handle such asynchronous operation, previous working flow was
as follows (IMFMediaEventGenerator::GetEvent() was used for now)
- Check if there is pending output data and push the data toward downstream.
- Pulling events (from streaming thread) until there's at least
  one pending "METransformNeedInput" event
- Then, push one data into MFT from streaming thread
- Check if there is pending "METransformHaveOutput" again.
  If there is, push new output data to downstream
  (unlikely there is pending output data at this moment)

Above flow was processed from upstream streaming thread. That means
even if there's available output data, it could be outputted later
when the next buffer is pushed from upstream streaming thread.
It would introduce at least one frame latency in case of live stream.

To reduce such latency, this commit modifies the flow to be fully
asynchronous like hardware MFT was designed and to be able to
output encoded data whenever it's available. More specifically,
IMFAsyncCallback object will be used for handling
"METransformNeedInput" and "METransformHaveOutput" events from
Media Foundation's internal thread, and new output data will be
also outputted from the Media Foundation's thread.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1520>
2020-12-19 18:56:33 +00:00
..
AsyncOperations.h mediafoundation: Add support video capture on UWP app 2020-05-25 15:09:20 +00:00
gstmfaacenc.cpp mediafoundation: Add support for AAC encoding 2020-05-27 10:34:47 +00:00
gstmfaacenc.h mediafoundation: Add support for AAC encoding 2020-05-27 10:34:47 +00:00
gstmfaudioenc.cpp plugins: Update for documentation of Windows plugins 2020-07-02 17:21:29 +02:00
gstmfaudioenc.h mediafoundation: Add support for AAC encoding 2020-05-27 10:34:47 +00:00
gstmfcapturewinrt.cpp mfvideosrc: Set timestamp on buffer when it's captured 2020-09-10 10:21:00 +00:00
gstmfcapturewinrt.h mfvideosrc: Add a new property for ICoreDispatcher setting 2020-07-26 12:52:15 +00:00
gstmfdevice.c mfvideosrc: Add a new property for ICoreDispatcher setting 2020-07-26 12:52:15 +00:00
gstmfdevice.h mediafoundation: Fix redefinition of variables. 2020-12-16 18:48:12 +00:00
gstmfh264enc.cpp plugins: Update for documentation of Windows plugins 2020-07-02 17:21:29 +02:00
gstmfh264enc.h mediafoundation: Add h264 encoder 2020-04-28 14:37:31 +00:00
gstmfh265enc.cpp plugins: Update for documentation of Windows plugins 2020-07-02 17:21:29 +02:00
gstmfh265enc.h mediafoundation: Add h265 encoder 2020-04-28 14:37:31 +00:00
gstmfmp3enc.cpp mediafoundation: Add support MP3 audio encoding 2020-05-27 10:34:47 +00:00
gstmfmp3enc.h mediafoundation: Add support MP3 audio encoding 2020-05-27 10:34:47 +00:00
gstmfsourceobject.c mfvideosrc: Set timestamp on buffer when it's captured 2020-09-10 10:21:00 +00:00
gstmfsourceobject.h mfvideosrc: Set timestamp on buffer when it's captured 2020-09-10 10:21:00 +00:00
gstmfsourcereader.cpp mfvideosrc: Use only the first video stream per device 2020-10-08 20:43:58 +00:00
gstmfsourcereader.h mediafoundation: Introduce Microsoft Media Foundation plugin 2020-04-28 14:37:31 +00:00
gstmftransform.cpp mfvideoenc: Improve latency performance for hardware encoder 2020-12-19 18:56:33 +00:00
gstmftransform.h mfvideoenc: Improve latency performance for hardware encoder 2020-12-19 18:56:33 +00:00
gstmfutils.cpp mediafoundation: Correct wrong raw video format mapping 2020-08-17 21:39:13 +09:00
gstmfutils.h mfutils: Move IMediaType release function to common utility 2020-05-27 10:34:47 +00:00
gstmfvideobuffer.cpp mfvideoenc: Add support for zero-copy encoding 2020-09-09 07:25:52 +00:00
gstmfvideobuffer.h mfvideoenc: Add support for zero-copy encoding 2020-09-09 07:25:52 +00:00
gstmfvideoenc.cpp mfvideoenc: Improve latency performance for hardware encoder 2020-12-19 18:56:33 +00:00
gstmfvideoenc.h mfvideoenc: Improve latency performance for hardware encoder 2020-12-19 18:56:33 +00:00
gstmfvideosrc.c mfvideosrc: Set timestamp on buffer when it's captured 2020-09-10 10:21:00 +00:00
gstmfvideosrc.h mediafoundation: Introduce Microsoft Media Foundation plugin 2020-04-28 14:37:31 +00:00
gstmfvp9enc.cpp plugins: Update for documentation of Windows plugins 2020-07-02 17:21:29 +02:00
gstmfvp9enc.h mediafoundation: Add VP9 encoder element 2020-06-22 07:58:03 +00:00
gststrmif.h mediafoundation: Add h264 encoder 2020-04-28 14:37:31 +00:00
mediacapturewrapper.cpp mfvideosrc: Set timestamp on buffer when it's captured 2020-09-10 10:21:00 +00:00
mediacapturewrapper.h mfvideosrc: Set timestamp on buffer when it's captured 2020-09-10 10:21:00 +00:00
meson.build mfvideoenc: Add support for zero-copy encoding 2020-09-09 07:25:52 +00:00
plugin.c mfvideoenc: Add support for zero-copy encoding 2020-09-09 07:25:52 +00:00