Capture::windows()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
13
namespace Streaming;
14
15
16
use Streaming\Exception\RuntimeException;
17
18
class Capture
19
{
20
    /**
21
     * @var string
22
     */
23
    private $video;
24
    /**
25
     * @var string|null
26
     */
27
    private $audio;
28
    /**
29
     * @var bool
30
     */
31
    private $screen;
32
33
    /**
34
     * Camera constructor.
35
     * @param string $video
36
     * @param string|null $audio
37
     * @param bool $screen
38
     */
39
    public function __construct(string $video, string $audio = null, $screen = false)
40
    {
41
        $this->video = $video;
42
        $this->audio = $audio;
43
        $this->screen = $screen;
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    public function linux(): array
50
    {
51
        return [$this->video, ['f' => $this->screen ? 'x11grab' : 'v4l2']];
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function windows(): array
58
    {
59
        $path = "video=$this->video";
60
        if (!is_null($this->audio)) {
61
            $path .= ":audio=$this->audio";
62
        }
63
64
        return [$path, ['f' => 'dshow']];
65
    }
66
67
    /**
68
     * @return array
69
     */
70
    public function osX(): array
71
    {
72
        return [$this->video, ['f' => 'avfoundation']];
73
    }
74
75
    /**
76
     * @throw Runtime exception
77
     */
78
    public function unknown()
79
    {
80
        throw new RuntimeException("Unknown operating system! It cannot run the camera on this platform");
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    public function getOptions(): array
87
    {
88
        return call_user_func([$this, Utiles::getOS()]);
89
    }
90
}