8000 fix: fix bug for windows. · strogo/flutter-webrtc@fc97839 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc97839

Browse files
committed
fix: fix bug for windows.
1 parent 808de9d commit fc97839

File tree

7 files changed

+40
-45
lines changed

7 files changed

+40
-45
lines changed

common/cpp/include/flutter_webrtc_base.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ inline int64_t findLongInt(const EncodableMap& map, const std::string& key) {
9494
return -1;
9595
}
9696

97+
inline int toInt(EncodableValue inputVal, int defaultVal) {
98+
int intValue = defaultVal;
99+
if (TypeIs<int>(inputVal)) {
100+
intValue = GetValue<int>(inputVal);
101+
} else if (TypeIs<int32_t>(inputVal)) {
102+
intValue = GetValue<int32_t>(inputVal);
103+
} else if (TypeIs<std::string>(inputVal)) {
104+
intValue = atoi(GetValue<std::string>(inputVal).c_str());
105+
}
106+
return intValue;
107+
}
108+
97109
class FlutterWebRTCBase {
98110
public:
99111
friend class FlutterMediaStream;

common/cpp/src/flutter_media_stream.cc

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "flutter_media_stream.h"
22

3-
#define DEFAULT_WIDTH 1280
4-
#define DEFAULT_HEIGHT 720
3+
#define DEFAULT_WIDTH 640
4+
#define DEFAULT_HEIGHT 480
55
#define DEFAULT_FPS 30
66

77
namespace flutter_webrtc_plugin {
@@ -151,35 +151,32 @@ void FlutterMediaStream::GetUserVideo(const EncodableMap& constraints,
151151
//bool isFacing = facing_mode == "" || facing_mode != "environment";
152152
std::string sourceId = getSourceIdConstraint(video_constraints);
153153

154-
int width = findInt(video_mandatory, "minWidth");
154+
EncodableValue widthValue = findEncodableValue(video_mandatory, "minWidth");
155155

156-
if (width == -1)
157-
width = < 8000 span class="pl-c1 x x-first x-last">findInt(video_mandatory, "width");
156+
if (widthValue == EncodableValue())
157+
widthValue = findEncodableValue(video_mandatory, "width");
158158

159-
if (width == -1)
160-
width = DEFAULT_WIDTH;
159+
EncodableValue heightValue = findEncodableValue(video_mandatory, "minHeight");
161160

162-
int height = findInt(video_mandatory, "minHeight");
161+
if (heightValue == EncodableValue())
162+
heightValue = findEncodableValue(video_mandatory, "height");
163163

164-
if (height == -1)
165-
height = findInt(video_mandatory, "height");
166164

167-
if (height == -1)
168-
height = DEFAULT_HEIGHT;
165+
EncodableValue fpsValue = findEncodableValue(video_mandatory, "minFrameRate");
169166

170-
int fps = findInt(video_mandatory, "minFrameRate");
167+
if (fpsValue == EncodableValue())
168+
fpsValue = findEncodableValue(video_mandatory, "frameRate");
171169

172-
if (fps == -1)
173-
fps = findInt(video_mandatory, "frameRate");
174-
175-
if (height == -1)
176-
height = DEFAULT_FPS;
177170

178171
scoped_refptr<RTCVideoCapturer> video_capturer;
179172
char strNameUTF8[256];
180173
char strGuidUTF8[256];
181174
int nb_video_devices = base_->video_device_->NumberOfDevices();
182175

176+
int32_t width = toInt(widthValue, DEFAULT_WIDTH);
177+
int32_t height = toInt(heightValue, DEFAULT_HEIGHT);
178+
int32_t fps = toInt(fpsValue, DEFAULT_FPS);
179+
183180
for (int i = 0; i < nb_video_devices; i++) {
184181
base_->video_device_->GetDeviceName(i, strNameUTF8, 256, strGuidUTF8, 256);
185182
if (sourceId != "" && sourceId == strGuidUTF8) {
@@ -312,6 +309,12 @@ void FlutterMediaStream::MediaStreamDispose(
312309
const std::string& stream_id,
313310
std::unique_ptr<MethodResult<EncodableValue>> result) {
314311
scoped_refptr<RTCMediaStream> stream = base_->MediaStreamForId(stream_id);
312+
313+
if (!stream) {
314+
result->Error("MediaStreamDisposeFailed", "stream [" + stream_id + "] not found!");
315+
return;
316+
}
317+
315318
vector<scoped_refptr<RTCAudioTrack>> audio_tracks = stream->audio_tracks();
316319

317320
for (auto track : audio_tracks.std_vector()) {
@@ -324,6 +327,7 @@ void FlutterMediaStream::MediaStreamDispose(
324327
stream->RemoveTrack(track);
325328
base_->local_tracks_.erase(track->id().std_string());
326329
}
330+
327331
base_->RemoveStreamForId(stream_id);
328332
result->Success();
329333
}

example/lib/src/get_user_media_sample.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
5151
'video': {
5252
'mandatory': {
5353
'minWidth':
54-
'1280', // Provide your own width, height and frame rate here
55-
'minHeight': '720',
54+
'640', // Provide your own width, height and frame rate here
55+
'minHeight': '480',
5656
'minFrameRate': '30',
5757
},
5858
'facingMode': 'user',

example/lib/src/loopback_sample.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ class _MyAppState extends State<LoopBackSample> {
133133
'video': {
134134
'mandatory': {
135135
'minWidth':
136-
'1280', // Provide your own width, height and frame rate here
137-
'minHeight': '720',
136+
'640', // Provide your own width, height and frame rate here
137+
'minHeight': '480',
138138
'minFrameRate': '30',
139139
},
140140
'facingMode': 'user',

lib/src/native/rtc_video_renderer_impl.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class RTCVideoRendererNative extends VideoRenderer {
7777
onResize?.call();
7878
break;
7979
case 'didFirstFrameRendered':
80+
value = value.copyWith(renderVideo: renderVideo);
8081
break;
8182
}
8283
}

third_party/libwebrtc/include/base/portable.h

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,6 @@ namespace portable {
3434
#ifndef _TRUNCATE
3535
#define _TRUNCATE ((size_t)-1)
3636
#endif // _TRUNCATE
37-
static int strncpy_safe(char* dest,
38-
size_t numberOfElements,
39-
const char* src,
40-
size_t count) {
41-
if (!count)
42-
return 0;
43-
if (!dest || !src || !numberOfElements)
44-
return -1;
45-
size_t end = count != _TRUNCATE && count < numberOfElements
46-
? count
47-
: numberOfElements - 1;
48-
size_t i = 0;
49-
for (; i < end && src[i]; ++i) {
50-
dest[i] = src[i];
51-
}
52-
if (!src[i] || end == count || count == _TRUNCATE) {
53-
dest[i] = '\0';
54-
return 0;
55-
}
56-
dest[0] = '\0';
57-
return -1;
58-
}
5937
#endif
6038

6139
#define PORTABLE_STRING_BUF_SIZE 48
@@ -104,7 +82,7 @@ class string {
10482
}
10583

10684
inline std::string std_string() const {
107-
return std::string(m_dynamic == 0 ? m_buf : m_dynamic);
85+
return std::string(m_dynamic == 0 ? m_buf : m_dynamic, m_length);
10886
}
10987
};
11088

-296 KB
Binary file not shown.

0 commit comments

Comments
 (0)
0