Mercurial > libavcodec.hg
comparison dvbsubdec.c @ 2967:ef2149182f1c libavcodec
COSMETICS: Remove all trailing whitespace.
author | diego |
---|---|
date | Sat, 17 Dec 2005 18:14:38 +0000 |
parents | 1f117208d20f |
children | 0b546eab515d |
comparison
equal
deleted
inserted
replaced
2966:564788471dd4 | 2967:ef2149182f1c |
---|---|
40 { | 40 { |
41 int x, y, v; | 41 int x, y, v; |
42 FILE *f; | 42 FILE *f; |
43 char fname[40], fname2[40]; | 43 char fname[40], fname2[40]; |
44 char command[1024]; | 44 char command[1024]; |
45 | 45 |
46 snprintf(fname, 40, "%s.ppm", filename); | 46 snprintf(fname, 40, "%s.ppm", filename); |
47 | 47 |
48 f = fopen(fname, "w"); | 48 f = fopen(fname, "w"); |
49 if (!f) { | 49 if (!f) { |
50 perror(fname); | 50 perror(fname); |
61 putc((v >> 8) & 0xff, f); | 61 putc((v >> 8) & 0xff, f); |
62 putc((v >> 0) & 0xff, f); | 62 putc((v >> 0) & 0xff, f); |
63 } | 63 } |
64 } | 64 } |
65 fclose(f); | 65 fclose(f); |
66 | 66 |
67 | 67 |
68 snprintf(fname2, 40, "%s-a.pgm", filename); | 68 snprintf(fname2, 40, "%s-a.pgm", filename); |
69 | 69 |
70 f = fopen(fname2, "w"); | 70 f = fopen(fname2, "w"); |
71 if (!f) { | 71 if (!f) { |
72 perror(fname2); | 72 perror(fname2); |
81 v = rgba_palette[bitmap[y * w + x]]; | 81 v = rgba_palette[bitmap[y * w + x]]; |
82 putc((v >> 24) & 0xff, f); | 82 putc((v >> 24) & 0xff, f); |
83 } | 83 } |
84 } | 84 } |
85 fclose(f); | 85 fclose(f); |
86 | 86 |
87 snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); | 87 snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); |
88 system(command); | 88 system(command); |
89 | 89 |
90 snprintf(command, 1024, "rm %s %s", fname, fname2); | 90 snprintf(command, 1024, "rm %s %s", fname, fname2); |
91 system(command); | 91 system(command); |
92 } | 92 } |
93 #endif | 93 #endif |
94 | 94 |
96 { | 96 { |
97 int x, y, v; | 97 int x, y, v; |
98 FILE *f; | 98 FILE *f; |
99 char fname[40], fname2[40]; | 99 char fname[40], fname2[40]; |
100 char command[1024]; | 100 char command[1024]; |
101 | 101 |
102 snprintf(fname, 40, "%s.ppm", filename); | 102 snprintf(fname, 40, "%s.ppm", filename); |
103 | 103 |
104 f = fopen(fname, "w"); | 104 f = fopen(fname, "w"); |
105 if (!f) { | 105 if (!f) { |
106 perror(fname); | 106 perror(fname); |
117 putc((v >> 8) & 0xff, f); | 117 putc((v >> 8) & 0xff, f); |
118 putc((v >> 0) & 0xff, f); | 118 putc((v >> 0) & 0xff, f); |
119 } | 119 } |
120 } | 120 } |
121 fclose(f); | 121 fclose(f); |
122 | 122 |
123 | 123 |
124 snprintf(fname2, 40, "%s-a.pgm", filename); | 124 snprintf(fname2, 40, "%s-a.pgm", filename); |
125 | 125 |
126 f = fopen(fname2, "w"); | 126 f = fopen(fname2, "w"); |
127 if (!f) { | 127 if (!f) { |
128 perror(fname2); | 128 perror(fname2); |
137 v = bitmap[y * w + x]; | 137 v = bitmap[y * w + x]; |
138 putc((v >> 24) & 0xff, f); | 138 putc((v >> 24) & 0xff, f); |
139 } | 139 } |
140 } | 140 } |
141 fclose(f); | 141 fclose(f); |
142 | 142 |
143 snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); | 143 snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); |
144 system(command); | 144 system(command); |
145 | 145 |
146 snprintf(command, 1024, "rm %s %s", fname, fname2); | 146 snprintf(command, 1024, "rm %s %s", fname, fname2); |
147 system(command); | 147 system(command); |
148 } | 148 } |
149 #endif | 149 #endif |
150 | 150 |
154 int id; | 154 int id; |
155 | 155 |
156 uint32_t clut4[4]; | 156 uint32_t clut4[4]; |
157 uint32_t clut16[16]; | 157 uint32_t clut16[16]; |
158 uint32_t clut256[256]; | 158 uint32_t clut256[256]; |
159 | 159 |
160 struct DVBSubCLUT *next; | 160 struct DVBSubCLUT *next; |
161 } DVBSubCLUT; | 161 } DVBSubCLUT; |
162 | 162 |
163 static DVBSubCLUT default_clut; | 163 static DVBSubCLUT default_clut; |
164 | 164 |
169 int x_pos; | 169 int x_pos; |
170 int y_pos; | 170 int y_pos; |
171 | 171 |
172 int fgcolour; | 172 int fgcolour; |
173 int bgcolour; | 173 int bgcolour; |
174 | 174 |
175 struct DVBSubObjectDisplay *region_list_next; | 175 struct DVBSubObjectDisplay *region_list_next; |
176 struct DVBSubObjectDisplay *object_list_next; | 176 struct DVBSubObjectDisplay *object_list_next; |
177 } DVBSubObjectDisplay; | 177 } DVBSubObjectDisplay; |
178 | 178 |
179 typedef struct DVBSubObject { | 179 typedef struct DVBSubObject { |
180 int id; | 180 int id; |
181 | 181 |
182 int type; | 182 int type; |
183 | 183 |
184 DVBSubObjectDisplay *display_list; | 184 DVBSubObjectDisplay *display_list; |
185 | 185 |
186 struct DVBSubObject *next; | 186 struct DVBSubObject *next; |
187 } DVBSubObject; | 187 } DVBSubObject; |
188 | 188 |
189 typedef struct DVBSubRegionDisplay { | 189 typedef struct DVBSubRegionDisplay { |
190 int region_id; | 190 int region_id; |
199 int id; | 199 int id; |
200 | 200 |
201 int width; | 201 int width; |
202 int height; | 202 int height; |
203 int depth; | 203 int depth; |
204 | 204 |
205 int clut; | 205 int clut; |
206 int bgcolour; | 206 int bgcolour; |
207 | 207 |
208 uint8_t *pbuf; | 208 uint8_t *pbuf; |
209 int buf_size; | 209 int buf_size; |
210 | 210 |
211 DVBSubObjectDisplay *display_list; | 211 DVBSubObjectDisplay *display_list; |
212 | 212 |
213 struct DVBSubRegion *next; | 213 struct DVBSubRegion *next; |
214 } DVBSubRegion; | 214 } DVBSubRegion; |
215 | 215 |
216 typedef struct DVBSubContext { | 216 typedef struct DVBSubContext { |
217 int composition_id; | 217 int composition_id; |
219 | 219 |
220 int time_out; | 220 int time_out; |
221 DVBSubRegion *region_list; | 221 DVBSubRegion *region_list; |
222 DVBSubCLUT *clut_list; | 222 DVBSubCLUT *clut_list; |
223 DVBSubObject *object_list; | 223 DVBSubObject *object_list; |
224 | 224 |
225 int display_list_size; | 225 int display_list_size; |
226 DVBSubRegionDisplay *display_list; | 226 DVBSubRegionDisplay *display_list; |
227 } DVBSubContext; | 227 } DVBSubContext; |
228 | 228 |
229 | 229 |
232 DVBSubObject *ptr = ctx->object_list; | 232 DVBSubObject *ptr = ctx->object_list; |
233 | 233 |
234 while (ptr != NULL && ptr->id != object_id) { | 234 while (ptr != NULL && ptr->id != object_id) { |
235 ptr = ptr->next; | 235 ptr = ptr->next; |
236 } | 236 } |
237 | 237 |
238 return ptr; | 238 return ptr; |
239 } | 239 } |
240 | 240 |
241 static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id) | 241 static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id) |
242 { | 242 { |
243 DVBSubCLUT *ptr = ctx->clut_list; | 243 DVBSubCLUT *ptr = ctx->clut_list; |
244 | 244 |
245 while (ptr != NULL && ptr->id != clut_id) { | 245 while (ptr != NULL && ptr->id != clut_id) { |
246 ptr = ptr->next; | 246 ptr = ptr->next; |
247 } | 247 } |
248 | 248 |
249 return ptr; | 249 return ptr; |
250 } | 250 } |
251 | 251 |
252 static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id) | 252 static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id) |
253 { | 253 { |
254 DVBSubRegion *ptr = ctx->region_list; | 254 DVBSubRegion *ptr = ctx->region_list; |
255 | 255 |
256 while (ptr != NULL && ptr->id != region_id) { | 256 while (ptr != NULL && ptr->id != region_id) { |
257 ptr = ptr->next; | 257 ptr = ptr->next; |
258 } | 258 } |
259 | 259 |
260 return ptr; | 260 return ptr; |
261 } | 261 } |
262 | 262 |
263 static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region) | 263 static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region) |
264 { | 264 { |
265 DVBSubObject *object, *obj2, **obj2_ptr; | 265 DVBSubObject *object, *obj2, **obj2_ptr; |
266 DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr; | 266 DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr; |
267 | 267 |
268 while (region->display_list != NULL) { | 268 while (region->display_list != NULL) { |
269 display = region->display_list; | 269 display = region->display_list; |
270 | 270 |
271 object = get_object(ctx, display->object_id); | 271 object = get_object(ctx, display->object_id); |
272 | 272 |
273 if (object != NULL) { | 273 if (object != NULL) { |
274 obj_disp = object->display_list; | 274 obj_disp = object->display_list; |
275 obj_disp_ptr = &object->display_list; | 275 obj_disp_ptr = &object->display_list; |
276 | 276 |
277 while (obj_disp != NULL && obj_disp != display) { | 277 while (obj_disp != NULL && obj_disp != display) { |
278 obj_disp_ptr = &obj_disp->object_list_next; | 278 obj_disp_ptr = &obj_disp->object_list_next; |
279 obj_disp = obj_disp->object_list_next; | 279 obj_disp = obj_disp->object_list_next; |
280 } | 280 } |
281 | 281 |
282 if (obj_disp) { | 282 if (obj_disp) { |
283 *obj_disp_ptr = obj_disp->object_list_next; | 283 *obj_disp_ptr = obj_disp->object_list_next; |
284 | 284 |
285 if (object->display_list == NULL) { | 285 if (object->display_list == NULL) { |
286 obj2 = ctx->object_list; | 286 obj2 = ctx->object_list; |
287 obj2_ptr = &ctx->object_list; | 287 obj2_ptr = &ctx->object_list; |
288 | 288 |
289 while (obj2 != NULL && obj2 != object) { | 289 while (obj2 != NULL && obj2 != object) { |
290 obj2_ptr = &obj2->next; | 290 obj2_ptr = &obj2->next; |
291 obj2 = obj2->next; | 291 obj2 = obj2->next; |
292 } | 292 } |
293 | 293 |
294 *obj2_ptr = obj2->next; | 294 *obj2_ptr = obj2->next; |
295 | 295 |
296 av_free(obj2); | 296 av_free(obj2); |
297 } | 297 } |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 region->display_list = display->region_list_next; | 301 region->display_list = display->region_list_next; |
302 | 302 |
303 av_free(display); | 303 av_free(display); |
304 } | 304 } |
305 | 305 |
306 } | 306 } |
307 | 307 |
308 static void delete_state(DVBSubContext *ctx) | 308 static void delete_state(DVBSubContext *ctx) |
309 { | 309 { |
310 DVBSubRegion *region; | 310 DVBSubRegion *region; |
311 DVBSubCLUT *clut; | 311 DVBSubCLUT *clut; |
312 | 312 |
313 while (ctx->region_list != NULL) | 313 while (ctx->region_list != NULL) |
314 { | 314 { |
315 region = ctx->region_list; | 315 region = ctx->region_list; |
316 | 316 |
317 ctx->region_list = region->next; | 317 ctx->region_list = region->next; |
343 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; | 343 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
344 | 344 |
345 cm = cropTbl + MAX_NEG_CROP; | 345 cm = cropTbl + MAX_NEG_CROP; |
346 | 346 |
347 memset(avctx->priv_data, 0, sizeof(DVBSubContext)); | 347 memset(avctx->priv_data, 0, sizeof(DVBSubContext)); |
348 | 348 |
349 ctx->composition_id = avctx->sub_id & 0xffff; | 349 ctx->composition_id = avctx->sub_id & 0xffff; |
350 ctx->ancillary_id = avctx->sub_id >> 16; | 350 ctx->ancillary_id = avctx->sub_id >> 16; |
351 | 351 |
352 default_clut.id = -1; | 352 default_clut.id = -1; |
353 default_clut.next = NULL; | 353 default_clut.next = NULL; |
365 b = (i & 4) ? 255 : 0; | 365 b = (i & 4) ? 255 : 0; |
366 } else { | 366 } else { |
367 r = (i & 1) ? 127 : 0; | 367 r = (i & 1) ? 127 : 0; |
368 g = (i & 2) ? 127 : 0; | 368 g = (i & 2) ? 127 : 0; |
369 b = (i & 4) ? 127 : 0; | 369 b = (i & 4) ? 127 : 0; |
370 } | 370 } |
371 default_clut.clut16[i] = RGBA(r, g, b, 255); | 371 default_clut.clut16[i] = RGBA(r, g, b, 255); |
372 } | 372 } |
373 | 373 |
374 default_clut.clut256[0] = RGBA( 0, 0, 0, 0); | 374 default_clut.clut256[0] = RGBA( 0, 0, 0, 0); |
375 for (i = 1; i < 256; i++) { | 375 for (i = 1; i < 256; i++) { |
403 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0); | 403 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0); |
404 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0); | 404 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0); |
405 a = 255; | 405 a = 255; |
406 break; | 406 break; |
407 } | 407 } |
408 } | 408 } |
409 default_clut.clut256[i] = RGBA(r, g, b, a); | 409 default_clut.clut256[i] = RGBA(r, g, b, a); |
410 } | 410 } |
411 | 411 |
412 return 0; | 412 return 0; |
413 } | 413 } |
416 { | 416 { |
417 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; | 417 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
418 DVBSubRegionDisplay *display; | 418 DVBSubRegionDisplay *display; |
419 | 419 |
420 delete_state(ctx); | 420 delete_state(ctx); |
421 | 421 |
422 while (ctx->display_list != NULL) | 422 while (ctx->display_list != NULL) |
423 { | 423 { |
424 display = ctx->display_list; | 424 display = ctx->display_list; |
425 ctx->display_list = display->next; | 425 ctx->display_list = display->next; |
426 | 426 |
427 av_free(display); | 427 av_free(display); |
428 } | 428 } |
429 | 429 |
430 return 0; | 430 return 0; |
431 } | 431 } |
432 | 432 |
433 static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, | 433 static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, |
434 uint8_t **srcbuf, int buf_size, | 434 uint8_t **srcbuf, int buf_size, |
435 int non_mod, uint8_t *map_table) | 435 int non_mod, uint8_t *map_table) |
436 { | 436 { |
437 GetBitContext gb; | 437 GetBitContext gb; |
438 | 438 |
439 int bits; | 439 int bits; |
440 int run_length; | 440 int run_length; |
441 int pixels_read = 0; | 441 int pixels_read = 0; |
442 | 442 |
443 init_get_bits(&gb, *srcbuf, buf_size << 8); | 443 init_get_bits(&gb, *srcbuf, buf_size << 8); |
444 | 444 |
445 while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) { | 445 while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) { |
446 bits = get_bits(&gb, 2); | 446 bits = get_bits(&gb, 2); |
447 | 447 |
448 if (bits != 0) { | 448 if (bits != 0) { |
449 if (non_mod != 1 || bits != 1) { | 449 if (non_mod != 1 || bits != 1) { |
456 } else { | 456 } else { |
457 bits = get_bits(&gb, 1); | 457 bits = get_bits(&gb, 1); |
458 if (bits == 1) { | 458 if (bits == 1) { |
459 run_length = get_bits(&gb, 3) + 3; | 459 run_length = get_bits(&gb, 3) + 3; |
460 bits = get_bits(&gb, 2); | 460 bits = get_bits(&gb, 2); |
461 | 461 |
462 if (non_mod == 1 && bits == 1) | 462 if (non_mod == 1 && bits == 1) |
463 pixels_read += run_length; | 463 pixels_read += run_length; |
464 else { | 464 else { |
465 if (map_table != NULL) | 465 if (map_table != NULL) |
466 bits = map_table[bits]; | 466 bits = map_table[bits]; |
524 pixels_read++; | 524 pixels_read++; |
525 } | 525 } |
526 } | 526 } |
527 } | 527 } |
528 } | 528 } |
529 | 529 |
530 if (get_bits(&gb, 6) != 0) | 530 if (get_bits(&gb, 6) != 0) |
531 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); | 531 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); |
532 | 532 |
533 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; | 533 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
534 | 534 |
535 return pixels_read; | 535 return pixels_read; |
536 } | 536 } |
537 | 537 |
538 static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, | 538 static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, |
539 uint8_t **srcbuf, int buf_size, | 539 uint8_t **srcbuf, int buf_size, |
540 int non_mod, uint8_t *map_table) | 540 int non_mod, uint8_t *map_table) |
541 { | 541 { |
542 GetBitContext gb; | 542 GetBitContext gb; |
543 | 543 |
544 int bits; | 544 int bits; |
545 int run_length; | 545 int run_length; |
546 int pixels_read = 0; | 546 int pixels_read = 0; |
547 | 547 |
548 init_get_bits(&gb, *srcbuf, buf_size << 8); | 548 init_get_bits(&gb, *srcbuf, buf_size << 8); |
549 | 549 |
550 while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) { | 550 while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) { |
551 bits = get_bits(&gb, 4); | 551 bits = get_bits(&gb, 4); |
552 | 552 |
553 if (bits != 0) { | 553 if (bits != 0) { |
554 if (non_mod != 1 || bits != 1) { | 554 if (non_mod != 1 || bits != 1) { |
560 pixels_read++; | 560 pixels_read++; |
561 } else { | 561 } else { |
562 bits = get_bits(&gb, 1); | 562 bits = get_bits(&gb, 1); |
563 if (bits == 0) { | 563 if (bits == 0) { |
564 run_length = get_bits(&gb, 3); | 564 run_length = get_bits(&gb, 3); |
565 | 565 |
566 if (run_length == 0) { | 566 if (run_length == 0) { |
567 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; | 567 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
568 return pixels_read; | 568 return pixels_read; |
569 } | 569 } |
570 | 570 |
571 run_length += 2; | 571 run_length += 2; |
572 | 572 |
573 if (map_table != NULL) | 573 if (map_table != NULL) |
574 bits = map_table[0]; | 574 bits = map_table[0]; |
575 else | 575 else |
576 bits = 0; | 576 bits = 0; |
577 | 577 |
578 while (run_length-- > 0 && pixels_read < dbuf_len) { | 578 while (run_length-- > 0 && pixels_read < dbuf_len) { |
579 *destbuf++ = bits; | 579 *destbuf++ = bits; |
580 pixels_read++; | 580 pixels_read++; |
581 } | 581 } |
582 } else { | 582 } else { |
598 } else { | 598 } else { |
599 bits = get_bits(&gb, 2); | 599 bits = get_bits(&gb, 2); |
600 if (bits == 2) { | 600 if (bits == 2) { |
601 run_length = get_bits(&gb, 4) + 9; | 601 run_length = get_bits(&gb, 4) + 9; |
602 bits = get_bits(&gb, 4); | 602 bits = get_bits(&gb, 4); |
603 | 603 |
604 if (non_mod == 1 && bits == 1) | 604 if (non_mod == 1 && bits == 1) |
605 pixels_read += run_length; | 605 pixels_read += run_length; |
606 else { | 606 else { |
607 if (map_table != NULL) | 607 if (map_table != NULL) |
608 bits = map_table[bits]; | 608 bits = map_table[bits]; |
645 } | 645 } |
646 } | 646 } |
647 } | 647 } |
648 } | 648 } |
649 } | 649 } |
650 | 650 |
651 if (get_bits(&gb, 8) != 0) | 651 if (get_bits(&gb, 8) != 0) |
652 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); | 652 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); |
653 | 653 |
654 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; | 654 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
655 | 655 |
656 return pixels_read; | 656 return pixels_read; |
657 } | 657 } |
658 | 658 |
659 static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, | 659 static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, |
660 uint8_t **srcbuf, int buf_size, | 660 uint8_t **srcbuf, int buf_size, |
661 int non_mod, uint8_t *map_table) | 661 int non_mod, uint8_t *map_table) |
662 { | 662 { |
663 uint8_t *sbuf_end = (*srcbuf) + buf_size; | 663 uint8_t *sbuf_end = (*srcbuf) + buf_size; |
664 int bits; | 664 int bits; |
665 int run_length; | 665 int run_length; |
666 int pixels_read = 0; | 666 int pixels_read = 0; |
667 | 667 |
668 while (*srcbuf < sbuf_end && pixels_read < dbuf_len) { | 668 while (*srcbuf < sbuf_end && pixels_read < dbuf_len) { |
669 bits = *(*srcbuf)++; | 669 bits = *(*srcbuf)++; |
670 | 670 |
671 if (bits != 0) { | 671 if (bits != 0) { |
672 if (non_mod != 1 || bits != 1) { | 672 if (non_mod != 1 || bits != 1) { |
673 if (map_table != NULL) | 673 if (map_table != NULL) |
674 *destbuf++ = map_table[bits]; | 674 *destbuf++ = map_table[bits]; |
675 else | 675 else |
681 run_length = bits & 0x7f; | 681 run_length = bits & 0x7f; |
682 if ((bits & 0x80) == 0) { | 682 if ((bits & 0x80) == 0) { |
683 if (run_length == 0) { | 683 if (run_length == 0) { |
684 return pixels_read; | 684 return pixels_read; |
685 } | 685 } |
686 | 686 |
687 if (map_table != NULL) | 687 if (map_table != NULL) |
688 bits = map_table[0]; | 688 bits = map_table[0]; |
689 else | 689 else |
690 bits = 0; | 690 bits = 0; |
691 while (run_length-- > 0 && pixels_read < dbuf_len) { | 691 while (run_length-- > 0 && pixels_read < dbuf_len) { |
704 pixels_read++; | 704 pixels_read++; |
705 } | 705 } |
706 } | 706 } |
707 } | 707 } |
708 } | 708 } |
709 | 709 |
710 if (*(*srcbuf)++ != 0) | 710 if (*(*srcbuf)++ != 0) |
711 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); | 711 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); |
712 | 712 |
713 return pixels_read; | 713 return pixels_read; |
714 } | 714 } |
715 | 715 |
716 | 716 |
717 | 717 |
718 static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, | 718 static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, |
719 uint8_t *buf, int buf_size, int top_bottom, int non_mod) | 719 uint8_t *buf, int buf_size, int top_bottom, int non_mod) |
720 { | 720 { |
723 DVBSubRegion *region = get_region(ctx, display->region_id); | 723 DVBSubRegion *region = get_region(ctx, display->region_id); |
724 uint8_t *buf_end = buf + buf_size; | 724 uint8_t *buf_end = buf + buf_size; |
725 uint8_t *pbuf; | 725 uint8_t *pbuf; |
726 int x_pos, y_pos; | 726 int x_pos, y_pos; |
727 int i; | 727 int i; |
728 | 728 |
729 uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf}; | 729 uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf}; |
730 uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff}; | 730 uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff}; |
731 uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 731 uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
732 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; | 732 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; |
733 uint8_t *map_table; | 733 uint8_t *map_table; |
734 | 734 |
735 #ifdef DEBUG | 735 #ifdef DEBUG |
736 av_log(avctx, AV_LOG_INFO, "DVB pixel block size %d, %s field:\n", buf_size, | 736 av_log(avctx, AV_LOG_INFO, "DVB pixel block size %d, %s field:\n", buf_size, |
737 top_bottom ? "bottom" : "top"); | 737 top_bottom ? "bottom" : "top"); |
738 #endif | 738 #endif |
739 | 739 |
745 | 745 |
746 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); | 746 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
747 if (i % 16 == 15) | 747 if (i % 16 == 15) |
748 av_log(avctx, AV_LOG_INFO, "\n"); | 748 av_log(avctx, AV_LOG_INFO, "\n"); |
749 } | 749 } |
750 | 750 |
751 if (i % 16 != 0) | 751 if (i % 16 != 0) |
752 av_log(avctx, AV_LOG_INFO, "\n"); | 752 av_log(avctx, AV_LOG_INFO, "\n"); |
753 | 753 |
754 #endif | 754 #endif |
755 | 755 |
756 if (region == 0) | 756 if (region == 0) |
757 return; | 757 return; |
758 | 758 |
759 pbuf = region->pbuf; | 759 pbuf = region->pbuf; |
760 | 760 |
761 x_pos = display->x_pos; | 761 x_pos = display->x_pos; |
762 y_pos = display->y_pos; | 762 y_pos = display->y_pos; |
763 | 763 |
764 if ((y_pos & 1) != top_bottom) | 764 if ((y_pos & 1) != top_bottom) |
765 y_pos++; | 765 y_pos++; |
766 | 766 |
767 while (buf < buf_end) { | 767 while (buf < buf_end) { |
768 if (x_pos > region->width || y_pos > region->height) { | 768 if (x_pos > region->width || y_pos > region->height) { |
769 av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n"); | 769 av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n"); |
770 return; | 770 return; |
771 } | 771 } |
772 | 772 |
773 switch (*buf++) { | 773 switch (*buf++) { |
774 case 0x10: | 774 case 0x10: |
775 if (region->depth == 8) | 775 if (region->depth == 8) |
776 map_table = map2to8; | 776 map_table = map2to8; |
777 else if (region->depth == 4) | 777 else if (region->depth == 4) |
778 map_table = map2to4; | 778 map_table = map2to4; |
779 else | 779 else |
780 map_table = NULL; | 780 map_table = NULL; |
781 | 781 |
782 x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos, | 782 x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos, |
783 region->width - x_pos, &buf, buf_size, | 783 region->width - x_pos, &buf, buf_size, |
784 non_mod, map_table); | 784 non_mod, map_table); |
785 break; | 785 break; |
786 case 0x11: | 786 case 0x11: |
787 if (region->depth < 4) { | 787 if (region->depth < 4) { |
788 av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth); | 788 av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth); |
789 return; | 789 return; |
790 } | 790 } |
791 | 791 |
792 if (region->depth == 8) | 792 if (region->depth == 8) |
793 map_table = map4to8; | 793 map_table = map4to8; |
794 else | 794 else |
795 map_table = NULL; | 795 map_table = NULL; |
796 | 796 |
797 x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos, | 797 x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos, |
798 region->width - x_pos, &buf, buf_size, | 798 region->width - x_pos, &buf, buf_size, |
799 non_mod, map_table); | 799 non_mod, map_table); |
800 break; | 800 break; |
801 case 0x12: | 801 case 0x12: |
802 if (region->depth < 8) { | 802 if (region->depth < 8) { |
803 av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth); | 803 av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth); |
804 return; | 804 return; |
805 } | 805 } |
806 | 806 |
807 x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos, | 807 x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos, |
808 region->width - x_pos, &buf, buf_size, | 808 region->width - x_pos, &buf, buf_size, |
809 non_mod, NULL); | 809 non_mod, NULL); |
810 break; | 810 break; |
811 | 811 |
812 case 0x20: | 812 case 0x20: |
813 map2to4[0] = (*buf) >> 4; | 813 map2to4[0] = (*buf) >> 4; |
814 map2to4[1] = (*buf++) & 0xf; | 814 map2to4[1] = (*buf++) & 0xf; |
815 map2to4[2] = (*buf) >> 4; | 815 map2to4[2] = (*buf) >> 4; |
816 map2to4[3] = (*buf++) & 0xf; | 816 map2to4[3] = (*buf++) & 0xf; |
821 break; | 821 break; |
822 case 0x22: | 822 case 0x22: |
823 for (i = 0; i < 16; i++) | 823 for (i = 0; i < 16; i++) |
824 map4to8[i] = *buf++; | 824 map4to8[i] = *buf++; |
825 break; | 825 break; |
826 | 826 |
827 case 0xf0: | 827 case 0xf0: |
828 x_pos = display->x_pos; | 828 x_pos = display->x_pos; |
829 y_pos += 2; | 829 y_pos += 2; |
830 break; | 830 break; |
831 default: | 831 default: |
832 av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1)); | 832 av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1)); |
833 } | 833 } |
834 } | 834 } |
835 | 835 |
836 } | 836 } |
837 | 837 |
838 static void dvbsub_parse_object_segment(AVCodecContext *avctx, | 838 static void dvbsub_parse_object_segment(AVCodecContext *avctx, |
839 uint8_t *buf, int buf_size) | 839 uint8_t *buf, int buf_size) |
840 { | 840 { |
841 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; | 841 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
842 | 842 |
843 uint8_t *buf_end = buf + buf_size; | 843 uint8_t *buf_end = buf + buf_size; |
844 uint8_t *block; | 844 uint8_t *block; |
845 int object_id; | 845 int object_id; |
846 DVBSubObject *object; | 846 DVBSubObject *object; |
847 DVBSubObjectDisplay *display; | 847 DVBSubObjectDisplay *display; |
848 int top_field_len, bottom_field_len; | 848 int top_field_len, bottom_field_len; |
849 | 849 |
850 int coding_method, non_modifying_colour; | 850 int coding_method, non_modifying_colour; |
851 | 851 |
852 object_id = BE_16(buf); | 852 object_id = BE_16(buf); |
853 buf += 2; | 853 buf += 2; |
854 | 854 |
855 object = get_object(ctx, object_id); | 855 object = get_object(ctx, object_id); |
856 | 856 |
857 if (!object) | 857 if (!object) |
858 return; | 858 return; |
859 | 859 |
860 coding_method = ((*buf) >> 2) & 3; | 860 coding_method = ((*buf) >> 2) & 3; |
861 non_modifying_colour = ((*buf++) >> 1) & 1; | 861 non_modifying_colour = ((*buf++) >> 1) & 1; |
862 | 862 |
863 if (coding_method == 0) { | 863 if (coding_method == 0) { |
864 top_field_len = BE_16(buf); | 864 top_field_len = BE_16(buf); |
865 buf += 2; | 865 buf += 2; |
866 bottom_field_len = BE_16(buf); | 866 bottom_field_len = BE_16(buf); |
867 buf += 2; | 867 buf += 2; |
868 | 868 |
869 if (buf + top_field_len + bottom_field_len > buf_end) { | 869 if (buf + top_field_len + bottom_field_len > buf_end) { |
870 av_log(avctx, AV_LOG_ERROR, "Field data size too large\n"); | 870 av_log(avctx, AV_LOG_ERROR, "Field data size too large\n"); |
871 return; | 871 return; |
872 } | 872 } |
873 | 873 |
874 for (display = object->display_list; display != 0; display = display->object_list_next) { | 874 for (display = object->display_list; display != 0; display = display->object_list_next) { |
875 block = buf; | 875 block = buf; |
876 | 876 |
877 dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0, | 877 dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0, |
878 non_modifying_colour); | 878 non_modifying_colour); |
883 bottom_field_len = top_field_len; | 883 bottom_field_len = top_field_len; |
884 | 884 |
885 dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1, | 885 dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1, |
886 non_modifying_colour); | 886 non_modifying_colour); |
887 } | 887 } |
888 | 888 |
889 /* } else if (coding_method == 1) {*/ | 889 /* } else if (coding_method == 1) {*/ |
890 | 890 |
891 } else { | 891 } else { |
892 av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method); | 892 av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method); |
893 } | 893 } |
894 | 894 |
895 } | 895 } |
896 | 896 |
897 #define SCALEBITS 10 | 897 #define SCALEBITS 10 |
898 #define ONE_HALF (1 << (SCALEBITS - 1)) | 898 #define ONE_HALF (1 << (SCALEBITS - 1)) |
899 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5)) | 899 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5)) |
919 | 919 |
920 static void dvbsub_parse_clut_segment(AVCodecContext *avctx, | 920 static void dvbsub_parse_clut_segment(AVCodecContext *avctx, |
921 uint8_t *buf, int buf_size) | 921 uint8_t *buf, int buf_size) |
922 { | 922 { |
923 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; | 923 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
924 | 924 |
925 uint8_t *buf_end = buf + buf_size; | 925 uint8_t *buf_end = buf + buf_size; |
926 int clut_id; | 926 int clut_id; |
927 DVBSubCLUT *clut; | 927 DVBSubCLUT *clut; |
928 int entry_id, depth , full_range; | 928 int entry_id, depth , full_range; |
929 int y, cr, cb, alpha; | 929 int y, cr, cb, alpha; |
938 { | 938 { |
939 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); | 939 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
940 if (i % 16 == 15) | 940 if (i % 16 == 15) |
941 av_log(avctx, AV_LOG_INFO, "\n"); | 941 av_log(avctx, AV_LOG_INFO, "\n"); |
942 } | 942 } |
943 | 943 |
944 if (i % 16 != 0) | 944 if (i % 16 != 0) |
945 av_log(avctx, AV_LOG_INFO, "\n"); | 945 av_log(avctx, AV_LOG_INFO, "\n"); |
946 | 946 |
947 #endif | 947 #endif |
948 | 948 |
949 clut_id = *buf++; | 949 clut_id = *buf++; |
950 buf += 1; | 950 buf += 1; |
951 | 951 |
952 clut = get_clut(ctx, clut_id); | 952 clut = get_clut(ctx, clut_id); |
953 | 953 |
954 if (clut == NULL) { | 954 if (clut == NULL) { |
955 clut = av_malloc(sizeof(DVBSubCLUT)); | 955 clut = av_malloc(sizeof(DVBSubCLUT)); |
956 | 956 |
957 memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); | 957 memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); |
958 | 958 |
959 clut->id = clut_id; | 959 clut->id = clut_id; |
960 | 960 |
961 clut->next = ctx->clut_list; | 961 clut->next = ctx->clut_list; |
962 ctx->clut_list = clut; | 962 ctx->clut_list = clut; |
963 } | 963 } |
964 | 964 |
965 while (buf + 4 < buf_end) | 965 while (buf + 4 < buf_end) |
966 { | 966 { |
967 entry_id = *buf++; | 967 entry_id = *buf++; |
968 | 968 |
969 depth = (*buf) & 0xe0; | 969 depth = (*buf) & 0xe0; |
970 | 970 |
971 if (depth == 0) { | 971 if (depth == 0) { |
972 av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf); | 972 av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf); |
973 return; | 973 return; |
974 } | 974 } |
975 | 975 |
976 full_range = (*buf++) & 1; | 976 full_range = (*buf++) & 1; |
977 | 977 |
978 if (full_range) { | 978 if (full_range) { |
979 y = *buf++; | 979 y = *buf++; |
980 cr = *buf++; | 980 cr = *buf++; |
981 cb = *buf++; | 981 cb = *buf++; |
982 alpha = *buf++; | 982 alpha = *buf++; |
983 } else { | 983 } else { |
984 y = buf[0] & 0xfc; | 984 y = buf[0] & 0xfc; |
985 cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4; | 985 cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4; |
986 cb = (buf[1] << 2) & 0xf0; | 986 cb = (buf[1] << 2) & 0xf0; |
987 alpha = (buf[1] << 6) & 0xc0; | 987 alpha = (buf[1] << 6) & 0xc0; |
988 | 988 |
989 buf += 2; | 989 buf += 2; |
990 } | 990 } |
991 | 991 |
992 if (y == 0) | 992 if (y == 0) |
993 alpha = 0xff; | 993 alpha = 0xff; |
994 | 994 |
995 YUV_TO_RGB1_CCIR(cb, cr); | 995 YUV_TO_RGB1_CCIR(cb, cr); |
996 YUV_TO_RGB2_CCIR(r, g, b, y); | 996 YUV_TO_RGB2_CCIR(r, g, b, y); |
997 | 997 |
998 #ifdef DEBUG | 998 #ifdef DEBUG |
999 av_log(avctx, AV_LOG_INFO, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha); | 999 av_log(avctx, AV_LOG_INFO, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha); |
1000 #endif | 1000 #endif |
1001 | 1001 |
1002 if (depth & 0x80) | 1002 if (depth & 0x80) |
1003 clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha); | 1003 clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha); |
1004 if (depth & 0x40) | 1004 if (depth & 0x40) |
1005 clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha); | 1005 clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha); |
1006 if (depth & 0x20) | 1006 if (depth & 0x20) |
1011 | 1011 |
1012 static void dvbsub_parse_region_segment(AVCodecContext *avctx, | 1012 static void dvbsub_parse_region_segment(AVCodecContext *avctx, |
1013 uint8_t *buf, int buf_size) | 1013 uint8_t *buf, int buf_size) |
1014 { | 1014 { |
1015 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; | 1015 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
1016 | 1016 |
1017 uint8_t *buf_end = buf + buf_size; | 1017 uint8_t *buf_end = buf + buf_size; |
1018 int region_id, object_id; | 1018 int region_id, object_id; |
1019 DVBSubRegion *region; | 1019 DVBSubRegion *region; |
1020 DVBSubObject *object; | 1020 DVBSubObject *object; |
1021 DVBSubObjectDisplay *display; | 1021 DVBSubObjectDisplay *display; |
1022 int fill; | 1022 int fill; |
1023 | 1023 |
1024 if (buf_size < 10) | 1024 if (buf_size < 10) |
1025 return; | 1025 return; |
1026 | 1026 |
1027 region_id = *buf++; | 1027 region_id = *buf++; |
1028 | 1028 |
1029 region = get_region(ctx, region_id); | 1029 region = get_region(ctx, region_id); |
1030 | 1030 |
1031 if (region == NULL) | 1031 if (region == NULL) |
1032 { | 1032 { |
1033 region = av_mallocz(sizeof(DVBSubRegion)); | 1033 region = av_mallocz(sizeof(DVBSubRegion)); |
1034 | 1034 |
1035 region->id = region_id; | 1035 region->id = region_id; |
1036 | 1036 |
1037 region->next = ctx->region_list; | 1037 region->next = ctx->region_list; |
1038 ctx->region_list = region; | 1038 ctx->region_list = region; |
1039 } | 1039 } |
1040 | 1040 |
1041 fill = ((*buf++) >> 3) & 1; | 1041 fill = ((*buf++) >> 3) & 1; |
1042 | 1042 |
1043 region->width = BE_16(buf); | 1043 region->width = BE_16(buf); |
1044 buf += 2; | 1044 buf += 2; |
1045 region->height = BE_16(buf); | 1045 region->height = BE_16(buf); |
1046 buf += 2; | 1046 buf += 2; |
1047 | 1047 |
1048 if (region->width * region->height != region->buf_size) { | 1048 if (region->width * region->height != region->buf_size) { |
1049 if (region->pbuf != 0) | 1049 if (region->pbuf != 0) |
1050 av_free(region->pbuf); | 1050 av_free(region->pbuf); |
1051 | 1051 |
1052 region->buf_size = region->width * region->height; | 1052 region->buf_size = region->width * region->height; |
1053 | 1053 |
1054 region->pbuf = av_malloc(region->buf_size); | 1054 region->pbuf = av_malloc(region->buf_size); |
1055 | 1055 |
1056 fill = 1; | 1056 fill = 1; |
1057 } | 1057 } |
1058 | 1058 |
1059 region->depth = 1 << (((*buf++) >> 2) & 7); | 1059 region->depth = 1 << (((*buf++) >> 2) & 7); |
1060 region->clut = *buf++; | 1060 region->clut = *buf++; |
1061 | 1061 |
1062 if (region->depth == 8) | 1062 if (region->depth == 8) |
1063 region->bgcolour = *buf++; | 1063 region->bgcolour = *buf++; |
1064 else { | 1064 else { |
1065 buf += 1; | 1065 buf += 1; |
1066 | 1066 |
1067 if (region->depth == 4) | 1067 if (region->depth == 4) |
1068 region->bgcolour = (((*buf++) >> 4) & 15); | 1068 region->bgcolour = (((*buf++) >> 4) & 15); |
1069 else | 1069 else |
1070 region->bgcolour = (((*buf++) >> 2) & 3); | 1070 region->bgcolour = (((*buf++) >> 2) & 3); |
1071 } | 1071 } |
1084 delete_region_display_list(ctx, region); | 1084 delete_region_display_list(ctx, region); |
1085 | 1085 |
1086 while (buf + 5 < buf_end) { | 1086 while (buf + 5 < buf_end) { |
1087 object_id = BE_16(buf); | 1087 object_id = BE_16(buf); |
1088 buf += 2; | 1088 buf += 2; |
1089 | 1089 |
1090 object = get_object(ctx, object_id); | 1090 object = get_object(ctx, object_id); |
1091 | 1091 |
1092 if (object == NULL) { | 1092 if (object == NULL) { |
1093 object = av_mallocz(sizeof(DVBSubObject)); | 1093 object = av_mallocz(sizeof(DVBSubObject)); |
1094 | 1094 |
1095 object->id = object_id; | 1095 object->id = object_id; |
1096 object->next = ctx->object_list; | 1096 object->next = ctx->object_list; |
1097 ctx->object_list = object; | 1097 ctx->object_list = object; |
1098 } | 1098 } |
1099 | 1099 |
1100 object->type = (*buf) >> 6; | 1100 object->type = (*buf) >> 6; |
1101 | 1101 |
1102 display = av_mallocz(sizeof(DVBSubObjectDisplay)); | 1102 display = av_mallocz(sizeof(DVBSubObjectDisplay)); |
1103 | 1103 |
1104 display->object_id = object_id; | 1104 display->object_id = object_id; |
1105 display->region_id = region_id; | 1105 display->region_id = region_id; |
1106 | 1106 |
1107 display->x_pos = BE_16(buf) & 0xfff; | 1107 display->x_pos = BE_16(buf) & 0xfff; |
1108 buf += 2; | 1108 buf += 2; |
1109 display->y_pos = BE_16(buf) & 0xfff; | 1109 display->y_pos = BE_16(buf) & 0xfff; |
1110 buf += 2; | 1110 buf += 2; |
1111 | 1111 |
1112 if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) { | 1112 if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) { |
1113 display->fgcolour = *buf++; | 1113 display->fgcolour = *buf++; |
1114 display->bgcolour = *buf++; | 1114 display->bgcolour = *buf++; |
1115 } | 1115 } |
1116 | 1116 |
1117 display->region_list_next = region->display_list; | 1117 display->region_list_next = region->display_list; |
1118 region->display_list = display; | 1118 region->display_list = display; |
1119 | 1119 |
1120 display->object_list_next = object->display_list; | 1120 display->object_list_next = object->display_list; |
1121 object->display_list = display; | 1121 object->display_list = display; |
1122 } | 1122 } |
1123 } | 1123 } |
1124 | 1124 |
1126 uint8_t *buf, int buf_size) | 1126 uint8_t *buf, int buf_size) |
1127 { | 1127 { |
1128 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; | 1128 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
1129 DVBSubRegionDisplay *display; | 1129 DVBSubRegionDisplay *display; |
1130 DVBSubRegionDisplay *tmp_display_list, **tmp_ptr; | 1130 DVBSubRegionDisplay *tmp_display_list, **tmp_ptr; |
1131 | 1131 |
1132 uint8_t *buf_end = buf + buf_size; | 1132 uint8_t *buf_end = buf + buf_size; |
1133 int region_id; | 1133 int region_id; |
1134 int page_state; | 1134 int page_state; |
1135 | 1135 |
1136 if (buf_size < 1) | 1136 if (buf_size < 1) |
1137 return; | 1137 return; |
1138 | 1138 |
1139 ctx->time_out = *buf++; | 1139 ctx->time_out = *buf++; |
1140 page_state = ((*buf++) >> 2) & 3; | 1140 page_state = ((*buf++) >> 2) & 3; |
1141 | 1141 |
1142 #ifdef DEBUG | 1142 #ifdef DEBUG |
1143 av_log(avctx, AV_LOG_INFO, "Page time out %ds, state %d\n", ctx->time_out, page_state); | 1143 av_log(avctx, AV_LOG_INFO, "Page time out %ds, state %d\n", ctx->time_out, page_state); |
1144 #endif | 1144 #endif |
1145 | 1145 |
1146 if (page_state == 2) | 1146 if (page_state == 2) |
1147 { | 1147 { |
1148 delete_state(ctx); | 1148 delete_state(ctx); |
1149 } | 1149 } |
1150 | 1150 |
1151 tmp_display_list = ctx->display_list; | 1151 tmp_display_list = ctx->display_list; |
1152 ctx->display_list = NULL; | 1152 ctx->display_list = NULL; |
1153 ctx->display_list_size = 0; | 1153 ctx->display_list_size = 0; |
1154 | 1154 |
1155 while (buf + 5 < buf_end) { | 1155 while (buf + 5 < buf_end) { |
1156 region_id = *buf++; | 1156 region_id = *buf++; |
1157 buf += 1; | 1157 buf += 1; |
1158 | 1158 |
1159 display = tmp_display_list; | 1159 display = tmp_display_list; |
1160 tmp_ptr = &tmp_display_list; | 1160 tmp_ptr = &tmp_display_list; |
1161 | 1161 |
1162 while (display != NULL && display->region_id != region_id) { | 1162 while (display != NULL && display->region_id != region_id) { |
1163 tmp_ptr = &display->next; | 1163 tmp_ptr = &display->next; |
1164 display = display->next; | 1164 display = display->next; |
1165 } | 1165 } |
1166 | 1166 |
1167 if (display == NULL) | 1167 if (display == NULL) |
1168 display = av_mallocz(sizeof(DVBSubRegionDisplay)); | 1168 display = av_mallocz(sizeof(DVBSubRegionDisplay)); |
1169 | 1169 |
1170 display->region_id = region_id; | 1170 display->region_id = region_id; |
1171 | 1171 |
1172 display->x_pos = BE_16(buf); | 1172 display->x_pos = BE_16(buf); |
1173 buf += 2; | 1173 buf += 2; |
1174 display->y_pos = BE_16(buf); | 1174 display->y_pos = BE_16(buf); |
1175 buf += 2; | 1175 buf += 2; |
1176 | 1176 |
1177 *tmp_ptr = display->next; | 1177 *tmp_ptr = display->next; |
1178 | 1178 |
1179 display->next = ctx->display_list; | 1179 display->next = ctx->display_list; |
1180 ctx->display_list = display; | 1180 ctx->display_list = display; |
1181 ctx->display_list_size++; | 1181 ctx->display_list_size++; |
1182 | 1182 |
1183 #ifdef DEBUG | 1183 #ifdef DEBUG |
1184 av_log(avctx, AV_LOG_INFO, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos); | 1184 av_log(avctx, AV_LOG_INFO, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos); |
1185 #endif | 1185 #endif |
1186 } | 1186 } |
1187 | 1187 |
1188 while (tmp_display_list != 0) { | 1188 while (tmp_display_list != 0) { |
1189 display = tmp_display_list; | 1189 display = tmp_display_list; |
1190 | 1190 |
1191 tmp_display_list = display->next; | 1191 tmp_display_list = display->next; |
1192 | 1192 |
1193 av_free(display); | 1193 av_free(display); |
1194 } | 1194 } |
1195 | 1195 |
1196 } | 1196 } |
1197 | 1197 |
1198 | 1198 |
1199 #ifdef DEBUG_SAVE_IMAGES | 1199 #ifdef DEBUG_SAVE_IMAGES |
1200 static void save_display_set(DVBSubContext *ctx) | 1200 static void save_display_set(DVBSubContext *ctx) |
1211 | 1211 |
1212 x_pos = -1; | 1212 x_pos = -1; |
1213 y_pos = -1; | 1213 y_pos = -1; |
1214 width = 0; | 1214 width = 0; |
1215 height = 0; | 1215 height = 0; |
1216 | 1216 |
1217 for (display = ctx->display_list; display != NULL; display = display->next) { | 1217 for (display = ctx->display_list; display != NULL; display = display->next) { |
1218 region = get_region(ctx, display->region_id); | 1218 region = get_region(ctx, display->region_id); |
1219 | 1219 |
1220 if (x_pos == -1) { | 1220 if (x_pos == -1) { |
1221 x_pos = display->x_pos; | 1221 x_pos = display->x_pos; |
1222 y_pos = display->y_pos; | 1222 y_pos = display->y_pos; |
1223 width = region->width; | 1223 width = region->width; |
1224 height = region->height; | 1224 height = region->height; |
1225 } else { | 1225 } else { |
1226 if (display->x_pos < x_pos) { | 1226 if (display->x_pos < x_pos) { |
1227 width += (x_pos - display->x_pos); | 1227 width += (x_pos - display->x_pos); |
1228 x_pos = display->x_pos; | 1228 x_pos = display->x_pos; |
1229 } | 1229 } |
1230 | 1230 |
1231 if (display->y_pos < y_pos) { | 1231 if (display->y_pos < y_pos) { |
1232 height += (y_pos - display->y_pos); | 1232 height += (y_pos - display->y_pos); |
1233 y_pos = display->y_pos; | 1233 y_pos = display->y_pos; |
1234 } | 1234 } |
1235 | 1235 |
1236 if (display->x_pos + region->width > x_pos + width) { | 1236 if (display->x_pos + region->width > x_pos + width) { |
1237 width = display->x_pos + region->width - x_pos; | 1237 width = display->x_pos + region->width - x_pos; |
1238 } | 1238 } |
1239 | 1239 |
1240 if (display->y_pos + region->height > y_pos + height) { | 1240 if (display->y_pos + region->height > y_pos + height) { |
1241 height = display->y_pos + region->height - y_pos; | 1241 height = display->y_pos + region->height - y_pos; |
1242 } | 1242 } |
1243 } | 1243 } |
1244 } | 1244 } |
1245 | 1245 |
1246 if (x_pos >= 0) { | 1246 if (x_pos >= 0) { |
1247 | 1247 |
1248 pbuf = av_malloc(width * height * 4); | 1248 pbuf = av_malloc(width * height * 4); |
1249 | 1249 |
1250 for (display = ctx->display_list; display != NULL; display = display->next) { | 1250 for (display = ctx->display_list; display != NULL; display = display->next) { |
1251 region = get_region(ctx, display->region_id); | 1251 region = get_region(ctx, display->region_id); |
1252 | 1252 |
1268 case 4: | 1268 case 4: |
1269 default: | 1269 default: |
1270 clut_table = clut->clut16; | 1270 clut_table = clut->clut16; |
1271 break; | 1271 break; |
1272 } | 1272 } |
1273 | 1273 |
1274 for (y = 0; y < region->height; y++) { | 1274 for (y = 0; y < region->height; y++) { |
1275 for (x = 0; x < region->width; x++) { | 1275 for (x = 0; x < region->width; x++) { |
1276 pbuf[((y + y_off) * width) + x_off + x] = | 1276 pbuf[((y + y_off) * width) + x_off + x] = |
1277 clut_table[region->pbuf[y * region->width + x]]; | 1277 clut_table[region->pbuf[y * region->width + x]]; |
1278 } | 1278 } |
1279 } | 1279 } |
1280 | 1280 |
1281 } | 1281 } |
1282 | 1282 |
1283 snprintf(filename, 32, "dvbs.%d", fileno_index); | 1283 snprintf(filename, 32, "dvbs.%d", fileno_index); |
1284 | 1284 |
1285 png_save2(filename, pbuf, width, height); | 1285 png_save2(filename, pbuf, width, height); |
1286 | 1286 |
1287 av_free(pbuf); | 1287 av_free(pbuf); |
1288 } | 1288 } |
1289 | 1289 |
1290 fileno_index++; | 1290 fileno_index++; |
1291 } | 1291 } |
1292 #endif | 1292 #endif |
1293 | 1293 |
1294 static int dvbsub_display_end_segment(AVCodecContext *avctx, uint8_t *buf, | 1294 static int dvbsub_display_end_segment(AVCodecContext *avctx, uint8_t *buf, |
1295 int buf_size, AVSubtitle *sub) | 1295 int buf_size, AVSubtitle *sub) |
1296 { | 1296 { |
1297 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; | 1297 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
1298 | 1298 |
1299 DVBSubRegion *region; | 1299 DVBSubRegion *region; |
1300 DVBSubRegionDisplay *display; | 1300 DVBSubRegionDisplay *display; |
1301 AVSubtitleRect *rect; | 1301 AVSubtitleRect *rect; |
1302 DVBSubCLUT *clut; | 1302 DVBSubCLUT *clut; |
1303 uint32_t *clut_table; | 1303 uint32_t *clut_table; |
1304 int i; | 1304 int i; |
1305 | 1305 |
1306 sub->rects = NULL; | 1306 sub->rects = NULL; |
1307 sub->start_display_time = 0; | 1307 sub->start_display_time = 0; |
1308 sub->end_display_time = ctx->time_out * 1000; | 1308 sub->end_display_time = ctx->time_out * 1000; |
1309 sub->format = 0; | 1309 sub->format = 0; |
1310 | 1310 |
1311 sub->num_rects = ctx->display_list_size; | 1311 sub->num_rects = ctx->display_list_size; |
1312 | 1312 |
1313 if (sub->num_rects > 0) | 1313 if (sub->num_rects > 0) |
1314 sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects); | 1314 sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects); |
1315 | 1315 |
1316 i = 0; | 1316 i = 0; |
1317 | 1317 |
1318 for (display = ctx->display_list; display != NULL; display = display->next) { | 1318 for (display = ctx->display_list; display != NULL; display = display->next) { |
1319 region = get_region(ctx, display->region_id); | 1319 region = get_region(ctx, display->region_id); |
1320 rect = &sub->rects[i]; | 1320 rect = &sub->rects[i]; |
1321 | 1321 |
1322 if (region == NULL) | 1322 if (region == NULL) |
1323 continue; | 1323 continue; |
1324 | 1324 |
1325 rect->x = display->x_pos; | 1325 rect->x = display->x_pos; |
1326 rect->y = display->y_pos; | 1326 rect->y = display->y_pos; |
1327 rect->w = region->width; | 1327 rect->w = region->width; |
1328 rect->h = region->height; | 1328 rect->h = region->height; |
1329 rect->nb_colors = 16; | 1329 rect->nb_colors = 16; |
1330 rect->linesize = region->width; | 1330 rect->linesize = region->width; |
1331 | 1331 |
1332 clut = get_clut(ctx, region->clut); | 1332 clut = get_clut(ctx, region->clut); |
1333 | 1333 |
1334 if (clut == NULL) | 1334 if (clut == NULL) |
1335 clut = &default_clut; | 1335 clut = &default_clut; |
1336 | 1336 |
1337 switch (region->depth) { | 1337 switch (region->depth) { |
1338 case 2: | 1338 case 2: |
1339 clut_table = clut->clut4; | 1339 clut_table = clut->clut4; |
1340 break; | 1340 break; |
1341 case 8: | 1341 case 8: |
1344 case 4: | 1344 case 4: |
1345 default: | 1345 default: |
1346 clut_table = clut->clut16; | 1346 clut_table = clut->clut16; |
1347 break; | 1347 break; |
1348 } | 1348 } |
1349 | 1349 |
1350 rect->rgba_palette = av_malloc((1 << region->depth) * sizeof(uint32_t)); | 1350 rect->rgba_palette = av_malloc((1 << region->depth) * sizeof(uint32_t)); |
1351 memcpy(rect->rgba_palette, clut_table, (1 << region->depth) * sizeof(uint32_t)); | 1351 memcpy(rect->rgba_palette, clut_table, (1 << region->depth) * sizeof(uint32_t)); |
1352 | 1352 |
1353 rect->bitmap = av_malloc(region->buf_size); | 1353 rect->bitmap = av_malloc(region->buf_size); |
1354 memcpy(rect->bitmap, region->pbuf, region->buf_size); | 1354 memcpy(rect->bitmap, region->pbuf, region->buf_size); |
1355 | 1355 |
1356 i++; | 1356 i++; |
1357 } | 1357 } |
1358 | 1358 |
1359 sub->num_rects = i; | 1359 sub->num_rects = i; |
1360 | 1360 |
1361 #ifdef DEBUG_SAVE_IMAGES | 1361 #ifdef DEBUG_SAVE_IMAGES |
1362 save_display_set(ctx); | 1362 save_display_set(ctx); |
1363 #endif | 1363 #endif |
1364 | 1364 |
1365 return 1; | 1365 return 1; |
1366 } | 1366 } |
1367 | 1367 |
1368 static int dvbsub_decode(AVCodecContext *avctx, | 1368 static int dvbsub_decode(AVCodecContext *avctx, |
1369 void *data, int *data_size, | 1369 void *data, int *data_size, |
1373 AVSubtitle *sub = (AVSubtitle*) data; | 1373 AVSubtitle *sub = (AVSubtitle*) data; |
1374 uint8_t *p, *p_end; | 1374 uint8_t *p, *p_end; |
1375 int segment_type; | 1375 int segment_type; |
1376 int page_id; | 1376 int page_id; |
1377 int segment_length; | 1377 int segment_length; |
1378 | 1378 |
1379 #ifdef DEBUG_PACKET_CONTENTS | 1379 #ifdef DEBUG_PACKET_CONTENTS |
1380 int i; | 1380 int i; |
1381 | 1381 |
1382 av_log(avctx, AV_LOG_INFO, "DVB sub packet:\n"); | 1382 av_log(avctx, AV_LOG_INFO, "DVB sub packet:\n"); |
1383 | 1383 |
1385 { | 1385 { |
1386 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); | 1386 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
1387 if (i % 16 == 15) | 1387 if (i % 16 == 15) |
1388 av_log(avctx, AV_LOG_INFO, "\n"); | 1388 av_log(avctx, AV_LOG_INFO, "\n"); |
1389 } | 1389 } |
1390 | 1390 |
1391 if (i % 16 != 0) | 1391 if (i % 16 != 0) |
1392 av_log(avctx, AV_LOG_INFO, "\n"); | 1392 av_log(avctx, AV_LOG_INFO, "\n"); |
1393 | 1393 |
1394 #endif | 1394 #endif |
1395 | 1395 |
1396 if (buf_size <= 2) | 1396 if (buf_size <= 2) |
1397 return -1; | 1397 return -1; |
1398 | 1398 |
1399 p = buf; | 1399 p = buf; |
1400 p_end = buf + buf_size; | 1400 p_end = buf + buf_size; |
1401 | 1401 |
1402 while (p < p_end && *p == 0x0f) | 1402 while (p < p_end && *p == 0x0f) |
1403 { | 1403 { |
1404 p += 1; | 1404 p += 1; |
1405 segment_type = *p++; | 1405 segment_type = *p++; |
1406 page_id = BE_16(p); | 1406 page_id = BE_16(p); |
1407 p += 2; | 1407 p += 2; |
1408 segment_length = BE_16(p); | 1408 segment_length = BE_16(p); |
1409 p += 2; | 1409 p += 2; |
1410 | 1410 |
1411 if (page_id == ctx->composition_id || page_id == ctx->ancillary_id) { | 1411 if (page_id == ctx->composition_id || page_id == ctx->ancillary_id) { |
1412 switch (segment_type) { | 1412 switch (segment_type) { |
1413 case DVBSUB_PAGE_SEGMENT: | 1413 case DVBSUB_PAGE_SEGMENT: |
1414 dvbsub_parse_page_segment(avctx, p, segment_length); | 1414 dvbsub_parse_page_segment(avctx, p, segment_length); |
1415 break; | 1415 break; |
1425 case DVBSUB_DISPLAY_SEGMENT: | 1425 case DVBSUB_DISPLAY_SEGMENT: |
1426 *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub); | 1426 *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub); |
1427 break; | 1427 break; |
1428 default: | 1428 default: |
1429 #ifdef DEBUG | 1429 #ifdef DEBUG |
1430 av_log(avctx, AV_LOG_INFO, "Subtitling segment type 0x%x, page id %d, length %d\n", | 1430 av_log(avctx, AV_LOG_INFO, "Subtitling segment type 0x%x, page id %d, length %d\n", |
1431 segment_type, page_id, segment_length); | 1431 segment_type, page_id, segment_length); |
1432 #endif | 1432 #endif |
1433 break; | 1433 break; |
1434 } | 1434 } |
1435 } | 1435 } |
1436 | 1436 |
1437 p += segment_length; | 1437 p += segment_length; |
1438 } | 1438 } |
1439 | 1439 |
1440 if (p != p_end) | 1440 if (p != p_end) |
1441 { | 1441 { |
1442 #ifdef DEBUG | 1442 #ifdef DEBUG |
1443 av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n"); | 1443 av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n"); |
1444 #endif | 1444 #endif |
1481 return 0; | 1481 return 0; |
1482 } | 1482 } |
1483 | 1483 |
1484 static int dvbsub_parse(AVCodecParserContext *s, | 1484 static int dvbsub_parse(AVCodecParserContext *s, |
1485 AVCodecContext *avctx, | 1485 AVCodecContext *avctx, |
1486 uint8_t **poutbuf, int *poutbuf_size, | 1486 uint8_t **poutbuf, int *poutbuf_size, |
1487 const uint8_t *buf, int buf_size) | 1487 const uint8_t *buf, int buf_size) |
1488 { | 1488 { |
1489 DVBSubParseContext *pc = s->priv_data; | 1489 DVBSubParseContext *pc = s->priv_data; |
1490 uint8_t *p, *p_end; | 1490 uint8_t *p, *p_end; |
1491 int len, buf_pos = 0; | 1491 int len, buf_pos = 0; |
1492 | 1492 |
1493 #ifdef DEBUG | 1493 #ifdef DEBUG |
1494 av_log(avctx, AV_LOG_INFO, "DVB parse packet pts=%Lx, lpts=%Lx, cpts=%Lx:\n", | 1494 av_log(avctx, AV_LOG_INFO, "DVB parse packet pts=%Lx, lpts=%Lx, cpts=%Lx:\n", |
1495 s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]); | 1495 s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]); |
1496 #endif | 1496 #endif |
1497 | 1497 |
1498 #ifdef DEBUG_PACKET_CONTENTS | 1498 #ifdef DEBUG_PACKET_CONTENTS |
1499 int i; | 1499 int i; |
1500 | 1500 |
1501 for (i=0; i < buf_size; i++) | 1501 for (i=0; i < buf_size; i++) |
1502 { | 1502 { |
1503 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); | 1503 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
1504 if (i % 16 == 15) | 1504 if (i % 16 == 15) |
1505 av_log(avctx, AV_LOG_INFO, "\n"); | 1505 av_log(avctx, AV_LOG_INFO, "\n"); |
1506 } | 1506 } |
1507 | 1507 |
1508 if (i % 16 != 0) | 1508 if (i % 16 != 0) |
1509 av_log(avctx, AV_LOG_INFO, "\n"); | 1509 av_log(avctx, AV_LOG_INFO, "\n"); |
1510 | 1510 |
1511 #endif | 1511 #endif |
1512 | 1512 |
1513 *poutbuf = NULL; | 1513 *poutbuf = NULL; |
1514 *poutbuf_size = 0; | 1514 *poutbuf_size = 0; |
1515 | 1515 |
1516 s->fetch_timestamp = 1; | 1516 s->fetch_timestamp = 1; |
1517 | 1517 |
1518 if (s->last_pts != s->pts && s->last_pts != AV_NOPTS_VALUE) /* Start of a new packet */ | 1518 if (s->last_pts != s->pts && s->last_pts != AV_NOPTS_VALUE) /* Start of a new packet */ |
1519 { | 1519 { |
1520 if (pc->packet_index != pc->packet_start) | 1520 if (pc->packet_index != pc->packet_start) |
1521 { | 1521 { |
1522 #ifdef DEBUG | 1522 #ifdef DEBUG |
1523 av_log(avctx, AV_LOG_INFO, "Discarding %d bytes\n", | 1523 av_log(avctx, AV_LOG_INFO, "Discarding %d bytes\n", |
1524 pc->packet_index - pc->packet_start); | 1524 pc->packet_index - pc->packet_start); |
1525 #endif | 1525 #endif |
1526 } | 1526 } |
1527 | 1527 |
1528 pc->packet_start = 0; | 1528 pc->packet_start = 0; |
1529 pc->packet_index = 0; | 1529 pc->packet_index = 0; |
1530 | 1530 |
1531 if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) { | 1531 if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) { |
1532 #ifdef DEBUG | 1532 #ifdef DEBUG |
1533 av_log(avctx, AV_LOG_INFO, "Bad packet header\n"); | 1533 av_log(avctx, AV_LOG_INFO, "Bad packet header\n"); |
1534 #endif | 1534 #endif |
1535 return -1; | 1535 return -1; |
1536 } | 1536 } |
1537 | 1537 |
1538 buf_pos = 2; | 1538 buf_pos = 2; |
1539 | 1539 |
1540 pc->in_packet = 1; | 1540 pc->in_packet = 1; |
1541 } else { | 1541 } else { |
1542 if (pc->packet_start != 0) | 1542 if (pc->packet_start != 0) |
1543 { | 1543 { |
1544 if (pc->packet_index != pc->packet_start) | 1544 if (pc->packet_index != pc->packet_start) |
1552 pc->packet_start = 0; | 1552 pc->packet_start = 0; |
1553 pc->packet_index = 0; | 1553 pc->packet_index = 0; |
1554 } | 1554 } |
1555 } | 1555 } |
1556 } | 1556 } |
1557 | 1557 |
1558 if (buf_size - buf_pos + pc->packet_index > PARSE_BUF_SIZE) | 1558 if (buf_size - buf_pos + pc->packet_index > PARSE_BUF_SIZE) |
1559 return -1; | 1559 return -1; |
1560 | 1560 |
1561 /* if not currently in a packet, discard data */ | 1561 /* if not currently in a packet, discard data */ |
1562 if (pc->in_packet == 0) | 1562 if (pc->in_packet == 0) |
1563 return buf_size; | 1563 return buf_size; |
1564 | 1564 |
1565 memcpy(pc->packet_buf + pc->packet_index, buf + buf_pos, buf_size - buf_pos); | 1565 memcpy(pc->packet_buf + pc->packet_index, buf + buf_pos, buf_size - buf_pos); |
1566 pc->packet_index += buf_size - buf_pos; | 1566 pc->packet_index += buf_size - buf_pos; |
1567 | 1567 |
1568 p = pc->packet_buf; | 1568 p = pc->packet_buf; |
1569 p_end = pc->packet_buf + pc->packet_index; | 1569 p_end = pc->packet_buf + pc->packet_index; |
1570 | 1570 |
1571 while (p < p_end) | 1571 while (p < p_end) |
1572 { | 1572 { |
1573 if (*p == 0x0f) | 1573 if (*p == 0x0f) |
1574 { | 1574 { |
1575 if (p + 6 <= p_end) | 1575 if (p + 6 <= p_end) |
1576 { | 1576 { |
1577 len = BE_16(p + 4); | 1577 len = BE_16(p + 4); |
1578 | 1578 |
1592 av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n"); | 1592 av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n"); |
1593 #endif | 1593 #endif |
1594 } | 1594 } |
1595 pc->packet_index = p - pc->packet_buf; | 1595 pc->packet_index = p - pc->packet_buf; |
1596 pc->in_packet = 0; | 1596 pc->in_packet = 0; |
1597 break; | 1597 break; |
1598 } else { | 1598 } else { |
1599 av_log(avctx, AV_LOG_ERROR, "Junk in packet\n"); | 1599 av_log(avctx, AV_LOG_ERROR, "Junk in packet\n"); |
1600 | 1600 |
1601 pc->packet_index = p - pc->packet_buf; | 1601 pc->packet_index = p - pc->packet_buf; |
1602 pc->in_packet = 0; | 1602 pc->in_packet = 0; |
1603 break; | 1603 break; |
1604 } | 1604 } |
1605 } | 1605 } |
1607 if (*poutbuf_size > 0) | 1607 if (*poutbuf_size > 0) |
1608 { | 1608 { |
1609 *poutbuf = pc->packet_buf; | 1609 *poutbuf = pc->packet_buf; |
1610 pc->packet_start = *poutbuf_size; | 1610 pc->packet_start = *poutbuf_size; |
1611 } | 1611 } |
1612 | 1612 |
1613 if (s->last_pts == AV_NOPTS_VALUE) | 1613 if (s->last_pts == AV_NOPTS_VALUE) |
1614 s->last_pts = s->pts; | 1614 s->last_pts = s->pts; |
1615 | 1615 |
1616 return buf_size; | 1616 return buf_size; |
1617 } | 1617 } |
1618 | 1618 |
1619 static void dvbsub_parse_close(AVCodecParserContext *s) | 1619 static void dvbsub_parse_close(AVCodecParserContext *s) |
1620 { | 1620 { |