| 454 | } |
| 455 | |
| 456 | static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src) |
| 457 | { |
| 458 | int ret = AVERROR_BUG; |
| 459 | AVSubtitle tmp = { |
| 460 | .format = src->format, |
| 461 | .start_display_time = src->start_display_time, |
| 462 | .end_display_time = src->end_display_time, |
| 463 | .num_rects = 0, |
| 464 | .rects = NULL, |
| 465 | .pts = src->pts |
| 466 | }; |
| 467 | |
| 468 | if (!src->num_rects) |
| 469 | goto success; |
| 470 | |
| 471 | if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects)))) |
| 472 | return AVERROR(ENOMEM); |
| 473 | |
| 474 | for (int i = 0; i < src->num_rects; i++) { |
| 475 | AVSubtitleRect *src_rect = src->rects[i]; |
| 476 | AVSubtitleRect *dst_rect; |
| 477 | |
| 478 | if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) { |
| 479 | ret = AVERROR(ENOMEM); |
| 480 | goto cleanup; |
| 481 | } |
| 482 | |
| 483 | tmp.num_rects++; |
| 484 | |
| 485 | dst_rect->type = src_rect->type; |
| 486 | dst_rect->flags = src_rect->flags; |
| 487 | |
| 488 | dst_rect->x = src_rect->x; |
| 489 | dst_rect->y = src_rect->y; |
| 490 | dst_rect->w = src_rect->w; |
| 491 | dst_rect->h = src_rect->h; |
| 492 | dst_rect->nb_colors = src_rect->nb_colors; |
| 493 | |
| 494 | if (src_rect->text) |
| 495 | if (!(dst_rect->text = av_strdup(src_rect->text))) { |
| 496 | ret = AVERROR(ENOMEM); |
| 497 | goto cleanup; |
| 498 | } |
| 499 | |
| 500 | if (src_rect->ass) |
| 501 | if (!(dst_rect->ass = av_strdup(src_rect->ass))) { |
| 502 | ret = AVERROR(ENOMEM); |
| 503 | goto cleanup; |
| 504 | } |
| 505 | |
| 506 | for (int j = 0; j < 4; j++) { |
| 507 | // SUBTITLE_BITMAP images are special in the sense that they |
| 508 | // are like PAL8 images. first pointer to data, second to |
| 509 | // palette. This makes the size calculation match this. |
| 510 | size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ? |
| 511 | AVPALETTE_SIZE : |
| 512 | src_rect->h * src_rect->linesize[j]; |
| 513 |
no test coverage detected