Skip to content

Commit

Permalink
Merge pull request #1578 from CastagnaIT/sub_workaround
Browse files Browse the repository at this point in the history
[SubtitleSampleReader] Limited PTS workaround to HLS
  • Loading branch information
CastagnaIT authored Jun 17, 2024
2 parents 71b4823 + ac39fbb commit b9c6a90
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common/AdaptiveTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ATTR_DLL_LOCAL AdaptiveTree
AdaptiveTree(const AdaptiveTree& left);
virtual ~AdaptiveTree() = default;

virtual TreeType GetTreeType() { return TreeType::UNKNOWN; }
virtual TreeType GetTreeType() const { return TreeType::UNKNOWN; }

/*!
* \brief Configure the adaptive tree.
Expand Down
2 changes: 1 addition & 1 deletion src/parser/DASHTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ATTR_DLL_LOCAL CDashTree : public adaptive::AdaptiveTree
std::string_view supportedKeySystem,
std::string_view manifestUpdParams) override;

virtual TreeType GetTreeType() override { return TreeType::DASH; }
virtual TreeType GetTreeType() const override { return TreeType::DASH; }

virtual bool Open(std::string_view url,
const std::map<std::string, std::string>& headers,
Expand Down
2 changes: 1 addition & 1 deletion src/parser/HLSTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ATTR_DLL_LOCAL CHLSTree : public AdaptiveTree
CHLSTree();
virtual ~CHLSTree() {}

virtual TreeType GetTreeType() override { return TreeType::HLS; }
virtual TreeType GetTreeType() const override { return TreeType::HLS; }

CHLSTree(const CHLSTree& left);

Expand Down
2 changes: 1 addition & 1 deletion src/parser/SmoothTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ATTR_DLL_LOCAL CSmoothTree : public AdaptiveTree
CSmoothTree();
CSmoothTree(const CSmoothTree& left);

virtual TreeType GetTreeType() override { return TreeType::SMOOTH_STREAMING; }
virtual TreeType GetTreeType() const override { return TreeType::SMOOTH_STREAMING; }

virtual bool Open(std::string_view url,
const std::map<std::string, std::string>& headers,
Expand Down
11 changes: 9 additions & 2 deletions src/samplereader/SubtitleSampleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#include "SubtitleSampleReader.h"

#include "CompKodiProps.h"
#include "CompResources.h"
#include "SrvBroker.h"
#include "Stream.h"
#include "AdaptiveByteStream.h"
#include "codechandler/TTMLCodecHandler.h"
#include "codechandler/WebVTTCodecHandler.h"
#include "common/AdaptiveStream.h"
#include "common/AdaptiveTree.h"
#include "common/Representation.h"
#include "utils/CurlUtils.h"
#include "utils/StringUtils.h"
Expand Down Expand Up @@ -161,11 +163,16 @@ AP4_Result CSubtitleSampleReader::ReadSample()
AP4_UI32 duration =
static_cast<AP4_UI32>((segDur * STREAM_TIME_BASE) / rep->GetTimescale());

uint64_t startPts = currentSegment->startPTS_;

//! @todo: startPTS workaround! pts has been taken by substracting the period start
//! this just to have a lower pts value, but the real problem is in CSession::GetNextSample
//! that that makes an incorrect comparison of DTSorPTS
const uint64_t pStart = m_adStream->getPeriod()->GetStart() * rep->GetTimescale() / 1000;
const uint64_t startPts = currentSegment->startPTS_ - pStart;
if (CSrvBroker::GetResources().GetTree().GetTreeType() == adaptive::TreeType::HLS)
{
const uint64_t pStart = m_adStream->getPeriod()->GetStart() * rep->GetTimescale() / 1000;
startPts -= pStart;
}

AP4_UI64 pts = (startPts * STREAM_TIME_BASE) / rep->GetTimescale();

Expand Down

0 comments on commit b9c6a90

Please sign in to comment.