annotate audiointerleave.c @ 5626:b3d4ef7e53ad libavformat

Indentation cleanup
author pross
date Wed, 03 Feb 2010 09:58:14 +0000
parents fc0a165de804
children 536e5527c1e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
1 /*
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
2 * Audio Interleaving functions
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
3 *
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
4 * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
5 *
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
6 * This file is part of FFmpeg.
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
7 *
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
12 *
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
16 * Lesser General Public License for more details.
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
17 *
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
21 */
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
22
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
23 #include "libavutil/fifo.h"
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
24 #include "avformat.h"
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
25 #include "audiointerleave.h"
4418
d5119d75439d Move declaration of ff_interleave_add_packet to internal.h.
bcoudurier
parents: 4417
diff changeset
26 #include "internal.h"
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
27
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
28 void ff_audio_interleave_close(AVFormatContext *s)
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
29 {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
30 int i;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
31 for (i = 0; i < s->nb_streams; i++) {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
32 AVStream *st = s->streams[i];
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
33 AudioInterleaveContext *aic = st->priv_data;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
34
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
35 if (st->codec->codec_type == CODEC_TYPE_AUDIO)
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4534
diff changeset
36 av_fifo_free(aic->fifo);
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
37 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
38 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
39
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
40 int ff_audio_interleave_init(AVFormatContext *s,
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
41 const int *samples_per_frame,
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
42 AVRational time_base)
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
43 {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
44 int i;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
45
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
46 if (!samples_per_frame)
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
47 return -1;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
48
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
49 for (i = 0; i < s->nb_streams; i++) {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
50 AVStream *st = s->streams[i];
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
51 AudioInterleaveContext *aic = st->priv_data;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
52
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
53 if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
54 aic->sample_size = (st->codec->channels *
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
55 av_get_bits_per_sample(st->codec->codec_id)) / 8;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
56 if (!aic->sample_size) {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
57 av_log(s, AV_LOG_ERROR, "could not compute sample size\n");
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
58 return -1;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
59 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
60 aic->samples_per_frame = samples_per_frame;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
61 aic->samples = aic->samples_per_frame;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
62 aic->time_base = time_base;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
63
4534
cb5bcf4bfe15 check fifo size and realloc if needed
bcoudurier
parents: 4426
diff changeset
64 aic->fifo_size = 100* *aic->samples;
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4534
diff changeset
65 aic->fifo= av_fifo_alloc(100 * *aic->samples);
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
66 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
67 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
68
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
69 return 0;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
70 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
71
4417
de5ccc7a4461 Declare ff_interleave_new_audio_packet as static, it is not used
bcoudurier
parents: 4409
diff changeset
72 static int ff_interleave_new_audio_packet(AVFormatContext *s, AVPacket *pkt,
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
73 int stream_index, int flush)
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
74 {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
75 AVStream *st = s->streams[stream_index];
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
76 AudioInterleaveContext *aic = st->priv_data;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
77
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4534
diff changeset
78 int size = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size);
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4534
diff changeset
79 if (!size || (!flush && size == av_fifo_size(aic->fifo)))
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
80 return 0;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
81
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
82 av_new_packet(pkt, size);
4689
fc0a165de804 Reorder arguments for av_fifo_generic_read to be more logical and
reimar
parents: 4670
diff changeset
83 av_fifo_generic_read(aic->fifo, pkt->data, size, NULL);
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
84
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
85 pkt->dts = pkt->pts = aic->dts;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
86 pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
87 pkt->stream_index = stream_index;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
88 aic->dts += pkt->duration;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
89
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
90 aic->samples++;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
91 if (!*aic->samples)
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
92 aic->samples = aic->samples_per_frame;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
93
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
94 return size;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
95 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
96
4426
7854590fb1fd rename ff_audio_interleave to ff_audio_rechunk_interleave
bcoudurier
parents: 4418
diff changeset
97 int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush,
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
98 int (*get_packet)(AVFormatContext *, AVPacket *, AVPacket *, int),
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
99 int (*compare_ts)(AVFormatContext *, AVPacket *, AVPacket *))
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
100 {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
101 int i;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
102
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
103 if (pkt) {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
104 AVStream *st = s->streams[pkt->stream_index];
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
105 AudioInterleaveContext *aic = st->priv_data;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
106 if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4534
diff changeset
107 unsigned new_size = av_fifo_size(aic->fifo) + pkt->size;
4534
cb5bcf4bfe15 check fifo size and realloc if needed
bcoudurier
parents: 4426
diff changeset
108 if (new_size > aic->fifo_size) {
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4534
diff changeset
109 if (av_fifo_realloc2(aic->fifo, new_size) < 0)
4534
cb5bcf4bfe15 check fifo size and realloc if needed
bcoudurier
parents: 4426
diff changeset
110 return -1;
cb5bcf4bfe15 check fifo size and realloc if needed
bcoudurier
parents: 4426
diff changeset
111 aic->fifo_size = new_size;
cb5bcf4bfe15 check fifo size and realloc if needed
bcoudurier
parents: 4426
diff changeset
112 }
4669
d6eb19c43e99 Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
michael
parents: 4534
diff changeset
113 av_fifo_generic_write(aic->fifo, pkt->data, pkt->size, NULL);
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
114 } else {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
115 // rewrite pts and dts to be decoded time line position
4409
38cf661aa650 rewrite pts also, as comment says
bcoudurier
parents: 4400
diff changeset
116 pkt->pts = pkt->dts = aic->dts;
4400
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
117 aic->dts += pkt->duration;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
118 ff_interleave_add_packet(s, pkt, compare_ts);
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
119 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
120 pkt = NULL;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
121 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
122
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
123 for (i = 0; i < s->nb_streams; i++) {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
124 AVStream *st = s->streams[i];
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
125 if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
126 AVPacket new_pkt;
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
127 while (ff_interleave_new_audio_packet(s, &new_pkt, i, flush))
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
128 ff_interleave_add_packet(s, &new_pkt, compare_ts);
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
129 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
130 }
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
131
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
132 return get_packet(s, out, pkt, flush);
65adb9e5214f extract audio interleaving code from mxf muxer, will be used by gxf and dv
bcoudurier
parents:
diff changeset
133 }