Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
f369b935
Commit
f369b935
authored
Sep 10, 2013
by
Alexandra Khirnova
Committed by
Diego Biurrun
Sep 10, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avformat: Use av_reallocp_array() where suitable
Signed-off-by:
Diego Biurrun
<
diego@biurrun.de
>
parent
bdf99042
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
90 additions
and
73 deletions
+90
-73
asfenc.c
libavformat/asfenc.c
+7
-3
gxfenc.c
libavformat/gxfenc.c
+12
-8
matroskadec.c
libavformat/matroskadec.c
+6
-5
matroskaenc.c
libavformat/matroskaenc.c
+12
-6
mov.c
libavformat/mov.c
+22
-18
mpegts.c
libavformat/mpegts.c
+3
-3
mxfdec.c
libavformat/mxfdec.c
+14
-10
oggdec.c
libavformat/oggdec.c
+6
-10
utils.c
libavformat/utils.c
+8
-10
No files found.
libavformat/asfenc.c
View file @
f369b935
...
...
@@ -788,10 +788,14 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
if
(
start_sec
!=
(
int
)(
asf
->
last_indexed_pts
/
INT64_C
(
10000000
)))
{
for
(
i
=
asf
->
nb_index_count
;
i
<
start_sec
;
i
++
)
{
if
(
i
>=
asf
->
nb_index_memory_alloc
)
{
int
err
;
asf
->
nb_index_memory_alloc
+=
ASF_INDEX_BLOCK
;
asf
->
index_ptr
=
(
ASFIndex
*
)
av_realloc
(
asf
->
index_ptr
,
sizeof
(
ASFIndex
)
*
asf
->
nb_index_memory_alloc
);
if
((
err
=
av_reallocp_array
(
&
asf
->
index_ptr
,
asf
->
nb_index_memory_alloc
,
sizeof
(
*
asf
->
index_ptr
)))
<
0
)
{
asf
->
nb_index_memory_alloc
=
0
;
return
err
;
}
}
// store
asf
->
index_ptr
[
i
].
packet_number
=
(
uint32_t
)
packet_st
;
...
...
libavformat/gxfenc.c
View file @
f369b935
...
...
@@ -342,11 +342,13 @@ static int gxf_write_map_packet(AVFormatContext *s, int rewrite)
if
(
!
rewrite
)
{
if
(
!
(
gxf
->
map_offsets_nb
%
30
))
{
gxf
->
map_offsets
=
av_realloc
(
gxf
->
map_offsets
,
(
gxf
->
map_offsets_nb
+
30
)
*
sizeof
(
*
gxf
->
map_offsets
));
if
(
!
gxf
->
map_offsets
)
{
int
err
;
if
((
err
=
av_reallocp_array
(
&
gxf
->
map_offsets
,
gxf
->
map_offsets_nb
+
30
,
sizeof
(
*
gxf
->
map_offsets
)))
<
0
)
{
gxf
->
map_offsets_nb
=
0
;
av_log
(
s
,
AV_LOG_ERROR
,
"could not realloc map offsets
\n
"
);
return
-
1
;
return
err
;
}
}
gxf
->
map_offsets
[
gxf
->
map_offsets_nb
++
]
=
pos
;
// do not increment here
...
...
@@ -873,11 +875,13 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt)
if
(
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_VIDEO
)
{
if
(
!
(
gxf
->
flt_entries_nb
%
500
))
{
gxf
->
flt_entries
=
av_realloc
(
gxf
->
flt_entries
,
(
gxf
->
flt_entries_nb
+
500
)
*
sizeof
(
*
gxf
->
flt_entries
));
if
(
!
gxf
->
flt_entries
)
{
int
err
;
if
((
err
=
av_reallocp_array
(
&
gxf
->
flt_entries
,
gxf
->
flt_entries_nb
+
500
,
sizeof
(
*
gxf
->
flt_entries
)))
<
0
)
{
gxf
->
flt_entries_nb
=
0
;
av_log
(
s
,
AV_LOG_ERROR
,
"could not reallocate flt entries
\n
"
);
return
-
1
;
return
err
;
}
}
gxf
->
flt_entries
[
gxf
->
flt_entries_nb
++
]
=
packet_start_offset
;
...
...
libavformat/matroskadec.c
View file @
f369b935
...
...
@@ -878,15 +878,16 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
uint32_t
id
=
syntax
->
id
;
uint64_t
length
;
int
res
;
void
*
newelem
;
data
=
(
char
*
)
data
+
syntax
->
data_offset
;
if
(
syntax
->
list_elem_size
)
{
EbmlList
*
list
=
data
;
newelem
=
av_realloc
(
list
->
elem
,
(
list
->
nb_elem
+
1
)
*
syntax
->
list_elem_size
);
if
(
!
newelem
)
return
AVERROR
(
ENOMEM
);
list
->
elem
=
newelem
;
if
((
res
=
av_reallocp_array
(
&
list
->
elem
,
list
->
nb_elem
+
1
,
syntax
->
list_elem_size
))
<
0
)
{
list
->
nb_elem
=
0
;
return
res
;
}
data
=
(
char
*
)
list
->
elem
+
list
->
nb_elem
*
syntax
->
list_elem_size
;
memset
(
data
,
0
,
syntax
->
list_elem_size
);
list
->
nb_elem
++
;
...
...
libavformat/matroskaenc.c
View file @
f369b935
...
...
@@ -295,14 +295,17 @@ static mkv_seekhead * mkv_start_seekhead(AVIOContext *pb, int64_t segment_offset
static
int
mkv_add_seekhead_entry
(
mkv_seekhead
*
seekhead
,
unsigned
int
elementid
,
uint64_t
filepos
)
{
mkv_seekhead_entry
*
entries
=
seekhead
->
entries
;
int
err
;
// don't store more elements than we reserved space for
if
(
seekhead
->
max_entries
>
0
&&
seekhead
->
max_entries
<=
seekhead
->
num_entries
)
return
-
1
;
entries
=
av_realloc
(
entries
,
(
seekhead
->
num_entries
+
1
)
*
sizeof
(
mkv_seekhead_entry
));
if
(
entries
==
NULL
)
return
AVERROR
(
ENOMEM
);
if
((
err
=
av_reallocp_array
(
&
entries
,
seekhead
->
num_entries
+
1
,
sizeof
(
*
entries
)))
<
0
)
{
seekhead
->
num_entries
=
0
;
return
err
;
}
entries
[
seekhead
->
num_entries
].
elementid
=
elementid
;
entries
[
seekhead
->
num_entries
++
].
segmentpos
=
filepos
-
seekhead
->
segment_offset
;
...
...
@@ -377,13 +380,16 @@ static mkv_cues * mkv_start_cues(int64_t segment_offset)
static
int
mkv_add_cuepoint
(
mkv_cues
*
cues
,
int
stream
,
int64_t
ts
,
int64_t
cluster_pos
)
{
mkv_cuepoint
*
entries
=
cues
->
entries
;
int
err
;
if
(
ts
<
0
)
return
0
;
entries
=
av_realloc
(
entries
,
(
cues
->
num_entries
+
1
)
*
sizeof
(
mkv_cuepoint
));
if
(
entries
==
NULL
)
return
AVERROR
(
ENOMEM
);
if
((
err
=
av_reallocp_array
(
&
entries
,
cues
->
num_entries
+
1
,
sizeof
(
*
entries
)))
<
0
)
{
cues
->
num_entries
=
0
;
return
err
;
}
entries
[
cues
->
num_entries
].
pts
=
ts
;
entries
[
cues
->
num_entries
].
tracknum
=
stream
+
1
;
...
...
libavformat/mov.c
View file @
f369b935
...
...
@@ -1841,7 +1841,6 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
unsigned
int
stps_index
=
0
;
unsigned
int
i
,
j
;
uint64_t
stream_size
=
0
;
AVIndexEntry
*
mem
;
/* adjust first dts according to edit list */
if
(
sc
->
time_offset
&&
mov
->
time_scale
>
0
)
{
...
...
@@ -1875,10 +1874,12 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
return
;
if
(
sc
->
sample_count
>=
UINT_MAX
/
sizeof
(
*
st
->
index_entries
)
-
st
->
nb_index_entries
)
return
;
mem
=
av_realloc
(
st
->
index_entries
,
(
st
->
nb_index_entries
+
sc
->
sample_count
)
*
sizeof
(
*
st
->
index_entries
));
if
(
!
mem
)
if
(
av_reallocp_array
(
&
st
->
index_entries
,
st
->
nb_index_entries
+
sc
->
sample_count
,
sizeof
(
*
st
->
index_entries
))
<
0
)
{
st
->
nb_index_entries
=
0
;
return
;
st
->
index_entries
=
mem
;
}
st
->
index_entries_allocated_size
=
(
st
->
nb_index_entries
+
sc
->
sample_count
)
*
sizeof
(
*
st
->
index_entries
);
for
(
i
=
0
;
i
<
sc
->
chunk_count
;
i
++
)
{
...
...
@@ -1973,10 +1974,12 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
av_dlog
(
mov
->
fc
,
"chunk count %d
\n
"
,
total
);
if
(
total
>=
UINT_MAX
/
sizeof
(
*
st
->
index_entries
)
-
st
->
nb_index_entries
)
return
;
mem
=
av_realloc
(
st
->
index_entries
,
(
st
->
nb_index_entries
+
total
)
*
sizeof
(
*
st
->
index_entries
));
if
(
!
mem
)
if
(
av_reallocp_array
(
&
st
->
index_entries
,
st
->
nb_index_entries
+
total
,
sizeof
(
*
st
->
index_entries
))
<
0
)
{
st
->
nb_index_entries
=
0
;
return
;
st
->
index_entries
=
mem
;
}
st
->
index_entries_allocated_size
=
(
st
->
nb_index_entries
+
total
)
*
sizeof
(
*
st
->
index_entries
);
// populate index
...
...
@@ -2307,13 +2310,15 @@ static int mov_read_chap(MOVContext *c, AVIOContext *pb, MOVAtom atom)
static
int
mov_read_trex
(
MOVContext
*
c
,
AVIOContext
*
pb
,
MOVAtom
atom
)
{
MOVTrackExt
*
trex
;
int
err
;
if
((
uint64_t
)
c
->
trex_count
+
1
>=
UINT_MAX
/
sizeof
(
*
c
->
trex_data
))
return
AVERROR_INVALIDDATA
;
trex
=
av_realloc
(
c
->
trex_data
,
(
c
->
trex_count
+
1
)
*
sizeof
(
*
c
->
trex_data
));
if
(
!
trex
)
return
AVERROR
(
ENOMEM
);
c
->
trex_data
=
trex
;
if
((
err
=
av_reallocp_array
(
&
c
->
trex_data
,
c
->
trex_count
+
1
,
sizeof
(
*
c
->
trex_data
)))
<
0
)
{
c
->
trex_count
=
0
;
return
err
;
}
trex
=
&
c
->
trex_data
[
c
->
trex_count
++
];
avio_r8
(
pb
);
/* version */
avio_rb24
(
pb
);
/* flags */
...
...
@@ -2335,7 +2340,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
int64_t
dts
;
int
data_offset
=
0
;
unsigned
entries
,
first_sample_flags
=
frag
->
flags
;
int
flags
,
distance
,
i
,
found_keyframe
=
0
;
int
flags
,
distance
,
i
,
found_keyframe
=
0
,
err
;
for
(
i
=
0
;
i
<
c
->
fc
->
nb_streams
;
i
++
)
{
if
(
c
->
fc
->
streams
[
i
]
->
id
==
frag
->
track_id
)
{
...
...
@@ -2373,12 +2378,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
}
if
((
uint64_t
)
entries
+
sc
->
ctts_count
>=
UINT_MAX
/
sizeof
(
*
sc
->
ctts_data
))
return
AVERROR_INVALIDDATA
;
ctts_data
=
av_realloc
(
sc
->
ctts_data
,
(
entries
+
sc
->
ctts_count
)
*
sizeof
(
*
sc
->
ctts_data
));
if
(
!
ctts_data
)
return
AVERROR
(
ENOMEM
);
sc
->
ctts_data
=
ctts_data
;
if
((
err
=
av_reallocp_array
(
&
sc
->
ctts_data
,
entries
+
sc
->
ctts_count
,
sizeof
(
*
sc
->
ctts_data
)))
<
0
)
{
sc
->
ctts_count
=
0
;
return
err
;
}
if
(
flags
&
MOV_TRUN_DATA_OFFSET
)
data_offset
=
avio_rb32
(
pb
);
if
(
flags
&
MOV_TRUN_FIRST_SAMPLE_FLAGS
)
first_sample_flags
=
avio_rb32
(
pb
);
dts
=
sc
->
track_end
-
sc
->
time_offset
;
...
...
libavformat/mpegts.c
View file @
f369b935
...
...
@@ -201,10 +201,10 @@ static void clear_programs(MpegTSContext *ts)
static
void
add_pat_entry
(
MpegTSContext
*
ts
,
unsigned
int
programid
)
{
struct
Program
*
p
;
void
*
tmp
=
av_realloc
(
ts
->
prg
,
(
ts
->
nb_prg
+
1
)
*
sizeof
(
struct
Program
));
if
(
!
tmp
)
if
(
av_reallocp_array
(
&
ts
->
prg
,
ts
->
nb_prg
+
1
,
sizeof
(
*
ts
->
prg
))
<
0
)
{
ts
->
nb_prg
=
0
;
return
;
ts
->
prg
=
tmp
;
}
p
=
&
ts
->
prg
[
ts
->
nb_prg
];
p
->
id
=
programid
;
p
->
nb_pids
=
0
;
...
...
libavformat/mxfdec.c
View file @
f369b935
...
...
@@ -410,18 +410,20 @@ static int mxf_read_primer_pack(void *arg, AVIOContext *pb, int tag, int size, U
static
int
mxf_read_partition_pack
(
void
*
arg
,
AVIOContext
*
pb
,
int
tag
,
int
size
,
UID
uid
,
int64_t
klv_offset
)
{
MXFContext
*
mxf
=
arg
;
MXFPartition
*
partition
,
*
tmp_part
;
MXFPartition
*
partition
;
UID
op
;
uint64_t
footer_partition
;
uint32_t
nb_essence_containers
;
int
err
;
if
(
mxf
->
partitions_count
+
1
>=
UINT_MAX
/
sizeof
(
*
mxf
->
partitions
))
return
AVERROR
(
ENOMEM
);
tmp_part
=
av_realloc
(
mxf
->
partitions
,
(
mxf
->
partitions_count
+
1
)
*
sizeof
(
*
mxf
->
partitions
));
if
(
!
tmp_part
)
return
AVERROR
(
ENOMEM
);
mxf
->
partitions
=
tmp_part
;
if
((
err
=
av_reallocp_array
(
&
mxf
->
partitions
,
mxf
->
partitions_count
+
1
,
sizeof
(
*
mxf
->
partitions
)))
<
0
)
{
mxf
->
partitions_count
=
0
;
return
err
;
}
if
(
mxf
->
parsing_backward
)
{
/* insert the new partition pack in the middle
...
...
@@ -546,13 +548,15 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size
static
int
mxf_add_metadata_set
(
MXFContext
*
mxf
,
void
*
metadata_set
)
{
MXFMetadataSet
**
tmp
;
int
err
;
if
(
mxf
->
metadata_sets_count
+
1
>=
UINT_MAX
/
sizeof
(
*
mxf
->
metadata_sets
))
return
AVERROR
(
ENOMEM
);
tmp
=
av_realloc
(
mxf
->
metadata_sets
,
(
mxf
->
metadata_sets_count
+
1
)
*
sizeof
(
*
mxf
->
metadata_sets
));
if
(
!
tmp
)
return
AVERROR
(
ENOMEM
);
mxf
->
metadata_sets
=
tmp
;
if
((
err
=
av_reallocp_array
(
&
mxf
->
metadata_sets
,
mxf
->
metadata_sets_count
+
1
,
sizeof
(
*
mxf
->
metadata_sets
)))
<
0
)
{
mxf
->
metadata_sets_count
=
0
;
return
err
;
}
mxf
->
metadata_sets
[
mxf
->
metadata_sets_count
]
=
metadata_set
;
mxf
->
metadata_sets_count
++
;
return
0
;
...
...
libavformat/oggdec.c
View file @
f369b935
...
...
@@ -84,7 +84,7 @@ static int ogg_restore(AVFormatContext *s, int discard)
struct
ogg
*
ogg
=
s
->
priv_data
;
AVIOContext
*
bc
=
s
->
pb
;
struct
ogg_state
*
ost
=
ogg
->
state
;
int
i
;
int
i
,
err
;
if
(
!
ost
)
return
0
;
...
...
@@ -92,7 +92,6 @@ static int ogg_restore(AVFormatContext *s, int discard)
ogg
->
state
=
ost
->
next
;
if
(
!
discard
)
{
struct
ogg_stream
*
old_streams
=
ogg
->
streams
;
for
(
i
=
0
;
i
<
ogg
->
nstreams
;
i
++
)
av_free
(
ogg
->
streams
[
i
].
buf
);
...
...
@@ -100,16 +99,13 @@ static int ogg_restore(AVFormatContext *s, int discard)
avio_seek
(
bc
,
ost
->
pos
,
SEEK_SET
);
ogg
->
curidx
=
ost
->
curidx
;
ogg
->
nstreams
=
ost
->
nstreams
;
ogg
->
streams
=
av_realloc
(
ogg
->
streams
,
ogg
->
nstreams
*
sizeof
(
*
ogg
->
streams
));
if
(
ogg
->
streams
)
{
if
((
err
=
av_reallocp_array
(
&
ogg
->
streams
,
ogg
->
nstreams
,
sizeof
(
*
ogg
->
streams
)))
<
0
)
{
ogg
->
nstreams
=
0
;
return
err
;
}
else
memcpy
(
ogg
->
streams
,
ost
->
streams
,
ost
->
nstreams
*
sizeof
(
*
ogg
->
streams
));
}
else
{
av_free
(
old_streams
);
ogg
->
nstreams
=
0
;
}
}
av_free
(
ost
);
...
...
libavformat/utils.c
View file @
f369b935
...
...
@@ -2574,14 +2574,11 @@ AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c)
{
AVStream
*
st
;
int
i
;
AVStream
**
streams
;
if
(
s
->
nb_streams
>=
INT_MAX
/
sizeof
(
*
streams
))
if
(
av_reallocp_array
(
&
s
->
streams
,
s
->
nb_streams
+
1
,
sizeof
(
*
s
->
streams
))
<
0
)
{
s
->
nb_streams
=
0
;
return
NULL
;
streams
=
av_realloc
(
s
->
streams
,
(
s
->
nb_streams
+
1
)
*
sizeof
(
*
streams
));
if
(
!
streams
)
return
NULL
;
s
->
streams
=
streams
;
}
st
=
av_mallocz
(
sizeof
(
AVStream
));
if
(
!
st
)
...
...
@@ -2674,7 +2671,6 @@ void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
{
int
i
,
j
;
AVProgram
*
program
=
NULL
;
void
*
tmp
;
if
(
idx
>=
ac
->
nb_streams
)
{
av_log
(
ac
,
AV_LOG_ERROR
,
"stream index %d is not valid
\n
"
,
idx
);
...
...
@@ -2689,10 +2685,12 @@ void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
if
(
program
->
stream_index
[
j
]
==
idx
)
return
;
tmp
=
av_realloc
(
program
->
stream_index
,
sizeof
(
unsigned
int
)
*
(
program
->
nb_stream_indexes
+
1
));
if
(
!
tmp
)
if
(
av_reallocp_array
(
&
program
->
stream_index
,
program
->
nb_stream_indexes
+
1
,
sizeof
(
*
program
->
stream_index
))
<
0
)
{
program
->
nb_stream_indexes
=
0
;
return
;
program
->
stream_index
=
tmp
;
}
program
->
stream_index
[
program
->
nb_stream_indexes
++
]
=
idx
;
return
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment