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

ash / components / arc / mojom / video_encode_accelerator.mojom [blame]

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file defined the mojo interface between Android and Chromium for video
// encoding.

module arc.mojom;

import "ash/components/arc/mojom/gfx.mojom";
import "ash/components/arc/mojom/video_common.mojom";
import "sandbox/policy/mojom/sandbox.mojom";

// Next MinVersion: 6

// Specification of an encoding profile supported by an encoder.
struct VideoEncodeProfile {
  VideoCodecProfile profile;
  Size max_resolution;
  uint32 max_framerate_numerator;
  uint32 max_framerate_denominator;
};


// The input buffer storage type.
[Extensible]
enum VideoFrameStorageType {
    SHMEM = 0,
    DMABUF = 1,
};

// Constant bitrate type, used for constant bitrate encoding.
//  |target| is the desired output bitrate.
struct ConstantBitrate {
  uint32 target;
};

// Variable bitrate type, used for variable bitrate encoding.
//  |target| is the desired output bitrate.
//  |peak| is the maximum output bitrate.
struct VariableBitrate {
  uint32 target;
  uint32 peak;
};

// Bitrate type, can either be constant (CBR) or variable (VBR).
//  |constant| constant bitrate mode, only target can be configured.
//  |variable| variable bitrate mode, both target and peak can be configured.
union Bitrate {
  ConstantBitrate constant;
  VariableBitrate variable;
};

// The encoder parameter set which matches to
// media::VideoEncodeAccelerator::Config except |is_constrained_h264| parameter
// which is a flag for H264 profile.
//  |input_format| is the pixel format of the input frames.
//  |input_visible_size| is the resolution of the input frames.
//  |output_profile| is the codec profile of the encoded output stream.
//  |initial_bitrate_deprecated| is the initial bitrate of the encoded output
//  stream, in bits per second. This field has been deprecated and should be
//  removed in favor of |bitrate|.
//  |initial_framerate| is the initial requested framerate. It is optional, only
//  valid when |has_initial_framerate| is true.
//  |h264_output_level| is H264 level of encoded output stream. It is optional,
//  only valid when |has_h264_output_level| is true.
//  |storage_type| is the storage type of video frame provided on Encode().
//  |bitrate| contains the desired bitrate mode (CBR/VBR), target bitrate and
//  peak bitrate (only applicable if using variable bitrate mode).
struct VideoEncodeAcceleratorConfig {
  VideoPixelFormat input_format;
  Size input_visible_size;
  VideoCodecProfile output_profile;
  // TODO(b/325160191): Sync mojom files in ARC/ARCVM side and remove these
  // variables.
  uint32 initial_bitrate_deprecated;
  uint32 initial_framerate;
  bool has_initial_framerate_deprecated;
  uint8 h264_output_level;
  bool has_h264_output_level;
  [MinVersion=1] VideoFrameStorageType storage_type;
  [MinVersion=5] Bitrate? bitrate;
};

// Video encoder IPC interface.
// Deprecated method IDs: 4, 7
// Next Method ID: 11
[ServiceSandbox=sandbox.mojom.Sandbox.kGpu]
interface VideoEncodeAccelerator {
  // Enumeration of potential errors generated by the API.
  [Extensible]
  enum Error {
    // An operation was attempted during an incompatible encoder state.
    kIllegalStateError = 0,
    // Invalid argument was passed to an API method.
    kInvalidArgumentError = 1,
    // A failure occurred at the GPU process or one of its dependencies.
    // Examples of such failures include GPU hardware failures, GPU driver
    // failures, GPU library failures, GPU process programming errors, and so
    // on.
    kPlatformFailureError = 2,
    kErrorMax = kPlatformFailureError,
  };

  enum Result {
    kSuccess = 0,
    kIllegalStateError = 1,
    kInvalidArgumentError = 2,
    kPlatformFailureError = 3,
    kInsufficientResourcesError = 4,
  };

  // Returns an array of the supported profiles of the video encoder. This can
  // be called before Initialize().
  GetSupportedProfiles@0() => (array<VideoEncodeProfile> profiles);

  [MinVersion=4]
  Initialize@9(VideoEncodeAcceleratorConfig config,
               pending_remote<VideoEncodeClient> client) => (Result result);

  // Encodes the given frame.
  // Parameters:
  //  |format| is the pixel format of video frame. This could be different from
  //  pixel format configured on Initialize().
  //  |frame_fd| is the handle of the video frame buffer. This could be the
  //  file descriptor of the shared memory or the dmabuf, depends on the
  //  storage type assigned in Initialize().
  //  |planes| is arrays of offset and stride of planes in the video frame.
  //  |timestamp| the timestamp of the video frame(in microseconds).
  //  |force_keyframe| forces the encoding of a keyframe for this frame.
  // Callback:
  //  Called when the frame has been processed and no longer used by this
  //  accelerator.
  [MinVersion=3]
  Encode@8(VideoPixelFormat format,
           handle frame_fd,
           array<VideoFramePlane> planes,
           int64 timestamp,
           bool force_keyframe) => ();

  // Sends a bitstream buffer to the encoder for storing encoded output. The
  // shared memory buffer will be filled with the encoded bitstream, and the
  // callback will be called.
  // Parameters:
  //  |bitstream_buffer_id| is the id of the bitstream buffer. It is used to
  //  identify the bitstream in VideoEncodeClient::BitstreamBufferReady().
  //  |shmem_fd| is the file descriptor of the shared memory.
  //  |offset| and |size| define the region in the shared memory to be used
  //  as the bitstream buffer.
  // Callback:
  //  Called when the encoded data has been filled in the bitstream buffer.
  //  |payload_size| is the byte size of the used portion of the buffer.
  //  |key_frame| is true if this delivered frame is a keyframe.
  //  |timestamp| is the same timestamp as the one passed to Encode().
  UseBitstreamBuffer@3(handle shmem_fd, uint32 offset, uint32 size)
      => (uint32 payload_size, bool key_frame, int64 timestamp);

  // Requests a change to the encoding parameters. This is only a request,
  // fulfilled on a best-effort basis.
  // Parameters:
  //  |bitrate| is the requested new target and peak bitrate. The bitrate mode
  //  should not be changed during encoding.
  //  |framerate| is the requested new framerate, in frames per second.
  [MinVersion=5]
  RequestEncodingParametersChange@10(Bitrate bitrate, uint32 framerate);

  // Requests a change to the encoding parameters. This is only a request,
  // fulfilled on a best-effort basis.
  // Parameters:
  //  |bitrate| is the requested new bitrate, in bits per second.
  //  |framerate| is the requested new framerate, in frames per second.
  RequestEncodingParametersChangeDeprecated@4(uint32 bitrate,
                                              uint32 framerate);

  // Flushes the encoder: all pending inputs will be encoded and all bitstreams
  // handed back to the client. The client should not invoke Flush() or
  // Encode() before the previous Flush() is finished.
  // Callback:
  //  Called with |true| if Flush() is complete; with |false| if Flush() is
  //  canceled.
  Flush@5() => (bool flush_done);
};

// Interface for clients that use VideoEncodeAccelerator. These callbacks will
// not be made unless VideoEncodeAccelerator::Initialize() has returned
// successfully.
// Next Method ID: 3
interface VideoEncodeClient {
  // Callback to tell the client what size of frames and buffers to provide
  // for input and output. The VEA disclaims use or ownership of all previously
  // provided buffers once this callback is made.
  // Parameters:
  //  |input_count| is the number of input buffers required for encoding.
  //  The client should be prepared to feed at least this many frames into the
  //  encoder before being returned any input frames, since the encoder may
  //  need to hold onto some subset of inputs as reference pictures.
  //  |input_coded_size| is the logical size of the input frames, in pixels.
  //  The encoder may have hardware alignment requirements that make this
  //  different from |visible_size|, as requested in Initialize(), in which
  //  case the input video frame to Encode() should be padded appropriately.
  //  |output_buffer_size| is the required size of output buffers for this
  //  encoder in bytes.
  RequireBitstreamBuffers@0(uint32 input_count,
                            Size input_coded_size,
                            uint32 output_buffer_size);

  // Error notification callback. Note that errors in
  // VideoEncodeAccelerator::Initialize() will not be reported here, but will
  // instead be indicated by a false return value there.
  NotifyError@2(VideoEncodeAccelerator.Error error);
};