/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <cstdint>
#include <optional>

namespace cuttlefish {

enum class AudioChannelsLayout {
  Mono,
  Stereo,
  Surround51,
};

struct AudioStreamSettings {
  enum class Direction {
    Playback,
    Capture,
  };

  struct VolumeControl {
    uint32_t min = 0;
    uint32_t max = 100;
    uint32_t step = 1;
  };

  uint8_t id = 0;
  AudioChannelsLayout channels_layout = AudioChannelsLayout::Stereo;
  Direction direction = Direction::Playback;

  bool has_mute_control = false;
  std::optional<VolumeControl> master_volume_control;
};

struct AudioMixerSettings {
  AudioChannelsLayout channels_layout = AudioChannelsLayout::Stereo;
  uint32_t sample_rate = 48000;
};

static constexpr inline uint8_t GetChannelsCount(AudioChannelsLayout layout) {
  switch (layout) {
    case AudioChannelsLayout::Mono:
      return 1;
    case AudioChannelsLayout::Stereo:
      return 2;
    case AudioChannelsLayout::Surround51:
      return 6;
  }
}

}  // namespace cuttlefish
