Skip to content

Commit 367c875

Browse files
authored
Merge pull request #96 from Shadowghost/cleanup
Add rules, fix issues and cleanup
2 parents 2a2cb3f + 4b51364 commit 367c875

92 files changed

Lines changed: 3186 additions & 1168 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 532 additions & 0 deletions
Large diffs are not rendered by default.

src/Jellyfin.Plugin.Dlna.Model/ContentFeatureBuilder.cs

Lines changed: 76 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#nullable disable
2-
#pragma warning disable CS1591
3-
41
using System;
52
using System.Collections.Generic;
63
using System.Globalization;
@@ -10,17 +7,29 @@
107

118
namespace Jellyfin.Plugin.Dlna.Model;
129

10+
/// <summary>
11+
/// Defines the <see cref="ContentFeatureBuilder" />.
12+
/// </summary>
1313
public static class ContentFeatureBuilder
1414
{
15+
/// <summary>
16+
/// Gets the image header.
17+
/// </summary>
18+
/// <param name="profile">The <see cref="DlnaDeviceProfile"/>.</param>
19+
/// <param name="container">The container.</param>
20+
/// <param name="width">The width.</param>
21+
/// <param name="height">The height.</param>
22+
/// <param name="isDirectStream">Value indicating wether the stream is direct.</param>
23+
/// <param name="orgPn">The orgPn.</param>
1524
public static string BuildImageHeader(
1625
DlnaDeviceProfile profile,
1726
string container,
1827
int? width,
1928
int? height,
2029
bool isDirectStream,
21-
string orgPn = null)
30+
string? orgPn = null)
2231
{
23-
string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetImageOrgOpValue();
32+
var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetImageOrgOpValue();
2433

2534
// 0 = native, 1 = transcoded
2635
var orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";
@@ -29,14 +38,14 @@ public static string BuildImageHeader(
2938
DlnaFlags.InteractiveTransferMode |
3039
DlnaFlags.DlnaV15;
3140

32-
string dlnaflags = string.Format(
41+
var dlnaflags = string.Format(
3342
CultureInfo.InvariantCulture,
3443
";DLNA.ORG_FLAGS={0}",
3544
DlnaMaps.FlagsToString(flagValue));
3645

3746
if (string.IsNullOrEmpty(orgPn))
3847
{
39-
ResponseProfile mediaProfile = profile.GetImageMediaProfile(
48+
ResponseProfile? mediaProfile = profile.GetImageMediaProfile(
4049
container,
4150
width,
4251
height);
@@ -57,10 +66,23 @@ public static string BuildImageHeader(
5766
return "DLNA.ORG_PN=" + orgPn + orgOp + orgCi + dlnaflags;
5867
}
5968

69+
/// <summary>
70+
/// Gets the audio header.
71+
/// </summary>
72+
/// <param name="profile">The <see cref="DlnaDeviceProfile"/>.</param>
73+
/// <param name="container">The container.</param>
74+
/// <param name="audioCodec">The codec.</param>
75+
/// <param name="audioBitrate">The bitrate.</param>
76+
/// <param name="audioSampleRate">The sample rate.</param>
77+
/// <param name="audioChannels">The channel count.</param>
78+
/// <param name="audioBitDepth">The bit depth.</param>
79+
/// <param name="isDirectStream">Value indicating wether the stream is direct.</param>
80+
/// <param name="runtimeTicks">The runtime ticks.</param>
81+
/// <param name="transcodeSeekInfo">The <see cref="TranscodeSeekInfo"/>.</param>
6082
public static string BuildAudioHeader(
6183
DlnaDeviceProfile profile,
62-
string container,
63-
string audioCodec,
84+
string? container,
85+
string? audioCodec,
6486
int? audioBitrate,
6587
int? audioSampleRate,
6688
int? audioChannels,
@@ -70,10 +92,10 @@ public static string BuildAudioHeader(
7092
TranscodeSeekInfo transcodeSeekInfo)
7193
{
7294
// first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none
73-
string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks > 0, isDirectStream, transcodeSeekInfo);
95+
var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks > 0, isDirectStream, transcodeSeekInfo);
7496

7597
// 0 = native, 1 = transcoded
76-
string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";
98+
var orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";
7799

78100
var flagValue = DlnaFlags.StreamingTransferMode |
79101
DlnaFlags.BackgroundTransferMode |
@@ -89,20 +111,20 @@ public static string BuildAudioHeader(
89111
// flagValue = flagValue | DlnaFlags.TimeBasedSeek;
90112
// }
91113

92-
string dlnaflags = string.Format(
114+
var dlnaflags = string.Format(
93115
CultureInfo.InvariantCulture,
94116
";DLNA.ORG_FLAGS={0}",
95117
DlnaMaps.FlagsToString(flagValue));
96118

97-
ResponseProfile mediaProfile = profile.GetAudioMediaProfile(
119+
ResponseProfile? mediaProfile = profile.GetAudioMediaProfile(
98120
container,
99121
audioCodec,
100122
audioChannels,
101123
audioBitrate,
102124
audioSampleRate,
103125
audioBitDepth);
104126

105-
string orgPn = mediaProfile?.OrgPn;
127+
var orgPn = mediaProfile?.OrgPn;
106128

107129
if (string.IsNullOrEmpty(orgPn))
108130
{
@@ -117,19 +139,46 @@ public static string BuildAudioHeader(
117139
return "DLNA.ORG_PN=" + orgPn + orgOp + orgCi + dlnaflags;
118140
}
119141

142+
/// <summary>
143+
/// Gets the video header.
144+
/// </summary>
145+
/// <param name="profile">The <see cref="DlnaDeviceProfile"/>.</param>
146+
/// <param name="container">The container.</param>
147+
/// <param name="videoCodec">The video codec.</param>
148+
/// <param name="audioCodec">The audio codec.</param>
149+
/// <param name="width">The width.</param>
150+
/// <param name="height">The height.</param>
151+
/// <param name="bitDepth">The bit depth.</param>
152+
/// <param name="videoBitrate">The video bitrate.</param>
153+
/// <param name="timestamp">The <see cref="TransportStreamTimestamp"/>.</param>
154+
/// <param name="isDirectStream">Value indicating wether the stream is direct.</param>
155+
/// <param name="runtimeTicks">The runtime ticks.</param>
156+
/// <param name="videoProfile">The video profile.</param>
157+
/// <param name="videoRangeType">The <see cref="VideoRangeType"/>.</param>
158+
/// <param name="videoLevel">The video level.</param>
159+
/// <param name="videoFramerate">The video framerate.</param>
160+
/// <param name="packetLength">The packet length.</param>
161+
/// <param name="transcodeSeekInfo">The <see cref="TranscodeSeekInfo"/>.</param>
162+
/// <param name="isAnamorphic">Value indicating wether the stream is anamorphic.</param>
163+
/// <param name="isInterlaced">Value indicating wether the stream is interlaced.</param>
164+
/// <param name="refFrames">The reference frames.</param>
165+
/// <param name="numVideoStreams">The number of video streams.</param>
166+
/// <param name="numAudioStreams">The number of audio streams.</param>
167+
/// <param name="videoCodecTag">The video codec tag.</param>
168+
/// <param name="isAvc">Value indicating wether the stream is AVC.</param>
120169
public static IEnumerable<string> BuildVideoHeader(
121170
DlnaDeviceProfile profile,
122-
string container,
123-
string videoCodec,
124-
string audioCodec,
171+
string? container,
172+
string? videoCodec,
173+
string? audioCodec,
125174
int? width,
126175
int? height,
127176
int? bitDepth,
128177
int? videoBitrate,
129178
TransportStreamTimestamp timestamp,
130179
bool isDirectStream,
131180
long? runtimeTicks,
132-
string videoProfile,
181+
string? videoProfile,
133182
VideoRangeType videoRangeType,
134183
double? videoLevel,
135184
float? videoFramerate,
@@ -140,14 +189,14 @@ public static IEnumerable<string> BuildVideoHeader(
140189
int? refFrames,
141190
int? numVideoStreams,
142191
int? numAudioStreams,
143-
string videoCodecTag,
192+
string? videoCodecTag,
144193
bool? isAvc)
145194
{
146195
// first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none
147-
string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks > 0, isDirectStream, transcodeSeekInfo);
196+
var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks > 0, isDirectStream, transcodeSeekInfo);
148197

149198
// 0 = native, 1 = transcoded
150-
string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";
199+
var orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";
151200

152201
var flagValue = DlnaFlags.StreamingTransferMode |
153202
DlnaFlags.BackgroundTransferMode |
@@ -165,12 +214,12 @@ public static IEnumerable<string> BuildVideoHeader(
165214
// flagValue = flagValue | DlnaFlags.TimeBasedSeek;
166215
// }
167216

168-
string dlnaflags = string.Format(
217+
var dlnaflags = string.Format(
169218
CultureInfo.InvariantCulture,
170219
";DLNA.ORG_FLAGS={0}",
171220
DlnaMaps.FlagsToString(flagValue));
172221

173-
ResponseProfile mediaProfile = profile.GetVideoMediaProfile(
222+
var mediaProfile = profile.GetVideoMediaProfile(
174223
container,
175224
audioCodec,
176225
videoCodec,
@@ -234,14 +283,14 @@ public static IEnumerable<string> BuildVideoHeader(
234283
return contentFeatureList;
235284
}
236285

237-
private static string GetImageOrgPnValue(string container, int? width, int? height)
286+
private static string? GetImageOrgPnValue(string container, int? width, int? height)
238287
{
239288
MediaFormatProfile? format = MediaFormatProfileResolver.ResolveImageFormat(container, width, height);
240289

241290
return format.HasValue ? format.Value.ToString() : null;
242291
}
243292

244-
private static string GetAudioOrgPnValue(string container, int? audioBitrate, int? audioSampleRate, int? audioChannels)
293+
private static string? GetAudioOrgPnValue(string? container, int? audioBitrate, int? audioSampleRate, int? audioChannels)
245294
{
246295
MediaFormatProfile? format = MediaFormatProfileResolver.ResolveAudioFormat(
247296
container,
@@ -252,8 +301,8 @@ private static string GetAudioOrgPnValue(string container, int? audioBitrate, in
252301
return format.HasValue ? format.Value.ToString() : null;
253302
}
254303

255-
private static MediaFormatProfile[] GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestamp)
304+
private static MediaFormatProfile[] GetVideoOrgPnValue(string? container, string? videoCodec, string? audioCodec, int? width, int? height, TransportStreamTimestamp timestamp)
256305
{
257306
return MediaFormatProfileResolver.ResolveVideoFormat(container, videoCodec, audioCodec, width, height, timestamp);
258307
}
259-
}
308+
}

src/Jellyfin.Plugin.Dlna.Model/DeviceIdentification.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
using System;
1+
#pragma warning disable CA1819 // Properties should not return arrays
22

33
namespace Jellyfin.Plugin.Dlna.Model;
44

5+
/// <summary>
6+
/// Defines the <see cref="DeviceIdentification" />.
7+
/// </summary>
58
public class DeviceIdentification
69
{
710
/// <summary>
@@ -56,5 +59,5 @@ public class DeviceIdentification
5659
/// Gets or sets the headers.
5760
/// </summary>
5861
/// <value>The headers.</value>
59-
public HttpHeaderInfo[] Headers { get; set; } = Array.Empty<HttpHeaderInfo>();
62+
public HttpHeaderInfo[] Headers { get; set; } = [];
6063
}

src/Jellyfin.Plugin.Dlna.Model/DeviceProfileInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Jellyfin.Plugin.Dlna.Model;
44

5+
/// <summary>
6+
/// Defines the <see cref="DeviceProfileInfo" />.
7+
/// </summary>
58
public class DeviceProfileInfo
69
{
710
/// <summary>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
namespace Jellyfin.Plugin.Dlna.Model;
22

3+
/// <summary>
4+
/// Defines the <see cref="DeviceProfileType" />.
5+
/// </summary>
36
public enum DeviceProfileType
47
{
8+
/// <summary>
9+
/// System profile.
10+
/// </summary>
511
System = 0,
12+
13+
/// <summary>
14+
/// User profile.
15+
/// </summary>
616
User = 1
717
}

src/Jellyfin.Plugin.Dlna.Model/DlnaDeviceProfile.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma warning disable CA1819 // Properties should not return arrays
2+
13
using System;
24
using System.ComponentModel;
35
using System.Linq;
@@ -10,6 +12,9 @@
1012

1113
namespace Jellyfin.Plugin.Dlna.Model;
1214

15+
/// <summary>
16+
/// Defines the <see cref="DlnaDeviceProfile" />.
17+
/// </summary>
1318
[XmlRoot("Profile")]
1419
public class DlnaDeviceProfile : DeviceProfile
1520
{
@@ -154,18 +159,18 @@ public class DlnaDeviceProfile : DeviceProfile
154159
/// <summary>
155160
/// Gets or sets the XmlRootAttributes.
156161
/// </summary>
157-
public XmlAttribute[] XmlRootAttributes { get; set; } = Array.Empty<XmlAttribute>();
162+
public XmlAttribute[] XmlRootAttributes { get; set; } = [];
158163

159164
/// <summary>
160165
/// Gets or sets the ResponseProfiles.
161166
/// </summary>
162-
public ResponseProfile[] ResponseProfiles { get; set; } = Array.Empty<ResponseProfile>();
167+
public ResponseProfile[] ResponseProfiles { get; set; } = [];
163168

164169
/// <summary>
165-
/// The GetSupportedMediaTypes.
170+
/// The supported media types.
166171
/// </summary>
167172
/// <returns>The .</returns>
168-
public MediaType[] GetSupportedMediaTypes()
173+
public MediaType[] FetchSupportedMediaTypes()
169174
{
170175
return ContainerHelper.Split(SupportedMediaTypes)
171176
.Select(m => Enum.TryParse<MediaType>(m, out var parsed) ? parsed : MediaType.Unknown)
@@ -265,8 +270,13 @@ public MediaType[] GetSupportedMediaTypes()
265270
/// <param name="width">The width.</param>
266271
/// <param name="height">The height.</param>
267272
/// <returns>The <see cref="ResponseProfile"/>.</returns>
268-
public ResponseProfile? GetImageMediaProfile(string container, int? width, int? height)
273+
public ResponseProfile? GetImageMediaProfile(string? container, int? width, int? height)
269274
{
275+
if (container is null)
276+
{
277+
return null;
278+
}
279+
270280
foreach (var i in ResponseProfiles)
271281
{
272282
if (i.Type != DlnaProfileType.Photo)

0 commit comments

Comments
 (0)