• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 OHOS_AVSESSION_INFO_H
17 #define OHOS_AVSESSION_INFO_H
18 
19 #include <string>
20 
21 #include "avcall_meta_data.h"
22 #include "avcall_state.h"
23 #include "avmeta_data.h"
24 #include "avplayback_state.h"
25 #include "avcast_player_state.h"
26 #include "avmedia_description.h"
27 #include "avqueue_item.h"
28 #include "avsession_descriptor.h"
29 #include "key_event.h"
30 #include "want_params.h"
31 /**
32  * @brief Listening events for the creation and destruction of sessions
33  *     and the latest session changes.
34  * @since 9
35  */
36 namespace OHOS::AVSession {
37 using DeathCallback = std::function<void()>;
38 
39 class SessionListener {
40 public:
41     /**
42      * @brief Listen for session creation events.
43      *
44      * @param descriptor Session related description callback.
45      * @since 9
46     */
47     virtual void OnSessionCreate(const AVSessionDescriptor& descriptor) = 0;
48 
49     /**
50      * @brief Listen for session release events.
51      *
52      * @param descriptor Session related description callback.
53      * @since 9
54     */
55     virtual void OnSessionRelease(const AVSessionDescriptor& descriptor) = 0;
56 
57     /**
58      * @brief Listen for changes in the latest session.
59      *
60      * @param descriptor Session related description callback.
61      * @since 9
62     */
63     virtual void OnTopSessionChange(const AVSessionDescriptor& descriptor) = 0;
64 
65     /**
66      * @brief Listen for AudioSession verification.
67      *
68      * @param uid Session related uid.
69      * @since 9
70     */
OnAudioSessionChecked(const int32_t uid)71     virtual void OnAudioSessionChecked(const int32_t uid) {};
72 
73     /**
74      * @brief Listen for the event of device discovery.
75      *
76      * @param { OutputDeviceInfo } castOutputDeviceInfo - Discovered device info.
77      * @since 10
78     */
OnDeviceAvailable(const OutputDeviceInfo & castOutputDeviceInfo)79     virtual void OnDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo) {};
80 
81     /**
82      * @brief Listen for the event of device offline.
83      *
84      * @param { std::string& } deviceId - Offlined device ID.
85      * @since 10
86     */
OnDeviceOffline(const std::string & deviceId)87     virtual void OnDeviceOffline(const std::string& deviceId) {};
88 
89     /**
90      * @brief Deconstruct SessionListener.
91      * @since 9
92     */
93     virtual ~SessionListener() = default;
94 };
95 
96 class IAVCastControllerProxyListener {
97 public:
98     virtual void OnCastPlaybackStateChange(const AVPlaybackState& state) = 0;
99 
100     virtual void OnMediaItemChange(const AVQueueItem& avQueueItem) = 0;
101 
102     virtual void OnPlayNext() = 0;
103 
104     virtual void OnPlayPrevious() = 0;
105 
106     virtual void OnSeekDone(const int32_t seekNumber) = 0;
107 
108     virtual void OnVideoSizeChange(const int32_t width, const int32_t height) = 0;
109 
110     virtual void OnPlayerError(const int32_t errorCode, const std::string& errorMsg) = 0;
111 
112     virtual void OnEndOfStream(const int32_t isLooping) = 0;
113 
114     virtual void OnPlayRequest(const AVQueueItem& avQueueItem) = 0;
115 
116     /**
117      * @brief Deconstruct SessionListener.
118      * @since 9
119     */
120     virtual ~IAVCastControllerProxyListener() = default;
121 };
122 
123 class AVSessionCallback {
124 public:
125     /**
126      * @brief playback.
127      * @since 9
128     */
129     virtual void OnPlay() = 0;
130 
131     /**
132      * @brief Pause playback.
133      * @since 9
134     */
135     virtual void OnPause() = 0;
136 
137     /**
138      * @brief Stop playback.
139      * @since 9
140     */
141     virtual void OnStop() = 0;
142 
143     /**
144      * @brief play next.
145      * @since 9
146     */
147     virtual void OnPlayNext() = 0;
148 
149     /**
150      * @brief Play the previous song.
151      * @since 9
152     */
153     virtual void OnPlayPrevious() = 0;
154 
155     /**
156      * @brief Fast forward.
157      *
158      * @param time fastforward skip intervals
159      * @since 9
160     */
161     virtual void OnFastForward(int64_t time) = 0;
162 
163     /**
164      * @brief Fast rewind.
165      *
166      * @param time rewind skip intervals
167      * @since 9
168     */
169     virtual void OnRewind(int64_t time) = 0;
170 
171     /**
172      * @brief Seek to the specified time.
173      *
174      * @param time Seek to the specified time
175      * @since 9
176     */
177     virtual void OnSeek(int64_t time) = 0;
178 
179     /**
180      * @brief Set playback speed.
181      *
182      * @param speed The playback speed to be set
183      * @return Whether the playback speed is set successfully
184      * @since 9
185     */
186     virtual void OnSetSpeed(double speed) = 0;
187 
188     /**
189      * @brief Set cycle mode.
190      *
191      * @param mode Cycle mode to be set {@link LoopMode}
192      * @return Whether the cycle mode is set successfully.
193      * @since 9
194     */
195     virtual void OnSetLoopMode(int32_t loopMode) = 0;
196 
197     /**
198      * @brief Whether to collect the current song.
199      *
200      * @param mediald current song id.
201      * @since 9
202     */
203     virtual void OnToggleFavorite(const std::string& mediald) = 0;
204 
205     /**
206      * @brief Listening for Media key events.
207      *
208      * @param keyEvent event callbacks.
209      * @since 9
210     */
211     virtual void OnMediaKeyEvent(const MMI::KeyEvent& keyEvent) = 0;
212 
213     /**
214      * @brief Monitor and play device change events.
215      *
216      * @param connectionState Event callback of device state.
217      * @param outputDeviceInfo Event callback of device information.
218      * @since 9
219     */
220     virtual void OnOutputDeviceChange(const int32_t connectionState, const OutputDeviceInfo& outputDeviceInfo) = 0;
221 
222     /**
223      * @brief Listen for command events.
224      *
225      * @param commonCommand The name of the command to be sent.
226     * @param commandArgs Command packets to be sent
227      * @since 10
228      */
229     virtual void OnCommonCommand(const std::string& commonCommand, const AAFwk::WantParams& commandArgs) = 0;
230 
231     /**
232      * @brief Listen to the change of item in the playlist to be played.
233      *
234      * @param itemId The serial number of the item to be played.
235      * @since 10
236      */
237     virtual void OnSkipToQueueItem(int32_t itemId) = 0;
238 
239     /**
240      * Register answer command callback.
241      * @since 11
242      */
243     virtual void OnAVCallAnswer() = 0;
244 
245     /**
246      * Register hangUp command callback.
247      * @since 11
248      */
249     virtual void OnAVCallHangUp() = 0;
250 
251     /**
252      * Register toggleCallMute command callback.
253      * @since 11
254      */
255     virtual void OnAVCallToggleCallMute() = 0;
256 
257     /**
258      * @brief Play from assetId.
259      *
260      * @param assetId Id for asset
261      * @since 11
262     */
263     virtual void OnPlayFromAssetId(int64_t assetId) = 0;
264 
265     /**
266      * @brief Deconstruct AVSessionCallback.
267      * @since 9
268     */
269     virtual ~AVSessionCallback() = default;
270 };
271 
272 class AVControllerCallback {
273 public:
274 
275     /**
276      * @brief Listen for avcall metadata change events.
277      *
278      * @param avCallMetaData is the changed avcall metadata.
279      * @since 11
280     */
281     virtual void OnAVCallMetaDataChange(const AVCallMetaData& avCallMetaData) = 0;
282 
283     /**
284      * @brief Listening session avcall status change event.
285      *
286      * @param avCallState Session related avcall state.
287      * @since 11
288     */
289     virtual void OnAVCallStateChange(const AVCallState& avCallState) = 0;
290     /**
291      * @brief Session Destroy.
292      * @since 9
293     */
294     virtual void OnSessionDestroy() = 0;
295 
296     /**
297      * @brief Listening session destruction playback status change event.
298      *
299      * @param state Session related description callback.
300      * @since 9
301     */
302     virtual void OnPlaybackStateChange(const AVPlaybackState& state) = 0;
303 
304     /**
305      * @brief Listen for metadata change events.
306      *
307      * @param data Data is the changed metadata.
308      * @since 9
309     */
310     virtual void OnMetaDataChange(const AVMetaData& data) = 0;
311 
312     /**
313      * @brief Listen to the activation status event of the session.
314      *
315      * @param isActive Whether the session is activated.
316      * @since 9
317     */
318     virtual void OnActiveStateChange(bool isActive) = 0;
319 
320     /**
321      * @brief Listen for valid command change events supported by the session.
322      *
323      * @param cmds Collection callback of valid commands.
324      * @since 9
325     */
326     virtual void OnValidCommandChange(const std::vector<int32_t>& cmds) = 0;
327 
328     /**
329      * @brief Monitor and play device change events.
330      *
331      * @param connectionState Event callback of device state.
332      * @param outputDeviceInfo Device related information callback.
333      * @since 9
334     */
335     virtual void OnOutputDeviceChange(const int32_t connectionState, const OutputDeviceInfo& outputDeviceInfo) = 0;
336 
337     /**
338      * @brief Listen for changes in custom events of the session.
339      *
340      * @param event Changed session event name.
341      * @param args Parameters of parts.
342      * @since 9
343     */
344     virtual void OnSessionEventChange(const std::string& event, const AAFwk::WantParams& args) = 0;
345 
346     /**
347      * @brief Session playlist change callback.
348      *
349      * @param items The changed queue items.
350      * @since 10
351      */
352     virtual void OnQueueItemsChange(const std::vector<AVQueueItem>& items) = 0;
353 
354     /**
355      * @brief Session title change callback.
356      *
357      * @param title The changed title.
358      * @since 10
359      */
360     virtual void OnQueueTitleChange(const std::string& title) = 0;
361 
362     /**
363      * @brief Session custom media packet change callback.
364      *
365      * @param extras The changed custom media packet.
366      * @since 10
367      */
368     virtual void OnExtrasChange(const AAFwk::WantParams& extras) = 0;
369 
370     /**
371      * @brief Deconstruct AVControllerCallback.
372      * @since 9
373     */
374     virtual ~AVControllerCallback() = default;
375 };
376 
377 class AVCastControllerCallback {
378 public:
379     virtual void OnCastPlaybackStateChange(const AVPlaybackState& state) = 0;
380 
381     virtual void OnMediaItemChange(const AVQueueItem& avQueueItem) = 0;
382 
383     virtual void OnPlayNext() = 0;
384 
385     virtual void OnPlayPrevious() = 0;
386 
387     virtual void OnSeekDone(const int32_t seekNumber) = 0;
388 
389     virtual void OnVideoSizeChange(const int32_t width, const int32_t height) = 0;
390 
391     virtual void OnPlayerError(const int32_t errorCode, const std::string& errorMsg) = 0;
392 
393     virtual void OnEndOfStream(const int32_t isLooping) = 0;
394 
395     virtual void OnPlayRequest(const AVQueueItem& avQueueItem) = 0;
396 
397     /**
398      * @brief Deconstruct AVControllerCallback.
399      * @since 9
400     */
401     virtual ~AVCastControllerCallback() = default;
402 };
403 
404 class IAVCastSessionStateListener {
405 public:
406     /**
407      * @brief Listen to the change of cast state change.
408      *
409      * @param castHandle The combination of providerId and castId.
410      * @since 9
411     */
412     virtual void OnCastStateChange(int32_t castState, DeviceInfo deviceInfo) = 0;
413 
414     /**
415      * @brief Listen to the change of cast event.
416      *
417      * @param castHandle The combination of providerId and castId.
418      * @since 9
419     */
420     virtual void OnCastEventRecv(int32_t errorCode, std::string& errorMsg) = 0;
421 
422     /**
423      * @brief Deconstruct IAVCastSessionStateListener.
424      * @since 10
425     */
426     virtual ~IAVCastSessionStateListener() = default;
427 };
428 
429 
430 struct SessionToken {
431     std::string sessionId;
432     pid_t pid;
433     pid_t uid;
434 };
435 
436 enum SessionDataCategory {
437     SESSION_DATA_CATEGORY_INVALID = -1,
438     SESSION_DATA_META = 0,
439     SESSION_DATA_PLAYBACK_STATE = 1,
440     SESSION_DATA_CONTROL_COMMAND = 2,
441     SESSION_DATA_SET_EVENT = 3,
442     SESSION_DATA_QUEUE_ITEMS = 4,
443     SESSION_DATA_QUEUE_TITLE = 5,
444     SESSION_DATA_COMMON_COMMAND = 6,
445     SESSION_DATA_EXTRAS = 7,
446     SESSION_DATA_CATEGORY_MAX = 8,
447 };
448 
449 enum AVCastCategory {
450     /**
451      * The default cast type "local", media can be routed on the same device,
452      * including internal speakers or audio jacks on the device itself, A2DP devices.
453      * @syscap SystemCapability.Multimedia.AVSession.AVCast
454      * @since 10
455      */
456     CATEGORY_LOCAL = 0,
457 
458     /**
459      * The remote category indicating the media is presenting on a remote device,
460      * the application needs to get an AVCastController to control remote playback.
461      * @syscap SystemCapability.Multimedia.AVSession.AVCast
462      * @since 10
463      */
464     CATEGORY_REMOTE = 1,
465 };
466 
467 enum ProtocolType {
468     /**
469      * The default cast type "local", media can be routed on the same device,
470      * including internal speakers or audio jacks on the device itself, A2DP devices.
471      * @syscap SystemCapability.Multimedia.AVSession.AVCast
472      * @since 10
473      */
474     TYPE_LOCAL = 0,
475 
476     /**
477      * Cast+ mirror capability
478      * @syscap SystemCapability.Multimedia.AVSession.AVCast
479      * @systemapi
480      * @since 10
481      */
482     TYPE_CAST_PLUS_MIRROR  = 1,
483 
484     /**
485      * The Cast+ Stream indicating the media is presenting on a different device
486      * the application need get an AVCastController to control remote playback.
487      * @syscap SystemCapability.Multimedia.AVSession.AVCast
488      * @since 10
489      */
490     TYPE_CAST_PLUS_STREAM  = 2,
491 };
492 
493 /**
494  * Define the device connection state.
495  * @syscap SystemCapability.Multimedia.AVSession.Core
496  * @since 10
497  */
498 enum ConnectionState {
499     /**
500      * A connection state indicating the device is in the process of connecting.
501      * @syscap SystemCapability.Multimedia.AVSession.Core
502      * @since 10
503      */
504     STATE_CONNECTING = 0,
505     /**
506      * A connection state indicating the device is connected.
507      * @syscap SystemCapability.Multimedia.AVSession.Core
508      * @since 10
509      */
510     STATE_CONNECTED = 1,
511     /**
512      * The default connection state indicating the device is disconnected.
513      * @syscap SystemCapability.Multimedia.AVSession.Core
514      * @since 10
515      */
516     STATE_DISCONNECTED = 6,
517 };
518 
519 enum DeviceType {
520     /**
521      * A device type indicating the route is on internal speakers or audio jacks on the device itself.
522      * @since 10
523      * @syscap SystemCapability.Multimedia.AVSession.Core
524      */
525     DEVICE_TYPE_LOCAL = 0,
526     /**
527      * A device type indicating the route is on a TV.
528      * @since 10
529      * @syscap SystemCapability.Multimedia.AVSession.AVCast
530      */
531     DEVICE_TYPE_TV = 2,
532     /**
533      * A device type indicating the route is on a smart speaker.
534      * @since 10
535      * @syscap SystemCapability.Multimedia.AVSession.AVCast
536      */
537     DEVICE_TYPE_SMART_SPEAKER = 3,
538     /**
539      * A device type indicating the route is on a bluetooth device.
540      * @since 10
541      * @syscap SystemCapability.Multimedia.AVSession.Core
542      */
543     DEVICE_TYPE_BLUETOOTH = 10,
544 };
545 
546 enum CastEngineConnectState {
547     CONNECTING = 0,
548     CONNECTED = 1,
549     PAUSED = 2,
550     PLAYING = 3,
551     DISCONNECTING = 4,
552     DISCONNECTED = 5,
553     STREAM = 6,
554     MIRROR_TO_UI = 7,
555     UI_TO_MIRROR = 8,
556     UICAST = 9,
557     DEVICE_STATE_MAX = 10,
558 };
559 
560 /**
561  * Enumerates ErrorCode types, returns in BusinessError.code.
562  * @enum { number }
563  * @syscap SystemCapability.Multimedia.AVSession.Core
564  * @since 10
565  */
566 enum AVSessionErrorCode {
567     /**
568      * Session service exception.
569      * @syscap SystemCapability.Multimedia.AVSession.Core
570      * @since 10
571      */
572     ERR_CODE_SERVICE_EXCEPTION = 6600101,
573 
574     /**
575      * The session does not exist
576      * @syscap SystemCapability.Multimedia.AVSession.Core
577      * @since 10
578      */
579     ERR_CODE_SESSION_NOT_EXIST = 6600102,
580 
581     /**
582      * The session controller does not exist.
583      * @syscap SystemCapability.Multimedia.AVSession.Core
584      * @since 10
585      */
586     ERR_CODE_CONTROLLER_NOT_EXIST = 6600103,
587 
588     /**
589      * The remote session connection failed.
590      * @syscap SystemCapability.Multimedia.AVSession.Core
591      * @since 10
592      */
593     ERR_CODE_REMOTE_CONNECTION_ERR = 6600104,
594 
595     /**
596      * Invalid session command.
597      * @syscap SystemCapability.Multimedia.AVSession.Core
598      * @since 10
599      */
600     ERR_CODE_COMMAND_INVALID = 6600105,
601 
602     /**
603      * The session is not activated.
604      * @syscap SystemCapability.Multimedia.AVSession.Core
605      * @since 10
606      */
607     ERR_CODE_SESSION_INACTIVE = 6600106,
608 
609     /**
610      * Too many commands or events.
611      * @syscap SystemCapability.Multimedia.AVSession.Core
612      * @since 10
613      */
614     ERR_CODE_MESSAGE_OVERLOAD = 6600107,
615 
616     /**
617      * Device connecting failed.
618      * @syscap SystemCapability.Multimedia.AVSession.Core
619      * @since 10
620      */
621     ERR_CODE_DEVICE_CONNECTION_FAILED = 6600108,
622 
623     /**
624      * The remote connection is not established.
625      * @syscap SystemCapability.Multimedia.AVSession.Core
626      * @since 10
627      */
628     ERR_CODE_REMOTE_CONNECTION_NOT_EXIST = 6600109,
629 };
630 } // namespace OHOS::AVSession
631 #endif // OHOS_AVSESSION_INFO_H
632