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

Resolve some compilation warnings (#3471)

Summary:
- FFmpeg 6 deprecated attributes
- Guard CUDA specific functions not used in CPU builds

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

Differential Revision: D47402174

Pulled By: mthrok

fbshipit-source-id: 00c0719ab1849b50c0b56b03d8fb38bc7aa74538
parent a3b6bfb6
......@@ -186,7 +186,8 @@ FilterGraphOutputInfo FilterGraph::get_output_info() const {
switch (l->type) {
case AVMEDIA_TYPE_AUDIO: {
ret.sample_rate = l->sample_rate;
#if LIBAVFILTER_VERSION_MAJOR >= 8 && LIBAVFILTER_VERSION_MINOR >= 44
#if LIBAVFILTER_VERSION_MAJOR >= 9 || \
(LIBAVFILTER_VERSION_MAJOR == 8 && LIBAVFILTER_VERSION_MINOR >= 44)
ret.num_channels = l->ch_layout.nb_channels;
#else
// Before FFmpeg 5.1
......
......@@ -98,6 +98,7 @@ torch::Tensor get_image_buffer(
shape, torch::TensorOptions().dtype(dtype).layout(torch::kStrided));
}
#ifdef USE_CUDA
torch::Tensor get_image_buffer(
at::IntArrayRef shape,
torch::Device device,
......@@ -109,6 +110,7 @@ torch::Tensor get_image_buffer(
.layout(torch::kStrided)
.device(device));
}
#endif
} // namespace
......
......@@ -27,6 +27,7 @@ AVCodecContextPtr alloc_codec_context(
return AVCodecContextPtr(codec_ctx);
}
#ifdef USE_CUDA
const AVCodecHWConfig* get_cuda_config(const AVCodec* codec) {
for (int i = 0;; ++i) {
const AVCodecHWConfig* config = avcodec_get_hw_config(codec, i);
......@@ -80,6 +81,7 @@ enum AVPixelFormat get_hw_format(
TORCH_WARN("Failed to get HW surface format.");
return AV_PIX_FMT_NONE;
}
#endif
AVBufferRef* get_hw_frames_ctx(AVCodecContext* codec_ctx) {
AVBufferRef* p = av_hwframe_ctx_alloc(codec_ctx->hw_device_ctx);
......@@ -138,10 +140,12 @@ void open_codec(
av_dict_set(&opts, "threads", "1", 0);
}
#if LIBAVUTIL_VERSION_MAJOR < 58
if (!codec_ctx->channel_layout) {
codec_ctx->channel_layout =
av_get_default_channel_layout(codec_ctx->channels);
}
#endif
int ret = avcodec_open2(codec_ctx, codec_ctx->codec, &opts);
clean_up_dict(opts);
......@@ -332,7 +336,12 @@ int StreamProcessor::process_packet(AVPacket* packet) {
// This is because they might be intra-frames not in chronological
// order. In this case, we use received frames as-is in the order they
// are received.
#if LIBAVCODEC_VERSION_MAJOR >= 60
frame->pts = codec_ctx->frame_num + 1;
#else
frame->pts = codec_ctx->frame_number + 1;
#endif
} else {
frame->pts = frame->best_effort_timestamp;
}
......
......@@ -527,6 +527,7 @@ void configure_video_codec_ctx(
}
}
#ifdef USE_CUDA
void configure_hw_accel(AVCodecContext* ctx, const std::string& hw_accel) {
torch::Device device{hw_accel};
TORCH_CHECK(
......@@ -570,6 +571,7 @@ void configure_hw_accel(AVCodecContext* ctx, const std::string& hw_accel) {
"Failed to initialize CUDA frame context: ",
av_err2string(ret));
}
#endif
////////////////////////////////////////////////////////////////////////////////
// AVStream
......
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