2010-07-01 20:12:58 +00:00
|
|
|
/*
|
|
|
|
* Sorenson-3 (SVQ3/SV3V) payload for RTP
|
|
|
|
* Copyright (c) 2010 Ronald S. Bultje
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief RTP support for the SV3V (SVQ3) payload
|
|
|
|
* @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
|
2011-07-14 01:56:07 +00:00
|
|
|
* @see http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization
|
2010-07-01 20:12:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2010-07-25 19:12:35 +00:00
|
|
|
#include "libavutil/intreadwrite.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-07-01 20:12:58 +00:00
|
|
|
#include "rtp.h"
|
|
|
|
#include "rtpdec.h"
|
2010-07-30 12:04:27 +00:00
|
|
|
#include "rtpdec_formats.h"
|
2010-07-01 20:12:58 +00:00
|
|
|
|
|
|
|
struct PayloadContext {
|
2011-02-20 10:04:12 +00:00
|
|
|
AVIOContext *pktbuf;
|
2010-07-01 20:12:58 +00:00
|
|
|
int64_t timestamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** return 0 on packet, <0 on partial packet or error... */
|
|
|
|
static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
|
|
|
|
AVStream *st, AVPacket *pkt,
|
|
|
|
uint32_t *timestamp,
|
2012-12-10 12:38:32 +00:00
|
|
|
const uint8_t *buf, int len, uint16_t seq,
|
|
|
|
int flags)
|
2010-07-01 20:12:58 +00:00
|
|
|
{
|
|
|
|
int config_packet, start_packet, end_packet;
|
|
|
|
|
|
|
|
if (len < 2)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
config_packet = buf[0] & 0x40;
|
|
|
|
start_packet = buf[0] & 0x20;
|
|
|
|
end_packet = buf[0] & 0x10;
|
|
|
|
buf += 2; // ignore buf[1]
|
|
|
|
len -= 2;
|
|
|
|
|
|
|
|
if (config_packet) {
|
|
|
|
|
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_freep(&st->codecpar->extradata);
|
|
|
|
st->codecpar->extradata_size = 0;
|
2010-07-01 20:12:58 +00:00
|
|
|
|
2016-04-10 19:58:15 +00:00
|
|
|
if (len < 2 || ff_alloc_extradata(st->codecpar, len + 8))
|
2010-07-01 20:12:58 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
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
|
|
|
memcpy(st->codecpar->extradata, "SEQH", 4);
|
|
|
|
AV_WB32(st->codecpar->extradata + 4, len);
|
|
|
|
memcpy(st->codecpar->extradata + 8, buf, len);
|
2010-07-01 20:12:58 +00:00
|
|
|
|
2012-08-05 09:11:04 +00:00
|
|
|
/* We set codec_id to AV_CODEC_ID_NONE initially to
|
2010-07-01 20:12:58 +00:00
|
|
|
* delay decoder initialization since extradata is
|
|
|
|
* carried within the RTP stream, not SDP. Here,
|
2012-08-05 09:11:04 +00:00
|
|
|
* by setting codec_id to AV_CODEC_ID_SVQ3, we are signalling
|
2010-07-01 20:12:58 +00:00
|
|
|
* to the decoder that it is OK to initialize. */
|
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
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_SVQ3;
|
2010-07-01 20:12:58 +00:00
|
|
|
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_packet) {
|
|
|
|
int res;
|
|
|
|
|
2015-02-24 11:37:03 +00:00
|
|
|
ffio_free_dyn_buf(&sv->pktbuf);
|
2011-03-17 07:13:34 +00:00
|
|
|
if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0)
|
2010-07-01 20:12:58 +00:00
|
|
|
return res;
|
|
|
|
sv->timestamp = *timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sv->pktbuf)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2011-02-21 18:28:17 +00:00
|
|
|
avio_write(sv->pktbuf, buf, len);
|
2010-07-01 20:12:58 +00:00
|
|
|
|
|
|
|
if (end_packet) {
|
2012-11-01 13:03:04 +00:00
|
|
|
int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2010-07-14 12:27:26 +00:00
|
|
|
*timestamp = sv->timestamp;
|
2010-07-01 20:12:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
}
|
|
|
|
|
2015-02-24 15:01:48 +00:00
|
|
|
static void svq3_close_context(PayloadContext *sv)
|
2010-07-01 20:12:58 +00:00
|
|
|
{
|
2015-02-24 11:37:03 +00:00
|
|
|
ffio_free_dyn_buf(&sv->pktbuf);
|
2010-07-01 20:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RTPDynamicProtocolHandler ff_svq3_dynamic_handler = {
|
2010-11-29 16:04:04 +00:00
|
|
|
.enc_name = "X-SV3V-ES",
|
|
|
|
.codec_type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 09:11:04 +00:00
|
|
|
.codec_id = AV_CODEC_ID_NONE, // see if (config_packet) above
|
2015-02-23 20:18:32 +00:00
|
|
|
.priv_data_size = sizeof(PayloadContext),
|
2015-02-24 15:01:48 +00:00
|
|
|
.close = svq3_close_context,
|
2010-11-29 16:04:04 +00:00
|
|
|
.parse_packet = svq3_parse_packet,
|
2010-07-01 20:12:58 +00:00
|
|
|
};
|