Permalink
Browse files

Merge pull request #2597 from Alphix/ffmpeg-libav-fixes

ffmpeg and libav compatibility fixes
  • Loading branch information...
2 parents 9eaf1cd + d98c922 commit 95e2d6df7e186be8e7af82665ecee78feb0648f2 @elupus elupus committed Apr 14, 2013
View
@@ -63,6 +63,12 @@ extern "C" {
#endif
}
+#if LIBAVCODEC_VERSION_MICRO >= 100
+ #define LIBAVCODEC_FROM_FFMPEG
+#else
+ #define LIBAVCODEC_FROM_LIBAV
+#endif
+
#include "threads/SingleLock.h"
class DllAvCodecInterface
View
@@ -58,6 +58,13 @@ extern "C" {
#endif
}
+#if LIBAVFILTER_VERSION_MICRO >= 100
+ #define LIBAVFILTER_FROM_FFMPEG
+#else
+ #define LIBAVFILTER_FROM_LIBAV
+#endif
+
+
#include "threads/SingleLock.h"
class DllAvFilterInterface
@@ -74,10 +81,13 @@ class DllAvFilterInterface
virtual void avfilter_inout_free(AVFilterInOut **inout)=0;
virtual int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)=0;
virtual int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)=0;
-#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
- virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags)=0;
-#else
+#if (defined(LIBAVFILTER_FROM_LIBAV) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(3,5,0)) || \
+ (defined(LIBAVFILTER_FROM_FFMPEG) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(3,43,100))
+ virtual int av_buffersrc_add_frame(AVFilterContext *buffer_filter, AVFrame *frame)=0;
+#elif defined(LIBAVFILTER_FROM_FFMPEG) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,72,105)
virtual int av_buffersrc_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags)=0;
+#else
+ virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags)=0;
#endif
virtual void avfilter_unref_buffer(AVFilterBufferRef *ref)=0;
virtual int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)=0;
@@ -134,10 +144,13 @@ class DllAvFilter : public DllDynamic, DllAvFilterInterface
{
return ::avfilter_graph_config(graphctx, log_ctx);
}
-#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
- virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags) { return ::av_vsrc_buffer_add_frame(buffer_filter, frame, flags); }
-#else
+#if (defined(LIBAVFILTER_FROM_LIBAV) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(3,5,0)) || \
+ (defined(LIBAVFILTER_FROM_FFMPEG) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(3,43,100))
+ virtual int av_buffersrc_add_frame(AVFilterContext *buffer_filter, AVFrame* frame) { return ::av_buffersrc_add_frame(buffer_filter, frame); }
+#elif defined(LIBAVFILTER_FROM_FFMPEG) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,72,105)
virtual int av_buffersrc_add_frame(AVFilterContext *buffer_filter, AVFrame* frame, int flags) { return ::av_buffersrc_add_frame(buffer_filter, frame, flags); }
+#else
+ virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags) { return ::av_vsrc_buffer_add_frame(buffer_filter, frame, flags); }
#endif
virtual void avfilter_unref_buffer(AVFilterBufferRef *ref) { ::avfilter_unref_buffer(ref); }
virtual int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad) { return ::avfilter_link(src, srcpad, dst, dstpad); }
@@ -172,10 +185,13 @@ class DllAvFilter : public DllDynamic, DllAvFilterInterface
DEFINE_METHOD1(void, avfilter_inout_free_dont_call, (AVFilterInOut **p1))
DEFINE_FUNC_ALIGNED5(int, __cdecl, avfilter_graph_parse_dont_call, AVFilterGraph *, const char *, AVFilterInOut **, AVFilterInOut **, void *)
DEFINE_FUNC_ALIGNED2(int, __cdecl, avfilter_graph_config_dont_call, AVFilterGraph *, void *)
-#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
- DEFINE_METHOD3(int, av_vsrc_buffer_add_frame, (AVFilterContext *p1, AVFrame *p2, int p3))
-#else
+#if (defined(LIBAVFILTER_FROM_LIBAV) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(3,5,0)) || \
+ (defined(LIBAVFILTER_FROM_FFMPEG) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(3,43,100))
+ DEFINE_METHOD2(int, av_buffersrc_add_frame, (AVFilterContext *p1, AVFrame *p2))
+#elif defined(LIBAVFILTER_FROM_FFMPEG) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,72,105)
DEFINE_METHOD3(int, av_buffersrc_add_frame, (AVFilterContext *p1, AVFrame *p2, int p3))
+#else
+ DEFINE_METHOD3(int, av_vsrc_buffer_add_frame, (AVFilterContext *p1, AVFrame *p2, int p3))
#endif
DEFINE_METHOD1(void, avfilter_unref_buffer, (AVFilterBufferRef *p1))
DEFINE_METHOD4(int, avfilter_link, (AVFilterContext *p1, unsigned p2, AVFilterContext *p3, unsigned p4))
@@ -348,6 +348,12 @@ CDVDOverlayCodec* CDVDFactoryCodec::CreateOverlayCodec( CDVDStreamInfo &hint )
switch (hint.codec)
{
case CODEC_ID_TEXT:
+#if defined(LIBAVCODEC_FROM_FFMPEG) && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,53,100)
+ // API changed in:
+ // ffmpeg: commit 2626cc4580bfd560c6983338d77b2c11c16af94f (11 Aug 2012)
+ // release 1.0 (28 Sept 2012)
+ case AV_CODEC_ID_SUBRIP:
+#endif
pCodec = OpenCodec(new CDVDOverlayCodecText(), hint, options);
if( pCodec ) return pCodec;
break;
@@ -237,13 +237,9 @@ CDVDOverlay* CDVDOverlayCodecFFmpeg::GetOverlay()
if(m_SubtitleIndex >= (int)m_Subtitle.num_rects)
return NULL;
-#if LIBAVCODEC_VERSION_INT >= (52<<10)
if(m_Subtitle.rects[m_SubtitleIndex] == NULL)
return NULL;
AVSubtitleRect& rect = *m_Subtitle.rects[m_SubtitleIndex];
-#else
- AVSubtitleRect& rect = m_Subtitle.rects[m_SubtitleIndex];
-#endif
CDVDOverlayImage* overlay = new CDVDOverlayImage();
@@ -259,7 +255,12 @@ CDVDOverlay* CDVDOverlayCodecFFmpeg::GetOverlay()
overlay->width = rect.w;
overlay->height = rect.h;
-#if (!defined USE_EXTERNAL_FFMPEG) || (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,71,100))
+#if (defined(LIBAVCODEC_FROM_FFMPEG) && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,71,100)) || \
+ (defined(LIBAVCODEC_FROM_LIBAV) && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,33,0))
+ // ffmpeg commit: 1885ffb03d0af28e6bac2bcc8725fa15b93f6ac9 (Nov 3 2012)
+ // release: 1.1 (Jan 7 2013)
+ // libav commit: 85f67c4865d8014ded2aaa64b3cba6e2970342d7 (Oct 20 2012)
+ // release: v9 (Jan 5 2013)
overlay->bForced = rect.flags != 0;
#endif
@@ -44,6 +44,13 @@ bool CDVDOverlayCodecText::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
m_bIsSSA = (hints.codec == CODEC_ID_SSA);
if(hints.codec == CODEC_ID_TEXT || hints.codec == CODEC_ID_SSA)
return true;
+#if defined(LIBAVCODEC_FROM_FFMPEG) && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,53,100)
+ // API changed in:
+ // ffmpeg: commit 2626cc4580bfd560c6983338d77b2c11c16af94f (11 Aug 2012)
+ // release 1.0 (28 Sept 2012)
+ if(hints.codec == AV_CODEC_ID_SUBRIP)
+ return true;
+#endif
return false;
}
@@ -21,6 +21,7 @@
*/
#include "DVDOverlayCodec.h"
+#include "DllAvCodec.h"
class CDVDOverlayText;
@@ -815,18 +815,25 @@ int CDVDVideoCodecFFmpeg::FilterProcess(AVFrame* frame)
if (frame)
{
-#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
- result = m_dllAvFilter.av_vsrc_buffer_add_frame(m_pFilterIn, frame, 0);
-#else
+#if (defined(LIBAVFILTER_FROM_LIBAV) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(3,5,0)) || \
+ (defined(LIBAVFILTER_FROM_FFMPEG) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(3,43,100))
+ // API changed in:
+ // ffmpeg: commit 7e350379f87e7f74420b4813170fe808e2313911 (28 Nov 2012)
+ // not released (post 1.2)
+ // libav: commit 7e350379f87e7f74420b4813170fe808e2313911 (28 Nov 2012)
+ // release v9 (5 January 2013)
+ result = m_dllAvFilter.av_buffersrc_add_frame(m_pFilterIn, frame);
+#elif defined(LIBAVFILTER_FROM_FFMPEG) && LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,72,105)
+ // API changed in:
+ // ffmpeg: commit 7bac2a78c2241df4bcc1665703bb71afd9a3e692 (28 Apr 2012)
+ // release 0.11 (25 May 2012)
result = m_dllAvFilter.av_buffersrc_add_frame(m_pFilterIn, frame, 0);
+#else
+ result = m_dllAvFilter.av_vsrc_buffer_add_frame(m_pFilterIn, frame, 0);
#endif
if (result < 0)
{
-#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,0,0)
- CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::FilterProcess - av_vsrc_buffer_add_frame");
-#else
- CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::FilterProcess - av_buffersrc_add_frame");
-#endif
+ CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::FilterProcess - av_buffersrc_add_frame/av_vsrc_buffer_add_frame");
return VC_ERROR;
}
}
@@ -1033,7 +1033,6 @@ void CDVDDemuxFFmpeg::AddStream(int iId)
}
case AVMEDIA_TYPE_SUBTITLE:
{
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,38,1)
if (pStream->codec->codec_id == CODEC_ID_DVB_TELETEXT && g_guiSettings.GetBool("videoplayer.teletextenabled"))
{
CDemuxStreamTeletext* st = new CDemuxStreamTeletext();
@@ -1042,7 +1041,6 @@ void CDVDDemuxFFmpeg::AddStream(int iId)
break;
}
else
-#endif
{
CDemuxStreamSubtitleFFmpeg* st = new CDemuxStreamSubtitleFFmpeg(this, pStream);
m_streams[iId] = st;
@@ -1110,16 +1108,9 @@ void CDVDDemuxFFmpeg::AddStream(int iId)
m_streams[iId]->pPrivate = pStream;
m_streams[iId]->flags = (CDemuxStream::EFlags)pStream->disposition;
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,83,0)
- // API added on: 2010-10-15
- // (Note that while the function was available earlier, the generic
- // metadata tags were not populated by default)
AVDictionaryEntry *langTag = m_dllAvUtil.av_dict_get(pStream->metadata, "language", NULL, 0);
if (langTag)
strncpy(m_streams[iId]->language, langTag->value, 3);
-#else
- strcpy( m_streams[iId]->language, pStream->language );
-#endif
if( pStream->codec->extradata && pStream->codec->extradata_size > 0 )
{
@@ -1180,11 +1171,8 @@ int CDVDDemuxFFmpeg::GetChapterCount()
if(m_pFormatContext == NULL)
return 0;
- #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,14,0)
- return m_pFormatContext->nb_chapters;
- #else
- return 0;
- #endif
+
+ return m_pFormatContext->nb_chapters;
}
int CDVDDemuxFFmpeg::GetChapter()
@@ -1197,15 +1185,14 @@ int CDVDDemuxFFmpeg::GetChapter()
|| m_iCurrentPts == DVD_NOPTS_VALUE)
return 0;
- #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,14,0)
- for(unsigned i = 0; i < m_pFormatContext->nb_chapters; i++)
- {
- AVChapter *chapter = m_pFormatContext->chapters[i];
- if(m_iCurrentPts >= ConvertTimestamp(chapter->start, chapter->time_base.den, chapter->time_base.num)
- && m_iCurrentPts < ConvertTimestamp(chapter->end, chapter->time_base.den, chapter->time_base.num))
- return i + 1;
- }
- #endif
+ for(unsigned i = 0; i < m_pFormatContext->nb_chapters; i++)
+ {
+ AVChapter *chapter = m_pFormatContext->chapters[i];
+ if(m_iCurrentPts >= ConvertTimestamp(chapter->start, chapter->time_base.den, chapter->time_base.num)
+ && m_iCurrentPts < ConvertTimestamp(chapter->end, chapter->time_base.den, chapter->time_base.num))
+ return i + 1;
+ }
+
return 0;
}
@@ -1216,23 +1203,14 @@ void CDVDDemuxFFmpeg::GetChapterName(std::string& strChapterName)
ich->GetChapterName(strChapterName);
else
{
- #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,14,0)
- int chapterIdx = GetChapter();
- if(chapterIdx <= 0)
- return;
-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,83,0)
- // API added on: 2010-10-15
- // (Note that while the function was available earlier, the generic
- // metadata tags were not populated by default)
- AVDictionaryEntry *titleTag = m_dllAvUtil.av_dict_get(m_pFormatContext->chapters[chapterIdx-1]->metadata,
- "title", NULL, 0);
- if (titleTag)
- strChapterName = titleTag->value;
-#else
- if (m_pFormatContext->chapters[chapterIdx-1]->title)
- strChapterName = m_pFormatContext->chapters[chapterIdx-1]->title;
-#endif
- #endif
+ int chapterIdx = GetChapter();
+ if(chapterIdx <= 0)
+ return;
+
+ AVDictionaryEntry *titleTag = m_dllAvUtil.av_dict_get(m_pFormatContext->chapters[chapterIdx-1]->metadata,
+ "title", NULL, 0);
+ if (titleTag)
+ strChapterName = titleTag->value;
}
}
@@ -1258,16 +1236,12 @@ bool CDVDDemuxFFmpeg::SeekChapter(int chapter, double* startpts)
if(m_pFormatContext == NULL)
return false;
- #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,14,0)
- if(chapter < 1 || chapter > (int)m_pFormatContext->nb_chapters)
- return false;
+ if(chapter < 1 || chapter > (int)m_pFormatContext->nb_chapters)
+ return false;
- AVChapter *ch = m_pFormatContext->chapters[chapter-1];
- double dts = ConvertTimestamp(ch->start, ch->time_base.den, ch->time_base.num);
- return SeekTime(DVD_TIME_TO_MSEC(dts), true, startpts);
- #else
- return false;
- #endif
+ AVChapter *ch = m_pFormatContext->chapters[chapter-1];
+ double dts = ConvertTimestamp(ch->start, ch->time_base.den, ch->time_base.num);
+ return SeekTime(DVD_TIME_TO_MSEC(dts), true, startpts);
}
void CDVDDemuxFFmpeg::GetStreamCodecName(int iStreamId, CStdString &strName)
@@ -113,10 +113,8 @@ CDVDTeletextData::~CDVDTeletextData()
bool CDVDTeletextData::CheckStream(CDVDStreamInfo &hints)
{
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,38,1)
if (hints.codec == CODEC_ID_DVB_TELETEXT)
return true;
-#endif
return false;
}
@@ -125,14 +123,12 @@ bool CDVDTeletextData::OpenStream(CDVDStreamInfo &hints)
{
m_messageQueue.Init();
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,38,1)
if (hints.codec == CODEC_ID_DVB_TELETEXT)
{
CLog::Log(LOGNOTICE, "Creating teletext data thread");
Create();
return true;
}
-#endif
return false;
}

0 comments on commit 95e2d6d

Please sign in to comment.