]>
Commit | Line | Data |
---|---|---|
0c9668f7 C |
1 | import EventEmitter from 'events' |
2 | import { LoggerTagsFn } from '@server/helpers/logger' | |
3 | import { MStreamingPlaylistVideo, MVideoLiveVideo } from '@server/types/models' | |
4 | import { LiveVideoError } from '@shared/models' | |
5 | ||
6 | interface TranscodingWrapperEvents { | |
7 | 'end': () => void | |
8 | ||
9 | 'error': (options: { err: Error }) => void | |
10 | } | |
11 | ||
12 | declare interface AbstractTranscodingWrapper { | |
13 | on<U extends keyof TranscodingWrapperEvents>( | |
14 | event: U, listener: TranscodingWrapperEvents[U] | |
15 | ): this | |
16 | ||
17 | emit<U extends keyof TranscodingWrapperEvents>( | |
18 | event: U, ...args: Parameters<TranscodingWrapperEvents[U]> | |
19 | ): boolean | |
20 | } | |
21 | ||
22 | interface AbstractTranscodingWrapperOptions { | |
23 | streamingPlaylist: MStreamingPlaylistVideo | |
24 | videoLive: MVideoLiveVideo | |
25 | ||
26 | lTags: LoggerTagsFn | |
27 | ||
17ecdf61 | 28 | sessionId: string |
28705705 C |
29 | inputLocalUrl: string |
30 | inputPublicUrl: string | |
31 | ||
0c9668f7 C |
32 | fps: number |
33 | toTranscode: { | |
34 | resolution: number | |
35 | fps: number | |
36 | }[] | |
37 | ||
38 | bitrate: number | |
39 | ratio: number | |
40 | hasAudio: boolean | |
41 | ||
42 | segmentListSize: number | |
43 | segmentDuration: number | |
44 | ||
45 | outDirectory: string | |
46 | } | |
47 | ||
48 | abstract class AbstractTranscodingWrapper extends EventEmitter { | |
49 | protected readonly videoLive: MVideoLiveVideo | |
50 | ||
51 | protected readonly toTranscode: { | |
52 | resolution: number | |
53 | fps: number | |
54 | }[] | |
55 | ||
17ecdf61 | 56 | protected readonly sessionId: string |
28705705 C |
57 | protected readonly inputLocalUrl: string |
58 | protected readonly inputPublicUrl: string | |
59 | ||
0c9668f7 C |
60 | protected readonly fps: number |
61 | protected readonly bitrate: number | |
62 | protected readonly ratio: number | |
63 | protected readonly hasAudio: boolean | |
64 | ||
65 | protected readonly segmentListSize: number | |
66 | protected readonly segmentDuration: number | |
67 | ||
68 | protected readonly videoUUID: string | |
69 | ||
70 | protected readonly outDirectory: string | |
71 | ||
72 | protected readonly lTags: LoggerTagsFn | |
73 | ||
74 | protected readonly streamingPlaylist: MStreamingPlaylistVideo | |
75 | ||
76 | constructor (options: AbstractTranscodingWrapperOptions) { | |
77 | super() | |
78 | ||
79 | this.lTags = options.lTags | |
80 | ||
81 | this.videoLive = options.videoLive | |
82 | this.videoUUID = options.videoLive.Video.uuid | |
83 | this.streamingPlaylist = options.streamingPlaylist | |
84 | ||
17ecdf61 | 85 | this.sessionId = options.sessionId |
28705705 C |
86 | this.inputLocalUrl = options.inputLocalUrl |
87 | this.inputPublicUrl = options.inputPublicUrl | |
88 | ||
0c9668f7 C |
89 | this.fps = options.fps |
90 | this.toTranscode = options.toTranscode | |
91 | ||
92 | this.bitrate = options.bitrate | |
93 | this.ratio = options.ratio | |
94 | this.hasAudio = options.hasAudio | |
95 | ||
96 | this.segmentListSize = options.segmentListSize | |
97 | this.segmentDuration = options.segmentDuration | |
98 | ||
99 | this.outDirectory = options.outDirectory | |
100 | } | |
101 | ||
102 | abstract run (): Promise<void> | |
103 | ||
104 | abstract abort (error?: LiveVideoError): void | |
105 | } | |
106 | ||
107 | export { | |
108 | AbstractTranscodingWrapper, | |
109 | AbstractTranscodingWrapperOptions | |
110 | } |