11
11
12
12
import org .webrtc .EglBase ;
13
13
import org .webrtc .MediaStream ;
14
+ import org .webrtc .MediaStreamTrack ;
14
15
import org .webrtc .RendererCommon .RendererEvents ;
15
16
import org .webrtc .VideoTrack ;
16
17
@@ -23,13 +24,14 @@ public class FlutterRTCVideoRenderer implements EventChannel.StreamHandler {
23
24
private final SurfaceTexture texture ;
24
25
private TextureRegistry .SurfaceTextureEntry entry ;
25
26
private int id = -1 ;
27
+ private MediaStream mediaStream ;
26
28
27
- public void Dispose (){
29
+ public void Dispose () {
28
30
//destroy
29
- if (surfaceTextureRenderer != null ) {
31
+ if (surfaceTextureRenderer != null ) {
30
32
surfaceTextureRenderer .release ();
31
33
}
32
- if (eventChannel != null )
34
+ if (eventChannel != null )
33
35
eventChannel .setStreamHandler (null );
34
36
35
37
eventSink = null ;
@@ -43,9 +45,9 @@ public void Dispose(){
43
45
private RendererEvents rendererEvents ;
44
46
45
47
private void listenRendererEvents () {
46
- rendererEvents = new RendererEvents () {
48
+ rendererEvents = new RendererEvents () {
47
49
private int _rotation = -1 ;
48
- private int _width = 0 , _height = 0 ;
50
+ private int _width = 0 , _height = 0 ;
49
51
50
52
@ Override
51
53
public void onFirstFrameRendered () {
@@ -60,8 +62,8 @@ public void onFrameResolutionChanged(
60
62
int videoWidth , int videoHeight ,
61
63
int rotation ) {
62
64
63
- if (eventSink != null ) {
64
- if (_width != videoWidth || _height != videoHeight ) {
65
+ if (eventSink != null ) {
66
+ if (_width != videoWidth || _height != videoHeight ) {
65
67
ConstraintsMap params = new ConstraintsMap ();
66
68
params .putString ("event" , "didTextureChangeVideoSize" );
67
69
params .putInt ("id" , id );
@@ -72,7 +74,7 @@ public void onFrameResolutionChanged(
72
74
eventSink .success (params .toMap ());
73
75
}
74
76
75
- if (_rotation != rotation ) {
77
+ if (_rotation != rotation ) {
76
78
ConstraintsMap params2 = new ConstraintsMap ();
77
79
params2 .putString ("event" , "didTextureChangeRotation" );
78
80
params2 .putInt ("id" , id );
@@ -84,6 +86,7 @@ public void onFrameResolutionChanged(
84
86
}
85
87
};
86
88
}
89
+
87
90
private SurfaceTextureRenderer surfaceTextureRenderer ;
88
91
89
92
/**
@@ -105,11 +108,11 @@ public FlutterRTCVideoRenderer(SurfaceTexture texture, TextureRegistry.SurfaceTe
105
108
this .entry = entry ;
106
109
}
107
110
108
- public void setEventChannel (EventChannel eventChannel ){
111
+ public void setEventChannel (EventChannel eventChannel ) {
109
112
this .eventChannel = eventChannel ;
110
113
}
111
114
112
- public void setId (int id ){
115
+ public void setId (int id ) {
113
116
this .id = id ;
114
117
}
115
118
@@ -137,11 +140,11 @@ private void removeRendererFromVideoTrack() {
137
140
* specified {@code mediaStream}.
138
141
*
139
142
* @param mediaStream The {@code MediaStream} to be rendered by this
140
- * {@code FlutterRTCVideoRenderer} or {@code null}.
143
+ * {@code FlutterRTCVideoRenderer} or {@code null}.
141
144
*/
142
145
public void setStream (MediaStream mediaStream ) {
143
146
VideoTrack videoTrack ;
144
-
147
+ this . mediaStream = mediaStream ;
145
148
if (mediaStream == null ) {
146
149
videoTrack = null ;
147
150
} else {
@@ -157,9 +160,9 @@ public void setStream(MediaStream mediaStream) {
157
160
* Sets the {@code VideoTrack} to be rendered by this {@code FlutterRTCVideoRenderer}.
158
161
*
159
162
* @param videoTrack The {@code VideoTrack} to be rendered by this
160
- * {@code FlutterRTCVideoRenderer} or {@code null}.
163
+ * {@code FlutterRTCVideoRenderer} or {@code null}.
161
164
*/
162
- private void setVideoTrack (VideoTrack videoTrack ) {
165
+ public void setVideoTrack (VideoTrack videoTrack ) {
163
166
VideoTrack oldValue = this .videoTrack ;
164
167
165
168
if (oldValue != videoTrack ) {
@@ -202,4 +205,17 @@ private void tryAddRendererToVideoTrack() {
202
205
}
203
206
}
204
207
208
+ public boolean checkMediaStream (String id ) {
209
+ if (null == id || null == mediaStream ) {
210
+ return false ;
211
+ }
212
+ return id .equals (mediaStream .getId ());
213
+ }
214
+
215
+ public boolean checkVideoTrack (String id ) {
216
+ if (null == id || null == videoTrack ) {
217
+ return false ;
218
+ }
219
+ return id .equals (videoTrack .id ());
220
+ }
205
221
}
0 commit comments