[MPlayer-dev-eng] [PATCH] Teletext support try3 (1/5, core)

Michael Niedermayer michaelni at gmx.at
Wed Jul 18 09:45:58 CEST 2007


Hi

On Tue, Jul 17, 2007 at 10:19:42PM +0700, Vladimir Voroshilov wrote:
> format (opaque,transparent, etc) and mode (on/off) options/slaves have been 
> splitted.
> 
> This version (along with another 4 patches) i want to commit at weekend if 
> nobody will object.
[...]
> +/**
> + * \brief convert chars from curent teletext codepage into MPlayer charset
> + * \param p tt_char structure to recode
> + * \param lang teletext internal language code (see lang2id)
> + *
> + * \remarks
> + * routine will analyze raw member of given tt_char structure and
> + * fill unicode member of the same struct with apropriate utf8 code.
> + *
> + */
> +void conv2uni(tt_char*p,int lang)
> +{
> +    if (lang>=LANGS || lang<0) //make sure that we will not get out of bounds error
> +        lang=LAT_UNI;//fall back to latin

useless check, should be removed or changed to assert()


> +
> +    if(p[0].raw<0x80 && p[0].raw>=0x20){
> +        p[0].unicode=lang_chars[lang][p[0].raw-0x20];
> +    }else
> +        p[0].unicode=0x20;
> +}

conv2uni(unsigned int p, int lang)
{
    if(p-0x20 < 0x80) return lang_chars[lang][p - 0x20];
    else              return 0x20;
}

that is, no need to make it dependant on tt_char ...


[...]

> +void put_to_cache(priv_vbi_t* priv,tt_page* pg){
> +    int cache_idx;
> +    tt_page* pgc; //page in cache
> +    int i;
> +
> +    cache_idx=pg->pagenum+VBI_MAX_PAGES*pg->subpagenum;
> +    pthread_mutex_lock(&(priv->buffer_mutex));
> +    if(ptt_cache_first_subpage[pg->pagenum]>pg->subpagenum){
> +        ptt_cache_first_subpage[pg->pagenum]=pg->subpagenum;
> +    }
> +
> +    if(!ptt_cache[cache_idx]){
> +        ptt_cache[cache_idx]=(tt_page*)malloc(sizeof(tt_page));
> +        memset(ptt_cache[cache_idx],0,sizeof(tt_page));
> +    }
> +
> +    pgc=ptt_cache[cache_idx];
> +    pgc->pagenum=pg->pagenum;
> +    pgc->subpagenum=pg->subpagenum;
> +    pgc->lang=pg->lang;
> +    pgc->flags=pg->flags;
> +    //instead of copying enture page into cache, copy only undamaged
> +    //symbols into cache
> +    for(i=0;i<VBI_ROWS*VBI_COLUMNS;i++){
> +        if(!(pg->text[i].raw&0x80))
> +            pgc->text[i].raw=pg->text[i].raw;
> +        else
> +            mp_msg(MSGT_TV,MSGL_DBG3,"char error. pg:%x, c[%d]=0x%x\n",pg->pagenum,i,pg->text[i].raw);
> +    }

the cache must only contain 1 byte per symbol, not a 12 byte struct
we dont need this bloat, we arent mozilla.org
theres no sense in caching fg/bg colors, unicode symbols, ... they can and
should just be calculated before rendering



> +    ptt_cache[cache_idx]->active=1;
> +    pthread_mutex_unlock(&(priv->buffer_mutex));
> +}
> +
> +tt_page* get_from_cache(priv_vbi_t* priv, int pagenum,int subpagenum){
> +    if(!ptt_cache)
> +        return NULL;

useless check, init_cache() must be called before any other cache
function


[...]
> +void init_cache(void){
> +    ptt_cache=(tt_page**)malloc(VBI_MAX_PAGES*VBI_MAX_SUBPAGES*sizeof(tt_page*));

useless cast, and for a non static function the name is too generic even
for mplayer


> +    memset(ptt_cache,0,VBI_MAX_PAGES*VBI_MAX_SUBPAGES*sizeof(tt_page*));

use calloc


[...]
> +        for(col=0;col<VBI_COLUMNS;col++){
> +            i=row*VBI_COLUMNS+col;
> +            if(p[i].raw&0x80){ //damaged char
> +              p[i]=tt_space;

a red '?' or some other symbol seems more appropriate than a space
also indention is inconsistant


> +              continue;
> +            }
> +            c=p[i].raw;
> +            p[i].gfx=gfx?(separated?2:1):0;

> +            p[i].lng=lat?1:0;

the ?1:0 is superflous


> +            p[i].ctl=(c&0x60)==0?1:0;
> +            p[i].fg=color;

> +            p[i].bg=bkg_color;

please use the same abbreviations, bg vs. bkg


> +
> +#ifdef DEEP_DEBUG
> +        if(pg->pagenum==0x770) fprintf(stderr,"(%02x %c) ",c,p[i].gfx?'1':'0');
> +#endif

> +            if ((c&0x60)==0){ //control chars
> +                switch (c){
> +                case 0x00://Alpha Black
> +                case 0x01://Alpha Red
> +                case 0x02://Alpha Green
> +                case 0x03://Alpha Yellow
> +                case 0x04://Alpha Blue
> +                case 0x05://Alpha Magenta
> +                case 0x06://Alpha Cyan
> +                case 0x07://Alpha White - Assumed at Row start
> +                    color=c;
> +                    gfx=0;
> +                    break;
> +                case 0x08://Flash (NYI)
> +                case 0x09://Steady (NYI) - Assumed at Row start
> +                case 0x0a://End Box (NYI) - Assumed at Row start
> +                case 0x0b://Start Box (NYI)
> +                case 0x0c://Normal Height (NYI) - Assumed at Row start
> +                case 0x0d://Double Height (NYI)
> +                case 0x0e://S0 (NYI)
> +                case 0x0f://S1 (NYI)
> +                    break;
> +                case 0x10://Graphics black
> +                case 0x11://Graphics Red
> +                case 0x12://Graphics Green
> +                case 0x13://Graphics Yellow
> +                case 0x14://Graphics Blue
> +                case 0x15://Graphics Magenta
> +                case 0x16://Graphics Cyan
> +                case 0x17://Graphics White - Assumed at Row start
> +                    color=c&0xf;
> +                    gfx=1;
> +                    break;
> +                case 0x18://Conceal display
> +                    break;
> +                case 0x19://Contiguous Gfx - Assumed at Row start
> +                    separated=0;
> +                    break;
> +                case 0x1a://Separate Gfx
> +                    separated=1;
> +                    break;
> +                case 0x1b: //ESC (Used as lang switch) - for backward compatibility
> +                    lat=!lat;
> +                    break;
> +                case 0x1c: //Black background - Assumed at Row start
> +                    bkg_color=0;
> +                    p[i].bg=0;
> +                    break;
> +                case 0x1d: //New background
> +                    bkg_color=color;
> +                    p[i].bg=color;
> +                    break;
> +                case 0x1e: //Hold graphics
> +                case 0x1f: //Release gaphics - Assumed at Row start
> +                    break;
> +                }

if(c>=0x08 && c<=0x0F){
}else if(c<=0x17){
    color= c&15;
    gfx  = c>>4;
}else if(c<=0x18){
}else if(c<=0x1A){
    separated= !(c&1);
}else if(c<=0x1B){
    lat=!lat;
}else if(c<=0x1D){
    bkg_color=
    p[i].bg= (c&1) ? color : 0;
}


[...]
> +            if(!pg)
> +            priv_vbi->subpagenum=0;

indention


[...]
> +/**
> + * \brief checks whether page is ready and copies it into cache array if so
> + * \param priv private data structure
> + * \param magAddr page's magazine address (0-7)
> + *
> + * Routine also calls decode_page to perform 1st stage of rendering
> + *
> + */
> +void store_in_cache(priv_vbi_t* priv, int magAddr){
> +    int pagenum=priv->mag[magAddr].pt->pagenum;
> +    int subpagenum=priv->mag[magAddr].pt->subpagenum;
> +    tt_page* pg;
> +
> +    if(magAddr<0 || magAddr>7)
> +        return;

another impossible to be true check, this should be assert() if its here
at all, though there are uses of magAddr before store_in_cache() so its
not the right place for assert() either


[...]
> +        case 1 ... VBI_ROWS-1:

not valid ISO C99


[...]
> +
> +        for(i=0; i<256; i++){
> +            j=i&0x7F;
> +            j^= j+j;
> +            j^= j<<2;
> +            j^= j<<4;
> +            fixParity[i]= i ^ (j&0x80) ^ 0x80;
> +        }

this (and possible other init code) should be in a seperate function


[...]
> +        priv_vbi->mag=malloc(8*sizeof(MAG));
> +        memset(priv_vbi->mag,0,8*sizeof(MAG));

calloc()


[...]
> +    case TV_VBI_CONTROL_SET_MODE:
> +        priv_vbi->on=(*(int*)arg!=0);
> +        return TVI_CONTROL_TRUE;
> +    case TV_VBI_CONTROL_GET_MODE:
> +        *(int*)arg=priv_vbi->on;
> +        return TVI_CONTROL_TRUE;
> +    case TV_VBI_CONTROL_STEP_MODE:
> +        priv_vbi->on=!priv_vbi->on;
> +        return TVI_CONTROL_TRUE;

set, get, flip? set/get are enough



> +    case TV_VBI_CONTROL_SET_FORMAT:
> +        return teletext_set_format(priv_vbi, *(int *) arg);
> +    case TV_VBI_CONTROL_GET_FORMAT:
> +        pthread_mutex_lock(&(priv_vbi->buffer_mutex));
> +        *(int*)arg=priv_vbi->tformat;
> +        pthread_mutex_unlock(&(priv_vbi->buffer_mutex));
> +        return TVI_CONTROL_TRUE;
> +    case TV_VBI_CONTROL_STEP_FORMAT:
> +    {
> +        int val;
> +        pthread_mutex_lock(&(priv_vbi->buffer_mutex));
> +        val=(priv_vbi->tformat+*(int*)arg)%4;
> +        pthread_mutex_unlock(&(priv_vbi->buffer_mutex));
> +        if (val<0)
> +            val+=4;
> +        return teletext_set_format(priv_vbi,val);
> +    }

same as above


> +    case TV_VBI_CONTROL_GET_HALF_PAGE:
> +        if(!priv_vbi->on)
> +            return TVI_CONTROL_FALSE;
> +        *(int *) arg = priv_vbi->zoom;
> +        return TVI_CONTROL_TRUE;
> +    case TV_VBI_CONTROL_SET_HALF_PAGE:
> +    {
> +        int val=*(int*)arg;
> +        if(val<0 || val>2)
> +           return TVI_CONTROL_FALSE;
> +        pthread_mutex_lock(&(priv_vbi->buffer_mutex));
> +        priv_vbi->zoom = val;
> +        pthread_mutex_unlock(&(priv_vbi->buffer_mutex));
> +        return TVI_CONTROL_TRUE;
> +    }
> +    case TV_VBI_CONTROL_STEP_HALF_PAGE:
> +    {
> +        int val;
> +        val=priv_vbi->zoom+((*(int*)arg)%3);
> +
> +        if (val<0)
> +            val+=3;
> +        if (val>2)
> +            val-=3;
> +        pthread_mutex_lock(&(priv_vbi->buffer_mutex));
> +        priv_vbi->zoom = val;
> +        pthread_mutex_unlock(&(priv_vbi->buffer_mutex));
> +        return TVI_CONTROL_TRUE;
> +    }

same as above

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I hate to see young programmers poisoned by the kind of thinking
Ulrich Drepper puts forward since it is simply too narrow -- Roman Shaposhnik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20070718/720c95d3/attachment.pgp>


More information about the MPlayer-dev-eng mailing list