Home | History | Annotate | Download | only in net
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_
      6 #define MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_
      7 
      8 #include <stdint.h>
      9 
     10 #include <map>
     11 #include <set>
     12 #include <string>
     13 
     14 #include "base/basictypes.h"
     15 #include "base/time/time.h"
     16 
     17 namespace media {
     18 namespace cast {
     19 
     20 // TODO(mikhal): Implement and add more types.
     21 enum CastTransportStatus {
     22   TRANSPORT_AUDIO_UNINITIALIZED = 0,
     23   TRANSPORT_VIDEO_UNINITIALIZED,
     24   TRANSPORT_AUDIO_INITIALIZED,
     25   TRANSPORT_VIDEO_INITIALIZED,
     26   TRANSPORT_INVALID_CRYPTO_CONFIG,
     27   TRANSPORT_SOCKET_ERROR,
     28   CAST_TRANSPORT_STATUS_LAST = TRANSPORT_SOCKET_ERROR
     29 };
     30 
     31 const size_t kMaxIpPacketSize = 1500;
     32 // Each uint16 represents one packet id within a cast frame.
     33 typedef std::set<uint16> PacketIdSet;
     34 // Each uint8 represents one cast frame.
     35 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
     36 
     37 // Rtcp defines.
     38 
     39 enum RtcpPacketFields {
     40   kPacketTypeLow = 194,  // SMPTE time-code mapping.
     41   kPacketTypeSenderReport = 200,
     42   kPacketTypeReceiverReport = 201,
     43   kPacketTypeApplicationDefined = 204,
     44   kPacketTypeGenericRtpFeedback = 205,
     45   kPacketTypePayloadSpecific = 206,
     46   kPacketTypeXr = 207,
     47   kPacketTypeHigh = 210,  // Port Mapping.
     48 };
     49 
     50 // Each uint16 represents one packet id within a cast frame.
     51 typedef std::set<uint16> PacketIdSet;
     52 // Each uint8 represents one cast frame.
     53 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
     54 
     55 class FrameIdWrapHelperTest;
     56 
     57 // TODO(miu): UGLY IN-LINE DEFINITION IN HEADER FILE!  Move to appropriate
     58 // location, separated into .h and .cc files.
     59 class FrameIdWrapHelper {
     60  public:
     61   FrameIdWrapHelper()
     62       : largest_frame_id_seen_(kStartFrameId) {}
     63 
     64   uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) {
     65     uint32 ret = (largest_frame_id_seen_ & ~0xff) | over_the_wire_frame_id;
     66     // Add 1000 to both sides to avoid underflows.
     67     if (1000 + ret - largest_frame_id_seen_ > 1000 + 127) {
     68       ret -= 0x100;
     69     } else if (1000 + ret - largest_frame_id_seen_ < 1000 - 128) {
     70       ret += 0x100;
     71     }
     72     if (1000 + ret - largest_frame_id_seen_ > 1000) {
     73       largest_frame_id_seen_ = ret;
     74     }
     75     return ret;
     76   }
     77 
     78  private:
     79   friend class FrameIdWrapHelperTest;
     80   static const uint32 kStartFrameId = UINT32_C(0xffffffff);
     81 
     82   uint32 largest_frame_id_seen_;
     83 
     84   DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelper);
     85 };
     86 
     87 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) {
     88   base::TimeTicks zero_time;
     89   base::TimeDelta recorded_delta = time_ticks - zero_time;
     90   // Timestamp is in 90 KHz for video.
     91   return static_cast<uint32>(recorded_delta.InMilliseconds() * 90);
     92 }
     93 
     94 }  // namespace cast
     95 }  // namespace media
     96 
     97 #endif  // MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_
     98