Passed
Push — master ( bc6590...e618e7 )
by Amin
05:42 queued 11s
created

Representation::getRatio()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
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
namespace Streaming;
13
14
use FFMpeg\Coordinate\AspectRatio;
15
use FFMpeg\Coordinate\Dimension;
16
use Streaming\Exception\InvalidArgumentException;
17
18
class Representation implements RepresentationInterface
19
{
20
    /** @var int $kiloBitrate video kilo bitrate */
21
    private $kiloBitrate;
22
23
    /** @var int $audioKiloBitrate audio kilo bitrate */
24
    private $audioKiloBitrate;
25
26
    /** @var Dimension $size size of representation */
27
    private $size;
28
29
    /** @var array $hls_stream_info hls stream info */
30
    private $hls_stream_info = [];
31
32
    /**
33
     * @return string | null
34
     */
35
    public function size2string(): ?string
36
    {
37
        return !is_null($this->size) ? implode("x", [$this->getWidth(), $this->getHeight()]) : null;
38
    }
39
40
    /**
41
     * @param $width
42
     * @param $height
43
     * @return Representation
44
     * @throws InvalidArgumentException
45
     */
46
    public function setResize(int $width, int $height): Representation
47
    {
48
        $this->setSize(new Dimension($width, $height));
49
        return $this;
50
    }
51
52
    /**
53
     * @return int
54
     */
55
    public function getKiloBitrate(): int
56
    {
57
        return $this->kiloBitrate;
58
    }
59
60
    /**
61
     * @return int|null
62
     */
63
    public function getAudioKiloBitrate()
64
    {
65
        return $this->audioKiloBitrate;
66
    }
67
68
    /**
69
     * Sets the video kiloBitrate value.
70
     *
71
     * @param  integer $kiloBitrate
72
     * @return Representation
73
     * @throws InvalidArgumentException
74
     */
75
    public function setKiloBitrate(int $kiloBitrate): Representation
76
    {
77
        if ($kiloBitrate < 1) {
78
            throw new InvalidArgumentException('Invalid kilo bit rate value');
79
        }
80
81
        $this->kiloBitrate = (int)$kiloBitrate;
82
        return $this;
83
    }
84
85
    /**
86
     * Sets the video kiloBitrate value.
87
     *
88
     * @param  integer $audioKiloBitrate
89
     * @return Representation
90
     * @throws InvalidArgumentException
91
     */
92
    public function setAudioKiloBitrate(int $audioKiloBitrate): Representation
93
    {
94
        $this->audioKiloBitrate = $audioKiloBitrate;
95
        return $this;
96
    }
97
98
    /**
99
     * @return int
100
     */
101
    public function getWidth(): int
102
    {
103
        return $this->size->getWidth();
104
    }
105
106
    /**
107
     * @return int
108
     */
109
    public function getHeight(): int
110
    {
111
        return $this->size->getHeight();
112
    }
113
114
    /**
115
     * @return AspectRatio
116
     */
117
    public function getRatio(): AspectRatio
118
    {
119
        return $this->size->getRatio();
120
    }
121
122
    /**
123
     * @param array $hls_stream_info
124
     * @return Representation
125
     */
126
    public function setHlsStreamInfo(array $hls_stream_info): Representation
127
    {
128
        $this->hls_stream_info = $hls_stream_info;
129
        return $this;
130
    }
131
132
    /**
133
     * @return array
134
     */
135
    public function getHlsStreamInfo(): array
136
    {
137
        return $this->hls_stream_info;
138
    }
139
140
    /**
141
     * @param Dimension $size
142
     * @return Representation
143
     */
144
    public function setSize(Dimension $size): Representation
145
    {
146
        $this->size = $size;
147
        return $this;
148
    }
149
150
    /**
151
     * @return Dimension
152
     */
153
    public function getSize(): Dimension
154
    {
155
        return $this->size;
156
    }
157
}