26cabdad4b09f63fdf8cb1401df429d908fc3443
[metze/wireshark/wip.git] / ui / qt / rtp_analysis_dialog.h
1 /* rtp_analysis_dialog.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+*/
8
9 #ifndef RTP_ANALYSIS_DIALOG_H
10 #define RTP_ANALYSIS_DIALOG_H
11
12 #include <config.h>
13
14 #include <glib.h>
15
16 #include "epan/address.h"
17
18 #include "ui/rtp_stream.h"
19 #include "ui/tap-rtp-analysis.h"
20
21 #include <QAbstractButton>
22 #include <QMenu>
23 #include <QFile>
24
25 #include "wireshark_dialog.h"
26
27 namespace Ui {
28 class RtpAnalysisDialog;
29 }
30
31 class QCPGraph;
32 class QTemporaryFile;
33
34 typedef enum {
35     TAP_RTP_NO_ERROR,
36     TAP_RTP_WRONG_LENGTH,
37     TAP_RTP_PADDING_ERROR,
38     TAP_RTP_FILE_IO_ERROR
39 } rtp_error_type_t;
40
41 class RtpAnalysisDialog : public WiresharkDialog
42 {
43     Q_OBJECT
44
45 public:
46     explicit RtpAnalysisDialog(QWidget &parent, CaptureFile &cf, struct _rtp_stream_info *stream_fwd = 0, struct _rtp_stream_info *stream_rev = 0);
47     ~RtpAnalysisDialog();
48
49 signals:
50     void goToPacket(int packet_num);
51
52 protected:
53     virtual void captureFileClosing();
54
55 protected slots:
56     virtual void updateWidgets();
57
58 private slots:
59     void on_actionGoToPacket_triggered();
60     void on_actionNextProblem_triggered();
61     void on_fJitterCheckBox_toggled(bool checked);
62     void on_fDiffCheckBox_toggled(bool checked);
63     void on_fDeltaCheckBox_toggled(bool checked);
64     void on_rJitterCheckBox_toggled(bool checked);
65     void on_rDiffCheckBox_toggled(bool checked);
66     void on_rDeltaCheckBox_toggled(bool checked);
67     void on_actionSaveAudioUnsync_triggered();
68     void on_actionSaveForwardAudioUnsync_triggered();
69     void on_actionSaveReverseAudioUnsync_triggered();
70     void on_actionSaveAudioSyncStream_triggered();
71     void on_actionSaveForwardAudioSyncStream_triggered();
72     void on_actionSaveReverseAudioSyncStream_triggered();
73     void on_actionSaveAudioSyncFile_triggered();
74     void on_actionSaveForwardAudioSyncFile_triggered();
75     void on_actionSaveReverseAudioSyncFile_triggered();
76     void on_actionSaveCsv_triggered();
77     void on_actionSaveForwardCsv_triggered();
78     void on_actionSaveReverseCsv_triggered();
79     void on_actionSaveGraph_triggered();
80     void on_buttonBox_clicked(QAbstractButton *button);
81     void on_buttonBox_helpRequested();
82     void showStreamMenu(QPoint pos);
83     void graphClicked(QMouseEvent *event);
84
85 private:
86     Ui::RtpAnalysisDialog *ui;
87     enum StreamDirection { dir_both_, dir_forward_, dir_reverse_ };
88     enum SyncType { sync_unsync_, sync_sync_stream_, sync_sync_file_ };
89
90     // XXX These are copied to and from rtp_stream_info_t structs. Should
91     // we just have a pair of those instead?
92     address src_fwd_;
93     guint32 port_src_fwd_;
94     address dst_fwd_;
95     guint32 port_dst_fwd_;
96     guint32 ssrc_fwd_;
97     guint32 packet_count_fwd_;
98     guint32 setup_frame_number_fwd_;
99     nstime_t start_rel_time_fwd_;
100
101     address src_rev_;
102     guint32 port_src_rev_;
103     address dst_rev_;
104     guint32 port_dst_rev_;
105     guint32 ssrc_rev_;
106     guint32 packet_count_rev_;
107     guint32 setup_frame_number_rev_;
108     nstime_t start_rel_time_rev_;
109
110     int num_streams_;
111
112     tap_rtp_stat_t fwd_statinfo_;
113     tap_rtp_stat_t rev_statinfo_;
114
115     QPushButton *player_button_;
116
117     QTemporaryFile *fwd_tempfile_;
118     QTemporaryFile *rev_tempfile_;
119
120     // Graph data for QCustomPlot
121     QList<QCPGraph *>graphs_;
122     QVector<double> fwd_time_vals_;
123     QVector<double> fwd_jitter_vals_;
124     QVector<double> fwd_diff_vals_;
125     QVector<double> fwd_delta_vals_;
126
127     QVector<double> rev_time_vals_;
128     QVector<double> rev_jitter_vals_;
129     QVector<double> rev_diff_vals_;
130     QVector<double> rev_delta_vals_;
131
132     rtpstream_tapinfo_t tapinfo_;
133     QString err_str_;
134     rtp_error_type_t save_payload_error_;
135
136     QMenu stream_ctx_menu_;
137     QMenu graph_ctx_menu_;
138
139     void findStreams();
140
141     // Tap callbacks
142     static void tapReset(void *tapinfo_ptr);
143     static gboolean tapPacket(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *, const void *rtpinfo_ptr);
144     static void tapDraw(void *tapinfo_ptr);
145
146     void resetStatistics();
147     void addPacket(bool forward, packet_info *pinfo, const struct _rtp_info *rtpinfo);
148     void savePayload(QTemporaryFile *tmpfile, tap_rtp_stat_t *statinfo, packet_info *pinfo, const struct _rtp_info *rtpinfo);
149     void updateStatistics();
150     void updateGraph();
151
152     void showPlayer();
153
154     size_t convert_payload_to_samples(unsigned int payload_type, QTemporaryFile *tempfile, gchar *pd_out, size_t expected_nchars);
155     gboolean saveAudioAUSilence(size_t total_len, QFile *save_file, gboolean *stop_flag);
156     gboolean saveAudioAUUnidir(tap_rtp_stat_t &statinfo, QTemporaryFile *tempfile, QFile *save_file, size_t header_end, gboolean *stop_flag, gboolean interleave, size_t prefix_silence);
157     gboolean saveAudioAUBidir(tap_rtp_stat_t &fwd_statinfo, tap_rtp_stat_t &rev_statinfo, QTemporaryFile *fwd_tempfile, QTemporaryFile *rev_tempfile, QFile *save_file, size_t header_end, gboolean *stop_flag, size_t prefix_silence_fwd, size_t prefix_silence_rev);
158     gboolean saveAudioAU(StreamDirection direction, QFile *save_file, gboolean *stop_flag, RtpAnalysisDialog::SyncType sync);
159     gboolean saveAudioRAW(StreamDirection direction, QFile *save_file, gboolean *stop_flag);
160     void saveAudio(StreamDirection direction, RtpAnalysisDialog::SyncType sync);
161     void saveCsv(StreamDirection direction);
162
163     guint32 processNode(proto_node *ptree_node, header_field_info *hfinformation, const gchar* proto_field, bool *ok);
164     guint32 getIntFromProtoTree(proto_tree *protocol_tree, const gchar *proto_name, const gchar *proto_field, bool *ok);
165
166     bool eventFilter(QObject*, QEvent* event);
167 };
168
169 #endif // RTP_ANALYSIS_DIALOG_H
170
171 /*
172  * Editor modelines
173  *
174  * Local Variables:
175  * c-basic-offset: 4
176  * tab-width: 8
177  * indent-tabs-mode: nil
178  * End:
179  *
180  * ex: set shiftwidth=4 tabstop=8 expandtab:
181  * :indentSize=4:tabSize=8:noTabs=true:
182  */