📄 loader_svg_da.c
字号:
parser->command->node = svg_find_node(parser, atNode); if (!parser->command->node) return svg_report(parser, GF_BAD_PARAM, "Cannot find node node ref %s for command", atNode); if (atAtt) { if (!strcmp(atAtt, "children")) { field = gf_sg_command_field_new(parser->command); field->pos = index; field->fieldIndex = 0; field->fieldType = 0; } else { if (gf_svg_get_attribute_by_name(parser->command->node, atAtt, 0, 0, &info)==GF_OK) { field = gf_sg_command_field_new(parser->command); field->pos = index; field->fieldIndex = info.fieldIndex; field->fieldType = info.fieldType; } } } else if (index>=0) { field = gf_sg_command_field_new(parser->command); field->pos = index; } gf_node_register(parser->command->node, NULL); return GF_OK; case GF_SG_LSR_REPLACE: is_replace = 1; case GF_SG_LSR_ADD: case GF_SG_LSR_INSERT: for (i=0; i<nb_attributes; i++) { GF_XMLAttribute *att = (GF_XMLAttribute *)&attributes[i]; if (!strcmp(att->name, "ref")) atNode = att->value; else if (!strcmp(att->name, "operandElementId")) atOperandNode = att->value; else if (!strcmp(att->name, "operandAttributeName")) atOperandAtt = att->value; else if (!strcmp(att->name, "value")) atValue = att->value; else if (!strcmp(att->name, "attributeName")) atAtt = att->value; /*replace only*/ else if (!strcmp(att->name, "index")) index = atoi(att->value); } if (!atNode) return svg_report(parser, GF_BAD_PARAM, "Missing node ref for command"); parser->command->node = svg_find_node(parser, atNode); if (!parser->command->node) return svg_report(parser, GF_BAD_PARAM, "Cannot find node node ref %s for command", atNode); /*child or node replacement*/ if ( (is_replace || (parser->command->tag==GF_SG_LSR_INSERT)) && (!atAtt || !strcmp(atAtt, "children")) ) { field = gf_sg_command_field_new(parser->command); field->pos = index; if (atAtt) field->fieldIndex = TAG_LSR_ATT_children; gf_node_register(parser->command->node, NULL); return GF_OK; } if (!atAtt) return svg_report(parser, GF_BAD_PARAM, "Missing attribute name for command"); if (!strcmp(atAtt, "textContent")) { field = gf_sg_command_field_new(parser->command); field->pos = -1; field->fieldIndex = (u32) -1; field->fieldType = SVG_String_datatype; gf_node_register(parser->command->node, NULL); if (atValue) { field->field_ptr = gf_svg_create_attribute_value(field->fieldType); *(SVG_String *)field->field_ptr = strdup(atValue); } return GF_OK; } if (!strcmp(atAtt, "scale") || !strcmp(atAtt, "translation") || !strcmp(atAtt, "rotation")) { if (!strcmp(atAtt, "scale")) { info.fieldType = SVG_Transform_Scale_datatype; info.fieldIndex = TAG_LSR_ATT_scale; } else if (!strcmp(atAtt, "translation")) { info.fieldType = SVG_Transform_Translate_datatype; info.fieldIndex = TAG_LSR_ATT_translation; } else if (!strcmp(atAtt, "rotation")) { info.fieldType = SVG_Transform_Rotate_datatype; info.fieldIndex = TAG_LSR_ATT_rotation; } } else { info.fieldIndex = gf_svg_get_attribute_tag(parser->command->node->sgprivate->tag, atAtt); info.fieldType = gf_svg_get_attribute_type(info.fieldIndex); if (gf_lsr_anim_type_from_attribute(info.fieldIndex)<0) { return svg_report(parser, GF_BAD_PARAM, "Attribute %s of element %s is not updatable\n", atAtt, gf_node_get_class_name(parser->command->node)); } } opNode = NULL; if (atOperandNode) { opNode = gf_sg_find_node_by_name(parser->load->scene_graph, atOperandNode); if (!opNode) return svg_report(parser, GF_BAD_PARAM, "Cannot find operand element %s for command", atOperandNode); } if (!atValue && (!atOperandNode || !atOperandAtt) ) return svg_report(parser, GF_BAD_PARAM, "Missing attribute value for command"); field = gf_sg_command_field_new(parser->command); field->pos = index; field->fieldIndex = info.fieldIndex; field->fieldType = info.fieldType; if (atValue) { GF_FieldInfo nf; nf.fieldType = info.fieldType; field->field_ptr = nf.far_ptr = gf_svg_create_attribute_value(info.fieldType); if (field->field_ptr) gf_svg_parse_attribute(parser->command->node, &nf, atValue, (u8) info.fieldType); } else if (opNode) { parser->command->fromNodeID = gf_node_get_id(opNode); parser->command->fromFieldIndex = gf_svg_get_attribute_tag(opNode->sgprivate->tag, atOperandAtt); } gf_node_register(parser->command->node, NULL); return GF_OK; case GF_SG_LSR_ACTIVATE: case GF_SG_LSR_DEACTIVATE: for (i=0; i<nb_attributes; i++) { GF_XMLAttribute *att = (GF_XMLAttribute *) &attributes[i]; if (!strcmp(att->name, "ref")) atNode = att->value; } if (!atNode) return svg_report(parser, GF_BAD_PARAM, "Missing node ref for command"); /*should be a XML IDREF, not an XML IRI*/ if (atNode[0]=='#') atNode++; parser->command->node = svg_find_node(parser, atNode); if (!parser->command->node) return svg_report(parser, GF_BAD_PARAM, "Cannot find node node ref %s for command", atNode); gf_node_register(parser->command->node, NULL); /*switch to V2*/ svg_lsr_set_v2(parser); return GF_OK; default: return GF_OK; }}static u32 lsr_get_command_by_name(const char *name){ if (!strcmp(name, "NewScene")) return GF_SG_LSR_NEW_SCENE; else if (!strcmp(name, "RefreshScene")) return GF_SG_LSR_REFRESH_SCENE; else if (!strcmp(name, "Add")) return GF_SG_LSR_ADD; else if (!strcmp(name, "Clean")) return GF_SG_LSR_CLEAN; else if (!strcmp(name, "Replace")) return GF_SG_LSR_REPLACE; else if (!strcmp(name, "Delete")) return GF_SG_LSR_DELETE; else if (!strcmp(name, "Insert")) return GF_SG_LSR_INSERT; else if (!strcmp(name, "Restore")) return GF_SG_LSR_RESTORE; else if (!strcmp(name, "Save")) return GF_SG_LSR_SAVE; else if (!strcmp(name, "SendEvent")) return GF_SG_LSR_SEND_EVENT; else if (!strcmp(name, "Activate")) return GF_SG_LSR_ACTIVATE; else if (!strcmp(name, "Deactivate")) return GF_SG_LSR_DEACTIVATE; return GF_SG_UNDEFINED;}static GF_ESD *lsr_parse_header(GF_SVG_Parser *parser, const char *name, const char *name_space, const GF_XMLAttribute *attributes, u32 nb_attributes){ GF_ESD *esd; u32 i; if (!strcmp(name, "LASeRHeader")) { GF_LASERConfig *lsrc = (GF_LASERConfig *) gf_odf_desc_new(GF_ODF_LASER_CFG_TAG); for (i=0; i<nb_attributes;i++) { GF_XMLAttribute *att = (GF_XMLAttribute *) &attributes[i]; if (!strcmp(att->name, "profile")) lsrc->profile = !strcmp(att->value, "full") ? 1 : 0; else if (!strcmp(att->name, "level")) lsrc->level = atoi(att->value); else if (!strcmp(att->name, "resolution")) lsrc->resolution = atoi(att->value); else if (!strcmp(att->name, "timeResolution")) lsrc->time_resolution = atoi(att->value); else if (!strcmp(att->name, "coordBits")) lsrc->coord_bits = atoi(att->value); else if (!strcmp(att->name, "scaleBits_minus_coordBits")) lsrc->scale_bits_minus_coord_bits = atoi(att->value); else if (!strcmp(att->name, "colorComponentBits")) lsrc->colorComponentBits = atoi(att->value); else if (!strcmp(att->name, "newSceneIndicator")) lsrc->newSceneIndicator = (!strcmp(att->value, "yes") || !strcmp(att->value, "true")) ? 1 : 0; else if (!strcmp(att->name, "useFullRequestHost")) lsrc->fullRequestHost = (!strcmp(att->value, "yes") || !strcmp(att->value, "true")) ? 1 : 0; else if (!strcmp(att->name, "pathComponents")) lsrc->fullRequestHost = atoi(att->value); else if (!strcmp(att->name, "extensionIDBits")) lsrc->extensionIDBits = atoi(att->value); /*others are ignored in GPAC atm*/ } esd = gf_odf_desc_esd_new(2); gf_odf_desc_del((GF_Descriptor *)esd->decoderConfig->decoderSpecificInfo); esd->decoderConfig->decoderSpecificInfo = (GF_DefaultDescriptor *) lsrc; esd->decoderConfig->streamType = GF_STREAM_SCENE; esd->decoderConfig->objectTypeIndication = 0x09; esd->slConfig->timestampResolution = lsrc->time_resolution ? lsrc->time_resolution : 1000; return esd; } return NULL;}static void svg_node_start(void *sax_cbck, const char *name, const char *name_space, const GF_XMLAttribute *attributes, u32 nb_attributes){ GF_SVG_Parser *parser = (GF_SVG_Parser *)sax_cbck; SVG_NodeStack *stack, *parent; SVG_Element *elt; SVG_Element *cond = NULL; parent = (SVG_NodeStack *)gf_list_last(parser->node_stack); /*switch to conditional*/ if (parent && parent->node->sgprivate->tag==TAG_SVG_conditional) { cond = parent->node; parent = NULL; } /*saf setup*/ if ((!parent && (parser->load->type==GF_SM_LOAD_XSR)) || cond) { u32 com_type; /*nothing to do, the context is already created*/ if (!strcmp(name, "SAFSession")) return; /*nothing to do, wait for the laser (or other) header before creating stream)*/ if (!strcmp(name, "sceneHeader")) return; /*nothing to do, wait for the laser (or other) header before creating stream)*/ if (!strcmp(name, "LASeRHeader")) { GF_ESD *esd = lsr_parse_header(parser, name, name_space, attributes, nb_attributes); if (!esd) svg_report(parser, GF_BAD_PARAM, "Invalid LASER Header"); /*TODO find a better way of assigning an ID to the laser stream...*/ esd->ESID = 1; parser->laser_es = gf_sm_stream_new(parser->load->ctx, esd->ESID, esd->decoderConfig->streamType, esd->decoderConfig->objectTypeIndication); if (!parser->load->ctx->root_od) parser->load->ctx->root_od = (GF_ObjectDescriptor *) gf_odf_desc_new(GF_ODF_IOD_TAG); gf_list_add(parser->load->ctx->root_od->ESDescriptors, esd); parser->laser_es->timeScale = esd->slConfig->timestampResolution; return; } if (!strcmp(name, "sceneUnit") ) { u32 time, rap, i; time = rap = 0; if (!gf_list_count(parser->laser_es->AUs)) rap = 1; for (i=0; i<nb_attributes;i++) { GF_XMLAttribute *att = (GF_XMLAttribute *) &attributes[i]; if (!strcmp(att->name, "time")) time = atoi(att->value); else if (!strcmp(att->name, "rap")) rap = !strcmp(att->value, "yes") ? 1 : 0; } /*create new laser unit*/ parser->laser_au = gf_sm_stream_au_new(parser->laser_es, time, 0, rap); return; } if (!strcmp(name, "StreamHeader") || !strcmp(name, "RemoteStreamHeader") /*SAF & SAFML are just a pain ...*/ || !strcmp(name, "mediaHeader") || !strcmp(name, "imageHeader") ) { char *url = NULL; char *src = NULL; const char *ID = NULL; u32 time, OTI, ST, i, ts_res; GF_ODUpdate *odU; GF_ObjectDescriptor *od; Bool rap; SVG_SAFExternalStream*st; /*create a SAF stream*/ if (!parser->saf_es) { GF_ESD *esd = (GF_ESD*)gf_odf_desc_esd_new(2); esd->ESID = 0xFFFE; esd->decoderConfig->streamType = GF_STREAM_OD; esd->decoderConfig->objectTypeIndication = 1; parser->saf_es = gf_sm_stream_new(parser->load->ctx, esd->ESID, GF_STREAM_OD, 1); if (!parser->load->ctx->root_od) parser->load->ctx->root_od = (GF_ObjectDescriptor *) gf_odf_desc_new(GF_ODF_IOD_TAG); parser->saf_es->timeScale = 1000; gf_list_add(parser->load->ctx->root_od->ESDescriptors, esd); } time = 0; rap = 0; ts_res = 1000; OTI = ST = 0; for (i=0; i<nb_attributes;i++) { GF_XMLAttribute *att = (GF_XMLAttribute *) &attributes[i]; if (!strcmp(att->name, "time")) time = atoi(att->value); else if (!strcmp(att->name, "rap")) rap = !strcmp(att->value, "yes") ? 1 : 0; else if (!strcmp(att->name, "url")) url = strdup(att->value); else if (!strcmp(att->name, "streamID")) ID = att->value; else if (!strcmp(att->name, "objectTypeIndication")) OTI = atoi(att->value); else if (!strcmp(att->name, "streamType")) ST = atoi(att->value); else if (!strcmp(att->name, "timeStampResolution")) ts_res = atoi(att->value); else if (!strcmp(att->name, "source")) src = att->value; } if (!strcmp(name, "imageHeader")) ST = 4; /*create new SAF stream*/ st = svg_saf_get_next_available_stream(parser); st->stream_name = strdup(ID); /*create new SAF unit*/ parser->saf_au = gf_sm_stream_au_new(parser->saf_es, time, 0, 0); odU = (GF_ODUpdate *) gf_odf_com_new(GF_ODF_OD_UPDATE_TAG); gf_list_add(parser->saf_au->commands, odU); od = (GF_ObjectDescriptor *) gf_odf_desc_new(GF_ODF_OD_TAG); gf_list_add(odU->objectDescriptors, od); od->objectDescriptorID = st->id; if (url) { od->URLString = url; } else { char szName[1024]; GF_MuxInfo *mux; FILE *nhml; GF_ESD *esd = (GF_ESD*)gf_odf_desc_esd_new(2); gf_list_add(od->ESDescriptors, esd); esd->decoderConfig->objectTypeIndication = OTI; esd->decoderConfig->streamType = ST; esd->ESID = st->id; mux = (GF_MuxInfo *)gf_odf_desc_new(GF_ODF_MUXINFO_TAG); gf_list_add(esd->extensionDescriptors, mux); /*global source for stream, don't use nhml dumping*/ if (src) { mux->file_name = strdup(src); st->nhml_info = NULL; } else { if (parser->load->localPath) { strcpy(szName, parser->load->localPath); strcat(szName, ID); } else { strcpy(szName, ID); } strcat(szName, "_temp.nhml"); mux->file_name = strdup(szName); st->nhml_info = mux->file_name; nhml = fopen(st->nhml_info, "wt"); fprintf(nhml, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); fprintf(nhml, "<NHNTStream version=\"1.0\" timeScale=\"%d\" streamType=\"%d\" objectTypeIndication=\"%d\" inRootOD=\"no\" trackID=\"%d\">\n", ts_res, ST, OTI, st->id); fclose(nhml); mux->delete_file = 1; } } return; } if (!strcmp(name, "mediaUnit") || !strcmp(name, "imageUnit") ) { FILE *nhml; char *id = NULL; char *src = NULL; SVG_SAFExternalStream*st; u32 i, rap, time, offset, length; rap = time = offset = length = 0; for (i=0; i<nb_attributes;i++) { GF_XMLAttribute *att = (GF_XMLAttribute *) &attributes[i]; if (!strcmp(att->name, "time")) time = atoi(att->value); else if (!strcmp(att->name, "source")) src = att->value; else if (!strcmp(att->name, "ref")) id = att->value; else if (!strcmp(att->name, "rap")) rap = !strcmp(att->value, "yes") ? 1 : 0; else if (!strcmp(att->name, "startOffset")) offset = atoi(att->value); else if (!strcmp(att->name, "length")) length = atoi(att->value); } st = svg_saf_get_stream(parser, 0, id); if (!st || !st->nhml_info) { return; } nhml = fopen(st->nhml_info, "a+t"); fprintf(nhml, "<NHNTSample "); if (time) fprintf(nhml, "DTS=\"%d\" ", time); if (length) fprintf(nhml, "dataLength=\"%d\" ", length); if (offset) fprintf(nhml, "mediaOffset=\"%d\" ", offset); if (rap) fprintf(nhml, "isRAP=\"yes\" "); if (src) fprintf(nhml, "mediaFile=\"%s\" ", src); fprintf(nhml, "/>\n"); fclose(nhml); return; } if (!strcmp(name, "endOfStream") ) { FILE *nhml; char *id = NULL; u32 i; SVG_SAFExternalStream*st; for (i=0; i<nb_attributes;i++) { GF_XMLAttribute *att = (GF_XMLAttribute *) &attributes[i]; if (!strcmp(att->name, "ref")) id = att->value; } st = svg_saf_get_stream(parser, 0, id); if (!st || !st->nhml_info) { return; } nhml = fopen(st->nhml_info, "a+t"); fprintf(nhml, "</NHNTStream>\n"); fclose(nhml); return; } if (!strcmp(name, "endOfSAFSession") ) { return; } if (!parser->laser_au && !cond) { svg_report(parser, GF_BAD_PARAM, "LASeR Scene unit not defined for command %s", name); return; } /*command parsing*/ com_type = lsr_get_command_by_name(name); if (com_type != GF_SG_UNDEFINED) { SVG_NodeStack *top; GF_Err e; parser->command = gf_sg_command_new(parser->load->scene_graph, com_type); if (cond) { GF_DOMUpdates *up = cond->children ? (GF_DOMUpdates *)cond->children->node : NULL; if (!up) { up = gf_dom_add_updates_node((GF_Node*)cond); if (parser->load->flags & GF_SM_LOAD_FOR_PLAYBACK) { gf_node_set_callback_function((GF_Node*)up, xsr_exec_command_list); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -