diff options
author | Martin Storsjö <martin@martin.st> | 2015-02-23 23:28:34 +0200 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2015-02-24 16:25:28 +0200 |
commit | 3567b91e49c6ae101c9a35c90f46b8ad9890ac15 (patch) | |
tree | 733470bf41dc595d4b80f670e98539f73eb8b681 /libavformat/rtpdec_h264.c | |
parent | f3449062a8d100ac4f703647336c32b126aa99f1 (diff) |
rtpdec_hevc: Share the implementation of fragmented packets with h264
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/rtpdec_h264.c')
-rw-r--r-- | libavformat/rtpdec_h264.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index ba166b87b6..e624cc962e 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -257,12 +257,32 @@ int ff_h264_handle_aggregated_packet(AVFormatContext *ctx, AVPacket *pkt, return 0; } +int ff_h264_handle_frag_packet(AVPacket *pkt, const uint8_t *buf, int len, + int start_bit, const uint8_t *nal_header, + int nal_header_len) +{ + int ret; + int tot_len = len; + int pos = 0; + if (start_bit) + tot_len += sizeof(start_sequence) + nal_header_len; + if ((ret = av_new_packet(pkt, tot_len)) < 0) + return ret; + if (start_bit) { + memcpy(pkt->data + pos, start_sequence, sizeof(start_sequence)); + pos += sizeof(start_sequence); + memcpy(pkt->data + pos, nal_header, nal_header_len); + pos += nal_header_len; + } + memcpy(pkt->data + pos, buf, len); + return 0; +} + static int h264_handle_packet_fu_a(AVFormatContext *ctx, AVPacket *pkt, const uint8_t *buf, int len, int *nal_counters, int nal_mask) { uint8_t fu_indicator, fu_header, start_bit, nal_type, nal; - int ret; if (len < 3) { av_log(ctx, AV_LOG_ERROR, "Too short data for FU-A H264 RTP packet\n"); @@ -279,22 +299,9 @@ static int h264_handle_packet_fu_a(AVFormatContext *ctx, AVPacket *pkt, buf += 2; len -= 2; - if (start_bit) { - if (nal_counters) - nal_counters[nal_type & nal_mask]++; - /* copy in the start sequence, and the reconstructed nal */ - if ((ret = av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len)) < 0) - return ret; - memcpy(pkt->data, start_sequence, sizeof(start_sequence)); - pkt->data[sizeof(start_sequence)] = nal; - memcpy(pkt->data + sizeof(start_sequence) + sizeof(nal), buf, len); - } else { - if ((ret = av_new_packet(pkt, len)) < 0) - return ret; - memcpy(pkt->data, buf, len); - } - - return 0; + if (start_bit && nal_counters) + nal_counters[nal_type & nal_mask]++; + return ff_h264_handle_frag_packet(pkt, buf, len, start_bit, &nal, 1); } // return 0 on packet, no more left, 1 on packet, 1 on partial packet |