Skip to content

Commit

Permalink
- start implementing segment recording
Browse files Browse the repository at this point in the history
  • Loading branch information
ritzalam committed Oct 20, 2017
1 parent fd8f38e commit e918a2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 31 deletions.
Expand Up @@ -35,6 +35,7 @@
import org.red5.server.api.stream.IServerStream;
import org.red5.server.api.stream.IStreamListener;
import org.red5.server.api.stream.ISubscriberStream;
import org.red5.server.scheduling.QuartzSchedulingService;
import org.red5.server.stream.ClientBroadcastStream;
import org.slf4j.Logger;

Expand All @@ -47,6 +48,9 @@
public class VideoApplication extends MultiThreadedApplicationAdapter {
private static Logger log = Red5LoggerFactory.getLogger(VideoApplication.class, "video");

// Scheduler
private QuartzSchedulingService scheduler;

private MessagePublisher publisher;
private EventRecordingService recordingService;
private final Map<String, IStreamListener> streamListeners = new HashMap<String, IStreamListener>();
Expand All @@ -65,6 +69,8 @@ public class VideoApplication extends MultiThreadedApplicationAdapter {
public boolean appStart(IScope app) {
super.appStart(app);
log.info("BBB Video appStart");
// get the scheduler
scheduler = (QuartzSchedulingService) getContext().getBean(QuartzSchedulingService.BEAN_NAME);
return true;
}

Expand Down Expand Up @@ -255,7 +261,8 @@ public void streamBroadcastStart(IBroadcastStream stream) {
log.info("Start recording of stream=[" + stream.getPublishedName() + "] for meeting=[" + conn.getScope().getName() + "]");
Boolean recordVideoStream = true;

VideoStreamListener listener = new VideoStreamListener(conn.getScope(), stream, recordVideoStream, userId, packetTimeout);
VideoStreamListener listener = new VideoStreamListener(meetingId, streamId,
recordVideoStream, userId, packetTimeout, scheduler);
listener.setEventRecordingService(recordingService);
stream.addStreamListener(listener);
streamListeners.put(conn.getScope().getName() + "-" + stream.getPublishedName(), listener);
Expand Down
Expand Up @@ -67,7 +67,7 @@ public class VideoStreamListener implements IStreamListener {
private String userId;

// Stream being observed
private IBroadcastStream stream;
private String streamId;

// if this stream is recorded or not
private boolean record;
Expand All @@ -82,17 +82,17 @@ public class VideoStreamListener implements IStreamListener {

private volatile boolean streamPaused = false;

private IScope scope;
private String meetingId;

public VideoStreamListener(IScope scope, IBroadcastStream stream, Boolean record, String userId, int packetTimeout) {
this.scope = scope;
this.stream = stream;
public VideoStreamListener(String meetingId, String streamId, Boolean record,
String userId, int packetTimeout,
QuartzSchedulingService scheduler) {
this.meetingId = meetingId;
this.streamId = streamId;
this.record = record;
this.videoTimeout = packetTimeout;
this.userId = userId;

// get the scheduler
scheduler = (QuartzSchedulingService) scope.getParent().getContext().getBean(QuartzSchedulingService.BEAN_NAME);
this.scheduler = scheduler;

}

Expand Down Expand Up @@ -127,11 +127,11 @@ public void packetReceived(IBroadcastStream stream, IStreamPacket packet) {
Map<String, String> event = new HashMap<String, String>();
event.put("module", "WEBCAM");
event.put("timestamp", genTimestamp().toString());
event.put("meetingId", scope.getName());
event.put("meetingId", meetingId);
event.put("stream", stream.getPublishedName());
event.put("eventName", "StartWebcamShareEvent");

recordingService.record(scope.getName(), event);
recordingService.record(meetingId, event);
}
}

Expand All @@ -142,7 +142,7 @@ public void packetReceived(IBroadcastStream stream, IStreamPacket packet) {
long numSeconds = (now - lastVideoTime)/1000;

Map<String, Object> logData = new HashMap<String, Object>();
logData.put("meetingId", scope.getName());
logData.put("meetingId", meetingId);
logData.put("userId", userId);
logData.put("stream", stream.getPublishedName());
logData.put("packetCount", packetCount);
Expand Down Expand Up @@ -173,9 +173,9 @@ private class TimeoutJob implements IScheduledJob {

public void execute(ISchedulingService service) {
Map<String, Object> logData = new HashMap<String, Object>();
logData.put("meetingId", scope.getName());
logData.put("meetingId", meetingId);
logData.put("userId", userId);
logData.put("stream", stream.getPublishedName());
logData.put("stream", streamId);
logData.put("packetCount", packetCount);
logData.put("publishing", publishing);

Expand All @@ -185,29 +185,13 @@ public void execute(ISchedulingService service) {
if ((now - lastVideoTime) > videoTimeout && !streamPaused) {
streamPaused = true;
long numSeconds = (now - lastVideoTime)/1000;


logData.put("lastPacketTime (sec)", numSeconds);



String logStr = gson.toJson(logData);

log.warn("Video packet timeout. data={}", logStr );



/*
if (!streamStopped) {
streamStopped = true;
// remove the scheduled job
scheduler.removeScheduledJob(timeoutJobName);
// stop / clean up
if (publishing) {
stream.stop();
}
}
*/

}

String logStr = gson.toJson(logData);
Expand Down

0 comments on commit e918a2b

Please sign in to comment.