]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-configuration.service.ts
Merge branch 'release/4.2.0' into develop
[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 isLiveEnabled (form: FormGroup) {
65 return form.value['live']['enabled'] === true
66 }
67
68 isLiveTranscodingEnabled (form: FormGroup) {
69 return form.value['live']['transcoding']['enabled'] === true
70 }
71
72 getTotalTranscodingThreads (form: FormGroup) {
73 const transcodingEnabled = form.value['transcoding']['enabled']
74 const transcodingThreads = form.value['transcoding']['threads']
75 const liveTranscodingEnabled = form.value['live']['transcoding']['enabled']
76 const liveTranscodingThreads = form.value['live']['transcoding']['threads']
77
78 // checks whether all enabled method are on fixed values and not on auto (= 0)
79 let noneOnAuto = !transcodingEnabled || +transcodingThreads > 0
80 noneOnAuto &&= !liveTranscodingEnabled || +liveTranscodingThreads > 0
81
82 // count total of fixed value, repalcing auto by a single thread (knowing it will display "at least")
83 let value = 0
84 if (transcodingEnabled) value += +transcodingThreads || 1
85 if (liveTranscodingEnabled) value += +liveTranscodingThreads || 1
86
87 return {
88 value,
89 atMost: noneOnAuto, // auto switches everything to a least estimation since ffmpeg will take as many threads as possible
90 unit: prepareIcu($localize`{value, plural, =1 {thread} other {threads}}`)(
91 { value },
92 $localize`threads`
93 )
94 }
95 }
96 }