Exemple #1
0
func (v *VideoProc) SrvHTTP(hs *routing.HTTPSession) routing.HResult {
	var tid string
	var duration int64
	err := hs.ValidCheckVal(`
		tid,R|S,L:0;
		duration,R|I,R:0;
		`, &tid, &duration)
	if err != nil {
		return hs.Printf("valid argument error by %v", err)
	}
	var reader = bufio.NewReader(hs.R.Body)
	var frame = util.Map{}
	for {
		bys, err := util.ReadLine(reader, 102400, false)
		if err != nil {
			break
		}
		line := strings.Trim(string(bys), " \n\t")
		lines := strings.SplitN(line, "=", 2)
		lines[0] = strings.Trim(lines[0], " \t")
		if len(lines) < 2 {
			frame[lines[0]] = ""
		} else {
			frame[lines[0]] = lines[1]
		}
		if lines[0] != "progress" {
			continue
		}
		var progress Progress
		frame.ToS(&progress)
		var rate = float64(progress.OutTimeMs) / float64(duration)
		if int(rate*1000)%10 == 0 {
			log.D("NofityProc receive rate(%v%%) to task(%v),duration(%v)", int(rate*100), tid, duration)
		}
		err = v.NotifyProc(tid, rate)
		if err != nil {
			return hs.Printf("notify procgress to task(%v) error by %v", tid, err)
		}
		frame = util.Map{}
	}
	return hs.Printf("%v", "DONE")
}