Find all subtitles in the list that start "now" and overlap for some period of time. Create a new subtitle buffer that is the merged results of the overlapping parts and update start times of non-overlapping parts.
| 2689 | // merged results of the overlapping parts and update start times |
| 2690 | // of non-overlapping parts. |
| 2691 | static int mergeSubtitleOverlaps(subtitle_sanitizer_t *sanitizer) |
| 2692 | { |
| 2693 | hb_buffer_t * merged_buf = NULL; |
| 2694 | hb_buffer_t * a, * b; |
| 2695 | |
| 2696 | a = hb_buffer_list_head(&sanitizer->list_current); |
| 2697 | if (a != NULL && (a->s.flags & HB_BUF_FLAG_EOF)) |
| 2698 | { |
| 2699 | // EOF |
| 2700 | return 0; |
| 2701 | } |
| 2702 | if (a == NULL || |
| 2703 | a->s.start == AV_NOPTS_VALUE || a->s.stop == AV_NOPTS_VALUE) |
| 2704 | { |
| 2705 | // Not enough information to resolve an overlap |
| 2706 | return -1; |
| 2707 | } |
| 2708 | b = a->next; |
| 2709 | if (b != NULL && a->s.stop <= b->s.start) |
| 2710 | { |
| 2711 | // No overlap |
| 2712 | return 0; |
| 2713 | } |
| 2714 | |
| 2715 | // Check that we have 2 non-overlapping buffers in the list |
| 2716 | // and that all timestamps are valid up to the non-overlap. |
| 2717 | // This ensures that multiple overlapping subtitles have been |
| 2718 | // completely merged. |
| 2719 | while (b != NULL && |
| 2720 | b->s.start < a->s.stop && !(b->s.flags & HB_BUF_FLAG_EOF)) |
| 2721 | { |
| 2722 | if (b->s.start == AV_NOPTS_VALUE || b->s.stop == AV_NOPTS_VALUE) |
| 2723 | { |
| 2724 | // Not enough information to resolve an overlap |
| 2725 | return -1; |
| 2726 | } |
| 2727 | b = b->next; |
| 2728 | } |
| 2729 | if (b == NULL) |
| 2730 | { |
| 2731 | // Not enough information to resolve an overlap |
| 2732 | return -1; |
| 2733 | } |
| 2734 | |
| 2735 | hb_buffer_list_t merged_list; |
| 2736 | int64_t start, stop, last; |
| 2737 | |
| 2738 | if (b->s.flags & HB_BUF_FLAG_EOF) |
| 2739 | { |
| 2740 | last = INT64_MAX; |
| 2741 | } |
| 2742 | else |
| 2743 | { |
| 2744 | last = b->s.start; |
| 2745 | } |
| 2746 | |
| 2747 | hb_buffer_list_clear(&merged_list); |
| 2748 | a = hb_buffer_list_head(&sanitizer->list_current); |
no test coverage detected