summaryrefslogtreecommitdiff
path: root/chromium/media/gpu/windows/d3d11_video_context_wrapper.h
blob: 30beeb950a98f155a8865e858c547c61c8846bce (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2018 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_D3D11_VIDEO_CONTEXT_WRAPPER_H_
#define MEDIA_GPU_WINDOWS_D3D11_VIDEO_CONTEXT_WRAPPER_H_

#include <d3d11_1.h>
#include <wrl/client.h>
#include <memory>

#include "base/memory/raw_ptr.h"
#include "media/gpu/media_gpu_export.h"
#include "media/gpu/windows/d3d11_com_defs.h"

namespace media {

class MEDIA_GPU_EXPORT VideoContextWrapper {
 public:
  VideoContextWrapper() = default;

  VideoContextWrapper(const VideoContextWrapper&) = delete;
  VideoContextWrapper& operator=(const VideoContextWrapper&) = delete;

  virtual ~VideoContextWrapper();
  // D3D11_VIDEO_DECODER_BUFFER_DESC1 and D3D11_VIDEO_DECODER_BUFFER_DESC
  // have radically different sets of member variables, which means that in
  // order to have a converter class, we need to support all fields. They are
  // also in different orders, which prevents using a simple memcpy.
  // It seems we don't currently use any of the D3D11_VIDEO_DECODER_BUFFER_DESC
  // specific fields right now.
  // Fields are named as they appear in the D3D11 Structs.
  struct VideoBufferWrapper {
    // Shared Fields
    D3D11_VIDEO_DECODER_BUFFER_TYPE BufferType;
    UINT DataOffset;
    UINT DataSize;
    raw_ptr<void> pIV;
    UINT IVSize;

    // DESC1-specific fields
    raw_ptr<D3D11_VIDEO_DECODER_SUB_SAMPLE_MAPPING_BLOCK>
        pSubSampleMappingBlock;
    UINT SubSampleMappingCount;
  };

  static std::unique_ptr<VideoContextWrapper> CreateWrapper(
      D3D_FEATURE_LEVEL supported_d3d11_version,
      ComD3D11DeviceContext device_context,
      HRESULT* status);

  // This method signiture is defined to match exactly that of
  // |ID3D11VideoContext::DecoderBeginFrame|.
  virtual HRESULT DecoderBeginFrame(ID3D11VideoDecoder* video_decoder,
                                    ID3D11VideoDecoderOutputView* output_view,
                                    UINT content_key_size,
                                    const void* content_key) = 0;

  // This method signiture is defined to match exactly that of
  // |ID3D11VideoContext::GetDecoderBuffer|.
  virtual HRESULT GetDecoderBuffer(ID3D11VideoDecoder* video_decoder,
                                   D3D11_VIDEO_DECODER_BUFFER_TYPE type,
                                   UINT* buffer_size,
                                   void** buffer) = 0;

  // This method signiture is defined to match exactly that of
  // |ID3D11VideoContext::ReleaseDecoderBuffer|.
  virtual HRESULT ReleaseDecoderBuffer(
      ID3D11VideoDecoder* video_decoder,
      D3D11_VIDEO_DECODER_BUFFER_TYPE type) = 0;

  // This method signiture is defined to match exactly that of
  // |ID3D11VideoContext::DecoderEndFrame|.
  virtual HRESULT DecoderEndFrame(ID3D11VideoDecoder* video_decoder) = 0;

  // This method signiture is defined to match exactly that of
  // |ID3D11VideoContext::SubmitDecoderBuffers|.
  virtual HRESULT SubmitDecoderBuffers(ID3D11VideoDecoder* video_decoder,
                                       UINT num_buffers,
                                       const VideoBufferWrapper* buffers) = 0;
};  // VideoContextWrapper

}  // namespace media

#endif  // MEDIA_GPU_WINDOWS_D3D11_VIDEO_CONTEXT_WRAPPER_H_