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

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

// 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.

module media.mojom;

import "mojo/public/mojom/base/shared_memory.mojom";

// Used by audio streams for realtime-ish data transfer, see AudioDeviceThread,
// SyncReader, and InputSyncWriter.
// |socket| is a base::SyncSocket used for signaling and |shared_memory| is used
// for the actual audio data.
//
// When using a pull model, the code pulling the data writes |n| (an unsigned
// 32 bit sequence number) to the socket, and the source from which data is
// pulled writes a buffer to |shared_memory| and writes |n| back to signal that
// it finished writing. Then the process continues with |n+1|. This model is
// used to get data for playout.
//
//
// When using a push model, there are two different models. For both models,
// |shared_memory| may have |S| slots for several buffers, in which case several
// buffers can be pushed without waiting for previous buffers to be consumed.
// TODO(crbug.com/380422501): Run experiment to evaluate the models and only use
// the best one.
//
// Model 1 (baseline):
// The code pushing data writes a buffer to |shared_memory| and writes |n| to
// the socket. When the other side finished reading the buffer, it writes
// |n| + 1 to the socket to signal that the memory is safe to write to again.
//
// Model 2 (experimental):
// The code pushing data writes a buffer to slot |n|%|S| in |shared_memory| and
// writes |n| to the socket. When the other side finished reading the buffer, it
// sets an atomic flag at slot |n|%|S| in |shared_memory| to signal that the
// memory is safe to write to again.
//
// These models are used to deliver microphone data to a consumer.
struct ReadWriteAudioDataPipe {
  mojo_base.mojom.UnsafeSharedMemoryRegion shared_memory;
  handle<platform> socket;
};