Skip to content

Commit

Permalink
add device support
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Dec 4, 2021
1 parent 4d212da commit fdbb573
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
17 changes: 13 additions & 4 deletions torchaudio/csrc/ffmpeg/ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ void AVFormatContextDeleter::operator()(AVFormatContext* p) {
};

namespace {
AVFormatContext* get_format_context(const std::string& src) {
AVFormatContext* get_format_context(
const std::string& src,
const std::string& device,
AVDictionary** option) {
AVFormatContext* pFormat = NULL;
if (avformat_open_input(&pFormat, src.c_str(), NULL, NULL) < 0)
AVInputFormat* pInput =
device.empty() ? NULL : av_find_input_format(device.c_str());

if (avformat_open_input(&pFormat, src.c_str(), pInput, option) < 0)
throw std::runtime_error("Failed to open the input: " + src);
return pFormat;
}
} // namespace

AVFormatContextPtr::AVFormatContextPtr(const std::string& src)
AVFormatContextPtr::AVFormatContextPtr(
const std::string& src,
const std::string& device,
AVDictionary** option)
: Wrapper<AVFormatContext, AVFormatContextDeleter>(
get_format_context(src)) {
get_format_context(src, device, option)) {
if (avformat_find_stream_info(ptr.get(), NULL) < 0)
throw std::runtime_error("Failed to find stream information.");
}
Expand Down
7 changes: 6 additions & 1 deletion torchaudio/csrc/ffmpeg/ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include <libavfilter/avfilter.h>
#include <libavfilter/buffersink.h>
#include <libavfilter/buffersrc.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/frame.h>
#include <libavutil/imgutils.h>
#include <libavutil/log.h>
#include <libavutil/pixdesc.h>
}

Expand Down Expand Up @@ -53,7 +55,10 @@ struct AVFormatContextDeleter {

struct AVFormatContextPtr
: public Wrapper<AVFormatContext, AVFormatContextDeleter> {
AVFormatContextPtr(const std::string& src);
AVFormatContextPtr(
const std::string& src,
const std::string& device,
AVDictionary** option);
};

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit fdbb573

Please sign in to comment.