Mercurial > libavformat.hg
comparison utils.c @ 3698:b7e347127897 libavformat
Maintain pointer to end of AVFormatContext.packet_buffer list
This changes add_to_pktbuf() to maintain a pointer to the last entry
in the list, avoiding a linear walk-through on each call. Before this
change, add_to_pktbuf() could take a significant amount of time (10%
of total decoding time), even with input files of several minutes.
After the change, the time spent in this function is barely measurable
with oprofile.
author | mru |
---|---|
date | Wed, 06 Aug 2008 22:17:38 +0000 |
parents | c6186d4ceda0 |
children | 5cf9918994ed |
comparison
equal
deleted
inserted
replaced
3697:c458ae91b0f9 | 3698:b7e347127897 |
---|---|
522 | 522 |
523 } | 523 } |
524 | 524 |
525 /*******************************************************/ | 525 /*******************************************************/ |
526 | 526 |
527 static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt){ | 527 static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt, |
528 AVPacketList *pktl; | 528 AVPacketList **plast_pktl){ |
529 AVPacketList **plast_pktl= packet_buffer; | 529 AVPacketList *pktl = av_mallocz(sizeof(AVPacketList)); |
530 | |
531 while(*plast_pktl) plast_pktl= &(*plast_pktl)->next; //FIXME maybe maintain pointer to the last? | |
532 | |
533 pktl = av_mallocz(sizeof(AVPacketList)); | |
534 if (!pktl) | 530 if (!pktl) |
535 return NULL; | 531 return NULL; |
532 | |
533 if (*packet_buffer) | |
534 (*plast_pktl)->next = pktl; | |
535 else | |
536 *packet_buffer = pktl; | |
536 | 537 |
537 /* add the packet in the buffered packet list */ | 538 /* add the packet in the buffered packet list */ |
538 *plast_pktl = pktl; | 539 *plast_pktl = pktl; |
539 pktl->pkt= *pkt; | 540 pktl->pkt= *pkt; |
540 return &pktl->pkt; | 541 return &pktl->pkt; |
576 } | 577 } |
577 | 578 |
578 if(!pktl && st->codec->codec_id!=CODEC_ID_PROBE) | 579 if(!pktl && st->codec->codec_id!=CODEC_ID_PROBE) |
579 return ret; | 580 return ret; |
580 | 581 |
581 add_to_pktbuf(&s->raw_packet_buffer, pkt); | 582 add_to_pktbuf(&s->raw_packet_buffer, pkt, &s->raw_packet_buffer_end); |
582 | 583 |
583 if(st->codec->codec_id == CODEC_ID_PROBE){ | 584 if(st->codec->codec_id == CODEC_ID_PROBE){ |
584 AVProbeData *pd = &st->probe_data; | 585 AVProbeData *pd = &st->probe_data; |
585 | 586 |
586 pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); | 587 pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); |
1041 continue; | 1042 continue; |
1042 }else | 1043 }else |
1043 return ret; | 1044 return ret; |
1044 } | 1045 } |
1045 | 1046 |
1046 if(av_dup_packet(add_to_pktbuf(&s->packet_buffer, pkt)) < 0) | 1047 if(av_dup_packet(add_to_pktbuf(&s->packet_buffer, pkt, |
1048 &s->packet_buffer_end)) < 0) | |
1047 return AVERROR(ENOMEM); | 1049 return AVERROR(ENOMEM); |
1048 }else{ | 1050 }else{ |
1049 assert(!s->packet_buffer); | 1051 assert(!s->packet_buffer); |
1050 return av_read_frame_internal(s, pkt); | 1052 return av_read_frame_internal(s, pkt); |
1051 } | 1053 } |
2019 } | 2021 } |
2020 } | 2022 } |
2021 break; | 2023 break; |
2022 } | 2024 } |
2023 | 2025 |
2024 pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1); | 2026 pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end); |
2025 if(av_dup_packet(pkt) < 0) { | 2027 if(av_dup_packet(pkt) < 0) { |
2026 av_free(duration_error); | 2028 av_free(duration_error); |
2027 return AVERROR(ENOMEM); | 2029 return AVERROR(ENOMEM); |
2028 } | 2030 } |
2029 | 2031 |