2014-08-26 01:51:59 +03:00
|
|
|
/*
|
|
|
|
* RTP parser for HEVC/H.265 payload format (draft version 6)
|
|
|
|
* Copyright (c) 2014 Thomas Volkert <thomas@homer-conferencing.com>
|
|
|
|
*
|
|
|
|
* 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-01-17 21:27:31 +02:00
|
|
|
#include "libavutil/avassert.h"
|
2014-08-26 01:51:59 +03:00
|
|
|
#include "libavutil/avstring.h"
|
2014-10-03 21:40:13 +03:00
|
|
|
#include "libavutil/base64.h"
|
2015-02-12 21:41:39 +02:00
|
|
|
#include "libavcodec/get_bits.h"
|
2014-08-26 22:00:03 +03:00
|
|
|
|
2014-08-26 01:51:59 +03:00
|
|
|
#include "avformat.h"
|
2019-12-10 23:59:52 +02:00
|
|
|
#include "internal.h"
|
2014-08-26 01:51:59 +03:00
|
|
|
#include "rtpdec.h"
|
2015-02-19 22:22:55 +02:00
|
|
|
#include "rtpdec_formats.h"
|
2014-08-26 01:51:59 +03:00
|
|
|
|
2015-02-12 21:41:39 +02:00
|
|
|
#define RTP_HEVC_PAYLOAD_HEADER_SIZE 2
|
|
|
|
#define RTP_HEVC_FU_HEADER_SIZE 1
|
|
|
|
#define RTP_HEVC_DONL_FIELD_SIZE 2
|
|
|
|
#define RTP_HEVC_DOND_FIELD_SIZE 1
|
|
|
|
#define RTP_HEVC_AP_NALU_LENGTH_FIELD_SIZE 2
|
|
|
|
#define HEVC_SPECIFIED_NAL_UNIT_TYPES 48
|
2014-08-26 01:51:59 +03:00
|
|
|
|
2014-08-26 22:00:03 +03:00
|
|
|
/* SDP out-of-band signaling data */
|
2014-08-26 01:51:59 +03:00
|
|
|
struct PayloadContext {
|
|
|
|
int using_donl_field;
|
|
|
|
int profile_id;
|
2014-10-03 21:40:13 +03:00
|
|
|
uint8_t *sps, *pps, *vps, *sei;
|
|
|
|
int sps_size, pps_size, vps_size, sei_size;
|
2014-08-26 01:51:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t start_sequence[] = { 0x00, 0x00, 0x00, 0x01 };
|
|
|
|
|
|
|
|
static av_cold int hevc_sdp_parse_fmtp_config(AVFormatContext *s,
|
2014-08-26 22:00:03 +03:00
|
|
|
AVStream *stream,
|
|
|
|
PayloadContext *hevc_data,
|
2015-02-24 12:32:17 +02:00
|
|
|
const char *attr, const char *value)
|
2014-08-26 01:51:59 +03:00
|
|
|
{
|
|
|
|
/* profile-space: 0-3 */
|
|
|
|
/* profile-id: 0-31 */
|
|
|
|
if (!strcmp(attr, "profile-id")) {
|
|
|
|
hevc_data->profile_id = atoi(value);
|
2015-03-16 10:57:35 +02:00
|
|
|
av_log(s, AV_LOG_TRACE, "SDP: found profile-id: %d\n", hevc_data->profile_id);
|
2014-08-26 01:51:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tier-flag: 0-1 */
|
|
|
|
/* level-id: 0-255 */
|
|
|
|
/* interop-constraints: [base16] */
|
|
|
|
/* profile-compatibility-indicator: [base16] */
|
|
|
|
/* sprop-sub-layer-id: 0-6, defines highest possible value for TID, default: 6 */
|
|
|
|
/* recv-sub-layer-id: 0-6 */
|
|
|
|
/* max-recv-level-id: 0-255 */
|
|
|
|
/* tx-mode: MSM,SSM */
|
|
|
|
/* sprop-vps: [base64] */
|
|
|
|
/* sprop-sps: [base64] */
|
|
|
|
/* sprop-pps: [base64] */
|
|
|
|
/* sprop-sei: [base64] */
|
2014-10-03 21:40:13 +03:00
|
|
|
if (!strcmp(attr, "sprop-vps") || !strcmp(attr, "sprop-sps") ||
|
|
|
|
!strcmp(attr, "sprop-pps") || !strcmp(attr, "sprop-sei")) {
|
2015-02-19 22:26:40 +02:00
|
|
|
uint8_t **data_ptr = NULL;
|
|
|
|
int *size_ptr = NULL;
|
2014-10-03 21:40:13 +03:00
|
|
|
if (!strcmp(attr, "sprop-vps")) {
|
|
|
|
data_ptr = &hevc_data->vps;
|
|
|
|
size_ptr = &hevc_data->vps_size;
|
|
|
|
} else if (!strcmp(attr, "sprop-sps")) {
|
|
|
|
data_ptr = &hevc_data->sps;
|
|
|
|
size_ptr = &hevc_data->sps_size;
|
|
|
|
} else if (!strcmp(attr, "sprop-pps")) {
|
|
|
|
data_ptr = &hevc_data->pps;
|
|
|
|
size_ptr = &hevc_data->pps_size;
|
|
|
|
} else if (!strcmp(attr, "sprop-sei")) {
|
|
|
|
data_ptr = &hevc_data->sei;
|
|
|
|
size_ptr = &hevc_data->sei_size;
|
2015-01-17 21:27:31 +02:00
|
|
|
} else
|
|
|
|
av_assert0(0);
|
2014-10-03 21:40:13 +03:00
|
|
|
|
2015-02-19 22:22:55 +02:00
|
|
|
ff_h264_parse_sprop_parameter_sets(s, data_ptr,
|
|
|
|
size_ptr, value);
|
2014-10-03 21:40:13 +03:00
|
|
|
}
|
|
|
|
|
2014-08-26 01:51:59 +03:00
|
|
|
/* max-lsr, max-lps, max-cpb, max-dpb, max-br, max-tr, max-tc */
|
|
|
|
/* max-fps */
|
|
|
|
|
|
|
|
/* sprop-max-don-diff: 0-32767
|
|
|
|
|
|
|
|
When the RTP stream depends on one or more other RTP
|
|
|
|
streams (in this case tx-mode MUST be equal to "MSM" and
|
|
|
|
MSM is in use), this parameter MUST be present and the
|
|
|
|
value MUST be greater than 0.
|
|
|
|
*/
|
|
|
|
if (!strcmp(attr, "sprop-max-don-diff")) {
|
2014-08-26 22:00:03 +03:00
|
|
|
if (atoi(value) > 0)
|
2014-08-26 01:51:59 +03:00
|
|
|
hevc_data->using_donl_field = 1;
|
2015-03-16 10:57:35 +02:00
|
|
|
av_log(s, AV_LOG_TRACE, "Found sprop-max-don-diff in SDP, DON field usage is: %d\n",
|
2014-08-26 22:00:03 +03:00
|
|
|
hevc_data->using_donl_field);
|
2014-08-26 01:51:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sprop-depack-buf-nalus: 0-32767 */
|
|
|
|
if (!strcmp(attr, "sprop-depack-buf-nalus")) {
|
2014-08-26 22:00:03 +03:00
|
|
|
if (atoi(value) > 0)
|
2014-08-26 01:51:59 +03:00
|
|
|
hevc_data->using_donl_field = 1;
|
2015-03-16 10:57:35 +02:00
|
|
|
av_log(s, AV_LOG_TRACE, "Found sprop-depack-buf-nalus in SDP, DON field usage is: %d\n",
|
2014-08-26 22:00:03 +03:00
|
|
|
hevc_data->using_donl_field);
|
2014-08-26 01:51:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sprop-depack-buf-bytes: 0-4294967295 */
|
|
|
|
/* depack-buf-cap */
|
|
|
|
/* sprop-segmentation-id: 0-3 */
|
|
|
|
/* sprop-spatial-segmentation-idc: [base16] */
|
|
|
|
/* dec-parallel-ca: */
|
|
|
|
/* include-dph */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold int hevc_parse_sdp_line(AVFormatContext *ctx, int st_index,
|
2014-08-26 22:00:03 +03:00
|
|
|
PayloadContext *hevc_data, const char *line)
|
2014-08-26 01:51:59 +03:00
|
|
|
{
|
|
|
|
AVStream *current_stream;
|
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 21:42:52 +03:00
|
|
|
AVCodecParameters *par;
|
2014-08-26 01:51:59 +03:00
|
|
|
const char *sdp_line_ptr = line;
|
|
|
|
|
|
|
|
if (st_index < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
current_stream = ctx->streams[st_index];
|
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 21:42:52 +03:00
|
|
|
par = current_stream->codecpar;
|
2014-08-26 01:51:59 +03:00
|
|
|
|
|
|
|
if (av_strstart(sdp_line_ptr, "framesize:", &sdp_line_ptr)) {
|
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 21:42:52 +03:00
|
|
|
ff_h264_parse_framesize(par, sdp_line_ptr);
|
2014-08-26 01:51:59 +03:00
|
|
|
} else if (av_strstart(sdp_line_ptr, "fmtp:", &sdp_line_ptr)) {
|
2014-10-03 21:40:13 +03:00
|
|
|
int ret = ff_parse_fmtp(ctx, current_stream, hevc_data, sdp_line_ptr,
|
|
|
|
hevc_sdp_parse_fmtp_config);
|
|
|
|
if (hevc_data->vps_size || hevc_data->sps_size ||
|
|
|
|
hevc_data->pps_size || hevc_data->sei_size) {
|
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 21:42:52 +03:00
|
|
|
par->extradata_size = hevc_data->vps_size + hevc_data->sps_size +
|
|
|
|
hevc_data->pps_size + hevc_data->sei_size;
|
2019-12-10 23:59:52 +02:00
|
|
|
if ((ret = ff_alloc_extradata(par, par->extradata_size)) >= 0) {
|
2014-10-03 21:40:13 +03:00
|
|
|
int pos = 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 21:42:52 +03:00
|
|
|
memcpy(par->extradata + pos, hevc_data->vps, hevc_data->vps_size);
|
2014-10-03 21:40:13 +03:00
|
|
|
pos += hevc_data->vps_size;
|
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 21:42:52 +03:00
|
|
|
memcpy(par->extradata + pos, hevc_data->sps, hevc_data->sps_size);
|
2014-10-03 21:40:13 +03:00
|
|
|
pos += hevc_data->sps_size;
|
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 21:42:52 +03:00
|
|
|
memcpy(par->extradata + pos, hevc_data->pps, hevc_data->pps_size);
|
2014-10-03 21:40:13 +03:00
|
|
|
pos += hevc_data->pps_size;
|
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 21:42:52 +03:00
|
|
|
memcpy(par->extradata + pos, hevc_data->sei, hevc_data->sei_size);
|
2014-10-03 21:40:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
av_freep(&hevc_data->vps);
|
|
|
|
av_freep(&hevc_data->sps);
|
|
|
|
av_freep(&hevc_data->pps);
|
|
|
|
av_freep(&hevc_data->sei);
|
|
|
|
hevc_data->vps_size = 0;
|
|
|
|
hevc_data->sps_size = 0;
|
|
|
|
hevc_data->pps_size = 0;
|
|
|
|
hevc_data->sei_size = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
2014-08-26 01:51:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hevc_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_hevc_ctx,
|
|
|
|
AVStream *st, AVPacket *pkt, uint32_t *timestamp,
|
|
|
|
const uint8_t *buf, int len, uint16_t seq,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
const uint8_t *rtp_pl = buf;
|
|
|
|
int tid, lid, nal_type;
|
|
|
|
int first_fragment, last_fragment, fu_type;
|
|
|
|
uint8_t new_nal_header[2];
|
2014-08-26 22:00:03 +03:00
|
|
|
int res = 0;
|
2014-08-26 01:51:59 +03:00
|
|
|
|
2014-08-26 22:00:03 +03:00
|
|
|
/* sanity check for size of input packet: 1 byte payload at least */
|
|
|
|
if (len < RTP_HEVC_PAYLOAD_HEADER_SIZE + 1) {
|
2014-08-26 01:51:59 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Too short RTP/HEVC packet, got %d bytes\n", len);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-02-23 23:13:55 +02:00
|
|
|
* decode the HEVC payload header according to section 4 of draft version 6:
|
|
|
|
*
|
|
|
|
* 0 1
|
|
|
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* |F| Type | LayerId | TID |
|
|
|
|
* +-------------+-----------------+
|
|
|
|
*
|
|
|
|
* Forbidden zero (F): 1 bit
|
|
|
|
* NAL unit type (Type): 6 bits
|
|
|
|
* NUH layer ID (LayerId): 6 bits
|
|
|
|
* NUH temporal ID plus 1 (TID): 3 bits
|
|
|
|
*/
|
2014-08-26 01:51:59 +03:00
|
|
|
nal_type = (buf[0] >> 1) & 0x3f;
|
|
|
|
lid = ((buf[0] << 5) & 0x20) | ((buf[1] >> 3) & 0x1f);
|
|
|
|
tid = buf[1] & 0x07;
|
|
|
|
|
|
|
|
/* sanity check for correct layer ID */
|
2014-08-26 22:00:03 +03:00
|
|
|
if (lid) {
|
2014-08-26 01:51:59 +03:00
|
|
|
/* future scalable or 3D video coding extensions */
|
2015-12-15 20:59:14 +02:00
|
|
|
avpriv_report_missing_feature(ctx, "Multi-layer HEVC coding");
|
2014-08-26 01:51:59 +03:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check for correct temporal ID */
|
2014-08-26 22:00:03 +03:00
|
|
|
if (!tid) {
|
2014-08-26 01:51:59 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Illegal temporal ID in RTP/HEVC packet\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check for correct NAL unit type */
|
2014-08-26 22:00:03 +03:00
|
|
|
if (nal_type > 50) {
|
2014-08-26 01:51:59 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Unsupported (HEVC) NAL type (%d)\n", nal_type);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2014-08-26 22:00:03 +03:00
|
|
|
switch (nal_type) {
|
2014-08-26 01:51:59 +03:00
|
|
|
/* video parameter set (VPS) */
|
|
|
|
case 32:
|
|
|
|
/* sequence parameter set (SPS) */
|
|
|
|
case 33:
|
|
|
|
/* picture parameter set (PPS) */
|
|
|
|
case 34:
|
|
|
|
/* supplemental enhancement information (SEI) */
|
|
|
|
case 39:
|
|
|
|
/* single NAL unit packet */
|
|
|
|
default:
|
|
|
|
/* create A/V packet */
|
|
|
|
if ((res = av_new_packet(pkt, sizeof(start_sequence) + len)) < 0)
|
|
|
|
return res;
|
|
|
|
/* A/V packet: copy start sequence */
|
|
|
|
memcpy(pkt->data, start_sequence, sizeof(start_sequence));
|
|
|
|
/* A/V packet: copy NAL unit data */
|
|
|
|
memcpy(pkt->data + sizeof(start_sequence), buf, len);
|
|
|
|
|
2015-02-12 21:41:39 +02:00
|
|
|
break;
|
|
|
|
/* aggregated packet (AP) - with two or more NAL units */
|
|
|
|
case 48:
|
|
|
|
/* pass the HEVC payload header */
|
|
|
|
buf += RTP_HEVC_PAYLOAD_HEADER_SIZE;
|
|
|
|
len -= RTP_HEVC_PAYLOAD_HEADER_SIZE;
|
|
|
|
|
2015-02-22 23:25:28 +02:00
|
|
|
/* pass the HEVC DONL field */
|
|
|
|
if (rtp_hevc_ctx->using_donl_field) {
|
|
|
|
buf += RTP_HEVC_DONL_FIELD_SIZE;
|
|
|
|
len -= RTP_HEVC_DONL_FIELD_SIZE;
|
|
|
|
}
|
|
|
|
|
2015-02-21 14:19:29 +02:00
|
|
|
res = ff_h264_handle_aggregated_packet(ctx, rtp_hevc_ctx, pkt, buf, len,
|
2015-02-13 23:43:16 +02:00
|
|
|
rtp_hevc_ctx->using_donl_field ?
|
2015-02-22 23:25:28 +02:00
|
|
|
RTP_HEVC_DOND_FIELD_SIZE : 0,
|
2015-02-13 23:43:16 +02:00
|
|
|
NULL, 0);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
2014-08-26 01:51:59 +03:00
|
|
|
break;
|
|
|
|
/* fragmentation unit (FU) */
|
|
|
|
case 49:
|
|
|
|
/* pass the HEVC payload header */
|
|
|
|
buf += RTP_HEVC_PAYLOAD_HEADER_SIZE;
|
|
|
|
len -= RTP_HEVC_PAYLOAD_HEADER_SIZE;
|
|
|
|
|
2014-08-26 22:00:03 +03:00
|
|
|
/*
|
2015-02-23 23:13:55 +02:00
|
|
|
* decode the FU header
|
|
|
|
*
|
|
|
|
* 0 1 2 3 4 5 6 7
|
|
|
|
* +-+-+-+-+-+-+-+-+
|
|
|
|
* |S|E| FuType |
|
|
|
|
* +---------------+
|
|
|
|
*
|
|
|
|
* Start fragment (S): 1 bit
|
|
|
|
* End fragment (E): 1 bit
|
|
|
|
* FuType: 6 bits
|
|
|
|
*/
|
2014-08-26 01:51:59 +03:00
|
|
|
first_fragment = buf[0] & 0x80;
|
2014-08-26 22:00:03 +03:00
|
|
|
last_fragment = buf[0] & 0x40;
|
|
|
|
fu_type = buf[0] & 0x3f;
|
2014-08-26 01:51:59 +03:00
|
|
|
|
|
|
|
/* pass the HEVC FU header */
|
|
|
|
buf += RTP_HEVC_FU_HEADER_SIZE;
|
|
|
|
len -= RTP_HEVC_FU_HEADER_SIZE;
|
|
|
|
|
2014-08-26 22:00:03 +03:00
|
|
|
/* pass the HEVC DONL field */
|
|
|
|
if (rtp_hevc_ctx->using_donl_field) {
|
|
|
|
buf += RTP_HEVC_DONL_FIELD_SIZE;
|
|
|
|
len -= RTP_HEVC_DONL_FIELD_SIZE;
|
2014-08-26 01:51:59 +03:00
|
|
|
}
|
|
|
|
|
2015-03-16 10:57:35 +02:00
|
|
|
av_log(ctx, AV_LOG_TRACE, " FU type %d with %d bytes\n", fu_type, len);
|
2014-08-26 01:51:59 +03:00
|
|
|
|
2014-09-21 14:50:12 +03:00
|
|
|
/* sanity check for size of input packet: 1 byte payload at least */
|
2015-02-23 23:17:54 +02:00
|
|
|
if (len <= 0) {
|
2014-09-21 14:50:12 +03:00
|
|
|
if (len < 0) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Too short RTP/HEVC packet, got %d bytes of NAL unit type %d\n",
|
|
|
|
len, nal_type);
|
2015-02-25 00:16:46 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2014-09-21 14:50:12 +03:00
|
|
|
} else {
|
2015-02-25 00:16:46 +02:00
|
|
|
return AVERROR(EAGAIN);
|
2014-09-21 14:50:12 +03:00
|
|
|
}
|
2014-08-26 01:51:59 +03:00
|
|
|
}
|
|
|
|
|
2015-02-23 23:17:54 +02:00
|
|
|
if (first_fragment && last_fragment) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Illegal combination of S and E bit in RTP/HEVC packet\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_nal_header[0] = (rtp_pl[0] & 0x81) | (fu_type << 1);
|
|
|
|
new_nal_header[1] = rtp_pl[1];
|
|
|
|
|
2015-02-23 23:28:34 +02:00
|
|
|
res = ff_h264_handle_frag_packet(pkt, buf, len, first_fragment,
|
|
|
|
new_nal_header, sizeof(new_nal_header));
|
2014-08-26 22:00:03 +03:00
|
|
|
|
2014-08-26 01:51:59 +03:00
|
|
|
break;
|
|
|
|
/* PACI packet */
|
|
|
|
case 50:
|
|
|
|
/* Temporal scalability control information (TSCI) */
|
2015-12-15 20:59:14 +02:00
|
|
|
avpriv_report_missing_feature(ctx, "PACI packets for RTP/HEVC");
|
2014-08-26 01:51:59 +03:00
|
|
|
res = AVERROR_PATCHWELCOME;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt->stream_index = st->index;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-02-12 23:21:06 +02:00
|
|
|
const RTPDynamicProtocolHandler ff_hevc_dynamic_handler = {
|
2014-08-26 01:51:59 +03:00
|
|
|
.enc_name = "H265",
|
|
|
|
.codec_type = AVMEDIA_TYPE_VIDEO,
|
2014-08-26 22:00:03 +03:00
|
|
|
.codec_id = AV_CODEC_ID_HEVC,
|
2015-02-23 21:51:05 +02:00
|
|
|
.need_parsing = AVSTREAM_PARSE_FULL,
|
2015-02-23 22:18:32 +02:00
|
|
|
.priv_data_size = sizeof(PayloadContext),
|
2014-08-26 01:51:59 +03:00
|
|
|
.parse_sdp_a_line = hevc_parse_sdp_line,
|
2015-02-23 22:06:41 +02:00
|
|
|
.parse_packet = hevc_handle_packet,
|
2014-08-26 01:51:59 +03:00
|
|
|
};
|