Upstream version 5.34.104.0
[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 #include "net/base/ip_endpoint.h"
16
17 namespace media {
18 namespace cast {
19 namespace transport {
20
21 enum RtcpMode {
22   kRtcpCompound,     // Compound RTCP mode is described by RFC 4585.
23   kRtcpReducedSize,  // Reduced-size RTCP mode is described by RFC 5506.
24 };
25
26 enum VideoCodec { kVp8, kH264, };
27
28 enum AudioCodec { kOpus, kPcm16, kExternalAudio, };
29
30 struct RtpConfig {
31   RtpConfig();
32   int history_ms;  // The time RTP packets are stored for retransmissions.
33   int max_delay_ms;
34   int payload_type;
35 };
36
37 struct CastTransportConfig {
38   CastTransportConfig();
39   ~CastTransportConfig();
40
41   // Transport: Local receiver.
42   net::IPEndPoint receiver_endpoint;
43   net::IPEndPoint local_endpoint;
44
45   uint32 audio_ssrc;
46   uint32 video_ssrc;
47
48   VideoCodec video_codec;
49   AudioCodec audio_codec;
50
51   // RTP.
52   RtpConfig audio_rtp_config;
53   RtpConfig video_rtp_config;
54
55   int audio_frequency;
56   int audio_channels;
57
58   std::string aes_key;      // Binary string of size kAesKeySize.
59   std::string aes_iv_mask;  // Binary string of size kAesBlockSize.
60 };
61
62 struct EncodedVideoFrame {
63   EncodedVideoFrame();
64   ~EncodedVideoFrame();
65
66   VideoCodec codec;
67   bool key_frame;
68   uint32 frame_id;
69   uint32 last_referenced_frame_id;
70   uint32 rtp_timestamp;
71   std::string data;
72 };
73
74 struct EncodedAudioFrame {
75   EncodedAudioFrame();
76   ~EncodedAudioFrame();
77
78   AudioCodec codec;
79   uint32 frame_id;  // Needed to release the frame.
80   uint32 rtp_timestamp;
81   // Support for max sampling rate of 48KHz, 2 channels, 100 ms duration.
82   static const int kMaxNumberOfSamples = 48 * 2 * 100;
83   std::string data;
84 };
85
86 typedef std::vector<uint8> Packet;
87 typedef std::vector<Packet> PacketList;
88
89 typedef base::Callback<void(scoped_ptr<Packet> packet)> PacketReceiverCallback;
90
91 class PacketSender {
92  public:
93   // All packets to be sent to the network will be delivered via these
94   // functions.
95   virtual bool SendPacket(const transport::Packet& packet) = 0;
96
97   virtual ~PacketSender() {}
98 };
99
100 // Log messages form sender to receiver.
101 // TODO(mikhal): Refactor to Chromium style (MACRO_STYLE).
102 enum RtcpSenderFrameStatus {
103   kRtcpSenderFrameStatusUnknown = 0,
104   kRtcpSenderFrameStatusDroppedByEncoder = 1,
105   kRtcpSenderFrameStatusDroppedByFlowControl = 2,
106   kRtcpSenderFrameStatusSentToNetwork = 3,
107 };
108
109 struct RtcpSenderFrameLogMessage {
110   RtcpSenderFrameLogMessage();
111   ~RtcpSenderFrameLogMessage();
112   RtcpSenderFrameStatus frame_status;
113   uint32 rtp_timestamp;
114 };
115
116 typedef std::vector<RtcpSenderFrameLogMessage> RtcpSenderLogMessage;
117
118 struct RtcpSenderInfo {
119   RtcpSenderInfo();
120   ~RtcpSenderInfo();
121   // First three members are used for lipsync.
122   // First two members are used for rtt.
123   uint32 ntp_seconds;
124   uint32 ntp_fraction;
125   uint32 rtp_timestamp;
126   uint32 send_packet_count;
127   size_t send_octet_count;
128 };
129
130 struct RtcpReportBlock {
131   RtcpReportBlock();
132   ~RtcpReportBlock();
133   uint32 remote_ssrc;  // SSRC of sender of this report.
134   uint32 media_ssrc;   // SSRC of the RTP packet sender.
135   uint8 fraction_lost;
136   uint32 cumulative_lost;  // 24 bits valid.
137   uint32 extended_high_sequence_number;
138   uint32 jitter;
139   uint32 last_sr;
140   uint32 delay_since_last_sr;
141 };
142
143 struct RtcpDlrrReportBlock {
144   RtcpDlrrReportBlock();
145   ~RtcpDlrrReportBlock();
146   uint32 last_rr;
147   uint32 delay_since_last_rr;
148 };
149
150 // This is only needed because IPC messages don't support more than
151 // 5 arguments.
152 struct SendRtcpFromRtpSenderData {
153   SendRtcpFromRtpSenderData();
154   ~SendRtcpFromRtpSenderData();
155   uint32 packet_type_flags;
156   uint32 sending_ssrc;
157   std::string c_name;
158 };
159
160 inline bool operator==(RtcpSenderInfo lhs, RtcpSenderInfo rhs) {
161   return lhs.ntp_seconds == rhs.ntp_seconds &&
162          lhs.ntp_fraction == rhs.ntp_fraction &&
163          lhs.rtp_timestamp == rhs.rtp_timestamp &&
164          lhs.send_packet_count == rhs.send_packet_count &&
165          lhs.send_octet_count == rhs.send_octet_count;
166 }
167
168 }  // namespace transport
169 }  // namespace cast
170 }  // namespace media
171
172 #endif  // MEDIA_CAST_TRANSPORT_CAST_TRANSPORT_CONFIG_H_