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.

1577 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 dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,
  627. const uint8_t *buf, int buf_size, int top_bottom, int non_mod)
  628. {
  629. DVBSubContext *ctx = avctx->priv_data;
  630. DVBSubRegion *region = get_region(ctx, display->region_id);
  631. const uint8_t *buf_end = buf + buf_size;
  632. uint8_t *pbuf;
  633. int x_pos, y_pos;
  634. int i;
  635. uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf};
  636. uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};
  637. uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  638. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
  639. uint8_t *map_table;
  640. #if 0
  641. av_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size,
  642. top_bottom ? "bottom" : "top");
  643. for (i = 0; i < buf_size; i++) {
  644. if (i % 16 == 0)
  645. av_dlog(avctx, "0x%8p: ", buf+i);
  646. av_dlog(avctx, "%02x ", buf[i]);
  647. if (i % 16 == 15)
  648. av_dlog(avctx, "\n");
  649. }
  650. if (i % 16)
  651. av_dlog(avctx, "\n");
  652. #endif
  653. if (region == 0)
  654. return;
  655. pbuf = region->pbuf;
  656. region->dirty = 1;
  657. x_pos = display->x_pos;
  658. y_pos = display->y_pos;
  659. y_pos += top_bottom;
  660. while (buf < buf_end) {
  661. if ((*buf!=0xf0 && x_pos >= region->width) || y_pos >= region->height) {
  662. av_log(avctx, AV_LOG_ERROR, "Invalid object location! %d-%d %d-%d %02x\n", x_pos, region->width, y_pos, region->height, *buf);
  663. return;
  664. }
  665. switch (*buf++) {
  666. case 0x10:
  667. if (region->depth == 8)
  668. map_table = map2to8;
  669. else if (region->depth == 4)
  670. map_table = map2to4;
  671. else
  672. map_table = NULL;
  673. x_pos = dvbsub_read_2bit_string(pbuf + (y_pos * region->width),
  674. region->width, &buf, buf_end - buf,
  675. non_mod, map_table, x_pos);
  676. break;
  677. case 0x11:
  678. if (region->depth < 4) {
  679. av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);
  680. return;
  681. }
  682. if (region->depth == 8)
  683. map_table = map4to8;
  684. else
  685. map_table = NULL;
  686. x_pos = dvbsub_read_4bit_string(pbuf + (y_pos * region->width),
  687. region->width, &buf, buf_end - buf,
  688. non_mod, map_table, x_pos);
  689. break;
  690. case 0x12:
  691. if (region->depth < 8) {
  692. av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);
  693. return;
  694. }
  695. x_pos = dvbsub_read_8bit_string(pbuf + (y_pos * region->width),
  696. region->width, &buf, buf_end - buf,
  697. non_mod, NULL, x_pos);
  698. break;
  699. case 0x20:
  700. map2to4[0] = (*buf) >> 4;
  701. map2to4[1] = (*buf++) & 0xf;
  702. map2to4[2] = (*buf) >> 4;
  703. map2to4[3] = (*buf++) & 0xf;
  704. break;
  705. case 0x21:
  706. for (i = 0; i < 4; i++)
  707. map2to8[i] = *buf++;
  708. break;
  709. case 0x22:
  710. for (i = 0; i < 16; i++)
  711. map4to8[i] = *buf++;
  712. break;
  713. case 0xf0:
  714. x_pos = display->x_pos;
  715. y_pos += 2;
  716. break;
  717. default:
  718. av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1));
  719. }
  720. }
  721. }
  722. static void dvbsub_parse_object_segment(AVCodecContext *avctx,
  723. const uint8_t *buf, int buf_size)
  724. {
  725. DVBSubContext *ctx = avctx->priv_data;
  726. const uint8_t *buf_end = buf + buf_size;
  727. int object_id;
  728. DVBSubObject *object;
  729. DVBSubObjectDisplay *display;
  730. int top_field_len, bottom_field_len;
  731. int coding_method, non_modifying_color;
  732. object_id = AV_RB16(buf);
  733. buf += 2;
  734. object = get_object(ctx, object_id);
  735. if (!object)
  736. return;
  737. coding_method = ((*buf) >> 2) & 3;
  738. non_modifying_color = ((*buf++) >> 1) & 1;
  739. if (coding_method == 0) {
  740. top_field_len = AV_RB16(buf);
  741. buf += 2;
  742. bottom_field_len = AV_RB16(buf);
  743. buf += 2;
  744. if (buf + top_field_len + bottom_field_len > buf_end) {
  745. av_log(avctx, AV_LOG_ERROR, "Field data size too large\n");
  746. return;
  747. }
  748. for (display = object->display_list; display; display = display->object_list_next) {
  749. const uint8_t *block = buf;
  750. int bfl = bottom_field_len;
  751. dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0,
  752. non_modifying_color);
  753. if (bottom_field_len > 0)
  754. block = buf + top_field_len;
  755. else
  756. bfl = top_field_len;
  757. dvbsub_parse_pixel_data_block(avctx, display, block, bfl, 1,
  758. non_modifying_color);
  759. }
  760. /* } else if (coding_method == 1) {*/
  761. } else {
  762. av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method);
  763. }
  764. }
  765. static int dvbsub_parse_clut_segment(AVCodecContext *avctx,
  766. const uint8_t *buf, int buf_size)
  767. {
  768. DVBSubContext *ctx = avctx->priv_data;
  769. const uint8_t *buf_end = buf + buf_size;
  770. int i, clut_id;
  771. int version;
  772. DVBSubCLUT *clut;
  773. int entry_id, depth , full_range;
  774. int y, cr, cb, alpha;
  775. int r, g, b, r_add, g_add, b_add;
  776. av_dlog(avctx, "DVB clut packet:\n");
  777. for (i=0; i < buf_size; i++) {
  778. av_dlog(avctx, "%02x ", buf[i]);
  779. if (i % 16 == 15)
  780. av_dlog(avctx, "\n");
  781. }
  782. if (i % 16)
  783. av_dlog(avctx, "\n");
  784. clut_id = *buf++;
  785. version = ((*buf)>>4)&15;
  786. buf += 1;
  787. clut = get_clut(ctx, clut_id);
  788. if (!clut) {
  789. clut = av_malloc(sizeof(DVBSubCLUT));
  790. memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
  791. clut->id = clut_id;
  792. clut->version = -1;
  793. clut->next = ctx->clut_list;
  794. ctx->clut_list = clut;
  795. }
  796. if (clut->version != version) {
  797. clut->version = version;
  798. while (buf + 4 < buf_end) {
  799. entry_id = *buf++;
  800. depth = (*buf) & 0xe0;
  801. if (depth == 0) {
  802. av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
  803. return 0;
  804. }
  805. full_range = (*buf++) & 1;
  806. if (full_range) {
  807. y = *buf++;
  808. cr = *buf++;
  809. cb = *buf++;
  810. alpha = *buf++;
  811. } else {
  812. y = buf[0] & 0xfc;
  813. cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
  814. cb = (buf[1] << 2) & 0xf0;
  815. alpha = (buf[1] << 6) & 0xc0;
  816. buf += 2;
  817. }
  818. if (y == 0)
  819. alpha = 0xff;
  820. YUV_TO_RGB1_CCIR(cb, cr);
  821. YUV_TO_RGB2_CCIR(r, g, b, y);
  822. av_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
  823. if (!!(depth & 0x80) + !!(depth & 0x40) + !!(depth & 0x20) > 1) {
  824. av_dlog(avctx, "More than one bit level marked: %x\n", depth);
  825. if (avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL)
  826. return AVERROR_INVALIDDATA;
  827. }
  828. if (depth & 0x80)
  829. clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
  830. else if (depth & 0x40)
  831. clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
  832. else if (depth & 0x20)
  833. clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
  834. }
  835. }
  836. return 0;
  837. }
  838. static void dvbsub_parse_region_segment(AVCodecContext *avctx,
  839. const uint8_t *buf, int buf_size)
  840. {
  841. DVBSubContext *ctx = avctx->priv_data;
  842. const uint8_t *buf_end = buf + buf_size;
  843. int region_id, object_id;
  844. int av_unused version;
  845. DVBSubRegion *region;
  846. DVBSubObject *object;
  847. DVBSubObjectDisplay *display;
  848. int fill;
  849. if (buf_size < 10)
  850. return;
  851. region_id = *buf++;
  852. region = get_region(ctx, region_id);
  853. if (!region) {
  854. region = av_mallocz(sizeof(DVBSubRegion));
  855. region->id = region_id;
  856. region->version = -1;
  857. region->next = ctx->region_list;
  858. ctx->region_list = region;
  859. }
  860. version = ((*buf)>>4) & 15;
  861. fill = ((*buf++) >> 3) & 1;
  862. region->width = AV_RB16(buf);
  863. buf += 2;
  864. region->height = AV_RB16(buf);
  865. buf += 2;
  866. if (region->width * region->height != region->buf_size) {
  867. av_free(region->pbuf);
  868. region->buf_size = region->width * region->height;
  869. region->pbuf = av_malloc(region->buf_size);
  870. fill = 1;
  871. region->dirty = 0;
  872. }
  873. region->depth = 1 << (((*buf++) >> 2) & 7);
  874. if(region->depth<2 || region->depth>8){
  875. av_log(avctx, AV_LOG_ERROR, "region depth %d is invalid\n", region->depth);
  876. region->depth= 4;
  877. }
  878. region->clut = *buf++;
  879. if (region->depth == 8) {
  880. region->bgcolor = *buf++;
  881. buf += 1;
  882. } else {
  883. buf += 1;
  884. if (region->depth == 4)
  885. region->bgcolor = (((*buf++) >> 4) & 15);
  886. else
  887. region->bgcolor = (((*buf++) >> 2) & 3);
  888. }
  889. av_dlog(avctx, "Region %d, (%dx%d)\n", region_id, region->width, region->height);
  890. if (fill) {
  891. memset(region->pbuf, region->bgcolor, region->buf_size);
  892. av_dlog(avctx, "Fill region (%d)\n", region->bgcolor);
  893. }
  894. delete_region_display_list(ctx, region);
  895. while (buf + 5 < buf_end) {
  896. object_id = AV_RB16(buf);
  897. buf += 2;
  898. object = get_object(ctx, object_id);
  899. if (!object) {
  900. object = av_mallocz(sizeof(DVBSubObject));
  901. object->id = object_id;
  902. object->next = ctx->object_list;
  903. ctx->object_list = object;
  904. }
  905. object->type = (*buf) >> 6;
  906. display = av_mallocz(sizeof(DVBSubObjectDisplay));
  907. display->object_id = object_id;
  908. display->region_id = region_id;
  909. display->x_pos = AV_RB16(buf) & 0xfff;
  910. buf += 2;
  911. display->y_pos = AV_RB16(buf) & 0xfff;
  912. buf += 2;
  913. if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) {
  914. display->fgcolor = *buf++;
  915. display->bgcolor = *buf++;
  916. }
  917. display->region_list_next = region->display_list;
  918. region->display_list = display;
  919. display->object_list_next = object->display_list;
  920. object->display_list = display;
  921. }
  922. }
  923. static void dvbsub_parse_page_segment(AVCodecContext *avctx,
  924. const uint8_t *buf, int buf_size)
  925. {
  926. DVBSubContext *ctx = avctx->priv_data;
  927. DVBSubRegionDisplay *display;
  928. DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
  929. const uint8_t *buf_end = buf + buf_size;
  930. int region_id;
  931. int page_state;
  932. int timeout;
  933. int version;
  934. if (buf_size < 1)
  935. return;
  936. timeout = *buf++;
  937. version = ((*buf)>>4) & 15;
  938. page_state = ((*buf++) >> 2) & 3;
  939. if (ctx->version == version) {
  940. return;
  941. }
  942. ctx->time_out = timeout;
  943. ctx->version = version;
  944. av_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
  945. if (page_state == 1 || page_state == 2) {
  946. delete_regions(ctx);
  947. delete_objects(ctx);
  948. delete_cluts(ctx);
  949. }
  950. tmp_display_list = ctx->display_list;
  951. ctx->display_list = NULL;
  952. while (buf + 5 < buf_end) {
  953. region_id = *buf++;
  954. buf += 1;
  955. display = tmp_display_list;
  956. tmp_ptr = &tmp_display_list;
  957. while (display && display->region_id != region_id) {
  958. tmp_ptr = &display->next;
  959. display = display->next;
  960. }
  961. if (!display)
  962. display = av_mallocz(sizeof(DVBSubRegionDisplay));
  963. display->region_id = region_id;
  964. display->x_pos = AV_RB16(buf);
  965. buf += 2;
  966. display->y_pos = AV_RB16(buf);
  967. buf += 2;
  968. *tmp_ptr = display->next;
  969. display->next = ctx->display_list;
  970. ctx->display_list = display;
  971. av_dlog(avctx, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos);
  972. }
  973. while (tmp_display_list) {
  974. display = tmp_display_list;
  975. tmp_display_list = display->next;
  976. av_free(display);
  977. }
  978. }
  979. #ifdef DEBUG
  980. static void save_display_set(DVBSubContext *ctx)
  981. {
  982. DVBSubRegion *region;
  983. DVBSubRegionDisplay *display;
  984. DVBSubCLUT *clut;
  985. uint32_t *clut_table;
  986. int x_pos, y_pos, width, height;
  987. int x, y, y_off, x_off;
  988. uint32_t *pbuf;
  989. char filename[32];
  990. static int fileno_index = 0;
  991. x_pos = -1;
  992. y_pos = -1;
  993. width = 0;
  994. height = 0;
  995. for (display = ctx->display_list; display; display = display->next) {
  996. region = get_region(ctx, display->region_id);
  997. if (x_pos == -1) {
  998. x_pos = display->x_pos;
  999. y_pos = display->y_pos;
  1000. width = region->width;
  1001. height = region->height;
  1002. } else {
  1003. if (display->x_pos < x_pos) {
  1004. width += (x_pos - display->x_pos);
  1005. x_pos = display->x_pos;
  1006. }
  1007. if (display->y_pos < y_pos) {
  1008. height += (y_pos - display->y_pos);
  1009. y_pos = display->y_pos;
  1010. }
  1011. if (display->x_pos + region->width > x_pos + width) {
  1012. width = display->x_pos + region->width - x_pos;
  1013. }
  1014. if (display->y_pos + region->height > y_pos + height) {
  1015. height = display->y_pos + region->height - y_pos;
  1016. }
  1017. }
  1018. }
  1019. if (x_pos >= 0) {
  1020. pbuf = av_malloc(width * height * 4);
  1021. for (display = ctx->display_list; display; display = display->next) {
  1022. region = get_region(ctx, display->region_id);
  1023. x_off = display->x_pos - x_pos;
  1024. y_off = display->y_pos - y_pos;
  1025. clut = get_clut(ctx, region->clut);
  1026. if (clut == 0)
  1027. clut = &default_clut;
  1028. switch (region->depth) {
  1029. case 2:
  1030. clut_table = clut->clut4;
  1031. break;
  1032. case 8:
  1033. clut_table = clut->clut256;
  1034. break;
  1035. case 4:
  1036. default:
  1037. clut_table = clut->clut16;
  1038. break;
  1039. }
  1040. for (y = 0; y < region->height; y++) {
  1041. for (x = 0; x < region->width; x++) {
  1042. pbuf[((y + y_off) * width) + x_off + x] =
  1043. clut_table[region->pbuf[y * region->width + x]];
  1044. }
  1045. }
  1046. }
  1047. snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index);
  1048. png_save2(filename, pbuf, width, height);
  1049. av_free(pbuf);
  1050. }
  1051. fileno_index++;
  1052. }
  1053. #endif
  1054. static void dvbsub_parse_display_definition_segment(AVCodecContext *avctx,
  1055. const uint8_t *buf,
  1056. int buf_size)
  1057. {
  1058. DVBSubContext *ctx = avctx->priv_data;
  1059. DVBSubDisplayDefinition *display_def = ctx->display_definition;
  1060. int dds_version, info_byte;
  1061. if (buf_size < 5)
  1062. return;
  1063. info_byte = bytestream_get_byte(&buf);
  1064. dds_version = info_byte >> 4;
  1065. if (display_def && display_def->version == dds_version)
  1066. return; // already have this display definition version
  1067. if (!display_def) {
  1068. display_def = av_mallocz(sizeof(*display_def));
  1069. ctx->display_definition = display_def;
  1070. }
  1071. if (!display_def)
  1072. return;
  1073. display_def->version = dds_version;
  1074. display_def->x = 0;
  1075. display_def->y = 0;
  1076. display_def->width = bytestream_get_be16(&buf) + 1;
  1077. display_def->height = bytestream_get_be16(&buf) + 1;
  1078. if (!avctx->width || !avctx->height) {
  1079. avctx->width = display_def->width;
  1080. avctx->height = display_def->height;
  1081. }
  1082. if (buf_size < 13)
  1083. return;
  1084. if (info_byte & 1<<3) { // display_window_flag
  1085. display_def->x = bytestream_get_be16(&buf);
  1086. display_def->width = bytestream_get_be16(&buf) - display_def->x + 1;
  1087. display_def->y = bytestream_get_be16(&buf);
  1088. display_def->height = bytestream_get_be16(&buf) - display_def->y + 1;
  1089. }
  1090. }
  1091. static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
  1092. int buf_size, AVSubtitle *sub)
  1093. {
  1094. DVBSubContext *ctx = avctx->priv_data;
  1095. DVBSubDisplayDefinition *display_def = ctx->display_definition;
  1096. DVBSubRegion *region;
  1097. DVBSubRegionDisplay *display;
  1098. AVSubtitleRect *rect;
  1099. DVBSubCLUT *clut;
  1100. uint32_t *clut_table;
  1101. int i;
  1102. int offset_x=0, offset_y=0;
  1103. sub->end_display_time = ctx->time_out * 1000;
  1104. if (display_def) {
  1105. offset_x = display_def->x;
  1106. offset_y = display_def->y;
  1107. }
  1108. sub->num_rects = 0;
  1109. for (display = ctx->display_list; display; display = display->next)
  1110. {
  1111. region = get_region(ctx, display->region_id);
  1112. if (region && region->dirty)
  1113. sub->num_rects++;
  1114. }
  1115. if (sub->num_rects > 0){
  1116. sub->rects = av_mallocz_array(sizeof(*sub->rects), sub->num_rects);
  1117. for(i=0; i<sub->num_rects; i++)
  1118. sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
  1119. i = 0;
  1120. for (display = ctx->display_list; display; display = display->next) {
  1121. region = get_region(ctx, display->region_id);
  1122. if (!region)
  1123. continue;
  1124. if (!region->dirty)
  1125. continue;
  1126. rect = sub->rects[i];
  1127. rect->x = display->x_pos + offset_x;
  1128. rect->y = display->y_pos + offset_y;
  1129. rect->w = region->width;
  1130. rect->h = region->height;
  1131. rect->nb_colors = (1 << region->depth);
  1132. rect->type = SUBTITLE_BITMAP;
  1133. rect->pict.linesize[0] = region->width;
  1134. clut = get_clut(ctx, region->clut);
  1135. if (!clut)
  1136. clut = &default_clut;
  1137. switch (region->depth) {
  1138. case 2:
  1139. clut_table = clut->clut4;
  1140. break;
  1141. case 8:
  1142. clut_table = clut->clut256;
  1143. break;
  1144. case 4:
  1145. default:
  1146. clut_table = clut->clut16;
  1147. break;
  1148. }
  1149. rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
  1150. memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
  1151. rect->pict.data[0] = av_malloc(region->buf_size);
  1152. memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
  1153. i++;
  1154. }
  1155. }
  1156. #ifdef DEBUG
  1157. save_display_set(ctx);
  1158. #endif
  1159. return 1;
  1160. }
  1161. static int dvbsub_decode(AVCodecContext *avctx,
  1162. void *data, int *data_size,
  1163. AVPacket *avpkt)
  1164. {
  1165. const uint8_t *buf = avpkt->data;
  1166. int buf_size = avpkt->size;
  1167. DVBSubContext *ctx = avctx->priv_data;
  1168. AVSubtitle *sub = data;
  1169. const uint8_t *p, *p_end;
  1170. int segment_type;
  1171. int page_id;
  1172. int segment_length;
  1173. int i;
  1174. int ret;
  1175. int got_segment = 0;
  1176. av_dlog(avctx, "DVB sub packet:\n");
  1177. for (i=0; i < buf_size; i++) {
  1178. av_dlog(avctx, "%02x ", buf[i]);
  1179. if (i % 16 == 15)
  1180. av_dlog(avctx, "\n");
  1181. }
  1182. if (i % 16)
  1183. av_dlog(avctx, "\n");
  1184. if (buf_size <= 6 || *buf != 0x0f) {
  1185. av_dlog(avctx, "incomplete or broken packet");
  1186. return -1;
  1187. }
  1188. p = buf;
  1189. p_end = buf + buf_size;
  1190. while (p_end - p >= 6 && *p == 0x0f) {
  1191. p += 1;
  1192. segment_type = *p++;
  1193. page_id = AV_RB16(p);
  1194. p += 2;
  1195. segment_length = AV_RB16(p);
  1196. p += 2;
  1197. if (avctx->debug & FF_DEBUG_STARTCODE) {
  1198. av_log(avctx, AV_LOG_DEBUG, "segment_type:%d page_id:%d segment_length:%d\n", segment_type, page_id, segment_length);
  1199. }
  1200. if (p_end - p < segment_length) {
  1201. av_dlog(avctx, "incomplete or broken packet");
  1202. return -1;
  1203. }
  1204. if (page_id == ctx->composition_id || page_id == ctx->ancillary_id ||
  1205. ctx->composition_id == -1 || ctx->ancillary_id == -1) {
  1206. switch (segment_type) {
  1207. case DVBSUB_PAGE_SEGMENT:
  1208. dvbsub_parse_page_segment(avctx, p, segment_length);
  1209. got_segment |= 1;
  1210. break;
  1211. case DVBSUB_REGION_SEGMENT:
  1212. dvbsub_parse_region_segment(avctx, p, segment_length);
  1213. got_segment |= 2;
  1214. break;
  1215. case DVBSUB_CLUT_SEGMENT:
  1216. ret = dvbsub_parse_clut_segment(avctx, p, segment_length);
  1217. if (ret < 0) return ret;
  1218. got_segment |= 4;
  1219. break;
  1220. case DVBSUB_OBJECT_SEGMENT:
  1221. dvbsub_parse_object_segment(avctx, p, segment_length);
  1222. got_segment |= 8;
  1223. break;
  1224. case DVBSUB_DISPLAYDEFINITION_SEGMENT:
  1225. dvbsub_parse_display_definition_segment(avctx, p, segment_length);
  1226. break;
  1227. case DVBSUB_DISPLAY_SEGMENT:
  1228. *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub);
  1229. got_segment |= 16;
  1230. break;
  1231. default:
  1232. av_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n",
  1233. segment_type, page_id, segment_length);
  1234. break;
  1235. }
  1236. }
  1237. p += segment_length;
  1238. }
  1239. // Some streams do not send a display segment but if we have all the other
  1240. // segments then we need no further data.
  1241. if (got_segment == 15 && sub) {
  1242. av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, emulating\n");
  1243. *data_size = dvbsub_display_end_segment(avctx, p, 0, sub);
  1244. }
  1245. return p - buf;
  1246. }
  1247. static const AVOption options[] = {
  1248. {NULL}
  1249. };
  1250. static const AVClass dvbsubdec_class = {
  1251. .class_name = "DVB Sub Decoder",
  1252. .item_name = av_default_item_name,
  1253. .option = options,
  1254. .version = LIBAVUTIL_VERSION_INT,
  1255. };
  1256. AVCodec ff_dvbsub_decoder = {
  1257. .name = "dvbsub",
  1258. .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"),
  1259. .type = AVMEDIA_TYPE_SUBTITLE,
  1260. .id = AV_CODEC_ID_DVB_SUBTITLE,
  1261. .priv_data_size = sizeof(DVBSubContext),
  1262. .init = dvbsub_init_decoder,
  1263. .close = dvbsub_close_decoder,
  1264. .decode = dvbsub_decode,
  1265. .priv_class = &dvbsubdec_class,
  1266. };