ffmpeg / libavcodec / xiph.c @ 6a5d31ac
History | View | Annotate | Download (2.26 KB)
1 | 5bb127a9 | Aurelien Jacobs | /*
|
---|---|---|---|
2 | * Copyright (C) 2007 FFmpeg Project
|
||
3 | *
|
||
4 | * This file is part of FFmpeg.
|
||
5 | *
|
||
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.
|
||
10 | *
|
||
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.
|
||
15 | *
|
||
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
|
||
19 | */
|
||
20 | |||
21 | 6a5d31ac | Diego Biurrun | #include "libavutil/intreadwrite.h" |
22 | 5bb127a9 | Aurelien Jacobs | #include "xiph.h" |
23 | |||
24 | int ff_split_xiph_headers(uint8_t *extradata, int extradata_size, |
||
25 | int first_header_size, uint8_t *header_start[3], |
||
26 | int header_len[3]) |
||
27 | { |
||
28 | b189e670 | Reimar Döffinger | int i;
|
29 | 5bb127a9 | Aurelien Jacobs | |
30 | 58720ebd | Reimar Döffinger | if (extradata_size >= 6 && AV_RB16(extradata) == first_header_size) { |
31 | int overall_len = 6; |
||
32 | 5bb127a9 | Aurelien Jacobs | for (i=0; i<3; i++) { |
33 | header_len[i] = AV_RB16(extradata); |
||
34 | extradata += 2;
|
||
35 | header_start[i] = extradata; |
||
36 | extradata += header_len[i]; |
||
37 | 58720ebd | Reimar Döffinger | if (overall_len > extradata_size - header_len[i])
|
38 | return -1; |
||
39 | overall_len += header_len[i]; |
||
40 | 5bb127a9 | Aurelien Jacobs | } |
41 | 58720ebd | Reimar Döffinger | } else if (extradata_size >= 3 && extradata_size < INT_MAX - 0x1ff && extradata[0] == 2) { |
42 | int overall_len = 3; |
||
43 | b189e670 | Reimar Döffinger | extradata++; |
44 | for (i=0; i<2; i++, extradata++) { |
||
45 | 5bb127a9 | Aurelien Jacobs | header_len[i] = 0;
|
46 | b189e670 | Reimar Döffinger | for (; overall_len < extradata_size && *extradata==0xff; extradata++) { |
47 | 5bb127a9 | Aurelien Jacobs | header_len[i] += 0xff;
|
48 | 58720ebd | Reimar Döffinger | overall_len += 0xff + 1; |
49 | 5bb127a9 | Aurelien Jacobs | } |
50 | b189e670 | Reimar Döffinger | header_len[i] += *extradata; |
51 | overall_len += *extradata; |
||
52 | 58720ebd | Reimar Döffinger | if (overall_len > extradata_size)
|
53 | 5bb127a9 | Aurelien Jacobs | return -1; |
54 | } |
||
55 | b189e670 | Reimar Döffinger | header_len[2] = extradata_size - overall_len;
|
56 | 5bb127a9 | Aurelien Jacobs | header_start[0] = extradata;
|
57 | header_start[1] = header_start[0] + header_len[0]; |
||
58 | header_start[2] = header_start[1] + header_len[1]; |
||
59 | } else {
|
||
60 | return -1; |
||
61 | } |
||
62 | return 0; |
||
63 | } |