ffmpeg plugin: remove more deprecated functions.

These were all deprecated between releases 0.6 and 0.10 of ffmpeg,
except for one change (renaming of CodecID to AVCodecID) which we can
work around with a typedef. The deprecated functions were still
available in 0.11, but were removed later on after several years of
deprecation.

This makes it possible to build our plugin with any ffmpeg version
between 0.10 and 2.7, so we can now experiment with updating to 2.7 at
least for the gcc4 builds.
This commit is contained in:
Adrien Destugues 2015-08-30 16:20:40 +02:00
parent 0f7e19ce7e
commit 9e5c694668
7 changed files with 39 additions and 11 deletions

View File

@ -57,6 +57,10 @@
// Otherwise the alternative code could simply be removed from this file.
#endif
#if __GNUC__ > 2
typedef AVCodecID CodecID;
#endif
struct wave_format_ex {
uint16 format_tag;
@ -409,10 +413,10 @@ AVCodecDecoder::_NegotiateAudioOutputFormat(media_format* inOutFormat)
if (fRawDecodedAudio->opaque == NULL)
return B_NO_MEMORY;
TRACE(" bit_rate = %d, sample_rate = %d, channels = %d, init = %d, "
TRACE(" bit_rate = %d, sample_rate = %d, channels = %d, "
"output frame size: %d, count: %ld, rate: %.2f\n",
fContext->bit_rate, fContext->sample_rate, fContext->channels,
result, fOutputFrameSize, fOutputFrameCount, fOutputFrameRate);
fOutputFrameSize, fOutputFrameCount, fOutputFrameRate);
return B_OK;
}
@ -716,7 +720,7 @@ AVCodecDecoder::_DecodeNextAudioFrame()
dump_ffframe_audio(fRawDecodedAudio, "ffaudi");
#endif
TRACE_AUDIO(" frame count: %lld current: %lld\n",
TRACE_AUDIO(" frame count: %ld current: %lld\n",
fRawDecodedAudio->nb_samples, fFrame);
return B_OK;
@ -1193,7 +1197,7 @@ AVCodecDecoder::_DecodeNextVideoFrame()
fRawDecodedPicture, &gotVideoFrame, &fTempPacket);
if (encodedDataSizeInBytes < 0) {
TRACE("[v] AVCodecDecoder: ignoring error in decoding frame %lld:"
" %d\n", fFrame, len);
" %d\n", fFrame, encodedDataSizeInBytes);
// NOTE: An error from avcodec_decode_video2() is ignored by the
// FFMPEG 0.10.2 example decoding_encoding.c. Only the packet
// buffers are flushed accordingly

View File

@ -40,9 +40,9 @@ AVCodecEncoder::AVCodecEncoder(uint32 codecID, int bitRateScale)
:
Encoder(),
fBitRateScale(bitRateScale),
fCodecID((enum CodecID)codecID),
fCodecID((CodecID)codecID),
fCodec(NULL),
fOwnContext(avcodec_alloc_context()),
fOwnContext(avcodec_alloc_context3(NULL)),
fContext(fOwnContext),
fCodecInitStatus(CODEC_INIT_NEEDED),
@ -494,7 +494,7 @@ AVCodecEncoder::_OpenCodecIfNeeded()
fContext->strict_std_compliance = -2;
// Open the codec
int result = avcodec_open(fContext, fCodec);
int result = avcodec_open2(fContext, fCodec, NULL);
if (result >= 0)
fCodecInitStatus = CODEC_INIT_DONE;
else

View File

@ -17,6 +17,11 @@ extern "C" {
#include "EncoderPlugin.h"
#if __GNUC__ > 2
typedef AVCodecID CodecID;
#endif
class AVCodecEncoder : public Encoder {
public:
AVCodecEncoder(uint32 codecID,

View File

@ -53,6 +53,9 @@ static const size_t kIOBufferSize = 64 * 1024;
#define OPEN_CODEC_CONTEXT 1
#define GET_CONTEXT_DEFAULTS 0
#if __GNUC__ > 2
typedef AVCodecID CodecID;
#endif
// #pragma mark - AVFormatWriter::StreamCookie
@ -109,7 +112,8 @@ AVFormatWriter::StreamCookie::Init(media_format* format,
BAutolock _(fStreamLock);
fPacket.stream_index = fContext->nb_streams;
fStream = av_new_stream(fContext, fPacket.stream_index);
fStream = avformat_new_stream(fContext, NULL);
fStream->id = fPacket.stream_index;
if (fStream == NULL) {
TRACE(" failed to add new stream\n");
@ -200,6 +204,10 @@ AVFormatWriter::StreamCookie::Init(media_format* format,
// Now negociate the actual format with the encoder
// First check if the requested format is acceptable
AVCodec* codec = avcodec_find_encoder(fStream->codec->codec_id);
if (codec == NULL)
return B_MEDIA_BAD_FORMAT;
const enum AVSampleFormat *p = codec->sample_fmts;
for (; *p != -1; p++) {
if (*p == fStream->codec->sample_fmt)
@ -466,7 +474,7 @@ AVFormatWriter::CommitHeader()
AVCodecContext* codecContext = stream->codec;
codecContext->strict_std_compliance = -2;
AVCodec* codec = avcodec_find_encoder(codecContext->codec_id);
if (codec == NULL || avcodec_open(codecContext, codec) < 0) {
if (codec == NULL || avcodec_open2(codecContext, codec, NULL) < 0) {
TRACE(" stream[%u] - failed to open AVCodecContext\n", i);
}
TRACE(" stream[%u] time_base: (%d/%d), codec->time_base: (%d/%d)\n",

View File

@ -11,9 +11,15 @@ extern "C" {
#include "avformat.h"
}
#if __GNUC__ > 2
typedef AVCodecID CodecID;
#endif
//XXX: newer versions have it in libavformat/internal.h
typedef struct AVCodecTag {
enum CodecID id;
CodecID id;
unsigned int tag;
} AVCodecTag;

View File

@ -13,6 +13,11 @@ extern "C" {
}
#if __GNUC__ > 2
typedef AVCodecID CodecID;
#endif
struct EncoderDescription {
media_codec_info codec_info;
media_format_family format_family;

View File

@ -53,7 +53,7 @@ manage_locks(void** _lock, enum AVLockOp operation)
case AV_LOCK_CREATE:
TRACE(" AV_LOCK_CREATE\n");
*lock = new(std::nothrow) BLocker("FFmpeg lock");
if (*lock == NULL)
if (*lock == NULL)
return 1;
break;