FFmpeg
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 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 /**
23  * @file
24  * PGS subtitle decoder
25  */
26 
27 #include "avcodec.h"
28 #include "bytestream.h"
29 #include "codec_internal.h"
30 #include "decode.h"
31 #include "mathops.h"
32 
33 #include "libavutil/colorspace.h"
34 #include "libavutil/opt.h"
35 
36 #define RGBA(r,g,b,a) (((unsigned)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
37 #define MAX_EPOCH_PALETTES 8 // Max 8 allowed per PGS epoch
38 #define MAX_EPOCH_OBJECTS 64 // Max 64 allowed per PGS epoch
39 #define MAX_OBJECT_REFS 2 // Max objects per display set
40 
47 };
48 
49 typedef struct PGSSubObjectRef {
50  int id;
51  int window_id;
53  int x;
54  int y;
55  int crop_x;
56  int crop_y;
57  int crop_w;
58  int crop_h;
60 
61 typedef struct PGSSubPresentation {
62  int id_number;
66  int64_t pts;
68 
69 typedef struct PGSSubObject {
70  int id;
71  int w;
72  int h;
73  uint8_t *rle;
75  unsigned int rle_remaining_len;
76 } PGSSubObject;
77 
78 typedef struct PGSSubObjects {
79  int count;
82 
83 typedef struct PGSSubPalette {
84  int id;
85  uint32_t clut[256];
87 
88 typedef struct PGSSubPalettes {
89  int count;
92 
93 typedef struct PGSSubContext {
94  AVClass *class;
100 
101 static void flush_cache(AVCodecContext *avctx)
102 {
103  PGSSubContext *ctx = avctx->priv_data;
104  int i;
105 
106  for (i = 0; i < ctx->objects.count; i++) {
107  av_freep(&ctx->objects.object[i].rle);
108  ctx->objects.object[i].rle_buffer_size = 0;
109  ctx->objects.object[i].rle_remaining_len = 0;
110  }
111  ctx->objects.count = 0;
112  ctx->palettes.count = 0;
113 }
114 
115 static PGSSubObject * find_object(int id, PGSSubObjects *objects)
116 {
117  int i;
118 
119  for (i = 0; i < objects->count; i++) {
120  if (objects->object[i].id == id)
121  return &objects->object[i];
122  }
123  return NULL;
124 }
125 
126 static PGSSubPalette * find_palette(int id, PGSSubPalettes *palettes)
127 {
128  int i;
129 
130  for (i = 0; i < palettes->count; i++) {
131  if (palettes->palette[i].id == id)
132  return &palettes->palette[i];
133  }
134  return NULL;
135 }
136 
138 {
139  avctx->pix_fmt = AV_PIX_FMT_PAL8;
140 
141  return 0;
142 }
143 
145 {
146  flush_cache(avctx);
147 
148  return 0;
149 }
150 
151 /**
152  * Decode the RLE data.
153  *
154  * The subtitle is stored as a Run Length Encoded image.
155  *
156  * @param avctx contains the current codec context
157  * @param sub pointer to the processed subtitle data
158  * @param buf pointer to the RLE data to process
159  * @param buf_size size of the RLE data to process
160  */
162  const uint8_t *buf, unsigned int buf_size)
163 {
164  const uint8_t *rle_bitmap_end;
165  int pixel_count, line_count;
166 
167  rle_bitmap_end = buf + buf_size;
168 
169  rect->data[0] = av_malloc_array(rect->w, rect->h);
170 
171  if (!rect->data[0])
172  return AVERROR(ENOMEM);
173 
174  pixel_count = 0;
175  line_count = 0;
176 
177  while (buf < rle_bitmap_end && line_count < rect->h) {
178  uint8_t flags, color;
179  int run;
180 
181  color = bytestream_get_byte(&buf);
182  run = 1;
183 
184  if (color == 0x00) {
185  flags = bytestream_get_byte(&buf);
186  run = flags & 0x3f;
187  if (flags & 0x40)
188  run = (run << 8) + bytestream_get_byte(&buf);
189  color = flags & 0x80 ? bytestream_get_byte(&buf) : 0;
190  }
191 
192  if (run > 0 && pixel_count + run <= rect->w * rect->h) {
193  memset(rect->data[0] + pixel_count, color, run);
194  pixel_count += run;
195  } else if (!run) {
196  /*
197  * New Line. Check if correct pixels decoded, if not display warning
198  * and adjust bitmap pointer to correct new line position.
199  */
200  if (pixel_count % rect->w > 0) {
201  av_log(avctx, AV_LOG_ERROR, "Decoded %d pixels, when line should be %d pixels\n",
202  pixel_count % rect->w, rect->w);
203  if (avctx->err_recognition & AV_EF_EXPLODE) {
204  return AVERROR_INVALIDDATA;
205  }
206  }
207  line_count++;
208  }
209  }
210 
211  if (pixel_count < rect->w * rect->h) {
212  av_log(avctx, AV_LOG_ERROR, "Insufficient RLE data for subtitle\n");
213  return AVERROR_INVALIDDATA;
214  }
215 
216  ff_dlog(avctx, "Pixel Count = %d, Area = %d\n", pixel_count, rect->w * rect->h);
217 
218  return 0;
219 }
220 
221 /**
222  * Parse the picture segment packet.
223  *
224  * The picture segment contains details on the sequence id,
225  * width, height and Run Length Encoded (RLE) bitmap data.
226  *
227  * @param avctx contains the current codec context
228  * @param buf pointer to the packet to process
229  * @param buf_size size of packet to process
230  */
232  const uint8_t *buf, int buf_size)
233 {
234  PGSSubContext *ctx = avctx->priv_data;
235  PGSSubObject *object;
236 
237  uint8_t sequence_desc;
238  unsigned int rle_bitmap_len, width, height;
239  int id;
240 
241  if (buf_size <= 4)
242  return AVERROR_INVALIDDATA;
243  buf_size -= 4;
244 
245  id = bytestream_get_be16(&buf);
246  object = find_object(id, &ctx->objects);
247  if (!object) {
248  if (ctx->objects.count >= MAX_EPOCH_OBJECTS) {
249  av_log(avctx, AV_LOG_ERROR, "Too many objects in epoch\n");
250  return AVERROR_INVALIDDATA;
251  }
252  object = &ctx->objects.object[ctx->objects.count++];
253  object->id = id;
254  }
255 
256  /* skip object version number */
257  buf += 1;
258 
259  /* Read the Sequence Description to determine if start of RLE data or appended to previous RLE */
260  sequence_desc = bytestream_get_byte(&buf);
261 
262  if (!(sequence_desc & 0x80)) {
263  /* Additional RLE data */
264  if (buf_size > object->rle_remaining_len)
265  return AVERROR_INVALIDDATA;
266 
267  memcpy(object->rle + object->rle_data_len, buf, buf_size);
268  object->rle_data_len += buf_size;
269  object->rle_remaining_len -= buf_size;
270 
271  return 0;
272  }
273 
274  if (buf_size <= 7)
275  return AVERROR_INVALIDDATA;
276  buf_size -= 7;
277 
278  /* Decode rle bitmap length, stored size includes width/height data */
279  rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
280 
281  if (buf_size > rle_bitmap_len) {
282  av_log(avctx, AV_LOG_ERROR,
283  "Buffer dimension %d larger than the expected RLE data %d\n",
284  buf_size, rle_bitmap_len);
285  return AVERROR_INVALIDDATA;
286  }
287 
288  /* Get bitmap dimensions from data */
289  width = bytestream_get_be16(&buf);
290  height = bytestream_get_be16(&buf);
291 
292  /* Make sure the bitmap is not too large */
293  if (avctx->width < width || avctx->height < height || !width || !height) {
294  av_log(avctx, AV_LOG_ERROR, "Bitmap dimensions (%dx%d) invalid.\n", width, height);
295  return AVERROR_INVALIDDATA;
296  }
297 
298  object->w = width;
299  object->h = height;
300 
301  av_fast_padded_malloc(&object->rle, &object->rle_buffer_size, rle_bitmap_len);
302 
303  if (!object->rle) {
304  object->rle_data_len = 0;
305  object->rle_remaining_len = 0;
306  return AVERROR(ENOMEM);
307  }
308 
309  memcpy(object->rle, buf, buf_size);
310  object->rle_data_len = buf_size;
311  object->rle_remaining_len = rle_bitmap_len - buf_size;
312 
313  return 0;
314 }
315 
316 /**
317  * Parse the palette segment packet.
318  *
319  * The palette segment contains details of the palette,
320  * a maximum of 256 colors can be defined.
321  *
322  * @param avctx contains the current codec context
323  * @param buf pointer to the packet to process
324  * @param buf_size size of packet to process
325  */
327  const uint8_t *buf, int buf_size)
328 {
329  PGSSubContext *ctx = avctx->priv_data;
330  PGSSubPalette *palette;
331 
332  const uint8_t *buf_end = buf + buf_size;
333  const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
334  int color_id;
335  int y, cb, cr, alpha;
336  int r, g, b, r_add, g_add, b_add;
337  int id;
338 
339  id = bytestream_get_byte(&buf);
340  palette = find_palette(id, &ctx->palettes);
341  if (!palette) {
342  if (ctx->palettes.count >= MAX_EPOCH_PALETTES) {
343  av_log(avctx, AV_LOG_ERROR, "Too many palettes in epoch\n");
344  return AVERROR_INVALIDDATA;
345  }
346  palette = &ctx->palettes.palette[ctx->palettes.count++];
347  palette->id = id;
348  }
349 
350  /* Skip palette version */
351  buf += 1;
352 
353  while (buf < buf_end) {
354  color_id = bytestream_get_byte(&buf);
355  y = bytestream_get_byte(&buf);
356  cr = bytestream_get_byte(&buf);
357  cb = bytestream_get_byte(&buf);
358  alpha = bytestream_get_byte(&buf);
359 
360  /* Default to BT.709 colorspace. In case of <= 576 height use BT.601 */
361  if (avctx->height <= 0 || avctx->height > 576) {
363  } else {
365  }
366 
367  YUV_TO_RGB2_CCIR(r, g, b, y);
368 
369  ff_dlog(avctx, "Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
370 
371  /* Store color in palette */
372  palette->clut[color_id] = RGBA(r,g,b,alpha);
373  }
374  return 0;
375 }
376 
377 /**
378  * Parse the presentation segment packet.
379  *
380  * The presentation segment contains details on the video
381  * width, video height, x & y subtitle position.
382  *
383  * @param avctx contains the current codec context
384  * @param buf pointer to the packet to process
385  * @param buf_size size of packet to process
386  * @todo TODO: Implement cropping
387  */
389  const uint8_t *buf, int buf_size,
390  int64_t pts)
391 {
392  PGSSubContext *ctx = avctx->priv_data;
393  int i, state, ret;
394  const uint8_t *buf_end = buf + buf_size;
395 
396  // Video descriptor
397  int w = bytestream_get_be16(&buf);
398  int h = bytestream_get_be16(&buf);
399 
400  ctx->presentation.pts = pts;
401 
402  ff_dlog(avctx, "Video Dimensions %dx%d\n",
403  w, h);
404  ret = ff_set_dimensions(avctx, w, h);
405  if (ret < 0)
406  return ret;
407 
408  /* Skip 1 bytes of unknown, frame rate */
409  buf++;
410 
411  // Composition descriptor
412  ctx->presentation.id_number = bytestream_get_be16(&buf);
413  /*
414  * state is a 2 bit field that defines pgs epoch boundaries
415  * 00 - Normal, previously defined objects and palettes are still valid
416  * 01 - Acquisition point, previous objects and palettes can be released
417  * 10 - Epoch start, previous objects and palettes can be released
418  * 11 - Epoch continue, previous objects and palettes can be released
419  *
420  * reserved 6 bits discarded
421  */
422  state = bytestream_get_byte(&buf) >> 6;
423  if (state != 0) {
424  flush_cache(avctx);
425  }
426 
427  /*
428  * skip palette_update_flag (0x80),
429  */
430  buf += 1;
431  ctx->presentation.palette_id = bytestream_get_byte(&buf);
432  ctx->presentation.object_count = bytestream_get_byte(&buf);
433  if (ctx->presentation.object_count > MAX_OBJECT_REFS) {
434  av_log(avctx, AV_LOG_ERROR,
435  "Invalid number of presentation objects %d\n",
436  ctx->presentation.object_count);
437  ctx->presentation.object_count = 2;
438  if (avctx->err_recognition & AV_EF_EXPLODE) {
439  return AVERROR_INVALIDDATA;
440  }
441  }
442 
443 
444  for (i = 0; i < ctx->presentation.object_count; i++)
445  {
446  PGSSubObjectRef *const object = &ctx->presentation.objects[i];
447 
448  if (buf_end - buf < 8) {
449  av_log(avctx, AV_LOG_ERROR, "Insufficent space for object\n");
450  ctx->presentation.object_count = i;
451  return AVERROR_INVALIDDATA;
452  }
453 
454  object->id = bytestream_get_be16(&buf);
455  object->window_id = bytestream_get_byte(&buf);
456  object->composition_flag = bytestream_get_byte(&buf);
457 
458  object->x = bytestream_get_be16(&buf);
459  object->y = bytestream_get_be16(&buf);
460 
461  // If cropping
462  if (object->composition_flag & 0x80) {
463  object->crop_x = bytestream_get_be16(&buf);
464  object->crop_y = bytestream_get_be16(&buf);
465  object->crop_w = bytestream_get_be16(&buf);
466  object->crop_h = bytestream_get_be16(&buf);
467  }
468 
469  ff_dlog(avctx, "Subtitle Placement x=%d, y=%d\n",
470  object->x, object->y);
471 
472  if (object->x > avctx->width || object->y > avctx->height) {
473  av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
474  object->x, object->y,
475  avctx->width, avctx->height);
476  object->y = object->x = 0;
477  if (avctx->err_recognition & AV_EF_EXPLODE) {
478  return AVERROR_INVALIDDATA;
479  }
480  }
481  }
482 
483  return 0;
484 }
485 
486 /**
487  * Parse the display segment packet.
488  *
489  * The display segment controls the updating of the display.
490  *
491  * @param avctx contains the current codec context
492  * @param data pointer to the data pertaining the subtitle to display
493  * @param buf pointer to the packet to process
494  * @param buf_size size of packet to process
495  */
497  const uint8_t *buf, int buf_size)
498 {
499  PGSSubContext *ctx = avctx->priv_data;
500  int64_t pts;
501  PGSSubPalette *palette;
502  int i, ret;
503 
504  pts = ctx->presentation.pts != AV_NOPTS_VALUE ? ctx->presentation.pts : sub->pts;
505  memset(sub, 0, sizeof(*sub));
506  sub->pts = pts;
507  ctx->presentation.pts = AV_NOPTS_VALUE;
508  sub->start_display_time = 0;
509  // There is no explicit end time for PGS subtitles. The end time
510  // is defined by the start of the next sub which may contain no
511  // objects (i.e. clears the previous sub)
512  sub->end_display_time = UINT32_MAX;
513  sub->format = 0;
514 
515  // Blank if last object_count was 0.
516  if (!ctx->presentation.object_count)
517  return 1;
518  sub->rects = av_calloc(ctx->presentation.object_count, sizeof(*sub->rects));
519  if (!sub->rects) {
520  return AVERROR(ENOMEM);
521  }
522  palette = find_palette(ctx->presentation.palette_id, &ctx->palettes);
523  if (!palette) {
524  // Missing palette. Should only happen with damaged streams.
525  av_log(avctx, AV_LOG_ERROR, "Invalid palette id %d\n",
526  ctx->presentation.palette_id);
528  return AVERROR_INVALIDDATA;
529  }
530  for (i = 0; i < ctx->presentation.object_count; i++) {
531  AVSubtitleRect *const rect = av_mallocz(sizeof(*rect));
532  PGSSubObject *object;
533 
534  if (!rect)
535  return AVERROR(ENOMEM);
536  sub->rects[sub->num_rects++] = rect;
537  rect->type = SUBTITLE_BITMAP;
538 
539  /* Process bitmap */
540  object = find_object(ctx->presentation.objects[i].id, &ctx->objects);
541  if (!object) {
542  // Missing object. Should only happen with damaged streams.
543  av_log(avctx, AV_LOG_ERROR, "Invalid object id %d\n",
544  ctx->presentation.objects[i].id);
545  if (avctx->err_recognition & AV_EF_EXPLODE)
546  return AVERROR_INVALIDDATA;
547  // Leaves rect empty with 0 width and height.
548  continue;
549  }
550  if (ctx->presentation.objects[i].composition_flag & 0x40)
551  rect->flags |= AV_SUBTITLE_FLAG_FORCED;
552 
553  rect->x = ctx->presentation.objects[i].x;
554  rect->y = ctx->presentation.objects[i].y;
555 
556  if (object->rle) {
557  rect->w = object->w;
558  rect->h = object->h;
559 
560  rect->linesize[0] = object->w;
561 
562  if (object->rle_remaining_len) {
563  av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n",
564  object->rle_data_len, object->rle_remaining_len);
565  if (avctx->err_recognition & AV_EF_EXPLODE)
566  return AVERROR_INVALIDDATA;
567  }
568  ret = decode_rle(avctx, rect, object->rle, object->rle_data_len);
569  if (ret < 0) {
570  if ((avctx->err_recognition & AV_EF_EXPLODE) ||
571  ret == AVERROR(ENOMEM)) {
572  return ret;
573  }
574  rect->w = 0;
575  rect->h = 0;
576  continue;
577  }
578  }
579  /* Allocate memory for colors */
580  rect->nb_colors = 256;
581  rect->data[1] = av_mallocz(AVPALETTE_SIZE);
582  if (!rect->data[1])
583  return AVERROR(ENOMEM);
584 
585  if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40)
586  memcpy(rect->data[1], palette->clut, rect->nb_colors * sizeof(uint32_t));
587  }
588  return 1;
589 }
590 
591 static int decode(AVCodecContext *avctx, AVSubtitle *sub,
592  int *got_sub_ptr, const AVPacket *avpkt)
593 {
594  const uint8_t *buf = avpkt->data;
595  int buf_size = avpkt->size;
596 
597  const uint8_t *buf_end;
598  uint8_t segment_type;
599  int segment_length;
600  int i, ret;
601 
602  ff_dlog(avctx, "PGS sub packet:\n");
603 
604  for (i = 0; i < buf_size; i++) {
605  ff_dlog(avctx, "%02x ", buf[i]);
606  if (i % 16 == 15)
607  ff_dlog(avctx, "\n");
608  }
609 
610  if (i & 15)
611  ff_dlog(avctx, "\n");
612 
613  *got_sub_ptr = 0;
614 
615  /* Ensure that we have received at a least a segment code and segment length */
616  if (buf_size < 3)
617  return -1;
618 
619  buf_end = buf + buf_size;
620 
621  /* Step through buffer to identify segments */
622  while (buf < buf_end) {
623  segment_type = bytestream_get_byte(&buf);
624  segment_length = bytestream_get_be16(&buf);
625 
626  ff_dlog(avctx, "Segment Length %d, Segment Type %x\n", segment_length, segment_type);
627 
628  if (segment_type != DISPLAY_SEGMENT && segment_length > buf_end - buf)
629  break;
630 
631  ret = 0;
632  switch (segment_type) {
633  case PALETTE_SEGMENT:
634  ret = parse_palette_segment(avctx, buf, segment_length);
635  break;
636  case OBJECT_SEGMENT:
637  ret = parse_object_segment(avctx, buf, segment_length);
638  break;
640  ret = parse_presentation_segment(avctx, buf, segment_length, sub->pts);
641  break;
642  case WINDOW_SEGMENT:
643  /*
644  * Window Segment Structure (No new information provided):
645  * 2 bytes: Unknown,
646  * 2 bytes: X position of subtitle,
647  * 2 bytes: Y position of subtitle,
648  * 2 bytes: Width of subtitle,
649  * 2 bytes: Height of subtitle.
650  */
651  break;
652  case DISPLAY_SEGMENT:
653  if (*got_sub_ptr) {
654  av_log(avctx, AV_LOG_ERROR, "Duplicate display segment\n");
656  break;
657  }
658  ret = display_end_segment(avctx, sub, buf, segment_length);
659  if (ret >= 0)
660  *got_sub_ptr = ret;
661  break;
662  default:
663  av_log(avctx, AV_LOG_ERROR, "Unknown subtitle segment type 0x%x, length %d\n",
664  segment_type, segment_length);
666  break;
667  }
668  if (ret < 0 && (ret == AVERROR(ENOMEM) ||
669  avctx->err_recognition & AV_EF_EXPLODE))
670  return ret;
671 
672  buf += segment_length;
673  }
674 
675  return buf_size;
676 }
677 
678 #define OFFSET(x) offsetof(PGSSubContext, x)
679 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
680 static const AVOption options[] = {
681  {"forced_subs_only", "Only show forced subtitles", OFFSET(forced_subs_only), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, SD},
682  { NULL },
683 };
684 
685 static const AVClass pgsdec_class = {
686  .class_name = "PGS subtitle decoder",
687  .item_name = av_default_item_name,
688  .option = options,
689  .version = LIBAVUTIL_VERSION_INT,
690 };
691 
693  .p.name = "pgssub",
694  CODEC_LONG_NAME("HDMV Presentation Graphic Stream subtitles"),
695  .p.type = AVMEDIA_TYPE_SUBTITLE,
697  .priv_data_size = sizeof(PGSSubContext),
698  .init = init_decoder,
699  .close = close_decoder,
701  .p.priv_class = &pgsdec_class,
702 };
AVSubtitle
Definition: avcodec.h:2330
rect::w
int w
Definition: f_ebur128.c:76
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
PGSSubObjectRef
Definition: pgssubdec.c:49
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
r
const char * r
Definition: vf_curves.c:126
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
color
Definition: vf_paletteuse.c:509
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:239
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
init_decoder
static av_cold int init_decoder(AVCodecContext *avctx)
Definition: pgssubdec.c:137
rect
Definition: f_ebur128.c:76
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1382
PGSSubObjects
Definition: pgssubdec.c:78
AVSubtitleRect
Definition: avcodec.h:2302
PGSSubObject
Definition: pgssubdec.c:69
rect::y
int y
Definition: f_ebur128.c:76
PGSSubObjectRef::y
int y
Definition: pgssubdec.c:54
w
uint8_t w
Definition: llviddspenc.c:38
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVOption
AVOption.
Definition: opt.h:251
b
#define b
Definition: input.c:41
PGSSubContext::objects
PGSSubObjects objects
Definition: pgssubdec.c:97
options
static const AVOption options[]
Definition: pgssubdec.c:680
PALETTE_SEGMENT
@ PALETTE_SEGMENT
Definition: pgssubdec.c:42
FFCodec
Definition: codec_internal.h:127
YUV_TO_RGB1_CCIR
#define YUV_TO_RGB1_CCIR(cb1, cr1)
Definition: colorspace.h:34
AV_CODEC_ID_HDMV_PGS_SUBTITLE
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
Definition: codec_id.h:550
ff_set_dimensions
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:91
parse_presentation_segment
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:388
ff_crop_tab
#define ff_crop_tab
Definition: motionpixels_tablegen.c:26
PGSSubObjectRef::crop_h
int crop_h
Definition: pgssubdec.c:58
find_object
static PGSSubObject * find_object(int id, PGSSubObjects *objects)
Definition: pgssubdec.c:115
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
PGSSubPalette
Definition: pgssubdec.c:83
pts
static int64_t pts
Definition: transcode_aac.c:653
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:409
colorspace.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
parse_object_segment
static int parse_object_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse the picture segment packet.
Definition: pgssubdec.c:231
PGSSubPalettes::palette
PGSSubPalette palette[MAX_EPOCH_PALETTES]
Definition: pgssubdec.c:90
YUV_TO_RGB1_CCIR_BT709
#define YUV_TO_RGB1_CCIR_BT709(cb1, cr1)
Definition: colorspace.h:44
width
#define width
PGSSubPalettes
Definition: pgssubdec.c:88
g
const char * g
Definition: vf_curves.c:127
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
OFFSET
#define OFFSET(x)
Definition: pgssubdec.c:678
ctx
AVFormatContext * ctx
Definition: movenc.c:48
decode.h
PGSSubPresentation::id_number
int id_number
Definition: pgssubdec.c:62
PGSSubObjects::object
PGSSubObject object[MAX_EPOCH_OBJECTS]
Definition: pgssubdec.c:80
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
PGSSubObjects::count
int count
Definition: pgssubdec.c:79
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
display_end_segment
static int display_end_segment(AVCodecContext *avctx, AVSubtitle *sub, const uint8_t *buf, int buf_size)
Parse the display segment packet.
Definition: pgssubdec.c:496
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:203
PGSSubObjectRef::composition_flag
uint8_t composition_flag
Definition: pgssubdec.c:52
PRESENTATION_SEGMENT
@ PRESENTATION_SEGMENT
Definition: pgssubdec.c:44
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
mathops.h
MAX_OBJECT_REFS
#define MAX_OBJECT_REFS
Definition: pgssubdec.c:39
DISPLAY_SEGMENT
@ DISPLAY_SEGMENT
Definition: pgssubdec.c:46
YUV_TO_RGB2_CCIR
#define YUV_TO_RGB2_CCIR(r, g, b, y1)
Definition: colorspace.h:55
decode
static int decode(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Definition: pgssubdec.c:591
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
PGSSubObject::rle
uint8_t * rle
Definition: pgssubdec.c:73
find_palette
static PGSSubPalette * find_palette(int id, PGSSubPalettes *palettes)
Definition: pgssubdec.c:126
PGSSubContext::presentation
PGSSubPresentation presentation
Definition: pgssubdec.c:95
AVPacket::size
int size
Definition: packet.h:375
codec_internal.h
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
PGSSubPresentation::palette_id
int palette_id
Definition: pgssubdec.c:63
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
rect::h
int h
Definition: f_ebur128.c:76
PGSSubObjectRef::crop_w
int crop_w
Definition: pgssubdec.c:57
SegmentType
SegmentType
Definition: pgssubdec.c:41
height
#define height
PGSSubPalette::clut
uint32_t clut[256]
Definition: pgssubdec.c:85
rect::x
int x
Definition: f_ebur128.c:76
AV_SUBTITLE_FLAG_FORCED
#define AV_SUBTITLE_FLAG_FORCED
Definition: avcodec.h:2300
SUBTITLE_BITMAP
@ SUBTITLE_BITMAP
A bitmap, pict will be set.
Definition: avcodec.h:2285
PGSSubPresentation
Definition: pgssubdec.c:61
PGSSubPresentation::object_count
int object_count
Definition: pgssubdec.c:64
PGSSubContext::forced_subs_only
int forced_subs_only
Definition: pgssubdec.c:98
MAX_EPOCH_PALETTES
#define MAX_EPOCH_PALETTES
Definition: pgssubdec.c:37
PGSSubObject::rle_remaining_len
unsigned int rle_remaining_len
Definition: pgssubdec.c:75
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
PGSSubObject::rle_data_len
unsigned int rle_data_len
Definition: pgssubdec.c:74
PGSSubPresentation::objects
PGSSubObjectRef objects[MAX_OBJECT_REFS]
Definition: pgssubdec.c:65
ff_pgssub_decoder
const FFCodec ff_pgssub_decoder
Definition: pgssubdec.c:692
PGSSubPalette::id
int id
Definition: pgssubdec.c:84
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
WINDOW_SEGMENT
@ WINDOW_SEGMENT
Definition: pgssubdec.c:45
PGSSubPresentation::pts
int64_t pts
Definition: pgssubdec.c:66
av_fast_padded_malloc
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:49
decode_rle
static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, const uint8_t *buf, unsigned int buf_size)
Decode the RLE data.
Definition: pgssubdec.c:161
MAX_EPOCH_OBJECTS
#define MAX_EPOCH_OBJECTS
Definition: pgssubdec.c:38
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:191
PGSSubObjectRef::id
int id
Definition: pgssubdec.c:50
AVCodecContext::height
int height
Definition: avcodec.h:598
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:635
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
avcodec.h
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
ret
ret
Definition: filter_design.txt:187
SD
#define SD
Definition: pgssubdec.c:679
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
id
enum AVCodecID id
Definition: dts2pts_bsf.c:364
AVCodecContext
main external API structure.
Definition: avcodec.h:426
PGSSubObject::h
int h
Definition: pgssubdec.c:72
PGSSubObject::w
int w
Definition: pgssubdec.c:71
PGSSubContext
Definition: pgssubdec.c:93
PGSSubObjectRef::window_id
int window_id
Definition: pgssubdec.c:51
PGSSubObjectRef::x
int x
Definition: pgssubdec.c:53
close_decoder
static av_cold int close_decoder(AVCodecContext *avctx)
Definition: pgssubdec.c:144
cm
#define cm
Definition: dvbsubdec.c:39
parse_palette_segment
static int parse_palette_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse the palette segment packet.
Definition: pgssubdec.c:326
FF_CODEC_DECODE_SUB_CB
#define FF_CODEC_DECODE_SUB_CB(func)
Definition: codec_internal.h:309
RGBA
#define RGBA(r, g, b, a)
Definition: pgssubdec.c:36
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
cr
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:240
OBJECT_SEGMENT
@ OBJECT_SEGMENT
Definition: pgssubdec.c:43
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:598
bytestream.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
PGSSubObject::id
int id
Definition: pgssubdec.c:70
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
PGSSubObjectRef::crop_y
int crop_y
Definition: pgssubdec.c:56
PGSSubContext::palettes
PGSSubPalettes palettes
Definition: pgssubdec.c:96
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2038
state
static struct @345 state
MAX_NEG_CROP
#define MAX_NEG_CROP
Definition: mathops.h:31
flush_cache
static void flush_cache(AVCodecContext *avctx)
Definition: pgssubdec.c:101
PGSSubPalettes::count
int count
Definition: pgssubdec.c:89
pgsdec_class
static const AVClass pgsdec_class
Definition: pgssubdec.c:685
PGSSubObject::rle_buffer_size
unsigned int rle_buffer_size
Definition: pgssubdec.c:74
PGSSubObjectRef::crop_x
int crop_x
Definition: pgssubdec.c:55