| 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); |
|---|
| 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 | |
|---|