Skip to content

Commit

Permalink
Move rate_estimator out of cras/src/server/rust
Browse files Browse the repository at this point in the history
BUG=b:372902037
TEST=devtools/rust_generate.py
TEST=cargo build && SYSTEM_CRAS_RUST_LIB=$PWD/target/debug/libcras_rust.a bazel test --//:system_cras_rust //...
TEST=bazel test //...
TEST=FEATURES='test -usersandbox' emerge-amd64-generic cras_rust adhd
TEST=bazel run //cras/server/rate_estimator:rate_estimator_test

Change-Id: I92dc7330f98648e86732b141d40b870ef8b2f15d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5922502
Reviewed-by: Hung-Hsien Chen <hunghsienchen@chromium.org>
Tested-by: Li-Yu Yu <aaronyu@google.com>
Commit-Queue: Li-Yu Yu <aaronyu@google.com>
Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
  • Loading branch information
afq984 authored and Chromeos LUCI committed Oct 14, 2024
1 parent 31f28a0 commit 2833ff1
Show file tree
Hide file tree
Showing 24 changed files with 133 additions and 43 deletions.
47 changes: 46 additions & 1 deletion Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "e3af85829e49125de8a0e94f1307d882246338a08bb2c2f0e7c4fedfe9a6b66f",
"checksum": "0a16d0c96d690b5045340c49e707449ec2f88cecf7d1a6bfafcd1752e6e97a19",
"crates": {
"addr2line 0.20.0": {
"name": "addr2line",
Expand Down Expand Up @@ -2306,6 +2306,50 @@
"license_ids": [],
"license_file": null
},
"cras_rate_estimator 0.1.0": {
"name": "cras_rate_estimator",
"version": "0.1.0",
"package_url": null,
"repository": null,
"targets": [
{
"Library": {
"crate_name": "cras_rate_estimator",
"crate_root": "src/lib.rs",
"srcs": {
"allow_empty": false,
"include": [
"**/*.rs"
]
}
}
}
],
"library_target_name": "cras_rate_estimator",
"common_attrs": {
"compile_data_glob": [
"**"
],
"deps": {
"common": [
{
"id": "libc 0.2.155",
"target": "libc"
},
{
"id": "log 0.4.20",
"target": "log"
}
],
"selects": {}
},
"edition": "2021",
"version": "0.1.0"
},
"license": null,
"license_ids": [],
"license_file": null
},
"cras_rust 0.1.1": {
"name": "cras_rust",
"version": "0.1.1",
Expand Down Expand Up @@ -11654,6 +11698,7 @@
"cras_feature_tier 0.1.0": "cras/server/feature_tier",
"cras_features_backend 0.1.0": "cras/server/platform/features",
"cras_processor 0.1.0": "cras/server/processor",
"cras_rate_estimator 0.1.0": "cras/server/rate_estimator",
"cras_rust 0.1.1": "cras/src/server/rust/staticlib",
"cras_s2 0.1.0": "cras/server/s2",
"dsp_rust 0.1.0": "cras/src/dsp/rust",
Expand Down
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"cras/server/platform/dlc",
"cras/server/platform/features",
"cras/server/processor",
"cras/server/rate_estimator",
"cras/server/s2",
"cras/src/dsp/rust",
"cras/src/server/rust",
Expand All @@ -30,6 +31,7 @@ cras_dlc = { path = "cras/server/platform/dlc" }
cras_features_backend = { path = "cras/server/platform/features" }
cras_feature_tier = { path = "cras/server/feature_tier" }
cras_processor = { path = "cras/server/processor" }
cras_rate_estimator = { path = "cras/server/rate_estimator" }
cras_s2 = { path = "cras/server/s2" }
dsp_rust = { path = "cras/src/dsp/rust" }

Expand Down
1 change: 1 addition & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ crates_repository(
"//cras/server/s2:Cargo.toml",
"//audio_processor:Cargo.toml",
"//cras/common:Cargo.toml",
"//cras/server/rate_estimator:Cargo.toml",
"//cras/server/feature_tier:Cargo.toml",
"//cras/server/platform/dlc:Cargo.toml",
"//cras/server/platform/features:Cargo.toml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WRITE_SOURCE_FILE_TARGETS = [
"@//cras/server/feature_tier:generate_feature_tier_h",
"@//cras/server/platform/dlc:generate_dlc_h",
"@//cras/server/processor:generate_processor_h",
"@//cras/server/rate_estimator:generate_rate_estimator_h",
"@//cras/server/s2:generate_s2_h",
"@//cras/src/dsp/rust:generate_dsp.h",
"@//cras/src/server/rust:generate_rate_estimator_h",
]
1 change: 0 additions & 1 deletion cras/deprecated/cras_test_client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ cc_binary(
"//cras/common:rust_common_cc",
"//cras/src/common:cras_types_internal",
"//cras/src/libcras:cras_client",
"//cras/src/server/rust:cc",
],
)
42 changes: 42 additions & 0 deletions cras/server/rate_estimator/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

load("@crate_index//:defs.bzl", "all_crate_deps")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_rust//rust:defs.bzl", "rust_test")
load("//:utils.bzl", "require_no_config")
load("//rules/cbindgen:rules.bzl", "cras_cbindgen")
load("//rules/rust:defs.bzl", "cras_rust_library")

cras_rust_library(
name = "rate_estimator",
srcs = glob(
include = ["src/**/*.rs"],
),
crate_name = "cras_rate_estimator",
edition = "2021",
visibility = ["//visibility:public"],
deps = all_crate_deps(normal = True),
)

rust_test(
name = "rate_estimator_test",
crate = ":rate_estimator",
target_compatible_with = require_no_config("//:system_cras_rust_build"),
)

cras_cbindgen(
name = "rate_estimator_h",
srcs = ["src/rate_estimator_bindings.rs"],
out = "rate_estimator.h",
copyright_year = 2024,
extra_args = [],
)

cc_library(
name = "cc",
hdrs = ["rate_estimator.h"],
visibility = ["//visibility:public"],
deps = [":rate_estimator"],
)
8 changes: 8 additions & 0 deletions cras/server/rate_estimator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "cras_rate_estimator"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = { workspace = true }
log = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 The ChromiumOS Authors
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -9,15 +9,14 @@
extern "C" {
#endif

#ifndef CRAS_SRC_SERVER_RUST_INCLUDE_RATE_ESTIMATOR_H_
#define CRAS_SRC_SERVER_RUST_INCLUDE_RATE_ESTIMATOR_H_
#ifndef CRAS_SERVER_RATE_ESTIMATOR_RATE_ESTIMATOR_H_
#define CRAS_SERVER_RATE_ESTIMATOR_RATE_ESTIMATOR_H_

#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>

struct rate_estimator;

Expand Down Expand Up @@ -93,7 +92,7 @@ int32_t rate_estimator_get_last_add_frames_value_for_test(const struct rate_esti
*/
uint64_t rate_estimator_get_add_frames_called_count_for_test(const struct rate_estimator *re);

#endif /* CRAS_SRC_SERVER_RUST_INCLUDE_RATE_ESTIMATOR_H_ */
#endif /* CRAS_SERVER_RATE_ESTIMATOR_RATE_ESTIMATOR_H_ */

#ifdef __cplusplus
}
Expand Down
6 changes: 6 additions & 0 deletions cras/server/rate_estimator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

mod rate_estimator;
pub mod rate_estimator_bindings;
File renamed without changes.
1 change: 0 additions & 1 deletion cras/src/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ cc_library(
deps = [
"//cras/common:rust_common_cc",
"//cras/include",
"//cras/src/server/rust:cc",
],
)

Expand Down
1 change: 1 addition & 0 deletions cras/src/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ cc_library(
"//cras/server/platform/features",
"//cras/server/platform/features:override",
"//cras/server/platform/segmentation",
"//cras/server/rate_estimator:cc",
"//cras/server/s2:cc",
"//cras/src/common",
"//cras/src/dsp",
Expand Down
2 changes: 1 addition & 1 deletion cras/src/server/cras_floop_iodev.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include <time.h>

#include "cras/server/cras_trace.h"
#include "cras/server/rate_estimator/rate_estimator.h"
#include "cras/src/common/byte_buffer.h"
#include "cras/src/server/cras_audio_area.h"
#include "cras/src/server/cras_iodev.h"
#include "cras/src/server/cras_iodev_list.h"
#include "cras/src/server/cras_rstream.h"
#include "cras/src/server/rust/include/rate_estimator.h"
#include "cras_audio_format.h"
#include "cras_types.h"
#include "cras_util.h"
Expand Down
2 changes: 1 addition & 1 deletion cras/src/server/cras_iodev.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "cras/common/check.h"
#include "cras/server/cras_trace.h"
#include "cras/server/platform/features/features.h"
#include "cras/server/rate_estimator/rate_estimator.h"
#include "cras/server/s2/s2.h"
#include "cras/src/common/cras_hats.h"
#include "cras/src/server/audio_thread.h"
Expand All @@ -41,7 +42,6 @@
#include "cras/src/server/dev_stream.h"
#include "cras/src/server/ewma_power.h"
#include "cras/src/server/input_data.h"
#include "cras/src/server/rust/include/rate_estimator.h"
#include "cras/src/server/softvol_curve.h"
#include "cras_audio_format.h"
#include "cras_iodev_info.h"
Expand Down
2 changes: 0 additions & 2 deletions cras/src/server/rust/.gitignore

This file was deleted.

24 changes: 1 addition & 23 deletions cras/src/server/rust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

load("@crate_index//:defs.bzl", "all_crate_deps")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_rust//rust:defs.bzl", "rust_test")
load("//:utils.bzl", "require_no_config")
load("//rules/cbindgen:rules.bzl", "cras_cbindgen")
load("//rules/rust:defs.bzl", "cras_rust_library")

cras_rust_library(
Expand All @@ -19,6 +16,7 @@ cras_rust_library(
"//cras/server/platform/features:backend",
"//cras/server/feature_tier",
"//cras/server/processor",
"//cras/server/rate_estimator",
"//cras/server/s2",
"//cras/src/dsp/rust:dsp_rust",
] + all_crate_deps(),
Expand All @@ -30,23 +28,3 @@ cc_library(
visibility = ["//visibility:public"],
deps = [":rust"],
)

rust_test(
name = "test",
crate = ":rust",
tags = [
"tsan-broken",
],
target_compatible_with = require_no_config("//:system_cras_rust_build"),
)

cras_cbindgen(
name = "rate_estimator_h",
srcs = [
"src/rate_estimator.rs",
"src/rate_estimator_bindings.rs",
],
out = "include/rate_estimator.h",
copyright_year = 2019,
extra_args = ["--with-sys-include=time.h"],
)
1 change: 1 addition & 0 deletions cras/src/server/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cras_features_backend = { workspace = true }
cras_s2 = { workspace = true }
cras_feature_tier = { workspace = true }
cras_processor = { workspace = true }
cras_rate_estimator = { workspace = true }
minijail = { workspace = true, optional = true }

[build-dependencies]
Expand Down
7 changes: 3 additions & 4 deletions cras/src/server/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

pub use cras_common::logging;
pub use cras_feature_tier;
mod rate_estimator;
pub mod rate_estimator_bindings;
pub use cras_common::fra;
pub use cras_common::logging;
pub use cras_common::pseudonymization;
pub use cras_dlc::bindings as cras_dlc_bindings;
pub use cras_feature_tier;
pub use cras_features_backend;
pub use cras_processor;
pub use cras_rate_estimator;
pub use cras_s2;
pub use dsp_rust;
pub use logging::bindings as logging_bindings;
3 changes: 3 additions & 0 deletions cras/src/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@ cc_test(
deps = [
":test_support",
"//cras/server:cras_trace",
"//cras/server/rate_estimator:cc",
"//cras/src/common",
"//cras/src/common:all_headers",
"//cras/src/server:all_headers",
Expand Down Expand Up @@ -1478,6 +1479,7 @@ cc_test(
"//cras/server:cras_trace",
"//cras/server/platform/dlc:cc",
"//cras/server/platform/features:override",
"//cras/server/rate_estimator:cc",
"//cras/server/s2:cc",
"//cras/src/common:all_headers",
"//cras/src/server:all_headers",
Expand Down Expand Up @@ -1639,6 +1641,7 @@ cc_test(
],
deps = [
":test_support",
"//cras/server/rate_estimator:cc",
"//cras/src/common:all_headers",
"//cras/src/server:all_headers",
"//cras/src/server/rust:cc",
Expand Down
2 changes: 1 addition & 1 deletion cras/src/tests/floop_iodev_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// within an `extern "C"` block. This ensures C++ code sees C linkage,
// while C code remains unaffected.
#include "cras/server/cras_trace.h"
#include "cras/server/rate_estimator/rate_estimator.h"
#include "cras/src/server/cras_iodev.h"
#include "cras/src/server/rust/include/rate_estimator.h"
extern "C" {
#include "cras/src/server/cras_floop_iodev.c"
}
Expand Down
2 changes: 1 addition & 1 deletion cras/src/tests/iodev_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdio.h>

#include "cras/include/cras_types.h"
#include "cras/server/rate_estimator/rate_estimator.h"
#include "cras/src/server/audio_thread_log.h"
#include "cras/src/server/cras_audio_area.h"
#include "cras/src/server/cras_iodev.h"
Expand All @@ -16,7 +17,6 @@
#include "cras/src/server/cras_server_metrics.h"
#include "cras/src/server/dev_stream.h"
#include "cras/src/server/input_data.h"
#include "cras/src/server/rust/include/rate_estimator.h"
#include "cras_types.h"
#include "third_party/utlist/utlist.h"

Expand Down
2 changes: 1 addition & 1 deletion cras/src/tests/rate_estimator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <gtest/gtest.h>

#include "cras/src/server/rust/include/rate_estimator.h"
#include "cras/server/rate_estimator/rate_estimator.h"

static struct timespec window = {.tv_sec = 0, .tv_nsec = 10000000};

Expand Down

0 comments on commit 2833ff1

Please sign in to comment.