History

avformat/cdxl: add support for custom 24bit pal8 formats

Also stop discarding half of audio samples and use planar pcm s8.

Paul B Mahol committed 5 years ago

Commit e8189511 parent e6254d53 files · +37 −22Browse files

Unified · Split

3 files
  1. libavcodec/cdxl.c +20 −9
  2. libavformat/cdxl.c +16 −12
  3. tests/ref/fate/cdxl-demux +1 −1
libavcodec/cdxl.c+20−9
@@ -43,6 +43,7 @@ · 42 unmodified lines
43typedef struct CDXLVideoContext {43typedef struct CDXLVideoContext {
44 AVCodecContext *avctx;44 AVCodecContext *avctx;
45 int bpp;45 int bpp;
46 int type;
46 int format;47 int format;
47 int padded_bits;48 int padded_bits;
48 const uint8_t *palette;49 const uint8_t *palette;
@@ -65,14 +66,19 @@ static av_cold int cdxl_decode_init(AVCodecContext *avctx) · 16 unmodified lines
65 66
66static void import_palette(CDXLVideoContext *c, uint32_t *new_palette)67static void import_palette(CDXLVideoContext *c, uint32_t *new_palette)
67{68{
68 int i;69 if (c->type == 1) {
69 70 for (int i = 0; i < c->palette_size / 2; i++) {
70 for (i = 0; i < c->palette_size / 2; i++) {71 unsigned rgb = AV_RB16(&c->palette[i * 2]);
71 unsigned rgb = AV_RB16(&c->palette[i * 2]);72 unsigned r = ((rgb >> 8) & 0xF) * 0x11;
72 unsigned r = ((rgb >> 8) & 0xF) * 0x11;73 unsigned g = ((rgb >> 4) & 0xF) * 0x11;
73 unsigned g = ((rgb >> 4) & 0xF) * 0x11;74 unsigned b = (rgb & 0xF) * 0x11;
74 unsigned b = (rgb & 0xF) * 0x11;75 AV_WN32(&new_palette[i], (0xFFU << 24) | (r << 16) | (g << 8) | b);
75 AV_WN32(&new_palette[i], (0xFFU << 24) | (r << 16) | (g << 8) | b);76 }
77 } else {
78 for (int i = 0; i < c->palette_size / 3; i++) {
79 unsigned rgb = AV_RB24(&c->palette[i * 3]);
80 AV_WN32(&new_palette[i], (0xFFU << 24) | rgb);
81 }
76 }82 }
77}83}
78 84
@@ -246,6 +252,7 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data, · 167 unmodified lines
246 252
247 if (buf_size < 32)253 if (buf_size < 32)
248 return AVERROR_INVALIDDATA;254 return AVERROR_INVALIDDATA;
255 c->type = buf[0];
249 encoding = buf[1] & 7;256 encoding = buf[1] & 7;
250 c->format = buf[1] & 0xE0;257 c->format = buf[1] & 0xE0;
251 w = AV_RB16(&buf[14]);258 w = AV_RB16(&buf[14]);
@@ -256,7 +263,11 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data, · 4 unmodified lines
256 c->video = c->palette + c->palette_size;263 c->video = c->palette + c->palette_size;
257 c->video_size = buf_size - c->palette_size - 32;264 c->video_size = buf_size - c->palette_size - 32;
258 265
259 if (c->palette_size > 512)266 if (c->type > 1)
267 return AVERROR_INVALIDDATA;
268 if (c->type == 1 && c->palette_size > 512)
269 return AVERROR_INVALIDDATA;
270 if (c->type == 0 && c->palette_size > 768)
260 return AVERROR_INVALIDDATA;271 return AVERROR_INVALIDDATA;
261 if (buf_size < c->palette_size + 32)272 if (buf_size < c->palette_size + 32)
262 return AVERROR_INVALIDDATA;273 return AVERROR_INVALIDDATA;
libavformat/cdxl.c+16−12
@@ -47,16 +47,18 @@ static int cdxl_read_probe(const AVProbeData *p) · 46 unmodified lines
47 if (p->buf_size < CDXL_HEADER_SIZE)47 if (p->buf_size < CDXL_HEADER_SIZE)
48 return 0;48 return 0;
49 49
50 /* reserved bytes should always be set to 0 */50 /* check type */
51 if (AV_RN64(&p->buf[24]) || AV_RN16(&p->buf[10]))51 if (p->buf[0] > 1)
52 return 0;52 return 0;
53 53
54 /* check type */54 /* reserved bytes should always be set to 0 */
55 if (p->buf[0] != 1)55 if (p->buf[0] == 1 && (AV_RN64(&p->buf[24]) || AV_RN16(&p->buf[10])))
56 return 0;56 return 0;
57 57
58 /* check palette size */58 /* check palette size */
59 if (AV_RB16(&p->buf[20]) > 512)59 if (p->buf[0] == 1 && AV_RB16(&p->buf[20]) > 512)
60 return 0;
61 if (p->buf[0] == 0 && AV_RB16(&p->buf[20]) > 768)
60 return 0;62 return 0;
61 63
62 /* check number of planes */64 /* check number of planes */
@@ -111,7 +113,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 48 unmodified lines
111 uint32_t current_size, video_size, image_size;113 uint32_t current_size, video_size, image_size;
112 uint16_t audio_size, palette_size, width, height;114 uint16_t audio_size, palette_size, width, height;
113 int64_t pos;115 int64_t pos;
114 int format, frames, ret;116 int type, format, frames, ret;
115 117
116 if (avio_feof(pb))118 if (avio_feof(pb))
117 return AVERROR_EOF;119 return AVERROR_EOF;
@@ -120,17 +122,18 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 2 unmodified lines
120 if (!cdxl->read_chunk &&122 if (!cdxl->read_chunk &&
121 avio_read(pb, cdxl->header, CDXL_HEADER_SIZE) != CDXL_HEADER_SIZE)123 avio_read(pb, cdxl->header, CDXL_HEADER_SIZE) != CDXL_HEADER_SIZE)
122 return AVERROR_EOF;124 return AVERROR_EOF;
123 if (cdxl->header[0] != 1) {125 if (cdxl->header[0] > 1) {
124 av_log(s, AV_LOG_ERROR, "non-standard cdxl file\n");126 av_log(s, AV_LOG_ERROR, "unsupported cdxl file\n");
125 return AVERROR_INVALIDDATA;127 return AVERROR_INVALIDDATA;
126 }128 }
127 129
130 type = cdxl->header[0];
128 format = cdxl->header[1] & 0xE0;131 format = cdxl->header[1] & 0xE0;
129 current_size = AV_RB32(&cdxl->header[2]);132 current_size = AV_RB32(&cdxl->header[2]);
130 width = AV_RB16(&cdxl->header[14]);133 width = AV_RB16(&cdxl->header[14]);
131 height = AV_RB16(&cdxl->header[16]);134 height = AV_RB16(&cdxl->header[16]);
132 palette_size = AV_RB16(&cdxl->header[20]);135 palette_size = AV_RB16(&cdxl->header[20]);
133 audio_size = AV_RB16(&cdxl->header[22]);136 audio_size = AV_RB16(&cdxl->header[22]) * (1 + !!(cdxl->header[1] & 0x10));
134 if (cdxl->header[19] == 0 ||137 if (cdxl->header[19] == 0 ||
135 FFALIGN(width, 16) * (uint64_t)height * cdxl->header[19] > INT_MAX)138 FFALIGN(width, 16) * (uint64_t)height * cdxl->header[19] > INT_MAX)
136 return AVERROR_INVALIDDATA;139 return AVERROR_INVALIDDATA;
@@ -140,7 +143,8 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 3 unmodified lines
140 image_size = FFALIGN(width, 16) * height * cdxl->header[19] / 8;143 image_size = FFALIGN(width, 16) * height * cdxl->header[19] / 8;
141 video_size = palette_size + image_size;144 video_size = palette_size + image_size;
142 145
143 if (palette_size > 512)146 if ((type == 1 && palette_size > 512) ||
147 (type == 0 && palette_size > 768))
144 return AVERROR_INVALIDDATA;148 return AVERROR_INVALIDDATA;
145 if (current_size < (uint64_t)audio_size + video_size + CDXL_HEADER_SIZE)149 if (current_size < (uint64_t)audio_size + video_size + CDXL_HEADER_SIZE)
146 return AVERROR_INVALIDDATA;150 return AVERROR_INVALIDDATA;
@@ -153,7 +157,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 6 unmodified lines
153 157
154 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;158 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
155 st->codecpar->codec_tag = 0;159 st->codecpar->codec_tag = 0;
156 st->codecpar->codec_id = AV_CODEC_ID_PCM_S8;160 st->codecpar->codec_id = AV_CODEC_ID_PCM_S8_PLANAR;
157 if (cdxl->header[1] & 0x10) {161 if (cdxl->header[1] & 0x10) {
158 st->codecpar->channels = 2;162 st->codecpar->channels = 2;
159 st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;163 st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
@@ -189,7 +193,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 29 unmodified lines
189 if (audio_size + video_size && cdxl->filesize > 0) {193 if (audio_size + video_size && cdxl->filesize > 0) {
190 frames = cdxl->filesize / (audio_size + video_size);194 frames = cdxl->filesize / (audio_size + video_size);
191 195
192 if(cdxl->framerate)196 if (cdxl->framerate)
193 st->duration = frames;197 st->duration = frames;
194 else198 else
195 st->duration = frames * (int64_t)audio_size;199 st->duration = frames * (int64_t)audio_size;
tests/ref/fate/cdxl-demux+1−1
@@ -5,7 +5,7 @@ · 4 unmodified lines
5#sar 0: 0/15#sar 0: 0/1
6#tb 1: 1/110256#tb 1: 1/11025
7#media_type 1: audio7#media_type 1: audio
8#codec_id 1: pcm_s88#codec_id 1: pcm_s8_planar
9#sample_rate 1: 110259#sample_rate 1: 11025
10#channel_layout 1: 410#channel_layout 1: 4
11#channel_layout_name 1: mono11#channel_layout_name 1: mono

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t