/**
  @brief Charge un schema depuis un fichier RIFF
  @param mem Tampon mémoire
  @return Résultat de procèdure
*/
bool QEquipmentView::fromRIFF(PTR* mem){
    RIFF riff;

    //supprime le contenu de la scene
    this->reset();

    //lit l'entete
    if(!riff_read(mem,&riff))
        return false;

    //Vérifie l'en-tete
    if(!(riff.id[0] == 'R' && riff.id[1] == 'I' && riff.id[2] == 'F' && riff.id[3] == 'F'))
        return QRESULT_DESC(Result::Failed, Result::RiffInvalidHeader);
    if(mem->ptr+riff.size > mem->down)
        return QRESULT_DESC(Result::Failed, Result::RiffInvalidTagSize);

    //lit les chunk
    char tag[4];
    unsigned int tag_size;
    while(mem->ptr<mem->down && riff_read_tag(mem,tag,&tag_size)){
        qDebug() << "tag=" << tag[0] << tag[1] << tag[2] << tag[3];
        qDebug() << "tag_size=" << tag_size;
        if(mem->ptr+tag_size > mem->down)
            return QRESULT_DESC(Result::Failed, Result::RiffInvalidTagSize);
        if(memcmp("EQUIP",tag,sizeof(tag)) == 0 ){
            qDebug() << "EQUIP tag...";
            //Charge l'équipement
            RIFF_EQUIP equip;
            equip.id = btoi(mem);
            bread(mem,equip.name,sizeof(equip.name));
            bread(mem,equip.type,sizeof(equip.type));
            //Ajoute l'équipement à la scene
            Equipment qequip;
            qequip.equipmentId = equip.id;
            qequip.name = QString(equip.name);
            qequip.type = QString(equip.type);
            QPRINT(qequip.type);
            qequip.posX = qequip.posY = qequip.posZ = 0;
            this->addEquipment(qequip);
        }
        else{
            qDebug() << "IGNORE tag";
            mem->ptr += tag_size;
        }
        qDebug() << "offset=" << boffset(mem);
    }

    return QRESULT_OK();
}
Exemple #2
0
static inline void buffering_do(buf_str *ctx, size_t idx) {
	ctx->p.name = malloc((strlen(ctx->list[idx].n) + 1) * sizeof(char));
	if (!ctx->p.name) return;
	ctx->p.update[ctx->cur_id] = 0xFF;
	strcpy(ctx->p.name, strrchr(ctx->list[idx].n, DIR_SEP) + 1);
	char *c = strrchr(ctx->p.name, '.');
	if (c) *c = 0;
	ctx->from = ctx->list[idx].f;
	ctx->to = ctx->list[idx].t;
	FILE *f = fopen(ctx->list[idx].n, "rb");
	uint32_t fourcc[2];
	if (fread(fourcc, 4, 2, f) < 2) { fourcc[0] = 0; fourcc[1] = 0; }
	fseek(f, 0, SEEK_SET);
	if (fourcc[0] == 0x46464952) riff_read(f, ctx);
	else if (fourcc[0] == 0x43614C66) flac_read(f, ctx);
	else if (fourcc[0] == 0x01564C46) flv1_read(f, ctx);
	else if (fourcc[1] == 0x70797466) mp4_read(f, ctx);
}