Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Dec 29, 2021
1 parent f0ecd0c commit 76263fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
38 changes: 21 additions & 17 deletions torchaudio/csrc/ffmpeg/stream_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ namespace ffmpeg {

using KeyType = StreamProcessor::KeyType;

Sink::Sink(
AVRational input_time_base,
AVCodecParameters* codecpar,
const std::string& filter_description,
double output_time_base)
: filter(input_time_base, codecpar, filter_description),
buffer(codecpar->codec_type),
time_base(output_time_base) {}

StreamProcessor::StreamProcessor(AVCodecParameters* codecpar)
: media_type(codecpar->codec_type), decoder(codecpar) {}

Expand All @@ -24,8 +15,10 @@ StreamProcessor::StreamProcessor(AVCodecParameters* codecpar)
KeyType StreamProcessor::add_stream(
AVRational input_time_base,
AVCodecParameters* codecpar,
const std::string& filter_description,
double output_rate) {
int frames_per_chunk,
int num_chunks,
double output_rate,
std::string filter_description) {
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
case AVMEDIA_TYPE_VIDEO:
Expand All @@ -40,8 +33,10 @@ KeyType StreamProcessor::add_stream(
std::forward_as_tuple(
input_time_base,
codecpar,
filter_description,
(output_rate > 0) ? 1 / output_rate : av_q2d(input_time_base)));
frames_per_chunk,
num_chunks,
(output_rate > 0) ? 1 / output_rate : av_q2d(input_time_base),
std::move(filter_description)));
decoder_time_base = av_q2d(input_time_base);
return key;
}
Expand All @@ -53,8 +48,17 @@ void StreamProcessor::remove_stream(KeyType key) {
////////////////////////////////////////////////////////////////////////////////
// Query methods
////////////////////////////////////////////////////////////////////////////////
std::string StreamProcessor::get_filter_description(KeyType key) {
return sinks.at(key).filter.filter_description;
std::string StreamProcessor::get_filter_description(KeyType key) const {
return sinks.at(key).filter.get_description();
}

bool StreamProcessor::is_buffer_ready() const {
for (const auto& it : sinks) {
if (!it.second.is_buffer_ready()) {
return false;
}
}
return true;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -117,8 +121,8 @@ int StreamProcessor::send_frame(AVFrame* pFrame) {
////////////////////////////////////////////////////////////////////////////////
// Retrieval
////////////////////////////////////////////////////////////////////////////////
torch::Tensor StreamProcessor::get_chunk(KeyType key) {
return sinks.at(key).buffer.pop_all();
c10::optional<torch::Tensor> StreamProcessor::pop_chunk(KeyType key) {
return sinks.at(key).buffer->pop_chunk();
}

} // namespace ffmpeg
Expand Down
11 changes: 7 additions & 4 deletions torchaudio/csrc/ffmpeg/stream_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ class StreamProcessor {
KeyType add_stream(
AVRational input_time_base,
AVCodecParameters* codecpar,
const std::string& filter_description,
double output_rate);
int frames_per_chunk,
int num_chunks,
double output_rate,
std::string filter_description);

// 1. Remove the stream
void remove_stream(KeyType key);

//////////////////////////////////////////////////////////////////////////////
// Query methods
//////////////////////////////////////////////////////////////////////////////
std::string get_filter_description(KeyType key);
std::string get_filter_description(KeyType key) const;
bool is_buffer_ready() const;

//////////////////////////////////////////////////////////////////////////////
// The streaming process
Expand All @@ -75,7 +78,7 @@ class StreamProcessor {
//////////////////////////////////////////////////////////////////////////////
public:
// Get the chunk from the given filter result
torch::Tensor get_chunk(KeyType key);
c10::optional<torch::Tensor> pop_chunk(KeyType key);
};

} // namespace ffmpeg
Expand Down

0 comments on commit 76263fe

Please sign in to comment.