Skip to content

Instantly share code, notes, and snippets.

@elupus
Created June 16, 2011 20:02
Show Gist options
  • Save elupus/1030129 to your computer and use it in GitHub Desktop.
Save elupus/1030129 to your computer and use it in GitHub Desktop.
Api test for deinterlacing in codec
diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h b/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h
index 0cabbc5..87f951f 100644
--- a/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h
+++ b/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h
@@ -207,6 +207,20 @@ public:
*/
virtual void SetDropState(bool bDrop) = 0;
+
+ enum EFilterFlags {
+ FILTER_NONE = 0x0,
+ FILTER_DEINTERLACE_1 = 0x1, /* use first deinterlace mode */
+ FILTER_DEINTERLACE_ANY = 0xf, /* use any deinterlace mode */
+ FILTER_DEINTERLACE_ALWAYS = 0x10, /* deinterlace all frame independent of flags */
+ FILTER_DEINTERLACE_HALFED = 0x20, /* do half rate deinterlacing */
+ };
+
+ /*
+ * set the type of filters that should be applied at decoding stage if possible
+ */
+ virtual unsigned int SetFilters(unsigned int filters) { return false; }
+
/*
*
* should return codecs name
diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
index 7f7ad1c..fdcefbb 100644
--- a/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
+++ b/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
@@ -371,6 +371,37 @@ void CDVDVideoCodecFFmpeg::SetDropState(bool bDrop)
}
}
+unsigned int CDVDVideoCodecFFmpeg::SetFilters(unsigned int flags)
+{
+ if(m_pHardware)
+ return false;
+
+#ifdef HAS_AVFILTER
+ CStdString filters;
+ if(flags & FILTER_DEINTERLACE_1)
+ {
+ if(flags & FILTER_DEINTERLACE_HALFED)
+ filters = "yadif=0:-1";
+ else
+ filters = "yadif=1:-1";
+ }
+
+ if (!m_filters.Equals(filters))
+ {
+ m_filters = filters;
+
+ if(InitVideoFilters(filters.c_str()) < 0)
+ {
+ DeInitVideoFilters();
+ return 0;
+ }
+ }
+ return flags;
+#else
+ return 0;
+#endif
+}
+
union pts_union
{
double pts_d;
@@ -517,14 +548,6 @@ int CDVDVideoCodecFFmpeg::Decode(BYTE* pData, int iSize, double dts, double pts)
}
}
-#ifdef HAS_AVFILTER
- if (InitVideoFilters("vflip") < 0)
- {
- CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::Decode - unable to configure video filter");
- return VC_ERROR;
- }
-#endif
-
int result;
if(m_pHardware)
result = m_pHardware->Decode(m_pCodecContext, m_pFrame);
@@ -685,12 +708,7 @@ int CDVDVideoCodecFFmpeg::InitVideoFilters(const CStdString& filters)
int result;
if (m_pFilterGraph)
- {
- if (!m_filters.Equals(filters))
- DeInitVideoFilters();
- else // filters not changed
- return 0;
- }
+ DeInitVideoFilters();
m_filters = filters;
diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h b/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h
index 90c6781..6bc8ff7 100644
--- a/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h
+++ b/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h
@@ -63,6 +63,7 @@ public:
bool GetPictureCommon(DVDVideoPicture* pDvdVideoPicture);
virtual bool GetPicture(DVDVideoPicture* pDvdVideoPicture);
virtual void SetDropState(bool bDrop);
+ virtual unsigned int SetFilters(unsigned int filters);
virtual const char* GetName() { return m_name.c_str(); }; // m_name is never changed after open
virtual unsigned GetConvergeCount();
diff --git a/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp b/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
index 247c5fc..ae1b9d5 100644
--- a/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
+++ b/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
@@ -494,6 +494,17 @@ void CDVDPlayerVideo::Process()
// decoder still needs to provide an empty image structure, with correct flags
m_pVideoCodec->SetDropState(bRequestDrop);
+ // ask codec to do deinterlacing if possible
+ EINTERLACEMETHOD mInt = g_settings.m_currentVideoSettings.m_InterlaceMethod;
+ unsigned int mFilters = 0;
+
+ if(mInt == VS_INTERLACEMETHOD_DEINTERLACE)
+ mFilters = CDVDVideoCodec::FILTER_DEINTERLACE_ANY | CDVDVideoCodec::FILTER_DEINTERLACE_ALWAYS;
+ else if(mInt == VS_INTERLACEMETHOD_AUTO)
+ mFilters = CDVDVideoCodec::FILTER_DEINTERLACE_ANY;
+
+ mFilters = m_pVideoCodec->SetFilters(mFilters);
+
int iDecoderState = m_pVideoCodec->Decode(pPacket->pData, pPacket->iSize, pPacket->dts, pPacket->pts);
// buffer packets so we can recover should decoder flush for some reason
@@ -585,14 +596,16 @@ void CDVDPlayerVideo::Process()
//Deinterlace if codec said format was interlaced or if we have selected we want to deinterlace
//this video
- EINTERLACEMETHOD mInt = g_settings.m_currentVideoSettings.m_InterlaceMethod;
- if((mInt == VS_INTERLACEMETHOD_DEINTERLACE)
- || (mInt == VS_INTERLACEMETHOD_AUTO && (picture.iFlags & DVP_FLAG_INTERLACED)
- && !g_renderManager.Supports(VS_INTERLACEMETHOD_RENDER_BOB)))
+ if(!(mFilters & CDVDVideoCodec::FILTER_DEINTERLACE_ANY))
{
- if (!sPostProcessType.empty())
- sPostProcessType += ",";
- sPostProcessType += g_advancedSettings.m_videoPPFFmpegDeint;
+ if((mInt == VS_INTERLACEMETHOD_DEINTERLACE)
+ || (mInt == VS_INTERLACEMETHOD_AUTO && (picture.iFlags & DVP_FLAG_INTERLACED)
+ && !g_renderManager.Supports(VS_INTERLACEMETHOD_RENDER_BOB)))
+ {
+ if (!sPostProcessType.empty())
+ sPostProcessType += ",";
+ sPostProcessType += g_advancedSettings.m_videoPPFFmpegDeint;
+ }
}
if (g_settings.m_currentVideoSettings.m_PostProcess)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment