Skip to content
2 changes: 1 addition & 1 deletion MediaStreamContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ bool CacheFragmentData(const FragmentCacheDescriptor& desc);
* @param[in] http error code
* @return void
*/
void ProcessPlaylist(AampGrowableBuffer& newPlaylist, int http_error) override {};
void ProcessPlaylist(std::vector<uint8_t>& newPlaylist, int http_error) override {};
/**
* @fn resetAbort
* @param[in] bool value
Expand Down
6 changes: 3 additions & 3 deletions StreamAbstractionAAMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class MediaTrack
*
* @return void
*/
virtual void ProcessPlaylist(AampGrowableBuffer& newPlaylist, int http_error) = 0;
virtual void ProcessPlaylist(std::vector<uint8_t>& newPlaylist, int http_error) = 0;
/**
* @fn GetPlaylistUrl
*
Expand Down Expand Up @@ -849,8 +849,8 @@ class MediaTrack
std::shared_ptr<IsoBmffHelper> mIsoBmffHelper; /**< Helper class for ISO BMFF parsing */
CachedFragment *mCachedFragment; /**< storage for currently-downloaded fragment */
CachedFragment mCachedFragmentChunks[DEFAULT_CACHED_FRAGMENT_CHUNKS_PER_TRACK];
AampGrowableBuffer unparsedBufferChunk; /**< Buffer to keep fragment content */
AampGrowableBuffer parsedBufferChunk; /**< Buffer to keep fragment content */
std::vector<uint8_t> unparsedBufferChunk{}; /**< Unparsed buffer chunk for ISOBMFF chunk processing */
std::vector<uint8_t> parsedBufferChunk{}; /**< Parsed buffer chunk for ISOBMFF chunk processing */
bool abort; /**< Abort all operations if flag is set*/
std::mutex mutex; /**< protection of track variables accessed from multiple threads */
bool ptsError; /**< flag to indicate if last injected fragment has ptsError */
Expand Down
10 changes: 3 additions & 7 deletions fragmentcollector_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ int TrackState::GetDefaultDurationBetweenPlaylistUpdates()
/**
* @brief Function to Parse/Index playlist after being downloaded.
*/
void TrackState::ProcessPlaylist(AampGrowableBuffer& newPlaylist, int http_error)
void TrackState::ProcessPlaylist(std::vector<uint8_t>& newPlaylist, int http_error)
{
AAMPLOG_TRACE("[%s] Enter", name);
if (newPlaylist.size() )
Expand All @@ -2334,8 +2334,7 @@ void TrackState::ProcessPlaylist(AampGrowableBuffer& newPlaylist, int http_error

AcquirePlaylistLock();
// Free previous playlist buffer and load with new one
playlist.Free();
playlist.Replace( &newPlaylist );
playlist.GetVector() = std::move(newPlaylist);

AampTime culled{};
IndexPlaylist(true, culled);
Expand Down Expand Up @@ -2379,10 +2378,7 @@ void TrackState::ProcessPlaylist(AampGrowableBuffer& newPlaylist, int http_error
else
{
// Clear data if any
if (newPlaylist.capacity() != 0)
{
newPlaylist.Free();
}
aamp_utils::ClearAndRelease(newPlaylist);

if (aamp->DownloadsAreEnabled())
{
Expand Down
2 changes: 1 addition & 1 deletion fragmentcollector_hls.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class TrackState : public MediaTrack
*
* @return none
****************************************************************************/
void ProcessPlaylist(AampGrowableBuffer& newPlaylist, int http_error) override;
void ProcessPlaylist(std::vector<uint8_t>& newPlaylist, int http_error) override;

/**
* @brief Get byteRangeLength and byteRangeOffset from fragmentInfo.
Expand Down
4 changes: 2 additions & 2 deletions isobmff/isobmffbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void IsoBmffBuffer::setBuffer(const std::vector<uint8_t> &buffer)
* @return true if parsed or false
* @brief Parse ISOBMFF boxes from buffer
*/
bool IsoBmffBuffer::ParseChunkData(const char* name, char* &unParsedBuffer, uint32_t timeScale,
bool IsoBmffBuffer::ParseChunkData(const char* name, uint8_t* &unParsedBuffer, uint32_t timeScale,
size_t & parsedBufferSize, size_t &unParsedBufferSize, double& fpts, double &fduration)
{
size_t mdatCount = 0;
Expand Down Expand Up @@ -702,7 +702,7 @@ bool IsoBmffBuffer::getChunkedfBoxMetaData(uint32_t &offset, std::string &type,
/**
* @brief Get list of box handles in a parsed buffer
*/
int IsoBmffBuffer::UpdateBufferData(size_t parsedBoxCount, char* &unParsedBuffer, size_t &unParsedBufferSize, size_t & parsedBufferSize)
int IsoBmffBuffer::UpdateBufferData(size_t parsedBoxCount, uint8_t* &unParsedBuffer, size_t &unParsedBufferSize, size_t & parsedBufferSize)
{
std::vector<Box*> *pBoxes = getParsedBoxes();
size_t mdatCount;
Expand Down
4 changes: 2 additions & 2 deletions isobmff/isobmffbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class IsoBmffBuffer
* @fn UpdateBufferData
* @return true if parsed or false
*/
int UpdateBufferData(size_t parsedBoxCount, char* &unParsedBuffer, size_t &unParsedBufferSize, size_t & parsedBufferSize);
int UpdateBufferData(size_t parsedBoxCount, uint8_t* &unParsedBuffer, size_t &unParsedBufferSize, size_t & parsedBufferSize);

/**
* @fn getTotalChunkDurationInTicks
Expand Down Expand Up @@ -244,7 +244,7 @@ class IsoBmffBuffer
* @return true if parsed or false
* @brief Parse ISOBMFF boxes from buffer
*/
bool ParseChunkData(const char* name, char* &unParsedBuffer, uint32_t timeScale,
bool ParseChunkData(const char* name, uint8_t* &unParsedBuffer, uint32_t timeScale,
size_t & parsedBufferSize, size_t &unParsedBufferSize, double& fpts, double &fduration);

/**
Expand Down
49 changes: 21 additions & 28 deletions streamabstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ void MediaTrack::UpdateTSAfterChunkInject()
prevDownloadStartTime = mCachedFragmentChunks[fragmentChunkIdxToInject].downloadStartTime;
aamp_utils::ClearAndRelease(mCachedFragmentChunks[fragmentChunkIdxToInject].fragment);

parsedBufferChunk.Free();
//memset(&parsedBufferChunk, 0x00, sizeof(AampGrowableBuffer));
aamp_utils::ClearAndRelease(parsedBufferChunk);

//increment Inject Index
++fragmentChunkIdxToInject;
Expand Down Expand Up @@ -993,26 +992,25 @@ bool MediaTrack::ProcessFragmentChunk()
cachedFragment->initFragment = false;
return true;
}
if((cachedFragment->downloadStartTime != prevDownloadStartTime) && (unparsedBufferChunk.capacity() != 0))
if((cachedFragment->downloadStartTime != prevDownloadStartTime) && (!unparsedBufferChunk.empty()))
{
AAMPLOG_WARN("[%s] clean up curl chunk buffer, since prevDownloadStartTime[%" PRIu64 "] != currentdownloadtime[%" PRIu64 "]", name,prevDownloadStartTime,cachedFragment->downloadStartTime);
unparsedBufferChunk.Free();
aamp_utils::ClearAndRelease(unparsedBufferChunk);
}
size_t requiredLength = cachedFragment->fragment.size() + unparsedBufferChunk.size();
AAMPLOG_DEBUG("[%s] cachedFragment->fragment.len [%zu] to unparsedBufferChunk.len [%zu] Required Len [%zu]", name, cachedFragment->fragment.size(), unparsedBufferChunk.size(), requiredLength);

//Append Cache buffer to unparsed buffer for processing
unparsedBufferChunk.insert(unparsedBufferChunk.GetVector().end(),
unparsedBufferChunk.insert(unparsedBufferChunk.end(),
cachedFragment->fragment.data(),
cachedFragment->fragment.data() + cachedFragment->fragment.size());

//Parse Chunk Data
IsoBmffBuffer isobuf; /**< Fragment Chunk buffer box parser*/
char *unParsedBuffer = NULL;
uint8_t *unParsedBuffer = unparsedBufferChunk.data();
size_t parsedBufferSize = 0, unParsedBufferSize = 0;
unParsedBuffer = reinterpret_cast<char*>(unparsedBufferChunk.data());
unParsedBufferSize = parsedBufferSize = unparsedBufferChunk.size();
isobuf.setBuffer(unparsedBufferChunk.GetVector());
isobuf.setBuffer(unparsedBufferChunk);
AAMPLOG_TRACE("[%s] Unparsed Buffer Size: %zu", name,unparsedBufferChunk.size() );

bool bParse = false;
Expand Down Expand Up @@ -1067,7 +1065,7 @@ bool MediaTrack::ProcessFragmentChunk()
if(parsedBufferSize)
{
//Prepare parsed buffer
parsedBufferChunk.insert(parsedBufferChunk.GetVector().end(),
parsedBufferChunk.insert(parsedBufferChunk.end(),
unparsedBufferChunk.data(),
unparsedBufferChunk.data() + parsedBufferSize);
if (ISCONFIGSET(eAAMPConfig_EnablePTSReStamp))
Expand All @@ -1076,14 +1074,14 @@ bool MediaTrack::ProcessFragmentChunk()
{
AAMPLOG_INFO("%s LLD chunk fpts = %f, absPosition = %f", name, fpts, cachedFragment->absPosition);
fpts = cachedFragment->absPosition;
TrickModePtsRestamp(parsedBufferChunk.GetVector(),fpts,fduration,cachedFragment->initFragment,cachedFragment->discontinuity);
TrickModePtsRestamp(parsedBufferChunk,fpts,fduration,cachedFragment->initFragment,cachedFragment->discontinuity);
}
else
{
if (!ISCONFIGSET(eAAMPConfig_UseMp4Demux))
{
int64_t ptsOffset = cachedFragment->PTSOffsetSec * cachedFragment->timeScale;
(void)mIsoBmffHelper->RestampPts(parsedBufferChunk.GetVector(), ptsOffset, cachedFragment->uri,
(void)mIsoBmffHelper->RestampPts(parsedBufferChunk, ptsOffset, cachedFragment->uri,
name, cachedFragment->timeScale);
fpts += cachedFragment->PTSOffsetSec;
}
Expand All @@ -1101,7 +1099,7 @@ bool MediaTrack::ProcessFragmentChunk()
AAMPLOG_MIL( "curl-inject type=%d", type );
}
AAMPLOG_INFO("Injecting chunk for %s br=%" BITSPERSECOND_FORMAT ",chunksize=%zu fpts=%f fduration=%f", name, bandwidthBitsPerSecond, parsedBufferChunk.size(), fpts, fduration);
InjectFragmentChunkInternal((AampMediaType)type, parsedBufferChunk.GetVector(), fpts, fpts, fduration, cachedFragment->PTSOffsetSec);
InjectFragmentChunkInternal((AampMediaType)type, parsedBufferChunk, fpts, fpts, fduration, cachedFragment->PTSOffsetSec);
totalInjectedChunksDuration += fduration;
}
}
Expand All @@ -1111,20 +1109,16 @@ bool MediaTrack::ProcessFragmentChunk()
if(unParsedBufferSize)
{
AAMPLOG_TRACE("[%s] unparsed[%p] unparsed_size[%zu]", name,unParsedBuffer,unParsedBufferSize);
AampGrowableBuffer tempBuffer("tempBuffer");
tempBuffer.assign(unParsedBuffer, unParsedBuffer + unParsedBufferSize);
unparsedBufferChunk.Free();
unparsedBufferChunk.assign(tempBuffer.GetVector().data(),
tempBuffer.GetVector().data() + tempBuffer.GetVector().size());
tempBuffer.Free();
// unParsedBuffer was advanced by ParseChunkData past the parsed data
std::vector<uint8_t> remaining(unParsedBuffer, unParsedBuffer + unParsedBufferSize);
unparsedBufferChunk = std::move(remaining);
}
else
{
AAMPLOG_TRACE("[%s] Set Unparsed Buffer chunk Empty...", name);
unparsedBufferChunk.Free();
//memset(&unparsedBufferChunk, 0x00, sizeof(AampGrowableBuffer));
aamp_utils::ClearAndRelease(unparsedBufferChunk);
}
parsedBufferChunk.Free();
aamp_utils::ClearAndRelease(parsedBufferChunk);
return true;
}

Expand Down Expand Up @@ -1976,8 +1970,8 @@ void MediaTrack::FlushFragments()
{
mCachedFragmentChunks[i].Clear();
}
unparsedBufferChunk.Free();
parsedBufferChunk.Free();
aamp_utils::ClearAndRelease(unparsedBufferChunk);
aamp_utils::ClearAndRelease(parsedBufferChunk);
fragmentChunkIdxToInject = 0;
fragmentChunkIdxToFetch = 0;
std::lock_guard<std::mutex> guard(mutex);
Expand Down Expand Up @@ -2037,7 +2031,7 @@ MediaTrack::MediaTrack(TrackType type, PrivateInstanceAAMP* aamp, const char* na
discontinuityProcessed(false), ptsError(false), mCachedFragment(NULL), name(name), type(type), aamp(aamp),
mutex(), fragmentFetched(), fragmentInjected(), abortInject(false),
mSubtitleParser(), refreshSubtitles(false), refreshAudio(false), maxCachedFragmentsPerTrack(0),
mCachedFragmentChunks{}, unparsedBufferChunk{"unparsedBufferChunk"}, parsedBufferChunk{"parsedBufferChunk"}, fragmentChunkFetched(), fragmentChunkInjected(), maxCachedFragmentChunksPerTrack(0),
mCachedFragmentChunks{}, fragmentChunkFetched(), fragmentChunkInjected(), maxCachedFragmentChunksPerTrack(0),
noMDATCount(0), loadNewAudio(false), audioFragmentCached(), audioMutex(), loadNewSubtitle(false), subtitleFragmentCached(), subtitleMutex(),
abortPlaylistDownloader(true), plDownloadWait()
,dwnldMutex(), playlistDownloaderThread(NULL), mManifestUpdateCounter(0)
Expand Down Expand Up @@ -4475,7 +4469,7 @@ void MediaTrack::PlaylistDownloader()
*/
if(aamp->DownloadsAreEnabled())
{
AampGrowableBuffer manifest("download-PlaylistManifest");
std::vector<uint8_t> manifest;
// reset quickPlaylistDownload for live playlist
quickPlaylistDownload = false;
std::string manifestUrl = GetPlaylistUrl();
Expand All @@ -4484,7 +4478,6 @@ void MediaTrack::PlaylistDownloader()
bool gotManifest = false;
int http_error = 0;
double downloadTime;
manifest.clear();

/*
*
Expand All @@ -4498,7 +4491,7 @@ void MediaTrack::PlaylistDownloader()
SetLastPlaylistDownloadTime(lastPlaylistDownloadTime);
}

if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(manifestUrl, manifest.GetVector(), effectiveUrl,mediaType))
if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(manifestUrl, manifest, effectiveUrl,mediaType))
{
gotManifest = true;
AAMPLOG_INFO("manifest[%s] retrieved from cache", trackName.c_str());
Expand All @@ -4512,7 +4505,7 @@ void MediaTrack::PlaylistDownloader()
AAMPLOG_INFO("[%s] Re-enabling media download", trackName.c_str());
aamp->EnableMediaDownloads(mediaType);
}
gotManifest = aamp->GetFile(manifestUrl, mediaType, manifest.GetVector(), effectiveUrl, &http_error, &downloadTime, NULL, curlInstance, true );
gotManifest = aamp->GetFile(manifestUrl, mediaType, manifest, effectiveUrl, &http_error, &downloadTime, NULL, curlInstance, true );
if(seamlessAudioSwitchInProgress && (manifestUrl != GetPlaylistUrl()))
{
//new Playlist updated in mid.
Expand Down
4 changes: 2 additions & 2 deletions test/utests/fakes/FakeIsoBmffBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool IsoBmffBuffer::parseBuffer(bool correctBoxSize, int newTrackId)
}
}

bool IsoBmffBuffer::ParseChunkData(const char* name, char* &unParsedBuffer, uint32_t timeScale,
bool IsoBmffBuffer::ParseChunkData(const char* name, uint8_t* &unParsedBuffer, uint32_t timeScale,
size_t & parsedBufferSize, size_t &unParsedBufferSize, double& fpts, double &fduration)
{
if (g_mockIsoBmffBuffer)
Expand Down Expand Up @@ -166,7 +166,7 @@ bool IsoBmffBuffer::getChunkedfBoxMetaData(uint32_t &offset, std::string &type,
}
}

int IsoBmffBuffer::UpdateBufferData(size_t parsedBoxCount, char *&unParsedBuffer, size_t &unParsedBufferSize, size_t &parsedBufferSize)
int IsoBmffBuffer::UpdateBufferData(size_t parsedBoxCount, uint8_t* &unParsedBuffer, size_t &unParsedBufferSize, size_t &parsedBufferSize)
{
if (g_mockIsoBmffBuffer)
{
Expand Down
2 changes: 1 addition & 1 deletion test/utests/fakes/FakeStreamAbstractionAamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bool MediaTrack::isPlaylistDownloaderThreadStarted()
return true;
}

MediaTrack::MediaTrack(TrackType type, PrivateInstanceAAMP* aamp, const char* name) : parsedBufferChunk("parsedBufferChunk"), unparsedBufferChunk("unparsedBufferChunk"), name(name), aamp(aamp), type(type), abort(false), abortInject(false)
MediaTrack::MediaTrack(TrackType type, PrivateInstanceAAMP* aamp, const char* name) : name(name), aamp(aamp), type(type), abort(false), abortInject(false)
{
}

Expand Down
4 changes: 2 additions & 2 deletions test/utests/mocks/MockIsoBmffBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class MockIsoBmffBuffer : public IsoBmffBuffer
MOCK_METHOD(bool, getMdatBoxCount, (size_t&));
MOCK_METHOD(size_t, getParsedBoxesSize, ());
MOCK_METHOD(bool, getChunkedfBoxMetaData, (uint32_t &, std::string &, uint32_t &));
MOCK_METHOD(int, UpdateBufferData, (size_t , char* &, size_t &, size_t& ));
MOCK_METHOD(int, UpdateBufferData, (size_t , uint8_t* &, size_t &, size_t& ));
MOCK_METHOD(uint64_t, getTotalChunkDurationInTicks, (int));
MOCK_METHOD(bool, ParseChunkData, (const char* , char* &, uint32_t, size_t & , size_t &, double& , double &));
MOCK_METHOD(bool, ParseChunkData, (const char* , uint8_t* &, uint32_t, size_t & , size_t &, double& , double &));
MOCK_METHOD(bool, setTrickmodeTimescale, (uint32_t));
MOCK_METHOD(bool, setMediaHeaderDuration, (uint64_t));
MOCK_METHOD(bool, getMdatBoxInfo, (size_t, size_t&, size_t&));
Expand Down
2 changes: 1 addition & 1 deletion test/utests/mocks/MockMediaTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MockMediaTrack : public MediaTrack
MOCK_METHOD(void, SetLocalTSBInjection, (bool value));
MOCK_METHOD(bool, IsLocalTSBInjection, ());
MOCK_METHOD(bool, Enabled, ());
MOCK_METHOD(void, ProcessPlaylist, (AampGrowableBuffer& newPlaylist, int http_error), (override));
MOCK_METHOD(void, ProcessPlaylist, (std::vector<uint8_t>& newPlaylist, int http_error), (override));
MOCK_METHOD(std::string&, GetPlaylistUrl, (), (override));
MOCK_METHOD(std::string&, GetEffectivePlaylistUrl, (), (override));
MOCK_METHOD(void, SetEffectivePlaylistUrl, (std::string url), (override));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST_F(MediaStreamContextTest, CacheFragmentChunkTest)

TEST_F(MediaStreamContextTest,ProcessPlaylistTest)
{
AampGrowableBuffer newPlaylist("download-PlaylistManifest");
std::vector<uint8_t> newPlaylist;
//Act:call ProcessPlaylist function
mMediaStreamContext->ProcessPlaylist(newPlaylist,1);
}
Expand Down
2 changes: 1 addition & 1 deletion test/utests/tests/MediaTrackTests/MediaTrackTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class TestableMediaTrack : public MediaTrack
}

// Provide overrides for pure virtuals - this is just to keep the compiler happy
void ProcessPlaylist(AampGrowableBuffer&, int) override {};
void ProcessPlaylist(std::vector<uint8_t>&, int) override {};
std::string& GetPlaylistUrl() override { return mFakeStr; };
std::string& GetEffectivePlaylistUrl() override { return mFakeStr; };
void SetEffectivePlaylistUrl(std::string) override {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ TEST_F(TrackStateTests, GetNextFragmentUri_WithReloadUri_new14)

TEST_F(TrackStateTests, ABRProfileChangedTest)
{
AampGrowableBuffer newPlaylist("test");
std::vector<uint8_t> newPlaylist;
int http_error = 2;
TrackStateobj->IsLive();
TrackStateobj->ProcessPlaylist(newPlaylist, http_error);
Expand Down
4 changes: 2 additions & 2 deletions test/utests/tests/TrackInjectTests/TrackInjectTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MediaTrackTest : public MediaTrack
playlistURL = "http://host/asset/low/manifest.mpd";
}

void ProcessPlaylist(AampGrowableBuffer &newPlaylist, int http_error)
void ProcessPlaylist(std::vector<uint8_t> &newPlaylist, int http_error)
{
}

Expand Down Expand Up @@ -349,7 +349,7 @@ TEST_F(TrackInjectTests, RunInjectLoopTestLLD)
.WillOnce(Return(true));
EXPECT_CALL(*g_mockPrivateInstanceAAMP, IsLocalAAMPTsbInjection()).WillRepeatedly(Return(false));

char unParsedBuffer[] = "AAAAAAAAAAAAAAAAAA";
uint8_t unParsedBuffer[] = "AAAAAAAAAAAAAAAAAA";
int parsedBufferSize = 12, unParsedBufferSize = sizeof(unParsedBuffer);
double pts = 10.0, duration = 0.48;
EXPECT_CALL(*g_mockIsoBmffBuffer, ParseChunkData(_, _, _, _, _, _, _))
Expand Down
Loading