Skip to content

Commit 8b19f3b

Browse files
lashminthaLashminthaJ
authored andcommitted
VPLAY-11829 L1 Test coverage for Mp4demux
Reason for change: Included possible L1 test for validating Mp4demux functionality, 1. Added AampMp4DemuxTests tests which validates SendSegment() in possible scenario's 2. Added Mp4BoxParsingtests which validates all the box parsing pssh, saiz, senc, trun, tfhd, moof, tenc, ftyp Test Procedure: Test with useMp4Demux=true and validate all types of Linear, VOD content in all apps. Risks: Low Signed-off-by: lashmintha <[email protected]>
1 parent 8303f3b commit 8b19f3b

File tree

15 files changed

+2172
-9
lines changed

15 files changed

+2172
-9
lines changed

test/mocks/MockAampMp4Demuxer.h

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
/**
21+
* @file MockAampMp4Demuxer.h
22+
* @brief Mock implementation of AampMp4Demuxer for testing
23+
*/
24+
25+
#ifndef __MOCK_AAMP_MP4_DEMUXER_H__
26+
#define __MOCK_AAMP_MP4_DEMUXER_H__
27+
28+
#include <gmock/gmock.h>
29+
#include "mediaprocessor.h"
30+
#include "AampMediaType.h"
31+
#include "AampGrowableBuffer.h"
32+
33+
/**
34+
* @class MockAampMp4Demuxer
35+
* @brief Mock implementation of AampMp4Demuxer using Google Mock
36+
*/
37+
class MockAampMp4Demuxer : public MediaProcessor
38+
{
39+
public:
40+
MockAampMp4Demuxer() = default;
41+
virtual ~MockAampMp4Demuxer() = default;
42+
43+
// Prevent copy construction and assignment
44+
MockAampMp4Demuxer(const MockAampMp4Demuxer&) = delete;
45+
MockAampMp4Demuxer& operator=(const MockAampMp4Demuxer&) = delete;
46+
47+
// Mock all pure virtual methods from MediaProcessor
48+
MOCK_METHOD(double, getFirstPts, (AampGrowableBuffer* pBuffer), (override));
49+
MOCK_METHOD(void, setPtsOffset, (double ptsOffset), (override));
50+
MOCK_METHOD(bool, sendSegment, (AampGrowableBuffer* pBuffer, double position, double duration,
51+
double fragmentPTSoffset, bool discontinuous, bool isInit,
52+
process_fcn_t processor, bool& ptsError), (override));
53+
MOCK_METHOD(void, setRate, (double rate, PlayMode mode), (override));
54+
MOCK_METHOD(void, setThrottleEnable, (bool enable), (override));
55+
MOCK_METHOD(void, setFrameRateForTM, (int frameRate), (override));
56+
MOCK_METHOD(void, abort, (), (override));
57+
MOCK_METHOD(void, reset, (), (override));
58+
MOCK_METHOD(void, abortInjectionWait, (), (override));
59+
MOCK_METHOD(void, enable, (bool enable), (override));
60+
MOCK_METHOD(void, setTrackOffset, (double offset), (override));
61+
62+
// Mock virtual methods that have default implementations
63+
MOCK_METHOD(void, resetPTSOnSubtitleSwitch, (AampGrowableBuffer* pBuffer, double position), (override));
64+
MOCK_METHOD(void, resetPTSOnAudioSwitch, (AampGrowableBuffer* pBuffer, double position), (override));
65+
MOCK_METHOD(void, ChangeMuxedAudioTrack, (unsigned char index), (override));
66+
MOCK_METHOD(void, SetAudioGroupId, (std::string& id), (override));
67+
MOCK_METHOD(void, setApplyOffsetFlag, (bool enable), (override));
68+
MOCK_METHOD(void, updateSkipPoint, (double skipPoint, double skipDuration), (override));
69+
MOCK_METHOD(void, setDiscontinuityState, (bool isDiscontinuity), (override));
70+
MOCK_METHOD(void, abortWaitForVideoPTS, (), (override));
71+
72+
// Helper methods for test setup
73+
void SetupDefaultBehavior() {
74+
// Set up default return values
75+
ON_CALL(*this, getFirstPts(::testing::_))
76+
.WillByDefault(::testing::Return(0.0));
77+
78+
ON_CALL(*this, sendSegment(::testing::_, ::testing::_, ::testing::_,
79+
::testing::_, ::testing::_, ::testing::_,
80+
::testing::_, ::testing::_))
81+
.WillByDefault(::testing::DoAll(
82+
::testing::SetArgReferee<7>(false), // Set ptsError to false
83+
::testing::Return(true)
84+
));
85+
86+
// Set up void methods to do nothing by default
87+
ON_CALL(*this, setPtsOffset(::testing::_))
88+
.WillByDefault(::testing::Return());
89+
90+
ON_CALL(*this, setRate(::testing::_, ::testing::_))
91+
.WillByDefault(::testing::Return());
92+
93+
ON_CALL(*this, setThrottleEnable(::testing::_))
94+
.WillByDefault(::testing::Return());
95+
96+
ON_CALL(*this, setFrameRateForTM(::testing::_))
97+
.WillByDefault(::testing::Return());
98+
99+
ON_CALL(*this, abort())
100+
.WillByDefault(::testing::Return());
101+
102+
ON_CALL(*this, reset())
103+
.WillByDefault(::testing::Return());
104+
105+
ON_CALL(*this, abortInjectionWait())
106+
.WillByDefault(::testing::Return());
107+
108+
ON_CALL(*this, enable(::testing::_))
109+
.WillByDefault(::testing::Return());
110+
111+
ON_CALL(*this, setTrackOffset(::testing::_))
112+
.WillByDefault(::testing::Return());
113+
}
114+
115+
// Test utilities for creating mock buffers
116+
static AampGrowableBuffer* CreateMockBuffer(const std::string& data) {
117+
AampGrowableBuffer* buffer = new AampGrowableBuffer("MockBuffer");
118+
buffer->AppendBytes(data.c_str(), data.length());
119+
return buffer;
120+
}
121+
122+
static AampGrowableBuffer* CreateMockMp4Buffer() {
123+
// Create a minimal MP4 buffer with ftyp box
124+
const uint8_t mp4Data[] = {
125+
0x00, 0x00, 0x00, 0x20, // size = 32
126+
0x66, 0x74, 0x79, 0x70, // 'ftyp'
127+
0x69, 0x73, 0x6f, 0x6d, // major_brand = 'isom'
128+
0x00, 0x00, 0x02, 0x00, // minor_version = 512
129+
0x69, 0x73, 0x6f, 0x6d, // compatible_brands[0] = 'isom'
130+
0x69, 0x73, 0x6f, 0x32, // compatible_brands[1] = 'iso2'
131+
0x61, 0x76, 0x63, 0x31, // compatible_brands[2] = 'avc1'
132+
0x6d, 0x70, 0x34, 0x31 // compatible_brands[3] = 'mp41'
133+
};
134+
135+
AampGrowableBuffer* buffer = new AampGrowableBuffer("MockMp4Buffer");
136+
buffer->AppendBytes((const char*)mp4Data, sizeof(mp4Data));
137+
return buffer;
138+
}
139+
140+
static AampGrowableBuffer* CreateMockInitSegment() {
141+
return CreateMockMp4Buffer();
142+
}
143+
144+
static AampGrowableBuffer* CreateMockDataSegment() {
145+
// Create a minimal MP4 fragment with moof and mdat
146+
const uint8_t fragmentData[] = {
147+
// moof box header
148+
0x00, 0x00, 0x00, 0x10, // size = 16
149+
0x6d, 0x6f, 0x6f, 0x66, // 'moof'
150+
// mfhd box
151+
0x00, 0x00, 0x00, 0x08, // size = 8
152+
0x6d, 0x66, 0x68, 0x64, // 'mfhd'
153+
// mdat box header
154+
0x00, 0x00, 0x00, 0x08, // size = 8
155+
0x6d, 0x64, 0x61, 0x74 // 'mdat'
156+
};
157+
158+
AampGrowableBuffer* buffer = new AampGrowableBuffer("MockFragmentBuffer");
159+
buffer->AppendBytes((const char*)fragmentData, sizeof(fragmentData));
160+
return buffer;
161+
}
162+
};
163+
164+
#endif /* __MOCK_AAMP_MP4_DEMUXER_H__ */

test/utests/fakes/FakeMP4Demux.cpp

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,120 @@
1717
* limitations under the License.
1818
*/
1919

20-
#include "MP4Demux.h"
20+
/**
21+
* @file FakeMP4Demux.cpp
22+
* @brief Fake implementation of MP4Demux for unit testing
23+
*/
24+
25+
#include "MP4Demux.h"
26+
#include "MockMp4Demux.h"
27+
#include "AampLogManager.h"
28+
#include <vector>
2129

30+
// Global mock instance used by the testable AampMp4Demuxer
31+
MockMp4Demux *g_mockMp4Demux = nullptr;
2232

33+
/**
34+
* @brief Fake MP4Demux constructor
35+
*/
2336
Mp4Demux::Mp4Demux()
2437
{
38+
AAMPLOG_INFO("FakeMP4Demux Constructor");
2539
}
2640

41+
/**
42+
* @brief Fake MP4Demux destructor
43+
*/
2744
Mp4Demux::~Mp4Demux()
2845
{
46+
AAMPLOG_INFO("FakeMP4Demux Destructor");
2947
}
3048

49+
/**
50+
* @brief Fake Parse implementation - delegates to mock if available
51+
* @param ptr Pointer to MP4 data
52+
* @param len Length of data
53+
* @return true if parsing was successful
54+
*/
3155
bool Mp4Demux::Parse(const void *ptr, size_t len)
3256
{
33-
return false;
34-
}
35-
36-
Mp4ParseError Mp4Demux::GetLastError() const
37-
{
38-
return Mp4ParseError::MP4_PARSE_OK;
57+
AAMPLOG_INFO("FakeMP4Demux::Parse called with %zu bytes", len);
58+
59+
// Delegate to mock if available
60+
if (g_mockMp4Demux) {
61+
g_mockMp4Demux->Parse(ptr, len);
62+
}
63+
// Otherwise, do nothing (fake behavior)
64+
return true;
3965
}
4066

67+
/**
68+
* @brief Fake GetTimeScale implementation
69+
* @return Default timescale value
70+
*/
4171
uint32_t Mp4Demux::GetTimeScale() const
4272
{
43-
return 0;
73+
AAMPLOG_INFO("FakeMP4Demux::GetTimeScale called");
74+
75+
// Delegate to mock if available
76+
if (g_mockMp4Demux) {
77+
return g_mockMp4Demux->GetTimeScale();
78+
}
79+
80+
// Default fake value
81+
return 90000; // Common timescale for video
4482
}
4583

84+
/**
85+
* @brief Fake GetCodecInfo implementation
86+
* @return Default codec info
87+
*/
4688
AampCodecInfo Mp4Demux::GetCodecInfo()
4789
{
48-
return AampCodecInfo();
90+
AAMPLOG_INFO("FakeMP4Demux::GetCodecInfo called");
91+
92+
// Delegate to mock if available
93+
if (g_mockMp4Demux) {
94+
return g_mockMp4Demux->GetCodecInfo();
95+
}
96+
97+
// Default fake codec info
98+
AampCodecInfo codecInfo;
99+
codecInfo.mCodecFormat = FORMAT_INVALID;
100+
codecInfo.mIsEncrypted = false;
101+
return codecInfo;
49102
}
50103

104+
/**
105+
* @brief Fake GetProtectionEvents implementation
106+
* @return Empty protection events vector
107+
*/
51108
std::vector<AampPsshData> Mp4Demux::GetProtectionEvents()
52109
{
110+
AAMPLOG_INFO("FakeMP4Demux::GetProtectionEvents called");
111+
112+
// Delegate to mock if available
113+
if (g_mockMp4Demux) {
114+
return g_mockMp4Demux->GetProtectionEvents();
115+
}
116+
117+
// Default fake - no protection events
53118
return std::vector<AampPsshData>();
54119
}
55120

121+
/**
122+
* @brief Fake GetSamples implementation
123+
* @return Empty samples vector or mock-provided samples
124+
*/
56125
std::vector<AampMediaSample> Mp4Demux::GetSamples()
57126
{
127+
AAMPLOG_INFO("FakeMP4Demux::GetSamples called");
128+
129+
// Delegate to mock if available
130+
if (g_mockMp4Demux) {
131+
return g_mockMp4Demux->GetSamples();
132+
}
133+
134+
// Default fake - no samples
58135
return std::vector<AampMediaSample>();
59136
}

test/utests/mocks/MockMp4Demux.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 MOCK_MP4_DEMUX_H
21+
#define MOCK_MP4_DEMUX_H
22+
23+
#include <gmock/gmock.h>
24+
#include <vector>
25+
#include "AampDemuxDataTypes.h"
26+
27+
class MockMp4Demux
28+
{
29+
public:
30+
MOCK_METHOD(void, Parse, (const void *ptr, size_t len));
31+
MOCK_METHOD(uint32_t, GetTimeScale, (), (const));
32+
MOCK_METHOD(AampCodecInfo, GetCodecInfo, ());
33+
MOCK_METHOD(std::vector<AampPsshData>, GetProtectionEvents, ());
34+
MOCK_METHOD(std::vector<AampMediaSample>, GetSamples, ());
35+
};
36+
37+
extern MockMp4Demux *g_mockMp4Demux;
38+
39+
#endif /* MOCK_MP4_DEMUX_H */

test/utests/mocks/MockPrivateInstanceAAMP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class MockPrivateInstanceAAMP
4949
MOCK_METHOD(void, SendErrorEvent, (AAMPTuneFailure, const char *, bool, int32_t, int32_t, int32_t, const std::string &));
5050
MOCK_METHOD(void, SendDownloadErrorEvent, (AAMPTuneFailure, long));
5151
MOCK_METHOD(void, SendStreamTransfer, (AampMediaType, AampGrowableBuffer*, double, double, double, double, bool, bool));
52+
MOCK_METHOD(void, SendStreamTransfer, (AampMediaType, AampMediaSample&));
53+
MOCK_METHOD(void, SetStreamCaps, (AampMediaType, AampCodecInfo&));
5254
MOCK_METHOD(bool, SendStreamCopy, (AampMediaType, const void *, size_t, double, double, double));
5355
MOCK_METHOD(MediaFormat,GetMediaFormatTypeEnum,());
5456
MOCK_METHOD(long long, GetPositionMs, ());
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
#include <gtest/gtest.h>
21+
22+
int main(int argc, char** argv)
23+
{
24+
testing::InitGoogleTest(&argc, argv);
25+
return RUN_ALL_TESTS();
26+
}

0 commit comments

Comments
 (0)