Repository: ossrs/srs
File: trunk/src/kernel/srs_kernel_mp4.cpp (C++)

Code before:
        
        if ((err = write_track(SrsFrameTypeVideo, stts, stss, ctts, stsc, stsz, co64)) != srs_success) {
            return srs_error_wrap(err, "write vide track");
        }
    }
    
    SrsMp4TrackBox* soun = moov->audio();
    if (soun) {
        SrsMp4SampleTableBox* stbl = soun->stbl();
        
        SrsMp4DecodingTime2SampleBox* stts = new SrsMp4DecodingTime2SampleBox();
        stbl->set_stts(stts);
        
        SrsMp4SyncSampleBox* stss = NULL;
        SrsMp4CompositionTime2SampleBox* ctts = NULL;
        
        SrsMp4Sample2ChunkBox* stsc = new SrsMp4Sample2ChunkBox();
        stbl->set_stsc(stsc);
        
        SrsMp4SampleSizeBox* stsz = new SrsMp4SampleSizeBox();
        stbl->set_stsz(stsz);
        
        SrsMp4ChunkLargeOffsetBox* co64 = new SrsMp4ChunkLargeOffsetBox();
        stbl->set_co64(co64);
        
        if ((err = write_track(SrsFrameTypeVideo, stts, stss, ctts, stsc, stsz, co64)) != srs_success) {
            return srs_error_wrap(err, "write soun track");
        }
    }
    
    return err;
}

srs_error_t SrsMp4SampleManager::write(SrsMp4MovieFragmentBox* moof, uint64_t& dts)
{
    srs_error_t err = srs_success;
    
    SrsMp4TrackFragmentBox* traf = moof->traf();
    SrsMp4TrackFragmentRunBox* trun = traf->trun();
    
    trun->flags = SrsMp4TrunFlagsDataOffset | SrsMp4TrunFlagsSampleDuration
        | SrsMp4TrunFlagsSampleSize | SrsMp4TrunFlagsSampleFlag | SrsMp4TrunFlagsSampleCtsOffset;

    SrsMp4Sample* previous = NULL;
    
    vector<SrsMp4Sample*>::iterator it;
    for (it = samples.begin(); it != samples.end(); ++it) {
        SrsMp4Sample* sample = *it;
        SrsMp4TrunEntry* entry = new SrsMp4TrunEntry(trun);
        
        if (!previous) {

Review comment (suggestion):
The type here is `SrsFrameTypeAudio`.

`TRANS_BY_GPT3`

Code after:
        if (samples.empty() || (*samples.rbegin())->offset < UINT32_MAX) {
            // stco support 32bit offset.
            co = new SrsMp4ChunkOffsetBox();
            stbl->set_stco(static_cast<SrsMp4ChunkOffsetBox*>(co));
        } else {
            // When sample offset bigger than UINT32_MAX, we use co64(support 64bit offset) box to avoid overflow.
            co = new SrsMp4ChunkLargeOffsetBox();
            stbl->set_co64(static_cast<SrsMp4ChunkLargeOffsetBox*>(co));
        }
        
        if ((err = write_track(SrsFrameTypeVideo, stts, stss, ctts, stsc, stsz, co)) != srs_success) {
            return srs_error_wrap(err, "write vide track");
        }
    }
    
    SrsMp4TrackBox* soun = moov->audio();
    if (soun) {
        SrsMp4SampleTableBox* stbl = soun->stbl();
        
        SrsMp4DecodingTime2SampleBox* stts = new SrsMp4DecodingTime2SampleBox();
        stbl->set_stts(stts);
        
        SrsMp4SyncSampleBox* stss = NULL;
        SrsMp4CompositionTime2SampleBox* ctts = NULL;
        
        SrsMp4Sample2ChunkBox* stsc = new SrsMp4Sample2ChunkBox();
        stbl->set_stsc(stsc);
        
        SrsMp4SampleSizeBox* stsz = new SrsMp4SampleSizeBox();
        stbl->set_stsz(stsz);
        
        SrsMp4FullBox* co = NULL;
        if (samples.empty() || (*samples.rbegin())->offset < UINT32_MAX) {
            co = new SrsMp4ChunkOffsetBox();
            stbl->set_stco(static_cast<SrsMp4ChunkOffsetBox*>(co));
        } else {
            co = new SrsMp4ChunkLargeOffsetBox();
            stbl->set_co64(static_cast<SrsMp4ChunkLargeOffsetBox*>(co));
        }
        
        if ((err = write_track(SrsFrameTypeAudio, stts, stss, ctts, stsc, stsz, co)) != srs_success) {
            return srs_error_wrap(err, "write soun track");
        }
    }
    
    return err;
}

srs_error_t SrsMp4SampleManager::write(SrsMp4MovieFragmentBox* moof, uint64_t& dts)
{
    srs_error_t err = srs_success;