aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/rtpenc_amr.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2015-02-26 00:00:39 +0200
committerMartin Storsjö <martin@martin.st>2015-02-28 22:54:31 +0200
commit4f6cd883f06f7893a2b60a41e7a4f8ae633dac2f (patch)
tree0a140108c19744a4399aa5d5244fd63d8b5e13bf /libavformat/rtpenc_amr.c
parentbde2bba45c2f2df27a8534028bda09a6e7f835e2 (diff)
downloadffmpeg-4f6cd883f06f7893a2b60a41e7a4f8ae633dac2f.tar.gz
rtpenc: Don't set max_frames_per_packet based on the packet frame size or frame rate
Instead check the timestamps while muxing, to avoid buffering a too long timestamp range into one single packet. This makes the AMR and AAC packetization slightly less efficient, since we set a possibly unnecessarily high max_frames_per_packet. (These packetizers end up doing a memmove of the TOC bytes if sending a packet before max_frames_per_packet is achieved, and we end up setting max_frames_per_packet to a value that should be high enough for most uses.) All packetizers that use max_frames_per_packet now set it either to a default value, or to a value calculated based on other parameters, so none of them rely on the previous default setting. For iLBC, copy one frame at a time, to allow checking the timestamp range for each of them - basically doing potentially multiple loops to simplify the code instead of trying to calculate the number of frames to buffer while honoring s1->max_delay. This is in preparation for reducing the coupling between libavformat and libavcodec, by not having the muxers use the encoder field frame_size (which may not be available during e.g. stream copy). Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/rtpenc_amr.c')
-rw-r--r--libavformat/rtpenc_amr.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/libavformat/rtpenc_amr.c b/libavformat/rtpenc_amr.c
index 6da5f0f17a..0adbf49a74 100644
--- a/libavformat/rtpenc_amr.c
+++ b/libavformat/rtpenc_amr.c
@@ -30,6 +30,7 @@
void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
{
RTPMuxContext *s = s1->priv_data;
+ AVStream *st = s1->streams[0];
int max_header_toc_size = 1 + s->max_frames_per_packet;
uint8_t *p;
int len;
@@ -38,7 +39,9 @@ void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
len = s->buf_ptr - s->buf;
if (s->num_frames &&
(s->num_frames == s->max_frames_per_packet ||
- len + size - 1 > s->max_payload_size)) {
+ len + size - 1 > s->max_payload_size ||
+ av_compare_ts(s->cur_timestamp - s->timestamp, st->time_base,
+ s1->max_delay, AV_TIME_BASE_Q) >= 0)) {
int header_size = s->num_frames + 1;
p = s->buf + max_header_toc_size - header_size;
if (p != s->buf)