Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / cast / transport / cast_transport_defines.h
index c096d6f..75e8d62 100644 (file)
@@ -5,9 +5,9 @@
 #ifndef MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_DEFINES_H_
 #define MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_DEFINES_H_
 
-#include <list>
 #include <map>
 #include <set>
+#include <string>
 
 #include "base/basictypes.h"
 #include "base/time/time.h"
@@ -30,6 +30,26 @@ typedef std::set<uint16> PacketIdSet;
 // Each uint8 represents one cast frame.
 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
 
+// Crypto.
+const size_t kAesBlockSize = 16;
+const size_t kAesKeySize = 16;
+
+inline std::string GetAesNonce(uint32 frame_id, const std::string& iv_mask) {
+  std::string aes_nonce(kAesBlockSize, 0);
+
+  // Serializing frame_id in big-endian order (aes_nonce[8] is the most
+  // significant byte of frame_id).
+  aes_nonce[11] = frame_id & 0xff;
+  aes_nonce[10] = (frame_id >> 8) & 0xff;
+  aes_nonce[9] = (frame_id >> 16) & 0xff;
+  aes_nonce[8] = (frame_id >> 24) & 0xff;
+
+  for (size_t i = 0; i < kAesBlockSize; ++i) {
+    aes_nonce[i] ^= iv_mask[i];
+  }
+  return aes_nonce;
+}
+
 // Rtcp defines.
 
 enum RtcpPacketTypes {
@@ -51,13 +71,10 @@ typedef std::set<uint16> PacketIdSet;
 // Each uint8 represents one cast frame.
 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
 
-
 class FrameIdWrapHelper {
  public:
   FrameIdWrapHelper()
-      : first_(true),
-        frame_id_wrap_count_(0),
-        range_(kLowRange) {}
+      : first_(true), frame_id_wrap_count_(0), range_(kLowRange) {}
 
   uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) {
     if (first_) {
@@ -101,11 +118,7 @@ class FrameIdWrapHelper {
   }
 
  private:
-  enum Range {
-    kLowRange,
-    kMiddleRange,
-    kHighRange,
-  };
+  enum Range { kLowRange, kMiddleRange, kHighRange, };
 
   static const uint8 kLowRangeThreshold = 0x0f;
   static const uint8 kHighRangeThreshold = 0xf0;
@@ -114,6 +127,8 @@ class FrameIdWrapHelper {
   bool first_;
   uint32 frame_id_wrap_count_;
   Range range_;
+
+  DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelper);
 };
 
 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) {