pike.git / src / modules / DVB / dvb.c

version» Context lines:

pike.git/src/modules/DVB/dvb.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: dvb.c,v 1.19 2003/04/07 17:24:37 nilsson Exp $ + || $Id: dvb.c,v 1.20 2003/05/12 20:21:33 mast Exp $   */      /*    * DVB module    *    * Creator: Honza Petrous <hop@unibase.cz>    *    * Credits:    * + Tuner zapping code inspired on 'szap' app from linux DVB driver    * package
pike.git/src/modules/DVB/dvb.c:285:    *! @member string "biterbi"    *! If 1 then lock at viterbi state    *! @member string "sync"    *! If 1 then TS sync byte detected    *! @member string "tuner_lock"    *! If 1 then tuner has a frequency lock    *! @endmapping    */   static void f_fe_status(INT32 args) {    +  dvb_data *dvb = DVB;    uint32_t status;    int cnt = 0, ret;       pop_n_elems(args);    THREADS_ALLOW(); -  ret = ioctl(DVB->fefd, FE_READ_STATUS, &status); +  ret = ioctl(dvb->fefd, FE_READ_STATUS, &status);    THREADS_DISALLOW();    if(ret < 0)    push_int(0);    else {    push_text("power"); push_int(!!(status & ~FE_HAS_POWER));    push_text("signal"); push_int(!!(status & ~FE_HAS_SIGNAL));    /*push_text("spectrum_inverse"); push_int(status & ~FE_HAS_SPECTRUM_INV);*/    push_text("lock"); push_int(!!(status & ~FE_HAS_LOCK));    push_text("carrier"); push_int(!!(status & ~FE_HAS_CARRIER));    push_text("viterbi"); push_int(!!(status & ~FE_HAS_VITERBI));    push_text("sync"); push_int(!!(status & ~FE_HAS_SYNC));    push_text("tuner_lock"); push_int(!!(status & ~FE_TUNER_HAS_LOCK));    cnt = 7;    THREADS_ALLOW(); -  ret = ioctl(DVB->fefd, FE_READ_BER, &status); +  ret = ioctl(dvb->fefd, FE_READ_BER, &status);    THREADS_DISALLOW();    if(ret > -1) {    push_text("ber"); push_int(status);    cnt++;    }    THREADS_ALLOW(); -  ret = ioctl(DVB->fefd, FE_READ_SNR, &status); +  ret = ioctl(dvb->fefd, FE_READ_SNR, &status);    THREADS_DISALLOW();    if(ret > -1) {    push_text("snr"); push_int(status);    cnt++;    }    THREADS_ALLOW(); -  ret = ioctl(DVB->fefd, FE_READ_SIGNAL_STRENGTH, &status); +  ret = ioctl(dvb->fefd, FE_READ_SIGNAL_STRENGTH, &status);    THREADS_DISALLOW();    if(ret > -1) {    push_text("signal_strength"); push_int(status);    cnt++;    }       f_aggregate_mapping(2 * cnt);    }   }      /*! @decl mapping fe_info()    *!    *! Return info of a frondend device.    *!    *! @note    *! The information heavily depends on driver. Many fields    *! contain dumb values.    */   static void f_fe_info(INT32 args) {    -  +  dvb_data *dvb = DVB;    FrontendInfo info;    int ret;       pop_n_elems(args);    THREADS_ALLOW(); -  ret = ioctl(DVB->fefd, FE_GET_INFO, &info); +  ret = ioctl(dvb->fefd, FE_GET_INFO, &info);    THREADS_DISALLOW();    if(ret < 0)    push_int(0);    else {    push_text("frequency");    push_text("min"); push_int(info.minFrequency);    push_text("max"); push_int(info.maxFrequency);    f_aggregate_mapping(2 * 2);    push_text("sr");    push_text("min"); push_int(info.minSymbolRate);
pike.git/src/modules/DVB/dvb.c:467:    *!    *! @param pol    *! Polarization. @expr{0@} or @expr{"v"@} for vertical type,    *! @expr{1@} or @expr{"h"@} for horizontal one.    *!    *! @param sr    *! The service rate parameter.    *!    */   static void f_zap(INT32 args) { +  dvb_data *dvb = DVB;    int secfd;    uint ifreq;    int hiband, result;    FrontendInfo fe_info;       int satno;    uint freq;    int pol;    uint sr;    char *devname;
pike.git/src/modules/DVB/dvb.c:496:    else    pol = Pike_sp[-1].u.string->str[0] == 'V' ||    Pike_sp[-1].u.string->str[0] == 'v';    Pike_sp--;       freq = (u_short)Pike_sp[-1].u.integer * 1000;    Pike_sp--;       satno = (u_short)Pike_sp[-1].u.integer;    -  if((devname = mk_devname(DVB->cardn, SECDEVICE)) == NULL) +  if((devname = mk_devname(dvb->cardn, SECDEVICE)) == NULL)    Pike_error("Internal error: can't malloc buffer.\n");    secfd = open (devname, O_RDWR);    /* free(devname); */    if (secfd == -1) {    Pike_error ("opening SEC device failed\n");    }    THREADS_ALLOW(); -  result = ioctl (DVB->fefd, FE_GET_INFO, &fe_info); +  result = ioctl (dvb->fefd, FE_GET_INFO, &fe_info);    THREADS_DISALLOW();    if (result == -1 || fe_info.type != FE_QPSK) {    close (secfd);    Pike_error("ioctl on fefd failed\n");    }       hiband = (freq >= SWITCHFREQ);    if (hiband)    ifreq = freq - LOF_HI;    else    ifreq = freq - LOF_LO;       result = 0;    if (diseqc (secfd, satno, pol, hiband)) -  if (do_tune (DVB->fefd, ifreq, sr)) +  if (do_tune (dvb->fefd, ifreq, sr))    result = 1;       close (secfd);       if(!result) -  Pike_error(DVB->low_errmsg); +  Pike_error(dvb->low_errmsg);       push_int(result);   }         /*! @decl mapping|int get_pids()    *!    *! Returns mapping with info of currently tuned program's pids.    *!    *! @seealso
pike.git/src/modules/DVB/dvb.c:1296:    *! Read data from a stream. It reads up to read buffer size data.    *!    *! @note    *! Read buffer size is 4096 by default.    *!    *! @seealso    *! @[DVB.dvb()->stream()], @[close()]    */   static void f_stream_read(INT32 args) {    +  dvb_stream_data *dvb_stream = DVBStream;    int all = 1, ret, e, cnt, ix = 0;    char buf[MAX_DVB_READ_SIZE], *bufptr;    -  if(DVBStream->fd < 0) +  if(dvb_stream->fd < 0)    Pike_error("Object destroyed!\n");       check_all_args("DVB.dvb->stream_read", args, BIT_INT | BIT_VOID, 0);    if(args > 1)    all = (u_short)Pike_sp[-1].u.integer;    pop_n_elems(args);    -  if(DVBStream->pkt.payload_len > 0) -  memcpy(buf, DVBStream->pkt.payload, DVBStream->pkt.payload_len); +  if(dvb_stream->pkt.payload_len > 0) +  memcpy(buf, dvb_stream->pkt.payload, dvb_stream->pkt.payload_len);    for(;;) {    e = 0;    THREADS_ALLOW(); -  ret = read(DVBStream->fd, buf + DVBStream->pkt.payload_len, -  DVBStream->buflen - DVBStream->pkt.payload_len); +  ret = read(dvb_stream->fd, buf + dvb_stream->pkt.payload_len, +  dvb_stream->buflen - dvb_stream->pkt.payload_len);    e = errno; /* check_threads_etc may effect errno */    THREADS_DISALLOW();       /* check_threads_etc(); */       if (ret > 0) { -  ret += DVBStream->pkt.payload_len; +  ret += dvb_stream->pkt.payload_len;    break;    }    if (ret == -1 && (e == EAGAIN || e == EINTR)) {    push_int(0);    return;    }   #if 0    if (!(ret == 0) || (ret == -1 && (e == EAGAIN || e == EINTR))) {   #ifdef DEBUG    printf("DEB: dvb: stream_read: errno=%d [%s]\n", e, strerror(e));   #endif    push_int(-e);    return;    }   #endif    }       if(ret > 0) {    bufptr = buf; -  while((cnt = dvb_pes2es(bufptr,ret,&DVBStream->pkt, 0xC0)) > 0) { +  while((cnt = dvb_pes2es(bufptr,ret,&dvb_stream->pkt, 0xC0)) > 0) {   #ifdef DVB_DEBUG -  /* printf("DEB: dvb: PID(%d): cnt=%d (ix: %d): pkt.len=%d (skipped: %d)\n", DVBStream->pid, cnt, ix, DVBStream->pkt.payload_len, DVBStream->pkt.skipped); */ -  if(DVBStream->pkt.skipped) -  printf("PID(%d): skipped: %d\n", DVBStream->pid, DVBStream->pkt.skipped); +  /* printf("DEB: dvb: PID(%d): cnt=%d (ix: %d): pkt.len=%d (skipped: %d)\n", dvb_stream->pid, cnt, ix, dvb_stream->pkt.payload_len, dvb_stream->pkt.skipped); */ +  if(dvb_stream->pkt.skipped) +  printf("PID(%d): skipped: %d\n", dvb_stream->pid, dvb_stream->pkt.skipped);   #endif -  push_string(make_shared_binary_string((char *)DVBStream->pkt.payload, -  DVBStream->pkt.payload_len)); -  DVBStream->pkt.payload_len = 0; /* clear internall buffer */ +  push_string(make_shared_binary_string((char *)dvb_stream->pkt.payload, +  dvb_stream->pkt.payload_len)); +  dvb_stream->pkt.payload_len = 0; /* clear internall buffer */    ix++;    bufptr += cnt;    ret -= cnt;    if(ret < 1)    break;    }    if(ix)    f_add(ix);    if(ret && ix) {    /* some unprocessed data remain in buf */ -  memcpy(DVBStream->pkt.payload, bufptr, ret); -  DVBStream->pkt.payload_len = ret; +  memcpy(dvb_stream->pkt.payload, bufptr, ret); +  dvb_stream->pkt.payload_len = ret;    }   #ifdef DVB_DEBUG    printf("DEB: dvb: ret=%d (ix: %d)\n", ret, ix);   #endif    return;    }    push_int(0);      }   
pike.git/src/modules/DVB/dvb.c:1447:   /*! @decl int mute(int mute)    *! @decl int mute()    *!    *! Mute or unmute audio device.    *!    *| @seealso    *| @[mixer()]    */   static void f_audio_mute(INT32 args) {    +  dvb_audio_data *dvb_audio = DVBAudio;    int mute = 1; /* default is mute = on */    int ret;       check_all_args("DVB.dvb->audio_mute", args, BIT_INT | BIT_VOID, 0);       if(args) {    mute = (u_short)Pike_sp[-1].u.integer;    Pike_sp--;    }       THREADS_ALLOW(); -  ret = ioctl(DVBAudio->fd, AUDIO_SET_MUTE, mute); +  ret = ioctl(dvb_audio->fd, AUDIO_SET_MUTE, mute);    THREADS_DISALLOW();    if(ret < 0)    push_int(0);    else    push_int(1);      }      /*! @decl mapping status()    *!    *! Returns mapping of current audio device status.    */   static void f_audio_status(INT32 args) {    -  +  dvb_audio_data *dvb_audio = DVBAudio;    int ret;    audioStatus_t status;       pop_n_elems(args);    THREADS_ALLOW(); -  ret = ioctl(DVBAudio->fd, AUDIO_GET_STATUS, &status); +  ret = ioctl(dvb_audio->fd, AUDIO_GET_STATUS, &status);    THREADS_DISALLOW();    if(ret < 0)    push_int(0);    else {    push_text("av_sync"); push_int(status.AVSyncState);    push_text("mute"); push_int(status.muteState);    push_text("state");    switch(status.playState) {    case AUDIO_STOPPED: push_text("stopped");    break;
pike.git/src/modules/DVB/dvb.c:1521:    default: push_text("unknown");    }    push_text("bypass"); push_int(status.bypassMode);    f_aggregate_mapping( 2 * 6 );    }      }      static void f_audio_ctrl(INT32 args) {    +  dvb_audio_data *dvb_audio = DVBAudio;    int ret;    int cw = -1;       check_all_args("DVB.dvb->ctrl", args, BIT_INT | BIT_STRING, 0);       if(Pike_sp[-1].type == T_INT)    cw = (u_short)Pike_sp[-1].u.integer;    else    if(!strcmp(Pike_sp[-1].u.string->str, "play"))    cw = AUDIO_PLAY;
pike.git/src/modules/DVB/dvb.c:1545:    if(!strcmp(Pike_sp[-1].u.string->str, "continue"))    cw = AUDIO_CONTINUE;       Pike_sp--;    if(cw == -1) {    push_int(0);    return;    }       THREADS_ALLOW(); -  ret = ioctl(DVBAudio->fd, cw); +  ret = ioctl(dvb_audio->fd, cw);    THREADS_DISALLOW();    if(ret < 0)    push_int(0);    else    push_int(1);      }      /*! @decl int mixer(int left, int right)    *! @decl int mixer(int both)    *!    *! Sets output level on DVB audio device.    *!    *| @seealso    *| @[mute()]    */   static void f_audio_mixer(INT32 args) {    -  +  dvb_audio_data *dvb_audio = DVBAudio;    int ret;    audioMixer_t mixer;       check_all_args("DVB.dvb->audio_mixer", args, BIT_INT, BIT_INT | BIT_VOID, 0);       mixer.volume_right = (unsigned int)Pike_sp[-1].u.integer;    Pike_sp--;    if(args > 1) {    mixer.volume_left = (unsigned int)Pike_sp[-1].u.integer;    Pike_sp--;    } else    mixer.volume_left = mixer.volume_right;       THREADS_ALLOW(); -  ret = ioctl(DVBAudio->fd, AUDIO_SET_MIXER, &mixer); +  ret = ioctl(dvb_audio->fd, AUDIO_SET_MIXER, &mixer);    THREADS_DISALLOW();    if(ret < 0)    Pike_error("Seting mixer failed.\n");    else    push_int(1);      }   /*! @endclass    */