-
Notifications
You must be signed in to change notification settings - Fork 408
/
IMediaSession.cs
153 lines (136 loc) · 6.31 KB
/
IMediaSession.cs
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//-----------------------------------------------------------------------------
// Filename: IMediaSession.cs
//
// Description: An interface for managing the Media in a SIP session
//
// Author(s):
// Yizchok G.
//
// History:
// 12/23/2019 Yitzchok Created.
//
// License:
// BSD 3-Clause "New" or "Revised" License, see included LICENSE.md file.
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using SIPSorcery.Net;
namespace SIPSorcery.SIP.App
{
/// <summary>
/// The type of the SDP packet being set.
/// </summary>
public enum SdpType
{
answer = 0,
offer = 1
}
/// <summary>
/// Offering and Answering SDP messages so that it can be
/// signaled to the other party using the SIPUserAgent.
///
/// The implementing class is responsible for ensuring that the client
/// can send media to the other party including creating and managing
/// the RTP streams and processing the audio and video.
/// </summary>
public interface IMediaSession
{
/// <summary>
/// Indicates whether the session supports audio.
/// </summary>
bool HasAudio { get; }
/// <summary>
/// Indicates whether the session supports video.
/// </summary>
bool HasVideo { get; }
/// <summary>
/// Indicates whether the session has been closed.
/// </summary>
bool IsClosed { get; }
/// <summary>
/// The SDP description from the remote party describing
/// their audio/video sending and receive capabilities.
/// </summary>
SDP RemoteDescription { get; }
/// <summary>
/// Set if the session has been bound to a specific IP address.
/// Normally not required but some esoteric call or network set ups may need.
/// </summary>
IPAddress RtpBindAddress { get; }
/// <summary>
/// Fired when the RTP channel is closed.
/// </summary>
event Action<string> OnRtpClosed;
/// <summary>
/// Fired when an RTP event (typically representing a DTMF tone) is
/// detected.
/// </summary>
event Action<IPEndPoint, RTPEvent, RTPHeader> OnRtpEvent;
/// <summary>
/// Fired when no RTP or RTCP packets are received for a pre-defined period (typically 30s).
/// </summary>
event Action<SDPMediaTypesEnum> OnTimeout;
/// <summary>
/// Creates a new SDP offer based on the local media tracks in the session.
/// Calling this method does NOT change the state of the media tracks. It is
/// safe to call at any time if a session description of the local media state is
/// required.
/// </summary>
/// <param name="connectionAddress">Optional. If set this address will be used
/// as the Connection address in the SDP offer. If not set an attempt will be
/// made to determine the best matching address.</param>
/// <returns>A new SDP offer representing the session's local media tracks.</returns>
SDP CreateOffer(IPAddress connectionAddress);
/// <summary>
/// Sets the remote description. Calling this method can result in the local
/// media tracks being disabled if not supported or setting the RTP/RTCP end points
/// if they are.
/// </summary>
/// <param name="sdpType">Whether the SDP being set is an offer or answer.</param>
/// <param name="sessionDescription">The SDP description from the remote party.</param>
/// <returns>If successful an OK enum result. If not an enum result indicating the
/// failure cause.</returns>
SetDescriptionResultEnum SetRemoteDescription(SdpType sdpType, SDP sessionDescription);
/// <summary>
/// Generates an SDP answer to an offer based on the local media tracks. Calling
/// this method does NOT result in any changes to the local tracks. To apply the
/// changes the SetRemoteDescription method must be called.
/// </summary>
/// <param name="connectionAddress">Optional. If set this address will be used as
/// the SDP Connection address. If not specified the Operating System routing table
/// will be used to lookup the address used to connect to the SDP connection address
/// from the remote offer.</param>
/// <returns>An SDP answer matching the offer and the local media tracks contained
/// in the session.</returns>
SDP CreateAnswer(IPAddress connectionAddress);
/// <summary>
/// Needs to be called prior to sending media. Performs any set up tasks such as
/// starting audio/video capture devices and starting RTCP reporting.
/// </summary>
Task Start();
/// <summary>
/// Sets the stream status on all local audio or all video media track.
/// </summary>
/// <param name="kind">The type of the media track. Must be audio or video.</param>
/// <param name="status">The stream status for the media track.</param>
void SetMediaStreamStatus(SDPMediaTypesEnum kind, MediaStreamStatusEnum status);
/// <summary>
/// Attempts to send a DTMF tone to the remote party.
/// </summary>
/// <param name="tone">The digit representing the DTMF tone to send.</param>
/// <param name="ct">A cancellation token that should be set if the DTMF send should be
/// cancelled before completing. Depending on the duration a DTMF send can require
/// multiple RTP packets. This token can be used to cancel any further RTP packets
/// being sent for the tone.</param>
Task SendDtmf(byte tone, CancellationToken ct);
/// <summary>
/// Closes the session. This will stop any audio/video capturing and rendering devices as
/// well as the RTP and RTCP sessions and sockets.
/// </summary>
/// <param name="reason">Optional. A descriptive reason for closing the session.</param>
void Close(string reason);
}
}