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.

670 lines
20KB

  1. /*
  2. * DVD subtitle decoding
  3. * Copyright (c) 2005 Fabrice Bellard
  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 "internal.h"
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/colorspace.h"
  26. #include "libavutil/opt.h"
  27. #include "libavutil/imgutils.h"
  28. #include "libavutil/avstring.h"
  29. typedef struct DVDSubContext
  30. {
  31. AVClass *class;
  32. uint32_t palette[16];
  33. char *palette_str;
  34. int has_palette;
  35. uint8_t colormap[4];
  36. uint8_t alpha[256];
  37. uint8_t *buf;
  38. int buf_size;
  39. #ifdef DEBUG
  40. int sub_id;
  41. #endif
  42. } DVDSubContext;
  43. static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values)
  44. {
  45. const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
  46. uint8_t r, g, b;
  47. int i, y, cb, cr;
  48. int r_add, g_add, b_add;
  49. for (i = num_values; i > 0; i--) {
  50. y = *ycbcr++;
  51. cr = *ycbcr++;
  52. cb = *ycbcr++;
  53. YUV_TO_RGB1_CCIR(cb, cr);
  54. YUV_TO_RGB2_CCIR(r, g, b, y);
  55. *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b;
  56. }
  57. }
  58. static int decode_run_2bit(GetBitContext *gb, int *color)
  59. {
  60. unsigned int v, t;
  61. v = 0;
  62. for (t = 1; v < t && t <= 0x40; t <<= 2)
  63. v = (v << 4) | get_bits(gb, 4);
  64. *color = v & 3;
  65. if (v < 4) { /* Code for fill rest of line */
  66. return INT_MAX;
  67. }
  68. return v >> 2;
  69. }
  70. static int decode_run_8bit(GetBitContext *gb, int *color)
  71. {
  72. int len;
  73. int has_run = get_bits1(gb);
  74. if (get_bits1(gb))
  75. *color = get_bits(gb, 8);
  76. else
  77. *color = get_bits(gb, 2);
  78. if (has_run) {
  79. if (get_bits1(gb)) {
  80. len = get_bits(gb, 7);
  81. if (len == 0)
  82. len = INT_MAX;
  83. else
  84. len += 9;
  85. } else
  86. len = get_bits(gb, 3) + 2;
  87. } else
  88. len = 1;
  89. return len;
  90. }
  91. static int decode_rle(uint8_t *bitmap, int linesize, int w, int h,
  92. const uint8_t *buf, int start, int buf_size, int is_8bit)
  93. {
  94. GetBitContext gb;
  95. int bit_len;
  96. int x, y, len, color;
  97. uint8_t *d;
  98. bit_len = (buf_size - start) * 8;
  99. init_get_bits(&gb, buf + start, bit_len);
  100. x = 0;
  101. y = 0;
  102. d = bitmap;
  103. for(;;) {
  104. if (get_bits_count(&gb) > bit_len)
  105. return -1;
  106. if (is_8bit)
  107. len = decode_run_8bit(&gb, &color);
  108. else
  109. len = decode_run_2bit(&gb, &color);
  110. len = FFMIN(len, w - x);
  111. memset(d + x, color, len);
  112. x += len;
  113. if (x >= w) {
  114. y++;
  115. if (y >= h)
  116. break;
  117. d += linesize;
  118. x = 0;
  119. /* byte align */
  120. align_get_bits(&gb);
  121. }
  122. }
  123. return 0;
  124. }
  125. static void guess_palette(DVDSubContext* ctx,
  126. uint32_t *rgba_palette,
  127. uint32_t subtitle_color)
  128. {
  129. static const uint8_t level_map[4][4] = {
  130. // this configuration (full range, lowest to highest) in tests
  131. // seemed most common, so assume this
  132. {0xff},
  133. {0x00, 0xff},
  134. {0x00, 0x80, 0xff},
  135. {0x00, 0x55, 0xaa, 0xff},
  136. };
  137. uint8_t color_used[16] = { 0 };
  138. int nb_opaque_colors, i, level, j, r, g, b;
  139. uint8_t *colormap = ctx->colormap, *alpha = ctx->alpha;
  140. if(ctx->has_palette) {
  141. for(i = 0; i < 4; i++)
  142. rgba_palette[i] = (ctx->palette[colormap[i]] & 0x00ffffff)
  143. | ((alpha[i] * 17U) << 24);
  144. return;
  145. }
  146. for(i = 0; i < 4; i++)
  147. rgba_palette[i] = 0;
  148. nb_opaque_colors = 0;
  149. for(i = 0; i < 4; i++) {
  150. if (alpha[i] != 0 && !color_used[colormap[i]]) {
  151. color_used[colormap[i]] = 1;
  152. nb_opaque_colors++;
  153. }
  154. }
  155. if (nb_opaque_colors == 0)
  156. return;
  157. j = 0;
  158. memset(color_used, 0, 16);
  159. for(i = 0; i < 4; i++) {
  160. if (alpha[i] != 0) {
  161. if (!color_used[colormap[i]]) {
  162. level = level_map[nb_opaque_colors][j];
  163. r = (((subtitle_color >> 16) & 0xff) * level) >> 8;
  164. g = (((subtitle_color >> 8) & 0xff) * level) >> 8;
  165. b = (((subtitle_color >> 0) & 0xff) * level) >> 8;
  166. rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);
  167. color_used[colormap[i]] = (i + 1);
  168. j++;
  169. } else {
  170. rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |
  171. ((alpha[i] * 17) << 24);
  172. }
  173. }
  174. }
  175. }
  176. static void reset_rects(AVSubtitle *sub_header)
  177. {
  178. int i;
  179. if (sub_header->rects != NULL) {
  180. for (i = 0; i < sub_header->num_rects; i++) {
  181. av_freep(&sub_header->rects[i]->pict.data[0]);
  182. av_freep(&sub_header->rects[i]->pict.data[1]);
  183. av_freep(&sub_header->rects[i]);
  184. }
  185. av_freep(&sub_header->rects);
  186. sub_header->num_rects = 0;
  187. }
  188. }
  189. #define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a))
  190. static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
  191. const uint8_t *buf, int buf_size)
  192. {
  193. int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos;
  194. int big_offsets, offset_size, is_8bit = 0;
  195. const uint8_t *yuv_palette = 0;
  196. uint8_t *colormap = ctx->colormap, *alpha = ctx->alpha;
  197. int date;
  198. int i;
  199. int is_menu = 0;
  200. if (buf_size < 10)
  201. return -1;
  202. if (AV_RB16(buf) == 0) { /* HD subpicture with 4-byte offsets */
  203. big_offsets = 1;
  204. offset_size = 4;
  205. cmd_pos = 6;
  206. } else {
  207. big_offsets = 0;
  208. offset_size = 2;
  209. cmd_pos = 2;
  210. }
  211. cmd_pos = READ_OFFSET(buf + cmd_pos);
  212. if (cmd_pos < 0 || cmd_pos > buf_size - 2 - offset_size)
  213. return AVERROR(EAGAIN);
  214. while (cmd_pos > 0 && cmd_pos < buf_size - 2 - offset_size) {
  215. date = AV_RB16(buf + cmd_pos);
  216. next_cmd_pos = READ_OFFSET(buf + cmd_pos + 2);
  217. av_dlog(NULL, "cmd_pos=0x%04x next=0x%04x date=%d\n",
  218. cmd_pos, next_cmd_pos, date);
  219. pos = cmd_pos + 2 + offset_size;
  220. offset1 = -1;
  221. offset2 = -1;
  222. x1 = y1 = x2 = y2 = 0;
  223. while (pos < buf_size) {
  224. cmd = buf[pos++];
  225. av_dlog(NULL, "cmd=%02x\n", cmd);
  226. switch(cmd) {
  227. case 0x00:
  228. /* menu subpicture */
  229. is_menu = 1;
  230. break;
  231. case 0x01:
  232. /* set start date */
  233. sub_header->start_display_time = (date << 10) / 90;
  234. break;
  235. case 0x02:
  236. /* set end date */
  237. sub_header->end_display_time = (date << 10) / 90;
  238. break;
  239. case 0x03:
  240. /* set colormap */
  241. if ((buf_size - pos) < 2)
  242. goto fail;
  243. colormap[3] = buf[pos] >> 4;
  244. colormap[2] = buf[pos] & 0x0f;
  245. colormap[1] = buf[pos + 1] >> 4;
  246. colormap[0] = buf[pos + 1] & 0x0f;
  247. pos += 2;
  248. break;
  249. case 0x04:
  250. /* set alpha */
  251. if ((buf_size - pos) < 2)
  252. goto fail;
  253. alpha[3] = buf[pos] >> 4;
  254. alpha[2] = buf[pos] & 0x0f;
  255. alpha[1] = buf[pos + 1] >> 4;
  256. alpha[0] = buf[pos + 1] & 0x0f;
  257. pos += 2;
  258. av_dlog(NULL, "alpha=%x%x%x%x\n", alpha[0],alpha[1],alpha[2],alpha[3]);
  259. break;
  260. case 0x05:
  261. case 0x85:
  262. if ((buf_size - pos) < 6)
  263. goto fail;
  264. x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4);
  265. x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2];
  266. y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4);
  267. y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];
  268. if (cmd & 0x80)
  269. is_8bit = 1;
  270. av_dlog(NULL, "x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2);
  271. pos += 6;
  272. break;
  273. case 0x06:
  274. if ((buf_size - pos) < 4)
  275. goto fail;
  276. offset1 = AV_RB16(buf + pos);
  277. offset2 = AV_RB16(buf + pos + 2);
  278. av_dlog(NULL, "offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
  279. pos += 4;
  280. break;
  281. case 0x86:
  282. if ((buf_size - pos) < 8)
  283. goto fail;
  284. offset1 = AV_RB32(buf + pos);
  285. offset2 = AV_RB32(buf + pos + 4);
  286. av_dlog(NULL, "offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
  287. pos += 8;
  288. break;
  289. case 0x83:
  290. /* HD set palette */
  291. if ((buf_size - pos) < 768)
  292. goto fail;
  293. yuv_palette = buf + pos;
  294. pos += 768;
  295. break;
  296. case 0x84:
  297. /* HD set contrast (alpha) */
  298. if ((buf_size - pos) < 256)
  299. goto fail;
  300. for (i = 0; i < 256; i++)
  301. alpha[i] = 0xFF - buf[pos+i];
  302. pos += 256;
  303. break;
  304. case 0xff:
  305. goto the_end;
  306. default:
  307. av_dlog(NULL, "unrecognised subpicture command 0x%x\n", cmd);
  308. goto the_end;
  309. }
  310. }
  311. the_end:
  312. if (offset1 >= 0) {
  313. int w, h;
  314. uint8_t *bitmap;
  315. /* decode the bitmap */
  316. w = x2 - x1 + 1;
  317. if (w < 0)
  318. w = 0;
  319. h = y2 - y1 + 1;
  320. if (h < 0)
  321. h = 0;
  322. if (w > 0 && h > 0) {
  323. reset_rects(sub_header);
  324. bitmap = av_malloc(w * h);
  325. sub_header->rects = av_mallocz(sizeof(*sub_header->rects));
  326. sub_header->rects[0] = av_mallocz(sizeof(AVSubtitleRect));
  327. sub_header->num_rects = 1;
  328. sub_header->rects[0]->pict.data[0] = bitmap;
  329. decode_rle(bitmap, w * 2, w, (h + 1) / 2,
  330. buf, offset1, buf_size, is_8bit);
  331. decode_rle(bitmap + w, w * 2, w, h / 2,
  332. buf, offset2, buf_size, is_8bit);
  333. sub_header->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
  334. if (is_8bit) {
  335. if (yuv_palette == 0)
  336. goto fail;
  337. sub_header->rects[0]->nb_colors = 256;
  338. yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256);
  339. } else {
  340. sub_header->rects[0]->nb_colors = 4;
  341. guess_palette(ctx, (uint32_t*)sub_header->rects[0]->pict.data[1],
  342. 0xffff00);
  343. }
  344. sub_header->rects[0]->x = x1;
  345. sub_header->rects[0]->y = y1;
  346. sub_header->rects[0]->w = w;
  347. sub_header->rects[0]->h = h;
  348. sub_header->rects[0]->type = SUBTITLE_BITMAP;
  349. sub_header->rects[0]->pict.linesize[0] = w;
  350. sub_header->rects[0]->flags = is_menu ? AV_SUBTITLE_FLAG_FORCED : 0;
  351. }
  352. }
  353. if (next_cmd_pos < cmd_pos) {
  354. av_log(NULL, AV_LOG_ERROR, "Invalid command offset\n");
  355. break;
  356. }
  357. if (next_cmd_pos == cmd_pos)
  358. break;
  359. cmd_pos = next_cmd_pos;
  360. }
  361. if (sub_header->num_rects > 0)
  362. return is_menu;
  363. fail:
  364. reset_rects(sub_header);
  365. return -1;
  366. }
  367. static int is_transp(const uint8_t *buf, int pitch, int n,
  368. const uint8_t *transp_color)
  369. {
  370. int i;
  371. for(i = 0; i < n; i++) {
  372. if (!transp_color[*buf])
  373. return 0;
  374. buf += pitch;
  375. }
  376. return 1;
  377. }
  378. /* return 0 if empty rectangle, 1 if non empty */
  379. static int find_smallest_bounding_rectangle(AVSubtitle *s)
  380. {
  381. uint8_t transp_color[256] = { 0 };
  382. int y1, y2, x1, x2, y, w, h, i;
  383. uint8_t *bitmap;
  384. if (s->num_rects == 0 || s->rects == NULL || s->rects[0]->w <= 0 || s->rects[0]->h <= 0)
  385. return 0;
  386. for(i = 0; i < s->rects[0]->nb_colors; i++) {
  387. if ((((uint32_t*)s->rects[0]->pict.data[1])[i] >> 24) == 0)
  388. transp_color[i] = 1;
  389. }
  390. y1 = 0;
  391. while (y1 < s->rects[0]->h && is_transp(s->rects[0]->pict.data[0] + y1 * s->rects[0]->pict.linesize[0],
  392. 1, s->rects[0]->w, transp_color))
  393. y1++;
  394. if (y1 == s->rects[0]->h) {
  395. av_freep(&s->rects[0]->pict.data[0]);
  396. s->rects[0]->w = s->rects[0]->h = 0;
  397. return 0;
  398. }
  399. y2 = s->rects[0]->h - 1;
  400. while (y2 > 0 && is_transp(s->rects[0]->pict.data[0] + y2 * s->rects[0]->pict.linesize[0], 1,
  401. s->rects[0]->w, transp_color))
  402. y2--;
  403. x1 = 0;
  404. while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->pict.data[0] + x1, s->rects[0]->pict.linesize[0],
  405. s->rects[0]->h, transp_color))
  406. x1++;
  407. x2 = s->rects[0]->w - 1;
  408. while (x2 > 0 && is_transp(s->rects[0]->pict.data[0] + x2, s->rects[0]->pict.linesize[0], s->rects[0]->h,
  409. transp_color))
  410. x2--;
  411. w = x2 - x1 + 1;
  412. h = y2 - y1 + 1;
  413. bitmap = av_malloc(w * h);
  414. if (!bitmap)
  415. return 1;
  416. for(y = 0; y < h; y++) {
  417. memcpy(bitmap + w * y, s->rects[0]->pict.data[0] + x1 + (y1 + y) * s->rects[0]->pict.linesize[0], w);
  418. }
  419. av_freep(&s->rects[0]->pict.data[0]);
  420. s->rects[0]->pict.data[0] = bitmap;
  421. s->rects[0]->pict.linesize[0] = w;
  422. s->rects[0]->w = w;
  423. s->rects[0]->h = h;
  424. s->rects[0]->x += x1;
  425. s->rects[0]->y += y1;
  426. return 1;
  427. }
  428. #ifdef DEBUG
  429. static void ppm_save(const char *filename, uint8_t *bitmap, int w, int h,
  430. uint32_t *rgba_palette)
  431. {
  432. int x, y, v;
  433. FILE *f;
  434. f = fopen(filename, "w");
  435. if (!f) {
  436. perror(filename);
  437. return;
  438. }
  439. fprintf(f, "P6\n"
  440. "%d %d\n"
  441. "%d\n",
  442. w, h, 255);
  443. for(y = 0; y < h; y++) {
  444. for(x = 0; x < w; x++) {
  445. v = rgba_palette[bitmap[y * w + x]];
  446. putc((v >> 16) & 0xff, f);
  447. putc((v >> 8) & 0xff, f);
  448. putc((v >> 0) & 0xff, f);
  449. }
  450. }
  451. fclose(f);
  452. }
  453. #endif
  454. static int append_to_cached_buf(AVCodecContext *avctx,
  455. const uint8_t *buf, int buf_size)
  456. {
  457. DVDSubContext *ctx = avctx->priv_data;
  458. if (ctx->buf_size > 0xffff - buf_size) {
  459. av_log(avctx, AV_LOG_WARNING, "Attempt to reconstruct "
  460. "too large SPU packets aborted.\n");
  461. av_freep(&ctx->buf);
  462. return AVERROR_INVALIDDATA;
  463. }
  464. ctx->buf = av_realloc(ctx->buf, ctx->buf_size + buf_size);
  465. if (!ctx->buf)
  466. return AVERROR(ENOMEM);
  467. memcpy(ctx->buf + ctx->buf_size, buf, buf_size);
  468. ctx->buf_size += buf_size;
  469. return 0;
  470. }
  471. static int dvdsub_decode(AVCodecContext *avctx,
  472. void *data, int *data_size,
  473. AVPacket *avpkt)
  474. {
  475. DVDSubContext *ctx = avctx->priv_data;
  476. const uint8_t *buf = avpkt->data;
  477. int buf_size = avpkt->size;
  478. AVSubtitle *sub = data;
  479. int is_menu;
  480. if (ctx->buf) {
  481. int ret = append_to_cached_buf(avctx, buf, buf_size);
  482. if (ret < 0) {
  483. *data_size = 0;
  484. return ret;
  485. }
  486. buf = ctx->buf;
  487. buf_size = ctx->buf_size;
  488. }
  489. is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size);
  490. if (is_menu == AVERROR(EAGAIN)) {
  491. *data_size = 0;
  492. return append_to_cached_buf(avctx, buf, buf_size);
  493. }
  494. if (is_menu < 0) {
  495. no_subtitle:
  496. *data_size = 0;
  497. return buf_size;
  498. }
  499. if (!is_menu && find_smallest_bounding_rectangle(sub) == 0)
  500. goto no_subtitle;
  501. #if defined(DEBUG)
  502. {
  503. char ppm_name[32];
  504. snprintf(ppm_name, sizeof(ppm_name), "/tmp/%05d.ppm", ctx->sub_id++);
  505. av_dlog(NULL, "start=%d ms end =%d ms\n",
  506. sub->start_display_time,
  507. sub->end_display_time);
  508. ppm_save(ppm_name, sub->rects[0]->pict.data[0],
  509. sub->rects[0]->w, sub->rects[0]->h, sub->rects[0]->pict.data[1]);
  510. }
  511. #endif
  512. av_freep(&ctx->buf);
  513. ctx->buf_size = 0;
  514. *data_size = 1;
  515. return buf_size;
  516. }
  517. static void parse_palette(DVDSubContext *ctx, char *p)
  518. {
  519. int i;
  520. ctx->has_palette = 1;
  521. for(i=0;i<16;i++) {
  522. ctx->palette[i] = strtoul(p, &p, 16);
  523. while(*p == ',' || av_isspace(*p))
  524. p++;
  525. }
  526. }
  527. static int dvdsub_parse_extradata(AVCodecContext *avctx)
  528. {
  529. DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data;
  530. char *dataorig, *data;
  531. if (!avctx->extradata || !avctx->extradata_size)
  532. return 1;
  533. dataorig = data = av_malloc(avctx->extradata_size+1);
  534. if (!data)
  535. return AVERROR(ENOMEM);
  536. memcpy(data, avctx->extradata, avctx->extradata_size);
  537. data[avctx->extradata_size] = '\0';
  538. for(;;) {
  539. int pos = strcspn(data, "\n\r");
  540. if (pos==0 && *data==0)
  541. break;
  542. if (strncmp("palette:", data, 8) == 0) {
  543. parse_palette(ctx, data + 8);
  544. } else if (strncmp("size:", data, 5) == 0) {
  545. int w, h;
  546. if (sscanf(data + 5, "%dx%d", &w, &h) == 2) {
  547. int ret = ff_set_dimensions(avctx, w, h);
  548. if (ret < 0) {
  549. av_free(dataorig);
  550. return ret;
  551. }
  552. }
  553. }
  554. data += pos;
  555. data += strspn(data, "\n\r");
  556. }
  557. av_free(dataorig);
  558. return 1;
  559. }
  560. static av_cold int dvdsub_init(AVCodecContext *avctx)
  561. {
  562. DVDSubContext *ctx = avctx->priv_data;
  563. int ret;
  564. if ((ret = dvdsub_parse_extradata(avctx)) < 0)
  565. return ret;
  566. if (ctx->palette_str)
  567. parse_palette(ctx, ctx->palette_str);
  568. if (ctx->has_palette) {
  569. int i;
  570. av_log(avctx, AV_LOG_DEBUG, "palette:");
  571. for(i=0;i<16;i++)
  572. av_log(avctx, AV_LOG_DEBUG, " 0x%06x", ctx->palette[i]);
  573. av_log(avctx, AV_LOG_DEBUG, "\n");
  574. }
  575. return 1;
  576. }
  577. static av_cold int dvdsub_close(AVCodecContext *avctx)
  578. {
  579. DVDSubContext *ctx = avctx->priv_data;
  580. av_freep(&ctx->buf);
  581. ctx->buf_size = 0;
  582. return 0;
  583. }
  584. #define OFFSET(field) offsetof(DVDSubContext, field)
  585. #define VD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
  586. static const AVOption options[] = {
  587. { "palette", "set the global palette", OFFSET(palette_str), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VD },
  588. { NULL }
  589. };
  590. static const AVClass dvdsub_class = {
  591. .class_name = "dvdsubdec",
  592. .item_name = av_default_item_name,
  593. .option = options,
  594. .version = LIBAVUTIL_VERSION_INT,
  595. };
  596. AVCodec ff_dvdsub_decoder = {
  597. .name = "dvdsub",
  598. .long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"),
  599. .type = AVMEDIA_TYPE_SUBTITLE,
  600. .id = AV_CODEC_ID_DVD_SUBTITLE,
  601. .priv_data_size = sizeof(DVDSubContext),
  602. .init = dvdsub_init,
  603. .decode = dvdsub_decode,
  604. .close = dvdsub_close,
  605. .priv_class = &dvdsub_class,
  606. };