Initialize Tizen 2.3 2.3a_release submit/tizen_2.3/20140531.054605
authorSehong Na <sehong.na@samsung.com>
Sat, 31 May 2014 03:29:38 +0000 (12:29 +0900)
committerSehong Na <sehong.na@samsung.com>
Sat, 31 May 2014 03:29:38 +0000 (12:29 +0900)
15 files changed:
AUTHORS [new file with mode: 0644]
LICENSE.APLv2 [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NOTICE [new file with mode: 0644]
audio-hal-e4x12.manifest [new file with mode: 0755]
autogen.sh [new file with mode: 0755]
configure.ac [new file with mode: 0644]
packaging/audio-hal-e4x12.spec [new file with mode: 0644]
tizen-audio-device.c [new file with mode: 0644]
tizen-audio-internal.h [new file with mode: 0644]
tizen-audio-session.c [new file with mode: 0644]
tizen-audio-stream.c [new file with mode: 0644]
tizen-audio-util.c [new file with mode: 0644]
tizen-audio.c [new file with mode: 0644]
tizen-audio.h [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..76f4125
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Hyunseok Lee <hs7388.lee at samsung.com>
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100644 (file)
index 0000000..76f9119
--- /dev/null
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..e328e7f
--- /dev/null
@@ -0,0 +1,12 @@
+lib_LTLIBRARIES = libtizen-audio.la
+
+libtizen_audio_la_SOURCES = tizen-audio.c \
+               tizen-audio-session.c \
+               tizen-audio-device.c \
+               tizen-audio-stream.c \
+               tizen-audio-util.c
+libtizen_audio_la_LDFLAGS = $(AM_LDFLAGS) -disable-static -avoid-version
+libtizen_audio_la_LIBADD = $(AM_LDADD) $(ASOUNDLIB_LIBS) $(VCONF_LIBS) $(DLOG_LIBS) $(INIPARSER_LIBS)
+libtizen_audio_la_CFLAGS = $(AM_CFLAGS) $(ASOUNDLIB_CFLAGS) $(VCONF_CFLAGS) $(DLOG_CFLAGS) $(INIPARSER_CFLAGS)
+libtizen_audio_la_CFLAGS += -DUSE_DLOG
+
diff --git a/NOTICE b/NOTICE
new file mode 100644 (file)
index 0000000..ccdad52
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,3 @@
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE file for Apache License terms and conditions.
diff --git a/audio-hal-e4x12.manifest b/audio-hal-e4x12.manifest
new file mode 100755 (executable)
index 0000000..823da83
--- /dev/null
@@ -0,0 +1,12 @@
+<manifest>
+       <define>
+               <domain name="audio-hal"/>
+               <request>
+                       <smack request="system::vconf" type="arwxt"/>
+                       <smack request="system::vconf_multimedia" type="arwxt"/>
+               </request>
+       </define>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
diff --git a/autogen.sh b/autogen.sh
new file mode 100755 (executable)
index 0000000..8e229ef
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# autogen.sh -- Autotools bootstrapping
+#
+
+libtoolize --copy --force
+aclocal && \
+autoheader && \
+autoconf && \
+automake --add-missing --copy
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..7c2da00
--- /dev/null
@@ -0,0 +1,49 @@
+AC_PREREQ([2.67])
+
+AC_INIT([libaudiofilters-sec], [0.1])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign])
+AC_CONFIG_HEADERS([config.h])
+
+AC_CONFIG_MACRO_DIR([m4])
+
+# Checks for programs.
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_CXX
+AC_PROG_LIBTOOL
+AC_PROG_AWK
+AC_PROG_CPP
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_MAKE_SET
+PKG_PROG_PKG_CONFIG
+
+# Checks for libraries.
+
+PKG_CHECK_MODULES(ASOUNDLIB, alsa >= 1.0.24)
+AC_SUBST(ASOUNDLIB_CFLAGS)
+AC_SUBST(ASOUNDLIB_LIBS)
+
+PKG_CHECK_MODULES(VCONF, vconf)
+AC_SUBST(VCONF_CFLAGS)
+AC_SUBST(VCONF_LIBS)
+
+PKG_CHECK_MODULES(INIPARSER, iniparser)
+AC_SUBST(INIPARSER_CFLAGS)
+AC_SUBST(INIPARSER_LIBS)
+
+PKG_CHECK_MODULES(DLOG, dlog)
+AC_SUBST(DLOG_CFLAGS)
+AC_SUBST(DLOG_LIBS)
+
+# Checks for header files.
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+
+
+AC_CONFIG_FILES([ \
+        Makefile
+        ])
+AC_OUTPUT
diff --git a/packaging/audio-hal-e4x12.spec b/packaging/audio-hal-e4x12.spec
new file mode 100644 (file)
index 0000000..488d159
--- /dev/null
@@ -0,0 +1,51 @@
+Name:       audio-hal-e4x12
+Summary:    TIZEN Audio HAL for Exynos4x12
+Version:    0.1.5
+Release:    0
+VCS:        magnolia/adaptation/ap_samsung/audio-hal-e4x12#a568942051241d60e37c6738466a2a5058f260c0
+Group:      System/Libraries
+License:    Apache-2.0
+URL:        http://tizen.org
+Source0:    audio-hal-e4x12-%{version}.tar.gz
+BuildRequires: pkgconfig(alsa)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(iniparser)
+BuildRequires: pkgconfig(dlog)
+
+%description
+TIZEN Audio HAL for Exynos4x12
+
+%prep
+%setup -q -n %{name}-%{version}
+
+%build
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS â€“DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+%endif
+
+%autogen
+%configure
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
+
+%make_install
+
+%post 
+/sbin/ldconfig
+
+%postun 
+/sbin/ldconfig
+
+%files
+%manifest audio-hal-e4x12.manifest
+%defattr(-,root,root,-)
+/usr/lib/libtizen-audio.so
+%{_datadir}/license/%{name}
diff --git a/tizen-audio-device.c b/tizen-audio-device.c
new file mode 100644 (file)
index 0000000..541285a
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * audio-hal
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunseok Lee <hs7388.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "tizen-audio-internal.h"
+
+audio_return_t _audio_device_init (audio_mgr_t *am)
+{
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    am->device.active_in = AUDIO_DEVICE_IN_NONE;
+    am->device.active_out = AUDIO_DEVICE_OUT_NONE;
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t _audio_device_deinit (audio_mgr_t *am)
+{
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t audio_set_route (void *userdata, uint32_t session, uint32_t subsession, uint32_t device_in, uint32_t device_out, uint32_t route_flag)
+{
+    audio_return_t audio_ret = AUDIO_RET_OK;
+    audio_mgr_t *am = (audio_mgr_t *)userdata;
+    bool update_volume = false;
+
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    AUDIO_LOG_INFO("session:%d,%d in:%d out:%d flag:0x%x", session, subsession, device_in, device_out, route_flag);
+
+    if (am->device.active_out != device_out)
+        update_volume = true;
+
+    am->device.active_in = device_in;
+    am->device.active_out = device_out;
+
+    /* Volume level should be updated if device changed */
+    if (update_volume)
+        audio_ret = _audio_update_volume_level(am);
+
+    return audio_ret;
+}
diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h
new file mode 100644 (file)
index 0000000..6594f0e
--- /dev/null
@@ -0,0 +1,130 @@
+#ifndef footizenaudiointernalfoo
+#define footizenaudiointernalfoo
+
+/*
+ * audio-hal
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunseok Lee <hs7388.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <asoundlib.h>
+#include <dlog.h>
+
+#include "tizen-audio.h"
+
+/* Debug */
+
+//#define AUDIO_DEBUG
+#define AUDIO_DUMP_STR_LEN              256
+#ifdef USE_DLOG
+#ifdef DLOG_TAG
+#undef DLOG_TAG
+#endif
+#define DLOG_TAG "AUDIO_HAL"
+#define AUDIO_LOG_ERROR(...)            SLOG(LOG_ERROR, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_WARN(...)             SLOG(LOG_WARN, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_INFO(...)             SLOG(LOG_INFO, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_DEBUG(...)            SLOG(LOG_DEBUG, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_VERBOSE(...)          SLOG(LOG_DEBUG, DLOG_TAG, __VA_ARGS__)
+#else
+#define AUDIO_LOG_ERROR(...)            fprintf(stderr, __VA_ARGS__)
+#define AUDIO_LOG_WARN(...)             fprintf(stderr, __VA_ARGS__)
+#define AUDIO_LOG_INFO(...)             fprintf(stdout, __VA_ARGS__)
+#define AUDIO_LOG_DEBUG(...)            fprintf(stdout, __VA_ARGS__)
+#define AUDIO_LOG_VERBOSE(...)          fprintf(stdout, __VA_ARGS__)
+#endif
+
+#define AUDIO_RETURN_IF_FAIL(expr, val) do { \
+    if (!expr) { \
+        AUDIO_LOG_ERROR("%s failed", #expr); \
+        return; \
+    } \
+} while (0)
+#define AUDIO_RETURN_VAL_IF_FAIL(expr, val) do { \
+    if (!expr) { \
+        AUDIO_LOG_ERROR("%s failed", #expr); \
+        return val; \
+    } \
+} while (0)
+
+/* Session */
+typedef struct audio_session_mgr {
+    audio_session_t session;
+    audio_subsession_t subsession;
+} audio_session_mgr_t;
+
+
+/* Device */
+
+typedef struct audio_device_mgr {
+    audio_device_in_t active_in;
+    audio_device_out_t active_out;
+} audio_device_mgr_t;
+
+
+/* Stream */
+
+#define AUDIO_VOLUME_LEVEL_MAX 16
+
+typedef struct audio_volume_gain_table {
+    double volume[AUDIO_VOLUME_TYPE_MAX][AUDIO_VOLUME_LEVEL_MAX];
+    uint32_t volume_level_max[AUDIO_VOLUME_LEVEL_MAX];
+    double gain[AUDIO_GAIN_TYPE_MAX];
+} audio_volume_gain_table_t;
+
+enum {
+    AUDIO_VOLUME_DEVICE_SPEAKER,
+    AUDIO_VOLUME_DEVICE_RECEIVER,
+    AUDIO_VOLUME_DEVICE_EARJACK,
+    AUDIO_VOLUME_DEVICE_BT_SCO,
+    AUDIO_VOLUME_DEVICE_BT_A2DP,
+    AUDIO_VOLUME_DEVICE_DOCK,
+    AUDIO_VOLUME_DEVICE_HDMI,
+    AUDIO_VOLUME_DEVICE_MIRRORING,
+    AUDIO_VOLUME_DEVICE_USB,
+    AUDIO_VOLUME_DEVICE_MULTIMEDIA_DOCK,
+    AUDIO_VOLUME_DEVICE_MAX,
+};
+
+typedef struct audio_stream_mgr {
+    uint32_t volume_level[AUDIO_VOLUME_TYPE_MAX];
+    audio_volume_gain_table_t *volume_gain_table;
+} audio_stream_mgr_t;
+
+typedef struct audio_mixer_mgr {
+    pthread_mutex_t mutex;
+} audio_mixer_mgr_t;
+
+/* Overall */
+
+typedef struct audio_mgr {
+    audio_session_mgr_t session;
+    audio_device_mgr_t device;
+    audio_stream_mgr_t stream;
+    audio_mixer_mgr_t mixer;
+} audio_mgr_t;
+
+audio_return_t _audio_stream_init (audio_mgr_t *am);
+audio_return_t _audio_stream_deinit (audio_mgr_t *am);
+audio_return_t _audio_update_volume_level (audio_mgr_t *am);
+
+audio_return_t _audio_device_init (audio_mgr_t *am);
+audio_return_t _audio_device_deinit (audio_mgr_t * am);
+
+
+#endif
diff --git a/tizen-audio-session.c b/tizen-audio-session.c
new file mode 100644 (file)
index 0000000..e533799
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * audio-hal
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunseok Lee <hs7388.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tizen-audio-internal.h"
+
+audio_return_t _audio_session_init (audio_mgr_t *am)
+{
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    am->session.session = AUDIO_SESSION_MEDIA;
+    am->session.subsession = AUDIO_SUBSESSION_NONE;
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t _audio_session_deinit (audio_mgr_t *am)
+{
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t audio_set_session (void *userdata, uint32_t session, uint32_t subsession)
+{
+    audio_return_t audio_ret = AUDIO_RET_OK;
+    audio_mgr_t *am = (audio_mgr_t *)userdata;
+
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    AUDIO_LOG_INFO("session:%d,%d", session, subsession);
+
+    am->session.session = session;
+    am->session.subsession = subsession;
+
+    return audio_ret;
+}
+
diff --git a/tizen-audio-stream.c b/tizen-audio-stream.c
new file mode 100644 (file)
index 0000000..0c263ae
--- /dev/null
@@ -0,0 +1,457 @@
+/*
+ * audio-hal
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunseok Lee <hs7388.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <vconf.h>
+#include <iniparser.h>
+#include <alsa/asoundlib.h>
+
+#include "tizen-audio-internal.h"
+
+#define VOLUME_INI_DEFAULT_PATH     "/usr/etc/mmfw_audio_volume.ini"
+#define VOLUME_INI_TEMP_PATH        "/opt/system/mmfw_audio_volume.ini"
+#define VOLUME_VALUE_MAX            (1.0f)
+#define GAIN_VALUE_MAX              (1.0f)
+
+enum {
+    STREAM_DEVICE_SPEAKER,
+    STREAM_DEVICE_HEADSET,
+    STREAM_DEVICE_BLUETOOTH,
+    STREAM_DEVICE_HDMI,
+    STREAM_DEVICE_MAX,
+};
+
+static const char *g_volume_vconf[AUDIO_VOLUME_TYPE_MAX] = {
+    "file/private/sound/volume/system",         /* AUDIO_VOLUME_TYPE_SYSTEM */
+    "file/private/sound/volume/notification",   /* AUDIO_VOLUME_TYPE_NOTIFICATION */
+    "file/private/sound/volume/alarm",          /* AUDIO_VOLUME_TYPE_ALARM */
+    "file/private/sound/volume/ringtone",       /* AUDIO_VOLUME_TYPE_RINGTONE */
+    "file/private/sound/volume/media",          /* AUDIO_VOLUME_TYPE_MEDIA */
+    "file/private/sound/volume/call",           /* AUDIO_VOLUME_TYPE_CALL */
+    "file/private/sound/volume/voip",           /* AUDIO_VOLUME_TYPE_VOIP */
+    "file/private/sound/volume/svoice",         /* AUDIO_VOLUME_TYPE_SVOICE */
+    "file/private/sound/volume/fixed",          /* AUDIO_VOLUME_TYPE_FIXED */
+    "file/private/sound/volume/java"            /* AUDIO_VOLUME_TYPE_EXT_JAVA */
+};
+
+static inline uint8_t __get_volume_dev_index(audio_mgr_t *am, uint32_t volume_type)
+{
+    return 0;
+}
+
+static const uint8_t __get_stream_dev_index (uint32_t device_out)
+{
+    switch (device_out) {
+    case AUDIO_DEVICE_OUT_SPEAKER:          return STREAM_DEVICE_SPEAKER;
+    case AUDIO_DEVICE_OUT_RECEIVER:         return STREAM_DEVICE_SPEAKER;
+    case AUDIO_DEVICE_OUT_WIRED_ACCESSORY:  return STREAM_DEVICE_HEADSET;
+    case AUDIO_DEVICE_OUT_BT_SCO:           return STREAM_DEVICE_BLUETOOTH;
+    case AUDIO_DEVICE_OUT_BT_A2DP:          return STREAM_DEVICE_BLUETOOTH;
+    case AUDIO_DEVICE_OUT_DOCK:             return STREAM_DEVICE_SPEAKER;
+    case AUDIO_DEVICE_OUT_HDMI:             return STREAM_DEVICE_HDMI;
+    case AUDIO_DEVICE_OUT_MIRRORING:        return STREAM_DEVICE_SPEAKER;
+    case AUDIO_DEVICE_OUT_USB_AUDIO:        return STREAM_DEVICE_SPEAKER;
+    case AUDIO_DEVICE_OUT_MULTIMEDIA_DOCK:  return STREAM_DEVICE_SPEAKER;
+    default:
+        AUDIO_LOG_DEBUG("invalid device_out:%d", device_out);
+        break;
+    }
+
+    return STREAM_DEVICE_SPEAKER;
+}
+
+static const char *__get_device_string_by_idx (uint32_t dev_idx)
+{
+    switch (dev_idx) {
+    case STREAM_DEVICE_SPEAKER:             return "speaker";
+    case STREAM_DEVICE_HEADSET:             return "headset";
+    case STREAM_DEVICE_BLUETOOTH:           return "btheadset";
+    case STREAM_DEVICE_HDMI:                return "hdmi";
+    default:                                return "invalid";
+    }
+}
+
+static const char *__get_direction_string_by_idx (uint32_t dir_idx)
+{
+    switch (dir_idx) {
+    case AUDIO_DIRECTION_NONE:              return "none";
+    case AUDIO_DIRECTION_IN:                return "in";
+    case AUDIO_DIRECTION_OUT:               return "out";
+    default:                                return "invalid";
+    }
+}
+
+static const char *__get_volume_type_string_by_idx (uint32_t vol_type_idx)
+{
+    switch (vol_type_idx) {
+    case AUDIO_VOLUME_TYPE_SYSTEM:          return "system";
+    case AUDIO_VOLUME_TYPE_NOTIFICATION:    return "notification";
+    case AUDIO_VOLUME_TYPE_ALARM:           return "alarm";
+    case AUDIO_VOLUME_TYPE_RINGTONE:        return "ringtone";
+    case AUDIO_VOLUME_TYPE_MEDIA:           return "media";
+    case AUDIO_VOLUME_TYPE_CALL:            return "call";
+    case AUDIO_VOLUME_TYPE_VOIP:            return "voip";
+    case AUDIO_VOLUME_TYPE_SVOICE:          return "svoice";
+    case AUDIO_VOLUME_TYPE_FIXED:           return "fixed";
+    case AUDIO_VOLUME_TYPE_EXT_JAVA:        return "java";
+    default:                                return "invalid";
+    }
+}
+
+static const char *__get_gain_type_string_by_idx (uint32_t gain_type_idx)
+{
+    switch (gain_type_idx) {
+    case AUDIO_GAIN_TYPE_DEFAULT:           return "default";
+    case AUDIO_GAIN_TYPE_DIALER:            return "dialer";
+    case AUDIO_GAIN_TYPE_TOUCH:             return "touch";
+    case AUDIO_GAIN_TYPE_AF:                return "af";
+    case AUDIO_GAIN_TYPE_SHUTTER1:          return "shutter1";
+    case AUDIO_GAIN_TYPE_SHUTTER2:          return "shutter2";
+    case AUDIO_GAIN_TYPE_CAMCODING:         return "camcording";
+    case AUDIO_GAIN_TYPE_MIDI:              return "midi";
+    case AUDIO_GAIN_TYPE_BOOTING:           return "booting";
+    case AUDIO_GAIN_TYPE_VIDEO:             return "video";
+    case AUDIO_GAIN_TYPE_TTS:               return "tts";
+    default:                                return "invalid";
+    }
+}
+
+static void __dump_info(char *dump, audio_info_t *info)
+{
+    int len;
+
+    if (info->device.api == AUDIO_DEVICE_API_ALSA) {
+        len = sprintf(dump, "device:alsa(%d.%d)", info->device.alsa.card_idx, info->device.alsa.device_idx);
+    } else if (info->device.api == AUDIO_DEVICE_API_ALSA) {
+        len = sprintf(dump, "device:bluez(%s,nrec:%d)", info->device.bluez.protocol, info->device.bluez.nrec);
+    } else {
+        len = sprintf(dump, "device:unknown");
+    }
+
+    if (len > 0)
+        dump += len;
+
+    len = sprintf(dump, "stream:%s(%dhz,%dch,vol:%s,gain:%s)",
+        info->stream.name ? info->stream.name : "null", info->stream.samplerate, info->stream.channels,
+        __get_volume_type_string_by_idx(info->stream.volume_type), __get_gain_type_string_by_idx(info->stream.gain_type));
+
+    if (len > 0)
+        dump += len;
+
+    *dump = '\0';
+}
+
+#ifdef AUDIO_DEBUG
+static void __dump_tb (audio_mgr_t *am)
+{
+    audio_volume_gain_table_t *volume_gain_table = am->stream.volume_gain_table;
+    uint32_t dev_idx, vol_type_idx, vol_level_idx, gain_type_idx;
+    const char *gain_type_str[] = {
+        "def",          /* AUDIO_GAIN_TYPE_DEFAULT */
+        "dial",         /* AUDIO_GAIN_TYPE_DIALER */
+        "touch",        /* AUDIO_GAIN_TYPE_TOUCH */
+        "af",           /* AUDIO_GAIN_TYPE_AF */
+        "shut1",        /* AUDIO_GAIN_TYPE_SHUTTER1 */
+        "shut2",        /* AUDIO_GAIN_TYPE_SHUTTER2 */
+        "cam",          /* AUDIO_GAIN_TYPE_CAMCODING */
+        "midi",         /* AUDIO_GAIN_TYPE_MIDI */
+        "boot",         /* AUDIO_GAIN_TYPE_BOOTING */
+        "video",        /* AUDIO_GAIN_TYPE_VIDEO */
+        "tts",          /* AUDIO_GAIN_TYPE_TTS */
+    };
+    char dump_str[AUDIO_DUMP_STR_LEN], *dump_str_ptr;
+
+    /* Dump volume table */
+    AUDIO_LOG_DEBUG("<<<<< volume table >>>>>");
+
+    for (dev_idx = 0; dev_idx < STREAM_DEVICE_MAX; dev_idx++) {
+        const char *dev_str = __get_device_string_by_idx(dev_idx);
+
+        AUDIO_LOG_DEBUG("<< %s >>", dev_str);
+
+        for (vol_type_idx = 0; vol_type_idx < AUDIO_VOLUME_TYPE_MAX; vol_type_idx++) {
+            const char *vol_type_str = __get_volume_type_string_by_idx(vol_type_idx);
+
+            dump_str_ptr = &dump_str[0];
+            memset(dump_str, 0x00, sizeof(char) * sizeof(dump_str));
+            snprintf(dump_str_ptr, 8, "%6s:", vol_type_str);
+            dump_str_ptr += strlen(dump_str_ptr);
+
+            for (vol_level_idx = 0; vol_level_idx < volume_gain_table->volume_level_max[vol_type_idx]; vol_level_idx++) {
+                snprintf(dump_str_ptr, 6, "%01.2f ", volume_gain_table->volume[vol_type_idx][vol_level_idx]);
+                dump_str_ptr += strlen(dump_str_ptr);
+            }
+            AUDIO_LOG_DEBUG("%s", dump_str);
+        }
+        volume_gain_table++;
+    }
+
+    volume_gain_table = am->stream.volume_gain_table;
+
+    /* Dump gain table */
+    AUDIO_LOG_DEBUG("<<<<< gain table >>>>>");
+
+    dump_str_ptr = &dump_str[0];
+    memset(dump_str, 0x00, sizeof(char) * sizeof(dump_str));
+
+    snprintf(dump_str_ptr, 11, "%10s", " ");
+    dump_str_ptr += strlen(dump_str_ptr);
+
+    for (gain_type_idx = 0; gain_type_idx < AUDIO_GAIN_TYPE_MAX; gain_type_idx++) {
+        snprintf(dump_str_ptr, 7, "%5s ", gain_type_str[gain_type_idx]);
+        dump_str_ptr += strlen(dump_str_ptr);
+    }
+    AUDIO_LOG_DEBUG("%s", dump_str);
+
+    for (dev_idx = 0; dev_idx < STREAM_DEVICE_MAX; dev_idx++) {
+        const char *dev_str = __get_device_string_by_idx(dev_idx);
+
+        dump_str_ptr = &dump_str[0];
+        memset(dump_str, 0x00, sizeof(char) * sizeof(dump_str));
+
+        snprintf(dump_str_ptr, 11, "%9s:", dev_str);
+        dump_str_ptr += strlen(dump_str_ptr);
+
+        for (gain_type_idx = 0; gain_type_idx < AUDIO_GAIN_TYPE_MAX; gain_type_idx++) {
+            snprintf(dump_str_ptr, 7, "%01.3f ", volume_gain_table->gain[gain_type_idx]);
+            dump_str_ptr += strlen(dump_str_ptr);
+        }
+        AUDIO_LOG_DEBUG("%s", dump_str);
+
+        volume_gain_table++;
+    }
+}
+#endif
+
+static audio_return_t __load_volume_gain_table_from_ini (audio_mgr_t *am)
+{
+    dictionary * dict = NULL;
+    uint32_t dev_idx, vol_type_idx, vol_level_idx, gain_type_idx;
+    audio_volume_gain_table_t *volume_gain_table = am->stream.volume_gain_table;
+
+    dict = iniparser_load(VOLUME_INI_TEMP_PATH);
+    if (!dict) {
+        AUDIO_LOG_DEBUG("Use temporary volume&gain ini file");
+        dict = iniparser_load(VOLUME_INI_DEFAULT_PATH);
+        if (!dict) {
+            AUDIO_LOG_WARN("Loading volume&gain table from ini file failed");
+            return AUDIO_ERR_UNDEFINED;
+        }
+    }
+
+    for (dev_idx = 0; dev_idx < STREAM_DEVICE_MAX; dev_idx++) {
+        const char delimiter[] = ", ";
+        char *key, *list_str, *token, *ptr = NULL;
+        const char *dev_str = __get_device_string_by_idx(dev_idx);
+
+        /* Load volume table */
+        for (vol_type_idx = 0; vol_type_idx < AUDIO_VOLUME_TYPE_MAX; vol_type_idx++) {
+            const char *vol_type_str = __get_volume_type_string_by_idx(vol_type_idx);
+
+            volume_gain_table->volume_level_max[vol_type_idx] = 0;
+
+            key = malloc(strlen(dev_str) + strlen(vol_type_str) + 2);
+            if (key) {
+                sprintf(key, "%s:%s", dev_str, vol_type_str);
+                list_str = iniparser_getstr(dict, key);
+                if (list_str) {
+                    token = strtok_r(list_str, delimiter, &ptr);
+                    while (token) {
+                        volume_gain_table->volume[vol_type_idx][volume_gain_table->volume_level_max[vol_type_idx]++] = atof(token);
+                        token = strtok_r(NULL, delimiter, &ptr);
+                    }
+                } else {
+                    for (vol_level_idx = 0; vol_level_idx < AUDIO_VOLUME_LEVEL_MAX; vol_level_idx++) {
+                        volume_gain_table->volume[vol_type_idx][vol_level_idx] = VOLUME_VALUE_MAX;
+                    }
+                }
+                free(key);
+            }
+        }
+
+        /* Load gain table */
+        key = malloc(strlen(dev_str) + strlen("gain") + 2);
+        if (key) {
+            sprintf(key, "%s:gain", dev_str);
+            list_str = iniparser_getstr(dict, key);
+            if (list_str) {
+                token = strtok_r(list_str, delimiter, &ptr);
+                volume_gain_table->gain[AUDIO_GAIN_TYPE_DEFAULT] = GAIN_VALUE_MAX;
+                for (gain_type_idx = AUDIO_GAIN_TYPE_DEFAULT + 1; gain_type_idx < AUDIO_GAIN_TYPE_MAX; gain_type_idx++) {
+                    if (token) {
+                        volume_gain_table->gain[gain_type_idx] = atof(token);
+                        token = strtok_r(NULL, delimiter, &ptr);
+                    } else {
+                        volume_gain_table->gain[gain_type_idx] = GAIN_VALUE_MAX;
+                    }
+                }
+            } else {
+                for (gain_type_idx = 0; gain_type_idx < AUDIO_GAIN_TYPE_MAX; gain_type_idx++)
+                    volume_gain_table->gain[gain_type_idx] = GAIN_VALUE_MAX;
+            }
+            free(key);
+        }
+        volume_gain_table++;
+    }
+
+    iniparser_freedict(dict);
+#ifdef AUDIO_DEBUG
+    __dump_tb(am);
+#endif
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t _audio_stream_init (audio_mgr_t *am)
+{
+    int i, value;
+
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    for (i = 0; i < AUDIO_VOLUME_TYPE_MAX; i++) {
+        /* Get volume value string from VCONF */
+        if (vconf_get_int(g_volume_vconf[i], &value) != 0) {
+            AUDIO_LOG_ERROR("vconf_get_int(%s) failed", g_volume_vconf[i]);
+            continue;
+        }
+        AUDIO_LOG_INFO("read vconf. %s = %d", g_volume_vconf[i], value);
+
+        /* Unified type uses only fisrt index of volume devices */
+        am->stream.volume_level[i] = value;
+    }
+
+    if (!(am->stream.volume_gain_table = malloc(STREAM_DEVICE_MAX * sizeof(audio_volume_gain_table_t)))) {
+        AUDIO_LOG_ERROR("volume_gain_table malloc failed");
+        return AUDIO_ERR_RESOURCE;
+    }
+
+    return __load_volume_gain_table_from_ini(am);
+}
+
+audio_return_t _audio_stream_deinit (audio_mgr_t *am)
+{
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    if (am->stream.volume_gain_table) {
+        free(am->stream.volume_gain_table);
+        am->stream.volume_gain_table = NULL;
+    }
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t audio_get_volume_level_max (void *userdata, uint32_t volume_type, uint32_t *level)
+{
+    audio_mgr_t *am = (audio_mgr_t *)userdata;
+    audio_volume_gain_table_t *volume_gain_table;
+
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+    AUDIO_RETURN_VAL_IF_FAIL(am->stream.volume_gain_table, AUDIO_ERR_PARAMETER);
+
+    /* Get max volume level by device & type */
+    volume_gain_table = am->stream.volume_gain_table + __get_stream_dev_index(am->device.active_out);
+    *level = volume_gain_table->volume_level_max[volume_type];
+
+    AUDIO_LOG_DEBUG("get_volume_level_max:%s=>%d", __get_volume_type_string_by_idx(volume_type), *level);
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t audio_get_volume_level (void *userdata, uint32_t volume_type, uint32_t *level)
+{
+    audio_mgr_t *am = (audio_mgr_t *)userdata;
+
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    *level = am->stream.volume_level[volume_type];
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t audio_get_volume_value (void *userdata, audio_info_t *info, uint32_t volume_type, uint32_t level, double *value)
+{
+    if (info) {
+        audio_mgr_t *am = (audio_mgr_t *)userdata;
+        audio_volume_gain_table_t *volume_gain_table;
+        char dump_str[AUDIO_DUMP_STR_LEN];
+
+        AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+        AUDIO_RETURN_VAL_IF_FAIL(am->stream.volume_gain_table, AUDIO_ERR_PARAMETER);
+
+        __dump_info(&dump_str[0], info);
+
+        /* Get basic volume by device & type & level */
+        volume_gain_table = am->stream.volume_gain_table + __get_stream_dev_index(am->device.active_out);
+        if (volume_gain_table->volume_level_max[volume_type] < level)
+            *value = VOLUME_VALUE_MAX;
+        else
+            *value = volume_gain_table->volume[volume_type][level];
+        *value *= volume_gain_table->gain[info->stream.gain_type];
+
+        AUDIO_LOG_DEBUG("get_volume_value:%d(%s)=>%f %s", level, __get_volume_type_string_by_idx(volume_type), *value, &dump_str[0]);
+    }
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t audio_set_volume_level (void *userdata, audio_info_t *info, uint32_t volume_type, uint32_t level)
+{
+    audio_mgr_t *am = (audio_mgr_t *)userdata;
+
+    AUDIO_RETURN_VAL_IF_FAIL(am, AUDIO_ERR_PARAMETER);
+
+    if (info == NULL) {
+        /* Update volume level */
+        am->stream.volume_level[volume_type] = level;
+    }
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t _audio_update_volume_level (audio_mgr_t *am)
+{
+    int i;
+
+    for (i = 0; i < AUDIO_VOLUME_TYPE_MAX; i++) {
+        /* Update vconf */
+        if (vconf_set_int(g_volume_vconf[i], am->stream.volume_level[i]) != 0) {
+            AUDIO_LOG_ERROR("vconf_set_int(%s) failed", g_volume_vconf[i]);
+            continue;
+        }
+    }
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t audio_get_mute (void *userdata, audio_info_t *info, uint32_t volume_type, uint32_t direction, uint32_t *mute)
+{
+    return AUDIO_RET_OK;\r}
+
+audio_return_t audio_set_mute (void *userdata, audio_info_t *info, uint32_t volume_type, uint32_t direction, uint32_t mute)
+{
+    return AUDIO_RET_OK;
+}
diff --git a/tizen-audio-util.c b/tizen-audio-util.c
new file mode 100644 (file)
index 0000000..f624ded
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * audio-hal
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunseok Lee <hs7388.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "tizen-audio-internal.h"
+
+audio_return_t _audio_util_init (audio_mgr_t *am)
+{
+    pthread_mutex_init(&(am->mixer.mutex), NULL);
+    return AUDIO_RET_OK;
+}
+
+audio_return_t _audio_util_deinit (audio_mgr_t *am)
+{
+    pthread_mutex_destroy(&(am->mixer.mutex));
+    return AUDIO_RET_OK;
+}
+
+static void __dump_mixer_param(char *dump, long *param, int size)
+{
+    int i, len;
+
+    for (i = 0; i < size; i++) {
+        len = sprintf(dump, "%ld", *param);
+        if (len > 0)
+            dump += len;
+        if (i != size -1) {
+            *dump++ = ',';
+        }
+
+        param++;
+    }
+    *dump = '\0';
+}
+
+audio_return_t _audio_mixer_control_set_param(audio_mgr_t *am, const char* ctl_name, struct snd_ctl_elem_value* param, int size)
+{
+    audio_return_t ret = AUDIO_RET_USE_HW_CONTROL;
+    char dump_str[AUDIO_DUMP_STR_LEN];
+
+    pthread_mutex_lock(&(am->mixer.mutex));
+
+    AUDIO_LOG_DEBUG("mixer_ctl_set_param %s=%s success", ctl_name, dump_str);
+
+exit:
+    pthread_mutex_unlock(&(am->mixer.mutex));
+
+    return ret;
+}
+
+audio_return_t _audio_mixer_control_get_value(audio_mgr_t *am, const char *ctl_name, int *val)
+{
+    audio_return_t ret = AUDIO_RET_USE_HW_CONTROL;
+
+    pthread_mutex_lock(&(am->mixer.mutex));
+
+    AUDIO_LOG_DEBUG("mixer_ctl_get %s=%d success", ctl_name, *val);
+
+exit:
+    pthread_mutex_unlock(&(am->mixer.mutex));
+
+    return ret;
+}
+
+audio_return_t _audio_mixer_control_set_value(audio_mgr_t *am, const char *ctl_name, int val)
+{
+    audio_return_t ret = AUDIO_RET_USE_HW_CONTROL;
+
+    pthread_mutex_lock(&(am->mixer.mutex));
+
+    AUDIO_LOG_DEBUG("set_mixer %s=%d success", ctl_name, val);
+
+exit:
+    pthread_mutex_unlock(&(am->mixer.mutex));
+
+    return ret;
+}
+
+audio_return_t _audio_mixer_control_set_value_string(audio_mgr_t *am, const char* ctl_name, const char* value)
+{
+    audio_return_t ret = AUDIO_RET_USE_HW_CONTROL;
+
+    pthread_mutex_lock(&(am->mixer.mutex));
+
+    AUDIO_LOG_DEBUG("set_mixer %s=%s success", ctl_name, value);
+
+exit:
+    pthread_mutex_unlock(&(am->mixer.mutex));
+
+    return ret;
+}
+
diff --git a/tizen-audio.c b/tizen-audio.c
new file mode 100644 (file)
index 0000000..6e1c3ce
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * audio-hal
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunseok Lee <hs7388.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "tizen-audio-internal.h"
+
+int audio_get_revision (void)
+{
+    return AUDIO_REVISION;
+}
+
+audio_return_t audio_init (void **userdata)
+{
+    audio_mgr_t *am;
+    audio_return_t ret = AUDIO_RET_OK;
+
+    if (!(am = malloc(sizeof(audio_mgr_t)))) {
+        AUDIO_LOG_ERROR("am malloc failed");
+        return AUDIO_ERR_RESOURCE;
+    }
+    if (AUDIO_IS_ERROR((ret = _audio_session_init(am)))) {
+        AUDIO_LOG_ERROR("session init failed");
+        goto error_exit;
+    }
+    if (AUDIO_IS_ERROR((ret = _audio_device_init(am)))) {
+        AUDIO_LOG_ERROR("device init failed");
+        goto error_exit;
+    }
+    if (AUDIO_IS_ERROR((ret = _audio_stream_init(am)))) {
+        AUDIO_LOG_ERROR("stream init failed");
+        goto error_exit;
+    }
+    if (AUDIO_IS_ERROR((ret = _audio_util_init(am)))) {
+        AUDIO_LOG_ERROR("mixer init failed");
+        goto error_exit;
+    }
+
+    *userdata = (void *)am;
+    return AUDIO_RET_OK;
+
+error_exit:
+    if (am)
+        free(am);
+
+    return ret;
+}
+
+audio_return_t audio_deinit (void **userdata)
+{
+    audio_mgr_t *am = (audio_mgr_t *)*userdata;
+    if (am) {
+        _audio_session_deinit(am);
+        _audio_device_deinit(am);
+        _audio_stream_deinit(am);
+        _audio_util_deinit(am);
+        free(am);
+        *userdata = NULL;
+    }
+
+    return AUDIO_RET_OK;
+}
+
+audio_return_t audio_reset (void **userdata)
+{
+    audio_mgr_t *am = (audio_mgr_t *)*userdata;
+    audio_return_t ret = AUDIO_RET_OK;
+
+    if (am) {
+        _audio_device_deinit(am);
+        _audio_stream_deinit(am);
+        _audio_util_deinit(am);
+
+        if (AUDIO_IS_ERROR((ret = _audio_session_init(am)))) {
+            AUDIO_LOG_ERROR("session init failed");
+            goto error_exit;
+        }
+        if (AUDIO_IS_ERROR((ret = _audio_device_init(am)))) {
+            AUDIO_LOG_ERROR("device init failed");
+            goto error_exit;
+        }
+        if (AUDIO_IS_ERROR((ret = _audio_stream_init(am)))) {
+            AUDIO_LOG_ERROR("stream init failed");
+            goto error_exit;
+        }
+        if (AUDIO_IS_ERROR((ret = _audio_util_init(am)))) {
+            AUDIO_LOG_ERROR("mixer init failed");
+            goto error_exit;
+        }
+    }
+
+    return AUDIO_RET_OK;
+
+error_exit:
+    if (am)
+        free(am);
+    *userdata = NULL;
+
+    return ret;
+}
diff --git a/tizen-audio.h b/tizen-audio.h
new file mode 100644 (file)
index 0000000..8cbe5ca
--- /dev/null
@@ -0,0 +1,222 @@
+#ifndef footizenaudiofoo
+#define footizenaudiofoo
+
+/*
+ * audio-hal
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunseok Lee <hs7388.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#define AUDIO_REVISION                  1
+
+/* Error code */
+
+#define AUDIO_IS_ERROR(ret)             (ret < 0)
+
+typedef enum audio_return {
+    AUDIO_RET_OK                        = 0,
+    AUDIO_RET_USE_HW_CONTROL            = (int32_t)0x40001000,
+    AUDIO_ERR_UNDEFINED                 = (int32_t)0x80001000,
+    AUDIO_ERR_RESOURCE                  = (int32_t)0x80001001,
+    AUDIO_ERR_PARAMETER                 = (int32_t)0x80001002,
+    AUDIO_ERR_IOCTL                     = (int32_t)0x80001003,
+} audio_return_t ;
+
+
+/* Session */
+typedef enum audio_session {
+    AUDIO_SESSION_MEDIA,
+    AUDIO_SESSION_VOICECALL,
+    AUDIO_SESSION_VIDEOCALL,
+    AUDIO_SESSION_VOIP,
+    AUDIO_SESSION_FMRADIO,
+    AUDIO_SESSION_CAMCORDER,
+    AUDIO_SESSION_NOTIFICATION,
+    AUDIO_SESSION_ALARM,
+    AUDIO_SESSION_EMERGENCY,
+    AUDIO_SESSION_VOICE_RECOGNITION,
+    AUDIO_SESSION_MAX
+} audio_session_t;
+
+/* Sub session */
+typedef enum audio_subsession {
+    AUDIO_SUBSESSION_NONE,
+    AUDIO_SUBSESSION_VOICE,
+    AUDIO_SUBSESSION_RINGTONE,
+    AUDIO_SUBSESSION_MEDIA,
+    AUDIO_SUBSESSION_VR_INIT,
+    AUDIO_SUBSESSION_VR_NORMAL,
+    AUDIO_SUBSESSION_VR_DRIVE,
+    AUDIO_SUBSESSION_STEREO_REC,
+    AUDIO_SUBSESSION_AM_PLAY,
+    AUDIO_SUBSESSION_AM_REC,
+    AUDIO_SUBSESSION_MAX
+} audio_subsession_t;
+
+
+/* Direction */
+typedef enum audio_direction {
+    AUDIO_DIRECTION_NONE,
+    AUDIO_DIRECTION_IN,                 /**< Capture */
+    AUDIO_DIRECTION_OUT,                /**< Playback */
+} audio_direction_t;
+
+
+/* Device */
+
+typedef enum audio_device_in {
+    AUDIO_DEVICE_IN_NONE,
+    AUDIO_DEVICE_IN_MIC,                /**< Device builtin mic. */
+    AUDIO_DEVICE_IN_WIRED_ACCESSORY,    /**< Wired input devices */
+    AUDIO_DEVICE_IN_BT_SCO,             /**< Bluetooth SCO device */
+    AUDIO_DEVICE_IN_MAX,
+} audio_device_in_t;
+
+typedef enum audio_device_out {
+    AUDIO_DEVICE_OUT_NONE,
+    AUDIO_DEVICE_OUT_SPEAKER,           /**< Device builtin speaker */
+    AUDIO_DEVICE_OUT_RECEIVER,          /**< Device builtin receiver */
+    AUDIO_DEVICE_OUT_WIRED_ACCESSORY,   /**< Wired output devices such as headphone, headset, and so on. */
+    AUDIO_DEVICE_OUT_BT_SCO,            /**< Bluetooth SCO device */
+    AUDIO_DEVICE_OUT_BT_A2DP,           /**< Bluetooth A2DP device */
+    AUDIO_DEVICE_OUT_DOCK,              /**< DOCK device */
+    AUDIO_DEVICE_OUT_HDMI,              /**< HDMI device */
+    AUDIO_DEVICE_OUT_MIRRORING,         /**< MIRRORING device */
+    AUDIO_DEVICE_OUT_USB_AUDIO,         /**< USB Audio device */
+    AUDIO_DEVICE_OUT_MULTIMEDIA_DOCK,   /**< Multimedia DOCK device */
+    AUDIO_DEVICE_OUT_MAX,
+} audio_device_out_t;
+
+typedef enum audio_route_flag {
+    AUDIO_ROUTE_FLAG_NONE               = 0,
+    AUDIO_ROUTE_FLAG_DUAL_OUT           = 0x00000001,
+    AUDIO_ROUTE_FLAG_NOISE_REDUCTION    = 0x00000002,
+    AUDIO_ROUTE_FLAG_EXTRA_VOL          = 0x00000004,
+    AUDIO_ROUTE_FLAG_WB                 = 0x00000008,
+    AUDIO_ROUTE_FLAG_SVOICE_COMMAND     = 0x00010000,
+    AUDIO_ROUTE_FLAG_SVOICE_WAKEUP      = 0x00020000,
+} audio_route_flag_t;
+
+typedef enum audio_device_api {
+    AUDIO_DEVICE_API_UNKNOWN,
+    AUDIO_DEVICE_API_ALSA,
+    AUDIO_DEVICE_API_BLUEZ,
+} audio_device_api_t;
+
+typedef struct audio_device_alsa_info {
+    uint32_t card_idx;
+    uint32_t device_idx;
+} audio_device_alsa_info_t;
+
+typedef struct audio_device_bluz_info {
+    char *protocol;
+    uint32_t nrec;
+} audio_device_bluez_info_t;
+
+typedef struct audio_device_info {
+    audio_device_api_t api;
+    union {
+        audio_device_alsa_info_t alsa;
+        audio_device_bluez_info_t bluez;
+    };
+} audio_device_info_t;
+
+
+/* Stream */
+
+typedef enum audio_volume {
+    AUDIO_VOLUME_TYPE_SYSTEM,           /**< System volume type */
+    AUDIO_VOLUME_TYPE_NOTIFICATION,     /**< Notification volume type */
+    AUDIO_VOLUME_TYPE_ALARM,            /**< Alarm volume type */
+    AUDIO_VOLUME_TYPE_RINGTONE,         /**< Ringtone volume type */
+    AUDIO_VOLUME_TYPE_MEDIA,            /**< Media volume type */
+    AUDIO_VOLUME_TYPE_CALL,             /**< Call volume type */
+    AUDIO_VOLUME_TYPE_VOIP,             /**< VOIP volume type */
+    AUDIO_VOLUME_TYPE_SVOICE,           /**< SVOICE volume type */
+    AUDIO_VOLUME_TYPE_FIXED,            /**< Volume type for fixed acoustic level */
+    AUDIO_VOLUME_TYPE_EXT_JAVA,         /**< External system volume for Java */
+    AUDIO_VOLUME_TYPE_MAX,              /**< Volume type count */
+} audio_volume_t;
+
+typedef enum audio_gain {
+    AUDIO_GAIN_TYPE_DEFAULT,
+    AUDIO_GAIN_TYPE_DIALER,
+    AUDIO_GAIN_TYPE_TOUCH,
+    AUDIO_GAIN_TYPE_AF,
+    AUDIO_GAIN_TYPE_SHUTTER1,
+    AUDIO_GAIN_TYPE_SHUTTER2,
+    AUDIO_GAIN_TYPE_CAMCODING,
+    AUDIO_GAIN_TYPE_MIDI,
+    AUDIO_GAIN_TYPE_BOOTING,
+    AUDIO_GAIN_TYPE_VIDEO,
+    AUDIO_GAIN_TYPE_TTS,
+    AUDIO_GAIN_TYPE_MAX,
+} audio_gain_t;
+
+#if 0 // TODO : need to consider */
+typedef enum audio_volume_format {
+    AUDIO_VOLUME_FORMAT_LINEAR,     /**< Linear format (double) */
+    AUDIO_VOLUME_FORMAT_DECIBEL,    /**< Decibel format (double) */
+    AUDIO_VOLUME_FORMAT_PA,         /**< PulseAudio format (pa_volume_t) */
+} audio_volume_format_t;
+
+typedef struct audio_volume_value {
+    audio_volume_format format;
+    union {
+        double linear;
+        double decibel;
+        uint32_t pa;
+    } value;
+} audio_volume_value_t;
+#endif
+
+typedef struct audio_stream_info {
+    const char *name;
+    uint32_t samplerate;
+    uint8_t channels;
+    uint32_t volume_type;
+    uint32_t gain_type;
+} audio_stream_info_t ;
+
+
+/* Overall */
+
+typedef struct audio_info {
+    audio_device_info_t device;
+    audio_stream_info_t stream;
+} audio_info_t;
+
+int audio_get_revision (void);
+audio_return_t audio_init (void **userdata);
+audio_return_t audio_deinit (void **userdata);
+audio_return_t audio_reset (void **userdata);
+audio_return_t audio_get_volume_level_max (void *userdata, uint32_t volume_type, uint32_t *level);
+audio_return_t audio_get_volume_level (void *userdata, uint32_t volume_type, uint32_t *level);
+audio_return_t audio_get_volume_value (void *userdata, audio_info_t *info, uint32_t volume_type, uint32_t level, double *value);
+audio_return_t audio_set_volume_level (void *userdata, audio_info_t *info, uint32_t volume_type, uint32_t level);
+audio_return_t audio_get_mute (void *userdata, audio_info_t *info, uint32_t volume_type, uint32_t direction, uint32_t *mute);
+audio_return_t audio_set_mute (void *userdata, audio_info_t *info, uint32_t volume_type, uint32_t direction, uint32_t mute);
+audio_return_t audio_set_session (void *userdata, uint32_t session, uint32_t subsession);
+audio_return_t audio_set_route (void *userdata, uint32_t session, uint32_t subsession, uint32_t device_in, uint32_t device_out, uint32_t route_flag);
+
+
+#endif