1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "audio_process_config.h" 17 18 #include <sstream> 19 20 #include "audio_errors.h" 21 #include "audio_log.h" 22 23 namespace OHOS { 24 namespace AudioStandard { WriteConfigToParcel(const AudioProcessConfig & config,MessageParcel & parcel)25int32_t ProcessConfig::WriteConfigToParcel(const AudioProcessConfig &config, MessageParcel &parcel) 26 { 27 // AppInfo 28 parcel.WriteInt32(config.appInfo.appUid); 29 parcel.WriteUint32(config.appInfo.appTokenId); 30 parcel.WriteInt32(config.appInfo.appPid); 31 32 // AudioStreamInfo 33 parcel.WriteInt32(config.streamInfo.samplingRate); 34 parcel.WriteInt32(config.streamInfo.encoding); 35 parcel.WriteInt32(config.streamInfo.format); 36 parcel.WriteInt32(config.streamInfo.channels); 37 parcel.WriteUint64(config.streamInfo.channelLayout); 38 39 // AudioMode 40 parcel.WriteInt32(config.audioMode); 41 42 // AudioRendererInfo 43 parcel.WriteInt32(config.rendererInfo.contentType); 44 parcel.WriteInt32(config.rendererInfo.streamUsage); 45 parcel.WriteInt32(config.rendererInfo.rendererFlags); 46 47 //AudioPrivacyType 48 parcel.WriteInt32(config.privacyType); 49 50 // AudioCapturerInfo 51 parcel.WriteInt32(config.capturerInfo.sourceType); 52 parcel.WriteInt32(config.capturerInfo.capturerFlags); 53 54 // streamType 55 parcel.WriteInt32(config.streamType); 56 57 // Recorder only 58 parcel.WriteBool(config.isInnerCapturer); 59 parcel.WriteBool(config.isWakeupCapturer); 60 61 return SUCCESS; 62 } 63 ReadConfigFromParcel(AudioProcessConfig & config,MessageParcel & parcel)64int32_t ProcessConfig::ReadConfigFromParcel(AudioProcessConfig &config, MessageParcel &parcel) 65 { 66 // AppInfo 67 config.appInfo.appUid = parcel.ReadInt32(); 68 config.appInfo.appTokenId = parcel.ReadUint32(); 69 config.appInfo.appPid = parcel.ReadInt32(); 70 71 // AudioStreamInfo 72 config.streamInfo.samplingRate = static_cast<AudioSamplingRate>(parcel.ReadInt32()); 73 config.streamInfo.encoding = static_cast<AudioEncodingType>(parcel.ReadInt32()); 74 config.streamInfo.format = static_cast<AudioSampleFormat>(parcel.ReadInt32()); 75 config.streamInfo.channels = static_cast<AudioChannel>(parcel.ReadInt32()); 76 config.streamInfo.channelLayout = static_cast<AudioChannelLayout>(parcel.ReadUint64()); 77 78 // AudioMode 79 config.audioMode = static_cast<AudioMode>(parcel.ReadInt32()); 80 81 // AudioRendererInfo 82 config.rendererInfo.contentType = static_cast<ContentType>(parcel.ReadInt32()); 83 config.rendererInfo.streamUsage = static_cast<StreamUsage>(parcel.ReadInt32()); 84 config.rendererInfo.rendererFlags = parcel.ReadInt32(); 85 86 //AudioPrivacyType 87 config.privacyType = static_cast<AudioPrivacyType>(parcel.ReadInt32()); 88 89 // AudioCapturerInfo 90 config.capturerInfo.sourceType = static_cast<SourceType>(parcel.ReadInt32()); 91 config.capturerInfo.capturerFlags = parcel.ReadInt32(); 92 93 // streamType 94 config.streamType = static_cast<AudioStreamType>(parcel.ReadInt32()); 95 96 // Recorder only 97 config.isInnerCapturer = parcel.ReadBool(); 98 config.isWakeupCapturer = parcel.ReadBool(); 99 return SUCCESS; 100 } 101 DumpProcessConfig(const AudioProcessConfig & config)102std::string ProcessConfig::DumpProcessConfig(const AudioProcessConfig &config) 103 { 104 std::stringstream temp; 105 106 // AppInfo 107 temp << "appInfo:pid<" << config.appInfo.appPid << "> uid<" << config.appInfo.appUid << "> tokenId<" << 108 config.appInfo.appTokenId << "> "; 109 110 // streamInfo 111 temp << "streamInfo:format(" << config.streamInfo.format << ") encoding(" << config.streamInfo.encoding << 112 ") channels(" << config.streamInfo.channels << ") samplingRate(" << config.streamInfo.samplingRate << ") "; 113 114 // audioMode 115 if (config.audioMode == AudioMode::AUDIO_MODE_PLAYBACK) { 116 temp << "[rendererInfo]:streamUsage(" << config.rendererInfo.streamUsage << ") contentType(" << 117 config.rendererInfo.contentType << ") flag(" << config.rendererInfo.rendererFlags << ") "; 118 } else { 119 temp << "[capturerInfo]:sourceType(" << config.capturerInfo.sourceType << ") flag(" << 120 config.capturerInfo.capturerFlags << ") "; 121 } 122 123 temp << "streamType<" << config.streamType << ">"; 124 125 return temp.str(); 126 } 127 } // namespace AudioStandard 128 } // namespace OHOS 129 130