Commit 2f702ab1 authored by Chunbo Hua's avatar Chunbo Hua Committed by Commit Bot

Enable H.264 hardware MFT encoder on Windows

Currently Microsoft H.264 encoder MFT is always used as WebRTC external
encoder without hardware acceleration. This change enables H.264
hardware MFT encoder on Windows.

Bug: 982799
Change-Id: Ia33812508034daa99dd3dc1fb64b83cb1d7c8465
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1777521
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarTommi <tommi@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745539}
parent 7a742ea7
...@@ -187,6 +187,7 @@ Chris Tserng <tserng@amazon.com> ...@@ -187,6 +187,7 @@ Chris Tserng <tserng@amazon.com>
Chris Vasselli <clindsay@gmail.com> Chris Vasselli <clindsay@gmail.com>
Christophe Dumez <ch.dumez@samsung.com> Christophe Dumez <ch.dumez@samsung.com>
Christopher Dale <chrelad@gmail.com> Christopher Dale <chrelad@gmail.com>
Chunbo Hua <chunbo.hua@intel.com>
Claudio DeSouza <claudiomdsjr@gmail.com> Claudio DeSouza <claudiomdsjr@gmail.com>
Clemens Fruhwirth <clemens@endorphin.org> Clemens Fruhwirth <clemens@endorphin.org>
Clement Scheelfeldt Skau <clementskau@gmail.com> Clement Scheelfeldt Skau <clementskau@gmail.com>
......
...@@ -65,8 +65,8 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator ...@@ -65,8 +65,8 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator
// Creates an hardware encoder backed IMFTransform instance on |encoder_|. // Creates an hardware encoder backed IMFTransform instance on |encoder_|.
bool CreateHardwareEncoderMFT(); bool CreateHardwareEncoderMFT();
// Initializes and allocates memory for input and output samples. // Initializes and allocates memory for input and output parameters.
bool InitializeInputOutputSamples(VideoCodecProfile output_profile); bool InitializeInputOutputParameters(VideoCodecProfile output_profile);
// Initializes encoder parameters for real-time use. // Initializes encoder parameters for real-time use.
bool SetEncoderModes(); bool SetEncoderModes();
...@@ -82,20 +82,23 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator ...@@ -82,20 +82,23 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator
// Encoding tasks to be run on |encoder_thread_|. // Encoding tasks to be run on |encoder_thread_|.
void EncodeTask(scoped_refptr<VideoFrame> frame, bool force_keyframe); void EncodeTask(scoped_refptr<VideoFrame> frame, bool force_keyframe);
// Processes the input video frame for the encoder.
void ProcessInput(scoped_refptr<VideoFrame> frame, bool force_keyframe);
// Checks for and copies encoded output on |encoder_thread_|. // Checks for and copies encoded output on |encoder_thread_|.
void ProcessOutput(); void ProcessOutput();
// Tries to deliver the input frame to the encoder.
bool TryToDeliverInputFrame(scoped_refptr<VideoFrame> frame,
bool force_keyframe);
// Tries to return a bitstream buffer to the client.
void TryToReturnBitstreamBuffer();
// Inserts the output buffers for reuse on |encoder_thread_|. // Inserts the output buffers for reuse on |encoder_thread_|.
void UseOutputBitstreamBufferTask( void UseOutputBitstreamBufferTask(
std::unique_ptr<BitstreamBufferRef> buffer_ref); std::unique_ptr<BitstreamBufferRef> buffer_ref);
// Copies EncodeOutput into a BitstreamBuffer and returns it to the
// |main_client_|.
void ReturnBitstreamBuffer(
std::unique_ptr<EncodeOutput> encode_output,
std::unique_ptr<MediaFoundationVideoEncodeAccelerator::BitstreamBufferRef>
buffer_ref);
// Changes encode parameters on |encoder_thread_|. // Changes encode parameters on |encoder_thread_|.
void RequestEncodingParametersChangeTask(uint32_t bitrate, void RequestEncodingParametersChangeTask(uint32_t bitrate,
uint32_t framerate); uint32_t framerate);
...@@ -119,14 +122,11 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator ...@@ -119,14 +122,11 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator
size_t bitstream_buffer_size_; size_t bitstream_buffer_size_;
uint32_t frame_rate_; uint32_t frame_rate_;
uint32_t target_bitrate_; uint32_t target_bitrate_;
size_t u_plane_offset_;
size_t v_plane_offset_;
size_t y_stride_;
size_t u_stride_;
size_t v_stride_;
Microsoft::WRL::ComPtr<IMFActivate> activate_;
Microsoft::WRL::ComPtr<IMFTransform> encoder_; Microsoft::WRL::ComPtr<IMFTransform> encoder_;
Microsoft::WRL::ComPtr<ICodecAPI> codec_api_; Microsoft::WRL::ComPtr<ICodecAPI> codec_api_;
Microsoft::WRL::ComPtr<IMFMediaEventGenerator> event_generator_;
DWORD input_stream_id_; DWORD input_stream_id_;
DWORD output_stream_id_; DWORD output_stream_id_;
...@@ -134,8 +134,8 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator ...@@ -134,8 +134,8 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator
Microsoft::WRL::ComPtr<IMFMediaType> imf_input_media_type_; Microsoft::WRL::ComPtr<IMFMediaType> imf_input_media_type_;
Microsoft::WRL::ComPtr<IMFMediaType> imf_output_media_type_; Microsoft::WRL::ComPtr<IMFMediaType> imf_output_media_type_;
bool input_required_;
Microsoft::WRL::ComPtr<IMFSample> input_sample_; Microsoft::WRL::ComPtr<IMFSample> input_sample_;
Microsoft::WRL::ComPtr<IMFSample> output_sample_;
// MediaFoundation session. // MediaFoundation session.
MFSessionLifetime session_; MFSessionLifetime session_;
...@@ -155,7 +155,7 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator ...@@ -155,7 +155,7 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator
// Declared last to ensure that all weak pointers are invalidated before // Declared last to ensure that all weak pointers are invalidated before
// other destructors run. // other destructors run.
base::WeakPtrFactory<MediaFoundationVideoEncodeAccelerator> base::WeakPtrFactory<MediaFoundationVideoEncodeAccelerator>
encoder_task_weak_factory_{this}; encoder_task_weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MediaFoundationVideoEncodeAccelerator); DISALLOW_COPY_AND_ASSIGN(MediaFoundationVideoEncodeAccelerator);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment