• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_RENDERER_H
17 #define AUDIO_RENDERER_H
18 
19 #include <vector>
20 #include <stddef.h>
21 #include <stdint.h>
22 #include <memory>
23 #include <cstring>
24 #include <timestamp.h>
25 #include <mutex>
26 #include "audio_effect.h"
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 /**
31  * @brief Defines information about audio renderer parameters.
32  * @since 8
33  */
34 
35 struct AudioRendererParams {
36     /** Sample Format */
37     AudioSampleFormat sampleFormat = SAMPLE_S16LE;
38     /** Sampling rate */
39     AudioSamplingRate sampleRate = SAMPLE_RATE_8000;
40     /** Number of channels */
41     AudioChannel channelCount = MONO;
42     /** Encoding Type */
43     AudioEncodingType encodingType = ENCODING_PCM;
44 };
45 
46 class AudioRendererCallback {
47 public:
48     virtual ~AudioRendererCallback() = default;
49 
50     /**
51      * Called when an interrupt is received.
52      *
53      * @param interruptEvent Indicates the InterruptEvent information needed by client.
54      * For details, refer InterruptEvent struct in audio_info.h
55      * @since 8
56      */
57     virtual void OnInterrupt(const InterruptEvent &interruptEvent) = 0;
58 
59     /**
60      * Called when renderer state is updated.
61      *
62      * @param state Indicates updated state of the renderer.
63      * For details, refer RendererState enum.
64      */
65     virtual void OnStateChange(const RendererState state, const StateChangeCmdType cmdType = CMD_FROM_CLIENT) = 0;
66 };
67 
68 class RendererPositionCallback {
69 public:
70     virtual ~RendererPositionCallback() = default;
71 
72     /**
73      * Called when the requested frame number is reached.
74      *
75      * @param framePosition requested frame position.
76      * @since 8
77      */
78     virtual void OnMarkReached(const int64_t &framePosition) = 0;
79 };
80 
81 class RendererPeriodPositionCallback {
82 public:
83     virtual ~RendererPeriodPositionCallback() = default;
84 
85     /**
86      * Called when the requested frame count is written.
87      *
88      * @param frameCount requested frame frame count for callback.
89      * @since 8
90      */
91     virtual void OnPeriodReached(const int64_t &frameNumber) = 0;
92 };
93 
94 class AudioRendererWriteCallback {
95 public:
96     virtual ~AudioRendererWriteCallback() = default;
97 
98     /**
99      * Called when buffer to be enqueued.
100      *
101      * @param length Indicates requested buffer length.
102      * @since 8
103      */
104     virtual void OnWriteData(size_t length) = 0;
105 };
106 
107 class AudioRendererDeviceChangeCallback {
108 public:
109     virtual ~AudioRendererDeviceChangeCallback() = default;
110 
111     /**
112      * Called when renderer device is updated.
113      *
114      * @param state Indicates updated device of the renderer.
115      * since 10
116      */
117     virtual void OnStateChange(const DeviceInfo &deviceInfo) = 0;
118     virtual void RemoveAllCallbacks() = 0;
119 };
120 
121 class AudioRendererErrorCallback {
122 public:
123     virtual ~AudioRendererErrorCallback() = default;
124 
125     /**
126      * Called when an unrecoverable exception occurs in the renderer
127      *
128      * @param errorCode Indicates error code of the exception.
129      * since 10
130      */
131     virtual void OnError(AudioErrors errorCode) = 0;
132 };
133 
134 /**
135  * @brief Provides functions for applications to implement audio rendering.
136  * @since 8
137  */
138 class AudioRenderer {
139 public:
140     static int32_t CheckMaxRendererInstances();
141 
142     /**
143      * @brief create renderer instance.
144      *
145      * @param audioStreamType The audio streamtype to be created.
146      * refer AudioStreamType in audio_info.h.
147      * @return Returns unique pointer to the AudioRenderer object
148      * @since 8
149     */
150     static std::unique_ptr<AudioRenderer> Create(AudioStreamType audioStreamType);
151 
152     /**
153      * @brief create renderer instance.
154      *
155      * @param audioStreamType The audio streamtype to be created.
156      * refer AudioStreamType in audio_info.h.
157      * @param appInfo Originating application's uid and token id can be passed here
158      * @return Returns unique pointer to the AudioRenderer object
159      * @since 9
160     */
161     static std::unique_ptr<AudioRenderer> Create(AudioStreamType audioStreamType, const AppInfo &appInfo);
162 
163     /**
164      * @brief create renderer instance.
165      *
166      * @param rendererOptions The audio renderer configuration to be used while creating renderer instance.
167      * refer AudioRendererOptions in audio_info.h.
168      * @return Returns unique pointer to the AudioRenderer object
169      * @since 8
170     */
171     static std::unique_ptr<AudioRenderer> Create(const AudioRendererOptions &rendererOptions);
172 
173     /**
174      * @brief create renderer instance.
175      *
176      * @param rendererOptions The audio renderer configuration to be used while creating renderer instance.
177      * refer AudioRendererOptions in audio_info.h.
178      * @param appInfo Originating application's uid and token id can be passed here
179      * @return Returns unique pointer to the AudioRenderer object
180      * @since 9
181     */
182     static std::unique_ptr<AudioRenderer> Create(const AudioRendererOptions &options, const AppInfo &appInfo);
183 
184     /**
185      * @brief create renderer instance.
186      *
187      * @param cachePath Application cache path
188      * @param rendererOptions The audio renderer configuration to be used while creating renderer instance.
189      * refer AudioRendererOptions in audio_info.h.
190      * @return Returns unique pointer to the AudioRenderer object
191      * @since 8
192     */
193     static std::unique_ptr<AudioRenderer> Create(const std::string cachePath,
194         const AudioRendererOptions &rendererOptions);
195 
196     /**
197      * @brief create renderer instance.
198      *
199      * @param cachePath Application cache path
200      * @param rendererOptions The audio renderer configuration to be used while creating renderer instance.
201      * refer AudioRendererOptions in audio_info.h.
202      * @param appInfo Originating application's uid and token id can be passed here
203      * @return Returns unique pointer to the AudioRenderer object
204      * @since 9
205     */
206     static std::unique_ptr<AudioRenderer> Create(const std::string cachePath,
207         const AudioRendererOptions &rendererOptions, const AppInfo &appInfo);
208 
209     /**
210      * @brief Sets audio privacy type.
211      *
212      * @param privacyType Indicates information about audio privacy type. For details, see
213      * {@link AudioPrivacyType}.
214      * @since 10
215      */
216     virtual void SetAudioPrivacyType(AudioPrivacyType privacyType) = 0;
217 
218     /**
219      * @brief Sets audio renderer parameters.
220      *
221      * @param params Indicates information about audio renderer parameters to set. For details, see
222      * {@link AudioRendererParams}.
223      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
224      * in {@link audio_errors.h} otherwise.
225      * @since 8
226      */
227     virtual int32_t SetParams(const AudioRendererParams params) = 0;
228 
229     /**
230      * @brief Registers the renderer callback listener.
231      * (1)If using old SetParams(const AudioCapturerParams params) API,
232      *    this API must be called immediately after SetParams.
233      * (2) Else if using Create(const AudioRendererOptions &rendererOptions),
234      *    this API must be called immediately after Create.
235      *
236      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
237      * defined in {@link audio_errors.h} otherwise.
238      * @since 8
239      */
240     virtual int32_t SetRendererCallback(const std::shared_ptr<AudioRendererCallback> &callback) = 0;
241 
242     /**
243      * @brief Obtains audio renderer parameters.
244      *
245      * This function can be called after {@link SetParams} is successful.
246      *
247      * @param params Indicates information about audio renderer parameters. For details, see
248      * {@link AudioRendererParams}.
249      * @return Returns {@link SUCCESS} if the parameter information is successfully obtained; returns an error code
250      * defined in {@link audio_errors.h} otherwise.
251      * @since 8
252      */
253     virtual int32_t GetParams(AudioRendererParams &params) const = 0;
254 
255     /**
256      * @brief Obtains audio renderer information.
257      *
258      * This function can be called after {@link Create} is successful.
259      *
260      * @param rendererInfo Indicates information about audio renderer. For details, see
261      * {@link AudioRendererInfo}.
262      * @return Returns {@link SUCCESS} if the parameter information is successfully obtained; returns an error code
263      * defined in {@link audio_errors.h} otherwise.
264      * @since 8
265      */
266     virtual int32_t GetRendererInfo(AudioRendererInfo &rendererInfo) const = 0;
267 
268     /**
269      * @brief Obtains renderer stream information.
270      *
271      * This function can be called after {@link Create} is successful.
272      *
273      * @param streamInfo Indicates information about audio renderer. For details, see
274      * {@link AudioStreamInfo}.
275      * @return Returns {@link SUCCESS} if the parameter information is successfully obtained; returns an error code
276      * defined in {@link audio_errors.h} otherwise.
277      * @since 8
278      */
279     virtual int32_t GetStreamInfo(AudioStreamInfo &streamInfo) const = 0;
280 
281     /**
282      * @brief Starts audio rendering.
283      *
284      * @return Returns <b>true</b> if the rendering is successfully started; returns <b>false</b> otherwise.
285      * @since 10
286      */
287     virtual bool Start(StateChangeCmdType cmdType = CMD_FROM_CLIENT) const = 0;
288 
289     /**
290      * @brief Writes audio data.
291      * * This API cannot be used if render mode is RENDER_MODE_CALLBACK.
292      *
293      * @param buffer Indicates the pointer to the buffer which contains the audio data to be written.
294      * @param bufferSize Indicates the size of the buffer which contains audio data to be written, in bytes.
295      * @return Returns the size of the audio data written to the device. The value ranges from <b>0</b> to
296      * <b>bufferSize</b>. If the write fails, one of the following error codes is returned.
297      * <b>ERR_INVALID_PARAM</b>: The input parameter is incorrect.
298      * <b>ERR_ILLEGAL_STATE</b>: The <b>AudioRenderer</b> instance is not initialized.
299      * <b>ERR_INVALID_WRITE</b>: The written audio data size is < 0.
300      * <b>ERR_WRITE_FAILED</b>: The audio data write failed .
301      * @since 8
302      */
303     virtual int32_t Write(uint8_t *buffer, size_t bufferSize) = 0;
304 
305     /**
306      * @brief Obtains the audio renderer state.
307      *
308      * @return Returns the audio renderer state defined in {@link RendererState}.
309      * @since 8
310      */
311     virtual RendererState GetStatus() const = 0;
312 
313     /**
314      * @brief Obtains the timestamp.
315      *
316      * @param timestamp Indicates a {@link Timestamp} instance reference provided by the caller.
317      * @param base Indicates the time base, which can be {@link Timestamp.Timestampbase#BOOTTIME} or
318      * {@link Timestamp.Timestampbase#MONOTONIC}.
319      * @return Returns <b>true</b> if the timestamp is successfully obtained; returns <b>false</b> otherwise.
320      * @since 8
321      */
322     virtual bool GetAudioTime(Timestamp &timestamp, Timestamp::Timestampbase base) const = 0;
323 
324     /**
325      * @brief Obtains the latency in microseconds.
326      *
327      * @param latency Indicates the reference variable into which latency value will be written.
328      * @return Returns {@link SUCCESS} if latency is successfully obtained, returns an error code
329      * defined in {@link audio_errors.h} otherwise.
330      * @since 8
331      */
332     virtual int32_t GetLatency(uint64_t &latency) const = 0;
333 
334     /**
335      * @brief drain renderer buffer.
336      *
337      * @return Returns <b>true</b> if the buffer is successfully drained; returns <b>false</b> otherwise.
338      * @since 8
339      */
340     virtual bool Drain() const = 0;
341 
342     /**
343      * @brief flush renderer stream.
344      *
345      * @return Returns <b>true</b> if the object is successfully flushed; returns <b>false</b> otherwise.
346      * @since 8
347      */
348     virtual bool Flush() const = 0;
349 
350     /**
351      * @brief Pauses audio rendering.
352      *
353      * @return Returns <b>true</b> if the rendering is successfully Paused; returns <b>false</b> otherwise.
354      * @since 10
355      */
356     virtual bool Pause(StateChangeCmdType cmdType = CMD_FROM_CLIENT) const = 0;
357 
358     /**
359      * @brief Stops audio rendering.
360      *
361      * @return Returns <b>true</b> if the rendering is successfully stopped; returns <b>false</b> otherwise.
362      * @since 8
363      */
364     virtual bool Stop() const = 0;
365 
366     /**
367      * @brief Releases a local <b>AudioRenderer</b> object.
368      *
369      * @return Returns <b>true</b> if the object is successfully released; returns <b>false</b> otherwise.
370      * @since 8
371      */
372     virtual bool Release() const = 0;
373 
374     /**
375      * @brief Obtains a reasonable minimum buffer size for rendering, however, the renderer can
376      *        accept other write sizes as well.
377      *
378      * @param bufferSize Indicates the reference variable into which buffer size value will be written.
379      * @return Returns {@link SUCCESS} if bufferSize is successfully obtained; returns an error code
380      * defined in {@link audio_errors.h} otherwise.
381      * @since 8
382      */
383     virtual int32_t GetBufferSize(size_t &bufferSize) const = 0;
384 
385     /**
386      * @brief Obtains the renderer stream id.
387      *
388      * @param sessionId Indicates the reference variable into which stream id value will be written.
389      * @return Returns {@link SUCCESS} if stream id is successfully obtained; returns an error code
390      * defined in {@link audio_errors.h} otherwise.
391      * @since 10
392      */
393     virtual int32_t GetAudioStreamId(uint32_t &sessionID) const = 0;
394 
395     /**
396      * @brief Obtains the number of frames required in the current condition, in bytes per sample.
397      *
398      * @param frameCount Indicates the reference variable in which framecount will be written
399      * @return Returns {@link SUCCESS} if frameCount is successfully obtained; returns an error code
400      * defined in {@link audio_errors.h} otherwise.
401      * @since 8
402      */
403     virtual int32_t GetFrameCount(uint32_t &frameCount) const = 0;
404 
405     /**
406      * @brief Set audio renderer descriptors
407      *
408      * @param audioRendererDesc Audio renderer descriptor
409      * @return Returns {@link SUCCESS} if attribute is successfully set; returns an error code
410      * defined in {@link audio_errors.h} otherwise.
411      * @since 8
412      */
413     virtual int32_t SetAudioRendererDesc(AudioRendererDesc audioRendererDesc) = 0;
414 
415     /**
416      * @brief Update the stream type
417      *
418      * @param audioStreamType Audio stream type
419      * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code
420      * defined in {@link audio_errors.h} otherwise.
421      * @since 8
422      */
423     virtual int32_t SetStreamType(AudioStreamType audioStreamType) = 0;
424 
425     /**
426      * @brief Set the track volume
427      *
428      * @param volume The volume to be set for the current track.
429      * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code
430      * defined in {@link audio_errors.h} otherwise.
431      * @since 8
432      */
433     virtual int32_t SetVolume(float volume) const = 0;
434 
435     /**
436      * @brief Obtains the current track volume
437      *
438      * @return Returns current track volume
439      * @since 8
440      */
441     virtual float GetVolume() const = 0;
442 
443     /**
444      * @brief Set the render rate
445      *
446      * @param renderRate The rate at which the stream needs to be rendered.
447      * @return Returns {@link SUCCESS} if render rate is successfully set; returns an error code
448      * defined in {@link audio_errors.h} otherwise.
449      * @since 8
450      */
451     virtual int32_t SetRenderRate(AudioRendererRate renderRate) const = 0;
452 
453     /**
454      * @brief Obtains the current render rate
455      *
456      * @return Returns current render rate
457      * @since 8
458      */
459     virtual AudioRendererRate GetRenderRate() const = 0;
460 
461     /**
462      * @brief Set the render sampling rate
463      *
464      * @param sampleRate The sample rate at which the stream needs to be rendered.
465      * @return Returns {@link SUCCESS} if render rate is successfully set; returns an error code
466      * defined in {@link audio_errors.h} otherwise.
467      * @since 10
468      */
469     virtual int32_t SetRendererSamplingRate(uint32_t sampleRate) const = 0;
470 
471     /**
472      * @brief Obtains the current render samplingrate
473      *
474      * @return Returns current render samplingrate
475      * @since 10
476      */
477     virtual uint32_t GetRendererSamplingRate() const = 0;
478 
479     /**
480      * @brief Registers the renderer position callback listener
481      *
482      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
483      * defined in {@link audio_errors.h} otherwise.
484      * @since 8
485      */
486     virtual int32_t SetRendererPositionCallback(int64_t markPosition,
487         const std::shared_ptr<RendererPositionCallback> &callback) = 0;
488 
489     /**
490      * @brief Unregisters the renderer position callback listener
491      * @since 8
492      *
493      */
494     virtual void UnsetRendererPositionCallback() = 0;
495 
496     /**
497      * @brief Registers the renderer period position callback listener
498      *
499      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
500      * defined in {@link audio_errors.h} otherwise.
501      * @since 8
502      */
503     virtual int32_t SetRendererPeriodPositionCallback(int64_t frameNumber,
504         const std::shared_ptr<RendererPeriodPositionCallback> &callback) = 0;
505 
506     /**
507      * @brief Unregisters the renderer period position callback listener
508      *
509      * @since 8
510      */
511     virtual void UnsetRendererPeriodPositionCallback() = 0;
512 
513     /**
514      * @brief set the buffer duration for renderer, minimum buffer duration is 5msec
515      *         maximum is 20msec
516      *
517      * @param bufferDuration  Indicates a buffer duration to be set for renderer
518      * @return Returns {@link SUCCESS} if bufferDuration is successfully set; returns an error code
519      * defined in {@link audio_errors.h} otherwise.
520      * @since 8
521      */
522     virtual int32_t SetBufferDuration(uint64_t bufferDuration) const = 0;
523 
524     /**
525      * @brief Obtains the formats supported by renderer.
526      *
527      * @return Returns vector with supported formats.
528      * @since 8
529      */
530     static std::vector<AudioSampleFormat> GetSupportedFormats();
531 
532     /**
533      * @brief Obtains the SupportedSamplingRates supported by renderer.
534      *
535      * @return Returns vector with supported SupportedSamplingRates.
536      * @since 8
537      */
538     static std::vector<AudioSamplingRate> GetSupportedSamplingRates();
539 
540     /**
541      * @brief Obtains the channels supported by renderer.
542      *
543      * @return Returns vector with supported channels.
544      * @since 8
545      */
546     static std::vector<AudioChannel> GetSupportedChannels();
547 
548     /**
549      * @brief Obtains the encoding types supported by renderer.
550      *
551      * @return Returns vector with supported encoding types.
552      * @since 8
553      */
554     static std::vector<AudioEncodingType> GetSupportedEncodingTypes();
555 
556     /**
557      * @brief Sets the render mode. By default the mode is RENDER_MODE_NORMAL.
558      * This API is needs to be used only if RENDER_MODE_CALLBACK is required.
559      *
560      * * @param renderMode The mode of render.
561      * @return  Returns {@link SUCCESS} if render mode is successfully set; returns an error code
562      * defined in {@link audio_errors.h} otherwise.
563      * @since 8
564      */
565     virtual int32_t SetRenderMode(AudioRenderMode renderMode) const = 0;
566 
567     /**
568      * @brief Obtains the render mode.
569      *
570      * @return  Returns current render mode.
571      * @since 8
572      */
573     virtual AudioRenderMode GetRenderMode() const = 0;
574 
575     /**
576      * @brief Registers the renderer write callback listener.
577      * This API should only be used if RENDER_MODE_CALLBACK is needed.
578      *
579      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
580      * defined in {@link audio_errors.h} otherwise.
581      * @since 8
582      */
583     virtual int32_t SetRendererWriteCallback(const std::shared_ptr<AudioRendererWriteCallback> &callback) = 0;
584 
585     /**
586      * @brief Gets the BufferDesc to fill the data.
587      * This API should only be used if RENDER_MODE_CALLBACK is needed.
588      *
589      * @param bufDesc Indicates the buffer descriptor in which data will filled.
590      * refer BufferQueueState in audio_info.h.
591      * @return Returns {@link SUCCESS} if bufDesc is successfully obtained; returns an error code
592      * defined in {@link audio_errors.h} otherwise.
593      * @since 8
594      */
595     virtual int32_t GetBufferDesc(BufferDesc &bufDesc) const = 0;
596 
597     /**
598      * @brief Enqueues the buffer to the bufferQueue.
599      * This API should only be used if RENDER_MODE_CALLBACK is needed.
600      *
601      * @param bufDesc Indicates the buffer descriptor in which buffer data will filled.
602      * refer BufferQueueState in audio_info.h.
603      * @return Returns {@link SUCCESS} if bufDesc is successfully enqued; returns an error code
604      * defined in {@link audio_errors.h} otherwise.
605      * @since 8
606      */
607     virtual int32_t Enqueue(const BufferDesc &bufDesc) const = 0;
608 
609     /**
610      * @brief Clears the bufferQueue.
611      * This API should only be used if RENDER_MODE_CALLBACK is needed.
612      *
613      * @return Returns {@link SUCCESS} if successful; returns an error code
614      * defined in {@link audio_errors.h} otherwise.
615      * @since 8
616      */
617     virtual int32_t Clear() const = 0;
618 
619     /**
620      * @brief Obtains the current state of bufferQueue.
621      * This API should only be used if RENDER_MODE_CALLBACK is needed.
622      *
623      * @param bufDesc Indicates the bufState reference in which state will be obtained.
624      * refer BufferQueueState in audio_info.h.
625      * @return Returns {@link SUCCESS} if bufState is successfully obtained; returns an error code
626      * defined in {@link audio_errors.h} otherwise.
627      * @since 8
628      */
629     virtual int32_t GetBufQueueState(BufferQueueState &bufState) const = 0;
630 
631     /**
632      * @brief Set the application cache path to access the application resources
633      *
634      * @param cachePath Indicates application cache path.
635      * @return none
636      * @since 8
637      */
638     virtual void SetApplicationCachePath(const std::string cachePath) = 0;
639 
640     /**
641      * @brief Set interrupt mode.
642      *
643      * @param mode The interrupt mode.
644      * @return none
645      * @since 9
646      */
647     virtual void SetInterruptMode(InterruptMode mode) = 0;
648 
649     /**
650      * @brief Set volume discount factor.
651      *
652      * @param volume Adjustment percentage.
653      * @return Whether the operation is effective
654      * @since 9
655      */
656     virtual int32_t SetLowPowerVolume(float volume) const = 0;
657 
658     /**
659      * @brief Get volume discount factor.
660      *
661      * @param none.
662      * @return volume adjustment percentage.
663      * @since 9
664      */
665     virtual float GetLowPowerVolume() const = 0;
666 
667     /**
668      * @brief Get single stream volume.
669      *
670      * @param none.
671      * @return single stream volume.
672      * @since 9
673      */
674     virtual float GetSingleStreamVolume() const = 0;
675 
676     /**
677      * @brief Gets the min volume this stream can set.
678      *
679      * @param none.
680      * @return min stream volume.
681      * @since 10
682      */
683     virtual float GetMinStreamVolume() const = 0;
684 
685     /**
686      * @brief Gets the max volume this stream can set.
687      *
688      * @param none.
689      * @return max stream volume.
690      * @since 10
691      */
692     virtual float GetMaxStreamVolume() const = 0;
693 
694     /**
695      * @brief Get underflow count.
696      *
697      * @param none.
698      * @return underflow count.
699      * @since 10
700      */
701     virtual uint32_t GetUnderflowCount() const = 0;
702 
703     /**
704      * @brief Get deviceInfo
705      *
706      * @param deviceInfo.
707      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
708      * defined in {@link audio_errors.h} otherwise.
709      * @since 10
710     */
711     virtual int32_t GetCurrentOutputDevices(DeviceInfo &deviceInfo) const = 0;
712 
713     /**
714      * @brief Gets the audio effect mode.
715      *
716      * @return  Returns current audio effect mode.
717      * @since 10
718      */
719     virtual AudioEffectMode GetAudioEffectMode() const = 0;
720 
721     /**
722      * @brief Gets the audio frame size that has been written.
723      *
724      * @return Returns the audio frame size that has been written.
725      */
726     virtual int64_t GetFramesWritten() const = 0;
727 
728     /**
729      * @brief Sets the audio effect mode.
730      *
731      * * @param effectMode The audio effect mode at which the stream needs to be rendered.
732      * @return  Returns {@link SUCCESS} if audio effect mode is successfully set; returns an error code
733      * defined in {@link audio_errors.h} otherwise.
734      * @since 10
735      */
736     virtual int32_t SetAudioEffectMode(AudioEffectMode effectMode) const = 0;
737 
738     /**
739      * @brief Registers the renderer error event callback listener.
740      *
741      * @param errorCallback Error callback pointer
742      * @since 10
743      */
744     virtual void SetAudioRendererErrorCallback(std::shared_ptr<AudioRendererErrorCallback> errorCallback) = 0;
745 
746     /**
747      * @brief Registers the renderer event callback listener.
748      *
749      * @param clientPid client PID
750      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
751      * defined in {@link audio_errors.h} otherwise.
752      * @since 10
753      */
754     virtual int32_t RegisterAudioRendererEventListener(const int32_t clientPid,
755         const std::shared_ptr<AudioRendererDeviceChangeCallback> &callback);
756 
757     /**
758      * @brief Unregisters the renderer event callback listener.
759      *
760      * @param clientPid client PID
761      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
762      * defined in {@link audio_errors.h} otherwise.
763      * @since 10
764      */
765     virtual int32_t UnregisterAudioRendererEventListener(const int32_t clientPid);
766 
767     /**
768      * @brief Register audio policy service died callback.
769      *
770      * @param clientPid client PID
771      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
772      * defined in {@link audio_errors.h} otherwise.
773      * @since 10
774      */
775     virtual int32_t RegisterAudioPolicyServerDiedCb(const int32_t clientPid,
776         const std::shared_ptr<AudioRendererPolicyServiceDiedCallback> &callback) = 0;
777 
778     /**
779      * @brief Unregister audio policy service died callback.
780      *
781      * @param clientPid client PID
782      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
783      * defined in {@link audio_errors.h} otherwise.
784      * @since 10
785      */
786     virtual int32_t UnregisterAudioPolicyServerDiedCb(const int32_t clientPid) = 0;
787 
788     /**
789      * @brief Destory callback instance when unregister renderer event listener.
790      * @since 10
791      */
792     virtual void DestroyAudioRendererStateCallback() = 0;
793 
794     /**
795      * @brief Set parallel play flag (only for sound pool)
796      *
797      * @param parallelPlayFlag Indicates whether the audio renderer can play in parallel with other stream.
798      * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined
799      * in {@link audio_errors.h} otherwise.
800      * @since 10
801      */
802     virtual int32_t SetParallelPlayFlag(bool parallelPlayFlag) = 0;
803 
804     virtual ~AudioRenderer();
805 private:
806     static std::mutex createRendererMutex_;
807 };
808 }  // namespace AudioStandard
809 }  // namespace OHOS
810 #endif  // AUDIO_RENDERER_H
811