xmms-wma-1.0.5/0000755000175000017500000000000010454605217013553 5ustar whistlerwhistlerxmms-wma-1.0.5/wma123_examples/0000755000175000017500000000000010032750057016456 5ustar whistlerwhistlerxmms-wma-1.0.5/wma123_examples/playlist.c0000644000175000017500000001532010024415732020463 0ustar whistlerwhistler/******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY * * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. * * PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2001 * * by Stan Seibert AND OTHER CONTRIBUTORS * * http://www.xiph.org/ * * * ******************************************************************** last mod: $Id: playlist.c,v 1.3 2002/07/13 17:57:10 volsung Exp $ ********************************************************************/ #include #include #include #include #include #include #include #include #include "playlist.h" /* Work with *BSD differences */ #if !defined(NAME_MAX) && defined(MAXNAMLEN) #define NAME_MAX MAXNAMLEN #endif playlist_element_t *playlist_element_create(char *filename) { playlist_element_t *element = (playlist_element_t *) malloc(sizeof(playlist_t)); if (element == NULL) { fprintf(stderr, "Error: Out of memory in create_playlist_member().\n"); exit(1); } if (filename == NULL) element->filename = NULL; else { element->filename = strdup(filename); if (element->filename == NULL) { fprintf(stderr, "Error: Out of memory in create_playlist_member().\n"); exit(1); } } element->next = NULL; return element; } /* Only destroys the current node. Does not affect linked nodes. */ void playlist_element_destroy(playlist_element_t *element) { free(element->filename); free(element); } playlist_t *playlist_create() { playlist_t *list = (playlist_t *) malloc(sizeof(playlist_t)); if (list != NULL) { list->head = playlist_element_create(NULL); list->last = list->head; } return list; } void playlist_destroy(playlist_t *list) { playlist_element_t *next_element; while (list->head != NULL) { next_element = list->head->next; playlist_element_destroy(list->head); list->head = next_element; } free(list); } /* All of the playlist_append_* functions return 1 if append was successful 0 if failure (either directory could not be accessed or playlist on disk could not be opened) */ /* Add this filename to the playlist. Filename will be strdup()'ed. Note that this function will never fail. */ int playlist_append_file(playlist_t *list, char *filename) { list->last->next = playlist_element_create(filename); list->last = list->last->next; return 1; /* No way to fail */ } /* Recursively adds files from the directory and subdirectories */ int playlist_append_directory(playlist_t *list, char *dirname) { DIR *dir; int dir_len = strlen(dirname); struct dirent *entry; struct stat stat_buf; char nextfile[NAME_MAX + 1]; dir = opendir(dirname); if (dir == NULL) { return 0; } entry = readdir(dir); while (entry != NULL) { int sub_len = strlen(entry->d_name); /* Make sure full pathname is within limits and we don't parse the relative directory entries. */ if (dir_len + sub_len + 1 < NAME_MAX && strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 ) { /* Build the new full pathname */ strcpy(nextfile, dirname); strcat(nextfile, "/"); strcat(nextfile, entry->d_name); if (stat(nextfile, &stat_buf) == 0) { /* Decide what type of entry this is */ if (S_ISDIR(stat_buf.st_mode)) { /* Recursively follow directories */ if ( playlist_append_directory(list, nextfile) == 0 ) { fprintf(stderr, "Warning: Could not read directory %s.\n", nextfile); } } else { /* Assume everything else is a file of some sort */ playlist_append_file(list, nextfile); } } } entry = readdir(dir); } closedir(dir); return 1; } /* Opens a file containing filenames, one per line, and adds them to the playlist */ int playlist_append_from_file(playlist_t *list, char *playlist_filename) { FILE *fp; char filename[NAME_MAX+1]; struct stat stat_buf; int length; int i; if (strcmp(playlist_filename, "-") == 0) fp = stdin; else fp = fopen(playlist_filename, "r"); if (fp == NULL) return 0; while (!feof(fp)) { if ( fgets(filename, NAME_MAX+1 /* no, really! */, fp) == NULL ) continue; filename[NAME_MAX] = '\0'; /* Just to make sure */ length = strlen(filename); /* Skip blank lines */ for (i = 0; i < length && isspace(filename[i]); i++); if (i == length) continue; /* Crop off last \n if present */ if (filename[length - 1] == '\n') filename[length - 1] = '\0'; if (stat(filename, &stat_buf) == 0) { if (S_ISDIR(stat_buf.st_mode)) { if (playlist_append_directory(list, filename) == 0) fprintf(stderr, "Warning from playlist %s: " "Could not read directory %s.\n", playlist_filename, filename); } else { playlist_append_file(list, filename); } } else /* If we can't stat it, it might be a non-disk source */ playlist_append_file(list, filename); } return 1; } /* Return the number of items in the playlist */ int playlist_length(playlist_t *list) { int length; playlist_element_t *element; element = list->head; length = 0; /* don't count head node */ while (element->next != NULL) { length++; element = element->next; } return length; } /* Convert the playlist to an array of strings. Strings are deep copied. Size will be set to the number of elements in the array. */ char **playlist_to_array(playlist_t *list, int *size) { char **array; int i; playlist_element_t *element; *size = playlist_length(list); array = calloc(*size, sizeof(char *)); if (array == NULL) { fprintf(stderr, "Error: Out of memory in playlist_to_array().\n"); exit(1); } for (i = 0, element = list->head->next; i < *size; i++, element = element->next) { array[i] = strdup(element->filename); if (array[i] == NULL) { fprintf(stderr, "Error: Out of memory in playlist_to_array().\n"); exit(1); } } return array; } /* Deallocate array and all contained strings created by playlist_to_array. */ void playlist_array_destroy(char **array, int size) { int i; for (i = 0; i < size; i++) free(array[i]); free(array); } xmms-wma-1.0.5/wma123_examples/alsawma.c0000644000175000017500000001731510024451340020250 0ustar whistlerwhistler/** * 2004 * Example mini WMA player by McMCC * Use ALSA 0.9 or high... (dmix support) */ #include #include #include #include #include #ifdef HAVE_AV_CONFIG_H #undef HAVE_AV_CONFIG_H #endif #include "avcodec.h" #include "avformat.h" #include "playlist.h" #define ST_BUFF 2048 void audio_decode(const char *filename) { AVCodec *codec; AVPacket pkt; AVCodecContext *c= NULL; AVFormatContext *ic= NULL; int out_size, size, len, err, i, s_rate; int tns, thh, tmm, tss, st_buff, frames; uint8_t *outbuf, *inbuf_ptr, *s_outbuf; snd_pcm_t *playback_handle; snd_pcm_hw_params_t *hw_params; FifoBuffer f; err = av_open_input_file(&ic, filename, NULL, 0, NULL); if (err < 0) { printf("Error file %s\n", filename); exit(1); } for(i = 0; i < ic->nb_streams; i++) { c = &ic->streams[i]->codec; if(c->codec_type == CODEC_TYPE_AUDIO) break; } av_find_stream_info(ic); codec = avcodec_find_decoder(c->codec_id); if (!codec) { fprintf(stderr, "codec not found\n"); exit(1); } /* open it */ if (avcodec_open(c, codec) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } st_buff = ST_BUFF; outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); s_outbuf = malloc(st_buff); fprintf(stderr, "\n\n"); dump_format(ic, 0, filename, 0); if (ic->title[0] != '\0') fprintf(stderr, "Title: %s\n", ic->title); if (ic->author[0] != '\0') fprintf(stderr, "Author: %s\n", ic->author); if (ic->album[0] != '\0') fprintf(stderr, "Album: %s\n", ic->album); if (ic->year != 0) fprintf(stderr, "Year: %d\n", ic->year); if (ic->track != 0) fprintf(stderr, "Track: %d\n", ic->track); if (ic->genre[0] != '\0') fprintf(stderr, "Genre: %s\n", ic->genre); if (ic->copyright[0] != '\0') fprintf(stderr, "Copyright: %s\n", ic->copyright); if (ic->comment[0] != '\0') fprintf(stderr, "Comments: %s\n", ic->comment); if (ic->duration != 0) { tns = ic->duration/1000000LL; thh = tns/3600; tmm = (tns%3600)/60; tss = (tns%60); fprintf(stderr, "Time: %2d:%02d:%02d\n", thh, tmm, tss); } tns = 0; thh = 0; tmm = 0; tss = 0; if ((err = snd_pcm_open (&playback_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0) { fprintf (stderr, "cannot open audio device -default- (%s)\n", snd_strerror (err)); exit (1); } snd_pcm_nonblock(playback_handle, 0); if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) { fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n", snd_strerror (err)); exit (1); } if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) { fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n", snd_strerror (err)); exit (1); } if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { fprintf (stderr, "cannot set access type (%s)\n", snd_strerror (err)); exit (1); } if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) { fprintf (stderr, "cannot set sample format (%s)\n", snd_strerror (err)); exit (1); } s_rate = c->sample_rate; if ((err = snd_pcm_hw_params_set_channels_near(playback_handle, hw_params, &c->channels)) < 0) { fprintf (stderr, "cannot set channel count (%s)\n", snd_strerror (err)); exit (1); } if ((err = snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, &s_rate, 0)) < 0) { fprintf (stderr, "cannot set sample rate (%s)\n", snd_strerror (err)); exit (1); } int buffer_time = 500 * 1000; /* 500 ms */ if ((err = snd_pcm_hw_params_set_buffer_time_near(playback_handle, hw_params, &buffer_time, 0)) <0) { fprintf (stderr, "cannot set buffer time (%s)\n", snd_strerror (err)); exit (1); } int period_time = 50 * 1000; /* 50 ms */ if ((err = snd_pcm_hw_params_set_period_time_near(playback_handle, hw_params, &period_time, 0)) < 0) { fprintf (stderr, "cannot set period time (%s)\n", snd_strerror (err)); exit (1); } if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) { fprintf (stderr, "cannot set parameters (%s)\n", snd_strerror (err)); exit (1); } snd_pcm_hw_params_free (hw_params); if ((err = snd_pcm_prepare (playback_handle)) < 0) { fprintf (stderr, "cannot prepare audio interface for use (%s)\n", snd_strerror (err)); exit (1); } fprintf(stderr, "\n"); for(;;){ if (av_read_frame(ic, &pkt) < 0) break; size = pkt.size; inbuf_ptr = pkt.data; tns = pkt.pts/1000000LL; thh = tns/3600; tmm = (tns%3600)/60; tss = (tns%60); fprintf(stderr, "Play Time: %2d:%02d:%02d bitrate: %d kb/s\r", thh, tmm, tss, c->bit_rate / 1000); if (size == 0) break; while (size > 0) { len = avcodec_decode_audio(c, (short *)outbuf, &out_size, inbuf_ptr, size); if (len < 0) { break; } if (out_size <= 0) { continue; } if (out_size > 0) { fifo_init(&f, out_size*2); fifo_write(&f, outbuf, out_size, &f.wptr); while(fifo_read(&f, s_outbuf, st_buff, &f.rptr) == 0) { frames = snd_pcm_bytes_to_frames(playback_handle, st_buff); if((err = snd_pcm_writei (playback_handle, (short *)s_outbuf, frames)) < 0) { fprintf (stderr, "write to audio interface failed (%s)\n", snd_strerror (err)); exit (1); } } fifo_free(&f); } size -= len; inbuf_ptr += len; if (pkt.data) av_free_packet(&pkt); } } fprintf(stderr, "\n"); snd_pcm_close (playback_handle); if(s_outbuf) free(s_outbuf); if(outbuf) free(outbuf); avcodec_close(c); av_close_input_file(ic); } int main(int argc, char *argv[]) { char **playlist_array; playlist_t *playlist; int items, i; struct stat stat_s; if(!argv[1]) { fprintf(stderr,"\nUse %s file.wma\n\n", argv[0]); exit(0); } avcodec_init(); avcodec_register_all(); av_register_all(); playlist = playlist_create(); for (i = 1; i < argc; i++) { if (stat(argv[i], &stat_s) == 0) { if (S_ISDIR(stat_s.st_mode)) { if (playlist_append_directory(playlist, argv[i]) == 0) fprintf(stderr, "Warning: Could not read directory %s.\n", argv[i]); } else { playlist_append_file(playlist, argv[i]); } } else playlist_append_file(playlist, argv[i]); } if (playlist_length(playlist)) { playlist_array = playlist_to_array(playlist, &items); playlist_destroy(playlist); playlist = NULL; } else exit (1); i = 0; while ( i < items) { audio_decode(playlist_array[i]); i++; } playlist_array_destroy(playlist_array, items); exit (0); } xmms-wma-1.0.5/wma123_examples/artswma.c0000644000175000017500000001201610031062672020276 0ustar whistlerwhistler/** * 2004 * Example mini WMA player by McMCC * Use aRtsD sound server from KDE... */ #include #include #include #include #include #include #include #ifdef HAVE_AV_CONFIG_H #undef HAVE_AV_CONFIG_H #endif #include "avcodec.h" #include "avformat.h" #include "playlist.h" #define ST_BUFF 2048 void audio_decode(const char *filename) { AVCodec *codec; AVPacket pkt; AVCodecContext *c= NULL; AVFormatContext *ic= NULL; arts_stream_t stream; int out_size, size, len, err, i; int tns, thh, tmm, tss, st_buff; uint8_t *outbuf, *inbuf_ptr, *s_outbuf; FifoBuffer f; err = av_open_input_file(&ic, filename, NULL, 0, NULL); if (err < 0) { printf("Error file %s\n", filename); exit(0); } for(i = 0; i < ic->nb_streams; i++) { c = &ic->streams[i]->codec; if(c->codec_type == CODEC_TYPE_AUDIO) break; } av_find_stream_info(ic); codec = avcodec_find_decoder(c->codec_id); if (!codec) { fprintf(stderr, "codec not found\n"); exit(1); } /* open it */ if (avcodec_open(c, codec) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } st_buff = ST_BUFF; outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); s_outbuf = malloc(st_buff); fprintf(stderr, "\n\n"); dump_format(ic, 0, filename, 0); if (ic->title[0] != '\0') fprintf(stderr, "Title: %s\n", ic->title); if (ic->author[0] != '\0') fprintf(stderr, "Author: %s\n", ic->author); if (ic->album[0] != '\0') fprintf(stderr, "Album: %s\n", ic->album); if (ic->year != 0) fprintf(stderr, "Year: %d\n", ic->year); if (ic->track != 0) fprintf(stderr, "Track: %d\n", ic->track); if (ic->genre[0] != '\0') fprintf(stderr, "Genre: %s\n", ic->genre); if (ic->copyright[0] != '\0') fprintf(stderr, "Copyright: %s\n", ic->copyright); if (ic->comment[0] != '\0') fprintf(stderr, "Comments: %s\n", ic->comment); if (ic->duration != 0) { tns = ic->duration/1000000LL; thh = tns/3600; tmm = (tns%3600)/60; tss = (tns%60); fprintf(stderr, "Time: %2d:%02d:%02d\n", thh, tmm, tss); } tns = 0; thh = 0; tmm = 0; tss = 0; fprintf(stderr, "\n"); stream = arts_play_stream(c->sample_rate, 16, c->channels, "artswma"); for(;;){ if (av_read_frame(ic, &pkt) < 0) break; size = pkt.size; inbuf_ptr = pkt.data; tns = pkt.pts/1000000LL; thh = tns/3600; tmm = (tns%3600)/60; tss = (tns%60); fprintf(stderr, "Play Time: %2d:%02d:%02d bitrate: %d kb/s\r", thh, tmm, tss, c->bit_rate / 1000); if (size == 0) break; while (size > 0) { len = avcodec_decode_audio(c, (short *)outbuf, &out_size, inbuf_ptr, size); if (len < 0) { break; } if (out_size <= 0) { continue; } if (out_size > 0) { fifo_init(&f, out_size*2); fifo_write(&f, outbuf, out_size, &f.wptr); while(fifo_read(&f, s_outbuf, st_buff, &f.rptr) == 0) { err = arts_write(stream, s_outbuf, st_buff); if(err < 0) { fprintf(stderr, "arts_write error: %s\n", arts_error_text(err)); return; } } fifo_free(&f); } size -= len; inbuf_ptr += len; if (pkt.data) av_free_packet(&pkt); } } fprintf(stderr, "\n"); arts_close_stream(stream); if(outbuf) free(outbuf); if(s_outbuf) free(s_outbuf); avcodec_close(c); av_close_input_file(ic); } int main(int argc, char **argv) { int errorcode; char **playlist_array; playlist_t *playlist; int items, i; struct stat stat_s; if(!argv[1]) { fprintf(stderr,"\nUse %s file.wma\n\n", argv[0]); exit(0); } errorcode = arts_init(); if (errorcode < 0) { fprintf(stderr, "arts_init error: %s\n", arts_error_text(errorcode)); return 1; } avcodec_init(); avcodec_register_all(); av_register_all(); playlist = playlist_create(); for (i = 1; i < argc; i++) { if (stat(argv[i], &stat_s) == 0) { if (S_ISDIR(stat_s.st_mode)) { if (playlist_append_directory(playlist, argv[i]) == 0) fprintf(stderr, "Warning: Could not read directory %s.\n", argv[i]); } else { playlist_append_file(playlist, argv[i]); } } else playlist_append_file(playlist, argv[i]); } if (playlist_length(playlist)) { playlist_array = playlist_to_array(playlist, &items); playlist_destroy(playlist); playlist = NULL; } else exit (1); i = 0; while ( i < items) { audio_decode(playlist_array[i]); i++; } playlist_array_destroy(playlist_array, items); arts_free(); exit (0); } xmms-wma-1.0.5/wma123_examples/playlist.h0000644000175000017500000000475007511461241020500 0ustar whistlerwhistler/******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY * * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. * * PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2002 * * by Kenneth C. Arnold AND OTHER CONTRIBUTORS * * http://www.xiph.org/ * * * ******************************************************************** last mod: $Id: playlist.h,v 1.1 2002/07/06 03:23:13 volsung Exp $ ********************************************************************/ #ifndef __PLAYLIST_H__ #define __PLAYLIST_H__ typedef struct playlist_element_t { char *filename; struct playlist_element_t *next; } playlist_element_t; /* Actual playlist structure */ typedef struct playlist_t { /* Linked list with empty head node */ playlist_element_t *head; /* Keep track of this for speedy appends */ playlist_element_t *last; } playlist_t; playlist_t *playlist_create(); void playlist_destroy(playlist_t *list); /* All of the playlist_append_* functions return 1 if append was successful 0 if failure (either directory could not be accessed or playlist on disk could not be opened) */ /* Add this filename to the playlist. Filename will be strdup()'ed. Note that this function will never fail. */ int playlist_append_file(playlist_t *list, char *filename); /* Recursively adds files from the directory and subdirectories */ int playlist_append_directory(playlist_t *list, char *dirname); /* Opens a file containing filenames, one per line, and adds them to the playlist */ int playlist_append_from_file(playlist_t *list, char *playlist_filename); /* Return the number of items in the playlist */ int playlist_length(playlist_t *list); /* Convert the playlist to an array of strings. Strings are deep copied. Size will be set to the number of elements in the array. */ char **playlist_to_array(playlist_t *list, int *size); /* Deallocate array and all contained strings created by playlist_to_array. */ void playlist_array_destroy(char **array, int size); #endif /* __PLAYLIST_H__ */ xmms-wma-1.0.5/wma123_examples/osswma.c0000644000175000017500000001233310030645143020132 0ustar whistlerwhistler/** * 2004 * Example mini WMA player by McMCC * Use OSS Sound system */ #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_AV_CONFIG_H #undef HAVE_AV_CONFIG_H #endif #include "avcodec.h" #include "avformat.h" #include "playlist.h" #define ST_BUFF 2048 void audio_decode(const char *filename) { AVCodec *codec; AVPacket pkt; AVCodecContext *c= NULL; AVFormatContext *ic= NULL; int out_size, size, len, err, i; int tns, thh, tmm, tss, st_buff; uint8_t *outbuf, *inbuf_ptr, *s_outbuf; FifoBuffer f; int oss_fd = -1; int val; err = av_open_input_file(&ic, filename, NULL, 0, NULL); if (err < 0) { printf("Error file %s\n", filename); exit(1); } for(i = 0; i < ic->nb_streams; i++) { c = &ic->streams[i]->codec; if(c->codec_type == CODEC_TYPE_AUDIO) break; } av_find_stream_info(ic); codec = avcodec_find_decoder(c->codec_id); if (!codec) { fprintf(stderr, "codec not found\n"); exit(1); } /* open it */ if (avcodec_open(c, codec) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } st_buff = ST_BUFF; outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); s_outbuf = malloc(st_buff); fprintf(stderr, "\n\n"); dump_format(ic, 0, filename, 0); if (ic->title[0] != '\0') fprintf(stderr, "Title: %s\n", ic->title); if (ic->author[0] != '\0') fprintf(stderr, "Author: %s\n", ic->author); if (ic->album[0] != '\0') fprintf(stderr, "Album: %s\n", ic->album); if (ic->year != 0) fprintf(stderr, "Year: %d\n", ic->year); if (ic->track != 0) fprintf(stderr, "Track: %d\n", ic->track); if (ic->genre[0] != '\0') fprintf(stderr, "Genre: %s\n", ic->genre); if (ic->copyright[0] != '\0') fprintf(stderr, "Copyright: %s\n", ic->copyright); if (ic->comment[0] != '\0') fprintf(stderr, "Comments: %s\n", ic->comment); if (ic->duration != 0) { tns = ic->duration/1000000LL; thh = tns/3600; tmm = (tns%3600)/60; tss = (tns%60); fprintf(stderr, "Time: %2d:%02d:%02d\n", thh, tmm, tss); } tns = 0; thh = 0; tmm = 0; tss = 0; if ((oss_fd = open("/dev/dsp0", O_WRONLY, 0)) == -1) { fprintf (stderr, "cannot open audio device /dev/dsp0\n"); exit (1); } val = AFMT_S16_LE; err = ioctl(oss_fd, SNDCTL_DSP_SETFMT, &val); if(err < 0) { perror("SNDCTL_DSP_SETFMT"); exit (1); } val = c->channels-1; err = ioctl(oss_fd, SNDCTL_DSP_STEREO, &val); if(err < 0) { perror("SNDCTL_DSP_STEREO"); exit (1); } val = c->sample_rate; err = ioctl(oss_fd, SNDCTL_DSP_SPEED, &val); if(err < 0) { perror("SNDCTL_DSP_SPEED"); exit (1); } val = 16; err = ioctl(oss_fd, SNDCTL_DSP_SAMPLESIZE, &val); if(err < 0) { perror("SNDCTL_DSP_SAMPLESIZE"); exit (1); } for(;;){ if (av_read_frame(ic, &pkt) < 0) break; size = pkt.size; inbuf_ptr = pkt.data; tns = pkt.pts/1000000LL; thh = tns/3600; tmm = (tns%3600)/60; tss = (tns%60); fprintf(stderr, "Play Time: %2d:%02d:%02d bitrate: %d kb/s\r", thh, tmm, tss, c->bit_rate / 1000); if (size == 0) break; while (size > 0) { len = avcodec_decode_audio(c, (short *)outbuf, &out_size, inbuf_ptr, size); if (len < 0) { break; } if (out_size <= 0) { continue; } if (out_size > 0) { fifo_init(&f, out_size*2); fifo_write(&f, outbuf, out_size, &f.wptr); while(fifo_read(&f, s_outbuf, st_buff, &f.rptr) == 0) { write(oss_fd, (short *)s_outbuf, st_buff); } fifo_free(&f); } size -= len; inbuf_ptr += len; if (pkt.data) av_free_packet(&pkt); } } fprintf(stderr, "\n"); close(oss_fd); if(s_outbuf) free(s_outbuf); if(outbuf) free(outbuf); avcodec_close(c); av_close_input_file(ic); } int main(int argc, char *argv[]) { char **playlist_array; playlist_t *playlist; int items, i; struct stat stat_s; if(!argv[1]) { fprintf(stderr,"\nUse %s file.wma\n\n", argv[0]); exit(0); } avcodec_init(); avcodec_register_all(); av_register_all(); playlist = playlist_create(); for (i = 1; i < argc; i++) { if (stat(argv[i], &stat_s) == 0) { if (S_ISDIR(stat_s.st_mode)) { if (playlist_append_directory(playlist, argv[i]) == 0) fprintf(stderr, "Warning: Could not read directory %s.\n", argv[i]); } else { playlist_append_file(playlist, argv[i]); } } else playlist_append_file(playlist, argv[i]); } if (playlist_length(playlist)) { playlist_array = playlist_to_array(playlist, &items); playlist_destroy(playlist); playlist = NULL; } else exit (1); i = 0; while ( i < items) { audio_decode(playlist_array[i]); i++; } playlist_array_destroy(playlist_array, items); exit (0); } xmms-wma-1.0.5/wma123_examples/Makefile0000644000175000017500000000157010031060763020116 0ustar whistlerwhistlerinclude ../ffmpeg-strip-wma/config.mak INC=-I../ffmpeg-strip-wma LIB=-L../ffmpeg-strip-wma CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE all: artswma alsawma osswma clean: rm -f *.o *.d *~ artswma alsawma osswma playlist.o: playlist.c playlist.h $(CC) $(CFLAGS) -c -o $@ $< distclean: clean rm -f Makefile.bak .depend artswma: artswma.c playlist.o $(CC) $(CFLAGS) $(INC) -s -o $@ $< playlist.o $(LIB) $(EXTRALIBS) `artsc-config --cflags` `artsc-config --libs` -lm -lffwma alsawma: alsawma.c playlist.o $(CC) $(CFLAGS) $(INC) -s -o $@ $< playlist.o $(LIB) $(EXTRALIBS) -lasound -lm -lffwma osswma: osswma.c playlist.o $(CC) $(CFLAGS) $(INC) -s -o $@ $< playlist.o $(LIB) $(EXTRALIBS) -lm -lffwma install: install -m 744 artswma $(prefix)/bin install -m 744 alsawma $(prefix)/bin install -m 744 osswma $(prefix)/bin xmms-wma-1.0.5/ffmpeg-strip-wma/0000755000175000017500000000000010307131204016723 5ustar whistlerwhistlerxmms-wma-1.0.5/ffmpeg-strip-wma/dsputil.h0000644000175000017500000004347310016246312020577 0ustar whistlerwhistler/* * DSP utils * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file dsputil.h * DSP utils. * note, many functions in here may use MMX which trashes the FPU state, it is * absolutely necessary to call emms_c() between dsp & float/double code */ #ifndef DSPUTIL_H #define DSPUTIL_H #include "common.h" #include "avcodec.h" //#define DEBUG /* dct code */ typedef short DCTELEM; void fdct_ifast (DCTELEM *data); void fdct_ifast248 (DCTELEM *data); void ff_jpeg_fdct_islow (DCTELEM *data); void ff_fdct248_islow (DCTELEM *data); void j_rev_dct (DCTELEM *data); void ff_fdct_mmx(DCTELEM *block); void ff_fdct_mmx2(DCTELEM *block); void ff_fdct_sse2(DCTELEM *block); /* encoding scans */ extern const uint8_t ff_alternate_horizontal_scan[64]; extern const uint8_t ff_alternate_vertical_scan[64]; extern const uint8_t ff_zigzag_direct[64]; extern const uint8_t ff_zigzag248_direct[64]; /* pixel operations */ #define MAX_NEG_CROP 384 /* temporary */ extern uint32_t squareTbl[512]; extern uint8_t cropTbl[256 + 2 * MAX_NEG_CROP]; /* minimum alignment rules ;) if u notice errors in the align stuff, need more alignment for some asm code for some cpu or need to use a function with less aligned data then send a mail to the ffmpeg-dev list, ... !warning these alignments might not match reallity, (missing attribute((align)) stuff somewhere possible) i (michael) didnt check them, these are just the alignents which i think could be reached easily ... !future video codecs might need functions with less strict alignment */ /* void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size); void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride); void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size); void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size); void clear_blocks_c(DCTELEM *blocks); */ /* add and put pixel (decoding) */ // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16 //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4 typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h); typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h); typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride); typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y); #define DEF_OLD_QPEL(name)\ void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\ void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\ void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride); DEF_OLD_QPEL(qpel16_mc11_old_c) DEF_OLD_QPEL(qpel16_mc31_old_c) DEF_OLD_QPEL(qpel16_mc12_old_c) DEF_OLD_QPEL(qpel16_mc32_old_c) DEF_OLD_QPEL(qpel16_mc13_old_c) DEF_OLD_QPEL(qpel16_mc33_old_c) DEF_OLD_QPEL(qpel8_mc11_old_c) DEF_OLD_QPEL(qpel8_mc31_old_c) DEF_OLD_QPEL(qpel8_mc12_old_c) DEF_OLD_QPEL(qpel8_mc32_old_c) DEF_OLD_QPEL(qpel8_mc13_old_c) DEF_OLD_QPEL(qpel8_mc33_old_c) #define CALL_2X_PIXELS(a, b, n)\ static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ b(block , pixels , line_size, h);\ b(block+n, pixels+n, line_size, h);\ } /* motion estimation */ // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2 // allthough currently h<4 is not used as functions with width <8 are not used and neither implemented typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/; /** * DSPContext. */ typedef struct DSPContext { /* pixel ops : interface with DCT */ void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size); void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride); void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); /** * translational global motion compensation. */ void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder); /** * global motion compensation. */ void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); void (*clear_blocks)(DCTELEM *blocks/*align 16*/); int (*pix_sum)(uint8_t * pix, int line_size); int (*pix_norm1)(uint8_t * pix, int line_size); // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4 me_cmp_func sad[5]; /* identical to pix_absAxA except additional void * */ me_cmp_func sse[5]; me_cmp_func hadamard8_diff[5]; me_cmp_func dct_sad[5]; me_cmp_func quant_psnr[5]; me_cmp_func bit[5]; me_cmp_func rd[5]; me_cmp_func vsad[5]; me_cmp_func vsse[5]; me_cmp_func me_pre_cmp[5]; me_cmp_func me_cmp[5]; me_cmp_func me_sub_cmp[5]; me_cmp_func mb_cmp[5]; me_cmp_func ildct_cmp[5]; //only width 16 used /** * Halfpel motion compensation with rounding (a+b+1)>>1. * this is an array[4][4] of motion compensation funcions for 4 * horizontal blocksizes (8,16) and the 4 halfpel positions
* *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] * @param block destination where the result is stored * @param pixels source * @param line_size number of bytes in a horizontal line of block * @param h height */ op_pixels_func put_pixels_tab[4][4]; /** * Halfpel motion compensation with rounding (a+b+1)>>1. * This is an array[4][4] of motion compensation functions for 4 * horizontal blocksizes (8,16) and the 4 halfpel positions
* *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] * @param block destination into which the result is averaged (a+b+1)>>1 * @param pixels source * @param line_size number of bytes in a horizontal line of block * @param h height */ op_pixels_func avg_pixels_tab[4][4]; /** * Halfpel motion compensation with no rounding (a+b)>>1. * this is an array[2][4] of motion compensation funcions for 2 * horizontal blocksizes (8,16) and the 4 halfpel positions
* *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] * @param block destination where the result is stored * @param pixels source * @param line_size number of bytes in a horizontal line of block * @param h height */ op_pixels_func put_no_rnd_pixels_tab[2][4]; /** * Halfpel motion compensation with no rounding (a+b)>>1. * this is an array[2][4] of motion compensation funcions for 2 * horizontal blocksizes (8,16) and the 4 halfpel positions
* *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] * @param block destination into which the result is averaged (a+b)>>1 * @param pixels source * @param line_size number of bytes in a horizontal line of block * @param h height */ op_pixels_func avg_no_rnd_pixels_tab[2][4]; /** * Thirdpel motion compensation with rounding (a+b+1)>>1. * this is an array[12] of motion compensation funcions for the 9 thirdpel positions
* *pixels_tab[ xthirdpel + 4*ythirdpel ] * @param block destination where the result is stored * @param pixels source * @param line_size number of bytes in a horizontal line of block * @param h height */ tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width? tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width? qpel_mc_func put_qpel_pixels_tab[2][16]; qpel_mc_func avg_qpel_pixels_tab[2][16]; qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16]; qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16]; qpel_mc_func put_mspel_pixels_tab[8]; /** * h264 Chram MC */ h264_chroma_mc_func put_h264_chroma_pixels_tab[3]; h264_chroma_mc_func avg_h264_chroma_pixels_tab[3]; qpel_mc_func put_h264_qpel_pixels_tab[3][16]; qpel_mc_func avg_h264_qpel_pixels_tab[3][16]; me_cmp_func pix_abs[2][4]; /* huffyuv specific */ void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w); void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w); /** * subtract huffyuv's variant of median prediction * note, this might read from src1[-1], src2[-1] */ void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top); void (*bswap_buf)(uint32_t *dst, uint32_t *src, int w); void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale); void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale); /* (I)DCT */ void (*fdct)(DCTELEM *block/* align 16*/); void (*fdct248)(DCTELEM *block/* align 16*/); /* IDCT really*/ void (*idct)(DCTELEM *block/* align 16*/); /** * block -> idct -> clip to unsigned 8 bit -> dest. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...) * @param line_size size in bytes of a horizotal line of dest */ void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); /** * block -> idct -> add dest -> clip to unsigned 8 bit -> dest. * @param line_size size in bytes of a horizotal line of dest */ void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); /** * idct input permutation. * several optimized IDCTs need a permutated input (relative to the normal order of the reference * IDCT) * this permutation must be performed before the idct_put/add, note, normally this can be merged * with the zigzag/alternate scan
* an example to avoid confusion: * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...) * - (x -> referece dct -> reference idct -> x) * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x) * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...) */ uint8_t idct_permutation[64]; int idct_permutation_type; #define FF_NO_IDCT_PERM 1 #define FF_LIBMPEG2_IDCT_PERM 2 #define FF_SIMPLE_IDCT_PERM 3 #define FF_TRANSPOSE_IDCT_PERM 4 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale); void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale); #define BASIS_SHIFT 16 #define RECON_SHIFT 6 } DSPContext; void dsputil_static_init(void); void dsputil_init(DSPContext* p, AVCodecContext *avctx); /** * permute block according to permuatation. * @param last last non zero element in scantable order */ void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last); void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type); #define BYTE_VEC32(c) ((c)*0x01010101UL) static inline uint32_t rnd_avg32(uint32_t a, uint32_t b) { return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); } static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b) { return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); } /** * Empty mmx state. * this must be called between any dsp function and float/double code. * for example sin(); dsp->idct_put(); emms_c(); cos() */ #define emms_c() /* should be defined by architectures supporting one or more MultiMedia extension */ int mm_support(void); #if defined(HAVE_MMX) #undef emms_c #define MM_MMX 0x0001 /* standard MMX */ #define MM_3DNOW 0x0004 /* AMD 3DNOW */ #define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */ #define MM_SSE 0x0008 /* SSE functions */ #define MM_SSE2 0x0010 /* PIV SSE2 functions */ extern int mm_flags; void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); static inline void emms(void) { __asm __volatile ("emms;":::"memory"); } #define emms_c() \ {\ if (mm_flags & MM_MMX)\ emms();\ } #define __align8 __attribute__ ((aligned (8))) void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx); void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx); #elif defined(ARCH_ARMV4L) /* This is to use 4 bytes read to the IDCT pointers for some 'zero' line ptimizations */ #define __align8 __attribute__ ((aligned (4))) void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx); #elif defined(HAVE_MLIB) /* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */ #define __align8 __attribute__ ((aligned (8))) void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx); #elif defined(ARCH_ALPHA) #define __align8 __attribute__ ((aligned (8))) void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx); #elif defined(ARCH_POWERPC) #define MM_ALTIVEC 0x0001 /* standard AltiVec */ extern int mm_flags; #if defined(HAVE_ALTIVEC) && !defined(CONFIG_DARWIN) #define pixel altivec_pixel #include #undef pixel #endif #define __align8 __attribute__ ((aligned (16))) void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx); #elif defined(HAVE_MMI) #define __align8 __attribute__ ((aligned (16))) void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx); #elif defined(ARCH_SH4) #define __align8 __attribute__ ((aligned (8))) void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); #else #define __align8 #endif #ifdef __GNUC__ struct unaligned_64 { uint64_t l; } __attribute__((packed)); struct unaligned_32 { uint32_t l; } __attribute__((packed)); struct unaligned_16 { uint16_t l; } __attribute__((packed)); #define LD16(a) (((const struct unaligned_16 *) (a))->l) #define LD32(a) (((const struct unaligned_32 *) (a))->l) #define LD64(a) (((const struct unaligned_64 *) (a))->l) #define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b) #else /* __GNUC__ */ #define LD16(a) (*((uint16_t*)(a))) #define LD32(a) (*((uint32_t*)(a))) #define LD64(a) (*((uint64_t*)(a))) #define ST32(a, b) *((uint32_t*)(a)) = (b) #endif /* !__GNUC__ */ /* PSNR */ void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3], int orig_linesize[3], int coded_linesize, AVCodecContext *avctx); /* FFT computation */ /* NOTE: soon integer code will be added, so you must use the FFTSample type */ typedef float FFTSample; typedef struct FFTComplex { FFTSample re, im; } FFTComplex; typedef struct FFTContext { int nbits; int inverse; uint16_t *revtab; FFTComplex *exptab; FFTComplex *exptab1; /* only used by SSE code */ void (*fft_calc)(struct FFTContext *s, FFTComplex *z); } FFTContext; int fft_inits(FFTContext *s, int nbits, int inverse); void fft_permute(FFTContext *s, FFTComplex *z); void fft_calc_c(FFTContext *s, FFTComplex *z); void fft_calc_sse(FFTContext *s, FFTComplex *z); void fft_calc_altivec(FFTContext *s, FFTComplex *z); static inline void fft_calc(FFTContext *s, FFTComplex *z) { s->fft_calc(s, z); } void fft_end(FFTContext *s); /* MDCT computation */ typedef struct MDCTContext { int n; /* size of MDCT (i.e. number of input data * 2) */ int nbits; /* n = 2^nbits */ /* pre/post rotation tables */ FFTSample *tcos; FFTSample *tsin; FFTContext fft; } MDCTContext; int ff_mdct_init(MDCTContext *s, int nbits, int inverse); void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input, FFTSample *tmp); void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input, FFTSample *tmp); void ff_mdct_end(MDCTContext *s); #define WARPER8_16(name8, name16)\ static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ return name8(s, dst , src , stride, h)\ +name8(s, dst+8 , src+8 , stride, h);\ } #define WARPER8_16_SQ(name8, name16)\ static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ int score=0;\ score +=name8(s, dst , src , stride, 8);\ score +=name8(s, dst+8 , src+8 , stride, 8);\ if(h==16){\ dst += 8*stride;\ src += 8*stride;\ score +=name8(s, dst , src , stride, 8);\ score +=name8(s, dst+8 , src+8 , stride, 8);\ }\ return score;\ } #ifndef HAVE_LRINTF /* XXX: add ISOC specific test to avoid specific BSD testing. */ /* better than nothing implementation. */ /* btw, rintf() is existing on fbsd too -- alex */ static inline long int lrintf(float x) { #ifdef CONFIG_WIN32 /* XXX: incorrect, but make it compile */ return (int)(x); #else return (int)(rint(x)); #endif } #endif #endif xmms-wma-1.0.5/ffmpeg-strip-wma/mdct.c0000644000175000017500000001065410016247112020027 0ustar whistlerwhistler/* * MDCT/IMDCT transforms * Copyright (c) 2002 Fabrice Bellard. * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "dsputil.h" /** * @file mdct.c * MDCT/IMDCT transforms. */ /** * init MDCT or IMDCT computation. */ int ff_mdct_init(MDCTContext *s, int nbits, int inverse) { int n, n4, i; float alpha; memset(s, 0, sizeof(*s)); n = 1 << nbits; s->nbits = nbits; s->n = n; n4 = n >> 2; s->tcos = av_malloc(n4 * sizeof(FFTSample)); if (!s->tcos) goto fail; s->tsin = av_malloc(n4 * sizeof(FFTSample)); if (!s->tsin) goto fail; for(i=0;itcos[i] = -cos(alpha); s->tsin[i] = -sin(alpha); } if (fft_inits(&s->fft, s->nbits - 2, inverse) < 0) goto fail; return 0; fail: av_freep(&s->tcos); av_freep(&s->tsin); return -1; } /* complex multiplication: p = a * b */ #define CMUL(pre, pim, are, aim, bre, bim) \ {\ float _are = (are);\ float _aim = (aim);\ float _bre = (bre);\ float _bim = (bim);\ (pre) = _are * _bre - _aim * _bim;\ (pim) = _are * _bim + _aim * _bre;\ } /** * Compute inverse MDCT of size N = 2^nbits * @param output N samples * @param input N/2 samples * @param tmp N/2 samples */ void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input, FFTSample *tmp) { int k, n8, n4, n2, n, j; const uint16_t *revtab = s->fft.revtab; const FFTSample *tcos = s->tcos; const FFTSample *tsin = s->tsin; const FFTSample *in1, *in2; FFTComplex *z = (FFTComplex *)tmp; n = 1 << s->nbits; n2 = n >> 1; n4 = n >> 2; n8 = n >> 3; /* pre rotation */ in1 = input; in2 = input + n2 - 1; for(k = 0; k < n4; k++) { j=revtab[k]; CMUL(z[j].re, z[j].im, *in2, *in1, tcos[k], tsin[k]); in1 += 2; in2 -= 2; } fft_calc(&s->fft, z); /* post rotation + reordering */ /* XXX: optimize */ for(k = 0; k < n4; k++) { CMUL(z[k].re, z[k].im, z[k].re, z[k].im, tcos[k], tsin[k]); } for(k = 0; k < n8; k++) { output[2*k] = -z[n8 + k].im; output[n2-1-2*k] = z[n8 + k].im; output[2*k+1] = z[n8-1-k].re; output[n2-1-2*k-1] = -z[n8-1-k].re; output[n2 + 2*k]=-z[k+n8].re; output[n-1- 2*k]=-z[k+n8].re; output[n2 + 2*k+1]=z[n8-k-1].im; output[n-2 - 2 * k] = z[n8-k-1].im; } } /** * Compute MDCT of size N = 2^nbits * @param input N samples * @param out N/2 samples * @param tmp temporary storage of N/2 samples */ void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input, FFTSample *tmp) { int i, j, n, n8, n4, n2, n3; FFTSample re, im, re1, im1; const uint16_t *revtab = s->fft.revtab; const FFTSample *tcos = s->tcos; const FFTSample *tsin = s->tsin; FFTComplex *x = (FFTComplex *)tmp; n = 1 << s->nbits; n2 = n >> 1; n4 = n >> 2; n8 = n >> 3; n3 = 3 * n4; /* pre rotation */ for(i=0;ifft, x); /* post rotation */ for(i=0;itcos); av_freep(&s->tsin); fft_end(&s->fft); } xmms-wma-1.0.5/ffmpeg-strip-wma/aviobuf.c0000644000175000017500000004024507742674171020557 0ustar whistlerwhistler/* * Buffered I/O for ffmpeg system * Copyright (c) 2000,2001 Fabrice Bellard * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avformat.h" #include "avio.h" #include #define IO_BUFFER_SIZE 32768 int init_put_byte(ByteIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), void (*write_packet)(void *opaque, uint8_t *buf, int buf_size), int (*seek)(void *opaque, offset_t offset, int whence)) { s->buffer = buffer; s->buffer_size = buffer_size; s->buf_ptr = buffer; s->write_flag = write_flag; if (!s->write_flag) s->buf_end = buffer; else s->buf_end = buffer + buffer_size; s->opaque = opaque; s->write_packet = write_packet; s->read_packet = read_packet; s->seek = seek; s->pos = 0; s->must_flush = 0; s->eof_reached = 0; s->is_streamed = 0; s->max_packet_size = 0; return 0; } #ifdef CONFIG_ENCODERS static void flush_buffer(ByteIOContext *s) { if (s->buf_ptr > s->buffer) { if (s->write_packet) s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer); s->pos += s->buf_ptr - s->buffer; } s->buf_ptr = s->buffer; } void put_byte(ByteIOContext *s, int b) { *(s->buf_ptr)++ = b; if (s->buf_ptr >= s->buf_end) flush_buffer(s); } void put_buffer(ByteIOContext *s, const unsigned char *buf, int size) { int len; while (size > 0) { len = (s->buf_end - s->buf_ptr); if (len > size) len = size; memcpy(s->buf_ptr, buf, len); s->buf_ptr += len; if (s->buf_ptr >= s->buf_end) flush_buffer(s); buf += len; size -= len; } } void put_flush_packet(ByteIOContext *s) { flush_buffer(s); s->must_flush = 0; } #endif //CONFIG_ENCODERS offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence) { offset_t offset1; if (whence != SEEK_CUR && whence != SEEK_SET) return -EINVAL; #ifdef CONFIG_ENCODERS if (s->write_flag) { if (whence == SEEK_CUR) { offset1 = s->pos + (s->buf_ptr - s->buffer); if (offset == 0) return offset1; offset += offset1; } offset1 = offset - s->pos; if (!s->must_flush && offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) { /* can do the seek inside the buffer */ s->buf_ptr = s->buffer + offset1; } else { if (!s->seek) return -EPIPE; flush_buffer(s); s->must_flush = 1; s->buf_ptr = s->buffer; s->seek(s->opaque, offset, SEEK_SET); s->pos = offset; } } else #endif //CONFIG_ENCODERS { if (whence == SEEK_CUR) { offset1 = s->pos - (s->buf_end - s->buffer) + (s->buf_ptr - s->buffer); if (offset == 0) return offset1; offset += offset1; } offset1 = offset - (s->pos - (s->buf_end - s->buffer)); if (offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) { /* can do the seek inside the buffer */ s->buf_ptr = s->buffer + offset1; } else { if (!s->seek) return -EPIPE; s->buf_ptr = s->buffer; s->buf_end = s->buffer; s->seek(s->opaque, offset, SEEK_SET); s->pos = offset; } s->eof_reached = 0; } return offset; } void url_fskip(ByteIOContext *s, offset_t offset) { url_fseek(s, offset, SEEK_CUR); } offset_t url_ftell(ByteIOContext *s) { return url_fseek(s, 0, SEEK_CUR); } int url_feof(ByteIOContext *s) { return s->eof_reached; } #ifdef CONFIG_ENCODERS void put_le32(ByteIOContext *s, unsigned int val) { put_byte(s, val); put_byte(s, val >> 8); put_byte(s, val >> 16); put_byte(s, val >> 24); } void put_be32(ByteIOContext *s, unsigned int val) { put_byte(s, val >> 24); put_byte(s, val >> 16); put_byte(s, val >> 8); put_byte(s, val); } /* IEEE format is assumed */ void put_be64_double(ByteIOContext *s, double val) { union { double d; uint64_t ull; } u; u.d = val; put_be64(s, u.ull); } void put_strz(ByteIOContext *s, const char *str) { if (str) put_buffer(s, (const unsigned char *) str, strlen(str) + 1); else put_byte(s, 0); } void put_le64(ByteIOContext *s, uint64_t val) { put_le32(s, (uint32_t)(val & 0xffffffff)); put_le32(s, (uint32_t)(val >> 32)); } void put_be64(ByteIOContext *s, uint64_t val) { put_be32(s, (uint32_t)(val >> 32)); put_be32(s, (uint32_t)(val & 0xffffffff)); } void put_le16(ByteIOContext *s, unsigned int val) { put_byte(s, val); put_byte(s, val >> 8); } void put_be16(ByteIOContext *s, unsigned int val) { put_byte(s, val >> 8); put_byte(s, val); } void put_tag(ByteIOContext *s, const char *tag) { while (*tag) { put_byte(s, *tag++); } } #endif //CONFIG_ENCODERS /* Input stream */ static void fill_buffer(ByteIOContext *s) { int len; /* no need to do anything if EOF already reached */ if (s->eof_reached) return; len = s->read_packet(s->opaque, s->buffer, s->buffer_size); if (len <= 0) { /* do not modify buffer if EOF reached so that a seek back can be done without rereading data */ s->eof_reached = 1; } else { s->pos += len; s->buf_ptr = s->buffer; s->buf_end = s->buffer + len; } } /* NOTE: return 0 if EOF, so you cannot use it if EOF handling is necessary */ /* XXX: put an inline version */ int get_byte(ByteIOContext *s) { if (s->buf_ptr < s->buf_end) { return *s->buf_ptr++; } else { fill_buffer(s); if (s->buf_ptr < s->buf_end) return *s->buf_ptr++; else return 0; } } /* NOTE: return URL_EOF (-1) if EOF */ int url_fgetc(ByteIOContext *s) { if (s->buf_ptr < s->buf_end) { return *s->buf_ptr++; } else { fill_buffer(s); if (s->buf_ptr < s->buf_end) return *s->buf_ptr++; else return URL_EOF; } } int get_buffer(ByteIOContext *s, unsigned char *buf, int size) { int len, size1; size1 = size; while (size > 0) { len = s->buf_end - s->buf_ptr; if (len > size) len = size; if (len == 0) { fill_buffer(s); len = s->buf_end - s->buf_ptr; if (len == 0) break; } else { memcpy(buf, s->buf_ptr, len); buf += len; s->buf_ptr += len; size -= len; } } return size1 - size; } unsigned int get_le16(ByteIOContext *s) { unsigned int val; val = get_byte(s); val |= get_byte(s) << 8; return val; } unsigned int get_le32(ByteIOContext *s) { unsigned int val; val = get_byte(s); val |= get_byte(s) << 8; val |= get_byte(s) << 16; val |= get_byte(s) << 24; return val; } uint64_t get_le64(ByteIOContext *s) { uint64_t val; val = (uint64_t)get_le32(s); val |= (uint64_t)get_le32(s) << 32; return val; } unsigned int get_be16(ByteIOContext *s) { unsigned int val; val = get_byte(s) << 8; val |= get_byte(s); return val; } unsigned int get_be32(ByteIOContext *s) { unsigned int val; val = get_byte(s) << 24; val |= get_byte(s) << 16; val |= get_byte(s) << 8; val |= get_byte(s); return val; } double get_be64_double(ByteIOContext *s) { union { double d; uint64_t ull; } u; u.ull = get_be64(s); return u.d; } char *get_strz(ByteIOContext *s, char *buf, int maxlen) { int i = 0; char c; while ((c = get_byte(s))) { if (i < maxlen-1) buf[i++] = c; } buf[i] = 0; /* Ensure null terminated, but may be truncated */ return buf; } uint64_t get_be64(ByteIOContext *s) { uint64_t val; val = (uint64_t)get_be32(s) << 32; val |= (uint64_t)get_be32(s); return val; } /* link with avio functions */ #ifdef CONFIG_ENCODERS static void url_write_packet(void *opaque, uint8_t *buf, int buf_size) { URLContext *h = opaque; url_write(h, buf, buf_size); } #else #define url_write_packet NULL #endif //CONFIG_ENCODERS static int url_read_packet(void *opaque, uint8_t *buf, int buf_size) { URLContext *h = opaque; return url_read(h, buf, buf_size); } static int url_seek_packet(void *opaque, int64_t offset, int whence) { URLContext *h = opaque; url_seek(h, offset, whence); return 0; } int url_fdopen(ByteIOContext *s, URLContext *h) { uint8_t *buffer; int buffer_size, max_packet_size; max_packet_size = url_get_max_packet_size(h); if (max_packet_size) { buffer_size = max_packet_size; /* no need to bufferize more than one packet */ } else { buffer_size = IO_BUFFER_SIZE; } buffer = av_malloc(buffer_size); if (!buffer) return -ENOMEM; if (init_put_byte(s, buffer, buffer_size, (h->flags & URL_WRONLY) != 0, h, url_read_packet, url_write_packet, url_seek_packet) < 0) { av_free(buffer); return -EIO; } s->is_streamed = h->is_streamed; s->max_packet_size = max_packet_size; return 0; } /* XXX: must be called before any I/O */ int url_setbufsize(ByteIOContext *s, int buf_size) { uint8_t *buffer; buffer = av_malloc(buf_size); if (!buffer) return -ENOMEM; av_free(s->buffer); s->buffer = buffer; s->buffer_size = buf_size; s->buf_ptr = buffer; if (!s->write_flag) s->buf_end = buffer; else s->buf_end = buffer + buf_size; return 0; } /* NOTE: when opened as read/write, the buffers are only used for reading */ int url_fopen(ByteIOContext *s, const char *filename, int flags) { URLContext *h; int err; err = url_open(&h, filename, flags); if (err < 0) return err; err = url_fdopen(s, h); if (err < 0) { url_close(h); return err; } return 0; } int url_fclose(ByteIOContext *s) { URLContext *h = s->opaque; av_free(s->buffer); memset(s, 0, sizeof(ByteIOContext)); return url_close(h); } URLContext *url_fileno(ByteIOContext *s) { return s->opaque; } #ifdef CONFIG_ENCODERS /* XXX: currently size is limited */ int url_fprintf(ByteIOContext *s, const char *fmt, ...) { va_list ap; char buf[4096]; int ret; va_start(ap, fmt); ret = vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); put_buffer(s, buf, strlen(buf)); return ret; } #endif //CONFIG_ENCODERS /* note: unlike fgets, the EOL character is not returned and a whole line is parsed. return NULL if first char read was EOF */ char *url_fgets(ByteIOContext *s, char *buf, int buf_size) { int c; char *q; c = url_fgetc(s); if (c == EOF) return NULL; q = buf; for(;;) { if (c == EOF || c == '\n') break; if ((q - buf) < buf_size - 1) *q++ = c; c = url_fgetc(s); } if (buf_size > 0) *q = '\0'; return buf; } /* * Return the maximum packet size associated to packetized buffered file * handle. If the file is not packetized (stream like http or file on * disk), then 0 is returned. * * @param h buffered file handle * @return maximum packet size in bytes */ int url_fget_max_packet_size(ByteIOContext *s) { return s->max_packet_size; } #ifdef CONFIG_ENCODERS /* buffer handling */ int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags) { return init_put_byte(s, buf, buf_size, (flags & URL_WRONLY) != 0, NULL, NULL, NULL, NULL); } /* return the written or read size */ int url_close_buf(ByteIOContext *s) { put_flush_packet(s); return s->buf_ptr - s->buffer; } /* output in a dynamic buffer */ typedef struct DynBuffer { int pos, size, allocated_size; uint8_t *buffer; int io_buffer_size; uint8_t io_buffer[1]; } DynBuffer; static void dyn_buf_write(void *opaque, uint8_t *buf, int buf_size) { DynBuffer *d = opaque; int new_size, new_allocated_size; /* reallocate buffer if needed */ new_size = d->pos + buf_size; new_allocated_size = d->allocated_size; while (new_size > new_allocated_size) { if (!new_allocated_size) new_allocated_size = new_size; else new_allocated_size = (new_allocated_size * 3) / 2 + 1; } if (new_allocated_size > d->allocated_size) { d->buffer = av_realloc(d->buffer, new_allocated_size); if(d->buffer == NULL) return ; d->allocated_size = new_allocated_size; } memcpy(d->buffer + d->pos, buf, buf_size); d->pos = new_size; if (d->pos > d->size) d->size = d->pos; } static void dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size) { unsigned char buf1[4]; /* packetized write: output the header */ buf1[0] = (buf_size >> 24); buf1[1] = (buf_size >> 16); buf1[2] = (buf_size >> 8); buf1[3] = (buf_size); dyn_buf_write(opaque, buf1, 4); /* then the data */ dyn_buf_write(opaque, buf, buf_size); } static int dyn_buf_seek(void *opaque, offset_t offset, int whence) { DynBuffer *d = opaque; if (whence == SEEK_CUR) offset += d->pos; else if (whence == SEEK_END) offset += d->size; if (offset < 0 || offset > 0x7fffffffLL) return -1; d->pos = offset; return 0; } static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size) { DynBuffer *d; int io_buffer_size, ret; if (max_packet_size) io_buffer_size = max_packet_size; else io_buffer_size = 1024; d = av_malloc(sizeof(DynBuffer) + io_buffer_size); if (!d) return -1; d->io_buffer_size = io_buffer_size; d->buffer = NULL; d->pos = 0; d->size = 0; d->allocated_size = 0; ret = init_put_byte(s, d->io_buffer, io_buffer_size, 1, d, NULL, max_packet_size ? dyn_packet_buf_write : dyn_buf_write, max_packet_size ? NULL : dyn_buf_seek); if (ret == 0) { s->max_packet_size = max_packet_size; } return ret; } /* * Open a write only memory stream. * * @param s new IO context * @return zero if no error. */ int url_open_dyn_buf(ByteIOContext *s) { return url_open_dyn_buf_internal(s, 0); } /* * Open a write only packetized memory stream with a maximum packet * size of 'max_packet_size'. The stream is stored in a memory buffer * with a big endian 4 byte header giving the packet size in bytes. * * @param s new IO context * @param max_packet_size maximum packet size (must be > 0) * @return zero if no error. */ int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size) { if (max_packet_size <= 0) return -1; return url_open_dyn_buf_internal(s, max_packet_size); } /* * Return the written size and a pointer to the buffer. The buffer * must be freed with av_free(). * @param s IO context * @param pointer to a byte buffer * @return the length of the byte buffer */ int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer) { DynBuffer *d = s->opaque; int size; put_flush_packet(s); *pbuffer = d->buffer; size = d->size; av_free(d); return size; } #endif //CONFIG_ENCODERS xmms-wma-1.0.5/ffmpeg-strip-wma/CREDITS0000644000175000017500000000063110007621445017753 0ustar whistlerwhistlerThis file contains the name of the people who have contributed to ffmpeg. The names are sorted alphabetically. Fabrice Bellard BERO Mario Brito Alex Beregszaszi Tim Ferguson Brian Foley Arpad Gereoffy Philip Gladstone Vladimir Gneushev Falk Hueffner Zdenek Kabelac Robin Kay Nick Kurshev Mike Melanson Michael Niedermayer FranГois Revol Dieter Shirley Juan J. Sierralta Ewald Snel Roberto Togni Lionel Ulmer xmms-wma-1.0.5/ffmpeg-strip-wma/config.h0000644000175000017500000000116310014777230020354 0ustar whistlerwhistler/* Automatically generated by configure - do not modify */ #define ARCH_X86 1 #define TUNECPU generic #undef HAVE_MMX #define __CPU__ 586 #define HAVE_BUILTIN_VECTOR 1 #define HAVE_LOCALTIME_R 1 #define HAVE_LRINTF 1 #undef HAVE_VHOOK #undef CONFIG_ENCODERS #define CONFIG_DECODERS 1 #undef CONFIG_MPEGAUDIO_HP #undef CONFIG_VIDEO4LINUX #undef CONFIG_DV1394 #define CONFIG_HAVE_DLOPEN 1 #define CONFIG_HAVE_DLFCN 1 #undef CONFIG_AUDIO_OSS #undef CONFIG_NETWORK #undef CONFIG_ZLIB #define HAVE_MALLOC_H 1 #define HAVE_MEMALIGN 1 #define SIMPLE_IDCT 1 #undef CONFIG_FFSERVER #define CONFIG_RISKY 1 #define restrict __restrict__ xmms-wma-1.0.5/ffmpeg-strip-wma/parser.c0000644000175000017500000007053110014773363020406 0ustar whistlerwhistler/* * Audio and Video frame extraction * Copyright (c) 2003 Fabrice Bellard. * Copyright (c) 2003 Michael Niedermayer. * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avcodec.h" //#include "mpegvideo.h" //#include "mpegaudio.h" AVCodecParser *av_first_parser = NULL; void av_register_codec_parser(AVCodecParser *parser) { parser->next = av_first_parser; av_first_parser = parser; } AVCodecParserContext *av_parser_init(int codec_id) { AVCodecParserContext *s; AVCodecParser *parser; int ret; for(parser = av_first_parser; parser != NULL; parser = parser->next) { if (parser->codec_ids[0] == codec_id || parser->codec_ids[1] == codec_id || parser->codec_ids[2] == codec_id) goto found; } return NULL; found: s = av_mallocz(sizeof(AVCodecParserContext)); if (!s) return NULL; s->parser = parser; s->priv_data = av_mallocz(parser->priv_data_size); if (!s->priv_data) { av_free(s); return NULL; } if (parser->parser_init) { ret = parser->parser_init(s); if (ret != 0) { av_free(s->priv_data); av_free(s); return NULL; } } return s; } /* NOTE: buf_size == 0 is used to signal EOF so that the last frame can be returned if necessary */ int av_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts) { int index, i, k; uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE]; if (buf_size == 0) { /* padding is always necessary even if EOF, so we add it here */ memset(dummy_buf, 0, sizeof(dummy_buf)); buf = dummy_buf; } else { /* add a new packet descriptor */ k = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1); s->cur_frame_start_index = k; s->cur_frame_offset[k] = s->cur_offset; s->cur_frame_pts[k] = pts; s->cur_frame_dts[k] = dts; /* fill first PTS/DTS */ if (s->cur_offset == 0) { s->last_pts = pts; s->last_dts = dts; } } /* WARNING: the returned index can be negative */ index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size); /* update the file pointer */ if (*poutbuf_size) { /* fill the data for the current frame */ s->frame_offset = s->last_frame_offset; s->pts = s->last_pts; s->dts = s->last_dts; /* offset of the next frame */ s->last_frame_offset = s->cur_offset + index; /* find the packet in which the new frame starts. It is tricky because of MPEG video start codes which can begin in one packet and finish in another packet. In the worst case, an MPEG video start code could be in 4 different packets. */ k = s->cur_frame_start_index; for(i = 0; i < AV_PARSER_PTS_NB; i++) { if (s->last_frame_offset >= s->cur_frame_offset[k]) break; k = (k - 1) & (AV_PARSER_PTS_NB - 1); } s->last_pts = s->cur_frame_pts[k]; s->last_dts = s->cur_frame_dts[k]; } if (index < 0) index = 0; s->cur_offset += index; return index; } void av_parser_close(AVCodecParserContext *s) { if (s->parser->parser_close) s->parser->parser_close(s); av_free(s->priv_data); av_free(s); } #if 0 /*****************************************************/ //#define END_NOT_FOUND (-100) #define PICTURE_START_CODE 0x00000100 #define SEQ_START_CODE 0x000001b3 #define EXT_START_CODE 0x000001b5 #define SLICE_MIN_START_CODE 0x00000101 #define SLICE_MAX_START_CODE 0x000001af typedef struct ParseContext1{ uint8_t *buffer; int index; int last_index; int buffer_size; uint32_t state; ///< contains the last few bytes in MSB order int frame_start_found; int overread; ///< the number of bytes which where irreversibly read from the next frame int overread_index; ///< the index into ParseContext1.buffer of the overreaded bytes /* MPEG2 specific */ int frame_rate; int progressive_sequence; int width, height; /* XXX: suppress that, needed by MPEG4 */ MpegEncContext *enc; int first_picture; } ParseContext1; /** * combines the (truncated) bitstream to a complete frame * @returns -1 if no complete frame could be created */ static int ff_combine_frame1(ParseContext1 *pc, int next, uint8_t **buf, int *buf_size) { #if 0 if(pc->overread){ printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index); printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]); } #endif /* copy overreaded bytes from last frame into buffer */ for(; pc->overread>0; pc->overread--){ pc->buffer[pc->index++]= pc->buffer[pc->overread_index++]; } pc->last_index= pc->index; /* copy into buffer end return */ if(next == END_NOT_FOUND){ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(&pc->buffer[pc->index], *buf, *buf_size); pc->index += *buf_size; return -1; } *buf_size= pc->overread_index= pc->index + next; /* append to buffer */ if(pc->index){ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE ); pc->index = 0; *buf= pc->buffer; } /* store overread bytes */ for(;next < 0; next++){ pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next]; pc->overread++; } #if 0 if(pc->overread){ printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index); printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]); } #endif return 0; } /** * finds the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 */ static int mpeg1_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size) { int i; uint32_t state; state= pc->state; i=0; if(!pc->frame_start_found){ for(i=0; i= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ i++; pc->frame_start_found=1; break; } } } if(pc->frame_start_found){ /* EOF considered as end of frame */ if (buf_size == 0) return 0; for(; i SLICE_MAX_START_CODE){ pc->frame_start_found=0; pc->state=-1; return i-3; } } } } pc->state= state; return END_NOT_FOUND; } static int find_start_code(const uint8_t **pbuf_ptr, const uint8_t *buf_end) { const uint8_t *buf_ptr; unsigned int state=0xFFFFFFFF, v; int val; buf_ptr = *pbuf_ptr; while (buf_ptr < buf_end) { v = *buf_ptr++; if (state == 0x000001) { state = ((state << 8) | v) & 0xffffff; val = state; goto found; } state = ((state << 8) | v) & 0xffffff; } val = -1; found: *pbuf_ptr = buf_ptr; return val; } /* XXX: merge with libavcodec ? */ #define MPEG1_FRAME_RATE_BASE 1001 static const int frame_rate_tab[16] = { 0, 24000, 24024, 25025, 30000, 30030, 50050, 60000, 60060, // Xing's 15fps: (9) 15015, // libmpeg3's "Unofficial economy rates": (10-13) 5005, 10010, 12012, 15015, // random, just to avoid segfault !never encode these 25025, 25025, }; static void mpegvideo_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s->priv_data; const uint8_t *buf_end; int32_t start_code; int frame_rate_index, ext_type, bytes_left; int frame_rate_ext_n, frame_rate_ext_d; int top_field_first, repeat_first_field, progressive_frame; int horiz_size_ext, vert_size_ext; s->repeat_pict = 0; buf_end = buf + buf_size; while (buf < buf_end) { start_code = find_start_code(&buf, buf_end); bytes_left = buf_end - buf; switch(start_code) { case PICTURE_START_CODE: if (bytes_left >= 2) { s->pict_type = (buf[1] >> 3) & 7; } break; case SEQ_START_CODE: if (bytes_left >= 4) { pc->width = avctx->width = (buf[0] << 4) | (buf[1] >> 4); pc->height = avctx->height = ((buf[1] & 0x0f) << 8) | buf[2]; frame_rate_index = buf[3] & 0xf; pc->frame_rate = avctx->frame_rate = frame_rate_tab[frame_rate_index]; avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE; avctx->codec_id = CODEC_ID_MPEG1VIDEO; avctx->sub_id = 1; } break; case EXT_START_CODE: if (bytes_left >= 1) { ext_type = (buf[0] >> 4); switch(ext_type) { case 0x1: /* sequence extension */ if (bytes_left >= 6) { horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7); vert_size_ext = (buf[2] >> 5) & 3; frame_rate_ext_n = (buf[5] >> 5) & 3; frame_rate_ext_d = (buf[5] & 0x1f); pc->progressive_sequence = buf[1] & (1 << 3); avctx->width = pc->width | (horiz_size_ext << 12); avctx->height = pc->height | (vert_size_ext << 12); avctx->frame_rate = pc->frame_rate * (frame_rate_ext_n + 1); avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d + 1); avctx->codec_id = CODEC_ID_MPEG2VIDEO; avctx->sub_id = 2; /* forces MPEG2 */ } break; case 0x8: /* picture coding extension */ if (bytes_left >= 5) { top_field_first = buf[3] & (1 << 7); repeat_first_field = buf[3] & (1 << 1); progressive_frame = buf[4] & (1 << 7); /* check if we must repeat the frame */ if (repeat_first_field) { if (pc->progressive_sequence) { if (top_field_first) s->repeat_pict = 4; else s->repeat_pict = 2; } else if (progressive_frame) { s->repeat_pict = 1; } } } break; } } break; case -1: goto the_end; default: /* we stop parsing when we encounter a slice. It ensures that this function takes a negligible amount of time */ if (start_code >= SLICE_MIN_START_CODE && start_code <= SLICE_MAX_START_CODE) goto the_end; break; } } the_end: ; } static int mpegvideo_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s->priv_data; int next; next= mpeg1_find_frame_end(pc, buf, buf_size); if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } /* we have a full frame : we just parse the first few MPEG headers to have the full timing information. The time take by this function should be negligible for uncorrupted streams */ mpegvideo_extract_headers(s, avctx, buf, buf_size); #if 0 printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n", s->pict_type, (double)avctx->frame_rate / avctx->frame_rate_base, s->repeat_pict); #endif *poutbuf = (uint8_t *)buf; *poutbuf_size = buf_size; return next; } static void mpegvideo_parse_close(AVCodecParserContext *s) { ParseContext1 *pc = s->priv_data; av_free(pc->buffer); av_free(pc->enc); } /*************************/ /** * finds the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 */ static int mpeg4_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size) { int vop_found, i; uint32_t state; vop_found= pc->frame_start_found; state= pc->state; i=0; if(!vop_found){ for(i=0; iframe_start_found=0; pc->state=-1; return i-3; } } } pc->frame_start_found= vop_found; pc->state= state; return END_NOT_FOUND; } /* used by parser */ /* XXX: make it use less memory */ #if 0 static int av_mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s1->priv_data; MpegEncContext *s = pc->enc; GetBitContext gb1, *gb = &gb1; int ret; s->avctx = avctx; s->current_picture_ptr = &s->current_picture; if (avctx->extradata_size && pc->first_picture){ init_get_bits(gb, avctx->extradata, avctx->extradata_size*8); ret = ff_mpeg4_decode_picture_header(s, gb); } init_get_bits(gb, buf, 8 * buf_size); ret = ff_mpeg4_decode_picture_header(s, gb); if (s->width) { avctx->width = s->width; avctx->height = s->height; } pc->first_picture = 0; return ret; } #endif int mpeg4video_parse_init(AVCodecParserContext *s) { ParseContext1 *pc = s->priv_data; pc->enc = av_mallocz(sizeof(MpegEncContext)); if (!pc->enc) return -1; pc->first_picture = 1; return 0; } static int mpeg4video_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s->priv_data; int next; next= mpeg4_find_frame_end(pc, buf, buf_size); if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } av_mpeg4_decode_header(s, avctx, buf, buf_size); *poutbuf = (uint8_t *)buf; *poutbuf_size = buf_size; return next; } /*************************/ static int h263_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size) { int vop_found, i; uint32_t state; vop_found= pc->frame_start_found; state= pc->state; i=0; if(!vop_found){ for(i=0; i>(32-22) == 0x20){ i++; vop_found=1; break; } } } if(vop_found){ for(; i>(32-22) == 0x20){ pc->frame_start_found=0; pc->state=-1; return i-3; } } } pc->frame_start_found= vop_found; pc->state= state; return END_NOT_FOUND; } static int h263_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s->priv_data; int next; next= h263_find_frame_end(pc, buf, buf_size); if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } *poutbuf = (uint8_t *)buf; *poutbuf_size = buf_size; return next; } /*************************/ /** * finds the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 */ static int h264_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_size) { int i; uint32_t state; //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); // mb_addr= pc->mb_addr - 1; state= pc->state; //FIXME this will fail with slices for(i=0; iframe_start_found){ pc->state=-1; pc->frame_start_found= 0; return i-3; } pc->frame_start_found= 1; } } pc->state= state; return END_NOT_FOUND; } static int h264_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s->priv_data; int next; next= h264_find_frame_end(pc, buf, buf_size); if (ff_combine_frame1(pc, next, (uint8_t **)&buf, &buf_size) < 0) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } *poutbuf = (uint8_t *)buf; *poutbuf_size = buf_size; return next; } /*************************/ typedef struct MpegAudioParseContext { uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ uint8_t *inbuf_ptr; int frame_size; int free_format_frame_size; int free_format_next_header; } MpegAudioParseContext; #define MPA_HEADER_SIZE 4 /* header + layer + bitrate + freq + lsf/mpeg25 */ #define SAME_HEADER_MASK \ (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19)) static int mpegaudio_parse_init(AVCodecParserContext *s1) { MpegAudioParseContext *s = s1->priv_data; s->inbuf_ptr = s->inbuf; return 0; } static int mpegaudio_parse(AVCodecParserContext *s1, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { MpegAudioParseContext *s = s1->priv_data; int len, ret; uint32_t header; const uint8_t *buf_ptr; *poutbuf = NULL; *poutbuf_size = 0; buf_ptr = buf; while (buf_size > 0) { len = s->inbuf_ptr - s->inbuf; if (s->frame_size == 0) { /* special case for next header for first frame in free format case (XXX: find a simpler method) */ if (s->free_format_next_header != 0) { s->inbuf[0] = s->free_format_next_header >> 24; s->inbuf[1] = s->free_format_next_header >> 16; s->inbuf[2] = s->free_format_next_header >> 8; s->inbuf[3] = s->free_format_next_header; s->inbuf_ptr = s->inbuf + 4; s->free_format_next_header = 0; goto got_header; } /* no header seen : find one. We need at least MPA_HEADER_SIZE bytes to parse it */ len = MPA_HEADER_SIZE - len; if (len > buf_size) len = buf_size; if (len > 0) { memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; buf_size -= len; s->inbuf_ptr += len; } if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { got_header: header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | (s->inbuf[2] << 8) | s->inbuf[3]; ret = mpa_decode_header(avctx, header); if (ret < 0) { /* no sync found : move by one byte (inefficient, but simple!) */ memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); s->inbuf_ptr--; dprintf("skip %x\n", header); /* reset free format frame size to give a chance to get a new bitrate */ s->free_format_frame_size = 0; } else { s->frame_size = ret; #if 0 /* free format: prepare to compute frame size */ if (decode_header(s, header) == 1) { s->frame_size = -1; } #endif } } } else #if 0 if (s->frame_size == -1) { /* free format : find next sync to compute frame size */ len = MPA_MAX_CODED_FRAME_SIZE - len; if (len > buf_size) len = buf_size; if (len == 0) { /* frame too long: resync */ s->frame_size = 0; memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); s->inbuf_ptr--; } else { uint8_t *p, *pend; uint32_t header1; int padding; memcpy(s->inbuf_ptr, buf_ptr, len); /* check for header */ p = s->inbuf_ptr - 3; pend = s->inbuf_ptr + len - 4; while (p <= pend) { header = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | (s->inbuf[2] << 8) | s->inbuf[3]; /* check with high probability that we have a valid header */ if ((header & SAME_HEADER_MASK) == (header1 & SAME_HEADER_MASK)) { /* header found: update pointers */ len = (p + 4) - s->inbuf_ptr; buf_ptr += len; buf_size -= len; s->inbuf_ptr = p; /* compute frame size */ s->free_format_next_header = header; s->free_format_frame_size = s->inbuf_ptr - s->inbuf; padding = (header1 >> 9) & 1; if (s->layer == 1) s->free_format_frame_size -= padding * 4; else s->free_format_frame_size -= padding; dprintf("free frame size=%d padding=%d\n", s->free_format_frame_size, padding); decode_header(s, header1); goto next_data; } p++; } /* not found: simply increase pointers */ buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; } } else #endif if (len < s->frame_size) { if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) s->frame_size = MPA_MAX_CODED_FRAME_SIZE; len = s->frame_size - len; if (len > buf_size) len = buf_size; memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; } // next_data: if (s->frame_size > 0 && (s->inbuf_ptr - s->inbuf) >= s->frame_size) { *poutbuf = s->inbuf; *poutbuf_size = s->inbuf_ptr - s->inbuf; s->inbuf_ptr = s->inbuf; s->frame_size = 0; break; } } return buf_ptr - buf; } #ifdef CONFIG_AC3 extern int a52_syncinfo (const uint8_t * buf, int * flags, int * sample_rate, int * bit_rate); typedef struct AC3ParseContext { uint8_t inbuf[4096]; /* input buffer */ uint8_t *inbuf_ptr; int frame_size; int flags; } AC3ParseContext; #define AC3_HEADER_SIZE 7 #define A52_LFE 16 static int ac3_parse_init(AVCodecParserContext *s1) { AC3ParseContext *s = s1->priv_data; s->inbuf_ptr = s->inbuf; return 0; } static int ac3_parse(AVCodecParserContext *s1, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { AC3ParseContext *s = s1->priv_data; const uint8_t *buf_ptr; int len, sample_rate, bit_rate; static const int ac3_channels[8] = { 2, 1, 2, 3, 3, 4, 4, 5 }; *poutbuf = NULL; *poutbuf_size = 0; buf_ptr = buf; while (buf_size > 0) { len = s->inbuf_ptr - s->inbuf; if (s->frame_size == 0) { /* no header seen : find one. We need at least 7 bytes to parse it */ len = AC3_HEADER_SIZE - len; if (len > buf_size) len = buf_size; memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; if ((s->inbuf_ptr - s->inbuf) == AC3_HEADER_SIZE) { len = a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate); if (len == 0) { /* no sync found : move by one byte (inefficient, but simple!) */ memmove(s->inbuf, s->inbuf + 1, AC3_HEADER_SIZE - 1); s->inbuf_ptr--; } else { s->frame_size = len; /* update codec info */ avctx->sample_rate = sample_rate; avctx->channels = ac3_channels[s->flags & 7]; if (s->flags & A52_LFE) avctx->channels++; avctx->bit_rate = bit_rate; avctx->frame_size = 6 * 256; } } } else if (len < s->frame_size) { len = s->frame_size - len; if (len > buf_size) len = buf_size; memcpy(s->inbuf_ptr, buf_ptr, len); buf_ptr += len; s->inbuf_ptr += len; buf_size -= len; } else { *poutbuf = s->inbuf; *poutbuf_size = s->frame_size; s->inbuf_ptr = s->inbuf; s->frame_size = 0; break; } } return buf_ptr - buf; } #endif AVCodecParser mpegvideo_parser = { { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, sizeof(ParseContext1), NULL, mpegvideo_parse, mpegvideo_parse_close, }; AVCodecParser mpeg4video_parser = { { CODEC_ID_MPEG4 }, sizeof(ParseContext1), mpeg4video_parse_init, mpeg4video_parse, mpegvideo_parse_close, }; AVCodecParser h263_parser = { { CODEC_ID_H263 }, sizeof(ParseContext1), NULL, h263_parse, mpegvideo_parse_close, }; AVCodecParser h264_parser = { { CODEC_ID_H264 }, sizeof(ParseContext1), NULL, h264_parse, mpegvideo_parse_close, }; AVCodecParser mpegaudio_parser = { { CODEC_ID_MP2, CODEC_ID_MP3 }, sizeof(MpegAudioParseContext), mpegaudio_parse_init, mpegaudio_parse, NULL, }; #ifdef CONFIG_AC3 AVCodecParser ac3_parser = { { CODEC_ID_AC3 }, sizeof(AC3ParseContext), ac3_parse_init, ac3_parse, NULL, }; #endif #endif xmms-wma-1.0.5/ffmpeg-strip-wma/avcodec.h0000644000175000017500000017033210014745224020516 0ustar whistlerwhistler#ifndef AVCODEC_H #define AVCODEC_H /** * @file avcodec.h * external api header. */ #ifdef __cplusplus extern "C" { #endif #include "common.h" //#include "rational.h" #include /* size_t */ #define FFMPEG_VERSION_INT 0x000408 #define FFMPEG_VERSION "0.4.8" #define LIBAVCODEC_BUILD 4701 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION FFMPEG_VERSION #define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_TOSTRING(s) #s #define LIBAVCODEC_IDENT "FFmpeg" LIBAVCODEC_VERSION "b" AV_STRINGIFY(LIBAVCODEC_BUILD) enum CodecID { CODEC_ID_NONE, CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */ CODEC_ID_MPEG2VIDEO_XVMC, CODEC_ID_H263, CODEC_ID_RV10, CODEC_ID_RV20, CODEC_ID_MP2, CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */ CODEC_ID_VORBIS, CODEC_ID_AC3, CODEC_ID_MJPEG, CODEC_ID_MJPEGB, CODEC_ID_LJPEG, CODEC_ID_SP5X, CODEC_ID_MPEG4, CODEC_ID_RAWVIDEO, CODEC_ID_MSMPEG4V1, CODEC_ID_MSMPEG4V2, CODEC_ID_MSMPEG4V3, CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_H263P, CODEC_ID_H263I, CODEC_ID_FLV1, CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_HUFFYUV, CODEC_ID_CYUV, CODEC_ID_H264, CODEC_ID_INDEO3, CODEC_ID_VP3, CODEC_ID_THEORA, CODEC_ID_AAC, CODEC_ID_MPEG4AAC, CODEC_ID_ASV1, CODEC_ID_ASV2, CODEC_ID_FFV1, CODEC_ID_4XM, CODEC_ID_VCR1, CODEC_ID_CLJR, CODEC_ID_MDEC, CODEC_ID_ROQ, CODEC_ID_INTERPLAY_VIDEO, CODEC_ID_XAN_WC3, CODEC_ID_XAN_WC4, CODEC_ID_RPZA, CODEC_ID_CINEPAK, CODEC_ID_WS_VQA, CODEC_ID_MSRLE, CODEC_ID_MSVIDEO1, CODEC_ID_IDCIN, CODEC_ID_8BPS, CODEC_ID_SMC, CODEC_ID_FLIC, CODEC_ID_TRUEMOTION1, CODEC_ID_VMDVIDEO, CODEC_ID_VMDAUDIO, CODEC_ID_MSZH, CODEC_ID_ZLIB, CODEC_ID_QTRLE, /* various pcm "codecs" */ CODEC_ID_PCM_S16LE, CODEC_ID_PCM_S16BE, CODEC_ID_PCM_U16LE, CODEC_ID_PCM_U16BE, CODEC_ID_PCM_S8, CODEC_ID_PCM_U8, CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, /* various adpcm codecs */ CODEC_ID_ADPCM_IMA_QT, CODEC_ID_ADPCM_IMA_WAV, CODEC_ID_ADPCM_IMA_DK3, CODEC_ID_ADPCM_IMA_DK4, CODEC_ID_ADPCM_IMA_WS, CODEC_ID_ADPCM_IMA_SMJPEG, CODEC_ID_ADPCM_MS, CODEC_ID_ADPCM_4XM, CODEC_ID_ADPCM_XA, CODEC_ID_ADPCM_ADX, CODEC_ID_ADPCM_EA, /* AMR */ CODEC_ID_AMR_NB, CODEC_ID_AMR_WB, /* RealAudio codecs*/ CODEC_ID_RA_144, CODEC_ID_RA_288, /* various DPCM codecs */ CODEC_ID_ROQ_DPCM, CODEC_ID_INTERPLAY_DPCM, CODEC_ID_XAN_DPCM, CODEC_ID_MPEG2TS, /* _FAKE_ codec to indicate a raw MPEG2 transport stream (only used by libavformat) */ }; /* CODEC_ID_MP3LAME is absolete */ #define CODEC_ID_MP3LAME CODEC_ID_MP3 enum CodecType { CODEC_TYPE_UNKNOWN = -1, CODEC_TYPE_VIDEO, CODEC_TYPE_AUDIO, CODEC_TYPE_DATA, }; /** * Pixel format. Notes: * * PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA * color is put together as: * (A << 24) | (R << 16) | (G << 8) | B * This is stored as BGRA on little endian CPU architectures and ARGB on * big endian CPUs. * * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized * image data is stored in AVFrame.data[0]. The palette is transported in * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is * also endian-specific). Note also that the individual RGB palette * components stored in AVFrame.data[1] should be in the range 0..255. * This is important as many custom PAL8 video codecs that were designed * to run on the IBM VGA graphics adapter use 6-bit palette components. */ enum PixelFormat { PIX_FMT_YUV420P, ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples) PIX_FMT_YUV422, PIX_FMT_RGB24, ///< Packed pixel, 3 bytes per pixel, RGBRGB... PIX_FMT_BGR24, ///< Packed pixel, 3 bytes per pixel, BGRBGR... PIX_FMT_YUV422P, ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples) PIX_FMT_YUV444P, ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples) PIX_FMT_RGBA32, ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness PIX_FMT_YUV410P, ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples) PIX_FMT_YUV411P, ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples) PIX_FMT_RGB565, ///< always stored in cpu endianness PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1 PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, ///< 0 is white PIX_FMT_MONOBLACK, ///< 0 is black PIX_FMT_PAL8, ///< 8 bit with RGBA palette PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0 full scale (jpeg) PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2 full scale (jpeg) PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4 full scale (jpeg) PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h) PIX_FMT_XVMC_MPEG2_IDCT, PIX_FMT_NB, }; /* currently unused, may be used if 24/32 bits samples ever supported */ enum SampleFormat { SAMPLE_FMT_S16 = 0, ///< signed 16 bits }; /* in bytes */ #define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072 /** * Required number of additionally allocated bytes at the end of the input bitstream for decoding. * this is mainly needed because some optimized bitstream readers read * 32 or 64 bit at once and could read over the end
* Note, if the first 23 bits of the additional bytes are not 0 then damaged * MPEG bitstreams could cause overread and segfault */ #define FF_INPUT_BUFFER_PADDING_SIZE 8 /* motion estimation type, EPZS by default */ enum Motion_Est_ID { ME_ZERO = 1, ME_FULL, ME_LOG, ME_PHODS, ME_EPZS, ME_X1 }; typedef struct RcOverride{ int start_frame; int end_frame; int qscale; // if this is 0 then quality_factor will be used instead float quality_factor; } RcOverride; /* only for ME compatiblity with old apps */ extern int motion_estimation_method; #define FF_MAX_B_FRAMES 8 /* encoding support these flags can be passed in AVCodecContext.flags before initing Note: note not everything is supported yet */ #define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / Advanced prediction for H263 #define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC #define CODEC_FLAG_GMC 0x0020 ///< use GMC #define CODEC_FLAG_MV0 0x0040 ///< always try a MB with MV=<0,0> #define CODEC_FLAG_PART 0x0080 ///< use data partitioning /* parent program gurantees that the input for b-frame containing streams is not written to for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */ #define CODEC_FLAG_INPUT_PRESERVED 0x0100 #define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode #define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode #define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg) #define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale #define CODEC_FLAG_EMU_EDGE 0x4000///< dont draw edges #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding #define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead of only at frame boundaries */ #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay #define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan #define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe #define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct) /* Fx : Flag for h263+ extra options */ #define CODEC_FLAG_H263P_AIC 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction (remove this) #define CODEC_FLAG_AC_PRED 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction #define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector #define CODEC_FLAG_CBP_RD 0x04000000 ///< use rate distortion optimization for cbp #define CODEC_FLAG_QP_RD 0x08000000 ///< use rate distortion optimization for qp selectioon #define CODEC_FLAG_H263P_AIV 0x00000008 ///< H263 Alternative inter vlc #define CODEC_FLAG_OBMC 0x00000001 ///< OBMC #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter #define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000 #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation #define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< will reserve space for SVCD scan offset user data #define CODEC_FLAG_CLOSED_GOP 0x80000000 /* Unsupported options : * Syntax Arithmetic coding (SAC) * Reference Picture Selection * Independant Segment Decoding */ /* /Fx */ /* codec capabilities */ #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< decoder can use draw_horiz_band callback /** * Codec uses get_buffer() for allocating buffers. * direct rendering method 1 */ #define CODEC_CAP_DR1 0x0002 /* if 'parse_only' field is true, then avcodec_parse_frame() can be used */ #define CODEC_CAP_PARSE_ONLY 0x0004 #define CODEC_CAP_TRUNCATED 0x0008 //the following defines might change, so dont expect compatibility if u use them #define MB_TYPE_INTRA4x4 0x0001 #define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific #define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific #define MB_TYPE_16x16 0x0008 #define MB_TYPE_16x8 0x0010 #define MB_TYPE_8x16 0x0020 #define MB_TYPE_8x8 0x0040 #define MB_TYPE_INTERLACED 0x0080 #define MB_TYPE_DIRECT2 0x0100 //FIXME #define MB_TYPE_ACPRED 0x0200 #define MB_TYPE_GMC 0x0400 #define MB_TYPE_SKIP 0x0800 #define MB_TYPE_P0L0 0x1000 #define MB_TYPE_P1L0 0x2000 #define MB_TYPE_P0L1 0x4000 #define MB_TYPE_P1L1 0x8000 #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0) #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1) #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1) #define MB_TYPE_QUANT 0x00010000 #define MB_TYPE_CBP 0x00020000 //Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...) /** * Pan Scan area. * this specifies the area which should be displayed. Note there may be multiple such areas for one frame */ typedef struct AVPanScan{ /** * id. * - encoding: set by user. * - decoding: set by lavc */ int id; /** * width and height in 1/16 pel * - encoding: set by user. * - decoding: set by lavc */ int width; int height; /** * position of the top left corner in 1/16 pel for up to 3 fields/frames. * - encoding: set by user. * - decoding: set by lavc */ int16_t position[3][2]; }AVPanScan; #define FF_COMMON_FRAME \ /**\ * pointer to the picture planes.\ * this might be different from the first allocated byte\ * - encoding: \ * - decoding: \ */\ uint8_t *data[4];\ int linesize[4];\ /**\ * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\ * this isnt used by lavc unless the default get/release_buffer() is used\ * - encoding: \ * - decoding: \ */\ uint8_t *base[4];\ /**\ * 1 -> keyframe, 0-> not\ * - encoding: set by lavc\ * - decoding: set by lavc\ */\ int key_frame;\ \ /**\ * picture type of the frame, see ?_TYPE below.\ * - encoding: set by lavc for coded_picture (and set by user for input)\ * - decoding: set by lavc\ */\ int pict_type;\ \ /**\ * presentation timestamp in micro seconds (time when frame should be shown to user)\ * if 0 then the frame_rate will be used as reference\ * - encoding: MUST be set by user\ * - decoding: set by lavc\ */\ int64_t pts;\ \ /**\ * picture number in bitstream order.\ * - encoding: set by\ * - decoding: set by lavc\ */\ int coded_picture_number;\ /**\ * picture number in display order.\ * - encoding: set by\ * - decoding: set by lavc\ */\ int display_picture_number;\ \ /**\ * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \ * - encoding: set by lavc for coded_picture (and set by user for input)\ * - decoding: set by lavc\ */\ int quality; \ \ /**\ * buffer age (1->was last buffer and dint change, 2->..., ...).\ * set to INT_MAX if the buffer has not been used yet \ * - encoding: unused\ * - decoding: MUST be set by get_buffer()\ */\ int age;\ \ /**\ * is this picture used as reference\ * - encoding: unused\ * - decoding: set by lavc (before get_buffer() call))\ */\ int reference;\ \ /**\ * QP table\ * - encoding: unused\ * - decoding: set by lavc\ */\ int8_t *qscale_table;\ /**\ * QP store stride\ * - encoding: unused\ * - decoding: set by lavc\ */\ int qstride;\ \ /**\ * mbskip_table[mb]>=1 if MB didnt change\ * stride= mb_width = (width+15)>>4\ * - encoding: unused\ * - decoding: set by lavc\ */\ uint8_t *mbskip_table;\ \ /**\ * Motion vector table\ * - encoding: unused\ * - decoding: set by lavc\ */\ int16_t (*motion_val[2])[2];\ \ /**\ * Macroblock type table\ * mb_type_base + mb_width + 2\ * - encoding: unused\ * - decoding: set by lavc\ */\ uint32_t *mb_type;\ \ /**\ * Macroblock size: (0->16x16, 1->8x8, 2-> 4x4, 3-> 2x2)\ * - encoding: unused\ * - decoding: set by lavc\ */\ uint8_t motion_subsample_log2;\ \ /**\ * for some private data of the user\ * - encoding: unused\ * - decoding: set by user\ */\ void *opaque;\ \ /**\ * error\ * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\ * - decoding: unused\ */\ uint64_t error[4];\ \ /**\ * type of the buffer (to keep track of who has to dealloc data[*])\ * - encoding: set by the one who allocs it\ * - decoding: set by the one who allocs it\ * Note: user allocated (direct rendering) & internal buffers can not coexist currently\ */\ int type;\ \ /**\ * when decoding, this signal how much the picture must be delayed.\ * extra_delay = repeat_pict / (2*fps)\ * - encoding: unused\ * - decoding: set by lavc\ */\ int repeat_pict;\ \ /**\ * \ */\ int qscale_type;\ \ /**\ * The content of the picture is interlaced.\ * - encoding: set by user\ * - decoding: set by lavc (default 0)\ */\ int interlaced_frame;\ \ /**\ * if the content is interlaced, is top field displayed first.\ * - encoding: set by user\ * - decoding: set by lavc\ */\ int top_field_first;\ \ /**\ * Pan scan.\ * - encoding: set by user\ * - decoding: set by lavc\ */\ AVPanScan *pan_scan;\ \ /**\ * tell user application that palette has changed from previous frame.\ * - encoding: ??? (no palette-enabled encoder yet)\ * - decoding: set by lavc (default 0)\ */\ int palette_has_changed;\ \ /**\ * Codec suggestion on buffer type if != 0\ * - encoding: unused\ * - decoding: set by lavc (before get_buffer() call))\ */\ int buffer_hints;\ #define FF_QSCALE_TYPE_MPEG1 0 #define FF_QSCALE_TYPE_MPEG2 1 #define FF_BUFFER_TYPE_INTERNAL 1 #define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user) #define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base) #define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, dont dealloc anything #define FF_I_TYPE 1 // Intra #define FF_P_TYPE 2 // Predicted #define FF_B_TYPE 3 // Bi-dir predicted #define FF_S_TYPE 4 // S(GMC)-VOP MPEG4 #define FF_SI_TYPE 5 #define FF_SP_TYPE 6 #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore) #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update) /** * Audio Video Frame. */ typedef struct AVFrame { FF_COMMON_FRAME } AVFrame; #define DEFAULT_FRAME_RATE_BASE 1001000 /** * main external api structure. */ typedef struct AVCodecContext { /** * the average bitrate. * - encoding: set by user. unused for constant quantizer encoding * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream */ int bit_rate; /** * number of bits the bitstream is allowed to diverge from the reference. * the reference can be CBR (for CBR pass1) or VBR (for pass2) * - encoding: set by user. unused for constant quantizer encoding * - decoding: unused */ int bit_rate_tolerance; /** * CODEC_FLAG_*. * - encoding: set by user. * - decoding: set by user. */ int flags; /** * some codecs needs additionnal format info. It is stored here * - encoding: set by user. * - decoding: set by lavc. (FIXME is this ok?) */ int sub_id; /** * motion estimation algorithm used for video coding. * - encoding: MUST be set by user. * - decoding: unused */ int me_method; /** * some codecs need / can use extra-data like huffman tables. * mjpeg: huffman tables * rv10: additional flags * mpeg4: global headers (they can be in the bitstream or here) * - encoding: set/allocated/freed by lavc. * - decoding: set/allocated/freed by user. */ void *extradata; int extradata_size; /* video only */ /** * frames per sec multiplied by frame_rate_base. * for variable fps this is the precission, so if the timestamps * can be specified in msec precssion then this is 1000*frame_rate_base * - encoding: MUST be set by user * - decoding: set by lavc. 0 or the frame_rate if available */ int frame_rate; /** * width / height. * - encoding: MUST be set by user. * - decoding: set by user if known, codec should override / dynamically change if needed */ int width, height; #define FF_ASPECT_SQUARE 1 #define FF_ASPECT_4_3_625 2 #define FF_ASPECT_4_3_525 3 #define FF_ASPECT_16_9_625 4 #define FF_ASPECT_16_9_525 5 #define FF_ASPECT_EXTENDED 15 /** * the number of pictures in a group of pitures, or 0 for intra_only. * - encoding: set by user. * - decoding: unused */ int gop_size; /** * pixel format, see PIX_FMT_xxx. * - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt * conversion is in order. This only works for * codecs with one supported pix_fmt, we should * do something for a generic case as well. * - decoding: set by lavc. */ enum PixelFormat pix_fmt; /** * Frame rate emulation. If not zero lower layer (i.e. format handler) * has to read frames at native frame rate. * - encoding: set by user. * - decoding: unused. */ int rate_emu; /** * if non NULL, 'draw_horiz_band' is called by the libavcodec * decoder to draw an horizontal band. It improve cache usage. Not * all codecs can do that. You must check the codec capabilities * before * - encoding: unused * - decoding: set by user. * @param height the height of the slice * @param y the y position of the slice * @param type 1->top field, 2->bottom field, 3->frame * @param offset offset into the AVFrame.data from which the slice should be read */ void (*draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[4], int y, int type, int height); /* audio only */ int sample_rate; ///< samples per sec int channels; int sample_fmt; ///< sample format, currenly unused /* the following data should not be initialized */ int frame_size; ///< in samples, initialized when calling 'init' int frame_number; ///< audio or video frame number int real_pict_num; ///< returns the real picture number of previous encoded frame /** * number of frames the decoded output will be delayed relative to * the encoded input. * - encoding: set by lavc. * - decoding: unused */ int delay; /* - encoding parameters */ float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0) float qblur; ///< amount of qscale smoothing over time (0.0-1.0) /** * minimum quantizer. * - encoding: set by user. * - decoding: unused */ int qmin; /** * maximum quantizer. * - encoding: set by user. * - decoding: unused */ int qmax; /** * maximum quantizer difference etween frames. * - encoding: set by user. * - decoding: unused */ int max_qdiff; /** * maximum number of b frames between non b frames. * note: the output will be delayed by max_b_frames+1 relative to the input * - encoding: set by user. * - decoding: unused */ int max_b_frames; /** * qscale factor between ip and b frames. * - encoding: set by user. * - decoding: unused */ float b_quant_factor; /** obsolete FIXME remove */ int rc_strategy; int b_frame_strategy; /** * hurry up amount. * - encoding: unused * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header */ int hurry_up; struct AVCodec *codec; void *priv_data; /* unused, FIXME remove*/ int rtp_mode; int rtp_payload_size; /* The size of the RTP payload, the coder will */ /* do it's best to deliver a chunk with size */ /* below rtp_payload_size, the chunk will start */ /* with a start code on some codecs like H.263 */ /* This doesn't take account of any particular */ /* headers inside the transmited RTP payload */ /* The RTP callcack: This function is called */ /* every time the encoder as a packet to send */ /* Depends on the encoder if the data starts */ /* with a Start Code (it should) H.263 does */ void (*rtp_callback)(void *data, int size, int packet_number); /* statistics, used for 2-pass encoding */ int mv_bits; int header_bits; int i_tex_bits; int p_tex_bits; int i_count; int p_count; int skip_count; int misc_bits; /** * number of bits used for the previously encoded frame. * - encoding: set by lavc * - decoding: unused */ int frame_bits; /** * private data of the user, can be used to carry app specific stuff. * - encoding: set by user * - decoding: set by user */ void *opaque; char codec_name[32]; enum CodecType codec_type; /* see CODEC_TYPE_xxx */ enum CodecID codec_id; /* see CODEC_ID_xxx */ /** * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). * this is used to workaround some encoder bugs * - encoding: set by user, if not then the default based on codec_id will be used * - decoding: set by user, will be converted to upper case by lavc during init */ unsigned int codec_tag; /** * workaround bugs in encoders which sometimes cannot be detected automatically. * - encoding: unused * - decoding: set by user */ int workaround_bugs; #define FF_BUG_AUTODETECT 1 ///< autodetection #define FF_BUG_OLD_MSMPEG4 2 #define FF_BUG_XVID_ILACE 4 #define FF_BUG_UMP4 8 #define FF_BUG_NO_PADDING 16 #define FF_BUG_AC_VLC 0 ///< will be removed, libavcodec can now handle these non compliant files by default #define FF_BUG_QPEL_CHROMA 64 #define FF_BUG_STD_QPEL 128 #define FF_BUG_QPEL_CHROMA2 256 #define FF_BUG_DIRECT_BLOCKSIZE 512 #define FF_BUG_EDGE 1024 //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100% /** * luma single coeff elimination threshold. * - encoding: set by user * - decoding: unused */ int luma_elim_threshold; /** * chroma single coeff elimination threshold. * - encoding: set by user * - decoding: unused */ int chroma_elim_threshold; /** * strictly follow the std (MPEG4, ...). * - encoding: set by user * - decoding: unused */ int strict_std_compliance; /** * qscale offset between ip and b frames. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset) * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset) * - encoding: set by user. * - decoding: unused */ float b_quant_offset; /** * error resilience higher values will detect more errors but may missdetect * some more or less valid parts as errors. * - encoding: unused * - decoding: set by user */ int error_resilience; #define FF_ER_CAREFULL 1 #define FF_ER_COMPLIANT 2 #define FF_ER_AGGRESSIVE 3 #define FF_ER_VERY_AGGRESSIVE 4 /** * called at the beginning of each frame to get a buffer for it. * if pic.reference is set then the frame will be read later by lavc * width and height should be rounded up to the next multiple of 16 * - encoding: unused * - decoding: set by lavc, user can override */ int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic); /** * called to release buffers which where allocated with get_buffer. * a released buffer can be reused in get_buffer() * pic.data[*] must be set to NULL * - encoding: unused * - decoding: set by lavc, user can override */ void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic); /** * is 1 if the decoded stream contains b frames, 0 otherwise. * - encoding: unused * - decoding: set by lavc */ int has_b_frames; int block_align; ///< used by some WAV based audio codecs int parse_only; /* - decoding only: if true, only parsing is done (function avcodec_parse_frame()). The frame data is returned. Only MPEG codecs support this now. */ /** * 0-> h263 quant 1-> mpeg quant. * - encoding: set by user. * - decoding: unused */ int mpeg_quant; /** * pass1 encoding statistics output buffer. * - encoding: set by lavc * - decoding: unused */ char *stats_out; /** * pass2 encoding statistics input buffer. * concatenated stuff from stats_out of pass1 should be placed here * - encoding: allocated/set/freed by user * - decoding: unused */ char *stats_in; /** * ratecontrol qmin qmax limiting method. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax * - encoding: set by user. * - decoding: unused */ float rc_qsquish; float rc_qmod_amp; int rc_qmod_freq; /** * ratecontrol override, see RcOverride. * - encoding: allocated/set/freed by user. * - decoding: unused */ RcOverride *rc_override; int rc_override_count; /** * rate control equation. * - encoding: set by user * - decoding: unused */ char *rc_eq; /** * maximum bitrate. * - encoding: set by user. * - decoding: unused */ int rc_max_rate; /** * minimum bitrate. * - encoding: set by user. * - decoding: unused */ int rc_min_rate; /** * decoder bitstream buffer size. * - encoding: set by user. * - decoding: unused */ int rc_buffer_size; float rc_buffer_aggressivity; /** * qscale factor between p and i frames. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset) * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset) * - encoding: set by user. * - decoding: unused */ float i_quant_factor; /** * qscale offset between p and i frames. * - encoding: set by user. * - decoding: unused */ float i_quant_offset; /** * initial complexity for pass1 ratecontrol. * - encoding: set by user. * - decoding: unused */ float rc_initial_cplx; /** * dct algorithm, see FF_DCT_* below. * - encoding: set by user * - decoding: unused */ int dct_algo; #define FF_DCT_AUTO 0 #define FF_DCT_FASTINT 1 #define FF_DCT_INT 2 #define FF_DCT_MMX 3 #define FF_DCT_MLIB 4 #define FF_DCT_ALTIVEC 5 #define FF_DCT_FAAN 6 /** * luminance masking (0-> disabled). * - encoding: set by user * - decoding: unused */ float lumi_masking; /** * temporary complexity masking (0-> disabled). * - encoding: set by user * - decoding: unused */ float temporal_cplx_masking; /** * spatial complexity masking (0-> disabled). * - encoding: set by user * - decoding: unused */ float spatial_cplx_masking; /** * p block masking (0-> disabled). * - encoding: set by user * - decoding: unused */ float p_masking; /** * darkness masking (0-> disabled). * - encoding: set by user * - decoding: unused */ float dark_masking; /* for binary compatibility */ int unused; /** * idct algorithm, see FF_IDCT_* below. * - encoding: set by user * - decoding: set by user */ int idct_algo; #define FF_IDCT_AUTO 0 #define FF_IDCT_INT 1 #define FF_IDCT_SIMPLE 2 #define FF_IDCT_SIMPLEMMX 3 #define FF_IDCT_LIBMPEG2MMX 4 #define FF_IDCT_PS2 5 #define FF_IDCT_MLIB 6 #define FF_IDCT_ARM 7 #define FF_IDCT_ALTIVEC 8 #define FF_IDCT_SH4 9 #define FF_IDCT_SIMPLEARM 10 /** * slice count. * - encoding: set by lavc * - decoding: set by user (or 0) */ int slice_count; /** * slice offsets in the frame in bytes. * - encoding: set/allocated by lavc * - decoding: set/allocated by user (or NULL) */ int *slice_offset; /** * error concealment flags. * - encoding: unused * - decoding: set by user */ int error_concealment; #define FF_EC_GUESS_MVS 1 #define FF_EC_DEBLOCK 2 /** * dsp_mask could be add used to disable unwanted CPU features * CPU features (i.e. MMX, SSE. ...) * * with FORCE flag you may instead enable given CPU features * (Dangerous: usable in case of misdetection, improper usage however will * result into program crash) */ unsigned dsp_mask; #define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */ /* lower 16 bits - CPU features */ #ifdef HAVE_MMX #define FF_MM_MMX 0x0001 /* standard MMX */ #define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */ #define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */ #define FF_MM_SSE 0x0008 /* SSE functions */ #define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */ #endif /* HAVE_MMX */ /** * bits per sample/pixel from the demuxer (needed for huffyuv). * - encoding: set by lavc * - decoding: set by user */ int bits_per_sample; /** * prediction method (needed for huffyuv). * - encoding: set by user * - decoding: unused */ int prediction_method; #define FF_PRED_LEFT 0 #define FF_PRED_PLANE 1 #define FF_PRED_MEDIAN 2 /** * sample aspect ratio (0 if unknown). * numerator and denominator must be relative prime and smaller then 256 for some video standards * - encoding: set by user. * - decoding: set by lavc. */ //AVRational sample_aspect_ratio; /** * the picture in the bitstream. * - encoding: set by lavc * - decoding: set by lavc */ AVFrame *coded_frame; /** * debug. * - encoding: set by user. * - decoding: set by user. */ int debug; #define FF_DEBUG_PICT_INFO 1 #define FF_DEBUG_RC 2 #define FF_DEBUG_BITSTREAM 4 #define FF_DEBUG_MB_TYPE 8 #define FF_DEBUG_QP 16 #define FF_DEBUG_MV 32 //#define FF_DEBUG_VIS_MV 0x00000040 #define FF_DEBUG_SKIP 0x00000080 #define FF_DEBUG_STARTCODE 0x00000100 #define FF_DEBUG_PTS 0x00000200 #define FF_DEBUG_ER 0x00000400 #define FF_DEBUG_MMCO 0x00000800 #define FF_DEBUG_BUGS 0x00001000 #define FF_DEBUG_VIS_QP 0x00002000 #define FF_DEBUG_VIS_MB_TYPE 0x00004000 /** * debug. * - encoding: set by user. * - decoding: set by user. */ int debug_mv; #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames /** * error. * - encoding: set by lavc if flags&CODEC_FLAG_PSNR * - decoding: unused */ uint64_t error[4]; /** * minimum MB quantizer. * - encoding: set by user. * - decoding: unused */ int mb_qmin; /** * maximum MB quantizer. * - encoding: set by user. * - decoding: unused */ int mb_qmax; /** * motion estimation compare function. * - encoding: set by user. * - decoding: unused */ int me_cmp; /** * subpixel motion estimation compare function. * - encoding: set by user. * - decoding: unused */ int me_sub_cmp; /** * macroblock compare function (not supported yet). * - encoding: set by user. * - decoding: unused */ int mb_cmp; /** * interlaced dct compare function * - encoding: set by user. * - decoding: unused */ int ildct_cmp; #define FF_CMP_SAD 0 #define FF_CMP_SSE 1 #define FF_CMP_SATD 2 #define FF_CMP_DCT 3 #define FF_CMP_PSNR 4 #define FF_CMP_BIT 5 #define FF_CMP_RD 6 #define FF_CMP_ZERO 7 #define FF_CMP_VSAD 8 #define FF_CMP_VSSE 9 #define FF_CMP_CHROMA 256 /** * ME diamond size & shape. * - encoding: set by user. * - decoding: unused */ int dia_size; /** * amount of previous MV predictors (2a+1 x 2a+1 square). * - encoding: set by user. * - decoding: unused */ int last_predictor_count; /** * pre pass for motion estimation. * - encoding: set by user. * - decoding: unused */ int pre_me; /** * motion estimation pre pass compare function. * - encoding: set by user. * - decoding: unused */ int me_pre_cmp; /** * ME pre pass diamond size & shape. * - encoding: set by user. * - decoding: unused */ int pre_dia_size; /** * subpel ME quality. * - encoding: set by user. * - decoding: unused */ int me_subpel_quality; /** * callback to negotiate the pixelFormat. * @param fmt is the list of formats which are supported by the codec, * its terminated by -1 as 0 is a valid format, the formats are ordered by quality * the first is allways the native one * @return the choosen format * - encoding: unused * - decoding: set by user, if not set then the native format will always be choosen */ enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt); /** * DTG active format information (additionnal aspect ratio * information only used in DVB MPEG2 transport streams). 0 if * not set. * * - encoding: unused. * - decoding: set by decoder */ int dtg_active_format; #define FF_DTG_AFD_SAME 8 #define FF_DTG_AFD_4_3 9 #define FF_DTG_AFD_16_9 10 #define FF_DTG_AFD_14_9 11 #define FF_DTG_AFD_4_3_SP_14_9 13 #define FF_DTG_AFD_16_9_SP_14_9 14 #define FF_DTG_AFD_SP_4_3 15 /** * Maximum motion estimation search range in subpel units. * if 0 then no limit * * - encoding: set by user. * - decoding: unused. */ int me_range; /** * frame_rate_base. * for variable fps this is 1 * - encoding: set by user. * - decoding: set by lavc. * @todo move this after frame_rate */ int frame_rate_base; /** * intra quantizer bias. * - encoding: set by user. * - decoding: unused */ int intra_quant_bias; #define FF_DEFAULT_QUANT_BIAS 999999 /** * inter quantizer bias. * - encoding: set by user. * - decoding: unused */ int inter_quant_bias; /** * color table ID. * - encoding: unused. * - decoding: which clrtable should be used for 8bit RGB images * table have to be stored somewhere FIXME */ int color_table_id; /** * internal_buffer count. * Dont touch, used by lavc default_get_buffer() */ int internal_buffer_count; /** * internal_buffers. * Dont touch, used by lavc default_get_buffer() */ void *internal_buffer; #define FF_LAMBDA_SHIFT 7 #define FF_LAMBDA_SCALE (1< ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). * this is used to workaround some encoder bugs * - encoding: unused * - decoding: set by user, will be converted to upper case by lavc during init */ unsigned int stream_codec_tag; /** * scene change detection threshold. * 0 is default, larger means fewer detected scene changes * - encoding: set by user. * - decoding: unused */ int scenechange_threshold; /** * minimum lagrange multipler * - encoding: set by user. * - decoding: unused */ int lmin; /** * maximum lagrange multipler * - encoding: set by user. * - decoding: unused */ int lmax; /** * Palette control structure * - encoding: ??? (no palette-enabled encoder yet) * - decoding: set by user. */ struct AVPaletteControl *palctrl; /** * noise reduction strength * - encoding: set by user. * - decoding: unused */ int noise_reduction; /** * called at the beginning of a frame to get cr buffer for it. * buffer type (size, hints) must be the same. lavc won't check it. * lavc will pass previous buffer in pic, function should return * same buffer or new buffer with old frame "painted" into it. * if pic.data[0] == NULL must behave like get_buffer(). * - encoding: unused * - decoding: set by lavc, user can override */ int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic); /** * number of bits which should be loaded into the rc buffer before decoding starts * - encoding: set by user. * - decoding: unused */ int rc_initial_buffer_occupancy; /** * * - encoding: set by user. * - decoding: unused */ int inter_threshold; /** * CODEC_FLAG2_*. * - encoding: set by user. * - decoding: set by user. */ int flags2; /** * simulates errors in the bitstream to test error concealment. * - encoding: set by user. * - decoding: unused. */ int error_rate; /** * MP3 antialias algorithm, see FF_AA_* below. * - encoding: unused * - decoding: set by user */ int antialias_algo; #define FF_AA_AUTO 0 #define FF_AA_FASTINT 1 //not implemented yet #define FF_AA_INT 2 #define FF_AA_FLOAT 3 /** * Quantizer noise shaping. * - encoding: set by user * - decoding: unused */ int quantizer_noise_shaping; } AVCodecContext; /** * AVOption. */ typedef struct AVOption { /** options' name */ const char *name; /* if name is NULL, it indicates a link to next */ /** short English text help or const struct AVOption* subpointer */ const char *help; // const struct AVOption* sub; /** offset to context structure where the parsed value should be stored */ int offset; /** options' type */ int type; #define FF_OPT_TYPE_BOOL 1 ///< boolean - true,1,on (or simply presence) #define FF_OPT_TYPE_DOUBLE 2 ///< double #define FF_OPT_TYPE_INT 3 ///< integer #define FF_OPT_TYPE_STRING 4 ///< string (finished with \0) #define FF_OPT_TYPE_MASK 0x1f ///< mask for types - upper bits are various flags //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40) #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80) /** min value (min == max -> no limits) */ double min; /** maximum value for double/int */ double max; /** default boo [0,1]l/double/int value */ double defval; /** * default string value (with optional semicolon delimited extra option-list * i.e. option1;option2;option3 * defval might select other then first argument as default */ const char *defstr; #define FF_OPT_MAX_DEPTH 10 } AVOption; /** * Parse option(s) and sets fields in passed structure * @param strct structure where the parsed results will be written * @param list list with AVOptions * @param opts string with options for parsing */ int avoption_parse(void* strct, const AVOption* list, const char* opts); /** * AVCodec. */ typedef struct AVCodec { const char *name; enum CodecType type; int id; int priv_data_size; int (*init)(AVCodecContext *); int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data); int (*close)(AVCodecContext *); int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, uint8_t *buf, int buf_size); int capabilities; const AVOption *options; struct AVCodec *next; void (*flush)(AVCodecContext *); } AVCodec; /** * four components are given, that's all. * the last component is alpha */ typedef struct AVPicture { uint8_t *data[4]; int linesize[4]; ///< number of bytes per line } AVPicture; /** * AVPaletteControl * This structure defines a method for communicating palette changes * between and demuxer and a decoder. */ #define AVPALETTE_SIZE 1024 #define AVPALETTE_COUNT 256 typedef struct AVPaletteControl { /* demuxer sets this to 1 to indicate the palette has changed; * decoder resets to 0 */ int palette_changed; /* 4-byte ARGB palette entries, stored in native byte order; note that * the individual palette components should be on a 8-bit scale; if * the palette data comes from a IBM VGA native format, the component * data is probably 6 bits in size and needs to be scaled */ unsigned int palette[AVPALETTE_COUNT]; } AVPaletteControl; extern AVCodec ac3_encoder; extern AVCodec mp2_encoder; extern AVCodec mp3lame_encoder; extern AVCodec oggvorbis_encoder; extern AVCodec faac_encoder; extern AVCodec mpeg1video_encoder; extern AVCodec mpeg2video_encoder; extern AVCodec h263_encoder; extern AVCodec h263p_encoder; extern AVCodec flv_encoder; extern AVCodec rv10_encoder; extern AVCodec rv20_encoder; extern AVCodec mjpeg_encoder; extern AVCodec ljpeg_encoder; extern AVCodec mpeg4_encoder; extern AVCodec msmpeg4v1_encoder; extern AVCodec msmpeg4v2_encoder; extern AVCodec msmpeg4v3_encoder; extern AVCodec wmv1_encoder; extern AVCodec wmv2_encoder; extern AVCodec huffyuv_encoder; extern AVCodec h264_encoder; extern AVCodec asv1_encoder; extern AVCodec asv2_encoder; extern AVCodec vcr1_encoder; extern AVCodec ffv1_encoder; extern AVCodec mdec_encoder; extern AVCodec zlib_encoder; extern AVCodec h263_decoder; extern AVCodec mpeg4_decoder; extern AVCodec msmpeg4v1_decoder; extern AVCodec msmpeg4v2_decoder; extern AVCodec msmpeg4v3_decoder; extern AVCodec wmv1_decoder; extern AVCodec wmv2_decoder; extern AVCodec mpeg1video_decoder; extern AVCodec mpeg2video_decoder; extern AVCodec mpegvideo_decoder; extern AVCodec mpeg_xvmc_decoder; extern AVCodec h263i_decoder; extern AVCodec flv_decoder; extern AVCodec rv10_decoder; extern AVCodec rv20_decoder; extern AVCodec svq1_decoder; extern AVCodec svq3_decoder; extern AVCodec dvvideo_decoder; extern AVCodec wmav1_decoder; extern AVCodec wmav2_decoder; extern AVCodec mjpeg_decoder; extern AVCodec mjpegb_decoder; extern AVCodec sp5x_decoder; extern AVCodec mp2_decoder; extern AVCodec mp3_decoder; extern AVCodec mace3_decoder; extern AVCodec mace6_decoder; extern AVCodec huffyuv_decoder; extern AVCodec oggvorbis_decoder; extern AVCodec cyuv_decoder; extern AVCodec h264_decoder; extern AVCodec indeo3_decoder; extern AVCodec vp3_decoder; extern AVCodec theora_decoder; extern AVCodec amr_nb_decoder; extern AVCodec amr_nb_encoder; extern AVCodec amr_wb_encoder; extern AVCodec amr_wb_decoder; extern AVCodec aac_decoder; extern AVCodec mpeg4aac_decoder; extern AVCodec asv1_decoder; extern AVCodec asv2_decoder; extern AVCodec vcr1_decoder; extern AVCodec cljr_decoder; extern AVCodec ffv1_decoder; extern AVCodec fourxm_decoder; extern AVCodec mdec_decoder; extern AVCodec roq_decoder; extern AVCodec interplay_video_decoder; extern AVCodec xan_wc3_decoder; extern AVCodec rpza_decoder; extern AVCodec cinepak_decoder; extern AVCodec msrle_decoder; extern AVCodec msvideo1_decoder; extern AVCodec vqa_decoder; extern AVCodec idcin_decoder; extern AVCodec eightbps_decoder; extern AVCodec smc_decoder; extern AVCodec flic_decoder; extern AVCodec vmdvideo_decoder; extern AVCodec vmdaudio_decoder; extern AVCodec truemotion1_decoder; extern AVCodec mszh_decoder; extern AVCodec zlib_decoder; extern AVCodec ra_144_decoder; extern AVCodec ra_288_decoder; extern AVCodec roq_dpcm_decoder; extern AVCodec interplay_dpcm_decoder; extern AVCodec xan_dpcm_decoder; extern AVCodec qtrle_decoder; /* pcm codecs */ #define PCM_CODEC(id, name) \ extern AVCodec name ## _decoder; \ extern AVCodec name ## _encoder PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le); PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be); PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le); PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be); PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8); PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8); PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw); PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw); /* adpcm codecs */ PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt); PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav); PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3); PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4); PCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws); PCM_CODEC(CODEC_ID_ADPCM_SMJPEG, adpcm_ima_smjpeg); PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms); PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm); PCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa); PCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx); PCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea); #undef PCM_CODEC /* dummy raw video codec */ extern AVCodec rawvideo_encoder; extern AVCodec rawvideo_decoder; /* the following codecs use external GPL libs */ extern AVCodec ac3_decoder; /* resample.c */ struct ReSampleContext; typedef struct ReSampleContext ReSampleContext; ReSampleContext *audio_resample_init(int output_channels, int input_channels, int output_rate, int input_rate); int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples); void audio_resample_close(ReSampleContext *s); /* YUV420 format is assumed ! */ struct ImgReSampleContext; typedef struct ImgReSampleContext ImgReSampleContext; ImgReSampleContext *img_resample_init(int output_width, int output_height, int input_width, int input_height); ImgReSampleContext *img_resample_full_init(int owidth, int oheight, int iwidth, int iheight, int topBand, int bottomBand, int leftBand, int rightBand); void img_resample(ImgReSampleContext *s, AVPicture *output, const AVPicture *input); void img_resample_close(ImgReSampleContext *s); /** * Allocate memory for a picture. Call avpicture_free to free it. * * @param picture the picture to be filled in. * @param pix_fmt the format of the picture. * @param width the width of the picture. * @param height the height of the picture. * @return 0 if successful, -1 if not. */ int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height); /* Free a picture previously allocated by avpicture_alloc. */ void avpicture_free(AVPicture *picture); int avpicture_fill(AVPicture *picture, uint8_t *ptr, int pix_fmt, int width, int height); int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height, unsigned char *dest, int dest_size); int avpicture_get_size(int pix_fmt, int width, int height); void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift); const char *avcodec_get_pix_fmt_name(int pix_fmt); enum PixelFormat avcodec_get_pix_fmt(const char* name); #define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */ #define FF_LOSS_DEPTH 0x0002 /* loss due to color depth change */ #define FF_LOSS_COLORSPACE 0x0004 /* loss due to color space conversion */ #define FF_LOSS_ALPHA 0x0008 /* loss of alpha bits */ #define FF_LOSS_COLORQUANT 0x0010 /* loss due to color quantization */ #define FF_LOSS_CHROMA 0x0020 /* loss of chroma (e.g. rgb to gray conversion) */ int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt, int has_alpha); int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt, int has_alpha, int *loss_ptr); #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */ #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */ int img_get_alpha_info(const AVPicture *src, int pix_fmt, int width, int height); /* convert among pixel formats */ int img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int pix_fmt, int width, int height); /* deinterlace a picture */ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, int pix_fmt, int width, int height); /* external high level API */ extern AVCodec *first_avcodec; /* returns LIBAVCODEC_VERSION_INT constant */ unsigned avcodec_version(void); /* returns LIBAVCODEC_BUILD constant */ unsigned avcodec_build(void); void avcodec_init(void); void register_avcodec(AVCodec *format); AVCodec *avcodec_find_encoder(enum CodecID id); AVCodec *avcodec_find_encoder_by_name(const char *name); AVCodec *avcodec_find_decoder(enum CodecID id); AVCodec *avcodec_find_decoder_by_name(const char *name); void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode); void avcodec_get_context_defaults(AVCodecContext *s); AVCodecContext *avcodec_alloc_context(void); AVFrame *avcodec_alloc_frame(void); int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic); void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic); void avcodec_default_free_buffers(AVCodecContext *s); /** * opens / inits the AVCodecContext. * not thread save! */ int avcodec_open(AVCodecContext *avctx, AVCodec *codec); int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, uint8_t *buf, int buf_size); int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, uint8_t *buf, int buf_size); int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, int *data_size_ptr, uint8_t *buf, int buf_size); int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples); int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVFrame *pict); int avcodec_close(AVCodecContext *avctx); void avcodec_register_all(void); void avcodec_flush_buffers(AVCodecContext *avctx); /* misc usefull functions */ /** * returns a single letter to describe the picture type */ char av_get_pict_type_char(int pict_type); /** * reduce a fraction. * this is usefull for framerate calculations * @param max the maximum allowed for dst_nom & dst_den * @return 1 if exact, 0 otherwise */ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max); /** * rescale a 64bit integer. * a simple a*b/c isnt possible as it can overflow */ int64_t av_rescale(int64_t a, int b, int c); /** * Interface for 0.5.0 version * * do not even think about it's usage for this moment */ typedef struct { /// compressed size used from given memory buffer int size; /// I/P/B frame type int frame_type; } avc_enc_result_t; /** * Commands * order can't be changed - once it was defined */ typedef enum { // general commands AVC_OPEN_BY_NAME = 0xACA000, AVC_OPEN_BY_CODEC_ID, AVC_OPEN_BY_FOURCC, AVC_CLOSE, AVC_FLUSH, // pin - struct { uint8_t* src, uint_t src_size } // pout - struct { AVPicture* img, consumed_bytes, AVC_DECODE, // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size } // pout - uint_t used_from_dest_size AVC_ENCODE, // query/get video commands AVC_GET_VERSION = 0xACB000, AVC_GET_WIDTH, AVC_GET_HEIGHT, AVC_GET_DELAY, AVC_GET_QUANT_TABLE, // ... // query/get audio commands AVC_GET_FRAME_SIZE = 0xABC000, // maybe define some simple structure which // might be passed to the user - but they can't // contain any codec specific parts and these // calls are usualy necessary only few times // set video commands AVC_SET_WIDTH = 0xACD000, AVC_SET_HEIGHT, // set video encoding commands AVC_SET_FRAME_RATE = 0xACD800, AVC_SET_QUALITY, AVC_SET_HURRY_UP, // set audio commands AVC_SET_SAMPLE_RATE = 0xACE000, AVC_SET_CHANNELS, } avc_cmd_t; /** * \param handle allocated private structure by libavcodec * for initialization pass NULL - will be returned pout * user is supposed to know nothing about its structure * \param cmd type of operation to be performed * \param pint input parameter * \param pout output parameter * * \returns command status - eventually for query command it might return * integer resulting value */ int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout); /* frame parsing */ typedef struct AVCodecParserContext { void *priv_data; struct AVCodecParser *parser; int64_t frame_offset; /* offset of the current frame */ int64_t cur_offset; /* current offset (incremented by each av_parser_parse()) */ int64_t last_frame_offset; /* offset of the last frame */ /* video info */ int pict_type; /* XXX: put it back in AVCodecContext */ int repeat_pict; /* XXX: put it back in AVCodecContext */ int64_t pts; /* pts of the current frame */ int64_t dts; /* dts of the current frame */ /* private data */ int64_t last_pts; int64_t last_dts; #define AV_PARSER_PTS_NB 4 int cur_frame_start_index; int64_t cur_frame_offset[AV_PARSER_PTS_NB]; int64_t cur_frame_pts[AV_PARSER_PTS_NB]; int64_t cur_frame_dts[AV_PARSER_PTS_NB]; } AVCodecParserContext; typedef struct AVCodecParser { int codec_ids[3]; /* several codec IDs are permitted */ int priv_data_size; int (*parser_init)(AVCodecParserContext *s); int (*parser_parse)(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size); void (*parser_close)(AVCodecParserContext *s); struct AVCodecParser *next; } AVCodecParser; extern AVCodecParser *av_first_parser; void av_register_codec_parser(AVCodecParser *parser); AVCodecParserContext *av_parser_init(int codec_id); int av_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts); void av_parser_close(AVCodecParserContext *s); extern AVCodecParser mpegvideo_parser; extern AVCodecParser mpeg4video_parser; extern AVCodecParser h263_parser; extern AVCodecParser h264_parser; extern AVCodecParser mpegaudio_parser; extern AVCodecParser ac3_parser; /* memory */ void *av_malloc(unsigned int size); void *av_mallocz(unsigned int size); void *av_realloc(void *ptr, unsigned int size); void av_free(void *ptr); char *av_strdup(const char *s); void __av_freep(void **ptr); #define av_freep(p) __av_freep((void **)(p)) void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size); /* for static data only */ /* call av_free_static to release all staticaly allocated tables */ void av_free_static(void); void *__av_mallocz_static(void** location, unsigned int size); #define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s) /* add by bero : in adx.c */ int is_adx(const unsigned char *buf,size_t bufsize); void img_copy(AVPicture *dst, const AVPicture *src, int pix_fmt, int width, int height); /* av_log API */ #include #define AV_LOG_ERROR 0 #define AV_LOG_INFO 1 #define AV_LOG_DEBUG 2 extern void av_log(AVCodecContext*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern void av_vlog(AVCodecContext*, int level, const char *fmt, va_list); extern int av_log_get_level(void); extern void av_log_set_level(int); extern void av_log_set_callback(void (*)(AVCodecContext*, int, const char*, va_list)); #undef AV_LOG_TRAP_PRINTF #ifdef AV_LOG_TRAP_PRINTF #define printf DO NOT USE #define fprintf DO NOT USE #undef stderr #define stderr DO NOT USE #endif #ifdef __cplusplus } #endif #endif /* AVCODEC_H */ xmms-wma-1.0.5/ffmpeg-strip-wma/avio.c0000644000175000017500000001103007742674171020050 0ustar whistlerwhistler/* * Unbuffered io for ffmpeg system * Copyright (c) 2001 Fabrice Bellard * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avformat.h" static int default_interrupt_cb(void); URLProtocol *first_protocol = NULL; URLInterruptCB *url_interrupt_cb = default_interrupt_cb; int register_protocol(URLProtocol *protocol) { URLProtocol **p; p = &first_protocol; while (*p != NULL) p = &(*p)->next; *p = protocol; protocol->next = NULL; return 0; } int url_open(URLContext **puc, const char *filename, int flags) { URLContext *uc; URLProtocol *up; const char *p; char proto_str[128], *q; int err; p = filename; q = proto_str; while (*p != '\0' && *p != ':') { /* protocols can only contain alphabetic chars */ if (!isalpha(*p)) goto file_proto; if ((q - proto_str) < sizeof(proto_str) - 1) *q++ = *p; p++; } /* if the protocol has length 1, we consider it is a dos drive */ if (*p == '\0' || (q - proto_str) <= 1) { file_proto: strcpy(proto_str, "file"); } else { *q = '\0'; } up = first_protocol; while (up != NULL) { if (!strcmp(proto_str, up->name)) goto found; up = up->next; } err = -ENOENT; goto fail; found: uc = av_malloc(sizeof(URLContext) + strlen(filename)); if (!uc) { err = -ENOMEM; goto fail; } strcpy(uc->filename, filename); uc->prot = up; uc->flags = flags; uc->is_streamed = 0; /* default = not streamed */ uc->max_packet_size = 0; /* default: stream file */ err = up->url_open(uc, filename, flags); if (err < 0) { av_free(uc); *puc = NULL; return err; } *puc = uc; return 0; fail: *puc = NULL; return err; } int url_read(URLContext *h, unsigned char *buf, int size) { int ret; if (h->flags & URL_WRONLY) return -EIO; ret = h->prot->url_read(h, buf, size); return ret; } #ifdef CONFIG_ENCODERS int url_write(URLContext *h, unsigned char *buf, int size) { int ret; if (!(h->flags & (URL_WRONLY | URL_RDWR))) return -EIO; /* avoid sending too big packets */ if (h->max_packet_size && size > h->max_packet_size) return -EIO; ret = h->prot->url_write(h, buf, size); return ret; } #endif //CONFIG_ENCODERS offset_t url_seek(URLContext *h, offset_t pos, int whence) { offset_t ret; if (!h->prot->url_seek) return -EPIPE; ret = h->prot->url_seek(h, pos, whence); return ret; } int url_close(URLContext *h) { int ret; ret = h->prot->url_close(h); av_free(h); return ret; } int url_exist(const char *filename) { URLContext *h; if (url_open(&h, filename, URL_RDONLY) < 0) return 0; url_close(h); return 1; } offset_t url_filesize(URLContext *h) { offset_t pos, size; pos = url_seek(h, 0, SEEK_CUR); size = url_seek(h, 0, SEEK_END); url_seek(h, pos, SEEK_SET); return size; } /* * Return the maximum packet size associated to packetized file * handle. If the file is not packetized (stream like http or file on * disk), then 0 is returned. * * @param h file handle * @return maximum packet size in bytes */ int url_get_max_packet_size(URLContext *h) { return h->max_packet_size; } void url_get_filename(URLContext *h, char *buf, int buf_size) { pstrcpy(buf, buf_size, h->filename); } static int default_interrupt_cb(void) { return 0; } /** * The callback is called in blocking functions to test regulary if * asynchronous interruption is needed. -EINTR is returned in this * case by the interrupted function. 'NULL' means no interrupt * callback is given. */ void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) { if (!interrupt_cb) interrupt_cb = default_interrupt_cb; url_interrupt_cb = interrupt_cb; } xmms-wma-1.0.5/ffmpeg-strip-wma/futils.c0000644000175000017500000017720710301157770020425 0ustar whistlerwhistler/* * Various utilities for ffmpeg system * Copyright (c) 2000, 2001, 2002 Fabrice Bellard * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avformat.h" #undef NDEBUG #include AVInputFormat *first_iformat; AVOutputFormat *first_oformat; AVImageFormat *first_image_format; void av_register_input_format(AVInputFormat *format) { AVInputFormat **p; p = &first_iformat; while (*p != NULL) p = &(*p)->next; *p = format; format->next = NULL; } void av_register_output_format(AVOutputFormat *format) { AVOutputFormat **p; p = &first_oformat; while (*p != NULL) p = &(*p)->next; *p = format; format->next = NULL; } int match_ext(const char *filename, const char *extensions) { const char *ext, *p; char ext1[32], *q; ext = strrchr(filename, '.'); if (ext) { ext++; p = extensions; for(;;) { q = ext1; while (*p != '\0' && *p != ',') *q++ = *p++; *q = '\0'; if (!strcasecmp(ext1, ext)) return 1; if (*p == '\0') break; p++; } } return 0; } AVOutputFormat *guess_format(const char *short_name, const char *filename, const char *mime_type) { AVOutputFormat *fmt, *fmt_found; int score_max, score; /* specific test for image sequences */ if (!short_name && filename && filename_number_test(filename) >= 0 && guess_image_format(filename)) { return guess_format("image", NULL, NULL); } /* find the proper file type */ fmt_found = NULL; score_max = 0; fmt = first_oformat; while (fmt != NULL) { score = 0; if (fmt->name && short_name && !strcmp(fmt->name, short_name)) score += 100; if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type)) score += 10; if (filename && fmt->extensions && match_ext(filename, fmt->extensions)) { score += 5; } if (score > score_max) { score_max = score; fmt_found = fmt; } fmt = fmt->next; } return fmt_found; } AVOutputFormat *guess_stream_format(const char *short_name, const char *filename, const char *mime_type) { AVOutputFormat *fmt = guess_format(short_name, filename, mime_type); if (fmt) { AVOutputFormat *stream_fmt; char stream_format_name[64]; snprintf(stream_format_name, sizeof(stream_format_name), "%s_stream", fmt->name); stream_fmt = guess_format(stream_format_name, NULL, NULL); if (stream_fmt) fmt = stream_fmt; } return fmt; } AVInputFormat *av_find_input_format(const char *short_name) { AVInputFormat *fmt; for(fmt = first_iformat; fmt != NULL; fmt = fmt->next) { if (!strcmp(fmt->name, short_name)) return fmt; } return NULL; } /* memory handling */ /** * Default packet destructor */ static void av_destruct_packet(AVPacket *pkt) { av_free(pkt->data); pkt->data = NULL; pkt->size = 0; } /** * Allocate the payload of a packet and intialized its fields to default values. * * @param pkt packet * @param size wanted payload size * @return 0 if OK. AVERROR_xxx otherwise. */ int av_new_packet(AVPacket *pkt, int size) { void *data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); if (!data) return AVERROR_NOMEM; memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); av_init_packet(pkt); pkt->data = data; pkt->size = size; pkt->destruct = av_destruct_packet; return 0; } /* This is a hack - the packet memory allocation stuff is broken. The packet is allocated if it was not really allocated */ int av_dup_packet(AVPacket *pkt) { if (pkt->destruct != av_destruct_packet) { uint8_t *data; /* we duplicate the packet and don't forget to put the padding again */ data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE); if (!data) { return AVERROR_NOMEM; } memcpy(data, pkt->data, pkt->size); memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); pkt->data = data; pkt->destruct = av_destruct_packet; } return 0; } /* fifo handling */ int fifo_init(FifoBuffer *f, int size) { f->buffer = av_malloc(size); if (!f->buffer) return -1; f->end = f->buffer + size; f->wptr = f->rptr = f->buffer; return 0; } void fifo_free(FifoBuffer *f) { av_free(f->buffer); } int fifo_size(FifoBuffer *f, uint8_t *rptr) { int size; if (f->wptr >= rptr) { size = f->wptr - rptr; } else { size = (f->end - rptr) + (f->wptr - f->buffer); } return size; } /* get data from the fifo (return -1 if not enough data) */ int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr) { uint8_t *rptr = *rptr_ptr; int size, len; if (f->wptr >= rptr) { size = f->wptr - rptr; } else { size = (f->end - rptr) + (f->wptr - f->buffer); } if (size < buf_size) return -1; while (buf_size > 0) { len = f->end - rptr; if (len > buf_size) len = buf_size; memcpy(buf, rptr, len); buf += len; rptr += len; if (rptr >= f->end) rptr = f->buffer; buf_size -= len; } *rptr_ptr = rptr; return 0; } void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr) { int len; uint8_t *wptr; wptr = *wptr_ptr; while (size > 0) { len = f->end - wptr; if (len > size) len = size; memcpy(wptr, buf, len); wptr += len; if (wptr >= f->end) wptr = f->buffer; buf += len; size -= len; } *wptr_ptr = wptr; } int filename_number_test(const char *filename) { char buf[1024]; return get_frame_filename(buf, sizeof(buf), filename, 1); } /* guess file format */ AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened) { AVInputFormat *fmt1, *fmt; int score, score_max; fmt = NULL; score_max = 0; for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) { if (!is_opened && !(fmt1->flags & AVFMT_NOFILE)) continue; score = 0; if (fmt1->read_probe) { score = fmt1->read_probe(pd); } else if (fmt1->extensions) { if (match_ext(pd->filename, fmt1->extensions)) { score = 50; } } if (score > score_max) { score_max = score; fmt = fmt1; } } return fmt; } /************************************************************/ /* input media file */ /** * open a media file from an IO stream. 'fmt' must be specified. */ int av_open_input_stream(AVFormatContext **ic_ptr, ByteIOContext *pb, const char *filename, AVInputFormat *fmt, AVFormatParameters *ap) { int err; AVFormatContext *ic; ic = av_mallocz(sizeof(AVFormatContext)); if (!ic) { err = AVERROR_NOMEM; goto fail; } ic->iformat = fmt; if (pb) ic->pb = *pb; ic->duration = AV_NOPTS_VALUE; ic->start_time = AV_NOPTS_VALUE; pstrcpy(ic->filename, sizeof(ic->filename), filename); /* allocate private data */ if (fmt->priv_data_size > 0) { ic->priv_data = av_mallocz(fmt->priv_data_size); if (!ic->priv_data) { err = AVERROR_NOMEM; goto fail; } } else { ic->priv_data = NULL; } /* default pts settings is MPEG like */ av_set_pts_info(ic, 33, 1, 90000); ic->last_pkt_pts = AV_NOPTS_VALUE; ic->last_pkt_dts = AV_NOPTS_VALUE; ic->last_pkt_stream_pts = AV_NOPTS_VALUE; ic->last_pkt_stream_dts = AV_NOPTS_VALUE; err = ic->iformat->read_header(ic, ap); if (err < 0) goto fail; if (pb) ic->data_offset = url_ftell(&ic->pb); *ic_ptr = ic; return 0; fail: if (ic) { av_freep(&ic->priv_data); } av_free(ic); *ic_ptr = NULL; return err; } #define PROBE_BUF_SIZE 2048 /** * Open a media file as input. The codec are not opened. Only the file * header (if present) is read. * * @param ic_ptr the opened media file handle is put here * @param filename filename to open. * @param fmt if non NULL, force the file format to use * @param buf_size optional buffer size (zero if default is OK) * @param ap additionnal parameters needed when opening the file (NULL if default) * @return 0 if OK. AVERROR_xxx otherwise. */ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap) { int err, must_open_file, file_opened; uint8_t buf[PROBE_BUF_SIZE]; AVProbeData probe_data, *pd = &probe_data; ByteIOContext pb1, *pb = &pb1; file_opened = 0; pd->filename = ""; if (filename) pd->filename = filename; pd->buf = buf; pd->buf_size = 0; if (!fmt) { /* guess format if no file can be opened */ fmt = av_probe_input_format(pd, 0); } /* do not open file if the format does not need it. XXX: specific hack needed to handle RTSP/TCP */ must_open_file = 1; if (fmt && (fmt->flags & AVFMT_NOFILE)) { must_open_file = 0; } if (!fmt || must_open_file) { /* if no file needed do not try to open one */ if (url_fopen(pb, filename, URL_RDONLY) < 0) { err = AVERROR_IO; goto fail; } file_opened = 1; if (buf_size > 0) { url_setbufsize(pb, buf_size); } if (!fmt) { /* read probe data */ pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE); url_fseek(pb, 0, SEEK_SET); } } /* guess file format */ if (!fmt) { fmt = av_probe_input_format(pd, 1); } /* if still no format found, error */ if (!fmt) { err = AVERROR_NOFMT; goto fail; } /* XXX: suppress this hack for redirectors */ #ifdef CONFIG_NETWORK if (fmt == &redir_demux) { err = redir_open(ic_ptr, pb); url_fclose(pb); return err; } #endif /* check filename in case of an image number is expected */ if (fmt->flags & AVFMT_NEEDNUMBER) { if (filename_number_test(filename) < 0) { err = AVERROR_NUMEXPECTED; goto fail; } } err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap); if (err) goto fail; return 0; fail: if (file_opened) url_fclose(pb); *ic_ptr = NULL; return err; } /*******************************************************/ /** * Read a transport packet from a media file. This function is * absolete and should never be used. Use av_read_frame() instead. * * @param s media file handle * @param pkt is filled * @return 0 if OK. AVERROR_xxx if error. */ int av_read_packet(AVFormatContext *s, AVPacket *pkt) { return s->iformat->read_packet(s, pkt); } /**********************************************************/ /* convert the packet time stamp units and handle wrapping. The wrapping is handled by considering the next PTS/DTS as a delta to the previous value. We handle the delta as a fraction to avoid any rounding errors. */ static inline int64_t convert_timestamp_units(AVFormatContext *s, int64_t *plast_pkt_pts, int *plast_pkt_pts_frac, int64_t *plast_pkt_stream_pts, int64_t pts) { int64_t stream_pts; int64_t delta_pts; int shift, pts_frac; if (pts != AV_NOPTS_VALUE) { stream_pts = pts; if (*plast_pkt_stream_pts != AV_NOPTS_VALUE) { shift = 64 - s->pts_wrap_bits; delta_pts = ((stream_pts - *plast_pkt_stream_pts) << shift) >> shift; /* XXX: overflow possible but very unlikely as it is a delta */ delta_pts = delta_pts * AV_TIME_BASE * s->pts_num; pts = *plast_pkt_pts + (delta_pts / s->pts_den); pts_frac = *plast_pkt_pts_frac + (delta_pts % s->pts_den); if (pts_frac >= s->pts_den) { pts_frac -= s->pts_den; pts++; } } else { /* no previous pts, so no wrapping possible */ pts = (int64_t)(((double)stream_pts * AV_TIME_BASE * s->pts_num) / (double)s->pts_den); pts_frac = 0; } *plast_pkt_stream_pts = stream_pts; *plast_pkt_pts = pts; *plast_pkt_pts_frac = pts_frac; } return pts; } /* get the number of samples of an audio frame. Return (-1) if error */ static int get_audio_frame_size(AVCodecContext *enc, int size) { int frame_size; if (enc->frame_size <= 1) { /* specific hack for pcm codecs because no frame size is provided */ switch(enc->codec_id) { case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_U16BE: if (enc->channels == 0) return -1; frame_size = size / (2 * enc->channels); break; case CODEC_ID_PCM_S8: case CODEC_ID_PCM_U8: case CODEC_ID_PCM_MULAW: case CODEC_ID_PCM_ALAW: if (enc->channels == 0) return -1; frame_size = size / (enc->channels); break; default: /* used for example by ADPCM codecs */ if (enc->bit_rate == 0) return -1; frame_size = (size * 8 * enc->sample_rate) / enc->bit_rate; break; } } else { frame_size = enc->frame_size; } return frame_size; } /* return the frame duration in seconds, return 0 if not available */ static void compute_frame_duration(int *pnum, int *pden, AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt) { int frame_size; *pnum = 0; *pden = 0; switch(st->codec.codec_type) { case CODEC_TYPE_VIDEO: *pnum = st->codec.frame_rate_base; *pden = st->codec.frame_rate; if (pc && pc->repeat_pict) { *pden *= 2; *pnum = (*pnum) * (2 + pc->repeat_pict); } break; case CODEC_TYPE_AUDIO: frame_size = get_audio_frame_size(&st->codec, pkt->size); if (frame_size < 0) break; *pnum = frame_size; *pden = st->codec.sample_rate; break; default: break; } } static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt) { int num, den, presentation_delayed; if (pkt->duration == 0) { compute_frame_duration(&num, &den, s, st, pc, pkt); if (den && num) { pkt->duration = (num * (int64_t)AV_TIME_BASE) / den; } } /* do we have a video B frame ? */ presentation_delayed = 0; if (st->codec.codec_type == CODEC_TYPE_VIDEO) { /* XXX: need has_b_frame, but cannot get it if the codec is not initialized */ if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO || st->codec.codec_id == CODEC_ID_MPEG2VIDEO || st->codec.codec_id == CODEC_ID_MPEG4 || st->codec.codec_id == CODEC_ID_H264) && pc && pc->pict_type != FF_B_TYPE) presentation_delayed = 1; } /* interpolate PTS and DTS if they are not present */ if (presentation_delayed) { /* DTS = decompression time stamp */ /* PTS = presentation time stamp */ if (pkt->dts == AV_NOPTS_VALUE) { pkt->dts = st->cur_dts; } else { st->cur_dts = pkt->dts; } /* this is tricky: the dts must be incremented by the duration of the frame we are displaying, i.e. the last I or P frame */ if (st->last_IP_duration == 0) st->cur_dts += pkt->duration; else st->cur_dts += st->last_IP_duration; st->last_IP_duration = pkt->duration; /* cannot compute PTS if not present (we can compute it only by knowing the futur */ } else { /* presentation is not delayed : PTS and DTS are the same */ if (pkt->pts == AV_NOPTS_VALUE) { pkt->pts = st->cur_dts; pkt->dts = st->cur_dts; } else { st->cur_dts = pkt->pts; pkt->dts = pkt->pts; } st->cur_dts += pkt->duration; } /* update flags */ if (pc) { pkt->flags = 0; /* key frame computation */ switch(st->codec.codec_type) { case CODEC_TYPE_VIDEO: if (pc->pict_type == FF_I_TYPE) pkt->flags |= PKT_FLAG_KEY; break; case CODEC_TYPE_AUDIO: pkt->flags |= PKT_FLAG_KEY; break; default: break; } } } static void av_destruct_packet_nofree(AVPacket *pkt) { pkt->data = NULL; pkt->size = 0; } static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) { AVStream *st; int len, ret, i; for(;;) { /* select current input stream component */ st = s->cur_st; if (st) { if (!st->parser) { /* no parsing needed: we just output the packet as is */ /* raw data support */ *pkt = s->cur_pkt; compute_pkt_fields(s, st, NULL, pkt); s->cur_st = NULL; return 0; } else if (s->cur_len > 0) { len = av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size, s->cur_ptr, s->cur_len, s->cur_pkt.pts, s->cur_pkt.dts); s->cur_pkt.pts = AV_NOPTS_VALUE; s->cur_pkt.dts = AV_NOPTS_VALUE; /* increment read pointer */ s->cur_ptr += len; s->cur_len -= len; /* return packet if any */ if (pkt->size) { got_packet: pkt->duration = 0; pkt->stream_index = st->index; pkt->pts = st->parser->pts; pkt->dts = st->parser->dts; pkt->destruct = av_destruct_packet_nofree; compute_pkt_fields(s, st, st->parser, pkt); return 0; } } else { /* free packet */ av_free_packet(&s->cur_pkt); s->cur_st = NULL; } } else { /* read next packet */ ret = av_read_packet(s, &s->cur_pkt); if (ret < 0) { if (ret == -EAGAIN) return ret; /* return the last frames, if any */ for(i = 0; i < s->nb_streams; i++) { st = s->streams[i]; if (st->parser) { av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size, NULL, 0, AV_NOPTS_VALUE, AV_NOPTS_VALUE); if (pkt->size) goto got_packet; } } /* no more packets: really terminates parsing */ return ret; } /* convert the packet time stamp units and handle wrapping */ s->cur_pkt.pts = convert_timestamp_units(s, &s->last_pkt_pts, &s->last_pkt_pts_frac, &s->last_pkt_stream_pts, s->cur_pkt.pts); s->cur_pkt.dts = convert_timestamp_units(s, &s->last_pkt_dts, &s->last_pkt_dts_frac, &s->last_pkt_stream_dts, s->cur_pkt.dts); #if 0 if (s->cur_pkt.stream_index == 0) { if (s->cur_pkt.pts != AV_NOPTS_VALUE) printf("PACKET pts=%0.3f\n", (double)s->cur_pkt.pts / AV_TIME_BASE); if (s->cur_pkt.dts != AV_NOPTS_VALUE) printf("PACKET dts=%0.3f\n", (double)s->cur_pkt.dts / AV_TIME_BASE); } #endif /* duration field */ if (s->cur_pkt.duration != 0) { s->cur_pkt.duration = ((int64_t)s->cur_pkt.duration * AV_TIME_BASE * s->pts_num) / s->pts_den; } st = s->streams[s->cur_pkt.stream_index]; s->cur_st = st; s->cur_ptr = s->cur_pkt.data; s->cur_len = s->cur_pkt.size; if (st->need_parsing && !st->parser) { st->parser = av_parser_init(st->codec.codec_id); if (!st->parser) { /* no parser available : just output the raw packets */ st->need_parsing = 0; } } } } } /** * Return the next frame of a stream. The returned packet is valid * until the next av_read_frame() or until av_close_input_file() and * must be freed with av_free_packet. For video, the packet contains * exactly one frame. For audio, it contains an integer number of * frames if each frame has a known fixed size (e.g. PCM or ADPCM * data). If the audio frames have a variable size (e.g. MPEG audio), * then it contains one frame. * * pkt->pts, pkt->dts and pkt->duration are always set to correct * values in AV_TIME_BASE unit (and guessed if the format cannot * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format * has B frames, so it is better to rely on pkt->dts if you do not * decompress the payload. * * Return 0 if OK, < 0 if error or end of file. */ int av_read_frame(AVFormatContext *s, AVPacket *pkt) { AVPacketList *pktl; pktl = s->packet_buffer; if (pktl) { /* read packet from packet buffer, if there is data */ *pkt = pktl->pkt; s->packet_buffer = pktl->next; av_free(pktl); return 0; } else { return av_read_frame_internal(s, pkt); } } /* XXX: suppress the packet queue */ static void flush_packet_queue(AVFormatContext *s) { AVPacketList *pktl; for(;;) { pktl = s->packet_buffer; if (!pktl) break; s->packet_buffer = pktl->next; av_free_packet(&pktl->pkt); av_free(pktl); } } /*******************************************************/ /* seek support */ int av_find_default_stream_index(AVFormatContext *s) { int i; AVStream *st; if (s->nb_streams <= 0) return -1; for(i = 0; i < s->nb_streams; i++) { st = s->streams[i]; if (st->codec.codec_type == CODEC_TYPE_VIDEO) { return i; } } return 0; } /* flush the frame reader */ static void av_read_frame_flush(AVFormatContext *s) { AVStream *st; int i; flush_packet_queue(s); /* free previous packet */ if (s->cur_st) { if (s->cur_st->parser) av_free_packet(&s->cur_pkt); s->cur_st = NULL; } /* fail safe */ s->cur_ptr = NULL; s->cur_len = 0; /* for each stream, reset read state */ for(i = 0; i < s->nb_streams; i++) { st = s->streams[i]; if (st->parser) { av_parser_close(st->parser); st->parser = NULL; } st->cur_dts = 0; /* we set the current DTS to an unspecified origin */ } } /* add a index entry into a sorted list updateing if it is already there */ int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int distance, int flags) { AVIndexEntry *entries, *ie; int index; entries = av_fast_realloc(st->index_entries, (unsigned int*)&st->index_entries_allocated_size, (st->nb_index_entries + 1) * sizeof(AVIndexEntry)); st->index_entries= entries; if(st->nb_index_entries){ index= av_index_search_timestamp(st, timestamp); ie= &entries[index]; if(ie->timestamp != timestamp){ if(ie->timestamp < timestamp){ index++; //index points to next instead of previous entry, maybe nonexistant ie= &st->index_entries[index]; }else assert(index==0); if(index != st->nb_index_entries){ assert(index < st->nb_index_entries); memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index)); } st->nb_index_entries++; } }else{ index= st->nb_index_entries++; ie= &entries[index]; } ie->pos = pos; ie->timestamp = timestamp; ie->min_distance= distance; ie->flags = flags; return index; } /* build an index for raw streams using a parser */ static void av_build_index_raw(AVFormatContext *s) { AVPacket pkt1, *pkt = &pkt1; int ret; AVStream *st; st = s->streams[0]; av_read_frame_flush(s); url_fseek(&s->pb, s->data_offset, SEEK_SET); for(;;) { ret = av_read_frame(s, pkt); if (ret < 0) break; if (pkt->stream_index == 0 && st->parser && (pkt->flags & PKT_FLAG_KEY)) { av_add_index_entry(st, st->parser->frame_offset, pkt->dts, 0, AVINDEX_KEYFRAME); } av_free_packet(pkt); } } /* return TRUE if we deal with a raw stream (raw codec data and parsing needed) */ static int is_raw_stream(AVFormatContext *s) { AVStream *st; if (s->nb_streams != 1) return 0; st = s->streams[0]; if (!st->need_parsing) return 0; return 1; } /* return the largest index entry whose timestamp is <= wanted_timestamp */ int av_index_search_timestamp(AVStream *st, int wanted_timestamp) { AVIndexEntry *entries= st->index_entries; int nb_entries= st->nb_index_entries; int a, b, m; int64_t timestamp; if (nb_entries <= 0) return -1; a = 0; b = nb_entries - 1; while (a < b) { m = (a + b + 1) >> 1; timestamp = entries[m].timestamp; if (timestamp > wanted_timestamp) { b = m - 1; } else { a = m; } } return a; } static int av_seek_frame_generic(AVFormatContext *s, int stream_index, int64_t timestamp) { int index; AVStream *st; AVIndexEntry *ie; if (!s->index_built) { if (is_raw_stream(s)) { av_build_index_raw(s); } else { return -1; } s->index_built = 1; } if (stream_index < 0) stream_index = 0; st = s->streams[stream_index]; index = av_index_search_timestamp(st, timestamp); if (index < 0) return -1; /* now we have found the index, we can seek */ ie = &st->index_entries[index]; av_read_frame_flush(s); url_fseek(&s->pb, ie->pos, SEEK_SET); st->cur_dts = ie->timestamp; return 0; } /** * Seek to the key frame just before the frame at timestamp * 'timestamp' in 'stream_index'. If stream_index is (-1), a default * stream is selected */ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp) { int ret; av_read_frame_flush(s); /* first, we try the format specific seek */ if (s->iformat->read_seek) ret = s->iformat->read_seek(s, stream_index, timestamp); else ret = -1; if (ret >= 0) { return 0; } return av_seek_frame_generic(s, stream_index, timestamp); } /*******************************************************/ /* return TRUE if the stream has accurate timings for at least one component */ //#if 0 McMCC static int av_has_timings(AVFormatContext *ic) { int i; AVStream *st; for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time != AV_NOPTS_VALUE && st->duration != AV_NOPTS_VALUE) return 1; } return 0; } /* estimate the stream timings from the one of each components. Also compute the global bitrate if possible */ static void av_update_stream_timings(AVFormatContext *ic) { int64_t start_time, end_time, end_time1; int i; AVStream *st; start_time = MAXINT64; end_time = MININT64; for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time != AV_NOPTS_VALUE) { if (st->start_time < start_time) start_time = st->start_time; if (st->duration != AV_NOPTS_VALUE) { end_time1 = st->start_time + st->duration; if (end_time1 > end_time) end_time = end_time1; } } } if (start_time != MAXINT64) { ic->start_time = start_time; if (end_time != MAXINT64) { ic->duration = end_time - start_time; if (ic->file_size > 0) { /* compute the bit rate */ ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE / (double)ic->duration; } } } } static void fill_all_stream_timings(AVFormatContext *ic) { int i; AVStream *st; av_update_stream_timings(ic); for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time == AV_NOPTS_VALUE) { st->start_time = ic->start_time; st->duration = ic->duration; } } } static void av_estimate_timings_from_bit_rate(AVFormatContext *ic) { int64_t filesize, duration; int bit_rate, i; AVStream *st; /* if bit_rate is already set, we believe it */ if (ic->bit_rate == 0) { bit_rate = 0; for(i=0;inb_streams;i++) { st = ic->streams[i]; bit_rate += st->codec.bit_rate; } ic->bit_rate = bit_rate; } /* if duration is already set, we believe it */ if (ic->duration == AV_NOPTS_VALUE && ic->bit_rate != 0 && ic->file_size != 0) { filesize = ic->file_size; if (filesize > 0) { duration = (int64_t)((8 * AV_TIME_BASE * (double)filesize) / (double)ic->bit_rate); for(i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time == AV_NOPTS_VALUE || st->duration == AV_NOPTS_VALUE) { st->start_time = 0; st->duration = duration; } } } } } #define DURATION_MAX_READ_SIZE 250000 #if 0 /* only usable for MPEG-PS streams */ static void av_estimate_timings_from_pts(AVFormatContext *ic) { AVPacket pkt1, *pkt = &pkt1; AVStream *st; int read_size, i, ret; int64_t start_time, end_time, end_time1; int64_t filesize, offset, duration; /* free previous packet */ if (ic->cur_st && ic->cur_st->parser) av_free_packet(&ic->cur_pkt); ic->cur_st = NULL; /* flush packet queue */ flush_packet_queue(ic); /* we read the first packets to get the first PTS (not fully accurate, but it is enough now) */ url_fseek(&ic->pb, 0, SEEK_SET); read_size = 0; for(;;) { if (read_size >= DURATION_MAX_READ_SIZE) break; /* if all info is available, we can stop */ for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time == AV_NOPTS_VALUE) break; } if (i == ic->nb_streams) break; ret = av_read_packet(ic, pkt); if (ret != 0) break; read_size += pkt->size; st = ic->streams[pkt->stream_index]; if (pkt->pts != AV_NOPTS_VALUE) { if (st->start_time == AV_NOPTS_VALUE) st->start_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den); } av_free_packet(pkt); } /* we compute the minimum start_time and use it as default */ start_time = MAXINT64; for(i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time != AV_NOPTS_VALUE && st->start_time < start_time) start_time = st->start_time; } if (start_time != MAXINT64) ic->start_time = start_time; /* estimate the end time (duration) */ /* XXX: may need to support wrapping */ filesize = ic->file_size; offset = filesize - DURATION_MAX_READ_SIZE; if (offset < 0) offset = 0; url_fseek(&ic->pb, offset, SEEK_SET); read_size = 0; for(;;) { if (read_size >= DURATION_MAX_READ_SIZE) break; /* if all info is available, we can stop */ for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->duration == AV_NOPTS_VALUE) break; } if (i == ic->nb_streams) break; ret = av_read_packet(ic, pkt); if (ret != 0) break; read_size += pkt->size; st = ic->streams[pkt->stream_index]; if (pkt->pts != AV_NOPTS_VALUE) { end_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den); duration = end_time - st->start_time; if (duration > 0) { if (st->duration == AV_NOPTS_VALUE || st->duration < duration) st->duration = duration; } } av_free_packet(pkt); } /* estimate total duration */ end_time = MININT64; for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->duration != AV_NOPTS_VALUE) { end_time1 = st->start_time + st->duration; if (end_time1 > end_time) end_time = end_time1; } } /* update start_time (new stream may have been created, so we do it at the end */ if (ic->start_time != AV_NOPTS_VALUE) { for(i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time == AV_NOPTS_VALUE) st->start_time = ic->start_time; } } if (end_time != MININT64) { /* put dummy values for duration if needed */ for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->duration == AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE) st->duration = end_time - st->start_time; } ic->duration = end_time - ic->start_time; } url_fseek(&ic->pb, 0, SEEK_SET); } #endif static void av_estimate_timings(AVFormatContext *ic) { URLContext *h; int64_t file_size; /* get the file size, if possible */ if (ic->iformat->flags & AVFMT_NOFILE) { file_size = 0; } else { h = url_fileno(&ic->pb); file_size = url_filesize(h); if (file_size < 0) file_size = 0; } ic->file_size = file_size; #if 0 if (ic->iformat == &mpegps_demux) { /* get accurate estimate from the PTSes */ av_estimate_timings_from_pts(ic); } else #endif if (av_has_timings(ic)) { /* at least one components has timings - we use them for all the components */ fill_all_stream_timings(ic); } else { /* less precise: use bit rate info */ av_estimate_timings_from_bit_rate(ic); } av_update_stream_timings(ic); #if 0 { int i; AVStream *st; for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; printf("%d: start_time: %0.3f duration: %0.3f\n", i, (double)st->start_time / AV_TIME_BASE, (double)st->duration / AV_TIME_BASE); } printf("stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n", (double)ic->start_time / AV_TIME_BASE, (double)ic->duration / AV_TIME_BASE, ic->bit_rate / 1000); } #endif } static int has_codec_parameters(AVCodecContext *enc) { int val; switch(enc->codec_type) { case CODEC_TYPE_AUDIO: val = enc->sample_rate; break; case CODEC_TYPE_VIDEO: val = enc->width; break; default: val = 1; break; } return (val != 0); } static int try_decode_frame(AVStream *st, const uint8_t *data, int size) { int16_t *samples; AVCodec *codec; int got_picture, ret; AVFrame picture; codec = avcodec_find_decoder(st->codec.codec_id); if (!codec) return -1; ret = avcodec_open(&st->codec, codec); if (ret < 0) return ret; switch(st->codec.codec_type) { case CODEC_TYPE_VIDEO: ret = avcodec_decode_video(&st->codec, &picture, &got_picture, (uint8_t *)data, size); break; case CODEC_TYPE_AUDIO: samples = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); if (!samples) goto fail; ret = avcodec_decode_audio(&st->codec, samples, &got_picture, (uint8_t *)data, size); av_free(samples); break; default: break; } fail: avcodec_close(&st->codec); return ret; } /* absolute maximum size we read until we abort */ #define MAX_READ_SIZE 5000000 /* maximum duration until we stop analysing the stream */ #define MAX_STREAM_DURATION ((int)(AV_TIME_BASE * 1.0)) /** * Read the beginning of a media file to get stream information. This * is useful for file formats with no headers such as MPEG. This * function also compute the real frame rate in case of mpeg2 repeat * frame mode. * * @param ic media file handle * @return >=0 if OK. AVERROR_xxx if error. */ int av_find_stream_info(AVFormatContext *ic) { int i, count, ret, read_size; AVStream *st; AVPacket pkt1, *pkt; AVPacketList *pktl=NULL, **ppktl; count = 0; read_size = 0; ppktl = &ic->packet_buffer; for(;;) { /* check if one codec still needs to be handled */ for(i=0;inb_streams;i++) { st = ic->streams[i]; if (!has_codec_parameters(&st->codec)) break; } if (i == ic->nb_streams) { /* NOTE: if the format has no header, then we need to read some packets to get most of the streams, so we cannot stop here */ if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) { /* if we found the info for all the codecs, we can stop */ ret = count; break; } } else { /* we did not get all the codec info, but we read too much data */ if (read_size >= MAX_READ_SIZE) { ret = count; break; } } /* NOTE: a new stream can be added there if no header in file (AVFMTCTX_NOHEADER) */ ret = av_read_frame_internal(ic, &pkt1); if (ret < 0) { /* EOF or error */ ret = -1; /* we could not have all the codec parameters before EOF */ if ((ic->ctx_flags & AVFMTCTX_NOHEADER) && i == ic->nb_streams) ret = 0; break; } pktl = av_mallocz(sizeof(AVPacketList)); if (!pktl) { ret = AVERROR_NOMEM; break; } /* add the packet in the buffered packet list */ *ppktl = pktl; ppktl = &pktl->next; pkt = &pktl->pkt; *pkt = pkt1; /* duplicate the packet */ if (av_dup_packet(pkt) < 0) { ret = AVERROR_NOMEM; break; } read_size += pkt->size; st = ic->streams[pkt->stream_index]; st->codec_info_duration += pkt->duration; if (pkt->duration != 0) st->codec_info_nb_frames++; /* if still no information, we try to open the codec and to decompress the frame. We try to avoid that in most cases as it takes longer and uses more memory. For MPEG4, we need to decompress for Quicktime. */ if (!has_codec_parameters(&st->codec) && (st->codec.codec_id == CODEC_ID_FLV1 || st->codec.codec_id == CODEC_ID_H264 || st->codec.codec_id == CODEC_ID_H263 || (st->codec.codec_id == CODEC_ID_MPEG4 && !st->need_parsing))) try_decode_frame(st, pkt->data, pkt->size); if (st->codec_info_duration >= MAX_STREAM_DURATION) { break; } count++; } /* set real frame rate info */ for(i=0;inb_streams;i++) { st = ic->streams[i]; if (st->codec.codec_type == CODEC_TYPE_VIDEO) { /* compute the real frame rate for telecine */ if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO || st->codec.codec_id == CODEC_ID_MPEG2VIDEO) && st->codec.sub_id == 2) { if (st->codec_info_nb_frames >= 20) { float coded_frame_rate, est_frame_rate; est_frame_rate = ((double)st->codec_info_nb_frames * AV_TIME_BASE) / (double)st->codec_info_duration ; coded_frame_rate = (double)st->codec.frame_rate / (double)st->codec.frame_rate_base; #if 0 printf("telecine: coded_frame_rate=%0.3f est_frame_rate=%0.3f\n", coded_frame_rate, est_frame_rate); #endif /* if we detect that it could be a telecine, we signal it. It would be better to do it at a higher level as it can change in a film */ if (coded_frame_rate >= 24.97 && (est_frame_rate >= 23.5 && est_frame_rate < 24.5)) { st->r_frame_rate = 24024; st->r_frame_rate_base = 1001; } } } /* if no real frame rate, use the codec one */ if (!st->r_frame_rate){ st->r_frame_rate = st->codec.frame_rate; st->r_frame_rate_base = st->codec.frame_rate_base; } } } av_estimate_timings(ic); return ret; } //McMCC /*******************************************************/ /** * start playing a network based stream (e.g. RTSP stream) at the * current position */ int av_read_play(AVFormatContext *s) { if (!s->iformat->read_play) return AVERROR_NOTSUPP; return s->iformat->read_play(s); } /** * pause a network based stream (e.g. RTSP stream). Use av_read_play() * to resume it. */ int av_read_pause(AVFormatContext *s) { if (!s->iformat->read_pause) return AVERROR_NOTSUPP; return s->iformat->read_pause(s); } /** * Close a media file (but not its codecs) * * @param s media file handle */ void av_close_input_file(AVFormatContext *s) { int i, must_open_file; AVStream *st; /* free previous packet */ if (s->cur_st && s->cur_st->parser) av_free_packet(&s->cur_pkt); if (s->iformat->read_close) s->iformat->read_close(s); for(i=0;inb_streams;i++) { /* free all data in a stream component */ st = s->streams[i]; if (st->parser) { av_parser_close(st->parser); } av_free(st->index_entries); av_free(st); } flush_packet_queue(s); must_open_file = 1; if (s->iformat->flags & AVFMT_NOFILE) { must_open_file = 0; } if (must_open_file) { url_fclose(&s->pb); } av_freep(&s->priv_data); av_free(s); } /** * Add a new stream to a media file. Can only be called in the * read_header function. If the flag AVFMTCTX_NOHEADER is in the * format context, then new streams can be added in read_packet too. * * * @param s media file handle * @param id file format dependent stream id */ AVStream *av_new_stream(AVFormatContext *s, int id) { AVStream *st; if (s->nb_streams >= MAX_STREAMS) return NULL; st = av_mallocz(sizeof(AVStream)); if (!st) return NULL; avcodec_get_context_defaults(&st->codec); if (s->iformat) { /* no default bitrate if decoding */ st->codec.bit_rate = 0; } st->index = s->nb_streams; st->id = id; st->start_time = AV_NOPTS_VALUE; st->duration = AV_NOPTS_VALUE; s->streams[s->nb_streams++] = st; return st; } /************************************************************/ /* output media file */ int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap) { int ret; if (s->oformat->priv_data_size > 0) { s->priv_data = av_mallocz(s->oformat->priv_data_size); if (!s->priv_data) return AVERROR_NOMEM; } else s->priv_data = NULL; if (s->oformat->set_parameters) { ret = s->oformat->set_parameters(s, ap); if (ret < 0) return ret; } return 0; } /** * allocate the stream private data and write the stream header to an * output media file * * @param s media file handle * @return 0 if OK. AVERROR_xxx if error. */ int av_write_header(AVFormatContext *s) { int ret, i; AVStream *st; /* default pts settings is MPEG like */ av_set_pts_info(s, 33, 1, 90000); ret = s->oformat->write_header(s); if (ret < 0) return ret; /* init PTS generation */ for(i=0;inb_streams;i++) { st = s->streams[i]; switch (st->codec.codec_type) { case CODEC_TYPE_AUDIO: av_frac_init(&st->pts, 0, 0, (int64_t)s->pts_num * st->codec.sample_rate); break; case CODEC_TYPE_VIDEO: av_frac_init(&st->pts, 0, 0, (int64_t)s->pts_num * st->codec.frame_rate); break; default: break; } } return 0; } /** * Write a packet to an output media file. The packet shall contain * one audio or video frame. * * @param s media file handle * @param stream_index stream index * @param buf buffer containing the frame data * @param size size of buffer * @return < 0 if error, = 0 if OK, 1 if end of stream wanted. */ int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf, int size) { AVStream *st; int64_t pts_mask; int ret, frame_size; st = s->streams[stream_index]; pts_mask = (1LL << s->pts_wrap_bits) - 1; ret = s->oformat->write_packet(s, stream_index, buf, size, st->pts.val & pts_mask); if (ret < 0) return ret; /* update pts */ switch (st->codec.codec_type) { case CODEC_TYPE_AUDIO: frame_size = get_audio_frame_size(&st->codec, size); if (frame_size >= 0) { av_frac_add(&st->pts, (int64_t)s->pts_den * frame_size); } break; case CODEC_TYPE_VIDEO: av_frac_add(&st->pts, (int64_t)s->pts_den * st->codec.frame_rate_base); break; default: break; } return ret; } /** * write the stream trailer to an output media file and and free the * file private data. * * @param s media file handle * @return 0 if OK. AVERROR_xxx if error. */ int av_write_trailer(AVFormatContext *s) { int ret; ret = s->oformat->write_trailer(s); av_freep(&s->priv_data); return ret; } /* "user interface" functions */ void dump_format(AVFormatContext *ic, int index, const char *url, int is_output) { int i, flags; char buf[256]; fprintf(stderr, "%s #%d, %s, %s '%s':\n", is_output ? "Output" : "Input", index, is_output ? ic->oformat->name : ic->iformat->name, is_output ? "to" : "from", url); if (!is_output) { fprintf(stderr, " Duration: "); if (ic->duration != AV_NOPTS_VALUE) { int hours, mins, secs, us; secs = ic->duration / AV_TIME_BASE; us = ic->duration % AV_TIME_BASE; mins = secs / 60; secs %= 60; hours = mins / 60; mins %= 60; fprintf(stderr, "%02d:%02d:%02d.%01d", hours, mins, secs, (10 * us) / AV_TIME_BASE); } else { fprintf(stderr, "N/A"); } fprintf(stderr, ", bitrate: "); if (ic->bit_rate) { fprintf(stderr,"%d kb/s", ic->bit_rate / 1000); } else { fprintf(stderr, "N/A"); } fprintf(stderr, "\n"); } for(i=0;inb_streams;i++) { AVStream *st = ic->streams[i]; avcodec_string(buf, sizeof(buf), &st->codec, is_output); fprintf(stderr, " Stream #%d.%d", index, i); /* the pid is an important information, so we display it */ /* XXX: add a generic system */ if (is_output) flags = ic->oformat->flags; else flags = ic->iformat->flags; if (flags & AVFMT_SHOW_IDS) { fprintf(stderr, "[0x%x]", st->id); } fprintf(stderr, ": %s\n", buf); } } typedef struct { const char *abv; int width, height; int frame_rate, frame_rate_base; } AbvEntry; static AbvEntry frame_abvs[] = { { "ntsc", 720, 480, 30000, 1001 }, { "pal", 720, 576, 25, 1 }, { "qntsc", 352, 240, 30000, 1001 }, /* VCD compliant ntsc */ { "qpal", 352, 288, 25, 1 }, /* VCD compliant pal */ { "sntsc", 640, 480, 30000, 1001 }, /* square pixel ntsc */ { "spal", 768, 576, 25, 1 }, /* square pixel pal */ { "film", 352, 240, 24, 1 }, { "ntsc-film", 352, 240, 24000, 1001 }, { "sqcif", 128, 96, 0, 0 }, { "qcif", 176, 144, 0, 0 }, { "cif", 352, 288, 0, 0 }, { "4cif", 704, 576, 0, 0 }, }; int parse_image_size(int *width_ptr, int *height_ptr, const char *str) { int i; int n = sizeof(frame_abvs) / sizeof(AbvEntry); const char *p; int frame_width = 0, frame_height = 0; for(i=0;i 0) lastch = datestr[len - 1]; else lastch = '\0'; is_utc = (lastch == 'z' || lastch == 'Z'); memset(&dt, 0, sizeof(dt)); p = datestr; q = NULL; if (!duration) { for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) { q = small_strptime(p, date_fmt[i], &dt); if (q) { break; } } if (!q) { if (is_utc) { dt = *gmtime(&now); } else { dt = *localtime(&now); } dt.tm_hour = dt.tm_min = dt.tm_sec = 0; } else { p = q; } if (*p == 'T' || *p == 't' || *p == ' ') p++; for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) { q = small_strptime(p, time_fmt[i], &dt); if (q) { break; } } } else { q = small_strptime(p, time_fmt[0], &dt); if (!q) { dt.tm_sec = strtol(p, (char **)&q, 10); dt.tm_min = 0; dt.tm_hour = 0; } } /* Now we have all the fields that we can get */ if (!q) { if (duration) return 0; else return now * int64_t_C(1000000); } if (duration) { t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; } else { dt.tm_isdst = -1; /* unknown */ if (is_utc) { t = mktimegm(&dt); } else { t = mktime(&dt); } } t *= 1000000; if (*q == '.') { int val, n; q++; for (val = 0, n = 100000; n >= 1; n /= 10, q++) { if (!isdigit(*q)) break; val += n * (*q - '0'); } t += val; } return t; } /* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. Return 1 if found */ int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) { const char *p; char tag[128], *q; p = info; if (*p == '?') p++; for(;;) { q = tag; while (*p != '\0' && *p != '=' && *p != '&') { if ((q - tag) < sizeof(tag) - 1) *q++ = *p; p++; } *q = '\0'; q = arg; if (*p == '=') { p++; while (*p != '&' && *p != '\0') { if ((q - arg) < arg_size - 1) { if (*p == '+') *q++ = ' '; else *q++ = *p; } p++; } *q = '\0'; } if (!strcmp(tag, tag1)) return 1; if (*p != '&') break; p++; } return 0; } /* Return in 'buf' the path with '%d' replaced by number. Also handles the '%0nd' format where 'n' is the total number of digits and '%%'. Return 0 if OK, and -1 if format error */ int get_frame_filename(char *buf, int buf_size, const char *path, int number) { const char *p; char *q, buf1[20], c; int nd, len, percentd_found; q = buf; p = path; percentd_found = 0; for(;;) { c = *p++; if (c == '\0') break; if (c == '%') { do { nd = 0; while (isdigit(*p)) { nd = nd * 10 + *p++ - '0'; } c = *p++; } while (isdigit(c)); switch(c) { case '%': goto addchar; case 'd': if (percentd_found) goto fail; percentd_found = 1; snprintf(buf1, sizeof(buf1), "%0*d", nd, number); len = strlen(buf1); if ((q - buf + len) > buf_size - 1) goto fail; memcpy(q, buf1, len); q += len; break; default: goto fail; } } else { addchar: if ((q - buf) < buf_size - 1) *q++ = c; } } if (!percentd_found) goto fail; *q = '\0'; return 0; fail: *q = '\0'; return -1; } /** * Print nice hexa dump of a buffer * @param f stream for output * @param buf buffer * @param size buffer size */ void av_hex_dump(FILE *f, uint8_t *buf, int size) { int len, i, j, c; for(i=0;i 16) len = 16; fprintf(f, "%08x ", i); for(j=0;j<16;j++) { if (j < len) fprintf(f, " %02x", buf[i+j]); else fprintf(f, " "); } fprintf(f, " "); for(j=0;j '~') c = '.'; fprintf(f, "%c", c); } fprintf(f, "\n"); } } /** * Print on 'f' a nice dump of a packet * @param f stream for output * @param pkt packet to dump * @param dump_payload true if the payload must be displayed too */ void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload) { fprintf(f, "stream #%d:\n", pkt->stream_index); fprintf(f, " keyframe=%d\n", ((pkt->flags & PKT_FLAG_KEY) != 0)); fprintf(f, " duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE); /* DTS is _always_ valid after av_read_frame() */ fprintf(f, " dts="); if (pkt->dts == AV_NOPTS_VALUE) fprintf(f, "N/A"); else fprintf(f, "%0.3f", (double)pkt->dts / AV_TIME_BASE); /* PTS may be not known if B frames are present */ fprintf(f, " pts="); if (pkt->pts == AV_NOPTS_VALUE) fprintf(f, "N/A"); else fprintf(f, "%0.3f", (double)pkt->pts / AV_TIME_BASE); fprintf(f, "\n"); fprintf(f, " size=%d\n", pkt->size); if (dump_payload) av_hex_dump(f, pkt->data, pkt->size); } void url_split(char *proto, int proto_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url) { const char *p; char *q; int port; port = -1; p = url; q = proto; while (*p != ':' && *p != '\0') { if ((q - proto) < proto_size - 1) *q++ = *p; p++; } if (proto_size > 0) *q = '\0'; if (*p == '\0') { if (proto_size > 0) proto[0] = '\0'; if (hostname_size > 0) hostname[0] = '\0'; p = url; } else { p++; if (*p == '/') p++; if (*p == '/') p++; q = hostname; while (*p != ':' && *p != '/' && *p != '?' && *p != '\0') { if ((q - hostname) < hostname_size - 1) *q++ = *p; p++; } if (hostname_size > 0) *q = '\0'; if (*p == ':') { p++; port = strtoul(p, (char **)&p, 10); } } if (port_ptr) *port_ptr = port; pstrcpy(path, path_size, p); } /** * Set the pts for a given stream * @param s stream * @param pts_wrap_bits number of bits effectively used by the pts * (used for wrap control, 33 is the value for MPEG) * @param pts_num numerator to convert to seconds (MPEG: 1) * @param pts_den denominator to convert to seconds (MPEG: 90000) */ void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits, int pts_num, int pts_den) { s->pts_wrap_bits = pts_wrap_bits; s->pts_num = pts_num; s->pts_den = pts_den; } /* fraction handling */ /** * f = val + (num / den) + 0.5. 'num' is normalized so that it is such * as 0 <= num < den. * * @param f fractional number * @param val integer value * @param num must be >= 0 * @param den must be >= 1 */ void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) { num += (den >> 1); if (num >= den) { val += num / den; num = num % den; } f->val = val; f->num = num; f->den = den; } /* set f to (val + 0.5) */ void av_frac_set(AVFrac *f, int64_t val) { f->val = val; f->num = f->den >> 1; } /** * Fractionnal addition to f: f = f + (incr / f->den) * * @param f fractional number * @param incr increment, can be positive or negative */ void av_frac_add(AVFrac *f, int64_t incr) { int64_t num, den; num = f->num + incr; den = f->den; if (num < 0) { f->val += num / den; num = num % den; if (num < 0) { num += den; f->val--; } } else if (num >= den) { f->val += num / den; num = num % den; } f->num = num; } /** * register a new image format * @param img_fmt Image format descriptor */ void av_register_image_format(AVImageFormat *img_fmt) { AVImageFormat **p; p = &first_image_format; while (*p != NULL) p = &(*p)->next; *p = img_fmt; img_fmt->next = NULL; } /* guess image format */ AVImageFormat *av_probe_image_format(AVProbeData *pd) { AVImageFormat *fmt1, *fmt; int score, score_max; fmt = NULL; score_max = 0; for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) { if (fmt1->img_probe) { score = fmt1->img_probe(pd); if (score > score_max) { score_max = score; fmt = fmt1; } } } return fmt; } AVImageFormat *guess_image_format(const char *filename) { AVImageFormat *fmt1; for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) { if (fmt1->extensions && match_ext(filename, fmt1->extensions)) return fmt1; } return NULL; } /** * Read an image from a stream. * @param gb byte stream containing the image * @param fmt image format, NULL if probing is required */ int av_read_image(ByteIOContext *pb, const char *filename, AVImageFormat *fmt, int (*alloc_cb)(void *, AVImageInfo *info), void *opaque) { unsigned char buf[PROBE_BUF_SIZE]; AVProbeData probe_data, *pd = &probe_data; offset_t pos; int ret; if (!fmt) { pd->filename = filename; pd->buf = buf; pos = url_ftell(pb); pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE); url_fseek(pb, pos, SEEK_SET); fmt = av_probe_image_format(pd); } if (!fmt) return AVERROR_NOFMT; ret = fmt->img_read(pb, alloc_cb, opaque); return ret; } /** * Write an image to a stream. * @param pb byte stream for the image output * @param fmt image format * @param img image data and informations */ int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img) { return fmt->img_write(pb, img); } xmms-wma-1.0.5/ffmpeg-strip-wma/avi.h0000644000175000017500000000255307753756601017711 0ustar whistlerwhistler#ifndef FFMPEG_AVI_H #define FFMPEG_AVI_H #include "avcodec.h" #define AVIF_HASINDEX 0x00000010 // Index at end of file? #define AVIF_MUSTUSEINDEX 0x00000020 #define AVIF_ISINTERLEAVED 0x00000100 #define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames? #define AVIF_WASCAPTUREFILE 0x00010000 #define AVIF_COPYRIGHTED 0x00020000 #define AVI_MAX_RIFF_SIZE 0x40000000LL #define AVI_MASTER_INDEX_SIZE 256 /* index flags */ #define AVIIF_INDEX 0x10 offset_t start_tag(ByteIOContext *pb, const char *tag); void end_tag(ByteIOContext *pb, offset_t start); typedef struct CodecTag { int id; unsigned int tag; unsigned int invalid_asf : 1; } CodecTag; void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf); int put_wav_header(ByteIOContext *pb, AVCodecContext *enc); int wav_codec_get_id(unsigned int tag, int bps); void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size); extern const CodecTag codec_bmp_tags[]; extern const CodecTag codec_wav_tags[]; unsigned int codec_get_tag(const CodecTag *tags, int id); enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag); unsigned int codec_get_bmp_tag(int id); unsigned int codec_get_wav_tag(int id); enum CodecID codec_get_bmp_id(unsigned int tag); enum CodecID codec_get_wav_id(unsigned int tag); #endif /* FFMPEG_AVI_H */ xmms-wma-1.0.5/ffmpeg-strip-wma/avio.h0000644000175000017500000001274607736341526020072 0ustar whistlerwhistler#ifndef AVIO_H #define AVIO_H /* output byte stream handling */ typedef int64_t offset_t; /* unbuffered I/O */ struct URLContext { struct URLProtocol *prot; int flags; int is_streamed; /* true if streamed (no seek possible), default = false */ int max_packet_size; /* if non zero, the stream is packetized with this max packet size */ void *priv_data; char filename[1]; /* specified filename */ }; typedef struct URLContext URLContext; typedef struct URLPollEntry { URLContext *handle; int events; int revents; } URLPollEntry; #define URL_RDONLY 0 #define URL_WRONLY 1 #define URL_RDWR 2 typedef int URLInterruptCB(void); int url_open(URLContext **h, const char *filename, int flags); int url_read(URLContext *h, unsigned char *buf, int size); int url_write(URLContext *h, unsigned char *buf, int size); offset_t url_seek(URLContext *h, offset_t pos, int whence); int url_close(URLContext *h); int url_exist(const char *filename); offset_t url_filesize(URLContext *h); int url_get_max_packet_size(URLContext *h); void url_get_filename(URLContext *h, char *buf, int buf_size); /* the callback is called in blocking functions to test regulary if asynchronous interruption is needed. -EINTR is returned in this case by the interrupted function. 'NULL' means no interrupt callback is given. */ void url_set_interrupt_cb(URLInterruptCB *interrupt_cb); /* not implemented */ int url_poll(URLPollEntry *poll_table, int n, int timeout); typedef struct URLProtocol { const char *name; int (*url_open)(URLContext *h, const char *filename, int flags); int (*url_read)(URLContext *h, unsigned char *buf, int size); int (*url_write)(URLContext *h, unsigned char *buf, int size); offset_t (*url_seek)(URLContext *h, offset_t pos, int whence); int (*url_close)(URLContext *h); struct URLProtocol *next; } URLProtocol; extern URLProtocol *first_protocol; extern URLInterruptCB *url_interrupt_cb; int register_protocol(URLProtocol *protocol); typedef struct { unsigned char *buffer; int buffer_size; unsigned char *buf_ptr, *buf_end; void *opaque; int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); void (*write_packet)(void *opaque, uint8_t *buf, int buf_size); int (*seek)(void *opaque, offset_t offset, int whence); offset_t pos; /* position in the file of the current buffer */ int must_flush; /* true if the next seek should flush */ int eof_reached; /* true if eof reached */ int write_flag; /* true if open for writing */ int is_streamed; int max_packet_size; } ByteIOContext; int init_put_byte(ByteIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), void (*write_packet)(void *opaque, uint8_t *buf, int buf_size), int (*seek)(void *opaque, offset_t offset, int whence)); void put_byte(ByteIOContext *s, int b); void put_buffer(ByteIOContext *s, const unsigned char *buf, int size); void put_le64(ByteIOContext *s, uint64_t val); void put_be64(ByteIOContext *s, uint64_t val); void put_le32(ByteIOContext *s, unsigned int val); void put_be32(ByteIOContext *s, unsigned int val); void put_le16(ByteIOContext *s, unsigned int val); void put_be16(ByteIOContext *s, unsigned int val); void put_tag(ByteIOContext *s, const char *tag); void put_be64_double(ByteIOContext *s, double val); void put_strz(ByteIOContext *s, const char *buf); offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence); void url_fskip(ByteIOContext *s, offset_t offset); offset_t url_ftell(ByteIOContext *s); int url_feof(ByteIOContext *s); #define URL_EOF (-1) int url_fgetc(ByteIOContext *s); #ifdef __GNUC__ int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); #else int url_fprintf(ByteIOContext *s, const char *fmt, ...); #endif char *url_fgets(ByteIOContext *s, char *buf, int buf_size); void put_flush_packet(ByteIOContext *s); int get_buffer(ByteIOContext *s, unsigned char *buf, int size); int get_byte(ByteIOContext *s); unsigned int get_le32(ByteIOContext *s); uint64_t get_le64(ByteIOContext *s); unsigned int get_le16(ByteIOContext *s); double get_be64_double(ByteIOContext *s); char *get_strz(ByteIOContext *s, char *buf, int maxlen); unsigned int get_be16(ByteIOContext *s); unsigned int get_be32(ByteIOContext *s); uint64_t get_be64(ByteIOContext *s); static inline int url_is_streamed(ByteIOContext *s) { return s->is_streamed; } int url_fdopen(ByteIOContext *s, URLContext *h); int url_setbufsize(ByteIOContext *s, int buf_size); int url_fopen(ByteIOContext *s, const char *filename, int flags); int url_fclose(ByteIOContext *s); URLContext *url_fileno(ByteIOContext *s); int url_fget_max_packet_size(ByteIOContext *s); int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags); int url_close_buf(ByteIOContext *s); int url_open_dyn_buf(ByteIOContext *s); int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size); int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer); /* file.c */ extern URLProtocol file_protocol; extern URLProtocol pipe_protocol; /* udp.c */ extern URLProtocol udp_protocol; int udp_set_remote_url(URLContext *h, const char *uri); int udp_get_local_port(URLContext *h); int udp_get_file_handle(URLContext *h); /* tcp.c */ extern URLProtocol tcp_protocol; /* http.c */ extern URLProtocol http_protocol; #endif xmms-wma-1.0.5/ffmpeg-strip-wma/common.c0000644000175000017500000002540710007011032020360 0ustar whistlerwhistler/* * Common bit i/o utils * Copyright (c) 2000, 2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * alternative bitstream reader & writer by Michael Niedermayer */ /** * @file common.c * common internal api. */ #include "avcodec.h" const uint8_t ff_sqrt_tab[128]={ 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11 }; const uint8_t ff_log2_tab[256]={ 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 }; void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) { s->buf = buffer; s->buf_end = s->buf + buffer_size; #ifdef ALT_BITSTREAM_WRITER s->index=0; ((uint32_t*)(s->buf))[0]=0; // memset(buffer, 0, buffer_size); #else s->buf_ptr = s->buf; s->bit_left=32; s->bit_buf=0; #endif } //#ifdef CONFIG_ENCODERS #if 1 /* return the number of bits output */ int get_bit_count(PutBitContext *s) { #ifdef ALT_BITSTREAM_WRITER return s->index; #else return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; #endif } void align_put_bits(PutBitContext *s) { #ifdef ALT_BITSTREAM_WRITER put_bits(s,( - s->index) & 7,0); #else put_bits(s,s->bit_left & 7,0); #endif } #endif //CONFIG_ENCODERS /* pad the end of the output stream with zeros */ void flush_put_bits(PutBitContext *s) { #ifdef ALT_BITSTREAM_WRITER align_put_bits(s); #else s->bit_buf<<= s->bit_left; while (s->bit_left < 32) { /* XXX: should test end of buffer */ *s->buf_ptr++=s->bit_buf >> 24; s->bit_buf<<=8; s->bit_left+=8; } s->bit_left=32; s->bit_buf=0; #endif } #ifdef CONFIG_ENCODERS void put_string(PutBitContext * pbc, char *s) { while(*s){ put_bits(pbc, 8, *s); s++; } put_bits(pbc, 8, 0); } /* bit input functions */ #endif //CONFIG_ENCODERS /** * init GetBitContext. * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end * @param bit_size the size of the buffer in bits */ void init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size) { const int buffer_size= (bit_size+7)>>3; s->buffer= buffer; s->size_in_bits= bit_size; s->buffer_end= buffer + buffer_size; #ifdef ALT_BITSTREAM_READER s->index=0; #elif defined LIBMPEG2_BITSTREAM_READER #ifdef LIBMPEG2_BITSTREAM_READER_HACK if ((int)buffer&1) { /* word alignment */ s->cache = (*buffer++)<<24; s->buffer_ptr = buffer; s->bit_count = 16-8; } else #endif { s->buffer_ptr = buffer; s->bit_count = 16; s->cache = 0; } #elif defined A32_BITSTREAM_READER s->buffer_ptr = (uint32_t*)buffer; s->bit_count = 32; s->cache0 = 0; s->cache1 = 0; #endif { OPEN_READER(re, s) UPDATE_CACHE(re, s) UPDATE_CACHE(re, s) CLOSE_READER(re, s) } #ifdef A32_BITSTREAM_READER s->cache1 = 0; #endif } /** * reads 0-32 bits. */ unsigned int get_bits_long(GetBitContext *s, int n){ if(n<=17) return get_bits(s, n); else{ int ret= get_bits(s, 16) << (n-16); return ret | get_bits(s, n-16); } } /** * shows 0-32 bits. */ unsigned int show_bits_long(GetBitContext *s, int n){ if(n<=17) return show_bits(s, n); else{ GetBitContext gb= *s; int ret= get_bits_long(s, n); *s= gb; return ret; } } void align_get_bits(GetBitContext *s) { int n= (-get_bits_count(s)) & 7; if(n) skip_bits(s, n); } int check_marker(GetBitContext *s, const char *msg) { int bit= get_bits1(s); if(!bit) av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg); return bit; } /* VLC decoding */ //#define DEBUG_VLC #define GET_DATA(v, table, i, wrap, size) \ {\ const uint8_t *ptr = (const uint8_t *)table + i * wrap;\ switch(size) {\ case 1:\ v = *(const uint8_t *)ptr;\ break;\ case 2:\ v = *(const uint16_t *)ptr;\ break;\ default:\ v = *(const uint32_t *)ptr;\ break;\ }\ } static int alloc_table(VLC *vlc, int size) { int index; index = vlc->table_size; vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { vlc->table_allocated += (1 << vlc->bits); vlc->table = av_realloc(vlc->table, sizeof(VLC_TYPE) * 2 * vlc->table_allocated); if (!vlc->table) return -1; } return index; } static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, uint32_t code_prefix, int n_prefix) { int i, j, k, n, table_size, table_index, nb, n1, index; uint32_t code; VLC_TYPE (*table)[2]; table_size = 1 << table_nb_bits; table_index = alloc_table(vlc, table_size); #ifdef DEBUG_VLC printf("new table index=%d size=%d code_prefix=%x n=%d\n", table_index, table_size, code_prefix, n_prefix); #endif if (table_index < 0) return -1; table = &vlc->table[table_index]; for(i=0;i 0 && (code >> n) == code_prefix) { if (n <= table_nb_bits) { /* no need to add another table */ j = (code << (table_nb_bits - n)) & (table_size - 1); nb = 1 << (table_nb_bits - n); for(k=0;k> n) & ((1 << table_nb_bits) - 1); #ifdef DEBUG_VLC printf("%4x: n=%d (subtable)\n", j, n); #endif /* compute table size */ n1 = -table[j][1]; //bits if (n > n1) n1 = n; table[j][1] = -n1; //bits } } } /* second pass : fill auxillary tables recursively */ for(i=0;i table_nb_bits) { n = table_nb_bits; table[i][1] = -n; //bits } index = build_table(vlc, n, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, (code_prefix << table_nb_bits) | i, n_prefix + table_nb_bits); if (index < 0) return -1; /* note: realloc has been done, so reload tables */ table = &vlc->table[table_index]; table[i][0] = index; //code } } return table_index; } /* Build VLC decoding tables suitable for use with get_vlc(). 'nb_bits' set thee decoding table size (2^nb_bits) entries. The bigger it is, the faster is the decoding. But it should not be too big to save memory and L1 cache. '9' is a good compromise. 'nb_codes' : number of vlcs codes 'bits' : table which gives the size (in bits) of each vlc code. 'codes' : table which gives the bit pattern of of each vlc code. 'xxx_wrap' : give the number of bytes between each entry of the 'bits' or 'codes' tables. 'xxx_size' : gives the number of bytes of each entry of the 'bits' or 'codes' tables. 'wrap' and 'size' allows to use any memory configuration and types (byte/word/long) to store the 'bits' and 'codes' tables. */ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size) { vlc->bits = nb_bits; vlc->table = NULL; vlc->table_allocated = 0; vlc->table_size = 0; #ifdef DEBUG_VLC printf("build table nb_codes=%d\n", nb_codes); #endif if (build_table(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, 0, 0) < 0) { av_free(vlc->table); return -1; } return 0; } void free_vlc(VLC *vlc) { av_free(vlc->table); } int64_t ff_gcd(int64_t a, int64_t b){ if(b) return ff_gcd(b, a%b); else return a; } xmms-wma-1.0.5/ffmpeg-strip-wma/file.c0000644000175000017500000000565107767121045020037 0ustar whistlerwhistler/* * Buffered file io for ffmpeg system * Copyright (c) 2001 Fabrice Bellard * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avformat.h" #include #ifndef CONFIG_WIN32 #include #include #include #else #include #define open(fname,oflag,pmode) _open(fname,oflag,pmode) #endif /* CONFIG_WIN32 */ /* standard file protocol */ static int file_open(URLContext *h, const char *filename, int flags) { int access; int fd; strstart(filename, "file:", &filename); if (flags & URL_WRONLY) { access = O_CREAT | O_TRUNC | O_WRONLY; } else { access = O_RDONLY; } #if defined(CONFIG_WIN32) || defined(CONFIG_OS2) || defined(__CYGWIN__) access |= O_BINARY; #endif fd = open(filename, access, 0666); if (fd < 0) return -ENOENT; h->priv_data = (void *)fd; return 0; } static int file_read(URLContext *h, unsigned char *buf, int size) { int fd = (int)h->priv_data; return read(fd, buf, size); } static int file_write(URLContext *h, unsigned char *buf, int size) { int fd = (int)h->priv_data; return write(fd, buf, size); } /* XXX: use llseek */ static offset_t file_seek(URLContext *h, offset_t pos, int whence) { int fd = (int)h->priv_data; #ifdef CONFIG_WIN32 return _lseeki64(fd, pos, whence); #else return lseek(fd, pos, whence); #endif } static int file_close(URLContext *h) { int fd = (int)h->priv_data; return close(fd); } URLProtocol file_protocol = { "file", file_open, file_read, file_write, file_seek, file_close, }; /* pipe protocol */ static int pipe_open(URLContext *h, const char *filename, int flags) { int fd; if (flags & URL_WRONLY) { fd = 1; } else { fd = 0; } h->priv_data = (void *)fd; return 0; } static int pipe_read(URLContext *h, unsigned char *buf, int size) { int fd = (int)h->priv_data; return read(fd, buf, size); } static int pipe_write(URLContext *h, unsigned char *buf, int size) { int fd = (int)h->priv_data; return write(fd, buf, size); } static int pipe_close(URLContext *h) { return 0; } URLProtocol pipe_protocol = { "pipe", pipe_open, pipe_read, pipe_write, NULL, pipe_close, }; xmms-wma-1.0.5/ffmpeg-strip-wma/common.h0000644000175000017500000006753610301157417020415 0ustar whistlerwhistler/** * @file common.h * common internal api header. */ #ifndef COMMON_H #define COMMON_H #if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) # define CONFIG_WIN32 #endif //#define ALT_BITSTREAM_WRITER //#define ALIGNED_BITSTREAM_WRITER #define ALT_BITSTREAM_READER //#define LIBMPEG2_BITSTREAM_READER //#define A32_BITSTREAM_READER #define LIBMPEG2_BITSTREAM_READER_HACK //add BERO #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifdef HAVE_AV_CONFIG_H /* only include the following when compiling package */ # include "config.h" # include # include # include # include # ifndef __BEOS__ # include # else # include "berrno.h" # endif # include # ifndef ENODATA # define ENODATA 61 # endif #include #ifndef offsetof # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) #endif #define AVOPTION_CODEC_BOOL(name, help, field) \ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL } #define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval } #define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval } #define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval } #define AVOPTION_CODEC_STRING(name, help, field, str, val) \ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str } #define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \ { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL } #define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr } #define AVOPTION_END() AVOPTION_SUB(NULL) struct AVOption; #endif /* HAVE_AV_CONFIG_H */ /* Suppress restrict if it was not defined in config.h. */ #ifndef restrict # define restrict #endif #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) # define always_inline __attribute__((always_inline)) inline #else # define always_inline inline #endif #ifndef EMULATE_INTTYPES # include #else typedef signed char int8_t; typedef signed short int16_t; typedef signed int int32_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; # ifdef CONFIG_WIN32 typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; # else /* other OS */ typedef signed long long int64_t; typedef unsigned long long uint64_t; # endif /* other OS */ #endif /* HAVE_INTTYPES_H */ #ifndef INT64_MAX #define INT64_MAX 9223372036854775807LL #endif #ifdef EMULATE_FAST_INT /* note that we don't emulate 64bit ints */ typedef signed char int_fast8_t; typedef signed int int_fast16_t; typedef signed int int_fast32_t; typedef unsigned char uint_fast8_t; typedef unsigned int uint_fast16_t; typedef unsigned int uint_fast32_t; #endif #if defined(CONFIG_OS2) || defined(CONFIG_SUNOS) static inline float floorf(float f) { return floor(f); } #endif #ifdef CONFIG_WIN32 /* windows */ # ifndef __MINGW32__ # define int64_t_C(c) (c ## i64) # define uint64_t_C(c) (c ## i64) # ifdef HAVE_AV_CONFIG_H # define inline __inline # endif # else # define int64_t_C(c) (c ## LL) # define uint64_t_C(c) (c ## ULL) # endif /* __MINGW32__ */ # ifdef HAVE_AV_CONFIG_H # ifdef _DEBUG # define DEBUG # endif # define snprintf _snprintf # define vsnprintf _vsnprintf # endif /* CONFIG_WIN32 end */ #elif defined (CONFIG_OS2) /* OS/2 EMX */ #ifndef int64_t_C #define int64_t_C(c) (c ## LL) #define uint64_t_C(c) (c ## ULL) #endif #ifdef HAVE_AV_CONFIG_H #ifdef USE_FASTMEMCPY #include "fastmemcpy.h" #endif #include #endif /* HAVE_AV_CONFIG_H */ /* CONFIG_OS2 end */ #else /* unix */ #ifndef int64_t_C #define int64_t_C(c) (c ## LL) #define uint64_t_C(c) (c ## ULL) #endif #ifdef HAVE_AV_CONFIG_H # ifdef USE_FASTMEMCPY # include "fastmemcpy.h" # endif # endif /* HAVE_AV_CONFIG_H */ #endif /* !CONFIG_WIN32 && !CONFIG_OS2 */ #ifdef HAVE_AV_CONFIG_H # include "bswap.h" # if defined(__MINGW32__) || defined(__CYGWIN__) || \ defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) # define MANGLE(a) "_" #a # else # define MANGLE(a) #a # endif /* debug stuff */ # ifndef DEBUG # define NDEBUG # endif # include /* dprintf macros */ # if defined(CONFIG_WIN32) && !defined(__MINGW32__) inline void dprintf(const char* fmt,...) {} # else # ifdef DEBUG # define dprintf(fmt,...) printf(fmt, __VA_ARGS__) # else # define dprintf(fmt,...) # endif # endif /* !CONFIG_WIN32 */ # define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) //rounded divison & shift #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) /* assume b>0 */ #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) #define ABS(a) ((a) >= 0 ? (a) : (-(a))) #define FFMAX(a,b) ((a) > (b) ? (a) : (b)) #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) extern const uint32_t inverse[256]; #ifdef ARCH_X86 # define FASTDIV(a,b) \ ({\ int ret,dmy;\ asm volatile(\ "mull %3"\ :"=d"(ret),"=a"(dmy)\ :"1"(a),"g"(inverse[b])\ );\ ret;\ }) #elif defined(CONFIG_FASTDIV) # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32)) #else # define FASTDIV(a,b) ((a)/(b)) #endif #ifdef ARCH_X86 // avoid +32 for shift optimization (gcc should do that ...) static inline int32_t NEG_SSR32( int32_t a, int8_t s){ asm ("sarl %1, %0\n\t" : "+r" (a) : "ic" ((uint8_t)(-s)) ); return a; } static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ asm ("shrl %1, %0\n\t" : "+r" (a) : "ic" ((uint8_t)(-s)) ); return a; } #else # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) #endif /* bit output */ struct PutBitContext; typedef void (*WriteDataFunc)(void *, uint8_t *, int); typedef struct PutBitContext { #ifdef ALT_BITSTREAM_WRITER uint8_t *buf, *buf_end; int index; #else uint32_t bit_buf; int bit_left; uint8_t *buf, *buf_ptr, *buf_end; #endif } PutBitContext; void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size); int get_bit_count(PutBitContext *s); /* XXX: change function name */ void align_put_bits(PutBitContext *s); void flush_put_bits(PutBitContext *s); void put_string(PutBitContext * pbc, char *s); /* bit input */ typedef struct GetBitContext { const uint8_t *buffer, *buffer_end; #ifdef ALT_BITSTREAM_READER int index; #elif defined LIBMPEG2_BITSTREAM_READER uint8_t *buffer_ptr; uint32_t cache; int bit_count; #elif defined A32_BITSTREAM_READER uint32_t *buffer_ptr; uint32_t cache0; uint32_t cache1; int bit_count; #endif int size_in_bits; } GetBitContext; static inline int get_bits_count(GetBitContext *s); #define VLC_TYPE int16_t typedef struct VLC { int bits; VLC_TYPE (*table)[2]; ///< code, bits int table_size, table_allocated; } VLC; typedef struct RL_VLC_ELEM { int16_t level; int8_t len; uint8_t run; } RL_VLC_ELEM; #ifdef ARCH_SPARC64 #define UNALIGNED_STORES_ARE_BAD #endif /* used to avoid missaligned exceptions on some archs (alpha, ...) */ #ifdef ARCH_X86 # define unaligned32(a) (*(uint32_t*)(a)) #else # ifdef __GNUC__ static inline uint32_t unaligned32(const void *v) { struct Unaligned { uint32_t i; } __attribute__((packed)); return ((const struct Unaligned *) v)->i; } # elif defined(__DECC) static inline uint32_t unaligned32(const void *v) { return *(const __unaligned uint32_t *) v; } # else static inline uint32_t unaligned32(const void *v) { return *(const uint32_t *) v; } # endif #endif //!ARCH_X86 #ifndef ALT_BITSTREAM_WRITER static inline void put_bits(PutBitContext *s, int n, unsigned int value) { unsigned int bit_buf; int bit_left; #ifdef STATS st_out_bit_counts[st_current_index] += n; #endif // printf("put_bits=%d %x\n", n, value); assert(n == 32 || value < (1U << n)); bit_buf = s->bit_buf; bit_left = s->bit_left; // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); /* XXX: optimize */ if (n < bit_left) { bit_buf = (bit_buf<> (n - bit_left); #ifdef UNALIGNED_STORES_ARE_BAD if (3 & (int) s->buf_ptr) { s->buf_ptr[0] = bit_buf >> 24; s->buf_ptr[1] = bit_buf >> 16; s->buf_ptr[2] = bit_buf >> 8; s->buf_ptr[3] = bit_buf ; } else #endif *(uint32_t *)s->buf_ptr = be2me_32(bit_buf); //printf("bitbuf = %08x\n", bit_buf); s->buf_ptr+=4; bit_left+=32 - n; bit_buf = value; } s->bit_buf = bit_buf; s->bit_left = bit_left; } #endif #ifdef ALT_BITSTREAM_WRITER static inline void put_bits(PutBitContext *s, int n, unsigned int value) { # ifdef ALIGNED_BITSTREAM_WRITER # ifdef ARCH_X86 asm volatile( "movl %0, %%ecx \n\t" "xorl %%eax, %%eax \n\t" "shrdl %%cl, %1, %%eax \n\t" "shrl %%cl, %1 \n\t" "movl %0, %%ecx \n\t" "shrl $3, %%ecx \n\t" "andl $0xFFFFFFFC, %%ecx \n\t" "bswapl %1 \n\t" "orl %1, (%2, %%ecx) \n\t" "bswapl %%eax \n\t" "addl %3, %0 \n\t" "movl %%eax, 4(%2, %%ecx) \n\t" : "=&r" (s->index), "=&r" (value) : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) : "%eax", "%ecx" ); # else int index= s->index; uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); value<<= 32-n; ptr[0] |= be2me_32(value>>(index&31)); ptr[1] = be2me_32(value<<(32-(index&31))); //if(n>24) printf("%d %d\n", n, value); index+= n; s->index= index; # endif # else //ALIGNED_BITSTREAM_WRITER # ifdef ARCH_X86 asm volatile( "movl $7, %%ecx \n\t" "andl %0, %%ecx \n\t" "addl %3, %%ecx \n\t" "negl %%ecx \n\t" "shll %%cl, %1 \n\t" "bswapl %1 \n\t" "movl %0, %%ecx \n\t" "shrl $3, %%ecx \n\t" "orl %1, (%%ecx, %2) \n\t" "addl %3, %0 \n\t" "movl $0, 4(%%ecx, %2) \n\t" : "=&r" (s->index), "=&r" (value) : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) : "%ecx" ); # else int index= s->index; uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); ptr[0] |= be2me_32(value<<(32-n-(index&7) )); ptr[1] = 0; //if(n>24) printf("%d %d\n", n, value); index+= n; s->index= index; # endif # endif //!ALIGNED_BITSTREAM_WRITER } #endif static inline uint8_t* pbBufPtr(PutBitContext *s) { #ifdef ALT_BITSTREAM_WRITER return s->buf + (s->index>>3); #else return s->buf_ptr; #endif } /* Bitstream reader API docs: name abritary name which is used as prefix for the internal variables gb getbitcontext OPEN_READER(name, gb) loads gb into local variables CLOSE_READER(name, gb) stores local vars in gb UPDATE_CACHE(name, gb) refills the internal cache from the bitstream after this call at least MIN_CACHE_BITS will be available, GET_CACHE(name, gb) will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) SHOW_UBITS(name, gb, num) will return the nest num bits SHOW_SBITS(name, gb, num) will return the nest num bits and do sign extension SKIP_BITS(name, gb, num) will skip over the next num bits note, this is equinvalent to SKIP_CACHE; SKIP_COUNTER SKIP_CACHE(name, gb, num) will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) SKIP_COUNTER(name, gb, num) will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) LAST_SKIP_CACHE(name, gb, num) will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing LAST_SKIP_BITS(name, gb, num) is equinvalent to SKIP_LAST_CACHE; SKIP_COUNTER for examples see get_bits, show_bits, skip_bits, get_vlc */ static inline int unaligned32_be(const void *v) { #ifdef CONFIG_ALIGN const uint8_t *p=v; return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]); #else return be2me_32( unaligned32(v)); //original #endif } #ifdef ALT_BITSTREAM_READER # define MIN_CACHE_BITS 25 # define OPEN_READER(name, gb)\ int name##_index= (gb)->index;\ int name##_cache= 0;\ # define CLOSE_READER(name, gb)\ (gb)->index= name##_index;\ # define UPDATE_CACHE(name, gb)\ name##_cache= unaligned32_be( ((uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ # define SKIP_CACHE(name, gb, num)\ name##_cache <<= (num);\ // FIXME name? # define SKIP_COUNTER(name, gb, num)\ name##_index += (num);\ # define SKIP_BITS(name, gb, num)\ {\ SKIP_CACHE(name, gb, num)\ SKIP_COUNTER(name, gb, num)\ }\ # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) # define LAST_SKIP_CACHE(name, gb, num) ; # define SHOW_UBITS(name, gb, num)\ NEG_USR32(name##_cache, num) # define SHOW_SBITS(name, gb, num)\ NEG_SSR32(name##_cache, num) # define GET_CACHE(name, gb)\ ((uint32_t)name##_cache) static inline int get_bits_count(GetBitContext *s){ return s->index; } #elif defined LIBMPEG2_BITSTREAM_READER //libmpeg2 like reader # define MIN_CACHE_BITS 17 # define OPEN_READER(name, gb)\ int name##_bit_count=(gb)->bit_count;\ int name##_cache= (gb)->cache;\ uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\ # define CLOSE_READER(name, gb)\ (gb)->bit_count= name##_bit_count;\ (gb)->cache= name##_cache;\ (gb)->buffer_ptr= name##_buffer_ptr;\ #ifdef LIBMPEG2_BITSTREAM_READER_HACK # define UPDATE_CACHE(name, gb)\ if(name##_bit_count >= 0){\ name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\ ((uint16_t*)name##_buffer_ptr)++;\ name##_bit_count-= 16;\ }\ #else # define UPDATE_CACHE(name, gb)\ if(name##_bit_count >= 0){\ name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\ name##_buffer_ptr+=2;\ name##_bit_count-= 16;\ }\ #endif # define SKIP_CACHE(name, gb, num)\ name##_cache <<= (num);\ # define SKIP_COUNTER(name, gb, num)\ name##_bit_count += (num);\ # define SKIP_BITS(name, gb, num)\ {\ SKIP_CACHE(name, gb, num)\ SKIP_COUNTER(name, gb, num)\ }\ # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) # define SHOW_UBITS(name, gb, num)\ NEG_USR32(name##_cache, num) # define SHOW_SBITS(name, gb, num)\ NEG_SSR32(name##_cache, num) # define GET_CACHE(name, gb)\ ((uint32_t)name##_cache) static inline int get_bits_count(GetBitContext *s){ return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count; } #elif defined A32_BITSTREAM_READER # define MIN_CACHE_BITS 32 # define OPEN_READER(name, gb)\ int name##_bit_count=(gb)->bit_count;\ uint32_t name##_cache0= (gb)->cache0;\ uint32_t name##_cache1= (gb)->cache1;\ uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\ # define CLOSE_READER(name, gb)\ (gb)->bit_count= name##_bit_count;\ (gb)->cache0= name##_cache0;\ (gb)->cache1= name##_cache1;\ (gb)->buffer_ptr= name##_buffer_ptr;\ # define UPDATE_CACHE(name, gb)\ if(name##_bit_count > 0){\ const uint32_t next= be2me_32( *name##_buffer_ptr );\ name##_cache0 |= NEG_USR32(next,name##_bit_count);\ name##_cache1 |= next<buffer_ptr - s->buffer)*8 - 32 + s->bit_count; } #endif /** * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). * if MSB not set it is negative * @param n length in bits * @author BERO */ static inline int get_xbits(GetBitContext *s, int n){ register int tmp; register int32_t cache; OPEN_READER(re, s) UPDATE_CACHE(re, s) cache = GET_CACHE(re,s); if ((int32_t)cache<0) { //MSB=1 tmp = NEG_USR32(cache,n); } else { // tmp = (-1<index+=n for the ALT_READER :)) OPEN_READER(re, s) UPDATE_CACHE(re, s) LAST_SKIP_BITS(re, s, n) CLOSE_READER(re, s) } static inline unsigned int get_bits1(GetBitContext *s){ #ifdef ALT_BITSTREAM_READER int index= s->index; uint8_t result= s->buffer[ index>>3 ]; result<<= (index&0x07); result>>= 8 - 1; index++; s->index= index; return result; #else return get_bits(s, 1); #endif } static inline unsigned int show_bits1(GetBitContext *s){ return show_bits(s, 1); } static inline void skip_bits1(GetBitContext *s){ skip_bits(s, 1); } void init_get_bits(GetBitContext *s, const uint8_t *buffer, int buffer_size); int check_marker(GetBitContext *s, const char *msg); void align_get_bits(GetBitContext *s); int init_vlc(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size); void free_vlc(VLC *vlc); /** * * if the vlc code is invalid and max_depth=1 than no bits will be removed * if the vlc code is invalid and max_depth>1 than the number of bits removed * is undefined */ #define GET_VLC(code, name, gb, table, bits, max_depth)\ {\ int n, index, nb_bits;\ \ index= SHOW_UBITS(name, gb, bits);\ code = table[index][0];\ n = table[index][1];\ \ if(max_depth > 1 && n < 0){\ LAST_SKIP_BITS(name, gb, bits)\ UPDATE_CACHE(name, gb)\ \ nb_bits = -n;\ \ index= SHOW_UBITS(name, gb, nb_bits) + code;\ code = table[index][0];\ n = table[index][1];\ if(max_depth > 2 && n < 0){\ LAST_SKIP_BITS(name, gb, nb_bits)\ UPDATE_CACHE(name, gb)\ \ nb_bits = -n;\ \ index= SHOW_UBITS(name, gb, nb_bits) + code;\ code = table[index][0];\ n = table[index][1];\ }\ }\ SKIP_BITS(name, gb, n)\ } #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth)\ {\ int n, index, nb_bits;\ \ index= SHOW_UBITS(name, gb, bits);\ level = table[index].level;\ n = table[index].len;\ \ if(max_depth > 1 && n < 0){\ LAST_SKIP_BITS(name, gb, bits)\ UPDATE_CACHE(name, gb)\ \ nb_bits = -n;\ \ index= SHOW_UBITS(name, gb, nb_bits) + level;\ level = table[index].level;\ n = table[index].len;\ }\ run= table[index].run;\ SKIP_BITS(name, gb, n)\ } // deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly static inline int get_vlc(GetBitContext *s, VLC *vlc) { int code; VLC_TYPE (*table)[2]= vlc->table; OPEN_READER(re, s) UPDATE_CACHE(re, s) GET_VLC(code, re, s, table, vlc->bits, 3) CLOSE_READER(re, s) return code; } /** * parses a vlc code, faster then get_vlc() * @param bits is the number of bits which will be read at once, must be * identical to nb_bits in init_vlc() * @param max_depth is the number of times bits bits must be readed to completly * read the longest vlc code * = (max_vlc_length + bits - 1) / bits */ static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth) { int code; OPEN_READER(re, s) UPDATE_CACHE(re, s) GET_VLC(code, re, s, table, bits, max_depth) CLOSE_READER(re, s) return code; } //#define TRACE #ifdef TRACE static inline void print_bin(int bits, int n){ int i; for(i=n-1; i>=0; i--){ printf("%d", (bits>>i)&1); } for(i=n; i<24; i++) printf(" "); } static inline int get_bits_trace(GetBitContext *s, int n, char *file, char *func, int line){ int r= get_bits(s, n); print_bin(r, n); printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); return r; } static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, char *func, int line){ int show= show_bits(s, 24); int pos= get_bits_count(s); int r= get_vlc2(s, table, bits, max_depth); int len= get_bits_count(s) - pos; int bits2= show>>(24-len); print_bin(bits2, len); printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); return r; } static inline int get_xbits_trace(GetBitContext *s, int n, char *file, char *func, int line){ int show= show_bits(s, n); int r= get_xbits(s, n); print_bin(show, n); printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); return r; } #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define tprintf printf #else //TRACE #define tprintf(_arg...) {} #endif /* define it to include statistics code (useful only for optimizing codec efficiency */ //#define STATS #ifdef STATS enum { ST_UNKNOWN, ST_DC, ST_INTRA_AC, ST_INTER_AC, ST_INTRA_MB, ST_INTER_MB, ST_MV, ST_NB, }; extern int st_current_index; extern unsigned int st_bit_counts[ST_NB]; extern unsigned int st_out_bit_counts[ST_NB]; void print_stats(void); #endif /* misc math functions */ extern const uint8_t ff_log2_tab[256]; static inline int av_log2(unsigned int v) { int n; n = 0; if (v & 0xffff0000) { v >>= 16; n += 16; } if (v & 0xff00) { v >>= 8; n += 8; } n += ff_log2_tab[v]; return n; } static inline int av_log2_16bit(unsigned int v) { int n; n = 0; if (v & 0xff00) { v >>= 8; n += 8; } n += ff_log2_tab[v]; return n; } /* median of 3 */ static inline int mid_pred(int a, int b, int c) { #if 0 int t= (a-b)&((a-b)>>31); a-=t; b+=t; b-= (b-c)&((b-c)>>31); b+= (a-b)&((a-b)>>31); return b; #else if(a>b){ if(c>b){ if(c>a) b=a; else b=c; } }else{ if(b>c){ if(c>a) b=c; else b=a; } } return b; #endif } static inline int clip(int a, int amin, int amax) { if (a < amin) return amin; else if (a > amax) return amax; else return a; } /* math */ extern const uint8_t ff_sqrt_tab[128]; int64_t ff_gcd(int64_t a, int64_t b); static inline int ff_sqrt(int a) { int ret=0; int s; int ret_sq=0; if(a<128) return ff_sqrt_tab[a]; for(s=15; s>=0; s--){ int b= ret_sq + (1<<(s*2)) + (ret<>31;\ level= (level^mask)-mask; #endif #if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT) #define COPY3_IF_LT(x,y,a,b,c,d)\ asm volatile (\ "cmpl %0, %3 \n\t"\ "cmovl %3, %0 \n\t"\ "cmovl %4, %1 \n\t"\ "cmovl %5, %2 \n\t"\ : "+r" (x), "+r" (a), "+r" (c)\ : "r" (y), "r" (b), "r" (d)\ ); #else #define COPY3_IF_LT(x,y,a,b,c,d)\ if((y)<(x)){\ (x)=(y);\ (a)=(b);\ (c)=(d);\ } #endif #ifdef ARCH_X86 static inline long long rdtsc() { long long l; asm volatile( "rdtsc\n\t" : "=A" (l) ); return l; } #define START_TIMER \ static uint64_t tsum=0;\ static int tcount=0;\ static int tskip_count=0;\ uint64_t tend;\ uint64_t tstart= rdtsc();\ #define STOP_TIMER(id) \ tend= rdtsc();\ if(tcount<2 || tend - tstart < 4*tsum/tcount){\ tsum+= tend - tstart;\ tcount++;\ }else\ tskip_count++;\ if(256*256*256*64%(tcount+tskip_count)==0){\ fprintf(stderr, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\ } #endif #define CLAMP_TO_8BIT(d) ((d > 0xff) ? 0xff : (d < 0) ? 0 : d) /* avoid usage of various functions */ #define malloc please_use_av_malloc #define free please_use_av_free #define realloc please_use_av_realloc #define CHECKED_ALLOCZ(p, size)\ {\ p= av_mallocz(size);\ if(p==NULL && (size)!=0){\ perror("malloc");\ goto fail;\ }\ } #endif /* HAVE_AV_CONFIG_H */ #endif /* COMMON_H */ xmms-wma-1.0.5/ffmpeg-strip-wma/config.mak0000644000175000017500000000127110307116550020672 0ustar whistlerwhistler# Automatically generated by configure - do not modify prefix=/usr bindir=/usr/bin mandir=/usr/share/man MAKE=make CC=gcc AR=ar RANLIB=ranlib STRIP=strip OPTFLAGS=-Wall -O3 -fPIC SHCFLAGS=-Wall -O3 -fPIC LDFLAGS=-Wl,--warn-common -rdynamic FFSLDFLAGS=-Wl,-E SHFLAGS=-shared LIBPREF=lib LIBSUF=.a SLIBPREF=lib SLIBSUF=.so EXESUF= TARGET_OS=Linux TARGET_ARCH_X86=yes TARGET_MMX=no TARGET_BUILTIN_VECTOR=yes HAVE_FREETYPE2=no CONFIG_SDL=no BUILD_VHOOK=no EXTRALIBS=-lm -ldl VERSION=0.4.8 CONFIG_ENCODERS=no CONFIG_DECODERS=yes CONFIG_VIDEO4LINUX=no CONFIG_DV1394=no CONFIG_AUDIO_OSS=no CONFIG_NETWORK=no CONFIG_ZLIB=no CONFIG_FFSERVER=no CONFIG_FFPLAY=no CONFIG_RISKY=yes SRC_PATH=/projects/ffmpeg_1 xmms-wma-1.0.5/ffmpeg-strip-wma/fft.c0000644000175000017500000001414510016246472017666 0ustar whistlerwhistler/* * FFT/IFFT transforms * Copyright (c) 2002 Fabrice Bellard. * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file fft.c * FFT/IFFT transforms. */ #include "dsputil.h" /** * The size of the FFT is 2^nbits. If inverse is TRUE, inverse FFT is * done */ int fft_inits(FFTContext *s, int nbits, int inverse) { int i, j, m, n; float alpha, c1, s1, s2; s->nbits = nbits; n = 1 << nbits; s->exptab = av_malloc((n / 2) * sizeof(FFTComplex)); if (!s->exptab) goto fail; s->revtab = av_malloc(n * sizeof(uint16_t)); if (!s->revtab) goto fail; s->inverse = inverse; s2 = inverse ? 1.0 : -1.0; for(i=0;i<(n/2);i++) { alpha = 2 * M_PI * (float)i / (float)n; c1 = cos(alpha); s1 = sin(alpha) * s2; s->exptab[i].re = c1; s->exptab[i].im = s1; } s->fft_calc = fft_calc_c; s->exptab1 = NULL; /* compute constant table for HAVE_SSE version */ #if (defined(HAVE_MMX) && defined(HAVE_BUILTIN_VECTOR)) || defined(HAVE_ALTIVEC) { int has_vectors = 0; #if defined(HAVE_MMX) has_vectors = mm_support() & MM_SSE; #endif #if defined(HAVE_ALTIVEC) && !defined(ALTIVEC_USE_REFERENCE_C_CODE) has_vectors = mm_support() & MM_ALTIVEC; #endif if (has_vectors) { int np, nblocks, np2, l; FFTComplex *q; np = 1 << nbits; nblocks = np >> 3; np2 = np >> 1; s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex)); if (!s->exptab1) goto fail; q = s->exptab1; do { for(l = 0; l < np2; l += 2 * nblocks) { *q++ = s->exptab[l]; *q++ = s->exptab[l + nblocks]; q->re = -s->exptab[l].im; q->im = s->exptab[l].re; q++; q->re = -s->exptab[l + nblocks].im; q->im = s->exptab[l + nblocks].re; q++; } nblocks = nblocks >> 1; } while (nblocks != 0); av_freep(&s->exptab); #if defined(HAVE_MMX) s->fft_calc = fft_calc_sse; #else s->fft_calc = fft_calc_altivec; #endif } } #endif /* compute bit reverse table */ for(i=0;i> j) & 1) << (nbits-j-1); } s->revtab[i]=m; } return 0; fail: av_freep(&s->revtab); av_freep(&s->exptab); av_freep(&s->exptab1); return -1; } /* butter fly op */ #define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \ {\ FFTSample ax, ay, bx, by;\ bx=pre1;\ by=pim1;\ ax=qre1;\ ay=qim1;\ pre = (bx + ax);\ pim = (by + ay);\ qre = (bx - ax);\ qim = (by - ay);\ } #define MUL16(a,b) ((a) * (b)) #define CMUL(pre, pim, are, aim, bre, bim) \ {\ pre = (MUL16(are, bre) - MUL16(aim, bim));\ pim = (MUL16(are, bim) + MUL16(bre, aim));\ } /** * Do a complex FFT with the parameters defined in fft_init(). The * input data must be permuted before with s->revtab table. No * 1.0/sqrt(n) normalization is done. */ void fft_calc_c(FFTContext *s, FFTComplex *z) { int ln = s->nbits; int j, np, np2; int nblocks, nloops; register FFTComplex *p, *q; FFTComplex *exptab = s->exptab; int l; FFTSample tmp_re, tmp_im; np = 1 << ln; /* pass 0 */ p=&z[0]; j=(np >> 1); do { BF(p[0].re, p[0].im, p[1].re, p[1].im, p[0].re, p[0].im, p[1].re, p[1].im); p+=2; } while (--j != 0); /* pass 1 */ p=&z[0]; j=np >> 2; if (s->inverse) { do { BF(p[0].re, p[0].im, p[2].re, p[2].im, p[0].re, p[0].im, p[2].re, p[2].im); BF(p[1].re, p[1].im, p[3].re, p[3].im, p[1].re, p[1].im, -p[3].im, p[3].re); p+=4; } while (--j != 0); } else { do { BF(p[0].re, p[0].im, p[2].re, p[2].im, p[0].re, p[0].im, p[2].re, p[2].im); BF(p[1].re, p[1].im, p[3].re, p[3].im, p[1].re, p[1].im, p[3].im, -p[3].re); p+=4; } while (--j != 0); } /* pass 2 .. ln-1 */ nblocks = np >> 3; nloops = 1 << 2; np2 = np >> 1; do { p = z; q = z + nloops; for (j = 0; j < nblocks; ++j) { BF(p->re, p->im, q->re, q->im, p->re, p->im, q->re, q->im); p++; q++; for(l = nblocks; l < np2; l += nblocks) { CMUL(tmp_re, tmp_im, exptab[l].re, exptab[l].im, q->re, q->im); BF(p->re, p->im, q->re, q->im, p->re, p->im, tmp_re, tmp_im); p++; q++; } p += nloops; q += nloops; } nblocks = nblocks >> 1; nloops = nloops << 1; } while (nblocks != 0); } /** * Do the permutation needed BEFORE calling fft_calc() */ void fft_permute(FFTContext *s, FFTComplex *z) { int j, k, np; FFTComplex tmp; const uint16_t *revtab = s->revtab; /* reverse */ np = 1 << s->nbits; for(j=0;jrevtab); av_freep(&s->exptab); av_freep(&s->exptab1); } xmms-wma-1.0.5/ffmpeg-strip-wma/mem.c0000644000175000017500000000572507631630662017700 0ustar whistlerwhistler/* * default memory allocator for libavcodec * Copyright (c) 2002 Fabrice Bellard. * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file mem.c * default memory allocator for libavcodec. */ #include "avcodec.h" /* here we can use OS dependant allocation functions */ #undef malloc #undef free #undef realloc #ifdef HAVE_MALLOC_H #include #endif /* you can redefine av_malloc and av_free in your project to use your memory allocator. You do not need to suppress this file because the linker will do it automatically */ /** * Memory allocation of size byte with alignment suitable for all * memory accesses (including vectors if available on the * CPU). av_malloc(0) must return a non NULL pointer. */ void *av_malloc(unsigned int size) { void *ptr; #if defined (HAVE_MEMALIGN) ptr = memalign(16,size); /* Why 64? Indeed, we should align it: on 4 for 386 on 16 for 486 on 32 for 586, PPro - k6-III on 64 for K7 (maybe for P3 too). Because L1 and L2 caches are aligned on those values. But I don't want to code such logic here! */ /* Why 16? because some cpus need alignment, for example SSE2 on P4, & most RISC cpus it will just trigger an exception and the unaligned load will be done in the exception handler or it will just segfault (SSE2 on P4) Why not larger? because i didnt see a difference in benchmarks ... */ /* benchmarks with p3 memalign(64)+1 3071,3051,3032 memalign(64)+2 3051,3032,3041 memalign(64)+4 2911,2896,2915 memalign(64)+8 2545,2554,2550 memalign(64)+16 2543,2572,2563 memalign(64)+32 2546,2545,2571 memalign(64)+64 2570,2533,2558 btw, malloc seems to do 8 byte alignment by default here */ #else ptr = malloc(size); #endif return ptr; } /** * av_realloc semantics (same as glibc): if ptr is NULL and size > 0, * identical to malloc(size). If size is zero, it is identical to * free(ptr) and NULL is returned. */ void *av_realloc(void *ptr, unsigned int size) { return realloc(ptr, size); } /* NOTE: ptr = NULL is explicetly allowed */ void av_free(void *ptr) { /* XXX: this test should not be needed on most libcs */ if (ptr) free(ptr); } xmms-wma-1.0.5/ffmpeg-strip-wma/dsputil.c0000644000175000017500000036102210014750141020561 0ustar whistlerwhistler/* * DSP utils * Copyright (c) 2000, 2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer */ /** * @file dsputil.c * DSP utils */ #include "avcodec.h" #include "dsputil.h" //#include "mpegvideo.h" #include "simple_idct.h" //#include "faandct.h" uint8_t cropTbl[256 + 2 * MAX_NEG_CROP]; uint32_t squareTbl[512]; const uint8_t ff_zigzag_direct[64] = { 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 }; /* Specific zigzag scan for 248 idct. NOTE that unlike the specification, we interleave the fields */ const uint8_t ff_zigzag248_direct[64] = { 0, 8, 1, 9, 16, 24, 2, 10, 17, 25, 32, 40, 48, 56, 33, 41, 18, 26, 3, 11, 4, 12, 19, 27, 34, 42, 49, 57, 50, 58, 35, 43, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 51, 59, 52, 60, 37, 45, 22, 30, 7, 15, 23, 31, 38, 46, 53, 61, 54, 62, 39, 47, 55, 63, }; /* not permutated inverse zigzag_direct + 1 for MMX quantizer */ uint16_t __align8 inv_zigzag_direct16[64]; const uint8_t ff_alternate_horizontal_scan[64] = { 0, 1, 2, 3, 8, 9, 16, 17, 10, 11, 4, 5, 6, 7, 15, 14, 13, 12, 19, 18, 24, 25, 32, 33, 26, 27, 20, 21, 22, 23, 28, 29, 30, 31, 34, 35, 40, 41, 48, 49, 42, 43, 36, 37, 38, 39, 44, 45, 46, 47, 50, 51, 56, 57, 58, 59, 52, 53, 54, 55, 60, 61, 62, 63, }; const uint8_t ff_alternate_vertical_scan[64] = { 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49, 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43, 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45, 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63, }; /* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */ const uint32_t inverse[256]={ 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757, 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154, 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709, 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333, 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367, 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283, 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315, 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085, 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498, 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675, 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441, 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183, 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712, 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400, 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163, 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641, 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573, 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737, 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493, 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373, 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368, 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671, 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767, 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740, 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751, 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635, 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593, 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944, 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933, 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575, 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532, 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010, }; /* Input permutation for the simple_idct_mmx */ static const uint8_t simple_mmx_permutation[64]={ 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, }; #if 0 static int pix_sum_c(uint8_t * pix, int line_size) { int s, i, j; s = 0; for (i = 0; i < 16; i++) { for (j = 0; j < 16; j += 8) { s += pix[0]; s += pix[1]; s += pix[2]; s += pix[3]; s += pix[4]; s += pix[5]; s += pix[6]; s += pix[7]; pix += 8; } pix += line_size - 16; } return s; } static int pix_norm1_c(uint8_t * pix, int line_size) { int s, i, j; uint32_t *sq = squareTbl + 256; s = 0; for (i = 0; i < 16; i++) { for (j = 0; j < 16; j += 8) { #if 0 s += sq[pix[0]]; s += sq[pix[1]]; s += sq[pix[2]]; s += sq[pix[3]]; s += sq[pix[4]]; s += sq[pix[5]]; s += sq[pix[6]]; s += sq[pix[7]]; #else #if LONG_MAX > 2147483647 register uint64_t x=*(uint64_t*)pix; s += sq[x&0xff]; s += sq[(x>>8)&0xff]; s += sq[(x>>16)&0xff]; s += sq[(x>>24)&0xff]; s += sq[(x>>32)&0xff]; s += sq[(x>>40)&0xff]; s += sq[(x>>48)&0xff]; s += sq[(x>>56)&0xff]; #else register uint32_t x=*(uint32_t*)pix; s += sq[x&0xff]; s += sq[(x>>8)&0xff]; s += sq[(x>>16)&0xff]; s += sq[(x>>24)&0xff]; x=*(uint32_t*)(pix+4); s += sq[x&0xff]; s += sq[(x>>8)&0xff]; s += sq[(x>>16)&0xff]; s += sq[(x>>24)&0xff]; #endif #endif pix += 8; } pix += line_size - 16; } return s; } static void bswap_buf(uint32_t *dst, uint32_t *src, int w){ int i; for(i=0; i+8<=w; i+=8){ dst[i+0]= bswap_32(src[i+0]); dst[i+1]= bswap_32(src[i+1]); dst[i+2]= bswap_32(src[i+2]); dst[i+3]= bswap_32(src[i+3]); dst[i+4]= bswap_32(src[i+4]); dst[i+5]= bswap_32(src[i+5]); dst[i+6]= bswap_32(src[i+6]); dst[i+7]= bswap_32(src[i+7]); } for(;i>1));\ pixels+=line_size;\ block +=line_size;\ }\ }\ \ static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ for(i=0; i>1));\ pixels+=line_size;\ block +=line_size;\ }\ }\ \ static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ for(i=0; i>1));\ pixels+=line_size;\ block +=line_size;\ }\ }\ \ static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ for(i=0; i>1));\ pixels+=line_size;\ block +=line_size;\ }\ }\ \ static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ const uint64_t a= LD64(pixels );\ const uint64_t b= LD64(pixels+1);\ uint64_t l0= (a&0x0303030303030303ULL)\ + (b&0x0303030303030303ULL)\ + 0x0202020202020202ULL;\ uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ uint64_t l1,h1;\ \ pixels+=line_size;\ for(i=0; i>2)\ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ pixels+=line_size;\ block +=line_size;\ a= LD64(pixels );\ b= LD64(pixels+1);\ l0= (a&0x0303030303030303ULL)\ + (b&0x0303030303030303ULL)\ + 0x0202020202020202ULL;\ h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ pixels+=line_size;\ block +=line_size;\ }\ }\ \ static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ const uint64_t a= LD64(pixels );\ const uint64_t b= LD64(pixels+1);\ uint64_t l0= (a&0x0303030303030303ULL)\ + (b&0x0303030303030303ULL)\ + 0x0101010101010101ULL;\ uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ uint64_t l1,h1;\ \ pixels+=line_size;\ for(i=0; i>2)\ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ pixels+=line_size;\ block +=line_size;\ a= LD64(pixels );\ b= LD64(pixels+1);\ l0= (a&0x0303030303030303ULL)\ + (b&0x0303030303030303ULL)\ + 0x0101010101010101ULL;\ h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ pixels+=line_size;\ block +=line_size;\ }\ }\ \ CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\ CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\ CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\ CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\ CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\ CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\ CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8) #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) ) #else // 64 bit variant #define PIXOP2(OPNAME, OP) \ static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ int i;\ for(i=0; i>2)\ + ((b&0xFCFCFCFCUL)>>2);\ l1= (c&0x03030303UL)\ + (d&0x03030303UL);\ h1= ((c&0xFCFCFCFCUL)>>2)\ + ((d&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ a= LD32(&src1[i*src_stride1+4]);\ b= LD32(&src2[i*src_stride2+4]);\ c= LD32(&src3[i*src_stride3+4]);\ d= LD32(&src4[i*src_stride4+4]);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ h0= ((a&0xFCFCFCFCUL)>>2)\ + ((b&0xFCFCFCFCUL)>>2);\ l1= (c&0x03030303UL)\ + (d&0x03030303UL);\ h1= ((c&0xFCFCFCFCUL)>>2)\ + ((d&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ }\ }\ \ static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\ }\ \ static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ }\ \ static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\ }\ \ static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ }\ \ static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ int i;\ for(i=0; i>2)\ + ((b&0xFCFCFCFCUL)>>2);\ l1= (c&0x03030303UL)\ + (d&0x03030303UL);\ h1= ((c&0xFCFCFCFCUL)>>2)\ + ((d&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ a= LD32(&src1[i*src_stride1+4]);\ b= LD32(&src2[i*src_stride2+4]);\ c= LD32(&src3[i*src_stride3+4]);\ d= LD32(&src4[i*src_stride4+4]);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x01010101UL;\ h0= ((a&0xFCFCFCFCUL)>>2)\ + ((b&0xFCFCFCFCUL)>>2);\ l1= (c&0x03030303UL)\ + (d&0x03030303UL);\ h1= ((c&0xFCFCFCFCUL)>>2)\ + ((d&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ }\ }\ static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ }\ static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ }\ \ static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i, a0, b0, a1, b1;\ a0= pixels[0];\ b0= pixels[1] + 2;\ a0 += b0;\ b0 += pixels[2];\ \ pixels+=line_size;\ for(i=0; i>2; /* FIXME non put */\ block[1]= (b1+b0)>>2;\ \ pixels+=line_size;\ block +=line_size;\ \ a0= pixels[0];\ b0= pixels[1] + 2;\ a0 += b0;\ b0 += pixels[2];\ \ block[0]= (a1+a0)>>2;\ block[1]= (b1+b0)>>2;\ pixels+=line_size;\ block +=line_size;\ }\ }\ \ static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ const uint32_t a= LD32(pixels );\ const uint32_t b= LD32(pixels+1);\ uint32_t l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ + ((b&0xFCFCFCFCUL)>>2);\ uint32_t l1,h1;\ \ pixels+=line_size;\ for(i=0; i>2)\ + ((b&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ a= LD32(pixels );\ b= LD32(pixels+1);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ h0= ((a&0xFCFCFCFCUL)>>2)\ + ((b&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ }\ }\ \ static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int j;\ for(j=0; j<2; j++){\ int i;\ const uint32_t a= LD32(pixels );\ const uint32_t b= LD32(pixels+1);\ uint32_t l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ + ((b&0xFCFCFCFCUL)>>2);\ uint32_t l1,h1;\ \ pixels+=line_size;\ for(i=0; i>2)\ + ((b&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ a= LD32(pixels );\ b= LD32(pixels+1);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ h0= ((a&0xFCFCFCFCUL)>>2)\ + ((b&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ }\ pixels+=4-line_size*(h+1);\ block +=4-line_size*h;\ }\ }\ \ static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int j;\ for(j=0; j<2; j++){\ int i;\ const uint32_t a= LD32(pixels );\ const uint32_t b= LD32(pixels+1);\ uint32_t l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x01010101UL;\ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ + ((b&0xFCFCFCFCUL)>>2);\ uint32_t l1,h1;\ \ pixels+=line_size;\ for(i=0; i>2)\ + ((b&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ a= LD32(pixels );\ b= LD32(pixels+1);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x01010101UL;\ h0= ((a&0xFCFCFCFCUL)>>2)\ + ((b&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ }\ pixels+=4-line_size*(h+1);\ block +=4-line_size*h;\ }\ }\ \ CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\ CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\ CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\ CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\ CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\ CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\ CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\ CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\ #define op_avg(a, b) a = rnd_avg32(a, b) #endif #define op_put(a, b) a = b //PIXOP2(avg, op_avg) //PIXOP2(put, op_put) #undef op_avg #undef op_put #define avg2(a,b) ((a+b+1)>>1) #define avg4(a,b,c,d) ((a+b+c+d+2)>>2) #if 0 static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder) { const int A=(16-x16)*(16-y16); const int B=( x16)*(16-y16); const int C=(16-x16)*( y16); const int D=( x16)*( y16); int i; for(i=0; i>8; dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8; dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8; dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8; dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8; dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8; dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8; dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8; dst+= stride; src+= stride; } } static void gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height) { int y, vx, vy; const int s= 1<>16; src_y= vy>>16; frac_x= src_x&(s-1); frac_y= src_y&(s-1); src_x>>=shift; src_y>>=shift; if((unsigned)src_x < width){ if((unsigned)src_y < height){ index= src_x + src_y*stride; dst[y*stride + x]= ( ( src[index ]*(s-frac_x) + src[index +1]* frac_x )*(s-frac_y) + ( src[index+stride ]*(s-frac_x) + src[index+stride+1]* frac_x )* frac_y + r)>>(shift*2); }else{ index= src_x + clip(src_y, 0, height)*stride; dst[y*stride + x]= ( ( src[index ]*(s-frac_x) + src[index +1]* frac_x )*s + r)>>(shift*2); } }else{ if((unsigned)src_y < height){ index= clip(src_x, 0, width) + src_y*stride; dst[y*stride + x]= ( ( src[index ]*(s-frac_y) + src[index+stride ]* frac_y )*s + r)>>(shift*2); }else{ index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride; dst[y*stride + x]= src[index ]; } } vx+= dxx; vy+= dyx; } ox += dxy; oy += dyy; } } static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ switch(width){ case 2: put_pixels2_c (dst, src, stride, height); break; case 4: put_pixels4_c (dst, src, stride, height); break; case 8: put_pixels8_c (dst, src, stride, height); break; case 16:put_pixels16_c(dst, src, stride, height); break; } } static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11; } src += stride; dst += stride; } } static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11; } src += stride; dst += stride; } } static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11; } src += stride; dst += stride; } } static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15; } src += stride; dst += stride; } } static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15; } src += stride; dst += stride; } } static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11; } src += stride; dst += stride; } } static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15; } src += stride; dst += stride; } } static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15; } src += stride; dst += stride; } } static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ switch(width){ case 2: avg_pixels2_c (dst, src, stride, height); break; case 4: avg_pixels4_c (dst, src, stride, height); break; case 8: avg_pixels8_c (dst, src, stride, height); break; case 16:avg_pixels16_c(dst, src, stride, height); break; } } static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1; } src += stride; dst += stride; } } static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1; } src += stride; dst += stride; } } static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1; } src += stride; dst += stride; } } static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1; } src += stride; dst += stride; } } static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1; } src += stride; dst += stride; } } static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1; } src += stride; dst += stride; } } static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1; } src += stride; dst += stride; } } static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ int i,j; for (i=0; i < height; i++) { for (j=0; j < width; j++) { dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1; } src += stride; dst += stride; } } #if 0 #define TPEL_WIDTH(width)\ static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\ static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\ static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\ static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\ static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\ static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\ static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\ static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\ static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ void put_tpel_pixels_mc22_c(dst, src, stride, width, height);} #endif #define H264_CHROMA_MC(OPNAME, OP)\ static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ const int A=(8-x)*(8-y);\ const int B=( x)*(8-y);\ const int C=(8-x)*( y);\ const int D=( x)*( y);\ int i;\ \ assert(x<8 && y<8 && x>=0 && y>=0);\ \ for(i=0; i=0 && y>=0);\ \ for(i=0; i=0 && y>=0);\ \ for(i=0; i>6)+1)>>1) #define op_put(a, b) a = (((b) + 32)>>6) H264_CHROMA_MC(put_ , op_put) H264_CHROMA_MC(avg_ , op_avg) #undef op_avg #undef op_put static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h) { int i; for(i=0; i>5]+1)>>1) #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1) #define op_put(a, b) a = cm[((b) + 16)>>5] #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5] QPEL_MC(0, put_ , _ , op_put) QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd) QPEL_MC(0, avg_ , _ , op_avg) //QPEL_MC(1, avg_no_rnd , _ , op_avg) #undef op_avg #undef op_avg_no_rnd #undef op_put #undef op_put_no_rnd #if 1 #define H264_LOWPASS(OPNAME, OP, OP2) \ static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ const int h=4;\ uint8_t *cm = cropTbl + MAX_NEG_CROP;\ int i;\ for(i=0; i>5]+1)>>1) //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7) #define op_put(a, b) a = cm[((b) + 16)>>5] #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1) #define op2_put(a, b) a = cm[((b) + 512)>>10] H264_LOWPASS(put_ , op_put, op2_put) H264_LOWPASS(avg_ , op_avg, op2_avg) H264_MC(put_, 4) H264_MC(put_, 8) H264_MC(put_, 16) H264_MC(avg_, 4) H264_MC(avg_, 8) H264_MC(avg_, 16) #undef op_avg #undef op_put #undef op2_avg #undef op2_put #endif static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){ uint8_t *cm = cropTbl + MAX_NEG_CROP; int i; for(i=0; i>4]; dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4]; dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4]; dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4]; dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4]; dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4]; dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4]; dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4]; dst+=dstStride; src+=srcStride; } } static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){ uint8_t *cm = cropTbl + MAX_NEG_CROP; int i; for(i=0; i>4]; dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4]; dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4]; dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4]; dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4]; dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4]; dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4]; dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4]; src++; dst++; } } static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){ put_pixels8_c(dst, src, stride, 8); } static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){ uint8_t half[64]; wmv2_mspel8_h_lowpass(half, src, 8, stride, 8); put_pixels8_l2(dst, src, half, stride, stride, 8, 8); } static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){ wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8); } static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){ uint8_t half[64]; wmv2_mspel8_h_lowpass(half, src, 8, stride, 8); put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8); } static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){ wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8); } static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){ uint8_t halfH[88]; uint8_t halfV[64]; uint8_t halfHV[64]; wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11); wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8); wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8); put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8); } static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){ uint8_t halfH[88]; uint8_t halfV[64]; uint8_t halfHV[64]; wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11); wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8); wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8); put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8); } static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){ uint8_t halfH[88]; wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11); wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8); } #endif #if 0 static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){ int x; const int strength= ff_h263_loop_filter_strength[qscale]; for(x=0; x<8; x++){ int d1, d2, ad1; int p0= src[x-2*stride]; int p1= src[x-1*stride]; int p2= src[x+0*stride]; int p3= src[x+1*stride]; int d = (p0 - p3 + 4*(p2 - p1)) / 8; if (d<-2*strength) d1= 0; else if(d<- strength) d1=-2*strength - d; else if(d< strength) d1= d; else if(d< 2*strength) d1= 2*strength - d; else d1= 0; p1 += d1; p2 -= d1; if(p1&256) p1= ~(p1>>31); if(p2&256) p2= ~(p2>>31); src[x-1*stride] = p1; src[x+0*stride] = p2; ad1= ABS(d1)>>1; d2= clip((p0-p3)/4, -ad1, ad1); src[x-2*stride] = p0 - d2; src[x+ stride] = p3 + d2; } } static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){ int y; const int strength= ff_h263_loop_filter_strength[qscale]; for(y=0; y<8; y++){ int d1, d2, ad1; int p0= src[y*stride-2]; int p1= src[y*stride-1]; int p2= src[y*stride+0]; int p3= src[y*stride+1]; int d = (p0 - p3 + 4*(p2 - p1)) / 8; if (d<-2*strength) d1= 0; else if(d<- strength) d1=-2*strength - d; else if(d< strength) d1= d; else if(d< 2*strength) d1= 2*strength - d; else d1= 0; p1 += d1; p2 -= d1; if(p1&256) p1= ~(p1>>31); if(p2&256) p2= ~(p2>>31); src[y*stride-1] = p1; src[y*stride+0] = p2; ad1= ABS(d1)>>1; d2= clip((p0-p3)/4, -ad1, ad1); src[y*stride-2] = p0 - d2; src[y*stride+1] = p3 + d2; } } #endif #if 0 static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int s, i; s = 0; for(i=0;i>(BASIS_SHIFT - RECON_SHIFT)); int w= weight[i]; b>>= RECON_SHIFT; assert(-512>4; } return sum>>2; } static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){ int i; for(i=0; i<8*8; i++){ rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT); } } /** * permutes an 8x8 block. * @param block the block which will be permuted according to the given permutation vector * @param permutation the permutation vector * @param last the last non zero coefficient in scantable order, used to speed the permutation up * @param scantable the used scantable, this is only used to speed the permutation up, the block is not * (inverse) permutated to scantable order! */ void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last) { int i; DCTELEM temp[64]; if(last<=0) return; //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms for(i=0; i<=last; i++){ const int j= scantable[i]; temp[j]= block[j]; block[j]=0; } for(i=0; i<=last; i++){ const int j= scantable[i]; const int perm_j= permutation[j]; block[perm_j]= temp[j]; } } static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){ return 0; } void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){ int i; memset(cmp, 0, sizeof(void*)*5); for(i=0; i<5; i++){ switch(type&0xFF){ case FF_CMP_SAD: cmp[i]= c->sad[i]; break; case FF_CMP_SATD: cmp[i]= c->hadamard8_diff[i]; break; case FF_CMP_SSE: cmp[i]= c->sse[i]; break; case FF_CMP_DCT: cmp[i]= c->dct_sad[i]; break; case FF_CMP_PSNR: cmp[i]= c->quant_psnr[i]; break; case FF_CMP_BIT: cmp[i]= c->bit[i]; break; case FF_CMP_RD: cmp[i]= c->rd[i]; break; case FF_CMP_VSAD: cmp[i]= c->vsad[i]; break; case FF_CMP_VSSE: cmp[i]= c->vsse[i]; break; case FF_CMP_ZERO: cmp[i]= zero_cmp; break; default: av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n"); } } } /** * memset(blocks, 0, sizeof(DCTELEM)*6*64) */ static void clear_blocks_c(DCTELEM *blocks) { memset(blocks, 0, sizeof(DCTELEM)*6*64); } static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){ int i; for(i=0; i+7maxi){ maxi=sum; printf("MAX:%d\n", maxi); } #endif return sum; } static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){ int i; int temp[64]; int sum=0; assert(h==8); for(i=0; i<8; i++){ //FIXME try pointer walks BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]); BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]); BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]); BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]); BUTTERFLY1(temp[8*i+0], temp[8*i+2]); BUTTERFLY1(temp[8*i+1], temp[8*i+3]); BUTTERFLY1(temp[8*i+4], temp[8*i+6]); BUTTERFLY1(temp[8*i+5], temp[8*i+7]); BUTTERFLY1(temp[8*i+0], temp[8*i+4]); BUTTERFLY1(temp[8*i+1], temp[8*i+5]); BUTTERFLY1(temp[8*i+2], temp[8*i+6]); BUTTERFLY1(temp[8*i+3], temp[8*i+7]); } for(i=0; i<8; i++){ BUTTERFLY1(temp[8*0+i], temp[8*1+i]); BUTTERFLY1(temp[8*2+i], temp[8*3+i]); BUTTERFLY1(temp[8*4+i], temp[8*5+i]); BUTTERFLY1(temp[8*6+i], temp[8*7+i]); BUTTERFLY1(temp[8*0+i], temp[8*2+i]); BUTTERFLY1(temp[8*1+i], temp[8*3+i]); BUTTERFLY1(temp[8*4+i], temp[8*6+i]); BUTTERFLY1(temp[8*5+i], temp[8*7+i]); sum += BUTTERFLYA(temp[8*0+i], temp[8*4+i]) +BUTTERFLYA(temp[8*1+i], temp[8*5+i]) +BUTTERFLYA(temp[8*2+i], temp[8*6+i]) +BUTTERFLYA(temp[8*3+i], temp[8*7+i]); } sum -= ABS(temp[8*0] + temp[8*4]); // -mean return sum; } static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8]; DCTELEM * const temp= (DCTELEM*)aligned_temp; int sum=0, i; assert(h==8); s->dsp.diff_pixels(temp, src1, src2, stride); s->dsp.fdct(temp); for(i=0; i<64; i++) sum+= ABS(temp[i]); return sum; } void simple_idct(DCTELEM *block); //FIXME static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64*2/8]; DCTELEM * const temp= (DCTELEM*)aligned_temp; DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64; int sum=0, i; assert(h==8); s->mb_intra=0; s->dsp.diff_pixels(temp, src1, src2, stride); memcpy(bak, temp, 64*sizeof(DCTELEM)); s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); s->dct_unquantize_inter(s, temp, 0, s->qscale); simple_idct(temp); //FIXME for(i=0; i<64; i++) sum+= (temp[i]-bak[i])*(temp[i]-bak[i]); return sum; } static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; const uint8_t *scantable= s->intra_scantable.permutated; uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8]; uint64_t __align8 aligned_bak[stride]; DCTELEM * const temp= (DCTELEM*)aligned_temp; uint8_t * const bak= (uint8_t*)aligned_bak; int i, last, run, bits, level, distoration, start_i; const int esc_length= s->ac_esc_length; uint8_t * length; uint8_t * last_length; assert(h==8); for(i=0; i<8; i++){ ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0]; ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1]; } s->dsp.diff_pixels(temp, src1, src2, stride); s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); bits=0; if (s->mb_intra) { start_i = 1; length = s->intra_ac_vlc_length; last_length= s->intra_ac_vlc_last_length; bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma } else { start_i = 0; length = s->inter_ac_vlc_length; last_length= s->inter_ac_vlc_last_length; } if(last>=start_i){ run=0; for(i=start_i; i=0){ if(s->mb_intra) s->dct_unquantize_intra(s, temp, 0, s->qscale); else s->dct_unquantize_inter(s, temp, 0, s->qscale); } s->dsp.idct_add(bak, stride, temp); distoration= s->dsp.sse[1](NULL, bak, src1, stride, 8); return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7); } static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; const uint8_t *scantable= s->intra_scantable.permutated; uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8]; DCTELEM * const temp= (DCTELEM*)aligned_temp; int i, last, run, bits, level, start_i; const int esc_length= s->ac_esc_length; uint8_t * length; uint8_t * last_length; assert(h==8); s->dsp.diff_pixels(temp, src1, src2, stride); s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); bits=0; if (s->mb_intra) { start_i = 1; length = s->intra_ac_vlc_length; last_length= s->intra_ac_vlc_last_length; bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma } else { start_i = 0; length = s->inter_ac_vlc_length; last_length= s->inter_ac_vlc_last_length; } if(last>=start_i){ run=0; for(i=start_i; idct_algo==FF_DCT_FASTINT) { c->fdct = fdct_ifast; c->fdct248 = fdct_ifast248; } else if(avctx->dct_algo==FF_DCT_FAAN) { c->fdct = ff_faandct; c->fdct248 = ff_faandct248; } else { c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default c->fdct248 = ff_fdct248_islow; } #endif //CONFIG_ENCODERS if(avctx->idct_algo==FF_IDCT_INT){ c->idct_put= ff_jref_idct_put; c->idct_add= ff_jref_idct_add; c->idct = j_rev_dct; c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM; }else{ //accurate/default c->idct_put= simple_idct_put; c->idct_add= simple_idct_add; c->idct = simple_idct; c->idct_permutation_type= FF_NO_IDCT_PERM; } c->get_pixels = get_pixels_c; c->diff_pixels = diff_pixels_c; c->put_pixels_clamped = put_pixels_clamped_c; c->add_pixels_clamped = add_pixels_clamped_c; c->gmc1 = gmc1_c; c->gmc = gmc_c; c->clear_blocks = clear_blocks_c; c->pix_sum = pix_sum_c; c->pix_norm1 = pix_norm1_c; /* TODO [0] 16 [1] 8 */ c->pix_abs[0][0] = pix_abs16_c; c->pix_abs[0][1] = pix_abs16_x2_c; c->pix_abs[0][2] = pix_abs16_y2_c; c->pix_abs[0][3] = pix_abs16_xy2_c; c->pix_abs[1][0] = pix_abs8_c; c->pix_abs[1][1] = pix_abs8_x2_c; c->pix_abs[1][2] = pix_abs8_y2_c; c->pix_abs[1][3] = pix_abs8_xy2_c; #define dspfunc(PFX, IDX, NUM) \ c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \ c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \ c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \ c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c dspfunc(put, 0, 16); dspfunc(put_no_rnd, 0, 16); dspfunc(put, 1, 8); dspfunc(put_no_rnd, 1, 8); dspfunc(put, 2, 4); dspfunc(put, 3, 2); dspfunc(avg, 0, 16); dspfunc(avg_no_rnd, 0, 16); dspfunc(avg, 1, 8); dspfunc(avg_no_rnd, 1, 8); dspfunc(avg, 2, 4); dspfunc(avg, 3, 2); #undef dspfunc c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c; c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c; c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c; c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c; c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c; c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c; c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c; c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c; c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c; c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c; c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c; c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c; c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c; c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c; c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c; c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c; c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c; c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c; #define dspfunc(PFX, IDX, NUM) \ c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \ c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \ c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \ c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \ c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \ c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \ c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \ c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \ c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \ c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \ c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \ c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \ c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \ c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \ c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \ c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c dspfunc(put_qpel, 0, 16); dspfunc(put_no_rnd_qpel, 0, 16); dspfunc(avg_qpel, 0, 16); /* dspfunc(avg_no_rnd_qpel, 0, 16); */ dspfunc(put_qpel, 1, 8); dspfunc(put_no_rnd_qpel, 1, 8); dspfunc(avg_qpel, 1, 8); /* dspfunc(avg_no_rnd_qpel, 1, 8); */ dspfunc(put_h264_qpel, 0, 16); dspfunc(put_h264_qpel, 1, 8); dspfunc(put_h264_qpel, 2, 4); dspfunc(avg_h264_qpel, 0, 16); dspfunc(avg_h264_qpel, 1, 8); dspfunc(avg_h264_qpel, 2, 4); #undef dspfunc c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c; c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c; c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c; c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c; c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c; c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c; c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c; c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c; c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c; c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c; c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c; c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c; c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c; c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c; #define SET_CMP_FUNC(name) \ c->name[0]= name ## 16_c;\ c->name[1]= name ## 8x8_c; SET_CMP_FUNC(hadamard8_diff) c->hadamard8_diff[4]= hadamard8_intra16_c; SET_CMP_FUNC(dct_sad) c->sad[0]= pix_abs16_c; c->sad[1]= pix_abs8_c; c->sse[0]= sse16_c; c->sse[1]= sse8_c; SET_CMP_FUNC(quant_psnr) SET_CMP_FUNC(rd) SET_CMP_FUNC(bit) c->vsad[0]= vsad16_c; c->vsad[4]= vsad_intra16_c; c->vsse[0]= vsse16_c; c->vsse[4]= vsse_intra16_c; c->add_bytes= add_bytes_c; c->diff_bytes= diff_bytes_c; c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c; c->bswap_buf= bswap_buf; #if 0 c->h263_h_loop_filter= h263_h_loop_filter_c; c->h263_v_loop_filter= h263_v_loop_filter_c; #endif c->try_8x8basis= try_8x8basis_c; c->add_8x8basis= add_8x8basis_c; #ifdef HAVE_MMX dsputil_init_mmx(c, avctx); #endif #ifdef ARCH_ARMV4L dsputil_init_armv4l(c, avctx); #endif #ifdef HAVE_MLIB dsputil_init_mlib(c, avctx); #endif #ifdef ARCH_ALPHA dsputil_init_alpha(c, avctx); #endif #ifdef ARCH_POWERPC dsputil_init_ppc(c, avctx); #endif #ifdef HAVE_MMI dsputil_init_mmi(c, avctx); #endif #ifdef ARCH_SH4 dsputil_init_sh4(c,avctx); #endif switch(c->idct_permutation_type){ case FF_NO_IDCT_PERM: for(i=0; i<64; i++) c->idct_permutation[i]= i; break; case FF_LIBMPEG2_IDCT_PERM: for(i=0; i<64; i++) c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2); break; case FF_SIMPLE_IDCT_PERM: for(i=0; i<64; i++) c->idct_permutation[i]= simple_mmx_permutation[i]; break; case FF_TRANSPOSE_IDCT_PERM: for(i=0; i<64; i++) c->idct_permutation[i]= ((i&7)<<3) | (i>>3); break; default: av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n"); } } #endif xmms-wma-1.0.5/ffmpeg-strip-wma/os_support.h0000644000175000017500000000143407727171267021344 0ustar whistlerwhistler#ifndef _OS_SUPPORT_H #define _OS_SUPPORT_H /** * @file os_support.h * miscellaneous OS support macros and functions. * * - usleep() (Win32, BeOS, OS/2) * - floatf() (OS/2) * - strcasecmp() (OS/2) */ #ifdef __MINGW32__ # undef DATADIR /* clashes with /usr/include/w32api/objidl.h */ __declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds); // # include # define usleep(t) Sleep((t) / 1000) #endif #ifdef __BEOS__ # ifndef usleep # include # define usleep(t) snooze((bigtime_t)(t)) # endif #endif #if defined(CONFIG_OS2) #include static inline int usleep(unsigned int t) { return _sleep2(t / 1000); } static inline int strcasecmp(const char* s1, const char* s2) { return stricmp(s1,s2); } #endif #endif /* _OS_SUPPORT_H */ xmms-wma-1.0.5/ffmpeg-strip-wma/utils.c0000644000175000017500000005312010016235672020243 0ustar whistlerwhistler/* * utils for libavcodec * Copyright (c) 2001 Fabrice Bellard. * Copyright (c) 2003 Michel Bardiaux for the av_log API * Copyright (c) 2002-2004 Michael Niedermayer * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file utils.c * utils. */ #include "avcodec.h" #include "dsputil.h" //#include "mpegvideo.h" #include void *av_mallocz(unsigned int size) { void *ptr; ptr = av_malloc(size); if (!ptr) return NULL; memset(ptr, 0, size); return ptr; } char *av_strdup(const char *s) { char *ptr; int len; len = strlen(s) + 1; ptr = av_malloc(len); if (!ptr) return NULL; memcpy(ptr, s, len); return ptr; } /** * realloc which does nothing if the block is large enough */ void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) { if(min_size < *size) return ptr; *size= min_size + 10*1024; return av_realloc(ptr, *size); } /* allocation of static arrays - do not use for normal allocation */ static unsigned int last_static = 0; static char*** array_static = NULL; static const unsigned int grow_static = 64; // ^2 void *__av_mallocz_static(void** location, unsigned int size) { unsigned int l = (last_static + grow_static) & ~(grow_static - 1); void *ptr = av_mallocz(size); if (!ptr) return NULL; if (location) { if (l > last_static) array_static = av_realloc(array_static, l); array_static[last_static++] = (char**) location; *location = ptr; } return ptr; } /* free all static arrays and reset pointers to 0 */ void av_free_static(void) { if (array_static) { unsigned i; for (i = 0; i < last_static; i++) { av_free(*array_static[i]); *array_static[i] = NULL; } av_free(array_static); array_static = 0; } last_static = 0; } /* cannot call it directly because of 'void **' casting is not automatic */ void __av_freep(void **ptr) { av_free(*ptr); *ptr = NULL; } /* encoder management */ AVCodec *first_avcodec; void register_avcodec(AVCodec *format) { AVCodec **p; p = &first_avcodec; while (*p != NULL) p = &(*p)->next; *p = format; format->next = NULL; } typedef struct InternalBuffer{ int last_pic_num; uint8_t *base[4]; uint8_t *data[4]; int linesize[4]; }InternalBuffer; #define INTERNAL_BUFFER_SIZE 32 #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1)) void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ int w_align= 1; int h_align= 1; switch(s->pix_fmt){ case PIX_FMT_YUV420P: case PIX_FMT_YUV422: case PIX_FMT_YUV422P: case PIX_FMT_YUV444P: case PIX_FMT_GRAY8: case PIX_FMT_YUVJ420P: case PIX_FMT_YUVJ422P: case PIX_FMT_YUVJ444P: w_align= 16; //FIXME check for non mpeg style codecs and use less alignment h_align= 16; break; case PIX_FMT_YUV411P: w_align=32; h_align=8; break; case PIX_FMT_YUV410P: if(s->codec_id == CODEC_ID_SVQ1){ w_align=64; h_align=64; } break; default: w_align= 1; h_align= 1; break; } *width = ALIGN(*width , w_align); *height= ALIGN(*height, h_align); } #if 0 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ int i; int w= s->width; int h= s->height; InternalBuffer *buf; int *picture_number; assert(pic->data[0]==NULL); assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count); if(s->internal_buffer==NULL){ s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer)); } #if 0 s->internal_buffer= av_fast_realloc( s->internal_buffer, &s->internal_buffer_size, sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ ); #endif buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack (*picture_number)++; if(buf->base[0]){ pic->age= *picture_number - buf->last_pic_num; buf->last_pic_num= *picture_number; }else{ int h_chroma_shift, v_chroma_shift; int s_align, pixel_size; avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); switch(s->pix_fmt){ case PIX_FMT_RGB555: case PIX_FMT_RGB565: case PIX_FMT_YUV422: pixel_size=2; break; case PIX_FMT_RGB24: case PIX_FMT_BGR24: pixel_size=3; break; case PIX_FMT_RGBA32: pixel_size=4; break; default: pixel_size=1; } avcodec_align_dimensions(s, &w, &h); #if defined(ARCH_POWERPC) || defined(HAVE_MMI) //FIXME some cleaner check s_align= 16; #else s_align= 8; #endif #if 0 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ w+= EDGE_WIDTH*2; h+= EDGE_WIDTH*2; } #endif buf->last_pic_num= -256*256*256*64; for(i=0; i<3; i++){ const int h_shift= i==0 ? 0 : h_chroma_shift; const int v_shift= i==0 ? 0 : v_chroma_shift; buf->linesize[i]= ALIGN(pixel_size*w>>h_shift, s_align); buf->base[i]= av_mallocz((buf->linesize[i]*h>>v_shift)+16); //FIXME 16 if(buf->base[i]==NULL) return -1; memset(buf->base[i], 128, buf->linesize[i]*h>>v_shift); #if 0 if(s->flags&CODEC_FLAG_EMU_EDGE) buf->data[i] = buf->base[i]; else buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), s_align); #endif } pic->age= 256*256*256*64; } pic->type= FF_BUFFER_TYPE_INTERNAL; for(i=0; i<4; i++){ pic->base[i]= buf->base[i]; pic->data[i]= buf->data[i]; pic->linesize[i]= buf->linesize[i]; } s->internal_buffer_count++; return 0; } #endif void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ int i; InternalBuffer *buf, *last, temp; assert(pic->type==FF_BUFFER_TYPE_INTERNAL); assert(s->internal_buffer_count); buf = NULL; /* avoids warning */ for(i=0; iinternal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize buf= &((InternalBuffer*)s->internal_buffer)[i]; if(buf->data[0] == pic->data[0]) break; } assert(i < s->internal_buffer_count); s->internal_buffer_count--; last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; temp= *buf; *buf= *last; *last= temp; for(i=0; i<3; i++){ pic->data[i]=NULL; // pic->base[i]=NULL; } //printf("R%X\n", pic->opaque); } #if 0 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ AVFrame temp_pic; int i; /* If no picture return a new buffer */ if(pic->data[0] == NULL) { /* We will copy from buffer, so must be readable */ pic->buffer_hints |= FF_BUFFER_HINTS_READABLE; return s->get_buffer(s, pic); } /* If internal buffer type return the same buffer */ if(pic->type == FF_BUFFER_TYPE_INTERNAL) return 0; /* * Not internal type and reget_buffer not overridden, emulate cr buffer */ temp_pic = *pic; for(i = 0; i < 4; i++) pic->data[i] = pic->base[i] = NULL; pic->opaque = NULL; /* Allocate new frame */ if (s->get_buffer(s, pic)) return -1; /* Copy image data from old buffer to new buffer */ img_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width, s->height); s->release_buffer(s, &temp_pic); // Release old frame return 0; } #endif enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){ return fmt[0]; } void avcodec_get_context_defaults(AVCodecContext *s){ s->bit_rate= 800*1000; s->bit_rate_tolerance= s->bit_rate*10; s->qmin= 2; s->qmax= 31; s->mb_qmin= 2; s->mb_qmax= 31; s->rc_eq= "tex^qComp"; s->qcompress= 0.5; s->max_qdiff= 3; s->b_quant_factor=1.25; s->b_quant_offset=1.25; s->i_quant_factor=-0.8; s->i_quant_offset=0.0; s->error_concealment= 3; s->error_resilience= 1; s->workaround_bugs= FF_BUG_AUTODETECT; s->frame_rate_base= 1; s->frame_rate = 25; s->gop_size= 50; s->me_method= ME_EPZS; //s->get_buffer= avcodec_default_get_buffer; s->release_buffer= avcodec_default_release_buffer; s->get_format= avcodec_default_get_format; s->me_subpel_quality=8; s->lmin= FF_QP2LAMBDA * s->qmin; s->lmax= FF_QP2LAMBDA * s->qmax; //s->sample_aspect_ratio= (AVRational){0,1}; s->ildct_cmp= FF_CMP_VSAD; s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS; s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS; s->palctrl = NULL; //s->reget_buffer= avcodec_default_reget_buffer; } /** * allocates a AVCodecContext and set it to defaults. * this can be deallocated by simply calling free() */ AVCodecContext *avcodec_alloc_context(void){ AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext)); if(avctx==NULL) return NULL; avcodec_get_context_defaults(avctx); return avctx; } /** * allocates a AVPFrame and set it to defaults. * this can be deallocated by simply calling free() */ AVFrame *avcodec_alloc_frame(void){ AVFrame *pic= av_mallocz(sizeof(AVFrame)); return pic; } int avcodec_open(AVCodecContext *avctx, AVCodec *codec) { int ret; if(avctx->codec) return -1; avctx->codec = codec; avctx->codec_id = codec->id; avctx->frame_number = 0; if (codec->priv_data_size > 0) { avctx->priv_data = av_mallocz(codec->priv_data_size); if (!avctx->priv_data) return -ENOMEM; } else { avctx->priv_data = NULL; } ret = avctx->codec->init(avctx); if (ret < 0) { av_freep(&avctx->priv_data); return ret; } return 0; } int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples) { int ret; ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples); avctx->frame_number++; return ret; } int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVFrame *pict) { int ret; ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict); emms_c(); //needed to avoid a emms_c() call before every return; avctx->frame_number++; return ret; } /** * decode a frame. * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end * @param buf_size the size of the buffer in bytes * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero * @return -1 if error, otherwise return the number of * bytes used. */ int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, uint8_t *buf, int buf_size) { int ret; ret = avctx->codec->decode(avctx, picture, got_picture_ptr, buf, buf_size); emms_c(); //needed to avoid a emms_c() call before every return; if (*got_picture_ptr) avctx->frame_number++; return ret; } /* decode an audio frame. return -1 if error, otherwise return the *number of bytes used. If no frame could be decompressed, *frame_size_ptr is zero. Otherwise, it is the decompressed frame *size in BYTES. */ int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, uint8_t *buf, int buf_size) { int ret; ret = avctx->codec->decode(avctx, samples, frame_size_ptr, buf, buf_size); avctx->frame_number++; return ret; } int avcodec_close(AVCodecContext *avctx) { if (avctx->codec->close) avctx->codec->close(avctx); av_freep(&avctx->priv_data); avctx->codec = NULL; return 0; } AVCodec *avcodec_find_encoder(enum CodecID id) { AVCodec *p; p = first_avcodec; while (p) { if (p->encode != NULL && p->id == id) return p; p = p->next; } return NULL; } AVCodec *avcodec_find_encoder_by_name(const char *name) { AVCodec *p; p = first_avcodec; while (p) { if (p->encode != NULL && strcmp(name,p->name) == 0) return p; p = p->next; } return NULL; } AVCodec *avcodec_find_decoder(enum CodecID id) { AVCodec *p; p = first_avcodec; while (p) { if (p->decode != NULL && p->id == id) return p; p = p->next; } return NULL; } AVCodec *avcodec_find_decoder_by_name(const char *name) { AVCodec *p; p = first_avcodec; while (p) { if (p->decode != NULL && strcmp(name,p->name) == 0) return p; p = p->next; } return NULL; } AVCodec *avcodec_find(enum CodecID id) { AVCodec *p; p = first_avcodec; while (p) { if (p->id == id) return p; p = p->next; } return NULL; } void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) { const char *codec_name; AVCodec *p; char buf1[32]; char channels_str[100]; int bitrate; if (encode) p = avcodec_find_encoder(enc->codec_id); else p = avcodec_find_decoder(enc->codec_id); if (p) { codec_name = p->name; if (!encode && enc->codec_id == CODEC_ID_MP3) { if (enc->sub_id == 2) codec_name = "mp2"; else if (enc->sub_id == 1) codec_name = "mp1"; } } else if (enc->codec_id == CODEC_ID_MPEG2TS) { /* fake mpeg2 transport stream codec (currently not registered) */ codec_name = "mpeg2ts"; } else if (enc->codec_name[0] != '\0') { codec_name = enc->codec_name; } else { /* output avi tags */ if (enc->codec_type == CODEC_TYPE_VIDEO) { snprintf(buf1, sizeof(buf1), "%c%c%c%c", enc->codec_tag & 0xff, (enc->codec_tag >> 8) & 0xff, (enc->codec_tag >> 16) & 0xff, (enc->codec_tag >> 24) & 0xff); } else { snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag); } codec_name = buf1; } switch(enc->codec_type) { #if 0 case CODEC_TYPE_VIDEO: snprintf(buf, buf_size, "Video: %s%s", codec_name, enc->mb_decision ? " (hq)" : ""); if (enc->codec_id == CODEC_ID_RAWVIDEO) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %s", avcodec_get_pix_fmt_name(enc->pix_fmt)); } if (enc->width) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %dx%d, %0.2f fps", enc->width, enc->height, (float)enc->frame_rate / enc->frame_rate_base); } if (encode) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", q=%d-%d", enc->qmin, enc->qmax); } bitrate = enc->bit_rate; break; #endif case CODEC_TYPE_AUDIO: snprintf(buf, buf_size, "Audio: %s", codec_name); switch (enc->channels) { case 1: strcpy(channels_str, "mono"); break; case 2: strcpy(channels_str, "stereo"); break; case 6: strcpy(channels_str, "5:1"); break; default: sprintf(channels_str, "%d channels", enc->channels); break; } if (enc->sample_rate) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %d Hz, %s", enc->sample_rate, channels_str); } /* for PCM codecs, compute bitrate directly */ switch(enc->codec_id) { case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_U16BE: bitrate = enc->sample_rate * enc->channels * 16; break; case CODEC_ID_PCM_S8: case CODEC_ID_PCM_U8: case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_MULAW: bitrate = enc->sample_rate * enc->channels * 8; break; default: bitrate = enc->bit_rate; break; } break; case CODEC_TYPE_DATA: snprintf(buf, buf_size, "Data: %s", codec_name); bitrate = enc->bit_rate; break; default: av_abort(); } if (encode) { if (enc->flags & CODEC_FLAG_PASS1) snprintf(buf + strlen(buf), buf_size - strlen(buf), ", pass 1"); if (enc->flags & CODEC_FLAG_PASS2) snprintf(buf + strlen(buf), buf_size - strlen(buf), ", pass 2"); } if (bitrate != 0) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %d kb/s", bitrate / 1000); } } unsigned avcodec_version( void ) { return LIBAVCODEC_VERSION_INT; } unsigned avcodec_build( void ) { return LIBAVCODEC_BUILD; } /* must be called before any other functions */ void avcodec_init(void) { static int inited = 0; if (inited != 0) return; inited = 1; dsputil_static_init(); } /** * Flush buffers, should be called when seeking or when swicthing to a different stream. */ void avcodec_flush_buffers(AVCodecContext *avctx) { if(avctx->codec->flush) avctx->codec->flush(avctx); } void avcodec_default_free_buffers(AVCodecContext *s){ int i, j; if(s->internal_buffer==NULL) return; for(i=0; iinternal_buffer)[i]; for(j=0; j<4; j++){ av_freep(&buf->base[j]); buf->data[j]= NULL; } } av_freep(&s->internal_buffer); s->internal_buffer_count=0; } #if 0 char av_get_pict_type_char(int pict_type){ switch(pict_type){ case I_TYPE: return 'I'; case P_TYPE: return 'P'; case B_TYPE: return 'B'; case S_TYPE: return 'S'; case SI_TYPE:return 'i'; case SP_TYPE:return 'p'; default: return '?'; } } int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){ int exact=1, sign=0; int64_t gcd; assert(den != 0); if(den < 0){ den= -den; nom= -nom; } if(nom < 0){ nom= -nom; sign= 1; } gcd = ff_gcd(nom, den); nom /= gcd; den /= gcd; if(nom > max || den > max){ AVRational a0={0,1}, a1={1,0}; exact=0; for(;;){ int64_t x= nom / den; int64_t a2n= x*a1.num + a0.num; int64_t a2d= x*a1.den + a0.den; if(a2n > max || a2d > max) break; nom %= den; a0= a1; a1= (AVRational){a2n, a2d}; if(nom==0) break; x= nom; nom=den; den=x; } nom= a1.num; den= a1.den; } assert(ff_gcd(nom, den) == 1); if(sign) nom= -nom; *dst_nom = nom; *dst_den = den; return exact; } #endif int64_t av_rescale(int64_t a, int b, int c){ uint64_t h, l; assert(c > 0); assert(b >=0); if(a<0) return -av_rescale(-a, b, c); h= a>>32; if(h==0) return a*b/c; l= a&0xFFFFFFFF; l *= b; h *= b; l += (h%c)<<32; return ((h/c)<<32) + l/c; } /* av_log API */ #ifdef AV_LOG_TRAP_PRINTF #undef stderr #undef fprintf #endif static int av_log_level = AV_LOG_DEBUG; static void av_log_default_callback(AVCodecContext* avctx, int level, const char* fmt, va_list vl) { static int print_prefix=1; if(level>av_log_level) return; if(avctx && print_prefix) fprintf(stderr, "[%s @ %p]", avctx->codec ? avctx->codec->name : "?", avctx); print_prefix= strstr(fmt, "\n") != NULL; vfprintf(stderr, fmt, vl); } static void (*av_log_callback)(AVCodecContext*, int, const char*, va_list) = av_log_default_callback; void av_log(AVCodecContext* avctx, int level, const char *fmt, ...) { va_list vl; va_start(vl, fmt); av_vlog(avctx, level, fmt, vl); va_end(vl); } void av_vlog(AVCodecContext* avctx, int level, const char *fmt, va_list vl) { av_log_callback(avctx, level, fmt, vl); } int av_log_get_level(void) { return av_log_level; } void av_log_set_level(int level) { av_log_level = level; } void av_log_set_callback(void (*callback)(AVCodecContext*, int, const char*, va_list)) { av_log_callback = callback; } xmms-wma-1.0.5/ffmpeg-strip-wma/simple_idct.c0000644000175000017500000003711307631630663021413 0ustar whistlerwhistler/* * Simple IDCT * * Copyright (c) 2001 Michael Niedermayer * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file simple_idct.c * simpleidct in C. */ /* based upon some outcommented c code from mpeg2dec (idct_mmx.c written by Aaron Holtzman ) */ #include "avcodec.h" #include "dsputil.h" #include "simple_idct.h" #if 0 #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */ #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */ #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */ #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */ #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */ #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */ #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */ #define ROW_SHIFT 8 #define COL_SHIFT 17 #else #define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 #define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 #define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 #define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 #define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 #define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 #define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 #define ROW_SHIFT 11 #define COL_SHIFT 20 // 6 #endif #if defined(ARCH_POWERPC_405) /* signed 16x16 -> 32 multiply add accumulate */ #define MAC16(rt, ra, rb) \ asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb)); /* signed 16x16 -> 32 multiply */ #define MUL16(rt, ra, rb) \ asm ("mullhw %0, %1, %2" : "=r" (rt) : "r" (ra), "r" (rb)); #else /* signed 16x16 -> 32 multiply add accumulate */ #define MAC16(rt, ra, rb) rt += (ra) * (rb) /* signed 16x16 -> 32 multiply */ #define MUL16(rt, ra, rb) rt = (ra) * (rb) #endif static inline void idctRowCondDC (DCTELEM * row) { int a0, a1, a2, a3, b0, b1, b2, b3; #ifdef FAST_64BIT uint64_t temp; #else uint32_t temp; #endif #ifdef FAST_64BIT #ifdef WORDS_BIGENDIAN #define ROW0_MASK 0xffff000000000000LL #else #define ROW0_MASK 0xffffLL #endif if(sizeof(DCTELEM)==2){ if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) | ((uint64_t *)row)[1]) == 0) { temp = (row[0] << 3) & 0xffff; temp += temp << 16; temp += temp << 32; ((uint64_t *)row)[0] = temp; ((uint64_t *)row)[1] = temp; return; } }else{ if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) { row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3; return; } } #else if(sizeof(DCTELEM)==2){ if (!(((uint32_t*)row)[1] | ((uint32_t*)row)[2] | ((uint32_t*)row)[3] | row[1])) { temp = (row[0] << 3) & 0xffff; temp += temp << 16; ((uint32_t*)row)[0]=((uint32_t*)row)[1] = ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp; return; } }else{ if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) { row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3; return; } } #endif a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1)); a1 = a0; a2 = a0; a3 = a0; /* no need to optimize : gcc does it */ a0 += W2 * row[2]; a1 += W6 * row[2]; a2 -= W6 * row[2]; a3 -= W2 * row[2]; MUL16(b0, W1, row[1]); MAC16(b0, W3, row[3]); MUL16(b1, W3, row[1]); MAC16(b1, -W7, row[3]); MUL16(b2, W5, row[1]); MAC16(b2, -W1, row[3]); MUL16(b3, W7, row[1]); MAC16(b3, -W5, row[3]); #ifdef FAST_64BIT temp = ((uint64_t*)row)[1]; #else temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3]; #endif if (temp != 0) { a0 += W4*row[4] + W6*row[6]; a1 += - W4*row[4] - W2*row[6]; a2 += - W4*row[4] + W2*row[6]; a3 += W4*row[4] - W6*row[6]; MAC16(b0, W5, row[5]); MAC16(b0, W7, row[7]); MAC16(b1, -W1, row[5]); MAC16(b1, -W5, row[7]); MAC16(b2, W7, row[5]); MAC16(b2, W3, row[7]); MAC16(b3, W3, row[5]); MAC16(b3, -W1, row[7]); } row[0] = (a0 + b0) >> ROW_SHIFT; row[7] = (a0 - b0) >> ROW_SHIFT; row[1] = (a1 + b1) >> ROW_SHIFT; row[6] = (a1 - b1) >> ROW_SHIFT; row[2] = (a2 + b2) >> ROW_SHIFT; row[5] = (a2 - b2) >> ROW_SHIFT; row[3] = (a3 + b3) >> ROW_SHIFT; row[4] = (a3 - b3) >> ROW_SHIFT; } static inline void idctSparseColPut (uint8_t *dest, int line_size, DCTELEM * col) { int a0, a1, a2, a3, b0, b1, b2, b3; uint8_t *cm = cropTbl + MAX_NEG_CROP; /* XXX: I did that only to give same values as previous code */ a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4)); a1 = a0; a2 = a0; a3 = a0; a0 += + W2*col[8*2]; a1 += + W6*col[8*2]; a2 += - W6*col[8*2]; a3 += - W2*col[8*2]; MUL16(b0, W1, col[8*1]); MUL16(b1, W3, col[8*1]); MUL16(b2, W5, col[8*1]); MUL16(b3, W7, col[8*1]); MAC16(b0, + W3, col[8*3]); MAC16(b1, - W7, col[8*3]); MAC16(b2, - W1, col[8*3]); MAC16(b3, - W5, col[8*3]); if(col[8*4]){ a0 += + W4*col[8*4]; a1 += - W4*col[8*4]; a2 += - W4*col[8*4]; a3 += + W4*col[8*4]; } if (col[8*5]) { MAC16(b0, + W5, col[8*5]); MAC16(b1, - W1, col[8*5]); MAC16(b2, + W7, col[8*5]); MAC16(b3, + W3, col[8*5]); } if(col[8*6]){ a0 += + W6*col[8*6]; a1 += - W2*col[8*6]; a2 += + W2*col[8*6]; a3 += - W6*col[8*6]; } if (col[8*7]) { MAC16(b0, + W7, col[8*7]); MAC16(b1, - W5, col[8*7]); MAC16(b2, + W3, col[8*7]); MAC16(b3, - W1, col[8*7]); } dest[0] = cm[(a0 + b0) >> COL_SHIFT]; dest += line_size; dest[0] = cm[(a1 + b1) >> COL_SHIFT]; dest += line_size; dest[0] = cm[(a2 + b2) >> COL_SHIFT]; dest += line_size; dest[0] = cm[(a3 + b3) >> COL_SHIFT]; dest += line_size; dest[0] = cm[(a3 - b3) >> COL_SHIFT]; dest += line_size; dest[0] = cm[(a2 - b2) >> COL_SHIFT]; dest += line_size; dest[0] = cm[(a1 - b1) >> COL_SHIFT]; dest += line_size; dest[0] = cm[(a0 - b0) >> COL_SHIFT]; } static inline void idctSparseColAdd (uint8_t *dest, int line_size, DCTELEM * col) { int a0, a1, a2, a3, b0, b1, b2, b3; uint8_t *cm = cropTbl + MAX_NEG_CROP; /* XXX: I did that only to give same values as previous code */ a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4)); a1 = a0; a2 = a0; a3 = a0; a0 += + W2*col[8*2]; a1 += + W6*col[8*2]; a2 += - W6*col[8*2]; a3 += - W2*col[8*2]; MUL16(b0, W1, col[8*1]); MUL16(b1, W3, col[8*1]); MUL16(b2, W5, col[8*1]); MUL16(b3, W7, col[8*1]); MAC16(b0, + W3, col[8*3]); MAC16(b1, - W7, col[8*3]); MAC16(b2, - W1, col[8*3]); MAC16(b3, - W5, col[8*3]); if(col[8*4]){ a0 += + W4*col[8*4]; a1 += - W4*col[8*4]; a2 += - W4*col[8*4]; a3 += + W4*col[8*4]; } if (col[8*5]) { MAC16(b0, + W5, col[8*5]); MAC16(b1, - W1, col[8*5]); MAC16(b2, + W7, col[8*5]); MAC16(b3, + W3, col[8*5]); } if(col[8*6]){ a0 += + W6*col[8*6]; a1 += - W2*col[8*6]; a2 += + W2*col[8*6]; a3 += - W6*col[8*6]; } if (col[8*7]) { MAC16(b0, + W7, col[8*7]); MAC16(b1, - W5, col[8*7]); MAC16(b2, + W3, col[8*7]); MAC16(b3, - W1, col[8*7]); } dest[0] = cm[dest[0] + ((a0 + b0) >> COL_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((a1 + b1) >> COL_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((a2 + b2) >> COL_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((a3 + b3) >> COL_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((a3 - b3) >> COL_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((a2 - b2) >> COL_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((a1 - b1) >> COL_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((a0 - b0) >> COL_SHIFT)]; } static inline void idctSparseCol (DCTELEM * col) { int a0, a1, a2, a3, b0, b1, b2, b3; /* XXX: I did that only to give same values as previous code */ a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4)); a1 = a0; a2 = a0; a3 = a0; a0 += + W2*col[8*2]; a1 += + W6*col[8*2]; a2 += - W6*col[8*2]; a3 += - W2*col[8*2]; MUL16(b0, W1, col[8*1]); MUL16(b1, W3, col[8*1]); MUL16(b2, W5, col[8*1]); MUL16(b3, W7, col[8*1]); MAC16(b0, + W3, col[8*3]); MAC16(b1, - W7, col[8*3]); MAC16(b2, - W1, col[8*3]); MAC16(b3, - W5, col[8*3]); if(col[8*4]){ a0 += + W4*col[8*4]; a1 += - W4*col[8*4]; a2 += - W4*col[8*4]; a3 += + W4*col[8*4]; } if (col[8*5]) { MAC16(b0, + W5, col[8*5]); MAC16(b1, - W1, col[8*5]); MAC16(b2, + W7, col[8*5]); MAC16(b3, + W3, col[8*5]); } if(col[8*6]){ a0 += + W6*col[8*6]; a1 += - W2*col[8*6]; a2 += + W2*col[8*6]; a3 += - W6*col[8*6]; } if (col[8*7]) { MAC16(b0, + W7, col[8*7]); MAC16(b1, - W5, col[8*7]); MAC16(b2, + W3, col[8*7]); MAC16(b3, - W1, col[8*7]); } col[0 ] = ((a0 + b0) >> COL_SHIFT); col[8 ] = ((a1 + b1) >> COL_SHIFT); col[16] = ((a2 + b2) >> COL_SHIFT); col[24] = ((a3 + b3) >> COL_SHIFT); col[32] = ((a3 - b3) >> COL_SHIFT); col[40] = ((a2 - b2) >> COL_SHIFT); col[48] = ((a1 - b1) >> COL_SHIFT); col[56] = ((a0 - b0) >> COL_SHIFT); } void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block) { int i; for(i=0; i<8; i++) idctRowCondDC(block + i*8); for(i=0; i<8; i++) idctSparseColPut(dest + i, line_size, block + i); } void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block) { int i; for(i=0; i<8; i++) idctRowCondDC(block + i*8); for(i=0; i<8; i++) idctSparseColAdd(dest + i, line_size, block + i); } void simple_idct(DCTELEM *block) { int i; for(i=0; i<8; i++) idctRowCondDC(block + i*8); for(i=0; i<8; i++) idctSparseCol(block + i); } /* 2x4x8 idct */ #define CN_SHIFT 12 #define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5)) #define C1 C_FIX(0.6532814824) #define C2 C_FIX(0.2705980501) /* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized, and the butterfly must be multiplied by 0.5 * sqrt(2.0) */ #define C_SHIFT (4+1+12) static inline void idct4col(uint8_t *dest, int line_size, const DCTELEM *col) { int c0, c1, c2, c3, a0, a1, a2, a3; const uint8_t *cm = cropTbl + MAX_NEG_CROP; a0 = col[8*0]; a1 = col[8*2]; a2 = col[8*4]; a3 = col[8*6]; c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); c1 = a1 * C1 + a3 * C2; c3 = a1 * C2 - a3 * C1; dest[0] = cm[(c0 + c1) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c2 + c3) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c2 - c3) >> C_SHIFT]; dest += line_size; dest[0] = cm[(c0 - c1) >> C_SHIFT]; } #define BF(k) \ {\ int a0, a1;\ a0 = ptr[k];\ a1 = ptr[8 + k];\ ptr[k] = a0 + a1;\ ptr[8 + k] = a0 - a1;\ } /* only used by DV codec. The input must be interlaced. 128 is added to the pixels before clamping to avoid systematic error (1024*sqrt(2)) offset would be needed otherwise. */ /* XXX: I think a 1.0/sqrt(2) normalization should be needed to compensate the extra butterfly stage - I don't have the full DV specification */ void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block) { int i; DCTELEM *ptr; /* butterfly */ ptr = block; for(i=0;i<4;i++) { BF(0); BF(1); BF(2); BF(3); BF(4); BF(5); BF(6); BF(7); ptr += 2 * 8; } /* IDCT8 on each line */ for(i=0; i<8; i++) { idctRowCondDC(block + i*8); } /* IDCT4 and store */ for(i=0;i<8;i++) { idct4col(dest + i, 2 * line_size, block + i); idct4col(dest + line_size + i, 2 * line_size, block + 8 + i); } } /* 8x4 & 4x8 WMV2 IDCT */ #undef CN_SHIFT #undef C_SHIFT #undef C_FIX #undef C1 #undef C2 #define CN_SHIFT 12 #define C_FIX(x) ((int)((x) * 1.414213562 * (1 << CN_SHIFT) + 0.5)) #define C1 C_FIX(0.6532814824) #define C2 C_FIX(0.2705980501) #define C3 C_FIX(0.5) #define C_SHIFT (4+1+12) static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col) { int c0, c1, c2, c3, a0, a1, a2, a3; const uint8_t *cm = cropTbl + MAX_NEG_CROP; a0 = col[8*0]; a1 = col[8*1]; a2 = col[8*2]; a3 = col[8*3]; c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1)); c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1)); c1 = a1 * C1 + a3 * C2; c3 = a1 * C2 - a3 * C1; dest[0] = cm[dest[0] + ((c0 + c1) >> C_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((c2 + c3) >> C_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((c2 - c3) >> C_SHIFT)]; dest += line_size; dest[0] = cm[dest[0] + ((c0 - c1) >> C_SHIFT)]; } #define RN_SHIFT 15 #define R_FIX(x) ((int)((x) * 1.414213562 * (1 << RN_SHIFT) + 0.5)) #define R1 R_FIX(0.6532814824) #define R2 R_FIX(0.2705980501) #define R3 R_FIX(0.5) #define R_SHIFT 11 static inline void idct4row(DCTELEM *row) { int c0, c1, c2, c3, a0, a1, a2, a3; //const uint8_t *cm = cropTbl + MAX_NEG_CROP; a0 = row[0]; a1 = row[1]; a2 = row[2]; a3 = row[3]; c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1)); c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1)); c1 = a1 * R1 + a3 * R2; c3 = a1 * R2 - a3 * R1; row[0]= (c0 + c1) >> R_SHIFT; row[1]= (c2 + c3) >> R_SHIFT; row[2]= (c2 - c3) >> R_SHIFT; row[3]= (c0 - c1) >> R_SHIFT; } void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block) { int i; /* IDCT8 on each line */ for(i=0; i<4; i++) { idctRowCondDC(block + i*8); } /* IDCT4 and store */ for(i=0;i<8;i++) { idct4col_add(dest + i, line_size, block + i); } } void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block) { int i; /* IDCT4 on each line */ for(i=0; i<8; i++) { idct4row(block + i*8); } /* IDCT8 and store */ for(i=0; i<4; i++){ idctSparseColAdd(dest + i, line_size, block + i); } } xmms-wma-1.0.5/ffmpeg-strip-wma/allformats.c0000644000175000017500000000631010014772273021247 0ustar whistlerwhistler/* * Register all the formats and protocols * Copyright (c) 2000, 2001, 2002 Fabrice Bellard * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avformat.h" /* If you do not call this function, then you can select exactly which formats you want to support */ /** * Initialize libavcodec and register all the codecs and formats. */ void av_register_all(void) { avcodec_init(); avcodec_register_all(); //mpegps_init(); //mpegts_init(); #ifdef CONFIG_ENCODERS crc_init(); img_init(); #endif //CONFIG_ENCODERS //raw_init(); //mp3_init(); //rm_init(); #ifdef CONFIG_RISKY asf_init(); #endif #ifdef CONFIG_ENCODERS avienc_init(); #endif //CONFIG_ENCODERS //avidec_init(); //wav_init(); //swf_init(); //au_init(); #ifdef CONFIG_ENCODERS gif_init(); #endif //CONFIG_ENCODERS //mov_init(); #ifdef CONFIG_ENCODERS movenc_init(); jpeg_init(); #endif //CONFIG_ENCODERS //dv_init(); //fourxm_init(); #ifdef CONFIG_ENCODERS flvenc_init(); #endif //CONFIG_ENCODERS //flvdec_init(); //str_init(); //roq_init(); //ipmovie_init(); //wc3_init(); //westwood_init(); //film_init(); //idcin_init(); //flic_init(); //vmd_init(); #if defined(AMR_NB) || defined(AMR_NB_FIXED) || defined(AMR_WB) amr_init(); #endif //yuv4mpeg_init(); #ifdef CONFIG_VORBIS ogg_init(); #endif #ifndef CONFIG_WIN32 //ffm_init(); #endif #ifdef CONFIG_VIDEO4LINUX video_grab_init(); #endif #if defined(CONFIG_AUDIO_OSS) || defined(CONFIG_AUDIO_BEOS) audio_init(); #endif #ifdef CONFIG_DV1394 dv1394_init(); #endif //nut_init(); #ifdef CONFIG_ENCODERS /* image formats */ av_register_image_format(&pnm_image_format); av_register_image_format(&pbm_image_format); av_register_image_format(&pgm_image_format); av_register_image_format(&ppm_image_format); av_register_image_format(&pam_image_format); av_register_image_format(&pgmyuv_image_format); av_register_image_format(&yuv_image_format); #ifdef CONFIG_ZLIB av_register_image_format(&png_image_format); #endif av_register_image_format(&jpeg_image_format); av_register_image_format(&gif_image_format); #endif //CONFIG_ENCODERS /* file protocols */ register_protocol(&file_protocol); register_protocol(&pipe_protocol); #ifdef CONFIG_NETWORK rtsp_init(); rtp_init(); register_protocol(&udp_protocol); register_protocol(&rtp_protocol); register_protocol(&tcp_protocol); register_protocol(&http_protocol); #endif } xmms-wma-1.0.5/ffmpeg-strip-wma/COPYING0000644000175000017500000006347407474013734020016 0ustar whistlerwhistler GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library 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 of the License, or (at your option) any later version. This library 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 this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! xmms-wma-1.0.5/ffmpeg-strip-wma/wmadata.h0000644000175000017500000021036507631630664020545 0ustar whistlerwhistler/** * @file wmadata.h * Various WMA tables. */ static const uint16_t wma_critical_freqs[25] = { 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500, 24500, }; /* first value is number of bands */ static const uint8_t exponent_band_22050[3][25] = { { 10, 4, 8, 4, 8, 8, 12, 20, 24, 24, 16, }, { 14, 4, 8, 8, 4, 12, 12, 16, 24, 16, 20, 24, 32, 40, 36, }, { 23, 4, 4, 4, 8, 4, 4, 8, 8, 8, 8, 8, 12, 12, 16, 16, 24, 24, 32, 44, 48, 60, 84, 72, }, }; static const uint8_t exponent_band_32000[3][25] = { { 11, 4, 4, 8, 4, 4, 12, 16, 24, 20, 28, 4, }, { 15, 4, 8, 4, 4, 8, 8, 16, 20, 12, 20, 20, 28, 40, 56, 8, }, { 16, 8, 4, 8, 8, 12, 16, 20, 24, 40, 32, 32, 44, 56, 80, 112, 16, }, }; static const uint8_t exponent_band_44100[3][25] = { { 12, 4, 4, 4, 4, 4, 8, 8, 8, 12, 16, 20, 36, }, { 15, 4, 8, 4, 8, 8, 4, 8, 8, 12, 12, 12, 24, 28, 40, 76, }, { 17, 4, 8, 8, 4, 12, 12, 8, 8, 24, 16, 20, 24, 32, 40, 60, 80, 152, }, }; static const uint16_t hgain_huffcodes[37] = { 0x00003, 0x002e7, 0x00001, 0x005cd, 0x0005d, 0x005c9, 0x0005e, 0x00003, 0x00016, 0x0000b, 0x00001, 0x00006, 0x00001, 0x00006, 0x00004, 0x00005, 0x00004, 0x00007, 0x00003, 0x00007, 0x00004, 0x0000a, 0x0000a, 0x00002, 0x00003, 0x00000, 0x00005, 0x00002, 0x0005f, 0x00004, 0x00003, 0x00002, 0x005c8, 0x000b8, 0x005ca, 0x005cb, 0x005cc, }; static const uint8_t hgain_huffbits[37] = { 10, 12, 10, 13, 9, 13, 9, 8, 7, 5, 5, 4, 4, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 8, 7, 10, 8, 10, 9, 8, 9, 9, 13, 10, 13, 13, 13, }; static const float lsp_codebook[NB_LSP_COEFS][16] = { { 1.98732877, 1.97944528, 1.97179088, 1.96260549, 1.95038374, 1.93336114, 1.90719232, 1.86191415, }, { 1.97260000, 1.96083160, 1.94982586, 1.93806164, 1.92516608, 1.91010199, 1.89232331, 1.87149812, 1.84564818, 1.81358067, 1.77620070, 1.73265264, 1.67907855, 1.60959081, 1.50829650, 1.33120330, }, { 1.90109110, 1.86482426, 1.83419671, 1.80168452, 1.76650116, 1.72816320, 1.68502700, 1.63738256, 1.58501580, 1.51795181, 1.43679906, 1.33950585, 1.24176208, 1.12260729, 0.96749668, 0.74048265, }, { 1.76943864, 1.67822463, 1.59946365, 1.53560582, 1.47470796, 1.41210167, 1.34509536, 1.27339507, 1.19303814, 1.09765169, 0.98818722, 0.87239446, 0.74369172, 0.59768184, 0.43168630, 0.17977021, }, { 1.43428349, 1.32038354, 1.21074086, 1.10577988, 1.00561746, 0.90335924, 0.80437489, 0.70709671, 0.60427395, 0.49814048, 0.38509539, 0.27106800, 0.14407416, 0.00219910, -0.16725141, -0.36936085, }, { 0.99895687, 0.84188166, 0.70753739, 0.57906595, 0.47055563, 0.36966965, 0.26826648, 0.17163380, 0.07208392, -0.03062936, -1.40037388, -0.25128968, -0.37213937, -0.51075646, -0.64887512, -0.80308031, }, { 0.26515280, 0.06313551, -0.08872080, -0.21103548, -0.31069678, -0.39680323, -0.47223474, -0.54167135, -0.61444740, -0.68943343, -0.76580211, -0.85170082, -0.95289061, -1.06514703, -1.20510707, -1.37617746, }, { -0.53940301, -0.73770929, -0.88424876, -1.01117930, -1.13389091, -1.26830073, -1.42041987, -1.62033919, -1.10158808, -1.16512566, -1.23337128, -1.30414401, -1.37663312, -1.46853845, -1.57625798, -1.66893638, }, { -0.38601997, -0.56009350, -0.66978483, -0.76028471, -0.83846064, -0.90868087, -0.97408881, -1.03694962, }, { -1.56144989, -1.65944032, -1.72689685, -1.77857740, -1.82203011, -1.86220079, -1.90283983, -1.94820479, }, }; static const uint32_t scale_huffcodes[121] = { 0x3ffe8, 0x3ffe6, 0x3ffe7, 0x3ffe5, 0x7fff5, 0x7fff1, 0x7ffed, 0x7fff6, 0x7ffee, 0x7ffef, 0x7fff0, 0x7fffc, 0x7fffd, 0x7ffff, 0x7fffe, 0x7fff7, 0x7fff8, 0x7fffb, 0x7fff9, 0x3ffe4, 0x7fffa, 0x3ffe3, 0x1ffef, 0x1fff0, 0x0fff5, 0x1ffee, 0x0fff2, 0x0fff3, 0x0fff4, 0x0fff1, 0x07ff6, 0x07ff7, 0x03ff9, 0x03ff5, 0x03ff7, 0x03ff3, 0x03ff6, 0x03ff2, 0x01ff7, 0x01ff5, 0x00ff9, 0x00ff7, 0x00ff6, 0x007f9, 0x00ff4, 0x007f8, 0x003f9, 0x003f7, 0x003f5, 0x001f8, 0x001f7, 0x000fa, 0x000f8, 0x000f6, 0x00079, 0x0003a, 0x00038, 0x0001a, 0x0000b, 0x00004, 0x00000, 0x0000a, 0x0000c, 0x0001b, 0x00039, 0x0003b, 0x00078, 0x0007a, 0x000f7, 0x000f9, 0x001f6, 0x001f9, 0x003f4, 0x003f6, 0x003f8, 0x007f5, 0x007f4, 0x007f6, 0x007f7, 0x00ff5, 0x00ff8, 0x01ff4, 0x01ff6, 0x01ff8, 0x03ff8, 0x03ff4, 0x0fff0, 0x07ff4, 0x0fff6, 0x07ff5, 0x3ffe2, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde, 0x7ffd8, 0x7ffd2, 0x7ffd3, 0x7ffd4, 0x7ffd5, 0x7ffd6, 0x7fff2, 0x7ffdf, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffe6, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffd7, 0x7ffec, 0x7fff4, 0x7fff3, }; static const uint8_t scale_huffbits[121] = { 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 19, 18, 17, 17, 16, 17, 16, 16, 16, 16, 15, 15, 14, 14, 14, 14, 14, 14, 13, 13, 12, 12, 12, 11, 12, 11, 10, 10, 10, 9, 9, 8, 8, 8, 7, 6, 6, 5, 4, 3, 1, 4, 4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 16, 15, 16, 15, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, }; static const uint32_t coef0_huffcodes[666] = { 0x00258, 0x0003d, 0x00000, 0x00005, 0x00008, 0x00008, 0x0000c, 0x0001b, 0x0001f, 0x00015, 0x00024, 0x00032, 0x0003a, 0x00026, 0x0002c, 0x0002f, 0x0004a, 0x0004d, 0x00061, 0x00070, 0x00073, 0x00048, 0x00052, 0x0005a, 0x0005d, 0x0006e, 0x00099, 0x0009e, 0x000c1, 0x000ce, 0x000e4, 0x000f0, 0x00093, 0x0009e, 0x000a2, 0x000a1, 0x000b8, 0x000d2, 0x000d3, 0x0012e, 0x00130, 0x000de, 0x0012d, 0x0019b, 0x001e4, 0x00139, 0x0013a, 0x0013f, 0x0014f, 0x0016d, 0x001a2, 0x0027c, 0x0027e, 0x00332, 0x0033c, 0x0033f, 0x0038b, 0x00396, 0x003c5, 0x00270, 0x0027c, 0x0025a, 0x00395, 0x00248, 0x004bd, 0x004fb, 0x00662, 0x00661, 0x0071b, 0x004e6, 0x004ff, 0x00666, 0x0071c, 0x0071a, 0x0071f, 0x00794, 0x00536, 0x004e2, 0x0078e, 0x004ee, 0x00518, 0x00535, 0x004fb, 0x0078d, 0x00530, 0x00680, 0x0068f, 0x005cb, 0x00965, 0x006a6, 0x00967, 0x0097f, 0x00682, 0x006ae, 0x00cd0, 0x00e28, 0x00f13, 0x00f1f, 0x009f5, 0x00cd3, 0x00f11, 0x00926, 0x00964, 0x00f32, 0x00f12, 0x00f30, 0x00966, 0x00d0b, 0x00a68, 0x00b91, 0x009c7, 0x00b73, 0x012fa, 0x0131d, 0x013f9, 0x01ca0, 0x0199c, 0x01c7a, 0x0198c, 0x01248, 0x01c74, 0x01c64, 0x0139e, 0x012fd, 0x00a77, 0x012fc, 0x01c7b, 0x012ca, 0x014cc, 0x014d2, 0x014e3, 0x014dc, 0x012dc, 0x03344, 0x02598, 0x0263c, 0x0333b, 0x025e6, 0x01a1c, 0x01e3c, 0x014e2, 0x033d4, 0x01a11, 0x03349, 0x03cce, 0x014e1, 0x01a34, 0x0273e, 0x02627, 0x0273f, 0x038ee, 0x03971, 0x03c67, 0x03c61, 0x0333d, 0x038c2, 0x0263f, 0x038cd, 0x02638, 0x02e41, 0x0351f, 0x03348, 0x03c66, 0x03562, 0x02989, 0x027d5, 0x0333c, 0x02e4f, 0x0343b, 0x02ddf, 0x04bc8, 0x029c0, 0x02e57, 0x04c72, 0x025b7, 0x03547, 0x03540, 0x029d3, 0x04c45, 0x025bb, 0x06600, 0x04c73, 0x04bce, 0x0357b, 0x029a6, 0x029d2, 0x0263e, 0x0298a, 0x07183, 0x06602, 0x07958, 0x04b66, 0x0537d, 0x05375, 0x04fe9, 0x04b67, 0x0799f, 0x04bc9, 0x051fe, 0x06a3b, 0x05bb6, 0x04fa8, 0x0728f, 0x05376, 0x0492c, 0x0537e, 0x0795a, 0x06a3c, 0x0e515, 0x07887, 0x0683a, 0x051f9, 0x051fd, 0x0cc6a, 0x06a8a, 0x0cc6d, 0x05bb3, 0x0683b, 0x051fc, 0x05378, 0x0728e, 0x07886, 0x05bb7, 0x0f2a4, 0x0795b, 0x0683c, 0x09fc1, 0x0683d, 0x0b752, 0x09678, 0x0a3e8, 0x06ac7, 0x051f0, 0x0b759, 0x06af3, 0x04b6b, 0x0f2a0, 0x0f2ad, 0x096c3, 0x0e518, 0x0b75c, 0x0d458, 0x0cc6b, 0x0537c, 0x067aa, 0x04fea, 0x0343a, 0x0cc71, 0x0967f, 0x09fc4, 0x096c2, 0x0e516, 0x0f2a1, 0x0d45c, 0x0d45d, 0x0d45e, 0x12fb9, 0x0967e, 0x1982f, 0x09883, 0x096c4, 0x0b753, 0x12fb8, 0x0f2a8, 0x1ca21, 0x096c5, 0x0e51a, 0x1ca27, 0x12f3c, 0x0d471, 0x0f2aa, 0x0b75b, 0x12fbb, 0x0f2a9, 0x0f2ac, 0x0d45a, 0x0b74f, 0x096c8, 0x16e91, 0x096ca, 0x12fbf, 0x0d0a7, 0x13103, 0x0d516, 0x16e99, 0x12cbd, 0x0a3ea, 0x19829, 0x0b755, 0x29ba7, 0x1ca28, 0x29ba5, 0x16e93, 0x1982c, 0x19828, 0x25994, 0x0a3eb, 0x1ca29, 0x16e90, 0x1ca25, 0x1982d, 0x1ca26, 0x16e9b, 0x0b756, 0x0967c, 0x25997, 0x0b75f, 0x198d3, 0x0b757, 0x19a2a, 0x0d45b, 0x0e517, 0x1ca24, 0x1ca23, 0x1ca22, 0x0b758, 0x16e97, 0x0cd14, 0x13100, 0x00007, 0x0003b, 0x0006b, 0x00097, 0x00138, 0x00125, 0x00173, 0x00258, 0x00335, 0x0028e, 0x004c6, 0x00715, 0x00729, 0x004ef, 0x00519, 0x004ed, 0x00532, 0x0068c, 0x00686, 0x00978, 0x00e5d, 0x00e31, 0x009f4, 0x00b92, 0x012f8, 0x00d06, 0x00a67, 0x00d44, 0x00a76, 0x00d59, 0x012cd, 0x01c78, 0x01c75, 0x0199f, 0x0198f, 0x01c67, 0x014c6, 0x01c79, 0x01c76, 0x00b94, 0x00d1b, 0x01e32, 0x01e31, 0x01ab0, 0x01a05, 0x01aa1, 0x0333a, 0x025e5, 0x02626, 0x03541, 0x03544, 0x03421, 0x03546, 0x02e55, 0x02e56, 0x0492d, 0x02dde, 0x0299b, 0x02ddc, 0x0357a, 0x0249c, 0x0668b, 0x1c77f, 0x1ca20, 0x0d45f, 0x09886, 0x16e9a, 0x0f2a7, 0x0b751, 0x0a3ee, 0x0cf59, 0x0cf57, 0x0b754, 0x0d0a6, 0x16e98, 0x0b760, 0x06ac6, 0x0a3f0, 0x12fbe, 0x13104, 0x0f2a5, 0x0a3ef, 0x0d472, 0x12cba, 0x1982e, 0x16e9c, 0x1c77e, 0x198d0, 0x13105, 0x16e92, 0x0b75d, 0x0d459, 0x0001a, 0x000c0, 0x0016c, 0x003cd, 0x00350, 0x0067b, 0x0051e, 0x006a9, 0x009f4, 0x00b72, 0x00d09, 0x01249, 0x01e3d, 0x01ca1, 0x01a1f, 0x01721, 0x01a8a, 0x016e8, 0x03347, 0x01a35, 0x0249d, 0x0299a, 0x02596, 0x02e4e, 0x0298b, 0x07182, 0x04c46, 0x025ba, 0x02e40, 0x027d6, 0x04fe8, 0x06607, 0x05310, 0x09884, 0x072e1, 0x06a3d, 0x04b6a, 0x04c7a, 0x06603, 0x04c7b, 0x03428, 0x06605, 0x09664, 0x09fc0, 0x071de, 0x06601, 0x05bb2, 0x09885, 0x0a3e2, 0x1c61f, 0x12cbb, 0x0b750, 0x0cf58, 0x0967d, 0x25995, 0x668ad, 0x0b75a, 0x09fc2, 0x0537f, 0x0b75e, 0x13fae, 0x12fbc, 0x00031, 0x001c4, 0x004c5, 0x005b8, 0x00cf4, 0x0096f, 0x00d46, 0x01e57, 0x01a04, 0x02625, 0x03346, 0x028f9, 0x04c47, 0x072e0, 0x04b69, 0x03420, 0x07957, 0x06639, 0x0799e, 0x07959, 0x07881, 0x04b68, 0x09fc3, 0x09fd6, 0x0cc70, 0x0a3f1, 0x12cbe, 0x0e30e, 0x0e51b, 0x06af2, 0x12cbc, 0x1c77d, 0x0f2ab, 0x12fbd, 0x1aa2f, 0x0a3ec, 0x0d473, 0x05377, 0x0a3e9, 0x1982b, 0x0e300, 0x12f3f, 0x0cf5f, 0x096c0, 0x38c3c, 0x16e94, 0x16e95, 0x12f3d, 0x29ba4, 0x29ba6, 0x1c77c, 0x6a8ba, 0x3545c, 0x33457, 0x668ac, 0x6a8bb, 0x16e9d, 0x0e519, 0x25996, 0x12f3e, 0x00036, 0x0033e, 0x006ad, 0x00d03, 0x012c8, 0x0124a, 0x03c42, 0x03ccd, 0x06606, 0x07880, 0x06852, 0x06a3a, 0x05bb4, 0x0f2a2, 0x09fc7, 0x12cb9, 0x0cc6c, 0x0a6e8, 0x096c1, 0x0004a, 0x00355, 0x012f9, 0x014e8, 0x01abe, 0x025b6, 0x0492e, 0x09fc6, 0x051ff, 0x0cc6f, 0x096cb, 0x0d071, 0x198d1, 0x12cb8, 0x38c3d, 0x13faf, 0x096c9, 0x0009d, 0x00539, 0x012ce, 0x0341f, 0x029c1, 0x04b33, 0x0a3e3, 0x0d070, 0x16e96, 0x0b763, 0x000a0, 0x009ce, 0x038cc, 0x0343d, 0x051fa, 0x09888, 0x12fba, 0x000df, 0x00a75, 0x029a7, 0x09fc5, 0x0e301, 0x0967b, 0x001e7, 0x012c9, 0x051fb, 0x09889, 0x0f2a6, 0x0016f, 0x01cb9, 0x0cf5a, 0x12cbf, 0x09679, 0x00272, 0x01a15, 0x0967a, 0x003cb, 0x025f6, 0x0b762, 0x0028d, 0x03c60, 0x0cf5e, 0x00352, 0x03ccc, 0x0072f, 0x07186, 0x004ec, 0x05379, 0x0068e, 0x09887, 0x006a7, 0x06af1, 0x00e29, 0x0cf5b, 0x00f31, 0x0d470, 0x009c6, 0x013fb, 0x13102, 0x019a5, 0x13101, 0x01983, 0x01c65, 0x0124f, 0x014c7, 0x01726, 0x01abf, 0x03304, 0x02624, 0x03c41, 0x027d7, 0x02ddd, 0x02e54, 0x0343c, 0x06604, 0x07181, 0x0663a, 0x04fa9, 0x0663b, 0x05311, 0x0537a, 0x06839, 0x05bb5, 0x0492f, 0x06af0, 0x096c7, 0x0cc6e, 0x0537b, 0x0cf5c, 0x0cf56, 0x198d2, 0x0cf5d, 0x0a3ed, 0x0f2a3, 0x1982a, 0x0b761, 0x096c6, }; static const uint8_t coef0_huffbits[666] = { 11, 6, 2, 3, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 11, 12, 12, 12, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 14, 14, 15, 15, 15, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 15, 15, 15, 15, 16, 16, 16, 15, 16, 15, 15, 16, 16, 16, 16, 15, 16, 16, 16, 15, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 16, 16, 15, 16, 16, 16, 17, 17, 17, 16, 16, 17, 16, 16, 16, 16, 17, 16, 17, 17, 16, 16, 15, 15, 15, 16, 17, 16, 17, 16, 16, 17, 17, 17, 17, 17, 17, 16, 17, 17, 17, 16, 17, 17, 16, 17, 17, 17, 16, 17, 17, 16, 16, 17, 17, 17, 18, 17, 17, 17, 17, 17, 18, 18, 17, 17, 17, 19, 17, 19, 18, 17, 17, 18, 17, 17, 18, 17, 17, 17, 18, 17, 17, 18, 17, 17, 17, 17, 17, 16, 17, 17, 17, 17, 18, 16, 17, 4, 6, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 15, 15, 15, 15, 15, 15, 17, 17, 17, 16, 18, 16, 17, 17, 16, 16, 17, 17, 18, 17, 16, 17, 17, 17, 16, 17, 17, 18, 17, 18, 17, 17, 17, 18, 17, 17, 5, 8, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 15, 16, 16, 15, 15, 15, 15, 15, 16, 16, 15, 15, 16, 16, 17, 17, 18, 17, 16, 17, 18, 19, 17, 16, 16, 17, 17, 17, 6, 9, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 17, 18, 16, 16, 16, 18, 17, 16, 17, 18, 17, 17, 16, 17, 17, 16, 17, 16, 17, 18, 18, 18, 17, 19, 19, 17, 20, 19, 18, 19, 20, 18, 16, 18, 17, 7, 10, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 16, 16, 18, 16, 17, 17, 8, 11, 13, 14, 14, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 17, 17, 8, 12, 14, 15, 15, 15, 17, 17, 18, 17, 9, 12, 14, 15, 16, 16, 17, 9, 13, 15, 16, 16, 17, 9, 13, 16, 16, 16, 10, 13, 16, 18, 17, 10, 14, 17, 10, 14, 17, 11, 14, 16, 11, 14, 11, 15, 12, 16, 12, 16, 12, 16, 12, 16, 12, 17, 13, 13, 17, 13, 17, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 16, 15, 16, 16, 16, 16, 16, 16, 17, 16, 16, 16, 16, 17, 16, 17, 16, 17, 17, 17, }; static const uint32_t coef1_huffcodes[555] = { 0x00115, 0x00002, 0x00001, 0x00000, 0x0000d, 0x00007, 0x00013, 0x0001d, 0x00008, 0x0000c, 0x00023, 0x0002b, 0x0003f, 0x00017, 0x0001b, 0x00043, 0x00049, 0x00050, 0x00055, 0x00054, 0x00067, 0x00064, 0x0007b, 0x0002d, 0x00028, 0x0002a, 0x00085, 0x00089, 0x0002b, 0x00035, 0x00090, 0x00091, 0x00094, 0x00088, 0x000c1, 0x000c6, 0x000f2, 0x000e3, 0x000c5, 0x000e2, 0x00036, 0x000f0, 0x000a7, 0x000cd, 0x000fb, 0x00059, 0x00116, 0x00103, 0x00108, 0x0012b, 0x0012d, 0x00188, 0x0012e, 0x0014c, 0x001c3, 0x00187, 0x001e7, 0x0006f, 0x00094, 0x00069, 0x001e6, 0x001ca, 0x00147, 0x00195, 0x000a7, 0x00213, 0x00209, 0x00303, 0x00295, 0x00289, 0x0028c, 0x0028d, 0x00312, 0x00330, 0x0029b, 0x00308, 0x00328, 0x0029a, 0x0025e, 0x003c5, 0x00384, 0x0039f, 0x00397, 0x00296, 0x0032e, 0x00332, 0x003c6, 0x003e6, 0x0012d, 0x000d1, 0x00402, 0x000dd, 0x00161, 0x0012b, 0x00127, 0x0045d, 0x00601, 0x004ab, 0x0045f, 0x00410, 0x004bf, 0x00528, 0x0045c, 0x00424, 0x00400, 0x00511, 0x00618, 0x0073d, 0x0063a, 0x00614, 0x0073c, 0x007c0, 0x007cf, 0x00802, 0x00966, 0x00964, 0x00951, 0x008a0, 0x00346, 0x00803, 0x00a52, 0x0024a, 0x007c1, 0x0063f, 0x00126, 0x00406, 0x00789, 0x008a2, 0x00960, 0x00967, 0x00c05, 0x00c70, 0x00c79, 0x00a5d, 0x00c26, 0x00c4d, 0x00372, 0x008a5, 0x00c08, 0x002c5, 0x00f11, 0x00cc4, 0x00f8e, 0x00e16, 0x00496, 0x00e77, 0x00f9c, 0x00c25, 0x00f1e, 0x00c27, 0x00f1f, 0x00e17, 0x00ccd, 0x00355, 0x00c09, 0x00c78, 0x00f90, 0x00521, 0x00357, 0x00356, 0x0068e, 0x00f9d, 0x00c04, 0x00e58, 0x00a20, 0x00a2c, 0x00c4c, 0x0052f, 0x00f8d, 0x01178, 0x01053, 0x01097, 0x0180f, 0x0180d, 0x012fb, 0x012aa, 0x0202a, 0x00a40, 0x018ed, 0x01ceb, 0x01455, 0x018e3, 0x012a1, 0x00354, 0x00353, 0x00f1c, 0x00c7b, 0x00c37, 0x0101d, 0x012cb, 0x01142, 0x0197d, 0x01095, 0x01e3b, 0x0186b, 0x00588, 0x01c2a, 0x014b8, 0x01e3a, 0x018ec, 0x01f46, 0x012fa, 0x00a53, 0x01ce8, 0x00a55, 0x01c29, 0x0117b, 0x01052, 0x012a0, 0x00589, 0x00950, 0x01c2b, 0x00a50, 0x0208b, 0x0180e, 0x02027, 0x02556, 0x01e20, 0x006e7, 0x01c28, 0x0197a, 0x00684, 0x020a2, 0x01f22, 0x03018, 0x039cf, 0x03e25, 0x02557, 0x0294c, 0x028a6, 0x00d11, 0x028a9, 0x02979, 0x00d46, 0x00a56, 0x039ce, 0x030cc, 0x0329a, 0x0149d, 0x0510f, 0x0451c, 0x02028, 0x03299, 0x01ced, 0x014b9, 0x00f85, 0x00c7a, 0x01800, 0x00341, 0x012ca, 0x039c8, 0x0329d, 0x00d0d, 0x03e20, 0x05144, 0x00d45, 0x030d0, 0x0186d, 0x030d5, 0x00d0f, 0x00d40, 0x04114, 0x020a1, 0x0297f, 0x03e24, 0x032f1, 0x04047, 0x030d4, 0x028a8, 0x00d0e, 0x0451d, 0x04044, 0x0297e, 0x04042, 0x030d2, 0x030cf, 0x03e21, 0x03e26, 0x028a5, 0x0451a, 0x00d48, 0x01a16, 0x00d44, 0x04518, 0x0149b, 0x039ca, 0x01498, 0x0403d, 0x0451b, 0x0149c, 0x032f3, 0x030cb, 0x08073, 0x03e22, 0x0529a, 0x020aa, 0x039cc, 0x0738a, 0x06530, 0x07389, 0x06193, 0x08071, 0x04043, 0x030ce, 0x05147, 0x07388, 0x05145, 0x08072, 0x04521, 0x00d47, 0x0297c, 0x030cd, 0x030ca, 0x0000b, 0x0000c, 0x00083, 0x000e4, 0x00048, 0x00102, 0x001cc, 0x001f5, 0x00097, 0x0020b, 0x00124, 0x00453, 0x00627, 0x00639, 0x00605, 0x00517, 0x001b8, 0x00663, 0x00667, 0x007c3, 0x00823, 0x00961, 0x00963, 0x00e5a, 0x00e59, 0x00a2b, 0x00cbf, 0x00292, 0x00a2d, 0x007d0, 0x00953, 0x00cc5, 0x00f84, 0x004ab, 0x014a7, 0x0068a, 0x0117a, 0x0052e, 0x01442, 0x0052c, 0x00c77, 0x00f8f, 0x004aa, 0x01094, 0x01801, 0x012c4, 0x0297b, 0x00952, 0x01f19, 0x006a5, 0x01149, 0x012c5, 0x01803, 0x022f2, 0x0329b, 0x04520, 0x0149e, 0x00d13, 0x01f16, 0x01ce9, 0x0101c, 0x006e6, 0x039c9, 0x06191, 0x07c8e, 0x06192, 0x0ca63, 0x039cd, 0x06190, 0x06884, 0x06885, 0x07382, 0x00d49, 0x00d41, 0x0450c, 0x0149a, 0x030d1, 0x08077, 0x03e23, 0x01a15, 0x0e701, 0x0e702, 0x08079, 0x0822a, 0x0a218, 0x07887, 0x0403f, 0x0520b, 0x0529b, 0x0e700, 0x04519, 0x00007, 0x000e0, 0x000d0, 0x0039b, 0x003e5, 0x00163, 0x0063e, 0x007c9, 0x00806, 0x00954, 0x01044, 0x01f44, 0x0197c, 0x01f45, 0x00a51, 0x01f47, 0x00951, 0x0052d, 0x02291, 0x0092f, 0x00a54, 0x00d12, 0x0297d, 0x00d0c, 0x01499, 0x0329e, 0x032f0, 0x02025, 0x039c6, 0x00a57, 0x03e46, 0x00d42, 0x0738b, 0x05146, 0x04046, 0x08078, 0x0510e, 0x07886, 0x02904, 0x04156, 0x04157, 0x06032, 0x030d3, 0x08bce, 0x04040, 0x0403e, 0x0a414, 0x10457, 0x08075, 0x06887, 0x07c8f, 0x039c7, 0x07387, 0x08070, 0x08bcf, 0x1482a, 0x10456, 0x1482b, 0x01a17, 0x06886, 0x0450d, 0x00013, 0x0006b, 0x00615, 0x0080b, 0x0082b, 0x00952, 0x00e5b, 0x018e2, 0x0186c, 0x01f18, 0x0329f, 0x00d43, 0x03e29, 0x05140, 0x05141, 0x0ca62, 0x06033, 0x03c42, 0x03e28, 0x0450f, 0x0a21a, 0x07384, 0x0a219, 0x0e703, 0x0a21b, 0x01a14, 0x07383, 0x045e6, 0x0007a, 0x0012c, 0x00ccc, 0x0068f, 0x01802, 0x00a52, 0x00953, 0x04045, 0x01a20, 0x0451f, 0x000a4, 0x00735, 0x01cec, 0x02029, 0x020a3, 0x0451e, 0x00069, 0x00c24, 0x02024, 0x032f2, 0x05142, 0x00196, 0x00523, 0x000a6, 0x0197b, 0x0030b, 0x0092e, 0x003e9, 0x03e27, 0x00160, 0x05143, 0x00652, 0x04041, 0x00734, 0x028a7, 0x0080f, 0x01483, 0x0097c, 0x00340, 0x0068b, 0x00522, 0x01054, 0x01096, 0x01f17, 0x0202b, 0x01cea, 0x020a0, 0x02978, 0x02026, 0x0297a, 0x039cb, 0x03e2b, 0x0149f, 0x0329c, 0x07385, 0x08074, 0x0450e, 0x03e2a, 0x05149, 0x08076, 0x07386, 0x05148, }; static const uint8_t coef1_huffbits[555] = { 9, 5, 2, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 12, 12, 12, 12, 12, 12, 12, 13, 12, 12, 12, 12, 12, 12, 12, 12, 13, 12, 12, 12, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 13, 12, 13, 13, 13, 13, 13, 13, 13, 14, 14, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 13, 14, 13, 13, 13, 13, 13, 14, 13, 14, 14, 13, 14, 14, 13, 14, 13, 13, 14, 14, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 14, 14, 14, 14, 15, 15, 15, 14, 14, 13, 13, 12, 12, 13, 13, 13, 14, 14, 15, 14, 15, 15, 14, 13, 14, 15, 15, 15, 14, 14, 14, 14, 15, 14, 14, 15, 15, 15, 14, 15, 14, 14, 14, 14, 14, 15, 15, 16, 15, 15, 15, 14, 15, 15, 15, 15, 14, 14, 16, 14, 15, 14, 14, 15, 15, 15, 15, 16, 15, 14, 15, 15, 15, 16, 15, 15, 14, 14, 14, 4, 7, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 11, 11, 11, 11, 12, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 13, 14, 13, 13, 13, 14, 14, 15, 15, 14, 13, 13, 13, 14, 14, 15, 15, 15, 16, 14, 15, 17, 17, 15, 15, 15, 15, 15, 14, 16, 14, 16, 16, 16, 16, 16, 16, 15, 15, 17, 15, 16, 15, 6, 8, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 14, 13, 14, 13, 14, 14, 14, 14, 14, 15, 15, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 16, 15, 15, 16, 15, 15, 15, 14, 16, 15, 15, 18, 17, 16, 17, 15, 14, 15, 16, 16, 19, 17, 19, 16, 17, 15, 7, 10, 11, 12, 12, 12, 12, 13, 13, 13, 14, 15, 14, 15, 15, 16, 15, 14, 14, 15, 16, 15, 16, 16, 16, 16, 15, 15, 7, 11, 12, 13, 13, 14, 14, 15, 15, 15, 8, 11, 13, 14, 14, 15, 9, 12, 14, 14, 15, 9, 13, 10, 13, 10, 14, 10, 14, 11, 15, 11, 15, 11, 14, 12, 15, 12, 13, 13, 13, 13, 13, 13, 14, 13, 14, 14, 14, 14, 14, 14, 15, 14, 15, 16, 15, 14, 15, 16, 15, 15, }; static const uint32_t coef2_huffcodes[1336] = { 0x003e6, 0x000f6, 0x00000, 0x00002, 0x00006, 0x0000f, 0x0001b, 0x00028, 0x00039, 0x0003f, 0x0006b, 0x00076, 0x000b7, 0x000e8, 0x000ef, 0x00169, 0x001a7, 0x001d4, 0x001dc, 0x002c4, 0x00349, 0x00355, 0x00391, 0x003dc, 0x00581, 0x005b2, 0x00698, 0x0070c, 0x00755, 0x0073a, 0x00774, 0x007cf, 0x00b0a, 0x00b66, 0x00d2e, 0x00d5e, 0x00e1b, 0x00eac, 0x00e5a, 0x00f7e, 0x00fa1, 0x0163e, 0x01a37, 0x01a52, 0x01c39, 0x01ab3, 0x01d5f, 0x01cb6, 0x01f52, 0x01dd9, 0x02c04, 0x02c2e, 0x02c2d, 0x02c23, 0x03467, 0x034a3, 0x0351b, 0x03501, 0x03a5d, 0x0351c, 0x03875, 0x03dea, 0x0397b, 0x039db, 0x03df1, 0x039d8, 0x03bb4, 0x0580a, 0x0584d, 0x05842, 0x05b13, 0x058ea, 0x0697d, 0x06a06, 0x068cc, 0x06ac7, 0x06a96, 0x072f4, 0x07543, 0x072b4, 0x07d20, 0x0b003, 0x073b5, 0x07be6, 0x0d180, 0x07bd1, 0x07cb8, 0x07d06, 0x07d25, 0x0d2f2, 0x0d19a, 0x0d334, 0x0e1dc, 0x0d529, 0x0d584, 0x0e1d2, 0x0e5e3, 0x0eec4, 0x0e564, 0x0fa49, 0x16001, 0x0eedc, 0x0f7fa, 0x1a32c, 0x16131, 0x16003, 0x0f9c8, 0x1ef80, 0x1d2a0, 0x1aa4b, 0x0f7ce, 0x1abfe, 0x1aa50, 0x1a458, 0x1a816, 0x1cae4, 0x1d2fe, 0x1d52e, 0x1aa4c, 0x2c245, 0x1d2a1, 0x1a35d, 0x1ca1b, 0x1d5d8, 0x1f531, 0x1ca1c, 0x1f389, 0x1f4af, 0x3a5e7, 0x351fb, 0x2c24b, 0x34bce, 0x2c24d, 0x2c249, 0x2c24a, 0x72dfc, 0x357ef, 0x35002, 0x3a5e6, 0x39431, 0x5843b, 0x34a77, 0x58431, 0x3a5f3, 0x3a5dd, 0x3e5e5, 0x356bd, 0x3976e, 0x6a3d2, 0x3500d, 0x694c4, 0x580bd, 0x3e5e8, 0x74b95, 0x34a6e, 0x3977c, 0x39432, 0x5b0d2, 0x6a3d8, 0x580b8, 0x5b0cb, 0x5b0d7, 0x72dee, 0x72ded, 0x72dec, 0x74b9c, 0x3977f, 0x72dea, 0x74b9e, 0x7be7d, 0x580bf, 0x5b0d5, 0x7cba8, 0x74b91, 0x3e5dd, 0xb6171, 0xd46b3, 0xd46b9, 0x7cba1, 0x74b9f, 0x72de1, 0xe59f5, 0x3e5eb, 0x00004, 0x00015, 0x00038, 0x00075, 0x000e8, 0x001d3, 0x00347, 0x0039c, 0x00690, 0x0074a, 0x00b60, 0x00e93, 0x00f74, 0x0163d, 0x01a5a, 0x01d24, 0x01cbe, 0x01f4b, 0x03468, 0x03562, 0x03947, 0x03e82, 0x05804, 0x05b12, 0x05803, 0x0696d, 0x06a9e, 0x0697c, 0x06978, 0x06afb, 0x074b2, 0x072f5, 0x073c0, 0x07541, 0x06944, 0x074b7, 0x070d3, 0x07ba9, 0x0b0b1, 0x0d1af, 0x0e1dd, 0x0e5e2, 0x0e1a3, 0x0eec3, 0x1612f, 0x0e961, 0x0eeda, 0x0e78e, 0x0fa48, 0x1612c, 0x0e511, 0x0e565, 0x0e953, 0x1aa4a, 0x0e59d, 0x1d52c, 0x1a811, 0x1cae7, 0x1abfc, 0x1d52d, 0x1cacf, 0x1cf05, 0x2c254, 0x34a72, 0x1f4ac, 0x3976b, 0x34a71, 0x2c6d9, 0x2d873, 0x34a6a, 0x357e7, 0x3464c, 0x3e5f5, 0x58433, 0x1f53a, 0x3500a, 0x357ea, 0x34a73, 0x3942f, 0x357e5, 0x39775, 0x694cd, 0x39772, 0x7cba5, 0x6a3ef, 0x35483, 0x74b98, 0x5b0c1, 0x39770, 0x3a5d7, 0x39433, 0x39434, 0x694ce, 0x580be, 0x3e5ff, 0x6a3ec, 0xb616f, 0xd46b1, 0x6a3d1, 0x72de5, 0x74b6e, 0x72de9, 0x3e700, 0xd46b6, 0x6a3e9, 0x74b69, 0xe5675, 0xd46b8, 0x7cbaa, 0x3a5d1, 0x0000c, 0x0003c, 0x000eb, 0x001f1, 0x003a4, 0x006a8, 0x007d5, 0x00d43, 0x00e77, 0x016c5, 0x01cb1, 0x02c5d, 0x03a55, 0x03a56, 0x03e51, 0x03bb5, 0x05b0a, 0x06a9f, 0x074b8, 0x07d28, 0x0d187, 0x0d40e, 0x0d52e, 0x0d425, 0x0eae3, 0x0e1d3, 0x1612e, 0x0e59e, 0x0eec2, 0x0e578, 0x0e51a, 0x0e579, 0x0e515, 0x0e960, 0x0d183, 0x0d220, 0x0d2cb, 0x0e512, 0x16c3e, 0x16002, 0x16c42, 0x1cae9, 0x3461a, 0x1d2fa, 0x1a308, 0x1a849, 0x1cf07, 0x1f38f, 0x34b65, 0x2c253, 0x1ef9e, 0x1cbc3, 0x1cbc1, 0x2c255, 0x1f384, 0x58435, 0x2c5cd, 0x3a5f7, 0x2c252, 0x3959c, 0x2c6d8, 0x3a5d3, 0x6ad78, 0x6a3f2, 0x7cba9, 0xb6176, 0x72deb, 0x39764, 0x3e5f6, 0x3a5d8, 0x74a8c, 0x6a3e6, 0x694d1, 0x6ad79, 0x1a4592, 0xe59fb, 0x7cbb3, 0x5b0cd, 0x00017, 0x000b5, 0x002c3, 0x005b7, 0x00b1c, 0x00e5c, 0x0163f, 0x01ab2, 0x01efa, 0x0348a, 0x0396e, 0x058da, 0x06963, 0x06a30, 0x072cd, 0x073cf, 0x07ce7, 0x0d2ca, 0x0d2d8, 0x0e764, 0x0e794, 0x16008, 0x16167, 0x1617e, 0x1aa49, 0x1a30b, 0x1a813, 0x2c6da, 0x1a580, 0x1cbc2, 0x0f9ca, 0x1617f, 0x1d2fe, 0x0f7fc, 0x16c40, 0x0e513, 0x0eec5, 0x0f7c3, 0x1d508, 0x1a81e, 0x1d2fd, 0x39430, 0x35486, 0x3e5fd, 0x2c24c, 0x2c75a, 0x34a74, 0x3a5f4, 0x3464d, 0x694ca, 0x3a5f1, 0x1d509, 0x1d5c0, 0x34648, 0x3464e, 0x6a3d5, 0x6a3e8, 0x6a3e7, 0x5b0c3, 0x2c248, 0x1f38a, 0x3a5f2, 0x6a3e5, 0x00029, 0x00168, 0x0058c, 0x00b67, 0x00f9d, 0x01c3d, 0x01cbf, 0x02c20, 0x0351d, 0x03df6, 0x06af9, 0x072b5, 0x0b1d7, 0x0b0b2, 0x0d40a, 0x0d52b, 0x0e952, 0x0e797, 0x163c3, 0x1c3a0, 0x1f386, 0x1ca21, 0x34655, 0x2c247, 0x1f53b, 0x2c250, 0x2c24f, 0x1f385, 0x1ef5d, 0x1cf15, 0x1caea, 0x1ab0a, 0x1cf19, 0x1f53d, 0x1d5c2, 0x1d2fb, 0x1ef58, 0x34a78, 0x357ec, 0x1f533, 0x3a5e1, 0x694d2, 0x58482, 0x3a5ee, 0x2c6dc, 0x357eb, 0x5b0c4, 0x39778, 0x6a3e1, 0x7cbb4, 0x3a5e1, 0x74b68, 0x3a5ef, 0x3a5d2, 0x39424, 0x72de2, 0xe59f6, 0xe59f7, 0x3e702, 0x3e5ec, 0x1f38b, 0x0003b, 0x001f0, 0x00777, 0x00fa8, 0x01cb2, 0x02d84, 0x03a57, 0x03dd6, 0x06917, 0x06a11, 0x07d07, 0x0eae2, 0x0e796, 0x0f9c9, 0x0f7fb, 0x16166, 0x16160, 0x1ab1b, 0x1abfa, 0x2d87b, 0x1d2f7, 0x39768, 0x1f38c, 0x34653, 0x34651, 0x6a3d9, 0x35001, 0x3abbd, 0x38742, 0x39426, 0x34a76, 0x3a5ec, 0x34a75, 0x35000, 0x35488, 0x1cf10, 0x2c6db, 0x357ed, 0x357e8, 0x357e9, 0x3a5f0, 0x694c2, 0xb6178, 0x72df5, 0x39425, 0x3942b, 0x74b6d, 0x74b6f, 0xb6177, 0xb6179, 0x74b6a, 0xb6172, 0x58487, 0x3e5ee, 0x3e5ed, 0x72df2, 0x72df4, 0x7cbae, 0x6a3ca, 0x70e86, 0x34bcf, 0x6a3c8, 0x00059, 0x00384, 0x00d5b, 0x01c38, 0x03560, 0x0395b, 0x0584e, 0x06964, 0x073cd, 0x0b1e7, 0x0e798, 0x0e78d, 0x0fa43, 0x1a848, 0x1a32f, 0x1aa4e, 0x3464a, 0x1f4ab, 0x1f38d, 0x3a5eb, 0x3a5d4, 0x3548a, 0x6a3c7, 0x5b0d0, 0x6a3c5, 0x7cbb0, 0x694cb, 0x3a5e5, 0x3e5e2, 0x3942c, 0x2d872, 0x1f4ae, 0x3a5d5, 0x694d3, 0x58481, 0x35009, 0x39774, 0x58432, 0xb616c, 0x5b0db, 0x3548b, 0xb6174, 0x1d5d95, 0xb004c, 0x7cbb2, 0x3a5e5, 0x74a8f, 0xe59f9, 0x72df6, 0xe59fd, 0x7cbad, 0xd427d, 0x72cff, 0x3977a, 0x5b0d9, 0xb616d, 0xb616b, 0x1a4593, 0x7cbaf, 0x5b0da, 0x00071, 0x003eb, 0x01603, 0x02c6c, 0x03961, 0x068c8, 0x06a31, 0x072bd, 0x0d2c2, 0x0e51b, 0x0e5e6, 0x1abfb, 0x1d2ff, 0x1cae5, 0x1ef5c, 0x1ef5e, 0x1cf13, 0x34a6d, 0x3976d, 0xb616a, 0x3e5f2, 0x6a3c4, 0xb6169, 0x3e5dc, 0x580b9, 0x74b99, 0x75764, 0x58434, 0x3a5d9, 0x6945a, 0x69459, 0x3548c, 0x3a5e9, 0x69457, 0x72df1, 0x6945e, 0x6a35e, 0x3e701, 0xb6168, 0x5b0dd, 0x3a5de, 0x6a3c2, 0xd4278, 0x6a3cc, 0x72dfd, 0xb6165, 0x16009a, 0x7cbb1, 0xd427c, 0xb6162, 0xe765e, 0x1cecbe, 0x7cbb6, 0x69454, 0xb6160, 0xd427a, 0x1d5d96, 0xb1d6d, 0xe59f4, 0x72de8, 0x3a5db, 0x0007a, 0x006ae, 0x01c3c, 0x03aba, 0x058e9, 0x072cc, 0x0d2dd, 0x0d22d, 0x0eec1, 0x0eedb, 0x1d2a2, 0x1ef5b, 0x357e2, 0x3abbf, 0x1d2f9, 0x35004, 0x3a5dc, 0x351fc, 0x3976c, 0x6a3c6, 0x6a3cb, 0x3e5ea, 0xe59f3, 0x6a3ce, 0x69452, 0xe59f0, 0x74b90, 0xd4279, 0xd427b, 0x7cbb5, 0x5b0c5, 0x3a5e3, 0x3a5e2, 0x000d0, 0x00775, 0x01efe, 0x03dd5, 0x0728c, 0x07cb9, 0x0e1a2, 0x0ea85, 0x0eed8, 0x1a30a, 0x1aa4f, 0x3a5df, 0x35008, 0x3a5e0, 0x3e5f4, 0x3e5f7, 0xb1d6c, 0x5843e, 0x34a70, 0x72df8, 0x74b6b, 0xd427f, 0x72df0, 0x5b0bf, 0x5b0c0, 0xd46b0, 0x72def, 0xe59f8, 0x162e64, 0xb1d6f, 0x3a5e0, 0x39427, 0x69166, 0x6a3e2, 0x6a3e3, 0x74a8d, 0xd427e, 0x1d5d97, 0xd46b4, 0x5b0d8, 0x6a3d3, 0x000e0, 0x00b63, 0x034cc, 0x06a33, 0x073c9, 0x0e1a0, 0x0f7fd, 0x0f9cc, 0x1617d, 0x1caeb, 0x1f4a9, 0x3abb3, 0x69450, 0x39420, 0x39777, 0x3e5e0, 0x6a3d4, 0x6a3ed, 0xb6166, 0xe59f1, 0xb1d6e, 0xe5676, 0x6a3ea, 0xe5674, 0xb6163, 0xd46b7, 0x7cba6, 0xd46ba, 0x1d5d94, 0xb6164, 0x6a3f1, 0x7cba2, 0x69451, 0x72dfa, 0xd46bb, 0x72df7, 0x74b94, 0x1cecbf, 0xe59fa, 0x16009b, 0x6a3e4, 0x000e6, 0x00e94, 0x03876, 0x070ef, 0x0d52a, 0x16015, 0x16014, 0x1abf9, 0x1cf17, 0x34a79, 0x34650, 0x3e705, 0x6a3d0, 0x58430, 0x74b9d, 0x7be7e, 0x5b0be, 0x39773, 0x6a3de, 0x000fb, 0x00f7b, 0x03dd7, 0x07bd0, 0x0e59c, 0x0f9cd, 0x1cf18, 0x1d2ff, 0x34a7a, 0x39429, 0x3500c, 0x72de0, 0x69456, 0x7be7c, 0xd46b5, 0xd46b2, 0x6a3dd, 0x001a2, 0x0163b, 0x06913, 0x0b016, 0x0fa42, 0x1a32d, 0x1cf06, 0x34a7c, 0x34a7d, 0xb6161, 0x35481, 0x3e5fa, 0x7cba0, 0x7be7f, 0x7cba3, 0x7cba7, 0x5b0d3, 0x72de6, 0x6a3dc, 0x001a9, 0x01ab4, 0x06a34, 0x0d46a, 0x16130, 0x1ef5f, 0x1f532, 0x1f536, 0x3942e, 0x58436, 0x6a3db, 0x6945b, 0x001c9, 0x01ca0, 0x0728b, 0x0eed9, 0x1f539, 0x1ca1d, 0x39765, 0x39766, 0x58439, 0x6945d, 0x39767, 0x001d3, 0x01f2c, 0x07bfc, 0x16161, 0x34652, 0x3a5ed, 0x3548d, 0x58438, 0x6a3da, 0x002c1, 0x02c5e, 0x0d335, 0x1ab1a, 0x2d874, 0x35006, 0x35484, 0x5b0cc, 0x74b9a, 0x72df3, 0x6a3d6, 0x002da, 0x034b3, 0x0d5ae, 0x1caee, 0x2d871, 0x357e3, 0x74b97, 0x72df9, 0x580ba, 0x5b0d4, 0x0034d, 0x0354e, 0x0f750, 0x1cbc0, 0x3a5e7, 0x3a5e4, 0x00385, 0x03a58, 0x16c41, 0x2c5cf, 0x3e5e1, 0x74b6c, 0xe5677, 0x6a3df, 0x00390, 0x03e50, 0x163c2, 0x2d876, 0x35482, 0x5b0d6, 0x5843a, 0x0039f, 0x0585e, 0x1a583, 0x3500f, 0x74b93, 0x39771, 0x003e4, 0x06912, 0x16c43, 0x357e1, 0x0058a, 0x0696f, 0x1f538, 0x5b0c9, 0x6a3cf, 0x005b6, 0x06af8, 0x1f534, 0x58483, 0x6a3e0, 0x00695, 0x07d02, 0x1cae8, 0x58485, 0x006a2, 0x0754a, 0x357ee, 0x3977b, 0x00748, 0x074b2, 0x34a7b, 0x00729, 0x0b1e0, 0x34649, 0x3e5e3, 0x0073d, 0x0d2c4, 0x3e5e6, 0x007bb, 0x0b099, 0x39762, 0x5b0ce, 0x6945f, 0x007d1, 0x0d5ab, 0x39779, 0x007d3, 0x0d52f, 0x39763, 0x6945c, 0x00b1a, 0x0d2c5, 0x35489, 0x00d23, 0x0eaed, 0x3e5f8, 0x00d32, 0x16016, 0x3e5fb, 0x00d41, 0x0e768, 0x3a5ed, 0x00e1f, 0x16017, 0x58027, 0x00ead, 0x0fa07, 0x69455, 0x00e54, 0x1612b, 0x00e55, 0x1a581, 0x00f78, 0x1a32b, 0x580bc, 0x6a3ee, 0x00f79, 0x1abfd, 0x00f95, 0x1ab18, 0x6a3f0, 0x01637, 0x1aa4d, 0x0162d, 0x1f53c, 0x6a3f3, 0x01a31, 0x1a810, 0x39769, 0x01a50, 0x1caef, 0x01a36, 0x1a32e, 0x01a67, 0x1f38e, 0x01a85, 0x1ef59, 0x01aa6, 0x1ef83, 0x01d51, 0x2c012, 0x01d53, 0x2d879, 0x01d5e, 0x35005, 0x01cba, 0x1cf04, 0x69453, 0x01d2d, 0x351ff, 0x01f2d, 0x2d86f, 0x01f29, 0x35007, 0x02c22, 0x351fa, 0x02c03, 0x3a5ec, 0x02c5f, 0x3a5eb, 0x02c58, 0x34a6b, 0x03469, 0x356be, 0x02c59, 0x34a6c, 0x0346a, 0x3a5ea, 0x034bd, 0x034bf, 0x356bf, 0x0386a, 0x03ab9, 0x5843f, 0x0386b, 0x3a5f5, 0x03a4b, 0x39421, 0x03aa4, 0x3a5e9, 0x03a5a, 0x03960, 0x3977e, 0x03de9, 0x03958, 0x03df7, 0x039e1, 0x3e5e4, 0x0395f, 0x69458, 0x03e91, 0x03df2, 0x39428, 0x058f2, 0x03e80, 0x6a3c3, 0x03e93, 0x694c0, 0x058b8, 0x5b0ca, 0x0584f, 0x694c1, 0x058f1, 0x068d6, 0x06a10, 0x06ac3, 0x06a32, 0x070d2, 0x06911, 0x074b1, 0x07494, 0x06ad4, 0x06ad6, 0x072b8, 0x06afa, 0x074b3, 0x07540, 0x073ce, 0x0b005, 0x074b3, 0x07495, 0x074b9, 0x0d336, 0x07bff, 0x07763, 0x073c8, 0x07d29, 0x0b622, 0x0d221, 0x0d181, 0x0b1d1, 0x074b8, 0x0b1d0, 0x0d19b, 0x0d2c3, 0x0b172, 0x0d2dc, 0x0b623, 0x0d5aa, 0x0d426, 0x0d182, 0x0e795, 0x0e1d1, 0x0d337, 0x0e96c, 0x0e5e4, 0x0e514, 0x0eaee, 0x16000, 0x0e767, 0x0e1a1, 0x0e78f, 0x16004, 0x0f7c2, 0x0e799, 0x0e5e7, 0x0e566, 0x0e769, 0x0f751, 0x0eede, 0x0fa06, 0x16005, 0x0fa9f, 0x1a5e6, 0x0e766, 0x1636f, 0x0eedd, 0x0eec0, 0x1a309, 0x1ceca, 0x163cd, 0x0f9cb, 0x0eedf, 0x1a582, 0x1612d, 0x0e5e5, 0x1abf8, 0x1a30c, 0x1ca1f, 0x163cc, 0x1a35c, 0x1ca1e, 0x1aa51, 0x163ac, 0x1a84e, 0x1a53f, 0x1cf16, 0x1d2fc, 0x1a5b3, 0x1ab19, 0x1a81f, 0x1d5c3, 0x16c3f, 0x1d5c1, 0x1d2fc, 0x1f4aa, 0x1a812, 0x1f535, 0x1cf12, 0x1a817, 0x1617c, 0x1ab0b, 0x1d2f8, 0x1ef82, 0x2d87a, 0x1d52f, 0x1f530, 0x1aa48, 0x35487, 0x1d2fd, 0x1f4ad, 0x1cf11, 0x3461b, 0x35485, 0x1ca20, 0x1caed, 0x1cae6, 0x1abff, 0x3464f, 0x34a6f, 0x1ef81, 0x3464b, 0x39d96, 0x1f383, 0x1f537, 0x1cf14, 0x2c5ce, 0x3500e, 0x2c251, 0x1caec, 0x1f387, 0x34654, 0x357e4, 0x2d878, 0x3500b, 0x35480, 0x3a5e8, 0x3548e, 0x34b64, 0x1f4a8, 0x35003, 0x3e5df, 0x2d870, 0x357e6, 0x3e5f0, 0x1ef5a, 0x3a5ea, 0x1f388, 0x3e703, 0x2c24e, 0x3a5e2, 0x351fd, 0x2c6dd, 0x3e704, 0x351fe, 0x2d875, 0x5b0c7, 0x3976a, 0x3a5e6, 0x39423, 0x58480, 0x2c246, 0x3a5e3, 0x2d877, 0x3e5f1, 0x3abbe, 0x58489, 0x3e5f9, 0x357e0, 0x3abbc, 0x5b0c6, 0x69167, 0x69165, 0x3e5e9, 0x39422, 0x3976f, 0x3977d, 0x3e5de, 0x6a3c9, 0x58b98, 0x3a5f6, 0x3a5d0, 0x58486, 0x6a3c1, 0x3e5fc, 0x5b0dc, 0x3548f, 0x3942d, 0x694c9, 0x58484, 0x3a5e8, 0x74b9b, 0x74b96, 0x694d0, 0x58488, 0x3a5e4, 0x3942a, 0x72ec2, 0x39776, 0x5b0d1, 0x5b0cf, 0x3a5d6, 0xe59fc, 0x5b0c8, 0x3e5e7, 0x7cbb7, 0x70e87, 0x7cbab, 0x5b0c2, 0x694c3, 0x74a8e, 0x3e5f3, 0x6a3cd, 0x72dfe, 0x73b2e, 0x72ec0, 0x694c5, 0x58437, 0x694c8, 0x72dff, 0x39435, 0x5843d, 0x6a3d7, 0x72ec1, 0xd22c8, 0x694cf, 0xb6173, 0x3e5fe, 0x580bb, 0xe59f2, 0xb616e, 0xb6175, 0x3a5da, 0x5b0bd, 0x694cc, 0x5843c, 0x694c7, 0x74b92, 0x72ec3, 0x694c6, 0xb6170, 0x7cbac, 0xb1733, 0x7cba4, 0xb6167, 0x72de7, 0x72de4, 0x6a3c0, 0x3e5ef, 0x162e65, 0x72de3, 0x72dfb, 0x6a35f, 0x6a3eb, }; static const uint8_t coef2_huffbits[1336] = { 11, 9, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 17, 17, 17, 17, 17, 18, 18, 17, 17, 18, 17, 17, 18, 17, 18, 18, 18, 18, 19, 18, 18, 18, 18, 18, 18, 20, 18, 18, 18, 19, 19, 18, 19, 18, 19, 19, 18, 19, 19, 18, 19, 19, 19, 19, 18, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 19, 19, 20, 19, 20, 19, 19, 20, 19, 19, 20, 20, 20, 20, 19, 20, 21, 19, 3, 5, 7, 8, 9, 9, 10, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 15, 15, 15, 15, 16, 16, 16, 16, 17, 16, 17, 17, 16, 17, 17, 17, 17, 17, 17, 16, 17, 17, 17, 17, 18, 17, 17, 18, 18, 18, 18, 18, 19, 18, 18, 18, 18, 18, 18, 19, 19, 18, 18, 18, 18, 19, 18, 19, 19, 19, 20, 19, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 19, 20, 19, 20, 19, 20, 19, 19, 21, 20, 20, 19, 4, 7, 8, 10, 11, 11, 12, 12, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 18, 18, 18, 19, 18, 19, 19, 19, 20, 20, 20, 19, 19, 19, 19, 19, 19, 19, 21, 21, 20, 19, 5, 8, 10, 11, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 18, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 19, 18, 19, 18, 18, 18, 18, 18, 19, 18, 17, 17, 18, 18, 19, 19, 19, 19, 18, 18, 18, 19, 6, 9, 11, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 18, 17, 18, 18, 18, 18, 18, 18, 19, 19, 18, 18, 18, 19, 19, 19, 20, 19, 19, 18, 19, 19, 20, 21, 21, 19, 19, 18, 6, 10, 12, 13, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17, 17, 17, 17, 17, 17, 18, 18, 19, 18, 18, 18, 19, 18, 18, 18, 19, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 20, 20, 19, 19, 19, 19, 20, 20, 19, 20, 19, 19, 19, 20, 20, 20, 19, 19, 18, 19, 7, 10, 12, 13, 14, 15, 15, 15, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 19, 18, 19, 19, 19, 20, 19, 18, 19, 19, 18, 18, 19, 19, 19, 18, 19, 19, 20, 19, 18, 20, 21, 20, 20, 19, 19, 21, 20, 21, 20, 20, 20, 19, 19, 20, 20, 21, 20, 19, 7, 11, 13, 14, 15, 15, 15, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 18, 19, 20, 19, 19, 20, 19, 19, 19, 19, 19, 19, 19, 19, 18, 18, 19, 20, 19, 19, 19, 20, 19, 19, 19, 20, 19, 20, 20, 21, 20, 20, 20, 21, 22, 20, 19, 20, 20, 21, 20, 21, 20, 19, 8, 11, 13, 14, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 18, 18, 19, 18, 19, 19, 19, 19, 21, 19, 19, 21, 19, 20, 20, 20, 19, 18, 18, 8, 12, 14, 15, 16, 16, 16, 16, 17, 17, 17, 19, 18, 18, 19, 19, 20, 19, 18, 20, 19, 20, 20, 19, 19, 20, 20, 21, 21, 20, 19, 19, 19, 19, 19, 19, 20, 21, 20, 19, 19, 8, 12, 14, 15, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 19, 19, 20, 21, 20, 21, 19, 21, 20, 20, 20, 20, 21, 20, 19, 20, 19, 20, 20, 20, 19, 22, 21, 21, 19, 9, 12, 14, 15, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20, 19, 19, 19, 9, 13, 15, 16, 17, 17, 18, 18, 18, 19, 18, 20, 19, 20, 20, 20, 19, 9, 13, 15, 16, 17, 17, 18, 18, 18, 20, 18, 19, 20, 20, 20, 20, 19, 20, 19, 9, 13, 15, 16, 17, 18, 18, 18, 19, 19, 19, 19, 10, 14, 16, 17, 18, 18, 19, 19, 19, 19, 19, 10, 14, 16, 17, 18, 18, 18, 19, 19, 10, 14, 16, 17, 18, 18, 18, 19, 19, 20, 19, 10, 14, 16, 18, 18, 18, 19, 20, 19, 19, 10, 14, 17, 18, 18, 18, 10, 15, 17, 18, 19, 19, 21, 19, 11, 15, 17, 18, 18, 19, 19, 11, 15, 17, 18, 19, 19, 11, 15, 17, 18, 11, 15, 18, 19, 19, 11, 15, 18, 19, 19, 11, 16, 18, 19, 11, 15, 18, 19, 11, 16, 18, 12, 16, 18, 19, 12, 16, 19, 12, 16, 19, 19, 19, 12, 16, 19, 12, 16, 19, 19, 12, 16, 18, 12, 16, 19, 12, 17, 19, 12, 17, 19, 12, 17, 19, 12, 17, 19, 13, 17, 13, 17, 13, 17, 19, 19, 13, 17, 13, 17, 19, 13, 17, 13, 18, 19, 13, 17, 19, 13, 18, 13, 17, 13, 18, 13, 18, 13, 18, 13, 18, 13, 18, 13, 18, 14, 18, 19, 14, 18, 14, 18, 14, 18, 14, 18, 14, 19, 14, 19, 14, 18, 14, 18, 14, 18, 14, 19, 14, 14, 18, 14, 14, 19, 14, 18, 14, 19, 14, 19, 14, 15, 19, 15, 15, 15, 15, 19, 15, 19, 15, 15, 19, 15, 15, 19, 15, 19, 15, 19, 15, 19, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 15, 15, 15, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 16, 16, 16, 17, 17, 16, 17, 17, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 18, 17, 17, 17, 17, 18, 18, 17, 17, 17, 17, 17, 17, 17, 18, 17, 18, 18, 17, 17, 17, 18, 18, 18, 17, 18, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 18, 18, 18, 19, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 18, 18, 19, 18, 18, 18, 19, 18, 19, 18, 18, 19, 18, 18, 19, 19, 19, 19, 19, 18, 19, 18, 19, 18, 19, 19, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 19, 19, 19, 19, 19, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 19, 19, 19, 19, 21, 19, 19, 20, 19, 20, 19, 19, 19, 19, 19, 20, 20, 20, 19, 19, 19, 20, 19, 19, 19, 20, 20, 19, 20, 19, 19, 21, 20, 20, 19, 19, 19, 19, 19, 19, 20, 19, 20, 20, 20, 20, 20, 20, 20, 19, 19, 21, 20, 20, 19, 19, }; static const uint32_t coef3_huffcodes[1072] = { 0x001b2, 0x00069, 0x00000, 0x00004, 0x00006, 0x0000e, 0x00014, 0x00019, 0x00016, 0x0002b, 0x00030, 0x0003d, 0x0003c, 0x0005a, 0x0005f, 0x0006d, 0x0007e, 0x0005f, 0x0007f, 0x000b6, 0x000bc, 0x000d8, 0x000f2, 0x000fe, 0x000bc, 0x000fc, 0x00161, 0x0016e, 0x00174, 0x00176, 0x001a2, 0x001e3, 0x001f3, 0x00174, 0x0017a, 0x001ea, 0x002a8, 0x002c4, 0x002e6, 0x00314, 0x00346, 0x00367, 0x003e9, 0x002e5, 0x002ee, 0x003d6, 0x00555, 0x00554, 0x00557, 0x005c3, 0x005d6, 0x006e0, 0x0062f, 0x006e2, 0x00799, 0x00789, 0x007fa, 0x005ce, 0x007fe, 0x005ec, 0x007cc, 0x007af, 0x00aa7, 0x00b19, 0x00b94, 0x00b85, 0x00b9f, 0x00c48, 0x00c45, 0x00dd8, 0x00c4c, 0x00c4b, 0x00d99, 0x00d1f, 0x00dc2, 0x00f95, 0x00fa2, 0x00bb5, 0x00b9f, 0x00f5d, 0x00bbf, 0x00f47, 0x0154a, 0x00fd5, 0x00f45, 0x00f7f, 0x0160d, 0x01889, 0x01757, 0x01722, 0x018b3, 0x0172d, 0x01a39, 0x01a18, 0x01bb3, 0x01b30, 0x01e63, 0x0173c, 0x01b35, 0x01723, 0x01e80, 0x01fee, 0x01761, 0x01ffc, 0x01f7f, 0x02c7c, 0x01fa1, 0x0177b, 0x01755, 0x0175a, 0x01fa6, 0x02eab, 0x0310a, 0x02c69, 0x03669, 0x03127, 0x03103, 0x02e43, 0x03662, 0x03165, 0x03124, 0x0313b, 0x03111, 0x03668, 0x0343b, 0x03c52, 0x03efc, 0x02e6c, 0x03fda, 0x03ef8, 0x02e7b, 0x03ee2, 0x03cc5, 0x03d72, 0x058c0, 0x03df8, 0x02ea9, 0x03e7e, 0x0556d, 0x05c82, 0x03d71, 0x03e7b, 0x03c42, 0x058d7, 0x03f4e, 0x06200, 0x03d70, 0x05cb2, 0x05c96, 0x05cb0, 0x03f45, 0x05cb1, 0x02e6d, 0x03110, 0x02f68, 0x05c90, 0x07ca6, 0x07c88, 0x06204, 0x062c8, 0x078a6, 0x07986, 0x079d5, 0x0b1ad, 0x07989, 0x0b079, 0x05cdd, 0x0aad4, 0x05de8, 0x07dcd, 0x07987, 0x05d67, 0x05d99, 0x0b91d, 0x07cf1, 0x05d9b, 0x079d7, 0x0b07b, 0x05c85, 0x05d9a, 0x07dcc, 0x07ebf, 0x07dce, 0x07dfb, 0x07ec0, 0x07d1a, 0x07a07, 0x05c84, 0x0c471, 0x07cf2, 0x0baef, 0x0b9d2, 0x05deb, 0x07bd6, 0x0b845, 0x05d98, 0x0b91a, 0x0bae8, 0x0c4e0, 0x0dc31, 0x0f93d, 0x0bbce, 0x0d1d2, 0x0f7a9, 0x0d9b9, 0x0bbcb, 0x0b900, 0x0aad7, 0x0babd, 0x0c4e1, 0x0f46f, 0x0c588, 0x0c58b, 0x160e6, 0x0bbcf, 0x0bac3, 0x0f945, 0x0f7a3, 0x0d1c1, 0x0fb8e, 0x0f7a4, 0x0fb8c, 0x0f40c, 0x0c473, 0x0fd72, 0x0bbcd, 0x0fffa, 0x0f940, 0x0bbc9, 0x0f7a8, 0x1a1ed, 0x0bbc5, 0x1f26f, 0x163fd, 0x160c7, 0x1a1f5, 0x0f947, 0x163fc, 0x154b3, 0x0fff6, 0x163f6, 0x160e9, 0x1a1f0, 0x0bab9, 0x0baba, 0x17086, 0x0b903, 0x0fd75, 0x0f308, 0x176f3, 0x163ff, 0x0fd7d, 0x1bb78, 0x163fb, 0x188db, 0x1a1f7, 0x154b2, 0x172fd, 0x163f4, 0x1bb73, 0x172ff, 0x0babc, 0x0f97d, 0x1a1f3, 0x1bb6d, 0x1ffd5, 0x1a1f4, 0x1f272, 0x17380, 0x17382, 0x1ffe7, 0x0bac8, 0x0bbc4, 0x188d3, 0x160e0, 0x0fd7b, 0x1725f, 0x172f5, 0x1bb79, 0x1fad9, 0x1f269, 0x188d0, 0x0bac4, 0x0bac5, 0x31185, 0x188d2, 0x188cc, 0x31187, 0x3e7fe, 0x188d1, 0x1bb6c, 0x1f268, 0x1fad2, 0x1ffd9, 0x1a1ea, 0x1bb68, 0x1facb, 0x3fdb2, 0x1e81a, 0x188ce, 0x172fb, 0x1a1ef, 0x1face, 0x1bb70, 0x0bac1, 0x1bb6b, 0x172f8, 0x1bb66, 0x1ffdf, 0x1bb6a, 0x1ffd7, 0x1f266, 0x176f8, 0x37653, 0x1fa7e, 0x31182, 0x1fac8, 0x2c7e3, 0x370ee, 0x176ec, 0x176e9, 0x2e4bc, 0x160c5, 0x3765a, 0x3ce9c, 0x17373, 0x176e8, 0x188d4, 0x176f1, 0x176ef, 0x37659, 0x1bb7c, 0x1ffde, 0x176f2, 0x3118b, 0x2c7d4, 0x37651, 0x5ce9f, 0x37650, 0x31191, 0x3f4f6, 0x3f4f5, 0x7a06c, 0x1fac1, 0x5c97b, 0x2c7e0, 0x79d3a, 0x3e7fd, 0x2c7df, 0x3f4f0, 0x7a06d, 0x376c1, 0x79d3b, 0x00004, 0x00014, 0x00059, 0x000ab, 0x000b8, 0x00177, 0x001f5, 0x001f2, 0x00315, 0x003fc, 0x005bd, 0x0062d, 0x006e8, 0x007dd, 0x00b04, 0x007cd, 0x00b1e, 0x00d1e, 0x00f15, 0x00f3b, 0x00f41, 0x01548, 0x018b0, 0x0173b, 0x01884, 0x01a1c, 0x01bb4, 0x01f25, 0x017b5, 0x0176d, 0x01ef8, 0x02e73, 0x03107, 0x03125, 0x03105, 0x02e49, 0x03ce8, 0x03ef9, 0x03e5e, 0x02e72, 0x03471, 0x03fd9, 0x0623f, 0x078a0, 0x06867, 0x05cb3, 0x06272, 0x068ec, 0x06e9a, 0x079d4, 0x06e98, 0x0b1aa, 0x06e1a, 0x07985, 0x068ee, 0x06e9b, 0x05c88, 0x0b1ac, 0x07dfa, 0x05d65, 0x07cf0, 0x07cbf, 0x0c475, 0x160eb, 0x1bb7e, 0x0f7a6, 0x1fedd, 0x160e3, 0x0fffb, 0x0fb8d, 0x0fff9, 0x0d1c0, 0x0c58c, 0x1a1e9, 0x0bab8, 0x0f5cf, 0x0fff5, 0x376c5, 0x1a1ec, 0x160ed, 0x1fede, 0x1fac9, 0x1a1eb, 0x1f224, 0x176ee, 0x0fd79, 0x17080, 0x17387, 0x1bb7a, 0x1ffe9, 0x176f7, 0x17385, 0x17781, 0x2c7d5, 0x17785, 0x1ffe3, 0x163f5, 0x1fac2, 0x3e7f9, 0x3118d, 0x3fdb1, 0x1ffe2, 0x1f226, 0x3118a, 0x2c7d9, 0x31190, 0x3118c, 0x3f4f3, 0x1bb7f, 0x1bb72, 0x31184, 0xb92f4, 0x3e7fb, 0x6e1d9, 0x1faca, 0x62300, 0x3fdb8, 0x3d037, 0x3e7fc, 0x62301, 0x3f4f2, 0x1f26a, 0x0000e, 0x00063, 0x000f8, 0x001ee, 0x00377, 0x003f7, 0x006e3, 0x005cc, 0x00b05, 0x00dd2, 0x00fd4, 0x0172e, 0x0172a, 0x01e23, 0x01f2d, 0x01763, 0x01769, 0x0176c, 0x02e75, 0x03104, 0x02ec1, 0x03e58, 0x0583f, 0x03f62, 0x03f44, 0x058c5, 0x0623c, 0x05cf4, 0x07bd7, 0x05d9d, 0x0aad2, 0x05d66, 0x0b1a9, 0x0b078, 0x07cfe, 0x0b918, 0x0c46f, 0x0b919, 0x0b847, 0x06e1b, 0x0b84b, 0x0aad8, 0x0fd74, 0x172f4, 0x17081, 0x0f97c, 0x1f273, 0x0f7a0, 0x0fd7c, 0x172f7, 0x0fd7a, 0x1bb77, 0x172fe, 0x1f270, 0x0fd73, 0x1bb7b, 0x1a1bc, 0x1bb7d, 0x0bbc3, 0x172f6, 0x0baeb, 0x0fb8f, 0x3f4f4, 0x3fdb4, 0x376c8, 0x3e7fa, 0x1ffd0, 0x62303, 0xb92f5, 0x1f261, 0x31189, 0x3fdb5, 0x2c7db, 0x376c9, 0x1fad6, 0x1fad1, 0x00015, 0x000f0, 0x002e0, 0x0058e, 0x005d7, 0x00c4d, 0x00fa1, 0x00bdb, 0x01756, 0x01f70, 0x02c19, 0x0313c, 0x0370f, 0x03cc0, 0x02ea8, 0x058c6, 0x058c7, 0x02eb7, 0x058d0, 0x07d18, 0x0aa58, 0x0b848, 0x05d9e, 0x05d6c, 0x0b84c, 0x0c589, 0x0b901, 0x163f8, 0x0bac9, 0x0b9c5, 0x0f93c, 0x188d8, 0x0bbc7, 0x160ec, 0x0fd6f, 0x188d9, 0x160ea, 0x0f7a7, 0x0f944, 0x0baab, 0x0dc3a, 0x188cf, 0x176fb, 0x2c7d8, 0x2c7d7, 0x1bb75, 0x5ce9e, 0x62302, 0x370ed, 0x176f4, 0x1ffd1, 0x370ef, 0x3f4f8, 0x376c7, 0x1ffe1, 0x376c6, 0x176ff, 0x6e1d8, 0x176f6, 0x17087, 0x0f5cd, 0x00035, 0x001a0, 0x0058b, 0x00aac, 0x00b9a, 0x0175f, 0x01e22, 0x01e8c, 0x01fb2, 0x0310b, 0x058d1, 0x0552e, 0x05c27, 0x0686e, 0x07ca7, 0x0c474, 0x0dc33, 0x07bf2, 0x05de9, 0x07a35, 0x0baaa, 0x0b9eb, 0x0fb95, 0x0b9b8, 0x17381, 0x1f262, 0x188cd, 0x17088, 0x172fa, 0x0f7a2, 0x1fad3, 0x0bac0, 0x3765c, 0x1fedf, 0x1f225, 0x1fad4, 0x2c7da, 0x5ce9d, 0x3e7f8, 0x1e203, 0x188d7, 0x00054, 0x002c0, 0x007a1, 0x00f78, 0x01b36, 0x01fa3, 0x0313a, 0x03436, 0x0343a, 0x07d1d, 0x07bd8, 0x05cdf, 0x0b846, 0x0b189, 0x0d9b8, 0x0fff8, 0x0d9be, 0x0c58a, 0x05dea, 0x0d1d3, 0x160e4, 0x1f26b, 0x188da, 0x1e202, 0x2c7d2, 0x163fe, 0x31193, 0x17782, 0x376c2, 0x2c7d1, 0x3fdb0, 0x3765d, 0x2c7d0, 0x1fad0, 0x1e201, 0x188dd, 0x2c7e2, 0x37657, 0x37655, 0x376c4, 0x376c0, 0x176ea, 0x0006f, 0x003cf, 0x00dd5, 0x01f23, 0x02c61, 0x02ed0, 0x05d54, 0x0552d, 0x07883, 0x0b1a8, 0x0b91c, 0x0babf, 0x0b902, 0x0f7aa, 0x0f7a5, 0x1a1e8, 0x1ffd6, 0x0babe, 0x1a1bf, 0x163f3, 0x1ffd8, 0x1fad7, 0x1f275, 0x1ffdc, 0x0007d, 0x005bc, 0x01549, 0x02a99, 0x03def, 0x06273, 0x079d6, 0x07d1b, 0x0aad3, 0x0d0fc, 0x2c7dd, 0x188d6, 0x0bac2, 0x2c7e1, 0x1bb76, 0x1a1bd, 0x31186, 0x0fd78, 0x1a1be, 0x31183, 0x3fdb6, 0x3f4f1, 0x37652, 0x1fad5, 0x3f4f9, 0x3e7ff, 0x5ce9c, 0x3765b, 0x31188, 0x17372, 0x000bd, 0x0078b, 0x01f21, 0x03c43, 0x03ded, 0x0aad6, 0x07ec1, 0x0f942, 0x05c86, 0x17089, 0x0babb, 0x1ffe8, 0x2c7de, 0x1f26e, 0x1fac4, 0x3f4f7, 0x37656, 0x1fa7d, 0x376c3, 0x3fdb3, 0x3118f, 0x1fac6, 0x000f8, 0x007ed, 0x01efd, 0x03e7a, 0x05c91, 0x0aad9, 0x0baec, 0x0dc32, 0x0f46e, 0x1e200, 0x176fa, 0x3765e, 0x3fdb7, 0x2c7d6, 0x3fdb9, 0x37654, 0x37658, 0x3118e, 0x1ffdb, 0x000f6, 0x00c43, 0x03106, 0x068ef, 0x0b84d, 0x0b188, 0x0bbcc, 0x1f264, 0x1bb69, 0x17386, 0x1fac0, 0x00171, 0x00f39, 0x03e41, 0x068ed, 0x0d9bc, 0x0f7a1, 0x1bb67, 0x1ffdd, 0x176f9, 0x001b9, 0x00f7d, 0x03f63, 0x0d0fd, 0x0b9ea, 0x188dc, 0x1fac3, 0x1a1f2, 0x31192, 0x1ffe4, 0x001f6, 0x01754, 0x06865, 0x0f309, 0x160e5, 0x176f5, 0x3765f, 0x1facc, 0x001e9, 0x01a1a, 0x06201, 0x0f105, 0x176f0, 0x002df, 0x01756, 0x05d6d, 0x163fa, 0x176ed, 0x00342, 0x02e40, 0x0d0ff, 0x17082, 0x003cd, 0x02a98, 0x0fffc, 0x2c7dc, 0x1fa7f, 0x003fe, 0x03764, 0x0fffd, 0x176fc, 0x1fac5, 0x002f7, 0x02ed1, 0x0fb97, 0x0058a, 0x02edc, 0x0bbc8, 0x005d4, 0x0623d, 0x160e8, 0x0062e, 0x05830, 0x163f9, 0x006eb, 0x06205, 0x1f274, 0x007de, 0x062c9, 0x1f265, 0x005c9, 0x05cde, 0x1ffd3, 0x005d4, 0x07988, 0x007ce, 0x0b849, 0x00b1b, 0x05c89, 0x1fac7, 0x00b93, 0x05c83, 0x00b9e, 0x0f14f, 0x00c4a, 0x0b9c7, 0x00dd4, 0x0c470, 0x1f271, 0x00f38, 0x0fb96, 0x176eb, 0x00fa0, 0x163f7, 0x00bb2, 0x0b91b, 0x00bbe, 0x0f102, 0x00f44, 0x0f946, 0x1facd, 0x00f79, 0x0d9bd, 0x0154d, 0x0bbc6, 0x00fd2, 0x160e7, 0x0172b, 0x188cb, 0x0175e, 0x0fd76, 0x0175c, 0x1bb71, 0x0189f, 0x1a1ee, 0x01f24, 0x1a1f6, 0x01ba7, 0x0bbca, 0x01f7d, 0x0ffff, 0x01f2e, 0x1bb65, 0x01bb5, 0x172f9, 0x01fef, 0x1f26c, 0x01f3e, 0x0fd77, 0x01762, 0x1bb6e, 0x01ef9, 0x172fc, 0x01fa0, 0x02ab7, 0x02e4a, 0x1f267, 0x01fb3, 0x1ffda, 0x02e42, 0x03101, 0x17780, 0x0313d, 0x03475, 0x17784, 0x03126, 0x1facf, 0x03c51, 0x17783, 0x03e40, 0x1ffe5, 0x03663, 0x1ffe0, 0x03e8f, 0x1f26d, 0x0343c, 0x03cc1, 0x176fd, 0x03e45, 0x02ec0, 0x03f61, 0x03dee, 0x03fd8, 0x0583e, 0x02e45, 0x03e59, 0x03d02, 0x05ce8, 0x05568, 0x176fe, 0x02f69, 0x1fad8, 0x058c1, 0x05c83, 0x1ffe6, 0x06271, 0x06e1c, 0x062c7, 0x068e1, 0x0552f, 0x06864, 0x06866, 0x06e99, 0x05cbc, 0x07ca5, 0x078a1, 0x05c82, 0x07dcf, 0x0623b, 0x0623e, 0x068e8, 0x07a36, 0x05d9c, 0x0b077, 0x07cf3, 0x07a34, 0x07ca4, 0x07d19, 0x079d2, 0x07d1c, 0x07bd9, 0x0b84a, 0x0fb94, 0x0aad5, 0x0dc30, 0x07bf3, 0x0baee, 0x0b07a, 0x0c472, 0x0b91e, 0x0d9ba, 0x05d9f, 0x0d0fe, 0x0b9c6, 0x05c87, 0x0f14e, 0x0baed, 0x0b92e, 0x0f103, 0x0b9c4, 0x0fb91, 0x0d9bb, 0x0b1ab, 0x0c58d, 0x0fffe, 0x0f93b, 0x0f941, 0x0baea, 0x0b91f, 0x0f5cc, 0x0d9bf, 0x0f943, 0x0f104, 0x1f260, 0x0fb92, 0x0f93f, 0x0f3a6, 0x0bac7, 0x0f7ab, 0x0bac6, 0x17383, 0x0fd6d, 0x0bae9, 0x0fd6e, 0x1e74f, 0x188ca, 0x1f227, 0x0fb93, 0x0fb90, 0x0fff7, 0x17085, 0x17083, 0x160e1, 0x17084, 0x0f93e, 0x160e2, 0x160c6, 0x1a1f1, 0x1bb6f, 0x17384, 0x0fd70, 0x1f263, 0x188d5, 0x173a6, 0x0f5ce, 0x163f2, 0x0fd71, 0x1ffd2, 0x160c4, 0x1ffd4, 0x2c7d3, 0x1bb74, }; static const uint8_t coef3_huffbits[1072] = { 9, 7, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 13, 14, 14, 13, 14, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 14, 14, 15, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 15, 16, 16, 16, 16, 15, 15, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 16, 15, 15, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 16, 17, 16, 17, 17, 16, 17, 16, 17, 16, 16, 17, 17, 17, 16, 17, 16, 16, 17, 16, 17, 16, 17, 17, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 16, 17, 17, 16, 17, 17, 17, 17, 17, 17, 17, 17, 16, 18, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 17, 17, 18, 17, 17, 18, 19, 17, 17, 17, 18, 17, 17, 17, 18, 18, 18, 17, 17, 17, 18, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 18, 18, 18, 17, 18, 18, 18, 17, 17, 18, 18, 18, 18, 19, 18, 18, 19, 19, 20, 18, 19, 18, 19, 19, 18, 19, 20, 18, 19, 4, 6, 7, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 15, 15, 15, 15, 16, 16, 15, 16, 16, 15, 16, 17, 17, 17, 17, 17, 16, 16, 16, 16, 16, 17, 17, 17, 16, 18, 17, 17, 17, 18, 17, 17, 18, 17, 17, 17, 17, 17, 18, 17, 18, 18, 18, 17, 17, 18, 19, 18, 18, 17, 17, 18, 18, 18, 18, 19, 17, 17, 18, 20, 19, 19, 18, 19, 18, 19, 19, 19, 19, 17, 5, 7, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 17, 17, 17, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 16, 16, 19, 18, 18, 19, 17, 19, 20, 17, 18, 18, 18, 18, 18, 18, 6, 8, 10, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 17, 17, 17, 16, 16, 17, 17, 17, 17, 17, 17, 17, 16, 16, 16, 17, 18, 18, 18, 17, 19, 19, 18, 18, 17, 18, 19, 18, 17, 18, 18, 19, 18, 17, 17, 6, 9, 11, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 17, 16, 17, 17, 17, 17, 17, 17, 17, 18, 17, 18, 17, 17, 18, 18, 19, 19, 17, 17, 7, 10, 12, 13, 13, 14, 14, 14, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 17, 18, 18, 18, 18, 18, 18, 18, 18, 17, 17, 18, 18, 18, 18, 18, 18, 7, 10, 12, 13, 14, 15, 15, 15, 15, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 8, 11, 13, 14, 15, 15, 15, 15, 16, 16, 18, 17, 17, 18, 17, 17, 18, 17, 17, 18, 18, 19, 18, 18, 19, 19, 19, 18, 18, 18, 8, 11, 13, 14, 15, 16, 16, 16, 16, 17, 17, 17, 18, 17, 18, 19, 18, 18, 18, 18, 18, 18, 8, 12, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 17, 9, 12, 14, 15, 16, 16, 17, 17, 17, 17, 18, 9, 12, 14, 15, 16, 17, 17, 17, 18, 9, 13, 15, 16, 17, 17, 18, 17, 18, 17, 9, 13, 15, 16, 17, 18, 18, 18, 10, 13, 15, 16, 18, 10, 14, 16, 17, 18, 10, 14, 16, 17, 10, 14, 16, 18, 18, 10, 14, 16, 18, 18, 11, 15, 16, 11, 15, 17, 11, 15, 17, 11, 15, 17, 11, 15, 17, 11, 15, 17, 12, 16, 17, 12, 15, 12, 16, 12, 16, 18, 12, 16, 12, 16, 12, 16, 12, 16, 17, 12, 16, 18, 12, 17, 13, 16, 13, 16, 13, 16, 18, 13, 16, 13, 17, 13, 17, 13, 17, 13, 17, 13, 17, 13, 17, 13, 17, 13, 17, 13, 16, 13, 17, 13, 17, 13, 17, 14, 17, 14, 17, 14, 17, 14, 14, 14, 17, 14, 17, 14, 14, 18, 14, 14, 18, 14, 18, 14, 18, 14, 17, 14, 17, 14, 17, 14, 14, 18, 14, 15, 15, 15, 14, 15, 15, 14, 15, 15, 15, 18, 15, 18, 15, 15, 17, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 15, 15, 15, 15, 16, 16, 16, 16, 16, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 16, 16, 16, 17, 16, 16, 16, 17, 17, 17, 17, 17, 16, 17, 17, 17, 17, 16, 16, 16, 17, 17, 17, 17, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, }; static const uint32_t coef4_huffcodes[476] = { 0x00f01, 0x0001e, 0x00000, 0x00004, 0x00006, 0x0000d, 0x0000a, 0x00017, 0x0001d, 0x00017, 0x0002c, 0x00031, 0x00039, 0x0003e, 0x00039, 0x0005a, 0x00066, 0x00070, 0x0007b, 0x00070, 0x00077, 0x000af, 0x000c9, 0x000f2, 0x000f4, 0x000b2, 0x000e3, 0x0015b, 0x0015d, 0x00181, 0x0019d, 0x001e3, 0x001c5, 0x002b5, 0x002db, 0x00338, 0x003c3, 0x003cc, 0x003f0, 0x002cd, 0x003fa, 0x003a1, 0x005b4, 0x00657, 0x007ab, 0x0074d, 0x0074c, 0x00ac1, 0x00ac5, 0x0076b, 0x00ca8, 0x00f04, 0x00f00, 0x00fe3, 0x00f3c, 0x00f10, 0x00f39, 0x00fe6, 0x00e26, 0x00e90, 0x016c5, 0x01827, 0x01954, 0x015c5, 0x01958, 0x01f8a, 0x01c4a, 0x02b0f, 0x02b41, 0x02b0e, 0x033c6, 0x03050, 0x01c4f, 0x02d88, 0x0305c, 0x03c18, 0x02b4f, 0x02cc2, 0x03a47, 0x05680, 0x0569d, 0x06442, 0x06443, 0x06446, 0x0656e, 0x06444, 0x07120, 0x0748a, 0x0c1ba, 0x07e22, 0x07aa6, 0x07f25, 0x07aa7, 0x07e20, 0x0c11b, 0x0c118, 0x07aa5, 0x0ad0a, 0x0f389, 0x19ebb, 0x0caad, 0x0fe42, 0x0fe40, 0x16c34, 0x2b4e5, 0x33d65, 0x16c30, 0x1e7ae, 0x1e25c, 0x18370, 0x1e703, 0x19eba, 0x16c37, 0x0e234, 0x16c6e, 0x00004, 0x0002a, 0x00061, 0x00075, 0x000cb, 0x000ff, 0x00190, 0x001eb, 0x001d1, 0x002b9, 0x00307, 0x00339, 0x0033f, 0x003fb, 0x003b4, 0x0060c, 0x00679, 0x00645, 0x0067d, 0x0078a, 0x007e3, 0x00749, 0x00ac4, 0x00ad2, 0x00ae3, 0x00c10, 0x00c16, 0x00ad1, 0x00cf4, 0x00fe2, 0x01586, 0x00e9d, 0x019f1, 0x01664, 0x01e26, 0x01d38, 0x02b4d, 0x033c5, 0x01fc2, 0x01fc3, 0x01d28, 0x03c1d, 0x0598e, 0x0f094, 0x07aa4, 0x0ad38, 0x0ac0c, 0x0c11a, 0x079ea, 0x0c881, 0x0fe44, 0x0b635, 0x0ac0d, 0x0b61e, 0x05987, 0x07121, 0x0f382, 0x0f387, 0x0e237, 0x0fe47, 0x0f383, 0x0f091, 0x0f385, 0x0e233, 0x182ee, 0x19eb8, 0x1663e, 0x0f093, 0x00014, 0x00058, 0x00159, 0x00167, 0x00300, 0x003d4, 0x005b5, 0x0079d, 0x0076a, 0x00b67, 0x00b60, 0x00f05, 0x00cf0, 0x00f17, 0x00e95, 0x01822, 0x01913, 0x016c2, 0x0182f, 0x01959, 0x01fcb, 0x01e27, 0x01c40, 0x033c7, 0x01e7b, 0x01c49, 0x02d89, 0x01e23, 0x01660, 0x03f12, 0x02cc6, 0x033e1, 0x05b34, 0x0609a, 0x06569, 0x07488, 0x07e21, 0x0cf5f, 0x0712c, 0x0389d, 0x067cf, 0x07f28, 0x1663f, 0x33d67, 0x1663d, 0x1e25d, 0x3c1ab, 0x15c44, 0x16c36, 0x0001f, 0x000ec, 0x00323, 0x005b2, 0x0079f, 0x00ac2, 0x00f16, 0x00e9e, 0x01956, 0x01e0f, 0x019ea, 0x01666, 0x02b89, 0x02b02, 0x02d8c, 0x03c1b, 0x03c19, 0x032b5, 0x03f9c, 0x02ccf, 0x03897, 0x05b35, 0x0ad02, 0x07f29, 0x06441, 0x03884, 0x07888, 0x0784e, 0x06568, 0x0c1bb, 0x05986, 0x067cc, 0x0fe49, 0x0fe48, 0x0c1bc, 0x0fe41, 0x18371, 0x1663c, 0x0e231, 0x0711e, 0x0ad09, 0x0f092, 0x0002d, 0x001db, 0x00781, 0x00c1a, 0x00f55, 0x01580, 0x01ea8, 0x02d9b, 0x032af, 0x03f16, 0x03c1c, 0x07834, 0x03c45, 0x0389c, 0x067ce, 0x06445, 0x0c1b9, 0x07889, 0x07f3a, 0x0784f, 0x07f2b, 0x0ad0b, 0x0f090, 0x0c11d, 0x0e94e, 0x0711f, 0x0e9f1, 0x0f38e, 0x079e9, 0x0ad03, 0x0f09b, 0x0caae, 0x0fe46, 0x2b4e6, 0x0e9f0, 0x19eb6, 0x67ac1, 0x67ac0, 0x33d66, 0x0f388, 0x00071, 0x003a0, 0x00ca9, 0x01829, 0x01d39, 0x02b43, 0x02cc4, 0x06554, 0x0f09a, 0x0b61f, 0x067cd, 0x0711c, 0x0b636, 0x07f2a, 0x0b634, 0x0c11f, 0x0cf5e, 0x0b61d, 0x0f06b, 0x0caab, 0x0c1be, 0x0e94c, 0x0f099, 0x182ed, 0x0e94f, 0x0c119, 0x0e232, 0x2b4e4, 0x0f38a, 0x19eb4, 0x1e25f, 0x0e94d, 0x000b7, 0x00785, 0x016cc, 0x03051, 0x033c4, 0x0656f, 0x03891, 0x0711d, 0x0caaf, 0x0f097, 0x07489, 0x0f098, 0x0c880, 0x0caaa, 0x0f386, 0x19eb7, 0x16c6f, 0x0f384, 0x182e8, 0x182e9, 0x0e230, 0x1e700, 0x33d62, 0x33d63, 0x33d64, 0x16c33, 0x0e216, 0x000fd, 0x00c15, 0x01665, 0x03c4a, 0x07f3b, 0x07896, 0x0c11c, 0x0e215, 0x16c32, 0x0f38b, 0x0f38d, 0x182ea, 0x1e701, 0x712df, 0x15c46, 0x00194, 0x00fe0, 0x03f13, 0x0748b, 0x0f096, 0x0cf80, 0x1e25e, 0xe25bd, 0x33d61, 0x16c31, 0x001f9, 0x01912, 0x05710, 0x0f3d0, 0x0c1bf, 0x00301, 0x01e24, 0x0ad08, 0x003cd, 0x01c41, 0x0c1bd, 0x00563, 0x03a52, 0x0f3d1, 0x00570, 0x02cce, 0x0e217, 0x0067b, 0x0655d, 0x0074b, 0x06447, 0x00c12, 0x074fb, 0x00f08, 0x0b61c, 0x00e22, 0x0fe43, 0x016c7, 0x01836, 0x019f2, 0x01c43, 0x01d3f, 0x01fcf, 0x02b4c, 0x0304c, 0x032b6, 0x03a46, 0x05607, 0x03f17, 0x02cc5, 0x0609b, 0x0655c, 0x07e23, 0x067c1, 0x07f26, 0x07f27, 0x0f095, 0x0e9f3, 0x0cf81, 0x0c11e, 0x0caac, 0x0f38f, 0x0e9f2, 0x074fa, 0x0e236, 0x0fe45, 0x1c428, 0x0e235, 0x182ef, 0x19eb5, 0x0f3d6, 0x182ec, 0x16c35, 0x0f38c, 0x2b4e7, 0x15c47, 0xe25bc, 0x1e702, 0x1c4b6, 0x0e25a, 0x3c1aa, 0x15c45, 0x1c429, 0x19eb9, 0x1e7af, 0x182eb, 0x1e0d4, 0x3896e, }; static const uint8_t coef4_huffbits[476] = { 12, 6, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 11, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 15, 15, 15, 15, 15, 16, 16, 15, 16, 16, 17, 16, 16, 16, 17, 18, 18, 17, 17, 17, 17, 17, 17, 17, 17, 17, 4, 6, 7, 8, 8, 8, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 14, 13, 14, 14, 14, 13, 13, 14, 14, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 16, 16, 16, 16, 17, 17, 17, 18, 16, 5, 8, 9, 10, 10, 10, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 13, 14, 14, 13, 14, 14, 15, 14, 15, 15, 15, 16, 15, 16, 16, 15, 15, 15, 18, 18, 18, 17, 18, 17, 17, 6, 9, 10, 11, 11, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 16, 15, 15, 15, 15, 15, 15, 16, 16, 15, 16, 16, 16, 16, 17, 18, 17, 16, 16, 16, 7, 10, 11, 12, 12, 13, 13, 14, 14, 14, 14, 15, 14, 15, 15, 15, 16, 15, 15, 15, 15, 16, 16, 16, 17, 16, 17, 16, 15, 16, 16, 16, 16, 18, 17, 17, 19, 19, 18, 16, 7, 11, 12, 13, 14, 14, 15, 15, 16, 16, 15, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 17, 16, 17, 17, 16, 17, 18, 16, 17, 17, 17, 8, 11, 13, 14, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 16, 17, 17, 17, 17, 18, 18, 18, 17, 17, 8, 12, 14, 14, 15, 15, 16, 17, 17, 16, 16, 17, 17, 20, 17, 9, 12, 14, 16, 16, 16, 17, 21, 18, 17, 9, 13, 15, 16, 16, 10, 13, 16, 10, 14, 16, 11, 15, 16, 11, 15, 17, 11, 15, 12, 15, 12, 16, 12, 16, 13, 16, 13, 13, 13, 14, 14, 13, 14, 14, 14, 15, 15, 14, 15, 15, 15, 15, 15, 15, 15, 16, 17, 16, 16, 16, 16, 17, 16, 17, 16, 18, 17, 17, 17, 16, 17, 17, 16, 18, 17, 21, 17, 18, 17, 18, 17, 18, 17, 17, 17, 17, 19, }; static const uint32_t coef5_huffcodes[435] = { 0x00347, 0x0000b, 0x00001, 0x00001, 0x0000c, 0x00004, 0x00010, 0x00015, 0x0001f, 0x0000b, 0x00023, 0x00026, 0x00029, 0x00035, 0x00037, 0x00001, 0x00015, 0x0001a, 0x0001d, 0x0001c, 0x0001e, 0x0004e, 0x00049, 0x00051, 0x00078, 0x00004, 0x00000, 0x00008, 0x0000d, 0x0007b, 0x00005, 0x00032, 0x00095, 0x00091, 0x00096, 0x000a1, 0x000d9, 0x00003, 0x00019, 0x00061, 0x00066, 0x00060, 0x00017, 0x0000e, 0x00063, 0x001a0, 0x001b7, 0x001e6, 0x001e7, 0x001b6, 0x00018, 0x001e8, 0x00038, 0x00031, 0x00005, 0x0003d, 0x00027, 0x001ea, 0x0001a, 0x000c5, 0x000f9, 0x000ff, 0x000db, 0x00250, 0x000fc, 0x0025c, 0x00008, 0x00075, 0x003d7, 0x003d3, 0x001b0, 0x0007c, 0x003ca, 0x00036, 0x00189, 0x004a6, 0x004a2, 0x004fb, 0x000c0, 0x0007f, 0x0009a, 0x00311, 0x0006e, 0x0009b, 0x0068c, 0x006c0, 0x00484, 0x00012, 0x000c3, 0x0094f, 0x00979, 0x009f9, 0x00d09, 0x00da6, 0x00da8, 0x00901, 0x000c1, 0x00373, 0x00d08, 0x009fa, 0x00d8b, 0x00d85, 0x00d86, 0x000df, 0x006e2, 0x000ce, 0x00f24, 0x009fe, 0x001f7, 0x007c1, 0x000cf, 0x009fc, 0x009ff, 0x00d89, 0x00da9, 0x009fd, 0x001f8, 0x01a36, 0x0128c, 0x0129d, 0x01a37, 0x00196, 0x003ea, 0x00f8b, 0x00d93, 0x01e45, 0x01e58, 0x01e4b, 0x01e59, 0x013f1, 0x00309, 0x00265, 0x00308, 0x0243a, 0x027e1, 0x00f89, 0x00324, 0x03cbc, 0x03c86, 0x03695, 0x0243c, 0x0243b, 0x0243e, 0x01e4a, 0x003a5, 0x03468, 0x03428, 0x03c84, 0x027e0, 0x025e2, 0x01880, 0x00197, 0x00325, 0x03cb7, 0x0791e, 0x007ec, 0x06c75, 0x004c8, 0x04bc7, 0x004c6, 0x00983, 0x0481e, 0x01b53, 0x0251b, 0x01b58, 0x00984, 0x04fa8, 0x03cbb, 0x00f8a, 0x00322, 0x0346a, 0x0243d, 0x00326, 0x03469, 0x0481f, 0x0481d, 0x00746, 0x09032, 0x01b50, 0x01d13, 0x0d8e4, 0x0481b, 0x06c74, 0x0796b, 0x07969, 0x00985, 0x0d8e3, 0x00986, 0x00fa2, 0x01301, 0x06c7c, 0x00987, 0x03cb8, 0x0f4af, 0x00e88, 0x1b1c0, 0x00fce, 0x033eb, 0x03f6a, 0x03f69, 0x00fcf, 0x0791f, 0x004c9, 0x04871, 0x00fcd, 0x00982, 0x00fcc, 0x00fa3, 0x01d12, 0x0796c, 0x01b47, 0x00321, 0x0796a, 0x0d8e2, 0x04872, 0x04873, 0x0000e, 0x00014, 0x0000a, 0x000a0, 0x00012, 0x0007d, 0x001a2, 0x0003b, 0x0025f, 0x000dd, 0x0027c, 0x00343, 0x00368, 0x0036b, 0x0003e, 0x001fa, 0x00485, 0x001b3, 0x0007f, 0x001b1, 0x0019e, 0x004ba, 0x007ad, 0x00339, 0x00066, 0x007a4, 0x00793, 0x006c6, 0x0007e, 0x000f1, 0x00372, 0x009fb, 0x00d83, 0x00d8a, 0x00947, 0x009f4, 0x001d0, 0x01b09, 0x01b4b, 0x007ec, 0x003e1, 0x000ca, 0x003ec, 0x02539, 0x04fa9, 0x01b57, 0x03429, 0x03d2a, 0x00d97, 0x003a7, 0x00dc0, 0x00d96, 0x00dc1, 0x007eb, 0x03cba, 0x00c43, 0x00c41, 0x01b52, 0x007ef, 0x00323, 0x03cb9, 0x03c83, 0x007d0, 0x007ed, 0x06c7f, 0x09033, 0x03f6c, 0x36383, 0x1e95d, 0x06c78, 0x00747, 0x01b51, 0x00022, 0x00016, 0x00039, 0x00252, 0x00079, 0x00486, 0x00338, 0x00369, 0x00d88, 0x00026, 0x00d87, 0x00f4b, 0x00d82, 0x00027, 0x001e1, 0x01a15, 0x007c7, 0x012f0, 0x001e0, 0x006d0, 0x01a16, 0x01e44, 0x01e5f, 0x03690, 0x00d90, 0x00c42, 0x00daf, 0x00d92, 0x00f80, 0x00cfb, 0x0342f, 0x0487f, 0x01b46, 0x07968, 0x00d95, 0x00d91, 0x01b55, 0x03f68, 0x04bc6, 0x03cbd, 0x00f81, 0x00320, 0x00069, 0x000fe, 0x006d5, 0x0033f, 0x000de, 0x007c6, 0x01e40, 0x00d94, 0x00f88, 0x03c8e, 0x03694, 0x00dae, 0x00dad, 0x00267, 0x003a6, 0x00327, 0x0487e, 0x007ee, 0x00749, 0x004c7, 0x03692, 0x01b56, 0x00fd1, 0x07a56, 0x06c77, 0x09031, 0x00748, 0x06c7a, 0x0796d, 0x033ea, 0x06c76, 0x00fd0, 0x36382, 0x1e417, 0x00745, 0x04faf, 0x0d8e1, 0x03f6b, 0x1e95c, 0x04fad, 0x0009e, 0x004bd, 0x0067c, 0x01b08, 0x003eb, 0x01b45, 0x03691, 0x0d8e5, 0x07904, 0x00981, 0x007ea, 0x019f4, 0x06c7d, 0x04fab, 0x04fac, 0x06c7e, 0x01300, 0x06c7b, 0x0006f, 0x003f7, 0x03c85, 0x004c4, 0x0001e, 0x006e1, 0x03693, 0x01b44, 0x00241, 0x01e46, 0x0019d, 0x00266, 0x004bb, 0x02538, 0x007ac, 0x01b54, 0x00902, 0x04870, 0x00da7, 0x00900, 0x00185, 0x06c79, 0x006e3, 0x003e9, 0x01e94, 0x003ed, 0x003f2, 0x0342e, 0x0346b, 0x0251a, 0x004c5, 0x01881, 0x0481c, 0x01b59, 0x03c87, 0x04fae, 0x007e9, 0x03f6d, 0x0f20a, 0x09030, 0x04faa, 0x0d8e6, 0x03f6f, 0x0481a, 0x03f6e, 0x1e416, 0x0d8e7, }; static const uint8_t coef5_huffbits[435] = { 10, 4, 2, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 9, 10, 10, 10, 10, 10, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 10, 10, 11, 11, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 12, 12, 13, 13, 13, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 14, 14, 14, 14, 14, 14, 13, 14, 14, 14, 14, 14, 14, 15, 14, 15, 14, 15, 15, 15, 15, 15, 15, 16, 15, 15, 14, 15, 16, 15, 14, 14, 15, 14, 14, 15, 14, 15, 15, 15, 16, 15, 17, 16, 15, 15, 15, 15, 16, 16, 16, 16, 17, 15, 16, 14, 16, 16, 17, 16, 16, 16, 16, 16, 15, 15, 15, 16, 16, 16, 16, 17, 15, 15, 15, 15, 16, 15, 15, 4, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 12, 13, 14, 14, 15, 15, 14, 14, 14, 14, 14, 14, 14, 15, 14, 14, 14, 15, 15, 15, 14, 14, 15, 15, 15, 16, 16, 18, 17, 15, 15, 15, 6, 9, 10, 10, 11, 11, 12, 12, 12, 13, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 14, 14, 15, 16, 15, 14, 14, 15, 7, 10, 11, 12, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 14, 15, 16, 15, 15, 16, 15, 15, 15, 16, 15, 16, 18, 17, 15, 15, 16, 16, 17, 15, 8, 11, 13, 13, 14, 15, 14, 16, 15, 16, 15, 15, 15, 15, 15, 15, 17, 15, 9, 12, 14, 15, 10, 13, 14, 15, 10, 13, 11, 14, 11, 14, 11, 15, 12, 15, 12, 12, 13, 15, 13, 14, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 14, 15, 15, 16, 16, 16, 15, 16, 16, 15, 16, 17, 16, }; static const uint16_t levels0[60] = { 317, 92, 62, 60, 19, 17, 10, 7, 6, 5, 5, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; static const uint16_t levels1[40] = { 311, 91, 61, 28, 10, 6, 5, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; static const uint16_t levels2[340] = { 181,110, 78, 63, 61, 62, 60, 61, 33, 41, 41, 19, 17, 19, 12, 11, 9, 11, 10, 6, 8, 7, 6, 4, 5, 5, 4, 4, 3, 4, 3, 5, 3, 4, 3, 3, 3, 3, 3, 3, 2, 2, 4, 2, 3, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; static const uint16_t levels3[180] = { 351,122, 76, 61, 41, 42, 24, 30, 22, 19, 11, 9, 10, 8, 5, 5, 4, 5, 5, 3, 3, 3, 3, 3, 3, 3, 2, 2, 3, 2, 2, 2, 3, 3, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; static const uint16_t levels4[70] = { 113, 68, 49, 42, 40, 32, 27, 15, 10, 5, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; static const uint16_t levels5[40] = { 214, 72, 42, 40, 18, 4, 4, 2, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; static const CoefVLCTable coef_vlcs[6] = { { sizeof(coef0_huffbits), coef0_huffcodes, coef0_huffbits, levels0, }, { sizeof(coef1_huffbits), coef1_huffcodes, coef1_huffbits, levels1, }, { sizeof(coef2_huffbits), coef2_huffcodes, coef2_huffbits, levels2, }, { sizeof(coef3_huffbits), coef3_huffcodes, coef3_huffbits, levels3, }, { sizeof(coef4_huffbits), coef4_huffcodes, coef4_huffbits, levels4, }, { sizeof(coef5_huffbits), coef5_huffcodes, coef5_huffbits, levels5, }, }; xmms-wma-1.0.5/ffmpeg-strip-wma/cutils.c0000644000175000017500000001362207727171267020427 0ustar whistlerwhistler/* * Various simple utilities for ffmpeg system * Copyright (c) 2000, 2001, 2002 Fabrice Bellard * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avformat.h" #if !defined(CONFIG_NOCUTILS) /** * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is * set to the next character in 'str' after the prefix. * * @param str input string * @param val prefix to test * @param ptr updated after the prefix in str in there is a match * @return TRUE if there is a match */ int strstart(const char *str, const char *val, const char **ptr) { const char *p, *q; p = str; q = val; while (*q != '\0') { if (*p != *q) return 0; p++; q++; } if (ptr) *ptr = p; return 1; } /** * Return TRUE if val is a prefix of str (case independent). If it * returns TRUE, ptr is set to the next character in 'str' after the * prefix. * * @param str input string * @param val prefix to test * @param ptr updated after the prefix in str in there is a match * @return TRUE if there is a match */ int stristart(const char *str, const char *val, const char **ptr) { const char *p, *q; p = str; q = val; while (*q != '\0') { if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q)) return 0; p++; q++; } if (ptr) *ptr = p; return 1; } /** * Copy the string str to buf. If str length is bigger than buf_size - * 1 then it is clamped to buf_size - 1. * NOTE: this function does what strncpy should have done to be * useful. NEVER use strncpy. * * @param buf destination buffer * @param buf_size size of destination buffer * @param str source string */ void pstrcpy(char *buf, int buf_size, const char *str) { int c; char *q = buf; if (buf_size <= 0) return; for(;;) { c = *str++; if (c == 0 || q >= buf + buf_size - 1) break; *q++ = c; } *q = '\0'; } /* strcat and truncate. */ char *pstrcat(char *buf, int buf_size, const char *s) { int len; len = strlen(buf); if (len < buf_size) pstrcpy(buf + len, buf_size - len, s); return buf; } #endif /* add one element to a dynamic array */ void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem) { int nb, nb_alloc; unsigned long *tab; nb = *nb_ptr; tab = *tab_ptr; if ((nb & (nb - 1)) == 0) { if (nb == 0) nb_alloc = 1; else nb_alloc = nb * 2; tab = av_realloc(tab, nb_alloc * sizeof(unsigned long)); *tab_ptr = tab; } tab[nb++] = elem; *nb_ptr = nb; } time_t mktimegm(struct tm *tm) { time_t t; int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday; if (m < 3) { m += 12; y--; } t = 86400 * (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469); t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; return t; } /* get a positive number between n_min and n_max, for a maximum length of len_max. Return -1 if error. */ static int date_get_num(const char **pp, int n_min, int n_max, int len_max) { int i, val, c; const char *p; p = *pp; val = 0; for(i = 0; i < len_max; i++) { c = *p; if (!isdigit(c)) break; val = (val * 10) + c - '0'; p++; } /* no number read ? */ if (p == *pp) return -1; if (val < n_min || val > n_max) return -1; *pp = p; return val; } /* small strptime for ffmpeg */ const char *small_strptime(const char *p, const char *fmt, struct tm *dt) { int c, val; for(;;) { c = *fmt++; if (c == '\0') { return p; } else if (c == '%') { c = *fmt++; switch(c) { case 'H': val = date_get_num(&p, 0, 23, 2); if (val == -1) return NULL; dt->tm_hour = val; break; case 'M': val = date_get_num(&p, 0, 59, 2); if (val == -1) return NULL; dt->tm_min = val; break; case 'S': val = date_get_num(&p, 0, 59, 2); if (val == -1) return NULL; dt->tm_sec = val; break; case 'Y': val = date_get_num(&p, 0, 9999, 4); if (val == -1) return NULL; dt->tm_year = val - 1900; break; case 'm': val = date_get_num(&p, 1, 12, 2); if (val == -1) return NULL; dt->tm_mon = val - 1; break; case 'd': val = date_get_num(&p, 1, 31, 2); if (val == -1) return NULL; dt->tm_mday = val; break; case '%': goto match; default: return NULL; } } else { match: if (c != *p) return NULL; p++; } } return p; } xmms-wma-1.0.5/ffmpeg-strip-wma/wmadec.c0000644000175000017500000012240610301161060020331 0ustar whistlerwhistler/* * WMA compatible decoder * Copyright (c) 2002 The FFmpeg Project. * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file wmadec.c * WMA compatible decoder. */ #include "avcodec.h" #include "dsputil.h" /* size of blocks */ #define BLOCK_MIN_BITS 7 #define BLOCK_MAX_BITS 11 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS) #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1) /* XXX: find exact max size */ #define HIGH_BAND_MAX_SIZE 16 #define NB_LSP_COEFS 10 /* XXX: is it a suitable value ? */ #define MAX_CODED_SUPERFRAME_SIZE 16384 #define MAX_CHANNELS 2 #define NOISE_TAB_SIZE 8192 #define LSP_POW_BITS 7 typedef struct WMADecodeContext { GetBitContext gb; int sample_rate; int nb_channels; int bit_rate; int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */ int block_align; int use_bit_reservoir; int use_variable_block_len; int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */ int use_noise_coding; /* true if perceptual noise is added */ int byte_offset_bits; VLC exp_vlc; int exponent_sizes[BLOCK_NB_SIZES]; uint16_t exponent_bands[BLOCK_NB_SIZES][25]; int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */ int coefs_start; /* first coded coef */ int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */ int exponent_high_sizes[BLOCK_NB_SIZES]; int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]; VLC hgain_vlc; /* coded values in high bands */ int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]; int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]; /* there are two possible tables for spectral coefficients */ VLC coef_vlc[2]; uint16_t *run_table[2]; uint16_t *level_table[2]; /* frame info */ int frame_len; /* frame length in samples */ int frame_len_bits; /* frame_len = 1 << frame_len_bits */ int nb_block_sizes; /* number of block sizes */ /* block info */ int reset_block_lengths; int block_len_bits; /* log2 of current block length */ int next_block_len_bits; /* log2 of next block length */ int prev_block_len_bits; /* log2 of prev block length */ int block_len; /* block length in samples */ int block_num; /* block number in current frame */ int block_pos; /* current position in frame */ uint8_t ms_stereo; /* true if mid/side stereo mode */ uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */ float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE] __attribute__((aligned(16))); float max_exponent[MAX_CHANNELS]; int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE] __attribute__((aligned(16))); MDCTContext mdct_ctx[BLOCK_NB_SIZES]; float *windows[BLOCK_NB_SIZES]; FFTSample mdct_tmp[BLOCK_MAX_SIZE] __attribute__((aligned(16))); /* temporary storage for imdct */ /* output buffer for one frame and the last for IMDCT windowing */ float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2] __attribute__((aligned(16))); /* last frame info */ uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */ int last_bitoffset; int last_superframe_len; float noise_table[NOISE_TAB_SIZE]; int noise_index; float noise_mult; /* XXX: suppress that and integrate it in the noise array */ /* lsp_to_curve tables */ float lsp_cos_table[BLOCK_MAX_SIZE]; float lsp_pow_e_table[256]; float lsp_pow_m_table1[(1 << LSP_POW_BITS)]; float lsp_pow_m_table2[(1 << LSP_POW_BITS)]; #ifdef TRACE int frame_count; #endif } WMADecodeContext; typedef struct CoefVLCTable { int n; /* total number of codes */ const uint32_t *huffcodes; /* VLC bit values */ const uint8_t *huffbits; /* VLC bit size */ const uint16_t *levels; /* table to build run/level tables */ } CoefVLCTable; static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len); #include "wmadata.h" #ifdef TRACE static void dump_shorts(const char *name, const short *tab, int n) { int i; tprintf("%s[%d]:\n", name, n); for(i=0;in; const uint8_t *table_bits = vlc_table->huffbits; const uint32_t *table_codes = vlc_table->huffcodes; const uint16_t *levels_table = vlc_table->levels; uint16_t *run_table, *level_table; const uint16_t *p; int i, l, j, level; init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4); run_table = av_malloc(n * sizeof(uint16_t)); level_table = av_malloc(n * sizeof(uint16_t)); p = levels_table; i = 2; level = 1; while (i < n) { l = *p++; for(j=0;jpriv_data; int i, flags1, flags2; float *window; uint8_t *extradata; float bps1, high_freq, bps; int sample_rate1; int coef_vlc_table; s->sample_rate = avctx->sample_rate; s->nb_channels = avctx->channels; s->bit_rate = avctx->bit_rate; s->block_align = avctx->block_align; if (avctx->codec->id == CODEC_ID_WMAV1) { s->version = 1; } else { s->version = 2; } /* extract flag infos */ flags1 = 0; flags2 = 0; extradata = avctx->extradata; if (s->version == 1 && avctx->extradata_size >= 4) { flags1 = extradata[0] | (extradata[1] << 8); flags2 = extradata[2] | (extradata[3] << 8); } else if (s->version == 2 && avctx->extradata_size >= 6) { flags1 = extradata[0] | (extradata[1] << 8) | (extradata[2] << 16) | (extradata[3] << 24); flags2 = extradata[4] | (extradata[5] << 8); } s->use_exp_vlc = flags2 & 0x0001; s->use_bit_reservoir = flags2 & 0x0002; s->use_variable_block_len = flags2 & 0x0004; /* compute MDCT block size */ if (s->sample_rate <= 16000) { s->frame_len_bits = 9; } else if (s->sample_rate <= 22050 || (s->sample_rate <= 32000 && s->version == 1)) { s->frame_len_bits = 10; } else { s->frame_len_bits = 11; } s->frame_len = 1 << s->frame_len_bits; if (s->use_variable_block_len) { int nb_max, nb; nb = ((flags2 >> 3) & 3) + 1; if ((s->bit_rate / s->nb_channels) >= 32000) nb += 2; nb_max = s->frame_len_bits - BLOCK_MIN_BITS; if (nb > nb_max) nb = nb_max; s->nb_block_sizes = nb + 1; } else { s->nb_block_sizes = 1; } /* init rate dependant parameters */ s->use_noise_coding = 1; high_freq = s->sample_rate * 0.5; /* if version 2, then the rates are normalized */ sample_rate1 = s->sample_rate; if (s->version == 2) { if (sample_rate1 >= 44100) sample_rate1 = 44100; else if (sample_rate1 >= 22050) sample_rate1 = 22050; else if (sample_rate1 >= 16000) sample_rate1 = 16000; else if (sample_rate1 >= 11025) sample_rate1 = 11025; else if (sample_rate1 >= 8000) sample_rate1 = 8000; } bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate); s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0)) + 2; /* compute high frequency value and choose if noise coding should be activated */ bps1 = bps; if (s->nb_channels == 2) bps1 = bps * 1.6; if (sample_rate1 == 44100) { if (bps1 >= 0.61) s->use_noise_coding = 0; else high_freq = high_freq * 0.4; } else if (sample_rate1 == 22050) { if (bps1 >= 1.16) s->use_noise_coding = 0; else if (bps1 >= 0.72) high_freq = high_freq * 0.7; else high_freq = high_freq * 0.6; } else if (sample_rate1 == 16000) { if (bps > 0.5) high_freq = high_freq * 0.5; else high_freq = high_freq * 0.3; } else if (sample_rate1 == 11025) { high_freq = high_freq * 0.7; } else if (sample_rate1 == 8000) { if (bps <= 0.625) { high_freq = high_freq * 0.5; } else if (bps > 0.75) { s->use_noise_coding = 0; } else { high_freq = high_freq * 0.65; } } else { if (bps >= 0.8) { high_freq = high_freq * 0.75; } else if (bps >= 0.6) { high_freq = high_freq * 0.6; } else { high_freq = high_freq * 0.5; } } dprintf("flags1=0x%x flags2=0x%x\n", flags1, flags2); dprintf("version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n", s->version, s->nb_channels, s->sample_rate, s->bit_rate, s->block_align); dprintf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n", bps, bps1, high_freq, s->byte_offset_bits); dprintf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n", s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes); /* compute the scale factor band sizes for each MDCT block size */ { int a, b, pos, lpos, k, block_len, i, j, n; const uint8_t *table; if (s->version == 1) { s->coefs_start = 3; } else { s->coefs_start = 0; } for(k = 0; k < s->nb_block_sizes; k++) { block_len = s->frame_len >> k; if (s->version == 1) { lpos = 0; for(i=0;i<25;i++) { a = wma_critical_freqs[i]; b = s->sample_rate; pos = ((block_len * 2 * a) + (b >> 1)) / b; if (pos > block_len) pos = block_len; s->exponent_bands[0][i] = pos - lpos; if (pos >= block_len) { i++; break; } lpos = pos; } s->exponent_sizes[0] = i; } else { /* hardcoded tables */ table = NULL; a = s->frame_len_bits - BLOCK_MIN_BITS - k; if (a < 3) { if (s->sample_rate >= 44100) table = exponent_band_44100[a]; else if (s->sample_rate >= 32000) table = exponent_band_32000[a]; else if (s->sample_rate >= 22050) table = exponent_band_22050[a]; } if (table) { n = *table++; for(i=0;iexponent_bands[k][i] = table[i]; s->exponent_sizes[k] = n; } else { j = 0; lpos = 0; for(i=0;i<25;i++) { a = wma_critical_freqs[i]; b = s->sample_rate; pos = ((block_len * 2 * a) + (b << 1)) / (4 * b); pos <<= 2; if (pos > block_len) pos = block_len; if (pos > lpos) s->exponent_bands[k][j++] = pos - lpos; if (pos >= block_len) break; lpos = pos; } s->exponent_sizes[k] = j; } } /* max number of coefs */ s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k; /* high freq computation */ s->high_band_start[k] = (int)((block_len * 2 * high_freq) / s->sample_rate + 0.5); n = s->exponent_sizes[k]; j = 0; pos = 0; for(i=0;iexponent_bands[k][i]; end = pos; if (start < s->high_band_start[k]) start = s->high_band_start[k]; if (end > s->coefs_end[k]) end = s->coefs_end[k]; if (end > start) s->exponent_high_bands[k][j++] = end - start; } s->exponent_high_sizes[k] = j; #if 0 tprintf("%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ", s->frame_len >> k, s->coefs_end[k], s->high_band_start[k], s->exponent_high_sizes[k]); for(j=0;jexponent_high_sizes[k];j++) tprintf(" %d", s->exponent_high_bands[k][j]); tprintf("\n"); #endif } } #ifdef TRACE { int i, j; for(i = 0; i < s->nb_block_sizes; i++) { tprintf("%5d: n=%2d:", s->frame_len >> i, s->exponent_sizes[i]); for(j=0;jexponent_sizes[i];j++) tprintf(" %d", s->exponent_bands[i][j]); tprintf("\n"); } } #endif /* init MDCT */ for(i = 0; i < s->nb_block_sizes; i++) ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1); /* init MDCT windows : simple sinus window */ for(i = 0; i < s->nb_block_sizes; i++) { int n, j; float alpha; n = 1 << (s->frame_len_bits - i); window = av_malloc(sizeof(float) * n); alpha = M_PI / (2.0 * n); for(j=0;jwindows[i] = window; } s->reset_block_lengths = 1; if (s->use_noise_coding) { /* init the noise generator */ if (s->use_exp_vlc) s->noise_mult = 0.02; else s->noise_mult = 0.04; #ifdef TRACE for(i=0;inoise_table[i] = 1.0 * s->noise_mult; #else { unsigned int seed; float norm; seed = 1; norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult; for(i=0;inoise_table[i] = (float)((int)seed) * norm; } } #endif init_vlc(&s->hgain_vlc, 9, sizeof(hgain_huffbits), hgain_huffbits, 1, 1, hgain_huffcodes, 2, 2); } if (s->use_exp_vlc) { init_vlc(&s->exp_vlc, 9, sizeof(scale_huffbits), scale_huffbits, 1, 1, scale_huffcodes, 4, 4); } else { wma_lsp_to_curve_init(s, s->frame_len); } /* choose the VLC tables for the coefficients */ coef_vlc_table = 2; if (s->sample_rate >= 32000) { if (bps1 < 0.72) coef_vlc_table = 0; else if (bps1 < 1.16) coef_vlc_table = 1; } init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &coef_vlcs[coef_vlc_table * 2]); init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &coef_vlcs[coef_vlc_table * 2 + 1]); return 0; } /* interpolate values for a bigger or smaller block. The block must have multiple sizes */ static void interpolate_array(float *scale, int old_size, int new_size) { int i, j, jincr, k; float v; if (new_size > old_size) { jincr = new_size / old_size; j = new_size; for(i = old_size - 1; i >=0; i--) { v = scale[i]; k = jincr; do { scale[--j] = v; } while (--k); } } else if (new_size < old_size) { j = 0; jincr = old_size / new_size; for(i = 0; i < new_size; i++) { scale[i] = scale[j]; j += jincr; } } } /* compute x^-0.25 with an exponent and mantissa table. We use linear interpolation to reduce the mantissa table size at a small speed expense (linear interpolation approximately doubles the number of bits of precision). */ static inline float pow_m1_4(WMADecodeContext *s, float x) { union { float f; unsigned int v; } u, t; unsigned int e, m; float a, b; u.f = x; e = u.v >> 23; m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1); /* build interpolation scale: 1 <= t < 2. */ t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23); a = s->lsp_pow_m_table1[m]; b = s->lsp_pow_m_table2[m]; return s->lsp_pow_e_table[e] * (a + b * t.f); } static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len) { float wdel, a, b; int i, e, m; wdel = M_PI / frame_len; for(i=0;ilsp_cos_table[i] = 2.0f * cos(wdel * i); /* tables for x^-0.25 computation */ for(i=0;i<256;i++) { e = i - 126; s->lsp_pow_e_table[i] = pow(2.0, e * -0.25); } /* NOTE: these two tables are needed to avoid two operations in pow_m1_4 */ b = 1.0; for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--) { m = (1 << LSP_POW_BITS) + i; a = (float)m * (0.5 / (1 << LSP_POW_BITS)); a = pow(a, -0.25); s->lsp_pow_m_table1[i] = 2 * a - b; s->lsp_pow_m_table2[i] = b - a; b = a; } #if 0 for(i=1;i<20;i++) { float v, r1, r2; v = 5.0 / i; r1 = pow_m1_4(s, v); r2 = pow(v,-0.25); printf("%f^-0.25=%f e=%f\n", v, r1, r2 - r1); } #endif } /* NOTE: We use the same code as Vorbis here */ /* XXX: optimize it further with SSE/3Dnow */ static void wma_lsp_to_curve(WMADecodeContext *s, float *out, float *val_max_ptr, int n, float *lsp) { int i, j; float p, q, w, v, val_max; val_max = 0; for(i=0;ilsp_cos_table[i]; for(j=1;j val_max) val_max = v; out[i] = v; } *val_max_ptr = val_max; } /* decode exponents coded with LSP coefficients (same idea as Vorbis) */ static void decode_exp_lsp(WMADecodeContext *s, int ch) { float lsp_coefs[NB_LSP_COEFS]; int val, i; for(i = 0; i < NB_LSP_COEFS; i++) { if (i == 0 || i >= 8) val = get_bits(&s->gb, 3); else val = get_bits(&s->gb, 4); lsp_coefs[i] = lsp_codebook[i][val]; } wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch], s->block_len, lsp_coefs); } /* decode exponents coded with VLC codes */ static int decode_exp_vlc(WMADecodeContext *s, int ch) { int last_exp, n, code; const uint16_t *ptr, *band_ptr; float v, *q, max_scale, *q_end; band_ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits]; ptr = band_ptr; q = s->exponents[ch]; q_end = q + s->block_len; max_scale = 0; if (s->version == 1) { last_exp = get_bits(&s->gb, 5) + 10; /* XXX: use a table */ v = pow(10, last_exp * (1.0 / 16.0)); max_scale = v; n = *ptr++; do { *q++ = v; } while (--n); } last_exp = 36; while (q < q_end) { code = get_vlc(&s->gb, &s->exp_vlc); if (code < 0) return -1; /* NOTE: this offset is the same as MPEG4 AAC ! */ last_exp += code - 60; /* XXX: use a table */ v = pow(10, last_exp * (1.0 / 16.0)); if (v > max_scale) max_scale = v; n = *ptr++; do { *q++ = v; } while (--n); } s->max_exponent[ch] = max_scale; return 0; } /* return 0 if OK. return 1 if last block of frame. return -1 if unrecorrable error. */ static int wma_decode_block(WMADecodeContext *s) { int n, v, a, ch, code, bsize; int coef_nb_bits, total_gain, parse_exponents; float window[BLOCK_MAX_SIZE * 2]; int nb_coefs[MAX_CHANNELS]; float mdct_norm; #ifdef TRACE tprintf("***decode_block: %d:%d\n", s->frame_count - 1, s->block_num); #endif /* compute current block length */ if (s->use_variable_block_len) { n = av_log2(s->nb_block_sizes - 1) + 1; if (s->reset_block_lengths) { s->reset_block_lengths = 0; v = get_bits(&s->gb, n); if (v >= s->nb_block_sizes) return -1; s->prev_block_len_bits = s->frame_len_bits - v; v = get_bits(&s->gb, n); if (v >= s->nb_block_sizes) return -1; s->block_len_bits = s->frame_len_bits - v; } else { /* update block lengths */ s->prev_block_len_bits = s->block_len_bits; s->block_len_bits = s->next_block_len_bits; } v = get_bits(&s->gb, n); if (v >= s->nb_block_sizes) return -1; s->next_block_len_bits = s->frame_len_bits - v; } else { /* fixed block len */ s->next_block_len_bits = s->frame_len_bits; s->prev_block_len_bits = s->frame_len_bits; s->block_len_bits = s->frame_len_bits; } /* now check if the block length is coherent with the frame length */ s->block_len = 1 << s->block_len_bits; if ((s->block_pos + s->block_len) > s->frame_len) return -1; if (s->nb_channels == 2) { s->ms_stereo = get_bits(&s->gb, 1); } v = 0; for(ch = 0; ch < s->nb_channels; ch++) { a = get_bits(&s->gb, 1); s->channel_coded[ch] = a; v |= a; } /* if no channel coded, no need to go further */ /* XXX: fix potential framing problems */ if (!v) goto next; bsize = s->frame_len_bits - s->block_len_bits; /* read total gain and extract corresponding number of bits for coef escape coding */ total_gain = 1; for(;;) { a = get_bits(&s->gb, 7); total_gain += a; if (a != 127) break; } if (total_gain < 15) coef_nb_bits = 13; else if (total_gain < 32) coef_nb_bits = 12; else if (total_gain < 40) coef_nb_bits = 11; else if (total_gain < 45) coef_nb_bits = 10; else coef_nb_bits = 9; /* compute number of coefficients */ n = s->coefs_end[bsize] - s->coefs_start; for(ch = 0; ch < s->nb_channels; ch++) nb_coefs[ch] = n; /* complex coding */ if (s->use_noise_coding) { for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { int i, n, a; n = s->exponent_high_sizes[bsize]; for(i=0;igb, 1); s->high_band_coded[ch][i] = a; /* if noise coding, the coefficients are not transmitted */ if (a) nb_coefs[ch] -= s->exponent_high_bands[bsize][i]; } } } for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { int i, n, val, code; n = s->exponent_high_sizes[bsize]; val = (int)0x80000000; for(i=0;ihigh_band_coded[ch][i]) { if (val == (int)0x80000000) { val = get_bits(&s->gb, 7) - 19; } else { code = get_vlc(&s->gb, &s->hgain_vlc); if (code < 0) return -1; val += code - 18; } s->high_band_values[ch][i] = val; } } } } } /* exposant can be interpolated in short blocks. */ parse_exponents = 1; if (s->block_len_bits != s->frame_len_bits) { parse_exponents = get_bits(&s->gb, 1); } if (parse_exponents) { for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { if (s->use_exp_vlc) { if (decode_exp_vlc(s, ch) < 0) return -1; } else { decode_exp_lsp(s, ch); } } } } else { for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { interpolate_array(s->exponents[ch], 1 << s->prev_block_len_bits, s->block_len); } } } /* parse spectral coefficients : just RLE encoding */ for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { VLC *coef_vlc; int level, run, sign, tindex; int16_t *ptr, *eptr; const uint16_t *level_table, *run_table; /* special VLC tables are used for ms stereo because there is potentially less energy there */ tindex = (ch == 1 && s->ms_stereo); coef_vlc = &s->coef_vlc[tindex]; run_table = s->run_table[tindex]; level_table = s->level_table[tindex]; /* XXX: optimize */ ptr = &s->coefs1[ch][0]; eptr = ptr + nb_coefs[ch]; memset(ptr, 0, s->block_len * sizeof(int16_t)); for(;;) { code = get_vlc(&s->gb, coef_vlc); if (code < 0) return -1; if (code == 1) { /* EOB */ break; } else if (code == 0) { /* escape */ level = get_bits(&s->gb, coef_nb_bits); /* NOTE: this is rather suboptimal. reading block_len_bits would be better */ run = get_bits(&s->gb, s->frame_len_bits); } else { /* normal code */ run = run_table[code]; level = level_table[code]; } sign = get_bits(&s->gb, 1); if (!sign) level = -level; ptr += run; if (ptr >= eptr) return -1; *ptr++ = level; /* NOTE: EOB can be omitted */ if (ptr >= eptr) break; } } if (s->version == 1 && s->nb_channels >= 2) { align_get_bits(&s->gb); } } /* normalize */ { int n4 = s->block_len / 2; mdct_norm = 1.0 / (float)n4; if (s->version == 1) { mdct_norm *= sqrt(n4); } } /* finally compute the MDCT coefficients */ for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { int16_t *coefs1; float *coefs, *exponents, mult, mult1, noise, *exp_ptr; int i, j, n, n1, last_high_band; float exp_power[HIGH_BAND_MAX_SIZE]; coefs1 = s->coefs1[ch]; exponents = s->exponents[ch]; mult = pow(10, total_gain * 0.05) / s->max_exponent[ch]; mult *= mdct_norm; coefs = s->coefs[ch]; if (s->use_noise_coding) { mult1 = mult; /* very low freqs : noise */ for(i = 0;i < s->coefs_start; i++) { *coefs++ = s->noise_table[s->noise_index] * (*exponents++) * mult1; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); } n1 = s->exponent_high_sizes[bsize]; /* compute power of high bands */ exp_ptr = exponents + s->high_band_start[bsize] - s->coefs_start; last_high_band = 0; /* avoid warning */ for(j=0;jexponent_high_bands[s->frame_len_bits - s->block_len_bits][j]; if (s->high_band_coded[ch][j]) { float e2, v; e2 = 0; for(i = 0;i < n; i++) { v = exp_ptr[i]; e2 += v * v; } exp_power[j] = e2 / n; last_high_band = j; tprintf("%d: power=%f (%d)\n", j, exp_power[j], n); } exp_ptr += n; } /* main freqs and high freqs */ for(j=-1;jhigh_band_start[bsize] - s->coefs_start; } else { n = s->exponent_high_bands[s->frame_len_bits - s->block_len_bits][j]; } if (j >= 0 && s->high_band_coded[ch][j]) { /* use noise with specified power */ mult1 = sqrt(exp_power[j] / exp_power[last_high_band]); /* XXX: use a table */ mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05); mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult); mult1 *= mdct_norm; for(i = 0;i < n; i++) { noise = s->noise_table[s->noise_index]; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); *coefs++ = (*exponents++) * noise * mult1; } } else { /* coded values + small noise */ for(i = 0;i < n; i++) { noise = s->noise_table[s->noise_index]; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); *coefs++ = ((*coefs1++) + noise) * (*exponents++) * mult; } } } /* very high freqs : noise */ n = s->block_len - s->coefs_end[bsize]; mult1 = mult * exponents[-1]; for(i = 0; i < n; i++) { *coefs++ = s->noise_table[s->noise_index] * mult1; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); } } else { /* XXX: optimize more */ for(i = 0;i < s->coefs_start; i++) *coefs++ = 0.0; n = nb_coefs[ch]; for(i = 0;i < n; i++) { *coefs++ = coefs1[i] * exponents[i] * mult; } n = s->block_len - s->coefs_end[bsize]; for(i = 0;i < n; i++) *coefs++ = 0.0; } } } #ifdef TRACE for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { dump_floats("exponents", 3, s->exponents[ch], s->block_len); dump_floats("coefs", 1, s->coefs[ch], s->block_len); } } #endif if (s->ms_stereo && s->channel_coded[1]) { float a, b; int i; /* nominal case for ms stereo: we do it before mdct */ /* no need to optimize this case because it should almost never happen */ if (!s->channel_coded[0]) { tprintf("rare ms-stereo case happened\n"); memset(s->coefs[0], 0, sizeof(float) * s->block_len); s->channel_coded[0] = 1; } for(i = 0; i < s->block_len; i++) { a = s->coefs[0][i]; b = s->coefs[1][i]; s->coefs[0][i] = a + b; s->coefs[1][i] = a - b; } } /* build the window : we ensure that when the windows overlap their squared sum is always 1 (MDCT reconstruction rule) */ /* XXX: merge with output */ { int i, next_block_len, block_len, prev_block_len, n; float *wptr; block_len = s->block_len; prev_block_len = 1 << s->prev_block_len_bits; next_block_len = 1 << s->next_block_len_bits; /* right part */ wptr = window + block_len; if (block_len <= next_block_len) { for(i=0;iwindows[bsize][i]; } else { /* overlap */ n = (block_len / 2) - (next_block_len / 2); for(i=0;iwindows[s->frame_len_bits - s->next_block_len_bits][i]; for(i=0;iwindows[bsize][i]; } else { /* overlap */ n = (block_len / 2) - (prev_block_len / 2); for(i=0;iwindows[s->frame_len_bits - s->prev_block_len_bits][i]; for(i=0;inb_channels; ch++) { if (s->channel_coded[ch]) { FFTSample output[BLOCK_MAX_SIZE * 2] __attribute__((aligned(16))); float *ptr; int i, n4, index, n; n = s->block_len; n4 = s->block_len / 2; ff_imdct_calc(&s->mdct_ctx[bsize], output, s->coefs[ch], s->mdct_tmp); /* XXX: optimize all that by build the window and multipying/adding at the same time */ /* multiply by the window */ for(i=0;iframe_len / 2) + s->block_pos - n4; ptr = &s->frame_out[ch][index]; for(i=0;ims_stereo && !s->channel_coded[1]) { ptr = &s->frame_out[1][index]; for(i=0;iblock_num++; s->block_pos += s->block_len; if (s->block_pos >= s->frame_len) return 1; else return 0; } /* decode a frame of frame_len samples */ static int wma_decode_frame(WMADecodeContext *s, int16_t *samples) { int ret, i, n, a, ch, incr; int16_t *ptr; float *iptr; #ifdef TRACE tprintf("***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len); #endif /* read each block */ s->block_num = 0; s->block_pos = 0; for(;;) { ret = wma_decode_block(s); if (ret < 0) return -1; if (ret) break; } /* convert frame to integer */ n = s->frame_len; incr = s->nb_channels; for(ch = 0; ch < s->nb_channels; ch++) { ptr = samples + ch; iptr = s->frame_out[ch]; for(i=0;i 32767) a = 32767; else if (a < -32768) a = -32768; *ptr = a; ptr += incr; } /* prepare for next block */ memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len], s->frame_len * sizeof(float)); /* XXX: suppress this */ memset(&s->frame_out[ch][s->frame_len], 0, s->frame_len * sizeof(float)); } #ifdef TRACE dump_shorts("samples", samples, n * s->nb_channels); #endif return 0; } static int wma_decode_superframe(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { WMADecodeContext *s = avctx->priv_data; int nb_frames, bit_offset, i, pos, len; uint8_t *q; int16_t *samples; tprintf("***decode_superframe:\n"); if(buf_size==0){ s->last_superframe_len = 0; return 0; } samples = data; init_get_bits(&s->gb, buf, buf_size*8); if (s->use_bit_reservoir) { /* read super frame header */ get_bits(&s->gb, 4); /* super frame index */ nb_frames = get_bits(&s->gb, 4) - 1; bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3); if (s->last_superframe_len > 0) { // printf("skip=%d\n", s->last_bitoffset); /* add bit_offset bits to last frame */ if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) > MAX_CODED_SUPERFRAME_SIZE) goto fail; q = s->last_superframe + s->last_superframe_len; len = bit_offset; while (len > 0) { *q++ = (get_bits)(&s->gb, 8); len -= 8; } if (len > 0) { *q++ = (get_bits)(&s->gb, len) << (8 - len); } /* XXX: bit_offset bits into last frame */ init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8); /* skip unused bits */ if (s->last_bitoffset > 0) skip_bits(&s->gb, s->last_bitoffset); /* this frame is stored in the last superframe and in the current one */ if (wma_decode_frame(s, samples) < 0) goto fail; samples += s->nb_channels * s->frame_len; } /* read each frame starting from bit_offset */ pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3; init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8); len = pos & 7; if (len > 0) skip_bits(&s->gb, len); s->reset_block_lengths = 1; for(i=0;inb_channels * s->frame_len; } /* we copy the end of the frame in the last frame buffer */ pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7); s->last_bitoffset = pos & 7; pos >>= 3; len = buf_size - pos; if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) { goto fail; } s->last_superframe_len = len; memcpy(s->last_superframe, buf + pos, len); } else { /* single frame decode */ if (wma_decode_frame(s, samples) < 0) goto fail; samples += s->nb_channels * s->frame_len; } *data_size = (int8_t *)samples - (int8_t *)data; return s->block_align; fail: /* when error, we reset the bit reservoir */ s->last_superframe_len = 0; return -1; } static int wma_decode_end(AVCodecContext *avctx) { WMADecodeContext *s = avctx->priv_data; int i; for(i = 0; i < s->nb_block_sizes; i++) ff_mdct_end(&s->mdct_ctx[i]); for(i = 0; i < s->nb_block_sizes; i++) av_free(s->windows[i]); if (s->use_exp_vlc) { free_vlc(&s->exp_vlc); } if (s->use_noise_coding) { free_vlc(&s->hgain_vlc); } for(i = 0;i < 2; i++) { free_vlc(&s->coef_vlc[i]); av_free(s->run_table[i]); av_free(s->level_table[i]); } return 0; } AVCodec wmav1_decoder = { "wmav1", CODEC_TYPE_AUDIO, CODEC_ID_WMAV1, sizeof(WMADecodeContext), wma_decode_init, NULL, wma_decode_end, wma_decode_superframe, }; AVCodec wmav2_decoder = { "wmav2", CODEC_TYPE_AUDIO, CODEC_ID_WMAV2, sizeof(WMADecodeContext), wma_decode_init, NULL, wma_decode_end, wma_decode_superframe, }; xmms-wma-1.0.5/ffmpeg-strip-wma/simple_idct.h0000644000175000017500000000265607631630664021425 0ustar whistlerwhistler/* * Simple IDCT * * Copyright (c) 2001 Michael Niedermayer * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file simple_idct.h * simple idct header. */ void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block); void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block); void ff_simple_idct_mmx(int16_t *block); void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block); void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block); void simple_idct(DCTELEM *block); void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block); void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block); void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block); xmms-wma-1.0.5/ffmpeg-strip-wma/allcodecs.c0000644000175000017500000000243710014711406021031 0ustar whistlerwhistler/* * Utils for libavcodec * Copyright (c) 2002 Fabrice Bellard. * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * @file allcodecs.c * Utils for libavcodec. */ #include "avcodec.h" /* If you do not call this function, then you can select exactly which formats you want to support */ /** * simple call to register all the codecs. */ void avcodec_register_all(void) { static int inited = 0; if (inited != 0) return; inited = 1; /* decoders */ #ifdef CONFIG_DECODERS #ifdef CONFIG_RISKY register_avcodec(&wmav1_decoder); register_avcodec(&wmav2_decoder); #endif #endif } xmms-wma-1.0.5/ffmpeg-strip-wma/Makefile0000644000175000017500000000307710016246612020401 0ustar whistlerwhistler# # libavcodec Makefile # (c) 2000-2003 Fabrice Bellard # (c) 2004 McMCC # include config.mak # NOTE: -I.. is needed to include config.h CFLAGS=$(OPTFLAGS) -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE OBJS= common.o utils.o mem.o allcodecs.o futils.o cutils.o os_support.o allformats.o parser.o \ avio.o aviobuf.o file.o simple_idct.o dsputil.o fft.o mdct.o asf.o # codecs which are patented in some non free countries like the us ifeq ($(CONFIG_RISKY),yes) OBJS+= wmadec.o endif ifeq ($(TARGET_GPROF),yes) CFLAGS+=-p LDFLAGS+=-p endif SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) OBJS := $(OBJS) $(ASM_OBJS) LIB= $(LIBPREF)ffwma$(LIBSUF) ifeq ($(BUILD_SHARED),yes) SLIB= $(SLIBPREF)ffwma$(SLIBSUF) endif all: $(LIB) $(SLIB) $(LIB): $(OBJS) rm -f $@ $(AR) rc $@ $(OBJS) $(RANLIB) $@ $(SLIB): $(OBJS) $(CC) $(SHFLAGS) -o $@ $(OBJS) $(EXTRALIBS) dsputil.o: dsputil.c dsputil.h %.o: %.c $(CC) $(CFLAGS) -c -o $@ $< %.o: %.S $(CC) $(CFLAGS) -c -o $@ $< depend: $(SRCS) $(CC) -MM $(CFLAGS) $^ 1>.depend dep: depend clean: rm -f *.o *.d *~ .depend $(LIB) $(SLIB) *.so distclean: clean rm -f Makefile.bak .depend ifeq ($(BUILD_SHARED),yes) install: all install-headers install -d $(prefix)/lib install -s -m 755 $(SLIB) $(prefix)/lib/libffwma-$(VERSION).so ln -sf libffwma-$(VERSION).so $(prefix)/lib/libffwma.so ldconfig || true else install: endif installlib: all install-headers install -m 644 $(LIB) $(prefix)/lib install-headers: mkdir -p "$(prefix)/include/ffwma" install -m 644 *.h "$(prefix)/include/ffwma" xmms-wma-1.0.5/ffmpeg-strip-wma/bswap.h0000644000175000017500000000512707710226544020235 0ustar whistlerwhistler/** * @file bswap.h * byte swap. */ #ifndef __BSWAP_H__ #define __BSWAP_H__ #ifdef HAVE_BYTESWAP_H #include #else #ifdef ARCH_X86 static inline unsigned short ByteSwap16(unsigned short x) { __asm("xchgb %b0,%h0" : "=q" (x) : "0" (x)); return x; } #define bswap_16(x) ByteSwap16(x) static inline unsigned int ByteSwap32(unsigned int x) { #if __CPU__ > 386 __asm("bswap %0": "=r" (x) : #else __asm("xchgb %b0,%h0\n" " rorl $16,%0\n" " xchgb %b0,%h0": "=q" (x) : #endif "0" (x)); return x; } #define bswap_32(x) ByteSwap32(x) static inline unsigned long long int ByteSwap64(unsigned long long int x) { register union { __extension__ uint64_t __ll; uint32_t __l[2]; } __x; asm("xchgl %0,%1": "=r"(__x.__l[0]),"=r"(__x.__l[1]): "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); return __x.__ll; } #define bswap_64(x) ByteSwap64(x) #elif defined(ARCH_SH4) static inline uint16_t ByteSwap16(uint16_t x) { __asm__("swap.b %0,%0":"=r"(x):"0"(x)); return x; } static inline uint32_t ByteSwap32(uint32_t x) { __asm__( "swap.b %0,%0\n" "swap.w %0,%0\n" "swap.b %0,%0\n" :"=r"(x):"0"(x)); return x; } #define bswap_16(x) ByteSwap16(x) #define bswap_32(x) ByteSwap32(x) static inline uint64_t ByteSwap64(uint64_t x) { union { uint64_t ll; struct { uint32_t l,h; } l; } r; r.l.l = bswap_32 (x); r.l.h = bswap_32 (x>>32); return r.ll; } #define bswap_64(x) ByteSwap64(x) #else #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. #define bswap_32(x) \ ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) static inline uint64_t ByteSwap64(uint64_t x) { union { uint64_t ll; uint32_t l[2]; } w, r; w.ll = x; r.l[0] = bswap_32 (w.l[1]); r.l[1] = bswap_32 (w.l[0]); return r.ll; } #define bswap_64(x) ByteSwap64(x) #endif /* !ARCH_X86 */ #endif /* !HAVE_BYTESWAP_H */ // be2me ... BigEndian to MachineEndian // le2me ... LittleEndian to MachineEndian #ifdef WORDS_BIGENDIAN #define be2me_16(x) (x) #define be2me_32(x) (x) #define be2me_64(x) (x) #define le2me_16(x) bswap_16(x) #define le2me_32(x) bswap_32(x) #define le2me_64(x) bswap_64(x) #else #define be2me_16(x) bswap_16(x) #define be2me_32(x) bswap_32(x) #define be2me_64(x) bswap_64(x) #define le2me_16(x) (x) #define le2me_32(x) (x) #define le2me_64(x) (x) #endif #endif /* __BSWAP_H__ */ xmms-wma-1.0.5/ffmpeg-strip-wma/avformat.h0000644000175000017500000004673310015251455020737 0ustar whistlerwhistler#ifndef AVFORMAT_H #define AVFORMAT_H #ifdef __cplusplus extern "C" { #endif #define LIBAVFORMAT_BUILD 4611 #define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT #define LIBAVFORMAT_VERSION FFMPEG_VERSION #define LIBAVFORMAT_IDENT "FFmpeg" FFMPEG_VERSION "b" AV_STRINGIFY(LIBAVFORMAT_BUILD) #include #include /* FILE */ #include "avcodec.h" #include "avio.h" /* packet functions */ #ifndef MAXINT64 #define MAXINT64 int64_t_C(0x7fffffffffffffff) #endif #ifndef MININT64 #define MININT64 int64_t_C(0x8000000000000000) #endif #define AV_NOPTS_VALUE MININT64 #define AV_TIME_BASE 1000000 typedef struct AVPacket { int64_t pts; /* presentation time stamp in AV_TIME_BASE units (or pts_den units in muxers or demuxers) */ int64_t dts; /* decompression time stamp in AV_TIME_BASE units (or pts_den units in muxers or demuxers) */ uint8_t *data; int size; int stream_index; int flags; int duration; /* presentation duration (0 if not available) */ void (*destruct)(struct AVPacket *); void *priv; } AVPacket; #define PKT_FLAG_KEY 0x0001 /* initialize optional fields of a packet */ static inline void av_init_packet(AVPacket *pkt) { pkt->pts = AV_NOPTS_VALUE; pkt->dts = AV_NOPTS_VALUE; pkt->duration = 0; pkt->flags = 0; pkt->stream_index = 0; } int av_new_packet(AVPacket *pkt, int size); int av_dup_packet(AVPacket *pkt); /** * Free a packet * * @param pkt packet to free */ static inline void av_free_packet(AVPacket *pkt) { if (pkt && pkt->destruct) { pkt->destruct(pkt); } } /*************************************************/ /* fractional numbers for exact pts handling */ /* the exact value of the fractional number is: 'val + num / den'. num is assumed to be such as 0 <= num < den */ typedef struct AVFrac { int64_t val, num, den; } AVFrac; void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den); void av_frac_add(AVFrac *f, int64_t incr); void av_frac_set(AVFrac *f, int64_t val); /*************************************************/ /* input/output formats */ struct AVFormatContext; /* this structure contains the data a format has to probe a file */ typedef struct AVProbeData { const char *filename; unsigned char *buf; int buf_size; } AVProbeData; #define AVPROBE_SCORE_MAX 100 typedef struct AVFormatParameters { int frame_rate; int frame_rate_base; int sample_rate; int channels; int width; int height; enum PixelFormat pix_fmt; struct AVImageFormat *image_format; int channel; /* used to select dv channel */ const char *device; /* video4linux, audio or DV device */ const char *standard; /* tv standard, NTSC, PAL, SECAM */ int mpeg2ts_raw:1; /* force raw MPEG2 transport stream output, if possible */ int mpeg2ts_compute_pcr:1; /* compute exact PCR for each transport stream packet (only meaningful if mpeg2ts_raw is TRUE */ int initial_pause:1; /* do not begin to play the stream immediately (RTSP only) */ } AVFormatParameters; #define AVFMT_NOFILE 0x0001 /* no file should be opened */ #define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */ #define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */ #define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for raw picture data */ typedef struct AVOutputFormat { const char *name; const char *long_name; const char *mime_type; const char *extensions; /* comma separated extensions */ /* size of private data so that it can be allocated in the wrapper */ int priv_data_size; /* output support */ enum CodecID audio_codec; /* default audio codec */ enum CodecID video_codec; /* default video codec */ int (*write_header)(struct AVFormatContext *); int (*write_packet)(struct AVFormatContext *, int stream_index, const uint8_t *buf, int size, int64_t pts); int (*write_trailer)(struct AVFormatContext *); /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */ int flags; /* currently only used to set pixel format if not YUV420P */ int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *); /* private fields */ struct AVOutputFormat *next; } AVOutputFormat; typedef struct AVInputFormat { const char *name; const char *long_name; /* size of private data so that it can be allocated in the wrapper */ int priv_data_size; /* tell if a given file has a chance of being parsing by this format */ int (*read_probe)(AVProbeData *); /* read the format header and initialize the AVFormatContext structure. Return 0 if OK. 'ap' if non NULL contains additionnal paramters. Only used in raw format right now. 'av_new_stream' should be called to create new streams. */ int (*read_header)(struct AVFormatContext *, AVFormatParameters *ap); /* read one packet and put it in 'pkt'. pts and flags are also set. 'av_new_stream' can be called only if the flag AVFMTCTX_NOHEADER is used. */ int (*read_packet)(struct AVFormatContext *, AVPacket *pkt); /* close the stream. The AVFormatContext and AVStreams are not freed by this function */ int (*read_close)(struct AVFormatContext *); /* seek at or before a given timestamp (given in AV_TIME_BASE units) relative to the frames in stream component stream_index */ int (*read_seek)(struct AVFormatContext *, int stream_index, int64_t timestamp); /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */ int flags; /* if extensions are defined, then no probe is done. You should usually not use extension format guessing because it is not reliable enough */ const char *extensions; /* general purpose read only value that the format can use */ int value; /* start/resume playing - only meaningful if using a network based format (RTSP) */ int (*read_play)(struct AVFormatContext *); /* pause playing - only meaningful if using a network based format (RTSP) */ int (*read_pause)(struct AVFormatContext *); /* private fields */ struct AVInputFormat *next; } AVInputFormat; typedef struct AVIndexEntry { int64_t pos; int64_t timestamp; #define AVINDEX_KEYFRAME 0x0001 /* the following 2 flags indicate that the next/prev keyframe is known, and scaning for it isnt needed */ int flags; int min_distance; /* min distance between this and the previous keyframe, used to avoid unneeded searching */ } AVIndexEntry; typedef struct AVStream { int index; /* stream index in AVFormatContext */ int id; /* format specific stream id */ AVCodecContext codec; /* codec context */ int r_frame_rate; /* real frame rate of the stream */ int r_frame_rate_base;/* real frame rate base of the stream */ void *priv_data; /* internal data used in av_find_stream_info() */ int64_t codec_info_duration; int codec_info_nb_frames; /* encoding: PTS generation when outputing stream */ AVFrac pts; /* ffmpeg.c private use */ int stream_copy; /* if TRUE, just copy stream */ /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame * MN:dunno if thats the right place, for it */ float quality; /* decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds. */ int64_t start_time; /* decoding: duration of the stream, in AV_TIME_BASE fractional seconds. */ int64_t duration; /* av_read_frame() support */ int need_parsing; struct AVCodecParserContext *parser; int64_t cur_dts; int last_IP_duration; /* av_seek_frame() support */ AVIndexEntry *index_entries; /* only used if the format does not support seeking natively */ int nb_index_entries; int index_entries_allocated_size; } AVStream; #define AVFMTCTX_NOHEADER 0x0001 /* signal that no header is present (streams are added dynamically) */ #define MAX_STREAMS 20 /* format I/O context */ typedef struct AVFormatContext { /* can only be iformat or oformat, not both at the same time */ struct AVInputFormat *iformat; struct AVOutputFormat *oformat; void *priv_data; ByteIOContext pb; int nb_streams; AVStream *streams[MAX_STREAMS]; char filename[1024]; /* input or output filename */ /* stream info */ char title[512]; char author[512]; char copyright[512]; char comment[512]; char album[512]; int year; /* ID3 year, 0 if none */ int track; /* track number, 0 if none */ char genre[32]; /* ID3 genre */ int ctx_flags; /* format specific flags, see AVFMTCTX_xx */ /* private data for pts handling (do not modify directly) */ int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */ int pts_num, pts_den; /* value to convert to seconds */ /* This buffer is only needed when packets were already buffered but not decoded, for example to get the codec parameters in mpeg streams */ struct AVPacketList *packet_buffer; /* decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds. NEVER set this value directly: it is deduced from the AVStream values. */ int64_t start_time; /* decoding: duration of the stream, in AV_TIME_BASE fractional seconds. NEVER set this value directly: it is deduced from the AVStream values. */ int64_t duration; /* decoding: total file size. 0 if unknown */ int64_t file_size; /* decoding: total stream bitrate in bit/s, 0 if not available. Never set it directly if the file_size and the duration are known as ffmpeg can compute it automatically. */ int bit_rate; /* av_read_frame() support */ AVStream *cur_st; const uint8_t *cur_ptr; int cur_len; AVPacket cur_pkt; /* the following are used for pts/dts unit conversion */ int64_t last_pkt_stream_pts; int64_t last_pkt_stream_dts; int64_t last_pkt_pts; int64_t last_pkt_dts; int last_pkt_pts_frac; int last_pkt_dts_frac; /* av_seek_frame() support */ int64_t data_offset; /* offset of the first packet */ int index_built; } AVFormatContext; typedef struct AVPacketList { AVPacket pkt; struct AVPacketList *next; } AVPacketList; extern AVInputFormat *first_iformat; extern AVOutputFormat *first_oformat; /* still image support */ struct AVInputImageContext; typedef struct AVInputImageContext AVInputImageContext; typedef struct AVImageInfo { enum PixelFormat pix_fmt; /* requested pixel format */ int width; /* requested width */ int height; /* requested height */ int interleaved; /* image is interleaved (e.g. interleaved GIF) */ AVPicture pict; /* returned allocated image */ } AVImageInfo; /* AVImageFormat.flags field constants */ #define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */ typedef struct AVImageFormat { const char *name; const char *extensions; /* tell if a given file has a chance of being parsing by this format */ int (*img_probe)(AVProbeData *); /* read a whole image. 'alloc_cb' is called when the image size is known so that the caller can allocate the image. If 'allo_cb' returns non zero, then the parsing is aborted. Return '0' if OK. */ int (*img_read)(ByteIOContext *, int (*alloc_cb)(void *, AVImageInfo *info), void *); /* write the image */ int supported_pixel_formats; /* mask of supported formats for output */ int (*img_write)(ByteIOContext *, AVImageInfo *); int flags; struct AVImageFormat *next; } AVImageFormat; void av_register_image_format(AVImageFormat *img_fmt); AVImageFormat *av_probe_image_format(AVProbeData *pd); AVImageFormat *guess_image_format(const char *filename); int av_read_image(ByteIOContext *pb, const char *filename, AVImageFormat *fmt, int (*alloc_cb)(void *, AVImageInfo *info), void *opaque); int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img); extern AVImageFormat *first_image_format; extern AVImageFormat pnm_image_format; extern AVImageFormat pbm_image_format; extern AVImageFormat pgm_image_format; extern AVImageFormat ppm_image_format; extern AVImageFormat pam_image_format; extern AVImageFormat pgmyuv_image_format; extern AVImageFormat yuv_image_format; #ifdef CONFIG_ZLIB extern AVImageFormat png_image_format; #endif extern AVImageFormat jpeg_image_format; extern AVImageFormat gif_image_format; /* XXX: use automatic init with either ELF sections or C file parser */ /* modules */ /* mpeg.c */ extern AVInputFormat mpegps_demux; int mpegps_init(void); /* mpegts.c */ extern AVInputFormat mpegts_demux; int mpegts_init(void); /* rm.c */ int rm_init(void); /* crc.c */ int crc_init(void); /* img.c */ int img_init(void); /* asf.c */ int asf_init(void); /* avienc.c */ int avienc_init(void); /* avidec.c */ int avidec_init(void); /* swf.c */ int swf_init(void); /* mov.c */ int mov_init(void); /* movenc.c */ int movenc_init(void); /* flvenc.c */ int flvenc_init(void); /* flvdec.c */ int flvdec_init(void); /* jpeg.c */ int jpeg_init(void); /* gif.c */ int gif_init(void); /* au.c */ int au_init(void); /* amr.c */ int amr_init(void); /* wav.c */ int wav_init(void); /* raw.c */ int pcm_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp); int raw_init(void); /* mp3.c */ int mp3_init(void); /* yuv4mpeg.c */ int yuv4mpeg_init(void); /* ogg.c */ int ogg_init(void); /* dv.c */ int dv_init(void); /* ffm.c */ int ffm_init(void); /* rtsp.c */ extern AVInputFormat redir_demux; int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f); /* 4xm.c */ int fourxm_init(void); /* psxstr.c */ int str_init(void); /* idroq.c */ int roq_init(void); /* ipmovie.c */ int ipmovie_init(void); /* nut.c */ int nut_init(void); /* wc3movie.c */ int wc3_init(void); /* westwood.c */ int westwood_init(void); /* segafilm.c */ int film_init(void); /* idcin.c */ int idcin_init(void); /* flic.c */ int flic_init(void); /* sierravmd.c */ int vmd_init(void); //#include "rtp.h" //#include "rtsp.h" /* yuv4mpeg.c */ extern AVOutputFormat yuv4mpegpipe_oformat; /* utils.c */ void av_register_input_format(AVInputFormat *format); void av_register_output_format(AVOutputFormat *format); AVOutputFormat *guess_stream_format(const char *short_name, const char *filename, const char *mime_type); AVOutputFormat *guess_format(const char *short_name, const char *filename, const char *mime_type); void av_hex_dump(FILE *f, uint8_t *buf, int size); void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload); void av_register_all(void); typedef struct FifoBuffer { uint8_t *buffer; uint8_t *rptr, *wptr, *end; } FifoBuffer; int fifo_init(FifoBuffer *f, int size); void fifo_free(FifoBuffer *f); int fifo_size(FifoBuffer *f, uint8_t *rptr); int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr); void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr); /* media file input */ AVInputFormat *av_find_input_format(const char *short_name); AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened); int av_open_input_stream(AVFormatContext **ic_ptr, ByteIOContext *pb, const char *filename, AVInputFormat *fmt, AVFormatParameters *ap); int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap); #define AVERROR_UNKNOWN (-1) /* unknown error */ #define AVERROR_IO (-2) /* i/o error */ #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */ #define AVERROR_INVALIDDATA (-4) /* invalid data found */ #define AVERROR_NOMEM (-5) /* not enough memory */ #define AVERROR_NOFMT (-6) /* unknown format */ #define AVERROR_NOTSUPP (-7) /* operation not supported */ int av_find_stream_info(AVFormatContext *ic); int av_read_packet(AVFormatContext *s, AVPacket *pkt); int av_read_frame(AVFormatContext *s, AVPacket *pkt); int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp); int av_read_play(AVFormatContext *s); int av_read_pause(AVFormatContext *s); void av_close_input_file(AVFormatContext *s); AVStream *av_new_stream(AVFormatContext *s, int id); void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits, int pts_num, int pts_den); int av_find_default_stream_index(AVFormatContext *s); int av_index_search_timestamp(AVStream *st, int timestamp); int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int distance, int flags); /* media file output */ int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap); int av_write_header(AVFormatContext *s); int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf, int size); int av_write_trailer(AVFormatContext *s); void dump_format(AVFormatContext *ic, int index, const char *url, int is_output); int parse_image_size(int *width_ptr, int *height_ptr, const char *str); int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg); int64_t parse_date(const char *datestr, int duration); int64_t av_gettime(void); /* ffm specific for ffserver */ #define FFM_PACKET_SIZE 4096 offset_t ffm_read_write_index(int fd); void ffm_write_write_index(int fd, offset_t pos); void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size); int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); int get_frame_filename(char *buf, int buf_size, const char *path, int number); int filename_number_test(const char *filename); /* grab specific */ int video_grab_init(void); int audio_init(void); /* DV1394 */ int dv1394_init(void); #ifdef HAVE_AV_CONFIG_H #include "os_support.h" int strstart(const char *str, const char *val, const char **ptr); int stristart(const char *str, const char *val, const char **ptr); void pstrcpy(char *buf, int buf_size, const char *str); char *pstrcat(char *buf, int buf_size, const char *s); void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem); #ifdef __GNUC__ #define dynarray_add(tab, nb_ptr, elem)\ do {\ typeof(tab) _tab = (tab);\ typeof(elem) _elem = (elem);\ (void)sizeof(**_tab == _elem); /* check that types are compatible */\ __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\ } while(0) #else #define dynarray_add(tab, nb_ptr, elem)\ do {\ __dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\ } while(0) #endif time_t mktimegm(struct tm *tm); const char *small_strptime(const char *p, const char *fmt, struct tm *dt); struct in_addr; int resolve_host(struct in_addr *sin_addr, const char *hostname); void url_split(char *proto, int proto_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url); int match_ext(const char *filename, const char *extensions); #endif /* HAVE_AV_CONFIG_H */ #ifdef __cplusplus } #endif #endif /* AVFORMAT_H */ xmms-wma-1.0.5/ffmpeg-strip-wma/asf.c0000644000175000017500000014673010301156626017664 0ustar whistlerwhistler/* * ASF compatible encoder and decoder. * Copyright (c) 2000, 2001 Fabrice Bellard. * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avformat.h" #include "avi.h" //#include "mpegaudio.h" #include #undef NDEBUG #include #define MPA_FRAME_SIZE 1152 #define PACKET_SIZE 3200 #define PACKET_HEADER_SIZE 12 #define FRAME_HEADER_SIZE 17 typedef struct { int num; int seq; /* use for reading */ AVPacket pkt; int frag_offset; int timestamp; int64_t duration; int ds_span; /* descrambling */ int ds_packet_size; int ds_chunk_size; int ds_data_size; int ds_silence_data; int packet_pos; } ASFStream; typedef struct { uint32_t v1; uint16_t v2; uint16_t v3; uint8_t v4[8]; } GUID; typedef struct { GUID guid; // generated by client computer uint64_t file_size; // in bytes // invalid if broadcasting uint64_t create_time; // time of creation, in 100-nanosecond units since 1.1.1601 // invalid if broadcasting uint64_t packets_count; // how many packets are there in the file // invalid if broadcasting uint64_t play_time; // play time, in 100-nanosecond units // invalid if broadcasting uint64_t send_time; // time to send file, in 100-nanosecond units // invalid if broadcasting (could be ignored) uint32_t preroll; // timestamp of the first packet, in milliseconds // if nonzero - substract from time uint32_t ignore; // preroll is 64bit - but let's just ignore it uint32_t flags; // 0x01 - broadcast // 0x02 - seekable // rest is reserved should be 0 uint32_t min_pktsize; // size of a data packet // invalid if broadcasting uint32_t max_pktsize; // shall be the same as for min_pktsize // invalid if broadcasting uint32_t max_bitrate; // bandwith of stream in bps // should be the sum of bitrates of the // individual media streams } ASFMainHeader; typedef struct { int seqno; int packet_size; int is_streamed; int asfid2avid[128]; /* conversion table from asf ID 2 AVStream ID */ ASFStream streams[128]; /* it's max number and it's not that big */ /* non streamed additonnal info */ int64_t nb_packets; int64_t duration; /* in 100ns units */ /* packet filling */ int packet_size_left; int packet_timestamp_start; int packet_timestamp_end; int packet_nb_frames; uint8_t packet_buf[PACKET_SIZE]; ByteIOContext pb; /* only for reading */ uint64_t data_offset; /* begining of the first data packet */ ASFMainHeader hdr; int packet_flags; int packet_property; int packet_timestamp; int packet_segsizetype; int packet_segments; int packet_seq; int packet_replic_size; int packet_key_frame; int packet_padsize; int packet_frag_offset; int packet_frag_size; int packet_frag_timestamp; int packet_multi_size; int packet_obj_size; int packet_time_delta; int packet_time_start; int packet_pos; int stream_index; ASFStream* asf_st; /* currently decoded stream */ } ASFContext; static const GUID asf_header = { 0x75B22630, 0x668E, 0x11CF, { 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C }, }; static const GUID file_header = { 0x8CABDCA1, 0xA947, 0x11CF, { 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }, }; static const GUID stream_header = { 0xB7DC0791, 0xA9B7, 0x11CF, { 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }, }; static const GUID audio_stream = { 0xF8699E40, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B }, }; static const GUID audio_conceal_none = { // 0x49f1a440, 0x4ece, 0x11d0, { 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 }, // New value lifted from avifile 0x20fb5700, 0x5b55, 0x11cf, { 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b }, }; static const GUID video_stream = { 0xBC19EFC0, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B }, }; static const GUID video_conceal_none = { 0x20FB5700, 0x5B55, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B }, }; static const GUID comment_header = { 0x75b22633, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }, }; static const GUID codec_comment_header = { 0x86D15240, 0x311D, 0x11D0, { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 }, }; static const GUID codec_comment1_header = { 0x86d15241, 0x311d, 0x11d0, { 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 }, }; static const GUID data_header = { 0x75b22636, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }, }; static const GUID index_guid = { 0x33000890, 0xe5b1, 0x11cf, { 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb }, }; static const GUID head1_guid = { 0x5fbf03b5, 0xa92e, 0x11cf, { 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }, }; static const GUID head2_guid = { 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }, }; static const GUID extended_content_header = { 0xD2D0A440, 0xE307, 0x11D2, { 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50 }, }; /* I am not a number !!! This GUID is the one found on the PC used to generate the stream */ static const GUID my_guid = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 }, }; const CodecTag codec_wav_tags[] = { { CODEC_ID_MP2, 0x50 }, { CODEC_ID_MP3, 0x55 }, { CODEC_ID_AC3, 0x2000 }, { CODEC_ID_PCM_S16LE, 0x01 }, { CODEC_ID_PCM_U8, 0x01 }, /* must come after s16le in this list */ { CODEC_ID_PCM_ALAW, 0x06 }, { CODEC_ID_PCM_MULAW, 0x07 }, { CODEC_ID_ADPCM_MS, 0x02 }, { CODEC_ID_ADPCM_IMA_WAV, 0x11 }, { CODEC_ID_ADPCM_IMA_DK4, 0x61 }, /* rogue format number */ { CODEC_ID_ADPCM_IMA_DK3, 0x62 }, /* rogue format number */ { CODEC_ID_WMAV1, 0x160 }, { CODEC_ID_WMAV2, 0x161 }, { 0, 0 }, }; enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag) { while (tags->id != 0) { if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF) && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF) && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF) && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF)) return tags->id; tags++; } return CODEC_ID_NONE; } int wav_codec_get_id(unsigned int tag, int bps) { int id; id = codec_get_id(codec_wav_tags, tag); if (id <= 0) return id; /* handle specific u8 codec */ if (id == CODEC_ID_PCM_S16LE && bps == 8) id = CODEC_ID_PCM_U8; return id; } void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size) { int id; id = get_le16(pb); codec->codec_type = CODEC_TYPE_AUDIO; codec->codec_tag = id; codec->channels = get_le16(pb); codec->sample_rate = get_le32(pb); codec->bit_rate = get_le32(pb) * 8; codec->block_align = get_le16(pb); if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */ codec->bits_per_sample = 8; }else codec->bits_per_sample = get_le16(pb); codec->codec_id = wav_codec_get_id(id, codec->bits_per_sample); if (size > 16) { /* We're obviously dealing with WAVEFORMATEX */ codec->extradata_size = get_le16(pb); if (codec->extradata_size > 0) { if (codec->extradata_size > size - 18) codec->extradata_size = size - 18; codec->extradata = av_mallocz(codec->extradata_size); get_buffer(pb, codec->extradata, codec->extradata_size); } else codec->extradata_size = 0; /* It is possible for the chunk to contain garbage at the end */ if (size - codec->extradata_size - 18 > 0) url_fskip(pb, size - codec->extradata_size - 18); } } #ifdef CONFIG_ENCODERS static void put_guid(ByteIOContext *s, const GUID *g) { int i; put_le32(s, g->v1); put_le16(s, g->v2); put_le16(s, g->v3); for(i=0;i<8;i++) put_byte(s, g->v4[i]); } static void put_str16(ByteIOContext *s, const char *tag) { int c; put_le16(s,strlen(tag) + 1); for(;;) { c = (uint8_t)*tag++; put_le16(s, c); if (c == '\0') break; } } static void put_str16_nolen(ByteIOContext *s, const char *tag) { int c; for(;;) { c = (uint8_t)*tag++; put_le16(s, c); if (c == '\0') break; } } static int64_t put_header(ByteIOContext *pb, const GUID *g) { int64_t pos; pos = url_ftell(pb); put_guid(pb, g); put_le64(pb, 24); return pos; } /* update header size */ static void end_header(ByteIOContext *pb, int64_t pos) { int64_t pos1; pos1 = url_ftell(pb); url_fseek(pb, pos + 16, SEEK_SET); put_le64(pb, pos1 - pos); url_fseek(pb, pos1, SEEK_SET); } /* write an asf chunk (only used in streaming case) */ static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags) { ASFContext *asf = s->priv_data; ByteIOContext *pb = &s->pb; int length; length = payload_length + 8; put_le16(pb, type); put_le16(pb, length); put_le32(pb, asf->seqno); put_le16(pb, flags); /* unknown bytes */ put_le16(pb, length); asf->seqno++; } /* convert from unix to windows time */ static int64_t unix_to_file_time(int ti) { int64_t t; t = ti * int64_t_C(10000000); t += int64_t_C(116444736000000000); return t; } /* write the header (used two times if non streamed) */ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size) { ASFContext *asf = s->priv_data; ByteIOContext *pb = &s->pb; int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; int has_title; AVCodecContext *enc; int64_t header_offset, cur_pos, hpos; int bit_rate; has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]); bit_rate = 0; for(n=0;nnb_streams;n++) { enc = &s->streams[n]->codec; bit_rate += enc->bit_rate; } if (asf->is_streamed) { put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */ } put_guid(pb, &asf_header); put_le64(pb, -1); /* header length, will be patched after */ put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */ put_byte(pb, 1); /* ??? */ put_byte(pb, 2); /* ??? */ /* file header */ header_offset = url_ftell(pb); hpos = put_header(pb, &file_header); put_guid(pb, &my_guid); put_le64(pb, file_size); file_time = 0; put_le64(pb, unix_to_file_time(file_time)); put_le64(pb, asf->nb_packets); /* number of packets */ put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */ put_le64(pb, asf->duration); /* duration (in 100ns units) */ put_le32(pb, 0); /* start time stamp */ put_le32(pb, 0); /* ??? */ put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */ put_le32(pb, asf->packet_size); /* packet size */ put_le32(pb, asf->packet_size); /* packet size */ put_le32(pb, bit_rate); /* Nominal data rate in bps */ end_header(pb, hpos); /* unknown headers */ hpos = put_header(pb, &head1_guid); put_guid(pb, &head2_guid); put_le32(pb, 6); put_le16(pb, 0); end_header(pb, hpos); /* title and other infos */ if (has_title) { hpos = put_header(pb, &comment_header); put_le16(pb, 2 * (strlen(s->title) + 1)); put_le16(pb, 2 * (strlen(s->author) + 1)); put_le16(pb, 2 * (strlen(s->copyright) + 1)); put_le16(pb, 2 * (strlen(s->comment) + 1)); put_le16(pb, 0); put_str16_nolen(pb, s->title); put_str16_nolen(pb, s->author); put_str16_nolen(pb, s->copyright); put_str16_nolen(pb, s->comment); end_header(pb, hpos); } /* stream headers */ for(n=0;nnb_streams;n++) { int64_t es_pos; // ASFStream *stream = &asf->streams[n]; enc = &s->streams[n]->codec; asf->streams[n].num = n + 1; asf->streams[n].seq = 0; switch(enc->codec_type) { case CODEC_TYPE_AUDIO: wav_extra_size = 0; extra_size = 18 + wav_extra_size; extra_size2 = 0; break; default: case CODEC_TYPE_VIDEO: wav_extra_size = 0; extra_size = 0x33; extra_size2 = 0; break; } hpos = put_header(pb, &stream_header); if (enc->codec_type == CODEC_TYPE_AUDIO) { put_guid(pb, &audio_stream); put_guid(pb, &audio_conceal_none); } else { put_guid(pb, &video_stream); put_guid(pb, &video_conceal_none); } put_le64(pb, 0); /* ??? */ es_pos = url_ftell(pb); put_le32(pb, extra_size); /* wav header len */ put_le32(pb, extra_size2); /* additional data len */ put_le16(pb, n + 1); /* stream number */ put_le32(pb, 0); /* ??? */ if (enc->codec_type == CODEC_TYPE_AUDIO) { /* WAVEFORMATEX header */ int wavsize = put_wav_header(pb, enc); if (wavsize < 0) return -1; if (wavsize != extra_size) { cur_pos = url_ftell(pb); url_fseek(pb, es_pos, SEEK_SET); put_le32(pb, wavsize); /* wav header len */ url_fseek(pb, cur_pos, SEEK_SET); } } else { put_le32(pb, enc->width); put_le32(pb, enc->height); put_byte(pb, 2); /* ??? */ put_le16(pb, 40); /* size */ /* BITMAPINFOHEADER header */ put_bmp_header(pb, enc, codec_bmp_tags, 1); } end_header(pb, hpos); } /* media comments */ hpos = put_header(pb, &codec_comment_header); put_guid(pb, &codec_comment1_header); put_le32(pb, s->nb_streams); for(n=0;nnb_streams;n++) { AVCodec *p; enc = &s->streams[n]->codec; p = avcodec_find_encoder(enc->codec_id); put_le16(pb, asf->streams[n].num); put_str16(pb, p ? p->name : enc->codec_name); put_le16(pb, 0); /* no parameters */ /* id */ if (enc->codec_type == CODEC_TYPE_AUDIO) { put_le16(pb, 2); if(!enc->codec_tag) enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id); if(!enc->codec_tag) return -1; put_le16(pb, enc->codec_tag); } else { put_le16(pb, 4); if(!enc->codec_tag) enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id); if(!enc->codec_tag) return -1; put_le32(pb, enc->codec_tag); } } end_header(pb, hpos); /* patch the header size fields */ cur_pos = url_ftell(pb); header_size = cur_pos - header_offset; if (asf->is_streamed) { header_size += 8 + 30 + 50; url_fseek(pb, header_offset - 10 - 30, SEEK_SET); put_le16(pb, header_size); url_fseek(pb, header_offset - 2 - 30, SEEK_SET); put_le16(pb, header_size); header_size -= 8 + 30 + 50; } header_size += 24 + 6; url_fseek(pb, header_offset - 14, SEEK_SET); put_le64(pb, header_size); url_fseek(pb, cur_pos, SEEK_SET); /* movie chunk, followed by packets of packet_size */ asf->data_offset = cur_pos; put_guid(pb, &data_header); put_le64(pb, data_chunk_size); put_guid(pb, &my_guid); put_le64(pb, asf->nb_packets); /* nb packets */ put_byte(pb, 1); /* ??? */ put_byte(pb, 1); /* ??? */ return 0; } static int asf_write_header(AVFormatContext *s) { ASFContext *asf = s->priv_data; av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */ asf->packet_size = PACKET_SIZE; asf->nb_packets = 0; if (asf_write_header1(s, 0, 50) < 0) { //av_free(asf); return -1; } put_flush_packet(&s->pb); asf->packet_nb_frames = 0; asf->packet_timestamp_start = -1; asf->packet_timestamp_end = -1; asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE; init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1, NULL, NULL, NULL, NULL); return 0; } static int asf_write_stream_header(AVFormatContext *s) { ASFContext *asf = s->priv_data; asf->is_streamed = 1; return asf_write_header(s); } /* write a fixed size packet */ static int put_packet(AVFormatContext *s, unsigned int timestamp, unsigned int duration, int nb_frames, int padsize) { ASFContext *asf = s->priv_data; ByteIOContext *pb = &s->pb; int flags; if (asf->is_streamed) { put_chunk(s, 0x4424, asf->packet_size, 0); } put_byte(pb, 0x82); put_le16(pb, 0); flags = 0x01; /* nb segments present */ if (padsize > 0) { if (padsize < 256) flags |= 0x08; else flags |= 0x10; } put_byte(pb, flags); /* flags */ put_byte(pb, 0x5d); if (flags & 0x10) put_le16(pb, padsize - 2); if (flags & 0x08) put_byte(pb, padsize - 1); put_le32(pb, timestamp); put_le16(pb, duration); put_byte(pb, nb_frames | 0x80); return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3); } static void flush_packet(AVFormatContext *s) { ASFContext *asf = s->priv_data; int hdr_size, ptr; hdr_size = put_packet(s, asf->packet_timestamp_start, asf->packet_timestamp_end - asf->packet_timestamp_start, asf->packet_nb_frames, asf->packet_size_left); /* Clear out the padding bytes */ ptr = asf->packet_size - hdr_size - asf->packet_size_left; memset(asf->packet_buf + ptr, 0, asf->packet_size_left); put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size); put_flush_packet(&s->pb); asf->nb_packets++; asf->packet_nb_frames = 0; asf->packet_timestamp_start = -1; asf->packet_timestamp_end = -1; asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE; init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1, NULL, NULL, NULL, NULL); } static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp, int payload_size, int frag_offset, int frag_len) { ASFContext *asf = s->priv_data; ByteIOContext *pb = &asf->pb; int val; val = stream->num; if (s->streams[val - 1]->codec.coded_frame->key_frame /* && frag_offset == 0 */) val |= 0x80; put_byte(pb, val); put_byte(pb, stream->seq); put_le32(pb, frag_offset); /* fragment offset */ put_byte(pb, 0x08); /* flags */ put_le32(pb, payload_size); put_le32(pb, timestamp); put_le16(pb, frag_len); } /* Output a frame. We suppose that payload_size <= PACKET_SIZE. It is there that you understand that the ASF format is really crap. They have misread the MPEG Systems spec ! */ static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp, const uint8_t *buf, int payload_size) { ASFContext *asf = s->priv_data; int frag_pos, frag_len, frag_len1; frag_pos = 0; while (frag_pos < payload_size) { frag_len = payload_size - frag_pos; frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE; if (frag_len1 > 0) { if (frag_len > frag_len1) frag_len = frag_len1; put_frame_header(s, stream, timestamp+1, payload_size, frag_pos, frag_len); put_buffer(&asf->pb, buf, frag_len); asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE); asf->packet_timestamp_end = timestamp; if (asf->packet_timestamp_start == -1) asf->packet_timestamp_start = timestamp; asf->packet_nb_frames++; } else { frag_len = 0; } frag_pos += frag_len; buf += frag_len; /* output the frame if filled */ if (asf->packet_size_left <= FRAME_HEADER_SIZE) flush_packet(s); } stream->seq++; } static int asf_write_packet(AVFormatContext *s, int stream_index, const uint8_t *buf, int size, int64_t timestamp) { ASFContext *asf = s->priv_data; ASFStream *stream; int64_t duration; AVCodecContext *codec; codec = &s->streams[stream_index]->codec; stream = &asf->streams[stream_index]; if (codec->codec_type == CODEC_TYPE_AUDIO) { duration = (codec->frame_number * codec->frame_size * int64_t_C(10000000)) / codec->sample_rate; } else { duration = av_rescale(codec->frame_number * codec->frame_rate_base, 10000000, codec->frame_rate); } if (duration > asf->duration) asf->duration = duration; put_frame(s, stream, timestamp, buf, size); return 0; } static int asf_write_trailer(AVFormatContext *s) { ASFContext *asf = s->priv_data; int64_t file_size; /* flush the current packet */ if (asf->pb.buf_ptr > asf->pb.buffer) flush_packet(s); if (asf->is_streamed) { put_chunk(s, 0x4524, 0, 0); /* end of stream */ } else { /* rewrite an updated header */ file_size = url_ftell(&s->pb); url_fseek(&s->pb, 0, SEEK_SET); asf_write_header1(s, file_size, file_size - asf->data_offset); } put_flush_packet(&s->pb); return 0; } #endif //CONFIG_ENCODERS /**********************************/ /* decoding */ //#define DEBUG #ifdef DEBUG #define PRINT_IF_GUID(g,cmp) \ if (!memcmp(g, &cmp, sizeof(GUID))) \ printf("(GUID: %s) ", #cmp) static void print_guid(const GUID *g) { int i; PRINT_IF_GUID(g, asf_header); else PRINT_IF_GUID(g, file_header); else PRINT_IF_GUID(g, stream_header); else PRINT_IF_GUID(g, audio_stream); else PRINT_IF_GUID(g, audio_conceal_none); else PRINT_IF_GUID(g, video_stream); else PRINT_IF_GUID(g, video_conceal_none); else PRINT_IF_GUID(g, comment_header); else PRINT_IF_GUID(g, codec_comment_header); else PRINT_IF_GUID(g, codec_comment1_header); else PRINT_IF_GUID(g, data_header); else PRINT_IF_GUID(g, index_guid); else PRINT_IF_GUID(g, head1_guid); else PRINT_IF_GUID(g, head2_guid); else PRINT_IF_GUID(g, my_guid); else printf("(GUID: unknown) "); printf("0x%08x, 0x%04x, 0x%04x, {", g->v1, g->v2, g->v3); for(i=0;i<8;i++) printf(" 0x%02x,", g->v4[i]); printf("}\n"); } #undef PRINT_IF_GUID(g,cmp) #endif static void get_guid(ByteIOContext *s, GUID *g) { int i; g->v1 = get_le32(s); g->v2 = get_le16(s); g->v3 = get_le16(s); for(i=0;i<8;i++) g->v4[i] = get_byte(s); } #if 0 static void get_str16(ByteIOContext *pb, char *buf, int buf_size) { int len, c; char *q; len = get_le16(pb); q = buf; while (len > 0) { c = get_le16(pb); if ((q - buf) < buf_size - 1) *q++ = c; len--; } *q = '\0'; } #endif static char *getlocale() { char *str; str = strstr(getenv("LANG"), "."); if(str) *str++; else str = "US-ASCII"; return str; } static void tag_recode(char *before, unsigned int len) { int result; iconv_t frt; char ansb[len]; char ansa[len]; char *ansbptr = ansb; char *ansaptr = ansa; unsigned int len1 = 2 * len; unsigned int length = len; memcpy(ansb, before, len); frt = iconv_open(getlocale(), "UNICODE"); if (frt == (iconv_t) - 1) { return; } result = iconv(frt, &ansbptr, &len, &ansaptr, &len1); if (result == (size_t) - 1) { return; } else memcpy(before, ansa, length); if (iconv_close(frt) != 0) if (iconv_close(frt) != 0) return; return; } static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size) { int c, lenz; char *q; q = buf; lenz = len; while (len > 0) { c = get_byte(pb); if ((q - buf) < buf_size-1) *q++ = c; len--; } tag_recode(buf, lenz); } static int asf_probe(AVProbeData *pd) { GUID g; const unsigned char *p; int i; /* check file header */ if (pd->buf_size <= 32) return 0; p = pd->buf; g.v1 = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); p += 4; g.v2 = p[0] | (p[1] << 8); p += 2; g.v3 = p[0] | (p[1] << 8); p += 2; for(i=0;i<8;i++) g.v4[i] = *p++; if (!memcmp(&g, &asf_header, sizeof(GUID))) return AVPROBE_SCORE_MAX; else return 0; } static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) { ASFContext *asf = s->priv_data; GUID g; ByteIOContext *pb = &s->pb; AVStream *st; ASFStream *asf_st; //int size, i; int i; int64_t gsize; av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */ get_guid(pb, &g); if (memcmp(&g, &asf_header, sizeof(GUID))) goto fail; get_le64(pb); get_le32(pb); get_byte(pb); get_byte(pb); memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid)); for(;;) { get_guid(pb, &g); gsize = get_le64(pb); #ifdef DEBUG printf("%08Lx: ", url_ftell(pb) - 24); print_guid(&g); printf(" size=0x%Lx\n", gsize); #endif if (gsize < 24) goto fail; if (!memcmp(&g, &file_header, sizeof(GUID))) { get_guid(pb, &asf->hdr.guid); asf->hdr.file_size = get_le64(pb); asf->hdr.create_time = get_le64(pb); asf->hdr.packets_count = get_le64(pb); asf->hdr.play_time = get_le64(pb); asf->hdr.send_time = get_le64(pb); asf->hdr.preroll = get_le32(pb); asf->hdr.ignore = get_le32(pb); asf->hdr.flags = get_le32(pb); asf->hdr.min_pktsize = get_le32(pb); asf->hdr.max_pktsize = get_le32(pb); asf->hdr.max_bitrate = get_le32(pb); asf->packet_size = asf->hdr.max_pktsize; asf->nb_packets = asf->hdr.packets_count; } else if (!memcmp(&g, &stream_header, sizeof(GUID))) { int type, total_size, type_specific_size; //unsigned int tag1; int64_t pos1, pos2; pos1 = url_ftell(pb); st = av_new_stream(s, 0); if (!st) goto fail; asf_st = av_mallocz(sizeof(ASFStream)); if (!asf_st) goto fail; st->priv_data = asf_st; st->start_time = asf->hdr.preroll / (10000000 / AV_TIME_BASE); st->duration = (asf->hdr.send_time - asf->hdr.preroll) / (10000000 / AV_TIME_BASE); get_guid(pb, &g); if (!memcmp(&g, &audio_stream, sizeof(GUID))) { type = CODEC_TYPE_AUDIO; } else if (!memcmp(&g, &video_stream, sizeof(GUID))) { type = CODEC_TYPE_VIDEO; } else { goto fail; } get_guid(pb, &g); total_size = get_le64(pb); type_specific_size = get_le32(pb); get_le32(pb); st->id = get_le16(pb) & 0x7f; /* stream id */ // mapping of asf ID to AV stream ID; asf->asfid2avid[st->id] = s->nb_streams - 1; get_le32(pb); st->codec.codec_type = type; /* 1 fps default (XXX: put 0 fps instead) */ st->codec.frame_rate = 1; st->codec.frame_rate_base = 1; if (type == CODEC_TYPE_AUDIO) { get_wav_header(pb, &st->codec, type_specific_size); st->need_parsing = 1; /* We have to init the frame size at some point .... */ pos2 = url_ftell(pb); if (gsize > (pos2 + 8 - pos1 + 24)) { asf_st->ds_span = get_byte(pb); asf_st->ds_packet_size = get_le16(pb); asf_st->ds_chunk_size = get_le16(pb); asf_st->ds_data_size = get_le16(pb); asf_st->ds_silence_data = get_byte(pb); } //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n", // asf_st->ds_packet_size, asf_st->ds_chunk_size, // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data); if (asf_st->ds_span > 1) { if (!asf_st->ds_chunk_size || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1)) asf_st->ds_span = 0; // disable descrambling } switch (st->codec.codec_id) { case CODEC_ID_MP3: st->codec.frame_size = MPA_FRAME_SIZE; break; case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_U16BE: case CODEC_ID_PCM_S8: case CODEC_ID_PCM_U8: case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_MULAW: st->codec.frame_size = 1; break; default: /* This is probably wrong, but it prevents a crash later */ st->codec.frame_size = 1; break; } } #if 0 } else { get_le32(pb); get_le32(pb); get_byte(pb); size = get_le16(pb); /* size */ get_le32(pb); /* size */ st->codec.width = get_le32(pb); st->codec.height = get_le32(pb); /* not available for asf */ get_le16(pb); /* panes */ st->codec.bits_per_sample = get_le16(pb); /* depth */ tag1 = get_le32(pb); url_fskip(pb, 20); if (size > 40) { st->codec.extradata_size = size - 40; st->codec.extradata = av_mallocz(st->codec.extradata_size); get_buffer(pb, st->codec.extradata, st->codec.extradata_size); } /* Extract palette from extradata if bpp <= 8 */ /* This code assumes that extradata contains only palette */ /* This is true for all paletted codecs implemented in ffmpeg */ if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) { st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl)); #ifdef WORDS_BIGENDIAN for (i = 0; i < FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)/4; i++) st->codec.palctrl->palette[i] = bswap_32(((uint32_t*)st->codec.extradata)[i]); #else memcpy(st->codec.palctrl->palette, st->codec.extradata, FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)); #endif st->codec.palctrl->palette_changed = 1; } st->codec.codec_tag = tag1; st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1); } #endif pos2 = url_ftell(pb); url_fskip(pb, gsize - (pos2 - pos1 + 24)); } else if (!memcmp(&g, &data_header, sizeof(GUID))) { break; } else if (!memcmp(&g, &comment_header, sizeof(GUID))) { int len1, len2, len3, len4, len5; len1 = get_le16(pb); len2 = get_le16(pb); len3 = get_le16(pb); len4 = get_le16(pb); len5 = get_le16(pb); get_str16_nolen(pb, len1, s->title, sizeof(s->title)); get_str16_nolen(pb, len2, s->author, sizeof(s->author)); get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright)); get_str16_nolen(pb, len4, s->comment, sizeof(s->comment)); url_fskip(pb, len5); } else if (!memcmp(&g, &extended_content_header, sizeof(GUID))) { int desc_count, i; desc_count = get_le16(pb); for(i=0;ialbum, value); } if (strcmp(name,"WM/Genre")==0) { strcpy(s->genre, value); } if (strcmp(name,"WM/Year")==0) s->year = atoi(value); av_free(value); } if ((value_type >= 2) || (value_type <= 5)) // boolean or DWORD or QWORD or WORD { if (value_type==2) value_num = get_le32(pb); if (value_type==3) value_num = get_le32(pb); if (value_type==4) value_num = get_le64(pb); if (value_type==5) value_num = get_le16(pb); if (strcmp(name,"WM/Track")==0) s->track = value_num + 1; if (strcmp(name,"WM/TrackNumber")==0) s->track = value_num; } av_free(name); } #if 0 } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) { int v1, v2; get_guid(pb, &g); v1 = get_le32(pb); v2 = get_le16(pb); } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) { int len, v1, n, num; char str[256], *q; char tag[16]; get_guid(pb, &g); print_guid(&g); n = get_le32(pb); for(i=0;i 0) { v1 = get_byte(pb); if ((q - tag) < sizeof(tag) - 1) *q++ = v1; len--; } *q = '\0'; } #endif } else if (url_feof(pb)) { goto fail; } else { url_fseek(pb, gsize - 24, SEEK_CUR); } } get_guid(pb, &g); get_le64(pb); get_byte(pb); get_byte(pb); if (url_feof(pb)) goto fail; asf->data_offset = url_ftell(pb); asf->packet_size_left = 0; return 0; fail: for(i=0;inb_streams;i++) { AVStream *st = s->streams[i]; if (st) { av_free(st->priv_data); av_free(st->codec.extradata); } av_free(st); } return -1; } #define DO_2BITS(bits, var, defval) \ switch (bits & 3) \ { \ case 3: var = get_le32(pb); rsize += 4; break; \ case 2: var = get_le16(pb); rsize += 2; break; \ case 1: var = get_byte(pb); rsize++; break; \ default: var = defval; break; \ } static int asf_get_packet(AVFormatContext *s) { ASFContext *asf = s->priv_data; ByteIOContext *pb = &s->pb; uint32_t packet_length, padsize; int rsize = 9; int c; assert((url_ftell(&s->pb) - s->data_offset) % asf->packet_size == 0); c = get_byte(pb); if (c != 0x82) { if (!url_feof(pb)) printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb)); } if ((c & 0x0f) == 2) { // always true for now if (get_le16(pb) != 0) { if (!url_feof(pb)) printf("ff asf bad non zero\n"); return -EIO; } rsize+=2; /* }else{ if (!url_feof(pb)) printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb)); return -EIO;*/ } asf->packet_flags = get_byte(pb); asf->packet_property = get_byte(pb); DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size); DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length asf->packet_timestamp = get_le32(pb); get_le16(pb); /* duration */ // rsize has at least 11 bytes which have to be present if (asf->packet_flags & 0x01) { asf->packet_segsizetype = get_byte(pb); rsize++; asf->packet_segments = asf->packet_segsizetype & 0x3f; } else { asf->packet_segments = 1; asf->packet_segsizetype = 0x80; } asf->packet_size_left = packet_length - padsize - rsize; if (packet_length < asf->hdr.min_pktsize) padsize += asf->hdr.min_pktsize - packet_length; asf->packet_padsize = padsize; #ifdef DEBUG printf("packet: size=%d padsize=%d left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left); #endif return 0; } static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) { ASFContext *asf = s->priv_data; ASFStream *asf_st = 0; ByteIOContext *pb = &s->pb; //static int pc = 0; for (;;) { int rsize = 0; if (asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1) { //asf->packet_size_left <= asf->packet_padsize) { int ret = asf->packet_size_left + asf->packet_padsize; //printf("PacketLeftSize:%d Pad:%d Pos:%Ld\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb)); /* fail safe */ url_fskip(pb, ret); asf->packet_pos= url_ftell(&s->pb); ret = asf_get_packet(s); //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++); if (ret < 0 || url_feof(pb)) return -EIO; asf->packet_time_start = 0; continue; } if (asf->packet_time_start == 0) { /* read frame header */ int num = get_byte(pb); asf->packet_segments--; rsize++; asf->packet_key_frame = (num & 0x80) >> 7; asf->stream_index = asf->asfid2avid[num & 0x7f]; // sequence should be ignored! DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0); DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0); DO_2BITS(asf->packet_property, asf->packet_replic_size, 0); //printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size); if (asf->packet_replic_size > 1) { assert(asf->packet_replic_size >= 8); // it should be always at least 8 bytes - FIXME validate asf->packet_obj_size = get_le32(pb); asf->packet_frag_timestamp = get_le32(pb); // timestamp if (asf->packet_replic_size > 8) url_fskip(pb, asf->packet_replic_size - 8); rsize += asf->packet_replic_size; // FIXME - check validity } else if (asf->packet_replic_size==1){ // multipacket - frag_offset is begining timestamp asf->packet_time_start = asf->packet_frag_offset; asf->packet_frag_offset = 0; asf->packet_frag_timestamp = asf->packet_timestamp; asf->packet_time_delta = get_byte(pb); rsize++; }else{ assert(asf->packet_replic_size==0); } if (asf->packet_flags & 0x01) { DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal #undef DO_2BITS //printf("Fragsize %d\n", asf->packet_frag_size); } else { asf->packet_frag_size = asf->packet_size_left - rsize; //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize); } if (asf->packet_replic_size == 1) { asf->packet_multi_size = asf->packet_frag_size; if (asf->packet_multi_size > asf->packet_size_left) { asf->packet_segments = 0; continue; } } asf->packet_size_left -= rsize; //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize); if (asf->stream_index < 0) { asf->packet_time_start = 0; /* unhandled packet (should not happen) */ url_fskip(pb, asf->packet_frag_size); asf->packet_size_left -= asf->packet_frag_size; printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f); continue; } asf->asf_st = s->streams[asf->stream_index]->priv_data; } asf_st = asf->asf_st; if ((asf->packet_frag_offset != asf_st->frag_offset || (asf->packet_frag_offset && asf->packet_seq != asf_st->seq)) // seq should be ignored ) { /* cannot continue current packet: free it */ // FIXME better check if packet was already allocated printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n", asf_st->pkt.size, asf->packet_obj_size, asf->packet_frag_offset, asf_st->frag_offset, asf->packet_seq, asf_st->seq, asf->packet_frag_size); if (asf_st->pkt.size) av_free_packet(&asf_st->pkt); asf_st->frag_offset = 0; if (asf->packet_frag_offset != 0) { url_fskip(pb, asf->packet_frag_size); printf("ff asf parser skiping %db\n", asf->packet_frag_size); asf->packet_size_left -= asf->packet_frag_size; continue; } } if (asf->packet_replic_size == 1) { // frag_offset is here used as the begining timestamp asf->packet_frag_timestamp = asf->packet_time_start; asf->packet_time_start += asf->packet_time_delta; asf->packet_obj_size = asf->packet_frag_size = get_byte(pb); asf->packet_size_left--; asf->packet_multi_size--; if (asf->packet_multi_size < asf->packet_obj_size) { asf->packet_time_start = 0; url_fskip(pb, asf->packet_multi_size); asf->packet_size_left -= asf->packet_multi_size; continue; } asf->packet_multi_size -= asf->packet_obj_size; //printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size); } if (asf_st->frag_offset == 0) { /* new packet */ av_new_packet(&asf_st->pkt, asf->packet_obj_size); asf_st->seq = asf->packet_seq; asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll; asf_st->pkt.stream_index = asf->stream_index; asf_st->packet_pos= asf->packet_pos; //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", //asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & PKT_FLAG_KEY, //s->streams[asf->stream_index]->codec.codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size); if (s->streams[asf->stream_index]->codec.codec_type == CODEC_TYPE_AUDIO) asf->packet_key_frame = 1; if (asf->packet_key_frame) asf_st->pkt.flags |= PKT_FLAG_KEY; } /* read data */ //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n", // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset, // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data); asf->packet_size_left -= asf->packet_frag_size; if (asf->packet_size_left < 0) continue; get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset, asf->packet_frag_size); asf_st->frag_offset += asf->packet_frag_size; /* test if whole packet is read */ if (asf_st->frag_offset == asf_st->pkt.size) { /* return packet */ if (asf_st->ds_span > 1) { /* packet descrambling */ unsigned char* newdata = av_malloc(asf_st->pkt.size); if (newdata) { int offset = 0; while (offset < asf_st->pkt.size) { int off = offset / asf_st->ds_chunk_size; int row = off / asf_st->ds_span; int col = off % asf_st->ds_span; int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size; //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx); memcpy(newdata + offset, asf_st->pkt.data + idx * asf_st->ds_chunk_size, asf_st->ds_chunk_size); offset += asf_st->ds_chunk_size; } av_free(asf_st->pkt.data); asf_st->pkt.data = newdata; } } asf_st->frag_offset = 0; memcpy(pkt, &asf_st->pkt, sizeof(AVPacket)); //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size); asf_st->pkt.size = 0; asf_st->pkt.data = 0; break; // packet completed } } return 0; } static int asf_read_close(AVFormatContext *s) { int i; for(i=0;inb_streams;i++) { AVStream *st = s->streams[i]; av_free(st->priv_data); av_free(st->codec.extradata); av_free(st->codec.palctrl); } return 0; } // Added to support seeking after packets have been read // If information is not reset, read_packet fails due to // leftover information from previous reads static void asf_reset_header(AVFormatContext *s) { ASFContext *asf = s->priv_data; ASFStream *asf_st; int i; asf->packet_nb_frames = 0; asf->packet_timestamp_start = -1; asf->packet_timestamp_end = -1; asf->packet_size_left = 0; asf->packet_segments = 0; asf->packet_flags = 0; asf->packet_property = 0; asf->packet_timestamp = 0; asf->packet_segsizetype = 0; asf->packet_segments = 0; asf->packet_seq = 0; asf->packet_replic_size = 0; asf->packet_key_frame = 0; asf->packet_padsize = 0; asf->packet_frag_offset = 0; asf->packet_frag_size = 0; asf->packet_frag_timestamp = 0; asf->packet_multi_size = 0; asf->packet_obj_size = 0; asf->packet_time_delta = 0; asf->packet_time_start = 0; for(i=0; inb_streams; i++){ asf_st= s->streams[i]->priv_data; av_free_packet(&asf_st->pkt); asf_st->frag_offset=0; asf_st->seq=0; } asf->asf_st= NULL; } static int64_t asf_read_pts(AVFormatContext *s, int64_t *ppos, int stream_index) { ASFContext *asf = s->priv_data; AVPacket pkt1, *pkt = &pkt1; ASFStream *asf_st; int64_t pts; int64_t pos= *ppos; int i; int64_t start_pos[s->nb_streams]; for(i=0; inb_streams; i++){ start_pos[i]= pos; } //printf("asf_read_pts\n"); url_fseek(&s->pb, pos*asf->packet_size + s->data_offset, SEEK_SET); asf_reset_header(s); for(;;){ if (av_read_frame(s, pkt) < 0){ printf("seek failed\n"); return AV_NOPTS_VALUE; } pts= pkt->pts; av_free_packet(pkt); if(pkt->flags&PKT_FLAG_KEY){ i= pkt->stream_index; asf_st= s->streams[i]->priv_data; assert((asf_st->packet_pos - s->data_offset) % asf->packet_size == 0); pos= (asf_st->packet_pos - s->data_offset) / asf->packet_size; av_add_index_entry(s->streams[i], pos, pts, pos - start_pos[i] + 1, AVINDEX_KEYFRAME); start_pos[i]= pos + 1; if(pkt->stream_index == stream_index) break; } } *ppos= pos; //printf("found keyframe at %Ld stream %d stamp:%Ld\n", *ppos, stream_index, pts); return pts; } static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts) { ASFContext *asf = s->priv_data; AVStream *st; int64_t pos; int64_t pos_min, pos_max, pts_min, pts_max, cur_pts, pos_limit; int no_change; if (stream_index == -1) stream_index= av_find_default_stream_index(s); if (asf->packet_size <= 0) return -1; pts_max= pts_min= AV_NOPTS_VALUE; pos_max= pos_limit= -1; // gcc thinks its uninitalized st= s->streams[stream_index]; if(st->index_entries){ AVIndexEntry *e; int index; index= av_index_search_timestamp(st, pts); e= &st->index_entries[index]; if(e->timestamp <= pts){ pos_min= e->pos; pts_min= e->timestamp; #ifdef DEBUG_SEEK printf("unsing cached pos_min=0x%llx dts_min=%0.3f\n", pos_min,pts_min / 90000.0); #endif }else{ assert(index==0); } index++; if(index < st->nb_index_entries){ e= &st->index_entries[index]; assert(e->timestamp >= pts); pos_max= e->pos; pts_max= e->timestamp; pos_limit= pos_max - e->min_distance; #ifdef DEBUG_SEEK printf("unsing cached pos_max=0x%llx dts_max=%0.3f\n", pos_max,pts_max / 90000.0); #endif } } if(pts_min == AV_NOPTS_VALUE){ pos_min = 0; pts_min = asf_read_pts(s, &pos_min, stream_index); if (pts_min == AV_NOPTS_VALUE) return -1; } if(pts_max == AV_NOPTS_VALUE){ pos_max = (url_filesize(url_fileno(&s->pb)) - 1 - s->data_offset) / asf->packet_size; //FIXME wrong pts_max = s->duration; //FIXME wrong pos_limit= pos_max; } no_change=0; while (pos_min < pos_limit) { int64_t start_pos; assert(pos_limit <= pos_max); if(no_change==0){ int64_t approximate_keyframe_distance= pos_max - pos_limit; // interpolate position (better than dichotomy) pos = (int64_t)((double)(pos_max - pos_min) * (double)(pts - pts_min) / (double)(pts_max - pts_min)) + pos_min - approximate_keyframe_distance; }else if(no_change==1){ // bisection, if interpolation failed to change min or max pos last time pos = (pos_min + pos_limit)>>1; }else{ // linear search if bisection failed, can only happen if there are very few or no keyframes between min/max pos=pos_min; } if(pos <= pos_min) pos= pos_min + 1; else if(pos > pos_limit) pos= pos_limit; start_pos= pos; // read the next timestamp cur_pts = asf_read_pts(s, &pos, stream_index); if(pos == pos_max) no_change++; else no_change=0; #ifdef DEBUG_SEEK printf("%Ld %Ld %Ld / %Ld %Ld %Ld target:%Ld limit:%Ld start:%Ld\n", pos_min, pos, pos_max, pts_min, cur_pts, pts_max, pts, pos_limit, start_pos); #endif assert (cur_pts != AV_NOPTS_VALUE); if (pts < cur_pts) { pos_limit = start_pos - 1; pos_max = pos; pts_max = cur_pts; } else { pos_min = pos; pts_min = cur_pts; /* check if we are lucky */ if (pts == cur_pts) break; } } pos = pos_min; url_fseek(&s->pb, pos*asf->packet_size + s->data_offset, SEEK_SET); asf_reset_header(s); return 0; } static AVInputFormat asf_iformat = { "asf", "asf format", sizeof(ASFContext), asf_probe, asf_read_header, asf_read_packet, asf_read_close, asf_read_seek, }; #ifdef CONFIG_ENCODERS static AVOutputFormat asf_oformat = { "asf", "asf format", "video/x-ms-asf", "asf,wmv", sizeof(ASFContext), #ifdef CONFIG_MP3LAME CODEC_ID_MP3, #else CODEC_ID_MP2, #endif CODEC_ID_MSMPEG4V3, asf_write_header, asf_write_packet, asf_write_trailer, }; static AVOutputFormat asf_stream_oformat = { "asf_stream", "asf format", "video/x-ms-asf", "asf,wmv", sizeof(ASFContext), #ifdef CONFIG_MP3LAME CODEC_ID_MP3, #else CODEC_ID_MP2, #endif CODEC_ID_MSMPEG4V3, asf_write_stream_header, asf_write_packet, asf_write_trailer, }; #endif //CONFIG_ENCODERS int asf_init(void) { av_register_input_format(&asf_iformat); #ifdef CONFIG_ENCODERS av_register_output_format(&asf_oformat); av_register_output_format(&asf_stream_oformat); #endif //CONFIG_ENCODERS return 0; } xmms-wma-1.0.5/ffmpeg-strip-wma/os_support.c0000644000175000017500000000311407727171267021334 0ustar whistlerwhistler/* * Various utilities for ffmpeg system * Copyright (c) 2000, 2001, 2002 Fabrice Bellard * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "avformat.h" #ifdef CONFIG_WIN32 #include #include #elif defined(CONFIG_OS2) #include #include #else #include #include #include #endif #include int64_t av_gettime(void) { #ifdef CONFIG_WIN32 struct _timeb tb; _ftime(&tb); return ((int64_t)tb.time * int64_t_C(1000) + (int64_t)tb.millitm) * int64_t_C(1000); #else struct timeval tv; gettimeofday(&tv,NULL); return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; #endif } #if !defined(HAVE_LOCALTIME_R) struct tm *localtime_r(const time_t *t, struct tm *tp) { struct tm *l; l = localtime(t); if (!l) return 0; *tp = *l; return tp; } #endif /* !defined(HAVE_LOCALTIME_R) */ xmms-wma-1.0.5/iir.c0000644000175000017500000001350410021437473014502 0ustar whistlerwhistler/* * PCM time-domain equalizer * * Copyright (C) 2002 Felipe Rivera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: iir.c,v 1.5 2003/09/10 21:53:08 liebremx Exp $ */ /* IIR filter coefficients */ #include "iir.h" /* History for two filters */ static sXYData data_history[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned)); static sXYData data_history2[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned)); /* Coefficients */ static sIIRCoefficients *iir_cf; /* Config EQ */ static int band_num = 10; /* Set num band: 10 - default in XMMS */ static int extra_filtering = 1; /* Set extra filtering: 0 - OFF, 1 - ON */ int round_trick(float floatvalue_to_round); /* Round function provided by Frank Klemm which saves around 100K * CPU cycles in my PIII for each call to the IIR function */ __inline__ int round_trick(float floatvalue_to_round) { float floattmp ; int rounded_value ; floattmp = (int) 0x00FD8000L + (floatvalue_to_round); rounded_value = *(int*)(&floattmp) - (int)0x4B7D8000L; if ( rounded_value != (short) rounded_value ) rounded_value = ( rounded_value >> 31 ) ^ 0x7FFF; return rounded_value; } /* Init the filter */ void init_iir() { iir_cf = iir_cforiginal10; /* Zero the history arrays */ bzero(data_history, sizeof(sXYData) * EQ_MAX_BANDS * EQ_CHANNELS); bzero(data_history2, sizeof(sXYData) * EQ_MAX_BANDS * EQ_CHANNELS); } __inline__ int iir(gpointer * d, gint length) { gint16 *data = (gint16 *) * d; /* Indexes for the history arrays * These have to be kept between calls to this function * hence they are static */ static gint i = 0, j = 2, k = 1; gint index, band, channel; gint tempgint, halflength; float out[EQ_CHANNELS], pcm[EQ_CHANNELS]; /** * IIR filter equation is * y[n] = 2 * (alpha*(x[n]-x[n-2]) + gamma*y[n-1] - beta*y[n-2]) * * NOTE: The 2 factor was introduced in the coefficients to save * a multiplication * * This algorithm cascades two filters to get nice filtering * at the expense of extra CPU cycles */ /* 16bit, 2 bytes per sample, so divide by two the length of * the buffer (length is in bytes) */ halflength = (length >> 1); for (index = 0; index < halflength; index+=2) { /* For each channel */ for (channel = 0; channel < EQ_CHANNELS; channel++) { /* No need to scale when processing the PCM with the filter */ pcm[channel] = data[index+channel]; /* Preamp gain */ pcm[channel] *= preamp[channel]; out[channel] = 0; /* For each band */ for (band = 0; band < band_num; band++) { /* Store Xi(n) */ data_history[band][channel].x[i] = pcm[channel]; /* Calculate and store Yi(n) */ data_history[band][channel].y[i] = ( /* = alpha * [x(n)-x(n-2)] */ iir_cf[band].alpha * ( data_history[band][channel].x[i] - data_history[band][channel].x[k]) /* + gamma * y(n-1) */ + iir_cf[band].gamma * data_history[band][channel].y[j] /* - beta * y(n-2) */ - iir_cf[band].beta * data_history[band][channel].y[k] ); /* * The multiplication by 2.0 was 'moved' into the coefficients to save * CPU cycles here */ /* Apply the gain */ out[channel] += data_history[band][channel].y[i]*gain[band][channel]; // * 2.0; } /* For each band */ if (extra_filtering) { /* Filter the sample again */ for (band = 0; band < band_num; band++) { /* Store Xi(n) */ data_history2[band][channel].x[i] = out[channel]; /* Calculate and store Yi(n) */ data_history2[band][channel].y[i] = ( /* y(n) = alpha * [x(n)-x(n-2)] */ iir_cf[band].alpha * (data_history2[band][channel].x[i] - data_history2[band][channel].x[k]) /* + gamma * y(n-1) */ + iir_cf[band].gamma * data_history2[band][channel].y[j] /* - beta * y(n-2) */ - iir_cf[band].beta * data_history2[band][channel].y[k] ); /* Apply the gain */ out[channel] += data_history2[band][channel].y[i]*gain[band][channel]; } /* For each band */ } /* Volume stuff Scale down original PCM sample and add it to the filters output. This substitutes the multiplication by 0.25 */ out[channel] += (data[index+channel]>>2); /* Round and convert to integer */ #ifdef X86 tempgint = round_trick(out[channel]); #else tempgint = (int)lroundf(out[channel]); #endif /* Limit the output */ if (tempgint < -32768) data[index+channel] = -32768; else if (tempgint > 32767) data[index+channel] = 32767; else data[index+channel] = tempgint; } /* For each channel */ i++; j++; k++; /* Wrap around the indexes */ if (i == 3) i = 0; else if (j == 3) j = 0; else k = 0; }/* For each pair of samples */ return length; } xmms-wma-1.0.5/readme.eng0000644000175000017500000000417710307135612015506 0ustar whistlerwhistler Plug-in of support of format WMA V1/V2 for players XMMS and BMP. XMMS-WMA/BEEPMP-WMA v.1.0.5 Stable Release. This plug-in is written using the ffmpeg library (http://ffmpeg.sf.net) written by Fabrice Bellard (to be exact, strongly advanced library). Everything besides wma format support were removed from it to make it more lite (it's widely known that ffmpeg eats about 10Mb of memory). Tags information converts from unicode to your system locale. There are some examples of console players written using the ffmpeg API in wma123_examples. Features implemented in the current version: - Tag conversion from unicode for your locale (using libiconv) support. - Positioning, it is possible to listen to a file from any desirable place. - A complete functional of playing, stop, pause and the information about files. - Equalizer support. That is not supported: - Playing on a network. That's not critical from wma though The license of distribution: - GPL v.2 Installation for XMMS: make make install (Installation for common usage) or make install-home (Installation for personal usage) Installation for BMP: make -f Makefile.bmp make -f Makefile.bmp install (Installation for common usage) or make -f Makefile.bmp install-home (Installation for personal usage) Stable branch: Changes in 1.0.1 - Small fix eliminating a problem of synchronization with clearing buffer, which in turn influenced operation of a pause and a stop of playback at strong loads of system. Changes in 1.0.2 - Small fix eliminating a problem of operation of positioning in a mode of a pause. Changes in 1.0.3 - In ffmpeg library possibility of mapping of the information type "Genre" is added. - Added README on English. Changes in 1.0.4 - Fix for high bitrates: Change size MAX_CODED_SUPERFRAME_SIZE in wma decoder Changes in 1.0.4.1 - Fix for compile gcc4. Changes in 1.0.5 - Added opportunity to build plug-in for player BMP. - Fix bug with blanks with use gnome-vfs in BMP. - WARNING: BEEPMP-WMA conflict with BMP-WMA. Remove BMP-WMA or do not use BEEPMP-WMA. Good Luck! (c) 2004,2005 Mokrushin I.V. aka McMCC http://mcmcc.bat.ru/xmms-wma/ xmms-wma-1.0.5/obj/0000755000175000017500000000000010307131204014310 5ustar whistlerwhistlerxmms-wma-1.0.5/obj/no_del!0000644000175000017500000000000010016754671015542 0ustar whistlerwhistlerxmms-wma-1.0.5/xmms-wma.c0000644000175000017500000004167010307124064015466 0ustar whistlerwhistler/* xmms-wma - WMA player for XMMS and BMP * * Copyright (C) 2004,2005 McMCC * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __XMMS_WMA_C__ #define __XMMS_WMA_C__ #include #include #include #include #include #include #ifdef BMP #include #include #include #include #else #include #include #include #include #endif #ifdef HAVE_AV_CONFIG_H #undef HAVE_AV_CONFIG_H #endif #include "avcodec.h" #include "avformat.h" #include "iir.h" #define ABOUT_TXT "Copyright (C) 2004,2005 Mokrushin I.V. aka McMCC (mcmcc@mail.ru).\n \ This plugin based on source code " LIBAVCODEC_IDENT "\nby Fabrice Bellard from \ http://ffmpeg.sourceforge.net.\n\n \ This program is free software; you can redistribute it and/or modify \n \ it under the terms of the GNU General Public License as published by \n \ the Free Software Foundation; either version 2 of the License, or \n \ (at your option) any later version. \n\n \ This program is distributed in the hope that it will be useful, \n \ but WITHOUT ANY WARRANTY; without even the implied warranty of \n \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n \ See the GNU General Public License for more details.\n" #ifdef BMP #define NAME "BEEPMP-WMA" #else #define NAME "XMMS-WMA" #endif #define VERSION "v.1.0.5" #define ST_BUFF 1024 static GtkWidget *dialog1, *button1, *label1; static GtkWidget *dialog, *button, *label; static gboolean wma_decode = 0; static gboolean wma_pause = 0; static gboolean wma_eq_on = 0; static int wma_seekpos = -1; static int wma_st_buff, wma_idx; static pthread_t wma_decode_thread; static pthread_mutex_t wma_mutex = PTHREAD_MUTEX_INITIALIZER; static AVCodecContext *c = NULL; static AVFormatContext *ic = NULL; static uint8_t *wma_outbuf, *wma_s_outbuf; char description[64]; static void wma_about(void); static void wma_init(void); static int wma_is_our_file(char *filename); static void wma_play_file(char *filename); static void wma_stop(void); static void wma_seek(int time); static void wma_do_pause(short p); static int wma_get_time(void); static void wma_get_song_info(char *filename, char **title, int *length); static void wma_file_info_box(char *filename); static void wma_set_eq(int q_on, float q_preamp, float *q_bands); static char *wsong_title; static int wsong_time; InputPlugin *get_iplugin_info(void); InputPlugin wma_ip = { NULL, // Filled in by xmms NULL, // Filled in by xmms description, // The description that is shown in the preferences box wma_init, // Called when the plugin is loaded wma_about, // Show the about box NULL, // Show the configure box wma_is_our_file, // Return 1 if the plugin can handle the file NULL, // Scan dir wma_play_file, // Play file wma_stop, // Stop wma_do_pause, // Pause wma_seek, // Seek wma_set_eq, // Set the equalizer, most plugins won't be able to do this wma_get_time, // Get the time, usually returns the output plugins output time NULL, // Get volume NULL, // Set volume NULL, // OBSOLETE! NULL, // OBSOLETE! NULL, // Send data to the visualization plugins NULL, // Fill in the stuff that is shown in the player window NULL, // Show some text in the song title box. Filled in by xmms wma_get_song_info, // Function to grab the title string wma_file_info_box, // Bring up an info window for the filename passed in NULL // Handle to the current output plugin. Filled in by xmms }; InputPlugin *get_iplugin_info(void) { memset(description, 0, 64); wma_ip.description = g_strdup_printf("WMA Player %s", VERSION); return &wma_ip; } #ifdef BMP static gchar *str_twenty_to_space(gchar * str) { gchar *match, *match_end; g_return_val_if_fail(str != NULL, NULL); while ((match = strstr(str, "%20"))) { match_end = match + 3; *match++ = ' '; while (*match_end) *match++ = *match_end++; *match = 0; } return str; } #endif static void wma_about(void) { char *title; char *message; if (dialog1) return; title = (char *)g_malloc(80); message = (char *)g_malloc(1000); memset(title, 0, 80); memset(message, 0, 1000); sprintf(title, "About %s", NAME); sprintf(message, "%s %s\n\n%s", NAME, VERSION, ABOUT_TXT); dialog1 = gtk_dialog_new(); gtk_signal_connect(GTK_OBJECT(dialog1), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog1); gtk_window_set_title(GTK_WINDOW(dialog1), title); gtk_window_set_policy(GTK_WINDOW(dialog1), FALSE, FALSE, FALSE); gtk_container_border_width(GTK_CONTAINER(dialog1), 5); label1 = gtk_label_new(message); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->vbox), label1, TRUE, TRUE, 0); gtk_widget_show(label1); button1 = gtk_button_new_with_label(" Close "); gtk_signal_connect_object(GTK_OBJECT(button1), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(dialog1)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->action_area), button1, FALSE, FALSE, 0); gtk_widget_show(button1); gtk_widget_show(dialog1); gtk_widget_grab_focus(button1); g_free(title); g_free(message); } static void wma_init(void) { avcodec_init(); avcodec_register_all(); av_register_all(); init_iir(); } static int wma_is_our_file(char *filename) { gchar *ext; ext = strrchr(filename, '.'); if(ext) if(!strcasecmp(ext, ".wma")) return 1; return 0; } static void wma_do_pause(short p) { wma_pause = p; wma_ip.output->pause(wma_pause); } static void wma_seek(int time) { wma_seekpos = time; if(wma_pause) wma_ip.output->pause(0); while(wma_decode && wma_seekpos!=-1) xmms_usleep(10000); if(wma_pause) wma_ip.output->pause(1); } static int wma_get_time(void) { wma_ip.output->buffer_free(); if(wma_decode) return wma_ip.output->output_time(); return -1; } static void wma_set_eq(int q_on, float q_preamp, float *q_bands) { int chn; int index; float value; wma_eq_on = q_on; if(wma_eq_on) { q_preamp = q_preamp/1.6; for(chn = 0; chn < c->channels; chn++) preamp[chn] = 1.0 + 0.0932471 * q_preamp + 0.00279033 * q_preamp * q_preamp; for(index = 0; index < 10; index++) { value = q_bands[index]/1.2; for(chn = 0; chn < c->channels; chn++) gain[index][chn] = 0.03 * value + 0.000999999 * value * value; } } } static gchar *extname(const char *filename) { gchar *ext = strrchr(filename, '.'); if(ext != NULL) ++ext; return ext; } static char *slashkill(gchar *fullname) { gchar *splitname = strrchr(fullname, '/'); if(splitname != NULL) ++splitname; return splitname; } static char* w_getstr(char* str) { if(str && strlen(str) > 0) return str; return NULL; } static gchar *get_song_title(AVFormatContext *in, gchar * filename) { gchar *ret = NULL; TitleInput *input; #ifdef BMP input = bmp_title_input_new(); #else XMMS_NEW_TITLEINPUT(input); #endif if((in->title[0] != '\0') || (in->author[0] != '\0') || (in->album[0] != '\0') || (in->comment[0] != '\0') || (in->genre[0] != '\0') || (in->year != 0) || (in->track != 0)) { input->performer = w_getstr(in->author); input->album_name = w_getstr(in->album); input->track_name = w_getstr(in->title); input->year = in->year; input->track_number = in->track; input->genre = w_getstr(in->genre); input->comment = w_getstr(in->comment); } #ifdef BMP input->file_name = g_path_get_basename(filename); input->file_path = g_path_get_dirname(filename); #else input->file_name = g_basename(filename); input->file_path = filename; #endif input->file_ext = extname(filename); ret = xmms_get_titlestring(xmms_get_gentitle_format(), input); if(input) g_free(input); if(!ret) { #ifdef BMP ret = g_strdup(input->file_name); #else ret = g_strdup(g_basename(filename)); #endif if (extname(ret) != NULL) *(extname(ret) - 1) = '\0'; } return ret; } static guint get_song_time(AVFormatContext *in) { if(in->duration) return in->duration/1000; else return 0; } static void wma_get_song_info(char *filename, char **title_real, int *len_real) { AVFormatContext *in = NULL; (*len_real) = -1; (*title_real) = NULL; #ifdef BMP if (av_open_input_file(&in, str_twenty_to_space(filename), NULL, 0, NULL) < 0) return; #else if (av_open_input_file(&in, filename, NULL, 0, NULL) < 0) return; #endif av_find_stream_info(in); (*len_real) = get_song_time(in); (*title_real) = get_song_title(in, filename); av_close_input_file(in); } static void wma_playbuff(int out_size) { FifoBuffer f; int sst_buff; fifo_init(&f, out_size*2); fifo_write(&f, wma_outbuf, out_size, &f.wptr); while(!fifo_read(&f, wma_s_outbuf, wma_st_buff, &f.rptr) && wma_decode) { if(wma_eq_on) sst_buff = iir((gpointer)&wma_s_outbuf, wma_st_buff); else sst_buff = wma_st_buff; if(wma_pause) memset(wma_s_outbuf, 0, sst_buff); while(wma_ip.output->buffer_free() < wma_st_buff) xmms_usleep(20000); if(wma_seekpos == -1) wma_ip.add_vis_pcm(wma_ip.output->written_time(), FMT_S16_NE, c->channels, sst_buff, (short *)wma_s_outbuf); wma_ip.output->write_audio((short *)wma_s_outbuf, sst_buff); memset(wma_s_outbuf, 0, sst_buff); } fifo_free(&f); return; } static void *wma_play_loop(void *arg) { uint8_t *inbuf_ptr; int out_size, size, len; AVPacket pkt; pthread_mutex_lock(&wma_mutex); while(wma_decode){ if(wma_seekpos != -1) { av_seek_frame(ic, wma_idx, wma_seekpos * 1000000LL); wma_ip.output->flush(wma_seekpos * 1000); wma_seekpos = -1; } if(av_read_frame(ic, &pkt) < 0) break; size = pkt.size; inbuf_ptr = pkt.data; if(size == 0) break; while(size > 0){ len = avcodec_decode_audio(c, (short *)wma_outbuf, &out_size, inbuf_ptr, size); if(len < 0) break; if(out_size <= 0) continue; wma_playbuff(out_size); size -= len; inbuf_ptr += len; if(pkt.data) av_free_packet(&pkt); } } while(wma_decode && wma_ip.output->buffer_playing()) xmms_usleep(30000); wma_decode = 0; if(wma_s_outbuf) g_free(wma_s_outbuf); if(wma_outbuf) g_free(wma_outbuf); if(pkt.data) av_free_packet(&pkt); if(c) avcodec_close(c); if(ic) av_close_input_file(ic); pthread_mutex_unlock(&wma_mutex); pthread_exit(NULL); } static void wma_play_file(char *filename) { AVCodec *codec; #ifdef BMP if(av_open_input_file(&ic, str_twenty_to_space(filename), NULL, 0, NULL) < 0) return; #else if(av_open_input_file(&ic, filename, NULL, 0, NULL) < 0) return; #endif for(wma_idx = 0; wma_idx < ic->nb_streams; wma_idx++) { c = &ic->streams[wma_idx]->codec; if(c->codec_type == CODEC_TYPE_AUDIO) break; } av_find_stream_info(ic); codec = avcodec_find_decoder(c->codec_id); if(!codec) return; if(avcodec_open(c, codec) < 0) return; wsong_title = get_song_title(ic, filename); wsong_time = get_song_time(ic); if(wma_ip.output->open_audio( FMT_S16_NE, c->sample_rate, c->channels) <= 0) return; wma_st_buff = ST_BUFF; wma_ip.set_info(wsong_title, wsong_time, c->bit_rate, c->sample_rate, c->channels); wma_s_outbuf = g_malloc0(wma_st_buff); wma_outbuf = g_malloc0(AVCODEC_MAX_AUDIO_FRAME_SIZE); wma_seekpos = -1; wma_decode = 1; pthread_create(&wma_decode_thread, NULL, wma_play_loop, NULL); } static void wma_stop(void) { wma_decode = 0; if(wma_pause) wma_do_pause(0); pthread_join(wma_decode_thread, NULL); wma_ip.output->close_audio(); } static void wma_file_info_box (char *filename) { char *title; char *tmp; char *message; AVFormatContext *in = NULL; AVCodecContext *s = NULL; AVCodec *codec; int tns, thh, tmm, tss, i; if(dialog) return; #ifdef BMP if(av_open_input_file(&in, str_twenty_to_space(filename), NULL, 0, NULL) < 0) return; #else if(av_open_input_file(&in, filename, NULL, 0, NULL) < 0) return; #endif for(i = 0; i < in->nb_streams; i++) { s = &in->streams[i]->codec; if(s->codec_type == CODEC_TYPE_AUDIO) break; } av_find_stream_info(in); codec = avcodec_find_decoder(s->codec_id); title = (char *)g_malloc(15); message = (char *)g_malloc(10000); tmp = (char *)g_malloc(256); memset(tmp, 0, 256); memset(title, 0, 15); memset(message, 0, 10000); strcpy(message, "\n\n\n"); strcat(message, "File Name: "); strcat(message, slashkill(filename)); strcat(message, "\n\n"); strcat(message, "Audio Info:\n"); strcat(message, "WMA Version: "); strcat(message, codec->name); strcat(message, "\n"); strcat(message, "Bitrate: "); sprintf(tmp, "%d", s->bit_rate / 1000); strcat(message, tmp); memset(tmp, 0, 256); strcat(message, " kb/s"); strcat(message, "\n"); strcat(message, "Samplerate: "); sprintf(tmp, "%d", s->sample_rate); strcat(message, tmp); memset(tmp, 0, 256); strcat(message, " Hz"); strcat(message, "\n"); strcat(message, "Channels: "); if(s->channels == 1) strcat(message, "MONO\n"); else strcat(message, "STEREO\n"); if (in->duration != 0) { tns = in->duration/1000000LL; thh = tns/3600; tmm = (tns%3600)/60; tss = (tns%60); strcat(message, "Play Time: "); sprintf(tmp, "%2d:%02d:%02d",thh, tmm, tss); strcat(message, tmp); memset(tmp, 0, 256); strcat(message, "\n"); } strcat(message, "\n"); strcat(message, "Text Info:\n"); if (in->title[0] != '\0') { strcat(message, "Title: "); strcat(message, in->title); strcat(message, "\n"); } if (in->author[0] != '\0') { strcat(message, "Author: "); strcat(message, in->author); strcat(message, "\n"); } if (in->album[0] != '\0') { strcat(message, "Album: "); strcat(message, in->album); strcat(message, "\n"); } if (in->year != 0) { strcat(message, "Year: "); sprintf(tmp, "%d", in->year); strcat(message, tmp); memset(tmp, 0, 256); strcat(message, "\n"); } if (in->track != 0) { strcat(message, "Track: "); sprintf(tmp, "%d", in->track); strcat(message, tmp); memset(tmp, 0, 256); strcat(message, "\n"); } if (in->genre[0] != '\0') { strcat(message, "Genre: "); strcat(message, in->genre); strcat(message, "\n"); } if (in->comment[0] != '\0') { strcat(message, "Comments: "); strcat(message, in->comment); strcat(message, "\n"); } if (in->copyright[0] != '\0') { strcat(message, "Copyright: "); strcat(message, in->copyright); strcat(message, "\n"); } strcat(message, "\n\n"); strcpy(title, "WMA file info:"); if(tmp) g_free(tmp); if(in) av_close_input_file(in); dialog = gtk_dialog_new(); gtk_signal_connect(GTK_OBJECT(dialog), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog); gtk_window_set_title(GTK_WINDOW(dialog), title); gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, FALSE); gtk_container_border_width(GTK_CONTAINER(dialog), 5); label = gtk_label_new(message); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0); gtk_widget_show(label); button = gtk_button_new_with_label(" Close "); gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(dialog)); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, FALSE, FALSE, 0); gtk_widget_show(button); gtk_widget_show(dialog); gtk_widget_grab_focus(button); g_free(title); g_free(message); } #endif xmms-wma-1.0.5/iir.h0000644000175000017500000000577010307036646014521 0ustar whistlerwhistler/* * PCM time-domain equalizer * * Copyright (C) 2002 Felipe Rivera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: iir.h,v 1.1 2003/05/21 13:59:59 liebremx Exp $ */ #ifndef IIR_H #define IIR_H #include #if 0 #include #include #include #endif #include #include #include #ifdef BMP /* BMP public headers */ #include #include #else /* XMMS public headers */ #include #include #endif #define EQ_MAX_BANDS 10 /* Number of channels (Stereo) */ #define EQ_CHANNELS 2 // Fixed Point Fractional bits #define FP_FRBITS 28 // Conversions #define EQ_REAL(x) ((gint)((x) * (1 << FP_FRBITS))) /* Floating point */ typedef struct { float beta; float alpha; float gamma; }sIIRCoefficients; /* Coefficient history for the IIR filter */ typedef struct { float x[3]; /* x[n], x[n-1], x[n-2] */ float y[3]; /* y[n], y[n-1], y[n-2] */ }sXYData; /* BETA, ALPHA, GAMMA */ static sIIRCoefficients iir_cforiginal10[] __attribute__((aligned)) = { { (9.9421504945e-01), (2.8924752745e-03), (1.9941421835e+00) }, /* 60.0 Hz */ { (9.8335039428e-01), (8.3248028618e-03), (1.9827686547e+00) }, /* 170.0 Hz */ { (9.6958094144e-01), (1.5209529281e-02), (1.9676601546e+00) }, /* 310.0 Hz */ { (9.4163923306e-01), (2.9180383468e-02), (1.9345490229e+00) }, /* 600.0 Hz */ { (9.0450844499e-01), (4.7745777504e-02), (1.8852109613e+00) }, /* 1000.0 Hz */ { (7.3940088234e-01), (1.3029955883e-01), (1.5829158753e+00) }, /* 3000.0 Hz */ { (5.4697667908e-01), (2.2651166046e-01), (1.0153238114e+00) }, /* 6000.0 Hz */ { (3.1023210589e-01), (3.4488394706e-01), (-1.8142472036e-01) }, /* 12000.0 Hz */ { (2.6718639778e-01), (3.6640680111e-01), (-5.2117742267e-01) }, /* 14000.0 Hz */ { (2.4201241845e-01), (3.7899379077e-01), (-8.0847117831e-01) }, /* 16000.0 Hz */ }; /* Gain for each band * values should be between -0.2 and 1.0 */ float gain[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned)); /* Volume gain * values should be between 0.0 and 1.0 * Use the preamp from XMMS for now * */ float preamp[EQ_CHANNELS] __attribute__((aligned)); __inline__ int iir(gpointer * d, gint length); void init_iir(); #endif /* #define IIR_H */ xmms-wma-1.0.5/Makefile.inc.bmp0000644000175000017500000000103410307116574016536 0ustar whistlerwhistlerCC := gcc CFLAGS := -O2 -ffast-math -fomit-frame-pointer -fPIC #CFLAGS := -Wall -g -O3 CFLAGS += -DBMP -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE CFLAGS += -I ffmpeg-strip-wma CFLAGS += `pkg-config bmp --cflags` LIBS := `pkg-config bmp --libs` -L ffmpeg-strip-wma -lffwma $(PLUGIN_FILE): $(OBJECTS) $(CC) -o $@ $^ $(LIBS) -shared $(OBJDIR)/%.o: %.c $(CC) -c -o $@ $(CFLAGS) $< $(DEPDIR)/%.d: %.c $(CC) -MM $(CFLAGS) $< | sed "s/^$*\.o:/$(OBJDIR)\/$*\.o $(DEPDIR)\/$*\.d:/" > $@ -include $(DEPS) xmms-wma-1.0.5/Makefile.bmp0000644000175000017500000000233510307061202015756 0ustar whistlerwhistler.PHONY: all install install-home uninstall uninstall-home clean INSTALL_DIR := /usr/lib/bmp/Input INSTALL_DIR_HOME := ~/.bmp/Plugins/Input export PLUGIN_FILE := libwma.so export OBJDIR := obj export DEPDIR := obj export SOURCES := xmms-wma.c iir.c export OBJECTS := $(SOURCES:%.c=$(OBJDIR)/%.o) export DEPS := $(SOURCES:%.c=$(DEPDIR)/%.d) all: @cd ffmpeg-strip-wma; make; cd .. @$(MAKE) --no-print-directory -f Makefile.inc.bmp @strip $(PLUGIN_FILE) @echo "The plug-in has been compiled. Run one of the following:" @echo "make install - for global (root) installation to $(INSTALL_DIR)" @echo "make install-home - for installation to home directory $(INSTALL_DIR_HOME)" install: all cp -f $(PLUGIN_FILE) $(INSTALL_DIR) @echo "The plug-in has been installed." @echo "Enjoy!" install-home: all -mkdir ~/.bmp -mkdir ~/.bmp/Plugins -mkdir ~/.bmp/Plugins/Input cp -f $(PLUGIN_FILE) $(INSTALL_DIR_HOME) @echo "The plug-in has been installed." @echo "Enjoy!" uninstall: rm -f $(INSTALL_DIR)/$(PLUGIN_FILE) @echo "The plug-in has been uninstalled." uninstall-home: rm -f $(INSTALL_DIR_HOME)/$(PLUGIN_FILE) @echo "The plug-in has been uninstalled." clean: cd ffmpeg-strip-wma; make clean; cd .. rm -f $(OBJECTS) $(DEPS) xmms-wma-1.0.5/COPYING0000644000175000017500000004311007304744461014612 0ustar whistlerwhistler GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. xmms-wma-1.0.5/xmms-wma.spec0000644000175000017500000000134010307136204016163 0ustar whistlerwhistler%define ver 1.0.5 %define rel 1 %define in_plugin_dir %(xmms-config --input-plugin-dir) Summary: xmms input plugin; wma format support Name: xmms-wma Version: %ver Release: %rel License: GPL Group: Applications/Multimedia Source: xmms-wma-%{ver}.tar.bz2 URL: http://mcmcc.bat.ru/xmms-wma Packager: Mokrushin I.V. aka McMCC Requires: xmms >= 1.0.1, gtk+ >= 1.2.2 BuildRoot: %{_tmppath}/%{name}-root %description It's a XMMS input plugin for support WMA format. %prep %setup %build make %install install -D -m 755 libwma.so %{buildroot}/%{in_plugin_dir}/libwma.so %clean [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT; %files %defattr(-,root,root) %doc readme.rus readme.eng COPYING %{in_plugin_dir}/libwma.so xmms-wma-1.0.5/Makefile0000644000175000017500000000233610021370036015203 0ustar whistlerwhistler.PHONY: all install install-home uninstall uninstall-home clean INSTALL_DIR := /usr/lib/xmms/Input INSTALL_DIR_HOME := ~/.xmms/Plugins/Input export PLUGIN_FILE := libwma.so export OBJDIR := obj export DEPDIR := obj export SOURCES := xmms-wma.c iir.c export OBJECTS := $(SOURCES:%.c=$(OBJDIR)/%.o) export DEPS := $(SOURCES:%.c=$(DEPDIR)/%.d) all: @cd ffmpeg-strip-wma; make; cd .. @$(MAKE) --no-print-directory -f Makefile.inc @strip $(PLUGIN_FILE) @echo "The plug-in has been compiled. Run one of the following:" @echo "make install - for global (root) installation to $(INSTALL_DIR)" @echo "make install-home - for installation to home directory $(INSTALL_DIR_HOME)" install: all cp -f $(PLUGIN_FILE) $(INSTALL_DIR) @echo "The plug-in has been installed." @echo "Enjoy!" install-home: all -mkdir ~/.xmms -mkdir ~/.xmms/Plugins -mkdir ~/.xmms/Plugins/Input cp -f $(PLUGIN_FILE) $(INSTALL_DIR_HOME) @echo "The plug-in has been installed." @echo "Enjoy!" uninstall: rm -f $(INSTALL_DIR)/$(PLUGIN_FILE) @echo "The plug-in has been uninstalled." uninstall-home: rm -f $(INSTALL_DIR_HOME)/$(PLUGIN_FILE) @echo "The plug-in has been uninstalled." clean: cd ffmpeg-strip-wma; make clean; cd .. rm -f $(OBJECTS) $(DEPS) xmms-wma-1.0.5/readme.rus0000644000175000017500000001067110307133541015541 0ustar whistlerwhistler Плагин поддержки формата WMA V1/V2 для плееров XMMS и BMP. XMMS-WMA/BEEPMP-WMA v.1.0.5 Stable Release Данный плагин написан с использованием библиотеки ffmpeg (http://ffmpeg.sf.net) автора Fabrice Bellard'а, если быть точным, то сильно переработанной библиотеки, из нее убраны все лишнее и оставлен только декодер формата wma, это сделано для того, что бы уменьшить размер самого бинарика после компиляции и уменьшить размер используемой памяти, ведь не секрет, что сам ffmpeg съедает 10-ки мегабайт в памяти, поэтому было принято решение провести "хирургическую операцию", по ходу дела была доработана часть работы с тэгами, теперь названия песен автоматически конвертятся из юникода в ту локаль, которая установлена в системе на данный момент, а так же убран неприятный эффект дублирующий название функции fft_init() в библиотеках xmms и ffmpeg, в урезанной ffmpeg она теперь имеет вид fft_inits()... В директории wma123_examples есть примеры простеньких консольных плееров с использованием API ffmpeg... Что сделано в текущей версии плагина: - Поддержка тэгов с конвертацией из unicode для вашей локали. - Позиционирование, можно слушать файл с любого желаемого места. - Полный функционал проигрывания, остановки, паузы и информации о файлах. - Поддержка эквалазера. Что не поддерживается: - Проигрывание по сети, думаю, что для wma это не критично... Лицензия распространения: - GPL v.2 Установка для XMMS: make make install (Установка для общего использования) или make install-home (Установка для личного использования) Установка для BMP: make -f Makefile.bmp make -f Makefile.bmp install (Установка для общего использования) или make -f Makefile.bmp install-home (Установка для личного использования) Деволоперская ветка для тестирования: Изменения в 0.1.1: - Небольшие исправления в коде и makefile Изменения в 0.1.2: - Устранена проблема воспроизведения с ALSA плагином, пришлось резать ровными кусками полученный поток с декодера по 4096 байт для стерео и 1024 байт для моно, затем их отсылать в буффер плагина sound'а. - В следствии уменьшения буффера полностью засинхронизирован поток для визуализации, теперь графический анализатор уровней и другие визуальные плагины синхронно попадают в ритм:)). Изменения в 0.1.3: - Сделана поддержка софтверного эквалазера, пришлось сделать небольшой откат, что в свою очередь немного улучшило работу плагина. Изменения в 0.1.4: - Добавлены примеры для написания проигрывателей WMA - небольшие фиксы и исправление бага связанного с iconv Изменения в 0.2: - Переработаны и разделены некоторые функции, удалось избавится от непрятного эффекта, который возникал при сильной нагрузки системы, перескакивания с проигрываемого файла сразу на другой, а также перепрыгивания в плейлисте... Изменения в 0.2.1 - Переодически возникают проблемы с перескакиваниями в плейлисте, пришлось увеличить задерку перед проигрыванием, так же увеличить размер для очистки буффера. Пока не знаю как побороть эту проблему:(((.... Изменения в 0.2.2 - Удалось победить прыгания по плейлисту, хотя точно не уверен в этом... Изменения в 1.0.0 (Релиз v.1.x.x) - Удалось исправить все проблемы:))), кто бы мог подумать, что все проблемы были из-за синхронизации, а именно из-за работы функции wma_get_time(). Вообщем решил не откладывать и выпустить первый стабильный релиз, т.к. практически все работает и доработки пока не требует;))).... Стабильная ветка: Изменения в 1.0.1 - Небольшой fix устраняющий проблему синхронизации с очисткой буффера, который в свою очередь влиял на работу паузы и остановки воспроизведения при сильной нагрузки системы. Изменения в 1.0.2 - Небольшой fix устраняющий проблему работы позиционирования в режиме паузы. Изменения в 1.0.3 - В ffmpeg библиотеку добавлена возможность отображения информации о Genre. - Добавлен README на английском. Изменения в 1.0.4 - Немного подчищен код - В WMA декодере найдена неточность, размер MAX_CODED_SUPERFRAME_SIZE оказался слишком маленьким на высоких битрейтах, это приводило к сильным искажениям, большое спасибо Marat'у . Изменения в 1.0.4.1 - Сделаны некоторые исправления для сборки с помощью gcc4. Изменения в 1.0.5 - Добавлена возможность сборки плагина для плеера BMP. - Устранен баг с пробелами при использовании gnome-vfs в BMP. - ВНИМАНИЕ: BEEPMP-WMA конфликтует с BMP-WMA. Удалите BMP-WMA или не используйте BEEPMP-WMA. Желаю Удачи! (c) 2004,2005 Мокрушин И.В. ака McMCC http://mcmcc.bat.ru/xmms-wma/ xmms-wma-1.0.5/beepmp-wma.spec0000644000175000017500000000144010307131423016446 0ustar whistlerwhistler%define ver 1.0.5 %define rel 1 %define in_plugin_dir %(pkg-config bmp --variable=input_plugin_dir) Summary: BMP input plugin; wma format support Name: beepmp-wma Version: %ver Release: %rel License: GPL Group: Applications/Multimedia Source: xmms-wma-%{ver}.tar.bz2 URL: http://mcmcc.bat.ru/xmms-wma Packager: Mokrushin I.V. aka McMCC Requires: bmp >= 0.9.7, gtk2 >= 2.0.1 Provides: bmp-wma BuildRoot: %{_tmppath}/%{name}-root %description It's a BMP input plugin for support WMA format. %prep %setup -n xmms-wma-%{ver} %build make -f Makefile.bmp %install install -D -m 755 libwma.so %{buildroot}/%{in_plugin_dir}/libwma.so %clean [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT; %files %defattr(-,root,root) %doc readme.rus readme.eng COPYING %{in_plugin_dir}/libwma.so xmms-wma-1.0.5/Makefile.inc0000644000175000017500000000102010307037224015746 0ustar whistlerwhistlerCC := gcc CFLAGS := -O2 -ffast-math -fomit-frame-pointer -fPIC #CFLAGS := -Wall -g -O3 CFLAGS += -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE CFLAGS += -I ffmpeg-strip-wma CFLAGS += `xmms-config --cflags` LIBS := `xmms-config --libs` -L ffmpeg-strip-wma -lffwma $(PLUGIN_FILE): $(OBJECTS) $(CC) -o $@ $^ $(LIBS) -shared $(OBJDIR)/%.o: %.c $(CC) -c -o $@ $(CFLAGS) $< $(DEPDIR)/%.d: %.c $(CC) -MM $(CFLAGS) $< | sed "s/^$*\.o:/$(OBJDIR)\/$*\.o $(DEPDIR)\/$*\.d:/" > $@ -include $(DEPS)