2 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "AudioSessionManagerGStreamerTizen.h"
33 #include "GStreamerUtilities.h"
34 #include "GStreamerVersioning.h"
36 #if ENABLE(TIZEN_AUDIO_SESSION_MANAGER)
40 #if ENABLE(TIZEN_EXTENSIBLE_API)
41 #include "TizenExtensibleAPI.h"
46 void AudioSessionManagerGStreamerTizen::setVolumeSessionToMediaType()
48 volume_type_t volumeType;
49 #if ENABLE(TIZEN_EXTENSIBLE_API)
50 if (TizenExtensibleAPI::extensibleAPI().mediaStreamRecord()) {
51 mm_sound_volume_get_current_playing_type(&volumeType);
52 if (volumeType != VOLUME_TYPE_MEDIA)
53 mm_sound_volume_primary_type_set(VOLUME_TYPE_MEDIA);
58 void AudioSessionManagerGStreamerTizen::clearVolumeSessionFromMediaType()
60 #if ENABLE(TIZEN_EXTENSIBLE_API)
61 if (TizenExtensibleAPI::extensibleAPI().mediaStreamRecord())
62 mm_sound_volume_primary_type_clear();
66 AudioSessionManagerGStreamerTizen::AudioSessionManagerGStreamerTizen()
67 : m_eventType(ASM_EVENT_NONE)
70 , m_processIdentifier(getpid())
71 , m_sessionType(MM_SESSION_TYPE_NUM)
72 , m_stateType(ASM_STATE_NONE)
76 AudioSessionManagerGStreamerTizen::~AudioSessionManagerGStreamerTizen()
78 unregisterAudioSessionManager();
81 bool AudioSessionManagerGStreamerTizen::registerAudioSessionManager(MMSessionType sessiontype, ASM_sound_cb_t notifyCallback, void* callbackData)
83 int error = _mm_session_util_read_type(m_processIdentifier, reinterpret_cast<int*>(&m_sessionType));
85 m_sessionType = sessiontype;
86 error = mm_session_init((int)m_sessionType);
88 LOG_MEDIA_MESSAGE("mm_session_init() failed.");
93 m_eventType = interpretSessionToEvent(m_sessionType);
94 m_notifyCallback = notifyCallback;
96 if (!ASM_register_sound(m_processIdentifier, &m_handle, m_eventType, m_stateType, m_notifyCallback, callbackData, ASM_RESOURCE_NONE, &error)) {
97 LOG_MEDIA_MESSAGE("register is failed. errcode = 0x%X", error);
104 bool AudioSessionManagerGStreamerTizen::unregisterAudioSessionManager()
107 if (!ASM_unregister_sound(m_handle, m_eventType, &error)) {
108 LOG_MEDIA_MESSAGE("unregister() is failed 0x%X\n", error);
115 int AudioSessionManagerGStreamerTizen::getSoundState(ASM_sound_states_t* state)
118 if (!ASM_get_sound_state( m_handle, m_eventType, state, &error))
119 LOG_MEDIA_MESSAGE("getSoundState state is failed 0x%X", error);
124 bool AudioSessionManagerGStreamerTizen::setSoundState(ASM_sound_states_t state)
127 if (!ASM_set_sound_state(m_handle, m_eventType, state, ASM_RESOURCE_NONE, &error)) {
128 LOG_MEDIA_MESSAGE("setSoundState state = [%d] failed 0x%X", state, error);
135 ASM_sound_events_t AudioSessionManagerGStreamerTizen::interpretSessionToEvent(MMSessionType sessionType)
137 switch (sessionType) {
138 case MM_SESSION_TYPE_SHARE:
139 return ASM_EVENT_SHARE_MMPLAYER;
140 case MM_SESSION_TYPE_EXCLUSIVE:
141 return ASM_EVENT_EXCLUSIVE_MMPLAYER;
143 return ASM_EVENT_NONE;