This source file includes following definitions.
- Conditional_PreDestroy
- Conditional_BufferReplaced
- Conditional_execute
- Conditional_OnActivate
- Conditional_OnReverseActivate
- SetupConditional
- BIFS_SetupConditionalClone
#include <gpac/internal/bifs_dev.h>
#ifndef GPAC_DISABLE_BIFS
typedef struct
{
GF_BifsDecoder *codec;
BIFSStreamInfo *info;
} ConditionalStack;
void Conditional_PreDestroy(GF_Node *n, void *eff, Bool is_destroy)
{
if (is_destroy) {
ConditionalStack *priv = (ConditionalStack*)gf_node_get_private(n);
if (priv) gf_free(priv);
}
}
void Conditional_BufferReplaced(GF_BifsDecoder *codec, GF_Node *n)
{
ConditionalStack *priv = (ConditionalStack*)gf_node_get_private(n);
if (!priv || (gf_node_get_tag(n) != TAG_MPEG4_Conditional)) return;
priv->info = codec->info;
}
static void Conditional_execute(M_Conditional *node)
{
char *buffer;
u32 len;
GF_BitStream *bs;
GF_BifsDecoder *codec;
GF_Proto *prevproto;
GF_SceneGraph *prev_graph;
ConditionalStack *priv = (ConditionalStack*)gf_node_get_private((GF_Node*)node);
if (!priv) return;
prev_graph = priv->codec->current_graph;
priv->codec->current_graph = gf_node_get_graph((GF_Node*)node);
assert(priv->codec->current_graph);
priv->codec->info = priv->info;
prevproto = priv->codec->pCurrentProto;
priv->codec->pCurrentProto = NULL;
if (priv->codec->current_graph->pOwningProto) priv->codec->pCurrentProto = priv->codec->current_graph->pOwningProto->proto_interface;
node->isActive = 1;
gf_node_event_out((GF_Node *)node, 3);
if (!node->buffer.bufferSize) return;
buffer = (char*)node->buffer.buffer;
len = node->buffer.bufferSize;
node->buffer.buffer = NULL;
node->buffer.bufferSize = 0;
bs = gf_bs_new(buffer, len, GF_BITSTREAM_READ);
codec = priv->codec;
codec->cts_offset = gf_node_get_scene_time((GF_Node*)node);
gf_node_register((GF_Node*)node, NULL);
#ifdef GF_SELF_REPLACE_ENABLE
cur_graph->graph_has_been_reset = 0;
#endif
gf_bifs_dec_command(codec, bs);
gf_bs_del(bs);
#ifdef GF_SELF_REPLACE_ENABLE
if (cur_graph->graph_has_been_reset) {
return;
}
#endif
if (node->buffer.buffer) {
gf_free(buffer);
} else {
node->buffer.buffer = (u8*)buffer;
node->buffer.bufferSize = len;
}
gf_node_unregister((GF_Node*)node, NULL);
codec->cts_offset = 0;
codec->pCurrentProto = prevproto;
codec->current_graph = prev_graph;
}
void Conditional_OnActivate(GF_Node *n, GF_Route *route)
{
M_Conditional *node = (M_Conditional *)n;
if (! node->activate) return;
Conditional_execute(node);
}
void Conditional_OnReverseActivate(GF_Node *n, GF_Route *route)
{
M_Conditional *node = (M_Conditional *)n;
if (node->reverseActivate) return;
Conditional_execute(node);
}
void SetupConditional(GF_BifsDecoder *codec, GF_Node *node)
{
ConditionalStack *priv;
if (gf_node_get_tag(node) != TAG_MPEG4_Conditional) return;
priv = (ConditionalStack*)gf_malloc(sizeof(ConditionalStack));
if (!codec->info) codec->info = (BIFSStreamInfo*)gf_list_get(codec->streamInfo, 0);
if (!codec->info) return;
priv->info = codec->info;
priv->codec = codec;
gf_node_set_callback_function(node, Conditional_PreDestroy);
gf_node_set_private(node, priv);
((M_Conditional *)node)->on_activate = Conditional_OnActivate;
((M_Conditional *)node)->on_reverseActivate = Conditional_OnReverseActivate;
}
#endif
void BIFS_SetupConditionalClone(GF_Node *node, GF_Node *orig)
{
#ifndef GPAC_DISABLE_BIFS
M_Conditional *ptr;
ConditionalStack *priv_orig, *priv;
priv_orig = (ConditionalStack*)gf_node_get_private(orig);
if (!priv_orig) {
#else
{
#endif
#ifndef GPAC_DISABLE_VRML
u32 i;
GF_Command *ori_com;
M_Conditional *c_orig, *c_dest;
c_orig = (M_Conditional *)orig;
c_dest = (M_Conditional *)node;
gf_node_init(node);
i=0;
while ((ori_com = (GF_Command*)gf_list_enum(c_orig->buffer.commandList, &i))) {
GF_Command *dest_com = gf_sg_vrml_command_clone(ori_com, gf_node_get_graph(node), GF_TRUE);
if (dest_com) gf_list_add(c_dest->buffer.commandList, dest_com);
}
#endif
return;
}
#ifndef GPAC_DISABLE_BIFS
priv = (ConditionalStack*)gf_malloc(sizeof(ConditionalStack));
priv->codec = priv_orig->codec;
priv->info = priv_orig->info;
gf_node_set_callback_function(node, Conditional_PreDestroy);
gf_node_set_private(node, priv);
ptr = (M_Conditional *)node;
ptr->on_activate = Conditional_OnActivate;
ptr->on_reverseActivate = Conditional_OnReverseActivate;
#endif
}