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.

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