Changeset 25448

Show
Ignore:
Timestamp:
05/11/08 08:09:54 (5 days ago)
Author:
dlmcpaul
Message:
Hardcode IMA4 sound description
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • haiku/trunk/src/add-ons/media/plugins/mov_reader/libMOV/MOVFileReader.cpp

    r25444 r25448  
    458458                                // Hmm 16bit format 32 bit FourCC. 
    459459                                theAudio.compression = aSoundDescription.basefields.DataFormat; 
    460 //                              theAudio.compression = aSoundDescription.desc.CompressionID; 
    461460 
    462461                                theAudio.NoOfChannels = aSoundDescription.desc.NoOfChannels; 
    463462                                theAudio.SampleSize = aSoundDescription.desc.SampleSize; 
    464463                                theAudio.SampleRate = aSoundDescription.desc.SampleRate / 65536;        // Convert from fixed point decimal to float 
    465                                 theAudio.PacketSize = uint32((theAudio.SampleRate * theAudio.NoOfChannels * theAudio.SampleSize) / 8); 
     464 
     465                                if (aSoundDescription.bytesPerFrame == 0) { 
     466                                        // XXX probably not right 
     467                                        theAudio.FrameSize = aSoundDescription.desc.SampleSize / 8; 
     468                                } else { 
     469                                        theAudio.FrameSize = aSoundDescription.bytesPerFrame; 
     470                                } 
     471                                 
     472                                if (aSoundDescription.bytesPerPacket == 0) { 
     473                                        theAudio.BufferSize = uint32((theAudio.SampleSize * theAudio.NoOfChannels * theAudio.FrameSize) / 8); 
     474                                } else { 
     475                                        theAudio.BufferSize = aSoundDescription.bytesPerPacket; 
     476                                } 
     477                                 
     478                                theAudio.BitRate = theAudio.SampleSize * theAudio.NoOfChannels * theAudio.SampleRate; 
    466479 
    467480                                theAudio.theVOL = aSoundDescription.theVOL; 
  • haiku/trunk/src/add-ons/media/plugins/mov_reader/libMOV/MOVParser.cpp

    r17893 r25448  
    817817        Read(&aSoundDescriptionV1->desc.SampleRate); 
    818818 
    819         if (aSoundDescriptionV1->desc.Version == 1) { 
     819        if ((aSoundDescriptionV1->desc.Version == 1) && (aSoundDescriptionV1->basefields.DataFormat != AUDIO_IMA4)) { 
     820                printf("V1 Sound Description Found\n"); 
    820821                Read(&(aSoundDescriptionV1->samplesPerPacket)); 
    821822                Read(&(aSoundDescriptionV1->bytesPerPacket)); 
     
    825826        } else { 
    826827                // Calculate? 
    827                 aSoundDescriptionV1->bytesPerSample = aSoundDescriptionV1->desc.SampleSize / 8; 
    828                 if (aSoundDescriptionV1->basefields.DataFormat == 'ima4') { 
    829                         aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * 64 / 34; 
     828                if (aSoundDescriptionV1->basefields.DataFormat == AUDIO_IMA4) { 
     829                        printf("Calculating IMA4 Sound Description\n"); 
     830                        aSoundDescriptionV1->samplesPerPacket = 64; 
     831                        aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * 34; 
     832 
     833                        aSoundDescriptionV1->bytesPerSample = aSoundDescriptionV1->desc.SampleSize / 8; 
     834                        aSoundDescriptionV1->bytesPerPacket = 64 * aSoundDescriptionV1->bytesPerFrame; 
    830835                } else { 
     836                        printf("Calculating Sound Description\n"); 
     837                        aSoundDescriptionV1->bytesPerSample = aSoundDescriptionV1->desc.SampleSize / 8; 
    831838                        aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * aSoundDescriptionV1->bytesPerSample; 
    832                 } 
    833                 aSoundDescriptionV1->bytesPerPacket = aSoundDescriptionV1->desc.PacketSize; 
    834                 aSoundDescriptionV1->samplesPerPacket = aSoundDescriptionV1->desc.PacketSize / aSoundDescriptionV1->bytesPerFrame; 
     839                       aSoundDescriptionV1->bytesPerPacket = aSoundDescriptionV1->desc.PacketSize; 
     840                       aSoundDescriptionV1->samplesPerPacket = aSoundDescriptionV1->desc.PacketSize / aSoundDescriptionV1->bytesPerFrame; 
     841                } 
    835842        } 
    836843 
  • haiku/trunk/src/add-ons/media/plugins/mov_reader/libMOV/QTStructs.h

    r18488 r25448  
    106106struct AudioMetaData 
    107107{ 
    108         uint32 compression;             // compression used 
     108        uint32 compression;             // compression type used 
    109109        uint16 NoOfChannels;    // 1 = mono, 2 = stereo 
    110110        uint16 SampleSize;              // bits per sample 
    111         float SampleRate;               // Samples per second (OR Frames per second) 
    112         uint32 PacketSize;              // (Sample Rate * NoOfchannels * SampleSize)/8 = bytes per second 
     111        float SampleRate;               // Samples per second 
     112        uint32 BufferSize;              // (Sample Rate * NoOfchannels * SampleSize) / 8 = bytes per second 
     113        uint32 FrameSize;               // Size of a Frame (NoOfChannels * SampleSize) / 8 
     114        float BitRate;                  // Bitrate of audio 
    113115        uint8 *theVOL; 
    114116        size_t VOLSize; 
  • haiku/trunk/src/add-ons/media/plugins/mov_reader/mov_reader.cpp

    r25444 r25448  
    3535#include "mov_reader.h" 
    3636 
    37 //#define TRACE_MOV_READER 
     37#define TRACE_MOV_READER 
    3838#ifdef TRACE_MOV_READER 
    3939  #define TRACE printf 
     
    137137movReader::AllocateCookie(int32 streamNumber, void **_cookie) 
    138138{ 
     139        uint32 codecID; 
     140 
    139141        mov_cookie *cookie = new mov_cookie; 
    140142        *_cookie = cookie; 
     
    172174                        return B_ERROR; 
    173175                } 
     176 
     177                codecID = B_BENDIAN_TO_HOST_INT32(audio_format->compression); 
    174178 
    175179                cookie->frame_count = theFileReader->getAudioFrameCount(cookie->stream); 
     
    192196                        cookie->frames_per_sec_scale = 1; 
    193197                        TRACE("bytes_per_sec_rate %ld, bytes_per_sec_scale %ld (using rate)\n", cookie->bytes_per_sec_rate, cookie->bytes_per_sec_scale); 
    194                 } else if (audio_format->PacketSize) { 
    195                         cookie->bytes_per_sec_rate = audio_format->PacketSize; 
     198                } else if (audio_format->BufferSize) { 
     199                        cookie->bytes_per_sec_rate = audio_format->BufferSize; 
    196200                        cookie->bytes_per_sec_scale = 1; 
    197                         cookie->frames_per_sec_rate = audio_format->PacketSize * 8 / audio_format->SampleSize / audio_format->NoOfChannels; 
     201                        cookie->frames_per_sec_rate = audio_format->BufferSize * 8 / audio_format->SampleSize / audio_format->NoOfChannels; 
    198202                        cookie->frames_per_sec_scale = 1; 
    199203                        TRACE("bytes_per_sec_rate %ld, bytes_per_sec_scale %ld (using PacketSize)\n", cookie->bytes_per_sec_rate, cookie->bytes_per_sec_scale); 
     
    260264                        } 
    261265                         
     266                        format->u.raw_audio.byte_order = B_MEDIA_BIG_ENDIAN; 
     267 
     268                        if (audio_format->SampleSize <= 8) 
     269                                format->u.raw_audio.format = B_AUDIO_FORMAT_UINT8; 
     270                        else if (audio_format->SampleSize <= 16) 
     271                                format->u.raw_audio.format = B_AUDIO_FORMAT_INT16; 
     272                        else if (audio_format->SampleSize <= 24) 
     273                                format->u.raw_audio.format = B_AUDIO_FORMAT_INT24; 
     274                        else if (audio_format->SampleSize <= 32) 
     275                                format->u.raw_audio.format = B_AUDIO_FORMAT_INT32; 
     276                        else { 
     277                                ERROR("movReader::AllocateCookie: unhandled bits per sample %d\n", audio_format->SampleSize); 
     278                                return B_ERROR; 
     279                        } 
     280 
     281                        format->u.encoded_audio.frame_size = audio_format->FrameSize; 
     282                        format->u.encoded_audio.output.buffer_size = audio_format->BufferSize; 
     283 
     284                        TRACE("compression "); 
     285 
    262286                        switch (audio_format->compression) { 
    263287                                case AUDIO_MS_PCM02: 
     
    281305                                        break; 
    282306                                case AUDIO_IMA4: 
    283                                  
     307                                        TRACE("IMA4\n"); 
     308                                        format->u.encoded_audio.bit_rate = audio_format->BitRate; 
     309                                        format->u.encoded_audio.output.frame_rate = cookie->frames_per_sec_rate / cookie->frames_per_sec_scale;; 
     310                                        format->u.encoded_audio.output.channel_count = audio_format->NoOfChannels; 
     311                                        break; 
    284312                                default: 
    285                                         TRACE("OTHER\n"); 
     313                                        TRACE("OTHER %s\n",(char *)(&codecID)); 
    286314                                        format->u.encoded_audio.bit_rate = 8 * cookie->frames_per_sec_rate / cookie->frames_per_sec_scale; 
    287315                                        format->u.encoded_audio.output.frame_rate = cookie->frames_per_sec_rate / cookie->frames_per_sec_scale; 
     
    291319                } 
    292320 
    293                 // this doesn't seem to work (it's not even a fourcc) 
    294                 format->user_data_type = B_CODEC_TYPE_INFO; 
    295                 *(uint32 *)format->user_data = audio_format->compression; format->user_data[4] = 0; 
     321                TRACE("Audio NoOfChannels %d, SampleSize %d, SampleRate %f, FrameSize %ld\n",audio_format->NoOfChannels, audio_format->SampleSize, audio_format->SampleRate, audio_format->FrameSize); 
     322 
     323                TRACE("Audio frame_rate %f, channel_count %ld, format %ld, buffer_size %ld, frame_size %ld, bit_rate %f\n", 
     324                                format->u.encoded_audio.output.frame_rate, format->u.encoded_audio.output.channel_count, format->u.encoded_audio.output.format,format->u.encoded_audio.output.buffer_size, format->u.encoded_audio.frame_size, format->u.encoded_audio.bit_rate); 
    296325                 
    297326                // Some codecs have additional setup data that they need, put it in metadata 
     
    299328                const void *data = audio_format->theVOL; 
    300329                if (size > 0) { 
     330                        TRACE("VOL SIZE %ld\n", size); 
    301331                        format->SetMetaData(data, size); 
    302332                } 
    303  
    304 #ifdef TRACE_MOV_READER 
    305                 uint8 *p = 18 + (uint8 *)data; 
    306                 TRACE("extra_data: %ld: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 
    307                         size - 18, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9]); 
    308 #endif 
    309333         
    310334                return B_OK; 
     
    318342                        return B_ERROR; 
    319343                } 
     344                 
     345                codecID = B_BENDIAN_TO_HOST_INT32(video_format->compression); 
    320346                 
    321347                cookie->audio = false; 
     
    341367                TRACE("frame_count %Ld\n", cookie->frame_count); 
    342368                TRACE("duration %.6f (%Ld)\n", cookie->duration / 1E6, cookie->duration); 
    343                 TRACE("compression %s\n", (char *)(&video_format->compression)); 
     369                TRACE("compression %s\n", (char *)(&codecID)); 
    344370 
    345371                description.family = B_QUICKTIME_FORMAT_FAMILY;