diff --git a/src/add-ons/media/plugins/avi_reader/avi_reader.cpp b/src/add-ons/media/plugins/avi_reader/avi_reader.cpp index a915c0b302..b47c2b52fa 100644 --- a/src/add-ons/media/plugins/avi_reader/avi_reader.cpp +++ b/src/add-ons/media/plugins/avi_reader/avi_reader.cpp @@ -182,6 +182,16 @@ aviReader::AllocateCookie(int32 streamNumber, void **_cookie) // this doesn't seem to work (it's not even a fourcc) format->user_data_type = B_CODEC_TYPE_INFO; *(uint32 *)format->user_data = audio_format->format_tag; format->user_data[4] = 0; + + // put the wave_format_ex struct, including extra data, into the format meta data. + size_t size; + const void *data = fFile->AudioFormat(cookie->stream, &size); + format->SetMetaData(data, size); + + uint8 *p = 18 + (uint8 *)data; + printf("extra_data: %d: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", + size - 18, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9]); + return B_OK; } diff --git a/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLFile.cpp b/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLFile.cpp index 96419f1538..dfaa6db8ff 100644 --- a/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLFile.cpp +++ b/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLFile.cpp @@ -394,10 +394,15 @@ OpenDMLFile::AviMainHeader() } const wave_format_ex * -OpenDMLFile::AudioFormat(int stream_index) +OpenDMLFile::AudioFormat(int stream_index, size_t *size /* = 0*/) { - return (fStreamData[stream_index].info->is_audio && fStreamData[stream_index].info->audio_format_valid) ? - &fStreamData[stream_index].info->audio_format : 0; + if (!fStreamData[stream_index].info->is_audio) + return 0; + if (!fStreamData[stream_index].info->audio_format) + return 0; + if (size) + *size = fStreamData[stream_index].info->audio_format_size; + return fStreamData[stream_index].info->audio_format; } const bitmap_info_header * diff --git a/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLFile.h b/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLFile.h index 7cfea37e60..a8005556e3 100644 --- a/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLFile.h +++ b/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLFile.h @@ -21,7 +21,7 @@ public: const avi_main_header *AviMainHeader(); - const wave_format_ex * AudioFormat(int stream_index); + const wave_format_ex * AudioFormat(int stream_index, size_t *size = 0); const bitmap_info_header * VideoFormat(int stream_index); const avi_stream_header * StreamFormat(int stream_index); diff --git a/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLParser.cpp b/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLParser.cpp index 9a9782a22c..7a4c488be6 100644 --- a/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLParser.cpp +++ b/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLParser.cpp @@ -34,6 +34,7 @@ OpenDMLParser::OpenDMLParser() OpenDMLParser::~OpenDMLParser() { + // XXX free memory here! } int @@ -92,7 +93,7 @@ OpenDMLParser::CreateNewStreamInfo() info->is_audio = false; info->is_video = false; info->stream_header_valid = false; - info->audio_format_valid = false; + info->audio_format = 0; info->video_format_valid = false; info->odml_index_start = 0; info->odml_index_size = 0; @@ -397,7 +398,7 @@ OpenDMLParser::ParseChunk_strh(uint64 start, uint32 size) void OpenDMLParser::ParseChunk_strf(uint64 start, uint32 size) { - TRACE("OpenDMLParser::ParseChunk_strf\n"); + TRACE("OpenDMLParser::ParseChunk_strf, size %lu\n", size); if (fCurrentStream == 0) { TRACE("OpenDMLParser::ParseChunk_strf: error, no Stream info\n"); @@ -406,43 +407,47 @@ OpenDMLParser::ParseChunk_strf(uint64 start, uint32 size) if (fCurrentStream->is_audio) { - if (fCurrentStream->audio_format_valid) { + if (fCurrentStream->audio_format) { TRACE("OpenDMLParser::ParseChunk_strf: error, already have audio format header\n"); return; } - + // if (size < sizeof(fCurrentStream->audio_format)) { // TRACE("OpenDMLParser::ParseChunk_strf: warning, avi audio header chunk too small\n"); // } - - memset(&fCurrentStream->audio_format, 0, sizeof(fCurrentStream->audio_format)); - - size = min_c(size, sizeof(fCurrentStream->audio_format)); - if ((ssize_t)size != fSource->ReadAt(start, &fCurrentStream->audio_format, size)) { + + // if size to read is less then sizeof(wave_format_ex), allocate + // a full wave_format_ex and fill reminder with zero bytes + fCurrentStream->audio_format_size = max_c(sizeof(wave_format_ex), size); + fCurrentStream->audio_format = (wave_format_ex *) new char[fCurrentStream->audio_format_size]; + memset(size + (char *)fCurrentStream->audio_format, 0, fCurrentStream->audio_format_size - size); + + if ((ssize_t)size != fSource->ReadAt(start, fCurrentStream->audio_format, size)) { TRACE("OpenDMLParser::ParseChunk_strf: read error at pos %llu\n", start); + delete [] fCurrentStream->audio_format; + fCurrentStream->audio_format_size = 0; + fCurrentStream->audio_format = 0; return; } #if B_HOST_IS_BENDIAN - B_SWAP_INT16(&fCurrentStream->audio_format.format_tag); - B_SWAP_INT16(&fCurrentStream->audio_format.channels); - B_SWAP_INT32(&fCurrentStream->audio_format.frames_per_sec); - B_SWAP_INT32(&fCurrentStream->audio_format.avg_bytes_per_sec); - B_SWAP_INT32(&fCurrentStream->audio_format.block_align); - B_SWAP_INT32(&fCurrentStream->audio_format.bits_per_sample); - B_SWAP_INT32(&fCurrentStream->audio_format.extra_size); + B_SWAP_INT16(&fCurrentStream->audio_format->format_tag); + B_SWAP_INT16(&fCurrentStream->audio_format->channels); + B_SWAP_INT32(&fCurrentStream->audio_format->frames_per_sec); + B_SWAP_INT32(&fCurrentStream->audio_format->avg_bytes_per_sec); + B_SWAP_INT32(&fCurrentStream->audio_format->block_align); + B_SWAP_INT32(&fCurrentStream->audio_format->bits_per_sample); + B_SWAP_INT32(&fCurrentStream->audio_format->extra_size); #endif - fCurrentStream->audio_format_valid = true; - TRACE("audio_format:\n"); - TRACE("format_tag = 0x%x\n", fCurrentStream->audio_format.format_tag); - TRACE("channels = %u\n", fCurrentStream->audio_format.channels); - TRACE("frames_per_sec = %lu\n", fCurrentStream->audio_format.frames_per_sec); - TRACE("avg_bytes_per_sec = %lu\n", fCurrentStream->audio_format.avg_bytes_per_sec); - TRACE("block_align = %u\n", fCurrentStream->audio_format.block_align); - TRACE("bits_per_sample = %u\n", fCurrentStream->audio_format.bits_per_sample); - TRACE("extra_size = %u\n", fCurrentStream->audio_format.extra_size); + TRACE("format_tag = 0x%x\n", fCurrentStream->audio_format->format_tag); + TRACE("channels = %u\n", fCurrentStream->audio_format->channels); + TRACE("frames_per_sec = %lu\n", fCurrentStream->audio_format->frames_per_sec); + TRACE("avg_bytes_per_sec = %lu\n", fCurrentStream->audio_format->avg_bytes_per_sec); + TRACE("block_align = %u\n", fCurrentStream->audio_format->block_align); + TRACE("bits_per_sample = %u\n", fCurrentStream->audio_format->bits_per_sample); + TRACE("extra_size = %u\n", fCurrentStream->audio_format->extra_size); // XXX read extra data diff --git a/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLParser.h b/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLParser.h index 86558e7a00..7fefdf5aa1 100644 --- a/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLParser.h +++ b/src/add-ons/media/plugins/avi_reader/libOpenDML/OpenDMLParser.h @@ -11,8 +11,8 @@ struct stream_info bool is_video; bool stream_header_valid; avi_stream_header stream_header; - bool audio_format_valid; - wave_format_ex audio_format; + wave_format_ex *audio_format; + size_t audio_format_size; bool video_format_valid; bitmap_info_header video_format; int64 odml_index_start;