xref: /aosp_15_r20/external/openscreen/cast/standalone_receiver/streaming_playback_controller.h (revision 3f982cf4871df8771c9d4abe6e9a6f8d829b2736)
1 // Copyright 2019 The Chromium 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 #ifndef CAST_STANDALONE_RECEIVER_STREAMING_PLAYBACK_CONTROLLER_H_
6 #define CAST_STANDALONE_RECEIVER_STREAMING_PLAYBACK_CONTROLLER_H_
7 
8 #include <memory>
9 
10 #include "cast/standalone_receiver/simple_remoting_receiver.h"
11 #include "cast/streaming/receiver_session.h"
12 #include "platform/impl/task_runner.h"
13 
14 #if defined(CAST_STANDALONE_RECEIVER_HAVE_EXTERNAL_LIBS)
15 #include "cast/standalone_receiver/sdl_audio_player.h"  // nogncheck
16 #include "cast/standalone_receiver/sdl_glue.h"          // nogncheck
17 #include "cast/standalone_receiver/sdl_video_player.h"  // nogncheck
18 #else
19 #include "cast/standalone_receiver/dummy_player.h"  // nogncheck
20 #endif  // defined(CAST_STANDALONE_RECEIVER_HAVE_EXTERNAL_LIBS)
21 
22 namespace openscreen {
23 namespace cast {
24 
25 class StreamingPlaybackController final : public ReceiverSession::Client {
26  public:
27   class Client {
28    public:
29     virtual void OnPlaybackError(StreamingPlaybackController* controller,
30                                  Error error) = 0;
31 
32    protected:
33     virtual ~Client();
34   };
35 
36   StreamingPlaybackController(TaskRunner* task_runner,
37                               StreamingPlaybackController::Client* client);
38 
39   // ReceiverSession::Client overrides.
40   void OnNegotiated(const ReceiverSession* session,
41                     ReceiverSession::ConfiguredReceivers receivers) override;
42   void OnRemotingNegotiated(
43       const ReceiverSession* session,
44       ReceiverSession::RemotingNegotiation negotiation) override;
45   void OnReceiversDestroying(const ReceiverSession* session,
46                              ReceiversDestroyingReason reason) override;
47   void OnError(const ReceiverSession* session, Error error) override;
48 
49  private:
50   TaskRunner* const task_runner_;
51   StreamingPlaybackController::Client* client_;
52 
53   void Initialize(ReceiverSession::ConfiguredReceivers receivers);
54 
55 #if defined(CAST_STANDALONE_RECEIVER_HAVE_EXTERNAL_LIBS)
56   void HandleKeyboardEvent(const SDL_KeyboardEvent& event);
57 
58   // NOTE: member ordering is important, since the sub systems must be
59   // first-constructed, last-destroyed. Make sure any new SDL related
60   // members are added below the sub systems.
61   const ScopedSDLSubSystem<SDL_INIT_AUDIO> sdl_audio_sub_system_;
62   const ScopedSDLSubSystem<SDL_INIT_VIDEO> sdl_video_sub_system_;
63   SDLEventLoopProcessor sdl_event_loop_;
64 
65   SDLWindowUniquePtr window_;
66   SDLRendererUniquePtr renderer_;
67   std::unique_ptr<SDLAudioPlayer> audio_player_;
68   std::unique_ptr<SDLVideoPlayer> video_player_;
69   double is_playing_ = true;
70 #else
71   std::unique_ptr<DummyPlayer> audio_player_;
72   std::unique_ptr<DummyPlayer> video_player_;
73 #endif  // defined(CAST_STANDALONE_RECEIVER_HAVE_EXTERNAL_LIBS)
74 
75   std::unique_ptr<SimpleRemotingReceiver> remoting_receiver_;
76 };
77 
78 }  // namespace cast
79 }  // namespace openscreen
80 
81 #endif  // CAST_STANDALONE_RECEIVER_STREAMING_PLAYBACK_CONTROLLER_H_
82