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"
defaultTimeout = "0"
defaultQuantization = "35"
defaultBitrate = "0"
)
// RevidInst provides methods to control a revidInst session; providing methods
@ -215,10 +216,21 @@ func (r *revidInst) ChangeState(config Config) error {
switch config.InputCodec {
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:
if config.Quantization != "" && config.Quantization > 0 || config.Bitrate == "" {
return errors.New("Bad bitrate or quantization for mjpeg input!")
}
case NothingDefined:
r.Log(Warning, "No input codec defined, defaulting to h264!")
config.InputCodec = H264
r.Log(Warning, "Defaulting bitrate to 0 and quantization to 35!")
config.Bitrate = defaultBitrate
config.Quantization = defaultQuantization
default:
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!")
}
}
r.config = config
return nil
}
@ -332,31 +345,22 @@ func (r *revidInst) Start() {
switch r.config.InputCodec {
case H264:
codec = "H264"
r.cmd = exec.Command("raspivid",
"-cd", codec,
"-o", "-",
"-n",
"-t", r.config.Timeout,
"-b", "0",
"-qp", r.config.Quantization,
"-w", r.config.Width,
"-h", r.config.Height,
"-fps", r.config.FrameRate,
"-ih",
"-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,
)
}
r.cmd = exec.Command("raspivid",
"-cd", codec,
"-o", "-",
"-n",
"-t", r.config.Timeout,
"-b", r.config.Bitrate,
"-qp", r.config.Quantization,
"-w", r.config.Width,
"-h", r.config.Height,
"-fps", r.config.FrameRate,
"-ih",
"-g", r.config.IntraRefreshPeriod,
)
stdout, _ := r.cmd.StdoutPipe()
err := r.cmd.Start()
r.inputReader = bufio.NewReader(stdout)
@ -448,10 +452,6 @@ func (r *revidInst) packClips() {
case None:
frame := <-r.mjpegOutputChan
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)
packetCount++
clipSize += len(frame)

View File

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