1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00

DATV demod: implemented audio and video mute. Corrected audio volume

This commit is contained in:
f4exb 2019-03-23 06:06:42 +01:00
parent 9e668f5f22
commit 2d6730678d
11 changed files with 101 additions and 71 deletions

Binary file not shown.

View File

@ -961,6 +961,13 @@ void DATVDemod::applySettings(const DATVDemodSettings& settings, bool force)
}
}
if ((settings.m_videoMute) != (m_settings.m_videoMute) || force)
{
if (m_objRegisteredVideoRender) {
m_objRegisteredVideoRender->setVideoMute(settings.m_videoMute);
}
}
if (m_settings.isDifferent(settings) || force)
{
m_objSettingsMutex.lock();

View File

@ -186,10 +186,10 @@ DATVDemodGUI::DATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, Ba
m_deviceUISet->addChannelMarker(&m_objChannelMarker);
m_deviceUISet->addRollupWidget(this);
QPixmap pixmapTarget = QPixmap(":/film.png");
pixmapTarget = pixmapTarget.scaled(16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation);
ui->videoPlay->setAlignment(Qt::AlignCenter);
ui->videoPlay->setPixmap(pixmapTarget);
// QPixmap pixmapTarget = QPixmap(":/film.png");
// pixmapTarget = pixmapTarget.scaled(16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation);
// ui->videoPlay->setAlignment(Qt::AlignCenter);
// ui->videoPlay->setPixmap(pixmapTarget);
CRightClickEnabler *audioMuteRightClickEnabler = new CRightClickEnabler(ui->audioMute);
connect(audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect()));
@ -234,9 +234,9 @@ void DATVDemodGUI::displaySettings()
ui->rfBandwidth->setValue(m_settings.m_rfBandwidth);
ui->spiSymbolRate->setValue(m_settings.m_symbolRate);
ui->spiExcursion->setValue(m_settings.m_excursion);
ui->audioMute->setChecked(m_settings.m_audioMute);
ui->audioVolume->setValue(m_settings.m_audioVolume);
ui->audioVolumeText->setText(tr("%1").arg(m_settings.m_audioVolume));
ui->videoMute->setChecked(m_settings.m_videoMute);
blockApplySettings(false);
m_objChannelMarker.blockSignals(false);
@ -352,6 +352,7 @@ void DATVDemodGUI::applySettings(bool force)
m_settings.m_excursion = ui->spiExcursion->value();
m_settings.m_audioMute = ui->audioMute->isChecked();
m_settings.m_audioVolume = ui->audioVolume->value();
m_settings.m_videoMute = ui->videoMute->isChecked();
QString msg = tr("DATVDemodGUI::applySettings: force: %1").arg(force);
m_settings.debug(msg);
@ -639,6 +640,12 @@ void DATVDemodGUI::on_audioMute_toggled(bool checked)
applySettings();
}
void DATVDemodGUI::on_videoMute_toggled(bool checked)
{
(void) checked;
applySettings();
}
void DATVDemodGUI::on_audioVolume_valueChanged(int value)
{
ui->audioVolumeText->setText(tr("%1").arg(value));
@ -669,9 +676,9 @@ void DATVDemodGUI::on_StreamMetaDataChanged(DataTSMetaData2 *objMetaData)
ui->chkDecoding->setChecked(objMetaData->OK_Decoding);
if (objMetaData->OK_Decoding) {
ui->videoPlay->setStyleSheet("QLabel { background-color : green; }");
ui->videoMute->setStyleSheet("QToolButton { background-color : green; }");
} else {
ui->videoPlay->setStyleSheet("QLabel { background:rgb(79,79,79); }");
ui->videoMute->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
}
if (objMetaData->Height > 0) {

View File

@ -94,6 +94,7 @@ private slots:
void on_rfBandwidth_changed(qint64 value);
void on_audioMute_toggled(bool checked);
void on_audioVolume_valueChanged(int value);
void on_videoMute_toggled(bool checked);
private:
Ui::DATVDemodGUI* ui;

View File

@ -204,7 +204,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="datvTab">
<attribute name="title">
@ -913,34 +913,15 @@
<string>Audio mute (right click: Audio select)</string>
</property>
<property name="text">
<string>...</string>
<string/>
</property>
<property name="icon">
<iconset resource="../../../sdrgui/resources/res.qrc">
<normaloff>:/sound_on.png</normaloff>
<normalon>:/sound_off.png</normalon>:/sound_on.png</iconset>
</property>
</widget>
<widget class="QLabel" name="videoPlay">
<property name="geometry">
<rect>
<x>400</x>
<y>300</y>
<width>24</width>
<height>24</height>
</rect>
</property>
<property name="toolTip">
<string>Video play indicator</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="text">
<string/>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
<widget class="QSlider" name="audioVolume">
@ -956,14 +937,17 @@
<string>Audio volume control</string>
</property>
<property name="minimum">
<number>-32</number>
<number>0</number>
</property>
<property name="maximum">
<number>32</number>
<number>100</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>80</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -981,12 +965,36 @@
<string>Audio volume</string>
</property>
<property name="text">
<string>-32</string>
<string>100</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QToolButton" name="videoMute">
<property name="geometry">
<rect>
<x>400</x>
<y>300</y>
<width>24</width>
<height>24</height>
</rect>
</property>
<property name="toolTip">
<string>Video mute</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../sdrgui/resources/res.qrc">
<normaloff>:/film.png</normaloff>
<normalon>:/no_film.png</normalon>:/film.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</widget>
</widget>
</widget>

View File

@ -50,6 +50,7 @@ void DATVDemodSettings::resetToDefaults()
m_audioMute = false;
m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName;
m_audioVolume = 0;
m_videoMute = false;
}
QByteArray DATVDemodSettings::serialize() const
@ -79,6 +80,7 @@ QByteArray DATVDemodSettings::serialize() const
s.writeS32(19, m_excursion);
s.writeString(20, m_audioDeviceName);
s.writeS32(21, m_audioVolume);
s.writeBool(22, m_videoMute);
return s.final();
}
@ -139,6 +141,7 @@ bool DATVDemodSettings::deserialize(const QByteArray& data)
d.readS32(19, &m_excursion, 10);
d.readString(20, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName);
d.readS32(21, &m_audioVolume, 0);
d.readBool(22, &m_videoMute, false);
return true;
}
@ -168,7 +171,8 @@ void DATVDemodSettings::debug(const QString& msg) const
<< " m_excursion: " << m_excursion
<< " m_audioMute: " << m_audioMute
<< " m_audioDeviceName: " << m_audioDeviceName
<< " m_audioVolume: " << m_audioVolume;
<< " m_audioVolume: " << m_audioVolume
<< " m_videoMute: " << m_videoMute;
}
bool DATVDemodSettings::isDifferent(const DATVDemodSettings& other)

View File

@ -73,6 +73,7 @@ struct DATVDemodSettings
bool m_viterbi;
int m_excursion;
int m_audioVolume;
bool m_videoMute;
DATVDemodSettings();
void resetToDefaults();

View File

@ -37,8 +37,6 @@ DATVideoRender::DATVideoRender(QWidget *parent) : TVScreen(true, parent)
m_formatCtx = nullptr;
m_videoDecoderCtx = nullptr;
m_swsCtx = nullptr;
m_audioBuffer.resize(1 << 14);
m_audioBufferFill = 0;
m_audioFifo = nullptr;
m_audioSWR = nullptr;
m_audioSampleRate = 48000;
@ -46,6 +44,7 @@ DATVideoRender::DATVideoRender(QWidget *parent) : TVScreen(true, parent)
m_videoStreamIndex = -1;
m_audioStreamIndex = -1;
m_audioMute = false;
m_videoMute = false;
m_audioVolume = 0;
m_updateAudioResampler = false;
@ -481,7 +480,7 @@ bool DATVideoRender::RenderStream()
}
//Video channel
if (packet.stream_index == m_videoStreamIndex)
if ((packet.stream_index == m_videoStreamIndex) && (!m_videoMute))
{
memset(m_frame, 0, sizeof(AVFrame));
av_frame_unref(m_frame);
@ -580,7 +579,7 @@ bool DATVideoRender::RenderStream()
}
}
// Audio channel
else if ((packet.stream_index == m_audioStreamIndex) && (m_audioFifo) && (swr_is_initialized(m_audioSWR)))
else if ((packet.stream_index == m_audioStreamIndex) && (m_audioFifo) && (swr_is_initialized(m_audioSWR)) && (!m_audioMute))
{
if (m_updateAudioResampler)
{
@ -597,37 +596,45 @@ bool DATVideoRender::RenderStream()
{
if (gotFrame)
{
uint16_t *audioBuffer;
int16_t *audioBuffer;
av_samples_alloc((uint8_t**) &audioBuffer, nullptr, 2, m_frame->nb_samples, AV_SAMPLE_FMT_S16, 0);
int frame_count = swr_convert(m_audioSWR, (uint8_t**) &audioBuffer, m_frame->nb_samples, (const uint8_t**) m_frame->data, m_frame->nb_samples);
// direct writing:
// int ret = m_audioFifo->write((const quint8*) &audioBuffer[0], frame_count);
// if (ret < frame_count) {
// qDebug("DATVideoRender::RenderStream: audio frames missing %d vs %d", ret, frame_count);
// }
if (m_audioFifoBufferIndex + frame_count < m_audioFifoBufferSize)
{
std::copy(&audioBuffer[0], &audioBuffer[2*frame_count], &m_audioFifoBuffer[2*m_audioFifoBufferIndex]);
m_audioFifoBufferIndex += frame_count;
}
else
{
int remainder = m_audioFifoBufferSize - m_audioFifoBufferIndex;
std::copy(&audioBuffer[0], &audioBuffer[2*remainder], &m_audioFifoBuffer[2*m_audioFifoBufferIndex]);
m_audioFifo->write((const quint8*) &m_audioFifoBuffer[0], m_audioFifoBufferSize);
std::copy(&audioBuffer[2*remainder], &audioBuffer[2*frame_count], &m_audioFifoBuffer[0]);
m_audioFifoBufferIndex = frame_count - remainder;
}
// m_audioFifoBufferIndex += frame_count;
// if (m_audioFifoBufferIndex >= m_audioFifoBufferSize)
// buffered writing:
// if (m_audioFifoBufferIndex + frame_count < m_audioFifoBufferSize)
// {
// m_audioFifo->write((const quint8*)&m_audioFifoBuffer[0], m_audioFifoBufferSize);
// m_audioFifoBufferIndex -= m_audioFifoBufferSize;
// std::copy(&audioBuffer[0], &audioBuffer[2*frame_count], &m_audioFifoBuffer[2*m_audioFifoBufferIndex]);
// m_audioFifoBufferIndex += frame_count;
// }
// else
// {
// int remainder = m_audioFifoBufferSize - m_audioFifoBufferIndex;
// std::copy(&audioBuffer[0], &audioBuffer[2*remainder], &m_audioFifoBuffer[2*m_audioFifoBufferIndex]);
// m_audioFifo->write((const quint8*) &m_audioFifoBuffer[0], m_audioFifoBufferSize);
// std::copy(&audioBuffer[2*remainder], &audioBuffer[2*frame_count], &m_audioFifoBuffer[0]);
// m_audioFifoBufferIndex = frame_count - remainder;
// }
// Apply volume:
for (int i = 0; i < frame_count; i++)
{
m_audioFifoBuffer[2*m_audioFifoBufferIndex] = m_audioVolume * audioBuffer[2*i];
m_audioFifoBuffer[2*m_audioFifoBufferIndex+1] = m_audioVolume * audioBuffer[2*i+1];
m_audioFifoBufferIndex++;
if (m_audioFifoBufferIndex >= m_audioFifoBufferSize)
{
m_audioFifo->write((const quint8*) &m_audioFifoBuffer[0], m_audioFifoBufferSize);
m_audioFifoBufferIndex = 0;
}
}
}
}
else
@ -647,8 +654,8 @@ bool DATVideoRender::RenderStream()
void DATVideoRender::setAudioVolume(int audioVolume)
{
m_audioVolume = audioVolume < -32 ? -32 : audioVolume > 32 ? 32 : audioVolume;
m_updateAudioResampler = true;
int audioVolumeConstrained = audioVolume < 0 ? 0 : audioVolume > 100 ? 100 : audioVolume;
m_audioVolume = audioVolumeConstrained / 100.0f;
}
void DATVideoRender::setResampler()
@ -666,9 +673,6 @@ void DATVideoRender::setResampler()
av_opt_set_int(m_audioSWR, "out_sample_rate", m_audioSampleRate, 0);
av_opt_set_sample_fmt(m_audioSWR, "in_sample_fmt", m_audioDecoderCtx->sample_fmt, 0);
av_opt_set_sample_fmt(m_audioSWR, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
av_opt_set_int(m_audioSWR, "center_mix_level", m_audioVolume, 0);
av_opt_set_int(m_audioSWR, "surround_mix_level", m_audioVolume, 0);
av_opt_set_int(m_audioSWR, "lfe_mix_level", m_audioVolume, 0);
swr_init(m_audioSWR);
@ -680,10 +684,7 @@ void DATVideoRender::setResampler()
<< " in_sample_rate: " << m_audioDecoderCtx->sample_rate
<< " out_sample_rate: " << m_audioSampleRate
<< " in_sample_fmt: " << m_audioDecoderCtx->sample_fmt
<< " out_sample_fmt: " << AV_SAMPLE_FMT_S16
<< " center_mix_level: " << m_audioVolume
<< " surround_mix_level: " << m_audioVolume
<< " lfe_mix_level: " << m_audioVolume;
<< " out_sample_fmt: " << AV_SAMPLE_FMT_S16;
}
bool DATVideoRender::CloseStream(QIODevice *device)

View File

@ -100,6 +100,7 @@ class DATVideoRender : public TVScreen
int getAudioStreamIndex() const { return m_audioStreamIndex; }
void setAudioMute(bool audioMute) { m_audioMute = audioMute; }
void setVideoMute(bool videoMute) { m_videoMute = videoMute; }
void setAudioVolume(int audioVolume);
struct DataTSMetaData2 MetaData;
@ -116,16 +117,15 @@ class DATVideoRender : public TVScreen
AVCodecContext *m_videoDecoderCtx;
AVCodecContext *m_audioDecoderCtx;
AVFrame *m_frame;
AudioVector m_audioBuffer;
uint32_t m_audioBufferFill;
AudioFifo *m_audioFifo;
struct SwrContext* m_audioSWR;
int m_audioSampleRate;
static const int m_audioFifoBufferSize = 16000;
uint16_t m_audioFifoBuffer[m_audioFifoBufferSize*2]; // 2 channels
int16_t m_audioFifoBuffer[m_audioFifoBufferSize*2]; // 2 channels
int m_audioFifoBufferIndex;
bool m_audioMute;
int m_audioVolume;
bool m_videoMute;
float m_audioVolume;
bool m_updateAudioResampler;
uint8_t *m_pbytDecodedData[4];

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>no_film.png</file>
<file>gps.png</file>
<file>linear.png</file>
<file>logarithmic.png</file>