[FFmpeg-cvslog] rtpenc: use av_get_audio_frame_duration() for max_frames_per_packet

Justin Ruggles git at videolan.org
Tue Mar 6 06:15:57 CET 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Mon Feb 27 03:01:45 2012 -0500| [14aecc50fae6466fe9c16992a2929fb86497f237] | committer: Justin Ruggles

rtpenc: use av_get_audio_frame_duration() for max_frames_per_packet

It is more reliable than AVCodecContext.frame_size for codecs with constant
packet duration.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=14aecc50fae6466fe9c16992a2929fb86497f237
---

 libavformat/rtpenc.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index 41d5843..787eba8 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -129,10 +129,17 @@ static int rtp_write_header(AVFormatContext *s1)
     s->max_frames_per_packet = 0;
     if (s1->max_delay) {
         if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-            if (st->codec->frame_size == 0) {
+            int frame_size = av_get_audio_frame_duration(st->codec, 0);
+            if (!frame_size)
+                frame_size = st->codec->frame_size;
+            if (frame_size == 0) {
                 av_log(s1, AV_LOG_ERROR, "Cannot respect max delay: frame size = 0\n");
             } else {
-                s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * (int64_t)st->codec->frame_size, AV_ROUND_DOWN);
+                s->max_frames_per_packet =
+                        av_rescale_q_rnd(s1->max_delay,
+                                         AV_TIME_BASE_Q,
+                                         (AVRational){ frame_size / st->codec->sample_rate },
+                                         AV_ROUND_DOWN);
             }
         }
         if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {



More information about the ffmpeg-cvslog mailing list