Skip to content

Commit

Permalink
[audio] cleanup vorbis file after usage (#1249)
Browse files Browse the repository at this point in the history
* [audio] cleanup vorbis file after usage

* move the file cleanup to destructor
  • Loading branch information
kvignesh1420 authored Dec 27, 2020
1 parent c409778 commit 1c90427
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tensorflow_io/core/kernels/audio_video_ogg_kernels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ static ov_callbacks OggVorbisCallbacks = {
class OggVorbisReadableResource : public AudioReadableResourceBase {
public:
OggVorbisReadableResource(Env* env) : env_(env) {}
~OggVorbisReadableResource() {}
~OggVorbisReadableResource() {
// Cleanup the vorbis file
ov_clear(&ogg_vorbis_file_);
}

Status Init(const string& filename, const void* optional_memory,
const size_t optional_length) override {
Expand Down Expand Up @@ -142,8 +145,8 @@ class OggVorbisReadableResource : public AudioReadableResourceBase {

long samples_read = 0;
long samples_to_read = value->shape().dim_size(0);
float** buffer;
while (samples_read < samples_to_read) {
float** buffer;
int bitstream = 0;
long chunk = ov_read_float(&ogg_vorbis_file_, &buffer,
samples_to_read - samples_read, &bitstream);
Expand All @@ -160,6 +163,7 @@ class OggVorbisReadableResource : public AudioReadableResourceBase {
}
samples_read += chunk;
}

return Status::OK();
}
string DebugString() const override { return "OggVorbisReadableResource"; }
Expand Down

0 comments on commit 1c90427

Please sign in to comment.