static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)

{

    NSVContext *nsv = s->priv_data;

    ByteIOContext *pb = &s->pb;

    uint32_t tag, tag1, handler;

    int codec_type, stream_index, frame_period, bit_rate, scale, rate;

    unsigned int file_size, size, nb_frames;

    int64_t duration;

    int strings_size;

    int table_entries;

    int table_entries_used;

    int i, n;

    AVStream *st;

    NSVStream *ast;



    PRINT(("%s()\n", __FUNCTION__));



    nsv->state = NSV_UNSYNC; /* in case we fail */

    

    size = get_le32(pb);

    if (size < 28)


    nsv->NSVf_end = size;



    //s->file_size = (uint32_t)get_le32(pb);

    file_size = (uint32_t)get_le32(pb);

    PRINT(("NSV NSVf chunk_size %ld\n", size));

    PRINT(("NSV NSVf file_size %Ld\n", file_size));



    duration = get_le32(pb); /* in ms */

    nsv->duration = duration * AV_TIME_BASE / 1000; /* convert */

    PRINT(("NSV NSVf duration %Ld ms\n", duration));

    // XXX: store it in AVStreams



    strings_size = get_le32(pb);

    table_entries = get_le32(pb);

    table_entries_used = get_le32(pb);

    PRINT(("NSV NSVf info-strings size: %d, table entries: %d, bis %d\n", 

            strings_size, table_entries, table_entries_used));

    if (url_feof(pb))


    

    PRINT(("NSV got header; filepos %Ld\n", url_ftell(pb)));



    if (strings_size > 0) {

        char *strings; /* last byte will be '\0' to play safe with str*() */

        char *p, *endp;

        char *token, *value;

        char quote;



        p = strings = av_mallocz(strings_size + 1);

        endp = strings + strings_size;

        get_buffer(pb, strings, strings_size);

        while (p < endp) {

            while (*p == ' ')

                p++; /* strip out spaces */

            if (p >= endp-2)

                break;

            token = p;

            p = strchr(p, '=');

            if (!p || p >= endp-2)

                break;

            *p++ = '\0';

            quote = *p++;

            value = p;

            p = strchr(p, quote);

            if (!p || p >= endp)

                break;

            *p++ = '\0';

            PRINT(("NSV NSVf INFO: %s='%s'\n", token, value));

            if (!strcmp(token, "ASPECT")) {

                /* don't care */

            } else if (!strcmp(token, "CREATOR") || !strcmp(token, "Author")) {

                strncpy(s->author, value, 512-1);

            } else if (!strcmp(token, "Copyright")) {

                strncpy(s->copyright, value, 512-1);

            } else if (!strcmp(token, "TITLE") || !strcmp(token, "Title")) {

                strncpy(s->title, value, 512-1);

            }

        }

        av_free(strings);

    }

    if (url_feof(pb))


    

    PRINT(("NSV got infos; filepos %Ld\n", url_ftell(pb)));



    if (table_entries_used > 0) {

        nsv->index_entries = table_entries_used;



        nsv->nsvf_index_data = av_malloc(table_entries * sizeof(uint32_t));

        get_buffer(pb, nsv->nsvf_index_data, table_entries * sizeof(uint32_t));

    }



    PRINT(("NSV got index; filepos %Ld\n", url_ftell(pb)));

    

#ifdef DEBUG_DUMP_INDEX

#define V(v) ((v<0x20 || v > 127)?'.':v)

    /* dump index */

    PRINT(("NSV %d INDEX ENTRIES:\n", table_entries));

    PRINT(("NSV [dataoffset][fileoffset]\n", table_entries));

    for (i = 0; i < table_entries; i++) {

        unsigned char b[8];

        url_fseek(pb, size + nsv->nsvf_index_data[i], SEEK_SET);

        get_buffer(pb, b, 8);

        PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"

           "%c%c%c%c%c%c%c%c\n",

           nsv->nsvf_index_data[i], size + nsv->nsvf_index_data[i],

           b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], 

           V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ));

    }

    //url_fseek(pb, size, SEEK_SET); /* go back to end of header */

#undef V

#endif

    

    url_fseek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */

    

    if (url_feof(pb))


    nsv->state = NSV_HAS_READ_NSVF;

    return 0;

}
static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)

{

    NSVContext *nsv = s->priv_data;

    ByteIOContext *pb = &s->pb;

    uint32_t tag, tag1, handler;

    int codec_type, stream_index, frame_period, bit_rate, scale, rate;

    unsigned int file_size, size, nb_frames;

    int64_t duration;

    int strings_size;

    int table_entries;

    int table_entries_used;

    int i, n;

    AVStream *st;

    NSVStream *ast;



    PRINT(("%s()\n", __FUNCTION__));



    nsv->state = NSV_UNSYNC; 

    

    size = get_le32(pb);

    if (size < 28)


    nsv->NSVf_end = size;



    

    file_size = (uint32_t)get_le32(pb);

    PRINT(("NSV NSVf chunk_size %ld\n", size));

    PRINT(("NSV NSVf file_size %Ld\n", file_size));



    duration = get_le32(pb); 

    nsv->duration = duration * AV_TIME_BASE / 1000; 

    PRINT(("NSV NSVf duration %Ld ms\n", duration));

    



    strings_size = get_le32(pb);

    table_entries = get_le32(pb);

    table_entries_used = get_le32(pb);

    PRINT(("NSV NSVf info-strings size: %d, table entries: %d, bis %d\n", 

            strings_size, table_entries, table_entries_used));

    if (url_feof(pb))


    

    PRINT(("NSV got header; filepos %Ld\n", url_ftell(pb)));



    if (strings_size > 0) {

        char *strings; 

        char *p, *endp;

        char *token, *value;

        char quote;



        p = strings = av_mallocz(strings_size + 1);

        endp = strings + strings_size;

        get_buffer(pb, strings, strings_size);

        while (p < endp) {

            while (*p == ' ')

                p++; 

            if (p >= endp-2)

                break;

            token = p;

            p = strchr(p, '=');

            if (!p || p >= endp-2)

                break;

            *p++ = '\0';

            quote = *p++;

            value = p;

            p = strchr(p, quote);

            if (!p || p >= endp)

                break;

            *p++ = '\0';

            PRINT(("NSV NSVf INFO: %s='%s'\n", token, value));

            if (!strcmp(token, "ASPECT")) {

                

            } else if (!strcmp(token, "CREATOR") || !strcmp(token, "Author")) {

                strncpy(s->author, value, 512-1);

            } else if (!strcmp(token, "Copyright")) {

                strncpy(s->copyright, value, 512-1);

            } else if (!strcmp(token, "TITLE") || !strcmp(token, "Title")) {

                strncpy(s->title, value, 512-1);

            }

        }

        av_free(strings);

    }

    if (url_feof(pb))


    

    PRINT(("NSV got infos; filepos %Ld\n", url_ftell(pb)));



    if (table_entries_used > 0) {

        nsv->index_entries = table_entries_used;



        nsv->nsvf_index_data = av_malloc(table_entries * sizeof(uint32_t));

        get_buffer(pb, nsv->nsvf_index_data, table_entries * sizeof(uint32_t));

    }



    PRINT(("NSV got index; filepos %Ld\n", url_ftell(pb)));

    

#ifdef DEBUG_DUMP_INDEX

#define V(v) ((v<0x20 || v > 127)?'.':v)

    

    PRINT(("NSV %d INDEX ENTRIES:\n", table_entries));

    PRINT(("NSV [dataoffset][fileoffset]\n", table_entries));

    for (i = 0; i < table_entries; i++) {

        unsigned char b[8];

        url_fseek(pb, size + nsv->nsvf_index_data[i], SEEK_SET);

        get_buffer(pb, b, 8);

        PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"

           "%c%c%c%c%c%c%c%c\n",

           nsv->nsvf_index_data[i], size + nsv->nsvf_index_data[i],

           b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], 

           V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ));

    }

    

#undef V

#endif

    

    url_fseek(pb, nsv->base_offset + size, SEEK_SET); 

    

    if (url_feof(pb))


    nsv->state = NSV_HAS_READ_NSVF;

    return 0;

}
static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)

{

    NSVContext *nsv = VAR_0->priv_data;

    ByteIOContext *pb = &VAR_0->pb;

    uint32_t tag, tag1, handler;

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7;

    unsigned int VAR_8, VAR_9, VAR_10;

    int64_t duration;

    int VAR_11;

    int VAR_12;

    int VAR_13;

    int VAR_14, VAR_15;

    AVStream *st;

    NSVStream *ast;



    PRINT(("%VAR_0()\VAR_15", __FUNCTION__));



    nsv->state = NSV_UNSYNC; 

    

    VAR_9 = get_le32(pb);

    if (VAR_9 < 28)


    nsv->NSVf_end = VAR_9;



    

    VAR_8 = (uint32_t)get_le32(pb);

    PRINT(("NSV NSVf chunk_size %ld\VAR_15", VAR_9));

    PRINT(("NSV NSVf VAR_8 %Ld\VAR_15", VAR_8));



    duration = get_le32(pb); 

    nsv->duration = duration * AV_TIME_BASE / 1000; 

    PRINT(("NSV NSVf duration %Ld ms\VAR_15", duration));

    



    VAR_11 = get_le32(pb);

    VAR_12 = get_le32(pb);

    VAR_13 = get_le32(pb);

    PRINT(("NSV NSVf info-VAR_16 VAR_9: %d, table entries: %d, bis %d\VAR_15", 

            VAR_11, VAR_12, VAR_13));

    if (url_feof(pb))


    

    PRINT(("NSV got header; filepos %Ld\VAR_15", url_ftell(pb)));



    if (VAR_11 > 0) {

        char *VAR_16; 

        char *VAR_17, *VAR_18;

        char *VAR_19, *VAR_20;

        char VAR_21;



        VAR_17 = VAR_16 = av_mallocz(VAR_11 + 1);

        VAR_18 = VAR_16 + VAR_11;

        get_buffer(pb, VAR_16, VAR_11);

        while (VAR_17 < VAR_18) {

            while (*VAR_17 == ' ')

                VAR_17++; 

            if (VAR_17 >= VAR_18-2)

                break;

            VAR_19 = VAR_17;

            VAR_17 = strchr(VAR_17, '=');

            if (!VAR_17 || VAR_17 >= VAR_18-2)

                break;

            *VAR_17++ = '\0';

            VAR_21 = *VAR_17++;

            VAR_20 = VAR_17;

            VAR_17 = strchr(VAR_17, VAR_21);

            if (!VAR_17 || VAR_17 >= VAR_18)

                break;

            *VAR_17++ = '\0';

            PRINT(("NSV NSVf INFO: %VAR_0='%VAR_0'\VAR_15", VAR_19, VAR_20));

            if (!strcmp(VAR_19, "ASPECT")) {

                

            } else if (!strcmp(VAR_19, "CREATOR") || !strcmp(VAR_19, "Author")) {

                strncpy(VAR_0->author, VAR_20, 512-1);

            } else if (!strcmp(VAR_19, "Copyright")) {

                strncpy(VAR_0->copyright, VAR_20, 512-1);

            } else if (!strcmp(VAR_19, "TITLE") || !strcmp(VAR_19, "Title")) {

                strncpy(VAR_0->title, VAR_20, 512-1);

            }

        }

        av_free(VAR_16);

    }

    if (url_feof(pb))


    

    PRINT(("NSV got infos; filepos %Ld\VAR_15", url_ftell(pb)));



    if (VAR_13 > 0) {

        nsv->index_entries = VAR_13;



        nsv->nsvf_index_data = av_malloc(VAR_12 * sizeof(uint32_t));

        get_buffer(pb, nsv->nsvf_index_data, VAR_12 * sizeof(uint32_t));

    }



    PRINT(("NSV got index; filepos %Ld\VAR_15", url_ftell(pb)));

    

#ifdef DEBUG_DUMP_INDEX

#define V(v) ((v<0x20 || v > 127)?'.':v)

    

    PRINT(("NSV %d INDEX ENTRIES:\VAR_15", VAR_12));

    PRINT(("NSV [dataoffset][fileoffset]\VAR_15", VAR_12));

    for (VAR_14 = 0; VAR_14 < VAR_12; VAR_14++) {

        unsigned char b[8];

        url_fseek(pb, VAR_9 + nsv->nsvf_index_data[VAR_14], SEEK_SET);

        get_buffer(pb, b, 8);

        PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"

           "%c%c%c%c%c%c%c%c\VAR_15",

           nsv->nsvf_index_data[VAR_14], VAR_9 + nsv->nsvf_index_data[VAR_14],

           b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], 

           V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ));

    }

    

#undef V

#endif

    

    url_fseek(pb, nsv->base_offset + VAR_9, SEEK_SET); 

    

    if (url_feof(pb))


    nsv->state = NSV_HAS_READ_NSVF;

    return 0;

}
static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)
{ NSVContext *nsv = VAR_0->priv_data; ByteIOContext *pb = &VAR_0->pb; uint32_t tag, tag1, handler; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7; unsigned int VAR_8, VAR_9, VAR_10; int64_t duration; int VAR_11; int VAR_12; int VAR_13; int VAR_14, VAR_15; AVStream *st; NSVStream *ast; PRINT(("%VAR_0()\VAR_15", __FUNCTION__)); nsv->state = NSV_UNSYNC; VAR_9 = get_le32(pb); if (VAR_9 < 28)
nsv->NSVf_end = VAR_9; VAR_8 = (uint32_t)get_le32(pb); PRINT(("NSV NSVf chunk_size %ld\VAR_15", VAR_9)); PRINT(("NSV NSVf VAR_8 %Ld\VAR_15", VAR_8)); duration = get_le32(pb); nsv->duration = duration * AV_TIME_BASE / 1000; PRINT(("NSV NSVf duration %Ld ms\VAR_15", duration)); VAR_11 = get_le32(pb); VAR_12 = get_le32(pb); VAR_13 = get_le32(pb); PRINT(("NSV NSVf info-VAR_16 VAR_9: %d, table entries: %d, bis %d\VAR_15",
VAR_11, VAR_12, VAR_13)); if (url_feof(pb))
PRINT(("NSV got header; filepos %Ld\VAR_15", url_ftell(pb))); if (VAR_11 > 0) { char *VAR_16; char *VAR_17, *VAR_18; char *VAR_19, *VAR_20; char VAR_21; VAR_17 = VAR_16 = av_mallocz(VAR_11 + 1); VAR_18 = VAR_16 + VAR_11; get_buffer(pb, VAR_16, VAR_11); while (VAR_17 < VAR_18) { while (*VAR_17 == ' ')
VAR_17++; if (VAR_17 >= VAR_18-2)
break; VAR_19 = VAR_17; VAR_17 = strchr(VAR_17, '='); if (!VAR_17 || VAR_17 >= VAR_18-2)
break; *VAR_17++ = '\0'; VAR_21 = *VAR_17++; VAR_20 = VAR_17; VAR_17 = strchr(VAR_17, VAR_21); if (!VAR_17 || VAR_17 >= VAR_18)
break; *VAR_17++ = '\0'; PRINT(("NSV NSVf INFO: %VAR_0='%VAR_0'\VAR_15", VAR_19, VAR_20)); if (!strcmp(VAR_19, "ASPECT")) { } else if (!strcmp(VAR_19, "CREATOR") || !strcmp(VAR_19, "Author")) { strncpy(VAR_0->author, VAR_20, 512-1); } else if (!strcmp(VAR_19, "Copyright")) { strncpy(VAR_0->copyright, VAR_20, 512-1); } else if (!strcmp(VAR_19, "TITLE") || !strcmp(VAR_19, "Title")) { strncpy(VAR_0->title, VAR_20, 512-1); } } av_free(VAR_16); } if (url_feof(pb))
PRINT(("NSV got infos; filepos %Ld\VAR_15", url_ftell(pb))); if (VAR_13 > 0) { nsv->index_entries = VAR_13; nsv->nsvf_index_data = av_malloc(VAR_12 * sizeof(uint32_t)); get_buffer(pb, nsv->nsvf_index_data, VAR_12 * sizeof(uint32_t)); } PRINT(("NSV got index; filepos %Ld\VAR_15", url_ftell(pb))); #ifdef DEBUG_DUMP_INDEX
#define V(v) ((v<0x20 || v > 127)?'.':v)
PRINT(("NSV %d INDEX ENTRIES:\VAR_15", VAR_12)); PRINT(("NSV [dataoffset][fileoffset]\VAR_15", VAR_12)); for (VAR_14 = 0; VAR_14 < VAR_12; VAR_14++) { unsigned char b[8]; url_fseek(pb, VAR_9 + nsv->nsvf_index_data[VAR_14], SEEK_SET); get_buffer(pb, b, 8); PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"
"%c%c%c%c%c%c%c%c\VAR_15",
nsv->nsvf_index_data[VAR_14], VAR_9 + nsv->nsvf_index_data[VAR_14],
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) )); } #undef V
#endif
url_fseek(pb, nsv->base_offset + VAR_9, SEEK_SET); if (url_feof(pb))
nsv->state = NSV_HAS_READ_NSVF; return 0; }