1 /* 2 * Copyright (c) 2024 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 SINK_USERDATA_H 17 #define SINK_USERDATA_H 18 19 #include <pulse/rtclock.h> 20 #include <pulse/timeval.h> 21 #include <pulse/xmalloc.h> 22 #include <pulsecore/log.h> 23 #include <pulsecore/modargs.h> 24 #include <pulsecore/module.h> 25 #include <pulsecore/rtpoll.h> 26 #include <pulsecore/sink.h> 27 #include <pulsecore/thread-mq.h> 28 #include <pulsecore/thread.h> 29 #include <pulsecore/memblock.h> 30 #include <pulsecore/mix.h> 31 #include <pulse/volume.h> 32 #include <pulsecore/protocol-native.h> 33 #include <pulsecore/memblockq.h> 34 35 #include "renderer_sink_adapter.h" 36 37 struct Userdata { 38 const char *adapterName; 39 uint32_t buffer_size; 40 uint32_t fixed_latency; 41 uint32_t sink_latency; 42 uint32_t render_in_idle_state; 43 uint32_t open_mic_speaker; 44 bool render_full_enable; 45 bool offload_enable; 46 bool multichannel_enable; 47 const char *deviceNetworkId; 48 int32_t deviceType; 49 size_t bytes_dropped; 50 pa_thread_mq thread_mq; 51 pa_memchunk memchunk; 52 pa_usec_t block_usec; 53 pa_thread *thread; 54 pa_rtpoll *rtpoll; 55 pa_core *core; 56 pa_module *module; 57 pa_sink *sink; 58 pa_sample_spec ss; 59 pa_channel_map map; 60 bool test_mode_on; 61 uint32_t writeCount; 62 uint32_t renderCount; 63 pa_sample_format_t format; 64 BufferAttr *bufferAttr; 65 int32_t processLen; 66 size_t processSize; 67 int32_t sinkSceneType; 68 int32_t sinkSceneMode; 69 pthread_mutex_t mutexPa; 70 pthread_mutex_t mutexPa2; 71 pthread_rwlock_t rwlockSleep; 72 int64_t timestampSleep; 73 pa_usec_t timestampLastLog; 74 int8_t spatializationFadingState; // for indicating the fading state, =0:no fading, >0:fading in, <0:fading out 75 int8_t spatializationFadingCount; // for indicating the fading rate 76 bool actualSpatializationEnabled; // the spatialization state that actually applies effect 77 bool isFirstStarted; 78 bool isEffectBufferAllocated; 79 uint64_t lastRecodedLatency; 80 uint32_t continuesGetLatencyErrCount; 81 uint32_t streamAvailable; 82 uint32_t lastStreamAvailable; 83 pa_hashmap *streamAvailableMap; 84 struct { 85 int32_t sessionID; 86 bool firstWriteHdi; // for set volume onstart, avoid mute 87 pa_usec_t pos; 88 pa_usec_t hdiPos; 89 pa_usec_t hdiPosTs; 90 pa_usec_t prewrite; 91 pa_thread *thread; 92 pa_asyncmsgq *msgq; 93 bool isHDISinkStarted; 94 struct RendererSinkAdapter *sinkAdapter; 95 pa_atomic_t hdistate; // 0:need_data 1:wait_consume 2:flushing 96 pa_usec_t fullTs; 97 bool runninglocked; 98 pa_memchunk chunk; 99 bool inited; 100 int32_t setHdiBufferSizeNum; // for set hdi buffer size count 101 } offload; 102 struct { 103 pa_usec_t timestamp; 104 pa_usec_t lastProcessDataTime; // The timestamp from the last time the data was prepared to HDI 105 pa_thread *thread; 106 pa_thread *thread_hdi; 107 pa_asyncmsgq *msgq; 108 pa_atomic_t isHDISinkStarted; 109 struct RendererSinkAdapter *sinkAdapter; 110 pa_asyncmsgq *dq; 111 pa_atomic_t dflag; 112 pa_usec_t writeTime; 113 pa_usec_t prewrite; 114 pa_sink_state_t previousState; 115 pa_atomic_t fadingFlagForPrimary; // 1:do fade in, 0: no need 116 int32_t primaryFadingInDone; 117 int32_t primarySinkInIndex; 118 } primary; 119 struct { 120 bool used; 121 pa_usec_t timestamp; 122 pa_thread *thread; 123 pa_thread *thread_hdi; 124 bool isHDISinkStarted; 125 bool isHDISinkInited; 126 struct RendererSinkAdapter *sinkAdapter; 127 pa_asyncmsgq *msgq; 128 pa_asyncmsgq *dq; 129 pa_atomic_t dflag; 130 pa_usec_t writeTime; 131 pa_usec_t prewrite; 132 pa_atomic_t hdistate; 133 pa_memchunk chunk; 134 SinkAttr sample_attrs; 135 pa_atomic_t fadingFlagForMultiChannel; // 1:do fade in, 0: no need 136 int32_t multiChannelFadingInDone; 137 int32_t multiChannelSinkInIndex; 138 int32_t multiChannelTmpSinkInIndex; 139 uint32_t sinkChannel; 140 uint64_t sinkChannelLayout; 141 } multiChannel; 142 }; 143 144 #endif // SINK_USERDATA_H