aboutsummaryrefslogtreecommitdiff
path: root/model/Stream.php
blob: d6ce5ef7f3482f96967a7a7c3e8489a49c4067f1 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php

class Stream
{
	public function __construct(Room $room, $selection, $language, $translation_label = null)
	{
		$this->room = $room;
		$this->selection = $selection;
		$this->language = $language;
	 	$this->translation_label = (empty($translation_label)) ? $language : $translation_label;
	}

	public function getRoom()
	{
		return $this->room;
	}

	public function getSelection()
	{
		return $this->selection;
	}

	public function getLanguage()
	{
		return $this->language;
	}

	public function getTranslationLabel()
	{
	  return $this->translation_label;
	}

	public function isTranslated()
	{
		return !empty($this->getLanguage()) &&
			$this->getLanguage() !== 'native' &&
			$this->getLanguage() !== 'stereo';
	}

	public function getVideoSize()
	{
		switch($this->getSelection())
		{
			case 'sd':
			case 'slides':
				return array(1024, 576);

			case 'hd':
				return array(1920, 1080);

			default:
				return null;
		}
	}

	public function getVideoWidth()
	{
		$sz = $this->getVideoSize();
		return $sz[0];
	}

	public function getVideoHeight()
	{
		$sz = $this->getVideoSize();
		return $sz[1];
	}

	public function getTab()
	{
		switch($this->getSelection())
		{
			case 'sd':
			case 'hd':
				return 'video';

			default:
				return $this->getSelection();
		}
	}

	public function getPlayerType()
	{
		return $this->getTab();
	}

	public function getDisplay()
	{
		$display = $this->getRoom()->getDisplay().' ';
		switch($this->getSelection())
		{
			case 'hd':
				$display .= 'FullHD Video';
				break;

			case 'sd':
				$display .= 'SD Video';
				break;

			case 'music':
				$display .= 'Radio';
				break;

			case 'dash':
				# no special attribution, this is the "normal" stream
				break;

			default:
				$display .= ucfirst($this->getSelection());
				break;
		}

		if($this->isTranslated())
			$display .= ' ('. $this->getTranslationLabel() .')';

		return $display;
	}

	public function getEmbedUrl()
	{
		return joinpath([
			baseurl(),
			$this->getRoom()->getConference()->getSlug(),
			'embed',
			rawurlencode($this->getRoom()->getSlug()),
			rawurlencode($this->getSelection()),
			rawurlencode($this->getLanguage()),
		]);
	}

	public function getVideoUrl($proto, $selection=null)
	{
		if (!$selection) {
			$selection = $this->getSelection();
		}

		switch($proto)
		{
			case 'webm':
				return proto().'://cdn.c3voc.de/'.rawurlencode($this->getRoom()->getStream()).'_'.rawurlencode($this->getLanguage()).'_'.rawurlencode($selection).'.webm';

			case 'hls':
				return proto().'://cdn.c3voc.de/hls/'.rawurlencode($this->getRoom()->getStream()).'_'.rawurlencode($this->getLanguage()).'_'.rawurlencode($selection).'.m3u8';
		}

		return null;
	}
	public function getVideoTech($proto)
	{
		switch($proto)
		{
			case 'webm':
				if($this->getSelection() == 'hd')
					return '1920x1080, VP8+Vorbis in WebM, 3.5 MBit/s';

				else if($this->getSelection() == 'sd')
					return '1024x576, VP8+Vorbis in WebM, 1 MBit/s';

			case 'hls':
				if($this->getSelection() == 'hd')
					return '1920x1080, h264+AAC im MPEG-TS-Container via HTTP, 3 MBit/s';

				else if($this->getSelection() == 'sd')
					return '1024x576, h264+AAC im MPEG-TS-Container via HTTP, 800 kBit/s';
		}

		return null;
	}
	public static function getVideoProtos()
	{
		return array(
			'webm' => 'WebM',
			'hls' => 'HLS',
		);
	}

	public function getSlidesUrl($proto)
	{
		return $this->getVideoUrl($proto);
	}
	public function getSlidesTech($proto)
	{
		switch($proto)
		{
			case 'webm':
				return '1024x576, VP8+Vorbis in WebM, 400 kBit/s';

			case 'hls':
				return '1024x576, h264+AAC im MPEG-TS-Container via HTTP, 400 kBit/s';
		}

		return null;
	}
	public static function getSlidesProtos()
	{
		return Stream::getVideoProtos();
	}


	public function getAudioUrl($proto)
	{
		switch($proto)
		{
			case 'mp3':
				return proto().'://cdn.c3voc.de/'.rawurlencode($this->getRoom()->getStream()).'_'.rawurlencode($this->getLanguage()).'.mp3';

			case 'opus':
				return proto().'://cdn.c3voc.de/'.rawurlencode($this->getRoom()->getStream()).'_'.rawurlencode($this->getLanguage()).'.opus';
		}

		return null;
	}
	public function getAudioTech($proto)
	{
		switch($proto)
		{
			case 'mp3':
				return 'MP3-Audio, 96 kBit/s';

			case 'opus':
				return 'Opus-Audio, 64 kBit/s';
		}

		return null;
	}
	public static function getAudioProtos()
	{
		return array(
			'mp3' => 'MP3',
			'opus' => 'Opus',
		);
	}

	public function getMusicUrl($proto)
	{
		switch($proto)
		{
			case 'mp3':
				return proto().'://cdn.c3voc.de/'.rawurlencode($this->getRoom()->getStream()).'.mp3';

			case 'opus':
				return proto().'://cdn.c3voc.de/'.rawurlencode($this->getRoom()->getStream()).'.opus';

			default:
				return null;
		}
	}
	public function getMusicTech($proto)
	{
		switch($proto)
		{
			case 'mp3':
				return 'MP3-Audio, 192 kBit/s';

			case 'opus':
				return 'Opus-Audio, 96 kBit/s';
		}

		return null;
	}
	public static function getMusicProtos()
	{
		return array(
			'mp3' => 'MP3',
			'opus' => 'Opus',
		);
	}
}