From 8d52474bc70c165c0cd4217af59d148ed810fa11 Mon Sep 17 00:00:00 2001 From: beveloper Date: Mon, 8 Dec 2003 22:16:03 +0000 Subject: [PATCH] a couple of fixes to the error handling code git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5631 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/media/MediaExtractor.cpp | 20 ++++++++++++-------- src/kits/media/MediaFile.cpp | 1 + src/kits/media/MediaTrack.cpp | 18 +++++++++++------- src/kits/media/PluginManager.cpp | 4 +++- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/kits/media/MediaExtractor.cpp b/src/kits/media/MediaExtractor.cpp index 72340f2c9c..31de2ef1b7 100644 --- a/src/kits/media/MediaExtractor.cpp +++ b/src/kits/media/MediaExtractor.cpp @@ -10,12 +10,13 @@ MediaExtractor::MediaExtractor(BDataIO * source, int32 flags) CALLED(); fSource = source; fStreamInfo = 0; - fStreamCount = 0; - fReader = 0; fErr = _CreateReader(&fReader, &fStreamCount, &fMff, source); - if (fErr) + if (fErr) { + fStreamCount = 0; + fReader = 0; return; + } fStreamInfo = new stream_info[fStreamCount]; @@ -162,19 +163,22 @@ status_t MediaExtractor::CreateDecoder(int32 stream, Decoder **decoder, media_codec_info *mci) { CALLED(); - if (fStreamInfo[stream].status != B_OK) { + status_t res; + + res = fStreamInfo[stream].status; + if (res != B_OK) { printf("MediaExtractor::CreateDecoder can't create decoder for stream %ld\n", stream); - return B_ERROR; + return res; } - if (B_OK != _CreateDecoder(decoder, mci, &fStreamInfo[stream].encodedFormat)) { + res = _CreateDecoder(decoder, mci, &fStreamInfo[stream].encodedFormat); + if (res != B_OK) { printf("MediaExtractor::CreateDecoder failed for stream %ld\n", stream); - return B_ERROR; + return res; } (*decoder)->Setup(this, stream); - status_t res; res = (*decoder)->Setup(&fStreamInfo[stream].encodedFormat, fStreamInfo[stream].infoBuffer , fStreamInfo[stream].infoBufferSize); if (res != B_OK) { printf("MediaExtractor::CreateDecoder Setup failed for stream %ld\n", stream); diff --git a/src/kits/media/MediaFile.cpp b/src/kits/media/MediaFile.cpp index 8987c22dda..1a6d029bf7 100644 --- a/src/kits/media/MediaFile.cpp +++ b/src/kits/media/MediaFile.cpp @@ -281,6 +281,7 @@ BMediaFile::InitReader(BDataIO *source, int32 flags) CALLED(); fSource = source; + fExtractor = new MediaExtractor(source, flags); fErr = fExtractor->InitCheck(); if (fErr) diff --git a/src/kits/media/MediaTrack.cpp b/src/kits/media/MediaTrack.cpp index 3d95ea938e..f08ba85b78 100644 --- a/src/kits/media/MediaTrack.cpp +++ b/src/kits/media/MediaTrack.cpp @@ -130,12 +130,13 @@ BMediaTrack::ReadFrames(void *out_buffer, if (!mh) mh = &temp_header; - *out_frameCount = 0; result = fDecoder->Decode(out_buffer, out_frameCount, mh, info); - - fCurFrame += *out_frameCount; - fCurTime = mh->start_time; - + if (result == B_OK) { + fCurFrame += *out_frameCount; + fCurTime = mh->start_time; + } else { + *out_frameCount = 0; + } return result; } @@ -452,13 +453,16 @@ BMediaTrack::BMediaTrack(BPrivate::media::MediaExtractor *extractor, CALLED(); fExtractor = extractor; fStream = stream; + fErr = B_OK; - if (B_OK != fExtractor->CreateDecoder(fStream, &fDecoder, &fMCI)) + if (fExtractor->CreateDecoder(fStream, &fDecoder, &fMCI) != B_OK) { + // we do not set fErr here, because ReadChunk should still work fDecoder = 0; + return; + } fCurFrame = 0; fCurTime = 0; - fErr = B_OK; // not used: fEncoder = 0; diff --git a/src/kits/media/PluginManager.cpp b/src/kits/media/PluginManager.cpp index af8f24e077..a92c1cf297 100644 --- a/src/kits/media/PluginManager.cpp +++ b/src/kits/media/PluginManager.cpp @@ -37,7 +37,9 @@ _CreateReader(Reader **reader, int32 *streamCount, media_file_format *mff, BData if (B_OK != (*reader)->Sniff(streamCount)) { printf("_CreateReader: Sniff failed\n"); - return B_ERROR; + _DestroyReader(*reader); + return B_MEDIA_NO_HANDLER; +// return B_ERROR; } (*reader)->GetFileFormatInfo(mff);