• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 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 #ifndef AUDIO_STREAM_DESCRIPTOR_H
17 #define AUDIO_STREAM_DESCRIPTOR_H
18 
19 #include <memory>
20 #include "parcel.h"
21 #include "audio_device_descriptor.h"
22 #include "audio_stream_enum.h"
23 #include "audio_info.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 enum AudioStreamAction : uint32_t {
28     AUDIO_STREAM_ACTION_DEFAULT = 0,
29     AUDIO_STREAM_ACTION_NEW,
30     AUDIO_STREAM_ACTION_MOVE,
31     AUDIO_STREAM_ACTION_RECREATE,
32 };
33 
34 class AudioStreamDescriptor : public Parcelable {
35 public:
36     AudioStreamInfo streamInfo_;
37     AudioMode audioMode_ = AUDIO_MODE_PLAYBACK;
38     AudioFlag audioFlag_ = AUDIO_FLAG_NONE;
39     uint32_t routeFlag_ = AUDIO_FLAG_NONE;
40     int64_t createTimeStamp_ = 0;
41     int64_t startTimeStamp_ = 0;
42     AudioRendererInfo rendererInfo_ = {};
43     AudioCapturerInfo capturerInfo_ = {};
44     AppInfo appInfo_ = {};
45     uint32_t sessionId_ = 0;
46     int32_t callerUid_ = -1;
47     int32_t callerPid_ = -1;
48     AudioStreamStatus streamStatus_ = STREAM_STATUS_NEW;
49     AudioStreamAction streamAction_ = AUDIO_STREAM_ACTION_DEFAULT;
50     mutable std::vector<std::shared_ptr<AudioDeviceDescriptor>> oldDeviceDescs_ = {};
51     mutable std::vector<std::shared_ptr<AudioDeviceDescriptor>> newDeviceDescs_ = {};
52     std::string bundleName_ = "";
53 
54     AudioStreamDescriptor();
55     virtual ~AudioStreamDescriptor();
56 
57     bool Marshalling(Parcel &parcel) const override;
58     static AudioStreamDescriptor *Unmarshalling(Parcel &parcel);
59     bool WriteDeviceDescVectorToParcel(
60         Parcel &parcel, std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descs) const;
61     void UnmarshallingDeviceDescVector(Parcel &parcel, std::vector<std::shared_ptr<AudioDeviceDescriptor>> &descs);
62 
63     void SetBunduleName(std::string &bundleName);
64 
65     // log and dump
66     void Dump(std::string &dumpString);
67     std::string GetNewDevicesTypeString();
68     std::string GetNewDevicesInfo();
69     std::string GetDeviceInfo(std::shared_ptr<AudioDeviceDescriptor> desc);
70 
71 private:
IsRenderer()72     bool IsRenderer()
73     {
74         return audioMode_ == AUDIO_MODE_PLAYBACK;
75     }
76     void DumpCommonAttrs(std::string &dumpString);
77     void DumpRendererStreamAttrs(std::string &dumpString);
78     void DumpCapturerStreamAttrs(std::string &dumpString);
79     void DumpDeviceAttrs(std::string &dumpString);
80 };
81 } // namespace AudioStandard
82 } // namespace OHOS
83 #endif // AUDIO_STREAM_DESCRIPTOR_H
84