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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
|
/*
* Copyright (c) 2010-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/uaccess.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/dma-mapping.h>
#include <linux/slab.h>
#include <linux/msm_audio_aac.h>
#include <linux/compat.h>
#include <asm/atomic.h>
#include <asm/ioctls.h>
#include "audio_utils.h"
/* Buffer with meta*/
#define PCM_BUF_SIZE (4096 + sizeof(struct meta_in))
/* Maximum 5 frames in buffer with meta */
#define FRAME_SIZE (1 + ((1536+sizeof(struct meta_out_dsp)) * 5))
#define AAC_FORMAT_ADTS 65535
#define MAX_SAMPLE_RATE_384K 384000
static long aac_in_ioctl_shared(struct file *file, unsigned int cmd, void *arg)
{
struct q6audio_in *audio = file->private_data;
int rc = 0;
int cnt = 0;
switch (cmd) {
case AUDIO_START: {
struct msm_audio_aac_enc_config *enc_cfg;
struct msm_audio_aac_config *aac_config;
uint32_t aac_mode = AAC_ENC_MODE_AAC_LC;
enc_cfg = audio->enc_cfg;
aac_config = audio->codec_cfg;
/* ENCODE CFG (after new set of API's are published )bharath*/
pr_debug("%s:session id %d: default buf alloc[%d]\n", __func__,
audio->ac->session, audio->buf_alloc);
if (audio->enabled == 1) {
pr_info("%s:AUDIO_START already over\n", __func__);
rc = 0;
break;
}
if (audio->opened) {
rc = audio_in_buf_alloc(audio);
if (rc < 0) {
pr_err("%s:session id %d: buffer allocation failed\n",
__func__, audio->ac->session);
break;
}
} else {
if (audio->feedback == NON_TUNNEL_MODE) {
pr_debug("%s: starting in non_tunnel mode",
__func__);
rc = q6asm_open_read_write(audio->ac,
FORMAT_MPEG4_AAC, FORMAT_LINEAR_PCM);
if (rc < 0) {
pr_err("%s:open read write failed\n",
__func__);
break;
}
}
if (audio->feedback == TUNNEL_MODE) {
pr_debug("%s: starting in tunnel mode",
__func__);
rc = q6asm_open_read(audio->ac,
FORMAT_MPEG4_AAC);
if (rc < 0) {
pr_err("%s:open read failed\n",
__func__);
break;
}
}
audio->stopped = 0;
}
pr_debug("%s:sbr_ps_flag = %d, sbr_flag = %d\n", __func__,
aac_config->sbr_ps_on_flag, aac_config->sbr_on_flag);
if (aac_config->sbr_ps_on_flag)
aac_mode = AAC_ENC_MODE_EAAC_P;
else if (aac_config->sbr_on_flag)
aac_mode = AAC_ENC_MODE_AAC_P;
else
aac_mode = AAC_ENC_MODE_AAC_LC;
rc = q6asm_enc_cfg_blk_aac(audio->ac,
audio->buf_cfg.frames_per_buf,
enc_cfg->sample_rate,
enc_cfg->channels,
enc_cfg->bit_rate,
aac_mode,
enc_cfg->stream_format);
if (rc < 0) {
pr_err("%s:session id %d: cmd media format block"
"failed\n", __func__, audio->ac->session);
break;
}
if (audio->feedback == NON_TUNNEL_MODE) {
rc = q6asm_media_format_block_pcm(audio->ac,
audio->pcm_cfg.sample_rate,
audio->pcm_cfg.channel_count);
if (rc < 0) {
pr_err("%s:session id %d: media format block"
"failed\n", __func__, audio->ac->session);
break;
}
}
rc = audio_in_enable(audio);
if (!rc) {
audio->enabled = 1;
} else {
audio->enabled = 0;
pr_err("%s:session id %d: Audio Start procedure"
"failed rc=%d\n", __func__, audio->ac->session, rc);
break;
}
while (cnt++ < audio->str_cfg.buffer_count)
q6asm_read(audio->ac);
pr_debug("%s:session id %d: AUDIO_START success enable[%d]\n",
__func__, audio->ac->session, audio->enabled);
break;
}
case AUDIO_STOP: {
pr_debug("%s:session id %d: Rxed AUDIO_STOP\n", __func__,
audio->ac->session);
rc = audio_in_disable(audio);
if (rc < 0) {
pr_err("%s:session id %d: Audio Stop procedure failed"
"rc=%d\n", __func__, audio->ac->session, rc);
break;
}
break;
}
case AUDIO_GET_AAC_ENC_CONFIG: {
struct msm_audio_aac_enc_config *cfg;
struct msm_audio_aac_enc_config *enc_cfg;
cfg = (struct msm_audio_aac_enc_config *)arg;
if (cfg == NULL) {
pr_err("%s: NULL config pointer for %s\n",
__func__, "AUDIO_GET_AAC_CONFIG");
rc = -EINVAL;
break;
}
memset(cfg, 0, sizeof(*cfg));
enc_cfg = audio->enc_cfg;
if (enc_cfg->channels == CH_MODE_MONO)
cfg->channels = 1;
else
cfg->channels = 2;
cfg->sample_rate = enc_cfg->sample_rate;
cfg->bit_rate = enc_cfg->bit_rate;
switch (enc_cfg->stream_format) {
case 0x00:
cfg->stream_format = AUDIO_AAC_FORMAT_ADTS;
break;
case 0x01:
cfg->stream_format = AUDIO_AAC_FORMAT_LOAS;
break;
case 0x02:
cfg->stream_format = AUDIO_AAC_FORMAT_ADIF;
break;
default:
case 0x03:
cfg->stream_format = AUDIO_AAC_FORMAT_RAW;
}
pr_debug("%s:session id %d: Get-aac-cfg: format=%d sr=%d"
"bitrate=%d\n", __func__, audio->ac->session,
cfg->stream_format, cfg->sample_rate, cfg->bit_rate);
break;
}
case AUDIO_SET_AAC_ENC_CONFIG: {
struct msm_audio_aac_enc_config *cfg;
struct msm_audio_aac_enc_config *enc_cfg;
uint32_t min_bitrate, max_bitrate;
cfg = (struct msm_audio_aac_enc_config *)arg;
if (cfg == NULL) {
pr_err("%s: NULL config pointer for %s\n",
"AUDIO_SET_AAC_ENC_CONFIG", __func__);
rc = -EINVAL;
break;
}
enc_cfg = audio->enc_cfg;
pr_debug("%s:session id %d: Set-aac-cfg: stream=%d\n", __func__,
audio->ac->session, cfg->stream_format);
switch (cfg->stream_format) {
case AUDIO_AAC_FORMAT_ADTS:
enc_cfg->stream_format = 0x00;
break;
case AUDIO_AAC_FORMAT_LOAS:
enc_cfg->stream_format = 0x01;
break;
case AUDIO_AAC_FORMAT_ADIF:
enc_cfg->stream_format = 0x02;
break;
case AUDIO_AAC_FORMAT_RAW:
enc_cfg->stream_format = 0x03;
break;
default:
pr_err("%s:session id %d: unsupported AAC format %d\n",
__func__, audio->ac->session,
cfg->stream_format);
rc = -EINVAL;
break;
}
if (cfg->channels == 1) {
cfg->channels = CH_MODE_MONO;
} else if (cfg->channels == 2) {
cfg->channels = CH_MODE_STEREO;
} else {
rc = -EINVAL;
break;
}
if (cfg->sample_rate > MAX_SAMPLE_RATE_384K) {
pr_err("%s: ERROR: invalid sample rate = %u",
__func__, cfg->sample_rate);
rc = -EINVAL;
break;
}
min_bitrate = ((cfg->sample_rate)*(cfg->channels))/2;
/* This calculation should be based on AAC mode. But we cannot
* get AAC mode in this setconfig. min_bitrate's logical max
* value is 24000. So if min_bitrate is higher than 24000,
* choose 24000.
*/
if (min_bitrate > 24000)
min_bitrate = 24000;
max_bitrate = 6*(cfg->sample_rate)*(cfg->channels);
if (max_bitrate > 192000)
max_bitrate = 192000;
if ((cfg->bit_rate < min_bitrate) ||
(cfg->bit_rate > max_bitrate)) {
pr_err("%s: bitrate permissible: max=%d, min=%d\n",
__func__, max_bitrate, min_bitrate);
pr_err("%s: ERROR in setting bitrate = %d\n",
__func__, cfg->bit_rate);
rc = -EINVAL;
break;
}
enc_cfg->sample_rate = cfg->sample_rate;
enc_cfg->channels = cfg->channels;
enc_cfg->bit_rate = cfg->bit_rate;
pr_debug("%s:session id %d: Set-aac-cfg:SR= 0x%x ch=0x%x"
"bitrate=0x%x, format(adts/raw) = %d\n",
__func__, audio->ac->session, enc_cfg->sample_rate,
enc_cfg->channels, enc_cfg->bit_rate,
enc_cfg->stream_format);
break;
}
case AUDIO_SET_AAC_CONFIG: {
struct msm_audio_aac_config *aac_cfg;
struct msm_audio_aac_config *audio_aac_cfg;
struct msm_audio_aac_enc_config *enc_cfg;
enc_cfg = audio->enc_cfg;
audio_aac_cfg = audio->codec_cfg;
aac_cfg = (struct msm_audio_aac_config *)arg;
if (aac_cfg == NULL) {
pr_err("%s: NULL config pointer %s\n",
__func__, "AUDIO_SET_AAC_CONFIG");
rc = -EINVAL;
break;
}
pr_debug("%s:session id %d: AUDIO_SET_AAC_CONFIG: sbr_flag = %d sbr_ps_flag = %d\n",
__func__, audio->ac->session, aac_cfg->sbr_on_flag,
aac_cfg->sbr_ps_on_flag);
audio_aac_cfg->sbr_on_flag = aac_cfg->sbr_on_flag;
audio_aac_cfg->sbr_ps_on_flag = aac_cfg->sbr_ps_on_flag;
if ((audio_aac_cfg->sbr_on_flag == 1) ||
(audio_aac_cfg->sbr_ps_on_flag == 1)) {
if (enc_cfg->sample_rate < 24000) {
pr_err("%s: ERROR in setting samplerate = %d"
"\n", __func__, enc_cfg->sample_rate);
rc = -EINVAL;
break;
}
}
break;
}
default:
pr_err("%s: Unknown ioctl cmd = %d", __func__, cmd);
rc = -EINVAL;
}
return rc;
}
static long aac_in_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
struct q6audio_in *audio = file->private_data;
int rc = 0;
switch (cmd) {
case AUDIO_START:
case AUDIO_STOP: {
rc = aac_in_ioctl_shared(file, cmd, NULL);
break;
}
case AUDIO_GET_AAC_ENC_CONFIG: {
struct msm_audio_aac_enc_config cfg;
rc = aac_in_ioctl_shared(file, cmd, &cfg);
if (rc) {
pr_err("%s:AUDIO_GET_AAC_ENC_CONFIG failed. rc=%d\n",
__func__, rc);
break;
}
if (copy_to_user((void *)arg, &cfg, sizeof(cfg))) {
pr_err("%s: copy_to_user for AUDIO_GET_AAC_ENC_CONFIG failed\n",
__func__);
rc = -EFAULT;
}
break;
}
case AUDIO_SET_AAC_ENC_CONFIG: {
struct msm_audio_aac_enc_config cfg;
if (copy_from_user(&cfg, (void *)arg, sizeof(cfg))) {
pr_err("%s: copy_from_user for AUDIO_SET_AAC_ENC_CONFIG failed\n",
__func__);
rc = -EFAULT;
break;
}
rc = aac_in_ioctl_shared(file, cmd, &cfg);
if (rc)
pr_err("%s:AUDIO_SET_AAC_ENC_CONFIG failed. rc=%d\n",
__func__, rc);
break;
}
case AUDIO_GET_AAC_CONFIG: {
if (copy_to_user((void *)arg, &audio->codec_cfg,
sizeof(struct msm_audio_aac_config))) {
pr_err("%s: copy_to_user for AUDIO_GET_AAC_CONFIG failed\n",
__func__);
rc = -EFAULT;
break;
}
break;
}
case AUDIO_SET_AAC_CONFIG: {
struct msm_audio_aac_config aac_cfg;
if (copy_from_user(&aac_cfg, (void *)arg,
sizeof(struct msm_audio_aac_config))) {
pr_err("%s: copy_to_user for AUDIO_SET_CONFIG failed\n",
__func__);
rc = -EFAULT;
break;
}
rc = aac_in_ioctl_shared(file, cmd, &aac_cfg);
if (rc)
pr_err("%s:AUDIO_SET_AAC_CONFIG failed. rc=%d\n",
__func__, rc);
break;
}
default:
pr_err("%s: Unknown ioctl cmd=%d\n", __func__, cmd);
rc = -EINVAL;
}
return rc;
}
#ifdef CONFIG_COMPAT
struct msm_audio_aac_enc_config32 {
u32 channels;
u32 sample_rate;
u32 bit_rate;
u32 stream_format;
};
struct msm_audio_aac_config32 {
s16 format;
u16 audio_object;
u16 ep_config; /* 0 ~ 3 useful only obj = ERLC */
u16 aac_section_data_resilience_flag;
u16 aac_scalefactor_data_resilience_flag;
u16 aac_spectral_data_resilience_flag;
u16 sbr_on_flag;
u16 sbr_ps_on_flag;
u16 dual_mono_mode;
u16 channel_configuration;
u16 sample_rate;
};
enum {
AUDIO_SET_AAC_CONFIG_32 = _IOW(AUDIO_IOCTL_MAGIC,
(AUDIO_MAX_COMMON_IOCTL_NUM+0), struct msm_audio_aac_config32),
AUDIO_GET_AAC_CONFIG_32 = _IOR(AUDIO_IOCTL_MAGIC,
(AUDIO_MAX_COMMON_IOCTL_NUM+1), struct msm_audio_aac_config32),
AUDIO_SET_AAC_ENC_CONFIG_32 = _IOW(AUDIO_IOCTL_MAGIC,
(AUDIO_MAX_COMMON_IOCTL_NUM+3), struct msm_audio_aac_enc_config32),
AUDIO_GET_AAC_ENC_CONFIG_32 = _IOR(AUDIO_IOCTL_MAGIC,
(AUDIO_MAX_COMMON_IOCTL_NUM+4), struct msm_audio_aac_enc_config32)
};
static long aac_in_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
struct q6audio_in *audio = file->private_data;
int rc = 0;
switch (cmd) {
case AUDIO_START:
case AUDIO_STOP: {
rc = aac_in_ioctl_shared(file, cmd, NULL);
break;
}
case AUDIO_GET_AAC_ENC_CONFIG_32: {
struct msm_audio_aac_enc_config cfg;
struct msm_audio_aac_enc_config32 cfg_32;
memset(&cfg_32, 0, sizeof(cfg_32));
cmd = AUDIO_GET_AAC_ENC_CONFIG;
rc = aac_in_ioctl_shared(file, cmd, &cfg);
if (rc) {
pr_err("%s:AUDIO_GET_AAC_ENC_CONFIG_32 failed. Rc= %d\n",
__func__, rc);
break;
}
cfg_32.channels = cfg.channels;
cfg_32.sample_rate = cfg.sample_rate;
cfg_32.bit_rate = cfg.bit_rate;
cfg_32.stream_format = cfg.stream_format;
if (copy_to_user((void *)arg, &cfg_32, sizeof(cfg_32))) {
pr_err("%s: copy_to_user for AUDIO_GET_AAC_ENC_CONFIG_32 failed\n",
__func__);
rc = -EFAULT;
}
break;
}
case AUDIO_SET_AAC_ENC_CONFIG_32: {
struct msm_audio_aac_enc_config cfg;
struct msm_audio_aac_enc_config32 cfg_32;
if (copy_from_user(&cfg_32, (void *)arg, sizeof(cfg_32))) {
pr_err("%s: copy_from_user for AUDIO_GET_AAC_ENC_CONFIG_32 failed\n",
__func__);
rc = -EFAULT;
break;
}
cfg.channels = cfg_32.channels;
cfg.sample_rate = cfg_32.sample_rate;
cfg.bit_rate = cfg_32.bit_rate;
cfg.stream_format = cfg_32.stream_format;
/* The command should be converted from 32 bit to normal
* before the shared ioctl is called as shared ioctl
* can process only normal commands */
cmd = AUDIO_SET_AAC_ENC_CONFIG;
rc = aac_in_ioctl_shared(file, cmd, &cfg);
if (rc)
pr_err("%s:AUDIO_SET_AAC_ENC_CONFIG_32 failed. rc=%d\n",
__func__, rc);
break;
}
case AUDIO_GET_AAC_CONFIG_32: {
struct msm_audio_aac_config *aac_config;
struct msm_audio_aac_config32 aac_config_32;
aac_config = (struct msm_audio_aac_config *)audio->codec_cfg;
aac_config_32.format = aac_config->format;
aac_config_32.audio_object = aac_config->audio_object;
aac_config_32.ep_config = aac_config->ep_config;
aac_config_32.aac_section_data_resilience_flag =
aac_config->aac_section_data_resilience_flag;
aac_config_32.aac_scalefactor_data_resilience_flag =
aac_config->aac_scalefactor_data_resilience_flag;
aac_config_32.aac_spectral_data_resilience_flag =
aac_config->aac_spectral_data_resilience_flag;
aac_config_32.sbr_on_flag = aac_config->sbr_on_flag;
aac_config_32.sbr_ps_on_flag = aac_config->sbr_ps_on_flag;
aac_config_32.dual_mono_mode = aac_config->dual_mono_mode;
aac_config_32.channel_configuration =
aac_config->channel_configuration;
aac_config_32.sample_rate = aac_config->sample_rate;
if (copy_to_user((void *)arg, &aac_config_32,
sizeof(aac_config_32))) {
pr_err("%s: copy_to_user for AUDIO_GET_AAC_CONFIG_32 failed\n",
__func__);
rc = -EFAULT;
break;
}
break;
}
case AUDIO_SET_AAC_CONFIG_32: {
struct msm_audio_aac_config aac_cfg;
struct msm_audio_aac_config32 aac_cfg_32;
if (copy_from_user(&aac_cfg_32, (void *)arg,
sizeof(aac_cfg_32))) {
pr_err("%s: copy_from_user for AUDIO_SET_AAC_CONFIG_32 failed\n",
__func__);
rc = -EFAULT;
break;
}
aac_cfg.format = aac_cfg_32.format;
aac_cfg.audio_object = aac_cfg_32.audio_object;
aac_cfg.ep_config = aac_cfg_32.ep_config;
aac_cfg.aac_section_data_resilience_flag =
aac_cfg_32.aac_section_data_resilience_flag;
aac_cfg.aac_scalefactor_data_resilience_flag =
aac_cfg_32.aac_scalefactor_data_resilience_flag;
aac_cfg.aac_spectral_data_resilience_flag =
aac_cfg_32.aac_spectral_data_resilience_flag;
aac_cfg.sbr_on_flag = aac_cfg_32.sbr_on_flag;
aac_cfg.sbr_ps_on_flag = aac_cfg_32.sbr_ps_on_flag;
aac_cfg.dual_mono_mode = aac_cfg_32.dual_mono_mode;
aac_cfg.channel_configuration =
aac_cfg_32.channel_configuration;
aac_cfg.sample_rate = aac_cfg_32.sample_rate;
cmd = AUDIO_SET_AAC_CONFIG;
rc = aac_in_ioctl_shared(file, cmd, &aac_cfg);
if (rc)
pr_err("%s:AUDIO_SET_AAC_CONFIG failed. Rc= %d\n",
__func__, rc);
break;
}
default:
pr_err("%s: Unknown ioctl cmd = %d\n", __func__, cmd);
rc = -EINVAL;
}
return rc;
}
#else
#define aac_in_compat_ioctl NULL
#endif
static int aac_in_open(struct inode *inode, struct file *file)
{
struct q6audio_in *audio = NULL;
struct msm_audio_aac_enc_config *enc_cfg;
struct msm_audio_aac_config *aac_config;
int rc = 0;
audio = kzalloc(sizeof(struct q6audio_in), GFP_KERNEL);
if (audio == NULL) {
pr_err("%s: Could not allocate memory for aac"
"driver\n", __func__);
return -ENOMEM;
}
/* Allocate memory for encoder config param */
audio->enc_cfg = kzalloc(sizeof(struct msm_audio_aac_enc_config),
GFP_KERNEL);
if (audio->enc_cfg == NULL) {
pr_err("%s:session id %d: Could not allocate memory for aac"
"config param\n", __func__, audio->ac->session);
kfree(audio);
return -ENOMEM;
}
enc_cfg = audio->enc_cfg;
audio->codec_cfg = kzalloc(sizeof(struct msm_audio_aac_config),
GFP_KERNEL);
if (audio->codec_cfg == NULL) {
pr_err("%s:session id %d: Could not allocate memory for aac"
"config\n", __func__, audio->ac->session);
kfree(audio->enc_cfg);
kfree(audio);
return -ENOMEM;
}
aac_config = audio->codec_cfg;
mutex_init(&audio->lock);
mutex_init(&audio->read_lock);
mutex_init(&audio->write_lock);
spin_lock_init(&audio->dsp_lock);
init_waitqueue_head(&audio->read_wait);
init_waitqueue_head(&audio->write_wait);
/* Settings will be re-config at AUDIO_SET_CONFIG,
* but at least we need to have initial config
*/
audio->str_cfg.buffer_size = FRAME_SIZE;
audio->str_cfg.buffer_count = FRAME_NUM;
audio->min_frame_size = 1536;
audio->max_frames_per_buf = 5;
enc_cfg->sample_rate = 8000;
enc_cfg->channels = 1;
enc_cfg->bit_rate = 16000;
enc_cfg->stream_format = 0x00;/* 0:ADTS, 3:RAW */
audio->buf_cfg.meta_info_enable = 0x01;
audio->buf_cfg.frames_per_buf = 0x01;
audio->pcm_cfg.buffer_count = PCM_BUF_COUNT;
audio->pcm_cfg.buffer_size = PCM_BUF_SIZE;
aac_config->format = AUDIO_AAC_FORMAT_ADTS;
aac_config->audio_object = AUDIO_AAC_OBJECT_LC;
aac_config->sbr_on_flag = 0;
aac_config->sbr_ps_on_flag = 0;
aac_config->channel_configuration = 1;
audio->ac = q6asm_audio_client_alloc((app_cb)q6asm_in_cb,
(void *)audio);
if (!audio->ac) {
pr_err("%s: Could not allocate memory for"
"audio client\n", __func__);
kfree(audio->enc_cfg);
kfree(audio->codec_cfg);
kfree(audio);
return -ENOMEM;
}
/* open aac encoder in tunnel mode */
audio->buf_cfg.frames_per_buf = 0x01;
if ((file->f_mode & FMODE_WRITE) &&
(file->f_mode & FMODE_READ)) {
audio->feedback = NON_TUNNEL_MODE;
rc = q6asm_open_read_write(audio->ac, FORMAT_MPEG4_AAC,
FORMAT_LINEAR_PCM);
if (rc < 0) {
pr_err("%s:session id %d: NT Open failed rc=%d\n",
__func__, audio->ac->session, rc);
rc = -ENODEV;
goto fail;
}
audio->buf_cfg.meta_info_enable = 0x01;
pr_info("%s:session id %d: NT mode encoder success\n", __func__,
audio->ac->session);
} else if (!(file->f_mode & FMODE_WRITE) &&
(file->f_mode & FMODE_READ)) {
audio->feedback = TUNNEL_MODE;
rc = q6asm_open_read(audio->ac, FORMAT_MPEG4_AAC);
if (rc < 0) {
pr_err("%s:session id %d: Tunnel Open failed rc=%d\n",
__func__, audio->ac->session, rc);
rc = -ENODEV;
goto fail;
}
/* register for tx overflow (valid for tunnel mode only) */
rc = q6asm_reg_tx_overflow(audio->ac, 0x01);
if (rc < 0) {
pr_err("%s:session id %d: TX Overflow registration"
"failed rc=%d\n", __func__,
audio->ac->session, rc);
rc = -ENODEV;
goto fail;
}
audio->buf_cfg.meta_info_enable = 0x00;
pr_info("%s:session id %d: T mode encoder success\n", __func__,
audio->ac->session);
} else {
pr_err("%s:session id %d: Unexpected mode\n", __func__,
audio->ac->session);
rc = -EACCES;
goto fail;
}
audio->opened = 1;
audio->reset_event = false;
atomic_set(&audio->in_count, PCM_BUF_COUNT);
atomic_set(&audio->out_count, 0x00);
audio->enc_compat_ioctl = aac_in_compat_ioctl;
audio->enc_ioctl = aac_in_ioctl;
file->private_data = audio;
pr_info("%s:session id %d: success\n", __func__, audio->ac->session);
return 0;
fail:
q6asm_audio_client_free(audio->ac);
kfree(audio->enc_cfg);
kfree(audio->codec_cfg);
kfree(audio);
return rc;
}
static const struct file_operations audio_in_fops = {
.owner = THIS_MODULE,
.open = aac_in_open,
.release = audio_in_release,
.read = audio_in_read,
.write = audio_in_write,
.unlocked_ioctl = audio_in_ioctl,
.compat_ioctl = audio_in_compat_ioctl
};
struct miscdevice audio_aac_in_misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = "msm_aac_in",
.fops = &audio_in_fops,
};
static int __init aac_in_init(void)
{
return misc_register(&audio_aac_in_misc);
}
device_initcall(aac_in_init);
|