put/get portable for IEEE double - renamed put_native_string/get_native_string

Originally committed as revision 1062 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Fabrice Bellard 23 years ago
parent d4c0ff917d
commit 3b4b29dcd9
  1. 8
      libav/avio.h
  2. 26
      libav/aviobuf.c
  3. 20
      libav/ffm.c

@ -87,8 +87,8 @@ void put_le16(ByteIOContext *s, unsigned int val);
void put_be16(ByteIOContext *s, unsigned int val); void put_be16(ByteIOContext *s, unsigned int val);
void put_tag(ByteIOContext *s, char *tag); void put_tag(ByteIOContext *s, char *tag);
void put_native_double(ByteIOContext *s, double val); void put_be64_double(ByteIOContext *s, double val);
void put_native_string(ByteIOContext *s, const char *buf); void put_strz(ByteIOContext *s, const char *buf);
offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence); offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
void url_fskip(ByteIOContext *s, offset_t offset); void url_fskip(ByteIOContext *s, offset_t offset);
@ -108,8 +108,8 @@ unsigned int get_le32(ByteIOContext *s);
UINT64 get_le64(ByteIOContext *s); UINT64 get_le64(ByteIOContext *s);
unsigned int get_le16(ByteIOContext *s); unsigned int get_le16(ByteIOContext *s);
double get_native_double(ByteIOContext *s); double get_be64_double(ByteIOContext *s);
char *get_native_string(ByteIOContext *s, char *buf, int maxlen); char *get_strz(ByteIOContext *s, char *buf, int maxlen);
unsigned int get_be16(ByteIOContext *s); unsigned int get_be16(ByteIOContext *s);
unsigned int get_be32(ByteIOContext *s); unsigned int get_be32(ByteIOContext *s);
UINT64 get_be64(ByteIOContext *s); UINT64 get_be64(ByteIOContext *s);

@ -176,12 +176,18 @@ void put_be32(ByteIOContext *s, unsigned int val)
put_byte(s, val); put_byte(s, val);
} }
void put_native_double(ByteIOContext *s, double val) /* IEEE format is assumed */
void put_be64_double(ByteIOContext *s, double val)
{ {
put_buffer(s, (const unsigned char *) &val, sizeof(val)); union {
double d;
UINT64 ull;
} u;
u.d = val;
put_be64(s, u.ull);
} }
void put_native_string(ByteIOContext *s, const char *str) void put_strz(ByteIOContext *s, const char *str)
{ {
if (str) if (str)
put_buffer(s, (const unsigned char *) str, strlen(str) + 1); put_buffer(s, (const unsigned char *) str, strlen(str) + 1);
@ -339,16 +345,18 @@ unsigned int get_be32(ByteIOContext *s)
return val; return val;
} }
double get_native_double(ByteIOContext *s) double get_be64_double(ByteIOContext *s)
{ {
double val; union {
double d;
UINT64 ull;
} u;
get_buffer(s, (unsigned char *) &val, sizeof(val)); u.ull = get_be64(s);
return u.d;
return val;
} }
char *get_native_string(ByteIOContext *s, char *buf, int maxlen) char *get_strz(ByteIOContext *s, char *buf, int maxlen)
{ {
int i = 0; int i = 0;
char c; char c;

@ -166,14 +166,14 @@ static int ffm_write_header(AVFormatContext *s)
put_be16(pb, (int) (codec->qcompress * 10000.0)); put_be16(pb, (int) (codec->qcompress * 10000.0));
put_be16(pb, (int) (codec->qblur * 10000.0)); put_be16(pb, (int) (codec->qblur * 10000.0));
put_be32(pb, codec->bit_rate_tolerance); put_be32(pb, codec->bit_rate_tolerance);
put_native_string(pb, codec->rc_eq); put_strz(pb, codec->rc_eq);
put_be32(pb, codec->rc_max_rate); put_be32(pb, codec->rc_max_rate);
put_be32(pb, codec->rc_min_rate); put_be32(pb, codec->rc_min_rate);
put_be32(pb, codec->rc_buffer_size); put_be32(pb, codec->rc_buffer_size);
put_native_double(pb, codec->i_quant_factor); put_be64_double(pb, codec->i_quant_factor);
put_native_double(pb, codec->b_quant_factor); put_be64_double(pb, codec->b_quant_factor);
put_native_double(pb, codec->i_quant_offset); put_be64_double(pb, codec->i_quant_offset);
put_native_double(pb, codec->b_quant_offset); put_be64_double(pb, codec->b_quant_offset);
put_be32(pb, codec->dct_algo); put_be32(pb, codec->dct_algo);
break; break;
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
@ -420,14 +420,14 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
codec->qcompress = get_be16(pb) / 10000.0; codec->qcompress = get_be16(pb) / 10000.0;
codec->qblur = get_be16(pb) / 10000.0; codec->qblur = get_be16(pb) / 10000.0;
codec->bit_rate_tolerance = get_be32(pb); codec->bit_rate_tolerance = get_be32(pb);
codec->rc_eq = strdup(get_native_string(pb, rc_eq_buf, sizeof(rc_eq_buf))); codec->rc_eq = strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf)));
codec->rc_max_rate = get_be32(pb); codec->rc_max_rate = get_be32(pb);
codec->rc_min_rate = get_be32(pb); codec->rc_min_rate = get_be32(pb);
codec->rc_buffer_size = get_be32(pb); codec->rc_buffer_size = get_be32(pb);
codec->i_quant_factor = get_native_double(pb); codec->i_quant_factor = get_be64_double(pb);
codec->b_quant_factor = get_native_double(pb); codec->b_quant_factor = get_be64_double(pb);
codec->i_quant_offset = get_native_double(pb); codec->i_quant_offset = get_be64_double(pb);
codec->b_quant_offset = get_native_double(pb); codec->b_quant_offset = get_be64_double(pb);
codec->dct_algo = get_be32(pb); codec->dct_algo = get_be32(pb);
break; break;
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:

Loading…
Cancel
Save