| 2858 | } |
| 2859 | |
| 2860 | static hb_buffer_t * sanitizeSubtitle( |
| 2861 | sync_stream_t * stream, |
| 2862 | hb_buffer_t * sub) |
| 2863 | { |
| 2864 | hb_buffer_list_t list; |
| 2865 | subtitle_sanitizer_t * sanitizer = &stream->subtitle.sanitizer; |
| 2866 | |
| 2867 | if (sub == NULL) |
| 2868 | { |
| 2869 | return NULL; |
| 2870 | } |
| 2871 | |
| 2872 | hb_buffer_list_set(&list, sub); |
| 2873 | if (!sanitizer->link && !sanitizer->merge) |
| 2874 | { |
| 2875 | hb_buffer_list_t out_list; |
| 2876 | hb_buffer_list_clear(&out_list); |
| 2877 | |
| 2878 | sub = hb_buffer_list_rem_head(&list); |
| 2879 | while (sub != NULL && !(sub->s.flags & HB_BUF_FLAG_EOF)) |
| 2880 | { |
| 2881 | sub = setSubDuration(stream, sub); |
| 2882 | hb_buffer_list_append(&out_list, sub); |
| 2883 | sub = hb_buffer_list_rem_head(&list); |
| 2884 | } |
| 2885 | if (sub != NULL) |
| 2886 | { |
| 2887 | hb_buffer_close(&sub); |
| 2888 | } |
| 2889 | return hb_buffer_list_clear(&out_list); |
| 2890 | } |
| 2891 | |
| 2892 | sub = hb_buffer_list_rem_head(&list); |
| 2893 | while (sub != NULL) |
| 2894 | { |
| 2895 | if (sub->s.flags & HB_BUF_FLAG_EOF) |
| 2896 | { |
| 2897 | hb_buffer_list_append(&sanitizer->list_current, sub); |
| 2898 | break; |
| 2899 | } |
| 2900 | |
| 2901 | hb_buffer_t *last = hb_buffer_list_tail(&sanitizer->list_current); |
| 2902 | if (last != NULL && last->s.stop == AV_NOPTS_VALUE) |
| 2903 | { |
| 2904 | last->s.stop = sub->s.start; |
| 2905 | if (last->s.stop <= last->s.start) |
| 2906 | { |
| 2907 | // Subtitle duration <= 0. Drop it. |
| 2908 | hb_log("sync: subtitle 0x%x has no duration, PTS %"PRId64"", |
| 2909 | stream->subtitle.subtitle->id, sub->s.start); |
| 2910 | hb_buffer_list_rem_tail(&sanitizer->list_current); |
| 2911 | hb_buffer_close(&last); |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | if (sub->s.flags & HB_BUF_FLAG_EOS) |
| 2916 | { |
| 2917 | // Used to indicate "clear" subtitles when the duration |
no test coverage detected