Commit 3383a53e authored by Mans Rullgard's avatar Mans Rullgard

lavu: replace int/float punning functions

The existing functions defined in intfloat_readwrite.[ch] are
both slow and incorrect (infinities are not handled).

This introduces a new header with fast, inline conversion
functions using direct union punning assuming an IEEE-754
system, an assumption already made throughout the code.

The one use of Intel/Motorola extended 80-bit format is
replaced by simpler code sufficient under the present
constraints (positive normal values).

The old functions are marked deprecated and retained for
compatibility.
Signed-off-by: 's avatarMans Rullgard <mans@mansr.com>
parent 5b3265a7
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "dct.h" #include "dct.h"
#include "rdft.h" #include "rdft.h"
#include "fmtconvert.h" #include "fmtconvert.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
extern const uint16_t ff_wma_critical_freqs[25]; extern const uint16_t ff_wma_critical_freqs[25];
...@@ -193,8 +193,8 @@ static int decode_block(BinkAudioContext *s, int16_t *out, int use_dct) ...@@ -193,8 +193,8 @@ static int decode_block(BinkAudioContext *s, int16_t *out, int use_dct)
if (s->version_b) { if (s->version_b) {
if (get_bits_left(gb) < 64) if (get_bits_left(gb) < 64)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
coeffs[0] = av_int2flt(get_bits(gb, 32)) * s->root; coeffs[0] = av_int2float(get_bits_long(gb, 32)) * s->root;
coeffs[1] = av_int2flt(get_bits(gb, 32)) * s->root; coeffs[1] = av_int2float(get_bits_long(gb, 32)) * s->root;
} else { } else {
if (get_bits_left(gb) < 58) if (get_bits_left(gb) < 58)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
...@@ -131,7 +131,7 @@ static int fourxm_read_header(AVFormatContext *s, ...@@ -131,7 +131,7 @@ static int fourxm_read_header(AVFormatContext *s,
size = AV_RL32(&header[i + 4]); size = AV_RL32(&header[i + 4]);
if (fourcc_tag == std__TAG) { if (fourcc_tag == std__TAG) {
fourxm->fps = av_int2flt(AV_RL32(&header[i + 12])); fourxm->fps = av_int2float(AV_RL32(&header[i + 12]));
} else if (fourcc_tag == vtrk_TAG) { } else if (fourcc_tag == vtrk_TAG) {
/* check that there is enough data */ /* check that there is enough data */
if (size != vtrk_SIZE) { if (size != vtrk_SIZE) {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/intfloat_readwrite.h" #include "libavutil/mathematics.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
...@@ -88,7 +88,8 @@ static void get_meta(AVFormatContext *s, const char *key, int size) ...@@ -88,7 +88,8 @@ static void get_meta(AVFormatContext *s, const char *key, int size)
static unsigned int get_aiff_header(AVIOContext *pb, AVCodecContext *codec, static unsigned int get_aiff_header(AVIOContext *pb, AVCodecContext *codec,
int size, unsigned version) int size, unsigned version)
{ {
AVExtFloat ext; int exp;
uint64_t val;
double sample_rate; double sample_rate;
unsigned int num_frames; unsigned int num_frames;
...@@ -99,8 +100,9 @@ static unsigned int get_aiff_header(AVIOContext *pb, AVCodecContext *codec, ...@@ -99,8 +100,9 @@ static unsigned int get_aiff_header(AVIOContext *pb, AVCodecContext *codec,
num_frames = avio_rb32(pb); num_frames = avio_rb32(pb);
codec->bits_per_coded_sample = avio_rb16(pb); codec->bits_per_coded_sample = avio_rb16(pb);
avio_read(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */ exp = avio_rb16(pb);
sample_rate = av_ext2dbl(ext); /* 80 bits BE IEEE extended float */ val = avio_rb64(pb);
sample_rate = ldexp(val, exp - 16383 - 63);
codec->sample_rate = sample_rate; codec->sample_rate = sample_rate;
size -= 18; size -= 18;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "aiff.h" #include "aiff.h"
...@@ -36,7 +36,7 @@ static int aiff_write_header(AVFormatContext *s) ...@@ -36,7 +36,7 @@ static int aiff_write_header(AVFormatContext *s)
AIFFOutputContext *aiff = s->priv_data; AIFFOutputContext *aiff = s->priv_data;
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
AVCodecContext *enc = s->streams[0]->codec; AVCodecContext *enc = s->streams[0]->codec;
AVExtFloat sample_rate; uint64_t sample_rate;
int aifc = 0; int aifc = 0;
/* First verify if format is ok */ /* First verify if format is ok */
...@@ -82,8 +82,9 @@ static int aiff_write_header(AVFormatContext *s) ...@@ -82,8 +82,9 @@ static int aiff_write_header(AVFormatContext *s)
avio_wb16(pb, enc->bits_per_coded_sample); /* Sample size */ avio_wb16(pb, enc->bits_per_coded_sample); /* Sample size */
sample_rate = av_dbl2ext((double)enc->sample_rate); sample_rate = av_double2int(enc->sample_rate);
avio_write(pb, (uint8_t*)&sample_rate, sizeof(sample_rate)); avio_wb16(pb, (sample_rate >> 52) + (16383 - 1023));
avio_wb64(pb, UINT64_C(1) << 63 | sample_rate << 11);
if (aifc) { if (aifc) {
avio_wl32(pb, enc->codec_tag); avio_wl32(pb, enc->codec_tag);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "riff.h" #include "riff.h"
#include "isom.h" #include "isom.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "caf.h" #include "caf.h"
...@@ -68,7 +68,7 @@ static int read_desc_chunk(AVFormatContext *s) ...@@ -68,7 +68,7 @@ static int read_desc_chunk(AVFormatContext *s)
/* parse format description */ /* parse format description */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->sample_rate = av_int2dbl(avio_rb64(pb)); st->codec->sample_rate = av_int2double(avio_rb64(pb));
st->codec->codec_tag = avio_rb32(pb); st->codec->codec_tag = avio_rb32(pb);
flags = avio_rb32(pb); flags = avio_rb32(pb);
caf->bytes_per_packet = avio_rb32(pb); caf->bytes_per_packet = avio_rb32(pb);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "ffm.h" #include "ffm.h"
...@@ -325,10 +325,10 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -325,10 +325,10 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
codec->rc_max_rate = avio_rb32(pb); codec->rc_max_rate = avio_rb32(pb);
codec->rc_min_rate = avio_rb32(pb); codec->rc_min_rate = avio_rb32(pb);
codec->rc_buffer_size = avio_rb32(pb); codec->rc_buffer_size = avio_rb32(pb);
codec->i_quant_factor = av_int2dbl(avio_rb64(pb)); codec->i_quant_factor = av_int2double(avio_rb64(pb));
codec->b_quant_factor = av_int2dbl(avio_rb64(pb)); codec->b_quant_factor = av_int2double(avio_rb64(pb));
codec->i_quant_offset = av_int2dbl(avio_rb64(pb)); codec->i_quant_offset = av_int2double(avio_rb64(pb));
codec->b_quant_offset = av_int2dbl(avio_rb64(pb)); codec->b_quant_offset = av_int2double(avio_rb64(pb));
codec->dct_algo = avio_rb32(pb); codec->dct_algo = avio_rb32(pb);
codec->strict_std_compliance = avio_rb32(pb); codec->strict_std_compliance = avio_rb32(pb);
codec->max_b_frames = avio_rb32(pb); codec->max_b_frames = avio_rb32(pb);
...@@ -340,7 +340,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -340,7 +340,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
codec->mb_decision = avio_rb32(pb); codec->mb_decision = avio_rb32(pb);
codec->nsse_weight = avio_rb32(pb); codec->nsse_weight = avio_rb32(pb);
codec->frame_skip_cmp = avio_rb32(pb); codec->frame_skip_cmp = avio_rb32(pb);
codec->rc_buffer_aggressivity = av_int2dbl(avio_rb64(pb)); codec->rc_buffer_aggressivity = av_int2double(avio_rb64(pb));
codec->codec_tag = avio_rb32(pb); codec->codec_tag = avio_rb32(pb);
codec->thread_count = avio_r8(pb); codec->thread_count = avio_r8(pb);
codec->coder_type = avio_rb32(pb); codec->coder_type = avio_rb32(pb);
...@@ -350,8 +350,8 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -350,8 +350,8 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
codec->keyint_min = avio_rb32(pb); codec->keyint_min = avio_rb32(pb);
codec->scenechange_threshold = avio_rb32(pb); codec->scenechange_threshold = avio_rb32(pb);
codec->b_frame_strategy = avio_rb32(pb); codec->b_frame_strategy = avio_rb32(pb);
codec->qcompress = av_int2dbl(avio_rb64(pb)); codec->qcompress = av_int2double(avio_rb64(pb));
codec->qblur = av_int2dbl(avio_rb64(pb)); codec->qblur = av_int2double(avio_rb64(pb));
codec->max_qdiff = avio_rb32(pb); codec->max_qdiff = avio_rb32(pb);
codec->refs = avio_rb32(pb); codec->refs = avio_rb32(pb);
break; break;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "ffm.h" #include "ffm.h"
...@@ -137,10 +137,10 @@ static int ffm_write_header(AVFormatContext *s) ...@@ -137,10 +137,10 @@ static int ffm_write_header(AVFormatContext *s)
avio_wb32(pb, codec->rc_max_rate); avio_wb32(pb, codec->rc_max_rate);
avio_wb32(pb, codec->rc_min_rate); avio_wb32(pb, codec->rc_min_rate);
avio_wb32(pb, codec->rc_buffer_size); avio_wb32(pb, codec->rc_buffer_size);
avio_wb64(pb, av_dbl2int(codec->i_quant_factor)); avio_wb64(pb, av_double2int(codec->i_quant_factor));
avio_wb64(pb, av_dbl2int(codec->b_quant_factor)); avio_wb64(pb, av_double2int(codec->b_quant_factor));
avio_wb64(pb, av_dbl2int(codec->i_quant_offset)); avio_wb64(pb, av_double2int(codec->i_quant_offset));
avio_wb64(pb, av_dbl2int(codec->b_quant_offset)); avio_wb64(pb, av_double2int(codec->b_quant_offset));
avio_wb32(pb, codec->dct_algo); avio_wb32(pb, codec->dct_algo);
avio_wb32(pb, codec->strict_std_compliance); avio_wb32(pb, codec->strict_std_compliance);
avio_wb32(pb, codec->max_b_frames); avio_wb32(pb, codec->max_b_frames);
...@@ -152,7 +152,7 @@ static int ffm_write_header(AVFormatContext *s) ...@@ -152,7 +152,7 @@ static int ffm_write_header(AVFormatContext *s)
avio_wb32(pb, codec->mb_decision); avio_wb32(pb, codec->mb_decision);
avio_wb32(pb, codec->nsse_weight); avio_wb32(pb, codec->nsse_weight);
avio_wb32(pb, codec->frame_skip_cmp); avio_wb32(pb, codec->frame_skip_cmp);
avio_wb64(pb, av_dbl2int(codec->rc_buffer_aggressivity)); avio_wb64(pb, av_double2int(codec->rc_buffer_aggressivity));
avio_wb32(pb, codec->codec_tag); avio_wb32(pb, codec->codec_tag);
avio_w8(pb, codec->thread_count); avio_w8(pb, codec->thread_count);
avio_wb32(pb, codec->coder_type); avio_wb32(pb, codec->coder_type);
...@@ -162,8 +162,8 @@ static int ffm_write_header(AVFormatContext *s) ...@@ -162,8 +162,8 @@ static int ffm_write_header(AVFormatContext *s)
avio_wb32(pb, codec->keyint_min); avio_wb32(pb, codec->keyint_min);
avio_wb32(pb, codec->scenechange_threshold); avio_wb32(pb, codec->scenechange_threshold);
avio_wb32(pb, codec->b_frame_strategy); avio_wb32(pb, codec->b_frame_strategy);
avio_wb64(pb, av_dbl2int(codec->qcompress)); avio_wb64(pb, av_double2int(codec->qcompress));
avio_wb64(pb, av_dbl2int(codec->qblur)); avio_wb64(pb, av_double2int(codec->qblur));
avio_wb32(pb, codec->max_qdiff); avio_wb32(pb, codec->max_qdiff);
avio_wb32(pb, codec->refs); avio_wb32(pb, codec->refs);
break; break;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavcodec/bytestream.h" #include "libavcodec/bytestream.h"
#include "libavcodec/mpeg4audio.h" #include "libavcodec/mpeg4audio.h"
...@@ -189,7 +189,7 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream ...@@ -189,7 +189,7 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream
for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) { for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER) if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
goto finish; goto finish;
num_val = av_int2dbl(avio_rb64(ioc)); num_val = av_int2double(avio_rb64(ioc));
current_array[i] = num_val; current_array[i] = num_val;
} }
if (times && filepositions) { if (times && filepositions) {
...@@ -230,7 +230,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst ...@@ -230,7 +230,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
switch(amf_type) { switch(amf_type) {
case AMF_DATA_TYPE_NUMBER: case AMF_DATA_TYPE_NUMBER:
num_val = av_int2dbl(avio_rb64(ioc)); break; num_val = av_int2double(avio_rb64(ioc)); break;
case AMF_DATA_TYPE_BOOL: case AMF_DATA_TYPE_BOOL:
num_val = avio_r8(ioc); break; num_val = avio_r8(ioc); break;
case AMF_DATA_TYPE_STRING: case AMF_DATA_TYPE_STRING:
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "avformat.h" #include "avformat.h"
#include "flv.h" #include "flv.h"
#include "internal.h" #include "internal.h"
...@@ -162,7 +162,7 @@ static void put_avc_eos_tag(AVIOContext *pb, unsigned ts) { ...@@ -162,7 +162,7 @@ static void put_avc_eos_tag(AVIOContext *pb, unsigned ts) {
static void put_amf_double(AVIOContext *pb, double d) static void put_amf_double(AVIOContext *pb, double d)
{ {
avio_w8(pb, AMF_DATA_TYPE_NUMBER); avio_w8(pb, AMF_DATA_TYPE_NUMBER);
avio_wb64(pb, av_dbl2int(d)); avio_wb64(pb, av_double2int(d));
} }
static void put_amf_bool(AVIOContext *pb, int b) { static void put_amf_bool(AVIOContext *pb, int b) {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
...@@ -520,8 +520,8 @@ static int gxf_write_umf_media_dv(AVIOContext *pb, GXFStreamContext *sc) ...@@ -520,8 +520,8 @@ static int gxf_write_umf_media_dv(AVIOContext *pb, GXFStreamContext *sc)
static int gxf_write_umf_media_audio(AVIOContext *pb, GXFStreamContext *sc) static int gxf_write_umf_media_audio(AVIOContext *pb, GXFStreamContext *sc)
{ {
avio_wl64(pb, av_dbl2int(1)); /* sound level to begin to */ avio_wl64(pb, av_double2int(1)); /* sound level to begin to */
avio_wl64(pb, av_dbl2int(1)); /* sound level to begin to */ avio_wl64(pb, av_double2int(1)); /* sound level to begin to */
avio_wl32(pb, 0); /* number of fields over which to ramp up sound level */ avio_wl32(pb, 0); /* number of fields over which to ramp up sound level */
avio_wl32(pb, 0); /* number of fields over which to ramp down sound level */ avio_wl32(pb, 0); /* number of fields over which to ramp down sound level */
avio_wl32(pb, 0); /* reserved */ avio_wl32(pb, 0); /* reserved */
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "rm.h" #include "rm.h"
#include "matroska.h" #include "matroska.h"
#include "libavcodec/mpeg4audio.h" #include "libavcodec/mpeg4audio.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/lzo.h" #include "libavutil/lzo.h"
...@@ -624,9 +624,9 @@ static int ebml_read_float(AVIOContext *pb, int size, double *num) ...@@ -624,9 +624,9 @@ static int ebml_read_float(AVIOContext *pb, int size, double *num)
if (size == 0) { if (size == 0) {
*num = 0; *num = 0;
} else if (size == 4) { } else if (size == 4) {
*num= av_int2flt(avio_rb32(pb)); *num = av_int2float(avio_rb32(pb));
} else if(size==8){ } else if (size == 8){
*num= av_int2dbl(avio_rb64(pb)); *num = av_int2double(avio_rb64(pb));
} else } else
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "avlanguage.h" #include "avlanguage.h"
#include "libavutil/samplefmt.h" #include "libavutil/samplefmt.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavutil/random_seed.h" #include "libavutil/random_seed.h"
#include "libavutil/lfg.h" #include "libavutil/lfg.h"
...@@ -185,7 +185,7 @@ static void put_ebml_float(AVIOContext *pb, unsigned int elementid, double val) ...@@ -185,7 +185,7 @@ static void put_ebml_float(AVIOContext *pb, unsigned int elementid, double val)
{ {
put_ebml_id(pb, elementid); put_ebml_id(pb, elementid);
put_ebml_num(pb, 8, 0); put_ebml_num(pb, 8, 0);
avio_wb64(pb, av_dbl2int(val)); avio_wb64(pb, av_double2int(val));
} }
static void put_ebml_binary(AVIOContext *pb, unsigned int elementid, static void put_ebml_binary(AVIOContext *pb, unsigned int elementid,
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
//#define MOV_EXPORT_ALL_METADATA //#define MOV_EXPORT_ALL_METADATA
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
...@@ -1218,7 +1218,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) ...@@ -1218,7 +1218,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
avio_rb32(pb); /* bytes per sample */ avio_rb32(pb); /* bytes per sample */
} else if (version==2) { } else if (version==2) {
avio_rb32(pb); /* sizeof struct only */ avio_rb32(pb); /* sizeof struct only */
st->codec->sample_rate = av_int2dbl(avio_rb64(pb)); /* float 64 */ st->codec->sample_rate = av_int2double(avio_rb64(pb)); /* float 64 */
st->codec->channels = avio_rb32(pb); st->codec->channels = avio_rb32(pb);
avio_rb32(pb); /* always 0x7F000000 */ avio_rb32(pb); /* always 0x7F000000 */
st->codec->bits_per_coded_sample = avio_rb32(pb); /* bits per channel if sound is uncompressed */ st->codec->bits_per_coded_sample = avio_rb32(pb); /* bits per channel if sound is uncompressed */
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "libavcodec/put_bits.h" #include "libavcodec/put_bits.h"
#include "internal.h" #include "internal.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
...@@ -468,7 +468,7 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) ...@@ -468,7 +468,7 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track)
avio_wb16(pb, 0); avio_wb16(pb, 0);
avio_wb32(pb, 0x00010000); avio_wb32(pb, 0x00010000);
avio_wb32(pb, 72); avio_wb32(pb, 72);
avio_wb64(pb, av_dbl2int(track->timescale)); avio_wb64(pb, av_double2int(track->timescale));
avio_wb32(pb, track->enc->channels); avio_wb32(pb, track->enc->channels);
avio_wb32(pb, 0x7F000000); avio_wb32(pb, 0x7F000000);
avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id)); avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id));
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "riff.h" #include "riff.h"
...@@ -140,10 +140,10 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { ...@@ -140,10 +140,10 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) {
avio_rl32(pb); // unused, "desiredheight" avio_rl32(pb); // unused, "desiredheight"
avio_r8(pb); // 'P' == progressive, 'I' == interlaced avio_r8(pb); // 'P' == progressive, 'I' == interlaced
avio_skip(pb, 3); // padding avio_skip(pb, 3); // padding
aspect = av_int2dbl(avio_rl64(pb)); aspect = av_int2double(avio_rl64(pb));
if (aspect > 0.9999 && aspect < 1.0001) if (aspect > 0.9999 && aspect < 1.0001)
aspect = 4.0 / 3.0; aspect = 4.0 / 3.0;
fps = av_int2dbl(avio_rl64(pb)); fps = av_int2double(avio_rl64(pb));
// number of packets per stream type, -1 means unknown, e.g. streaming // number of packets per stream type, -1 means unknown, e.g. streaming
v_packs = avio_rl32(pb); v_packs = avio_rl32(pb);
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "libavcodec/bytestream.h" #include "libavcodec/bytestream.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "avformat.h" #include "avformat.h"
#include "rtmppkt.h" #include "rtmppkt.h"
...@@ -37,7 +37,7 @@ void ff_amf_write_bool(uint8_t **dst, int val) ...@@ -37,7 +37,7 @@ void ff_amf_write_bool(uint8_t **dst, int val)
void ff_amf_write_number(uint8_t **dst, double val) void ff_amf_write_number(uint8_t **dst, double val)
{ {
bytestream_put_byte(dst, AMF_DATA_TYPE_NUMBER); bytestream_put_byte(dst, AMF_DATA_TYPE_NUMBER);
bytestream_put_be64(dst, av_dbl2int(val)); bytestream_put_be64(dst, av_double2int(val));
} }
void ff_amf_write_string(uint8_t **dst, const char *str) void ff_amf_write_string(uint8_t **dst, const char *str)
...@@ -318,7 +318,7 @@ int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end, ...@@ -318,7 +318,7 @@ int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end,
if (size == namelen && !memcmp(data-size, name, namelen)) { if (size == namelen && !memcmp(data-size, name, namelen)) {
switch (*data++) { switch (*data++) {
case AMF_DATA_TYPE_NUMBER: case AMF_DATA_TYPE_NUMBER:
snprintf(dst, dst_size, "%g", av_int2dbl(AV_RB64(data))); snprintf(dst, dst_size, "%g", av_int2double(AV_RB64(data)));
break; break;
case AMF_DATA_TYPE_BOOL: case AMF_DATA_TYPE_BOOL:
snprintf(dst, dst_size, "%s", *data ? "true" : "false"); snprintf(dst, dst_size, "%s", *data ? "true" : "false");
...@@ -370,7 +370,7 @@ static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *d ...@@ -370,7 +370,7 @@ static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *d
return; return;
switch (*data++) { switch (*data++) {
case AMF_DATA_TYPE_NUMBER: case AMF_DATA_TYPE_NUMBER:
av_log(ctx, AV_LOG_DEBUG, " number %g\n", av_int2dbl(AV_RB64(data))); av_log(ctx, AV_LOG_DEBUG, " number %g\n", av_int2double(AV_RB64(data)));
return; return;
case AMF_DATA_TYPE_BOOL: case AMF_DATA_TYPE_BOOL:
av_log(ctx, AV_LOG_DEBUG, " bool %d\n", *data); av_log(ctx, AV_LOG_DEBUG, " bool %d\n", *data);
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "libavcodec/bytestream.h" #include "libavcodec/bytestream.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/lfg.h" #include "libavutil/lfg.h"
#include "libavutil/sha.h" #include "libavutil/sha.h"
#include "avformat.h" #include "avformat.h"
...@@ -615,7 +615,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) ...@@ -615,7 +615,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
/* hack for Wowza Media Server, it does not send result for /* hack for Wowza Media Server, it does not send result for
* releaseStream and FCPublish calls */ * releaseStream and FCPublish calls */
if (!pkt->data[10]) { if (!pkt->data[10]) {
int pkt_id = (int) av_int2dbl(AV_RB64(pkt->data + 11)); int pkt_id = av_int2double(AV_RB64(pkt->data + 11));
if (pkt_id == rt->create_stream_invoke) if (pkt_id == rt->create_stream_invoke)
rt->state = STATE_CONNECTING; rt->state = STATE_CONNECTING;
} }
...@@ -626,7 +626,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) ...@@ -626,7 +626,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) { if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) {
av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n"); av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n");
} else { } else {
rt->main_channel_id = (int) av_int2dbl(AV_RB64(pkt->data + 21)); rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21));
} }
if (rt->is_input) { if (rt->is_input) {
gen_play(s, rt); gen_play(s, rt);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
...@@ -62,14 +62,14 @@ static int sox_read_header(AVFormatContext *s, ...@@ -62,14 +62,14 @@ static int sox_read_header(AVFormatContext *s,
st->codec->codec_id = CODEC_ID_PCM_S32LE; st->codec->codec_id = CODEC_ID_PCM_S32LE;
header_size = avio_rl32(pb); header_size = avio_rl32(pb);
avio_skip(pb, 8); /* sample count */ avio_skip(pb, 8); /* sample count */
sample_rate = av_int2dbl(avio_rl64(pb)); sample_rate = av_int2double(avio_rl64(pb));
st->codec->channels = avio_rl32(pb); st->codec->channels = avio_rl32(pb);
comment_size = avio_rl32(pb); comment_size = avio_rl32(pb);
} else { } else {
st->codec->codec_id = CODEC_ID_PCM_S32BE; st->codec->codec_id = CODEC_ID_PCM_S32BE;
header_size = avio_rb32(pb); header_size = avio_rb32(pb);
avio_skip(pb, 8); /* sample count */ avio_skip(pb, 8); /* sample count */
sample_rate = av_int2dbl(avio_rb64(pb)); sample_rate = av_int2double(avio_rb64(pb));
st->codec->channels = avio_rb32(pb); st->codec->channels = avio_rb32(pb);
comment_size = avio_rb32(pb); comment_size = avio_rb32(pb);
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "avformat.h" #include "avformat.h"
#include "avio_internal.h" #include "avio_internal.h"
...@@ -59,14 +59,14 @@ static int sox_write_header(AVFormatContext *s) ...@@ -59,14 +59,14 @@ static int sox_write_header(AVFormatContext *s)
ffio_wfourcc(pb, ".SoX"); ffio_wfourcc(pb, ".SoX");
avio_wl32(pb, sox->header_size); avio_wl32(pb, sox->header_size);
avio_wl64(pb, 0); /* number of samples */ avio_wl64(pb, 0); /* number of samples */
avio_wl64(pb, av_dbl2int(enc->sample_rate)); avio_wl64(pb, av_double2int(enc->sample_rate));
avio_wl32(pb, enc->channels); avio_wl32(pb, enc->channels);
avio_wl32(pb, comment_size); avio_wl32(pb, comment_size);
} else if (enc->codec_id == CODEC_ID_PCM_S32BE) { } else if (enc->codec_id == CODEC_ID_PCM_S32BE) {
ffio_wfourcc(pb, "XoS."); ffio_wfourcc(pb, "XoS.");
avio_wb32(pb, sox->header_size); avio_wb32(pb, sox->header_size);
avio_wb64(pb, 0); /* number of samples */ avio_wb64(pb, 0); /* number of samples */
avio_wb64(pb, av_dbl2int(enc->sample_rate)); avio_wb64(pb, av_double2int(enc->sample_rate));
avio_wb32(pb, enc->channels); avio_wb32(pb, enc->channels);
avio_wb32(pb, comment_size); avio_wb32(pb, comment_size);
} else { } else {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
...@@ -69,7 +69,7 @@ static int thp_read_header(AVFormatContext *s, ...@@ -69,7 +69,7 @@ static int thp_read_header(AVFormatContext *s,
avio_rb32(pb); /* Max buf size. */ avio_rb32(pb); /* Max buf size. */
avio_rb32(pb); /* Max samples. */ avio_rb32(pb); /* Max samples. */
thp->fps = av_d2q(av_int2flt(avio_rb32(pb)), INT_MAX); thp->fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX);
thp->framecnt = avio_rb32(pb); thp->framecnt = avio_rb32(pb);
thp->first_framesz = avio_rb32(pb); thp->first_framesz = avio_rb32(pb);
avio_rb32(pb); /* Data size. */ avio_rb32(pb); /* Data size. */
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
*/ */
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/intfloat_readwrite.h" #include "libavutil/intfloat.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
...@@ -458,7 +458,7 @@ static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value) ...@@ -458,7 +458,7 @@ static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value)
*/ */
static void oledate_to_iso8601(char *buf, int buf_size, int64_t value) static void oledate_to_iso8601(char *buf, int buf_size, int64_t value)
{ {
time_t t = 631112400LL + 86400*av_int2dbl(value); time_t t = 631112400LL + 86400*av_int2double(value);
strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t)); strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t));
} }
...@@ -523,7 +523,7 @@ static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int ty ...@@ -523,7 +523,7 @@ static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int ty
else if (!strcmp(key, "WM/WMRVExpirationDate")) else if (!strcmp(key, "WM/WMRVExpirationDate"))
oledate_to_iso8601(buf, buf_size, num); oledate_to_iso8601(buf, buf_size, num);
else if (!strcmp(key, "WM/WMRVBitrate")) else if (!strcmp(key, "WM/WMRVBitrate"))
snprintf(buf, buf_size, "%f", av_int2dbl(num)); snprintf(buf, buf_size, "%f", av_int2double(num));
else else
snprintf(buf, buf_size, "%"PRIi64, num); snprintf(buf, buf_size, "%"PRIi64, num);
} else if (type == 5 && length == 2) { } else if (type == 5 && length == 2) {
......
/*
* Copyright (c) 2011 Mans Rullgard
*
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_INTFLOAT_H
#define AVUTIL_INTFLOAT_H
#include <stdint.h>
#include "attributes.h"
union av_intfloat32 {
uint32_t i;
float f;
};
union av_intfloat64 {
uint64_t i;
double f;
};
/**
* Reinterpret a 32-bit integer as a float.
*/
static av_always_inline float av_int2float(uint32_t i)
{
union av_intfloat32 v = { .i = i };
return v.f;
}
/**
* Reinterpret a float as a 32-bit integer.
*/
static av_always_inline uint32_t av_float2int(float f)
{
union av_intfloat32 v = { .f = f };
return v.i;
}
/**
* Reinterpret a 64-bit integer as a double.
*/
static av_always_inline double av_int2double(uint64_t i)
{
union av_intfloat64 v = { .i = i };
return v.f;
}
/**
* Reinterpret a double as a 64-bit integer.
*/
static av_always_inline uint64_t av_double2int(double f)
{
union av_intfloat64 v = { .f = f };
return v.i;
}
#endif /* AVUTIL_INTFLOAT_H */
...@@ -30,11 +30,11 @@ typedef struct AVExtFloat { ...@@ -30,11 +30,11 @@ typedef struct AVExtFloat {
uint8_t mantissa[8]; uint8_t mantissa[8];
} AVExtFloat; } AVExtFloat;
double av_int2dbl(int64_t v) av_const; attribute_deprecated double av_int2dbl(int64_t v) av_const;
float av_int2flt(int32_t v) av_const; attribute_deprecated float av_int2flt(int32_t v) av_const;
double av_ext2dbl(const AVExtFloat ext) av_const; attribute_deprecated double av_ext2dbl(const AVExtFloat ext) av_const;
int64_t av_dbl2int(double d) av_const; attribute_deprecated int64_t av_dbl2int(double d) av_const;
int32_t av_flt2int(float d) av_const; attribute_deprecated int32_t av_flt2int(float d) av_const;
AVExtFloat av_dbl2ext(double d) av_const; attribute_deprecated AVExtFloat av_dbl2ext(double d) av_const;
#endif /* AVUTIL_INTFLOAT_READWRITE_H */ #endif /* AVUTIL_INTFLOAT_READWRITE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment