Skip to content

Commit 3bf778e

Browse files
committed
VPLAY-11143: AAMP mp4Demux Integration
Reason for change: Integrate mp4Demux formally into AAMP Test Procedure: Test with useMp4Demux=true and validate all types of Linear, VOD content in all apps. Risks: Low Signed-off-by: Vinish100 <[email protected]>
1 parent 2d149af commit 3bf778e

22 files changed

+1896
-225
lines changed

AampDemuxDataTypes.h

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* If not stated otherwise in this file or this component's license file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2025 RDK Management
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifndef __AAMP_DEMUX_DATA_TYPES_H__
21+
#define __AAMP_DEMUX_DATA_TYPES_H__
22+
23+
#include <string>
24+
#include <vector>
25+
#include "AampGrowableBuffer.h" // for AampGrowableBuffer
26+
#include "AampTime.h" // for AampTime
27+
#include "StreamOutputFormat.h" // for StreamOutputFormat
28+
#include "AampMediaType.h" // for AampMediaType
29+
30+
struct AampPsshData
31+
{
32+
std::string systemID; // 16 bytes UUID
33+
std::vector<uint8_t> pssh; // variable length
34+
};
35+
36+
struct AampCodecInfo
37+
{
38+
StreamOutputFormat mCodecFormat; // FORMAT_VIDEO_ES_H264, etc
39+
std::vector<uint8_t> mCodecData; // codec private data, e.g. avcC box
40+
AampMediaType mType;
41+
bool mIsEncrypted;
42+
union
43+
{
44+
struct
45+
{
46+
uint16_t mChannelCount;
47+
uint16_t mSampleSize;
48+
uint16_t mSampleRate;
49+
uint8_t mObjectTypeId;
50+
uint8_t mStreamType;
51+
uint8_t mUpStream;
52+
uint16_t mBufferSize;
53+
uint32_t mMaxBitrate;
54+
uint32_t mAvgBitrate;
55+
} audio;
56+
57+
struct
58+
{
59+
uint16_t mWidth;
60+
uint16_t mHeight;
61+
uint16_t mFrameCount;
62+
uint16_t mDepth;
63+
uint32_t mHorizontalResolution;
64+
uint32_t mVerticalResolution;
65+
} video;
66+
} mInfo;
67+
68+
AampCodecInfo() : mCodecFormat(FORMAT_INVALID), mIsEncrypted(false), mCodecData()
69+
{
70+
std::memset(&mInfo, 0, sizeof(mInfo));
71+
}
72+
73+
AampCodecInfo(StreamOutputFormat format) : mCodecFormat(format), mIsEncrypted(false), mCodecData()
74+
{
75+
std::memset(&mInfo, 0, sizeof(mInfo));
76+
}
77+
};
78+
79+
struct AampDrmMetadata
80+
{
81+
bool mIsEncrypted;
82+
std::string mKeyId; // 16 bytes UUID
83+
std::vector<uint8_t> mIV; // 8 or 16 bytes
84+
std::string mCipher; // e.g. 'cenc', 'cbcs'
85+
std::string mOriginalMediaType; // 'vide' or 'soun'
86+
std::vector<uint8_t> mSubSamples; // optional subsample encryption data
87+
uint8_t mCryptByteBlock;
88+
uint8_t mSkipByteBlock;
89+
90+
AampDrmMetadata() : mIsEncrypted(false), mKeyId(), mIV(), mCipher(), mOriginalMediaType(),
91+
mSubSamples(), mCryptByteBlock(0), mSkipByteBlock(0)
92+
{
93+
}
94+
};
95+
96+
struct AampMediaSample
97+
{
98+
AampGrowableBuffer mData;
99+
AampTime mPts;
100+
AampTime mDts;
101+
AampTime mDuration;
102+
103+
AampDrmMetadata mDrmMetadata; // empty if not encrypted
104+
105+
AampMediaSample() : mData("AampMediaSample"), mPts(0), mDts(0), mDuration(0), mDrmMetadata()
106+
{
107+
}
108+
};
109+
110+
#endif /* __AAMP_DEMUX_DATA_TYPES_H__ */

AampStreamSinkInactive.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ class AampStreamSinkInactive : public StreamSink
7070
return false;
7171
}
7272
/**
73+
* @fn SendSample
74+
* @brief stub implementation for Inactive aamp instance
75+
*/
76+
virtual bool SendSample( AampMediaType mediaType, AampMediaSample& sample)
77+
{
78+
AAMPLOG_WARN("Called AAMPGstPlayer()::%s stub", __FUNCTION__);
79+
return false;
80+
}
81+
/**
7382
* @fn EndOfStreamReached
7483
* @brief stub implementation for Inactive aamp instance
7584
*/

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/jsbindings)
148148
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/jsbindings/PersistentWatermark)
149149
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/subtec/subtecparser)
150150
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/subtitle)
151-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/gstTestHarness)
151+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/mp4demux)
152152
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tsb/api)
153153

154154
# Locally built/installed dependencies are here
@@ -351,10 +351,12 @@ set(LIBAAMP_SOURCES
351351
subtec/subtecparser/WebvttSubtecDevParser.cpp
352352
AampTrackWorker.cpp AampTrackWorker.h
353353
LangCodePreference.h
354-
test/gstTestHarness/mp4demux.hpp
355354
AampTrackWorkerManager.cpp
356355
AampFragmentDescriptor.cpp
357356
AampTimeBasedBufferManager.cpp
357+
mp4demux/AampMp4Demuxer.cpp mp4demux/AampMp4Demuxer.h
358+
mp4demux/Mp4Demux.hpp
359+
AampDemuxDataTypes.h
358360
)
359361

360362
if(CMAKE_SOC_PLATFORM_RPI)
@@ -514,6 +516,7 @@ install(FILES
514516
MediaSegmentDownloadJob.hpp
515517
tsb/api/TsbApi.h
516518
LangCodePreference.h StreamOutputFormat.h VideoZoomMode.h StreamSink.h TimedMetadata.h
519+
AampDemuxDataTypes.h AampTime.h
517520
DESTINATION include
518521
)
519522

StreamAbstractionAAMP.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "AampTime.h"
4747
#include "AampTimeBasedBufferManager.hpp"
4848
#include "CachedFragment.h"
49+
#include "AampDemuxDataTypes.h"
4950

5051
/**
5152
* @brief Media Track Types
@@ -1992,6 +1993,8 @@ class StreamAbstractionAAMP : public AampLicenseFetcher
19921993
*/
19931994
void ReinitializeInjection(double rate);
19941995

1996+
virtual void GetStreamCodecInfo (AampCodecInfo &videoCodec, AampCodecInfo &audioCodec, AampCodecInfo &textCodec) { (void)videoCodec; (void)audioCodec; (void)textCodec; }
1997+
19951998
protected:
19961999
/**
19972000
* @brief Get stream information of a profile from subclass.

StreamSink.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "StreamOutputFormat.h"
2424
#include "AampMediaType.h"
25+
#include "AampDemuxDataTypes.h"
2526

2627
/**
2728
* @struct PlaybackQualityData
@@ -81,6 +82,8 @@ class StreamSink
8182
*/
8283
virtual bool SendTransfer( AampMediaType mediaType, void *ptr, size_t len, double fpts, double fdts, double fDuration, double fragmentPTSoffset, bool initFragment = false, bool discontinuity = false)= 0;
8384

85+
virtual bool SendSample( AampMediaType mediaType, AampMediaSample& sample ) = 0;
86+
8487
/**
8588
* @brief Checks pipeline is configured for media type
8689
*
@@ -390,6 +393,8 @@ class StreamSink
390393
*/
391394
virtual void NotifyInjectorToPause() {};
392395

396+
virtual void SetStreamCaps(AampMediaType type, const AampCodecInfo &codecInfo) {};
397+
393398
};
394399

395400
#endif // STREAM_SINK_H

aampgstplayer.cpp

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ static void InitializePlayerConfigs(AAMPGstPlayer *_this, void *playerInstance)
102102
interfacePlayer->m_gstConfigParam->audioOnlyMode = _this->aamp->mAudioOnlyPb;
103103
interfacePlayer->m_gstConfigParam->gstreamerSubsEnabled = _this->aamp->IsGstreamerSubsEnabled();
104104
interfacePlayer->m_gstConfigParam->media = _this->aamp->GetMediaFormatTypeEnum();
105-
interfacePlayer->m_gstConfigParam->useMp4Demux = config->IsConfigSet(eAAMPConfig_UseMp4Demux);
106105
}
107106

108107
/*
@@ -679,7 +678,7 @@ void AAMPGstPlayer::NotifyInjectorToResume()
679678
/**
680679
* @brief Inject stream buffer to gstreamer pipeline
681680
*/
682-
bool AAMPGstPlayer::SendHelper(AampMediaType mediaType, const void *ptr, size_t len, double fpts, double fdts, double fDuration, bool copy, double fragmentPTSoffset, bool initFragment, bool discontinuity)
681+
bool AAMPGstPlayer::SendHelper(AampMediaType mediaType, MediaSample sample, bool copy, bool initFragment, bool discontinuity)
683682
{
684683
if(ISCONFIGSET(eAAMPConfig_SuppressDecode))
685684
{
@@ -707,10 +706,10 @@ bool AAMPGstPlayer::SendHelper(AampMediaType mediaType, const void *ptr, size_t
707706
namespace aih = aamp::id3_metadata::helpers;
708707

709708
if (aih::IsValidMediaType(mediaType) &&
710-
aih::IsValidHeader(static_cast<const uint8_t*>(ptr), len))
709+
aih::IsValidHeader(static_cast<const uint8_t*>(sample.data), sample.dataSize))
711710
{
712-
m_ID3MetadataHandler(mediaType, static_cast<const uint8_t*>(ptr), len,
713-
{fpts, fdts, fDuration}, nullptr);
711+
m_ID3MetadataHandler(mediaType, static_cast<const uint8_t*>(sample.data), sample.dataSize,
712+
{sample.pts, sample.dts, sample.duration}, nullptr);
714713
}
715714
}
716715

@@ -723,7 +722,7 @@ bool AAMPGstPlayer::SendHelper(AampMediaType mediaType, const void *ptr, size_t
723722
{
724723
sendNewSegmentEvent = true;
725724
}
726-
bool bPushBuffer = playerInstance->SendHelper(mediaType, ptr, len, fpts, fdts, fDuration, fragmentPTSoffset, copy, initFragment, discontinuity, notifyFirstBufferProcessed, sendNewSegmentEvent, resetTrickUTC, firstBufferPushed);
725+
bool bPushBuffer = playerInstance->SendHelper(mediaType, std::move(sample), copy, initFragment, discontinuity, notifyFirstBufferProcessed, sendNewSegmentEvent, resetTrickUTC, firstBufferPushed);
727726
if(sendNewSegmentEvent)
728727
{
729728
aamp->mbNewSegmentEvtSent[mediaType] = true;
@@ -734,7 +733,8 @@ bool AAMPGstPlayer::SendHelper(AampMediaType mediaType, const void *ptr, size_t
734733
}
735734
if(bPushBuffer)
736735
{
737-
privateContext->mBufferControl[mediaType].notifyFragmentInject(this, mediaType, fpts, fdts, fDuration, discontinuity);
736+
// TODO: Accessing values from a moved object
737+
privateContext->mBufferControl[mediaType].notifyFragmentInject(this, mediaType, sample.pts, sample.dts, sample.duration, discontinuity);
738738
}
739739
if (eMEDIATYPE_VIDEO == mediaType)
740740
{
@@ -763,15 +763,29 @@ bool AAMPGstPlayer::SendHelper(AampMediaType mediaType, const void *ptr, size_t
763763
*/
764764
bool AAMPGstPlayer::SendCopy(AampMediaType mediaType, const void *ptr, size_t len, double fpts, double fdts, double fDuration)
765765
{
766-
return SendHelper( mediaType, ptr, len, fpts, fdts, fDuration, true /*copy*/, 0.0 );
766+
MediaSample sample;
767+
sample.data = ptr;
768+
sample.dataSize = len;
769+
sample.pts = fpts;
770+
sample.dts = fdts;
771+
sample.duration = fDuration;
772+
sample.ptsOffset = 0.0;
773+
return SendHelper( mediaType, std::move(sample), true /*copy*/ );
767774
}
768775

769776
/**
770777
* @brief inject mp4 segment to gstreamer pipeline
771778
*/
772779
bool AAMPGstPlayer::SendTransfer(AampMediaType mediaType, void *ptr, size_t len, double fpts, double fdts, double fDuration, double fragmentPTSoffset, bool initFragment, bool discontinuity)
773780
{
774-
return SendHelper( mediaType, ptr, len, fpts, fdts, fDuration, false /*transfer*/, fragmentPTSoffset, initFragment, discontinuity );
781+
MediaSample sample;
782+
sample.data = ptr;
783+
sample.dataSize = len;
784+
sample.pts = fpts;
785+
sample.dts = fdts;
786+
sample.duration = fDuration;
787+
sample.ptsOffset = fragmentPTSoffset;
788+
return SendHelper( mediaType, std::move(sample), false /*transfer*/, initFragment, discontinuity );
775789
}
776790

777791
/**
@@ -1312,3 +1326,63 @@ void AAMPGstPlayer::StopMonitorAvTimer()
13121326
AAMPLOG_MIL("MonitorAvTimer stopped");
13131327
}
13141328
}
1329+
1330+
void AAMPGstPlayer::SetStreamCaps(AampMediaType type, const AampCodecInfo &codecInfo)
1331+
{
1332+
CodecInfo gstCodecInfo;
1333+
gstCodecInfo.codecFormat = (GstStreamOutputFormat)codecInfo.mCodecFormat;
1334+
gstCodecInfo.codecData = std::move(codecInfo.mCodecData);
1335+
gstCodecInfo.isEncrypted = codecInfo.mIsEncrypted;
1336+
if (codecInfo.mType == eMEDIATYPE_VIDEO)
1337+
{
1338+
gstCodecInfo.info.video.width = codecInfo.mInfo.video.mWidth;
1339+
gstCodecInfo.info.video.height = codecInfo.mInfo.video.mHeight;
1340+
}
1341+
else if (codecInfo.mType == eMEDIATYPE_AUDIO)
1342+
{
1343+
gstCodecInfo.info.audio.channelCount = codecInfo.mInfo.audio.mChannelCount;
1344+
gstCodecInfo.info.audio.sampleRate = codecInfo.mInfo.audio.mSampleRate;
1345+
}
1346+
playerInstance->SetStreamCaps((GstMediaType)type, gstCodecInfo);
1347+
}
1348+
1349+
bool AAMPGstPlayer::SendSample(AampMediaType mediaType, AampMediaSample& sample)
1350+
{
1351+
bool ret = false;
1352+
MediaSample gstSample;
1353+
1354+
// Convert AampMediaSample to MediaSample
1355+
gstSample.data = sample.mData.GetPtr();
1356+
gstSample.dataSize = sample.mData.GetLen();
1357+
gstSample.pts = static_cast<double>(sample.mPts);
1358+
gstSample.dts = static_cast<double>(sample.mDts);
1359+
gstSample.duration = static_cast<double>(sample.mDuration);
1360+
// Sample is encrypted, set the DRM metadata
1361+
if (sample.mDrmMetadata.mIsEncrypted)
1362+
{
1363+
gstSample.drmMetadata.isEncrypted = true;
1364+
gstSample.drmMetadata.subSamples = std::move(sample.mDrmMetadata.mSubSamples);
1365+
gstSample.drmMetadata.keyId = std::move(sample.mDrmMetadata.mKeyId);
1366+
gstSample.drmMetadata.iv = std::move(sample.mDrmMetadata.mIV);
1367+
gstSample.drmMetadata.cipher = std::move(sample.mDrmMetadata.mCipher);
1368+
gstSample.drmMetadata.cryptByteBlock = sample.mDrmMetadata.mCryptByteBlock;
1369+
gstSample.drmMetadata.skipByteBlock = sample.mDrmMetadata.mSkipByteBlock;
1370+
gstSample.drmMetadata.originalMediaType = std::move(sample.mDrmMetadata.mOriginalMediaType);
1371+
}
1372+
else
1373+
{
1374+
gstSample.drmMetadata.isEncrypted = false;
1375+
}
1376+
1377+
ret = SendHelper( mediaType, std::move(gstSample), false /*transfer*/);
1378+
1379+
if (ret)
1380+
{
1381+
sample.mData.Transfer();
1382+
}
1383+
else
1384+
{
1385+
sample.mData.Free();
1386+
}
1387+
return ret;
1388+
}

aampgstplayer.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ class AAMPGstPlayer : public StreamSink
9191
{
9292
private:
9393
/**
94-
* @fn SendHelper
95-
* @param[in] mediaType stream type
96-
* @param[in] ptr buffer pointer
97-
* @param[in] len length of buffer
98-
* @param[in] fpts PTS of buffer (in sec)
99-
* @param[in] fdts DTS of buffer (in sec)
100-
* @param[in] duration duration of buffer (in sec)
101-
* @param[in] fragmentPTSoffset PTS offset
102-
* @param[in] copy to map or transfer the buffer
103-
* @param[in] initFragment flag for buffer type (init, data)
104-
*/
105-
bool SendHelper(AampMediaType mediaType, const void *ptr, size_t len, double fpts, double fdts, double duration, bool copy, double fragmentPTSoffset, bool initFragment = false, bool discontinuity = false);
94+
* @fn SendHelper
95+
* @param[in] mediaType stream type
96+
* @param[in] ptr buffer pointer
97+
* @param[in] len length of buffer
98+
* @param[in] fpts PTS of buffer (in sec)
99+
* @param[in] fdts DTS of buffer (in sec)
100+
* @param[in] duration duration of buffer (in sec)
101+
* @param[in] fragmentPTSoffset PTS offset
102+
* @param[in] copy to map or transfer the buffer
103+
* @param[in] initFragment flag for buffer type (init, data)
104+
*/
105+
bool SendHelper(AampMediaType mediaType, MediaSample sample, bool copy, bool initFragment = false, bool discontinuity = false);
106106

107107
public:
108108
class PrivateInstanceAAMP *aamp;
@@ -141,6 +141,8 @@ class AAMPGstPlayer : public StreamSink
141141
* @param[in] discontinuity flag for discontinuity
142142
*/
143143
bool SendTransfer(AampMediaType mediaType, void *ptr, size_t len, double fpts, double fdts, double fDuration, double fragmentPTSoffset, bool initFragment = false, bool discontinuity = false) override;
144+
145+
bool SendSample( AampMediaType mediaType, AampMediaSample& sample ) override;
144146
/**
145147
* @fn PipelineConfiguredForMedia
146148
* @param[in] type stream type
@@ -425,6 +427,8 @@ class AAMPGstPlayer : public StreamSink
425427
*/
426428
int GetMonitorAVInterval() const { return mMonitorAVInterval; }
427429

430+
void SetStreamCaps(AampMediaType type, const AampCodecInfo &codecInfo) override;
431+
428432
private:
429433
std::mutex mBufferingLock;
430434
id3_callback_t m_ID3MetadataHandler; /**< Function to call to generate the JS event for in ID3 packet */

0 commit comments

Comments
 (0)