[Ffmpeg-cvslog] CVS: ffmpeg/libavcodec dvbsubdec.c, NONE, 1.1 Makefile, 1.195, 1.196 allcodecs.c, 1.108, 1.109 avcodec.h, 1.408, 1.409 dvbsub.c, 1.1, 1.2
Michael Niedermayer CVS
michael
Sun Jul 17 02:28:14 CEST 2005
Update of /cvsroot/ffmpeg/ffmpeg/libavcodec
In directory mail:/var2/tmp/cvs-serv17566/libavcodec
Modified Files:
Makefile allcodecs.c avcodec.h dvbsub.c
Added Files:
dvbsubdec.c
Log Message:
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
--- NEW FILE: dvbsubdec.c ---
/*
* DVB subtitle decoding for ffmpeg
* Copyright (c) 2005 Ian Caulfield.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "avcodec.h"
[...1594 lines suppressed...]
if (s->last_pts == AV_NOPTS_VALUE)
s->last_pts = s->pts;
return buf_size;
}
static void dvbsub_parse_close(AVCodecParserContext *s)
{
DVBSubParseContext *pc = s->priv_data;
av_freep(&pc->packet_buf);
}
AVCodecParser dvbsub_parser = {
{ CODEC_ID_DVB_SUBTITLE },
sizeof(DVBSubParseContext),
dvbsub_parse_init,
dvbsub_parse,
dvbsub_parse_close,
};
Index: Makefile
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/Makefile,v
retrieving revision 1.195
retrieving revision 1.196
diff -u -d -r1.195 -r1.196
--- Makefile 27 Jun 2005 00:55:28 -0000 1.195
+++ Makefile 17 Jul 2005 00:28:11 -0000 1.196
@@ -17,7 +17,7 @@
ratecontrol.o adpcm.o eval.o error_resilience.o \
fft.o mdct.o raw.o golomb.o cabac.o\
dpcm.o adx.o rational.o faandct.o parser.o g726.o \
- vp3dsp.o integer.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o
+ vp3dsp.o integer.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o
ifeq ($(CONFIG_AASC_DECODER),yes)
OBJS+= aasc.o
Index: allcodecs.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/allcodecs.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- allcodecs.c 15 Jul 2005 06:51:36 -0000 1.108
+++ allcodecs.c 17 Jul 2005 00:28:11 -0000 1.109
@@ -555,6 +555,7 @@
/* subtitles */
register_avcodec(&dvdsub_decoder);
register_avcodec(&dvbsub_encoder);
+ register_avcodec(&dvbsub_decoder);
/* parsers */
av_register_codec_parser(&mpegvideo_parser);
@@ -574,5 +575,6 @@
av_register_codec_parser(&ac3_parser);
#endif
av_register_codec_parser(&dvdsub_parser);
+ av_register_codec_parser(&dvbsub_parser);
}
Index: avcodec.h
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/avcodec.h,v
retrieving revision 1.408
retrieving revision 1.409
diff -u -d -r1.408 -r1.409
--- avcodec.h 15 Jul 2005 06:51:36 -0000 1.408
+++ avcodec.h 17 Jul 2005 00:28:11 -0000 1.409
@@ -1930,18 +1930,23 @@
} AVPaletteControl;
-typedef struct AVSubtitle {
- uint16_t format; /* 0 = graphics */
+typedef struct AVSubtitleRect {
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
uint16_t nb_colors;
- uint32_t start_display_time; /* relative to packet pts, in ms */
- uint32_t end_display_time; /* relative to packet pts, in ms */
int linesize;
uint32_t *rgba_palette;
uint8_t *bitmap;
+} AVSubtitleRect;
+
+typedef struct AVSubtitle {
+ uint16_t format; /* 0 = graphics */
+ uint32_t start_display_time; /* relative to packet pts, in ms */
+ uint32_t end_display_time; /* relative to packet pts, in ms */
+ uint32_t num_rects;
+ AVSubtitleRect *rects;
} AVSubtitle;
extern AVCodec ac3_encoder;
@@ -2135,6 +2140,7 @@
/* subtitles */
extern AVCodec dvdsub_decoder;
extern AVCodec dvbsub_encoder;
+extern AVCodec dvbsub_decoder;
/* resample.c */
@@ -2390,6 +2396,7 @@
extern AVCodecParser mpegaudio_parser;
extern AVCodecParser ac3_parser;
extern AVCodecParser dvdsub_parser;
+extern AVCodecParser dvbsub_parser;
/* memory */
void *av_malloc(unsigned int size);
Index: dvbsub.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/dvbsub.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dvbsub.c 3 Jun 2005 13:59:38 -0000 1.1
+++ dvbsub.c 17 Jul 2005 00:28:11 -0000 1.2
@@ -225,18 +225,9 @@
q = outbuf;
page_id = 1;
- region_id = 0;
- clut_id = 0;
- object_id = 0;
- if (h->nb_colors <= 4) {
- /* 2 bpp, some decoders do not support it correctly */
- bpp_index = 0;
- } else if (h->nb_colors <= 16) {
- /* 4 bpp, standard encoding */
- bpp_index = 1;
- } else {
+
+ if (h->num_rects == 0 || h->rects == NULL)
return -1;
- }
*q++ = 0x00; /* subtitle_stream_id */
@@ -254,108 +245,153 @@
page_state = 2; /* mode change */
/* page_version = 0 + page_state */
*q++ = s->object_version | (page_state << 2) | 3;
- *q++ = region_id;
- *q++ = 0xff; /* reserved */
- putbe16(&q, 0); /* left pos */
- putbe16(&q, 0); /* top pos */
+
+ for (region_id = 0; region_id < h->num_rects; region_id++) {
+ *q++ = region_id;
+ *q++ = 0xff; /* reserved */
+ putbe16(&q, h->rects[region_id].x); /* left pos */
+ putbe16(&q, h->rects[region_id].y); /* top pos */
+ }
putbe16(&pseg_len, q - pseg_len - 2);
if (!s->hide_state) {
- /* CLUT segment */
+ for (clut_id = 0; clut_id < h->num_rects; clut_id++) {
+
+ /* CLUT segment */
+
+ if (h->rects[clut_id].nb_colors <= 4) {
+ /* 2 bpp, some decoders do not support it correctly */
+ bpp_index = 0;
+ } else if (h->rects[clut_id].nb_colors <= 16) {
+ /* 4 bpp, standard encoding */
+ bpp_index = 1;
+ } else {
+ return -1;
+ }
+
+ *q++ = 0x0f; /* sync byte */
+ *q++ = 0x12; /* CLUT definition segment */
+ putbe16(&q, page_id);
+ pseg_len = q;
+ q += 2; /* segment length */
+ *q++ = clut_id;
+ *q++ = (0 << 4) | 0xf; /* version = 0 */
+
+ for(i = 0; i < h->rects[clut_id].nb_colors; i++) {
+ *q++ = i; /* clut_entry_id */
+ *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */
+ {
+ int a, r, g, b;
+ a = (h->rects[clut_id].rgba_palette[i] >> 24) & 0xff;
+ r = (h->rects[clut_id].rgba_palette[i] >> 16) & 0xff;
+ g = (h->rects[clut_id].rgba_palette[i] >> 8) & 0xff;
+ b = (h->rects[clut_id].rgba_palette[i] >> 0) & 0xff;
+
+ *q++ = RGB_TO_Y_CCIR(r, g, b);
+ *q++ = RGB_TO_V_CCIR(r, g, b, 0);
+ *q++ = RGB_TO_U_CCIR(r, g, b, 0);
+ *q++ = 255 - a;
+ }
+ }
+
+ putbe16(&pseg_len, q - pseg_len - 2);
+ }
+ }
+
+ for (region_id = 0; region_id < h->num_rects; region_id++) {
+
+ /* region composition segment */
- *q++ = 0x0f; /* sync byte */
- *q++ = 0x12; /* CLUT definition segment */
+ if (h->rects[region_id].nb_colors <= 4) {
+ /* 2 bpp, some decoders do not support it correctly */
+ bpp_index = 0;
+ } else if (h->rects[region_id].nb_colors <= 16) {
+ /* 4 bpp, standard encoding */
+ bpp_index = 1;
+ } else {
+ return -1;
+ }
+
+ *q++ = 0x0f; /* sync_byte */
+ *q++ = 0x11; /* segment_type */
putbe16(&q, page_id);
pseg_len = q;
q += 2; /* segment length */
- *q++ = clut_id;
- *q++ = (0 << 4) | 0xf; /* version = 0 */
-
- for(i = 0; i < h->nb_colors; i++) {
- *q++ = i; /* clut_entry_id */
- *q++ = (1 << (7 - bpp_index)) | (0xf << 1) | 1; /* 2 bits/pixel full range */
- {
- int a, r, g, b;
- a = (h->rgba_palette[i] >> 24) & 0xff;
- r = (h->rgba_palette[i] >> 16) & 0xff;
- g = (h->rgba_palette[i] >> 8) & 0xff;
- b = (h->rgba_palette[i] >> 0) & 0xff;
-
- *q++ = RGB_TO_Y_CCIR(r, g, b);
- *q++ = RGB_TO_V_CCIR(r, g, b, 0);
- *q++ = RGB_TO_U_CCIR(r, g, b, 0);
- *q++ = 255 - a;
- }
+ *q++ = region_id;
+ *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */
+ putbe16(&q, h->rects[region_id].w); /* region width */
+ putbe16(&q, h->rects[region_id].h); /* region height */
+ *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03;
+ *q++ = region_id; /* clut_id == region_id */
+ *q++ = 0; /* 8 bit fill colors */
+ *q++ = 0x03; /* 4 bit and 2 bit fill colors */
+
+ if (!s->hide_state) {
+ putbe16(&q, region_id); /* object_id == region_id */
+ *q++ = (0 << 6) | (0 << 4);
+ *q++ = 0;
+ *q++ = 0xf0;
+ *q++ = 0;
}
putbe16(&pseg_len, q - pseg_len - 2);
}
- /* region composition segment */
-
- *q++ = 0x0f; /* sync_byte */
- *q++ = 0x11; /* segment_type */
- putbe16(&q, page_id);
- pseg_len = q;
- q += 2; /* segment length */
- *q++ = region_id;
- *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */
- putbe16(&q, 720); /* region width */
- putbe16(&q, 576); /* region height */
- *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03;
- *q++ = clut_id;
- *q++ = 0; /* 8 bit fill colors */
- *q++ = 0x03; /* 4 bit and 2 bit fill colors */
-
- if (!s->hide_state) {
- putbe16(&q, object_id);
- *q++ = (0 << 6) | (0 << 4) | ((h->x >> 8) & 0xf);
- *q++ = h->x;
- *q++ = 0xf0 | ((h->y >> 8) & 0xf);
- *q++ = h->y;
- }
-
- putbe16(&pseg_len, q - pseg_len - 2);
if (!s->hide_state) {
- /* Object Data segment */
+ for (object_id = 0; object_id < h->num_rects; object_id++) {
+ /* Object Data segment */
- *q++ = 0x0f; /* sync byte */
- *q++ = 0x13;
- putbe16(&q, page_id);
- pseg_len = q;
- q += 2; /* segment length */
-
- putbe16(&q, object_id);
- *q++ = (s->object_version << 4) | (0 << 2) | (0 << 1) | 1; /* version = 0,
- onject_coding_method,
- non_modifying_color_flag */
- {
- uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr;
- void (*dvb_encode_rle)(uint8_t **pq,
- const uint8_t *bitmap, int linesize,
- int w, int h);
- ptop_field_len = q;
- q += 2;
- pbottom_field_len = q;
- q += 2;
+ if (h->rects[region_id].nb_colors <= 4) {
+ /* 2 bpp, some decoders do not support it correctly */
+ bpp_index = 0;
+ } else if (h->rects[region_id].nb_colors <= 16) {
+ /* 4 bpp, standard encoding */
+ bpp_index = 1;
+ } else {
+ return -1;
+ }
- if (bpp_index == 0)
- dvb_encode_rle = dvb_encode_rle2;
- else
- dvb_encode_rle = dvb_encode_rle4;
-
- top_ptr = q;
- dvb_encode_rle(&q, h->bitmap, h->w * 2, h->w, h->h >> 1);
- bottom_ptr = q;
- dvb_encode_rle(&q, h->bitmap + h->w, h->w * 2, h->w, h->h >> 1);
+ *q++ = 0x0f; /* sync byte */
+ *q++ = 0x13;
+ putbe16(&q, page_id);
+ pseg_len = q;
+ q += 2; /* segment length */
- putbe16(&ptop_field_len, bottom_ptr - top_ptr);
- putbe16(&pbottom_field_len, q - bottom_ptr);
- }
+ putbe16(&q, object_id);
+ *q++ = (s->object_version << 4) | (0 << 2) | (0 << 1) | 1; /* version = 0,
+ onject_coding_method,
+ non_modifying_color_flag */
+ {
+ uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr;
+ void (*dvb_encode_rle)(uint8_t **pq,
+ const uint8_t *bitmap, int linesize,
+ int w, int h);
+ ptop_field_len = q;
+ q += 2;
+ pbottom_field_len = q;
+ q += 2;
- putbe16(&pseg_len, q - pseg_len - 2);
+ if (bpp_index == 0)
+ dvb_encode_rle = dvb_encode_rle2;
+ else
+ dvb_encode_rle = dvb_encode_rle4;
+
+ top_ptr = q;
+ dvb_encode_rle(&q, h->rects[object_id].bitmap, h->rects[object_id].w * 2,
+ h->rects[object_id].w, h->rects[object_id].h >> 1);
+ bottom_ptr = q;
+ dvb_encode_rle(&q, h->rects[object_id].bitmap + h->rects[object_id].w,
+ h->rects[object_id].w * 2, h->rects[object_id].w,
+ h->rects[object_id].h >> 1);
+
+ putbe16(&ptop_field_len, bottom_ptr - top_ptr);
+ putbe16(&pbottom_field_len, q - bottom_ptr);
+ }
+
+ putbe16(&pseg_len, q - pseg_len - 2);
+ }
}
/* end of display set segment */
More information about the ffmpeg-cvslog
mailing list