Mailing List archive

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

[linux-dvb] example again



ok, any idea why I get snr 0 all the time?

This is todays cvs, and tzap or the following minimal code. Have I missed
something stupid/obvious? 

#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>

#include <linux/dvb/frontend.h>
#include <linux/dvb/dmx.h>

#define FRONTEND "/dev/dvb/adapter0/frontend0"
#define DEMUX "/dev/dvb/adapter0/demux0"
#define DVR "/dev/dvb/adapter0/dvr0"

#define SIZE 1024

int main(int argc, char ** argv) {
  struct dvb_frontend_info info;
  struct dvb_frontend_parameters frontend;
  struct dmx_pes_filter_params pesfilter;
  int fd, fdd, fdts;
  uint16_t strength, snr;
  fe_status_t status;
  int buffersize = 64 * 1024;
  char buffer[SIZE];
  int pid = 0;

  /* example settings (UK: Crystal Palace MUX 1)*/
  uint32_t frequency = 50583333;
  fe_spectral_inversion_t inversion = INVERSION_OFF;
  fe_bandwidth_t bandwidth = BANDWIDTH_8_MHZ;
  fe_code_rate_t coderateHP = FEC_2_3;
  fe_code_rate_t coderateLP = FEC_NONE;
  fe_modulation_t modulation = QAM_64;
  fe_transmit_mode_t transmission = TRANSMISSION_MODE_2K;
  fe_guard_interval_t guard = GUARD_INTERVAL_1_32;
  fe_hierarchy_t hierarchy = HIERARCHY_NONE;


  if ((fd = open (FRONTEND, O_RDWR)) < 0) {
    perror ("frontend open failed");
    return -1;
  }
  
  ioctl (fd, FE_GET_INFO, &info);

  fprintf(stderr, "card found: %s\n", info.name);

  if (info.type != FE_OFDM)
    fprintf(stderr, "warning: this program understands DVB-T best\n");

  frontend.frequency = frequency;
  frontend.inversion = inversion;
  frontend.u.ofdm.bandwidth = bandwidth;
  frontend.u.ofdm.code_rate_HP = coderateHP;
  frontend.u.ofdm.code_rate_LP = coderateLP;
  frontend.u.ofdm.constellation = modulation;
  frontend.u.ofdm.transmission_mode = transmission;
  frontend.u.ofdm.guard_interval = guard;
  frontend.u.ofdm.hierarchy_information = hierarchy;

  fprintf (stderr, "tuning to %i Hz\n", frontend.frequency);
  
  if (ioctl(fd, FE_SET_FRONTEND, &frontend) < 0) {
    perror("ioctl FE_SET_FRONTEND failed");
    close(fd);
    return -1;
  }

  usleep(100000);

  ioctl(fd, FE_READ_SIGNAL_STRENGTH, &strength);
  ioctl(fd, FE_READ_SNR, &snr);

  fprintf(stderr, "signal strength %d SNR %d\n", strength, snr);

  ioctl(fd, FE_READ_STATUS, &status);
  if (status & FE_HAS_LOCK)
    fprintf(stderr, "FE_HAS_LOCK\n");
  else
    fprintf(stderr, "no lock...\n");

  if ((fdd = open(DEMUX, O_RDWR)) < 0) {
   perror ("demux open failed");
   return -1;
  }

  if (ioctl(fdd, DMX_SET_BUFFER_SIZE, buffersize) == -1)
    perror("DMX_SET_BUFFER_SIZE failed");

  pesfilter.pid = pid; // ?
  pesfilter.input = DMX_IN_FRONTEND;
  pesfilter.output = DMX_OUT_TS_TAP;
  pesfilter.pes_type = DMX_PES_VIDEO;
  pesfilter.flags = DMX_IMMEDIATE_START;

  if (ioctl(fdd, DMX_SET_PES_FILTER, &pesfilter) == -1) {
    fprintf(stderr, "DMX_SET_PES_FILTER failed "
	    "(PID = 0x%04x): %d %m\n", pid, errno);
    return -1;
  }

  if ((fdts = open(DVR, O_RDONLY)) < 0) {
   perror ("dvr open failed");
   return -1;
  }

  while (read(fdts, buffer, SIZE) > 0)
    write(STDOUT_FILENO, buffer, SIZE);

  return 0;
}


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



Home | Main Index | Thread Index