1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

Merge commit '4f6cd883f06f7893a2b60a41e7a4f8ae633dac2f'

* commit '4f6cd883f06f7893a2b60a41e7a4f8ae633dac2f':
  rtpenc: Don't set max_frames_per_packet based on the packet frame size or frame rate

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2015-03-01 01:31:45 +01:00
commit 5cb6b53050
4 changed files with 29 additions and 49 deletions

View File

@ -152,33 +152,6 @@ static int rtp_write_header(AVFormatContext *s1)
} }
s->max_payload_size = s1->packet_size - 12; s->max_payload_size = s1->packet_size - 12;
s->max_frames_per_packet = 0;
if (s1->max_delay > 0) {
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
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_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) {
/* FIXME: We should round down here... */
if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) {
s->max_frames_per_packet = av_rescale_q(s1->max_delay,
(AVRational){1, 1000000},
av_inv_q(st->avg_frame_rate));
} else
s->max_frames_per_packet = 1;
}
}
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);
} else { } else {
@ -228,9 +201,7 @@ static int rtp_write_header(AVFormatContext *s1)
break; break;
case AV_CODEC_ID_VORBIS: case AV_CODEC_ID_VORBIS:
case AV_CODEC_ID_THEORA: case AV_CODEC_ID_THEORA:
if (!s->max_frames_per_packet) s->max_frames_per_packet = 15;
s->max_frames_per_packet = 15;
s->max_frames_per_packet = av_clip(s->max_frames_per_packet, 1, 15);
break; break;
case AV_CODEC_ID_ADPCM_G722: case AV_CODEC_ID_ADPCM_G722:
/* Due to a historical error, the clock rate for G722 in RTP is /* Due to a historical error, the clock rate for G722 in RTP is
@ -252,15 +223,11 @@ static int rtp_write_header(AVFormatContext *s1)
av_log(s1, AV_LOG_ERROR, "Incorrect iLBC block size specified\n"); av_log(s1, AV_LOG_ERROR, "Incorrect iLBC block size specified\n");
goto fail; goto fail;
} }
if (!s->max_frames_per_packet) s->max_frames_per_packet = s->max_payload_size / st->codec->block_align;
s->max_frames_per_packet = 1;
s->max_frames_per_packet = FFMIN(s->max_frames_per_packet,
s->max_payload_size / st->codec->block_align);
break; break;
case AV_CODEC_ID_AMR_NB: case AV_CODEC_ID_AMR_NB:
case AV_CODEC_ID_AMR_WB: case AV_CODEC_ID_AMR_WB:
if (!s->max_frames_per_packet) s->max_frames_per_packet = 50;
s->max_frames_per_packet = 12;
if (st->codec->codec_id == AV_CODEC_ID_AMR_NB) if (st->codec->codec_id == AV_CODEC_ID_AMR_NB)
n = 31; n = 31;
else else
@ -276,8 +243,7 @@ static int rtp_write_header(AVFormatContext *s1)
} }
break; break;
case AV_CODEC_ID_AAC: case AV_CODEC_ID_AAC:
if (!s->max_frames_per_packet) s->max_frames_per_packet = 50;
s->max_frames_per_packet = 5;
break; break;
default: default:
break; break;
@ -496,18 +462,23 @@ static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
int frames = size / frame_size; int frames = size / frame_size;
while (frames > 0) { while (frames > 0) {
int n = FFMIN(s->max_frames_per_packet - s->num_frames, frames); if (s->num_frames > 0 &&
av_compare_ts(s->cur_timestamp - s->timestamp, st->time_base,
s1->max_delay, AV_TIME_BASE_Q) >= 0) {
ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);
s->num_frames = 0;
}
if (!s->num_frames) { if (!s->num_frames) {
s->buf_ptr = s->buf; s->buf_ptr = s->buf;
s->timestamp = s->cur_timestamp; s->timestamp = s->cur_timestamp;
} }
memcpy(s->buf_ptr, buf, n * frame_size); memcpy(s->buf_ptr, buf, frame_size);
frames -= n; frames--;
s->num_frames += n; s->num_frames++;
s->buf_ptr += n * frame_size; s->buf_ptr += frame_size;
buf += n * frame_size; buf += frame_size;
s->cur_timestamp += n * frame_duration; s->cur_timestamp += frame_duration;
if (s->num_frames == s->max_frames_per_packet) { if (s->num_frames == s->max_frames_per_packet) {
ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1); ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);

View File

@ -27,6 +27,7 @@
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size) void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
{ {
RTPMuxContext *s = s1->priv_data; RTPMuxContext *s = s1->priv_data;
AVStream *st = s1->streams[0];
const int max_au_headers_size = 2 + 2 * s->max_frames_per_packet; const int max_au_headers_size = 2 + 2 * s->max_frames_per_packet;
int len, max_packet_size = s->max_payload_size - max_au_headers_size; int len, max_packet_size = s->max_payload_size - max_au_headers_size;
uint8_t *p; uint8_t *p;
@ -41,7 +42,9 @@ void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
len = (s->buf_ptr - s->buf); len = (s->buf_ptr - s->buf);
if (s->num_frames && if (s->num_frames &&
(s->num_frames == s->max_frames_per_packet || (s->num_frames == s->max_frames_per_packet ||
(len + size) > s->max_payload_size)) { (len + size) > s->max_payload_size ||
av_compare_ts(s->cur_timestamp - s->timestamp, st->time_base,
s1->max_delay, AV_TIME_BASE_Q) >= 0)) {
int au_size = s->num_frames * 2; int au_size = s->num_frames * 2;
p = s->buf + max_au_headers_size - au_size - 2; p = s->buf + max_au_headers_size - au_size - 2;

View File

@ -30,6 +30,7 @@
void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size) void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
{ {
RTPMuxContext *s = s1->priv_data; RTPMuxContext *s = s1->priv_data;
AVStream *st = s1->streams[0];
int max_header_toc_size = 1 + s->max_frames_per_packet; int max_header_toc_size = 1 + s->max_frames_per_packet;
uint8_t *p; uint8_t *p;
int len; 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; len = s->buf_ptr - s->buf;
if (s->num_frames && if (s->num_frames &&
(s->num_frames == s->max_frames_per_packet || (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; int header_size = s->num_frames + 1;
p = s->buf + max_header_toc_size - header_size; p = s->buf + max_header_toc_size - header_size;
if (p != s->buf) if (p != s->buf)

View File

@ -33,6 +33,7 @@
void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size) void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size)
{ {
RTPMuxContext *s = s1->priv_data; RTPMuxContext *s = s1->priv_data;
AVStream *st = s1->streams[0];
int max_pkt_size, xdt, frag; int max_pkt_size, xdt, frag;
uint8_t *q; uint8_t *q;
@ -78,8 +79,10 @@ void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size)
av_assert1(s->num_frames <= s->max_frames_per_packet); av_assert1(s->num_frames <= s->max_frames_per_packet);
if (s->num_frames > 0 && if (s->num_frames > 0 &&
(remaining < 0 || (remaining < 0 ||
s->num_frames == s->max_frames_per_packet)) { s->num_frames == s->max_frames_per_packet ||
// send previous packets now; no room for new data av_compare_ts(s->cur_timestamp - s->timestamp, st->time_base,
s1->max_delay, AV_TIME_BASE_Q) >= 0)) {
// send previous packets now; no room for new data, or too much delay
ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
s->num_frames = 0; s->num_frames = 0;
} }