git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube...
authorVásáry Dániel <daniel.vasary@userrendszerhaz.hu>
Wed, 11 Oct 2017 14:17:28 +0000 (14:17 +0000)
committerVásáry Dániel <daniel.vasary@userrendszerhaz.hu>
Wed, 11 Oct 2017 14:17:28 +0000 (14:17 +0000)
server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Clip.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipImpl.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/GetExtendedFieldGetRecordDateTimestampCommand.java [new file with mode: 0644]
server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocol.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/server/protocol/NexioServerProtocolImpl.java
server/user.jobengine.osgi.services/src/user/jobengine/osgi/ws/nexio/NexioWSServlet.java

index ffdf9d83cc9919576df02c8ccbee6b70dc41285a..01b9d94603650ffa801f587740390570924d876d 100644 (file)
@@ -17,6 +17,7 @@ import user.commons.nosql.NoSQLUtils;
 \r
 public class NexioAPI implements INexioAPI {\r
        private static final Logger logger = LogManager.getLogger();\r
+       private static final String MODIFIEDTIMESTAMP = "modifiedtimestamp";\r
 \r
        @Override\r
        public List<DBObject> getItems(Date modified, boolean itemsWithAgency) {\r
@@ -25,7 +26,7 @@ public class NexioAPI implements INexioAPI {
                try {\r
                        db = NoSQLUtils.getDB();\r
                        DBCollection collection = db.getCollection(NexioDataMiner.CLIP_COLLECTION_NAME);\r
-                       DBCursor find = collection.find().sort(new BasicDBObject("modified", new BasicDBList(-1, "$date")));\r
+                       DBCursor find = collection.find().sort(new BasicDBObject(MODIFIEDTIMESTAMP, new BasicDBList(-1, "$date")));\r
                        if (find.hasNext())\r
                                result = find.toArray();\r
                } catch (Exception e) {\r
index bbf50902ebf1b6ffe9f3ed9a0d1fa9029933e77e..262d6bba327e3815bcc1d867e17a2a478657dffe 100644 (file)
@@ -175,42 +175,52 @@ public class NexioClipEventDispatcher implements ClipEventListener {
                try {\r
                        jsClip.put(ID, clip.getId().get()); //Unique internal ID\r
                } catch (Exception e) {\r
-                       System.out.println(e);\r
+                       //                      System.out.println(e);\r
                }\r
                try {\r
                        jsClip.put(LONGNAMEID, clip.getXid().get()); //Extended ID (Filename)\r
                } catch (Exception e) {\r
-                       System.out.println(e);\r
+                       //                      System.out.println(e);\r
                }\r
                try {\r
                        jsClip.put(DURATION, clip.getDuration());\r
                } catch (Exception e) {\r
-                       System.out.println(e);\r
+                       //                      System.out.println(e);\r
                }\r
                try {\r
                        jsClip.put(MODIFIEDTIMESTAMP, clip.getModifiedTimestamp().getTime());\r
                } catch (Exception e) {\r
-                       System.out.println(e);\r
+                       //                      System.out.println(e);\r
                }\r
                try {\r
                        jsClip.put(VIDEO_FORMAT, clip.getVideoFormat());\r
                } catch (Exception e) {\r
-                       System.out.println(e);\r
+                       //                      System.out.println(e);\r
                }\r
                try {\r
                        jsClip.put(VIDEO_BITRATE, clip.getVideoBitrate());\r
                } catch (Exception e) {\r
-                       System.out.println(e);\r
+                       //                      System.out.println(e);\r
                }\r
                try {\r
                        jsClip.put(FILESIZE, clip.getFileSize());\r
                } catch (Exception e) {\r
-                       System.out.println(e);\r
+                       //                      System.out.println(e);\r
                }\r
                try {\r
                        jsClip.put(EXTAGENCY, new String(clip.getExtendedField(GetExtendedFieldCommand.FN_AGENCY)));\r
                } catch (Exception e) {\r
-                       System.out.println(e);\r
+                       //                      System.out.println(e);\r
+               }\r
+               try {\r
+                       jsClip.put(RECORDDATE, clip.getRecordDateTimestamp().getTime());\r
+               } catch (Exception e) {\r
+                       //                      System.out.println(e);\r
+               }\r
+               try {\r
+                       jsClip.put(DURATION, clip.getDuration());\r
+               } catch (Exception e) {\r
+                       //                      System.out.println(e);\r
                }\r
                //jsClip.put(RECORDDATE, new DateTime(rs.getString(i++)).toDate());\r
                //jsClip.put(EXTAGENCY, rs.getString(i++));\r
index a25a69359ff4bcd42a82e46fd6e5efedf15aa099..58cd56db50d734576dd9c3ca9adb5aaffd8076a3 100644 (file)
@@ -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;
-       
+
 }
index 447e1ad7ff9465a77c1dd04872d0f4414c705986..1a92f3e20f09c0f894c290debd9e4eba1d040ddb 100644 (file)
@@ -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 (file)
index 0000000..e730160
--- /dev/null
@@ -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;
+       }
+}
index eb80becc727804297f29a4716f4eaed199fb3e02..565618551a54334b7364adf29ffed1a7b8ea3061 100644 (file)
@@ -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();
-       
+
 }
index f8361ab20111f95079e44158a768b225f8edb642..884621c7cb127bff31112b3eeafb15248c086a49 100644 (file)
@@ -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;
        }
 
-       
 }
index 4cccfac85dbed880d6fb060f233e5842f51b5b0c..4dda64231e425d0d385514ee4ff7af90ecdd7104 100644 (file)
@@ -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<INexioChangeListener> 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<Session> 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) {