diff options
Diffstat (limited to 'audio')
-rw-r--r-- | audio/decode/ad_lavc.c | 34 | ||||
-rw-r--r-- | audio/out/ao_lavc.c | 77 |
2 files changed, 22 insertions, 89 deletions
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index c42c430850..2e0cade8c5 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -63,12 +63,10 @@ const m_option_t ad_lavc_decode_opts_conf[] = { struct pcm_map { int tag; - const char *codecs[5]; // {any, 1byte, 2bytes, 3bytes, 4bytes} + const char *codecs[6]; // {any, 1byte, 2bytes, 3bytes, 4bytes, 8bytes} }; -// NOTE: some of these are needed to make rawaudio with demux_mkv and others -// work. ffmpeg does similar mapping internally, not part of the public -// API. Some of these might be dead leftovers for demux_mov support. +// NOTE: these are needed to make rawaudio with demux_mkv work. static const struct pcm_map tag_map[] = { // Microsoft PCM {0x0, {NULL, "pcm_u8", "pcm_s16le", "pcm_s24le", "pcm_s32le"}}, @@ -76,26 +74,12 @@ static const struct pcm_map tag_map[] = { // MS PCM, Extended {0xfffe, {NULL, "pcm_u8", "pcm_s16le", "pcm_s24le", "pcm_s32le"}}, // IEEE float - {0x3, {"pcm_f32le"}}, + {0x3, {"pcm_f32le", [5] = "pcm_f64le"}}, // 'raw ' {0x20776172, {"pcm_s16be", [1] = "pcm_u8"}}, - // 'twos'/'sowt' - {0x736F7774, {"pcm_s16be", [1] = "pcm_s8"}}, - {0x74776F73, {"pcm_s16be", [1] = "pcm_s8"}}, - // 'fl32'/'FL32' - {0x32336c66, {"pcm_f32be"}}, - {0x32334C46, {"pcm_f32be"}}, - // '23lf'/'lpcm' - {0x666c3332, {"pcm_f32le"}}, - {0x6D63706C, {"pcm_f32le"}}, - // 'in24', bigendian int24 - {0x34326e69, {"pcm_s24be"}}, - // '42ni', little endian int24, MPlayer internal fourCC - {0x696e3234, {"pcm_s24le"}}, - // 'in32', bigendian int32 - {0x32336e69, {"pcm_s32be"}}, - // '23ni', little endian int32, MPlayer internal fourCC - {0x696e3332, {"pcm_s32le"}}, + // 'twos', used by demux_mkv.c internally + {MKTAG('t', 'w', 'o', 's'), + {NULL, "pcm_s8", "pcm_s16be", "pcm_s24be", "pcm_s32be"}}, {-1}, }; @@ -118,6 +102,8 @@ static const struct pcm_map af_map[] = { {AF_FORMAT_S32_BE, {"pcm_s32be"}}, {AF_FORMAT_FLOAT_LE, {"pcm_f32le"}}, {AF_FORMAT_FLOAT_BE, {"pcm_f32be"}}, + {AF_FORMAT_DOUBLE_LE, {"pcm_f64le"}}, + {AF_FORMAT_DOUBLE_BE, {"pcm_f64be"}}, {-1}, }; @@ -125,11 +111,13 @@ static const char *find_pcm_decoder(const struct pcm_map *map, int format, int bits_per_sample) { int bytes = (bits_per_sample + 7) / 8; + if (bytes == 8) + bytes = 5; // 64 bit entry for (int n = 0; map[n].tag != -1; n++) { const struct pcm_map *entry = &map[n]; if (entry->tag == format) { const char *dec = NULL; - if (bytes >= 1 && bytes <= 4) + if (bytes >= 1 && bytes <= 5) dec = entry->codecs[bytes]; if (!dec) dec = entry->codecs[0]; diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index 9be3a7b6ae..c1fce6a715 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -50,8 +50,6 @@ struct priv { int pcmhack; int aframesize; int aframecount; - int offset; - int offset_left; int64_t savepts; int framecount; int64_t lastpts; @@ -271,9 +269,6 @@ out_takefirst: ac->savepts = MP_NOPTS_VALUE; ac->lastpts = MP_NOPTS_VALUE; - ac->offset = ac->stream->codec->sample_rate * - encode_lavc_getoffset(ao->encode_lavc_ctx, ac->stream); - ac->offset_left = ac->offset; ao->untimed = true; ao->priv = ac; @@ -450,7 +445,6 @@ static int play(struct ao *ao, void **ni_data, int samples, int flags) struct priv *ac = ao->priv; struct encode_lavc_context *ectx = ao->encode_lavc_ctx; int bufpos = 0; - int64_t ptsoffset; void *paddingbuf = NULL; double nextpts; double pts = ao->pts; @@ -542,63 +536,10 @@ static int play(struct ao *ao, void **ni_data, int samples, int flags) // Absurd, as this range MUST contain at least one multiple of B. } - ptsoffset = ac->offset; - // this basically just edits ao->apts for syncing purposes - - if (ectx->options->copyts || ectx->options->rawts) { - // we do not send time sync data to the video side, - // but we always need the exact pts, even if zero - } else { - // here we must "simulate" the pts editing - // 1. if we have to skip stuff, we skip it - // 2. if we have to add samples, we add them - // 3. we must still adjust ptsoffset appropriately for AV sync! - // invariant: - // if no partial skipping is done, the first frame gets ao->apts passed as pts! - - if (ac->offset_left < 0) { - if (ac->offset_left <= -len) { - // skip whole frame - ac->offset_left += len; - return len; - } else { - // skip part of this frame, buffer/encode the rest - bufpos -= ac->offset_left; - ptsoffset += ac->offset_left; - ac->offset_left = 0; - } - } else if (ac->offset_left > 0) { - // make a temporary buffer, filled with zeroes at the start - // (don't worry, only happens once) - - paddingbuf = talloc_size(ac, ac->sample_size * ao->channels.num * - (ac->offset_left + len)); - fill_with_padding(paddingbuf, ac->offset_left, ac->sample_size, - ac->sample_padding); - data = (char *) paddingbuf + ac->sample_size * ao->channels.num * - ac->offset_left; - bufpos -= ac->offset_left; // yes, negative! - ptsoffset += ac->offset_left; - ac->offset_left = 0; - - // now adjust the bufpos so the final value of bufpos is positive! - /* - int cnt = (len - bufpos) / ac->aframesize; - int finalbufpos = bufpos + cnt * ac->aframesize; - */ - int finalbufpos = len - (len - bufpos) % ac->aframesize; - if (finalbufpos < 0) { - MP_WARN(ao, "cannot attain the " - "exact requested audio sync; shifting by %d frames\n", - -finalbufpos); - bufpos -= finalbufpos; - } - } - } - + // Fix and apply the discontinuity pts offset. if (!ectx->options->rawts && ectx->options->copyts) { // fix the discontinuity pts offset - nextpts = pts + ptsoffset / (double) ao->samplerate; + nextpts = pts; if (ectx->discontinuity_pts_offset == MP_NOPTS_VALUE) { ectx->discontinuity_pts_offset = ectx->next_in_pts - nextpts; } @@ -611,23 +552,27 @@ static int play(struct ao *ao, void **ni_data, int samples, int flags) outpts = pts + ectx->discontinuity_pts_offset; } - else + else { outpts = pts; + } + + // Shift pts by the pts offset first. + outpts += encode_lavc_getoffset(ectx, ac->stream); while (len - bufpos >= ac->aframesize) { encode(ao, - outpts + (bufpos + ptsoffset) / (double) ao->samplerate + encode_lavc_getoffset(ectx, ac->stream), + outpts + bufpos / (double) ao->samplerate, (char *) data + ac->sample_size * bufpos * ao->channels.num); bufpos += ac->aframesize; } talloc_free(paddingbuf); - // calculate expected pts of next audio frame - ac->expected_next_pts = pts + (bufpos + ptsoffset) / (double) ao->samplerate; + // Calculate expected pts of next audio frame (input side). + ac->expected_next_pts = pts + bufpos / (double) ao->samplerate; + // Set next allowed input pts value (input side). if (!ectx->options->rawts && ectx->options->copyts) { - // set next allowed output pts value nextpts = ac->expected_next_pts + ectx->discontinuity_pts_offset; if (nextpts > ectx->next_in_pts) ectx->next_in_pts = nextpts; |