Revision 5a897cfa

View differences:

libavformat/mxfenc.c
49 49
    int sample_size;              ///< size of one sample all channels included
50 50
    const int *samples_per_frame; ///< must be 0 terminated
51 51
    const int *samples;           ///< current samples per frame, pointer to samples_per_frame
52
    AVRational time_base;         ///< time base of output audio packets
52 53
} AudioInterleaveContext;
53 54

  
54 55
typedef struct {
......
463 464

  
464 465
static void mxf_write_track(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type)
465 466
{
467
    MXFContext *mxf = s->priv_data;
466 468
    ByteIOContext *pb = s->pb;
467 469
    MXFStreamContext *sc = st->priv_data;
468 470

  
......
487 489
        put_buffer(pb, sc->track_essence_element_key + 12, 4);
488 490

  
489 491
    mxf_write_local_tag(pb, 8, 0x4B01);
490
    put_be32(pb, st->time_base.den);
491
    put_be32(pb, st->time_base.num);
492
    put_be32(pb, mxf->time_base.den);
493
    put_be32(pb, mxf->time_base.num);
492 494

  
493 495
    // write origin
494 496
    mxf_write_local_tag(pb, 8, 0x4B02);
......
1059 1061
    return !!sc->codec_ul;
1060 1062
}
1061 1063

  
1062
static int ff_audio_interleave_init(AVFormatContext *s, const int *samples_per_frame)
1064
static int ff_audio_interleave_init(AVFormatContext *s,
1065
                                    const int *samples_per_frame,
1066
                                    AVRational time_base)
1063 1067
{
1064 1068
    int i;
1065 1069

  
......
1079 1083
            }
1080 1084
            aic->samples_per_frame = samples_per_frame;
1081 1085
            aic->samples = aic->samples_per_frame;
1086
            aic->time_base = time_base;
1082 1087

  
1083 1088
            av_fifo_init(&aic->fifo, 100 * *aic->samples);
1084 1089
        }
......
1130 1135
                return -1;
1131 1136
            }
1132 1137
            mxf->edit_unit_start = st->index;
1138
            av_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den);
1133 1139
        } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
1134 1140
            if (st->codec->sample_rate != 48000) {
1135 1141
                av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n");
1136 1142
                return -1;
1137 1143
            }
1144
            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
1138 1145
        }
1139 1146
        sc->duration = -1;
1140 1147

  
......
1159 1166

  
1160 1167
    for (i = 0; i < s->nb_streams; i++) {
1161 1168
        MXFStreamContext *sc = s->streams[i]->priv_data;
1162
        av_set_pts_info(s->streams[i], 64, mxf->time_base.num, mxf->time_base.den);
1163 1169
        // update element count
1164 1170
        sc->track_essence_element_key[13] = present[sc->index];
1165 1171
        sc->order = AV_RB32(sc->track_essence_element_key+12);
......
1168 1174
    if (!samples_per_frame)
1169 1175
        samples_per_frame = PAL_samples_per_frame;
1170 1176

  
1171
    if (ff_audio_interleave_init(s, samples_per_frame) < 0)
1177
    if (ff_audio_interleave_init(s, samples_per_frame, mxf->time_base) < 0)
1172 1178
        return -1;
1173 1179

  
1174 1180
    return 0;
......
1284 1290
    av_fifo_read(&aic->fifo, pkt->data, size);
1285 1291

  
1286 1292
    pkt->dts = pkt->pts = aic->dts;
1287
    pkt->duration = av_rescale_q(*aic->samples,
1288
                                 (AVRational){ 1, st->codec->sample_rate },
1289
                                 st->time_base);
1293
    pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);
1290 1294
    pkt->stream_index = stream_index;
1291 1295
    aic->dts += pkt->duration;
1292 1296

  
......
1353 1357

  
1354 1358
static int mxf_compare_timestamps(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
1355 1359
{
1356
    AVStream *st  = s->streams[pkt ->stream_index];
1357
    AVStream *st2 = s->streams[next->stream_index];
1358
    MXFStreamContext *sc  = st ->priv_data;
1359
    MXFStreamContext *sc2 = st2->priv_data;
1360

  
1361
    int64_t left  = st2->time_base.num * (int64_t)st ->time_base.den;
1362
    int64_t right = st ->time_base.num * (int64_t)st2->time_base.den;
1360
    MXFStreamContext *sc  = s->streams[pkt ->stream_index]->priv_data;
1361
    MXFStreamContext *sc2 = s->streams[next->stream_index]->priv_data;
1363 1362

  
1364
    return next->dts * left > pkt->dts * right || // FIXME this can overflow
1365
        (next->dts * left == pkt->dts * right && sc->order < sc2->order);
1363
    return next->dts > pkt->dts ||
1364
        (next->dts == pkt->dts && sc->order < sc2->order);
1366 1365
}
1367 1366

  
1368 1367
static int mxf_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)

Also available in: Unified diff