21
21
import com .connectsdk .service .webos .lgcast .common .connection .MobileDescription ;
22
22
import com .connectsdk .service .webos .lgcast .common .streaming .RTPStreaming ;
23
23
import com .connectsdk .service .webos .lgcast .common .utils .AppUtil ;
24
+ import com .connectsdk .service .webos .lgcast .common .utils .DeviceUtil ;
24
25
import com .connectsdk .service .webos .lgcast .common .utils .HandlerThreadEx ;
25
26
import com .connectsdk .service .webos .lgcast .common .utils .IOUtil ;
26
27
import com .connectsdk .service .webos .lgcast .common .utils .Logger ;
33
34
import com .connectsdk .service .webos .lgcast .screenmirroring .uibc .UibcAccessibilityService ;
34
35
import com .lge .lib .lgcast .iface .AudioCaptureIF ;
35
36
import com .lge .lib .lgcast .iface .CaptureStatus ;
36
- import com .lge .lib .lgcast .iface .VideoCaptureIF ;
37
37
import com .lge .lib .lgcast .iface .MasterKeyFactoryIF ;
38
+ import com .lge .lib .lgcast .iface .VideoCaptureIF ;
38
39
import org .json .JSONObject ;
39
40
40
41
public class MirroringService extends Service {
@@ -327,11 +328,21 @@ private boolean startCaptureAndStreaming(Intent intent) {
327
328
Logger .print ("startCaptureAndStreaming" );
328
329
329
330
try {
331
+ Point captureSizeInLandscape = MirroringServiceFunc .getCaptureSizeInLandscape (this );
332
+ int width = captureSizeInLandscape .x ;
333
+ int height = captureSizeInLandscape .y ;
334
+ int bitrate = ScreenMirroringConfig .Video .BITRATE_6MB ;
335
+
336
+ float totalMemoryGB = DeviceUtil .getTotalMemorySpace (this ) / 1024F / 1024F / 1024F ;
337
+ if (totalMemoryGB <= 3.0 ) bitrate = ScreenMirroringConfig .Video .BITRATE_1MB ;
338
+ else if (totalMemoryGB <= 4.0 ) bitrate = ScreenMirroringConfig .Video .BITRATE_4MB ;
339
+ Logger .error ("### width=%d, height=%d, totalMemory=%f, bitrate=%d ###" , width , height , totalMemoryGB , bitrate );
340
+
330
341
mMediaProjection = MirroringServiceFunc .getMediaProjection (this , intent );
331
342
if (mMediaProjection == null ) throw new Exception ("Invalid projection" );
332
343
333
344
mRTPStreaming = new RTPStreaming ();
334
- mRTPStreaming .setStreamingConfig (MirroringServiceFunc .createRtpVideoConfig (ScreenMirroringConfig . Video . BITRATE ), MirroringServiceFunc .createRtpAudioConfig (), MirroringServiceFunc .createRtpSecurityConfig (mMirroringSourceCapability .masterKeys ));
345
+ mRTPStreaming .setStreamingConfig (MirroringServiceFunc .createRtpVideoConfig (bitrate ), MirroringServiceFunc .createRtpAudioConfig (), MirroringServiceFunc .createRtpSecurityConfig (mMirroringSourceCapability .masterKeys ));
335
346
mRTPStreaming .open (this , ScreenMirroringConfig .RTP .SSRC , mMirroringSinkCapability .ipAddress , mMirroringSinkCapability .videoUdpPort , mMirroringSinkCapability .audioUdpPort );
336
347
337
348
if (ScreenMirroringConfig .Test .testMkiUpdate == true ) {
@@ -345,19 +356,16 @@ private boolean startCaptureAndStreaming(Intent intent) {
345
356
mAudioCapture .setErrorListener (this ::stop );
346
357
mAudioCapture .startCapture (mMediaProjection , mRTPStreaming .getAudioStreamHandler ());
347
358
348
- Point captureSizeInLandscape = MirroringServiceFunc .getCaptureSizeInLandscape (this );
349
- Logger .debug ("captureSizeInLandscape.x=%d, captureSizeInLandscape.y=%d" , captureSizeInLandscape .x , captureSizeInLandscape .y );
350
-
351
359
mLandscapeVideoCapture = new VideoCaptureIF ("land" );
352
360
mLandscapeVideoCapture .setErrorListener (this ::stop );
353
- mLandscapeVideoCapture .prepare (captureSizeInLandscape . x , captureSizeInLandscape . y , ScreenMirroringConfig . Video . BITRATE , mMediaProjection , mRTPStreaming .getVideoStreamHandler ());
361
+ mLandscapeVideoCapture .prepare (width , height , bitrate , mMediaProjection , mRTPStreaming .getVideoStreamHandler ());
354
362
355
363
mPortraitVideoCapture = new VideoCaptureIF ("port" );
356
364
mPortraitVideoCapture .setErrorListener (this ::stop );
357
365
358
366
if (MirroringServiceFunc .isDualScreen (intent ) == false ) {
359
367
Logger .debug ("Prepare portrait capture" );
360
- mPortraitVideoCapture .prepare (captureSizeInLandscape . y , captureSizeInLandscape . x , ScreenMirroringConfig . Video . BITRATE , mMediaProjection , mRTPStreaming .getVideoStreamHandler ());
368
+ mPortraitVideoCapture .prepare (height , width , bitrate , mMediaProjection , mRTPStreaming .getVideoStreamHandler ());
361
369
}
362
370
363
371
if (mMirroringSinkCapability .isDisplayPortrait () == true ) mPortraitVideoCapture .start ();
0 commit comments