blob: e2ded3ec0a805eb1be3972e9c9dc2436ee985ea9 [file] [log] [blame]
Ashish Jaina9aac352020-10-30 23:49:09 +05301/*
Aniket Kumar Lata25f2d522021-05-21 09:37:17 -07002 * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
Ashish Jaina9aac352020-10-30 23:49:09 +05303 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
Ankit Mishra7e2b3bb2022-07-11 15:03:33 +053020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
Ashish Jaina9aac352020-10-30 23:49:09 +053021 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ankit Mishra7e2b3bb2022-07-11 15:03:33 +053028 *
29 * Changes from Qualcomm Innovation Center are provided under the following license:
30 *
31 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
32 * SPDX-License-Identifier: BSD-3-Clause-Clear
Ashish Jaina9aac352020-10-30 23:49:09 +053033 */
34
35#define LOG_TAG "StreamNonTunnel"
36
37#include "Session.h"
38#include "kvh2xml.h"
39#include "SessionGsl.h"
40#include "ResourceManager.h"
41#include <unistd.h>
42
43static void handleSessionCallBack(uint64_t hdl, uint32_t event_id, void *data,
Ganapathiraju Sarath Varmacccd4192022-06-22 16:39:19 +053044 uint32_t event_size, uint32_t miid __unused)
Ashish Jaina9aac352020-10-30 23:49:09 +053045{
46 Stream *s = NULL;
47 s = reinterpret_cast<Stream *>(hdl);
48 if (s->streamCb)
49 s->streamCb(reinterpret_cast<pal_stream_handle_t *>(s), event_id, (uint32_t *)data,
50 event_size, s->cookie);
51}
52
53StreamNonTunnel::StreamNonTunnel(const struct pal_stream_attributes *sattr, struct pal_device *dattr __unused,
54 const uint32_t no_of_devices __unused, const struct modifier_kv *modifiers,
55 const uint32_t no_of_modifiers, const std::shared_ptr<ResourceManager> rm)
56{
57 mStreamMutex.lock();
58 uint32_t in_channels = 0, out_channels = 0;
59 uint32_t attribute_size = 0;
60 if (!sattr) {
61 PAL_ERR(LOG_TAG,"invalid arguments");
62 mStreamMutex.unlock();
63 throw std::runtime_error("invalid arguments");
64 }
65
66 if (rm->cardState == CARD_STATUS_OFFLINE) {
67 PAL_ERR(LOG_TAG, "Sound card offline, can not create stream");
68 usleep(SSR_RECOVERY);
69 mStreamMutex.unlock();
70 throw std::runtime_error("Sound card offline");
71 }
72
73 session = NULL;
74 mStreamAttr = (struct pal_stream_attributes *)nullptr;
Ashish Jaina9aac352020-10-30 23:49:09 +053075 inMaxMetadataSz = 0;
76 outMaxMetadataSz = 0;
77 mDevices.clear();
78 currentState = STREAM_IDLE;
Ashish Jain35a20ca2021-02-12 07:01:54 +053079 ssrInNTMode = false;
Ashish Jaina9aac352020-10-30 23:49:09 +053080 //Modify cached values only at time of SSR down.
81 cachedState = STREAM_IDLE;
82
83 PAL_DBG(LOG_TAG, "Enter");
84
85 //TBD handle modifiers later
86 mNoOfModifiers = 0; //no_of_modifiers;
87 mModifiers = (struct modifier_kv *) (NULL);
88 std::ignore = modifiers;
89 std::ignore = no_of_modifiers;
90
91
92 attribute_size = sizeof(struct pal_stream_attributes);
93 mStreamAttr = (struct pal_stream_attributes *) calloc(1, attribute_size);
94 if (!mStreamAttr) {
95 PAL_ERR(LOG_TAG, "malloc for stream attributes failed %s", strerror(errno));
96 mStreamMutex.unlock();
97 throw std::runtime_error("failed to malloc for stream attributes");
98 }
99
100 ar_mem_cpy(mStreamAttr, sizeof(pal_stream_attributes), sattr, sizeof(pal_stream_attributes));
101
102 if (mStreamAttr->in_media_config.ch_info.channels > PAL_MAX_CHANNELS_SUPPORTED) {
103 PAL_ERR(LOG_TAG,"in_channels is invalid %d", in_channels);
104 mStreamAttr->in_media_config.ch_info.channels = PAL_MAX_CHANNELS_SUPPORTED;
105 }
106 if (mStreamAttr->out_media_config.ch_info.channels > PAL_MAX_CHANNELS_SUPPORTED) {
107 PAL_ERR(LOG_TAG,"out_channels is invalid %d", out_channels);
108 mStreamAttr->out_media_config.ch_info.channels = PAL_MAX_CHANNELS_SUPPORTED;
109 }
110
111 PAL_VERBOSE(LOG_TAG, "Create new Session");
112 session = Session::makeSession(rm, sattr);
113 if (!session) {
114 PAL_ERR(LOG_TAG, "session creation failed");
115 free(mStreamAttr);
116 mStreamMutex.unlock();
117 throw std::runtime_error("failed to create session object");
118 }
119
120 session->registerCallBack(handleSessionCallBack, (uint64_t)this);
121
Ashish Jaina9aac352020-10-30 23:49:09 +0530122 mStreamMutex.unlock();
Ritu Sharma3ca101a2021-05-31 13:21:30 +0530123 rm->registerStream(this);
Ashish Jaina9aac352020-10-30 23:49:09 +0530124 PAL_DBG(LOG_TAG, "Exit. state %d", currentState);
125 return;
126}
127
128StreamNonTunnel::~StreamNonTunnel()
129{
130 rm->resetStreamInstanceID(this);
Jaideep Sharma79937c52021-05-27 10:56:17 +0530131 rm->deregisterStream(this);
Ashish Jaina9aac352020-10-30 23:49:09 +0530132 if (mStreamAttr) {
133 free(mStreamAttr);
134 mStreamAttr = (struct pal_stream_attributes *)NULL;
135 }
Jaideep Sharma79937c52021-05-27 10:56:17 +0530136 delete session;
137 session = nullptr;
Ashish Jaina9aac352020-10-30 23:49:09 +0530138}
139
140int32_t StreamNonTunnel::open()
141{
142 int32_t status = 0;
143
144 mStreamMutex.lock();
Ashish Jain35a20ca2021-02-12 07:01:54 +0530145 if (rm->cardState == CARD_STATUS_OFFLINE || ssrInNTMode == true) {
Ashish Jaina9aac352020-10-30 23:49:09 +0530146 PAL_ERR(LOG_TAG, "Sound card offline, can not open stream");
147 usleep(SSR_RECOVERY);
Ashish Jain35a20ca2021-02-12 07:01:54 +0530148 status = -ENETRESET;
Ashish Jaina9aac352020-10-30 23:49:09 +0530149 goto exit;
150 }
151
152 if (currentState == STREAM_IDLE) {
153 PAL_VERBOSE(LOG_TAG, "Enter. session handle - %pK", session);
154 status = session->open(this);
155 if (0 != status) {
156 PAL_ERR(LOG_TAG, "session open failed with status %d", status);
157 goto exit;
158 }
159 PAL_VERBOSE(LOG_TAG, "session open successful");
160
161 currentState = STREAM_INIT;
162 PAL_DBG(LOG_TAG, "Exit. streamLL opened. state %d", currentState);
163 } else if (currentState == STREAM_INIT) {
164 PAL_INFO(LOG_TAG, "Stream is already opened, state %d", currentState);
165 status = 0;
166 goto exit;
167 } else {
168 PAL_ERR(LOG_TAG, "Stream is not in correct state %d", currentState);
169 //TBD : which error code to return here.
170 status = -EINVAL;
171 goto exit;
172 }
173exit:
174 mStreamMutex.unlock();
175 return status;
176}
177
Ashish Jaina9aac352020-10-30 23:49:09 +0530178int32_t StreamNonTunnel::close()
179{
180 int32_t status = 0;
181 mStreamMutex.lock();
182
183 PAL_INFO(LOG_TAG, "Enter. session handle - %pK state %d",
184 session, currentState);
185
186 if (currentState == STREAM_IDLE) {
Ashish Jaina9aac352020-10-30 23:49:09 +0530187 PAL_VERBOSE(LOG_TAG, "closed the devices successfully");
188 goto exit;
189 } else if (currentState == STREAM_STARTED || currentState == STREAM_PAUSED) {
190 status = stop();
191 if (0 != status)
192 PAL_ERR(LOG_TAG, "stream stop failed. status %d", status);
193 }
194
Ashish Jaina9aac352020-10-30 23:49:09 +0530195 status = session->close(this);
Ashish Jaina9aac352020-10-30 23:49:09 +0530196 if (0 != status) {
197 PAL_ERR(LOG_TAG, "session close failed with status %d", status);
198 }
199
200exit:
201 currentState = STREAM_IDLE;
202 mStreamMutex.unlock();
Ashish Jaina9aac352020-10-30 23:49:09 +0530203 PAL_INFO(LOG_TAG, "Exit. closed the stream successfully %d status %d",
204 currentState, status);
205 return status;
206}
207
208//TBD: move this to Stream, why duplicate code?
209int32_t StreamNonTunnel::start()
210{
211 int32_t status = 0;
212 mStreamMutex.lock();
Ashish Jain35a20ca2021-02-12 07:01:54 +0530213 if (rm->cardState == CARD_STATUS_OFFLINE || ssrInNTMode == true) {
214 PAL_ERR(LOG_TAG, "Sound card offline currentState %d",
215 currentState);
216 status = -ENETRESET;
Ashish Jaina9aac352020-10-30 23:49:09 +0530217 goto exit;
218 }
219
220 PAL_DBG(LOG_TAG, "Enter. session handle - %pK mStreamAttr->direction - %d state %d",
221 session, mStreamAttr->direction, currentState);
222
Aniket Kumar Lata25f2d522021-05-21 09:37:17 -0700223 if (currentState == STREAM_INIT || currentState == STREAM_STOPPED ||
224 currentState == STREAM_SUSPENDED) {
Ashish Jaina9aac352020-10-30 23:49:09 +0530225 status = session->prepare(this);
226 if (0 != status) {
227 PAL_ERR(LOG_TAG, "Rx session prepare is failed with status %d",
228 status);
Ashish Jaina9aac352020-10-30 23:49:09 +0530229 goto exit;
230 }
231 PAL_VERBOSE(LOG_TAG, "session prepare successful");
232
233 status = session->start(this);
Ashish Jain35a20ca2021-02-12 07:01:54 +0530234 if (status == -ENETRESET &&
Ashish Jaina9aac352020-10-30 23:49:09 +0530235 rm->cardState != CARD_STATUS_OFFLINE) {
236 PAL_ERR(LOG_TAG, "Sound card offline, informing RM");
237 rm->ssrHandler(CARD_STATUS_OFFLINE);
Ashish Jaina9aac352020-10-30 23:49:09 +0530238 goto exit;
239 }
240 if (0 != status) {
241 PAL_ERR(LOG_TAG, "Rx session start is failed with status %d",
242 status);
Ashish Jaina9aac352020-10-30 23:49:09 +0530243 goto exit;
244 }
245 PAL_VERBOSE(LOG_TAG, "session start successful");
Ashish Jaina9aac352020-10-30 23:49:09 +0530246 currentState = STREAM_STARTED;
247 } else if (currentState == STREAM_STARTED) {
248 PAL_INFO(LOG_TAG, "Stream already started, state %d", currentState);
249 goto exit;
250 } else {
251 PAL_ERR(LOG_TAG, "Stream is not opened yet");
252 status = -EINVAL;
253 goto exit;
254 }
255 PAL_DBG(LOG_TAG, "Exit. state %d", currentState);
256
257exit:
258 mStreamMutex.unlock();
259 return status;
260}
261
262//TBD: move this to Stream, why duplicate code?
263int32_t StreamNonTunnel::stop()
264{
265 int32_t status = 0;
266
267 mStreamMutex.lock();
Ashish Jain35a20ca2021-02-12 07:01:54 +0530268 PAL_DBG(LOG_TAG, "Enter. session handle - %pK mStreamAttr->direction - %d state %d",
Ashish Jaina9aac352020-10-30 23:49:09 +0530269 session, mStreamAttr->direction, currentState);
270
271 if (currentState == STREAM_STARTED || currentState == STREAM_PAUSED) {
272 status = session->stop(this);
273 if (0 != status) {
274 PAL_ERR(LOG_TAG, "Rx session stop failed with status %d", status);
275 }
276 PAL_VERBOSE(LOG_TAG, "session stop successful");
277 currentState = STREAM_STOPPED;
278 } else if (currentState == STREAM_STOPPED || currentState == STREAM_IDLE) {
279 PAL_INFO(LOG_TAG, "Stream is already in Stopped state %d", currentState);
280 goto exit;
281 } else {
282 PAL_ERR(LOG_TAG, "Stream should be in start/pause state, %d", currentState);
283 status = -EINVAL;
284 goto exit;
285 }
286 PAL_DBG(LOG_TAG, "Exit. status %d, state %d", status, currentState);
287
288exit:
289 mStreamMutex.unlock();
290 return status;
291}
292
293//TBD: move this to Stream, why duplicate code?
294int32_t StreamNonTunnel::prepare()
295{
296 int32_t status = 0;
297
298 PAL_DBG(LOG_TAG, "Enter. session handle - %pK", session);
299
300 mStreamMutex.lock();
Ashish Jain35a20ca2021-02-12 07:01:54 +0530301
302 if ((rm->cardState == CARD_STATUS_OFFLINE)
303 || ssrInNTMode == true) {
304 PAL_ERR(LOG_TAG, "Sound card offline currentState %d",
305 currentState);
306 mStreamMutex.unlock();
307 return -ENETRESET;
308 }
309
Ashish Jaina9aac352020-10-30 23:49:09 +0530310 status = session->prepare(this);
311 if (0 != status)
312 PAL_ERR(LOG_TAG, "session prepare failed with status = %d", status);
313 mStreamMutex.unlock();
314 PAL_DBG(LOG_TAG, "Exit. status - %d", status);
315
316 return status;
317}
318
319int32_t StreamNonTunnel::read(struct pal_buffer* buf)
320{
321 int32_t status = 0;
322 int32_t size;
323 PAL_DBG(LOG_TAG, "Enter. session handle - %pK, state %d",
324 session, currentState);
325
Zhou Song88cbe032022-02-27 13:45:27 +0800326 mStreamMutex.lock();
Ashish Jain35a20ca2021-02-12 07:01:54 +0530327 if ((rm->cardState == CARD_STATUS_OFFLINE) || ssrInNTMode == true) {
328 PAL_ERR(LOG_TAG, "Sound card offline currentState %d",
329 currentState);
330 status = -ENETRESET;
Ashish Jaina9aac352020-10-30 23:49:09 +0530331 goto exit;
332 }
333
334 if (currentState == STREAM_STARTED) {
335 status = session->read(this, SHMEM_ENDPOINT, buf, &size);
336 if (0 != status) {
337 PAL_ERR(LOG_TAG, "session read is failed with status %d", status);
Ashish Jain35a20ca2021-02-12 07:01:54 +0530338 if (status == -ENETRESET &&
Ashish Jaina9aac352020-10-30 23:49:09 +0530339 rm->cardState != CARD_STATUS_OFFLINE) {
340 PAL_ERR(LOG_TAG, "Sound card offline, informing RM");
341 rm->ssrHandler(CARD_STATUS_OFFLINE);
342 size = buf->size;
Ashish Jaina9aac352020-10-30 23:49:09 +0530343 PAL_DBG(LOG_TAG, "dropped buffer size - %d", size);
344 goto exit;
345 } else if (rm->cardState == CARD_STATUS_OFFLINE) {
346 size = buf->size;
Ashish Jaina9aac352020-10-30 23:49:09 +0530347 PAL_DBG(LOG_TAG, "dropped buffer size - %d", size);
348 goto exit;
349 } else {
Ashish Jaina9aac352020-10-30 23:49:09 +0530350 goto exit;
351 }
352 }
353 } else {
354 PAL_ERR(LOG_TAG, "Stream not started yet, state %d", currentState);
355 status = -EINVAL;
356 goto exit;
357 }
Zhou Song88cbe032022-02-27 13:45:27 +0800358 mStreamMutex.unlock();
Ashish Jaina9aac352020-10-30 23:49:09 +0530359 PAL_DBG(LOG_TAG, "Exit. session read successful size - %d", size);
360 return size;
361exit :
Zhou Song88cbe032022-02-27 13:45:27 +0800362 mStreamMutex.unlock();
Ashish Jaina9aac352020-10-30 23:49:09 +0530363 PAL_DBG(LOG_TAG, "session read failed status %d", status);
364 return status;
365}
366
367int32_t StreamNonTunnel::write(struct pal_buffer* buf)
368{
369 int32_t status = 0;
370 int32_t size = 0;
Ashish Jaina9aac352020-10-30 23:49:09 +0530371
372 PAL_DBG(LOG_TAG, "Enter. session handle - %pK, state %d",
373 session, currentState);
374
375 mStreamMutex.lock();
376
377 // If cached state is not STREAM_IDLE, we are still processing SSR up.
378 if ((rm->cardState == CARD_STATUS_OFFLINE)
Ashish Jain35a20ca2021-02-12 07:01:54 +0530379 || ssrInNTMode == true) {
Ashish Jaina9aac352020-10-30 23:49:09 +0530380 size = buf->size;
Ashish Jain35a20ca2021-02-12 07:01:54 +0530381 PAL_DBG(LOG_TAG, "sound card offline dropped buffer size - %d", size);
Ashish Jaina9aac352020-10-30 23:49:09 +0530382 mStreamMutex.unlock();
Ashish Jain35a20ca2021-02-12 07:01:54 +0530383 return -ENETRESET;
Ashish Jaina9aac352020-10-30 23:49:09 +0530384 }
385 mStreamMutex.unlock();
Bharath Tirunagaruc6484d72021-07-14 21:56:20 -0700386 //we should allow writes to go through in Start/Pause state as well.
387 if ( (currentState == STREAM_STARTED) ||
388 (currentState == STREAM_PAUSED) ) {
Ashish Jaina9aac352020-10-30 23:49:09 +0530389 status = session->write(this, SHMEM_ENDPOINT, buf, &size, 0);
390 if (0 != status) {
391 PAL_ERR(LOG_TAG, "session write is failed with status %d", status);
392
393 /* ENETRESET is the error code returned by AGM during SSR */
Ashish Jain35a20ca2021-02-12 07:01:54 +0530394 if (status == -ENETRESET &&
Ashish Jaina9aac352020-10-30 23:49:09 +0530395 rm->cardState != CARD_STATUS_OFFLINE) {
396 PAL_ERR(LOG_TAG, "Sound card offline, informing RM");
397 rm->ssrHandler(CARD_STATUS_OFFLINE);
398 size = buf->size;
Ashish Jaina9aac352020-10-30 23:49:09 +0530399 PAL_DBG(LOG_TAG, "dropped buffer size - %d", size);
400 goto exit;
401 } else if (rm->cardState == CARD_STATUS_OFFLINE) {
402 size = buf->size;
Ashish Jaina9aac352020-10-30 23:49:09 +0530403 PAL_DBG(LOG_TAG, "dropped buffer size - %d", size);
404 goto exit;
405 } else {
Ashish Jaina9aac352020-10-30 23:49:09 +0530406 goto exit;
407 }
408 }
409 PAL_DBG(LOG_TAG, "Exit. session write successful size - %d", size);
410 return size;
411 } else {
412 PAL_ERR(LOG_TAG, "Stream not started yet, state %d", currentState);
413 if (currentState == STREAM_STOPPED)
414 status = -EIO;
415 else
416 status = -EINVAL;
417 goto exit;
418 }
419
420exit :
421 PAL_DBG(LOG_TAG, "session write failed status %d", status);
422 return status;
423}
424
425int32_t StreamNonTunnel::registerCallBack(pal_stream_callback cb, uint64_t cookie)
426{
427 streamCb = cb;
428 this->cookie = cookie;
429 return 0; return 0;
430}
431
432int32_t StreamNonTunnel::getTagsWithModuleInfo(size_t *size, uint8_t *payload)
433{
434 int32_t status = 0;
435
Ashish Jainf5da4e12020-11-18 23:58:21 +0530436 if (*size > 0 && !payload)
Ashish Jaina9aac352020-10-30 23:49:09 +0530437 {
438 status = -EINVAL;
439 PAL_ERR(LOG_TAG, "wrong params");
440 goto exit;
441 }
442
443 status = session->getTagsWithModuleInfo(this, size, payload);
444exit:
445 return status;
446}
447
448int32_t StreamNonTunnel::getCallBack(pal_stream_callback * /*cb*/)
449{
450 return 0;
451}
452
453int32_t StreamNonTunnel::getParameters(uint32_t /*param_id*/, void ** /*payload*/)
454{
455 return 0;
456}
457
458int32_t StreamNonTunnel::setParameters(uint32_t param_id, void *payload)
459{
460 int32_t status = 0;
461
462 if (!payload)
463 {
464 status = -EINVAL;
465 PAL_ERR(LOG_TAG, "wrong params");
466 goto error;
467 }
468
Ashish Jain35a20ca2021-02-12 07:01:54 +0530469 mStreamMutex.lock();
Zhou Songbb7f7b72021-12-13 16:04:38 +0800470 if (currentState == STREAM_IDLE) {
471 PAL_ERR(LOG_TAG, "Invalid stream state: IDLE for param ID: %d", param_id);
472 mStreamMutex.unlock();
473 return -EINVAL;
474 }
Ashish Jain35a20ca2021-02-12 07:01:54 +0530475 if ((rm->cardState == CARD_STATUS_OFFLINE) || ssrInNTMode == true) {
476 PAL_ERR(LOG_TAG, "Sound card offline currentState %d",
477 currentState);
478 status = -ENETRESET;
479 goto error;
480 }
481
Ashish Jaina9aac352020-10-30 23:49:09 +0530482 PAL_DBG(LOG_TAG, "start, set parameter %u, session handle - %p", param_id, session);
483
Ashish Jaina9aac352020-10-30 23:49:09 +0530484 // Stream may not know about tags, so use setParameters instead of setConfig
485 switch (param_id) {
486 case PAL_PARAM_ID_MODULE_CONFIG:
487 status = session->setParameters(this, 0, param_id, payload);
488 break;
489 default:
490 PAL_ERR(LOG_TAG, "Unsupported param id %u", param_id);
491 status = -EINVAL;
492 break;
493 }
494
Ashish Jain35a20ca2021-02-12 07:01:54 +0530495error:
Ashish Jaina9aac352020-10-30 23:49:09 +0530496 mStreamMutex.unlock();
497 PAL_VERBOSE(LOG_TAG, "exit, session parameter %u set with status %d", param_id, status);
Ashish Jaina9aac352020-10-30 23:49:09 +0530498 return status;
499}
500
Ashish Jain89d0fc02021-01-18 23:37:59 +0530501int32_t StreamNonTunnel::drain(pal_drain_type_t type)
502{
503 PAL_ERR(LOG_TAG, "drain");
Ashish Jain35a20ca2021-02-12 07:01:54 +0530504 if ((rm->cardState == CARD_STATUS_OFFLINE) || ssrInNTMode == true) {
505 PAL_ERR(LOG_TAG, "Sound card offline currentState %d",
506 currentState);
507 return -ENETRESET;
508 }
Ashish Jain89d0fc02021-01-18 23:37:59 +0530509 return session->drain(type);
510}
511
Ashish Jaina9aac352020-10-30 23:49:09 +0530512int32_t StreamNonTunnel::flush()
513{
514 int32_t status = 0;
515
516 mStreamMutex.lock();
Ashish Jain35a20ca2021-02-12 07:01:54 +0530517 if ((rm->cardState == CARD_STATUS_OFFLINE) || ssrInNTMode == true) {
518 PAL_ERR(LOG_TAG, "Sound card offline currentState %d",
519 currentState);
520 status = -ENETRESET;
521 goto exit;
522 }
Ashish Jaina9aac352020-10-30 23:49:09 +0530523
524 status = session->flush();
Ashish Jain89d0fc02021-01-18 23:37:59 +0530525
Ashish Jain35a20ca2021-02-12 07:01:54 +0530526exit:
527 mStreamMutex.unlock();
Ashish Jaina9aac352020-10-30 23:49:09 +0530528 return status;
529}
530
Aniket Kumar Lata25f2d522021-05-21 09:37:17 -0700531int32_t StreamNonTunnel::suspend()
532{
533 int32_t status = 0;
534
535 mStreamMutex.lock();
536 if ((rm->cardState == CARD_STATUS_OFFLINE) || ssrInNTMode) {
537 PAL_ERR(LOG_TAG, "Sound card offline currentState %d",
538 currentState);
539 status = -ENETRESET;
540 goto exit;
541 }
542
543 if (currentState == STREAM_STARTED) {
Ankit Mishraf2f8b732022-06-01 09:01:06 +0530544 status = session->suspend(this);
Aniket Kumar Lata25f2d522021-05-21 09:37:17 -0700545 if (status) {
546 PAL_ERR(LOG_TAG, "Rx session suspend failed with status %d", status);
547 goto exit;
548 }
549 currentState = STREAM_SUSPENDED;
550 }
551exit:
552 mStreamMutex.unlock();
553 return status;
554}
555
Ashish Jaina9aac352020-10-30 23:49:09 +0530556int32_t StreamNonTunnel::isSampleRateSupported(uint32_t sampleRate)
557{
558 int32_t rc = 0;
559 PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
560 switch(sampleRate) {
561 case SAMPLINGRATE_8K:
562 case SAMPLINGRATE_16K:
563 case SAMPLINGRATE_22K:
564 case SAMPLINGRATE_32K:
565 case SAMPLINGRATE_44K:
566 case SAMPLINGRATE_48K:
567 case SAMPLINGRATE_96K:
568 case SAMPLINGRATE_192K:
569 case SAMPLINGRATE_384K:
570 break;
571 default:
572 rc = 0;
573 PAL_VERBOSE(LOG_TAG, "sample rate received %d rc %d", sampleRate, rc);
574 break;
575 }
576 return rc;
577}
578
579int32_t StreamNonTunnel::isChannelSupported(uint32_t numChannels)
580{
581 int32_t rc = 0;
582 PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
583 switch(numChannels) {
584 case CHANNELS_1:
585 case CHANNELS_2:
586 case CHANNELS_3:
587 case CHANNELS_4:
588 case CHANNELS_5:
589 case CHANNELS_5_1:
590 case CHANNELS_7:
591 case CHANNELS_8:
592 break;
593 default:
594 rc = -EINVAL;
595 PAL_ERR(LOG_TAG, "channels not supported %d rc %d", numChannels, rc);
596 break;
597 }
598 return rc;
599}
600
601int32_t StreamNonTunnel::isBitWidthSupported(uint32_t bitWidth)
602{
603 int32_t rc = 0;
604 PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
605 switch(bitWidth) {
606 case BITWIDTH_16:
607 case BITWIDTH_24:
608 case BITWIDTH_32:
609 break;
610 default:
611 rc = -EINVAL;
612 PAL_ERR(LOG_TAG, "bit width not supported %d rc %d", bitWidth, rc);
613 break;
614 }
615 return rc;
616}
617
618int32_t StreamNonTunnel::ssrDownHandler()
619{
Aditya Rathi0529a9e2022-11-07 21:13:45 -0800620 int32_t status = 0;
Ashish Jaina9aac352020-10-30 23:49:09 +0530621
Ashish Jain35a20ca2021-02-12 07:01:54 +0530622
Ashish Jaina9aac352020-10-30 23:49:09 +0530623 mStreamMutex.lock();
Ashish Jain35a20ca2021-02-12 07:01:54 +0530624 /* In NonTunnelMode once SSR happens, that session is not reusuable
625 * Hence set the ssr to true and return all subsequent calls with
626 * -ENETRESET, untill the client sets up a new session.
627 *
Ashish Jaina9aac352020-10-30 23:49:09 +0530628 */
Ashish Jain35a20ca2021-02-12 07:01:54 +0530629 PAL_DBG(LOG_TAG, "Enter. session handle - %pK currentState State %d",
630 session, currentState);
Ashish Jaina9aac352020-10-30 23:49:09 +0530631
Ashish Jain35a20ca2021-02-12 07:01:54 +0530632 ssrInNTMode = true;
633 if (streamCb)
634 streamCb(reinterpret_cast<pal_stream_handle_t *>(this), PAL_STREAM_CBK_EVENT_ERROR, NULL, 0, this->cookie);
Ashish Jaina9aac352020-10-30 23:49:09 +0530635
Ashish Jain35a20ca2021-02-12 07:01:54 +0530636 mStreamMutex.unlock();
637
Ashish Jaina9aac352020-10-30 23:49:09 +0530638 PAL_DBG(LOG_TAG, "Exit, status %d", status);
639 return status;
640}
641
642int32_t StreamNonTunnel::ssrUpHandler()
643{
Ashish Jain35a20ca2021-02-12 07:01:54 +0530644 return 0;
Ashish Jaina9aac352020-10-30 23:49:09 +0530645}
646