Skip to content

Commit

Permalink
export VideoSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
fffilimonov committed Jan 30, 2024
1 parent 9dda644 commit 9edb74d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
58 changes: 29 additions & 29 deletions pkg/provider/embeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,47 @@ const (
)

type VideoSpec struct {
codec string
prefix string
height int
width int
kbps int
fps int
Codec string
Prefix string
Height int
Width int
Kbps int
Fps int
}

func (v *VideoSpec) Name() string {
ext := "h264"
if v.codec == vp8Codec {
if v.Codec == vp8Codec {
ext = "ivf"
}
size := strconv.Itoa(v.height)
if v.height > v.width {
size = fmt.Sprintf("p%d", v.width)
size := strconv.Itoa(v.Height)
if v.Height > v.Width {
size = fmt.Sprintf("p%d", v.Width)
}
return fmt.Sprintf("resources/%s_%s_%d.%s", v.prefix, size, v.kbps, ext)
return fmt.Sprintf("resources/%s_%s_%d.%s", v.Prefix, size, v.Kbps, ext)
}

func (v *VideoSpec) ToVideoLayer(quality livekit.VideoQuality) *livekit.VideoLayer {
return &livekit.VideoLayer{
Quality: quality,
Height: uint32(v.height),
Width: uint32(v.width),
Height: uint32(v.Height),
Width: uint32(v.Width),
Bitrate: v.bitrate(),
}
}

func (v *VideoSpec) bitrate() uint32 {
return uint32(v.kbps * 1000)
return uint32(v.Kbps * 1000)
}

func circlesSpec(width, kbps, fps int) *VideoSpec {
return &VideoSpec{
codec: h264Codec,
prefix: "circles",
height: width * 4 / 3,
width: width,
kbps: kbps,
fps: fps,
Codec: h264Codec,
Prefix: "circles",
Height: width * 4 / 3,
Width: width,
Kbps: kbps,
Fps: fps,
}
}

Expand All @@ -69,12 +69,12 @@ func createSpecs(prefix string, codec string, bitrates ...int) []*VideoSpec {
for i, b := range bitrates {
dimMultiple := int(math.Pow(2, float64(i)))
specs = append(specs, &VideoSpec{
prefix: prefix,
codec: codec,
kbps: b,
fps: videoFps[i],
height: 180 * dimMultiple,
width: 180 * dimMultiple * 16 / 9,
Prefix: prefix,
Codec: codec,
Kbps: b,
Fps: videoFps[i],
Height: 180 * dimMultiple,
Width: 180 * dimMultiple * 16 / 9,
})
}
return specs
Expand Down Expand Up @@ -117,7 +117,7 @@ func init() {
func randomVideoSpecsForCodec(videoCodec string) []*VideoSpec {
filtered := make([][]*VideoSpec, 0)
for _, specs := range videoSpecs {
if videoCodec == "" || specs[0].codec == videoCodec {
if videoCodec == "" || specs[0].Codec == videoCodec {
filtered = append(filtered, specs)
}
}
Expand Down Expand Up @@ -147,13 +147,13 @@ func CreateVideoLoopers(resolution string, codecFilter string, simulcast bool) (
return nil, err
}
defer f.Close()
if spec.codec == h264Codec {
if spec.Codec == h264Codec {
looper, err := NewH264VideoLooper(f, spec)
if err != nil {
return nil, err
}
loopers = append(loopers, looper)
} else if spec.codec == vp8Codec {
} else if spec.Codec == vp8Codec {
looper, err := NewVP8VideoLooper(f, spec)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/h264looper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type H264VideoLooper struct {
func NewH264VideoLooper(input io.Reader, spec *VideoSpec) (*H264VideoLooper, error) {
l := &H264VideoLooper{
spec: spec,
frameDuration: time.Second / time.Duration(spec.fps),
frameDuration: time.Second / time.Duration(spec.Fps),
}

buf := bytes.NewBuffer(nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/vp8looper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type VP8VideoLooper struct {
func NewVP8VideoLooper(input io.Reader, spec *VideoSpec) (*VP8VideoLooper, error) {
l := &VP8VideoLooper{
spec: spec,
frameDuration: time.Second / time.Duration(spec.fps),
frameDuration: time.Second / time.Duration(spec.Fps),
}

buf := bytes.NewBuffer(nil)
Expand Down

0 comments on commit 9edb74d

Please sign in to comment.