Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
7684a361
Commit
7684a361
authored
Aug 02, 2013
by
Alexandra Khirnova
Committed by
Anton Khirnov
Aug 04, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mxfenc: switch to av_reallocp_array() and check allocation errors
Signed-off-by:
Anton Khirnov
<
anton@khirnov.net
>
parent
a10c4ce2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
18 deletions
+29
-18
mxfenc.c
libavformat/mxfenc.c
+29
-18
No files found.
libavformat/mxfenc.c
View file @
7684a361
...
@@ -1182,7 +1182,7 @@ static void mxf_write_klv_fill(AVFormatContext *s)
...
@@ -1182,7 +1182,7 @@ static void mxf_write_klv_fill(AVFormatContext *s)
}
}
}
}
static
void
mxf_write_partition
(
AVFormatContext
*
s
,
int
bodysid
,
static
int
mxf_write_partition
(
AVFormatContext
*
s
,
int
bodysid
,
int
indexsid
,
int
indexsid
,
const
uint8_t
*
key
,
int
write_metadata
)
const
uint8_t
*
key
,
int
write_metadata
)
{
{
...
@@ -1191,6 +1191,7 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid,
...
@@ -1191,6 +1191,7 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid,
int64_t
header_byte_count_offset
;
int64_t
header_byte_count_offset
;
unsigned
index_byte_count
=
0
;
unsigned
index_byte_count
=
0
;
uint64_t
partition_offset
=
avio_tell
(
pb
);
uint64_t
partition_offset
=
avio_tell
(
pb
);
int
err
;
if
(
!
mxf
->
edit_unit_byte_count
&&
mxf
->
edit_units_count
)
if
(
!
mxf
->
edit_unit_byte_count
&&
mxf
->
edit_units_count
)
index_byte_count
=
85
+
12
+
(
s
->
nb_streams
+
1
)
*
6
+
index_byte_count
=
85
+
12
+
(
s
->
nb_streams
+
1
)
*
6
+
...
@@ -1205,10 +1206,11 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid,
...
@@ -1205,10 +1206,11 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid,
}
}
if
(
!
memcmp
(
key
,
body_partition_key
,
16
))
{
if
(
!
memcmp
(
key
,
body_partition_key
,
16
))
{
mxf
->
body_partition_offset
=
if
((
err
=
av_reallocp_array
(
&
mxf
->
body_partition_offset
,
mxf
->
body_partitions_count
+
1
,
av_realloc
(
mxf
->
body_partition_offset
,
sizeof
(
*
mxf
->
body_partition_offset
)))
<
0
)
{
(
mxf
->
body_partitions_count
+
1
)
*
mxf
->
body_partitions_count
=
0
;
sizeof
(
*
mxf
->
body_partition_offset
));
return
err
;
}
mxf
->
body_partition_offset
[
mxf
->
body_partitions_count
++
]
=
partition_offset
;
mxf
->
body_partition_offset
[
mxf
->
body_partitions_count
++
]
=
partition_offset
;
}
}
...
@@ -1273,6 +1275,8 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid,
...
@@ -1273,6 +1275,8 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid,
}
}
avio_flush
(
pb
);
avio_flush
(
pb
);
return
0
;
}
}
static
const
UID
mxf_mpeg2_codec_uls
[]
=
{
static
const
UID
mxf_mpeg2_codec_uls
[]
=
{
...
@@ -1673,13 +1677,14 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
...
@@ -1673,13 +1677,14 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
AVStream
*
st
=
s
->
streams
[
pkt
->
stream_index
];
AVStream
*
st
=
s
->
streams
[
pkt
->
stream_index
];
MXFStreamContext
*
sc
=
st
->
priv_data
;
MXFStreamContext
*
sc
=
st
->
priv_data
;
MXFIndexEntry
ie
=
{
0
};
MXFIndexEntry
ie
=
{
0
};
int
err
;
if
(
!
mxf
->
edit_unit_byte_count
&&
!
(
mxf
->
edit_units_count
%
EDIT_UNITS_PER_BODY
))
{
if
(
!
mxf
->
edit_unit_byte_count
&&
!
(
mxf
->
edit_units_count
%
EDIT_UNITS_PER_BODY
))
{
mxf
->
index_entries
=
av_realloc
(
mxf
->
index_entries
,
if
((
err
=
av_reallocp_array
(
&
mxf
->
index_entries
,
mxf
->
edit_units_count
(
mxf
->
edit_units_count
+
EDIT_UNITS_PER_BODY
)
*
sizeof
(
*
mxf
->
index_entries
));
+
EDIT_UNITS_PER_BODY
,
sizeof
(
*
mxf
->
index_entries
)))
<
0
)
{
if
(
!
mxf
->
index_entries
)
{
mxf
->
edit_units_count
=
0
;
av_log
(
s
,
AV_LOG_ERROR
,
"could not allocate index entries
\n
"
);
av_log
(
s
,
AV_LOG_ERROR
,
"could not allocate index entries
\n
"
);
return
-
1
;
return
err
;
}
}
}
}
...
@@ -1692,11 +1697,13 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
...
@@ -1692,11 +1697,13 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
if
(
!
mxf
->
header_written
)
{
if
(
!
mxf
->
header_written
)
{
if
(
mxf
->
edit_unit_byte_count
)
{
if
(
mxf
->
edit_unit_byte_count
)
{
mxf_write_partition
(
s
,
1
,
2
,
header_open_partition_key
,
1
);
if
((
err
=
mxf_write_partition
(
s
,
1
,
2
,
header_open_partition_key
,
1
))
<
0
)
return
err
;
mxf_write_klv_fill
(
s
);
mxf_write_klv_fill
(
s
);
mxf_write_index_table_segment
(
s
);
mxf_write_index_table_segment
(
s
);
}
else
{
}
else
{
mxf_write_partition
(
s
,
0
,
0
,
header_open_partition_key
,
1
);
if
((
err
=
mxf_write_partition
(
s
,
0
,
0
,
header_open_partition_key
,
1
))
<
0
)
return
err
;
}
}
mxf
->
header_written
=
1
;
mxf
->
header_written
=
1
;
}
}
...
@@ -1706,8 +1713,8 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
...
@@ -1706,8 +1713,8 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
(
!
mxf
->
edit_units_count
||
mxf
->
edit_units_count
>
EDIT_UNITS_PER_BODY
)
&&
(
!
mxf
->
edit_units_count
||
mxf
->
edit_units_count
>
EDIT_UNITS_PER_BODY
)
&&
!
(
ie
.
flags
&
0x33
))
{
// I frame, Gop start
!
(
ie
.
flags
&
0x33
))
{
// I frame, Gop start
mxf_write_klv_fill
(
s
);
mxf_write_klv_fill
(
s
);
mxf_write_partition
(
s
,
1
,
2
,
body_partition_key
,
0
);
if
((
err
=
mxf_write_partition
(
s
,
1
,
2
,
body_partition_key
,
0
))
<
0
)
return
err
;
mxf_write_klv_fill
(
s
);
mxf_write_klv_fill
(
s
);
mxf_write_index_table_segment
(
s
);
mxf_write_index_table_segment
(
s
);
}
}
...
@@ -1776,16 +1783,18 @@ static int mxf_write_footer(AVFormatContext *s)
...
@@ -1776,16 +1783,18 @@ static int mxf_write_footer(AVFormatContext *s)
{
{
MXFContext
*
mxf
=
s
->
priv_data
;
MXFContext
*
mxf
=
s
->
priv_data
;
AVIOContext
*
pb
=
s
->
pb
;
AVIOContext
*
pb
=
s
->
pb
;
int
err
;
mxf
->
duration
=
mxf
->
last_indexed_edit_unit
+
mxf
->
edit_units_count
;
mxf
->
duration
=
mxf
->
last_indexed_edit_unit
+
mxf
->
edit_units_count
;
mxf_write_klv_fill
(
s
);
mxf_write_klv_fill
(
s
);
mxf
->
footer_partition_offset
=
avio_tell
(
pb
);
mxf
->
footer_partition_offset
=
avio_tell
(
pb
);
if
(
mxf
->
edit_unit_byte_count
)
{
// no need to repeat index
if
(
mxf
->
edit_unit_byte_count
)
{
// no need to repeat index
mxf_write_partition
(
s
,
0
,
0
,
footer_partition_key
,
0
);
if
((
err
=
mxf_write_partition
(
s
,
0
,
0
,
footer_partition_key
,
0
))
<
0
)
return
err
;
}
else
{
}
else
{
mxf_write_partition
(
s
,
0
,
2
,
footer_partition_key
,
0
);
if
((
err
=
mxf_write_partition
(
s
,
0
,
2
,
footer_partition_key
,
0
))
<
0
)
return
err
;
mxf_write_klv_fill
(
s
);
mxf_write_klv_fill
(
s
);
mxf_write_index_table_segment
(
s
);
mxf_write_index_table_segment
(
s
);
}
}
...
@@ -1796,11 +1805,13 @@ static int mxf_write_footer(AVFormatContext *s)
...
@@ -1796,11 +1805,13 @@ static int mxf_write_footer(AVFormatContext *s)
if
(
s
->
pb
->
seekable
)
{
if
(
s
->
pb
->
seekable
)
{
avio_seek
(
pb
,
0
,
SEEK_SET
);
avio_seek
(
pb
,
0
,
SEEK_SET
);
if
(
mxf
->
edit_unit_byte_count
)
{
if
(
mxf
->
edit_unit_byte_count
)
{
mxf_write_partition
(
s
,
1
,
2
,
header_closed_partition_key
,
1
);
if
((
err
=
mxf_write_partition
(
s
,
1
,
2
,
header_closed_partition_key
,
1
))
<
0
)
return
err
;
mxf_write_klv_fill
(
s
);
mxf_write_klv_fill
(
s
);
mxf_write_index_table_segment
(
s
);
mxf_write_index_table_segment
(
s
);
}
else
{
}
else
{
mxf_write_partition
(
s
,
0
,
0
,
header_closed_partition_key
,
1
);
if
((
err
=
mxf_write_partition
(
s
,
0
,
0
,
header_closed_partition_key
,
1
))
<
0
)
return
err
;
}
}
}
}
...
...
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