rtpenc: HEVC/H.265 support
Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
a2efbecc4e
commit
ddf5fb71ee
@ -3,7 +3,7 @@ releases are sorted from youngest to oldest.
|
|||||||
|
|
||||||
version <next>:
|
version <next>:
|
||||||
- aliases and defaults for Ogg subtypes (opus, spx)
|
- aliases and defaults for Ogg subtypes (opus, spx)
|
||||||
- HEVC/H.265 RTP payload format (draft v6) depacketizer
|
- HEVC/H.265 RTP payload format (draft v6) packetizer and depacketizer
|
||||||
- avplay now exits by default at the end of playback
|
- avplay now exits by default at the end of playback
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,6 +291,7 @@ OBJS-$(CONFIG_RTP_MUXER) += rtp.o \
|
|||||||
rtpenc_amr.o \
|
rtpenc_amr.o \
|
||||||
rtpenc_h263.o \
|
rtpenc_h263.o \
|
||||||
rtpenc_h263_rfc2190.o \
|
rtpenc_h263_rfc2190.o \
|
||||||
|
rtpenc_hevc.o \
|
||||||
rtpenc_jpeg.o \
|
rtpenc_jpeg.o \
|
||||||
rtpenc_mpv.o \
|
rtpenc_mpv.o \
|
||||||
rtpenc.o \
|
rtpenc.o \
|
||||||
|
@ -52,6 +52,7 @@ static int is_supported(enum AVCodecID id)
|
|||||||
case AV_CODEC_ID_H263:
|
case AV_CODEC_ID_H263:
|
||||||
case AV_CODEC_ID_H263P:
|
case AV_CODEC_ID_H263P:
|
||||||
case AV_CODEC_ID_H264:
|
case AV_CODEC_ID_H264:
|
||||||
|
case AV_CODEC_ID_HEVC:
|
||||||
case AV_CODEC_ID_MPEG1VIDEO:
|
case AV_CODEC_ID_MPEG1VIDEO:
|
||||||
case AV_CODEC_ID_MPEG2VIDEO:
|
case AV_CODEC_ID_MPEG2VIDEO:
|
||||||
case AV_CODEC_ID_MPEG4:
|
case AV_CODEC_ID_MPEG4:
|
||||||
@ -196,6 +197,15 @@ static int rtp_write_header(AVFormatContext *s1)
|
|||||||
s->nal_length_size = (st->codec->extradata[4] & 0x03) + 1;
|
s->nal_length_size = (st->codec->extradata[4] & 0x03) + 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case AV_CODEC_ID_HEVC:
|
||||||
|
/* Only check for the standardized hvcC version of extradata, keeping
|
||||||
|
* things simple and similar to the avcC/H264 case above, instead
|
||||||
|
* of trying to handle the pre-standardization versions (as in
|
||||||
|
* libavcodec/hevc.c). */
|
||||||
|
if (st->codec->extradata_size > 21 && st->codec->extradata[0] == 1) {
|
||||||
|
s->nal_length_size = (st->codec->extradata[21] & 0x03) + 1;
|
||||||
|
}
|
||||||
|
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;
|
if (!s->max_frames_per_packet) s->max_frames_per_packet = 15;
|
||||||
@ -566,6 +576,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||||||
case AV_CODEC_ID_H263P:
|
case AV_CODEC_ID_H263P:
|
||||||
ff_rtp_send_h263(s1, pkt->data, size);
|
ff_rtp_send_h263(s1, pkt->data, size);
|
||||||
break;
|
break;
|
||||||
|
case AV_CODEC_ID_HEVC:
|
||||||
|
ff_rtp_send_hevc(s1, pkt->data, size);
|
||||||
|
break;
|
||||||
case AV_CODEC_ID_VORBIS:
|
case AV_CODEC_ID_VORBIS:
|
||||||
case AV_CODEC_ID_THEORA:
|
case AV_CODEC_ID_THEORA:
|
||||||
ff_rtp_send_xiph(s1, pkt->data, size);
|
ff_rtp_send_xiph(s1, pkt->data, size);
|
||||||
|
@ -84,6 +84,7 @@ void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size);
|
|||||||
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size);
|
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size);
|
||||||
void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf1, int size,
|
void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf1, int size,
|
||||||
const uint8_t *mb_info, int mb_info_size);
|
const uint8_t *mb_info, int mb_info_size);
|
||||||
|
void ff_rtp_send_hevc(AVFormatContext *s1, const uint8_t *buf1, int size);
|
||||||
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);
|
||||||
void ff_rtp_send_latm(AVFormatContext *s1, const uint8_t *buff, int size);
|
void ff_rtp_send_latm(AVFormatContext *s1, const uint8_t *buff, int size);
|
||||||
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);
|
||||||
|
130
libavformat/rtpenc_hevc.c
Normal file
130
libavformat/rtpenc_hevc.c
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
* RTP packetizer for HEVC/H.265 payload format (draft version 6)
|
||||||
|
* Copyright (c) 2014 Thomas Volkert <thomas@homer-conferencing.com>
|
||||||
|
*
|
||||||
|
* This file is part of Libav.
|
||||||
|
*
|
||||||
|
* Libav 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.
|
||||||
|
*
|
||||||
|
* Libav 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 Libav; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "avc.h"
|
||||||
|
#include "avformat.h"
|
||||||
|
#include "rtpenc.h"
|
||||||
|
|
||||||
|
#define RTP_HEVC_HEADERS_SIZE 3
|
||||||
|
|
||||||
|
static void nal_send(AVFormatContext *ctx, const uint8_t *buf, int len, int last_packet_of_frame)
|
||||||
|
{
|
||||||
|
RTPMuxContext *rtp_ctx = ctx->priv_data;
|
||||||
|
int rtp_payload_size = rtp_ctx->max_payload_size - RTP_HEVC_HEADERS_SIZE;
|
||||||
|
int nal_type = (buf[0] >> 1) & 0x3F;
|
||||||
|
|
||||||
|
/* send it as one single NAL unit? */
|
||||||
|
if (len <= rtp_ctx->max_payload_size) {
|
||||||
|
/* use the original NAL unit buffer and transmit it as RTP payload */
|
||||||
|
ff_rtp_send_data(ctx, buf, len, last_packet_of_frame);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
create the HEVC payload header and transmit the buffer as fragmentation units (FU)
|
||||||
|
|
||||||
|
0 1
|
||||||
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|F| Type | LayerId | TID |
|
||||||
|
+-------------+-----------------+
|
||||||
|
|
||||||
|
F = 0
|
||||||
|
Type = 49 (fragmentation unit (FU))
|
||||||
|
LayerId = 0
|
||||||
|
TID = 1
|
||||||
|
*/
|
||||||
|
rtp_ctx->buf[0] = 49 << 1;
|
||||||
|
rtp_ctx->buf[1] = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
create the FU header
|
||||||
|
|
||||||
|
0 1 2 3 4 5 6 7
|
||||||
|
+-+-+-+-+-+-+-+-+
|
||||||
|
|S|E| FuType |
|
||||||
|
+---------------+
|
||||||
|
|
||||||
|
S = variable
|
||||||
|
E = variable
|
||||||
|
FuType = NAL unit type
|
||||||
|
*/
|
||||||
|
rtp_ctx->buf[2] = nal_type;
|
||||||
|
/* set the S bit: mark as start fragment */
|
||||||
|
rtp_ctx->buf[2] |= 1 << 7;
|
||||||
|
|
||||||
|
/* pass the original NAL header */
|
||||||
|
buf += 2;
|
||||||
|
len -= 2;
|
||||||
|
|
||||||
|
while (len > rtp_payload_size) {
|
||||||
|
/* complete and send current RTP packet */
|
||||||
|
memcpy(&rtp_ctx->buf[RTP_HEVC_HEADERS_SIZE], buf, rtp_payload_size);
|
||||||
|
ff_rtp_send_data(ctx, rtp_ctx->buf, rtp_ctx->max_payload_size, 0);
|
||||||
|
|
||||||
|
buf += rtp_payload_size;
|
||||||
|
len -= rtp_payload_size;
|
||||||
|
|
||||||
|
/* reset the S bit */
|
||||||
|
rtp_ctx->buf[2] &= ~(1 << 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the E bit: mark as last fragment */
|
||||||
|
rtp_ctx->buf[2] |= 1 << 6;
|
||||||
|
|
||||||
|
/* complete and send last RTP packet */
|
||||||
|
memcpy(&rtp_ctx->buf[RTP_HEVC_HEADERS_SIZE], buf, len);
|
||||||
|
ff_rtp_send_data(ctx, rtp_ctx->buf, len + 2, last_packet_of_frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ff_rtp_send_hevc(AVFormatContext *ctx, const uint8_t *frame_buf, int frame_size)
|
||||||
|
{
|
||||||
|
const uint8_t *next_NAL_unit;
|
||||||
|
const uint8_t *buf_ptr, *buf_end = frame_buf + frame_size;
|
||||||
|
RTPMuxContext *rtp_ctx = ctx->priv_data;
|
||||||
|
|
||||||
|
/* use the default 90 KHz time stamp */
|
||||||
|
rtp_ctx->timestamp = rtp_ctx->cur_timestamp;
|
||||||
|
|
||||||
|
if (rtp_ctx->nal_length_size)
|
||||||
|
buf_ptr = ff_avc_mp4_find_startcode(frame_buf, buf_end, rtp_ctx->nal_length_size) ? frame_buf : buf_end;
|
||||||
|
else
|
||||||
|
buf_ptr = ff_avc_find_startcode(frame_buf, buf_end);
|
||||||
|
|
||||||
|
/* find all NAL units and send them as separate packets */
|
||||||
|
while (buf_ptr < buf_end) {
|
||||||
|
if (rtp_ctx->nal_length_size) {
|
||||||
|
next_NAL_unit = ff_avc_mp4_find_startcode(buf_ptr, buf_end, rtp_ctx->nal_length_size);
|
||||||
|
if (!next_NAL_unit)
|
||||||
|
next_NAL_unit = buf_end;
|
||||||
|
|
||||||
|
buf_ptr += rtp_ctx->nal_length_size;
|
||||||
|
} else {
|
||||||
|
while (!*(buf_ptr++))
|
||||||
|
;
|
||||||
|
next_NAL_unit = ff_avc_find_startcode(buf_ptr, buf_end);
|
||||||
|
}
|
||||||
|
/* send the next NAL unit */
|
||||||
|
nal_send(ctx, buf_ptr, next_NAL_unit - buf_ptr, next_NAL_unit == buf_end);
|
||||||
|
|
||||||
|
/* jump to the next NAL unit */
|
||||||
|
buf_ptr = next_NAL_unit;
|
||||||
|
}
|
||||||
|
}
|
@ -428,6 +428,12 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c,
|
|||||||
payload_type,
|
payload_type,
|
||||||
payload_type, c->width, c->height);
|
payload_type, c->width, c->height);
|
||||||
break;
|
break;
|
||||||
|
case AV_CODEC_ID_HEVC:
|
||||||
|
if (c->extradata_size)
|
||||||
|
av_log(NULL, AV_LOG_WARNING, "HEVC extradata not currently "
|
||||||
|
"passed properly through SDP\n");
|
||||||
|
av_strlcatf(buff, size, "a=rtpmap:%d H265/90000\r\n", payload_type);
|
||||||
|
break;
|
||||||
case AV_CODEC_ID_MPEG4:
|
case AV_CODEC_ID_MPEG4:
|
||||||
if (c->extradata_size) {
|
if (c->extradata_size) {
|
||||||
config = extradata2config(c);
|
config = extradata2config(c);
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#include "libavutil/version.h"
|
#include "libavutil/version.h"
|
||||||
|
|
||||||
#define LIBAVFORMAT_VERSION_MAJOR 56
|
#define LIBAVFORMAT_VERSION_MAJOR 56
|
||||||
#define LIBAVFORMAT_VERSION_MINOR 4
|
#define LIBAVFORMAT_VERSION_MINOR 5
|
||||||
#define LIBAVFORMAT_VERSION_MICRO 0
|
#define LIBAVFORMAT_VERSION_MICRO 0
|
||||||
|
|
||||||
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
|
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user