18
18
#include " StringLiterals.h"
19
19
20
20
#include < chrono>
21
+ #include < ranges>
21
22
22
23
// gstreamer
23
24
#include < gst/gst.h>
@@ -153,7 +154,7 @@ GstCaps *QXmppCallPrivate::ptMap(uint sessionId, uint pt)
153
154
return nullptr ;
154
155
}
155
156
156
- bool QXmppCallPrivate::isFormatSupported (const QString &codecName) const
157
+ bool QXmppCallPrivate::isFormatSupported (const QString &codecName)
157
158
{
158
159
GstElementFactory *factory;
159
160
factory = gst_element_factory_find (codecName.toLatin1 ().data ());
@@ -164,67 +165,60 @@ bool QXmppCallPrivate::isFormatSupported(const QString &codecName) const
164
165
return true ;
165
166
}
166
167
168
+ bool QXmppCallPrivate::isCodecSupported (const GstCodec &codec)
169
+ {
170
+ return isFormatSupported (codec.gstPay ) &&
171
+ isFormatSupported (codec.gstDepay ) &&
172
+ isFormatSupported (codec.gstEnc ) &&
173
+ isFormatSupported (codec.gstDec );
174
+ }
175
+
167
176
void QXmppCallPrivate::filterGStreamerFormats (QList<GstCodec> &formats)
168
177
{
169
- auto it = formats.begin ();
170
- while (it != formats.end ()) {
171
- bool supported = isFormatSupported (it->gstPay ) &&
172
- isFormatSupported (it->gstDepay ) &&
173
- isFormatSupported (it->gstEnc ) &&
174
- isFormatSupported (it->gstDec );
175
- if (!supported) {
176
- it = formats.erase (it);
177
- } else {
178
- ++it;
179
- }
180
- }
178
+ auto removedRange = std::ranges::remove_if (formats, std::not_fn (isCodecSupported));
179
+ formats.erase (removedRange.begin (), removedRange.end ());
181
180
}
182
181
183
182
QXmppCallStream *QXmppCallPrivate::findStreamByMedia (QStringView media)
184
183
{
185
- for (auto stream : std::as_const (streams)) {
186
- if (stream->media () == media) {
187
- return stream;
188
- }
184
+ if (auto stream = std::ranges::find (streams, media, &QXmppCallStream::media);
185
+ stream != streams.end ()) {
186
+ return *stream;
189
187
}
190
188
return nullptr ;
191
189
}
192
190
193
191
QXmppCallStream *QXmppCallPrivate::findStreamByName (QStringView name)
194
192
{
195
- for (auto stream : std::as_const (streams)) {
196
- if (stream->name () == name) {
197
- return stream;
198
- }
193
+ if (auto stream = std::ranges::find (streams, name, &QXmppCallStream::name);
194
+ stream != streams.end ()) {
195
+ return *stream;
199
196
}
200
197
return nullptr ;
201
198
}
202
199
203
- QXmppCallStream *QXmppCallPrivate::findStreamById (const int id)
200
+ QXmppCallStream *QXmppCallPrivate::findStreamById (int id)
204
201
{
205
- for (auto stream : std::as_const (streams)) {
206
- if (stream->id () == id) {
207
- return stream;
208
- }
202
+ if (auto stream = std::ranges::find (streams, id, &QXmppCallStream::id);
203
+ stream != streams.end ()) {
204
+ return *stream;
209
205
}
210
206
return nullptr ;
211
207
}
212
208
213
209
void QXmppCallPrivate::handleAck (const QXmppIq &ack)
214
210
{
215
- const QString id = ack.id ();
216
- for (int i = 0 ; i < requests.size (); ++i) {
217
- if (id == requests[i].id ()) {
218
- // process acknowledgement
219
- const QXmppJingleIq request = requests.takeAt (i);
220
- q->debug (u" Received ACK for packet %1" _s.arg (id));
211
+ auto request = std::ranges::find (requests, ack.id (), &QXmppJingleIq::id);
212
+ if (request != requests.end ()) {
213
+ // process acknowledgement
214
+ q->debug (u" Received ACK for packet %1" _s.arg (ack.id ()));
221
215
222
- // handle termination
223
- if (request.action () == QXmppJingleIq::SessionTerminate) {
224
- q->terminated ();
225
- }
226
- return ;
216
+ // handle termination
217
+ if (request->action () == QXmppJingleIq::SessionTerminate) {
218
+ q->terminated ();
227
219
}
220
+
221
+ requests.erase (request);
228
222
}
229
223
}
230
224
0 commit comments