diff --git a/plugins/channeltx/moddatv/datvmodgui.cpp b/plugins/channeltx/moddatv/datvmodgui.cpp index 4f33220da..e7f77f28b 100644 --- a/plugins/channeltx/moddatv/datvmodgui.cpp +++ b/plugins/channeltx/moddatv/datvmodgui.cpp @@ -289,6 +289,8 @@ void DATVModGUI::on_dvbStandard_currentIndexChanged(int index) ui->rollOff->blockSignals(false); ui->modulation->blockSignals(false); + // Called from displaySettings() too (applying off then: the settings came from the modulator), so it's restored + const bool doApplySettings = m_doApplySettings; m_doApplySettings = false; idx = ui->rollOff->findText(QString("%1").arg(m_settings.m_rollOff, 0, 'f', 2)); @@ -303,9 +305,10 @@ void DATVModGUI::on_dvbStandard_currentIndexChanged(int index) updateFEC(); setImageBitrate(); - m_doApplySettings = true; + m_doApplySettings = doApplySettings; - applySettings(QStringList("standard")); + // The roll-off, modulation and code rate can change with the standard + applySettings(QStringList({"standard", "rollOff", "modulation", "fec"})); } void DATVModGUI::updateFEC() @@ -376,11 +379,14 @@ void DATVModGUI::on_modulation_currentIndexChanged(int index) m_settings.m_modulation = (DATVModSettings::DATVModulation) index; else m_settings.m_modulation = (DATVModSettings::DATVModulation) (index + 1); + // The code rate can change with the modulation (as 32APSK has none below 3/4), so it's applied with it. When the + // standard's changing, that applies them all once it's done + const bool doApplySettings = m_doApplySettings; m_doApplySettings = false; updateFEC(); setImageBitrate(); - m_doApplySettings = true; - applySettings(QStringList("modulation")); + m_doApplySettings = doApplySettings; + applySettings(QStringList({"modulation", "fec"})); } void DATVModGUI::on_rollOff_currentIndexChanged(int index) diff --git a/plugins/channeltx/moddatv/datvmodsource.cpp b/plugins/channeltx/moddatv/datvmodsource.cpp index 567800e55..817dae746 100644 --- a/plugins/channeltx/moddatv/datvmodsource.cpp +++ b/plugins/channeltx/moddatv/datvmodsource.cpp @@ -17,6 +17,8 @@ /////////////////////////////////////////////////////////////////////////////////// #define BOOST_CHRONO_HEADER_ONLY +#include +#include #include //#include @@ -220,7 +222,13 @@ void DATVModSource::checkBitrates() } if (dataBitrate < m_mpegTSBitrate) qWarning() << "DVB data bitrate is lower than the bitrate of the MPEG transport stream"; - m_tsRatio = m_mpegTSBitrate/(float)dataBitrate; + const float tsRatio = m_mpegTSBitrate/(float)dataBitrate; + + if ((tsRatio != m_tsRatio) && (tsRatio > 0.0f) && (m_settings.m_source == DATVModSettings::SourceFile) && m_tsFileOK) { + m_frameCount = (int)(m_frameIdx / tsRatio); + } + + m_tsRatio = tsRatio; } DATVModSource::DATVModSource() : @@ -235,6 +243,7 @@ DATVModSource::DATVModSource() : m_symbolSel(0), m_symbolIdx(0), m_samplesPerSymbol(1), + m_symbolGain(0.5f), m_iqSymbols{}, m_plFrame(nullptr), m_udpSocket(nullptr), @@ -325,8 +334,10 @@ void DATVModSource::pullFinalize(Complex& ci, Sample& sample) double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); m_movingAverage(magsq); - sample.m_real = (FixReal) (ci.real() * SDR_TX_SCALEF); - sample.m_imag = (FixReal) (ci.imag() * SDR_TX_SCALEF); + // Clipped to full scale + const Real limit = (SDR_TX_SCALEF - 1.0f) / SDR_TX_SCALEF; + sample.m_real = (FixReal) (std::max(-limit, std::min(limit, (Real) ci.real())) * SDR_TX_SCALEF); + sample.m_imag = (FixReal) (std::max(-limit, std::min(limit, (Real) ci.imag())) * SDR_TX_SCALEF); } void DATVModSource::modulateSample() @@ -396,7 +407,7 @@ void DATVModSource::modulateSample() } else if (m_settings.m_source == DATVModSettings::SourceImage) { - if (m_frameCount == static_cast(m_tsGenerator.get_buffer_size()/sizeof(m_mpegTS))) + if (m_frameCount >= static_cast(m_tsGenerator.get_buffer_size()/sizeof(m_mpegTS))) { int bitrate = static_cast(getDVBSDataBitrate(m_settings) * 1.1f); // Add 10% margin if (bitrate <= 0) @@ -495,10 +506,11 @@ void DATVModSource::modulateSample() // QPSK if (m_settings.m_standard == DATVModSettings::DVB_S) { - // Does the 45-degree rotation matter? - // Makes a little difference to amplitude of filter output, but we could scale that - i = m_pulseShapeI.filter(m_iqSymbols[m_symbolIdx*2] ? -1.0f : 1.0f); - q = m_pulseShapeQ.filter(m_iqSymbols[m_symbolIdx*2+1] ? -1.0f : 1.0f); + // Unit magnitude, as the DVB-S2 and BPSK symbols are: +/-1 on each axis put the pulse shaping's peaks + // beyond full scale at 2 samples a symbol + const float a = 0.70710678f; + i = m_pulseShapeI.filter(m_iqSymbols[m_symbolIdx*2] ? -a : a); + q = m_pulseShapeQ.filter(m_iqSymbols[m_symbolIdx*2+1] ? -a : a); /* int sym = (m_iqSymbols[m_symbolIdx*2] << 1) | m_iqSymbols[m_symbolIdx*2+1]; if (sym == 0) @@ -547,8 +559,8 @@ void DATVModSource::modulateSample() m_sampleIdx = 0; } - m_modSample.real(i); - m_modSample.imag(q); + m_modSample.real(i * m_symbolGain); + m_modSample.imag(q * m_symbolGain); // These levels aren't currently used in the GUI Real t = std::abs(m_modSample); @@ -578,6 +590,12 @@ void DATVModSource::openTsFile(const QString& fileName) m_tsFileOK = false; m_mpegTSBitrate = getTSBitrate(fileName); + if (m_mpegTSStream.is_open()) { + m_mpegTSStream.close(); + } + + m_mpegTSStream.clear(); + if (m_mpegTSBitrate > 0) { m_mpegTSStream.open(qPrintable(fileName), std::ifstream::binary); @@ -588,7 +606,7 @@ void DATVModSource::openTsFile(const QString& fileName) m_mpegTSStream.seekg (0, m_mpegTSStream.beg); m_frameIdx = 0; m_frameCount = 0; - m_tsFileOK = true; + m_tsFileOK = m_mpegTSSize > 0; } checkBitrates(); } @@ -714,6 +732,11 @@ void DATVModSource::applyChannelSettings(int channelSampleRate, int channelFrequ m_pulseShapeI.create(m_settings.m_rollOff, 8, m_samplesPerSymbol, RootRaisedCosine::Energy); m_pulseShapeQ.create(m_settings.m_rollOff, 8, m_samplesPerSymbol, RootRaisedCosine::Energy); + // The filter's taps have unit energy, and it's given a symbol every m_samplesPerSymbol samples, so its output's + // power is 1 / m_samplesPerSymbol: scaled, whatever the symbol rate, to -3 dB of full scale for QPSK (its peaks, on + // each axis, then 0.78 of full scale at roll-off 0.35, 0.94 at 0.20), or -6 dB for 8PSK and APSK (whose outer ring is + // at full scale) and BPSK (on one axis), whose peaks are higher + m_symbolGain = (m_settings.m_modulation == DATVModSettings::QPSK ? 0.70710678f : 0.5f) * std::sqrt((Real) std::max(1, m_samplesPerSymbol)); } void DATVModSource::applySettings(const QStringList& settingsKeys, const DATVModSettings& settings, bool force) @@ -916,6 +939,7 @@ void DATVModSource::applySettings(const QStringList& settingsKeys, const DATVMod m_pulseShapeI.create(m_settings.m_rollOff, 8, m_samplesPerSymbol, RootRaisedCosine::Energy); m_pulseShapeQ.create(m_settings.m_rollOff, 8, m_samplesPerSymbol, RootRaisedCosine::Energy); + m_symbolGain = (m_settings.m_modulation == DATVModSettings::QPSK ? 0.70710678f : 0.5f) * std::sqrt((Real) std::max(1, m_samplesPerSymbol)); checkBitrates(); } diff --git a/plugins/channeltx/moddatv/datvmodsource.h b/plugins/channeltx/moddatv/datvmodsource.h index 706daff1e..64876652a 100644 --- a/plugins/channeltx/moddatv/datvmodsource.h +++ b/plugins/channeltx/moddatv/datvmodsource.h @@ -90,6 +90,7 @@ private: int m_symbolSel; //!< I or Q symbol for BPSK modulation only int m_symbolIdx; int m_samplesPerSymbol; + Real m_symbolGain; //!< Of the pulse shaping's output, so its level doesn't change with the samples a symbol uint8_t m_iqSymbols[DVBS::m_maxIQSymbols*2]; DVBS2 m_dvbs2; diff --git a/plugins/channeltx/moddatv/readme.md b/plugins/channeltx/moddatv/readme.md index 756bd8d24..6435be112 100644 --- a/plugins/channeltx/moddatv/readme.md +++ b/plugins/channeltx/moddatv/readme.md @@ -42,6 +42,9 @@ If the transport stream is via UDP, null packets will be transmitted when no dat Average total power in dB relative to a ±1.0 amplitude signal generated in the pass band. +The modulated signal's level doesn't depend on the symbol rate (or the samples per symbol): it's -3 dB of full scale for QPSK, and -6 dB for BPSK, +8PSK, 16APSK and 32APSK, whose peaks are higher. That leaves room for the pulse shaping's peaks, at any roll-off, and anything beyond full scale is clipped. +

5: Channel mute

Use this button to toggle mute for this channel. The radio waves on the icon are toggled on (active) and off (muted) accordingly. Default is channel active. @@ -161,11 +164,25 @@ This slider can be used to randomly set the current position in the file when fi An MPEG transport stream file can be created from a video file using ffmpeg: - ffmpeg -i input.avi -pix_fmt yuv420p -r 25 -s 720x576 -aspect 4:3 -c:v hevc -c:a libopus -b:v 500k -b:a 64k -maxrate 600k -bufsize 50k -f mpegts -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 -mpegts_service_id 1 -mpegts_pmt_start_pid 4096 -streamid 0:289 -streamid 1:337 -metadata service_provider="SDRangel" -metadata service_name="SDRangel TV" -y mpeg.ts + ffmpeg -i input.avi -pix_fmt yuv420p -r 25 -s 720x576 -aspect 4:3 -c:v hevc -c:a libopus -b:v 400k -b:a 64k -maxrate 450k -bufsize 450k -f mpegts -muxrate 691176 -g 50 -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 -mpegts_service_id 1 -mpegts_pmt_start_pid 4096 -streamid 0:289 -streamid 1:337 -metadata service_provider="SDRangel" -metadata service_name="SDRangel TV" -y mpeg.ts + +The transport stream should have a constant rate, set with `-muxrate` in bits per second, equal to (or a little below) the DVB data rate (3) for the settings it will be transmitted with. +The example's 691176 is the data rate for DVB-S, QPSK, code rate 1/2 at 0.75 MSym/s. +ffmpeg then pads the stream with null packets to that rate, and the timing in the stream (its PCRs) matches the rate the modulator transmits it at. + +Without `-muxrate`, ffmpeg creates a variable rate stream: its rate follows the video encoder's, which over a few seconds can be several times higher or lower than its average, even with `-maxrate`, which can cause choppy audio or video. + +The video and audio bitrates, plus 10 to 15% for the transport stream's overheads, must be less than the `-muxrate`. +Set the video encoder's `-maxrate` to limit its peak rate, with `-bufsize` (the video buffer it's measured over) about the same value (around a second's worth): a much smaller buffer reduces the picture quality. + +A "dts < pcr, TS is invalid" warning from ffmpeg means the video and audio rates need lowering. To stream from a video camera via UDP (on Windows): - ffmpeg -f dshow -i video="c922 Pro Stream Webcam":audio="Microphone (C922 Pro Stream Webcam)" -pix_fmt yuv420p -r 25 -s 720x576 -aspect 4:3 -c:v hevc -c:a libopus -b:v 500k -b:a 64k -maxrate 600k -bufsize 50k -f mpegts -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 -mpegts_service_id 1 -mpegts_pmt_start_pid 4096 -streamid 0:289 -streamid 1:337 -metadata service_provider="SDRangel" -metadata service_name="SDRangel TV" -flush_packets 0 "udp://127.0.0.1:5004?pkt_size=1316&bitrate=600000" + ffmpeg -f dshow -i video="c922 Pro Stream Webcam":audio="Microphone (C922 Pro Stream Webcam)" -pix_fmt yuv420p -r 25 -s 720x576 -aspect 4:3 -c:v hevc -c:a libopus -b:v 500k -b:a 64k -maxrate 600k -bufsize 600k -f mpegts -muxrate 691180 -g 50 -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 -mpegts_service_id 1 -mpegts_pmt_start_pid 4096 -streamid 0:289 -streamid 1:337 -metadata service_provider="SDRangel" -metadata service_name="SDRangel TV" -flush_packets 0 "udp://127.0.0.1:5004?pkt_size=1316&bitrate=1350000" + +When streaming via UDP, set the URL's `bitrate` to the same value as `-muxrate`, so ffmpeg sends the packets at a steady rate. +Here, both are set a little (about 2%) below the DVB data rate, so that differences between the PC's and the SDR's clocks don't build up a backlog of packets in the modulator: it transmits null packets whenever it has nothing else to send. You can list camera devices with: