2024-01-05 13:58:13 +00:00
|
|
|
package metadata
|
|
|
|
|
2024-03-01 08:01:30 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
|
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ msgpack.CustomDecoder = (*MediaFormat)(nil)
|
|
|
|
_ msgpack.CustomEncoder = (*MediaFormat)(nil)
|
|
|
|
)
|
2024-01-05 13:58:13 +00:00
|
|
|
|
|
|
|
type MediaFormat struct {
|
|
|
|
Subtype string
|
|
|
|
Role string
|
|
|
|
Ext string
|
|
|
|
Cid *encoding.CID
|
|
|
|
Height int
|
|
|
|
Width int
|
|
|
|
Languages []string
|
|
|
|
Asr int
|
|
|
|
Fps int
|
|
|
|
Bitrate int
|
|
|
|
AudioChannels int
|
|
|
|
Vcodec string
|
|
|
|
Acodec string
|
|
|
|
Container string
|
|
|
|
DynamicRange string
|
|
|
|
Charset string
|
|
|
|
Value []byte
|
|
|
|
Duration int
|
|
|
|
Rows int
|
|
|
|
Columns int
|
|
|
|
Index int
|
|
|
|
InitRange string
|
|
|
|
IndexRange string
|
|
|
|
Caption string
|
|
|
|
}
|
|
|
|
|
2024-03-01 08:01:30 +00:00
|
|
|
func (mmd *MediaFormat) EncodeMsgpack(encoder *msgpack.Encoder) error {
|
|
|
|
return errors.New("Not implemented")
|
|
|
|
}
|
|
|
|
|
2024-01-05 13:58:13 +00:00
|
|
|
func NewMediaFormat(subtype string, role, ext, vcodec, acodec, container, dynamicRange, charset, initRange, indexRange, caption string, cid *encoding.CID, height, width, asr, fps, bitrate, audioChannels, duration, rows, columns, index int, languages []string, value []byte) *MediaFormat {
|
|
|
|
return &MediaFormat{
|
|
|
|
Subtype: subtype,
|
|
|
|
Role: role,
|
|
|
|
Ext: ext,
|
|
|
|
Cid: cid,
|
|
|
|
Height: height,
|
|
|
|
Width: width,
|
|
|
|
Languages: languages,
|
|
|
|
Asr: asr,
|
|
|
|
Fps: fps,
|
|
|
|
Bitrate: bitrate,
|
|
|
|
AudioChannels: audioChannels,
|
|
|
|
Vcodec: vcodec,
|
|
|
|
Acodec: acodec,
|
|
|
|
Container: container,
|
|
|
|
DynamicRange: dynamicRange,
|
|
|
|
Charset: charset,
|
|
|
|
Value: value,
|
|
|
|
Duration: duration,
|
|
|
|
Rows: rows,
|
|
|
|
Columns: columns,
|
|
|
|
Index: index,
|
|
|
|
InitRange: initRange,
|
|
|
|
IndexRange: indexRange,
|
|
|
|
Caption: caption,
|
|
|
|
}
|
|
|
|
}
|
2024-03-01 08:01:30 +00:00
|
|
|
func (mmd *MediaFormat) DecodeMsgpack(dec *msgpack.Decoder) error {
|
|
|
|
intMap, err := decodeIntMap(dec)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for key, value := range intMap {
|
|
|
|
switch key {
|
|
|
|
case 1:
|
|
|
|
mmd.Cid, err = encoding.CIDFromBytes(value.([]byte))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
mmd.Subtype = value.(string)
|
|
|
|
case 3:
|
|
|
|
mmd.Role = value.(string)
|
|
|
|
case 4:
|
|
|
|
mmd.Ext = value.(string)
|
|
|
|
case 10:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Height = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 11:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Width = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 12:
|
2024-03-01 08:25:20 +00:00
|
|
|
vals := value.([]interface{})
|
|
|
|
|
|
|
|
for _, val := range vals {
|
|
|
|
mmd.Languages = append(mmd.Languages, val.(string))
|
|
|
|
}
|
2024-03-01 08:01:30 +00:00
|
|
|
case 13:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Asr = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 14:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Fps = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 15:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Bitrate = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 18:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.AudioChannels = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 19:
|
|
|
|
mmd.Vcodec = value.(string)
|
|
|
|
case 20:
|
|
|
|
mmd.Acodec = value.(string)
|
|
|
|
case 21:
|
|
|
|
mmd.Container = value.(string)
|
|
|
|
case 22:
|
|
|
|
mmd.DynamicRange = value.(string)
|
|
|
|
case 23:
|
|
|
|
mmd.Charset = value.(string)
|
|
|
|
case 24:
|
|
|
|
mmd.Value = value.([]byte)
|
|
|
|
case 25:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Duration = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 26:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Rows = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 27:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Columns = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 28:
|
2024-03-01 08:21:31 +00:00
|
|
|
mmd.Index = intParse(value)
|
2024-03-01 08:01:30 +00:00
|
|
|
case 29:
|
|
|
|
mmd.InitRange = value.(string)
|
|
|
|
case 30:
|
|
|
|
mmd.IndexRange = value.(string)
|
|
|
|
case 31:
|
|
|
|
mmd.Caption = value.(string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2024-03-01 08:21:31 +00:00
|
|
|
|
|
|
|
func intParse(value interface{}) int {
|
|
|
|
switch value.(type) {
|
|
|
|
case int:
|
|
|
|
return value.(int)
|
|
|
|
case uint:
|
|
|
|
return int(value.(uint))
|
|
|
|
case uint16:
|
|
|
|
return int(value.(uint16))
|
|
|
|
case uint32:
|
|
|
|
return int(value.(uint32))
|
|
|
|
case int16:
|
|
|
|
return int(value.(int16))
|
|
|
|
case int8:
|
|
|
|
return int(value.(int8))
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|