On 2014-05-15 22:06:50 -0400, Vittorio Giovara wrote:
> ---
> libavformat/isom.h | 2 ++
> libavformat/mov.c | 42 +++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 41 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index bf0792c..b2d5574 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -135,6 +135,8 @@ typedef struct MOVStreamContext {
> int64_t track_end; ///< used for dts generation in fragmented movie
> files
> unsigned int rap_group_count;
> MOVSbgp *rap_group;
> +
> + int32_t *display_matrix;
> } MOVStreamContext;
>
> typedef struct MOVContext {
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index e3dc67b..5e45882 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -2344,7 +2344,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext
> *pb, MOVAtom atom)
> int width;
> int height;
> int64_t disp_transform[2];
> - int display_matrix[3][2];
> + int display_matrix[3][3];
> AVStream *st;
> MOVStreamContext *sc;
> int version;
> @@ -2381,11 +2381,12 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext
> *pb, MOVAtom atom)
>
> //read in the display matrix (outlined in ISO 14496-12, Section 6.2.2)
> // they're kept in fixed point format through all calculations
> - // ignore u,v,z b/c we don't need the scale factor to calc aspect ratio
> + // save u,v,z to store the whole matrix in the AV_PKT_DATA_DISPLAYMATRIX
> + // side data, but the scale factor is not needed to calculate aspect
> ratio
> for (i = 0; i < 3; i++) {
> display_matrix[i][0] = avio_rb32(pb); // 16.16 fixed point
> display_matrix[i][1] = avio_rb32(pb); // 16.16 fixed point
> - avio_rb32(pb); // 2.30 fixed point (not used)
> + display_matrix[i][2] = avio_rb32(pb); // 2.30 fixed point
> }
>
> width = avio_rb32(pb); // 16.16 fixed point track width
> @@ -2393,6 +2394,20 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext
> *pb, MOVAtom atom)
> sc->width = width >> 16;
> sc->height = height >> 16;
>
> + // save the matrix when it is not the default identity
> + if (display_matrix[0][0] != (1 << 16) ||
> + display_matrix[1][1] != (1 << 16) ||
> + display_matrix[2][2] != (1 << 30) ||
> + display_matrix[0][1] || display_matrix[0][2] ||
> + display_matrix[1][0] || display_matrix[1][2] ||
> + display_matrix[2][0] || display_matrix[2][1]) {
> + int i, j, k = 0;
> + sc->display_matrix = av_malloc(sizeof(int32_t) * 9);
> + for (i = 0; i < 3; i++)
> + for (j = 0; j < 3; j++)
> + sc->display_matrix[k++] = display_matrix[j][i];
> + }
> +
> // transform the display width/height according to the matrix
> // skip this if the display matrix is the default identity matrix
> // or if it is rotating the picture, ex iPhone 3GS
> @@ -3134,6 +3149,27 @@ static int mov_read_packet(AVFormatContext *s,
> AVPacket *pkt)
> sc->has_palette = 0;
> }
> }
> + if (sc->display_matrix) {
> + AVPacketSideData *sd, *tmp;
> +
> + tmp = av_realloc_array(st->side_data,
> + st->nb_side_data + 1, sizeof(*tmp));
> + if (!tmp)
> + return AVERROR(ENOMEM);
> +
> + st->side_data = tmp;
> + st->nb_side_data++;
> +
> + sd = &st->side_data[st->nb_side_data - 1];
> + sd->type = AV_PKT_DATA_DISPLAYMATRIX;
> + sd->size = sizeof(int32_t) * 9;
> + sd->data = av_malloc(sd->size);
> + if (!sd->data)
> + return AVERROR(ENOMEM);
> +
> + memcpy(sd->data, sc->display_matrix, sd->size);
> + av_freep(&sc->display_matrix);
no need for malloc and memcpy, just assign sc->display_matrix to sd->data
and set sc->display_matrix to NULL
ok otherwise
Janne
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel