Changeset 2815

Show
Ignore:
Timestamp:
2007-05-31 01:49:07 (2 years ago)
Author:
shans
Message:

oggz_tell_granulepos now returns -1 for header packets, and when the gp is
unknowable (i.e. before the first packet with a gp in the stream)

Files:

Legend:

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

    r2733 r2815  
    368368  int keyframe_shift; 
    369369  unsigned char first_byte; 
    370    
    371   if (now > (ogg_int64_t)(-1)) 
    372     return now; 
    373370 
    374371  first_byte = op->packet[0]; 
    375372 
     373  /* header packet */ 
    376374  if (first_byte & 0x80) 
    377375  { 
    378     /* header packet */ 
    379     return (ogg_int64_t)0; 
    380   } 
    381    
     376    stream->last_granulepos = -1; 
     377    return (ogg_int64_t)-1; 
     378  } 
     379   
     380  /* known granulepos */ 
     381  if (now > (ogg_int64_t)(-1)) { 
     382    return now; 
     383  } 
     384 
     385  /* last granulepos unknown */ 
     386  if (stream->last_granulepos == -1) { 
     387    return (ogg_int64_t)-1; 
     388  } 
     389 
     390  
     391  /* inter-coded packet */ 
    382392  if (first_byte & 0x40) 
    383393  { 
    384     /* inter-coded packet */ 
    385394    return stream->last_granulepos + 1; 
    386   } 
    387  
    388   /* intra-coded packet */ 
    389   if (stream->last_granulepos == 0) 
    390   { 
    391     /* first intra-coded packet */ 
    392     return (ogg_int64_t)0; 
    393395  } 
    394396 
     
    629631  info = (auto_calc_vorbis_info_t *)stream->calculate_data; 
    630632 
     633 
    631634  if (now > -1) 
    632635  { 
    633     info->encountered_first_data_packet = 1; 
    634     //return now; 
     636    return now; 
    635637  } 
    636638  
     
    649651    size = info->mode_sizes[mode]; 
    650652   
     653    info->last_was_long = size; 
     654 
    651655    /* 
    652      * the first packet is always 0 
     656     * if we have a working granulepos, we use it. 
    653657     */ 
    654     if (!info->encountered_first_data_packet) { 
     658    if (now > -1) { 
    655659      info->encountered_first_data_packet = 1; 
    656       info->last_was_long = size; 
    657       return 0; 
     660      return now; 
    658661    } 
    659   
     662 
     663    if (info->encountered_first_data_packet == 0) { 
     664      info->encountered_first_data_packet = 1; 
     665      return -1; 
     666    } 
     667 
    660668    /* 
    661      * the second pos is an increment of half the current packetsize only 
     669     * otherwise, if we haven't yet had a working granulepos, we return 
     670     * -1 
    662671     */ 
    663     if (stream->last_granulepos == 0) { 
    664       info->last_was_long = size; 
    665       return (size ? info->long_size : info->short_size) / 2; 
     672    if (stream->last_granulepos == -1) { 
     673      return -1; 
    666674    } 
    667      
    668     /* 
    669      * if it's a short packet, then we can just use nsn_increment 
    670      * 
    671     if (size == 0) 
    672     { 
    673       return stream->last_granulepos + info->nsn_increment; 
    674     } 
    675      * actually, this is not how the decoder behaves.  It always decodes 
    676      * no further than the middle of the current packet, regardless of the 
    677      * number of additional samples that could be fully decoded. 
    678      */ 
    679675 
    680676    result = stream->last_granulepos +  
     
    688684    return result; 
    689685     
    690     /* 
    691      * I'll keep this around for now - it might come in handy if the  
    692      * specification and the vorbis code ever match 
    693      * 
    694     prev_bit = info->log2_num_modes + 1; 
    695     next_bit = prev_bit + 1; 
    696  
    697     prev_bit = (op->packet[0] >> prev_bit) & 0x1; 
    698  
    699     if (next_bit == 8) 
    700     { 
    701       next_bit = op->packet[1] & 0x1; 
    702     } 
    703     else 
    704     { 
    705       next_bit = (op->packet[0] >> next_bit) & 0x1; 
    706     } 
    707  
    708     return stream->last_granulepos +  
    709             info->nln_increments[(prev_bit << 1) | next_bit]; 
    710      */ 
    711   } 
    712    
    713    
    714   return now; 
     686  } 
    715687   
    716688} 
     
    898870     * page. 
    899871     */ 
     872    /* 
    900873    if (now != -1LL) { 
    901874      return op->granulepos; 
    902875    } 
     876    */ 
    903877    return r; 
    904878  }