Skip to content

Commit 439628e

Browse files
committed
VPLAY-11143: AAMP Mp4Demux integration
Reason for change: Added function headers, split up Mp4Demux.hpp to a .h and .cpp. Code cleanup Test Procedure: Play clear and encrypted content using mp4demux Risks: Low Signed-off-by: Vinish100 <[email protected]>
1 parent 293952b commit 439628e

15 files changed

+1660
-987
lines changed

AampDemuxDataTypes.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,30 @@
2222

2323
#include <string>
2424
#include <vector>
25+
#include <cstring> // for std::memset
2526
#include "AampGrowableBuffer.h" // for AampGrowableBuffer
2627
#include "AampTime.h" // for AampTime
2728
#include "StreamOutputFormat.h" // for StreamOutputFormat
2829
#include "AampMediaType.h" // for AampMediaType
2930

31+
/*
32+
* @struct AampPsshData
33+
* @brief PSSH data structure
34+
*/
3035
struct AampPsshData
3136
{
3237
std::string systemID; // 16 bytes UUID
3338
std::vector<uint8_t> pssh; // variable length
3439
};
3540

41+
/*
42+
* @struct AampCodecInfo
43+
* @brief Codec information structure
44+
*/
3645
struct AampCodecInfo
3746
{
3847
StreamOutputFormat mCodecFormat; // FORMAT_VIDEO_ES_H264, etc
3948
std::vector<uint8_t> mCodecData; // codec private data, e.g. avcC box
40-
AampMediaType mType;
4149
bool mIsEncrypted;
4250
union
4351
{
@@ -76,23 +84,30 @@ struct AampCodecInfo
7684
}
7785
};
7886

87+
/*
88+
* @struct AampDrmMetadata
89+
* @brief DRM metadata for encrypted samples
90+
*/
7991
struct AampDrmMetadata
8092
{
8193
bool mIsEncrypted;
8294
std::string mKeyId; // 16 bytes UUID
8395
std::vector<uint8_t> mIV; // 8 or 16 bytes
8496
std::string mCipher; // e.g. 'cenc', 'cbcs'
85-
std::string mOriginalMediaType; // 'vide' or 'soun'
8697
std::vector<uint8_t> mSubSamples; // optional subsample encryption data
8798
uint8_t mCryptByteBlock;
8899
uint8_t mSkipByteBlock;
89100

90-
AampDrmMetadata() : mIsEncrypted(false), mKeyId(), mIV(), mCipher(), mOriginalMediaType(),
101+
AampDrmMetadata() : mIsEncrypted(false), mKeyId(), mIV(), mCipher(),
91102
mSubSamples(), mCryptByteBlock(0), mSkipByteBlock(0)
92103
{
93104
}
94105
};
95106

107+
/*
108+
* @struct AampMediaSample
109+
* @brief Media sample structure
110+
*/
96111
struct AampMediaSample
97112
{
98113
AampGrowableBuffer mData;

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ set(LIBAAMP_SOURCES
355355
AampFragmentDescriptor.cpp
356356
AampTimeBasedBufferManager.cpp
357357
mp4demux/AampMp4Demuxer.cpp mp4demux/AampMp4Demuxer.h
358-
mp4demux/Mp4Demux.hpp
358+
mp4demux/MP4Demux.cpp mp4demux/MP4Demux.h
359359
AampDemuxDataTypes.h
360360
)
361361

StreamSink.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ class StreamSink
393393
*/
394394
virtual void NotifyInjectorToPause() {};
395395

396+
/**
397+
* @brief Set stream capabilities based on codec info
398+
*
399+
* @param[in] type - Media type
400+
* @param[in] codecInfo - Codec information
401+
*/
396402
virtual void SetStreamCaps(AampMediaType type, const AampCodecInfo &codecInfo) {};
397403

398404
};

aampgstplayer.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ bool AAMPGstPlayer::SendHelper(AampMediaType mediaType, MediaSample sample, bool
699699
bool notifyFirstBufferProcessed = false;
700700
bool resetTrickUTC = false;
701701
bool firstBufferPushed = false;
702+
// To be used in buffer control notification
703+
double fpts = sample.pts;
704+
double fdts = sample.dts;
705+
double fDuration = sample.duration;
702706

703707
// This block checks if the data contain a valid ID3 header and if it is the case
704708
// calls the callback function.
@@ -733,8 +737,7 @@ bool AAMPGstPlayer::SendHelper(AampMediaType mediaType, MediaSample sample, bool
733737
}
734738
if(bPushBuffer)
735739
{
736-
// TODO: Accessing values from a moved object
737-
privateContext->mBufferControl[mediaType].notifyFragmentInject(this, mediaType, sample.pts, sample.dts, sample.duration, discontinuity);
740+
privateContext->mBufferControl[mediaType].notifyFragmentInject(this, mediaType, fpts, fdts, fDuration, discontinuity);
738741
}
739742
if (eMEDIATYPE_VIDEO == mediaType)
740743
{
@@ -1327,18 +1330,24 @@ void AAMPGstPlayer::StopMonitorAvTimer()
13271330
}
13281331
}
13291332

1333+
/**
1334+
* @brief Set stream capabilities based on codec info
1335+
*
1336+
* @param[in] type - Media type
1337+
* @param[in] codecInfo - Codec information
1338+
*/
13301339
void AAMPGstPlayer::SetStreamCaps(AampMediaType type, const AampCodecInfo &codecInfo)
13311340
{
13321341
CodecInfo gstCodecInfo;
13331342
gstCodecInfo.codecFormat = (GstStreamOutputFormat)codecInfo.mCodecFormat;
13341343
gstCodecInfo.codecData = std::move(codecInfo.mCodecData);
13351344
gstCodecInfo.isEncrypted = codecInfo.mIsEncrypted;
1336-
if (codecInfo.mType == eMEDIATYPE_VIDEO)
1345+
if (type == eMEDIATYPE_VIDEO)
13371346
{
13381347
gstCodecInfo.info.video.width = codecInfo.mInfo.video.mWidth;
13391348
gstCodecInfo.info.video.height = codecInfo.mInfo.video.mHeight;
13401349
}
1341-
else if (codecInfo.mType == eMEDIATYPE_AUDIO)
1350+
else if (type == eMEDIATYPE_AUDIO)
13421351
{
13431352
gstCodecInfo.info.audio.channelCount = codecInfo.mInfo.audio.mChannelCount;
13441353
gstCodecInfo.info.audio.sampleRate = codecInfo.mInfo.audio.mSampleRate;
@@ -1367,7 +1376,6 @@ bool AAMPGstPlayer::SendSample(AampMediaType mediaType, AampMediaSample& sample)
13671376
gstSample.drmMetadata.cipher = std::move(sample.mDrmMetadata.mCipher);
13681377
gstSample.drmMetadata.cryptByteBlock = sample.mDrmMetadata.mCryptByteBlock;
13691378
gstSample.drmMetadata.skipByteBlock = sample.mDrmMetadata.mSkipByteBlock;
1370-
gstSample.drmMetadata.originalMediaType = std::move(sample.mDrmMetadata.mOriginalMediaType);
13711379
}
13721380
else
13731381
{

aampgstplayer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct AAMPGstPlayerPriv;
4444
*/
4545
class SegmentInfo_t;
4646

47+
// Forward declaration of MediaSample
48+
struct MediaSample;
49+
4750
/**
4851
* @struct TaskControlData
4952
* @brief data for scheduling and handling asynchronous tasks
@@ -427,6 +430,12 @@ class AAMPGstPlayer : public StreamSink
427430
*/
428431
int GetMonitorAVInterval() const { return mMonitorAVInterval; }
429432

433+
/**
434+
* @brief Set stream capabilities based on codec info
435+
*
436+
* @param[in] type - Media type
437+
* @param[in] codecInfo - Codec information
438+
*/
430439
void SetStreamCaps(AampMediaType type, const AampCodecInfo &codecInfo) override;
431440

432441
private:

middleware/InterfacePlayerRDK.cpp

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,14 @@ const char *gstGetMediaTypeName(GstMediaType mediaType)
239239

240240

241241
static GstStateChangeReturn SetStateWithWarnings(GstElement *element, GstState targetState);
242+
243+
/**
244+
* @brief Decorate a GstBuffer with DRM metadata
245+
* @param[in] buffer The GstBuffer to decorate
246+
* @param[in] drmMetadata The DRM metadata
247+
*/
242248
static void DecorateGstBufferWithDrmMetadata(GstBuffer *buffer, const MediaDrmMetadata &drmMetadata);
249+
243250
/**
244251
* @brief Configures the GStreamer pipeline.
245252
* @param format Video format.
@@ -2995,6 +3002,22 @@ void InterfacePlayerRDK::SetPlayerName(std::string name)
29953002
interfacePlayerPriv->mPlayerName = name;
29963003
}
29973004

3005+
/**
3006+
* @brief Create GstBuffer with data copied from input data pointer
3007+
*/
3008+
static GstBuffer* CreateGstBufferWithData(gconstpointer data, gsize size)
3009+
{
3010+
GstBuffer *buffer = gst_buffer_new_and_alloc(size);
3011+
if (buffer)
3012+
{
3013+
GstMapInfo map;
3014+
gst_buffer_map(buffer, &map, GST_MAP_WRITE);
3015+
memcpy(map.data, data, size );
3016+
gst_buffer_unmap(buffer, &map);
3017+
}
3018+
return buffer;
3019+
}
3020+
29983021
/**
29993022
* @brief Inject stream buffer to gstreamer pipeline
30003023
*/
@@ -3076,14 +3099,10 @@ bool InterfacePlayerRDK::SendHelper(int type, MediaSample sample, bool copy, boo
30763099

30773100
if(copy)
30783101
{
3079-
buffer = gst_buffer_new_and_alloc((guint)sample.dataSize);
3102+
buffer = CreateGstBufferWithData(sample.data, sample.dataSize);
30803103

30813104
if (buffer)
30823105
{
3083-
GstMapInfo map;
3084-
gst_buffer_map(buffer, &map, GST_MAP_WRITE);
3085-
memcpy(map.data, sample.data, sample.dataSize);
3086-
gst_buffer_unmap(buffer, &map);
30873106
GST_BUFFER_PTS(buffer) = pts;
30883107
GST_BUFFER_DTS(buffer) = dts;
30893108
GST_BUFFER_DURATION(buffer) = duration;
@@ -5296,6 +5315,11 @@ double InterfacePlayerRDK::FlushTrack(int mediaType, double pos, double audioDel
52965315
return rate;
52975316
}
52985317

5318+
/**
5319+
* @brief Sets the stream capabilities.
5320+
* @param[in] type The media type.
5321+
* @param[in] codecInfo The codec information.
5322+
*/
52995323
void InterfacePlayerRDK::SetStreamCaps(GstMediaType type, const CodecInfo &codecInfo)
53005324
{
53015325
GstCaps *caps = GetCaps(codecInfo.codecFormat);
@@ -5374,19 +5398,11 @@ void InterfacePlayerRDK::SetStreamCaps(GstMediaType type, const CodecInfo &codec
53745398
}
53755399
}
53765400

5377-
static GstBuffer* CreateGstBufferWithData(gconstpointer data, gsize size)
5378-
{
5379-
GstBuffer *buffer = gst_buffer_new_and_alloc( size );
5380-
if (buffer)
5381-
{
5382-
GstMapInfo map;
5383-
gst_buffer_map(buffer, &map, GST_MAP_WRITE);
5384-
memcpy(map.data, data, size );
5385-
gst_buffer_unmap(buffer, &map);
5386-
}
5387-
return buffer;
5388-
}
5389-
5401+
/**
5402+
* @brief Decorate a GstBuffer with DRM metadata
5403+
* @param[in] buffer The GstBuffer to decorate
5404+
* @param[in] drmMetadata The DRM metadata
5405+
*/
53905406
void DecorateGstBufferWithDrmMetadata(GstBuffer *buffer, const MediaDrmMetadata &drmMetadata)
53915407
{
53925408
GstStructure *metadata = NULL;
@@ -5397,8 +5413,6 @@ void DecorateGstBufferWithDrmMetadata(GstBuffer *buffer, const MediaDrmMetadata
53975413
"application/x-cenc",
53985414
"encrypted", G_TYPE_BOOLEAN, TRUE,
53995415
"kid", GST_TYPE_BUFFER, kidBuffer,
5400-
// TODO: deprecate original-media-type from drmMetadata
5401-
//"original-media-type", G_TYPE_STRING, drmMetadata.originalMediaType.c_str(),
54025416
// TODO : cipher-mode to be added in caps and not drmMetadata
54035417
"cipher-mode", G_TYPE_STRING, drmMetadata.cipher.c_str(),
54045418
NULL);
@@ -5446,9 +5460,10 @@ void DecorateGstBufferWithDrmMetadata(GstBuffer *buffer, const MediaDrmMetadata
54465460
}
54475461

54485462
if (metadata)
5449-
{ // serialize and print the metadata
5463+
{
5464+
// serialize and print the metadata
54505465
gchar *metaStr = gst_structure_to_string( metadata );
5451-
MW_LOG_INFO("metadata: %s\n", metaStr);
5466+
MW_LOG_INFO("Added drm metadata: %s\n", metaStr);
54525467
g_free(metaStr);
54535468

54545469
gst_buffer_add_protection_meta(buffer, metadata);

middleware/InterfacePlayerRDK.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ enum class InterfaceCB
146146
startNewSubtitleStream // Add more events here if needed
147147
};
148148

149-
149+
// Codec information structure
150150
struct CodecInfo
151151
{
152152
GstStreamOutputFormat codecFormat; // 'avc1', 'mp4a', etc
@@ -166,20 +166,31 @@ struct CodecInfo
166166
uint16_t height;
167167
} video;
168168
} info;
169+
170+
CodecInfo() : codecFormat(GST_FORMAT_INVALID), codecData(), isEncrypted(false)
171+
{
172+
memset(&info, 0, sizeof(info));
173+
}
169174
};
170175

176+
// DRM metadata structure
171177
struct MediaDrmMetadata
172178
{
173179
bool isEncrypted;
174180
std::string keyId; // 16 bytes UUID
175181
std::vector<uint8_t> iv; // 8 or 16 bytes
176182
std::string cipher; // e.g. 'cenc', 'cbcs'
177-
std::string originalMediaType; // 'vide' or 'soun'
178183
std::vector<uint8_t> subSamples; // optional subsample encryption data
179184
uint8_t cryptByteBlock;
180185
uint8_t skipByteBlock;
186+
187+
MediaDrmMetadata() : isEncrypted(false), keyId(), iv(), cipher(),
188+
subSamples(), cryptByteBlock(0), skipByteBlock(0)
189+
{
190+
}
181191
};
182192

193+
// Media sample structure
183194
struct MediaSample
184195
{
185196
const void *data;
@@ -188,7 +199,11 @@ struct MediaSample
188199
double dts;
189200
double duration;
190201
double ptsOffset;
191-
MediaDrmMetadata drmMetadata; // DRM metadata
202+
MediaDrmMetadata drmMetadata;
203+
204+
MediaSample() : data(nullptr), dataSize(0), pts(0.0), dts(0.0), duration(0.0), ptsOffset(0.0), drmMetadata()
205+
{
206+
}
192207
};
193208

194209
// Class to encapsulate GStreamer-related functionality
@@ -812,6 +827,11 @@ class InterfacePlayerRDK
812827
*/
813828
const MonitorAVState& GetMonitorAVState();
814829

830+
/**
831+
* @brief Sets the stream capabilities.
832+
* @param[in] type The media type.
833+
* @param[in] codecInfo The codec information.
834+
*/
815835
void SetStreamCaps(GstMediaType type, const CodecInfo &codecInfo);
816836

817837
private:

mp4demux/AampMp4Demuxer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
AampMp4Demuxer::AampMp4Demuxer(PrivateInstanceAAMP* aamp, AampMediaType type) :
3232
MediaProcessor(), mMp4Demux(nullptr), mAamp(aamp), mEnable(true), mMediaType(type)
3333
{
34-
AAMPLOG_INFO("AampMp4Demuxer Constructor");
34+
AAMPLOG_WARN("Created AampMp4Demuxer(%p) for type %d", this, type);
3535
mMp4Demux = new Mp4Demux();
3636
}
3737

@@ -40,7 +40,7 @@ AampMp4Demuxer::AampMp4Demuxer(PrivateInstanceAAMP* aamp, AampMediaType type) :
4040
*/
4141
AampMp4Demuxer::~AampMp4Demuxer()
4242
{
43-
AAMPLOG_INFO("AampMp4Demuxer Destructor");
43+
AAMPLOG_DEBUG("AampMp4Demuxer destructor");
4444
if (mMp4Demux)
4545
{
4646
delete mMp4Demux;
@@ -82,13 +82,13 @@ bool AampMp4Demuxer::sendSegment(AampGrowableBuffer* pBuffer, double position, d
8282
else
8383
{
8484
const AampCodecInfo& codecInfo = mMp4Demux->getCodecInfo();
85-
AAMPLOG_WARN("Updating codecInfo:%d", codecInfo.mCodecFormat);
85+
AAMPLOG_WARN("Updating codecInfo with format:%d", codecInfo.mCodecFormat);
8686
mAamp->SetStreamCaps(mMediaType, codecInfo);
8787
}
8888
}
8989
else
9090
{
91-
AAMPLOG_WARN("AampMp4Demuxer::sendSegment Invalid buffer or demuxer disabled");
91+
AAMPLOG_WARN("Invalid buffer or demuxer disabled");
9292
}
9393
ptsError = false;
9494
return ret;

mp4demux/AampMp4Demuxer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define __AAMPMP4DEMUXER_H__
2727

2828
#include "mediaprocessor.h"
29-
#include "Mp4Demux.hpp"
29+
#include "MP4Demux.h"
3030
#include "priv_aamp.h"
3131

3232
class AampMp4Demuxer : public MediaProcessor

0 commit comments

Comments
 (0)