int64_t size; /* total size (excluding the size and type fields) */
} MOV_atom_t;
-typedef struct {
- offset_t offset;
- int64_t size;
-} MOV_mdat_t;
-
struct MOVParseTableEntry;
typedef struct MOVStreamContext {
unsigned int samples_per_frame;
int dv_audio_container;
int pseudo_stream_id;
+ int16_t audio_cid; ///< stsd audio compression id
} MOVStreamContext;
typedef struct MOVContext {
int found_moov; /* when both 'moov' and 'mdat' sections has been found */
int found_mdat; /* we suppose we have enough data to read the file */
AVPaletteControl palette_control;
- MOV_mdat_t *mdat_list;
- int mdat_count;
DVDemuxContext *dv_demux;
AVFormatContext *dv_fctx;
int isom; /* 1 if file is ISO Media (mp4/3gp) */
{
if(atom.size == 0) /* wrong one (MP4) */
return 0;
- c->mdat_list = av_realloc(c->mdat_list, (c->mdat_count + 1) * sizeof(*c->mdat_list));
- c->mdat_list[c->mdat_count].offset = atom.offset;
- c->mdat_list[c->mdat_count].size = atom.size;
- c->mdat_count++;
c->found_mdat=1;
if(c->found_moov)
return 1; /* found both, just go */
st->codec->channels = get_be16(pb); /* channel count */
dprintf(c->fc, "audio channels %d\n", st->codec->channels);
st->codec->bits_per_sample = get_be16(pb); /* sample size */
- /* do we need to force to 16 for AMR ? */
- /* handle specific s8 codec */
- get_be16(pb); /* compression id = 0*/
+ sc->audio_cid = get_be16(pb);
get_be16(pb); /* packet size = 0 */
st->codec->sample_rate = ((get_be32(pb) >> 16));
else if (st->codec->bits_per_sample == 24)
st->codec->codec_id = CODEC_ID_PCM_S24BE;
break;
+ /* set values for old format before stsd version 1 appeared */
+ case CODEC_ID_MACE3:
+ sc->samples_per_frame = 6;
+ sc->bytes_per_frame = 2*st->codec->channels;
+ break;
+ case CODEC_ID_MACE6:
+ sc->samples_per_frame = 6;
+ sc->bytes_per_frame = 1*st->codec->channels;
+ break;
+ case CODEC_ID_ADPCM_IMA_QT:
+ sc->samples_per_frame = 64;
+ sc->bytes_per_frame = 34*st->codec->channels;
+ break;
default:
break;
}
edit_count= sc->edit_count = get_be32(pb); /* entries */
for(i=0; i<edit_count; i++){
+ int time;
get_be32(pb); /* Track duration */
- get_be32(pb); /* Media time */
+ time = get_be32(pb); /* Media time */
get_be32(pb); /* Media rate */
+ if (time != 0)
+ av_log(c->fc, AV_LOG_WARNING, "edit list not starting at 0, "
+ "a/v desync might occur, patch welcome\n");
}
dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, sc->edit_count);
return 0;
unsigned int stts_index = 0;
unsigned int stsc_index = 0;
unsigned int stss_index = 0;
- unsigned int i, j, k;
+ unsigned int i, j;
- if (sc->sample_sizes || st->codec->codec_type == CODEC_TYPE_VIDEO || sc->dv_audio_container) {
+ if (sc->sample_sizes || st->codec->codec_type == CODEC_TYPE_VIDEO ||
+ sc->audio_cid == -2) {
unsigned int current_sample = 0;
unsigned int stts_sample = 0;
unsigned int keyframe, sample_size;
}
} else { /* read whole chunk */
unsigned int chunk_samples, chunk_size, chunk_duration;
+ unsigned int frames = 1;
for (i = 0; i < sc->chunk_count; i++) {
current_offset = sc->chunk_offsets[i];
if (stsc_index + 1 < sc->sample_to_chunk_sz &&
i + 1 == sc->sample_to_chunk[stsc_index + 1].first)
stsc_index++;
chunk_samples = sc->sample_to_chunk[stsc_index].count;
- /* get chunk size */
- if (sc->sample_size > 1 ||
- st->codec->codec_id == CODEC_ID_PCM_U8 || st->codec->codec_id == CODEC_ID_PCM_S8)
- chunk_size = chunk_samples * sc->sample_size;
- else if (sc->samples_per_frame > 0 &&
- (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0))
- chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame;
- else { /* workaround to find nearest next chunk offset */
- chunk_size = INT_MAX;
- for (j = 0; j < mov->fc->nb_streams; j++) {
- MOVStreamContext *msc = mov->fc->streams[j]->priv_data;
- for (k = msc->next_chunk; k < msc->chunk_count; k++) {
- if (msc->chunk_offsets[k] > current_offset &&
- msc->chunk_offsets[k] - current_offset < chunk_size) {
- chunk_size = msc->chunk_offsets[k] - current_offset;
- msc->next_chunk = k;
- break;
- }
- }
- }
- /* check for last chunk */
- if (chunk_size == INT_MAX)
- for (j = 0; j < mov->mdat_count; j++) {
- dprintf(mov->fc, "mdat %d, offset %"PRIx64", size %"PRId64", current offset %"PRIx64"\n",
- j, mov->mdat_list[j].offset, mov->mdat_list[j].size, current_offset);
- if (mov->mdat_list[j].offset <= current_offset &&
- mov->mdat_list[j].offset + mov->mdat_list[j].size > current_offset)
- chunk_size = mov->mdat_list[j].offset + mov->mdat_list[j].size - current_offset;
- }
- assert(chunk_size != INT_MAX);
- for (j = 0; j < mov->fc->nb_streams; j++) {
- MOVStreamContext *msc = mov->fc->streams[j]->priv_data;
- msc->next_chunk = 0;
+ /* get chunk size, beware of alaw/ulaw/mace */
+ if (sc->samples_per_frame > 0 &&
+ (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) {
+ if (sc->samples_per_frame < 1024)
+ chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame;
+ else {
+ chunk_size = sc->bytes_per_frame;
+ frames = chunk_samples / sc->samples_per_frame;
+ chunk_samples = sc->samples_per_frame;
}
+ } else if (sc->sample_size > 1 || st->codec->bits_per_sample == 8) {
+ chunk_size = chunk_samples * sc->sample_size;
+ } else {
+ av_log(mov->fc, AV_LOG_ERROR, "could not determine chunk size, report problem\n");
+ goto out;
}
+ for (j = 0; j < frames; j++) {
av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME);
/* get chunk duration */
chunk_duration = 0;
} else {
chunk_duration += sc->stts_data[stts_index].duration * chunk_samples;
chunk_samples -= sc->stts_data[stts_index].count;
- if (stts_index + 1 < sc->stts_count) {
+ if (stts_index + 1 < sc->stts_count)
stts_index++;
- }
}
}
+ current_offset += sc->bytes_per_frame;
dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, "
"duration %d\n", st->index, i, current_offset, current_dts, chunk_size, chunk_duration);
assert(chunk_duration % sc->time_rate == 0);
current_dts += chunk_duration / sc->time_rate;
+ }
}
}
out:
av_freep(&sc->keyframes);
av_freep(&sc->stts_data);
}
- av_freep(&mov->mdat_list);
return 0;
}
sc->ffindex, sample->pos);
return -1;
}
+ av_get_packet(s->pb, pkt, sample->size);
#ifdef CONFIG_DV_DEMUXER
- if (sc->dv_audio_container) {
- dv_get_packet(mov->dv_demux, pkt);
- dprintf(s, "dv audio pkt size %d\n", pkt->size);
- } else {
-#endif
- av_get_packet(s->pb, pkt, sample->size);
-#ifdef CONFIG_DV_DEMUXER
- if (mov->dv_demux) {
- void *pkt_destruct_func = pkt->destruct;
- dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size);
- pkt->destruct = pkt_destruct_func;
- }
+ if (mov->dv_demux && sc->dv_audio_container) {
+ dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size);
+ av_free(pkt->data);
+ pkt->size = 0;
+ if (dv_get_packet(mov->dv_demux, pkt) < 0)
+ return -1;
}
#endif
pkt->stream_index = sc->ffindex;