Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
rtp_audio_stream.h
Go to the documentation of this file.
1
10#ifndef RTPAUDIOSTREAM_H
11#define RTPAUDIOSTREAM_H
12
13#include "config.h"
14
15#ifdef QT_MULTIMEDIA_LIB
16
17#include <epan/address.h>
18#include <ui/rtp_stream.h>
21#include <ui/rtp_media.h>
22
23#include <QAudio>
24#include <QColor>
25#include <QMap>
26#include <QObject>
27#include <QSet>
28#include <QVector>
29#include <QIODevice>
30#include <QAudioOutput>
31
32class QAudioFormat;
33#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
34class QAudioSink;
35#else
36class QAudioOutput;
37#endif
38class QIODevice;
39
40
41class RtpAudioStream : public QObject
42{
43 Q_OBJECT
44public:
45 enum TimingMode { JitterBuffer, RtpTimestamp, Uninterrupted };
46
47 explicit RtpAudioStream(QObject *parent, rtpstream_id_t *id, bool stereo_required);
48 ~RtpAudioStream();
49 bool isMatch(const rtpstream_id_t *id) const;
50 bool isMatch(const struct _packet_info *pinfo, const struct _rtp_info *rtp_info) const;
51 void addRtpPacket(const struct _packet_info *pinfo, const struct _rtp_info *rtp_info);
52 void clearPackets();
53 void reset(double global_start_time);
54 AudioRouting getAudioRouting();
55 void setAudioRouting(AudioRouting audio_routing);
56#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
57 void decode(QAudioDevice out_device);
58#else
59 void decode(QAudioDeviceInfo out_device);
60#endif
61
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;
68
73 const QVector<double> visualTimestamps(bool relative = true);
80 const QVector<double> visualSamples(int y_offset = 0);
81
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);
94
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);
107
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);
120
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);
133
134 quint32 nearestPacket(double timestamp, bool is_relative = true);
135
136 QRgb color() { return color_; }
137 void setColor(QRgb color) { color_ = color; }
138
139 QAudio::State outputState() const;
140
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);
146#else
147 bool prepareForPlay(QAudioDeviceInfo out_device);
148#endif
149 void startPlaying();
150 void pausePlaying();
151 void stopPlaying();
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_)); }
165 rtpstream_id_t *getID() { return &(id_); }
166 QString getIDAsQString();
167 rtpstream_info_t *getStreamInfo() { return &rtpstream_; }
168
169signals:
170 void processedSecs(double secs);
171 void playbackError(const QString error_msg);
172 void finishedPlaying(RtpAudioStream *stream, QAudio::Error error);
173
174private:
175 // Used to identify unique streams.
176 // The GTK+ UI also uses the call number + current channel.
177 rtpstream_id_t id_;
178 rtpstream_info_t rtpstream_;
179 bool first_packet_;
180
181 QVector<struct _rtp_packet *>rtp_packets_;
182 RtpAudioFile *audio_file_; // Stores waveform samples in sparse file
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_; // Count of silence samples at begin of the stream to align with other streams
190 AudioRouting audio_routing_;
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_;
205 QRgb color_;
206
207 int jitter_buffer_size_;
208 TimingMode timing_mode_;
209 double start_play_time_;
210
211 const QString formatDescription(const QAudioFormat & format);
212 QString currentOutputDevice();
213
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);
218#else
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);
222#endif
223 void decodeVisual();
224 SAMPLE *resizeBufferIfNeeded(SAMPLE *buff, int32_t *buff_bytes, qint64 requested_size);
225
226private slots:
227 void outputStateChanged(QAudio::State new_state);
228 void delayedStopStream();
229};
230
231#endif // QT_MULTIMEDIA_LIB
232
233#endif // RTPAUDIOSTREAM_H
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
Definition stream.c:41