?? mp4scene.c
字號:
/* * * Copyright (c) Sigma Designs, Inc. 2006. All rights reserved. * *//** @file mp4scene.c @brief limited BIFS parsing for MP4 streams @author Yifan Liu @ingroup dccsamplecode*/#include "../samples/sample_os.h"#define ALLOW_OS_CODE 1#include "../dcc/include/dcc.h"#include "../samples/common.h"#include "psfdemux_common.h"#include "mp4scene.h"#if 1#define CALLDBG ENABLE#else#define CALLDBG DISABLE#endifenum SFNodeType_type { UnknownSFNodeType = 0, SF2DNode, SF3DNode, SFAppearanceNode, SFAudioNode, SFBackground2DNode, SFBackground3DNode, SFColorNode, SFCoordinate2DNode, SFCoordinateNode, SFExpressionNode, SFFAPNode, SFFDPNode, SFFITNode, SFFaceDefMeshNode, SFFaceDefTablesNode, SFFaceDefTransformNode, SFFogNode, SFFontStyleNode, SFGeometryNode, SFLinePropertiesNode, SFMaterialNode, SFNavigationInfoNode, SFNormalNode, SFStreamingNode, SFTextureCoordinateNode, SFTextureNode, SFTextureTransformNode, SFTopNode, SFViewpointNode, SFVisemeNode, SFWorldNode};RMuint8 NodeTypeBitNumber_table[] ={ 0, /*UnknownNodeType*/ 5, /*SF2DNode*/ 6, /*SF3DNode*/ 1, /*SFAppearanceNode*/ 3, /*SFAudioNode*/ 1, /*SFBackground2DNode*/ 1, /*SFBackground3DNode*/ 1, /*SFColorNode*/ 1, /*SFCoordinate2DNode*/ 1, /*SFCoordinateNode*/ 1, /*SFExpressionNode*/ 1, /*SFFAPNode*/ 1, /*SFFDPNode*/ 1, /*SFFITNode*/ 1, /*SFFaceDefMeshNode*/ 1, /*SFFaceDefTablesNode*/ 1, /*SFFaceDefTransformNode*/ 1, /*SFFogNode*/ 1, /*SFFontStyleNode*/ 5, /*SFGeometryNode*/ 1, /*SFLinePropertiesNode*/ 2, /*SFMaterialNode*/ 1, /*SFNavigationInfoNode*/ 1, /*SFNormalNode*/ 3, /*SFStreamingNode*/ 1, /*SFTextureCoordinateNode*/ 3, /*SFTextureNode*/ 1, /*SFTextureTransformNode*/ 3, /*SFTopNode*/ 1, /*SFViewpointNode*/ 1, /*SFVisemeNode*/ 7, /*SFWorldNode*/};enum SFWorldNode_type { Reserved_Type = 0, Anchor, AnimationStream, Appearance, AudioBuffer, AudioClip, AudioDelay, AudioFX, AudioMix, AudioSource, AudioSwitch, Background, Background2D, Billboard, Bitmap, Box, Circle, Collision, Color, ColorInterpolator, CompositeTexture2D, CompositeTexture3D, Conditional, Cone, Coordinate, Coordinate2D, CoordinateInterpolator, CoordinateInterpolator2D, Curve2D, Cylinder, CylinderSensor, DirectionalLight, DiscSensor, ElevationGrid, Expression, Extrusion, Face, FaceDefMesh, FaceDefTables, FaceDefTransform, FAP, FDP, FIT, Fog, FontStyle, Form, Group, ImageTexture, IndexedFaceSet, IndexedFaceSet2D, IndexedLineSet, IndexedLineSet2D, Inline, LOD, Layer2D, Layer3D, Layout, LineProperties, ListeningPoint, Material, Material2D, MovieTexture, NavigationInfo, Normal, NormalInterpolator, OrderedGroup, OrientationInterpolator, PixelTexture, PlaneSensor, PlaneSensor2D, PointLight, PointSet, PointSet2D, PositionInterpolator, PositionInterpolator2D, ProximitySensor2D, ProximitySensor, QuantizationParameter, Rectangle, ScalarInterpolator, Script, Shape, Sound, Sound2D, Sphere, SphereSensor, SpotLight, Switch, TermCap, Text, TextureCoordinate, TextureTransform, TimeSensor, TouchSensor, Transform, Transform2D, Valuator, Viewpoint, VisibilitySensor, Viseme, WorldInfo,};char SFWorldNode_name[][64] = { "Reserved_Type = 0", "Anchor", "AnimationStream", "Appearance", "AudioBuffer", "AudioClip", "AudioDelay", "AudioFX", "AudioMix", "AudioSource", "AudioSwitch", "Background", "Background2D", "Billboard", "Bitmap", "Box", "Circle", "Collision", "Color", "ColorInterpolator", "CompositeTexture2D", "CompositeTexture3D", "Conditional", "Cone", "Coordinate", "Coordinate2D", "CoordinateInterpolator", "CoordinateInterpolator2D", "Curve2D", "Cylinder", "CylinderSensor", "DirectionalLight", "DiscSensor", "ElevationGrid", "Expression", "Extrusion", "Face", "FaceDefMesh", "FaceDefTables", "FaceDefTransform", "FAP", "FDP", "FIT", "Fog", "FontStyle", "Form", "Group", "ImageTexture", "IndexedFaceSet", "IndexedFaceSet2D", "IndexedLineSet", "IndexedLineSet2D", "Inline", "LOD", "Layer2D", "Layer3D", "Layout", "LineProperties", "ListeningPoint", "Material", "Material2D", "MovieTexture", "NavigationInfo", "Normal", "NormalInterpolator", "OrderedGroup", "OrientationInterpolator", "PixelTexture", "PlaneSensor", "PlaneSensor2D", "PointLight", "PointSet", "PointSet2D", "PositionInterpolator", "PositionInterpolator2D", "ProximitySensor2D", "ProximitySensor", "QuantizationParameter", "Rectangle", "ScalarInterpolator", "Script", "Shape", "Sound", "Sound2D", "Sphere", "SphereSensor", "SpotLight", "Switch", "TermCap", "Text", "TextureCoordinate", "TextureTransform", "TimeSensor", "TouchSensor", "Transform", "Transform2D", "Valuator", "Viewpoint", "VisibilitySensor", "Viseme", "WorldInfo"};enum FieldType_type { UnknownNodeType = 0, SF2DNodeType = SF2DNode, SF3DNodeType = SF3DNode, SFBoolType = SFWorldNode+1, SFColorType, SFFloatType, SFInt32Type, SFRotationType, SFStringType, SFTimeType, SFUrlType, SFVec2fType, SFVec3fType, SFImageType, SFCommandBufferType, SFScriptType, MF2DNodeType, MF3DNodeType, MFFloatType, MFBoolType, MFColorType, MFInt32Type, MFRotationType, MFStringType, MFTimeType, MFUrlType, MFVec2fType, MFVec3fType, MFImageType, MFCommandBufferType, MFScriptType,};struct BitStream_type { RMuint8 * stream; RMuint32 size; RMuint32 cur_byte; RMuint32 cur_bit;};struct FieldData { int fieldType; /* The type of the field (e.g., SFInt32Type). This is given by */ /* the .Field Type. column of the node coding table for the */ /* node to which it belongs. */ int quantType; /* The type of quantization used for the field. This is given by */ /* the .Q. column of the node coding table of the node to */ /* which it belongs. Types refer to Table 19 in 9.3.3.1.1. */ int animType; /* The animation method for the field. This is given by the .A. */ /* column of the node coding table. Types refer to animation */ /* type in Table 25 in 9.3.3.2.1. */ boolean useEfficientCoding; /* Set to true if the efficient coding is to be used. This value is */ /* FALSE by default. If there is a local */ /* QuantizationParameter node this value is the same */ /* as its useEfficientCoding field. */ /* The following data structures are used in the quantization */ /* process: */ //FieldCodingTable fct; /* This field is determined from the node coding table as */ /* described in 9.3.2.9. */ //AnimFieldQP aqp; /* This field is only used in BIFS-Anim. It references an */ /* AnimFieldQP stucture described in 9.3.2.10. */ //QuantizationParameter lqp; /* This field points to the local QuantizationParameter */ //boolean isQuantized; /* Set to true if the corresponding field is quantized, false */ /* otherwise. */ //int nbBits; /* The number of bits used for the quantization of the field. */ //float floatMin[]; /* The minimum bounds for the quantization of vector fields. */ /* These values are obtained from the FieldCodingTable */ /* (described in 9.3.2.9) and the current */ /* QuantizationParameter node (for BIFS-Scene) or the */ /* animField (for BIFS-Anim). */ //float floatMax[]; /* The maximum bounds for the quantization of vector fields. */ /* These values are obtained from the FieldCodingTable */ /* (described in 9.3.2.9) and the current */ /* QuantizationParameter node (for BIFS-Scene) or the */ /* animField (for BIFS-Anim). */ //int intMin[]; /* The minimum bounds for integers (SFInt32 and MFInt32). */ /* These values are obtained from the FieldCodingTable */ /* (described in 9.3.2.9) and the current */ /* QuantizationParameter node (for BIFS-Scene) or the */ /* animField (for BIFS-Anim). */};#define NODE_DATA_FIELD_NUMBER 16struct NodeData { int nodeType; /* The nodeType of the node. */ struct FieldData field[NODE_DATA_FIELD_NUMBER]; /* The fields of this node whose construction is described below. This array is indexed in all mode. */ boolean isAnimField[NODE_DATA_FIELD_NUMBER]; /* The mask of animated fields for the entire BIFS-Anim session, */ /* indexed in .dyn. mode. This array is only used in BIFS-Anim. */ /* The following data describes the indexing of the fields in .in., .out., */ /* .def., .dyn. and .all. modes */ int nDEFbits; /* The number of bits used for .def. field codes (the width of the codewords in the 2nd column of the node coding tables). */ int nINbits; /* The number of bits used for .in. field codes (the width of the codewords in the 3rd column of the node coding tables). */ int nOUTbits; /* The number of bits used for .out. field codes (the width of the codewords in the 4th column of the node coding tables). */ int numDEFfields; /* The number of .def. fields available for this node */ int numDYNfields; /* The number of .dyn. fields available for this node. */ int in2all[NODE_DATA_FIELD_NUMBER]; /* The ids of eventIns and exposedFields in .all. mode, indexed with the ids in .in. mode. */ int def2all[NODE_DATA_FIELD_NUMBER]; /* The ids of fields and exposedFields in .all. mode, indexed with the ids in .def. mode. */ int dyn2all[NODE_DATA_FIELD_NUMBER]; /* The ids of dynamic fields in .all. mode, indexed with the ids in .dyn. mode. */ boolean useQuant; /* When the NodeData is used for storing a prototype, the useQuant states whether the quantization is applied on the PROTO or not. */ /* boolean useAnim; When the NodeData is used for storing a prototype, the useQuant */ /* states whether the BIFS-Anim is applied on the PROTO or not. */ struct NodeData * protoData; /* In case that a node is contained in a PROTO, its NodeData structure points to the PROTO NodeData structure in the proto field.*/};#define ParseBIFS_GET_BITS( s, n, b ) \ do { \ RMstatus err; \ err = bitstream_get_bits( (s), (n), (RMuint32*)(b) ); \ if( err ) { \ bitstream_destory( (s) ); \ return RM_ERROR; \ } \ } while(0)//printf( "get %d bits from 0x%02x bit %d\n", (n), (s)->stream[(s)->cur_byte], (s)->cur_bit );//printf( "got 0x%02x \n", *(b)&0xff );/*RMuint8 buf[] ={ 0x47 ,0x40 ,0x20 ,0x12 ,0x00 ,0x04 ,0xb0 ,0x1a ,0x00 ,0x00 ,0xc1 ,0x00 ,0x00 ,0xd0 ,0xc0 ,0x10, 0x12 ,0x81 ,0x30 ,0x2a ,0x05 ,0x72 ,0x61 ,0x04 ,0x88 ,0x50 ,0x45 ,0x05 ,0x3f ,0x00 ,0x70 ,0xa1, 0xd4 ,0xbe ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff, 0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff};*/RMuint8 USENAMES = 0;static RMstatus SFNode( enum SFNodeType_type nodeDataType, struct BitStream_type * bs, struct BIFSInfo_type * out );static struct BitStream_type * bitstream_create( RMuint8 *src, RMuint32 size ){ struct BitStream_type * bs = (struct BitStream_type *)malloc( sizeof(struct BitStream_type) ); bs->stream = src; bs->size = size; bs->cur_byte = 0; bs->cur_bit = 7; /* assuming big endian, bit counter start from MSB */ return bs;}static void bitstream_destory( struct BitStream_type * bs ){ if( bs != NULL ){ free( bs ); bs = NULL; } return;}static RMstatus bitstream_get_one_byte( struct BitStream_type * bs, RMuint8 * byte ){ RMuint8 curbyte = bs->stream[bs->cur_byte]; RMuint8 curbit = bs->cur_bit; *byte = 0; /* init the output */ if( bs->cur_byte >= bs->size ) return RM_ERROR; *byte = curbyte << (7-curbit); bs->cur_byte ++; curbyte = bs->stream[bs->cur_byte]; *byte |= curbyte >> (curbit+1); return RM_OK;}static RMstatus bitstream_get_less_one_byte( struct BitStream_type * bs, RMuint32 num, RMuint8 * byte ){ RMuint8 curbyte = bs->stream[bs->cur_byte]; RMuint8 curbit = bs->cur_bit; *byte = 0; /* init the output */ if( num >= 8 ) /* get 0 - 7 bits only */ return RM_ERROR; if( bs->cur_byte >= bs->size ) return RM_ERROR; *byte = curbyte << (7-curbit); if( curbit >= num) { /* enough bits in curbyte */ *byte >>= (8-num); bs->cur_bit -= num; } else if( curbit + 1 == (RMuint8)num ){ /* curbyte is just used up */ *byte >>= (8-num); bs->cur_bit = 7; bs->cur_byte ++; } else { /* curbyte is not enough */ RMuint32 more = num - (curbit+1); RMuint32 next; bs->cur_byte++; if( bs->cur_byte >= bs->size ) { *byte = 0; return RM_ERROR; /* end of stream no next byte */ } next = bs->stream[bs->cur_byte]; next >>= curbit+1; *byte |= next; *byte >>= 8-num; bs->cur_bit = 7-more; } return RM_OK;}static RMstatus bitstream_get_bits( struct BitStream_type * bs, RMuint32 num, RMuint32 *bits ){ RMstatus err; *bits = 0; if( num >= 8 ) { RMuint32 bytes = num/8; RMuint32 shift = 8-(num%8); RMuint8 bottom = 0; RMuint32 i; for( i=0; i<bytes; i++ ) { RMuint8 b; err = bitstream_get_one_byte( bs, &b ); if( RMFAILED(err) ) return err; *bits |= ((RMuint32)b & 0x000000ff) << (8*bytes - i*8); } *bits >>= shift; err = bitstream_get_less_one_byte( bs, num%8, &bottom ); if( RMFAILED(err) ) return err; *bits |= (RMuint32)bottom & (0x000000ff>>shift) ; return RM_OK; } else { return bitstream_get_less_one_byte( bs, num, (RMuint8*)bits ); }}static RMstatus PROTOlist( struct BitStream_type * bs, struct BIFSInfo_type * out ){ RMuint8 bits; RMDBGLOG((CALLDBG, "PROTOlist\n" )); ParseBIFS_GET_BITS( bs, 1, &bits ); while( bits ){ // PROTOdeclaration(); fprintf( stderr, "PROTOdeclaration is not implemented, return now\n" ); return RM_ERROR; /* protodeclaration isnot implemneted */ ParseBIFS_GET_BITS( bs, 1, &bits ); } return RM_OK;}static RMuint32 GetNDTnbBits( enum SFNodeType_type node )
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -