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

Unified Diff: media/gpu/media_foundation_video_encode_accelerator_win.h

Issue 2058413003: H264 HW encode using MediaFoundation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: media/gpu/media_foundation_video_encode_accelerator_win.h
diff --git a/media/gpu/media_foundation_video_encode_accelerator_win.h b/media/gpu/media_foundation_video_encode_accelerator_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..6b9a4a22f8312944c5cb44f416937629eb1bd961
--- /dev/null
+++ b/media/gpu/media_foundation_video_encode_accelerator_win.h
@@ -0,0 +1,105 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_GPU_MEDIA_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_H_
+#define CONTENT_COMMON_GPU_MEDIA_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_H_
+
+#include <mfapi.h>
+#include <mfidl.h>
+#include <strmif.h>
+
+#include "base/threading/thread_checker.h"
+#include "base/win/scoped_comptr.h"
+#include "base/win/windows_version.h"
+#include "media/gpu/media_gpu_export.h"
+#include "media/video/video_encode_accelerator.h"
+
+namespace media {
+
+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.
+ : public media::VideoEncodeAccelerator {
+ public:
+ MediaFoundationVideoEncodeAccelerator();
+ ~MediaFoundationVideoEncodeAccelerator() override;
+
+ // media::VideoEncodeAccelerator implementation.
+ media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles()
+ override;
+ bool Initialize(media::VideoPixelFormat input_format,
+ const gfx::Size& input_visible_size,
+ media::VideoCodecProfile output_profile,
+ uint32_t initial_bitrate,
+ Client* client) override;
+ void Encode(const scoped_refptr<media::VideoFrame>& frame,
+ bool force_keyframe) override;
+ void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override;
+ void RequestEncodingParametersChange(uint32_t bitrate,
+ uint32_t framerate) override;
+ void Destroy() override;
+
+ private:
+ // Holds output buffers coming from the client ready to be filled.
+ struct BitstreamBufferRef;
+
+ // Encoding tasks to be run on |encoder_thread_|.
+ void EncodeTask(const scoped_refptr<media::VideoFrame>& frame,
+ bool force_keyframe);
+ void ProcessOutput();
ananta 2016/06/28 22:50:01 Please add newlines between the functions.
emircan 2016/07/02 00:07:38 Done.
+ 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.
+ std::unique_ptr<BitstreamBufferRef> buffer_ref);
+ void RequestEncodingParametersChangeTask(uint32_t bitrate,
+ uint32_t framerate);
+ void DestroyTask();
+
+ // Bitstream buffers ready to be used to return encoded output as a FIFO.
+ std::deque<std::unique_ptr<BitstreamBufferRef>> bitstream_buffer_queue_;
+
+ 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.
+ gfx::Size input_visible_size_;
+ size_t bitstream_buffer_size_;
+ int32_t frame_rate_;
+ int32_t target_bitrate_;
+ size_t u_plane_offset_;
+ size_t v_plane_offset_;
+
+ // Our original calling task runner for the child thread.
+ const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_;
+
+ // To expose client callbacks from VideoEncodeAccelerator.
+ // NOTE: all calls to this object *MUST* be executed on
+ // |client_task_runner_|.
+ base::WeakPtr<Client> client_;
+ std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_;
+
+ base::win::ScopedComPtr<IMFTransform> encoder_;
+ base::win::ScopedComPtr<ICodecAPI> codec_api_;
+
+ DWORD input_stream_count_min_;
+ DWORD input_stream_count_max_;
+ DWORD output_stream_count_min_;
+ DWORD output_stream_count_max_;
+
+ base::win::ScopedComPtr<IMFSample> input_sample_;
+ base::win::ScopedComPtr<IMFSample> output_sample_;
+
+ // Thread checker to enforce that this object is used on a specific thread.
+ // It is pinned on |client_task_runner_| thread.
+ base::ThreadChecker thread_checker_;
+
+ // This thread services tasks posted from the VEA API entry points by the
+ // GPU child thread and CompressionCallback() posted from device thread.
+ base::Thread encoder_thread_;
+ scoped_refptr<base::SingleThreadTaskRunner> encoder_thread_task_runner_;
+
+ // Declared last to ensure that all weak pointers are invalidated before
+ // other destructors run.
+ base::WeakPtr<MediaFoundationVideoEncodeAccelerator> encoder_weak_ptr_;
+ base::WeakPtrFactory<MediaFoundationVideoEncodeAccelerator>
+ encoder_task_weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaFoundationVideoEncodeAccelerator);
+};
+} // namespace content
+
+#endif // CONTENT_COMMON_GPU_MEDIA_MEDIA_FOUNDATION_VIDEO_ENCODE_ACCELERATOR_H_

Powered by Google App Engine
This is Rietveld 408576698