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