8000 Code format and follow google C++ style (#1280) · flutter-webrtc/flutter-webrtc@4e09e0a · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e09e0a

Browse files
authored
Code format and follow google C++ style (#1280)
1.Code format by format.sh 2.Remove ; after a } 3.Use reinterpret_cast<T*>(...) instead of C style cast. 4.Use static_cast<T*>() instread of C style cast.
1 parent 5dc6dab commit 4e09e0a
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ class FlutterPeerConnection {
148148
std::string direction,
149149
std::unique_ptr<MethodResultProxy> result);
150150

151-
void RtpTransceiverSetCodecPreferences(RTCPeerConnection* pc,
152-
std::string rtpTransceiverId,
153-
const EncodableList codecs,
154-
std::unique_ptr<MethodResultProxy> result);
151+
void RtpTransceiverSetCodecPreferences(
152+
RTCPeerConnection* pc,
153+
std::string rtpTransceiverId,
154+
const EncodableList codecs,
155+
std::unique_ptr<MethodResultProxy> result);
155156

156157
void GetSenders(RTCPeerConnection* pc,
157158
std::unique_ptr<MethodResultProxy> result);
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class MethodCallProxyImpl : public MethodCallProxy {
44
public:
5-
MethodCallProxyImpl(const MethodCall& method_call)
5+
explicit MethodCallProxyImpl(const MethodCall& method_call)
66
: method_call_(method_call) {}
77

88
~MethodCallProxyImpl() {}
@@ -29,7 +29,7 @@ std::unique_ptr<MethodCallProxy> MethodCallProxy::Create(
2929

3030
class MethodResultProxyImpl : public MethodResultProxy {
3131
public:
32-
MethodResultProxyImpl(std::unique_ptr<MethodResult> method_result)
32+
explicit MethodResultProxyImpl(std::unique_ptr<MethodResult> method_result)
3333
: method_result_(std::move(method_result)) {}
3434
~MethodResultProxyImpl() {}
3535

Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ EncodableMap rtpParametersToMap(
7474
map[EncodableValue("minBitrate")] =
7575
EncodableValue(encoding->min_bitrate_bps());
7676
map[EncodableValue("maxFramerate")] =
77-
EncodableValue((int)encoding->max_framerate());
77+
EncodableValue(static_cast<int>(encoding->max_framerate()));
7878
map[EncodableValue("scaleResolutionDownBy")] =
7979
EncodableValue(encoding->scale_resolution_down_by());
8080
map[EncodableValue("ssrc")] = EncodableValue((long)encoding->ssrc());
@@ -528,7 +528,6 @@ void FlutterPeerConnection::GetReceivers(
528528
result_ptr->Success(EncodableValue(map));
529529
}
530530

531-
532531
void FlutterPeerConnection::RtpSenderSetTrack(
533532
RTCPeerConnection* pc,
534533
RTCMediaTrack* track,
@@ -622,7 +621,7 @@ void FlutterPeerConnection::RtpSenderSetParameters(
622621
param = updateRtpParameters(parameters, param);
623622
bool success = sender->set_parameters(param);
624623

625-
EncodableMap map;
624+
EncodableMap map;
626625
map[EncodableValue("result")] = EncodableValue(success);
627626
result_ptr->Success(EncodableValue(map));
628627
}
@@ -723,18 +722,19 @@ void FlutterPeerConnection::RtpTransceiverSetCodecPreferences(
723722
std::shared_ptr<MethodResultProxy> result_ptr(result.release());
724723
auto transceiver = getRtpTransceiverById(pc, rtpTransceiverId);
725724
if (nullptr == transceiver.get()) {
726-
result_ptr->Error("RtpTransceiverSetCodecPreferences", " transceiver is null ");
725+
result_ptr->Error("RtpTransceiverSetCodecPreferences",
726+
" transceiver is null ");
727727
return;
728728
}
729729
std::vector<scoped_refptr<RTCRtpCodecCapability>> codecList;
730-
for(auto codec : codecs) {
730+
for (auto codec : codecs) {
731731
auto codecMap = GetValue<EncodableMap>(codec);
732732
auto codecMimeType = findString(codecMap, "mimeType");
733733
auto codecClockRate = findInt(codecMap, "clockRate");
734734
auto codecNumChannels = findInt(codecMap, "channels");
735735
auto codecSdpFmtpLine = findString(codecMap, "sdpFmtpLine");
736736
auto codecCapability = RTCRtpCodecCapability::Create();
737-
if(codecSdpFmtpLine != std::string())
737+
if (codecSdpFmtpLine != std::string())
738738
codecCapability->set_sdp_fmtp_line(codecSdpFmtpLine);
739739
codecCapability->set_clock_rate(codecClockRate);
740740
if (codecNumChannels != -1)
@@ -744,7 +744,7 @@ void FlutterPeerConnection::RtpTransceiverSetCodecPreferences(
744744
}
745745
transceiver->SetCodecPreferences(codecList);
746746
result_ptr->Success();
747-
}
747+
}
748748

749749
void FlutterPeerConnection::GetSenders(
750750
RTCPeerConnection* pc,
@@ -777,7 +777,7 @@ EncodableMap statsToMap(const scoped_refptr<MediaRTCStats>& stats) {
777777
report_map[EncodableValue("type")] =
778778
EncodableValue(stats->type().std_string());
779779
report_map[EncodableValue("timestamp")] =
780-
EncodableValue(double(stats->timestamp_us()));
780+
EncodableValue(static_cast<double>(stats->timestamp_us()));
781781
EncodableMap values;
782782
auto members = stats->Members();
783783
for (int i = 0; i < members.size(); i++) {
@@ -934,13 +934,15 @@ void FlutterPeerConnection::AddTrack(
934934
streamids.push_back(item.c_str());
935935
}
936936
if (0 == kind.compare("audio")) {
937-
auto sender = pc->AddTrack((RTCAudioTrack*)track.get(), streamids);
937+
auto sender =
938+
pc->AddTrack(reinterpret_cast<RTCAudioTrack*>(track.get()), streamids);
938939
if (sender.get() != nullptr) {
939940
result_ptr->Success(EncodableValue(rtpSenderToMap(sender)));
940941
return;
941942
}
942943
} else if (0 == kind.compare("video")) {
943-
auto sender = pc->AddTrack((RTCVideoTrack*)track.get(), streamids);
944+
auto sender =
945+
pc->AddTrack(reinterpret_cast<RTCAudioTrack*>(track.get()), streamids);
944946
if (sender.get() != nullptr) {
945947
result_ptr->Success(EncodableValue(rtpSenderToMap(sender)));
946948
return;
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,4 @@ void FlutterScreenCapture::GetDisplayMedia(
279279
result->Success(EncodableValue(params));
280280
}
281281

282-
} // namespace flutter_webrtc_plugin
282+
} // namespace flutter_webrtc_plugin
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const FlutterDesktopPixelBuffer* FlutterVideoRenderer::CopyPixelBuffer(
3434
}
3535

3636
frame_->ConvertToARGB(RTCVideoFrame::Type::kABGR, rgb_buffer_.get(), 0,
37-
(int)pixel_buffer_->width,
38-
(int)pixel_buffer_->height);
37+
static_cast<int>(pixel_buffer_->width),
38+
static_cast<int>(pixel_buffer_->height));
3939

4040
pixel_buffer_->buffer = rgb_buffer_.get();
4141
mutex_.unlock();
@@ -159,4 +159,4 @@ void FlutterVideoRendererManager::VideoRendererDispose(
159159
"VideoRendererDispose() texture not found!");
160160
}
161161

162-
} // namespace flutter_webrtc_plugin
162+
} // namespace flutter_webrtc_plugin
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void FlutterWebRTC::HandleMethodCall(
531531
if (renderer->CheckMediaStream(streamId) && 0 == kind.compare("video")) {
532532
renderer->SetVideoTrack(static_cast<RTCVideoTrack*>(track.get()));
533533
}
534-
};
534+
}
535535
} else if (method_call.method_name().compare("mediaStreamRemoveTrack") == 0) {
536536
if (!method_call.arguments()) {
537537
result->Error("Bad Arguments", "Null constraints arguments received");
@@ -564,7 +564,7 @@ void FlutterWebRTC::HandleMethodCall(
564564
if (renderer->CheckVideoTrack(streamId)) {
565565
renderer->SetVideoTrack(nullptr);
566566
}
567-
};
567+
}
568568
} else if (method_call.method_name().compare("addTrack") == 0) {
569569
if (!method_call.arguments()) {
570570
result->Error("Bad Arguments", "Null constraints arguments received");
@@ -587,7 +587,7 @@ void FlutterWebRTC::HandleMethodCall(
587587
if (track == nullptr) {
588588
result->Error("AddTrack", "AddTrack() track is null");
589589
return;
590-
};
590+
}
591591
std::list<std::string> listId;
592592
for (EncodableValue value : streamIds) {
593593
listId.push_back(GetValue<std::string>(value));
@@ -916,7 +916,8 @@ void FlutterWebRTC::HandleMethodCall(
916916
result->Error("captureFrame", "captureFrame() track not is video track");
917917
return;
918918
}
919-
CaptureFrame((RTCVideoTrack*)track, path, std::move(result));
919+
CaptureFrame(reinterpret_cast<RTCVideoTrack*>(track), path,
920+
std::move(result));
920921

921922
} else if (method_call.method_name().compare("createLocalMediaStream") == 0) {
922923
CreateLocalMediaStream(std::move(result));
@@ -976,7 +977,8 @@ void FlutterWebRTC::HandleMethodCall(
976977
dtmfSender->InsertDtmf(tone, duration, gap);
977978

978979
result->Success();
979-
} else if (method_call.method_name().compare("getRtpSenderCapabilities") == 0) {
980+
} else if (method_call.method_name().compare("getRtpSenderCapabilities") ==
981+
0) {
980982
if (!method_call.arguments()) {
981983
result->Error("Bad Arguments", "Null arguments received");
982984
return;
@@ -998,20 +1000,24 @@ void FlutterWebRTC::HandleMethodCall(
9981000
auto capabilities = factory_->GetRtpSenderCapabilities(mediaType);
9991001
EncodableMap map;
10001002
EncodableList codecsList;
1001-
for(auto codec : capabilities->codecs().std_vector()) {
1003+
for (auto codec : capabilities->codecs().std_vector()) {
10021004
EncodableMap codecMap;
1003-
codecMap[EncodableValue("mimeType")] = EncodableValue(codec->mime_type().std_string());
1004-
codecMap[EncodableValue("clockRate")] = EncodableValue(codec->clock_rate());
1005+
codecMap[EncodableValue("mimeType")] =
1006+
EncodableValue(codec->mime_type().std_string());
1007+
codecMap[EncodableValue("clockRate")] =
1008+
EncodableValue(codec->clock_rate());
10051009
codecMap[EncodableValue("channels")] = EncodableValue(codec->channels());
1006-
codecMap[EncodableValue("sdpFmtpLine")] = EncodableValue(codec->sdp_fmtp_line().std_string());
1010+
codecMap[EncodableValue("sdpFmtpLine")] =
1011+
EncodableValue(codec->sdp_fmtp_line().std_string());
10071012
codecsList.push_back(EncodableValue(codecMap));
10081013
}
10091014
map[EncodableValue("codecs")] = EncodableValue(codecsList);
10101015
map[EncodableValue("headerExtensions")] = EncodableValue(EncodableList());
10111016
map[EncodableValue("fecMechanisms")] = EncodableValue(EncodableList());
1012-
1017+
10131018
result->Success(EncodableValue(map));
1014-
} else if (method_call.method_name().compare("getRtpReceiverCapabilities") == 0) {
1019+
} else if (method_call.method_name().compare("getRtpReceiverCapabilities") ==
1020+
0) {
10151021
const EncodableMap params =
10161022
GetValue<EncodableMap>(*method_call.arguments());
10171023

@@ -1050,7 +1056,7 @@ void FlutterWebRTC::HandleMethodCall(
10501056
result->Error("Bad Arguments", "Null arguments received");
10511057
return;
10521058
}
1053-
const EncodableMap params =
1059+
const EncodableMap params =
10541060
GetValue<EncodableMap>(*method_call.arguments());
10551061
const std::string peerConnectionId = findString(params, "peerConnectionId");
10561062
RTCPeerConnection* pc = PeerConnectionForId(peerConnectionId);
@@ -1063,8 +1069,9 @@ void FlutterWebRTC::HandleMethodCall(
10631069
const std::string rtpTransceiverId = findString(params, "transceiverId");
10641070
if (0 < rtpTransceiverId.size()) {
10651071
if (pc == nullptr) {
1066-
result->Error("setCodecPreferences",
1067-
"setCodecPreferences() rtpTransceiverId is null or empty");
1072+
result->Error(
1073+
"setCodecPreferences",
1074+
"setCodecPreferences() rtpTransceiverId is null or empty");
10681075
return;
10691076
}
10701077
}
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ bool FlutterWebRTCBase::CreateIceServers(const EncodableList& iceServersArray,
201201
EncodableMap iceServerMap = GetValue<EncodableMap>(iceServersArray[i]);
202202

203203
if (iceServerMap.find(EncodableValue("username")) != iceServerMap.end()) {
204-
;
205204
ice_server.username = GetValue<std::string>(
206205
iceServerMap.find(EncodableValue("username"))->second);
207206
}
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ + (void)setSpeakerphoneOn:(BOOL)enable {
9292
}
9393

9494
+ (void)deactiveRtcAudioSession {
95-
NSError* error = nil;
96-
RTCAudioSession* session = [RTCAudioSession sharedInstance];
97-
[session lockForConfiguration];
98-
if([session isActive]) {
99-
BOOL success = [session setActive:NO error:&error];
100-
if (!success)
101-
NSLog(@"RTC Audio session deactive failed: %@", error);
102-
else
103-
NSLog(@"RTC AudioSession deactive is successful ");
104-
}
105-
[session unlockForConfiguration];
95+
NSError* error = nil;
96+
RTCAudioSession* session = [RTCAudioSession sharedInstance];
97+
[session lockForConfiguration];
98+
if ([session isActive]) {
99+
BOOL success = [session setActive:NO error:&error];
100+
if (!success)
101+
NSLog(@"RTC Audio session deactive failed: %@", error);
102+
else
103+
NSLog(@"RTC AudioSession deactive is successful ");
104+
}
105+
[session unlockForConfiguration];
106106
}
107107

108108
@end
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@
4545
- (void)peerConnectionSetConfiguration:(nonnull RTCConfiguration*)configuration
4646
peerConnection:(nonnull RTCPeerConnection*)peerConnection;
4747

48-
- (void)peerConnectionGetRtpReceiverCapabilities:(nonnull NSDictionary*)argsMap result:(nonnull FlutterResult)result;
48+
- (void)peerConnectionGetRtpReceiverCapabilities:(nonnull NSDictionary*)argsMap
49+
result:(nonnull FlutterResult)result;
4950

50-
- (void)peerConnectionGetRtpSenderCapabilities:(nonnull NSDictionary*)argsMap result:(nonnull FlutterResult)result;
51+
- (void)peerConnectionGetRtpSenderCapabilities:(nonnull NSDictionary*)argsMap
52+
result:(nonnull FlutterResult)result;
5153

52-
- (void)transceiverSetCodecPreferences:(nonnull NSDictionary*)argsMap result:(nonnull FlutterResult)result;
54+
- (void)transceiverSetCodecPreferences:(nonnull NSDictionary*)argsMap
55+
result:(nonnull FlutterResult)result;
5356
@end