Exemplo n.º 1
0
WEBVTT_INTERN webvtt_status
webvtt_create_bytearray_nt( const webvtt_byte *text, webvtt_uint32 alloc, webvtt_bytearray *pba )
{
	webvtt_uint n = 0;
	webvtt_status status;
	webvtt_bytearray s;
	webvtt_byte b;
	if( !pba )
	{
		return WEBVTT_INVALID_PARAM;
	}
	s = (webvtt_bytearray)webvtt_alloc0( sizeof(struct webvtt_bytearray_t) + (alloc*sizeof(webvtt_byte)) );
	if( !s )
	{
		return WEBVTT_OUT_OF_MEMORY;
	}
	s->alloc = alloc;
	s->length = 0;
	s->text = s->array;
	s->text[0] = 0;

	while( (alloc--) && (b = text[n++]) )
	{
		if( WEBVTT_FAILED( status = webvtt_bytearray_putc( &s, b ) ) )
		{
			webvtt_delete_bytearray( &s );
			return status;
		}
	}
	*pba = s;
	return WEBVTT_SUCCESS;
}
Exemplo n.º 2
0
WEBVTT_INTERN webvtt_status
webvtt_create_internal_node( webvtt_node **node, webvtt_node *parent, webvtt_node_kind kind, 
  webvtt_stringlist *css_classes, webvtt_string *annotation )
{
  webvtt_status status;
  webvtt_internal_node_data *node_data;

  if( WEBVTT_FAILED( status = webvtt_create_node( node, kind, parent ) ) ) {
    return status;
  }

  if ( !( node_data = (webvtt_internal_node_data *)webvtt_alloc0( sizeof(*node_data) ) ) )
  {
    return WEBVTT_OUT_OF_MEMORY;
  }

  webvtt_copy_stringlist( &node_data->css_classes, css_classes );
  webvtt_copy_string( &node_data->annotation, annotation );
  node_data->children = NULL;
  node_data->length = 0;
  node_data->alloc = 0;

  (*node)->data.internal_data = node_data;

  return WEBVTT_SUCCESS;
}
Exemplo n.º 3
0
WEBVTT_INTERN webvtt_status
webvtt_attach_node( webvtt_node *parent, webvtt_node *to_attach )
{
  webvtt_node **next = 0;
  webvtt_internal_node_data *nd = 0;
  
  if( !parent || !to_attach || !parent->data.internal_data ) {
    return WEBVTT_INVALID_PARAM;
  }
  nd = parent->data.internal_data;
  
  if( nd->alloc == 0 ) {
    next = (webvtt_node **)webvtt_alloc0( sizeof( webvtt_node * ) * 8 );
    
    if( !next ) {
      return WEBVTT_OUT_OF_MEMORY;
    }
    
    nd->children = next;
    nd->alloc = 8;
  }
  
  if( nd->length + 1 >= ( nd->alloc / 3 ) * 2 ) {

    next = (webvtt_node **)webvtt_alloc0( sizeof( *next ) * nd->alloc * 2 );
    
    if( !next ) {
      return WEBVTT_OUT_OF_MEMORY;
    }

    nd->alloc *= 2;
    memcpy( next, nd->children, nd->length * sizeof( webvtt_node * ) );
    webvtt_free( nd->children );
    nd->children = next;
  }

  nd->children[ nd->length++ ] = to_attach;
  webvtt_ref_node( to_attach );

  return WEBVTT_SUCCESS;
}
Exemplo n.º 4
0
WEBVTT_INTERN webvtt_status
webvtt_create_token( webvtt_cuetext_token **token, webvtt_token_type token_type )
{
  webvtt_cuetext_token *temp_token = (webvtt_cuetext_token *)webvtt_alloc0( sizeof(*temp_token) );

  if( !temp_token ) {
    return WEBVTT_OUT_OF_MEMORY;
  }

  temp_token->token_type = token_type;
  *token = temp_token;

  return WEBVTT_SUCCESS;
}
Exemplo n.º 5
0
WEBVTT_INTERN webvtt_status
webvtt_create_node( webvtt_node **node, webvtt_node_kind kind, webvtt_node *parent )
{
  webvtt_node *temp_node;

  if( !node ) {
    return WEBVTT_INVALID_PARAM;
  }

  if( !( temp_node = (webvtt_node *)webvtt_alloc0(sizeof(*temp_node)) ) )
  {
    return WEBVTT_OUT_OF_MEMORY;
  }

  webvtt_ref_node( temp_node );
  temp_node->kind = kind;
  temp_node->parent = parent;
  *node = temp_node;

  return WEBVTT_SUCCESS;
}
Exemplo n.º 6
0
Arquivo: cue.c Projeto: caitp/webvtt
WEBVTT_EXPORT webvtt_status
webvtt_create_cue( webvtt_cue **pcue )
{
  webvtt_cue *cue;
  if( !pcue ) {
    return WEBVTT_INVALID_PARAM;
  }
  cue = (webvtt_cue *)webvtt_alloc0( sizeof(*cue) );
  if( !cue ) {
    return WEBVTT_OUT_OF_MEMORY;
  }
  /**
   * From http://dev.w3.org/html5/webvtt/#parsing (10/25/2012)
   *
   * Let cue's text track cue snap-to-lines flag be true.
   *
   * Let cue's text track cue line position be auto.
   *
   * Let cue's text track cue text position be 50.
   *
   * Let cue's text track cue size be 100.
   *
   * Let cue's text track cue alignment be middle alignment.
   */
  webvtt_ref( &cue->refs );
  webvtt_init_string( &cue->id );
  webvtt_init_string( &cue->body );
  cue->from = 0xFFFFFFFFFFFFFFFF;
  cue->until = 0xFFFFFFFFFFFFFFFF;
  cue->snap_to_lines = 1;
  cue->settings.position = 50;
  cue->settings.size = 100;
  cue->settings.align = WEBVTT_ALIGN_MIDDLE;
  cue->settings.line = WEBVTT_AUTO;
  cue->settings.vertical = WEBVTT_HORIZONTAL;

  *pcue = cue;
  return WEBVTT_SUCCESS;
}