1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
media / gpu / windows / d3d12_video_encoder_wrapper.h [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_GPU_WINDOWS_D3D12_VIDEO_ENCODER_WRAPPER_H_
#define MEDIA_GPU_WINDOWS_D3D12_VIDEO_ENCODER_WRAPPER_H_
#include <d3d12.h>
#include <d3d12video.h>
#include <wrl.h>
#include "base/containers/span.h"
#include "media/base/encoder_status.h"
#include "media/gpu/windows/d3d12_fence.h"
#include "media/gpu/windows/d3d12_helpers.h"
namespace media {
class D3D12VideoEncoderWrapper {
public:
D3D12VideoEncoderWrapper(
Microsoft::WRL::ComPtr<ID3D12VideoEncoder> video_encoder,
Microsoft::WRL::ComPtr<ID3D12VideoEncoderHeap> video_encoder_heap);
~D3D12VideoEncoderWrapper();
bool Initialize();
// Do the encode and wait for the completion of the encoding.
EncoderStatus Encode(
const D3D12_VIDEO_ENCODER_ENCODEFRAME_INPUT_ARGUMENTS& input_arguments,
const D3D12_VIDEO_ENCODER_RECONSTRUCTED_PICTURE& reconstructed_picture);
// Get the number of bytes written to the bitstream buffer or log the encoding
// error.
EncoderStatus::Or<uint64_t> GetEncodedBitstreamWrittenBytesCount() const;
// Readback bitstream from GPU memory to |data|. The |size| must be no greater
// than the value returned by |GetEncodedBitstreamWrittenBytesCount()|.
EncoderStatus ReadbackBitstream(base::span<uint8_t> data) const;
private:
Microsoft::WRL::ComPtr<ID3D12VideoEncoder> video_encoder_;
Microsoft::WRL::ComPtr<ID3D12VideoEncoderHeap> video_encoder_heap_;
Microsoft::WRL::ComPtr<ID3D12CommandQueue> command_queue_;
Microsoft::WRL::ComPtr<ID3D12CommandAllocator> command_allocator_;
Microsoft::WRL::ComPtr<ID3D12VideoEncodeCommandList2> command_list_;
scoped_refptr<D3D12Fence> fence_;
Microsoft::WRL::ComPtr<ID3D12Resource> bitstream_buffer_;
Microsoft::WRL::ComPtr<ID3D12Resource> opaque_metadata_buffer_;
Microsoft::WRL::ComPtr<ID3D12Resource> metadata_buffer_;
D3D12_VIDEO_ENCODER_ENCODEFRAME_OUTPUT_ARGUMENTS output_arguments_{};
D3D12_VIDEO_ENCODER_RESOLVE_METADATA_INPUT_ARGUMENTS
resolve_metadata_input_arguments_{};
D3D12_VIDEO_ENCODER_RESOLVE_METADATA_OUTPUT_ARGUMENTS
resolve_metadata_output_arguments_{};
};
} // namespace media
#endif // MEDIA_GPU_WINDOWS_D3D12_VIDEO_ENCODER_WRAPPER_H_