Skip to content

Commit

Permalink
[DemuxClient] Parse for mid stream changes (optional)
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Sep 23, 2019
1 parent 2284918 commit 4b1562b
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 149 deletions.
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.cpp
Expand Up @@ -64,7 +64,7 @@ CDVDVideoCodec* CDVDFactoryCodec::CreateVideoCodec(CDVDStreamInfo &hint, CProces
}

// platform specifig video decoders
if (!(hint.codecOptions & CODEC_FORCE_SOFTWARE))
if (!m_hwVideoCodecs.empty() && !(hint.codecOptions & CODEC_FORCE_SOFTWARE))
{
for (auto &codec : m_hwVideoCodecs)
{
Expand Down
13 changes: 13 additions & 0 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodec.h
Expand Up @@ -235,6 +235,19 @@ class CDVDVideoCodec
*/
virtual void Reopen() {};

/**
* Return true, if codec parses stream to detect mid stream changes
* If false, demuxer tries to parse the stream and notifies VideoPlayer on changes.
*/
virtual bool HasCodecParser() const { return true; }

/**
* Get the framerate calculated by decoder.
* The return value could be different to what provided in hints for interlaced media
* Return 0.0f for default handling
*/
virtual float GetFramerate() const { return 0.0f; }

protected:
CProcessInfo &m_processInfo;
};
Expand Down
Expand Up @@ -1042,6 +1042,16 @@ unsigned CDVDVideoCodecAndroidMediaCodec::GetAllowedReferences()
return 4;
}

float CDVDVideoCodecAndroidMediaCodec::GetFramerate() const
{
int fpsRate = m_hints.fpsrate;
if (m_hints.fieldOrder > AV_FIELD_PROGRESSIVE)
fpsRate *= 2;

return (fpsRate > 0 && m_hints.fpsscale > 0) ? static_cast<float>(fpsRate) / m_hints.fpsscale
: 0.0f;
}

void CDVDVideoCodecAndroidMediaCodec::FlushInternal()
{
SignalEndOfStream();
Expand Down Expand Up @@ -1445,14 +1455,21 @@ void CDVDVideoCodecAndroidMediaCodec::ReleaseSurfaceTexture(void)

void CDVDVideoCodecAndroidMediaCodec::UpdateFpsDuration()
{
if (m_hints.fpsrate > 0 && m_hints.fpsscale > 0)
m_fpsDuration = static_cast<uint32_t>(static_cast<uint64_t>(DVD_TIME_BASE) * m_hints.fpsscale / m_hints.fpsrate);
int fpsRate = m_hints.fpsrate;
if (m_hints.fieldOrder > AV_FIELD_PROGRESSIVE)
fpsRate *= 2;

if (fpsRate > 0 && m_hints.fpsscale > 0)
{
m_fpsDuration =
static_cast<uint32_t>(static_cast<uint64_t>(DVD_TIME_BASE) * m_hints.fpsscale / fpsRate);
m_processInfo.SetVideoFps(static_cast<float>(fpsRate) / m_hints.fpsscale);
}
else
m_fpsDuration = 1;

m_processInfo.SetVideoFps(static_cast<float>(m_hints.fpsrate) / m_hints.fpsscale);

CLog::Log(LOGDEBUG, "CDVDVideoCodecAndroidMediaCodec::UpdateFpsDuration fpsRate:%u fpsscale:%u, fpsDur:%u", m_hints.fpsrate, m_hints.fpsscale, m_fpsDuration);
CLog::Log(LOGDEBUG,
"CDVDVideoCodecAndroidMediaCodec::UpdateFpsDuration fpsRate:%u fpsscale:%u, fpsDur:%u",
fpsRate, m_hints.fpsscale, m_fpsDuration);
}

void CDVDVideoCodecAndroidMediaCodec::surfaceChanged(CJNISurfaceHolder holder, int format, int width, int height)
Expand Down
Expand Up @@ -141,6 +141,8 @@ class CDVDVideoCodecAndroidMediaCodec : public CDVDVideoCodec, public CJNISurfac
virtual const char* GetName() override { return m_formatname.c_str(); };
virtual void SetCodecControl(int flags) override;
virtual unsigned GetAllowedReferences() override;
bool HasCodecParser() const override { return false; }
float GetFramerate() const override;

protected:
void Dispose();
Expand Down
66 changes: 28 additions & 38 deletions xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemux.h
Expand Up @@ -69,53 +69,37 @@ enum StreamSource
class CDemuxStream
{
public:
CDemuxStream()
{
uniqueId = 0;
dvdNavId = 0;
demuxerId = -1;
codec = (AVCodecID)0; // AV_CODEC_ID_NONE
codec_fourcc = 0;
profile = FF_PROFILE_UNKNOWN;
level = FF_LEVEL_UNKNOWN;
type = STREAM_NONE;
source = STREAM_SOURCE_NONE;
iDuration = 0;
pPrivate = NULL;
ExtraData = NULL;
ExtraSize = 0;
disabled = false;
changes = 0;
flags = StreamFlags::FLAG_NONE;
}

CDemuxStream() = default;
virtual ~CDemuxStream() { delete[] ExtraData; }

virtual std::string GetStreamName();

int uniqueId; // unique stream id
int dvdNavId;
int64_t demuxerId; // id of the associated demuxer
AVCodecID codec;
unsigned int codec_fourcc; // if available
int profile; // encoder profile of the stream reported by the decoder. used to qualify hw decoders.
int level; // encoder level of the stream reported by the decoder. used to qualify hw decoders.
StreamType type;
int source;

int iDuration; // in mseconds
void* pPrivate; // private pointer for the demuxer
uint8_t* ExtraData; // extra data for codec to use
unsigned int ExtraSize; // size of extra data

StreamFlags flags;
int uniqueId = 0; // unique stream id
int dvdNavId = 0;
int64_t demuxerId = -1; // id of the associated demuxer
AVCodecID codec = AV_CODEC_ID_NONE;
unsigned int codec_fourcc = 0; // if available
int profile =
FF_PROFILE_UNKNOWN; // encoder profile of the stream reported by the decoder. used to qualify hw decoders.
int level =
FF_LEVEL_UNKNOWN; // encoder level of the stream reported by the decoder. used to qualify hw decoders.
StreamType type = STREAM_NONE;
int source = STREAM_SOURCE_NONE;

int iDuration = 0; // in mseconds
void* pPrivate = nullptr; // private pointer for the demuxer
uint8_t* ExtraData = nullptr; // extra data for codec to use
unsigned int ExtraSize = 0; // size of extra data

StreamFlags flags = StreamFlags::FLAG_NONE;
std::string language; // RFC 5646 language code (empty string if undefined)
bool disabled; // set when stream is disabled. (when no decoder exists)
bool disabled = false; // set when stream is disabled. (when no decoder exists)

std::string name;
std::string codecName;

int changes; // increment on change which player may need to know about
bool checkStreamChange = false;
int changes = 0; // increment on change which player may need to know about

std::shared_ptr<DemuxCryptoSession> cryptoSession;
std::shared_ptr<ADDON::IAddonProvider> externalInterfaces;
Expand All @@ -138,6 +122,7 @@ class CDemuxStreamVideo : public CDemuxStream
int iOrientation = 0; // orientation of the video in degrees counter clockwise
int iBitsPerPixel = 0;
int iBitRate = 0;
AVFieldOrder fieldOrder = AV_FIELD_UNKNOWN;

AVColorSpace colorSpace = AVCOL_SPC_UNSPECIFIED;
AVColorRange colorRange = AVCOL_RANGE_UNSPECIFIED;
Expand Down Expand Up @@ -349,6 +334,11 @@ class CDVDDemux
*/
virtual void SetVideoResolution(int width, int height){};

/*
* Enable ParsePacket to detect mid stream changes
*/
virtual void EnableParsePacket(int64_t demuxerId, bool enable){};

/*
* return the id of the demuxer
*/
Expand Down

0 comments on commit 4b1562b

Please sign in to comment.