Commit 424059d1 authored by Philippe Gorley's avatar Philippe Gorley

refactor: remove libav-related dead code

With the bumps to FFmpeg 3.3.1 and libav 12.1, these code paths
will never be executed.

Change-Id: Ia8d7602a91896620dd6b3848dd6ed63d79fcc809
Reviewed-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 9587ef90
......@@ -51,9 +51,7 @@ extern "C" {
#include <libavdevice/avdevice.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>
#if LIBAVUTIL_VERSION_CHECK(51, 33, 0, 60, 100)
#include <libavutil/time.h>
#endif
#include <libavutil/pixdesc.h>
#include <libavutil/opt.h>
#include <libavutil/channel_layout.h>
......@@ -65,44 +63,6 @@ extern "C" {
#include "libav_utils.h"
#if !LIBAVFORMAT_VERSION_CHECK(54,20,3,59,103)
#error "Used libavformat doesn't support sdp custom_io"
#endif
#if !LIBAVUTIL_VERSION_CHECK(51, 42, 0, 74, 100) && !defined(FF_API_PIX_FMT)
#define AVPixelFormat PixelFormat
#define PIXEL_FORMAT(FMT) PIX_FMT_ ## FMT
static inline const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
{
if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
return NULL;
return &av_pix_fmt_descriptors[pix_fmt];
}
#else
#define PIXEL_FORMAT(FMT) AV_PIX_FMT_ ## FMT
#endif
#if !LIBAVCODEC_VERSION_CHECK(54, 28, 0, 59, 100)
#define avcodec_free_frame(x) av_freep(x)
#endif
// Especially for Fedora < 20 and UBUNTU < 14.10
#define USE_OLD_AVU ! LIBAVUTIL_VERSION_CHECK(52, 8, 0, 19, 100)
#if USE_OLD_AVU
#define av_frame_alloc avcodec_alloc_frame
#define av_frame_free avcodec_free_frame
#define av_frame_unref avcodec_get_frame_defaults
#define av_frame_get_buffer(x, y) avpicture_alloc((AVPicture *)(x), \
(AVPixelFormat)(x)->format, \
(x)->width, (x)->height)
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 24, 102)
#define av_free_packet av_packet_unref
#endif
#endif // __LIBAV_DEPS_H__
......@@ -97,9 +97,7 @@ init_once()
{
av_register_all();
avdevice_register_all();
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 13, 0)
avformat_network_init();
#endif
av_lockmgr_register(avcodecManageMutex);
......
......@@ -125,13 +125,8 @@ VideoFrame::setFromMemory(uint8_t* ptr, int format, int width, int height) noexc
setGeometry(format, width, height);
if (not ptr)
return;
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 24, 102)
av_image_fill_arrays(frame_->data, frame_->linesize, (uint8_t*)ptr,
(AVPixelFormat)frame_->format, width, height, 1);
#else
avpicture_fill((AVPicture*)frame_.get(), (uint8_t*)ptr,
(AVPixelFormat)frame_->format, width, height);
#endif
}
void
......@@ -160,16 +155,10 @@ VideoFrame&
VideoFrame::operator =(const VideoFrame& src)
{
reserve(src.format(), src.width(), src.height());
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 24, 102)
auto source = src.pointer();
av_image_copy(frame_->data, frame_->linesize, (const uint8_t **)source->data,
source->linesize, (AVPixelFormat)frame_->format,
frame_->width, frame_->height);
#else
av_picture_copy((AVPicture *)frame_.get(), (AVPicture *)src.pointer(),
(AVPixelFormat)frame_->format,
frame_->width, frame_->height);
#endif
return *this;
}
......@@ -178,13 +167,8 @@ VideoFrame::operator =(const VideoFrame& src)
std::size_t
videoFrameSize(int format, int width, int height)
{
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 24, 102)
return av_image_get_buffer_size((AVPixelFormat)libav_utils::libav_pixel_format(format),
width, height, 1);
#else
return avpicture_get_size((AVPixelFormat)libav_utils::libav_pixel_format(format),
width, height);
#endif
}
void
......
......@@ -145,11 +145,7 @@ int MediaDecoder::setupFromAudioData(const AudioFormat format)
inputCtx_->max_analyze_duration = MAX_ANALYZE_DURATION * AV_TIME_BASE;
RING_DBG("Finding stream info");
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 8, 0)
ret = av_find_stream_info(inputCtx_);
#else
ret = avformat_find_stream_info(inputCtx_, NULL);
#endif
RING_DBG("Finding stream info DONE");
if (ret < 0) {
......@@ -169,7 +165,7 @@ int MediaDecoder::setupFromAudioData(const AudioFormat format)
// find the first audio stream from the input
for (size_t i = 0; streamIndex_ == -1 && i < inputCtx_->nb_streams; ++i)
#if LIBAVFORMAT_VERSION_CHECK(57, 7, 2, 40, 101) && !defined(_WIN32)
#ifndef _WIN32
if (inputCtx_->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
#else
if (inputCtx_->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
......@@ -183,7 +179,7 @@ int MediaDecoder::setupFromAudioData(const AudioFormat format)
// Get a pointer to the codec context for the video stream
avStream_ = inputCtx_->streams[streamIndex_];
#if LIBAVFORMAT_VERSION_CHECK(57, 7, 2, 40, 101) && !defined(_WIN32)
#ifndef _WIN32
inputDecoder_ = avcodec_find_decoder(avStream_->codecpar->codec_id);
if (!inputDecoder_) {
RING_ERR("Unsupported codec");
......@@ -219,9 +215,7 @@ int MediaDecoder::setupFromAudioData(const AudioFormat format)
startTime_ = av_gettime();
}
#if LIBAVCODEC_VERSION_MAJOR >= 55
decoderCtx_->refcounted_frames = 1;
#endif
ret = avcodec_open2(decoderCtx_, inputDecoder_, NULL);
if (ret) {
RING_ERR("Could not open codec");
......@@ -245,11 +239,7 @@ int MediaDecoder::setupFromVideoData()
inputCtx_->max_analyze_duration = MAX_ANALYZE_DURATION * AV_TIME_BASE;
RING_DBG("Finding stream info");
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 8, 0)
ret = av_find_stream_info(inputCtx_);
#else
ret = avformat_find_stream_info(inputCtx_, NULL);
#endif
if (ret < 0) {
// workaround for this bug:
// http://patches.libav.org/patch/22541/
......@@ -267,7 +257,7 @@ int MediaDecoder::setupFromVideoData()
// find the first video stream from the input
for (size_t i = 0; streamIndex_ == -1 && i < inputCtx_->nb_streams; ++i)
#if LIBAVFORMAT_VERSION_CHECK(57, 7, 2, 40, 101) && !defined(_WIN32)
#ifndef _WIN32
if (inputCtx_->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
#else
if (inputCtx_->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
......@@ -281,7 +271,7 @@ int MediaDecoder::setupFromVideoData()
// Get a pointer to the codec context for the video stream
avStream_ = inputCtx_->streams[streamIndex_];
#if LIBAVFORMAT_VERSION_CHECK(57, 7, 2, 40, 101) && !defined(_WIN32)
#ifndef _WIN32
inputDecoder_ = video::findDecoder(avStream_->codecpar->codec_id);
if (!inputDecoder_) {
RING_ERR("Unsupported codec");
......@@ -322,14 +312,8 @@ int MediaDecoder::setupFromVideoData()
startTime_ = av_gettime();
}
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 6, 0)
ret = avcodec_open(decoderCtx_, inputDecoder_);
#else
# if LIBAVCODEC_VERSION_MAJOR >= 55
decoderCtx_->refcounted_frames = 1;
# endif
ret = avcodec_open2(decoderCtx_, inputDecoder_, NULL);
#endif
if (ret) {
RING_ERR("Could not open codec");
return -1;
......@@ -363,7 +347,6 @@ MediaDecoder::decode(VideoFrame& result)
auto frame = result.pointer();
int frameFinished = 0;
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 48, 101)
ret = avcodec_send_packet(decoderCtx_, &inpacket);
if (ret < 0) {
#ifdef RING_ACCEL
......@@ -382,17 +365,6 @@ MediaDecoder::decode(VideoFrame& result)
}
if (ret >= 0)
frameFinished = 1;
#else
ret = avcodec_decode_video2(decoderCtx_, frame,
&frameFinished, &inpacket);
if (ret <= 0) {
#ifdef RING_ACCEL
if (accel_ && accel_->hasFailed())
return Status::RestartRequired;
#endif
return Status::DecodeError;
}
#endif
av_packet_unref(&inpacket);
......@@ -406,13 +378,8 @@ MediaDecoder::decode(VideoFrame& result)
return Status::RestartRequired;
}
#endif // RING_ACCEL
#if LIBAVUTIL_VERSION_CHECK(55, 20, 0, 34, 100)
if (emulateRate_ and frame->pts != AV_NOPTS_VALUE) {
auto frame_time = getTimeBase()*(frame->pts - avStream_->start_time);
#else
if (emulateRate_ and frame->pkt_pts != AV_NOPTS_VALUE) {
auto frame_time = getTimeBase()*(frame->pkt_pts - avStream_->start_time);
#endif
auto target = startTime_ + static_cast<std::int64_t>(frame_time.real() * 1e6);
auto now = av_gettime();
if (target > now) {
......@@ -453,7 +420,6 @@ MediaDecoder::decode(const AudioFrame& decodedFrame)
}
int frameFinished = 0;
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 48, 101)
ret = avcodec_send_packet(decoderCtx_, &inpacket);
if (ret < 0)
return ret == AVERROR_EOF ? Status::Success : Status::DecodeError;
......@@ -463,24 +429,11 @@ MediaDecoder::decode(const AudioFrame& decodedFrame)
return Status::DecodeError;
if (ret >= 0)
frameFinished = 1;
#else
ret = avcodec_decode_audio4(decoderCtx_, frame,
&frameFinished, &inpacket);
av_packet_unref(&inpacket);
if (ret <= 0)
return Status::DecodeError;
#endif
if (frameFinished) {
av_packet_unref(&inpacket);
#if LIBAVUTIL_VERSION_CHECK(55, 20, 0, 34, 100)
if (emulateRate_ and frame->pts != AV_NOPTS_VALUE) {
auto frame_time = getTimeBase()*(frame->pts - avStream_->start_time);
#else
if (emulateRate_ and frame->pkt_pts != AV_NOPTS_VALUE) {
auto frame_time = getTimeBase()*(frame->pkt_pts - avStream_->start_time);
#endif
auto target = startTime_ + static_cast<std::int64_t>(frame_time.real() * 1e6);
auto now = av_gettime();
if (target > now) {
......@@ -502,7 +455,6 @@ MediaDecoder::flush(VideoFrame& result)
int frameFinished = 0;
int ret = 0;
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 48, 101)
ret = avcodec_send_packet(decoderCtx_, &inpacket);
if (ret < 0)
return ret == AVERROR_EOF ? Status::Success : Status::DecodeError;
......@@ -512,14 +464,6 @@ MediaDecoder::flush(VideoFrame& result)
return Status::DecodeError;
if (ret >= 0)
frameFinished = 1;
#else
ret = avcodec_decode_video2(decoderCtx_, result.pointer(),
&frameFinished, &inpacket);
av_packet_unref(&inpacket);
if (ret <= 0)
return Status::DecodeError;
#endif
if (frameFinished) {
av_packet_unref(&inpacket);
......
......@@ -211,24 +211,16 @@ MediaEncoder::openOutput(const char *filename,
}
int ret;
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 6, 0)
ret = avcodec_open(encoderCtx_, outputEncoder_);
#else
ret = avcodec_open2(encoderCtx_, outputEncoder_, NULL);
#endif
if (ret)
throw MediaEncoderException("Could not open encoder");
// add video stream to outputformat context
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 8, 0)
stream_ = av_new_stream(outputCtx_, 0);
#else
stream_ = avformat_new_stream(outputCtx_, 0);
#endif
if (!stream_)
throw MediaEncoderException("Could not allocate stream");
#if LIBAVFORMAT_VERSION_CHECK(57, 7, 2, 40, 101) && !defined(_WIN32)
#ifndef _WIN32
auto par = std::unique_ptr<AVCodecParameters>(new AVCodecParameters());
avcodec_parameters_from_context(par.get(), encoderCtx_);
stream_->codecpar = par.release();
......@@ -245,11 +237,6 @@ MediaEncoder::openOutput(const char *filename,
if (scaledFrameBufferSize_ <= FF_MIN_BUFFER_SIZE)
throw MediaEncoderException("buffer too small");
#if (LIBAVCODEC_VERSION_MAJOR < 54)
encoderBufferSize_ = scaledFrameBufferSize_; // seems to be ok
encoderBuffer_.reserve(encoderBufferSize_);
#endif
scaledFrameBuffer_.reserve(scaledFrameBufferSize_);
scaledFrame_.setFromMemory(scaledFrameBuffer_.data(), format, width, height);
}
......@@ -307,11 +294,7 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe,
frame->pts = frame_number;
if (is_keyframe) {
#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(53, 20, 0)
frame->pict_type = AV_PICTURE_TYPE_I;
#else
frame->pict_type = FF_I_TYPE;
#endif
} else {
/* FIXME: Should be AV_PICTURE_TYPE_NONE for newer libavutil */
frame->pict_type = (AVPictureType) 0;
......@@ -322,7 +305,6 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe,
av_init_packet(&pkt);
int ret = 0;
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 48, 101)
ret = avcodec_send_frame(encoderCtx_, frame);
if (ret < 0)
return -1;
......@@ -352,63 +334,6 @@ MediaEncoder::encode(VideoFrame& input, bool is_keyframe,
break;
}
}
#elif LIBAVCODEC_VERSION_MAJOR >= 54
int got_packet;
ret = avcodec_encode_video2(encoderCtx_, &pkt, frame, &got_packet);
if (ret < 0) {
print_averror("avcodec_encode_video2", ret);
av_free_packet(&pkt);
return ret;
}
if (pkt.size and got_packet) {
if (pkt.pts != AV_NOPTS_VALUE)
pkt.pts = av_rescale_q(pkt.pts, encoderCtx_->time_base,
stream_->time_base);
if (pkt.dts != AV_NOPTS_VALUE)
pkt.dts = av_rescale_q(pkt.dts, encoderCtx_->time_base,
stream_->time_base);
pkt.stream_index = stream_->index;
// write the compressed frame
ret = av_write_frame(outputCtx_, &pkt);
if (ret < 0)
print_averror("av_write_frame", ret);
}
#else
ret = avcodec_encode_video(encoderCtx_, encoderBuffer_.data(),
encoderBufferSize_, frame);
if (ret < 0) {
print_averror("avcodec_encode_video", ret);
av_free_packet(&pkt);
return ret;
}
pkt.data = encoderBuffer_.data();
pkt.size = ret;
// rescale pts from encoded video framerate to rtp clock rate
if (encoderCtx_->coded_frame->pts != static_cast<int64_t>(AV_NOPTS_VALUE)) {
pkt.pts = av_rescale_q(encoderCtx_->coded_frame->pts,
encoderCtx_->time_base, stream_->time_base);
} else {
pkt.pts = 0;
}
// is it a key frame?
if (encoderCtx_->coded_frame->key_frame)
pkt.flags |= AV_PKT_FLAG_KEY;
pkt.stream_index = stream_->index;
// write the compressed frame
ret = av_write_frame(outputCtx_, &pkt);
if (ret < 0)
print_averror("av_write_frame", ret);
#endif // LIBAVCODEC_VERSION_MAJOR >= 54
av_free_packet(&pkt);
......@@ -486,7 +411,6 @@ int MediaEncoder::encode_audio(const AudioBuffer &buffer)
pkt.size = 0;
int ret = 0;
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 48, 101)
ret = avcodec_send_frame(encoderCtx_, frame);
if (ret < 0)
return -1;
......@@ -516,32 +440,6 @@ int MediaEncoder::encode_audio(const AudioBuffer &buffer)
break;
}
}
#else
int got_packet;
ret = avcodec_encode_audio2(encoderCtx_, &pkt, frame, &got_packet);
if (ret < 0) {
print_averror("avcodec_encode_audio2", ret);
av_free_packet(&pkt);
av_frame_free(&frame);
return ret;
}
if (pkt.size and got_packet) {
if (pkt.pts != AV_NOPTS_VALUE)
pkt.pts = av_rescale_q(pkt.pts, encoderCtx_->time_base,
stream_->time_base);
if (pkt.dts != AV_NOPTS_VALUE)
pkt.dts = av_rescale_q(pkt.dts, encoderCtx_->time_base,
stream_->time_base);
pkt.stream_index = stream_->index;
// write the compressed frame
ret = av_write_frame(outputCtx_, &pkt);
if (ret < 0)
print_averror("av_write_frame", ret);
}
#endif
av_free_packet(&pkt);
av_frame_free(&frame);
......@@ -557,7 +455,6 @@ int MediaEncoder::flush()
av_init_packet(&pkt);
int ret = 0;
#if LIBAVCODEC_VERSION_CHECK(57, 25, 0, 48, 101)
ret = avcodec_send_frame(encoderCtx_, nullptr);
if (ret < 0)
return -1;
......@@ -587,40 +484,6 @@ int MediaEncoder::flush()
break;
}
}
#elif (LIBAVCODEC_VERSION_MAJOR >= 54)
int got_packet;
ret = avcodec_encode_video2(encoderCtx_, &pkt, NULL, &got_packet);
if (ret != 0) {
RING_ERR("avcodec_encode_video failed");
av_free_packet(&pkt);
return -1;
}
if (pkt.size and got_packet) {
// write the compressed frame
ret = av_write_frame(outputCtx_, &pkt);
if (ret < 0)
RING_ERR("write_frame failed");
}
#else
ret = avcodec_encode_video(encoderCtx_, encoderBuffer_.data(),
encoderBufferSize_, NULL);
if (ret < 0) {
RING_ERR("avcodec_encode_video failed");
av_free_packet(&pkt);
return ret;
}
pkt.data = encoderBuffer_.data();
pkt.size = ret;
// write the compressed frame
ret = av_write_frame(outputCtx_, &pkt);
if (ret < 0)
RING_ERR("write_frame failed");
#endif
av_free_packet(&pkt);
return ret;
......@@ -630,7 +493,7 @@ std::string
MediaEncoder::print_sdp()
{
/* theora sdp can be huge */
#if LIBAVFORMAT_VERSION_CHECK(57, 7, 2, 40, 101) && !defined(_WIN32)
#ifndef _WIN32
const auto sdp_size = outputCtx_->streams[0]->codecpar->extradata_size + 2048;
#else
const auto sdp_size = outputCtx_->streams[0]->codec->extradata_size + 2048;
......@@ -653,13 +516,7 @@ MediaEncoder::print_sdp()
void MediaEncoder::prepareEncoderContext(bool is_video)
{
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 12, 0)
encoderCtx_ = avcodec_alloc_context();
avcodec_get_context_defaults(encoderCtx_);
(void) outputEncoder_;
#else
encoderCtx_ = avcodec_alloc_context3(outputEncoder_);
#endif
auto encoderName = encoderCtx_->av_class->item_name ?
encoderCtx_->av_class->item_name(encoderCtx_) : nullptr;
......
......@@ -110,10 +110,6 @@ private:
std::vector<uint8_t> scaledFrameBuffer_;
int scaledFrameBufferSize_ = 0;
int streamIndex_ = -1;
#if defined(LIBAVCODEC_VERSION_MAJOR) && (LIBAVCODEC_VERSION_MAJOR < 54)
std::vector<uint8_t> encoderBuffer_;
int encoderBufferSize_ = 0;
#endif
bool is_muted = false;
protected:
......
......@@ -124,11 +124,7 @@ VideoScaler::scale_and_pad(const VideoFrame& input, VideoFrame& output,
x_shift = -((-x_shift) >> out_desc->log2_chroma_w);
y_shift = -((-y_shift) >> out_desc->log2_chroma_h);
}
#if LIBAVUTIL_VERSION_CHECK(55, 20, 0, 17, 103)
auto x_step = out_desc->comp[i].step;
#else
auto x_step = out_desc->comp[i].step_minus1 + 1;
#endif
tmp_data_[i] = output_frame->data[i] + y_shift * output_frame->linesize[i] + x_shift * x_step;
}
......
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