summaryrefslogtreecommitdiff
path: root/tizen-audio-internal.h
blob: 6594f0efc783445cba6967487cfb71be1297dc52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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