mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-27 01:42:20 +00:00
rtp: h264: Move STAP-A NAL parsing to a function
This commit is contained in:
parent
a9a0b8d6c1
commit
f0a8747996
@ -180,49 +180,13 @@ static int sdp_parse_fmtp_config_h264(AVFormatContext *s,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// return 0 on packet, no more left, 1 on packet, 1 on partial packet
|
||||
static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
|
||||
AVStream *st, AVPacket *pkt, uint32_t *timestamp,
|
||||
const uint8_t *buf, int len, uint16_t seq,
|
||||
int flags)
|
||||
{
|
||||
uint8_t nal;
|
||||
uint8_t type;
|
||||
int result = 0;
|
||||
|
||||
if (!len) {
|
||||
av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
nal = buf[0];
|
||||
type = nal & 0x1f;
|
||||
|
||||
assert(data);
|
||||
assert(buf);
|
||||
|
||||
/* Simplify the case (these are all the nal types used internally by
|
||||
* the h264 codec). */
|
||||
if (type >= 1 && type <= 23)
|
||||
type = 1;
|
||||
switch (type) {
|
||||
case 0: // undefined, but pass them through
|
||||
case 1:
|
||||
if ((result = av_new_packet(pkt, len + sizeof(start_sequence))) < 0)
|
||||
return result;
|
||||
memcpy(pkt->data, start_sequence, sizeof(start_sequence));
|
||||
memcpy(pkt->data + sizeof(start_sequence), buf, len);
|
||||
COUNT_NAL_TYPE(data, nal);
|
||||
break;
|
||||
|
||||
case 24: // STAP-A (one packet, multiple nals)
|
||||
// consume the STAP-A NAL
|
||||
buf++;
|
||||
len--;
|
||||
// first we are going to figure out the total size
|
||||
static int h264_handle_packet_stap_a(AVFormatContext *ctx, AVPacket *pkt,
|
||||
const uint8_t *buf, int len)
|
||||
{
|
||||
int pass = 0;
|
||||
int total_length = 0;
|
||||
uint8_t *dst = NULL;
|
||||
int ret;
|
||||
|
||||
for (pass = 0; pass < 2; pass++) {
|
||||
const uint8_t *src = buf;
|
||||
@ -265,14 +229,57 @@ static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
|
||||
if (pass == 0) {
|
||||
/* now we know the total size of the packet (with the
|
||||
* start sequences added) */
|
||||
if ((result = av_new_packet(pkt, total_length)) < 0)
|
||||
return result;
|
||||
if ((ret = av_new_packet(pkt, total_length)) < 0)
|
||||
return ret;
|
||||
dst = pkt->data;
|
||||
} else {
|
||||
assert(dst - pkt->data == total_length);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// return 0 on packet, no more left, 1 on packet, 1 on partial packet
|
||||
static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
|
||||
AVStream *st, AVPacket *pkt, uint32_t *timestamp,
|
||||
const uint8_t *buf, int len, uint16_t seq,
|
||||
int flags)
|
||||
{
|
||||
uint8_t nal;
|
||||
uint8_t type;
|
||||
int result = 0;
|
||||
|
||||
if (!len) {
|
||||
av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
nal = buf[0];
|
||||
type = nal & 0x1f;
|
||||
|
||||
assert(data);
|
||||
assert(buf);
|
||||
|
||||
/* Simplify the case (these are all the nal types used internally by
|
||||
* the h264 codec). */
|
||||
if (type >= 1 && type <= 23)
|
||||
type = 1;
|
||||
switch (type) {
|
||||
case 0: // undefined, but pass them through
|
||||
case 1:
|
||||
if ((result = av_new_packet(pkt, len + sizeof(start_sequence))) < 0)
|
||||
return result;
|
||||
memcpy(pkt->data, start_sequence, sizeof(start_sequence));
|
||||
memcpy(pkt->data + sizeof(start_sequence), buf, len);
|
||||
COUNT_NAL_TYPE(data, nal);
|
||||
break;
|
||||
|
||||
case 24: // STAP-A (one packet, multiple nals)
|
||||
// consume the STAP-A NAL
|
||||
buf++;
|
||||
len--;
|
||||
// first we are going to figure out the total size
|
||||
result = h264_handle_packet_stap_a(ctx, pkt, buf, len);
|
||||
break;
|
||||
|
||||
case 25: // STAP-B
|
||||
|
Loading…
Reference in New Issue
Block a user