summaryrefslogtreecommitdiff
path: root/chromium/media/mojo/mojom/video_encode_accelerator.mojom
blob: 9e720fdf94ae3c0617b749305dfea5c4cd13f328 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// Copyright 2017 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.

module media.mojom;

import "media/mojo/mojom/media_log.mojom";
import "media/mojo/mojom/media_types.mojom";
import "mojo/public/mojom/base/shared_memory.mojom";
import "mojo/public/mojom/base/time.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
import "media/mojo/mojom/video_encoder_info.mojom";

// This file is the Mojo version of the media::VideoEncodeAccelerator interface
// and describes the communication between a Client and a remote "service"
// VideoEncodeAccelerator (VEA) with the purpose of encoding Video Frames by
// means of hardware accelerated features.
//
//   Client                                    VideoEncodeAccelerator
//      | ---> Initialize                                       |
//      |                     RequireBitstreamBuffers(N) <---   |
//      | ---> UseOutputBitstreamBuffer(0)                      |
//      | ---> UseOutputBitstreamBuffer(1)                      |
//      |  ...                                                  |
//      =                                                       =
// The Client requests a remote Encode() and eventually the VEA will leave the
// encoded results in a pre-shared BitstreamBuffer, that is then restored to the
// VEA when the Client is finished with it. Note that there might not be a 1:1
// relationship between Encode() and BitstreamBufferReady() calls.
//      | ---> Encode()                                         |
//      |                        BitstreamBufferReady(k) <---   |
//      | ---> UseOutputBitstreamBuffer(k)                      |
//      =                                                       =
// At any time the VEA can send a NotifyError() to the Client. Similarly at any
// time the Client can send a RequestEncodingParametersChange() to the VEA. None
// of these messages are acknowledged.


enum VideoEncodeAcceleratorSupportedRateControlMode {
  kNoMode,
  kConstantMode,
  kVariableMode
};

struct VideoEncodeAcceleratorSupportedProfile {
  VideoCodecProfile profile;
  gfx.mojom.Size min_resolution;
  gfx.mojom.Size max_resolution;
  uint32 max_framerate_numerator;
  uint32 max_framerate_denominator;
  array<VideoEncodeAcceleratorSupportedRateControlMode> rate_control_modes;
  array<SVCScalabilityMode> scalability_modes;
};

// A renderer process calls this interface's functions. GPU process implements
// this interface.
interface VideoEncodeAcceleratorProvider {
  // Creates a VideoEncodeAccelerator bound to |receiver|.
  CreateVideoEncodeAccelerator(
        pending_receiver<VideoEncodeAccelerator> receiver);

  // Get a VideoEncodeAccelerator supported profiles.
  GetVideoEncodeAcceleratorSupportedProfiles()
      => (array<VideoEncodeAcceleratorSupportedProfile> profiles);
};

// This defines a mojo transport format used in the
// mojo::VideoBitrateAllocation that corresponds to media::Bitrate::peak_bps_
struct VariableBitratePeak {
  uint32 bps;
};

// Class that describes how video bitrate, in bps, is allocated across temporal
// and spatial layers. See media::VideoBitrateAllocation for more details.
struct VideoBitrateAllocation {
  array<uint32> bitrates;
  VariableBitratePeak? variable_bitrate_peak;
};

// This defines a mojo transport format for
// media::VideoEncodeAccelerator::Config::SpatialLayer.
struct SpatialLayer {
  int32 width;
  int32 height;
  uint32 bitrate_bps;
  uint32 framerate;
  uint8 max_qp;
  uint8 num_of_temporal_layers;
};

// This defines a mojo transport format for a media::Bitrate of type kConstant.
// The default target here matches that in media::Bitrate.
struct ConstantBitrate {
  uint32 target_bps = 0;
};

// This defines a mojo transport format for a media::Bitrate of type kVariable.
// The default target here matches that in media::Bitrate.
struct VariableBitrate {
  uint32 target_bps = 0;
  uint32 peak_bps;
};

// This defines a mojo transport format for media::Bitrate.
union Bitrate {
  ConstantBitrate constant;
  VariableBitrate variable;
};

// This defines a mojo transport format for
// media::VideoEncodeAccelerator::Config.
struct VideoEncodeAcceleratorConfig {
  // See media::VideoEncodeAccelerator::Config::ContentType
  enum ContentType {
    kCamera,
    kDisplay
  };

  // See media::VideoEncodeAccelerator::Config::InterLayerPredMode
  enum InterLayerPredMode {
    kOff,
    kOn,
    kOnKeyPic
  };

  // See media::VideoEncodeAccelerator::Config::StorageType
  enum StorageType {
    kShmem,
    kGpuMemoryBuffer,
  };

  VideoPixelFormat input_format;
  gfx.mojom.Size input_visible_size;
  VideoCodecProfile output_profile;
  Bitrate bitrate;
  uint32 initial_framerate;
  bool has_initial_framerate;  // Whether or not config has initial framerate
  uint32 gop_length;
  bool has_gop_length;  // Whether or not config has group of picture length
  uint8 h264_output_level;
  bool has_h264_output_level;  // Whether or not config has H264 output level
  bool is_constrained_h264;
  StorageType storage_type;
  bool has_storage_type;  // Whether or not config has storage type config
  ContentType content_type;
  array<SpatialLayer> spatial_layers;
  InterLayerPredMode inter_layer_pred;
  bool require_low_delay;
};

interface VideoEncodeAccelerator {
  // See media::VideoEncodeAccelerator::Error
  enum Error {
    ILLEGAL_STATE,
    INVALID_ARGUMENT,
    PLATFORM_FAILURE
  };

  // Responded by VideoEncodeAcceleratorClient.RequireBitstreamBuffers().
  [Sync]
  Initialize(VideoEncodeAcceleratorConfig config,
             pending_associated_remote<VideoEncodeAcceleratorClient> client,
             pending_remote<MediaLog> media_log)
      => (bool result);

  // Encodes a |frame|, being completely done with it after its callback.
  Encode(VideoFrame frame, bool force_keyframe) => ();

  UseOutputBitstreamBuffer(int32 bitstream_buffer_id,
                           mojo_base.mojom.UnsafeSharedMemoryRegion region);

  // Request a change to the encoding parameters. This is only a request,
  // fulfilled on a best-effort basis. This method is intended for use with
  // spatial or temporal layers, and is implicitly a constant bitrate encoding.
  // Parameters:
  //  |bitrate_allocation| is the requested new bitrate, per spatial and
  //                       temporal layer.
  //  |framerate| is the requested new framerate, in frames per second.
  RequestEncodingParametersChangeWithLayers(
    VideoBitrateAllocation bitrate_allocation,
    uint32 framerate);

  // Request a change to the encoding parameters. This is only a request,
  // fulfilled on a best-effort basis. This method is for use with non-layered
  // bitrates, and may make requests for constant or variable bitrates based on
  // the initially-configured bitrate mode.
  // Parameters:
  //  |bitrate| is the requested new bitrate for non-layered encoding, which
  //            may be constant or variable bitrate. This should not change the
  //            encoding mode (constant -> variable or variable -> constant).
  //  |framerate| is the requested new framerate, in frames per second.
  RequestEncodingParametersChangeWithBitrate(
    Bitrate bitrate,
    uint32 framerate);

  [Sync]
  IsFlushSupported() => (bool result);

  Flush() => (bool result);
};

// H264Metadata, Vp8Metadata, Vp9Metadata define mojo transport formats for
// media::H264Metadata, media::Vp8Metadata and media::Vp9Metadata, respectively.
// See the structures defined video_encode_accelerator.h for the descriptions of
// the variables.
// Either of them is filled in GPU process only in the case of temporal/spatial
// SVC encoding. That is, none of them is filled in the case of non
// temporal/spatial SVC encoding. Thus CodecMetadata is union and CodecMetadata
// exists as optional in BitstreamBufferMetadata.
// BitstreamBufferMetadata is metadata about a bitstream buffer produced by a
// hardware encoder. The structure is passed from GPU process to renderer
// process in BitstreamBufferReady() call.
struct H264Metadata {
  uint8 temporal_idx;
  bool layer_sync;
};

struct Vp8Metadata {
  bool non_reference;
  uint8 temporal_idx;
  bool layer_sync;
};

struct Vp9Metadata {
  bool inter_pic_predicted;
  bool temporal_up_switch;
  bool referenced_by_upper_spatial_layers;
  bool reference_lower_spatial_layers;
  bool end_of_picture;
  uint8 temporal_idx;
  uint8 spatial_idx;
  array<gfx.mojom.Size> spatial_layer_resolutions;
  array<uint8> p_diffs;
};

struct Av1Metadata {
  bool inter_pic_predicted;
  bool switch_frame;
  bool end_of_picture;
  uint8 temporal_idx;
  uint8 spatial_idx;
  array<gfx.mojom.Size> spatial_layer_resolutions;
  array<uint8> f_diffs;
};

// Codec specific metadata.
union CodecMetadata {
  H264Metadata h264;
  Vp8Metadata vp8;
  Vp9Metadata vp9;
  Av1Metadata av1;
};

struct BitstreamBufferMetadata {
  uint32 payload_size_bytes;
  bool key_frame;
  mojo_base.mojom.TimeDelta timestamp;
  int32 qp;
  CodecMetadata? codec_metadata;
};

interface VideoEncodeAcceleratorClient {
  // Response to VideoEncodeAccelerator.Initialize().
  RequireBitstreamBuffers(uint32 input_count,
                          gfx.mojom.Size input_coded_size,
                          uint32 output_buffer_size);

  BitstreamBufferReady(int32 bitstream_buffer_id,
                       BitstreamBufferMetadata metadata);

  NotifyError(VideoEncodeAccelerator.Error error);

  // VideoEncodeAccelerator calls this when its VideoEncoderInfo is changed.
  // |info| is the updated VideoEncoderInfo.
  NotifyEncoderInfoChange(VideoEncoderInfo info);
};