More cosmetics
[FFMpeg-mirror/DVCPRO-HD.git] / libavcodec / xiph.c
blob6554264648912d80d5f6a7c02f1364d11a82c218
1 /*
2 * Copyright (C) 2007 FFmpeg Project
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "xiph.h"
23 int ff_split_xiph_headers(uint8_t *extradata, int extradata_size,
24 int first_header_size, uint8_t *header_start[3],
25 int header_len[3])
27 int i;
29 if (extradata_size >= 6 && AV_RB16(extradata) == first_header_size) {
30 int overall_len = 6;
31 for (i=0; i<3; i++) {
32 header_len[i] = AV_RB16(extradata);
33 extradata += 2;
34 header_start[i] = extradata;
35 extradata += header_len[i];
36 if (overall_len > extradata_size - header_len[i])
37 return -1;
38 overall_len += header_len[i];
40 } else if (extradata_size >= 3 && extradata_size < INT_MAX - 0x1ff && extradata[0] == 2) {
41 int overall_len = 3;
42 extradata++;
43 for (i=0; i<2; i++, extradata++) {
44 header_len[i] = 0;
45 for (; overall_len < extradata_size && *extradata==0xff; extradata++) {
46 header_len[i] += 0xff;
47 overall_len += 0xff + 1;
49 header_len[i] += *extradata;
50 overall_len += *extradata;
51 if (overall_len > extradata_size)
52 return -1;
54 header_len[2] = extradata_size - overall_len;
55 header_start[0] = extradata;
56 header_start[1] = header_start[0] + header_len[0];
57 header_start[2] = header_start[1] + header_len[1];
58 } else {
59 return -1;
61 return 0;