Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions aampgstplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,12 +881,14 @@ void AAMPGstPlayer::EndOfStreamReached(AampMediaType type)
*/
void AAMPGstPlayer::Stop(bool keepLastFrame)
{
aamp->SyncBegin();
AAMPLOG_MIL("entering AAMPGstPlayer_Stop keepLastFrame %d", keepLastFrame);
StopMonitorAvTimer();
playerInstance->Stop(keepLastFrame);

aamp->seiTimecode.assign("");
AAMPLOG_MIL("exiting AAMPGstPlayer_Stop");
aamp->SyncEnd();
}


Expand Down Expand Up @@ -983,21 +985,29 @@ long long AAMPGstPlayer::GetPositionMilliseconds(void)
*/
bool AAMPGstPlayer::Pause( bool pause, bool forceStopGstreamerPreBuffering )
{
aamp->SyncBegin(); /* Obtains a mutex lock */
bool res = false;

AAMPLOG_MIL("entering AAMPGstPlayer_Pause - pause(%d) stop-pre-buffering(%d)", pause, forceStopGstreamerPreBuffering);
aamp->SyncBegin(); /* Obtains a mutex lock */

bool res = this->playerInstance->Pause(pause, forceStopGstreamerPreBuffering);
if(res)
if (!playerInstance)
{
AAMPLOG_WARN("AAMPGstPlayer_Pause called but playerInstance is null");
}
else
{
if(!aamp->IsGstreamerSubsEnabled())
aamp->PauseSubtitleParser(pause);
AAMPLOG_MIL("entering AAMPGstPlayer_Pause - pause(%d) stop-pre-buffering(%d)", pause, forceStopGstreamerPreBuffering);

res = this->playerInstance->Pause(pause, forceStopGstreamerPreBuffering);
if(res)
{
if(!aamp->IsGstreamerSubsEnabled())
aamp->PauseSubtitleParser(pause);
}
}

aamp->SyncEnd(); /* Releases the mutex */

return res;
//return retValue;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions test/utests/fakes/FakePrivateInstanceAAMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,10 +1032,18 @@ void PrivateInstanceAAMP::StopTrackInjection(AampMediaType type)

void PrivateInstanceAAMP::SyncBegin(void)
{
if (g_mockPrivateInstanceAAMP != nullptr)
{
g_mockPrivateInstanceAAMP->SyncBegin();
}
}

void PrivateInstanceAAMP::SyncEnd(void)
{
if (g_mockPrivateInstanceAAMP != nullptr)
{
g_mockPrivateInstanceAAMP->SyncEnd();
}
}

void PrivateInstanceAAMP::UpdateCullingState(double culledSecs)
Expand Down
2 changes: 2 additions & 0 deletions test/utests/mocks/MockPrivateInstanceAAMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class MockPrivateInstanceAAMP
MOCK_METHOD(void, NotifyReservationComplete, (const std::string& reservationId));
MOCK_METHOD(void, LoadIDX, (ProfilerBucketType bucketType, std::string fragmentUrl, std::string& effectiveUrl, std::vector<uint8_t>& fragment, unsigned int curlInstance, const char *range, int& http_code, double *downloadTime, AampMediaType mediaType, int *fogError));
MOCK_METHOD(void, UpdateUseSinglePipeline, ());
MOCK_METHOD(void, SyncBegin, ());
MOCK_METHOD(void, SyncEnd, ());
};

extern MockPrivateInstanceAAMP *g_mockPrivateInstanceAAMP;
Expand Down
46 changes: 46 additions & 0 deletions test/utests/tests/AampGstPlayer/FunctionalTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,50 @@ TEST_F(AAMPGstPlayerTests, MonitorAV )
DestroyAMPGstPlayer();
}

TEST_F(AAMPGstPlayerTests, Pause_NullPlayerInstance)
{
// Setup
ConstructAMPGstPlayer();

// Simulate playerInstance being null (as could happen during a race with Stop)
InterfacePlayerRDK *savedPlayerInstance = mAAMPGstPlayer->playerInstance;
mAAMPGstPlayer->playerInstance = nullptr;

// Expect SyncBegin/SyncEnd to be called even when playerInstance is null
EXPECT_CALL(*g_mockPrivateInstanceAAMP, SyncBegin()).Times(2);
EXPECT_CALL(*g_mockPrivateInstanceAAMP, SyncEnd()).Times(2);

// Code under test - should return false without crashing
bool result = mAAMPGstPlayer->Pause(true, false);
EXPECT_FALSE(result);

result = mAAMPGstPlayer->Pause(false, false);
EXPECT_FALSE(result);

// Restore playerInstance for proper cleanup
mAAMPGstPlayer->playerInstance = savedPlayerInstance;

// Tidy Up
DestroyAMPGstPlayer();
}

TEST_F(AAMPGstPlayerTests, Stop_WithPipeline)
{
// Setup
ConstructAMPGstPlayer();
SetupPipeline(&tbl[0]);

// Expect SyncBegin/SyncEnd to be called during Stop
EXPECT_CALL(*g_mockPrivateInstanceAAMP, SyncBegin()).Times(1);
EXPECT_CALL(*g_mockPrivateInstanceAAMP, SyncEnd()).Times(1);

// Code under test - Stop should execute with SyncBegin/SyncEnd without issues
mAAMPGstPlayer->Stop(false);

// After Stop, playerInstance->Stop() should have been called (pipeline torn down)
// The DestroyAMPGstPlayer expectations for pipeline teardown are no longer needed
isPipelineSetup = false;

// Tidy Up
DestroyAMPGstPlayer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class AdSelectionTests : public ::testing::Test

mPrivateInstanceAAMP->mIsDefaultOffset = true;

g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();

g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class AudioOnlyTests : public ::testing::Test

g_mockAampGstPlayer = new MockAAMPGstPlayer(mPrivateInstanceAAMP);

g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();

g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class SelectAudioTrackTests : public ::testing::Test

mPrivateInstanceAAMP->mIsDefaultOffset = true;

g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();

g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class SwitchAudioTrackTests : public ::testing::Test

mPrivateInstanceAAMP->mIsDefaultOffset = true;

g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();

g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class FetcherLoopTests : public ::testing::Test
assert( g_mockAampUtils == nullptr );
g_mockAampGstPlayer = new MockAAMPGstPlayer(mPrivateInstanceAAMP);
mPrivateInstanceAAMP->mIsDefaultOffset = true;
g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();
g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();
g_mockAampMPDDownloader = new StrictMock<MockAampMPDDownloader>();
g_mockAampStreamSinkManager = new NiceMock<MockAampStreamSinkManager>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class FunctionalTestsBase

mPrivateInstanceAAMP->mIsDefaultOffset = true;

g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();

g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class LinearFOGTests : public testing::TestWithParam<double>

mPrivateInstanceAAMP->mIsDefaultOffset = true;

g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();

g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class StreamSelectionTests : public testing::TestWithParam<StreamSelectionTestPa
mPrivateInstanceAAMP->mIsDefaultOffset = true;
g_mockAampConfig = new NiceMock<MockAampConfig>();
mPrivateInstanceAAMP->mIsDefaultOffset = true;
g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();
g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();
g_mockAampMPDDownloader = new StrictMock<MockAampMPDDownloader>();
mStreamAbstractionAAMP_MPD = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class SubtitleTrackTests : public ::testing::Test
mPrivateInstanceAAMP = new PrivateInstanceAAMP(gpGlobalConfig);
g_mockAampConfig = new NiceMock<MockAampConfig>();
mPrivateInstanceAAMP->mIsDefaultOffset = true;
g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();
g_mockMediaStreamContext = new StrictMock<MockMediaStreamContext>();
g_mockAampMPDDownloader = new StrictMock<MockAampMPDDownloader>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class FindTimedMetadataTests : public ::testing::Test

mPrivateInstanceAAMP = new PrivateInstanceAAMP(gpGlobalConfig);

g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();

g_mockAampUtils = new NiceMock<MockAampUtils>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class MpdTests : public ::testing::Test

mPrivateInstanceAAMP = new PrivateInstanceAAMP(gpGlobalConfig);

g_mockPrivateInstanceAAMP = new StrictMock<MockPrivateInstanceAAMP>();
g_mockPrivateInstanceAAMP = new NiceMock<MockPrivateInstanceAAMP>();

mStreamAbstractionAAMP_MPD = nullptr;

Expand Down
Loading