[AudioIO] Fixed AudioIOEnumerations file
authorchungryeol Lim <cdark.lim@samsung.com>
Fri, 10 Jun 2016 04:42:26 +0000 (13:42 +0900)
committerchungryeol Lim <cdark.lim@samsung.com>
Thu, 16 Jun 2016 06:39:46 +0000 (15:39 +0900)
Change-Id: If13b874affa4ee674cdb2773ad640fda6131c4db
Signed-off-by: chungryeol Lim <cdark.lim@samsung.com>
src/Tizen.Multimedia/AudioIO/AudioErrorHelper.cs [new file with mode: 0755]
src/Tizen.Multimedia/AudioIO/AudioIOEnumerations.cs [new file with mode: 0755]
src/Tizen.Multimedia/AudioIO/AudioInput.cs [new file with mode: 0755]
src/Tizen.Multimedia/AudioIO/AudioOutput.cs [new file with mode: 0755]
src/Tizen.Multimedia/AudioIO/AudioStateChangedEventArgs.cs [new file with mode: 0755]
src/Tizen.Multimedia/AudioIO/AudioStreamLengthChangedEventArgs.cs [new file with mode: 0755]
src/Tizen.Multimedia/AudioIO/BaseAudio.cs [new file with mode: 0755]
src/Tizen.Multimedia/Interop/Interop.AudioIO.cs [new file with mode: 0755]
src/Tizen.Multimedia/Interop/Interop.Libraries.cs [changed mode: 0644->0755]
src/Tizen.Multimedia/Tizen.Multimedia.csproj [changed mode: 0644->0755]

diff --git a/src/Tizen.Multimedia/AudioIO/AudioErrorHelper.cs b/src/Tizen.Multimedia/AudioIO/AudioErrorHelper.cs
new file mode 100755 (executable)
index 0000000..7445592
--- /dev/null
@@ -0,0 +1,57 @@
+using System;\r
+\r
+namespace Tizen.Multimedia\r
+{\r
+    internal class AudioErrorHelper\r
+    {\r
+        public static void Try(int errorCode)\r
+        {\r
+            AudioIOError code = (AudioIOError)errorCode;\r
+            // 현재는 에러코드 최상위 exception으로 전달, 추후 상황에 맞게 케이스 처리해야 함.\r
+            switch (code)\r
+            {\r
+                case AudioIOError.None:\r
+                    break;\r
+                case AudioIOError.OutOfMemory:\r
+                    Log.Info("Audio", "OutOfMemoryException");\r
+                    throw new OutOfMemoryException();\r
+                case AudioIOError.InvalidParameter:\r
+                    Log.Info("Audio", "ArgumentException");\r
+                    throw new ArgumentException();\r
+                case AudioIOError.InvalidOperation:\r
+                    Log.Info("Audio", "InvalidOperationException");\r
+                    throw new InvalidOperationException();\r
+                case AudioIOError.PermissionDenied:\r
+                    Log.Info("Audio", "Permission Denied Error");\r
+                    throw new Exception("Permission Denied Error");\r
+                case AudioIOError.NotSupported:\r
+                    Log.Info("Audio", "NotSupportedException");\r
+                    throw new NotSupportedException();\r
+                case AudioIOError.DevicePolicyRestriction:\r
+                    Log.Info("Audio", "Device_policy_restriction");\r
+                    throw new Exception("Device_policy_restriction");\r
+                case AudioIOError.DeviceNotOpened:\r
+                    Log.Info("Audio", "Device Not Opened Error");\r
+                    throw new Exception("Device Not Opened Error");\r
+                case AudioIOError.DeviceNotClosed:\r
+                    Log.Info("Audio", "Device Not Closed Error");\r
+                    throw new Exception("Device Not Closed Error");\r
+                case AudioIOError.InvalidBuffer:\r
+                    Log.Info("Audio", "Invalid Buffer Error");\r
+                    throw new InvalidOperationException("Invalid Buffer Error");\r
+                case AudioIOError.SoundPolicy:\r
+                    Log.Info("Audio", "Sound Policy Error");\r
+                    throw new Exception("Sound Policy Error");\r
+                case AudioIOError.InvalidState:\r
+                    Log.Info("Audio", "Invalid State Error");\r
+                    throw new Exception("Invalid State Error");\r
+                case AudioIOError.NotSupportedType:\r
+                    Log.Info("Audio", "Not supported stream type Error");\r
+                    throw new Exception("Not supported stream type Error");\r
+                default:\r
+                    Log.Info("Audio", "Unknown Exception" + code);\r
+                    throw new Exception("Unknown Exception");\r
+            } \r
+        }\r
+    }\r
+}\r
diff --git a/src/Tizen.Multimedia/AudioIO/AudioIOEnumerations.cs b/src/Tizen.Multimedia/AudioIO/AudioIOEnumerations.cs
new file mode 100755 (executable)
index 0000000..aa9a0b3
--- /dev/null
@@ -0,0 +1,34 @@
+using Tizen.Internals.Errors;\r
+\r
+namespace Tizen.Multimedia\r
+{\r
+    public enum AudioChannel\r
+    {\r
+        Mono = 0x80,            // 1 channel, mono\r
+        Stereo                  // 2 cahnnel, stereo\r
+    };\r
+\r
+    public enum AudioIOError\r
+    {\r
+        None = ErrorCode.None,                   // Successful\r
+        OutOfMemory = ErrorCode.OutOfMemory,          //Out of memory\r
+        InvalidParameter = ErrorCode.InvalidParameter,      //Invalid parameter\r
+        InvalidOperation = ErrorCode.InvalidOperation,      //Invalid operation\r
+        PermissionDenied = ErrorCode.PermissionDenied,      //Device open error by security\r
+        NotSupported = ErrorCode.NotSupported,          //Not supported\r
+        DevicePolicyRestriction = (-2147483648 / 2) + 4,\r
+        DeviceNotOpened = -0x01900000 | 0x01,      //Device open error\r
+        DeviceNotClosed = -0x01900000 | 0x02,      //Device close error\r
+        InvalidBuffer = -0x01900000 | 0x03,         //Invalid buffer pointer\r
+        SoundPolicy = -0x01900000 | 0x04,           //Sound policy error\r
+        InvalidState = -0x01900000 | 0x05,       //Invalid state (Since 3.0)\r
+        NotSupportedType = -0x01900000 | 0x06,  //Not supported stream type (Since 3.0)\r
+    };\r
+\r
+    public enum AudioState\r
+    {\r
+        Idle = 0,      /** Audio-io handle is created, but not prepared */\r
+        Running = 1,   /** Audio-io handle is ready and the stream is running */\r
+        Paused = 2    /** Audio-io handle is ready and the stream is paused */\r
+    };\r
+}\r
diff --git a/src/Tizen.Multimedia/AudioIO/AudioInput.cs b/src/Tizen.Multimedia/AudioIO/AudioInput.cs
new file mode 100755 (executable)
index 0000000..d358165
--- /dev/null
@@ -0,0 +1,228 @@
+using System;\r
+using System.Runtime.InteropServices;\r
+\r
+namespace Tizen.Multimedia\r
+{\r
+    /// <summary>\r
+    /// The Audio Input class provides a set of functions to directly manage the system audio input devices.\r
+    /// </summary>\r
+    public class AudioInput : BaseAudio\r
+    {\r
+        /// <summary>\r
+        /// Gets the sample rate of the audio input data stream. \r
+        /// </summary>\r
+        public override int SampleRate\r
+        {\r
+            get\r
+            {\r
+                int sampleRate;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioInput.GetSampleRate(_handle, out sampleRate));\r
+                return sampleRate;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the channel type of the audio input data stream. \r
+        /// The audio channel type defines whether the audio is mono or stereo.\r
+        /// </summary>\r
+        public override AudioChannel Channel\r
+        {\r
+            get\r
+            {\r
+                int channel;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioInput.GetChannel(_handle, out channel));\r
+                return (AudioChannel)channel;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Gets the sample audio format (8-bit or 16-bit) of the audio input data stream.\r
+        /// </summary>\r
+        public override AudioSampleType SampleType\r
+        {\r
+            get\r
+            {\r
+                int type;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioInput.GetSampleType(_handle, out type));\r
+                return (AudioSampleType)type;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the size to be allocated for the audio input buffer. \r
+        /// </summary>\r
+        public override int BufferSize\r
+        {\r
+            get\r
+            {\r
+                int size;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioInput.GetBufferSize(_handle, out size));\r
+                return size;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Reads audio data from the audio input buffer. \r
+        /// </summary>\r
+        /// <param name="length"></param>\r
+        /// <returns>The buffer of audio data receiving an input</returns>\r
+        public byte[] Read(int length)\r
+        {\r
+            byte[] dataArray = new byte[length];\r
+\r
+            if (dataArray.Length <= 0)\r
+                throw new IndexOutOfRangeException("Bed Buffer Length");\r
+\r
+            IntPtr ptrByteArray = Marshal.AllocHGlobal(length);\r
+            try\r
+            {\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Read(_handle, ptrByteArray, length));\r
+                Marshal.Copy(ptrByteArray, dataArray, 0, dataArray.Length);\r
+            }\r
+            catch (Exception e)\r
+            {\r
+                Log.Info("Audio", "Read Exception : " + e.ToString());\r
+                Console.WriteLine("read error" + e.ToString());\r
+            }\r
+            finally\r
+            {\r
+                if (ptrByteArray != IntPtr.Zero)\r
+                {\r
+                    Marshal.FreeHGlobal(ptrByteArray);\r
+                    ptrByteArray = IntPtr.Zero;\r
+                }\r
+            }\r
+            return dataArray;\r
+        }\r
+        /// <summary>\r
+        /// peek from audio in buffer \r
+        /// This function works correctly only with read, write callback.Otherwise it won't operate as intended.\r
+        /// </summary>\r
+        /// <param name="length"></param>\r
+        /// <returns> The allocated buffer - byte[] </returns>\r
+        public byte[] Peek(uint length)\r
+        {\r
+            IntPtr ptrByteArray = IntPtr.Zero;\r
+            uint nBytes = 0;\r
+            try\r
+            {\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Peek(_handle, out ptrByteArray, out nBytes));\r
+                byte[] dataArray = new byte[nBytes];\r
+                Marshal.Copy(ptrByteArray, dataArray, 0, (int)nBytes);\r
+\r
+                return dataArray;\r
+            }\r
+            finally\r
+            {\r
+                if (ptrByteArray != IntPtr.Zero)\r
+                {\r
+                    ptrByteArray = IntPtr.Zero;\r
+                }\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// drop peeked audio buffer. \r
+        /// This function works correctly only with read, write callback.Otherwise it won't operate as intended.\r
+        /// </summary>\r
+        public void Drop()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Drop(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Releases the audio input handle and all its resources associated with an audio stream.\r
+        /// </summary>\r
+        protected override void Destroy()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Destroy(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Sets an asynchronous(event) callback function to handle recording PCM (pulse-code modulation) data. \r
+        /// </summary>\r
+        protected override void RegisterAudioStreamLengthChanged()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.SetAudioInputStreamChangedCallback(_handle, OnStream, IntPtr.Zero));\r
+        }\r
+        /// <summary>\r
+        /// Unregisters the callback function. \r
+        /// </summary>\r
+        protected override void UnregisterAudioStreamLengthChanged()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.UnsetAudioInputStreamChangedCallback(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Sets the state changed callback function to the audio input handle. \r
+        /// </summary>\r
+        protected override void RegisterAudioStateChangedCallback()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.SetAudioInputStateChangedCallback(_handle, OnStateChanged, IntPtr.Zero));\r
+        }\r
+        /// <summary>\r
+        /// Unregisters the state changed callback function of the audio input handle. \r
+        /// </summary>\r
+        protected override void UnregisterAudioStateChangedmCallback()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.UnsetAudioInputStateChangedCallback(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Prepares the audio input for reading audio data by starting buffering of audio data from the device. \r
+        /// </summary>\r
+        public override void Prepare()\r
+        {\r
+            if(_bReady == false)\r
+            {\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Prepare(_handle));\r
+                _bReady = true;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Unprepares the audio input. \r
+        /// </summary>\r
+        public override void Unprepare()\r
+        {\r
+            if (_bReady)\r
+            {\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Unprepare(_handle));\r
+                _bReady = false;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Pauses buffering of audio data from the device. \r
+        /// </summary>\r
+        public override void Pause()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Pause(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Resumes buffering audio data from the device. \r
+        /// </summary>\r
+        public override void Resume()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Resume(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Flushes and discards buffered audio data from the input stream. \r
+        /// </summary>\r
+        public override void Flush()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Flush(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Sets the sound stream information to the audio input. \r
+        /// </summary>\r
+        /// <param name="stream_info"></param>\r
+        /// <returns></returns>\r
+        public override void SetStreamInfo(AudioStreamPolicy streamPolicy)\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.SetStreamInfo(_handle, streamPolicy.Handle));\r
+        }\r
+        /// <summary>\r
+        /// Initializes the instance of the AudioInput class with the SafeAudioInputHandle.\r
+        /// </summary>\r
+        /// <param name="_sample_rate"></param>\r
+        /// <param name="_channel"></param>\r
+        /// <param name="_type"></param>\r
+        public AudioInput(int sample_rate, AudioChannel channel, AudioSampleType type)\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioInput.Create(sample_rate, (int)channel, (int)type, out _handle));\r
+        }\r
+        private AudioInput() { }\r
+    }\r
+}\r
diff --git a/src/Tizen.Multimedia/AudioIO/AudioOutput.cs b/src/Tizen.Multimedia/AudioIO/AudioOutput.cs
new file mode 100755 (executable)
index 0000000..d2bad14
--- /dev/null
@@ -0,0 +1,207 @@
+using System;\r
+using System.Runtime.InteropServices;\r
+\r
+namespace Tizen.Multimedia\r
+{\r
+    /// <summary>\r
+    /// The Audio Output class provides a set of functions to directly manage the system audio output devices. \r
+    /// </summary>\r
+    public class AudioOutput : BaseAudio\r
+    {\r
+        /// <summary>\r
+        /// Gets the sample rate of the audio output data stream. \r
+        /// </summary>\r
+        public override int SampleRate\r
+        {\r
+            get\r
+            {\r
+                int sampleRate;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.GetSampleRate(_handle, out sampleRate));\r
+                return sampleRate;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Gets the channel type of the audio output data stream. \r
+        /// The audio channel type defines whether the audio is mono or stereo.\r
+        /// </summary>\r
+        public override AudioChannel Channel\r
+        {\r
+            get\r
+            {\r
+                int channel;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.GetChannel(_handle, out channel));\r
+                return (AudioChannel)channel;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Gets the sample audio format (8-bit or 16-bit) of the audio output data stream. \r
+        /// </summary>\r
+        public override AudioSampleType SampleType\r
+        {\r
+            get\r
+            {\r
+                int type;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.GetSampleType(_handle, out type));\r
+                return (AudioSampleType)type;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Gets the size to be allocated for the audio output buffer. \r
+        /// </summary>\r
+        public override int BufferSize\r
+        {\r
+            get\r
+            {\r
+                int size = 0;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.GetBufferSize(_handle, out size));\r
+                return size;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Gets the sound type supported by the audio output device. \r
+        /// </summary>\r
+        public AudioStreamType SoundStreamType\r
+        {\r
+            get\r
+            {\r
+                int audioType = 0;\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.GetSoundType(_handle, out audioType));\r
+                return (AudioStreamType)audioType;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Drains buffered audio data from the output stream. \r
+        /// This function waits until drains stream buffer completely. (e.g end of playback)\r
+        /// </summary>\r
+        public void Drain()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Drain(_handle));\r
+        }\r
+        object _lock = new object();\r
+        /// <summary>\r
+        /// Starts writing the audio data to the device. \r
+        /// </summary>\r
+        /// <param name="buffer"></param>\r
+        public void Write(byte[] buffer)\r
+        {\r
+            if (buffer.Length <= 0)\r
+            {\r
+                throw new IndexOutOfRangeException("Bed File Length");\r
+            }\r
+            IntPtr ptrByteArray = Marshal.AllocHGlobal(buffer.Length);\r
+            try\r
+            {\r
+                Marshal.Copy(buffer, 0, ptrByteArray, buffer.Length);\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Write(_handle, ptrByteArray, (uint)buffer.Length));\r
+            }\r
+            finally\r
+            {\r
+                if (ptrByteArray != IntPtr.Zero)\r
+                {\r
+                    Marshal.FreeHGlobal(ptrByteArray);\r
+                    ptrByteArray = IntPtr.Zero;\r
+                }\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Sets an asynchronous(event) callback function to handle playing PCM (pulse-code modulation) data. \r
+        /// </summary>\r
+        protected override void RegisterAudioStreamLengthChanged()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.SetAudioOutputStreamChangedCallback(_handle, OnStream, IntPtr.Zero));\r
+        }\r
+        /// <summary>\r
+        /// Unregisters the callback function. \r
+        /// </summary>\r
+        protected override void UnregisterAudioStreamLengthChanged()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.UnsetAudioOutputStreamChangedCallback(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Sets the state changed callback function to the audio output handle. \r
+        /// </summary>\r
+        protected override void RegisterAudioStateChangedCallback()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.SetAudioOutputStateChangedCallback(_handle, OnStateChanged, IntPtr.Zero));\r
+        }\r
+        /// <summary>\r
+        /// Unregisters the state changed callback function of the audio output handle. \r
+        /// </summary>\r
+        protected override void UnregisterAudioStateChangedmCallback()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.UnsetAudioOutputStateChangedCallback(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Releases the audio output handle, along with all its resources. \r
+        /// </summary>\r
+        protected override void Destroy()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Destroy(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Prepares the audio output for playback, this must be called before audio_out_write(). \r
+        /// </summary>\r
+        public override void Prepare()\r
+        {\r
+            if (_bReady == false)\r
+            {\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Prepare(_handle));\r
+                _bReady = true;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Unprepares the audio output. \r
+        /// </summary>\r
+        public override void Unprepare()\r
+        {\r
+            if (_bReady)\r
+            {\r
+                AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Unprepare(_handle));\r
+                _bReady = false;\r
+            }\r
+        }\r
+        /// <summary>\r
+        /// Pauses feeding of audio data to the device. \r
+        /// </summary>\r
+        public override void Pause()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Pause(_handle));\r
+\r
+        }\r
+        /// <summary>\r
+        /// Resumes feeding of audio data to the device. \r
+        /// </summary>\r
+        public override void Resume()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Resume(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Flushes and discards buffered audio data from the output stream. \r
+        /// </summary>\r
+        public override void Flush()\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Flush(_handle));\r
+        }\r
+        /// <summary>\r
+        /// Sets the sound stream information to the audio output. \r
+        /// </summary>\r
+        /// <param name="stream_info"></param>\r
+        /// <returns></returns>\r
+        public override void SetStreamInfo(AudioStreamPolicy streamPolicy)\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.SetStreamInfo(_handle, streamPolicy.Handle));\r
+        }\r
+        /// <summary>\r
+        /// Initializes the instance of the AudioOutput class with the SafeAudioInputHandle.\r
+        /// </summary>\r
+        /// <param name="_sample_rate"></param>\r
+        /// <param name="_channel"></param>\r
+        /// <param name="_type"></param>\r
+        public AudioOutput(int sample_rate, AudioChannel channel, AudioSampleType type)\r
+        {\r
+            AudioErrorHelper.Try(Interop.AudioIO.AudioOutput.Create(sample_rate, (int)channel, (int)type, out _handle));\r
+        }\r
+        private AudioOutput() { }\r
+    }\r
+}\r
diff --git a/src/Tizen.Multimedia/AudioIO/AudioStateChangedEventArgs.cs b/src/Tizen.Multimedia/AudioIO/AudioStateChangedEventArgs.cs
new file mode 100755 (executable)
index 0000000..ab3d4f1
--- /dev/null
@@ -0,0 +1,30 @@
+using System;\r
+\r
+namespace Tizen.Multimedia\r
+{\r
+    /// <summary>\r
+    /// Argument for the event that is Audio State Changed.\r
+    /// </summary>\r
+    public class AudioStateChangedEventArgs : EventArgs\r
+    {\r
+        private readonly AudioState _previous;\r
+        private readonly AudioState _current;\r
+        private readonly bool _by_policy;\r
+        /// <summary>\r
+        /// Initializes the instance of the AudioStateChangedEventArgs class. \r
+        /// </summary>\r
+        /// <param name="_prev"></param>\r
+        /// <param name="_current"></param>\r
+        /// <param name="by_policy"></param>\r
+        internal AudioStateChangedEventArgs(AudioState previous, AudioState current, bool by_policy) \r
+        {\r
+            this._previous = previous;\r
+            this._current = current;\r
+            this._by_policy = by_policy;\r
+        }\r
+\r
+        public AudioState Previous { get { return _previous; } }\r
+        public AudioState Current { get { return _current; } }\r
+        public bool Policy { get { return _by_policy; } }\r
+    }\r
+}\r
diff --git a/src/Tizen.Multimedia/AudioIO/AudioStreamLengthChangedEventArgs.cs b/src/Tizen.Multimedia/AudioIO/AudioStreamLengthChangedEventArgs.cs
new file mode 100755 (executable)
index 0000000..3c3c772
--- /dev/null
@@ -0,0 +1,15 @@
+using System;\r
+\r
+namespace Tizen.Multimedia\r
+{\r
+    public class AudioStreamLengthChangedEventArgs : EventArgs\r
+    {\r
+        private readonly uint _length;\r
+\r
+        internal AudioStreamLengthChangedEventArgs( uint length )\r
+        {\r
+            this._length = length;\r
+        }\r
+        public uint Length { get { return _length; } }\r
+    }\r
+}\r
diff --git a/src/Tizen.Multimedia/AudioIO/BaseAudio.cs b/src/Tizen.Multimedia/AudioIO/BaseAudio.cs
new file mode 100755 (executable)
index 0000000..6f7c7cb
--- /dev/null
@@ -0,0 +1,109 @@
+using System;\r
+\r
+namespace Tizen.Multimedia\r
+{\r
+    public abstract class BaseAudio : IDisposable\r
+    {\r
+        #region Event\r
+        private EventHandler<AudioStreamLengthChangedEventArgs> streamCallback;\r
+        private EventHandler<AudioStateChangedEventArgs> stateChanged;\r
+\r
+        public event EventHandler<AudioStreamLengthChangedEventArgs> StreamLengthChanged\r
+        {\r
+            add\r
+            {\r
+                if (streamCallback == null)\r
+                {\r
+                    RegisterAudioStreamLengthChanged();\r
+                }\r
+                streamCallback += value;\r
+            }\r
+            remove\r
+            {\r
+                streamCallback -= value;\r
+                if (streamCallback == null)\r
+                {\r
+                    UnregisterAudioStreamLengthChanged();\r
+                }\r
+            }\r
+        }\r
+        public event EventHandler<AudioStateChangedEventArgs> StateChanged\r
+        {\r
+            add\r
+            {\r
+                if (streamCallback == null)\r
+                {\r
+                    RegisterAudioStateChangedCallback();\r
+                }\r
+                stateChanged += value;\r
+            }\r
+            remove\r
+            {\r
+                stateChanged -= value;\r
+                if (streamCallback == null)\r
+                {\r
+                    UnregisterAudioStateChangedmCallback();\r
+                }\r
+            }\r
+        }\r
+\r
+        protected void OnStream(IntPtr handle, uint nbytes, IntPtr userdata)\r
+        {\r
+            if (streamCallback != null)\r
+            {\r
+                streamCallback(this, new AudioStreamLengthChangedEventArgs(nbytes));\r
+            }\r
+        }\r
+        protected void OnStateChanged(IntPtr handle, int previous, int current, bool by_policy, IntPtr user_data)\r
+        {\r
+            if (streamCallback != null)\r
+            {\r
+                stateChanged(this, new AudioStateChangedEventArgs((AudioState)previous, (AudioState)current, by_policy));\r
+            }\r
+        } \r
+        #endregion\r
+        protected IntPtr _handle = IntPtr.Zero;\r
+        protected bool _bReady = false;\r
+\r
+        public abstract int SampleRate { get;}\r
+        public abstract AudioChannel Channel { get; }\r
+        public abstract AudioSampleType SampleType { get; }\r
+        public abstract int BufferSize{ get; }\r
+\r
+        public abstract void Prepare();\r
+        public abstract void Unprepare();\r
+        public abstract void Pause();\r
+        public abstract void Resume();\r
+        public abstract void Flush();\r
+        public abstract void SetStreamInfo(AudioStreamPolicy streamPolicy);  // 현재는 임의의 타입으로 실제 AudioPolicy가 들어와야 함.\r
+        protected abstract void Destroy();\r
+        protected abstract void RegisterAudioStreamLengthChanged();\r
+        protected abstract void UnregisterAudioStreamLengthChanged();\r
+        protected abstract void UnregisterAudioStateChangedmCallback();\r
+        protected abstract void RegisterAudioStateChangedCallback();\r
+\r
+        public BaseAudio() { }\r
+        ~BaseAudio()\r
+        {\r
+            Dispose(false);\r
+        }\r
+        public void Dispose()\r
+        {\r
+            Dispose(true);\r
+        }\r
+        protected virtual void Dispose(bool _bDisposing)\r
+        {\r
+            if (_bDisposing) // // Free managed objects.\r
+            {\r
+                // to be used if there are any other disposable objects\r
+            }\r
+            // // Free Unmanaged objects.\r
+            if (_bReady)\r
+                Unprepare();\r
+            if (_handle != IntPtr.Zero)\r
+                Destroy();\r
+\r
+            GC.SuppressFinalize(this);\r
+        }\r
+    }    \r
+}\r
diff --git a/src/Tizen.Multimedia/Interop/Interop.AudioIO.cs b/src/Tizen.Multimedia/Interop/Interop.AudioIO.cs
new file mode 100755 (executable)
index 0000000..36671a8
--- /dev/null
@@ -0,0 +1,132 @@
+using System;\r
+using System.Runtime.InteropServices;\r
+\r
+internal static partial class Interop\r
+{\r
+    internal static partial class AudioIO\r
+    {\r
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r
+        public delegate void AudioStreamCallback(IntPtr handle, uint nbytes, IntPtr userdata);\r
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\r
+        public delegate void AudioStateChangedCallback(IntPtr handle, int previous, int current, bool byPolicy, IntPtr userData);\r
+\r
+        internal static partial class AudioInput\r
+        {\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_set_state_changed_cb")]\r
+            internal static extern int SetAudioInputStateChangedCallback(IntPtr handle, AudioStateChangedCallback callback, IntPtr user_data);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_unset_state_changed_cb")]\r
+            internal static extern int UnsetAudioInputStateChangedCallback(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_set_stream_cb")]\r
+            internal static extern int SetAudioInputStreamChangedCallback(IntPtr handle, AudioStreamCallback callback, IntPtr user_data);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_unset_stream_cb")]\r
+            internal static extern int UnsetAudioInputStreamChangedCallback(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_create")]\r
+            internal static extern int Create(int sampleRate, int channel, int type, out IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_destroy")]\r
+            internal static extern int Destroy(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_set_stream_info")]\r
+            internal static extern int SetStreamInfo(IntPtr handle, IntPtr streamInfoHandle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_prepare")]\r
+            internal static extern int Prepare(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_unprepare")]\r
+            internal static extern int Unprepare(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_pause")]\r
+            internal static extern int Pause(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_resume")]\r
+            internal static extern int Resume(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_flush")]\r
+            internal static extern int Flush(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_read")]\r
+            internal static extern int Read(IntPtr handle, IntPtr buffer, int length);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_get_buffer_size")]\r
+            internal static extern int GetBufferSize(IntPtr handle, out int size);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_get_sample_rate")]\r
+            internal static extern int GetSampleRate(IntPtr handle, out int sampleRate);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_get_channel")]\r
+            internal static extern int GetChannel(IntPtr handle, out int channel);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_get_sample_type")]\r
+            internal static extern int GetSampleType(IntPtr handle, out int sampleType);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_peek")]\r
+            internal static extern int Peek(IntPtr handle, out IntPtr buffer, out uint length);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_in_drop")]\r
+            internal static extern int Drop(IntPtr handle);\r
+        }\r
+        internal static partial class AudioOutput\r
+        {\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_set_state_changed_cb")]\r
+            internal static extern int SetAudioOutputStateChangedCallback(IntPtr handle, AudioStateChangedCallback callback, IntPtr user_data);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_unset_state_changed_cb")]\r
+            internal static extern int UnsetAudioOutputStateChangedCallback(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_set_stream_cb")]\r
+            internal static extern int SetAudioOutputStreamChangedCallback(IntPtr handle, AudioStreamCallback callback, IntPtr user_data);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_unset_stream_cb")]\r
+            internal static extern int UnsetAudioOutputStreamChangedCallback(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_create_new")]\r
+            internal static extern int Create(int sampleRate, int channel, int type, out IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_destroy")]\r
+            internal static extern int Destroy(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_drain")]\r
+            internal static extern int Drain(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_flush")]\r
+            internal static extern int Flush(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_get_buffer_size")]\r
+            internal static extern int GetBufferSize(IntPtr handle, out int size);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_get_channel")]\r
+            internal static extern int GetChannel(IntPtr handle, out int channel);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_get_sample_rate")]\r
+            internal static extern int GetSampleRate(IntPtr handle, out int sampleRate);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_get_sample_type")]\r
+            internal static extern int GetSampleType(IntPtr handle, out int sampleType);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_get_sound_type")]\r
+            internal static extern int GetSoundType(IntPtr handle, out int soundType);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_pause")]\r
+            internal static extern int Pause(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_prepare")]\r
+            internal static extern int Prepare(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_resume")]\r
+            internal static extern int Resume(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_set_stream_info")]\r
+            internal static extern int SetStreamInfo(IntPtr handle, IntPtr streamInfoHandle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_unprepare")]\r
+            internal static extern int Unprepare(IntPtr handle);\r
+\r
+            [DllImport(Libraries.AudioIO, EntryPoint = "audio_out_write")]\r
+            internal static extern int Write(IntPtr handle, IntPtr buffer, uint length);\r
+        }\r
+    }\r
+}\r
old mode 100644 (file)
new mode 100755 (executable)
index 3185e9a..4462211
@@ -8,6 +8,7 @@ internal static partial class Interop
                public const string Player = "libcapi-media-player.so.0";
                public const string Recorder = "libcapi-media-recorder.so.0";
                public const string SoundManager = "libcapi-media-sound-manager.so.0";
-               public const string Libc = "libc.so.6";
+        public const string AudioIO = "libcapi-media-audio-io.so.0";\r
+        public const string Libc = "libc.so.6";
        }
 }
old mode 100644 (file)
new mode 100755 (executable)
index d8f8cdb..86c5db7
     </Reference>\r
   </ItemGroup>\r
   <ItemGroup>\r
+    <Compile Include="AudioIO\AudioErrorHelper.cs" />\r
+    <Compile Include="AudioIO\AudioInput.cs" />\r
+    <Compile Include="AudioIO\AudioIOEnumerations.cs" />\r
+    <Compile Include="AudioIO\AudioOutput.cs" />\r
+    <Compile Include="AudioIO\AudioStateChangedEventArgs.cs" />\r
+    <Compile Include="AudioIO\AudioStreamLengthChangedEventArgs.cs" />\r
+    <Compile Include="AudioIO\BaseAudio.cs" />\r
+    <Compile Include="Interop\Interop.AudioIO.cs" />\r
     <Compile Include="Interop\Interop.Player.cs" />\r
     <Compile Include="Player\PlayerEnums.cs" />\r
     <Compile Include="Player\MediaStreamConfiguration.cs" />\r
       <Name>Tizen.Internals</Name>\r
     </ProjectReference>\r
   </ItemGroup>\r
-</Project>\r
+</Project>
\ No newline at end of file