Commit 3c8a2a11 authored by Andreas Rheinhardt's avatar Andreas Rheinhardt Committed by Mark Thompson

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: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
parent a72cc47a
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment