10#ifndef RTPAUDIOSTREAM_H
11#define RTPAUDIOSTREAM_H
15#ifdef QT_MULTIMEDIA_LIB
30#include <QAudioOutput>
33#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
41class RtpAudioStream :
public QObject
45 enum TimingMode { JitterBuffer, RtpTimestamp, Uninterrupted };
47 explicit RtpAudioStream(QObject *parent,
rtpstream_id_t *
id,
bool stereo_required);
53 void reset(
double global_start_time);
56#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
57 void decode(QAudioDevice out_device);
59 void decode(QAudioDeviceInfo out_device);
62 double startRelTime()
const {
return start_rel_time_; }
63 double stopRelTime()
const {
return stop_rel_time_; }
64 unsigned sampleRate()
const {
return first_sample_rate_; }
65 unsigned playRate()
const {
return audio_out_rate_; }
66 void setRequestedPlayRate(
unsigned new_rate) { audio_requested_out_rate_ = new_rate; }
67 const QStringList payloadNames()
const;
73 const QVector<double> visualTimestamps(
bool relative =
true);
80 const QVector<double> visualSamples(
int y_offset = 0);
86 const QVector<double> outOfSequenceTimestamps(
bool relative =
true);
87 int outOfSequence() {
return static_cast<int>(out_of_seq_timestamps_.size()); }
93 const QVector<double> outOfSequenceSamples(
int y_offset = 0);
99 const QVector<double> jitterDroppedTimestamps(
bool relative =
true);
100 int jitterDropped() {
return static_cast<int>(jitter_drop_timestamps_.size()); }
106 const QVector<double> jitterDroppedSamples(
int y_offset = 0);
112 const QVector<double> wrongTimestampTimestamps(
bool relative =
true);
113 int wrongTimestamps() {
return static_cast<int>(wrong_timestamp_timestamps_.size()); }
119 const QVector<double> wrongTimestampSamples(
int y_offset = 0);
125 const QVector<double> insertedSilenceTimestamps(
bool relative =
true);
126 int insertedSilences() {
return static_cast<int>(silence_timestamps_.size()); }
132 const QVector<double> insertedSilenceSamples(
int y_offset = 0);
134 quint32 nearestPacket(
double timestamp,
bool is_relative =
true);
136 QRgb color() {
return color_; }
137 void setColor(QRgb color) { color_ = color; }
139 QAudio::State outputState()
const;
141 void setJitterBufferSize(
int jitter_buffer_size) { jitter_buffer_size_ = jitter_buffer_size; }
142 void setTimingMode(TimingMode timing_mode) { timing_mode_ = timing_mode; }
143 void setStartPlayTime(
double start_play_time) { start_play_time_ = start_play_time; }
144#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
145 bool prepareForPlay(QAudioDevice out_device);
147 bool prepareForPlay(QAudioDeviceInfo out_device);
152 void seekPlaying(qint64 samples);
153 void setStereoRequired(
bool stereo_required) { stereo_required_ = stereo_required; }
154 qint16 getMaxSampleValue() {
return max_sample_val_; }
155 void setMaxSampleValue(int16_t max_sample_val) { max_sample_val_used_ = max_sample_val; }
156 void seekSample(qint64 samples);
157 qint64 readSample(SAMPLE *sample);
158 qint64 getLeadSilenceSamples() {
return prepend_samples_; }
159 qint64 getTotalSamples() {
return (audio_file_->getTotalSamples()); }
160 qint64 getEndOfSilenceSample() {
return (audio_file_->getEndOfSilenceSample()); }
161 double getEndOfSilenceTime() {
return (
double)getEndOfSilenceSample() / (double)playRate(); }
162 qint64 convertTimeToSamples(
double time) {
return (qint64)(time * playRate()); }
163 bool savePayload(QIODevice *file);
164 unsigned getHash() {
return rtpstream_id_to_hash(&(id_)); }
166 QString getIDAsQString();
170 void processedSecs(
double secs);
171 void playbackError(
const QString error_msg);
172 void finishedPlaying(RtpAudioStream *
stream, QAudio::Error error);
181 QVector<struct _rtp_packet *>rtp_packets_;
183 QIODevice *temp_file_;
184 struct _GHashTable *decoders_hash_;
185 double global_start_rel_time_;
186 double start_abs_offset_;
187 double start_rel_time_;
188 double stop_rel_time_;
189 qint64 prepend_samples_;
191 bool stereo_required_;
192 quint32 first_sample_rate_;
193 quint32 audio_out_rate_;
194 quint32 audio_requested_out_rate_;
195 QSet<QString> payload_names_;
196 struct SpeexResamplerState_ *visual_resampler_;
197 QMap<double, quint32> packet_timestamps_;
198 QVector<qint16> visual_samples_;
199 QVector<double> out_of_seq_timestamps_;
200 QVector<double> jitter_drop_timestamps_;
201 QVector<double> wrong_timestamp_timestamps_;
202 QVector<double> silence_timestamps_;
203 qint16 max_sample_val_;
204 qint16 max_sample_val_used_;
207 int jitter_buffer_size_;
208 TimingMode timing_mode_;
209 double start_play_time_;
211 const QString formatDescription(
const QAudioFormat & format);
212 QString currentOutputDevice();
214#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
215 QAudioSink *audio_output_;
216 void decodeAudio(QAudioDevice out_device);
217 quint32 calculateAudioOutRate(QAudioDevice out_device,
unsigned int sample_rate,
unsigned int requested_out_rate);
219 QAudioOutput *audio_output_;
220 void decodeAudio(QAudioDeviceInfo out_device);
221 quint32 calculateAudioOutRate(QAudioDeviceInfo out_device,
unsigned int sample_rate,
unsigned int requested_out_rate);
224 SAMPLE *resizeBufferIfNeeded(SAMPLE *buff, int32_t *buff_bytes, qint64 requested_size);
227 void outputStateChanged(QAudio::State new_state);
228 void delayedStopStream();
Definition rtp_audio_routing.h:28
Definition rtp_audio_file.h:42
Definition packet_info.h:43
Definition packet-rtp.h:29
Definition rtp_stream_id.h:33
Definition rtp_stream.h:40