1 #include <linux/dvb/frontend.h>
2 #include <linux/dvb/dmx.h>
3 #include <linux/dvb/audio.h>
4 #include <linux/dvb/version.h>
11 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
16 unsigned int frequency;
19 static int search(int adapter_nr,struct channel *ch)
23 struct dvb_frontend_info info;
24 struct channel *channel;
25 struct dtv_property prop[3];
26 struct dtv_properties props;
30 sprintf(file, "/dev/dvb/adapter%d/frontend0", adapter_nr);
31 if ((fd = open(file, O_RDWR)) < 0) {
36 if (ioctl(fd, FE_GET_INFO, &info) < 0) {
37 perror("ioctl FE_GET_INFO");
41 if (info.type == FE_QPSK) {
43 //channel = lookup_channel(channel_id, isdbs_channels,
44 // ARRAY_SIZE(isdbs_channels));
45 } else if (info.type == FE_OFDM) {
47 //channel = lookup_channel(channel_id, isdbt_channels,
48 // ARRAY_SIZE(isdbt_channels));
50 fprintf(stderr, "Unknown type of adapter\n");
53 if (channel == NULL) {
54 fprintf(stderr, "Unknown id of channel\n");
58 prop[0].cmd = DTV_FREQUENCY;
59 prop[0].u.data = channel->frequency;
60 prop[1].cmd = DTV_ISDBS_TS_ID;
61 prop[1].u.data = channel->ts_id;
62 prop[2].cmd = DTV_TUNE;
67 if ((ioctl(fd, FE_SET_PROPERTY, &props)) < 0) {
68 perror("ioctl FE_SET_PROPERTY");
72 for (i = 0; i < 4; i++) {
73 if (ioctl(fd, FE_READ_STATUS, &status) < 0) {
74 perror("ioctl FE_READ_STATUS");
77 if (status & FE_HAS_LOCK) {
78 fprintf(stderr, "Successfully tuned to %d(%d) .\n",
79 channel->frequency,channel->ts_id);
85 fprintf(stderr, "Failed to tune to %s (status %02x).\n",
86 channel->name, status);
93 static int track(int adapter_nr)
97 struct dmx_pes_filter_params filter;
100 filter.input = DMX_IN_FRONTEND;
101 filter.output = DMX_OUT_TS_TAP;
102 filter.pes_type = DMX_PES_VIDEO;
103 filter.flags = DMX_IMMEDIATE_START;
105 sprintf(file, "/dev/dvb/adapter%d/demux0", adapter_nr);
106 if ((fd = open(file, O_RDWR)) < 0) {
112 if (ioctl(fd, DMX_SET_PES_FILTER, &filter) < 0) {
113 perror("ioctl DMX_SET_PES_FILTER");
124 int main(int argc, char *argv[]) {
132 fprintf(stderr, "Usage: %s adapter_nr freq [tsid]\n", argv[0]);
136 adapter_nr = strtol(argv[1], NULL, 0);
137 channel_freq = strtol(argv[2], NULL, 10);
140 channel_id = strtol(argv[3], NULL, 10);
142 struct channel ch1 ={0,"",channel_freq,channel_id};
144 //struct channel ch;//{ 1, "NHK BS-1", 1318000, 0x40f1 }
146 fd = search(adapter_nr, ch);
150 ret = track(adapter_nr);