1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-07-07 09:11:38 +00:00

switch to lock_guards

This commit is contained in:
Evil Eye 2021-05-13 11:25:58 +02:00
parent de37ca8e2c
commit 1b61ec979d

View file

@ -80,8 +80,7 @@ void VideoState::setAudioFactory(MovieAudioFactory *factory)
void PacketQueue::put(AVPacket *pkt) void PacketQueue::put(AVPacket *pkt)
{ {
AVPacketList *pkt1; std::unique_ptr<AVPacketList> pkt1(static_cast<AVPacketList*>(av_malloc(sizeof(AVPacketList))));
pkt1 = (AVPacketList*)av_malloc(sizeof(AVPacketList));
if(!pkt1) throw std::bad_alloc(); if(!pkt1) throw std::bad_alloc();
if(pkt == &flush_pkt) if(pkt == &flush_pkt)
@ -91,18 +90,16 @@ void PacketQueue::put(AVPacket *pkt)
pkt1->next = nullptr; pkt1->next = nullptr;
this->mutex.lock (); std::lock_guard<std::mutex> lock(this->mutex);
if(!last_pkt) if(!last_pkt)
this->first_pkt = pkt1; this->first_pkt = pkt1.get();
else else
this->last_pkt->next = pkt1; this->last_pkt->next = pkt1.get();
this->last_pkt = pkt1; this->last_pkt = pkt1.release();
this->nb_packets++; this->nb_packets++;
this->size += pkt1->pkt.size; this->size += pkt1->pkt.size;
this->cond.notify_one(); this->cond.notify_one();
this->mutex.unlock();
} }
int PacketQueue::get(AVPacket *pkt, VideoState *is) int PacketQueue::get(AVPacket *pkt, VideoState *is)
@ -144,7 +141,7 @@ void PacketQueue::clear()
{ {
AVPacketList *pkt, *pkt1; AVPacketList *pkt, *pkt1;
this->mutex.lock(); std::lock_guard<std::mutex> lock(this->mutex);
for(pkt = this->first_pkt; pkt != nullptr; pkt = pkt1) for(pkt = this->first_pkt; pkt != nullptr; pkt = pkt1)
{ {
pkt1 = pkt->next; pkt1 = pkt->next;
@ -156,7 +153,6 @@ void PacketQueue::clear()
this->first_pkt = nullptr; this->first_pkt = nullptr;
this->nb_packets = 0; this->nb_packets = 0;
this->size = 0; this->size = 0;
this->mutex.unlock ();
} }
int VideoPicture::set_dimensions(int w, int h) { int VideoPicture::set_dimensions(int w, int h) {
@ -325,7 +321,7 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts)
if(this->mQuit) if(this->mQuit)
return -1; return -1;
this->pictq_mutex.lock(); std::lock_guard<std::mutex> lock(this->pictq_mutex);
// windex is set to 0 initially // windex is set to 0 initially
vp = &this->pictq[this->pictq_windex]; vp = &this->pictq[this->pictq_windex];
@ -350,10 +346,7 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts)
vp->pts = pts; vp->pts = pts;
if (vp->set_dimensions(w, h) < 0) if (vp->set_dimensions(w, h) < 0)
{
this->pictq_mutex.unlock();
return -1; return -1;
}
sws_scale(this->sws_context, pFrame->data, pFrame->linesize, sws_scale(this->sws_context, pFrame->data, pFrame->linesize,
0, this->video_ctx->height, vp->rgbaFrame->data, vp->rgbaFrame->linesize); 0, this->video_ctx->height, vp->rgbaFrame->data, vp->rgbaFrame->linesize);
@ -361,7 +354,6 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts)
// now we inform our display thread that we have a pic ready // now we inform our display thread that we have a pic ready
this->pictq_windex = (this->pictq_windex+1) % VIDEO_PICTURE_ARRAY_SIZE; this->pictq_windex = (this->pictq_windex+1) % VIDEO_PICTURE_ARRAY_SIZE;
this->pictq_size++; this->pictq_size++;
this->pictq_mutex.unlock();
return 0; return 0;
} }