1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * libdvbsub - DVB subtitle decoding
4 * Copyright (C) Mart Raudsepp 2009 <mart.raudsepp@artecdesign.ee>
6 * Heavily uses code algorithms ported from ffmpeg's libavcodec/dvbsubdec.c,
7 * especially the segment parsers. The original license applies to this
8 * ported code and the whole code in this file as well.
10 * Original copyright information follows:
13 * DVB subtitle decoding for ffmpeg
14 * Copyright (c) 2005 Ian Caulfield
16 * This file is part of FFmpeg.
18 * FFmpeg is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
23 * FFmpeg is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
28 * You should have received a copy of the GNU Lesser General Public
29 * License along with FFmpeg; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <string.h> /* memset */
34 #include <gst/gstutils.h> /* GST_READ_UINT16_BE */
35 #include <gst/base/gstbitreader.h> /* GstBitReader */
36 #include "ffmpeg-colorspace.h" /* YUV_TO_RGB1_CCIR */ /* FIXME: Just give YUV data to gstreamer then? */
40 GST_DEBUG_CATEGORY_STATIC (dvbsub_debug);
41 #define GST_CAT_DEFAULT dvbsub_debug
43 static void dvb_sub_init (void);
45 /* FIXME: Are we waiting for an acquisition point before trying to do things? */
46 /* FIXME: In the end convert some of the guint8/16 (especially stack variables) back to gint for access efficiency */
50 * @short_description: a DVB subtitle parsing class
51 * @stability: Unstable
53 * The #DvbSub represents an object used for parsing a DVB subpicture,
54 * and signalling the API user for new bitmaps to show on screen.
57 #define MAX_NEG_CROP 1024
58 static guint8 ff_cropTbl[256 + 2 * MAX_NEG_CROP] = { 0, };
60 #define cm (ff_cropTbl + MAX_NEG_CROP)
62 /* FIXME: This is really ARGB... We might need this configurable for performant
63 * FIXME: use in GStreamer as well if that likes RGBA more (Qt prefers ARGB) */
64 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
66 typedef struct DVBSubCLUT
68 int id; /* default_clut uses -1 for this, so guint8 isn't fine without adaptations first */
74 struct DVBSubCLUT *next;
77 static DVBSubCLUT default_clut;
79 typedef struct DVBSubObjectDisplay
81 /* FIXME: Use more correct sizes */
91 /* FIXME: Should we use GSList? The relating interaction and pointer assigment is quite complex and perhaps unsuited for a plain GSList anyway */
92 struct DVBSubObjectDisplay *region_list_next;
93 struct DVBSubObjectDisplay *object_list_next;
94 } DVBSubObjectDisplay;
96 typedef struct DVBSubObject
98 /* FIXME: Use more correct sizes */
99 int id; /* FIXME: Use guint8 after checking it's fine in all code using it */
103 /* FIXME: Should we use GSList? */
104 DVBSubObjectDisplay *display_list;
105 struct DVBSubObject *next;
108 typedef struct DVBSubRegionDisplay
109 { /* FIXME: Figure out if this structure is only used temporarily in page_segment parser, or also more */
115 struct DVBSubRegionDisplay *next;
116 } DVBSubRegionDisplay;
118 typedef struct DVBSubRegion
123 guint8 depth; /* If we want to make this a guint8, then need to ensure it isn't wrap around with reserved values in region handling code */
128 /* FIXME: Validate these fields existence and exact types */
132 DVBSubObjectDisplay *display_list;
134 struct DVBSubRegion *next;
137 typedef struct _DvbSubPrivate DvbSubPrivate;
138 struct _DvbSubPrivate
141 DvbSubCallbacks callbacks;
144 guint8 page_time_out;
145 DVBSubRegion *region_list;
146 DVBSubCLUT *clut_list;
147 DVBSubObject *object_list;
149 int display_list_size;
150 DVBSubRegionDisplay *display_list;
152 DVBSubtitleWindow display_def;
156 DvbSubPrivate priv; // FIXME (tpm)
158 DvbSubPrivate *private_data;
165 } DvbSubPixelDataSubBlockFieldType;
167 /* FIXME: It might make sense to pass DvbSubPrivate for all the get_* functions, instead of public DvbSub */
168 static DVBSubObject *
169 get_object (DvbSub * dvb_sub, guint16 object_id)
171 const DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
172 DVBSubObject *ptr = priv->object_list;
174 while (ptr && ptr->id != object_id) {
182 get_clut (DvbSub * dvb_sub, gint clut_id)
184 const DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
185 DVBSubCLUT *ptr = priv->clut_list;
187 while (ptr && ptr->id != clut_id) {
194 // FIXME: Just pass private_data pointer directly here and in other get_* helper functions?
195 static DVBSubRegion *
196 get_region (DvbSub * dvb_sub, guint8 region_id)
198 const DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
199 DVBSubRegion *ptr = priv->region_list;
201 while (ptr && ptr->id != region_id) {
209 delete_region_display_list (DvbSub * dvb_sub, DVBSubRegion * region)
211 const DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
212 DVBSubObject *object, *obj2;
213 DVBSubObject **obj2_ptr;
214 DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr;
216 while (region->display_list) {
217 display = region->display_list;
219 object = get_object (dvb_sub, display->object_id);
222 obj_disp_ptr = &object->display_list;
223 obj_disp = *obj_disp_ptr;
225 while (obj_disp && obj_disp != display) {
226 obj_disp_ptr = &obj_disp->object_list_next;
227 obj_disp = *obj_disp_ptr;
231 *obj_disp_ptr = obj_disp->object_list_next;
233 if (!object->display_list) {
234 obj2_ptr = (DVBSubObject **) & priv->object_list; /* FIXME: Evil casting */
237 while (obj2 != object) {
239 obj2_ptr = &obj2->next;
243 *obj2_ptr = obj2->next;
245 g_slice_free (DVBSubObject, obj2);
250 region->display_list = display->region_list_next;
252 g_slice_free (DVBSubObjectDisplay, display);
257 delete_state (DvbSub * dvb_sub)
259 DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
260 DVBSubRegion *region;
262 while (priv->region_list) {
263 region = priv->region_list;
265 priv->region_list = region->next;
267 delete_region_display_list (dvb_sub, region);
269 g_free (region->pbuf);
271 g_slice_free (DVBSubRegion, region);
274 g_slice_free_chain (DVBSubCLUT, priv->clut_list, next);
275 priv->clut_list = NULL;
277 /* Should already be null */
278 if (priv->object_list)
279 g_warning ("Memory deallocation error!");
282 /* init static data necessary for ffmpeg-colorspace conversion */
284 dsputil_static_init (void)
288 for (i = 0; i < 256; i++)
289 ff_cropTbl[i + MAX_NEG_CROP] = i;
290 for (i = 0; i < MAX_NEG_CROP; i++) {
292 ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
299 int i, r, g, b, a = 0;
301 GST_DEBUG_CATEGORY_INIT (dvbsub_debug, "dvbsub", 0, "dvbsuboverlay parser");
303 dsputil_static_init (); /* Initializes ff_cropTbl table, used in YUV_TO_RGB conversion */
305 /* Initialize the static default_clut structure, from which other clut
306 * structures are initialized from (to start off with default CLUTs
307 * as defined in the specification). */
308 default_clut.id = -1;
310 default_clut.clut4[0] = RGBA (0, 0, 0, 0);
311 default_clut.clut4[1] = RGBA (255, 255, 255, 255);
312 default_clut.clut4[2] = RGBA (0, 0, 0, 255);
313 default_clut.clut4[3] = RGBA (127, 127, 127, 255);
315 default_clut.clut16[0] = RGBA (0, 0, 0, 0);
316 for (i = 1; i < 16; i++) {
318 r = (i & 1) ? 255 : 0;
319 g = (i & 2) ? 255 : 0;
320 b = (i & 4) ? 255 : 0;
322 r = (i & 1) ? 127 : 0;
323 g = (i & 2) ? 127 : 0;
324 b = (i & 4) ? 127 : 0;
326 default_clut.clut16[i] = RGBA (r, g, b, 255);
329 default_clut.clut256[0] = RGBA (0, 0, 0, 0);
330 for (i = 1; i < 256; i++) {
332 r = (i & 1) ? 255 : 0;
333 g = (i & 2) ? 255 : 0;
334 b = (i & 4) ? 255 : 0;
339 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
340 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
341 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
345 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
346 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
347 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
351 r = 127 + ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
352 g = 127 + ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
353 b = 127 + ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
357 r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
358 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
359 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
364 default_clut.clut256[i] = RGBA (r, g, b, a);
369 _dvb_sub_parse_page_segment (DvbSub * dvb_sub, guint16 page_id, guint8 * buf,
371 { /* FIXME: Use guint for buf_size here and in many other places? */
372 DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
373 DVBSubRegionDisplay *display;
374 DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
376 const guint8 *buf_end = buf + buf_size;
380 #ifndef GST_DISABLE_GST_DEBUG
381 static int counter = 0; /* FIXME: static counter? I think not.. */
387 priv->page_time_out = *buf++;
388 page_state = ((*buf++) >> 2) & 3;
390 #ifndef GST_DISABLE_GST_DEBUG
392 static const gchar *page_state_str[4] = {
393 "Normal case", "ACQUISITION POINT", "Mode Change", "RESERVED"
397 GST_DEBUG ("PAGE: %d: page_id = %u, length = %d, page_time_out = %u secs, "
398 "page_state = %s", counter, page_id, buf_size, priv->page_time_out,
399 page_state_str[page_state]);
403 if (page_state == 2) { /* Mode change */
404 delete_state (dvb_sub);
407 tmp_display_list = priv->display_list;
408 priv->display_list = NULL;
409 priv->display_list_size = 0;
411 while (buf + 5 < buf_end) {
415 display = tmp_display_list;
416 tmp_ptr = &tmp_display_list;
418 while (display && display->region_id != region_id) {
419 tmp_ptr = &display->next;
420 display = display->next;
424 display = g_slice_new0 (DVBSubRegionDisplay);
426 display->region_id = region_id;
428 display->x_pos = GST_READ_UINT16_BE (buf);
430 display->y_pos = GST_READ_UINT16_BE (buf);
433 *tmp_ptr = display->next;
435 display->next = priv->display_list;
436 priv->display_list = display;
437 priv->display_list_size++;
439 GST_LOG ("PAGE %d: REGION information: ID = %u, address = %ux%u",
440 counter, region_id, display->x_pos, display->y_pos);
443 while (tmp_display_list) {
444 display = tmp_display_list;
446 tmp_display_list = display->next;
448 g_slice_free (DVBSubRegionDisplay, display);
453 _dvb_sub_parse_region_segment (DvbSub * dvb_sub, guint16 page_id, guint8 * buf,
456 DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
458 const guint8 *buf_end = buf + buf_size;
461 DVBSubRegion *region;
462 DVBSubObject *object;
463 DVBSubObjectDisplay *object_display;
471 region = get_region (dvb_sub, region_id);
473 if (!region) { /* Create a new region */
474 region = g_slice_new0 (DVBSubRegion);
475 region->id = region_id;
476 region->next = priv->region_list;
477 priv->region_list = region;
480 fill = ((*buf++) >> 3) & 1;
482 region->width = GST_READ_UINT16_BE (buf);
484 region->height = GST_READ_UINT16_BE (buf);
487 if (region->width * region->height != region->buf_size) { /* FIXME: Read closer from spec what happens when dimensions change */
489 g_free (region->pbuf);
491 region->buf_size = region->width * region->height;
493 region->pbuf = g_malloc (region->buf_size); /* TODO: We can probably use GSlice here if careful about freeing while buf_size still records the correct size */
495 fill = 1; /* FIXME: Validate from spec that fill is forced on (in the following codes context) when dimensions change */
498 region->depth = 1 << (((*buf++) >> 2) & 7);
499 if (region->depth < 2 || region->depth > 8) {
500 GST_WARNING ("region depth %d is invalid", region->depth);
501 region->depth = 4; /* FIXME: Check from spec this is the default? */
504 region->clut = *buf++;
506 if (region->depth == 8)
507 region->bgcolor = *buf++;
511 if (region->depth == 4)
512 region->bgcolor = (((*buf++) >> 4) & 15);
514 region->bgcolor = (((*buf++) >> 2) & 3);
517 GST_DEBUG ("REGION: id = %u, (%ux%u)@%u-bit", region_id, region->width,
518 region->height, region->depth);
521 memset (region->pbuf, region->bgcolor, region->buf_size);
522 GST_DEBUG ("REGION: filling region (%u) with bgcolor = %u", region->id,
526 delete_region_display_list (dvb_sub, region); /* Delete the region display list for current region - FIXME: why? */
528 while (buf + 6 <= buf_end) {
529 object_id = GST_READ_UINT16_BE (buf);
532 object = get_object (dvb_sub, object_id);
535 object = g_slice_new0 (DVBSubObject);
537 object->id = object_id;
539 object->next = priv->object_list;
540 priv->object_list = object;
543 object->type = (*buf) >> 6;
545 object_display = g_slice_new0 (DVBSubObjectDisplay);
547 object_display->object_id = object_id;
548 object_display->region_id = region_id;
550 object_display->x_pos = GST_READ_UINT16_BE (buf) & 0xfff;
552 object_display->y_pos = GST_READ_UINT16_BE (buf) & 0xfff;
555 if ((object->type == 1 || object->type == 2) && buf + 2 <= buf_end) {
556 object_display->fgcolor = *buf++;
557 object_display->bgcolor = *buf++;
560 object_display->region_list_next = region->display_list;
561 region->display_list = object_display;
563 object_display->object_list_next = object->display_list;
564 object->display_list = object_display;
566 GST_DEBUG ("REGION DATA: object_id = %u, region_id = %u, pos = %ux%u, "
567 "obj_type = %u", object->id, region->id, object_display->x_pos,
568 object_display->y_pos, object->type);
570 if (object->type == 1 || object->type == 2) {
571 GST_DEBUG ("REGION DATA: fgcolor = %u, bgcolor = %u",
572 object_display->fgcolor, object_display->bgcolor);
578 _dvb_sub_parse_clut_segment (DvbSub * dvb_sub, guint16 page_id, guint8 * buf,
581 DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
583 const guint8 *buf_end = buf + buf_size;
586 int entry_id, depth, full_range;
587 int y, cr, cb, alpha;
588 int r, g, b, r_add, g_add, b_add;
590 GST_MEMDUMP ("DVB clut packet", buf, buf_size);
595 clut = get_clut (dvb_sub, clut_id);
598 clut = g_slice_new (DVBSubCLUT); /* FIXME-MEMORY-LEAK: This seems to leak per valgrind */
600 memcpy (clut, &default_clut, sizeof (DVBSubCLUT));
604 clut->next = priv->clut_list;
605 priv->clut_list = clut;
608 while (buf + 4 < buf_end) {
611 depth = (*buf) & 0xe0;
614 GST_WARNING ("Invalid clut depth 0x%x!", *buf);
618 full_range = (*buf++) & 1;
627 cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
628 cb = (buf[1] << 2) & 0xf0;
629 alpha = (buf[1] << 6) & 0xc0;
637 YUV_TO_RGB1_CCIR (cb, cr);
638 YUV_TO_RGB2_CCIR (r, g, b, y);
640 GST_DEBUG ("CLUT DEFINITION: clut %d := (%d,%d,%d,%d)", entry_id, r, g, b,
644 clut->clut4[entry_id] = RGBA (r, g, b, 255 - alpha);
646 clut->clut16[entry_id] = RGBA (r, g, b, 255 - alpha);
648 clut->clut256[entry_id] = RGBA (r, g, b, 255 - alpha);
652 // FFMPEG-FIXME: The same code in ffmpeg is much more complex, it could use the same
653 // FFMPEG-FIXME: refactoring as done here
655 _dvb_sub_read_2bit_string (guint8 * destbuf, gint dbuf_len,
656 const guint8 ** srcbuf, gint buf_size, guint8 non_mod, guint8 * map_table)
658 GstBitReader gb = GST_BIT_READER_INIT (*srcbuf, buf_size);
659 /* FIXME: Handle FALSE returns from gst_bit_reader_get_* calls? */
661 gboolean stop_parsing = FALSE;
663 guint32 pixels_read = 0;
665 static gboolean warning_shown = FALSE;
666 if (!warning_shown) {
667 g_warning ("Parsing 2bit color DVB sub-picture. This is not tested at all. "
668 "If you see this message, please provide the developers with sample "
669 "media with these subtitles, if possible.");
670 warning_shown = TRUE;
673 GST_TRACE ("dbuf_len = %d", dbuf_len);
675 while (!stop_parsing && (gst_bit_reader_get_remaining (&gb) > 0)) {
676 guint run_length = 0, clut_index = 0;
677 gst_bit_reader_get_bits_uint32 (&gb, &bits, 2);
679 if (bits) { /* 2-bit_pixel-code */
682 } else { /* 2-bit_zero */
683 gst_bit_reader_get_bits_uint32 (&gb, &bits, 1);
684 if (bits == 1) { /* switch_1 == '1' */
685 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 3);
687 gst_bit_reader_get_bits_uint32 (&gb, &clut_index, 2);
688 } else { /* switch_1 == '0' */
689 gst_bit_reader_get_bits_uint32 (&gb, &bits, 1);
690 if (bits == 1) { /* switch_2 == '1' */
691 run_length = 1; /* 1x pseudo-colour '00' */
692 } else { /* switch_2 == '0' */
693 gst_bit_reader_get_bits_uint32 (&gb, &bits, 2);
694 switch (bits) { /* switch_3 */
695 case 0x0: /* end of 2-bit/pixel_code_string */
698 case 0x1: /* two pixels shall be set to pseudo colour (entry) '00' */
701 case 0x2: /* the following 6 bits contain run length coded pixel data */
702 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 4);
704 gst_bit_reader_get_bits_uint32 (&gb, &clut_index, 2);
706 case 0x3: /* the following 10 bits contain run length coded pixel data */
707 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 8);
709 gst_bit_reader_get_bits_uint32 (&gb, &clut_index, 2);
716 /* If run_length is zero, continue. Only case happening is when
717 * stop_parsing is TRUE too, so next cycle shouldn't run */
721 /* Trim the run_length to not go beyond the line end and consume
722 * it from remaining length of dest line */
723 run_length = MIN (run_length, dbuf_len);
724 dbuf_len -= run_length;
726 /* Make clut_index refer to the index into the desired bit depths
727 * CLUT definition table */
729 clut_index = map_table[clut_index]; /* now clut_index signifies the index into map_table dest */
731 /* Now we can simply memset run_length count of destination bytes
732 * to clut_index, but only if not non_modifying */
733 GST_TRACE ("RUNLEN: setting %u pixels to color 0x%x in destination buffer, "
734 "dbuf_len left is %d pixels", run_length, clut_index, dbuf_len);
736 if (!(non_mod == 1 && bits == 1))
737 memset (destbuf, clut_index, run_length);
739 destbuf += run_length;
740 pixels_read += run_length;
743 // FIXME: Test skip_to_byte instead of adding 7 bits, once everything else is working good
744 //gst_bit_reader_skip_to_byte (&gb);
745 *srcbuf += (gst_bit_reader_get_pos (&gb) + 7) >> 3;
747 GST_TRACE ("PIXEL: returning, read %u pixels", pixels_read);
748 // FIXME: Shouldn't need this variable if tracking things in the loop better
752 // FFMPEG-FIXME: The same code in ffmpeg is much more complex, it could use the same
753 // FFMPEG-FIXME: refactoring as done here, explained in commit 895296c3
755 _dvb_sub_read_4bit_string (guint8 * destbuf, gint dbuf_len,
756 const guint8 ** srcbuf, gint buf_size, guint8 non_mod, guint8 * map_table)
758 GstBitReader gb = GST_BIT_READER_INIT (*srcbuf, buf_size);
759 /* FIXME: Handle FALSE returns from gst_bit_reader_get_* calls? */
760 gboolean stop_parsing = FALSE;
762 guint32 pixels_read = 0;
764 GST_TRACE ("RUNLEN: srcbuf position %p, buf_size = %d; destination buffer "
765 "size is %d @ %p", *srcbuf, buf_size, dbuf_len, destbuf);
767 while (!stop_parsing && (gst_bit_reader_get_remaining (&gb) > 0)) {
768 guint run_length = 0, clut_index = 0;
769 gst_bit_reader_get_bits_uint32 (&gb, &bits, 4);
775 gst_bit_reader_get_bits_uint32 (&gb, &bits, 1);
776 if (bits == 0) { /* switch_1 == '0' */
777 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 3);
783 } else { /* switch_1 == '1' */
784 gst_bit_reader_get_bits_uint32 (&gb, &bits, 1);
785 if (bits == 0) { /* switch_2 == '0' */
786 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 2);
788 gst_bit_reader_get_bits_uint32 (&gb, &clut_index, 4);
789 } else { /* switch_2 == '1' */
790 gst_bit_reader_get_bits_uint32 (&gb, &bits, 2);
792 case 0x0: /* switch_3 == '00' */
793 run_length = 1; /* 1 pixel of pseudo-color 0 */
795 case 0x1: /* switch_3 == '01' */
796 run_length = 2; /* 2 pixels of pseudo-color 0 */
798 case 0x2: /* switch_3 == '10' */
799 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 4);
801 gst_bit_reader_get_bits_uint32 (&gb, &clut_index, 4);
803 case 0x3: /* switch_3 == '11' */
804 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 8);
806 gst_bit_reader_get_bits_uint32 (&gb, &clut_index, 4);
813 /* If run_length is zero, continue. Only case happening is when
814 * stop_parsing is TRUE too, so next cycle shouldn't run */
818 /* Trim the run_length to not go beyond the line end and consume
819 * it from remaining length of dest line */
820 run_length = MIN (run_length, dbuf_len);
821 dbuf_len -= run_length;
823 /* Make clut_index refer to the index into the desired bit depths
824 * CLUT definition table */
826 clut_index = map_table[clut_index]; /* now clut_index signifies the index into map_table dest */
828 /* Now we can simply memset run_length count of destination bytes
829 * to clut_index, but only if not non_modifying */
830 GST_TRACE ("RUNLEN: setting %u pixels to color 0x%x in destination buffer; "
831 "dbuf_len left is %d pixels", run_length, clut_index, dbuf_len);
833 if (!(non_mod == 1 && bits == 1))
834 memset (destbuf, clut_index, run_length);
836 destbuf += run_length;
837 pixels_read += run_length;
840 // FIXME: Test skip_to_byte instead of adding 7 bits, once everything else is working good
841 //gst_bit_reader_skip_to_byte (&gb);
842 *srcbuf += (gst_bit_reader_get_pos (&gb) + 7) >> 3;
844 GST_LOG ("Returning with %u pixels read", pixels_read);
846 // FIXME: Shouldn't need this variable if tracking things in the loop better
851 _dvb_sub_read_8bit_string (guint8 * destbuf, gint dbuf_len,
852 const guint8 ** srcbuf, gint buf_size, guint8 non_mod, guint8 * map_table)
854 GstBitReader gb = GST_BIT_READER_INIT (*srcbuf, buf_size);
855 /* FIXME: Handle FALSE returns from gst_bit_reader_get_* calls? */
857 gboolean stop_parsing = FALSE;
859 guint32 pixels_read = 0;
861 static gboolean warning_shown = FALSE;
862 if (!warning_shown) {
864 ("Parsing 8bit color DVB sub-picture. This is not tested at all. If you see this message, "
865 "please provide the developers with sample media with these subtitles, if possible.");
866 warning_shown = TRUE;
869 GST_LOG ("dbuf_len = %d", dbuf_len);
871 /* FFMPEG-FIXME: ffmpeg uses a manual byte walking algorithm, which might be more performant,
872 * FFMPEG-FIXME: but it does almost absolutely no buffer length checking, so could walk over
873 * FFMPEG-FIXME: memory boundaries. While we don't check gst_bit_reader_get_bits_uint32
874 * FFMPEG-FIXME: return values either and therefore might get some pixels corrupted, we at
875 * FFMPEG-FIXME: lest have no chance of reading memory we don't own and visual corruption
876 * FFMPEG-FIXME: is guaranteed anyway when not all bytes are present */
877 /* Rephrased - it's better to work with bytes with default value '0' instead of reading from memory we don't own. */
878 while (!stop_parsing && (gst_bit_reader_get_remaining (&gb) > 0)) {
879 guint run_length = 0, clut_index = 0;
880 gst_bit_reader_get_bits_uint32 (&gb, &bits, 8);
882 if (bits) { /* 8-bit_pixel-code */
885 } else { /* 8-bit_zero */
886 gst_bit_reader_get_bits_uint32 (&gb, &bits, 1);
887 if (bits == 0) { /* switch_1 == '0' */
888 /* run_length_1-127 for pseudo-colour _entry) '0x00' */
889 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 7);
890 if (run_length == 0) { /* end_of_string_signal */
893 } else { /* switch_1 == '1' */
894 /* run_length_3-127 */
895 gst_bit_reader_get_bits_uint32 (&gb, &run_length, 7);
896 gst_bit_reader_get_bits_uint32 (&gb, &clut_index, 8);
898 if (run_length < 3) {
899 GST_WARNING ("runlength value was %u, but the spec requires it "
900 "must be >=3", run_length);
905 /* If run_length is zero, continue. Only case happening is when
906 * stop_parsing is TRUE too, so next cycle shouldn't run */
910 /* Trim the run_length to not go beyond the line end and consume
911 * it from remaining length of dest line */
912 run_length = MIN (run_length, dbuf_len);
913 dbuf_len -= run_length;
915 /* Make clut_index refer to the index into the desired bit depths
916 * CLUT definition table */
918 clut_index = map_table[clut_index]; /* now clut_index signifies the index into map_table dest */
920 /* Now we can simply memset run_length count of destination bytes
921 * to clut_index, but only if not non_modifying */
922 GST_TRACE ("RUNLEN: setting %u pixels to color 0x%x in destination buffer; "
923 "dbuf_len left is %d pixels", run_length, clut_index, dbuf_len);
925 if (!(non_mod == 1 && bits == 1))
926 memset (destbuf, clut_index, run_length);
928 destbuf += run_length;
929 pixels_read += run_length;
932 GST_LOG ("Returning with %u pixels read", pixels_read);
934 // FIXME: Shouldn't need this variable if tracking things in the loop better
939 _dvb_sub_parse_pixel_data_block (DvbSub * dvb_sub,
940 DVBSubObjectDisplay * display, const guint8 * buf, gint buf_size,
941 DvbSubPixelDataSubBlockFieldType top_bottom, guint8 non_mod)
943 DVBSubRegion *region = get_region (dvb_sub, display->region_id);
944 const guint8 *buf_end = buf + buf_size;
948 gboolean dest_buf_filled = FALSE;
950 guint8 map2to4[] = { 0x0, 0x7, 0x8, 0xf };
951 guint8 map2to8[] = { 0x00, 0x77, 0x88, 0xff };
952 guint8 map4to8[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
953 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
957 GST_LOG ("DVB pixel block size %d, %s field:", buf_size,
958 top_bottom ? "bottom" : "top");
960 GST_MEMDUMP ("packet", buf, buf_size);
962 if (region == NULL) {
963 GST_LOG ("Region is NULL, returning");
969 x_pos = display->x_pos;
970 y_pos = display->y_pos;
972 if ((y_pos & 1) != top_bottom)
975 while (buf < buf_end) {
976 GST_LOG ("Iteration start, %u bytes missing from end; buf = %p, "
977 "buf_end = %p; Region is number %u, with a dimension of %dx%d; "
978 "We are at position %dx%d", (guint) (buf_end - buf), buf, buf_end,
979 region->id, region->width, region->height, x_pos, y_pos);
981 // FFMPEG-FIXME: ffmpeg doesn't check for equality and so can overflow destination buffer later on with bad input data
982 // FFMPEG-FIXME: However that makes it warn on end_of_object_line and map tables as well, so we add the dest_buf_filled tracking
983 // FIXME: Removed x_pos checking here, because we don't want to turn dest_buf_filled to TRUE permanently in that case
984 // FIXME: We assume that region->width - x_pos as dbuf_len to read_nbit_string will take care of that case nicely;
985 // FIXME: That is, that read_nbit_string never scribbles anything if dbuf_len passed to it is zero due to this.
986 if (y_pos >= region->height) {
987 dest_buf_filled = TRUE;
992 if (dest_buf_filled) {
993 /* FIXME: Be more verbose */
994 GST_WARNING ("Invalid object location for data_type 0x%x!",
996 GST_MEMDUMP ("Remaining data after invalid object location:", buf,
997 (guint) (buf_end - buf));
1001 if (region->depth == 8)
1002 map_table = map2to8;
1003 else if (region->depth == 4)
1004 map_table = map2to4;
1008 // FFMPEG-FIXME: ffmpeg code passes buf_size instead of buf_end - buf, and could
1009 // FFMPEG-FIXME: therefore potentially walk over the memory area we own
1011 _dvb_sub_read_2bit_string (pbuf + (y_pos * region->width) + x_pos,
1012 region->width - x_pos, &buf, buf_end - buf, non_mod, map_table);
1015 if (dest_buf_filled) {
1016 /* FIXME: Be more verbose */
1017 GST_WARNING ("Invalid object location for data_type 0x%x!",
1019 GST_MEMDUMP ("Remaining data after invalid object location:", buf,
1021 return; // FIXME: Perhaps tell read_nbit_string that dbuf_len is zero and let it walk the bytes regardless? (Same FIXME for 2bit and 8bit)
1024 if (region->depth < 4) {
1025 GST_WARNING ("4-bit pixel string in %d-bit region!", region->depth);
1029 if (region->depth == 8)
1030 map_table = map4to8;
1034 GST_LOG ("READ_4BIT_STRING: String data into position %dx%d; "
1035 "buf before is %p", x_pos, y_pos, buf);
1036 // FFMPEG-FIXME: ffmpeg code passes buf_size instead of buf_end - buf, and could
1037 // FFMPEG-FIXME: therefore potentially walk over the memory area we own
1039 _dvb_sub_read_4bit_string (pbuf + (y_pos * region->width) + x_pos,
1040 region->width - x_pos, &buf, buf_end - buf, non_mod, map_table);
1041 GST_DEBUG ("READ_4BIT_STRING finished: buf pointer now %p", buf);
1044 if (dest_buf_filled) {
1045 /* FIXME: Be more verbose */
1046 GST_WARNING ("Invalid object location for data_type 0x%x!",
1048 GST_MEMDUMP ("Remaining data after invalid object location:",
1049 buf, (guint) (buf_end - buf));
1053 if (region->depth < 8) {
1054 GST_WARNING ("8-bit pixel string in %d-bit region!", region->depth);
1057 // FFMPEG-FIXME: ffmpeg code passes buf_size instead of buf_end - buf, and could
1058 // FFMPEG-FIXME: therefore potentially walk over the memory area we own
1060 _dvb_sub_read_8bit_string (pbuf + (y_pos * region->width) + x_pos,
1061 region->width - x_pos, &buf, buf_end - buf, non_mod, NULL);
1065 GST_DEBUG ("handling map2to4 table data");
1066 /* FIXME: I don't see any guards about buffer size here - buf++ happens with the switch, but
1067 * FIXME: buffer is walked without length checks? Same deal in other map table cases */
1068 map2to4[0] = (*buf) >> 4;
1069 map2to4[1] = (*buf++) & 0xf;
1070 map2to4[2] = (*buf) >> 4;
1071 map2to4[3] = (*buf++) & 0xf;
1074 GST_DEBUG ("handling map2to8 table data");
1075 for (i = 0; i < 4; i++)
1076 map2to8[i] = *buf++;
1079 GST_DEBUG ("handling map4to8 table data");
1080 for (i = 0; i < 16; i++)
1081 map4to8[i] = *buf++;
1084 GST_DEBUG ("end of object line code encountered");
1085 x_pos = display->x_pos;
1089 /* FIXME: Do we consume word align stuffing byte that could follow top/bottom data? */
1090 GST_WARNING ("Unknown/unsupported pixel block 0x%x", *(buf - 1));
1096 _dvb_sub_parse_object_segment (DvbSub * dvb_sub, guint16 page_id, guint8 * buf,
1099 const guint8 *buf_end = buf + buf_size;
1101 DVBSubObject *object;
1103 guint8 coding_method, non_modifying_color;
1105 object_id = GST_READ_UINT16_BE (buf);
1108 object = get_object (dvb_sub, object_id);
1110 GST_DEBUG ("OBJECT: a new object segment has occurred for object_id = %u",
1114 GST_WARNING ("Nothing known about object with ID %u yet, bailing out",
1119 coding_method = ((*buf) >> 2) & 3;
1120 non_modifying_color = ((*buf++) >> 1) & 1;
1122 if (coding_method == 0) {
1123 const guint8 *block;
1124 DVBSubObjectDisplay *display;
1125 guint16 top_field_len, bottom_field_len;
1127 top_field_len = GST_READ_UINT16_BE (buf);
1129 bottom_field_len = GST_READ_UINT16_BE (buf);
1132 if (buf + top_field_len + bottom_field_len > buf_end) {
1133 GST_WARNING ("Field data size too large");
1137 /* FIXME: Potential optimization opportunity here - parse the object pixmap only once, and copy it to all the
1138 * FIXME: regions that need it. One object being in multiple regions is a rare occurrence in real life, however */
1139 for (display = object->display_list; display;
1140 display = display->object_list_next) {
1143 GST_DEBUG ("OBJECT: parsing top and bottom part of object id %d; "
1144 "top_field_len = %u, bottom_field_len = %u",
1145 display->object_id, top_field_len, bottom_field_len);
1147 _dvb_sub_parse_pixel_data_block (dvb_sub, display, block, top_field_len,
1148 TOP_FIELD, non_modifying_color);
1150 if (bottom_field_len > 0)
1151 block = buf + top_field_len;
1153 bottom_field_len = top_field_len;
1155 _dvb_sub_parse_pixel_data_block (dvb_sub, display, block,
1156 bottom_field_len, BOTTOM_FIELD, non_modifying_color);
1159 } else if (coding_method == 1) {
1160 GST_FIXME ("'a string of characters' coding method not supported yet!");
1162 GST_WARNING ("Unknown object coding 0x%x", coding_method);
1167 _dvb_sub_parse_display_definition_segment (DvbSub * dvb_sub, guint8 * buf,
1170 int dds_version, info_byte;
1171 DvbSubPrivate *ctx = dvb_sub->private_data;
1177 dds_version = info_byte >> 4;
1179 if (ctx->display_def.version == dds_version)
1180 return 0; /* already have this display definition version */
1182 ctx->display_def.version = dds_version;
1183 ctx->display_def.display_width = GST_READ_UINT16_BE (buf) + 1;
1185 ctx->display_def.display_height = GST_READ_UINT16_BE (buf) + 1;
1188 ctx->display_def.window_flag = info_byte & 1 << 3;
1190 if (buf_size >= 13 && ctx->display_def.window_flag) {
1191 ctx->display_def.window_x = GST_READ_UINT16_BE (buf);
1193 ctx->display_def.window_y = GST_READ_UINT16_BE (buf);
1195 ctx->display_def.window_width =
1196 GST_READ_UINT16_BE (buf) - ctx->display_def.window_x + 1;
1198 ctx->display_def.window_height =
1199 GST_READ_UINT16_BE (buf) - ctx->display_def.window_y + 1;
1207 _dvb_sub_parse_end_of_display_set (DvbSub * dvb_sub, guint16 page_id,
1208 guint8 * buf, gint buf_size, guint64 pts)
1210 DvbSubPrivate *priv = (DvbSubPrivate *) dvb_sub->private_data;
1212 DVBSubtitles *sub = g_slice_new0 (DVBSubtitles);
1214 DVBSubRegion *region;
1215 DVBSubRegionDisplay *display;
1216 DVBSubtitleRect *rect;
1218 guint32 *clut_table;
1221 static unsigned counter = 0; /* DEBUG use only *//* FIXME: get rid */
1223 GST_DEBUG ("DISPLAY SET END: page_id = %u, length = %d", page_id, buf_size);
1226 #if 0 /* FIXME: PTS stuff not figured out yet */
1227 sub->start_display_time = 0;
1228 sub->end_display_time = priv->page_time_out * 1000;
1229 sub->format = 0; /* 0 = graphics */
1232 sub->num_rects = priv->display_list_size;
1234 if (sub->num_rects > 0) {
1235 // FIXME-MEMORY-LEAK: This structure is not freed up yet
1236 sub->rects = g_malloc0 (sizeof (*sub->rects) * sub->num_rects); /* GSlice? */
1237 for (i = 0; i < sub->num_rects; i++)
1238 sub->rects[i] = g_malloc0 (sizeof (*sub->rects[i])); /* GSlice? */
1243 /* copy subtitle display and window information */
1244 sub->display_def = priv->display_def;
1246 for (display = priv->display_list; display; display = display->next) {
1247 region = get_region (dvb_sub, display->region_id);
1248 rect = sub->rects[i];
1253 rect->x = display->x_pos;
1254 rect->y = display->y_pos;
1255 rect->w = region->width;
1256 rect->h = region->height;
1257 #if 0 /* FIXME: Don't think we need to save the number of colors in the palette when we are saving as RGBA? */
1258 rect->nb_colors = 16;
1260 #if 0 /* FIXME: Needed to be specified once we support strings of characters based subtitles */
1261 rect->type = SUBTITLE_BITMAP;
1263 rect->pict.rowstride = region->width;
1264 rect->pict.palette_bits_count = region->depth;
1266 clut = get_clut (dvb_sub, region->clut);
1269 clut = &default_clut;
1271 switch (region->depth) {
1273 clut_table = clut->clut4;
1276 clut_table = clut->clut256;
1280 clut_table = clut->clut16;
1284 /* FIXME: Tweak this to be saved in a format most suitable for Qt and GStreamer instead.
1285 * Currently kept in AVPicture for quick save_display_set testing */
1286 rect->pict.palette = g_malloc ((1 << region->depth) * sizeof (guint32)); /* FIXME: Can we use GSlice here? */
1287 memcpy (rect->pict.palette, clut_table,
1288 (1 << region->depth) * sizeof (guint32));
1290 GST_MEMDUMP ("rect->pict.data.palette content",
1291 (guint8 *) rect->pict.palette, (1 << region->depth) * sizeof (guint32));
1293 rect->pict.data = g_malloc (region->buf_size); /* FIXME: Can we use GSlice here? */
1294 memcpy (rect->pict.data, region->pbuf, region->buf_size);
1297 GST_DEBUG ("DISPLAY: an object rect created: number %u, iteration %u, "
1298 "pos: %d:%d, size: %dx%d", counter, i, rect->x, rect->y, rect->w,
1301 GST_MEMDUMP ("rect->pict.data content", rect->pict.data, region->buf_size);
1307 sub->page_time_out = priv->page_time_out;
1310 if (priv->callbacks.new_data) {
1311 priv->callbacks.new_data (dvb_sub, sub, priv->user_data);
1313 /* No-one responsible to clean up memory, so do it ourselves */
1314 /* FIXME: Just don't bother with all this palette image creation in the first place then... */
1315 dvb_subtitles_free (sub);
1318 return 1; /* FIXME: The caller of this function is probably supposed to do something with the return value */
1322 dvb_subtitles_free (DVBSubtitles * sub)
1325 DVBSubtitleRect *rect;
1330 /* Now free up all the temporary memory we allocated */
1331 for (i = 0; i < sub->num_rects; ++i) {
1332 rect = sub->rects[i];
1334 g_free (rect->pict.palette);
1335 g_free (rect->pict.data);
1338 g_free (sub->rects);
1339 g_slice_free (DVBSubtitles, sub);
1345 static gsize inited = 0;
1349 if (g_once_init_enter (&inited)) {
1351 g_once_init_leave (&inited, TRUE);
1354 dvb_sub = g_slice_new0 (DvbSub);
1355 dvb_sub->private_data = &dvb_sub->priv;
1357 sub = dvb_sub->private_data;
1359 /* TODO: Add initialization code here */
1360 /* FIXME: Do we have a reason to initiate the members to zero, or are we guaranteed that anyway? */
1361 sub->region_list = NULL;
1362 sub->object_list = NULL;
1363 sub->page_time_out = 0; /* FIXME: Maybe 255 instead? */
1364 sub->pes_buffer = g_string_new (NULL);
1366 /* display/window information */
1367 sub->display_def.version = -1;
1368 sub->display_def.window_flag = 0;
1369 sub->display_def.display_width = 720;
1370 sub->display_def.display_height = 576;
1376 dvb_sub_free (DvbSub * sub)
1378 /* TODO: Add deinitalization code here */
1379 /* FIXME: Clear up region_list contents */
1381 g_string_free (sub->private_data->pes_buffer, TRUE);
1382 g_slice_free (DvbSub, sub);
1385 #define DVB_SUB_SEGMENT_PAGE_COMPOSITION 0x10
1386 #define DVB_SUB_SEGMENT_REGION_COMPOSITION 0x11
1387 #define DVB_SUB_SEGMENT_CLUT_DEFINITION 0x12
1388 #define DVB_SUB_SEGMENT_OBJECT_DATA 0x13
1389 #define DVB_SUB_SEGMENT_DISPLAY_DEFINITION 0x14
1390 #define DVB_SUB_SEGMENT_END_OF_DISPLAY_SET 0x80
1391 #define DVB_SUB_SEGMENT_STUFFING 0xFF
1393 #define DVB_SUB_SYNC_BYTE 0x0f
1395 * dvb_sub_feed_with_pts:
1396 * @dvb_sub: a #DvbSub
1397 * @pts: The PTS of the data
1398 * @data: The data to feed to the parser
1399 * @len: Length of the data
1401 * Feeds the DvbSub parser with new binary data to parse,
1402 * with an associated PTS value. E.g, data left after PES
1403 * packet header has been already parsed, which contains
1404 * the PTS information).
1406 * Return value: -1 if data was unhandled (e.g, not a subtitle packet),
1407 * -2 if data parsing was unsuccesful (e.g, length was invalid),
1408 * 0 or positive if data was handled. If positive, then amount of data consumed on success. FIXME: List the positive return values.
1411 dvb_sub_feed_with_pts (DvbSub * dvb_sub, guint64 pts, guint8 * data, gint len)
1413 unsigned int pos = 0;
1414 guint8 segment_type;
1415 guint16 segment_len;
1418 GST_DEBUG ("pts=%" G_GUINT64_FORMAT " and length %d", pts, len);
1420 g_return_val_if_fail (data != NULL, -1);
1422 if (len <= 3) { /* len(0x20 0x00 end_of_PES_data_field_marker) */
1423 GST_WARNING ("Data length too short");
1427 if (data[pos++] != 0x20) {
1428 GST_WARNING ("Tried to handle a PES packet private data that isn't a "
1429 "subtitle packet (does not start with 0x20)");
1433 if (data[pos++] != 0x00) {
1434 GST_WARNING ("'Subtitle stream in this PES packet' was not 0x00, so this "
1435 "is in theory not a DVB subtitle stream (but some other subtitle "
1436 "standard?); bailing out");
1440 while (data[pos++] == DVB_SUB_SYNC_BYTE) {
1441 if ((len - pos) < (2 * 2 + 1)) {
1442 GST_WARNING ("Data after SYNC BYTE too short, less than needed to "
1443 "even get to segment_length");
1446 segment_type = data[pos++];
1447 GST_DEBUG ("=== Segment type is 0x%x", segment_type);
1448 page_id = (data[pos] << 8) | data[pos + 1];
1449 GST_DEBUG ("page_id is 0x%x", page_id);
1451 segment_len = (data[pos] << 8) | data[pos + 1];
1452 GST_DEBUG ("segment_length is %d (0x%x 0x%x)", segment_len, data[pos],
1455 if ((len - pos) < segment_len) {
1456 GST_WARNING ("segment_length was told to be %u, but we only have "
1457 "%d bytes left", segment_len, len - pos);
1460 // TODO: Parse the segment per type (this is probably a leftover TODO that is now done?)
1461 /* FIXME: Handle differing PTS values - all segments of a given display set must be with the same PTS,
1462 * FIXME: but we let it slip and just take it for granted in end_of_display_set */
1463 switch (segment_type) {
1464 case DVB_SUB_SEGMENT_PAGE_COMPOSITION:
1465 GST_DEBUG ("Page composition segment at buffer pos %u", pos);
1466 _dvb_sub_parse_page_segment (dvb_sub, page_id, data + pos, segment_len); /* FIXME: Not sure about args */
1468 case DVB_SUB_SEGMENT_REGION_COMPOSITION:
1469 GST_DEBUG ("Region composition segment at buffer pos %u", pos);
1470 _dvb_sub_parse_region_segment (dvb_sub, page_id, data + pos, segment_len); /* FIXME: Not sure about args */
1472 case DVB_SUB_SEGMENT_CLUT_DEFINITION:
1473 GST_DEBUG ("CLUT definition segment at buffer pos %u", pos);
1474 _dvb_sub_parse_clut_segment (dvb_sub, page_id, data + pos, segment_len); /* FIXME: Not sure about args */
1476 case DVB_SUB_SEGMENT_OBJECT_DATA:
1477 GST_DEBUG ("Object data segment at buffer pos %u", pos);
1478 _dvb_sub_parse_object_segment (dvb_sub, page_id, data + pos, segment_len); /* FIXME: Not sure about args */
1480 case DVB_SUB_SEGMENT_DISPLAY_DEFINITION:
1481 GST_DEBUG ("display definition segment at buffer pos %u", pos);
1482 _dvb_sub_parse_display_definition_segment (dvb_sub, data + pos,
1485 case DVB_SUB_SEGMENT_END_OF_DISPLAY_SET:
1486 GST_DEBUG ("End of display set at buffer pos %u", pos);
1487 _dvb_sub_parse_end_of_display_set (dvb_sub, page_id, data + pos, segment_len, pts); /* FIXME: Not sure about args */
1490 GST_FIXME ("Unhandled segment type 0x%x", segment_type);
1497 GST_WARNING ("Data ended without a PES data end marker");
1502 GST_LOG ("Processed %d bytes out of %d", pos, len);
1507 * dvb_sub_set_callbacks:
1508 * @dvb_sub: a #DvbSub
1509 * @callbacks: the callbacks to install
1510 * @user_data: a user_data argument for the callback
1512 * Set callback which will be executed when new subpictures are available.
1515 dvb_sub_set_callbacks (DvbSub * dvb_sub, DvbSubCallbacks * callbacks,
1518 DvbSubPrivate *priv;
1520 g_return_if_fail (dvb_sub != NULL);
1521 g_return_if_fail (callbacks != NULL);
1523 priv = (DvbSubPrivate *) dvb_sub->private_data;
1525 priv->callbacks = *callbacks;
1526 priv->user_data = user_data;