8000 Use AspectRatio for RTCVideoView. · lineCode/flutter-webrtc@4dbd164 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4dbd164

Browse files
committed
Use AspectRatio for RTCVideoView.
1 parent 69a1bda commit 4dbd164

File tree

4 files changed

+23
-36
lines changed

4 files changed

+23
-36
lines changed

android/src/main/java/com/cloudwebrtc/webrtc/SurfaceTextureRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ private void renderFrameOnRenderThread() {
449449
}
450450
if (!checkConsistentLayout()) {
451451
// Output intermediate black frames while the layout is updated.
452-
makeBlack();
453-
VideoRenderer.renderFrameDone(frame);
452+
//makeBlack();
453+
//VideoRenderer.renderFrameDone(frame);
454454
return;
455455
}
456456
// After a surface size change, the EGLSurface might still have a buffer of the old size in the

example/lib/src/basic_sample/get_user_media_sample.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
8888
return new Center(
8989
child: new Container(
9090
margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
91-
height: 600.0,
92-
width: 400.0,
91+
width: MediaQuery.of(context).size.width,
92+
height: MediaQuery.of(context).size.height,
9393
child: RTCVideoView(_localRenderer),
9494
decoration: new BoxDecoration(color: Colors.black54),
9595
),

example/lib/src/basic_sample/loopback_sample.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class _MyAppState extends State<LoopBackSample> {
195195
? const FractionalOffset(0.5, 0.1)
196196
: const FractionalOffset(0.0, 0.5),
197197
child: new Container(
198+
margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
198199
width: 320.0,
199200
height: 240.0,
200201
child: new RTCVideoView(_localRenderer),
@@ -206,6 +207,7 @@ class _MyAppState extends State<LoopBackSample> {
206207
? const FractionalOffset(0.5, 0.9)
207208
: const FractionalOffset(1.0, 0.5),
208209
child: new Container(
210+
margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
209211
width: 320.0,
210212
height: 240.0,
211213
child: new RTCVideoView(_remoteRenderer),

lib/rtc_video_view.dart

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,10 @@ class RTCVideoView extends StatefulWidget {
105105

106106
class _RTCVideoViewState extends State<RTCVideoView> {
107107
final RTCVideoRenderer renderer;
108-
double textureWidth = 0.0;
109-
double textureHeight = 0.0;
110-
double scale = 1.0;
111-
_RTCVideoViewState(this.renderer) {
112-
this.textureHeight = 0.0;
113-
this.textureWidth = 0.0;
114-
}
108+
var aspectRatio = 1.0;
109+
110+
_RTCVideoViewState(this.renderer);
111+
115112
@override
116113
void initState() {
117114
super.initState();
@@ -145,37 +142,25 @@ class _RTCVideoViewState extends State<RTCVideoView> {
145142
}
146143

147144
void _updateContainerSize() {
148-
if (context.findRenderObject() != null) {
149-
final BoxConstraints constraints = context.findRenderObject().constraints;
150-
if (constraints is BoxConstraints) {
151-
if (renderer.rotation == 90 || renderer.rotation == 270) {
152-
textureWidth = min(renderer.width, renderer.height);
153-
textureHeight = max(renderer.width, renderer.height);
154-
scale = min(constraints.minWidth / textureWidth,
155-
constraints.minHeight / textureHeight);
156-
} else {
157-
textureWidth = max(renderer.width, renderer.height);
158-
textureHeight = min(renderer.width, renderer.height);
159-
scale = min(constraints.minWidth / textureWidth,
160-
constraints.minHeight / textureHeight);
161-
}
162-
163-
textureWidth *= scale;
164-
textureHeight *= scale;
165-
}
145+
double textureWidth = 0.0, textureHeight = 0.0;
146+
if (renderer.rotation == 90 || renderer.rotation == 270) {
147+
textureWidth = min(renderer.width, renderer.height);
148+
textureHeight = max(renderer.width, renderer.height);
149+
aspectRatio = textureWidth / textureHeight;
150+
} else {
151+
textureWidth = max(renderer.width, renderer.height);
152+
textureHeight = min(renderer.width, renderer.height);
153+
aspectRatio = textureWidth / textureHeight;
166154
}
167155
}
168156

169157
@override
170158
Widget build(BuildContext context) {
171159
return new Center(
172-
child: (this.renderer._textureId == null ||
173-
this.renderer._srcObject == null)
160+
child: (this.renderer._textureId == null || this.renderer._srcObject == null)
174161
? new Container()
175-
: new Container(
176-
width: this.textureWidth,
177-
height: this.textureHeight,
178-
child: new Texture(textureId: this.renderer._textureId),
179-
));
162+
: new AspectRatio(
163+
aspectRatio: aspectRatio,
164+
child: new Texture(textureId: this.renderer._textureId)));
180165
}
181166
}

0 commit comments

Comments
 (0)
0