2007-09-14 10:17:06 +02:00
|
|
|
/*
|
|
|
|
* copyright (c) 2007 Luca Abeni
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2015-02-25 23:25:11 +01:00
|
|
|
#include "libavutil/intreadwrite.h"
|
|
|
|
|
2007-09-14 10:17:06 +02:00
|
|
|
#include "avformat.h"
|
2009-02-06 11:35:52 +01:00
|
|
|
#include "rtpenc.h"
|
2007-09-14 10:17:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
|
|
|
|
{
|
2009-02-06 11:35:52 +01:00
|
|
|
RTPMuxContext *s = s1->priv_data;
|
2015-02-25 23:00:39 +01:00
|
|
|
AVStream *st = s1->streams[0];
|
2015-02-25 22:34:36 +01:00
|
|
|
const int max_au_headers_size = 2 + 2 * s->max_frames_per_packet;
|
2015-02-25 23:21:03 +01:00
|
|
|
int len, max_packet_size = s->max_payload_size - max_au_headers_size;
|
|
|
|
uint8_t *p;
|
2007-09-14 10:17:06 +02:00
|
|
|
|
|
|
|
/* skip ADTS header, if present */
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 20:42:52 +02:00
|
|
|
if ((s1->streams[0]->codecpar->extradata_size) == 0) {
|
2007-09-14 10:17:06 +02:00
|
|
|
size -= 7;
|
|
|
|
buff += 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test if the packet must be sent */
|
|
|
|
len = (s->buf_ptr - s->buf);
|
2015-02-27 11:32:42 +01:00
|
|
|
if (s->num_frames &&
|
|
|
|
(s->num_frames == s->max_frames_per_packet ||
|
2015-02-25 23:00:39 +01:00
|
|
|
(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)) {
|
2009-02-05 15:53:25 +01:00
|
|
|
int au_size = s->num_frames * 2;
|
2007-09-14 10:17:06 +02:00
|
|
|
|
2009-04-09 23:48:45 +02:00
|
|
|
p = s->buf + max_au_headers_size - au_size - 2;
|
2007-09-14 10:17:06 +02:00
|
|
|
if (p != s->buf) {
|
|
|
|
memmove(p + 2, s->buf + 2, au_size);
|
|
|
|
}
|
|
|
|
/* Write the AU header size */
|
2015-02-25 23:25:11 +01:00
|
|
|
AV_WB16(p, au_size * 8);
|
2007-09-14 10:17:06 +02:00
|
|
|
|
|
|
|
ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
|
|
|
|
|
2009-02-05 15:53:25 +01:00
|
|
|
s->num_frames = 0;
|
2007-09-14 10:17:06 +02:00
|
|
|
}
|
2009-02-05 15:53:25 +01:00
|
|
|
if (s->num_frames == 0) {
|
2009-04-09 23:48:45 +02:00
|
|
|
s->buf_ptr = s->buf + max_au_headers_size;
|
2007-09-14 10:17:06 +02:00
|
|
|
s->timestamp = s->cur_timestamp;
|
|
|
|
}
|
|
|
|
|
2009-04-09 23:37:11 +02:00
|
|
|
if (size <= max_packet_size) {
|
2009-02-05 15:53:25 +01:00
|
|
|
p = s->buf + s->num_frames++ * 2 + 2;
|
2015-02-25 23:25:11 +01:00
|
|
|
AV_WB16(p, size * 8);
|
2007-09-14 10:17:06 +02:00
|
|
|
memcpy(s->buf_ptr, buff, size);
|
|
|
|
s->buf_ptr += size;
|
|
|
|
} else {
|
2009-05-29 15:46:46 +02:00
|
|
|
int au_size = size;
|
|
|
|
|
2007-09-14 11:00:31 +02:00
|
|
|
max_packet_size = s->max_payload_size - 4;
|
|
|
|
p = s->buf;
|
2015-02-25 23:25:11 +01:00
|
|
|
AV_WB16(p, 2 * 8);
|
2007-09-14 11:00:31 +02:00
|
|
|
while (size > 0) {
|
|
|
|
len = FFMIN(size, max_packet_size);
|
2015-02-25 23:25:11 +01:00
|
|
|
AV_WB16(&p[2], au_size * 8);
|
2007-09-14 11:00:31 +02:00
|
|
|
memcpy(p + 4, buff, len);
|
|
|
|
ff_rtp_send_data(s1, p, len + 4, len == size);
|
|
|
|
size -= len;
|
|
|
|
buff += len;
|
|
|
|
}
|
2007-09-14 10:17:06 +02:00
|
|
|
}
|
|
|
|
}
|