From 855c460ff37687f3a1c5167ea6b650772fe057a5 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 19 Sep 2020 12:30:42 +1000 Subject: [PATCH] footageviewer: use sequence functions to set video/audio params Code improvement by re-using existing code. Existing code prevents crash when loading a still image. --- app/widget/viewer/footageviewer.cpp | 51 +++++++++++------------------ app/widget/viewer/footageviewer.h | 4 +-- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/app/widget/viewer/footageviewer.cpp b/app/widget/viewer/footageviewer.cpp index c4df185ce..5ca81ae1e 100644 --- a/app/widget/viewer/footageviewer.cpp +++ b/app/widget/viewer/footageviewer.cpp @@ -33,8 +33,10 @@ FootageViewerWidget::FootageViewerWidget(QWidget *parent) : footage_(nullptr) { video_node_ = new VideoInput(); + sequence_.AddNode(video_node_); + audio_node_ = new AudioInput(); - viewer_node_ = new ViewerOutput(); + sequence_.AddNode(audio_node_); connect(display_widget(), &ViewerDisplayWidget::DragStarted, this, &FootageViewerWidget::StartFootageDrag); @@ -55,17 +57,29 @@ void FootageViewerWidget::SetFootage(Footage *footage) ConnectViewerNode(nullptr); - NodeParam::DisconnectEdge(video_node_->output(), viewer_node_->texture_input()); - NodeParam::DisconnectEdge(audio_node_->output(), viewer_node_->samples_input()); + NodeParam::DisconnectEdge(video_node_->output(), sequence_.viewer_output()->texture_input()); + NodeParam::DisconnectEdge(audio_node_->output(), sequence_.viewer_output()->samples_input()); } footage_ = footage; if (footage_) { + // Update sequence media name + sequence_.viewer_output()->set_media_name(footage_->name()); + + // Reset parameters and then attempt to set from footage + sequence_.set_default_parameters(); + sequence_.set_parameters_from_footage({footage_}); + + // Use first of each stream VideoStreamPtr video_stream = nullptr; AudioStreamPtr audio_stream = nullptr; foreach (StreamPtr s, footage_->streams()) { + if (!s->enabled()) { + continue; + } + if (!audio_stream && s->type() == Stream::kAudio) { audio_stream = std::static_pointer_cast(s); } @@ -80,42 +94,17 @@ void FootageViewerWidget::SetFootage(Footage *footage) } } - viewer_node_->set_media_name(footage_->name()); - if (video_stream) { video_node_->SetFootage(video_stream); - viewer_node_->set_video_params(VideoParams(video_stream->width(), - video_stream->height(), - video_stream->frame_rate().flipped(), - static_cast(Config::Current()["DefaultSequencePreviewFormat"].toInt()), - video_stream->pixel_aspect_ratio(), - video_stream->interlacing(), - VideoParams::generate_auto_divider(video_stream->width(), video_stream->height()))); - NodeParam::ConnectEdge(video_node_->output(), viewer_node_->texture_input()); - } else { - int width = Config::Current()["DefaultSequenceWidth"].toInt(); - int height = Config::Current()["DefaultSequenceHeight"].toInt(); - - viewer_node_->set_video_params(VideoParams(width, - height, - Config::Current()["DefaultSequenceFrameRate"].value(), - static_cast(Config::Current()["DefaultSequencePreviewFormat"].toInt()), - Config::Current()["DefaultSequencePixelAspect"].value(), - Config::Current()["DefaultSequenceInterlacing"].value(), - VideoParams::generate_auto_divider(width, height))); + NodeParam::ConnectEdge(video_node_->output(), sequence_.viewer_output()->texture_input()); } if (audio_stream) { audio_node_->SetFootage(audio_stream); - viewer_node_->set_audio_params(AudioParams(audio_stream->sample_rate(), audio_stream->channel_layout(), SampleFormat::kInternalFormat)); - NodeParam::ConnectEdge(audio_node_->output(), viewer_node_->samples_input()); - } else { - viewer_node_->set_audio_params(AudioParams(Config::Current()["DefaultSequenceAudioFrequency"].toInt(), - Config::Current()["DefaultSequenceAudioLayout"].toULongLong(), - SampleFormat::kInternalFormat)); + NodeParam::ConnectEdge(audio_node_->output(), sequence_.viewer_output()->samples_input()); } - ConnectViewerNode(viewer_node_, footage_->project()->color_manager()); + ConnectViewerNode(sequence_.viewer_output(), footage_->project()->color_manager()); SetTimestamp(cached_timestamps_.value(footage_, 0)); } diff --git a/app/widget/viewer/footageviewer.h b/app/widget/viewer/footageviewer.h index 36f688fa9..af093eb8f 100644 --- a/app/widget/viewer/footageviewer.h +++ b/app/widget/viewer/footageviewer.h @@ -47,12 +47,12 @@ private: Footage* footage_; + Sequence sequence_; + VideoInput* video_node_; AudioInput* audio_node_; - ViewerOutput* viewer_node_; - QHash cached_timestamps_; private slots: