forked from Threadfin/Threadfin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct-buffer.go
More file actions
264 lines (203 loc) · 5.16 KB
/
struct-buffer.go
File metadata and controls
264 lines (203 loc) · 5.16 KB
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
package src
import "time"
// Playlist : Enthält allen Playlistinformationen, die der Buffer benötigr
type Playlist struct {
Folder string
PlaylistID string
PlaylistName string
Tuner int
HttpProxyIP string
HttpProxyPort string
HttpUserOrigin string
HttpUserReferer string
Buffer string
Clients map[int]ThisClient
Streams map[int]ThisStream
}
// ThisClient : Clientinfos
type ThisClient struct {
Connection int
}
// ThisStream : Enthält Informationen zu dem abzuspielenden Stream einer Playlist
type ThisStream struct {
ChannelName string
Error string
Folder string
MD5 string
NetworkBandwidth int
PlaylistID string
PlaylistName string
Status bool
URL string
BackupChannel1 *BackupStream
BackupChannel2 *BackupStream
BackupChannel3 *BackupStream
Segment []Segment
// Serverinformationen
Location string
URLFile string
URLHost string
URLPath string
URLRedirect string
URLScheme string
URLStreamingServer string
// Wird nur für HLS / M3U8 verwendet
Body string
Difference float64
Duration float64
DynamicBandwidth bool
FirstSequence int64
HLS bool
LastSequence int64
M3U8URL string
NewSegCount int
OldSegCount int
Sequence int64
TimeDiff float64
TimeEnd time.Time
TimeSegDuration float64
TimeStart time.Time
Version int
Wait float64
DynamicStream map[int]DynamicStream
// Lokale Temp Datein
OldSegments []string
ClientID string
}
// Segment : URL Segmente (HLS / M3U8)
type Segment struct {
Duration float64
Info bool
PlaylistType string
Sequence int64
URL string
Version int
Wait float64
StreamInf struct {
AverageBandwidth int
Bandwidth int
Framerate float64
Resolution string
SegmentURL string
}
}
// DynamicStream : Streaminformationen bei dynamischer Bandbreite
type DynamicStream struct {
AverageBandwidth int
Bandwidth int
Framerate float64
Resolution string
URL string
}
// ClientConnection : Client Verbindungen
type ClientConnection struct {
Connection int
Error error
}
// BandwidthCalculation : Bandbreitenberechnung für den Stream
type BandwidthCalculation struct {
NetworkBandwidth int
Size int
Start time.Time
Stop time.Time
TimeDiff float64
}
/*
var args = "-hide_banner -loglevel panic -re -i " + url + " -codec copy -f mpegts pipe:1"
//var args = "-re -i " + url + " -codec copy -f mpegts pipe:1"
cmd := exec.Command("/usr/local/bin/ffmpeg", strings.Split(args, " ")...)
//run := exec.Command("/usr/local/bin/ffmpeg", "-hide_banner", "-loglevel", "panic", "-re", "-i", url, "-codec", "copy", "-f", "mpegts", "pipe:1")
//run := exec.Command("/usr/local/bin/ffmpeg", "-re", "-i", url, "-codec", "copy", "-f", "mpegts", "pipe:1")
stderr, _ := cmd.StderrPipe()
cmd.Start()
scanner := bufio.NewScanner(stderr)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
}
cmd.Wait()
os.Exit(0)
*/
/*
ffmpegOut, _ := run.StderrPipe()
//run.Start()
scanner = bufio.NewScanner(ffmpegOut)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
}
ffmpegOut, err = run.StdoutPipe()
if err != nil {
ShowError(err, 0)
return
}
stderr, stderrErr := run.StderrPipe()
if stderrErr != nil {
fmt.Println(stderrErr)
}
_ = stderr
if startErr := run.Start(); startErr != nil {
fmt.Println(startErr)
return
}
n, err := ffmpegOut.Read(buffer)
_ = n
_ = stream
_ = fileSize
if err != nil && err != io.EOF {
ShowError(err, 0)
addErrorToStream(err)
return
}
defer bufferFile.Close()
scanner = bufio.NewScanner(ffmpegOut)
for scanner.Scan() {
//fmt.Printf("%s\n", scanner.Text())
//fmt.Println(scanner)
thisLine := scanner.Text()
line := make([]byte, len(thisLine))
buffer = append(buffer, line...)
fmt.Println(len(buffer))
if len(buffer) > tmpFileSize {
if _, err := bufferFile.Write(buffer[:]); err != nil {
ShowError(err, 0)
addErrorToStream(err)
run.Process.Kill()
return
}
buffer = make([]byte, 1024*Settings.BufferSize*2)
debug = fmt.Sprintf("Buffer Status:Done (%s)", tmpFile)
showDebug(debug, 2)
bufferFile.Close()
stream.Status = true
playlist.Streams[streamID] = stream
BufferInformation.Store(playlistID, playlist)
tmpSegment++
tmpFile = fmt.Sprintf("%s%d.ts", tmpFolder, tmpSegment)
if clientConnection(stream) == false {
bufferFile.Close()
run.Process.Kill()
err = os.RemoveAll(stream.Folder)
if err != nil {
ShowError(err, 4005)
}
return
}
bufferFile, err = os.Create(tmpFile)
if err != nil {
addErrorToStream(err)
run.Process.Kill()
return
}
fileSize = 0
if n == 0 {
bufferFile.Close()
run.Process.Kill()
break
}
os.Exit(0)
}
}
*/