aboutsummaryrefslogtreecommitdiff
path: root/cast/streaming/answer_messages.h
blob: a2cb76587463abf0d9c82522b0a047a5c21a1ae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CAST_STREAMING_ANSWER_MESSAGES_H_
#define CAST_STREAMING_ANSWER_MESSAGES_H_

#include <array>
#include <chrono>  // NOLINT
#include <cstdint>
#include <initializer_list>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "cast/streaming/offer_messages.h"
#include "cast/streaming/ssrc.h"
#include "json/value.h"
#include "platform/base/error.h"

namespace cast {
namespace streaming {

struct AudioConstraints {
  int max_sample_rate = 0;
  int max_channels = 0;
  // Technically optional, sender will assume 32kbps if omitted.
  int min_bit_rate = 0;
  int max_bit_rate = 0;
  std::chrono::milliseconds max_delay = {};

  openscreen::ErrorOr<Json::Value> ToJson() const;
};

struct Dimensions {
  int width = 0;
  int height = 0;
  int frame_rate_numerator = 0;
  int frame_rate_denominator = 0;

  openscreen::ErrorOr<Json::Value> ToJson() const;
};

struct VideoConstraints {
  double max_pixels_per_second = {};
  Dimensions min_dimensions = {};
  Dimensions max_dimensions = {};
  // Technically optional, sender will assume 300kbps if omitted.
  int min_bit_rate = 0;
  int max_bit_rate = 0;
  std::chrono::milliseconds max_delay = {};

  openscreen::ErrorOr<Json::Value> ToJson() const;
};

struct Constraints {
  AudioConstraints audio;
  VideoConstraints video;

  openscreen::ErrorOr<Json::Value> ToJson() const;
};

// Decides whether the Sender scales and letterboxes content to 16:9, or if
// it may send video frames of any arbitrary size and the Receiver must
// handle the presentation details.
enum class AspectRatioConstraint : uint8_t { kVariable = 0, kFixed };

struct AspectRatio {
  int width = 0;
  int height = 0;
};

struct DisplayDescription {
  // May exceed, be the same, or less than those mentioned in the
  // video constraints.
  Dimensions dimensions;
  AspectRatio aspect_ratio = {};
  AspectRatioConstraint aspect_ratio_constraint = {};

  openscreen::ErrorOr<Json::Value> ToJson() const;
};

struct Answer {
  CastMode cast_mode = {};
  int udp_port = 0;
  std::vector<int> send_indexes;
  std::vector<Ssrc> ssrcs;

  // Constraints and display descriptions are optional fields, and maybe null in
  // the valid case.
  absl::optional<Constraints> constraints;
  absl::optional<DisplayDescription> display;
  std::vector<int> receiver_rtcp_event_log;
  std::vector<int> receiver_rtcp_dscp;
  bool supports_wifi_status_reporting = false;

  // RTP extensions should be empty, but not null.
  std::vector<std::string> rtp_extensions = {};

  // ToJson performs a standard serialization, returning an error if this
  // instance failed to serialize properly.
  openscreen::ErrorOr<Json::Value> ToJson() const;

  // In constrast to ToJson, ToAnswerMessage performs a successful serialization
  // even if the answer object is malformed, by complying to the spec's
  // error answer message format in this case.
  Json::Value ToAnswerMessage() const;
};

// Helper method that creates an invalid Answer response. Exposed publicly
// here as it is called in ToAnswerMessage(), but can also be called by
// the receiver session.
Json::Value CreateInvalidAnswer(openscreen::Error error);

}  // namespace streaming
}  // namespace cast

#endif  // CAST_STREAMING_ANSWER_MESSAGES_H_