Originally committed as revision 9169 to svn://svn.ffmpeg.org/ffmpeg/trunk
Ramiro Polla authored on 2007/06/02 10:41:07... | ... |
@@ -1136,12 +1136,10 @@ static int output_frame_end(AC3EncodeContext *s) |
1136 | 1136 |
/* XXX: could precompute crc_inv */ |
1137 | 1137 |
crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY); |
1138 | 1138 |
crc1 = mul_poly(crc_inv, crc1, CRC16_POLY); |
1139 |
- frame[2] = crc1 >> 8; |
|
1140 |
- frame[3] = crc1; |
|
1139 |
+ AV_WB16(frame+2,crc1); |
|
1141 | 1140 |
|
1142 | 1141 |
crc2 = bswap_16(av_crc(av_crc8005, 0, frame + 2 * frame_size_58, (frame_size - frame_size_58) * 2 - 2)); |
1143 |
- frame[2*frame_size - 2] = crc2 >> 8; |
|
1144 |
- frame[2*frame_size - 1] = crc2; |
|
1142 |
+ AV_WB16(frame+2*frame_size-2,crc2); |
|
1145 | 1143 |
|
1146 | 1144 |
// printf("n=%d frame_size=%d\n", n, frame_size); |
1147 | 1145 |
return frame_size * 2; |
... | ... |
@@ -451,16 +451,14 @@ static int adpcm_encode_frame(AVCodecContext *avctx, |
451 | 451 |
n = avctx->frame_size / 8; |
452 | 452 |
c->status[0].prev_sample = (signed short)samples[0]; /* XXX */ |
453 | 453 |
/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */ |
454 |
- *dst++ = (c->status[0].prev_sample) & 0xFF; /* little endian */ |
|
455 |
- *dst++ = (c->status[0].prev_sample >> 8) & 0xFF; |
|
454 |
+ bytestream_put_le16(&dst, c->status[0].prev_sample); |
|
456 | 455 |
*dst++ = (unsigned char)c->status[0].step_index; |
457 | 456 |
*dst++ = 0; /* unknown */ |
458 | 457 |
samples++; |
459 | 458 |
if (avctx->channels == 2) { |
460 | 459 |
c->status[1].prev_sample = (signed short)samples[1]; |
461 | 460 |
/* c->status[1].step_index = 0; */ |
462 |
- *dst++ = (c->status[1].prev_sample) & 0xFF; |
|
463 |
- *dst++ = (c->status[1].prev_sample >> 8) & 0xFF; |
|
461 |
+ bytestream_put_le16(&dst, c->status[1].prev_sample); |
|
464 | 462 |
*dst++ = (unsigned char)c->status[1].step_index; |
465 | 463 |
*dst++ = 0; |
466 | 464 |
samples++; |
... | ... |
@@ -553,20 +551,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, |
553 | 553 |
if (c->status[i].idelta < 16) |
554 | 554 |
c->status[i].idelta = 16; |
555 | 555 |
|
556 |
- *dst++ = c->status[i].idelta & 0xFF; |
|
557 |
- *dst++ = c->status[i].idelta >> 8; |
|
556 |
+ bytestream_put_le16(&dst, c->status[i].idelta); |
|
558 | 557 |
} |
559 | 558 |
for(i=0; i<avctx->channels; i++){ |
560 | 559 |
c->status[i].sample1= *samples++; |
561 | 560 |
|
562 |
- *dst++ = c->status[i].sample1 & 0xFF; |
|
563 |
- *dst++ = c->status[i].sample1 >> 8; |
|
561 |
+ bytestream_put_le16(&dst, c->status[i].sample1); |
|
564 | 562 |
} |
565 | 563 |
for(i=0; i<avctx->channels; i++){ |
566 | 564 |
c->status[i].sample2= *samples++; |
567 | 565 |
|
568 |
- *dst++ = c->status[i].sample2 & 0xFF; |
|
569 |
- *dst++ = c->status[i].sample2 >> 8; |
|
566 |
+ bytestream_put_le16(&dst, c->status[i].sample2); |
|
570 | 567 |
} |
571 | 568 |
|
572 | 569 |
if(avctx->trellis > 0) { |
... | ... |
@@ -25,6 +25,7 @@ |
25 | 25 |
*/ |
26 | 26 |
|
27 | 27 |
#include "avcodec.h" |
28 |
+#include "bytestream.h" |
|
28 | 29 |
|
29 | 30 |
|
30 | 31 |
typedef enum CinVideoBitmapIndex { |
... | ... |
@@ -206,7 +207,7 @@ static int cinvideo_decode_frame(AVCodecContext *avctx, |
206 | 206 |
} |
207 | 207 |
|
208 | 208 |
palette_type = buf[0]; |
209 |
- palette_colors_count = buf[1] | (buf[2] << 8); |
|
209 |
+ palette_colors_count = AV_RL16(buf+1); |
|
210 | 210 |
bitmap_frame_type = buf[3]; |
211 | 211 |
buf += 4; |
212 | 212 |
|
... | ... |
@@ -215,13 +216,12 @@ static int cinvideo_decode_frame(AVCodecContext *avctx, |
215 | 215 |
/* handle palette */ |
216 | 216 |
if (palette_type == 0) { |
217 | 217 |
for (i = 0; i < palette_colors_count; ++i) { |
218 |
- cin->palette[i] = (buf[2] << 16) | (buf[1] << 8) | buf[0]; |
|
219 |
- buf += 3; |
|
218 |
+ cin->palette[i] = bytestream_get_le24(&buf); |
|
220 | 219 |
bitmap_frame_size -= 3; |
221 | 220 |
} |
222 | 221 |
} else { |
223 | 222 |
for (i = 0; i < palette_colors_count; ++i) { |
224 |
- cin->palette[buf[0]] = (buf[3] << 16) | (buf[2] << 8) | buf[1]; |
|
223 |
+ cin->palette[buf[0]] = AV_RL24(buf+1); |
|
225 | 224 |
buf += 4; |
226 | 225 |
bitmap_frame_size -= 4; |
227 | 226 |
} |
... | ... |
@@ -132,13 +132,9 @@ static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value) |
132 | 132 |
} else { |
133 | 133 |
bit_buf |= value << (bit_cnt); |
134 | 134 |
|
135 |
- *s->buf_ptr = bit_buf & 0xff; |
|
136 |
- s->buf_ptr[1] = (bit_buf >> 8) & 0xff; |
|
137 |
- s->buf_ptr[2] = (bit_buf >> 16) & 0xff; |
|
138 |
- s->buf_ptr[3] = (bit_buf >> 24) & 0xff; |
|
135 |
+ bytestream_put_le32(&s->buf_ptr, bit_buf); |
|
139 | 136 |
|
140 | 137 |
//printf("bitbuf = %08x\n", bit_buf); |
141 |
- s->buf_ptr+=4; |
|
142 | 138 |
if (s->buf_ptr >= s->buf_end) |
143 | 139 |
puts("bit buffer overflow !!"); // should never happen ! who got rid of the callback ??? |
144 | 140 |
// flush_buffer_rev(s); |
... | ... |
@@ -195,9 +191,7 @@ static int gif_image_write_header(uint8_t **bytestream, |
195 | 195 |
} else { |
196 | 196 |
for(i=0;i<256;i++) { |
197 | 197 |
v = palette[i]; |
198 |
- bytestream_put_byte(bytestream, (v >> 16) & 0xff); |
|
199 |
- bytestream_put_byte(bytestream, (v >> 8) & 0xff); |
|
200 |
- bytestream_put_byte(bytestream, (v) & 0xff); |
|
198 |
+ bytestream_put_be24(bytestream, v); |
|
201 | 199 |
} |
202 | 200 |
} |
203 | 201 |
|
... | ... |
@@ -96,8 +96,7 @@ static int gif_read_image(GifState *s) |
96 | 96 |
n = (1 << bits_per_pixel); |
97 | 97 |
spal = palette; |
98 | 98 |
for(i = 0; i < n; i++) { |
99 |
- s->image_palette[i] = (0xff << 24) | |
|
100 |
- (spal[0] << 16) | (spal[1] << 8) | (spal[2]); |
|
99 |
+ s->image_palette[i] = (0xff << 24) | AV_RB24(spal); |
|
101 | 100 |
spal += 3; |
102 | 101 |
} |
103 | 102 |
for(; i < 256; i++) |
... | ... |
@@ -41,6 +41,7 @@ |
41 | 41 |
#include <unistd.h> |
42 | 42 |
|
43 | 43 |
#include "avcodec.h" |
44 |
+#include "bytestream.h" |
|
44 | 45 |
#include "dsputil.h" |
45 | 46 |
|
46 | 47 |
#define PALETTE_COUNT 256 |
... | ... |
@@ -297,10 +298,8 @@ static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s) |
297 | 297 |
|
298 | 298 |
/* need 2 more bytes from the stream */ |
299 | 299 |
CHECK_STREAM_PTR(2); |
300 |
- B[0] = *s->stream_ptr++; |
|
301 |
- B[1] = *s->stream_ptr++; |
|
302 | 300 |
|
303 |
- flags = (B[1] << 8) | B[0]; |
|
301 |
+ flags = bytestream_get_le16(&s->stream_ptr); |
|
304 | 302 |
bitmask = 0x0001; |
305 | 303 |
for (y = 0; y < 8; y += 2) { |
306 | 304 |
for (x = 0; x < 8; x += 2, bitmask <<= 1) { |
... | ... |
@@ -478,7 +477,6 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) |
478 | 478 |
{ |
479 | 479 |
int x, y; |
480 | 480 |
unsigned char P[4]; |
481 |
- unsigned char B[4]; |
|
482 | 481 |
unsigned int flags = 0; |
483 | 482 |
int shifter = 0; |
484 | 483 |
unsigned char pix; |
... | ... |
@@ -496,8 +494,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) |
496 | 496 |
|
497 | 497 |
for (y = 0; y < 8; y++) { |
498 | 498 |
/* get the next set of 8 2-bit flags */ |
499 |
- flags = (s->stream_ptr[1] << 8) | s->stream_ptr[0]; |
|
500 |
- s->stream_ptr += 2; |
|
499 |
+ flags = bytestream_get_le16(&s->stream_ptr); |
|
501 | 500 |
for (x = 0, shifter = 0; x < 8; x++, shifter += 2) { |
502 | 501 |
*s->pixel_ptr++ = P[(flags >> shifter) & 0x03]; |
503 | 502 |
} |
... | ... |
@@ -509,11 +506,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) |
509 | 509 |
/* 1 of 4 colors for each 2x2 block, need 4 more bytes */ |
510 | 510 |
CHECK_STREAM_PTR(4); |
511 | 511 |
|
512 |
- B[0] = *s->stream_ptr++; |
|
513 |
- B[1] = *s->stream_ptr++; |
|
514 |
- B[2] = *s->stream_ptr++; |
|
515 |
- B[3] = *s->stream_ptr++; |
|
516 |
- flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; |
|
512 |
+ flags = bytestream_get_le32(&s->stream_ptr); |
|
517 | 513 |
shifter = 0; |
518 | 514 |
|
519 | 515 |
for (y = 0; y < 8; y += 2) { |
... | ... |
@@ -535,11 +528,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) |
535 | 535 |
for (y = 0; y < 8; y++) { |
536 | 536 |
/* time to reload flags? */ |
537 | 537 |
if ((y == 0) || (y == 4)) { |
538 |
- B[0] = *s->stream_ptr++; |
|
539 |
- B[1] = *s->stream_ptr++; |
|
540 |
- B[2] = *s->stream_ptr++; |
|
541 |
- B[3] = *s->stream_ptr++; |
|
542 |
- flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; |
|
538 |
+ flags = bytestream_get_le32(&s->stream_ptr); |
|
543 | 539 |
shifter = 0; |
544 | 540 |
} |
545 | 541 |
for (x = 0; x < 8; x += 2, shifter += 2) { |
... | ... |
@@ -558,11 +547,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) |
558 | 558 |
for (y = 0; y < 8; y += 2) { |
559 | 559 |
/* time to reload flags? */ |
560 | 560 |
if ((y == 0) || (y == 4)) { |
561 |
- B[0] = *s->stream_ptr++; |
|
562 |
- B[1] = *s->stream_ptr++; |
|
563 |
- B[2] = *s->stream_ptr++; |
|
564 |
- B[3] = *s->stream_ptr++; |
|
565 |
- flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; |
|
561 |
+ flags = bytestream_get_le32(&s->stream_ptr); |
|
566 | 562 |
shifter = 0; |
567 | 563 |
} |
568 | 564 |
for (x = 0; x < 8; x++, shifter += 2) { |
... | ... |
@@ -29,6 +29,7 @@ |
29 | 29 |
#include <stdlib.h> |
30 | 30 |
|
31 | 31 |
#include "avcodec.h" |
32 |
+#include "bytestream.h" |
|
32 | 33 |
|
33 | 34 |
#define KMVC_KEYFRAME 0x80 |
34 | 35 |
#define KMVC_PALETTE 0x40 |
... | ... |
@@ -249,7 +250,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint |
249 | 249 |
if (buf[0] == 127) { |
250 | 250 |
buf += 3; |
251 | 251 |
for (i = 0; i < 127; i++) { |
252 |
- ctx->pal[i + (header & 0x81)] = (buf[0] << 16) | (buf[1] << 8) | buf[2]; |
|
252 |
+ ctx->pal[i + (header & 0x81)] = AV_RB24(buf); |
|
253 | 253 |
buf += 4; |
254 | 254 |
} |
255 | 255 |
buf -= 127 * 4 + 3; |
... | ... |
@@ -274,8 +275,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint |
274 | 274 |
ctx->pic.palette_has_changed = 1; |
275 | 275 |
// palette starts from index 1 and has 127 entries |
276 | 276 |
for (i = 1; i <= ctx->palsize; i++) { |
277 |
- ctx->pal[i] = (buf[0] << 16) | (buf[1] << 8) | buf[2]; |
|
278 |
- buf += 3; |
|
277 |
+ ctx->pal[i] = bytestream_get_be24(&buf); |
|
279 | 278 |
} |
280 | 279 |
} |
281 | 280 |
|
... | ... |
@@ -358,13 +358,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 |
358 | 358 |
for (row = 0; row < height; row++) { |
359 | 359 |
pixel_ptr = row * width * 3; |
360 | 360 |
yq = encoded[pixel_ptr++]; |
361 |
- uqvq = encoded[pixel_ptr++]; |
|
362 |
- uqvq+=(encoded[pixel_ptr++] << 8); |
|
361 |
+ uqvq = AV_RL16(encoded+pixel_ptr); |
|
362 |
+ pixel_ptr += 2; |
|
363 | 363 |
for (col = 1; col < width; col++) { |
364 | 364 |
encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; |
365 |
- uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8)); |
|
366 |
- encoded[pixel_ptr+1] = (uqvq) & 0xff; |
|
367 |
- encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff; |
|
365 |
+ uqvq -= AV_RL16(encoded+pixel_ptr+1); |
|
366 |
+ AV_WL16(encoded+pixel_ptr+1, uqvq); |
|
368 | 367 |
pixel_ptr += 3; |
369 | 368 |
} |
370 | 369 |
} |
... | ... |
@@ -69,8 +69,8 @@ static int concatenate_packet(unsigned int* offset, AVCodecContext* avc_context, |
69 | 69 |
|
70 | 70 |
avc_context->extradata = newdata; |
71 | 71 |
avc_context->extradata_size = newsize; |
72 |
- avc_context->extradata[ (*offset)++ ] = packet->bytes >> 8; |
|
73 |
- avc_context->extradata[ (*offset)++ ] = packet->bytes & 0xff; |
|
72 |
+ AV_WB16(avc_context->extradata + (*offset), packet->bytes); |
|
73 |
+ *offset += 2; |
|
74 | 74 |
memcpy( avc_context->extradata + (*offset), packet->packet, packet->bytes ); |
75 | 75 |
(*offset) += packet->bytes; |
76 | 76 |
return 0; |
... | ... |
@@ -147,8 +147,7 @@ static void jpeg_table_header(MpegEncContext *s) |
147 | 147 |
ff_mjpeg_val_ac_luminance); |
148 | 148 |
size += put_huffman_table(s, 1, 1, ff_mjpeg_bits_ac_chrominance, |
149 | 149 |
ff_mjpeg_val_ac_chrominance); |
150 |
- ptr[0] = size >> 8; |
|
151 |
- ptr[1] = size; |
|
150 |
+ AV_WB16(ptr, size); |
|
152 | 151 |
} |
153 | 152 |
|
154 | 153 |
static void jpeg_put_comments(MpegEncContext *s) |
... | ... |
@@ -179,8 +178,7 @@ static void jpeg_put_comments(MpegEncContext *s) |
179 | 179 |
put_bits(p, 16, 0); /* patched later */ |
180 | 180 |
ff_put_string(p, LIBAVCODEC_IDENT, 1); |
181 | 181 |
size = strlen(LIBAVCODEC_IDENT)+3; |
182 |
- ptr[0] = size >> 8; |
|
183 |
- ptr[1] = size; |
|
182 |
+ AV_WB16(ptr, size); |
|
184 | 183 |
} |
185 | 184 |
|
186 | 185 |
if( s->avctx->pix_fmt == PIX_FMT_YUV420P |
... | ... |
@@ -192,8 +190,7 @@ static void jpeg_put_comments(MpegEncContext *s) |
192 | 192 |
put_bits(p, 16, 0); /* patched later */ |
193 | 193 |
ff_put_string(p, "CS=ITU601", 1); |
194 | 194 |
size = strlen("CS=ITU601")+3; |
195 |
- ptr[0] = size >> 8; |
|
196 |
- ptr[1] = size; |
|
195 |
+ AV_WB16(ptr, size); |
|
197 | 196 |
} |
198 | 197 |
} |
199 | 198 |
|
... | ... |
@@ -84,10 +84,7 @@ static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext |
84 | 84 |
} |
85 | 85 |
} |
86 | 86 |
|
87 |
- (*poutbuf)[0]= header>>24; |
|
88 |
- (*poutbuf)[1]= header>>16; |
|
89 |
- (*poutbuf)[2]= header>> 8; |
|
90 |
- (*poutbuf)[3]= header ; |
|
87 |
+ AV_WB32(*poutbuf, header); |
|
91 | 88 |
|
92 | 89 |
return 1; |
93 | 90 |
} |
... | ... |
@@ -106,8 +106,7 @@ static const int sBitsPerSlot[3] = { |
106 | 106 |
|
107 | 107 |
static int mp3len(void *data, int *samplesPerFrame, int *sampleRate) |
108 | 108 |
{ |
109 |
- uint8_t *dataTmp = (uint8_t *)data; |
|
110 |
- uint32_t header = ( (uint32_t)dataTmp[0] << 24 ) | ( (uint32_t)dataTmp[1] << 16 ) | ( (uint32_t)dataTmp[2] << 8 ) | (uint32_t)dataTmp[3]; |
|
109 |
+ uint32_t header = AV_RB32(data); |
|
111 | 110 |
int layerID = 3 - ((header >> 17) & 0x03); |
112 | 111 |
int bitRateID = ((header >> 12) & 0x0f); |
113 | 112 |
int sampleRateID = ((header >> 10) & 0x03); |
... | ... |
@@ -105,10 +105,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, |
105 | 105 |
/* special case for next header for first frame in free |
106 | 106 |
format case (XXX: find a simpler method) */ |
107 | 107 |
if (s->free_format_next_header != 0) { |
108 |
- s->inbuf[0] = s->free_format_next_header >> 24; |
|
109 |
- s->inbuf[1] = s->free_format_next_header >> 16; |
|
110 |
- s->inbuf[2] = s->free_format_next_header >> 8; |
|
111 |
- s->inbuf[3] = s->free_format_next_header; |
|
108 |
+ AV_WB32(s->inbuf, s->free_format_next_header); |
|
112 | 109 |
s->inbuf_ptr = s->inbuf + 4; |
113 | 110 |
s->free_format_next_header = 0; |
114 | 111 |
goto got_header; |
... | ... |
@@ -124,8 +121,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, |
124 | 124 |
} |
125 | 125 |
if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { |
126 | 126 |
got_header: |
127 |
- header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | |
|
128 |
- (s->inbuf[2] << 8) | s->inbuf[3]; |
|
127 |
+ header = AV_RB32(s->inbuf); |
|
129 | 128 |
|
130 | 129 |
ret = ff_mpa_decode_header(avctx, header, &sr); |
131 | 130 |
if (ret < 0) { |
... | ... |
@@ -176,10 +172,8 @@ static int mpegaudio_parse(AVCodecParserContext *s1, |
176 | 176 |
p = s->inbuf_ptr - 3; |
177 | 177 |
pend = s->inbuf_ptr + len - 4; |
178 | 178 |
while (p <= pend) { |
179 |
- header = (p[0] << 24) | (p[1] << 16) | |
|
180 |
- (p[2] << 8) | p[3]; |
|
181 |
- header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | |
|
182 |
- (s->inbuf[2] << 8) | s->inbuf[3]; |
|
179 |
+ header = AV_RB32(p); |
|
180 |
+ header1 = AV_RB32(s->inbuf); |
|
183 | 181 |
/* check with high probability that we have a |
184 | 182 |
valid header */ |
185 | 183 |
if ((header & SAME_HEADER_MASK) == |
... | ... |
@@ -2380,7 +2380,7 @@ retry: |
2380 | 2380 |
if(buf_size < HEADER_SIZE) |
2381 | 2381 |
return -1; |
2382 | 2382 |
|
2383 |
- header = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; |
|
2383 |
+ header = AV_RB32(buf); |
|
2384 | 2384 |
if(ff_mpa_check_header(header) < 0){ |
2385 | 2385 |
buf++; |
2386 | 2386 |
// buf_size--; |
... | ... |
@@ -2459,7 +2459,7 @@ static int decode_frame_adu(AVCodecContext * avctx, |
2459 | 2459 |
len = MPA_MAX_CODED_FRAME_SIZE; |
2460 | 2460 |
|
2461 | 2461 |
// Get header and restore sync word |
2462 |
- header = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3] | 0xffe00000; |
|
2462 |
+ header = AV_RB32(buf) | 0xffe00000; |
|
2463 | 2463 |
|
2464 | 2464 |
if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame |
2465 | 2465 |
*data_size = 0; |
... | ... |
@@ -2604,7 +2604,7 @@ static int decode_frame_mp3on4(AVCodecContext * avctx, |
2604 | 2604 |
assert (m != NULL); |
2605 | 2605 |
|
2606 | 2606 |
// Get header |
2607 |
- header = (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3] | 0xfff00000; |
|
2607 |
+ header = AV_RB32(start) | 0xfff00000; |
|
2608 | 2608 |
|
2609 | 2609 |
if (ff_mpa_check_header(header) < 0) { // Bad header, discard block |
2610 | 2610 |
*data_size = 0; |
... | ... |
@@ -27,6 +27,7 @@ |
27 | 27 |
#include <vorbis/vorbisenc.h> |
28 | 28 |
|
29 | 29 |
#include "avcodec.h" |
30 |
+#include "bytestream.h" |
|
30 | 31 |
|
31 | 32 |
#undef NDEBUG |
32 | 33 |
#include <assert.h> |
... | ... |
@@ -234,8 +235,7 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) { |
234 | 234 |
|
235 | 235 |
if(p[0] == 0 && p[1] == 30) { |
236 | 236 |
for(i = 0; i < 3; i++){ |
237 |
- hsizes[i] = *p++ << 8; |
|
238 |
- hsizes[i] += *p++; |
|
237 |
+ hsizes[i] = bytestream_get_be16(&p); |
|
239 | 238 |
headers[i] = p; |
240 | 239 |
p += hsizes[i]; |
241 | 240 |
} |
... | ... |
@@ -693,10 +693,7 @@ static void png_write_chunk(uint8_t **f, uint32_t tag, |
693 | 693 |
|
694 | 694 |
bytestream_put_be32(f, length); |
695 | 695 |
crc = crc32(0, Z_NULL, 0); |
696 |
- tagbuf[0] = tag; |
|
697 |
- tagbuf[1] = tag >> 8; |
|
698 |
- tagbuf[2] = tag >> 16; |
|
699 |
- tagbuf[3] = tag >> 24; |
|
696 |
+ AV_WL32(tagbuf, tag); |
|
700 | 697 |
crc = crc32(crc, tagbuf, 4); |
701 | 698 |
bytestream_put_be32(f, bswap_32(tag)); |
702 | 699 |
if (length > 0) { |
... | ... |
@@ -833,10 +830,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, |
833 | 833 |
if (alpha && alpha != 0xff) |
834 | 834 |
has_alpha = 1; |
835 | 835 |
*alpha_ptr++ = alpha; |
836 |
- ptr[0] = v >> 16; |
|
837 |
- ptr[1] = v >> 8; |
|
838 |
- ptr[2] = v; |
|
839 |
- ptr += 3; |
|
836 |
+ bytestream_put_be24(&ptr, v); |
|
840 | 837 |
} |
841 | 838 |
png_write_chunk(&s->bytestream, MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3); |
842 | 839 |
if (has_alpha) { |
... | ... |
@@ -19,6 +19,7 @@ |
19 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 |
*/ |
21 | 21 |
#include "avcodec.h" |
22 |
+#include "bytestream.h" |
|
22 | 23 |
#include "pnm.h" |
23 | 24 |
|
24 | 25 |
|
... | ... |
@@ -303,9 +304,7 @@ static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu |
303 | 303 |
for(i=0;i<h;i++) { |
304 | 304 |
for(j=0;j<w;j++) { |
305 | 305 |
v = ((uint32_t *)ptr)[j]; |
306 |
- *s->bytestream++ = v >> 16; |
|
307 |
- *s->bytestream++ = v >> 8; |
|
308 |
- *s->bytestream++ = v; |
|
306 |
+ bytestream_put_be24(&s->bytestream, v); |
|
309 | 307 |
*s->bytestream++ = v >> 24; |
310 | 308 |
} |
311 | 309 |
ptr += linesize; |
... | ... |
@@ -36,6 +36,7 @@ |
36 | 36 |
|
37 | 37 |
#include "avcodec.h" |
38 | 38 |
#include "rangecoder.h" |
39 |
+#include "bytestream.h" |
|
39 | 40 |
|
40 | 41 |
|
41 | 42 |
void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size){ |
... | ... |
@@ -53,8 +54,7 @@ void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size){ |
53 | 53 |
/* cast to avoid compiler warning */ |
54 | 54 |
ff_init_range_encoder(c, (uint8_t *) buf, buf_size); |
55 | 55 |
|
56 |
- c->low =(*c->bytestream++)<<8; |
|
57 |
- c->low+= *c->bytestream++; |
|
56 |
+ c->low = bytestream_get_be16(&c->bytestream); |
|
58 | 57 |
} |
59 | 58 |
|
60 | 59 |
void ff_build_rac_states(RangeCoder *c, int factor, int max_p){ |
... | ... |
@@ -436,11 +436,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 |
436 | 436 |
case 0: |
437 | 437 |
for(i = 0; i < 4; i++) { |
438 | 438 |
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last); |
439 |
- out[2] = pix & 0xFF; |
|
440 |
- out[3] = pix >> 8; |
|
439 |
+ AV_WL16(out+2,pix); |
|
441 | 440 |
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last); |
442 |
- out[0] = pix & 0xFF; |
|
443 |
- out[1] = pix >> 8; |
|
441 |
+ AV_WL16(out,pix); |
|
444 | 442 |
out += stride; |
445 | 443 |
} |
446 | 444 |
break; |
... | ... |
@@ -465,11 +463,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 |
465 | 465 |
uint16_t pix1, pix2; |
466 | 466 |
pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last); |
467 | 467 |
pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last); |
468 |
- out[0] = pix1 & 0xFF; out[1] = pix1 >> 8; |
|
469 |
- out[2] = pix2 & 0xFF; out[3] = pix2 >> 8; |
|
468 |
+ AV_WL16(out,pix1); |
|
469 |
+ AV_WL16(out+2,pix2); |
|
470 | 470 |
out += stride; |
471 |
- out[0] = pix1 & 0xFF; out[1] = pix1 >> 8; |
|
472 |
- out[2] = pix2 & 0xFF; out[3] = pix2 >> 8; |
|
471 |
+ AV_WL16(out,pix1); |
|
472 |
+ AV_WL16(out+2,pix2); |
|
473 | 473 |
out += stride; |
474 | 474 |
} |
475 | 475 |
break; |
... | ... |
@@ -65,10 +65,8 @@ static int sp5x_decode_frame(AVCodecContext *avctx, |
65 | 65 |
j += sizeof(sp5x_data_dht); |
66 | 66 |
|
67 | 67 |
memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof)); |
68 |
- recoded[j+5] = (avctx->coded_height >> 8) & 0xFF; |
|
69 |
- recoded[j+6] = avctx->coded_height & 0xFF; |
|
70 |
- recoded[j+7] = (avctx->coded_width >> 8) & 0xFF; |
|
71 |
- recoded[j+8] = avctx->coded_width & 0xFF; |
|
68 |
+ AV_WB16(recoded+j+5, avctx->coded_height); |
|
69 |
+ AV_WB16(recoded+j+7, avctx->coded_width); |
|
72 | 70 |
j += sizeof(sp5x_data_sof); |
73 | 71 |
|
74 | 72 |
memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos)); |
... | ... |
@@ -146,7 +146,7 @@ static void seqvideo_decode(SeqVideoContext *seq, unsigned char *data, int data_ |
146 | 146 |
for (i = 0; i < 256; i++) { |
147 | 147 |
for (j = 0; j < 3; j++, data++) |
148 | 148 |
c[j] = (*data << 2) | (*data >> 4); |
149 |
- seq->palette[i] = (c[0] << 16) | (c[1] << 8) | c[2]; |
|
149 |
+ seq->palette[i] = AV_RB24(c); |
|
150 | 150 |
} |
151 | 151 |
memcpy(seq->frame.data[1], seq->palette, sizeof(seq->palette)); |
152 | 152 |
seq->frame.palette_has_changed = 1; |
... | ... |
@@ -31,6 +31,7 @@ |
31 | 31 |
#include <unistd.h> |
32 | 32 |
|
33 | 33 |
#include "avcodec.h" |
34 |
+#include "bytestream.h" |
|
34 | 35 |
|
35 | 36 |
#include "ulti_cb.h" |
36 | 37 |
|
... | ... |
@@ -305,9 +306,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, |
305 | 305 |
|
306 | 306 |
case 2: |
307 | 307 |
if (modifier) { // unpack four luma samples |
308 |
- tmp = (*buf++) << 16; |
|
309 |
- tmp += (*buf++) << 8; |
|
310 |
- tmp += *buf++; |
|
308 |
+ tmp = bytestream_get_be24(&buf); |
|
311 | 309 |
|
312 | 310 |
Y[0] = (tmp >> 18) & 0x3F; |
313 | 311 |
Y[1] = (tmp >> 12) & 0x3F; |
... | ... |
@@ -315,8 +314,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, |
315 | 315 |
Y[3] = tmp & 0x3F; |
316 | 316 |
angle = 16; |
317 | 317 |
} else { // retrieve luma samples from codebook |
318 |
- tmp = (*buf++) << 8; |
|
319 |
- tmp += (*buf++); |
|
318 |
+ tmp = bytestream_get_be16(&buf); |
|
320 | 319 |
|
321 | 320 |
angle = (tmp >> 12) & 0xF; |
322 | 321 |
tmp &= 0xFFF; |
... | ... |
@@ -332,33 +330,25 @@ static int ulti_decode_frame(AVCodecContext *avctx, |
332 | 332 |
if (modifier) { // all 16 luma samples |
333 | 333 |
uint8_t Luma[16]; |
334 | 334 |
|
335 |
- tmp = (*buf++) << 16; |
|
336 |
- tmp += (*buf++) << 8; |
|
337 |
- tmp += *buf++; |
|
335 |
+ tmp = bytestream_get_be24(&buf); |
|
338 | 336 |
Luma[0] = (tmp >> 18) & 0x3F; |
339 | 337 |
Luma[1] = (tmp >> 12) & 0x3F; |
340 | 338 |
Luma[2] = (tmp >> 6) & 0x3F; |
341 | 339 |
Luma[3] = tmp & 0x3F; |
342 | 340 |
|
343 |
- tmp = (*buf++) << 16; |
|
344 |
- tmp += (*buf++) << 8; |
|
345 |
- tmp += *buf++; |
|
341 |
+ tmp = bytestream_get_be24(&buf); |
|
346 | 342 |
Luma[4] = (tmp >> 18) & 0x3F; |
347 | 343 |
Luma[5] = (tmp >> 12) & 0x3F; |
348 | 344 |
Luma[6] = (tmp >> 6) & 0x3F; |
349 | 345 |
Luma[7] = tmp & 0x3F; |
350 | 346 |
|
351 |
- tmp = (*buf++) << 16; |
|
352 |
- tmp += (*buf++) << 8; |
|
353 |
- tmp += *buf++; |
|
347 |
+ tmp = bytestream_get_be24(&buf); |
|
354 | 348 |
Luma[8] = (tmp >> 18) & 0x3F; |
355 | 349 |
Luma[9] = (tmp >> 12) & 0x3F; |
356 | 350 |
Luma[10] = (tmp >> 6) & 0x3F; |
357 | 351 |
Luma[11] = tmp & 0x3F; |
358 | 352 |
|
359 |
- tmp = (*buf++) << 16; |
|
360 |
- tmp += (*buf++) << 8; |
|
361 |
- tmp += *buf++; |
|
353 |
+ tmp = bytestream_get_be24(&buf); |
|
362 | 354 |
Luma[12] = (tmp >> 18) & 0x3F; |
363 | 355 |
Luma[13] = (tmp >> 12) & 0x3F; |
364 | 356 |
Luma[14] = (tmp >> 6) & 0x3F; |
... | ... |
@@ -27,6 +27,7 @@ |
27 | 27 |
#include "vp56data.h" |
28 | 28 |
#include "dsputil.h" |
29 | 29 |
#include "mpegvideo.h" |
30 |
+#include "bytestream.h" |
|
30 | 31 |
|
31 | 32 |
|
32 | 33 |
typedef struct vp56_context vp56_context_t; |
... | ... |
@@ -169,8 +170,7 @@ static inline void vp56_init_range_decoder(vp56_range_coder_t *c, |
169 | 169 |
c->high = 255; |
170 | 170 |
c->bits = 8; |
171 | 171 |
c->buffer = buf; |
172 |
- c->code_word = *c->buffer++ << 8; |
|
173 |
- c->code_word |= *c->buffer++; |
|
172 |
+ c->code_word = bytestream_get_be16(&c->buffer); |
|
174 | 173 |
} |
175 | 174 |
|
176 | 175 |
static inline int vp56_rac_get_prob(vp56_range_coder_t *c, uint8_t prob) |
... | ... |
@@ -92,12 +92,11 @@ static int wma_decode_init(AVCodecContext * avctx) |
92 | 92 |
flags2 = 0; |
93 | 93 |
extradata = avctx->extradata; |
94 | 94 |
if (avctx->codec->id == CODEC_ID_WMAV1 && avctx->extradata_size >= 4) { |
95 |
- flags1 = extradata[0] | (extradata[1] << 8); |
|
96 |
- flags2 = extradata[2] | (extradata[3] << 8); |
|
95 |
+ flags1 = AV_RL16(extradata); |
|
96 |
+ flags2 = AV_RL16(extradata+2); |
|
97 | 97 |
} else if (avctx->codec->id == CODEC_ID_WMAV2 && avctx->extradata_size >= 6) { |
98 |
- flags1 = extradata[0] | (extradata[1] << 8) | |
|
99 |
- (extradata[2] << 16) | (extradata[3] << 24); |
|
100 |
- flags2 = extradata[4] | (extradata[5] << 8); |
|
98 |
+ flags1 = AV_RL32(extradata); |
|
99 |
+ flags2 = AV_RL16(extradata+4); |
|
101 | 100 |
} |
102 | 101 |
// for(i=0; i<avctx->extradata_size; i++) |
103 | 102 |
// av_log(NULL, AV_LOG_ERROR, "%02X ", extradata[i]); |
... | ... |
@@ -45,19 +45,13 @@ static int encode_init(AVCodecContext * avctx){ |
45 | 45 |
if (avctx->codec->id == CODEC_ID_WMAV1) { |
46 | 46 |
extradata= av_malloc(4); |
47 | 47 |
avctx->extradata_size= 4; |
48 |
- extradata[0] = flags1; |
|
49 |
- extradata[1] = flags1>>8; |
|
50 |
- extradata[2] = flags2; |
|
51 |
- extradata[3] = flags2>>8; |
|
48 |
+ AV_WL16(extradata, flags1); |
|
49 |
+ AV_WL16(extradata+2, flags2); |
|
52 | 50 |
} else if (avctx->codec->id == CODEC_ID_WMAV2) { |
53 | 51 |
extradata= av_mallocz(10); |
54 | 52 |
avctx->extradata_size= 10; |
55 |
- extradata[0] = flags1; |
|
56 |
- extradata[1] = flags1>>8; |
|
57 |
- extradata[2] = flags1>>16; |
|
58 |
- extradata[3] = flags1>>24; |
|
59 |
- extradata[4] = flags2; |
|
60 |
- extradata[5] = flags2>>8; |
|
53 |
+ AV_WL32(extradata, flags1); |
|
54 |
+ AV_WL16(extradata+4, flags2); |
|
61 | 55 |
}else |
62 | 56 |
assert(0); |
63 | 57 |
avctx->extradata= extradata; |
... | ... |
@@ -579,9 +579,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 |
579 | 579 |
for(i = 0; i < c->width; i++) { |
580 | 580 |
uint32_t tmp = AV_RL32(src); |
581 | 581 |
src += 4; |
582 |
- out[i * 3 + 0] = tmp >> 16; |
|
583 |
- out[i * 3 + 1] = tmp >> 8; |
|
584 |
- out[i * 3 + 2] = tmp >> 0; |
|
582 |
+ AV_WB24(out+(i*3), tmp); |
|
585 | 583 |
} |
586 | 584 |
out += c->pic.linesize[0]; |
587 | 585 |
} |
... | ... |
@@ -144,9 +144,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void |
144 | 144 |
if(chpal){ |
145 | 145 |
uint8_t tpal[3]; |
146 | 146 |
for(i = 0; i < 256; i++){ |
147 |
- tpal[0] = palptr[i] >> 16; |
|
148 |
- tpal[1] = palptr[i] >> 8; |
|
149 |
- tpal[2] = palptr[i]; |
|
147 |
+ AV_WB24(tpal, palptr[i]); |
|
150 | 148 |
c->work_buf[work_size++] = tpal[0] ^ c->pal[i * 3 + 0]; |
151 | 149 |
c->work_buf[work_size++] = tpal[1] ^ c->pal[i * 3 + 1]; |
152 | 150 |
c->work_buf[work_size++] = tpal[2] ^ c->pal[i * 3 + 2]; |
... | ... |
@@ -158,9 +156,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void |
158 | 158 |
} |
159 | 159 |
if(keyframe){ |
160 | 160 |
for(i = 0; i < 256; i++){ |
161 |
- c->pal[i*3 + 0] = palptr[i] >> 16; |
|
162 |
- c->pal[i*3 + 1] = palptr[i] >> 8; |
|
163 |
- c->pal[i*3 + 2] = palptr[i]; |
|
161 |
+ AV_WB24(c->pal+(i*3), palptr[i]); |
|
164 | 162 |
} |
165 | 163 |
memcpy(c->work_buf, c->pal, 768); |
166 | 164 |
memcpy(c->pal2, p->data[1], 1024); |