15015cdba06f94da5aa4b8a9763647785e1d9dbf
[platform/framework/web/crosswalk.git] / src / media / cast / transport / 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_TRANSPORT_CAST_TRANSPORT_CONFIG_H_
6 #define MEDIA_CAST_TRANSPORT_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/ref_counted.h"
14 #include "media/cast/transport/cast_transport_defines.h"
15
16 namespace media {
17 namespace cast {
18 namespace transport {
19
20 enum RtcpMode {
21   kRtcpCompound,  // Compound RTCP mode is described by RFC 4585.
22   kRtcpReducedSize,  // Reduced-size RTCP mode is described by RFC 5506.
23 };
24
25 enum VideoCodec {
26   kVp8,
27   kH264,
28 };
29
30 enum AudioCodec {
31   kOpus,
32   kPcm16,
33   kExternalAudio,
34 };
35
36 struct CastTransportConfig {
37   CastTransportConfig();
38   ~CastTransportConfig();
39
40   // Transport: Local receiver.
41   std::string receiver_ip_address;
42   std::string local_ip_address;
43   int receive_port;
44   int send_port;
45
46   uint32 audio_ssrc;
47   uint32 video_ssrc;
48
49   VideoCodec video_codec;
50   AudioCodec audio_codec;
51
52   // RTP.
53   int audio_rtp_history_ms;
54   int video_rtp_history_ms;
55   int audio_rtp_max_delay_ms;
56   int video_rtp_max_delay_ms;
57   int audio_rtp_payload_type;
58   int video_rtp_payload_type;
59
60   int audio_frequency;
61   int audio_channels;
62
63   std::string aes_key;  // Binary string of size kAesKeySize.
64   std::string aes_iv_mask;  // Binary string of size kAesBlockSize.
65 };
66
67 struct EncodedVideoFrame {
68   EncodedVideoFrame();
69   ~EncodedVideoFrame();
70
71   VideoCodec codec;
72   bool key_frame;
73   uint32 frame_id;
74   uint32 last_referenced_frame_id;
75   std::string data;
76 };
77
78 struct EncodedAudioFrame {
79   EncodedAudioFrame();
80   ~EncodedAudioFrame();
81
82   AudioCodec codec;
83   uint32 frame_id;  // Needed to release the frame.
84   int samples;  // Needed send side to advance the RTP timestamp.
85                 // Not used receive side.
86   // Support for max sampling rate of 48KHz, 2 channels, 100 ms duration.
87   static const int kMaxNumberOfSamples = 48 * 2 * 100;
88   std::string data;
89 };
90
91 typedef std::vector<uint8> Packet;
92 typedef std::vector<Packet> PacketList;
93
94 class PacketReceiver : public base::RefCountedThreadSafe<PacketReceiver> {
95  public:
96   // All packets received from the network should be delivered via this
97   // function.
98   virtual void ReceivedPacket(const uint8* packet, size_t length,
99                               const base::Closure callback) = 0;
100
101   static void DeletePacket(const uint8* packet);
102
103  protected:
104   virtual ~PacketReceiver() {}
105
106  private:
107   friend class base::RefCountedThreadSafe<PacketReceiver>;
108 };
109
110 class PacketSender {
111  public:
112   // All packets to be sent to the network will be delivered via these
113   // functions.
114   virtual bool SendPacket(const transport::Packet& packet) = 0;
115
116   virtual ~PacketSender() {}
117 };
118
119 // Log messages form sender to receiver.
120 // TODO(mikhal): Refactor to Chromium style (MACRO_STYLE).
121 enum RtcpSenderFrameStatus {
122   kRtcpSenderFrameStatusUnknown = 0,
123   kRtcpSenderFrameStatusDroppedByEncoder = 1,
124   kRtcpSenderFrameStatusDroppedByFlowControl = 2,
125   kRtcpSenderFrameStatusSentToNetwork = 3,
126 };
127
128 struct RtcpSenderFrameLogMessage {
129   RtcpSenderFrameLogMessage();
130   ~RtcpSenderFrameLogMessage();
131   RtcpSenderFrameStatus frame_status;
132   uint32 rtp_timestamp;
133 };
134
135 typedef std::list<RtcpSenderFrameLogMessage> RtcpSenderLogMessage;
136
137 struct RtcpSenderInfo {
138   RtcpSenderInfo();
139   ~RtcpSenderInfo();
140   // First three members are used for lipsync.
141   // First two members are used for rtt.
142   uint32 ntp_seconds;
143   uint32 ntp_fraction;
144   uint32 rtp_timestamp;
145   uint32 send_packet_count;
146   size_t send_octet_count;
147 };
148
149 struct RtcpReportBlock {
150   RtcpReportBlock();
151   ~RtcpReportBlock();
152   uint32 remote_ssrc;  // SSRC of sender of this report.
153   uint32 media_ssrc;  // SSRC of the RTP packet sender.
154   uint8 fraction_lost;
155   uint32 cumulative_lost;  // 24 bits valid.
156   uint32 extended_high_sequence_number;
157   uint32 jitter;
158   uint32 last_sr;
159   uint32 delay_since_last_sr;
160 };
161
162 struct RtcpDlrrReportBlock {
163   RtcpDlrrReportBlock();
164   ~RtcpDlrrReportBlock();
165   uint32 last_rr;
166   uint32 delay_since_last_rr;
167 };
168
169 inline bool operator==(RtcpSenderInfo lhs, RtcpSenderInfo rhs) {
170   return lhs.ntp_seconds == rhs.ntp_seconds &&
171       lhs.ntp_fraction == rhs.ntp_fraction &&
172       lhs.rtp_timestamp == rhs.rtp_timestamp &&
173       lhs.send_packet_count == rhs.send_packet_count &&
174       lhs.send_octet_count == rhs.send_octet_count;
175 }
176
177 }  // namespace transport
178 }  // namespace cast
179 }  // namespace media
180
181 #endif // MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_CONFIG_H_