1 /*
2  *  Copyright 2004 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef PC_RTCP_MUX_FILTER_H_
12 #define PC_RTCP_MUX_FILTER_H_
13 
14 #include "pc/session_description.h"
15 
16 namespace cricket {
17 
18 // RTCP Muxer, as defined in RFC 5761 (http://tools.ietf.org/html/rfc5761)
19 class RtcpMuxFilter {
20  public:
21   RtcpMuxFilter();
22 
23   // Whether RTCP mux has been negotiated with a final answer (not provisional).
24   bool IsFullyActive() const;
25 
26   // Whether RTCP mux has been negotiated with a provisional answer; this means
27   // a later answer could disable RTCP mux, and so the RTCP transport should
28   // not be disposed yet.
29   bool IsProvisionallyActive() const;
30 
31   // Whether the filter is active, i.e. has RTCP mux been properly negotiated,
32   // either with a final or provisional answer.
33   bool IsActive() const;
34 
35   // Make the filter active (fully, not provisionally) regardless of the
36   // current state. This should be used when an endpoint *requires* RTCP mux.
37   void SetActive();
38 
39   // Specifies whether the offer indicates the use of RTCP mux.
40   bool SetOffer(bool offer_enable, ContentSource src);
41 
42   // Specifies whether the provisional answer indicates the use of RTCP mux.
43   bool SetProvisionalAnswer(bool answer_enable, ContentSource src);
44 
45   // Specifies whether the answer indicates the use of RTCP mux.
46   bool SetAnswer(bool answer_enable, ContentSource src);
47 
48  private:
49   bool ExpectOffer(bool offer_enable, ContentSource source);
50   bool ExpectAnswer(ContentSource source);
51   enum State {
52     // RTCP mux filter unused.
53     ST_INIT,
54     // Offer with RTCP mux enabled received.
55     // RTCP mux filter is not active.
56     ST_RECEIVEDOFFER,
57     // Offer with RTCP mux enabled sent.
58     // RTCP mux filter can demux incoming packets but is not active.
59     ST_SENTOFFER,
60     // RTCP mux filter is active but the sent answer is only provisional.
61     // When the final answer is set, the state transitions to ST_ACTIVE or
62     // ST_INIT.
63     ST_SENTPRANSWER,
64     // RTCP mux filter is active but the received answer is only provisional.
65     // When the final answer is set, the state transitions to ST_ACTIVE or
66     // ST_INIT.
67     ST_RECEIVEDPRANSWER,
68     // Offer and answer set, RTCP mux enabled. It is not possible to de-activate
69     // the filter.
70     ST_ACTIVE
71   };
72   State state_;
73   bool offer_enable_;
74 };
75 
76 }  // namespace cricket
77 
78 #endif  // PC_RTCP_MUX_FILTER_H_
79