Skip to content

Commit

Permalink
Update ALWebRTC
Browse files Browse the repository at this point in the history
  • Loading branch information
zeus64 committed Jun 30, 2019
1 parent 7d88c51 commit f9f42a3
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 5 deletions.
Binary file modified lib/jar/com.alcinoe/com.alcinoe.appsflyer/alcinoe-appsflyer.jar
Binary file not shown.
Binary file modified lib/jar/com.alcinoe/com.alcinoe.common/alcinoe-common.jar
Binary file not shown.
Binary file not shown.
Binary file modified lib/jar/com.alcinoe/com.alcinoe.edittext/alcinoe-edittext.jar
Binary file not shown.
Binary file modified lib/jar/com.alcinoe/com.alcinoe.facebook/alcinoe-facebook.jar
Binary file not shown.
Binary file modified lib/jar/com.alcinoe/com.alcinoe.firebase/alcinoe-firebase.jar
Binary file not shown.
Binary file modified lib/jar/com.alcinoe/com.alcinoe.webrtc/alcinoe-webrtc.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions source/ALAndroidWebRTCApi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ TJALWebRTC_PeerConnectionParameters = class(TJavaGenericImport<JALWebRTC_PeerC
procedure setListener(listener: JALWebRTC_Listener); cdecl;
function start: boolean; cdecl;
procedure stop; cdecl;
procedure resumeVideoCapturer; cdecl;
procedure pauseVideoCapturer; cdecl;
procedure setAudioEnabled(enable: boolean); cdecl;
procedure setVideoEnabled(enable: boolean); cdecl;
function setVideoMaxBitrate(maxBitrateKbps: integer): boolean; cdecl;
Expand Down
106 changes: 104 additions & 2 deletions source/ALWebRTC.pas
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ TRemoteVideoTrackRenderer = class(TOCLocal, RTCVideoRenderer)
fPeerConnection: RTCPeerConnection;
fPeerConnectionDelegate: TPeerConnectionDelegate;
fCameraVideoCapturer: RTCCameraVideoCapturer;
fCameraVideoCapturerStopped: Boolean;
fVideoSource: RTCVideoSource;
fLocalAudioTrack: RTCAudioTrack;
fLocalVideoTrack: RTCVideoTrack;
Expand All @@ -267,6 +268,8 @@ TRemoteVideoTrackRenderer = class(TOCLocal, RTCVideoRenderer)
destructor Destroy; override;
function Start: boolean;
procedure Stop;
procedure resumeVideoCapturer;
procedure pauseVideoCapturer;
procedure createOffer;
procedure createAnswer;
procedure setRemoteDescription(const aSdpType: TALWebRTCSDPType; const aSdpDescription: String);
Expand Down Expand Up @@ -390,6 +393,8 @@ TAndroidWebRTCListener = class(TJavaLocal, JALWebRTC_Listener)
destructor Destroy; override;
function Start: boolean;
procedure Stop;
procedure resumeVideoCapturer;
procedure pauseVideoCapturer;
procedure createOffer;
procedure createAnswer;
procedure setRemoteDescription(const aSdpType: TALWebRTCSDPType; const aSdpDescription: String);
Expand Down Expand Up @@ -699,6 +704,10 @@ function TALWebRTC.Start: boolean;

begin

{$IFDEF DEBUG}
allog('TALWebRTC.Start', 'ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.verbose);
{$ENDIF}

{$REGION ' ANDROID'}
{$IF defined(android)}

Expand Down Expand Up @@ -741,6 +750,10 @@ procedure TALWebRTC.Stop;

begin

{$IFDEF DEBUG}
allog('TALWebRTC.Stop', 'ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.verbose);
{$ENDIF}

{$REGION ' ANDROID'}
{$IF defined(android)}

Expand Down Expand Up @@ -770,6 +783,50 @@ procedure TALWebRTC.Stop;

end;

{**************************************}
procedure TALWebRTC.resumeVideoCapturer;
begin

{$REGION ' ANDROID'}
{$IF defined(android)}

fAndroidWebRTC.resumeVideoCapturer;

{$ENDIF}
{$ENDREGION}

{$REGION ' IOS'}
{$IF defined(ios)}

fiOSWebRTC.resumeVideoCapturer;

{$ENDIF}
{$ENDREGION}

end;

{************************************}
procedure TALWebRTC.pauseVideoCapturer;
begin

{$REGION ' ANDROID'}
{$IF defined(android)}

fAndroidWebRTC.pauseVideoCapturer;

{$ENDIF}
{$ENDREGION}

{$REGION ' IOS'}
{$IF defined(ios)}

fiOSWebRTC.pauseVideoCapturer;

{$ENDIF}
{$ENDREGION}

end;

{******************************}
procedure TALWebRTC.createOffer;
begin
Expand Down Expand Up @@ -1182,7 +1239,7 @@ constructor TALiOSWebRTC.Create(const aWebRTC: TALWebRTC; const aIceServers: TAL
begin

{$IFDEF DEBUG}
allog('TALiOSWebRTC.Create', 'TALiOSWebRTC.Create - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.verbose);
allog('TALiOSWebRTC.Create', 'ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.verbose);
{$ENDIF}

FreeOnTerminate := True;
Expand All @@ -1207,6 +1264,7 @@ constructor TALiOSWebRTC.Create(const aWebRTC: TALWebRTC; const aIceServers: TAL
fPeerConnection := nil;
fPeerConnectionDelegate := nil;
fCameraVideoCapturer := nil;
fCameraVideoCapturerStopped := true;
fVideoSource := nil;
fLocalAudioTrack := nil;
fLocalVideoTrack := nil;
Expand All @@ -1226,7 +1284,7 @@ destructor TALiOSWebRTC.Destroy;
begin

{$IFDEF DEBUG}
allog('TALiOSWebRTC.Destroy', 'TALiOSWebRTC.Destroy - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.verbose);
allog('TALiOSWebRTC.Destroy', 'ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.verbose);
{$ENDIF}

if not terminated then begin
Expand Down Expand Up @@ -1296,6 +1354,10 @@ procedure TALiOSWebRTC.Execute;
End;
end;

{$IFDEF DEBUG}
allog('TALiOSWebRTC.Execute', 'Terminating', TalLogType.verbose);
{$ENDIF}

//release all retained object
//-----
if fpeerConnection <> nil then begin
Expand All @@ -1305,6 +1367,7 @@ procedure TALiOSWebRTC.Execute;
//-----
if fCameraVideoCapturer <> nil then begin
fCameraVideoCapturer.stopCapture;
fCameraVideoCapturerStopped := true;
fCameraVideoCapturer.release; // << was created - taken from TRTCCameraVideoCapturer.OCClass.alloc.initWithDelegate(fVideoSource)
fCameraVideoCapturer := nil;
end;
Expand Down Expand Up @@ -1404,6 +1467,9 @@ function TALiOSWebRTC.start: boolean;
i: integer;
begin

//exit if already started
if fPeerConnectionFactory <> nil then exit;

//init fPeerConnectionFactory
aDecoderFactory := TRTCDefaultVideoDecoderFactory.Wrap(TRTCDefaultVideoDecoderFactory.Wrap(TRTCDefaultVideoDecoderFactory.OCClass.alloc).init);
aEncoderFactory := TRTCDefaultVideoEncoderFactory.Wrap(TRTCDefaultVideoEncoderFactory.Wrap(TRTCDefaultVideoEncoderFactory.OCClass.alloc).init);
Expand Down Expand Up @@ -1551,6 +1617,7 @@ function TALiOSWebRTC.start: boolean;
fCameraVideoCapturer.startCaptureWithDeviceFormatFps(aCaptureDevice, // device: AVCaptureDevice;
aCaptureDeviceFormat, // format: AVCaptureDeviceFormat;
selectFpsForFormat(aCaptureDeviceFormat)); // fps: NSInteger)
fCameraVideoCapturerStopped := False;

// We can set up rendering for the remote track right away since the transceiver already has an
// RTCRtpReceiver with a track. The track will automatically get unmuted and produce frames
Expand Down Expand Up @@ -1586,6 +1653,41 @@ procedure TALiOSWebRTC.Stop;
Terminate;
end;

{*****************************************}
procedure TALiOSWebRTC.resumeVideoCapturer;
begin

Enqueue(
Procedure
var aCaptureDevice: AVCaptureDevice;
aCaptureDeviceFormat: AVCaptureDeviceFormat;
begin
if not fCameraVideoCapturerStopped then exit;
aCaptureDevice := findDeviceForPosition(AVCaptureDevicePositionFront);
aCaptureDeviceFormat := selectFormatForDevice(aCaptureDevice, fCameraVideoCapturer.PreferredOutputPixelFormat);
if aCaptureDeviceFormat = nil then raise Exception.Create('No valid formats for device');
fCameraVideoCapturer.startCaptureWithDeviceFormatFps(aCaptureDevice, // device: AVCaptureDevice;
aCaptureDeviceFormat, // format: AVCaptureDeviceFormat;
selectFpsForFormat(aCaptureDeviceFormat)); // fps: NSInteger)
fCameraVideoCapturerStopped := False;
end);

end;

{****************************************}
procedure TALiOSWebRTC.pauseVideoCapturer;
begin

Enqueue(
Procedure
begin
if fCameraVideoCapturerStopped then exit;
fCameraVideoCapturer.stopCapture;
fCameraVideoCapturerStopped := true;
end);

end;

{*********************************}
procedure TALiOSWebRTC.createOffer;
begin
Expand Down
23 changes: 20 additions & 3 deletions source/java/com/alcinoe/webrtc/ALWebRTC.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class ALWebRTC {
private VideoTrack mRemoteVideoTrack = null;
private SurfaceTextureHelper mSurfaceTextureHelper = null;
private VideoCapturer mVideoCapturer = null;
private boolean mVideoCapturerStopped = true;
private List<IceCandidate> mQueuedRemoteCandidates = null;
private PeerConnection mPeerConnection = null;
private DataChannel mDataChannel = null;
Expand Down Expand Up @@ -505,6 +506,7 @@ public boolean start() throws ClassNotFoundException, InstantiationException, Il
mVideoCapturer.startCapture(mPeerConnectionParameters.videoWidth, /*width*/
mPeerConnectionParameters.videoHeight, /*height*/
mPeerConnectionParameters.videoFps); /*framerate*/
mVideoCapturerStopped = false;

mLocalVideoTrack = mPeerConnectionFactory.createVideoTrack(VIDEO_TRACK_ID, mVideoSource);
mLocalVideoTrack.setEnabled(true);
Expand Down Expand Up @@ -603,9 +605,8 @@ public void stop() {
if (mVideoCapturer != null) {
try {
mVideoCapturer.stopCapture();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} catch (InterruptedException e) {}
mVideoCapturerStopped = true;
mVideoCapturer.dispose();
mVideoCapturer = null;
}
Expand All @@ -624,6 +625,22 @@ public void stop() {
mEglBase.release();
}

public void pauseVideoCapturer() {
if (mVideoCapturerStopped) { return; }
try {
mVideoCapturer.stopCapture();
} catch (InterruptedException e) {}
mVideoCapturerStopped = true;
}

public void resumeVideoCapturer() {
if (!mVideoCapturerStopped) { return; }
mVideoCapturer.startCapture(mPeerConnectionParameters.videoWidth, /*width*/
mPeerConnectionParameters.videoHeight, /*height*/
mPeerConnectionParameters.videoFps); /*framerate*/
mVideoCapturerStopped = false;
}

public void setAudioEnabled(final boolean enable) {
if (mLocalAudioTrack != null) { mLocalAudioTrack.setEnabled(enable); }
}
Expand Down

0 comments on commit f9f42a3

Please sign in to comment.