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