Skip to content

Commit

Permalink
[ssif] re-factoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Fedchin authored and popcornmix committed Jan 26, 2016
1 parent ff63160 commit 2aa3585
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 180 deletions.
2 changes: 2 additions & 0 deletions project/VS2010Express/XBMC.vcxproj
Expand Up @@ -265,6 +265,7 @@
<ClCompile Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxCC.cpp" />
<ClCompile Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxCDDA.cpp" />
<ClCompile Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxPVRClient.cpp" />
<ClCompile Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxStreamSSIF.cpp" />
<ClCompile Include="..\..\xbmc\cores\VideoPlayer\DVDInputStreams\DVDInputStreamBluray.cpp" />
<ClCompile Include="..\..\xbmc\cores\VideoPlayer\DVDInputStreams\DVDInputStreamPVRManager.cpp" />
<ClCompile Include="..\..\xbmc\cores\FFmpeg.cpp" />
Expand Down Expand Up @@ -950,6 +951,7 @@
<ClInclude Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxCC.h" />
<ClInclude Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxCDDA.h" />
<ClInclude Include="..\..\xbmc\cores\FFmpeg.h" />
<ClInclude Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxStreamSSIF.h" />
<ClInclude Include="..\..\xbmc\cores\VideoPlayer\VideoRenderers\BaseRenderer.h" />
<ClInclude Include="..\..\xbmc\cores\VideoPlayer\VideoRenderers\HwDecRender\DXVAHD.h" />
<ClInclude Include="..\..\xbmc\cores\VideoPlayer\VideoRenderers\OverlayRenderer.h" />
Expand Down
6 changes: 6 additions & 0 deletions project/VS2010Express/XBMC.vcxproj.filters
Expand Up @@ -3229,6 +3229,9 @@
<Filter>filesystem\VideoDatabaseDirectory</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\InfoScanner.cpp" />
<ClCompile Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxStreamSSIF.cpp">
<Filter>cores\VideoPlayer\DVDDemuxers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\xbmc\win32\pch.h">
Expand Down Expand Up @@ -6254,6 +6257,9 @@
<Filter>filesystem\VideoDatabaseDirectory</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\InfoScanner.h" />
<ClInclude Include="..\..\xbmc\cores\VideoPlayer\DVDDemuxers\DVDDemuxStreamSSIF.h">
<Filter>cores\VideoPlayer\DVDDemuxers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
Expand Down
204 changes: 29 additions & 175 deletions xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
Expand Up @@ -194,8 +194,7 @@ CDVDDemuxFFmpeg::CDVDDemuxFFmpeg() : CDVDDemux()
m_currentPts = DVD_NOPTS_VALUE;
m_bMatroska = false;
m_bAVI = false;
m_bSSIF = false;
m_bSSIFSyncing = false;
m_pSSIF = nullptr;
m_speed = DVD_PLAYSPEED_NORMAL;
m_program = UINT_MAX;
m_pkt.result = -1;
Expand Down Expand Up @@ -503,7 +502,7 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput, bool streaminfo, bool filein
if (m_checkvideo)
{
// make sure we start video with an i-frame
//ResetVideoStreams();
ResetVideoStreams();
}
}
else
Expand Down Expand Up @@ -539,17 +538,8 @@ void CDVDDemuxFFmpeg::Dispose()
{
m_pkt.result = -1;
av_free_packet(&m_pkt.pkt);
while (!m_H264queue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_H264queue.front());
m_H264queue.pop();
}
while (!m_MVCqueue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_MVCqueue.front());
m_MVCqueue.pop();
}
m_bSSIFSyncing = true;

SAFE_DELETE(m_pSSIF);

if (m_pFormatContext)
{
Expand Down Expand Up @@ -598,17 +588,9 @@ void CDVDDemuxFFmpeg::Flush()

m_pkt.result = -1;
av_free_packet(&m_pkt.pkt);
while (!m_H264queue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_H264queue.front());
m_H264queue.pop();
}
while (!m_MVCqueue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_MVCqueue.front());
m_MVCqueue.pop();
}
m_bSSIFSyncing = true;

if (m_pSSIF)
m_pSSIF->Flush();
}

void CDVDDemuxFFmpeg::Abort()
Expand Down Expand Up @@ -761,107 +743,6 @@ DemuxPacket* movePacket(DemuxPacket* &srcPkt)
return newpkt;
}

DemuxPacket* CDVDDemuxFFmpeg::GetMVCPacket()
{
// Here, we recreate a h264 MVC packet from the base one + buffered MVC NALU's
DemuxPacket* newpkt = NULL;

double tsH264 = DVD_NOPTS_VALUE;
DemuxPacket* h264pkt = NULL;
if (!m_H264queue.empty())
{
h264pkt = m_H264queue.front();
tsH264 = (h264pkt->dts != DVD_NOPTS_VALUE ? h264pkt->dts : h264pkt->pts);
//CLog::Log(LOGDEBUG, ">>> MVC h264 packet: %d, pts(%f) dts (%f)", h264pkt->iSize, h264pkt->pts, h264pkt->dts);
}

double tsMVC = DVD_NOPTS_VALUE;
DemuxPacket* mvcpkt = NULL;
if (!m_MVCqueue.empty())
{
mvcpkt = m_MVCqueue.front();
tsMVC = (mvcpkt->dts != DVD_NOPTS_VALUE ? mvcpkt->dts : mvcpkt->pts);
//CLog::Log(LOGDEBUG, ">>> MVC mvc packet: %d, pts(%f) dts (%f)", mvcpkt->iSize, mvcpkt->pts, mvcpkt->dts);
}

if (tsH264 == tsMVC)
{
m_bSSIFSyncing = false;
m_H264queue.pop();
m_MVCqueue.pop();
#if defined(DEBUG_VERBOSE)
CLog::Log(LOGDEBUG, ">>> MVC merge packet: %d+%d, pts(%f/%f) dts (%f/%f)", h264pkt->iSize, mvcpkt->iSize, h264pkt->pts, mvcpkt->pts, h264pkt->dts, mvcpkt->dts);
#endif
newpkt = mergePacket(h264pkt, mvcpkt);
if (!m_MVCqueue.empty())
{
mvcpkt = m_MVCqueue.front();
while (mvcpkt->dts == DVD_NOPTS_VALUE && mvcpkt->pts == DVD_NOPTS_VALUE)
{
// Append leftover
#if defined(DEBUG_VERBOSE)
CLog::Log(LOGDEBUG, ">>> MVC merge leftover: %d+%d, pts(%f) dts (%f)", newpkt->iSize, mvcpkt->iSize, newpkt->pts, newpkt->dts);
#endif
newpkt = mergePacket(newpkt, mvcpkt);
m_MVCqueue.pop();
if (m_MVCqueue.empty())
break;
mvcpkt = m_MVCqueue.front();
}
}
}
else if (tsH264 > tsMVC)
{
// H264 before MVC ?
#if defined(DEBUG_VERBOSE)
CLog::Log(LOGDEBUG, ">>> MVC missing mvc: %d, pts(%f) dts (%f)", h264pkt->iSize, h264pkt->pts, h264pkt->dts);
#endif
if (m_bSSIFSyncing)
{
if (!m_H264queue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_H264queue.front());
m_H264queue.pop();
}
while (!m_MVCqueue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_MVCqueue.front());
m_MVCqueue.pop();
}
}
else if (!m_MVCqueue.empty())
{
// pop or we are stuck
CDVDDemuxUtils::FreeDemuxPacket(m_MVCqueue.front());
m_MVCqueue.pop();
}
newpkt = CDVDDemuxUtils::AllocateDemuxPacket(0);
newpkt->iSize = 0;
}
else
{
if (m_bSSIFSyncing && !m_H264queue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_H264queue.front());
m_H264queue.pop();
}
else if (!m_H264queue.empty())
{
// missing an MVC packets
#if defined(DEBUG_VERBOSE)
CLog::Log(LOGDEBUG, ">>> MVC missing mvc2: %d, pts(%f) dts (%f)", h264pkt->iSize, h264pkt->pts, h264pkt->dts);
#endif
// pop or we are stuck
CDVDDemuxUtils::FreeDemuxPacket(m_H264queue.front());
m_H264queue.pop();
}
newpkt = CDVDDemuxUtils::AllocateDemuxPacket(0);
newpkt->iSize = 0;
}

return newpkt;
}

DemuxPacket* CDVDDemuxFFmpeg::Read()
{
DemuxPacket* pPacket = NULL;
Expand Down Expand Up @@ -899,7 +780,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
}
// libavformat is confused by the interleaved SSIF.
// Disable program management for those
else if (!m_bSSIF && IsProgramChange())
else if (!m_pSSIF && IsProgramChange())
{
// update streams
CreateStreams(m_program);
Expand All @@ -926,11 +807,9 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()

m_pkt.result = -1;
av_free_packet(&m_pkt.pkt);
while (!m_MVCqueue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_MVCqueue.front());
m_MVCqueue.pop();
}

if (m_pSSIF)
m_pSSIF->Flush();
}
else
{
Expand All @@ -942,7 +821,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
{
// libavformat is confused by the interleaved SSIF.
// Disable program management for those
if ( !m_bSSIF && m_program != UINT_MAX )
if (!m_pSSIF && m_program != UINT_MAX )
{
/* check so packet belongs to selected program */
for (unsigned int i = 0; i < m_pFormatContext->programs[m_program]->nb_stream_indexes; i++)
Expand Down Expand Up @@ -1082,23 +961,12 @@ DemuxPacket* CDVDDemuxFFmpeg::Read()
// content has changed
stream = AddStream(pPacket->iStreamId);
}
if (m_bSSIF && stream->iPhysicalId == 0x1011)
{
DemuxPacket* newpkt = movePacket(pPacket);
m_H264queue.push(newpkt);
pPacket = GetMVCPacket();
}
}
else if (stream->type == STREAM_DATA)
if (stream && m_pSSIF)
{
if (m_bSSIF && stream->iPhysicalId == 0x1012)
{
DemuxPacket* newpkt = movePacket(pPacket);
m_MVCqueue.push(newpkt);
pPacket = GetMVCPacket();
if (pPacket->iSize)
stream = GetStreamInternal(pPacket->iStreamId);
}
if (stream->type == STREAM_VIDEO ||
stream->type == STREAM_DATA)
pPacket = m_pSSIF->AddPacket(pPacket);
}
if (!stream)
{
Expand All @@ -1122,17 +990,9 @@ bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts)

m_pkt.result = -1;
av_free_packet(&m_pkt.pkt);
while (!m_H264queue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_H264queue.front());
m_H264queue.pop();
}
while (!m_MVCqueue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_MVCqueue.front());
m_MVCqueue.pop();
}
m_bSSIFSyncing = true;

if (m_pSSIF)
m_pSSIF->Flush();

CDVDInputStream::ISeekTime* ist = dynamic_cast<CDVDInputStream::ISeekTime*>(m_pInput);
if (ist)
Expand Down Expand Up @@ -1200,17 +1060,9 @@ bool CDVDDemuxFFmpeg::SeekByte(int64_t pos)

m_pkt.result = -1;
av_free_packet(&m_pkt.pkt);
while (!m_H264queue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_H264queue.front());
m_H264queue.pop();
}
while (!m_MVCqueue.empty())
{
CDVDDemuxUtils::FreeDemuxPacket(m_MVCqueue.front());
m_MVCqueue.pop();
}
m_bSSIFSyncing = true;

if (m_pSSIF)
m_pSSIF->Flush();

return (ret >= 0);
}
Expand Down Expand Up @@ -1400,8 +1252,9 @@ CDemuxStream* CDVDDemuxFFmpeg::AddStream(int iId)
{
if (pStream->codec->codec_id == AV_CODEC_ID_H264_MVC)
{
// ignore MVC extension streams, they are handled specially
m_bSSIF = true;
m_pSSIF = new CDVDDemuxStreamSSIF();
m_pSSIF->SetMVCStreamId(iId);

stream = new CDemuxStream();
stream->type = STREAM_DATA;
pStream->need_parsing = AVSTREAM_PARSE_NONE;
Expand Down Expand Up @@ -1503,11 +1356,11 @@ CDemuxStream* CDVDDemuxFFmpeg::AddStream(int iId)
{
if (h264_is_annexb(m_pFormatContext->iformat->name, pStream))
{
// TODO
if (m_bSSIF)
if (m_pSSIF)
{
//pStream->codec->codec_id = AV_CODEC_ID_H264_MVC;
m_pSSIF->SetH264StreamId(iId);
pStream->codec->codec_tag = MKTAG('m', 'v', 'c', 'C');

AVStream *mvc = nullptr;
for (size_t i = 0; i < m_pFormatContext->nb_streams; i++)
if (m_pFormatContext->streams[i]->codec->codec_id == AV_CODEC_ID_H264_MVC)
Expand Down Expand Up @@ -2066,6 +1919,7 @@ void CDVDDemuxFFmpeg::ResetVideoStreams()
if (st->codec->extradata)
av_free(st->codec->extradata);
st->codec->extradata = NULL;
st->codec->extradata_size = 0;
st->codec->width = 0;
}
}
Expand Down
7 changes: 2 additions & 5 deletions xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.h
Expand Up @@ -21,6 +21,7 @@
*/

#include "DVDDemux.h"
#include "DVDDemuxStreamSSIF.h"
#include "threads/CriticalSection.h"
#include "threads/SystemClock.h"
#include <map>
Expand Down Expand Up @@ -148,7 +149,6 @@ class CDVDDemuxFFmpeg : public CDVDDemux
void ParsePacket(AVPacket *pkt);
bool IsVideoReady();
void ResetVideoStreams();
DemuxPacket* GetMVCPacket();

AVDictionary *GetFFMpegOptionsFromURL(const CURL &url);
double ConvertTimestamp(int64_t pts, int den, int num);
Expand All @@ -170,10 +170,7 @@ class CDVDDemuxFFmpeg : public CDVDDemux
double m_currentPts; // used for stream length estimation
bool m_bMatroska;
bool m_bAVI;
bool m_bSSIF;
bool m_bSSIFSyncing;
std::queue<DemuxPacket*> m_H264queue;
std::queue<DemuxPacket*> m_MVCqueue;
CDVDDemuxStreamSSIF* m_pSSIF;
int m_speed;
unsigned m_program;
XbmcThreads::EndTime m_timeout;
Expand Down

0 comments on commit 2aa3585

Please sign in to comment.