From: Vásáry Dániel Date: Wed, 11 Oct 2017 14:17:28 +0000 (+0000) Subject: git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube... X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=e7a9a69d50e508ab2ada0fdf341d867235ecf155;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C30589 --- diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java index ffdf9d83..01b9d946 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java @@ -17,6 +17,7 @@ import user.commons.nosql.NoSQLUtils; public class NexioAPI implements INexioAPI { private static final Logger logger = LogManager.getLogger(); + private static final String MODIFIEDTIMESTAMP = "modifiedtimestamp"; @Override public List getItems(Date modified, boolean itemsWithAgency) { @@ -25,7 +26,7 @@ public class NexioAPI implements INexioAPI { try { db = NoSQLUtils.getDB(); DBCollection collection = db.getCollection(NexioDataMiner.CLIP_COLLECTION_NAME); - DBCursor find = collection.find().sort(new BasicDBObject("modified", new BasicDBList(-1, "$date"))); + DBCursor find = collection.find().sort(new BasicDBObject(MODIFIEDTIMESTAMP, new BasicDBList(-1, "$date"))); if (find.hasNext()) result = find.toArray(); } catch (Exception e) { diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java index bbf50902..262d6bba 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java @@ -175,42 +175,52 @@ public class NexioClipEventDispatcher implements ClipEventListener { try { jsClip.put(ID, clip.getId().get()); //Unique internal ID } catch (Exception e) { - System.out.println(e); + // System.out.println(e); } try { jsClip.put(LONGNAMEID, clip.getXid().get()); //Extended ID (Filename) } catch (Exception e) { - System.out.println(e); + // System.out.println(e); } try { jsClip.put(DURATION, clip.getDuration()); } catch (Exception e) { - System.out.println(e); + // System.out.println(e); } try { jsClip.put(MODIFIEDTIMESTAMP, clip.getModifiedTimestamp().getTime()); } catch (Exception e) { - System.out.println(e); + // System.out.println(e); } try { jsClip.put(VIDEO_FORMAT, clip.getVideoFormat()); } catch (Exception e) { - System.out.println(e); + // System.out.println(e); } try { jsClip.put(VIDEO_BITRATE, clip.getVideoBitrate()); } catch (Exception e) { - System.out.println(e); + // System.out.println(e); } try { jsClip.put(FILESIZE, clip.getFileSize()); } catch (Exception e) { - System.out.println(e); + // System.out.println(e); } try { jsClip.put(EXTAGENCY, new String(clip.getExtendedField(GetExtendedFieldCommand.FN_AGENCY))); } catch (Exception e) { - System.out.println(e); + // System.out.println(e); + } + try { + jsClip.put(RECORDDATE, clip.getRecordDateTimestamp().getTime()); + } catch (Exception e) { + // System.out.println(e); + } + try { + jsClip.put(DURATION, clip.getDuration()); + } catch (Exception e) { + // System.out.println(e); } //jsClip.put(RECORDDATE, new DateTime(rs.getString(i++)).toDate()); //jsClip.put(EXTAGENCY, rs.getString(i++)); diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Clip.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Clip.java index a25a6935..58cd56db 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Clip.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Clip.java @@ -1,24 +1,29 @@ package user.commons.nexio.api; -import user.commons.nexio.server.protocol.*; import java.io.IOException; import java.util.Calendar; +import user.commons.nexio.server.protocol.Id; +import user.commons.nexio.server.protocol.ProtocolException; +import user.commons.nexio.server.protocol.Xid; + public interface Clip { public int getDuration() throws ClipNotFoundException, IOException, ProtocolException; - - public int getVideoFormat() throws ClipNotFoundException, IOException, ProtocolException; - - public int getVideoBitrate() throws ClipNotFoundException, IOException, ProtocolException; + + public byte[] getExtendedField(byte[] fieldNumber) throws IOException, ProtocolException; + + public long getFileSize() throws ClipNotFoundException, IOException, ProtocolException; public Id getId(); public Calendar getModifiedTimestamp() throws ClipNotFoundException, IOException, ProtocolException; + Calendar getRecordDateTimestamp() throws ClipNotFoundException, IOException, ProtocolException; + + public int getVideoBitrate() throws ClipNotFoundException, IOException, ProtocolException; + + public int getVideoFormat() throws ClipNotFoundException, IOException, ProtocolException; + public Xid getXid() throws ClipNotFoundException, IOException, ProtocolException; - - public long getFileSize() throws ClipNotFoundException, IOException, ProtocolException; - - public byte[] getExtendedField(byte[] fieldNumber) throws IOException, ProtocolException; - + } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java index 447e1ad7..1a92f3e2 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java @@ -1,9 +1,13 @@ package user.commons.nexio.api; -import user.commons.nexio.server.protocol.*; import java.io.IOException; import java.util.Calendar; +import user.commons.nexio.server.protocol.Id; +import user.commons.nexio.server.protocol.NexioServerProtocol; +import user.commons.nexio.server.protocol.ProtocolException; +import user.commons.nexio.server.protocol.Xid; + class ClipImpl implements Clip { private static final String PROTOCOL = "protocol"; @@ -58,52 +62,58 @@ class ClipImpl implements Clip { metadata = protocol.executeGetIDMetadata(id); checkClipExists(metadata); } - return metadata[16] + (metadata[17] << 8) + (metadata[18] << 16) - + (metadata[19] << 24); + return metadata[16] + (metadata[17] << 8) + (metadata[18] << 16) + (metadata[19] << 24); } - /** - @return - 0x00 Not supported - 0x01 Not supported - 0x02 MPEG2 4:2:0 - 0x03 MPEG2 4:2:2 - 0x04 DVCAM version of DV25 - 0x05 DVCPRO version of DV25 - 0x06 DV50, DVCPRO HD, or DNxHD - 0x07 Uncompressed KRGB 8 bits - 0x08 Uncompressed K 16 bits - 0x09 IMX (MPEG 4:2:2), CBG (constrained bytes per GOP) - 0x0A H.264 4:2:0 - 0x0B H.264 4:2:2 - 0x0C H.264 4:2:0 CBG (e.g. AVC-Intra class 50) - 0x0D H.264 4:2:2 CBG (e.g. AVC-Intra class 100) - 0x0E Reserved - 0x0F Audio-only (no video) - */ @Override - public int getVideoFormat() throws ClipNotFoundException, IOException, ProtocolException{ - if (metadata == null) { - metadata = protocol.executeGetIDMetadata(id); - checkClipExists(metadata); + public byte[] getExtendedField(byte[] fieldNumber) throws IOException, ProtocolException { + return protocol.executeGetExtendedFieldCommand(id, fieldNumber); + } + + @Override + public long getFileSize() throws ClipNotFoundException, IOException, ProtocolException { + if (fileSize == -1) { + fileSize = protocol.executeGetIDFileSizeCommand(id); + checkClipExists(fileSize > -1 ? new Long(fileSize) : null); } - return metadata[8]; + return fileSize; } + @Override + public Id getId() { + return id; + } + + @Override + public Calendar getModifiedTimestamp() throws ClipNotFoundException, IOException, ProtocolException { + if (timestamp == null) { + timestamp = protocol.executeGetExtendedFieldGetModifiedTimestamp(id); + checkClipExists(timestamp); + } + return timestamp; + } + @Override + public Calendar getRecordDateTimestamp() throws ClipNotFoundException, IOException, ProtocolException { + if (timestamp == null) { + timestamp = protocol.executeGetExtendedFieldGetModifiedTimestamp(id); + checkClipExists(timestamp); + } + return timestamp; + } @Override - public int getVideoBitrate() throws ClipNotFoundException, IOException, ProtocolException{ + public int getVideoBitrate() throws ClipNotFoundException, IOException, ProtocolException { int ret = 0; if (metadata == null) { metadata = protocol.executeGetIDMetadata(id); checkClipExists(metadata); } - //Exact report of the compressed bit rate of the video portion of the clip. - //The 2 bytes are returned LSB first. This information replaces information provided + //Exact report of the compressed bit rate of the video portion of the clip. + //The 2 bytes are returned LSB first. This information replaces information provided //in Data #11 as of the NEXIO 6.0 Software Release - ret = metadata[20] + (metadata[21] << 8); - if(ret == 0){ + ret = metadata[20] + (metadata[21] << 8); + if (ret == 0) { //Use the information in this field only if the Exact Video Bit Rate = 0 (Data #20-21). //It reports the compressed bit rate of the video portion of the clip. //See note below for interpreting values >50 Mb/s. @@ -112,47 +122,28 @@ class ClipImpl implements Clip { return ret; } - - - - @Override - public Id getId() { - return id; - } - + /** + * @return 0x00 Not supported 0x01 Not supported 0x02 MPEG2 4:2:0 0x03 MPEG2 4:2:2 0x04 DVCAM version of DV25 0x05 DVCPRO version of DV25 0x06 DV50, DVCPRO + * HD, or DNxHD 0x07 Uncompressed KRGB 8 bits 0x08 Uncompressed K 16 bits 0x09 IMX (MPEG 4:2:2), CBG (constrained bytes per GOP) 0x0A H.264 4:2:0 + * 0x0B H.264 4:2:2 0x0C H.264 4:2:0 CBG (e.g. AVC-Intra class 50) 0x0D H.264 4:2:2 CBG (e.g. AVC-Intra class 100) 0x0E Reserved 0x0F Audio-only (no + * video) + */ @Override - public Calendar getModifiedTimestamp() throws ClipNotFoundException, - IOException, ProtocolException { - if (timestamp == null) { - timestamp = protocol - .executeGetExtendedFieldGetModifiedTimestamp(id); - checkClipExists(timestamp); + public int getVideoFormat() throws ClipNotFoundException, IOException, ProtocolException { + if (metadata == null) { + metadata = protocol.executeGetIDMetadata(id); + checkClipExists(metadata); } - return timestamp; + return metadata[8]; } @Override - public Xid getXid() throws ClipNotFoundException, IOException, - ProtocolException { + public Xid getXid() throws ClipNotFoundException, IOException, ProtocolException { if (xid == null) { xid = protocol.executeGetExtendedIDFromIDHandle(id); checkClipExists(xid); } return xid; } - - @Override - public long getFileSize() throws ClipNotFoundException, IOException, ProtocolException { - if (fileSize == -1) { - fileSize = protocol.executeGetIDFileSizeCommand(id); - checkClipExists(fileSize > -1 ? new Long(fileSize) : null); - } - return fileSize; - } - @Override - public byte[] getExtendedField(byte[] fieldNumber) throws IOException, ProtocolException{ - return protocol.executeGetExtendedFieldCommand(id, fieldNumber); - } - } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/GetExtendedFieldGetRecordDateTimestampCommand.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/GetExtendedFieldGetRecordDateTimestampCommand.java new file mode 100644 index 00000000..e7301606 --- /dev/null +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/GetExtendedFieldGetRecordDateTimestampCommand.java @@ -0,0 +1,79 @@ +package user.commons.nexio.server.protocol; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Calendar; + +public class GetExtendedFieldGetRecordDateTimestampCommand extends Command { + + private final static byte[] GET_EXTENDED_FIELD = { (byte) 0xc9, (byte) 0xc3 }; + private final static byte[] EXTENDED_FIELD_NUMBER = { (byte) 0 }; + + private byte[] buffer; + private byte filetime[]; + + public GetExtendedFieldGetRecordDateTimestampCommand(Connection connection) { + super(connection); + } + + private Calendar convertFromFILETIME(byte[] filetime) { + Calendar result = Calendar.getInstance(); + + ByteBuffer b = ByteBuffer.wrap(filetime); + b.order(ByteOrder.LITTLE_ENDIAN); + int lo = b.asIntBuffer().get(0); + int hi = b.asIntBuffer().get(1); + + long wFILETIME = ((long) hi << 32) + lo; + + final long EPOCH_DIFF = 11644473600000L; + final long ms_since_16010101 = wFILETIME / (10000); + final long ms_since_19700101 = ms_since_16010101 - EPOCH_DIFF; + + result.setTimeInMillis(ms_since_19700101); + + return result; + } + + public Calendar execute(Id id) throws IOException, ProtocolException { + + Calendar ret = null; + + connection.write(GET_EXTENDED_FIELD); + connection.write(id.get().getBytes()); + connection.write(EXTENDED_FIELD_NUMBER); + connection.flush(); + + buffer = new byte[2]; + int c = connection.read(buffer, 0, 2); + if (c < 2) { + throw getException_InvalidResponseLength(c, 2, 2); + } + + // Not found + if (buffer[0] == (byte) 0xd0 && buffer[1] == (byte) 0xc3) { + throw new ProtocolException("ID handle is not found!"); + } else + // 1. Found + if (buffer[0] == (byte) 0xdf && buffer[1] == (byte) 0xc3) { + + // 2. read NOF BYTES + buffer = new byte[1]; + c = connection.read(buffer, 0, 1); + + int toRead = buffer[0]; + if (toRead != 8) { + throw new ProtocolException("Invalid ModifiedTimeStamp's data length: " + toRead); + } else { + filetime = new byte[8]; + c = connection.read(filetime, 0, 8); + if (c != 8) { + throw getException_InvalidResponseLength(c, 8, 8); + } + ret = convertFromFILETIME(filetime); + } + } + return ret; + } +} diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocol.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocol.java index eb80becc..56561855 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocol.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocol.java @@ -2,14 +2,19 @@ package user.commons.nexio.server.protocol; import java.io.IOException; import java.util.Calendar; -import java.util.List; public interface NexioServerProtocol { + public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException; + public Calendar executeGetExtendedFieldGetModifiedTimestamp(Id id) throws IOException, ProtocolException; + public Calendar executeGetExtendedFieldGetRecordDateTimestamp(Id id) throws IOException, ProtocolException; + public Xid executeGetExtendedIDFromIDHandle(Id id) throws IOException, ProtocolException; + public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException; + public Id executeGetIDHandleFromExtendedID(Xid xid) throws IOException, ProtocolException; public byte[] executeGetIDMetadata(Id id) throws IOException, ProtocolException; @@ -18,12 +23,8 @@ public interface NexioServerProtocol { public Id executeListNextIDHandle() throws IOException, ProtocolException; - public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException; - public byte executePortStatusCommand() throws IOException, ProtocolException; - - public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException; - + public Connection getConnection(); - + } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocolImpl.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocolImpl.java index f8361ab2..884621c7 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocolImpl.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocolImpl.java @@ -2,7 +2,6 @@ package user.commons.nexio.server.protocol; import java.io.IOException; import java.util.Calendar; -import java.util.List; public class NexioServerProtocolImpl implements NexioServerProtocol { @@ -10,25 +9,32 @@ public class NexioServerProtocolImpl implements NexioServerProtocol { private GetIDMetadataCommand getIDMetadataCommand = null; private GetIDHandleFromExtendedIDCommand getIDHandleFromExtendedIDCommand = null; private GetExtendedFieldGetModifiedTimestampCommand getExtendedFieldGetModifiedTimestampCommand = null; + private GetExtendedFieldGetRecordDateTimestampCommand getExtendedFieldGetRecordDateTimestampCommand = null; private ListFirstIDHandleCommand listFirstIDHandleCommand = null; private ListNextIDHandleCommand listNextIDHandleCommand = null; private GetIDFileSizeCommand getIDFileSizeCommand = null; private PortStatusCommand portStatusCommand = null; private GetExtendedFieldCommand getExtendedFieldCommand = null; - + private Connection connection = null; - + public NexioServerProtocolImpl(Connection _connection) { this.connection = _connection; getExtendedIDFromIDHandleCommand = new GetExtendedIDFromIDHandleCommand(connection); getIDMetadataCommand = new GetIDMetadataCommand(connection); getIDHandleFromExtendedIDCommand = new GetIDHandleFromExtendedIDCommand(connection); getExtendedFieldGetModifiedTimestampCommand = new GetExtendedFieldGetModifiedTimestampCommand(connection); + getExtendedFieldGetRecordDateTimestampCommand = new GetExtendedFieldGetRecordDateTimestampCommand(connection); listFirstIDHandleCommand = new ListFirstIDHandleCommand(connection); listNextIDHandleCommand = new ListNextIDHandleCommand(connection); getIDFileSizeCommand = new GetIDFileSizeCommand(connection); portStatusCommand = new PortStatusCommand(connection); - getExtendedFieldCommand = new GetExtendedFieldCommand(connection); + getExtendedFieldCommand = new GetExtendedFieldCommand(connection); + } + + @Override + public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException { + return getExtendedFieldCommand.execute(id, fieldNumber); } @Override @@ -36,11 +42,21 @@ public class NexioServerProtocolImpl implements NexioServerProtocol { return getExtendedFieldGetModifiedTimestampCommand.execute(id); } + @Override + public Calendar executeGetExtendedFieldGetRecordDateTimestamp(Id id) throws IOException, ProtocolException { + return getExtendedFieldGetRecordDateTimestampCommand.execute(id); + } + @Override public Xid executeGetExtendedIDFromIDHandle(Id id) throws IOException, ProtocolException { return getExtendedIDFromIDHandleCommand.execute(id); } + @Override + public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException { + return getIDFileSizeCommand.execute(id); + } + @Override public Id executeGetIDHandleFromExtendedID(Xid xid) throws IOException, ProtocolException { return getIDHandleFromExtendedIDCommand.execute(xid); @@ -62,25 +78,14 @@ public class NexioServerProtocolImpl implements NexioServerProtocol { } @Override - public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException { - return getIDFileSizeCommand.execute(id); - } - - @Override - public byte executePortStatusCommand() throws IOException, ProtocolException{ - return portStatusCommand.execute(); + public byte executePortStatusCommand() throws IOException, ProtocolException { + return portStatusCommand.execute(); } @Override - public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException{ - return getExtendedFieldCommand.execute(id, fieldNumber); - } - - - @Override - public Connection getConnection(){; + public Connection getConnection() { + ; return this.connection; } - } diff --git a/server/user.jobengine.osgi.services/src/user/jobengine/osgi/ws/nexio/NexioWSServlet.java b/server/user.jobengine.osgi.services/src/user/jobengine/osgi/ws/nexio/NexioWSServlet.java index 4cccfac8..4dda6423 100644 --- a/server/user.jobengine.osgi.services/src/user/jobengine/osgi/ws/nexio/NexioWSServlet.java +++ b/server/user.jobengine.osgi.services/src/user/jobengine/osgi/ws/nexio/NexioWSServlet.java @@ -1,5 +1,7 @@ package user.jobengine.osgi.ws.nexio; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import org.apache.logging.log4j.LogManager; @@ -38,12 +40,12 @@ public class NexioWSServlet extends WebSocketServlet implements INexioChangeList this.dispatcher = new NexioClipEventDispatcher(); this.dispatcher.setNexioChangeListener(this); logger.info("NexioWSServlet has been initialized."); - /* + /* BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); if (bundleContext != null) { ServiceRegistration registerService = bundleContext .registerService(INexioChangeListener.class, this, null); - + logger.info("{} successfully registered", INexioChangeListener.class.getSimpleName()); } */ @@ -86,14 +88,20 @@ public class NexioWSServlet extends WebSocketServlet implements INexioChangeList } private void processMessage(BasicDBObject message) { + List deadSessions = null; for (Session session : sessions) { try { NexioWSSocket.asyncSendResponse(session, message); } catch (Exception e) { - // TODO remove closed logger.error(e); + if (deadSessions == null) + deadSessions = new ArrayList<>(); + deadSessions.add(session); } } + + if (deadSessions != null) + sessions.removeAll(deadSessions); } public void removeSession(Session session) {