comparison oggdec.c @ 5514:52c7b29eca31 libavformat

oggdec: Set dts when known
author conrad
date Mon, 11 Jan 2010 05:51:09 +0000
parents 60671fac35ad
children 37e2c3e635b3
comparison
equal deleted inserted replaced
5513:f4eceb1eb100 5514:52c7b29eca31
117 os->bufpos = 0; 117 os->bufpos = 0;
118 os->pstart = 0; 118 os->pstart = 0;
119 os->psize = 0; 119 os->psize = 0;
120 os->granule = -1; 120 os->granule = -1;
121 os->lastpts = AV_NOPTS_VALUE; 121 os->lastpts = AV_NOPTS_VALUE;
122 os->lastdts = AV_NOPTS_VALUE;
122 os->nsegs = 0; 123 os->nsegs = 0;
123 os->segp = 0; 124 os->segp = 0;
124 } 125 }
125 126
126 ogg->curidx = -1; 127 ogg->curidx = -1;
426 427
427 return 0; 428 return 0;
428 } 429 }
429 430
430 static uint64_t 431 static uint64_t
431 ogg_gptopts (AVFormatContext * s, int i, uint64_t gp) 432 ogg_gptopts (AVFormatContext * s, int i, uint64_t gp, int64_t *dts)
432 { 433 {
433 struct ogg *ogg = s->priv_data; 434 struct ogg *ogg = s->priv_data;
434 struct ogg_stream *os = ogg->streams + i; 435 struct ogg_stream *os = ogg->streams + i;
435 uint64_t pts = AV_NOPTS_VALUE; 436 uint64_t pts = AV_NOPTS_VALUE;
436 437
437 if(os->codec->gptopts){ 438 if(os->codec->gptopts){
438 pts = os->codec->gptopts(s, i, gp); 439 pts = os->codec->gptopts(s, i, gp, dts);
439 } else { 440 } else {
440 pts = gp; 441 pts = gp;
442 if (dts)
443 *dts = pts;
441 } 444 }
442 445
443 return pts; 446 return pts;
444 } 447 }
445 448
472 idx = i; 475 idx = i;
473 } 476 }
474 477
475 if (idx != -1){ 478 if (idx != -1){
476 s->streams[idx]->duration = 479 s->streams[idx]->duration =
477 ogg_gptopts (s, idx, ogg->streams[idx].granule); 480 ogg_gptopts (s, idx, ogg->streams[idx].granule, NULL);
478 } 481 }
479 482
480 ogg->size = size; 483 ogg->size = size;
481 ogg_restore (s, 0); 484 ogg_restore (s, 0);
482 485
532 535
533 if (os->lastpts != AV_NOPTS_VALUE) { 536 if (os->lastpts != AV_NOPTS_VALUE) {
534 pkt->pts = os->lastpts; 537 pkt->pts = os->lastpts;
535 os->lastpts = AV_NOPTS_VALUE; 538 os->lastpts = AV_NOPTS_VALUE;
536 } 539 }
540 if (os->lastdts != AV_NOPTS_VALUE) {
541 pkt->dts = os->lastdts;
542 os->lastdts = AV_NOPTS_VALUE;
543 }
537 if (os->page_end) { 544 if (os->page_end) {
538 if (os->granule != -1LL) { 545 if (os->granule != -1LL) {
539 if (os->codec && os->codec->granule_is_start) 546 if (os->codec && os->codec->granule_is_start)
540 pkt->pts = ogg_gptopts(s, idx, os->granule); 547 pkt->pts = ogg_gptopts(s, idx, os->granule, &pkt->dts);
541 else 548 else
542 os->lastpts = ogg_gptopts(s, idx, os->granule); 549 os->lastpts = ogg_gptopts(s, idx, os->granule, &os->lastdts);
543 os->granule = -1LL; 550 os->granule = -1LL;
544 } else 551 } else
545 av_log(s, AV_LOG_WARNING, "Packet is missing granule\n"); 552 av_log(s, AV_LOG_WARNING, "Packet is missing granule\n");
546 } 553 }
547 554
577 int i; 584 int i;
578 url_fseek(bc, *pos_arg, SEEK_SET); 585 url_fseek(bc, *pos_arg, SEEK_SET);
579 while (url_ftell(bc) < pos_limit && !ogg_read_page (s, &i)) { 586 while (url_ftell(bc) < pos_limit && !ogg_read_page (s, &i)) {
580 if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && 587 if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
581 ogg->streams[i].codec && i == stream_index) { 588 ogg->streams[i].codec && i == stream_index) {
582 pts = ogg_gptopts(s, i, ogg->streams[i].granule); 589 pts = ogg_gptopts(s, i, ogg->streams[i].granule, NULL);
583 // FIXME: this is the position of the packet after the one with above 590 // FIXME: this is the position of the packet after the one with above
584 // pts. 591 // pts.
585 *pos_arg = url_ftell(bc); 592 *pos_arg = url_ftell(bc);
586 break; 593 break;
587 } 594 }