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

// The <code>chrome.cast.streaming.receiverSession</code> API creates a Cast
// receiver session and adds the resulting audio and video tracks to a
// MediaStream.
namespace cast.streaming.receiverSession {
  // The UDP socket address and port.
  dictionary IPEndPoint {
    DOMString address;
    long port;
  };

  // RTP receiver parameters.
  dictionary RtpReceiverParams {
    // Maximum latency in milliseconds. This parameter controls the logic
    // of flow control. Implementation can adjust latency adaptively and
    // tries to keep it under this threshold. A larger value allows smoother
    // playback at the cost of higher latency.
    long maxLatency;

    DOMString codecName;

    // Synchronization source identifier for incoming data.
    long senderSsrc;

    // The SSRC used to send RTCP reports back to the sender.
    long receiverSsrc;

    // RTP time units per second, defaults to 48000 for audio
    // and 90000 for video.
    long? rtpTimebase;

    // 32 bytes hex-encoded AES key.
    DOMString? aesKey;

    // 32 bytes hex-encoded AES IV (Initialization vector) mask.
    DOMString? aesIvMask;
  };

  callback ErrorCallback = void (DOMString error);

  interface Functions {
    // Creates a Cast receiver session which receives data from a UDP
    // socket. The receiver will decode the incoming data into an audio
    // and a video track which will be added to the provided media stream.
    // The |audioParams| and |videoParams| are generally provided by the
    // sender through some other messaging channel.
    //
    // |audioParams| : Audio stream parameters.
    // |videoParams| : Video stream parameters.
    // |localEndpoint| : Local IP and port to bind to.
    // |height| : Video height.
    // |width| : Video width.
    // |maxFrameRate| : Max video frame rate.
    // |mediaStreamURL| : URL of MediaStream to add the audio and video to.
    // |transport_options| : Optional transport settings.
    [nocompile] static void createAndBind(
        RtpReceiverParams audioParams,
        RtpReceiverParams videoParams,
        IPEndPoint localEndpoint,
        long maxWidth,
        long maxHeight,
        double maxFrameRate,
        DOMString mediaStreamURL,
        ErrorCallback error_callback,
        optional object transport_options);
  };
};
