Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / media / cast / net / cast_transport_config.h
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_CONFIG_H_
6 #define MEDIA_CAST_NET_CAST_TRANSPORT_CONFIG_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/stl_util.h"
16 #include "media/cast/net/cast_transport_defines.h"
17
18 namespace media {
19 namespace cast {
20
21 enum Codec {
22   CODEC_UNKNOWN,
23   CODEC_AUDIO_OPUS,
24   CODEC_AUDIO_PCM16,
25   CODEC_AUDIO_AAC,
26   CODEC_VIDEO_FAKE,
27   CODEC_VIDEO_VP8,
28   CODEC_VIDEO_H264,
29   CODEC_LAST = CODEC_VIDEO_H264
30 };
31
32 struct CastTransportRtpConfig {
33   CastTransportRtpConfig();
34   ~CastTransportRtpConfig();
35
36   // Identifier refering to this sender.
37   uint32 ssrc;
38
39   // Identifier for incoming RTCP traffic.
40   uint32 feedback_ssrc;
41
42   // RTP payload type enum: Specifies the type/encoding of frame data.
43   int rtp_payload_type;
44
45   // The AES crypto key and initialization vector.  Each of these strings
46   // contains the data in binary form, of size kAesKeySize.  If they are empty
47   // strings, crypto is not being used.
48   std::string aes_key;
49   std::string aes_iv_mask;
50 };
51
52 // A combination of metadata and data for one encoded frame.  This can contain
53 // audio data or video data or other.
54 struct EncodedFrame {
55   enum Dependency {
56     // "null" value, used to indicate whether |dependency| has been set.
57     UNKNOWN_DEPENDENCY,
58
59     // Not decodable without the reference frame indicated by
60     // |referenced_frame_id|.
61     DEPENDENT,
62
63     // Independently decodable.
64     INDEPENDENT,
65
66     // Independently decodable, and no future frames will depend on any frames
67     // before this one.
68     KEY,
69
70     DEPENDENCY_LAST = KEY
71   };
72
73   EncodedFrame();
74   ~EncodedFrame();
75
76   // Convenience accessors to data as an array of uint8 elements.
77   const uint8* bytes() const {
78     return reinterpret_cast<uint8*>(string_as_array(
79         const_cast<std::string*>(&data)));
80   }
81   uint8* mutable_bytes() {
82     return reinterpret_cast<uint8*>(string_as_array(&data));
83   }
84
85   // Copies all data members except |data| to |dest|.
86   // Does not modify |dest->data|.
87   void CopyMetadataTo(EncodedFrame* dest) const;
88
89   // This frame's dependency relationship with respect to other frames.
90   Dependency dependency;
91
92   // The label associated with this frame.  Implies an ordering relative to
93   // other frames in the same stream.
94   uint32 frame_id;
95
96   // The label associated with the frame upon which this frame depends.  If
97   // this frame does not require any other frame in order to become decodable
98   // (e.g., key frames), |referenced_frame_id| must equal |frame_id|.
99   uint32 referenced_frame_id;
100
101   // The stream timestamp, on the timeline of the signal data.  For example, RTP
102   // timestamps for audio are usually defined as the total number of audio
103   // samples encoded in all prior frames.  A playback system uses this value to
104   // detect gaps in the stream, and otherwise stretch the signal to match
105   // playout targets.
106   uint32 rtp_timestamp;
107
108   // The common reference clock timestamp for this frame.  This value originates
109   // from a sender and is used to provide lip synchronization between streams in
110   // a receiver.  Thus, in the sender context, this is set to the time at which
111   // the frame was captured/recorded.  In the receiver context, this is set to
112   // the target playout time.  Over a sequence of frames, this time value is
113   // expected to drift with respect to the elapsed time implied by the RTP
114   // timestamps; and it may not necessarily increment with precise regularity.
115   base::TimeTicks reference_time;
116
117   // Playout delay for this and all future frames. Used by the Adaptive
118   // Playout delay extension. Zero means no change.
119   uint16 new_playout_delay_ms;
120
121   // The encoded signal data.
122   std::string data;
123 };
124
125 typedef std::vector<uint8> Packet;
126 typedef scoped_refptr<base::RefCountedData<Packet> > PacketRef;
127 typedef std::vector<PacketRef> PacketList;
128
129 typedef base::Callback<void(scoped_ptr<Packet> packet)> PacketReceiverCallback;
130
131 class PacketSender {
132  public:
133   // Send a packet to the network. Returns false if the network is blocked
134   // and we should wait for |cb| to be called. It is not allowed to called
135   // SendPacket again until |cb| has been called. Any other errors that
136   // occur will be reported through side channels, in such cases, this function
137   // will return true indicating that the channel is not blocked.
138   virtual bool SendPacket(PacketRef packet, const base::Closure& cb) = 0;
139
140   // Returns the number of bytes ever sent.
141   virtual int64 GetBytesSent() = 0;
142
143   virtual ~PacketSender() {}
144 };
145
146 struct RtcpSenderInfo {
147   RtcpSenderInfo();
148   ~RtcpSenderInfo();
149   // First three members are used for lipsync.
150   // First two members are used for rtt.
151   uint32 ntp_seconds;
152   uint32 ntp_fraction;
153   uint32 rtp_timestamp;
154   uint32 send_packet_count;
155   size_t send_octet_count;
156 };
157
158 struct RtcpReportBlock {
159   RtcpReportBlock();
160   ~RtcpReportBlock();
161   uint32 remote_ssrc;  // SSRC of sender of this report.
162   uint32 media_ssrc;   // SSRC of the RTP packet sender.
163   uint8 fraction_lost;
164   uint32 cumulative_lost;  // 24 bits valid.
165   uint32 extended_high_sequence_number;
166   uint32 jitter;
167   uint32 last_sr;
168   uint32 delay_since_last_sr;
169 };
170
171 struct RtcpDlrrReportBlock {
172   RtcpDlrrReportBlock();
173   ~RtcpDlrrReportBlock();
174   uint32 last_rr;
175   uint32 delay_since_last_rr;
176 };
177
178 inline bool operator==(RtcpSenderInfo lhs, RtcpSenderInfo rhs) {
179   return lhs.ntp_seconds == rhs.ntp_seconds &&
180          lhs.ntp_fraction == rhs.ntp_fraction &&
181          lhs.rtp_timestamp == rhs.rtp_timestamp &&
182          lhs.send_packet_count == rhs.send_packet_count &&
183          lhs.send_octet_count == rhs.send_octet_count;
184 }
185
186 }  // namespace cast
187 }  // namespace media
188
189 #endif  // MEDIA_CAST_NET_CAST_TRANSPORT_CONFIG_H_