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.

698 lines
21KB

  1. /*
  2. * PGS subtitle decoder
  3. * Copyright (c) 2009 Stephen Backway
  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. /**
  22. * @file
  23. * PGS subtitle decoder
  24. */
  25. #include "avcodec.h"
  26. #include "bytestream.h"
  27. #include "internal.h"
  28. #include "mathops.h"
  29. #include "libavutil/colorspace.h"
  30. #include "libavutil/imgutils.h"
  31. #include "libavutil/opt.h"
  32. #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
  33. #define MAX_EPOCH_PALETTES 8 // Max 8 allowed per PGS epoch
  34. #define MAX_EPOCH_OBJECTS 64 // Max 64 allowed per PGS epoch
  35. #define MAX_OBJECT_REFS 2 // Max objects per display set
  36. enum SegmentType {
  37. PALETTE_SEGMENT = 0x14,
  38. OBJECT_SEGMENT = 0x15,
  39. PRESENTATION_SEGMENT = 0x16,
  40. WINDOW_SEGMENT = 0x17,
  41. DISPLAY_SEGMENT = 0x80,
  42. };
  43. typedef struct PGSSubObjectRef {
  44. int id;
  45. int window_id;
  46. uint8_t composition_flag;
  47. int x;
  48. int y;
  49. int crop_x;
  50. int crop_y;
  51. int crop_w;
  52. int crop_h;
  53. } PGSSubObjectRef;
  54. typedef struct PGSSubPresentation {
  55. int id_number;
  56. int palette_id;
  57. int object_count;
  58. PGSSubObjectRef objects[MAX_OBJECT_REFS];
  59. int64_t pts;
  60. } PGSSubPresentation;
  61. typedef struct PGSSubObject {
  62. int id;
  63. int w;
  64. int h;
  65. uint8_t *rle;
  66. unsigned int rle_buffer_size, rle_data_len;
  67. unsigned int rle_remaining_len;
  68. } PGSSubObject;
  69. typedef struct PGSSubObjects {
  70. int count;
  71. PGSSubObject object[MAX_EPOCH_OBJECTS];
  72. } PGSSubObjects;
  73. typedef struct PGSSubPalette {
  74. int id;
  75. uint32_t clut[256];
  76. } PGSSubPalette;
  77. typedef struct PGSSubPalettes {
  78. int count;
  79. PGSSubPalette palette[MAX_EPOCH_PALETTES];
  80. } PGSSubPalettes;
  81. typedef struct PGSSubContext {
  82. AVClass *class;
  83. PGSSubPresentation presentation;
  84. PGSSubPalettes palettes;
  85. PGSSubObjects objects;
  86. int forced_subs_only;
  87. } PGSSubContext;
  88. static void flush_cache(AVCodecContext *avctx)
  89. {
  90. PGSSubContext *ctx = avctx->priv_data;
  91. int i;
  92. for (i = 0; i < ctx->objects.count; i++) {
  93. av_freep(&ctx->objects.object[i].rle);
  94. ctx->objects.object[i].rle_buffer_size = 0;
  95. ctx->objects.object[i].rle_remaining_len = 0;
  96. }
  97. ctx->objects.count = 0;
  98. ctx->palettes.count = 0;
  99. }
  100. static PGSSubObject * find_object(int id, PGSSubObjects *objects)
  101. {
  102. int i;
  103. for (i = 0; i < objects->count; i++) {
  104. if (objects->object[i].id == id)
  105. return &objects->object[i];
  106. }
  107. return NULL;
  108. }
  109. static PGSSubPalette * find_palette(int id, PGSSubPalettes *palettes)
  110. {
  111. int i;
  112. for (i = 0; i < palettes->count; i++) {
  113. if (palettes->palette[i].id == id)
  114. return &palettes->palette[i];
  115. }
  116. return NULL;
  117. }
  118. static av_cold int init_decoder(AVCodecContext *avctx)
  119. {
  120. avctx->pix_fmt = AV_PIX_FMT_PAL8;
  121. return 0;
  122. }
  123. static av_cold int close_decoder(AVCodecContext *avctx)
  124. {
  125. flush_cache(avctx);
  126. return 0;
  127. }
  128. /**
  129. * Decode the RLE data.
  130. *
  131. * The subtitle is stored as a Run Length Encoded image.
  132. *
  133. * @param avctx contains the current codec context
  134. * @param sub pointer to the processed subtitle data
  135. * @param buf pointer to the RLE data to process
  136. * @param buf_size size of the RLE data to process
  137. */
  138. static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect,
  139. const uint8_t *buf, unsigned int buf_size)
  140. {
  141. const uint8_t *rle_bitmap_end;
  142. int pixel_count, line_count;
  143. rle_bitmap_end = buf + buf_size;
  144. rect->pict.data[0] = av_malloc(rect->w * rect->h);
  145. if (!rect->pict.data[0])
  146. return AVERROR(ENOMEM);
  147. pixel_count = 0;
  148. line_count = 0;
  149. while (buf < rle_bitmap_end && line_count < rect->h) {
  150. uint8_t flags, color;
  151. int run;
  152. color = bytestream_get_byte(&buf);
  153. run = 1;
  154. if (color == 0x00) {
  155. flags = bytestream_get_byte(&buf);
  156. run = flags & 0x3f;
  157. if (flags & 0x40)
  158. run = (run << 8) + bytestream_get_byte(&buf);
  159. color = flags & 0x80 ? bytestream_get_byte(&buf) : 0;
  160. }
  161. if (run > 0 && pixel_count + run <= rect->w * rect->h) {
  162. memset(rect->pict.data[0] + pixel_count, color, run);
  163. pixel_count += run;
  164. } else if (!run) {
  165. /*
  166. * New Line. Check if correct pixels decoded, if not display warning
  167. * and adjust bitmap pointer to correct new line position.
  168. */
  169. if (pixel_count % rect->w > 0) {
  170. av_log(avctx, AV_LOG_ERROR, "Decoded %d pixels, when line should be %d pixels\n",
  171. pixel_count % rect->w, rect->w);
  172. if (avctx->err_recognition & AV_EF_EXPLODE) {
  173. return AVERROR_INVALIDDATA;
  174. }
  175. }
  176. line_count++;
  177. }
  178. }
  179. if (pixel_count < rect->w * rect->h) {
  180. av_log(avctx, AV_LOG_ERROR, "Insufficient RLE data for subtitle\n");
  181. return AVERROR_INVALIDDATA;
  182. }
  183. av_dlog(avctx, "Pixel Count = %d, Area = %d\n", pixel_count, rect->w * rect->h);
  184. return 0;
  185. }
  186. /**
  187. * Parse the picture segment packet.
  188. *
  189. * The picture segment contains details on the sequence id,
  190. * width, height and Run Length Encoded (RLE) bitmap data.
  191. *
  192. * @param avctx contains the current codec context
  193. * @param buf pointer to the packet to process
  194. * @param buf_size size of packet to process
  195. */
  196. static int parse_object_segment(AVCodecContext *avctx,
  197. const uint8_t *buf, int buf_size)
  198. {
  199. PGSSubContext *ctx = avctx->priv_data;
  200. PGSSubObject *object;
  201. uint8_t sequence_desc;
  202. unsigned int rle_bitmap_len, width, height;
  203. int id;
  204. if (buf_size <= 4)
  205. return AVERROR_INVALIDDATA;
  206. buf_size -= 4;
  207. id = bytestream_get_be16(&buf);
  208. object = find_object(id, &ctx->objects);
  209. if (!object) {
  210. if (ctx->objects.count >= MAX_EPOCH_OBJECTS) {
  211. av_log(avctx, AV_LOG_ERROR, "Too many objects in epoch\n");
  212. return AVERROR_INVALIDDATA;
  213. }
  214. object = &ctx->objects.object[ctx->objects.count++];
  215. object->id = id;
  216. }
  217. /* skip object version number */
  218. buf += 1;
  219. /* Read the Sequence Description to determine if start of RLE data or appended to previous RLE */
  220. sequence_desc = bytestream_get_byte(&buf);
  221. if (!(sequence_desc & 0x80)) {
  222. /* Additional RLE data */
  223. if (buf_size > object->rle_remaining_len)
  224. return AVERROR_INVALIDDATA;
  225. memcpy(object->rle + object->rle_data_len, buf, buf_size);
  226. object->rle_data_len += buf_size;
  227. object->rle_remaining_len -= buf_size;
  228. return 0;
  229. }
  230. if (buf_size <= 7)
  231. return AVERROR_INVALIDDATA;
  232. buf_size -= 7;
  233. /* Decode rle bitmap length, stored size includes width/height data */
  234. rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
  235. /* Get bitmap dimensions from data */
  236. width = bytestream_get_be16(&buf);
  237. height = bytestream_get_be16(&buf);
  238. /* Make sure the bitmap is not too large */
  239. if (avctx->width < width || avctx->height < height) {
  240. av_log(avctx, AV_LOG_ERROR, "Bitmap dimensions larger than video.\n");
  241. return AVERROR_INVALIDDATA;
  242. }
  243. if (buf_size > rle_bitmap_len) {
  244. av_log(avctx, AV_LOG_ERROR, "too much RLE data\n");
  245. return AVERROR_INVALIDDATA;
  246. }
  247. object->w = width;
  248. object->h = height;
  249. av_fast_padded_malloc(&object->rle, &object->rle_buffer_size, rle_bitmap_len);
  250. if (!object->rle)
  251. return AVERROR(ENOMEM);
  252. memcpy(object->rle, buf, buf_size);
  253. object->rle_data_len = buf_size;
  254. object->rle_remaining_len = rle_bitmap_len - buf_size;
  255. return 0;
  256. }
  257. /**
  258. * Parse the palette segment packet.
  259. *
  260. * The palette segment contains details of the palette,
  261. * a maximum of 256 colors can be defined.
  262. *
  263. * @param avctx contains the current codec context
  264. * @param buf pointer to the packet to process
  265. * @param buf_size size of packet to process
  266. */
  267. static int parse_palette_segment(AVCodecContext *avctx,
  268. const uint8_t *buf, int buf_size)
  269. {
  270. PGSSubContext *ctx = avctx->priv_data;
  271. PGSSubPalette *palette;
  272. const uint8_t *buf_end = buf + buf_size;
  273. const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
  274. int color_id;
  275. int y, cb, cr, alpha;
  276. int r, g, b, r_add, g_add, b_add;
  277. int id;
  278. id = bytestream_get_byte(&buf);
  279. palette = find_palette(id, &ctx->palettes);
  280. if (!palette) {
  281. if (ctx->palettes.count >= MAX_EPOCH_PALETTES) {
  282. av_log(avctx, AV_LOG_ERROR, "Too many palettes in epoch\n");
  283. return AVERROR_INVALIDDATA;
  284. }
  285. palette = &ctx->palettes.palette[ctx->palettes.count++];
  286. palette->id = id;
  287. }
  288. /* Skip palette version */
  289. buf += 1;
  290. while (buf < buf_end) {
  291. color_id = bytestream_get_byte(&buf);
  292. y = bytestream_get_byte(&buf);
  293. cr = bytestream_get_byte(&buf);
  294. cb = bytestream_get_byte(&buf);
  295. alpha = bytestream_get_byte(&buf);
  296. YUV_TO_RGB1(cb, cr);
  297. YUV_TO_RGB2(r, g, b, y);
  298. av_dlog(avctx, "Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
  299. /* Store color in palette */
  300. palette->clut[color_id] = RGBA(r,g,b,alpha);
  301. }
  302. return 0;
  303. }
  304. /**
  305. * Parse the presentation segment packet.
  306. *
  307. * The presentation segment contains details on the video
  308. * width, video height, x & y subtitle position.
  309. *
  310. * @param avctx contains the current codec context
  311. * @param buf pointer to the packet to process
  312. * @param buf_size size of packet to process
  313. * @todo TODO: Implement cropping
  314. */
  315. static int parse_presentation_segment(AVCodecContext *avctx,
  316. const uint8_t *buf, int buf_size,
  317. int64_t pts)
  318. {
  319. PGSSubContext *ctx = avctx->priv_data;
  320. int i, state, ret;
  321. const uint8_t *buf_end = buf + buf_size;
  322. // Video descriptor
  323. int w = bytestream_get_be16(&buf);
  324. int h = bytestream_get_be16(&buf);
  325. ctx->presentation.pts = pts;
  326. av_dlog(avctx, "Video Dimensions %dx%d\n",
  327. w, h);
  328. ret = ff_set_dimensions(avctx, w, h);
  329. if (ret < 0)
  330. return ret;
  331. /* Skip 1 bytes of unknown, frame rate */
  332. buf++;
  333. // Composition descriptor
  334. ctx->presentation.id_number = bytestream_get_be16(&buf);
  335. /*
  336. * state is a 2 bit field that defines pgs epoch boundaries
  337. * 00 - Normal, previously defined objects and palettes are still valid
  338. * 01 - Acquisition point, previous objects and palettes can be released
  339. * 10 - Epoch start, previous objects and palettes can be released
  340. * 11 - Epoch continue, previous objects and palettes can be released
  341. *
  342. * reserved 6 bits discarded
  343. */
  344. state = bytestream_get_byte(&buf) >> 6;
  345. if (state != 0) {
  346. flush_cache(avctx);
  347. }
  348. /*
  349. * skip palette_update_flag (0x80),
  350. */
  351. buf += 1;
  352. ctx->presentation.palette_id = bytestream_get_byte(&buf);
  353. ctx->presentation.object_count = bytestream_get_byte(&buf);
  354. if (ctx->presentation.object_count > MAX_OBJECT_REFS) {
  355. av_log(avctx, AV_LOG_ERROR,
  356. "Invalid number of presentation objects %d\n",
  357. ctx->presentation.object_count);
  358. ctx->presentation.object_count = 2;
  359. if (avctx->err_recognition & AV_EF_EXPLODE) {
  360. return AVERROR_INVALIDDATA;
  361. }
  362. }
  363. for (i = 0; i < ctx->presentation.object_count; i++)
  364. {
  365. if (buf_end - buf < 8) {
  366. av_log(avctx, AV_LOG_ERROR, "Insufficent space for object\n");
  367. ctx->presentation.object_count = i;
  368. return AVERROR_INVALIDDATA;
  369. }
  370. ctx->presentation.objects[i].id = bytestream_get_be16(&buf);
  371. ctx->presentation.objects[i].window_id = bytestream_get_byte(&buf);
  372. ctx->presentation.objects[i].composition_flag = bytestream_get_byte(&buf);
  373. ctx->presentation.objects[i].x = bytestream_get_be16(&buf);
  374. ctx->presentation.objects[i].y = bytestream_get_be16(&buf);
  375. // If cropping
  376. if (ctx->presentation.objects[i].composition_flag & 0x80) {
  377. ctx->presentation.objects[i].crop_x = bytestream_get_be16(&buf);
  378. ctx->presentation.objects[i].crop_y = bytestream_get_be16(&buf);
  379. ctx->presentation.objects[i].crop_w = bytestream_get_be16(&buf);
  380. ctx->presentation.objects[i].crop_h = bytestream_get_be16(&buf);
  381. }
  382. av_dlog(avctx, "Subtitle Placement x=%d, y=%d\n",
  383. ctx->presentation.objects[i].x, ctx->presentation.objects[i].y);
  384. if (ctx->presentation.objects[i].x > avctx->width ||
  385. ctx->presentation.objects[i].y > avctx->height) {
  386. av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
  387. ctx->presentation.objects[i].x,
  388. ctx->presentation.objects[i].y,
  389. avctx->width, avctx->height);
  390. ctx->presentation.objects[i].x = 0;
  391. ctx->presentation.objects[i].y = 0;
  392. if (avctx->err_recognition & AV_EF_EXPLODE) {
  393. return AVERROR_INVALIDDATA;
  394. }
  395. }
  396. }
  397. return 0;
  398. }
  399. /**
  400. * Parse the display segment packet.
  401. *
  402. * The display segment controls the updating of the display.
  403. *
  404. * @param avctx contains the current codec context
  405. * @param data pointer to the data pertaining the subtitle to display
  406. * @param buf pointer to the packet to process
  407. * @param buf_size size of packet to process
  408. */
  409. static int display_end_segment(AVCodecContext *avctx, void *data,
  410. const uint8_t *buf, int buf_size)
  411. {
  412. AVSubtitle *sub = data;
  413. PGSSubContext *ctx = avctx->priv_data;
  414. int64_t pts;
  415. PGSSubPalette *palette;
  416. int i, ret;
  417. pts = ctx->presentation.pts != AV_NOPTS_VALUE ? ctx->presentation.pts : sub->pts;
  418. memset(sub, 0, sizeof(*sub));
  419. sub->pts = pts;
  420. ctx->presentation.pts = AV_NOPTS_VALUE;
  421. sub->start_display_time = 0;
  422. // There is no explicit end time for PGS subtitles. The end time
  423. // is defined by the start of the next sub which may contain no
  424. // objects (i.e. clears the previous sub)
  425. sub->end_display_time = UINT32_MAX;
  426. sub->format = 0;
  427. // Blank if last object_count was 0.
  428. if (!ctx->presentation.object_count)
  429. return 1;
  430. sub->rects = av_mallocz(sizeof(*sub->rects) * ctx->presentation.object_count);
  431. if (!sub->rects) {
  432. return AVERROR(ENOMEM);
  433. }
  434. palette = find_palette(ctx->presentation.palette_id, &ctx->palettes);
  435. if (!palette) {
  436. // Missing palette. Should only happen with damaged streams.
  437. av_log(avctx, AV_LOG_ERROR, "Invalid palette id %d\n",
  438. ctx->presentation.palette_id);
  439. avsubtitle_free(sub);
  440. return AVERROR_INVALIDDATA;
  441. }
  442. for (i = 0; i < ctx->presentation.object_count; i++) {
  443. PGSSubObject *object;
  444. sub->rects[i] = av_mallocz(sizeof(*sub->rects[0]));
  445. if (!sub->rects[i]) {
  446. avsubtitle_free(sub);
  447. return AVERROR(ENOMEM);
  448. }
  449. sub->num_rects++;
  450. sub->rects[i]->type = SUBTITLE_BITMAP;
  451. /* Process bitmap */
  452. object = find_object(ctx->presentation.objects[i].id, &ctx->objects);
  453. if (!object) {
  454. // Missing object. Should only happen with damaged streams.
  455. av_log(avctx, AV_LOG_ERROR, "Invalid object id %d\n",
  456. ctx->presentation.objects[i].id);
  457. if (avctx->err_recognition & AV_EF_EXPLODE) {
  458. avsubtitle_free(sub);
  459. return AVERROR_INVALIDDATA;
  460. }
  461. // Leaves rect empty with 0 width and height.
  462. continue;
  463. }
  464. if (ctx->presentation.objects[i].composition_flag & 0x40)
  465. sub->rects[i]->flags |= AV_SUBTITLE_FLAG_FORCED;
  466. sub->rects[i]->x = ctx->presentation.objects[i].x;
  467. sub->rects[i]->y = ctx->presentation.objects[i].y;
  468. sub->rects[i]->w = object->w;
  469. sub->rects[i]->h = object->h;
  470. sub->rects[i]->pict.linesize[0] = object->w;
  471. if (object->rle) {
  472. if (object->rle_remaining_len) {
  473. av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n",
  474. object->rle_data_len, object->rle_remaining_len);
  475. if (avctx->err_recognition & AV_EF_EXPLODE) {
  476. avsubtitle_free(sub);
  477. return AVERROR_INVALIDDATA;
  478. }
  479. }
  480. ret = decode_rle(avctx, sub->rects[i], object->rle, object->rle_data_len);
  481. if (ret < 0) {
  482. if ((avctx->err_recognition & AV_EF_EXPLODE) ||
  483. ret == AVERROR(ENOMEM)) {
  484. avsubtitle_free(sub);
  485. return ret;
  486. }
  487. sub->rects[i]->w = 0;
  488. sub->rects[i]->h = 0;
  489. continue;
  490. }
  491. }
  492. /* Allocate memory for colors */
  493. sub->rects[i]->nb_colors = 256;
  494. sub->rects[i]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
  495. if (!sub->rects[i]->pict.data[1]) {
  496. avsubtitle_free(sub);
  497. return AVERROR(ENOMEM);
  498. }
  499. if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40)
  500. memcpy(sub->rects[i]->pict.data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t));
  501. }
  502. return 1;
  503. }
  504. static int decode(AVCodecContext *avctx, void *data, int *data_size,
  505. AVPacket *avpkt)
  506. {
  507. const uint8_t *buf = avpkt->data;
  508. int buf_size = avpkt->size;
  509. const uint8_t *buf_end;
  510. uint8_t segment_type;
  511. int segment_length;
  512. int i, ret;
  513. av_dlog(avctx, "PGS sub packet:\n");
  514. for (i = 0; i < buf_size; i++) {
  515. av_dlog(avctx, "%02x ", buf[i]);
  516. if (i % 16 == 15)
  517. av_dlog(avctx, "\n");
  518. }
  519. if (i & 15)
  520. av_dlog(avctx, "\n");
  521. *data_size = 0;
  522. /* Ensure that we have received at a least a segment code and segment length */
  523. if (buf_size < 3)
  524. return -1;
  525. buf_end = buf + buf_size;
  526. /* Step through buffer to identify segments */
  527. while (buf < buf_end) {
  528. segment_type = bytestream_get_byte(&buf);
  529. segment_length = bytestream_get_be16(&buf);
  530. av_dlog(avctx, "Segment Length %d, Segment Type %x\n", segment_length, segment_type);
  531. if (segment_type != DISPLAY_SEGMENT && segment_length > buf_end - buf)
  532. break;
  533. ret = 0;
  534. switch (segment_type) {
  535. case PALETTE_SEGMENT:
  536. ret = parse_palette_segment(avctx, buf, segment_length);
  537. break;
  538. case OBJECT_SEGMENT:
  539. ret = parse_object_segment(avctx, buf, segment_length);
  540. break;
  541. case PRESENTATION_SEGMENT:
  542. ret = parse_presentation_segment(avctx, buf, segment_length, ((AVSubtitle*)(data))->pts);
  543. break;
  544. case WINDOW_SEGMENT:
  545. /*
  546. * Window Segment Structure (No new information provided):
  547. * 2 bytes: Unknown,
  548. * 2 bytes: X position of subtitle,
  549. * 2 bytes: Y position of subtitle,
  550. * 2 bytes: Width of subtitle,
  551. * 2 bytes: Height of subtitle.
  552. */
  553. break;
  554. case DISPLAY_SEGMENT:
  555. ret = display_end_segment(avctx, data, buf, segment_length);
  556. if (ret >= 0)
  557. *data_size = ret;
  558. break;
  559. default:
  560. av_log(avctx, AV_LOG_ERROR, "Unknown subtitle segment type 0x%x, length %d\n",
  561. segment_type, segment_length);
  562. ret = AVERROR_INVALIDDATA;
  563. break;
  564. }
  565. if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
  566. return ret;
  567. buf += segment_length;
  568. }
  569. return buf_size;
  570. }
  571. #define OFFSET(x) offsetof(PGSSubContext, x)
  572. #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
  573. static const AVOption options[] = {
  574. {"forced_subs_only", "Only show forced subtitles", OFFSET(forced_subs_only), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, SD},
  575. { NULL },
  576. };
  577. static const AVClass pgsdec_class = {
  578. .class_name = "PGS subtitle decoder",
  579. .item_name = av_default_item_name,
  580. .option = options,
  581. .version = LIBAVUTIL_VERSION_INT,
  582. };
  583. AVCodec ff_pgssub_decoder = {
  584. .name = "pgssub",
  585. .long_name = NULL_IF_CONFIG_SMALL("HDMV Presentation Graphic Stream subtitles"),
  586. .type = AVMEDIA_TYPE_SUBTITLE,
  587. .id = AV_CODEC_ID_HDMV_PGS_SUBTITLE,
  588. .priv_data_size = sizeof(PGSSubContext),
  589. .init = init_decoder,
  590. .close = close_decoder,
  591. .decode = decode,
  592. .priv_class = &pgsdec_class,
  593. };