[haiku-commits] haiku: hrev49603 - src/add-ons/media/plugins/ffmpeg

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 30 Aug 2015 16:55:27 +0200 (CEST)

hrev49603 adds 2 changesets to branch 'master'
old head: cccf804d9691b645621f923102d0d22295f29744
new head: 9e5c694668556b60e49a49e6708bfb550fc6ce1b
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=9e5c69466855+%5Ecccf804d9691

----------------------------------------------------------------------------

0f7e19ce7ec4: ffmpeg plugin: add support for MOD and other "tracked music"

* ffmpeg can handle these through ModPlug
* By default, ffmpoeg will not try these formats because the way to
detect them are a bit unsafe (4 bytes at a particular offset in the file
serve as an identifier). So, hint the sniffing by giving it a filename
of ".mod" to get modplug to be used. This does not affect sniffing in
the regular way for other formats.
* Add some common tracked music formats to the muxer table.
* Fix some tracing to use current (as of ffmpeg 0.10) function names and
because some variables were renamed.

9e5c69466855: 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.

[ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

9 files changed, 97 insertions(+), 13 deletions(-)
.../media/plugins/ffmpeg/AVCodecDecoder.cpp | 12 +++--
.../media/plugins/ffmpeg/AVCodecEncoder.cpp | 6 +--
.../media/plugins/ffmpeg/AVCodecEncoder.h | 5 ++
.../media/plugins/ffmpeg/AVFormatReader.cpp | 4 +-
.../media/plugins/ffmpeg/AVFormatWriter.cpp | 12 ++++-
src/add-ons/media/plugins/ffmpeg/CodecTable.cpp | 8 ++-
src/add-ons/media/plugins/ffmpeg/EncoderTable.h | 5 ++
.../media/plugins/ffmpeg/FFmpegPlugin.cpp | 2 +-
src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp | 56 ++++++++++++++++++++

############################################################################

Commit: 0f7e19ce7ec4dfe4d0a4e0b21eb22c4392637568
URL: http://cgit.haiku-os.org/haiku/commit/?id=0f7e19ce7ec4
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Aug 30 12:53:47 2015 UTC

ffmpeg plugin: add support for MOD and other "tracked music"

* ffmpeg can handle these through ModPlug
* By default, ffmpoeg will not try these formats because the way to
detect them are a bit unsafe (4 bytes at a particular offset in the file
serve as an identifier). So, hint the sniffing by giving it a filename
of ".mod" to get modplug to be used. This does not affect sniffing in
the regular way for other formats.
* Add some common tracked music formats to the muxer table.
* Fix some tracing to use current (as of ffmpeg 0.10) function names and
because some variables were renamed.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
index 742976f..5da841c 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
@@ -257,7 +257,7 @@ StreamBase::Open()
fContext->pb = fIOContext;

// Allocate our context and probe the input format
- if (avformat_open_input(&fContext, "", NULL, NULL) < 0) {
+ if (avformat_open_input(&fContext, ".mod", NULL, NULL) < 0) {
TRACE("StreamBase::Open() - avformat_open_input() failed!\n");
// avformat_open_input() frees the context in case of failure
fContext = NULL;
@@ -1505,7 +1505,7 @@ AVFormatReader::Sniff(int32* _streamCount)
streamDeleter.Detach();

#ifdef TRACE_AVFORMAT_READER
- dump_format(const_cast<AVFormatContext*>(stream->Context()), 0, "", 0);
+ av_dump_format(const_cast<AVFormatContext*>(stream->Context()), 0, "",
0);
#endif

if (_streamCount != NULL)
diff --git a/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp
b/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp
index 2856694..ed22c4e 100644
--- a/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp
@@ -318,6 +318,62 @@ const media_file_format gMuxerTable[] = {
"webm",
{ 0 }
},
+ {
+ media_file_format::B_READABLE
+ | media_file_format::B_KNOWS_RAW_AUDIO
+ | media_file_format::B_KNOWS_ENCODED_AUDIO,
+ { 0 },
+ B_MISC_FORMAT_FAMILY,
+ 100,
+ { 0 },
+ "audio/xm",
+ "Fast Tracker eXtended Module",
+ "xm",
+ "xm",
+ { 0 }
+ },
+ {
+ media_file_format::B_READABLE
+ | media_file_format::B_KNOWS_RAW_AUDIO
+ | media_file_format::B_KNOWS_ENCODED_AUDIO,
+ { 0 },
+ B_MISC_FORMAT_FAMILY,
+ 100,
+ { 0 },
+ "audio/s3m",
+ "Scream Tracker 3",
+ "s3m",
+ "s3m",
+ { 0 }
+ },
+ {
+ media_file_format::B_READABLE
+ | media_file_format::B_KNOWS_RAW_AUDIO
+ | media_file_format::B_KNOWS_ENCODED_AUDIO,
+ { 0 },
+ B_MISC_FORMAT_FAMILY,
+ 100,
+ { 0 },
+ "audio/it",
+ "Impulse Tracker",
+ "it",
+ "it",
+ { 0 }
+ },
+ {
+ media_file_format::B_READABLE
+ | media_file_format::B_KNOWS_RAW_AUDIO
+ | media_file_format::B_KNOWS_ENCODED_AUDIO,
+ { 0 },
+ B_MISC_FORMAT_FAMILY,
+ 100,
+ { 0 },
+ "audio/x-mod",
+ "Protracker MOD",
+ "mod",
+ "mod",
+ { 0 }
+ },
};

const size_t gMuxerCount = sizeof(gMuxerTable) / sizeof(media_file_format);

############################################################################

Revision: hrev49603
Commit: 9e5c694668556b60e49a49e6708bfb550fc6ce1b
URL: http://cgit.haiku-os.org/haiku/commit/?id=9e5c69466855
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Aug 30 14:20:40 2015 UTC

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.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp
b/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp
index ac417f4..67d8847 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp
@@ -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
diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
index 6476746..b30de87 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
@@ -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
diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h
b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h
index 79139f7..4056c37 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h
+++ b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h
@@ -17,6 +17,11 @@ extern "C" {
#include "EncoderPlugin.h"


+#if __GNUC__ > 2
+typedef AVCodecID CodecID;
+#endif
+
+
class AVCodecEncoder : public Encoder {
public:

AVCodecEncoder(uint32 codecID,
diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
index 1095a7d..a453dd8 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp
@@ -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",
diff --git a/src/add-ons/media/plugins/ffmpeg/CodecTable.cpp
b/src/add-ons/media/plugins/ffmpeg/CodecTable.cpp
index dd5e0ce..80ee775 100644
--- a/src/add-ons/media/plugins/ffmpeg/CodecTable.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/CodecTable.cpp
@@ -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;

diff --git a/src/add-ons/media/plugins/ffmpeg/EncoderTable.h
b/src/add-ons/media/plugins/ffmpeg/EncoderTable.h
index 2e966de..9170116 100644
--- a/src/add-ons/media/plugins/ffmpeg/EncoderTable.h
+++ b/src/add-ons/media/plugins/ffmpeg/EncoderTable.h
@@ -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;
diff --git a/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp
b/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp
index b17304b..e3ec987 100644
--- a/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp
@@ -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;



Other related posts:

  • » [haiku-commits] haiku: hrev49603 - src/add-ons/media/plugins/ffmpeg - pulkomandy