HEVCHdrParams* receives a pointer which points to a dynamically allocated memory block. It causes the memcmp always returning 1. Add a function to do the comparision. A condition is also added to avoid malloc(0).
Unified · Split
| @@ -449,6 +449,15 @@ static void uninit_vps(FFRefStructOpaque opaque, void *obj) · 448 unmodified lines | ||
| 449 | 449 | av_freep(&vps->hdr); |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | +static int compare_vps(const HEVCVPS *vps1, const HEVCVPS *vps2) | |
| 453 | +{ | |
| 454 | + if (!memcmp(vps1, vps2, offsetof(HEVCVPS, hdr))) | |
| 455 | + return !vps1->vps_num_hrd_parameters || | |
| 456 | + !memcmp(vps1->hdr, vps2->hdr, vps1->vps_num_hrd_parameters * sizeof(*vps1->hdr)); | |
| 457 | + | |
| 458 | + return 0; | |
| 459 | +} | |
| 460 | + | |
| 452 | 461 | int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, |
| 453 | 462 | HEVCParamSets *ps) |
| 454 | 463 | { |
| @@ -545,9 +554,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, · 90 unmodified lines | ||
| 545 | 554 | goto err; |
| 546 | 555 | } |
| 547 | 556 | |
| 548 | − vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); | |
| 549 | − if (!vps->hdr) | |
| 550 | − goto err; | |
| 557 | + if (vps->vps_num_hrd_parameters) { | |
| 558 | + vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); | |
| 559 | + if (!vps->hdr) | |
| 560 | + goto err; | |
| 561 | + } | |
| 551 | 562 | |
| 552 | 563 | for (i = 0; i < vps->vps_num_hrd_parameters; i++) { |
| 553 | 564 | int common_inf_present = 1; |
| @@ -569,7 +580,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, · 15 unmodified lines | ||
| 569 | 580 | } |
| 570 | 581 | |
| 571 | 582 | if (ps->vps_list[vps_id] && |
| 572 | − !memcmp(ps->vps_list[vps_id], vps, sizeof(*vps))) { | |
| 583 | + compare_vps(ps->vps_list[vps_id], vps)) { | |
| 573 | 584 | ff_refstruct_unref(&vps); |
| 574 | 585 | } else { |
| 575 | 586 | remove_vps(ps, vps_id); |
| @@ -153,7 +153,6 @@ typedef struct PTL { · 152 unmodified lines | ||
| 153 | 153 | |
| 154 | 154 | typedef struct HEVCVPS { |
| 155 | 155 | unsigned int vps_id; |
| 156 | − HEVCHdrParams *hdr; | |
| 157 | 156 | |
| 158 | 157 | uint8_t vps_temporal_id_nesting_flag; |
| 159 | 158 | int vps_max_layers; |
| @@ -175,6 +174,9 @@ typedef struct HEVCVPS { · 15 unmodified lines | ||
| 175 | 174 | |
| 176 | 175 | uint8_t data[4096]; |
| 177 | 176 | int data_size; |
| 177 | + /* Put this at the end of the structure to make it easier to calculate the | |
| 178 | + * size before this pointer, which is used for memcmp */ | |
| 179 | + HEVCHdrParams *hdr; | |
| 178 | 180 | } HEVCVPS; |
| 179 | 181 | |
| 180 | 182 | typedef struct ScalingList { |