made speed changes undoable

This commit is contained in:
itsmattkc
2018-10-06 17:16:30 +10:00
parent b749d3409b
commit d0dc2661d9
7 changed files with 308 additions and 55 deletions
+5 -19
View File
@@ -250,21 +250,11 @@ void cache_video_worker(Clip* c, long playhead, ClipCache* cache) {
ret = retrieve_next_frame(c, c->frame);
if (ret >= 0) {
// optimization: mathematically determine based on the sequence and clips' frame rates whether this frame will actually be shown
// note: is not actually much faster and currently leads to crashes, may remove in the future
// int proposed_frame = qFloor((i+cache->offset) * fr_ratio);
// if (proposed_frame != c->last_cached_frame) {
if ((ret = av_buffersrc_add_frame_flags(c->buffersrc_ctx, c->frame, AV_BUFFERSRC_FLAG_KEEP_REF)) < 0) {
qDebug() << "[ERROR] Could not feed filtergraph -" << ret;
error = true;
break;
// } else {
// c->last_cached_frame = proposed_frame;
}
// } else {
// i++;
// }
if ((ret = av_buffersrc_add_frame_flags(c->buffersrc_ctx, c->frame, AV_BUFFERSRC_FLAG_KEEP_REF)) < 0) {
qDebug() << "[ERROR] Could not feed filtergraph -" << ret;
error = true;
break;
}
} else {
if (ret == AVERROR_EOF) {
c->reached_end = true;
@@ -313,7 +303,6 @@ void reset_cache(Clip* c, long target_frame) {
if (c->stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
// seeks to nearest keyframe (target_frame represents internal clip frame)
av_seek_frame(c->formatCtx, ms->file_index, (int64_t) qFloor(clip_frame_to_seconds(c, target_frame) / timebase), AVSEEK_FLAG_BACKWARD);
// play up to the frame we actually want
@@ -329,11 +318,8 @@ void reset_cache(Clip* c, long target_frame) {
} while (retrieved_frame < target_frame);
av_frame_free(&temp);
c->last_cached_frame = -1;
} else if (c->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
// seek (target_frame represents timeline timecode in frames, not clip timecode)
// swr_drop_output(c->swr_ctx, swr_get_out_samples(c->swr_ctx, 0));
av_seek_frame(c->formatCtx, ms->file_index, playhead_to_seconds(c, target_frame) / timebase, AVSEEK_FLAG_BACKWARD);
c->audio_target_frame = target_frame;
c->frame_sample_index = -1;
+16 -3
View File
@@ -110,6 +110,9 @@ bool get_clip_frame(Clip* c, long playhead) {
MediaStream* ms = static_cast<Media*>(c->media)->get_stream_from_file_index(c->track < 0, c->media_stream);
long sequence_clip_time = playhead - c->timeline_in + c->clip_in;
if (c->reverse && !ms->infinite_length) sequence_clip_time = c->getMaximumLength() - sequence_clip_time - 1;
long clip_time = refactor_frame_number(sequence_clip_time, c->sequence->frame_rate, c->getMediaFrameRate()*c->speed);
AVFrame* current_frame = NULL;
@@ -162,7 +165,8 @@ bool get_clip_frame(Clip* c, long playhead) {
}
} else {
// this is technically bad, unless we just seeked
c->cache_A.unread = c->cache_B.unread = false;
c->cache_A.unread = false;
c->cache_B.unread = false;
cache_needs_reset = true;
}
@@ -171,14 +175,23 @@ bool get_clip_frame(Clip* c, long playhead) {
current_frame = cache[clip_time - cache_offset];
}
// determine whether we should s1tart filling the other cache
// determine whether we should start filling the other cache
if (!using_cache_A || !using_cache_B) {
if (c->lock.tryLock()) {
long cache_time;
if (cache_needs_reset) {
cache_time = (c->reverse) ? qMax(clip_time - c->cache_size, 0L) : qMax(clip_time, 0L);
} else if (c->reverse) {
cache_time = (cache_offset - c->cache_size);
} else {
cache_time = (cache_offset + c->cache_size);
}
bool write_A = (!using_cache_A && !c->cache_A.unread);
bool write_B = (!using_cache_B && !c->cache_B.unread);
if (write_A || write_B) {
// if we have no cache and need to seek, start us at the current playhead, otherwise start at the end of the current cache
cache_clip(c, (cache_needs_reset) ? qMax(clip_time, 0L) : cache_offset + c->cache_size, write_A, write_B, cache_needs_reset, NULL);
cache_clip(c, cache_time, write_A, write_B, (cache_needs_reset || c->reverse), NULL);
}
c->lock.unlock();
}