From 24817be98a1a24196902e8b79a105b17f71c9199 Mon Sep 17 00:00:00 2001 From: shatty Date: Wed, 21 Jan 2004 09:09:43 +0000 Subject: [PATCH] media_decoder tuning: find first audio stream, errors for no tracks, do not bother with seek, add intermediary variables to assist in viewing functionality in bdb git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6208 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/media_decoder/media_decoder.cpp | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/tests/kits/media/media_decoder/media_decoder.cpp b/src/tests/kits/media/media_decoder/media_decoder.cpp index b61d066b2e..9ab8c0681a 100644 --- a/src/tests/kits/media/media_decoder/media_decoder.cpp +++ b/src/tests/kits/media/media_decoder/media_decoder.cpp @@ -19,7 +19,10 @@ public: protected: virtual status_t GetNextChunk(const void **chunkData, size_t *chunkLen, media_header *mh) { - return track->ReadChunk((char**)chunkData,(int32*)chunkLen,mh); + memset(mh,0,sizeof(media_header)); + status_t result = track->ReadChunk((char**)chunkData,(int32*)chunkLen,mh); + const void * data = *chunkData; + return result; } }; @@ -31,17 +34,32 @@ int main (int argc, const char ** argv) { fprintf(stderr,"%s: invalid usage\n",argv[0]); fprintf(stderr,"supply an input file and an output file:\n"); fprintf(stderr," media_decoder input.mp3 output.raw\n"); - return 0; + return -1; } - // open the file using BMediaFile/BMediaTrack + // open the file using BMediaFile BFile * file = new BFile(argv[1],B_READ_ONLY); BMediaFile * mf = new BMediaFile(file); - BMediaTrack * track = mf->TrackAt(0); - - // create a BMediaDecoder and initialize it + if (mf->CountTracks() == 0) { + fprintf(stderr,"no tracks found in %s\n",argv[1]); + return -1; + } media_format format; memset(&format,0,sizeof(format)); - track->EncodedFormat(&format); + // find an audio track + BMediaTrack * track = 0; + for (int i = 0; i < mf->CountTracks() ; i++) { + track = mf->TrackAt(i); + track->EncodedFormat(&format); + if (format.IsAudio()) { + break; + } + track = 0; + } + if (track == 0) { + fprintf(stderr,"no audio stream found in %s\n",argv[1]); + return -1; + } + // create a BMediaDecoder and initialize it FileDecoder * fd = new FileDecoder(track,&format); // fd->SetInputFormat(&format); memset(&format,0,sizeof(format)); @@ -51,10 +69,6 @@ int main (int argc, const char ** argv) { // open the output file BFile * file2 = new BFile(argv[2],B_WRITE_ONLY|B_CREATE_FILE|B_ERASE_FILE); - // be sure we are at the start - int64 frame = 0; - track->SeekToFrame(&frame,0); - // decode until we hit an error uint8 * buffer = new uint8[format.u.raw_audio.buffer_size]; int64 size = 0;