1 /* dvb-usb-dvb.c is part of the DVB USB library.
3 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
6 * This file contains functions for initializing and handling the
9 #include "dvb-usb-common.h"
11 /* does the complete input transfer handling */
12 static int dvb_usb_ctrl_feed(struct dvb_demux_feed
*dvbdmxfeed
, int onoff
)
14 struct dvb_usb_adapter
*adap
= dvbdmxfeed
->demux
->priv
;
15 int newfeedcount
, ret
;
20 newfeedcount
= adap
->feedcount
+ (onoff
? 1 : -1);
22 /* stop feed before setting a new pid if there will be no pid anymore */
23 if (newfeedcount
== 0) {
24 deb_ts("stop feeding\n");
25 usb_urb_kill(&adap
->stream
);
27 if (adap
->props
.streaming_ctrl
!= NULL
) {
28 ret
= adap
->props
.streaming_ctrl(adap
, 0);
30 err("error while stopping stream.");
36 adap
->feedcount
= newfeedcount
;
38 /* activate the pid on the device specific pid_filter */
39 deb_ts("setting pid (%s): %5d %04x at index %d '%s'\n",adap
->pid_filtering
?
40 "yes" : "no", dvbdmxfeed
->pid
,dvbdmxfeed
->pid
,dvbdmxfeed
->index
,onoff
?
42 if (adap
->props
.caps
& DVB_USB_ADAP_HAS_PID_FILTER
&&
43 adap
->pid_filtering
&&
44 adap
->props
.pid_filter
!= NULL
)
45 adap
->props
.pid_filter(adap
, dvbdmxfeed
->index
, dvbdmxfeed
->pid
,onoff
);
47 /* start the feed if this was the first feed and there is still a feed
50 if (adap
->feedcount
== onoff
&& adap
->feedcount
> 0) {
51 deb_ts("submitting all URBs\n");
52 usb_urb_submit(&adap
->stream
);
54 deb_ts("controlling pid parser\n");
55 if (adap
->props
.caps
& DVB_USB_ADAP_HAS_PID_FILTER
&&
57 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
&&
58 adap
->props
.pid_filter_ctrl
!= NULL
) {
59 ret
= adap
->props
.pid_filter_ctrl(adap
,
62 err("could not handle pid_parser");
66 deb_ts("start feeding\n");
67 if (adap
->props
.streaming_ctrl
!= NULL
) {
68 ret
= adap
->props
.streaming_ctrl(adap
, 1);
70 err("error while enabling fifo.");
79 static int dvb_usb_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
81 deb_ts("start pid: 0x%04x, feedtype: %d\n", dvbdmxfeed
->pid
,dvbdmxfeed
->type
);
82 return dvb_usb_ctrl_feed(dvbdmxfeed
,1);
85 static int dvb_usb_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
87 deb_ts("stop pid: 0x%04x, feedtype: %d\n", dvbdmxfeed
->pid
, dvbdmxfeed
->type
);
88 return dvb_usb_ctrl_feed(dvbdmxfeed
,0);
91 int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter
*adap
, short *adapter_nums
)
93 int ret
= dvb_register_adapter(&adap
->dvb_adap
, adap
->dev
->desc
->name
,
94 adap
->dev
->owner
, &adap
->dev
->udev
->dev
,
98 deb_info("dvb_register_adapter failed: error %d", ret
);
101 adap
->dvb_adap
.priv
= adap
;
102 adap
->dvb_adap
.fe_ioctl_override
= adap
->props
.fe_ioctl_override
;
104 if (adap
->dev
->props
.read_mac_address
) {
105 if (adap
->dev
->props
.read_mac_address(adap
->dev
,adap
->dvb_adap
.proposed_mac
) == 0)
106 info("MAC address: %pM",adap
->dvb_adap
.proposed_mac
);
108 err("MAC address reading failed.");
112 adap
->demux
.dmx
.capabilities
= DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
113 adap
->demux
.priv
= adap
;
115 adap
->demux
.feednum
= adap
->demux
.filternum
= adap
->max_feed_count
;
116 adap
->demux
.start_feed
= dvb_usb_start_feed
;
117 adap
->demux
.stop_feed
= dvb_usb_stop_feed
;
118 adap
->demux
.write_to_decoder
= NULL
;
119 if ((ret
= dvb_dmx_init(&adap
->demux
)) < 0) {
120 err("dvb_dmx_init failed: error %d",ret
);
124 adap
->dmxdev
.filternum
= adap
->demux
.filternum
;
125 adap
->dmxdev
.demux
= &adap
->demux
.dmx
;
126 adap
->dmxdev
.capabilities
= 0;
127 if ((ret
= dvb_dmxdev_init(&adap
->dmxdev
, &adap
->dvb_adap
)) < 0) {
128 err("dvb_dmxdev_init failed: error %d",ret
);
132 dvb_net_init(&adap
->dvb_adap
, &adap
->dvb_net
, &adap
->demux
.dmx
);
134 adap
->state
|= DVB_USB_ADAP_STATE_DVB
;
138 dvb_dmx_release(&adap
->demux
);
140 dvb_unregister_adapter(&adap
->dvb_adap
);
145 int dvb_usb_adapter_dvb_exit(struct dvb_usb_adapter
*adap
)
147 if (adap
->state
& DVB_USB_ADAP_STATE_DVB
) {
148 deb_info("unregistering DVB part\n");
149 dvb_net_release(&adap
->dvb_net
);
150 adap
->demux
.dmx
.close(&adap
->demux
.dmx
);
151 dvb_dmxdev_release(&adap
->dmxdev
);
152 dvb_dmx_release(&adap
->demux
);
153 dvb_unregister_adapter(&adap
->dvb_adap
);
154 adap
->state
&= ~DVB_USB_ADAP_STATE_DVB
;
159 static int dvb_usb_fe_wakeup(struct dvb_frontend
*fe
)
161 struct dvb_usb_adapter
*adap
= fe
->dvb
->priv
;
163 dvb_usb_device_power_ctrl(adap
->dev
, 1);
171 static int dvb_usb_fe_sleep(struct dvb_frontend
*fe
)
173 struct dvb_usb_adapter
*adap
= fe
->dvb
->priv
;
178 return dvb_usb_device_power_ctrl(adap
->dev
, 0);
181 int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter
*adap
)
183 if (adap
->props
.frontend_attach
== NULL
) {
184 err("strange: '%s' #%d doesn't want to attach a frontend.",adap
->dev
->desc
->name
, adap
->id
);
188 /* re-assign sleep and wakeup functions */
189 if (adap
->props
.frontend_attach(adap
) == 0 && adap
->fe
!= NULL
) {
190 adap
->fe_init
= adap
->fe
->ops
.init
; adap
->fe
->ops
.init
= dvb_usb_fe_wakeup
;
191 adap
->fe_sleep
= adap
->fe
->ops
.sleep
; adap
->fe
->ops
.sleep
= dvb_usb_fe_sleep
;
193 if (dvb_register_frontend(&adap
->dvb_adap
, adap
->fe
)) {
194 err("Frontend registration failed.");
195 dvb_frontend_detach(adap
->fe
);
200 /* only attach the tuner if the demod is there */
201 if (adap
->props
.tuner_attach
!= NULL
)
202 adap
->props
.tuner_attach(adap
);
204 err("no frontend was attached by '%s'",adap
->dev
->desc
->name
);
209 int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter
*adap
)
211 if (adap
->fe
!= NULL
) {
212 dvb_unregister_frontend(adap
->fe
);
213 dvb_frontend_detach(adap
->fe
);