Revision 46a7e3ec

View differences:

libavformat/gxfenc.c
58 58
    uint16_t umf_media_size;
59 59
    int sample_rate;
60 60
    int flags;
61
    GXFStreamContext timecode_track;
61 62
} GXFContext;
62 63

  
63 64
typedef struct GXF_Lines {
......
198 199

  
199 200
static int gxf_write_timecode_auxiliary(ByteIOContext *pb, GXFStreamContext *sc)
200 201
{
201
    /* FIXME implement that */
202 202
    put_byte(pb, 0); /* fields */
203 203
    put_byte(pb, 0);  /* seconds */
204 204
    put_byte(pb, 0); /* minutes */
......
208 208
    return 8;
209 209
}
210 210

  
211
static int gxf_write_track_description(ByteIOContext *pb, AVStream *st)
211
static int gxf_write_track_description(AVFormatContext *s, GXFStreamContext *sc, int index)
212 212
{
213
    GXFStreamContext *sc = st->priv_data;
213
    ByteIOContext *pb = s->pb;
214 214
    int64_t pos;
215
    int mpeg = sc->track_type == 4 || sc->track_type == 9;
215 216

  
216 217
    /* track description section */
217 218
    put_byte(pb, sc->media_type + 0x80);
218
    put_byte(pb, st->index + 0xC0);
219
    put_byte(pb, index + 0xC0);
219 220

  
220 221
    pos = url_ftell(pb);
221 222
    put_be16(pb, 0); /* size */
......
227 228
    put_be16(pb, sc->media_info);
228 229
    put_byte(pb, 0);
229 230

  
230
    if (st->codec->codec_id != CODEC_ID_MPEG2VIDEO) {
231
    if (!mpeg) {
231 232
        /* auxiliary information */
232 233
        put_byte(pb, TRACK_AUX);
233 234
        put_byte(pb, 8);
234
        if (st->codec->codec_id == CODEC_ID_NONE)
235
        if (sc->track_type == 3)
235 236
            gxf_write_timecode_auxiliary(pb, sc);
236 237
        else
237 238
            put_le64(pb, 0);
......
242 243
    put_byte(pb, 4);
243 244
    put_be32(pb, 0);
244 245

  
245
    if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO)
246
        gxf_write_mpeg_auxiliary(pb, st);
246
    if (mpeg)
247
        gxf_write_mpeg_auxiliary(pb, s->streams[index]);
247 248

  
248 249
    /* frame rate */
249 250
    put_byte(pb, TRACK_FPS);
......
313 314

  
314 315
static int gxf_write_track_description_section(AVFormatContext *s)
315 316
{
317
    GXFContext *gxf = s->priv_data;
316 318
    ByteIOContext *pb = s->pb;
317 319
    int64_t pos;
318 320
    int i;
......
320 322
    pos = url_ftell(pb);
321 323
    put_be16(pb, 0); /* size */
322 324
    for (i = 0; i < s->nb_streams; ++i)
323
        gxf_write_track_description(pb, s->streams[i]);
325
        gxf_write_track_description(s, s->streams[i]->priv_data, i);
326

  
327
    gxf_write_track_description(s, &gxf->timecode_track, s->nb_streams);
328

  
324 329
    return updateSize(pb, pos);
325 330
}
326 331

  
......
385 390
    put_le16(pb, 0); /* reserved */
386 391
    put_le16(pb, 0); /* reserved */
387 392
    put_le16(pb, gxf->audio_tracks);
388
    put_le16(pb, 0); /* timecode track count */
393
    put_le16(pb, 1); /* timecode track count */
389 394
    put_le16(pb, 0); /* reserved */
390 395
    put_le16(pb, gxf->mpeg_tracks);
391 396
    return 48;
......
398 403

  
399 404
    put_le32(pb, gxf->umf_length); /* total length of the umf data */
400 405
    put_le32(pb, 3); /* version */
401
    put_le32(pb, s->nb_streams);
406
    put_le32(pb, s->nb_streams+1);
402 407
    put_le32(pb, gxf->umf_track_offset); /* umf track section offset */
403 408
    put_le32(pb, gxf->umf_track_size);
404
    put_le32(pb, s->nb_streams);
409
    put_le32(pb, s->nb_streams+1);
405 410
    put_le32(pb, gxf->umf_media_offset);
406 411
    put_le32(pb, gxf->umf_media_size);
407 412
    put_le32(pb, gxf->umf_length); /* user data offset */
......
424 429
        put_le16(pb, sc->media_info);
425 430
        put_le16(pb, 1);
426 431
    }
432

  
433
    put_le16(pb, gxf->timecode_track.media_info);
434
    put_le16(pb, 1);
435

  
427 436
    return url_ftell(pb) - pos;
428 437
}
429 438

  
......
452 461

  
453 462
static int gxf_write_umf_media_timecode(ByteIOContext *pb, GXFStreamContext *sc)
454 463
{
455
    /* FIXME implement */
456
    put_be32(pb, 0); /* drop frame flag */
457
    put_be32(pb, 0); /* reserved */
458
    put_be32(pb, 0); /* reserved */
459
    put_be32(pb, 0); /* reserved */
460
    put_be32(pb, 0); /* reserved */
461
    put_be32(pb, 0); /* reserved */
462
    put_be32(pb, 0); /* reserved */
463
    put_be32(pb, 0); /* reserved */
464
    put_le32(pb, 1); /* non drop frame */
465
    put_le32(pb, 0); /* reserved */
466
    put_le32(pb, 0); /* reserved */
467
    put_le32(pb, 0); /* reserved */
468
    put_le32(pb, 0); /* reserved */
469
    put_le32(pb, 0); /* reserved */
470
    put_le32(pb, 0); /* reserved */
471
    put_le32(pb, 0); /* reserved */
464 472
    return 32;
465 473
}
466 474

  
......
505 513

  
506 514
    pos = url_ftell(pb);
507 515
    gxf->umf_media_offset = pos - gxf->umf_start_offset;
508
    for (i = 0; i < s->nb_streams; ++i) {
509
        AVStream *st = s->streams[i];
510
        GXFStreamContext *sc = st->priv_data;
516
    for (i = 0; i <= s->nb_streams; ++i) {
517
        GXFStreamContext *sc;
511 518
        char buffer[88];
512 519
        int64_t startpos, curpos;
513 520
        int path_size = strlen(ES_NAME_PATTERN);
514 521

  
522
        if (i == s->nb_streams)
523
            sc = &gxf->timecode_track;
524
        else
525
            sc = s->streams[i]->priv_data;
526

  
515 527
        memset(buffer, 0, 88);
516 528
        startpos = url_ftell(pb);
517 529
        put_le16(pb, 0); /* length */
......
530 542
        put_le32(pb, sc->sample_rate);
531 543
        put_le32(pb, sc->sample_size);
532 544
        put_le32(pb, 0); /* reserved */
545

  
546
        if (sc == &gxf->timecode_track)
547
            gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */
548
        else {
549
            AVStream *st = s->streams[i];
533 550
        switch (st->codec->codec_id) {
534 551
        case CODEC_ID_MPEG2VIDEO:
535 552
            gxf_write_umf_media_mpeg(pb, st);
......
540 557
        case CODEC_ID_DVVIDEO:
541 558
            gxf_write_umf_media_dv(pb, sc);
542 559
            break;
543
        default:
544
            gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */
545 560
        }
561
        }
562

  
546 563
        curpos = url_ftell(pb);
547 564
        url_fseek(pb, startpos, SEEK_SET);
548 565
        put_le16(pb, curpos - startpos);
......
574 591

  
575 592
static const int GXF_samples_per_frame[] = { 32768, 0 };
576 593

  
594
static void gxf_init_timecode_track(GXFStreamContext *sc, GXFStreamContext *vsc)
595
{
596
    if (!vsc)
597
        return;
598

  
599
    sc->media_type = vsc->sample_rate == 60 ? 7 : 8;
600
    sc->sample_rate = vsc->sample_rate;
601
    sc->media_info = ('T'<<8) | '0';
602
    sc->track_type = 3;
603
    sc->frame_rate_index = vsc->frame_rate_index;
604
    sc->lines_index = vsc->lines_index;
605
    sc->sample_size = 16;
606
    sc->fields = vsc->fields;
607
}
608

  
577 609
static int gxf_write_header(AVFormatContext *s)
578 610
{
579 611
    ByteIOContext *pb = s->pb;
580 612
    GXFContext *gxf = s->priv_data;
613
    GXFStreamContext *vsc = NULL;
581 614
    uint8_t tracks[255] = {0};
582 615
    int i, media_info = 0;
583 616

  
......
631 664
                sc->lines_index = -1;
632 665
            sc->sample_size = st->codec->bit_rate;
633 666
            sc->fields = 2; /* interlaced */
667

  
668
            vsc = sc;
669

  
634 670
            switch (st->codec->codec_id) {
635 671
            case CODEC_ID_MJPEG:
636 672
                sc->track_type = 1;
......
673 709
    if (ff_audio_interleave_init(s, GXF_samples_per_frame, (AVRational){ 1, 48000 }) < 0)
674 710
        return -1;
675 711

  
712
    gxf_init_timecode_track(&gxf->timecode_track, vsc);
713
    gxf->flags |= 0x200000; // time code track is non-drop frame
714

  
676 715
    gxf_write_map_packet(s);
677 716
    //gxf_write_flt_packet(s);
678 717
    gxf_write_umf_packet(s);
tests/seek.regression.ref
2907 2907
ret:-22 st:-1 ts:-0.645825 flags:1
2908 2908
----------------
2909 2909
tests/data/b-libav.gxf
2910
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:752 size:55076 flags:1
2910
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:940 size:55076 flags:1

2911 2911
ret: 0 st:-1 ts:-1.000000 flags:0
2912
ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:55860 size:65536 flags:1
2912
ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:56048 size:65536 flags:1

2913 2913
ret: 0 st:-1 ts:1.894167 flags:1
2914
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2914
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2915 2915
ret: 0 st: 0 ts:0.780000 flags:0
2916
ret: 0 st: 0 dts:0.800000 pts:-184467440737095520.000000 pos:661360 size:22568 flags:0
2916
ret: 0 st: 0 dts:0.800000 pts:-184467440737095520.000000 pos:661548 size:22568 flags:0

2917 2917
ret: 0 st: 0 ts:-0.320000 flags:1
2918
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:752 size:55076 flags:1
2918
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:940 size:55076 flags:1

2919 2919
ret: 0 st: 1 ts:2.580000 flags:0
2920
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2920
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2921 2921
ret: 0 st: 1 ts:1.480000 flags:1
2922
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2923
ret: 0 st:-1 ts:0.365002 flags:0
2924
ret: 0 st: 0 dts:0.360000 pts:-184467440737095520.000000 pos:303896 size:23176 flags:0
2925
ret: 0 st:-1 ts:-0.740831 flags:1
2926
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:752 size:55076 flags:1
2927
ret: 0 st: 0 ts:2.160000 flags:0
2928
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2929
ret: 0 st: 0 ts:1.040000 flags:1
2930
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2931
ret: 0 st: 1 ts:-0.060000 flags:0
2932
ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:55860 size:65536 flags:1
2933
ret: 0 st: 1 ts:2.840000 flags:1
2934
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2935
ret: 0 st:-1 ts:1.730004 flags:0
2936
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2937
ret: 0 st:-1 ts:0.624171 flags:1
2938
ret: 0 st: 0 dts:0.600000 pts:-184467440737095520.000000 pos:476172 size:23728 flags:0
2939
ret: 0 st: 0 ts:-0.480000 flags:0
2940
ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:55860 size:65536 flags:1
2941
ret: 0 st: 0 ts:2.420000 flags:1
2942
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2943
ret: 0 st: 1 ts:1.300000 flags:0
2944
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2945
ret: 0 st: 1 ts:0.200000 flags:1
2946
ret: 0 st: 0 dts:0.200000 pts:-184467440737095520.000000 pos:211056 size:20944 flags:0
2947
ret: 0 st:-1 ts:-0.904994 flags:0
2948
ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:55860 size:65536 flags:1
2949
ret: 0 st:-1 ts:1.989173 flags:1
2950
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2951
ret: 0 st: 0 ts:0.880000 flags:0
2952
ret: 0 st: 0 dts:0.880000 pts:-184467440737095520.000000 pos:706776 size:22456 flags:0
2953
ret: 0 st: 0 ts:-0.220000 flags:1
2954
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:752 size:55076 flags:1
2955
ret: 0 st: 1 ts:2.680000 flags:0
2956
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2957
ret: 0 st: 1 ts:1.560000 flags:1
2958
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751660 size:54320 flags:1
2959
ret: 0 st:-1 ts:0.460008 flags:0
2960
ret: 0 st: 0 dts:0.480000 pts:-184467440737095520.000000 pos:371520 size:53804 flags:1
2922
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2923
ret: 0 st: 2 ts:0.360000 flags:0

2924
ret: 0 st: 0 dts:0.360000 pts:-184467440737095520.000000 pos:304084 size:23176 flags:0

2925
ret: 0 st: 2 ts:-0.740000 flags:1

2926
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:940 size:55076 flags:1

2927
ret: 0 st:-1 ts:2.153336 flags:0

2928
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2929
ret: 0 st:-1 ts:1.047503 flags:1

2930
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2931
ret: 0 st: 0 ts:-0.060000 flags:0

2932
ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:56048 size:65536 flags:1

2933
ret: 0 st: 0 ts:2.840000 flags:1

2934
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2935
ret: 0 st: 1 ts:1.740000 flags:0

2936
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2937
ret: 0 st: 1 ts:0.620000 flags:1

2938
ret: 0 st: 0 dts:0.600000 pts:-184467440737095520.000000 pos:476360 size:23728 flags:0

2939
ret: 0 st: 2 ts:-0.480000 flags:0

2940
ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:56048 size:65536 flags:1

2941
ret: 0 st: 2 ts:2.420000 flags:1

2942
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2943
ret: 0 st:-1 ts:1.306672 flags:0

2944
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2945
ret: 0 st:-1 ts:0.200839 flags:1

2946
ret: 0 st: 0 dts:0.200000 pts:-184467440737095520.000000 pos:211244 size:20944 flags:0

2947
ret: 0 st: 0 ts:-0.900000 flags:0

2948
ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:56048 size:65536 flags:1

2949
ret: 0 st: 0 ts:1.980000 flags:1

2950
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2951
ret: 0 st: 1 ts:0.880000 flags:0

2952
ret: 0 st: 0 dts:0.880000 pts:-184467440737095520.000000 pos:706964 size:22456 flags:0

2953
ret: 0 st: 1 ts:-0.220000 flags:1

2954
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:940 size:55076 flags:1

2955
ret: 0 st: 2 ts:2.680000 flags:0

2956
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2957
ret: 0 st: 2 ts:1.560000 flags:1

2958
ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:751848 size:54320 flags:1

2959
ret: 0 st:-1 ts:0.460008 flags:0
2960
ret: 0 st: 0 dts:0.480000 pts:-184467440737095520.000000 pos:371708 size:53804 flags:1

2961 2961
ret: 0 st:-1 ts:-0.645825 flags:1
2962
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:752 size:55076 flags:1
2962
ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:940 size:55076 flags:1

2963 2963
----------------
2964 2964
tests/data/b-libav.mkv
2965 2965
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:505 size:28088 flags:1

Also available in: Unified diff