Mercurial > libavformat.hg
comparison audiointerleave.c @ 4669:d6eb19c43e99 libavformat
Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
Yes this breaks ABI/API but ive already broken it and will bump avutil major
soon.
author | michael |
---|---|
date | Sun, 08 Mar 2009 14:16:55 +0000 |
parents | cb5bcf4bfe15 |
children | b1feed18d106 |
comparison
equal
deleted
inserted
replaced
4668:1f87eacc3c32 | 4669:d6eb19c43e99 |
---|---|
31 for (i = 0; i < s->nb_streams; i++) { | 31 for (i = 0; i < s->nb_streams; i++) { |
32 AVStream *st = s->streams[i]; | 32 AVStream *st = s->streams[i]; |
33 AudioInterleaveContext *aic = st->priv_data; | 33 AudioInterleaveContext *aic = st->priv_data; |
34 | 34 |
35 if (st->codec->codec_type == CODEC_TYPE_AUDIO) | 35 if (st->codec->codec_type == CODEC_TYPE_AUDIO) |
36 av_fifo_free(&aic->fifo); | 36 av_fifo_free(aic->fifo); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 int ff_audio_interleave_init(AVFormatContext *s, | 40 int ff_audio_interleave_init(AVFormatContext *s, |
41 const int *samples_per_frame, | 41 const int *samples_per_frame, |
60 aic->samples_per_frame = samples_per_frame; | 60 aic->samples_per_frame = samples_per_frame; |
61 aic->samples = aic->samples_per_frame; | 61 aic->samples = aic->samples_per_frame; |
62 aic->time_base = time_base; | 62 aic->time_base = time_base; |
63 | 63 |
64 aic->fifo_size = 100* *aic->samples; | 64 aic->fifo_size = 100* *aic->samples; |
65 av_fifo_init(&aic->fifo, 100 * *aic->samples); | 65 aic->fifo= av_fifo_alloc(100 * *aic->samples); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 return 0; | 69 return 0; |
70 } | 70 } |
73 int stream_index, int flush) | 73 int stream_index, int flush) |
74 { | 74 { |
75 AVStream *st = s->streams[stream_index]; | 75 AVStream *st = s->streams[stream_index]; |
76 AudioInterleaveContext *aic = st->priv_data; | 76 AudioInterleaveContext *aic = st->priv_data; |
77 | 77 |
78 int size = FFMIN(av_fifo_size(&aic->fifo), *aic->samples * aic->sample_size); | 78 int size = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size); |
79 if (!size || (!flush && size == av_fifo_size(&aic->fifo))) | 79 if (!size || (!flush && size == av_fifo_size(aic->fifo))) |
80 return 0; | 80 return 0; |
81 | 81 |
82 av_new_packet(pkt, size); | 82 av_new_packet(pkt, size); |
83 av_fifo_read(&aic->fifo, pkt->data, size); | 83 av_fifo_read(aic->fifo, pkt->data, size); |
84 | 84 |
85 pkt->dts = pkt->pts = aic->dts; | 85 pkt->dts = pkt->pts = aic->dts; |
86 pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base); | 86 pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base); |
87 pkt->stream_index = stream_index; | 87 pkt->stream_index = stream_index; |
88 aic->dts += pkt->duration; | 88 aic->dts += pkt->duration; |
102 | 102 |
103 if (pkt) { | 103 if (pkt) { |
104 AVStream *st = s->streams[pkt->stream_index]; | 104 AVStream *st = s->streams[pkt->stream_index]; |
105 AudioInterleaveContext *aic = st->priv_data; | 105 AudioInterleaveContext *aic = st->priv_data; |
106 if (st->codec->codec_type == CODEC_TYPE_AUDIO) { | 106 if (st->codec->codec_type == CODEC_TYPE_AUDIO) { |
107 unsigned new_size = av_fifo_size(&aic->fifo) + pkt->size; | 107 unsigned new_size = av_fifo_size(aic->fifo) + pkt->size; |
108 if (new_size > aic->fifo_size) { | 108 if (new_size > aic->fifo_size) { |
109 if (av_fifo_realloc2(&aic->fifo, new_size) < 0) | 109 if (av_fifo_realloc2(aic->fifo, new_size) < 0) |
110 return -1; | 110 return -1; |
111 aic->fifo_size = new_size; | 111 aic->fifo_size = new_size; |
112 } | 112 } |
113 av_fifo_generic_write(&aic->fifo, pkt->data, pkt->size, NULL); | 113 av_fifo_generic_write(aic->fifo, pkt->data, pkt->size, NULL); |
114 } else { | 114 } else { |
115 // rewrite pts and dts to be decoded time line position | 115 // rewrite pts and dts to be decoded time line position |
116 pkt->pts = pkt->dts = aic->dts; | 116 pkt->pts = pkt->dts = aic->dts; |
117 aic->dts += pkt->duration; | 117 aic->dts += pkt->duration; |
118 ff_interleave_add_packet(s, pkt, compare_ts); | 118 ff_interleave_add_packet(s, pkt, compare_ts); |