1// Copyright 2013 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_CAST_CONFIG_H_
6#define MEDIA_CAST_CAST_CONFIG_H_
7
8#include <list>
9#include <string>
10#include <vector>
11
12#include "base/basictypes.h"
13#include "base/callback.h"
14#include "base/memory/ref_counted.h"
15#include "base/memory/shared_memory.h"
16#include "base/single_thread_task_runner.h"
17#include "media/cast/cast_defines.h"
18#include "media/cast/transport/cast_transport_config.h"
19
20namespace media {
21class VideoEncodeAccelerator;
22
23namespace cast {
24
25enum RtcpMode {
26  kRtcpCompound,     // Compound RTCP mode is described by RFC 4585.
27  kRtcpReducedSize,  // Reduced-size RTCP mode is described by RFC 5506.
28};
29
30// TODO(miu): Merge AudioSenderConfig and VideoSenderConfig and make their
31// naming/documentation consistent with FrameReceiverConfig.
32struct AudioSenderConfig {
33  AudioSenderConfig();
34
35  // The sender ssrc is in rtp_config.ssrc.
36  uint32 incoming_feedback_ssrc;
37
38  int rtcp_interval;
39  std::string rtcp_c_name;
40  RtcpMode rtcp_mode;
41
42  transport::RtpConfig rtp_config;
43
44  bool use_external_encoder;
45  int frequency;
46  int channels;
47  int bitrate;  // Set to <= 0 for "auto variable bitrate" (libopus knows best).
48  transport::AudioCodec codec;
49};
50
51struct VideoSenderConfig {
52  VideoSenderConfig();
53
54  // The sender ssrc is in rtp_config.ssrc.
55  uint32 incoming_feedback_ssrc;
56
57  int rtcp_interval;
58  std::string rtcp_c_name;
59  RtcpMode rtcp_mode;
60
61  transport::RtpConfig rtp_config;
62
63  bool use_external_encoder;
64  int width;  // Incoming frames will be scaled to this size.
65  int height;
66
67  float congestion_control_back_off;
68  int max_bitrate;
69  int min_bitrate;
70  int start_bitrate;
71  int max_qp;
72  int min_qp;
73  int max_frame_rate;
74  int max_number_of_video_buffers_used;  // Max value depend on codec.
75  transport::VideoCodec codec;
76  int number_of_encode_threads;
77};
78
79// TODO(miu): Naming and minor type changes are badly needed in a later CL.
80struct FrameReceiverConfig {
81  FrameReceiverConfig();
82  ~FrameReceiverConfig();
83
84  // The receiver's SSRC identifier.
85  uint32 feedback_ssrc;  // TODO(miu): Rename to receiver_ssrc for clarity.
86
87  // The sender's SSRC identifier.
88  uint32 incoming_ssrc;  // TODO(miu): Rename to sender_ssrc for clarity.
89
90  // Mean interval (in milliseconds) between RTCP reports.
91  // TODO(miu): Remove this since it's never not kDefaultRtcpIntervalMs.
92  int rtcp_interval;
93
94  // CNAME representing this receiver.
95  // TODO(miu): Remove this since it should be derived elsewhere (probably in
96  // the transport layer).
97  std::string rtcp_c_name;
98
99  // Determines amount of detail in RTCP reports.
100  // TODO(miu): Remove this since it's never anything but kRtcpReducedSize.
101  RtcpMode rtcp_mode;
102
103  // The total amount of time between a frame's capture/recording on the sender
104  // and its playback on the receiver (i.e., shown to a user).  This is fixed as
105  // a value large enough to give the system sufficient time to encode,
106  // transmit/retransmit, receive, decode, and render; given its run-time
107  // environment (sender/receiver hardware performance, network conditions,
108  // etc.).
109  int rtp_max_delay_ms;  // TODO(miu): Change to TimeDelta target_playout_delay.
110
111  // RTP payload type enum: Specifies the type/encoding of frame data.
112  int rtp_payload_type;
113
114  // RTP timebase: The number of RTP units advanced per one second.  For audio,
115  // this is the sampling rate.  For video, by convention, this is 90 kHz.
116  int frequency;  // TODO(miu): Rename to rtp_timebase for clarity.
117
118  // Number of channels.  For audio, this is normally 2.  For video, this must
119  // be 1 as Cast does not have support for stereoscopic video.
120  int channels;
121
122  // The target frame rate.  For audio, this is normally 100 (i.e., frames have
123  // a duration of 10ms each).  For video, this is normally 30, but any frame
124  // rate is supported.
125  int max_frame_rate;  // TODO(miu): Rename to target_frame_rate.
126
127  // Codec used for the compression of signal data.
128  // TODO(miu): Merge the AudioCodec and VideoCodec enums into one so this union
129  // is not necessary.
130  union MergedCodecPlaceholder {
131    transport::AudioCodec audio;
132    transport::VideoCodec video;
133    MergedCodecPlaceholder() : audio(transport::kUnknownAudioCodec) {}
134  } codec;
135
136  // The AES crypto key and initialization vector.  Each of these strings
137  // contains the data in binary form, of size kAesKeySize.  If they are empty
138  // strings, crypto is not being used.
139  std::string aes_key;
140  std::string aes_iv_mask;
141};
142
143// import from media::cast::transport
144typedef transport::Packet Packet;
145typedef transport::PacketList PacketList;
146
147typedef base::Callback<void(CastInitializationStatus)>
148    CastInitializationCallback;
149
150typedef base::Callback<void(scoped_refptr<base::SingleThreadTaskRunner>,
151                            scoped_ptr<media::VideoEncodeAccelerator>)>
152    ReceiveVideoEncodeAcceleratorCallback;
153typedef base::Callback<void(const ReceiveVideoEncodeAcceleratorCallback&)>
154    CreateVideoEncodeAcceleratorCallback;
155
156typedef base::Callback<void(scoped_ptr<base::SharedMemory>)>
157    ReceiveVideoEncodeMemoryCallback;
158typedef base::Callback<void(size_t size,
159                            const ReceiveVideoEncodeMemoryCallback&)>
160    CreateVideoEncodeMemoryCallback;
161
162}  // namespace cast
163}  // namespace media
164
165#endif  // MEDIA_CAST_CAST_CONFIG_H_
166