Libav 0.7.1
|
00001 /* 00002 * Copyright (C) 2007 Libav Project 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include "libavutil/intreadwrite.h" 00022 #include "xiph.h" 00023 00024 int ff_split_xiph_headers(uint8_t *extradata, int extradata_size, 00025 int first_header_size, uint8_t *header_start[3], 00026 int header_len[3]) 00027 { 00028 int i; 00029 00030 if (extradata_size >= 6 && AV_RB16(extradata) == first_header_size) { 00031 int overall_len = 6; 00032 for (i=0; i<3; i++) { 00033 header_len[i] = AV_RB16(extradata); 00034 extradata += 2; 00035 header_start[i] = extradata; 00036 extradata += header_len[i]; 00037 if (overall_len > extradata_size - header_len[i]) 00038 return -1; 00039 overall_len += header_len[i]; 00040 } 00041 } else if (extradata_size >= 3 && extradata_size < INT_MAX - 0x1ff && extradata[0] == 2) { 00042 int overall_len = 3; 00043 extradata++; 00044 for (i=0; i<2; i++, extradata++) { 00045 header_len[i] = 0; 00046 for (; overall_len < extradata_size && *extradata==0xff; extradata++) { 00047 header_len[i] += 0xff; 00048 overall_len += 0xff + 1; 00049 } 00050 header_len[i] += *extradata; 00051 overall_len += *extradata; 00052 if (overall_len > extradata_size) 00053 return -1; 00054 } 00055 header_len[2] = extradata_size - overall_len; 00056 header_start[0] = extradata; 00057 header_start[1] = header_start[0] + header_len[0]; 00058 header_start[2] = header_start[1] + header_len[1]; 00059 } else { 00060 return -1; 00061 } 00062 return 0; 00063 }