#ifndef _GF_BIFS_DEV_H_
#define _GF_BIFS_DEV_H_
#include <gpac/nodes_mpeg4.h>
#include <gpac/bitstream.h>
#include <gpac/bifs.h>
#include <gpac/thread.h>
#include <gpac/internal/scenegraph_dev.h>
#ifndef GPAC_DISABLE_BIFS
typedef struct {
GF_Node *node;
u32 node_id;
} BIFSElementaryMask;
typedef struct
{
u8 version;
u16 NodeIDBits;
u16 RouteIDBits;
Bool PixelMetrics;
u16 Width, Height;
Bool BAnimRAP;
GF_List *elementaryMasks;
Bool Use3DMeshCoding;
Bool UsePredictiveMFField;
u16 ProtoIDBits;
} BIFSConfig;
typedef struct
{
BIFSConfig config;
u16 ESID;
} BIFSStreamInfo;
typedef struct
{
GF_Node *node;
SFCommandBuffer *cb;
} CommandBufferItem;
struct __tag_bifs_dec
{
GF_Err LastError;
GF_List *streamInfo;
BIFSStreamInfo *info;
Bool UseName;
GF_SceneGraph *scenegraph;
GF_SceneGraph *current_graph;
GF_List *QPs;
M_QuantizationParameter *ActiveQP;
u32 NumCoord;
Bool coord_stored, storing_coord;
GF_Proto *pCurrentProto;
Bool dec_memory_mode;
Bool force_keep_qp;
GF_List *command_buffers;
Bool ignore_size;
Bool is_com_dec;
Double cts_offset;
char *extraction_path;
char *service_url;
};
GF_Node *gf_bifs_dec_node(GF_BifsDecoder * codec, GF_BitStream *bs, u32 NDT_Tag);
GF_Err gf_bifs_dec_sf_field(GF_BifsDecoder * codec, GF_BitStream *bs, GF_Node *node, GF_FieldInfo *field, Bool is_mem_com);
GF_Err gf_bifs_dec_field(GF_BifsDecoder * codec, GF_BitStream *bs, GF_Node *node, GF_FieldInfo *field, Bool is_mem_com);
GF_Err gf_bifs_dec_route(GF_BifsDecoder * codec, GF_BitStream *bs, Bool is_insert);
void gf_bifs_dec_name(GF_BitStream *bs, char *name);
BIFSStreamInfo *gf_bifs_dec_get_stream(GF_BifsDecoder * codec, u16 ESID);
GF_Err gf_bifs_dec_command(GF_BifsDecoder * codec, GF_BitStream *bs);
GF_Err gf_bifs_dec_proto_list(GF_BifsDecoder * codec, GF_BitStream *bs, GF_List *proto_list);
GF_Err gf_bifs_dec_node_list(GF_BifsDecoder * codec, GF_BitStream *bs, GF_Node *node, Bool is_proto);
GF_Err gf_bifs_dec_node_mask(GF_BifsDecoder * codec, GF_BitStream *bs, GF_Node *node, Bool is_proto);
void gf_bifs_check_field_change(GF_Node *node, GF_FieldInfo *field);
GF_Err gf_bifs_flush_command_list(GF_BifsDecoder *codec);
#ifndef GPAC_DISABLE_BIFS_ENC
struct __tag_bifs_enc
{
GF_Err LastError;
GF_List *streamInfo;
BIFSStreamInfo *info;
Bool UseName;
GF_SceneGraph *scene_graph;
GF_SceneGraph *current_proto_graph;
GF_List *QPs;
M_QuantizationParameter *ActiveQP;
u32 NumCoord;
Bool coord_stored, storing_coord;
GF_Proto *encoding_proto;
GF_List *encoded_nodes;
Bool is_encoding_command;
char *src_url;
};
GF_Err gf_bifs_enc_commands(GF_BifsEncoder *codec, GF_List *comList, GF_BitStream *bs);
GF_Err gf_bifs_enc_node(GF_BifsEncoder * codec, GF_Node *node, u32 NDT_Tag, GF_BitStream *bs, GF_Node *parent_node);
GF_Err gf_bifs_enc_sf_field(GF_BifsEncoder *codec, GF_BitStream *bs, GF_Node *node, GF_FieldInfo *field);
GF_Err gf_bifs_enc_field(GF_BifsEncoder * codec, GF_BitStream *bs, GF_Node *node, GF_FieldInfo *field);
GF_Err gf_bifs_enc_mf_field(GF_BifsEncoder *codec, GF_BitStream *bs, GF_Node *node, GF_FieldInfo *field);
GF_Err gf_bifs_enc_route(GF_BifsEncoder *codec, GF_Route *r, GF_BitStream *bs);
void gf_bifs_enc_name(GF_BifsEncoder *codec, GF_BitStream *bs, char *name);
GF_Node *gf_bifs_enc_find_node(GF_BifsEncoder *codec, u32 nodeID);
#define GF_BIFS_WRITE_INT(codec, bs, val, nbBits, str, com) {\
gf_bs_write_int(bs, val, nbBits); \
GF_LOG(GF_LOG_DEBUG, GF_LOG_CODING, ("[BIFS] %s\t\t%d\t\t%d\t\t%s\n", str, nbBits, val, com ? com : "") ); \
} \
GF_Route *gf_bifs_enc_is_field_ised(GF_BifsEncoder *codec, GF_Node *node, u32 fieldIndex);
#endif
Bool gf_bifs_get_aq_info(GF_Node *Node, u32 FieldIndex, u8 *QType, u8 *AType, Fixed *b_min, Fixed *b_max, u32 *QT13_bits);
GF_Err gf_bifs_get_field_index(GF_Node *Node, u32 inField, u8 IndexMode, u32 *allField);
u32 gf_bifs_get_child_table(GF_Node *Node);
u32 gf_bifs_get_node_type(u32 NDT_Tag, u32 NodeTag, u32 Version);
GF_Err gf_bifs_field_index_by_mode(GF_Node *node, u32 all_ind, u8 indexMode, u32 *outField);
u32 gf_bifs_get_ndt_bits(u32 NDT_Tag, u32 Version);
u32 gf_bifs_ndt_get_node_type(u32 NDT_Tag, u32 NodeType, u32 Version);
#endif
#endif