]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dvbsub.c
amrwbdec: set channels, channel_layout, and sample_rate
[ffmpeg] / libavcodec / dvbsub.c
index a1594edd037c298436f0dd8b5fa2b4f276edc9f4..26d14bd3637d345b69f7102e73c2c463ec6625ce 100644 (file)
@@ -1,26 +1,26 @@
 /*
- * DVB subtitle encoding for ffmpeg
- * Copyright (c) 2005 Fabrice Bellard.
+ * DVB subtitle encoding
+ * Copyright (c) 2005 Fabrice Bellard
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav 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.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav 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 FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avcodec.h"
 #include "bytestream.h"
-#include "colorspace.h"
+#include "libavutil/colorspace.h"
 
 typedef struct DVBSubtitleContext {
     int hide_state;
@@ -195,7 +195,7 @@ static void dvb_encode_rle4(uint8_t **pq,
 }
 
 static int encode_dvb_subtitles(DVBSubtitleContext *s,
-                                uint8_t *outbuf, AVSubtitle *h)
+                                uint8_t *outbuf, const AVSubtitle *h)
 {
     uint8_t *q, *pseg_len;
     int page_id, region_id, clut_id, object_id, i, bpp_index, page_state;
@@ -223,13 +223,13 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
     else
         page_state = 2; /* mode change */
     /* page_version = 0 + page_state */
-    *q++ = s->object_version | (page_state << 2) | 3;
+    *q++ = (s->object_version << 4) | (page_state << 2) | 3;
 
     for (region_id = 0; region_id < h->num_rects; region_id++) {
         *q++ = region_id;
         *q++ = 0xff; /* reserved */
-        bytestream_put_be16(&q, h->rects[region_id].x); /* left pos */
-        bytestream_put_be16(&q, h->rects[region_id].y); /* top pos */
+        bytestream_put_be16(&q, h->rects[region_id]->x); /* left pos */
+        bytestream_put_be16(&q, h->rects[region_id]->y); /* top pos */
     }
 
     bytestream_put_be16(&pseg_len, q - pseg_len - 2);
@@ -239,10 +239,10 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
 
             /* CLUT segment */
 
-            if (h->rects[clut_id].nb_colors <= 4) {
+            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) {
+            } else if (h->rects[clut_id]->nb_colors <= 16) {
                 /* 4 bpp, standard encoding */
                 bpp_index = 1;
             } else {
@@ -257,15 +257,16 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
             *q++ = clut_id;
             *q++ = (0 << 4) | 0xf; /* version = 0 */
 
-            for(i = 0; i < h->rects[clut_id].nb_colors; i++) {
+            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;
+                    uint32_t x= ((uint32_t*)h->rects[clut_id]->pict.data[1])[i];
+                    a = (x >> 24) & 0xff;
+                    r = (x >> 16) & 0xff;
+                    g = (x >>  8) & 0xff;
+                    b = (x >>  0) & 0xff;
 
                     *q++ = RGB_TO_Y_CCIR(r, g, b);
                     *q++ = RGB_TO_V_CCIR(r, g, b, 0);
@@ -282,10 +283,10 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
 
         /* region composition segment */
 
-        if (h->rects[region_id].nb_colors <= 4) {
+        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) {
+        } else if (h->rects[region_id]->nb_colors <= 16) {
             /* 4 bpp, standard encoding */
             bpp_index = 1;
         } else {
@@ -299,8 +300,8 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
         q += 2; /* segment length */
         *q++ = region_id;
         *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */
-        bytestream_put_be16(&q, h->rects[region_id].w); /* region width */
-        bytestream_put_be16(&q, h->rects[region_id].h); /* region height */
+        bytestream_put_be16(&q, h->rects[region_id]->w); /* region width */
+        bytestream_put_be16(&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 */
@@ -322,10 +323,10 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
         for (object_id = 0; object_id < h->num_rects; object_id++) {
             /* Object Data segment */
 
-            if (h->rects[object_id].nb_colors <= 4) {
+            if (h->rects[object_id]->nb_colors <= 4) {
                 /* 2 bpp, some decoders do not support it correctly */
                 bpp_index = 0;
-            } else if (h->rects[object_id].nb_colors <= 16) {
+            } else if (h->rects[object_id]->nb_colors <= 16) {
                 /* 4 bpp, standard encoding */
                 bpp_index = 1;
             } else {
@@ -358,12 +359,12 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
                     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);
+                dvb_encode_rle(&q, h->rects[object_id]->pict.data[0], 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);
+                dvb_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w,
+                                    h->rects[object_id]->w * 2, h->rects[object_id]->w,
+                                    h->rects[object_id]->h >> 1);
 
                 bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr);
                 bytestream_put_be16(&pbottom_field_len, q - bottom_ptr);
@@ -391,21 +392,21 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
 }
 
 static int dvbsub_encode(AVCodecContext *avctx,
-                       unsigned char *buf, int buf_size, void *data)
+                         unsigned char *buf, int buf_size,
+                         const AVSubtitle *sub)
 {
     DVBSubtitleContext *s = avctx->priv_data;
-    AVSubtitle *sub = data;
     int ret;
 
     ret = encode_dvb_subtitles(s, buf, sub);
     return ret;
 }
 
-AVCodec dvbsub_encoder = {
-    "dvbsub",
-    CODEC_TYPE_SUBTITLE,
-    CODEC_ID_DVB_SUBTITLE,
-    sizeof(DVBSubtitleContext),
-    NULL,
-    dvbsub_encode,
+AVCodec ff_dvbsub_encoder = {
+    .name           = "dvbsub",
+    .type           = AVMEDIA_TYPE_SUBTITLE,
+    .id             = AV_CODEC_ID_DVB_SUBTITLE,
+    .priv_data_size = sizeof(DVBSubtitleContext),
+    .encode_sub     = dvbsub_encode,
+    .long_name      = NULL_IF_CONFIG_SMALL("DVB subtitles"),
 };