]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '1263b2039eb5aaf1522e9de9f07c787ab30a5f50'
authorClément Bœsch <u@pkh.me>
Fri, 24 Mar 2017 12:29:45 +0000 (13:29 +0100)
committerClément Bœsch <u@pkh.me>
Fri, 24 Mar 2017 12:34:39 +0000 (13:34 +0100)
* commit '1263b2039eb5aaf1522e9de9f07c787ab30a5f50':
  Adjust printf conversion specifiers to match variable signedness

Merged-by: Clément Bœsch <u@pkh.me>
1  2 
libavcodec/dnxhddec.c
libavcodec/dvdec.c
libavcodec/dxv.c
libavcodec/fraps.c
libavcodec/txd.c
libavformat/mov.c
libavformat/rtpdec_jpeg.c
libavformat/rtpdec_xiph.c
libavformat/rtpenc.c
libswscale/tests/swscale.c

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index dbe94e2368c006e6ef2299ec11f5a479c83f29fd,0d7ce3da1a1c0ca41be007d0070b54dbd53566c0..41bf21d8c35eb7bce0a7bf673a08578122ac5aec
@@@ -2631,14 -2155,16 +2631,14 @@@ static int mov_read_stts(MOVContext *c
      avio_rb24(pb); /* flags */
      entries = avio_rb32(pb);
  
-     av_log(c->fc, AV_LOG_TRACE, "track[%i].stts.entries = %i\n",
+     av_log(c->fc, AV_LOG_TRACE, "track[%u].stts.entries = %u\n",
              c->fc->nb_streams-1, entries);
  
 -    if (!entries)
 -        return 0;
 -    if (entries >= UINT_MAX / sizeof(*sc->stts_data))
 -        return AVERROR(EINVAL);
 -
 +    if (sc->stts_data)
 +        av_log(c->fc, AV_LOG_WARNING, "Duplicated STTS atom\n");
      av_free(sc->stts_data);
 -    sc->stts_data = av_malloc(entries * sizeof(*sc->stts_data));
 +    sc->stts_count = 0;
 +    sc->stts_data = av_malloc_array(entries, sizeof(*sc->stts_data));
      if (!sc->stts_data)
          return AVERROR(ENOMEM);
  
@@@ -2710,8 -2215,10 +2710,8 @@@ static int mov_read_ctts(MOVContext *c
      avio_rb24(pb); /* flags */
      entries = avio_rb32(pb);
  
-     av_log(c->fc, AV_LOG_TRACE, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries);
+     av_log(c->fc, AV_LOG_TRACE, "track[%u].ctts.entries = %u\n", c->fc->nb_streams - 1, entries);
  
 -    av_freep(&sc->ctts_data);
 -
      if (!entries)
          return 0;
      if (entries >= UINT_MAX / sizeof(*sc->ctts_data))
@@@ -3425,11 -2372,9 +3425,11 @@@ static void mov_build_index(MOVContext 
                      e->size = sample_size;
                      e->min_distance = distance;
                      e->flags = keyframe ? AVINDEX_KEYFRAME : 0;
-                     av_log(mov->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
-                             "size %d, distance %d, keyframe %d\n", st->index, current_sample,
+                     av_log(mov->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset %"PRIx64", dts %"PRId64", "
 -                           "size %u, distance %u, keyframe %d\n", st->index, current_sample,
 -                           current_offset, current_dts, sample_size, distance, keyframe);
++                            "size %u, distance %u, keyframe %d\n", st->index, current_sample,
 +                            current_offset, current_dts, sample_size, distance, keyframe);
 +                    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100)
 +                        ff_rfps_add_frame(mov->fc, st, current_dts);
                  }
  
                  current_offset += sample_size;
                  }
  
                  if (st->nb_index_entries >= total) {
-                     av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %d\n", total);
+                     av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %u\n", total);
                      return;
                  }
 +                if (size > 0x3FFFFFFF) {
 +                    av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", size);
 +                    return;
 +                }
                  e = &st->index_entries[st->nb_index_entries++];
                  e->pos = current_offset;
                  e->timestamp = current_dts;
@@@ -4302,14 -3016,11 +4302,14 @@@ static int mov_read_trun(MOVContext *c
                                    MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES));
          if (keyframe)
              distance = 0;
 -        av_add_index_entry(st, offset, dts, sample_size, distance,
 -                           keyframe ? AVINDEX_KEYFRAME : 0);
 +        err = av_add_index_entry(st, offset, dts, sample_size, distance,
 +                                 keyframe ? AVINDEX_KEYFRAME : 0);
 +        if (err < 0) {
 +            av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n");
 +        }
-         av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
-                 "size %d, distance %d, keyframe %d\n", st->index, sc->sample_count+i,
+         av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset %"PRIx64", dts %"PRId64", "
 -               "size %u, distance %d, keyframe %d\n", st->index, sc->sample_count+i,
 -               offset, dts, sample_size, distance, keyframe);
++                "size %u, distance %d, keyframe %d\n", st->index, sc->sample_count+i,
 +                offset, dts, sample_size, distance, keyframe);
          distance++;
          dts += sample_duration;
          offset += sample_size;
@@@ -4537,707 -3123,30 +4537,707 @@@ static int mov_read_elst(MOVContext *c
      avio_rb24(pb); /* flags */
      edit_count = avio_rb32(pb); /* entries */
  
 -    if ((uint64_t)edit_count*12+8 > atom.size)
 -        return AVERROR_INVALIDDATA;
 +    if (!edit_count)
 +        return 0;
 +    if (sc->elst_data)
 +        av_log(c->fc, AV_LOG_WARNING, "Duplicated ELST atom\n");
 +    av_free(sc->elst_data);
 +    sc->elst_count = 0;
 +    sc->elst_data = av_malloc_array(edit_count, sizeof(*sc->elst_data));
 +    if (!sc->elst_data)
 +        return AVERROR(ENOMEM);
 +
-     av_log(c->fc, AV_LOG_TRACE, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, edit_count);
++    av_log(c->fc, AV_LOG_TRACE, "track[%u].edit_count = %i\n", c->fc->nb_streams - 1, edit_count);
 +    for (i = 0; i < edit_count && !pb->eof_reached; i++) {
 +        MOVElst *e = &sc->elst_data[i];
  
 -    for (i=0; i<edit_count; i++){
 -        int64_t time;
 -        int64_t duration;
          if (version == 1) {
 -            duration = avio_rb64(pb);
 -            time     = avio_rb64(pb);
 +            e->duration = avio_rb64(pb);
 +            e->time     = avio_rb64(pb);
          } else {
 -            duration = avio_rb32(pb); /* segment duration */
 -            time     = (int32_t)avio_rb32(pb); /* media time */
 +            e->duration = avio_rb32(pb); /* segment duration */
 +            e->time     = (int32_t)avio_rb32(pb); /* media time */
          }
 -        avio_rb32(pb); /* Media rate */
 -        if (i == 0 && time >= -1) {
 -            sc->time_offset = time != -1 ? time : -duration;
 +        e->rate = avio_rb32(pb) / 65536.0;
 +        av_log(c->fc, AV_LOG_TRACE, "duration=%"PRId64" time=%"PRId64" rate=%f\n",
 +               e->duration, e->time, e->rate);
 +
 +        if (e->time < 0 && e->time != -1 &&
 +            c->fc->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
 +            av_log(c->fc, AV_LOG_ERROR, "Track %d, edit %d: Invalid edit list media time=%"PRId64"\n",
 +                   c->fc->nb_streams-1, i, e->time);
 +            return AVERROR_INVALIDDATA;
          }
      }
 +    sc->elst_count = i;
  
 -    if (edit_count > 1)
 -        av_log(c->fc, AV_LOG_WARNING, "multiple edit list entries, "
 -               "a/v desync might occur, patch welcome\n");
 +    return 0;
 +}
 +
 +static int mov_read_tmcd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    MOVStreamContext *sc;
 +
 +    if (c->fc->nb_streams < 1)
 +        return AVERROR_INVALIDDATA;
 +    sc = c->fc->streams[c->fc->nb_streams - 1]->priv_data;
 +    sc->timecode_track = avio_rb32(pb);
 +    return 0;
 +}
 +
 +static int mov_read_st3d(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    AVStream *st;
 +    MOVStreamContext *sc;
 +    enum AVStereo3DType type;
 +    int mode;
 +
 +    if (c->fc->nb_streams < 1)
 +        return 0;
 +
 +    st = c->fc->streams[c->fc->nb_streams - 1];
 +    sc = st->priv_data;
 +
 +    if (atom.size < 5) {
 +        av_log(c->fc, AV_LOG_ERROR, "Empty stereoscopic video box\n");
 +        return AVERROR_INVALIDDATA;
 +    }
 +    avio_skip(pb, 4); /* version + flags */
 +
 +    mode = avio_r8(pb);
 +    switch (mode) {
 +    case 0:
 +        type = AV_STEREO3D_2D;
 +        break;
 +    case 1:
 +        type = AV_STEREO3D_TOPBOTTOM;
 +        break;
 +    case 2:
 +        type = AV_STEREO3D_SIDEBYSIDE;
 +        break;
 +    default:
 +        av_log(c->fc, AV_LOG_WARNING, "Unknown st3d mode value %d\n", mode);
 +        return 0;
 +    }
 +
 +    sc->stereo3d = av_stereo3d_alloc();
 +    if (!sc->stereo3d)
 +        return AVERROR(ENOMEM);
 +
 +    sc->stereo3d->type = type;
 +    return 0;
 +}
 +
 +static int mov_read_sv3d(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    AVStream *st;
 +    MOVStreamContext *sc;
 +    int size, layout;
 +    int32_t yaw, pitch, roll;
 +    uint32_t l = 0, t = 0, r = 0, b = 0;
 +    uint32_t tag, padding = 0;
 +    enum AVSphericalProjection projection;
 +
 +    if (c->fc->nb_streams < 1)
 +        return 0;
 +
 +    st = c->fc->streams[c->fc->nb_streams - 1];
 +    sc = st->priv_data;
 +
 +    if (atom.size < 8) {
 +        av_log(c->fc, AV_LOG_ERROR, "Empty spherical video box\n");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    size = avio_rb32(pb);
 +    if (size <= 12 || size > atom.size)
 +        return AVERROR_INVALIDDATA;
 +
 +    tag = avio_rl32(pb);
 +    if (tag != MKTAG('s','v','h','d')) {
 +        av_log(c->fc, AV_LOG_ERROR, "Missing spherical video header\n");
 +        return 0;
 +    }
 +    avio_skip(pb, 4); /*  version + flags */
 +    avio_skip(pb, size - 12); /* metadata_source */
 +
 +    size = avio_rb32(pb);
 +    if (size > atom.size)
 +        return AVERROR_INVALIDDATA;
 +
 +    tag = avio_rl32(pb);
 +    if (tag != MKTAG('p','r','o','j')) {
 +        av_log(c->fc, AV_LOG_ERROR, "Missing projection box\n");
 +        return 0;
 +    }
 +
 +    size = avio_rb32(pb);
 +    if (size > atom.size)
 +        return AVERROR_INVALIDDATA;
 +
 +    tag = avio_rl32(pb);
 +    if (tag != MKTAG('p','r','h','d')) {
 +        av_log(c->fc, AV_LOG_ERROR, "Missing projection header box\n");
 +        return 0;
 +    }
 +    avio_skip(pb, 4); /*  version + flags */
 +
 +    /* 16.16 fixed point */
 +    yaw   = avio_rb32(pb);
 +    pitch = avio_rb32(pb);
 +    roll  = avio_rb32(pb);
 +
 +    size = avio_rb32(pb);
 +    if (size > atom.size)
 +        return AVERROR_INVALIDDATA;
 +
 +    tag = avio_rl32(pb);
 +    avio_skip(pb, 4); /*  version + flags */
 +    switch (tag) {
 +    case MKTAG('c','b','m','p'):
 +        layout = avio_rb32(pb);
 +        if (layout) {
 +            av_log(c->fc, AV_LOG_WARNING,
 +                   "Unsupported cubemap layout %d\n", layout);
 +            return 0;
 +        }
 +        projection = AV_SPHERICAL_CUBEMAP;
 +        padding = avio_rb32(pb);
 +        break;
 +    case MKTAG('e','q','u','i'):
 +        t = avio_rb32(pb);
 +        b = avio_rb32(pb);
 +        l = avio_rb32(pb);
 +        r = avio_rb32(pb);
 +
 +        if (b >= UINT_MAX - t || r >= UINT_MAX - l) {
 +            av_log(c->fc, AV_LOG_ERROR,
 +                   "Invalid bounding rectangle coordinates "
 +                   "%"PRIu32",%"PRIu32",%"PRIu32",%"PRIu32"\n", l, t, r, b);
 +            return AVERROR_INVALIDDATA;
 +        }
 +
 +        if (l || t || r || b)
 +            projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE;
 +        else
 +            projection = AV_SPHERICAL_EQUIRECTANGULAR;
 +        break;
 +    default:
 +        av_log(c->fc, AV_LOG_ERROR, "Unknown projection type\n");
 +        return 0;
 +    }
 +
 +    sc->spherical = av_spherical_alloc(&sc->spherical_size);
 +    if (!sc->spherical)
 +        return AVERROR(ENOMEM);
 +
 +    sc->spherical->projection = projection;
 +
 +    sc->spherical->yaw   = yaw;
 +    sc->spherical->pitch = pitch;
 +    sc->spherical->roll  = roll;
 +
 +    sc->spherical->padding = padding;
 +
 +    sc->spherical->bound_left   = l;
 +    sc->spherical->bound_top    = t;
 +    sc->spherical->bound_right  = r;
 +    sc->spherical->bound_bottom = b;
  
 -    av_log(c->fc, AV_LOG_TRACE, "track[%u].edit_count = %i\n", c->fc->nb_streams - 1, edit_count);
 +    return 0;
 +}
 +
 +static int mov_parse_uuid_spherical(MOVStreamContext *sc, AVIOContext *pb, size_t len)
 +{
 +    int ret = 0;
 +    uint8_t *buffer = av_malloc(len + 1);
 +    const char *val;
 +
 +    if (!buffer)
 +        return AVERROR(ENOMEM);
 +    buffer[len] = '\0';
 +
 +    ret = ffio_read_size(pb, buffer, len);
 +    if (ret < 0)
 +        goto out;
 +
 +    /* Check for mandatory keys and values, try to support XML as best-effort */
 +    if (av_stristr(buffer, "<GSpherical:StitchingSoftware>") &&
 +        (val = av_stristr(buffer, "<GSpherical:Spherical>")) &&
 +        av_stristr(val, "true") &&
 +        (val = av_stristr(buffer, "<GSpherical:Stitched>")) &&
 +        av_stristr(val, "true") &&
 +        (val = av_stristr(buffer, "<GSpherical:ProjectionType>")) &&
 +        av_stristr(val, "equirectangular")) {
 +        sc->spherical = av_spherical_alloc(&sc->spherical_size);
 +        if (!sc->spherical)
 +            goto out;
 +
 +        sc->spherical->projection = AV_SPHERICAL_EQUIRECTANGULAR;
 +
 +        if (av_stristr(buffer, "<GSpherical:StereoMode>")) {
 +            enum AVStereo3DType mode;
 +
 +            if (av_stristr(buffer, "left-right"))
 +                mode = AV_STEREO3D_SIDEBYSIDE;
 +            else if (av_stristr(buffer, "top-bottom"))
 +                mode = AV_STEREO3D_TOPBOTTOM;
 +            else
 +                mode = AV_STEREO3D_2D;
 +
 +            sc->stereo3d = av_stereo3d_alloc();
 +            if (!sc->stereo3d)
 +                goto out;
 +
 +            sc->stereo3d->type = mode;
 +        }
 +
 +        /* orientation */
 +        val = av_stristr(buffer, "<GSpherical:InitialViewHeadingDegrees>");
 +        if (val)
 +            sc->spherical->yaw = strtol(val, NULL, 10) * (1 << 16);
 +        val = av_stristr(buffer, "<GSpherical:InitialViewPitchDegrees>");
 +        if (val)
 +            sc->spherical->pitch = strtol(val, NULL, 10) * (1 << 16);
 +        val = av_stristr(buffer, "<GSpherical:InitialViewRollDegrees>");
 +        if (val)
 +            sc->spherical->roll = strtol(val, NULL, 10) * (1 << 16);
 +    }
 +
 +out:
 +    av_free(buffer);
 +    return ret;
 +}
 +
 +static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    AVStream *st;
 +    MOVStreamContext *sc;
 +    int64_t ret;
 +    uint8_t uuid[16];
 +    static const uint8_t uuid_isml_manifest[] = {
 +        0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
 +        0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
 +    };
 +    static const uint8_t uuid_xmp[] = {
 +        0xbe, 0x7a, 0xcf, 0xcb, 0x97, 0xa9, 0x42, 0xe8,
 +        0x9c, 0x71, 0x99, 0x94, 0x91, 0xe3, 0xaf, 0xac
 +    };
 +    static const uint8_t uuid_spherical[] = {
 +        0xff, 0xcc, 0x82, 0x63, 0xf8, 0x55, 0x4a, 0x93,
 +        0x88, 0x14, 0x58, 0x7a, 0x02, 0x52, 0x1f, 0xdd,
 +    };
 +
 +    if (atom.size < sizeof(uuid) || atom.size >= FFMIN(INT_MAX, SIZE_MAX))
 +        return AVERROR_INVALIDDATA;
 +
 +    if (c->fc->nb_streams < 1)
 +        return 0;
 +    st = c->fc->streams[c->fc->nb_streams - 1];
 +    sc = st->priv_data;
 +
 +    ret = avio_read(pb, uuid, sizeof(uuid));
 +    if (ret < 0) {
 +        return ret;
 +    } else if (ret != sizeof(uuid)) {
 +        return AVERROR_INVALIDDATA;
 +    }
 +    if (!memcmp(uuid, uuid_isml_manifest, sizeof(uuid))) {
 +        uint8_t *buffer, *ptr;
 +        char *endptr;
 +        size_t len = atom.size - sizeof(uuid);
 +
 +        if (len < 4) {
 +            return AVERROR_INVALIDDATA;
 +        }
 +        ret = avio_skip(pb, 4); // zeroes
 +        len -= 4;
 +
 +        buffer = av_mallocz(len + 1);
 +        if (!buffer) {
 +            return AVERROR(ENOMEM);
 +        }
 +        ret = avio_read(pb, buffer, len);
 +        if (ret < 0) {
 +            av_free(buffer);
 +            return ret;
 +        } else if (ret != len) {
 +            av_free(buffer);
 +            return AVERROR_INVALIDDATA;
 +        }
 +
 +        ptr = buffer;
 +        while ((ptr = av_stristr(ptr, "systemBitrate=\""))) {
 +            ptr += sizeof("systemBitrate=\"") - 1;
 +            c->bitrates_count++;
 +            c->bitrates = av_realloc_f(c->bitrates, c->bitrates_count, sizeof(*c->bitrates));
 +            if (!c->bitrates) {
 +                c->bitrates_count = 0;
 +                av_free(buffer);
 +                return AVERROR(ENOMEM);
 +            }
 +            errno = 0;
 +            ret = strtol(ptr, &endptr, 10);
 +            if (ret < 0 || errno || *endptr != '"') {
 +                c->bitrates[c->bitrates_count - 1] = 0;
 +            } else {
 +                c->bitrates[c->bitrates_count - 1] = ret;
 +            }
 +        }
 +
 +        av_free(buffer);
 +    } else if (!memcmp(uuid, uuid_xmp, sizeof(uuid))) {
 +        uint8_t *buffer;
 +        size_t len = atom.size - sizeof(uuid);
 +        if (c->export_xmp) {
 +            buffer = av_mallocz(len + 1);
 +            if (!buffer) {
 +                return AVERROR(ENOMEM);
 +            }
 +            ret = avio_read(pb, buffer, len);
 +            if (ret < 0) {
 +                av_free(buffer);
 +                return ret;
 +            } else if (ret != len) {
 +                av_free(buffer);
 +                return AVERROR_INVALIDDATA;
 +            }
 +            buffer[len] = '\0';
 +            av_dict_set(&c->fc->metadata, "xmp", buffer, 0);
 +            av_free(buffer);
 +        } else {
 +            // skip all uuid atom, which makes it fast for long uuid-xmp file
 +            ret = avio_skip(pb, len);
 +            if (ret < 0)
 +                return ret;
 +        }
 +    } else if (!memcmp(uuid, uuid_spherical, sizeof(uuid))) {
 +        size_t len = atom.size - sizeof(uuid);
 +        ret = mov_parse_uuid_spherical(sc, pb, len);
 +        if (ret < 0)
 +            return ret;
 +        if (!sc->spherical)
 +            av_log(c->fc, AV_LOG_WARNING, "Invalid spherical metadata found\n");    }
 +
 +    return 0;
 +}
 +
 +static int mov_read_free(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    int ret;
 +    uint8_t content[16];
 +
 +    if (atom.size < 8)
 +        return 0;
 +
 +    ret = avio_read(pb, content, FFMIN(sizeof(content), atom.size));
 +    if (ret < 0)
 +        return ret;
 +
 +    if (   !c->found_moov
 +        && !c->found_mdat
 +        && !memcmp(content, "Anevia\x1A\x1A", 8)
 +        && c->use_mfra_for == FF_MOV_FLAG_MFRA_AUTO) {
 +        c->use_mfra_for = FF_MOV_FLAG_MFRA_PTS;
 +    }
 +
 +    return 0;
 +}
 +
 +static int mov_read_frma(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    uint32_t format = avio_rl32(pb);
 +    MOVStreamContext *sc;
 +    enum AVCodecID id;
 +    AVStream *st;
 +
 +    if (c->fc->nb_streams < 1)
 +        return 0;
 +    st = c->fc->streams[c->fc->nb_streams - 1];
 +    sc = st->priv_data;
 +
 +    switch (sc->format)
 +    {
 +    case MKTAG('e','n','c','v'):        // encrypted video
 +    case MKTAG('e','n','c','a'):        // encrypted audio
 +        id = mov_codec_id(st, format);
 +        if (st->codecpar->codec_id != AV_CODEC_ID_NONE &&
 +            st->codecpar->codec_id != id) {
 +            av_log(c->fc, AV_LOG_WARNING,
 +                   "ignoring 'frma' atom of '%.4s', stream has codec id %d\n",
 +                   (char*)&format, st->codecpar->codec_id);
 +            break;
 +        }
 +
 +        st->codecpar->codec_id = id;
 +        sc->format = format;
 +        break;
 +
 +    default:
 +        if (format != sc->format) {
 +            av_log(c->fc, AV_LOG_WARNING,
 +                   "ignoring 'frma' atom of '%.4s', stream format is '%.4s'\n",
 +                   (char*)&format, (char*)&sc->format);
 +        }
 +        break;
 +    }
 +
 +    return 0;
 +}
 +
 +static int mov_read_senc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    AVStream *st;
 +    MOVStreamContext *sc;
 +    size_t auxiliary_info_size;
 +
 +    if (c->decryption_key_len == 0 || c->fc->nb_streams < 1)
 +        return 0;
 +
 +    st = c->fc->streams[c->fc->nb_streams - 1];
 +    sc = st->priv_data;
 +
 +    if (sc->cenc.aes_ctr) {
 +        av_log(c->fc, AV_LOG_ERROR, "duplicate senc atom\n");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    avio_r8(pb); /* version */
 +    sc->cenc.use_subsamples = avio_rb24(pb) & 0x02; /* flags */
 +
 +    avio_rb32(pb);        /* entries */
 +
 +    if (atom.size < 8 || atom.size > FFMIN(INT_MAX, SIZE_MAX)) {
 +        av_log(c->fc, AV_LOG_ERROR, "senc atom size %"PRId64" invalid\n", atom.size);
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    /* save the auxiliary info as is */
 +    auxiliary_info_size = atom.size - 8;
 +
 +    sc->cenc.auxiliary_info = av_malloc(auxiliary_info_size);
 +    if (!sc->cenc.auxiliary_info) {
 +        return AVERROR(ENOMEM);
 +    }
 +
 +    sc->cenc.auxiliary_info_end = sc->cenc.auxiliary_info + auxiliary_info_size;
 +    sc->cenc.auxiliary_info_pos = sc->cenc.auxiliary_info;
 +    sc->cenc.auxiliary_info_index = 0;
 +
 +    if (avio_read(pb, sc->cenc.auxiliary_info, auxiliary_info_size) != auxiliary_info_size) {
 +        av_log(c->fc, AV_LOG_ERROR, "failed to read the auxiliary info");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    /* initialize the cipher */
 +    sc->cenc.aes_ctr = av_aes_ctr_alloc();
 +    if (!sc->cenc.aes_ctr) {
 +        return AVERROR(ENOMEM);
 +    }
 +
 +    return av_aes_ctr_init(sc->cenc.aes_ctr, c->decryption_key);
 +}
 +
 +static int mov_read_saiz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    AVStream *st;
 +    MOVStreamContext *sc;
 +    size_t data_size;
 +    int atom_header_size;
 +    int flags;
 +
 +    if (c->decryption_key_len == 0 || c->fc->nb_streams < 1)
 +        return 0;
 +
 +    st = c->fc->streams[c->fc->nb_streams - 1];
 +    sc = st->priv_data;
 +
 +    if (sc->cenc.auxiliary_info_sizes || sc->cenc.auxiliary_info_default_size) {
 +        av_log(c->fc, AV_LOG_ERROR, "duplicate saiz atom\n");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    atom_header_size = 9;
 +
 +    avio_r8(pb); /* version */
 +    flags = avio_rb24(pb);
 +
 +    if ((flags & 0x01) != 0) {
 +        atom_header_size += 8;
 +
 +        avio_rb32(pb);    /* info type */
 +        avio_rb32(pb);    /* info type param */
 +    }
 +
 +    sc->cenc.auxiliary_info_default_size = avio_r8(pb);
 +    avio_rb32(pb);    /* entries */
 +
 +    if (atom.size <= atom_header_size) {
 +        return 0;
 +    }
 +
 +    if (atom.size > FFMIN(INT_MAX, SIZE_MAX)) {
 +        av_log(c->fc, AV_LOG_ERROR, "saiz atom auxiliary_info_sizes size %"PRId64" invalid\n", atom.size);
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    /* save the auxiliary info sizes as is */
 +    data_size = atom.size - atom_header_size;
 +
 +    sc->cenc.auxiliary_info_sizes = av_malloc(data_size);
 +    if (!sc->cenc.auxiliary_info_sizes) {
 +        return AVERROR(ENOMEM);
 +    }
 +
 +    sc->cenc.auxiliary_info_sizes_count = data_size;
 +
 +    if (avio_read(pb, sc->cenc.auxiliary_info_sizes, data_size) != data_size) {
 +        av_log(c->fc, AV_LOG_ERROR, "failed to read the auxiliary info sizes");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    return 0;
 +}
 +
 +static int mov_read_dfla(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 +{
 +    AVStream *st;
 +    int last, type, size, ret;
 +    uint8_t buf[4];
 +
 +    if (c->fc->nb_streams < 1)
 +        return 0;
 +    st = c->fc->streams[c->fc->nb_streams-1];
 +
 +    if ((uint64_t)atom.size > (1<<30) || atom.size < 42)
 +        return AVERROR_INVALIDDATA;
 +
 +    /* Check FlacSpecificBox version. */
 +    if (avio_r8(pb) != 0)
 +        return AVERROR_INVALIDDATA;
 +
 +    avio_rb24(pb); /* Flags */
 +
 +    avio_read(pb, buf, sizeof(buf));
 +    flac_parse_block_header(buf, &last, &type, &size);
 +
 +    if (type != FLAC_METADATA_TYPE_STREAMINFO || size != FLAC_STREAMINFO_SIZE) {
 +        av_log(c->fc, AV_LOG_ERROR, "STREAMINFO must be first FLACMetadataBlock\n");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    ret = ff_get_extradata(c->fc, st->codecpar, pb, size);
 +    if (ret < 0)
 +        return ret;
 +
 +    if (!last)
 +        av_log(c->fc, AV_LOG_WARNING, "non-STREAMINFO FLACMetadataBlock(s) ignored\n");
 +
 +    return 0;
 +}
 +
 +static int mov_seek_auxiliary_info(MOVContext *c, MOVStreamContext *sc, int64_t index)
 +{
 +    size_t auxiliary_info_seek_offset = 0;
 +    int i;
 +
 +    if (sc->cenc.auxiliary_info_default_size) {
 +        auxiliary_info_seek_offset = (size_t)sc->cenc.auxiliary_info_default_size * index;
 +    } else if (sc->cenc.auxiliary_info_sizes) {
 +        if (index > sc->cenc.auxiliary_info_sizes_count) {
 +            av_log(c, AV_LOG_ERROR, "current sample %"PRId64" greater than the number of auxiliary info sample sizes %"SIZE_SPECIFIER"\n",
 +                index, sc->cenc.auxiliary_info_sizes_count);
 +            return AVERROR_INVALIDDATA;
 +        }
 +
 +        for (i = 0; i < index; i++) {
 +            auxiliary_info_seek_offset += sc->cenc.auxiliary_info_sizes[i];
 +        }
 +    }
 +
 +    if (auxiliary_info_seek_offset > sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info) {
 +        av_log(c, AV_LOG_ERROR, "auxiliary info offset %"SIZE_SPECIFIER" greater than auxiliary info size %"SIZE_SPECIFIER"\n",
 +            auxiliary_info_seek_offset, (size_t)(sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info));
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    sc->cenc.auxiliary_info_pos = sc->cenc.auxiliary_info + auxiliary_info_seek_offset;
 +    sc->cenc.auxiliary_info_index = index;
 +    return 0;
 +}
 +
 +static int cenc_filter(MOVContext *c, MOVStreamContext *sc, int64_t index, uint8_t *input, int size)
 +{
 +    uint32_t encrypted_bytes;
 +    uint16_t subsample_count;
 +    uint16_t clear_bytes;
 +    uint8_t* input_end = input + size;
 +    int ret;
 +
 +    if (index != sc->cenc.auxiliary_info_index) {
 +        ret = mov_seek_auxiliary_info(c, sc, index);
 +        if (ret < 0) {
 +            return ret;
 +        }
 +    }
 +
 +    /* read the iv */
 +    if (AES_CTR_IV_SIZE > sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info_pos) {
 +        av_log(c->fc, AV_LOG_ERROR, "failed to read iv from the auxiliary info\n");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    av_aes_ctr_set_iv(sc->cenc.aes_ctr, sc->cenc.auxiliary_info_pos);
 +    sc->cenc.auxiliary_info_pos += AES_CTR_IV_SIZE;
 +
 +    if (!sc->cenc.use_subsamples)
 +    {
 +        /* decrypt the whole packet */
 +        av_aes_ctr_crypt(sc->cenc.aes_ctr, input, input, size);
 +        return 0;
 +    }
 +
 +    /* read the subsample count */
 +    if (sizeof(uint16_t) > sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info_pos) {
 +        av_log(c->fc, AV_LOG_ERROR, "failed to read subsample count from the auxiliary info\n");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    subsample_count = AV_RB16(sc->cenc.auxiliary_info_pos);
 +    sc->cenc.auxiliary_info_pos += sizeof(uint16_t);
 +
 +    for (; subsample_count > 0; subsample_count--)
 +    {
 +        if (6 > sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info_pos) {
 +            av_log(c->fc, AV_LOG_ERROR, "failed to read subsample from the auxiliary info\n");
 +            return AVERROR_INVALIDDATA;
 +        }
 +
 +        /* read the number of clear / encrypted bytes */
 +        clear_bytes = AV_RB16(sc->cenc.auxiliary_info_pos);
 +        sc->cenc.auxiliary_info_pos += sizeof(uint16_t);
 +        encrypted_bytes = AV_RB32(sc->cenc.auxiliary_info_pos);
 +        sc->cenc.auxiliary_info_pos += sizeof(uint32_t);
 +
 +        if ((uint64_t)clear_bytes + encrypted_bytes > input_end - input) {
 +            av_log(c->fc, AV_LOG_ERROR, "subsample size exceeds the packet size left\n");
 +            return AVERROR_INVALIDDATA;
 +        }
 +
 +        /* skip the clear bytes */
 +        input += clear_bytes;
 +
 +        /* decrypt the encrypted bytes */
 +        av_aes_ctr_crypt(sc->cenc.aes_ctr, input, input, encrypted_bytes);
 +        input += encrypted_bytes;
 +    }
 +
 +    if (input < input_end) {
 +        av_log(c->fc, AV_LOG_ERROR, "leftover packet bytes after subsample processing\n");
 +        return AVERROR_INVALIDDATA;
 +    }
 +
 +    sc->cenc.auxiliary_info_index++;
      return 0;
  }
  
index 397b5cf56c3fbba4b4eea26fb9310d60a1ae4f77,2cf41139c3794bc62b6bd2c6da184529bb4fcce5..05dd17205c9903cd61b105cfa8e8130dec641fdb
@@@ -236,18 -229,8 +236,18 @@@ static int jpeg_parse_packet(AVFormatCo
      buf += 8;
      len -= 8;
  
 +    if (type & 0x40) {
 +        if (len < 4) {
 +            av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
 +            return AVERROR_INVALIDDATA;
 +        }
 +        dri = AV_RB16(buf);
 +        buf += 4;
 +        len -= 4;
 +        type &= ~0x40;
 +    }
      if (type > 1) {
-         av_log(ctx, AV_LOG_ERROR, "Unimplemented RTP/JPEG type %d\n", type);
+         av_log(ctx, AV_LOG_ERROR, "Unimplemented RTP/JPEG type %"PRIu8"\n", type);
          return AVERROR_PATCHWELCOME;
      }
  
index 26aef54e1d87ecc2dc965ff221e8dc121d8e5f28,7821686983e1a95d2cf0b57a427d7f989e585aea..e1b79903f6ae4a305016ab7122ca093297c1a6bc
@@@ -255,7 -255,7 +255,7 @@@ parse_packed_headers(AVFormatContext *s
      if (packed_headers_end - packed_headers != length ||
          length1 > length || length2 > length - length1) {
          av_log(s, AV_LOG_ERROR,
-                "Bad packed header lengths (%d,%d,%"PTRDIFF_SPECIFIER",%d)\n", length1,
 -               "Bad packed header lengths (%u,%u,%td,%u)\n", length1,
++               "Bad packed header lengths (%d,%d,%"PTRDIFF_SPECIFIER",%u)\n", length1,
                 length2, packed_headers_end - packed_headers, length);
          return AVERROR_INVALIDDATA;
      }
Simple merge
index da6a41b779c85591aa0baeb5619418acb54d0919,853a8a723175431a4e8370a10e6b774606564630..bd8d098a3dbff20e3d13adc1f2bf80a761d21b0c
@@@ -318,7 -305,7 +318,7 @@@ static int fileTest(uint8_t *ref[4], in
  
          ret = sscanf(buf,
                       " %12s %dx%d -> %12s %dx%d flags=%d CRC=%x"
-                      " SSD=%"SCNd64 ", %"SCNd64 ", %"SCNd64 ", %"SCNd64 "\n",
 -                     " SSD=%"PRIu64 ", %"PRIu64 ", %"PRIu64 ", %"PRIu64 "\n",
++                     " SSD=%"SCNu64 ", %"SCNu64 ", %"SCNu64 ", %"SCNu64 "\n",
                       srcStr, &srcW, &srcH, dstStr, &dstW, &dstH,
                       &flags, &r.crc, &r.ssdY, &r.ssdU, &r.ssdV, &r.ssdA);
          if (ret != 12) {