Beispiel #1
0
/*emulate a default IOD for all other files (3GP, weird MP4, QT )*/
GF_Descriptor *isor_emulate_iod(ISOMReader *read)
{
	/*generate an IOD with our private dynamic OD stream*/
	GF_InitialObjectDescriptor *fake_iod = (GF_InitialObjectDescriptor *) gf_odf_desc_new(GF_ODF_IOD_TAG);
	isor_emulate_chapters(read->mov, fake_iod);
	read->no_service_desc = GF_TRUE;
	return (GF_Descriptor *)fake_iod;
}
Beispiel #2
0
/*fixme, this doesn't work properly with respect to @expect_type*/
static GF_Descriptor *ISOR_GetServiceDesc(GF_InputService *plug, u32 expect_type, const char *sub_url)
{
    u32 count, nb_st, i, trackID;
    GF_ESD *esd;
    ISOMReader *read;
    GF_InitialObjectDescriptor *iod;
    if (!plug || !plug->priv) return NULL;
    read = (ISOMReader *) plug->priv;
    if (!read->mov) return NULL;

    /*no matter what always read text as TTUs*/
    gf_isom_text_set_streaming_mode(read->mov, 1);

    trackID = 0;
    if (!sub_url) {
        trackID = read->base_track_id;
        read->base_track_id = 0;
    } else {
        char *ext = strrchr(sub_url, '#');
        if (!ext) {
            trackID = 0;
        } else {
            if (!strnicmp(ext, "#trackID=", 9)) trackID = atoi(ext+9);
            else if (!stricmp(ext, "#video")) trackID = get_track_id(read->mov, GF_ISOM_MEDIA_VISUAL, 0);
            else if (!strnicmp(ext, "#video", 6)) {
                trackID = atoi(ext+6);
                trackID = get_track_id(read->mov, GF_ISOM_MEDIA_VISUAL, trackID);
            }
            else if (!stricmp(ext, "#audio")) trackID = get_track_id(read->mov, GF_ISOM_MEDIA_AUDIO, 0);
            else if (!strnicmp(ext, "#audio", 6)) {
                trackID = atoi(ext+6);
                trackID = get_track_id(read->mov, GF_ISOM_MEDIA_AUDIO, trackID);
            }
            else trackID = atoi(ext+1);

            /*if trackID is 0, assume this is a fragment identifier*/
        }
    }

    if (!trackID && (expect_type!=GF_MEDIA_OBJECT_SCENE) && (expect_type!=GF_MEDIA_OBJECT_UNDEF)) {
        for (i=0; i<gf_isom_get_track_count(read->mov); i++) {
            u32 type = gf_isom_get_media_type(read->mov, i+1);
            if (
                ((type==GF_ISOM_MEDIA_VISUAL) && (expect_type==GF_MEDIA_OBJECT_VIDEO))
                || ((type==GF_ISOM_MEDIA_AUDIO) && (expect_type==GF_MEDIA_OBJECT_AUDIO)) ) {
                trackID = gf_isom_get_track_id(read->mov, i+1);
                break;
            }

        }
    }
    if (trackID && (expect_type!=GF_MEDIA_OBJECT_SCENE) ) {
        u32 track = gf_isom_get_track_by_id(read->mov, trackID);
        if (!track) return NULL;
        esd = gf_media_map_esd(read->mov, track);
        esd->OCRESID = 0;
        iod = (GF_InitialObjectDescriptor *) gf_isom_get_root_od(read->mov);
        if (!iod) {
            iod = (GF_InitialObjectDescriptor *) gf_odf_desc_new(GF_ODF_IOD_TAG);
            iod->OD_profileAndLevel = iod->audio_profileAndLevel = iod->graphics_profileAndLevel = iod->scene_profileAndLevel = iod->visual_profileAndLevel = 0xFE;
        } else {
            while (gf_list_count(iod->ESDescriptors)) {
                GF_ESD *old = (GF_ESD *)gf_list_get(iod->ESDescriptors, 0);
                gf_odf_desc_del((GF_Descriptor *) old);
                gf_list_rem(iod->ESDescriptors, 0);
            }
        }
        gf_list_add(iod->ESDescriptors, esd);
        isor_emulate_chapters(read->mov, iod);
        return (GF_Descriptor *) iod;
    }

    iod = NULL;
    if (check_mpeg4_systems(plug, read->mov)) {
        iod = (GF_InitialObjectDescriptor *) gf_isom_get_root_od(read->mov);
        if (!iod) {
#ifndef GPAC_DISABLE_LOG
            GF_Err e = gf_isom_last_error(read->mov);
            if (e) {
                GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[IsoMedia] Cannot fetch MPEG-4 IOD (error %s) - generating one\n", gf_error_to_string(e) ));
            } else {
                GF_LOG(GF_LOG_DEBUG, GF_LOG_NETWORK, ("[IsoMedia] No MPEG-4 IOD found in file - generating one\n"));
            }
#endif
        }
    }
    if (!iod) return isor_emulate_iod(read);

    count = gf_list_count(iod->ESDescriptors);
    if (!count) {
        gf_odf_desc_del((GF_Descriptor*) iod);
        return isor_emulate_iod(read);
    }
    if (count==1) {
        esd = (GF_ESD *)gf_list_get(iod->ESDescriptors, 0);
        switch (esd->decoderConfig->streamType) {
        case GF_STREAM_SCENE:
        case GF_STREAM_PRIVATE_SCENE:
            break;
        case GF_STREAM_VISUAL:
            if (expect_type!=GF_MEDIA_OBJECT_VIDEO) {
                gf_odf_desc_del((GF_Descriptor*) iod);
                return isor_emulate_iod(read);
            }
            break;
        case GF_STREAM_AUDIO:
            /*we need a fake scene graph*/
            if (expect_type!=GF_MEDIA_OBJECT_AUDIO) {
                gf_odf_desc_del((GF_Descriptor*) iod);
                return isor_emulate_iod(read);
            }
            break;
        default:
            gf_odf_desc_del((GF_Descriptor*) iod);
            return NULL;
        }
    }
    /*check IOD is not badly formed (eg mixing audio, video or text streams)*/
    nb_st = 0;
    for (i=0; i<count; i++) {
        esd = (GF_ESD *)gf_list_get(iod->ESDescriptors, i);
        switch (esd->decoderConfig->streamType) {
        case GF_STREAM_VISUAL:
            nb_st |= 1;
            break;
        case GF_STREAM_AUDIO:
            nb_st |= 2;
            break;
        case GF_STREAM_TEXT:
            nb_st |= 4;
            break;
        }
    }
    if ( (nb_st & 1) + (nb_st & 2) + (nb_st & 4) > 1) {
        gf_odf_desc_del((GF_Descriptor*) iod);
        return isor_emulate_iod(read);
    }

    isor_emulate_chapters(read->mov, iod);
    return (GF_Descriptor *) iod;
}