Merge "StreamHalLocal: Fix STREAM_EVENT_CBK_TYPE_CODEC_FORMAT_CHANGED" am: 5dd9da8b09 am: 2eeee6fff8 am: 358f6f9465 am: 9a8a479a73 am: 52fedbfc32 am: ae7217e976
Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1694625
Change-Id: Iaccaf25696887edd10beda8bce27c33b55ec751e
diff --git a/cmds/screenrecord/screenrecord.cpp b/cmds/screenrecord/screenrecord.cpp
index e6e3473..cd8fe97 100644
--- a/cmds/screenrecord/screenrecord.cpp
+++ b/cmds/screenrecord/screenrecord.cpp
@@ -1067,7 +1067,7 @@
std::optional<PhysicalDisplayId> displayId = SurfaceComposerClient::getInternalDisplayId();
if (!displayId) {
- fprintf(stderr, "Failed to get token for internal display\n");
+ fprintf(stderr, "Failed to get ID for internal display\n");
return 1;
}
@@ -1168,17 +1168,14 @@
}
break;
case 'd':
- gPhysicalDisplayId = PhysicalDisplayId(atoll(optarg));
- if (gPhysicalDisplayId.value == 0) {
- fprintf(stderr, "Please specify a valid physical display id\n");
- return 2;
- } else if (SurfaceComposerClient::
- getPhysicalDisplayToken(gPhysicalDisplayId) == nullptr) {
- fprintf(stderr, "Invalid physical display id: %s\n",
- to_string(gPhysicalDisplayId).c_str());
- return 2;
+ if (const auto id = android::DisplayId::fromValue<PhysicalDisplayId>(atoll(optarg));
+ id && SurfaceComposerClient::getPhysicalDisplayToken(*id)) {
+ gPhysicalDisplayId = *id;
+ break;
}
- break;
+
+ fprintf(stderr, "Invalid physical display ID\n");
+ return 2;
default:
if (ic != '?') {
fprintf(stderr, "getopt_long returned unexpected value 0x%x\n", ic);
diff --git a/drm/mediadrm/plugins/TEST_MAPPING b/drm/mediadrm/plugins/TEST_MAPPING
index 7bd1568..87becb6 100644
--- a/drm/mediadrm/plugins/TEST_MAPPING
+++ b/drm/mediadrm/plugins/TEST_MAPPING
@@ -11,6 +11,9 @@
},
{
"include-filter": "android.media.cts.MediaDrmMetricsTest"
+ },
+ {
+ "include-filter": "android.media.cts.NativeMediaDrmClearkeyTest"
}
]
}
diff --git a/drm/mediadrm/plugins/clearkey/hidl/DrmPlugin.cpp b/drm/mediadrm/plugins/clearkey/hidl/DrmPlugin.cpp
index 6a374f9..0cd9375 100644
--- a/drm/mediadrm/plugins/clearkey/hidl/DrmPlugin.cpp
+++ b/drm/mediadrm/plugins/clearkey/hidl/DrmPlugin.cpp
@@ -221,7 +221,6 @@
if (requestString.find(kOfflineLicense) != std::string::npos) {
std::string emptyResponse;
std::string keySetIdString(keySetId.begin(), keySetId.end());
- Mutex::Autolock lock(mFileHandleLock);
if (!mFileHandle.StoreLicense(keySetIdString,
DeviceFiles::kLicenseStateReleasing,
emptyResponse)) {
@@ -337,7 +336,6 @@
}
*keySetId = kKeySetIdPrefix + ByteArrayToHexString(
reinterpret_cast<const uint8_t*>(randomData.data()), randomData.size());
- Mutex::Autolock lock(mFileHandleLock);
if (mFileHandle.LicenseExists(*keySetId)) {
// collision, regenerate
ALOGV("Retry generating KeySetId");
@@ -395,7 +393,6 @@
if (status == Status::OK) {
if (isOfflineLicense) {
if (isRelease) {
- Mutex::Autolock lock(mFileHandleLock);
mFileHandle.DeleteLicense(keySetId);
mSessionLibrary->destroySession(session);
} else {
@@ -404,7 +401,6 @@
return Void();
}
- Mutex::Autolock lock(mFileHandleLock);
bool ok = mFileHandle.StoreLicense(
keySetId,
DeviceFiles::kLicenseStateActive,
@@ -459,7 +455,6 @@
DeviceFiles::LicenseState licenseState;
std::string offlineLicense;
Status status = Status::OK;
- Mutex::Autolock lock(mFileHandleLock);
if (!mFileHandle.RetrieveLicense(std::string(keySetId.begin(), keySetId.end()),
&licenseState, &offlineLicense)) {
ALOGE("Failed to restore offline license");
@@ -769,8 +764,6 @@
}
Return<void> DrmPlugin::getOfflineLicenseKeySetIds(getOfflineLicenseKeySetIds_cb _hidl_cb) {
- Mutex::Autolock lock(mFileHandleLock);
-
std::vector<std::string> licenseNames = mFileHandle.ListLicenses();
std::vector<KeySetId> keySetIds;
if (mMockError != Status_V1_2::OK) {
@@ -791,7 +784,6 @@
return toStatus_1_0(mMockError);
}
std::string licenseName(keySetId.begin(), keySetId.end());
- Mutex::Autolock lock(mFileHandleLock);
if (mFileHandle.DeleteLicense(licenseName)) {
return Status::OK;
}
@@ -800,8 +792,6 @@
Return<void> DrmPlugin::getOfflineLicenseState(const KeySetId& keySetId,
getOfflineLicenseState_cb _hidl_cb) {
- Mutex::Autolock lock(mFileHandleLock);
-
std::string licenseName(keySetId.begin(), keySetId.end());
DeviceFiles::LicenseState state;
std::string license;
diff --git a/drm/mediadrm/plugins/clearkey/hidl/MemoryFileSystem.cpp b/drm/mediadrm/plugins/clearkey/hidl/MemoryFileSystem.cpp
index e61db3f..56910be 100644
--- a/drm/mediadrm/plugins/clearkey/hidl/MemoryFileSystem.cpp
+++ b/drm/mediadrm/plugins/clearkey/hidl/MemoryFileSystem.cpp
@@ -24,13 +24,11 @@
}
bool MemoryFileSystem::FileExists(const std::string& fileName) const {
- std::lock_guard<std::mutex> lock(mMemoryFileSystemLock);
auto result = mMemoryFileSystem.find(fileName);
return result != mMemoryFileSystem.end();
}
ssize_t MemoryFileSystem::GetFileSize(const std::string& fileName) const {
- std::lock_guard<std::mutex> lock(mMemoryFileSystemLock);
auto result = mMemoryFileSystem.find(fileName);
if (result != mMemoryFileSystem.end()) {
return static_cast<ssize_t>(result->second.getFileSize());
@@ -42,7 +40,6 @@
std::vector<std::string> MemoryFileSystem::ListFiles() const {
std::vector<std::string> list;
- std::lock_guard<std::mutex> lock(mMemoryFileSystemLock);
for (const auto& filename : mMemoryFileSystem) {
list.push_back(filename.first);
}
@@ -51,7 +48,6 @@
size_t MemoryFileSystem::Read(const std::string& path, std::string* buffer) {
std::string key = GetFileName(path);
- std::lock_guard<std::mutex> lock(mMemoryFileSystemLock);
auto result = mMemoryFileSystem.find(key);
if (result != mMemoryFileSystem.end()) {
std::string serializedHashFile = result->second.getContent();
@@ -65,7 +61,6 @@
size_t MemoryFileSystem::Write(const std::string& path, const MemoryFile& memoryFile) {
std::string key = GetFileName(path);
- std::lock_guard<std::mutex> lock(mMemoryFileSystemLock);
auto result = mMemoryFileSystem.find(key);
if (result != mMemoryFileSystem.end()) {
mMemoryFileSystem.erase(key);
@@ -75,7 +70,6 @@
}
bool MemoryFileSystem::RemoveFile(const std::string& fileName) {
- std::lock_guard<std::mutex> lock(mMemoryFileSystemLock);
auto result = mMemoryFileSystem.find(fileName);
if (result != mMemoryFileSystem.end()) {
mMemoryFileSystem.erase(result);
@@ -87,7 +81,6 @@
}
bool MemoryFileSystem::RemoveAllFiles() {
- std::lock_guard<std::mutex> lock(mMemoryFileSystemLock);
mMemoryFileSystem.clear();
return mMemoryFileSystem.empty();
}
diff --git a/drm/mediadrm/plugins/clearkey/hidl/include/DrmPlugin.h b/drm/mediadrm/plugins/clearkey/hidl/include/DrmPlugin.h
index 5d6e3da..cb5c9fe 100644
--- a/drm/mediadrm/plugins/clearkey/hidl/include/DrmPlugin.h
+++ b/drm/mediadrm/plugins/clearkey/hidl/include/DrmPlugin.h
@@ -432,8 +432,7 @@
mMockError = Status_V1_2::OK;
}
- DeviceFiles mFileHandle GUARDED_BY(mFileHandleLock);
- Mutex mFileHandleLock;
+ DeviceFiles mFileHandle;
Mutex mSecureStopLock;
CLEARKEY_DISALLOW_COPY_AND_ASSIGN_AND_NEW(DrmPlugin);
diff --git a/drm/mediadrm/plugins/clearkey/hidl/include/MemoryFileSystem.h b/drm/mediadrm/plugins/clearkey/hidl/include/MemoryFileSystem.h
index a90d818..1d98860 100644
--- a/drm/mediadrm/plugins/clearkey/hidl/include/MemoryFileSystem.h
+++ b/drm/mediadrm/plugins/clearkey/hidl/include/MemoryFileSystem.h
@@ -5,9 +5,7 @@
#ifndef CLEARKEY_MEMORY_FILE_SYSTEM_H_
#define CLEARKEY_MEMORY_FILE_SYSTEM_H_
-#include <android-base/thread_annotations.h>
#include <map>
-#include <mutex>
#include <string>
#include "ClearKeyTypes.h"
@@ -51,12 +49,10 @@
size_t Write(const std::string& pathName, const MemoryFile& memoryFile);
private:
- mutable std::mutex mMemoryFileSystemLock;
-
// License file name is made up of a unique keySetId, therefore,
// the filename can be used as the key to locate licenses in the
// memory file system.
- std::map<std::string, MemoryFile> mMemoryFileSystem GUARDED_BY(mMemoryFileSystemLock);
+ std::map<std::string, MemoryFile> mMemoryFileSystem;
std::string GetFileName(const std::string& path);
diff --git a/media/codec2/components/gav1/C2SoftGav1Dec.cpp b/media/codec2/components/gav1/C2SoftGav1Dec.cpp
index 76345ae..9872504 100644
--- a/media/codec2/components/gav1/C2SoftGav1Dec.cpp
+++ b/media/codec2/components/gav1/C2SoftGav1Dec.cpp
@@ -26,6 +26,11 @@
#include <media/stagefright/foundation/MediaDefs.h>
namespace android {
+namespace {
+
+constexpr uint8_t NEUTRAL_UV_VALUE = 128;
+
+} // namespace
// codecname set and passed in as a compile flag from Android.bp
constexpr char COMPONENT_NAME[] = CODECNAME;
@@ -51,8 +56,8 @@
DefineParam(mSize, C2_PARAMKEY_PICTURE_SIZE)
.withDefault(new C2StreamPictureSizeInfo::output(0u, 320, 240))
.withFields({
- C2F(mSize, width).inRange(2, 2048, 2),
- C2F(mSize, height).inRange(2, 2048, 2),
+ C2F(mSize, width).inRange(2, 4096, 2),
+ C2F(mSize, height).inRange(2, 4096, 2),
})
.withSetter(SizeSetter)
.build());
@@ -462,7 +467,8 @@
const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV,
size_t srcYStride, size_t srcUStride, size_t srcVStride,
size_t dstYStride, size_t dstUVStride,
- uint32_t width, uint32_t height) {
+ uint32_t width, uint32_t height,
+ bool isMonochrome) {
for (size_t i = 0; i < height; ++i) {
memcpy(dstY, srcY, width);
@@ -470,6 +476,17 @@
dstY += dstYStride;
}
+ if (isMonochrome) {
+ // Fill with neutral U/V values.
+ for (size_t i = 0; i < height / 2; ++i) {
+ memset(dstV, NEUTRAL_UV_VALUE, width / 2);
+ memset(dstU, NEUTRAL_UV_VALUE, width / 2);
+ dstV += dstUVStride;
+ dstU += dstUVStride;
+ }
+ return;
+ }
+
for (size_t i = 0; i < height / 2; ++i) {
memcpy(dstV, srcV, width / 2);
srcV += srcVStride;
@@ -555,7 +572,7 @@
const uint16_t *srcY, const uint16_t *srcU, const uint16_t *srcV,
size_t srcYStride, size_t srcUStride, size_t srcVStride,
size_t dstYStride, size_t dstUVStride,
- size_t width, size_t height) {
+ size_t width, size_t height, bool isMonochrome) {
for (size_t y = 0; y < height; ++y) {
for (size_t x = 0; x < width; ++x) {
@@ -566,6 +583,17 @@
dstY += dstYStride;
}
+ if (isMonochrome) {
+ // Fill with neutral U/V values.
+ for (size_t y = 0; y < (height + 1) / 2; ++y) {
+ memset(dstV, NEUTRAL_UV_VALUE, (width + 1) / 2);
+ memset(dstU, NEUTRAL_UV_VALUE, (width + 1) / 2);
+ dstV += dstUVStride;
+ dstU += dstUVStride;
+ }
+ return;
+ }
+
for (size_t y = 0; y < (height + 1) / 2; ++y) {
for (size_t x = 0; x < (width + 1) / 2; ++x) {
dstU[x] = (uint8_t)(srcU[x] >> 2);
@@ -621,8 +649,10 @@
}
}
- // TODO(vigneshv): Add support for monochrome videos since AV1 supports it.
- CHECK(buffer->image_format == libgav1::kImageFormatYuv420);
+ CHECK(buffer->image_format == libgav1::kImageFormatYuv420 ||
+ buffer->image_format == libgav1::kImageFormatMonochrome400);
+ const bool isMonochrome =
+ buffer->image_format == libgav1::kImageFormatMonochrome400;
std::shared_ptr<C2GraphicBlock> block;
uint32_t format = HAL_PIXEL_FORMAT_YV12;
@@ -634,6 +664,13 @@
if (defaultColorAspects->primaries == C2Color::PRIMARIES_BT2020 &&
defaultColorAspects->matrix == C2Color::MATRIX_BT2020 &&
defaultColorAspects->transfer == C2Color::TRANSFER_ST2084) {
+ if (buffer->image_format != libgav1::kImageFormatYuv420) {
+ ALOGE("Only YUV420 output is supported when targeting RGBA_1010102");
+ mSignalledError = true;
+ work->result = C2_OMITTED;
+ work->workletsProcessed = 1u;
+ return false;
+ }
format = HAL_PIXEL_FORMAT_RGBA_1010102;
}
}
@@ -680,21 +717,18 @@
(uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2, srcUStride / 2,
srcVStride / 2, dstYStride / sizeof(uint32_t), mWidth, mHeight);
} else {
- convertYUV420Planar16ToYUV420Planar(dstY, dstU, dstV,
- srcY, srcU, srcV,
- srcYStride / 2, srcUStride / 2, srcVStride / 2,
- dstYStride, dstUVStride,
- mWidth, mHeight);
+ convertYUV420Planar16ToYUV420Planar(
+ dstY, dstU, dstV, srcY, srcU, srcV, srcYStride / 2, srcUStride / 2,
+ srcVStride / 2, dstYStride, dstUVStride, mWidth, mHeight,
+ isMonochrome);
}
} else {
const uint8_t *srcY = (const uint8_t *)buffer->plane[0];
const uint8_t *srcU = (const uint8_t *)buffer->plane[1];
const uint8_t *srcV = (const uint8_t *)buffer->plane[2];
- copyOutputBufferToYV12Frame(dstY, dstU, dstV,
- srcY, srcU, srcV,
- srcYStride, srcUStride, srcVStride,
- dstYStride, dstUVStride,
- mWidth, mHeight);
+ copyOutputBufferToYV12Frame(
+ dstY, dstU, dstV, srcY, srcU, srcV, srcYStride, srcUStride, srcVStride,
+ dstYStride, dstUVStride, mWidth, mHeight, isMonochrome);
}
finishWork(buffer->user_private_data, work, std::move(block));
block = nullptr;
diff --git a/media/libaaudio/src/Android.bp b/media/libaaudio/src/Android.bp
index fe2d98e..7cadacd 100644
--- a/media/libaaudio/src/Android.bp
+++ b/media/libaaudio/src/Android.bp
@@ -7,6 +7,65 @@
default_applicable_licenses: ["frameworks_av_license"],
}
+tidy_errors = [
+ // https://clang.llvm.org/extra/clang-tidy/checks/list.html
+ // For many categories, the checks are too many to specify individually.
+ // Feel free to disable as needed - as warnings are generally ignored,
+ // we treat warnings as errors.
+ "android-*",
+ "bugprone-*",
+ "cert-*",
+ "clang-analyzer-security*",
+ "google-*",
+ "misc-*",
+ //"modernize-*", // explicitly list the modernize as they can be subjective.
+ "modernize-avoid-bind",
+ //"modernize-avoid-c-arrays", // std::array<> can be verbose
+ "modernize-concat-nested-namespaces",
+ //"modernize-deprecated-headers", // C headers still ok even if there is C++ equivalent.
+ "modernize-deprecated-ios-base-aliases",
+ "modernize-loop-convert",
+ "modernize-make-shared",
+ "modernize-make-unique",
+ "modernize-pass-by-value",
+ "modernize-raw-string-literal",
+ "modernize-redundant-void-arg",
+ "modernize-replace-auto-ptr",
+ "modernize-replace-random-shuffle",
+ "modernize-return-braced-init-list",
+ "modernize-shrink-to-fit",
+ "modernize-unary-static-assert",
+ // "modernize-use-auto", // found in AAudioAudio.cpp
+ "modernize-use-bool-literals",
+ "modernize-use-default-member-init",
+ "modernize-use-emplace",
+ "modernize-use-equals-default",
+ "modernize-use-equals-delete",
+ // "modernize-use-nodiscard", // found in aidl generated files
+ "modernize-use-noexcept",
+ "modernize-use-nullptr",
+ // "modernize-use-override", // found in aidl generated files
+ // "modernize-use-trailing-return-type", // not necessarily more readable
+ "modernize-use-transparent-functors",
+ "modernize-use-uncaught-exceptions",
+ // "modernize-use-using", // found typedef in several files
+ "performance-*",
+
+ // Remove some pedantic stylistic requirements.
+ "-android-cloexec-dup", // found in SharedMemoryParcelable.cpp
+ "-bugprone-macro-parentheses", // found in SharedMemoryParcelable.h
+ "-bugprone-narrowing-conversions", // found in several interface from size_t to int32_t
+
+ "-google-readability-casting", // C++ casts not always necessary and may be verbose
+ "-google-readability-todo", // do not require TODO(info)
+ "-google-build-using-namespace", // Reenable and fix later.
+ "-google-global-names-in-headers", // found in several files
+
+ "-misc-non-private-member-variables-in-classes", // found in aidl generated files
+
+ "-performance-no-int-to-ptr", // found in SharedMemoryParcelable.h
+]
+
cc_library {
name: "libaaudio",
@@ -63,6 +122,13 @@
symbol_file: "libaaudio.map.txt",
versions: ["28"],
},
+
+ tidy: true,
+ tidy_checks: tidy_errors,
+ tidy_checks_as_errors: tidy_errors,
+ tidy_flags: [
+ "-format-style=file",
+ ]
}
cc_library {
@@ -159,6 +225,13 @@
integer_overflow: true,
misc_undefined: ["bounds"],
},
+
+ tidy: true,
+ tidy_checks: tidy_errors,
+ tidy_checks_as_errors: tidy_errors,
+ tidy_flags: [
+ "-format-style=file",
+ ]
}
aidl_interface {
@@ -175,19 +248,14 @@
"binding/aidl/aaudio/IAAudioService.aidl",
],
imports: [
- "audio_common-aidl",
+ "android.media.audio.common.types",
"shared-file-region-aidl",
"media_permission-aidl",
],
backend:
{
- cpp: {
- enabled: true,
- },
java: {
- // TODO: need to have audio_common-aidl available in Java to enable
- // this.
- enabled: false,
+ sdk_version: "module_current",
},
},
}
diff --git a/media/libaaudio/src/binding/AAudioBinderClient.cpp b/media/libaaudio/src/binding/AAudioBinderClient.cpp
index fa5a2da..135bac3 100644
--- a/media/libaaudio/src/binding/AAudioBinderClient.cpp
+++ b/media/libaaudio/src/binding/AAudioBinderClient.cpp
@@ -36,13 +36,10 @@
using android::IServiceManager;
using android::defaultServiceManager;
using android::interface_cast;
-using android::IInterface;
using android::Mutex;
using android::ProcessState;
using android::sp;
using android::status_t;
-using android::wp;
-using android::binder::Status;
using namespace aaudio;
@@ -93,7 +90,7 @@
ALOGE("%s() - linkToDeath() returned %d", __func__, status);
}
aaudioService = interface_cast<IAAudioService>(binder);
- mAdapter.reset(new Adapter(aaudioService, mAAudioClient));
+ mAdapter = std::make_shared<Adapter>(aaudioService, mAAudioClient);
needToRegister = true;
// Make sure callbacks can be received by mAAudioClient
ProcessState::self()->startThreadPool();
diff --git a/media/libaaudio/src/binding/AAudioBinderClient.h b/media/libaaudio/src/binding/AAudioBinderClient.h
index 6a7b639..557ced5 100644
--- a/media/libaaudio/src/binding/AAudioBinderClient.h
+++ b/media/libaaudio/src/binding/AAudioBinderClient.h
@@ -108,7 +108,7 @@
return AAUDIO_ERROR_UNAVAILABLE;
}
- void onStreamChange(aaudio_handle_t handle, int32_t opcode, int32_t value) {
+ void onStreamChange(aaudio_handle_t /*handle*/, int32_t /*opcode*/, int32_t /*value*/) {
// TODO This is just a stub so we can have a client Binder to pass to the service.
// TODO Implemented in a later CL.
ALOGW("onStreamChange called!");
@@ -116,7 +116,7 @@
class AAudioClient : public android::IBinder::DeathRecipient, public BnAAudioClient {
public:
- AAudioClient(android::wp<AAudioBinderClient> aaudioBinderClient)
+ explicit AAudioClient(const android::wp<AAudioBinderClient>& aaudioBinderClient)
: mBinderClient(aaudioBinderClient) {
}
@@ -150,10 +150,10 @@
class Adapter : public AAudioBinderAdapter {
public:
Adapter(const android::sp<IAAudioService>& delegate,
- const android::sp<AAudioClient>& aaudioClient)
+ android::sp<AAudioClient> aaudioClient)
: AAudioBinderAdapter(delegate.get()),
mDelegate(delegate),
- mAAudioClient(aaudioClient) {}
+ mAAudioClient(std::move(aaudioClient)) {}
virtual ~Adapter() {
if (mDelegate != nullptr) {
diff --git a/media/libaaudio/src/binding/AAudioServiceInterface.h b/media/libaaudio/src/binding/AAudioServiceInterface.h
index 5d11512..bf94774 100644
--- a/media/libaaudio/src/binding/AAudioServiceInterface.h
+++ b/media/libaaudio/src/binding/AAudioServiceInterface.h
@@ -37,7 +37,7 @@
class AAudioServiceInterface {
public:
- AAudioServiceInterface() {};
+ AAudioServiceInterface() = default;
virtual ~AAudioServiceInterface() = default;
virtual void registerClient(const android::sp<IAAudioClient>& client) = 0;
diff --git a/media/libaaudio/src/binding/AAudioStreamRequest.cpp b/media/libaaudio/src/binding/AAudioStreamRequest.cpp
index 5e0a4bb..09f7a1c 100644
--- a/media/libaaudio/src/binding/AAudioStreamRequest.cpp
+++ b/media/libaaudio/src/binding/AAudioStreamRequest.cpp
@@ -30,7 +30,7 @@
using namespace aaudio;
AAudioStreamRequest::AAudioStreamRequest(const StreamRequest& parcelable) :
- mConfiguration(std::move(parcelable.params)),
+ mConfiguration(parcelable.params),
mIdentity(parcelable.identity),
mSharingModeMatchRequired(parcelable.sharingModeMatchRequired),
mInService(parcelable.inService) {
@@ -38,7 +38,7 @@
StreamRequest AAudioStreamRequest::parcelable() const {
StreamRequest result;
- result.params = std::move(mConfiguration).parcelable();
+ result.params = mConfiguration.parcelable();
result.identity = mIdentity;
result.sharingModeMatchRequired = mSharingModeMatchRequired;
result.inService = mInService;
diff --git a/media/libaaudio/src/binding/AudioEndpointParcelable.cpp b/media/libaaudio/src/binding/AudioEndpointParcelable.cpp
index aa4ac27..dea3e4a 100644
--- a/media/libaaudio/src/binding/AudioEndpointParcelable.cpp
+++ b/media/libaaudio/src/binding/AudioEndpointParcelable.cpp
@@ -29,17 +29,15 @@
#include "binding/AudioEndpointParcelable.h"
using android::base::unique_fd;
-using android::media::SharedFileRegion;
-using android::NO_ERROR;
using android::status_t;
using namespace aaudio;
AudioEndpointParcelable::AudioEndpointParcelable(Endpoint&& parcelable)
- : mUpMessageQueueParcelable(std::move(parcelable.upMessageQueueParcelable)),
- mDownMessageQueueParcelable(std::move(parcelable.downMessageQueueParcelable)),
- mUpDataQueueParcelable(std::move(parcelable.upDataQueueParcelable)),
- mDownDataQueueParcelable(std::move(parcelable.downDataQueueParcelable)),
+ : mUpMessageQueueParcelable(parcelable.upMessageQueueParcelable),
+ mDownMessageQueueParcelable(parcelable.downMessageQueueParcelable),
+ mUpDataQueueParcelable(parcelable.upDataQueueParcelable),
+ mDownDataQueueParcelable(parcelable.downDataQueueParcelable),
mNumSharedMemories(parcelable.sharedMemories.size()) {
for (size_t i = 0; i < parcelable.sharedMemories.size() && i < MAX_SHARED_MEMORIES; ++i) {
// Re-construct.
@@ -56,10 +54,10 @@
Endpoint AudioEndpointParcelable::parcelable()&& {
Endpoint result;
- result.upMessageQueueParcelable = std::move(mUpMessageQueueParcelable).parcelable();
- result.downMessageQueueParcelable = std::move(mDownMessageQueueParcelable).parcelable();
- result.upDataQueueParcelable = std::move(mUpDataQueueParcelable).parcelable();
- result.downDataQueueParcelable = std::move(mDownDataQueueParcelable).parcelable();
+ result.upMessageQueueParcelable = mUpMessageQueueParcelable.parcelable();
+ result.downMessageQueueParcelable = mDownMessageQueueParcelable.parcelable();
+ result.upDataQueueParcelable = mUpDataQueueParcelable.parcelable();
+ result.downDataQueueParcelable = mDownDataQueueParcelable.parcelable();
result.sharedMemories.reserve(std::min(mNumSharedMemories, MAX_SHARED_MEMORIES));
for (size_t i = 0; i < mNumSharedMemories && i < MAX_SHARED_MEMORIES; ++i) {
result.sharedMemories.emplace_back(std::move(mSharedMemories[i]).parcelable());
diff --git a/media/libaaudio/src/binding/AudioEndpointParcelable.h b/media/libaaudio/src/binding/AudioEndpointParcelable.h
index 5237a1a..544aa92 100644
--- a/media/libaaudio/src/binding/AudioEndpointParcelable.h
+++ b/media/libaaudio/src/binding/AudioEndpointParcelable.h
@@ -43,7 +43,7 @@
// Ctor/assignment from a parcelable representation.
// Since the parcelable object owns unique FDs (for shared memory blocks), move semantics are
// provided to avoid the need to dupe.
- AudioEndpointParcelable(Endpoint&& parcelable);
+ explicit AudioEndpointParcelable(Endpoint&& parcelable);
AudioEndpointParcelable& operator=(Endpoint&& parcelable);
/**
diff --git a/media/libaaudio/src/binding/RingBufferParcelable.cpp b/media/libaaudio/src/binding/RingBufferParcelable.cpp
index a4b3cec..fa7ca72 100644
--- a/media/libaaudio/src/binding/RingBufferParcelable.cpp
+++ b/media/libaaudio/src/binding/RingBufferParcelable.cpp
@@ -30,9 +30,9 @@
using namespace aaudio;
RingBufferParcelable::RingBufferParcelable(const RingBuffer& parcelable)
- : mReadCounterParcelable(std::move(parcelable.readCounterParcelable)),
- mWriteCounterParcelable(std::move(parcelable.writeCounterParcelable)),
- mDataParcelable(std::move(parcelable.dataParcelable)),
+ : mReadCounterParcelable(parcelable.readCounterParcelable),
+ mWriteCounterParcelable(parcelable.writeCounterParcelable),
+ mDataParcelable(parcelable.dataParcelable),
mBytesPerFrame(parcelable.bytesPerFrame),
mFramesPerBurst(parcelable.framesPerBurst),
mCapacityInFrames(parcelable.capacityInFrames),
@@ -42,9 +42,9 @@
RingBuffer RingBufferParcelable::parcelable() const {
RingBuffer result;
- result.readCounterParcelable = std::move(mReadCounterParcelable).parcelable();
- result.writeCounterParcelable = std::move(mWriteCounterParcelable).parcelable();
- result.dataParcelable = std::move(mDataParcelable).parcelable();
+ result.readCounterParcelable = mReadCounterParcelable.parcelable();
+ result.writeCounterParcelable = mWriteCounterParcelable.parcelable();
+ result.dataParcelable = mDataParcelable.parcelable();
result.bytesPerFrame = mBytesPerFrame;
result.framesPerBurst = mFramesPerBurst;
result.capacityInFrames = mCapacityInFrames;
diff --git a/media/libaaudio/src/binding/SharedMemoryParcelable.cpp b/media/libaaudio/src/binding/SharedMemoryParcelable.cpp
index eef238f..3a49655 100644
--- a/media/libaaudio/src/binding/SharedMemoryParcelable.cpp
+++ b/media/libaaudio/src/binding/SharedMemoryParcelable.cpp
@@ -32,7 +32,6 @@
#include "binding/SharedMemoryParcelable.h"
using android::base::unique_fd;
-using android::NO_ERROR;
using android::status_t;
using android::media::SharedFileRegion;
@@ -78,7 +77,7 @@
}
aaudio_result_t SharedMemoryParcelable::resolveSharedMemory(const unique_fd& fd) {
- mResolvedAddress = (uint8_t *) mmap(0, mSizeInBytes, PROT_READ | PROT_WRITE,
+ mResolvedAddress = (uint8_t *) mmap(nullptr, mSizeInBytes, PROT_READ | PROT_WRITE,
MAP_SHARED, fd.get(), 0);
if (mResolvedAddress == MMAP_UNRESOLVED_ADDRESS) {
ALOGE("mmap() failed for fd = %d, nBytes = %" PRId64 ", errno = %s",
diff --git a/media/libaaudio/src/binding/SharedRegionParcelable.cpp b/media/libaaudio/src/binding/SharedRegionParcelable.cpp
index 56b99c0..6fa109b 100644
--- a/media/libaaudio/src/binding/SharedRegionParcelable.cpp
+++ b/media/libaaudio/src/binding/SharedRegionParcelable.cpp
@@ -29,10 +29,7 @@
#include "binding/SharedMemoryParcelable.h"
#include "binding/SharedRegionParcelable.h"
-using android::NO_ERROR;
using android::status_t;
-using android::Parcel;
-using android::Parcelable;
using namespace aaudio;
diff --git a/media/libaaudio/src/client/AudioEndpoint.cpp b/media/libaaudio/src/client/AudioEndpoint.cpp
index 0a19d17..7427a8e 100644
--- a/media/libaaudio/src/client/AudioEndpoint.cpp
+++ b/media/libaaudio/src/client/AudioEndpoint.cpp
@@ -31,13 +31,6 @@
#define RIDICULOUSLY_LARGE_BUFFER_CAPACITY (256 * 1024)
#define RIDICULOUSLY_LARGE_FRAME_SIZE 4096
-AudioEndpoint::AudioEndpoint()
- : mFreeRunning(false)
- , mDataReadCounter(0)
- , mDataWriteCounter(0)
-{
-}
-
// TODO Consider moving to a method in RingBufferDescriptor
static aaudio_result_t AudioEndpoint_validateQueueDescriptor(const char *type,
const RingBufferDescriptor *descriptor) {
diff --git a/media/libaaudio/src/client/AudioEndpoint.h b/media/libaaudio/src/client/AudioEndpoint.h
index 4c8d60f..b3dbc20 100644
--- a/media/libaaudio/src/client/AudioEndpoint.h
+++ b/media/libaaudio/src/client/AudioEndpoint.h
@@ -34,7 +34,7 @@
class AudioEndpoint {
public:
- AudioEndpoint();
+ AudioEndpoint() = default;
/**
* Configure based on the EndPointDescriptor_t.
@@ -95,9 +95,9 @@
private:
std::unique_ptr<android::FifoBufferIndirect> mUpCommandQueue;
std::unique_ptr<android::FifoBufferIndirect> mDataQueue;
- bool mFreeRunning;
- android::fifo_counter_t mDataReadCounter; // only used if free-running
- android::fifo_counter_t mDataWriteCounter; // only used if free-running
+ bool mFreeRunning{false};
+ android::fifo_counter_t mDataReadCounter{0}; // only used if free-running
+ android::fifo_counter_t mDataWriteCounter{0}; // only used if free-running
};
} // namespace aaudio
diff --git a/media/libaaudio/src/client/AudioStreamInternal.cpp b/media/libaaudio/src/client/AudioStreamInternal.cpp
index d8b27c3..a747e89 100644
--- a/media/libaaudio/src/client/AudioStreamInternal.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternal.cpp
@@ -49,8 +49,6 @@
// This is needed to make sense of the logs more easily.
#define LOG_TAG (mInService ? "AudioStreamInternal_Service" : "AudioStreamInternal_Client")
-using android::Mutex;
-using android::WrappingBuffer;
using android::media::permission::Identity;
using namespace aaudio;
@@ -328,10 +326,10 @@
{
AudioStreamInternal *stream = (AudioStreamInternal *)context;
//LOGD("oboe_callback_thread, stream = %p", stream);
- if (stream != NULL) {
+ if (stream != nullptr) {
return stream->callbackLoop();
} else {
- return NULL;
+ return nullptr;
}
}
@@ -420,7 +418,7 @@
if (isDataCallbackSet()
&& (isActive() || getState() == AAUDIO_STREAM_STATE_DISCONNECTED)) {
mCallbackEnabled.store(false);
- aaudio_result_t result = joinThread_l(NULL); // may temporarily unlock mStreamLock
+ aaudio_result_t result = joinThread_l(nullptr); // may temporarily unlock mStreamLock
if (result == AAUDIO_ERROR_INVALID_HANDLE) {
ALOGD("%s() INVALID_HANDLE, stream was probably stolen", __func__);
result = AAUDIO_OK;
@@ -507,7 +505,7 @@
return result;
}
-aaudio_result_t AudioStreamInternal::getTimestamp(clockid_t clockId,
+aaudio_result_t AudioStreamInternal::getTimestamp(clockid_t /*clockId*/,
int64_t *framePosition,
int64_t *timeNanoseconds) {
// Generated in server and passed to client. Return latest.
diff --git a/media/libaaudio/src/client/AudioStreamInternal.h b/media/libaaudio/src/client/AudioStreamInternal.h
index fbe4c13..eab1382 100644
--- a/media/libaaudio/src/client/AudioStreamInternal.h
+++ b/media/libaaudio/src/client/AudioStreamInternal.h
@@ -116,7 +116,7 @@
virtual void prepareBuffersForStart() {}
- virtual void advanceClientToMatchServerPosition(int32_t serverMargin = 0) = 0;
+ virtual void advanceClientToMatchServerPosition(int32_t serverMargin) = 0;
virtual void onFlushFromServer() {}
diff --git a/media/libaaudio/src/client/AudioStreamInternalCapture.cpp b/media/libaaudio/src/client/AudioStreamInternalCapture.cpp
index 2da5406..1efccb1 100644
--- a/media/libaaudio/src/client/AudioStreamInternalCapture.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternalCapture.cpp
@@ -46,8 +46,6 @@
}
-AudioStreamInternalCapture::~AudioStreamInternalCapture() {}
-
void AudioStreamInternalCapture::advanceClientToMatchServerPosition(int32_t serverMargin) {
int64_t readCounter = mAudioEndpoint->getDataReadCounter();
int64_t writeCounter = mAudioEndpoint->getDataWriteCounter() + serverMargin;
@@ -109,7 +107,7 @@
if (mNeedCatchUp.isRequested()) {
// Catch an MMAP pointer that is already advancing.
// This will avoid initial underruns caused by a slow cold start.
- advanceClientToMatchServerPosition();
+ advanceClientToMatchServerPosition(0 /*serverMargin*/);
mNeedCatchUp.acknowledge();
}
@@ -228,7 +226,7 @@
void *AudioStreamInternalCapture::callbackLoop() {
aaudio_result_t result = AAUDIO_OK;
aaudio_data_callback_result_t callbackResult = AAUDIO_CALLBACK_RESULT_CONTINUE;
- if (!isDataCallbackSet()) return NULL;
+ if (!isDataCallbackSet()) return nullptr;
// result might be a frame count
while (mCallbackEnabled.load() && isActive() && (result >= 0)) {
@@ -260,5 +258,5 @@
ALOGD("callbackLoop() exiting, result = %d, isActive() = %d",
result, (int) isActive());
- return NULL;
+ return nullptr;
}
diff --git a/media/libaaudio/src/client/AudioStreamInternalCapture.h b/media/libaaudio/src/client/AudioStreamInternalCapture.h
index 251a7f2..87017de 100644
--- a/media/libaaudio/src/client/AudioStreamInternalCapture.h
+++ b/media/libaaudio/src/client/AudioStreamInternalCapture.h
@@ -28,8 +28,9 @@
class AudioStreamInternalCapture : public AudioStreamInternal {
public:
- AudioStreamInternalCapture(AAudioServiceInterface &serviceInterface, bool inService = false);
- virtual ~AudioStreamInternalCapture();
+ explicit AudioStreamInternalCapture(AAudioServiceInterface &serviceInterface,
+ bool inService = false);
+ virtual ~AudioStreamInternalCapture() = default;
aaudio_result_t read(void *buffer,
int32_t numFrames,
@@ -45,7 +46,7 @@
}
protected:
- void advanceClientToMatchServerPosition(int32_t serverOffset = 0) override;
+ void advanceClientToMatchServerPosition(int32_t serverOffset) override;
/**
* Low level data processing that will not block. It will just read or write as much as it can.
diff --git a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
index 71bde90..5921799 100644
--- a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
@@ -44,8 +44,6 @@
}
-AudioStreamInternalPlay::~AudioStreamInternalPlay() {}
-
constexpr int kRampMSec = 10; // time to apply a change in volume
aaudio_result_t AudioStreamInternalPlay::open(const AudioStreamBuilder &builder) {
@@ -115,7 +113,7 @@
}
void AudioStreamInternalPlay::onFlushFromServer() {
- advanceClientToMatchServerPosition();
+ advanceClientToMatchServerPosition(0 /*serverMargin*/);
}
// Write the data, block if needed and timeoutMillis > 0
@@ -281,7 +279,7 @@
ALOGD("%s() entering >>>>>>>>>>>>>>>", __func__);
aaudio_result_t result = AAUDIO_OK;
aaudio_data_callback_result_t callbackResult = AAUDIO_CALLBACK_RESULT_CONTINUE;
- if (!isDataCallbackSet()) return NULL;
+ if (!isDataCallbackSet()) return nullptr;
int64_t timeoutNanos = calculateReasonableTimeout(mCallbackFrames);
// result might be a frame count
@@ -309,7 +307,7 @@
ALOGD("%s() exiting, result = %d, isActive() = %d <<<<<<<<<<<<<<",
__func__, result, (int) isActive());
- return NULL;
+ return nullptr;
}
//------------------------------------------------------------------------------
diff --git a/media/libaaudio/src/client/AudioStreamInternalPlay.h b/media/libaaudio/src/client/AudioStreamInternalPlay.h
index 03c957d..e761807 100644
--- a/media/libaaudio/src/client/AudioStreamInternalPlay.h
+++ b/media/libaaudio/src/client/AudioStreamInternalPlay.h
@@ -30,8 +30,9 @@
class AudioStreamInternalPlay : public AudioStreamInternal {
public:
- AudioStreamInternalPlay(AAudioServiceInterface &serviceInterface, bool inService = false);
- virtual ~AudioStreamInternalPlay();
+ explicit AudioStreamInternalPlay(AAudioServiceInterface &serviceInterface,
+ bool inService = false);
+ virtual ~AudioStreamInternalPlay() = default;
aaudio_result_t open(const AudioStreamBuilder &builder) override;
@@ -66,7 +67,7 @@
void prepareBuffersForStart() override;
- void advanceClientToMatchServerPosition(int32_t serverMargin = 0) override;
+ void advanceClientToMatchServerPosition(int32_t serverMargin) override;
void onFlushFromServer() override;
diff --git a/media/libaaudio/src/client/IsochronousClockModel.cpp b/media/libaaudio/src/client/IsochronousClockModel.cpp
index f0dcd44..6921271 100644
--- a/media/libaaudio/src/client/IsochronousClockModel.cpp
+++ b/media/libaaudio/src/client/IsochronousClockModel.cpp
@@ -43,14 +43,7 @@
// and dumped to the log when the stream is stopped.
IsochronousClockModel::IsochronousClockModel()
- : mMarkerFramePosition(0)
- , mMarkerNanoTime(0)
- , mSampleRate(48000)
- , mFramesPerBurst(48)
- , mBurstPeriodNanos(0) // this will be updated before use
- , mMaxMeasuredLatenessNanos(0)
- , mLatenessForDriftNanos(kInitialLatenessForDriftNanos)
- , mState(STATE_STOPPED)
+ : mLatenessForDriftNanos(kInitialLatenessForDriftNanos)
{
if ((AAudioProperty_getLogMask() & AAUDIO_LOG_CLOCK_MODEL_HISTOGRAM) != 0) {
mHistogramMicros = std::make_unique<Histogram>(kHistogramBinCount,
diff --git a/media/libaaudio/src/client/IsochronousClockModel.h b/media/libaaudio/src/client/IsochronousClockModel.h
index 6280013..3007237 100644
--- a/media/libaaudio/src/client/IsochronousClockModel.h
+++ b/media/libaaudio/src/client/IsochronousClockModel.h
@@ -149,16 +149,16 @@
static constexpr int32_t kHistogramBinWidthMicros = 50;
static constexpr int32_t kHistogramBinCount = 128;
- int64_t mMarkerFramePosition; // Estimated HW position.
- int64_t mMarkerNanoTime; // Estimated HW time.
- int32_t mSampleRate;
- int32_t mFramesPerBurst; // number of frames transferred at one time.
- int32_t mBurstPeriodNanos; // Time between HW bursts.
+ int64_t mMarkerFramePosition{0}; // Estimated HW position.
+ int64_t mMarkerNanoTime{0}; // Estimated HW time.
+ int32_t mSampleRate{48000};
+ int32_t mFramesPerBurst{48}; // number of frames transferred at one time.
+ int32_t mBurstPeriodNanos{0}; // Time between HW bursts.
// Includes mBurstPeriodNanos because we sample randomly over time.
- int32_t mMaxMeasuredLatenessNanos;
+ int32_t mMaxMeasuredLatenessNanos{0};
// Threshold for lateness that triggers a drift later in time.
int32_t mLatenessForDriftNanos;
- clock_model_state_t mState; // State machine handles startup sequence.
+ clock_model_state_t mState{STATE_STOPPED}; // State machine handles startup sequence.
int32_t mTimestampCount = 0; // For logging.
diff --git a/media/libaaudio/src/core/AAudioStreamParameters.cpp b/media/libaaudio/src/core/AAudioStreamParameters.cpp
index 0d60120..2694f41 100644
--- a/media/libaaudio/src/core/AAudioStreamParameters.cpp
+++ b/media/libaaudio/src/core/AAudioStreamParameters.cpp
@@ -31,9 +31,6 @@
// HDMI supports up to 32 channels at 1536000 Hz.
#define SAMPLE_RATE_HZ_MAX 1600000
-AAudioStreamParameters::AAudioStreamParameters() {}
-AAudioStreamParameters::~AAudioStreamParameters() {}
-
void AAudioStreamParameters::copyFrom(const AAudioStreamParameters &other) {
mSamplesPerFrame = other.mSamplesPerFrame;
mSampleRate = other.mSampleRate;
diff --git a/media/libaaudio/src/core/AAudioStreamParameters.h b/media/libaaudio/src/core/AAudioStreamParameters.h
index 5737052..0349ffc 100644
--- a/media/libaaudio/src/core/AAudioStreamParameters.h
+++ b/media/libaaudio/src/core/AAudioStreamParameters.h
@@ -26,8 +26,8 @@
class AAudioStreamParameters {
public:
- AAudioStreamParameters();
- virtual ~AAudioStreamParameters();
+ AAudioStreamParameters() = default;
+ virtual ~AAudioStreamParameters() = default;
int32_t getDeviceId() const {
return mDeviceId;
@@ -141,7 +141,7 @@
}
// TODO b/182392769: reexamine if Identity can be used
- void setOpPackageName(const std::optional<std::string> opPackageName) {
+ void setOpPackageName(const std::optional<std::string>& opPackageName) {
mOpPackageName = opPackageName;
}
@@ -149,7 +149,7 @@
return mAttributionTag;
}
- void setAttributionTag(const std::optional<std::string> attributionTag) {
+ void setAttributionTag(const std::optional<std::string>& attributionTag) {
mAttributionTag = attributionTag;
}
diff --git a/media/libaaudio/src/core/AudioGlobal.h b/media/libaaudio/src/core/AudioGlobal.h
index 1e88d15..6c22744 100644
--- a/media/libaaudio/src/core/AudioGlobal.h
+++ b/media/libaaudio/src/core/AudioGlobal.h
@@ -31,7 +31,8 @@
const char* AudioGlobal_convertResultToText(aaudio_result_t returnCode);
const char* AudioGlobal_convertSharingModeToText(aaudio_sharing_mode_t mode);
const char* AudioGlobal_convertStreamStateToText(aaudio_stream_state_t state);
-}
+
+} // namespace aaudio
#endif // AAUDIO_AUDIOGLOBAL_H
diff --git a/media/libaaudio/src/core/AudioStream.h b/media/libaaudio/src/core/AudioStream.h
index 2b45ed3..0068508 100644
--- a/media/libaaudio/src/core/AudioStream.h
+++ b/media/libaaudio/src/core/AudioStream.h
@@ -425,7 +425,7 @@
// PlayerBase allows the system to control the stream volume.
class MyPlayerBase : public android::PlayerBase {
public:
- MyPlayerBase() {};
+ MyPlayerBase() = default;
virtual ~MyPlayerBase() = default;
@@ -554,7 +554,7 @@
* @param numFrames
* @return original pointer or the conversion buffer
*/
- virtual const void * maybeConvertDeviceData(const void *audioData, int32_t numFrames) {
+ virtual const void * maybeConvertDeviceData(const void *audioData, int32_t /*numFrames*/) {
return audioData;
}
diff --git a/media/libaaudio/src/core/AudioStreamBuilder.cpp b/media/libaaudio/src/core/AudioStreamBuilder.cpp
index 2135c54..275fca1 100644
--- a/media/libaaudio/src/core/AudioStreamBuilder.cpp
+++ b/media/libaaudio/src/core/AudioStreamBuilder.cpp
@@ -54,16 +54,10 @@
/*
* AudioStreamBuilder
*/
-AudioStreamBuilder::AudioStreamBuilder() {
-}
-
-AudioStreamBuilder::~AudioStreamBuilder() {
-}
-
static aaudio_result_t builder_createStream(aaudio_direction_t direction,
- aaudio_sharing_mode_t sharingMode,
- bool tryMMap,
- android::sp<AudioStream> &stream) {
+ aaudio_sharing_mode_t /*sharingMode*/,
+ bool tryMMap,
+ android::sp<AudioStream> &stream) {
aaudio_result_t result = AAUDIO_OK;
switch (direction) {
diff --git a/media/libaaudio/src/core/AudioStreamBuilder.h b/media/libaaudio/src/core/AudioStreamBuilder.h
index 9f93341..f91c25a 100644
--- a/media/libaaudio/src/core/AudioStreamBuilder.h
+++ b/media/libaaudio/src/core/AudioStreamBuilder.h
@@ -31,9 +31,9 @@
*/
class AudioStreamBuilder : public AAudioStreamParameters {
public:
- AudioStreamBuilder();
+ AudioStreamBuilder() = default;
- ~AudioStreamBuilder();
+ ~AudioStreamBuilder() = default;
bool isSharingModeMatchRequired() const {
return mSharingModeMatchRequired;
diff --git a/media/libaaudio/src/fifo/FifoBuffer.h b/media/libaaudio/src/fifo/FifoBuffer.h
index 37548f0..7b0aca1 100644
--- a/media/libaaudio/src/fifo/FifoBuffer.h
+++ b/media/libaaudio/src/fifo/FifoBuffer.h
@@ -38,7 +38,7 @@
class FifoBuffer {
public:
- FifoBuffer(int32_t bytesPerFrame);
+ explicit FifoBuffer(int32_t bytesPerFrame);
virtual ~FifoBuffer() = default;
@@ -162,6 +162,6 @@
uint8_t *mExternalStorage = nullptr;
};
-} // android
+} // namespace android
#endif //FIFO_FIFO_BUFFER_H
diff --git a/media/libaaudio/src/fifo/FifoController.h b/media/libaaudio/src/fifo/FifoController.h
index 057a94e..e15d444 100644
--- a/media/libaaudio/src/fifo/FifoController.h
+++ b/media/libaaudio/src/fifo/FifoController.h
@@ -36,7 +36,7 @@
, mWriteCounter(0)
{}
- virtual ~FifoController() {}
+ virtual ~FifoController() = default;
// TODO review use of memory barriers, probably incorrect
virtual fifo_counter_t getReadCounter() override {
@@ -57,6 +57,6 @@
std::atomic<fifo_counter_t> mWriteCounter;
};
-} // android
+} // namespace android
#endif //FIFO_FIFO_CONTROLLER_H
diff --git a/media/libaaudio/src/fifo/FifoControllerBase.cpp b/media/libaaudio/src/fifo/FifoControllerBase.cpp
index 1dece0e..ad6d041 100644
--- a/media/libaaudio/src/fifo/FifoControllerBase.cpp
+++ b/media/libaaudio/src/fifo/FifoControllerBase.cpp
@@ -29,9 +29,6 @@
{
}
-FifoControllerBase::~FifoControllerBase() {
-}
-
fifo_frames_t FifoControllerBase::getFullFramesAvailable() {
fifo_frames_t temp = 0;
__builtin_sub_overflow(getWriteCounter(), getReadCounter(), &temp);
diff --git a/media/libaaudio/src/fifo/FifoControllerBase.h b/media/libaaudio/src/fifo/FifoControllerBase.h
index 1edb8a3..2a6173b 100644
--- a/media/libaaudio/src/fifo/FifoControllerBase.h
+++ b/media/libaaudio/src/fifo/FifoControllerBase.h
@@ -43,7 +43,7 @@
*/
FifoControllerBase(fifo_frames_t capacity, fifo_frames_t threshold);
- virtual ~FifoControllerBase();
+ virtual ~FifoControllerBase() = default;
// Abstract methods to be implemented in subclasses.
/**
@@ -123,6 +123,6 @@
fifo_frames_t mThreshold;
};
-} // android
+} // namespace android
#endif // FIFO_FIFO_CONTROLLER_BASE_H
diff --git a/media/libaaudio/src/fifo/FifoControllerIndirect.h b/media/libaaudio/src/fifo/FifoControllerIndirect.h
index ec48e57..a59225a 100644
--- a/media/libaaudio/src/fifo/FifoControllerIndirect.h
+++ b/media/libaaudio/src/fifo/FifoControllerIndirect.h
@@ -44,7 +44,7 @@
setReadCounter(0);
setWriteCounter(0);
}
- virtual ~FifoControllerIndirect() {};
+ virtual ~FifoControllerIndirect() = default;
// TODO review use of memory barriers, probably incorrect
virtual fifo_counter_t getReadCounter() override {
@@ -68,6 +68,6 @@
std::atomic<fifo_counter_t> * mWriteCounterAddress;
};
-} // android
+} // namespace android
#endif //FIFO_FIFO_CONTROLLER_INDIRECT_H
diff --git a/media/libaaudio/src/flowgraph/AudioProcessorBase.cpp b/media/libaaudio/src/flowgraph/AudioProcessorBase.cpp
index 5667fdb..d8ffd00 100644
--- a/media/libaaudio/src/flowgraph/AudioProcessorBase.cpp
+++ b/media/libaaudio/src/flowgraph/AudioProcessorBase.cpp
@@ -34,8 +34,7 @@
int32_t samplesPerFrame,
int32_t framesPerBlock)
: AudioPort(parent, samplesPerFrame)
- , mFramesPerBlock(framesPerBlock)
- , mSampleBlock(NULL) {
+ , mFramesPerBlock(framesPerBlock) {
int32_t numFloats = framesPerBlock * getSamplesPerFrame();
mSampleBlock = new float[numFloats]{0.0f};
}
@@ -61,13 +60,13 @@
/***************************************************************************/
int32_t AudioFloatInputPort::pullData(int64_t framePosition, int32_t numFrames) {
- return (mConnected == NULL)
+ return (mConnected == nullptr)
? std::min(getFramesPerBlock(), numFrames)
: mConnected->pullData(framePosition, numFrames);
}
float *AudioFloatInputPort::getBlock() {
- if (mConnected == NULL) {
+ if (mConnected == nullptr) {
return AudioFloatBlockPort::getBlock(); // loaded using setValue()
} else {
return mConnected->getBlock();
diff --git a/media/libaaudio/src/flowgraph/MonoToMultiConverter.cpp b/media/libaaudio/src/flowgraph/MonoToMultiConverter.cpp
index 78aad52..c6fcac6 100644
--- a/media/libaaudio/src/flowgraph/MonoToMultiConverter.cpp
+++ b/media/libaaudio/src/flowgraph/MonoToMultiConverter.cpp
@@ -26,8 +26,6 @@
, output(*this, channelCount) {
}
-MonoToMultiConverter::~MonoToMultiConverter() { }
-
int32_t MonoToMultiConverter::onProcess(int64_t framePosition, int32_t numFrames) {
int32_t framesToProcess = input.pullData(framePosition, numFrames);
diff --git a/media/libaaudio/src/flowgraph/MonoToMultiConverter.h b/media/libaaudio/src/flowgraph/MonoToMultiConverter.h
index 34d53c7..5058ae0 100644
--- a/media/libaaudio/src/flowgraph/MonoToMultiConverter.h
+++ b/media/libaaudio/src/flowgraph/MonoToMultiConverter.h
@@ -29,7 +29,7 @@
public:
explicit MonoToMultiConverter(int32_t channelCount);
- virtual ~MonoToMultiConverter();
+ virtual ~MonoToMultiConverter() = default;
int32_t onProcess(int64_t framePosition, int32_t numFrames) override;
diff --git a/media/libaaudio/src/flowgraph/SourceFloat.cpp b/media/libaaudio/src/flowgraph/SourceFloat.cpp
index 4bb674f..5b3a51e 100644
--- a/media/libaaudio/src/flowgraph/SourceFloat.cpp
+++ b/media/libaaudio/src/flowgraph/SourceFloat.cpp
@@ -25,7 +25,7 @@
: AudioSource(channelCount) {
}
-int32_t SourceFloat::onProcess(int64_t framePosition, int32_t numFrames) {
+int32_t SourceFloat::onProcess(int64_t /*framePosition*/, int32_t numFrames) {
float *outputBuffer = output.getBlock();
int32_t channelCount = output.getSamplesPerFrame();
diff --git a/media/libaaudio/src/flowgraph/SourceI16.cpp b/media/libaaudio/src/flowgraph/SourceI16.cpp
index c3fcec2..a645cc2 100644
--- a/media/libaaudio/src/flowgraph/SourceI16.cpp
+++ b/media/libaaudio/src/flowgraph/SourceI16.cpp
@@ -30,7 +30,7 @@
: AudioSource(channelCount) {
}
-int32_t SourceI16::onProcess(int64_t framePosition, int32_t numFrames) {
+int32_t SourceI16::onProcess(int64_t /*framePosition*/, int32_t numFrames) {
float *floatData = output.getBlock();
int32_t channelCount = output.getSamplesPerFrame();
diff --git a/media/libaaudio/src/flowgraph/SourceI24.cpp b/media/libaaudio/src/flowgraph/SourceI24.cpp
index 097954e..50fb98e 100644
--- a/media/libaaudio/src/flowgraph/SourceI24.cpp
+++ b/media/libaaudio/src/flowgraph/SourceI24.cpp
@@ -32,7 +32,7 @@
: AudioSource(channelCount) {
}
-int32_t SourceI24::onProcess(int64_t framePosition, int32_t numFrames) {
+int32_t SourceI24::onProcess(int64_t /*framePosition*/, int32_t numFrames) {
float *floatData = output.getBlock();
int32_t channelCount = output.getSamplesPerFrame();
diff --git a/media/libaaudio/src/flowgraph/SourceI32.cpp b/media/libaaudio/src/flowgraph/SourceI32.cpp
index e8177ad..95bfd8f 100644
--- a/media/libaaudio/src/flowgraph/SourceI32.cpp
+++ b/media/libaaudio/src/flowgraph/SourceI32.cpp
@@ -30,7 +30,7 @@
: AudioSource(channelCount) {
}
-int32_t SourceI32::onProcess(int64_t framePosition, int32_t numFrames) {
+int32_t SourceI32::onProcess(int64_t /*framePosition*/, int32_t numFrames) {
float *floatData = output.getBlock();
int32_t channelCount = output.getSamplesPerFrame();
diff --git a/media/libaaudio/src/legacy/AudioStreamLegacy.cpp b/media/libaaudio/src/legacy/AudioStreamLegacy.cpp
index 60eb73a..b6bd0e1 100644
--- a/media/libaaudio/src/legacy/AudioStreamLegacy.cpp
+++ b/media/libaaudio/src/legacy/AudioStreamLegacy.cpp
@@ -37,9 +37,6 @@
: AudioStream() {
}
-AudioStreamLegacy::~AudioStreamLegacy() {
-}
-
// Called from AudioTrack.cpp or AudioRecord.cpp
static void AudioStreamLegacy_callback(int event, void* userData, void *info) {
AudioStreamLegacy *streamLegacy = (AudioStreamLegacy *) userData;
diff --git a/media/libaaudio/src/legacy/AudioStreamLegacy.h b/media/libaaudio/src/legacy/AudioStreamLegacy.h
index 88ef270..d9ba990 100644
--- a/media/libaaudio/src/legacy/AudioStreamLegacy.h
+++ b/media/libaaudio/src/legacy/AudioStreamLegacy.h
@@ -60,7 +60,7 @@
public:
AudioStreamLegacy();
- virtual ~AudioStreamLegacy();
+ virtual ~AudioStreamLegacy() = default;
aaudio_legacy_callback_t getLegacyCallback();
diff --git a/media/libaaudio/src/legacy/AudioStreamRecord.cpp b/media/libaaudio/src/legacy/AudioStreamRecord.cpp
index eca5392..9ca4e60 100644
--- a/media/libaaudio/src/legacy/AudioStreamRecord.cpp
+++ b/media/libaaudio/src/legacy/AudioStreamRecord.cpp
@@ -504,7 +504,7 @@
return (aaudio_result_t) framesRead;
}
-aaudio_result_t AudioStreamRecord::setBufferSize(int32_t requestedFrames)
+aaudio_result_t AudioStreamRecord::setBufferSize(int32_t /*requestedFrames*/)
{
return getBufferSize();
}
diff --git a/media/libaaudio/src/legacy/AudioStreamTrack.cpp b/media/libaaudio/src/legacy/AudioStreamTrack.cpp
index 04a9dec..3078d96 100644
--- a/media/libaaudio/src/legacy/AudioStreamTrack.cpp
+++ b/media/libaaudio/src/legacy/AudioStreamTrack.cpp
@@ -162,11 +162,11 @@
callback,
callbackData,
notificationFrames,
- 0, // DEFAULT sharedBuffer*/,
+ nullptr, // DEFAULT sharedBuffer*/,
false, // DEFAULT threadCanCallJava
sessionId,
streamTransferType,
- NULL, // DEFAULT audio_offload_info_t
+ nullptr, // DEFAULT audio_offload_info_t
Identity(), // DEFAULT uid and pid
&attributes,
// WARNING - If doNotReconnect set true then audio stops after plugging and unplugging
diff --git a/media/libaaudio/src/utility/AAudioUtilities.h b/media/libaaudio/src/utility/AAudioUtilities.h
index 82eb77d..ee8cfd2 100644
--- a/media/libaaudio/src/utility/AAudioUtilities.h
+++ b/media/libaaudio/src/utility/AAudioUtilities.h
@@ -198,7 +198,7 @@
* @return true if f() eventually returns true.
*/
static inline bool AAudio_tryUntilTrue(
- std::function<bool()> f, int times, int sleepMs) {
+ const std::function<bool()>& f, int times, int sleepMs) {
static const useconds_t US_PER_MS = 1000;
sleepMs = std::max(sleepMs, 0);
@@ -270,9 +270,7 @@
class Timestamp {
public:
- Timestamp()
- : mPosition(0)
- , mNanoseconds(0) {}
+ Timestamp() = default;
Timestamp(int64_t position, int64_t nanoseconds)
: mPosition(position)
, mNanoseconds(nanoseconds) {}
@@ -283,8 +281,8 @@
private:
// These cannot be const because we need to implement the copy assignment operator.
- int64_t mPosition;
- int64_t mNanoseconds;
+ int64_t mPosition{0};
+ int64_t mNanoseconds{0};
};
diff --git a/media/libaaudio/src/utility/FixedBlockAdapter.h b/media/libaaudio/src/utility/FixedBlockAdapter.h
index 4dc7e68..290e473 100644
--- a/media/libaaudio/src/utility/FixedBlockAdapter.h
+++ b/media/libaaudio/src/utility/FixedBlockAdapter.h
@@ -35,7 +35,7 @@
class FixedBlockAdapter
{
public:
- FixedBlockAdapter(FixedBlockProcessor &fixedBlockProcessor)
+ explicit FixedBlockAdapter(FixedBlockProcessor &fixedBlockProcessor)
: mFixedBlockProcessor(fixedBlockProcessor) {}
virtual ~FixedBlockAdapter() = default;
diff --git a/media/libaaudio/src/utility/FixedBlockReader.h b/media/libaaudio/src/utility/FixedBlockReader.h
index 128dd52..dc82416 100644
--- a/media/libaaudio/src/utility/FixedBlockReader.h
+++ b/media/libaaudio/src/utility/FixedBlockReader.h
@@ -30,7 +30,7 @@
class FixedBlockReader : public FixedBlockAdapter
{
public:
- FixedBlockReader(FixedBlockProcessor &fixedBlockProcessor);
+ explicit FixedBlockReader(FixedBlockProcessor &fixedBlockProcessor);
virtual ~FixedBlockReader() = default;
diff --git a/media/libaaudio/src/utility/FixedBlockWriter.h b/media/libaaudio/src/utility/FixedBlockWriter.h
index f1d917c..3e89b5d 100644
--- a/media/libaaudio/src/utility/FixedBlockWriter.h
+++ b/media/libaaudio/src/utility/FixedBlockWriter.h
@@ -28,7 +28,7 @@
class FixedBlockWriter : public FixedBlockAdapter
{
public:
- FixedBlockWriter(FixedBlockProcessor &fixedBlockProcessor);
+ explicit FixedBlockWriter(FixedBlockProcessor &fixedBlockProcessor);
virtual ~FixedBlockWriter() = default;
diff --git a/media/libaaudio/src/utility/MonotonicCounter.h b/media/libaaudio/src/utility/MonotonicCounter.h
index 63add4e..313ccbd 100644
--- a/media/libaaudio/src/utility/MonotonicCounter.h
+++ b/media/libaaudio/src/utility/MonotonicCounter.h
@@ -30,8 +30,8 @@
class MonotonicCounter {
public:
- MonotonicCounter() {};
- virtual ~MonotonicCounter() {};
+ MonotonicCounter() = default;
+ virtual ~MonotonicCounter() = default;
/**
* @return current value of the counter
diff --git a/media/libaudioclient/AidlConversion.cpp b/media/libaudioclient/AidlConversion.cpp
index c77aeeb..946ec17 100644
--- a/media/libaudioclient/AidlConversion.cpp
+++ b/media/libaudioclient/AidlConversion.cpp
@@ -2323,4 +2323,28 @@
return unexpected(BAD_VALUE);
}
+ConversionResult<TrackSecondaryOutputInfoPair>
+aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair(
+ const media::TrackSecondaryOutputInfo& aidl) {
+ TrackSecondaryOutputInfoPair trackSecondaryOutputInfoPair;
+ trackSecondaryOutputInfoPair.first =
+ VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
+ trackSecondaryOutputInfoPair.second =
+ VALUE_OR_RETURN(convertContainer<std::vector<audio_port_handle_t>>(
+ aidl.secondaryOutputIds, aidl2legacy_int32_t_audio_io_handle_t));
+ return trackSecondaryOutputInfoPair;
+}
+
+ConversionResult<media::TrackSecondaryOutputInfo>
+legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo(
+ const TrackSecondaryOutputInfoPair& legacy) {
+ media::TrackSecondaryOutputInfo trackSecondaryOutputInfo;
+ trackSecondaryOutputInfo.portId =
+ VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.first));
+ trackSecondaryOutputInfo.secondaryOutputIds =
+ VALUE_OR_RETURN(convertContainer<std::vector<int32_t>>(
+ legacy.second, legacy2aidl_audio_io_handle_t_int32_t));
+ return trackSecondaryOutputInfo;
+}
+
} // namespace android
diff --git a/media/libaudioclient/Android.bp b/media/libaudioclient/Android.bp
index 19d68a0..c7f23e3 100644
--- a/media/libaudioclient/Android.bp
+++ b/media/libaudioclient/Android.bp
@@ -351,9 +351,10 @@
"aidl/android/media/AudioVibratorInfo.aidl",
"aidl/android/media/EffectDescriptor.aidl",
"aidl/android/media/ExtraAudioDescriptor.aidl",
+ "aidl/android/media/TrackSecondaryOutputInfo.aidl",
],
imports: [
- "audio_common-aidl",
+ "android.media.audio.common.types",
"media_permission-aidl",
],
backend: {
@@ -364,6 +365,9 @@
"com.android.media",
],
},
+ java: {
+ sdk_version: "module_current",
+ },
},
}
aidl_interface {
@@ -391,7 +395,7 @@
"aidl/android/media/SoundTriggerSession.aidl",
],
imports: [
- "audio_common-aidl",
+ "android.media.audio.common.types",
"audioclient-types-aidl",
],
backend: {
@@ -402,6 +406,9 @@
"com.android.media",
],
},
+ java: {
+ sdk_version: "module_current",
+ },
},
}
@@ -431,7 +438,7 @@
"aidl/android/media/IAudioTrackCallback.aidl",
],
imports: [
- "audio_common-aidl",
+ "android.media.audio.common.types",
"audioclient-types-aidl",
"av-types-aidl",
"effect-aidl",
@@ -447,6 +454,9 @@
"com.android.media",
],
},
+ java: {
+ sdk_version: "module_current",
+ },
},
}
@@ -466,7 +476,7 @@
"aidl/android/media/IAudioPolicyServiceClient.aidl",
],
imports: [
- "audio_common-aidl",
+ "android.media.audio.common.types",
"audioclient-types-aidl",
"audiopolicy-types-aidl",
"capture_state_listener-aidl",
@@ -481,5 +491,8 @@
"com.android.media",
],
},
+ java: {
+ sdk_version: "module_current",
+ },
},
}
diff --git a/media/libaudioclient/IAudioFlinger.cpp b/media/libaudioclient/IAudioFlinger.cpp
index 389b73f..0564cdf 100644
--- a/media/libaudioclient/IAudioFlinger.cpp
+++ b/media/libaudioclient/IAudioFlinger.cpp
@@ -743,6 +743,16 @@
return statusTFromBinderStatus(mDelegate->setVibratorInfos(vibratorInfos));
}
+status_t AudioFlingerClientAdapter::updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs) {
+ std::vector<media::TrackSecondaryOutputInfo> trackSecondaryOutputInfos =
+ VALUE_OR_RETURN_STATUS(
+ convertContainer<std::vector<media::TrackSecondaryOutputInfo>>(
+ trackSecondaryOutputs,
+ legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo));
+ return statusTFromBinderStatus(mDelegate->updateSecondaryOutputs(trackSecondaryOutputInfos));
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
// AudioFlingerServerAdapter
@@ -1199,4 +1209,13 @@
return Status::fromStatusT(mDelegate->setVibratorInfos(vibratorInfos));
}
+Status AudioFlingerServerAdapter::updateSecondaryOutputs(
+ const std::vector<media::TrackSecondaryOutputInfo>& trackSecondaryOutputInfos) {
+ TrackSecondaryOutputsMap trackSecondaryOutputs =
+ VALUE_OR_RETURN_BINDER(convertContainer<TrackSecondaryOutputsMap>(
+ trackSecondaryOutputInfos,
+ aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair));
+ return Status::fromStatusT(mDelegate->updateSecondaryOutputs(trackSecondaryOutputs));
+}
+
} // namespace android
diff --git a/media/libaudioclient/aidl/android/media/IAudioFlingerService.aidl b/media/libaudioclient/aidl/android/media/IAudioFlingerService.aidl
index abbced5..d2cae6d 100644
--- a/media/libaudioclient/aidl/android/media/IAudioFlingerService.aidl
+++ b/media/libaudioclient/aidl/android/media/IAudioFlingerService.aidl
@@ -40,6 +40,7 @@
import android.media.IAudioTrack;
import android.media.MicrophoneInfoData;
import android.media.RenderPosition;
+import android.media.TrackSecondaryOutputInfo;
import android.media.audio.common.AudioFormat;
/**
@@ -207,4 +208,9 @@
// Set vibrators' information.
// The value will be used to initialize HapticGenerator.
void setVibratorInfos(in AudioVibratorInfo[] vibratorInfos);
+
+ // Update secondary outputs.
+ // This usually happens when there is a dynamic policy registered.
+ void updateSecondaryOutputs(
+ in TrackSecondaryOutputInfo[] trackSecondaryOutputInfos);
}
diff --git a/media/libaudioclient/aidl/android/media/TrackSecondaryOutputInfo.aidl b/media/libaudioclient/aidl/android/media/TrackSecondaryOutputInfo.aidl
new file mode 100644
index 0000000..113328e
--- /dev/null
+++ b/media/libaudioclient/aidl/android/media/TrackSecondaryOutputInfo.aidl
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+package android.media;
+
+/**
+ * This is a class that contains port handle for a track and handles for all secondary
+ * outputs of the track.
+ * @hide
+ */
+parcelable TrackSecondaryOutputInfo {
+ int portId; // audio_port_handle_t
+ int[] secondaryOutputIds; // audio_io_handle_t[]
+}
\ No newline at end of file
diff --git a/media/libaudioclient/include/media/AidlConversion.h b/media/libaudioclient/include/media/AidlConversion.h
index 1dd9d60..4ec69c7 100644
--- a/media/libaudioclient/include/media/AidlConversion.h
+++ b/media/libaudioclient/include/media/AidlConversion.h
@@ -50,6 +50,7 @@
#include <android/media/AudioUniqueIdUse.h>
#include <android/media/EffectDescriptor.h>
#include <android/media/ExtraAudioDescriptor.h>
+#include <android/media/TrackSecondaryOutputInfo.h>
#include <android/media/SharedFileRegion.h>
#include <binder/IMemory.h>
@@ -407,6 +408,13 @@
legacy2aidl_audio_encapsulation_type_t_AudioEncapsulationType(
const audio_encapsulation_type_t & legacy);
+using TrackSecondaryOutputInfoPair = std::pair<audio_port_handle_t, std::vector<audio_io_handle_t>>;
+ConversionResult<TrackSecondaryOutputInfoPair>
+aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair(
+ const media::TrackSecondaryOutputInfo& aidl);
+ConversionResult<media::TrackSecondaryOutputInfo>
+legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo(
+ const TrackSecondaryOutputInfoPair& legacy);
} // namespace android
diff --git a/media/libaudioclient/include/media/AudioCommonTypes.h b/media/libaudioclient/include/media/AudioCommonTypes.h
index 8e446ea..5dfe5fc 100644
--- a/media/libaudioclient/include/media/AudioCommonTypes.h
+++ b/media/libaudioclient/include/media/AudioCommonTypes.h
@@ -29,6 +29,8 @@
using AttributesVector = std::vector<audio_attributes_t>;
using StreamTypeVector = std::vector<audio_stream_type_t>;
+using TrackSecondaryOutputsMap = std::map<audio_port_handle_t, std::vector<audio_io_handle_t>>;
+
constexpr bool operator==(const audio_attributes_t &lhs, const audio_attributes_t &rhs)
{
return lhs.usage == rhs.usage && lhs.content_type == rhs.content_type &&
diff --git a/media/libaudioclient/include/media/IAudioFlinger.h b/media/libaudioclient/include/media/IAudioFlinger.h
index 3a04569..3a4868e 100644
--- a/media/libaudioclient/include/media/IAudioFlinger.h
+++ b/media/libaudioclient/include/media/IAudioFlinger.h
@@ -26,12 +26,14 @@
#include <binder/IInterface.h>
#include <media/AidlConversion.h>
#include <media/AudioClient.h>
+#include <media/AudioCommonTypes.h>
#include <media/DeviceDescriptorBase.h>
#include <system/audio.h>
#include <system/audio_effect.h>
#include <system/audio_policy.h>
#include <utils/String8.h>
#include <media/MicrophoneInfo.h>
+#include <map>
#include <string>
#include <vector>
@@ -55,6 +57,7 @@
#include "android/media/OpenInputResponse.h"
#include "android/media/OpenOutputRequest.h"
#include "android/media/OpenOutputResponse.h"
+#include "android/media/TrackSecondaryOutputInfo.h"
namespace android {
@@ -338,6 +341,9 @@
// The values will be used to initialize HapticGenerator.
virtual status_t setVibratorInfos(
const std::vector<media::AudioVibratorInfo>& vibratorInfos) = 0;
+
+ virtual status_t updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs) = 0;
};
/**
@@ -430,6 +436,8 @@
status_t getMicrophones(std::vector<media::MicrophoneInfo>* microphones) override;
status_t setAudioHalPids(const std::vector<pid_t>& pids) override;
status_t setVibratorInfos(const std::vector<media::AudioVibratorInfo>& vibratorInfos) override;
+ status_t updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs) override;
private:
const sp<media::IAudioFlingerService> mDelegate;
@@ -513,6 +521,7 @@
SET_EFFECT_SUSPENDED = media::BnAudioFlingerService::TRANSACTION_setEffectSuspended,
SET_AUDIO_HAL_PIDS = media::BnAudioFlingerService::TRANSACTION_setAudioHalPids,
SET_VIBRATOR_INFOS = media::BnAudioFlingerService::TRANSACTION_setVibratorInfos,
+ UPDATE_SECONDARY_OUTPUTS = media::BnAudioFlingerService::TRANSACTION_updateSecondaryOutputs,
};
/**
@@ -619,6 +628,8 @@
Status getMicrophones(std::vector<media::MicrophoneInfoData>* _aidl_return) override;
Status setAudioHalPids(const std::vector<int32_t>& pids) override;
Status setVibratorInfos(const std::vector<media::AudioVibratorInfo>& vibratorInfos) override;
+ Status updateSecondaryOutputs(
+ const std::vector<media::TrackSecondaryOutputInfo>& trackSecondaryOutputInfos) override;
private:
const sp<AudioFlingerServerAdapter::Delegate> mDelegate;
diff --git a/media/libmedia/IMediaPlayer.cpp b/media/libmedia/IMediaPlayer.cpp
index c89c023..c9f361e 100644
--- a/media/libmedia/IMediaPlayer.cpp
+++ b/media/libmedia/IMediaPlayer.cpp
@@ -17,7 +17,6 @@
#include <arpa/inet.h>
#include <stdint.h>
-#include <sys/types.h>
#include <android/IDataSource.h>
#include <binder/IPCThreadState.h>
diff --git a/media/libmedia/tests/codeclist/Android.bp b/media/libmedia/tests/codeclist/Android.bp
index 7dd0caa..57af9a9 100644
--- a/media/libmedia/tests/codeclist/Android.bp
+++ b/media/libmedia/tests/codeclist/Android.bp
@@ -25,7 +25,7 @@
cc_test {
name: "CodecListTest",
- test_suites: ["device-tests"],
+ test_suites: ["device-tests", "mts"],
gtest: true,
srcs: [
@@ -41,7 +41,7 @@
"libstagefright_xmlparser",
"libutils",
],
-
+ compile_multilib: "first",
cflags: [
"-Werror",
"-Wall",
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index 57bdba0..295abb1 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -92,6 +92,7 @@
// NB: these are matched with public Java API constants defined
// in frameworks/base/media/java/android/media/MediaCodec.java
// These must be kept synchronized with the constants there.
+static const char *kCodecLogSessionId = "android.media.mediacodec.log-session-id";
static const char *kCodecCodec = "android.media.mediacodec.codec"; /* e.g. OMX.google.aac.decoder */
static const char *kCodecMime = "android.media.mediacodec.mime"; /* e.g. audio/mime */
static const char *kCodecMode = "android.media.mediacodec.mode"; /* audio, video */
@@ -1460,6 +1461,8 @@
}
if (mIsVideo) {
+ // TODO: validity check log-session-id: it should be a 32-hex-digit.
+ format->findString("log-session-id", &mLogSessionId);
format->findInt32("width", &mVideoWidth);
format->findInt32("height", &mVideoHeight);
if (!format->findInt32("rotation-degrees", &mRotationDegrees)) {
@@ -1467,6 +1470,7 @@
}
if (mMetricsHandle != 0) {
+ mediametrics_setCString(mMetricsHandle, kCodecLogSessionId, mLogSessionId.c_str());
mediametrics_setInt32(mMetricsHandle, kCodecWidth, mVideoWidth);
mediametrics_setInt32(mMetricsHandle, kCodecHeight, mVideoHeight);
mediametrics_setInt32(mMetricsHandle, kCodecRotation, mRotationDegrees);
@@ -4585,8 +4589,8 @@
}
const CryptoPlugin::SubSample *subSamples;
size_t numSubSamples;
- const uint8_t *key;
- const uint8_t *iv;
+ const uint8_t *key = NULL;
+ const uint8_t *iv = NULL;
CryptoPlugin::Mode mode = CryptoPlugin::kMode_Unencrypted;
// We allow the simpler queueInputBuffer API to be used even in
@@ -4601,8 +4605,6 @@
subSamples = &ss;
numSubSamples = 1;
- key = NULL;
- iv = NULL;
pattern.mEncryptBlocks = 0;
pattern.mSkipBlocks = 0;
}
diff --git a/media/libstagefright/include/media/stagefright/MediaCodec.h b/media/libstagefright/include/media/stagefright/MediaCodec.h
index 3517bae..12b38ef 100644
--- a/media/libstagefright/include/media/stagefright/MediaCodec.h
+++ b/media/libstagefright/include/media/stagefright/MediaCodec.h
@@ -429,6 +429,7 @@
sp<ResourceManagerServiceProxy> mResourceManagerProxy;
bool mIsVideo;
+ AString mLogSessionId;
int32_t mVideoWidth;
int32_t mVideoHeight;
int32_t mRotationDegrees;
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 3562b00..00f423c 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -312,6 +312,27 @@
return NO_ERROR;
}
+status_t AudioFlinger::updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs) {
+ Mutex::Autolock _l(mLock);
+ for (const auto& [trackId, secondaryOutputs] : trackSecondaryOutputs) {
+ size_t i = 0;
+ for (; i < mPlaybackThreads.size(); ++i) {
+ PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
+ Mutex::Autolock _tl(thread->mLock);
+ sp<PlaybackThread::Track> track = thread->getTrackById_l(trackId);
+ if (track != nullptr) {
+ ALOGD("%s trackId: %u", __func__, trackId);
+ updateSecondaryOutputsForTrack_l(track.get(), thread, secondaryOutputs);
+ break;
+ }
+ }
+ ALOGW_IF(i >= mPlaybackThreads.size(),
+ "%s cannot find track with id %u", __func__, trackId);
+ }
+ return NO_ERROR;
+}
+
// getDefaultVibratorInfo_l must be called with AudioFlinger lock held.
const media::AudioVibratorInfo* AudioFlinger::getDefaultVibratorInfo_l() {
if (mAudioVibratorInfos.empty()) {
@@ -944,88 +965,7 @@
// Connect secondary outputs. Failure on a secondary output must not imped the primary
// Any secondary output setup failure will lead to a desync between the AP and AF until
// the track is destroyed.
- TeePatches teePatches;
- for (audio_io_handle_t secondaryOutput : secondaryOutputs) {
- PlaybackThread *secondaryThread = checkPlaybackThread_l(secondaryOutput);
- if (secondaryThread == NULL) {
- ALOGE("no playback thread found for secondary output %d", output.outputId);
- continue;
- }
-
- size_t sourceFrameCount = thread->frameCount() * output.sampleRate
- / thread->sampleRate();
- size_t sinkFrameCount = secondaryThread->frameCount() * output.sampleRate
- / secondaryThread->sampleRate();
- // If the secondary output has just been opened, the first secondaryThread write
- // will not block as it will fill the empty startup buffer of the HAL,
- // so a second sink buffer needs to be ready for the immediate next blocking write.
- // Additionally, have a margin of one main thread buffer as the scheduling jitter
- // can reorder the writes (eg if thread A&B have the same write intervale,
- // the scheduler could schedule AB...BA)
- size_t frameCountToBeReady = 2 * sinkFrameCount + sourceFrameCount;
- // Total secondary output buffer must be at least as the read frames plus
- // the margin of a few buffers on both sides in case the
- // threads scheduling has some jitter.
- // That value should not impact latency as the secondary track is started before
- // its buffer is full, see frameCountToBeReady.
- size_t frameCount = frameCountToBeReady + 2 * (sourceFrameCount + sinkFrameCount);
- // The frameCount should also not be smaller than the secondary thread min frame
- // count
- size_t minFrameCount = AudioSystem::calculateMinFrameCount(
- [&] { Mutex::Autolock _l(secondaryThread->mLock);
- return secondaryThread->latency_l(); }(),
- secondaryThread->mNormalFrameCount,
- secondaryThread->mSampleRate,
- output.sampleRate,
- input.speed);
- frameCount = std::max(frameCount, minFrameCount);
-
- using namespace std::chrono_literals;
- auto inChannelMask = audio_channel_mask_out_to_in(input.config.channel_mask);
- sp patchRecord = new RecordThread::PatchRecord(nullptr /* thread */,
- output.sampleRate,
- inChannelMask,
- input.config.format,
- frameCount,
- NULL /* buffer */,
- (size_t)0 /* bufferSize */,
- AUDIO_INPUT_FLAG_DIRECT,
- 0ns /* timeout */);
- status_t status = patchRecord->initCheck();
- if (status != NO_ERROR) {
- ALOGE("Secondary output patchRecord init failed: %d", status);
- continue;
- }
-
- // TODO: We could check compatibility of the secondaryThread with the PatchTrack
- // for fast usage: thread has fast mixer, sample rate matches, etc.;
- // for now, we exclude fast tracks by removing the Fast flag.
- const audio_output_flags_t outputFlags =
- (audio_output_flags_t)(output.flags & ~AUDIO_OUTPUT_FLAG_FAST);
- sp patchTrack = new PlaybackThread::PatchTrack(secondaryThread,
- streamType,
- output.sampleRate,
- input.config.channel_mask,
- input.config.format,
- frameCount,
- patchRecord->buffer(),
- patchRecord->bufferSize(),
- outputFlags,
- 0ns /* timeout */,
- frameCountToBeReady);
- status = patchTrack->initCheck();
- if (status != NO_ERROR) {
- ALOGE("Secondary output patchTrack init failed: %d", status);
- continue;
- }
- teePatches.push_back({patchRecord, patchTrack});
- secondaryThread->addPatchTrack(patchTrack);
- // In case the downstream patchTrack on the secondaryThread temporarily outlives
- // our created track, ensure the corresponding patchRecord is still alive.
- patchTrack->setPeerProxy(patchRecord, true /* holdReference */);
- patchRecord->setPeerProxy(patchTrack, false /* holdReference */);
- }
- track->setTeePatches(std::move(teePatches));
+ updateSecondaryOutputsForTrack_l(track.get(), thread, secondaryOutputs);
}
// move effect chain to this output thread if an effect on same session was waiting
@@ -3441,6 +3381,94 @@
return nullptr;
}
+void AudioFlinger::updateSecondaryOutputsForTrack_l(
+ PlaybackThread::Track* track,
+ PlaybackThread* thread,
+ const std::vector<audio_io_handle_t> &secondaryOutputs) const {
+ TeePatches teePatches;
+ for (audio_io_handle_t secondaryOutput : secondaryOutputs) {
+ PlaybackThread *secondaryThread = checkPlaybackThread_l(secondaryOutput);
+ if (secondaryThread == nullptr) {
+ ALOGE("no playback thread found for secondary output %d", thread->id());
+ continue;
+ }
+
+ size_t sourceFrameCount = thread->frameCount() * track->sampleRate()
+ / thread->sampleRate();
+ size_t sinkFrameCount = secondaryThread->frameCount() * track->sampleRate()
+ / secondaryThread->sampleRate();
+ // If the secondary output has just been opened, the first secondaryThread write
+ // will not block as it will fill the empty startup buffer of the HAL,
+ // so a second sink buffer needs to be ready for the immediate next blocking write.
+ // Additionally, have a margin of one main thread buffer as the scheduling jitter
+ // can reorder the writes (eg if thread A&B have the same write intervale,
+ // the scheduler could schedule AB...BA)
+ size_t frameCountToBeReady = 2 * sinkFrameCount + sourceFrameCount;
+ // Total secondary output buffer must be at least as the read frames plus
+ // the margin of a few buffers on both sides in case the
+ // threads scheduling has some jitter.
+ // That value should not impact latency as the secondary track is started before
+ // its buffer is full, see frameCountToBeReady.
+ size_t frameCount = frameCountToBeReady + 2 * (sourceFrameCount + sinkFrameCount);
+ // The frameCount should also not be smaller than the secondary thread min frame
+ // count
+ size_t minFrameCount = AudioSystem::calculateMinFrameCount(
+ [&] { Mutex::Autolock _l(secondaryThread->mLock);
+ return secondaryThread->latency_l(); }(),
+ secondaryThread->mNormalFrameCount,
+ secondaryThread->mSampleRate,
+ track->sampleRate(),
+ track->getSpeed());
+ frameCount = std::max(frameCount, minFrameCount);
+
+ using namespace std::chrono_literals;
+ auto inChannelMask = audio_channel_mask_out_to_in(track->channelMask());
+ sp patchRecord = new RecordThread::PatchRecord(nullptr /* thread */,
+ track->sampleRate(),
+ inChannelMask,
+ track->format(),
+ frameCount,
+ nullptr /* buffer */,
+ (size_t)0 /* bufferSize */,
+ AUDIO_INPUT_FLAG_DIRECT,
+ 0ns /* timeout */);
+ status_t status = patchRecord->initCheck();
+ if (status != NO_ERROR) {
+ ALOGE("Secondary output patchRecord init failed: %d", status);
+ continue;
+ }
+
+ // TODO: We could check compatibility of the secondaryThread with the PatchTrack
+ // for fast usage: thread has fast mixer, sample rate matches, etc.;
+ // for now, we exclude fast tracks by removing the Fast flag.
+ const audio_output_flags_t outputFlags =
+ (audio_output_flags_t)(track->getOutputFlags() & ~AUDIO_OUTPUT_FLAG_FAST);
+ sp patchTrack = new PlaybackThread::PatchTrack(secondaryThread,
+ track->streamType(),
+ track->sampleRate(),
+ track->channelMask(),
+ track->format(),
+ frameCount,
+ patchRecord->buffer(),
+ patchRecord->bufferSize(),
+ outputFlags,
+ 0ns /* timeout */,
+ frameCountToBeReady);
+ status = patchTrack->initCheck();
+ if (status != NO_ERROR) {
+ ALOGE("Secondary output patchTrack init failed: %d", status);
+ continue;
+ }
+ teePatches.push_back({patchRecord, patchTrack});
+ secondaryThread->addPatchTrack(patchTrack);
+ // In case the downstream patchTrack on the secondaryThread temporarily outlives
+ // our created track, ensure the corresponding patchRecord is still alive.
+ patchTrack->setPeerProxy(patchRecord, true /* holdReference */);
+ patchRecord->setPeerProxy(patchTrack, false /* holdReference */);
+ }
+ track->setTeePatches(std::move(teePatches));
+}
+
sp<AudioFlinger::SyncEvent> AudioFlinger::createSyncEvent(AudioSystem::sync_event_t type,
audio_session_t triggerSession,
audio_session_t listenerSession,
@@ -4170,7 +4198,8 @@
case TransactionCode::SET_LOW_RAM_DEVICE:
case TransactionCode::SYSTEM_READY:
case TransactionCode::SET_AUDIO_HAL_PIDS:
- case TransactionCode::SET_VIBRATOR_INFOS: {
+ case TransactionCode::SET_VIBRATOR_INFOS:
+ case TransactionCode::UPDATE_SECONDARY_OUTPUTS: {
if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
__func__, code, IPCThreadState::self()->getCallingPid(),
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 4b03d10..b12f52e 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -272,6 +272,9 @@
virtual status_t setVibratorInfos(const std::vector<media::AudioVibratorInfo>& vibratorInfos);
+ virtual status_t updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs);
+
status_t onTransactWrapper(TransactionCode code, const Parcel& data, uint32_t flags,
const std::function<status_t()>& delegate) override;
@@ -775,6 +778,11 @@
ThreadBase *hapticPlaybackThread_l() const;
+ void updateSecondaryOutputsForTrack_l(
+ PlaybackThread::Track* track,
+ PlaybackThread* thread,
+ const std::vector<audio_io_handle_t>& secondaryOutputs) const;
+
void removeClient_l(pid_t pid);
void removeNotificationClient(pid_t pid);
diff --git a/services/audioflinger/PlaybackTracks.h b/services/audioflinger/PlaybackTracks.h
index 2436248..30a2432 100644
--- a/services/audioflinger/PlaybackTracks.h
+++ b/services/audioflinger/PlaybackTracks.h
@@ -81,7 +81,8 @@
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE,
/** default behaviour is to start when there are as many frames
* ready as possible (aka. Buffer is full). */
- size_t frameCountToBeReady = SIZE_MAX);
+ size_t frameCountToBeReady = SIZE_MAX,
+ float speed = 1.0f);
virtual ~Track();
virtual status_t initCheck() const;
@@ -148,14 +149,6 @@
void setFinalVolume(float volume);
float getFinalVolume() const { return mFinalVolume; }
- /** @return true if the track has changed (metadata or volume) since
- * the last time this function was called,
- * true if this function was never called since the track creation,
- * false otherwise.
- * Thread safe.
- */
- bool readAndClearHasChanged() { return !mChangeNotified.test_and_set(); }
-
using SourceMetadatas = std::vector<playback_track_metadata_v7_t>;
using MetadataInserter = std::back_insert_iterator<SourceMetadatas>;
/** Copy the track metadata in the provided iterator. Thread safe. */
@@ -191,6 +184,9 @@
mAudioTrackServerProxy->getUnderrunFrames());
}
}
+
+ audio_output_flags_t getOutputFlags() const { return mFlags; }
+ float getSpeed() const { return mSpeed; }
protected:
// for numerous
friend class PlaybackThread;
@@ -234,8 +230,6 @@
bool presentationComplete(int64_t framesWritten, size_t audioHalFrames);
void signalClientFlag(int32_t flag);
- /** Set that a metadata has changed and needs to be notified to backend. Thread safe. */
- void setMetadataHasChanged() { mChangeNotified.clear(); }
public:
void triggerEvents(AudioSystem::sync_event_t type);
virtual void invalidate();
@@ -320,9 +314,8 @@
bool mFlushHwPending; // track requests for thread flush
bool mPauseHwPending = false; // direct/offload track request for thread pause
audio_output_flags_t mFlags;
- // If the last track change was notified to the client with readAndClearHasChanged
- std::atomic_flag mChangeNotified = ATOMIC_FLAG_INIT;
TeePatches mTeePatches;
+ const float mSpeed;
}; // end of Track
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index d42a6ca..25a19a2 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -1798,8 +1798,14 @@
template <typename T>
bool AudioFlinger::ThreadBase::ActiveTracks<T>::readAndClearHasChanged() {
- const bool hasChanged = mHasChanged;
+ bool hasChanged = mHasChanged;
mHasChanged = false;
+
+ for (const sp<T> &track : mActiveTracks) {
+ // Do not short-circuit as all hasChanged states must be reset
+ // as all the metadata are going to be sent
+ hasChanged |= track->readAndClearHasChanged();
+ }
return hasChanged;
}
@@ -1986,7 +1992,7 @@
void AudioFlinger::PlaybackThread::onFirstRef()
{
- if (mOutput == nullptr || mOutput->stream == nullptr) {
+ if (!isStreamInitialized()) {
ALOGE("The stream is not open yet"); // This should not happen.
} else {
// setEventCallback will need a strong pointer as a parameter. Calling it
@@ -2419,7 +2425,7 @@
channelMask, frameCount,
nullptr /* buffer */, (size_t)0 /* bufferSize */, sharedBuffer,
sessionId, creatorPid, identity, trackFlags, TrackBase::TYPE_DEFAULT,
- portId, SIZE_MAX /*frameCountToBeReady*/);
+ portId, SIZE_MAX /*frameCountToBeReady*/, speed);
lStatus = track != 0 ? track->initCheck() : (status_t) NO_MEMORY;
if (lStatus != NO_ERROR) {
@@ -2695,7 +2701,7 @@
status_t AudioFlinger::DirectOutputThread::selectPresentation(int presentationId, int programId) {
Mutex::Autolock _l(mLock);
- if (mOutput == nullptr || mOutput->stream == nullptr) {
+ if (!isStreamInitialized()) {
return NO_INIT;
}
return mOutput->stream->selectPresentation(presentationId, programId);
@@ -2992,16 +2998,7 @@
void AudioFlinger::PlaybackThread::updateMetadata_l()
{
- if (mOutput == nullptr || mOutput->stream == nullptr ) {
- return; // That should not happen
- }
- bool hasChanged = mActiveTracks.readAndClearHasChanged();
- for (const sp<Track> &track : mActiveTracks) {
- // Do not short-circuit as all hasChanged states must be reset
- // as all the metadata are going to be sent
- hasChanged |= track->readAndClearHasChanged();
- }
- if (!hasChanged) {
+ if (!isStreamInitialized() || !mActiveTracks.readAndClearHasChanged()) {
return; // nothing to do
}
StreamOutHalInterface::SourceMetadata metadata;
@@ -3324,6 +3321,17 @@
invalidateTracks_l(streamType);
}
+// getTrackById_l must be called with holding thread lock
+AudioFlinger::PlaybackThread::Track* AudioFlinger::PlaybackThread::getTrackById_l(
+ audio_port_handle_t trackPortId) {
+ for (size_t i = 0; i < mTracks.size(); i++) {
+ if (mTracks[i]->portId() == trackPortId) {
+ return mTracks[i].get();
+ }
+ }
+ return nullptr;
+}
+
status_t AudioFlinger::PlaybackThread::addEffectChain_l(const sp<EffectChain>& chain)
{
audio_session_t session = chain->sessionId();
@@ -8186,7 +8194,7 @@
{
ALOGV("RecordThread::getActiveMicrophones");
AutoMutex _l(mLock);
- if (mInput == nullptr || mInput->stream == nullptr) {
+ if (!isStreamInitialized()) {
return NO_INIT;
}
status_t status = mInput->stream->getActiveMicrophones(activeMicrophones);
@@ -8198,7 +8206,7 @@
{
ALOGV("setPreferredMicrophoneDirection(%d)", direction);
AutoMutex _l(mLock);
- if (mInput == nullptr || mInput->stream == nullptr) {
+ if (!isStreamInitialized()) {
return NO_INIT;
}
return mInput->stream->setPreferredMicrophoneDirection(direction);
@@ -8208,7 +8216,7 @@
{
ALOGV("setPreferredMicrophoneFieldDimension(%f)", zoom);
AutoMutex _l(mLock);
- if (mInput == nullptr || mInput->stream == nullptr) {
+ if (!isStreamInitialized()) {
return NO_INIT;
}
return mInput->stream->setPreferredMicrophoneFieldDimension(zoom);
@@ -8259,9 +8267,8 @@
void AudioFlinger::RecordThread::updateMetadata_l()
{
- if (mInput == nullptr || mInput->stream == nullptr ||
- !mActiveTracks.readAndClearHasChanged()) {
- return;
+ if (!isStreamInitialized() || !mActiveTracks.readAndClearHasChanged()) {
+ return; // nothing to do
}
StreamInHalInterface::SinkMetadata metadata;
for (const sp<RecordTrack> &track : mActiveTracks) {
@@ -9959,14 +9966,16 @@
}
}
}
+ for (const sp<MmapTrack> &track : mActiveTracks) {
+ track->setMetadataHasChanged();
+ }
}
}
void AudioFlinger::MmapPlaybackThread::updateMetadata_l()
{
- if (mOutput == nullptr || mOutput->stream == nullptr ||
- !mActiveTracks.readAndClearHasChanged()) {
- return;
+ if (!isStreamInitialized() || !mActiveTracks.readAndClearHasChanged()) {
+ return; // nothing to do
}
StreamOutHalInterface::SourceMetadata metadata;
for (const sp<MmapTrack> &track : mActiveTracks) {
@@ -10093,9 +10102,8 @@
void AudioFlinger::MmapCaptureThread::updateMetadata_l()
{
- if (mInput == nullptr || mInput->stream == nullptr ||
- !mActiveTracks.readAndClearHasChanged()) {
- return;
+ if (!isStreamInitialized() || !mActiveTracks.readAndClearHasChanged()) {
+ return; // nothing to do
}
StreamInHalInterface::SinkMetadata metadata;
for (const sp<MmapTrack> &track : mActiveTracks) {
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 65db986..d4fb995 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -527,6 +527,8 @@
}
}
+ virtual bool isStreamInitialized() = 0;
+
protected:
// entry describing an effect being suspended in mSuspendedSessions keyed vector
@@ -741,7 +743,9 @@
void updatePowerState(sp<ThreadBase> thread, bool force = false);
/** @return true if one or move active tracks was added or removed since the
- * last time this function was called or the vector was created. */
+ * last time this function was called or the vector was created.
+ * true if volume of one of active tracks was changed.
+ */
bool readAndClearHasChanged();
private:
@@ -993,6 +997,10 @@
&& outDeviceTypes().count(mTimestampCorrectedDevice) != 0;
}
+ virtual bool isStreamInitialized() {
+ return !(mOutput == nullptr || mOutput->stream == nullptr);
+ }
+
audio_channel_mask_t hapticChannelMask() const override {
return mHapticChannelMask;
}
@@ -1005,6 +1013,8 @@
mDownStreamPatch = *patch;
}
+ PlaybackThread::Track* getTrackById_l(audio_port_handle_t trackId);
+
protected:
// updated by readOutputParameters_l()
size_t mNormalFrameCount; // normal mixer and effects
@@ -1780,6 +1790,10 @@
audio_session_t sharedSessionId = AUDIO_SESSION_NONE,
int64_t sharedAudioStartMs = -1);
+ virtual bool isStreamInitialized() {
+ return !(mInput == nullptr || mInput->stream == nullptr);
+ }
+
protected:
void dumpInternals_l(int fd, const Vector<String16>& args) override;
void dumpTracks_l(int fd, const Vector<String16>& args) override;
@@ -1949,6 +1963,8 @@
virtual void setRecordSilenced(audio_port_handle_t portId __unused,
bool silenced __unused) {}
+ virtual bool isStreamInitialized() { return false; }
+
protected:
void dumpInternals_l(int fd, const Vector<String16>& args) override;
void dumpTracks_l(int fd, const Vector<String16>& args) override;
@@ -2011,6 +2027,10 @@
status_t getExternalPosition(uint64_t *position, int64_t *timeNanos) override;
+ virtual bool isStreamInitialized() {
+ return !(mOutput == nullptr || mOutput->stream == nullptr);
+ }
+
protected:
void dumpInternals_l(int fd, const Vector<String16>& args) override;
@@ -2043,6 +2063,10 @@
status_t getExternalPosition(uint64_t *position, int64_t *timeNanos) override;
+ virtual bool isStreamInitialized() {
+ return !(mInput == nullptr || mInput->stream == nullptr);
+ }
+
protected:
AudioStreamIn* mInput;
diff --git a/services/audioflinger/TrackBase.h b/services/audioflinger/TrackBase.h
index 38dab5b..92f129c 100644
--- a/services/audioflinger/TrackBase.h
+++ b/services/audioflinger/TrackBase.h
@@ -255,6 +255,17 @@
audio_channel_mask_t channelMask() const { return mChannelMask; }
+ /** @return true if the track has changed (metadata or volume) since
+ * the last time this function was called,
+ * true if this function was never called since the track creation,
+ * false otherwise.
+ * Thread safe.
+ */
+ bool readAndClearHasChanged() { return !mChangeNotified.test_and_set(); }
+
+ /** Set that a metadata has changed and needs to be notified to backend. Thread safe. */
+ void setMetadataHasChanged() { mChangeNotified.clear(); }
+
protected:
DISALLOW_COPY_AND_ASSIGN(TrackBase);
@@ -391,6 +402,9 @@
std::atomic<FrameTime> mKernelFrameTime{}; // last frame time on kernel side.
const pid_t mCreatorPid; // can be different from mclient->pid() for instance
// when created by NuPlayer on behalf of a client
+
+ // If the last track change was notified to the client with readAndClearHasChanged
+ std::atomic_flag mChangeNotified = ATOMIC_FLAG_INIT;
};
// PatchProxyBufferProvider interface is implemented by PatchTrack and PatchRecord.
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index 3e04804..a6dfe1e 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -624,7 +624,8 @@
audio_output_flags_t flags,
track_type type,
audio_port_handle_t portId,
- size_t frameCountToBeReady)
+ size_t frameCountToBeReady,
+ float speed)
: TrackBase(thread, client, attr, sampleRate, format, channelMask, frameCount,
// TODO: Using unsecurePointer() has some associated security pitfalls
// (see declaration for details).
@@ -658,7 +659,8 @@
mFinalVolume(0.f),
mResumeToStopping(false),
mFlushHwPending(false),
- mFlags(flags)
+ mFlags(flags),
+ mSpeed(speed)
{
// client == 0 implies sharedBuffer == 0
ALOG_ASSERT(!(client == 0 && sharedBuffer != 0));
@@ -1402,6 +1404,10 @@
void AudioFlinger::PlaybackThread::Track::setTeePatches(TeePatches teePatches) {
forEachTeePatchTrack([](auto patchTrack) { patchTrack->destroy(); });
mTeePatches = std::move(teePatches);
+ if (mState == TrackBase::ACTIVE || mState == TrackBase::RESUMING ||
+ mState == TrackBase::STOPPING_1) {
+ forEachTeePatchTrack([](auto patchTrack) { patchTrack->start(); });
+ }
}
status_t AudioFlinger::PlaybackThread::Track::getTimestamp(AudioTimestamp& timestamp)
diff --git a/services/audiopolicy/AudioPolicyInterface.h b/services/audiopolicy/AudioPolicyInterface.h
index 5f052a5..a904321 100644
--- a/services/audiopolicy/AudioPolicyInterface.h
+++ b/services/audiopolicy/AudioPolicyInterface.h
@@ -17,6 +17,7 @@
#ifndef ANDROID_AUDIOPOLICY_INTERFACE_H
#define ANDROID_AUDIOPOLICY_INTERFACE_H
+#include <media/AudioCommonTypes.h>
#include <media/AudioDeviceTypeAddr.h>
#include <media/AudioSystem.h>
#include <media/AudioPolicy.h>
@@ -453,6 +454,9 @@
virtual void setSoundTriggerCaptureState(bool active) = 0;
virtual status_t getAudioPort(struct audio_port_v7 *port) = 0;
+
+ virtual status_t updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs) = 0;
};
// These are the signatures of createAudioPolicyManager/destroyAudioPolicyManager
diff --git a/services/audiopolicy/common/managerdefinitions/include/ClientDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/ClientDescriptor.h
index 59876c6..74b3405 100644
--- a/services/audiopolicy/common/managerdefinitions/include/ClientDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/ClientDescriptor.h
@@ -109,6 +109,9 @@
const std::vector<wp<SwAudioOutputDescriptor>>& getSecondaryOutputs() const {
return mSecondaryOutputs;
};
+ void setSecondaryOutputs(std::vector<wp<SwAudioOutputDescriptor>>&& secondaryOutputs) {
+ mSecondaryOutputs = std::move(secondaryOutputs);
+ }
VolumeSource volumeSource() const { return mVolumeSource; }
const sp<AudioPolicyMix> getPrimaryMix() const {
return mPrimaryMix.promote();
@@ -143,7 +146,7 @@
const product_strategy_t mStrategy;
const VolumeSource mVolumeSource;
const audio_output_flags_t mFlags;
- const std::vector<wp<SwAudioOutputDescriptor>> mSecondaryOutputs;
+ std::vector<wp<SwAudioOutputDescriptor>> mSecondaryOutputs;
const wp<AudioPolicyMix> mPrimaryMix;
/**
* required for duplicating thread, prevent from removing active client from an output
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 7185435..c8ddbc6 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -31,6 +31,7 @@
#include <algorithm>
#include <inttypes.h>
+#include <map>
#include <math.h>
#include <set>
#include <unordered_set>
@@ -5694,6 +5695,7 @@
void AudioPolicyManager::checkSecondaryOutputs() {
std::set<audio_stream_type_t> streamsToInvalidate;
+ TrackSecondaryOutputsMap trackSecondaryOutputs;
for (size_t i = 0; i < mOutputs.size(); i++) {
const sp<SwAudioOutputDescriptor>& outputDescriptor = mOutputs[i];
for (const sp<TrackClientDescriptor>& client : outputDescriptor->getClientIterable()) {
@@ -5710,16 +5712,28 @@
}
}
- if (status != OK ||
- !std::equal(client->getSecondaryOutputs().begin(),
- client->getSecondaryOutputs().end(),
- secondaryDescs.begin(), secondaryDescs.end())) {
+ if (status != OK) {
streamsToInvalidate.insert(client->stream());
+ } else if (!std::equal(
+ client->getSecondaryOutputs().begin(),
+ client->getSecondaryOutputs().end(),
+ secondaryDescs.begin(), secondaryDescs.end())) {
+ std::vector<wp<SwAudioOutputDescriptor>> weakSecondaryDescs;
+ std::vector<audio_io_handle_t> secondaryOutputIds;
+ for (const auto& secondaryDesc : secondaryDescs) {
+ secondaryOutputIds.push_back(secondaryDesc->mIoHandle);
+ weakSecondaryDescs.push_back(secondaryDesc);
+ }
+ trackSecondaryOutputs.emplace(client->portId(), secondaryOutputIds);
+ client->setSecondaryOutputs(std::move(weakSecondaryDescs));
}
}
}
+ if (!trackSecondaryOutputs.empty()) {
+ mpClientInterface->updateSecondaryOutputs(trackSecondaryOutputs);
+ }
for (audio_stream_type_t stream : streamsToInvalidate) {
- ALOGD("%s Invalidate stream %d due to secondary output change", __func__, stream);
+ ALOGD("%s Invalidate stream %d due to fail getting output for attr", __func__, stream);
mpClientInterface->invalidateStream(stream);
}
}
diff --git a/services/audiopolicy/service/AudioPolicyClientImpl.cpp b/services/audiopolicy/service/AudioPolicyClientImpl.cpp
index 77b5200..cd53073 100644
--- a/services/audiopolicy/service/AudioPolicyClientImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyClientImpl.cpp
@@ -291,4 +291,14 @@
return af->getAudioPort(port);
}
+status_t AudioPolicyService::AudioPolicyClient::updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs) {
+ sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
+ if (af == nullptr) {
+ ALOGW("%s: could not get AudioFlinger", __func__);
+ return PERMISSION_DENIED;
+ }
+ return af->updateSecondaryOutputs(trackSecondaryOutputs);
+}
+
} // namespace android
diff --git a/services/audiopolicy/service/AudioPolicyService.h b/services/audiopolicy/service/AudioPolicyService.h
index 00d9670..6eb33f6 100644
--- a/services/audiopolicy/service/AudioPolicyService.h
+++ b/services/audiopolicy/service/AudioPolicyService.h
@@ -735,6 +735,9 @@
status_t getAudioPort(struct audio_port_v7 *port) override;
+ status_t updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs) override;
+
private:
AudioPolicyService *mAudioPolicyService;
};
diff --git a/services/audiopolicy/tests/AudioPolicyManagerTestClient.h b/services/audiopolicy/tests/AudioPolicyManagerTestClient.h
index e2d7d17..f7b0565 100644
--- a/services/audiopolicy/tests/AudioPolicyManagerTestClient.h
+++ b/services/audiopolicy/tests/AudioPolicyManagerTestClient.h
@@ -134,6 +134,11 @@
size_t getRoutingUpdatedCounter() const {
return mRoutingUpdatedUpdateCount; }
+ status_t updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs __unused) override {
+ return NO_ERROR;
+ }
+
private:
audio_module_handle_t mNextModuleHandle = AUDIO_MODULE_HANDLE_NONE + 1;
audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1;
diff --git a/services/audiopolicy/tests/AudioPolicyTestClient.h b/services/audiopolicy/tests/AudioPolicyTestClient.h
index d289e15..1384864 100644
--- a/services/audiopolicy/tests/AudioPolicyTestClient.h
+++ b/services/audiopolicy/tests/AudioPolicyTestClient.h
@@ -91,6 +91,10 @@
status_t getAudioPort(struct audio_port_v7 *port __unused) override {
return INVALID_OPERATION;
};
+ status_t updateSecondaryOutputs(
+ const TrackSecondaryOutputsMap& trackSecondaryOutputs __unused) override {
+ return NO_INIT;
+ }
};
} // namespace android
diff --git a/services/mediametrics/statsd_codec.cpp b/services/mediametrics/statsd_codec.cpp
index 2cfdf24..15a729b 100644
--- a/services/mediametrics/statsd_codec.cpp
+++ b/services/mediametrics/statsd_codec.cpp
@@ -55,6 +55,11 @@
// flesh out the protobuf we'll hand off with our data
//
+ //android.media.mediacodec.videoSessionId string
+ std::string sessionId;
+ if (item->getString("android.media.mediacodec.log-session_id", &sessionId)) {
+ metrics_proto.set_log_session_id(std::move(sessionId));
+ }
// android.media.mediacodec.codec string
std::string codec;
if (item->getString("android.media.mediacodec.codec", &codec)) {