Home | History | Annotate | Download | only in libaudioclient
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define LOG_TAG "AudioAttributes"
     18 //#define LOG_NDEBUG 0
     19 #include <utils/Log.h>
     20 
     21 #include <binder/Parcel.h>
     22 
     23 #include <media/AudioAttributes.h>
     24 
     25 namespace android {
     26 
     27 status_t AudioAttributes::readFromParcel(const Parcel *parcel)
     28 {
     29     status_t ret = NO_ERROR;
     30     mAttributes.content_type = static_cast<audio_content_type_t>(parcel->readInt32());
     31     mAttributes.usage = static_cast<audio_usage_t>(parcel->readInt32());
     32     mAttributes.source = static_cast<audio_source_t>(parcel->readInt32());
     33     mAttributes.flags = static_cast<audio_flags_mask_t>(parcel->readInt32());
     34     const bool hasFlattenedTag = (parcel->readInt32() == 1);
     35     if (hasFlattenedTag) {
     36         std::string tags;
     37         ret = parcel->readUtf8FromUtf16(&tags);
     38         if (ret != NO_ERROR) {
     39             return ret;
     40         }
     41         std::strncpy(mAttributes.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1);
     42     } else {
     43         strcpy(mAttributes.tags, "");
     44     }
     45     mStreamType = static_cast<audio_stream_type_t>(parcel->readInt32());
     46     mGroupId = static_cast<volume_group_t>(parcel->readUint32());
     47     return NO_ERROR;
     48 }
     49 
     50 status_t AudioAttributes::writeToParcel(Parcel *parcel) const
     51 {
     52     parcel->writeInt32(static_cast<int32_t>(mAttributes.content_type));
     53     parcel->writeInt32(static_cast<int32_t>(mAttributes.usage));
     54     parcel->writeInt32(static_cast<int32_t>(mAttributes.source));
     55     parcel->writeInt32(static_cast<int32_t>(mAttributes.flags));
     56     if (strlen(mAttributes.tags) == 0) {
     57         parcel->writeInt32(0);
     58     } else {
     59         parcel->writeInt32(1);
     60         parcel->writeUtf8AsUtf16(mAttributes.tags);
     61     }
     62     parcel->writeInt32(static_cast<int32_t>(mStreamType));
     63     parcel->writeUint32(static_cast<uint32_t>(mGroupId));
     64     return NO_ERROR;
     65 }
     66 
     67 } // namespace android
     68