vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / media-add-ons / opensound / SupportFunctions.h
blobfc39606d7797b1f1f35b711b4d4a61b0665a7421
1 /*
2 * Copyright 2008 Stephan Aßmus, <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
4 */
5 #ifndef SUPPORT_FUNCTIONS_H
6 #define SUPPORT_FUNCTIONS_H
8 #include <MediaDefs.h>
10 static inline int32
11 bytes_per_frame(const media_format& format)
13 int32 channelCount = format.u.raw_audio.channel_count;
14 size_t sampleSize = format.u.raw_audio.format
15 & media_raw_audio_format::B_AUDIO_SIZE_MASK;
16 return sampleSize * channelCount;
20 static inline bigtime_t
21 time_for_buffer(size_t size, const media_format& format)
23 int32 frameSize = bytes_per_frame(format);
24 float frameRate = format.u.raw_audio.frame_rate;
26 return (bigtime_t)((double)size * 1000000 / frameSize / frameRate);
30 #endif // SUPPORT_FUNCTIONS_H