mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-10-06 21:55:22 +00:00
dash异常片源兼容
Signed-off-by: w00526960 <winson.wang@huawei.com>
This commit is contained in:
parent
e3be667cba
commit
5c4034d13f
@ -16,6 +16,7 @@
|
||||
#include <mutex>
|
||||
#include <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include "plugin/plugin_time.h"
|
||||
@ -681,8 +682,7 @@ void DashMpdDownloader::ParseSidx()
|
||||
currentDownloadStream_->initSegment_->rangeBegin_;
|
||||
if (initLen >= 0 && (unsigned int)initLen < downloadContent_.size()) {
|
||||
sidxContent = downloadContent_.substr((unsigned int)initLen);
|
||||
MEDIA_LOG_I("ParseSidx update sidx segment content size is " PUBLIC_LOG_ZU ", "
|
||||
PUBLIC_LOG_C "-" PUBLIC_LOG_C, sidxContent.size(), sidxContent[0], sidxContent[1]);
|
||||
MEDIA_LOG_I("ParseSidx update sidx segment content size is " PUBLIC_LOG_ZU, sidxContent.size());
|
||||
}
|
||||
}
|
||||
|
||||
@ -715,12 +715,20 @@ void DashMpdDownloader::ParseSidx()
|
||||
void DashMpdDownloader::BuildDashSegment(std::list<std::shared_ptr<SubSegmentIndex>> &subSegIndexList) const
|
||||
{
|
||||
uint64_t segDurSum = 0; // the sum of segment duration, not devide timescale
|
||||
unsigned int segAddDuration = 0; // add all segments duration(ms) before current segment
|
||||
uint64_t segAddDuration = 0; // add all segments duration(ms) before current segment
|
||||
uint32_t timeScale = 1;
|
||||
int64_t segSeq = currentDownloadStream_->startNumberSeq_;
|
||||
for (const auto &subSegIndex : subSegIndexList) {
|
||||
unsigned int durationMS = (static_cast<uint64_t>(subSegIndex->duration_) * S_2_MS) / subSegIndex->timeScale_;
|
||||
timeScale = (subSegIndex->timeScale_ > 0) ? subSegIndex->timeScale_ : 1;
|
||||
uint64_t durationMS = (static_cast<uint64_t>(subSegIndex->duration_) * S_2_MS) / timeScale;
|
||||
segDurSum += subSegIndex->duration_;
|
||||
unsigned int segDurMsSum = static_cast<unsigned int>((segDurSum * S_2_MS) / subSegIndex->timeScale_);
|
||||
uint64_t segDurMsSum = (segDurSum * S_2_MS) / timeScale;
|
||||
if (segDurMsSum >= UINT_MAX) {
|
||||
MEDIA_LOG_W("segDurMsSum is too large: " PUBLIC_LOG_U64 ", timeScale: "
|
||||
PUBLIC_LOG_U32, segDurMsSum, timeScale);
|
||||
break;
|
||||
}
|
||||
|
||||
if (segDurMsSum > segAddDuration) {
|
||||
durationMS = segDurMsSum - segAddDuration;
|
||||
}
|
||||
@ -730,7 +738,7 @@ void DashMpdDownloader::BuildDashSegment(std::list<std::shared_ptr<SubSegmentInd
|
||||
DashSegment srcSegment;
|
||||
srcSegment.streamId_ = currentDownloadStream_->streamId_;
|
||||
srcSegment.bandwidth_ = currentDownloadStream_->bandwidth_;
|
||||
srcSegment.duration_ = durationMS;
|
||||
srcSegment.duration_ = (uint32_t)durationMS;
|
||||
srcSegment.startNumberSeq_ = currentDownloadStream_->startNumberSeq_;
|
||||
srcSegment.numberSeq_ = segSeq++;
|
||||
srcSegment.startRangeValue_ = subSegIndex->startPos_;
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
~SidxBoxParser();
|
||||
|
||||
private:
|
||||
static void BuildSubSegmentIndexes(char *bitStream, int64_t sidxEndOffset,
|
||||
static bool BuildSubSegmentIndexes(char *bitStream, uint32_t streamSize, int64_t sidxEndOffset,
|
||||
DashList<std::shared_ptr<SubSegmentIndex>> &subSegIndexTable, uint32_t &currPos);
|
||||
|
||||
private:
|
||||
|
@ -38,6 +38,7 @@ namespace {
|
||||
constexpr unsigned int BUFF_INDEX_1 = 1;
|
||||
constexpr unsigned int BUFF_INDEX_2 = 2;
|
||||
constexpr unsigned int BUFF_INDEX_3 = 3;
|
||||
constexpr unsigned int SIDX_REFERENCE_ITEM_SIZE = 12; // bytes of one referenced item
|
||||
}
|
||||
|
||||
static inline unsigned short Get2Bytes(char *buffer, uint32_t &currPos);
|
||||
@ -65,7 +66,9 @@ int32_t SidxBoxParser::ParseSidxBox(char *bitStream, uint32_t streamSize, int64_
|
||||
uint32_t boxType = Get4Bytes(bitStream, currPos);
|
||||
if (boxType == BEM_SIDX) {
|
||||
MEDIA_LOG_D("it is a sidx box");
|
||||
BuildSubSegmentIndexes(bitStream, sidxEndOffset, subSegIndexTable, currPos);
|
||||
if (!BuildSubSegmentIndexes(bitStream, streamSize, sidxEndOffset, subSegIndexTable, currPos)) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
MEDIA_LOG_W("sdix box error box=(%c %c %c %c), typeSize="
|
||||
PUBLIC_LOG_D32, (boxType >> SHIFT_NUM_24) & 0x000000ff, (boxType >> SHIFT_NUM_16) & 0x000000ff,
|
||||
@ -77,7 +80,7 @@ int32_t SidxBoxParser::ParseSidxBox(char *bitStream, uint32_t streamSize, int64_
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SidxBoxParser::BuildSubSegmentIndexes(char *bitStream, int64_t sidxEndOffset,
|
||||
bool SidxBoxParser::BuildSubSegmentIndexes(char *bitStream, uint32_t streamSize, int64_t sidxEndOffset,
|
||||
DashList<std::shared_ptr<SubSegmentIndex>> &subSegIndexTable,
|
||||
uint32_t &currPos)
|
||||
{
|
||||
@ -107,6 +110,13 @@ void SidxBoxParser::BuildSubSegmentIndexes(char *bitStream, int64_t sidxEndOffse
|
||||
ForwardBytes(currPos, SHIFT_NUM_2);
|
||||
|
||||
uint32_t referenceCount = Get2Bytes(bitStream, currPos);
|
||||
if ((referenceCount * SIDX_REFERENCE_ITEM_SIZE + currPos) > streamSize) {
|
||||
MEDIA_LOG_W("sidx box reference count error: " PUBLIC_LOG_U32 ", currPos:" PUBLIC_LOG_U32 ", streamSize:"
|
||||
PUBLIC_LOG_U32, referenceCount, currPos, streamSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
MEDIA_LOG_D("sidx box reference count " PUBLIC_LOG_U32, referenceCount);
|
||||
for (uint32_t i = 0; i < referenceCount; i++) {
|
||||
std::shared_ptr<SubSegmentIndex> subSegIndex = std::make_shared<SubSegmentIndex>();
|
||||
uint32_t typeAndSize = Get4Bytes(bitStream, currPos);
|
||||
@ -120,7 +130,7 @@ void SidxBoxParser::BuildSubSegmentIndexes(char *bitStream, int64_t sidxEndOffse
|
||||
Get4Bytes(bitStream, currPos); // uint32_t sapInfo
|
||||
subSegIndexTable.push_back(subSegIndex);
|
||||
}
|
||||
MEDIA_LOG_D("sidx box reference count " PUBLIC_LOG_U32, referenceCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned short Get2Bytes(char *buffer, uint32_t &currPos)
|
||||
|
Loading…
Reference in New Issue
Block a user