PDA

View Full Version : bytesAvailable() allways returning 0



updatelee
28th October 2012, 05:34
ok here is the background, Im trying to open /dev/dvb/adapter0/demux0 for read/write. I know the write (ioctl) is successful as I can see it setup in my kernel logs. but no matter what I try bytesAvailable() always returns 0.



dmx_fd = new QFile("/dev/dvb/adapter0/demux0");
if (!dmx_fd->open(QIODevice::ReadWrite))
cout << "open() failed" << endl;

struct dmx_sct_filter_params sctfilter;
memset(&sctfilter, 0, sizeof(struct dmx_sct_filter_params));
sctfilter.pid = 0x11;
sctfilter.timeout = 5000;
sctfilter.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC;

if (ioctl(dmx_fd->handle(), DMX_SET_FILTER, &sctfilter) == -1)
cout << "DEMUX: DMX_SET_FILTER" << endl;

cout << "isSequential() = " << dmx_fd->isSequential() << endl;
cout << "isReadable() = " << dmx_fd->isReadable() << endl;
cout << "bytesAvailable() = " << dmx_fd->bytesAvailable() << endl;

dmx_fd->waitForReadyRead(5000);
sleep(5);

cout << "isReadable() = " << dmx_fd->isReadable() << endl;
cout << "bytesAvailable() = " << dmx_fd->bytesAvailable() << endl;

buffer.clear();
buffer = dmx_fd->read(dmx_fd->bytesAvailable());
cout << "Length read: " << buffer.size() << endl;

ioctl(dmx_fd->handle(), DMX_STOP);
dmx_fd->close();


outputs



Starting /home/updatelee/src/untitled/untitled...
isSequential() = 1
isReadable() = 1
bytesAvailable() = 0
isReadable() = 1
bytesAvailable() = 0
Length read: 0
/home/updatelee/src/untitled/untitled exited with code 0


Ive got the adapter tuned by another app if anyone was wondering. The demux is ready to accept pids as I can use my C app on it just fine, as well as my b*stardized qt app with ::open() calls.

QMake version 2.01a
Using Qt version 4.8.3 in /usr/lib/x86_64-linux-gnu
Qt Creator 2.5.2

Any idea's ?

kuzulis
28th October 2012, 15:31
@updatelee

Because /dev/dvb/adapter0/demux0 is device, not file, and bytesAvailable() should be wrapper for ioctl().
Therefore QFile::bytesAvailable() will not work, because this implementation specific for the file system only.

You should be make custom class for "demux" device, inherited from QIODevice and implement all necessary methods,
include open(), close(), bytesAvailable() and so forth.

updatelee
28th October 2012, 16:22
Its just odd that I can write to it using QFile but not read.

the packet im receiving is 131 bytes long. (in this case, its not a constant depending on the signal Ive tuned, just in this case I know its 131 bytes long)



int BUFFY = 10*188*1024;
char buf[BUFFY];
memset(buf, 0, BUFFY);
int len = read(dmx_fd->handle(), buf, BUFFY);
cout << "Length read: " << len << endl;


outputs



Length read: 131




int BUFFY = 10*188*1024;
buffer.clear();
buffer = dmx_fd->read(BUFFY);
cout << "Length read: " << buffer.size() << endl;

application locks up on the read()



buffer.clear();
buffer = dmx_fd->read(131);
cout << "Length read: " << buffer.size() << endl;

application locks up on the read()



buffer.clear();
buffer = dmx_fd->read(1);
cout << "Length read: " << buffer.size() << endl;

application locks up on the read()

I just cant read anything from it. readAll() does the same. How can I write to it but not read from it ? lol just seems so odd that it wont work.

UDL