blob: 35a8c31e9f4bc4837077d455f639ce80a40461b3 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*****************************************************************************
2** °æÈ¨ËùÓÐ (C)2015, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
3**
4** ÎļþÃû³Æ: mix.c
5** Îļþ±êʶ:
6** ÄÚÈÝÕªÒª:
7** ʹÓ÷½·¨:
8**
9** ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
10** -----------------------------------------------------------------------------
11** 2019/09/25 V1.0 Create xxq ´´½¨
12**
13* ******************************************************************************/
14
15#include <stdio.h>
16#include <unistd.h>
17#include <string.h>
18#include <stdlib.h>
19
20#include <stdint.h>
21#include <linux/volte_drv.h>
22#include <sys/ioctl.h>
23#include <fcntl.h>
24
25#define MIX_DEV_INVALID_ID (-1)
26#define DRV_SUCCESS 0
27#define DRV_ERROR (-1)
28#define AUDIO_MIX_DEV_NAME "/dev/audio_mix_device"
29
30int audio_mix_devfd = MIX_DEV_INVALID_ID;
31
32int zDrvAudioMix_Write(unsigned char *pBuf, unsigned int uiLen)
33{
34 if(audio_mix_devfd == MIX_DEV_INVALID_ID)
35 {
xf.li742dd022023-06-08 01:43:32 -070036 printf("audio /dev/audio_mix_device zDrvAudioMix_WriteOneFrame invalid dev!\n");
lh9ed821d2023-04-07 01:36:19 -070037 return DRV_ERROR;
38 }
39
40 if(write(audio_mix_devfd, pBuf, uiLen) <= 0)
41 {
xf.li742dd022023-06-08 01:43:32 -070042 printf("audio /dev/audio_mix_device zDrvAudioMix_WriteOneFrame write failed!\n");
lh9ed821d2023-04-07 01:36:19 -070043 return DRV_ERROR;
44 }
45
46 return DRV_SUCCESS;
47}
48
49int zDrvAudioMix_Open(T_ZDrvAudioMix_Cfg *cfgParam)
50{
51 audio_mix_devfd = open(AUDIO_MIX_DEV_NAME, O_RDWR);
52 printf("open end! audio_mix_devfd=%d, audioType=%d, sample_rate=%d\n", audio_mix_devfd, cfgParam->audioType, cfgParam->sample_rate);
53 if(audio_mix_devfd < 0)
54 {
xf.li742dd022023-06-08 01:43:32 -070055 printf("audio /dev/audio_mix_device zDrvAudioMix_Open failed!\n");
lh9ed821d2023-04-07 01:36:19 -070056 return DRV_ERROR;
57 }
58
59 if(ioctl(audio_mix_devfd, AUDIOMIX_IOCTL_SET_CFG, cfgParam) < 0)
60 {
xf.li742dd022023-06-08 01:43:32 -070061 printf("audio /dev/audio_mix_device set cfg failed!\n");
lh9ed821d2023-04-07 01:36:19 -070062 goto err;
63 }
64
65 return DRV_SUCCESS;
66err:
67 close(audio_mix_devfd);
68 audio_mix_devfd = MIX_DEV_INVALID_ID;
xf.li742dd022023-06-08 01:43:32 -070069 printf("audio /dev/audio_mix_device zDrvAudioMix_Open failed!\n");
lh9ed821d2023-04-07 01:36:19 -070070 return DRV_ERROR;
71
72}
73
74int zDrvAudioMix_Close(void)
75{
76 if(audio_mix_devfd == MIX_DEV_INVALID_ID)
77 {
xf.li742dd022023-06-08 01:43:32 -070078 printf("audio /dev/audio_mix_device zDrvAudioMix_Close invalid dev!\n");
lh9ed821d2023-04-07 01:36:19 -070079 return DRV_ERROR;
80 }
81 close(audio_mix_devfd);
82 audio_mix_devfd = MIX_DEV_INVALID_ID;
83
84 return DRV_SUCCESS;
85}
86