Пример #1
0
GF_Err MergeFragment(GF_MovieFragmentBox *moof, GF_ISOFile *mov)
{
	u32 i, j;
	u64 MaxDur;
	GF_TrackFragmentBox *traf;
	GF_TrackBox *trak;
	
	MaxDur = 0;

	//we shall have a MOOV and its MVEX BEFORE any MOOF
	if (!mov->moov || !mov->moov->mvex) return GF_ISOM_INVALID_FILE;
	//and all fragments must be continous
	if (mov->NextMoofNumber && (mov->NextMoofNumber >= moof->mfhd->sequence_number)) return GF_ISOM_INVALID_FILE;

	i=0;
	while ((traf = (GF_TrackFragmentBox*)gf_list_enum(moof->TrackList, &i))) {
		if (!traf->tfhd) {
			trak = NULL;
			traf->trex = NULL;
		} else {
			trak = gf_isom_get_track_from_id(mov->moov, traf->tfhd->trackID);
			j=0;
			while ((traf->trex = (GF_TrackExtendsBox*)gf_list_enum(mov->moov->mvex->TrackExList, &j))) {
				if (traf->trex->trackID == traf->tfhd->trackID) break;
				traf->trex = NULL;
			}
		}
		if (!trak || !traf->trex) return GF_ISOM_INVALID_FILE;

		MergeTrack(trak, traf, mov->current_top_box_start, !mov->first_moof_merged);

		//update trak duration
		SetTrackDuration(trak);
		if (trak->Header->duration > MaxDur) 
			MaxDur = trak->Header->duration;
	}

	mov->first_moof_merged = 1;
	mov->NextMoofNumber = moof->mfhd->sequence_number;
	//update movie duration
	if (mov->moov->mvhd->duration < MaxDur) mov->moov->mvhd->duration = MaxDur;
	return GF_OK;
}
Пример #2
0
GF_Err MergeFragment(GF_MovieFragmentBox *moof, GF_ISOFile *mov)
{
    GF_Err e;
    u32 i, j;
    u64 MaxDur;
    GF_TrackFragmentBox *traf;
    GF_TrackBox *trak;

    MaxDur = 0;

    //we shall have a MOOV and its MVEX BEFORE any MOOF
    if (!mov->moov || !mov->moov->mvex) {
        GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso file] Error: %s not received before merging fragment\n", mov->moov ? "mvex" : "moov" ));
        return GF_ISOM_INVALID_FILE;
    }
    //and all fragments must be continous - we do not throw an error as we may still want to be able to concatenate dependent representations in DASH and
    //we will likely a-have R1(moofSN 1, 3, 5, 7) plus R2(moofSN 2, 4, 6, 8)
    if (mov->NextMoofNumber && (mov->NextMoofNumber >= moof->mfhd->sequence_number)) {
        GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] Warning: wrong sequence number: got %d but last one was %d\n", moof->mfhd->sequence_number, mov->NextMoofNumber));
//		return GF_ISOM_INVALID_FILE;
    }

    i=0;
    while ((traf = (GF_TrackFragmentBox*)gf_list_enum(moof->TrackList, &i))) {
        if (!traf->tfhd) {
            trak = NULL;
            traf->trex = NULL;
        } else {
            trak = gf_isom_get_track_from_id(mov->moov, traf->tfhd->trackID);
            j=0;
            while ((traf->trex = (GF_TrackExtendsBox*)gf_list_enum(mov->moov->mvex->TrackExList, &j))) {
                if (traf->trex->trackID == traf->tfhd->trackID) break;
                traf->trex = NULL;
            }
        }

        if (!trak || !traf->trex) {
            GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso file] Error: Cannot find fragment track with ID %d\n", traf->tfhd->trackID));
            return GF_ISOM_INVALID_FILE;
        }

        e = MergeTrack(trak, traf, mov->current_top_box_start, !trak->first_traf_merged);
        if (e) return e;

        trak->present_in_scalable_segment = 1;

        //update trak duration
        SetTrackDuration(trak);
        if (trak->Header->duration > MaxDur)
            MaxDur = trak->Header->duration;

        trak->first_traf_merged = 1;
    }

    if (moof->other_boxes) {
        GF_Box *a;
        i = 0;
        while ((a = (GF_Box *)gf_list_enum(moof->other_boxes, &i))) {
            if (a->type == GF_ISOM_BOX_TYPE_PSSH) {
                GF_ProtectionSystemHeaderBox *pssh = (GF_ProtectionSystemHeaderBox *)pssh_New();
                memmove(pssh->SystemID, ((GF_ProtectionSystemHeaderBox *)a)->SystemID, 16);
                pssh->KID_count = ((GF_ProtectionSystemHeaderBox *)a)->KID_count;
                pssh->KIDs = (bin128 *)gf_malloc(pssh->KID_count*sizeof(bin128));
                memmove(pssh->KIDs, ((GF_ProtectionSystemHeaderBox *)a)->KIDs, pssh->KID_count*sizeof(bin128));
                pssh->private_data_size = ((GF_ProtectionSystemHeaderBox *)a)->private_data_size;
                pssh->private_data = (u8 *)gf_malloc(pssh->private_data_size*sizeof(char));
                memmove(pssh->private_data, ((GF_ProtectionSystemHeaderBox *)a)->private_data, pssh->private_data_size);

                if (!mov->moov->other_boxes) mov->moov->other_boxes = gf_list_new();
                gf_list_add(mov->moov->other_boxes, pssh);
            }
        }
    }

    mov->NextMoofNumber = moof->mfhd->sequence_number;
    //update movie duration
    if (mov->moov->mvhd->duration < MaxDur) mov->moov->mvhd->duration = MaxDur;
    return GF_OK;
}