Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c0cbaa44 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Refine the log messages of audio_bluetooth_hal"

parents 0c9aee90 59fcee0b
Loading
Loading
Loading
Loading
+56 −60
Original line number Original line Diff line number Diff line
@@ -32,8 +32,7 @@ namespace android {
namespace bluetooth {
namespace bluetooth {
namespace audio {
namespace audio {


using android::base::StringPrintf;
using ::android::base::StringPrintf;

using ::android::bluetooth::audio::BluetoothAudioSessionControl;
using ::android::bluetooth::audio::BluetoothAudioSessionControl;
using ::android::hardware::bluetooth::audio::V2_0::BitsPerSample;
using ::android::hardware::bluetooth::audio::V2_0::BitsPerSample;
using ::android::hardware::bluetooth::audio::V2_0::ChannelMode;
using ::android::hardware::bluetooth::audio::V2_0::ChannelMode;
@@ -116,7 +115,7 @@ bool BluetoothAudioPortOut::SetUp(audio_devices_t devices) {
      return;
      return;
    }
    }
    if (port->cookie_ != cookie) {
    if (port->cookie_ != cookie) {
      LOG(ERROR) << "control_result_cb: proxy of device port (cookie=0x" << StringPrintf("%04hx", cookie)
      LOG(ERROR) << "control_result_cb: proxy of device port (cookie=" << StringPrintf("%#hx", cookie)
                 << ") is corrupted";
                 << ") is corrupted";
      return;
      return;
    }
    }
@@ -128,7 +127,7 @@ bool BluetoothAudioPortOut::SetUp(audio_devices_t devices) {
      return;
      return;
    }
    }
    if (port->cookie_ != cookie) {
    if (port->cookie_ != cookie) {
      LOG(ERROR) << "session_changed_cb: proxy of device port (cookie=0x" << StringPrintf("%04hx", cookie)
      LOG(ERROR) << "session_changed_cb: proxy of device port (cookie=" << StringPrintf("%#hx", cookie)
                 << ") is corrupted";
                 << ") is corrupted";
      return;
      return;
    }
    }
@@ -139,8 +138,7 @@ bool BluetoothAudioPortOut::SetUp(audio_devices_t devices) {
      .session_changed_cb_ = session_changed_cb};
      .session_changed_cb_ = session_changed_cb};
  cookie_ = BluetoothAudioSessionControl::RegisterControlResultCback(
  cookie_ = BluetoothAudioSessionControl::RegisterControlResultCback(
      session_type_, cbacks);
      session_type_, cbacks);
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_);
            << StringPrintf("%04hx", cookie_);


  return (cookie_ != android::bluetooth::audio::kObserversCookieUndefined);
  return (cookie_ != android::bluetooth::audio::kObserversCookieUndefined);
}
}
@@ -150,23 +148,23 @@ bool BluetoothAudioPortOut::init_session_type(audio_devices_t device) {
    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP:
    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP:
    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES:
    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES:
    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
      LOG(VERBOSE) << __func__ << ": device=AUDIO_DEVICE_OUT_BLUETOOTH_A2DP (HEADPHONES/SPEAKER) (0x"
      LOG(VERBOSE) << __func__ << ": device=AUDIO_DEVICE_OUT_BLUETOOTH_A2DP (HEADPHONES/SPEAKER) ("
                   << StringPrintf("%08x", device) << ")";
                   << StringPrintf("%#x", device) << ")";
      session_type_ = SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH;
      session_type_ = SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH;
      break;
      break;
    case AUDIO_DEVICE_OUT_HEARING_AID:
    case AUDIO_DEVICE_OUT_HEARING_AID:
      LOG(VERBOSE) << __func__ << ": device=AUDIO_DEVICE_OUT_HEARING_AID (MEDIA/VOICE) (0x"
      LOG(VERBOSE) << __func__ << ": device=AUDIO_DEVICE_OUT_HEARING_AID (MEDIA/VOICE) (" << StringPrintf("%#x", device)
                   << StringPrintf("%08x", device) << ")";
                   << ")";
      session_type_ = SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH;
      session_type_ = SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH;
      break;
      break;
    default:
    default:
      LOG(ERROR) << __func__ << ": unknown device=0x" << StringPrintf("%08x", device);
      LOG(ERROR) << __func__ << ": unknown device=" << StringPrintf("%#x", device);
      return false;
      return false;
  }
  }


  if (!BluetoothAudioSessionControl::IsSessionReady(session_type_)) {
  if (!BluetoothAudioSessionControl::IsSessionReady(session_type_)) {
    LOG(ERROR) << __func__ << ": device=0x" << StringPrintf("%08x", device)
    LOG(ERROR) << __func__ << ": device=" << StringPrintf("%#x", device) << ", session_type=" << toString(session_type_)
               << ", session_type=" << toString(session_type_) << " is not ready";
               << " is not ready";
    return false;
    return false;
  }
  }
  return true;
  return true;
@@ -174,13 +172,12 @@ bool BluetoothAudioPortOut::init_session_type(audio_devices_t device) {


void BluetoothAudioPortOut::TearDown() {
void BluetoothAudioPortOut::TearDown() {
  if (!in_use()) {
  if (!in_use()) {
    LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
    LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_)
               << StringPrintf("%04hx", cookie_) << " unknown monitor";
               << ", cookie=" << StringPrintf("%#hx", cookie_) << " unknown monitor";
    return;
    return;
  }
  }


  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_);
            << StringPrintf("%04hx", cookie_);
  BluetoothAudioSessionControl::UnregisterControlResultCback(session_type_,
  BluetoothAudioSessionControl::UnregisterControlResultCback(session_type_,
                                                             cookie_);
                                                             cookie_);
  cookie_ = android::bluetooth::audio::kObserversCookieUndefined;
  cookie_ = android::bluetooth::audio::kObserversCookieUndefined;
@@ -194,8 +191,8 @@ void BluetoothAudioPortOut::ControlResultHandler(
  }
  }
  std::unique_lock<std::mutex> port_lock(cv_mutex_);
  std::unique_lock<std::mutex> port_lock(cv_mutex_);
  BluetoothStreamState previous_state = state_;
  BluetoothStreamState previous_state = state_;
  LOG(INFO) << "control_result_cb: session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(INFO) << "control_result_cb: session_type=" << toString(session_type_)
            << StringPrintf("%04hx", cookie_) << ", previous_state=" << previous_state
            << ", cookie=" << StringPrintf("%#hx", cookie_) << ", previous_state=" << previous_state
            << ", status=" << toString(status);
            << ", status=" << toString(status);


  switch (previous_state) {
  switch (previous_state) {
@@ -205,8 +202,8 @@ void BluetoothAudioPortOut::ControlResultHandler(
      } else {
      } else {
        // Set to standby since the stack may be busy switching between outputs
        // Set to standby since the stack may be busy switching between outputs
        LOG(WARNING) << "control_result_cb: status=" << toString(status)
        LOG(WARNING) << "control_result_cb: status=" << toString(status)
                     << " failure for session_type=" << toString(session_type_) << ", cookie=0x"
                     << " failure for session_type=" << toString(session_type_)
                     << StringPrintf("%04hx", cookie_) << ", previous_state=" << previous_state;
                     << ", cookie=" << StringPrintf("%#hx", cookie_) << ", previous_state=" << previous_state;
        state_ = BluetoothStreamState::STANDBY;
        state_ = BluetoothStreamState::STANDBY;
      }
      }
      break;
      break;
@@ -217,14 +214,14 @@ void BluetoothAudioPortOut::ControlResultHandler(
        // It will be failed if the headset is disconnecting, and set to disable
        // It will be failed if the headset is disconnecting, and set to disable
        // to wait for re-init again
        // to wait for re-init again
        LOG(WARNING) << "control_result_cb: status=" << toString(status)
        LOG(WARNING) << "control_result_cb: status=" << toString(status)
                     << " failure for session_type=" << toString(session_type_) << ", cookie=0x"
                     << " failure for session_type=" << toString(session_type_)
                     << StringPrintf("%04hx", cookie_) << ", previous_state=" << previous_state;
                     << ", cookie=" << StringPrintf("%#hx", cookie_) << ", previous_state=" << previous_state;
        state_ = BluetoothStreamState::DISABLED;
        state_ = BluetoothStreamState::DISABLED;
      }
      }
      break;
      break;
    default:
    default:
      LOG(ERROR) << "control_result_cb: unexpected status=" << toString(status)
      LOG(ERROR) << "control_result_cb: unexpected status=" << toString(status)
                 << " for session_type=" << toString(session_type_) << ", cookie=0x" << StringPrintf("%04hx", cookie_)
                 << " for session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
                 << ", previous_state=" << previous_state;
                 << ", previous_state=" << previous_state;
      return;
      return;
  }
  }
@@ -239,8 +236,8 @@ void BluetoothAudioPortOut::SessionChangedHandler() {
  }
  }
  std::unique_lock<std::mutex> port_lock(cv_mutex_);
  std::unique_lock<std::mutex> port_lock(cv_mutex_);
  BluetoothStreamState previous_state = state_;
  BluetoothStreamState previous_state = state_;
  LOG(INFO) << "session_changed_cb: session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(INFO) << "session_changed_cb: session_type=" << toString(session_type_)
            << StringPrintf("%04hx", cookie_) << ", previous_state=" << previous_state;
            << ", cookie=" << StringPrintf("%#hx", cookie_) << ", previous_state=" << previous_state;
  if (previous_state != BluetoothStreamState::DISABLED) {
  if (previous_state != BluetoothStreamState::DISABLED) {
    state_ = BluetoothStreamState::DISABLED;
    state_ = BluetoothStreamState::DISABLED;
  } else {
  } else {
@@ -273,8 +270,9 @@ bool BluetoothAudioPortOut::LoadAudioConfig(audio_config_t* audio_cfg) const {
    return false;
    return false;
  }
  }
  const PcmParameters& pcm_cfg = hal_audio_cfg.pcmConfig();
  const PcmParameters& pcm_cfg = hal_audio_cfg.pcmConfig();
  LOG(VERBOSE) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(VERBOSE) << __func__ << ": session_type=" << toString(session_type_)
               << StringPrintf("%04hx", cookie_) << ", state=" << state_ << ", PcmConfig=[" << toString(pcm_cfg) << "]";
               << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_ << ", PcmConfig=["
               << toString(pcm_cfg) << "]";
  if (pcm_cfg.sampleRate == SampleRate::RATE_UNKNOWN ||
  if (pcm_cfg.sampleRate == SampleRate::RATE_UNKNOWN ||
      pcm_cfg.channelMode == ChannelMode::UNKNOWN ||
      pcm_cfg.channelMode == ChannelMode::UNKNOWN ||
      pcm_cfg.bitsPerSample == BitsPerSample::BITS_UNKNOWN) {
      pcm_cfg.bitsPerSample == BitsPerSample::BITS_UNKNOWN) {
@@ -292,24 +290,24 @@ bool BluetoothAudioPortOut::CondwaitState(BluetoothStreamState state) {
  std::unique_lock<std::mutex> port_lock(cv_mutex_);
  std::unique_lock<std::mutex> port_lock(cv_mutex_);
  switch (state) {
  switch (state) {
    case BluetoothStreamState::STARTING:
    case BluetoothStreamState::STARTING:
      LOG(VERBOSE) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
      LOG(VERBOSE) << __func__ << ": session_type=" << toString(session_type_)
                   << StringPrintf("%04hx", cookie_) << " waiting for STARTED";
                   << ", cookie=" << StringPrintf("%#hx", cookie_) << " waiting for STARTED";
      retval = internal_cv_.wait_for(
      retval = internal_cv_.wait_for(
          port_lock, std::chrono::milliseconds(kMaxWaitingTimeMs),
          port_lock, std::chrono::milliseconds(kMaxWaitingTimeMs),
          [this] { return this->state_ != BluetoothStreamState::STARTING; });
          [this] { return this->state_ != BluetoothStreamState::STARTING; });
      retval = retval && state_ == BluetoothStreamState::STARTED;
      retval = retval && state_ == BluetoothStreamState::STARTED;
      break;
      break;
    case BluetoothStreamState::SUSPENDING:
    case BluetoothStreamState::SUSPENDING:
      LOG(VERBOSE) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
      LOG(VERBOSE) << __func__ << ": session_type=" << toString(session_type_)
                   << StringPrintf("%04hx", cookie_) << " waiting for SUSPENDED";
                   << ", cookie=" << StringPrintf("%#hx", cookie_) << " waiting for SUSPENDED";
      retval = internal_cv_.wait_for(
      retval = internal_cv_.wait_for(
          port_lock, std::chrono::milliseconds(kMaxWaitingTimeMs),
          port_lock, std::chrono::milliseconds(kMaxWaitingTimeMs),
          [this] { return this->state_ != BluetoothStreamState::SUSPENDING; });
          [this] { return this->state_ != BluetoothStreamState::SUSPENDING; });
      retval = retval && state_ == BluetoothStreamState::STANDBY;
      retval = retval && state_ == BluetoothStreamState::STANDBY;
      break;
      break;
    default:
    default:
      LOG(WARNING) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
      LOG(WARNING) << __func__ << ": session_type=" << toString(session_type_)
                   << StringPrintf("%04hx", cookie_) << " waiting for KNOWN";
                   << ", cookie=" << StringPrintf("%#hx", cookie_) << " waiting for KNOWN";
      return false;
      return false;
  }
  }


@@ -322,27 +320,26 @@ bool BluetoothAudioPortOut::Start() {
    return false;
    return false;
  }
  }


  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
            << StringPrintf("%04hx", cookie_) << ", state=" << state_
            << ", state=" << state_ << ", mono=" << (is_stereo_to_mono_ ? "true" : "false") << " request";
            << ", mono=" << (is_stereo_to_mono_ ? "true" : "false") << " request";
  bool retval = false;
  bool retval = false;
  if (state_ == BluetoothStreamState::STANDBY) {
  if (state_ == BluetoothStreamState::STANDBY) {
    state_ = BluetoothStreamState::STARTING;
    state_ = BluetoothStreamState::STARTING;
    if (BluetoothAudioSessionControl::StartStream(session_type_)) {
    if (BluetoothAudioSessionControl::StartStream(session_type_)) {
      retval = CondwaitState(BluetoothStreamState::STARTING);
      retval = CondwaitState(BluetoothStreamState::STARTING);
    } else {
    } else {
      LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
      LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_)
                 << StringPrintf("%04hx", cookie_) << ", state=" << state_ << " Hal fails";
                 << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_ << " Hal fails";
    }
    }
  }
  }


  if (retval) {
  if (retval) {
    LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
    LOG(INFO) << __func__ << ": session_type=" << toString(session_type_)
              << StringPrintf("%04hx", cookie_) << ", state=" << state_
              << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_
              << ", mono=" << (is_stereo_to_mono_ ? "true" : "false") << " done";
              << ", mono=" << (is_stereo_to_mono_ ? "true" : "false") << " done";
  } else {
  } else {
    LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
    LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_)
               << StringPrintf("%04hx", cookie_) << ", state=" << state_ << " failure";
               << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_ << " failure";
  }
  }


  return retval;  // false if any failure like timeout
  return retval;  // false if any failure like timeout
@@ -354,25 +351,25 @@ bool BluetoothAudioPortOut::Suspend() {
    return false;
    return false;
  }
  }


  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
            << StringPrintf("%04hx", cookie_) << ", state=" << state_ << " request";
            << ", state=" << state_ << " request";
  bool retval = false;
  bool retval = false;
  if (state_ == BluetoothStreamState::STARTED) {
  if (state_ == BluetoothStreamState::STARTED) {
    state_ = BluetoothStreamState::SUSPENDING;
    state_ = BluetoothStreamState::SUSPENDING;
    if (BluetoothAudioSessionControl::SuspendStream(session_type_)) {
    if (BluetoothAudioSessionControl::SuspendStream(session_type_)) {
      retval = CondwaitState(BluetoothStreamState::SUSPENDING);
      retval = CondwaitState(BluetoothStreamState::SUSPENDING);
    } else {
    } else {
      LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
      LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_)
                 << StringPrintf("%04hx", cookie_) << ", state=" << state_ << " Hal fails";
                 << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_ << " Hal fails";
    }
    }
  }
  }


  if (retval) {
  if (retval) {
    LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
    LOG(INFO) << __func__ << ": session_type=" << toString(session_type_)
              << StringPrintf("%04hx", cookie_) << ", state=" << state_ << " done";
              << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_ << " done";
  } else {
  } else {
    LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
    LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_)
               << StringPrintf("%04hx", cookie_) << ", state=" << state_ << " failure";
               << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_ << " failure";
  }
  }


  return retval;  // false if any failure like timeout
  return retval;  // false if any failure like timeout
@@ -383,12 +380,12 @@ void BluetoothAudioPortOut::Stop() {
    LOG(ERROR) << __func__ << ": BluetoothAudioPortOut is not in use";
    LOG(ERROR) << __func__ << ": BluetoothAudioPortOut is not in use";
    return;
    return;
  }
  }
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
            << StringPrintf("%04hx", cookie_) << ", state=" << state_ << " request";
            << ", state=" << state_ << " request";
  state_ = BluetoothStreamState::DISABLED;
  state_ = BluetoothStreamState::DISABLED;
  BluetoothAudioSessionControl::StopStream(session_type_);
  BluetoothAudioSessionControl::StopStream(session_type_);
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
            << StringPrintf("%04hx", cookie_) << ", state=" << state_ << " done";
            << ", state=" << state_ << " done";
}
}


size_t BluetoothAudioPortOut::WriteData(const void* buffer, size_t bytes) const {
size_t BluetoothAudioPortOut::WriteData(const void* buffer, size_t bytes) const {
@@ -416,8 +413,8 @@ bool BluetoothAudioPortOut::GetPresentationPosition(uint64_t* delay_ns,
  }
  }
  bool retval = BluetoothAudioSessionControl::GetPresentationPosition(
  bool retval = BluetoothAudioSessionControl::GetPresentationPosition(
      session_type_, delay_ns, bytes, timestamp);
      session_type_, delay_ns, bytes, timestamp);
  LOG(VERBOSE) << __func__ << ": session_type=0x" << StringPrintf("%02hhx", session_type_) << ", cookie=0x"
  LOG(VERBOSE) << __func__ << ": session_type=" << StringPrintf("%#hhx", session_type_)
               << StringPrintf("%04hx", cookie_) << ", state=" << state_ << ", delay=" << *delay_ns
               << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_ << ", delay=" << *delay_ns
               << "ns, data=" << *bytes << " bytes, timestamp=" << timestamp->tv_sec << "."
               << "ns, data=" << *bytes << " bytes, timestamp=" << timestamp->tv_sec << "."
               << StringPrintf("%09ld", timestamp->tv_nsec) << "s";
               << StringPrintf("%09ld", timestamp->tv_nsec) << "s";


@@ -430,9 +427,8 @@ void BluetoothAudioPortOut::UpdateMetadata(
    LOG(ERROR) << __func__ << ": BluetoothAudioPortOut is not in use";
    LOG(ERROR) << __func__ << ": BluetoothAudioPortOut is not in use";
    return;
    return;
  }
  }
  LOG(DEBUG) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=0x"
  LOG(DEBUG) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
             << StringPrintf("%04hx", cookie_) << ", state=" << state_ << ", " << source_metadata->track_count
             << ", state=" << state_ << ", " << source_metadata->track_count << " track(s)";
             << " track(s)";
  if (source_metadata->track_count == 0) return;
  if (source_metadata->track_count == 0) return;
  BluetoothAudioSessionControl::UpdateTracksMetadata(session_type_,
  BluetoothAudioSessionControl::UpdateTracksMetadata(session_type_,
                                                     source_metadata);
                                                     source_metadata);
+17 −29
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@
#include "stream_apis.h"
#include "stream_apis.h"
#include "utils.h"
#include "utils.h"


using ::android::base::StringPrintf;
using ::android::bluetooth::audio::BluetoothAudioPortOut;
using ::android::bluetooth::audio::BluetoothAudioPortOut;
using ::android::bluetooth::audio::utils::GetAudioParamString;
using ::android::bluetooth::audio::utils::GetAudioParamString;
using ::android::bluetooth::audio::utils::ParseAudioParams;
using ::android::bluetooth::audio::utils::ParseAudioParams;
@@ -41,9 +42,7 @@ constexpr int kExtraAudioSyncMs = 200;


std::ostream& operator<<(std::ostream& os, const audio_config& config) {
std::ostream& operator<<(std::ostream& os, const audio_config& config) {
  return os << "audio_config[sample_rate=" << config.sample_rate
  return os << "audio_config[sample_rate=" << config.sample_rate
            << ", channels=0x"
            << ", channels=" << StringPrintf("%#x", config.channel_mask) << ", format=" << config.format << "]";
            << android::base::StringPrintf("%x", config.channel_mask)
            << ", format=" << config.format << "]";
}
}


}  // namespace
}  // namespace
@@ -63,7 +62,7 @@ std::ostream& operator<<(std::ostream& os, const BluetoothStreamState& state) {
    case BluetoothStreamState::UNKNOWN:
    case BluetoothStreamState::UNKNOWN:
      return os << "UNKNOWN";
      return os << "UNKNOWN";
    default:
    default:
      return os << "0x" + android::base::StringPrintf("%hhx", state);
      return os << StringPrintf("%#hhx", state);
  }
  }
}
}


@@ -107,9 +106,7 @@ static audio_channel_mask_t out_get_channels(
    return audio_cfg.channel_mask;
    return audio_cfg.channel_mask;
  } else {
  } else {
    LOG(WARNING) << __func__ << ": state=" << out->bluetooth_output_.GetState()
    LOG(WARNING) << __func__ << ": state=" << out->bluetooth_output_.GetState()
                 << ", channels=0x"
                 << ", channels=" << StringPrintf("%#x", out->channel_mask_) << " failure";
                 << android::base::StringPrintf("%x", out->channel_mask_)
                 << " failure";
    return out->channel_mask_;
    return out->channel_mask_;
  }
  }
}
}
@@ -194,10 +191,8 @@ static int out_set_parameters(struct audio_stream* stream,
      out->sample_rate_ = audio_cfg.sample_rate;
      out->sample_rate_ = audio_cfg.sample_rate;
      out->channel_mask_ = audio_cfg.channel_mask;
      out->channel_mask_ = audio_cfg.channel_mask;
      out->format_ = audio_cfg.format;
      out->format_ = audio_cfg.format;
      LOG(VERBOSE) << "state=" << out->bluetooth_output_.GetState()
      LOG(VERBOSE) << "state=" << out->bluetooth_output_.GetState() << ", sample_rate=" << out->sample_rate_
                   << ", sample_rate=" << out->sample_rate_ << ", channels=0x"
                   << ", channels=" << StringPrintf("%#x", out->channel_mask_) << ", format=" << out->format_;
                   << android::base::StringPrintf("%x", out->channel_mask_)
                   << ", format=" << out->format_;
    } else {
    } else {
      LOG(WARNING) << __func__
      LOG(WARNING) << __func__
                   << ": state=" << out->bluetooth_output_.GetState()
                   << ": state=" << out->bluetooth_output_.GetState()
@@ -554,12 +549,9 @@ static int out_get_presentation_position(const struct audio_stream_out* stream,
        timestamp->tv_sec += static_cast<int>(timestamp->tv_nsec / 1000000000);
        timestamp->tv_sec += static_cast<int>(timestamp->tv_nsec / 1000000000);
        timestamp->tv_nsec %= 1000000000;
        timestamp->tv_nsec %= 1000000000;
      }
      }
      LOG(VERBOSE) << __func__
      LOG(VERBOSE) << __func__ << ": state=" << out->bluetooth_output_.GetState() << ", frames=" << *frames << " ("
                   << ": state=" << out->bluetooth_output_.GetState()
                   << bytes << " bytes), timestamp=" << timestamp->tv_sec << "."
                   << ", frames=" << *frames << " (" << bytes
                   << StringPrintf("%09ld", timestamp->tv_nsec) << "s";
                   << " bytes), timestamp=" << timestamp->tv_sec << "."
                   << android::base::StringPrintf("%09ld", timestamp->tv_nsec)
                   << "s";
      return 0;
      return 0;
    } else if (delay_report_ns >= kMaximumDelayMs * 1000000) {
    } else if (delay_report_ns >= kMaximumDelayMs * 1000000) {
      LOG(WARNING) << __func__
      LOG(WARNING) << __func__
@@ -572,11 +564,9 @@ static int out_get_presentation_position(const struct audio_stream_out* stream,
  if (out->frames_presented_ >= out->frames_count_) {
  if (out->frames_presented_ >= out->frames_count_) {
    clock_gettime(CLOCK_MONOTONIC, timestamp);
    clock_gettime(CLOCK_MONOTONIC, timestamp);
    *frames = out->frames_presented_ - out->frames_count_;
    *frames = out->frames_presented_ - out->frames_count_;
    LOG(VERBOSE) << __func__ << ": state=" << out->bluetooth_output_.GetState()
    LOG(VERBOSE) << __func__ << ": state=" << out->bluetooth_output_.GetState() << ", frames=" << *frames << " ("
                 << ", frames=" << *frames << " (" << bytes
                 << bytes << " bytes), timestamp=" << timestamp->tv_sec << "."
                 << " bytes), timestamp=" << timestamp->tv_sec << "."
                 << StringPrintf("%09ld", timestamp->tv_nsec) << "s";
                 << android::base::StringPrintf("%09ld", timestamp->tv_nsec)
                 << "s";
    return 0;
    return 0;
  }
  }


@@ -615,8 +605,7 @@ int adev_open_output_stream(struct audio_hw_device* dev,
    delete out;
    delete out;
    return -EINVAL;
    return -EINVAL;
  }
  }
  LOG(VERBOSE) << __func__ << ": device=0x"
  LOG(VERBOSE) << __func__ << ": device=" << StringPrintf("%#x", devices);
               << android::base::StringPrintf("%08x", devices);


  out->stream_out_.common.get_sample_rate = out_get_sample_rate;
  out->stream_out_.common.get_sample_rate = out_get_sample_rate;
  out->stream_out_.common.set_sample_rate = out_set_sample_rate;
  out->stream_out_.common.set_sample_rate = out_set_sample_rate;
@@ -646,7 +635,7 @@ int adev_open_output_stream(struct audio_hw_device* dev,
  }
  }
  // WAR to support Mono / 16 bits per sample as the Bluetooth stack required
  // WAR to support Mono / 16 bits per sample as the Bluetooth stack required
  if (config->channel_mask == AUDIO_CHANNEL_OUT_MONO && config->format == AUDIO_FORMAT_PCM_16_BIT) {
  if (config->channel_mask == AUDIO_CHANNEL_OUT_MONO && config->format == AUDIO_FORMAT_PCM_16_BIT) {
    LOG(INFO) << __func__ << ": force channels=0x" << android::base::StringPrintf("%x", out->channel_mask_)
    LOG(INFO) << __func__ << ": force channels=" << StringPrintf("%#x", out->channel_mask_)
              << " to be AUDIO_CHANNEL_OUT_STEREO";
              << " to be AUDIO_CHANNEL_OUT_STEREO";
    out->bluetooth_output_.ForcePcmStereoToMono(true);
    out->bluetooth_output_.ForcePcmStereoToMono(true);
    config->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
    config->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
@@ -661,10 +650,9 @@ int adev_open_output_stream(struct audio_hw_device* dev,
  out->frames_presented_ = 0;
  out->frames_presented_ = 0;


  *stream_out = &out->stream_out_;
  *stream_out = &out->stream_out_;
  LOG(INFO) << __func__ << ": state=" << out->bluetooth_output_.GetState()
  LOG(INFO) << __func__ << ": state=" << out->bluetooth_output_.GetState() << ", sample_rate=" << out->sample_rate_
            << ", sample_rate=" << out->sample_rate_ << ", channels="
            << ", channels=" << StringPrintf("%#x", out->channel_mask_) << ", format=" << out->format_
            << android::base::StringPrintf("%x", out->channel_mask_)
            << ", frames=" << out->frames_count_;
            << ", format=" << out->format_ << ", frames=" << out->frames_count_;
  return 0;
  return 0;
}
}