OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_H_ | |
grt (UTC plus 2)
2016/07/14 20:07:25
CONTENT_COMMON -> MEDIA
H_ -> WIN_H_
emircan
2016/07/15 04:58:31
Done. I must have missed it in one of the rebases.
| |
6 #define CONTENT_COMMON_GPU_MEDIA_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_H_ | |
7 | |
8 #include <mfapi.h> | |
9 #include <mfidl.h> | |
10 #include <strmif.h> | |
11 | |
12 #include "base/threading/thread_checker.h" | |
13 #include "base/win/scoped_comptr.h" | |
14 #include "media/gpu/media_gpu_export.h" | |
15 #include "media/video/video_encode_accelerator.h" | |
16 | |
17 namespace media { | |
18 | |
19 // Media Foundation implementation of the VideoEncodeAccelerator interface for | |
20 // Windows. | |
21 // This class is pinned to the thread on which it is constructed and DCHECKs | |
22 // that it is never accessed from any other. It starts an encoder thread on | |
23 // which media::VideoEncodeAccelerator implementation tasks are posted. | |
24 class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator | |
25 : public media::VideoEncodeAccelerator { | |
grt (UTC plus 2)
2016/07/14 20:07:25
nit: omit "media::" here and elsewhere since you'r
emircan
2016/07/15 04:58:31
Done.
| |
26 public: | |
27 MediaFoundationVideoEncodeAccelerator(); | |
28 ~MediaFoundationVideoEncodeAccelerator() override; | |
29 | |
30 // media::VideoEncodeAccelerator implementation. | |
31 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() | |
32 override; | |
33 bool Initialize(media::VideoPixelFormat input_format, | |
34 const gfx::Size& input_visible_size, | |
35 media::VideoCodecProfile output_profile, | |
36 uint32_t initial_bitrate, | |
37 Client* client) override; | |
38 void Encode(const scoped_refptr<media::VideoFrame>& frame, | |
39 bool force_keyframe) override; | |
40 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; | |
41 void RequestEncodingParametersChange(uint32_t bitrate, | |
42 uint32_t framerate) override; | |
43 void Destroy() override; | |
44 | |
45 // Preload dlls required for decoding. | |
46 static void PreSandboxInitialization(); | |
47 | |
48 private: | |
49 // Holds output buffers coming from the client ready to be filled. | |
50 struct BitstreamBufferRef; | |
51 | |
52 // Holds output buffers coming from the encoder. | |
53 class EncodeOutput; | |
54 | |
55 // Initializes and allocates memory for input and output samples. | |
56 bool InitializeInputOutputSamples(); | |
57 | |
58 // Initializes encoder parameters for real-time use. | |
59 bool SetEncoderModes(); | |
60 | |
61 // Encoding tasks to be run on |encoder_thread_|. | |
62 void EncodeTask(const scoped_refptr<media::VideoFrame>& frame, | |
63 bool force_keyframe); | |
64 | |
65 // Checks for and copies encoded output on |encoder_thread_|. | |
66 void ProcessOutput(); | |
67 | |
68 // Inserts the output buffers for reuse on |encoder_thread_|. | |
69 void UseOutputBitstreamBufferTask( | |
70 std::unique_ptr<BitstreamBufferRef> buffer_ref); | |
grt (UTC plus 2)
2016/07/14 20:07:25
#include <memory>
i see many other missing #includ
emircan
2016/07/15 04:58:31
Done.
| |
71 | |
72 // Copies EncodeOutput into a BitstreamBuffer and returns it to the |client_|. | |
73 void ReturnBitstreamBuffer( | |
74 std::unique_ptr<EncodeOutput> encode_output, | |
75 std::unique_ptr<MediaFoundationVideoEncodeAccelerator::BitstreamBufferRef> | |
76 buffer_ref); | |
77 | |
78 // Changes encode parameters on |encoder_thread_|. | |
79 void RequestEncodingParametersChangeTask(uint32_t bitrate, | |
grt (UTC plus 2)
2016/07/14 20:07:25
#include <stdint.h> for uint32_t
emircan
2016/07/15 04:58:31
Done.
| |
80 uint32_t framerate); | |
81 | |
82 // Destroys encode session on |encoder_thread_|. | |
83 void DestroyTask(); | |
84 | |
85 // Bitstream buffers ready to be used to return encoded output as a FIFO. | |
86 std::deque<std::unique_ptr<BitstreamBufferRef>> bitstream_buffer_queue_; | |
grt (UTC plus 2)
2016/07/14 20:07:25
#include <deque>
emircan
2016/07/15 04:58:31
Done.
| |
87 | |
88 // EncodeOutput needs to be copied into a BitstreamBufferRef as a FIFO. | |
89 std::deque<std::unique_ptr<EncodeOutput>> encoder_output_queue_; | |
90 | |
91 gfx::Size input_visible_size_; | |
92 size_t bitstream_buffer_size_; | |
93 int32_t frame_rate_; | |
94 int32_t target_bitrate_; | |
95 size_t u_plane_offset_; | |
96 size_t v_plane_offset_; | |
97 | |
98 // Our original calling task runner for the child thread. | |
99 const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; | |
grt (UTC plus 2)
2016/07/14 20:07:25
do you really require that the caller be bound to
emircan
2016/07/15 04:58:31
It does not specify in the VideoEncodeAccelerator
grt (UTC plus 2)
2016/07/15 07:59:03
Whether or not other parts of the video pipeline r
emircan
2016/07/16 06:56:37
Sounds good. I am going to change this to Sequence
| |
100 | |
101 // To expose client callbacks from VideoEncodeAccelerator. | |
102 // NOTE: all calls to this object *MUST* be executed on | |
103 // |client_task_runner_|. | |
104 base::WeakPtr<Client> client_; | |
105 std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; | |
grt (UTC plus 2)
2016/07/14 20:07:25
this seems backward. does base::CancelableCallback
emircan
2016/07/15 04:58:31
We receive client as a naked ptr in VideoEncodeAcc
| |
106 | |
107 base::win::ScopedComPtr<IMFTransform> encoder_; | |
108 base::win::ScopedComPtr<ICodecAPI> codec_api_; | |
109 | |
110 DWORD input_stream_count_min_; | |
111 DWORD input_stream_count_max_; | |
112 DWORD output_stream_count_min_; | |
113 DWORD output_stream_count_max_; | |
114 | |
115 base::win::ScopedComPtr<IMFSample> input_sample_; | |
116 base::win::ScopedComPtr<IMFSample> output_sample_; | |
117 | |
118 // Thread checker to enforce that this object is used on a specific thread. | |
119 // It is pinned on |client_task_runner_| thread. | |
120 base::ThreadChecker thread_checker_; | |
121 | |
122 // This thread services tasks posted from the VEA API entry points by the | |
123 // GPU child thread and CompressionCallback() posted from device thread. | |
124 base::Thread encoder_thread_; | |
125 scoped_refptr<base::SingleThreadTaskRunner> encoder_thread_task_runner_; | |
126 | |
127 // Declared last to ensure that all weak pointers are invalidated before | |
128 // other destructors run. | |
129 base::WeakPtr<MediaFoundationVideoEncodeAccelerator> encoder_weak_ptr_; | |
130 base::WeakPtrFactory<MediaFoundationVideoEncodeAccelerator> | |
131 encoder_task_weak_factory_; | |
132 | |
133 DISALLOW_COPY_AND_ASSIGN(MediaFoundationVideoEncodeAccelerator); | |
134 }; | |
grt (UTC plus 2)
2016/07/14 20:07:25
nit: blank line after this
emircan
2016/07/15 04:58:31
Done.
| |
135 } // namespace content | |
grt (UTC plus 2)
2016/07/14 20:07:25
media
emircan
2016/07/15 04:58:31
Done.
| |
136 | |
137 #endif // CONTENT_COMMON_GPU_MEDIA_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_H_ | |
OLD | NEW |