]>
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 | ||
28705705 C |
28 | inputLocalUrl: string |
29 | inputPublicUrl: string | |
30 | ||
0c9668f7 C |
31 | fps: number |
32 | toTranscode: { | |
33 | resolution: number | |
34 | fps: number | |
35 | }[] | |
36 | ||
37 | bitrate: number | |
38 | ratio: number | |
39 | hasAudio: boolean | |
40 | ||
41 | segmentListSize: number | |
42 | segmentDuration: number | |
43 | ||
44 | outDirectory: string | |
45 | } | |
46 | ||
47 | abstract class AbstractTranscodingWrapper extends EventEmitter { | |
48 | protected readonly videoLive: MVideoLiveVideo | |
49 | ||
50 | protected readonly toTranscode: { | |
51 | resolution: number | |
52 | fps: number | |
53 | }[] | |
54 | ||
28705705 C |
55 | protected readonly inputLocalUrl: string |
56 | protected readonly inputPublicUrl: string | |
57 | ||
0c9668f7 C |
58 | protected readonly fps: number |
59 | protected readonly bitrate: number | |
60 | protected readonly ratio: number | |
61 | protected readonly hasAudio: boolean | |
62 | ||
63 | protected readonly segmentListSize: number | |
64 | protected readonly segmentDuration: number | |
65 | ||
66 | protected readonly videoUUID: string | |
67 | ||
68 | protected readonly outDirectory: string | |
69 | ||
70 | protected readonly lTags: LoggerTagsFn | |
71 | ||
72 | protected readonly streamingPlaylist: MStreamingPlaylistVideo | |
73 | ||
74 | constructor (options: AbstractTranscodingWrapperOptions) { | |
75 | super() | |
76 | ||
77 | this.lTags = options.lTags | |
78 | ||
79 | this.videoLive = options.videoLive | |
80 | this.videoUUID = options.videoLive.Video.uuid | |
81 | this.streamingPlaylist = options.streamingPlaylist | |
82 | ||
28705705 C |
83 | this.inputLocalUrl = options.inputLocalUrl |
84 | this.inputPublicUrl = options.inputPublicUrl | |
85 | ||
0c9668f7 C |
86 | this.fps = options.fps |
87 | this.toTranscode = options.toTranscode | |
88 | ||
89 | this.bitrate = options.bitrate | |
90 | this.ratio = options.ratio | |
91 | this.hasAudio = options.hasAudio | |
92 | ||
93 | this.segmentListSize = options.segmentListSize | |
94 | this.segmentDuration = options.segmentDuration | |
95 | ||
96 | this.outDirectory = options.outDirectory | |
97 | } | |
98 | ||
99 | abstract run (): Promise<void> | |
100 | ||
101 | abstract abort (error?: LiveVideoError): void | |
102 | } | |
103 | ||
104 | export { | |
105 | AbstractTranscodingWrapper, | |
106 | AbstractTranscodingWrapperOptions | |
107 | } |