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.

693 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. // Video descriptor
  322. int w = bytestream_get_be16(&buf);
  323. int h = bytestream_get_be16(&buf);
  324. uint16_t object_index;
  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. ctx->presentation.objects[i].id = bytestream_get_be16(&buf);
  366. ctx->presentation.objects[i].window_id = bytestream_get_byte(&buf);
  367. ctx->presentation.objects[i].composition_flag = bytestream_get_byte(&buf);
  368. ctx->presentation.objects[i].x = bytestream_get_be16(&buf);
  369. ctx->presentation.objects[i].y = bytestream_get_be16(&buf);
  370. // If cropping
  371. if (ctx->presentation.objects[i].composition_flag & 0x80) {
  372. ctx->presentation.objects[i].crop_x = bytestream_get_be16(&buf);
  373. ctx->presentation.objects[i].crop_y = bytestream_get_be16(&buf);
  374. ctx->presentation.objects[i].crop_w = bytestream_get_be16(&buf);
  375. ctx->presentation.objects[i].crop_h = bytestream_get_be16(&buf);
  376. }
  377. av_dlog(avctx, "Subtitle Placement x=%d, y=%d\n",
  378. ctx->presentation.objects[i].x, ctx->presentation.objects[i].y);
  379. if (ctx->presentation.objects[i].x > avctx->width ||
  380. ctx->presentation.objects[i].y > avctx->height) {
  381. av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
  382. ctx->presentation.objects[i].x,
  383. ctx->presentation.objects[i].y,
  384. avctx->width, avctx->height);
  385. ctx->presentation.objects[i].x = 0;
  386. ctx->presentation.objects[i].y = 0;
  387. if (avctx->err_recognition & AV_EF_EXPLODE) {
  388. return AVERROR_INVALIDDATA;
  389. }
  390. }
  391. }
  392. return 0;
  393. }
  394. /**
  395. * Parse the display segment packet.
  396. *
  397. * The display segment controls the updating of the display.
  398. *
  399. * @param avctx contains the current codec context
  400. * @param data pointer to the data pertaining the subtitle to display
  401. * @param buf pointer to the packet to process
  402. * @param buf_size size of packet to process
  403. */
  404. static int display_end_segment(AVCodecContext *avctx, void *data,
  405. const uint8_t *buf, int buf_size)
  406. {
  407. AVSubtitle *sub = data;
  408. PGSSubContext *ctx = avctx->priv_data;
  409. int64_t pts;
  410. PGSSubPalette *palette;
  411. int i, ret;
  412. pts = ctx->presentation.pts != AV_NOPTS_VALUE ? ctx->presentation.pts : sub->pts;
  413. memset(sub, 0, sizeof(*sub));
  414. sub->pts = pts;
  415. ctx->presentation.pts = AV_NOPTS_VALUE;
  416. sub->start_display_time = 0;
  417. // There is no explicit end time for PGS subtitles. The end time
  418. // is defined by the start of the next sub which may contain no
  419. // objects (i.e. clears the previous sub)
  420. sub->end_display_time = UINT32_MAX;
  421. sub->format = 0;
  422. // Blank if last object_count was 0.
  423. if (!ctx->presentation.object_count)
  424. return 1;
  425. sub->rects = av_mallocz(sizeof(*sub->rects) * ctx->presentation.object_count);
  426. if (!sub->rects) {
  427. return AVERROR(ENOMEM);
  428. }
  429. palette = find_palette(ctx->presentation.palette_id, &ctx->palettes);
  430. if (!palette) {
  431. // Missing palette. Should only happen with damaged streams.
  432. av_log(avctx, AV_LOG_ERROR, "Invalid palette id %d\n",
  433. ctx->presentation.palette_id);
  434. avsubtitle_free(sub);
  435. return AVERROR_INVALIDDATA;
  436. }
  437. for (i = 0; i < ctx->presentation.object_count; i++) {
  438. PGSSubObject *object;
  439. sub->rects[i] = av_mallocz(sizeof(*sub->rects[0]));
  440. if (!sub->rects[i]) {
  441. avsubtitle_free(sub);
  442. return AVERROR(ENOMEM);
  443. }
  444. sub->num_rects++;
  445. sub->rects[i]->type = SUBTITLE_BITMAP;
  446. /* Process bitmap */
  447. object = find_object(ctx->presentation.objects[i].id, &ctx->objects);
  448. if (!object) {
  449. // Missing object. Should only happen with damaged streams.
  450. av_log(avctx, AV_LOG_ERROR, "Invalid object id %d\n",
  451. ctx->presentation.objects[i].id);
  452. if (avctx->err_recognition & AV_EF_EXPLODE) {
  453. avsubtitle_free(sub);
  454. return AVERROR_INVALIDDATA;
  455. }
  456. // Leaves rect empty with 0 width and height.
  457. continue;
  458. }
  459. if (ctx->presentation.objects[i].composition_flag & 0x40)
  460. sub->rects[i]->flags |= AV_SUBTITLE_FLAG_FORCED;
  461. sub->rects[i]->x = ctx->presentation.objects[i].x;
  462. sub->rects[i]->y = ctx->presentation.objects[i].y;
  463. sub->rects[i]->w = object->w;
  464. sub->rects[i]->h = object->h;
  465. sub->rects[i]->pict.linesize[0] = object->w;
  466. if (object->rle) {
  467. if (object->rle_remaining_len) {
  468. av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n",
  469. object->rle_data_len, object->rle_remaining_len);
  470. if (avctx->err_recognition & AV_EF_EXPLODE) {
  471. avsubtitle_free(sub);
  472. return AVERROR_INVALIDDATA;
  473. }
  474. }
  475. ret = decode_rle(avctx, sub->rects[i], object->rle, object->rle_data_len);
  476. if (ret < 0) {
  477. if ((avctx->err_recognition & AV_EF_EXPLODE) ||
  478. ret == AVERROR(ENOMEM)) {
  479. avsubtitle_free(sub);
  480. return ret;
  481. }
  482. sub->rects[i]->w = 0;
  483. sub->rects[i]->h = 0;
  484. continue;
  485. }
  486. }
  487. /* Allocate memory for colors */
  488. sub->rects[i]->nb_colors = 256;
  489. sub->rects[i]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
  490. if (!sub->rects[i]->pict.data[1]) {
  491. avsubtitle_free(sub);
  492. return AVERROR(ENOMEM);
  493. }
  494. if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40)
  495. memcpy(sub->rects[i]->pict.data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t));
  496. }
  497. return 1;
  498. }
  499. static int decode(AVCodecContext *avctx, void *data, int *data_size,
  500. AVPacket *avpkt)
  501. {
  502. const uint8_t *buf = avpkt->data;
  503. int buf_size = avpkt->size;
  504. AVSubtitle *sub = data;
  505. const uint8_t *buf_end;
  506. uint8_t segment_type;
  507. int segment_length;
  508. int i, ret;
  509. av_dlog(avctx, "PGS sub packet:\n");
  510. for (i = 0; i < buf_size; i++) {
  511. av_dlog(avctx, "%02x ", buf[i]);
  512. if (i % 16 == 15)
  513. av_dlog(avctx, "\n");
  514. }
  515. if (i & 15)
  516. av_dlog(avctx, "\n");
  517. *data_size = 0;
  518. /* Ensure that we have received at a least a segment code and segment length */
  519. if (buf_size < 3)
  520. return -1;
  521. buf_end = buf + buf_size;
  522. /* Step through buffer to identify segments */
  523. while (buf < buf_end) {
  524. segment_type = bytestream_get_byte(&buf);
  525. segment_length = bytestream_get_be16(&buf);
  526. av_dlog(avctx, "Segment Length %d, Segment Type %x\n", segment_length, segment_type);
  527. if (segment_type != DISPLAY_SEGMENT && segment_length > buf_end - buf)
  528. break;
  529. ret = 0;
  530. switch (segment_type) {
  531. case PALETTE_SEGMENT:
  532. ret = parse_palette_segment(avctx, buf, segment_length);
  533. break;
  534. case OBJECT_SEGMENT:
  535. ret = parse_object_segment(avctx, buf, segment_length);
  536. break;
  537. case PRESENTATION_SEGMENT:
  538. ret = parse_presentation_segment(avctx, buf, segment_length, avpkt->pts);
  539. break;
  540. case WINDOW_SEGMENT:
  541. /*
  542. * Window Segment Structure (No new information provided):
  543. * 2 bytes: Unknown,
  544. * 2 bytes: X position of subtitle,
  545. * 2 bytes: Y position of subtitle,
  546. * 2 bytes: Width of subtitle,
  547. * 2 bytes: Height of subtitle.
  548. */
  549. break;
  550. case DISPLAY_SEGMENT:
  551. ret = display_end_segment(avctx, data, buf, segment_length);
  552. if (ret >= 0)
  553. *data_size = ret;
  554. break;
  555. default:
  556. av_log(avctx, AV_LOG_ERROR, "Unknown subtitle segment type 0x%x, length %d\n",
  557. segment_type, segment_length);
  558. ret = AVERROR_INVALIDDATA;
  559. break;
  560. }
  561. if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
  562. return ret;
  563. buf += segment_length;
  564. }
  565. return buf_size;
  566. }
  567. #define OFFSET(x) offsetof(PGSSubContext, x)
  568. #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
  569. static const AVOption options[] = {
  570. {"forced_subs_only", "Only show forced subtitles", OFFSET(forced_subs_only), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, SD},
  571. { NULL },
  572. };
  573. static const AVClass pgsdec_class = {
  574. .class_name = "PGS subtitle decoder",
  575. .item_name = av_default_item_name,
  576. .option = options,
  577. .version = LIBAVUTIL_VERSION_INT,
  578. };
  579. AVCodec ff_pgssub_decoder = {
  580. .name = "pgssub",
  581. .long_name = NULL_IF_CONFIG_SMALL("HDMV Presentation Graphic Stream subtitles"),
  582. .type = AVMEDIA_TYPE_SUBTITLE,
  583. .id = AV_CODEC_ID_HDMV_PGS_SUBTITLE,
  584. .priv_data_size = sizeof(PGSSubContext),
  585. .init = init_decoder,
  586. .close = close_decoder,
  587. .decode = decode,
  588. .priv_class = &pgsdec_class,
  589. };