1 /* rtp_audio_file.h 2 * 3 * Wireshark - Network traffic analyzer 4 * By Gerald Combs <gerald@wireshark.org> 5 * Copyright 1998 Gerald Combs 6 * 7 * SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 10 #ifndef RTP_AUDIO_FILE_H 11 #define RTP_AUDIO_FILE_H 12 13 #include "config.h" 14 #include <ui/rtp_media.h> 15 16 #ifdef HAVE_SPEEXDSP 17 #include <speex/speex_resampler.h> 18 #else 19 #include "../../speexdsp/speex_resampler.h" 20 #endif /* HAVE_SPEEXDSP */ 21 22 #include <QIODevice> 23 #include <QDir> 24 #include <QTemporaryFile> 25 #include <QDebug> 26 #include <QBuffer> 27 28 struct _rtp_info; 29 30 typedef enum { 31 RTP_FRAME_AUDIO = 0, 32 RTP_FRAME_SILENCE 33 } rtp_frame_type; 34 35 // Structure used for storing frame num during visual waveform decoding 36 typedef struct { 37 qint64 real_pos; 38 qint64 sample_pos; 39 qint64 len; 40 guint32 frame_num; 41 rtp_frame_type type; 42 } rtp_frame_info; 43 44 45 class RtpAudioFile: public QIODevice 46 { 47 public: 48 explicit RtpAudioFile(bool use_disk_for_temp, bool use_disk_for_frames); 49 ~RtpAudioFile(); 50 51 // Functions for writing Frames 52 void setFrameWriteStage(); 53 void frameWriteSilence(guint32 frame_num, qint64 samples); 54 qint64 frameWriteSamples(guint32 frame_num, const char *data, qint64 max_size); 55 56 // Functions for reading Frames 57 void setFrameReadStage(qint64 prepend_samples); 58 bool readFrameSamples(gint32 *read_buff_bytes, SAMPLE **read_buff, spx_uint32_t *read_len, guint32 *frame_num, rtp_frame_type *type); 59 60 // Functions for reading data during play 61 void setDataReadStage(); 62 bool open(QIODevice::OpenMode mode) override; 63 qint64 size() const override; 64 qint64 pos() const override; 65 bool seek(qint64 off) override; 66 qint64 sampleFileSize(); 67 void seekSample(qint64 samples); 68 qint64 readSample(SAMPLE *sample); 69 qint64 getTotalSamples(); 70 qint64 getEndOfSilenceSample(); 71 72 protected: 73 // Functions for reading data during play 74 qint64 readData(char *data, qint64 maxSize) override; 75 qint64 writeData(const char *data, qint64 maxSize) override; 76 77 private: 78 QIODevice *sample_file_; // Stores waveform samples 79 QIODevice *sample_file_frame_; // Stores rtp_packet_info per packet 80 qint64 real_pos_; 81 qint64 real_size_; 82 qint64 sample_pos_; 83 qint64 sample_size_; 84 rtp_frame_info cur_frame_; 85 86 // Functions for writing Frames 87 qint64 frameWriteFrame(guint32 frame_num, qint64 real_pos, qint64 sample_pos, qint64 len, rtp_frame_type type); 88 void frameUpdateRealCounters(qint64 written_bytes); 89 void frameUpdateSampleCounters(qint64 written_bytes); 90 91 // Functions for reading Frames 92 93 // Functions for reading data during play 94 qint64 readFrameData(char *data , qint64 want_read); 95 }; 96 97 #endif // RTP_AUDIO_FILE_H 98