Commit f174b5c9 authored by Yuchen Liu's avatar Yuchen Liu Committed by Commit Bot

[Chromecast] New struct BitstreamAudioCodecsInfo

The struct contains two bitmaps for passthrough codecs' properties:
-- Supported bitstream codecs
-- A bit mask specifying which of the corresponding codecs support
   spatial rendering

This allows renderer process to get more information on passthrough
codecs from browser process.

Merge-with: eureka-internal/336787
Bug: internal b/139027108
Test: Build, unit test
Change-Id: I834ac35abc827bed9618b508e89209333e31afbc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1922981
Commit-Queue: Yuchen Liu <yucliu@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarSergey Volk <servolk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719463}
parent d8809aa6
......@@ -6,6 +6,7 @@
#include <vector>
#include "base/strings/strcat.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
......@@ -36,6 +37,27 @@ const char* BitstreamAudioCodecToString(int codec) {
} // namespace
BitstreamAudioCodecsInfo BitstreamAudioCodecsInfo::operator&(
const BitstreamAudioCodecsInfo& other) const {
return BitstreamAudioCodecsInfo{codecs & other.codecs,
spatial_rendering & other.spatial_rendering};
}
bool BitstreamAudioCodecsInfo::operator==(
const BitstreamAudioCodecsInfo& other) const {
return codecs == other.codecs && spatial_rendering == other.spatial_rendering;
}
bool BitstreamAudioCodecsInfo::operator!=(
const BitstreamAudioCodecsInfo& other) const {
return !(*this == other);
}
BitstreamAudioCodecsInfo BitstreamAudioCodecsInfo::ApplyCodecMask(
int mask) const {
return BitstreamAudioCodecsInfo{codecs & mask, spatial_rendering & mask};
}
std::string BitstreamAudioCodecsToString(int codecs) {
std::string codec_string = BitstreamAudioCodecToString(codecs);
if (!codec_string.empty()) {
......@@ -53,4 +75,11 @@ std::string BitstreamAudioCodecsToString(int codecs) {
return "[" + base::JoinString(codec_strings, ", ") + "]";
}
std::string BitstreamAudioCodecsInfoToString(
const BitstreamAudioCodecsInfo& info) {
return base::StrCat({"[codecs]", BitstreamAudioCodecsToString(info.codecs),
"[spatial_rendering]",
BitstreamAudioCodecsToString(info.spatial_rendering)});
}
} // namespace chromecast
......@@ -18,7 +18,27 @@ constexpr int kBitstreamAudioCodecPcmSurround = 0b010000;
constexpr int kBitstreamAudioCodecMpegHAudio = 0b100000;
constexpr int kBitstreamAudioCodecAll = 0b111111;
// Supported bitstream audio codecs and their associated properties.
struct BitstreamAudioCodecsInfo {
// Bitmap of supported bitstream audio codecs.
int codecs = kBitstreamAudioCodecNone;
// Bitmap specifying which of the corresponding codecs in |codecs| support
// spatial rendering.
int spatial_rendering = kBitstreamAudioCodecNone;
BitstreamAudioCodecsInfo operator&(
const BitstreamAudioCodecsInfo& other) const;
bool operator==(const BitstreamAudioCodecsInfo& other) const;
bool operator!=(const BitstreamAudioCodecsInfo& other) const;
BitstreamAudioCodecsInfo ApplyCodecMask(int mask) const;
};
std::string BitstreamAudioCodecsToString(int codecs);
std::string BitstreamAudioCodecsInfoToString(
const BitstreamAudioCodecsInfo& info);
} // namespace chromecast
......
......@@ -11,8 +11,7 @@
namespace chromecast {
namespace shell {
ApplicationMediaCapabilities::ApplicationMediaCapabilities()
: supported_bitstream_audio_codecs_(kBitstreamAudioCodecNone) {}
ApplicationMediaCapabilities::ApplicationMediaCapabilities() = default;
ApplicationMediaCapabilities::~ApplicationMediaCapabilities() = default;
......@@ -22,10 +21,10 @@ void ApplicationMediaCapabilities::AddReceiver(
}
void ApplicationMediaCapabilities::SetSupportedBitstreamAudioCodecs(
int codecs) {
supported_bitstream_audio_codecs_ = codecs;
const BitstreamAudioCodecsInfo& info) {
supported_bitstream_audio_codecs_info_ = info;
for (auto& observer : observers_)
observer->OnSupportedBitstreamAudioCodecsChanged(codecs);
observer->OnSupportedBitstreamAudioCodecsChanged(info);
}
void ApplicationMediaCapabilities::AddObserver(
......@@ -34,7 +33,7 @@ void ApplicationMediaCapabilities::AddObserver(
mojo::Remote<mojom::ApplicationMediaCapabilitiesObserver> observer(
std::move(observer_remote));
observer->OnSupportedBitstreamAudioCodecsChanged(
supported_bitstream_audio_codecs_);
supported_bitstream_audio_codecs_info_);
observers_.Add(std::move(observer));
}
......
......@@ -27,7 +27,7 @@ class ApplicationMediaCapabilities
void AddReceiver(
mojo::PendingReceiver<mojom::ApplicationMediaCapabilities> receiver);
void SetSupportedBitstreamAudioCodecs(int codecs);
void SetSupportedBitstreamAudioCodecs(const BitstreamAudioCodecsInfo& info);
private:
// mojom::ApplicationMediaCapabilities implementation:
......@@ -37,7 +37,7 @@ class ApplicationMediaCapabilities
mojo::ReceiverSet<mojom::ApplicationMediaCapabilities> receivers_;
mojo::RemoteSet<mojom::ApplicationMediaCapabilitiesObserver> observers_;
int supported_bitstream_audio_codecs_;
BitstreamAudioCodecsInfo supported_bitstream_audio_codecs_info_;
DISALLOW_COPY_AND_ASSIGN(ApplicationMediaCapabilities);
};
......
......@@ -4,10 +4,24 @@
module chromecast.shell.mojom;
// Supported bitstream audio codecs and their associated properties. This is the
// corresponding mojo struct of BitstreamAudioCodecsInfo in
// chromecast/base/bitstream_audio_codecs.h
struct BitstreamAudioCodecsInfo {
// Bitmap of supported bitstream audio codecs.
int32 codecs = 0;
// Bitmap specifying which of the corresponding codecs in |codecs| support
// spatial rendering.
int32 spatial_rendering = 0;
};
// Observes changes in an individual application's media capabilities.
// See chromecast/base/bitstream_audio_codecs.h for codec values.
interface ApplicationMediaCapabilitiesObserver {
OnSupportedBitstreamAudioCodecsChanged(int32 codecs);
// Called when bitstream audio supporting information is changed.
// |info| contains the latest supported bitstream audio codec information.
OnSupportedBitstreamAudioCodecsChanged(BitstreamAudioCodecsInfo info);
};
// Media capabilities for an individual application.
......
# Copyright 2019 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.
mojom = "//chromecast/common/mojom/application_media_capabilities.mojom"
public_headers = [ "//chromecast/base/bitstream_audio_codecs.h" ]
traits_headers =
[ "//chromecast/common/mojom/application_media_capabilities_traits.h" ]
sources = [
"//chromecast/common/mojom/application_media_capabilities_traits.h",
]
public_deps = [
"//chromecast/base",
]
type_mappings = [ "chromecast.shell.mojom.BitstreamAudioCodecsInfo=::chromecast::BitstreamAudioCodecsInfo" ]
// Copyright 2019 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.
#ifndef CHROMECAST_COMMON_MOJOM_APPLICATION_MEDIA_CAPABILITIES_TRAITS_H_
#define CHROMECAST_COMMON_MOJOM_APPLICATION_MEDIA_CAPABILITIES_TRAITS_H_
#include "chromecast/base/bitstream_audio_codecs.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
namespace mojo {
template <>
struct StructTraits<chromecast::shell::mojom::BitstreamAudioCodecsInfoDataView,
chromecast::BitstreamAudioCodecsInfo> {
static int32_t codecs(const chromecast::BitstreamAudioCodecsInfo& info) {
return info.codecs;
}
static int32_t spatial_rendering(
const chromecast::BitstreamAudioCodecsInfo& info) {
return info.spatial_rendering;
}
static bool Read(
chromecast::shell::mojom::BitstreamAudioCodecsInfoDataView input,
chromecast::BitstreamAudioCodecsInfo* output) {
output->codecs = input.codecs();
output->spatial_rendering = input.spatial_rendering();
return true;
}
};
} // namespace mojo
#endif // CHROMECAST_COMMON_MOJOM_APPLICATION_MEDIA_CAPABILITIES_TRAITS_H_
......@@ -78,8 +78,7 @@ constexpr base::TimeDelta kAudioRendererStartingCapacityEncrypted =
CastContentRendererClient::CastContentRendererClient()
: supported_profiles_(
std::make_unique<media::SupportedCodecProfileLevelsMemo>()),
supported_bitstream_audio_codecs_(kBitstreamAudioCodecNone) {
std::make_unique<media::SupportedCodecProfileLevelsMemo>()) {
#if defined(OS_ANDROID)
DCHECK(::media::MediaCodecUtil::IsMediaCodecAvailable())
<< "MediaCodec is not available!";
......@@ -243,11 +242,14 @@ bool CastContentRendererClient::IsSupportedAudioType(
// No ATV device we know of has (E)AC3 decoder, so it relies on the audio sink
// device.
if (type.codec == ::media::kCodecEAC3)
return kBitstreamAudioCodecEac3 & supported_bitstream_audio_codecs_;
return kBitstreamAudioCodecEac3 &
supported_bitstream_audio_codecs_info_.codecs;
if (type.codec == ::media::kCodecAC3)
return kBitstreamAudioCodecAc3 & supported_bitstream_audio_codecs_;
return kBitstreamAudioCodecAc3 &
supported_bitstream_audio_codecs_info_.codecs;
if (type.codec == ::media::kCodecMpegHAudio)
return kBitstreamAudioCodecMpegHAudio & supported_bitstream_audio_codecs_;
return kBitstreamAudioCodecMpegHAudio &
supported_bitstream_audio_codecs_info_.codecs;
// TODO(sanfin): Implement this for Android.
return true;
......@@ -288,11 +290,14 @@ bool CastContentRendererClient::IsSupportedVideoType(
bool CastContentRendererClient::IsSupportedBitstreamAudioCodec(
::media::AudioCodec codec) {
return (codec == ::media::kCodecAC3 &&
(kBitstreamAudioCodecAc3 & supported_bitstream_audio_codecs_)) ||
(kBitstreamAudioCodecAc3 &
supported_bitstream_audio_codecs_info_.codecs)) ||
(codec == ::media::kCodecEAC3 &&
(kBitstreamAudioCodecEac3 & supported_bitstream_audio_codecs_)) ||
(kBitstreamAudioCodecEac3 &
supported_bitstream_audio_codecs_info_.codecs)) ||
(codec == ::media::kCodecMpegHAudio &&
(kBitstreamAudioCodecMpegHAudio & supported_bitstream_audio_codecs_));
(kBitstreamAudioCodecMpegHAudio &
supported_bitstream_audio_codecs_info_.codecs));
}
blink::WebPrescientNetworking*
......@@ -333,8 +338,8 @@ void CastContentRendererClient::
}
void CastContentRendererClient::OnSupportedBitstreamAudioCodecsChanged(
int codecs) {
supported_bitstream_audio_codecs_ = codecs;
const BitstreamAudioCodecsInfo& info) {
supported_bitstream_audio_codecs_info_ = info;
}
std::unique_ptr<content::URLLoaderThrottleProvider>
......
......@@ -90,7 +90,8 @@ class CastContentRendererClient
private:
// mojom::ApplicationMediaCapabilitiesObserver implementation:
void OnSupportedBitstreamAudioCodecsChanged(int codecs) override;
void OnSupportedBitstreamAudioCodecsChanged(
const BitstreamAudioCodecsInfo& info) override;
std::unique_ptr<network_hints::WebPrescientNetworkingImpl>
web_prescient_networking_impl_;
......@@ -114,7 +115,7 @@ class CastContentRendererClient
std::unique_ptr<media::CastAudioDeviceFactory> cast_audio_device_factory_;
#endif
int supported_bitstream_audio_codecs_;
BitstreamAudioCodecsInfo supported_bitstream_audio_codecs_info_;
DISALLOW_COPY_AND_ASSIGN(CastContentRendererClient);
};
......
......@@ -4,7 +4,10 @@
import("//build/config/chromecast_build.gni")
typemaps = [ "//chromecast/common/mojom/multiroom.typemap" ]
typemaps = [
"//chromecast/common/mojom/application_media_capabilities.typemap",
"//chromecast/common/mojom/multiroom.typemap",
]
if (chromecast_branding != "public") {
_typemap_internal = read_file("//chromecast/internal/typemaps.gni", "scope")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment