summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_lavc.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio/out/ao_lavc.c')
-rw-r--r--audio/out/ao_lavc.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c
index b49898fc5c..4bae4389e8 100644
--- a/audio/out/ao_lavc.c
+++ b/audio/out/ao_lavc.c
@@ -26,11 +26,13 @@
#include <limits.h>
#include <libavutil/common.h>
+#include <libavutil/samplefmt.h>
#include "config.h"
#include "options/options.h"
#include "common/common.h"
#include "audio/aframe.h"
+#include "audio/chmap_avchannel.h"
#include "audio/format.h"
#include "audio/fmt-conversion.h"
#include "filters/filter_internal.h"
@@ -124,8 +126,13 @@ static int init(struct ao *ao)
if (!ao_chmap_sel_adjust2(ao, &sel, &ao->channels, false))
goto fail;
mp_chmap_reorder_to_lavc(&ao->channels);
+
+#if !HAVE_AV_CHANNEL_LAYOUT
encoder->channels = ao->channels.num;
encoder->channel_layout = mp_chmap_to_lavc(&ao->channels);
+#else
+ mp_chmap_to_av_layout(&encoder->ch_layout, &ao->channels);
+#endif
encoder->sample_fmt = AV_SAMPLE_FMT_NONE;
@@ -167,7 +174,7 @@ static int init(struct ao *ao)
return 0;
fail:
- pthread_mutex_unlock(&ao->encode_lavc_ctx->lock);
+ mp_mutex_unlock(&ao->encode_lavc_ctx->lock);
ac->shutdown = true;
return -1;
}
@@ -176,18 +183,8 @@ fail:
static void uninit(struct ao *ao)
{
struct priv *ac = ao->priv;
- struct encode_lavc_context *ectx = ao->encode_lavc_ctx;
if (!ac->shutdown) {
- double outpts = ac->expected_next_pts;
-
- pthread_mutex_lock(&ectx->lock);
- if (!ac->enc->options->rawts)
- outpts += ectx->discontinuity_pts_offset;
- pthread_mutex_unlock(&ectx->lock);
-
- outpts += encoder_get_offset(ac->enc);
-
if (!write_frame(ao, MP_EOF_FRAME))
MP_WARN(ao, "could not flush last frame\n");
encoder_encode(ac->enc, NULL);
@@ -204,8 +201,7 @@ static void encode(struct ao *ao, struct mp_aframe *af)
double outpts = mp_aframe_get_pts(af);
AVFrame *frame = mp_aframe_to_avframe(af);
- if (!frame)
- abort();
+ MP_HANDLE_OOM(frame);
frame->pts = rint(outpts * av_q2d(av_inv_q(encoder->time_base)));
@@ -266,7 +262,7 @@ static bool audio_write(struct ao *ao, void **data, int samples)
double outpts = pts;
// for ectx PTS fields
- pthread_mutex_lock(&ectx->lock);
+ mp_mutex_lock(&ectx->lock);
if (!ectx->options->rawts) {
// Fix and apply the discontinuity pts offset.
@@ -285,9 +281,6 @@ static bool audio_write(struct ao *ao, void **data, int samples)
outpts = pts + ectx->discontinuity_pts_offset;
}
- // Shift pts by the pts offset first.
- outpts += encoder_get_offset(ac->enc);
-
// Calculate expected pts of next audio frame (input side).
ac->expected_next_pts = pts + mp_aframe_get_size(af) / (double) ao->samplerate;
@@ -298,7 +291,7 @@ static bool audio_write(struct ao *ao, void **data, int samples)
ectx->next_in_pts = nextpts;
}
- pthread_mutex_unlock(&ectx->lock);
+ mp_mutex_unlock(&ectx->lock);
mp_aframe_set_pts(af, outpts);