Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linux-dvb] ?: How I can recording video PES to a file with NAPI



Hi!


We have a SIEMENS DVB-S card. We would like capture from the card a video
pes stream and write it to a file. I have made the follows steps, but
it unfortunately don't functional, I can't anything to read from
/dev/ost/demux. My program is:

---

#include <sys/ioctl.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <sys/poll.h>
#include <errno.h>

#include <ost/sec.h>
#include <ost/frontend.h>
#include <ost/dmx.h>

#define SECDEV          "/dev/ost/sec"
#define FRONTENDDEV     "/dev/ost/qpskfe"
#define DEMUXDEV        "/dev/ost/demux"
#define BUFFSIZE        8192 // 2 * maximum size of a section
#define NFD             1
#define FALSE           0
#define TRUE            1
//#define WE_WANT_DEBUG


unsigned long convertFreq(unsigned long wantedFreq) {
    if (wantedFreq < 11800UL) {
	return ((wantedFreq - 9750UL) * 1000000UL);
    }
    else {
        return ((wantedFreq - 10600UL) * 1000000UL);
    }
}

unsigned long convertSr(unsigned long wantedSr) {
    return (wantedSr * 1000);
}

int main(int argc, char **argv) {
    char *file;
    char *secDev = SECDEV;
    char *frontendDev = FRONTENDDEV;
    char *demuxDev = DEMUXDEV;
    int fileFd;
    int secDevFd;
    int frontendDevFd;
    int demuxDevFd;
    secToneMode mySecToneMode;
    secVoltage mySecVoltage;
    struct qpskParameters myQpskParams;
        unsigned long wantedFreq;
        unsigned long wantedSr;
    struct dmxPesFilterParams myDmxPesFilterParams;
    char buffer[BUFFSIZE];
    int retValue;
    int readCount;
    int writtenCount;


    if (argc != 2) {
        printf("usage: %s <filename> \n", *(argv + 0));
        return -1;
    }
    else { file = *(argv + 1); }

    fprintf(stderr, " \n");

// file
    if ((fileFd = open(file, O_WRONLY)) < 0) {
        perror("File open O_WRONLY error");
        return -1;
    }
    else { fprintf(stderr, "%s file opened for O_WRONLY, fileFd = %d \n", file, fileFd); }

// SET CHANNEL:
// VOX - HOTBIRD D 127 11.054 H W DEUTSCHE TELEKOM DIGITAL PLATF DVB 5/6 27.5 CLEAR GERMAN 24
//
// Channel: VOX
// Frequency: 11054
// CBHC: 255 0 0 255
// NI: -1 0
// SAT: 1 27500 4 500 501 1 1 0

// /dev/ost/sec ( for 22khz, voltage )
// /dev/ost/qpskfe ( for frequency, symbolrate, fec )
// /dev/ost/demux (for vpid, apid)

// sec
    if ((secDevFd = open(secDev, O_RDWR)) < 0) {
        perror("Sec device open O_RDWR error");
        return -1;
    }
    else { fprintf(stderr, "%s sec device opened for O_RDWR, secDevFd = %d \n", secDev, secDevFd); }

    mySecToneMode = SEC_TONE_OFF; // 22KHz (ttk) (freq < 118000UL) ? 0 : 1
    if (ioctl(secDevFd, SEC_SET_TONE, mySecToneMode) < 0) {
        perror("SEC_SET_TONE");
        return -1;
    }
    else { fprintf(stderr, "SEC_SET_TONE set \n"); }
    mySecVoltage = SEC_VOLTAGE_18; // 14V/18V (V=0/H=1)
    if (ioctl(secDevFd, SEC_SET_VOLTAGE, mySecVoltage) < 0) {
        perror("SEC_SET_VOLTAGE");
        return -1;
    }
    else { fprintf(stderr, "SEC_SET_VOLTAGE set \n"); }

// frontend
    if ((frontendDevFd = open(frontendDev, O_RDWR)) < 0) {
        perror("Frontend device open O_RDWR error");
        return -1;
    }
    else { fprintf(stderr, "%s frontend device opened for O_RDWR, frontendDevFd = %d \n", frontendDev, frontendDevFd); }

    wantedFreq  = 11054;
    wantedSr    = 27500;

    myQpskParams.iFrequency     = convertFreq(wantedFreq);
    myQpskParams.SymbolRate     = convertSr(wantedSr);
    myQpskParams.FEC_inner      = 4;
    if (ioctl(frontendDevFd, QPSK_TUNE, &myQpskParams) < 0) {
        perror("QPSK_TUNE");
        return -1;
    }
    else { fprintf(stderr, "QPSK_TUNE set \n"); }

// demux
    if ((demuxDevFd = open(demuxDev, O_RDWR | O_NONBLOCK)) < 0) {
        perror("Demux device open O_RDWR | O_NONBLOCK error");
        return -1;
    }
    else { fprintf(stderr, "%s demux device opened for O_RDWR | O_NONBLOCK, demuxDevFd = %d \n", demuxDev, demuxDevFd); }

    myDmxPesFilterParams.pid            = 500; // VOX video_pes_pid
    myDmxPesFilterParams.input          = DMX_IN_FRONTEND;
    myDmxPesFilterParams.output         = DMX_OUT_TAP;
    myDmxPesFilterParams.pesType        = DMX_PES_VIDEO;
    myDmxPesFilterParams.flags          = DMX_IMMEDIATE_START;
    if (ioctl(demuxDevFd, DMX_SET_PES_FILTER, &myDmxPesFilterParams) < 0) {
        perror("DMX_SET_PES_FILTER");
        return -1;
    }
    else { fprintf(stderr, "DMX_SET_PES_FILTER set \n"); }

// the motor
    while (TRUE) {
        readCount = 0;
        while (readCount < BUFFSIZE) {
            retValue =  read(demuxDevFd, buffer, BUFFSIZE - readCount);
            if (retValue < 0) {
        	perror("Demux device read error");
		return -1;
            }
            else
            {
        	readCount += retValue;
#if defined WE_WANT_DEBUG
                fprintf(stderr, "%d Bytes read \n", retValue);
		fprintf(stderr, "%d Bytes read \n", readCount);
#endif
            }
	}
        writtenCount = 0;
        while (writtenCount < BUFFSIZE) {
            retValue =  write(fileFd, buffer, BUFFSIZE);
	    if (retValue < 0) {
    	        perror("File write error");
		return -1;
            }
	    else
	    {
        	writtenCount += retValue;
#if defined WE_WANT_DEBUG
        	fprintf(stderr, "%d Bytes read \n", retValue);
        	fprintf(stderr, "%d Bytes read \n", writtenCount);
#endif
	    }
	}
    }

    close(demuxDevFd);
    close(frontendDevFd);
    close(secDevFd);
    close(fileFd);

    fprintf(stderr, "\n");
    fprintf(stderr, "end of the demux capture \n");

    return 0;
}

---

Sorry to the lot of text and my bad grammar.

I have setted the sec (/dev/ost/sec - for 22khz, voltage), the frontend
(/dev/ost/qpskfe - for frequency, symbolrate, fec) and the demux
(/dev/ost/demux - for vpid, apid) devices properly, but I can nothing data
read from /dev/ost/demux device. I have tried it to read also with poll()
on /dev/ost/demux ( if (pfd[0].revents & POLLIN) { ... ), but the device
is never ready for reading. What kind of mistake have I made or how can I
read a wanted VIDEO_PES from the satellit TS via DVB card, must I use the
old API (v4l)? Can I both PES simultaneously read (e.g. DMX_PES_AUDIO and
DMX_PES_VIDEO)?


Thanks,
Peter

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Peter Varga Zsager
Phone:  +36-72-253947 (weekend)
Mobile: +36-30-2950386
E-mail: jagger@sch.bme.hu



--- 
Info:
To unsubscribe send a mail to listar@linuxtv.org with "unsubscribe linux-dvb" as subject.



Home | Main Index | Thread Index