Skip to content

Commit

Permalink
[FIX] Refactoring recording functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
flashphoner committed Mar 28, 2014
1 parent fb54922 commit e3c7e12
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
12 changes: 9 additions & 3 deletions server/phone_app/phone_app.iml
Expand Up @@ -7,9 +7,15 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="wowza" level="project" />
<orderEntry type="module" module-name="flashphoner" />
<orderEntry type="library" name="slf4j" level="project" />
<orderEntry type="library" exported="" name="wowza" level="project" />
<orderEntry type="module" module-name="flashphoner" exported="" />
<orderEntry type="library" exported="" name="slf4j" level="project" />
<orderEntry type="library" exported="" name="tbs-flashphoner" level="project" />
<orderEntry type="library" name="jain-sip" level="project" />
<orderEntry type="library" name="slf4j-api-1.6.4" level="project" />
<orderEntry type="library" name="wms-server" level="project" />
<orderEntry type="library" name="wms-stream-live" level="project" />
<orderEntry type="library" name="wms-stream-publish" level="project" />
</component>
</module>

24 changes: 14 additions & 10 deletions server/phone_app/src/com/flashphoner/phone_app/Recorder.java
Expand Up @@ -35,6 +35,7 @@ public class Recorder {
}

private static Logger log = LoggerFactory.getLogger("Recorder");
private static Logger isRecordingAllowedLog = LoggerFactory.getLogger("isRecordingAllowed.Recorder");

protected static Map<IMediaStream, ILiveStreamRecord> recordingMap = new HashMap<IMediaStream, ILiveStreamRecord>();

Expand All @@ -47,7 +48,7 @@ public Recorder(IRtmpClient rtmpClient) {

protected void startRecording() {

log.info("startRecording rtmpClient: " + rtmpClient);
log.info("startRecording rtmpClientID: " + rtmpClient.getClient().getClientId());

String login = rtmpClient.getRtmpClientConfig().getAuthenticationName();

Expand Down Expand Up @@ -83,15 +84,18 @@ protected void startRecording() {
log.debug("Recording folder is ready: " + folderPath);
}

MediaStreamMap mediaStreamMap = rtmpClient.getClient().getVHost().getApplication(rtmpClient.getRtmpClientConfig().getApplicationName()).getAppInstance("_definst_").getStreams();
MediaStreamMap mediaStreamMap = rtmpClient.getClient().getAppInstance().getStreams();
List<IMediaStream> streams = mediaStreamMap.getStreams();


for (IMediaStream stream : streams) {
if (isRecordingAllowed(stream, callId, caller, callee, recordingBitMask)) {
record(stream, folderPath);
} else {
log.info("Recording is not allowed: caller: " + caller + " callee: " + callee + " stream: " + stream.getName() + " streamObj: " + stream + " recordingBitMask: " + recordingBitMask);
//check stream clientID, can be -1
if (stream.getClientId() == rtmpClient.getClient().getClientId()) {
//check if recording allowed
if (isRecordingAllowed(stream, callId, caller, callee, recordingBitMask)) {
record(stream, folderPath);
} else {
log.info("Recording is not allowed: caller: " + caller + " callee: " + callee + " stream: " + stream.getName() + " streamObj: " + stream + " recordingBitMask: " + recordingBitMask);
}
}
}

Expand All @@ -108,9 +112,9 @@ private boolean isRecordingAllowed(IMediaStream stream, String callId, String ca
boolean recordCalleeIncomingAudio = (recordingBitMask >> 1 & 0x01) == 1;
boolean recordCalleeIncomingVideo = (recordingBitMask >> 0 & 0x01) == 1;

log.info("isRecordingAllowed stream: " + stream.getName() + " callId: " + callId + " caller: " + caller + "callee: " + callee + " mask: " + recordingBitMask);
log.info("isRecordingAllowed for CALLER recordCallerOutgoingAudioVideo: " + recordCallerOutgoingAudioVideo + " recordCallerIncomingAudio: " + recordCallerIncomingAudio + " recordCallerIncomingVideo: " + recordCallerIncomingVideo);
log.info("isRecordingAllowed for CALLEE recordCalleeOutgoingAudioVideo: " + recordCalleeOutgoingAudioVideo + " recordCalleeIncomingAudio: " + recordCalleeIncomingAudio + " recordCalleeIncomingVideo: " + recordCalleeIncomingVideo);
isRecordingAllowedLog.debug("isRecordingAllowed stream: " + stream.getName() + " callId: " + callId + " caller: " + caller + "callee: " + callee + " mask: " + recordingBitMask);
isRecordingAllowedLog.debug("isRecordingAllowed for CALLER recordCallerOutgoingAudioVideo: " + recordCallerOutgoingAudioVideo + " recordCallerIncomingAudio: " + recordCallerIncomingAudio + " recordCallerIncomingVideo: " + recordCallerIncomingVideo);
isRecordingAllowedLog.debug("isRecordingAllowed for CALLEE recordCalleeOutgoingAudioVideo: " + recordCalleeOutgoingAudioVideo + " recordCalleeIncomingAudio: " + recordCalleeIncomingAudio + " recordCalleeIncomingVideo: " + recordCalleeIncomingVideo);

String streamName = stream.getName();
if (stream.getStreamType().equalsIgnoreCase("live")) {
Expand Down
Expand Up @@ -258,12 +258,12 @@ public void notifyOptions(SipMessageObject sipMessageObject) {

@Override
public void notifyRecordComplete(RecordReport recordReport) {
log.info("notifyRecordComplete: " + recordReport.getMixedFilename());
log.info("notifyRecordComplete for clientID + " + getClient().getClientId() + ", " + recordReport.getMixedFilename());
}

public void startRecording() {
if (log.isDebugEnabled()) {
log.debug("startRecording");
log.debug("startRecording clientID " + getClient().getClientId());
}
recorder.startRecording();
}
Expand Down
34 changes: 25 additions & 9 deletions server/phone_app/src/com/flashphoner/phone_app/TalkCallResult.java
Expand Up @@ -33,7 +33,7 @@ public TalkCallResult(RtmpClient rtmpClient) {

@Override
public void onResult(final IClient iClient, RequestFunction requestFunction, AMFDataList amfDataList) {
log.info("onResult rtmpClient: " + rtmpClient);
log.info("onResult rtmpClientID: " + rtmpClient.getClient().getClientId());
startRecording(iClient);
}

Expand All @@ -55,6 +55,7 @@ public void run() {
if (log.isDebugEnabled()) {
log.debug("currentCall: " + call);
}

MediaStreamMap map = rtmpClient.getClient().getAppInstance().getStreams();
for (int i = 0; i < 10; i++) {
if (call != null) {
Expand All @@ -63,14 +64,7 @@ public void run() {
IMediaStream stream = map.getStream(publishStreamName);

if (stream != null) {

long audioTC = stream.getAudioTC();

if (log.isDebugEnabled()) {
log.debug("Checking stream tc: " + audioTC + " stream: " + publishStreamName);
}

if (audioTC != 0) {
if (checkStreamTC(stream)) {
rtmpClient.startRecording();
return;
}
Expand All @@ -93,4 +87,26 @@ public void run() {


}

private Boolean checkStreamTC(IMediaStream stream) {
Boolean triggerOnVideo = Config.getInstance().getBooleanProperty("trigger_record_on_video", false);
Boolean result = false;

long videoTC = stream.getVideoTC();
long audioTC = stream.getAudioTC();

if (log.isDebugEnabled()) {
log.debug("Checking stream audioTC: " + audioTC + " videoTC: " + videoTC + " stream: " + stream.getName());
}

if (audioTC != 0 && !triggerOnVideo) {
log.debug("CheckStreamTC audioTC is present, triggerOnVideo " + triggerOnVideo + ", returning true");
result = true;
} else if (audioTC != 0 && videoTC != 0 && triggerOnVideo) {
log.debug("CheckStreamTC audioTC and videoTC are present, triggerOnVideo " + triggerOnVideo + ", returning true");
result = true;
}

return result;
}
}

0 comments on commit e3c7e12

Please sign in to comment.