comparison mov.c @ 1014:90cb439ffca9 libavformat

fix sample size for uncompressed sound
author bcoudurier
date Tue, 14 Mar 2006 00:25:46 +0000
parents a149521570f8
children 32cfbb9cdbdd
comparison
equal deleted inserted replaced
1013:4abfc175a5d7 1014:90cb439ffca9
1194 1194
1195 sc->sample_count = entries; 1195 sc->sample_count = entries;
1196 #ifdef DEBUG 1196 #ifdef DEBUG
1197 av_log(NULL, AV_LOG_DEBUG, "sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count); 1197 av_log(NULL, AV_LOG_DEBUG, "sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count);
1198 #endif 1198 #endif
1199 if(sc->sample_size) 1199 if(sc->sample_size) {
1200 /* override sample size for uncompressed sound */
1201 switch (st->codec->codec_id) {
1202 case CODEC_ID_PCM_S32BE:
1203 case CODEC_ID_PCM_S32LE:
1204 sc->sample_size = 4 * st->codec->channels;
1205 break;
1206 case CODEC_ID_PCM_S24BE:
1207 case CODEC_ID_PCM_S24LE:
1208 sc->sample_size = 3 * st->codec->channels;
1209 break;
1210 case CODEC_ID_PCM_S16BE:
1211 case CODEC_ID_PCM_S16LE:
1212 sc->sample_size = 2 * st->codec->channels;
1213 break;
1214 case CODEC_ID_PCM_MULAW:
1215 case CODEC_ID_PCM_ALAW:
1216 case CODEC_ID_PCM_S8:
1217 case CODEC_ID_PCM_U8:
1218 sc->sample_size = 1 * st->codec->channels;
1219 break;
1220 default:
1221 break;
1222 }
1223 assert(sc->sample_size);
1200 return 0; /* there isn't any table following */ 1224 return 0; /* there isn't any table following */
1225 }
1201 sc->sample_sizes = (long*) av_malloc(entries * sizeof(long)); 1226 sc->sample_sizes = (long*) av_malloc(entries * sizeof(long));
1202 if (!sc->sample_sizes) 1227 if (!sc->sample_sizes)
1203 return -1; 1228 return -1;
1204 for(i=0; i<entries; i++) { 1229 for(i=0; i<entries; i++) {
1205 sc->sample_sizes[i] = get_be32(pb); 1230 sc->sample_sizes[i] = get_be32(pb);
1766 if (sc->sample_size > 0) { 1791 if (sc->sample_size > 0) {
1767 int foundsize=0; 1792 int foundsize=0;
1768 for(i=0; i<(sc->sample_to_chunk_sz); i++) { 1793 for(i=0; i<(sc->sample_to_chunk_sz); i++) {
1769 if( (sc->sample_to_chunk[i].first)<=(sc->next_chunk) ) 1794 if( (sc->sample_to_chunk[i].first)<=(sc->next_chunk) )
1770 { 1795 {
1771 // I can't figure out why for PCM audio sample_size is always 1 1796 foundsize=sc->sample_to_chunk[i].count*sc->sample_size;
1772 // (it should actually be channels*bits_per_second/8) but it is.
1773 AVCodecContext* cod = s->streams[sc->ffindex]->codec;
1774 if (sc->sample_size == 1 && (cod->codec_id == CODEC_ID_PCM_S16BE || cod->codec_id == CODEC_ID_PCM_S16LE))
1775 foundsize=(sc->sample_to_chunk[i].count*cod->channels*cod->bits_per_sample)/8;
1776 else
1777 foundsize=sc->sample_to_chunk[i].count*sc->sample_size;
1778 } 1797 }
1779 dprintf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id); 1798 dprintf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id);
1780 } 1799 }
1781 if( (foundsize>0) && (foundsize<size) ) 1800 if( (foundsize>0) && (foundsize<size) )
1782 { 1801 {