summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/api/audio_modem.idl
blob: a306f7c2a3803dacfb41a34c9ab57dc0d94ef60d (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
// Copyright 2015 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.

// Use the <code>chrome.audio_modem</code> API
// to transmit and receive short tokens over audio.
namespace audioModem {
  // The audio bands supported.
  enum Audioband {
    // Audible (up to 3 kHz)
    audible,
    // Inaudible (18-20 kHz)
    inaudible
  };

  // Details for how a token is encoded in audio.
  dictionary TokenEncoding {
    // The length of the tokens to transmit, in bytes.
    // For now, apps must always use the same token length.
    long tokenLength;
    // Whether to use a 2-byte CRC checksum. Defaults to false.
    boolean? crc;
    // Whether to use a parity symbol. Defaults to false.
    boolean? parity;
  };

  // Details of a transmit or receive request.
  dictionary RequestParams {
    // How long to transmit or receive for.
    // The timeout has a maximum of 10 minutes for transmit,
    // or 1 hour for receive.
    long timeoutMillis;
    // The audio band to use.
    Audioband band;
    // The token encoding details.
    TokenEncoding encoding;
  };

  // Results of token decoding.
  dictionary ReceivedToken {
    // The token contents in raw bytes.
    ArrayBuffer token;
    // The audio band the token was heard on.
    Audioband band;
  };

  // The result of a requested operation.
  enum Status {
    // The requested operation was processed successfully.
    success,
    // The request was invalid. See chrome.runtime.lastError for details.
    invalidRequest,
    // The requested audio band is already in use by another client.
    // Eventually, simultaneous tokens will be time-sliced,
    // and this error will no longer occur.
    inUse,
    // Audio encoding or decoding failed.
    coderError
  };

  // A callback to report the status of a request.
  callback StatusCallback = void(Status status);

  interface Functions {
    // Transmit a token. Only one can be transmitted at a time.
    // Transmission of any previous tokens (by this app) will stop.
    static void transmit(
        RequestParams params, ArrayBuffer token, StatusCallback callback);
    // Stop any active transmission on the specified band.
    static void stopTransmit(Audioband band, StatusCallback callback);
    // Start listening for audio tokens. For now,
    // only one app will be able to listen at a time.
    static void receive(RequestParams params, StatusCallback callback);
    // Stop any active listening on the specified band.
    static void stopReceive(Audioband band, StatusCallback callback);
  };

  interface Events {
    // Audio tokens have been received.
    static void onReceived(ReceivedToken[] tokens);
    // Transmit could not be confirmed.
    // The speaker volume might be too low.
    static void onTransmitFail(Audioband band);
  };
};