static int mov_metadata_loci(MOVContext *c, AVIOContext *pb, unsigned len)
{
char language[4] = { 0 };
- char buf[100];
+ char buf[200], place[100];
uint16_t langcode = 0;
- double longitude, latitude;
+ double longitude, latitude, altitude;
const char *key = "location";
if (len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
ff_mov_lang_to_iso639(langcode, language);
len -= 6;
- len -= avio_get_str(pb, len, buf, sizeof(buf)); // place name
+ len -= avio_get_str(pb, len, place, sizeof(place));
if (len < 1) {
av_log(c->fc, AV_LOG_ERROR, "place name too long\n");
return AVERROR_INVALIDDATA;
}
longitude = ((int32_t) avio_rb32(pb)) / (float) (1 << 16);
latitude = ((int32_t) avio_rb32(pb)) / (float) (1 << 16);
+ altitude = ((int32_t) avio_rb32(pb)) / (float) (1 << 16);
// Try to output in the same format as the ?xyz field
- snprintf(buf, sizeof(buf), "%+08.4f%+09.4f/", latitude, longitude);
+ snprintf(buf, sizeof(buf), "%+08.4f%+09.4f", latitude, longitude);
+ if (altitude)
+ av_strlcatf(buf, sizeof(buf), "%+f", altitude);
+ av_strlcatf(buf, sizeof(buf), "/%s", place);
+
if (*language && strcmp(language, "und")) {
char key2[16];
snprintf(key2, sizeof(key2), "%s-%s", key, language);
if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) { // MAC Encoded
mov_read_mac_string(c, pb, str_size, str, str_size_alloc);
} else {
- int ret = avio_read(pb, str, str_size);
- if (ret != str_size) {
- av_freep(&str);
- return ret < 0 ? ret : AVERROR_INVALIDDATA;
+ int ret = ffio_read_size(pb, str, str_size);
+ if (ret < 0) {
+ av_free(str);
+ return ret;
}
str[str_size] = 0;
}
int64_t start;
int i, nb_chapters, str_len, version;
char str[256+1];
+ int ret;
if ((atom.size -= 5) < 0)
return 0;
if ((atom.size -= 9+str_len) < 0)
return 0;
- if (avio_read(pb, str, str_len) != str_len)
- return AVERROR_INVALIDDATA;
+ ret = ffio_read_size(pb, str, str_len);
+ if (ret < 0)
+ return ret;
str[str_len] = 0;
avpriv_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str);
}
/* macintosh alias record */
uint16_t volume_len, len;
int16_t type;
+ int ret;
avio_skip(pb, 10);
volume_len = avio_r8(pb);
volume_len = FFMIN(volume_len, 27);
- if (avio_read(pb, dref->volume, 27) != 27)
- return AVERROR_INVALIDDATA;
+ ret = ffio_read_size(pb, dref->volume, 27);
+ if (ret < 0)
+ return ret;
dref->volume[volume_len] = 0;
av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len);
len = avio_r8(pb);
len = FFMIN(len, 63);
- if (avio_read(pb, dref->filename, 63) != 63)
- return AVERROR_INVALIDDATA;
+ ret = ffio_read_size(pb, dref->filename, 63);
+ if (ret < 0)
+ return ret;
dref->filename[len] = 0;
av_log(c->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len);
dref->path = av_mallocz(len+1);
if (!dref->path)
return AVERROR(ENOMEM);
- if (avio_read(pb, dref->path, len) != len) {
+
+ ret = ffio_read_size(pb, dref->path, len);
+ if (ret < 0) {
av_freep(&dref->path);
- return AVERROR_INVALIDDATA;
+ return ret;
}
if (type == 18) // no additional processing needed
continue;
dref->dir = av_malloc(len+1);
if (!dref->dir)
return AVERROR(ENOMEM);
- if (avio_read(pb, dref->dir, len) != len) {
+
+ ret = ffio_read_size(pb, dref->dir, len);
+ if (ret < 0) {
av_freep(&dref->dir);
- return AVERROR_INVALIDDATA;
+ return ret;
}
dref->dir[len] = 0;
for (j = 0; j < len; j++)
uint32_t av_unused ctype;
int64_t title_size;
char *title_str;
+ int ret;
if (c->fc->nb_streams < 1) // meta before first trak
return 0;
title_str = av_malloc(title_size + 1); /* Add null terminator */
if (!title_str)
return AVERROR(ENOMEM);
- if (avio_read(pb, title_str, title_size) != title_size) {
+
+ ret = ffio_read_size(pb, title_str, title_size);
+ if (ret < 0) {
av_freep(&title_str);
- return AVERROR_INVALIDDATA;
+ return ret;
}
title_str[title_size] = 0;
if (title_str[0]) {
int comp_brand_size;
char* comp_brands_str;
uint8_t type[5] = {0};
+ int ret = ffio_read_size(pb, type, 4);
+ if (ret < 0)
+ return ret;
- if (avio_read(pb, type, 4) != 4)
- return AVERROR_INVALIDDATA;
if (strcmp(type, "qt "))
c->isom = 1;
av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type);
comp_brands_str = av_malloc(comp_brand_size + 1); /* Add null terminator */
if (!comp_brands_str)
return AVERROR(ENOMEM);
- if (avio_read(pb, comp_brands_str, comp_brand_size) != comp_brand_size) {
+
+ ret = ffio_read_size(pb, comp_brands_str, comp_brand_size);
+ if (ret < 0) {
av_freep(&comp_brands_str);
- return AVERROR_INVALIDDATA;
+ return ret;
}
comp_brands_str[comp_brand_size] = 0;
av_dict_set(&c->fc->metadata, "compatible_brands", comp_brands_str, 0);
avio_rb32(pb); /* selection duration */
avio_rb32(pb); /* current time */
avio_rb32(pb); /* next track ID */
+
return 0;
}
AVStream *st;
char color_parameter_type[5] = { 0 };
int color_primaries, color_trc, color_matrix;
+ int ret;
if (c->fc->nb_streams < 1)
return 0;
st = c->fc->streams[c->fc->nb_streams - 1];
- if (avio_read(pb, color_parameter_type, 4) != 4)
- return AVERROR_INVALIDDATA;
+ ret = ffio_read_size(pb, color_parameter_type, 4);
+ if (ret < 0)
+ return ret;
if (strncmp(color_parameter_type, "nclx", 4) &&
strncmp(color_parameter_type, "nclc", 4)) {
av_log(c->fc, AV_LOG_WARNING, "unsupported color_parameter_type %s\n",
AV_WB32(buf , atom.size + 8);
AV_WL32(buf + 4, atom.type);
- err = avio_read(pb, buf + 8, atom.size);
+ err = ffio_read_size(pb, buf + 8, atom.size);
if (err < 0) {
codec->extradata_size -= atom.size;
return err;
static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
+ int ret;
if (c->fc->nb_streams < 1)
return 0;
st->codec->codec_id == AV_CODEC_ID_SPEEX) {
// pass all frma atom to codec, needed at least for QDMC and QDM2
av_freep(&st->codec->extradata);
- if (ff_get_extradata(st->codec, pb, atom.size) < 0)
- return AVERROR(ENOMEM);
+ ret = ff_get_extradata(st->codec, pb, atom.size);
+ if (ret < 0)
+ return ret;
} else if (atom.size > 8) { /* to read frma, esds atoms */
- int ret;
if ((ret = mov_read_default(c, pb, atom)) < 0)
return ret;
} else
static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
+ int ret;
if (c->fc->nb_streams < 1)
return 0;
return 0;
}
av_freep(&st->codec->extradata);
- if (ff_get_extradata(st->codec, pb, atom.size) < 0)
- return AVERROR(ENOMEM);
+ ret = ff_get_extradata(st->codec, pb, atom.size);
+ if (ret < 0)
+ return ret;
return 0;
}
avio_seek(pb, 6, SEEK_CUR);
av_freep(&st->codec->extradata);
- if ((ret = ff_get_extradata(st->codec, pb, atom.size - 7)) < 0)
+ ret = ff_get_extradata(st->codec, pb, atom.size - 7);
+ if (ret < 0)
return ret;
return 0;
static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
+ int ret;
if (c->fc->nb_streams < 1)
return 0;
avio_skip(pb, 40);
av_freep(&st->codec->extradata);
- if (ff_get_extradata(st->codec, pb, atom.size - 40) < 0)
- return AVERROR(ENOMEM);
+ ret = ff_get_extradata(st->codec, pb, atom.size - 40);
+ if (ret < 0)
+ return ret;
+
return 0;
}
cr = (ycbcr >> 8) & 0xFF;
cb = ycbcr & 0xFF;
- b = av_clip_uint8(1.164 * (y - 16) + 2.018 * (cb - 128));
- g = av_clip_uint8(1.164 * (y - 16) - 0.813 * (cr - 128) - 0.391 * (cb - 128));
- r = av_clip_uint8(1.164 * (y - 16) + 1.596 * (cr - 128));
+ b = av_clip_uint8((1164 * (y - 16) + 2018 * (cb - 128)) / 1000);
+ g = av_clip_uint8((1164 * (y - 16) - 813 * (cr - 128) - 391 * (cb - 128)) / 1000);
+ r = av_clip_uint8((1164 * (y - 16) + 1596 * (cr - 128) ) / 1000);
return (r << 16) | (g << 8) | b;
}
AVStream *st, MOVStreamContext *sc,
int64_t size)
{
+ int ret;
+
if (st->codec->codec_tag == MKTAG('t','m','c','d')) {
- if ((int)size != size || ff_get_extradata(st->codec, pb, size) < 0)
+ if ((int)size != size)
return AVERROR(ENOMEM);
+
+ ret = ff_get_extradata(st->codec, pb, size);
+ if (ret < 0)
+ return ret;
if (size > 16) {
MOVStreamContext *tmcd_ctx = st->priv_data;
int val;
unsigned int i, entries, sample_size, field_size, num_bytes;
GetBitContext gb;
unsigned char* buf;
+ int ret;
if (c->fc->nb_streams < 1)
return 0;
return AVERROR(ENOMEM);
}
- if (avio_read(pb, buf, num_bytes) < num_bytes) {
+ ret = ffio_read_size(pb, buf, num_bytes);
+ if (ret < 0) {
av_freep(&sc->sample_sizes);
av_free(buf);
- return AVERROR_INVALIDDATA;
+ return ret;
}
init_get_bits(&gb, buf, 8*num_bytes);
sample_count=avio_rb32(pb);
sample_duration = avio_rb32(pb);
- /* sample_duration < 0 is invalid based on the spec */
- if (sample_duration < 0) {
- av_log(c->fc, AV_LOG_ERROR, "Invalid SampleDelta %d in STTS, at %d st:%d\n",
- sample_duration, i, c->fc->nb_streams-1);
- sample_duration = 1;
- }
if (sample_count < 0) {
av_log(c->fc, AV_LOG_ERROR, "Invalid sample_count=%d\n", sample_count);
return AVERROR_INVALIDDATA;
if (entries >= UINT_MAX / sizeof(*sc->ctts_data))
return AVERROR_INVALIDDATA;
av_freep(&sc->ctts_data);
- sc->ctts_data = av_malloc(entries * sizeof(*sc->ctts_data));
+ sc->ctts_data = av_realloc(NULL, entries * sizeof(*sc->ctts_data));
if (!sc->ctts_data)
return AVERROR(ENOMEM);
unsigned int distance = 0;
unsigned int rap_group_index = 0;
unsigned int rap_group_sample = 0;
+ int64_t last_dts = 0;
+ int64_t dts_correction = 0;
int rap_group_present = sc->rap_group_count && sc->rap_group;
int key_off = (sc->keyframe_count && sc->keyframes[0] > 0) || (sc->stps_count && sc->stps_data[0] > 0);
current_dts -= sc->dts_shift;
+ last_dts = current_dts;
if (!sc->sample_count || st->nb_index_entries)
return;
current_offset += sample_size;
stream_size += sample_size;
+
+ /* A negative sample duration is invalid based on the spec,
+ * but some samples need it to correct the DTS. */
+ if (sc->stts_data[stts_index].duration < 0) {
+ av_log(mov->fc, AV_LOG_WARNING,
+ "Invalid SampleDelta %d in STTS, at %d st:%d\n",
+ sc->stts_data[stts_index].duration, stts_index,
+ st->index);
+ dts_correction += sc->stts_data[stts_index].duration - 1;
+ sc->stts_data[stts_index].duration = 1;
+ }
current_dts += sc->stts_data[stts_index].duration;
+ if (!dts_correction || current_dts + dts_correction > last_dts) {
+ current_dts += dts_correction;
+ dts_correction = 0;
+ } else {
+ /* Avoid creating non-monotonous DTS */
+ dts_correction += current_dts - last_dts - 1;
+ current_dts = last_dts + 1;
+ }
+ last_dts = current_dts;
distance++;
stts_sample++;
current_sample++;
for (i = 0; i < 2; i++) {
uint8_t **p;
uint32_t len, tag;
+ int ret;
if (end - avio_tell(pb) <= 12)
break;
*p = av_malloc(len + 1);
if (!*p)
break;
- if (avio_read(pb, *p, len) != len) {
+ ret = ffio_read_size(pb, *p, len);
+ if (ret < 0) {
av_freep(p);
- return AVERROR_INVALIDDATA;
+ return ret;
}
(*p)[len] = 0;
}
av_free(cmov_data);
return AVERROR(ENOMEM);
}
- if (avio_read(pb, cmov_data, cmov_len) != cmov_len) {
- av_freep(&cmov_data);
- av_freep(&moov_data);
- return AVERROR_INVALIDDATA;
- }
+ ret = ffio_read_size(pb, cmov_data, cmov_len);
+ if (ret < 0)
+ goto free_and_return;
+
if (uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
goto free_and_return;
if (ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)