2 * This file is part of Libav.
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 ff_voc_get_packet(AVFormatContext
*s
, AVPacket
*pkt
, AVStream
*st
, int max_size
)
26 VocDecContext
*voc
= s
->priv_data
;
27 AVCodecParameters
*par
= st
->codecpar
;
28 AVIOContext
*pb
= s
->pb
;
30 int size
, tmp_codec
=-1;
34 while (!voc
->remaining_size
) {
36 if (type
== VOC_TYPE_EOF
)
38 voc
->remaining_size
= avio_rl24(pb
);
39 if (!voc
->remaining_size
) {
40 if (!(s
->pb
->seekable
& AVIO_SEEKABLE_NORMAL
))
42 voc
->remaining_size
= avio_size(pb
) - avio_tell(pb
);
47 case VOC_TYPE_VOICE_DATA
:
48 if (!par
->sample_rate
) {
49 par
->sample_rate
= 1000000 / (256 - avio_r8(pb
));
51 par
->sample_rate
= sample_rate
;
52 avpriv_set_pts_info(st
, 64, 1, par
->sample_rate
);
53 par
->channels
= channels
;
54 par
->bits_per_coded_sample
= av_get_bits_per_sample(par
->codec_id
);
57 tmp_codec
= avio_r8(pb
);
58 voc
->remaining_size
-= 2;
63 case VOC_TYPE_VOICE_DATA_CONT
:
66 case VOC_TYPE_EXTENDED
:
67 sample_rate
= avio_rl16(pb
);
69 channels
= avio_r8(pb
) + 1;
70 sample_rate
= 256000000 / (channels
* (65536 - sample_rate
));
71 voc
->remaining_size
= 0;
75 case VOC_TYPE_NEW_VOICE_DATA
:
76 if (!par
->sample_rate
) {
77 par
->sample_rate
= avio_rl32(pb
);
78 avpriv_set_pts_info(st
, 64, 1, par
->sample_rate
);
79 par
->bits_per_coded_sample
= avio_r8(pb
);
80 par
->channels
= avio_r8(pb
);
83 tmp_codec
= avio_rl16(pb
);
85 voc
->remaining_size
-= 12;
90 avio_skip(pb
, voc
->remaining_size
);
91 max_size
-= voc
->remaining_size
;
92 voc
->remaining_size
= 0;
98 tmp_codec
= ff_codec_get_id(ff_voc_codec_tags
, tmp_codec
);
99 if (par
->codec_id
== AV_CODEC_ID_NONE
)
100 par
->codec_id
= tmp_codec
;
101 else if (par
->codec_id
!= tmp_codec
)
102 av_log(s
, AV_LOG_WARNING
, "Ignoring mid-stream change in audio codec\n");
103 if (par
->codec_id
== AV_CODEC_ID_NONE
) {
104 if (s
->audio_codec_id
== AV_CODEC_ID_NONE
) {
105 av_log(s
, AV_LOG_ERROR
, "unknown codec tag\n");
106 return AVERROR(EINVAL
);
108 av_log(s
, AV_LOG_WARNING
, "unknown codec tag\n");
112 par
->bit_rate
= par
->sample_rate
* par
->bits_per_coded_sample
;
116 size
= FFMIN(voc
->remaining_size
, max_size
);
117 voc
->remaining_size
-= size
;
118 return av_get_packet(pb
, pkt
, size
);