Commit 07941c2c authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '853cc025'

* commit '853cc025':
  mov: store display matrix in a stream side data

Conflicts:
	libavformat/isom.h
	libavformat/mov.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents ef1d4ee2 853cc025
...@@ -145,6 +145,8 @@ typedef struct MOVStreamContext { ...@@ -145,6 +145,8 @@ typedef struct MOVStreamContext {
int nb_frames_for_fps; int nb_frames_for_fps;
int64_t duration_for_fps; int64_t duration_for_fps;
int32_t *display_matrix;
} MOVStreamContext; } MOVStreamContext;
typedef struct MOVContext { typedef struct MOVContext {
......
...@@ -2560,7 +2560,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -2560,7 +2560,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
int width; int width;
int height; int height;
int64_t disp_transform[2]; int64_t disp_transform[2];
int display_matrix[3][2]; int display_matrix[3][3];
AVStream *st; AVStream *st;
MOVStreamContext *sc; MOVStreamContext *sc;
int version; int version;
...@@ -2597,11 +2597,12 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -2597,11 +2597,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) //read in the display matrix (outlined in ISO 14496-12, Section 6.2.2)
// they're kept in fixed point format through all calculations // 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++) { for (i = 0; i < 3; i++) {
display_matrix[i][0] = avio_rb32(pb); // 16.16 fixed point display_matrix[i][0] = avio_rb32(pb); // 16.16 fixed point
display_matrix[i][1] = 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 width = avio_rb32(pb); // 16.16 fixed point track width
...@@ -2624,6 +2625,25 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -2624,6 +2625,25 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_dict_set(&st->metadata, "rotate", "270", 0); av_dict_set(&st->metadata, "rotate", "270", 0);
} }
// 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;
av_freep(&sc->display_matrix);
sc->display_matrix = av_malloc(sizeof(int32_t) * 9);
if (!sc->display_matrix)
return AVERROR(ENOMEM);
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
sc->display_matrix[i * 3 + j] = display_matrix[j][i];
}
// transform the display width/height according to the matrix // transform the display width/height according to the matrix
// skip this if the display matrix is the default identity matrix // skip this if the display matrix is the default identity matrix
// or if it is rotating the picture, ex iPhone 3GS // or if it is rotating the picture, ex iPhone 3GS
...@@ -3395,6 +3415,7 @@ static int mov_read_close(AVFormatContext *s) ...@@ -3395,6 +3415,7 @@ static int mov_read_close(AVFormatContext *s)
av_freep(&sc->stts_data); av_freep(&sc->stts_data);
av_freep(&sc->stps_data); av_freep(&sc->stps_data);
av_freep(&sc->rap_group); av_freep(&sc->rap_group);
av_freep(&sc->display_matrix);
} }
if (mov->dv_demux) { if (mov->dv_demux) {
...@@ -3544,14 +3565,35 @@ static int mov_read_header(AVFormatContext *s) ...@@ -3544,14 +3565,35 @@ static int mov_read_header(AVFormatContext *s)
for (i = 0; i < s->nb_streams; i++) { for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i]; AVStream *st = s->streams[i];
MOVStreamContext *sc = st->priv_data;
if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) switch (st->codec->codec_type) {
continue; case AVMEDIA_TYPE_AUDIO:
err = ff_replaygain_export(st, s->metadata);
err = ff_replaygain_export(st, s->metadata); if (err < 0) {
if (err < 0) { mov_read_close(s);
mov_read_close(s); return err;
return err; }
break;
case AVMEDIA_TYPE_VIDEO:
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 = (uint8_t*)sc->display_matrix;
sc->display_matrix = NULL;
}
break;
} }
} }
......
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