1 /* BSound.h */ 2 /* Copyright 1998 Be Incorporated. All rights reserved. */ 3 4 #if !defined(_SOUND_H) 5 #define _SOUND_H 6 7 #include <MediaDefs.h> 8 9 class BMediaFile; 10 class BSoundFile; 11 class BSoundPlayer; 12 struct entry_ref; 13 14 namespace BPrivate { 15 class BTrackReader; 16 } 17 18 class BSound { 19 public: 20 BSound( 21 void * data, 22 size_t size, 23 const media_raw_audio_format & format, 24 bool free_when_done = false); 25 BSound( 26 const entry_ref * sound_file, 27 bool load_into_memory = false); 28 29 status_t InitCheck(); 30 BSound * AcquireRef(); 31 bool ReleaseRef(); 32 int32 RefCount() const; // unreliable! 33 34 virtual bigtime_t Duration() const; 35 virtual const media_raw_audio_format & Format() const; 36 virtual const void * Data() const; /* returns NULL for files */ 37 virtual off_t Size() const; 38 39 virtual bool GetDataAt( 40 off_t offset, 41 void * into_buffer, 42 size_t buffer_size, 43 size_t * out_used); 44 45 protected: 46 47 BSound( 48 const media_raw_audio_format & format); 49 50 virtual status_t Perform( 51 int32 code, 52 ...); 53 54 private: 55 56 BSound(const BSound &); // unimplemented 57 BSound & operator=(const BSound &); // unimplemented 58 59 friend class BSoundPlayer; 60 friend class _HostApp; 61 62 void Reset(); 63 64 virtual ~BSound(); 65 66 void free_data(); 67 static status_t load_entry(void * arg); 68 void loader_thread(); 69 bool check_stop(); 70 71 public: 72 73 virtual status_t BindTo( 74 BSoundPlayer * player, 75 const media_raw_audio_format & format); 76 virtual status_t UnbindFrom( 77 BSoundPlayer * player); 78 79 private: 80 status_t _Reserved_Sound_0(void *); // BindTo 81 status_t _Reserved_Sound_1(void *); // UnbindFrom 82 virtual status_t _Reserved_Sound_2(void *); 83 virtual status_t _Reserved_Sound_3(void *); 84 virtual status_t _Reserved_Sound_4(void *); 85 virtual status_t _Reserved_Sound_5(void *); 86 87 void * _m_data; 88 BMediaFile * _m_file; 89 int32 _m_ref_count; 90 status_t _m_error; 91 size_t _m_size; 92 media_raw_audio_format _m_format; 93 bool _m_free_when_done; 94 bool _m_checkStopped; 95 bool _m_reserved[2]; 96 area_id _m_area; 97 sem_id _m_avail_sem; 98 sem_id _m_free_sem; 99 thread_id _m_loader_thread; 100 size_t _m_read_pos; 101 sem_id _m_check_token; 102 int32 _m_prev_sem_count; 103 104 BSoundPlayer * _m_bound_player; 105 int32 _m_bind_flags; 106 107 BPrivate::BTrackReader * _m_trackReader; 108 char m_tname[32]; 109 uint32 _reserved_[1]; 110 111 }; 112 113 114 #endif /* _SOUND_H */ 115