2007-03-25 03:06:45 +02:00
|
|
|
/*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Copyright (C) 2007 Libav Project
|
2007-03-25 03:06:45 +02:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* This file is part of Libav.
|
2007-03-25 03:06:45 +02:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2007-03-25 03:06:45 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2007-03-25 03:06:45 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 18:35:10 +01:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2007-03-25 03:06:45 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2009-01-11 23:19:48 +01:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2007-03-25 03:06:45 +02:00
|
|
|
#include "xiph.h"
|
|
|
|
|
2011-10-17 09:45:27 +02:00
|
|
|
int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size,
|
2007-03-25 03:06:45 +02:00
|
|
|
int first_header_size, uint8_t *header_start[3],
|
|
|
|
int header_len[3])
|
|
|
|
{
|
2008-04-21 01:54:40 +02:00
|
|
|
int i;
|
2007-03-25 03:06:45 +02:00
|
|
|
|
2008-04-21 01:33:49 +02:00
|
|
|
if (extradata_size >= 6 && AV_RB16(extradata) == first_header_size) {
|
|
|
|
int overall_len = 6;
|
2007-03-25 03:06:45 +02:00
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
header_len[i] = AV_RB16(extradata);
|
|
|
|
extradata += 2;
|
|
|
|
header_start[i] = extradata;
|
|
|
|
extradata += header_len[i];
|
2008-04-21 01:33:49 +02:00
|
|
|
if (overall_len > extradata_size - header_len[i])
|
|
|
|
return -1;
|
|
|
|
overall_len += header_len[i];
|
2007-03-25 03:06:45 +02:00
|
|
|
}
|
2008-04-21 01:33:49 +02:00
|
|
|
} else if (extradata_size >= 3 && extradata_size < INT_MAX - 0x1ff && extradata[0] == 2) {
|
|
|
|
int overall_len = 3;
|
2008-04-21 01:54:40 +02:00
|
|
|
extradata++;
|
|
|
|
for (i=0; i<2; i++, extradata++) {
|
2007-03-25 03:06:45 +02:00
|
|
|
header_len[i] = 0;
|
2008-04-21 01:54:40 +02:00
|
|
|
for (; overall_len < extradata_size && *extradata==0xff; extradata++) {
|
2007-03-25 03:06:45 +02:00
|
|
|
header_len[i] += 0xff;
|
2008-04-21 01:33:49 +02:00
|
|
|
overall_len += 0xff + 1;
|
2007-03-25 03:06:45 +02:00
|
|
|
}
|
2008-04-21 01:54:40 +02:00
|
|
|
header_len[i] += *extradata;
|
|
|
|
overall_len += *extradata;
|
2008-04-21 01:33:49 +02:00
|
|
|
if (overall_len > extradata_size)
|
2007-03-25 03:06:45 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2008-04-21 01:54:40 +02:00
|
|
|
header_len[2] = extradata_size - overall_len;
|
2007-03-25 03:06:45 +02:00
|
|
|
header_start[0] = extradata;
|
|
|
|
header_start[1] = header_start[0] + header_len[0];
|
|
|
|
header_start[2] = header_start[1] + header_len[1];
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|