Always make a full copy of the subtitles for ThreadedFrameSource after a save

Saving can add new lines to the file without making a commit, resulting
in the rendering thread's copy of the file getting out of sync.
This commit is contained in:
Thomas Goyne 2013-01-14 08:15:12 -08:00
parent 9a69ca9de4
commit c08a9d4d7d
2 changed files with 12 additions and 3 deletions

View File

@ -63,8 +63,6 @@
#include "video_context.h"
#include "video_frame.h"
/// @brief Constructor
///
VideoContext::VideoContext()
: playback(this)
, startMS(0)
@ -74,6 +72,7 @@ VideoContext::VideoContext()
, arType(0)
, hasSubtitles(false)
, playAudioOnStep(OPT_GET("Audio/Plays When Stepping Video"))
, no_amend(false)
{
Bind(EVT_VIDEO_ERROR, &VideoContext::OnVideoError, this);
Bind(EVT_SUBTITLES_ERROR, &VideoContext::OnSubtitlesError, this);
@ -236,15 +235,19 @@ void VideoContext::Reload() {
void VideoContext::OnSubtitlesCommit(int type, std::set<const AssEntry *> const& changed) {
if (!IsLoaded()) return;
if (changed.empty())
if (changed.empty() || no_amend)
provider->LoadSubtitles(context->ass);
else
provider->UpdateSubtitles(context->ass, changed);
if (!IsPlaying())
GetFrameAsync(frame_n);
no_amend = false;
}
void VideoContext::OnSubtitlesSave() {
no_amend = true;
context->ass->SetScriptInfo("VFR File", MakeRelativePath(GetTimecodesName(), context->ass->filename));
context->ass->SetScriptInfo("Keyframes File", MakeRelativePath(GetKeyFramesName(), context->ass->filename));

View File

@ -130,6 +130,12 @@ class VideoContext : public wxEvtHandler {
/// Cached option for audio playing when frame stepping
const agi::OptionValue* playAudioOnStep;
/// Amending the frame source's copy of the subtitle file requires that it
/// be kept in perfect sync. Saving the file can add lines to the file
/// without a commit, breaking this sync, so force a non-amend after each
/// save.
bool no_amend;
void OnPlayTimer(wxTimerEvent &event);
/// The timecodes from the video file