* encavsubWork *********************************************************************** * Work function for libav subtitle encoding that may be wrapped * by HB subtitle encoder **********************************************************************/
| 188 | * by HB subtitle encoder |
| 189 | **********************************************************************/ |
| 190 | int encavsubWork(hb_encavsub_context_t *ctx, |
| 191 | hb_buffer_t **buf_in, |
| 192 | hb_buffer_t **buf_out) |
| 193 | { |
| 194 | hb_buffer_t *in = *buf_in; |
| 195 | AVSubtitle subtitle; |
| 196 | int num_rects = 1; |
| 197 | int64_t duration; |
| 198 | |
| 199 | if (in->s.flags & HB_BUF_FLAG_EOF) |
| 200 | { |
| 201 | /* EOF on input stream - send it downstream & say that we're done */ |
| 202 | *buf_in = NULL; |
| 203 | |
| 204 | *buf_out = in; |
| 205 | return HB_WORK_DONE; |
| 206 | } |
| 207 | |
| 208 | // Create an AVSubtitle from the input buffer |
| 209 | memset(&subtitle, 0, sizeof(subtitle)); |
| 210 | subtitle.rects = av_mallocz(num_rects * sizeof(subtitle.rects)); |
| 211 | if (subtitle.rects == NULL) |
| 212 | { |
| 213 | *buf_out = hb_buffer_eof_init(); |
| 214 | hb_error("encavsubInit: av_mallocz_array failed"); |
| 215 | return HB_WORK_DONE; |
| 216 | } |
| 217 | |
| 218 | for (int ii = 0; ii < num_rects; ii++) |
| 219 | { |
| 220 | subtitle.rects[ii] = av_mallocz(sizeof(*subtitle.rects[0])); |
| 221 | if (!subtitle.rects[ii]) { |
| 222 | avsubtitle_free(&subtitle); |
| 223 | *buf_out = hb_buffer_eof_init(); |
| 224 | hb_error("encavsubInit: av_mallocz failed"); |
| 225 | return HB_WORK_DONE; |
| 226 | } |
| 227 | subtitle.num_rects++; |
| 228 | } |
| 229 | |
| 230 | if (ctx->subtitle->format == TEXTSUB) |
| 231 | { |
| 232 | subtitle.rects[0]->type = SUBTITLE_ASS; |
| 233 | subtitle.rects[0]->ass = av_strdup((char *)in->data); |
| 234 | if (subtitle.rects[0]->ass == NULL) |
| 235 | { |
| 236 | avsubtitle_free(&subtitle); |
| 237 | *buf_out = hb_buffer_eof_init(); |
| 238 | hb_error("encavsubInit: av_strdup failed"); |
| 239 | return HB_WORK_DONE; |
| 240 | } |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | // TODO: bitmap subtitles |
| 245 | // Must simplify format of hb_buffer_t bitmap representation |
| 246 | for (int ii = 0; ii < num_rects; ii++) |
| 247 | { |
no test coverage detected