annotate oggparseflac.c @ 842:43210d766412 libavformat

parse pict_type for streams in avi fix mpeg4 parser so it outputs te pict_type support header only parseing without repacking
author michael
date Mon, 15 Aug 2005 15:58:21 +0000
parents feca73904e67
children da1d5db0ce5c
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
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
3 *
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
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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" */
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
48
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;
756
677bad57fca2 flac in ogg support
mru
parents:
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;
756
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
66 } else if (mdt == 4) {
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
67 vorbis_comment (s, os->buf + os->pstart + 4, os->psize - 4);
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
68 }
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
69
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
70 return 1;
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 ogg_codec_t flac_codec = {
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
74 .magic = "\177FLAC",
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
75 .magicsize = 5,
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
76 .header = flac_header
677bad57fca2 flac in ogg support
mru
parents:
diff changeset
77 };