mirror of
https://github.com/gpac/gpac.git
synced 2026-01-12 00:05:22 +08:00
ffmpeg7 support
This commit is contained in:
@@ -582,8 +582,14 @@ static GF_Err ffavf_process(GF_Filter *filter)
|
||||
ctx->frame->sample_aspect_ratio.num = ipid->sar.num;
|
||||
ctx->frame->sample_aspect_ratio.den = ipid->sar.den;
|
||||
} else {
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
ctx->frame->channel_layout = ipid->ch_layout;
|
||||
ctx->frame->channels = ipid->nb_ch;
|
||||
#else
|
||||
ctx->frame->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
|
||||
ctx->frame->ch_layout.nb_channels = ipid->nb_ch;
|
||||
ctx->frame->ch_layout.u.mask = ipid->ch_layout;
|
||||
#endif
|
||||
ctx->frame->sample_rate = ipid->sr;
|
||||
ctx->frame->format = ipid->pfmt;
|
||||
ctx->frame->nb_samples = data_size / ipid->nb_ch / ipid->bps;
|
||||
@@ -728,24 +734,36 @@ static GF_Err ffavf_process(GF_Filter *filter)
|
||||
GF_FilterPacket *pck;
|
||||
Bool update_props=GF_TRUE;
|
||||
if (frame->sample_rate!=opid->sr) {}
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
else if (frame->channel_layout!=opid->ch_layout) {}
|
||||
else if (frame->channels != opid->nb_ch) {}
|
||||
#else
|
||||
else if (frame->ch_layout.u.mask!=opid->ch_layout) {}
|
||||
else if (frame->ch_layout.nb_channels != opid->nb_ch) {}
|
||||
#endif
|
||||
else if (frame->format != opid->pfmt) {}
|
||||
else {
|
||||
update_props = GF_FALSE;
|
||||
}
|
||||
if (update_props) {
|
||||
u64 gpac_ch_layout = ffmpeg_channel_layout_to_gpac(frame->channel_layout);
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
u32 nb_ch = frame->channels;
|
||||
u64 ff_ch_layout = frame->channel_layout;
|
||||
#else
|
||||
u32 nb_ch = frame->ch_layout.nb_channels;
|
||||
u64 ff_ch_layout = (frame->ch_layout.order>=AV_CHANNEL_ORDER_CUSTOM) ? 0 : frame->ch_layout.u.mask;
|
||||
#endif
|
||||
u64 gpac_ch_layout = ffmpeg_channel_layout_to_gpac(ff_ch_layout);
|
||||
gf_filter_pid_set_property(opid->io_pid, GF_PROP_PID_SAMPLE_RATE, &PROP_UINT(frame->sample_rate));
|
||||
gf_filter_pid_set_property(opid->io_pid, GF_PROP_PID_CHANNEL_LAYOUT, &PROP_LONGUINT(gpac_ch_layout));
|
||||
gf_filter_pid_set_property(opid->io_pid, GF_PROP_PID_NUM_CHANNELS, &PROP_UINT(frame->channels));
|
||||
gf_filter_pid_set_property(opid->io_pid, GF_PROP_PID_NUM_CHANNELS, &PROP_UINT(nb_ch));
|
||||
opid->gf_pfmt = ffmpeg_audio_fmt_to_gpac(frame->format);
|
||||
gf_filter_pid_set_property(opid->io_pid, GF_PROP_PID_AUDIO_FORMAT, &PROP_UINT(opid->gf_pfmt));
|
||||
gf_filter_pid_set_property(opid->io_pid, GF_PROP_PID_TIMESCALE, &PROP_UINT(opid->io_filter_ctx->inputs[0]->time_base.den) );
|
||||
|
||||
opid->sr = frame->sample_rate;
|
||||
opid->ch_layout = frame->channel_layout;
|
||||
opid->nb_ch = frame->channels;
|
||||
opid->ch_layout = ff_ch_layout;
|
||||
opid->nb_ch = nb_ch;
|
||||
opid->pfmt = frame->format;
|
||||
opid->tb_num = opid->io_filter_ctx->inputs[0]->time_base.num;
|
||||
opid->bps = gf_audio_fmt_bit_depth(opid->gf_pfmt) / 8;
|
||||
@@ -890,8 +908,15 @@ static GF_Err ffavf_configure_pid(GF_Filter *filter, GF_FilterPid *pid, Bool is_
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_NUM_CHANNELS);
|
||||
if (!p) return GF_OK; //not ready yet
|
||||
nb_ch = p->value.uint;
|
||||
if (!ch_layout) ch_layout = av_get_default_channel_layout(p->value.uint);
|
||||
|
||||
if (!ch_layout) {
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
ch_layout = av_get_default_channel_layout(p->value.uint);
|
||||
#else
|
||||
AVChannelLayout ff_ch_layout;
|
||||
av_channel_layout_default(&ff_ch_layout, p->value.uint);
|
||||
ch_layout = ff_ch_layout.u.mask;
|
||||
#endif
|
||||
}
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_SAMPLE_RATE);
|
||||
if (!p) return GF_OK; //not ready yet
|
||||
sr = p->value.uint;
|
||||
|
||||
@@ -809,7 +809,9 @@ GF_FilterArgs ffmpeg_arg_translate(const struct AVOption *opt)
|
||||
switch (opt->type) {
|
||||
case AV_OPT_TYPE_INT64:
|
||||
case AV_OPT_TYPE_INT:
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
case AV_OPT_TYPE_CHANNEL_LAYOUT:
|
||||
#endif
|
||||
if (opt->type==AV_OPT_TYPE_INT64) arg.arg_type = GF_PROP_LSINT;
|
||||
else if (opt->type==AV_OPT_TYPE_INT) arg.arg_type = GF_PROP_SINT;
|
||||
else arg.arg_type = GF_PROP_UINT; //channel layout, map to int
|
||||
@@ -2091,12 +2093,21 @@ GF_Err ffmpeg_codec_par_from_gpac(GF_FilterPid *pid, AVCodecParameters *codecpar
|
||||
}
|
||||
else if (streamtype==GF_STREAM_AUDIO) {
|
||||
u64 ch_layout;
|
||||
u32 samplerate=0;
|
||||
u32 nb_ch=0, samplerate=0;
|
||||
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_SAMPLE_RATE);
|
||||
if (p) codecpar->sample_rate = samplerate = p->value.uint;
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_NUM_CHANNELS);
|
||||
if (p) codecpar->channels = p->value.uint;
|
||||
if (p) {
|
||||
nb_ch = p->value.uint;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
codecpar->channels = p->value.uint;
|
||||
#else
|
||||
codecpar->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
|
||||
codecpar->ch_layout.nb_channels = p->value.uint;
|
||||
#endif
|
||||
}
|
||||
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_SAMPLES_PER_FRAME);
|
||||
if (p) codecpar->frame_size = p->value.uint;
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_AUDIO_BPS);
|
||||
@@ -2110,10 +2121,13 @@ GF_Err ffmpeg_codec_par_from_gpac(GF_FilterPid *pid, AVCodecParameters *codecpar
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_CHANNEL_LAYOUT);
|
||||
if (p)
|
||||
ch_layout = p->value.longuint;
|
||||
else if (codecpar->channels==2)
|
||||
else if (nb_ch==2)
|
||||
ch_layout = GF_AUDIO_CH_FRONT_LEFT|GF_AUDIO_CH_FRONT_RIGHT;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
codecpar->channel_layout = ffmpeg_channel_layout_from_gpac(ch_layout);
|
||||
|
||||
#else
|
||||
codecpar->ch_layout.u.mask = ffmpeg_channel_layout_from_gpac(ch_layout);
|
||||
#endif
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_DELAY);
|
||||
if (p && (p->value.sint<0) && samplerate) {
|
||||
s64 pad = -p->value.longsint;
|
||||
@@ -2173,10 +2187,19 @@ GF_Err ffmpeg_codec_par_to_gpac(AVCodecParameters *codecpar, GF_FilterPid *opid,
|
||||
if (codecpar->sample_rate)
|
||||
gf_filter_pid_set_property(opid, GF_PROP_PID_SAMPLE_RATE, &PROP_UINT(codecpar->sample_rate));
|
||||
|
||||
if (codecpar->channels) {
|
||||
gf_filter_pid_set_property(opid, GF_PROP_PID_NUM_CHANNELS, &PROP_UINT(codecpar->channels));
|
||||
if (codecpar->channel_layout) {
|
||||
gf_filter_pid_set_property(opid, GF_PROP_PID_CHANNEL_LAYOUT, &PROP_LONGUINT( ffmpeg_channel_layout_to_gpac(codecpar->channel_layout) ));
|
||||
u32 nb_ch=0;
|
||||
u64 ch_layout=0;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
nb_ch = codecpar->channels;
|
||||
ch_layout = codecpar->channel_layout;
|
||||
#else
|
||||
nb_ch = codecpar->ch_layout.nb_channels;
|
||||
ch_layout = (codecpar->ch_layout.order>=AV_CHANNEL_ORDER_CUSTOM) ? 0 : codecpar->ch_layout.u.mask;
|
||||
#endif
|
||||
if (nb_ch) {
|
||||
gf_filter_pid_set_property(opid, GF_PROP_PID_NUM_CHANNELS, &PROP_UINT(nb_ch));
|
||||
if (ch_layout) {
|
||||
gf_filter_pid_set_property(opid, GF_PROP_PID_CHANNEL_LAYOUT, &PROP_LONGUINT( ffmpeg_channel_layout_to_gpac(ch_layout) ));
|
||||
}
|
||||
|
||||
if (codecpar->frame_size)
|
||||
|
||||
@@ -64,6 +64,10 @@
|
||||
#include <libavcodec/bsf.h>
|
||||
#endif
|
||||
|
||||
#if AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, LIBAFORMAT_VERSION_MINOR, 0) < AV_VERSION_INT(59,19, 0)
|
||||
#define FFMPEG_OLD_CHLAYOUT
|
||||
#endif
|
||||
|
||||
|
||||
GF_FilterArgs ffmpeg_arg_translate(const struct AVOption *opt);
|
||||
void ffmpeg_setup_logs(u32 log_class);
|
||||
|
||||
@@ -713,8 +713,13 @@ dispatch_next:
|
||||
FF_RELEASE_PCK(pkt);
|
||||
|
||||
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
FF_CHECK_PROP(channels, channels, GF_PROP_PID_NUM_CHANNELS)
|
||||
FF_CHECK_PROPL(channel_layout, channel_layout, GF_PROP_PID_CHANNEL_LAYOUT)
|
||||
#else
|
||||
FF_CHECK_PROP(channels, ch_layout.nb_channels, GF_PROP_PID_NUM_CHANNELS)
|
||||
FF_CHECK_PROPL(channel_layout, ch_layout.u.mask, GF_PROP_PID_CHANNEL_LAYOUT)
|
||||
#endif
|
||||
FF_CHECK_PROP(sample_rate, sample_rate, GF_PROP_PID_SAMPLE_RATE)
|
||||
|
||||
if (prev_afmt != ctx->decoder->sample_fmt) {
|
||||
@@ -1202,7 +1207,11 @@ static GF_Err ffdec_configure_pid(GF_Filter *filter, GF_FilterPid *pid, Bool is_
|
||||
}
|
||||
if (ctx->sample_rate && ctx->channels) {
|
||||
ctx->decoder->sample_rate = ctx->sample_rate;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
ctx->decoder->channels = ctx->channels;
|
||||
#else
|
||||
ctx->decoder->ch_layout.nb_channels = ctx->channels;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1352,13 +1361,23 @@ reuse_codec_context:
|
||||
ctx->bytes_per_sample = gf_audio_fmt_bit_depth(ctx->sample_fmt) / 8;
|
||||
}
|
||||
|
||||
u32 nb_ch=0;
|
||||
u64 ff_ch_layout=0;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
nb_ch = ctx->decoder->channels;
|
||||
ff_ch_layout = ctx->decoder->channel_layout;
|
||||
#else
|
||||
nb_ch = ctx->decoder->ch_layout.nb_channels;
|
||||
ff_ch_layout = (ctx->decoder->ch_layout.order>=AV_CHANNEL_ORDER_CUSTOM) ? 0 : ctx->decoder->ch_layout.u.mask;
|
||||
#endif
|
||||
|
||||
//override PID props with what decoder gives us
|
||||
if (ctx->decoder->channels) {
|
||||
ctx->channels = 0;
|
||||
FF_CHECK_PROP(channels, channels, GF_PROP_PID_NUM_CHANNELS)
|
||||
if (nb_ch) {
|
||||
gf_filter_pid_set_property(ctx->out_pid, GF_PROP_PID_NUM_CHANNELS, &PROP_UINT(nb_ch ) );
|
||||
ctx->channels = nb_ch;
|
||||
}
|
||||
if (ctx->decoder->channel_layout) {
|
||||
u64 ch_lay = ffmpeg_channel_layout_to_gpac(ctx->decoder->channel_layout);
|
||||
if (ff_ch_layout) {
|
||||
u64 ch_lay = ffmpeg_channel_layout_to_gpac(ff_ch_layout);
|
||||
if (ctx->channel_layout != ch_lay) {
|
||||
gf_filter_pid_set_property(ctx->out_pid, GF_PROP_PID_CHANNEL_LAYOUT, &PROP_LONGUINT(ch_lay ) );
|
||||
ctx->channel_layout = ch_lay;
|
||||
|
||||
@@ -599,6 +599,7 @@ restart:
|
||||
GF_BitStream *bs = gf_bs_new(sd->data, sd->size, GF_BITSTREAM_READ);
|
||||
|
||||
u32 flags = gf_bs_read_u32_le(bs);
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
|
||||
u32 new_ch = gf_bs_read_u32_le(bs);
|
||||
gf_filter_pid_set_property(pctx->pid, GF_PROP_PID_NUM_CHANNELS, &PROP_UINT(new_ch) );
|
||||
@@ -608,6 +609,10 @@ restart:
|
||||
new_lay = ffmpeg_channel_layout_to_gpac(new_lay);
|
||||
gf_filter_pid_set_property(pctx->pid, GF_PROP_PID_CHANNEL_LAYOUT, &PROP_LONGUINT(new_lay) );
|
||||
}
|
||||
#else
|
||||
//no message for ch layout/count change in latest API
|
||||
#endif
|
||||
|
||||
if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
|
||||
u32 new_sr = gf_bs_read_u32_le(bs);
|
||||
gf_filter_pid_set_property(pctx->pid, GF_PROP_PID_SAMPLE_RATE, &PROP_UINT(new_sr) );
|
||||
@@ -978,7 +983,11 @@ GF_Err ffdmx_init_common(GF_Filter *filter, GF_FFDemuxCtx *ctx, u32 grab_type)
|
||||
u32 exdata_size = stream->codecpar->extradata_size;
|
||||
u32 codec_sample_rate = stream->codecpar->sample_rate;
|
||||
u32 codec_frame_size = stream->codecpar->frame_size;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
u32 codec_channels = stream->codecpar->channels;
|
||||
#else
|
||||
u32 codec_channels = stream->codecpar->ch_layout.nb_channels;
|
||||
#endif
|
||||
u32 codec_width = stream->codecpar->width;
|
||||
u32 codec_height = stream->codecpar->height;
|
||||
u32 codec_field_order = stream->codecpar->field_order;
|
||||
@@ -1068,8 +1077,13 @@ GF_Err ffdmx_init_common(GF_Filter *filter, GF_FFDemuxCtx *ctx, u32 grab_type)
|
||||
if (grab_type)
|
||||
gf_filter_pid_set_property(pid, GF_PROP_PID_RAWGRAB, &PROP_UINT(grab_type) );
|
||||
else if (ctx->demuxer->iformat) {
|
||||
if ((ctx->demuxer->iformat->flags & AVFMT_SEEK_TO_PTS) || ctx->demuxer->iformat->read_seek)
|
||||
if ((ctx->demuxer->iformat->flags & AVFMT_SEEK_TO_PTS)
|
||||
#if (LIBAVFORMAT_VERSION_MAJOR < 59)
|
||||
|| ctx->demuxer->iformat->read_seek
|
||||
#endif
|
||||
) {
|
||||
gf_filter_pid_set_property(pid, GF_PROP_PID_PLAYBACK_MODE, &PROP_UINT(GF_PLAYBACK_MODE_FASTFORWARD ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
|
||||
#include "ff_common.h"
|
||||
|
||||
#if (LIBAVUTIL_VERSION_MAJOR < 59)
|
||||
#define _avf_dur pkt_duration
|
||||
#else
|
||||
#define _avf_dur duration
|
||||
#endif
|
||||
|
||||
#define ENC_BUF_ALLOC_SAFE 10000
|
||||
|
||||
typedef struct _gf_ffenc_ctx
|
||||
@@ -590,7 +596,7 @@ static GF_Err ffenc_process_video(GF_Filter *filter, struct _gf_ffenc_ctx *ctx)
|
||||
ctx->frame->top_field_first = (ilaced==2) ? 1 : 0;
|
||||
}
|
||||
ctx->frame->pts = ffenc_get_cts(ctx, pck);
|
||||
ctx->frame->pkt_duration = gf_filter_pck_get_duration(pck);
|
||||
ctx->frame->_avf_dur = gf_filter_pck_get_duration(pck);
|
||||
}
|
||||
|
||||
//use signed version of timestamp rescale since we may have negative dts
|
||||
@@ -601,7 +607,7 @@ static GF_Err ffenc_process_video(GF_Filter *filter, struct _gf_ffenc_ctx *ctx)
|
||||
if (ctx->remap_ts) {
|
||||
SCALE_TS(ctx->frame->pts);
|
||||
|
||||
SCALE_TS(ctx->frame->pkt_duration);
|
||||
SCALE_TS(ctx->frame->_avf_dur);
|
||||
}
|
||||
|
||||
//store first frame CTS as will be seen after rescaling (to cope with rounding errors
|
||||
@@ -673,7 +679,7 @@ static GF_Err ffenc_process_video(GF_Filter *filter, struct _gf_ffenc_ctx *ctx)
|
||||
|
||||
if (ctx->remap_ts) {
|
||||
UNSCALE_TS(ctx->frame->pts);
|
||||
UNSCALE_TS(ctx->frame->pkt_duration);
|
||||
UNSCALE_TS(ctx->frame->_avf_dur);
|
||||
if (gotpck) {
|
||||
UNSCALE_TS(pkt->dts);
|
||||
UNSCALE_TS(pkt->pts);
|
||||
@@ -857,7 +863,7 @@ static GF_Err ffenc_process_video(GF_Filter *filter, struct _gf_ffenc_ctx *ctx)
|
||||
if (pkt->duration) {
|
||||
gf_filter_pck_set_duration(dst_pck, (u32) pkt->duration);
|
||||
} else {
|
||||
gf_filter_pck_set_duration(dst_pck, (u32) ctx->frame->pkt_duration);
|
||||
gf_filter_pck_set_duration(dst_pck, (u32) ctx->frame->_avf_dur);
|
||||
}
|
||||
}
|
||||
if (ctx->gen_dsi) {
|
||||
@@ -1118,8 +1124,13 @@ static GF_Err ffenc_process_audio(GF_Filter *filter, struct _gf_ffenc_ctx *ctx)
|
||||
if (pck)
|
||||
ctx->frame->nb_samples = ctx->encoder->frame_size;
|
||||
ctx->frame->format = ctx->encoder->sample_fmt;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
ctx->frame->channels = ctx->encoder->channels;
|
||||
ctx->frame->channel_layout = ctx->encoder->channel_layout;
|
||||
#else
|
||||
av_channel_layout_copy(&ctx->frame->ch_layout, &ctx->encoder->ch_layout);
|
||||
#endif
|
||||
|
||||
gotpck = 0;
|
||||
if (pck || ctx->samples_in_audio_buffer) {
|
||||
#if (LIBAVFORMAT_VERSION_MAJOR<59)
|
||||
@@ -1526,7 +1537,12 @@ static GF_Err ffenc_configure_pid_ex(GF_Filter *filter, GF_FilterPid *pid, Bool
|
||||
|
||||
if ((type==GF_STREAM_AUDIO)
|
||||
&& (ctx->encoder->codec->id==codec_id) && (ctx->encoder->sample_rate==ctx->sample_rate)
|
||||
&& (ctx->encoder->channels==ctx->channels) && (ctx->gpac_audio_fmt == afmt )
|
||||
&& (ctx->gpac_audio_fmt == afmt )
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
&& (ctx->encoder->channels==ctx->channels)
|
||||
#else
|
||||
&& (ctx->encoder->ch_layout.nb_channels==ctx->channels)
|
||||
#endif
|
||||
) {
|
||||
reuse = GF_TRUE;
|
||||
} else if ((ctx->encoder->codec->id==codec_id)
|
||||
@@ -1680,6 +1696,7 @@ static GF_Err ffenc_configure_pid_ex(GF_Filter *filter, GF_FilterPid *pid, Bool
|
||||
ctx->channel_layout = gf_audio_fmt_get_layout_from_cicp(gf_audio_fmt_get_cicp_layout(ctx->channels, 0, 0));
|
||||
}
|
||||
u64 ff_ch_layout = ffmpeg_channel_layout_from_gpac(ctx->channel_layout);
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
if (!codec->channel_layouts)
|
||||
change_chan_layout = ctx->channel_layout;
|
||||
|
||||
@@ -1691,6 +1708,19 @@ static GF_Err ffenc_configure_pid_ex(GF_Filter *filter, GF_FilterPid *pid, Bool
|
||||
}
|
||||
i++;
|
||||
}
|
||||
#else
|
||||
if (!codec->ch_layouts)
|
||||
change_chan_layout = ctx->channel_layout;
|
||||
|
||||
while (codec->ch_layouts) {
|
||||
if (!codec->ch_layouts[i].nb_channels) break;
|
||||
if (codec->ch_layouts[i].u.mask == ff_ch_layout) {
|
||||
change_chan_layout = ctx->channel_layout;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
#endif
|
||||
//vorbis in ffmpeg currently requires stereo but channel_layouts is not set
|
||||
if (ctx->codecid==GF_CODECID_VORBIS) {
|
||||
change_chan_layout = gf_audio_fmt_get_layout_from_cicp(gf_audio_fmt_get_cicp_layout(2, 0, 0));
|
||||
@@ -1710,8 +1740,13 @@ static GF_Err ffenc_configure_pid_ex(GF_Filter *filter, GF_FilterPid *pid, Bool
|
||||
gf_filter_pid_negotiate_property(ctx->in_pid, GF_PROP_PID_SAMPLE_RATE, &PROP_UINT(codec->supported_samplerates[0]) );
|
||||
}
|
||||
if (ctx->channel_layout != change_chan_layout) {
|
||||
if (!change_chan_layout)
|
||||
if (!change_chan_layout) {
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
change_chan_layout = ffmpeg_channel_layout_to_gpac(codec->channel_layouts[0]);
|
||||
#else
|
||||
change_chan_layout = ffmpeg_channel_layout_to_gpac(codec->ch_layouts[0].u.mask);
|
||||
#endif
|
||||
}
|
||||
u32 nb_chans = gf_audio_fmt_get_num_channels_from_layout(change_chan_layout);
|
||||
gf_filter_pid_negotiate_property(ctx->in_pid, GF_PROP_PID_NUM_CHANNELS, &PROP_UINT(nb_chans) );
|
||||
gf_filter_pid_negotiate_property(ctx->in_pid, GF_PROP_PID_CHANNEL_LAYOUT, &PROP_LONGUINT(change_chan_layout) );
|
||||
@@ -1869,9 +1904,8 @@ static GF_Err ffenc_configure_pid_ex(GF_Filter *filter, GF_FilterPid *pid, Bool
|
||||
av_dict_set(&ctx->options, "strict", "experimental", 0);
|
||||
} else if (type==GF_STREAM_AUDIO) {
|
||||
ctx->encoder->sample_rate = ctx->sample_rate;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
ctx->encoder->channels = ctx->channels;
|
||||
|
||||
//TODO
|
||||
prop = gf_filter_pid_get_property(pid, GF_PROP_PID_CHANNEL_LAYOUT);
|
||||
if (prop) {
|
||||
ctx->encoder->channel_layout = ffmpeg_channel_layout_from_gpac(prop->value.longuint);
|
||||
@@ -1880,6 +1914,19 @@ static GF_Err ffenc_configure_pid_ex(GF_Filter *filter, GF_FilterPid *pid, Bool
|
||||
} else if (ctx->channels==2) {
|
||||
ctx->encoder->channel_layout = AV_CH_LAYOUT_STEREO;
|
||||
}
|
||||
#else
|
||||
av_channel_layout_uninit(&ctx->encoder->ch_layout);
|
||||
ctx->encoder->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
|
||||
ctx->encoder->ch_layout.nb_channels = ctx->channels;
|
||||
prop = gf_filter_pid_get_property(pid, GF_PROP_PID_CHANNEL_LAYOUT);
|
||||
if (prop) {
|
||||
ctx->encoder->ch_layout.u.mask = ffmpeg_channel_layout_from_gpac(prop->value.longuint);
|
||||
} else if (ctx->channels==1) {
|
||||
ctx->encoder->ch_layout.u.mask = AV_CH_LAYOUT_MONO;
|
||||
} else if (ctx->channels==2) {
|
||||
ctx->encoder->ch_layout.u.mask = AV_CH_LAYOUT_STEREO;
|
||||
}
|
||||
#endif
|
||||
|
||||
prop = gf_filter_pid_get_property(pid, GF_PROP_PID_TIMESCALE);
|
||||
if (prop) {
|
||||
|
||||
@@ -247,7 +247,7 @@ static GF_Err ffmx_init_mux(GF_Filter *filter, GF_FFMuxCtx *ctx)
|
||||
}
|
||||
|
||||
|
||||
static int ffavio_write_packet(void *opaque, uint8_t *buf, int buf_size)
|
||||
static int ffavio_write_packet(void *opaque, const uint8_t *buf, int buf_size)
|
||||
{
|
||||
GF_FFMuxCtx *ctx = (GF_FFMuxCtx *)opaque;
|
||||
return (int) gf_fwrite(buf, buf_size, ctx->gfio);
|
||||
@@ -412,7 +412,11 @@ static GF_Err ffmx_start_seg(GF_Filter *filter, GF_FFMuxCtx *ctx, const char *se
|
||||
segmux->max_delay = ctx->muxer->max_delay;
|
||||
av_dict_copy(&segmux->metadata, ctx->muxer->metadata, 0);
|
||||
segmux->opaque = ctx->muxer->opaque;
|
||||
#if (LIBAVFORMAT_VERSION_MAJOR < 59)
|
||||
segmux->io_close = ctx->muxer->io_close;
|
||||
#else
|
||||
segmux->io_close2 = ctx->muxer->io_close2;
|
||||
#endif
|
||||
segmux->io_open = ctx->muxer->io_open;
|
||||
segmux->flags = ctx->muxer->flags;
|
||||
|
||||
@@ -459,7 +463,11 @@ static GF_Err ffmx_start_seg(GF_Filter *filter, GF_FFMuxCtx *ctx, const char *se
|
||||
avformat_free_context(ctx->muxer);
|
||||
ctx->muxer = segmux;
|
||||
} else {
|
||||
#if (LIBAVFORMAT_VERSION_MAJOR < 59)
|
||||
ctx->muxer->io_close(ctx->muxer, ctx->muxer->pb);
|
||||
#else
|
||||
ctx->muxer->io_close2(ctx->muxer, ctx->muxer->pb);
|
||||
#endif
|
||||
ctx->muxer->pb = NULL;
|
||||
}
|
||||
|
||||
@@ -603,13 +611,20 @@ void ffmx_inject_config(GF_FilterPid *pid, GF_FFMuxStream *st, AVPacket *pkt)
|
||||
}
|
||||
}
|
||||
if (st->reconfig_stream & FFMX_INJECT_AUD_INFO) {
|
||||
u32 sr, ch, size=12;
|
||||
u64 ch_layout;
|
||||
u32 flags = AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT | AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE;
|
||||
u32 sr, size=12;
|
||||
u32 flags = AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT;
|
||||
u64 ch_layout=0;
|
||||
u32 ch;
|
||||
#endif
|
||||
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_SAMPLE_RATE);
|
||||
sr = p ? p->value.uint : st->stream->codecpar->sample_rate;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_NUM_CHANNELS);
|
||||
ch = p ? p->value.uint : st->stream->codecpar->channels;
|
||||
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_CHANNEL_LAYOUT);
|
||||
if (p) {
|
||||
ch_layout = ffmpeg_channel_layout_from_gpac(p->value.uint);
|
||||
@@ -620,14 +635,17 @@ void ffmx_inject_config(GF_FilterPid *pid, GF_FFMuxStream *st, AVPacket *pkt)
|
||||
size += 8;
|
||||
flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT;
|
||||
}
|
||||
#endif
|
||||
|
||||
data = av_packet_new_side_data(pkt, AV_PKT_DATA_PARAM_CHANGE, size);
|
||||
if (data) {
|
||||
GF_BitStream *bs = gf_bs_new(data, 12, GF_BITSTREAM_WRITE);
|
||||
gf_bs_write_u32_le(bs, flags);
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
gf_bs_write_u32_le(bs, ch);
|
||||
if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
|
||||
gf_bs_write_u64_le(bs, ch_layout);
|
||||
#endif
|
||||
gf_bs_write_u32_le(bs, sr);
|
||||
gf_bs_del(bs);
|
||||
}
|
||||
@@ -1169,18 +1187,25 @@ static GF_Err ffmx_configure_pid(GF_Filter *filter, GF_FilterPid *pid, Bool is_r
|
||||
if ((w != avst->codecpar->width) || (h != avst->codecpar->height))
|
||||
st->reconfig_stream |= FFMX_INJECT_VID_INFO;
|
||||
} else if (streamtype==GF_STREAM_AUDIO) {
|
||||
u32 sr, ch;
|
||||
u32 sr;
|
||||
u64 ch_layout;
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_SAMPLE_RATE);
|
||||
sr = p ? p->value.uint : 0;
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_NUM_CHANNELS);
|
||||
ch = p ? p->value.uint : 0;
|
||||
u32 ch = p ? p->value.uint : 0;
|
||||
#endif
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_CHANNEL_LAYOUT);
|
||||
ch_layout = p ? p->value.uint : 0;
|
||||
if (ch_layout)
|
||||
ch_layout = ffmpeg_channel_layout_from_gpac(ch_layout);
|
||||
if ((sr != avst->codecpar->sample_rate) || (ch != avst->codecpar->channels) || (ch_layout!=avst->codecpar->channel_layout))
|
||||
if ((sr != avst->codecpar->sample_rate)
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
|| (ch != avst->codecpar->channels) || (ch_layout!=avst->codecpar->channel_layout)
|
||||
#endif
|
||||
) {
|
||||
st->reconfig_stream |= FFMX_INJECT_AUD_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_TIMESCALE);
|
||||
@@ -1239,12 +1264,21 @@ static GF_Err ffmx_configure_pid(GF_Filter *filter, GF_FilterPid *pid, Bool is_r
|
||||
}
|
||||
else if (streamtype==GF_STREAM_AUDIO) {
|
||||
u64 ch_layout;
|
||||
u32 samplerate=0;
|
||||
|
||||
u32 nb_ch, samplerate=0;
|
||||
#ifndef FFMPEG_OLD_CHLAYOUT
|
||||
av_channel_layout_uninit(&avst->codecpar->ch_layout);
|
||||
avst->codecpar->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
|
||||
#endif
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_SAMPLE_RATE);
|
||||
if (p) avst->codecpar->sample_rate = samplerate = p->value.uint;
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_NUM_CHANNELS);
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
if (p) avst->codecpar->channels = p->value.uint;
|
||||
nb_ch = avst->codecpar->channels;
|
||||
#else
|
||||
if (p) avst->codecpar->ch_layout.nb_channels = p->value.uint;
|
||||
nb_ch = avst->codecpar->ch_layout.nb_channels;
|
||||
#endif
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_SAMPLES_PER_FRAME);
|
||||
if (p) avst->codecpar->frame_size = p->value.uint;
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_AUDIO_BPS);
|
||||
@@ -1258,12 +1292,16 @@ static GF_Err ffmx_configure_pid(GF_Filter *filter, GF_FilterPid *pid, Bool is_r
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_CHANNEL_LAYOUT);
|
||||
if (p)
|
||||
ch_layout = p->value.longuint;
|
||||
else if (avst->codecpar->channels==2)
|
||||
else if (nb_ch==2)
|
||||
ch_layout = GF_AUDIO_CH_FRONT_LEFT|GF_AUDIO_CH_FRONT_RIGHT;
|
||||
else if (avst->codecpar->channels==1)
|
||||
else if (nb_ch==1)
|
||||
ch_layout = GF_AUDIO_CH_FRONT_CENTER;
|
||||
|
||||
#ifdef FFMPEG_OLD_CHLAYOUT
|
||||
avst->codecpar->channel_layout = ch_layout ? ffmpeg_channel_layout_from_gpac(ch_layout) : 0;
|
||||
#else
|
||||
avst->codecpar->ch_layout.u.mask = ch_layout ? ffmpeg_channel_layout_from_gpac(ch_layout) : 0;
|
||||
#endif
|
||||
|
||||
p = gf_filter_pid_get_property(pid, GF_PROP_PID_DELAY);
|
||||
if (p && (p->value.sint<0) && samplerate) {
|
||||
@@ -1399,7 +1437,11 @@ static void ffmx_finalize(GF_Filter *filter)
|
||||
ctx->status = FFMX_STATE_TRAILER_DONE;
|
||||
}
|
||||
if (!ctx->gfio && ctx->muxer && ctx->muxer->pb) {
|
||||
#if (LIBAVFORMAT_VERSION_MAJOR < 59)
|
||||
ctx->muxer->io_close(ctx->muxer, ctx->muxer->pb);
|
||||
#else
|
||||
ctx->muxer->io_close2(ctx->muxer, ctx->muxer->pb);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (LIBAVCODEC_VERSION_MAJOR >= 59)
|
||||
|
||||
Reference in New Issue
Block a user