Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some deprecated warnings #315

Merged
merged 5 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/AvTranscoder/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ Libraries getLibraries()
std::vector<std::string> getInputExtensions()
{
std::vector<std::string> extensions;
AVInputFormat* iFormat = NULL;
const AVInputFormat* iFormat = NULL;
void *iFormatOpaque = NULL;

while((iFormat = av_iformat_next(iFormat)))
while((iFormat = av_demuxer_iterate(&iFormatOpaque)))
{
if(iFormat->extensions != NULL)
{
Expand Down Expand Up @@ -143,9 +144,10 @@ std::vector<std::string> getInputExtensions()
std::vector<std::string> getOutputExtensions()
{
std::vector<std::string> extensions;
AVOutputFormat* oFormat = NULL;
const AVOutputFormat* oFormat = NULL;
void *oFormatOpaque = NULL;

while((oFormat = av_oformat_next(oFormat)))
while((oFormat = av_muxer_iterate(&oFormatOpaque)))
{
if(oFormat->extensions != NULL)
{
Expand Down
2 changes: 2 additions & 0 deletions src/AvTranscoder/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ namespace avtranscoder

void preloadCodecsAndFormats()
{
#if LIBAVFILTER_VERSION_MAJOR < 7
av_register_all();
avfilter_register_all();
#endif
}

std::string getDescriptionFromErrorCode(const int code)
Expand Down
8 changes: 5 additions & 3 deletions src/AvTranscoder/data/coded/CodedData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CodedData& CodedData::operator=(const CodedData& other)

CodedData::~CodedData()
{
av_free_packet(&_packet);
av_packet_unref(&_packet);
}

void CodedData::resize(const size_t newSize)
Expand Down Expand Up @@ -75,7 +75,7 @@ void CodedData::refData(CodedData& frame)

void CodedData::clear()
{
av_free_packet(&_packet);
av_packet_unref(&_packet);
initAVPacket();
}

Expand All @@ -94,7 +94,9 @@ void CodedData::initAVPacket()

void CodedData::copyAVPacket(const AVPacket& avPacket)
{
#if AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(54, 56, 0)
#if AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVCODEC_VERSION_MAJOR > 57
av_packet_ref(&_packet, &avPacket);
#elif AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(54, 56, 0)
// Need const_cast<AVCodec*> for libav versions from 54.56. to 55.56.
av_copy_packet(&_packet, const_cast<AVPacket*>(&avPacket));
#else
Expand Down
12 changes: 6 additions & 6 deletions src/AvTranscoder/data/decoded/AudioFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ AudioFrame::AudioFrame(const AudioFrameDesc& desc, const bool forceDataAllocatio
, _desc(desc)
{
// Set Frame properties
av_frame_set_sample_rate(_frame, desc._sampleRate);
av_frame_set_channels(_frame, desc._nbChannels);
av_frame_set_channel_layout(_frame, av_get_default_channel_layout(desc._nbChannels));
_frame->sample_rate = desc._sampleRate;
_frame->channels = desc._nbChannels;
_frame->channel_layout = av_get_default_channel_layout(desc._nbChannels);
_frame->format = desc._sampleFormat;
_frame->nb_samples = getDefaultNbSamples();

Expand Down Expand Up @@ -102,9 +102,9 @@ void AudioFrame::allocateData()
LOG_WARN("The AudioFrame seems to already have allocated data. This could lead to memory leaks.")

// Set Frame properties
av_frame_set_sample_rate(_frame, _desc._sampleRate);
av_frame_set_channels(_frame, _desc._nbChannels);
av_frame_set_channel_layout(_frame, av_get_default_channel_layout(_desc._nbChannels));
_frame->sample_rate = _desc._sampleRate;
_frame->channels = _desc._nbChannels;
_frame->channel_layout = av_get_default_channel_layout(_desc._nbChannels);
_frame->format = _desc._sampleFormat;
if(_frame->nb_samples == 0)
_frame->nb_samples = getDefaultNbSamples();
Expand Down
6 changes: 3 additions & 3 deletions src/AvTranscoder/data/decoded/AudioFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class AvExport AudioFrame : public IFrame
void freeData();
size_t getDataSize() const;

size_t getSampleRate() const { return av_frame_get_sample_rate(_frame); }
size_t getNbChannels() const { return av_frame_get_channels(_frame); }
size_t getChannelLayout() const { return av_frame_get_channel_layout(_frame); }
size_t getSampleRate() const { return _frame->sample_rate; }
size_t getNbChannels() const { return _frame->channels; }
size_t getChannelLayout() const { return _frame->channel_layout; }
std::string getChannelLayoutDesc() const; ///< Get a description of a channel layout (example: '5.1').
AVSampleFormat getSampleFormat() const { return static_cast<AVSampleFormat>(_frame->format); }
size_t getBytesPerSample() const; ///< 0 if unknown sample format
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/data/decoded/IFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void IFrame::assignValue(const unsigned char value)

// Create the buffer
const int bufferSize = getDataSize();
unsigned char* dataBuffer = static_cast<unsigned char*>(malloc(bufferSize * sizeof(unsigned char)));
unsigned char* dataBuffer = static_cast<unsigned char*>(av_malloc(bufferSize * sizeof(unsigned char)));
memset(dataBuffer, value, bufferSize);

// Fill the frame
Expand Down
10 changes: 5 additions & 5 deletions src/AvTranscoder/data/decoded/VideoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/pixdesc.h>
#include <libavutil/imgutils.h>
}

#include <stdexcept>
Expand Down Expand Up @@ -75,7 +76,7 @@ size_t VideoFrame::getDataSize() const
return 0;
}

const size_t size = avpicture_get_size(getPixelFormat(), getWidth(), getHeight());
const size_t size = av_image_get_buffer_size(getPixelFormat(), getWidth(), getHeight(), 1);
if(size == 0)
throw std::runtime_error("Unable to determine image buffer size: " + getDescriptionFromErrorCode(size));
return size;
Expand All @@ -92,7 +93,7 @@ void VideoFrame::allocateData()
_frame->format = _desc._pixelFormat;

// Allocate data
const int ret = avpicture_alloc(reinterpret_cast<AVPicture*>(_frame), _desc._pixelFormat, _desc._width, _desc._height);
const int ret = av_image_alloc(_frame->data, _frame->linesize, _desc._width, _desc._height, _desc._pixelFormat, 1);
if(ret < 0)
{
const std::string formatName = getPixelFormatName(_desc._pixelFormat);
Expand All @@ -109,14 +110,13 @@ void VideoFrame::allocateData()

void VideoFrame::freeData()
{
avpicture_free(reinterpret_cast<AVPicture*>(_frame));
av_freep(&_frame->data[0]);
_dataAllocated = false;
}

void VideoFrame::assignBuffer(const unsigned char* ptrValue)
{
const int ret =
avpicture_fill(reinterpret_cast<AVPicture*>(_frame), ptrValue, getPixelFormat(), getWidth(), getHeight());
const int ret = av_image_fill_arrays(_frame->data, _frame->linesize, ptrValue, getPixelFormat(), getWidth(), getHeight(), 1);
if(ret < 0)
{
std::stringstream msg;
Expand Down
9 changes: 5 additions & 4 deletions src/AvTranscoder/encoder/AudioEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,18 @@ bool AudioEncoder::encodeFrame(const IFrame& sourceFrame, CodedData& codedFrame)
AVCodecContext& avCodecContext = _codec.getAVCodecContext();

AVPacket& packet = codedFrame.getAVPacket();
if((avCodecContext.coded_frame) && (avCodecContext.coded_frame->pts != (int)AV_NOPTS_VALUE))
const AVFrame& srcAvFrame = sourceFrame.getAVFrame();
if(srcAvFrame.pts != (int)AV_NOPTS_VALUE)
{
packet.pts = avCodecContext.coded_frame->pts;
packet.pts = srcAvFrame.pts;
}

if(avCodecContext.coded_frame && avCodecContext.coded_frame->key_frame)
if(srcAvFrame.key_frame)
{
packet.flags |= AV_PKT_FLAG_KEY;
}

return encode(&sourceFrame.getAVFrame(), packet);
return encode(&srcAvFrame, packet);
}

bool AudioEncoder::encodeFrame(CodedData& codedFrame)
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/encoder/AudioEncoder.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _AV_TRANSCODER_ENCODER_AUDIO_ENCODER_HPP_
#define _AV_TRANSCODER_ENCODER_AUDIO_ENCODER_HPP_

#include "IEncoder.hpp"
#include <AvTranscoder/encoder/IEncoder.hpp>
#include <AvTranscoder/codec/AudioCodec.hpp>
#include <AvTranscoder/profile/ProfileLoader.hpp>

Expand Down
9 changes: 5 additions & 4 deletions src/AvTranscoder/encoder/VideoEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,18 @@ bool VideoEncoder::encodeFrame(const IFrame& sourceFrame, CodedData& codedFrame)
AVCodecContext& avCodecContext = _codec.getAVCodecContext();

AVPacket& packet = codedFrame.getAVPacket();
if((avCodecContext.coded_frame) && (avCodecContext.coded_frame->pts != (int)AV_NOPTS_VALUE))
const AVFrame& srcAvFrame = sourceFrame.getAVFrame();
if(srcAvFrame.pts != (int)AV_NOPTS_VALUE)
{
packet.pts = avCodecContext.coded_frame->pts;
packet.pts = srcAvFrame.pts;
}

if(avCodecContext.coded_frame && avCodecContext.coded_frame->key_frame)
if(srcAvFrame.key_frame)
{
packet.flags |= AV_PKT_FLAG_KEY;
}

return encode(&sourceFrame.getAVFrame(), packet);
return encode(&srcAvFrame, packet);
}

bool VideoEncoder::encodeFrame(CodedData& codedFrame)
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/encoder/VideoEncoder.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _AV_TRANSCODER_ENCODER_VIDEO_ENCODER_HPP_
#define _AV_TRANSCODER_ENCODER_VIDEO_ENCODER_HPP_

#include "IEncoder.hpp"
#include <AvTranscoder/encoder/IEncoder.hpp>
#include <AvTranscoder/codec/VideoCodec.hpp>
#include <AvTranscoder/profile/ProfileLoader.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/properties/DataProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void DataProperties::detectAncillaryData()
detection = true;
}

av_free_packet(&pkt);
av_packet_unref(&pkt);

if(detection)
break;
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/properties/PixelProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ size_t PixelProperties::getMaxNbBitsInChannels() const
size_t maxNbBitsInChannels = 0;
for(unsigned int channelIndex = 0; channelIndex < _pixelDesc->nb_components; ++channelIndex)
{
const size_t nbBits = _pixelDesc->comp[channelIndex].depth_minus1 + 1;
const size_t nbBits = _pixelDesc->comp[channelIndex].depth;
if(nbBits > maxNbBitsInChannels)
maxNbBitsInChannels = nbBits;
}
Expand Down Expand Up @@ -227,7 +227,7 @@ std::vector<Channel> PixelProperties::getChannels() const
Channel c;
c.id = channel;
c.chromaHeight = (size_t)_pixelDesc->comp[channel].plane;
c.bitStep = (size_t)_pixelDesc->comp[channel].step_minus1;
c.bitStep = (size_t)_pixelDesc->comp[channel].step - 1;
channels.push_back(c);
}
return channels;
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/properties/VideoProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ size_t VideoProperties::analyseGopStructure(IProgress& progress)
AVFrame& avFrame = frame.getAVFrame();

_gopStructure.push_back(
std::make_pair(av_get_picture_type_char(avFrame.pict_type), av_frame_get_pkt_size(&avFrame)));
std::make_pair(av_get_picture_type_char(avFrame.pict_type), avFrame.pkt_size));
_isInterlaced = avFrame.interlaced_frame;
_isTopFieldFirst = avFrame.top_field_first;
if(avFrame.pict_type == AV_PICTURE_TYPE_I)
Expand Down