File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -208,9 +208,12 @@ torch::Tensor AudioEncoder::encodeToTensor() {
208208}
209209
210210void AudioEncoder::encode () {
211- // TODO-ENCODING: Need to check, but consecutive calls to encode() are
212- // probably invalid. We can address this once we (re)design the public and
213- // private encoding APIs.
211+ // To be on the safe side we enforce that encode() can only be called once on
212+ // an encoder object. Whether this is actually necessary is unknown, so this
213+ // may be relaxed if needed.
214+ TORCH_CHECK (!encodeWasCalled_, " Cannot call encode() twice." );
215+ encodeWasCalled_ = true ;
216+
214217 UniqueAVFrame avFrame (av_frame_alloc ());
215218 TORCH_CHECK (avFrame != nullptr , " Couldn't allocate AVFrame." );
216219 // Default to 256 like in torchaudio
Original file line number Diff line number Diff line change @@ -49,5 +49,7 @@ class AudioEncoder {
4949
5050 // Stores the AVIOContext for the output tensor buffer.
5151 std::unique_ptr<AVIOToTensorContext> avioContextHolder_;
52+
53+ bool encodeWasCalled_ = false ;
5254};
5355} // namespace facebook::torchcodec
You can’t perform that action at this time.
0 commit comments