Ejemplo n.º 1
0
Archivo: filter.go Proyecto: ziutek/dvb
func setFilter(dmxpath, dvrpath string, pids []int16) (ts.PktReader, demux.StreamFilter) {
	filterParam := demux.StreamFilterParam{
		Pid:  pids[0],
		In:   demux.InFrontend,
		Out:  demux.OutTSDemuxTap,
		Type: demux.Other,
	}
	if dvrpath != "" {
		filterParam.Out = demux.OutTSTap
	}
	filter, err := demux.Device(dmxpath).NewStreamFilter(&filterParam)
	checkErr(err)
	for _, pid := range pids[1:] {
		checkErr(filter.AddPid(pid))
	}
	if dvrpath == "" {
		checkErr(filter.SetBufferSize(1024 * 188))
		checkErr(filter.Start())
		return ts.NewPktStreamReader(filter), filter
	}
	dvr, err := os.Open(dvrpath)
	checkErr(err)
	checkErr(filter.Start())
	return ts.NewPktStreamReader(dvr), filter
}
Ejemplo n.º 2
0
Archivo: main.go Proyecto: ziutek/dvb
func main() {
	if len(os.Args) != 4 {
		fmt.Fprintf(os.Stderr, "Usage: stream_file FILE BITRATE DESTINATION\n")
		os.Exit(1)
	}

	file, err := os.Open(os.Args[1])
	checkErr(err)
	r := ts.NewPktStreamReader(bufio.NewReader(file))

	bitrate, err := strconv.ParseUint(os.Args[2], 0, 64)
	checkErr(err)

	addr, err := net.ResolveUDPAddr("udp", os.Args[3])
	checkErr(err)
	conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4zero, Port: 0})
	checkErr(err)

	var (
		buf [7 * ts.PktLen]byte
		n   int
	)
	bps := time.Duration(bitrate)
	pktperiod := (time.Second*ts.PktLen*8 + bps/2) / bps
	sendt := time.Now()
	for {
		pkt := ts.AsPkt(buf[n:])
		err := r.ReadPkt(pkt)
		if err == nil {
			n += ts.PktLen
			if n == len(buf) {
				n = 0
				sendt = sendt.Add(pktperiod)
				time.Sleep(sendt.Sub(time.Now()))
				conn.WriteToUDP(buf[:], addr)
				//fmt.Printf("PID: %d\n", pkt.Pid())
			}
		} else if err == io.EOF {
			_, err := file.Seek(0, os.SEEK_SET)
			checkErr(err)
			os.Stdout.WriteString("seek\n")
		} else if _, ok := err.(dvb.TemporaryError); ok {
			fmt.Fprintf(os.Stderr, "temporary error:%v\n", err)
		} else {
			die(err)
		}
	}
}
Ejemplo n.º 3
0
Archivo: main.go Proyecto: ziutek/dvb
func main() {
	if len(os.Args) != 2 {
		fmt.Fprintf(
			os.Stderr,
			"Usage: %s ADDR:PORT|MADDR:PORT[@IFNAME]|FILE\n",
			filepath.Base(os.Args[0]),
		)
		os.Exit(1)
	}
	src := os.Args[1]

	var rp ts.PktReplacer

	if strings.IndexByte(src, ':') == -1 {
		f, err := os.Open(src)
		checkErr(err)
		rp = ts.NewPktStreamReader(f)
	} else {
		r, err := internal.ListenMulticastUDP(src, 17)
		if err == internal.ErrNotMulticast {
			r, err = internal.ListenUDP(src, 17)
		}
		checkErr(err)
		rp = ts.PktReaderAsReplacer{r}
	}
	d := psi.NewSectionDecoder(rp, true)
	fmt.Println("SID Provider Name Type Status Scrambled EIT(PresentFollowing/Schedule)")
	var sdt psi.SDT
	for {
		checkErr(sdt.Update(d, true, true))
		sl := sdt.ServiceInfo()
		for !sl.IsEmpty() {
			var si psi.ServiceInfo
			si, sl = sl.Pop()
			if si == nil {
				os.Stderr.WriteString("Error: demaged service list\n")
				break
			}
			sid := si.ServiceId()
			status := si.Status()
			scrambled := si.Scrambled()
			eitPF := si.EITPresentFollowing()
			eitSched := si.EITSchedule()
			var (
				name     string
				provider string
				typ      psi.ServiceType
			)
			dl := si.Descriptors()
			for len(dl) != 0 {
				var d psi.Descriptor
				d, dl = dl.Pop()
				if d == nil {
					os.Stderr.WriteString("Error: demaged descriptor list\n")
					break
				}
				if d.Tag() == psi.ServiceTag {
					sd, ok := psi.ParseServiceDescriptor(d)
					if !ok {
						os.Stderr.WriteString("Error: bad service descriptor\n")
						break
					}
					typ = sd.Type
					name = psi.DecodeText(sd.ServiceName)
					provider = psi.DecodeText(sd.ProviderName)
					break
				}
			}
			fmt.Printf(
				"%d \"%s\" \"%s\" \"%v\" %v %t %t/%t\n",
				sid, provider, name, typ, status, scrambled, eitPF, eitSched,
			)
		}
	}
}
Ejemplo n.º 4
0
Archivo: main.go Proyecto: ziutek/dvb
func main() {
	adapterPath := flag.String(
		"a", "/dev/dvb/adapter0",
		"path to the adapter directory",
	)
	frontendPath := flag.String(
		"f", "frontend0",
		"frontend path, relative to the adapter directory",
	)
	demuxPath := flag.String(
		"d", "demux0",
		"demux path, relative to the adapter directory",
	)
	flag.Usage = usage
	flag.Parse()

	args := flag.Args()

	if len(args) < 4 {
		usage()
		os.Exit(1)
	}

	freq, err := strconv.ParseInt(args[0], 0, 64)
	checkErr(err)
	freq *= 1e6

	var polar byte
	switch args[1] {
	case "v", "V":
		polar = 'v'
	case "h", "H":
		polar = 'h'
	default:
		die("wrong polarisation: " + args[1])
	}

	sr, err := strconv.ParseUint(args[2], 0, 32)
	checkErr(err)

	args = args[3:]
	pids := make([]int16, len(args))
	for i, a := range args {
		pid, err := strconv.ParseInt(a, 0, 64)
		checkErr(err)
		if uint64(pid) > 8192 {
			die(a + " isn't in valid PID range [0, 8192]")
		}
		pids[i] = int16(pid)
	}

	fe, err := frontend.Open(filepath.Join(*adapterPath, *frontendPath))
	checkErr(err)

	checkErr(fe.SetDeliverySystem(dvb.SysDVBS2))
	checkErr(fe.SetModulation(dvb.PSK8))
	checkErr(fe.SetRolloff(dvb.RolloffAuto))
	checkErr(fe.SetPilot(dvb.PilotAuto))
	checkErr(fe.SetSymbolRate(uint32(sr * 1e3)))
	checkErr(fe.SetInnerFEC(dvb.FECAuto))
	checkErr(fe.SetInversion(dvb.InversionAuto))
	ifreq, tone, volt := frontend.SecParam(freq, rune(polar))
	checkErr(fe.SetFrequency(ifreq))
	checkErr(fe.SetTone(tone))
	checkErr(fe.SetVoltage(volt))

	checkErr(fe.Tune())

	deadline := time.Now().Add(5 * time.Second)
	var ev frontend.Event
	for ev.Status()&frontend.HasLock == 0 {
		timedout, err := frontend.API3{fe}.WaitEvent(&ev, deadline)
		checkErr(err)
		if timedout {
			die("tuning timeout")
		}
		fmt.Fprintln(os.Stderr, ev.Status())
	}
	fmt.Fprintln(os.Stderr, "tuned!")

	dmx := demux.Device(filepath.Join(*adapterPath, *demuxPath))
	f, err := dmx.NewStreamFilter(
		&demux.StreamFilterParam{
			Pid:  pids[0],
			In:   demux.InFrontend,
			Out:  demux.OutTSDemuxTap,
			Type: demux.Other,
		},
	)
	checkErr(err)
	defer f.Close()

	for _, pid := range pids[1:] {
		checkErr(f.AddPid(pid))
	}
	checkErr(f.SetBufferSize(1024 * ts.PktLen))
	checkErr(f.Start())

	r := ts.NewPktStreamReader(f)
	pkt := new(ts.ArrayPkt)

	for {
		t := time.Now()
		n := 4000
		for i := 0; i < n; i++ {
			checkErr(r.ReadPkt(pkt))
		}
		dt := time.Now().Sub(t)
		pps := time.Duration(n) * time.Second / dt
		fmt.Printf("%d pkt/s (%d kb/s)\n", pps, pps*ts.PktLen*8/1000)
	}
}