Merge "Camera: Cache and defer Surface binder IPC calls" into main
diff --git a/camera/camera2/OutputConfiguration.cpp b/camera/camera2/OutputConfiguration.cpp
index 73b153c..2d1af32 100644
--- a/camera/camera2/OutputConfiguration.cpp
+++ b/camera/camera2/OutputConfiguration.cpp
@@ -25,6 +25,7 @@
#include <binder/Parcel.h>
#include <gui/view/Surface.h>
#include <system/camera_metadata.h>
+#include <system/graphics.h>
#include <utils/String8.h>
@@ -102,6 +103,25 @@
return mUseReadoutTimestamp;
}
+int OutputConfiguration::getFormat() const {
+ return mFormat;
+}
+
+int OutputConfiguration::getDataspace() const {
+ return mDataspace;
+}
+
+int64_t OutputConfiguration::getUsage() const {
+ return mUsage;
+}
+
+bool OutputConfiguration::isComplete() const {
+ return !((mSurfaceType == SURFACE_TYPE_MEDIA_RECORDER ||
+ mSurfaceType == SURFACE_TYPE_MEDIA_CODEC ||
+ mSurfaceType == SURFACE_TYPE_IMAGE_READER) &&
+ mGbps.empty());
+}
+
OutputConfiguration::OutputConfiguration() :
mRotation(INVALID_ROTATION),
mSurfaceSetID(INVALID_SET_ID),
@@ -116,7 +136,10 @@
mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
mTimestampBase(TIMESTAMP_BASE_DEFAULT),
mMirrorMode(MIRROR_MODE_AUTO),
- mUseReadoutTimestamp(false) {
+ mUseReadoutTimestamp(false),
+ mFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
+ mDataspace(0),
+ mUsage(0) {
}
OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
@@ -234,6 +257,24 @@
return err;
}
+ int format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
+ if ((err = parcel->readInt32(&format)) != OK) {
+ ALOGE("%s: Failed to read format from parcel", __FUNCTION__);
+ return err;
+ }
+
+ int dataspace = 0;
+ if ((err = parcel->readInt32(&dataspace)) != OK) {
+ ALOGE("%s: Failed to read dataspace from parcel", __FUNCTION__);
+ return err;
+ }
+
+ int64_t usage = 0;
+ if ((err = parcel->readInt64(&usage)) != OK) {
+ ALOGE("%s: Failed to read usage flag from parcel", __FUNCTION__);
+ return err;
+ }
+
mRotation = rotation;
mSurfaceSetID = setID;
mSurfaceType = surfaceType;
@@ -256,13 +297,17 @@
mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
mDynamicRangeProfile = dynamicProfile;
mColorSpace = colorSpace;
+ mFormat = format;
+ mDataspace = dataspace;
+ mUsage = usage;
ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
" physicalCameraId = %s, isMultiResolution = %d, streamUseCase = %" PRId64
- ", timestampBase = %d, mirrorMode = %d, useReadoutTimestamp = %d",
+ ", timestampBase = %d, mirrorMode = %d, useReadoutTimestamp = %d, format = %d, "
+ "dataspace = %d, usage = %" PRId64,
__FUNCTION__, mRotation, mSurfaceSetID, mSurfaceType,
mPhysicalCameraId.c_str(), mIsMultiResolution, mStreamUseCase, timestampBase,
- mMirrorMode, mUseReadoutTimestamp);
+ mMirrorMode, mUseReadoutTimestamp, mFormat, mDataspace, mUsage);
return err;
}
@@ -283,6 +328,9 @@
mTimestampBase = TIMESTAMP_BASE_DEFAULT;
mMirrorMode = MIRROR_MODE_AUTO;
mUseReadoutTimestamp = false;
+ mFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
+ mDataspace = 0;
+ mUsage = 0;
}
OutputConfiguration::OutputConfiguration(
@@ -296,7 +344,9 @@
mColorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED),
mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
mTimestampBase(TIMESTAMP_BASE_DEFAULT),
- mMirrorMode(MIRROR_MODE_AUTO), mUseReadoutTimestamp(false) { }
+ mMirrorMode(MIRROR_MODE_AUTO), mUseReadoutTimestamp(false),
+ mFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED), mDataspace(0),
+ mUsage(0) { }
status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
@@ -362,6 +412,15 @@
err = parcel->writeInt32(mUseReadoutTimestamp ? 1 : 0);
if (err != OK) return err;
+ err = parcel->writeInt32(mFormat);
+ if (err != OK) return err;
+
+ err = parcel->writeInt32(mDataspace);
+ if (err != OK) return err;
+
+ err = parcel->writeInt64(mUsage);
+ if (err != OK) return err;
+
return OK;
}
diff --git a/camera/camera_platform.aconfig b/camera/camera_platform.aconfig
index 8e455c6..0dd5df2 100644
--- a/camera/camera_platform.aconfig
+++ b/camera/camera_platform.aconfig
@@ -170,3 +170,13 @@
bug: "297083874"
}
+
+flag {
+ namespace: "camera_platform"
+ name: "cache_permission_services"
+ description: "Cache IPermissionController and IPermissionChecker in CameraService to reduce query latency."
+ bug: "326139956"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
diff --git a/camera/include/camera/camera2/OutputConfiguration.h b/camera/include/camera/camera2/OutputConfiguration.h
index 3f74b4a..83ce39d 100644
--- a/camera/include/camera/camera2/OutputConfiguration.h
+++ b/camera/include/camera/camera2/OutputConfiguration.h
@@ -35,10 +35,13 @@
static const int INVALID_ROTATION;
static const int INVALID_SET_ID;
- enum SurfaceType{
+ enum SurfaceType {
SURFACE_TYPE_UNKNOWN = -1,
SURFACE_TYPE_SURFACE_VIEW = 0,
- SURFACE_TYPE_SURFACE_TEXTURE = 1
+ SURFACE_TYPE_SURFACE_TEXTURE = 1,
+ SURFACE_TYPE_MEDIA_RECORDER = 2,
+ SURFACE_TYPE_MEDIA_CODEC = 3,
+ SURFACE_TYPE_IMAGE_READER = 4
};
enum TimestampBaseType {
TIMESTAMP_BASE_DEFAULT = 0,
@@ -71,6 +74,10 @@
int getTimestampBase() const;
int getMirrorMode() const;
bool useReadoutTimestamp() const;
+ int getFormat() const;
+ int getDataspace() const;
+ int64_t getUsage() const;
+ bool isComplete() const;
// set of sensor pixel mode resolutions allowed {MAX_RESOLUTION, DEFAULT_MODE};
const std::vector<int32_t>& getSensorPixelModesUsed() const;
@@ -98,7 +105,7 @@
OutputConfiguration(const std::vector<sp<IGraphicBufferProducer>>& gbps,
int rotation, const std::string& physicalCameraId,
int surfaceSetID = INVALID_SET_ID,
- int surfaceType = OutputConfiguration::SURFACE_TYPE_UNKNOWN, int width = 0,
+ int surfaceType = SURFACE_TYPE_UNKNOWN, int width = 0,
int height = 0, bool isShared = false);
bool operator == (const OutputConfiguration& other) const {
@@ -118,7 +125,10 @@
mStreamUseCase == other.mStreamUseCase &&
mTimestampBase == other.mTimestampBase &&
mMirrorMode == other.mMirrorMode &&
- mUseReadoutTimestamp == other.mUseReadoutTimestamp);
+ mUseReadoutTimestamp == other.mUseReadoutTimestamp &&
+ mFormat == other.mFormat &&
+ mDataspace == other.mDataspace &&
+ mUsage == other.mUsage);
}
bool operator != (const OutputConfiguration& other) const {
return !(*this == other);
@@ -173,6 +183,15 @@
if (mUseReadoutTimestamp != other.mUseReadoutTimestamp) {
return mUseReadoutTimestamp < other.mUseReadoutTimestamp;
}
+ if (mFormat != other.mFormat) {
+ return mFormat < other.mFormat;
+ }
+ if (mDataspace != other.mDataspace) {
+ return mDataspace < other.mDataspace;
+ }
+ if (mUsage != other.mUsage) {
+ return mUsage < other.mUsage;
+ }
return gbpsLessThan(other);
}
@@ -203,6 +222,9 @@
int mTimestampBase;
int mMirrorMode;
bool mUseReadoutTimestamp;
+ int mFormat;
+ int mDataspace;
+ int64_t mUsage;
};
} // namespace params
} // namespace camera2
diff --git a/camera/ndk/include/camera/NdkCameraMetadataTags.h b/camera/ndk/include/camera/NdkCameraMetadataTags.h
index 94599d3..6c58bcf 100644
--- a/camera/ndk/include/camera/NdkCameraMetadataTags.h
+++ b/camera/ndk/include/camera/NdkCameraMetadataTags.h
@@ -2688,7 +2688,9 @@
* upright.</p>
* <p>Camera devices may either encode this value into the JPEG EXIF header, or
* rotate the image data to match this orientation. When the image data is rotated,
- * the thumbnail data will also be rotated.</p>
+ * the thumbnail data will also be rotated. Additionally, in the case where the image data
+ * is rotated, <a href="https://developer.android.com/reference/android/media/Image.html#getWidth">Image#getWidth</a> and <a href="https://developer.android.com/reference/android/media/Image.html#getHeight">Image#getHeight</a>
+ * will not be updated to reflect the height and width of the rotated image.</p>
* <p>Note that this orientation is relative to the orientation of the camera sensor, given
* by ACAMERA_SENSOR_ORIENTATION.</p>
* <p>To translate from the device orientation given by the Android sensor APIs for camera
diff --git a/drm/mediadrm/plugins/clearkey/aidl/Android.bp b/drm/mediadrm/plugins/clearkey/aidl/Android.bp
index 0b0d46a..9a06bd2 100644
--- a/drm/mediadrm/plugins/clearkey/aidl/Android.bp
+++ b/drm/mediadrm/plugins/clearkey/aidl/Android.bp
@@ -107,6 +107,17 @@
installable: false, // installed in APEX
}
+cc_binary {
+ name: "android.hardware.drm-service-lazy.clearkey.apex",
+ stem: "android.hardware.drm-service-lazy.clearkey",
+ defaults: [
+ "aidl_clearkey_service_defaults",
+ "aidl_clearkey_service_defaults-use-static-deps",
+ ],
+ srcs: ["ServiceLazy.cpp"],
+ installable: false, // installed in APEX
+}
+
phony {
name: "android.hardware.drm@latest-service.clearkey",
required: [
@@ -183,17 +194,63 @@
"android.hardware.drm-service.clearkey.apex.rc",
"android.hardware.drm-service.clearkey.xml"
],
+ overrides: [
+ "android.hardware.drm-service.clearkey",
+ ],
}
prebuilt_etc {
name: "android.hardware.drm-service.clearkey.apex.rc",
- src: "android.hardware.drm-service.clearkey.apex.rc",
+ src: ":gen-android.hardware.drm-service.clearkey.apex.rc",
installable: false,
}
+genrule {
+ name: "gen-android.hardware.drm-service.clearkey.apex.rc",
+ srcs: ["android.hardware.drm-service.clearkey.rc"],
+ out: ["android.hardware.drm-service.clearkey.apex.rc"],
+ cmd: "sed -E 's%/vendor/bin/%/apex/com.android.hardware.drm.clearkey/bin/%' $(in) > $(out)",
+}
+
prebuilt_etc {
name: "android.hardware.drm-service.clearkey.xml",
src: "android.hardware.drm-service.clearkey.xml",
sub_dir: "vintf",
installable: false,
}
+
+apex {
+ name: "com.android.hardware.drm.clearkey.lazy",
+ manifest: "manifest.json",
+ file_contexts: "file_contexts",
+ key: "com.android.hardware.key",
+ certificate: ":com.android.hardware.certificate",
+ vendor: true,
+ updatable: false,
+
+ binaries: [
+ "android.hardware.drm-service-lazy.clearkey.apex",
+ ],
+ prebuilts: [
+ "android.hardware.drm-service-lazy.clearkey.apex.rc",
+ "android.hardware.drm-service.clearkey.xml"
+ ],
+ overrides: [
+ "android.hardware.drm-service.clearkey",
+ "android.hardware.drm-service-lazy.clearkey",
+ "com.android.hardware.drm.clearkey",
+ ],
+}
+
+prebuilt_etc {
+ name: "android.hardware.drm-service-lazy.clearkey.apex.rc",
+ src: ":gen-android.hardware.drm-service-lazy.clearkey.apex.rc",
+ installable: false,
+}
+
+genrule {
+ name: "gen-android.hardware.drm-service-lazy.clearkey.apex.rc",
+ srcs: ["android.hardware.drm-service-lazy.clearkey.rc"],
+ out: ["android.hardware.drm-service-lazy.clearkey.apex.rc"],
+ cmd: "sed -E 's%/vendor/bin/%/apex/com.android.hardware.drm.clearkey/bin/%' $(in) > $(out)",
+}
diff --git a/drm/mediadrm/plugins/clearkey/aidl/android.hardware.drm-service.clearkey.apex.rc b/drm/mediadrm/plugins/clearkey/aidl/android.hardware.drm-service.clearkey.apex.rc
deleted file mode 100644
index f4645b3..0000000
--- a/drm/mediadrm/plugins/clearkey/aidl/android.hardware.drm-service.clearkey.apex.rc
+++ /dev/null
@@ -1,7 +0,0 @@
-service vendor.drm-clearkey-service /apex/com.android.hardware.drm.clearkey/bin/hw/android.hardware.drm-service.clearkey
- class hal
- user media
- group mediadrm drmrpc
- ioprio rt 4
- task_profiles ProcessCapacityHigh
- interface aidl android.hardware.drm.IDrmFactory/clearkey
diff --git a/media/audio/aconfig/Android.bp b/media/audio/aconfig/Android.bp
index 6d21e97..71c2cd1 100644
--- a/media/audio/aconfig/Android.bp
+++ b/media/audio/aconfig/Android.bp
@@ -53,9 +53,9 @@
// TODO(b/316909431) native_bridge_supported: true,
apex_available: [
"//apex_available:platform",
+ "com.android.btservices",
"com.android.media",
"com.android.media.swcodec",
- "com.android.btservices",
],
min_sdk_version: "29",
}
diff --git a/media/audio/aconfig/audio_framework.aconfig b/media/audio/aconfig/audio_framework.aconfig
index 676733d..a2e9849 100644
--- a/media/audio/aconfig/audio_framework.aconfig
+++ b/media/audio/aconfig/audio_framework.aconfig
@@ -4,6 +4,7 @@
# Please add flags in alphabetical order.
package: "android.media.audio"
+container: "system"
flag {
name: "auto_public_volume_api_hardening"
@@ -45,8 +46,9 @@
namespace: "media_audio"
description:
"Audio focus gain requires FGS or delegation to "
- "take effect"
+ "take effect"
bug: "296232417"
+ is_fixed_read_only: true
}
# TODO remove
diff --git a/media/audioaidlconversion/Android.bp b/media/audioaidlconversion/Android.bp
index 07c59c7..2e1eb8c 100644
--- a/media/audioaidlconversion/Android.bp
+++ b/media/audioaidlconversion/Android.bp
@@ -58,10 +58,10 @@
cc_defaults {
name: "audio_aidl_conversion_common_default_cpp",
shared_libs: [
+ "framework-permission-aidl-cpp",
"libbinder",
"libshmemcompat",
"shared-file-region-aidl-cpp",
- "framework-permission-aidl-cpp",
],
export_shared_lib_headers: [
"shared-file-region-aidl-cpp",
@@ -94,8 +94,8 @@
],
sanitize: {
misc_undefined: [
- "unsigned-integer-overflow",
"signed-integer-overflow",
+ "unsigned-integer-overflow",
],
},
target: {
@@ -148,8 +148,8 @@
"latest_android_media_audio_common_types_ndk_shared",
],
shared_libs: [
- "libbinder_ndk",
"libbase",
+ "libbinder_ndk",
],
static_libs: [
"libaudioaidlcommon",
@@ -182,8 +182,8 @@
],
shared_libs: [
"libaudio_aidl_conversion_common_ndk",
- "libbinder_ndk",
"libbase",
+ "libbinder_ndk",
],
cflags: [
"-DBACKEND_NDK",
@@ -213,8 +213,8 @@
],
shared_libs: [
"libaudio_aidl_conversion_common_ndk",
- "libbinder_ndk",
"libbase",
+ "libbinder_ndk",
],
cflags: [
"-DBACKEND_NDK",
@@ -238,8 +238,8 @@
"latest_android_media_audio_common_types_ndk_shared",
],
shared_libs: [
- "libbinder_ndk",
"libbase",
+ "libbinder_ndk",
],
cflags: [
"-DBACKEND_CPP_NDK",
diff --git a/media/audioaidlconversion/tests/Android.bp b/media/audioaidlconversion/tests/Android.bp
index 88b2cc9..bca4dd0 100644
--- a/media/audioaidlconversion/tests/Android.bp
+++ b/media/audioaidlconversion/tests/Android.bp
@@ -16,8 +16,8 @@
],
sanitize: {
misc_undefined: [
- "unsigned-integer-overflow",
"signed-integer-overflow",
+ "unsigned-integer-overflow",
],
},
}
@@ -26,8 +26,8 @@
name: "audio_aidl_ndk_conversion_tests",
defaults: [
- "latest_android_media_audio_common_types_ndk_static",
"latest_android_hardware_audio_common_ndk_static",
+ "latest_android_media_audio_common_types_ndk_static",
"libaudio_aidl_conversion_tests_defaults",
],
srcs: ["audio_aidl_ndk_conversion_tests.cpp"],
diff --git a/media/audioserver/Android.bp b/media/audioserver/Android.bp
index 479e13a..e74fb91 100644
--- a/media/audioserver/Android.bp
+++ b/media/audioserver/Android.bp
@@ -27,11 +27,11 @@
],
defaults: [
+ "latest_android_hardware_audio_core_sounddose_ndk_shared",
+ "latest_android_media_audio_common_types_cpp_shared",
"libaaudioservice_dependencies",
"libaudioflinger_dependencies",
"libaudiopolicyservice_dependencies",
- "latest_android_media_audio_common_types_cpp_shared",
- "latest_android_hardware_audio_core_sounddose_ndk_shared",
],
static_libs: [
diff --git a/media/codec2/components/aom/C2SoftAomEnc.cpp b/media/codec2/components/aom/C2SoftAomEnc.cpp
index 7c9d3e8..128e16e 100644
--- a/media/codec2/components/aom/C2SoftAomEnc.cpp
+++ b/media/codec2/components/aom/C2SoftAomEnc.cpp
@@ -605,7 +605,7 @@
mCodecConfiguration->g_timebase.den = 1000000;
// rc_target_bitrate is in kbps, mBitrate in bps
mCodecConfiguration->rc_target_bitrate = (mBitrate->value + 500) / 1000;
- mCodecConfiguration->rc_end_usage = mBitrateControlMode == AOM_Q ? AOM_Q : AOM_CBR;
+ mCodecConfiguration->rc_end_usage = mBitrateControlMode;
// Disable frame drop - not allowed in MediaCodec now.
mCodecConfiguration->rc_dropframe_thresh = 0;
// Disable lagged encoding.
diff --git a/media/codec2/core/include/C2Config.h b/media/codec2/core/include/C2Config.h
index 785cdf2..e6782a9 100644
--- a/media/codec2/core/include/C2Config.h
+++ b/media/codec2/core/include/C2Config.h
@@ -164,6 +164,9 @@
kParamIndexLargeFrame,
kParamIndexAccessUnitInfos, // struct
+ /* Region of Interest Encoding parameters */
+ kParamIndexQpOffsetMapBuffer, // info-buffer, used to signal qp-offset map for a frame
+
// deprecated
kParamIndexDelayRequest = kParamIndexDelay | C2Param::CoreIndex::IS_REQUEST_FLAG,
@@ -201,6 +204,8 @@
kParamIndexPictureQuantization,
kParamIndexHdrDynamicMetadata,
kParamIndexHdrFormat,
+ kParamIndexQpOffsetRect,
+ kParamIndexQpOffsetRects,
/* ------------------------------------ video components ------------------------------------ */
@@ -1394,6 +1399,47 @@
constexpr char C2_PARAMKEY_VUI_ROTATION[] = "coded.vui.rotation";
/**
+ * Region of Interest of an image/video frame communicated as an array of C2QpOffsetRectStruct
+ *
+ * Fields width, height, left and top of C2QpOffsetRectStruct form a bounding box contouring RoI.
+ * Field qpOffset of C2QpOffsetRectStruct indicates the qp bias to be used for quantizing the
+ * coding units of the bounding box.
+ *
+ * If Roi rect is not valid that is bounding box width is < 0 or bounding box height is < 0,
+ * components may ignore the configuration silently. If Roi rect extends outside frame
+ * boundaries, then rect shall be clamped to the frame boundaries.
+ *
+ * The scope of this key is throughout the encoding session until it is reconfigured with a
+ * different value.
+ *
+ * The number of elements in C2StreamQpOffset array is not limited by C2 specification.
+ * However components may mandate a limit. Implementations may drop the rectangles that are beyond
+ * the supported limits. Hence it is preferable to place the rects in descending order of
+ * importance. Transitively, if the bounding boxes overlap, then the most preferred
+ * rectangle's qp offset (earlier rectangle qp offset) will be used to quantize the block.
+ */
+struct C2QpOffsetRectStruct : C2Rect {
+ C2QpOffsetRectStruct() = default;
+ C2QpOffsetRectStruct(const C2Rect &rect, int32_t offset) : C2Rect(rect), qpOffset(offset) {}
+
+ bool operator==(const C2QpOffsetRectStruct &) = delete;
+ bool operator!=(const C2QpOffsetRectStruct &) = delete;
+
+ int32_t qpOffset;
+
+ DEFINE_AND_DESCRIBE_C2STRUCT(QpOffsetRect)
+ C2FIELD(width, "width")
+ C2FIELD(height, "height")
+ C2FIELD(left, "left")
+ C2FIELD(top, "top")
+ C2FIELD(qpOffset, "qp-offset")
+};
+
+typedef C2StreamParam<C2Info, C2SimpleArrayStruct<C2QpOffsetRectStruct>, kParamIndexQpOffsetRects>
+ C2StreamQpOffsetRects;
+constexpr char C2_PARAMKEY_QP_OFFSET_RECTS[] = "coding.qp-offset-rects";
+
+/**
* Pixel (sample) aspect ratio.
*/
typedef C2StreamParam<C2Info, C2PictureSizeStruct, kParamIndexPixelAspectRatio>
diff --git a/media/libaaudio/fuzzer/Android.bp b/media/libaaudio/fuzzer/Android.bp
index 6d94f38..fc8ad77 100644
--- a/media/libaaudio/fuzzer/Android.bp
+++ b/media/libaaudio/fuzzer/Android.bp
@@ -36,37 +36,37 @@
"libaaudio_headers",
],
shared_libs: [
- "libbinder",
+ "com.android.media.aaudio-aconfig-cc",
+ "libaudio_aidl_conversion_common_cpp",
+ "libaudioclient_aidl_conversion",
"libaudiomanager",
"libaudiopolicy",
- "libaudioclient_aidl_conversion",
- "libaudio_aidl_conversion_common_cpp",
+ "libbinder",
"libutils",
- "com.android.media.aaudio-aconfig-cc",
],
static_libs: [
- "liblog",
- "libcutils",
+ "aaudio-aidl-cpp",
+ "audioclient-types-aidl-cpp",
+ "audioflinger-aidl-cpp",
+ "audiopolicy-aidl-cpp",
+ "audiopolicy-types-aidl-cpp",
+ "av-types-aidl-cpp",
+ "framework-permission-aidl-cpp",
"libaaudio",
- "libjsoncpp",
+ "libaaudio_internal",
+ "libaudioclient",
+ "libaudioutils",
"libbase_ndk",
"libcgrouprc",
- "libaudioutils",
- "libaudioclient",
- "aaudio-aidl-cpp",
+ "libcgrouprc_format",
+ "libcutils",
+ "libjsoncpp",
+ "liblog",
"libmedia_helper",
"libmediametrics",
"libprocessgroup",
- "av-types-aidl-cpp",
- "libaaudio_internal",
- "libcgrouprc_format",
- "audiopolicy-aidl-cpp",
- "audioflinger-aidl-cpp",
- "audiopolicy-types-aidl-cpp",
- "audioclient-types-aidl-cpp",
- "shared-file-region-aidl-cpp",
- "framework-permission-aidl-cpp",
"mediametricsservice-aidl-cpp",
+ "shared-file-region-aidl-cpp",
],
fuzz_config: {
cc: [
diff --git a/media/libaaudio/src/Android.bp b/media/libaaudio/src/Android.bp
index d2cb265..398ac5b 100644
--- a/media/libaaudio/src/Android.bp
+++ b/media/libaaudio/src/Android.bp
@@ -57,10 +57,10 @@
"-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
+ "-google-readability-casting", // C++ casts not always necessary and may be verbose
+ "-google-readability-todo", // do not require TODO(info)
"-misc-non-private-member-variables-in-classes", // found in aidl generated files
@@ -90,28 +90,30 @@
],
cflags: [
- "-Wthread-safety",
- "-Wno-unused-parameter",
"-Wall",
"-Werror",
// By default, all symbols are hidden.
+
// "-fvisibility=hidden",
// AAUDIO_API is used to explicitly export a function or a variable as a visible symbol.
+ "-Wno-unused-parameter",
+ "-Wthread-safety",
+
"-DAAUDIO_API=__attribute__((visibility(\"default\")))",
],
shared_libs: [
+ "framework-permission-aidl-cpp",
"libaaudio_internal",
"libaudioclient",
"libaudioutils",
+ "libbinder",
+ "libcutils",
+ "liblog",
"libmedia_helper",
"libmediametrics",
"libmediautils",
- "liblog",
- "libcutils",
"libutils",
- "libbinder",
- "framework-permission-aidl-cpp",
],
sanitize: {
@@ -161,56 +163,49 @@
],
shared_libs: [
+ "aaudio-aidl-cpp",
+ "audioclient-types-aidl-cpp",
+ "com.android.media.aaudio-aconfig-cc",
+ "framework-permission-aidl-cpp",
"libaudioclient",
+ "libaudioclient_aidl_conversion",
"libaudioutils",
+ "libbinder",
+ "libcutils",
+ "liblog",
"libmedia_helper",
"libmediametrics",
"libmediautils",
- "liblog",
- "libcutils",
"libutils",
- "libbinder",
- "framework-permission-aidl-cpp",
- "aaudio-aidl-cpp",
- "audioclient-types-aidl-cpp",
- "libaudioclient_aidl_conversion",
- "com.android.media.aaudio-aconfig-cc",
],
cflags: [
- "-Wno-unused-parameter",
"-Wall",
"-Werror",
+ "-Wno-unused-parameter",
],
srcs: [
- "core/AudioGlobal.cpp",
- "core/AudioStream.cpp",
- "core/AudioStreamBuilder.cpp",
- "core/AAudioStreamParameters.cpp",
- "legacy/AudioStreamLegacy.cpp",
- "legacy/AudioStreamRecord.cpp",
- "legacy/AudioStreamTrack.cpp",
- "utility/AAudioUtilities.cpp",
- "utility/FixedBlockAdapter.cpp",
- "utility/FixedBlockReader.cpp",
- "utility/FixedBlockWriter.cpp",
- "fifo/FifoBuffer.cpp",
- "fifo/FifoControllerBase.cpp",
+ "binding/AAudioBinderAdapter.cpp",
+ "binding/AAudioBinderClient.cpp",
+ "binding/AAudioStreamConfiguration.cpp",
+ "binding/AAudioStreamRequest.cpp",
+ "binding/AudioEndpointParcelable.cpp",
+ "binding/RingBufferParcelable.cpp",
+ "binding/SharedMemoryParcelable.cpp",
+ "binding/SharedRegionParcelable.cpp",
"client/AAudioFlowGraph.cpp",
"client/AudioEndpoint.cpp",
"client/AudioStreamInternal.cpp",
"client/AudioStreamInternalCapture.cpp",
"client/AudioStreamInternalPlay.cpp",
"client/IsochronousClockModel.cpp",
- "binding/AudioEndpointParcelable.cpp",
- "binding/AAudioBinderAdapter.cpp",
- "binding/AAudioBinderClient.cpp",
- "binding/AAudioStreamRequest.cpp",
- "binding/AAudioStreamConfiguration.cpp",
- "binding/RingBufferParcelable.cpp",
- "binding/SharedMemoryParcelable.cpp",
- "binding/SharedRegionParcelable.cpp",
+ "core/AAudioStreamParameters.cpp",
+ "core/AudioGlobal.cpp",
+ "core/AudioStream.cpp",
+ "core/AudioStreamBuilder.cpp",
+ "fifo/FifoBuffer.cpp",
+ "fifo/FifoControllerBase.cpp",
"flowgraph/ChannelCountConverter.cpp",
"flowgraph/ClipToRange.cpp",
"flowgraph/FlowGraphNode.cpp",
@@ -218,20 +213,20 @@
"flowgraph/ManyToMultiConverter.cpp",
"flowgraph/MonoBlend.cpp",
"flowgraph/MonoToMultiConverter.cpp",
- "flowgraph/MultiToMonoConverter.cpp",
"flowgraph/MultiToManyConverter.cpp",
+ "flowgraph/MultiToMonoConverter.cpp",
"flowgraph/RampLinear.cpp",
"flowgraph/SampleRateConverter.cpp",
"flowgraph/SinkFloat.cpp",
+ "flowgraph/SinkI8_24.cpp",
"flowgraph/SinkI16.cpp",
"flowgraph/SinkI24.cpp",
"flowgraph/SinkI32.cpp",
- "flowgraph/SinkI8_24.cpp",
"flowgraph/SourceFloat.cpp",
+ "flowgraph/SourceI8_24.cpp",
"flowgraph/SourceI16.cpp",
"flowgraph/SourceI24.cpp",
"flowgraph/SourceI32.cpp",
- "flowgraph/SourceI8_24.cpp",
"flowgraph/resampler/IntegerRatio.cpp",
"flowgraph/resampler/LinearResampler.cpp",
"flowgraph/resampler/MultiChannelResampler.cpp",
@@ -240,6 +235,13 @@
"flowgraph/resampler/PolyphaseResamplerStereo.cpp",
"flowgraph/resampler/SincResampler.cpp",
"flowgraph/resampler/SincResamplerStereo.cpp",
+ "legacy/AudioStreamLegacy.cpp",
+ "legacy/AudioStreamRecord.cpp",
+ "legacy/AudioStreamTrack.cpp",
+ "utility/AAudioUtilities.cpp",
+ "utility/FixedBlockAdapter.cpp",
+ "utility/FixedBlockReader.cpp",
+ "utility/FixedBlockWriter.cpp",
],
sanitize: {
integer_overflow: true,
@@ -263,17 +265,17 @@
],
srcs: [
"binding/aidl/aaudio/Endpoint.aidl",
+ "binding/aidl/aaudio/IAAudioClient.aidl",
+ "binding/aidl/aaudio/IAAudioService.aidl",
"binding/aidl/aaudio/RingBuffer.aidl",
"binding/aidl/aaudio/SharedRegion.aidl",
"binding/aidl/aaudio/StreamParameters.aidl",
"binding/aidl/aaudio/StreamRequest.aidl",
- "binding/aidl/aaudio/IAAudioClient.aidl",
- "binding/aidl/aaudio/IAAudioService.aidl",
],
imports: [
"audioclient-types-aidl",
- "shared-file-region-aidl",
"framework-permission-aidl",
+ "shared-file-region-aidl",
],
backend: {
java: {
diff --git a/media/libaaudio/tests/Android.bp b/media/libaaudio/tests/Android.bp
index 5ec8276..6aa04a8 100644
--- a/media/libaaudio/tests/Android.bp
+++ b/media/libaaudio/tests/Android.bp
@@ -206,9 +206,9 @@
srcs: ["test_steal_exclusive.cpp"],
shared_libs: [
"libaaudio",
- "liblog",
"libbinder",
"libcutils",
+ "liblog",
"libutils",
],
}
diff --git a/media/libaudioclient/Android.bp b/media/libaudioclient/Android.bp
index 90910a1..2505c7c 100644
--- a/media/libaudioclient/Android.bp
+++ b/media/libaudioclient/Android.bp
@@ -30,14 +30,14 @@
static_libs: [
"audioflinger-aidl-cpp",
"audiopolicy-aidl-cpp",
- "spatializer-aidl-cpp",
"av-types-aidl-cpp",
+ "spatializer-aidl-cpp",
],
export_static_lib_headers: [
"audioflinger-aidl-cpp",
"audiopolicy-aidl-cpp",
- "spatializer-aidl-cpp",
"av-types-aidl-cpp",
+ "spatializer-aidl-cpp",
],
target: {
darwin: {
@@ -49,11 +49,11 @@
cc_library {
name: "libaudiopolicy",
srcs: [
- "VolumeGroupAttributes.cpp",
"AudioPolicy.cpp",
"AudioProductStrategy.cpp",
"AudioVolumeGroup.cpp",
"PolicyAidlConversion.cpp",
+ "VolumeGroupAttributes.cpp",
],
defaults: [
"latest_android_media_audio_common_types_cpp_export_shared",
@@ -64,8 +64,9 @@
"audiopolicy-aidl-cpp",
"audiopolicy-types-aidl-cpp",
"capture_state_listener-aidl-cpp",
- "libaudiofoundation",
+ "framework-permission-aidl-cpp",
"libaudioclient_aidl_conversion",
+ "libaudiofoundation",
"libaudioutils",
"libbinder",
"libcutils",
@@ -73,8 +74,8 @@
"libutils",
],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
include_dirs: ["system/media/audio_utils/include"],
export_include_dirs: ["include"],
@@ -84,8 +85,8 @@
"audiopolicy-aidl-cpp",
"audiopolicy-types-aidl-cpp",
"capture_state_listener-aidl-cpp",
- "libaudiofoundation",
"libaudioclient_aidl_conversion",
+ "libaudiofoundation",
],
header_libs: ["libaudioclient_headers"],
}
@@ -113,9 +114,9 @@
"AudioTrack.cpp",
"AudioTrackShared.cpp",
"IAudioFlinger.cpp",
- "ToneGenerator.cpp",
"PlayerBase.cpp",
"RecordingActivityTracker.cpp",
+ "ToneGenerator.cpp",
"TrackPlayerBase.cpp",
],
defaults: [
@@ -126,16 +127,16 @@
"audioclient-types-aidl-cpp",
"audioflinger-aidl-cpp",
"audiopolicy-aidl-cpp",
- "spatializer-aidl-cpp",
"audiopolicy-types-aidl-cpp",
"av-types-aidl-cpp",
"capture_state_listener-aidl-cpp",
+ "framework-permission-aidl-cpp",
"libaudio_aidl_conversion_common_cpp",
"libaudioclient_aidl_conversion",
"libaudiofoundation",
- "libaudioutils",
- "libaudiopolicy",
"libaudiomanager",
+ "libaudiopolicy",
+ "libaudioutils",
"libbinder",
"libcutils",
"libdl",
@@ -147,24 +148,24 @@
"libprocessgroup",
"libshmemcompat",
"libutils",
- "framework-permission-aidl-cpp",
"packagemanager_aidl-cpp",
+ "spatializer-aidl-cpp",
],
export_shared_lib_headers: [
"audioflinger-aidl-cpp",
"audiopolicy-aidl-cpp",
- "spatializer-aidl-cpp",
"framework-permission-aidl-cpp",
"libbinder",
"libmediametrics",
+ "spatializer-aidl-cpp",
],
include_dirs: [
"frameworks/av/media/libnbaio/include_mono/",
],
local_include_dirs: [
- "include/media",
"aidl",
+ "include/media",
],
header_libs: [
"libaudioclient_headers",
@@ -191,8 +192,8 @@
],
sanitize: {
misc_undefined: [
- "unsigned-integer-overflow",
"signed-integer-overflow",
+ "unsigned-integer-overflow",
],
},
}
@@ -229,8 +230,8 @@
filegroup {
name: "libaudioclient_aidl",
srcs: [
- "aidl/android/media/IPlayer.aidl",
"aidl/android/media/AudioHalVersion.aidl",
+ "aidl/android/media/IPlayer.aidl",
],
path: "aidl",
}
@@ -296,14 +297,14 @@
"aidl/android/media/AudioIoDescriptor.aidl",
"aidl/android/media/AudioPatchFw.aidl",
"aidl/android/media/AudioPolicyConfig.aidl",
- "aidl/android/media/AudioPortFw.aidl",
- "aidl/android/media/AudioPortSys.aidl",
"aidl/android/media/AudioPortConfigFw.aidl",
"aidl/android/media/AudioPortConfigSys.aidl",
"aidl/android/media/AudioPortDeviceExtSys.aidl",
"aidl/android/media/AudioPortExtSys.aidl",
+ "aidl/android/media/AudioPortFw.aidl",
"aidl/android/media/AudioPortMixExtSys.aidl",
"aidl/android/media/AudioPortRole.aidl",
+ "aidl/android/media/AudioPortSys.aidl",
"aidl/android/media/AudioPortType.aidl",
"aidl/android/media/AudioProfileSys.aidl",
"aidl/android/media/AudioRoute.aidl",
@@ -312,8 +313,8 @@
"aidl/android/media/AudioVibratorInfo.aidl",
"aidl/android/media/DeviceConnectedState.aidl",
"aidl/android/media/EffectDescriptor.aidl",
- "aidl/android/media/TrackSecondaryOutputInfo.aidl",
"aidl/android/media/SurroundSoundConfig.aidl",
+ "aidl/android/media/TrackSecondaryOutputInfo.aidl",
],
defaults: [
"latest_android_media_audio_common_types_import_interface",
@@ -345,14 +346,14 @@
srcs: [
"aidl/android/media/AudioAttributesEx.aidl",
"aidl/android/media/AudioMix.aidl",
- "aidl/android/media/AudioMixUpdate.aidl",
- "aidl/android/media/AudioMixerAttributesInternal.aidl",
- "aidl/android/media/AudioMixerBehavior.aidl",
"aidl/android/media/AudioMixCallbackFlag.aidl",
"aidl/android/media/AudioMixMatchCriterion.aidl",
"aidl/android/media/AudioMixMatchCriterionValue.aidl",
"aidl/android/media/AudioMixRouteFlag.aidl",
"aidl/android/media/AudioMixType.aidl",
+ "aidl/android/media/AudioMixUpdate.aidl",
+ "aidl/android/media/AudioMixerAttributesInternal.aidl",
+ "aidl/android/media/AudioMixerBehavior.aidl",
"aidl/android/media/AudioOffloadMode.aidl",
"aidl/android/media/AudioPolicyDeviceState.aidl",
"aidl/android/media/AudioPolicyForceUse.aidl",
@@ -367,6 +368,7 @@
],
imports: [
"audioclient-types-aidl",
+ "framework-permission-aidl",
],
backend: {
cpp: {
@@ -401,8 +403,8 @@
"aidl/android/media/OpenOutputResponse.aidl",
"aidl/android/media/RenderPosition.aidl",
- "aidl/android/media/IAudioFlingerService.aidl",
"aidl/android/media/IAudioFlingerClient.aidl",
+ "aidl/android/media/IAudioFlingerService.aidl",
"aidl/android/media/IAudioRecord.aidl",
"aidl/android/media/IAudioTrack.aidl",
"aidl/android/media/IAudioTrackCallback.aidl",
@@ -418,8 +420,8 @@
"audioclient-types-aidl",
"av-types-aidl",
"effect-aidl",
- "shared-file-region-aidl",
"framework-permission-aidl",
+ "shared-file-region-aidl",
],
double_loadable: true,
backend: {
@@ -446,9 +448,9 @@
"aidl/android/media/GetInputForAttrResponse.aidl",
"aidl/android/media/GetOutputForAttrResponse.aidl",
"aidl/android/media/GetSpatializerResponse.aidl",
- "aidl/android/media/RecordClientInfo.aidl",
"aidl/android/media/IAudioPolicyService.aidl",
"aidl/android/media/IAudioPolicyServiceClient.aidl",
+ "aidl/android/media/RecordClientInfo.aidl",
],
defaults: [
"latest_android_media_audio_common_types_import_interface",
diff --git a/media/libaudioclient/PolicyAidlConversion.cpp b/media/libaudioclient/PolicyAidlConversion.cpp
index a71bb18..441e329 100644
--- a/media/libaudioclient/PolicyAidlConversion.cpp
+++ b/media/libaudioclient/PolicyAidlConversion.cpp
@@ -243,6 +243,7 @@
legacy.mAllowPrivilegedMediaPlaybackCapture = aidl.allowPrivilegedMediaPlaybackCapture;
legacy.mVoiceCommunicationCaptureAllowed = aidl.voiceCommunicationCaptureAllowed;
legacy.mToken = aidl.mToken;
+ legacy.mVirtualDeviceId = aidl.mVirtualDeviceId;
return legacy;
}
@@ -267,6 +268,7 @@
aidl.allowPrivilegedMediaPlaybackCapture = legacy.mAllowPrivilegedMediaPlaybackCapture;
aidl.voiceCommunicationCaptureAllowed = legacy.mVoiceCommunicationCaptureAllowed;
aidl.mToken = legacy.mToken;
+ aidl.mVirtualDeviceId = legacy.mVirtualDeviceId;
return aidl;
}
diff --git a/media/libaudioclient/aidl/android/media/AudioMix.aidl b/media/libaudioclient/aidl/android/media/AudioMix.aidl
index f0c561c..bb8537d 100644
--- a/media/libaudioclient/aidl/android/media/AudioMix.aidl
+++ b/media/libaudioclient/aidl/android/media/AudioMix.aidl
@@ -41,4 +41,6 @@
boolean voiceCommunicationCaptureAllowed;
/** Identifies the owner of the AudioPolicy that this AudioMix belongs to */
IBinder mToken;
+ /** Indicates the Id of the VirtualDevice this AudioMix was registered for */
+ int mVirtualDeviceId;
}
diff --git a/media/libaudioclient/aidl/fuzzer/Android.bp b/media/libaudioclient/aidl/fuzzer/Android.bp
index 02c5a3f..6cfccd6 100644
--- a/media/libaudioclient/aidl/fuzzer/Android.bp
+++ b/media/libaudioclient/aidl/fuzzer/Android.bp
@@ -22,44 +22,45 @@
name: "libaudioclient_aidl_fuzzer_defaults",
static_libs: [
"android.hardware.audio.common@7.0-enums",
- "effect-aidl-cpp",
+ "libaudiomockhal",
"libcgrouprc",
"libcgrouprc_format",
"libfakeservicemanager",
"libjsoncpp",
"liblog",
- "libmediametricsservice",
"libmedia_helper",
+ "libmediametricsservice",
"libprocessgroup",
"shared-file-region-aidl-cpp",
],
shared_libs: [
"android.hardware.audio.common-util",
"audioclient-types-aidl-cpp",
+ "audioflinger-aidl-cpp",
"audiopolicy-aidl-cpp",
"audiopolicy-types-aidl-cpp",
"av-types-aidl-cpp",
"capture_state_listener-aidl-cpp",
+ "effect-aidl-cpp",
"framework-permission-aidl-cpp",
+ "libactivitymanager_aidl",
"libaudioclient",
- "audioflinger-aidl-cpp",
- "libaudioflinger",
"libaudioclient_aidl_conversion",
+ "libaudioflinger",
"libaudiofoundation",
+ "libaudiohal",
"libaudiomanager",
"libaudiopolicy",
- "libaudioutils",
- "libaudiopolicyservice",
"libaudiopolicymanagerdefault",
- "libaudiohal",
+ "libaudiopolicyservice",
"libaudioprocessing",
- "libactivitymanager_aidl",
+ "libaudioutils",
"libdl",
"libheadtracking",
- "libmediautils",
"libmediametrics",
- "libnblog",
+ "libmediautils",
"libnbaio",
+ "libnblog",
"libpowermanager",
"libvibrator",
"libvndksupport",
@@ -68,10 +69,10 @@
"packagemanager_aidl-cpp",
],
header_libs: [
- "libaudiopolicymanager_interface_headers",
+ "libaudioflinger_headers",
"libaudiofoundation_headers",
"libaudiohal_headers",
- "libaudioflinger_headers",
+ "libaudiopolicymanager_interface_headers",
"libbinder_headers",
"libmedia_headers",
],
@@ -93,6 +94,9 @@
name: "audioflinger_aidl_fuzzer",
srcs: ["audioflinger_aidl_fuzzer.cpp"],
defaults: [
+ "latest_android_hardware_audio_core_ndk_shared",
+ "latest_android_hardware_audio_core_sounddose_ndk_shared",
+ "latest_android_hardware_audio_effect_ndk_shared",
"libaudioclient_aidl_fuzzer_defaults",
"service_fuzzer_defaults",
],
diff --git a/media/libaudioclient/aidl/fuzzer/audioflinger_aidl_fuzzer.cpp b/media/libaudioclient/aidl/fuzzer/audioflinger_aidl_fuzzer.cpp
index f99cc3b..5e4f9a1 100644
--- a/media/libaudioclient/aidl/fuzzer/audioflinger_aidl_fuzzer.cpp
+++ b/media/libaudioclient/aidl/fuzzer/audioflinger_aidl_fuzzer.cpp
@@ -17,8 +17,12 @@
#include <AudioFlinger.h>
#include <android-base/logging.h>
#include <android/binder_interface_utils.h>
+#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <android/media/IAudioPolicyService.h>
+#include <core-mock/ConfigMock.h>
+#include <core-mock/ModuleMock.h>
+#include <effect-mock/FactoryMock.h>
#include <fakeservicemanager/FakeServiceManager.h>
#include <fuzzbinder/libbinder_driver.h>
#include <fuzzbinder/random_binder.h>
@@ -53,14 +57,26 @@
});
gFakeServiceManager->clear();
- for (const char* service :
- {"activity", "sensor_privacy", "permission", "scheduling_policy",
- "android.hardware.audio.core.IConfig", "batterystats", "media.metrics"}) {
+ for (const char* service : {"activity", "sensor_privacy", "permission", "scheduling_policy",
+ "batterystats", "media.metrics"}) {
if (!addService(String16(service), gFakeServiceManager, fdp)) {
return 0;
}
}
+ auto configService = ndk::SharedRefBase::make<ConfigMock>();
+ CHECK_EQ(NO_ERROR, AServiceManager_addService(configService.get()->asBinder().get(),
+ "android.hardware.audio.core.IConfig/default"));
+
+ auto factoryService = ndk::SharedRefBase::make<FactoryMock>();
+ CHECK_EQ(NO_ERROR,
+ AServiceManager_addService(factoryService.get()->asBinder().get(),
+ "android.hardware.audio.effect.IFactory/default"));
+
+ auto moduleService = ndk::SharedRefBase::make<ModuleMock>();
+ CHECK_EQ(NO_ERROR, AServiceManager_addService(moduleService.get()->asBinder().get(),
+ "android.hardware.audio.core.IModule/default"));
+
const auto audioFlinger = sp<AudioFlinger>::make();
const auto afAdapter = sp<AudioFlingerServerAdapter>::make(audioFlinger);
@@ -77,12 +93,7 @@
false /* allowIsolated */,
IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT));
- sp<IBinder> audioFlingerServiceBinder =
- gFakeServiceManager->getService(String16(IAudioFlinger::DEFAULT_SERVICE_NAME));
- sp<media::IAudioFlingerService> audioFlingerService =
- interface_cast<media::IAudioFlingerService>(audioFlingerServiceBinder);
-
- fuzzService(media::IAudioFlingerService::asBinder(audioFlingerService), std::move(fdp));
+ fuzzService(media::IAudioFlingerService::asBinder(afAdapter), std::move(fdp));
return 0;
}
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/Android.bp b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/Android.bp
new file mode 100644
index 0000000..c4afffb
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/Android.bp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2024 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.
+ */
+
+cc_library {
+ name: "libaudiomockhal",
+
+ defaults: [
+ "latest_android_hardware_audio_core_ndk_shared",
+ "latest_android_hardware_audio_core_sounddose_ndk_shared",
+ "latest_android_hardware_audio_effect_ndk_shared",
+ ],
+ header_libs: [
+ "libbinder_headers",
+ ],
+ static_libs: [
+ "libbinder_random_parcel",
+ ],
+ shared_libs: [
+ "libbinder_ndk",
+ ],
+
+ host_supported: true,
+ srcs: [
+ "FactoryMock.cpp",
+ "ModuleMock.cpp",
+ "StreamInMock.cpp",
+ "StreamOutMock.cpp",
+ ],
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+ export_include_dirs: ["include"],
+}
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/FactoryMock.cpp b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/FactoryMock.cpp
new file mode 100644
index 0000000..ea07afc
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/FactoryMock.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include "effect-mock/FactoryMock.h"
+#include "effect-mock/EffectMock.h"
+
+namespace aidl::android::hardware::audio::effect {
+
+ndk::ScopedAStatus FactoryMock::createEffect(const AudioUuid&,
+ std::shared_ptr<IEffect>* _aidl_return) {
+ *_aidl_return = ndk::SharedRefBase::make<EffectMock>();
+ return ndk::ScopedAStatus::ok();
+}
+
+} // namespace aidl::android::hardware::audio::effect
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/ModuleMock.cpp b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/ModuleMock.cpp
new file mode 100644
index 0000000..711924f
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/ModuleMock.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include "core-mock/ModuleMock.h"
+#include "core-mock/BluetoothA2dpMock.h"
+#include "core-mock/BluetoothLeMock.h"
+#include "core-mock/BluetoothMock.h"
+#include "core-mock/StreamInMock.h"
+#include "core-mock/StreamOutMock.h"
+#include "core-mock/TelephonyMock.h"
+#include "sounddose-mock/SoundDoseMock.h"
+
+namespace aidl::android::hardware::audio::core {
+
+ModuleMock::ModuleMock() {
+ // Device ports
+ auto outDevice = createPort(/* PortId */ 0, /* Name */ "Default",
+ /* Flags */ 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE,
+ /* isInput */ false,
+ createDeviceExt(
+ /* DeviceType */ AudioDeviceType::OUT_DEFAULT,
+ /* Flags */ AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE));
+ mPorts.push_back(outDevice);
+ auto inDevice = createPort(/* PortId */ 1, /* Name */ "Default",
+ /* Flags */ 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE,
+ /* isInput */ true,
+ createDeviceExt(
+ /* DeviceType */ AudioDeviceType::IN_DEFAULT,
+ /* Flags */ 0));
+ mPorts.push_back(outDevice);
+}
+
+ndk::ScopedAStatus ModuleMock::getTelephony(std::shared_ptr<ITelephony>* _aidl_return) {
+ *_aidl_return = ndk::SharedRefBase::make<TelephonyMock>();
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::getBluetooth(std::shared_ptr<IBluetooth>* _aidl_return) {
+ *_aidl_return = ndk::SharedRefBase::make<BluetoothMock>();
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp>* _aidl_return) {
+ *_aidl_return = ndk::SharedRefBase::make<BluetoothA2dpMock>();
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::getBluetoothLe(std::shared_ptr<IBluetoothLe>* _aidl_return) {
+ *_aidl_return = ndk::SharedRefBase::make<BluetoothLeMock>();
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::openInputStream(const OpenInputStreamArguments&,
+ OpenInputStreamReturn* _aidl_return) {
+ _aidl_return->stream = ndk::SharedRefBase::make<StreamInMock>();
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::openOutputStream(const OpenOutputStreamArguments&,
+ OpenOutputStreamReturn* _aidl_return) {
+ _aidl_return->stream = ndk::SharedRefBase::make<StreamOutMock>();
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::getMasterMute(bool* _aidl_return) {
+ *_aidl_return = mMasterMute;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::setMasterMute(bool masterMute) {
+ mMasterMute = masterMute;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::getMasterVolume(float* _aidl_return) {
+ *_aidl_return = mMasterVolume;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::setMasterVolume(float masterVolume) {
+ mMasterVolume = masterVolume;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::getMicMute(bool* _aidl_return) {
+ *_aidl_return = mMicMute;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::setMicMute(bool micMute) {
+ mMicMute = micMute;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::getSoundDose(std::shared_ptr<ISoundDose>* _aidl_return) {
+ *_aidl_return = ndk::SharedRefBase::make<SoundDoseMock>();
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::getMmapPolicyInfos(AudioMMapPolicyType,
+ std::vector<AudioMMapPolicyInfo>* _aidl_return) {
+ AudioMMapPolicyInfo never;
+ never.mmapPolicy = AudioMMapPolicy::NEVER;
+ _aidl_return->push_back(never);
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus ModuleMock::supportsVariableLatency(bool* _aidl_return) {
+ *_aidl_return = false;
+ return ndk::ScopedAStatus::ok();
+}
+
+AudioPortExt ModuleMock::createDeviceExt(AudioDeviceType devType, int32_t flags) {
+ AudioPortDeviceExt deviceExt;
+ deviceExt.device.type.type = devType;
+ deviceExt.flags = flags;
+ return AudioPortExt::make<AudioPortExt::Tag::device>(deviceExt);
+}
+
+AudioPort ModuleMock::createPort(int32_t id, const std::string& name, int32_t flags, bool isInput,
+ const AudioPortExt& ext) {
+ AudioPort port;
+ port.id = id;
+ port.name = name;
+ port.flags = isInput ? AudioIoFlags::make<AudioIoFlags::Tag::input>(flags)
+ : AudioIoFlags::make<AudioIoFlags::Tag::output>(flags);
+ port.ext = ext;
+ return port;
+}
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/StreamInMock.cpp b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/StreamInMock.cpp
new file mode 100644
index 0000000..093a979
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/StreamInMock.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include "core-mock/StreamInMock.h"
+#include "core-mock/StreamCommonMock.h"
+
+namespace aidl::android::hardware::audio::core {
+
+ndk::ScopedAStatus StreamInMock::getStreamCommon(std::shared_ptr<IStreamCommon>* _aidl_return) {
+ if (!mStreamCommon) {
+ mStreamCommon = ndk::SharedRefBase::make<StreamCommonMock>();
+ }
+ *_aidl_return = mStreamCommon;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus StreamInMock::getMicrophoneDirection(
+ IStreamIn::MicrophoneDirection* _aidl_return) {
+ *_aidl_return = mMicrophoneDirection;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus StreamInMock::setMicrophoneDirection(
+ IStreamIn::MicrophoneDirection in_direction) {
+ mMicrophoneDirection = in_direction;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus StreamInMock::getMicrophoneFieldDimension(float* _aidl_return) {
+ *_aidl_return = mMicrophoneFieldDimension;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus StreamInMock::setMicrophoneFieldDimension(float in_zoom) {
+ mMicrophoneFieldDimension = in_zoom;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus StreamInMock::getHwGain(std::vector<float>* _aidl_return) {
+ *_aidl_return = mHwGains;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus StreamInMock::setHwGain(const std::vector<float>& in_channelGains) {
+ mHwGains = in_channelGains;
+ return ndk::ScopedAStatus::ok();
+}
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/StreamOutMock.cpp b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/StreamOutMock.cpp
new file mode 100644
index 0000000..a71f954
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/StreamOutMock.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include "core-mock/StreamOutMock.h"
+#include "core-mock/StreamCommonMock.h"
+
+namespace aidl::android::hardware::audio::core {
+
+ndk::ScopedAStatus StreamOutMock::getStreamCommon(std::shared_ptr<IStreamCommon>* _aidl_return) {
+ if (!mStreamCommon) {
+ mStreamCommon = ndk::SharedRefBase::make<StreamCommonMock>();
+ }
+ *_aidl_return = mStreamCommon;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus StreamOutMock::getHwVolume(std::vector<float>* _aidl_return) {
+ *_aidl_return = mHwVolume;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus StreamOutMock::setHwVolume(const std::vector<float>& in_channelVolumes) {
+ mHwVolume = in_channelVolumes;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus StreamOutMock::getAudioDescriptionMixLevel(float* _aidl_return) {
+ *_aidl_return = mAudioDescriptionMixLeveldB;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus StreamOutMock::setAudioDescriptionMixLevel(float in_leveldB) {
+ mAudioDescriptionMixLeveldB = in_leveldB;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus StreamOutMock::getDualMonoMode(AudioDualMonoMode* _aidl_return) {
+ *_aidl_return = mDualMonoMode;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus StreamOutMock::setDualMonoMode(AudioDualMonoMode in_mode) {
+ mDualMonoMode = in_mode;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus StreamOutMock::getPlaybackRateParameters(AudioPlaybackRate* _aidl_return) {
+ *_aidl_return = mPlaybackRateParameters;
+ return ndk::ScopedAStatus::ok();
+}
+ndk::ScopedAStatus StreamOutMock::setPlaybackRateParameters(
+ const AudioPlaybackRate& in_playbackRate) {
+ mPlaybackRateParameters = in_playbackRate;
+ return ndk::ScopedAStatus::ok();
+}
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothA2dpMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothA2dpMock.h
new file mode 100644
index 0000000..c4dd0d9
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothA2dpMock.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnBluetoothA2dp.h>
+
+using namespace aidl::android::hardware::audio::core;
+
+namespace aidl::android::hardware::audio::core {
+
+class BluetoothA2dpMock : public BnBluetoothA2dp {
+ public:
+ ndk::ScopedAStatus isEnabled(bool* _aidl_return) override {
+ *_aidl_return = mEnabled;
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus setEnabled(bool enabled) override {
+ mEnabled = enabled;
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus supportsOffloadReconfiguration(bool* _aidl_return) override {
+ *_aidl_return = kSupportsOffloadReconfiguration;
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus reconfigureOffload(const std::vector<VendorParameter>&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+
+ private:
+ static constexpr bool kSupportsOffloadReconfiguration = true;
+ bool mEnabled = false;
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothLeMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothLeMock.h
new file mode 100644
index 0000000..d58695a
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothLeMock.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnBluetoothLe.h>
+
+using namespace aidl::android::hardware::audio::core;
+
+namespace aidl::android::hardware::audio::core {
+
+class BluetoothLeMock : public BnBluetoothLe {
+ public:
+ ndk::ScopedAStatus isEnabled(bool* _aidl_return) override {
+ *_aidl_return = mEnabled;
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus setEnabled(bool enabled) override {
+ mEnabled = enabled;
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus supportsOffloadReconfiguration(bool* _aidl_return) override {
+ *_aidl_return = kSupportsOffloadReconfiguration;
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus reconfigureOffload(const std::vector<VendorParameter>&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+
+ private:
+ static constexpr bool kSupportsOffloadReconfiguration = true;
+ bool mEnabled = false;
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothMock.h
new file mode 100644
index 0000000..e805840
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/BluetoothMock.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnBluetooth.h>
+
+using namespace aidl::android::hardware::audio::core;
+
+namespace aidl::android::hardware::audio::core {
+
+class BluetoothMock : public BnBluetooth {
+ public:
+ ndk::ScopedAStatus setScoConfig(const IBluetooth::ScoConfig&, IBluetooth::ScoConfig*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus setHfpConfig(const IBluetooth::HfpConfig&, IBluetooth::HfpConfig*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/ConfigMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/ConfigMock.h
new file mode 100644
index 0000000..f4031b5
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/ConfigMock.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnConfig.h>
+
+using namespace aidl::android::media::audio::common;
+using namespace aidl::android::hardware::audio::core;
+
+namespace aidl::android::hardware::audio::core {
+
+class ConfigMock : public BnConfig {
+ private:
+ ndk::ScopedAStatus getSurroundSoundConfig(SurroundSoundConfig*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getEngineConfig(AudioHalEngineConfig*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/ModuleMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/ModuleMock.h
new file mode 100644
index 0000000..d49203d
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/ModuleMock.h
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnModule.h>
+
+using namespace aidl::android::media::audio::common;
+using namespace aidl::android::hardware::audio::core;
+using namespace aidl::android::hardware::audio::core::sounddose;
+using namespace aidl::android::hardware::audio::effect;
+
+namespace aidl::android::hardware::audio::core {
+
+class ModuleMock : public BnModule {
+ public:
+ ModuleMock();
+
+ private:
+ ndk::ScopedAStatus getTelephony(std::shared_ptr<ITelephony>*) override;
+ ndk::ScopedAStatus getBluetooth(std::shared_ptr<IBluetooth>*) override;
+ ndk::ScopedAStatus getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp>*) override;
+ ndk::ScopedAStatus getBluetoothLe(std::shared_ptr<IBluetoothLe>*) override;
+ ndk::ScopedAStatus openInputStream(const OpenInputStreamArguments&,
+ OpenInputStreamReturn*) override;
+ ndk::ScopedAStatus openOutputStream(const OpenOutputStreamArguments&,
+ OpenOutputStreamReturn*) override;
+ ndk::ScopedAStatus getMasterMute(bool*) override;
+ ndk::ScopedAStatus setMasterMute(bool) override;
+ ndk::ScopedAStatus getMasterVolume(float*) override;
+ ndk::ScopedAStatus setMasterVolume(float) override;
+ ndk::ScopedAStatus getMicMute(bool*) override;
+ ndk::ScopedAStatus setMicMute(bool) override;
+ ndk::ScopedAStatus getSoundDose(std::shared_ptr<ISoundDose>*) override;
+ ndk::ScopedAStatus getMmapPolicyInfos(AudioMMapPolicyType,
+ std::vector<AudioMMapPolicyInfo>*) override;
+ ndk::ScopedAStatus supportsVariableLatency(bool*) override;
+
+ ndk::ScopedAStatus setModuleDebug(const ModuleDebug&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus connectExternalDevice(const AudioPort&, AudioPort*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus disconnectExternalDevice(int32_t) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getAudioPatches(std::vector<AudioPatch>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getAudioPort(int32_t, AudioPort*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getAudioPortConfigs(std::vector<AudioPortConfig>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getAudioPorts(std::vector<AudioPort>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getAudioRoutes(std::vector<AudioRoute>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getAudioRoutesForAudioPort(int32_t, std::vector<AudioRoute>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getSupportedPlaybackRateFactors(SupportedPlaybackRateFactors*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus setAudioPatch(const AudioPatch&, AudioPatch*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus setAudioPortConfig(const AudioPortConfig&, AudioPortConfig*,
+ bool*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus resetAudioPatch(int32_t) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus resetAudioPortConfig(int32_t) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus getMicrophones(std::vector<MicrophoneInfo>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus updateAudioMode(AudioMode) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus updateScreenRotation(ScreenRotation) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus updateScreenState(bool) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus generateHwAvSyncId(int32_t*) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus getVendorParameters(const std::vector<std::string>&,
+ std::vector<VendorParameter>*) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus setVendorParameters(const std::vector<VendorParameter>&, bool) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus addDeviceEffect(int32_t, const std::shared_ptr<IEffect>&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus removeDeviceEffect(int32_t, const std::shared_ptr<IEffect>&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getAAudioMixerBurstCount(int32_t*) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus getAAudioHardwareBurstMinUsec(int32_t*) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus prepareToDisconnectExternalDevice(int32_t) override {
+ return ndk::ScopedAStatus::ok();
+ }
+
+ AudioPortExt createDeviceExt(AudioDeviceType devType, int32_t flags);
+ AudioPort createPort(int32_t id, const std::string& name, int32_t flags, bool isInput,
+ const AudioPortExt& ext);
+
+ bool mMasterMute;
+ float mMasterVolume;
+ bool mMicMute;
+ std::vector<AudioPort> mPorts;
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamCommonMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamCommonMock.h
new file mode 100644
index 0000000..25d53f8
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamCommonMock.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnStreamCommon.h>
+
+using namespace aidl::android::hardware::audio::core;
+using namespace aidl::android::hardware::audio::effect;
+
+namespace aidl::android::hardware::audio::core {
+
+class StreamCommonMock : public BnStreamCommon {
+ ndk::ScopedAStatus close() override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus prepareToClose() override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus updateHwAvSyncId(int32_t) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus getVendorParameters(const std::vector<std::string>&,
+ std::vector<VendorParameter>*) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus setVendorParameters(const std::vector<VendorParameter>&, bool) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus addEffect(const std::shared_ptr<IEffect>&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus removeEffect(const std::shared_ptr<IEffect>&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamInMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamInMock.h
new file mode 100644
index 0000000..5deab5b
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamInMock.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnStreamIn.h>
+
+using namespace aidl::android::hardware::audio::common;
+using namespace aidl::android::hardware::audio::core;
+using namespace aidl::android::media::audio::common;
+
+namespace aidl::android::hardware::audio::core {
+
+class StreamInMock : public BnStreamIn {
+ ndk::ScopedAStatus getStreamCommon(std::shared_ptr<IStreamCommon>* _aidl_return) override;
+ ndk::ScopedAStatus getMicrophoneDirection(
+ IStreamIn::MicrophoneDirection* _aidl_return) override;
+ ndk::ScopedAStatus setMicrophoneDirection(IStreamIn::MicrophoneDirection in_direction) override;
+ ndk::ScopedAStatus getMicrophoneFieldDimension(float* _aidl_return) override;
+ ndk::ScopedAStatus setMicrophoneFieldDimension(float in_zoom) override;
+ ndk::ScopedAStatus getHwGain(std::vector<float>* _aidl_return) override;
+ ndk::ScopedAStatus setHwGain(const std::vector<float>& in_channelGains) override;
+
+ ndk::ScopedAStatus getActiveMicrophones(std::vector<MicrophoneDynamicInfo>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus updateMetadata(const SinkMetadata&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+
+ private:
+ IStreamIn::MicrophoneDirection mMicrophoneDirection;
+ float mMicrophoneFieldDimension;
+ std::vector<float> mHwGains;
+ std::shared_ptr<IStreamCommon> mStreamCommon;
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamOutMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamOutMock.h
new file mode 100644
index 0000000..4d12815
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/StreamOutMock.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnStreamOut.h>
+
+using namespace aidl::android::hardware::audio::common;
+using namespace aidl::android::hardware::audio::core;
+using namespace aidl::android::media::audio::common;
+
+namespace aidl::android::hardware::audio::core {
+
+class StreamOutMock : public BnStreamOut {
+ ndk::ScopedAStatus getStreamCommon(std::shared_ptr<IStreamCommon>* _aidl_return) override;
+ ndk::ScopedAStatus getHwVolume(std::vector<float>* _aidl_return) override;
+ ndk::ScopedAStatus setHwVolume(const std::vector<float>& in_channelVolumes) override;
+ ndk::ScopedAStatus getAudioDescriptionMixLevel(float* _aidl_return) override;
+ ndk::ScopedAStatus setAudioDescriptionMixLevel(float in_leveldB) override;
+ ndk::ScopedAStatus getDualMonoMode(AudioDualMonoMode* _aidl_return) override;
+ ndk::ScopedAStatus setDualMonoMode(AudioDualMonoMode in_mode) override;
+ ndk::ScopedAStatus getPlaybackRateParameters(AudioPlaybackRate* _aidl_return) override;
+ ndk::ScopedAStatus setPlaybackRateParameters(const AudioPlaybackRate& in_playbackRate) override;
+
+ ndk::ScopedAStatus updateMetadata(const SourceMetadata&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus updateOffloadMetadata(const AudioOffloadMetadata&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getRecommendedLatencyModes(std::vector<AudioLatencyMode>*) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus setLatencyMode(AudioLatencyMode) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+ ndk::ScopedAStatus selectPresentation(int32_t, int32_t) override {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ }
+
+ private:
+ AudioPlaybackRate mPlaybackRateParameters;
+ AudioDualMonoMode mDualMonoMode;
+ float mAudioDescriptionMixLeveldB;
+ std::vector<float> mHwVolume;
+ std::shared_ptr<IStreamCommon> mStreamCommon;
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/TelephonyMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/TelephonyMock.h
new file mode 100644
index 0000000..d56dee6
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/core-mock/TelephonyMock.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/BnTelephony.h>
+
+using namespace aidl::android::hardware::audio::core;
+using namespace aidl::android::media::audio::common;
+
+namespace aidl::android::hardware::audio::core {
+
+class TelephonyMock : public BnTelephony {
+ public:
+ ndk::ScopedAStatus getSupportedAudioModes(std::vector<AudioMode>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus switchAudioMode(AudioMode) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus setTelecomConfig(const ITelephony::TelecomConfig&,
+ ITelephony::TelecomConfig*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+};
+
+} // namespace aidl::android::hardware::audio::core
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/effect-mock/EffectMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/effect-mock/EffectMock.h
new file mode 100644
index 0000000..db20cd8
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/effect-mock/EffectMock.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/effect/BnEffect.h>
+
+using namespace aidl::android::hardware::audio::effect;
+
+namespace aidl::android::hardware::audio::effect {
+
+class EffectMock : public BnEffect {
+ public:
+ ndk::ScopedAStatus open(const Parameter::Common&, const std::optional<Parameter::Specific>&,
+ IEffect::OpenEffectReturn*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus close() override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus command(CommandId) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus getState(State*) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus getDescriptor(Descriptor*) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus reopen(IEffect::OpenEffectReturn*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus setParameter(const Parameter&) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus getParameter(const Parameter::Id&, Parameter*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+};
+
+} // namespace aidl::android::hardware::audio::effect
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/effect-mock/FactoryMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/effect-mock/FactoryMock.h
new file mode 100644
index 0000000..57d58d5
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/effect-mock/FactoryMock.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/effect/BnFactory.h>
+
+using namespace aidl::android::media::audio::common;
+using namespace aidl::android::hardware::audio::effect;
+
+namespace aidl::android::hardware::audio::effect {
+
+class FactoryMock : public BnFactory {
+ ndk::ScopedAStatus queryEffects(const std::optional<AudioUuid>&,
+ const std::optional<AudioUuid>&,
+ const std::optional<AudioUuid>&,
+ std::vector<Descriptor>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus queryProcessing(const std::optional<Processing::Type>&,
+ std::vector<Processing>*) override {
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus destroyEffect(const std::shared_ptr<IEffect>&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+
+ ndk::ScopedAStatus createEffect(const AudioUuid&, std::shared_ptr<IEffect>*) override;
+};
+
+} // namespace aidl::android::hardware::audio::effect
diff --git a/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/sounddose-mock/SoundDoseMock.h b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/sounddose-mock/SoundDoseMock.h
new file mode 100644
index 0000000..5557b10
--- /dev/null
+++ b/media/libaudioclient/aidl/fuzzer/libaudiomockhal/include/sounddose-mock/SoundDoseMock.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2024 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.
+ *
+ */
+#include <aidl/android/hardware/audio/core/sounddose/BnSoundDose.h>
+
+using namespace aidl::android::hardware::audio::core::sounddose;
+
+namespace aidl::android::hardware::audio::core::sounddose {
+
+class SoundDoseMock : public BnSoundDose {
+ ndk::ScopedAStatus setOutputRs2UpperBound(float in_rs2ValueDbA) override {
+ mOutputRs2UpperBound = in_rs2ValueDbA;
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus getOutputRs2UpperBound(float* _aidl_return) override {
+ *_aidl_return = mOutputRs2UpperBound;
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus registerSoundDoseCallback(
+ const std::shared_ptr<ISoundDose::IHalSoundDoseCallback>&) override {
+ return ndk::ScopedAStatus::ok();
+ }
+
+ private:
+ float mOutputRs2UpperBound;
+};
+
+} // namespace aidl::android::hardware::audio::core::sounddose
diff --git a/media/libaudioclient/fuzzer/Android.bp b/media/libaudioclient/fuzzer/Android.bp
index f2ad91c..a95c700 100644
--- a/media/libaudioclient/fuzzer/Android.bp
+++ b/media/libaudioclient/fuzzer/Android.bp
@@ -42,9 +42,9 @@
"libcutils",
"libjsoncpp",
"liblog",
+ "libmedia_helper",
"libmediametrics",
"libmediametricsservice",
- "libmedia_helper",
"libprocessgroup",
"shared-file-region-aidl-cpp",
],
@@ -56,8 +56,9 @@
"audiopolicy-types-aidl-cpp",
"av-types-aidl-cpp",
"capture_state_listener-aidl-cpp",
- "libaudioclient_aidl_conversion",
+ "framework-permission-aidl-cpp",
"libaudio_aidl_conversion_common_cpp",
+ "libaudioclient_aidl_conversion",
"libaudioflinger",
"libaudiofoundation",
"libaudiomanager",
@@ -70,7 +71,6 @@
"libutils",
"libxml2",
"mediametricsservice-aidl-cpp",
- "framework-permission-aidl-cpp",
],
header_libs: [
"libaudiofoundation_headers",
diff --git a/media/libaudioclient/include/media/AudioPolicy.h b/media/libaudioclient/include/media/AudioPolicy.h
index 9e4ae54..b190fba 100644
--- a/media/libaudioclient/include/media/AudioPolicy.h
+++ b/media/libaudioclient/include/media/AudioPolicy.h
@@ -129,6 +129,7 @@
String8 mDeviceAddress;
uint32_t mCbFlags; // flags indicating which callbacks to use, see kCbFlag*
sp<IBinder> mToken;
+ uint32_t mVirtualDeviceId;
/** Ignore the AUDIO_FLAG_NO_MEDIA_PROJECTION */
bool mAllowPrivilegedMediaPlaybackCapture = false;
/** Indicates if the caller can capture voice communication output */
diff --git a/media/libaudioclient/tests/Android.bp b/media/libaudioclient/tests/Android.bp
index b667c8d..055da5b 100644
--- a/media/libaudioclient/tests/Android.bp
+++ b/media/libaudioclient/tests/Android.bp
@@ -23,8 +23,8 @@
],
sanitize: {
misc_undefined: [
- "unsigned-integer-overflow",
"signed-integer-overflow",
+ "unsigned-integer-overflow",
],
},
}
@@ -32,8 +32,8 @@
cc_defaults {
name: "audio_aidl_conversion_test_defaults",
defaults: [
- "libaudioclient_tests_defaults",
"latest_android_media_audio_common_types_cpp_static",
+ "libaudioclient_tests_defaults",
],
static_libs: [
"audioclient-types-aidl-cpp",
@@ -110,9 +110,9 @@
"libcgrouprc",
"libdl",
"libmedia",
+ "libmedia_helper",
"libmediametrics",
"libmediautils",
- "libmedia_helper",
"libnblog",
"libprocessgroup",
"libshmemcompat",
diff --git a/media/libaudiofoundation/Android.bp b/media/libaudiofoundation/Android.bp
index c758fcd..576406d 100644
--- a/media/libaudiofoundation/Android.bp
+++ b/media/libaudiofoundation/Android.bp
@@ -87,7 +87,7 @@
],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
}
diff --git a/media/libaudiofoundation/tests/Android.bp b/media/libaudiofoundation/tests/Android.bp
index 82c7db7..0ca50ab 100644
--- a/media/libaudiofoundation/tests/Android.bp
+++ b/media/libaudiofoundation/tests/Android.bp
@@ -22,8 +22,8 @@
static_libs: [
"audioclient-types-aidl-cpp",
- "libaudioclient_aidl_conversion",
"libaudio_aidl_conversion_common_cpp",
+ "libaudioclient_aidl_conversion",
"libaudiofoundation",
"libstagefright_foundation",
],
@@ -37,8 +37,8 @@
],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
test_suites: ["device-tests"],
@@ -64,8 +64,8 @@
],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
test_suites: ["device-tests"],
diff --git a/media/libaudiohal/Android.bp b/media/libaudiohal/Android.bp
index b8d0998..639c7aa 100644
--- a/media/libaudiohal/Android.bp
+++ b/media/libaudiohal/Android.bp
@@ -18,8 +18,8 @@
cflags: [
"-Wall",
- "-Wextra",
"-Werror",
+ "-Wextra",
],
required: [
@@ -44,7 +44,7 @@
"libbase_headers",
"liberror_headers",
"libmediautils_headers",
- ]
+ ],
}
cc_library_shared {
@@ -61,12 +61,12 @@
shared_libs: [
"libhidlbase",
- "libutils",
"liblog",
+ "libutils",
],
header_libs: [
- "libaudiohal_headers"
+ "libaudiohal_headers",
],
}
diff --git a/media/libaudiohal/impl/Android.bp b/media/libaudiohal/impl/Android.bp
index 4d81f77..c7fa96e 100644
--- a/media/libaudiohal/impl/Android.bp
+++ b/media/libaudiohal/impl/Android.bp
@@ -49,8 +49,8 @@
cflags: [
"-Wall",
- "-Wextra",
"-Werror",
+ "-Wextra",
"-fvisibility=hidden",
],
shared_libs: [
@@ -211,10 +211,10 @@
"libbinder_ndk",
],
cflags: [
- "-DMAJOR_VERSION=7",
- "-DMINOR_VERSION=1",
"-DCOMMON_TYPES_MINOR_VERSION=0",
"-DCORE_TYPES_MINOR_VERSION=0",
+ "-DMAJOR_VERSION=7",
+ "-DMINOR_VERSION=1",
"-include common/all-versions/VersionMacro.h",
],
}
@@ -245,25 +245,25 @@
"libeffectsconfig_headers",
],
cflags: [
- "-Wall",
- "-Wextra",
- "-Werror",
- "-Wthread-safety",
"-DBACKEND_CPP_NDK",
+ "-Wall",
+ "-Werror",
+ "-Wextra",
+ "-Wthread-safety",
],
}
cc_library_shared {
name: "libaudiohal@aidl",
defaults: [
- "libaudiohal_default",
"libaudiohal_aidl_default",
+ "libaudiohal_default",
],
srcs: [
- "DevicesFactoryHalEntry.cpp",
- "EffectsFactoryHalEntry.cpp",
":audio_effect_hal_aidl_src_files",
":core_audio_hal_aidl_src_files",
+ "DevicesFactoryHalEntry.cpp",
+ "EffectsFactoryHalEntry.cpp",
],
}
@@ -281,8 +281,9 @@
filegroup {
name: "audio_effect_hal_aidl_src_files",
srcs: [
- "EffectConversionHelperAidl.cpp",
+ ":audio_effectproxy_src_files",
"EffectBufferHalAidl.cpp",
+ "EffectConversionHelperAidl.cpp",
"EffectHalAidl.cpp",
"EffectsFactoryHalAidl.cpp",
"effectsAidlConversion/AidlConversionAec.cpp",
@@ -301,7 +302,6 @@
"effectsAidlConversion/AidlConversionVendorExtension.cpp",
"effectsAidlConversion/AidlConversionVirtualizer.cpp",
"effectsAidlConversion/AidlConversionVisualizer.cpp",
- ":audio_effectproxy_src_files",
],
}
diff --git a/media/libaudiohal/impl/DeviceHalAidl.cpp b/media/libaudiohal/impl/DeviceHalAidl.cpp
index 14765f6b..f865603 100644
--- a/media/libaudiohal/impl/DeviceHalAidl.cpp
+++ b/media/libaudiohal/impl/DeviceHalAidl.cpp
@@ -589,7 +589,6 @@
// that the HAL module uses `int32_t` for patch IDs. The following assert ensures
// that both the framework and the HAL use the same value for "no ID":
static_assert(AUDIO_PATCH_HANDLE_NONE == 0);
- int32_t aidlPatchId = static_cast<int32_t>(*patch);
// Upon conversion, mix port configs contain audio configuration, while
// device port configs contain device address. This data is used to find
@@ -611,11 +610,27 @@
::aidl::android::legacy2aidl_audio_port_config_AudioPortConfig(
sinks[i], isInput, 0)));
}
+ int32_t aidlPatchId = static_cast<int32_t>(*patch);
Hal2AidlMapper::Cleanups cleanups(mMapperAccessor);
{
std::lock_guard l(mLock);
- RETURN_STATUS_IF_ERROR(mMapper.createOrUpdatePatch(
- aidlSources, aidlSinks, &aidlPatchId, &cleanups));
+ // Check for patches that only exist for the framework, or have different HAL patch ID.
+ if (int32_t aidlHalPatchId = mMapper.findFwkPatch(aidlPatchId); aidlHalPatchId != 0) {
+ if (aidlHalPatchId == aidlPatchId) {
+ // This patch was previously released by the HAL. Thus we need to pass '0'
+ // to the HAL to obtain a new patch.
+ int32_t newAidlPatchId = 0;
+ RETURN_STATUS_IF_ERROR(mMapper.createOrUpdatePatch(
+ aidlSources, aidlSinks, &newAidlPatchId, &cleanups));
+ mMapper.updateFwkPatch(aidlPatchId, newAidlPatchId);
+ } else {
+ RETURN_STATUS_IF_ERROR(mMapper.createOrUpdatePatch(
+ aidlSources, aidlSinks, &aidlHalPatchId, &cleanups));
+ }
+ } else {
+ RETURN_STATUS_IF_ERROR(mMapper.createOrUpdatePatch(
+ aidlSources, aidlSinks, &aidlPatchId, &cleanups));
+ }
}
*patch = static_cast<audio_patch_handle_t>(aidlPatchId);
cleanups.disarmAll();
@@ -631,7 +646,19 @@
return BAD_VALUE;
}
std::lock_guard l(mLock);
- RETURN_STATUS_IF_ERROR(mMapper.releaseAudioPatch(static_cast<int32_t>(patch)));
+ // Check for patches that only exist for the framework, or have different HAL patch ID.
+ int32_t aidlPatchId = static_cast<int32_t>(patch);
+ if (int32_t aidlHalPatchId = mMapper.findFwkPatch(aidlPatchId); aidlHalPatchId != 0) {
+ if (aidlHalPatchId == aidlPatchId) {
+ // This patch was previously released by the HAL, just need to finish its removal.
+ mMapper.eraseFwkPatch(aidlPatchId);
+ return OK;
+ } else {
+ // This patch has a HAL patch ID which is different
+ aidlPatchId = aidlHalPatchId;
+ }
+ }
+ RETURN_STATUS_IF_ERROR(mMapper.releaseAudioPatch(aidlPatchId));
return OK;
}
@@ -988,7 +1015,7 @@
if (mModule == nullptr) return NO_INIT;
{
std::lock_guard l(mLock);
- mMapper.resetUnusedPatchesPortConfigsAndPorts();
+ mMapper.resetUnusedPatchesAndPortConfigs();
}
ModuleDebug debug{ .simulateDeviceConnections = enabled };
status_t status = statusTFromBinderStatus(mModule->setModuleDebug(debug));
diff --git a/media/libaudiohal/impl/DeviceHalHidl.cpp b/media/libaudiohal/impl/DeviceHalHidl.cpp
index 478e0f0..ea4258c 100644
--- a/media/libaudiohal/impl/DeviceHalHidl.cpp
+++ b/media/libaudiohal/impl/DeviceHalHidl.cpp
@@ -752,10 +752,14 @@
// the attributes reported by `getParameters` API.
struct audio_port_v7 temp = *devicePort;
AudioProfileAttributesMultimap attrsFromDevice;
- status_t status = getAudioPort(&temp);
- if (status == NO_ERROR) {
- attrsFromDevice = createAudioProfilesAttrMap(temp.audio_profiles, 0 /*first*/,
- temp.num_audio_profiles);
+ bool supportsPatches;
+ if (supportsAudioPatches(&supportsPatches) == OK && supportsPatches) {
+ // The audio patches are supported since HAL 3.0, which is the same HAL version
+ // requirement for 'getAudioPort' API.
+ if (getAudioPort(&temp) == NO_ERROR) {
+ attrsFromDevice = createAudioProfilesAttrMap(temp.audio_profiles, 0 /*first*/,
+ temp.num_audio_profiles);
+ }
}
auto streamIt = mStreams.find(mixPort->ext.mix.handle);
if (streamIt == mStreams.end()) {
@@ -767,7 +771,7 @@
}
String8 formatsStr;
- status = getParametersFromStream(
+ status_t status = getParametersFromStream(
stream, AudioParameter::keyStreamSupportedFormats, nullptr /*extraParameters*/,
&formatsStr);
if (status != NO_ERROR) {
diff --git a/media/libaudiohal/impl/EffectConversionHelperAidl.cpp b/media/libaudiohal/impl/EffectConversionHelperAidl.cpp
index 882c550..ff6126d 100644
--- a/media/libaudiohal/impl/EffectConversionHelperAidl.cpp
+++ b/media/libaudiohal/impl/EffectConversionHelperAidl.cpp
@@ -181,7 +181,7 @@
State state;
RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getState(&state)));
if (state == State::INIT) {
- ALOGI("%s at state %s, opening effect with input %s output %s", __func__,
+ ALOGD("%s at state %s, opening effect with input %s output %s", __func__,
android::internal::ToString(state).c_str(), common.input.toString().c_str(),
common.output.toString().c_str());
IEffect::OpenEffectReturn openReturn;
@@ -189,7 +189,8 @@
statusTFromBinderStatus(mEffect->open(common, std::nullopt, &openReturn)));
updateMqsAndEventFlags(openReturn);
} else if (mCommon != common) {
- ALOGI("%s at state %s, setParameter", __func__, android::internal::ToString(state).c_str());
+ ALOGV("%s at state %s, setCommonParameter %s", __func__,
+ android::internal::ToString(state).c_str(), common.toString().c_str());
Parameter aidlParam = UNION_MAKE(Parameter, common, common);
RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->setParameter(aidlParam)));
}
@@ -398,12 +399,12 @@
effect_offload_param_t* offload = (effect_offload_param_t*)pCmdData;
// send to proxy to update active sub-effect
if (mIsProxyEffect) {
- ALOGI("%s offload param offload %s ioHandle %d", __func__,
+ ALOGV("%s offload param offload %s ioHandle %d", __func__,
offload->isOffload ? "true" : "false", offload->ioHandle);
const auto& effectProxy = std::static_pointer_cast<EffectProxy>(mEffect);
RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(effectProxy->setOffloadParam(offload)));
if (mCommon.ioHandle != offload->ioHandle) {
- ALOGI("%s ioHandle update [%d to %d]", __func__, mCommon.ioHandle, offload->ioHandle);
+ ALOGV("%s ioHandle update [%d to %d]", __func__, mCommon.ioHandle, offload->ioHandle);
mCommon.ioHandle = offload->ioHandle;
Parameter aidlParam = UNION_MAKE(Parameter, common, mCommon);
RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->setParameter(aidlParam)));
diff --git a/media/libaudiohal/impl/EffectHalAidl.cpp b/media/libaudiohal/impl/EffectHalAidl.cpp
index 7262148..87d24a5 100644
--- a/media/libaudiohal/impl/EffectHalAidl.cpp
+++ b/media/libaudiohal/impl/EffectHalAidl.cpp
@@ -198,7 +198,7 @@
::android::OK == efGroup->wait(kEventFlagDataMqUpdate, &efState,
1 /* ns */, true /* retry */) &&
efState & kEventFlagDataMqUpdate) {
- ALOGI("%s %s V%d receive dataMQUpdate eventFlag from HAL", __func__, effectName.c_str(),
+ ALOGV("%s %s V%d receive dataMQUpdate eventFlag from HAL", __func__, effectName.c_str(),
halVersion);
mConversion->reopen();
}
@@ -258,8 +258,6 @@
accumulate_float(mOutBuffer->audioBuffer()->f32, outputRawBuffer, floatsToRead);
}
- ALOGD("%s %s consumed %zu produced %zu", __func__, effectName.c_str(), floatsToWrite,
- floatsToRead);
return OK;
}
diff --git a/media/libaudiohal/impl/EffectProxy.cpp b/media/libaudiohal/impl/EffectProxy.cpp
index 9a8d96b..af0f8f2 100644
--- a/media/libaudiohal/impl/EffectProxy.cpp
+++ b/media/libaudiohal/impl/EffectProxy.cpp
@@ -147,7 +147,7 @@
// close all opened effects if failure
if (!status.isOk()) {
- ALOGE("%s: closing all sub-effects with error %s", __func__,
+ ALOGW("%s: closing all sub-effects with error %s", __func__,
status.getDescription().c_str());
close();
}
@@ -260,7 +260,7 @@
std::function<ndk::ScopedAStatus(const std::shared_ptr<IEffect>&)> const& func) {
ndk::ScopedAStatus status = runWithActiveSubEffect(func);
if (!status.isOk()) {
- ALOGE("%s active sub-effect return error %s", __func__, status.getDescription().c_str());
+ ALOGW("%s active sub-effect return error %s", __func__, status.getDescription().c_str());
}
// proceed with others
@@ -269,7 +269,7 @@
continue;
}
if (!mSubEffects[i].handle) {
- ALOGE("%s null sub-effect interface for %s", __func__,
+ ALOGW("%s null sub-effect interface for %s", __func__,
mSubEffects[i].descriptor.common.id.uuid.toString().c_str());
continue;
}
diff --git a/media/libaudiohal/impl/EffectsFactoryHalAidl.cpp b/media/libaudiohal/impl/EffectsFactoryHalAidl.cpp
index 7d807b2..424fdb7 100644
--- a/media/libaudiohal/impl/EffectsFactoryHalAidl.cpp
+++ b/media/libaudiohal/impl/EffectsFactoryHalAidl.cpp
@@ -120,8 +120,6 @@
}
*pNumEffects = mEffectCount;
- ALOGD("%s %u non %zu proxyMap %zu proxyDesc %zu", __func__, *pNumEffects,
- mNonProxyDescList.size(), mProxyUuidDescriptorMap.size(), mProxyDescList.size());
return OK;
}
@@ -178,7 +176,7 @@
if (sessionId == AUDIO_SESSION_DEVICE && ioId == AUDIO_IO_HANDLE_NONE) {
return INVALID_OPERATION;
}
- ALOGI("%s session %d ioId %d", __func__, sessionId, ioId);
+ ALOGV("%s session %d ioId %d", __func__, sessionId, ioId);
AudioUuid aidlUuid =
VALUE_OR_RETURN_STATUS(::aidl::android::legacy2aidl_audio_uuid_t_AudioUuid(*uuid));
@@ -218,13 +216,11 @@
}
status_t EffectsFactoryHalAidl::allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) {
- ALOGI("%s size %zu buffer %p", __func__, size, buffer);
return EffectBufferHalAidl::allocate(size, buffer);
}
status_t EffectsFactoryHalAidl::mirrorBuffer(void* external, size_t size,
sp<EffectBufferHalInterface>* buffer) {
- ALOGI("%s extern %p size %zu buffer %p", __func__, external, size, buffer);
return EffectBufferHalAidl::mirror(external, size, buffer);
}
@@ -245,7 +241,6 @@
ALOGE("%s UUID not found in HAL and proxy list %s", __func__, toString(uuid).c_str());
return NAME_NOT_FOUND;
}
- ALOGI("%s UUID impl found %s", __func__, toString(uuid).c_str());
*pDescriptor = VALUE_OR_RETURN_STATUS(
::aidl::android::aidl2legacy_Descriptor_effect_descriptor(*matchIt));
@@ -267,7 +262,6 @@
ALOGW("%s UUID type not found in HAL and proxy list %s", __func__, toString(type).c_str());
return BAD_VALUE;
}
- ALOGI("%s UUID type found %zu \n %s", __func__, result.size(), toString(type).c_str());
*descriptors = VALUE_OR_RETURN_STATUS(
aidl::android::convertContainer<std::vector<effect_descriptor_t>>(
diff --git a/media/libaudiohal/impl/Hal2AidlMapper.cpp b/media/libaudiohal/impl/Hal2AidlMapper.cpp
index 2b7f298..263e3e9 100644
--- a/media/libaudiohal/impl/Hal2AidlMapper.cpp
+++ b/media/libaudiohal/impl/Hal2AidlMapper.cpp
@@ -102,8 +102,8 @@
}
void Hal2AidlMapper::addStream(
- const sp<StreamHalInterface>& stream, int32_t portConfigId, int32_t patchId) {
- mStreams.insert(std::pair(stream, std::pair(portConfigId, patchId)));
+ const sp<StreamHalInterface>& stream, int32_t mixPortConfigId, int32_t patchId) {
+ mStreams.insert(std::pair(stream, std::pair(mixPortConfigId, patchId)));
}
bool Hal2AidlMapper::audioDeviceMatches(const AudioDevice& device, const AudioPort& p) {
@@ -450,7 +450,7 @@
*portConfig = it->second;
return OK;
}
- ALOGE("%s: could not find a configured device port for device %s",
+ ALOGE("%s: could not find a device port config for device %s",
__func__, device.toString().c_str());
return BAD_VALUE;
}
@@ -698,20 +698,23 @@
return OK;
}
-bool Hal2AidlMapper::isPortBeingHeld(int32_t portId) {
- // It is assumed that mStreams has already been cleaned up.
- for (const auto& s : mStreams) {
- if (portConfigBelongsToPort(s.second.first, portId)) return true;
- }
- for (const auto& [_, patch] : mPatches) {
+std::set<int32_t> Hal2AidlMapper::getPatchIdsByPortId(int32_t portId) {
+ std::set<int32_t> result;
+ for (const auto& [patchId, patch] : mPatches) {
for (int32_t id : patch.sourcePortConfigIds) {
- if (portConfigBelongsToPort(id, portId)) return true;
+ if (portConfigBelongsToPort(id, portId)) {
+ result.insert(patchId);
+ break;
+ }
}
for (int32_t id : patch.sinkPortConfigIds) {
- if (portConfigBelongsToPort(id, portId)) return true;
+ if (portConfigBelongsToPort(id, portId)) {
+ result.insert(patchId);
+ break;
+ }
}
}
- return false;
+ return result;
}
status_t Hal2AidlMapper::prepareToDisconnectExternalDevice(const AudioPort& devicePort) {
@@ -730,7 +733,7 @@
this, __func__, ioHandle, device.toString().c_str(),
flags.toString().c_str(), toString(source).c_str(),
config->toString().c_str(), mixPortConfig->toString().c_str());
- resetUnusedPatchesPortConfigsAndPorts();
+ resetUnusedPatchesAndPortConfigs();
const AudioConfig initialConfig = *config;
// Find / create AudioPortConfigs for the device port and the mix port,
// then find / create a patch between them, and open a stream on the mix port.
@@ -843,39 +846,52 @@
return releaseAudioPatches({patchId});
}
+// Note: does not reset port configs.
+status_t Hal2AidlMapper::releaseAudioPatch(Patches::iterator it) {
+ const int32_t patchId = it->first;
+ if (ndk::ScopedAStatus status = mModule->resetAudioPatch(patchId); !status.isOk()) {
+ ALOGE("%s: error while resetting patch %d: %s",
+ __func__, patchId, status.getDescription().c_str());
+ return statusTFromBinderStatus(status);
+ }
+ mPatches.erase(it);
+ for (auto it = mFwkPatches.begin(); it != mFwkPatches.end(); ++it) {
+ if (it->second == patchId) {
+ mFwkPatches.erase(it);
+ break;
+ }
+ }
+ return OK;
+}
+
status_t Hal2AidlMapper::releaseAudioPatches(const std::set<int32_t>& patchIds) {
status_t result = OK;
for (const auto patchId : patchIds) {
if (auto it = mPatches.find(patchId); it != mPatches.end()) {
- mPatches.erase(it);
- if (ndk::ScopedAStatus status = mModule->resetAudioPatch(patchId); !status.isOk()) {
- ALOGE("%s: error while resetting patch %d: %s",
- __func__, patchId, status.getDescription().c_str());
- result = statusTFromBinderStatus(status);
- }
+ releaseAudioPatch(it);
} else {
ALOGE("%s: patch id %d not found", __func__, patchId);
result = BAD_VALUE;
}
}
- resetUnusedPortConfigsAndPorts();
+ resetUnusedPortConfigs();
return result;
}
void Hal2AidlMapper::resetPortConfig(int32_t portConfigId) {
if (auto it = mPortConfigs.find(portConfigId); it != mPortConfigs.end()) {
- mPortConfigs.erase(it);
if (ndk::ScopedAStatus status = mModule->resetAudioPortConfig(portConfigId);
!status.isOk()) {
ALOGE("%s: error while resetting port config %d: %s",
__func__, portConfigId, status.getDescription().c_str());
}
+ mPortConfigs.erase(it);
return;
}
ALOGE("%s: port config id %d not found", __func__, portConfigId);
}
-void Hal2AidlMapper::resetUnusedPatchesPortConfigsAndPorts() {
+void Hal2AidlMapper::resetUnusedPatchesAndPortConfigs() {
// Since patches can be created independently of streams via 'createOrUpdatePatch',
// here we only clean up patches for released streams.
std::set<int32_t> patchesToRelease;
@@ -889,52 +905,35 @@
it = mStreams.erase(it);
}
}
- // 'releaseAudioPatches' also resets unused port configs and ports.
+ // 'releaseAudioPatches' also resets unused port configs.
releaseAudioPatches(patchesToRelease);
}
-void Hal2AidlMapper::resetUnusedPortConfigsAndPorts() {
+void Hal2AidlMapper::resetUnusedPortConfigs() {
// The assumption is that port configs are used to create patches
// (or to open streams, but that involves creation of patches, too). Thus,
// orphaned port configs can and should be reset.
- std::map<int32_t, int32_t /*portID*/> portConfigIds;
+ std::set<int32_t> portConfigIdsToReset;
std::transform(mPortConfigs.begin(), mPortConfigs.end(),
- std::inserter(portConfigIds, portConfigIds.end()),
- [](const auto& pcPair) { return std::make_pair(pcPair.first, pcPair.second.portId); });
+ std::inserter(portConfigIdsToReset, portConfigIdsToReset.end()),
+ [](const auto& pcPair) { return pcPair.first; });
for (const auto& p : mPatches) {
- for (int32_t id : p.second.sourcePortConfigIds) portConfigIds.erase(id);
- for (int32_t id : p.second.sinkPortConfigIds) portConfigIds.erase(id);
+ for (int32_t id : p.second.sourcePortConfigIds) portConfigIdsToReset.erase(id);
+ for (int32_t id : p.second.sinkPortConfigIds) portConfigIdsToReset.erase(id);
}
for (int32_t id : mInitialPortConfigIds) {
- portConfigIds.erase(id);
+ portConfigIdsToReset.erase(id);
}
for (const auto& s : mStreams) {
- portConfigIds.erase(s.second.first);
+ portConfigIdsToReset.erase(s.second.first);
}
- std::set<int32_t> retryDeviceDisconnection;
- for (const auto& portConfigAndIdPair : portConfigIds) {
- resetPortConfig(portConfigAndIdPair.first);
- if (const auto it = mConnectedPorts.find(portConfigAndIdPair.second);
- it != mConnectedPorts.end() && it->second) {
- retryDeviceDisconnection.insert(portConfigAndIdPair.second);
- }
- }
- for (int32_t portId : retryDeviceDisconnection) {
- if (!isPortBeingHeld(portId)) {
- if (auto status = mModule->disconnectExternalDevice(portId); status.isOk()) {
- eraseConnectedPort(portId);
- ALOGD("%s: executed postponed external device disconnection for port ID %d",
- __func__, portId);
- }
- }
- }
- if (!retryDeviceDisconnection.empty()) {
- updateRoutes();
+ for (const auto& portConfigId : portConfigIdsToReset) {
+ resetPortConfig(portConfigId);
}
}
status_t Hal2AidlMapper::setDevicePortConnectedState(const AudioPort& devicePort, bool connected) {
- resetUnusedPatchesPortConfigsAndPorts();
+ resetUnusedPatchesAndPortConfigs();
if (connected) {
AudioDevice matchDevice = devicePort.ext.get<AudioPortExt::device>().device;
std::optional<AudioPort> templatePort;
@@ -980,7 +979,7 @@
"%s: module %s, duplicate port ID received from HAL: %s, existing port: %s",
__func__, mInstance.c_str(), connectedPort.toString().c_str(),
it->second.toString().c_str());
- mConnectedPorts[connectedPort.id] = false;
+ mConnectedPorts.insert(connectedPort.id);
if (erasePortAfterConnectionIt != mPorts.end()) {
mPorts.erase(erasePortAfterConnectionIt);
}
@@ -1007,17 +1006,34 @@
port.ext.get<AudioPortExt::Tag::device>().device = matchDevice;
port.profiles = portsIt->second.profiles;
}
- // Streams are closed by AudioFlinger independently from device disconnections.
- // It is possible that the stream has not been closed yet.
- if (!isPortBeingHeld(portId)) {
- RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
- mModule->disconnectExternalDevice(portId)));
- eraseConnectedPort(portId);
- } else {
- ALOGD("%s: since device port ID %d is used by a stream, "
- "external device disconnection postponed", __func__, portId);
- mConnectedPorts[portId] = true;
+
+ // Patches may still exist, the framework may reset or update them later.
+ // For disconnection to succeed, need to release these patches first.
+ if (std::set<int32_t> patchIdsToRelease = getPatchIdsByPortId(portId);
+ !patchIdsToRelease.empty()) {
+ FwkPatches releasedPatches;
+ status_t status = OK;
+ for (int32_t patchId : patchIdsToRelease) {
+ if (auto it = mPatches.find(patchId); it != mPatches.end()) {
+ if (status = releaseAudioPatch(it); status != OK) break;
+ releasedPatches.insert(std::make_pair(patchId, patchId));
+ }
+ }
+ resetUnusedPortConfigs();
+ // Patches created by Hal2AidlMapper during stream creation and not "claimed"
+ // by the framework must not be surfaced to it.
+ for (auto& s : mStreams) {
+ if (auto it = releasedPatches.find(s.second.second); it != releasedPatches.end()) {
+ releasedPatches.erase(it);
+ }
+ }
+ mFwkPatches.merge(releasedPatches);
+ LOG_ALWAYS_FATAL_IF(!releasedPatches.empty(),
+ "mFwkPatches already contains some of released patches");
+ if (status != OK) return status;
}
+ RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mModule->disconnectExternalDevice(portId)));
+ eraseConnectedPort(portId);
}
return updateRoutes();
}
diff --git a/media/libaudiohal/impl/Hal2AidlMapper.h b/media/libaudiohal/impl/Hal2AidlMapper.h
index f937173..f302c23 100644
--- a/media/libaudiohal/impl/Hal2AidlMapper.h
+++ b/media/libaudiohal/impl/Hal2AidlMapper.h
@@ -49,7 +49,7 @@
const std::string& instance,
const std::shared_ptr<::aidl::android::hardware::audio::core::IModule>& module);
- void addStream(const sp<StreamHalInterface>& stream, int32_t portConfigId, int32_t patchId);
+ void addStream(const sp<StreamHalInterface>& stream, int32_t mixPortConfigId, int32_t patchId);
status_t createOrUpdatePatch(
const std::vector<::aidl::android::media::audio::common::AudioPortConfig>& sources,
const std::vector<::aidl::android::media::audio::common::AudioPortConfig>& sinks,
@@ -91,13 +91,32 @@
::aidl::android::media::audio::common::AudioPortConfig* portConfig,
Cleanups* cleanups = nullptr);
status_t releaseAudioPatch(int32_t patchId);
- void resetUnusedPatchesPortConfigsAndPorts();
+ void resetUnusedPatchesAndPortConfigs();
status_t setDevicePortConnectedState(
const ::aidl::android::media::audio::common::AudioPort& devicePort, bool connected);
+ // Methods to work with FwkPatches.
+ void eraseFwkPatch(int32_t fwkPatchId) { mFwkPatches.erase(fwkPatchId); }
+ int32_t findFwkPatch(int32_t fwkPatchId) {
+ const auto it = mFwkPatches.find(fwkPatchId);
+ return it != mFwkPatches.end() ? it->second : 0;
+ }
+ void updateFwkPatch(int32_t fwkPatchId, int32_t halPatchId) {
+ mFwkPatches[fwkPatchId] = halPatchId;
+ }
+
private:
- // IDs of ports for connected external devices, and whether they are held by streams.
- using ConnectedPorts = std::map<int32_t /*port ID*/, bool>;
+ // 'FwkPatches' is used to store patches that diverge from the framework's state.
+ // Uses framework patch ID (aka audio_patch_handle_t) values for indexing.
+ // When the 'key == value', that means Hal2AidlMapper has removed this patch, and it is absent
+ // from 'mPatches', but it still "exists" for the framework. It will either remove it or
+ // re-patch. If the framework re-patches, it will continue to use the same patch handle,
+ // but the HAL will use the new one (since the old patch was reset), thus 'key != value'
+ // for such patches. Since they "exist" both for the framework and the HAL, 'mPatches'
+ // contains their data under HAL patch ID ('value' of 'FwkPatches').
+ // To avoid confusion, all patchIDs used by Hal2AidlMapper are HAL IDs. Mapping between
+ // framework patch IDs and HAL patch IDs is done by DeviceHalAidl.
+ using FwkPatches = std::map<int32_t /*audio_patch_handle_t*/, int32_t /*patch ID*/>;
using Patches = std::map<int32_t /*patch ID*/,
::aidl::android::hardware::audio::core::AudioPatch>;
using PortConfigs = std::map<int32_t /*port config ID*/,
@@ -107,12 +126,12 @@
// Answers the question "whether portID 'first' is reachable from portID 'second'?"
// It's not a map because both portIDs are known. The matrix is symmetric.
using RoutingMatrix = std::set<std::pair<int32_t, int32_t>>;
- // There is always a port config ID set. The patch ID is set after stream
+ // There is always a mix port config ID set. The patch ID is set after stream
// creation, and can be set to '-1' later if the framework happens to create
// a patch between the same endpoints. In that case, the ownership of the patch
// is on the framework.
using Streams = std::map<wp<StreamHalInterface>,
- std::pair<int32_t /*port config ID*/, int32_t /*patch ID*/>>;
+ std::pair<int32_t /*mix port config ID*/, int32_t /*patch ID*/>>;
const std::string mInstance;
const std::shared_ptr<::aidl::android::hardware::audio::core::IModule> mModule;
@@ -168,7 +187,7 @@
const std::optional<::aidl::android::media::audio::common::AudioConfig>& config,
const std::optional<::aidl::android::media::audio::common::AudioIoFlags>& flags,
int32_t ioHandle);
- bool isPortBeingHeld(int32_t portId);
+ std::set<int32_t> getPatchIdsByPortId(int32_t portId);
status_t prepareToOpenStreamHelper(
int32_t ioHandle, int32_t devicePortId, int32_t devicePortConfigId,
const ::aidl::android::media::audio::common::AudioIoFlags& flags,
@@ -181,10 +200,11 @@
auto it = mPortConfigs.find(portConfigId);
return it != mPortConfigs.end() && it->second.portId == portId;
}
+ status_t releaseAudioPatch(Patches::iterator it);
status_t releaseAudioPatches(const std::set<int32_t>& patchIds);
void resetPatch(int32_t patchId) { (void)releaseAudioPatch(patchId); }
void resetPortConfig(int32_t portConfigId);
- void resetUnusedPortConfigsAndPorts();
+ void resetUnusedPortConfigs();
status_t updateAudioPort(
int32_t portId, ::aidl::android::media::audio::common::AudioPort* port);
status_t updateRoutes();
@@ -197,13 +217,14 @@
std::optional<::aidl::android::media::audio::common::AudioPort> mRemoteSubmixOut;
int32_t mDefaultInputPortId = -1;
int32_t mDefaultOutputPortId = -1;
+ FwkPatches mFwkPatches;
PortConfigs mPortConfigs;
std::set<int32_t> mInitialPortConfigIds;
Patches mPatches;
Routes mRoutes;
RoutingMatrix mRoutingMatrix;
Streams mStreams;
- ConnectedPorts mConnectedPorts;
+ std::set<int32_t> mConnectedPorts;
std::pair<int32_t, ::aidl::android::media::audio::common::AudioPort>
mDisconnectedPortReplacement;
std::set<int32_t> mDynamicMixPortIds;
diff --git a/media/libaudiohal/impl/effectsAidlConversion/AidlConversionPresetReverb.cpp b/media/libaudiohal/impl/effectsAidlConversion/AidlConversionPresetReverb.cpp
index 3cac591..642c370 100644
--- a/media/libaudiohal/impl/effectsAidlConversion/AidlConversionPresetReverb.cpp
+++ b/media/libaudiohal/impl/effectsAidlConversion/AidlConversionPresetReverb.cpp
@@ -71,7 +71,6 @@
status_t AidlConversionPresetReverb::getParameter(EffectParamWriter& param) {
uint32_t type = 0;
uint16_t value = 0;
- ALOGE("%s enter %s", __func__, param.toString().c_str());
if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
OK != param.readFromParameter(&type)) {
ALOGE("%s invalid param %s", __func__, param.toString().c_str());
diff --git a/media/libaudiohal/impl/effectsAidlConversion/AidlConversionSpatializer.cpp b/media/libaudiohal/impl/effectsAidlConversion/AidlConversionSpatializer.cpp
index d1794f0..da28204 100644
--- a/media/libaudiohal/impl/effectsAidlConversion/AidlConversionSpatializer.cpp
+++ b/media/libaudiohal/impl/effectsAidlConversion/AidlConversionSpatializer.cpp
@@ -142,10 +142,8 @@
toString(mode).c_str());
return status;
}
- ALOGI("%s %d: %s", __func__, __LINE__, aidlParam.toString().c_str());
aidlParam = MAKE_SPECIFIC_PARAMETER(Spatializer, spatializer, headTrackingSensorId,
sensorId);
- ALOGI("%s %d: %s", __func__, __LINE__, aidlParam.toString().c_str());
return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
}
default: {
@@ -158,7 +156,6 @@
::aidl::android::legacy2aidl_EffectParameterReader_Parameter(param));
}
- ALOGI("%s %d: %s", __func__, __LINE__, aidlParam.toString().c_str());
return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
}
@@ -183,7 +180,7 @@
Spatializer::make<Spatializer::spatializationLevel>(level);
if (spatializer >= range->min && spatializer <= range->max) {
if (status_t status = param.writeToValue(&level); status != OK) {
- ALOGI("%s %d: write level %s to value failed %d", __func__, __LINE__,
+ ALOGW("%s %d: write level %s to value failed %d", __func__, __LINE__,
toString(level).c_str(), status);
return status;
}
@@ -200,7 +197,6 @@
const auto level = VALUE_OR_RETURN_STATUS(GET_PARAMETER_SPECIFIC_FIELD(
aidlParam, Spatializer, spatializer, Spatializer::spatializationLevel,
Spatialization::Level));
- ALOGI("%s %d: %s", __func__, __LINE__, aidlParam.toString().c_str());
return param.writeToValue(&level);
}
case SPATIALIZER_PARAM_HEADTRACKING_SUPPORTED: {
@@ -227,7 +223,6 @@
const auto mode = VALUE_OR_RETURN_STATUS(GET_PARAMETER_SPECIFIC_FIELD(
aidlParam, Spatializer, spatializer, Spatializer::headTrackingMode,
HeadTracking::Mode));
- ALOGI("%s %d: %s", __func__, __LINE__, aidlParam.toString().c_str());
return param.writeToValue(&mode);
}
case SPATIALIZER_PARAM_SUPPORTED_CHANNEL_MASKS: {
@@ -244,12 +239,11 @@
::aidl::android::aidl2legacy_AudioChannelLayout_audio_channel_mask_t(
layout, false /* isInput */));
if (status_t status = param.writeToValue(&mask); status != OK) {
- ALOGI("%s %d: write mask %s to value failed %d", __func__, __LINE__,
+ ALOGW("%s %d: write mask %s to value failed %d", __func__, __LINE__,
layout.toString().c_str(), status);
return status;
}
}
- ALOGI("%s %d: %s", __func__, __LINE__, aidlParam.toString().c_str());
return OK;
}
case SPATIALIZER_PARAM_SUPPORTED_SPATIALIZATION_MODES: {
@@ -263,7 +257,7 @@
Spatializer::make<Spatializer::spatializationMode>(mode);
spatializer >= range->min && spatializer <= range->max) {
if (status_t status = param.writeToValue(&mode); status != OK) {
- ALOGI("%s %d: write mode %s to value failed %d", __func__, __LINE__,
+ ALOGW("%s %d: write mode %s to value failed %d", __func__, __LINE__,
toString(mode).c_str(), status);
return status;
}
@@ -284,8 +278,8 @@
continue;
}
if (status_t status = param.writeToValue(&mode); status != OK) {
- ALOGI("%s %d: write mode %s to value failed %d", __func__, __LINE__,
- toString(mode).c_str(), status);
+ ALOGW("%s %d: write mode %s to value failed %d", __func__, __LINE__,
+ toString(mode).c_str(), status);
return status;
}
}
@@ -311,16 +305,15 @@
Spatializer::headTrackingSensorId, int32_t));
uint32_t modeInt32 = static_cast<int32_t>(mode);
if (status = param.writeToValue(&modeInt32); status != OK) {
- ALOGI("%s %d: write mode %s to value failed %d", __func__, __LINE__,
+ ALOGW("%s %d: write mode %s to value failed %d", __func__, __LINE__,
toString(mode).c_str(), status);
return status;
}
if (status = param.writeToValue(&sensorId); status != OK) {
- ALOGI("%s %d: write sensorId %d to value failed %d", __func__, __LINE__,
+ ALOGW("%s %d: write sensorId %d to value failed %d", __func__, __LINE__,
sensorId, status);
return status;
}
- ALOGI("%s %d: %s", __func__, __LINE__, aidlParam.toString().c_str());
return OK;
}
default: {
@@ -343,8 +336,6 @@
idTag.extension.setParcelable(defaultExt);
Parameter::Id id = UNION_MAKE(Parameter::Id, vendorEffectTag, idTag);
RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
- ALOGI("%s %d: %s", __func__, __LINE__,
- aidlParam.get<Parameter::specific>().toString().c_str());
// copy the AIDL extension data back to effect_param_t
return VALUE_OR_RETURN_STATUS(
::aidl::android::aidl2legacy_Parameter_EffectParameterWriter(aidlParam, param));
diff --git a/media/libaudiohal/impl/effectsAidlConversion/AidlConversionVirtualizer.cpp b/media/libaudiohal/impl/effectsAidlConversion/AidlConversionVirtualizer.cpp
index cad0068..db5cb9a 100644
--- a/media/libaudiohal/impl/effectsAidlConversion/AidlConversionVirtualizer.cpp
+++ b/media/libaudiohal/impl/effectsAidlConversion/AidlConversionVirtualizer.cpp
@@ -133,7 +133,6 @@
const audio_channel_mask_t chMask = ::aidl::android::
aidl2legacy_AudioChannelLayout_layout_audio_channel_mask_t_bits(
angle.channel, false);
- ALOGW("%s aidl %d ch %d", __func__, angle.channel, chMask);
if (OK != param.writeToValue(&chMask) ||
OK != param.writeToValue(&angle.azimuthDegree) ||
OK != param.writeToValue(&angle.elevationDegree)) {
diff --git a/media/libaudiohal/tests/Android.bp b/media/libaudiohal/tests/Android.bp
index b9af0bf..f6a7eea 100644
--- a/media/libaudiohal/tests/Android.bp
+++ b/media/libaudiohal/tests/Android.bp
@@ -25,8 +25,8 @@
name: "libaudiohal_aidl_test_default",
test_suites: ["device-tests"],
defaults: [
- "libaudiohal_default",
"libaudiohal_aidl_default",
+ "libaudiohal_default",
],
shared_libs: [
"libaudiohal",
@@ -36,8 +36,8 @@
cc_test {
name: "CoreAudioHalAidlTest",
srcs: [
- "CoreAudioHalAidl_test.cpp",
":core_audio_hal_aidl_src_files",
+ "CoreAudioHalAidl_test.cpp",
],
defaults: ["libaudiohal_aidl_test_default"],
header_libs: ["libaudiohalimpl_headers"],
@@ -56,8 +56,8 @@
cc_test {
name: "EffectProxyTest",
srcs: [
- "EffectProxy_test.cpp",
":audio_effectproxy_src_files",
+ "EffectProxy_test.cpp",
],
defaults: [
"libaudiohal_aidl_test_default",
@@ -69,8 +69,8 @@
cc_test {
name: "EffectHalVersionCompatibilityTest",
srcs: [
- "EffectHalVersionCompatibility_test.cpp",
":audio_effect_hal_aidl_src_files",
+ "EffectHalVersionCompatibility_test.cpp",
],
defaults: ["libaudiohal_aidl_test_default"],
header_libs: ["libaudiohalimpl_headers"],
diff --git a/media/libaudiohal/tests/CoreAudioHalAidl_test.cpp b/media/libaudiohal/tests/CoreAudioHalAidl_test.cpp
index 3541078..5106874 100644
--- a/media/libaudiohal/tests/CoreAudioHalAidl_test.cpp
+++ b/media/libaudiohal/tests/CoreAudioHalAidl_test.cpp
@@ -14,7 +14,9 @@
* limitations under the License.
*/
+#include <algorithm>
#include <memory>
+#include <mutex>
#include <string>
#include <vector>
@@ -22,6 +24,7 @@
#include <gtest/gtest.h>
#include <DeviceHalAidl.h>
+#include <Hal2AidlMapper.h>
#include <StreamHalAidl.h>
#include <aidl/android/hardware/audio/core/BnModule.h>
#include <aidl/android/hardware/audio/core/BnStreamCommon.h>
@@ -31,7 +34,24 @@
namespace {
+using ::aidl::android::hardware::audio::core::AudioPatch;
+using ::aidl::android::hardware::audio::core::AudioRoute;
using ::aidl::android::hardware::audio::core::VendorParameter;
+using ::aidl::android::media::audio::common::AudioChannelLayout;
+using ::aidl::android::media::audio::common::AudioConfig;
+using ::aidl::android::media::audio::common::AudioDeviceDescription;
+using ::aidl::android::media::audio::common::AudioDeviceType;
+using ::aidl::android::media::audio::common::AudioFormatDescription;
+using ::aidl::android::media::audio::common::AudioFormatType;
+using ::aidl::android::media::audio::common::AudioIoFlags;
+using ::aidl::android::media::audio::common::AudioPort;
+using ::aidl::android::media::audio::common::AudioPortConfig;
+using ::aidl::android::media::audio::common::AudioPortDeviceExt;
+using ::aidl::android::media::audio::common::AudioPortExt;
+using ::aidl::android::media::audio::common::AudioPortMixExt;
+using ::aidl::android::media::audio::common::AudioProfile;
+using ::aidl::android::media::audio::common::AudioSource;
+using ::aidl::android::media::audio::common::PcmType;
class VendorParameterMock {
public:
@@ -63,9 +83,105 @@
std::vector<VendorParameter> mSyncParameters;
};
+struct Configuration {
+ std::vector<AudioPort> ports;
+ std::vector<AudioPortConfig> portConfigs;
+ std::vector<AudioRoute> routes;
+ std::vector<AudioPatch> patches;
+ int32_t nextPortId = 1;
+ int32_t nextPatchId = 1;
+};
+
+void fillProfile(AudioProfile* profile, const std::vector<int32_t>& channelLayouts,
+ const std::vector<int32_t>& sampleRates) {
+ for (auto layout : channelLayouts) {
+ profile->channelMasks.push_back(
+ AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layout));
+ }
+ profile->sampleRates.insert(profile->sampleRates.end(), sampleRates.begin(), sampleRates.end());
+}
+
+AudioProfile createProfile(PcmType pcmType, const std::vector<int32_t>& channelLayouts,
+ const std::vector<int32_t>& sampleRates) {
+ AudioProfile profile;
+ profile.format.type = AudioFormatType::PCM;
+ profile.format.pcm = pcmType;
+ fillProfile(&profile, channelLayouts, sampleRates);
+ return profile;
+}
+
+AudioPortExt createPortDeviceExt(AudioDeviceType devType, int32_t flags,
+ std::string connection = "") {
+ AudioPortDeviceExt deviceExt;
+ deviceExt.device.type.type = devType;
+ if (devType == AudioDeviceType::IN_MICROPHONE && connection.empty()) {
+ deviceExt.device.address = "bottom";
+ } else if (devType == AudioDeviceType::IN_MICROPHONE_BACK && connection.empty()) {
+ deviceExt.device.address = "back";
+ }
+ deviceExt.device.type.connection = std::move(connection);
+ deviceExt.flags = flags;
+ return AudioPortExt::make<AudioPortExt::device>(deviceExt);
+}
+
+AudioPortExt createPortMixExt(int32_t maxOpenStreamCount, int32_t maxActiveStreamCount) {
+ AudioPortMixExt mixExt;
+ mixExt.maxOpenStreamCount = maxOpenStreamCount;
+ mixExt.maxActiveStreamCount = maxActiveStreamCount;
+ return AudioPortExt::make<AudioPortExt::mix>(mixExt);
+}
+
+AudioPort createPort(int32_t id, const std::string& name, int32_t flags, bool isInput,
+ const AudioPortExt& ext) {
+ AudioPort port;
+ port.id = id;
+ port.name = name;
+ port.flags = isInput ? AudioIoFlags::make<AudioIoFlags::input>(flags)
+ : AudioIoFlags::make<AudioIoFlags::output>(flags);
+ port.ext = ext;
+ return port;
+}
+
+AudioRoute createRoute(const std::vector<AudioPort>& sources, const AudioPort& sink) {
+ AudioRoute route;
+ route.sinkPortId = sink.id;
+ std::transform(sources.begin(), sources.end(), std::back_inserter(route.sourcePortIds),
+ [](const auto& port) { return port.id; });
+ return route;
+}
+
+template <typename T>
+auto findById(std::vector<T>& v, int32_t id) {
+ return std::find_if(v.begin(), v.end(), [&](const auto& e) { return e.id == id; });
+}
+
+Configuration getTestConfiguration() {
+ const std::vector<AudioProfile> standardPcmAudioProfiles = {
+ createProfile(PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {48000})};
+ Configuration c;
+
+ AudioPort btOutDevice =
+ createPort(c.nextPortId++, "BT A2DP Out", 0, false,
+ createPortDeviceExt(AudioDeviceType::OUT_DEVICE, 0,
+ AudioDeviceDescription::CONNECTION_BT_A2DP));
+ btOutDevice.profiles = standardPcmAudioProfiles;
+ c.ports.push_back(btOutDevice);
+
+ AudioPort btOutMix =
+ createPort(c.nextPortId++, "a2dp output", 0, false, createPortMixExt(1, 1));
+ btOutMix.profiles = standardPcmAudioProfiles;
+ c.ports.push_back(btOutMix);
+
+ c.routes.push_back(createRoute({btOutMix}, btOutDevice));
+
+ return c;
+}
+
class ModuleMock : public ::aidl::android::hardware::audio::core::BnModule,
public VendorParameterMock {
public:
+ ModuleMock() = default;
+ explicit ModuleMock(const Configuration& config) : mConfig(config) {}
bool isScreenTurnedOn() const { return mIsScreenTurnedOn; }
ScreenRotation getScreenRotation() const { return mScreenRotation; }
@@ -91,35 +207,91 @@
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus connectExternalDevice(
- const ::aidl::android::media::audio::common::AudioPort&,
- ::aidl::android::media::audio::common::AudioPort*) override {
+ const ::aidl::android::media::audio::common::AudioPort& portIdAndData,
+ ::aidl::android::media::audio::common::AudioPort* port) override {
+ auto src = portIdAndData; // Make a copy to mimic RPC behavior.
+ auto iter = findById<AudioPort>(mConfig.ports, src.id);
+ if (iter == mConfig.ports.end()) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ *port = *iter;
+ port->ext = src.ext;
+ port->id = mConfig.nextPortId++;
+ ALOGD("%s: returning %s", __func__, port->toString().c_str());
+ mConfig.ports.push_back(*port);
+ std::vector<AudioRoute> newRoutes;
+ for (auto& r : mConfig.routes) {
+ if (r.sinkPortId == src.id) {
+ newRoutes.push_back(AudioRoute{.sourcePortIds = r.sourcePortIds,
+ .sinkPortId = port->id,
+ .isExclusive = r.isExclusive});
+ } else if (std::find(r.sourcePortIds.begin(), r.sourcePortIds.end(), src.id) !=
+ r.sourcePortIds.end()) {
+ r.sourcePortIds.push_back(port->id);
+ }
+ }
+ mConfig.routes.insert(mConfig.routes.end(), newRoutes.begin(), newRoutes.end());
return ndk::ScopedAStatus::ok();
}
- ndk::ScopedAStatus disconnectExternalDevice(int32_t) override {
+ ndk::ScopedAStatus disconnectExternalDevice(int32_t portId) override {
+ auto iter = findById<AudioPort>(mConfig.ports, portId);
+ if (iter == mConfig.ports.end()) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ mConfig.ports.erase(iter);
+ for (auto it = mConfig.routes.begin(); it != mConfig.routes.end();) {
+ if (it->sinkPortId == portId) {
+ it = mConfig.routes.erase(it);
+ } else {
+ if (auto srcIt =
+ std::find(it->sourcePortIds.begin(), it->sourcePortIds.end(), portId);
+ srcIt != it->sourcePortIds.end()) {
+ it->sourcePortIds.erase(srcIt);
+ }
+ ++it;
+ }
+ }
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus getAudioPatches(
- std::vector<::aidl::android::hardware::audio::core::AudioPatch>*) override {
+ std::vector<::aidl::android::hardware::audio::core::AudioPatch>* patches) override {
+ *patches = mConfig.patches;
return ndk::ScopedAStatus::ok();
}
- ndk::ScopedAStatus getAudioPort(int32_t,
- ::aidl::android::media::audio::common::AudioPort*) override {
+ ndk::ScopedAStatus getAudioPort(
+ int32_t portId, ::aidl::android::media::audio::common::AudioPort* port) override {
+ auto iter = findById<AudioPort>(mConfig.ports, portId);
+ if (iter == mConfig.ports.end()) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ *port = *iter;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus getAudioPortConfigs(
- std::vector<::aidl::android::media::audio::common::AudioPortConfig>*) override {
+ std::vector<::aidl::android::media::audio::common::AudioPortConfig>* configs) override {
+ *configs = mConfig.portConfigs;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus getAudioPorts(
- std::vector<::aidl::android::media::audio::common::AudioPort>*) override {
+ std::vector<::aidl::android::media::audio::common::AudioPort>* ports) override {
+ *ports = mConfig.ports;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus getAudioRoutes(
- std::vector<::aidl::android::hardware::audio::core::AudioRoute>*) override {
+ std::vector<::aidl::android::hardware::audio::core::AudioRoute>* routes) override {
+ *routes = mConfig.routes;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus getAudioRoutesForAudioPort(
- int32_t, std::vector<::aidl::android::hardware::audio::core::AudioRoute>*) override {
+ int32_t portId,
+ std::vector<::aidl::android::hardware::audio::core::AudioRoute>* routes) override {
+ for (auto& r : mConfig.routes) {
+ const auto& srcs = r.sourcePortIds;
+ if (r.sinkPortId == portId ||
+ std::find(srcs.begin(), srcs.end(), portId) != srcs.end()) {
+ routes->push_back(r);
+ }
+ }
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus openInputStream(const OpenInputStreamArguments&,
@@ -133,17 +305,69 @@
ndk::ScopedAStatus getSupportedPlaybackRateFactors(SupportedPlaybackRateFactors*) override {
return ndk::ScopedAStatus::ok();
}
- ndk::ScopedAStatus setAudioPatch(const ::aidl::android::hardware::audio::core::AudioPatch&,
- ::aidl::android::hardware::audio::core::AudioPatch*) override {
+ ndk::ScopedAStatus setAudioPatch(
+ const ::aidl::android::hardware::audio::core::AudioPatch& requested,
+ ::aidl::android::hardware::audio::core::AudioPatch* patch) override {
+ if (requested.id == 0) {
+ *patch = requested;
+ patch->id = mConfig.nextPatchId++;
+ mConfig.patches.push_back(*patch);
+ ALOGD("%s: returning %s", __func__, patch->toString().c_str());
+ } else {
+ auto iter = findById<AudioPatch>(mConfig.patches, requested.id);
+ if (iter == mConfig.patches.end()) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ *iter = *patch = requested;
+ ALOGD("%s: updated %s", __func__, patch->toString().c_str());
+ }
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus setAudioPortConfig(
- const ::aidl::android::media::audio::common::AudioPortConfig&,
- ::aidl::android::media::audio::common::AudioPortConfig*, bool*) override {
+ const ::aidl::android::media::audio::common::AudioPortConfig& requested,
+ ::aidl::android::media::audio::common::AudioPortConfig* config,
+ bool* applied) override {
+ *applied = false;
+ auto src = requested; // Make a copy to mimic RPC behavior.
+ if (src.id == 0) {
+ *config = src;
+ if (config->ext.getTag() == AudioPortExt::unspecified) {
+ auto iter = findById<AudioPort>(mConfig.ports, src.portId);
+ if (iter == mConfig.ports.end()) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ config->ext = iter->ext;
+ }
+ config->id = mConfig.nextPortId++;
+ mConfig.portConfigs.push_back(*config);
+ ALOGD("%s: returning %s", __func__, config->toString().c_str());
+ } else {
+ auto iter = findById<AudioPortConfig>(mConfig.portConfigs, src.id);
+ if (iter == mConfig.portConfigs.end()) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ *iter = *config = src;
+ ALOGD("%s: updated %s", __func__, config->toString().c_str());
+ }
+ *applied = true;
return ndk::ScopedAStatus::ok();
}
- ndk::ScopedAStatus resetAudioPatch(int32_t) override { return ndk::ScopedAStatus::ok(); }
- ndk::ScopedAStatus resetAudioPortConfig(int32_t) override { return ndk::ScopedAStatus::ok(); }
+ ndk::ScopedAStatus resetAudioPatch(int32_t patchId) override {
+ auto iter = findById<AudioPatch>(mConfig.patches, patchId);
+ if (iter == mConfig.patches.end()) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ mConfig.patches.erase(iter);
+ return ndk::ScopedAStatus::ok();
+ }
+ ndk::ScopedAStatus resetAudioPortConfig(int32_t portConfigId) override {
+ auto iter = findById<AudioPortConfig>(mConfig.portConfigs, portConfigId);
+ if (iter == mConfig.portConfigs.end()) {
+ return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+ }
+ mConfig.portConfigs.erase(iter);
+ return ndk::ScopedAStatus::ok();
+ }
ndk::ScopedAStatus getMasterMute(bool*) override { return ndk::ScopedAStatus::ok(); }
ndk::ScopedAStatus setMasterMute(bool) override { return ndk::ScopedAStatus::ok(); }
ndk::ScopedAStatus getMasterVolume(float*) override { return ndk::ScopedAStatus::ok(); }
@@ -205,6 +429,7 @@
return ndk::ScopedAStatus::ok();
}
+ Configuration mConfig;
bool mIsScreenTurnedOn = false;
ScreenRotation mScreenRotation = ScreenRotation::DEG_0;
};
@@ -398,6 +623,35 @@
using namespace android;
+namespace {
+
+class StreamHalMock : public virtual StreamHalInterface {
+ public:
+ StreamHalMock() = default;
+ ~StreamHalMock() override = default;
+ status_t getBufferSize(size_t*) override { return OK; }
+ status_t getAudioProperties(audio_config_base_t*) override { return OK; }
+ status_t setParameters(const String8&) override { return OK; }
+ status_t getParameters(const String8&, String8*) override { return OK; }
+ status_t getFrameSize(size_t*) override { return OK; }
+ status_t addEffect(sp<EffectHalInterface>) override { return OK; }
+ status_t removeEffect(sp<EffectHalInterface>) override { return OK; }
+ status_t standby() override { return OK; }
+ status_t dump(int, const Vector<String16>&) override { return OK; }
+ status_t start() override { return OK; }
+ status_t stop() override { return OK; }
+ status_t createMmapBuffer(int32_t, struct audio_mmap_buffer_info*) override { return OK; }
+ status_t getMmapPosition(struct audio_mmap_position*) override { return OK; }
+ status_t setHalThreadPriority(int) override { return OK; }
+ status_t legacyCreateAudioPatch(const struct audio_port_config&, std::optional<audio_source_t>,
+ audio_devices_t) override {
+ return OK;
+ }
+ status_t legacyReleaseAudioPatch() override { return OK; }
+};
+
+} // namespace
+
class DeviceHalAidlTest : public testing::Test {
public:
void SetUp() override {
@@ -593,3 +847,297 @@
EXPECT_EQ(0UL, mStreamCommon->getAsyncParameters().size());
EXPECT_EQ(0UL, mStreamCommon->getSyncParameters().size());
}
+
+class Hal2AidlMapperTest : public testing::Test {
+ public:
+ void SetUp() override {
+ mModule = ndk::SharedRefBase::make<ModuleMock>(getTestConfiguration());
+ mMapper = std::make_unique<Hal2AidlMapper>("test", mModule);
+ ASSERT_EQ(OK, mMapper->initialize());
+
+ mConnectedPort.ext = createPortDeviceExt(AudioDeviceType::OUT_DEVICE, 0,
+ AudioDeviceDescription::CONNECTION_BT_A2DP);
+ mConnectedPort.ext.get<AudioPortExt::device>().device.address = "00:11:22:33:44:55";
+ ASSERT_EQ(OK, mMapper->setDevicePortConnectedState(mConnectedPort, true /*connected*/));
+
+ std::mutex mutex; // Only needed for cleanups.
+ auto mapperAccessor = std::make_unique<LockedAccessor<Hal2AidlMapper>>(*mMapper, mutex);
+ Hal2AidlMapper::Cleanups cleanups(*mapperAccessor);
+ AudioConfig config;
+ config.base.channelMask = AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
+ AudioChannelLayout::LAYOUT_STEREO);
+ config.base.format =
+ AudioFormatDescription{.type = AudioFormatType::PCM, .pcm = PcmType::INT_16_BIT};
+ config.base.sampleRate = 48000;
+ ASSERT_EQ(OK,
+ mMapper->prepareToOpenStream(
+ 42 /*ioHandle*/, mConnectedPort.ext.get<AudioPortExt::device>().device,
+ AudioIoFlags::make<AudioIoFlags::output>(0), AudioSource::DEFAULT,
+ &cleanups, &config, &mMixPortConfig, &mPatch));
+ cleanups.disarmAll();
+ ASSERT_NE(0, mPatch.id);
+ ASSERT_NE(0, mMixPortConfig.id);
+ mStream = sp<StreamHalMock>::make();
+ mMapper->addStream(mStream, mMixPortConfig.id, mPatch.id);
+
+ ASSERT_EQ(OK, mMapper->findPortConfig(mConnectedPort.ext.get<AudioPortExt::device>().device,
+ &mDevicePortConfig));
+ ASSERT_EQ(1UL, mPatch.sourcePortConfigIds.size());
+ ASSERT_EQ(mMixPortConfig.id, mPatch.sourcePortConfigIds[0]);
+ ASSERT_EQ(1UL, mPatch.sinkPortConfigIds.size());
+ ASSERT_EQ(mDevicePortConfig.id, mPatch.sinkPortConfigIds[0]);
+ }
+
+ void TearDown() override {
+ mStream.clear();
+ mMapper.reset();
+ mModule.reset();
+ }
+
+ protected:
+ void CloseDisconnectImpl() {
+ mStream.clear();
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ }
+
+ void ConnectAnotherDevice() {
+ mConnectedPort.ext.get<AudioPortExt::device>().device.address = "00:11:22:33:44:66";
+ ASSERT_EQ(OK, mMapper->setDevicePortConnectedState(mConnectedPort, true /*connected*/));
+ }
+
+ void CreateFwkPatch(int32_t* patchId) {
+ std::mutex mutex; // Only needed for cleanups.
+ auto mapperAccessor = std::make_unique<LockedAccessor<Hal2AidlMapper>>(*mMapper, mutex);
+ Hal2AidlMapper::Cleanups cleanups(*mapperAccessor);
+ ASSERT_EQ(OK, mMapper->createOrUpdatePatch({mMixPortConfig}, {mDevicePortConfig}, patchId,
+ &cleanups));
+ cleanups.disarmAll();
+ }
+
+ void DisconnectDevice() {
+ ASSERT_EQ(OK, mMapper->prepareToDisconnectExternalDevice(mConnectedPort));
+ ASSERT_EQ(OK, mMapper->setDevicePortConnectedState(mConnectedPort, false /*connected*/));
+ }
+
+ void ReleaseFwkOnlyPatch(int32_t patchId) {
+ // The patch only exists for the framework.
+ EXPECT_EQ(patchId, mMapper->findFwkPatch(patchId));
+ ASSERT_EQ(BAD_VALUE, mMapper->releaseAudioPatch(patchId));
+ mMapper->eraseFwkPatch(patchId);
+ // The patch is now erased.
+ EXPECT_EQ(0, mMapper->findFwkPatch(patchId));
+ }
+
+ std::shared_ptr<ModuleMock> mModule;
+ std::unique_ptr<Hal2AidlMapper> mMapper;
+ AudioPort mConnectedPort;
+ AudioPortConfig mMixPortConfig;
+ AudioPortConfig mDevicePortConfig;
+ AudioPatch mPatch;
+ sp<StreamHalInterface> mStream;
+};
+
+/**
+ * External device connections and patches tests diagram.
+ *
+ * [Connect device] -> [Create Stream]
+ * |-> [ (1) Close Stream] -> [Disconnect Device]
+ * |-> [ (2) Disconnect Device]
+ * | |-> [ (3) Close Stream]
+ * | \-> [ (4) Connect Another Device]
+ * | |-> (1)
+ * | |-> (2) -> (3)
+ * | \-> (5) -> (7)
+ * \-> [ (5) Create/Update Fwk Patch]
+ * |-> [(6) Release Fwk Patch]
+ * | |-> (1)
+ * | \-> (2) (including reconnection)
+ * \-> [(7) Disconnect Device]
+ * |-> [Release Fwk Patch] -> [Close Stream]
+ * \-> (4) -> (5) -> (6) -> (1)
+ *
+ * Note that the test (acting on behalf of DeviceHalAidl) is responsible
+ * for calling `eraseFwkPatch` and `updateFwkPatch` when needed.
+ */
+
+// (1)
+TEST_F(Hal2AidlMapperTest, CloseDisconnect) {
+ ASSERT_NO_FATAL_FAILURE(CloseDisconnectImpl());
+ // The patch is owned by HAL, must not be listed under fwkPatches after disconnection.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+}
+
+// (2) -> (3)
+TEST_F(Hal2AidlMapperTest, DisconnectClose) {
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch is owned by HAL, must not be listed under fwkPatches after disconnection.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+ mStream.clear();
+}
+
+// (2) -> (4) -> (1)
+TEST_F(Hal2AidlMapperTest, DisconnectConnectCloseDisconnect) {
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch is owned by HAL, must not be listed under fwkPatches after disconnection.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+ ASSERT_NO_FATAL_FAILURE(ConnectAnotherDevice());
+ ASSERT_NO_FATAL_FAILURE(CloseDisconnectImpl());
+ // The patch is owned by HAL, must not be listed under fwkPatches after disconnection.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+}
+
+// (2) -> (4) -> (2) -> (3)
+TEST_F(Hal2AidlMapperTest, DisconnectConnectDisconnectClose) {
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch is owned by HAL, must not be listed under fwkPatches after disconnection.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+ ASSERT_NO_FATAL_FAILURE(ConnectAnotherDevice());
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch is owned by HAL, must not be listed under fwkPatches after disconnection.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+ mStream.clear();
+}
+
+// (5) -> (6) -> (1)
+TEST_F(Hal2AidlMapperTest, CreateFwkPatchReleaseCloseDisconnect) {
+ int32_t patchId;
+ ASSERT_NO_FATAL_FAILURE(CreateFwkPatch(&patchId));
+ // Must be the patch created during stream opening.
+ ASSERT_EQ(mPatch.id, patchId);
+ // The patch was not reset by HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+
+ ASSERT_EQ(OK, mMapper->releaseAudioPatch(patchId));
+ // The patch does not exist both for the fwk and the HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(patchId));
+ ASSERT_NO_FATAL_FAILURE(CloseDisconnectImpl());
+ // The patch does not exist both for the fwk and the HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(patchId));
+}
+
+// (5) -> (6) -> (2) -> (3)
+TEST_F(Hal2AidlMapperTest, CreateFwkPatchReleaseDisconnectClose) {
+ int32_t patchId;
+ ASSERT_NO_FATAL_FAILURE(CreateFwkPatch(&patchId));
+ // Must be the patch created during stream opening.
+ ASSERT_EQ(mPatch.id, patchId);
+ // The patch was not reset by HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+
+ ASSERT_EQ(OK, mMapper->releaseAudioPatch(patchId));
+ // The patch does not exist both for the fwk and the HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(patchId));
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch does not exist both for the fwk and the HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+ mStream.clear();
+}
+
+// (5) -> (6) -> (2) -> (4) -> (2) -> (3)
+TEST_F(Hal2AidlMapperTest, CreateFwkPatchReleaseDisconnectConnectDisconnectClose) {
+ int32_t patchId;
+ ASSERT_NO_FATAL_FAILURE(CreateFwkPatch(&patchId));
+ // Must be the patch created during stream opening.
+ ASSERT_EQ(mPatch.id, patchId);
+ // The patch was not reset by HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+
+ ASSERT_EQ(OK, mMapper->releaseAudioPatch(patchId));
+ // The patch does not exist both for the fwk and the HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(patchId));
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch does not exist both for the fwk and the HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+
+ ASSERT_NO_FATAL_FAILURE(ConnectAnotherDevice());
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch does not exist both for the fwk and the HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+ mStream.clear();
+}
+
+// (5) -> (7) -> Release -> Close
+TEST_F(Hal2AidlMapperTest, CreateFwkPatchDisconnectReleaseClose) {
+ int32_t patchId;
+ ASSERT_NO_FATAL_FAILURE(CreateFwkPatch(&patchId));
+ // Must be the patch created during stream opening.
+ ASSERT_EQ(mPatch.id, patchId);
+ // The patch was not reset by HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ ASSERT_NO_FATAL_FAILURE(ReleaseFwkOnlyPatch(patchId));
+
+ mStream.clear();
+ EXPECT_EQ(0, mMapper->findFwkPatch(patchId));
+}
+
+// (5) -> (7) -> (4) -> (5) -> (6) -> (1)
+TEST_F(Hal2AidlMapperTest, CreateFwkPatchDisconnectConnectUpdateReleaseCloseDisconnect) {
+ int32_t patchId;
+ ASSERT_NO_FATAL_FAILURE(CreateFwkPatch(&patchId));
+ // Must be the patch created during stream opening.
+ ASSERT_EQ(mPatch.id, patchId);
+ // The patch was not reset by HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch now only exists for the framework.
+ EXPECT_EQ(mPatch.id, mMapper->findFwkPatch(mPatch.id));
+
+ ASSERT_NO_FATAL_FAILURE(ConnectAnotherDevice());
+ // Change the device address locally, for patch update.
+ mDevicePortConfig.ext.get<AudioPortExt::device>().device.address =
+ mConnectedPort.ext.get<AudioPortExt::device>().device.address;
+ int32_t newPatchId = patchId;
+ ASSERT_NO_FATAL_FAILURE(CreateFwkPatch(&newPatchId));
+ EXPECT_NE(patchId, newPatchId);
+ mMapper->updateFwkPatch(patchId, newPatchId);
+ EXPECT_EQ(newPatchId, mMapper->findFwkPatch(patchId));
+ // Just in case, check that HAL patch ID is not listed as a fwk patch.
+ EXPECT_EQ(0, mMapper->findFwkPatch(newPatchId));
+ // Verify that device port config was updated.
+ ASSERT_EQ(OK, mMapper->findPortConfig(mConnectedPort.ext.get<AudioPortExt::device>().device,
+ &mDevicePortConfig));
+
+ ASSERT_EQ(OK, mMapper->releaseAudioPatch(newPatchId));
+ // The patch does not exist both for the fwk and the HAL, must not be listed under fwkPatches.
+ EXPECT_EQ(0, mMapper->findFwkPatch(patchId));
+ // Just in case, check that HAL patch ID is not listed.
+ EXPECT_EQ(0, mMapper->findFwkPatch(newPatchId));
+
+ ASSERT_NO_FATAL_FAILURE(CloseDisconnectImpl());
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+ EXPECT_EQ(0, mMapper->findFwkPatch(patchId));
+ EXPECT_EQ(0, mMapper->findFwkPatch(newPatchId));
+}
+
+// (2) -> (4) -> (5) -> (7) -> Release -> Close
+TEST_F(Hal2AidlMapperTest, DisconnectConnectCreateFwkPatchDisconnectReleaseClose) {
+ const int32_t patchId = mPatch.id;
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ // The patch is owned by HAL, must not be listed under fwkPatches after disconnection.
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+
+ ASSERT_NO_FATAL_FAILURE(ConnectAnotherDevice());
+ // Change the device address locally, for patch update.
+ mDevicePortConfig.ext.get<AudioPortExt::device>().device.address =
+ mConnectedPort.ext.get<AudioPortExt::device>().device.address;
+ int32_t newPatchId = 0; // Use 0 since the fwk does not know about the HAL patch.
+ EXPECT_EQ(0, mMapper->findFwkPatch(newPatchId));
+ ASSERT_NO_FATAL_FAILURE(CreateFwkPatch(&newPatchId));
+ EXPECT_NE(0, newPatchId);
+ EXPECT_NE(patchId, newPatchId);
+ // Just in case, check that HAL patch ID is not listed as a fwk patch.
+ EXPECT_EQ(0, mMapper->findFwkPatch(newPatchId));
+ // Verify that device port config was updated.
+ ASSERT_EQ(OK, mMapper->findPortConfig(mConnectedPort.ext.get<AudioPortExt::device>().device,
+ &mDevicePortConfig));
+
+ ASSERT_NO_FATAL_FAILURE(DisconnectDevice());
+ ASSERT_NO_FATAL_FAILURE(ReleaseFwkOnlyPatch(newPatchId));
+
+ mStream.clear();
+ EXPECT_EQ(0, mMapper->findFwkPatch(mPatch.id));
+ EXPECT_EQ(0, mMapper->findFwkPatch(newPatchId));
+}
diff --git a/media/libaudioprocessing/Android.bp b/media/libaudioprocessing/Android.bp
index 6160d7d..9d510a8 100644
--- a/media/libaudioprocessing/Android.bp
+++ b/media/libaudioprocessing/Android.bp
@@ -22,11 +22,13 @@
],
cflags: [
- "-Werror",
"-Wall",
// uncomment to disable NEON on architectures that actually do support NEON, for benchmarking
+
// "-DUSE_NEON=false",
+ "-Werror",
+
],
arch: {
@@ -62,7 +64,7 @@
header_libs: [
"libaudiohal_headers",
"libbase_headers",
- "libmedia_headers"
+ "libmedia_headers",
],
shared_libs: [
@@ -87,8 +89,8 @@
"AudioMixerBase.cpp",
"AudioResampler.cpp",
"AudioResamplerCubic.cpp",
- "AudioResamplerSinc.cpp",
"AudioResamplerDyn.cpp",
+ "AudioResamplerSinc.cpp",
],
arch: {
diff --git a/media/libaudioprocessing/audio-resampler/Android.bp b/media/libaudioprocessing/audio-resampler/Android.bp
index 4ea75e7..791ae37 100644
--- a/media/libaudioprocessing/audio-resampler/Android.bp
+++ b/media/libaudioprocessing/audio-resampler/Android.bp
@@ -13,12 +13,12 @@
srcs: ["AudioResamplerCoefficients.cpp"],
shared_libs: [
- "libutils",
"liblog",
+ "libutils",
],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
}
diff --git a/media/libaudioprocessing/tests/Android.bp b/media/libaudioprocessing/tests/Android.bp
index a33bf55..ba9b165 100644
--- a/media/libaudioprocessing/tests/Android.bp
+++ b/media/libaudioprocessing/tests/Android.bp
@@ -29,8 +29,8 @@
],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
}
diff --git a/media/libcpustats/Android.bp b/media/libcpustats/Android.bp
index 1ab1de0..2b134a7 100644
--- a/media/libcpustats/Android.bp
+++ b/media/libcpustats/Android.bp
@@ -24,8 +24,8 @@
],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
host_supported: true,
diff --git a/media/libeffects/config/Android.bp b/media/libeffects/config/Android.bp
index 293a9c2..1672797 100644
--- a/media/libeffects/config/Android.bp
+++ b/media/libeffects/config/Android.bp
@@ -20,11 +20,11 @@
],
shared_libs: [
+ "libcutils",
"liblog",
+ "libmedia_helper",
"libtinyxml2",
"libutils",
- "libmedia_helper",
- "libcutils",
],
header_libs: [
diff --git a/media/libeffects/downmix/Android.bp b/media/libeffects/downmix/Android.bp
index 0b25327..19b8082 100644
--- a/media/libeffects/downmix/Android.bp
+++ b/media/libeffects/downmix/Android.bp
@@ -38,9 +38,9 @@
relative_install_path: "soundfx",
cflags: [
- "-fvisibility=hidden",
"-Wall",
"-Werror",
+ "-fvisibility=hidden",
],
header_libs: [
@@ -52,9 +52,9 @@
cc_library_shared {
name: "libdownmixaidl",
srcs: [
- "aidl/EffectDownmix.cpp",
- "aidl/DownmixContext.cpp",
":effectCommonFile",
+ "aidl/DownmixContext.cpp",
+ "aidl/EffectDownmix.cpp",
],
defaults: [
"aidlaudioeffectservice_defaults",
diff --git a/media/libeffects/downmix/aidl/DownmixContext.cpp b/media/libeffects/downmix/aidl/DownmixContext.cpp
index 5fb44b5..593e16f 100644
--- a/media/libeffects/downmix/aidl/DownmixContext.cpp
+++ b/media/libeffects/downmix/aidl/DownmixContext.cpp
@@ -76,18 +76,15 @@
DownmixContext::DownmixContext(int statusDepth, const Parameter::Common& common)
: EffectContext(statusDepth, common) {
- LOG(DEBUG) << __func__;
mState = DOWNMIX_STATE_UNINITIALIZED;
init_params(common);
}
DownmixContext::~DownmixContext() {
- LOG(DEBUG) << __func__;
mState = DOWNMIX_STATE_UNINITIALIZED;
}
RetCode DownmixContext::enable() {
- LOG(DEBUG) << __func__;
if (mState != DOWNMIX_STATE_INITIALIZED) {
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
@@ -96,7 +93,6 @@
}
RetCode DownmixContext::disable() {
- LOG(DEBUG) << __func__;
if (mState != DOWNMIX_STATE_ACTIVE) {
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
@@ -105,7 +101,6 @@
}
void DownmixContext::reset() {
- LOG(DEBUG) << __func__;
disable();
resetBuffer();
}
@@ -127,7 +122,6 @@
return status;
}
- LOG(DEBUG) << __func__ << " start processing";
bool accumulate = false;
int frames = samples * sizeof(float) / getInputFrameSize();
if (mType == Downmix::Type::STRIP) {
@@ -152,9 +146,6 @@
}
}
int producedSamples = (samples / mInputChannelCount) << 1;
- LOG(DEBUG) << __func__ << " done processing " << samples << " samples, generated "
- << producedSamples << " frameSize: " << getInputFrameSize() << " - "
- << getOutputFrameSize();
return {STATUS_OK, samples, producedSamples};
}
diff --git a/media/libeffects/downmix/aidl/EffectDownmix.cpp b/media/libeffects/downmix/aidl/EffectDownmix.cpp
index 46156ce..de60ca4 100644
--- a/media/libeffects/downmix/aidl/EffectDownmix.cpp
+++ b/media/libeffects/downmix/aidl/EffectDownmix.cpp
@@ -14,10 +14,12 @@
* limitations under the License.
*/
+#define ATRACE_TAG ATRACE_TAG_AUDIO
#define LOG_TAG "AHAL_DownmixImpl"
#include <android-base/logging.h>
#include <system/audio_effects/effect_uuid.h>
+#include <utils/Trace.h>
#include "EffectDownmix.h"
@@ -36,7 +38,6 @@
}
if (instanceSpp) {
*instanceSpp = ndk::SharedRefBase::make<DownmixImpl>();
- LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
} else {
LOG(ERROR) << __func__ << " invalid input parameter!";
@@ -66,7 +67,6 @@
ndk::ScopedAStatus DownmixImpl::getDescriptor(Descriptor* _aidl_return) {
RETURN_IF(!_aidl_return, EX_ILLEGAL_ARGUMENT, "Parameter:nullptr");
- LOG(DEBUG) << __func__ << kDescriptor.toString();
*_aidl_return = kDescriptor;
return ndk::ScopedAStatus::ok();
}
@@ -171,6 +171,7 @@
}
void DownmixImpl::process() {
+ ATRACE_NAME("Downmix::process");
/**
* wait for the EventFlag without lock, it's ok because the mEfGroup pointer will not change
* in the life cycle of workerThread (threadLoop).
@@ -203,8 +204,6 @@
IEffect::Status status = effectProcessImpl(buffer, buffer, processSamples);
outputMQ->write(buffer, status.fmqProduced);
statusMQ->writeBlocking(&status, 1);
- LOG(VERBOSE) << getEffectName() << __func__ << ": done processing, effect consumed "
- << status.fmqConsumed << " produced " << status.fmqProduced;
}
}
}
diff --git a/media/libeffects/downmix/aidl/EffectDownmix.h b/media/libeffects/downmix/aidl/EffectDownmix.h
index 54557dc..b7d621a 100644
--- a/media/libeffects/downmix/aidl/EffectDownmix.h
+++ b/media/libeffects/downmix/aidl/EffectDownmix.h
@@ -28,11 +28,8 @@
public:
static const std::string kEffectName;
static const Descriptor kDescriptor;
- DownmixImpl() { LOG(DEBUG) << __func__; }
- ~DownmixImpl() {
- cleanUp();
- LOG(DEBUG) << __func__;
- }
+ DownmixImpl() = default;
+ ~DownmixImpl() { cleanUp(); }
ndk::ScopedAStatus commandImpl(CommandId command) REQUIRES(mImplMutex) override;
ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
diff --git a/media/libeffects/dynamicsproc/Android.bp b/media/libeffects/dynamicsproc/Android.bp
index e93a4e6..12477a4 100644
--- a/media/libeffects/dynamicsproc/Android.bp
+++ b/media/libeffects/dynamicsproc/Android.bp
@@ -33,7 +33,7 @@
}
cc_defaults {
- name : "dynamicsprocessingdefaults",
+ name: "dynamicsprocessingdefaults",
srcs: [
"dsp/DPBase.cpp",
"dsp/DPFrequency.cpp",
@@ -50,9 +50,9 @@
"libeigen",
],
cflags: [
- "-Wthread-safety",
"-Wall",
"-Werror",
+ "-Wthread-safety",
],
relative_install_path: "soundfx",
}
@@ -80,9 +80,9 @@
name: "libdynamicsprocessingaidl",
srcs: [
+ ":effectCommonFile",
"aidl/DynamicsProcessing.cpp",
"aidl/DynamicsProcessingContext.cpp",
- ":effectCommonFile",
],
defaults: [
diff --git a/media/libeffects/dynamicsproc/aidl/DynamicsProcessing.cpp b/media/libeffects/dynamicsproc/aidl/DynamicsProcessing.cpp
index 7e1549d..fdc16e3 100644
--- a/media/libeffects/dynamicsproc/aidl/DynamicsProcessing.cpp
+++ b/media/libeffects/dynamicsproc/aidl/DynamicsProcessing.cpp
@@ -41,7 +41,6 @@
}
if (instanceSpp) {
*instanceSpp = ndk::SharedRefBase::make<DynamicsProcessingImpl>();
- LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
} else {
LOG(ERROR) << __func__ << " invalid input parameter!";
@@ -206,7 +205,6 @@
ndk::ScopedAStatus DynamicsProcessingImpl::open(const Parameter::Common& common,
const std::optional<Parameter::Specific>& specific,
OpenEffectReturn* ret) {
- LOG(DEBUG) << __func__;
// effect only support 32bits float
RETURN_IF(common.input.base.format.pcm != common.output.base.format.pcm ||
common.input.base.format.pcm != PcmType::FLOAT_32_BIT,
@@ -240,7 +238,6 @@
ndk::ScopedAStatus DynamicsProcessingImpl::getDescriptor(Descriptor* _aidl_return) {
RETURN_IF(!_aidl_return, EX_ILLEGAL_ARGUMENT, "Parameter:nullptr");
- LOG(DEBUG) << __func__ << kDescriptor.toString();
*_aidl_return = kDescriptor;
return ndk::ScopedAStatus::ok();
}
diff --git a/media/libeffects/dynamicsproc/aidl/DynamicsProcessing.h b/media/libeffects/dynamicsproc/aidl/DynamicsProcessing.h
index 4897888..e850ba4 100644
--- a/media/libeffects/dynamicsproc/aidl/DynamicsProcessing.h
+++ b/media/libeffects/dynamicsproc/aidl/DynamicsProcessing.h
@@ -30,11 +30,8 @@
static const Descriptor kDescriptor;
static const Capability kCapability;
- DynamicsProcessingImpl() { LOG(DEBUG) << __func__; }
- ~DynamicsProcessingImpl() {
- cleanUp();
- LOG(DEBUG) << __func__;
- }
+ DynamicsProcessingImpl() = default;
+ ~DynamicsProcessingImpl() { cleanUp(); }
ndk::ScopedAStatus open(const Parameter::Common& common,
const std::optional<Parameter::Specific>& specific,
diff --git a/media/libeffects/dynamicsproc/aidl/DynamicsProcessingContext.cpp b/media/libeffects/dynamicsproc/aidl/DynamicsProcessingContext.cpp
index 311d60a..9c440df 100644
--- a/media/libeffects/dynamicsproc/aidl/DynamicsProcessingContext.cpp
+++ b/media/libeffects/dynamicsproc/aidl/DynamicsProcessingContext.cpp
@@ -29,16 +29,10 @@
DynamicsProcessingContext::DynamicsProcessingContext(int statusDepth,
const Parameter::Common& common)
: EffectContext(statusDepth, common) {
- LOG(DEBUG) << __func__;
init();
}
-DynamicsProcessingContext::~DynamicsProcessingContext() {
- LOG(DEBUG) << __func__;
-}
-
RetCode DynamicsProcessingContext::enable() {
- std::lock_guard lg(mMutex);
if (mState != DYNAMICS_PROCESSING_STATE_INITIALIZED) {
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
@@ -47,7 +41,6 @@
}
RetCode DynamicsProcessingContext::disable() {
- std::lock_guard lg(mMutex);
if (mState != DYNAMICS_PROCESSING_STATE_ACTIVE) {
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
@@ -56,7 +49,6 @@
}
void DynamicsProcessingContext::reset() {
- std::lock_guard lg(mMutex);
if (mDpFreq != nullptr) {
mDpFreq.reset();
}
@@ -68,12 +60,10 @@
}
mCommon = common;
init();
- LOG(INFO) << __func__ << common.toString();
return RetCode::SUCCESS;
}
RetCode DynamicsProcessingContext::setVolumeStereo(const Parameter::VolumeStereo& volumeStereo) {
- std::lock_guard lg(mMutex);
dp_fx::DPChannel* leftChannel = mDpFreq->getChannel(0);
dp_fx::DPChannel* rightChannel = mDpFreq->getChannel(1);
if (leftChannel != nullptr) {
@@ -99,8 +89,8 @@
int32_t sampleRate = mCommon.input.base.sampleRate;
int32_t minBlockSize = (int32_t)dp_fx::DPFrequency::getMinBockSize();
int32_t block = engine.preferredProcessingDurationMs * sampleRate / 1000.0f;
- LOG(INFO) << __func__ << " sampleRate " << sampleRate << " block length "
- << engine.preferredProcessingDurationMs << " ms (" << block << "samples)";
+ LOG(VERBOSE) << __func__ << " sampleRate " << sampleRate << " block length "
+ << engine.preferredProcessingDurationMs << " ms (" << block << "samples)";
if (block < minBlockSize) {
block = minBlockSize;
} else if (!powerof2(block)) {
@@ -112,7 +102,6 @@
RetCode DynamicsProcessingContext::setEngineArchitecture(
const DynamicsProcessing::EngineArchitecture& engineArchitecture) {
- std::lock_guard lg(mMutex);
if (!mEngineInited || mEngineArchitecture != engineArchitecture) {
if (engineArchitecture.resolutionPreference ==
DynamicsProcessing::ResolutionPreference::FAVOR_FREQUENCY_RESOLUTION) {
@@ -124,34 +113,29 @@
mEngineInited = true;
mEngineArchitecture = engineArchitecture;
}
- LOG(INFO) << __func__ << engineArchitecture.toString();
return RetCode::SUCCESS;
}
RetCode DynamicsProcessingContext::setPreEq(
const std::vector<DynamicsProcessing::ChannelConfig>& channels) {
- std::lock_guard lg(mMutex);
return setDpChannels_l<dp_fx::DPEq>(channels, mEngineArchitecture.preEqStage.inUse,
StageType::PREEQ);
}
RetCode DynamicsProcessingContext::setPostEq(
const std::vector<DynamicsProcessing::ChannelConfig>& channels) {
- std::lock_guard lg(mMutex);
return setDpChannels_l<dp_fx::DPEq>(channels, mEngineArchitecture.postEqStage.inUse,
StageType::POSTEQ);
}
RetCode DynamicsProcessingContext::setMbc(
const std::vector<DynamicsProcessing::ChannelConfig>& channels) {
- std::lock_guard lg(mMutex);
return setDpChannels_l<dp_fx::DPMbc>(channels, mEngineArchitecture.mbcStage.inUse,
StageType::MBC);
}
RetCode DynamicsProcessingContext::setPreEqBand(
const std::vector<DynamicsProcessing::EqBandConfig>& bands) {
- std::lock_guard lg(mMutex);
RETURN_VALUE_IF(!mEngineArchitecture.preEqStage.inUse, RetCode::ERROR_ILLEGAL_PARAMETER,
"preEqNotInUse");
RETURN_VALUE_IF(
@@ -162,7 +146,6 @@
RetCode DynamicsProcessingContext::setPostEqBand(
const std::vector<DynamicsProcessing::EqBandConfig>& bands) {
- std::lock_guard lg(mMutex);
RETURN_VALUE_IF(!mEngineArchitecture.postEqStage.inUse, RetCode::ERROR_ILLEGAL_PARAMETER,
"postEqNotInUse");
RETURN_VALUE_IF(
@@ -173,7 +156,6 @@
RetCode DynamicsProcessingContext::setMbcBand(
const std::vector<DynamicsProcessing::MbcBandConfig>& bands) {
- std::lock_guard lg(mMutex);
RETURN_VALUE_IF(!mEngineArchitecture.mbcStage.inUse, RetCode::ERROR_ILLEGAL_PARAMETER,
"mbcNotInUse");
RETURN_VALUE_IF(
@@ -184,7 +166,6 @@
RetCode DynamicsProcessingContext::setLimiter(
const std::vector<DynamicsProcessing::LimiterConfig>& limiters) {
- std::lock_guard lg(mMutex);
RETURN_VALUE_IF(!mEngineArchitecture.limiterInUse, RetCode::ERROR_ILLEGAL_PARAMETER,
"limiterNotInUse");
RETURN_VALUE_IF(!validateLimiterConfig(limiters, mChannelCount),
@@ -194,15 +175,12 @@
RetCode DynamicsProcessingContext::setInputGain(
const std::vector<DynamicsProcessing::InputGain>& inputGains) {
- std::lock_guard lg(mMutex);
RETURN_VALUE_IF(!validateInputGainConfig(inputGains, mChannelCount),
RetCode::ERROR_ILLEGAL_PARAMETER, "inputGainNotValid");
return setBands_l<DynamicsProcessing::InputGain>(inputGains, StageType::INPUTGAIN);
}
DynamicsProcessing::EngineArchitecture DynamicsProcessingContext::getEngineArchitecture() {
- std::lock_guard lg(mMutex);
- LOG(INFO) << __func__ << mEngineArchitecture.toString();
return mEngineArchitecture;
}
@@ -228,8 +206,6 @@
std::vector<DynamicsProcessing::MbcBandConfig> DynamicsProcessingContext::getMbcBand() {
std::vector<DynamicsProcessing::MbcBandConfig> bands;
-
- std::lock_guard lg(mMutex);
auto maxBand = mEngineArchitecture.mbcStage.bandCount;
for (int32_t ch = 0; ch < mChannelCount; ch++) {
auto mbc = getMbc_l(ch);
@@ -261,8 +237,6 @@
std::vector<DynamicsProcessing::LimiterConfig> DynamicsProcessingContext::getLimiter() {
std::vector<DynamicsProcessing::LimiterConfig> ret;
-
- std::lock_guard lg(mMutex);
for (int32_t ch = 0; ch < mChannelCount; ch++) {
auto limiter = getLimiter_l(ch);
if (!limiter) {
@@ -282,8 +256,6 @@
std::vector<DynamicsProcessing::InputGain> DynamicsProcessingContext::getInputGain() {
std::vector<DynamicsProcessing::InputGain> ret;
-
- std::lock_guard lg(mMutex);
for (int32_t ch = 0; ch < mChannelCount; ch++) {
auto channel = getChannel_l(ch);
if (!channel) {
@@ -295,26 +267,20 @@
}
IEffect::Status DynamicsProcessingContext::dpeProcess(float* in, float* out, int samples) {
- LOG(DEBUG) << __func__ << " in " << in << " out " << out << " sample " << samples;
IEffect::Status status = {EX_NULL_POINTER, 0, 0};
RETURN_VALUE_IF(!in, status, "nullInput");
RETURN_VALUE_IF(!out, status, "nullOutput");
status = {EX_ILLEGAL_STATE, 0, 0};
- LOG(DEBUG) << __func__ << " start processing";
- {
- std::lock_guard lg(mMutex);
- RETURN_VALUE_IF(mState != DynamicsProcessingState::DYNAMICS_PROCESSING_STATE_ACTIVE, status,
- "notInActiveState");
- RETURN_VALUE_IF(!mDpFreq, status, "engineNotInited");
- mDpFreq->processSamples(in, out, samples);
- }
+ RETURN_VALUE_IF(mState != DynamicsProcessingState::DYNAMICS_PROCESSING_STATE_ACTIVE, status,
+ "notInActiveState");
+ RETURN_VALUE_IF(!mDpFreq, status, "engineNotInited");
+ mDpFreq->processSamples(in, out, samples);
return {STATUS_OK, samples, samples};
}
void DynamicsProcessingContext::init() {
- std::lock_guard lg(mMutex);
if (mState == DYNAMICS_PROCESSING_STATE_UNINITIALIZED) {
mState = DYNAMICS_PROCESSING_STATE_INITIALIZED;
}
@@ -399,7 +365,6 @@
StageType type) {
std::vector<DynamicsProcessing::ChannelConfig> ret;
- std::lock_guard lg(mMutex);
for (int32_t ch = 0; ch < mChannelCount; ch++) {
auto stage = getStageWithType_l(type, ch);
if (!stage) {
@@ -414,7 +379,6 @@
StageType type) {
std::vector<DynamicsProcessing::EqBandConfig> eqBands;
- std::lock_guard lg(mMutex);
auto maxBand = mEngineArchitecture.preEqStage.bandCount;
for (int32_t ch = 0; ch < mChannelCount; ch++) {
auto eq = getEqWithType_l(type, ch);
@@ -509,7 +473,6 @@
continue;
}
if (dp->isEnabled() != it.enable) {
- LOG(INFO) << __func__ << it.toString();
dp->setEnabled(it.enable);
}
}
@@ -590,7 +553,6 @@
ret = RetCode::ERROR_ILLEGAL_PARAMETER;
continue;
}
- LOG(INFO) << __func__ << it.toString();
}
return ret;
}
diff --git a/media/libeffects/dynamicsproc/aidl/DynamicsProcessingContext.h b/media/libeffects/dynamicsproc/aidl/DynamicsProcessingContext.h
index 839c6dd..a059dd0 100644
--- a/media/libeffects/dynamicsproc/aidl/DynamicsProcessingContext.h
+++ b/media/libeffects/dynamicsproc/aidl/DynamicsProcessingContext.h
@@ -16,7 +16,6 @@
#pragma once
-#include <android-base/thread_annotations.h>
#include <audio_effects/effect_dynamicsprocessing.h>
#include "effect-impl/EffectContext.h"
@@ -37,8 +36,7 @@
class DynamicsProcessingContext final : public EffectContext {
public:
DynamicsProcessingContext(int statusDepth, const Parameter::Common& common);
- ~DynamicsProcessingContext();
-
+ ~DynamicsProcessingContext() = default;
RetCode enable();
RetCode disable();
void reset();
@@ -73,12 +71,11 @@
private:
static constexpr float kPreferredProcessingDurationMs = 10.0f;
static constexpr int kBandCount = 5;
- std::mutex mMutex;
- int mChannelCount GUARDED_BY(mMutex) = 0;
- DynamicsProcessingState mState GUARDED_BY(mMutex) = DYNAMICS_PROCESSING_STATE_UNINITIALIZED;
- std::unique_ptr<dp_fx::DPFrequency> mDpFreq GUARDED_BY(mMutex) = nullptr;
- bool mEngineInited GUARDED_BY(mMutex) = false;
- DynamicsProcessing::EngineArchitecture mEngineArchitecture GUARDED_BY(mMutex) = {
+ int mChannelCount = 0;
+ DynamicsProcessingState mState = DYNAMICS_PROCESSING_STATE_UNINITIALIZED;
+ std::unique_ptr<dp_fx::DPFrequency> mDpFreq = nullptr;
+ bool mEngineInited = false;
+ DynamicsProcessing::EngineArchitecture mEngineArchitecture = {
.resolutionPreference =
DynamicsProcessing::ResolutionPreference::FAVOR_FREQUENCY_RESOLUTION,
.preferredProcessingDurationMs = kPreferredProcessingDurationMs,
@@ -92,22 +89,21 @@
void init();
- void dpSetFreqDomainVariant_l(const DynamicsProcessing::EngineArchitecture& engine)
- REQUIRES(mMutex);
- dp_fx::DPChannel* getChannel_l(int ch) REQUIRES(mMutex);
- dp_fx::DPEq* getPreEq_l(int ch) REQUIRES(mMutex);
- dp_fx::DPEq* getPostEq_l(int ch) REQUIRES(mMutex);
- dp_fx::DPMbc* getMbc_l(int ch) REQUIRES(mMutex);
- dp_fx::DPLimiter* getLimiter_l(int ch) REQUIRES(mMutex);
- dp_fx::DPBandStage* getStageWithType_l(StageType type, int ch) REQUIRES(mMutex);
- dp_fx::DPEq* getEqWithType_l(StageType type, int ch) REQUIRES(mMutex);
+ void dpSetFreqDomainVariant_l(const DynamicsProcessing::EngineArchitecture& engine);
+ dp_fx::DPChannel* getChannel_l(int ch);
+ dp_fx::DPEq* getPreEq_l(int ch);
+ dp_fx::DPEq* getPostEq_l(int ch);
+ dp_fx::DPMbc* getMbc_l(int ch);
+ dp_fx::DPLimiter* getLimiter_l(int ch);
+ dp_fx::DPBandStage* getStageWithType_l(StageType type, int ch);
+ dp_fx::DPEq* getEqWithType_l(StageType type, int ch);
template <typename D>
RetCode setDpChannels_l(const std::vector<DynamicsProcessing::ChannelConfig>& channels,
- bool stageInUse, StageType type) REQUIRES(mMutex);
+ bool stageInUse, StageType type);
template <typename T /* BandConfig */>
- RetCode setBands_l(const std::vector<T>& bands, StageType type) REQUIRES(mMutex);
+ RetCode setBands_l(const std::vector<T>& bands, StageType type);
RetCode setDpChannelBand_l(const std::any& anyConfig, StageType type,
- std::set<std::pair<int, int>>& chBandSet) REQUIRES(mMutex);
+ std::set<std::pair<int, int>>& chBandSet);
std::vector<DynamicsProcessing::EqBandConfig> getEqBandConfigs(StageType type);
std::vector<DynamicsProcessing::ChannelConfig> getChannelConfig(StageType type);
diff --git a/media/libeffects/factory/Android.bp b/media/libeffects/factory/Android.bp
index ad5188f..9be45a5 100644
--- a/media/libeffects/factory/Android.bp
+++ b/media/libeffects/factory/Android.bp
@@ -21,17 +21,17 @@
name: "libeffects",
vendor: true,
srcs: [
- "EffectsFactory.c",
"EffectsConfigLoader.c",
+ "EffectsFactory.c",
"EffectsFactoryState.c",
"EffectsXmlConfigLoader.cpp",
],
shared_libs: [
"libcutils",
- "liblog",
"libdl",
"libeffectsconfig",
+ "liblog",
],
cflags: ["-fvisibility=hidden"],
@@ -54,13 +54,13 @@
cflags: [
"-Wall",
- "-Wextra",
"-Werror",
+ "-Wextra",
],
shared_libs: [
- "libeffectsconfig",
"libeffects",
+ "libeffectsconfig",
],
local_include_dirs: [
".",
diff --git a/media/libeffects/hapticgenerator/Android.bp b/media/libeffects/hapticgenerator/Android.bp
index 7d96b53..9975f75 100644
--- a/media/libeffects/hapticgenerator/Android.bp
+++ b/media/libeffects/hapticgenerator/Android.bp
@@ -23,7 +23,7 @@
}
cc_defaults {
- name : "hapticgeneratordefaults",
+ name: "hapticgeneratordefaults",
srcs: [
"Processors.cpp",
],
@@ -54,13 +54,15 @@
],
cflags: [
- "-O2", // Turning on the optimization in order to reduce effect processing time.
- // The latency is around 1/5 less than without the optimization.
+ // Turning on the optimization in order to reduce effect processing time.
+ // The latency is around 1/5 less than without the optimization.
+ "-O2",
"-Wall",
"-Werror",
- "-ffast-math", // This is needed for the non-zero coefficients optimization for
- // BiquadFilter. Try the biquad_filter_benchmark test in audio_utils
- // with/without `-ffast-math` for more context.
+ // This is needed for the non-zero coefficients optimization for
+ // BiquadFilter. Try the biquad_filter_benchmark test in audio_utils
+ // with/without `-ffast-math` for more context.
+ "-ffast-math",
"-fvisibility=hidden",
],
}
@@ -69,9 +71,9 @@
name: "libhapticgeneratoraidl",
srcs: [
+ ":effectCommonFile",
"aidl/EffectHapticGenerator.cpp",
"aidl/HapticGeneratorContext.cpp",
- ":effectCommonFile",
],
defaults: [
diff --git a/media/libeffects/hapticgenerator/aidl/EffectHapticGenerator.cpp b/media/libeffects/hapticgenerator/aidl/EffectHapticGenerator.cpp
index 2d3bdd0..b803ee4 100644
--- a/media/libeffects/hapticgenerator/aidl/EffectHapticGenerator.cpp
+++ b/media/libeffects/hapticgenerator/aidl/EffectHapticGenerator.cpp
@@ -37,7 +37,6 @@
}
if (instanceSpp) {
*instanceSpp = ndk::SharedRefBase::make<HapticGeneratorImpl>();
- LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
} else {
LOG(ERROR) << __func__ << " invalid input parameter!";
@@ -67,7 +66,6 @@
ndk::ScopedAStatus HapticGeneratorImpl::getDescriptor(Descriptor* _aidl_return) {
RETURN_IF(!_aidl_return, EX_ILLEGAL_ARGUMENT, "Parameter:nullptr");
- LOG(DEBUG) << __func__ << kDescriptor.toString();
*_aidl_return = kDescriptor;
return ndk::ScopedAStatus::ok();
}
diff --git a/media/libeffects/hapticgenerator/aidl/EffectHapticGenerator.h b/media/libeffects/hapticgenerator/aidl/EffectHapticGenerator.h
index 53dcd49..a775f06 100644
--- a/media/libeffects/hapticgenerator/aidl/EffectHapticGenerator.h
+++ b/media/libeffects/hapticgenerator/aidl/EffectHapticGenerator.h
@@ -27,11 +27,8 @@
public:
static const std::string kEffectName;
static const Descriptor kDescriptor;
- HapticGeneratorImpl() { LOG(DEBUG) << __func__; }
- ~HapticGeneratorImpl() {
- cleanUp();
- LOG(DEBUG) << __func__;
- }
+ HapticGeneratorImpl() = default;
+ ~HapticGeneratorImpl() { cleanUp(); }
ndk::ScopedAStatus commandImpl(CommandId command) REQUIRES(mImplMutex) override;
ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
diff --git a/media/libeffects/hapticgenerator/aidl/HapticGeneratorContext.cpp b/media/libeffects/hapticgenerator/aidl/HapticGeneratorContext.cpp
index 5c38d17..0a04250 100644
--- a/media/libeffects/hapticgenerator/aidl/HapticGeneratorContext.cpp
+++ b/media/libeffects/hapticgenerator/aidl/HapticGeneratorContext.cpp
@@ -28,7 +28,6 @@
HapticGeneratorContext::HapticGeneratorContext(int statusDepth, const Parameter::Common& common)
: EffectContext(statusDepth, common) {
- LOG(DEBUG) << __func__;
mState = HAPTIC_GENERATOR_STATE_UNINITIALIZED;
mSampleRate = common.input.base.sampleRate;
mFrameCount = common.input.frameCount;
@@ -36,7 +35,6 @@
}
HapticGeneratorContext::~HapticGeneratorContext() {
- LOG(DEBUG) << __func__;
mState = HAPTIC_GENERATOR_STATE_UNINITIALIZED;
}
@@ -70,7 +68,6 @@
RetCode HapticGeneratorContext::setHgHapticScales(
const std::vector<HapticGenerator::HapticScale>& hapticScales) {
- std::lock_guard lg(mMutex);
for (auto hapticScale : hapticScales) {
mParams.mHapticScales.insert_or_assign(hapticScale.id, hapticScale.scale);
}
@@ -82,13 +79,11 @@
}
HapticGenerator::VibratorInformation HapticGeneratorContext::getHgVibratorInformation() {
- std::lock_guard lg(mMutex);
return mParams.mVibratorInfo;
}
std::vector<HapticGenerator::HapticScale> HapticGeneratorContext::getHgHapticScales() {
std::vector<HapticGenerator::HapticScale> result;
- std::lock_guard lg(mMutex);
for (const auto& [id, vibratorScale] : mParams.mHapticScales) {
result.push_back({id, vibratorScale});
}
@@ -97,30 +92,23 @@
RetCode HapticGeneratorContext::setHgVibratorInformation(
const HapticGenerator::VibratorInformation& vibratorInfo) {
- {
- std::lock_guard lg(mMutex);
- mParams.mVibratorInfo = vibratorInfo;
+ mParams.mVibratorInfo = vibratorInfo;
- if (mProcessorsRecord.bpf != nullptr) {
- mProcessorsRecord.bpf->setCoefficients(
- ::android::audio_effect::haptic_generator::bpfCoefs(
- mParams.mVibratorInfo.resonantFrequencyHz, DEFAULT_BPF_Q, mSampleRate));
- }
- if (mProcessorsRecord.bsf != nullptr) {
- mProcessorsRecord.bsf->setCoefficients(
- ::android::audio_effect::haptic_generator::bsfCoefs(
- mParams.mVibratorInfo.resonantFrequencyHz,
- mParams.mVibratorInfo.qFactor, mParams.mVibratorInfo.qFactor / 2.0f,
- mSampleRate));
- }
+ if (mProcessorsRecord.bpf != nullptr) {
+ mProcessorsRecord.bpf->setCoefficients(::android::audio_effect::haptic_generator::bpfCoefs(
+ mParams.mVibratorInfo.resonantFrequencyHz, DEFAULT_BPF_Q, mSampleRate));
}
+ if (mProcessorsRecord.bsf != nullptr) {
+ mProcessorsRecord.bsf->setCoefficients(::android::audio_effect::haptic_generator::bsfCoefs(
+ mParams.mVibratorInfo.resonantFrequencyHz, mParams.mVibratorInfo.qFactor,
+ mParams.mVibratorInfo.qFactor / 2.0f, mSampleRate));
+ }
+
configure();
return RetCode::SUCCESS;
}
IEffect::Status HapticGeneratorContext::process(float* in, float* out, int samples) {
- LOG(DEBUG) << __func__ << " in " << in << " out " << out << " sample " << samples;
-
IEffect::Status status = {EX_NULL_POINTER, 0, 0};
RETURN_VALUE_IF(!in, status, "nullInput");
RETURN_VALUE_IF(!out, status, "nullOutput");
@@ -129,17 +117,11 @@
auto frameSize = getInputFrameSize();
RETURN_VALUE_IF(0 == frameSize, status, "zeroFrameSize");
- LOG(DEBUG) << __func__ << " start processing";
// The audio data must not be modified but just written to
// output buffer according the access mode.
- bool accumulate = false;
if (in != out) {
for (int i = 0; i < samples; i++) {
- if (accumulate) {
- out[i] += in[i];
- } else {
- out[i] = in[i];
- }
+ out[i] = in[i];
}
}
@@ -147,7 +129,6 @@
return status;
}
- std::lock_guard lg(mMutex);
if (mParams.mMaxVibratorScale == HapticGenerator::VibratorScale::MUTE) {
// Haptic channels are muted, not need to generate haptic data.
return {STATUS_OK, samples, samples};
@@ -189,7 +170,6 @@
void HapticGeneratorContext::init_params(media::audio::common::AudioChannelLayout inputChMask,
media::audio::common::AudioChannelLayout outputChMask) {
- std::lock_guard lg(mMutex);
mParams.mMaxVibratorScale = HapticGenerator::VibratorScale::MUTE;
mParams.mVibratorInfo.resonantFrequencyHz = DEFAULT_RESONANT_FREQUENCY;
mParams.mVibratorInfo.qFactor = DEFAULT_BSF_ZERO_Q;
@@ -210,7 +190,6 @@
float HapticGeneratorContext::getDistortionOutputGain() {
float distortionOutputGain = getFloatProperty(
"vendor.audio.hapticgenerator.distortion.output.gain", DEFAULT_DISTORTION_OUTPUT_GAIN);
- LOG(DEBUG) << "Using distortion output gain as " << distortionOutputGain;
return distortionOutputGain;
}
@@ -237,7 +216,6 @@
* Build haptic generator processing chain.
*/
void HapticGeneratorContext::buildProcessingChain() {
- std::lock_guard lg(mMutex);
const size_t channelCount = mParams.mHapticChannelCount;
float highPassCornerFrequency = 50.0f;
auto hpf = ::android::audio_effect::haptic_generator::createHPF2(highPassCornerFrequency,
diff --git a/media/libeffects/hapticgenerator/aidl/HapticGeneratorContext.h b/media/libeffects/hapticgenerator/aidl/HapticGeneratorContext.h
index 8618b7b..3a2ad1c 100644
--- a/media/libeffects/hapticgenerator/aidl/HapticGeneratorContext.h
+++ b/media/libeffects/hapticgenerator/aidl/HapticGeneratorContext.h
@@ -16,7 +16,6 @@
#pragma once
-#include <android-base/thread_annotations.h>
#include <vibrator/ExternalVibrationUtils.h>
#include <map>
@@ -88,9 +87,8 @@
static constexpr float DEFAULT_DISTORTION_INPUT_GAIN = 0.3f;
static constexpr float DEFAULT_DISTORTION_CUBE_THRESHOLD = 0.1f;
- std::mutex mMutex;
HapticGeneratorState mState;
- HapticGeneratorParam mParams GUARDED_BY(mMutex);
+ HapticGeneratorParam mParams;
int mSampleRate;
int64_t mFrameCount = 0;
diff --git a/media/libeffects/loudness/Android.bp b/media/libeffects/loudness/Android.bp
index 46e4669..4f04ffb 100644
--- a/media/libeffects/loudness/Android.bp
+++ b/media/libeffects/loudness/Android.bp
@@ -48,10 +48,10 @@
cc_library_shared {
name: "libloudnessenhanceraidl",
srcs: [
+ ":effectCommonFile",
"aidl/EffectLoudnessEnhancer.cpp",
"aidl/LoudnessEnhancerContext.cpp",
"dsp/core/dynamic_range_compression.cpp",
- ":effectCommonFile",
],
defaults: [
"aidlaudioeffectservice_defaults",
diff --git a/media/libeffects/loudness/aidl/EffectLoudnessEnhancer.cpp b/media/libeffects/loudness/aidl/EffectLoudnessEnhancer.cpp
index bcf0db6..f89606e 100644
--- a/media/libeffects/loudness/aidl/EffectLoudnessEnhancer.cpp
+++ b/media/libeffects/loudness/aidl/EffectLoudnessEnhancer.cpp
@@ -37,7 +37,6 @@
}
if (instanceSpp) {
*instanceSpp = ndk::SharedRefBase::make<LoudnessEnhancerImpl>();
- LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
} else {
LOG(ERROR) << __func__ << " invalid input parameter!";
@@ -67,7 +66,6 @@
ndk::ScopedAStatus LoudnessEnhancerImpl::getDescriptor(Descriptor* _aidl_return) {
RETURN_IF(!_aidl_return, EX_ILLEGAL_ARGUMENT, "Parameter:nullptr");
- LOG(DEBUG) << __func__ << kDescriptor.toString();
*_aidl_return = kDescriptor;
return ndk::ScopedAStatus::ok();
}
diff --git a/media/libeffects/loudness/aidl/EffectLoudnessEnhancer.h b/media/libeffects/loudness/aidl/EffectLoudnessEnhancer.h
index e2e716c..98bdc6b 100644
--- a/media/libeffects/loudness/aidl/EffectLoudnessEnhancer.h
+++ b/media/libeffects/loudness/aidl/EffectLoudnessEnhancer.h
@@ -27,11 +27,8 @@
public:
static const std::string kEffectName;
static const Descriptor kDescriptor;
- LoudnessEnhancerImpl() { LOG(DEBUG) << __func__; }
- ~LoudnessEnhancerImpl() {
- cleanUp();
- LOG(DEBUG) << __func__;
- }
+ LoudnessEnhancerImpl() = default;
+ ~LoudnessEnhancerImpl() { cleanUp(); }
ndk::ScopedAStatus commandImpl(CommandId command) REQUIRES(mImplMutex) override;
ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
diff --git a/media/libeffects/loudness/aidl/LoudnessEnhancerContext.cpp b/media/libeffects/loudness/aidl/LoudnessEnhancerContext.cpp
index be914bf..d8bcfc0 100644
--- a/media/libeffects/loudness/aidl/LoudnessEnhancerContext.cpp
+++ b/media/libeffects/loudness/aidl/LoudnessEnhancerContext.cpp
@@ -24,16 +24,10 @@
LoudnessEnhancerContext::LoudnessEnhancerContext(int statusDepth, const Parameter::Common& common)
: EffectContext(statusDepth, common) {
- LOG(DEBUG) << __func__;
init_params();
}
-LoudnessEnhancerContext::~LoudnessEnhancerContext() {
- LOG(DEBUG) << __func__;
-}
-
RetCode LoudnessEnhancerContext::enable() {
- std::lock_guard lg(mMutex);
if (mState != LOUDNESS_ENHANCER_STATE_INITIALIZED) {
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
@@ -42,7 +36,6 @@
}
RetCode LoudnessEnhancerContext::disable() {
- std::lock_guard lg(mMutex);
if (mState != LOUDNESS_ENHANCER_STATE_ACTIVE) {
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
@@ -52,7 +45,6 @@
void LoudnessEnhancerContext::reset() {
float targetAmp = pow(10, mGain / 2000.0f); // mB to linear amplification
- std::lock_guard lg(mMutex);
if (mCompressor != nullptr) {
// Get samplingRate from input
mCompressor->Initialize(targetAmp, mCommon.input.base.sampleRate);
@@ -66,8 +58,6 @@
}
IEffect::Status LoudnessEnhancerContext::process(float* in, float* out, int samples) {
- LOG(DEBUG) << __func__ << " in " << in << " out " << out << " sample " << samples;
-
IEffect::Status status = {EX_NULL_POINTER, 0, 0};
RETURN_VALUE_IF(!in, status, "nullInput");
RETURN_VALUE_IF(!out, status, "nullOutput");
@@ -76,11 +66,9 @@
auto frameSize = getInputFrameSize();
RETURN_VALUE_IF(0 == frameSize, status, "zeroFrameSize");
- std::lock_guard lg(mMutex);
status = {STATUS_INVALID_OPERATION, 0, 0};
RETURN_VALUE_IF(mState != LOUDNESS_ENHANCER_STATE_ACTIVE, status, "stateNotActive");
- LOG(DEBUG) << __func__ << " start processing";
// PcmType is always expected to be Float 32 bit.
constexpr float scale = 1 << 15; // power of 2 is lossless conversion to int16_t range
constexpr float inverseScale = 1.f / scale;
@@ -124,9 +112,8 @@
mGain = LOUDNESS_ENHANCER_DEFAULT_TARGET_GAIN_MB;
float targetAmp = pow(10, mGain / 2000.0f); // mB to linear amplification
- LOG(DEBUG) << __func__ << "Target gain = " << mGain << "mB <=> factor = " << targetAmp;
+ LOG(VERBOSE) << __func__ << "Target gain = " << mGain << "mB <=> factor = " << targetAmp;
- std::lock_guard lg(mMutex);
mCompressor = std::make_unique<le_fx::AdaptiveDynamicRangeCompression>();
mCompressor->Initialize(targetAmp, mCommon.input.base.sampleRate);
mState = LOUDNESS_ENHANCER_STATE_INITIALIZED;
diff --git a/media/libeffects/loudness/aidl/LoudnessEnhancerContext.h b/media/libeffects/loudness/aidl/LoudnessEnhancerContext.h
index fd688d7..192b212 100644
--- a/media/libeffects/loudness/aidl/LoudnessEnhancerContext.h
+++ b/media/libeffects/loudness/aidl/LoudnessEnhancerContext.h
@@ -16,7 +16,6 @@
#pragma once
-#include <android-base/thread_annotations.h>
#include <audio_effects/effect_loudnessenhancer.h>
#include "dsp/core/dynamic_range_compression.h"
@@ -33,7 +32,7 @@
class LoudnessEnhancerContext final : public EffectContext {
public:
LoudnessEnhancerContext(int statusDepth, const Parameter::Common& common);
- ~LoudnessEnhancerContext();
+ ~LoudnessEnhancerContext() = default;
RetCode enable();
RetCode disable();
@@ -45,12 +44,11 @@
IEffect::Status process(float* in, float* out, int samples);
private:
- std::mutex mMutex;
- LoudnessEnhancerState mState GUARDED_BY(mMutex) = LOUDNESS_ENHANCER_STATE_UNINITIALIZED;
+ LoudnessEnhancerState mState = LOUDNESS_ENHANCER_STATE_UNINITIALIZED;
int mGain = LOUDNESS_ENHANCER_DEFAULT_TARGET_GAIN_MB;
// In this implementation, there is no coupling between the compression on the left and right
// channels
- std::unique_ptr<le_fx::AdaptiveDynamicRangeCompression> mCompressor GUARDED_BY(mMutex);
+ std::unique_ptr<le_fx::AdaptiveDynamicRangeCompression> mCompressor;
void init_params();
};
diff --git a/media/libeffects/lvm/lib/Android.bp b/media/libeffects/lvm/lib/Android.bp
index c1a77f0..02b918b 100644
--- a/media/libeffects/lvm/lib/Android.bp
+++ b/media/libeffects/lvm/lib/Android.bp
@@ -31,6 +31,60 @@
vendor: true,
host_supported: true,
srcs: [
+ "Bass/src/LVDBE_Control.cpp",
+ "Bass/src/LVDBE_Init.cpp",
+ "Bass/src/LVDBE_Process.cpp",
+ "Bass/src/LVDBE_Tables.cpp",
+ "Bundle/src/LVM_API_Specials.cpp",
+ "Bundle/src/LVM_Buffers.cpp",
+ "Bundle/src/LVM_Control.cpp",
+ "Bundle/src/LVM_Init.cpp",
+ "Bundle/src/LVM_Process.cpp",
+ "Bundle/src/LVM_Tables.cpp",
+ "Common/src/AGC_MIX_VOL_2St1Mon_D32_WRA.cpp",
+ "Common/src/Add2_Sat_32x32.cpp",
+ "Common/src/Copy_16.cpp",
+ "Common/src/DC_2I_D16_TRC_WRA_01.cpp",
+ "Common/src/DC_2I_D16_TRC_WRA_01_Init.cpp",
+ "Common/src/DelayMix_16x16.cpp",
+ "Common/src/From2iToMS_16x16.cpp",
+ "Common/src/From2iToMono_32.cpp",
+ "Common/src/LVC_Core_MixHard_1St_2i_D16C31_SAT.cpp",
+ "Common/src/LVC_Core_MixHard_2St_D16C31_SAT.cpp",
+ "Common/src/LVC_Core_MixInSoft_D16C31_SAT.cpp",
+ "Common/src/LVC_Core_MixSoft_1St_2i_D16C31_WRA.cpp",
+ "Common/src/LVC_Core_MixSoft_1St_D16C31_WRA.cpp",
+ "Common/src/LVC_MixInSoft_D16C31_SAT.cpp",
+ "Common/src/LVC_MixSoft_1St_2i_D16C31_SAT.cpp",
+ "Common/src/LVC_MixSoft_1St_D16C31_SAT.cpp",
+ "Common/src/LVC_MixSoft_2St_D16C31_SAT.cpp",
+ "Common/src/LVC_Mixer_GetCurrent.cpp",
+ "Common/src/LVC_Mixer_GetTarget.cpp",
+ "Common/src/LVC_Mixer_Init.cpp",
+ "Common/src/LVC_Mixer_SetTarget.cpp",
+ "Common/src/LVC_Mixer_SetTimeConstant.cpp",
+ "Common/src/LVC_Mixer_VarSlope_SetTimeConstant.cpp",
+ "Common/src/LVM_Timer.cpp",
+ "Common/src/LVM_Timer_Init.cpp",
+ "Common/src/MSTo2i_Sat_16x16.cpp",
+ "Common/src/Mac3s_Sat_32x16.cpp",
+ "Common/src/MonoTo2I_32.cpp",
+ "Common/src/Mult3s_32x16.cpp",
+ "Common/src/NonLinComp_D16.cpp",
+ "Common/src/Shift_Sat_v16xv16.cpp",
+ "Common/src/Shift_Sat_v32xv32.cpp",
+ "Common/src/dB_to_Lin32.cpp",
+ "Eq/src/LVEQNB_CalcCoef.cpp",
+ "Eq/src/LVEQNB_Control.cpp",
+ "Eq/src/LVEQNB_Init.cpp",
+ "Eq/src/LVEQNB_Process.cpp",
+ "Eq/src/LVEQNB_Tables.cpp",
+ "SpectrumAnalyzer/src/LVPSA_Control.cpp",
+ "SpectrumAnalyzer/src/LVPSA_Init.cpp",
+ "SpectrumAnalyzer/src/LVPSA_Process.cpp",
+ "SpectrumAnalyzer/src/LVPSA_QPD_Init.cpp",
+ "SpectrumAnalyzer/src/LVPSA_QPD_Process.cpp",
+ "SpectrumAnalyzer/src/LVPSA_Tables.cpp",
"StereoWidening/src/LVCS_BypassMix.cpp",
"StereoWidening/src/LVCS_Control.cpp",
"StereoWidening/src/LVCS_Equaliser.cpp",
@@ -39,77 +93,23 @@
"StereoWidening/src/LVCS_ReverbGenerator.cpp",
"StereoWidening/src/LVCS_StereoEnhancer.cpp",
"StereoWidening/src/LVCS_Tables.cpp",
- "Bass/src/LVDBE_Control.cpp",
- "Bass/src/LVDBE_Init.cpp",
- "Bass/src/LVDBE_Process.cpp",
- "Bass/src/LVDBE_Tables.cpp",
- "Bundle/src/LVM_API_Specials.cpp",
- "Bundle/src/LVM_Buffers.cpp",
- "Bundle/src/LVM_Init.cpp",
- "Bundle/src/LVM_Process.cpp",
- "Bundle/src/LVM_Tables.cpp",
- "Bundle/src/LVM_Control.cpp",
- "SpectrumAnalyzer/src/LVPSA_Control.cpp",
- "SpectrumAnalyzer/src/LVPSA_Init.cpp",
- "SpectrumAnalyzer/src/LVPSA_Process.cpp",
- "SpectrumAnalyzer/src/LVPSA_QPD_Init.cpp",
- "SpectrumAnalyzer/src/LVPSA_QPD_Process.cpp",
- "SpectrumAnalyzer/src/LVPSA_Tables.cpp",
- "Eq/src/LVEQNB_CalcCoef.cpp",
- "Eq/src/LVEQNB_Control.cpp",
- "Eq/src/LVEQNB_Init.cpp",
- "Eq/src/LVEQNB_Process.cpp",
- "Eq/src/LVEQNB_Tables.cpp",
- "Common/src/DC_2I_D16_TRC_WRA_01.cpp",
- "Common/src/DC_2I_D16_TRC_WRA_01_Init.cpp",
- "Common/src/Copy_16.cpp",
- "Common/src/MonoTo2I_32.cpp",
- "Common/src/dB_to_Lin32.cpp",
- "Common/src/Shift_Sat_v16xv16.cpp",
- "Common/src/Shift_Sat_v32xv32.cpp",
- "Common/src/From2iToMono_32.cpp",
- "Common/src/Mult3s_32x16.cpp",
- "Common/src/NonLinComp_D16.cpp",
- "Common/src/DelayMix_16x16.cpp",
- "Common/src/MSTo2i_Sat_16x16.cpp",
- "Common/src/From2iToMS_16x16.cpp",
- "Common/src/Mac3s_Sat_32x16.cpp",
- "Common/src/Add2_Sat_32x32.cpp",
- "Common/src/LVC_MixSoft_1St_2i_D16C31_SAT.cpp",
- "Common/src/LVC_MixSoft_1St_D16C31_SAT.cpp",
- "Common/src/LVC_Mixer_VarSlope_SetTimeConstant.cpp",
- "Common/src/LVC_Mixer_SetTimeConstant.cpp",
- "Common/src/LVC_Mixer_SetTarget.cpp",
- "Common/src/LVC_Mixer_GetTarget.cpp",
- "Common/src/LVC_Mixer_Init.cpp",
- "Common/src/LVC_Core_MixHard_1St_2i_D16C31_SAT.cpp",
- "Common/src/LVC_Core_MixSoft_1St_2i_D16C31_WRA.cpp",
- "Common/src/LVC_Core_MixInSoft_D16C31_SAT.cpp",
- "Common/src/LVC_Mixer_GetCurrent.cpp",
- "Common/src/LVC_MixSoft_2St_D16C31_SAT.cpp",
- "Common/src/LVC_Core_MixSoft_1St_D16C31_WRA.cpp",
- "Common/src/LVC_Core_MixHard_2St_D16C31_SAT.cpp",
- "Common/src/LVC_MixInSoft_D16C31_SAT.cpp",
- "Common/src/AGC_MIX_VOL_2St1Mon_D32_WRA.cpp",
- "Common/src/LVM_Timer.cpp",
- "Common/src/LVM_Timer_Init.cpp",
],
local_include_dirs: [
- "Eq/lib",
- "Eq/src",
"Bass/lib",
"Bass/src",
- "Common/src",
"Bundle/src",
+ "Common/src",
+ "Eq/lib",
+ "Eq/src",
"SpectrumAnalyzer/lib",
"SpectrumAnalyzer/src",
- "StereoWidening/src",
"StereoWidening/lib",
+ "StereoWidening/src",
],
export_include_dirs: [
- "Common/lib",
"Bundle/lib",
+ "Common/lib",
],
shared_libs: [
"liblog",
@@ -121,9 +121,9 @@
"libhardware_headers",
],
cppflags: [
- "-fvisibility=hidden",
"-Wall",
"-Werror",
+ "-fvisibility=hidden",
],
}
@@ -141,6 +141,26 @@
vendor: true,
host_supported: true,
srcs: [
+ "Common/src/Add2_Sat_32x32.cpp",
+ "Common/src/Copy_16.cpp",
+ "Common/src/Core_MixHard_2St_D32C31_SAT.cpp",
+ "Common/src/Core_MixInSoft_D32C31_SAT.cpp",
+ "Common/src/Core_MixSoft_1St_D32C31_WRA.cpp",
+ "Common/src/From2iToMono_32.cpp",
+ "Common/src/JoinTo2i_32x32.cpp",
+ "Common/src/LVM_FO_HPF.cpp",
+ "Common/src/LVM_FO_LPF.cpp",
+ "Common/src/LVM_GetOmega.cpp",
+ "Common/src/LVM_Mixer_TimeConstant.cpp",
+ "Common/src/LVM_Polynomial.cpp",
+ "Common/src/LVM_Power10.cpp",
+ "Common/src/Mac3s_Sat_32x16.cpp",
+ "Common/src/MixInSoft_D32C31_SAT.cpp",
+ "Common/src/MixSoft_1St_D32C31_WRA.cpp",
+ "Common/src/MixSoft_2St_D32C31_SAT.cpp",
+ "Common/src/MonoTo2I_32.cpp",
+ "Common/src/Mult3s_32x16.cpp",
+ "Common/src/Shift_Sat_v32xv32.cpp",
"Reverb/src/LVREV_ApplyNewSettings.cpp",
"Reverb/src/LVREV_ClearAudioBuffers.cpp",
"Reverb/src/LVREV_GetControlParameters.cpp",
@@ -148,42 +168,22 @@
"Reverb/src/LVREV_Process.cpp",
"Reverb/src/LVREV_SetControlParameters.cpp",
"Reverb/src/LVREV_Tables.cpp",
- "Common/src/From2iToMono_32.cpp",
- "Common/src/Mult3s_32x16.cpp",
- "Common/src/Copy_16.cpp",
- "Common/src/Mac3s_Sat_32x16.cpp",
- "Common/src/Shift_Sat_v32xv32.cpp",
- "Common/src/Add2_Sat_32x32.cpp",
- "Common/src/JoinTo2i_32x32.cpp",
- "Common/src/MonoTo2I_32.cpp",
- "Common/src/LVM_FO_HPF.cpp",
- "Common/src/LVM_FO_LPF.cpp",
- "Common/src/LVM_Polynomial.cpp",
- "Common/src/LVM_Power10.cpp",
- "Common/src/LVM_GetOmega.cpp",
- "Common/src/MixSoft_2St_D32C31_SAT.cpp",
- "Common/src/MixSoft_1St_D32C31_WRA.cpp",
- "Common/src/MixInSoft_D32C31_SAT.cpp",
- "Common/src/LVM_Mixer_TimeConstant.cpp",
- "Common/src/Core_MixHard_2St_D32C31_SAT.cpp",
- "Common/src/Core_MixSoft_1St_D32C31_WRA.cpp",
- "Common/src/Core_MixInSoft_D32C31_SAT.cpp",
],
local_include_dirs: [
- "Reverb/src",
"Common/src",
+ "Reverb/src",
],
export_include_dirs: [
- "Reverb/lib",
"Common/lib",
+ "Reverb/lib",
],
static_libs: [
"libaudioutils",
],
cppflags: [
- "-fvisibility=hidden",
"-Wall",
"-Werror",
+ "-fvisibility=hidden",
],
}
diff --git a/media/libeffects/lvm/wrapper/Aidl/BundleContext.cpp b/media/libeffects/lvm/wrapper/Aidl/BundleContext.cpp
index aa18deb..90406e9 100644
--- a/media/libeffects/lvm/wrapper/Aidl/BundleContext.cpp
+++ b/media/libeffects/lvm/wrapper/Aidl/BundleContext.cpp
@@ -36,20 +36,16 @@
BundleContext::BundleContext(int statusDepth, const Parameter::Common& common,
const lvm::BundleEffectType& type)
: EffectContext(statusDepth, common), mType(type) {
- LOG(DEBUG) << __func__ << type;
-
int inputChannelCount = ::aidl::android::hardware::audio::common::getChannelCount(
common.input.base.channelMask);
mSamplesPerSecond = common.input.base.sampleRate * inputChannelCount;
}
BundleContext::~BundleContext() {
- LOG(DEBUG) << __func__;
deInit();
}
RetCode BundleContext::init() {
- std::lock_guard lg(mMutex);
// init with pre-defined preset NORMAL
for (std::size_t i = 0; i < lvm::MAX_NUM_BANDS; i++) {
mBandGainmB[i] = lvm::kSoftPresets[0 /* normal */][i] * 100;
@@ -88,7 +84,6 @@
}
void BundleContext::deInit() {
- std::lock_guard lg(mMutex);
if (mInstance) {
LVM_DelInstanceHandle(&mInstance);
mInstance = nullptr;
@@ -102,27 +97,23 @@
bool tempDisabled = false;
switch (mType) {
case lvm::BundleEffectType::EQUALIZER:
- LOG(DEBUG) << __func__ << " enable bundle EQ";
if (mSamplesToExitCountEq <= 0) mNumberEffectsEnabled++;
mSamplesToExitCountEq = (mSamplesPerSecond * 0.1);
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::EQUALIZER));
break;
case lvm::BundleEffectType::BASS_BOOST:
- LOG(DEBUG) << __func__ << " enable bundle BB";
if (mSamplesToExitCountBb <= 0) mNumberEffectsEnabled++;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::BASS_BOOST));
mSamplesToExitCountBb = (mSamplesPerSecond * 0.1);
tempDisabled = mBassTempDisabled;
break;
case lvm::BundleEffectType::VIRTUALIZER:
- LOG(DEBUG) << __func__ << " enable bundle VR";
if (mSamplesToExitCountVirt <= 0) mNumberEffectsEnabled++;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::VIRTUALIZER));
mSamplesToExitCountVirt = (mSamplesPerSecond * 0.1);
tempDisabled = mVirtualizerTempDisabled;
break;
case lvm::BundleEffectType::VOLUME:
- LOG(DEBUG) << __func__ << " enable bundle VOL";
if ((mEffectInDrain & (1 << int(lvm::BundleEffectType::VOLUME))) == 0)
mNumberEffectsEnabled++;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::VOLUME));
@@ -134,30 +125,24 @@
RetCode BundleContext::enableOperatingMode() {
LVM_ControlParams_t params;
- {
- std::lock_guard lg(mMutex);
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, "failGetControlParams");
- switch (mType) {
- case lvm::BundleEffectType::EQUALIZER:
- LOG(DEBUG) << __func__ << " enable bundle EQ";
- params.EQNB_OperatingMode = LVM_EQNB_ON;
- break;
- case lvm::BundleEffectType::BASS_BOOST:
- LOG(DEBUG) << __func__ << " enable bundle BB";
- params.BE_OperatingMode = LVM_BE_ON;
- break;
- case lvm::BundleEffectType::VIRTUALIZER:
- LOG(DEBUG) << __func__ << " enable bundle VR";
- params.VirtualizerOperatingMode = LVM_MODE_ON;
- break;
- case lvm::BundleEffectType::VOLUME:
- LOG(DEBUG) << __func__ << " enable bundle VOL";
- break;
- }
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, "failSetControlParams");
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, "failGetControlParams");
+ switch (mType) {
+ case lvm::BundleEffectType::EQUALIZER:
+ params.EQNB_OperatingMode = LVM_EQNB_ON;
+ break;
+ case lvm::BundleEffectType::BASS_BOOST:
+ params.BE_OperatingMode = LVM_BE_ON;
+ break;
+ case lvm::BundleEffectType::VIRTUALIZER:
+ params.VirtualizerOperatingMode = LVM_MODE_ON;
+ break;
+ case lvm::BundleEffectType::VOLUME:
+ break;
}
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, "failSetControlParams");
+
return limitLevel();
}
@@ -165,19 +150,15 @@
if (!mEnabled) return RetCode::ERROR_ILLEGAL_PARAMETER;
switch (mType) {
case lvm::BundleEffectType::EQUALIZER:
- LOG(DEBUG) << __func__ << " disable bundle EQ";
mEffectInDrain |= 1 << int(lvm::BundleEffectType::EQUALIZER);
break;
case lvm::BundleEffectType::BASS_BOOST:
- LOG(DEBUG) << __func__ << " disable bundle BB";
mEffectInDrain |= 1 << int(lvm::BundleEffectType::BASS_BOOST);
break;
case lvm::BundleEffectType::VIRTUALIZER:
- LOG(DEBUG) << __func__ << " disable bundle VR";
mEffectInDrain |= 1 << int(lvm::BundleEffectType::VIRTUALIZER);
break;
case lvm::BundleEffectType::VOLUME:
- LOG(DEBUG) << __func__ << " disable bundle VOL";
mEffectInDrain |= 1 << int(lvm::BundleEffectType::VOLUME);
break;
}
@@ -187,30 +168,23 @@
RetCode BundleContext::disableOperatingMode() {
LVM_ControlParams_t params;
- {
- std::lock_guard lg(mMutex);
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, "failGetControlParams");
- switch (mType) {
- case lvm::BundleEffectType::EQUALIZER:
- LOG(DEBUG) << __func__ << " disable bundle EQ";
- params.EQNB_OperatingMode = LVM_EQNB_OFF;
- break;
- case lvm::BundleEffectType::BASS_BOOST:
- LOG(DEBUG) << __func__ << " disable bundle BB";
- params.BE_OperatingMode = LVM_BE_OFF;
- break;
- case lvm::BundleEffectType::VIRTUALIZER:
- LOG(DEBUG) << __func__ << " disable bundle VR";
- params.VirtualizerOperatingMode = LVM_MODE_OFF;
- break;
- case lvm::BundleEffectType::VOLUME:
- LOG(DEBUG) << __func__ << " disable bundle VOL";
- break;
- }
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, "failSetControlParams");
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, "failGetControlParams");
+ switch (mType) {
+ case lvm::BundleEffectType::EQUALIZER:
+ params.EQNB_OperatingMode = LVM_EQNB_OFF;
+ break;
+ case lvm::BundleEffectType::BASS_BOOST:
+ params.BE_OperatingMode = LVM_BE_OFF;
+ break;
+ case lvm::BundleEffectType::VIRTUALIZER:
+ params.VirtualizerOperatingMode = LVM_MODE_OFF;
+ break;
+ case lvm::BundleEffectType::VOLUME:
+ break;
}
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, "failSetControlParams");
mEnabled = false;
return limitLevel();
}
@@ -223,89 +197,80 @@
float energyBassBoost = 0;
float crossCorrection = 0;
LVM_ControlParams_t params;
- {
- std::lock_guard lg(mMutex);
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");
- bool eqEnabled = params.EQNB_OperatingMode == LVM_EQNB_ON;
- bool bbEnabled = params.BE_OperatingMode == LVM_BE_ON;
- bool viEnabled = params.VirtualizerOperatingMode == LVM_MODE_ON;
+ bool eqEnabled = params.EQNB_OperatingMode == LVM_EQNB_ON;
+ bool bbEnabled = params.BE_OperatingMode == LVM_BE_ON;
+ bool viEnabled = params.VirtualizerOperatingMode == LVM_MODE_ON;
+
+ if (eqEnabled) {
+ for (unsigned int i = 0; i < lvm::MAX_NUM_BANDS; i++) {
+ float bandFactor = mBandGainmB[i] / 1500.0;
+ float bandCoefficient = lvm::kBandEnergyCoefficient[i];
+ float bandEnergy = bandFactor * bandCoefficient * bandCoefficient;
+ if (bandEnergy > 0) energyContribution += bandEnergy;
+ }
+
+ // cross EQ coefficients
+ float bandFactorSum = 0;
+ for (unsigned int i = 0; i < lvm::MAX_NUM_BANDS - 1; i++) {
+ float bandFactor1 = mBandGainmB[i] / 1500.0;
+ float bandFactor2 = mBandGainmB[i + 1] / 1500.0;
+
+ if (bandFactor1 > 0 && bandFactor2 > 0) {
+ float crossEnergy =
+ bandFactor1 * bandFactor2 * lvm::kBandEnergyCrossCoefficient[i];
+ bandFactorSum += bandFactor1 * bandFactor2;
+
+ if (crossEnergy > 0) energyCross += crossEnergy;
+ }
+ }
+ bandFactorSum -= 1.0;
+ if (bandFactorSum > 0) crossCorrection = bandFactorSum * 0.7;
+ }
+ // BassBoost contribution
+ if (bbEnabled) {
+ float boostFactor = mBassStrengthSaved / 1000.0;
+ float boostCoefficient = lvm::kBassBoostEnergyCoefficient;
+
+ energyContribution += boostFactor * boostCoefficient * boostCoefficient;
if (eqEnabled) {
for (unsigned int i = 0; i < lvm::MAX_NUM_BANDS; i++) {
float bandFactor = mBandGainmB[i] / 1500.0;
- float bandCoefficient = lvm::kBandEnergyCoefficient[i];
- float bandEnergy = bandFactor * bandCoefficient * bandCoefficient;
- if (bandEnergy > 0) energyContribution += bandEnergy;
- }
-
- // cross EQ coefficients
- float bandFactorSum = 0;
- for (unsigned int i = 0; i < lvm::MAX_NUM_BANDS - 1; i++) {
- float bandFactor1 = mBandGainmB[i] / 1500.0;
- float bandFactor2 = mBandGainmB[i + 1] / 1500.0;
-
- if (bandFactor1 > 0 && bandFactor2 > 0) {
- float crossEnergy =
- bandFactor1 * bandFactor2 * lvm::kBandEnergyCrossCoefficient[i];
- bandFactorSum += bandFactor1 * bandFactor2;
-
- if (crossEnergy > 0) energyCross += crossEnergy;
- }
- }
- bandFactorSum -= 1.0;
- if (bandFactorSum > 0) crossCorrection = bandFactorSum * 0.7;
- }
- // BassBoost contribution
- if (bbEnabled) {
- float boostFactor = mBassStrengthSaved / 1000.0;
- float boostCoefficient = lvm::kBassBoostEnergyCoefficient;
-
- energyContribution += boostFactor * boostCoefficient * boostCoefficient;
-
- if (eqEnabled) {
- for (unsigned int i = 0; i < lvm::MAX_NUM_BANDS; i++) {
- float bandFactor = mBandGainmB[i] / 1500.0;
- float bandCrossCoefficient = lvm::kBassBoostEnergyCrossCoefficient[i];
- float bandEnergy = boostFactor * bandFactor * bandCrossCoefficient;
- if (bandEnergy > 0) energyBassBoost += bandEnergy;
- }
+ float bandCrossCoefficient = lvm::kBassBoostEnergyCrossCoefficient[i];
+ float bandEnergy = boostFactor * bandFactor * bandCrossCoefficient;
+ if (bandEnergy > 0) energyBassBoost += bandEnergy;
}
}
- // Virtualizer contribution
- if (viEnabled) {
- energyContribution += lvm::kVirtualizerContribution * lvm::kVirtualizerContribution;
- }
+ }
+ // Virtualizer contribution
+ if (viEnabled) {
+ energyContribution += lvm::kVirtualizerContribution * lvm::kVirtualizerContribution;
+ }
- double totalEnergyEstimation =
- sqrt(energyContribution + energyCross + energyBassBoost) - crossCorrection;
- LOG(INFO) << " TOTAL energy estimation: " << totalEnergyEstimation << " dB";
+ double totalEnergyEstimation =
+ sqrt(energyContribution + energyCross + energyBassBoost) - crossCorrection;
- // roundoff
- int maxLevelRound = (int)(totalEnergyEstimation + 0.99);
- if (maxLevelRound + mVolumedB > 0) {
- gainCorrection = maxLevelRound + mVolumedB;
- }
+ // roundoff
+ int maxLevelRound = (int)(totalEnergyEstimation + 0.99);
+ if (maxLevelRound + mVolumedB > 0) {
+ gainCorrection = maxLevelRound + mVolumedB;
+ }
- params.VC_EffectLevel = mVolumedB - gainCorrection;
- if (params.VC_EffectLevel < -96) {
- params.VC_EffectLevel = -96;
- }
- LOG(INFO) << "\tVol: " << mVolumedB << ", GainCorrection: " << gainCorrection
- << ", Actual vol: " << params.VC_EffectLevel;
+ params.VC_EffectLevel = mVolumedB - gainCorrection;
+ if (params.VC_EffectLevel < -96) {
+ params.VC_EffectLevel = -96;
+ }
+ /* Activate the initial settings */
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
- /* Activate the initial settings */
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
-
- if (mFirstVolume) {
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetVolumeNoSmoothing(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " setVolumeNoSmoothingFailed");
- LOG(INFO) << "\tLVM_VOLUME: Disabling Smoothing for first volume change to remove "
- "spikes/clicks";
- mFirstVolume = false;
- }
+ if (mFirstVolume) {
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetVolumeNoSmoothing(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " setVolumeNoSmoothingFailed");
+ mFirstVolume = false;
}
return RetCode::SUCCESS;
@@ -439,17 +404,13 @@
float maxdB = std::max(leftdB, rightdB);
float pandB = rightdB - leftdB;
setVolumeLevel(maxdB);
- LOG(DEBUG) << __func__ << " pandB: " << pandB << " maxdB " << maxdB;
- {
- std::lock_guard lg(mMutex);
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, "");
- params.VC_Balance = pandB;
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, "");
+ params.VC_Balance = pandB;
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, "");
- }
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, "");
mVolumeStereo = volume;
return RetCode::SUCCESS;
}
@@ -469,7 +430,6 @@
RetCode ret = updateControlParameter(bandLevels);
if (RetCode::SUCCESS == ret) {
mCurPresetIdx = presetIdx;
- LOG(INFO) << __func__ << " success with " << presetIdx;
} else {
LOG(ERROR) << __func__ << " failed to setPreset " << presetIdx;
}
@@ -483,7 +443,6 @@
RetCode ret = updateControlParameter(bandLevels);
if (RetCode::SUCCESS == ret) {
mCurPresetIdx = lvm::PRESET_CUSTOM;
- LOG(INFO) << __func__ << " succeed with " << ::android::internal::ToString(bandLevels);
} else {
LOG(ERROR) << __func__ << " failed with " << ::android::internal::ToString(bandLevels);
}
@@ -502,14 +461,11 @@
std::vector<int32_t> BundleContext::getEqualizerCenterFreqs() {
std::vector<int32_t> freqs;
LVM_ControlParams_t params;
- {
- std::lock_guard lg(mMutex);
- /* Get the current settings */
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms), freqs,
- " getControlParamFailed");
- for (std::size_t i = 0; i < lvm::MAX_NUM_BANDS; i++) {
- freqs.push_back((int32_t)params.pEQNB_BandDefinition[i].Frequency * 1000);
- }
+ /* Get the current settings */
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms), freqs,
+ " getControlParamFailed");
+ for (std::size_t i = 0; i < lvm::MAX_NUM_BANDS; i++) {
+ freqs.push_back((int32_t)params.pEQNB_BandDefinition[i].Frequency * 1000);
}
return freqs;
@@ -533,44 +489,36 @@
}
LVM_ControlParams_t params;
- {
- std::lock_guard lg(mMutex);
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");
- for (std::size_t i = 0; i < lvm::MAX_NUM_BANDS; i++) {
- params.pEQNB_BandDefinition[i].Frequency = lvm::kPresetsFrequencies[i];
- params.pEQNB_BandDefinition[i].QFactor = lvm::kPresetsQFactors[i];
- params.pEQNB_BandDefinition[i].Gain =
- tempLevel[i] > 0 ? (tempLevel[i] + 50) / 100 : (tempLevel[i] - 50) / 100;
- }
-
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
+ for (std::size_t i = 0; i < lvm::MAX_NUM_BANDS; i++) {
+ params.pEQNB_BandDefinition[i].Frequency = lvm::kPresetsFrequencies[i];
+ params.pEQNB_BandDefinition[i].QFactor = lvm::kPresetsQFactors[i];
+ params.pEQNB_BandDefinition[i].Gain =
+ tempLevel[i] > 0 ? (tempLevel[i] + 50) / 100 : (tempLevel[i] - 50) / 100;
}
- mBandGainmB = tempLevel;
- LOG(DEBUG) << __func__ << " update bandGain to " << ::android::internal::ToString(mBandGainmB)
- << "mdB";
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
+
+ mBandGainmB = tempLevel;
return RetCode::SUCCESS;
}
RetCode BundleContext::setBassBoostStrength(int strength) {
// Update Control Parameter
LVM_ControlParams_t params;
- {
- std::lock_guard lg(mMutex);
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");
- params.BE_EffectLevel = (LVM_INT16)((15 * strength) / 1000);
- params.BE_CentreFreq = LVM_BE_CENTRE_90Hz;
+ params.BE_EffectLevel = (LVM_INT16)((15 * strength) / 1000);
+ params.BE_CentreFreq = LVM_BE_CENTRE_90Hz;
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
- }
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
+
mBassStrengthSaved = strength;
- LOG(INFO) << __func__ << " success with strength " << strength;
return limitLevel();
}
@@ -580,7 +528,6 @@
} else {
mVolumedB = level;
}
- LOG(INFO) << __func__ << " success with level " << level;
return limitLevel();
}
@@ -602,19 +549,15 @@
RetCode BundleContext::setVirtualizerStrength(int strength) {
// Update Control Parameter
LVM_ControlParams_t params;
- {
- std::lock_guard lg(mMutex);
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_GetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");
- params.CS_EffectLevel = ((strength * 32767) / 1000);
+ params.CS_EffectLevel = ((strength * 32767) / 1000);
- RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
- RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
- }
+ RETURN_VALUE_IF(LVM_SUCCESS != LVM_SetControlParameters(mInstance, ¶ms),
+ RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
mVirtStrengthSaved = strength;
- LOG(INFO) << __func__ << " success with strength " << strength;
return limitLevel();
}
@@ -760,29 +703,24 @@
auto frameSize = getInputFrameSize();
RETURN_VALUE_IF(0 == frameSize, status, "zeroFrameSize");
- LOG(DEBUG) << __func__ << " start processing";
if ((mEffectProcessCalled & 1 << int(mType)) != 0) {
const int undrainedEffects = mEffectInDrain & ~mEffectProcessCalled;
if ((undrainedEffects & 1 << int(lvm::BundleEffectType::EQUALIZER)) != 0) {
- LOG(DEBUG) << "Draining EQUALIZER";
mSamplesToExitCountEq = 0;
--mNumberEffectsEnabled;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::EQUALIZER));
}
if ((undrainedEffects & 1 << int(lvm::BundleEffectType::BASS_BOOST)) != 0) {
- LOG(DEBUG) << "Draining BASS_BOOST";
mSamplesToExitCountBb = 0;
--mNumberEffectsEnabled;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::BASS_BOOST));
}
if ((undrainedEffects & 1 << int(lvm::BundleEffectType::VIRTUALIZER)) != 0) {
- LOG(DEBUG) << "Draining VIRTUALIZER";
mSamplesToExitCountVirt = 0;
--mNumberEffectsEnabled;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::VIRTUALIZER));
}
if ((undrainedEffects & 1 << int(lvm::BundleEffectType::VOLUME)) != 0) {
- LOG(DEBUG) << "Draining VOLUME";
--mNumberEffectsEnabled;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::VOLUME));
}
@@ -800,7 +738,6 @@
mNumberEffectsEnabled--;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::EQUALIZER));
}
- LOG(DEBUG) << "Effect_process() this is the last frame for EQUALIZER";
}
break;
case lvm::BundleEffectType::BASS_BOOST:
@@ -813,7 +750,6 @@
mNumberEffectsEnabled--;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::BASS_BOOST));
}
- LOG(DEBUG) << "Effect_process() this is the last frame for BASS_BOOST";
}
break;
case lvm::BundleEffectType::VIRTUALIZER:
@@ -826,7 +762,6 @@
mNumberEffectsEnabled--;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::VIRTUALIZER));
}
- LOG(DEBUG) << "Effect_process() this is the last frame for VIRTUALIZER";
}
break;
case lvm::BundleEffectType::VOLUME:
@@ -835,14 +770,13 @@
mNumberEffectsEnabled--;
mEffectInDrain &= ~(1 << int(lvm::BundleEffectType::VOLUME));
}
- LOG(DEBUG) << "Effect_process() LVM_VOLUME Effect is not enabled";
break;
}
}
if (isDataAvailable) {
mNumberEffectsCalled++;
}
- bool accumulate = false;
+
if (mNumberEffectsCalled >= mNumberEffectsEnabled) {
// We expect the # effects called to be equal to # effects enabled in sequence (including
// draining effects). Warn if this is not the case due to inconsistent calls.
@@ -850,9 +784,6 @@
"%s Number of effects called %d is greater than number of effects enabled %d",
__func__, mNumberEffectsCalled, mNumberEffectsEnabled);
mEffectProcessCalled = 0; // reset our consistency check.
- if (!isDataAvailable) {
- LOG(DEBUG) << "Effect_process() processing last frame";
- }
mNumberEffectsCalled = 0;
int frames = samples * sizeof(float) / frameSize;
int bufferIndex = 0;
@@ -862,38 +793,24 @@
constexpr int kMaxBlockFrames =
(std::numeric_limits<int16_t>::max() / kBlockSizeMultiple) * kBlockSizeMultiple;
while (frames > 0) {
- float* outTmp = (accumulate ? getWorkBuffer() : out);
/* Process the samples */
LVM_ReturnStatus_en lvmStatus;
- {
- std::lock_guard lg(mMutex);
- int processFrames = std::min(frames, kMaxBlockFrames);
- lvmStatus = LVM_Process(mInstance, in + bufferIndex, outTmp + bufferIndex,
- processFrames, 0);
- if (lvmStatus != LVM_SUCCESS) {
- LOG(ERROR) << "LVM lib failed with error: " << lvmStatus;
- return {EX_UNSUPPORTED_OPERATION, 0, 0};
- }
- if (accumulate) {
- for (int i = 0; i < samples; i++) {
- out[i] += outTmp[i];
- }
- }
- frames -= processFrames;
- int processedSize = processFrames * frameSize / sizeof(float);
- bufferIndex += processedSize;
+ int processFrames = std::min(frames, kMaxBlockFrames);
+ lvmStatus = LVM_Process(mInstance, in + bufferIndex, out + bufferIndex,
+ processFrames, 0);
+ if (lvmStatus != LVM_SUCCESS) {
+ LOG(ERROR) << "LVM_Process failed with error: " << lvmStatus;
+ return {EX_UNSUPPORTED_OPERATION, 0, 0};
}
+ frames -= processFrames;
+ int processedSize = processFrames * frameSize / sizeof(float);
+ bufferIndex += processedSize;
}
} else {
for (int i = 0; i < samples; i++) {
- if (accumulate) {
- out[i] += in[i];
- } else {
- out[i] = in[i];
- }
+ out[i] = in[i];
}
}
- LOG(DEBUG) << __func__ << " done processing";
return {STATUS_OK, samples, samples};
}
diff --git a/media/libeffects/lvm/wrapper/Aidl/BundleContext.h b/media/libeffects/lvm/wrapper/Aidl/BundleContext.h
index d823030..ba3997a 100644
--- a/media/libeffects/lvm/wrapper/Aidl/BundleContext.h
+++ b/media/libeffects/lvm/wrapper/Aidl/BundleContext.h
@@ -17,7 +17,6 @@
#pragma once
#include <android-base/logging.h>
-#include <android-base/thread_annotations.h>
#include <array>
#include <cstddef>
@@ -90,10 +89,9 @@
IEffect::Status processEffect(float* in, float* out, int sampleToProcess);
private:
- std::mutex mMutex;
const lvm::BundleEffectType mType;
bool mEnabled = false;
- LVM_Handle_t mInstance GUARDED_BY(mMutex);
+ LVM_Handle_t mInstance;
aidl::android::media::audio::common::AudioDeviceDescription mVirtualizerForcedDevice;
diff --git a/media/libeffects/lvm/wrapper/Aidl/EffectBundleAidl.cpp b/media/libeffects/lvm/wrapper/Aidl/EffectBundleAidl.cpp
index 755f57c..70c276d 100644
--- a/media/libeffects/lvm/wrapper/Aidl/EffectBundleAidl.cpp
+++ b/media/libeffects/lvm/wrapper/Aidl/EffectBundleAidl.cpp
@@ -55,7 +55,6 @@
}
if (instanceSpp) {
*instanceSpp = ndk::SharedRefBase::make<EffectBundleAidl>(*uuid);
- LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
} else {
LOG(ERROR) << __func__ << " invalid input parameter!";
@@ -83,7 +82,6 @@
namespace aidl::android::hardware::audio::effect {
EffectBundleAidl::EffectBundleAidl(const AudioUuid& uuid) {
- LOG(DEBUG) << __func__ << uuid.toString();
if (uuid == getEffectImplUuidEqualizerBundle()) {
mType = lvm::BundleEffectType::EQUALIZER;
mDescriptor = &lvm::kEqualizerDesc;
@@ -107,12 +105,10 @@
EffectBundleAidl::~EffectBundleAidl() {
cleanUp();
- LOG(DEBUG) << __func__;
}
ndk::ScopedAStatus EffectBundleAidl::getDescriptor(Descriptor* _aidl_return) {
RETURN_IF(!_aidl_return, EX_ILLEGAL_ARGUMENT, "Parameter:nullptr");
- LOG(DEBUG) << _aidl_return->toString();
*_aidl_return = *mDescriptor;
return ndk::ScopedAStatus::ok();
}
@@ -154,7 +150,6 @@
}
ndk::ScopedAStatus EffectBundleAidl::setParameterSpecific(const Parameter::Specific& specific) {
- LOG(DEBUG) << __func__ << " specific " << specific.toString();
RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");
auto tag = specific.getTag();
diff --git a/media/libeffects/lvm/wrapper/Aidl/GlobalSession.h b/media/libeffects/lvm/wrapper/Aidl/GlobalSession.h
index d31763b..ea1a8fe 100644
--- a/media/libeffects/lvm/wrapper/Aidl/GlobalSession.h
+++ b/media/libeffects/lvm/wrapper/Aidl/GlobalSession.h
@@ -21,7 +21,6 @@
#include <unordered_map>
#include <android-base/logging.h>
-#include <android-base/thread_annotations.h>
#include "BundleContext.h"
#include "BundleTypes.h"
@@ -41,11 +40,6 @@
return instance;
}
- bool isSessionIdExist(int sessionId) {
- std::lock_guard lg(mMutex);
- return mSessionMap.count(sessionId);
- }
-
static bool findBundleTypeInList(std::vector<std::shared_ptr<BundleContext>>& list,
const lvm::BundleEffectType& type, bool remove = false) {
auto itor = std::find_if(list.begin(), list.end(),
@@ -69,8 +63,7 @@
std::shared_ptr<BundleContext> createSession(const lvm::BundleEffectType& type, int statusDepth,
const Parameter::Common& common) {
int sessionId = common.session;
- LOG(DEBUG) << __func__ << type << " with sessionId " << sessionId;
- std::lock_guard lg(mMutex);
+ LOG(VERBOSE) << __func__ << type << " with sessionId " << sessionId;
if (mSessionMap.count(sessionId) == 0 && mSessionMap.size() >= MAX_BUNDLE_SESSIONS) {
LOG(ERROR) << __func__ << " exceed max bundle session";
return nullptr;
@@ -97,8 +90,7 @@
}
void releaseSession(const lvm::BundleEffectType& type, int sessionId) {
- LOG(DEBUG) << __func__ << type << " sessionId " << sessionId;
- std::lock_guard lg(mMutex);
+ LOG(VERBOSE) << __func__ << type << " sessionId " << sessionId;
if (mSessionMap.count(sessionId)) {
auto& list = mSessionMap[sessionId];
if (!findBundleTypeInList(list, type, true /* remove */)) {
@@ -112,11 +104,9 @@
}
private:
- // Lock for mSessionMap access.
- std::mutex mMutex;
// Max session number supported.
static constexpr int MAX_BUNDLE_SESSIONS = 32;
std::unordered_map<int /* session ID */, std::vector<std::shared_ptr<BundleContext>>>
- mSessionMap GUARDED_BY(mMutex);
+ mSessionMap;
};
} // namespace aidl::android::hardware::audio::effect
diff --git a/media/libeffects/lvm/wrapper/Android.bp b/media/libeffects/lvm/wrapper/Android.bp
index 781aad6..5b48045 100644
--- a/media/libeffects/lvm/wrapper/Android.bp
+++ b/media/libeffects/lvm/wrapper/Android.bp
@@ -52,8 +52,8 @@
local_include_dirs: ["Bundle"],
header_libs: [
- "libhardware_headers",
"libaudioeffects",
+ "libhardware_headers",
],
}
@@ -93,8 +93,8 @@
export_include_dirs: ["Reverb"],
header_libs: [
- "libhardware_headers",
"libaudioeffects",
+ "libhardware_headers",
],
sanitize: {
@@ -105,9 +105,9 @@
cc_library_shared {
name: "libbundleaidl",
srcs: [
+ ":effectCommonFile",
"Aidl/BundleContext.cpp",
"Aidl/EffectBundleAidl.cpp",
- ":effectCommonFile",
],
static_libs: ["libmusicbundle"],
defaults: [
@@ -125,8 +125,8 @@
"libstagefright_foundation",
],
cflags: [
- "-Wthread-safety",
"-DBACKEND_NDK",
+ "-Wthread-safety",
],
relative_install_path: "soundfx",
visibility: [
@@ -137,9 +137,9 @@
cc_library_shared {
name: "libreverbaidl",
srcs: [
- "Reverb/aidl/ReverbContext.cpp",
- "Reverb/aidl/EffectReverb.cpp",
":effectCommonFile",
+ "Reverb/aidl/EffectReverb.cpp",
+ "Reverb/aidl/ReverbContext.cpp",
],
static_libs: ["libreverb"],
defaults: [
@@ -151,8 +151,8 @@
"libhardware_headers",
],
shared_libs: [
- "libbase",
"libaudioutils",
+ "libbase",
"libcutils",
"liblog",
],
diff --git a/media/libeffects/lvm/wrapper/Reverb/aidl/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/aidl/EffectReverb.cpp
index 5fe2f44..4d369b1 100644
--- a/media/libeffects/lvm/wrapper/Reverb/aidl/EffectReverb.cpp
+++ b/media/libeffects/lvm/wrapper/Reverb/aidl/EffectReverb.cpp
@@ -55,7 +55,6 @@
}
if (instanceSpp) {
*instanceSpp = ndk::SharedRefBase::make<EffectReverb>(*uuid);
- LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
} else {
LOG(ERROR) << __func__ << " invalid input parameter!";
diff --git a/media/libeffects/lvm/wrapper/Reverb/aidl/ReverbContext.h b/media/libeffects/lvm/wrapper/Reverb/aidl/ReverbContext.h
index 8068f33..44391f2 100644
--- a/media/libeffects/lvm/wrapper/Reverb/aidl/ReverbContext.h
+++ b/media/libeffects/lvm/wrapper/Reverb/aidl/ReverbContext.h
@@ -17,7 +17,6 @@
#pragma once
#include <android-base/logging.h>
-#include <android-base/thread_annotations.h>
#include <unordered_map>
#include "ReverbTypes.h"
diff --git a/media/libeffects/preprocessing/Android.bp b/media/libeffects/preprocessing/Android.bp
index d658536..44b7d97 100644
--- a/media/libeffects/preprocessing/Android.bp
+++ b/media/libeffects/preprocessing/Android.bp
@@ -63,30 +63,30 @@
cc_library_shared {
name: "libpreprocessingaidl",
srcs: [
- "aidl/PreProcessingContext.cpp",
- "aidl/EffectPreProcessing.cpp",
":effectCommonFile",
+ "aidl/EffectPreProcessing.cpp",
+ "aidl/PreProcessingContext.cpp",
],
defaults: [
"aidlaudioeffectservice_defaults",
],
local_include_dirs: ["aidl"],
shared_libs: [
+ "libaudioutils",
"liblog",
"libutils",
- "libaudioutils",
],
static_libs: [
"webrtc_audio_processing",
],
header_libs: [
- "libwebrtc_absl_headers",
"libaudioeffects",
"libhardware_headers",
+ "libwebrtc_absl_headers",
],
cflags: [
- "-Wthread-safety",
"-Wno-unused-parameter",
+ "-Wthread-safety",
],
relative_install_path: "soundfx",
visibility: [
diff --git a/media/libeffects/preprocessing/aidl/EffectPreProcessing.cpp b/media/libeffects/preprocessing/aidl/EffectPreProcessing.cpp
index 1675d97..87d267b 100644
--- a/media/libeffects/preprocessing/aidl/EffectPreProcessing.cpp
+++ b/media/libeffects/preprocessing/aidl/EffectPreProcessing.cpp
@@ -50,7 +50,6 @@
}
if (instanceSpp) {
*instanceSpp = ndk::SharedRefBase::make<EffectPreProcessing>(*uuid);
- LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
} else {
LOG(ERROR) << __func__ << " invalid input parameter!";
@@ -78,7 +77,6 @@
namespace aidl::android::hardware::audio::effect {
EffectPreProcessing::EffectPreProcessing(const AudioUuid& uuid) {
- LOG(DEBUG) << __func__ << uuid.toString();
if (uuid == getEffectImplUuidAcousticEchoCancelerSw()) {
mType = PreProcessingEffectType::ACOUSTIC_ECHO_CANCELLATION;
mDescriptor = &kAcousticEchoCancelerDesc;
@@ -102,18 +100,16 @@
EffectPreProcessing::~EffectPreProcessing() {
cleanUp();
- LOG(DEBUG) << __func__;
}
ndk::ScopedAStatus EffectPreProcessing::getDescriptor(Descriptor* _aidl_return) {
RETURN_IF(!_aidl_return, EX_ILLEGAL_ARGUMENT, "Parameter:nullptr");
- LOG(DEBUG) << _aidl_return->toString();
*_aidl_return = *mDescriptor;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus EffectPreProcessing::setParameterSpecific(const Parameter::Specific& specific) {
- LOG(DEBUG) << __func__ << " specific " << specific.toString();
+ LOG(VERBOSE) << __func__ << " specific " << specific.toString();
RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");
auto tag = specific.getTag();
diff --git a/media/libeffects/preprocessing/aidl/PreProcessingContext.cpp b/media/libeffects/preprocessing/aidl/PreProcessingContext.cpp
index 6f671f0..2d549ef 100644
--- a/media/libeffects/preprocessing/aidl/PreProcessingContext.cpp
+++ b/media/libeffects/preprocessing/aidl/PreProcessingContext.cpp
@@ -26,7 +26,6 @@
using aidl::android::media::audio::common::AudioDeviceType;
RetCode PreProcessingContext::init(const Parameter::Common& common) {
- std::lock_guard lg(mMutex);
webrtc::AudioProcessingBuilder apBuilder;
mAudioProcessingModule = apBuilder.Create();
if (mAudioProcessingModule == nullptr) {
@@ -64,7 +63,6 @@
}
RetCode PreProcessingContext::deInit() {
- std::lock_guard lg(mMutex);
mAudioProcessingModule = nullptr;
mState = PRE_PROC_STATE_UNINITIALIZED;
return RetCode::SUCCESS;
@@ -75,7 +73,6 @@
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
int typeMsk = (1 << int(mType));
- std::lock_guard lg(mMutex);
// Check if effect is already enabled.
if ((mEnabledMsk & typeMsk) == typeMsk) {
return RetCode::ERROR_ILLEGAL_PARAMETER;
@@ -110,7 +107,6 @@
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
int typeMsk = (1 << int(mType));
- std::lock_guard lg(mMutex);
// Check if effect is already disabled.
if ((mEnabledMsk & typeMsk) != typeMsk) {
return RetCode::ERROR_ILLEGAL_PARAMETER;
@@ -160,7 +156,6 @@
RetCode PreProcessingContext::setAcousticEchoCancelerEchoDelay(int echoDelayUs) {
mEchoDelayUs = echoDelayUs;
- std::lock_guard lg(mMutex);
mAudioProcessingModule->set_stream_delay_ms(mEchoDelayUs / 1000);
return RetCode::SUCCESS;
}
@@ -171,7 +166,6 @@
RetCode PreProcessingContext::setAcousticEchoCancelerMobileMode(bool mobileMode) {
mMobileMode = mobileMode;
- std::lock_guard lg(mMutex);
auto config = mAudioProcessingModule->GetConfig();
config.echo_canceller.mobile_mode = mobileMode;
mAudioProcessingModule->ApplyConfig(config);
@@ -184,7 +178,6 @@
RetCode PreProcessingContext::setAutomaticGainControlV1TargetPeakLevel(int targetPeakLevel) {
mTargetPeakLevel = targetPeakLevel;
- std::lock_guard lg(mMutex);
auto config = mAudioProcessingModule->GetConfig();
config.gain_controller1.target_level_dbfs = -(mTargetPeakLevel / 100);
mAudioProcessingModule->ApplyConfig(config);
@@ -197,7 +190,6 @@
RetCode PreProcessingContext::setAutomaticGainControlV1MaxCompressionGain(int maxCompressionGain) {
mMaxCompressionGain = maxCompressionGain;
- std::lock_guard lg(mMutex);
auto config = mAudioProcessingModule->GetConfig();
config.gain_controller1.compression_gain_db = mMaxCompressionGain / 100;
mAudioProcessingModule->ApplyConfig(config);
@@ -210,7 +202,6 @@
RetCode PreProcessingContext::setAutomaticGainControlV1EnableLimiter(bool enableLimiter) {
mEnableLimiter = enableLimiter;
- std::lock_guard lg(mMutex);
auto config = mAudioProcessingModule->GetConfig();
config.gain_controller1.enable_limiter = mEnableLimiter;
mAudioProcessingModule->ApplyConfig(config);
@@ -223,7 +214,6 @@
RetCode PreProcessingContext::setAutomaticGainControlV2DigitalGain(int gain) {
mDigitalGain = gain;
- std::lock_guard lg(mMutex);
auto config = mAudioProcessingModule->GetConfig();
config.gain_controller2.fixed_digital.gain_db = mDigitalGain;
mAudioProcessingModule->ApplyConfig(config);
@@ -256,7 +246,6 @@
RetCode PreProcessingContext::setNoiseSuppressionLevel(NoiseSuppression::Level level) {
mLevel = level;
- std::lock_guard lg(mMutex);
auto config = mAudioProcessingModule->GetConfig();
config.noise_suppression.level =
(webrtc::AudioProcessing::Config::NoiseSuppression::Level)level;
@@ -278,9 +267,6 @@
RETURN_VALUE_IF(inputFrameCount != outputFrameCount, status, "FrameCountMismatch");
RETURN_VALUE_IF(0 == getInputFrameSize(), status, "zeroFrameSize");
- LOG(DEBUG) << __func__ << " start processing";
- std::lock_guard lg(mMutex);
-
mProcessedMsk |= (1 << int(mType));
// webrtc implementation clear out was_stream_delay_set every time after ProcessStream() call
diff --git a/media/libeffects/preprocessing/aidl/PreProcessingContext.h b/media/libeffects/preprocessing/aidl/PreProcessingContext.h
index 811bacf..11a2bea 100644
--- a/media/libeffects/preprocessing/aidl/PreProcessingContext.h
+++ b/media/libeffects/preprocessing/aidl/PreProcessingContext.h
@@ -17,7 +17,6 @@
#pragma once
#include <android-base/logging.h>
-#include <android-base/thread_annotations.h>
#include <audio_processing.h>
#include <unordered_map>
@@ -37,10 +36,9 @@
PreProcessingContext(int statusDepth, const Parameter::Common& common,
const PreProcessingEffectType& type)
: EffectContext(statusDepth, common), mType(type) {
- LOG(DEBUG) << __func__ << type;
mState = PRE_PROC_STATE_UNINITIALIZED;
}
- ~PreProcessingContext() override { LOG(DEBUG) << __func__; }
+ ~PreProcessingContext() = default;
RetCode init(const Parameter::Common& common);
RetCode deInit();
@@ -85,20 +83,19 @@
static constexpr inline webrtc::AudioProcessing::Config::NoiseSuppression::Level
kNsDefaultLevel = webrtc::AudioProcessing::Config::NoiseSuppression::kModerate;
- std::mutex mMutex;
const PreProcessingEffectType mType;
PreProcEffectState mState; // current state
// handle on webRTC audio processing module (APM)
- rtc::scoped_refptr<webrtc::AudioProcessing> mAudioProcessingModule GUARDED_BY(mMutex);
+ rtc::scoped_refptr<webrtc::AudioProcessing> mAudioProcessingModule;
- int mEnabledMsk GUARDED_BY(mMutex); // bit field containing IDs of enabled pre processors
- int mProcessedMsk GUARDED_BY(mMutex); // bit field containing IDs of pre processors already
+ int mEnabledMsk; // bit field containing IDs of enabled pre processors
+ int mProcessedMsk; // bit field containing IDs of pre processors already
// processed in current round
- int mRevEnabledMsk GUARDED_BY(mMutex); // bit field containing IDs of enabled pre processors
+ int mRevEnabledMsk; // bit field containing IDs of enabled pre processors
// with reverse channel
- int mRevProcessedMsk GUARDED_BY(mMutex); // bit field containing IDs of pre processors with
- // reverse channel already processed in current round
+ int mRevProcessedMsk; // bit field containing IDs of pre processors with
+ // reverse channel already processed in current round
webrtc::StreamConfig mInputConfig; // input stream configuration
webrtc::StreamConfig mOutputConfig; // output stream configuration
diff --git a/media/libeffects/preprocessing/aidl/PreProcessingSession.h b/media/libeffects/preprocessing/aidl/PreProcessingSession.h
index 877292f..4a66e81 100644
--- a/media/libeffects/preprocessing/aidl/PreProcessingSession.h
+++ b/media/libeffects/preprocessing/aidl/PreProcessingSession.h
@@ -21,7 +21,6 @@
#include <unordered_map>
#include <android-base/logging.h>
-#include <android-base/thread_annotations.h>
#include "PreProcessingContext.h"
#include "PreProcessingTypes.h"
@@ -67,7 +66,6 @@
const Parameter::Common& common) {
int sessionId = common.session;
LOG(DEBUG) << __func__ << type << " with sessionId " << sessionId;
- std::lock_guard lg(mMutex);
if (mSessionMap.count(sessionId) == 0 && mSessionMap.size() >= MAX_PRE_PROC_SESSIONS) {
LOG(ERROR) << __func__ << " exceed max bundle session";
return nullptr;
@@ -95,7 +93,6 @@
void releaseSession(const PreProcessingEffectType& type, int sessionId) {
LOG(DEBUG) << __func__ << type << " sessionId " << sessionId;
- std::lock_guard lg(mMutex);
if (mSessionMap.count(sessionId)) {
auto& list = mSessionMap[sessionId];
if (!findPreProcessingTypeInList(list, type, true /* remove */)) {
@@ -109,11 +106,9 @@
}
private:
- // Lock for mSessionMap access.
- std::mutex mMutex;
// Max session number supported.
static constexpr int MAX_PRE_PROC_SESSIONS = 8;
std::unordered_map<int /* session ID */, std::vector<std::shared_ptr<PreProcessingContext>>>
- mSessionMap GUARDED_BY(mMutex);
+ mSessionMap;
};
} // namespace aidl::android::hardware::audio::effect
diff --git a/media/libeffects/proxy/Android.bp b/media/libeffects/proxy/Android.bp
index 6256eda..95da4de 100644
--- a/media/libeffects/proxy/Android.bp
+++ b/media/libeffects/proxy/Android.bp
@@ -29,19 +29,19 @@
srcs: ["EffectProxy.cpp"],
cflags: [
- "-fvisibility=hidden",
"-Wall",
"-Werror",
+ "-fvisibility=hidden",
],
include_dirs: ["frameworks/av/media/libeffects/factory"],
header_libs: ["libaudioeffects"],
shared_libs: [
- "liblog",
"libcutils",
- "libutils",
"libdl",
"libeffects",
+ "liblog",
+ "libutils",
],
}
diff --git a/media/libeffects/testlibs/Android.bp b/media/libeffects/testlibs/Android.bp
index 5ba56bb..f5aad92 100644
--- a/media/libeffects/testlibs/Android.bp
+++ b/media/libeffects/testlibs/Android.bp
@@ -33,10 +33,10 @@
relative_install_path: "soundfx",
cflags: [
- "-fvisibility=hidden",
"-Wall",
"-Werror",
"-Wno-address-of-packed-member",
+ "-fvisibility=hidden",
],
header_libs: [
@@ -66,9 +66,9 @@
relative_install_path: "soundfx",
cflags: [
- "-fvisibility=hidden",
"-Wall",
"-Werror",
+ "-fvisibility=hidden",
],
header_libs: [
diff --git a/media/libeffects/visualizer/Android.bp b/media/libeffects/visualizer/Android.bp
index 66ceadf..8f1d8da 100644
--- a/media/libeffects/visualizer/Android.bp
+++ b/media/libeffects/visualizer/Android.bp
@@ -54,9 +54,9 @@
cc_library_shared {
name: "libvisualizeraidl",
srcs: [
+ ":effectCommonFile",
"aidl/Visualizer.cpp",
"aidl/VisualizerContext.cpp",
- ":effectCommonFile",
],
defaults: [
"aidlaudioeffectservice_defaults",
diff --git a/media/libeffects/visualizer/aidl/Visualizer.cpp b/media/libeffects/visualizer/aidl/Visualizer.cpp
index 9b1bac6..9c2b71e 100644
--- a/media/libeffects/visualizer/aidl/Visualizer.cpp
+++ b/media/libeffects/visualizer/aidl/Visualizer.cpp
@@ -37,7 +37,6 @@
}
if (instanceSpp) {
*instanceSpp = ndk::SharedRefBase::make<VisualizerImpl>();
- LOG(DEBUG) << __func__ << " instance " << instanceSpp->get() << " created";
return EX_NONE;
} else {
LOG(ERROR) << __func__ << " invalid input parameter!";
diff --git a/media/libeffects/visualizer/aidl/Visualizer.h b/media/libeffects/visualizer/aidl/Visualizer.h
index b48c85e..3180972 100644
--- a/media/libeffects/visualizer/aidl/Visualizer.h
+++ b/media/libeffects/visualizer/aidl/Visualizer.h
@@ -29,11 +29,8 @@
static const std::string kEffectName;
static const Capability kCapability;
static const Descriptor kDescriptor;
- VisualizerImpl() { LOG(DEBUG) << __func__; }
- ~VisualizerImpl() {
- cleanUp();
- LOG(DEBUG) << __func__;
- }
+ VisualizerImpl() = default;
+ ~VisualizerImpl() { cleanUp(); }
ndk::ScopedAStatus commandImpl(CommandId command) REQUIRES(mImplMutex) override;
ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
diff --git a/media/libeffects/visualizer/aidl/VisualizerContext.cpp b/media/libeffects/visualizer/aidl/VisualizerContext.cpp
index c763b1a..1e08674 100644
--- a/media/libeffects/visualizer/aidl/VisualizerContext.cpp
+++ b/media/libeffects/visualizer/aidl/VisualizerContext.cpp
@@ -38,14 +38,10 @@
}
VisualizerContext::~VisualizerContext() {
- std::lock_guard lg(mMutex);
- LOG(DEBUG) << __func__;
mState = State::UNINITIALIZED;
}
RetCode VisualizerContext::initParams(const Parameter::Common& common) {
- std::lock_guard lg(mMutex);
- LOG(DEBUG) << __func__;
if (common.input != common.output) {
LOG(ERROR) << __func__ << " mismatch input: " << common.input.toString()
<< " and output: " << common.output.toString();
@@ -66,7 +62,6 @@
}
RetCode VisualizerContext::enable() {
- std::lock_guard lg(mMutex);
if (mState != State::INITIALIZED) {
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
@@ -75,7 +70,6 @@
}
RetCode VisualizerContext::disable() {
- std::lock_guard lg(mMutex);
if (mState != State::ACTIVE) {
return RetCode::ERROR_EFFECT_LIB_ERROR;
}
@@ -84,48 +78,39 @@
}
void VisualizerContext::reset() {
- std::lock_guard lg(mMutex);
std::fill(mCaptureBuf.begin(), mCaptureBuf.end(), 0x80);
}
RetCode VisualizerContext::setCaptureSamples(int samples) {
- std::lock_guard lg(mMutex);
mCaptureSamples = samples;
return RetCode::SUCCESS;
}
int32_t VisualizerContext::getCaptureSamples() {
- std::lock_guard lg(mMutex);
return mCaptureSamples;
}
RetCode VisualizerContext::setMeasurementMode(Visualizer::MeasurementMode mode) {
- std::lock_guard lg(mMutex);
mMeasurementMode = mode;
return RetCode::SUCCESS;
}
Visualizer::MeasurementMode VisualizerContext::getMeasurementMode() {
- std::lock_guard lg(mMutex);
return mMeasurementMode;
}
RetCode VisualizerContext::setScalingMode(Visualizer::ScalingMode mode) {
- std::lock_guard lg(mMutex);
mScalingMode = mode;
return RetCode::SUCCESS;
}
Visualizer::ScalingMode VisualizerContext::getScalingMode() {
- std::lock_guard lg(mMutex);
return mScalingMode;
}
RetCode VisualizerContext::setDownstreamLatency(int latency) {
- std::lock_guard lg(mMutex);
mDownstreamLatency = latency;
return RetCode::SUCCESS;
}
int VisualizerContext::getDownstreamLatency() {
- std::lock_guard lg(mMutex);
return mDownstreamLatency;
}
@@ -152,7 +137,6 @@
uint8_t nbValidMeasurements = 0;
{
- std::lock_guard lg(mMutex);
// reset measurements if last measurement was too long ago (which implies stored
// measurements aren't relevant anymore and shouldn't bias the new one)
const uint32_t delayMs = getDeltaTimeMsFromUpdatedTime_l();
@@ -185,13 +169,12 @@
// convert from I16 sample values to mB and write results
measure.rms = (rms < 0.000016f) ? -9600 : (int32_t)(2000 * log10(rms / 32767.0f));
measure.peak = (peakU16 == 0) ? -9600 : (int32_t)(2000 * log10(peakU16 / 32767.0f));
- LOG(INFO) << __func__ << " peak " << peakU16 << " (" << measure.peak << "mB), rms " << rms
- << " (" << measure.rms << "mB)";
+ LOG(VERBOSE) << __func__ << " peak " << peakU16 << " (" << measure.peak << "mB), rms " << rms
+ << " (" << measure.rms << "mB)";
return measure;
}
std::vector<uint8_t> VisualizerContext::capture() {
- std::lock_guard lg(mMutex);
uint32_t captureSamples = mCaptureSamples;
std::vector<uint8_t> result(captureSamples, 0x80);
// cts android.media.audio.cts.VisualizerTest expecting silence data when effect not running
@@ -205,7 +188,6 @@
// clear the capture buffer to return silence
if ((mLastCaptureIdx == mCaptureIdx) && (mBufferUpdateTime.tv_sec != 0) &&
(deltaMs > kMaxStallTimeMs)) {
- LOG(INFO) << __func__ << " capture going to idle";
mBufferUpdateTime.tv_sec = 0;
return result;
}
@@ -247,10 +229,8 @@
IEffect::Status result = {STATUS_NOT_ENOUGH_DATA, 0, 0};
RETURN_VALUE_IF(in == nullptr || out == nullptr || samples == 0, result, "dataBufferError");
- std::lock_guard lg(mMutex);
result.status = STATUS_INVALID_OPERATION;
RETURN_VALUE_IF(mState != State::ACTIVE, result, "stateNotActive");
- LOG(DEBUG) << __func__ << " in " << in << " out " << out << " sample " << samples;
// perform measurements if needed
if (mMeasurementMode == Visualizer::MeasurementMode::PEAK_RMS) {
// find the peak and RMS squared for the new buffer
diff --git a/media/libeffects/visualizer/aidl/VisualizerContext.h b/media/libeffects/visualizer/aidl/VisualizerContext.h
index b03e038..9715e20 100644
--- a/media/libeffects/visualizer/aidl/VisualizerContext.h
+++ b/media/libeffects/visualizer/aidl/VisualizerContext.h
@@ -16,7 +16,6 @@
#pragma once
-#include <android-base/thread_annotations.h>
#include <audio_effects/effect_dynamicsprocessing.h>
#include <system/audio_effects/effect_visualizer.h>
@@ -79,28 +78,26 @@
// note: buffer index is stored in uint8_t
static const uint32_t kMeasurementWindowMaxSizeInBuffers = 25;
- // serialize process() and parameter setting
- std::mutex mMutex;
- Parameter::Common mCommon GUARDED_BY(mMutex);
- State mState GUARDED_BY(mMutex) = State::UNINITIALIZED;
- uint32_t mCaptureIdx GUARDED_BY(mMutex) = 0;
- uint32_t mLastCaptureIdx GUARDED_BY(mMutex) = 0;
- Visualizer::ScalingMode mScalingMode GUARDED_BY(mMutex) = Visualizer::ScalingMode::NORMALIZED;
- struct timespec mBufferUpdateTime GUARDED_BY(mMutex);
+ Parameter::Common mCommon;
+ State mState = State::UNINITIALIZED;
+ uint32_t mCaptureIdx = 0;
+ uint32_t mLastCaptureIdx = 0;
+ Visualizer::ScalingMode mScalingMode = Visualizer::ScalingMode::NORMALIZED;
+ struct timespec mBufferUpdateTime;
// capture buf with 8 bits mono PCM samples
- std::array<uint8_t, kMaxCaptureBufSize> mCaptureBuf GUARDED_BY(mMutex);
- uint32_t mDownstreamLatency GUARDED_BY(mMutex) = 0;
- int32_t mCaptureSamples GUARDED_BY(mMutex) = kMaxCaptureBufSize;
+ std::array<uint8_t, kMaxCaptureBufSize> mCaptureBuf;
+ uint32_t mDownstreamLatency = 0;
+ int32_t mCaptureSamples = kMaxCaptureBufSize;
// to avoid recomputing it every time a buffer is processed
- uint8_t mChannelCount GUARDED_BY(mMutex) = 0;
- Visualizer::MeasurementMode mMeasurementMode GUARDED_BY(mMutex) =
+ uint8_t mChannelCount = 0;
+ Visualizer::MeasurementMode mMeasurementMode =
Visualizer::MeasurementMode::NONE;
uint8_t mMeasurementWindowSizeInBuffers = kMeasurementWindowMaxSizeInBuffers;
- uint8_t mMeasurementBufferIdx GUARDED_BY(mMutex) = 0;
+ uint8_t mMeasurementBufferIdx = 0;
std::array<BufferStats, kMeasurementWindowMaxSizeInBuffers> mPastMeasurements;
void init_params();
- uint32_t getDeltaTimeMsFromUpdatedTime_l() REQUIRES(mMutex);
+ uint32_t getDeltaTimeMsFromUpdatedTime_l();
};
} // namespace aidl::android::hardware::audio::effect
diff --git a/media/libnbaio/Android.bp b/media/libnbaio/Android.bp
index 434ae00..158900a 100644
--- a/media/libnbaio/Android.bp
+++ b/media/libnbaio/Android.bp
@@ -15,8 +15,8 @@
"NBAIO.cpp",
],
header_libs: [
- "libaudioclient_headers",
"libaudio_system_headers",
+ "libaudioclient_headers",
],
export_header_lib_headers: [
"libaudioclient_headers",
@@ -35,8 +35,8 @@
export_include_dirs: ["include_mono"],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
}
diff --git a/media/libnblog/Android.bp b/media/libnblog/Android.bp
index 8cfece6..b4d48b0 100644
--- a/media/libnblog/Android.bp
+++ b/media/libnblog/Android.bp
@@ -35,8 +35,8 @@
],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
include_dirs: ["system/media/audio_utils/include"],
diff --git a/media/libstagefright/FrameDecoder.cpp b/media/libstagefright/FrameDecoder.cpp
index 1a0bb7f..46703bb 100644
--- a/media/libstagefright/FrameDecoder.cpp
+++ b/media/libstagefright/FrameDecoder.cpp
@@ -48,6 +48,9 @@
static const int64_t kBufferTimeOutUs = 10000LL; // 10 msec
static const size_t kRetryCount = 100; // must be >0
static const int64_t kDefaultSampleDurationUs = 33333LL; // 33ms
+// For codec, 0 is the highest importance; higher the number lesser important.
+// To make codec for thumbnail less important, give it a value more than 0.
+static const int kThumbnailImportance = 1;
sp<IMemory> allocVideoFrame(const sp<MetaData>& trackMeta,
int32_t width, int32_t height, int32_t tileWidth, int32_t tileHeight,
@@ -585,6 +588,9 @@
}
}
+ // Set the importance for thumbnail.
+ videoFormat->setInt32(KEY_IMPORTANCE, kThumbnailImportance);
+
int32_t frameRate;
if (trackMeta()->findInt32(kKeyFrameRate, &frameRate) && frameRate > 0) {
mDefaultSampleDurationUs = 1000000LL / frameRate;
@@ -902,6 +908,10 @@
videoFormat->setInt32("android._num-input-buffers", 1);
videoFormat->setInt32("android._num-output-buffers", 1);
}
+
+ /// Set the importance for thumbnail.
+ videoFormat->setInt32(KEY_IMPORTANCE, kThumbnailImportance);
+
return videoFormat;
}
diff --git a/media/libstagefright/webm/Android.bp b/media/libstagefright/webm/Android.bp
index 6ed3e0e..723131d 100644
--- a/media/libstagefright/webm/Android.bp
+++ b/media/libstagefright/webm/Android.bp
@@ -10,8 +10,6 @@
cc_library_static {
name: "libstagefright_webm",
- cppflags: ["-D__STDINT_LIMITS"],
-
cflags: [
"-Werror",
"-Wall",
diff --git a/media/utils/ServiceUtilities.cpp b/media/utils/ServiceUtilities.cpp
index deef31d..4926e46 100644
--- a/media/utils/ServiceUtilities.cpp
+++ b/media/utils/ServiceUtilities.cpp
@@ -114,8 +114,9 @@
return std::optional<AttributionSourceState>{myAttributionSource};
}
-static bool checkRecordingInternal(const AttributionSourceState& attributionSource,
- const String16& msg, bool start, audio_source_t source) {
+ static bool checkRecordingInternal(const AttributionSourceState &attributionSource,
+ const uint32_t virtualDeviceId,
+ const String16 &msg, bool start, audio_source_t source) {
// Okay to not track in app ops as audio server or media server is us and if
// device is rooted security model is considered compromised.
// system_server loses its RECORD_AUDIO permission when a secondary
@@ -127,7 +128,7 @@
// We specify a pid and uid here as mediaserver (aka MediaRecorder or StageFrightRecorder)
// may open a record track on behalf of a client. Note that pid may be a tid.
// IMPORTANT: DON'T USE PermissionCache - RUNTIME PERMISSIONS CHANGE.
- const std::optional<AttributionSourceState> resolvedAttributionSource =
+ std::optional<AttributionSourceState> resolvedAttributionSource =
resolveAttributionSource(attributionSource);
if (!resolvedAttributionSource.has_value()) {
return false;
@@ -136,6 +137,7 @@
const int32_t attributedOpCode = getOpForSource(source);
permission::PermissionChecker permissionChecker;
+ resolvedAttributionSource.value().deviceId = virtualDeviceId;
bool permitted = false;
if (start) {
permitted = (permissionChecker.checkPermissionForStartDataDeliveryFromDatasource(
@@ -150,13 +152,24 @@
return permitted;
}
-bool recordingAllowed(const AttributionSourceState& attributionSource, audio_source_t source) {
- return checkRecordingInternal(attributionSource, String16(), /*start*/ false, source);
+static constexpr int DEVICE_ID_DEFAULT = 0;
+
+bool recordingAllowed(const AttributionSourceState &attributionSource, audio_source_t source) {
+ return checkRecordingInternal(attributionSource, DEVICE_ID_DEFAULT, String16(), /*start*/ false,
+ source);
+}
+
+bool recordingAllowed(const AttributionSourceState &attributionSource,
+ const uint32_t virtualDeviceId,
+ audio_source_t source) {
+ return checkRecordingInternal(attributionSource, virtualDeviceId,
+ String16(), /*start*/ false, source);
}
bool startRecording(const AttributionSourceState& attributionSource, const String16& msg,
audio_source_t source) {
- return checkRecordingInternal(attributionSource, msg, /*start*/ true, source);
+ return checkRecordingInternal(attributionSource, DEVICE_ID_DEFAULT, msg, /*start*/ true,
+ source);
}
void finishRecording(const AttributionSourceState& attributionSource, audio_source_t source) {
diff --git a/media/utils/include/mediautils/ServiceUtilities.h b/media/utils/include/mediautils/ServiceUtilities.h
index 0b3a3f9..aa9e120 100644
--- a/media/utils/include/mediautils/ServiceUtilities.h
+++ b/media/utils/include/mediautils/ServiceUtilities.h
@@ -87,6 +87,10 @@
bool recordingAllowed(const AttributionSourceState& attributionSource,
audio_source_t source = AUDIO_SOURCE_DEFAULT);
+
+bool recordingAllowed(const AttributionSourceState &attributionSource,
+ uint32_t virtualDeviceId,
+ audio_source_t source);
bool startRecording(const AttributionSourceState& attributionSource,
const String16& msg, audio_source_t source);
void finishRecording(const AttributionSourceState& attributionSource, audio_source_t source);
diff --git a/services/audioflinger/Android.bp b/services/audioflinger/Android.bp
index 129541f..3652aa2 100644
--- a/services/audioflinger/Android.bp
+++ b/services/audioflinger/Android.bp
@@ -66,12 +66,12 @@
// Remove some pedantic stylistic requirements.
"-google-readability-casting", // C++ casts not always necessary and may be verbose
- "-google-readability-todo", // do not require TODO(info)
+ "-google-readability-todo", // do not require TODO(info)
- "-bugprone-unhandled-self-assignment",
- "-bugprone-suspicious-string-compare",
- "-cert-oop54-cpp", // found in TransactionLog.h
"-bugprone-narrowing-conversions", // b/182410845
+ "-bugprone-suspicious-string-compare",
+ "-bugprone-unhandled-self-assignment",
+ "-cert-oop54-cpp", // found in TransactionLog.h
]
// TODO(b/275642749) Reenable these warnings
@@ -101,9 +101,9 @@
"-Wall",
"-Wdeprecated",
"-Werror",
+ "-Werror=conditional-uninitialized",
"-Werror=implicit-fallthrough",
"-Werror=sometimes-uninitialized",
- "-Werror=conditional-uninitialized",
"-Wextra",
// suppress some warning chatter.
@@ -113,9 +113,9 @@
"-Wredundant-decls",
"-Wshadow",
"-Wstrict-aliasing",
- "-fstrict-aliasing",
"-Wthread-safety",
//"-Wthread-safety-negative", // experimental - looks broken in R.
+ "-fstrict-aliasing",
"-Wunreachable-code",
"-Wunreachable-code-break",
"-Wunreachable-code-return",
@@ -134,7 +134,7 @@
tidy_checks: audioflinger_tidy_errors,
tidy_checks_as_errors: audioflinger_tidy_errors,
tidy_flags: [
- "-format-style=file",
+ "-format-style=file",
],
}
@@ -142,49 +142,48 @@
name: "libaudioflinger_dependencies",
shared_libs: [
- "audioflinger-aidl-cpp",
"audioclient-types-aidl-cpp",
+ "audioflinger-aidl-cpp",
"av-types-aidl-cpp",
"com.android.media.audio-aconfig-cc",
"effect-aidl-cpp",
- "libaudioclient_aidl_conversion",
"libactivitymanager_aidl",
+ "libaudioclient",
+ "libaudioclient_aidl_conversion",
"libaudioflinger_datapath",
"libaudioflinger_fastpath",
"libaudioflinger_timing",
"libaudioflinger_utils",
"libaudiofoundation",
"libaudiohal",
+ "libaudiomanager",
"libaudioprocessing",
"libaudioutils",
- "libcutils",
- "libutils",
- "liblog",
"libbinder",
"libbinder_ndk",
- "libaudioclient",
- "libaudiomanager",
+ "libcutils",
+ "liblog",
+ "libmedia_helper",
"libmediametrics",
"libmediautils",
+ "libmemunreachable",
"libnbaio",
"libnblog",
"libpermission",
"libpowermanager",
- "libmemunreachable",
- "libmedia_helper",
"libshmemcompat",
"libsounddose",
+ "libutils",
"libvibrator",
"packagemanager_aidl-cpp",
],
static_libs: [
- "libmedialogservice",
"libaudiospdif",
+ "libmedialogservice",
],
}
-
cc_library {
name: "libaudioflinger",
@@ -231,9 +230,9 @@
],
cflags: [
- "-fvisibility=hidden",
- "-Werror",
"-Wall",
+ "-Werror",
+ "-fvisibility=hidden",
],
sanitize: {
integer_overflow: true,
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 725e5a6..01f55dd 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -3059,6 +3059,25 @@
mPlaybackThreads.removeItem(output);
+ // Save AUDIO_SESSION_OUTPUT_MIX effect to orphan chains
+ // Output Mix Effect session is used to manage Music Effect by AudioPolicy Manager.
+ // It exists across all playback threads.
+ if (playbackThread->type() == IAfThreadBase::MIXER
+ || playbackThread->type() == IAfThreadBase::OFFLOAD
+ || playbackThread->type() == IAfThreadBase::SPATIALIZER) {
+ sp<IAfEffectChain> mixChain;
+ {
+ audio_utils::scoped_lock sl(playbackThread->mutex());
+ mixChain = playbackThread->getEffectChain_l(AUDIO_SESSION_OUTPUT_MIX);
+ if (mixChain != nullptr) {
+ ALOGW("%s() output %d moving mix session to orphans", __func__, output);
+ playbackThread->removeEffectChain_l(mixChain);
+ }
+ }
+ if (mixChain != nullptr) {
+ putOrphanEffectChain_l(mixChain);
+ }
+ }
// save all effects to the default thread
if (mPlaybackThreads.size()) {
IAfPlaybackThread* const dstThread =
@@ -4203,7 +4222,8 @@
// before creating the AudioEffect or the io handle must be specified.
//
// Detect if the effect is created after an AudioRecord is destroyed.
- if (getOrphanEffectChain_l(sessionId).get() != nullptr) {
+ if ((sessionId != AUDIO_SESSION_OUTPUT_MIX) &&
+ getOrphanEffectChain_l(sessionId).get() != nullptr) {
ALOGE("%s: effect %s with no specified io handle is denied because the AudioRecord"
" for session %d no longer exists",
__func__, descOut.name, sessionId);
@@ -4259,7 +4279,8 @@
goto Exit;
}
}
- } else {
+ }
+ if (thread->type() == IAfThreadBase::RECORD || sessionId == AUDIO_SESSION_OUTPUT_MIX) {
// Check if one effect chain was awaiting for an effect to be created on this
// session and used it instead of creating a new one.
sp<IAfEffectChain> chain = getOrphanEffectChain_l(sessionId);
@@ -4363,17 +4384,39 @@
}
return ret;
}
- IAfPlaybackThread* const srcThread = checkPlaybackThread_l(srcIo);
- if (srcThread == nullptr) {
- ALOGW("%s() bad srcIo %d", __func__, srcIo);
- return BAD_VALUE;
- }
- IAfPlaybackThread* const dstThread = checkPlaybackThread_l(dstIo);
+
+ IAfPlaybackThread* dstThread = checkPlaybackThread_l(dstIo);
if (dstThread == nullptr) {
ALOGW("%s() bad dstIo %d", __func__, dstIo);
return BAD_VALUE;
}
+ IAfPlaybackThread* srcThread = checkPlaybackThread_l(srcIo);
+ sp<IAfEffectChain> orphanChain = getOrphanEffectChain_l(sessionId);
+ if (srcThread == nullptr && orphanChain == nullptr && sessionId == AUDIO_SESSION_OUTPUT_MIX) {
+ ALOGW("%s() AUDIO_SESSION_OUTPUT_MIX not found in orphans, checking other mix", __func__);
+ for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
+ const sp<IAfPlaybackThread> pt = mPlaybackThreads.valueAt(i);
+ const uint32_t sessionType = pt->hasAudioSession(AUDIO_SESSION_OUTPUT_MIX);
+ if ((pt->type() == IAfThreadBase::MIXER || pt->type() == IAfThreadBase::OFFLOAD) &&
+ ((sessionType & IAfThreadBase::EFFECT_SESSION) != 0)) {
+ srcThread = pt.get();
+ ALOGW("%s() found srcOutput %d hosting AUDIO_SESSION_OUTPUT_MIX", __func__,
+ pt->id());
+ break;
+ }
+ }
+ }
+ if (srcThread == nullptr && orphanChain == nullptr) {
+ ALOGW("moveEffects() bad srcIo %d", srcIo);
+ return BAD_VALUE;
+ }
+ // dstThread pointer validity has already been checked
+ if (orphanChain != nullptr) {
+ audio_utils::scoped_lock _ll(dstThread->mutex());
+ return moveEffectChain_ll(sessionId, nullptr, dstThread, orphanChain.get());
+ }
+ // srcThread pointer validity has already been checked
audio_utils::scoped_lock _ll(dstThread->mutex(), srcThread->mutex());
return moveEffectChain_ll(sessionId, srcThread, dstThread);
}
@@ -4399,12 +4442,17 @@
// moveEffectChain_ll must be called with the AudioFlinger::mutex()
// and both srcThread and dstThread mutex()s held
status_t AudioFlinger::moveEffectChain_ll(audio_session_t sessionId,
- IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread)
+ IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread,
+ IAfEffectChain* srcChain)
{
- ALOGV("%s: session %d from thread %p to thread %p",
- __func__, sessionId, srcThread, dstThread);
+ ALOGV("%s: session %d from thread %p to thread %p %s",
+ __func__, sessionId, srcThread, dstThread,
+ (srcChain != nullptr ? "from specific chain" : ""));
+ ALOG_ASSERT((srcThread != nullptr) != (srcChain != nullptr),
+ "no source provided for source chain");
- sp<IAfEffectChain> chain = srcThread->getEffectChain_l(sessionId);
+ sp<IAfEffectChain> chain =
+ srcChain != nullptr ? srcChain : srcThread->getEffectChain_l(sessionId);
if (chain == 0) {
ALOGW("%s: effect chain for session %d not on source thread %p",
__func__, sessionId, srcThread);
@@ -4424,8 +4472,9 @@
// otherwise unnecessary as removeEffect_l() will remove the chain when last effect is
// removed.
// TODO(b/216875016): consider holding the effect chain locks for the duration of the move.
- srcThread->removeEffectChain_l(chain);
-
+ if (srcThread != nullptr) {
+ srcThread->removeEffectChain_l(chain);
+ }
// transfer all effects one by one so that new effect chain is created on new thread with
// correct buffer sizes and audio parameters and effect engines reconfigured accordingly
sp<IAfEffectChain> dstChain;
@@ -4435,7 +4484,11 @@
// process effects one by one.
for (sp<IAfEffectModule> effect = chain->getEffectFromId_l(0); effect != nullptr;
effect = chain->getEffectFromId_l(0)) {
- srcThread->removeEffect_l(effect);
+ if (srcThread != nullptr) {
+ srcThread->removeEffect_l(effect);
+ } else {
+ chain->removeEffect_l(effect);
+ }
removed.add(effect);
status = dstThread->addEffect_ll(effect);
if (status != NO_ERROR) {
@@ -4463,7 +4516,7 @@
for (const auto& effect : removed) {
dstThread->removeEffect_l(effect); // Note: Depending on error location, the last
// effect may not have been placed on dstThread.
- if (srcThread->addEffect_ll(effect) == NO_ERROR) {
+ if (srcThread != nullptr && srcThread->addEffect_ll(effect) == NO_ERROR) {
++restored;
if (dstChain == nullptr) {
dstChain = effect->getCallback()->chain().promote();
@@ -4494,15 +4547,19 @@
if (errorString.empty()) {
errorString = StringPrintf("%s: failed status %d", __func__, status);
}
- ALOGW("%s: %s unsuccessful move of session %d from srcThread %p to dstThread %p "
+ ALOGW("%s: %s unsuccessful move of session %d from %s %p to dstThread %p "
"(%zu effects removed from srcThread, %zu effects restored to srcThread, "
"%zu effects started)",
- __func__, errorString.c_str(), sessionId, srcThread, dstThread,
+ __func__, errorString.c_str(), sessionId,
+ (srcThread != nullptr ? "srcThread" : "srcChain"),
+ (srcThread != nullptr ? (void*) srcThread : (void*) srcChain), dstThread,
removed.size(), restored, started);
} else {
- ALOGD("%s: successful move of session %d from srcThread %p to dstThread %p "
+ ALOGD("%s: successful move of session %d from %s %p to dstThread %p "
"(%zu effects moved, %zu effects started)",
- __func__, sessionId, srcThread, dstThread, removed.size(), started);
+ __func__, sessionId, (srcThread != nullptr ? "srcThread" : "srcChain"),
+ (srcThread != nullptr ? (void*) srcThread : (void*) srcChain), dstThread,
+ removed.size(), started);
}
return status;
}
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 0f75d6e..7c26f72 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -373,7 +373,8 @@
EXCLUDES_AudioFlinger_Mutex;
status_t moveEffectChain_ll(audio_session_t sessionId,
- IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread) final
+ IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread,
+ IAfEffectChain* srcChain = nullptr) final
REQUIRES(mutex(), audio_utils::ThreadBase_Mutex);
// This is a helper that is called during incoming binder calls.
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index 819f2d6..10a8883 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -2492,6 +2492,7 @@
size_t size = mEffects.size();
uint32_t type = effect->desc().flags & EFFECT_FLAG_TYPE_MASK;
+ const bool hasThreadAttached = mEffectCallback->hasThreadAttached();
for (size_t i = 0; i < size; i++) {
if (effect == mEffects[i]) {
// calling stop here will remove pre-processing effect from the audio HAL.
@@ -2504,8 +2505,8 @@
if (release) {
mEffects[i]->release_l();
}
-
- if (type != EFFECT_FLAG_TYPE_AUXILIARY) {
+ // Skip operation when no thread attached (could lead to sigfpe as framecount is 0...)
+ if (hasThreadAttached && type != EFFECT_FLAG_TYPE_AUXILIARY) {
if (i == size - 1 && i != 0) {
mEffects[i - 1]->configure_l();
mEffects[i - 1]->setOutBuffer(mOutBuffer);
@@ -2517,7 +2518,7 @@
// make sure the input buffer configuration for the new first effect in the chain
// is updated if needed (can switch from HAL channel mask to mixer channel mask)
if (type != EFFECT_FLAG_TYPE_AUXILIARY // TODO(b/284522658) breaks for aux FX, why?
- && i == 0 && size > 1) {
+ && hasThreadAttached && i == 0 && size > 1) {
mEffects[0]->configure_l();
mEffects[0]->setInBuffer(mInBuffer);
mEffects[0]->updateAccessMode_l(); // reconfig if needed.
@@ -3146,11 +3147,11 @@
{
const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
- return AUDIO_CHANNEL_NONE;
+ return AUDIO_CHANNEL_OUT_STEREO;
}
sp<IAfEffectChain> c = chain().promote();
if (c == nullptr) {
- return AUDIO_CHANNEL_NONE;
+ return AUDIO_CHANNEL_OUT_STEREO;
}
if (mThreadType == IAfThreadBase::SPATIALIZER) {
@@ -3185,11 +3186,11 @@
{
const sp<IAfThreadBase> t = thread().promote();
if (t == nullptr) {
- return AUDIO_CHANNEL_NONE;
+ return AUDIO_CHANNEL_OUT_STEREO;
}
sp<IAfEffectChain> c = chain().promote();
if (c == nullptr) {
- return AUDIO_CHANNEL_NONE;
+ return AUDIO_CHANNEL_OUT_STEREO;
}
if (mThreadType == IAfThreadBase::SPATIALIZER) {
diff --git a/services/audioflinger/Effects.h b/services/audioflinger/Effects.h
index 46c44a6..5e527d3 100644
--- a/services/audioflinger/Effects.h
+++ b/services/audioflinger/Effects.h
@@ -616,7 +616,9 @@
mThreadType = thread->type();
mAfThreadCallback = thread->afThreadCallback();
}
-
+ bool hasThreadAttached() const {
+ return thread().promote() != nullptr;
+ }
private:
const wp<IAfEffectChain> mChain;
mediautils::atomic_wp<IAfThreadBase> mThread;
diff --git a/services/audioflinger/IAfThread.h b/services/audioflinger/IAfThread.h
index d701288..4b6ab89 100644
--- a/services/audioflinger/IAfThread.h
+++ b/services/audioflinger/IAfThread.h
@@ -95,7 +95,8 @@
virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect)
EXCLUDES_AudioFlinger_Mutex = 0;
virtual status_t moveEffectChain_ll(audio_session_t sessionId,
- IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread)
+ IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread,
+ IAfEffectChain* srcChain = nullptr)
REQUIRES(mutex(), audio_utils::ThreadBase_Mutex) = 0;
virtual void requestLogMerge() = 0;
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index f1be3976..b519289 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -8217,7 +8217,6 @@
inputStandBy();
reacquire_wakelock:
- sp<IAfRecordTrack> activeTrack;
{
audio_utils::lock_guard _l(mutex());
acquireWakeLock_l();
@@ -8233,6 +8232,8 @@
// loop while there is work to do
for (int64_t loopCount = 0;; ++loopCount) { // loopCount used for statistics tracking
+ // Note: these sp<> are released at the end of the for loop outside of the mutex() lock.
+ sp<IAfRecordTrack> activeTrack;
Vector<sp<IAfEffectChain>> effectChains;
// activeTracks accumulates a copy of a subset of mActiveTracks
diff --git a/services/audioflinger/afutils/Android.bp b/services/audioflinger/afutils/Android.bp
index 5e29ce9..e147266 100644
--- a/services/audioflinger/afutils/Android.bp
+++ b/services/audioflinger/afutils/Android.bp
@@ -23,7 +23,7 @@
tidy_checks: audioflinger_utils_tidy_errors,
tidy_checks_as_errors: audioflinger_utils_tidy_errors,
tidy_flags: [
- "-format-style=file",
+ "-format-style=file",
],
}
@@ -64,10 +64,10 @@
],
header_libs: [
- "libaaudio_headers", // PropertyUtils.cpp
+ "libaaudio_headers", // PropertyUtils.cpp
],
include_dirs: [
- "frameworks/av/services/audioflinger", // for configuration
+ "frameworks/av/services/audioflinger", // for configuration
],
}
diff --git a/services/audioflinger/datapath/Android.bp b/services/audioflinger/datapath/Android.bp
index 4235f14..6918881 100644
--- a/services/audioflinger/datapath/Android.bp
+++ b/services/audioflinger/datapath/Android.bp
@@ -29,7 +29,7 @@
tidy_checks: audioflinger_datapath_tidy_errors,
tidy_checks_as_errors: audioflinger_datapath_tidy_errors,
tidy_flags: [
- "-format-style=file",
+ "-format-style=file",
],
}
@@ -70,6 +70,6 @@
],
include_dirs: [
- "frameworks/av/services/audioflinger", // for configuration
+ "frameworks/av/services/audioflinger", // for configuration
],
}
diff --git a/services/audioflinger/fastpath/Android.bp b/services/audioflinger/fastpath/Android.bp
index 84a580f..5ebc583 100644
--- a/services/audioflinger/fastpath/Android.bp
+++ b/services/audioflinger/fastpath/Android.bp
@@ -24,7 +24,7 @@
tidy_checks: fastpath_tidy_errors,
tidy_checks_as_errors: fastpath_tidy_errors,
tidy_flags: [
- "-format-style=file",
+ "-format-style=file",
],
}
diff --git a/services/audioflinger/sounddose/Android.bp b/services/audioflinger/sounddose/Android.bp
index 2cab5d1..884622e 100644
--- a/services/audioflinger/sounddose/Android.bp
+++ b/services/audioflinger/sounddose/Android.bp
@@ -29,7 +29,7 @@
tidy_checks: audioflinger_sounddose_tidy_errors,
tidy_checks_as_errors: audioflinger_sounddose_tidy_errors,
tidy_flags: [
- "-format-style=file",
+ "-format-style=file",
],
}
@@ -40,9 +40,9 @@
defaults: [
"audioflinger_sounddose_flags_defaults",
- "latest_android_media_audio_common_types_ndk_shared",
"latest_android_hardware_audio_core_sounddose_ndk_shared",
"latest_android_hardware_audio_sounddose_ndk_shared",
+ "latest_android_media_audio_common_types_ndk_shared",
],
srcs: [
@@ -66,9 +66,9 @@
],
cflags: [
+ "-DBACKEND_NDK",
"-Wall",
"-Werror",
- "-DBACKEND_NDK",
],
}
diff --git a/services/audioflinger/sounddose/tests/Android.bp b/services/audioflinger/sounddose/tests/Android.bp
index 60e170d..fcbebe1 100644
--- a/services/audioflinger/sounddose/tests/Android.bp
+++ b/services/audioflinger/sounddose/tests/Android.bp
@@ -16,9 +16,9 @@
],
defaults: [
- "latest_android_media_audio_common_types_ndk_static",
"latest_android_hardware_audio_core_sounddose_ndk_static",
"latest_android_hardware_audio_sounddose_ndk_static",
+ "latest_android_media_audio_common_types_ndk_static",
],
shared_libs: [
@@ -43,10 +43,10 @@
],
cflags: [
+ "-DBACKEND_NDK",
"-Wall",
"-Werror",
"-Wextra",
- "-DBACKEND_NDK",
],
test_suites: [
diff --git a/services/audioflinger/timing/Android.bp b/services/audioflinger/timing/Android.bp
index 30ebca0..2666ddb 100644
--- a/services/audioflinger/timing/Android.bp
+++ b/services/audioflinger/timing/Android.bp
@@ -29,7 +29,7 @@
tidy_checks: audioflinger_timing_tidy_errors,
tidy_checks_as_errors: audioflinger_timing_tidy_errors,
tidy_flags: [
- "-format-style=file",
+ "-format-style=file",
],
}
diff --git a/services/audioparameterparser/Android.bp b/services/audioparameterparser/Android.bp
index b3da333..f5feece 100644
--- a/services/audioparameterparser/Android.bp
+++ b/services/audioparameterparser/Android.bp
@@ -45,8 +45,8 @@
cflags: [
"-Wall",
- "-Wextra",
"-Werror",
+ "-Wextra",
"-Wthread-safety",
],
}
diff --git a/services/audiopolicy/AudioPolicyInterface.h b/services/audiopolicy/AudioPolicyInterface.h
index bfc3132..8f17ffc 100644
--- a/services/audiopolicy/AudioPolicyInterface.h
+++ b/services/audiopolicy/AudioPolicyInterface.h
@@ -166,7 +166,8 @@
audio_input_flags_t flags,
audio_port_handle_t *selectedDeviceId,
input_type_t *inputType,
- audio_port_handle_t *portId) = 0;
+ audio_port_handle_t *portId,
+ uint32_t *virtualDeviceId) = 0;
// indicates to the audio policy manager that the input starts being used.
virtual status_t startInput(audio_port_handle_t portId) = 0;
// indicates to the audio policy manager that the input stops being used.
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
index 7c70877..00958aa 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
@@ -16,7 +16,6 @@
#pragma once
-#define __STDC_LIMIT_MACROS
#include <inttypes.h>
#include <sys/types.h>
diff --git a/services/audiopolicy/engine/common/Android.bp b/services/audiopolicy/engine/common/Android.bp
index a93c816..9e07d79 100644
--- a/services/audiopolicy/engine/common/Android.bp
+++ b/services/audiopolicy/engine/common/Android.bp
@@ -32,10 +32,10 @@
name: "libaudiopolicyengine_common",
srcs: [
"src/EngineBase.cpp",
+ "src/LastRemovableMediaDevices.cpp",
"src/ProductStrategy.cpp",
"src/VolumeCurve.cpp",
"src/VolumeGroup.cpp",
- "src/LastRemovableMediaDevices.cpp",
],
cflags: [
"-Wall",
@@ -43,10 +43,10 @@
"-Wextra",
],
header_libs: [
- "libbase_headers",
"libaudiopolicycommon",
"libaudiopolicyengine_common_headers",
"libaudiopolicyengine_interface_headers",
+ "libbase_headers",
],
export_header_lib_headers: [
"libaudiopolicyengine_common_headers",
@@ -59,7 +59,7 @@
"libaudiopolicycomponents",
],
whole_static_libs: [
- "server_configurable_flags",
"com.android.media.audio-aconfig-cc",
+ "server_configurable_flags",
],
}
diff --git a/services/audiopolicy/engine/common/src/VolumeCurve.cpp b/services/audiopolicy/engine/common/src/VolumeCurve.cpp
index fccbc60..9411155 100644
--- a/services/audiopolicy/engine/common/src/VolumeCurve.cpp
+++ b/services/audiopolicy/engine/common/src/VolumeCurve.cpp
@@ -69,7 +69,7 @@
return mCurvePoints[nbCurvePoints - 1].mAttenuationInMb / 100.0f;
}
if (indexInUiPosition == 0) {
- if (indexInUiPosition != mCurvePoints[0].mIndex) {
+ if ((size_t)volIdx != mCurvePoints[0].mIndex) {
return VOLUME_MIN_DB; // out of bounds
}
return mCurvePoints[0].mAttenuationInMb / 100.0f;
diff --git a/services/audiopolicy/engine/config/Android.bp b/services/audiopolicy/engine/config/Android.bp
index 0864e6a..ab2c134 100644
--- a/services/audiopolicy/engine/config/Android.bp
+++ b/services/audiopolicy/engine/config/Android.bp
@@ -33,7 +33,7 @@
],
header_libs: [
"libaudio_system_headers",
- "libmedia_headers",
"libaudioclient_headers",
+ "libmedia_headers",
],
}
diff --git a/services/audiopolicy/engine/config/tests/Android.bp b/services/audiopolicy/engine/config/tests/Android.bp
index 8c7b7db..2df51d0 100644
--- a/services/audiopolicy/engine/config/tests/Android.bp
+++ b/services/audiopolicy/engine/config/tests/Android.bp
@@ -28,8 +28,8 @@
data: [":audiopolicy_engineconfig_files"],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
test_suites: ["device-tests"],
diff --git a/services/audiopolicy/engineconfigurable/Android.bp b/services/audiopolicy/engineconfigurable/Android.bp
index d59ab5a..66df930 100644
--- a/services/audiopolicy/engineconfigurable/Android.bp
+++ b/services/audiopolicy/engineconfigurable/Android.bp
@@ -20,8 +20,8 @@
srcs: [
"src/Engine.cpp",
"src/EngineInstance.cpp",
- "src/Stream.cpp",
"src/InputSource.cpp",
+ "src/Stream.cpp",
],
cflags: [
"-Wall",
@@ -30,10 +30,10 @@
],
local_include_dirs: ["include"],
header_libs: [
- "libbase_headers",
"libaudiopolicycommon",
"libaudiopolicyengine_interface_headers",
"libaudiopolicyengineconfigurable_interface_headers",
+ "libbase_headers",
],
static_libs: [
"libaudiopolicyengine_common",
@@ -44,14 +44,14 @@
shared_libs: [
"libaudio_aidl_conversion_common_cpp",
"libaudiofoundation",
+ "libaudiopolicy",
"libaudiopolicycomponents",
"libbase",
- "liblog",
"libcutils",
- "libutils",
+ "liblog",
"libmedia_helper",
- "libaudiopolicy",
"libparameter",
+ "libutils",
"libxml2",
],
}
diff --git a/services/audiopolicy/engineconfigurable/config/example/automotive/Android.bp b/services/audiopolicy/engineconfigurable/config/example/automotive/Android.bp
index fb1a71c..7e429ef 100644
--- a/services/audiopolicy/engineconfigurable/config/example/automotive/Android.bp
+++ b/services/audiopolicy/engineconfigurable/config/example/automotive/Android.bp
@@ -37,8 +37,8 @@
vendor: true,
src: ":audio_policy_engine_configuration",
required: [
- ":audio_policy_engine_criterion_types.xml",
":audio_policy_engine_criteria.xml",
+ ":audio_policy_engine_criterion_types.xml",
":audio_policy_engine_product_strategies.xml",
":audio_policy_engine_volumes.xml",
],
@@ -69,19 +69,19 @@
name: "audio_policy_engine_criterion_types",
defaults: ["buildpolicycriteriontypesrule"],
srcs: [
- ":audio_policy_configuration_top_file",
":audio_policy_configuration_files",
+ ":audio_policy_configuration_top_file",
],
}
filegroup {
name: "audio_policy_configuration_files",
srcs: [
- ":r_submix_audio_policy_configuration",
- ":default_volume_tables",
":audio_policy_volumes",
- ":surround_sound_configuration_5_0",
+ ":default_volume_tables",
":primary_audio_policy_configuration",
+ ":r_submix_audio_policy_configuration",
+ ":surround_sound_configuration_5_0",
],
}
@@ -104,9 +104,9 @@
name: "audio_policy_engine_configuration_files",
srcs: [
":audio_policy_engine_configuration",
- "audio_policy_engine_product_strategies.xml",
- ":audio_policy_engine_volumes",
- ":audio_policy_engine_criterion_types",
":audio_policy_engine_criteria",
+ ":audio_policy_engine_criterion_types",
+ ":audio_policy_engine_volumes",
+ "audio_policy_engine_product_strategies.xml",
],
}
diff --git a/services/audiopolicy/engineconfigurable/config/example/caremu/Android.bp b/services/audiopolicy/engineconfigurable/config/example/caremu/Android.bp
index b9abb54..12a554d 100644
--- a/services/audiopolicy/engineconfigurable/config/example/caremu/Android.bp
+++ b/services/audiopolicy/engineconfigurable/config/example/caremu/Android.bp
@@ -18,8 +18,8 @@
soong_namespace {
imports: [
- "frameworks/av/services/audiopolicy/engineconfigurable/config/example/automotive",
"frameworks/av/services/audiopolicy/config",
+ "frameworks/av/services/audiopolicy/engineconfigurable/config/example/automotive",
],
}
@@ -38,10 +38,10 @@
vendor: true,
src: ":audio_policy_engine_configuration",
required: [
- "audio_policy_engine_criterion_types.xml",
- "audio_policy_engine_criteria.xml",
- "audio_policy_engine_product_strategies.xml",
":audio_policy_engine_volumes.xml",
+ "audio_policy_engine_criteria.xml",
+ "audio_policy_engine_criterion_types.xml",
+ "audio_policy_engine_product_strategies.xml",
],
}
@@ -64,19 +64,19 @@
name: "audio_policy_engine_criterion_types",
defaults: ["buildpolicycriteriontypesrule"],
srcs: [
- ":audio_policy_configuration_top_file",
":audio_policy_configuration_files",
+ ":audio_policy_configuration_top_file",
],
}
filegroup {
name: "audio_policy_configuration_files",
srcs: [
- ":r_submix_audio_policy_configuration",
- ":default_volume_tables",
":audio_policy_volumes",
- ":surround_sound_configuration_5_0",
+ ":default_volume_tables",
":primary_audio_policy_configuration",
+ ":r_submix_audio_policy_configuration",
+ ":surround_sound_configuration_5_0",
],
}
@@ -89,9 +89,9 @@
name: "audio_policy_engine_configuration_files",
srcs: [
":audio_policy_engine_configuration",
- "audio_policy_engine_product_strategies.xml",
- ":audio_policy_engine_volumes",
- ":audio_policy_engine_criterion_types",
":audio_policy_engine_criteria",
+ ":audio_policy_engine_criterion_types",
+ ":audio_policy_engine_volumes",
+ "audio_policy_engine_product_strategies.xml",
],
}
diff --git a/services/audiopolicy/engineconfigurable/config/example/phone/Android.bp b/services/audiopolicy/engineconfigurable/config/example/phone/Android.bp
index 67a6128..b0a4dfd 100644
--- a/services/audiopolicy/engineconfigurable/config/example/phone/Android.bp
+++ b/services/audiopolicy/engineconfigurable/config/example/phone/Android.bp
@@ -37,8 +37,8 @@
vendor: true,
src: ":audio_policy_engine_configuration",
required: [
- ":audio_policy_engine_criterion_types.xml",
":audio_policy_engine_criteria.xml",
+ ":audio_policy_engine_criterion_types.xml",
":audio_policy_engine_product_strategies.xml",
":audio_policy_engine_volumes.xml",
],
@@ -75,19 +75,19 @@
name: "audio_policy_engine_criterion_types",
defaults: ["buildpolicycriteriontypesrule"],
srcs: [
- ":audio_policy_configuration_top_file",
":audio_policy_configuration_files",
+ ":audio_policy_configuration_top_file",
],
}
filegroup {
name: "audio_policy_configuration_files",
srcs: [
- ":r_submix_audio_policy_configuration",
- ":default_volume_tables",
":audio_policy_volumes",
- ":surround_sound_configuration_5_0",
+ ":default_volume_tables",
":primary_audio_policy_configuration",
+ ":r_submix_audio_policy_configuration",
+ ":surround_sound_configuration_5_0",
],
}
@@ -115,10 +115,10 @@
name: "audio_policy_engine_configuration_files",
srcs: [
":audio_policy_engine_configuration",
- "audio_policy_engine_product_strategies.xml",
- ":audio_policy_engine_stream_volumes",
- ":audio_policy_engine_default_stream_volumes",
- ":audio_policy_engine_criterion_types",
":audio_policy_engine_criteria",
+ ":audio_policy_engine_criterion_types",
+ ":audio_policy_engine_default_stream_volumes",
+ ":audio_policy_engine_stream_volumes",
+ "audio_policy_engine_product_strategies.xml",
],
}
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/examples/Car/Android.bp b/services/audiopolicy/engineconfigurable/parameter-framework/examples/Car/Android.bp
index 38451f2..42585e9 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/examples/Car/Android.bp
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/examples/Car/Android.bp
@@ -18,8 +18,8 @@
soong_namespace {
imports: [
- "frameworks/av/services/audiopolicy/engineconfigurable/config/example/automotive",
"frameworks/av/services/audiopolicy/config",
+ "frameworks/av/services/audiopolicy/engineconfigurable/config/example/automotive",
],
}
@@ -63,10 +63,10 @@
src: ":domaingeneratorpolicyrule_gen",
sub_dir: "parameter-framework/Settings/Policy",
required: [
- "ProductStrategies.xml",
"PolicyClass.xml",
- "PolicySubsystem.xml",
"PolicySubsystem-CommonTypes.xml",
+ "PolicySubsystem.xml",
+ "ProductStrategies.xml",
],
}
@@ -75,9 +75,9 @@
enabled: false, // TODO: This module fails to build
defaults: ["domaingeneratorpolicyrule"],
srcs: [
- ":audio_policy_pfw_toplevel",
- ":audio_policy_pfw_structure_files",
":audio_policy_engine_criterion_types",
+ ":audio_policy_pfw_structure_files",
+ ":audio_policy_pfw_toplevel",
":edd_files",
],
}
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/examples/CarEmu/Android.bp b/services/audiopolicy/engineconfigurable/parameter-framework/examples/CarEmu/Android.bp
index eae6ae2..efde298 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/examples/CarEmu/Android.bp
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/examples/CarEmu/Android.bp
@@ -18,9 +18,9 @@
soong_namespace {
imports: [
+ "frameworks/av/services/audiopolicy/config",
"frameworks/av/services/audiopolicy/engineconfigurable/config/example/caremu",
"frameworks/av/services/audiopolicy/engineconfigurable/parameter-framework/examples/Car",
- "frameworks/av/services/audiopolicy/config",
],
}
@@ -64,10 +64,10 @@
src: ":domaingeneratorpolicyrule_gen",
sub_dir: "parameter-framework/Settings/Policy",
required: [
- "ProductStrategies.xml",
"PolicyClass.xml",
- "PolicySubsystem.xml",
"PolicySubsystem-CommonTypes.xml",
+ "PolicySubsystem.xml",
+ "ProductStrategies.xml",
],
}
@@ -76,9 +76,9 @@
enabled: false, // TODO: This module fails to build
defaults: ["domaingeneratorpolicyrule"],
srcs: [
- ":audio_policy_pfw_toplevel",
- ":audio_policy_pfw_structure_files",
":audio_policy_engine_criterion_types",
+ ":audio_policy_pfw_structure_files",
+ ":audio_policy_pfw_toplevel",
":edd_files",
],
}
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/examples/Phone/Android.bp b/services/audiopolicy/engineconfigurable/parameter-framework/examples/Phone/Android.bp
index 4e8654b..474094e 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/examples/Phone/Android.bp
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/examples/Phone/Android.bp
@@ -18,8 +18,8 @@
soong_namespace {
imports: [
- "frameworks/av/services/audiopolicy/engineconfigurable/config/example/phone",
"frameworks/av/services/audiopolicy/config",
+ "frameworks/av/services/audiopolicy/engineconfigurable/config/example/phone",
],
}
@@ -63,10 +63,10 @@
src: ":domaingeneratorpolicyrule_gen",
sub_dir: "parameter-framework/Settings/Policy",
required: [
- "ProductStrategies.xml",
"PolicyClass.xml",
- "PolicySubsystem.xml",
"PolicySubsystem-CommonTypes.xml",
+ "PolicySubsystem.xml",
+ "ProductStrategies.xml",
],
}
@@ -75,9 +75,9 @@
enabled: false, // TODO: This module fails to build
defaults: ["domaingeneratorpolicyrule"],
srcs: [
- ":audio_policy_pfw_toplevel",
- ":audio_policy_pfw_structure_files",
":audio_policy_engine_criterion_types",
+ ":audio_policy_pfw_structure_files",
+ ":audio_policy_pfw_toplevel",
":edd_files",
],
}
@@ -87,16 +87,16 @@
srcs: [
":device_for_input_source.pfw",
":volumes.pfw",
- "Settings/device_for_product_strategy_media.pfw",
"Settings/device_for_product_strategy_accessibility.pfw",
"Settings/device_for_product_strategy_dtmf.pfw",
"Settings/device_for_product_strategy_enforced_audible.pfw",
+ "Settings/device_for_product_strategy_media.pfw",
+ "Settings/device_for_product_strategy_patch.pfw",
"Settings/device_for_product_strategy_phone.pfw",
+ "Settings/device_for_product_strategy_rerouting.pfw",
"Settings/device_for_product_strategy_sonification.pfw",
"Settings/device_for_product_strategy_sonification_respectful.pfw",
"Settings/device_for_product_strategy_transmitted_through_speaker.pfw",
- "Settings/device_for_product_strategy_rerouting.pfw",
- "Settings/device_for_product_strategy_patch.pfw",
],
}
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/examples/SettingsNoInput/Android.bp b/services/audiopolicy/engineconfigurable/parameter-framework/examples/SettingsNoInput/Android.bp
index e279a8f..aba9767 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/examples/SettingsNoInput/Android.bp
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/examples/SettingsNoInput/Android.bp
@@ -18,8 +18,8 @@
soong_namespace {
imports: [
- "frameworks/av/services/audiopolicy/engineconfigurable/config/example/phone",
"frameworks/av/services/audiopolicy/config",
+ "frameworks/av/services/audiopolicy/engineconfigurable/config/example/phone",
],
}
@@ -42,8 +42,8 @@
sub_dir: "parameter-framework/Settings/Policy",
required: [
"PolicyClass.xml",
- "PolicySubsystem.xml",
"PolicySubsystem-CommonTypes.xml",
+ "PolicySubsystem.xml",
],
}
@@ -52,9 +52,9 @@
enabled: false, // TODO: This module fails to build
defaults: ["domaingeneratorpolicyrule"],
srcs: [
- ":audio_policy_pfw_toplevel",
- ":audio_policy_pfw_structure_files",
":audio_policy_engine_criterion_types",
+ ":audio_policy_pfw_structure_files",
+ ":audio_policy_pfw_toplevel",
":edd_files",
],
}
@@ -76,8 +76,8 @@
filegroup {
name: "edd_files",
srcs: [
- "device_for_input_source.pfw",
":volumes.pfw",
+ "device_for_input_source.pfw",
],
}
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/examples/SettingsNoOutput/Android.bp b/services/audiopolicy/engineconfigurable/parameter-framework/examples/SettingsNoOutput/Android.bp
index 47b8b54..77677a1 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/examples/SettingsNoOutput/Android.bp
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/examples/SettingsNoOutput/Android.bp
@@ -18,8 +18,8 @@
soong_namespace {
imports: [
- "frameworks/av/services/audiopolicy/engineconfigurable/config/example/phone",
"frameworks/av/services/audiopolicy/config",
+ "frameworks/av/services/audiopolicy/engineconfigurable/config/example/phone",
],
}
@@ -42,8 +42,8 @@
sub_dir: "parameter-framework/Settings/Policy",
required: [
"PolicyClass.xml",
- "PolicySubsystem.xml",
"PolicySubsystem-CommonTypes.xml",
+ "PolicySubsystem.xml",
],
}
@@ -52,9 +52,9 @@
enabled: false, // TODO: This module fails to build
defaults: ["domaingeneratorpolicyrule"],
srcs: [
- ":audio_policy_pfw_toplevel",
- ":audio_policy_pfw_structure_files",
":audio_policy_engine_criterion_types",
+ ":audio_policy_pfw_structure_files",
+ ":audio_policy_pfw_toplevel",
":edd_files",
],
}
@@ -76,9 +76,9 @@
filegroup {
name: "edd_files",
srcs: [
- "device_for_strategies.pfw",
- ":volumes.pfw",
":device_for_input_source.pfw",
+ ":volumes.pfw",
+ "device_for_strategies.pfw",
],
}
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Android.bp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Android.bp
index aa2163e..3dc2229 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Android.bp
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Android.bp
@@ -11,11 +11,11 @@
cc_library_shared {
name: "libpolicy-subsystem",
srcs: [
- "PolicySubsystemBuilder.cpp",
- "PolicySubsystem.cpp",
"InputSource.cpp",
- "Stream.cpp",
+ "PolicySubsystem.cpp",
+ "PolicySubsystemBuilder.cpp",
"ProductStrategy.cpp",
+ "Stream.cpp",
],
cflags: [
"-Wall",
@@ -25,11 +25,11 @@
"-fvisibility=hidden",
],
header_libs: [
- "libbase_headers",
- "libaudiopolicycommon",
"libaudioclient_headers",
+ "libaudiopolicycommon",
"libaudiopolicyengine_interface_headers",
"libaudiopolicyengineconfigurable_interface_headers",
+ "libbase_headers",
],
static_libs: [
"libaudiopolicyengine_common",
@@ -39,8 +39,8 @@
"libaudiopolicycomponents",
"libaudiopolicyengineconfigurable",
"liblog",
- "libutils",
"libmedia_helper",
"libparameter",
+ "libutils",
],
}
diff --git a/services/audiopolicy/engineconfigurable/tools/Android.bp b/services/audiopolicy/engineconfigurable/tools/Android.bp
index 2f77372..d1fb2fb 100644
--- a/services/audiopolicy/engineconfigurable/tools/Android.bp
+++ b/services/audiopolicy/engineconfigurable/tools/Android.bp
@@ -67,8 +67,8 @@
],
libs: [
"EddParser.py",
- "hostConfig.py",
"PFWScriptGenerator.py",
+ "hostConfig.py",
],
required: [
"domainGeneratorConnector",
@@ -78,8 +78,8 @@
genrule_defaults {
name: "domaingeneratorpolicyrule",
tools: [
- "domainGeneratorPolicy",
"domainGeneratorConnector",
+ "domainGeneratorPolicy",
],
cmd: "mkdir -p $(genDir)/Structure/Policy && " +
"cp $(locations :audio_policy_pfw_structure_files) $(genDir)/Structure/Policy && " +
diff --git a/services/audiopolicy/engineconfigurable/wrapper/Android.bp b/services/audiopolicy/engineconfigurable/wrapper/Android.bp
index a897880..78d5fa3 100644
--- a/services/audiopolicy/engineconfigurable/wrapper/Android.bp
+++ b/services/audiopolicy/engineconfigurable/wrapper/Android.bp
@@ -18,14 +18,14 @@
"-Wextra",
],
header_libs: [
- "libbase_headers",
- "libaudiopolicycommon",
"libaudiofoundation_headers",
+ "libaudiopolicycommon",
+ "libbase_headers",
],
shared_libs: [
"liblog",
- "libutils",
"libmedia_helper",
"libparameter",
+ "libutils",
],
}
diff --git a/services/audiopolicy/enginedefault/Android.bp b/services/audiopolicy/enginedefault/Android.bp
index 98adff0..7810d63 100644
--- a/services/audiopolicy/enginedefault/Android.bp
+++ b/services/audiopolicy/enginedefault/Android.bp
@@ -15,15 +15,15 @@
"src/EngineInstance.cpp",
],
cflags: [
- "-fvisibility=hidden",
"-Wall",
"-Werror",
"-Wextra",
+ "-fvisibility=hidden",
],
header_libs: [
- "libbase_headers",
"libaudiopolicycommon",
"libaudiopolicyengine_interface_headers",
+ "libbase_headers",
],
static_libs: [
"libaudiopolicyengine_common",
@@ -32,13 +32,13 @@
shared_libs: [
"libaudio_aidl_conversion_common_cpp",
"libaudiofoundation",
+ "libaudiopolicy",
"libaudiopolicycomponents",
"libbase",
- "liblog",
"libcutils",
- "libutils",
+ "liblog",
"libmedia_helper",
- "libaudiopolicy",
+ "libutils",
"libxml2",
],
}
diff --git a/services/audiopolicy/enginedefault/config/example/Android.bp b/services/audiopolicy/enginedefault/config/example/Android.bp
index f305c39..31f9a46 100644
--- a/services/audiopolicy/enginedefault/config/example/Android.bp
+++ b/services/audiopolicy/enginedefault/config/example/Android.bp
@@ -34,9 +34,9 @@
vendor: true,
src: "phone/audio_policy_engine_configuration.xml",
required: [
- ":audio_policy_engine_stream_volumes.xml",
":audio_policy_engine_default_stream_volumes.xml",
":audio_policy_engine_product_strategies.xml",
+ ":audio_policy_engine_stream_volumes.xml",
],
}
diff --git a/services/audiopolicy/fuzzer/Android.bp b/services/audiopolicy/fuzzer/Android.bp
index fca02e4..8cee613 100644
--- a/services/audiopolicy/fuzzer/Android.bp
+++ b/services/audiopolicy/fuzzer/Android.bp
@@ -37,22 +37,22 @@
shared_libs: [
"android.hardware.audio.common-util",
"capture_state_listener-aidl-cpp",
+ "framework-permission-aidl-cpp",
"libaudioclient",
"libaudiofoundation",
+ "libaudiopolicy",
"libaudiopolicycomponents",
+ "libaudiopolicymanagerdefault",
"libbase",
+ "libbinder",
"libcutils",
- "libhidlbase",
"libdl",
+ "libhidlbase",
"liblog",
"libmedia_helper",
"libmediametrics",
"libutils",
"libxml2",
- "libbinder",
- "libaudiopolicy",
- "libaudiopolicymanagerdefault",
- "framework-permission-aidl-cpp",
],
static_libs: [
"android.hardware.audio.common@7.0-enums",
diff --git a/services/audiopolicy/fuzzer/aidl/Android.bp b/services/audiopolicy/fuzzer/aidl/Android.bp
index 8b37d36..2c85955 100644
--- a/services/audiopolicy/fuzzer/aidl/Android.bp
+++ b/services/audiopolicy/fuzzer/aidl/Android.bp
@@ -26,30 +26,31 @@
"audiopolicy-aidl-cpp",
"audiopolicy-types-aidl-cpp",
"framework-permission-aidl-cpp",
+ "libactivitymanager_aidl",
+ "libaudioclient",
+ "libaudioflinger",
+ "libaudiohal",
"libaudiopolicy",
"libaudiopolicymanagerdefault",
- "libactivitymanager_aidl",
- "libaudiohal",
"libaudiopolicyservice",
- "libaudioflinger",
- "libaudioclient",
"libaudioprocessing",
"libhidlbase",
"liblog",
"libmediautils",
- "libnblog",
"libnbaio",
+ "libnblog",
"libpowermanager",
"libvibrator",
"packagemanager_aidl-cpp",
],
static_libs: [
+ "libaudiomockhal",
"libfakeservicemanager",
"libmediaplayerservice",
],
header_libs: [
- "libaudiohal_headers",
"libaudioflinger_headers",
+ "libaudiohal_headers",
"libaudiopolicymanager_interface_headers",
"libbinder_headers",
"libmedia_headers",
@@ -73,6 +74,9 @@
srcs: ["audiopolicy_aidl_fuzzer.cpp"],
defaults: [
"audiopolicy_aidl_fuzzer_defaults",
+ "latest_android_hardware_audio_core_ndk_shared",
+ "latest_android_hardware_audio_core_sounddose_ndk_shared",
+ "latest_android_hardware_audio_effect_ndk_shared",
"service_fuzzer_defaults",
],
}
diff --git a/services/audiopolicy/fuzzer/aidl/audiopolicy_aidl_fuzzer.cpp b/services/audiopolicy/fuzzer/aidl/audiopolicy_aidl_fuzzer.cpp
index ca79c49..3d972dc 100644
--- a/services/audiopolicy/fuzzer/aidl/audiopolicy_aidl_fuzzer.cpp
+++ b/services/audiopolicy/fuzzer/aidl/audiopolicy_aidl_fuzzer.cpp
@@ -18,8 +18,12 @@
#include <AudioFlinger.h>
#include <android-base/logging.h>
#include <android/binder_interface_utils.h>
+#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <android/media/IAudioPolicyService.h>
+#include <core-mock/ConfigMock.h>
+#include <core-mock/ModuleMock.h>
+#include <effect-mock/FactoryMock.h>
#include <fakeservicemanager/FakeServiceManager.h>
#include <fuzzbinder/libbinder_driver.h>
#include <fuzzbinder/random_binder.h>
@@ -55,14 +59,26 @@
});
gFakeServiceManager->clear();
- for (const char* service :
- {"activity", "sensor_privacy", "permission", "scheduling_policy",
- "android.hardware.audio.core.IConfig", "batterystats", "media.metrics"}) {
+ for (const char* service : {"activity", "sensor_privacy", "permission", "scheduling_policy",
+ "batterystats", "media.metrics"}) {
if (!addService(String16(service), gFakeServiceManager, fdp)) {
return 0;
}
}
+ auto configService = ndk::SharedRefBase::make<ConfigMock>();
+ CHECK_EQ(NO_ERROR, AServiceManager_addService(configService.get()->asBinder().get(),
+ "android.hardware.audio.core.IConfig/default"));
+
+ auto factoryService = ndk::SharedRefBase::make<FactoryMock>();
+ CHECK_EQ(NO_ERROR,
+ AServiceManager_addService(factoryService.get()->asBinder().get(),
+ "android.hardware.audio.effect.IFactory/default"));
+
+ auto moduleService = ndk::SharedRefBase::make<ModuleMock>();
+ CHECK_EQ(NO_ERROR, AServiceManager_addService(moduleService.get()->asBinder().get(),
+ "android.hardware.audio.core.IModule/default"));
+
const auto audioFlinger = sp<AudioFlinger>::make();
const auto afAdapter = sp<AudioFlingerServerAdapter>::make(audioFlinger);
@@ -79,8 +95,7 @@
false /* allowIsolated */,
IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT));
- fuzzService(media::IAudioPolicyService::asBinder(audioPolicyService),
- FuzzedDataProvider(data, size));
+ fuzzService(media::IAudioPolicyService::asBinder(audioPolicyService), std::move(fdp));
return 0;
}
diff --git a/services/audiopolicy/fuzzer/audiopolicy_fuzzer.cpp b/services/audiopolicy/fuzzer/audiopolicy_fuzzer.cpp
index 58fcb5c..6416a47 100644
--- a/services/audiopolicy/fuzzer/audiopolicy_fuzzer.cpp
+++ b/services/audiopolicy/fuzzer/audiopolicy_fuzzer.cpp
@@ -207,7 +207,8 @@
audio_port_handle_t *selectedDeviceId, audio_format_t format,
audio_channel_mask_t channelMask, int sampleRate,
audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
- audio_port_handle_t *portId = nullptr);
+ audio_port_handle_t *portId = nullptr,
+ uint32_t *virtualDeviceId = nullptr);
bool findDevicePort(audio_port_role_t role, audio_devices_t deviceType,
const std::string &address, audio_port_v7 *foundPort);
static audio_port_handle_t getDeviceIdFromPatch(const struct audio_patch *patch);
@@ -283,7 +284,7 @@
bool AudioPolicyManagerFuzzer::getInputForAttr(
const audio_attributes_t &attr, audio_unique_id_t riid, audio_port_handle_t *selectedDeviceId,
audio_format_t format, audio_channel_mask_t channelMask, int sampleRate,
- audio_input_flags_t flags, audio_port_handle_t *portId) {
+ audio_input_flags_t flags, audio_port_handle_t *portId, uint32_t *virtualDeviceId) {
audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER;
config.sample_rate = sampleRate;
@@ -298,7 +299,7 @@
attributionSource.uid = 0;
attributionSource.token = sp<BBinder>::make();
if (mManager->getInputForAttr(&attr, &input, riid, AUDIO_SESSION_NONE, attributionSource,
- &config, flags, selectedDeviceId, &inputType, portId) != OK) {
+ &config, flags, selectedDeviceId, &inputType, portId, virtualDeviceId) != OK) {
return false;
}
if (*portId == AUDIO_PORT_HANDLE_NONE || input == AUDIO_IO_HANDLE_NONE) {
diff --git a/services/audiopolicy/managerdefault/Android.bp b/services/audiopolicy/managerdefault/Android.bp
index 2f46d48..c1b8705 100644
--- a/services/audiopolicy/managerdefault/Android.bp
+++ b/services/audiopolicy/managerdefault/Android.bp
@@ -25,26 +25,26 @@
shared_libs: [
"com.android.media.audio-aconfig-cc",
"libaudiofoundation",
+ "libaudiopolicy",
"libaudiopolicycomponents",
+ "libbinder",
"libcutils",
"libdl",
- "libutils",
+ "libhidlbase",
"liblog",
- "libaudiopolicy",
"libmedia_helper",
"libmediametrics",
- "libbinder",
- "libhidlbase",
+ "libutils",
"libxml2",
// The default audio policy engine is always present in the system image.
// libaudiopolicyengineconfigurable can be built in addition by specifying
// a dependency on it in the device makefile. There will be no build time
// conflict with libaudiopolicyenginedefault.
- "libaudiopolicyenginedefault",
- "framework-permission-aidl-cpp",
- "libaudioclient_aidl_conversion",
"audioclient-types-aidl-cpp",
// Flag support
+ "framework-permission-aidl-cpp",
+ "libaudioclient_aidl_conversion",
+ "libaudiopolicyenginedefault",
"android.media.audiopolicy-aconfig-cc",
"com.android.media.audioserver-aconfig-cc",
],
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 154172a..efcd420 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -2697,7 +2697,8 @@
audio_input_flags_t flags,
audio_port_handle_t *selectedDeviceId,
input_type_t *inputType,
- audio_port_handle_t *portId)
+ audio_port_handle_t *portId,
+ uint32_t *virtualDeviceId)
{
ALOGV("%s() source %d, sampling rate %d, format %#x, channel mask %#x, session %d, "
"flags %#x attributes=%s requested device ID %d",
@@ -2799,6 +2800,9 @@
} else {
*inputType = API_INPUT_MIX_EXT_POLICY_REROUTE;
}
+ if (virtualDeviceId) {
+ *virtualDeviceId = policyMix->mVirtualDeviceId;
+ }
} else {
if (explicitRoutingDevice != nullptr) {
device = explicitRoutingDevice;
@@ -2822,6 +2826,10 @@
// meaning it receives audio injected into the framework, so the recorder doesn't
// know about it and is therefore considered "legacy"
*inputType = API_INPUT_LEGACY;
+
+ if (virtualDeviceId) {
+ *virtualDeviceId = policyMix->mVirtualDeviceId;
+ }
} else if (audio_is_remote_submix_device(device->type())) {
*inputType = API_INPUT_MIX_CAPTURE;
} else if (device->type() == AUDIO_DEVICE_IN_TELEPHONY_RX) {
@@ -2853,6 +2861,11 @@
goto error;
}
+
+ if (policyMix != nullptr && virtualDeviceId != nullptr) {
+ *virtualDeviceId = policyMix->mVirtualDeviceId;
+ }
+
exit:
*selectedDeviceId = mAvailableInputDevices.contains(device) ?
@@ -3900,6 +3913,7 @@
policyMix->mCbFlags);
_aidl_return.back().mDeviceType = policyMix->mDeviceType;
_aidl_return.back().mToken = policyMix->mToken;
+ _aidl_return.back().mVirtualDeviceId = policyMix->mVirtualDeviceId;
}
ALOGVV("%s() returning %zu registered mixes", __func__, _aidl_return.size());
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index a3232a2..0454e6e 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -141,7 +141,8 @@
audio_input_flags_t flags,
audio_port_handle_t *selectedDeviceId,
input_type_t *inputType,
- audio_port_handle_t *portId);
+ audio_port_handle_t *portId,
+ uint32_t *virtualDeviceId);
// indicates to the audio policy manager that the input starts being used.
virtual status_t startInput(audio_port_handle_t portId);
diff --git a/services/audiopolicy/service/Android.bp b/services/audiopolicy/service/Android.bp
index 05b0ddb..dae3cce 100644
--- a/services/audiopolicy/service/Android.bp
+++ b/services/audiopolicy/service/Android.bp
@@ -12,6 +12,14 @@
name: "libaudiopolicyservice_dependencies",
shared_libs: [
+ "audioclient-types-aidl-cpp",
+ "audioflinger-aidl-cpp",
+ "audiopolicy-aidl-cpp",
+ "audiopolicy-types-aidl-cpp",
+ "capture_state_listener-aidl-cpp",
+ "com.android.media.audio-aconfig-cc",
+ "framework-permission-aidl-cpp",
+ "libPlatformProperties",
"libactivitymanager_aidl",
"libaudioclient",
"libaudioclient_aidl_conversion",
@@ -32,27 +40,20 @@
"libmediametrics",
"libmediautils",
"libpermission",
- "libPlatformProperties",
"libsensor",
"libsensorprivacy",
"libshmemcompat",
"libstagefright_foundation",
"libutils",
"libxml2",
- "audioclient-types-aidl-cpp",
- "audioflinger-aidl-cpp",
- "audiopolicy-aidl-cpp",
- "audiopolicy-types-aidl-cpp",
- "capture_state_listener-aidl-cpp",
- "com.android.media.audio-aconfig-cc",
- "framework-permission-aidl-cpp",
+ "android.media.audiopolicy-aconfig-cc",
"packagemanager_aidl-cpp",
"spatializer-aidl-cpp",
],
static_libs: [
- "libeffectsconfig",
"libaudiopolicycomponents",
+ "libeffectsconfig",
],
}
@@ -60,16 +61,16 @@
name: "libaudiopolicyservice",
defaults: [
- "libaudiopolicyservice_dependencies",
"latest_android_media_audio_common_types_cpp_shared",
+ "libaudiopolicyservice_dependencies",
],
srcs: [
- "AudioRecordClient.cpp",
"AudioPolicyClientImpl.cpp",
"AudioPolicyEffects.cpp",
"AudioPolicyInterfaceImpl.cpp",
"AudioPolicyService.cpp",
+ "AudioRecordClient.cpp",
"CaptureStateNotifier.cpp",
"Spatializer.cpp",
"SpatializerPoseController.cpp",
@@ -92,19 +93,19 @@
],
cflags: [
- "-fvisibility=hidden",
- "-Werror",
"-Wall",
+ "-Werror",
"-Wthread-safety",
+ "-fvisibility=hidden",
],
export_shared_lib_headers: [
+ "framework-permission-aidl-cpp",
"libactivitymanager_aidl",
"libaudiousecasevalidation",
"libheadtracking",
"libheadtracking-binding",
"libsensorprivacy",
- "framework-permission-aidl-cpp",
],
}
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index 2a4c069..0c68ad1 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -20,6 +20,7 @@
#include "AudioPolicyService.h"
#include "AudioRecordClient.h"
#include "TypeConverter.h"
+#include <android_media_audiopolicy.h>
#include <media/AidlConversion.h>
#include <media/AudioPolicy.h>
#include <media/AudioValidator.h>
@@ -45,6 +46,7 @@
#define MAX_ITEMS_PER_LIST 1024
namespace android {
+namespace audiopolicy_flags = android::media::audiopolicy;
using binder::Status;
using aidl_utils::binderStatusFromStatusT;
using content::AttributionSourceState;
@@ -62,6 +64,8 @@
using media::audio::common::AudioUuid;
using media::audio::common::Int;
+constexpr int kDefaultVirtualDeviceId = 0;
+
const std::vector<audio_usage_t>& SYSTEM_USAGES = {
AUDIO_USAGE_CALL_ASSISTANT,
AUDIO_USAGE_EMERGENCY,
@@ -627,6 +631,8 @@
RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(validateUsage(attr,
attributionSource)));
+ uint32_t virtualDeviceId = kDefaultVirtualDeviceId;
+
// check calling permissions.
// Capturing from the following sources does not require permission RECORD_AUDIO
// as the captured audio does not come from a microphone:
@@ -698,7 +704,8 @@
status = mAudioPolicyManager->getInputForAttr(&attr, &input, riid, session,
attributionSource, &config,
flags, &selectedDeviceId,
- &inputType, &portId);
+ &inputType, &portId,
+ &virtualDeviceId);
}
audioPolicyEffects = mAudioPolicyEffects;
@@ -737,6 +744,14 @@
LOG_ALWAYS_FATAL("%s encountered an invalid input type %d",
__func__, (int)inputType);
}
+
+ if (audiopolicy_flags::record_audio_device_aware_permission()) {
+ // enforce device-aware RECORD_AUDIO permission
+ if (virtualDeviceId != kDefaultVirtualDeviceId &&
+ !recordingAllowed(attributionSource, virtualDeviceId, inputSource)) {
+ status = PERMISSION_DENIED;
+ }
+ }
}
if (status != NO_ERROR) {
@@ -752,6 +767,7 @@
sp<AudioRecordClient> client = new AudioRecordClient(attr, input, session, portId,
selectedDeviceId, attributionSource,
+ virtualDeviceId,
canCaptureOutput, canCaptureHotword,
mOutputCommandThread);
mAudioRecordClients.add(portId, client);
@@ -1561,17 +1577,20 @@
std::unique_ptr<audio_port_v7[]> ports(new audio_port_v7[num_ports]);
unsigned int generation;
- audio_utils::lock_guard _l(mMutex);
- if (mAudioPolicyManager == NULL) {
- return binderStatusFromStatusT(NO_INIT);
- }
-
const AttributionSourceState attributionSource = getCallingAttributionSource();
-
AutoCallerClear acc;
- RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(
- mAudioPolicyManager->listAudioPorts(role, type, &num_ports, ports.get(), &generation)));
- numPortsReq = std::min(numPortsReq, num_ports);
+ {
+ audio_utils::lock_guard _l(mMutex);
+ if (mAudioPolicyManager == NULL) {
+ return binderStatusFromStatusT(NO_INIT);
+ }
+ // AudioPolicyManager->listAudioPorts makes a deep copy of port structs into ports
+ // so it is safe to access after releasing the mutex
+ RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(
+ mAudioPolicyManager->listAudioPorts(
+ role, type, &num_ports, ports.get(), &generation)));
+ numPortsReq = std::min(numPortsReq, num_ports);
+ }
if (mustAnonymizeBluetoothAddress(attributionSource, String16(__func__))) {
for (size_t i = 0; i < numPortsReq; ++i) {
@@ -1601,15 +1620,19 @@
Status AudioPolicyService::getAudioPort(int portId,
media::AudioPortFw* _aidl_return) {
audio_port_v7 port{ .id = portId };
- audio_utils::lock_guard _l(mMutex);
- if (mAudioPolicyManager == NULL) {
- return binderStatusFromStatusT(NO_INIT);
- }
const AttributionSourceState attributionSource = getCallingAttributionSource();
-
AutoCallerClear acc;
- RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(mAudioPolicyManager->getAudioPort(&port)));
+
+ {
+ audio_utils::lock_guard _l(mMutex);
+ if (mAudioPolicyManager == NULL) {
+ return binderStatusFromStatusT(NO_INIT);
+ }
+ // AudioPolicyManager->getAudioPort makes a deep copy of the port struct into port
+ // so it is safe to access after releasing the mutex
+ RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(mAudioPolicyManager->getAudioPort(&port)));
+ }
if (mustAnonymizeBluetoothAddress(attributionSource, String16(__func__))) {
anonymizePortBluetoothAddress(&port);
@@ -1672,17 +1695,20 @@
std::unique_ptr<audio_patch[]> patches(new audio_patch[num_patches]);
unsigned int generation;
- audio_utils::lock_guard _l(mMutex);
- if (mAudioPolicyManager == NULL) {
- return binderStatusFromStatusT(NO_INIT);
- }
-
const AttributionSourceState attributionSource = getCallingAttributionSource();
-
AutoCallerClear acc;
- RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(
- mAudioPolicyManager->listAudioPatches(&num_patches, patches.get(), &generation)));
- numPatchesReq = std::min(numPatchesReq, num_patches);
+
+ {
+ audio_utils::lock_guard _l(mMutex);
+ if (mAudioPolicyManager == NULL) {
+ return binderStatusFromStatusT(NO_INIT);
+ }
+ // AudioPolicyManager->listAudioPatches makes a deep copy of patches structs into patches
+ // so it is safe to access after releasing the mutex
+ RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(
+ mAudioPolicyManager->listAudioPatches(&num_patches, patches.get(), &generation)));
+ numPatchesReq = std::min(numPatchesReq, num_patches);
+ }
if (mustAnonymizeBluetoothAddress(attributionSource, String16(__func__))) {
for (size_t i = 0; i < numPatchesReq; ++i) {
diff --git a/services/audiopolicy/service/AudioPolicyService.cpp b/services/audiopolicy/service/AudioPolicyService.cpp
index e95147e..f6492d4 100644
--- a/services/audiopolicy/service/AudioPolicyService.cpp
+++ b/services/audiopolicy/service/AudioPolicyService.cpp
@@ -18,9 +18,6 @@
//#define LOG_NDEBUG 0
#include "Configuration.h"
-#undef __STRICT_ANSI__
-#define __STDINT_LIMITS
-#define __STDC_LIMIT_MACROS
#include <stdint.h>
#include <sys/time.h>
#include <dlfcn.h>
diff --git a/services/audiopolicy/service/AudioRecordClient.cpp b/services/audiopolicy/service/AudioRecordClient.cpp
index a89a84d..6d8b3cf 100644
--- a/services/audiopolicy/service/AudioRecordClient.cpp
+++ b/services/audiopolicy/service/AudioRecordClient.cpp
@@ -18,9 +18,10 @@
#include "AudioRecordClient.h"
#include "AudioPolicyService.h"
+#include <android_media_audiopolicy.h>
namespace android::media::audiopolicy {
-
+namespace audiopolicy_flags = android::media::audiopolicy;
using android::AudioPolicyService;
namespace {
@@ -59,8 +60,10 @@
// static
sp<OpRecordAudioMonitor>
OpRecordAudioMonitor::createIfNeeded(
- const AttributionSourceState& attributionSource, const audio_attributes_t& attr,
- wp<AudioPolicyService::AudioCommandThread> commandThread)
+ const AttributionSourceState &attributionSource,
+ const uint32_t virtualDeviceId,
+ const audio_attributes_t &attr,
+ wp<AudioPolicyService::AudioCommandThread> commandThread)
{
if (isAudioServerOrRootUid(attributionSource.uid)) {
ALOGV("not silencing record for audio or root source %s",
@@ -78,15 +81,19 @@
|| attributionSource.packageName.value().size() == 0) {
return nullptr;
}
- return new OpRecordAudioMonitor(attributionSource, getOpForSource(attr.source), commandThread);
+
+ return new OpRecordAudioMonitor(attributionSource, virtualDeviceId, attr,
+ getOpForSource(attr.source), commandThread);
}
OpRecordAudioMonitor::OpRecordAudioMonitor(
- const AttributionSourceState& attributionSource, int32_t appOp,
+ const AttributionSourceState &attributionSource,
+ const uint32_t virtualDeviceId, const audio_attributes_t &attr,
+ int32_t appOp,
wp<AudioPolicyService::AudioCommandThread> commandThread) :
- mHasOp(true), mAttributionSource(attributionSource), mAppOp(appOp),
- mCommandThread(commandThread)
-{
+ mHasOp(true), mAttributionSource(attributionSource),
+ mVirtualDeviceId(virtualDeviceId), mAttr(attr), mAppOp(appOp),
+ mCommandThread(commandThread) {
}
OpRecordAudioMonitor::~OpRecordAudioMonitor()
@@ -131,7 +138,12 @@
const int32_t mode = mAppOpsManager.checkOp(mAppOp,
mAttributionSource.uid, VALUE_OR_FATAL(aidl2legacy_string_view_String16(
mAttributionSource.packageName.value_or(""))));
- const bool hasIt = (mode == AppOpsManager::MODE_ALLOWED);
+ bool hasIt = (mode == AppOpsManager::MODE_ALLOWED);
+
+ if (audiopolicy_flags::record_audio_device_aware_permission()) {
+ const bool canRecord = recordingAllowed(mAttributionSource, mVirtualDeviceId, mAttr.source);
+ hasIt = hasIt && canRecord;
+ }
// verbose logging only log when appOp changed
ALOGI_IF(hasIt != mHasOp.load(),
"App op %d missing, %ssilencing record %s",
diff --git a/services/audiopolicy/service/AudioRecordClient.h b/services/audiopolicy/service/AudioRecordClient.h
index d3be316..76aff41 100644
--- a/services/audiopolicy/service/AudioRecordClient.h
+++ b/services/audiopolicy/service/AudioRecordClient.h
@@ -38,12 +38,16 @@
static sp<OpRecordAudioMonitor> createIfNeeded(
const AttributionSourceState& attributionSource,
+ uint32_t virtualDeviceId,
const audio_attributes_t& attr,
wp<AudioPolicyService::AudioCommandThread> commandThread);
private:
- OpRecordAudioMonitor(const AttributionSourceState& attributionSource, int32_t appOp,
- wp<AudioPolicyService::AudioCommandThread> commandThread);
+ OpRecordAudioMonitor(const AttributionSourceState &attributionSource,
+ uint32_t virtualDeviceId,
+ const audio_attributes_t &attr,
+ int32_t appOp,
+ wp<AudioPolicyService::AudioCommandThread> commandThread);
void onFirstRef() override;
@@ -67,6 +71,8 @@
std::atomic_bool mHasOp;
const AttributionSourceState mAttributionSource;
+ const uint32_t mVirtualDeviceId;
+ const audio_attributes_t mAttr;
const int32_t mAppOp;
wp<AudioPolicyService::AudioCommandThread> mCommandThread;
};
@@ -81,15 +87,20 @@
const audio_session_t session, audio_port_handle_t portId,
const audio_port_handle_t deviceId,
const AttributionSourceState& attributionSource,
+ const uint32_t virtualDeviceId,
bool canCaptureOutput, bool canCaptureHotword,
wp<AudioPolicyService::AudioCommandThread> commandThread) :
AudioClient(attributes, io, attributionSource,
session, portId, deviceId), attributionSource(attributionSource),
+ virtualDeviceId(virtualDeviceId),
startTimeNs(0), canCaptureOutput(canCaptureOutput),
canCaptureHotword(canCaptureHotword), silenced(false),
mOpRecordAudioMonitor(
OpRecordAudioMonitor::createIfNeeded(attributionSource,
- attributes, commandThread)) {}
+ virtualDeviceId,
+ attributes, commandThread)) {
+
+ }
~AudioRecordClient() override = default;
bool hasOp() const {
@@ -97,6 +108,7 @@
}
const AttributionSourceState attributionSource; // attribution source of client
+ const uint32_t virtualDeviceId; // id of the virtual device associated with the audio device
nsecs_t startTimeNs;
const bool canCaptureOutput;
const bool canCaptureHotword;
diff --git a/services/audiopolicy/tests/Android.bp b/services/audiopolicy/tests/Android.bp
index 21ded60..fc349ee 100644
--- a/services/audiopolicy/tests/Android.bp
+++ b/services/audiopolicy/tests/Android.bp
@@ -28,11 +28,11 @@
"libbase",
"libbinder",
"libcutils",
+ "libcutils",
"libhidlbase",
"liblog",
"libmedia_helper",
"libutils",
- "libcutils",
"libxml2",
"server_configurable_flags",
],
@@ -56,13 +56,13 @@
data: [":audiopolicytest_configuration_files"],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
test_suites: [
- "device-tests",
"automotive-tests",
+ "device-tests",
],
}
@@ -101,8 +101,8 @@
srcs: ["audio_health_tests.cpp"],
cflags: [
- "-Werror",
"-Wall",
+ "-Werror",
],
test_suites: ["device-tests"],
@@ -131,9 +131,9 @@
],
header_libs: [
- "libaudiohal_headers",
- "libaudiopolicyservice_headers",
- "libmediametrics_headers",
+ "libaudiohal_headers",
+ "libaudiopolicyservice_headers",
+ "libmediametrics_headers",
],
srcs: ["spatializer_tests.cpp"],
diff --git a/services/audiopolicy/tests/audiopolicymanager_tests.cpp b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
index afd8765..f9d5946 100644
--- a/services/audiopolicy/tests/audiopolicymanager_tests.cpp
+++ b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
@@ -204,7 +204,8 @@
audio_channel_mask_t channelMask,
int sampleRate,
audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
- audio_port_handle_t *portId = nullptr);
+ audio_port_handle_t *portId = nullptr,
+ uint32_t *virtualDeviceId = nullptr);
PatchCountCheck snapshotPatchCount() { return PatchCountCheck(mClient.get()); }
void getAudioPorts(audio_port_type_t type, audio_port_role_t role,
@@ -316,7 +317,8 @@
audio_channel_mask_t channelMask,
int sampleRate,
audio_input_flags_t flags,
- audio_port_handle_t *portId) {
+ audio_port_handle_t *portId,
+ uint32_t *virtualDeviceId) {
audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER;
config.sample_rate = sampleRate;
config.channel_mask = channelMask;
@@ -324,11 +326,12 @@
audio_port_handle_t localPortId;
if (!portId) portId = &localPortId;
*portId = AUDIO_PORT_HANDLE_NONE;
+ if (!virtualDeviceId) virtualDeviceId = 0;
AudioPolicyInterface::input_type_t inputType;
AttributionSourceState attributionSource = createAttributionSourceState(/*uid=*/ 0);
ASSERT_EQ(OK, mManager->getInputForAttr(
&attr, input, riid, session, attributionSource, &config, flags,
- selectedDeviceId, &inputType, portId));
+ selectedDeviceId, &inputType, portId, virtualDeviceId));
ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId);
}
@@ -1296,10 +1299,11 @@
};
audio_config_base_t config = requestedConfig;
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE;
+ uint32_t *virtualDeviceId = 0;
ASSERT_EQ(OK, mManager->getInputForAttr(
&attr, &input, 1 /*riid*/, AUDIO_SESSION_NONE, attributionSource, &config,
AUDIO_INPUT_FLAG_NONE,
- &selectedDeviceId, &inputType, &portId));
+ &selectedDeviceId, &inputType, &portId, virtualDeviceId));
ASSERT_NE(AUDIO_PORT_HANDLE_NONE, portId);
ASSERT_TRUE(equals(requestedConfig, config));
@@ -1313,7 +1317,7 @@
ASSERT_EQ(OK, mManager->getInputForAttr(
&attr, &input, 1 /*riid*/, AUDIO_SESSION_NONE, attributionSource, &config,
AUDIO_INPUT_FLAG_NONE,
- &selectedDeviceId, &inputType, &portId));
+ &selectedDeviceId, &inputType, &portId, virtualDeviceId));
ASSERT_NE(AUDIO_PORT_HANDLE_NONE, portId);
ASSERT_TRUE(equals(requestedConfig, config));
diff --git a/services/audiopolicy/tests/resources/Android.bp b/services/audiopolicy/tests/resources/Android.bp
index 43e2e39..abf72e0 100644
--- a/services/audiopolicy/tests/resources/Android.bp
+++ b/services/audiopolicy/tests/resources/Android.bp
@@ -15,7 +15,7 @@
"test_audio_policy_primary_only_configuration.xml",
"test_car_ap_atmos_offload_configuration.xml",
"test_invalid_audio_policy_configuration.xml",
- "test_tv_apm_configuration.xml",
"test_settop_box_surround_configuration.xml",
+ "test_tv_apm_configuration.xml",
],
}
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 78c14b2..26208c5 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -2309,16 +2309,31 @@
std::string CameraService::getPackageNameFromUid(int clientUid) {
std::string packageName("");
- sp<IServiceManager> sm = defaultServiceManager();
- sp<IBinder> binder = sm->getService(toString16(kPermissionServiceName));
- if (binder == 0) {
- ALOGE("Cannot get permission service");
+ sp<IPermissionController> permCtrl;
+ if (flags::cache_permission_services()) {
+ permCtrl = getPermissionController();
+ } else {
+ sp<IServiceManager> sm = defaultServiceManager();
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ // Using deprecated function to preserve functionality until the
+ // cache_permission_services flag is removed.
+ sp<IBinder> binder = sm->getService(toString16(kPermissionServiceName));
+#pragma clang diagnostic pop
+ if (binder == 0) {
+ ALOGE("Cannot get permission service");
+ permCtrl = nullptr;
+ } else {
+ permCtrl = interface_cast<IPermissionController>(binder);
+ }
+ }
+
+ if (permCtrl == nullptr) {
// Return empty package name and the further interaction
// with camera will likely fail
return packageName;
}
- sp<IPermissionController> permCtrl = interface_cast<IPermissionController>(binder);
Vector<String16> packages;
permCtrl->getPackagesForUid(clientUid, packages);
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 1a887a1..f25cf7d 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -34,6 +34,7 @@
#include <binder/IServiceManager.h>
#include <binder/IActivityManager.h>
#include <binder/IAppOpsCallback.h>
+#include <binder/IPermissionController.h>
#include <binder/IUidObserver.h>
#include <hardware/camera.h>
#include <sensorprivacy/SensorPrivacyManager.h>
@@ -675,7 +676,26 @@
return activityManager;
}
- /**
+ static const sp<IPermissionController>& getPermissionController() {
+ static const char* kPermissionControllerService = "permission";
+ static thread_local sp<IPermissionController> sPermissionController = nullptr;
+
+ if (sPermissionController == nullptr ||
+ !IInterface::asBinder(sPermissionController)->isBinderAlive()) {
+ sp<IServiceManager> sm = defaultServiceManager();
+ sp<IBinder> binder = sm->checkService(toString16(kPermissionControllerService));
+ if (binder == nullptr) {
+ ALOGE("%s: Could not get permission service", __FUNCTION__);
+ sPermissionController = nullptr;
+ } else {
+ sPermissionController = interface_cast<IPermissionController>(binder);
+ }
+ }
+
+ return sPermissionController;
+ }
+
+ /**
* Typesafe version of device status, containing both the HAL-layer and the service interface-
* layer values.
*/
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
index 7c2f71c..59828fb 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
@@ -892,6 +892,11 @@
Mutex::Autolock icl(mBinderSerializationLock);
+ if (!outputConfiguration.isComplete()) {
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "OutputConfiguration isn't valid!");
+ }
+
const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
outputConfiguration.getGraphicBufferProducers();
size_t numBufferProducers = bufferProducers.size();
@@ -908,7 +913,7 @@
bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
- outputConfiguration.getSurfaceType());
+ outputConfiguration.getSurfaceType(), /*isConfigurationComplete*/true);
if (!res.isOk()) {
return res;
}
@@ -951,7 +956,7 @@
res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
- streamUseCase, timestampBase, mirrorMode, colorSpace);
+ streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
if (!res.isOk())
return res;
@@ -1064,6 +1069,10 @@
if (!mDevice.get()) {
return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
}
+ if (!outputConfiguration.isComplete()) {
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "OutputConfiguration isn't valid!");
+ }
// Infer the surface info for deferred surface stream creation.
width = outputConfiguration.getWidth();
@@ -1256,6 +1265,10 @@
if (!mDevice.get()) {
return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
}
+ if (!outputConfiguration.isComplete()) {
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "OutputConfiguration isn't valid!");
+ }
const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
outputConfiguration.getGraphicBufferProducers();
@@ -1323,7 +1336,7 @@
res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
/*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
- streamUseCase, timestampBase, mirrorMode, colorSpace);
+ streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
if (!res.isOk())
return res;
@@ -1636,6 +1649,11 @@
Mutex::Autolock icl(mBinderSerializationLock);
+ if (!outputConfiguration.isComplete()) {
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "OutputConfiguration isn't valid!");
+ }
+
const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
outputConfiguration.getGraphicBufferProducers();
const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
@@ -1701,7 +1719,7 @@
res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
- streamUseCase, timestampBase, mirrorMode, colorSpace);
+ streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
if (!res.isOk())
return res;
diff --git a/services/camera/libcameraservice/utils/AttributionAndPermissionUtils.cpp b/services/camera/libcameraservice/utils/AttributionAndPermissionUtils.cpp
index e63b30b..e8301c1 100644
--- a/services/camera/libcameraservice/utils/AttributionAndPermissionUtils.cpp
+++ b/services/camera/libcameraservice/utils/AttributionAndPermissionUtils.cpp
@@ -18,6 +18,7 @@
#include <binder/AppOpsManager.h>
#include <binder/PermissionController.h>
+#include <com_android_internal_camera_flags.h>
#include <cutils/properties.h>
#include <private/android_filesystem_config.h>
@@ -26,6 +27,8 @@
namespace android {
+namespace flags = com::android::internal::camera::flags;
+
const std::string AttributionAndPermissionUtils::sDumpPermission("android.permission.DUMP");
const std::string AttributionAndPermissionUtils::sManageCameraPermission(
"android.permission.MANAGE_CAMERA");
@@ -75,9 +78,16 @@
return true;
}
- PermissionChecker permissionChecker;
- return permissionChecker.checkPermissionForPreflight(toString16(permission), attributionSource,
- toString16(message), attributedOpCode) != PermissionChecker::PERMISSION_HARD_DENIED;
+ if (!flags::cache_permission_services()) {
+ PermissionChecker permissionChecker;
+ return permissionChecker.checkPermissionForPreflight(
+ toString16(permission), attributionSource, toString16(message),
+ attributedOpCode) != PermissionChecker::PERMISSION_HARD_DENIED;
+ } else {
+ return mPermissionChecker->checkPermissionForPreflight(
+ toString16(permission), attributionSource, toString16(message),
+ attributedOpCode) != PermissionChecker::PERMISSION_HARD_DENIED;
+ }
}
// Can camera service trust the caller based on the calling UID?
diff --git a/services/camera/libcameraservice/utils/AttributionAndPermissionUtils.h b/services/camera/libcameraservice/utils/AttributionAndPermissionUtils.h
index 7f4a1bd..830a8e8 100644
--- a/services/camera/libcameraservice/utils/AttributionAndPermissionUtils.h
+++ b/services/camera/libcameraservice/utils/AttributionAndPermissionUtils.h
@@ -32,7 +32,7 @@
* caller.
*/
class AttributionAndPermissionUtils {
-public:
+ public:
AttributionAndPermissionUtils() { }
virtual ~AttributionAndPermissionUtils() {}
@@ -90,11 +90,15 @@
static const std::string sCameraOpenCloseListenerPermission;
static const std::string sCameraInjectExternalCameraPermission;
-protected:
+ protected:
wp<CameraService> mCameraService;
bool checkAutomotivePrivilegedClient(const std::string &cameraId,
const AttributionSourceState &attributionSource);
+
+ private:
+ std::unique_ptr<permission::PermissionChecker> mPermissionChecker =
+ std::make_unique<permission::PermissionChecker>();
};
/**
diff --git a/services/camera/libcameraservice/utils/SessionConfigurationUtils.cpp b/services/camera/libcameraservice/utils/SessionConfigurationUtils.cpp
index 11ef9b7..23aed6e 100644
--- a/services/camera/libcameraservice/utils/SessionConfigurationUtils.cpp
+++ b/services/camera/libcameraservice/utils/SessionConfigurationUtils.cpp
@@ -432,7 +432,7 @@
const std::string &logicalCameraId, const CameraMetadata &physicalCameraMetadata,
const std::vector<int32_t> &sensorPixelModesUsed, int64_t dynamicRangeProfile,
int64_t streamUseCase, int timestampBase, int mirrorMode,
- int32_t colorSpace) {
+ int32_t colorSpace, bool respectSurfaceSize) {
// bufferProducer must be non-null
if (gbp == nullptr) {
std::string msg = fmt::sprintf("Camera %s: Surface is NULL", logicalCameraId.c_str());
@@ -529,8 +529,10 @@
// we can use the default stream configuration map
foundInMaxRes = true;
}
- // Round dimensions to the nearest dimensions available for this format
- if (flexibleConsumer && isPublicFormat(format) &&
+ // Round dimensions to the nearest dimensions available for this format.
+ // Only do the rounding if the client doesn't ask to respect the surface
+ // size.
+ if (flexibleConsumer && isPublicFormat(format) && !respectSurfaceSize &&
!SessionConfigurationUtils::roundBufferDimensionNearest(width, height,
format, dataSpace, physicalCameraMetadata, foundInMaxRes, /*out*/&width,
/*out*/&height)) {
@@ -753,6 +755,7 @@
const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
it.getGraphicBufferProducers();
bool deferredConsumer = it.isDeferred();
+ bool isConfigurationComplete = it.isComplete();
const std::string &physicalCameraId = it.getPhysicalCameraId();
int64_t dynamicRangeProfile = it.getDynamicRangeProfile();
@@ -768,7 +771,8 @@
int32_t groupId = it.isMultiResolution() ? it.getSurfaceSetID() : -1;
OutputStreamInfo streamInfo;
- res = checkSurfaceType(numBufferProducers, deferredConsumer, it.getSurfaceType());
+ res = checkSurfaceType(numBufferProducers, deferredConsumer, it.getSurfaceType(),
+ isConfigurationComplete);
if (!res.isOk()) {
return res;
}
@@ -781,15 +785,38 @@
int64_t streamUseCase = it.getStreamUseCase();
int timestampBase = it.getTimestampBase();
int mirrorMode = it.getMirrorMode();
- if (deferredConsumer) {
+ // If the configuration is a deferred consumer, or a not yet completed
+ // configuration with no buffer producers attached.
+ if (deferredConsumer || (!isConfigurationComplete && numBufferProducers == 0)) {
streamInfo.width = it.getWidth();
streamInfo.height = it.getHeight();
- streamInfo.format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
- streamInfo.dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
auto surfaceType = it.getSurfaceType();
- streamInfo.consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
- if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
- streamInfo.consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
+ switch (surfaceType) {
+ case OutputConfiguration::SURFACE_TYPE_SURFACE_TEXTURE:
+ streamInfo.consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
+ streamInfo.format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
+ streamInfo.dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
+ break;
+ case OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW:
+ streamInfo.consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE
+ | GraphicBuffer::USAGE_HW_COMPOSER;
+ streamInfo.format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
+ streamInfo.dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
+ break;
+ case OutputConfiguration::SURFACE_TYPE_MEDIA_RECORDER:
+ case OutputConfiguration::SURFACE_TYPE_MEDIA_CODEC:
+ streamInfo.consumerUsage = GraphicBuffer::USAGE_HW_VIDEO_ENCODER;
+ streamInfo.format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
+ streamInfo.dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
+ break;
+ case OutputConfiguration::SURFACE_TYPE_IMAGE_READER:
+ streamInfo.consumerUsage = it.getUsage();
+ streamInfo.format = it.getFormat();
+ streamInfo.dataSpace = (android_dataspace)it.getDataspace();
+ break;
+ default:
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "Invalid surface type.");
}
streamInfo.dynamicRangeProfile = it.getDynamicRangeProfile();
if (checkAndOverrideSensorPixelModesUsed(sensorPixelModesUsed,
@@ -815,7 +842,8 @@
sp<Surface> surface;
res = createSurfaceFromGbp(streamInfo, isStreamInfoValid, surface, bufferProducer,
logicalCameraId, metadataChosen, sensorPixelModesUsed, dynamicRangeProfile,
- streamUseCase, timestampBase, mirrorMode, colorSpace);
+ streamUseCase, timestampBase, mirrorMode, colorSpace,
+ /*respectSurfaceSize*/true);
if (!res.isOk())
return res;
@@ -912,22 +940,37 @@
}
binder::Status checkSurfaceType(size_t numBufferProducers,
- bool deferredConsumer, int surfaceType) {
+ bool deferredConsumer, int surfaceType, bool isConfigurationComplete) {
if (numBufferProducers > MAX_SURFACES_PER_STREAM) {
ALOGE("%s: GraphicBufferProducer count %zu for stream exceeds limit of %d",
__FUNCTION__, numBufferProducers, MAX_SURFACES_PER_STREAM);
return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Surface count is too high");
- } else if ((numBufferProducers == 0) && (!deferredConsumer)) {
+ } else if ((numBufferProducers == 0) && (!deferredConsumer) && isConfigurationComplete) {
ALOGE("%s: Number of consumers cannot be smaller than 1", __FUNCTION__);
return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "No valid consumers.");
}
- bool validSurfaceType = ((surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) ||
- (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_TEXTURE));
-
- if (deferredConsumer && !validSurfaceType) {
- ALOGE("%s: Target surface has invalid surfaceType = %d.", __FUNCTION__, surfaceType);
- return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
+ if (deferredConsumer) {
+ bool validSurfaceType = (
+ (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) ||
+ (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_TEXTURE));
+ if (!validSurfaceType) {
+ std::string msg = fmt::sprintf("Deferred target surface has invalid "
+ "surfaceType = %d.", surfaceType);
+ ALOGE("%s: %s", __FUNCTION__, msg.c_str());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
+ }
+ } else if (!isConfigurationComplete && numBufferProducers == 0) {
+ bool validSurfaceType = (
+ (surfaceType == OutputConfiguration::SURFACE_TYPE_MEDIA_RECORDER) ||
+ (surfaceType == OutputConfiguration::SURFACE_TYPE_MEDIA_CODEC) ||
+ (surfaceType == OutputConfiguration::SURFACE_TYPE_IMAGE_READER));
+ if (!validSurfaceType) {
+ std::string msg = fmt::sprintf("OutputConfiguration target surface has invalid "
+ "surfaceType = %d.", surfaceType);
+ ALOGE("%s: %s", __FUNCTION__, msg.c_str());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
+ }
}
return binder::Status::ok();
diff --git a/services/camera/libcameraservice/utils/SessionConfigurationUtils.h b/services/camera/libcameraservice/utils/SessionConfigurationUtils.h
index 0545cea..a226829 100644
--- a/services/camera/libcameraservice/utils/SessionConfigurationUtils.h
+++ b/services/camera/libcameraservice/utils/SessionConfigurationUtils.h
@@ -112,7 +112,7 @@
const std::string &logicalCameraId, const CameraMetadata &physicalCameraMetadata,
const std::vector<int32_t> &sensorPixelModesUsed, int64_t dynamicRangeProfile,
int64_t streamUseCase, int timestampBase, int mirrorMode,
- int32_t colorSpace);
+ int32_t colorSpace, bool respectSurfaceSize);
//check if format is 10-bit output compatible
bool is10bitCompatibleFormat(int32_t format, android_dataspace_t dataSpace);
@@ -143,10 +143,10 @@
const std::string &logicalCameraId);
binder::Status checkSurfaceType(size_t numBufferProducers,
-bool deferredConsumer, int surfaceType);
+ bool deferredConsumer, int surfaceType, bool isConfigurationComplete);
binder::Status checkOperatingMode(int operatingMode,
-const CameraMetadata &staticInfo, const std::string &cameraId);
+ const CameraMetadata &staticInfo, const std::string &cameraId);
binder::Status
convertToHALStreamCombination(
diff --git a/services/camera/virtualcamera/VirtualCameraDevice.cc b/services/camera/virtualcamera/VirtualCameraDevice.cc
index ddb245a..a5301e5 100644
--- a/services/camera/virtualcamera/VirtualCameraDevice.cc
+++ b/services/camera/virtualcamera/VirtualCameraDevice.cc
@@ -296,8 +296,10 @@
ANDROID_CONTROL_ZOOM_RATIO,
ANDROID_FLASH_MODE,
ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES,
+ ANDROID_JPEG_ORIENTATION,
ANDROID_JPEG_QUALITY,
ANDROID_JPEG_THUMBNAIL_QUALITY,
+ ANDROID_JPEG_THUMBNAIL_SIZE,
ANDROID_NOISE_REDUCTION_MODE,
ANDROID_STATISTICS_FACE_DETECT_MODE})
.setAvailableResultKeys({
diff --git a/services/camera/virtualcamera/VirtualCameraDevice.h b/services/camera/virtualcamera/VirtualCameraDevice.h
index 4c50041..0aebf6e 100644
--- a/services/camera/virtualcamera/VirtualCameraDevice.h
+++ b/services/camera/virtualcamera/VirtualCameraDevice.h
@@ -122,6 +122,12 @@
// Default JPEG compression quality.
static constexpr uint8_t kDefaultJpegQuality = 80;
+ // Default JPEG orientation.
+ static constexpr uint8_t kDefaultJpegOrientation = 0;
+
+ // Default Make and Model for Exif
+ static constexpr char kDefaultMakeAndModel[] = "Android Virtual Camera";
+
static constexpr camera_metadata_enum_android_control_capture_intent_t
kDefaultCaptureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
diff --git a/services/camera/virtualcamera/VirtualCameraProvider.cc b/services/camera/virtualcamera/VirtualCameraProvider.cc
index e4a68f5..eed3e85 100644
--- a/services/camera/virtualcamera/VirtualCameraProvider.cc
+++ b/services/camera/virtualcamera/VirtualCameraProvider.cc
@@ -42,10 +42,6 @@
using ::aidl::android::hardware::camera::provider::ConcurrentCameraIdCombination;
using ::aidl::android::hardware::camera::provider::ICameraProviderCallback;
-// TODO(b/301023410) Make camera id range configurable / dynamic
-// based on already registered devices.
-std::atomic_int VirtualCameraProvider::sNextId{42};
-
ndk::ScopedAStatus VirtualCameraProvider::setCallback(
const std::shared_ptr<ICameraProviderCallback>& in_callback) {
ALOGV("%s", __func__);
@@ -154,9 +150,15 @@
}
std::shared_ptr<VirtualCameraDevice> VirtualCameraProvider::createCamera(
- const VirtualCameraConfiguration& configuration) {
+ const VirtualCameraConfiguration& configuration, const int cameraId) {
+ if (cameraId < 0) {
+ ALOGE("%s: Cannot create camera with negative id. cameraId: %d", __func__,
+ cameraId);
+ return nullptr;
+ }
+
auto camera =
- ndk::SharedRefBase::make<VirtualCameraDevice>(sNextId++, configuration);
+ ndk::SharedRefBase::make<VirtualCameraDevice>(cameraId, configuration);
std::shared_ptr<ICameraProviderCallback> callback;
{
const std::lock_guard<std::mutex> lock(mLock);
diff --git a/services/camera/virtualcamera/VirtualCameraProvider.h b/services/camera/virtualcamera/VirtualCameraProvider.h
index 11d3123..c1283a0 100644
--- a/services/camera/virtualcamera/VirtualCameraProvider.h
+++ b/services/camera/virtualcamera/VirtualCameraProvider.h
@@ -76,7 +76,8 @@
// Returns nullptr if creation was not successful.
std::shared_ptr<VirtualCameraDevice> createCamera(
const aidl::android::companion::virtualcamera::VirtualCameraConfiguration&
- configuration);
+ configuration,
+ int cameraId);
std::shared_ptr<VirtualCameraDevice> getCamera(const std::string& name);
@@ -91,9 +92,6 @@
std::map<std::string, std::shared_ptr<VirtualCameraDevice>> mCameras
GUARDED_BY(mLock);
-
- // Numerical id to assign to next created camera.
- static std::atomic_int sNextId;
};
} // namespace virtualcamera
diff --git a/services/camera/virtualcamera/VirtualCameraRenderThread.cc b/services/camera/virtualcamera/VirtualCameraRenderThread.cc
index 6e89b5f..f68efe2 100644
--- a/services/camera/virtualcamera/VirtualCameraRenderThread.cc
+++ b/services/camera/virtualcamera/VirtualCameraRenderThread.cc
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include "system/camera_metadata.h"
#define LOG_TAG "VirtualCameraRenderThread"
#include "VirtualCameraRenderThread.h"
@@ -45,7 +44,9 @@
#include "android-base/thread_annotations.h"
#include "android/binder_auto_utils.h"
#include "android/hardware_buffer.h"
+#include "system/camera_metadata.h"
#include "ui/GraphicBuffer.h"
+#include "ui/Rect.h"
#include "util/EglFramebuffer.h"
#include "util/JpegUtil.h"
#include "util/MetadataUtil.h"
@@ -128,6 +129,7 @@
.setFlashMode(ANDROID_FLASH_MODE_OFF)
.setFocalLength(VirtualCameraDevice::kFocalLength)
.setJpegQuality(requestSettings.jpegQuality)
+ .setJpegOrientation(requestSettings.jpegOrientation)
.setJpegThumbnailSize(requestSettings.thumbnailResolution.width,
requestSettings.thumbnailResolution.height)
.setJpegThumbnailQuality(requestSettings.thumbnailJpegQuality)
@@ -146,6 +148,11 @@
builder.setControlAeTargetFpsRange(requestSettings.fpsRange.value());
}
+ if (requestSettings.gpsCoordinates.has_value()) {
+ const GpsCoordinates& coordinates = requestSettings.gpsCoordinates.value();
+ builder.setJpegGpsCoordinates(coordinates);
+ }
+
std::unique_ptr<CameraMetadata> metadata = builder.build();
if (metadata == nullptr) {
@@ -224,12 +231,24 @@
}
std::vector<uint8_t> createExif(
- Resolution imageSize, const std::vector<uint8_t>& compressedThumbnail = {}) {
+ Resolution imageSize, const CameraMetadata resultMetadata,
+ const std::vector<uint8_t>& compressedThumbnail = {}) {
std::unique_ptr<ExifUtils> exifUtils(ExifUtils::create());
exifUtils->initialize();
- exifUtils->setImageWidth(imageSize.width);
- exifUtils->setImageHeight(imageSize.height);
- // TODO(b/324383963) Set Make/Model and orientation.
+
+ // Make a copy of the metadata in order to converting it the HAL metadata
+ // format (as opposed to the AIDL class) and use the setFromMetadata method
+ // from ExifUtil
+ camera_metadata_t* rawSettings =
+ clone_camera_metadata((camera_metadata_t*)resultMetadata.metadata.data());
+ if (rawSettings != nullptr) {
+ android::hardware::camera::common::helper::CameraMetadata halMetadata(
+ rawSettings);
+ exifUtils->setFromMetadata(halMetadata, imageSize.width, imageSize.height);
+ }
+ exifUtils->setMake(VirtualCameraDevice::kDefaultMakeAndModel);
+ exifUtils->setModel(VirtualCameraDevice::kDefaultMakeAndModel);
+ exifUtils->setFlash(0);
std::vector<uint8_t> app1Data;
@@ -379,6 +398,12 @@
processCaptureRequest(*task);
}
+ // Destroy EGL utilities still on the render thread.
+ mEglSurfaceTexture.reset();
+ mEglTextureRgbProgram.reset();
+ mEglTextureYuvProgram.reset();
+ mEglDisplayContext.reset();
+
ALOGV("Render thread exiting");
}
@@ -427,7 +452,8 @@
auto status = streamConfig->format == PixelFormat::BLOB
? renderIntoBlobStreamBuffer(
reqBuffer.getStreamId(), reqBuffer.getBufferId(),
- request.getRequestSettings(), reqBuffer.getFence())
+ captureResult.result, request.getRequestSettings(),
+ reqBuffer.getFence())
: renderIntoImageStreamBuffer(reqBuffer.getStreamId(),
reqBuffer.getBufferId(),
reqBuffer.getFence());
@@ -516,8 +542,9 @@
ALOGV("%s: Creating thumbnail with size %d x %d, quality %d", __func__,
resolution.width, resolution.height, quality);
+ Resolution bufferSize = roundTo2DctSize(resolution);
std::shared_ptr<EglFrameBuffer> framebuffer = allocateTemporaryFramebuffer(
- mEglDisplayContext->getEglDisplay(), resolution.width, resolution.height);
+ mEglDisplayContext->getEglDisplay(), bufferSize.width, bufferSize.height);
if (framebuffer == nullptr) {
ALOGE(
"Failed to allocate temporary framebuffer for JPEG thumbnail "
@@ -528,38 +555,23 @@
// TODO(b/324383963) Add support for letterboxing if the thumbnail size
// doesn't correspond
// to input texture aspect ratio.
- if (!renderIntoEglFramebuffer(*framebuffer).isOk()) {
+ if (!renderIntoEglFramebuffer(*framebuffer, /*fence=*/nullptr,
+ Rect(resolution.width, resolution.height))
+ .isOk()) {
ALOGE(
"Failed to render input texture into temporary framebuffer for JPEG "
"thumbnail");
return {};
}
- std::shared_ptr<AHardwareBuffer> inHwBuffer = framebuffer->getHardwareBuffer();
- GraphicBuffer* gBuffer = GraphicBuffer::fromAHardwareBuffer(inHwBuffer.get());
-
- if (gBuffer->getPixelFormat() != HAL_PIXEL_FORMAT_YCbCr_420_888) {
- // This should never happen since we're allocating the temporary buffer
- // with YUV420 layout above.
- ALOGE("%s: Cannot compress non-YUV buffer (pixelFormat %d)", __func__,
- gBuffer->getPixelFormat());
- return {};
- }
-
- YCbCrLockGuard yCbCrLock(inHwBuffer, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
- if (yCbCrLock.getStatus() != NO_ERROR) {
- ALOGE("%s: Failed to lock graphic buffer while generating thumbnail: %d",
- __func__, yCbCrLock.getStatus());
- return {};
- }
-
std::vector<uint8_t> compressedThumbnail;
compressedThumbnail.resize(kJpegThumbnailBufferSize);
- ALOGE("%s: Compressing thumbnail %d x %d", __func__, gBuffer->getWidth(),
- gBuffer->getHeight());
- std::optional<size_t> compressedSize = compressJpeg(
- gBuffer->getWidth(), gBuffer->getHeight(), quality, *yCbCrLock, {},
- compressedThumbnail.size(), compressedThumbnail.data());
+ ALOGE("%s: Compressing thumbnail %d x %d", __func__, resolution.width,
+ resolution.height);
+ std::optional<size_t> compressedSize =
+ compressJpeg(resolution.width, resolution.height, quality,
+ framebuffer->getHardwareBuffer(), {},
+ compressedThumbnail.size(), compressedThumbnail.data());
if (!compressedSize.has_value()) {
ALOGE("%s: Failed to compress jpeg thumbnail", __func__);
return {};
@@ -569,7 +581,7 @@
}
ndk::ScopedAStatus VirtualCameraRenderThread::renderIntoBlobStreamBuffer(
- const int streamId, const int bufferId,
+ const int streamId, const int bufferId, const CameraMetadata& resultMetadata,
const RequestSettings& requestSettings, sp<Fence> fence) {
std::shared_ptr<AHardwareBuffer> hwBuffer =
mSessionContext.fetchHardwareBuffer(streamId, bufferId);
@@ -590,15 +602,22 @@
// Let's create YUV framebuffer and render the surface into this.
// This will take care about rescaling as well as potential format conversion.
+ // The buffer dimensions need to be rounded to nearest multiple of JPEG DCT
+ // size, however we pass the viewport corresponding to size of the stream so
+ // the image will be only rendered to the area corresponding to the stream
+ // size.
+ Resolution bufferSize =
+ roundTo2DctSize(Resolution(stream->width, stream->height));
std::shared_ptr<EglFrameBuffer> framebuffer = allocateTemporaryFramebuffer(
- mEglDisplayContext->getEglDisplay(), stream->width, stream->height);
+ mEglDisplayContext->getEglDisplay(), bufferSize.width, bufferSize.height);
if (framebuffer == nullptr) {
ALOGE("Failed to allocate temporary framebuffer for JPEG compression");
return cameraStatus(Status::INTERNAL_ERROR);
}
// Render into temporary framebuffer.
- ndk::ScopedAStatus status = renderIntoEglFramebuffer(*framebuffer);
+ ndk::ScopedAStatus status = renderIntoEglFramebuffer(
+ *framebuffer, /*fence=*/nullptr, Rect(stream->width, stream->height));
if (!status.isOk()) {
ALOGE("Failed to render input texture into temporary framebuffer");
return status;
@@ -610,38 +629,14 @@
return cameraStatus(Status::INTERNAL_ERROR);
}
- std::shared_ptr<AHardwareBuffer> inHwBuffer = framebuffer->getHardwareBuffer();
- GraphicBuffer* gBuffer = GraphicBuffer::fromAHardwareBuffer(inHwBuffer.get());
-
- if (gBuffer == nullptr) {
- ALOGE(
- "%s: Encountered invalid temporary buffer while rendering JPEG "
- "into BLOB stream",
- __func__);
- return cameraStatus(Status::INTERNAL_ERROR);
- }
-
- if (gBuffer->getPixelFormat() != HAL_PIXEL_FORMAT_YCbCr_420_888) {
- // This should never happen since we're allocating the temporary buffer
- // with YUV420 layout above.
- ALOGE("%s: Cannot compress non-YUV buffer (pixelFormat %d)", __func__,
- gBuffer->getPixelFormat());
- return cameraStatus(Status::INTERNAL_ERROR);
- }
-
- YCbCrLockGuard yCbCrLock(inHwBuffer, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
- if (yCbCrLock.getStatus() != OK) {
- return cameraStatus(Status::INTERNAL_ERROR);
- }
-
std::vector<uint8_t> app1ExifData =
- createExif(Resolution(stream->width, stream->height),
+ createExif(Resolution(stream->width, stream->height), resultMetadata,
createThumbnail(requestSettings.thumbnailResolution,
requestSettings.thumbnailJpegQuality));
std::optional<size_t> compressedSize = compressJpeg(
- gBuffer->getWidth(), gBuffer->getHeight(), requestSettings.jpegQuality,
- *yCbCrLock, app1ExifData, stream->bufferSize - sizeof(CameraBlob),
- (*planesLock).planes[0].data);
+ stream->width, stream->height, requestSettings.jpegQuality,
+ framebuffer->getHardwareBuffer(), app1ExifData,
+ stream->bufferSize - sizeof(CameraBlob), (*planesLock).planes[0].data);
if (!compressedSize.has_value()) {
ALOGE("%s: Failed to compress JPEG image", __func__);
@@ -695,7 +690,7 @@
}
ndk::ScopedAStatus VirtualCameraRenderThread::renderIntoEglFramebuffer(
- EglFrameBuffer& framebuffer, sp<Fence> fence) {
+ EglFrameBuffer& framebuffer, sp<Fence> fence, std::optional<Rect> viewport) {
ALOGV("%s", __func__);
// Wait for fence to clear.
if (fence != nullptr && fence->isValid()) {
@@ -709,6 +704,11 @@
mEglDisplayContext->makeCurrent();
framebuffer.beforeDraw();
+ Rect viewportRect =
+ viewport.value_or(Rect(framebuffer.getWidth(), framebuffer.getHeight()));
+ glViewport(viewportRect.leftTop().x, viewportRect.leftTop().y,
+ viewportRect.getWidth(), viewportRect.getHeight());
+
sp<GraphicBuffer> textureBuffer = mEglSurfaceTexture->getCurrentBuffer();
if (textureBuffer == nullptr) {
// If there's no current buffer, nothing was written to the surface and
diff --git a/services/camera/virtualcamera/VirtualCameraRenderThread.h b/services/camera/virtualcamera/VirtualCameraRenderThread.h
index e8e0bd4..90757a0 100644
--- a/services/camera/virtualcamera/VirtualCameraRenderThread.h
+++ b/services/camera/virtualcamera/VirtualCameraRenderThread.h
@@ -57,11 +57,13 @@
struct RequestSettings {
int jpegQuality = VirtualCameraDevice::kDefaultJpegQuality;
+ int jpegOrientation = VirtualCameraDevice::kDefaultJpegOrientation;
Resolution thumbnailResolution = Resolution(0, 0);
int thumbnailJpegQuality = VirtualCameraDevice::kDefaultJpegQuality;
- std::optional<FpsRange> fpsRange = {};
+ std::optional<FpsRange> fpsRange;
camera_metadata_enum_android_control_capture_intent_t captureIntent =
VirtualCameraDevice::kDefaultCaptureIntent;
+ std::optional<GpsCoordinates> gpsCoordinates;
};
// Represents single capture request to fill set of buffers.
@@ -153,6 +155,8 @@
// Always called on render thread.
ndk::ScopedAStatus renderIntoBlobStreamBuffer(
const int streamId, const int bufferId,
+ const ::aidl::android::hardware::camera::device::CameraMetadata&
+ resultMetadata,
const RequestSettings& requestSettings, sp<Fence> fence = nullptr);
// Render current image to the YCbCr buffer.
@@ -166,8 +170,9 @@
// If fence is specified, this function will block until the fence is cleared
// before writing to the buffer.
// Always called on the render thread.
- ndk::ScopedAStatus renderIntoEglFramebuffer(EglFrameBuffer& framebuffer,
- sp<Fence> fence = nullptr);
+ ndk::ScopedAStatus renderIntoEglFramebuffer(
+ EglFrameBuffer& framebuffer, sp<Fence> fence = nullptr,
+ std::optional<Rect> viewport = std::nullopt);
// Camera callback
const std::shared_ptr<
diff --git a/services/camera/virtualcamera/VirtualCameraService.cc b/services/camera/virtualcamera/VirtualCameraService.cc
index 1144997..18961c0 100644
--- a/services/camera/virtualcamera/VirtualCameraService.cc
+++ b/services/camera/virtualcamera/VirtualCameraService.cc
@@ -46,6 +46,10 @@
using ::aidl::android::companion::virtualcamera::SupportedStreamConfiguration;
using ::aidl::android::companion::virtualcamera::VirtualCameraConfiguration;
+// TODO(b/301023410) Make camera id range configurable / dynamic
+// based on already registered devices.
+std::atomic_int VirtualCameraService::sNextId{1000};
+
namespace {
constexpr int kVgaWidth = 640;
@@ -110,6 +114,13 @@
ndk::ScopedAStatus VirtualCameraService::registerCamera(
const ::ndk::SpAIBinder& token,
const VirtualCameraConfiguration& configuration, bool* _aidl_return) {
+ return registerCamera(token, configuration, sNextId++, _aidl_return);
+}
+
+ndk::ScopedAStatus VirtualCameraService::registerCamera(
+ const ::ndk::SpAIBinder& token,
+ const VirtualCameraConfiguration& configuration, const int cameraId,
+ bool* _aidl_return) {
if (!mPermissionProxy.checkCallingPermission(kCreateVirtualDevicePermission)) {
ALOGE("%s: caller (pid %d, uid %d) doesn't hold %s permission", __func__,
getpid(), getuid(), kCreateVirtualDevicePermission);
@@ -141,7 +152,7 @@
}
std::shared_ptr<VirtualCameraDevice> camera =
- mVirtualCameraProvider->createCamera(configuration);
+ mVirtualCameraProvider->createCamera(configuration, cameraId);
if (camera == nullptr) {
ALOGE("Failed to create camera for binder token 0x%" PRIxPTR,
reinterpret_cast<uintptr_t>(token.get()));
@@ -175,11 +186,12 @@
mVirtualCameraProvider->removeCamera(it->second);
+ mTokenToCameraName.erase(it);
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus VirtualCameraService::getCameraId(
- const ::ndk::SpAIBinder& token, int32_t* _aidl_return) {
+ const ::ndk::SpAIBinder& token, int32_t* _aidl_return) {
if (!mPermissionProxy.checkCallingPermission(kCreateVirtualDevicePermission)) {
ALOGE("%s: caller (pid %d, uid %d) doesn't hold %s permission", __func__,
getpid(), getuid(), kCreateVirtualDevicePermission);
@@ -188,7 +200,7 @@
if (_aidl_return == nullptr) {
return ndk::ScopedAStatus::fromServiceSpecificError(
- Status::EX_ILLEGAL_ARGUMENT);
+ Status::EX_ILLEGAL_ARGUMENT);
}
auto camera = getCamera(token);
@@ -235,7 +247,15 @@
}
const char* const cmd = args[0];
if (strcmp(kEnableTestCameraCmd, cmd) == 0) {
- enableTestCameraCmd(in, err);
+ int cameraId = 0;
+ if (numArgs > 1 && args[1] != nullptr) {
+ cameraId = atoi(args[1]);
+ }
+ if (cameraId == 0) {
+ cameraId = sNextId++;
+ }
+
+ enableTestCameraCmd(in, err, cameraId);
} else if (strcmp(kDisableTestCameraCmd, cmd) == 0) {
disableTestCameraCmd(in);
} else {
@@ -246,7 +266,8 @@
return STATUS_OK;
}
-void VirtualCameraService::enableTestCameraCmd(const int out, const int err) {
+void VirtualCameraService::enableTestCameraCmd(const int out, const int err,
+ const int cameraId) {
if (mTestCameraToken != nullptr) {
dprintf(out, "Test camera is already enabled (%s).",
getCamera(mTestCameraToken)->getCameraName().c_str());
@@ -263,7 +284,7 @@
Format::YUV_420_888,
.maxFps = kMaxFps});
configuration.lensFacing = LensFacing::EXTERNAL;
- registerCamera(mTestCameraToken, configuration, &ret);
+ registerCamera(mTestCameraToken, configuration, cameraId, &ret);
if (ret) {
dprintf(out, "Successfully registered test camera %s",
getCamera(mTestCameraToken)->getCameraName().c_str());
diff --git a/services/camera/virtualcamera/VirtualCameraService.h b/services/camera/virtualcamera/VirtualCameraService.h
index d573986..d447fc7 100644
--- a/services/camera/virtualcamera/VirtualCameraService.h
+++ b/services/camera/virtualcamera/VirtualCameraService.h
@@ -45,6 +45,13 @@
configuration,
bool* _aidl_return) override EXCLUDES(mLock);
+ // Register camera corresponding to the binder token.
+ ndk::ScopedAStatus registerCamera(
+ const ::ndk::SpAIBinder& token,
+ const ::aidl::android::companion::virtualcamera::VirtualCameraConfiguration&
+ configuration,
+ int cameraId, bool* _aidl_return) EXCLUDES(mLock);
+
// Unregisters camera corresponding to the binder token.
ndk::ScopedAStatus unregisterCamera(const ::ndk::SpAIBinder& token) override
EXCLUDES(mLock);
@@ -64,7 +71,7 @@
private:
// Create and enable test camera instance if there's none.
- void enableTestCameraCmd(int out, int err);
+ void enableTestCameraCmd(int out, int err, int cameraId);
// Disable and destroy test camera instance if there's one.
void disableTestCameraCmd(int out);
@@ -84,6 +91,9 @@
// Local binder token for test camera instance, or nullptr if there's none.
::ndk::SpAIBinder mTestCameraToken;
+
+ // Numerical id to assign to next created camera.
+ static std::atomic_int sNextId;
};
} // namespace virtualcamera
diff --git a/services/camera/virtualcamera/VirtualCameraSession.cc b/services/camera/virtualcamera/VirtualCameraSession.cc
index a0bb72e..05fa5ae 100644
--- a/services/camera/virtualcamera/VirtualCameraSession.cc
+++ b/services/camera/virtualcamera/VirtualCameraSession.cc
@@ -257,13 +257,15 @@
return RequestSettings{
.jpegQuality = getJpegQuality(metadata).value_or(
VirtualCameraDevice::kDefaultJpegQuality),
+ .jpegOrientation = getJpegOrientation(metadata),
.thumbnailResolution =
getJpegThumbnailSize(metadata).value_or(Resolution(0, 0)),
.thumbnailJpegQuality = getJpegThumbnailQuality(metadata).value_or(
VirtualCameraDevice::kDefaultJpegQuality),
.fpsRange = getFpsRange(metadata),
.captureIntent = getCaptureIntent(metadata).value_or(
- ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW)};
+ ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW),
+ .gpsCoordinates = getGpsCoordinates(metadata)};
}
} // namespace
diff --git a/services/camera/virtualcamera/tests/Android.bp b/services/camera/virtualcamera/tests/Android.bp
index c51b4a3..543cc10 100644
--- a/services/camera/virtualcamera/tests/Android.bp
+++ b/services/camera/virtualcamera/tests/Android.bp
@@ -17,6 +17,7 @@
],
srcs: [
"EglUtilTest.cc",
+ "JpegUtilTest.cc",
"VirtualCameraDeviceTest.cc",
"VirtualCameraProviderTest.cc",
"VirtualCameraRenderThreadTest.cc",
diff --git a/services/camera/virtualcamera/tests/JpegUtilTest.cc b/services/camera/virtualcamera/tests/JpegUtilTest.cc
new file mode 100644
index 0000000..e6481f0
--- /dev/null
+++ b/services/camera/virtualcamera/tests/JpegUtilTest.cc
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2023 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.
+ */
+
+#include <sys/types.h>
+
+#include "system/graphics.h"
+#define LOG_TAG "JpegUtilTest"
+
+#include <array>
+#include <cstdint>
+#include <cstring>
+
+#include "android/hardware_buffer.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include "jpeglib.h"
+#include "util/JpegUtil.h"
+#include "util/Util.h"
+#include "utils/Errors.h"
+
+namespace android {
+namespace companion {
+namespace virtualcamera {
+namespace {
+
+using testing::Eq;
+using testing::Gt;
+using testing::Optional;
+using testing::VariantWith;
+
+constexpr int kOutputBufferSize = 1024 * 1024; // 1 MiB.
+constexpr int kJpegQuality = 80;
+
+// Create black YUV420 buffer for testing purposes.
+std::shared_ptr<AHardwareBuffer> createHardwareBufferForTest(const int width,
+ const int height) {
+ const AHardwareBuffer_Desc desc{.width = static_cast<uint32_t>(width),
+ .height = static_cast<uint32_t>(height),
+ .layers = 1,
+ .format = AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420,
+ .usage = AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN,
+ .stride = 0,
+ .rfu0 = 0,
+ .rfu1 = 0};
+
+ AHardwareBuffer* hwBufferPtr;
+ int status = AHardwareBuffer_allocate(&desc, &hwBufferPtr);
+ if (status != NO_ERROR) {
+ ALOGE(
+ "%s: Failed to allocate hardware buffer for temporary framebuffer: %d",
+ __func__, status);
+ return nullptr;
+ }
+
+ std::shared_ptr<AHardwareBuffer> hwBuffer(hwBufferPtr,
+ AHardwareBuffer_release);
+
+ YCbCrLockGuard yCbCrLock(hwBuffer, AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN);
+ const android_ycbcr& ycbr = (*yCbCrLock);
+
+ uint8_t* y = reinterpret_cast<uint8_t*>(ycbr.y);
+ for (int r = 0; r < height; r++) {
+ memset(y + r * ycbr.ystride, 0x00, width);
+ }
+
+ uint8_t* cb = reinterpret_cast<uint8_t*>(ycbr.cb);
+ uint8_t* cr = reinterpret_cast<uint8_t*>(ycbr.cr);
+ for (int r = 0; r < height / 2; r++) {
+ for (int c = 0; c < width / 2; c++) {
+ cb[r * ycbr.cstride + c * ycbr.chroma_step] = 0xff / 2;
+ cr[r * ycbr.cstride + c * ycbr.chroma_step] = 0xff / 2;
+ }
+ }
+
+ return hwBuffer;
+}
+
+// Decode JPEG header, return image resolution on success or error message on error.
+std::variant<std::string, Resolution> verifyHeaderAndGetResolution(
+ const uint8_t* data, int size) {
+ struct jpeg_decompress_struct ctx;
+ struct jpeg_error_mgr jerr;
+
+ struct DecompressionError {
+ bool success = true;
+ std::string error;
+ } result;
+
+ ctx.client_data = &result;
+
+ ctx.err = jpeg_std_error(&jerr);
+ ctx.err->error_exit = [](j_common_ptr cinfo) {
+ reinterpret_cast<DecompressionError*>(cinfo->client_data)->success = false;
+ };
+ ctx.err->output_message = [](j_common_ptr cinfo) {
+ char buffer[JMSG_LENGTH_MAX];
+ (*cinfo->err->format_message)(cinfo, buffer);
+ reinterpret_cast<DecompressionError*>(cinfo->client_data)->error = buffer;
+ ALOGE("libjpeg error: %s", buffer);
+ };
+
+ jpeg_create_decompress(&ctx);
+ jpeg_mem_src(&ctx, data, size);
+ jpeg_read_header(&ctx, /*require_image=*/true);
+
+ if (!result.success) {
+ jpeg_destroy_decompress(&ctx);
+ return result.error;
+ }
+
+ Resolution resolution(ctx.image_width, ctx.image_height);
+ jpeg_destroy_decompress(&ctx);
+ return resolution;
+}
+
+TEST(JpegUtil, roundToDctSize) {
+ EXPECT_THAT(roundTo2DctSize(Resolution(640, 480)), Eq(Resolution(640, 480)));
+ EXPECT_THAT(roundTo2DctSize(Resolution(5, 5)), Eq(Resolution(16, 16)));
+ EXPECT_THAT(roundTo2DctSize(Resolution(32, 32)), Eq(Resolution(32, 32)));
+ EXPECT_THAT(roundTo2DctSize(Resolution(33, 32)), Eq(Resolution(48, 32)));
+ EXPECT_THAT(roundTo2DctSize(Resolution(32, 33)), Eq(Resolution(32, 48)));
+}
+
+class JpegUtilTest : public ::testing::Test {
+ public:
+ void SetUp() override {
+ std::fill(mOutputBuffer.begin(), mOutputBuffer.end(), 0);
+ }
+
+ protected:
+ std::optional<size_t> compress(int imageWidth, int imageHeight,
+ std::shared_ptr<AHardwareBuffer> inBuffer) {
+ return compressJpeg(imageWidth, imageHeight, kJpegQuality, inBuffer,
+ /*app1ExifData=*/{}, mOutputBuffer.size(),
+ mOutputBuffer.data());
+ }
+
+ std::array<uint8_t, kOutputBufferSize> mOutputBuffer;
+};
+
+TEST_F(JpegUtilTest, compressImageSizeAlignedWithDctSucceeds) {
+ std::shared_ptr<AHardwareBuffer> inBuffer =
+ createHardwareBufferForTest(640, 480);
+
+ std::optional<size_t> compressedSize = compress(640, 480, inBuffer);
+
+ EXPECT_THAT(compressedSize, Optional(Gt(0)));
+ EXPECT_THAT(verifyHeaderAndGetResolution(mOutputBuffer.data(),
+ compressedSize.value()),
+ VariantWith<Resolution>(Resolution(640, 480)));
+}
+
+TEST_F(JpegUtilTest, compressImageSizeNotAlignedWidthDctSucceeds) {
+ std::shared_ptr<AHardwareBuffer> inBuffer =
+ createHardwareBufferForTest(640, 480);
+
+ std::optional<size_t> compressedSize = compress(630, 470, inBuffer);
+
+ EXPECT_THAT(compressedSize, Optional(Gt(0)));
+ EXPECT_THAT(verifyHeaderAndGetResolution(mOutputBuffer.data(),
+ compressedSize.value()),
+ VariantWith<Resolution>(Resolution(630, 470)));
+}
+
+TEST_F(JpegUtilTest, compressImageWithBufferNotAlignedWithDctFails) {
+ std::shared_ptr<AHardwareBuffer> inBuffer =
+ createHardwareBufferForTest(641, 480);
+
+ std::optional<size_t> compressedSize = compress(640, 480, inBuffer);
+
+ EXPECT_THAT(compressedSize, Eq(std::nullopt));
+}
+
+TEST_F(JpegUtilTest, compressImageWithBufferTooSmallFails) {
+ std::shared_ptr<AHardwareBuffer> inBuffer =
+ createHardwareBufferForTest(634, 464);
+
+ std::optional<size_t> compressedSize = compress(640, 480, inBuffer);
+
+ EXPECT_THAT(compressedSize, Eq(std::nullopt));
+}
+
+} // namespace
+} // namespace virtualcamera
+} // namespace companion
+} // namespace android
diff --git a/services/camera/virtualcamera/tests/VirtualCameraProviderTest.cc b/services/camera/virtualcamera/tests/VirtualCameraProviderTest.cc
index ab647a4..cd64ca5 100644
--- a/services/camera/virtualcamera/tests/VirtualCameraProviderTest.cc
+++ b/services/camera/virtualcamera/tests/VirtualCameraProviderTest.cc
@@ -53,6 +53,7 @@
constexpr int kVgaWidth = 640;
constexpr int kVgaHeight = 480;
constexpr int kMaxFps = 30;
+constexpr int kCameraId = 9999;
constexpr char kVirtualCameraNameRegex[] =
"device@[0-9]+\\.[0-9]+/virtual/[0-9]+";
@@ -118,7 +119,7 @@
ASSERT_TRUE(mCameraProvider->setCallback(mMockCameraProviderCallback).isOk());
std::shared_ptr<VirtualCameraDevice> camera =
- mCameraProvider->createCamera(mInputConfig);
+ mCameraProvider->createCamera(mInputConfig, kCameraId);
EXPECT_THAT(camera, Not(IsNull()));
EXPECT_THAT(camera->getCameraName(), MatchesRegex(kVirtualCameraNameRegex));
@@ -136,7 +137,7 @@
.WillOnce(Return(ndk::ScopedAStatus::ok()));
std::shared_ptr<VirtualCameraDevice> camera =
- mCameraProvider->createCamera(mInputConfig);
+ mCameraProvider->createCamera(mInputConfig, kCameraId);
ASSERT_TRUE(mCameraProvider->setCallback(mMockCameraProviderCallback).isOk());
// Created camera should be in the list of cameras.
@@ -148,7 +149,7 @@
TEST_F(VirtualCameraProviderTest, RemoveCamera) {
ASSERT_TRUE(mCameraProvider->setCallback(mMockCameraProviderCallback).isOk());
std::shared_ptr<VirtualCameraDevice> camera =
- mCameraProvider->createCamera(mInputConfig);
+ mCameraProvider->createCamera(mInputConfig, kCameraId);
EXPECT_CALL(*mMockCameraProviderCallback,
cameraDeviceStatusChange(Eq(camera->getCameraName()),
@@ -165,7 +166,7 @@
TEST_F(VirtualCameraProviderTest, RemoveNonExistingCamera) {
ASSERT_TRUE(mCameraProvider->setCallback(mMockCameraProviderCallback).isOk());
std::shared_ptr<VirtualCameraDevice> camera =
- mCameraProvider->createCamera(mInputConfig);
+ mCameraProvider->createCamera(mInputConfig, kCameraId);
// Removing non-existing camera should fail.
const std::string cameraName = "DefinitelyNoTCamera";
diff --git a/services/camera/virtualcamera/tests/VirtualCameraServiceTest.cc b/services/camera/virtualcamera/tests/VirtualCameraServiceTest.cc
index d4d00a2..f729f73 100644
--- a/services/camera/virtualcamera/tests/VirtualCameraServiceTest.cc
+++ b/services/camera/virtualcamera/tests/VirtualCameraServiceTest.cc
@@ -142,6 +142,14 @@
Eq(NO_ERROR));
}
+ void execute_shell_command(const std::string cmd, const std::string cameraId) {
+ std::array<const char*, 2> args{cmd.data(), cameraId.data()};
+ ASSERT_THAT(
+ mCameraService->handleShellCommand(mDevNullFd, mDevNullFd, mDevNullFd,
+ args.data(), args.size()),
+ Eq(NO_ERROR));
+ }
+
std::vector<std::string> getCameraIds() {
std::vector<std::string> cameraIds;
EXPECT_TRUE(mCameraProvider->getCameraIdList(&cameraIds).isOk());
@@ -238,17 +246,6 @@
EXPECT_THAT(getCameraIds(), IsEmpty());
}
-TEST_F(VirtualCameraServiceTest, ConfigurationWithUnalignedResolutionFails) {
- bool aidlRet;
- VirtualCameraConfiguration config =
- createConfiguration(641, 481, Format::YUV_420_888, kMaxFps);
-
- ASSERT_FALSE(
- mCameraService->registerCamera(mNdkOwnerToken, config, &aidlRet).isOk());
- EXPECT_FALSE(aidlRet);
- EXPECT_THAT(getCameraIds(), IsEmpty());
-}
-
TEST_F(VirtualCameraServiceTest, ConfigurationWithNegativeResolutionFails) {
bool aidlRet;
VirtualCameraConfiguration config =
@@ -381,6 +378,18 @@
EXPECT_THAT(cameraIdsAfterDisable, IsEmpty());
}
+TEST_F(VirtualCameraServiceTest, TestCameraShellCmdWithId) {
+ execute_shell_command("enable_test_camera", "12345");
+
+ std::vector<std::string> cameraIdsAfterEnable = getCameraIds();
+ EXPECT_THAT(cameraIdsAfterEnable, SizeIs(1));
+
+ execute_shell_command("disable_test_camera");
+
+ std::vector<std::string> cameraIdsAfterDisable = getCameraIds();
+ EXPECT_THAT(cameraIdsAfterDisable, IsEmpty());
+}
+
} // namespace
} // namespace virtualcamera
} // namespace companion
diff --git a/services/camera/virtualcamera/util/JpegUtil.cc b/services/camera/virtualcamera/util/JpegUtil.cc
index 8569eff..b034584 100644
--- a/services/camera/virtualcamera/util/JpegUtil.cc
+++ b/services/camera/virtualcamera/util/JpegUtil.cc
@@ -14,19 +14,20 @@
* limitations under the License.
*/
// #define LOG_NDEBUG 0
+#include "system/graphics.h"
#define LOG_TAG "JpegUtil"
-#include "JpegUtil.h"
-
#include <cstddef>
#include <cstdint>
#include <optional>
#include <vector>
+#include "JpegUtil.h"
#include "android/hardware_buffer.h"
#include "jpeglib.h"
#include "log/log.h"
#include "ui/GraphicBuffer.h"
#include "ui/GraphicBufferMapper.h"
+#include "util/Util.h"
#include "utils/Errors.h"
namespace android {
@@ -34,6 +35,8 @@
namespace virtualcamera {
namespace {
+constexpr int k2DCTSIZE = 2 * DCTSIZE;
+
class LibJpegContext {
public:
LibJpegContext(int width, int height, int quality, const size_t outBufferSize,
@@ -98,23 +101,55 @@
return *this;
}
- std::optional<size_t> compress(const android_ycbcr& ycbr) {
- // TODO(b/301023410) - Add support for compressing image sizes not aligned
- // with DCT size.
- if (mWidth % (2 * DCTSIZE) || (mHeight % (2 * DCTSIZE))) {
+ std::optional<size_t> compress(std::shared_ptr<AHardwareBuffer> inBuffer) {
+ GraphicBuffer* gBuffer = GraphicBuffer::fromAHardwareBuffer(inBuffer.get());
+
+ if (gBuffer == nullptr) {
+ ALOGE("%s: Input graphic buffer is nullptr", __func__);
+ return std::nullopt;
+ }
+
+ if (gBuffer->getPixelFormat() != HAL_PIXEL_FORMAT_YCbCr_420_888) {
+ // This should never happen since we're allocating the temporary buffer
+ // with YUV420 layout above.
+ ALOGE("%s: Cannot compress non-YUV buffer (pixelFormat %d)", __func__,
+ gBuffer->getPixelFormat());
+ return std::nullopt;
+ }
+
+ YCbCrLockGuard yCbCrLock(inBuffer, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN);
+ if (yCbCrLock.getStatus() != OK) {
+ ALOGE("%s: Failed to lock the input buffer: %s", __func__,
+ statusToString(yCbCrLock.getStatus()).c_str());
+ return std::nullopt;
+ }
+ const android_ycbcr& ycbr = *yCbCrLock;
+
+ const int inBufferWidth = gBuffer->getWidth();
+ const int inBufferHeight = gBuffer->getHeight();
+
+ if (inBufferWidth % k2DCTSIZE || (inBufferHeight % k2DCTSIZE)) {
ALOGE(
- "%s: Compressing YUV420 image with size %dx%d not aligned with 2 * "
+ "%s: Compressing YUV420 buffer with size %dx%d not aligned with 2 * "
"DCTSIZE (%d) is not currently supported.",
- __func__, mWidth, mHeight, 2 * DCTSIZE);
+ __func__, inBufferWidth, inBufferHeight, DCTSIZE);
+ return std::nullopt;
+ }
+
+ if (inBufferWidth < mWidth || inBufferHeight < mHeight) {
+ ALOGE(
+ "%s: Input buffer has smaller size (%dx%d) than image to be "
+ "compressed (%dx%d)",
+ __func__, inBufferWidth, inBufferHeight, mWidth, mHeight);
return std::nullopt;
}
// Chroma planes have 1/2 resolution of the original image.
- const int cHeight = mHeight / 2;
- const int cWidth = mWidth / 2;
+ const int cHeight = inBufferHeight / 2;
+ const int cWidth = inBufferWidth / 2;
// Prepare arrays of pointers to scanlines of each plane.
- std::vector<JSAMPROW> yLines(mHeight);
+ std::vector<JSAMPROW> yLines(inBufferHeight);
std::vector<JSAMPROW> cbLines(cHeight);
std::vector<JSAMPROW> crLines(cHeight);
@@ -142,12 +177,12 @@
}
// Collect pointers to individual scanline of each plane.
- for (int i = 0; i < mHeight; ++i) {
+ for (int i = 0; i < inBufferHeight; ++i) {
yLines[i] = y + i * ycbr.ystride;
}
for (int i = 0; i < cHeight; ++i) {
- cbLines[i] = cb_plane.data() + i * (mWidth / 2);
- crLines[i] = cr_plane.data() + i * (mWidth / 2);
+ cbLines[i] = cb_plane.data() + i * cWidth;
+ crLines[i] = cr_plane.data() + i * cWidth;
}
return compress(yLines, cbLines, crLines);
@@ -254,17 +289,28 @@
boolean mSuccess = true;
};
+int roundTo2DCTMultiple(const int n) {
+ const int mod = n % k2DCTSIZE;
+ return mod == 0 ? n : n + (k2DCTSIZE - mod);
+}
+
} // namespace
std::optional<size_t> compressJpeg(const int width, const int height,
- const int quality, const android_ycbcr& ycbcr,
+ const int quality,
+ std::shared_ptr<AHardwareBuffer> inBuffer,
const std::vector<uint8_t>& app1ExifData,
size_t outBufferSize, void* outBuffer) {
LibJpegContext context(width, height, quality, outBufferSize, outBuffer);
if (!app1ExifData.empty()) {
context.setApp1Data(app1ExifData.data(), app1ExifData.size());
}
- return context.compress(ycbcr);
+ return context.compress(inBuffer);
+}
+
+Resolution roundTo2DctSize(const Resolution resolution) {
+ return Resolution(roundTo2DCTMultiple(resolution.width),
+ roundTo2DCTMultiple(resolution.height));
}
} // namespace virtualcamera
diff --git a/services/camera/virtualcamera/util/JpegUtil.h b/services/camera/virtualcamera/util/JpegUtil.h
index 83ed74b..184dd56 100644
--- a/services/camera/virtualcamera/util/JpegUtil.h
+++ b/services/camera/virtualcamera/util/JpegUtil.h
@@ -19,17 +19,20 @@
#include <optional>
-#include "system/graphics.h"
+#include "android/hardware_buffer.h"
+#include "util/Util.h"
namespace android {
namespace companion {
namespace virtualcamera {
// Jpeg-compress image into the output buffer.
-// * width - width of the image
-// * heigh - height of the image
+// * width - width of the image, can be less than width of inBuffer.
+// * heigh - height of the image, can be less than height of inBuffer.
// * quality - 0-100, higher number corresponds to higher quality.
-// * ycbr - android_ycbr structure describing layout of input YUV420 image.
+// * inBuffer - Input buffer, the dimensions of the buffer must be aligned to
+// 2*DCT_SIZE (16) to include necessary padding in case width and height of
+// image is not aligned with 2*DCT_SIZE.
// * app1ExifData - vector containing data to be included in APP1
// segment. Can be empty.
// * outBufferSize - capacity of the output buffer.
@@ -37,10 +40,14 @@
// Returns size of compressed data if the compression was successful,
// empty optional otherwise.
std::optional<size_t> compressJpeg(int width, int height, int quality,
- const android_ycbcr& ycbcr,
+ std::shared_ptr<AHardwareBuffer> inBuffer,
const std::vector<uint8_t>& app1ExifData,
size_t outBufferSize, void* outBuffer);
+// Round the resolution to the closest higher resolution where width and height
+// are divisible by 2*DCT_SIZE ().
+Resolution roundTo2DctSize(Resolution resolution);
+
} // namespace virtualcamera
} // namespace companion
} // namespace android
diff --git a/services/camera/virtualcamera/util/MetadataUtil.cc b/services/camera/virtualcamera/util/MetadataUtil.cc
index 119260f..c7dc80e 100644
--- a/services/camera/virtualcamera/util/MetadataUtil.cc
+++ b/services/camera/virtualcamera/util/MetadataUtil.cc
@@ -24,6 +24,7 @@
#include <iterator>
#include <memory>
#include <optional>
+#include <string>
#include <utility>
#include <variant>
#include <vector>
@@ -435,6 +436,29 @@
return *this;
}
+MetadataBuilder& MetadataBuilder::setJpegGpsCoordinates(
+ const GpsCoordinates& gpsCoordinates) {
+ mEntryMap[ANDROID_JPEG_GPS_COORDINATES] =
+ std::vector<double>({gpsCoordinates.latitude, gpsCoordinates.longitude,
+ gpsCoordinates.altitude});
+
+ if (!gpsCoordinates.provider.empty()) {
+ mEntryMap[ANDROID_JPEG_GPS_PROCESSING_METHOD] = std::vector<uint8_t>{
+ gpsCoordinates.provider.begin(), gpsCoordinates.provider.end()};
+ }
+
+ if (gpsCoordinates.timestamp.has_value()) {
+ mEntryMap[ANDROID_JPEG_GPS_TIMESTAMP] =
+ asVectorOf<int64_t>(gpsCoordinates.timestamp.value());
+ }
+ return *this;
+}
+
+MetadataBuilder& MetadataBuilder::setJpegOrientation(const int32_t orientation) {
+ mEntryMap[ANDROID_JPEG_ORIENTATION] = asVectorOf<int32_t>(orientation);
+ return *this;
+}
+
MetadataBuilder& MetadataBuilder::setJpegQuality(const uint8_t quality) {
mEntryMap[ANDROID_JPEG_QUALITY] = asVectorOf<uint8_t>(quality);
return *this;
@@ -753,6 +777,20 @@
return *entry.data.i32;
}
+int32_t getJpegOrientation(
+ const aidl::android::hardware::camera::device::CameraMetadata& cameraMetadata) {
+ auto metadata =
+ reinterpret_cast<const camera_metadata_t*>(cameraMetadata.metadata.data());
+
+ camera_metadata_ro_entry_t entry;
+ if (find_camera_metadata_ro_entry(metadata, ANDROID_JPEG_ORIENTATION,
+ &entry) != OK) {
+ return 0;
+ }
+
+ return *entry.data.i32;
+}
+
std::optional<Resolution> getJpegThumbnailSize(
const aidl::android::hardware::camera::device::CameraMetadata& cameraMetadata) {
auto metadata =
@@ -832,6 +870,39 @@
entry.data.u8[0]);
}
+std::optional<GpsCoordinates> getGpsCoordinates(
+ const aidl::android::hardware::camera::device::CameraMetadata& cameraMetadata) {
+ auto metadata =
+ reinterpret_cast<const camera_metadata_t*>(cameraMetadata.metadata.data());
+
+ camera_metadata_ro_entry_t entry;
+ if (find_camera_metadata_ro_entry(metadata, ANDROID_JPEG_GPS_COORDINATES,
+ &entry) != OK) {
+ return std::nullopt;
+ }
+
+ GpsCoordinates coordinates{.latitude = entry.data.d[0],
+ .longitude = entry.data.d[1],
+ .altitude = entry.data.d[2]};
+
+ if (find_camera_metadata_ro_entry(metadata, ANDROID_JPEG_GPS_TIMESTAMP,
+ &entry) == OK) {
+ coordinates.timestamp = entry.data.i64[0];
+ }
+
+ // According to types.hal, the string describing the GPS processing method has
+ // a 32 characters size
+ static constexpr float kGpsProviderStringLength = 32;
+ if (find_camera_metadata_ro_entry(
+ metadata, ANDROID_JPEG_GPS_PROCESSING_METHOD, &entry) == OK) {
+ coordinates.provider.assign(
+ reinterpret_cast<const char*>(entry.data.u8),
+ std::min(entry.count, static_cast<size_t>(kGpsProviderStringLength)));
+ }
+
+ return coordinates;
+}
+
} // namespace virtualcamera
} // namespace companion
} // namespace android
diff --git a/services/camera/virtualcamera/util/MetadataUtil.h b/services/camera/virtualcamera/util/MetadataUtil.h
index f6848cd..5d16506 100644
--- a/services/camera/virtualcamera/util/MetadataUtil.h
+++ b/services/camera/virtualcamera/util/MetadataUtil.h
@@ -328,6 +328,12 @@
MetadataBuilder& setJpegAvailableThumbnailSizes(
const std::vector<Resolution>& thumbnailSizes);
+ // See ANDROID_JPEG_GPS_COORDINATES.
+ MetadataBuilder& setJpegGpsCoordinates(const GpsCoordinates& gpsCoordinates);
+
+ // See JPEG_ORIENTATION in CaptureRequest.java.
+ MetadataBuilder& setJpegOrientation(int32_t orientation);
+
// See JPEG_QUALITY in CaptureRequest.java.
MetadataBuilder& setJpegQuality(uint8_t quality);
@@ -421,10 +427,11 @@
private:
// Maps metadata tags to vectors of values for the given tag.
- std::map<camera_metadata_tag_t,
- std::variant<std::vector<int64_t>, std::vector<int32_t>,
- std::vector<uint8_t>, std::vector<float>,
- std::vector<camera_metadata_rational_t>>>
+ std::map<
+ camera_metadata_tag_t,
+ std::variant<std::vector<int64_t>, std::vector<int32_t>,
+ std::vector<uint8_t>, std::vector<float>,
+ std::vector<camera_metadata_rational_t>, std::vector<double>>>
mEntryMap;
// Extend metadata with ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS.
bool mExtendWithAvailableCharacteristicsKeys = false;
@@ -434,6 +441,10 @@
std::optional<int32_t> getJpegQuality(
const aidl::android::hardware::camera::device::CameraMetadata& metadata);
+// Return JPEG_ORIENTATION from metadata, or 0 if the key is not present
+int32_t getJpegOrientation(
+ const aidl::android::hardware::camera::device::CameraMetadata& metadata);
+
// Returns JPEG_THUMBNAIL_SIZE from metadata, or nullopt if the key is not present.
std::optional<Resolution> getJpegThumbnailSize(
const aidl::android::hardware::camera::device::CameraMetadata& metadata);
@@ -453,6 +464,11 @@
std::optional<camera_metadata_enum_android_control_capture_intent> getCaptureIntent(
const aidl::android::hardware::camera::device::CameraMetadata& metadata);
+// Returns ANDROID_JPEG_GPS_COORDINATES in a GpsCoordinate object or nullopt if
+// the key is not present.
+std::optional<GpsCoordinates> getGpsCoordinates(
+ const aidl::android::hardware::camera::device::CameraMetadata& metadata);
+
} // namespace virtualcamera
} // namespace companion
} // namespace android
diff --git a/services/camera/virtualcamera/util/Util.cc b/services/camera/virtualcamera/util/Util.cc
index b2048bc..0c607d7 100644
--- a/services/camera/virtualcamera/util/Util.cc
+++ b/services/camera/virtualcamera/util/Util.cc
@@ -146,13 +146,6 @@
return false;
}
- if (width % kLibJpegDctSize != 0 || height % kLibJpegDctSize != 0) {
- // Input dimension needs to be multiple of libjpeg DCT size.
- // TODO(b/301023410) This restriction can be removed once we add support for
- // unaligned jpeg compression.
- return false;
- }
-
if (maxFps <= 0 || maxFps > kMaxFpsUpperLimit) {
return false;
}
diff --git a/services/camera/virtualcamera/util/Util.h b/services/camera/virtualcamera/util/Util.h
index f08eb1c..291e105 100644
--- a/services/camera/virtualcamera/util/Util.h
+++ b/services/camera/virtualcamera/util/Util.h
@@ -20,6 +20,8 @@
#include <cmath>
#include <cstdint>
#include <memory>
+#include <optional>
+#include <string>
#include "aidl/android/companion/virtualcamera/Format.h"
#include "aidl/android/hardware/camera/common/Status.h"
@@ -152,6 +154,16 @@
}
};
+struct GpsCoordinates {
+ // Represented by a double[] in metadata with index 0 for
+ // latitude and index 1 for longitude, 2 for altitude.
+ double_t latitude;
+ double_t longitude;
+ double_t altitude;
+ std::optional<int64_t> timestamp;
+ std::string provider;
+};
+
inline bool isApproximatellySameAspectRatio(const Resolution r1,
const Resolution r2) {
static constexpr float kAspectRatioEpsilon = 0.05;
diff --git a/services/oboeservice/Android.bp b/services/oboeservice/Android.bp
index 12ce17f..e3601a1 100644
--- a/services/oboeservice/Android.bp
+++ b/services/oboeservice/Android.bp
@@ -69,10 +69,10 @@
"-android-cloexec-dup", // found in AAudioServiceEndpointMMAP.cpp
"-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
+ "-google-readability-casting", // C++ casts not always necessary and may be verbose
+ "-google-readability-todo", // do not require TODO(info)
"-misc-non-private-member-variables-in-classes", // found in aidl generated files
@@ -82,27 +82,27 @@
name: "libaaudioservice_dependencies",
shared_libs: [
+ "aaudio-aidl-cpp",
+ "com.android.media.aaudio-aconfig-cc",
+ "framework-permission-aidl-cpp",
"libaaudio_internal",
"libaudioclient",
+ "libaudioclient_aidl_conversion",
"libaudioutils",
- "libmedia_helper",
- "libmediametrics",
- "libmediautils",
"libbase",
"libbinder",
"libcutils",
"liblog",
+ "libmedia_helper",
+ "libmediametrics",
+ "libmediautils",
"libutils",
- "aaudio-aidl-cpp",
- "framework-permission-aidl-cpp",
- "libaudioclient_aidl_conversion",
"packagemanager_aidl-cpp",
- "com.android.media.aaudio-aconfig-cc",
],
static_libs: [
"libaudioflinger",
- ]
+ ],
}
cc_library_static {
@@ -110,8 +110,8 @@
name: "libaaudioservice",
defaults: [
- "libaaudioservice_dependencies",
"latest_android_media_audio_common_types_cpp_shared",
+ "libaaudioservice_dependencies",
],
srcs: [
@@ -137,15 +137,15 @@
],
cflags: [
- "-Wthread-safety",
- "-Wno-unused-parameter",
"-Wall",
"-Werror",
+ "-Wno-unused-parameter",
+ "-Wthread-safety",
],
export_shared_lib_headers: [
- "libaaudio_internal",
"framework-permission-aidl-cpp",
+ "libaaudio_internal",
],
header_libs: [
@@ -153,8 +153,8 @@
],
include_dirs: [
- "frameworks/av/media/libnbaio/include_mono",
"frameworks/av/media/libnbaio/include",
+ "frameworks/av/media/libnbaio/include_mono",
],
tidy: true,
@@ -162,5 +162,5 @@
tidy_checks_as_errors: tidy_errors,
tidy_flags: [
"-format-style=file",
- ]
+ ],
}
diff --git a/services/oboeservice/fuzzer/Android.bp b/services/oboeservice/fuzzer/Android.bp
index 31ed8ac..97825b3 100644
--- a/services/oboeservice/fuzzer/Android.bp
+++ b/services/oboeservice/fuzzer/Android.bp
@@ -37,22 +37,22 @@
"oboeservice_fuzzer.cpp",
],
shared_libs: [
+ "aaudio-aidl-cpp",
+ "com.android.media.aaudio-aconfig-cc",
+ "framework-permission-aidl-cpp",
"libaaudio_internal",
"libaudioclient",
+ "libaudioclient_aidl_conversion",
"libaudioflinger",
"libaudioutils",
- "libmedia_helper",
- "libmediametrics",
- "libmediautils",
"libbase",
"libbinder",
"libcutils",
"liblog",
+ "libmedia_helper",
+ "libmediametrics",
+ "libmediautils",
"libutils",
- "aaudio-aidl-cpp",
- "framework-permission-aidl-cpp",
- "libaudioclient_aidl_conversion",
- "com.android.media.aaudio-aconfig-cc",
],
static_libs: [
"libaaudioservice",
diff --git a/services/tuner/TunerDemux.cpp b/services/tuner/TunerDemux.cpp
index 92fa970..a80a88e 100644
--- a/services/tuner/TunerDemux.cpp
+++ b/services/tuner/TunerDemux.cpp
@@ -50,7 +50,9 @@
}
TunerDemux::~TunerDemux() {
- close();
+ if (!isClosed) {
+ close();
+ }
mDemux = nullptr;
mTunerService = nullptr;
}
@@ -125,6 +127,7 @@
}
::ndk::ScopedAStatus TunerDemux::close() {
+ isClosed = true;
return mDemux->close();
}
diff --git a/services/tuner/TunerDemux.h b/services/tuner/TunerDemux.h
index 0c71987..17dd7e0 100644
--- a/services/tuner/TunerDemux.h
+++ b/services/tuner/TunerDemux.h
@@ -64,6 +64,7 @@
shared_ptr<IDemux> mDemux;
int mDemuxId;
shared_ptr<TunerService> mTunerService;
+ bool isClosed = false;
};
} // namespace tuner
diff --git a/services/tuner/TunerDescrambler.cpp b/services/tuner/TunerDescrambler.cpp
index ffe0be9..c1214bd 100644
--- a/services/tuner/TunerDescrambler.cpp
+++ b/services/tuner/TunerDescrambler.cpp
@@ -41,7 +41,9 @@
}
TunerDescrambler::~TunerDescrambler() {
- close();
+ if (!isClosed) {
+ close();
+ }
mDescrambler = nullptr;
}
@@ -75,6 +77,7 @@
}
::ndk::ScopedAStatus TunerDescrambler::close() {
+ isClosed = true;
return mDescrambler->close();
}
diff --git a/services/tuner/TunerDescrambler.h b/services/tuner/TunerDescrambler.h
index b1d5fb9..434fc5d 100644
--- a/services/tuner/TunerDescrambler.h
+++ b/services/tuner/TunerDescrambler.h
@@ -48,6 +48,7 @@
private:
shared_ptr<IDescrambler> mDescrambler;
+ bool isClosed = false;
};
} // namespace tuner
diff --git a/services/tuner/TunerDvr.cpp b/services/tuner/TunerDvr.cpp
index fcee966..0e1b0fa 100644
--- a/services/tuner/TunerDvr.cpp
+++ b/services/tuner/TunerDvr.cpp
@@ -37,7 +37,9 @@
}
TunerDvr::~TunerDvr() {
- close();
+ if (!isClosed) {
+ close();
+ }
mDvr = nullptr;
}
@@ -92,6 +94,7 @@
}
::ndk::ScopedAStatus TunerDvr::close() {
+ isClosed = true;
return mDvr->close();
}
diff --git a/services/tuner/TunerDvr.h b/services/tuner/TunerDvr.h
index 2330e7b..1fb7a5c 100644
--- a/services/tuner/TunerDvr.h
+++ b/services/tuner/TunerDvr.h
@@ -77,6 +77,7 @@
private:
shared_ptr<IDvr> mDvr;
DvrType mType;
+ bool isClosed = false;
};
} // namespace tuner
diff --git a/services/tuner/TunerFilter.cpp b/services/tuner/TunerFilter.cpp
index 478e7ea..84a2b4e 100644
--- a/services/tuner/TunerFilter.cpp
+++ b/services/tuner/TunerFilter.cpp
@@ -47,7 +47,9 @@
mTunerService(tuner) {}
TunerFilter::~TunerFilter() {
- close();
+ if (!isClosed) {
+ close();
+ }
freeSharedFilterToken("");
{
Mutex::Autolock _l(mLock);
@@ -266,6 +268,7 @@
mStarted = false;
mShared = false;
mClientPid = -1;
+ isClosed = true;
return res;
}
diff --git a/services/tuner/TunerFilter.h b/services/tuner/TunerFilter.h
index f6178c4..06735aa 100644
--- a/services/tuner/TunerFilter.h
+++ b/services/tuner/TunerFilter.h
@@ -116,6 +116,7 @@
shared_ptr<FilterCallback> mFilterCallback;
Mutex mLock;
shared_ptr<TunerService> mTunerService;
+ bool isClosed = false;
};
} // namespace tuner
diff --git a/services/tuner/TunerFrontend.cpp b/services/tuner/TunerFrontend.cpp
index 1e93d95..081596a 100644
--- a/services/tuner/TunerFrontend.cpp
+++ b/services/tuner/TunerFrontend.cpp
@@ -37,7 +37,9 @@
}
TunerFrontend::~TunerFrontend() {
- close();
+ if (!isClosed) {
+ close();
+ }
mFrontend = nullptr;
mId = -1;
}
@@ -89,6 +91,7 @@
}
::ndk::ScopedAStatus TunerFrontend::close() {
+ isClosed = true;
return mFrontend->close();
}
diff --git a/services/tuner/TunerFrontend.h b/services/tuner/TunerFrontend.h
index da471fb..9612124 100644
--- a/services/tuner/TunerFrontend.h
+++ b/services/tuner/TunerFrontend.h
@@ -83,6 +83,7 @@
private:
int mId;
shared_ptr<IFrontend> mFrontend;
+ bool isClosed = false;
};
} // namespace tuner
diff --git a/services/tuner/TunerLnb.cpp b/services/tuner/TunerLnb.cpp
index 2fb6135..d27a978 100644
--- a/services/tuner/TunerLnb.cpp
+++ b/services/tuner/TunerLnb.cpp
@@ -36,7 +36,9 @@
}
TunerLnb::~TunerLnb() {
- close();
+ if (!isClosed) {
+ close();
+ }
mLnb = nullptr;
mId = -1;
}
@@ -70,6 +72,7 @@
}
::ndk::ScopedAStatus TunerLnb::close() {
+ isClosed = true;
return mLnb->close();
}
diff --git a/services/tuner/TunerLnb.h b/services/tuner/TunerLnb.h
index 72988a6..b0222d7 100644
--- a/services/tuner/TunerLnb.h
+++ b/services/tuner/TunerLnb.h
@@ -66,6 +66,7 @@
private:
int mId;
shared_ptr<ILnb> mLnb;
+ bool isClosed = false;
};
} // namespace tuner
diff --git a/services/tuner/TunerTimeFilter.cpp b/services/tuner/TunerTimeFilter.cpp
index 385a063..7a4e200 100644
--- a/services/tuner/TunerTimeFilter.cpp
+++ b/services/tuner/TunerTimeFilter.cpp
@@ -35,7 +35,9 @@
}
TunerTimeFilter::~TunerTimeFilter() {
- close();
+ if (!isClosed) {
+ close();
+ }
mTimeFilter = nullptr;
}
@@ -64,6 +66,7 @@
}
::ndk::ScopedAStatus TunerTimeFilter::close() {
+ isClosed = true;
return mTimeFilter->close();
}
diff --git a/services/tuner/TunerTimeFilter.h b/services/tuner/TunerTimeFilter.h
index 31a47cd..7e40ebe 100644
--- a/services/tuner/TunerTimeFilter.h
+++ b/services/tuner/TunerTimeFilter.h
@@ -45,6 +45,7 @@
private:
shared_ptr<ITimeFilter> mTimeFilter;
+ bool isClosed = false;
};
} // namespace tuner