| Line | Branch | Exec | Source | 
|---|---|---|---|
| 1 | /* | ||
| 2 | * HEVC Annex B format parser | ||
| 3 | * | ||
| 4 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "libavutil/common.h" | ||
| 24 | #include "libavutil/mem.h" | ||
| 25 | |||
| 26 | #include "golomb.h" | ||
| 27 | #include "hevc.h" | ||
| 28 | #include "parse.h" | ||
| 29 | #include "ps.h" | ||
| 30 | #include "sei.h" | ||
| 31 | #include "h2645_parse.h" | ||
| 32 | #include "parser.h" | ||
| 33 | |||
| 34 | #define START_CODE 0x000001 ///< start_code_prefix_one_3bytes | ||
| 35 | |||
| 36 | #define IS_IRAP_NAL(nal) (nal->type >= 16 && nal->type <= 23) | ||
| 37 | #define IS_IDR_NAL(nal) (nal->type == HEVC_NAL_IDR_W_RADL || nal->type == HEVC_NAL_IDR_N_LP) | ||
| 38 | |||
| 39 | typedef struct HEVCParserContext { | ||
| 40 | ParseContext pc; | ||
| 41 | |||
| 42 | H2645Packet pkt; | ||
| 43 | HEVCParamSets ps; | ||
| 44 | HEVCSEI sei; | ||
| 45 | |||
| 46 | int is_avc; | ||
| 47 | int nal_length_size; | ||
| 48 | int parsed_extradata; | ||
| 49 | |||
| 50 | int poc; | ||
| 51 | int pocTid0; | ||
| 52 | } HEVCParserContext; | ||
| 53 | |||
| 54 | 12511 | static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, | |
| 55 | AVCodecContext *avctx) | ||
| 56 | { | ||
| 57 | 12511 | HEVCParserContext *ctx = s->priv_data; | |
| 58 | 12511 | HEVCParamSets *ps = &ctx->ps; | |
| 59 | 12511 | HEVCSEI *sei = &ctx->sei; | |
| 60 | 12511 | GetBitContext *gb = &nal->gb; | |
| 61 | const HEVCPPS *pps; | ||
| 62 | const HEVCSPS *sps; | ||
| 63 | const HEVCWindow *ow; | ||
| 64 | 12511 | int i, num = 0, den = 0; | |
| 65 | |||
| 66 | unsigned int pps_id, first_slice_in_pic_flag, dependent_slice_segment_flag; | ||
| 67 | enum HEVCSliceType slice_type; | ||
| 68 | |||
| 69 | 12511 | first_slice_in_pic_flag = get_bits1(gb); | |
| 70 | 12511 | s->picture_structure = sei->picture_timing.picture_struct; | |
| 71 | 12511 | s->field_order = sei->picture_timing.picture_struct; | |
| 72 | |||
| 73 | 3/4✓ Branch 0 taken 490 times. ✓ Branch 1 taken 12021 times. ✓ Branch 2 taken 490 times. ✗ Branch 3 not taken. | 12511 | if (IS_IRAP_NAL(nal)) { | 
| 74 | 490 | s->key_frame = 1; | |
| 75 | 490 | skip_bits1(gb); // no_output_of_prior_pics_flag | |
| 76 | } | ||
| 77 | |||
| 78 | 12511 | pps_id = get_ue_golomb(gb); | |
| 79 | 3/4✓ Branch 0 taken 12511 times. ✗ Branch 1 not taken. ✓ Branch 2 taken 33 times. ✓ Branch 3 taken 12478 times. | 12511 | if (pps_id >= HEVC_MAX_PPS_COUNT || !ps->pps_list[pps_id]) { | 
| 80 | 33 | av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); | |
| 81 | 33 | return AVERROR_INVALIDDATA; | |
| 82 | } | ||
| 83 | 12478 | pps = ps->pps_list[pps_id]; | |
| 84 | 12478 | sps = pps->sps; | |
| 85 | |||
| 86 | 12478 | ow = &sps->output_window; | |
| 87 | |||
| 88 | 12478 | s->coded_width = sps->width; | |
| 89 | 12478 | s->coded_height = sps->height; | |
| 90 | 12478 | s->width = sps->width - ow->left_offset - ow->right_offset; | |
| 91 | 12478 | s->height = sps->height - ow->top_offset - ow->bottom_offset; | |
| 92 | 12478 | s->format = sps->pix_fmt; | |
| 93 | 12478 | avctx->profile = sps->ptl.general_ptl.profile_idc; | |
| 94 | 12478 | avctx->level = sps->ptl.general_ptl.level_idc; | |
| 95 | |||
| 96 | 2/2✓ Branch 0 taken 355 times. ✓ Branch 1 taken 12123 times. | 12478 | if (sps->vps->vps_timing_info_present_flag) { | 
| 97 | 355 | num = sps->vps->vps_num_units_in_tick; | |
| 98 | 355 | den = sps->vps->vps_time_scale; | |
| 99 | 2/2✓ Branch 0 taken 603 times. ✓ Branch 1 taken 11520 times. | 12123 | } else if (sps->vui.vui_timing_info_present_flag) { | 
| 100 | 603 | num = sps->vui.vui_num_units_in_tick; | |
| 101 | 603 | den = sps->vui.vui_time_scale; | |
| 102 | } | ||
| 103 | |||
| 104 | 3/4✓ Branch 0 taken 958 times. ✓ Branch 1 taken 11520 times. ✓ Branch 2 taken 958 times. ✗ Branch 3 not taken. | 12478 | if (num > 0 && den > 0) | 
| 105 | 958 | av_reduce(&avctx->framerate.den, &avctx->framerate.num, | |
| 106 | num, den, 1 << 30); | ||
| 107 | |||
| 108 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 12478 times. | 12478 | if (!first_slice_in_pic_flag) { | 
| 109 | unsigned int slice_segment_addr; | ||
| 110 | int slice_address_length; | ||
| 111 | |||
| 112 | ✗ | if (pps->dependent_slice_segments_enabled_flag) | |
| 113 | ✗ | dependent_slice_segment_flag = get_bits1(gb); | |
| 114 | else | ||
| 115 | ✗ | dependent_slice_segment_flag = 0; | |
| 116 | |||
| 117 | ✗ | slice_address_length = av_ceil_log2_c(sps->ctb_width * | |
| 118 | ✗ | sps->ctb_height); | |
| 119 | ✗ | slice_segment_addr = get_bitsz(gb, slice_address_length); | |
| 120 | ✗ | if (slice_segment_addr >= sps->ctb_width * sps->ctb_height) { | |
| 121 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n", | |
| 122 | slice_segment_addr); | ||
| 123 | ✗ | return AVERROR_INVALIDDATA; | |
| 124 | } | ||
| 125 | } else | ||
| 126 | 12478 | dependent_slice_segment_flag = 0; | |
| 127 | |||
| 128 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 12478 times. | 12478 | if (dependent_slice_segment_flag) | 
| 129 | ✗ | return 0; /* break; */ | |
| 130 | |||
| 131 | 2/2✓ Branch 0 taken 535 times. ✓ Branch 1 taken 12478 times. | 13013 | for (i = 0; i < pps->num_extra_slice_header_bits; i++) | 
| 132 | 535 | skip_bits(gb, 1); // slice_reserved_undetermined_flag[] | |
| 133 | |||
| 134 | 12478 | slice_type = get_ue_golomb_31(gb); | |
| 135 | 5/6✓ Branch 0 taken 11820 times. ✓ Branch 1 taken 658 times. ✓ Branch 2 taken 9143 times. ✓ Branch 3 taken 2677 times. ✗ Branch 4 not taken. ✓ Branch 5 taken 9143 times. | 12478 | if (!(slice_type == HEVC_SLICE_I || slice_type == HEVC_SLICE_P || | 
| 136 | slice_type == HEVC_SLICE_B)) { | ||
| 137 | ✗ | av_log(avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", | |
| 138 | slice_type); | ||
| 139 | ✗ | return AVERROR_INVALIDDATA; | |
| 140 | } | ||
| 141 | 2/2✓ Branch 0 taken 3335 times. ✓ Branch 1 taken 9143 times. | 15813 | s->pict_type = slice_type == HEVC_SLICE_B ? AV_PICTURE_TYPE_B : | 
| 142 | 2/2✓ Branch 0 taken 2677 times. ✓ Branch 1 taken 658 times. | 3335 | slice_type == HEVC_SLICE_P ? AV_PICTURE_TYPE_P : | 
| 143 | AV_PICTURE_TYPE_I; | ||
| 144 | |||
| 145 | 2/2✓ Branch 0 taken 700 times. ✓ Branch 1 taken 11778 times. | 12478 | if (pps->output_flag_present_flag) | 
| 146 | 700 | skip_bits1(gb); // pic_output_flag | |
| 147 | |||
| 148 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 12478 times. | 12478 | if (sps->separate_colour_plane) | 
| 149 | ✗ | skip_bits(gb, 2); // colour_plane_id | |
| 150 | |||
| 151 | 4/4✓ Branch 0 taken 12257 times. ✓ Branch 1 taken 221 times. ✓ Branch 2 taken 12244 times. ✓ Branch 3 taken 13 times. | 12478 | if (!IS_IDR_NAL(nal)) { | 
| 152 | 12244 | int pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb); | |
| 153 | 12244 | s->output_picture_number = ctx->poc = | |
| 154 | 12244 | ff_hevc_compute_poc(sps, ctx->pocTid0, pic_order_cnt_lsb, nal->type); | |
| 155 | } else | ||
| 156 | 234 | s->output_picture_number = ctx->poc = 0; | |
| 157 | |||
| 158 | 2/2✓ Branch 0 taken 12115 times. ✓ Branch 1 taken 363 times. | 12478 | if (nal->temporal_id == 0 && | 
| 159 | 2/2✓ Branch 0 taken 8851 times. ✓ Branch 1 taken 3264 times. | 12115 | nal->type != HEVC_NAL_TRAIL_N && | 
| 160 | 1/2✓ Branch 0 taken 8851 times. ✗ Branch 1 not taken. | 8851 | nal->type != HEVC_NAL_TSA_N && | 
| 161 | 1/2✓ Branch 0 taken 8851 times. ✗ Branch 1 not taken. | 8851 | nal->type != HEVC_NAL_STSA_N && | 
| 162 | 2/2✓ Branch 0 taken 8815 times. ✓ Branch 1 taken 36 times. | 8851 | nal->type != HEVC_NAL_RADL_N && | 
| 163 | 2/2✓ Branch 0 taken 8372 times. ✓ Branch 1 taken 443 times. | 8815 | nal->type != HEVC_NAL_RASL_N && | 
| 164 | 2/2✓ Branch 0 taken 8341 times. ✓ Branch 1 taken 31 times. | 8372 | nal->type != HEVC_NAL_RADL_R && | 
| 165 | 2/2✓ Branch 0 taken 7706 times. ✓ Branch 1 taken 635 times. | 8341 | nal->type != HEVC_NAL_RASL_R) | 
| 166 | 7706 | ctx->pocTid0 = ctx->poc; | |
| 167 | |||
| 168 | 12478 | return 1; /* no need to evaluate the rest */ | |
| 169 | } | ||
| 170 | |||
| 171 | /** | ||
| 172 | * Parse NAL units of found picture and decode some basic information. | ||
| 173 | * | ||
| 174 | * @param s parser context. | ||
| 175 | * @param avctx codec context. | ||
| 176 | * @param buf buffer with field/frame data. | ||
| 177 | * @param buf_size size of the buffer. | ||
| 178 | */ | ||
| 179 | 12512 | static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, | |
| 180 | int buf_size, AVCodecContext *avctx) | ||
| 181 | { | ||
| 182 | 12512 | HEVCParserContext *ctx = s->priv_data; | |
| 183 | 12512 | HEVCParamSets *ps = &ctx->ps; | |
| 184 | 12512 | HEVCSEI *sei = &ctx->sei; | |
| 185 | 2/2✓ Branch 0 taken 220 times. ✓ Branch 1 taken 12292 times. | 12512 | int flags = (H2645_FLAG_IS_NALFF * !!ctx->is_avc) | H2645_FLAG_SMALL_PADDING; | 
| 186 | int ret, i; | ||
| 187 | |||
| 188 | /* set some sane default values */ | ||
| 189 | 12512 | s->pict_type = AV_PICTURE_TYPE_I; | |
| 190 | 12512 | s->key_frame = 0; | |
| 191 | 12512 | s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN; | |
| 192 | |||
| 193 | 12512 | ff_hevc_reset_sei(sei); | |
| 194 | |||
| 195 | 12512 | ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, | |
| 196 | ctx->nal_length_size, AV_CODEC_ID_HEVC, flags); | ||
| 197 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 12512 times. | 12512 | if (ret < 0) | 
| 198 | ✗ | return ret; | |
| 199 | |||
| 200 | 2/2✓ Branch 0 taken 16157 times. ✓ Branch 1 taken 1 times. | 16158 | for (i = 0; i < ctx->pkt.nb_nals; i++) { | 
| 201 | 16157 | H2645NAL *nal = &ctx->pkt.nals[i]; | |
| 202 | 16157 | GetBitContext *gb = &nal->gb; | |
| 203 | |||
| 204 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 16157 times. | 16157 | if (nal->nuh_layer_id > 0) | 
| 205 | ✗ | continue; | |
| 206 | |||
| 207 | 6/6✓ Branch 0 taken 256 times. ✓ Branch 1 taken 255 times. ✓ Branch 2 taken 1380 times. ✓ Branch 3 taken 1070 times. ✓ Branch 4 taken 12511 times. ✓ Branch 5 taken 685 times. | 16157 | switch (nal->type) { | 
| 208 | 256 | case HEVC_NAL_VPS: | |
| 209 | 256 | ff_hevc_decode_nal_vps(gb, avctx, ps); | |
| 210 | 256 | break; | |
| 211 | 255 | case HEVC_NAL_SPS: | |
| 212 | 255 | ff_hevc_decode_nal_sps(gb, avctx, ps, nal->nuh_layer_id, 1); | |
| 213 | 255 | break; | |
| 214 | 1380 | case HEVC_NAL_PPS: | |
| 215 | 1380 | ff_hevc_decode_nal_pps(gb, avctx, ps); | |
| 216 | 1380 | break; | |
| 217 | 1070 | case HEVC_NAL_SEI_PREFIX: | |
| 218 | case HEVC_NAL_SEI_SUFFIX: | ||
| 219 | 1070 | ff_hevc_decode_nal_sei(gb, avctx, sei, ps, nal->type); | |
| 220 | 1070 | break; | |
| 221 | 12511 | case HEVC_NAL_TRAIL_N: | |
| 222 | case HEVC_NAL_TRAIL_R: | ||
| 223 | case HEVC_NAL_TSA_N: | ||
| 224 | case HEVC_NAL_TSA_R: | ||
| 225 | case HEVC_NAL_STSA_N: | ||
| 226 | case HEVC_NAL_STSA_R: | ||
| 227 | case HEVC_NAL_BLA_W_LP: | ||
| 228 | case HEVC_NAL_BLA_W_RADL: | ||
| 229 | case HEVC_NAL_BLA_N_LP: | ||
| 230 | case HEVC_NAL_IDR_W_RADL: | ||
| 231 | case HEVC_NAL_IDR_N_LP: | ||
| 232 | case HEVC_NAL_CRA_NUT: | ||
| 233 | case HEVC_NAL_RADL_N: | ||
| 234 | case HEVC_NAL_RADL_R: | ||
| 235 | case HEVC_NAL_RASL_N: | ||
| 236 | case HEVC_NAL_RASL_R: | ||
| 237 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 12511 times. | 12511 | if (ctx->sei.picture_timing.picture_struct == HEVC_SEI_PIC_STRUCT_FRAME_DOUBLING) { | 
| 238 | ✗ | s->repeat_pict = 1; | |
| 239 | 1/2✗ Branch 0 not taken. ✓ Branch 1 taken 12511 times. | 12511 | } else if (ctx->sei.picture_timing.picture_struct == HEVC_SEI_PIC_STRUCT_FRAME_TRIPLING) { | 
| 240 | ✗ | s->repeat_pict = 2; | |
| 241 | } | ||
| 242 | 12511 | ret = hevc_parse_slice_header(s, nal, avctx); | |
| 243 | 1/2✓ Branch 0 taken 12511 times. ✗ Branch 1 not taken. | 12511 | if (ret) | 
| 244 | 12511 | return ret; | |
| 245 | ✗ | break; | |
| 246 | } | ||
| 247 | } | ||
| 248 | /* didn't find a picture! */ | ||
| 249 | 1 | av_log(avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size); | |
| 250 | 1 | return -1; | |
| 251 | } | ||
| 252 | |||
| 253 | /** | ||
| 254 | * Find the end of the current frame in the bitstream. | ||
| 255 | * @return the position of the first byte of the next frame, or END_NOT_FOUND | ||
| 256 | */ | ||
| 257 | 96343 | static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, | |
| 258 | int buf_size) | ||
| 259 | { | ||
| 260 | 96343 | HEVCParserContext *ctx = s->priv_data; | |
| 261 | 96343 | ParseContext *pc = &ctx->pc; | |
| 262 | int i; | ||
| 263 | |||
| 264 | 2/2✓ Branch 0 taken 86386294 times. ✓ Branch 1 taken 84261 times. | 86470555 | for (i = 0; i < buf_size; i++) { | 
| 265 | int nut, layer_id; | ||
| 266 | |||
| 267 | 86386294 | pc->state64 = (pc->state64 << 8) | buf[i]; | |
| 268 | |||
| 269 | 2/2✓ Branch 0 taken 86326168 times. ✓ Branch 1 taken 60126 times. | 86386294 | if (((pc->state64 >> 3 * 8) & 0xFFFFFF) != START_CODE) | 
| 270 | 86326168 | continue; | |
| 271 | |||
| 272 | 60126 | nut = (pc->state64 >> 2 * 8 + 1) & 0x3F; | |
| 273 | |||
| 274 | 60126 | layer_id = (pc->state64 >> 11) & 0x3F; | |
| 275 | 2/2✓ Branch 0 taken 344 times. ✓ Branch 1 taken 59782 times. | 60126 | if (layer_id > 0) | 
| 276 | 344 | continue; | |
| 277 | |||
| 278 | // Beginning of access unit | ||
| 279 | 7/8✓ Branch 0 taken 14027 times. ✓ Branch 1 taken 45755 times. ✓ Branch 2 taken 10060 times. ✓ Branch 3 taken 3967 times. ✓ Branch 4 taken 54365 times. ✓ Branch 5 taken 1450 times. ✗ Branch 6 not taken. ✓ Branch 7 taken 54365 times. | 59782 | if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_EOB_NUT) || nut == HEVC_NAL_SEI_PREFIX || | 
| 280 | 1/6✗ Branch 0 not taken. ✗ Branch 1 not taken. ✗ Branch 2 not taken. ✓ Branch 3 taken 54365 times. ✗ Branch 4 not taken. ✗ Branch 5 not taken. | 54365 | (nut >= 41 && nut <= 44) || (nut >= 48 && nut <= 55)) { | 
| 281 | 2/2✓ Branch 0 taken 1787 times. ✓ Branch 1 taken 3630 times. | 5417 | if (pc->frame_start_found) { | 
| 282 | 1787 | pc->frame_start_found = 0; | |
| 283 | 2/2✓ Branch 0 taken 1786 times. ✓ Branch 1 taken 1 times. | 1787 | if (!((pc->state64 >> 6 * 8) & 0xFF)) | 
| 284 | 1786 | return i - 6; | |
| 285 | 1 | return i - 5; | |
| 286 | } | ||
| 287 | 3/4✓ Branch 0 taken 9806 times. ✓ Branch 1 taken 44559 times. ✓ Branch 2 taken 9806 times. ✗ Branch 3 not taken. | 54365 | } else if (nut <= HEVC_NAL_RASL_R || | 
| 288 | 2/2✓ Branch 0 taken 1196 times. ✓ Branch 1 taken 8610 times. | 9806 | (nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT)) { | 
| 289 | 45755 | int first_slice_segment_in_pic_flag = buf[i] >> 7; | |
| 290 | 2/2✓ Branch 0 taken 22588 times. ✓ Branch 1 taken 23167 times. | 45755 | if (first_slice_segment_in_pic_flag) { | 
| 291 | 2/2✓ Branch 0 taken 12293 times. ✓ Branch 1 taken 10295 times. | 22588 | if (!pc->frame_start_found) { | 
| 292 | 12293 | pc->frame_start_found = 1; | |
| 293 | } else { // First slice of next frame found | ||
| 294 | 10295 | pc->frame_start_found = 0; | |
| 295 | 2/2✓ Branch 0 taken 10203 times. ✓ Branch 1 taken 92 times. | 10295 | if (!((pc->state64 >> 6 * 8) & 0xFF)) | 
| 296 | 10203 | return i - 6; | |
| 297 | 92 | return i - 5; | |
| 298 | } | ||
| 299 | } | ||
| 300 | } | ||
| 301 | } | ||
| 302 | |||
| 303 | 84261 | return END_NOT_FOUND; | |
| 304 | } | ||
| 305 | |||
| 306 | 96570 | static int hevc_parse(AVCodecParserContext *s, AVCodecContext *avctx, | |
| 307 | const uint8_t **poutbuf, int *poutbuf_size, | ||
| 308 | const uint8_t *buf, int buf_size) | ||
| 309 | { | ||
| 310 | int next; | ||
| 311 | 96570 | HEVCParserContext *ctx = s->priv_data; | |
| 312 | 96570 | ParseContext *pc = &ctx->pc; | |
| 313 | 96570 | int is_dummy_buf = !buf_size; | |
| 314 | 96570 | const uint8_t *dummy_buf = buf; | |
| 315 | |||
| 316 | 4/4✓ Branch 0 taken 82755 times. ✓ Branch 1 taken 13815 times. ✓ Branch 2 taken 204 times. ✓ Branch 3 taken 82551 times. | 96570 | if (avctx->extradata && !ctx->parsed_extradata) { | 
| 317 | 204 | ff_hevc_decode_extradata(avctx->extradata, avctx->extradata_size, &ctx->ps, &ctx->sei, | |
| 318 | &ctx->is_avc, &ctx->nal_length_size, avctx->err_recognition, | ||
| 319 | 1, avctx); | ||
| 320 | 204 | ctx->parsed_extradata = 1; | |
| 321 | } | ||
| 322 | |||
| 323 | 2/2✓ Branch 0 taken 227 times. ✓ Branch 1 taken 96343 times. | 96570 | if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { | 
| 324 | 227 | next = buf_size; | |
| 325 | } else { | ||
| 326 | 96343 | next = hevc_find_frame_end(s, buf, buf_size); | |
| 327 | 2/2✓ Branch 1 taken 83841 times. ✓ Branch 2 taken 12502 times. | 96343 | if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { | 
| 328 | 83841 | *poutbuf = NULL; | |
| 329 | 83841 | *poutbuf_size = 0; | |
| 330 | 83841 | return buf_size; | |
| 331 | } | ||
| 332 | } | ||
| 333 | |||
| 334 | 12729 | is_dummy_buf &= (dummy_buf == buf); | |
| 335 | |||
| 336 | 2/2✓ Branch 0 taken 12512 times. ✓ Branch 1 taken 217 times. | 12729 | if (!is_dummy_buf) | 
| 337 | 12512 | parse_nal_units(s, buf, buf_size, avctx); | |
| 338 | |||
| 339 | 12729 | *poutbuf = buf; | |
| 340 | 12729 | *poutbuf_size = buf_size; | |
| 341 | 12729 | return next; | |
| 342 | } | ||
| 343 | |||
| 344 | 273 | static void hevc_parser_close(AVCodecParserContext *s) | |
| 345 | { | ||
| 346 | 273 | HEVCParserContext *ctx = s->priv_data; | |
| 347 | |||
| 348 | 273 | ff_hevc_ps_uninit(&ctx->ps); | |
| 349 | 273 | ff_h2645_packet_uninit(&ctx->pkt); | |
| 350 | 273 | ff_hevc_reset_sei(&ctx->sei); | |
| 351 | |||
| 352 | 273 | av_freep(&ctx->pc.buffer); | |
| 353 | 273 | } | |
| 354 | |||
| 355 | const AVCodecParser ff_hevc_parser = { | ||
| 356 | .codec_ids = { AV_CODEC_ID_HEVC }, | ||
| 357 | .priv_data_size = sizeof(HEVCParserContext), | ||
| 358 | .parser_parse = hevc_parse, | ||
| 359 | .parser_close = hevc_parser_close, | ||
| 360 | }; | ||
| 361 |