aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-06-17 05:42:14 +0200
committerMark Thompson <sw@jkqxz.net>2019-07-07 22:17:07 +0100
commit3c8a2a1180f03ca6b299ebc27eef21ae86635ca0 (patch)
treec0290cabe814ad0ec3191d79dfda82d1ad6b110e /libavcodec
parenta72cc47a275a62c9a36f9df8c912e6f1cd820fc7 (diff)
downloadffmpeg-3c8a2a1180f03ca6b299ebc27eef21ae86635ca0.tar.gz
h264_metadata: Localize code for display orientation
The recent changes to h264_metadata (enabled by the recent changes to ff_cbs_write_packet) made it possible to add side_data to the output packet at any place, not only after the output packet has been written and the properties of the input packet copied. This means that one can now localize the code to add display orientation side-data to the packet to the place dealing with said display-orientation. Furthermore, the documentation of av_display_rotation_set states that the matrix will be fully overwritten by it, so there is no need to allocate it with av_mallocz. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/h264_metadata_bsf.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 18c5ae807d..f7ca1f0f09 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -289,8 +289,6 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
CodedBitstreamFragment *au = &ctx->access_unit;
int err, i, j, has_sps;
H264RawAUD aud;
- uint8_t *displaymatrix_side_data = NULL;
- size_t displaymatrix_side_data_size = 0;
err = ff_bsf_get_packet_ref(bsf, pkt);
if (err < 0)
@@ -487,7 +485,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
continue;
}
- matrix = av_mallocz(9 * sizeof(int32_t));
+ matrix = av_malloc(9 * sizeof(int32_t));
if (!matrix) {
err = AVERROR(ENOMEM);
goto fail;
@@ -499,11 +497,17 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
av_display_matrix_flip(matrix, disp->hor_flip, disp->ver_flip);
// If there are multiple display orientation messages in an
- // access unit then ignore all but the first one.
- av_freep(&displaymatrix_side_data);
-
- displaymatrix_side_data = (uint8_t*)matrix;
- displaymatrix_side_data_size = 9 * sizeof(int32_t);
+ // access unit, then the last one added to the packet (i.e.
+ // the first one in the access unit) will prevail.
+ err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX,
+ (uint8_t*)matrix,
+ 9 * sizeof(int32_t));
+ if (err < 0) {
+ av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted "
+ "displaymatrix side data to packet.\n");
+ av_freep(matrix);
+ goto fail;
+ }
}
}
}
@@ -583,24 +587,11 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
goto fail;
}
- if (displaymatrix_side_data) {
- err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX,
- displaymatrix_side_data,
- displaymatrix_side_data_size);
- if (err) {
- av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted "
- "displaymatrix side data to packet.\n");
- goto fail;
- }
- displaymatrix_side_data = NULL;
- }
-
ctx->done_first_au = 1;
err = 0;
fail:
ff_cbs_fragment_reset(ctx->cbc, au);
- av_freep(&displaymatrix_side_data);
if (err < 0)
av_packet_unref(pkt);