1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 #include "pv_avifile_indx.h"
19
PVAviFileIdxChunk(PVFile * aFp,uint32 aIndxSize,uint32 aNumStreams)20 PVAviFileIdxChunk::PVAviFileIdxChunk(PVFile* aFp, uint32 aIndxSize, uint32 aNumStreams)
21 {
22 iIndexSize = aIndxSize;
23 iNumStreams = aNumStreams;
24 uint32 bytesRead = 0;
25 int32 strNum = 0;
26 uint32 data = 0;
27 iError = PV_AVI_FILE_PARSER_SUCCESS;
28 iOffsetFrmMoviLst = false;
29 bool firstSample = true;
30
31 for (uint32 ii = 0; ii < iNumStreams; ii++)
32 {
33 IndxTblVector xtbl;
34 iIndexTable.push_back(xtbl);
35 }
36
37 while (bytesRead < iIndexSize)
38 {
39 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, data))
40 {
41 iError = PV_AVI_FILE_PARSER_READ_ERROR;
42 break;
43 }
44 bytesRead += CHUNK_SIZE;
45 if (bytesRead > iIndexSize)
46 {
47 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
48 break;
49 }
50
51 strNum = PVAviFileParserUtils::GetStreamNumber(data);
52
53 if ((strNum < 0) || (strNum >= (int32)iNumStreams))
54 {
55 //bogus entry skip it.
56 aFp->Seek((CHUNK_SIZE + CHUNK_SIZE + CHUNK_SIZE), Oscl_File::SEEKCUR);
57
58 bytesRead += CHUNK_SIZE + CHUNK_SIZE + CHUNK_SIZE ; //flags+offset+size
59 continue;
60 }
61
62 IdxTblType tbl;
63 tbl.chunkId = data;
64
65 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, (tbl.flags)))
66 {
67 iError = PV_AVI_FILE_PARSER_READ_ERROR;
68 break;
69 }
70
71 bytesRead += CHUNK_SIZE;
72 if (bytesRead > iIndexSize)
73 {
74 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
75 break;
76 }
77
78 if (tbl.flags & AVIIF_KEYFRAME)
79 tbl.isKeyFrame = true;
80 if (tbl.flags & AVIIF_LIST)
81 tbl.ifRecList = true;
82 if (tbl.flags & AVIIF_NO_TIME)
83 tbl.ifNoTime = true;
84
85 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, tbl.offset, true))
86 {
87 iError = PV_AVI_FILE_PARSER_READ_ERROR;
88 break;
89 }
90
91 bytesRead += CHUNK_SIZE;
92 if (bytesRead > iIndexSize)
93 {
94 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
95 break;
96 }
97
98 if (firstSample)
99 {
100 firstSample = false;
101 if (OFFSET_FROM_MOVI_LST == tbl.offset)
102 {
103 iOffsetFrmMoviLst = true;
104 }
105 }
106
107 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, tbl.size, true))
108 {
109 iError = PV_AVI_FILE_PARSER_READ_ERROR;
110 break;
111 }
112
113 bytesRead += CHUNK_SIZE;
114 if (bytesRead > iIndexSize)
115 {
116 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
117 break;
118 }
119
120 (iIndexTable[strNum]).push_back(tbl);
121
122 }
123 }
124
125