lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /*****************************************************************************
|
| 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 |
|
| 30 | int audio_mix_devfd = MIX_DEV_INVALID_ID;
|
| 31 |
|
| 32 | int zDrvAudioMix_Write(unsigned char *pBuf, unsigned int uiLen)
|
| 33 | {
|
| 34 | if(audio_mix_devfd == MIX_DEV_INVALID_ID)
|
| 35 | {
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 36 | printf("audio /dev/audio_mix_device zDrvAudioMix_WriteOneFrame invalid dev!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 37 | return DRV_ERROR;
|
| 38 | }
|
| 39 |
|
| 40 | if(write(audio_mix_devfd, pBuf, uiLen) <= 0)
|
| 41 | {
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 42 | printf("audio /dev/audio_mix_device zDrvAudioMix_WriteOneFrame write failed!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 43 | return DRV_ERROR;
|
| 44 | }
|
| 45 |
|
| 46 | return DRV_SUCCESS;
|
| 47 | }
|
| 48 |
|
| 49 | int 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 55 | printf("audio /dev/audio_mix_device zDrvAudioMix_Open failed!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 56 | return DRV_ERROR;
|
| 57 | }
|
| 58 |
|
| 59 | if(ioctl(audio_mix_devfd, AUDIOMIX_IOCTL_SET_CFG, cfgParam) < 0)
|
| 60 | {
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 61 | printf("audio /dev/audio_mix_device set cfg failed!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 62 | goto err;
|
| 63 | }
|
| 64 |
|
| 65 | return DRV_SUCCESS;
|
| 66 | err:
|
| 67 | close(audio_mix_devfd);
|
| 68 | audio_mix_devfd = MIX_DEV_INVALID_ID;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 69 | printf("audio /dev/audio_mix_device zDrvAudioMix_Open failed!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 70 | return DRV_ERROR;
|
| 71 |
|
| 72 | }
|
| 73 |
|
| 74 | int zDrvAudioMix_Close(void)
|
| 75 | {
|
| 76 | if(audio_mix_devfd == MIX_DEV_INVALID_ID)
|
| 77 | {
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 78 | printf("audio /dev/audio_mix_device zDrvAudioMix_Close invalid dev!\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 79 | return DRV_ERROR;
|
| 80 | }
|
| 81 | close(audio_mix_devfd);
|
| 82 | audio_mix_devfd = MIX_DEV_INVALID_ID;
|
| 83 |
|
| 84 | return DRV_SUCCESS;
|
| 85 | }
|
| 86 |
|