Commit 34e1d24f authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Add decoder class (#2042)

Summary:
Part of https://github.com/pytorch/audio/issues/1986. Splitting the PR for easier review.

Add `Decoder` class that manages `AVCodecContext` resource and process input `AVPacket`.
For the overall architecture, see https://github.com/mthrok/audio/blob/ffmpeg/torchaudio/csrc/ffmpeg/README.md.

Note: Without a change to build process, the code added here won't be compiled. The build process will be updated later.
Needs to be imported after https://github.com/pytorch/audio/issues/2041.

Pull Request resolved: https://github.com/pytorch/audio/pull/2042

Reviewed By: carolineechen

Differential Revision: D32933294

Pulled By: mthrok

fbshipit-source-id: e443debadb44d491462fb641cd5b7b20c413b5b9
parent e0280cf5
#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
#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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment