1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <ddk/device.h>
8 
9 #include <intel-hda/codec-utils/stream-base.h>
10 
11 #include "intel-dsp-topology.h"
12 #include "debug-logging.h"
13 
14 namespace audio {
15 namespace intel_hda {
16 
17 class IntelAudioDsp;
18 
19 class IntelDspStream : public codecs::IntelHDAStreamBase {
20 public:
21     IntelDspStream(uint32_t id, bool is_input, const DspPipeline& pipeline,
22                    const audio_stream_unique_id_t* unique_id = nullptr);
23 
24     // Overloaded
25     zx_status_t ProcessSetStreamFmt(const ihda_proto::SetStreamFmtResp& resp,
26                                     zx::channel&& ring_buffer_channel)
27         __TA_EXCLUDES(obj_lock()) override;
28 
log_prefix()29     const char* log_prefix() const { return log_prefix_; }
30 
31 protected:
~IntelDspStream()32     virtual ~IntelDspStream() { }
33 
34     zx_status_t OnActivateLocked()    __TA_REQUIRES(obj_lock()) final;
35     void        OnDeactivateLocked()  __TA_REQUIRES(obj_lock()) final;
36     void        OnChannelDeactivateLocked(const dispatcher::Channel& channel)
37         __TA_REQUIRES(obj_lock()) final;
38     zx_status_t OnDMAAssignedLocked() __TA_REQUIRES(obj_lock()) final;
39     zx_status_t OnSolicitedResponseLocked(const CodecResponse& resp)
40         __TA_REQUIRES(obj_lock()) final;
41     zx_status_t OnUnsolicitedResponseLocked(const CodecResponse& resp)
42         __TA_REQUIRES(obj_lock()) final;
43     zx_status_t BeginChangeStreamFormatLocked(const audio_proto::StreamSetFmtReq& fmt)
44         __TA_REQUIRES(obj_lock()) final;
45     zx_status_t FinishChangeStreamFormatLocked(uint16_t encoded_fmt)
46         __TA_REQUIRES(obj_lock()) final;
47     void OnGetGainLocked(audio_proto::GetGainResp* out_resp)
48         __TA_REQUIRES(obj_lock()) final;
49     void OnSetGainLocked(const audio_proto::SetGainReq& req,
50                          audio_proto::SetGainResp* out_resp) __TA_REQUIRES(obj_lock()) final;
51     void OnPlugDetectLocked(dispatcher::Channel* response_channel,
52                             const audio_proto::PlugDetectReq& req,
53                             audio_proto::PlugDetectResp* out_resp) __TA_REQUIRES(obj_lock()) final;
54     void OnGetStringLocked(const audio_proto::GetStringReq& req,
55                            audio_proto::GetStringResp* out_resp) __TA_REQUIRES(obj_lock()) final;
56 
57 private:
58     friend class fbl::RefPtr<IntelDspStream>;
59 
60     zx_status_t CreateClientRingBufferChannelLocked(zx::channel&& ring_buffer_channel,
61                                                     zx::channel* out_client_channel)
62         __TA_REQUIRES(obj_lock());
63 
64     zx_status_t ProcessRbRequest(dispatcher::Channel* channel);
65     void ProcessRbDeactivate(const dispatcher::Channel* channel);
66 
67     zx_status_t ProcessClientRbRequest(dispatcher::Channel* channel);
68     void ProcessClientRbDeactivate(const dispatcher::Channel* channel);
69 
70     // Log prefix storage
71     char log_prefix_[LOG_PREFIX_STORAGE] = { 0 };
72 
73     const DspPipeline pipeline_;
74 
75     fbl::RefPtr<dispatcher::Channel> rb_channel_ __TA_GUARDED(obj_lock());
76     fbl::RefPtr<dispatcher::Channel> client_rb_channel_ __TA_GUARDED(obj_lock());
77 };
78 
79 }  // namespace intel_hda
80 }  // namespace audio
81