| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "bytestream.h" | ||
| 20 | #include "h2645_parse.h" | ||
| 21 | #include "hevc.h" | ||
| 22 | #include "parse.h" | ||
| 23 | |||
| 24 | 727 | static int hevc_decode_nal_units(const uint8_t *buf, int buf_size, HEVCParamSets *ps, | |
| 25 | HEVCSEI *sei, int is_nalff, int nal_length_size, | ||
| 26 | int err_recognition, int apply_defdispwin, void *logctx) | ||
| 27 | { | ||
| 28 | int i; | ||
| 29 | 727 | int ret = 0; | |
| 30 |
2/2✓ Branch 0 taken 348 times.
✓ Branch 1 taken 379 times.
|
727 | int flags = (H2645_FLAG_IS_NALFF * !!is_nalff) | H2645_FLAG_SMALL_PADDING; |
| 31 | 727 | H2645Packet pkt = { 0 }; | |
| 32 | |||
| 33 | 727 | ret = ff_h2645_packet_split(&pkt, buf, buf_size, logctx, | |
| 34 | nal_length_size, AV_CODEC_ID_HEVC, flags); | ||
| 35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 727 times.
|
727 | if (ret < 0) { |
| 36 | ✗ | goto done; | |
| 37 | } | ||
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 1680 times.
✓ Branch 1 taken 726 times.
|
2406 | for (i = 0; i < pkt.nb_nals; i++) { |
| 40 | 1680 | H2645NAL *nal = &pkt.nals[i]; | |
| 41 | /* ignore everything except parameter sets and VCL NALUs */ | ||
| 42 |
4/5✓ Branch 0 taken 494 times.
✓ Branch 1 taken 507 times.
✓ Branch 2 taken 646 times.
✓ Branch 3 taken 33 times.
✗ Branch 4 not taken.
|
1680 | switch (nal->type) { |
| 43 | 494 | case HEVC_NAL_VPS: | |
| 44 | 494 | ret = ff_hevc_decode_nal_vps(&nal->gb, logctx, ps); | |
| 45 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
|
494 | if (ret < 0) |
| 46 | ✗ | goto done; | |
| 47 | 494 | break; | |
| 48 | 507 | case HEVC_NAL_SPS: | |
| 49 | 507 | ret = ff_hevc_decode_nal_sps(&nal->gb, logctx, ps, | |
| 50 | 507 | nal->nuh_layer_id, apply_defdispwin); | |
| 51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 507 times.
|
507 | if (ret < 0) |
| 52 | ✗ | goto done; | |
| 53 | 507 | break; | |
| 54 | 646 | case HEVC_NAL_PPS: | |
| 55 | 646 | ret = ff_hevc_decode_nal_pps(&nal->gb, logctx, ps); | |
| 56 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 645 times.
|
646 | if (ret < 0) |
| 57 | 1 | goto done; | |
| 58 | 645 | break; | |
| 59 | 33 | case HEVC_NAL_SEI_PREFIX: | |
| 60 | case HEVC_NAL_SEI_SUFFIX: | ||
| 61 | 33 | ret = ff_hevc_decode_nal_sei(&nal->gb, logctx, sei, ps, nal->type); | |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (ret < 0) |
| 63 | ✗ | goto done; | |
| 64 | 33 | break; | |
| 65 | ✗ | default: | |
| 66 | ✗ | av_log(logctx, AV_LOG_VERBOSE, "Ignoring NAL type %d in extradata\n", nal->type); | |
| 67 | ✗ | break; | |
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | 726 | done: | |
| 72 | 727 | ff_h2645_packet_uninit(&pkt); | |
| 73 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 727 times.
|
727 | if (err_recognition & AV_EF_EXPLODE) |
| 74 | ✗ | return ret; | |
| 75 | |||
| 76 | 727 | return 0; | |
| 77 | } | ||
| 78 | |||
| 79 | 477 | int ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps, | |
| 80 | HEVCSEI *sei, int *is_nalff, int *nal_length_size, | ||
| 81 | int err_recognition, int apply_defdispwin, void *logctx) | ||
| 82 | { | ||
| 83 | 477 | int ret = 0; | |
| 84 | GetByteContext gb; | ||
| 85 | |||
| 86 | 477 | bytestream2_init(&gb, data, size); | |
| 87 | |||
| 88 | /* data[0] == 1 is configurationVersion from 14496-15. | ||
| 89 | * data[0] == 0 is for backward compatibility predates the standard. | ||
| 90 | * | ||
| 91 | * Minimum number of bytes of hvcC with 0 numOfArrays is 23. | ||
| 92 | */ | ||
| 93 |
6/10✓ Branch 0 taken 477 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 379 times.
✓ Branch 3 taken 98 times.
✓ Branch 4 taken 379 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 379 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 379 times.
|
477 | if (size >= 23 && ((data[0] == 1) || (data[0] == 0 && (data[1] || data[2] > 1)))) { |
| 94 | /* It seems the extradata is encoded as hvcC format. */ | ||
| 95 | int i, j, num_arrays, nal_len_size; | ||
| 96 | |||
| 97 | 98 | *is_nalff = 1; | |
| 98 | |||
| 99 | 98 | bytestream2_skip(&gb, 21); | |
| 100 | 98 | nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1; | |
| 101 | 98 | num_arrays = bytestream2_get_byte(&gb); | |
| 102 | |||
| 103 | /* nal units in the hvcC always have length coded with 2 bytes, | ||
| 104 | * so put a fake nal_length_size = 2 while parsing them */ | ||
| 105 | 98 | *nal_length_size = 2; | |
| 106 | |||
| 107 | /* Decode nal units from hvcC. */ | ||
| 108 |
2/2✓ Branch 0 taken 335 times.
✓ Branch 1 taken 98 times.
|
433 | for (i = 0; i < num_arrays; i++) { |
| 109 | 335 | int type = bytestream2_get_byte(&gb) & 0x3f; | |
| 110 | 335 | int cnt = bytestream2_get_be16(&gb); | |
| 111 | |||
| 112 |
2/2✓ Branch 0 taken 348 times.
✓ Branch 1 taken 335 times.
|
683 | for (j = 0; j < cnt; j++) { |
| 113 | // +2 for the nal size field | ||
| 114 | 348 | int nalsize = bytestream2_peek_be16(&gb) + 2; | |
| 115 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 348 times.
|
348 | if (bytestream2_get_bytes_left(&gb) < nalsize) { |
| 116 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 117 | "Invalid NAL unit size in extradata.\n"); | ||
| 118 | ✗ | return AVERROR_INVALIDDATA; | |
| 119 | } | ||
| 120 | |||
| 121 | 348 | ret = hevc_decode_nal_units(gb.buffer, nalsize, ps, sei, *is_nalff, | |
| 122 | *nal_length_size, err_recognition, apply_defdispwin, | ||
| 123 | logctx); | ||
| 124 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
|
348 | if (ret < 0) { |
| 125 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 126 | "Decoding nal unit %d %d from hvcC failed\n", | ||
| 127 | type, i); | ||
| 128 | ✗ | return ret; | |
| 129 | } | ||
| 130 | 348 | bytestream2_skip(&gb, nalsize); | |
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | /* Now store right nal length size, that will be used to parse | ||
| 135 | * all other nals */ | ||
| 136 | 98 | *nal_length_size = nal_len_size; | |
| 137 | } else { | ||
| 138 | 379 | *is_nalff = 0; | |
| 139 | 379 | ret = hevc_decode_nal_units(data, size, ps, sei, *is_nalff, *nal_length_size, | |
| 140 | err_recognition, apply_defdispwin, logctx); | ||
| 141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 379 times.
|
379 | if (ret < 0) |
| 142 | ✗ | return ret; | |
| 143 | } | ||
| 144 | |||
| 145 | 477 | return ret; | |
| 146 | } | ||
| 147 |