1 /* 2 * Copyright © 2000-2004 Ingo Weinhold <ingo_weinhold@gmx.de> 3 * Copyright © 2006-2008 Stephan Aßmus <superstippi@gmx.de> 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 #ifndef MEDIA_TRACK_AUDIO_SUPPLIER_H 7 #define MEDIA_TRACK_AUDIO_SUPPLIER_H 8 9 #include <List.h> 10 11 #include "AudioTrackSupplier.h" 12 13 class BMediaTrack; 14 struct media_codec_info; 15 struct media_format; 16 17 class MediaTrackAudioSupplier : public AudioTrackSupplier { 18 public: 19 MediaTrackAudioSupplier(BMediaTrack* track, 20 int32 trackIndex); 21 virtual ~MediaTrackAudioSupplier(); 22 23 virtual const media_format& Format() const; 24 virtual status_t GetEncodedFormat(media_format* format) const; 25 virtual status_t GetCodecInfo(media_codec_info* info) const; 26 virtual bigtime_t Duration() const; 27 28 // AudioReader interface 29 // (needed to reuse the class as AudioResampler input) 30 virtual status_t Read(void* buffer, int64 pos, int64 frames); 31 32 virtual status_t InitCheck() const; 33 34 virtual int32 TrackIndex() const 35 { return fTrackIndex; } 36 37 private: 38 struct Buffer; 39 void _InitFromTrack(); 40 41 int64 _FramesPerBuffer() const; 42 43 void _CopyFrames(void* source, int64 sourceOffset, 44 void* target, int64 targetOffset, 45 int64 position, int64 frames) const; 46 void _CopyFrames(Buffer* buffer, void* target, 47 int64 targetOffset, int64 position, 48 int64 frames) const; 49 50 void _AllocateBuffers(); 51 void _FreeBuffers(); 52 Buffer* _BufferAt(int32 index) const; 53 Buffer* _FindBufferAtFrame(int64 frame) const; 54 Buffer* _FindUnusedBuffer() const; 55 Buffer* _FindUsableBuffer() const; 56 Buffer* _FindUsableBufferFor(int64 position) const; 57 void _GetBuffersFor(BList& buffers, int64 position, 58 int64 frames) const; 59 void _TouchBuffer(Buffer* buffer); 60 61 status_t _ReadBuffer(Buffer* buffer, int64 position); 62 status_t _ReadBuffer(Buffer* buffer, int64 position, 63 bigtime_t time); 64 65 void _ReadCachedFrames(void*& buffer, 66 int64& position, int64& frames); 67 void _ReadCachedFrames(void*& buffer, 68 int64& position, int64& frames, 69 bigtime_t time); 70 71 status_t _ReadUncachedFrames(void* buffer, 72 int64 position, int64 frames); 73 status_t _ReadUncachedFrames(void* buffer, 74 int64 position, int64 frames, 75 bigtime_t time); 76 77 status_t _FindKeyFrameForward(int64& position); 78 status_t _FindKeyFrameBackward(int64& position); 79 status_t _SeekToKeyFrameForward(int64& position); 80 status_t _SeekToKeyFrameBackward(int64& position); 81 82 private: 83 BMediaTrack* fMediaTrack; 84 char* fBuffer; 85 int64 fBufferOffset; 86 int64 fBufferSize; 87 BList fBuffers; 88 bool fHasKeyFrames; 89 int64 fCountFrames; 90 bool fReportSeekError; 91 int32 fTrackIndex; 92 }; 93 94 #endif // MEDIA_TRACK_AUDIO_SUPPLIER_H 95