Revision d06497f3 libavformat/nsvdec.c

View differences:

libavformat/nsvdec.c
81 81
 * - seek
82 82
 */
83 83

  
84
#ifdef DEBUG
85
#define PRINT(_v) printf _v
86
#else
87
#define PRINT(_v)
88
#endif
89

  
90 84
#if 0
91 85
struct NSVf_header {
92 86
    uint32_t chunk_tag; /* 'NSVf' */
......
216 210
//static int nsv_load_index(AVFormatContext *s);
217 211
static int nsv_read_chunk(AVFormatContext *s, int fill_header);
218 212

  
219
#ifdef DEBUG
220
static void print_tag(const char *str, unsigned int tag, int size)
221
{
222
    printf("%s: tag=%c%c%c%c\n",
223
           str, tag & 0xff,
224
           (tag >> 8) & 0xff,
225
           (tag >> 16) & 0xff,
226
           (tag >> 24) & 0xff);
227
}
228
#endif
213
#define print_tag(str, tag, size)       \
214
    av_dlog(NULL, "%s: tag=%c%c%c%c\n", \
215
            str, tag & 0xff,            \
216
            (tag >> 8) & 0xff,          \
217
            (tag >> 16) & 0xff,         \
218
            (tag >> 24) & 0xff);
229 219

  
230 220
/* try to find something we recognize, and set the state accordingly */
231 221
static int nsv_resync(AVFormatContext *s)
......
235 225
    uint32_t v = 0;
236 226
    int i;
237 227

  
238
    PRINT(("%s(), offset = %"PRId64", state = %d\n", __FUNCTION__, url_ftell(pb), nsv->state));
228
    av_dlog(s, "%s(), offset = %"PRId64", state = %d\n", __FUNCTION__, url_ftell(pb), nsv->state);
239 229

  
240 230
    //nsv->state = NSV_UNSYNC;
241 231

  
242 232
    for (i = 0; i < NSV_MAX_RESYNC; i++) {
243 233
        if (url_feof(pb)) {
244
            PRINT(("NSV EOF\n"));
234
            av_dlog(s, "NSV EOF\n");
245 235
            nsv->state = NSV_UNSYNC;
246 236
            return -1;
247 237
        }
248 238
        v <<= 8;
249 239
        v |= get_byte(pb);
250
/*
251 240
        if (i < 8) {
252
            PRINT(("NSV resync: [%d] = %02x\n", i, v & 0x0FF));
241
            av_dlog(s, "NSV resync: [%d] = %02x\n", i, v & 0x0FF);
253 242
        }
254
*/
255 243

  
256 244
        if ((v & 0x0000ffff) == 0xefbe) { /* BEEF */
257
            PRINT(("NSV resynced on BEEF after %d bytes\n", i+1));
245
            av_dlog(s, "NSV resynced on BEEF after %d bytes\n", i+1);
258 246
            nsv->state = NSV_FOUND_BEEF;
259 247
            return 0;
260 248
        }
261 249
        /* we read as big endian, thus the MK*BE* */
262 250
        if (v == TB_NSVF) { /* NSVf */
263
            PRINT(("NSV resynced on NSVf after %d bytes\n", i+1));
251
            av_dlog(s, "NSV resynced on NSVf after %d bytes\n", i+1);
264 252
            nsv->state = NSV_FOUND_NSVF;
265 253
            return 0;
266 254
        }
267 255
        if (v == MKBETAG('N', 'S', 'V', 's')) { /* NSVs */
268
            PRINT(("NSV resynced on NSVs after %d bytes\n", i+1));
256
            av_dlog(s, "NSV resynced on NSVs after %d bytes\n", i+1);
269 257
            nsv->state = NSV_FOUND_NSVS;
270 258
            return 0;
271 259
        }
272 260

  
273 261
    }
274
    PRINT(("NSV sync lost\n"));
262
    av_dlog(s, "NSV sync lost\n");
275 263
    return -1;
276 264
}
277 265

  
......
285 273
    int table_entries;
286 274
    int table_entries_used;
287 275

  
288
    PRINT(("%s()\n", __FUNCTION__));
276
    av_dlog(s, "%s()\n", __FUNCTION__);
289 277

  
290 278
    nsv->state = NSV_UNSYNC; /* in case we fail */
291 279

  
......
296 284

  
297 285
    //s->file_size = (uint32_t)get_le32(pb);
298 286
    file_size = (uint32_t)get_le32(pb);
299
    PRINT(("NSV NSVf chunk_size %u\n", size));
300
    PRINT(("NSV NSVf file_size %u\n", file_size));
287
    av_dlog(s, "NSV NSVf chunk_size %u\n", size);
288
    av_dlog(s, "NSV NSVf file_size %u\n", file_size);
301 289

  
302 290
    nsv->duration = duration = get_le32(pb); /* in ms */
303
    PRINT(("NSV NSVf duration %"PRId64" ms\n", duration));
291
    av_dlog(s, "NSV NSVf duration %"PRId64" ms\n", duration);
304 292
    // XXX: store it in AVStreams
305 293

  
306 294
    strings_size = get_le32(pb);
307 295
    table_entries = get_le32(pb);
308 296
    table_entries_used = get_le32(pb);
309
    PRINT(("NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
310
            strings_size, table_entries, table_entries_used));
297
    av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\n",
298
            strings_size, table_entries, table_entries_used);
311 299
    if (url_feof(pb))
312 300
        return -1;
313 301

  
314
    PRINT(("NSV got header; filepos %"PRId64"\n", url_ftell(pb)));
302
    av_dlog(s, "NSV got header; filepos %"PRId64"\n", url_ftell(pb));
315 303

  
316 304
    if (strings_size > 0) {
317 305
        char *strings; /* last byte will be '\0' to play safe with str*() */
......
338 326
            if (!p || p >= endp)
339 327
                break;
340 328
            *p++ = '\0';
341
            PRINT(("NSV NSVf INFO: %s='%s'\n", token, value));
329
            av_dlog(s, "NSV NSVf INFO: %s='%s'\n", token, value);
342 330
            av_metadata_set2(&s->metadata, token, value, 0);
343 331
        }
344 332
        av_free(strings);
......
346 334
    if (url_feof(pb))
347 335
        return -1;
348 336

  
349
    PRINT(("NSV got infos; filepos %"PRId64"\n", url_ftell(pb)));
337
    av_dlog(s, "NSV got infos; filepos %"PRId64"\n", url_ftell(pb));
350 338

  
351 339
    if (table_entries_used > 0) {
352 340
        int i;
......
367 355
        }
368 356
    }
369 357

  
370
    PRINT(("NSV got index; filepos %"PRId64"\n", url_ftell(pb)));
358
    av_dlog(s, "NSV got index; filepos %"PRId64"\n", url_ftell(pb));
371 359

  
372 360
#ifdef DEBUG_DUMP_INDEX
373 361
#define V(v) ((v<0x20 || v > 127)?'.':v)
374 362
    /* dump index */
375
    PRINT(("NSV %d INDEX ENTRIES:\n", table_entries));
376
    PRINT(("NSV [dataoffset][fileoffset]\n", table_entries));
363
    av_dlog(s, "NSV %d INDEX ENTRIES:\n", table_entries);
364
    av_dlog(s, "NSV [dataoffset][fileoffset]\n", table_entries);
377 365
    for (i = 0; i < table_entries; i++) {
378 366
        unsigned char b[8];
379 367
        url_fseek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET);
380 368
        get_buffer(pb, b, 8);
381
        PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"
369
        av_dlog(s, "NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"
382 370
           "%c%c%c%c%c%c%c%c\n",
383 371
           nsv->nsvs_file_offset[i], size + nsv->nsvs_file_offset[i],
384 372
           b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
385
           V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ));
373
           V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) );
386 374
    }
387 375
    //url_fseek(pb, size, SEEK_SET); /* go back to end of header */
388 376
#undef V
......
406 394
    int i;
407 395
    AVStream *st;
408 396
    NSVStream *nst;
409
    PRINT(("%s()\n", __FUNCTION__));
397
    av_dlog(s, "%s()\n", __FUNCTION__);
410 398

  
411 399
    vtag = get_le32(pb);
412 400
    atag = get_le32(pb);
......
414 402
    vheight = get_le16(pb);
415 403
    i = get_byte(pb);
416 404

  
417
    PRINT(("NSV NSVs framerate code %2x\n", i));
405
    av_dlog(s, "NSV NSVs framerate code %2x\n", i);
418 406
    if(i&0x80) { /* odd way of giving native framerates from docs */
419 407
        int t=(i & 0x7F)>>2;
420 408
        if(t<16) framerate = (AVRational){1, t+1};
......
434 422

  
435 423
    nsv->avsync = get_le16(pb);
436 424
    nsv->framerate = framerate;
437
#ifdef DEBUG
425

  
438 426
    print_tag("NSV NSVs vtag", vtag, 0);
439 427
    print_tag("NSV NSVs atag", atag, 0);
440
    PRINT(("NSV NSVs vsize %dx%d\n", vwidth, vheight));
441
#endif
428
    av_dlog(s, "NSV NSVs vsize %dx%d\n", vwidth, vheight);
442 429

  
443 430
    /* XXX change to ap != NULL ? */
444 431
    if (s->nb_streams == 0) { /* streams not yet published, let's do that */
......
502 489
#ifdef CHECK_SUBSEQUENT_NSVS
503 490
    } else {
504 491
        if (nsv->vtag != vtag || nsv->atag != atag || nsv->vwidth != vwidth || nsv->vheight != vwidth) {
505
            PRINT(("NSV NSVs header values differ from the first one!!!\n"));
492
            av_dlog(s, "NSV NSVs header values differ from the first one!!!\n");
506 493
            //return -1;
507 494
        }
508 495
#endif /* CHECK_SUBSEQUENT_NSVS */
......
521 508
    NSVContext *nsv = s->priv_data;
522 509
    int i, err;
523 510

  
524
    PRINT(("%s()\n", __FUNCTION__));
525
    PRINT(("filename '%s'\n", s->filename));
511
    av_dlog(s, "%s()\n", __FUNCTION__);
512
    av_dlog(s, "filename '%s'\n", s->filename);
526 513

  
527 514
    nsv->state = NSV_UNSYNC;
528 515
    nsv->ahead[0].data = nsv->ahead[1].data = NULL;
......
543 530
    /* now read the first chunk, so we can attempt to decode more info */
544 531
    err = nsv_read_chunk(s, 1);
545 532

  
546
    PRINT(("parsed header\n"));
533
    av_dlog(s, "parsed header\n");
547 534
    return 0;
548 535
}
549 536

  
......
561 548
    uint16_t auxsize;
562 549
    uint32_t auxtag;
563 550

  
564
    PRINT(("%s(%d)\n", __FUNCTION__, fill_header));
551
    av_dlog(s, "%s(%d)\n", __FUNCTION__, fill_header);
565 552

  
566 553
    if (nsv->ahead[0].data || nsv->ahead[1].data)
567 554
        return 0; //-1; /* hey! eat what you've in your plate first! */
......
586 573
    asize = get_le16(pb);
587 574
    vsize = (vsize << 4) | (auxcount >> 4);
588 575
    auxcount &= 0x0f;
589
    PRINT(("NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize));
576
    av_dlog(s, "NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize);
590 577
    /* skip aux stuff */
591 578
    for (i = 0; i < auxcount; i++) {
592 579
        auxsize = get_le16(pb);
593 580
        auxtag = get_le32(pb);
594
        PRINT(("NSV aux data: '%c%c%c%c', %d bytes\n",
581
        av_dlog(s, "NSV aux data: '%c%c%c%c', %d bytes\n",
595 582
              (auxtag & 0x0ff),
596 583
              ((auxtag >> 8) & 0x0ff),
597 584
              ((auxtag >> 16) & 0x0ff),
598 585
              ((auxtag >> 24) & 0x0ff),
599
              auxsize));
586
              auxsize);
600 587
        url_fskip(pb, auxsize);
601 588
        vsize -= auxsize + sizeof(uint16_t) + sizeof(uint32_t); /* that's becoming braindead */
602 589
    }
......
621 608
        pkt->stream_index = st[NSV_ST_VIDEO]->index;//NSV_ST_VIDEO;
622 609
        pkt->dts = nst->frame_offset;
623 610
        pkt->flags |= nsv->state == NSV_HAS_READ_NSVS ? AV_PKT_FLAG_KEY : 0; /* keyframe only likely on a sync frame */
624
/*
625
        for (i = 0; i < MIN(8, vsize); i++)
626
            PRINT(("NSV video: [%d] = %02x\n", i, pkt->data[i]));
627
*/
611
        for (i = 0; i < FFMIN(8, vsize); i++)
612
            av_dlog(s, "NSV video: [%d] = %02x\n", i, pkt->data[i]);
628 613
    }
629 614
    if(st[NSV_ST_VIDEO])
630 615
        ((NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset++;
......
642 627
            channels = get_byte(pb);
643 628
            samplerate = get_le16(pb);
644 629
            asize-=4;
645
            PRINT(("NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate));
630
            av_dlog(s, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
646 631
            if (fill_header) {
647 632
                st[NSV_ST_AUDIO]->need_parsing = AVSTREAM_PARSE_NONE; /* we know everything */
648 633
                if (bps != 16) {
649
                    PRINT(("NSV AUDIO bit/sample != 16 (%d)!!!\n", bps));
634
                    av_dlog(s, "NSV AUDIO bit/sample != 16 (%d)!!!\n", bps);
650 635
                }
651 636
                bps /= channels; // ???
652 637
                if (bps == 8)
......
655 640
                channels = 1;
656 641
                st[NSV_ST_AUDIO]->codec->channels = channels;
657 642
                st[NSV_ST_AUDIO]->codec->sample_rate = samplerate;
658
                PRINT(("NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate));
643
                av_dlog(s, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
659 644
            }
660 645
        }
661 646
        av_get_packet(pb, pkt, asize);
......
666 651
            pkt->dts = (((NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset-1);
667 652
            pkt->dts *= (int64_t)1000        * nsv->framerate.den;
668 653
            pkt->dts += (int64_t)nsv->avsync * nsv->framerate.num;
669
            PRINT(("NSV AUDIO: sync:%d, dts:%"PRId64, nsv->avsync, pkt->dts));
654
            av_dlog(s, "NSV AUDIO: sync:%d, dts:%"PRId64, nsv->avsync, pkt->dts);
670 655
        }
671 656
        nst->frame_offset++;
672 657
    }
......
681 666
    NSVContext *nsv = s->priv_data;
682 667
    int i, err = 0;
683 668

  
684
    PRINT(("%s()\n", __FUNCTION__));
669
    av_dlog(s, "%s()\n", __FUNCTION__);
685 670

  
686 671
    /* in case we don't already have something to eat ... */
687 672
    if (nsv->ahead[0].data == NULL && nsv->ahead[1].data == NULL)
......
692 677
    /* now pick one of the plates */
693 678
    for (i = 0; i < 2; i++) {
694 679
        if (nsv->ahead[i].data) {
695
                PRINT(("%s: using cached packet[%d]\n", __FUNCTION__, i));
680
            av_dlog(s, "%s: using cached packet[%d]\n", __FUNCTION__, i);
696 681
            /* avoid the cost of new_packet + memcpy(->data) */
697 682
            memcpy(pkt, &nsv->ahead[i], sizeof(AVPacket));
698 683
            nsv->ahead[i].data = NULL; /* we ate that one */
......
752 737
static int nsv_probe(AVProbeData *p)
753 738
{
754 739
    int i;
755
//    PRINT(("nsv_probe(), buf_size %d\n", p->buf_size));
740
    av_dlog(s, "nsv_probe(), buf_size %d\n", p->buf_size);
756 741
    /* check file header */
757 742
    /* streamed files might not have any header */
758 743
    if (p->buf[0] == 'N' && p->buf[1] == 'S' &&

Also available in: Unified diff