annotate oggparseflac.c @ 1086:4c7e75e255f8 libavformat

add quicktime uncompressed 8bit 4:2:2 support
author bcoudurier
date Sun, 14 May 2006 14:21:06 +0000
parents 91677ac6fb19
children 0899bfe4105c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
1 /*
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
2 * Copyright (C) 2005 Matthieu CASTET
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
3 *
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
5 * modify it under the terms of the GNU Lesser General Public
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
8 *
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
12 * Lesser General Public License for more details.
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
13 *
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
14 * You should have received a copy of the GNU Lesser General Public
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
15 * License along with this library; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
17 */
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
18
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
19 #include <stdlib.h>
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
20 #include "avformat.h"
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
21 #include "bitstream.h"
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
22 #include "ogg2.h"
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
23
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
24 #define FLAC_STREAMINFO_SIZE 0x22
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
25
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
26 static int
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
27 flac_header (AVFormatContext * s, int idx)
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
28 {
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
29 ogg_t *ogg = s->priv_data;
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
30 ogg_stream_t *os = ogg->streams + idx;
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
31 AVStream *st = s->streams[idx];
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
32 GetBitContext gb;
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
33 int mdt;
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
34
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
35 if (os->buf[os->pstart] == 0xff)
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
36 return 0;
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
37
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
38 init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
39 get_bits(&gb, 1); /* metadata_last */
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
40 mdt = get_bits(&gb, 7);
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
41
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
42 if (mdt == 0x7f) {
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
43 skip_bits(&gb, 4*8); /* "FLAC" */
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
44 if(get_bits(&gb, 8) != 1) /* unsupported major version */
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
45 return -1;
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
46 skip_bits(&gb, 8 + 16); /* minor version + header count */
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
47 skip_bits(&gb, 4*8); /* "fLaC" */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
48
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
49 /* METADATA_BLOCK_HEADER */
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
50 if (get_bits(&gb, 32) != FLAC_STREAMINFO_SIZE)
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
51 return -1;
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
52
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
53 skip_bits(&gb, 16*2+24*2);
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
54
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 756
diff changeset
55 st->codec->sample_rate = get_bits_long(&gb, 20);
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 756
diff changeset
56 st->codec->channels = get_bits(&gb, 3) + 1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
57
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 756
diff changeset
58 st->codec->codec_type = CODEC_TYPE_AUDIO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 756
diff changeset
59 st->codec->codec_id = CODEC_ID_FLAC;
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
60
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 756
diff changeset
61 st->codec->extradata =
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
62 av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 756
diff changeset
63 memcpy (st->codec->extradata, os->buf + os->pstart + 5 + 4 + 4 + 4,
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
64 FLAC_STREAMINFO_SIZE);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 756
diff changeset
65 st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
1077
91677ac6fb19 set stream time_base properly
mru
parents: 896
diff changeset
66
91677ac6fb19 set stream time_base properly
mru
parents: 896
diff changeset
67 st->time_base.num = 1;
91677ac6fb19 set stream time_base properly
mru
parents: 896
diff changeset
68 st->time_base.den = st->codec->sample_rate;
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
69 } else if (mdt == 4) {
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
70 vorbis_comment (s, os->buf + os->pstart + 4, os->psize - 4);
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
71 }
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
72
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
73 return 1;
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
74 }
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
75
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
76 ogg_codec_t flac_codec = {
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
77 .magic = "\177FLAC",
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
78 .magicsize = 5,
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
79 .header = flac_header
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
80 };