diff options
author | Antti Palosaari <crope@iki.fi> | 2012-06-19 20:47:42 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-08-04 06:56:37 -0400 |
commit | 62a5f449cab52a458120ba5b046675ee2f81000f (patch) | |
tree | 6314d869d1cd81f91a3f0f6c49a5206f0aa26be7 /drivers/media/dvb | |
parent | 5cd983200ae8cba06d6ff5f515f741a654b62cf1 (diff) |
[media] dvb_usb_v2: refactor dvb_usb_ctrl_feed() logic
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r-- | drivers/media/dvb/dvb-usb/dvb_usb.h | 2 | ||||
-rw-r--r-- | drivers/media/dvb/dvb-usb/dvb_usb_dvb.c | 82 |
2 files changed, 36 insertions, 48 deletions
diff --git a/drivers/media/dvb/dvb-usb/dvb_usb.h b/drivers/media/dvb/dvb-usb/dvb_usb.h index 2bef8f4ab71a..a87a9ff579c4 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb.h +++ b/drivers/media/dvb/dvb-usb/dvb_usb.h | |||
@@ -300,7 +300,7 @@ struct dvb_usb_adapter { | |||
300 | u8 id; | 300 | u8 id; |
301 | u8 ts_type; | 301 | u8 ts_type; |
302 | int pid_filtering; | 302 | int pid_filtering; |
303 | int feedcount; | 303 | int feed_count; |
304 | int max_feed_count; | 304 | int max_feed_count; |
305 | 305 | ||
306 | /* sync frontend and streaming as those are different tasks */ | 306 | /* sync frontend and streaming as those are different tasks */ |
diff --git a/drivers/media/dvb/dvb-usb/dvb_usb_dvb.c b/drivers/media/dvb/dvb-usb/dvb_usb_dvb.c index f87319c788c0..384fe8eec21f 100644 --- a/drivers/media/dvb/dvb-usb/dvb_usb_dvb.c +++ b/drivers/media/dvb/dvb-usb/dvb_usb_dvb.c | |||
@@ -49,58 +49,54 @@ int dvb_usbv2_adapter_stream_exit(struct dvb_usb_adapter *adap) | |||
49 | } | 49 | } |
50 | 50 | ||
51 | /* does the complete input transfer handling */ | 51 | /* does the complete input transfer handling */ |
52 | static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) | 52 | static inline int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int count) |
53 | { | 53 | { |
54 | struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv; | 54 | struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv; |
55 | struct dvb_usb_device *d = adap_to_d(adap); | 55 | struct dvb_usb_device *d = adap_to_d(adap); |
56 | int newfeedcount, ret; | 56 | int ret; |
57 | 57 | pr_debug("%s: adap=%d active_fe=%d feed_type=%d setting pid [%s]: " \ | |
58 | if (adap == NULL) { | 58 | "%04x (%04d) at index %d '%s'\n", __func__, adap->id, |
59 | ret = -ENODEV; | 59 | adap->active_fe, dvbdmxfeed->type, |
60 | goto err; | 60 | adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid, |
61 | } | 61 | dvbdmxfeed->pid, dvbdmxfeed->index, |
62 | (count == 1) ? "on" : "off"); | ||
62 | 63 | ||
63 | pr_debug("%s: adap=%d active_fe=%d\n", __func__, adap->id, | 64 | if (adap->active_fe == -1) |
64 | adap->active_fe); | 65 | return -EINVAL; |
65 | 66 | ||
66 | newfeedcount = adap->feedcount + (onoff ? 1 : -1); | 67 | adap->feed_count += count; |
67 | 68 | ||
68 | /* stop feed before setting a new pid if there will be no pid anymore */ | 69 | /* stop feeding if it is last pid */ |
69 | if (newfeedcount == 0) { | 70 | if (adap->feed_count == 0) { |
70 | pr_debug("%s: stop feeding\n", __func__); | 71 | pr_debug("%s: stop feeding\n", __func__); |
71 | usb_urb_killv2(&adap->stream); | 72 | usb_urb_killv2(&adap->stream); |
72 | 73 | ||
73 | if (d->props->streaming_ctrl != NULL) { | 74 | if (d->props->streaming_ctrl) { |
74 | ret = d->props->streaming_ctrl(adap, 0); | 75 | ret = d->props->streaming_ctrl(adap, 0); |
75 | if (ret < 0) { | 76 | if (ret < 0) { |
76 | pr_err("%s: error while stopping stream\n", | 77 | pr_err("%s: streaming_ctrl() failed=%d\n", |
77 | KBUILD_MODNAME); | 78 | KBUILD_MODNAME, ret); |
78 | goto err_mutex_unlock; | 79 | goto err_mutex_unlock; |
79 | } | 80 | } |
80 | } | 81 | } |
81 | mutex_unlock(&adap->sync_mutex); | 82 | mutex_unlock(&adap->sync_mutex); |
82 | } | 83 | } |
83 | 84 | ||
84 | adap->feedcount = newfeedcount; | 85 | /* activate the pid on the device pid filter */ |
85 | |||
86 | /* activate the pid on the device specific pid_filter */ | ||
87 | pr_debug("%s: setting pid (%s): %5d %04x at index %d '%s'\n", __func__, | ||
88 | adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid, | ||
89 | dvbdmxfeed->pid, dvbdmxfeed->index, | ||
90 | onoff ? "on" : "off"); | ||
91 | if (adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER && | 86 | if (adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER && |
92 | adap->pid_filtering && | 87 | adap->pid_filtering && |
93 | adap->props->pid_filter != NULL) | 88 | adap->props->pid_filter) |
94 | adap->props->pid_filter(adap, dvbdmxfeed->index, | 89 | ret = adap->props->pid_filter(adap, dvbdmxfeed->index, |
95 | dvbdmxfeed->pid, onoff); | 90 | dvbdmxfeed->pid, (count == 1) ? 1 : 0); |
96 | 91 | if (ret < 0) | |
97 | /* | 92 | pr_err("%s: pid_filter() failed=%d\n", |
98 | * Start the feed if this was the first feed and there is still a feed | 93 | KBUILD_MODNAME, ret); |
99 | * for reception. | 94 | |
100 | */ | 95 | /* start feeding if it is first pid */ |
101 | if (adap->feedcount == onoff && adap->feedcount > 0) { | 96 | if (adap->feed_count == 1 && count == 1) { |
102 | struct usb_data_stream_properties stream_props; | 97 | struct usb_data_stream_properties stream_props; |
103 | mutex_lock(&adap->sync_mutex); | 98 | mutex_lock(&adap->sync_mutex); |
99 | pr_debug("%s: start feeding\n", __func__); | ||
104 | 100 | ||
105 | /* resolve input and output streaming paramters */ | 101 | /* resolve input and output streaming paramters */ |
106 | if (d->props->get_stream_config) { | 102 | if (d->props->get_stream_config) { |
@@ -128,54 +124,46 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) | |||
128 | break; | 124 | break; |
129 | } | 125 | } |
130 | 126 | ||
131 | pr_debug("%s: submitting all URBs\n", __func__); | ||
132 | usb_urb_submitv2(&adap->stream, &stream_props); | 127 | usb_urb_submitv2(&adap->stream, &stream_props); |
133 | 128 | ||
134 | pr_debug("%s: controlling pid parser\n", __func__); | ||
135 | if (adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER && | 129 | if (adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER && |
136 | adap->props->caps & | 130 | adap->props->caps & |
137 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF && | 131 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF && |
138 | adap->props->pid_filter_ctrl != NULL) { | 132 | adap->props->pid_filter_ctrl) { |
139 | ret = adap->props->pid_filter_ctrl(adap, | 133 | ret = adap->props->pid_filter_ctrl(adap, |
140 | adap->pid_filtering); | 134 | adap->pid_filtering); |
141 | if (ret < 0) { | 135 | if (ret < 0) { |
142 | pr_err("%s: could not handle pid_parser\n", | 136 | pr_err("%s: pid_filter_ctrl() failed=%d\n", |
143 | KBUILD_MODNAME); | 137 | KBUILD_MODNAME, ret); |
144 | goto err_mutex_unlock; | 138 | goto err_mutex_unlock; |
145 | } | 139 | } |
146 | } | 140 | } |
147 | pr_debug("%s: start feeding\n", __func__); | 141 | |
148 | if (d->props->streaming_ctrl != NULL) { | 142 | if (d->props->streaming_ctrl) { |
149 | ret = d->props->streaming_ctrl(adap, 1); | 143 | ret = d->props->streaming_ctrl(adap, 1); |
150 | if (ret < 0) { | 144 | if (ret < 0) { |
151 | pr_err("%s: error while enabling fifo\n", | 145 | pr_err("%s: streaming_ctrl() failed=%d\n", |
152 | KBUILD_MODNAME); | 146 | KBUILD_MODNAME, ret); |
153 | goto err_mutex_unlock; | 147 | goto err_mutex_unlock; |
154 | } | 148 | } |
155 | } | 149 | } |
156 | |||
157 | } | 150 | } |
158 | 151 | ||
159 | return 0; | 152 | return 0; |
160 | err_mutex_unlock: | 153 | err_mutex_unlock: |
161 | mutex_unlock(&adap->sync_mutex); | 154 | mutex_unlock(&adap->sync_mutex); |
162 | err: | ||
163 | pr_debug("%s: failed=%d\n", __func__, ret); | 155 | pr_debug("%s: failed=%d\n", __func__, ret); |
164 | return ret; | 156 | return ret; |
165 | } | 157 | } |
166 | 158 | ||
167 | static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed) | 159 | static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed) |
168 | { | 160 | { |
169 | pr_debug("%s: start pid=%04x feedtype=%d\n", __func__, dvbdmxfeed->pid, | ||
170 | dvbdmxfeed->type); | ||
171 | return dvb_usb_ctrl_feed(dvbdmxfeed, 1); | 161 | return dvb_usb_ctrl_feed(dvbdmxfeed, 1); |
172 | } | 162 | } |
173 | 163 | ||
174 | static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed) | 164 | static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed) |
175 | { | 165 | { |
176 | pr_debug("%s: stop pid=%04x feedtype=%d\n", __func__, dvbdmxfeed->pid, | 166 | return dvb_usb_ctrl_feed(dvbdmxfeed, -1); |
177 | dvbdmxfeed->type); | ||
178 | return dvb_usb_ctrl_feed(dvbdmxfeed, 0); | ||
179 | } | 167 | } |
180 | 168 | ||
181 | int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap) | 169 | int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap) |