Changeset 3450

Show
Ignore:
Timestamp:
2008-02-12 19:52:23 (10 months ago)
Author:
conrad
Message:

add calculation of unmarked granulepos for celt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • liboggz/trunk/src/liboggz/oggz_auto.c

    r3449 r3450  
    432432} 
    433433 
     434/* 
     435 * The first two CELT packets are header and comment packets (granulepos = 0) 
     436 */ 
     437 
     438typedef struct { 
     439  int headers_encountered; 
     440  int packet_size; 
     441  int encountered_first_data_packet; 
     442} auto_calc_celt_info_t; 
     443 
     444static ogg_int64_t  
     445auto_calc_celt (ogg_int64_t now, oggz_stream_t *stream, ogg_packet *op) { 
     446   
     447  /* 
     448   * on the first (b_o_s) packet, set calculate_data to be the number 
     449   * of celt frames per packet 
     450   */ 
     451 
     452  auto_calc_celt_info_t *info  
     453          = (auto_calc_celt_info_t *)stream->calculate_data; 
     454 
     455  if (stream->calculate_data == NULL) { 
     456    stream->calculate_data = malloc(sizeof(auto_calc_celt_info_t)); 
     457    info = stream->calculate_data; 
     458    info->encountered_first_data_packet = 0; 
     459 
     460    /* In general, the number of frames per packet depends on the mode. 
     461     * Currently (20080213) both available modes, mono and stereo, have 256 
     462     * frames per packet. 
     463     */ 
     464    info->packet_size = 256; 
     465 
     466    info->headers_encountered = 1; 
     467    return 0; 
     468  } 
     469   
     470  if (info->headers_encountered < 2) { 
     471    info->headers_encountered += 1; 
     472  } else { 
     473    info->encountered_first_data_packet = 1; 
     474  } 
     475 
     476  if (now > -1) { 
     477    return now; 
     478  } 
     479 
     480  if (info->encountered_first_data_packet) { 
     481    if (stream->last_granulepos > 0) { 
     482      return stream->last_granulepos + info->packet_size; 
     483    } 
     484     
     485    return -1; 
     486  } 
     487 
     488  return 0; 
     489 
     490} 
    434491/* 
    435492 * Header packets are marked by a set MSB in the first byte.  Inter packets 
     
    9541011  {"\177FLAC", 4, "Flac", auto_flac, auto_calc_flac, NULL}, 
    9551012  {"AnxData", 7, "AnxData", auto_anxdata, NULL, NULL}, 
    956   {"CELT    ", 8, "CELT", auto_celt, NULL, NULL}, 
     1013  {"CELT    ", 8, "CELT", auto_celt, auto_calc_celt, NULL}, 
    9571014  {"", 0, "Unknown", NULL, NULL, NULL} 
    9581015};