aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/MediaEncoding/ITranscodeManager.cs
blob: 3b410d1bac8951043ac480306de5d61493453653 (plain)
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
using System;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Streaming;

namespace MediaBrowser.Controller.MediaEncoding;

/// <summary>
/// A service for managing media transcoding.
/// </summary>
public interface ITranscodeManager
{
    /// <summary>
    /// Get transcoding job.
    /// </summary>
    /// <param name="playSessionId">Playback session id.</param>
    /// <returns>The transcoding job.</returns>
    public TranscodingJob? GetTranscodingJob(string playSessionId);

    /// <summary>
    /// Get transcoding job.
    /// </summary>
    /// <param name="path">Path to the transcoding file.</param>
    /// <param name="type">The <see cref="TranscodingJobType"/>.</param>
    /// <returns>The transcoding job.</returns>
    public TranscodingJob? GetTranscodingJob(string path, TranscodingJobType type);

    /// <summary>
    /// Ping transcoding job.
    /// </summary>
    /// <param name="playSessionId">Play session id.</param>
    /// <param name="isUserPaused">Is user paused.</param>
    /// <exception cref="ArgumentNullException">Play session id is null.</exception>
    public void PingTranscodingJob(string playSessionId, bool? isUserPaused);

    /// <summary>
    /// Kills the single transcoding job.
    /// </summary>
    /// <param name="deviceId">The device id.</param>
    /// <param name="playSessionId">The play session identifier.</param>
    /// <param name="deleteFiles">The delete files.</param>
    /// <returns>Task.</returns>
    public Task KillTranscodingJobs(string deviceId, string? playSessionId, Func<string, bool> deleteFiles);

    /// <summary>
    /// Report the transcoding progress to the session manager.
    /// </summary>
    /// <param name="job">The <see cref="TranscodingJob"/> of which the progress will be reported.</param>
    /// <param name="state">The <see cref="StreamState"/> of the current transcoding job.</param>
    /// <param name="transcodingPosition">The current transcoding position.</param>
    /// <param name="framerate">The framerate of the transcoding job.</param>
    /// <param name="percentComplete">The completion percentage of the transcode.</param>
    /// <param name="bytesTranscoded">The number of bytes transcoded.</param>
    /// <param name="bitRate">The bitrate of the transcoding job.</param>
    public void ReportTranscodingProgress(
        TranscodingJob job,
        StreamState state,
        TimeSpan? transcodingPosition,
        float? framerate,
        double? percentComplete,
        long? bytesTranscoded,
        int? bitRate);

    /// <summary>
    /// Starts FFMpeg.
    /// </summary>
    /// <param name="state">The state.</param>
    /// <param name="outputPath">The output path.</param>
    /// <param name="commandLineArguments">The command line arguments for FFmpeg.</param>
    /// <param name="userId">The user id.</param>
    /// <param name="transcodingJobType">The <see cref="TranscodingJobType"/>.</param>
    /// <param name="cancellationTokenSource">The cancellation token source.</param>
    /// <param name="workingDirectory">The working directory.</param>
    /// <returns>Task.</returns>
    public Task<TranscodingJob> StartFfMpeg(
        StreamState state,
        string outputPath,
        string commandLineArguments,
        Guid userId,
        TranscodingJobType transcodingJobType,
        CancellationTokenSource cancellationTokenSource,
        string? workingDirectory = null);

    /// <summary>
    /// Called when [transcode begin request].
    /// </summary>
    /// <param name="path">The path.</param>
    /// <param name="type">The type.</param>
    /// <returns>The <see cref="TranscodingJob"/>.</returns>
    public TranscodingJob? OnTranscodeBeginRequest(string path, TranscodingJobType type);

    /// <summary>
    /// Called when [transcode end].
    /// </summary>
    /// <param name="job">The transcode job.</param>
    public void OnTranscodeEndRequest(TranscodingJob job);

    /// <summary>
    /// Transcoding lock.
    /// </summary>
    /// <param name="outputPath">The output path of the transcoded file.</param>
    /// <param name="cancellationToken">The cancellation token.</param>
    /// <returns>A <see cref="SemaphoreSlim"/>.</returns>
    ValueTask<IDisposable> LockAsync(string outputPath, CancellationToken cancellationToken);
}