From c1ee694618d533f533ead9a268714585f0af7c75 Mon Sep 17 00:00:00 2001 From: David McPaul Date: Mon, 13 Apr 2009 05:45:32 +0000 Subject: [PATCH] Add seeking support (my first commit from haiku) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30143 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/ape_reader/APEReader.cpp | 40 ++++++++++++------- .../media/plugins/ape_reader/APEReader.h | 6 ++- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/add-ons/media/plugins/ape_reader/APEReader.cpp b/src/add-ons/media/plugins/ape_reader/APEReader.cpp index b4b3be46c5..25e5e12c10 100644 --- a/src/add-ons/media/plugins/ape_reader/APEReader.cpp +++ b/src/add-ons/media/plugins/ape_reader/APEReader.cpp @@ -2,8 +2,8 @@ /*============================================================================*/ const char* gAppName = "APE (Monkey's Audio) reader"; -const char* gAppVer = "Ver 1.12"; -const char* gCright = "Copyright "B_UTF8_COPYRIGHT" 2005-2008 by SHINTA"; +const char* gAppVer = "Ver 1.13"; +const char* gCright = "Copyright "B_UTF8_COPYRIGHT" 2005-2009 by SHINTA"; const char* gAppSignature = "application/x-vnd.SHINTA-MediaKitAPEReader"; /*============================================================================*/ @@ -137,27 +137,39 @@ status_t TAPEReader::ReadBlocks() return B_OK; } //------------------------------------------------------------------------------ -status_t TAPEReader::Seek(void* oCookie, uint32 oFlags, int64* oFrame, bigtime_t* oTime) + +status_t TAPEReader::FindKeyFrame(void* cookie, uint32 flags, + int64* frame, bigtime_t* time) +{ + printf("FindKeyFrame for time %Ld or frame %Ld\n",*time,*frame); + if ( flags & B_MEDIA_SEEK_TO_FRAME ) { + *time = *frame * 1000 / mDecomp->GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS) * mDecomp->GetInfo(APE_DECOMPRESS_LENGTH_MS); + } else if ( flags & B_MEDIA_SEEK_TO_TIME ) { + *frame = (*time)/1000*mDecomp->GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS)/mDecomp->GetInfo(APE_DECOMPRESS_LENGTH_MS); + } else { + return B_ERROR; + } + + return B_OK; +} + +status_t TAPEReader::Seek(void *cookie, uint32 flags, + int64 *frame, bigtime_t *time) { - return B_ERROR; -#if 0 // not work in Haiku int32 aNewBlock; - if ( oFlags&B_MEDIA_SEEK_TO_FRAME ) { - DBEXP("TAPEReader::Seek()", "Seek by frame not supported yet"); - return B_ERROR; - } else if ( oFlags&B_MEDIA_SEEK_TO_TIME ) { - DBEXP("TAPEReader::Seek() - B_MEDIA_SEEK_TO_TIME", *oTime); - aNewBlock = (*oTime)/1000*mDecomp->GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS)/mDecomp->GetInfo(APE_DECOMPRESS_LENGTH_MS); - DBEXP("TAPEReader::Seek() - aNewBlock", aNewBlock); + printf("Seek for time %Ld or frame %Ld\n",*time,*frame); + if ( flags & B_MEDIA_SEEK_TO_FRAME ) { + aNewBlock = *frame; + } else if ( flags & B_MEDIA_SEEK_TO_TIME ) { + aNewBlock = (*time)/1000*mDecomp->GetInfo(APE_DECOMPRESS_TOTAL_BLOCKS)/mDecomp->GetInfo(APE_DECOMPRESS_LENGTH_MS); } else { return B_ERROR; } mReadPosTotal = aNewBlock*mDecomp->GetInfo(APE_INFO_BLOCK_ALIGN); - int a = mDecomp->Seek(aNewBlock); + mDecomp->Seek(aNewBlock); ReadBlocks(); return B_OK; -#endif } //------------------------------------------------------------------------------ status_t TAPEReader::Sniff(int32* oStreamCount) diff --git a/src/add-ons/media/plugins/ape_reader/APEReader.h b/src/add-ons/media/plugins/ape_reader/APEReader.h index 0c8e9e36b9..5400523841 100644 --- a/src/add-ons/media/plugins/ape_reader/APEReader.h +++ b/src/add-ons/media/plugins/ape_reader/APEReader.h @@ -31,7 +31,11 @@ public: virtual status_t GetStreamInfo(void* oCookie, int64* oFrameCount, bigtime_t* oDuration, media_format* oFormat, const void** oInfoBuffer, size_t* oInfoSize); - virtual status_t Seek(void* oCookie, uint32 oFlags, int64* oFrame, bigtime_t* oTime); + virtual status_t Seek(void *cookie, uint32 flags, + int64 *frame, bigtime_t *time); + + virtual status_t FindKeyFrame(void* cookie, uint32 flags, + int64* frame, bigtime_t* time); virtual status_t GetNextChunk(void* oCookie, const void** oChunkBuffer, size_t* oChunkSize, media_header* oMediaHeader);