Skip to content

Commit

Permalink
Merge pull request #791 from ElderOrb/fake_mkv
Browse files Browse the repository at this point in the history
only apply video filters if video streams exist
  • Loading branch information
dericed authored Sep 2, 2023
2 parents 0e7d78f + 60b4d39 commit f21108c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
16 changes: 14 additions & 2 deletions Source/Core/FileInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,13 +907,14 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil

QList<QString> filters;

if(!Filters[0].empty())
if(!Filters[0].empty() && !m_mediaParser->currentVideoStreams().empty())
filters.append(QString("%1 [stats]").arg(QString::fromStdString(Filters[0])));

if(!Filters[1].empty() && !m_mediaParser->currentAudioStreams().empty())
filters.append(QString::fromStdString(Filters[1]));

filters.append("scale=72:72,format=rgb24 [thumbnails]");
if(!m_mediaParser->currentVideoStreams().empty())
filters.append("scale=72:72,format=rgb24 [thumbnails]");

if(!StatsFromExternalData_IsOpen) {
// only do panels if no legacy report was opened
Expand Down Expand Up @@ -2106,6 +2107,16 @@ double FileInformation::abitDepth() const
return stream.stream()->codecpar->bits_per_coded_sample;
}

bool FileInformation::hasVideoStreams() const
{
return !m_mediaParser->currentVideoStreams().empty();
}

bool FileInformation::hasAudioStreams() const
{
return !m_mediaParser->currentAudioStreams().empty();
}

//---------------------------------------------------------------------------
int FileInformation::Frames_Count_Get (size_t Stats_Pos) const
{
Expand Down Expand Up @@ -2297,6 +2308,7 @@ double FileInformation::TimeStampOfCurrentFrame() const

bool FileInformation::isValid() const
{
qDebug() << "checking if media file valid: " << m_mediaParser->mediaStatus();
return m_mediaParser->mediaStatus() != QAVPlayer::InvalidMedia && m_mediaParser->mediaStatus() != QAVPlayer::NoMedia;
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Core/FileInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class FileInformation : public QThread
std::string channelLayout() const;
double abitDepth() const;

bool hasVideoStreams() const;
bool hasAudioStreams() const;

activefilters ActiveFilters;
activealltracks ActiveAllTracks;

Expand Down
16 changes: 16 additions & 0 deletions Source/GUI/filterselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QGridLayout>
#include <string>
#include <cmath>
#include <QStandardItemModel>

FilterSelector::FilterSelector(QWidget *parent, const std::function<bool(const char*)>& nameFilter) : QFrame(parent), FileInfoData(nullptr)
{
Expand Down Expand Up @@ -183,6 +184,21 @@ void FilterSelector::selectCurrentFilterByName(const char *filterName)
}
}

void FilterSelector::setFiltersEnabled(int type, bool enabled)
{
auto model = qobject_cast<QStandardItemModel*>(m_filterOptions.FiltersList->model());

for(auto i = 0; i < m_filterOptions.FiltersList->count(); ++i) {
auto physicalFilterIndex = getPhysicalFilterIndex(i);
auto filterType = Filters[physicalFilterIndex].Type;

if(filterType == type) {
auto item = model->item(i);
item->setFlags(enabled ? item->flags() | Qt::ItemIsEnabled : item->flags() & ~Qt::ItemIsEnabled);
}
}
}

QString FilterSelector::getFilter()
{
QString filterString;
Expand Down
1 change: 1 addition & 0 deletions Source/GUI/filterselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class FilterSelector : public QFrame
void setCurrentIndex(int index);
void selectCurrentFilter(int index);
void selectCurrentFilterByName(const char* filterName);
void setFiltersEnabled(int type, bool enabled);

QString getFilter();
QString getFilterName();
Expand Down
35 changes: 26 additions & 9 deletions Source/GUI/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ Player::Player(QWidget *parent) :
ui->adjustmentsGroupBox->layout()->setContentsMargins(2, 2, 2, 2);
ui->adjustmentsGroupBox->layout()->addWidget(m_adjustmentSelector);

m_filterSelectors[0]->selectCurrentFilter(-1);

// select 'normal' by default
m_filterSelectors[0]->enableCurrentFilter(true);

m_filterUpdateTimer.setSingleShot(true);
connect(&m_filterUpdateTimer, &QTimer::timeout, this, &Player::applyFilter);

Expand Down Expand Up @@ -449,10 +444,32 @@ void Player::setFile(FileInformation *fileInfo)
m_filterSelectors[i]->setFileInformation(m_fileInformation);
}

m_filterSelectors[0]->selectCurrentFilterByName("Normal");
m_filterSelectors[1]->selectCurrentFilterByName("Waveform");
m_filterSelectors[2]->selectCurrentFilterByName("Bit Plane (10 slices)");
m_filterSelectors[3]->selectCurrentFilterByName("Vectorscope");
bool hasVideoStreams = m_fileInformation->hasVideoStreams();
bool hasAudioStreams = m_fileInformation->hasAudioStreams();

if(hasVideoStreams) {
m_filterSelectors[0]->selectCurrentFilterByName("Normal");
m_filterSelectors[1]->selectCurrentFilterByName("Waveform");
m_filterSelectors[2]->selectCurrentFilterByName("Bit Plane (10 slices)");
m_filterSelectors[3]->selectCurrentFilterByName("Vectorscope");

// select 'normal' by default
m_filterSelectors[0]->enableCurrentFilter(true);

} else if (hasAudioStreams) {
m_filterSelectors[0]->selectCurrentFilterByName("Audio Bit Scope");
m_filterSelectors[1]->selectCurrentFilterByName("Audio Waveform");
m_filterSelectors[2]->selectCurrentFilterByName("Audio Spectrum");
m_filterSelectors[3]->selectCurrentFilterByName("Audio Vectorscope");

// deselect 'normal' by default
m_filterSelectors[0]->enableCurrentFilter(false);
}

for(auto i = 0; i < 4; ++i) {
m_filterSelectors[i]->setFiltersEnabled(AVMEDIA_TYPE_AUDIO, hasAudioStreams);
m_filterSelectors[i]->setFiltersEnabled(AVMEDIA_TYPE_VIDEO, hasVideoStreams);
}

m_player->stop();
m_player->setFile(fileInfo->fileName());
Expand Down

0 comments on commit f21108c

Please sign in to comment.