Changeset 2823

Show
Ignore:
Timestamp:
2007-05-31 04:52:53 (2 years ago)
Author:
shans
Message:

Correct gp handling for speex

Files:

Legend:

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

    r2819 r2823  
    317317/* 
    318318 * The first two speex packets are header and comment packets (granulepos = 0) 
    319  * The next packet is a data packet, and has a smaller-than-usual granulepos  
    320  * (see below). 
    321  * Each other packet has a granulepos increment mandated by values in the  
    322  * header packet.  See: 
    323  *         http://www.speex.org/manual2/node7.html#SECTION00073000000000000000 
    324  * for details on the header packet 
    325319 */ 
     320 
     321typedef struct { 
     322  int headers_encountered; 
     323  int packet_size; 
     324  int encountered_first_data_packet; 
     325} auto_calc_speex_info_t; 
     326 
    326327static ogg_int64_t  
    327328auto_calc_speex(ogg_int64_t now, oggz_stream_t *stream, ogg_packet *op) { 
     
    331332   * of speex frames per packet 
    332333   */ 
     334 
     335  auto_calc_speex_info_t *info  
     336          = (auto_calc_speex_info_t *)stream->calculate_data; 
     337 
    333338  if (stream->calculate_data == NULL) { 
    334     stream->calculate_data = malloc(sizeof(int)); 
    335     *(int *)stream->calculate_data =  
    336         (*(int *)(op->packet + 64)) * (*(int *)(op->packet + 56)); 
    337   } 
    338    
    339   if (now > -1) 
     339    stream->calculate_data = malloc(sizeof(auto_calc_speex_info_t)); 
     340    info = stream->calculate_data; 
     341    info->encountered_first_data_packet = 0; 
     342    info->packet_size =  
     343            (*(int *)(op->packet + 64)) * (*(int *)(op->packet + 56)); 
     344    info->headers_encountered = 1; 
     345    printf("first header, returning 0\n"); 
     346    return 0; 
     347  } 
     348   
     349  if (info->headers_encountered < 2) { 
     350    info->headers_encountered += 1; 
     351    printf("second header\n"); 
     352  } else { 
     353    info->encountered_first_data_packet = 1; 
     354    printf("encountered data packet\n"); 
     355  } 
     356 
     357  if (now > -1) { 
     358    printf("returning valid gp %lld\n", now); 
    340359    return now; 
    341  
    342   /* 
    343    * the first data packet has smaller-than-usual granulepos to account 
    344    * for the fact that several of the output samples from the beginning 
    345    * of this packet need to be thrown away.  We calculate the granulepos 
    346    * by taking the mod of the page's granulepos with respect to the increment 
    347    * between packets. 
    348    */ 
    349   if (stream->last_granulepos == 0) { 
    350     return stream->page_granulepos % *(int *)(stream->calculate_data); 
    351   } 
    352    
    353   return stream->last_granulepos + *(int *)(stream->calculate_data); 
     360  } 
     361 
     362  if (info->encountered_first_data_packet) { 
     363    if (stream->last_granulepos > 0) { 
     364      printf("returning calced gp %lld\n", 
     365          stream->last_granulepos + info->packet_size); 
     366      return stream->last_granulepos + info->packet_size; 
     367    } 
     368     
     369    printf("returning unknown gp\n"); 
     370    return -1; 
     371  } 
     372 
     373  printf("fallback return of 0\n"); 
     374  return 0; 
     375 
    354376} 
    355377