[vlc-devel] [PATCH 1/2] First release of blt module

Steve Lhomme robux4 at gmail.com
Mon Aug 7 08:47:09 CEST 2017


Give the patches are meant to be applied on git, the title you put is
the one that will end up in the commit log. "First release of
something" doesn't say much. You could use "demux: add a .blt demuxer"

On Thu, Aug 3, 2017 at 11:38 AM,  <francesco at bltitalia.com> wrote:
> From: Francesco Cuzzocrea <francesco at bltitalia.com>
>
> Hi to all
> this is the first version of a module I wrote in order to make vlc play custom *.blt files.
> Those file format is used mainly in Europe and in Italy. First of all I apologize for some
> error I will made in submitting and documenting a patch, but I'm new to linux development,
> so for me using git, formatting a patch and so on (that for experienced linux developer are
> pretty normal) entails some difficulties (that I'm overcoming).
> So, suggestions on how to do are well well welcome.
> Two words on the module: Is a demuxer with a codec. Demuxing is nearly ok (I think..) but I
> should work for the codec.  We use 4:2:2 JPEG2000 compression but codestream is slight different
> That is we can have a single codestream with three components or two separate codestreams
> (one for luma with a single components and one for chroma with the remaining two components).
> I decoded it using ffmpeg, and converted in RGB format. I can't make vlc accept YUV format at
> output (suggestions are welcome).
> Moreover up to now my knowledges can't allow me to set menu settings (I'm still studying the vlc code.)
> For example in the decode block, when we have an HD image the output is halfed because the decoder
> is slow in decoding (If I haven't make some mistakes), but I haven't figured out how to set the menu

Do you mean you reduce the picture size because the decoding is slow ?
That seems wrong. You can't assume the player will have a slow
machine. If your system is too slow to decode, it will drop frames,
that's all.

> Video -> Zoom -> 1:2.
> Some example files are available at this address:
>
> www.blt.it/support/samples
>
> regards
> ---
>  modules/demux/Makefile.am            |  21 +
>  modules/demux/blt/BLT_Utils.c        | 796 +++++++++++++++++++++++++++++++++++
>  modules/demux/blt/BLT_Utils.h        |  24 ++
>  modules/demux/blt/blt_jp2k_codec.c   | 742 ++++++++++++++++++++++++++++++++

This should go in a separate patch, as Remi said. And it should go in
modules/codec/

>  modules/demux/blt/blt_jp2k_codec.h   |  20 +
>  modules/demux/blt/glob_def_vlci.h    | 186 ++++++++
>  modules/demux/blt/glob_struct_vlci.h |  71 ++++
>  modules/demux/blt/libblt.c           | 679 ++++++++++++++++++++++++++++++
>  8 files changed, 2539 insertions(+)
>  create mode 100644 modules/demux/blt/BLT_Utils.c
>  create mode 100644 modules/demux/blt/BLT_Utils.h
>  create mode 100644 modules/demux/blt/blt_jp2k_codec.c
>  create mode 100644 modules/demux/blt/blt_jp2k_codec.h
>  create mode 100644 modules/demux/blt/glob_def_vlci.h
>  create mode 100644 modules/demux/blt/glob_struct_vlci.h
>  create mode 100644 modules/demux/blt/libblt.c
>
> diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
> index 584ddd4..e629326 100644
> --- a/modules/demux/Makefile.am
> +++ b/modules/demux/Makefile.am
> @@ -13,6 +13,27 @@ libogg_plugin_la_LIBADD = $(LIBVORBIS_LIBS) $(OGG_LIBS)
>  EXTRA_LTLIBRARIES += libogg_plugin.la
>  demux_LTLIBRARIES += $(LTLIBogg)
>
> +
> +
> +libblt_plugin_la_SOURCES =  demux/blt/glob_def_vlci.h \
> +                            demux/blt/glob_struct_vlci.h \
> +                            demux/blt/Blt_Utils.h \
> +                            demux/blt/blt_jp2k_codec.h \
> +                            demux/blt/blt_jp2k_codec.c \
> +                            demux/blt/BLT_Utils.c \
> +                            demux/blt/libblt.c
> +#
> +libblt_plugin_la_CFLAGS = $(AM_CFLAGS) $(AVFORMAT_CFLAGS) $(AVUTIL_CFLAGS) \
> +      -DMODULE_STRING=\"blt_import\" \
> +      -DMODULE_NAME=\"blt_import\"
> +libblt_plugin_la_LIBADD = $(AM_LIBADD) $(AVFORMAT_LIBS) $(AVUTIL_LIBS)
> +#libblt_plugin_la_DEPENDENCIES =
> +#libblt_plugin_la_LDFLAGS = \
> +#      -avoid-version -module -export-symbol-regex ^vlc_entry
> +
> +demux_LTLIBRARIES += libblt_plugin.la
> +
> +
>  libdemuxdump_plugin_la_SOURCES = demux/demuxdump.c
>  demux_LTLIBRARIES += libdemuxdump_plugin.la
>
> diff --git a/modules/demux/blt/BLT_Utils.c b/modules/demux/blt/BLT_Utils.c
> new file mode 100644
> index 0000000..744a84d
> --- /dev/null
> +++ b/modules/demux/blt/BLT_Utils.c
> @@ -0,0 +1,796 @@
> +
> +#include "BLT_Utils.h"
> +#include <stdio.h>
> +
> +int BLT_get_jp2k_ch_offset(unsigned char * sbuff, unsigned int *ch_size,
> +        unsigned int loff)
> +{
> +    uint32_t *dwPnt, isize, qwsize;
> +    int choffs = loff;
> +
> +    dwPnt = (uint32_t *) &sbuff[loff - 4];
> +    isize = *dwPnt;
> +    dwPnt++;
> +    qwsize = ((isize << 24) & 0xFF000000) | ((isize << 8) & 0x00FF0000)
> +            | ((isize >> 8) & 0x0000FF00) | ((isize >> 24) & 0x000000FF);
> +    dwPnt += qwsize;
> +    choffs += (qwsize << 2);
> +    if ( (*dwPnt & 0xFEFFFFFF) != 0xF2FFFFFF )
> +    {
> +        if ( ch_size != NULL )
> +            *ch_size = 0;
> +        fprintf(stderr,
> +                "Error detecting chroma mark (loffs %d, size %x, mark %x) \n",
> +                loff, isize, *dwPnt);
> +        return -1; // Subsequently check here for chroma
> +    }
> +    dwPnt += 3;
> +    choffs += 16;
> +    isize = *dwPnt;
> +    qwsize = ((isize << 24) & 0xFF000000) | ((isize << 8) & 0x00FF0000)
> +            | ((isize >> 8) & 0x0000FF00) | ((isize >> 24) & 0x000000FF);
> +    if ( ch_size != NULL )
> +        *ch_size = (qwsize << 2);
> +    return choffs;
> +
> +}
> +
> +int BLT_get_jp2k_offset(unsigned char * sbuff, unsigned int *size,
> +        unsigned char *aub, unsigned int *ausz)
> +{
> +
> +    uint32_t *dwPnt, isize, qwsize, kk;
> +    int offs = 0;
> +    unsigned char *jp2p;
> +
> +    dwPnt = (uint32_t *) sbuff;
> +    if ( *dwPnt != 0xF8FFFFFF )
> +        return -1;
> +    dwPnt += 4;
> +    offs += 16;
> +    if ( *dwPnt != 0xF4FFFFFF )
> +        return -2;
> +    dwPnt += 5;
> +    offs += 20;
> +    if ( *dwPnt != 0xF5FFFFFF )
> +        return -3;
> +    dwPnt++;
> +    isize = (sbuff[offs + 4] << 8) | sbuff[offs + 5];
> +    if ( ausz != NULL )
> +        *ausz = isize - 4;
> +    if ( aub != NULL )
> +    {
> +        memcpy(aub, &sbuff[offs + 8], (isize - 4));
> +    }
> +    offs += (isize + 4);
> +    dwPnt += (isize >> 2);
> +    if ( (*dwPnt & 0xFEFFFFFF) != 0xF0FFFFFF )
> +        return -4;
> +    dwPnt += 3;
> +    isize = *dwPnt;
> +    qwsize = ((isize << 24) & 0xFF000000) | ((isize << 8) & 0x00FF0000)
> +            | ((isize >> 8) & 0x0000FF00) | ((isize >> 24) & 0x000000FF);
> +    qwsize <<= 2;
> +    if ( size != NULL )
> +        *size = qwsize;
> +    offs += 16;
> +    // Check for FF D9 and correct lenght
> +    qwsize += 4;
> +    kk = 0;
> +    jp2p = &sbuff[offs];
> +    while ( (qwsize > 32) && (kk < 64) )
> +    {
> +        if ( (jp2p[qwsize - 1] == 0xFF) && (jp2p[qwsize] == 0xD9) )
> +            break;
> +        else
> +        {
> +            qwsize--;
> +            kk++;
> +        }
> +    }
> +    if ( (qwsize == 32) || (kk == 64) )
> +    {
> +        fprintf(stderr, "##### Error EOC mark not found \n");
> +    }
> +    // qwsize++;
> +    //  if(qwsize&0x03){qwsize|=0x03; qwsize++;}
> +
> +    return offs;
> +}
> +
> +// -----------------------------------------------------------------------------
> +long BLT_Time2Frm(unsigned char Df, unsigned short HR, unsigned char MN,
> +        unsigned char SC, unsigned char FR)
> +{
> +    if ( Df )
> +        return (((FR + (SC * 30) + (MN * 1800) + (HR * 108000))
> +                - (((MN * 2) - ((MN / 10) * 2)) + (HR * 108)))); /* 59.94Hz */
> +    else
> +        return (FR + (SC * 25) + (MN * 1500) + (HR * 90000)); /* 50Hz */
> +}
> +
> +// -----------------------------------------------------------------------------
> +
> +void BLT_cv_long_tcs(long dato, unsigned char Df, unsigned char *sign,
> +        unsigned short *HR, unsigned char *MN, unsigned char *SC,
> +        unsigned char *FR)
> +{
> +    if ( dato < 0 )
> +    {
> +        *sign = '-';
> +        dato = -dato;
> +    } else
> +    {
> +        *sign = ' ';
> +    }
> +    BLT_Frm2Time(dato, Df, HR, MN, SC, FR);
> +
> +}
> +
> +// -----------------------------------------------------------------------------
> +void BLT_Frm2Time(long dato, unsigned char Df, unsigned short *HR,
> +        unsigned char *MN, unsigned char *SC, unsigned char *FR)
> +{
> +    unsigned char Md, Mu;
> +    unsigned short HH, frq, min, ore;
> +    short Mrst;
> +
> +    if ( Df )
> +    {
> +        frq = 30;
> +        min = 1800;
> +        ore = 17982;
> +    } else
> +    {
> +        frq = 25;
> +        min = 1500;
> +        ore = 15000;
> +    }
> +    HH = dato / ore;
> +    Md = HH % 6;
> +    HH /= 6;
> +    Mrst = dato % ore;
> +    if ( Df )
> +    {
> +        Mu = ((Mrst - 1) * 10L) / (ore - 1);
> +        Mrst += (Mu * 2);
> +    } else
> +    {
> +        Mu = Mrst / min;
> +    }
> +    *FR = Mrst % frq;
> +    Mrst /= frq;
> +    *SC = Mrst % 60;
> +    Mu += (Md * 10);
> +    *HR = HH;
> +    *MN = Mu;
> +
> +}
> +
> +// ----------------------------------------------------------------------------
> +int32_t BLT_cv_txt_dat(int sel, unsigned char *dpnt, unsigned char tv_standard)
> +{
> +    unsigned char o, m, s, f;
> +    int32_t ctl;
> +
> +    o = m = s = f = ctl = 0;
> +
> +    switch ( sel )
> +    {
> +    case 0:
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0); /* Read 3 bytes (for clip number) */
> +        ctl = (*dpnt++ & 0x0f) * 100;
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        ctl += (*dpnt++ & 0x0f) * 10;
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        ctl += (*dpnt++ & 0x0f);
> +    break;
> +    case 1:
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0); /* read 11 bytes x tc (x HOUR) */
> +        o = ((*dpnt++ & 0x0f) * 10);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        o += (*dpnt++ & 0x0f);
> +        if ( *dpnt++ != ':' )
> +            return (0);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        m = ((*dpnt++ & 0x0f) * 10);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        m += (*dpnt++ & 0x0f);
> +        if ( *dpnt++ != ':' )
> +            return (0);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        s = ((*dpnt++ & 0x0f) * 10);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        s += (*dpnt++ & 0x0f);
> +        if ( *dpnt++ != ':' )
> +            return (0);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        f = ((*dpnt++ & 0x0f) * 10);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        f += (*dpnt++ & 0x0f);
> +        ctl = BLT_Time2Frm(tv_standard, o, m, s, f);
> +    break;
> +    case 2:
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') ) /* Read 2 bytes hex */
> +            ctl = (*dpnt++ & 0x0f) * 16;
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            ctl = (*dpnt++ - 55) * 16;
> +        else
> +            return (0);
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') ) /* Read 2 bytes hex */
> +            ctl += (*dpnt++ & 0x0f);
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            ctl += (*dpnt++ - 55);
> +        else
> +            return (0);
> +    break;
> +    case 4:
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') )
> +            o = ((*dpnt++) & 0x0f); /* read 10 bytes x tc (x DATE) */
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            o = (((*dpnt++) - 7) & 0x0f);
> +        else
> +            return (0);
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') )
> +            m = ((*dpnt++) & 0x0f);
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            m = (((*dpnt++) - 7) & 0x0f);
> +        else
> +            return (0);
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') )
> +            s = ((*dpnt++) & 0x0f);
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            s = (((*dpnt++) - 7) & 0x0f);
> +        else
> +            return (0);
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') )
> +            f = ((*dpnt++) & 0x0f);
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            f = (((*dpnt++) - 7) & 0x0f);
> +        else
> +            return (0);
> +        ctl = ((o << 28) | (m << 24) | (s << 20) | (f << 16));
> +        if ( (*dpnt++) != '/' )
> +            return (0);
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') )
> +            s = ((*dpnt++) & 0x0f);
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            s = (((*dpnt++) - 7) & 0x0f);
> +        else
> +            return (0);
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') )
> +            f = ((*dpnt++) & 0x0f);
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            f = (((*dpnt++) - 7) & 0x0f);
> +        else
> +            return (0);
> +        ctl |= ((s << 12) | (f << 8));
> +        if ( (*dpnt++) != '/' )
> +            return (0);
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') )
> +            s = ((*dpnt++) & 0x0f);
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            s = (((*dpnt++) - 7) & 0x0f);
> +        else
> +            return (0);
> +        if ( (*dpnt >= '0') && (*dpnt <= '9') )
> +            f = ((*dpnt++) & 0x0f);
> +        else if ( (*dpnt >= 'A') && (*dpnt <= 'F') )
> +            f = (((*dpnt++) - 7) & 0x0f);
> +        else
> +            return (0);
> +        ctl |= ((s << 4) | f);
> +    break;
> +    case 5:
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0); /* read 5 bytes (clip number) */
> +        ctl = (*dpnt++ & 0x0f) * 10000;
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        ctl += (*dpnt++ & 0x0f) * 1000;
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        ctl += (*dpnt++ & 0x0f) * 100;
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (0);
> +        ctl += (*dpnt++ & 0x0f) * 10;
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +        {
> +            if ( ctl )
> +                ctl /= 10;
> +        } else
> +            ctl += (*dpnt++ & 0x0f);
> +    break;
> +    case 6:
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (-1); /* read 11 bytes x tc (x HOUR x Edit Pc Clip) */
> +        o = ((*dpnt++ & 0x0f) * 10);
> +        if ( *dpnt == 0 )
> +        {
> +            o /= 10;
> +            goto calo;
> +        }
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (-1);
> +        o += (*dpnt++ & 0x0f);
> +        if ( *dpnt == 0 )
> +            goto calo;
> +        if ( *dpnt++ != ':' )
> +            return (-1);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (-1);
> +        m = ((*dpnt++ & 0x0f) * 10);
> +        if ( *dpnt == 0 )
> +        {
> +            m /= 10;
> +            goto calo;
> +        }
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (-1);
> +        m += (*dpnt++ & 0x0f);
> +        if ( *dpnt == 0 )
> +            goto calo;
> +        if ( *dpnt++ != ':' )
> +            return (-1);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (-1);
> +        s = ((*dpnt++ & 0x0f) * 10);
> +        if ( *dpnt == 0 )
> +        {
> +            s /= 10;
> +            goto calo;
> +        }
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (-1);
> +        s += (*dpnt++ & 0x0f);
> +        if ( *dpnt == 0 )
> +            goto calo;
> +        if ( *dpnt++ != ':' )
> +            return (-1);
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (-1);
> +        f = ((*dpnt++ & 0x0f) * 10);
> +        if ( *dpnt == 0 )
> +        {
> +            f /= 10;
> +            goto calo;
> +        }
> +        if ( (*dpnt < '0') || (*dpnt > '9') )
> +            return (-1);
> +        f += (*dpnt++ & 0x0f);
> +        calo: if ( tv_standard )
> +            ctl = (f + (s * 30) + (m * 1800) + (o * 108000)); /* NTSC */
> +        else
> +            ctl = (f + (s * 25) + (m * 1500) + (o * 90000)); /* PAL  */
> +    break;
> +    }
> +    return (ctl);
> +}
> +
> +// ----------------------------------------------------------------------------
> +int32_t BLT_rd_blt_header(struct pclp_tab *csrc, unsigned char *hbuf)
> +{
> +    unsigned char c, new_n1[CLNL], new_n2[CLNL], new_n3[CLN3];
> +    int32_t mmm;
> +    int32_t n, dat;
> +
> +    memset(new_n1, 0, CLNL);
> +    memset(new_n2, 0, CLNL);
> +    memset(new_n3, 0, CLN3);
> +    memset(csrc, 0, sizeof(struct pclp_tab));
> +    csrc->fldprec = 1024;
> +    csrc->pctv_std = 0; /*Default 50Hz */
> +
> +    if ( strncmp((char*) hbuf, "BLTMB01", 7) )
> +        return (-1000);
> +
> +    for ( n = 7; n < LENheader ; n++ ) /* read TV Standard first in order to set 50 or 60 Hz */
> +    {
> +        if ( hbuf[n] == 0 )
> +            break;
> +        if ( ((hbuf[(n - 1)] == 0x0a) || (hbuf[(n - 1)] == 0x0d))
> +                && ((hbuf[(n - 2)] == 0x0a) || (hbuf[(n - 2)] == 0x0d)) )
> +        {
> +            if ( strncmp((char*) &hbuf[n], "TVstandard: ", 12) == 0 ) /* 576/50i - 480/60i - 1080/50i - 1080/60i - 720/50p - 720/60p */
> +            {
> +                //  cv_txt_str((char*)&hbuf[(n+12)],&csrc->pctvstand);csrc->tv_format=0;
> +                if ( strncmp((char*) &hbuf[n + 12], "625/50i", 7) == 0 )
> +                {
> +                    csrc->hhlen = 720;
> +                    csrc->vvlen = 576;
> +                    csrc->pctv_std = 0;
> +                    csrc->tv_format = 0x04;
> +                    break;
> +                }
> +                if ( strncmp((char*) &hbuf[n + 12], "525/60i", 7) == 0 )
> +                {
> +                    csrc->hhlen = 720;
> +                    csrc->vvlen = 496;
> +                    csrc->pctv_std = 1;
> +                    csrc->tv_format = 0x05;
> +                    break;
> +                }
> +                if ( strncmp((char*) &hbuf[n + 12], "1080/50i", 8) == 0 )
> +                {
> +                    csrc->hhlen = 1920;
> +                    csrc->vvlen = 1080;
> +                    csrc->pctv_std = 0;
> +                    csrc->tv_format = 0x00;
> +                    break;
> +                }
> +                if ( strncmp((char*) &hbuf[n + 12], "1080/60i", 8) == 0 )
> +                {
> +                    csrc->hhlen = 1920;
> +                    csrc->vvlen = 1080;
> +                    csrc->pctv_std = 1;
> +                    csrc->tv_format = 0x01;
> +                    break;
> +                }
> +                if ( strncmp((char*) &hbuf[n + 12], "720/50P", 7) == 0 )
> +                {
> +                    csrc->hhlen = 1280;
> +                    csrc->vvlen = 720;
> +                    csrc->pctv_std = 0;
> +                    csrc->tv_format = 0x02;
> +                    break;
> +                }
> +                if ( strncmp((char*) &hbuf[n + 12], "720/60P", 7) == 0 )
> +                {
> +                    csrc->hhlen = 1280;
> +                    csrc->vvlen = 720;
> +                    csrc->pctv_std = 1;
> +                    csrc->tv_format = 0x03;
> +                    break;
> +                }
> +                if ( strncmp((char*) &hbuf[n + 12], "2160/50P", 8) == 0 )
> +                {
> +                    csrc->hhlen = 3840;
> +                    csrc->vvlen = 2160;
> +                    csrc->pctv_std = 0;
> +                    csrc->tv_format = 0x06;
> +                    break;
> +                }
> +                if ( strncmp((char*) &hbuf[n + 12], "2160/60P", 8) == 0 )
> +                {
> +                    csrc->hhlen = 3840;
> +                    csrc->vvlen = 2160;
> +                    csrc->pctv_std = 1;
> +                    csrc->tv_format = 0x07;
> +                    break;
> +                }
> +            }
> +        }
> +    }
> +    for ( n = 7; n < LENheader ; n++ )
> +    {
> +        if ( hbuf[n] == 0 )
> +            return (n);
> +        if ( ((hbuf[(n - 1)] == 0x0a) || (hbuf[(n - 1)] == 0x0d))
> +                && ((hbuf[(n - 2)] == 0x0a) || (hbuf[(n - 2)] == 0x0d)) )
> +        {
> +            if ( strncmp((char*) &hbuf[n], "NUMBER: ", 8) == 0 )
> +            {
> +                csrc->pcclip = BLT_cv_txt_dat(5, &hbuf[(n + 8)],
> +                        csrc->pctv_std);
> +            }
> +            if ( strncmp((char*) &hbuf[n], "NAME1: ", 7) == 0 )
> +            {
> +                for ( mmm = 0; mmm < CLNL ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 7)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->pcn1[mmm] = c;
> +                    new_n1[mmm] = c;
> +                }
> +            }
> +            if ( strncmp((char*) &hbuf[n], "NAME2: ", 7) == 0 )
> +            {
> +                for ( mmm = 0; mmm < CLNL ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 7)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->pcn2[mmm] = c;
> +                    new_n2[mmm] = c;
> +                }
> +            }
> +            if ( strncmp((char*) &hbuf[n], "NAME3: ", 7) == 0 )
> +            {
> +                for ( mmm = 0; mmm < CLN3 ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 7)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->pcn3[mmm] = c;
> +                    new_n3[mmm] = c;
> +                }
> +            }
> +            if ( strncmp((char*) &hbuf[n], "DURATION: ", 10) == 0 )
> +            {
> +                dat = BLT_cv_txt_dat(1, &hbuf[(n + 10)], csrc->pctv_std);
> +                if ( dat > 0 )
> +                    csrc->pctotf = dat; //else LENheader=-2;
> +
> +            }
> +            if ( strncmp((char*) &hbuf[n], "DATE: ", 6) == 0 )
> +            {
> +                dat = BLT_cv_txt_dat(4, &hbuf[(n + 6)], csrc->pctv_std);
> +                if ( dat > 0 )
> +                    csrc->pcui = dat;
> +                dat = BLT_cv_txt_dat(1, &hbuf[(n + 11 + 6)], csrc->pctv_std);
> +                if ( dat > 0 )
> +                    csrc->pcti = dat;
> +                csrc->pcci = csrc->pcti;
> +                csrc->pcco = csrc->pctotf + csrc->pcti;
> +            }
> +            if ( strncmp((char*) &hbuf[n], "ID: ", 4) == 0 )
> +            {
> +                csrc->pcid[3] = BLT_cv_txt_dat(2, &hbuf[(n + 4)],
> +                        csrc->pctv_std);
> +                csrc->pcid[2] = BLT_cv_txt_dat(2, &hbuf[(n + 6)],
> +                        csrc->pctv_std);
> +                csrc->pcid[1] = BLT_cv_txt_dat(2, &hbuf[(n + 8)],
> +                        csrc->pctv_std);
> +                csrc->pcid[0] = BLT_cv_txt_dat(2, &hbuf[(n + 10)],
> +                        csrc->pctv_std);
> +                csrc->pcid[5] = BLT_cv_txt_dat(2, &hbuf[(n + 13)],
> +                        csrc->pctv_std);
> +                csrc->pcid[4] = BLT_cv_txt_dat(2, &hbuf[(n + 15)],
> +                        csrc->pctv_std);
> +                csrc->pcid[7] = BLT_cv_txt_dat(2, &hbuf[(n + 18)],
> +                        csrc->pctv_std);
> +                csrc->pcid[6] = BLT_cv_txt_dat(2, &hbuf[(n + 20)],
> +                        csrc->pctv_std);
> +                csrc->pcid[8] = BLT_cv_txt_dat(2, &hbuf[(n + 23)],
> +                        csrc->pctv_std);
> +                csrc->pcid[9] = BLT_cv_txt_dat(2, &hbuf[(n + 25)],
> +                        csrc->pctv_std);
> +                csrc->pcid[10] = BLT_cv_txt_dat(2, &hbuf[(n + 28)],
> +                        csrc->pctv_std);
> +                csrc->pcid[11] = BLT_cv_txt_dat(2, &hbuf[(n + 30)],
> +                        csrc->pctv_std);
> +                csrc->pcid[12] = BLT_cv_txt_dat(2, &hbuf[(n + 32)],
> +                        csrc->pctv_std);
> +                csrc->pcid[13] = BLT_cv_txt_dat(2, &hbuf[(n + 34)],
> +                        csrc->pctv_std);
> +                csrc->pcid[14] = BLT_cv_txt_dat(2, &hbuf[(n + 36)],
> +                        csrc->pctv_std);
> +                csrc->pcid[15] = BLT_cv_txt_dat(2, &hbuf[(n + 38)],
> +                        csrc->pctv_std);
> +            }
> +            if ( strncmp((char*) &hbuf[n], "GROWING: ", 9) == 0 )
> +            {
> +                dat = BLT_cv_txt_dat(1, &hbuf[(n + 9)], csrc->pctv_std);
> +                if ( dat > 0 )
> +                    csrc->grwing = dat;
> +            }
> +
> +            /* NO REFERENCE CLIP FOR NOW */
> +            if ( strncmp((char*) &hbuf[n], "REFBLT: ", 8) == 0 ) /* set if file is a reference one */
> +            {
> +                csrc->ref_clip = 1;
> +                /*     msg_Err(p_demux, "Error : Reference clip not managed up to now"); */
> +                return -1;
> +            }
> +
> +            if ( strncmp((char*) &hbuf[n], "BREAK: ", 7) == 0 )
> +            {
> +                dat = BLT_cv_txt_dat(1, &hbuf[(n + 7)], csrc->pctv_std);
> +                if ( dat > 0 )
> +                    csrc->pcbrk = dat;
> +            }
> +            if ( strncmp((char*) &hbuf[n], "LENGHT: ", 8) == 0 )
> +            {
> +                csrc->pclen = 0;
> +                n += 8;
> +                for ( ; ; )
> +                {
> +                    if ( (hbuf[n] >= '0') && (hbuf[n] <= '9') )
> +                    {
> +                        csrc->pclen *= 10;
> +                        csrc->pclen += (hbuf[n++] & 0x0f);
> +                    } else
> +                        break;
> +                }
> +            }
> +            if ( strncmp((char*) &hbuf[n], "TYPE: ", 6) == 0 )
> +            {
> +                csrc->pctype = (hbuf[(n + 6)] & 0x0f);
> +            }
> +            if ( strncmp((char*) &hbuf[n], "VIDEO: ", 7) == 0 ) /* Uncompress - JPEG - JP2K - MPG2 */
> +            {
> +                if ( strncmp((char*) &hbuf[(n + 7)], "JP2K", 4) == 0 )
> +                    csrc->pcvd = 1;
> +            }
> +            if ( strncmp((char*) &hbuf[n], "FLDPRECISION: ", 14) == 0 ) /*Field alignment (1024,2048,4096) */
> +            {
> +                if ( strncmp((char*) &hbuf[(n + 14)], "4KB", 3) == 0 )
> +                    csrc->fldprec = 4096;
> +                else if ( strncmp((char*) &hbuf[(n + 14)], "2KB", 3) == 0 )
> +                    csrc->fldprec = 2048;
> +            }
> +            if ( strncmp((char*) &hbuf[n], "ASPECT: ", 8) == 0 ) /* 4:3 - 16:9 */
> +            { /* cv_txt_str(&hbuf[(n+8)],&csrc->pcaspect); */
> +                csrc->pcaspect = 0;
> +                if ( strncmp((char*) &hbuf[n + 8], "16:9", 4) == 0 )
> +                    csrc->pcaspect = 1;
> +            }
> +
> +            if ( strncmp((char*) &hbuf[n], "VTRACK: ", 8) == 0 ) /* AB ago2010 :: NOR / VKA / L+R /UHD1 */
> +                switch ( hbuf[n + 8] )
> +                {
> +                default:
> +                    csrc->pcvtrack = 0;
> +                break;
> +                case 'V':
> +                    csrc->pcvtrack = 1;
> +                    csrc->clpmsk = 3;
> +                break;
> +                case 'L':
> +                    csrc->pcvtrack = 2;
> +                    csrc->clpmsk = 3;
> +                break;
> +                case 'Q':
> +                    if ( strstr((char*) &hbuf[n + 8], "QHD1") != NULL )
> +                    {
> +                        csrc->pcvtrack = 3;
> +                        csrc->clpmsk = 1;
> +                    }
> +                break;
> +                }
> +
> +            if ( strncmp((char*) &hbuf[n], "SSM: ", 5) == 0 ) /* AB ago2010 ::  NOR / x2 / x3 */
> +                switch ( hbuf[n + 6] )
> +                {
> +                default:
> +                    csrc->pcssm = 0;
> +                break;
> +                case '2':
> +                    csrc->pcssm = 2;
> +                    csrc->clpmsk = c2S2;
> +                break;
> +                case '3':
> +                    csrc->pcssm = 3;
> +                    csrc->clpmsk = c3S3;
> +                break;
> +                }
> +
> +            if ( strncmp((char*) &hbuf[n], "PROXY: ", 7) == 0 )
> +                csrc->proxq = hbuf[(n + 7)];
> +
> +            //   if (strncmp((char*)&hbuf[n],"AUDIO: ",7)==0) /* Uncompress */
> +            //                     cv_txt_str(&hbuf[(n+7)],&csrc->pcaudio);
> +            if ( strncmp((char*) &hbuf[n], "ASAMPLE: ", 9) == 0 ) /* 32KHz - 48KHz */
> +            {/*  cv_txt_str(&hbuf[(n+9)],&csrc->pcasample); */
> +                csrc->pcasample = 48000;
> +                if ( strncmp((char*) &hbuf[n + 9], "32KHz", 5) == 0 )
> +                    csrc->pcasample = 32000;
> +            }
> +            if ( strncmp((char*) &hbuf[n], "APRECISION: ", 12) == 0 ) /* 8 - 16 - 24 bit */
> +            {/*  cv_txt_str(&hbuf[(n+12)],&csrc->pcaprecision); */
> +                csrc->pcaprecision = 16;
> +                if ( strncmp((char*) &hbuf[n + 12], "24", 2) == 0 )
> +                    csrc->pcaprecision = 24;
> +                if ( hbuf[n + 12] == 0x38 )
> +                    csrc->pcaprecision = 8;
> +            }
> +            if ( strncmp((char*) &hbuf[n], "ACHANNEL: ", 10) == 0 ) /* 2 - 4 - 8 - 16 */
> +            {
> +                csrc->pcachn = 4;
> +                if ( strncmp((char*) &hbuf[n + 10], "16", 2) == 0 )
> +                    csrc->pcachn = 16;
> +                if ( hbuf[n + 10] == 0x38 )
> +                    csrc->pcachn = 8;
> +            }
> +            if ( strncmp((char*) &hbuf[n], "VMASK: ", 7) == 0 ) /* Recorded video channel mask */
> +                if ( csrc->pcvtrack != 3 )
> +                    csrc->clpmsk = BLT_cv_txt_dat(2, &hbuf[(n + 7)],
> +                            csrc->pctv_std);
> +            if ( strncmp((char*) &hbuf[n], "VCHANNEL: ", 10) == 0 ) /* main channel  */
> +                csrc->cchn = (hbuf[(n + 10)] - 'A');
> +            if ( strncmp((char*) &hbuf[n], "SMSNAM: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->smsn[mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "INCAMA: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->camn[0][mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "INCAMB: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->camn[1][mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "INCAMC: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->camn[2][mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "INCAMD: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->camn[3][mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "INCAME: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->camn[4][mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "INCAMF: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->camn[5][mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "INCAMG: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->camn[6][mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "INCAMH: ", 8) == 0 )
> +                for ( mmm = 0; mmm < MAX_INPNAM ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 8)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->camn[7][mmm] = c;
> +                }
> +            if ( strncmp((char*) &hbuf[n], "APP: ", 5) == 0 )
> +                for ( mmm = 0; mmm < CLNL ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 5)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->appn[mmm] = c;
> +                }
> +
> +            if ( strncmp((char*) &hbuf[n], "ID: ", 4) == 0 )
> +                for ( mmm = 0; mmm < CLNL ; mmm++ )
> +                {
> +                    c = hbuf[(mmm + n + 4)];
> +                    if ( c < ' ' )
> +                        break;
> +                    csrc->clid[mmm] = c;
> +                }
> +        }
> +    }
> +    return (n);
> +}
> +;
> diff --git a/modules/demux/blt/BLT_Utils.h b/modules/demux/blt/BLT_Utils.h
> new file mode 100644
> index 0000000..2ad44e0
> --- /dev/null
> +++ b/modules/demux/blt/BLT_Utils.h
> @@ -0,0 +1,24 @@
> +#ifndef _BLT_UTILS_H_
> +#define _BLT_UTILS_H_
> +
> +#include <stdint.h>
> +#include <string.h>
> +#include "glob_def_vlci.h"
> +#include "glob_struct_vlci.h"
> +
> +void BLT_Frm2Time(long dato, unsigned char Df,unsigned short *HR,unsigned char *MN,unsigned char *SC,unsigned char *FR);
> +
> +long BLT_Time2Frm(unsigned char Df,unsigned short HR,unsigned char MN,unsigned char SC,unsigned char FR);
> +
> +void BLT_cv_long_tcs (long dato,unsigned char Df,unsigned char *sign, unsigned short *HR,unsigned char *MN,unsigned char *SC,unsigned char *FR);
> +
> +int32_t BLT_cv_txt_dat(int sel,unsigned char *dpnt, unsigned char tv_standard);
> +
> +int32_t BLT_rd_blt_header(struct pclp_tab *csrc,unsigned char *hbuf);
> +
> +int BLT_get_jp2k_offset(unsigned char * sbuff, unsigned int *size, unsigned char *aub, unsigned int *ausz);
> +
> +int BLT_get_jp2k_ch_offset(unsigned char * sbuff, unsigned int *ch_size, unsigned int loff);
> +
> +
> +#endif
> diff --git a/modules/demux/blt/blt_jp2k_codec.c b/modules/demux/blt/blt_jp2k_codec.c
> new file mode 100644
> index 0000000..71a7b72
> --- /dev/null
> +++ b/modules/demux/blt/blt_jp2k_codec.c
> @@ -0,0 +1,742 @@
> +/*
> + * blt_jp2k_codec.c
> + *
> + *  Created on: 21 Jul 2017
> + *      Author: alfredo
> + */
> +
> +/* VLC core API headers */
> +#include <vlc_common.h>
> +#include <vlc_plugin.h>
> +#include <vlc_access.h>
> +#include <vlc_demux.h>
> +#include <vlc_input.h>
> +
> +#include <vlc_dialog.h>
> +
> +#include <vlc_meta.h>
> +//#include <vlc_codecs.h>
> +#include <vlc_charset.h>
> +#include <vlc_memory.h>
> +
> +#include <vlc_fourcc.h>
> +//#include <vlc_interface.h>
> +#include <vlc_fs.h>
> +#include <vlc_stream.h>
> +
> +#include <vlc_codec.h>
> +#include <vlc_messages.h>
> +
> +//#ifndef _GLOB_DEF_VLCIMPORT_
> +#include "glob_def_vlci.h"
> +//#endif
> +
> +//#ifndef MODULES_DEMUX_BLT_BLT_JP2K_CODEC_H_
> +#include "blt_jp2k_codec.h"
> +//#endif
> +
> +#include <stdint.h>
> +#include "../../codec/avcodec/avcodec.h"
> +#include "../../codec/avcodec/avcommon.h"
> +#include "../avformat/avformat.h"
> +
> +struct decoder_sys_t
> +{
> +    AVCodecContext *pCodecContext, *pCodecContext_ch;
> +    AVCodec *vd_codec, *vd_codec_ch;
> +    AVFrame *glob_frm, *glob_frm_ch;
> +    unsigned long codec_cnt;
> +    unsigned char *dec_rd_buff;
> +    unsigned char locked;
> +    vlc_object_t *p_obj;
> +    AVPacket thpkt, thpkt_ch;
> +    date_t pts;
> +    unsigned char d_ncompo;
> +    unsigned char bpp;
> +    uint32_t ui_imgH, ui_imgV;
> +    int16_t *i_myR_Crscaled;
> +    int16_t *i_myG_Crscaled;
> +    int16_t *i_myG_Cbscaled;
> +    int16_t *i_myB_Cbscaled;
> +};
> +
> +enum AVOptionType
> +{
> +    AV_OPT_TYPE_FLAGS,
> +    AV_OPT_TYPE_INT,
> +    AV_OPT_TYPE_INT64,
> +    AV_OPT_TYPE_DOUBLE,
> +    AV_OPT_TYPE_FLOAT,
> +    AV_OPT_TYPE_STRING,
> +    AV_OPT_TYPE_RATIONAL,
> +    AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
> +    AV_OPT_TYPE_DICT,
> +    AV_OPT_TYPE_UINT64,
> +    AV_OPT_TYPE_CONST = 128,
> +    AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S', 'I', 'Z', 'E'), ///< offset must point to two consecutive integers
> +    AV_OPT_TYPE_PIXEL_FMT = MKBETAG('P', 'F', 'M', 'T'),
> +    AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S', 'F', 'M', 'T'),
> +    AV_OPT_TYPE_VIDEO_RATE = MKBETAG('V', 'R', 'A', 'T'), ///< offset must point to AVRational
> +    AV_OPT_TYPE_DURATION = MKBETAG('D', 'U', 'R', ' '),
> +    AV_OPT_TYPE_COLOR = MKBETAG('C', 'O', 'L', 'R'),
> +    AV_OPT_TYPE_CHANNEL_LAYOUT = MKBETAG('C', 'H', 'L', 'A'),
> +    AV_OPT_TYPE_BOOL = MKBETAG('B', 'O', 'O', 'L'),
> +};
> +
> +extern int av_opt_set_int(void *obj, const char *name, int64_t val,
> +        int search_flags);
> +void blt_convertUYVY_to_rgb(decoder_sys_t *p_sys, uint8_t *px);
> +
> +// ----------------------------------------------------------------------------
> +
> +void CloseBLTDecoder(vlc_object_t *p_this)
> +{
> +    decoder_t *p_dec = (decoder_t*) p_this;
> +    decoder_sys_t *p_sys = p_dec->p_sys;
> +
> +    if ( p_sys->dec_rd_buff != NULL )
> +    {
> +        free(p_sys->dec_rd_buff);
> +        p_sys->dec_rd_buff = NULL;
> +    }
> +    if ( p_sys->vd_codec != NULL )
> +    {
> +        if ( avcodec_is_open(p_sys->vd_codec) )
> +        {
> +            avcodec_close(p_sys->vd_codec);
> +            av_free(p_sys->vd_codec);
> +            p_sys->vd_codec = NULL;
> +        }
> +    }
> +    if ( p_sys->vd_codec_ch != NULL )
> +    {
> +        if ( avcodec_is_open(p_sys->vd_codec_ch) )
> +        {
> +            avcodec_close(p_sys->vd_codec_ch);
> +            av_free(p_sys->vd_codec_ch);
> +            p_sys->vd_codec_ch = NULL;
> +        }
> +    }
> +    if ( p_sys->glob_frm != NULL )
> +    {
> +        av_frame_free(&p_sys->glob_frm);
> +        p_sys->glob_frm = NULL;
> +    }
> +    if ( p_sys->glob_frm_ch != NULL )
> +    {
> +        av_frame_free(&p_sys->glob_frm_ch);
> +        p_sys->glob_frm_ch = NULL;
> +    }
> +    if ( p_sys->i_myR_Crscaled != NULL )
> +    {
> +        free(p_sys->i_myR_Crscaled);
> +        p_sys->i_myR_Crscaled = NULL;
> +    }
> +    if ( p_sys->i_myG_Crscaled != NULL )
> +    {
> +        free(p_sys->i_myG_Crscaled);
> +        p_sys->i_myG_Crscaled = NULL;
> +    }
> +    if ( p_sys->i_myG_Cbscaled != NULL )
> +    {
> +        free(p_sys->i_myG_Cbscaled);
> +        p_sys->i_myG_Cbscaled = NULL;
> +    }
> +    if ( p_sys->i_myB_Cbscaled != NULL )
> +    {
> +        free(p_sys->i_myB_Cbscaled);
> +        p_sys->i_myB_Cbscaled = NULL;
> +    }
> +    free(p_sys);
> +}
> +
> +// ----------------------------------------------------------------------------
> +
> +int OpenBLTDecoder(vlc_object_t *p_this)
> +{
> +    decoder_t *p_dec = (decoder_t*) p_this;
> +
> +    if ( p_dec->fmt_in.i_codec != VLC_CODEC_JPEG2000 )
> +    {
> +        return VLC_EGENERIC;
> +    }
> +    decoder_sys_t *p_sys = malloc(sizeof(decoder_sys_t));
> +
> +    if ( p_sys == NULL )
> +    {
> +        return VLC_ENOMEM;
> +    }
> +    p_dec->p_sys = p_sys;
> +    p_sys->vd_codec = p_sys->vd_codec_ch = NULL;
> +    p_sys->dec_rd_buff = NULL;
> +    p_sys->glob_frm = p_sys->glob_frm_ch = NULL;
> +    p_sys->pCodecContext = p_sys->pCodecContext_ch = NULL;
> +    p_sys->i_myR_Crscaled = p_sys->i_myG_Crscaled = NULL;
> +    p_sys->i_myG_Cbscaled = p_sys->i_myB_Cbscaled = NULL;
> +
> +    if ( strstr(p_dec->fmt_in.psz_description, "BLT Codestream") == NULL )
> +    {
> +        goto _decode_error;
> +    }
> +
> +    p_sys->p_obj = p_this;
> +    p_dec->pf_decode = DecodeBlock;
> +
> +    msg_Dbg(p_dec, "##################   OpenBLTDecoder ok");
> +    p_sys->codec_cnt = 0;
> +    p_sys->locked = 0;
> +
> +    msg_Dbg(p_dec, "############## Allocating avcodec ");
> +    vlc_init_avformat(p_dec);
> +    p_sys->vd_codec = avcodec_find_decoder(AV_CODEC_ID_JPEG2000);
> +    if ( !p_sys->vd_codec )
> +    {
> +        msg_Err(p_dec, "Error decoder not found");
> +        goto _decode_error;
> +    };
> +    p_sys->vd_codec_ch = avcodec_find_decoder(AV_CODEC_ID_JPEG2000);
> +    if ( !p_sys->vd_codec_ch )
> +    {
> +        msg_Err(p_dec, "Error chroma decoder not found");
> +        goto _decode_error;
> +    };
> +
> +    p_sys->pCodecContext = avcodec_alloc_context3(p_sys->vd_codec);
> +    if ( !p_sys->pCodecContext )
> +    {
> +        msg_Err(p_dec, "Error unable to allocate codec context");
> +        goto _decode_error;
> +    }
> +    p_sys->pCodecContext_ch = avcodec_alloc_context3(p_sys->vd_codec);
> +    if ( !p_sys->pCodecContext_ch )
> +    {
> +        msg_Err(p_dec, "Error unable to allocate chroma codec context");
> +        goto _decode_error;
> +    }
> +
> +    p_sys->glob_frm = av_frame_alloc();
> +    if ( !p_sys->glob_frm )
> +    {
> +        msg_Err(p_dec, "Error unable to allocate frame");
> +        goto _decode_error;
> +    }
> +    p_sys->glob_frm_ch = av_frame_alloc();
> +    if ( !p_sys->glob_frm_ch )
> +    {
> +        msg_Err(p_dec, "Error unable to allocate chroma frame");
> +        goto _decode_error;
> +    }
> +
> +    p_sys->glob_frm->interlaced_frame = 0;
> +    p_sys->glob_frm->top_field_first = 1;
> +    date_Init(&p_sys->pts, p_dec->fmt_out.video.i_frame_rate,
> +            p_dec->fmt_out.video.i_frame_rate_base);
> +    if ( (p_dec->fmt_out.video.i_frame_rate == 0)
> +            || (p_dec->fmt_out.video.i_frame_rate_base == 0) )
> +    {
> +        date_Init(&p_sys->pts, 25, 1);
> +    }
> +    p_sys->i_myR_Crscaled = calloc(256, 2);
> +    if ( p_sys->i_myR_Crscaled == NULL )
> +    {
> +        msg_Err(p_dec, "Error allocating conversion buffer");
> +        goto _decode_error;
> +    }
> +    p_sys->i_myG_Crscaled = calloc(256, 2);
> +    if ( p_sys->i_myG_Crscaled == NULL )
> +    {
> +        msg_Err(p_dec, "Error allocating conversion buffer");
> +        goto _decode_error;
> +    }
> +    p_sys->i_myG_Cbscaled = calloc(256, 2);
> +    if ( p_sys->i_myG_Cbscaled == NULL )
> +    {
> +        msg_Err(p_dec, "Error allocating conversion buffer");
> +        goto _decode_error;
> +    }
> +    p_sys->i_myB_Cbscaled = calloc(256, 2);
> +    if ( p_sys->i_myB_Cbscaled == NULL )
> +    {
> +        msg_Err(p_dec, "Error allocating conversion buffer");
> +        goto _decode_error;
> +    }
> +
> +    int16_t X;
> +
> +    for ( X = 0; X < 256 ; X++ )
> +        p_sys->i_myR_Crscaled[X] = ((1370 * (X - 128)) / 1000);
> +    for ( X = 0; X < 256 ; X++ )
> +        p_sys->i_myG_Crscaled[X] = ((698 * (X - 128)) / 1000);
> +    for ( X = 0; X < 256 ; X++ )
> +        p_sys->i_myG_Cbscaled[X] = ((336 * (X - 128)) / 1000);
> +    for ( X = 0; X < 256 ; X++ )
> +        p_sys->i_myB_Cbscaled[X] = ((1730 * (X - 128)) / 1000);
> +
> +    return VLC_SUCCESS;
> +    _decode_error: if ( p_sys->dec_rd_buff != NULL )
> +    {
> +        free(p_sys->dec_rd_buff);
> +        p_sys->dec_rd_buff = NULL;
> +    }
> +    if ( p_sys->vd_codec != NULL )
> +    {
> +        if ( avcodec_is_open(p_sys->vd_codec) )
> +        {
> +            avcodec_close(p_sys->vd_codec);
> +            av_free(p_sys->vd_codec);
> +            p_sys->vd_codec = NULL;
> +        }
> +    }
> +    if ( p_sys->vd_codec_ch != NULL )
> +    {
> +        if ( avcodec_is_open(p_sys->vd_codec_ch) )
> +        {
> +            avcodec_close(p_sys->vd_codec_ch);
> +            av_free(p_sys->vd_codec_ch);
> +            p_sys->vd_codec_ch = NULL;
> +        }
> +    }
> +    if ( p_sys->glob_frm != NULL )
> +    {
> +        av_frame_free(&p_sys->glob_frm);
> +        p_sys->glob_frm = NULL;
> +    }
> +    if ( p_sys->glob_frm_ch != NULL )
> +    {
> +        av_frame_free(&p_sys->glob_frm_ch);
> +        p_sys->glob_frm_ch = NULL;
> +    }
> +
> +    if ( p_sys->i_myR_Crscaled != NULL )
> +    {
> +        free(p_sys->i_myR_Crscaled);
> +        p_sys->i_myR_Crscaled = NULL;
> +    }
> +    if ( p_sys->i_myG_Crscaled != NULL )
> +    {
> +        free(p_sys->i_myG_Crscaled);
> +        p_sys->i_myG_Crscaled = NULL;
> +    }
> +    if ( p_sys->i_myG_Cbscaled != NULL )
> +    {
> +        free(p_sys->i_myG_Cbscaled);
> +        p_sys->i_myG_Cbscaled = NULL;
> +    }
> +    if ( p_sys->i_myB_Cbscaled != NULL )
> +    {
> +        free(p_sys->i_myB_Cbscaled);
> +        p_sys->i_myB_Cbscaled = NULL;
> +    }
> +    return VLC_EGENERIC;
> +}
> +
> +// ----------------------------------------------------------------------------
> +
> +int DecodeBlock(decoder_t *p_dec, block_t * p_block)
> +{
> +    decoder_sys_t *p_sys = p_dec->p_sys;
> +    picture_t *p_pic = 0;
> +    unsigned long kk;
> +    uint32_t *pDw, lsz, d_choffs, chsz, *usp, ch_tile_size, delta_smpl;
> +    int i_conv_res, got_pkt;
> +    char str_err[256];
> +    uint8_t *p_dst_l, ladj;
> +    int64_t i_scale_factor = 0;
> +
> +    p_sys->codec_cnt++;
> +    if ( !p_block )
> +    {
> +        msg_Err(p_dec, "##################   Block invalid !!!!!");
> +        return VLCDEC_SUCCESS;
> +    }
> +
> +    if ( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
> +    {
> +        msg_Err(p_dec, "##################   Block corrupted !!!!!");
> +        block_Release(p_block);
> +        return VLCDEC_SUCCESS;
> +    }
> +
> +    if ( p_sys->locked != 0 )
> +    {
> +        fprintf(stderr, "###  Decoder busy");
> +        return VLCDEC_SUCCESS;
> +    }
> +    p_sys->locked = 1;
> +
> +    pDw = (uint32_t *) p_block->p_start;
> +    lsz = __Swap32(*pDw);
> +
> +//   fprintf(stderr,"###  luma size 0x%x ",lsz);
> +
> +    lsz <<= 2;
> +    pDw++;
> +
> +    if ( *pDw != 0x51FF4FFF )
> +    {
> +        msg_Err(p_dec, "Error invalid codestream (%x)", *pDw);
> +        goto __error;
> +    }
> +
> +    pDw += 2;
> +    p_sys->ui_imgH = __Swap32(*pDw);
> +    pDw++;
> +    p_sys->ui_imgV = __Swap32(*pDw);
> +    p_sys->d_ncompo = p_block->p_start[9];
> +    p_sys->bpp = p_block->p_start[46] + 1;
> +
> +    if ( p_sys->d_ncompo != 0x2f )
> +    {
> +        d_choffs = lsz + 4;
> +        pDw = (uint32_t *) &p_block->p_start[lsz + 4];
> +        chsz = __Swap32(*pDw);
> +        fprintf(stderr, "chroma size 0x%x  ", chsz);
> +        chsz <<= 2;
> +        pDw++;
> +        if ( *pDw != 0x51FF4FFF )
> +        {
> +            msg_Err(p_dec, "Error invalid chroma codestream (%x)", *pDw);
> +            for ( unsigned char tt = 0 ; tt < 8 ; tt++ )
> +                fprintf(stderr, "0x%08x ", *pDw++);
> +
> +            goto __error;
> +        }
> +    }
> +
> +    delta_smpl = 1;
> +    if ( p_sys->ui_imgH > 720 )
> +    {
> +        i_scale_factor = 1;
> +    }
> +
> +    if ( av_opt_set_int(p_sys->pCodecContext->priv_data, "lowres",
> +            i_scale_factor, AV_OPT_TYPE_INT) != 0 )
> +    {
> +        msg_Err(p_dec, "Error rescaling picture");
> +    }
> +    if ( av_opt_set_int(p_sys->pCodecContext_ch->priv_data, "lowres",
> +            i_scale_factor, AV_OPT_TYPE_INT) != 0 )
> +    {
> +        msg_Err(p_dec, "Error rescaling picture");
> +    }
> +    p_sys->ui_imgH >>= i_scale_factor;
> +    p_sys->ui_imgV >>= i_scale_factor;
> +
> +    p_dec->fmt_out.i_codec = VLC_CODEC_RGB24; // VLC_CODEC_UYVY; //
> +    p_dec->fmt_out.video.i_visible_width = p_dec->fmt_out.video.i_width =
> +            p_sys->ui_imgH;
> +    p_dec->fmt_out.video.i_visible_height = p_dec->fmt_out.video.i_height =
> +            p_sys->ui_imgV;
> +    p_dec->fmt_out.video.i_sar_num = 1;
> +    p_dec->fmt_out.video.i_sar_den = 1;
> +
> +    p_dec->fmt_out.video.i_frame_rate = 25;
> +    p_dec->fmt_out.video.i_frame_rate_base = 1;
> +    p_dec->fmt_out.video.i_bits_per_pixel = 24;
> +
> +    p_dec->fmt_out.video.space =
> +            (p_sys->ui_imgH > 720) ? COLOR_SPACE_BT709 : COLOR_SPACE_BT601; //
> +
> +    if ( decoder_UpdateVideoFormat(p_dec) )
> +        goto __error;
> +
> +    p_pic = decoder_NewPicture(p_dec);
> +    if ( !p_pic )
> +    {
> +        msg_Err(p_dec, "Error unable to allocate picture");
> +        goto __error;
> +    }
> +
> +    av_init_packet(&p_sys->thpkt);
> +    av_init_packet(&p_sys->thpkt_ch);
> +    p_sys->thpkt.size = lsz;
> +    p_sys->thpkt.data = &p_block->p_start[4];
> +
> +    ladj = 0;
> +    while ( ladj < 16 )
> +    {
> +        if ( (p_sys->thpkt.data[p_sys->thpkt.size - 1] == 0xFF)
> +                && (p_sys->thpkt.data[p_sys->thpkt.size] == 0xD9) )
> +            break;
> +        p_sys->thpkt.size--;
> +        ladj++;
> +    }
> +    if ( ladj )
> +    {
> +        p_sys->thpkt.size++;
> +    }
> +
> +    if ( p_sys->d_ncompo != 0x2f )
> +    {
> +        p_sys->thpkt_ch.size = chsz;
> +        p_sys->thpkt_ch.data = &p_block->p_start[d_choffs + 4];
> +        ladj = 0;
> +        while ( ladj < 16 )
> +        {
> +            if ( (p_sys->thpkt_ch.data[p_sys->thpkt_ch.size - 1] == 0xFF)
> +                    && (p_sys->thpkt_ch.data[p_sys->thpkt_ch.size] == 0xD9) )
> +                break;
> +            p_sys->thpkt_ch.size--;
> +            ladj++;
> +        }
> +        if ( ladj )
> +        {
> +            p_sys->thpkt_ch.size++;
> +        }
> +        // Trick to let current libavcodec library to decode blt chroma
> +        usp = (uint32_t*) p_sys->thpkt_ch.data;
> +        usp += 2;
> +        ch_tile_size = __Swap32(*usp);
> +        ch_tile_size >>= 1;
> +        *usp = __Swap32(ch_tile_size);
> +        usp += 4;
> +        *usp = __Swap32(ch_tile_size);
> +        p_sys->thpkt_ch.data[0x2b] = 1;
> +        p_sys->thpkt_ch.data[0x2e] = 1;  // Set scale 1:1
> +    }
> +
> +    if ( avcodec_open2(p_sys->pCodecContext, p_sys->vd_codec, NULL) < 0 )
> +    {
> +        msg_Err(p_dec, "Error unable to open JPEG2000 codec");
> +        goto __error;
> +    }
> +    if ( avcodec_open2(p_sys->pCodecContext_ch, p_sys->vd_codec_ch, NULL) < 0 )
> +    {
> +        msg_Err(p_dec, "Error unable to open chroma JPEG2000 codec");
> +        goto __error;
> +    }
> +
> +    i_conv_res = avcodec_send_packet(p_sys->pCodecContext, &p_sys->thpkt);
> +    if ( (i_conv_res != 0) && (i_conv_res != AVERROR(EAGAIN)) )
> +    {
> +        if ( (i_conv_res == AVERROR(ENOMEM))
> +                || (i_conv_res == AVERROR(EINVAL)) )
> +        {
> +            msg_Err(p_dec, "Error unable to send packet");
> +            goto __error;
> +        }
> +    }
> +
> +    if ( p_sys->d_ncompo != 0x2f )
> +    {
> +        i_conv_res = avcodec_send_packet(p_sys->pCodecContext_ch,
> +                &p_sys->thpkt_ch);
> +        if ( (i_conv_res != 0) && (i_conv_res != AVERROR(EAGAIN)) )
> +        {
> +            if ( (i_conv_res == AVERROR(ENOMEM))
> +                    || (i_conv_res == AVERROR(EINVAL)) )
> +            {
> +                msg_Err(p_dec, "Error unable to send chroma packet");
> +                goto __error;
> +            }
> +        }
> +    }
> +    i_conv_res = avcodec_receive_frame(p_sys->pCodecContext, p_sys->glob_frm);
> +    if ( (i_conv_res != 0) && (i_conv_res != AVERROR(EAGAIN)) )
> +    {
> +        if ( (i_conv_res == AVERROR(ENOMEM))
> +                || (i_conv_res == AVERROR(EINVAL)) )
> +        {
> +            msg_Err(p_dec, "Critical error while receiving luma frame");
> +            goto __error;
> +        }
> +        if ( i_conv_res == AVERROR_EOF )
> +        {
> +            avcodec_flush_buffers(p_sys->pCodecContext);
> +        }
> +    }
> +    if ( p_sys->d_ncompo != 0x2f )
> +    {
> +        i_conv_res = avcodec_receive_frame(p_sys->pCodecContext_ch,
> +                p_sys->glob_frm_ch);
> +        if ( (i_conv_res != 0) && (i_conv_res != AVERROR(EAGAIN)) )
> +        {
> +            if ( (i_conv_res == AVERROR(ENOMEM))
> +                    || (i_conv_res == AVERROR(EINVAL)) )
> +            {
> +                msg_Err(p_dec, "Critical error while receiving chroma frame");
> +                goto __error;
> +            }
> +            if ( i_conv_res == AVERROR_EOF )
> +            {
> +                avcodec_flush_buffers(p_sys->pCodecContext);
> +            }
> +        }
> +    }
> +
> +    if ( i_conv_res == 0 )
> +        blt_convertUYVY_to_rgb(p_sys, p_pic->p->p_pixels);
> +
> +    p_pic->date =
> +            p_block->i_pts > VLC_TS_INVALID ? p_block->i_pts : p_block->i_dts;
> +
> +    //  p_pic->date = date_Get( &p_dec->p_sys->pts);
> +    //  date_Increment(&p_sys->pts, delta_smpl);
> +
> +    if ( decoder_QueueVideo(p_dec, p_pic) < 0 )
> +        msg_Err(p_dec, "##################   Error queuing picture");
> +
> +    p_pic->b_progressive = true;
> +
> +    __error: block_Release(p_block);
> +    p_sys->locked = 0;
> +    return VLCDEC_SUCCESS;
> +
> +}
> +// ---------------------------------------------------------------------------------------------------
> +void blt_convertUYVY_to_rgb(decoder_sys_t *p_sys, uint8_t* px)
> +{
> +    uint8_t *bf_l, *bf_ch1, *bf_ch2;
> +    int16_t *bf_ls, *bf_ch1s, *bf_ch2s;
> +    int16_t R, G, B, Y, Cr, Cb;
> +
> +    if ( p_sys->bpp == 8 )
> +    {
> +        bf_l = p_sys->glob_frm->data[0];
> +        bf_ch1 =
> +                (p_sys->d_ncompo == 0x2F) ?
> +                        p_sys->glob_frm->data[1] : p_sys->glob_frm_ch->data[0];
> +
> +        if ( p_sys->d_ncompo == 0x2F )
> +        {
> +            bf_ch2 = p_sys->glob_frm->data[2];
> +        } else
> +        {
> +            bf_ch2 = &p_sys->glob_frm_ch->data[0][1];
> +        }
> +
> +        for ( unsigned int jj = 0 ; jj < p_sys->ui_imgV ; jj++ )
> +        {
> +            Cr = *bf_ch2;
> +            Cb = *bf_ch1;
> +            for ( unsigned int kk = 0 ; kk < p_sys->ui_imgH ; kk++ )
> +            {
> +                Y = *bf_l++;
> +                if ( kk & 1 )
> +                {
> +                    Cr = *bf_ch2;
> +                    Cb = *bf_ch1;
> +                    if ( p_sys->d_ncompo == 0x2F )
> +                    {
> +                        bf_ch1++;
> +                        bf_ch2++;
> +                    } else
> +                    {
> +                        bf_ch1 += 2;
> +                        bf_ch2 += 2;
> +                    }
> +                }
> +
> +                R = Y + p_sys->i_myR_Crscaled[Cr];
> +                if ( R > 255 )
> +                    R = 255;
> +                else if ( R < 0 )
> +                    R = 0;
> +
> +                G = Y - p_sys->i_myG_Crscaled[Cr] - p_sys->i_myG_Cbscaled[Cb];
> +                if ( G > 255 )
> +                    G = 255;
> +                else if ( G < 0 )
> +                    G = 0;
> +
> +                B = Y + p_sys->i_myB_Cbscaled[Cb];
> +                if ( B > 255 )
> +                    B = 255;
> +                else if ( B < 0 )
> +                    B = 0;
> +
> +                *px++ = R;
> +                *px++ = G;
> +                *px++ = B;
> +            }
> +
> +        }
> +    } else
> +    {
> +        bf_ls = p_sys->glob_frm->data[0];
> +        bf_ch1s =
> +                (p_sys->d_ncompo == 0x2F) ?
> +                        p_sys->glob_frm->data[1] : p_sys->glob_frm_ch->data[0];
> +
> +        if ( p_sys->d_ncompo == 0x2F )
> +        {
> +            bf_ch2s = p_sys->glob_frm->data[2];
> +        } else
> +        {
> +            bf_ch2s = &p_sys->glob_frm_ch->data[0][2];
> +        }
> +
> +        for ( unsigned int jj = 0 ; jj < p_sys->ui_imgV ; jj++ )
> +        {
> +            Cr = *bf_ch2s;
> +            Cb = *bf_ch1s;
> +            Cr >>= 2;
> +            ;
> +            Cb >>= 2;
> +            for ( unsigned int kk = 0 ; kk < p_sys->ui_imgH ; kk++ )
> +            {
> +                if ( p_sys->ui_imgH > 720 )
> +                {
> +                    Y = __Swap16(*bf_ls);
> +                    Y &= 0xFF;
> +                } else
> +                {
> +                    Y = *bf_ls;
> +                    Y >>= 2;
> +                }
> +                bf_ls++;
> +                if ( kk & 1 )
> +                {
> +                    Cr = *bf_ch2s;
> +                    Cb = *bf_ch1s;
> +                    Cr >>= 2;
> +                    ;
> +                    Cb >>= 2;
> +                    if ( p_sys->d_ncompo == 0x2F )
> +                    {
> +                        bf_ch1s++;
> +                        bf_ch2s++;
> +                    } else
> +                    {
> +                        bf_ch1s += 2;
> +                        bf_ch2s += 2;
> +                    }
> +                }
> +
> +                R = Y + p_sys->i_myR_Crscaled[Cr];
> +                if ( R > 255 )
> +                    R = 255;
> +                else if ( R < 0 )
> +                    R = 0;
> +
> +                G = Y - p_sys->i_myG_Crscaled[Cr] - p_sys->i_myG_Cbscaled[Cb];
> +                if ( G > 255 )
> +                    G = 255;
> +                else if ( G < 0 )
> +                    G = 0;
> +
> +                B = Y + p_sys->i_myB_Cbscaled[Cb];
> +                if ( B > 255 )
> +                    B = 255;
> +                else if ( B < 0 )
> +                    B = 0;
> +
> +                *px++ = R;
> +                *px++ = G;
> +                *px++ = B;
> +            }
> +            if ( (p_sys->glob_frm->linesize[0] >> 1) > p_sys->ui_imgH )
> +            {
> +                int delta = p_sys->glob_frm->linesize[0] >> 1;
> +                delta -= p_sys->ui_imgH;
> +                bf_ls += delta;
> +                delta >>= 1;
> +                bf_ch1s += delta;
> +                bf_ch2s += delta;
> +            }
> +
> +        }
> +
> +    }
> +
> +}
> diff --git a/modules/demux/blt/blt_jp2k_codec.h b/modules/demux/blt/blt_jp2k_codec.h
> new file mode 100644
> index 0000000..275e75d
> --- /dev/null
> +++ b/modules/demux/blt/blt_jp2k_codec.h
> @@ -0,0 +1,20 @@
> +/*
> + * blt_jp2k_codec.h
> + *
> + *  Created on: 21 Jul 2017
> + *      Author: alfredo
> + */
> +
> +//#ifndef MODULES_DEMUX_BLT_BLT_JP2K_CODEC_H_
> +//#define MODULES_DEMUX_BLT_BLT_JP2K_CODEC_H_
> +
> +
> + int OpenBLTDecoder(vlc_object_t *p_this);
> + void CloseBLTDecoder(vlc_object_t *p_this);
> + int DecodeBlock(decoder_t *, block_t *);
> +
> +
> +
> +
> +
> +//#endif /* MODULES_DEMUX_BLT_BLT_JP2K_CODEC_H_ */
> diff --git a/modules/demux/blt/glob_def_vlci.h b/modules/demux/blt/glob_def_vlci.h
> new file mode 100644
> index 0000000..0dfd342
> --- /dev/null
> +++ b/modules/demux/blt/glob_def_vlci.h
> @@ -0,0 +1,186 @@
> +#pragma once
> +
> +#ifndef _GLOB_DEF_VLCIMPORT_
> +#define _GLOB_DEF_VLCIMPORT_
> +
> +
> +#define MAYOR_VER  1
> +#define MINOR_VER  0
> +#define REL_VER    'A'
> +
> +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> +2017/05/17 v. 1.00A    - WIP : First release (Experimental)
> +
> +
> +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
> +
> +#define DEV_ID     2 //DeviceID 0=NoDev 1=RUSColor 2=SMSLIB
> +
> +#define Fbuf_size    20000000
> +#define Fbuf_size1   24000000
> +
> +#define Ibuf_size    1080000 //Tabella download clip 1080000=30*60*60*10 (10ore a 30frm)
> +
> +#define EEbuf_size   0x60000 //393.216 (0x60000 = 150 mBits)
> +
> +#define CLIP_FIRST_LBA 98304
> +#define CLIP_TABLE_LBA 32768
> +#define CLIP_ENTRY_LBA CLIP_TABLE_LBA-16
> +#define USED_TAB_LBA   CLIP_ENTRY_LBA-1024
> +
> +#define LENheader 4096     //Dimensione header file .blt
> +#define MAX_CAR_STR  50
> +
> +#define CLNL     64 //Numero byte nome clip (campo 1 e 2)
> +#define CLN3     48 //Numero byte nome clip (campo 3)
> +#define CIDL     16 //Numero byte ID univoco clip
> +
> +#define SHFTSCT  12 //Shift x Settore da 2048 Byte
> +
> +#define CHNAUD 16 //numero totale canali audio x file BLT
> +
> +
> +#define AUDIO_BUFF_SIZE  CHNAUD * 2 *1920  // Max buffer size per frame
> +
> +#define NN_CAR 48
> +#define LEN_SN 38 //Massima lunghezza nome Still
> +/*
> +#define LN_N1     1
> +#define LN_N2     2
> +#define LN_N3     3
> +#define LN_DAT    4
> +#define LN_DUR    5
> +#define LN_NUM    6
> +#define LN_TVS    7
> +#define LN_VID    8
> +#define LN_ASP    9
> +#define LN_VTK   10
> +#define LN_CID   11
> +#define LN_FPTH  12
> +#define LN_FNAM  13
> +#define LN_FCRE  14
> +#define LN_FLEN  15
> +*/
> +#define CLN1     64 //Numero byte nome clip (campo 1)
> +#define CLN2     48 //Numero byte nome clip (campo 2)
> +#define CLN3     48 //Numero byte nome clip (campo 3)
> +#define CIDL     16 //Numero byte ID univoco clip
> +
> +//  dimh dimv posh posv
> +
> +#define VF00  0 //form Principale
> +#define VF01  1 //form bkptab
> +#define VF02  2 //form smscmd
> +#define VF05  5 //form smslog
> +#define VF06  6 //form smsmemo
> +
> +#define MAX_RCDEV          8 //Numero massimo schede x Rec su bus PCIexpress
> +#define MAX_INPNAM        24 //Lunghezza nome Input
> +
> +//Tabella Registrazione in SSM - DA TENERE AGGIORNATA CON RUSEXP e Teca !!!!!
> +#define NoSSM        0 //No SSM
> +#define c2S2      0x81 //SSMx2
> +#define  c3S3     0x82 //SSMx3
> +#define  c3S2C    0x83 //SSMx2+1
> +#define c4S2S2    0x84 //SSMx2+SSMx2
> +#define c4S2CD    0x85 //SSMx2+1+1
> +#define c4S3D     0x86 //SSMx3+1
> +#define  c5S3S2   0x87 //SSMx3+SSMx2
> +#define  c5S3DE   0x88 //SSMx3+1+1
> +#define  c5S2S2E  0x89 //SSMx2+SSMx2+1
> +#define  c5S2CDE  0x8A //SSMx2+1+1+1
> +#define c6S3S3    0x8B //SSMx3+SSMx3
> +#define c6S3S2F   0x8C //SSMx3+SSMx2+1
> +#define c6S3DEF   0x8D //SSMx3+1+1+1
> +#define c6S2S2S2  0x8E //SSMx2+SSMx2+SSMx2
> +#define c6S2S2EF  0x8F //SSMx2+SSMx2+1+1
> +#define c6S2CDEF  0x90 //SSMx2+1+1+1+1
> +
> +// Bit variabile clip_tab.clf1 (usato solo in elenco Clip)
> +#define CLJPG  0x01 //Clip JPEG
> +#define CLN4K  0x02 //Clip non allineata a 4K
> +#define CLVKA  0x04 //1=Video+Key+Audio    //ex CLASP  0x04 //Aspect 0=16/9 - 1=4/3
> +#define CL3D   0x08 //1=3D    //ex TECPL  0x08 //Clip x Teca PlayOut (usato da solo da smsteca)
> +#define CLVK3D (CLVKA|CL3D) //
> +#define ENASP  0x10 //Flag Aspect Abilitato (x compatibilita con WdrTeca)
> +#define ASP16  0x20 //Aspect 0=4/3 - 1=16/9 (x compatibilita con WdrTeca)
> +#define SSM2X  0x40 //1= SuperMotion x 2
> +#define SSM3X  0x80 //1= SuperMotion x 3
> +
> +// Bit variabile mbcfg.mbdbg
> +#define DBGEN   0x01
> +#define DBDSP   0x02
> +#define DBLAN   0x04
> +#define DBFIL   0x08
> +#define DBUID   0x10
> +
> +/***inizio**** variabili memorizzate in file di configurazione ****************/
> +
> +
> +/****fine***** variabili memorizzate in file di configurazione ****************/
> +
> +
> +#define my_Decompressor_Version                        (0x00040001)    // The high word is the codecInterfaceVersion.
> +#define my_Compressor_Version                          (0x00040001)
> +
> +#define KDU_TRUNC_FACTOR                              0 //768             // Each 256 increment equals removal of one coding pass from all code blocks.
> +#define XDCAM_AU_BUFF_SIZE  48000 * CHNAUD * 2 * 32
> +
> +#define LIV_ZOOM 10
> +#define HEADER_LENGTH_DEF 0x10000
> +#define MAX_HEADER_BUFF   0x400000
> +
> +// CUF February 2015 - Definitions according to BLTJP2KV6.pdf dated 3 August 2010
> +
> +typedef  enum { CONV_OK_GOT_PACKET=1,     // Conversion OK, valid packet in thpkt
> +                CONV_OK=0,                // Conversion OK, no valid packet in thpkt
> +                CONV_NO_MARK_INIT=-1,     // Marker FFFFFFF8 not found
> +                CONV_NO_MARK_TCD=-2,      // Marker FFFFFFF4 not found
> +                CONV_NO_MARK_AU=-3,       // Marker FFFFFFF5 not found
> +                CONV_MARK_F0_INV=-4,      // Field 0 toggle
> +                CONV_MARK_F1_INV=-5,      // Field 1 toggle
> +                CONV_ERR_IMG_ALLOC=-6,    // Error allocating image
> +                CONV_ERR_KDU=-7,          // Error (kdu) decompressing image
> +                CONV_ERR_OPEN=-8,         // Error opening codec (libavcodec)
> +                CONV_ERR_FFENC=-9        // Error compressing image (libavcodec)
> +              } conv_stat ;
> +
> +typedef  enum { TYPE_JPEG2000=1,     // Jpeg 200 video
> +                TYPE_MJPEG_DS1=2,   // MJPEG video (EVS DS1 file format)
> +                TYPE_D10=3,         // D10 video (mpeg2)
> +                TYPE_MPEG2_ES=4,    // XDCAM video (Mpeg2 elementary stream)
> +                TYPE_DVPAL=5,
> +                TYPE_DVNTSC=6,
> +                TYPE_AVC=7,
> +                TYPE_UPHD=8,
> +                TYPE_VC3=9,         // AVID DNxHD codec
> +                TYPE_UNKNOWN=-1
> +               } video_type ;
> +
> +#define LUMA_SIZE     1024 * 1024       // Luma buffer 1M
> +#define CHROMA_SIZE   LUMA_SIZE      // Chroma buffer 512K for each component
> +#define CR1_OFFS      LUMA_SIZE
> +#define CR2_OFFS      CR1_OFFS + (CHROMA_SIZE>>1)
> +#define LCH_SIZE      LUMA_SIZE + CHROMA_SIZE     // Field buffer 2M
> +
> +#define CONVBUF_SIZE  4 * (LCH_SIZE)  // 8M 2M for each Field
> +
> +#define NUM_KDU_THREADS 8 // Un thread per field
> +
> +#define _MAX_PATH 1024
> +
> +#define DWORD int32_t
> +
> +
> +
> +
> +
> +
> +#define __Swap32(myVal) (((myVal<<24)&0xFF000000) | ((myVal<<8)&0x00FF0000) | ((myVal>>8)&0x0000FF00) | ((myVal>>24)&0x000000FF))
> +
> +#define __Swap16(myVal) (((myVal>>8)&0x00FF) | ((myVal<<8)&0xFF00))
> +
> +
> +#define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24))
> +
> +#endif
> diff --git a/modules/demux/blt/glob_struct_vlci.h b/modules/demux/blt/glob_struct_vlci.h
> new file mode 100644
> index 0000000..46d6e33
> --- /dev/null
> +++ b/modules/demux/blt/glob_struct_vlci.h
> @@ -0,0 +1,71 @@
> +
> +#ifndef _GLOBSTRUCT_
> +#define _GLOBSTRUCT_
> +
> +
> +struct pclp_tab //Tabella dati memorizzati x PcClip
> +{
> + unsigned char  pcachn,     //Numero canali Audio Clip corrente (4,8,16)
> +                pcdsk,      //HDD sorgente di Clip caricata su PC
> +                pcname[_MAX_PATH], //Nome File di Clip caricata su PC (senza Path e senza Estensione)
> +                pcpath[_MAX_PATH], //File Path di Clip caricata su PC (senza nome)
> +                pctype,     //Versione file di Clip caricata su PC  2=JP2k, 3=MXF XDCAM, 4=MXF DNxHD, 5=MXF D10
> +                pctv_std,   //0: 50Hz, 1: 59,94
> +                pcvd,       //Video Compression 0=JPEG 1=JP2K 2=MPEG2 3=DNxHD
> +                proxq,      //Qualita proxy 0=No proxy
> +                clpmsk,     //Maschera canali registrati
> +                cchn,       //Canale preferenziale
> +                pcssm,      //SuperSlomo: 0,1 = normale; 2 = x2; 3 = x3;
> +                pcvtrack,   //Video track Type: 0 = normale; 1 = VKA; 2 = Stereo
> +                tv_format,
> +                ref_clip;   // If set this is a reference clip (pcpath and pcname contains the referenced file)
> + uint16_t       fldprec,    //Allineamento Field (1024,2048,4096) // KAG_SIZE per mxf file
> +                hhlen,      //pixel x line
> +                pcbn,       //Numero Clip su HDD Backup (se madre coincide con pare)
> +                pcpa,       //User ID (x richiamo clip tramite numero)
> +                precslv,    //Allineamento Field clip slave (1024,2048,4096)
> +                vvlen;      //Numero righe immagine
> + int            pcclip,     //Numero di Clip caricata su PC
> +                pcasample,   //32KHz - 48KHz
> +                pcaprecision, //8 - 16 - 24 bit
> +                pcaspect;     //0->4:3, 1->16:9
> + long           pcbrk,
> +                pcci,pcco,  //CTL Clip IN/OUT
> +                pcti,pcto,  //TCD Clip IN/OUT
> +                pcui,pcuo,  //User Bit IN/OUT
> +                pclstfrm,   // last frame pushed
> +                pctotf,     // Total frame number for Clip loaded
> +                pctfslv;    // Total frame number for slave Clip loaded
> + DWORD         grwing,     // Growing file
> +                memgrw,     // Growing flag
> +                pcli,pclo,  // LBA Clip IN/OUT
> +                pnte;       // Puntatore Posizione Dati Clip caricata su PC in Elenco (x Edit Clip su PC)
> + uint64_t       pclen;      //Dimensione File Clip su PC
> + unsigned char  pcn1[CLNL], //Buffer nome1 Clip (64 Byte)
> +                pcn2[CLNL], //Buffer nome2 Clip (64 Byte)
> +                pcn3[CLN3], //Buffer nome3 Clip (48 Byte)
> +                pcid[CIDL], //Buffer ID unico x riconoscimento Clip (16 Byte)
> +                smsn[MAX_INPNAM],
> +                appn[CLNL], // Application name
> +                clid[CLNL], // Clip ID
> +                camn[MAX_RCDEV][MAX_INPNAM];
> + //String         pcaudio,      //Uncompress
> +  //              pctvstand;    //576/50i - 480/60i - 1080/50i - 1080/60i - 720/50P - 720/60P -2180/50P
> +};
> +
> +struct imm_tab //Tabella dati memorizzati x ogni Frame di Imm su Hdd Scsi
> +{
> + unsigned char  fld0,   //Size Fld 0 (in KByte)
> +                fld1,   //Size Fld 1 (in KByte)
> +                errt,
> +                tcdt[8];
> + uint64_t       frma;    //Offset inizio Frame (dall`inizio file)
> +};
> +
> +
> +
> +
> +
> +#endif // _GLOBSTRUCT_
> +
> +
> diff --git a/modules/demux/blt/libblt.c b/modules/demux/blt/libblt.c
> new file mode 100644
> index 0000000..5a1087a
> --- /dev/null
> +++ b/modules/demux/blt/libblt.c
> @@ -0,0 +1,679 @@
> +#ifdef HAVE_CONFIG_H
> +# include "config.h"
> +#endif
> +
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +/* VLC core API headers */
> +#include <vlc_common.h>
> +#include <vlc_plugin.h>
> +#include <vlc_access.h>
> +#include <vlc_demux.h>
> +#include <vlc_input.h>
> +
> +#include <vlc_dialog.h>
> +
> +#include <vlc_meta.h>
> +//#include <vlc_codecs.h>
> +#include <vlc_charset.h>
> +#include <vlc_memory.h>
> +
> +#include <vlc_fourcc.h>
> +//#include <vlc_interface.h>
> +#include <vlc_fs.h>
> +#include <vlc_stream.h>
> +
> +#include <vlc_codec.h>
> +
> +#include <vlc_messages.h>
> +
> +#include "glob_def_vlci.h"
> +#include "glob_struct_vlci.h"
> +#include "BLT_Utils.h"
> +
> +#include "blt_jp2k_codec.h"
> +
> +enum AVOptionType
> +{
> +    AV_OPT_TYPE_FLAGS,
> +    AV_OPT_TYPE_INT,
> +    AV_OPT_TYPE_INT64,
> +    AV_OPT_TYPE_DOUBLE,
> +    AV_OPT_TYPE_FLOAT,
> +    AV_OPT_TYPE_STRING,
> +    AV_OPT_TYPE_RATIONAL,
> +    AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
> +    AV_OPT_TYPE_DICT,
> +    AV_OPT_TYPE_UINT64,
> +    AV_OPT_TYPE_CONST = 128,
> +    AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S', 'I', 'Z', 'E'), ///< offset must point to two consecutive integers
> +    AV_OPT_TYPE_PIXEL_FMT = MKBETAG('P', 'F', 'M', 'T'),
> +    AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S', 'F', 'M', 'T'),
> +    AV_OPT_TYPE_VIDEO_RATE = MKBETAG('V', 'R', 'A', 'T'), ///< offset must point to AVRational
> +    AV_OPT_TYPE_DURATION = MKBETAG('D', 'U', 'R', ' '),
> +    AV_OPT_TYPE_COLOR = MKBETAG('C', 'O', 'L', 'R'),
> +    AV_OPT_TYPE_CHANNEL_LAYOUT = MKBETAG('C', 'H', 'L', 'A'),
> +    AV_OPT_TYPE_BOOL = MKBETAG('B', 'O', 'O', 'L'),
> +};
> +
> +extern int av_opt_set_int(void *obj, const char *name, int64_t val,
> +        int search_flags);
> +
> +#define SIZE_TEXT N_("Video size")
> +#define SIZE_LONGTEXT N_( \
> + "Size of the video that will be displayed by the" \
> + "plugin. If you don't specify anything the default size will be used ")
> +
> +/* Forward declarations */
> +static int DemuxOpen(vlc_object_t *);
> +static void DemuxClose(vlc_object_t *);
> +
> +/*****************************************************************************
> + * Local prototypes
> + *****************************************************************************/
> +static int BLTControl(demux_t * p_demux, int i_query, va_list args);
> +static int blt_Seek(demux_t *, double, uint8_t*, uint8_t*);
> +static int Blt_demux_seekable(demux_t*);
> +static int Blt_track_seek(demux_t*, int, mtime_t);
> +
> +typedef struct
> +{
> +    bool b_activated;
> +    bool b_eof;
> +
> +    unsigned int i_cat; /* AUDIO_ES, VIDEO_ES */
> +    vlc_fourcc_t i_codec;
> +
> +    unsigned int i_rate;
> +    unsigned int i_scale;
> +    unsigned int i_samplesize;
> +
> +    unsigned int i_width_bytes;
> +    bool b_flipped;
> +
> +    es_out_id_t *p_es; // Evaluate this
> +
> +    int i_dv_audio_rate;
> +    es_out_id_t *p_es_dv_audio;
> +    unsigned char dim0;
> +    unsigned char dim1;
> +
> +    int cframe; /* current frame number */
> +
> +} blt_track_t;
> +
> +struct demux_sys_t
> +{
> +    struct pclp_tab *p_pctab;
> +    unsigned char *p_blt_tbl;
> +
> +    mtime_t i_time;
> +    mtime_t i_length;
> +    uint8_t *p_rd_buff;
> +    uint8_t *p_audiobuff;
> +
> +    bool b_seekable;
> +    bool b_paused;
> +    unsigned long simple_cnt;
> +    vlc_meta_t *p_meta;
> +    /* number of streams and information */
> +    unsigned int i_track;
> +    blt_track_t **pp_track;
> +
> +};
> +
> +/* Module descriptor */
> +vlc_module_begin()
> +    set_shortname(N_("BLT Import"))
> +    set_description(N_("BLT Files demuxer"))
> +    set_category(CAT_INPUT)
> +    set_subcategory(SUBCAT_INPUT_DEMUX)
> +    //SUBCAT_INPUT_ACCESS)
> +    set_capability("demux", 50)
> +    set_callbacks(DemuxOpen, DemuxClose)
> +
> +    add_submodule()
> +    set_section(N_("Decoding"), NULL)
> +    set_description(N_("BLT JP2K decoder"))
> +    set_capability("video decoder", 250)
> +    set_callbacks(OpenBLTDecoder, CloseBLTDecoder)
> +    add_shortcut("blt")
> +    vlc_module_end ()
> +
> +    /*****************************************************************************
> +     * Open: check file and initializes BLT structures
> +     *****************************************************************************/
> +
> +static int DemuxOpen(vlc_object_t * obj)
> +{
> +
> +    demux_t *dm = (demux_t*) obj;
> +    demux_sys_t* sys = calloc(1, sizeof(*sys));
> +    const uint8_t *p_head = NULL;
> +    uint32_t ui_size;
> +    char buffer[256], *facp;
> +    unsigned char oo, mm, ss, ff;
> +
> +    if ( unlikely(sys == NULL) )
> +        return VLC_ENOMEM;
> +    dm->p_sys = sys;
> +
> +    sys->pp_track = NULL;
> +    sys->p_pctab = NULL;
> +    sys->p_blt_tbl = NULL;
> +    sys->p_rd_buff = NULL;
> +    sys->simple_cnt = 0;
> +    sys->p_audiobuff = NULL;
> +
> +    vlc_stream_Control(dm->s, STREAM_CAN_SEEK, &sys->b_seekable);
> +
> +    if ( dm->psz_demux != NULL )
> +    {
> +        free(dm->psz_demux);
> +        dm->psz_demux = strdup("ps");
> +    }
> +    if ( dm->psz_access != NULL )
> +    {
> +        msg_Dbg(dm, "##################  Found access value %s",
> +                dm->psz_access);
> +    }
> +    if ( dm->psz_location != NULL )
> +    {
> +        msg_Dbg(dm, "##################  Found location value %s",
> +                dm->psz_location);
> +    }
> +
> +    sys->p_pctab = calloc(1, sizeof(*sys->p_pctab));
> +    if ( unlikely(sys->p_pctab == NULL) )
> +    {
> +        msg_Err(obj, "Error allocating cliptab");
> +        goto _demux_error;
> +    }
> +    memset(sys->p_pctab, 0, sizeof(*sys->p_pctab));         // Clears it
> +
> +    sys->p_audiobuff = calloc(1, AUDIO_BUFF_SIZE);
> +    if ( unlikely(sys->p_audiobuff == NULL) )
> +    {
> +        msg_Err(obj, "Error allocating audio buffer");
> +        goto _demux_error;
> +    }
> +
> +    if ( dm->psz_file != NULL )
> +    {
> +        if ( vlc_stream_Peek(dm->s, &p_head, 4096) < 4096 )
> +        {
> +            msg_Err(obj, "Error reading header from stream");
> +            goto _demux_error;
> +        }
> +        if ( BLT_rd_blt_header(sys->p_pctab, p_head) < 0 )
> +        {
> +            msg_Err(obj, "Error reading header");
> +            goto _demux_error;
> +        }
> +        msg_Dbg(obj, "BLT File found : Frames %d, audio channels %d",
> +                (int ) sys->p_pctab->pctotf, sys->p_pctab->pcachn);
> +        ui_size = sys->p_pctab->pctotf << 4;
> +        if ( ui_size & 0xFFF )
> +        {
> +            ui_size |= 0xFFF;
> +            ui_size++;
> +        }
> +        sys->p_blt_tbl = calloc(1, ui_size);
> +        if ( unlikely(sys->p_blt_tbl == NULL) )
> +        {
> +            msg_Err(obj, "Error allocating blt table memory");
> +            goto _demux_error;
> +        }
> +        if ( vlc_stream_Seek(dm->s, 4096) != VLC_SUCCESS )
> +        {
> +            msg_Err(obj, "Error seeking stream");
> +            goto _demux_error;
> +        }
> +        if ( vlc_stream_Peek(dm->s, &p_head, ui_size) < ui_size )
> +        {
> +            msg_Err(obj, "Error reading table from stream");
> +            goto _demux_error;
> +        }
> +        memcpy(sys->p_blt_tbl, p_head, ui_size);
> +    } else
> +    {
> +        msg_Err(obj, "############## File pointer NULL");
> +        goto _demux_error;
> +    }
> +    /* Allocate video track  */
> +    blt_track_t *p_tkv = calloc(1, sizeof(blt_track_t));
> +    if ( unlikely(!p_tkv) )
> +    {
> +        msg_Err(obj, "############## Error allocating video track");
> +        goto _demux_error;
> +    }
> +
> +    es_format_t fmtv;
> +    vlc_fourcc_t chroma = VLC_CODEC_JPEG2000;         //UYVY;
> +
> +    p_tkv->b_eof = false;
> +    p_tkv->b_activated = true;
> +    p_tkv->i_rate = (sys->p_pctab->tv_format & 1) ? 30 : 25;
> +    p_tkv->i_scale = 1;
> +    p_tkv->i_samplesize = -1;
> +    p_tkv->cframe = -1;
> +
> +    p_tkv->i_cat = VIDEO_ES;
> +    es_format_Init(&fmtv, VIDEO_ES, chroma);
> +
> +    fmtv.video.i_width = sys->p_pctab->hhlen;
> +    fmtv.video.i_height = sys->p_pctab->vvlen;
> +    fmtv.video.i_visible_width = sys->p_pctab->hhlen;
> +    fmtv.video.i_visible_height = sys->p_pctab->vvlen;
> +    fmtv.video.i_bits_per_pixel = 16;
> +    fmtv.video.i_frame_rate = (sys->p_pctab->tv_format & 1) ? 30.0 : 25.0;
> +    fmtv.video.i_frame_rate_base = p_tkv->i_scale;
> +    fmtv.b_packetized = false;
> +
> +    fmtv.video.i_sar_num = 1;
> +    fmtv.video.i_sar_den = 1;
> +    fmtv.video.space = COLOR_SPACE_BT709;
> +    fmtv.video.transfer = TRANSFER_FUNC_BT709;
> +    fmtv.video.primaries = COLOR_PRIMARIES_BT709;
> +    fmtv.psz_description = strdup("BLT Codestream");
> +    p_tkv->i_dv_audio_rate = 0;
> +    p_tkv->p_es = es_out_Add(dm->out, &fmtv);
> +    TAB_APPEND(sys->i_track, sys->pp_track, p_tkv);
> +
> +    /*  Allocate audio track  */
> +    blt_track_t *p_tka = calloc(1, sizeof(blt_track_t));
> +    if ( unlikely(!p_tka) )
> +    {
> +        msg_Err(obj, "############## Error allocating audio track");
> +        goto _demux_error;
> +    }
> +    es_format_t fmta;
> +
> +    p_tka->b_eof = false;
> +    p_tka->b_activated = true;
> +    p_tka->i_rate = sys->p_pctab->pcasample;
> +    p_tka->i_scale = 1;
> +    p_tka->i_samplesize = sys->p_pctab->pcachn
> +            * (sys->p_pctab->pcaprecision >> 3) * 1920;
> +    p_tka->i_codec = VLC_CODEC_S16L;
> +    p_tka->cframe = -1;
> +
> +    p_tka->i_cat = AUDIO_ES;
> +    es_format_Init(&fmta, AUDIO_ES, p_tka->i_codec);
> +    fmta.audio.i_channels = sys->p_pctab->pcachn;
> +    fmta.audio.i_rate = sys->p_pctab->pcasample;
> +    fmta.i_bitrate = sys->p_pctab->pcasample * 16;
> +    fmta.audio.i_blockalign = sys->p_pctab->pcachn;
> +    fmta.audio.i_bitspersample = sys->p_pctab->pcaprecision;
> +    fmta.b_packetized = false;
> +
> +    p_tka->i_dv_audio_rate = sys->p_pctab->pcasample;
> +    fmta.psz_description = strdup("it");
> +    p_tka->p_es = es_out_Add(dm->out, &fmta);
> +    TAB_APPEND(sys->i_track, sys->pp_track, p_tka);
> +
> +    /* *** movie length in sec *** */
> +    sys->i_length = (mtime_t) (sys->p_pctab->pctotf * 40000);
> +
> +    dm->pf_control = BLTControl;
> +    dm->pf_demux = Blt_demux_seekable;
> +    sys->b_paused = false;
> +
> +    sys->p_meta = vlc_meta_New();
> +
> +    ff = sys->p_pctab->pcui;
> +    ss = (sys->p_pctab->pcui >> 8);
> +    mm = (sys->p_pctab->pcui >> 16);
> +    oo = (sys->p_pctab->pcui >> 24);
> +    sprintf(buffer, "%.2x%.2x/%.2x/%.2x", oo, mm, ss, ff);
> +    vlc_meta_AddExtra(sys->p_meta, "Date ", buffer);
> +
> +    BLT_cv_long_tcs(sys->p_pctab->pcti, (sys->p_pctab->tv_format & 1), buffer,
> +            &oo, &mm, &ss, &ff);
> +    sprintf(&buffer[1], "%.2d:%.2d:%.2d:%.2d", oo, mm, ss, ff);
> +    vlc_meta_AddExtra(sys->p_meta, "Start TCD", buffer);
> +
> +    BLT_Frm2Time((sys->p_pctab->pcco - sys->p_pctab->pcci + 1),
> +            (sys->p_pctab->tv_format & 1), &oo, &mm, &ss, &ff);
> +    sprintf(buffer, "%.2d:%.2d:%.2d:%.2d", oo, mm, ss, ff);
> +    vlc_meta_AddExtra(sys->p_meta, "Duration", buffer);
> +
> +    vlc_meta_AddExtra(sys->p_meta, "  ID  ", sys->p_pctab->clid);
> +
> +    facp = FromCharset(vlc_pgettext("GetACP", "CP1252"), sys->p_pctab->appn,
> +            strlen(sys->p_pctab->appn));
> +    if ( facp )
> +    {
> +        vlc_meta_Set(sys->p_meta, vlc_meta_EncodedBy, facp);
> +        free(facp);
> +    }
> +
> +    return VLC_SUCCESS;
> +
> +    _demux_error:
> +    msg_Err(obj, "################## DemuxOpen error \n");
> +
> +    if ( sys->p_pctab != NULL )
> +    {
> +        free(sys->p_pctab);
> +        sys->p_pctab = NULL;
> +    }
> +    if ( sys->p_blt_tbl != NULL )
> +    {
> +        free(sys->p_blt_tbl);
> +        sys->p_blt_tbl = NULL;
> +    }
> +    if ( sys->p_audiobuff != NULL )
> +    {
> +        free(sys->p_audiobuff);
> +        sys->p_audiobuff = NULL;
> +    }
> +    free(sys);
> +    return VLC_EGENERIC;
> +
> +}
> +// ----------------------------------------------------------------------------
> +static void DemuxClose(vlc_object_t * obj)
> +{
> +    demux_t *dm = (demux_t*) obj;
> +    demux_sys_t* sys = dm->p_sys;
> +    if ( sys->p_audiobuff != NULL )
> +        free(sys->p_audiobuff);
> +    if ( sys->p_pctab != NULL )
> +        free(sys->p_pctab);
> +    if ( sys->p_meta )
> +        vlc_meta_Delete(sys->p_meta);
> +    if ( sys->p_blt_tbl != NULL )
> +        free(sys->p_blt_tbl);
> +    free(sys);
> +
> +}
> +// ----------------------------------------------------------------------------
> +
> +static int blt_Seek(demux_t * p_dem, double pos, uint8_t* dim0, uint8_t* dim1)
> +{
> +    unsigned int offs;
> +    int64_t fofs = 0;
> +    unsigned char kk;
> +    demux_sys_t* sys = p_dem->p_sys;
> +
> +    offs = (int) pos << 4;
> +    for ( kk = 0; kk < 5 ; kk++ )
> +    {
> +        fofs <<= 8;
> +        fofs |= sys->p_blt_tbl[offs + 8 + kk];
> +    }
> +    if ( dim0 != NULL )
> +        *dim0 = sys->p_blt_tbl[offs + 13];
> +    if ( dim1 != NULL )
> +        *dim1 = sys->p_blt_tbl[offs + 14];
> +
> +    if ( vlc_stream_Seek(p_dem->s, fofs) != VLC_SUCCESS )
> +    {
> +        msg_Err(p_dem, "Error seeking stream");
> +        return VLC_EGENERIC;
> +    }
> +
> +    return VLC_SUCCESS;
> +}
> +
> +// ----------------------------------------------------------------------------
> +static int BLTControl(demux_t * p_demux, int i_query, va_list args)
> +{
> +    double fs, *pf, frm;
> +    int64_t *pi64, i64;
> +    bool *pb;
> +    int retval = VLC_SUCCESS;
> +    vlc_meta_t *p_meta;
> +
> +    switch ( i_query )
> +    {
> +    case DEMUX_GET_POSITION:
> +        pf = (double*) va_arg(args, double*);
> +        fs = p_demux->p_sys->p_pctab->pclstfrm;
> +        fs /= p_demux->p_sys->p_pctab->pctotf;
> +        *pf = fs;
> +    break;
> +    case DEMUX_SET_POSITION:
> +        fs = (double) va_arg (args, double);
> +        frm = p_demux->p_sys->p_pctab->pctotf;
> +        frm *= fs;
> +        p_demux->p_sys->i_time = 40000 * frm;
> +        if ( blt_Seek(p_demux, fs, NULL, NULL) != 0 )
> +            retval = VLC_EGENERIC;
> +        for ( unsigned char trkcnt = 0 ; trkcnt < p_demux->p_sys->i_track ;
> +                trkcnt++ )
> +            p_demux->p_sys->pp_track[trkcnt]->cframe = (int) frm;
> +        Blt_demux_seekable(p_demux);
> +    break;
> +    case DEMUX_GET_TIME:
> +        pi64 = (int64_t*)va_arg (args, int64_t *);
> +        *pi64 = p_demux->p_sys->i_time;
> +    break;
> +    case DEMUX_SET_TIME:
> +        i64 = (int64_t) va_arg(args, int64_t);  // Time is im usec
> +        p_demux->p_sys->i_time = i64;
> +        i64 /= 40000; //
> +        if ( blt_Seek(p_demux, i64, NULL, NULL) != 0 )
> +            retval = VLC_EGENERIC;
> +    break;
> +    case DEMUX_GET_LENGTH:
> +        pi64 = (int64_t*)va_arg (args, int64_t *);
> +        *pi64 = (p_demux->p_sys->p_pctab->pctotf * 40000);
> +    break;
> +    case DEMUX_GET_FPS:
> +        pf = (double*) va_arg(args, double*);
> +        *pf = 25.0;
> +    break;
> +    case DEMUX_CAN_SEEK:
> +        pb = (bool*) va_arg(args, bool*);
> +        *pb = true;
> +    break;
> +    case DEMUX_GET_META:
> +        p_meta = va_arg(args, vlc_meta_t*);
> +        vlc_meta_Merge(p_meta, p_demux->p_sys->p_meta);
> +
> +    break;
> +    break;
> +    case DEMUX_SET_PAUSE_STATE:
> +        p_demux->p_sys->b_paused = (bool)
> +    va_arg(args, bool*);
> +    break;
> +    case DEMUX_GET_PTS_DELAY:
> +        pi64 = (int64_t*)va_arg (args, int64_t *);
> +        *pi64 = 40000; // Value is in useconds
> +    break;
> +    default:
> +        retval = VLC_EGENERIC;
> +    }
> +
> +    return retval;
> +}
> +// ----------------------------------------------------------------------------
> +
> +static int Blt_track_seek(demux_t* p_demux, int i_stream, mtime_t i_date)
> +{
> +    demux_sys_t *p_sys = p_demux->p_sys;
> +    int reterr = VLC_SUCCESS;
> +#define p_stream p_sys->pp_track[i_stream]
> +    unsigned long frame = 0;
> +
> +    if ( (p_stream->i_cat == AUDIO_ES)||(p_stream->i_cat == VIDEO_ES))
> +    {
> +        frame = (i_date * 1000)/ 40;
> +        if(frame > p_sys->p_pctab->pctotf) reterr = VLC_EGENERIC;
> +        else
> +        {
> +            reterr = blt_Seek( p_demux, frame, &p_stream->dim0,&p_stream->dim1);
> +        }
> +    }
> +    else
> +    {
> +        reterr = VLC_EGENERIC;
> +    }
> +    return reterr;
> +
> +}
> +
> +// ----------------------------------------------------------------------------
> +
> +static int Blt_demux_seekable(demux_t* p_demux)
> +{
> +    demux_sys_t *p_sys = p_demux->p_sys;
> +    unsigned int i_track_count = 0;
> +    unsigned int i_track, fld0_ausz, fld1_ausz, luma0_sz, luma1_sz, fld0_sz,
> +            chr_sz;
> +    unsigned char nucompo;
> +    int cur_frm;
> +    size_t blsize;
> +    block_t *p_frame = NULL;
> +    blt_track_t *p_ctk = NULL;
> +    int cds_offs, bl_offs, chr_offs;
> +
> +    p_sys->simple_cnt++;
> +    for ( i_track = 0; i_track < p_sys->i_track ; i_track++ )
> +    {
> +        blt_track_t *p_tk = p_sys->pp_track[i_track];
> +        bool sel;
> +        es_out_Control(p_demux->out, ES_OUT_GET_ES_STATE, p_tk->p_es, &sel);
> +        if ( p_tk->p_es_dv_audio )
> +        {
> +            bool b_extra;
> +            es_out_Control(p_demux->out, ES_OUT_GET_ES_STATE,
> +                    p_tk->p_es_dv_audio, &b_extra);
> +            sel |= b_extra;
> +        }
> +        if ( sel && !p_tk->b_activated )
> +        {
> +            Blt_track_seek(p_demux, i_track, p_sys->i_time);
> +            p_tk->b_activated = true;
> +        } else if ( !sel && p_tk->b_activated )
> +        {
> +            p_tk->b_activated = false;
> +        }
> +        if ( sel )
> +        {
> +            i_track_count++;
> +        }
> +    }
> +    if ( i_track_count <= 0 )
> +    {
> +        msg_Err(p_demux, "no track selected, exiting....");
> +        return 0;
> +    }
> +
> +    cur_frm = p_sys->i_time / 40000;
> +    // wait for the good time
> +    es_out_Control(p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_time);
> +
> +    fld0_ausz = fld1_ausz = 0;
> +    for ( i_track = 0; i_track < p_sys->i_track ; i_track++ )
> +    {
> +        p_ctk = p_sys->pp_track[i_track];
> +        if ( p_sys->b_paused )
> +            cur_frm = p_ctk->cframe;
> +
> +        if ( (p_ctk->cframe <= cur_frm)
> +                && (cur_frm < (unsigned int) p_sys->p_pctab->pctotf) )
> +        {
> +            // Read and decompress frame
> +            p_sys->p_pctab->pclstfrm = cur_frm;
> +
> +            if ( p_ctk->i_dv_audio_rate )
> +            {
> +                if ( (fld0_ausz == 0) || (fld1_ausz == 0) )
> +                {
> +                    blsize = p_sys->p_pctab->pcachn
> +                            * (p_sys->p_pctab->pcaprecision >> 3) * 1920;
> +                }  //Correct here for 59,94
> +                else
> +                {
> +                    blsize = fld0_ausz + fld1_ausz;
> +                }
> +                p_frame = block_Alloc(blsize);
> +                memcpy(p_frame->p_start, p_sys->p_audiobuff, p_frame->i_size);
> +                p_frame->i_pts = p_frame->i_dts = p_sys->i_time;
> +
> +            } else
> +            {
> +                blt_Seek(p_demux, cur_frm, &p_ctk->dim0, &p_ctk->dim1);
> +                blsize = (p_ctk->dim0 + p_ctk->dim1) * p_sys->p_pctab->fldprec;
> +                if ( vlc_stream_Peek(p_demux->s, &p_sys->p_rd_buff, blsize)
> +                        < blsize )
> +                {
> +                    msg_Err(p_demux, "Error reading frame");
> +                }
> +
> +                cds_offs = BLT_get_jp2k_offset(p_sys->p_rd_buff, &luma0_sz,
> +                        p_sys->p_audiobuff, &fld0_ausz);
> +                if ( cds_offs < 0 )
> +                {
> +                    msg_Err(p_demux, "Error checking frame (%d)", cds_offs);
> +                    return 0;
> +                }
> +                nucompo = p_sys->p_rd_buff[cds_offs + 5];
> +                blsize = luma0_sz + 4;
> +
> +                if ( nucompo != 0x2f )
> +                {
> +                    chr_offs = BLT_get_jp2k_ch_offset(p_sys->p_rd_buff, &chr_sz,
> +                            cds_offs);
> +                    if ( chr_offs < 0 )
> +                    {
> +                        msg_Err(p_demux,
> +                                "Error checking chroma offset at frame (%d)",
> +                                chr_offs);
> +                        return 0;
> +                    }
> +                    blsize += (chr_sz + 4);
> +                }
> +
> +                bl_offs = cds_offs;
> +                fld0_sz = p_ctk->dim0 * p_sys->p_pctab->fldprec;
> +                // Get field 1 audio size
> +                BLT_get_jp2k_offset(&p_sys->p_rd_buff[fld0_sz], &luma1_sz,
> +                        &p_sys->p_audiobuff[fld0_ausz], &fld1_ausz);
> +
> +                if ( blsize & 0x3 )
> +                {
> +                    blsize |= 0x3;
> +                    blsize++;
> +                }
> +
> +                p_frame = block_Alloc(blsize);
> +
> +                memcpy(p_frame->p_start, &p_sys->p_rd_buff[bl_offs - 4],
> +                        (luma0_sz + 4)); // Copy Luma
> +                if ( nucompo != 0x2f )
> +                {
> +                    memcpy(&p_frame->p_start[(luma0_sz + 4)],
> +                            &p_sys->p_rd_buff[chr_offs - 4], (chr_sz + 4)); // Copy chroma
> +                }
> +
> +                p_frame->i_flags = BLOCK_FLAG_SINGLE_FIELD;
> +
> +                p_frame->i_pts = p_sys->i_time;
> +                p_frame->i_dts = p_sys->i_time + 1;
> +
> +            }
> +            p_frame->i_length = 40000;
> +            es_out_Send(p_demux->out, p_ctk->p_es, p_frame);
> +            if ( p_sys->b_paused == false )
> +                p_ctk->cframe++;
> +
> +        } else
> +        {
> +            p_ctk->cframe = 0;
> +            p_sys->i_time = 0;
> +            return 0; // EOF
> +        }
> +
> +    }
> +    p_sys->i_time += 40000; // Increments of 40ms (1 frame)
> +    return VLC_DEMUXER_SUCCESS;
> +
> +}
> --
> 2.1.4
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



More information about the vlc-devel mailing list