You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1580 lines
43KB

  1. /*
  2. * DVB subtitle decoding
  3. * Copyright (c) 2005 Ian Caulfield
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avcodec.h"
  22. #include "get_bits.h"
  23. #include "bytestream.h"
  24. #include "libavutil/colorspace.h"
  25. #include "libavutil/opt.h"
  26. #define DVBSUB_PAGE_SEGMENT 0x10
  27. #define DVBSUB_REGION_SEGMENT 0x11
  28. #define DVBSUB_CLUT_SEGMENT 0x12
  29. #define DVBSUB_OBJECT_SEGMENT 0x13
  30. #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14
  31. #define DVBSUB_DISPLAY_SEGMENT 0x80
  32. #define cm (ff_crop_tab + MAX_NEG_CROP)
  33. #ifdef DEBUG
  34. #if 0
  35. static void png_save(const char *filename, uint8_t *bitmap, int w, int h,
  36. uint32_t *rgba_palette)
  37. {
  38. int x, y, v;
  39. FILE *f;
  40. char fname[40], fname2[40];
  41. char command[1024];
  42. snprintf(fname, 40, "%s.ppm", filename);
  43. f = fopen(fname, "w");
  44. if (!f) {
  45. perror(fname);
  46. return;
  47. }
  48. fprintf(f, "P6\n"
  49. "%d %d\n"
  50. "%d\n",
  51. w, h, 255);
  52. for(y = 0; y < h; y++) {
  53. for(x = 0; x < w; x++) {
  54. v = rgba_palette[bitmap[y * w + x]];
  55. putc((v >> 16) & 0xff, f);
  56. putc((v >> 8) & 0xff, f);
  57. putc((v >> 0) & 0xff, f);
  58. }
  59. }
  60. fclose(f);
  61. snprintf(fname2, 40, "%s-a.pgm", filename);
  62. f = fopen(fname2, "w");
  63. if (!f) {
  64. perror(fname2);
  65. return;
  66. }
  67. fprintf(f, "P5\n"
  68. "%d %d\n"
  69. "%d\n",
  70. w, h, 255);
  71. for(y = 0; y < h; y++) {
  72. for(x = 0; x < w; x++) {
  73. v = rgba_palette[bitmap[y * w + x]];
  74. putc((v >> 24) & 0xff, f);
  75. }
  76. }
  77. fclose(f);
  78. snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename);
  79. system(command);
  80. snprintf(command, 1024, "rm %s %s", fname, fname2);
  81. system(command);
  82. }
  83. #endif
  84. static void png_save2(const char *filename, uint32_t *bitmap, int w, int h)
  85. {
  86. int x, y, v;
  87. FILE *f;
  88. char fname[40], fname2[40];
  89. char command[1024];
  90. snprintf(fname, sizeof(fname), "%s.ppm", filename);
  91. f = fopen(fname, "w");
  92. if (!f) {
  93. perror(fname);
  94. return;
  95. }
  96. fprintf(f, "P6\n"
  97. "%d %d\n"
  98. "%d\n",
  99. w, h, 255);
  100. for(y = 0; y < h; y++) {
  101. for(x = 0; x < w; x++) {
  102. v = bitmap[y * w + x];
  103. putc((v >> 16) & 0xff, f);
  104. putc((v >> 8) & 0xff, f);
  105. putc((v >> 0) & 0xff, f);
  106. }
  107. }
  108. fclose(f);
  109. snprintf(fname2, sizeof(fname2), "%s-a.pgm", filename);
  110. f = fopen(fname2, "w");
  111. if (!f) {
  112. perror(fname2);
  113. return;
  114. }
  115. fprintf(f, "P5\n"
  116. "%d %d\n"
  117. "%d\n",
  118. w, h, 255);
  119. for(y = 0; y < h; y++) {
  120. for(x = 0; x < w; x++) {
  121. v = bitmap[y * w + x];
  122. putc((v >> 24) & 0xff, f);
  123. }
  124. }
  125. fclose(f);
  126. snprintf(command, sizeof(command), "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename);
  127. system(command);
  128. snprintf(command, sizeof(command), "rm %s %s", fname, fname2);
  129. system(command);
  130. }
  131. #endif
  132. #define RGBA(r,g,b,a) (((unsigned)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
  133. typedef struct DVBSubCLUT {
  134. int id;
  135. int version;
  136. uint32_t clut4[4];
  137. uint32_t clut16[16];
  138. uint32_t clut256[256];
  139. struct DVBSubCLUT *next;
  140. } DVBSubCLUT;
  141. static DVBSubCLUT default_clut;
  142. typedef struct DVBSubObjectDisplay {
  143. int object_id;
  144. int region_id;
  145. int x_pos;
  146. int y_pos;
  147. int fgcolor;
  148. int bgcolor;
  149. struct DVBSubObjectDisplay *region_list_next;
  150. struct DVBSubObjectDisplay *object_list_next;
  151. } DVBSubObjectDisplay;
  152. typedef struct DVBSubObject {
  153. int id;
  154. int version;
  155. int type;
  156. DVBSubObjectDisplay *display_list;
  157. struct DVBSubObject *next;
  158. } DVBSubObject;
  159. typedef struct DVBSubRegionDisplay {
  160. int region_id;
  161. int x_pos;
  162. int y_pos;
  163. struct DVBSubRegionDisplay *next;
  164. } DVBSubRegionDisplay;
  165. typedef struct DVBSubRegion {
  166. int id;
  167. int version;
  168. int width;
  169. int height;
  170. int depth;
  171. int clut;
  172. int bgcolor;
  173. uint8_t *pbuf;
  174. int buf_size;
  175. int dirty;
  176. DVBSubObjectDisplay *display_list;
  177. struct DVBSubRegion *next;
  178. } DVBSubRegion;
  179. typedef struct DVBSubDisplayDefinition {
  180. int version;
  181. int x;
  182. int y;
  183. int width;
  184. int height;
  185. } DVBSubDisplayDefinition;
  186. typedef struct DVBSubContext {
  187. AVClass *class;
  188. int composition_id;
  189. int ancillary_id;
  190. int version;
  191. int time_out;
  192. DVBSubRegion *region_list;
  193. DVBSubCLUT *clut_list;
  194. DVBSubObject *object_list;
  195. DVBSubRegionDisplay *display_list;
  196. DVBSubDisplayDefinition *display_definition;
  197. } DVBSubContext;
  198. static DVBSubObject* get_object(DVBSubContext *ctx, int object_id)
  199. {
  200. DVBSubObject *ptr = ctx->object_list;
  201. while (ptr && ptr->id != object_id) {
  202. ptr = ptr->next;
  203. }
  204. return ptr;
  205. }
  206. static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)
  207. {
  208. DVBSubCLUT *ptr = ctx->clut_list;
  209. while (ptr && ptr->id != clut_id) {
  210. ptr = ptr->next;
  211. }
  212. return ptr;
  213. }
  214. static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
  215. {
  216. DVBSubRegion *ptr = ctx->region_list;
  217. while (ptr && ptr->id != region_id) {
  218. ptr = ptr->next;
  219. }
  220. return ptr;
  221. }
  222. static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)
  223. {
  224. DVBSubObject *object, *obj2, **obj2_ptr;
  225. DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr;
  226. while (region->display_list) {
  227. display = region->display_list;
  228. object = get_object(ctx, display->object_id);
  229. if (object) {
  230. obj_disp_ptr = &object->display_list;
  231. obj_disp = *obj_disp_ptr;
  232. while (obj_disp && obj_disp != display) {
  233. obj_disp_ptr = &obj_disp->object_list_next;
  234. obj_disp = *obj_disp_ptr;
  235. }
  236. if (obj_disp) {
  237. *obj_disp_ptr = obj_disp->object_list_next;
  238. if (!object->display_list) {
  239. obj2_ptr = &ctx->object_list;
  240. obj2 = *obj2_ptr;
  241. while (obj2 != object) {
  242. assert(obj2);
  243. obj2_ptr = &obj2->next;
  244. obj2 = *obj2_ptr;
  245. }
  246. *obj2_ptr = obj2->next;
  247. av_free(obj2);
  248. }
  249. }
  250. }
  251. region->display_list = display->region_list_next;
  252. av_free(display);
  253. }
  254. }
  255. static void delete_cluts(DVBSubContext *ctx)
  256. {
  257. DVBSubCLUT *clut;
  258. while (ctx->clut_list) {
  259. clut = ctx->clut_list;
  260. ctx->clut_list = clut->next;
  261. av_free(clut);
  262. }
  263. }
  264. static void delete_objects(DVBSubContext *ctx)
  265. {
  266. DVBSubObject *object;
  267. while (ctx->object_list) {
  268. object = ctx->object_list;
  269. ctx->object_list = object->next;
  270. av_free(object);
  271. }
  272. }
  273. static void delete_regions(DVBSubContext *ctx)
  274. {
  275. DVBSubRegion *region;
  276. while (ctx->region_list) {
  277. region = ctx->region_list;
  278. ctx->region_list = region->next;
  279. delete_region_display_list(ctx, region);
  280. av_free(region->pbuf);
  281. av_free(region);
  282. }
  283. }
  284. static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
  285. {
  286. int i, r, g, b, a = 0;
  287. DVBSubContext *ctx = avctx->priv_data;
  288. if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
  289. av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n");
  290. ctx->composition_id = -1;
  291. ctx->ancillary_id = -1;
  292. } else {
  293. if (avctx->extradata_size > 5) {
  294. av_log(avctx, AV_LOG_WARNING, "Decoding first DVB subtitles sub-stream\n");
  295. }
  296. ctx->composition_id = AV_RB16(avctx->extradata);
  297. ctx->ancillary_id = AV_RB16(avctx->extradata + 2);
  298. }
  299. ctx->version = -1;
  300. default_clut.id = -1;
  301. default_clut.next = NULL;
  302. default_clut.clut4[0] = RGBA( 0, 0, 0, 0);
  303. default_clut.clut4[1] = RGBA(255, 255, 255, 255);
  304. default_clut.clut4[2] = RGBA( 0, 0, 0, 255);
  305. default_clut.clut4[3] = RGBA(127, 127, 127, 255);
  306. default_clut.clut16[0] = RGBA( 0, 0, 0, 0);
  307. for (i = 1; i < 16; i++) {
  308. if (i < 8) {
  309. r = (i & 1) ? 255 : 0;
  310. g = (i & 2) ? 255 : 0;
  311. b = (i & 4) ? 255 : 0;
  312. } else {
  313. r = (i & 1) ? 127 : 0;
  314. g = (i & 2) ? 127 : 0;
  315. b = (i & 4) ? 127 : 0;
  316. }
  317. default_clut.clut16[i] = RGBA(r, g, b, 255);
  318. }
  319. default_clut.clut256[0] = RGBA( 0, 0, 0, 0);
  320. for (i = 1; i < 256; i++) {
  321. if (i < 8) {
  322. r = (i & 1) ? 255 : 0;
  323. g = (i & 2) ? 255 : 0;
  324. b = (i & 4) ? 255 : 0;
  325. a = 63;
  326. } else {
  327. switch (i & 0x88) {
  328. case 0x00:
  329. r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
  330. g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
  331. b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
  332. a = 255;
  333. break;
  334. case 0x08:
  335. r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
  336. g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
  337. b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
  338. a = 127;
  339. break;
  340. case 0x80:
  341. r = 127 + ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
  342. g = 127 + ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
  343. b = 127 + ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
  344. a = 255;
  345. break;
  346. case 0x88:
  347. r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
  348. g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
  349. b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
  350. a = 255;
  351. break;
  352. }
  353. }
  354. default_clut.clut256[i] = RGBA(r, g, b, a);
  355. }
  356. return 0;
  357. }
  358. static av_cold int dvbsub_close_decoder(AVCodecContext *avctx)
  359. {
  360. DVBSubContext *ctx = avctx->priv_data;
  361. DVBSubRegionDisplay *display;
  362. delete_regions(ctx);
  363. delete_objects(ctx);
  364. delete_cluts(ctx);
  365. av_freep(&ctx->display_definition);
  366. while (ctx->display_list) {
  367. display = ctx->display_list;
  368. ctx->display_list = display->next;
  369. av_free(display);
  370. }
  371. return 0;
  372. }
  373. static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
  374. const uint8_t **srcbuf, int buf_size,
  375. int non_mod, uint8_t *map_table, int x_pos)
  376. {
  377. GetBitContext gb;
  378. int bits;
  379. int run_length;
  380. int pixels_read = x_pos;
  381. init_get_bits(&gb, *srcbuf, buf_size << 3);
  382. destbuf += x_pos;
  383. while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
  384. bits = get_bits(&gb, 2);
  385. if (bits) {
  386. if (non_mod != 1 || bits != 1) {
  387. if (map_table)
  388. *destbuf++ = map_table[bits];
  389. else
  390. *destbuf++ = bits;
  391. }
  392. pixels_read++;
  393. } else {
  394. bits = get_bits1(&gb);
  395. if (bits == 1) {
  396. run_length = get_bits(&gb, 3) + 3;
  397. bits = get_bits(&gb, 2);
  398. if (non_mod == 1 && bits == 1)
  399. pixels_read += run_length;
  400. else {
  401. if (map_table)
  402. bits = map_table[bits];
  403. while (run_length-- > 0 && pixels_read < dbuf_len) {
  404. *destbuf++ = bits;
  405. pixels_read++;
  406. }
  407. }
  408. } else {
  409. bits = get_bits1(&gb);
  410. if (bits == 0) {
  411. bits = get_bits(&gb, 2);
  412. if (bits == 2) {
  413. run_length = get_bits(&gb, 4) + 12;
  414. bits = get_bits(&gb, 2);
  415. if (non_mod == 1 && bits == 1)
  416. pixels_read += run_length;
  417. else {
  418. if (map_table)
  419. bits = map_table[bits];
  420. while (run_length-- > 0 && pixels_read < dbuf_len) {
  421. *destbuf++ = bits;
  422. pixels_read++;
  423. }
  424. }
  425. } else if (bits == 3) {
  426. run_length = get_bits(&gb, 8) + 29;
  427. bits = get_bits(&gb, 2);
  428. if (non_mod == 1 && bits == 1)
  429. pixels_read += run_length;
  430. else {
  431. if (map_table)
  432. bits = map_table[bits];
  433. while (run_length-- > 0 && pixels_read < dbuf_len) {
  434. *destbuf++ = bits;
  435. pixels_read++;
  436. }
  437. }
  438. } else if (bits == 1) {
  439. if (map_table)
  440. bits = map_table[0];
  441. else
  442. bits = 0;
  443. run_length = 2;
  444. while (run_length-- > 0 && pixels_read < dbuf_len) {
  445. *destbuf++ = bits;
  446. pixels_read++;
  447. }
  448. } else {
  449. (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
  450. return pixels_read;
  451. }
  452. } else {
  453. if (map_table)
  454. bits = map_table[0];
  455. else
  456. bits = 0;
  457. *destbuf++ = bits;
  458. pixels_read++;
  459. }
  460. }
  461. }
  462. }
  463. if (get_bits(&gb, 6))
  464. av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
  465. (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
  466. return pixels_read;
  467. }
  468. static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
  469. const uint8_t **srcbuf, int buf_size,
  470. int non_mod, uint8_t *map_table, int x_pos)
  471. {
  472. GetBitContext gb;
  473. int bits;
  474. int run_length;
  475. int pixels_read = x_pos;
  476. init_get_bits(&gb, *srcbuf, buf_size << 3);
  477. destbuf += x_pos;
  478. while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
  479. bits = get_bits(&gb, 4);
  480. if (bits) {
  481. if (non_mod != 1 || bits != 1) {
  482. if (map_table)
  483. *destbuf++ = map_table[bits];
  484. else
  485. *destbuf++ = bits;
  486. }
  487. pixels_read++;
  488. } else {
  489. bits = get_bits1(&gb);
  490. if (bits == 0) {
  491. run_length = get_bits(&gb, 3);
  492. if (run_length == 0) {
  493. (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
  494. return pixels_read;
  495. }
  496. run_length += 2;
  497. if (map_table)
  498. bits = map_table[0];
  499. else
  500. bits = 0;
  501. while (run_length-- > 0 && pixels_read < dbuf_len) {
  502. *destbuf++ = bits;
  503. pixels_read++;
  504. }
  505. } else {
  506. bits = get_bits1(&gb);
  507. if (bits == 0) {
  508. run_length = get_bits(&gb, 2) + 4;
  509. bits = get_bits(&gb, 4);
  510. if (non_mod == 1 && bits == 1)
  511. pixels_read += run_length;
  512. else {
  513. if (map_table)
  514. bits = map_table[bits];
  515. while (run_length-- > 0 && pixels_read < dbuf_len) {
  516. *destbuf++ = bits;
  517. pixels_read++;
  518. }
  519. }
  520. } else {
  521. bits = get_bits(&gb, 2);
  522. if (bits == 2) {
  523. run_length = get_bits(&gb, 4) + 9;
  524. bits = get_bits(&gb, 4);
  525. if (non_mod == 1 && bits == 1)
  526. pixels_read += run_length;
  527. else {
  528. if (map_table)
  529. bits = map_table[bits];
  530. while (run_length-- > 0 && pixels_read < dbuf_len) {
  531. *destbuf++ = bits;
  532. pixels_read++;
  533. }
  534. }
  535. } else if (bits == 3) {
  536. run_length = get_bits(&gb, 8) + 25;
  537. bits = get_bits(&gb, 4);
  538. if (non_mod == 1 && bits == 1)
  539. pixels_read += run_length;
  540. else {
  541. if (map_table)
  542. bits = map_table[bits];
  543. while (run_length-- > 0 && pixels_read < dbuf_len) {
  544. *destbuf++ = bits;
  545. pixels_read++;
  546. }
  547. }
  548. } else if (bits == 1) {
  549. if (map_table)
  550. bits = map_table[0];
  551. else
  552. bits = 0;
  553. run_length = 2;
  554. while (run_length-- > 0 && pixels_read < dbuf_len) {
  555. *destbuf++ = bits;
  556. pixels_read++;
  557. }
  558. } else {
  559. if (map_table)
  560. bits = map_table[0];
  561. else
  562. bits = 0;
  563. *destbuf++ = bits;
  564. pixels_read ++;
  565. }
  566. }
  567. }
  568. }
  569. }
  570. if (get_bits(&gb, 8))
  571. av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
  572. (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
  573. return pixels_read;
  574. }
  575. static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len,
  576. const uint8_t **srcbuf, int buf_size,
  577. int non_mod, uint8_t *map_table, int x_pos)
  578. {
  579. const uint8_t *sbuf_end = (*srcbuf) + buf_size;
  580. int bits;
  581. int run_length;
  582. int pixels_read = x_pos;
  583. destbuf += x_pos;
  584. while (*srcbuf < sbuf_end && pixels_read < dbuf_len) {
  585. bits = *(*srcbuf)++;
  586. if (bits) {
  587. if (non_mod != 1 || bits != 1) {
  588. if (map_table)
  589. *destbuf++ = map_table[bits];
  590. else
  591. *destbuf++ = bits;
  592. }
  593. pixels_read++;
  594. } else {
  595. bits = *(*srcbuf)++;
  596. run_length = bits & 0x7f;
  597. if ((bits & 0x80) == 0) {
  598. if (run_length == 0) {
  599. return pixels_read;
  600. }
  601. if (map_table)
  602. bits = map_table[0];
  603. else
  604. bits = 0;
  605. while (run_length-- > 0 && pixels_read < dbuf_len) {
  606. *destbuf++ = bits;
  607. pixels_read++;
  608. }
  609. } else {
  610. bits = *(*srcbuf)++;
  611. if (non_mod == 1 && bits == 1)
  612. pixels_read += run_length;
  613. if (map_table)
  614. bits = map_table[bits];
  615. else while (run_length-- > 0 && pixels_read < dbuf_len) {
  616. *destbuf++ = bits;
  617. pixels_read++;
  618. }
  619. }
  620. }
  621. }
  622. if (*(*srcbuf)++)
  623. av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
  624. return pixels_read;
  625. }
  626. static void save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub)
  627. {
  628. DVBSubContext *ctx = avctx->priv_data;
  629. DVBSubRegionDisplay *display;
  630. DVBSubDisplayDefinition *display_def = ctx->display_definition;
  631. DVBSubRegion *region;
  632. AVSubtitleRect *rect;
  633. DVBSubCLUT *clut;
  634. uint32_t *clut_table;
  635. int i;
  636. int offset_x=0, offset_y=0;
  637. sub->end_display_time = ctx->time_out * 1000;
  638. if (display_def) {
  639. offset_x = display_def->x;
  640. offset_y = display_def->y;
  641. }
  642. sub->num_rects = 0;
  643. for (display = ctx->display_list; display; display = display->next) {
  644. region = get_region(ctx, display->region_id);
  645. if (region && region->dirty)
  646. sub->num_rects++;
  647. }
  648. if (sub->num_rects > 0) {
  649. sub->rects = av_mallocz_array(sizeof(*sub->rects), sub->num_rects);
  650. for(i=0; i<sub->num_rects; i++)
  651. sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
  652. i = 0;
  653. for (display = ctx->display_list; display; display = display->next) {
  654. region = get_region(ctx, display->region_id);
  655. if (!region)
  656. continue;
  657. if (!region->dirty)
  658. continue;
  659. rect = sub->rects[i];
  660. rect->x = display->x_pos + offset_x;
  661. rect->y = display->y_pos + offset_y;
  662. rect->w = region->width;
  663. rect->h = region->height;
  664. rect->nb_colors = (1 << region->depth);
  665. rect->type = SUBTITLE_BITMAP;
  666. rect->pict.linesize[0] = region->width;
  667. clut = get_clut(ctx, region->clut);
  668. if (!clut)
  669. clut = &default_clut;
  670. switch (region->depth) {
  671. case 2:
  672. clut_table = clut->clut4;
  673. break;
  674. case 8:
  675. clut_table = clut->clut256;
  676. break;
  677. case 4:
  678. default:
  679. clut_table = clut->clut16;
  680. break;
  681. }
  682. rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
  683. memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
  684. rect->pict.data[0] = av_malloc(region->buf_size);
  685. memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
  686. i++;
  687. }
  688. }
  689. }
  690. static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,
  691. const uint8_t *buf, int buf_size, int top_bottom, int non_mod)
  692. {
  693. DVBSubContext *ctx = avctx->priv_data;
  694. DVBSubRegion *region = get_region(ctx, display->region_id);
  695. const uint8_t *buf_end = buf + buf_size;
  696. uint8_t *pbuf;
  697. int x_pos, y_pos;
  698. int i;
  699. uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf};
  700. uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};
  701. uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  702. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
  703. uint8_t *map_table;
  704. #if 0
  705. av_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size,
  706. top_bottom ? "bottom" : "top");
  707. for (i = 0; i < buf_size; i++) {
  708. if (i % 16 == 0)
  709. av_dlog(avctx, "0x%8p: ", buf+i);
  710. av_dlog(avctx, "%02x ", buf[i]);
  711. if (i % 16 == 15)
  712. av_dlog(avctx, "\n");
  713. }
  714. if (i % 16)
  715. av_dlog(avctx, "\n");
  716. #endif
  717. if (region == 0)
  718. return;
  719. pbuf = region->pbuf;
  720. region->dirty = 1;
  721. x_pos = display->x_pos;
  722. y_pos = display->y_pos;
  723. y_pos += top_bottom;
  724. while (buf < buf_end) {
  725. if ((*buf!=0xf0 && x_pos >= region->width) || y_pos >= region->height) {
  726. av_log(avctx, AV_LOG_ERROR, "Invalid object location! %d-%d %d-%d %02x\n", x_pos, region->width, y_pos, region->height, *buf);
  727. return;
  728. }
  729. switch (*buf++) {
  730. case 0x10:
  731. if (region->depth == 8)
  732. map_table = map2to8;
  733. else if (region->depth == 4)
  734. map_table = map2to4;
  735. else
  736. map_table = NULL;
  737. x_pos = dvbsub_read_2bit_string(pbuf + (y_pos * region->width),
  738. region->width, &buf, buf_end - buf,
  739. non_mod, map_table, x_pos);
  740. break;
  741. case 0x11:
  742. if (region->depth < 4) {
  743. av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);
  744. return;
  745. }
  746. if (region->depth == 8)
  747. map_table = map4to8;
  748. else
  749. map_table = NULL;
  750. x_pos = dvbsub_read_4bit_string(pbuf + (y_pos * region->width),
  751. region->width, &buf, buf_end - buf,
  752. non_mod, map_table, x_pos);
  753. break;
  754. case 0x12:
  755. if (region->depth < 8) {
  756. av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);
  757. return;
  758. }
  759. x_pos = dvbsub_read_8bit_string(pbuf + (y_pos * region->width),
  760. region->width, &buf, buf_end - buf,
  761. non_mod, NULL, x_pos);
  762. break;
  763. case 0x20:
  764. map2to4[0] = (*buf) >> 4;
  765. map2to4[1] = (*buf++) & 0xf;
  766. map2to4[2] = (*buf) >> 4;
  767. map2to4[3] = (*buf++) & 0xf;
  768. break;
  769. case 0x21:
  770. for (i = 0; i < 4; i++)
  771. map2to8[i] = *buf++;
  772. break;
  773. case 0x22:
  774. for (i = 0; i < 16; i++)
  775. map4to8[i] = *buf++;
  776. break;
  777. case 0xf0:
  778. x_pos = display->x_pos;
  779. y_pos += 2;
  780. break;
  781. default:
  782. av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1));
  783. }
  784. }
  785. }
  786. static void dvbsub_parse_object_segment(AVCodecContext *avctx,
  787. const uint8_t *buf, int buf_size)
  788. {
  789. DVBSubContext *ctx = avctx->priv_data;
  790. const uint8_t *buf_end = buf + buf_size;
  791. int object_id;
  792. DVBSubObject *object;
  793. DVBSubObjectDisplay *display;
  794. int top_field_len, bottom_field_len;
  795. int coding_method, non_modifying_color;
  796. object_id = AV_RB16(buf);
  797. buf += 2;
  798. object = get_object(ctx, object_id);
  799. if (!object)
  800. return;
  801. coding_method = ((*buf) >> 2) & 3;
  802. non_modifying_color = ((*buf++) >> 1) & 1;
  803. if (coding_method == 0) {
  804. top_field_len = AV_RB16(buf);
  805. buf += 2;
  806. bottom_field_len = AV_RB16(buf);
  807. buf += 2;
  808. if (buf + top_field_len + bottom_field_len > buf_end) {
  809. av_log(avctx, AV_LOG_ERROR, "Field data size too large\n");
  810. return;
  811. }
  812. for (display = object->display_list; display; display = display->object_list_next) {
  813. const uint8_t *block = buf;
  814. int bfl = bottom_field_len;
  815. dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0,
  816. non_modifying_color);
  817. if (bottom_field_len > 0)
  818. block = buf + top_field_len;
  819. else
  820. bfl = top_field_len;
  821. dvbsub_parse_pixel_data_block(avctx, display, block, bfl, 1,
  822. non_modifying_color);
  823. }
  824. /* } else if (coding_method == 1) {*/
  825. } else {
  826. av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method);
  827. }
  828. }
  829. static int dvbsub_parse_clut_segment(AVCodecContext *avctx,
  830. const uint8_t *buf, int buf_size)
  831. {
  832. DVBSubContext *ctx = avctx->priv_data;
  833. const uint8_t *buf_end = buf + buf_size;
  834. int i, clut_id;
  835. int version;
  836. DVBSubCLUT *clut;
  837. int entry_id, depth , full_range;
  838. int y, cr, cb, alpha;
  839. int r, g, b, r_add, g_add, b_add;
  840. av_dlog(avctx, "DVB clut packet:\n");
  841. for (i=0; i < buf_size; i++) {
  842. av_dlog(avctx, "%02x ", buf[i]);
  843. if (i % 16 == 15)
  844. av_dlog(avctx, "\n");
  845. }
  846. if (i % 16)
  847. av_dlog(avctx, "\n");
  848. clut_id = *buf++;
  849. version = ((*buf)>>4)&15;
  850. buf += 1;
  851. clut = get_clut(ctx, clut_id);
  852. if (!clut) {
  853. clut = av_malloc(sizeof(DVBSubCLUT));
  854. memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
  855. clut->id = clut_id;
  856. clut->version = -1;
  857. clut->next = ctx->clut_list;
  858. ctx->clut_list = clut;
  859. }
  860. if (clut->version != version) {
  861. clut->version = version;
  862. while (buf + 4 < buf_end) {
  863. entry_id = *buf++;
  864. depth = (*buf) & 0xe0;
  865. if (depth == 0) {
  866. av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
  867. return 0;
  868. }
  869. full_range = (*buf++) & 1;
  870. if (full_range) {
  871. y = *buf++;
  872. cr = *buf++;
  873. cb = *buf++;
  874. alpha = *buf++;
  875. } else {
  876. y = buf[0] & 0xfc;
  877. cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
  878. cb = (buf[1] << 2) & 0xf0;
  879. alpha = (buf[1] << 6) & 0xc0;
  880. buf += 2;
  881. }
  882. if (y == 0)
  883. alpha = 0xff;
  884. YUV_TO_RGB1_CCIR(cb, cr);
  885. YUV_TO_RGB2_CCIR(r, g, b, y);
  886. av_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
  887. if (!!(depth & 0x80) + !!(depth & 0x40) + !!(depth & 0x20) > 1) {
  888. av_dlog(avctx, "More than one bit level marked: %x\n", depth);
  889. if (avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL)
  890. return AVERROR_INVALIDDATA;
  891. }
  892. if (depth & 0x80)
  893. clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
  894. else if (depth & 0x40)
  895. clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
  896. else if (depth & 0x20)
  897. clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
  898. }
  899. }
  900. return 0;
  901. }
  902. static void dvbsub_parse_region_segment(AVCodecContext *avctx,
  903. const uint8_t *buf, int buf_size)
  904. {
  905. DVBSubContext *ctx = avctx->priv_data;
  906. const uint8_t *buf_end = buf + buf_size;
  907. int region_id, object_id;
  908. int av_unused version;
  909. DVBSubRegion *region;
  910. DVBSubObject *object;
  911. DVBSubObjectDisplay *display;
  912. int fill;
  913. if (buf_size < 10)
  914. return;
  915. region_id = *buf++;
  916. region = get_region(ctx, region_id);
  917. if (!region) {
  918. region = av_mallocz(sizeof(DVBSubRegion));
  919. region->id = region_id;
  920. region->version = -1;
  921. region->next = ctx->region_list;
  922. ctx->region_list = region;
  923. }
  924. version = ((*buf)>>4) & 15;
  925. fill = ((*buf++) >> 3) & 1;
  926. region->width = AV_RB16(buf);
  927. buf += 2;
  928. region->height = AV_RB16(buf);
  929. buf += 2;
  930. if (region->width * region->height != region->buf_size) {
  931. av_free(region->pbuf);
  932. region->buf_size = region->width * region->height;
  933. region->pbuf = av_malloc(region->buf_size);
  934. fill = 1;
  935. region->dirty = 0;
  936. }
  937. region->depth = 1 << (((*buf++) >> 2) & 7);
  938. if(region->depth<2 || region->depth>8){
  939. av_log(avctx, AV_LOG_ERROR, "region depth %d is invalid\n", region->depth);
  940. region->depth= 4;
  941. }
  942. region->clut = *buf++;
  943. if (region->depth == 8) {
  944. region->bgcolor = *buf++;
  945. buf += 1;
  946. } else {
  947. buf += 1;
  948. if (region->depth == 4)
  949. region->bgcolor = (((*buf++) >> 4) & 15);
  950. else
  951. region->bgcolor = (((*buf++) >> 2) & 3);
  952. }
  953. av_dlog(avctx, "Region %d, (%dx%d)\n", region_id, region->width, region->height);
  954. if (fill) {
  955. memset(region->pbuf, region->bgcolor, region->buf_size);
  956. av_dlog(avctx, "Fill region (%d)\n", region->bgcolor);
  957. }
  958. delete_region_display_list(ctx, region);
  959. while (buf + 5 < buf_end) {
  960. object_id = AV_RB16(buf);
  961. buf += 2;
  962. object = get_object(ctx, object_id);
  963. if (!object) {
  964. object = av_mallocz(sizeof(DVBSubObject));
  965. object->id = object_id;
  966. object->next = ctx->object_list;
  967. ctx->object_list = object;
  968. }
  969. object->type = (*buf) >> 6;
  970. display = av_mallocz(sizeof(DVBSubObjectDisplay));
  971. display->object_id = object_id;
  972. display->region_id = region_id;
  973. display->x_pos = AV_RB16(buf) & 0xfff;
  974. buf += 2;
  975. display->y_pos = AV_RB16(buf) & 0xfff;
  976. buf += 2;
  977. if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) {
  978. display->fgcolor = *buf++;
  979. display->bgcolor = *buf++;
  980. }
  981. display->region_list_next = region->display_list;
  982. region->display_list = display;
  983. display->object_list_next = object->display_list;
  984. object->display_list = display;
  985. }
  986. }
  987. static void dvbsub_parse_page_segment(AVCodecContext *avctx,
  988. const uint8_t *buf, int buf_size, AVSubtitle *sub)
  989. {
  990. DVBSubContext *ctx = avctx->priv_data;
  991. DVBSubRegionDisplay *display;
  992. DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
  993. const uint8_t *buf_end = buf + buf_size;
  994. int region_id;
  995. int page_state;
  996. int timeout;
  997. int version;
  998. if (buf_size < 1)
  999. return;
  1000. timeout = *buf++;
  1001. version = ((*buf)>>4) & 15;
  1002. page_state = ((*buf++) >> 2) & 3;
  1003. if (ctx->version == version) {
  1004. return;
  1005. }
  1006. ctx->time_out = timeout;
  1007. ctx->version = version;
  1008. av_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
  1009. if (page_state == 1 || page_state == 2) {
  1010. delete_regions(ctx);
  1011. delete_objects(ctx);
  1012. delete_cluts(ctx);
  1013. }
  1014. tmp_display_list = ctx->display_list;
  1015. ctx->display_list = NULL;
  1016. while (buf + 5 < buf_end) {
  1017. region_id = *buf++;
  1018. buf += 1;
  1019. display = tmp_display_list;
  1020. tmp_ptr = &tmp_display_list;
  1021. while (display && display->region_id != region_id) {
  1022. tmp_ptr = &display->next;
  1023. display = display->next;
  1024. }
  1025. if (!display)
  1026. display = av_mallocz(sizeof(DVBSubRegionDisplay));
  1027. display->region_id = region_id;
  1028. display->x_pos = AV_RB16(buf);
  1029. buf += 2;
  1030. display->y_pos = AV_RB16(buf);
  1031. buf += 2;
  1032. *tmp_ptr = display->next;
  1033. display->next = ctx->display_list;
  1034. ctx->display_list = display;
  1035. av_dlog(avctx, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos);
  1036. }
  1037. while (tmp_display_list) {
  1038. display = tmp_display_list;
  1039. tmp_display_list = display->next;
  1040. av_free(display);
  1041. }
  1042. }
  1043. #ifdef DEBUG
  1044. static void save_display_set(DVBSubContext *ctx)
  1045. {
  1046. DVBSubRegion *region;
  1047. DVBSubRegionDisplay *display;
  1048. DVBSubCLUT *clut;
  1049. uint32_t *clut_table;
  1050. int x_pos, y_pos, width, height;
  1051. int x, y, y_off, x_off;
  1052. uint32_t *pbuf;
  1053. char filename[32];
  1054. static int fileno_index = 0;
  1055. x_pos = -1;
  1056. y_pos = -1;
  1057. width = 0;
  1058. height = 0;
  1059. for (display = ctx->display_list; display; display = display->next) {
  1060. region = get_region(ctx, display->region_id);
  1061. if (x_pos == -1) {
  1062. x_pos = display->x_pos;
  1063. y_pos = display->y_pos;
  1064. width = region->width;
  1065. height = region->height;
  1066. } else {
  1067. if (display->x_pos < x_pos) {
  1068. width += (x_pos - display->x_pos);
  1069. x_pos = display->x_pos;
  1070. }
  1071. if (display->y_pos < y_pos) {
  1072. height += (y_pos - display->y_pos);
  1073. y_pos = display->y_pos;
  1074. }
  1075. if (display->x_pos + region->width > x_pos + width) {
  1076. width = display->x_pos + region->width - x_pos;
  1077. }
  1078. if (display->y_pos + region->height > y_pos + height) {
  1079. height = display->y_pos + region->height - y_pos;
  1080. }
  1081. }
  1082. }
  1083. if (x_pos >= 0) {
  1084. pbuf = av_malloc(width * height * 4);
  1085. for (display = ctx->display_list; display; display = display->next) {
  1086. region = get_region(ctx, display->region_id);
  1087. x_off = display->x_pos - x_pos;
  1088. y_off = display->y_pos - y_pos;
  1089. clut = get_clut(ctx, region->clut);
  1090. if (clut == 0)
  1091. clut = &default_clut;
  1092. switch (region->depth) {
  1093. case 2:
  1094. clut_table = clut->clut4;
  1095. break;
  1096. case 8:
  1097. clut_table = clut->clut256;
  1098. break;
  1099. case 4:
  1100. default:
  1101. clut_table = clut->clut16;
  1102. break;
  1103. }
  1104. for (y = 0; y < region->height; y++) {
  1105. for (x = 0; x < region->width; x++) {
  1106. pbuf[((y + y_off) * width) + x_off + x] =
  1107. clut_table[region->pbuf[y * region->width + x]];
  1108. }
  1109. }
  1110. }
  1111. snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index);
  1112. png_save2(filename, pbuf, width, height);
  1113. av_free(pbuf);
  1114. }
  1115. fileno_index++;
  1116. }
  1117. #endif
  1118. static void dvbsub_parse_display_definition_segment(AVCodecContext *avctx,
  1119. const uint8_t *buf,
  1120. int buf_size)
  1121. {
  1122. DVBSubContext *ctx = avctx->priv_data;
  1123. DVBSubDisplayDefinition *display_def = ctx->display_definition;
  1124. int dds_version, info_byte;
  1125. if (buf_size < 5)
  1126. return;
  1127. info_byte = bytestream_get_byte(&buf);
  1128. dds_version = info_byte >> 4;
  1129. if (display_def && display_def->version == dds_version)
  1130. return; // already have this display definition version
  1131. if (!display_def) {
  1132. display_def = av_mallocz(sizeof(*display_def));
  1133. ctx->display_definition = display_def;
  1134. }
  1135. if (!display_def)
  1136. return;
  1137. display_def->version = dds_version;
  1138. display_def->x = 0;
  1139. display_def->y = 0;
  1140. display_def->width = bytestream_get_be16(&buf) + 1;
  1141. display_def->height = bytestream_get_be16(&buf) + 1;
  1142. if (!avctx->width || !avctx->height) {
  1143. avctx->width = display_def->width;
  1144. avctx->height = display_def->height;
  1145. }
  1146. if (buf_size < 13)
  1147. return;
  1148. if (info_byte & 1<<3) { // display_window_flag
  1149. display_def->x = bytestream_get_be16(&buf);
  1150. display_def->width = bytestream_get_be16(&buf) - display_def->x + 1;
  1151. display_def->y = bytestream_get_be16(&buf);
  1152. display_def->height = bytestream_get_be16(&buf) - display_def->y + 1;
  1153. }
  1154. }
  1155. static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
  1156. int buf_size, AVSubtitle *sub)
  1157. {
  1158. DVBSubContext *ctx = avctx->priv_data;
  1159. save_subtitle_set(avctx,sub);
  1160. #ifdef DEBUG
  1161. save_display_set(ctx);
  1162. #endif
  1163. return 1;
  1164. }
  1165. static int dvbsub_decode(AVCodecContext *avctx,
  1166. void *data, int *data_size,
  1167. AVPacket *avpkt)
  1168. {
  1169. const uint8_t *buf = avpkt->data;
  1170. int buf_size = avpkt->size;
  1171. DVBSubContext *ctx = avctx->priv_data;
  1172. AVSubtitle *sub = data;
  1173. const uint8_t *p, *p_end;
  1174. int segment_type;
  1175. int page_id;
  1176. int segment_length;
  1177. int i;
  1178. int ret;
  1179. int got_segment = 0;
  1180. av_dlog(avctx, "DVB sub packet:\n");
  1181. for (i=0; i < buf_size; i++) {
  1182. av_dlog(avctx, "%02x ", buf[i]);
  1183. if (i % 16 == 15)
  1184. av_dlog(avctx, "\n");
  1185. }
  1186. if (i % 16)
  1187. av_dlog(avctx, "\n");
  1188. if (buf_size <= 6 || *buf != 0x0f) {
  1189. av_dlog(avctx, "incomplete or broken packet");
  1190. return -1;
  1191. }
  1192. p = buf;
  1193. p_end = buf + buf_size;
  1194. while (p_end - p >= 6 && *p == 0x0f) {
  1195. p += 1;
  1196. segment_type = *p++;
  1197. page_id = AV_RB16(p);
  1198. p += 2;
  1199. segment_length = AV_RB16(p);
  1200. p += 2;
  1201. if (avctx->debug & FF_DEBUG_STARTCODE) {
  1202. av_log(avctx, AV_LOG_DEBUG, "segment_type:%d page_id:%d segment_length:%d\n", segment_type, page_id, segment_length);
  1203. }
  1204. if (p_end - p < segment_length) {
  1205. av_dlog(avctx, "incomplete or broken packet");
  1206. return -1;
  1207. }
  1208. if (page_id == ctx->composition_id || page_id == ctx->ancillary_id ||
  1209. ctx->composition_id == -1 || ctx->ancillary_id == -1) {
  1210. switch (segment_type) {
  1211. case DVBSUB_PAGE_SEGMENT:
  1212. dvbsub_parse_page_segment(avctx, p, segment_length, sub);
  1213. got_segment |= 1;
  1214. break;
  1215. case DVBSUB_REGION_SEGMENT:
  1216. dvbsub_parse_region_segment(avctx, p, segment_length);
  1217. got_segment |= 2;
  1218. break;
  1219. case DVBSUB_CLUT_SEGMENT:
  1220. ret = dvbsub_parse_clut_segment(avctx, p, segment_length);
  1221. if (ret < 0) return ret;
  1222. got_segment |= 4;
  1223. break;
  1224. case DVBSUB_OBJECT_SEGMENT:
  1225. dvbsub_parse_object_segment(avctx, p, segment_length);
  1226. got_segment |= 8;
  1227. break;
  1228. case DVBSUB_DISPLAYDEFINITION_SEGMENT:
  1229. dvbsub_parse_display_definition_segment(avctx, p, segment_length);
  1230. break;
  1231. case DVBSUB_DISPLAY_SEGMENT:
  1232. *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub);
  1233. got_segment |= 16;
  1234. break;
  1235. default:
  1236. av_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n",
  1237. segment_type, page_id, segment_length);
  1238. break;
  1239. }
  1240. }
  1241. p += segment_length;
  1242. }
  1243. // Some streams do not send a display segment but if we have all the other
  1244. // segments then we need no further data.
  1245. if (got_segment == 15 && sub) {
  1246. av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, emulating\n");
  1247. *data_size = dvbsub_display_end_segment(avctx, p, 0, sub);
  1248. }
  1249. return p - buf;
  1250. }
  1251. static const AVOption options[] = {
  1252. {NULL}
  1253. };
  1254. static const AVClass dvbsubdec_class = {
  1255. .class_name = "DVB Sub Decoder",
  1256. .item_name = av_default_item_name,
  1257. .option = options,
  1258. .version = LIBAVUTIL_VERSION_INT,
  1259. };
  1260. AVCodec ff_dvbsub_decoder = {
  1261. .name = "dvbsub",
  1262. .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"),
  1263. .type = AVMEDIA_TYPE_SUBTITLE,
  1264. .id = AV_CODEC_ID_DVB_SUBTITLE,
  1265. .priv_data_size = sizeof(DVBSubContext),
  1266. .init = dvbsub_init_decoder,
  1267. .close = dvbsub_close_decoder,
  1268. .decode = dvbsub_decode,
  1269. .priv_class = &dvbsubdec_class,
  1270. };