[vlc-commits] [Git][videolan/vlc][master] 4 commits: demux:adaptive: use C++ vlc_mutex_locker
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Feb 11 13:18:16 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
4f031da5 by Steve Lhomme at 2023-02-11T12:48:17+00:00
demux:adaptive: use C++ vlc_mutex_locker
It can simplify the code in some cases and avoid missing unlocks on return.
- - - - -
91c042fe by Steve Lhomme at 2023-02-11T12:48:17+00:00
qt: use C++ vlc_mutex_locker
It can simplify the code in some cases and avoid missing unlocks on return.
- - - - -
2ccf9ba6 by Steve Lhomme at 2023-02-11T12:48:17+00:00
sout/sdi: use C++ vlc_mutex_locker
It can simplify the code in some cases and avoid missing unlocks on return.
- - - - -
3dc7f9dc by Steve Lhomme at 2023-02-11T12:48:17+00:00
vout/decklink: use C++ vlc_mutex_locker
It can simplify the code in some cases and avoid missing unlocks on return.
- - - - -
12 changed files:
- modules/demux/adaptive/PlaylistManager.cpp
- modules/demux/adaptive/encryption/Keyring.cpp
- modules/demux/adaptive/http/HTTPConnectionManager.cpp
- modules/demux/adaptive/logic/NearOptimalAdaptationLogic.cpp
- modules/demux/adaptive/logic/PredictiveAdaptationLogic.cpp
- modules/demux/adaptive/logic/RateBasedAdaptationLogic.cpp
- modules/gui/qt/maininterface/videosurface.cpp
- modules/gui/qt/player/player_controller.cpp
- modules/gui/qt/playlist/playlist_item.cpp
- modules/stream_out/sdi/DBMSDIOutput.cpp
- modules/stream_out/sdi/SDIStream.cpp
- modules/video_output/decklink.cpp
Changes:
=====================================
modules/demux/adaptive/PlaylistManager.cpp
=====================================
@@ -271,7 +271,7 @@ AbstractStream::BufferingStatus PlaylistManager::bufferize(Times deadline,
break;
}
- vlc_mutex_lock(&demux.lock);
+ vlc_mutex_locker locker(&demux.lock);
if(demux.times.continuous == VLC_TICK_INVALID &&
/* don't wait minbuffer on simple discontinuity or restart */
(demux.pcr_syncpoint == TimestampSynchronizationPoint::Discontinuity ||
@@ -280,7 +280,6 @@ AbstractStream::BufferingStatus PlaylistManager::bufferize(Times deadline,
{
demux.times = getFirstTimes();
}
- vlc_mutex_unlock(&demux.lock);
return i_return;
}
=====================================
modules/demux/adaptive/encryption/Keyring.cpp
=====================================
@@ -46,7 +46,7 @@ KeyringKey Keyring::getKey(SharedResources *resources, const std::string &uri)
{
KeyringKey key;
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
std::map<std::string, KeyringKey>::iterator it = keys.find(uri);
if(it == keys.end())
{
@@ -80,7 +80,6 @@ KeyringKey Keyring::getKey(SharedResources *resources, const std::string &uri)
}
key = (*it).second;
}
- vlc_mutex_unlock(&lock);
return key;
}
=====================================
modules/demux/adaptive/http/HTTPConnectionManager.cpp
=====================================
@@ -109,10 +109,9 @@ HTTPConnectionManager::~HTTPConnectionManager ()
void HTTPConnectionManager::closeAllConnections ()
{
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
releaseAllConnections();
vlc_delete_all(this->connectionPool);
- vlc_mutex_unlock(&lock);
}
void HTTPConnectionManager::releaseAllConnections()
@@ -145,7 +144,7 @@ AbstractConnection * HTTPConnectionManager::getConnection(ConnectionParams ¶
return nullptr;
}
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
AbstractConnection *conn = reuseConnection(params);
if(!conn)
{
@@ -154,7 +153,6 @@ AbstractConnection * HTTPConnectionManager::getConnection(ConnectionParams ¶
if(!conn)
{
- vlc_mutex_unlock(&lock);
return nullptr;
}
@@ -162,13 +160,11 @@ AbstractConnection * HTTPConnectionManager::getConnection(ConnectionParams ¶
if (!conn->prepare(params))
{
- vlc_mutex_unlock(&lock);
return nullptr;
}
}
conn->setUsed(true);
- vlc_mutex_unlock(&lock);
return conn;
}
=====================================
modules/demux/adaptive/logic/NearOptimalAdaptationLogic.cpp
=====================================
@@ -193,7 +193,7 @@ unsigned NearOptimalAdaptationLogic::getMaxCurrentBw() const
void NearOptimalAdaptationLogic::updateDownloadRate(const ID &id, size_t dlsize,
vlc_tick_t time, vlc_tick_t)
{
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
std::map<ID, NearOptimalContext>::iterator it = streams.find(id);
if(it != streams.end())
{
@@ -201,7 +201,6 @@ void NearOptimalAdaptationLogic::updateDownloadRate(const ID &id, size_t dlsize,
ctx.last_download_rate = ctx.average.push(CLOCK_FREQ * dlsize * 8 / time);
}
currentBps = getMaxCurrentBw();
- vlc_mutex_unlock(&lock);
}
void NearOptimalAdaptationLogic::trackerEvent(const TrackerEvent &ev)
@@ -212,13 +211,12 @@ void NearOptimalAdaptationLogic::trackerEvent(const TrackerEvent &ev)
{
const RepresentationSwitchEvent &event =
static_cast<const RepresentationSwitchEvent &>(ev);
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
if(event.prev)
usedBps -= event.prev->getBandwidth();
if(event.next)
usedBps += event.next->getBandwidth();
BwDebug(msg_Info(p_obj, "New total bandwidth usage %zu kBps", (usedBps / 8000)));
- vlc_mutex_unlock(&lock);
}
break;
@@ -227,7 +225,7 @@ void NearOptimalAdaptationLogic::trackerEvent(const TrackerEvent &ev)
const BufferingStateUpdatedEvent &event =
static_cast<const BufferingStateUpdatedEvent &>(ev);
const ID &id = *event.id;
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
if(event.enabled)
{
if(streams.find(id) == streams.end())
@@ -242,7 +240,6 @@ void NearOptimalAdaptationLogic::trackerEvent(const TrackerEvent &ev)
if(it != streams.end())
streams.erase(it);
}
- vlc_mutex_unlock(&lock);
BwDebug(msg_Info(p_obj, "Stream %s is now known %sactive", id.str().c_str(),
(event.enabled) ? "" : "in"));
}
@@ -253,11 +250,10 @@ void NearOptimalAdaptationLogic::trackerEvent(const TrackerEvent &ev)
const BufferingLevelChangedEvent &event =
static_cast<const BufferingLevelChangedEvent &>(ev);
const ID &id = *event.id;
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
NearOptimalContext &ctx = streams[id];
ctx.buffering_level = event.current;
ctx.buffering_target = event.target;
- vlc_mutex_unlock(&lock);
}
break;
=====================================
modules/demux/adaptive/logic/PredictiveAdaptationLogic.cpp
=====================================
@@ -69,7 +69,7 @@ BaseRepresentation *PredictiveAdaptationLogic::getNextRepresentation(BaseAdaptat
RepresentationSelector selector(maxwidth, maxheight);
BaseRepresentation *rep;
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
std::map<ID, PredictiveStats>::iterator it = streams.find(adaptSet->getID());
if(it == streams.end())
@@ -145,22 +145,19 @@ BaseRepresentation *PredictiveAdaptationLogic::getNextRepresentation(BaseAdaptat
stats.segments_count++;
}
- vlc_mutex_unlock(&lock);
-
return rep;
}
void PredictiveAdaptationLogic::updateDownloadRate(const ID &id, size_t dlsize,
vlc_tick_t time, vlc_tick_t)
{
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
std::map<ID, PredictiveStats>::iterator it = streams.find(id);
if(it != streams.end())
{
PredictiveStats &stats = (*it).second;
stats.last_download_rate = stats.average.push(CLOCK_FREQ * dlsize * 8 / time);
}
- vlc_mutex_unlock(&lock);
}
unsigned PredictiveAdaptationLogic::getAvailableBw(unsigned i_bw, const BaseRepresentation *curRep) const
@@ -183,14 +180,13 @@ void PredictiveAdaptationLogic::trackerEvent(const TrackerEvent &ev)
{
const RepresentationSwitchEvent &event =
static_cast<const RepresentationSwitchEvent &>(ev);
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
if(event.prev)
usedBps -= event.prev->getBandwidth();
if(event.next)
usedBps += event.next->getBandwidth();
BwDebug(msg_Info(p_obj, "New total bandwidth usage %zu KiB/s", (usedBps / 8000)));
- vlc_mutex_unlock(&lock);
}
break;
@@ -199,7 +195,7 @@ void PredictiveAdaptationLogic::trackerEvent(const TrackerEvent &ev)
const BufferingStateUpdatedEvent &event =
static_cast<const BufferingStateUpdatedEvent &>(ev);
const ID &id = *event.id;
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
if(event.enabled)
{
if(streams.find(id) == streams.end())
@@ -214,7 +210,6 @@ void PredictiveAdaptationLogic::trackerEvent(const TrackerEvent &ev)
if(it != streams.end())
streams.erase(it);
}
- vlc_mutex_unlock(&lock);
BwDebug(msg_Info(p_obj, "Stream %s is now known %sactive", id.str().c_str(),
(event.enabled) ? "" : "in"));
}
@@ -225,11 +220,10 @@ void PredictiveAdaptationLogic::trackerEvent(const TrackerEvent &ev)
const BufferingLevelChangedEvent &event =
static_cast<const BufferingLevelChangedEvent &>(ev);
const ID &id = *event.id;
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
PredictiveStats &stats = streams[id];
stats.buffering_level = event.current;
stats.buffering_target = event.target;
- vlc_mutex_unlock(&lock);
}
break;
@@ -238,10 +232,9 @@ void PredictiveAdaptationLogic::trackerEvent(const TrackerEvent &ev)
const SegmentChangedEvent &event =
static_cast<const SegmentChangedEvent &>(ev);
const ID &id = *event.id;
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
PredictiveStats &stats = streams[id];
stats.last_duration = event.duration;
- vlc_mutex_unlock(&lock);
}
break;
=====================================
modules/demux/adaptive/logic/RateBasedAdaptationLogic.cpp
=====================================
@@ -89,7 +89,7 @@ void RateBasedAdaptationLogic::updateDownloadRate(const ID &, size_t size,
const size_t bps = CLOCK_FREQ * dlsize * 8 / dllength;
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
bpsAvg = average.push(bps);
// BwDebug(msg_Dbg(p_obj, "alpha1 %lf alpha0 %lf dmax %ld ds %ld", alpha,
@@ -102,7 +102,6 @@ void RateBasedAdaptationLogic::updateDownloadRate(const ID &, size_t size,
BwDebug(msg_Info(p_obj, "Current bandwidth %zu KiB/s using %u%%",
(bpsAvg / 8000), (bpsAvg) ? (unsigned)(usedBps * 100.0 / bpsAvg) : 0));
- vlc_mutex_unlock(&lock);
}
void RateBasedAdaptationLogic::trackerEvent(const TrackerEvent &ev)
@@ -111,7 +110,7 @@ void RateBasedAdaptationLogic::trackerEvent(const TrackerEvent &ev)
{
const RepresentationSwitchEvent &event =
static_cast<const RepresentationSwitchEvent &>(ev);
- vlc_mutex_lock(&lock);
+ vlc_mutex_locker locker(&lock);
if(event.prev)
usedBps -= event.prev->getBandwidth();
if(event.next)
@@ -119,7 +118,6 @@ void RateBasedAdaptationLogic::trackerEvent(const TrackerEvent &ev)
BwDebug(msg_Info(p_obj, "New bandwidth usage %zu KiB/s %u%%",
(usedBps / 8000), (bpsAvg) ? (unsigned)(usedBps * 100.0 / bpsAvg) : 0 ));
- vlc_mutex_unlock(&lock);
}
}
=====================================
modules/gui/qt/maininterface/videosurface.cpp
=====================================
@@ -64,7 +64,7 @@ void WindowResizer::reportSize(float width, float height)
if (width < 0 || height < 0)
return;
- vlc_mutex_lock(&m_lock);
+ vlc_mutex_locker locker(&m_lock);
m_requestedWidth = static_cast<unsigned>(width);
m_requestedHeight = static_cast<unsigned>(height);
if (m_running == false)
@@ -72,16 +72,14 @@ void WindowResizer::reportSize(float width, float height)
m_running = true;
QThreadPool::globalInstance()->start(this);
}
- vlc_mutex_unlock(&m_lock);
}
/* Must called under m_voutlock before deletion */
void WindowResizer::waitForCompletion()
{
- vlc_mutex_lock(&m_lock);
+ vlc_mutex_locker locker(&m_lock);
while (m_running)
vlc_cond_wait(&m_cond, &m_lock);
- vlc_mutex_unlock(&m_lock);
}
VideoSurfaceProvider::VideoSurfaceProvider(QObject* parent)
=====================================
modules/gui/qt/player/player_controller.cpp
=====================================
@@ -188,7 +188,7 @@ void PlayerControllerPrivate::UpdateMeta( input_item_t *p_item )
Q_Q(PlayerController);
{
- vlc_mutex_lock(&p_item->lock);
+ vlc_mutex_locker locker(&p_item->lock);
if (p_item->p_meta)
{
@@ -197,8 +197,6 @@ void PlayerControllerPrivate::UpdateMeta( input_item_t *p_item )
m_album = vlc_meta_Get(p_item->p_meta, vlc_meta_Album);
m_artwork = vlc_meta_Get(p_item->p_meta, vlc_meta_ArtworkURL);
}
-
- vlc_mutex_unlock(&p_item->lock);
}
emit q->currentMetaChanged( p_item );
=====================================
modules/gui/qt/playlist/playlist_item.cpp
=====================================
@@ -72,7 +72,7 @@ QUrl PlaylistItem::getUrl() const
void PlaylistItem::sync() {
input_item_t *media = vlc_playlist_item_GetMedia(d->item.get());
- vlc_mutex_lock(&media->lock);
+ vlc_mutex_locker locker(&media->lock);
d->duration = media->i_duration;
d->url = media->psz_uri;
@@ -86,8 +86,6 @@ void PlaylistItem::sync() {
if (d->title.isNull())
/* If there is no title, use the item name */
d->title = media->psz_name;
-
- vlc_mutex_unlock(&media->lock);
}
PlaylistItem::operator bool() const
=====================================
modules/stream_out/sdi/DBMSDIOutput.cpp
=====================================
@@ -161,10 +161,9 @@ HRESULT STDMETHODCALLTYPE DBMSDIOutput::ScheduledFrameCompleted
#else
bool b_active;
#endif
- vlc_mutex_lock(&feeder.lock);
+ vlc_mutex_locker locker(&feeder.lock);
if((S_OK == p_output->IsScheduledPlaybackRunning(&b_active)) && b_active)
vlc_cond_signal(&feeder.cond);
- vlc_mutex_unlock(&feeder.lock);
return S_OK;
}
@@ -592,14 +591,13 @@ void DBMSDIOutput::feederThread()
vlc_tick_t maxdelay = CLOCK_FREQ/60;
for(;;)
{
- vlc_mutex_lock(&feeder.lock);
+ vlc_mutex_locker locker(&feeder.lock);
vlc_cond_timedwait(&feeder.cond, &feeder.lock, vlc_tick_now() + maxdelay);
if (feeder.canceled)
break;
doSchedule();
if(timescale)
maxdelay = CLOCK_FREQ * frameduration / timescale;
- vlc_mutex_unlock(&feeder.lock);
}
}
@@ -608,9 +606,8 @@ int DBMSDIOutput::Process()
if((!p_output && !FAKE_DRIVER))
return VLC_SUCCESS;
- vlc_mutex_lock(&feeder.lock);
+ vlc_mutex_locker locker(&feeder.lock);
vlc_cond_signal(&feeder.cond);
- vlc_mutex_unlock(&feeder.lock);
return VLC_SUCCESS;
}
=====================================
modules/stream_out/sdi/SDIStream.cpp
=====================================
@@ -362,7 +362,7 @@ void AbstractDecodedStream::decoderThread()
int AbstractDecodedStream::Send(block_t *p_block)
{
assert(p_decoder);
- vlc_mutex_lock(&inputLock);
+ vlc_mutex_locker locker(&inputLock);
inputQueue.push(p_block);
if(p_block)
{
@@ -372,45 +372,40 @@ int AbstractDecodedStream::Send(block_t *p_block)
pcr = std::max(pcr, t);
}
vlc_cond_signal(&inputWait);
- vlc_mutex_unlock(&inputLock);
return VLC_SUCCESS;
}
void AbstractDecodedStream::Flush()
{
- vlc_mutex_lock(&inputLock);
+ vlc_mutex_locker locker(&inputLock);
while(!inputQueue.empty())
{
if(inputQueue.front())
block_Release(inputQueue.front());
inputQueue.pop();
}
- vlc_mutex_unlock(&inputLock);
}
void AbstractDecodedStream::Drain()
{
Send(NULL);
- vlc_mutex_lock(&inputLock);
+ vlc_mutex_locker locker(&inputLock);
if(status != FAILED && status != DRAINED)
status = DRAINING;
- vlc_mutex_unlock(&inputLock);
}
bool AbstractDecodedStream::isEOS()
{
- vlc_mutex_lock(&inputLock);
+ vlc_mutex_locker locker(&inputLock);
bool b = (status == FAILED || status == DRAINED);
- vlc_mutex_unlock(&inputLock);
return b;
}
bool AbstractDecodedStream::ReachedPlaybackTime(vlc_tick_t t)
{
- vlc_mutex_lock(&inputLock);
+ vlc_mutex_locker locker(&inputLock);
bool b = (pcr != VLC_TICK_INVALID) && t < pcr;
b |= (status == DRAINED) || (status == FAILED);
- vlc_mutex_unlock(&inputLock);
return b;
}
=====================================
modules/video_output/decklink.cpp
=====================================
@@ -424,7 +424,7 @@ static int OpenDecklink(vout_display_t *vd, decklink_sys_t *sys, video_format_t
} wanted_mode;
wanted_mode.id = bmdModeUnknown;
- vlc_mutex_lock(&sys->lock);
+ vlc_mutex_locker locker(&sys->lock);
/* wait until aout is ready */
msg_Info(vd, "Waiting for DeckLink audio input module to start");
@@ -610,8 +610,6 @@ static int OpenDecklink(vout_display_t *vd, decklink_sys_t *sys, video_format_t
p_attributes->Release();
decklink_iterator->Release();
- vlc_mutex_unlock(&sys->lock);
-
return VLC_SUCCESS;
error:
@@ -631,8 +629,6 @@ error:
p_display_mode->Release();
video_format_Clean(fmt);
- vlc_mutex_unlock(&sys->lock);
-
return VLC_EGENERIC;
#undef CHECK
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/800b477ca8cee6ccc6a6b2d9b484a748f153d8cd...3dc7f9dcd17014a7c161204f9933a4412a88020d
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/800b477ca8cee6ccc6a6b2d9b484a748f153d8cd...3dc7f9dcd17014a7c161204f9933a4412a88020d
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list