Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: media/gpu/media_foundation_video_encode_accelerator_win.h

Issue 2427053002: Move video encode accelerator IPC messages to GPU IO thread (Closed)
Patch Set: posciak@ comments. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_GPU_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_WIN_H_ 5 #ifndef MEDIA_GPU_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_WIN_H_
6 #define MEDIA_GPU_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_WIN_H_ 6 #define MEDIA_GPU_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_WIN_H_
7 7
8 #include <mfapi.h> 8 #include <mfapi.h>
9 #include <mfidl.h> 9 #include <mfidl.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 #include <strmif.h> 11 #include <strmif.h>
12 12
13 #include <deque> 13 #include <deque>
14 #include <memory> 14 #include <memory>
15 15
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/sequenced_task_runner.h"
19 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
20 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
21 #include "base/threading/thread_checker.h"
22 #include "base/win/scoped_comptr.h" 20 #include "base/win/scoped_comptr.h"
23 #include "media/gpu/media_gpu_export.h" 21 #include "media/gpu/media_gpu_export.h"
24 #include "media/video/video_encode_accelerator.h" 22 #include "media/video/video_encode_accelerator.h"
25 23
26 namespace media { 24 namespace media {
27 25
28 // Media Foundation implementation of the VideoEncodeAccelerator interface for 26 // Media Foundation implementation of the VideoEncodeAccelerator interface for
29 // Windows. 27 // Windows.
30 // This class saves the task runner on which it is constructed and returns 28 // This class saves the task runner on which it is constructed and runs client
31 // encoded data to the client using that same task runner. This class has 29 // callbacks using that same task runner. If TryToSetupEncodeOnSeparateThread()
32 // DCHECKs to makes sure that methods are called in sequence. It starts an 30 // is called, it uses the given |encode_task_runner| instead to return encoded
33 // internal encoder thread on which VideoEncodeAccelerator implementation tasks 31 // data. This class has DCHECKs to makes sure that methods are called in the
34 // are posted. 32 // correct task runners. It starts an internal encoder thread on which
33 // VideoEncodeAccelerator implementation tasks are posted.
35 class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator 34 class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator
36 : public VideoEncodeAccelerator { 35 : public VideoEncodeAccelerator {
37 public: 36 public:
38 MediaFoundationVideoEncodeAccelerator(); 37 MediaFoundationVideoEncodeAccelerator();
39 38
40 // VideoEncodeAccelerator implementation. 39 // VideoEncodeAccelerator implementation.
41 VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() override; 40 VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() override;
42 bool Initialize(VideoPixelFormat input_format, 41 bool Initialize(VideoPixelFormat input_format,
43 const gfx::Size& input_visible_size, 42 const gfx::Size& input_visible_size,
44 VideoCodecProfile output_profile, 43 VideoCodecProfile output_profile,
45 uint32_t initial_bitrate, 44 uint32_t initial_bitrate,
46 Client* client) override; 45 Client* client) override;
47 void Encode(const scoped_refptr<VideoFrame>& frame, 46 void Encode(const scoped_refptr<VideoFrame>& frame,
48 bool force_keyframe) override; 47 bool force_keyframe) override;
49 void UseOutputBitstreamBuffer(const BitstreamBuffer& buffer) override; 48 void UseOutputBitstreamBuffer(const BitstreamBuffer& buffer) override;
50 void RequestEncodingParametersChange(uint32_t bitrate, 49 void RequestEncodingParametersChange(uint32_t bitrate,
51 uint32_t framerate) override; 50 uint32_t framerate) override;
52 void Destroy() override; 51 void Destroy() override;
52 bool TryToSetupEncodeOnSeparateThread(
53 const base::WeakPtr<Client>& encode_client,
54 const scoped_refptr<base::SingleThreadTaskRunner>& encode_task_runner)
55 override;
53 56
54 // Preload dlls required for encoding. 57 // Preload dlls required for encoding.
55 static void PreSandboxInitialization(); 58 static void PreSandboxInitialization();
56 59
57 protected: 60 protected:
58 ~MediaFoundationVideoEncodeAccelerator() override; 61 ~MediaFoundationVideoEncodeAccelerator() override;
59 62
60 private: 63 private:
61 // Holds output buffers coming from the client ready to be filled. 64 // Holds output buffers coming from the client ready to be filled.
62 struct BitstreamBufferRef; 65 struct BitstreamBufferRef;
63 66
64 // Holds output buffers coming from the encoder. 67 // Holds output buffers coming from the encoder.
65 class EncodeOutput; 68 class EncodeOutput;
66 69
67 // Creates an hardware encoder backed IMFTransform instance on |encoder_|. 70 // Creates an hardware encoder backed IMFTransform instance on |encoder_|.
68 bool CreateHardwareEncoderMFT(); 71 bool CreateHardwareEncoderMFT();
69 72
70 // Initializes and allocates memory for input and output samples. 73 // Initializes and allocates memory for input and output samples.
71 bool InitializeInputOutputSamples(); 74 bool InitializeInputOutputSamples();
72 75
73 // Initializes encoder parameters for real-time use. 76 // Initializes encoder parameters for real-time use.
74 bool SetEncoderModes(); 77 bool SetEncoderModes();
75 78
76 // Helper function to notify the client of an error on |client_task_runner_|. 79 // Helper function to notify the client of an error on
80 // |main_client_task_runner_|.
77 void NotifyError(VideoEncodeAccelerator::Error error); 81 void NotifyError(VideoEncodeAccelerator::Error error);
78 82
79 // Encoding tasks to be run on |encoder_thread_|. 83 // Encoding tasks to be run on |encoder_thread_|.
80 void EncodeTask(scoped_refptr<VideoFrame> frame, bool force_keyframe); 84 void EncodeTask(scoped_refptr<VideoFrame> frame, bool force_keyframe);
81 85
82 // Checks for and copies encoded output on |encoder_thread_|. 86 // Checks for and copies encoded output on |encoder_thread_|.
83 void ProcessOutput(); 87 void ProcessOutput();
84 88
85 // Inserts the output buffers for reuse on |encoder_thread_|. 89 // Inserts the output buffers for reuse on |encoder_thread_|.
86 void UseOutputBitstreamBufferTask( 90 void UseOutputBitstreamBufferTask(
87 std::unique_ptr<BitstreamBufferRef> buffer_ref); 91 std::unique_ptr<BitstreamBufferRef> buffer_ref);
88 92
89 // Copies EncodeOutput into a BitstreamBuffer and returns it to the |client_|. 93 // Copies EncodeOutput into a BitstreamBuffer and returns it to the
94 // |encode_client_|.
90 void ReturnBitstreamBuffer( 95 void ReturnBitstreamBuffer(
91 std::unique_ptr<EncodeOutput> encode_output, 96 std::unique_ptr<EncodeOutput> encode_output,
92 std::unique_ptr<MediaFoundationVideoEncodeAccelerator::BitstreamBufferRef> 97 std::unique_ptr<MediaFoundationVideoEncodeAccelerator::BitstreamBufferRef>
93 buffer_ref); 98 buffer_ref);
94 99
95 // Changes encode parameters on |encoder_thread_|. 100 // Changes encode parameters on |encoder_thread_|.
96 void RequestEncodingParametersChangeTask(uint32_t bitrate, 101 void RequestEncodingParametersChangeTask(uint32_t bitrate,
97 uint32_t framerate); 102 uint32_t framerate);
98 103
99 // Destroys encode session on |encoder_thread_|. 104 // Destroys encode session on |encoder_thread_|.
(...skipping 18 matching lines...) Expand all
118 base::win::ScopedComPtr<IMFTransform> encoder_; 123 base::win::ScopedComPtr<IMFTransform> encoder_;
119 base::win::ScopedComPtr<ICodecAPI> codec_api_; 124 base::win::ScopedComPtr<ICodecAPI> codec_api_;
120 125
121 base::win::ScopedComPtr<IMFMediaType> imf_input_media_type_; 126 base::win::ScopedComPtr<IMFMediaType> imf_input_media_type_;
122 base::win::ScopedComPtr<IMFMediaType> imf_output_media_type_; 127 base::win::ScopedComPtr<IMFMediaType> imf_output_media_type_;
123 128
124 base::win::ScopedComPtr<IMFSample> input_sample_; 129 base::win::ScopedComPtr<IMFSample> input_sample_;
125 base::win::ScopedComPtr<IMFSample> output_sample_; 130 base::win::ScopedComPtr<IMFSample> output_sample_;
126 131
127 // To expose client callbacks from VideoEncodeAccelerator. 132 // To expose client callbacks from VideoEncodeAccelerator.
128 // NOTE: all calls to this object *MUST* be executed on |client_task_runner_|. 133 // NOTE: all calls to this object *MUST* be executed on
129 base::WeakPtr<Client> client_; 134 // |main_client_task_runner_|.
130 std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; 135 base::WeakPtr<Client> main_client_;
136 std::unique_ptr<base::WeakPtrFactory<Client>> main_client_weak_factory_;
137 scoped_refptr<base::SingleThreadTaskRunner> main_client_task_runner_;
131 138
132 // Our original calling task runner for the child thread. 139 // Used to run client callback BitstreamBufferReady() on the encode task
Pawel Osciak 2016/10/27 01:45:19 s/encode task runner/encode_client_task_runner_/
emircan 2016/10/27 17:53:30 Done.
133 const scoped_refptr<base::SequencedTaskRunner> client_task_runner_; 140 // runner if given by TryToSetupEncodeOnSeparateThread().
134 // Sequence checker to enforce that the methods of this object are called in 141 base::WeakPtr<Client> encode_client_;
135 // sequence. 142 scoped_refptr<base::SingleThreadTaskRunner> encode_client_task_runner_;
136 base::SequenceChecker sequence_checker_;
137 143
138 // This thread services tasks posted from the VEA API entry points by the 144 // This thread services tasks posted from the VEA API entry points by the
139 // GPU child thread and CompressionCallback() posted from device thread. 145 // GPU child thread and CompressionCallback() posted from device thread.
140 base::Thread encoder_thread_; 146 base::Thread encoder_thread_;
141 scoped_refptr<base::SingleThreadTaskRunner> encoder_thread_task_runner_; 147 scoped_refptr<base::SingleThreadTaskRunner> encoder_thread_task_runner_;
142 148
143 // Declared last to ensure that all weak pointers are invalidated before 149 // Declared last to ensure that all weak pointers are invalidated before
144 // other destructors run. 150 // other destructors run.
145 base::WeakPtrFactory<MediaFoundationVideoEncodeAccelerator> 151 base::WeakPtrFactory<MediaFoundationVideoEncodeAccelerator>
146 encoder_task_weak_factory_; 152 encoder_task_weak_factory_;
147 153
148 DISALLOW_COPY_AND_ASSIGN(MediaFoundationVideoEncodeAccelerator); 154 DISALLOW_COPY_AND_ASSIGN(MediaFoundationVideoEncodeAccelerator);
149 }; 155 };
150 156
151 } // namespace media 157 } // namespace media
152 158
153 #endif // MEDIA_GPU_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_WIN_H_ 159 #endif // MEDIA_GPU_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698