-#define BUFFER_COUNT 32
-#define BUFFER_SIZE PAGE_ALIGN(0x4000)
-
-struct pvr2_dvb_fh {
- struct pvr2_channel channel;
- struct pvr2_stream *stream;
- struct pvr2_dvb_adapter *adap;
- wait_queue_head_t wait_data;
- char *buffer_storage[BUFFER_COUNT];
-};
-
-static void pvr2_dvb_notify(struct pvr2_dvb_fh *fhp)
-{
- wake_up(&fhp->wait_data);
-}
-
-static int pvr2_dvb_fh_init(struct pvr2_dvb_fh *fh,
- struct pvr2_dvb_adapter *adap)
-{
- struct pvr2_context *pvr = adap->pvr;
- unsigned int idx;
- int ret;
- struct pvr2_buffer *bp;
-
- init_waitqueue_head(&fh->wait_data);
-
- fh->adap = adap;
-
- pvr2_channel_init(&fh->channel, adap->pvr);
-
- ret = pvr2_channel_claim_stream(&fh->channel, &pvr->video_stream);
- /* somebody else already has the stream */
- if (ret != 0)
- return ret;
-
- fh->stream = pvr->video_stream.stream;
-
- for (idx = 0; idx < BUFFER_COUNT; idx++) {
- fh->buffer_storage[idx] = kmalloc(BUFFER_SIZE, GFP_KERNEL);
- if (!(fh->buffer_storage[idx]))
- break;
- }
-
- if (idx < BUFFER_COUNT) {
- /* An allocation appears to have failed */
- ret = -ENOMEM;
- goto cleanup;
- }
-
- pvr2_stream_set_callback(pvr->video_stream.stream,
- (pvr2_stream_callback) pvr2_dvb_notify, fh);
-
- ret = pvr2_stream_set_buffer_count(fh->stream, BUFFER_COUNT);
- if (ret < 0)
- return ret;
-
- for (idx = 0; idx < BUFFER_COUNT; idx++) {
- bp = pvr2_stream_get_buffer(fh->stream, idx);
- pvr2_buffer_set_buffer(bp,
- fh->buffer_storage[idx],
- BUFFER_SIZE);
- }
-
- ret = pvr2_hdw_set_streaming(fh->channel.hdw, 1);
- if (ret < 0)
- goto cleanup;
-
- while ((bp = pvr2_stream_get_idle_buffer(fh->stream)) != 0) {
- ret = pvr2_buffer_queue(bp);
- if (ret < 0)
- goto cleanup;
- }
-
- return ret;
-
-cleanup:
- if (fh->stream)
- pvr2_stream_kill(fh->stream);
-
- for (idx = 0; idx < BUFFER_COUNT; idx++) {
- if (!(fh->buffer_storage[idx]))
- continue;
-
- kfree(fh->buffer_storage[idx]);
- }
- pvr2_channel_done(&fh->channel);
-
- return ret;
-}
-
-static void pvr2_dvb_fh_done(struct pvr2_dvb_fh *fh)
-{
- unsigned int idx;
-
- pvr2_hdw_set_streaming(fh->channel.hdw, 0);
-
- pvr2_stream_kill(fh->stream);
-
-// pvr2_channel_claim_stream(&fh->channel, NULL);
-
- for (idx = 0; idx < BUFFER_COUNT; idx++) {
- if (!(fh->buffer_storage[idx]))
- continue;
-
- kfree(fh->buffer_storage[idx]);
- }
-
- pvr2_channel_done(&fh->channel);
-}
-