From 1200eacd50f509e23c5adcd040a1194544f228fd Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 22 Jun 2018 22:15:08 -0700 Subject: [PATCH] testing paste hang fix --- olive.pro.user | 2 +- playback/cacher.cpp | 11 +++--- playback/playback.cpp | 2 +- project/clip.cpp | 6 ++-- ui/viewerwidget.cpp | 82 +++++++++++++++++++++++-------------------- 5 files changed, 53 insertions(+), 50 deletions(-) diff --git a/olive.pro.user b/olive.pro.user index 593fd1514..148ad29d4 100644 --- a/olive.pro.user +++ b/olive.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/playback/cacher.cpp b/playback/cacher.cpp index 37c1462d5..87d103e9a 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -302,9 +302,7 @@ void open_clip_worker(Clip* clip) { clip->frame = av_frame_alloc(); - qDebug() << "[INFO] Clip opened on track" << clip->track; - - clip->open = true; + qDebug() << "[INFO] Clip opened on track" << clip->track; } void cache_clip_worker(Clip* clip, long playhead, bool write_A, bool write_B, bool reset) { @@ -369,12 +367,13 @@ void close_clip_worker(Clip* clip) { void Cacher::run() { // open_lock is used to prevent the clip from being destroyed before the cacher has closed it properly + clip->open = true; + caching = true; clip->open_lock.lock(); open_clip_worker(clip); - caching = true; - while (true) { + while (caching) { clip->can_cache.wait(&clip->lock); if (!caching) { break; @@ -383,7 +382,7 @@ void Cacher::run() { } } - close_clip_worker(clip); + close_clip_worker(clip); clip->lock.unlock(); clip->open_lock.unlock(); diff --git a/playback/playback.cpp b/playback/playback.cpp index 48d89c6b9..be4cbe922 100644 --- a/playback/playback.cpp +++ b/playback/playback.cpp @@ -40,7 +40,7 @@ void handle_media(Sequence* sequence, long playhead, bool multithreaded) { open_clip(c, multithreaded); // add to current_clips, (insertion) sorted by track so composite them in order - cc_lock.lock(); + cc_lock.lock(); bool found = false; for (int j=0;jtrack < c->track) { diff --git a/project/clip.cpp b/project/clip.cpp index 021de08da..3f92f0083 100644 --- a/project/clip.cpp +++ b/project/clip.cpp @@ -77,12 +77,12 @@ void Clip::reset() { } Clip::~Clip() { - if (open) { + if (open) { close_clip(this); } - // make sure clip has closed before clip is destroyed - open_lock.lock(); + // make sure clip has closed before clip is destroyed + open_lock.lock(); open_lock.unlock(); for (int i=0;istream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - // start preparing cache - get_clip_frame(c, playhead); + if (c->lock.tryLock()) { + if (c->stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + // start preparing cache + get_clip_frame(c, playhead); - if (c->texture == NULL) { - qDebug() << "[WARNING] Texture hasn't been created yet"; - texture_failed = true; - } else if (playhead >= c->timeline_in) { - glLoadIdentity(); - int half_width = c->sequence->width/2; - int half_height = c->sequence->height/2; - glOrtho(-half_width, half_width, half_height,- half_height, -1, 1); - int anchor_x = c->media_stream->video_width/2; - int anchor_y = c->media_stream->video_height/2; + if (c->texture == NULL) { + qDebug() << "[WARNING] Texture hasn't been created yet"; + texture_failed = true; + } else if (playhead >= c->timeline_in) { + glLoadIdentity(); + int half_width = c->sequence->width/2; + int half_height = c->sequence->height/2; + glOrtho(-half_width, half_width, half_height,- half_height, -1, 1); + int anchor_x = c->media_stream->video_width/2; + int anchor_y = c->media_stream->video_height/2; - // perform all transform effects - for (int j=0;jeffects.size();j++) { - c->effects.at(j)->process_gl(&anchor_x, &anchor_y); + // perform all transform effects + for (int j=0;jeffects.size();j++) { + c->effects.at(j)->process_gl(&anchor_x, &anchor_y); + } + + int anchor_right = c->media_stream->video_width - anchor_x; + int anchor_bottom = c->media_stream->video_height - anchor_y; + + c->texture->bind(); + + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); + glVertex2f(-anchor_x, -anchor_y); + glTexCoord2f(1.0, 0.0); + glVertex2f(anchor_right, -anchor_y); + glTexCoord2f(1.0, 1.0); + glVertex2f(anchor_right, anchor_bottom); + glTexCoord2f(0.0, 1.0); + glVertex2f(-anchor_x, anchor_bottom); + glEnd(); + + c->texture->release(); } - - int anchor_right = c->media_stream->video_width - anchor_x; - int anchor_bottom = c->media_stream->video_height - anchor_y; - - c->texture->bind(); - - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex2f(-anchor_x, -anchor_y); - glTexCoord2f(1.0, 0.0); - glVertex2f(anchor_right, -anchor_y); - glTexCoord2f(1.0, 1.0); - glVertex2f(anchor_right, anchor_bottom); - glTexCoord2f(0.0, 1.0); - glVertex2f(-anchor_x, anchor_bottom); - glEnd(); - - c->texture->release(); + } else if (render_audio && + c->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + // clip is not caching, start caching audio + cache_clip(c, playhead, false, false, c->reset_audio); } - } else if (render_audio && - c->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && - c->lock.tryLock()) { - // clip is not caching, start caching audio c->lock.unlock(); - cache_clip(c, playhead, false, false, c->reset_audio); + } else { + qDebug() << "[WARNING] Clip was locked, must still be active"; + texture_failed = true; } } }