MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / mergeSubtitles

Function mergeSubtitles

libhb/sync.c:2799–2858  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2797}
2798
2799static hb_buffer_t * mergeSubtitles(sync_stream_t * stream)
2800{
2801 hb_buffer_t * buf;
2802 hb_buffer_list_t list;
2803 subtitle_sanitizer_t * sanitizer = &stream->subtitle.sanitizer;
2804
2805 hb_buffer_list_clear(&list);
2806
2807 if (!sanitizer->merge)
2808 {
2809 // Handle all but the last buffer
2810 // The last buffer may not have been "linked" yet
2811 while (hb_buffer_list_count(&sanitizer->list_current) > 0)
2812 {
2813 buf = hb_buffer_list_head(&sanitizer->list_current);
2814 if (!(buf->s.flags & HB_BUF_FLAG_EOF) &&
2815 buf->s.stop != AV_NOPTS_VALUE)
2816 {
2817 buf = hb_buffer_list_rem_head(&sanitizer->list_current);
2818 buf = setSubDuration(stream, buf);
2819 hb_buffer_list_append(&list, buf);
2820 }
2821 else
2822 {
2823 break;
2824 }
2825 }
2826 return hb_buffer_list_clear(&list);
2827 }
2828
2829 // We only reach here if we are merging subtitles
2830 while (hb_buffer_list_count(&sanitizer->list_current) > 0)
2831 {
2832 buf = hb_buffer_list_head(&sanitizer->list_current);
2833 if (buf->s.flags & HB_BUF_FLAG_EOF)
2834 {
2835 // remove EOF from list, add to output
2836 buf = hb_buffer_list_rem_head(&sanitizer->list_current);
2837 hb_buffer_list_append(&list, buf);
2838 break;
2839 }
2840
2841 int result = mergeSubtitleOverlaps(sanitizer);
2842 if (result < 0)
2843 {
2844 // not enough information available yet to resolve the overlap
2845 break;
2846 }
2847
2848 // Overlap resolved, output a buffer
2849 buf = hb_buffer_list_rem_head(&sanitizer->list_current);
2850 if (buf != NULL && !(buf->s.flags & HB_BUF_FLAG_EOF))
2851 {
2852 buf = setSubDuration(stream, buf);
2853 hb_buffer_list_append(&list, buf);
2854 }
2855 }
2856

Callers 1

sanitizeSubtitleFunction · 0.85

Calls 7

hb_buffer_list_clearFunction · 0.85
hb_buffer_list_countFunction · 0.85
hb_buffer_list_headFunction · 0.85
hb_buffer_list_rem_headFunction · 0.85
setSubDurationFunction · 0.85
hb_buffer_list_appendFunction · 0.85
mergeSubtitleOverlapsFunction · 0.85

Tested by

no test coverage detected