forked from JMS-1/DVB.NET---VCR.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataGraph.Tuning.cs
More file actions
171 lines (148 loc) · 6.46 KB
/
DataGraph.Tuning.cs
File metadata and controls
171 lines (148 loc) · 6.46 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using JMS.DVB.DeviceAccess.Pipeline;
using JMS.DVB.DeviceAccess.Interfaces;
namespace JMS.DVB.DeviceAccess
{
partial class DataGraph
{
/// <summary>
/// Enthält alle Informationen, die während einer Auswahl einer Quellgruppe benötigt werden.
/// </summary>
public partial class TuneToken : PipelineToken<TuneToken>, IDisposable
{
/// <summary>
/// Die Anfrage zum Wechseln der Quellgruppe.
/// </summary>
private ITuneRequest m_Request;
/// <summary>
/// Meldet die Anfrage zum Wechseln der Quellgruppe.
/// </summary>
public ITuneRequest TuneRequest => m_Request;
/// <summary>
/// Der Ursprung der Quellegruppe - zurzeit nur für den Satellitenempfang von Bedeutung.
/// </summary>
public GroupLocation GroupLocation { get; }
/// <summary>
/// Die neu anzuwählende Quellgruppe.
/// </summary>
public SourceGroup SourceGroup { get; }
/// <summary>
/// Für den Fall des Empfangs über Satellite die zugehörige DiSEqC Steuermeldung.
/// </summary>
public StandardDiSEqC DiSEqCMessage { get; private set; }
/// <summary>
/// Erzeugt eine neue Beschreibung.
/// </summary>
/// <param name="pipeline">Die zugehörige Gesamtliste aller Aktionen gleicher Art.</param>
/// <param name="location">Der Ursprung für die angegebene Quellgruppe.</param>
/// <param name="group">Die neue Quellgruppe.</param>
private TuneToken( ActionPipeline<TuneToken> pipeline, GroupLocation location, SourceGroup group )
: base( pipeline )
{
// Remember
GroupLocation = location;
SourceGroup = group;
}
/// <summary>
/// Erzeugt ein neue Zustandsinformation.
/// </summary>
/// <param name="pipeline">Die zugehörige Gesamtliste aller Aktionen gleicher Art.</param>
/// <param name="location">Der Ursprung für die angegebene Quellgruppe.</param>
/// <param name="group">Die neue Quellgruppe.</param>
/// <returns>Die gewünschte Information.</returns>
/// <exception cref="ArgumentNullException">Es wurde kein Graph übergeben.</exception>
internal static TuneToken Create( ActionPipeline<TuneToken> pipeline, GroupLocation location, SourceGroup group )
{
// Create new
var token = new TuneToken( pipeline, location, group );
// Configure
IDVBTuningSpace2 tuningSpace;
Action<ILocator> initializer;
switch (pipeline.Graph.DVBType)
{
case DVBSystemType.Terrestrial: tuningSpace = token.PrepareTerrestrial( out initializer ); break;
case DVBSystemType.Satellite: tuningSpace = token.PrepareSatellite( out initializer ); break;
case DVBSystemType.Cable: tuningSpace = token.PrepareCable( out initializer ); break;
default: throw new NotImplementedException( pipeline.Graph.DVBType.ToString() );
}
// With cleanup
try
{
// Create a new tune request
token.CreateTuneRequest( tuningSpace, initializer );
}
finally
{
// No longer used
BDAEnvironment.Release( ref tuningSpace );
}
// Report
return token;
}
/// <summary>
/// Erzeugt die eigentliche Anfrage zum Wechseln der Quellgruppe.
/// </summary>
/// <param name="tuningSpace">Der zu verwendende Namensraum.</param>
/// <param name="initializer">Methode zur Übertragung der aktuellen Quellgruppenparameter.</param>
private void CreateTuneRequest( IDVBTuningSpace2 tuningSpace, Action<ILocator> initializer )
{
// Create from tuning space
m_Request = tuningSpace.CreateTuneRequest();
// Reset internally - just in case
m_Request.ONID = -1;
m_Request.TSID = -1;
m_Request.SID = -1;
// Attach to the default locator
var @default = tuningSpace.DefaultLocator;
try
{
// Clone the default locator
var locator = @default.Clone();
try
{
// Set it up
initializer?.Invoke( locator );
// Attach locator
m_Request.Locator = locator;
}
finally
{
// Detach from clone
BDAEnvironment.Release( ref locator );
}
}
finally
{
// Detach
BDAEnvironment.Release( ref @default );
}
}
#region IDisposable Members
/// <summary>
/// Beendet die Nutzung dieser Instanz endgültig.
/// </summary>
public void Dispose() => BDAEnvironment.Release( ref m_Request );
#endregion
}
/// <summary>
/// Die für die Auswahl der Quellgruppe verantwortliche Aktionslist.
/// </summary>
public ActionPipeline<TuneToken> TunePipeline { get; }
/// <summary>
/// Wechselt die Quellgruppe.
/// </summary>
/// <param name="token">Die Informationen zur neuen Quellgruppe.</param>
/// <returns>Meldet, wie die Bearbeitung fortgesetzt werden soll.</returns>
private PipelineResult SetTuneRequest( TuneToken token )
{
// Ignore termination
if (token == null)
return PipelineResult.Continue;
// Connect the request to the network provider
using (var provider = NetworkProvider.MarshalToManaged())
((ITuner) provider.Object).TuneRequest = token.TuneRequest;
// Now run post processings
return PipelineResult.Continue;
}
}
}