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