-
Notifications
You must be signed in to change notification settings - Fork 1
/
Media.go
61 lines (57 loc) · 1.26 KB
/
Media.go
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
package sofia
import (
"errors"
"io"
)
// ISO/IEC 14496-12
// aligned(8) class MediaBox extends Box('mdia') {
// }
type Media struct {
BoxHeader BoxHeader
Boxes []Box
MediaInformation MediaInformation
}
func (m *Media) read(r io.Reader, size int64) error {
r = io.LimitReader(r, size)
for {
var head BoxHeader
err := head.read(r)
if err == io.EOF {
return nil
} else if err != nil {
return err
}
switch head.debug() {
case "minf":
_, size := head.get_size()
m.MediaInformation.BoxHeader = head
err := m.MediaInformation.read(r, size)
if err != nil {
return err
}
case "hdlr", // Roku
"mdhd": // Roku
object := Box{BoxHeader: head}
err := object.read(r)
if err != nil {
return err
}
m.Boxes = append(m.Boxes, object)
default:
return errors.New("Media.read")
}
}
}
func (m Media) write(w io.Writer) error {
err := m.BoxHeader.write(w)
if err != nil {
return err
}
for _, object := range m.Boxes {
err := object.write(w)
if err != nil {
return err
}
}
return m.MediaInformation.write(w)
}