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

media / mojo / mojom / audio_encoder.mojom [blame]

// Copyright 2021 The Chromium Authors
// 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_types.mojom";
import "media/mojo/mojom/audio_parameters.mojom";
import "mojo/public/mojom/base/time.mojom";

enum AacOutputFormat { kAAC, kADTS };
struct AacAudioEncoderConfig {
  AacOutputFormat format;
};

// This defines a mojo transport format for media::AudioEncoderConfig.
// See media/base/audio_encoder.h for descriptions.
struct AudioEncoderConfig {
  // Audio codec to be used for encoding.
  AudioCodec codec;

  // Number of channels.
  uint8 channel_count;

  // Sample rate of the buffer, number of audio samples per second.
  uint32 sample_rate;

  // Target encoded bitrate - bits per second of playback
  // 0 - if client has no bitrate preference.
  uint32 bitrate;

  // AAC specific parts of the config
  AacAudioEncoderConfig aac;
};

// This defines a mojo transport format for media::EncodedAudioBuffer.
// See media/base/audio_encoder.h for descriptions.
struct EncodedAudioBuffer {
  // Parameters of the encoded audio (channel count, sample rate etc)
  // It might be different from parameters provided in AudioEncoderConfig.
  AudioParameters params;

  // Presentation time of the encoded audio
  mojo_base.mojom.TimeDelta timestamp;

  // Duration of the encoded audio stretch
  mojo_base.mojom.TimeDelta duration;

  // Compressed audio data blob (e.g. opus, AAC etc)
  array<uint8> data;
};

// An interface for a platform dependent audio encoder that needs to run in
// GPU process. It's called from renderers.
interface AudioEncoder {
  // Initializes encoded with a given |config|, prepares underlying resources
  // etc.
  // |client| will be use to return encoded data.
  // This must be called only once before any other Encode() and Flush().
  // Returns errors as |status|.
  Initialize(pending_associated_remote<AudioEncoderClient> client,
             AudioEncoderConfig config) => (EncoderStatus status);

  // Requests contents of audio |buffer| to be encoded, encoded results
  // produced via AudioEncoderClient.EncodedBufferReady().
  // Returns errors as |status|.
  Encode(AudioBuffer buffer) => (EncoderStatus status);

  // Requests all outputs for already encoded frames to be
  // produced via AudioEncoderClient.EncodedBufferReady().
  // Returns errors as |status|.
  Flush() => (EncoderStatus status);
};

// A complimentary interface for AudioEncoder, bound
// in AudioEncoder.Initialize()
// It is used for sending encoded audio back to renderer.
interface AudioEncoderClient {
  // Sends the encoded audio buffer back to the mojo client.
  // |buffer| - encoded audio binary with timestamp and duration.
  // |description| - codec specific extra data that is sometimes used to
  //                 configure decoders.
  //                 Empty, if no extra data comes with this buffer.
  OnEncodedBufferReady(EncodedAudioBuffer buffer, array<uint8> description);
};