Commit 9e1999ae authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Refactor StreamProcessor interface (#2791)

Summary:
StreamProcessor is constructed on top of AVStream object, and attach streams defined by client code.

This commit refactor the constructor and add_stream method signature so that `add_stream`'s signature is centered around the parameters required for filter construction.

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

Reviewed By: xiaohui-zhang

Differential Revision: D40667979

Pulled By: mthrok

fbshipit-source-id: 42220832f09a7895ede3cddf969d57feeb4ef7ec
parent 17a2b93b
...@@ -7,23 +7,22 @@ namespace ffmpeg { ...@@ -7,23 +7,22 @@ namespace ffmpeg {
using KeyType = StreamProcessor::KeyType; using KeyType = StreamProcessor::KeyType;
StreamProcessor::StreamProcessor( StreamProcessor::StreamProcessor(
AVCodecParameters* codecpar, AVStream* stream,
const c10::optional<std::string>& decoder_name, const c10::optional<std::string>& decoder_name,
const c10::optional<OptionDict>& decoder_option, const c10::optional<OptionDict>& decoder_option,
const torch::Device& device) const torch::Device& device)
: decoder(codecpar, decoder_name, decoder_option, device) {} : stream(stream),
decoder(stream->codecpar, decoder_name, decoder_option, device) {}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Configurations // Configurations
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
KeyType StreamProcessor::add_stream( KeyType StreamProcessor::add_stream(
AVRational input_time_base,
AVCodecParameters* codecpar,
int frames_per_chunk, int frames_per_chunk,
int num_chunks, int num_chunks,
const c10::optional<std::string>& filter_description, const c10::optional<std::string>& filter_description,
const torch::Device& device) { const torch::Device& device) {
switch (codecpar->codec_type) { switch (stream->codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO: case AVMEDIA_TYPE_AUDIO:
case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_VIDEO:
break; break;
...@@ -35,13 +34,12 @@ KeyType StreamProcessor::add_stream( ...@@ -35,13 +34,12 @@ KeyType StreamProcessor::add_stream(
std::piecewise_construct, std::piecewise_construct,
std::forward_as_tuple(key), std::forward_as_tuple(key),
std::forward_as_tuple( std::forward_as_tuple(
input_time_base, stream->time_base,
codecpar, stream->codecpar,
frames_per_chunk, frames_per_chunk,
num_chunks, num_chunks,
filter_description, filter_description,
device)); device));
decoder_time_base = av_q2d(input_time_base);
return key; return key;
} }
......
...@@ -14,11 +14,12 @@ class StreamProcessor { ...@@ -14,11 +14,12 @@ class StreamProcessor {
using KeyType = int; using KeyType = int;
private: private:
AVFramePtr pFrame1; // Link to the corresponding stream object
AVFramePtr pFrame2; const AVStream* stream;
// Components for decoding source media // Components for decoding source media
double decoder_time_base; // for debug AVFramePtr pFrame1;
AVFramePtr pFrame2;
Decoder decoder; Decoder decoder;
KeyType current_key = 0; KeyType current_key = 0;
...@@ -26,7 +27,7 @@ class StreamProcessor { ...@@ -26,7 +27,7 @@ class StreamProcessor {
public: public:
StreamProcessor( StreamProcessor(
AVCodecParameters* codecpar, AVStream* stream,
const c10::optional<std::string>& decoder_name, const c10::optional<std::string>& decoder_name,
const c10::optional<OptionDict>& decoder_option, const c10::optional<OptionDict>& decoder_option,
const torch::Device& device); const torch::Device& device);
...@@ -48,8 +49,6 @@ class StreamProcessor { ...@@ -48,8 +49,6 @@ class StreamProcessor {
// 3. Configure a buffer. // 3. Configure a buffer.
// 4. Return filter ID. // 4. Return filter ID.
KeyType add_stream( KeyType add_stream(
AVRational input_time_base,
AVCodecParameters* codecpar,
int frames_per_chunk, int frames_per_chunk,
int num_chunks, int num_chunks,
const c10::optional<std::string>& filter_description, const c10::optional<std::string>& filter_description,
......
...@@ -251,16 +251,11 @@ void StreamReader::add_stream( ...@@ -251,16 +251,11 @@ void StreamReader::add_stream(
if (!processors[i]) { if (!processors[i]) {
processors[i] = std::make_unique<StreamProcessor>( processors[i] = std::make_unique<StreamProcessor>(
stream->codecpar, decoder, decoder_option, device); stream, decoder, decoder_option, device);
} }
stream->discard = AVDISCARD_DEFAULT; stream->discard = AVDISCARD_DEFAULT;
int key = processors[i]->add_stream( int key = processors[i]->add_stream(
stream->time_base, frames_per_chunk, num_chunks, filter_desc, device);
stream->codecpar,
frames_per_chunk,
num_chunks,
filter_desc,
device);
stream_indices.push_back(std::make_pair<>(i, key)); stream_indices.push_back(std::make_pair<>(i, key));
} }
......
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