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 38 // AudioMode 39 parcel.WriteInt32(config.audioMode); 40 41 // AudioRendererInfo 42 parcel.WriteInt32(config.rendererInfo.contentType); 43 parcel.WriteInt32(config.rendererInfo.streamUsage); 44 parcel.WriteInt32(config.rendererInfo.rendererFlags); 45 46 // AudioCapturerInfo 47 parcel.WriteInt32(config.capturerInfo.sourceType); 48 parcel.WriteInt32(config.capturerInfo.capturerFlags); 49 50 // streamType 51 parcel.WriteInt32(config.streamType); 52 53 return SUCCESS; 54 } 55 ReadConfigFromParcel(AudioProcessConfig & config,MessageParcel & parcel)56int32_t ProcessConfig::ReadConfigFromParcel(AudioProcessConfig &config, MessageParcel &parcel) 57 { 58 // AppInfo 59 config.appInfo.appUid = parcel.ReadInt32(); 60 config.appInfo.appTokenId = parcel.ReadUint32(); 61 config.appInfo.appPid = parcel.ReadInt32(); 62 63 // AudioStreamInfo 64 config.streamInfo.samplingRate = static_cast<AudioSamplingRate>(parcel.ReadInt32()); 65 config.streamInfo.encoding = static_cast<AudioEncodingType>(parcel.ReadInt32()); 66 config.streamInfo.format = static_cast<AudioSampleFormat>(parcel.ReadInt32()); 67 config.streamInfo.channels = static_cast<AudioChannel>(parcel.ReadInt32()); 68 69 // AudioMode 70 config.audioMode = static_cast<AudioMode>(parcel.ReadInt32()); 71 72 // AudioRendererInfo 73 config.rendererInfo.contentType = static_cast<ContentType>(parcel.ReadInt32()); 74 config.rendererInfo.streamUsage = static_cast<StreamUsage>(parcel.ReadInt32()); 75 config.rendererInfo.rendererFlags = parcel.ReadInt32(); 76 77 // AudioCapturerInfo 78 config.capturerInfo.sourceType = static_cast<SourceType>(parcel.ReadInt32()); 79 config.capturerInfo.capturerFlags = parcel.ReadInt32(); 80 81 // streamType 82 config.streamType = static_cast<AudioStreamType>(parcel.ReadInt32()); 83 84 return SUCCESS; 85 } 86 DumpProcessConfig(const AudioProcessConfig & config)87std::string ProcessConfig::DumpProcessConfig(const AudioProcessConfig &config) 88 { 89 std::stringstream temp; 90 91 // AppInfo 92 temp << "appInfo:pid<" << config.appInfo.appPid << "> uid<" << config.appInfo.appUid << "> tokenId<" << 93 config.appInfo.appTokenId << "> "; 94 95 // streamInfo 96 temp << "streamInfo:format(" << config.streamInfo.format << ") encoding(" << config.streamInfo.encoding << 97 ") channels(" << config.streamInfo.channels << ") samplingRate(" << config.streamInfo.samplingRate << ") "; 98 99 // audioMode 100 if (config.audioMode == AudioMode::AUDIO_MODE_PLAYBACK) { 101 temp << "[rendererInfo]:streamUsage(" << config.rendererInfo.streamUsage << ") contentType(" << 102 config.rendererInfo.contentType << ") flag(" << config.rendererInfo.rendererFlags << ") "; 103 } else { 104 temp << "[capturerInfo]:sourceType(" << config.capturerInfo.sourceType << ") flag(" << 105 config.capturerInfo.capturerFlags << ") "; 106 } 107 108 temp << "streamType<" << config.streamType << ">"; 109 110 return temp.str(); 111 } 112 } // namespace AudioStandard 113 } // namespace OHOS 114 115