|
|
|
@ -18,8 +18,7 @@ using Microsoft.EntityFrameworkCore; |
|
|
|
|
|
|
|
|
|
|
|
namespace ErsatzTV.Application.Streaming; |
|
|
|
namespace ErsatzTV.Application.Streaming; |
|
|
|
|
|
|
|
|
|
|
|
public class GetPlayoutItemProcessByChannelNumberHandler : |
|
|
|
public class GetPlayoutItemProcessByChannelNumberHandler : FFmpegProcessHandler<GetPlayoutItemProcessByChannelNumber> |
|
|
|
FFmpegProcessHandler<GetPlayoutItemProcessByChannelNumber> |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
private readonly IEmbyPathReplacementService _embyPathReplacementService; |
|
|
|
private readonly IEmbyPathReplacementService _embyPathReplacementService; |
|
|
|
private readonly IMediaCollectionRepository _mediaCollectionRepository; |
|
|
|
private readonly IMediaCollectionRepository _mediaCollectionRepository; |
|
|
|
@ -108,144 +107,146 @@ public class GetPlayoutItemProcessByChannelNumberHandler : |
|
|
|
|
|
|
|
|
|
|
|
IFFmpegProcessService ffmpegProcessService = await _ffmpegProcessServiceFactory.GetService(); |
|
|
|
IFFmpegProcessService ffmpegProcessService = await _ffmpegProcessServiceFactory.GetService(); |
|
|
|
|
|
|
|
|
|
|
|
return await maybePlayoutItem.Match( |
|
|
|
foreach (PlayoutItemWithPath playoutItemWithPath in maybePlayoutItem.RightToSeq()) |
|
|
|
async playoutItemWithPath => |
|
|
|
{ |
|
|
|
|
|
|
|
MediaVersion version = playoutItemWithPath.PlayoutItem.MediaItem.GetHeadVersion(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string videoPath = playoutItemWithPath.Path; |
|
|
|
|
|
|
|
MediaVersion videoVersion = version; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string audioPath = playoutItemWithPath.Path; |
|
|
|
|
|
|
|
MediaVersion audioVersion = version; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Option<ChannelWatermark> maybeGlobalWatermark = await dbContext.ConfigElements |
|
|
|
|
|
|
|
.GetValue<int>(ConfigElementKey.FFmpegGlobalWatermarkId) |
|
|
|
|
|
|
|
.BindT( |
|
|
|
|
|
|
|
watermarkId => dbContext.ChannelWatermarks |
|
|
|
|
|
|
|
.SelectOneAsync(w => w.Id, w => w.Id == watermarkId)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (playoutItemWithPath.PlayoutItem.MediaItem is Song song) |
|
|
|
{ |
|
|
|
{ |
|
|
|
MediaVersion version = playoutItemWithPath.PlayoutItem.MediaItem.GetHeadVersion(); |
|
|
|
(videoPath, videoVersion) = await _songVideoGenerator.GenerateSongVideo( |
|
|
|
|
|
|
|
song, |
|
|
|
string videoPath = playoutItemWithPath.Path; |
|
|
|
|
|
|
|
MediaVersion videoVersion = version; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string audioPath = playoutItemWithPath.Path; |
|
|
|
|
|
|
|
MediaVersion audioVersion = version; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Option<ChannelWatermark> maybeGlobalWatermark = await dbContext.ConfigElements |
|
|
|
|
|
|
|
.GetValue<int>(ConfigElementKey.FFmpegGlobalWatermarkId) |
|
|
|
|
|
|
|
.BindT( |
|
|
|
|
|
|
|
watermarkId => dbContext.ChannelWatermarks |
|
|
|
|
|
|
|
.SelectOneAsync(w => w.Id, w => w.Id == watermarkId)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (playoutItemWithPath.PlayoutItem.MediaItem is Song song) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
(videoPath, videoVersion) = await _songVideoGenerator.GenerateSongVideo( |
|
|
|
|
|
|
|
song, |
|
|
|
|
|
|
|
channel, |
|
|
|
|
|
|
|
maybeGlobalWatermark, |
|
|
|
|
|
|
|
ffmpegPath); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool saveReports = await dbContext.ConfigElements |
|
|
|
|
|
|
|
.GetValue<bool>(ConfigElementKey.FFmpegSaveReports) |
|
|
|
|
|
|
|
.Map(result => result.IfNone(false)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Process process = await ffmpegProcessService.ForPlayoutItem( |
|
|
|
|
|
|
|
ffmpegPath, |
|
|
|
|
|
|
|
saveReports, |
|
|
|
|
|
|
|
channel, |
|
|
|
channel, |
|
|
|
videoVersion, |
|
|
|
|
|
|
|
audioVersion, |
|
|
|
|
|
|
|
videoPath, |
|
|
|
|
|
|
|
audioPath, |
|
|
|
|
|
|
|
playoutItemWithPath.PlayoutItem.StartOffset, |
|
|
|
|
|
|
|
playoutItemWithPath.PlayoutItem.FinishOffset, |
|
|
|
|
|
|
|
request.StartAtZero ? playoutItemWithPath.PlayoutItem.StartOffset : now, |
|
|
|
|
|
|
|
maybeGlobalWatermark, |
|
|
|
maybeGlobalWatermark, |
|
|
|
channel.FFmpegProfile.VaapiDriver, |
|
|
|
ffmpegPath); |
|
|
|
channel.FFmpegProfile.VaapiDevice, |
|
|
|
} |
|
|
|
request.HlsRealtime, |
|
|
|
|
|
|
|
playoutItemWithPath.PlayoutItem.FillerKind, |
|
|
|
bool saveReports = await dbContext.ConfigElements |
|
|
|
playoutItemWithPath.PlayoutItem.InPoint, |
|
|
|
.GetValue<bool>(ConfigElementKey.FFmpegSaveReports) |
|
|
|
playoutItemWithPath.PlayoutItem.OutPoint, |
|
|
|
.Map(result => result.IfNone(false)); |
|
|
|
request.PtsOffset, |
|
|
|
|
|
|
|
request.TargetFramerate); |
|
|
|
Process process = await ffmpegProcessService.ForPlayoutItem( |
|
|
|
|
|
|
|
ffmpegPath, |
|
|
|
var result = new PlayoutItemProcessModel(process, playoutItemWithPath.PlayoutItem.FinishOffset); |
|
|
|
saveReports, |
|
|
|
|
|
|
|
channel, |
|
|
|
return Right<BaseError, PlayoutItemProcessModel>(result); |
|
|
|
videoVersion, |
|
|
|
}, |
|
|
|
audioVersion, |
|
|
|
async error => |
|
|
|
videoPath, |
|
|
|
|
|
|
|
audioPath, |
|
|
|
|
|
|
|
playoutItemWithPath.PlayoutItem.StartOffset, |
|
|
|
|
|
|
|
playoutItemWithPath.PlayoutItem.FinishOffset, |
|
|
|
|
|
|
|
request.StartAtZero ? playoutItemWithPath.PlayoutItem.StartOffset : now, |
|
|
|
|
|
|
|
maybeGlobalWatermark, |
|
|
|
|
|
|
|
channel.FFmpegProfile.VaapiDriver, |
|
|
|
|
|
|
|
channel.FFmpegProfile.VaapiDevice, |
|
|
|
|
|
|
|
request.HlsRealtime, |
|
|
|
|
|
|
|
playoutItemWithPath.PlayoutItem.FillerKind, |
|
|
|
|
|
|
|
playoutItemWithPath.PlayoutItem.InPoint, |
|
|
|
|
|
|
|
playoutItemWithPath.PlayoutItem.OutPoint, |
|
|
|
|
|
|
|
request.PtsOffset, |
|
|
|
|
|
|
|
request.TargetFramerate); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = new PlayoutItemProcessModel(process, playoutItemWithPath.PlayoutItem.FinishOffset); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Right<BaseError, PlayoutItemProcessModel>(result); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (BaseError error in maybePlayoutItem.LeftToSeq()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var offlineTranscodeMessage = |
|
|
|
|
|
|
|
$"offline image is unavailable because transcoding is disabled in ffmpeg profile '{channel.FFmpegProfile.Name}'"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Option<TimeSpan> maybeDuration = await Optional(channel.FFmpegProfile.Transcode) |
|
|
|
|
|
|
|
.Where(transcode => transcode) |
|
|
|
|
|
|
|
.Match( |
|
|
|
|
|
|
|
_ => dbContext.PlayoutItems |
|
|
|
|
|
|
|
.Filter(pi => pi.Playout.ChannelId == channel.Id) |
|
|
|
|
|
|
|
.Filter(pi => pi.Start > now.UtcDateTime) |
|
|
|
|
|
|
|
.OrderBy(pi => pi.Start) |
|
|
|
|
|
|
|
.FirstOrDefaultAsync() |
|
|
|
|
|
|
|
.Map(Optional) |
|
|
|
|
|
|
|
.MapT(pi => pi.StartOffset - now), |
|
|
|
|
|
|
|
() => Option<TimeSpan>.None.AsTask()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTimeOffset finish = maybeDuration.Match(d => now.Add(d), () => now); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (error) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var offlineTranscodeMessage = |
|
|
|
case UnableToLocatePlayoutItem: |
|
|
|
$"offline image is unavailable because transcoding is disabled in ffmpeg profile '{channel.FFmpegProfile.Name}'"; |
|
|
|
if (channel.FFmpegProfile.Transcode) |
|
|
|
|
|
|
|
{ |
|
|
|
Option<TimeSpan> maybeDuration = await Optional(channel.FFmpegProfile.Transcode) |
|
|
|
Process errorProcess = await ffmpegProcessService.ForError( |
|
|
|
.Where(transcode => transcode) |
|
|
|
ffmpegPath, |
|
|
|
.Match( |
|
|
|
channel, |
|
|
|
_ => dbContext.PlayoutItems |
|
|
|
maybeDuration, |
|
|
|
.Filter(pi => pi.Playout.ChannelId == channel.Id) |
|
|
|
"Channel is Offline", |
|
|
|
.Filter(pi => pi.Start > now.UtcDateTime) |
|
|
|
request.HlsRealtime, |
|
|
|
.OrderBy(pi => pi.Start) |
|
|
|
request.PtsOffset); |
|
|
|
.FirstOrDefaultAsync() |
|
|
|
|
|
|
|
.Map(Optional) |
|
|
|
return new PlayoutItemProcessModel(errorProcess, finish); |
|
|
|
.MapT(pi => pi.StartOffset - now), |
|
|
|
} |
|
|
|
() => Option<TimeSpan>.None.AsTask()); |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
DateTimeOffset finish = maybeDuration.Match(d => now.Add(d), () => now); |
|
|
|
var message = |
|
|
|
|
|
|
|
$"Unable to locate playout item for channel {channel.Number}; {offlineTranscodeMessage}"; |
|
|
|
switch (error) |
|
|
|
|
|
|
|
{ |
|
|
|
return BaseError.New(message); |
|
|
|
case UnableToLocatePlayoutItem: |
|
|
|
} |
|
|
|
if (channel.FFmpegProfile.Transcode) |
|
|
|
case PlayoutItemDoesNotExistOnDisk: |
|
|
|
{ |
|
|
|
if (channel.FFmpegProfile.Transcode) |
|
|
|
Process errorProcess = await ffmpegProcessService.ForError( |
|
|
|
{ |
|
|
|
ffmpegPath, |
|
|
|
Process errorProcess = await ffmpegProcessService.ForError( |
|
|
|
channel, |
|
|
|
ffmpegPath, |
|
|
|
maybeDuration, |
|
|
|
channel, |
|
|
|
"Channel is Offline", |
|
|
|
maybeDuration, |
|
|
|
request.HlsRealtime, |
|
|
|
error.Value, |
|
|
|
request.PtsOffset); |
|
|
|
request.HlsRealtime, |
|
|
|
|
|
|
|
request.PtsOffset); |
|
|
|
return new PlayoutItemProcessModel(errorProcess, finish); |
|
|
|
|
|
|
|
} |
|
|
|
return new PlayoutItemProcessModel(errorProcess, finish); |
|
|
|
else |
|
|
|
} |
|
|
|
{ |
|
|
|
else |
|
|
|
var message = |
|
|
|
{ |
|
|
|
$"Unable to locate playout item for channel {channel.Number}; {offlineTranscodeMessage}"; |
|
|
|
var message = |
|
|
|
|
|
|
|
$"Playout item does not exist on disk for channel {channel.Number}; {offlineTranscodeMessage}"; |
|
|
|
return BaseError.New(message); |
|
|
|
|
|
|
|
} |
|
|
|
return BaseError.New(message); |
|
|
|
case PlayoutItemDoesNotExistOnDisk: |
|
|
|
} |
|
|
|
if (channel.FFmpegProfile.Transcode) |
|
|
|
default: |
|
|
|
{ |
|
|
|
if (channel.FFmpegProfile.Transcode) |
|
|
|
Process errorProcess = await ffmpegProcessService.ForError( |
|
|
|
{ |
|
|
|
ffmpegPath, |
|
|
|
Process errorProcess = await ffmpegProcessService.ForError( |
|
|
|
channel, |
|
|
|
ffmpegPath, |
|
|
|
maybeDuration, |
|
|
|
channel, |
|
|
|
error.Value, |
|
|
|
maybeDuration, |
|
|
|
request.HlsRealtime, |
|
|
|
"Channel is Offline", |
|
|
|
request.PtsOffset); |
|
|
|
request.HlsRealtime, |
|
|
|
|
|
|
|
request.PtsOffset); |
|
|
|
return new PlayoutItemProcessModel(errorProcess, finish); |
|
|
|
|
|
|
|
} |
|
|
|
return new PlayoutItemProcessModel(errorProcess, finish); |
|
|
|
else |
|
|
|
} |
|
|
|
{ |
|
|
|
else |
|
|
|
var message = |
|
|
|
{ |
|
|
|
$"Playout item does not exist on disk for channel {channel.Number}; {offlineTranscodeMessage}"; |
|
|
|
var message = |
|
|
|
|
|
|
|
$"Unexpected error locating playout item for channel {channel.Number}; {offlineTranscodeMessage}"; |
|
|
|
return BaseError.New(message); |
|
|
|
|
|
|
|
} |
|
|
|
return BaseError.New(message); |
|
|
|
default: |
|
|
|
} |
|
|
|
if (channel.FFmpegProfile.Transcode) |
|
|
|
} |
|
|
|
{ |
|
|
|
} |
|
|
|
Process errorProcess = await ffmpegProcessService.ForError( |
|
|
|
|
|
|
|
ffmpegPath, |
|
|
|
return BaseError.New($"Unexpected error locating playout item for channel {channel.Number}"); |
|
|
|
channel, |
|
|
|
|
|
|
|
maybeDuration, |
|
|
|
|
|
|
|
"Channel is Offline", |
|
|
|
|
|
|
|
request.HlsRealtime, |
|
|
|
|
|
|
|
request.PtsOffset); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new PlayoutItemProcessModel(errorProcess, finish); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var message = |
|
|
|
|
|
|
|
$"Unexpected error locating playout item for channel {channel.Number}; {offlineTranscodeMessage}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return BaseError.New(message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task<Either<BaseError, PlayoutItemWithPath>> CheckForFallbackFiller( |
|
|
|
private async Task<Either<BaseError, PlayoutItemWithPath>> CheckForFallbackFiller( |
|
|
|
|