mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-05-31 23:32:36 +08:00
Merge remote-tracking branch 'qatar/master'
* qatar/master: rtmp: Support 'rtmp_live', an option which specifies if the media is a live stream. av_samples_fill_array: Mark unmodified function argument as const. lagarith: add YUY2 decoding support Support decoding unaligned rgb24 lagarith. dv: Split profile handling code into a separate file. flvenc: use AVFormatContext, not AVCodecContext for logging. mov: Remove write-only variable in mov_read_chan(). fate: Change the probe-format refs to match the final text format committed. fate: Add avprobe as a make dependency Add probe fate tests to test for regressions in detecting media types. fate: Add oneline comparison method qdm2: clip array indices returned by qdm2_get_vlc(). avplay: properly close/reopen AVAudioResampleContext on channel layout change avcodec: do not needlessly set packet size to 0 in avcodec_encode_audio2() avcodec: for audio encoding, reset output packet when it is not valid avcodec: refactor avcodec_encode_audio2() to merge common branches avcodec: remove fallbacks for AVCodec.encode() in avcodec_encode_audio2() Conflicts: ffplay.c libavcodec/Makefile libavcodec/dvdata.c libavcodec/dvdata.h libavcodec/qdm2.c libavcodec/utils.c libavformat/flvenc.c libavformat/mov.c tests/Makefile Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
@ -1008,7 +1008,6 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
|
||||
{
|
||||
int ret;
|
||||
AVPacket user_pkt = *avpkt;
|
||||
int nb_samples;
|
||||
int needs_realloc = !user_pkt.data;
|
||||
|
||||
*got_packet_ptr = 0;
|
||||
@ -1016,27 +1015,23 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
|
||||
if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
|
||||
av_free_packet(avpkt);
|
||||
av_init_packet(avpkt);
|
||||
avpkt->size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check for valid frame size */
|
||||
if (frame) {
|
||||
nb_samples = frame->nb_samples;
|
||||
if (avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
|
||||
if (nb_samples > avctx->frame_size)
|
||||
if (frame->nb_samples > avctx->frame_size)
|
||||
return AVERROR(EINVAL);
|
||||
} else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
|
||||
if (nb_samples != avctx->frame_size)
|
||||
if (frame->nb_samples != avctx->frame_size)
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
} else {
|
||||
nb_samples = avctx->frame_size;
|
||||
}
|
||||
|
||||
if (avctx->codec->encode2) {
|
||||
ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
|
||||
if (!ret && *got_packet_ptr) {
|
||||
ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
|
||||
if (!ret) {
|
||||
if (*got_packet_ptr) {
|
||||
if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
|
||||
if (avpkt->pts == AV_NOPTS_VALUE)
|
||||
avpkt->pts = frame->pts;
|
||||
@ -1048,69 +1043,6 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
|
||||
} else {
|
||||
avpkt->size = 0;
|
||||
}
|
||||
} else {
|
||||
/* for compatibility with encoders not supporting encode2(), we need to
|
||||
allocate a packet buffer if the user has not provided one or check
|
||||
the size otherwise */
|
||||
int fs_tmp = 0;
|
||||
int buf_size = avpkt->size;
|
||||
if (!user_pkt.data) {
|
||||
if (avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) {
|
||||
av_assert0(av_get_bits_per_sample(avctx->codec_id) != 0);
|
||||
if (!frame)
|
||||
return AVERROR(EINVAL);
|
||||
buf_size = nb_samples * avctx->channels *
|
||||
av_get_bits_per_sample(avctx->codec_id) / 8;
|
||||
} else {
|
||||
/* this is a guess as to the required size.
|
||||
if an encoder needs more than this, it should probably
|
||||
implement encode2() */
|
||||
buf_size = 2 * avctx->frame_size * avctx->channels *
|
||||
av_get_bytes_per_sample(avctx->sample_fmt);
|
||||
buf_size += 2*FF_MIN_BUFFER_SIZE;
|
||||
}
|
||||
}
|
||||
if ((ret = ff_alloc_packet2(avctx, avpkt, buf_size)))
|
||||
return ret;
|
||||
|
||||
/* Encoders using AVCodec.encode() that support
|
||||
CODEC_CAP_SMALL_LAST_FRAME require avctx->frame_size to be set to
|
||||
the smaller size when encoding the last frame.
|
||||
This code can be removed once all encoders supporting
|
||||
CODEC_CAP_SMALL_LAST_FRAME use encode2() */
|
||||
if ((avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) &&
|
||||
nb_samples < avctx->frame_size) {
|
||||
fs_tmp = avctx->frame_size;
|
||||
avctx->frame_size = nb_samples;
|
||||
}
|
||||
|
||||
/* encode the frame */
|
||||
ret = avctx->codec->encode(avctx, avpkt->data, avpkt->size,
|
||||
frame ? frame->data[0] : NULL);
|
||||
if (ret >= 0) {
|
||||
if (!ret) {
|
||||
/* no output. if the packet data was allocated by libavcodec,
|
||||
free it */
|
||||
if (!user_pkt.data && avpkt->data != avctx->internal->byte_buffer)
|
||||
av_freep(&avpkt->data);
|
||||
} else {
|
||||
if (avctx->coded_frame)
|
||||
avpkt->pts = avpkt->dts = avctx->coded_frame->pts;
|
||||
/* Set duration for final small packet. This can be removed
|
||||
once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use
|
||||
encode2() */
|
||||
if (fs_tmp) {
|
||||
avpkt->duration = ff_samples_to_time_base(avctx,
|
||||
avctx->frame_size);
|
||||
}
|
||||
}
|
||||
avpkt->size = ret;
|
||||
*got_packet_ptr = (ret > 0);
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
if (fs_tmp)
|
||||
avctx->frame_size = fs_tmp;
|
||||
}
|
||||
if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
|
||||
needs_realloc = 0;
|
||||
@ -1141,8 +1073,11 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
|
||||
avctx->frame_number++;
|
||||
}
|
||||
|
||||
if (ret < 0 || !*got_packet_ptr)
|
||||
if (ret < 0 || !*got_packet_ptr) {
|
||||
av_free_packet(avpkt);
|
||||
av_init_packet(avpkt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* NOTE: if we add any audio encoders which output non-keyframe packets,
|
||||
this needs to be moved to the encoders, but for now we can do it
|
||||
|
Reference in New Issue
Block a user