Skip to content

Commit

Permalink
sync upstream lib cppmyth 2.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Feb 13, 2024
1 parent 5daad48 commit 022475d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 71 deletions.
2 changes: 1 addition & 1 deletion lib/cppmyth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif ()
# set lib version here
set (PACKAGE_VERSION_MAJOR 2)
set (PACKAGE_VERSION_MINOR 17)
set (PACKAGE_VERSION_PATCH 0)
set (PACKAGE_VERSION_PATCH 1)

set (PACKAGE_VERSION ${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH})
set (PACKAGE_LIB_SOVERSION ${PACKAGE_VERSION_MAJOR})
Expand Down
10 changes: 10 additions & 0 deletions lib/cppmyth/src/mythfileplayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,29 @@ void FilePlayback::CloseTransfer()

bool FilePlayback::TransferIsOpen()
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
return ProtoPlayback::TransferIsOpen(*transfer);
return false;
}

int64_t FilePlayback::GetSize() const
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
return transfer->GetSize();
return 0;
}

int FilePlayback::Read(void *buffer, unsigned n)
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
{
int r = 0;
Expand All @@ -126,15 +132,19 @@ int FilePlayback::Read(void *buffer, unsigned n)

int64_t FilePlayback::Seek(int64_t offset, WHENCE_t whence)
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
return TransferSeek(*transfer, offset, whence);
return -1;
}

int64_t FilePlayback::GetPosition() const
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
return transfer->GetPosition();
return 0;
Expand Down
59 changes: 36 additions & 23 deletions lib/cppmyth/src/mythlivetvplayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ void LiveTVPlayback::ClearChain()

bool LiveTVPlayback::IsChained(const Program& program)
{
OS::CReadLock lock(*m_latch);
for (chained_t::const_iterator it = m_chain.chained.begin(); it != m_chain.chained.end(); ++it)
{
if (it->first && it->first->GetPathName() == program.fileName)
Expand All @@ -273,11 +274,11 @@ bool LiveTVPlayback::IsChained(const Program& program)

void LiveTVPlayback::HandleChainUpdate()
{
// Begin critical section
OS::CWriteLock lock(*m_latch); // Lock chain
ProtoRecorderPtr recorder(m_recorder);
if (!recorder)
if (!m_recorder)
return;
ProgramPtr prog = recorder->GetCurrentRecording();
ProgramPtr prog = m_recorder->GetCurrentRecording();
/*
* If program file doesn't exist in the recorder chain then create a new
* transfer and add it to the chain.
Expand All @@ -286,7 +287,7 @@ void LiveTVPlayback::HandleChainUpdate()
{
DBG(DBG_DEBUG, "%s: liveTV (%s): adding new transfer %s\n", __FUNCTION__,
m_chain.UID.c_str(), prog->fileName.c_str());
ProtoTransferPtr transfer(new ProtoTransfer(recorder->GetServer(), recorder->GetPort(), prog->fileName, prog->recording.storageGroup));
ProtoTransferPtr transfer(new ProtoTransfer(m_recorder->GetServer(), m_recorder->GetPort(), prog->fileName, prog->recording.storageGroup));
// Pop previous dummy file if exists then add the new into the chain
if (m_chain.lastSequence && m_chain.chained[m_chain.lastSequence - 1].first->GetSize() == 0)
{
Expand Down Expand Up @@ -327,17 +328,20 @@ bool LiveTVPlayback::SwitchChainLast()
{
if (SwitchChain(m_chain.lastSequence))
{
ProtoRecorderPtr recorder(m_recorder);
ProtoTransferPtr transfer(m_chain.currentTransfer);
if (recorder && transfer && recorder->TransferSeek(*transfer, 0, WHENCE_SET) == 0)
OS::CReadLock lock(*m_latch);
if (m_recorder && m_chain.currentTransfer
&& m_recorder->TransferSeek(*m_chain.currentTransfer, 0, WHENCE_SET) == 0)
return true;
}
return false;
}

void LiveTVPlayback::HandleBackendMessage(EventMessagePtr msg)
{
/* stage the current recorder */
m_latch->lock_shared();
ProtoRecorderPtr recorder(m_recorder);
m_latch->unlock_shared();
if (!recorder || !recorder->IsPlaying())
return;
switch (msg->event)
Expand Down Expand Up @@ -404,8 +408,8 @@ void LiveTVPlayback::HandleBackendMessage(EventMessagePtr msg)
{
// Recorder is not subscriber. So callback event to it
recorder->DoneRecordingCallback();
// Manage program break
if (m_chain.watch)
// Manage program break without locking
if (m_chain.watch /* volatile */)
{
/*
* Last recording is now completed but watch signal is ON.
Expand All @@ -418,14 +422,16 @@ void LiveTVPlayback::HandleBackendMessage(EventMessagePtr msg)
usleep(500000); // wait for 500 ms
HandleChainUpdate();
}
while (m_chain.watch && timeout.TimeLeft() > 0);
while (m_chain.watch /* volatile */ &&
timeout.TimeLeft() > 0);
}
}
}
break;
case EVENT_UPDATE_FILE_SIZE:
if (msg->subject.size() >= 3)
{
// Begin critical section
OS::CWriteLock lock(*m_latch); // Lock chain
if (m_chain.lastSequence > 0)
{
Expand Down Expand Up @@ -468,7 +474,12 @@ void LiveTVPlayback::HandleBackendMessage(EventMessagePtr msg)
{
int32_t rnum;
if (string_to_int32(msg->subject[1].c_str(), &rnum) == 0 && recorder->GetNum() == (int)rnum)
{
// Begin critical section
m_latch->lock();
m_signal = msg->signal;
m_latch->unlock();
}
}
break;
//case EVENT_HANDLER_STATUS:
Expand Down Expand Up @@ -545,9 +556,10 @@ int LiveTVPlayback::_read(void* buffer, unsigned n)
bool retry;
int64_t s, fp;

// Begin critical section
// First of all i hold my shared resources using copies
/* stage the current recorder */
m_latch->lock_shared();
ProtoRecorderPtr recorder(m_recorder);
m_latch->unlock_shared();
if (!m_chain.currentTransfer || !recorder)
return -1;

Expand Down Expand Up @@ -639,6 +651,7 @@ int64_t LiveTVPlayback::Seek(int64_t offset, WHENCE_t whence)

int64_t LiveTVPlayback::_seek(int64_t offset, WHENCE_t whence)
{
// Begin critical section
OS::CWriteLock lock(*m_latch); // Lock chain
if (!m_recorder || !m_chain.currentSequence)
return -1;
Expand Down Expand Up @@ -730,37 +743,36 @@ int64_t LiveTVPlayback::GetPosition() const

bool LiveTVPlayback::IsPlaying() const
{
ProtoRecorderPtr recorder(m_recorder);
return (recorder ? recorder->IsPlaying() : false);
OS::CReadLock lock(*m_latch);
return (m_recorder ? m_recorder->IsPlaying() : false);
}

bool LiveTVPlayback::IsLiveRecording() const
{
ProtoRecorderPtr recorder(m_recorder);
return (recorder ? recorder->IsLiveRecording() : false);
OS::CReadLock lock(*m_latch);
return (m_recorder ? m_recorder->IsLiveRecording() : false);
}

bool LiveTVPlayback::KeepLiveRecording(bool keep)
{
ProtoRecorderPtr recorder(m_recorder);
// Begin critical section
OS::CWriteLock lock(*m_latch);
if (recorder && recorder->IsPlaying())
if (m_recorder && m_recorder->IsPlaying())
{
ProgramPtr prog = recorder->GetCurrentRecording();
ProgramPtr prog = m_recorder->GetCurrentRecording();
if (prog)
{
if (keep)
{
if (UndeleteRecording(*prog) && recorder->SetLiveRecording(keep))
if (UndeleteRecording(*prog) && m_recorder->SetLiveRecording(keep))
{
QueryGenpixmap(*prog);
return true;
}
}
else
{
if (recorder->SetLiveRecording(keep) && recorder->FinishRecording())
if (m_recorder->SetLiveRecording(keep) && m_recorder->FinishRecording())
return true;
}
}
Expand Down Expand Up @@ -800,12 +812,13 @@ ProgramPtr LiveTVPlayback::GetChainedProgram(unsigned sequence) const

uint32_t LiveTVPlayback::GetCardId() const
{
ProtoRecorderPtr recorder(m_recorder);
return (recorder ? recorder->GetNum() : 0);
OS::CReadLock lock(*m_latch);
return (m_recorder ? m_recorder->GetNum() : 0);
}

SignalStatusPtr LiveTVPlayback::GetSignal() const
{
OS::CReadLock lock(*m_latch);
return (m_recorder ? m_signal : SignalStatusPtr());
}

Expand Down
12 changes: 12 additions & 0 deletions lib/cppmyth/src/mythrecordingplayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ void RecordingPlayback::CloseTransfer()

bool RecordingPlayback::TransferIsOpen()
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
return ProtoPlayback::TransferIsOpen(*transfer);
return false;
Expand All @@ -160,7 +162,9 @@ void RecordingPlayback::SetChunk(unsigned size)

int64_t RecordingPlayback::GetSize() const
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
return transfer->GetSize();
return 0;
Expand Down Expand Up @@ -209,7 +213,9 @@ int RecordingPlayback::Read(void* buffer, unsigned n)

int RecordingPlayback::_read(void *buffer, unsigned n)
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
{
if (!m_readAhead)
Expand Down Expand Up @@ -261,15 +267,19 @@ int64_t RecordingPlayback::Seek(int64_t offset, WHENCE_t whence)

int64_t RecordingPlayback::_seek(int64_t offset, WHENCE_t whence)
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
return TransferSeek(*transfer, offset, whence);
return -1;
}

int64_t RecordingPlayback::GetPosition() const
{
m_latch->lock_shared();
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
if (transfer)
{
// it must returns the current position of first byte in buffer
Expand All @@ -282,8 +292,10 @@ int64_t RecordingPlayback::GetPosition() const
void RecordingPlayback::HandleBackendMessage(EventMessagePtr msg)
{
// First of all i hold shared resources using copies
m_latch->lock_shared();
ProgramPtr recording(m_recording);
ProtoTransferPtr transfer(m_transfer);
m_latch->unlock_shared();
switch (msg->event)
{
case EVENT_UPDATE_FILE_SIZE:
Expand Down
Loading

0 comments on commit 022475d

Please sign in to comment.