if (stream == null) {
stream = streamConn.newBroadcastStream(streamId);
created = true;
}
IClientBroadcastStream bs = (IClientBroadcastStream) stream;
try {
bs.setPublishedName(name);
IContext context = conn.getScope().getContext();
IProviderService providerService = (IProviderService) context
.getBean(IProviderService.BEAN_NAME);
// TODO handle registration failure
if (providerService.registerBroadcastStream(conn.getScope(),
name, bs)) {
bsScope = getBroadcastScope(conn.getScope(), name);
bsScope.setAttribute(IBroadcastScope.STREAM_ATTRIBUTE, bs);
if (conn instanceof BaseConnection) {
((BaseConnection) conn).registerBasicScope(bsScope);
}
}
if (IClientStream.MODE_RECORD.equals(mode)) {
bs.start();
bs.saveAs(name, false);
} else if (IClientStream.MODE_APPEND.equals(mode)) {
bs.start();
bs.saveAs(name, true);
} else if (IClientStream.MODE_LIVE.equals(mode)) {
bs.start();
}
bs.startPublishing();
} catch (IOException e) {
Status accessDenied = new Status(StatusCodes.NS_RECORD_NOACCESS);
accessDenied.setClientid(streamId);
accessDenied.setDesciption("The file could not be created/written to.");
accessDenied.setDetails(name);
accessDenied.setLevel("error");
// FIXME: there should be a direct way to send the status
Channel channel = ((RTMPConnection) streamConn).getChannel((byte) (4 + ((streamId-1) * 5)));
channel.sendStatus(accessDenied);
bs.close();
if (created)
streamConn.deleteStreamById(streamId);
return;
} catch (Exception e) {
logger.warn("publish caught Exception");