• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "audio_platform_base.h"
10 #include "audio_core.h"
11 
12 #define HDF_LOG_TAG audio_platform_base
13 
PlatformDataFromDevice(const struct AudioCard * card)14 struct PlatformData *PlatformDataFromDevice(const struct AudioCard *card)
15 {
16     if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL) {
17         AUDIO_DRIVER_LOG_ERR("param is null.");
18         return NULL;
19     }
20     return card->rtd->platform->devData;
21 }
22 
PlatformCreatePlatformHost(const struct AudioCard * card,struct PlatformHost ** platformHost)23 int32_t PlatformCreatePlatformHost(const struct AudioCard *card, struct PlatformHost **platformHost)
24 {
25     if (platformHost == NULL) {
26         AUDIO_DRIVER_LOG_ERR("input param platformHost is invalid.");
27         return HDF_ERR_INVALID_PARAM;
28     }
29     if (card == NULL || card->rtd == NULL || card->rtd->platform == NULL) {
30         AUDIO_DRIVER_LOG_ERR("input para is NULL.");
31         return HDF_FAILURE;
32     }
33 
34     *platformHost = PlatformHostFromDevice(card->rtd->platform->device);
35     if (*platformHost == NULL) {
36         AUDIO_DRIVER_LOG_ERR("PlatformHostFromDevice faile.");
37         return HDF_FAILURE;
38     }
39     return HDF_SUCCESS;
40 }
41 
AudioDataBigEndianChange(char * srcData,uint32_t audioLen,enum DataBitWidth bitWidth)42 int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum DataBitWidth bitWidth)
43 {
44     uint64_t i;
45     uint16_t framesize;
46     char temp;
47     if (srcData == NULL) {
48         AUDIO_DRIVER_LOG_ERR("srcData is NULL.");
49         return HDF_FAILURE;
50     }
51 
52     switch (bitWidth) {
53         case DATA_BIT_WIDTH8:
54             framesize = 1; /* 1 byte */
55             break;
56         case DATA_BIT_WIDTH16:
57             framesize = 2; /* 2 bytes */
58             break;
59         case DATA_BIT_WIDTH24:
60             framesize = 3; /* 3 bytes */
61             break;
62         default:
63             framesize = 2; /* default 2 bytes */
64             break;
65     }
66 
67     for (i = 0; i < audioLen; i += framesize) {
68         temp = srcData[i];
69         srcData[i] = srcData[i + framesize - 1];
70         srcData[i + framesize - 1] = temp;
71     }
72     AUDIO_DRIVER_LOG_DEBUG("audioLen = %d\n", audioLen);
73     return HDF_SUCCESS;
74 }
75