Libav
pgssubdec.c
Go to the documentation of this file.
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 
27 #include "avcodec.h"
28 #include "bytestream.h"
29 #include "internal.h"
30 #include "mathops.h"
31 
32 #include "libavutil/colorspace.h"
33 #include "libavutil/imgutils.h"
34 
35 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
36 #define MAX_EPOCH_PALETTES 8 // Max 8 allowed per PGS epoch
37 #define MAX_EPOCH_OBJECTS 64 // Max 64 allowed per PGS epoch
38 #define MAX_OBJECT_REFS 2 // Max objects per display set
39 
46 };
47 
48 typedef struct PGSSubObjectRef {
49  int id;
50  int window_id;
52  int x;
53  int y;
54  int crop_x;
55  int crop_y;
56  int crop_w;
57  int crop_h;
59 
60 typedef struct PGSSubPresentation {
61  int id_number;
65  int64_t pts;
67 
68 typedef struct PGSSubObject {
69  int id;
70  int w;
71  int h;
74  unsigned int rle_remaining_len;
75 } PGSSubObject;
76 
77 typedef struct PGSSubObjects {
78  int count;
81 
82 typedef struct PGSSubPalette {
83  int id;
84  uint32_t clut[256];
86 
87 typedef struct PGSSubPalettes {
88  int count;
91 
92 typedef struct PGSSubContext {
97 
98 static void flush_cache(AVCodecContext *avctx)
99 {
100  PGSSubContext *ctx = avctx->priv_data;
101  int i;
102 
103  for (i = 0; i < ctx->objects.count; i++) {
104  av_freep(&ctx->objects.object[i].rle);
105  ctx->objects.object[i].rle_buffer_size = 0;
106  ctx->objects.object[i].rle_remaining_len = 0;
107  }
108  ctx->objects.count = 0;
109  ctx->palettes.count = 0;
110 }
111 
112 static PGSSubObject * find_object(int id, PGSSubObjects *objects)
113 {
114  int i;
115 
116  for (i = 0; i < objects->count; i++) {
117  if (objects->object[i].id == id)
118  return &objects->object[i];
119  }
120  return NULL;
121 }
122 
123 static PGSSubPalette * find_palette(int id, PGSSubPalettes *palettes)
124 {
125  int i;
126 
127  for (i = 0; i < palettes->count; i++) {
128  if (palettes->palette[i].id == id)
129  return &palettes->palette[i];
130  }
131  return NULL;
132 }
133 
135 {
136  avctx->pix_fmt = AV_PIX_FMT_PAL8;
137 
138  return 0;
139 }
140 
142 {
143  flush_cache(avctx);
144 
145  return 0;
146 }
147 
158 static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect,
159  const uint8_t *buf, unsigned int buf_size)
160 {
161  const uint8_t *rle_bitmap_end;
162  int pixel_count, line_count;
163 
164  rle_bitmap_end = buf + buf_size;
165 
166  rect->pict.data[0] = av_malloc(rect->w * rect->h);
167 
168  if (!rect->pict.data[0])
169  return AVERROR(ENOMEM);
170 
171  pixel_count = 0;
172  line_count = 0;
173 
174  while (buf < rle_bitmap_end && line_count < rect->h) {
176  int run;
177 
178  color = bytestream_get_byte(&buf);
179  run = 1;
180 
181  if (color == 0x00) {
182  flags = bytestream_get_byte(&buf);
183  run = flags & 0x3f;
184  if (flags & 0x40)
185  run = (run << 8) + bytestream_get_byte(&buf);
186  color = flags & 0x80 ? bytestream_get_byte(&buf) : 0;
187  }
188 
189  if (run > 0 && pixel_count + run <= rect->w * rect->h) {
190  memset(rect->pict.data[0] + pixel_count, color, run);
191  pixel_count += run;
192  } else if (!run) {
193  /*
194  * New Line. Check if correct pixels decoded, if not display warning
195  * and adjust bitmap pointer to correct new line position.
196  */
197  if (pixel_count % rect->w > 0) {
198  av_log(avctx, AV_LOG_ERROR, "Decoded %d pixels, when line should be %d pixels\n",
199  pixel_count % rect->w, rect->w);
200  if (avctx->err_recognition & AV_EF_EXPLODE) {
201  return AVERROR_INVALIDDATA;
202  }
203  }
204  line_count++;
205  }
206  }
207 
208  if (pixel_count < rect->w * rect->h) {
209  av_log(avctx, AV_LOG_ERROR, "Insufficient RLE data for subtitle\n");
210  return AVERROR_INVALIDDATA;
211  }
212 
213  av_dlog(avctx, "Pixel Count = %d, Area = %d\n", pixel_count, rect->w * rect->h);
214 
215  return 0;
216 }
217 
229  const uint8_t *buf, int buf_size)
230 {
231  PGSSubContext *ctx = avctx->priv_data;
232  PGSSubObject *object;
233 
234  uint8_t sequence_desc;
235  unsigned int rle_bitmap_len, width, height;
236  int id;
237 
238  if (buf_size <= 4)
239  return AVERROR_INVALIDDATA;
240  buf_size -= 4;
241 
242  id = bytestream_get_be16(&buf);
243  object = find_object(id, &ctx->objects);
244  if (!object) {
245  if (ctx->objects.count >= MAX_EPOCH_OBJECTS) {
246  av_log(avctx, AV_LOG_ERROR, "Too many objects in epoch\n");
247  return AVERROR_INVALIDDATA;
248  }
249  object = &ctx->objects.object[ctx->objects.count++];
250  object->id = id;
251  }
252 
253  /* skip object version number */
254  buf += 1;
255 
256  /* Read the Sequence Description to determine if start of RLE data or appended to previous RLE */
257  sequence_desc = bytestream_get_byte(&buf);
258 
259  if (!(sequence_desc & 0x80)) {
260  /* Additional RLE data */
261  if (buf_size > object->rle_remaining_len)
262  return AVERROR_INVALIDDATA;
263 
264  memcpy(object->rle + object->rle_data_len, buf, buf_size);
265  object->rle_data_len += buf_size;
266  object->rle_remaining_len -= buf_size;
267 
268  return 0;
269  }
270 
271  if (buf_size <= 7)
272  return AVERROR_INVALIDDATA;
273  buf_size -= 7;
274 
275  /* Decode rle bitmap length, stored size includes width/height data */
276  rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
277 
278  if (buf_size > rle_bitmap_len) {
279  av_log(avctx, AV_LOG_ERROR,
280  "Buffer dimension %d larger than the expected RLE data %d\n",
281  buf_size, rle_bitmap_len);
282  return AVERROR_INVALIDDATA;
283  }
284 
285  /* Get bitmap dimensions from data */
286  width = bytestream_get_be16(&buf);
287  height = bytestream_get_be16(&buf);
288 
289  /* Make sure the bitmap is not too large */
290  if (avctx->width < width || avctx->height < height) {
291  av_log(avctx, AV_LOG_ERROR, "Bitmap dimensions larger than video.\n");
292  return AVERROR_INVALIDDATA;
293  }
294 
295  object->w = width;
296  object->h = height;
297 
298  av_fast_malloc(&object->rle, &object->rle_buffer_size, rle_bitmap_len);
299 
300  if (!object->rle)
301  return AVERROR(ENOMEM);
302 
303  memcpy(object->rle, buf, buf_size);
304  object->rle_data_len = buf_size;
305  object->rle_remaining_len = rle_bitmap_len - buf_size;
306 
307  return 0;
308 }
309 
321  const uint8_t *buf, int buf_size)
322 {
323  PGSSubContext *ctx = avctx->priv_data;
324  PGSSubPalette *palette;
325 
326  const uint8_t *buf_end = buf + buf_size;
327  const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
328  int color_id;
329  int y, cb, cr, alpha;
330  int r, g, b, r_add, g_add, b_add;
331  int id;
332 
333  id = bytestream_get_byte(&buf);
334  palette = find_palette(id, &ctx->palettes);
335  if (!palette) {
336  if (ctx->palettes.count >= MAX_EPOCH_PALETTES) {
337  av_log(avctx, AV_LOG_ERROR, "Too many palettes in epoch\n");
338  return AVERROR_INVALIDDATA;
339  }
340  palette = &ctx->palettes.palette[ctx->palettes.count++];
341  palette->id = id;
342  }
343 
344  /* Skip palette version */
345  buf += 1;
346 
347  while (buf < buf_end) {
348  color_id = bytestream_get_byte(&buf);
349  y = bytestream_get_byte(&buf);
350  cr = bytestream_get_byte(&buf);
351  cb = bytestream_get_byte(&buf);
352  alpha = bytestream_get_byte(&buf);
353 
354  /* Default to BT.709 colorspace. In case of <= 576 height use BT.601 */
355  if (avctx->height <= 0 || avctx->height > 576) {
356  YUV_TO_RGB1_CCIR_BT709(cb, cr);
357  } else {
358  YUV_TO_RGB1_CCIR(cb, cr);
359  }
360 
361  YUV_TO_RGB2_CCIR(r, g, b, y);
362 
363  av_dlog(avctx, "Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
364 
365  /* Store color in palette */
366  palette->clut[color_id] = RGBA(r,g,b,alpha);
367  }
368  return 0;
369 }
370 
383  const uint8_t *buf, int buf_size,
384  int64_t pts)
385 {
386  PGSSubContext *ctx = avctx->priv_data;
387 
388  int i, state, ret;
389 
390  // Video descriptor
391  int w = bytestream_get_be16(&buf);
392  int h = bytestream_get_be16(&buf);
393 
394  ctx->presentation.pts = pts;
395 
396  av_dlog(avctx, "Video Dimensions %dx%d\n",
397  w, h);
398  ret = ff_set_dimensions(avctx, w, h);
399  if (ret < 0)
400  return ret;
401 
402  /* Skip 1 bytes of unknown, frame rate */
403  buf++;
404 
405  // Composition descriptor
406  ctx->presentation.id_number = bytestream_get_be16(&buf);
407  /*
408  * state is a 2 bit field that defines pgs epoch boundaries
409  * 00 - Normal, previously defined objects and palettes are still valid
410  * 01 - Acquisition point, previous objects and palettes can be released
411  * 10 - Epoch start, previous objects and palettes can be released
412  * 11 - Epoch continue, previous objects and palettes can be released
413  *
414  * reserved 6 bits discarded
415  */
416  state = bytestream_get_byte(&buf) >> 6;
417  if (state != 0) {
418  flush_cache(avctx);
419  }
420 
421  /*
422  * skip palette_update_flag (0x80),
423  */
424  buf += 1;
425  ctx->presentation.palette_id = bytestream_get_byte(&buf);
426  ctx->presentation.object_count = bytestream_get_byte(&buf);
428  av_log(avctx, AV_LOG_ERROR,
429  "Invalid number of presentation objects %d\n",
431  ctx->presentation.object_count = 2;
432  if (avctx->err_recognition & AV_EF_EXPLODE) {
433  return AVERROR_INVALIDDATA;
434  }
435  }
436 
437  for (i = 0; i < ctx->presentation.object_count; i++)
438  {
439  ctx->presentation.objects[i].id = bytestream_get_be16(&buf);
440  ctx->presentation.objects[i].window_id = bytestream_get_byte(&buf);
441  ctx->presentation.objects[i].composition_flag = bytestream_get_byte(&buf);
442 
443  ctx->presentation.objects[i].x = bytestream_get_be16(&buf);
444  ctx->presentation.objects[i].y = bytestream_get_be16(&buf);
445 
446  // If cropping
447  if (ctx->presentation.objects[i].composition_flag & 0x80) {
448  ctx->presentation.objects[i].crop_x = bytestream_get_be16(&buf);
449  ctx->presentation.objects[i].crop_y = bytestream_get_be16(&buf);
450  ctx->presentation.objects[i].crop_w = bytestream_get_be16(&buf);
451  ctx->presentation.objects[i].crop_h = bytestream_get_be16(&buf);
452  }
453 
454  av_dlog(avctx, "Subtitle Placement x=%d, y=%d\n",
455  ctx->presentation.objects[i].x, ctx->presentation.objects[i].y);
456 
457  if (ctx->presentation.objects[i].x > avctx->width ||
458  ctx->presentation.objects[i].y > avctx->height) {
459  av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
460  ctx->presentation.objects[i].x,
461  ctx->presentation.objects[i].y,
462  avctx->width, avctx->height);
463  ctx->presentation.objects[i].x = 0;
464  ctx->presentation.objects[i].y = 0;
465  if (avctx->err_recognition & AV_EF_EXPLODE) {
466  return AVERROR_INVALIDDATA;
467  }
468  }
469  }
470 
471  return 0;
472 }
473 
484 static int display_end_segment(AVCodecContext *avctx, void *data,
485  const uint8_t *buf, int buf_size)
486 {
487  AVSubtitle *sub = data;
488  PGSSubContext *ctx = avctx->priv_data;
489  PGSSubPalette *palette;
490  int i, ret;
491 
492  memset(sub, 0, sizeof(*sub));
493  sub->pts = ctx->presentation.pts;
494  sub->start_display_time = 0;
495  // There is no explicit end time for PGS subtitles. The end time
496  // is defined by the start of the next sub which may contain no
497  // objects (i.e. clears the previous sub)
498  sub->end_display_time = UINT32_MAX;
499  sub->format = 0;
500 
501  // Blank if last object_count was 0.
502  if (!ctx->presentation.object_count)
503  return 1;
504  sub->rects = av_mallocz(sizeof(*sub->rects) * ctx->presentation.object_count);
505  if (!sub->rects) {
506  return AVERROR(ENOMEM);
507  }
508  palette = find_palette(ctx->presentation.palette_id, &ctx->palettes);
509  if (!palette) {
510  // Missing palette. Should only happen with damaged streams.
511  av_log(avctx, AV_LOG_ERROR, "Invalid palette id %d\n",
512  ctx->presentation.palette_id);
513  avsubtitle_free(sub);
514  return AVERROR_INVALIDDATA;
515  }
516  for (i = 0; i < ctx->presentation.object_count; i++) {
517  PGSSubObject *object;
518 
519  sub->rects[i] = av_mallocz(sizeof(*sub->rects[0]));
520  if (!sub->rects[i]) {
521  avsubtitle_free(sub);
522  return AVERROR(ENOMEM);
523  }
524  sub->num_rects++;
525  sub->rects[i]->type = SUBTITLE_BITMAP;
526 
527  /* Process bitmap */
528  object = find_object(ctx->presentation.objects[i].id, &ctx->objects);
529  if (!object) {
530  // Missing object. Should only happen with damaged streams.
531  av_log(avctx, AV_LOG_ERROR, "Invalid object id %d\n",
532  ctx->presentation.objects[i].id);
533  if (avctx->err_recognition & AV_EF_EXPLODE) {
534  avsubtitle_free(sub);
535  return AVERROR_INVALIDDATA;
536  }
537  // Leaves rect empty with 0 width and height.
538  continue;
539  }
540  if (ctx->presentation.objects[i].composition_flag & 0x40)
541  sub->rects[i]->flags |= AV_SUBTITLE_FLAG_FORCED;
542 
543  sub->rects[i]->x = ctx->presentation.objects[i].x;
544  sub->rects[i]->y = ctx->presentation.objects[i].y;
545  sub->rects[i]->w = object->w;
546  sub->rects[i]->h = object->h;
547 
548  sub->rects[i]->pict.linesize[0] = object->w;
549 
550  if (object->rle) {
551  if (object->rle_remaining_len) {
552  av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n",
553  object->rle_data_len, object->rle_remaining_len);
554  if (avctx->err_recognition & AV_EF_EXPLODE) {
555  avsubtitle_free(sub);
556  return AVERROR_INVALIDDATA;
557  }
558  }
559  ret = decode_rle(avctx, sub->rects[i], object->rle, object->rle_data_len);
560  if (ret < 0) {
561  if ((avctx->err_recognition & AV_EF_EXPLODE) ||
562  ret == AVERROR(ENOMEM)) {
563  avsubtitle_free(sub);
564  return ret;
565  }
566  sub->rects[i]->w = 0;
567  sub->rects[i]->h = 0;
568  continue;
569  }
570  }
571  /* Allocate memory for colors */
572  sub->rects[i]->nb_colors = 256;
573  sub->rects[i]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
574  if (!sub->rects[i]->pict.data[1]) {
575  avsubtitle_free(sub);
576  return AVERROR(ENOMEM);
577  }
578 
579  memcpy(sub->rects[i]->pict.data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t));
580 
581  }
582  return 1;
583 }
584 
585 static int decode(AVCodecContext *avctx, void *data, int *data_size,
586  AVPacket *avpkt)
587 {
588  const uint8_t *buf = avpkt->data;
589  int buf_size = avpkt->size;
590 
591  const uint8_t *buf_end;
592  uint8_t segment_type;
593  int segment_length;
594  int i, ret;
595 
596  av_dlog(avctx, "PGS sub packet:\n");
597 
598  for (i = 0; i < buf_size; i++) {
599  av_dlog(avctx, "%02x ", buf[i]);
600  if (i % 16 == 15)
601  av_dlog(avctx, "\n");
602  }
603 
604  if (i & 15)
605  av_dlog(avctx, "\n");
606 
607  *data_size = 0;
608 
609  /* Ensure that we have received at a least a segment code and segment length */
610  if (buf_size < 3)
611  return -1;
612 
613  buf_end = buf + buf_size;
614 
615  /* Step through buffer to identify segments */
616  while (buf < buf_end) {
617  segment_type = bytestream_get_byte(&buf);
618  segment_length = bytestream_get_be16(&buf);
619 
620  av_dlog(avctx, "Segment Length %d, Segment Type %x\n", segment_length, segment_type);
621 
622  if (segment_type != DISPLAY_SEGMENT && segment_length > buf_end - buf)
623  break;
624 
625  ret = 0;
626  switch (segment_type) {
627  case PALETTE_SEGMENT:
628  ret = parse_palette_segment(avctx, buf, segment_length);
629  break;
630  case OBJECT_SEGMENT:
631  ret = parse_object_segment(avctx, buf, segment_length);
632  break;
634  ret = parse_presentation_segment(avctx, buf, segment_length, avpkt->pts);
635  break;
636  case WINDOW_SEGMENT:
637  /*
638  * Window Segment Structure (No new information provided):
639  * 2 bytes: Unknown,
640  * 2 bytes: X position of subtitle,
641  * 2 bytes: Y position of subtitle,
642  * 2 bytes: Width of subtitle,
643  * 2 bytes: Height of subtitle.
644  */
645  break;
646  case DISPLAY_SEGMENT:
647  ret = display_end_segment(avctx, data, buf, segment_length);
648  if (ret >= 0)
649  *data_size = ret;
650  break;
651  default:
652  av_log(avctx, AV_LOG_ERROR, "Unknown subtitle segment type 0x%x, length %d\n",
653  segment_type, segment_length);
654  ret = AVERROR_INVALIDDATA;
655  break;
656  }
657  if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
658  return ret;
659 
660  buf += segment_length;
661  }
662 
663  return buf_size;
664 }
665 
667  .name = "pgssub",
668  .long_name = NULL_IF_CONFIG_SMALL("HDMV Presentation Graphic Stream subtitles"),
669  .type = AVMEDIA_TYPE_SUBTITLE,
671  .priv_data_size = sizeof(PGSSubContext),
672  .init = init_decoder,
673  .close = close_decoder,
674  .decode = decode,
675 };
#define AVPALETTE_SIZE
Definition: avcodec.h:3051
static int parse_object_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse the picture segment packet.
Definition: pgssubdec.c:228
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
Definition: avcodec.h:3044
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:3075
enum AVCodecID id
Definition: mxfenc.c:84
misc image utilities
static int parse_presentation_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int64_t pts)
Parse the presentation segment packet.
Definition: pgssubdec.c:382
#define YUV_TO_RGB1_CCIR(cb1, cr1)
Definition: colorspace.h:34
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:133
int nb_colors
number of colors in pict, undefined when pict is not set
Definition: avcodec.h:3079
int size
Definition: avcodec.h:974
#define MAX_NEG_CROP
Definition: mathops.h:30
Various defines for YUV<->RGB conversion.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1270
unsigned num_rects
Definition: avcodec.h:3103
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
uint8_t run
Definition: svq3.c:146
AVCodec ff_pgssub_decoder
Definition: pgssubdec.c:666
PGSSubPresentation presentation
Definition: pgssubdec.c:93
AVCodec.
Definition: avcodec.h:2812
#define MAX_OBJECT_REFS
Definition: pgssubdec.c:38
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVSubtitleRect ** rects
Definition: avcodec.h:3104
int w
width of pict, undefined when pict is not set
Definition: avcodec.h:3077
uint8_t composition_flag
Definition: pgssubdec.c:51
uint8_t
#define av_cold
Definition: attributes.h:66
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: avcodec.h:3043
#define b
Definition: input.c:52
#define YUV_TO_RGB1_CCIR_BT709(cb1, cr1)
Definition: colorspace.h:44
PGSSubObjects objects
Definition: pgssubdec.c:95
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:973
static int flags
Definition: log.c:44
static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
Definition: pgssubdec.c:585
int h
height of pict, undefined when pict is not set
Definition: avcodec.h:3078
#define cm
Definition: dvbsubdec.c:34
static int parse_palette_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse the palette segment packet.
Definition: pgssubdec.c:320
#define r
Definition: input.c:51
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
#define RGBA(r, g, b, a)
Definition: pgssubdec.c:35
int y
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:3076
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
g
Definition: yuv2rgb.c:535
static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, const uint8_t *buf, unsigned int buf_size)
Decode the RLE data.
Definition: pgssubdec.c:158
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:2819
uint32_t end_display_time
Definition: avcodec.h:3102
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:3105
PGSSubObject object[MAX_EPOCH_OBJECTS]
Definition: pgssubdec.c:79
A bitmap, pict will be set.
Definition: avcodec.h:3057
#define AV_SUBTITLE_FLAG_FORCED
Definition: avcodec.h:3072
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2422
AVPicture pict
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3085
static av_cold int close_decoder(AVCodecContext *avctx)
Definition: pgssubdec.c:141
int width
picture width / height.
Definition: avcodec.h:1229
static PGSSubObject * find_object(int id, PGSSubObjects *objects)
Definition: pgssubdec.c:112
uint16_t format
Definition: avcodec.h:3100
#define AV_EF_EXPLODE
Definition: avcodec.h:2433
static av_cold int init_decoder(AVCodecContext *avctx)
Definition: pgssubdec.c:134
static int display_end_segment(AVCodecContext *avctx, void *data, const uint8_t *buf, int buf_size)
Parse the display segment packet.
Definition: pgssubdec.c:484
#define MAX_EPOCH_OBJECTS
Definition: pgssubdec.c:37
NULL
Definition: eval.c:55
static int width
Definition: utils.c:156
Libavcodec external API header.
main external API structure.
Definition: avcodec.h:1050
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
static void flush_cache(AVCodecContext *avctx)
Definition: pgssubdec.c:98
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:1703
PGSSubPalette palette[MAX_EPOCH_PALETTES]
Definition: pgssubdec.c:89
#define YUV_TO_RGB2_CCIR(r, g, b, y1)
Definition: colorspace.h:55
PGSSubObjectRef objects[MAX_OBJECT_REFS]
Definition: pgssubdec.c:64
static uint32_t state
Definition: trasher.c:27
int height
Definition: gxfenc.c:72
uint32_t clut[256]
Definition: pgssubdec.c:84
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:388
unsigned int rle_remaining_len
Definition: pgssubdec.c:74
common internal api header.
unsigned int rle_data_len
Definition: pgssubdec.c:73
uint32_t start_display_time
Definition: avcodec.h:3101
#define ff_crop_tab
static const uint8_t color[]
Definition: log.c:55
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
void * priv_data
Definition: avcodec.h:1092
static PGSSubPalette * find_palette(int id, PGSSubPalettes *palettes)
Definition: pgssubdec.c:123
uint8_t * rle
Definition: pgssubdec.c:72
unsigned int rle_buffer_size
Definition: pgssubdec.c:73
SegmentType
Definition: pgssubdec.c:40
enum AVSubtitleType type
Definition: avcodec.h:3086
This structure stores compressed data.
Definition: avcodec.h:950
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
#define MAX_EPOCH_PALETTES
Definition: pgssubdec.c:36
PGSSubPalettes palettes
Definition: pgssubdec.c:94