Skip to content

Commit d49d72c

Browse files
authored
Use constant refs for passing samples into encoder (#712)
1 parent 0f22b2b commit d49d72c

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace facebook::torchcodec {
88

99
namespace {
1010

11-
torch::Tensor validateSamples(torch::Tensor samples) {
11+
torch::Tensor validateSamples(const torch::Tensor& samples) {
1212
TORCH_CHECK(
1313
samples.dtype() == torch::kFloat32,
1414
"samples must have float32 dtype, got ",
@@ -101,7 +101,7 @@ AVSampleFormat findBestOutputSampleFormat(const AVCodec& avCodec) {
101101
AudioEncoder::~AudioEncoder() {}
102102

103103
AudioEncoder::AudioEncoder(
104-
const torch::Tensor samples,
104+
const torch::Tensor& samples,
105105
int sampleRate,
106106
std::string_view fileName,
107107
const AudioStreamOptions& audioStreamOptions)
@@ -132,7 +132,7 @@ AudioEncoder::AudioEncoder(
132132
}
133133

134134
AudioEncoder::AudioEncoder(
135-
const torch::Tensor samples,
135+
const torch::Tensor& samples,
136136
int sampleRate,
137137
std::string_view formatName,
138138
std::unique_ptr<AVIOToTensorContext> avioContextHolder,

src/torchcodec/_core/Encoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AudioEncoder {
1515
// Passing 44_100 could result in output being 44000 if only 44000 is
1616
// supported.
1717
AudioEncoder(
18-
const torch::Tensor samples,
18+
const torch::Tensor& samples,
1919
// TODO-ENCODING: update this comment when we support an output sample
2020
// rate. This will become the input sample rate.
2121
// The *output* sample rate. We can't really decide for the user what it
@@ -26,7 +26,7 @@ class AudioEncoder {
2626
std::string_view fileName,
2727
const AudioStreamOptions& audioStreamOptions);
2828
AudioEncoder(
29-
const torch::Tensor samples,
29+
const torch::Tensor& samples,
3030
int sampleRate,
3131
std::string_view formatName,
3232
std::unique_ptr<AVIOToTensorContext> avioContextHolder,

src/torchcodec/_core/custom_ops.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ OpsAudioFramesOutput get_frames_by_pts_in_range_audio(
388388
}
389389

390390
void encode_audio_to_file(
391-
const at::Tensor samples,
391+
const at::Tensor& samples,
392392
int64_t sample_rate,
393393
std::string_view file_name,
394394
std::optional<int64_t> bit_rate = std::nullopt,
@@ -404,7 +404,7 @@ void encode_audio_to_file(
404404
}
405405

406406
at::Tensor encode_audio_to_tensor(
407-
const at::Tensor samples,
407+
const at::Tensor& samples,
408408
int64_t sample_rate,
409409
std::string_view format,
410410
std::optional<int64_t> bit_rate = std::nullopt,

0 commit comments

Comments
 (0)