You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lal/pkg/httpflv/flv_file_writer.go

65 lines
1.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// Copyright 2019, Chef. All rights reserved.
// https://github.com/q191201771/lal
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)
package httpflv
import (
"os"
"github.com/q191201771/lal/pkg/base"
)
// TODO chef: 结构体重命名为FileWriter文件名重命名为file_writer.go。所有写流文件的flv,hls,ts统一重构
type FlvFileWriter struct {
fp *os.File
}
func (ffw *FlvFileWriter) Open(filename string) (err error) {
ffw.fp, err = os.Create(filename)
return
}
func (ffw *FlvFileWriter) WriteRaw(b []byte) (err error) {
if ffw.fp == nil {
return base.ErrFileNotExist
}
_, err = ffw.fp.Write(b)
return
}
func (ffw *FlvFileWriter) WriteFlvHeader() (err error) {
if ffw.fp == nil {
return base.ErrFileNotExist
}
_, err = ffw.fp.Write(FlvHeader)
return
}
func (ffw *FlvFileWriter) WriteTag(tag Tag) (err error) {
if ffw.fp == nil {
return base.ErrFileNotExist
}
_, err = ffw.fp.Write(tag.Raw)
return
}
func (ffw *FlvFileWriter) Dispose() error {
if ffw.fp == nil {
return base.ErrFileNotExist
}
return ffw.fp.Close()
}
func (ffw *FlvFileWriter) Name() string {
if ffw.fp == nil {
return ""
}
return ffw.fp.Name()
}