chromium/services/media_session/public/mojom/media_controller.mojom

// 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_session.mojom;

import "mojo/public/mojom/base/time.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "services/media_session/public/mojom/media_session.mojom";

// Next MinVersion: 8

// Next Method ID: 3
[Stable, Uuid="1ed3225e-33c8-487b-b79f-4c3ec13ad623"]
interface MediaControllerManager {
  // Creates a MediaController linked to a specific session with |request_id|.
  // This should match the |request_id| from the AudioFocusRequestState.
  CreateMediaControllerForSession@0(
      pending_receiver<MediaController> receiver,
      mojo_base.mojom.UnguessableToken request_id);

  // Creates a MediaController linked to the active session. This will
  // automatically route commands to the correct session if the active session
  // changes. If there is no active session then commands will be no-ops.
  CreateActiveMediaController@1(pending_receiver<MediaController> receiver);

  // Suspends all media sessions.
  SuspendAllSessions@2();
};

// Controls the associated MediaSession. An active media controller will be
// automatically associated with the most recently interacted with media
// session, otherwise media sessions will be associated with a particular media
// session provided to the service when creating the media controller. If the
// media session is not controllable then the commands will be no-ops.
// Next Method ID: 22
[Stable]
interface MediaController {
  // Suspend the media session.
  Suspend@0();

  // Resume the media session.
  Resume@1();

  // Stop the media session.
  Stop@2();

  // This will either suspend or resume the media session based on the
  // playback state.
  ToggleSuspendResume@3();

  // Adds an observer that will forward events from the active media session.
  // If the active session changes then observers do not need to be readded.
  // Adding the observer will update the observer with the latest state.
  AddObserver@4(pending_remote<MediaControllerObserver> observer);

  // Skip to the previous track. If there is no previous track then this will be
  // a no-op.
  PreviousTrack@5();

  // Skip to the next track. If there is no next track then this will be a
  // no-op.
  NextTrack@6();

  // Seek the media session. If the media cannot seek then this will be a
  // no-op. The |seek_time| is the time delta that the media will seek by and
  // supports both positive and negative values. This value cannot be zero.
  // The |kDefaultSeekTimeSeconds| provides a default value for seeking by a
  // few seconds.
  Seek@7(mojo_base.mojom.TimeDelta seek_time);

  // Creates an image observer that will be notified when the image of |type|
  // for the underlying media session has changed. The image will be at least
  // |minimum_size_pc| and closest to |desired_size_px|.
  ObserveImages@8(
      MediaSessionImageType type, int32 minimum_size_px, int32 desired_size_px,
      pending_remote<MediaControllerImageObserver> observer);

  // Seek the media session to a non-negative |seek_time| from the beginning of
  // the current playing media. If the media cannot seek then this will be a
  // no-op.
  SeekTo@9(mojo_base.mojom.TimeDelta seek_time);

  // Scrub ("fast seek") the media session to a non-negative |seek_time| from
  // the beginning of the current playing media. If the media cannot scrub then
  // this will be a no-op. The client should call |SeekTo| to finish the
  // scrubbing operation.
  ScrubTo@10(mojo_base.mojom.TimeDelta seek_time);

  // Enter picture-in-picture.
  EnterPictureInPicture@11();

  // Exit picture-in-picture.
  ExitPictureInPicture@12();

  // Routes the audio from this Media Session to the given output device. If
  // |id| is null, we will route to the default output device.
  SetAudioSinkId@13(string? id);

  // Mute or unmute the microphone for a WebRTC session.
  [MinVersion=1] ToggleMicrophone@14();

  // Turn on or off the camera for a WebRTC session.
  [MinVersion=1] ToggleCamera@15();

  // Hang up a WebRTC session.
  [MinVersion=1] HangUp@16();

  // Display the source of the MediaSession (e.g. show the tab or the
  // application).
  [MinVersion=2] Raise@17();

  // Mute or unmute the media player.
  [MinVersion=3] SetMute@18(bool mute);

  // Start Media Remoting once there are available sinks.
  [MinVersion=4] RequestMediaRemoting@19();

  // Automatically enter picture-in-picture from a non-user source (e.g. in
  // reaction to content being hidden).
  [MinVersion=5] EnterAutoPictureInPicture@20();

  // Skips the advertisement that is currently playing.
  [MinVersion=6] SkipAd@21();
};

// The observer for observing media controller events. This is different to a
// MediaSessionObserver because a media controller can have nullable session
// info which will be null if it is not bound to a media session. This would
// be invalid for a media session because it must always have some state.
// Next Method ID: 5
[Stable]
interface MediaControllerObserver {
  // Called when the state of the bound media session changes. If |info| is
  // empty then the controller is no longer bound to a media session.
  MediaSessionInfoChanged@0(MediaSessionInfo? info);

  // Called when the bound media session has changed metadata. If |metadata|
  // is null then it can be reset, e.g. the media that ws being played has
  // been stopped.
  MediaSessionMetadataChanged@1(MediaMetadata? metadata);

  // Called when the bound media session action list has changed. This tells
  // the observer which actions can be used to control the session.
  MediaSessionActionsChanged@2(array<MediaSessionAction> action);

  // Called when the bound media session changes. This tells the observer the
  // |request_id| of the new session of null if it is not bound to a session.
  MediaSessionChanged@3(mojo_base.mojom.UnguessableToken? request_id);

  // Called when the position of the bound media session has changed. If
  // |position| is empty then the media session does not have a position or
  // the controller is no longer bound to a media session. Position is updated
  // anytime the position state (playback rate, duration) is changed or the
  // media is seeked.
  MediaSessionPositionChanged@4(MediaPosition? position);
};

// The observer for observing when images associated with a media controller
// change. This is a separate observer because not all clients need to handle
// images.
// Next Method ID: 2
[Stable]
interface MediaControllerImageObserver {
  // Called when the observed media controller has a new image of |type|.
  // It may be null if there is no image.
  MediaControllerImageChanged@0(
      MediaSessionImageType type, MediaImageBitmap? bitmap);

  // Called when the observed media controller has a new image of the chapter
  // at the `index` in the chapter list.
  [MinVersion=7] MediaControllerChapterImageChanged@1(
      int32 index, MediaImageBitmap? bitmap);
};