Chromium Code Reviews| 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_ | |
| 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 "base/win/windows_version.h" | |
| 15 #include "media/gpu/media_gpu_export.h" | |
| 16 #include "media/video/video_encode_accelerator.h" | |
| 17 | |
| 18 namespace media { | |
| 19 | |
| 20 class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator | |
|
ananta
2016/06/28 22:50:01
Please add some documentation on what the threadin
emircan
2016/07/02 00:07:38
Done.
| |
| 21 : public media::VideoEncodeAccelerator { | |
| 22 public: | |
| 23 MediaFoundationVideoEncodeAccelerator(); | |
| 24 ~MediaFoundationVideoEncodeAccelerator() override; | |
| 25 | |
| 26 // media::VideoEncodeAccelerator implementation. | |
| 27 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() | |
| 28 override; | |
| 29 bool Initialize(media::VideoPixelFormat input_format, | |
| 30 const gfx::Size& input_visible_size, | |
| 31 media::VideoCodecProfile output_profile, | |
| 32 uint32_t initial_bitrate, | |
| 33 Client* client) override; | |
| 34 void Encode(const scoped_refptr<media::VideoFrame>& frame, | |
| 35 bool force_keyframe) override; | |
| 36 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; | |
| 37 void RequestEncodingParametersChange(uint32_t bitrate, | |
| 38 uint32_t framerate) override; | |
| 39 void Destroy() override; | |
| 40 | |
| 41 private: | |
| 42 // Holds output buffers coming from the client ready to be filled. | |
| 43 struct BitstreamBufferRef; | |
| 44 | |
| 45 // Encoding tasks to be run on |encoder_thread_|. | |
| 46 void EncodeTask(const scoped_refptr<media::VideoFrame>& frame, | |
| 47 bool force_keyframe); | |
| 48 void ProcessOutput(); | |
|
ananta
2016/06/28 22:50:01
Please add newlines between the functions.
emircan
2016/07/02 00:07:38
Done.
| |
| 49 void UseOutputBitstreamBufferTask( | |
|
ananta
2016/06/28 22:50:01
Some commentary about what these functions do woul
emircan
2016/07/02 00:07:38
Done.
| |
| 50 std::unique_ptr<BitstreamBufferRef> buffer_ref); | |
| 51 void RequestEncodingParametersChangeTask(uint32_t bitrate, | |
| 52 uint32_t framerate); | |
| 53 void DestroyTask(); | |
| 54 | |
| 55 // Bitstream buffers ready to be used to return encoded output as a FIFO. | |
| 56 std::deque<std::unique_ptr<BitstreamBufferRef>> bitstream_buffer_queue_; | |
| 57 | |
| 58 base::win::Version win_version_; | |
|
ananta
2016/06/28 22:50:01
Why do you need to save the version?
emircan
2016/07/02 00:07:38
Removed.
| |
| 59 gfx::Size input_visible_size_; | |
| 60 size_t bitstream_buffer_size_; | |
| 61 int32_t frame_rate_; | |
| 62 int32_t target_bitrate_; | |
| 63 size_t u_plane_offset_; | |
| 64 size_t v_plane_offset_; | |
| 65 | |
| 66 // Our original calling task runner for the child thread. | |
| 67 const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; | |
| 68 | |
| 69 // To expose client callbacks from VideoEncodeAccelerator. | |
| 70 // NOTE: all calls to this object *MUST* be executed on | |
| 71 // |client_task_runner_|. | |
| 72 base::WeakPtr<Client> client_; | |
| 73 std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; | |
| 74 | |
| 75 base::win::ScopedComPtr<IMFTransform> encoder_; | |
| 76 base::win::ScopedComPtr<ICodecAPI> codec_api_; | |
| 77 | |
| 78 DWORD input_stream_count_min_; | |
| 79 DWORD input_stream_count_max_; | |
| 80 DWORD output_stream_count_min_; | |
| 81 DWORD output_stream_count_max_; | |
| 82 | |
| 83 base::win::ScopedComPtr<IMFSample> input_sample_; | |
| 84 base::win::ScopedComPtr<IMFSample> output_sample_; | |
| 85 | |
| 86 // Thread checker to enforce that this object is used on a specific thread. | |
| 87 // It is pinned on |client_task_runner_| thread. | |
| 88 base::ThreadChecker thread_checker_; | |
| 89 | |
| 90 // This thread services tasks posted from the VEA API entry points by the | |
| 91 // GPU child thread and CompressionCallback() posted from device thread. | |
| 92 base::Thread encoder_thread_; | |
| 93 scoped_refptr<base::SingleThreadTaskRunner> encoder_thread_task_runner_; | |
| 94 | |
| 95 // Declared last to ensure that all weak pointers are invalidated before | |
| 96 // other destructors run. | |
| 97 base::WeakPtr<MediaFoundationVideoEncodeAccelerator> encoder_weak_ptr_; | |
| 98 base::WeakPtrFactory<MediaFoundationVideoEncodeAccelerator> | |
| 99 encoder_task_weak_factory_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(MediaFoundationVideoEncodeAccelerator); | |
| 102 }; | |
| 103 } // namespace content | |
| 104 | |
| 105 #endif // CONTENT_COMMON_GPU_MEDIA_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_H_ | |
| OLD | NEW |