annotate ffmpeg/libavformat/oggparseflac.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * Copyright (C) 2005 Matthieu CASTET
yading@11 3 *
yading@11 4 * This file is part of FFmpeg.
yading@11 5 *
yading@11 6 * FFmpeg is free software; you can redistribute it and/or
yading@11 7 * modify it under the terms of the GNU Lesser General Public
yading@11 8 * License as published by the Free Software Foundation; either
yading@11 9 * version 2.1 of the License, or (at your option) any later version.
yading@11 10 *
yading@11 11 * FFmpeg is distributed in the hope that it will be useful,
yading@11 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 14 * Lesser General Public License for more details.
yading@11 15 *
yading@11 16 * You should have received a copy of the GNU Lesser General Public
yading@11 17 * License along with FFmpeg; if not, write to the Free Software
yading@11 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 19 */
yading@11 20
yading@11 21 #include <stdlib.h>
yading@11 22 #include "libavcodec/get_bits.h"
yading@11 23 #include "libavcodec/flac.h"
yading@11 24 #include "avformat.h"
yading@11 25 #include "internal.h"
yading@11 26 #include "oggdec.h"
yading@11 27
yading@11 28 #define OGG_FLAC_METADATA_TYPE_STREAMINFO 0x7F
yading@11 29
yading@11 30 static int
yading@11 31 flac_header (AVFormatContext * s, int idx)
yading@11 32 {
yading@11 33 struct ogg *ogg = s->priv_data;
yading@11 34 struct ogg_stream *os = ogg->streams + idx;
yading@11 35 AVStream *st = s->streams[idx];
yading@11 36 GetBitContext gb;
yading@11 37 FLACStreaminfo si;
yading@11 38 int mdt;
yading@11 39
yading@11 40 if (os->buf[os->pstart] == 0xff)
yading@11 41 return 0;
yading@11 42
yading@11 43 init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
yading@11 44 skip_bits1(&gb); /* metadata_last */
yading@11 45 mdt = get_bits(&gb, 7);
yading@11 46
yading@11 47 if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) {
yading@11 48 uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4;
yading@11 49 skip_bits_long(&gb, 4*8); /* "FLAC" */
yading@11 50 if(get_bits(&gb, 8) != 1) /* unsupported major version */
yading@11 51 return -1;
yading@11 52 skip_bits_long(&gb, 8 + 16); /* minor version + header count */
yading@11 53 skip_bits_long(&gb, 4*8); /* "fLaC" */
yading@11 54
yading@11 55 /* METADATA_BLOCK_HEADER */
yading@11 56 if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE)
yading@11 57 return -1;
yading@11 58
yading@11 59 avpriv_flac_parse_streaminfo(st->codec, &si, streaminfo_start);
yading@11 60
yading@11 61 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 62 st->codec->codec_id = AV_CODEC_ID_FLAC;
yading@11 63 st->need_parsing = AVSTREAM_PARSE_HEADERS;
yading@11 64
yading@11 65 st->codec->extradata =
yading@11 66 av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
yading@11 67 memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE);
yading@11 68 st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
yading@11 69
yading@11 70 avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
yading@11 71 } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
yading@11 72 ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 4, os->psize - 4);
yading@11 73 }
yading@11 74
yading@11 75 return 1;
yading@11 76 }
yading@11 77
yading@11 78 static int
yading@11 79 old_flac_header (AVFormatContext * s, int idx)
yading@11 80 {
yading@11 81 AVStream *st = s->streams[idx];
yading@11 82 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 83 st->codec->codec_id = AV_CODEC_ID_FLAC;
yading@11 84
yading@11 85 return 0;
yading@11 86 }
yading@11 87
yading@11 88 const struct ogg_codec ff_flac_codec = {
yading@11 89 .magic = "\177FLAC",
yading@11 90 .magicsize = 5,
yading@11 91 .header = flac_header,
yading@11 92 .nb_header = 2,
yading@11 93 };
yading@11 94
yading@11 95 const struct ogg_codec ff_old_flac_codec = {
yading@11 96 .magic = "fLaC",
yading@11 97 .magicsize = 4,
yading@11 98 .header = old_flac_header,
yading@11 99 .nb_header = 0,
yading@11 100 };