switch to C99 types, part II

Do full C99 integer type conversion in all modules which were not
touched by Eric's merged patch.
This commit is contained in:
Max Kellermann 2008-09-29 15:49:29 +02:00
parent 0352766dca
commit 226d52b36f
17 changed files with 82 additions and 58 deletions

View File

@ -153,7 +153,7 @@ static int shout_mp3_encoder_encode(struct shout_data *sd,
for (i = 0; i < samples; i++) {
for (j = 0; j < sd->audio_format.channels; j++) {
lamebuf[j][i] = *((const mpd_sint16 *) chunk);
lamebuf[j][i] = *((const int16_t *) chunk);
chunk += bytes;
}
}

View File

@ -267,7 +267,7 @@ static int shout_ogg_encoder_encode(struct shout_data *sd,
for (i = 0; i < samples; i++) {
for (j = 0; j < sd->audio_format.channels; j++) {
vorbbuf[j][i] = (*((const mpd_sint16 *) chunk)) / 32768.0;
vorbbuf[j][i] = (*((const int16_t *) chunk)) / 32768.0;
chunk += bytes;
}
}

View File

@ -22,9 +22,9 @@
#include "mpd_types.h"
struct audio_format {
mpd_uint32 sampleRate;
mpd_sint8 bits;
mpd_sint8 channels;
uint32_t sampleRate;
int8_t bits;
int8_t channels;
};
static inline void audio_format_clear(struct audio_format *af)

View File

@ -197,7 +197,7 @@ mpd_fprintf_ void command_error(struct client *client, int error,
va_end(args);
}
static int mpd_fprintf__ check_uint32(struct client *client, mpd_uint32 *dst,
static int mpd_fprintf__ check_uint32(struct client *client, uint32_t *dst,
const char *s, const char *fmt, ...)
{
char *test;
@ -627,7 +627,7 @@ static int handleRename(struct client *client,
static int handlePlaylistChanges(struct client *client,
mpd_unused int argc, char *argv[])
{
mpd_uint32 version;
uint32_t version;
if (check_uint32(client, &version, argv[1], need_positive) < 0)
return -1;
@ -637,7 +637,7 @@ static int handlePlaylistChanges(struct client *client,
static int handlePlaylistChangesPosId(struct client *client,
mpd_unused int argc, char *argv[])
{
mpd_uint32 version;
uint32_t version;
if (check_uint32(client, &version, argv[1], need_positive) < 0)
return -1;

View File

@ -152,7 +152,7 @@ need_chunks(struct decoder *decoder, InputStream * inStream, int seekable)
enum decoder_command
decoder_data(struct decoder *decoder, InputStream * inStream, int seekable,
void *dataIn, size_t dataInLen,
float data_time, mpd_uint16 bitRate,
float data_time, uint16_t bitRate,
ReplayGainInfo * replayGainInfo)
{
size_t nbytes;

View File

@ -149,7 +149,7 @@ size_t decoder_read(struct decoder *decoder,
*/
enum decoder_command
decoder_data(struct decoder *decoder, InputStream * inStream, int seekable,
void *data, size_t datalen, float data_time, mpd_uint16 bitRate,
void *data, size_t datalen, float data_time, uint16_t bitRate,
ReplayGainInfo * replayGainInfo);
void decoder_flush(struct decoder *decoder);

View File

@ -44,9 +44,9 @@ struct decoder_control {
volatile enum decoder_state state;
volatile enum decoder_command command;
volatile mpd_uint16 error;
volatile mpd_sint8 seekError;
volatile mpd_sint8 seekable;
volatile uint16_t error;
volatile int8_t seekError;
volatile int8_t seekable;
volatile double seekWhere;
struct audio_format audioFormat;
Song *current_song;

View File

@ -161,9 +161,9 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
switch (block->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
data->audio_format.bits = (mpd_sint8)si->bits_per_sample;
data->audio_format.bits = (int8_t)si->bits_per_sample;
data->audio_format.sampleRate = si->sample_rate;
data->audio_format.channels = (mpd_sint8)si->channels;
data->audio_format.channels = (int8_t)si->channels;
data->total_time = ((float)si->total_samples) / (si->sample_rate);
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:

View File

@ -50,7 +50,7 @@ static int audiofile_decode(struct decoder * decoder, char *path)
int bits;
struct audio_format audio_format;
float total_time;
mpd_uint16 bitRate;
uint16_t bitRate;
struct stat st;
int ret, current = 0;
char chunk[CHUNK_SIZE];
@ -69,17 +69,17 @@ static int audiofile_decode(struct decoder * decoder, char *path)
afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK,
AF_SAMPFMT_TWOSCOMP, 16);
afGetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits);
audio_format.bits = (mpd_uint8)bits;
audio_format.bits = (uint8_t)bits;
audio_format.sampleRate =
(unsigned int)afGetRate(af_fp, AF_DEFAULT_TRACK);
audio_format.channels =
(mpd_uint8)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
(uint8_t)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
total_time = ((float)frame_count / (float)audio_format.sampleRate);
bitRate = (mpd_uint16)(st.st_size * 8.0 / total_time / 1000.0 + 0.5);
bitRate = (uint16_t)(st.st_size * 8.0 / total_time / 1000.0 + 0.5);
if (audio_format.bits != 8 && audio_format.bits != 16) {
ERROR("Only 8 and 16-bit files are supported. %s is %i-bit\n",

View File

@ -66,10 +66,10 @@ static mpc_int32_t mpc_getsize_cb(void *vdata)
}
/* this _looks_ performance-critical, don't de-inline -- eric */
static inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT sample)
static inline int16_t convertSample(MPC_SAMPLE_FORMAT sample)
{
/* only doing 16-bit audio for now */
mpd_sint32 val;
int32_t val;
const int clip_min = -1 << (16 - 1);
const int clip_max = (1 << (16 - 1)) - 1;
@ -114,7 +114,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
char chunk[MPC_CHUNK_SIZE];
int chunkpos = 0;
long bitRate = 0;
mpd_sint16 *s16 = (mpd_sint16 *) chunk;
int16_t *s16 = (int16_t *) chunk;
unsigned long samplePos = 0;
mpc_uint32_t vbrUpdateAcc;
mpc_uint32_t vbrUpdateBits;
@ -171,7 +171,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
audio_format.sampleRate;
if (mpc_decoder_seek_sample(&decoder, samplePos)) {
decoder_clear(mpd_decoder);
s16 = (mpd_sint16 *) chunk;
s16 = (int16_t *) chunk;
chunkpos = 0;
decoder_command_finished(mpd_decoder);
} else
@ -213,7 +213,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
bitRate, replayGainInfo);
chunkpos = 0;
s16 = (mpd_sint16 *) chunk;
s16 = (int16_t *) chunk;
if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP) {
eof = 1;
break;

View File

@ -21,24 +21,49 @@
#include "../config.h"
typedef unsigned char mpd_uint8;
typedef signed char mpd_sint8;
#if defined(HAVE_INTTYPES_H)
/*
* inttypes.h pulls in stdint.h on C99 systems, needed for older systems
* that didn't provide stdint.h but still defined equivalent types.
*/
# include <inttypes.h>
#elif defined(HAVE_STDINT_H)
# include <stdint.h>
#elif defined(HAVE_SYS_INTTYPES_H)
# include <sys/inttypes.h> /* some ancient systems had this, untested */
#endif /* C99-ish type headers */
#include <sys/types.h>
#if (!defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H))
/*
* this only includes a partial subset of what is expected in a C99
* stdint.h or inttypes.h; but includes enough of what is needed for mpd
* to function on older platforms
* (especially Linux ones still using gcc 2.95)
*/
typedef unsigned char uint8_t;
typedef signed char int8_t;
#if SIZEOF_SHORT == 2
typedef unsigned short mpd_uint16;
typedef signed short mpd_sint16;
typedef unsigned short uint16_t;
typedef signed short int16_t;
#elif SIZEOF_INT == 2
typedef unsigned int mpd_uint16;
typedef signed int mpd_sint16;
#endif
typedef unsigned int uint16_t;
typedef signed int int16_t;
#endif /* (u)int_16_t */
#if SIZEOF_INT == 4
typedef unsigned int mpd_uint32;
typedef signed int mpd_sint32;
typedef unsigned int uint32_t;
typedef signed int int32_t;
#elif SIZEOF_LONG == 4
typedef unsigned long mpd_uint32;
typedef signed long mpd_sint32;
#endif
typedef unsigned long uint32_t;
typedef signed long int32_t;
#endif /* (u)int_32 */
#endif /* !HAVE_STDINT_H && !HAVE_INTTYPES_H */
union const_hack {
const char *in;

View File

@ -153,7 +153,7 @@ ob_chunk * ob_get_chunk(const unsigned i)
* @return the chunk which has room for more data; NULL if there is no
* room.
*/
static ob_chunk *tail_chunk(float data_time, mpd_uint16 bitRate)
static ob_chunk *tail_chunk(float data_time, uint16_t bitRate)
{
unsigned int next;
ob_chunk *chunk;
@ -184,7 +184,7 @@ static ob_chunk *tail_chunk(float data_time, mpd_uint16 bitRate)
}
size_t ob_append(const void *data0, size_t datalen,
float data_time, mpd_uint16 bitRate)
float data_time, uint16_t bitRate)
{
const unsigned char *data = data0;
size_t ret = 0, dataToSend;

View File

@ -26,8 +26,8 @@
#define CHUNK_SIZE 1020
typedef struct _OutputBufferChunk {
mpd_uint16 chunkSize;
mpd_uint16 bitRate;
uint16_t chunkSize;
uint16_t bitRate;
float times;
char data[CHUNK_SIZE];
} ob_chunk;
@ -102,9 +102,8 @@ ob_chunk * ob_get_chunk(const unsigned i);
* @return the number of bytes actually written
*/
size_t ob_append(const void *data, size_t datalen,
float data_time, mpd_uint16 bitRate);
float data_time, uint16_t bitRate);
void ob_skip(unsigned num);
#endif

View File

@ -85,21 +85,21 @@ struct player_control {
Notify notify;
volatile enum player_command command;
volatile enum player_state state;
volatile mpd_sint8 error;
volatile mpd_uint16 bitRate;
volatile mpd_sint8 bits;
volatile mpd_sint8 channels;
volatile mpd_uint32 sampleRate;
volatile int8_t error;
volatile uint16_t bitRate;
volatile int8_t bits;
volatile int8_t channels;
volatile uint32_t sampleRate;
volatile float totalTime;
volatile float elapsedTime;
volatile float fileTime;
Song *volatile next_song;
Song *errored_song;
volatile enum player_queue_state queueState;
volatile mpd_sint8 queueLockState;
volatile int8_t queueLockState;
volatile double seekWhere;
volatile float crossFade;
volatile mpd_uint16 softwareVolume;
volatile uint16_t softwareVolume;
volatile double totalPlayTime;
};

View File

@ -73,7 +73,7 @@ static void randomizeOrder(int start, int end);
static void incrPlaylistVersion(void)
{
static unsigned long max = ((mpd_uint32) 1 << 31) - 1;
static unsigned long max = ((uint32_t) 1 << 31) - 1;
playlist.version++;
if (playlist.version >= max) {
int i;
@ -141,7 +141,7 @@ void initPlaylist(void)
DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
playlist.songs = xmalloc(sizeof(Song *) * playlist_max_length);
playlist.songMod = xmalloc(sizeof(mpd_uint32) * playlist_max_length);
playlist.songMod = xmalloc(sizeof(uint32_t) * playlist_max_length);
playlist.order = xmalloc(sizeof(int) * playlist_max_length);
playlist.idToPosition = xmalloc(sizeof(int) * playlist_max_length *
PLAYLIST_HASH_MULT);
@ -369,7 +369,7 @@ static void printPlaylistSongInfo(struct client *client, int song)
client_printf(client, "Pos: %i\nId: %i\n", song, playlist.positionToId[song]);
}
int playlistChanges(struct client *client, mpd_uint32 version)
int playlistChanges(struct client *client, uint32_t version)
{
int i;
@ -384,7 +384,7 @@ int playlistChanges(struct client *client, mpd_uint32 version)
return 0;
}
int playlistChangesPosId(struct client *client, mpd_uint32 version)
int playlistChangesPosId(struct client *client, uint32_t version)
{
int i;

View File

@ -39,7 +39,7 @@ enum playlist_result {
typedef struct _Playlist {
Song **songs;
/* holds version a song was modified on */
mpd_uint32 *songMod;
uint32_t *songMod;
int *order;
int *positionToId;
int *idToPosition;
@ -48,7 +48,7 @@ typedef struct _Playlist {
int queued;
int repeat;
int random;
mpd_uint32 version;
uint32_t version;
} Playlist;
extern int playlist_saveAbsolutePaths;
@ -137,9 +137,9 @@ enum playlist_result seekSongInPlaylistById(int id, float seek_time);
void playlistVersionChange(void);
int playlistChanges(struct client *client, mpd_uint32 version);
int playlistChanges(struct client *client, uint32_t version);
int playlistChangesPosId(struct client *client, mpd_uint32 version);
int playlistChangesPosId(struct client *client, uint32_t version);
int PlaylistInfo(struct client *client, const char *utf8file, int detail);

View File

@ -35,7 +35,7 @@ struct client;
typedef struct _Song {
char *url;
mpd_sint8 type;
int8_t type;
struct tag *tag;
struct _Directory *parentDir;
time_t mtime;