Signed-off-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Diego Biurrun <diego@biurrun.de>
| ... | ... |
@@ -131,6 +131,8 @@ library: |
| 131 | 131 |
@tab Multimedia format used by Delphine Software games. |
| 132 | 132 |
@item CD+G @tab @tab X |
| 133 | 133 |
@tab Video format used by CD+G karaoke disks |
| 134 |
+@item Commodore CDXL @tab @tab X |
|
| 135 |
+ @tab Amiga CD video format |
|
| 134 | 136 |
@item Core Audio Format @tab @tab X |
| 135 | 137 |
@tab Apple Core Audio Format |
| 136 | 138 |
@item CRC testing format @tab X @tab |
| ... | ... |
@@ -435,6 +437,8 @@ following image formats are supported: |
| 435 | 435 |
@tab fourcc: CSCD |
| 436 | 436 |
@item CD+G @tab @tab X |
| 437 | 437 |
@tab Video codec for CD+G karaoke disks |
| 438 |
+@item CDXL @tab @tab X |
|
| 439 |
+ @tab Amiga CD video codec |
|
| 438 | 440 |
@item Chinese AVS video @tab E @tab X |
| 439 | 441 |
@tab AVS1-P2, JiZhun profile, encoding through external library libxavs |
| 440 | 442 |
@item Delphine Software International CIN video @tab @tab X |
| ... | ... |
@@ -102,6 +102,7 @@ OBJS-$(CONFIG_C93_DECODER) += c93.o |
| 102 | 102 |
OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdec.o cavsdsp.o \ |
| 103 | 103 |
mpeg12data.o mpegvideo.o |
| 104 | 104 |
OBJS-$(CONFIG_CDGRAPHICS_DECODER) += cdgraphics.o |
| 105 |
+OBJS-$(CONFIG_CDXL_DECODER) += cdxl.o |
|
| 105 | 106 |
OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o |
| 106 | 107 |
OBJS-$(CONFIG_CLJR_DECODER) += cljr.o |
| 107 | 108 |
OBJS-$(CONFIG_CLJR_ENCODER) += cljr.o |
| ... | ... |
@@ -86,6 +86,7 @@ void avcodec_register_all(void) |
| 86 | 86 |
REGISTER_DECODER (C93, c93); |
| 87 | 87 |
REGISTER_DECODER (CAVS, cavs); |
| 88 | 88 |
REGISTER_DECODER (CDGRAPHICS, cdgraphics); |
| 89 |
+ REGISTER_DECODER (CDXL, cdxl); |
|
| 89 | 90 |
REGISTER_DECODER (CINEPAK, cinepak); |
| 90 | 91 |
REGISTER_ENCDEC (CLJR, cljr); |
| 91 | 92 |
REGISTER_DECODER (CSCD, cscd); |
| 250 | 251 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,278 @@ |
| 0 |
+/* |
|
| 1 |
+ * CDXL video decoder |
|
| 2 |
+ * Copyright (c) 2011-2012 Paul B Mahol |
|
| 3 |
+ * |
|
| 4 |
+ * This file is part of Libav. |
|
| 5 |
+ * |
|
| 6 |
+ * Libav is free software; you can redistribute it and/or |
|
| 7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 8 |
+ * License as published by the Free Software Foundation; either |
|
| 9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 10 |
+ * |
|
| 11 |
+ * Libav is distributed in the hope that it will be useful, |
|
| 12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 14 |
+ * Lesser General Public License for more details. |
|
| 15 |
+ * |
|
| 16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 17 |
+ * License along with Libav; if not, write to the Free Software |
|
| 18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 19 |
+ */ |
|
| 20 |
+ |
|
| 21 |
+#include "libavutil/intreadwrite.h" |
|
| 22 |
+#include "libavutil/imgutils.h" |
|
| 23 |
+#include "avcodec.h" |
|
| 24 |
+#include "get_bits.h" |
|
| 25 |
+ |
|
| 26 |
+typedef struct {
|
|
| 27 |
+ AVCodecContext *avctx; |
|
| 28 |
+ AVFrame frame; |
|
| 29 |
+ int bpp; |
|
| 30 |
+ const uint8_t *palette; |
|
| 31 |
+ int palette_size; |
|
| 32 |
+ const uint8_t *video; |
|
| 33 |
+ int video_size; |
|
| 34 |
+ uint8_t *new_video; |
|
| 35 |
+ int new_video_size; |
|
| 36 |
+} CDXLVideoContext; |
|
| 37 |
+ |
|
| 38 |
+static av_cold int cdxl_decode_init(AVCodecContext *avctx) |
|
| 39 |
+{
|
|
| 40 |
+ CDXLVideoContext *c = avctx->priv_data; |
|
| 41 |
+ |
|
| 42 |
+ avcodec_get_frame_defaults(&c->frame); |
|
| 43 |
+ c->new_video_size = 0; |
|
| 44 |
+ c->avctx = avctx; |
|
| 45 |
+ |
|
| 46 |
+ return 0; |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 49 |
+static void import_palette(CDXLVideoContext *c, uint32_t *new_palette) |
|
| 50 |
+{
|
|
| 51 |
+ int i; |
|
| 52 |
+ |
|
| 53 |
+ for (i = 0; i < c->palette_size / 2; i++) {
|
|
| 54 |
+ unsigned rgb = AV_RB16(&c->palette[i * 2]); |
|
| 55 |
+ unsigned r = ((rgb >> 8) & 0xF) * 0x11; |
|
| 56 |
+ unsigned g = ((rgb >> 4) & 0xF) * 0x11; |
|
| 57 |
+ unsigned b = (rgb & 0xF) * 0x11; |
|
| 58 |
+ AV_WN32(&new_palette[i], (r << 16) | (g << 8) | b); |
|
| 59 |
+ } |
|
| 60 |
+} |
|
| 61 |
+ |
|
| 62 |
+static void bitplanar2chunky(CDXLVideoContext *c, int width, |
|
| 63 |
+ int linesize, uint8_t *out) |
|
| 64 |
+{
|
|
| 65 |
+ GetBitContext gb; |
|
| 66 |
+ int x, y, plane; |
|
| 67 |
+ |
|
| 68 |
+ init_get_bits(&gb, c->video, c->video_size * 8); |
|
| 69 |
+ memset(out, 0, linesize * c->avctx->height); |
|
| 70 |
+ for (plane = 0; plane < c->bpp; plane++) |
|
| 71 |
+ for (y = 0; y < c->avctx->height; y++) |
|
| 72 |
+ for (x = 0; x < width; x++) |
|
| 73 |
+ out[linesize * y + x] |= get_bits1(&gb) << plane; |
|
| 74 |
+} |
|
| 75 |
+ |
|
| 76 |
+static void cdxl_decode_rgb(CDXLVideoContext *c) |
|
| 77 |
+{
|
|
| 78 |
+ uint32_t *new_palette = (uint32_t *)c->frame.data[1]; |
|
| 79 |
+ int padded_width = FFALIGN(c->avctx->width, 16); |
|
| 80 |
+ |
|
| 81 |
+ import_palette(c, new_palette); |
|
| 82 |
+ bitplanar2chunky(c, padded_width, c->frame.linesize[0], c->frame.data[0]); |
|
| 83 |
+} |
|
| 84 |
+ |
|
| 85 |
+static void cdxl_decode_ham6(CDXLVideoContext *c) |
|
| 86 |
+{
|
|
| 87 |
+ AVCodecContext *avctx = c->avctx; |
|
| 88 |
+ uint32_t new_palette[16], r, g, b; |
|
| 89 |
+ uint8_t *ptr, *out, index, op; |
|
| 90 |
+ int x, y; |
|
| 91 |
+ |
|
| 92 |
+ ptr = c->new_video; |
|
| 93 |
+ out = c->frame.data[0]; |
|
| 94 |
+ |
|
| 95 |
+ import_palette(c, new_palette); |
|
| 96 |
+ bitplanar2chunky(c, avctx->width, avctx->width, c->new_video); |
|
| 97 |
+ |
|
| 98 |
+ for (y = 0; y < avctx->height; y++) {
|
|
| 99 |
+ r = new_palette[0] & 0xFF0000; |
|
| 100 |
+ g = new_palette[0] & 0xFF00; |
|
| 101 |
+ b = new_palette[0] & 0xFF; |
|
| 102 |
+ for (x = 0; x < avctx->width; x++) {
|
|
| 103 |
+ index = *ptr++; |
|
| 104 |
+ op = index >> 4; |
|
| 105 |
+ index &= 15; |
|
| 106 |
+ switch (op) {
|
|
| 107 |
+ case 0: |
|
| 108 |
+ r = new_palette[index] & 0xFF0000; |
|
| 109 |
+ g = new_palette[index] & 0xFF00; |
|
| 110 |
+ b = new_palette[index] & 0xFF; |
|
| 111 |
+ break; |
|
| 112 |
+ case 1: |
|
| 113 |
+ b = index * 0x11; |
|
| 114 |
+ break; |
|
| 115 |
+ case 2: |
|
| 116 |
+ r = index * 0x11 << 16; |
|
| 117 |
+ break; |
|
| 118 |
+ case 3: |
|
| 119 |
+ g = index * 0x11 << 8; |
|
| 120 |
+ break; |
|
| 121 |
+ } |
|
| 122 |
+ AV_WN32(out + x * 3, r | g | b); |
|
| 123 |
+ } |
|
| 124 |
+ out += c->frame.linesize[0]; |
|
| 125 |
+ } |
|
| 126 |
+} |
|
| 127 |
+ |
|
| 128 |
+static void cdxl_decode_ham8(CDXLVideoContext *c) |
|
| 129 |
+{
|
|
| 130 |
+ AVCodecContext *avctx = c->avctx; |
|
| 131 |
+ uint32_t new_palette[64], r, g, b; |
|
| 132 |
+ uint8_t *ptr, *out, index, op; |
|
| 133 |
+ int x, y; |
|
| 134 |
+ |
|
| 135 |
+ ptr = c->new_video; |
|
| 136 |
+ out = c->frame.data[0]; |
|
| 137 |
+ |
|
| 138 |
+ import_palette(c, new_palette); |
|
| 139 |
+ bitplanar2chunky(c, avctx->width, avctx->width, c->new_video); |
|
| 140 |
+ |
|
| 141 |
+ for (y = 0; y < avctx->height; y++) {
|
|
| 142 |
+ r = new_palette[0] & 0xFF0000; |
|
| 143 |
+ g = new_palette[0] & 0xFF00; |
|
| 144 |
+ b = new_palette[0] & 0xFF; |
|
| 145 |
+ for (x = 0; x < avctx->width; x++) {
|
|
| 146 |
+ index = *ptr++; |
|
| 147 |
+ op = index >> 6; |
|
| 148 |
+ index &= 63; |
|
| 149 |
+ switch (op) {
|
|
| 150 |
+ case 0: |
|
| 151 |
+ r = new_palette[index] & 0xFF0000; |
|
| 152 |
+ g = new_palette[index] & 0xFF00; |
|
| 153 |
+ b = new_palette[index] & 0xFF; |
|
| 154 |
+ break; |
|
| 155 |
+ case 1: |
|
| 156 |
+ b = (index << 2) | (b & 3); |
|
| 157 |
+ break; |
|
| 158 |
+ case 2: |
|
| 159 |
+ r = (index << 18) | (r & (3 << 16)); |
|
| 160 |
+ break; |
|
| 161 |
+ case 3: |
|
| 162 |
+ g = (index << 10) | (g & (3 << 8)); |
|
| 163 |
+ break; |
|
| 164 |
+ } |
|
| 165 |
+ AV_WN32(out + x * 3, r | g | b); |
|
| 166 |
+ } |
|
| 167 |
+ out += c->frame.linesize[0]; |
|
| 168 |
+ } |
|
| 169 |
+} |
|
| 170 |
+ |
|
| 171 |
+static int cdxl_decode_frame(AVCodecContext *avctx, void *data, |
|
| 172 |
+ int *data_size, AVPacket *pkt) |
|
| 173 |
+{
|
|
| 174 |
+ CDXLVideoContext *c = avctx->priv_data; |
|
| 175 |
+ AVFrame * const p = &c->frame; |
|
| 176 |
+ int ret, w, h, encoding, format, buf_size = pkt->size; |
|
| 177 |
+ const uint8_t *buf = pkt->data; |
|
| 178 |
+ |
|
| 179 |
+ if (buf_size < 32) |
|
| 180 |
+ return AVERROR_INVALIDDATA; |
|
| 181 |
+ encoding = buf[1] & 7; |
|
| 182 |
+ format = buf[1] & 0xE0; |
|
| 183 |
+ w = AV_RB16(&buf[14]); |
|
| 184 |
+ h = AV_RB16(&buf[16]); |
|
| 185 |
+ c->bpp = buf[19]; |
|
| 186 |
+ c->palette_size = AV_RB16(&buf[20]); |
|
| 187 |
+ c->palette = buf + 32; |
|
| 188 |
+ c->video = c->palette + c->palette_size; |
|
| 189 |
+ c->video_size = buf_size - c->palette_size - 32; |
|
| 190 |
+ |
|
| 191 |
+ if (c->palette_size > 512) |
|
| 192 |
+ return AVERROR_INVALIDDATA; |
|
| 193 |
+ if (buf_size < c->palette_size + 32) |
|
| 194 |
+ return AVERROR_INVALIDDATA; |
|
| 195 |
+ if (c->bpp < 1) |
|
| 196 |
+ return AVERROR_INVALIDDATA; |
|
| 197 |
+ if (c->bpp > 8) {
|
|
| 198 |
+ av_log_ask_for_sample(avctx, "unsupported pixel size: %d\n", c->bpp); |
|
| 199 |
+ return AVERROR_PATCHWELCOME; |
|
| 200 |
+ } |
|
| 201 |
+ if (format) {
|
|
| 202 |
+ av_log_ask_for_sample(avctx, "unsupported pixel format: %d\n", format); |
|
| 203 |
+ return AVERROR_PATCHWELCOME; |
|
| 204 |
+ } |
|
| 205 |
+ |
|
| 206 |
+ if ((ret = av_image_check_size(w, h, 0, avctx)) < 0) |
|
| 207 |
+ return ret; |
|
| 208 |
+ if (w != avctx->width || h != avctx->height) |
|
| 209 |
+ avcodec_set_dimensions(avctx, w, h); |
|
| 210 |
+ |
|
| 211 |
+ if (encoding == 0) {
|
|
| 212 |
+ if (c->video_size < FFALIGN(avctx->width, 16) * |
|
| 213 |
+ avctx->height * c->bpp / 8) |
|
| 214 |
+ return AVERROR_INVALIDDATA; |
|
| 215 |
+ avctx->pix_fmt = PIX_FMT_PAL8; |
|
| 216 |
+ } else if (encoding == 1 && (c->bpp == 6 || c->bpp == 8)) {
|
|
| 217 |
+ if (c->palette_size != (1 << (c->bpp - 1))) |
|
| 218 |
+ return AVERROR_INVALIDDATA; |
|
| 219 |
+ if (c->video_size < avctx->width * avctx->height * c->bpp / 8) |
|
| 220 |
+ return AVERROR_INVALIDDATA; |
|
| 221 |
+ avctx->pix_fmt = PIX_FMT_BGR24; |
|
| 222 |
+ } else {
|
|
| 223 |
+ av_log_ask_for_sample(avctx, "unsupported encoding %d and bpp %d\n", |
|
| 224 |
+ encoding, c->bpp); |
|
| 225 |
+ return AVERROR_PATCHWELCOME; |
|
| 226 |
+ } |
|
| 227 |
+ |
|
| 228 |
+ if (p->data[0]) |
|
| 229 |
+ avctx->release_buffer(avctx, p); |
|
| 230 |
+ |
|
| 231 |
+ p->reference = 0; |
|
| 232 |
+ if ((ret = avctx->get_buffer(avctx, p)) < 0) {
|
|
| 233 |
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
| 234 |
+ return ret; |
|
| 235 |
+ } |
|
| 236 |
+ p->pict_type = AV_PICTURE_TYPE_I; |
|
| 237 |
+ |
|
| 238 |
+ if (encoding) {
|
|
| 239 |
+ av_fast_padded_malloc(&c->new_video, &c->new_video_size, |
|
| 240 |
+ h * w + FF_INPUT_BUFFER_PADDING_SIZE); |
|
| 241 |
+ if (!c->new_video) |
|
| 242 |
+ return AVERROR(ENOMEM); |
|
| 243 |
+ if (c->bpp == 8) |
|
| 244 |
+ cdxl_decode_ham8(c); |
|
| 245 |
+ else |
|
| 246 |
+ cdxl_decode_ham6(c); |
|
| 247 |
+ } else {
|
|
| 248 |
+ cdxl_decode_rgb(c); |
|
| 249 |
+ } |
|
| 250 |
+ *data_size = sizeof(AVFrame); |
|
| 251 |
+ *(AVFrame*)data = c->frame; |
|
| 252 |
+ |
|
| 253 |
+ return buf_size; |
|
| 254 |
+} |
|
| 255 |
+ |
|
| 256 |
+static av_cold int cdxl_decode_end(AVCodecContext *avctx) |
|
| 257 |
+{
|
|
| 258 |
+ CDXLVideoContext *c = avctx->priv_data; |
|
| 259 |
+ |
|
| 260 |
+ av_free(c->new_video); |
|
| 261 |
+ if (c->frame.data[0]) |
|
| 262 |
+ avctx->release_buffer(avctx, &c->frame); |
|
| 263 |
+ |
|
| 264 |
+ return 0; |
|
| 265 |
+} |
|
| 266 |
+ |
|
| 267 |
+AVCodec ff_cdxl_decoder = {
|
|
| 268 |
+ .name = "cdxl", |
|
| 269 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
| 270 |
+ .id = CODEC_ID_CDXL, |
|
| 271 |
+ .priv_data_size = sizeof(CDXLVideoContext), |
|
| 272 |
+ .init = cdxl_decode_init, |
|
| 273 |
+ .close = cdxl_decode_end, |
|
| 274 |
+ .decode = cdxl_decode_frame, |
|
| 275 |
+ .capabilities = CODEC_CAP_DR1, |
|
| 276 |
+ .long_name = NULL_IF_CONFIG_SMALL("Commodore CDXL video"),
|
|
| 277 |
+}; |
| ... | ... |
@@ -21,7 +21,7 @@ |
| 21 | 21 |
#define AVCODEC_VERSION_H |
| 22 | 22 |
|
| 23 | 23 |
#define LIBAVCODEC_VERSION_MAJOR 54 |
| 24 |
-#define LIBAVCODEC_VERSION_MINOR 0 |
|
| 24 |
+#define LIBAVCODEC_VERSION_MINOR 1 |
|
| 25 | 25 |
#define LIBAVCODEC_VERSION_MICRO 0 |
| 26 | 26 |
|
| 27 | 27 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| ... | ... |
@@ -55,6 +55,7 @@ OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o mov_chan.o \ |
| 55 | 55 |
OBJS-$(CONFIG_CAVSVIDEO_DEMUXER) += cavsvideodec.o rawdec.o |
| 56 | 56 |
OBJS-$(CONFIG_CAVSVIDEO_MUXER) += rawenc.o |
| 57 | 57 |
OBJS-$(CONFIG_CDG_DEMUXER) += cdg.o |
| 58 |
+OBJS-$(CONFIG_CDXL_DEMUXER) += cdxl.o |
|
| 58 | 59 |
OBJS-$(CONFIG_CRC_MUXER) += crcenc.o |
| 59 | 60 |
OBJS-$(CONFIG_DAUD_DEMUXER) += daud.o |
| 60 | 61 |
OBJS-$(CONFIG_DAUD_MUXER) += daud.o |
| ... | ... |
@@ -76,6 +76,7 @@ void av_register_all(void) |
| 76 | 76 |
REGISTER_DEMUXER (CAF, caf); |
| 77 | 77 |
REGISTER_MUXDEMUX (CAVSVIDEO, cavsvideo); |
| 78 | 78 |
REGISTER_DEMUXER (CDG, cdg); |
| 79 |
+ REGISTER_DEMUXER (CDXL, cdxl); |
|
| 79 | 80 |
REGISTER_MUXER (CRC, crc); |
| 80 | 81 |
REGISTER_MUXDEMUX (DAUD, daud); |
| 81 | 82 |
REGISTER_DEMUXER (DFA, dfa); |
| 82 | 83 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,170 @@ |
| 0 |
+/* |
|
| 1 |
+ * CDXL demuxer |
|
| 2 |
+ * Copyright (c) 2011-2012 Paul B Mahol |
|
| 3 |
+ * |
|
| 4 |
+ * This file is part of Libav. |
|
| 5 |
+ * |
|
| 6 |
+ * Libav is free software; you can redistribute it and/or |
|
| 7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 8 |
+ * License as published by the Free Software Foundation; either |
|
| 9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 10 |
+ * |
|
| 11 |
+ * Libav is distributed in the hope that it will be useful, |
|
| 12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 14 |
+ * Lesser General Public License for more details. |
|
| 15 |
+ * |
|
| 16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 17 |
+ * License along with Libav; if not, write to the Free Software |
|
| 18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 19 |
+ */ |
|
| 20 |
+ |
|
| 21 |
+#include "libavutil/intreadwrite.h" |
|
| 22 |
+#include "libavutil/parseutils.h" |
|
| 23 |
+#include "libavutil/opt.h" |
|
| 24 |
+#include "avformat.h" |
|
| 25 |
+#include "internal.h" |
|
| 26 |
+ |
|
| 27 |
+#define CDXL_HEADER_SIZE 32 |
|
| 28 |
+ |
|
| 29 |
+typedef struct CDXLDemuxContext {
|
|
| 30 |
+ AVClass *class; |
|
| 31 |
+ int sample_rate; |
|
| 32 |
+ char *framerate; |
|
| 33 |
+ AVRational fps; |
|
| 34 |
+ int read_chunk; |
|
| 35 |
+ uint8_t header[CDXL_HEADER_SIZE]; |
|
| 36 |
+ int video_stream_index; |
|
| 37 |
+ int audio_stream_index; |
|
| 38 |
+} CDXLDemuxContext; |
|
| 39 |
+ |
|
| 40 |
+static int cdxl_read_header(AVFormatContext *s) |
|
| 41 |
+{
|
|
| 42 |
+ CDXLDemuxContext *cdxl = s->priv_data; |
|
| 43 |
+ int ret; |
|
| 44 |
+ |
|
| 45 |
+ if ((ret = av_parse_video_rate(&cdxl->fps, cdxl->framerate)) < 0) {
|
|
| 46 |
+ av_log(s, AV_LOG_ERROR, |
|
| 47 |
+ "Could not parse framerate: %s.\n", cdxl->framerate); |
|
| 48 |
+ return ret; |
|
| 49 |
+ } |
|
| 50 |
+ |
|
| 51 |
+ cdxl->read_chunk = 0; |
|
| 52 |
+ cdxl->video_stream_index = -1; |
|
| 53 |
+ cdxl->audio_stream_index = -1; |
|
| 54 |
+ |
|
| 55 |
+ s->ctx_flags |= AVFMTCTX_NOHEADER; |
|
| 56 |
+ |
|
| 57 |
+ return 0; |
|
| 58 |
+} |
|
| 59 |
+ |
|
| 60 |
+static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
| 61 |
+{
|
|
| 62 |
+ CDXLDemuxContext *cdxl = s->priv_data; |
|
| 63 |
+ AVIOContext *pb = s->pb; |
|
| 64 |
+ uint32_t current_size; |
|
| 65 |
+ uint16_t audio_size, palette_size; |
|
| 66 |
+ int32_t video_size; |
|
| 67 |
+ int64_t pos; |
|
| 68 |
+ int ret; |
|
| 69 |
+ |
|
| 70 |
+ if (pb->eof_reached) |
|
| 71 |
+ return AVERROR_EOF; |
|
| 72 |
+ |
|
| 73 |
+ pos = avio_tell(pb); |
|
| 74 |
+ if (!cdxl->read_chunk && |
|
| 75 |
+ avio_read(pb, cdxl->header, CDXL_HEADER_SIZE) != CDXL_HEADER_SIZE) |
|
| 76 |
+ return AVERROR_EOF; |
|
| 77 |
+ if (cdxl->header[0] != 1) {
|
|
| 78 |
+ av_log(s, AV_LOG_ERROR, "non-standard cdxl file\n"); |
|
| 79 |
+ return AVERROR_INVALIDDATA; |
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 82 |
+ current_size = AV_RB32(&cdxl->header[2]); |
|
| 83 |
+ palette_size = AV_RB16(&cdxl->header[20]); |
|
| 84 |
+ audio_size = AV_RB16(&cdxl->header[22]); |
|
| 85 |
+ |
|
| 86 |
+ if (palette_size > 512) |
|
| 87 |
+ return AVERROR_INVALIDDATA; |
|
| 88 |
+ if (current_size < audio_size + palette_size + CDXL_HEADER_SIZE) |
|
| 89 |
+ return AVERROR_INVALIDDATA; |
|
| 90 |
+ video_size = current_size - audio_size - CDXL_HEADER_SIZE; |
|
| 91 |
+ |
|
| 92 |
+ if (cdxl->read_chunk && audio_size) {
|
|
| 93 |
+ if (cdxl->audio_stream_index == -1) {
|
|
| 94 |
+ AVStream *st = avformat_new_stream(s, NULL); |
|
| 95 |
+ if (!st) |
|
| 96 |
+ return AVERROR(ENOMEM); |
|
| 97 |
+ |
|
| 98 |
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; |
|
| 99 |
+ st->codec->codec_tag = 0; |
|
| 100 |
+ st->codec->codec_id = CODEC_ID_PCM_S8; |
|
| 101 |
+ st->codec->channels = cdxl->header[1] & 0x10 ? 2 : 1; |
|
| 102 |
+ st->codec->sample_rate = cdxl->sample_rate; |
|
| 103 |
+ cdxl->audio_stream_index = st->index; |
|
| 104 |
+ avpriv_set_pts_info(st, 32, 1, cdxl->sample_rate); |
|
| 105 |
+ } |
|
| 106 |
+ |
|
| 107 |
+ ret = av_get_packet(pb, pkt, audio_size); |
|
| 108 |
+ if (ret < 0) |
|
| 109 |
+ return ret; |
|
| 110 |
+ pkt->stream_index = cdxl->audio_stream_index; |
|
| 111 |
+ pkt->pos = pos; |
|
| 112 |
+ pkt->duration = audio_size; |
|
| 113 |
+ cdxl->read_chunk = 0; |
|
| 114 |
+ } else {
|
|
| 115 |
+ if (cdxl->video_stream_index == -1) {
|
|
| 116 |
+ AVStream *st = avformat_new_stream(s, NULL); |
|
| 117 |
+ if (!st) |
|
| 118 |
+ return AVERROR(ENOMEM); |
|
| 119 |
+ |
|
| 120 |
+ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; |
|
| 121 |
+ st->codec->codec_tag = 0; |
|
| 122 |
+ st->codec->codec_id = CODEC_ID_CDXL; |
|
| 123 |
+ st->codec->width = AV_RB16(&cdxl->header[14]); |
|
| 124 |
+ st->codec->height = AV_RB16(&cdxl->header[16]); |
|
| 125 |
+ cdxl->video_stream_index = st->index; |
|
| 126 |
+ avpriv_set_pts_info(st, 63, cdxl->fps.den, cdxl->fps.num); |
|
| 127 |
+ } |
|
| 128 |
+ |
|
| 129 |
+ if (av_new_packet(pkt, video_size + CDXL_HEADER_SIZE) < 0) |
|
| 130 |
+ return AVERROR(ENOMEM); |
|
| 131 |
+ memcpy(pkt->data, cdxl->header, CDXL_HEADER_SIZE); |
|
| 132 |
+ ret = avio_read(pb, pkt->data + CDXL_HEADER_SIZE, video_size); |
|
| 133 |
+ if (ret < 0) {
|
|
| 134 |
+ av_free_packet(pkt); |
|
| 135 |
+ return ret; |
|
| 136 |
+ } |
|
| 137 |
+ pkt->stream_index = cdxl->video_stream_index; |
|
| 138 |
+ pkt->flags |= AV_PKT_FLAG_KEY; |
|
| 139 |
+ pkt->pos = pos; |
|
| 140 |
+ cdxl->read_chunk = audio_size; |
|
| 141 |
+ } |
|
| 142 |
+ |
|
| 143 |
+ return ret; |
|
| 144 |
+} |
|
| 145 |
+ |
|
| 146 |
+#define OFFSET(x) offsetof(CDXLDemuxContext, x) |
|
| 147 |
+static const AVOption cdxl_options[] = {
|
|
| 148 |
+ { "sample_rate", "", OFFSET(sample_rate), AV_OPT_TYPE_INT, { .dbl = 11025 }, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
|
|
| 149 |
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = "10" }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
|
|
| 150 |
+ { NULL },
|
|
| 151 |
+}; |
|
| 152 |
+ |
|
| 153 |
+static const AVClass cdxl_demuxer_class = {
|
|
| 154 |
+ .class_name = "CDXL demuxer", |
|
| 155 |
+ .item_name = av_default_item_name, |
|
| 156 |
+ .option = cdxl_options, |
|
| 157 |
+ .version = LIBAVUTIL_VERSION_INT, |
|
| 158 |
+}; |
|
| 159 |
+ |
|
| 160 |
+AVInputFormat ff_cdxl_demuxer = {
|
|
| 161 |
+ .name = "cdxl", |
|
| 162 |
+ .long_name = NULL_IF_CONFIG_SMALL("Commodore CDXL video format"),
|
|
| 163 |
+ .priv_data_size = sizeof(CDXLDemuxContext), |
|
| 164 |
+ .read_header = cdxl_read_header, |
|
| 165 |
+ .read_packet = cdxl_read_packet, |
|
| 166 |
+ .extensions = "cdxl,xl", |
|
| 167 |
+ .flags = AVFMT_GENERIC_INDEX, |
|
| 168 |
+ .priv_class = &cdxl_demuxer_class, |
|
| 169 |
+}; |
| ... | ... |
@@ -30,7 +30,7 @@ |
| 30 | 30 |
#include "libavutil/avutil.h" |
| 31 | 31 |
|
| 32 | 32 |
#define LIBAVFORMAT_VERSION_MAJOR 54 |
| 33 |
-#define LIBAVFORMAT_VERSION_MINOR 0 |
|
| 33 |
+#define LIBAVFORMAT_VERSION_MINOR 1 |
|
| 34 | 34 |
#define LIBAVFORMAT_VERSION_MICRO 0 |
| 35 | 35 |
|
| 36 | 36 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |