]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-configuration.service.ts
Improve remote runner config UX
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-configuration.service.ts
1 import { Injectable } from '@angular/core'
2 import { FormGroup } from '@angular/forms'
3 import { prepareIcu } from '@app/helpers'
4
5 export type ResolutionOption = {
6 id: string
7 label: string
8 description?: string
9 }
10
11 @Injectable()
12 export class EditConfigurationService {
13
14 getVODResolutions () {
15 return [
16 {
17 id: '0p',
18 label: $localize`Audio-only`,
19 description: $localize`A <code>.mp4</code> that keeps the original audio track, with no video`
20 },
21 {
22 id: '144p',
23 label: $localize`144p`
24 },
25 {
26 id: '240p',
27 label: $localize`240p`
28 },
29 {
30 id: '360p',
31 label: $localize`360p`
32 },
33 {
34 id: '480p',
35 label: $localize`480p`
36 },
37 {
38 id: '720p',
39 label: $localize`720p`
40 },
41 {
42 id: '1080p',
43 label: $localize`1080p`
44 },
45 {
46 id: '1440p',
47 label: $localize`1440p`
48 },
49 {
50 id: '2160p',
51 label: $localize`2160p`
52 }
53 ]
54 }
55
56 getLiveResolutions () {
57 return this.getVODResolutions().filter(r => r.id !== '0p')
58 }
59
60 isTranscodingEnabled (form: FormGroup) {
61 return form.value['transcoding']['enabled'] === true
62 }
63
64 isRemoteRunnerVODEnabled (form: FormGroup) {
65 return form.value['transcoding']['remoteRunners']['enabled'] === true
66 }
67
68 isRemoteRunnerLiveEnabled (form: FormGroup) {
69 return form.value['live']['transcoding']['remoteRunners']['enabled'] === true
70 }
71
72 isStudioEnabled (form: FormGroup) {
73 return form.value['videoStudio']['enabled'] === true
74 }
75
76 isLiveEnabled (form: FormGroup) {
77 return form.value['live']['enabled'] === true
78 }
79
80 isLiveTranscodingEnabled (form: FormGroup) {
81 return form.value['live']['transcoding']['enabled'] === true
82 }
83
84 getTotalTranscodingThreads (form: FormGroup) {
85 const transcodingEnabled = form.value['transcoding']['enabled']
86 const transcodingThreads = form.value['transcoding']['threads']
87 const liveTranscodingEnabled = form.value['live']['transcoding']['enabled']
88 const liveTranscodingThreads = form.value['live']['transcoding']['threads']
89
90 // checks whether all enabled method are on fixed values and not on auto (= 0)
91 let noneOnAuto = !transcodingEnabled || +transcodingThreads > 0
92 noneOnAuto &&= !liveTranscodingEnabled || +liveTranscodingThreads > 0
93
94 // count total of fixed value, repalcing auto by a single thread (knowing it will display "at least")
95 let value = 0
96 if (transcodingEnabled) value += +transcodingThreads || 1
97 if (liveTranscodingEnabled) value += +liveTranscodingThreads || 1
98
99 return {
100 value,
101 atMost: noneOnAuto, // auto switches everything to a least estimation since ffmpeg will take as many threads as possible
102 unit: prepareIcu($localize`{value, plural, =1 {thread} other {threads}}`)(
103 { value },
104 $localize`threads`
105 )
106 }
107 }
108 }