Skip to content

Commit

Permalink
Add decoder class
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Dec 7, 2021
1 parent e0280cf commit 81b7c65
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
20 changes: 20 additions & 0 deletions torchaudio/csrc/ffmpeg/decoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <torchaudio/csrc/ffmpeg/decoder.h>

namespace torchaudio {
namespace ffmpeg {

////////////////////////////////////////////////////////////////////////////////
// Decoder
////////////////////////////////////////////////////////////////////////////////
Decoder::Decoder(AVCodecParameters* pParam) : pCodecContext(pParam) {}

int Decoder::process_packet(AVPacket* pPacket) {
return avcodec_send_packet(pCodecContext, pPacket);
}

int Decoder::get_frame(AVFrame* pFrame) {
return avcodec_receive_frame(pCodecContext, pFrame);
}

} // namespace ffmpeg
} // namespace torchaudio
30 changes: 30 additions & 0 deletions torchaudio/csrc/ffmpeg/decoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <torchaudio/csrc/ffmpeg/ffmpeg.h>

namespace torchaudio {
namespace ffmpeg {

class Decoder {
AVCodecContextPtr pCodecContext;

public:
// Default constructable
Decoder(AVCodecParameters* pParam);
// Custom destructor to clean up the resources
~Decoder() = default;
// Non-copyable
Decoder(const Decoder&) = delete;
Decoder& operator=(const Decoder&) = delete;
// Movable
Decoder(Decoder&&) = default;
Decoder& operator=(Decoder&&) = default;

// Process incoming packet
int process_packet(AVPacket* pPacket);
// Fetch a decoded frame
int get_frame(AVFrame* pFrame);
};

} // namespace ffmpeg
} // namespace torchaudio

0 comments on commit 81b7c65

Please sign in to comment.