Merge pull request #2266 from Bond-009/nullref2

Try to fix nullreff
pull/2278/head
dkanada 5 years ago committed by GitHub
commit b1e76db21e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -264,41 +264,26 @@ namespace MediaBrowser.Api.Playback
return ToOptimizedResult(result); return ToOptimizedResult(result);
} }
private T Clone<T>(T obj)
{
// Since we're going to be setting properties on MediaSourceInfos that come out of _mediaSourceManager, we should clone it
// Should we move this directly into MediaSourceManager?
var json = JsonSerializer.SerializeToUtf8Bytes(obj);
return JsonSerializer.Deserialize<T>(json);
}
private async Task<PlaybackInfoResponse> GetPlaybackInfo(Guid id, Guid userId, string[] supportedLiveMediaTypes, string mediaSourceId = null, string liveStreamId = null) private async Task<PlaybackInfoResponse> GetPlaybackInfo(Guid id, Guid userId, string[] supportedLiveMediaTypes, string mediaSourceId = null, string liveStreamId = null)
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
var item = _libraryManager.GetItemById(id); var item = _libraryManager.GetItemById(id);
var result = new PlaybackInfoResponse(); var result = new PlaybackInfoResponse();
MediaSourceInfo[] mediaSources;
if (string.IsNullOrWhiteSpace(liveStreamId)) if (string.IsNullOrWhiteSpace(liveStreamId))
{ {
IEnumerable<MediaSourceInfo> mediaSources;
try
{
// TODO handle supportedLiveMediaTypes ?
mediaSources = await _mediaSourceManager.GetPlaybackMediaSources(item, user, true, false, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
mediaSources = new List<MediaSourceInfo>();
Logger.LogError(ex, "Could not find media sources for item id {id}", id);
// TODO PlaybackException ??
//result.ErrorCode = ex.ErrorCode;
}
result.MediaSources = mediaSources.ToArray(); // TODO handle supportedLiveMediaTypes?
var mediaSourcesList = await _mediaSourceManager.GetPlaybackMediaSources(item, user, true, false, CancellationToken.None).ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(mediaSourceId)) if (string.IsNullOrWhiteSpace(mediaSourceId))
{
mediaSources = mediaSourcesList.ToArray();
}
else
{ {
result.MediaSources = result.MediaSources mediaSources = mediaSourcesList
.Where(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase))
.ToArray(); .ToArray();
} }
@ -307,11 +292,13 @@ namespace MediaBrowser.Api.Playback
{ {
var mediaSource = await _mediaSourceManager.GetLiveStream(liveStreamId, CancellationToken.None).ConfigureAwait(false); var mediaSource = await _mediaSourceManager.GetLiveStream(liveStreamId, CancellationToken.None).ConfigureAwait(false);
result.MediaSources = new MediaSourceInfo[] { mediaSource }; mediaSources = new MediaSourceInfo[] { mediaSource };
} }
if (result.MediaSources.Count == 0) if (mediaSources.Length == 0)
{ {
result.MediaSources = Array.Empty<MediaSourceInfo>();
if (!result.ErrorCode.HasValue) if (!result.ErrorCode.HasValue)
{ {
result.ErrorCode = PlaybackErrorCode.NoCompatibleStream; result.ErrorCode = PlaybackErrorCode.NoCompatibleStream;
@ -319,7 +306,9 @@ namespace MediaBrowser.Api.Playback
} }
else else
{ {
result.MediaSources = Clone(result.MediaSources); // Since we're going to be setting properties on MediaSourceInfos that come out of _mediaSourceManager, we should clone it
// Should we move this directly into MediaSourceManager?
result.MediaSources = JsonSerializer.Deserialize<MediaSourceInfo[]>(JsonSerializer.SerializeToUtf8Bytes(mediaSources));
result.PlaySessionId = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); result.PlaySessionId = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
} }

@ -225,7 +225,7 @@ namespace MediaBrowser.MediaEncoding.Probing
/// </summary> /// </summary>
/// <value>The start_pts.</value> /// <value>The start_pts.</value>
[JsonPropertyName("start_pts")] [JsonPropertyName("start_pts")]
public int StartPts { get; set; } public long StartPts { get; set; }
/// <summary> /// <summary>
/// Gets or sets the is_avc. /// Gets or sets the is_avc.

@ -76,6 +76,7 @@ namespace MediaBrowser.Model.Dto
{ {
Formats = Array.Empty<string>(); Formats = Array.Empty<string>();
MediaStreams = new List<MediaStream>(); MediaStreams = new List<MediaStream>();
MediaAttachments = Array.Empty<MediaAttachment>();
RequiredHttpHeaders = new Dictionary<string, string>(); RequiredHttpHeaders = new Dictionary<string, string>();
SupportsTranscoding = true; SupportsTranscoding = true;
SupportsDirectStream = true; SupportsDirectStream = true;

@ -0,0 +1,22 @@
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using MediaBrowser.MediaEncoding.Probing;
using Xunit;
namespace Jellyfin.MediaEncoding.Tests
{
public class FFprobeParserTests
{
[Theory]
[InlineData("ffprobe1.json")]
public async Task Test(string fileName)
{
var path = Path.Join("Test Data", fileName);
using (var stream = File.OpenRead(path))
{
await JsonSerializer.DeserializeAsync<InternalMediaInfoResult>(stream).ConfigureAwait(false);
}
}
}
}

@ -5,6 +5,12 @@
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Include="Test Data\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />

@ -0,0 +1,105 @@
{
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "Main",
"codec_type": "video",
"codec_time_base": "1/50",
"codec_tag_string": "[27][0][0][0]",
"codec_tag": "0x001b",
"width": 1920,
"height": 1080,
"coded_width": 1920,
"coded_height": 1080,
"has_b_frames": 0,
"sample_aspect_ratio": "0:1",
"display_aspect_ratio": "0:1",
"pix_fmt": "yuvj420p",
"level": 42,
"color_range": "pc",
"color_space": "bt709",
"color_transfer": "bt709",
"color_primaries": "bt709",
"chroma_location": "left",
"field_order": "progressive",
"refs": 1,
"is_avc": "false",
"nal_length_size": "0",
"id": "0x1",
"r_frame_rate": "25/1",
"avg_frame_rate": "25/1",
"time_base": "1/90000",
"start_pts": 8570867078,
"start_time": "95231.856422",
"duration_ts": 31694552,
"duration": "352.161689",
"bits_per_raw_sample": "8",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
}
},
{
"index": 1,
"codec_name": "aac",
"codec_long_name": "AAC (Advanced Audio Coding)",
"profile": "LC",
"codec_type": "audio",
"codec_time_base": "1/44100",
"codec_tag_string": "[15][0][0][0]",
"codec_tag": "0x000f",
"sample_fmt": "fltp",
"sample_rate": "44100",
"channels": 2,
"channel_layout": "stereo",
"bits_per_sample": 0,
"id": "0x2",
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/90000",
"start_pts": 8570867697,
"start_time": "95231.863300",
"duration_ts": 31695687,
"duration": "352.174300",
"bit_rate": "98191",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
}
}
],
"format": {
"filename": "TS Test record.ts",
"nb_streams": 2,
"nb_programs": 1,
"format_name": "mpegts",
"format_long_name": "MPEG-TS (MPEG-2 Transport Stream)",
"start_time": "95231.856422",
"duration": "352.181178",
"size": "179003772",
"bit_rate": "4066174",
"probe_score": 50
}
}
Loading…
Cancel
Save