1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Remove duplicate bytestream functions

Originally committed as revision 9108 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Ramiro Polla 2007-05-23 14:55:13 +00:00
parent cb1a74cf8c
commit 67a5daf07f
5 changed files with 59 additions and 113 deletions

View File

@ -86,8 +86,7 @@ static void adx_encode(unsigned char *adx,const short *wav,PREV *prev)
if (scale==0) scale=1;
adx[0] = scale>>8;
adx[1] = scale;
AV_WB16(adx, scale);
for(i=0;i<16;i++) {
adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf);
@ -97,7 +96,7 @@ static void adx_encode(unsigned char *adx,const short *wav,PREV *prev)
static void adx_decode(short *out,const unsigned char *in,PREV *prev)
{
int scale = ((in[0]<<8)|(in[1]));
int scale = AV_RB16(in);
int i;
int s0,s1,s2,d;
@ -145,14 +144,6 @@ static void adx_decode_stereo(short *out,const unsigned char *in,PREV *prev)
#ifdef CONFIG_ENCODERS
static void write_long(unsigned char *p,uint32_t v)
{
p[0] = v>>24;
p[1] = v>>16;
p[2] = v>>8;
p[3] = v;
}
static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t bufsize)
{
#if 0
@ -178,13 +169,13 @@ static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t buf
} adxhdr; /* big endian */
/* offset-6 "(c)CRI" */
#endif
write_long(buf+0x00,0x80000000|0x20);
write_long(buf+0x04,0x03120400|avctx->channels);
write_long(buf+0x08,avctx->sample_rate);
write_long(buf+0x0c,0); /* FIXME: set after */
write_long(buf+0x10,0x01040300);
write_long(buf+0x14,0x00000000);
write_long(buf+0x18,0x00000000);
AV_WB32(buf+0x00,0x80000000|0x20);
AV_WB32(buf+0x04,0x03120400|avctx->channels);
AV_WB32(buf+0x08,avctx->sample_rate);
AV_WB32(buf+0x0c,0); /* FIXME: set after */
AV_WB32(buf+0x10,0x01040300);
AV_WB32(buf+0x14,0x00000000);
AV_WB32(buf+0x18,0x00000000);
memcpy(buf+0x1c,"\0\0(c)CRI",8);
return 0x20+4;
}
@ -264,17 +255,12 @@ static int adx_encode_frame(AVCodecContext *avctx,
#endif //CONFIG_ENCODERS
static uint32_t read_long(const unsigned char *p)
{
return (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
}
static int is_adx(const unsigned char *buf,size_t bufsize)
{
int offset;
if (buf[0]!=0x80) return 0;
offset = (read_long(buf)^0x80000000)+4;
offset = (AV_RB32(buf)^0x80000000)+4;
if (bufsize<offset || memcmp(buf+offset-6,"(c)CRI",6)) return 0;
return offset;
}
@ -289,8 +275,8 @@ static int adx_decode_header(AVCodecContext *avctx,const unsigned char *buf,size
if (offset==0) return 0;
channels = buf[7];
freq = read_long(buf+8);
size = read_long(buf+12);
freq = AV_RB32(buf+8);
size = AV_RB32(buf+12);
// printf("freq=%d ch=%d\n",freq,channels);

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
typedef struct DVBSubtitleContext {
int hide_state;
@ -208,15 +209,6 @@ static void dvb_encode_rle4(uint8_t **pq,
(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
static inline void putbe16(uint8_t **pq, uint16_t v)
{
uint8_t *q;
q = *pq;
*q++ = v >> 8;
*q++ = v;
*pq = q;
}
static int encode_dvb_subtitles(DVBSubtitleContext *s,
uint8_t *outbuf, AVSubtitle *h)
{
@ -237,7 +229,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
*q++ = 0x0f; /* sync_byte */
*q++ = 0x10; /* segment_type */
putbe16(&q, page_id);
bytestream_put_be16(&q, page_id);
pseg_len = q;
q += 2; /* segment length */
*q++ = 30; /* page_timeout (seconds) */
@ -251,11 +243,11 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
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 */
bytestream_put_be16(&q, h->rects[region_id].x); /* left pos */
bytestream_put_be16(&q, h->rects[region_id].y); /* top pos */
}
putbe16(&pseg_len, q - pseg_len - 2);
bytestream_put_be16(&pseg_len, q - pseg_len - 2);
if (!s->hide_state) {
for (clut_id = 0; clut_id < h->num_rects; clut_id++) {
@ -274,7 +266,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
*q++ = 0x0f; /* sync byte */
*q++ = 0x12; /* CLUT definition segment */
putbe16(&q, page_id);
bytestream_put_be16(&q, page_id);
pseg_len = q;
q += 2; /* segment length */
*q++ = clut_id;
@ -297,7 +289,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
}
}
putbe16(&pseg_len, q - pseg_len - 2);
bytestream_put_be16(&pseg_len, q - pseg_len - 2);
}
}
@ -317,27 +309,27 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
*q++ = 0x0f; /* sync_byte */
*q++ = 0x11; /* segment_type */
putbe16(&q, page_id);
bytestream_put_be16(&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, h->rects[region_id].w); /* region width */
putbe16(&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 */
*q++ = 0x03; /* 4 bit and 2 bit fill colors */
if (!s->hide_state) {
putbe16(&q, region_id); /* object_id == region_id */
bytestream_put_be16(&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);
bytestream_put_be16(&pseg_len, q - pseg_len - 2);
}
if (!s->hide_state) {
@ -357,11 +349,11 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
*q++ = 0x0f; /* sync byte */
*q++ = 0x13;
putbe16(&q, page_id);
bytestream_put_be16(&q, page_id);
pseg_len = q;
q += 2; /* segment length */
putbe16(&q, object_id);
bytestream_put_be16(&q, object_id);
*q++ = (s->object_version << 4) | (0 << 2) | (0 << 1) | 1; /* version = 0,
onject_coding_method,
non_modifying_color_flag */
@ -388,11 +380,11 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
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);
bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr);
bytestream_put_be16(&pbottom_field_len, q - bottom_ptr);
}
putbe16(&pseg_len, q - pseg_len - 2);
bytestream_put_be16(&pseg_len, q - pseg_len - 2);
}
}
@ -400,11 +392,11 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
*q++ = 0x0f; /* sync_byte */
*q++ = 0x80; /* segment_type */
putbe16(&q, page_id);
bytestream_put_be16(&q, page_id);
pseg_len = q;
q += 2; /* segment length */
putbe16(&pseg_len, q - pseg_len - 2);
bytestream_put_be16(&pseg_len, q - pseg_len - 2);
*q++ = 0xff; /* end of PES data */

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
#undef NDEBUG
#include <assert.h>
@ -85,14 +86,6 @@ static void dvd_encode_rle(uint8_t **pq,
*pq = q;
}
static inline void putbe16(uint8_t **pq, uint16_t v)
{
uint8_t *q = *pq;
*q++ = v >> 8;
*q++ = v;
*pq = q;
}
static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size,
const AVSubtitle *h)
{
@ -163,11 +156,11 @@ static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size,
// set data packet size
qq = outbuf + 2;
putbe16(&qq, q - outbuf);
bytestream_put_be16(&qq, q - outbuf);
// send start display command
putbe16(&q, (h->start_display_time*90) >> 10);
putbe16(&q, (q - outbuf) /*- 2 */ + 8 + 12*rects + 2);
bytestream_put_be16(&q, (h->start_display_time*90) >> 10);
bytestream_put_be16(&q, (q - outbuf) /*- 2 */ + 8 + 12*rects + 2);
*q++ = 0x03; // palette - 4 nibbles
*q++ = 0x03; *q++ = 0x7f;
*q++ = 0x04; // alpha - 4 nibbles
@ -192,20 +185,20 @@ static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size,
*q++ = 0x06;
// offset1, offset2
putbe16(&q, offset1[object_id]);
putbe16(&q, offset2[object_id]);
bytestream_put_be16(&q, offset1[object_id]);
bytestream_put_be16(&q, offset2[object_id]);
}
*q++ = 0x01; // start command
*q++ = 0xff; // terminating command
// send stop display command last
putbe16(&q, (h->end_display_time*90) >> 10);
putbe16(&q, (q - outbuf) - 2 /*+ 4*/);
bytestream_put_be16(&q, (h->end_display_time*90) >> 10);
bytestream_put_be16(&q, (q - outbuf) - 2 /*+ 4*/);
*q++ = 0x02; // set end
*q++ = 0xff; // terminating command
qq = outbuf;
putbe16(&qq, q - outbuf);
bytestream_put_be16(&qq, q - outbuf);
av_log(NULL, AV_LOG_DEBUG, "subtitle_packet size=%td\n", q - outbuf);
return q - outbuf;

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
/* TODO:
* - add 2, 4 and 16 bit depth support
@ -86,20 +87,6 @@ typedef struct PNGContext {
uint8_t buf[IOBUF_SIZE];
} PNGContext;
static unsigned int get32(uint8_t **b){
(*b) += 4;
return ((*b)[-4]<<24) + ((*b)[-3]<<16) + ((*b)[-2]<<8) + (*b)[-1];
}
#ifdef CONFIG_ENCODERS
static void put32(uint8_t **b, unsigned int v){
*(*b)++= v>>24;
*(*b)++= v>>16;
*(*b)++= v>>8;
*(*b)++= v;
}
#endif
static const uint8_t pngsig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
/* Mask to determine which y pixels are valid in a pass */
@ -509,10 +496,10 @@ static int decode_frame(AVCodecContext *avctx,
int tag32;
if (s->bytestream >= s->bytestream_end)
goto fail;
length = get32(&s->bytestream);
length = bytestream_get_be32(&s->bytestream);
if (length > 0x7fffffff)
goto fail;
tag32 = get32(&s->bytestream);
tag32 = bytestream_get_be32(&s->bytestream);
tag = bswap_32(tag32);
#ifdef DEBUG
av_log(avctx, AV_LOG_DEBUG, "png: tag=%c%c%c%c length=%u\n",
@ -525,8 +512,8 @@ static int decode_frame(AVCodecContext *avctx,
case MKTAG('I', 'H', 'D', 'R'):
if (length != 13)
goto fail;
s->width = get32(&s->bytestream);
s->height = get32(&s->bytestream);
s->width = bytestream_get_be32(&s->bytestream);
s->height = bytestream_get_be32(&s->bytestream);
if(avcodec_check_dimensions(avctx, s->width, s->height)){
s->width= s->height= 0;
goto fail;
@ -536,7 +523,7 @@ static int decode_frame(AVCodecContext *avctx,
s->compression_type = *s->bytestream++;
s->filter_type = *s->bytestream++;
s->interlace_type = *s->bytestream++;
crc = get32(&s->bytestream);
crc = bytestream_get_be32(&s->bytestream);
s->state |= PNG_IHDR;
#ifdef DEBUG
av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
@ -629,7 +616,7 @@ static int decode_frame(AVCodecContext *avctx,
if (png_decode_idat(s, length) < 0)
goto fail;
/* skip crc */
crc = get32(&s->bytestream);
crc = bytestream_get_be32(&s->bytestream);
break;
case MKTAG('P', 'L', 'T', 'E'):
{
@ -649,7 +636,7 @@ static int decode_frame(AVCodecContext *avctx,
s->palette[i] = (0xff << 24);
}
s->state |= PNG_PLTE;
crc = get32(&s->bytestream);
crc = bytestream_get_be32(&s->bytestream);
}
break;
case MKTAG('t', 'R', 'N', 'S'):
@ -665,13 +652,13 @@ static int decode_frame(AVCodecContext *avctx,
v = *s->bytestream++;
s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
}
crc = get32(&s->bytestream);
crc = bytestream_get_be32(&s->bytestream);
}
break;
case MKTAG('I', 'E', 'N', 'D'):
if (!(s->state & PNG_ALLIMAGE))
goto fail;
crc = get32(&s->bytestream);
crc = bytestream_get_be32(&s->bytestream);
goto exit_loop;
default:
/* skip tag */
@ -704,29 +691,20 @@ static void png_write_chunk(uint8_t **f, uint32_t tag,
uint32_t crc;
uint8_t tagbuf[4];
put32(f, length);
bytestream_put_be32(f, length);
crc = crc32(0, Z_NULL, 0);
tagbuf[0] = tag;
tagbuf[1] = tag >> 8;
tagbuf[2] = tag >> 16;
tagbuf[3] = tag >> 24;
crc = crc32(crc, tagbuf, 4);
put32(f, bswap_32(tag));
bytestream_put_be32(f, bswap_32(tag));
if (length > 0) {
crc = crc32(crc, buf, length);
memcpy(*f, buf, length);
*f += length;
}
put32(f, crc);
}
/* XXX: use avcodec generic function ? */
static void to_be32(uint8_t *p, uint32_t v)
{
p[0] = v >> 24;
p[1] = v >> 16;
p[2] = v >> 8;
p[3] = v;
bytestream_put_be32(f, crc);
}
/* XXX: do filtering */
@ -828,8 +806,8 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
memcpy(s->bytestream, pngsig, 8);
s->bytestream += 8;
to_be32(s->buf, avctx->width);
to_be32(s->buf + 4, avctx->height);
AV_WB32(s->buf, avctx->width);
AV_WB32(s->buf + 4, avctx->height);
s->buf[8] = bit_depth;
s->buf[9] = color_type;
s->buf[10] = 0; /* compression type */

View File

@ -32,6 +32,7 @@
#include <unistd.h>
#include "avcodec.h"
#include "bytestream.h"
#include "dsputil.h"
typedef struct {
@ -77,10 +78,6 @@ typedef struct RoqContext {
#define RoQ_ID_CCC 0x03
#define get_byte(in_buffer) *(in_buffer++)
#define get_word(in_buffer) ((unsigned short)(in_buffer += 2, \
(in_buffer[-1] << 8 | in_buffer[-2])))
#define get_long(in_buffer) ((unsigned long)(in_buffer += 4, \
(in_buffer[-1] << 24 | in_buffer[-2] << 16 | in_buffer[-3] << 8 | in_buffer[-4])))
static void apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
@ -293,9 +290,9 @@ static void roqvideo_decode_frame(RoqContext *ri)
unsigned char *buf_end = ri->buf + ri->size;
while (buf < buf_end) {
chunk_id = get_word(buf);
chunk_size = get_long(buf);
chunk_arg = get_word(buf);
chunk_id = bytestream_get_le16(&buf);
chunk_size = bytestream_get_le32(&buf);
chunk_arg = bytestream_get_le16(&buf);
if(chunk_id == RoQ_QUAD_VQ)
break;