Version
menu_open
link
Wwise SDK 2018.1.11
AkStreamMgrModule.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
26 *******************************************************************************/
27 
28 /// \file
29 /// Audiokinetic's implementation-specific definitions and factory of
30 /// overridable Stream Manager module.
31 /// Contains the default Stream Manager's implementation-specific interfaces that altogether constitute
32 /// the Low-Level I/O submodule. This submodule needs to be implemented by the game. All I/O requests
33 /// generated by the Stream Manager end up to one of the I/O hooks defined herein.
34 /// Read \ref streamingmanager_lowlevel to learn more about the Low-Level I/O.
35 
36 #ifndef _AK_STREAM_MGR_MODULE_H_
37 #define _AK_STREAM_MGR_MODULE_H_
38 
41 
42 /// \name Audiokinetic Stream Manager's implementation-specific definitions.
43 //@{
44 /// Stream Manager initialization settings.
45 /// \sa
46 /// - AK::IAkStreamMgr
47 /// - AK::StreamMgr::Create()
48 /// - \ref streamingmanager_settings
49 
51 {
52  AkUInt32 uMemorySize; ///< Size of memory pool for small objects of Stream Manager.
53  ///< Small objects are the Stream Manager instance, devices,
54  ///< stream objects, user stream names, pending transfers,
55  ///< buffer records, pending open commands, and so on.
56  ///< Ideally, this pool should never run out of memory,
57  ///< because it may cause undesired I/O transfer
58  ///< cancellation, and even major CPU spikes. I/O memory should
59  ///< be bound by the size of each device's I/O pool instead.
60 };
61 
62 /// High-level IO devices initialization settings.
63 /// \sa
64 /// - AK::IAkStreamMgr
65 /// - AK::StreamMgr::CreateDevice()
66 /// - \ref streamingmanager_settings
68 {
69  void * pIOMemory; ///< Pointer for I/O memory allocated by user. This is fed directly to AK::MemoryMgr::CreatePool().
70  ///< Pass NULL if you want memory to be allocated by the MemoryMgr via AK alloc hooks.
71  ///< If specified, uIOMemorySize, uIOMemoryAlignment and ePoolAttributes are ignored.
72  AkUInt32 uIOMemorySize; ///< Size of memory pool for I/O (for automatic streams). It is passed directly to AK::MemoryMgr::CreatePool(), after having been rounded down to a multiple of uGranularity.
73  AkUInt32 uIOMemoryAlignment; ///< I/O memory pool alignment. It is passed directly to AK::MemoryMgr::CreatePool().
74  AkMemPoolAttributes ePoolAttributes; ///< Attributes for internal I/O memory pool. Note that these pools are always allocated internally as AkFixedSizeBlocksMode-style pools. Here, specify the block allocation type (AkMalloc, and so on). It is passed directly to AK::MemoryMgr::CreatePool().
75  AkUInt32 uGranularity; ///< I/O requests granularity (typical bytes/request).
76  AkUInt32 uSchedulerTypeFlags; ///< Scheduler type flags.
77  AkThreadProperties threadProperties; ///< Scheduler thread properties.
78  AkReal32 fTargetAutoStmBufferLength; ///< Targetted automatic stream buffer length (ms). When a stream reaches that buffering, it stops being scheduled for I/O except if the scheduler is idle.
79  AkUInt32 uMaxConcurrentIO; ///< Maximum number of transfers that can be sent simultaneously to the Low-Level I/O (applies to AK_SCHEDULER_DEFERRED_LINED_UP device only).
80  bool bUseStreamCache; ///< If true the device attempts to reuse IO buffers that have already been streamed from disk. This is particularly useful when streaming small looping sounds. The drawback is a small CPU hit when allocating memory, and a slightly larger memory footprint in the StreamManager pool.
81  AkUInt32 uMaxCachePinnedBytes; ///< Maximum number of bytes that can be "pinned" using AK::SoundEngine::PinEventInStreamCache() or AK::IAkStreamMgr::PinFileInCache()
82 };
83 
84 /// \name Scheduler type flags.
85 
86 /// Requests to Low-Level IO are synchronous. The streaming device expects a blocking I/O hook at creation time (IAkIOHookBlocking interface, see CreateDevice()).
87 /// Functions of this interface should return only when the transfer is complete.
88 #define AK_SCHEDULER_BLOCKING (0x01)
89 /// Requests to Low-Level IO are asynchronous, but posted one after the other, starting with streams that need data the most.
90 /// The streaming device expects a deferred I/O hook at creation time (IAkIOHookDeferred interface, see CreateDevice()).
91 /// Up to AkDeviceSettings::uMaxConcurrentIO requests can be sent to the Low-Level I/O at the same time.
92 #define AK_SCHEDULER_DEFERRED_LINED_UP (0x02)
93 
94 /// File descriptor. File identification for the low-level I/O.
95 /// \sa
96 /// - AK::StreamMgr::IAkLowLevelIOHook
97 struct AkFileDesc
98 {
99  AkInt64 iFileSize; ///< File size in bytes
100  AkUInt32 uSector; ///< Start sector (the sector size is specified by the low-level I/O)
101  ///< \sa
102  ///< - AK::StreamMgr::IAkFileLocationResolver::Open()
103  ///< - AK::StreamMgr::IAkLowLevelIOHook::GetBlockSize()
104  AkUInt32 uCustomParamSize; ///< Size of the custom parameter
105  void * pCustomParam; ///< Custom parameter
106  AkFileHandle hFile; ///< File handle/identifier
107  AkDeviceID deviceID; ///< Device ID, obtained from CreateDevice() \sa AK::IAkStreamMgr::CreateDevice()
108 };
109 
110 /// Structure for synchronous transfers handshaking with the Low-Level I/O. Used with blocking I/O hooks.
111 /// \sa AK::StreamMgr::IAkIOHookBlocking
113 {
114  AkUInt64 uFilePosition; ///< File offset where transfer should begin.
115  AkUInt32 uBufferSize; ///< Size of the buffer in which the I/O hook can write to.
116  AkUInt32 uRequestedSize; ///< Exact number of requested bytes for this transfer. Always equal to or smaller than uBufferSize.
117 };
118 
119 struct AkAsyncIOTransferInfo;
120 /// Callback function prototype definition used for asynchronous I/O transfers between the Stream Manager
121 /// and the Low-Level IO. Used with deferred I/O hooks.
122 /// Notes:
123 /// - If you return AK_Fail, all streams awaiting for this transfer are marked as invalid and will stop. An "IO error" notification is posted to the capture log.
124 /// - If the transfer was cancelled by the Stream Manager while it was in the Low-Level IO, you must return AK_Success, whether
125 /// you performed the operation or not. The Stream Manager knows that it was cancelled, so it will not try to use it after you call it back.
126 /// \sa
127 /// - AkAsyncIOTransferInfo
128 /// - AK::StreamMgr::IAkIOHookDeferred
130  AkAsyncIOTransferInfo * in_pTransferInfo, ///< Pointer to the AkAsyncIOTransferInfo structure that was passed to corresponding Read() or Write() call.
131  AKRESULT in_eResult ///< Result of transfer: AK_Success or AK_Fail (streams waiting for this transfer become invalid).
132  );
133 
134 /// Structure for asynchronous transfers handshaking with the Low-Level I/O. Extends AkIOTransferInfo.
135 /// \sa
136 /// - AK::StreamMgr::IAkIOHookDeferred
137 /// - AkIOTransferInfo
138 /// - AkAIOCallback
140 {
141  void * pBuffer; ///< Buffer for data transfer.
142  AkIOCallback pCallback; ///< Callback function used to notify the high-level device when the transfer is complete.
143  void * pCookie; ///< Reserved. The I/O device uses this cookie to retrieve the owner of the transfer.
144  void * pUserData; ///< Custom user data.
145 };
146 
147 /// Low-Level I/O requests heuristics.
148 /// Used for asynchronous read requests.
149 /// \sa
150 /// - AK::StreamMgr::IAkIOHookBlocking::Read()
151 /// - AK::StreamMgr::IAkIOHookBlocking::Write()
152 /// - AK::StreamMgr::IAkIOHookDeferred::Read()
153 /// - AK::StreamMgr::IAkIOHookDeferred::Write()
155 {
156  AkReal32 fDeadline; ///< Operation deadline (ms).
157  AkPriority priority; ///< Operation priority (at the time it was scheduled and sent to the Low-Level I/O). Range is [AK_MIN_PRIORITY,AK_MAX_PRIORITY], inclusively.
158 };
159 
160 
161 
162 //@}
163 
164 namespace AK
165 {
166  // Audiokinetic Stream Manager's implementation-specific interfaces of the Low-Level IO submodule.
167  namespace StreamMgr
168  {
169  /// Base interface for Low-Level I/O hooks. Defines common methods across both types of hooks.
171  {
172  protected:
173  /// Virtual destructor on interface to avoid warnings.
174  virtual ~IAkLowLevelIOHook(){}
175 
176  public:
177  /// Cleans up a file.
178  /// \return AK_Success if the file was properly cleaned-up.
179  virtual AKRESULT Close(
180  AkFileDesc & in_fileDesc ///< File descriptor.
181  ) = 0;
182 
183  /// Returns the block size for the file or its storage device.
184  /// The block size is a constraint for clients
185  /// of the Stream Manager: All reads, writes and position changes need to be a multiple of
186  /// that size.
187  /// \return
188  /// The block size for a specific file or storage device.
189  /// \remarks
190  /// - Some files might be opened with flags that require I/O transfers to be a multiple
191  /// of this size. The stream manager will query this function to resolve calls
192  /// to IAk(Auto)Stream::GetBlockSize( ).
193  /// - Also, AkFileDesc::uSector specifies a number of sectors in multiples of this value.
194  /// - Files/IO devices that do not require byte alignment should return 1.
195  /// - Whether file opening was deferred or not, GetBlockSize() is always called right
196  /// after the first call to Open(), in the client's thread, and is never called again.
197  /// \warning
198  /// Returning 0 is not allowed and will likely make the Stream Manager crash.
199  /// \sa
200  /// - AK::StreamMgr::IAkFileLocationResolver::Open()
201  /// - AK::StreamMgr::IAkIOHookBlocking::Read()
202  /// - AK::StreamMgr::IAkIOHookBlocking::Write()
203  /// - AK::StreamMgr::IAkIOHookDeferred::Read()
204  /// - AK::StreamMgr::IAkIOHookDeferred::Write()
205  virtual AkUInt32 GetBlockSize(
206  AkFileDesc & in_fileDesc ///< File descriptor.
207  ) = 0;
208 
209  /// Returns a description for the streaming device above this low-level hook.
210  /// \remarks For profiling purposes only. The Release configuration of the
211  /// Stream Manager never calls it.
212  virtual void GetDeviceDesc(
213  AkDeviceDesc & out_deviceDesc ///< Device description.
214  ) = 0;
215 
216  /// Returns custom profiling data for the streaming device above this low-level hook.
217  /// As opposed to GetDeviceDesc(), this is called at every monitoring frame.
218  /// You may implement this function in order to display any value you find useful
219  /// in the "Streaming Devices" tab of the Wwise profiler ("Custom Param" column).
220  /// \remarks For profiling purposes only. The Release configuration of the
221  /// Stream Manager never calls it.
222  /// \return A 32-bit unsigned value to display in the Wwise profiler.
223  virtual AkUInt32 GetDeviceData() = 0;
224  };
225 
226  /// Interface for blocking low-level I/O transfers. Used by streaming devices created with the
227  /// AK_SCHEDULER_BLOCKING flag.
228  /// This is the simplest I/O hook. Calls to Read()/Write() must block until they are completed.
229  /// The streaming device's I/O thread sends one transfer at a time.
231  {
232  protected:
233  /// Virtual destructor on interface to avoid warnings.
234  virtual ~IAkIOHookBlocking(){}
235 
236  public:
237 
238  /// Reads data from a file (synchronous).
239  /// Read data from the file described by in_fileDesc, in address out_pBuffer and with size and position
240  /// passed within io_transferInfo. When transfer is complete, return with the proper return code.
241  /// \remarks
242  /// File position passed in io_transferInfo takes the offset of this file relative
243  /// to AkFileDesc::hFile (described with AkFileDesc::uSector). It is computed by the high-level
244  /// device as "in_fileDesc.uSector * Block_Size + Stream_Position", where Block_Size is obtained
245  /// via AK::StreamMgr::IAkLowLevelIOHook::GetBlockSize().
246  /// \return
247  /// - AK_Success: transfer was successful and out_pBuffer is filled with data.
248  /// - AK_Fail: an error occured.
249  virtual AKRESULT Read(
250  AkFileDesc & in_fileDesc, ///< File descriptor.
251  const AkIoHeuristics & in_heuristics, ///< Heuristics for this data transfer.
252  void * out_pBuffer, ///< Buffer to be filled with data.
253  AkIOTransferInfo & in_transferInfo ///< Synchronous data transfer info.
254  ) = 0;
255 
256  /// Writes data to a file (synchronous).
257  /// Write data to the file described by in_fileDesc, from address in_pData and with size and position
258  /// passed within io_transferInfo. When transfer is complete, return with the proper return code.
259  /// \remarks File position passed in io_transferInfo takes the offset of this file relative
260  /// to AkFileDesc::hFile (described with AkFileDesc::uSector). It is computed by the high-level
261  /// device as "in_fileDesc.uSector * Block_Size + Stream_Position", where Block_Size is obtained
262  /// via AK::StreamMgr::IAkLowLevelIOHook::GetBlockSize().
263  /// \return
264  /// - AK_Success: transfer was successful.
265  /// - AK_Fail: an error occured.
266  virtual AKRESULT Write(
267  AkFileDesc & in_fileDesc, ///< File descriptor.
268  const AkIoHeuristics & in_heuristics, ///< Heuristics for this data transfer.
269  void * in_pData, ///< Data to be written.
270  AkIOTransferInfo & io_transferInfo ///< Synchronous data transfer info.
271  ) = 0;
272  };
273 
274  /// Interface for deferred low-level I/O transfers. Used by streaming devices created with the
275  /// AK_SCHEDULER_DEFERRED_LINED_UP flag.
276  /// This I/O transfer handshaking method is preferred when you want to hook I/O to your own
277  /// I/O streaming technology. You will receive up to AkDeviceSettings::uMaxConcurrentIO requests
278  /// at the same time. You may queue them into your own system, and even use the heuristics passed
279  /// down to this level for your convenience.
280  /// Note that the requests are always sent in the order that the Stream Manager considers to be
281  /// the most appropriate. You may receive less than AkDeviceSettings::uMaxConcurrentIO at any
282  /// given time. The number of concurrent transfers depends on the number of streams running in
283  /// the high-level streaming device, and on its target buffering length and granularity.
284  /// Your advantage at this level is to be aware of file placement, so you may try to re-order
285  /// requests in order to minimize seeking on disk.
286  /// Calls to Read()/Write() should return as soon as possible. You need to call
287  /// AkAsyncIOTransferInfo::pCallback as soon as a transfer is completed.
288  /// Cancel() is provided in order to inform you that the streaming device will flush this transfer
289  /// upon completion. You may implement it or not. In all cases, you must call the callback.
291  {
292  protected:
293  /// Virtual destructor on interface to avoid warnings.
294  virtual ~IAkIOHookDeferred(){}
295 
296  public:
297 
298  /// Reads data from a file (asynchronous).
299  /// \remarks
300  /// - Queue up your read request with address, size and file position specified in io_transferInfo.
301  /// - When transfer is complete (whether it was successful, cancelled or failed), call
302  /// AkAsyncIOTransferInfo::pCallback. However, if you return AK_Fail() from Read(), do not call
303  /// AkAsyncIOTransferInfo::pCallback.
304  /// - AkAsyncIOTransferInfo::pCookie must be passed to the callback function as-is. It must not
305  /// be changed by the Low-Level I/O.
306  /// - The reference to io_transferInfo will be valid until the high-level device is notified
307  /// through the callback.
308  /// - File position passed in io_transferInfo takes the offset of this file relative
309  /// to AkFileDesc::hFile (described with AkFileDesc::uSector). It is computed by the high-level
310  /// device as "in_fileDesc.uSector * Block_Size + Stream_Position", where Block_Size is obtained
311  /// via AK::StreamMgr::IAkLowLevelIOHook::GetBlockSize().
312  /// \return
313  /// - AK_Success: An I/O request was successfully processed and is pending:
314  /// AkAsyncIOTransferInfo::pCallback must be called when it completes.
315  /// - AK_Fail: an error occured.
316  virtual AKRESULT Read(
317  AkFileDesc & in_fileDesc, ///< File descriptor.
318  const AkIoHeuristics & in_heuristics, ///< Heuristics for this data transfer.
319  AkAsyncIOTransferInfo & io_transferInfo ///< Asynchronous data transfer info.
320  ) = 0;
321 
322  /// Writes data to a file (asynchronous).
323  /// \remarks
324  /// - Queue up your write request with address, size and file position specified in io_transferInfo.
325  /// - When transfer is complete (whether it was successful, cancelled or failed), call
326  /// AkAsyncIOTransferInfo::pCallback. However, if you return AK_Fail() from Write(), do not call
327  /// AkAsyncIOTransferInfo::pCallback.
328  /// - AkAsyncIOTransferInfo::pCookie must be passed to the callback function as-is. It must not
329  /// be changed by the Low-Level I/O.
330  /// - The reference to io_transferInfo will be valid until the high-level device is notified
331  /// through the callback.
332  /// - File position passed in io_transferInfo takes the offset of this file relative
333  /// to AkFileDesc::hFile (described with AkFileDesc::uSector). It is computed by the high-level
334  /// device as "in_fileDesc.uSector * Block_Size + Stream_Position", where Block_Size is obtained
335  /// via AK::StreamMgr::IAkLowLevelIOHook::GetBlockSize().
336  /// \return
337  /// - AK_Success: An I/O request was successfully processed and is pending:
338  /// AkAsyncIOTransferInfo::pCallback must be called when it completes.
339  /// - AK_Fail: an error occured.
340  virtual AKRESULT Write(
341  AkFileDesc & in_fileDesc, ///< File descriptor.
342  const AkIoHeuristics & in_heuristics, ///< Heuristics for this data transfer.
343  AkAsyncIOTransferInfo & io_transferInfo ///< Platform-specific asynchronous IO operation info.
344  ) = 0;
345 
346  /// Notifies that a transfer request is cancelled. It will be flushed by the streaming device when completed.
347  /// Cancellation is normal and happens regularly; for example, whenever a sound stops before the end
348  /// or stops looping. It happens even more frequently when buffering (AkDeviceSettings::fTargetAutoStmBufferLength
349  /// and AkDeviceSettings::uGranularity) is large and when you low-level IO hook accepts many concurrent requests
350  /// at the same time.
351  /// \remarks
352  /// - Cancel() simply informs the Low-Level I/O that a specific transfer will be flushed upon reception.
353  /// The Low-Level I/O may use this information to stop this transfer right away, or not (it is internally tagged
354  /// by the high-level device as cancelled). Nevertheless, the callback function MUST be called for cancelled
355  /// transfers to be resolved.
356  /// - When calling the callback function of a cancelled transfer, pass it *AK_Success*. Passing AK_Fail
357  /// to AkAsyncIOTransfer::pCallback has the effect of killing the stream once and for all. This is not
358  /// what you want.
359  /// - If io_bCancelAllTransfersForThisFile is set, you may cancel all transfers for this file at once.
360  /// Leave io_bCancelAllTransfersForThisFile to true if you don't want to be called again. For example, if
361  /// you don't do anything special in Cancel(), leave it to true. This will reduce the amount of useless calls.
362  /// If you set it to false, Cancel() will be called again for each remaining pending transfer that need to be cancelled.
363  /// - If io_bCancelAllTransfersForThisFile is not set, Cancel() is only called for a subset of pending
364  /// transfers for this file. You must not set it to true, as Cancel() needs to be called explicitly for each transfer that should be cancelled.
365  /// \warning
366  /// - The calling thread holds the stream's lock. You may call the callback function directly from here
367  /// (if you can guarantee that the I/O buffer will not be accessed in the meantime), but you must not wait here
368  /// for another thread to call the callback function.
369  /// - Likewise, if you resolve transfers with your own thread and use a lock to protect your transfers queue,
370  /// be careful not to run into a deadlock. Cancel() can be executed by any thread. Thus, if you need to lock your queue
371  /// in Cancel(), you must never hold this lock when calling back transfers, either from within Cancel() or from your
372  /// worker thread's routine. Lock your list, dequeue the transfer if you can, unlock, and call pCallback if and only if
373  /// the transfer was found and dequeued. On the other hand, if you choose not to do anything in Cancel(), the lock only protects
374  /// your list between Read()/Write() and your worker thread's routine, and since the device I/O thread does not hold the
375  /// stream's lock while calling Read()/Write(), your worker thread may therefore hold it while calling back transfers.
376  /// - A race condition exists when cancelling all transfers (io_bCancelAllTransfersForThisFile is true) directly from within this hook.
377  /// If you handle the io_bCancelAllTransfersForThisFile == true case, you need to defer calling the completion callback to later
378  /// (from your usual I/O completion thread, for example). This will be fixed in a future version of Wwise.
379  virtual void Cancel(
380  AkFileDesc & in_fileDesc, ///< File descriptor.
381  AkAsyncIOTransferInfo & io_transferInfo, ///< Transfer info to cancel.
382  bool & io_bCancelAllTransfersForThisFile ///< Flag indicating whether all transfers should be cancelled for this file (see notes in function description).
383  ) = 0;
384  };
385 
386  /// File location resolver interface. There is one and only one File Location Resolver that is
387  /// registered to the Stream Manager (using AK::StreamMgr::SetFileLocationResolver()). Its purpose
388  /// is to map a file name or ID to
389  /// 1) a streaming device / I/O hook;
390  /// 2) a valid file descriptor (AkFileDesc) usable by the I/O hook.
391  /// When your Low-Level I/O submodule uses a single device, you should create a standalone I/O
392  /// hook which implements one of the I/O hooks defined above (blocking or deferred), as well
393  /// as the File Location Resolver. You then register this object to the Stream Manager as the
394  /// File Location Resolver.
395  /// If you wish to create multiple devices, then you should have a separate object that implements
396  /// AK::StreamMgr::IAkFileLocationResolver and registers to the Stream Manager as such. This object
397  /// will be used to dispatch the file open request to the appropriate device. The strategy you will
398  /// use to select the correct device is up to you to implement. You may also implement a set of
399  /// hooks that delegate opening to the next device when they can't find the file requested
400  /// (like a chain of responsiblity pattern), although this will likely be less efficient.
402  {
403  protected:
404  /// Virtual destructor on interface to avoid warnings.
406 
407  public:
408 
409  /// Returns a file descriptor for a given file name (string).
410  /// Performs the operations needed to make the file descriptor usable by
411  /// the other methods of the interface (for e.g. ask the OS for a valid file handle).
412  /// \return
413  /// - AK_Success: A valid file descriptor is returned
414  /// - AK_FileNotFound: File was not found.
415  /// - AK_Fail: File could not be open for any other reason.
416  /// \return
417  /// - A file descriptor, which contains
418  /// - an unique identifier to be used with functions of the low-level IO
419  /// interface.
420  /// - the total stream size in bytes.
421  /// - the offset from the beginning of the file (in blocks).
422  /// - a device ID, that was obtained through AK::StreamMgr::CreateDevice().
423  /// - The updated io_bSyncOpen flag depending on the File Resolver's deferred opening policy.
424  /// \remarks
425  /// - The file descriptor is unique for each stream, and its address remains the same
426  /// throughout its lifetime. In other words, the value of &in_fileDesc inside Read() or
427  /// Close() is the same as &out_fileDesc in Open().
428  /// - Open() is always called first in the client thread.
429  /// - If io_bSyncOpen is true, file opening must be executed now. If it is false,
430  /// the File Location Resolver may choose whether it wants open it now, or later
431  /// from the streaming device's thread. If it wishes to open it now, then it must
432  /// set io_bSyncOpen to true. Otherwise, it needs to do the following: leave
433  /// io_bSyncOpen to false, clear out_fileDesc::iFileSize and out_fileDesc::uSector,
434  /// and set out_fileDesc::deviceID to the streaming device's ID that will handle
435  /// this file. By returning io_bSyncOpen as false, the Stream Manager will interpret
436  /// this as a request for deferred file opening, and this function will called again
437  /// from the streaming device's thread (this time, with this io_bSyncOpen set to true).
438  /// - All members of out_fileDesc will be cleared upon first call to Open().
439  /// \warning
440  /// - It is illegal to return io_bSyncOpen as false if Open() was called with io_bSyncOpen
441  /// set to true.
442  /// - Deferred file opening requires allocations in the Stream Manager's small object pool.
443  /// The File Location Resolver should always choose to open files synchronously if it is
444  /// fast to do so.
445  /// - Whether opening is deferred or not, GetBlockSize() is always called right after the
446  /// first call to Open(), in the client's thread, and is never called again.
447  /// \sa
448  /// - GetBlockSize()
449  /// - \ref streamingmanager_lowlevel_location
450  virtual AKRESULT Open(
451  const AkOSChar* in_pszFileName, ///< File name.
452  AkOpenMode in_eOpenMode, ///< Open mode.
453  AkFileSystemFlags * in_pFlags, ///< Special flags. Can pass NULL.
454  bool & io_bSyncOpen, ///< If true, the file must be opened synchronously. Otherwise it is left at the File Location Resolver's discretion. Return false if Open needs to be deferred.
455  AkFileDesc & io_fileDesc ///< Returned file descriptor.
456  ) = 0;
457 
458  /// Returns a file descriptor for a given file ID.
459  /// Performs the operations needed to make the file descriptor usable by
460  /// the other methods of the interface (for e.g. ask the OS for a valid file handle).
461  /// \return
462  /// - AK_Success: A valid file descriptor is returned
463  /// - AK_FileNotFound: File was not found.
464  /// - AK_Fail: File could not be open for any other reason.
465  /// \return
466  /// - A file descriptor, which contains
467  /// - an unique identifier to be used with functions of the low-level IO
468  /// interface.
469  /// - the total stream size in bytes.
470  /// - the offset of the beginning of the file (in blocks).
471  /// - a device ID, that was obtained through AK::StreamMgr::CreateDevice().
472  /// - A file descriptor, that contains
473  /// - an unique identifier to be used with functions of the low-level IO
474  /// interface.
475  /// - the total stream size in bytes.
476  /// - the offset from the beginning of the file (in blocks).
477  /// - a device ID, that was obtained through AK::StreamMgr::CreateDevice().
478  /// - The updated io_bSyncOpen flag depending on the File Resolver's deferred opening policy.
479  /// \remarks
480  /// - Open() is always called first in the client thread.
481  /// - If io_bSyncOpen is true, file opening must be executed now. If it is false,
482  /// the File Location Resolver may choose whether it wants open it now, or later
483  /// from the streaming device's thread. If it wishes to open it now, then it must
484  /// set io_bSyncOpen to true. Otherwise, it needs to do the following: leave
485  /// io_bSyncOpen to false, clear out_fileDesc::iFileSize and out_fileDesc::uSector,
486  /// and set out_fileDesc::deviceID to the streaming device's ID that will handle
487  /// this file. By returning io_bSyncOpen as false, the Stream Manager will interpret
488  /// this as a request for deferred file opening, and this function will called again
489  /// from the streaming device's thread (this time, with this io_bSyncOpen set to true).
490  /// - All members of out_fileDesc will be cleared upon first call to Open().
491  /// \warning
492  /// - It is illegal to return io_bSyncOpen as false if Open() was called with io_bSyncOpen
493  /// set to true.
494  /// - Deferred file opening requires allocations in the Stream Manager's small object pool.
495  /// The File Location Resolver should always choose to open files synchronously if it is
496  /// fast to do so.
497  /// - Whether opening is deferred or not, GetBlockSize() is always called right after the
498  /// first call to Open(), in the client's thread, and is never called again.
499  /// - GetBlockSize()
500  /// - \ref streamingmanager_lowlevel_location
501  virtual AKRESULT Open(
502  AkFileID in_fileID, ///< File ID.
503  AkOpenMode in_eOpenMode, ///< Open mode.
504  AkFileSystemFlags * in_pFlags, ///< Special flags. Can pass NULL.
505  bool & io_bSyncOpen, ///< If true, the file must be opened synchronously. Otherwise it is left at the File Location Resolver's discretion. Return false if Open needs to be deferred.
506  AkFileDesc & io_fileDesc ///< Returned file descriptor.
507  ) = 0;
508  };
509 
510  /// \name Audiokinetic implementation-specific Stream Manager factory.
511  //@{
512  /// Stream Manager factory.
513  /// \remarks
514  /// - In order for the Stream Manager to work properly, you also need to create
515  /// at least one streaming device (and implement its I/O hook), and register the
516  /// File Location Resolver with AK::StreamMgr::SetFileLocationResolver().
517  /// - Use AK::StreamMgr::GetDefaultSettings(), then modify the settings you want,
518  /// then feed this function with them.
519  /// \sa
520  /// - AK::IAkStreamMgr
521  /// - AK::StreamMgr::SetFileLocationResolver()
522  /// - AK::StreamMgr::GetDefaultSettings()
524  const AkStreamMgrSettings & in_settings ///< Stream manager initialization settings.
525  );
526 
527  /// Get the default values for the Stream Manager's settings.
528  /// \sa
529  /// - AK::StreamMgr::Create()
530  /// - AkStreamMgrSettings
531  /// - \ref streamingmanager_settings
533  AkStreamMgrSettings & out_settings ///< Returned AkStreamMgrSettings structure with default values.
534  );
535 
536  /// Get the one and only File Location Resolver registered to the Stream Manager.
537  /// \sa
538  /// - AK::StreamMgr::IAkFileLocationResolver
539  /// - AK::StreamMgr::SetFileLocationResolver()
540  AK_EXTERNAPIFUNC( IAkFileLocationResolver *, GetFileLocationResolver )();
541 
542  /// Register the one and only File Location Resolver to the Stream Manager.
543  /// \sa
544  /// - AK::StreamMgr::IAkFileLocationResolver
546  IAkFileLocationResolver * in_pFileLocationResolver ///< Interface to your File Location Resolver
547  );
548 
549  /// Get the Stream Manager's pool ID, created according to setting
550  /// AkStreamMgrSettings::uMemorySize.
551  /// \remarks This is the small objects pool, not one of the device ("Stream I/O") pools.
552  /// \sa
553  /// - AkStreamMgrSettings
554  /// - AK::StreamMgr::Create()
556 
557  //@}
558 
559  /// \name Stream Manager: High-level I/O devices management.
560  //@{
561  /// Streaming device creation.
562  /// Creates a high-level device, with specific settings.
563  /// You need to provide the associated low-level I/O hook, implemented on your side.
564  /// \return The device ID. AK_INVALID_DEVICE_ID if there was an error and it could not be created.
565  /// \warning
566  /// - This function is not thread-safe.
567  /// - Use a blocking hook (IAkIOHookBlocking) with SCHEDULER_BLOCKING devices, and a
568  /// deferred hook (IAkIOHookDeferred) with SCHEDULER_DEFERRED_LINED_UP devices (these flags are
569  /// specified in the device settings (AkDeviceSettings). The pointer to IAkLowLevelIOHook is
570  /// statically cast internally into one of these hooks. Implementing the wrong (or no) interface
571  /// will result into a crash.
572  /// \remarks
573  /// - You may use AK::StreamMgr::GetDefaultDeviceSettings() first to get default values for the
574  /// settings, change those you want, then feed the structure to this function.
575  /// - The returned device ID should be kept by the Low-Level IO, to assign it to file descriptors
576  /// in AK::StreamMgr::IAkFileLocationResolver::Open().
577  /// \sa
578  /// - AK::StreamMgr::IAkLowLevelIOHook
579  /// - AK::StreamMgr::GetDefaultDeviceSettings()
580  /// - \ref streamingmanager_settings
582  const AkDeviceSettings & in_settings, ///< Device settings.
583  IAkLowLevelIOHook * in_pLowLevelHook ///< Associated low-level I/O hook. Pass either a IAkIOHookBlocking or a IAkIOHookDeferred interface, consistent with the type of the scheduler.
584  );
585  /// Streaming device destruction.
586  /// \return AK_Success if the device was successfully destroyed.
587  /// \warning This function is not thread-safe. No stream should exist for that device when it is destroyed.
589  AkDeviceID in_deviceID ///< Device ID of the device to destroy.
590  );
591 
592  /// Get the default values for the streaming device's settings. Recommended usage
593  /// is to call this function first, then pass the settings to AK::StreamMgr::CreateDevice().
594  /// \sa
595  /// - AK::StreamMgr::CreateDevice()
596  /// - AkDeviceSettings
597  /// - \ref streamingmanager_settings
599  AkDeviceSettings & out_settings ///< Returned AkDeviceSettings structure with default values.
600  );
601  //@}
602 
603  /// \name Language management.
604  //@{
605  /// Set the current language once and only once, here. The language name is stored in a static buffer
606  /// inside the Stream Manager. In order to resolve localized (language-specific) file location,
607  /// AK::StreamMgr::IAkFileLocationResolver implementations query this string. They may use it to
608  /// construct a file path (for e.g. SDK/samples/SoundEngine/Common/AkFileLocationBase.cpp), or to
609  /// find a language-specific file within a look-up table (for e.g. SDK/samples/SoundEngine/Common/AkFilePackageLUT.cpp).
610  /// Pass a valid null-terminated string, without a trailing slash or backslash. Empty strings are accepted.
611  /// You may register for language changes (see RegisterToLanguageChangeNotification()).
612  /// After changing the current language, all observers are notified.
613  /// \return AK_Success if successful (if language string has less than AK_MAX_LANGUAGE_NAME_SIZE characters). AK_Fail otherwise.
614  /// \warning Not multithread safe.
615  /// \sa
616  /// - AK::StreamMgr::GetCurrentLanguage()
617  /// - AK::StreamMgr::AddLanguageChangeObserver()
619  const AkOSChar * in_pszLanguageName ///< Language name.
620  );
621 
622  /// Get the current language. The language name is stored in a static buffer inside the Stream Manager,
623  /// with AK::StreamMgr::SetCurrentLanguage(). In order to resolve localized (language-specific) file location,
624  /// AK::StreamMgr::IAkFileLocationResolver implementations query this string. They may use it to
625  /// construct a file path (for e.g. SDK/samples/SoundEngine/Common/AkFileLocationBase.cpp), or to
626  /// find a language-specific file within a look-up table (for e.g. SDK/samples/SoundEngine/Common/AkFilePackageLUT.cpp).
627  /// \return Current language.
628  /// \sa AK::StreamMgr::SetCurrentLanguage()
630 
631  /// Definition of handlers for language change notifications.
632  /// Called after SetCurrentLanguage() is called.
633  /// \warning Do not call AddLanguageChangeObserver or SetCurrentLanguage from within your handler.
634  /// \warning Not multithread safe.
635  /// \sa
636  /// - AK::StreamMgr::SetCurrentLanguage()
637  /// - AK::StreamMgr::AddLanguageChangeObserver()
639  const AkOSChar * const in_pLanguageName,///< New language name.
640  void * in_pCookie ///< Cookie that was passed to AddLanguageChangeObserver().
641  );
642 
643  /// Register to language change notifications.
644  /// \return AK_Success if successful, AK_Fail otherwise (no memory or no cookie).
645  /// \warning Not multithread safe.
646  /// \sa
647  /// - AK::StreamMgr::SetCurrentLanguage()
648  /// - AK::StreamMgr::RemoveLanguageChangeObserver()
650  AkLanguageChangeHandler in_handler, ///< Callback function.
651  void * in_pCookie ///< Cookie, passed back to AkLanguageChangeHandler. Must set.
652  );
653 
654  /// Unregister to language change notifications. Use the cookie you have passed to
655  /// AddLanguageChangeObserver() to identify the observer.
656  /// \warning Not multithread safe.
657  /// \sa
658  /// - AK::StreamMgr::SetCurrentLanguage()
659  /// - AK::StreamMgr::AddLanguageChangeObserver()
661  void * in_pCookie ///< Cookie that was passed to AddLanguageChangeObserver().
662  );
663 
664  /// \name Stream Manager: Cache management.
665  //@{
666  /// Flush cache of all devices. This function has no effect for devices where
667  /// AkDeviceSettings::bUseStreamCache was set to false (no caching).
668  /// \sa
669  /// - \ref streamingmanager_settings
670  AK_EXTERNAPIFUNC( void, FlushAllCaches )();
671 
672  //@}
673  }
674 }
675 
676 #endif //_AK_STREAM_MGR_MODULE_H_
virtual ~IAkIOHookBlocking()
Virtual destructor on interface to avoid warnings.
AkOpenMode
File open mode.
Definition: IAkStreamMgr.h:72
AkMemPoolAttributes
Definition: AkTypes.h:628
AkDeviceID deviceID
Device ID, obtained from CreateDevice()
AkUInt32 uBufferSize
Size of the buffer in which the I/O hook can write to.
#define AK_CALLBACK(__TYPE__, __NAME__)
virtual ~IAkLowLevelIOHook()
Virtual destructor on interface to avoid warnings.
void * pBuffer
Buffer for data transfer.
virtual AKRESULT Read(AkFileDesc &in_fileDesc, const AkIoHeuristics &in_heuristics, AkAsyncIOTransferInfo &io_transferInfo)=0
AkUInt32 uCustomParamSize
Size of the custom parameter.
virtual void Cancel(AkFileDesc &in_fileDesc, AkAsyncIOTransferInfo &io_transferInfo, bool &io_bCancelAllTransfersForThisFile)=0
AkUInt32 uGranularity
I/O requests granularity (typical bytes/request).
void(* AkIOCallback)(AkAsyncIOTransferInfo *in_pTransferInfo, AKRESULT in_eResult)
AKRESULT
Standard function call result.
Definition: AkTypes.h:126
AKRESULT __cdecl AddLanguageChangeObserver(AkLanguageChangeHandler in_handler, void *in_pCookie)
uint64_t AkUInt64
Unsigned 64-bit integer.
Definition: AkTypes.h:80
virtual AKRESULT Read(AkFileDesc &in_fileDesc, const AkIoHeuristics &in_heuristics, void *out_pBuffer, AkIOTransferInfo &in_transferInfo)=0
File system flags for file descriptors mapping.
Definition: IAkStreamMgr.h:81
Audiokinetic namespace.
Base interface for Low-Level I/O hooks. Defines common methods across both types of hooks.
virtual AKRESULT Write(AkFileDesc &in_fileDesc, const AkIoHeuristics &in_heuristics, AkAsyncIOTransferInfo &io_transferInfo)=0
AKRESULT __cdecl DestroyDevice(AkDeviceID in_deviceID)
AkUInt32 uMemorySize
virtual ~IAkFileLocationResolver()
Virtual destructor on interface to avoid warnings.
#define AK_EXTERNAPIFUNC(__TYPE__, __NAME__)
AkUInt32 uRequestedSize
Exact number of requested bytes for this transfer. Always equal to or smaller than uBufferSize.
AkUInt32 AkDeviceID
I/O device ID.
Definition: AkTypes.h:87
SceFiosFH AkFileHandle
File handle.
Definition: AkTypes.h:105
virtual AkUInt32 GetDeviceData()=0
void __cdecl FlushAllCaches()
AkDeviceID __cdecl CreateDevice(const AkDeviceSettings &in_settings, IAkLowLevelIOHook *in_pLowLevelHook)
void __cdecl RemoveLanguageChangeObserver(void *in_pCookie)
virtual AkUInt32 GetBlockSize(AkFileDesc &in_fileDesc)=0
IAkFileLocationResolver *__cdecl GetFileLocationResolver()
AkUInt32 uMaxCachePinnedBytes
Maximum number of bytes that can be "pinned" using AK::SoundEngine::PinEventInStreamCache() or AK::IA...
AkIOCallback pCallback
Callback function used to notify the high-level device when the transfer is complete.
AkUInt32 uIOMemorySize
Size of memory pool for I/O (for automatic streams). It is passed directly to AK::MemoryMgr::CreatePo...
void __cdecl SetFileLocationResolver(IAkFileLocationResolver *in_pFileLocationResolver)
AkMemPoolId __cdecl GetPoolID()
AkInt8 AkPriority
Priority.
Definition: AkTypes.h:77
AkMemPoolAttributes ePoolAttributes
Attributes for internal I/O memory pool. Note that these pools are always allocated internally as AkF...
bool bUseStreamCache
If true the device attempts to reuse IO buffers that have already been streamed from disk....
AkUInt64 uFilePosition
File offset where transfer should begin.
virtual ~IAkIOHookDeferred()
Virtual destructor on interface to avoid warnings.
void * pCustomParam
Custom parameter.
virtual AKRESULT Write(AkFileDesc &in_fileDesc, const AkIoHeuristics &in_heuristics, void *in_pData, AkIOTransferInfo &io_transferInfo)=0
virtual AKRESULT Open(const AkOSChar *in_pszFileName, AkOpenMode in_eOpenMode, AkFileSystemFlags *in_pFlags, bool &io_bSyncOpen, AkFileDesc &io_fileDesc)=0
void(* AkLanguageChangeHandler)(const AkOSChar *const in_pLanguageName, void *in_pCookie)
void * pUserData
Custom user data.
Device descriptor.
Definition: IAkStreamMgr.h:149
int64_t AkInt64
Signed 64-bit integer.
Definition: AkTypes.h:93
virtual void GetDeviceDesc(AkDeviceDesc &out_deviceDesc)=0
AKRESULT __cdecl SetCurrentLanguage(const AkOSChar *in_pszLanguageName)
void __cdecl GetDefaultDeviceSettings(AkDeviceSettings &out_settings)
AkReal32 fDeadline
Operation deadline (ms).
AkUInt32 AkFileID
Integer-type file identifier.
Definition: AkTypes.h:86
AkInt64 iFileSize
File size in bytes.
virtual AKRESULT Close(AkFileDesc &in_fileDesc)=0
AkUInt32 uSchedulerTypeFlags
Scheduler type flags.
AkReal32 fTargetAutoStmBufferLength
Targetted automatic stream buffer length (ms). When a stream reaches that buffering,...
void __cdecl GetDefaultSettings(AkStreamMgrSettings &out_settings)
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:79
const AkOSChar *__cdecl GetCurrentLanguage()
AkThreadProperties threadProperties
Scheduler thread properties.
void * pCookie
Reserved. The I/O device uses this cookie to retrieve the owner of the transfer.
float AkReal32
32-bit floating point
Definition: AkTypes.h:97
AkUInt32 uMaxConcurrentIO
Maximum number of transfers that can be sent simultaneously to the Low-Level I/O (applies to AK_SCHED...
char AkOSChar
Generic character string.
Definition: AkTypes.h:95
AkUInt32 uIOMemoryAlignment
I/O memory pool alignment. It is passed directly to AK::MemoryMgr::CreatePool().
AkPriority priority
Operation priority (at the time it was scheduled and sent to the Low-Level I/O). Range is [AK_MIN_PRI...
AkInt32 AkMemPoolId
Memory pool ID.
Definition: AkTypes.h:72
AkFileHandle hFile
File handle/identifier.
AkUInt32 uSector
IAkStreamMgr *__cdecl Create(const AkStreamMgrSettings &in_settings)

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise