Updating remote

This commit is contained in:
Unknown 2018-02-01 10:25:06 +10:30
parent 26430f1ff8
commit 333e18e1c6
2 changed files with 28 additions and 27 deletions

View File

@ -116,6 +116,7 @@ const (
defaultIntraRefreshPeriod = "100" defaultIntraRefreshPeriod = "100"
defaultTimeout = "0" defaultTimeout = "0"
defaultQuantization = "35" defaultQuantization = "35"
defaultBitrate = "0"
) )
// RevidInst provides methods to control a revidInst session; providing methods // RevidInst provides methods to control a revidInst session; providing methods
@ -215,10 +216,21 @@ func (r *revidInst) ChangeState(config Config) error {
switch config.InputCodec { switch config.InputCodec {
case H264: case H264:
if config.Bitrate != "" && config.Quantization != "" && (
(strconv.Atoi(config.Bitrate) > 0 && strconv.AtoI(config.Quantization) > 0) ||
(strconv.Atoi(config.Bitrate) == 0 && strconv.AtoI(config.Quantization) == 0) ){
return errors.New("Bad bitrate and quantization combination for H264 input!")
}
case Mjpeg: case Mjpeg:
if config.Quantization != "" && config.Quantization > 0 || config.Bitrate == "" {
return errors.New("Bad bitrate or quantization for mjpeg input!")
}
case NothingDefined: case NothingDefined:
r.Log(Warning, "No input codec defined, defaulting to h264!") r.Log(Warning, "No input codec defined, defaulting to h264!")
config.InputCodec = H264 config.InputCodec = H264
r.Log(Warning, "Defaulting bitrate to 0 and quantization to 35!")
config.Bitrate = defaultBitrate
config.Quantization = defaultQuantization
default: default:
return errors.New("Bad input codec defined in config!") return errors.New("Bad input codec defined in config!")
} }
@ -296,6 +308,7 @@ func (r *revidInst) ChangeState(config Config) error {
return errors.New("Bad quantization defined in config!") return errors.New("Bad quantization defined in config!")
} }
} }
r.config = config r.config = config
return nil return nil
} }
@ -332,12 +345,15 @@ func (r *revidInst) Start() {
switch r.config.InputCodec { switch r.config.InputCodec {
case H264: case H264:
codec = "H264" codec = "H264"
case Mjpeg:
codec = "MJPEG"
}
r.cmd = exec.Command("raspivid", r.cmd = exec.Command("raspivid",
"-cd", codec, "-cd", codec,
"-o", "-", "-o", "-",
"-n", "-n",
"-t", r.config.Timeout, "-t", r.config.Timeout,
"-b", "0", "-b", r.config.Bitrate,
"-qp", r.config.Quantization, "-qp", r.config.Quantization,
"-w", r.config.Width, "-w", r.config.Width,
"-h", r.config.Height, "-h", r.config.Height,
@ -345,18 +361,6 @@ func (r *revidInst) Start() {
"-ih", "-ih",
"-g", r.config.IntraRefreshPeriod, "-g", r.config.IntraRefreshPeriod,
) )
case Mjpeg:
codec = "MJPEG"
r.cmd = exec.Command("raspivid",
"-cd", codec,
"-o", "-",
"-n",
"-t", r.config.Timeout,
"-w", r.config.Width,
"-h", r.config.Height,
"-fps", r.config.FrameRate,
)
}
stdout, _ := r.cmd.StdoutPipe() stdout, _ := r.cmd.StdoutPipe()
err := r.cmd.Start() err := r.cmd.Start()
r.inputReader = bufio.NewReader(stdout) r.inputReader = bufio.NewReader(stdout)
@ -448,10 +452,6 @@ func (r *revidInst) packClips() {
case None: case None:
frame := <-r.mjpegOutputChan frame := <-r.mjpegOutputChan
upperBound := clipSize + len(frame) upperBound := clipSize + len(frame)
fmt.Printf("len(clip): %v\n", len(clip))
fmt.Printf("clipsize: %v\n", clipSize)
fmt.Printf("upperBound: %v\n", upperBound)
fmt.Printf("len(frame): %v\n", len(frame))
copy(clip[clipSize:upperBound], frame) copy(clip[clipSize:upperBound], frame)
packetCount++ packetCount++
clipSize += len(frame) clipSize += len(frame)

View File

@ -81,8 +81,9 @@ func TestRaspividMJPEGInput(t *testing.T){
Output: File, Output: File,
OutputFileName: "output/TestRaspividMjpegOutput.mjpeg", OutputFileName: "output/TestRaspividMjpegOutput.mjpeg",
Width: "1280", Width: "1280",
Bitrate: "1000000",
Height: "720", Height: "720",
Quantization: "20", Quantization: "0",
FrameRate: "25", FrameRate: "25",
} }
revidInst, err := NewRevidInstance(config) revidInst, err := NewRevidInstance(config)