2010-03-22 16:26:29 +00:00
|
|
|
/*
|
2010-04-01 21:41:48 +00:00
|
|
|
* Xiph RTP Protocols
|
2010-04-01 21:43:22 +00:00
|
|
|
* Copyright (c) 2009 Colin McQuillian
|
2010-03-22 16:26:29 +00:00
|
|
|
* Copyright (c) 2010 Josh Allmann
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2010-04-01 21:41:48 +00:00
|
|
|
* @brief Xiph / RTP Code
|
2010-04-01 21:43:22 +00:00
|
|
|
* @author Colin McQuillan <m.niloc@gmail.com>
|
2010-03-22 16:26:29 +00:00
|
|
|
* @author Josh Allmann <joshua.allmann@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2013-04-18 13:54:26 +00:00
|
|
|
#include "libavutil/attributes.h"
|
2012-08-24 03:39:30 +00:00
|
|
|
#include "libavutil/avassert.h"
|
2010-03-22 16:26:29 +00:00
|
|
|
#include "libavutil/avstring.h"
|
|
|
|
#include "libavutil/base64.h"
|
|
|
|
#include "libavcodec/bytestream.h"
|
|
|
|
|
2015-02-24 11:37:03 +00:00
|
|
|
#include "avio_internal.h"
|
2013-10-13 10:30:59 +00:00
|
|
|
#include "internal.h"
|
2010-03-22 16:26:29 +00:00
|
|
|
#include "rtpdec.h"
|
2010-07-30 12:04:27 +00:00
|
|
|
#include "rtpdec_formats.h"
|
2010-03-22 16:26:29 +00:00
|
|
|
|
|
|
|
/**
|
2010-04-01 21:41:48 +00:00
|
|
|
* RTP/Xiph specific private data.
|
2010-03-22 16:26:29 +00:00
|
|
|
*/
|
|
|
|
struct PayloadContext {
|
|
|
|
unsigned ident; ///< 24-bit stream configuration identifier
|
|
|
|
uint32_t timestamp;
|
2011-02-20 10:04:12 +00:00
|
|
|
AVIOContext* fragment; ///< buffer for split payloads
|
2010-08-05 04:42:36 +00:00
|
|
|
uint8_t *split_buf;
|
|
|
|
int split_pos, split_buf_len, split_buf_size;
|
|
|
|
int split_pkts;
|
2010-03-22 16:26:29 +00:00
|
|
|
};
|
|
|
|
|
2015-02-24 15:01:48 +00:00
|
|
|
static void xiph_close_context(PayloadContext * data)
|
2010-03-22 16:26:29 +00:00
|
|
|
{
|
2015-02-24 11:37:03 +00:00
|
|
|
ffio_free_dyn_buf(&data->fragment);
|
2014-12-23 14:33:07 +00:00
|
|
|
av_freep(&data->split_buf);
|
2010-03-22 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 13:29:12 +00:00
|
|
|
|
2012-12-10 12:38:32 +00:00
|
|
|
static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
|
|
|
|
AVStream *st, AVPacket *pkt, uint32_t *timestamp,
|
|
|
|
const uint8_t *buf, int len, uint16_t seq,
|
|
|
|
int flags)
|
2010-03-22 16:26:29 +00:00
|
|
|
{
|
|
|
|
|
2019-12-10 21:59:53 +00:00
|
|
|
int ident, fragmented, tdt, num_pkts, pkt_len, ret;
|
2010-03-22 16:26:29 +00:00
|
|
|
|
2010-08-05 04:42:36 +00:00
|
|
|
if (!buf) {
|
|
|
|
if (!data->split_buf || data->split_pos + 2 > data->split_buf_len ||
|
|
|
|
data->split_pkts <= 0) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "No more data to return\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
pkt_len = AV_RB16(data->split_buf + data->split_pos);
|
|
|
|
data->split_pos += 2;
|
2015-05-12 16:07:32 +00:00
|
|
|
if (pkt_len > data->split_buf_len - data->split_pos) {
|
2010-08-05 04:42:36 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Not enough data to return\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2019-12-10 21:59:53 +00:00
|
|
|
if ((ret = av_new_packet(pkt, pkt_len)) < 0) {
|
2010-08-05 04:42:36 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Out of memory.\n");
|
2019-12-10 21:59:53 +00:00
|
|
|
return ret;
|
2010-08-05 04:42:36 +00:00
|
|
|
}
|
|
|
|
pkt->stream_index = st->index;
|
|
|
|
memcpy(pkt->data, data->split_buf + data->split_pos, pkt_len);
|
|
|
|
data->split_pos += pkt_len;
|
|
|
|
data->split_pkts--;
|
|
|
|
return data->split_pkts > 0;
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:03:55 +00:00
|
|
|
if (len < 6 || len > INT_MAX/2) {
|
2010-03-22 16:26:29 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Invalid %d byte packet\n", len);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2010-04-01 21:41:48 +00:00
|
|
|
// read xiph rtp headers
|
2010-03-22 16:26:29 +00:00
|
|
|
ident = AV_RB24(buf);
|
|
|
|
fragmented = buf[3] >> 6;
|
|
|
|
tdt = (buf[3] >> 4) & 3;
|
2010-08-04 17:22:25 +00:00
|
|
|
num_pkts = buf[3] & 0xf;
|
2010-03-22 16:26:29 +00:00
|
|
|
pkt_len = AV_RB16(buf + 4);
|
|
|
|
|
|
|
|
if (pkt_len > len - 6) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Invalid packet length %d in %d byte packet\n", pkt_len,
|
|
|
|
len);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ident != data->ident) {
|
2015-12-16 17:01:34 +00:00
|
|
|
avpriv_report_missing_feature(ctx, "Xiph SDP configuration change");
|
2010-03-22 16:26:29 +00:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tdt) {
|
2015-12-16 17:01:34 +00:00
|
|
|
avpriv_report_missing_feature(ctx,
|
|
|
|
"RTP Xiph packet settings (%d,%d,%d)",
|
|
|
|
fragmented, tdt, num_pkts);
|
2010-03-22 16:26:29 +00:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf += 6; // move past header bits
|
|
|
|
len -= 6;
|
|
|
|
|
|
|
|
if (fragmented == 0) {
|
2019-12-10 21:59:53 +00:00
|
|
|
if ((ret = av_new_packet(pkt, pkt_len)) < 0) {
|
2010-03-22 16:26:29 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Out of memory.\n");
|
2019-12-10 21:59:53 +00:00
|
|
|
return ret;
|
2010-03-22 16:26:29 +00:00
|
|
|
}
|
|
|
|
pkt->stream_index = st->index;
|
2010-08-05 04:42:36 +00:00
|
|
|
memcpy(pkt->data, buf, pkt_len);
|
|
|
|
buf += pkt_len;
|
|
|
|
len -= pkt_len;
|
|
|
|
num_pkts--;
|
|
|
|
|
|
|
|
if (num_pkts > 0) {
|
|
|
|
if (len > data->split_buf_size || !data->split_buf) {
|
|
|
|
av_freep(&data->split_buf);
|
|
|
|
data->split_buf_size = 2 * len;
|
|
|
|
data->split_buf = av_malloc(data->split_buf_size);
|
|
|
|
if (!data->split_buf) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Out of memory.\n");
|
2015-10-23 09:11:31 +00:00
|
|
|
av_packet_unref(pkt);
|
2010-08-05 04:42:36 +00:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy(data->split_buf, buf, len);
|
|
|
|
data->split_buf_len = len;
|
|
|
|
data->split_pos = 0;
|
|
|
|
data->split_pkts = num_pkts;
|
|
|
|
return 1;
|
2010-03-22 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
} else if (fragmented == 1) {
|
2010-04-01 21:41:48 +00:00
|
|
|
// start of xiph data fragment
|
2010-03-22 16:26:29 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
// end packet has been lost somewhere, so drop buffered data
|
2015-02-24 11:37:03 +00:00
|
|
|
ffio_free_dyn_buf(&data->fragment);
|
2010-03-22 16:26:29 +00:00
|
|
|
|
2011-03-17 07:13:34 +00:00
|
|
|
if((res = avio_open_dyn_buf(&data->fragment)) < 0)
|
2010-03-22 16:26:29 +00:00
|
|
|
return res;
|
|
|
|
|
2011-02-21 18:28:17 +00:00
|
|
|
avio_write(data->fragment, buf, pkt_len);
|
2010-03-22 16:26:29 +00:00
|
|
|
data->timestamp = *timestamp;
|
|
|
|
|
|
|
|
} else {
|
2012-08-24 03:39:30 +00:00
|
|
|
av_assert1(fragmented < 4);
|
2010-03-22 16:26:29 +00:00
|
|
|
if (data->timestamp != *timestamp) {
|
|
|
|
// skip if fragmented timestamp is incorrect;
|
|
|
|
// a start packet has been lost somewhere
|
2015-02-24 11:37:03 +00:00
|
|
|
ffio_free_dyn_buf(&data->fragment);
|
2010-03-22 16:26:29 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "RTP timestamps don't match!\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2010-07-27 08:16:03 +00:00
|
|
|
if (!data->fragment) {
|
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
|
|
|
"Received packet without a start fragment; dropping.\n");
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
}
|
2010-03-22 16:26:29 +00:00
|
|
|
|
|
|
|
// copy data to fragment buffer
|
2011-02-21 18:28:17 +00:00
|
|
|
avio_write(data->fragment, buf, pkt_len);
|
2010-03-22 16:26:29 +00:00
|
|
|
|
|
|
|
if (fragmented == 3) {
|
2010-04-01 21:41:48 +00:00
|
|
|
// end of xiph data packet
|
2012-11-01 13:03:04 +00:00
|
|
|
int ret = ff_rtp_finalize_packet(pkt, &data->fragment, st->index);
|
|
|
|
if (ret < 0) {
|
2010-03-22 16:26:29 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Error occurred when getting fragment buffer.");
|
2012-11-01 13:03:04 +00:00
|
|
|
return ret;
|
2010-03-22 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Length encoding described in RFC5215 section 3.1.1.
|
|
|
|
*/
|
|
|
|
static int get_base128(const uint8_t ** buf, const uint8_t * buf_end)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
for (; *buf < buf_end; ++*buf) {
|
|
|
|
n <<= 7;
|
|
|
|
n += **buf & 0x7f;
|
|
|
|
if (!(**buf & 0x80)) {
|
|
|
|
++*buf;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Based off parse_packed_headers in Vorbis RTP
|
|
|
|
*/
|
2012-10-11 20:59:12 +00:00
|
|
|
static int
|
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 18:42:52 +00:00
|
|
|
parse_packed_headers(AVFormatContext *s,
|
|
|
|
const uint8_t * packed_headers,
|
2010-03-22 16:26:29 +00:00
|
|
|
const uint8_t * packed_headers_end,
|
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 18:42:52 +00:00
|
|
|
AVCodecParameters *par, PayloadContext * xiph_data)
|
2010-03-22 16:26:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
unsigned num_packed, num_headers, length, length1, length2, extradata_alloc;
|
2019-12-10 21:59:53 +00:00
|
|
|
int ret;
|
2010-03-22 16:26:29 +00:00
|
|
|
uint8_t *ptr;
|
|
|
|
|
|
|
|
if (packed_headers_end - packed_headers < 9) {
|
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 18:42:52 +00:00
|
|
|
av_log(s, AV_LOG_ERROR,
|
2014-04-24 16:01:30 +00:00
|
|
|
"Invalid %"PTRDIFF_SPECIFIER" byte packed header.",
|
2010-03-22 16:26:29 +00:00
|
|
|
packed_headers_end - packed_headers);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_packed = bytestream_get_be32(&packed_headers);
|
2010-04-01 21:41:48 +00:00
|
|
|
xiph_data->ident = bytestream_get_be24(&packed_headers);
|
2010-03-22 16:26:29 +00:00
|
|
|
length = bytestream_get_be16(&packed_headers);
|
|
|
|
num_headers = get_base128(&packed_headers, packed_headers_end);
|
|
|
|
length1 = get_base128(&packed_headers, packed_headers_end);
|
|
|
|
length2 = get_base128(&packed_headers, packed_headers_end);
|
|
|
|
|
|
|
|
if (num_packed != 1 || num_headers > 3) {
|
2015-12-16 17:01:34 +00:00
|
|
|
avpriv_report_missing_feature(s, "%u packed headers, %u headers",
|
|
|
|
num_packed, num_headers);
|
2010-03-22 16:26:29 +00:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packed_headers_end - packed_headers != length ||
|
|
|
|
length1 > length || length2 > length - length1) {
|
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 18:42:52 +00:00
|
|
|
av_log(s, AV_LOG_ERROR,
|
2017-03-24 12:29:45 +00:00
|
|
|
"Bad packed header lengths (%d,%d,%"PTRDIFF_SPECIFIER",%u)\n", length1,
|
2010-03-22 16:26:29 +00:00
|
|
|
length2, packed_headers_end - packed_headers, length);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate extra space:
|
|
|
|
* -- length/255 +2 for xiphlacing
|
|
|
|
* -- one for the '2' marker
|
2015-06-29 21:48:34 +00:00
|
|
|
* -- AV_INPUT_BUFFER_PADDING_SIZE required */
|
|
|
|
extradata_alloc = length + length/255 + 3 + AV_INPUT_BUFFER_PADDING_SIZE;
|
2010-03-22 16:26:29 +00:00
|
|
|
|
2019-12-10 21:59:53 +00:00
|
|
|
if ((ret = ff_alloc_extradata(par, extradata_alloc)) < 0) {
|
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 18:42:52 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "Out of memory\n");
|
2019-12-10 21:59:53 +00:00
|
|
|
return ret;
|
2010-03-22 16:26:29 +00:00
|
|
|
}
|
2016-04-10 19:58:15 +00:00
|
|
|
ptr = par->extradata;
|
2010-03-22 16:26:29 +00:00
|
|
|
*ptr++ = 2;
|
|
|
|
ptr += av_xiphlacing(ptr, length1);
|
|
|
|
ptr += av_xiphlacing(ptr, length2);
|
|
|
|
memcpy(ptr, packed_headers, length);
|
|
|
|
ptr += length;
|
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 18:42:52 +00:00
|
|
|
par->extradata_size = ptr - par->extradata;
|
2010-03-22 16:26:29 +00:00
|
|
|
// clear out remaining parts of the buffer
|
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 18:42:52 +00:00
|
|
|
memset(ptr, 0, extradata_alloc - par->extradata_size);
|
2010-03-22 16:26:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-05 07:01:07 +00:00
|
|
|
static int xiph_parse_fmtp_pair(AVFormatContext *s,
|
|
|
|
AVStream* stream,
|
2010-04-01 21:41:48 +00:00
|
|
|
PayloadContext *xiph_data,
|
2015-02-24 10:32:17 +00:00
|
|
|
const char *attr, const char *value)
|
2010-03-22 16:26:29 +00:00
|
|
|
{
|
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 18:42:52 +00:00
|
|
|
AVCodecParameters *par = stream->codecpar;
|
2010-03-22 16:26:29 +00:00
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
if (!strcmp(attr, "sampling")) {
|
2010-07-28 06:43:58 +00:00
|
|
|
if (!strcmp(value, "YCbCr-4:2:0")) {
|
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 18:42:52 +00:00
|
|
|
par->format = AV_PIX_FMT_YUV420P;
|
2010-07-28 06:43:58 +00:00
|
|
|
} else if (!strcmp(value, "YCbCr-4:4:2")) {
|
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 18:42:52 +00:00
|
|
|
par->format = AV_PIX_FMT_YUV422P;
|
2010-07-28 06:43:58 +00:00
|
|
|
} else if (!strcmp(value, "YCbCr-4:4:4")) {
|
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 18:42:52 +00:00
|
|
|
par->format = AV_PIX_FMT_YUV444P;
|
2010-07-28 06:43:58 +00:00
|
|
|
} else {
|
2014-07-05 07:01:07 +00:00
|
|
|
av_log(s, AV_LOG_ERROR,
|
2010-07-28 06:43:58 +00:00
|
|
|
"Unsupported pixel format %s\n", attr);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2010-03-22 16:26:29 +00:00
|
|
|
} else if (!strcmp(attr, "width")) {
|
|
|
|
/* This is an integer between 1 and 1048561
|
|
|
|
* and MUST be in multiples of 16. */
|
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 18:42:52 +00:00
|
|
|
par->width = atoi(value);
|
2010-03-22 16:26:29 +00:00
|
|
|
return 0;
|
|
|
|
} else if (!strcmp(attr, "height")) {
|
|
|
|
/* This is an integer between 1 and 1048561
|
|
|
|
* and MUST be in multiples of 16. */
|
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 18:42:52 +00:00
|
|
|
par->height = atoi(value);
|
2010-03-22 16:26:29 +00:00
|
|
|
return 0;
|
|
|
|
} else if (!strcmp(attr, "delivery-method")) {
|
|
|
|
/* Possible values are: inline, in_band, out_band/specific_name. */
|
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
} else if (!strcmp(attr, "configuration-uri")) {
|
|
|
|
/* NOTE: configuration-uri is supported only under 2 conditions:
|
|
|
|
*--after the delivery-method tag
|
|
|
|
* --with a delivery-method value of out_band */
|
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
} else if (!strcmp(attr, "configuration")) {
|
|
|
|
/* NOTE: configuration is supported only AFTER the delivery-method tag
|
|
|
|
* The configuration value is a base64 encoded packed header */
|
|
|
|
uint8_t *decoded_packet = NULL;
|
|
|
|
int packet_size;
|
|
|
|
size_t decoded_alloc = strlen(value) / 4 * 3 + 4;
|
|
|
|
|
|
|
|
if (decoded_alloc <= INT_MAX) {
|
|
|
|
decoded_packet = av_malloc(decoded_alloc);
|
|
|
|
if (decoded_packet) {
|
|
|
|
packet_size =
|
|
|
|
av_base64_decode(decoded_packet, value, decoded_alloc);
|
|
|
|
|
|
|
|
result = parse_packed_headers
|
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 18:42:52 +00:00
|
|
|
(s, decoded_packet, decoded_packet + packet_size, par,
|
2010-04-01 21:41:48 +00:00
|
|
|
xiph_data);
|
2010-03-22 16:26:29 +00:00
|
|
|
} else {
|
2014-07-05 07:01:07 +00:00
|
|
|
av_log(s, AV_LOG_ERROR,
|
2010-03-22 16:26:29 +00:00
|
|
|
"Out of memory while decoding SDP configuration.\n");
|
2010-04-03 14:15:00 +00:00
|
|
|
result = AVERROR(ENOMEM);
|
2010-03-22 16:26:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-07-05 07:01:07 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "Packet too large\n");
|
2010-03-22 16:26:29 +00:00
|
|
|
result = AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
av_free(decoded_packet);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-01 21:41:48 +00:00
|
|
|
static int xiph_parse_sdp_line(AVFormatContext *s, int st_index,
|
2012-04-07 20:40:37 +00:00
|
|
|
PayloadContext *data, const char *line)
|
2010-03-22 16:26:29 +00:00
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
2012-04-06 20:07:12 +00:00
|
|
|
if (st_index < 0)
|
|
|
|
return 0;
|
|
|
|
|
2010-03-22 16:26:29 +00:00
|
|
|
if (av_strstart(line, "fmtp:", &p)) {
|
2014-07-05 07:01:07 +00:00
|
|
|
return ff_parse_fmtp(s, s->streams[st_index], data, p,
|
2010-06-28 20:32:03 +00:00
|
|
|
xiph_parse_fmtp_pair);
|
2010-03-22 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-12 21:21:06 +00:00
|
|
|
const RTPDynamicProtocolHandler ff_theora_dynamic_handler = {
|
2010-03-22 16:26:29 +00:00
|
|
|
.enc_name = "theora",
|
2010-03-30 23:30:55 +00:00
|
|
|
.codec_type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 09:11:04 +00:00
|
|
|
.codec_id = AV_CODEC_ID_THEORA,
|
2015-02-23 20:18:32 +00:00
|
|
|
.priv_data_size = sizeof(PayloadContext),
|
2010-04-01 21:41:48 +00:00
|
|
|
.parse_sdp_a_line = xiph_parse_sdp_line,
|
2015-02-24 15:01:48 +00:00
|
|
|
.close = xiph_close_context,
|
2015-02-23 20:06:41 +00:00
|
|
|
.parse_packet = xiph_handle_packet,
|
2010-03-22 16:26:29 +00:00
|
|
|
};
|
2010-04-01 21:43:22 +00:00
|
|
|
|
2018-02-12 21:21:06 +00:00
|
|
|
const RTPDynamicProtocolHandler ff_vorbis_dynamic_handler = {
|
2010-04-01 21:43:22 +00:00
|
|
|
.enc_name = "vorbis",
|
2010-04-02 11:33:02 +00:00
|
|
|
.codec_type = AVMEDIA_TYPE_AUDIO,
|
2012-08-05 09:11:04 +00:00
|
|
|
.codec_id = AV_CODEC_ID_VORBIS,
|
2015-02-23 19:51:05 +00:00
|
|
|
.need_parsing = AVSTREAM_PARSE_HEADERS,
|
2015-02-23 20:18:32 +00:00
|
|
|
.priv_data_size = sizeof(PayloadContext),
|
2010-04-01 21:43:22 +00:00
|
|
|
.parse_sdp_a_line = xiph_parse_sdp_line,
|
2015-02-24 15:01:48 +00:00
|
|
|
.close = xiph_close_context,
|
2015-02-23 20:06:41 +00:00
|
|
|
.parse_packet = xiph_handle_packet,
|
2010-04-01 21:43:22 +00:00
|
|
|
};
|