261fcd51cadfae9d5f170bc6651ea99e731431d4
[platform/framework/web/chromium-efl.git] /
1 // Copyright (c) 2020 Samsung Electronics. 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 TIZEN_SRC_CHROMIUM_IMPL_CONTENT_RENDERER_MEDIA_TIZEN_ELEMENTARY_MEDIA_STREAM_SOURCE_ANY_THREAD_TRACK_DISPATCHER_H_
6 #define TIZEN_SRC_CHROMIUM_IMPL_CONTENT_RENDERER_MEDIA_TIZEN_ELEMENTARY_MEDIA_STREAM_SOURCE_ANY_THREAD_TRACK_DISPATCHER_H_
7
8 #include <memory>
9 #include <tuple>
10 #include <utility>
11
12 #include "base/functional/bind.h"
13 #include "base/functional/callback.h"
14 #include "base/memory/scoped_refptr.h"
15 #include "base/task/single_thread_task_runner.h"
16 #include "base/threading/thread.h"
17 #include "content/renderer/media/tizen/elementary_media_stream_source/any_thread/audio_track_impl.h"
18 #include "content/renderer/media/tizen/elementary_media_stream_source/any_thread/source_dispatcher.h"
19 #include "content/renderer/media/tizen/elementary_media_stream_source/any_thread/track_params.h"
20 #include "content/renderer/media/tizen/elementary_media_stream_source/any_thread/video_track_impl.h"
21 #include "content/renderer/media/tizen/elementary_media_stream_source/common/dispatcher.h"
22 #include "content/renderer/media/tizen/elementary_media_stream_source/control_thread/audio_track_impl.h"
23 #include "content/renderer/media/tizen/elementary_media_stream_source/control_thread/video_track_impl.h"
24 #include "content/renderer/media/tizen/elementary_media_stream_source/worker_thread/audio_track_impl.h"
25 #include "content/renderer/media/tizen/elementary_media_stream_source/worker_thread/video_track_impl.h"
26 #include "media/base/audio_decoder.h"
27 #include "media/base/audio_decoder_config.h"
28 #include "media/base/decryptor.h"
29 #include "media/base/tizen/stream_framerate.h"
30 #include "media/base/video_decoder_config.h"
31 #include "ui/gfx/geometry/size.h"
32
33 namespace blink {
34 class WebElementaryMediaTrackControl;
35 class WebElementaryMediaTrackOperations;
36 }  // namespace blink
37
38 namespace content::elementary_media_stream_source {
39
40 namespace control_thread {
41 class TrackDispatcherClient;
42 class TrackImpl;
43 }  // namespace control_thread
44
45 namespace worker_thread {
46 class TrackDispatcherClient;
47 class TrackImpl;
48 }  // namespace worker_thread
49
50 namespace any_thread {
51 class TrackDispatcherClient;
52 class TrackImpl;
53
54 // Class used for communication between
55 // {any|control|worker}_thread::TrackImpl classes.
56 class TrackDispatcher : public Dispatcher<TrackDispatcher> {
57   using Dispatcher = Dispatcher<TrackDispatcher>;
58   friend Dispatcher;
59
60  public:
61   using AnyThreadClient = any_thread::TrackDispatcherClient;
62   using ControlThreadClient = control_thread::TrackDispatcherClient;
63   using WorkerThreadClient = worker_thread::TrackDispatcherClient;
64
65   ~TrackDispatcher() override;
66
67   using DecryptDoneCB =
68       base::RepeatingCallback<void(worker_thread::TrackDispatcherClient*,
69                                    any_thread::TrackDispatcherClient*,
70                                    media::Decryptor::Status,
71                                    scoped_refptr<media::DecoderBuffer>)>;
72
73   void DispatchAppendPacket(
74       base::OnceCallback<void(media::Decryptor::DecryptCBTizen decrypt_cb)>&&,
75       DecryptDoneCB&& buffer);
76
77  protected:
78   TrackDispatcher(
79       TrackMode,
80       TrackType,
81       const scoped_refptr<base::SingleThreadTaskRunner>&
82           control_thread_task_runner,
83       scoped_refptr<base::SequencedTaskRunner> worker_thread_task_runner);
84
85  private:
86   using Clients = std::tuple<std::shared_ptr<AnyThreadClient>,
87                              std::shared_ptr<ControlThreadClient>,
88                              std::shared_ptr<WorkerThreadClient>>;
89
90   using CreationTuple = std::tuple<std::shared_ptr<TrackDispatcher>,
91                                    std::shared_ptr<any_thread::TrackImpl>,
92                                    std::shared_ptr<control_thread::TrackImpl>,
93                                    std::shared_ptr<worker_thread::TrackImpl>>;
94
95   static CreationTuple Create(
96       TrackMode,
97       const scoped_refptr<base::SingleThreadTaskRunner>&
98           control_thread_task_runner,
99       scoped_refptr<base::SequencedTaskRunner> worker_thread_task_runner,
100       media::AudioDecoderConfig&& configs);
101
102   static CreationTuple Create(
103       TrackMode,
104       const scoped_refptr<base::SingleThreadTaskRunner>&
105           control_thread_task_runner,
106       scoped_refptr<base::SequencedTaskRunner> worker_thread_task_runner,
107       media::VideoDecoderConfig&& configs);
108
109   TrackType Type() const { return type_; }
110
111   Clients clients_;
112   const TrackMode track_mode_;
113   const TrackType type_;
114   const scoped_refptr<base::SequencedTaskRunner> worker_thread_task_runner_;
115
116   friend std::tuple<std::shared_ptr<TrackDispatcher>,
117                     std::shared_ptr<blink::WebElementaryMediaTrackControl>,
118                     std::shared_ptr<blink::WebElementaryMediaTrackOperations>>
119   SourceDispatcher::CreateAudioTrackDispatcher(
120       media::AudioDecoderConfig&& config);
121
122   friend std::tuple<std::shared_ptr<TrackDispatcher>,
123                     std::shared_ptr<blink::WebElementaryMediaTrackControl>,
124                     std::shared_ptr<blink::WebElementaryMediaTrackOperations>>
125   SourceDispatcher::CreateVideoTrackDispatcher(
126       media::VideoDecoderConfig&& config);
127 };
128
129 }  // namespace any_thread
130
131 }  // namespace content::elementary_media_stream_source
132
133 #endif  // TIZEN_SRC_CHROMIUM_IMPL_CONTENT_RENDERER_MEDIA_TIZEN_ELEMENTARY_MEDIA_STREAM_SOURCE_ANY_THREAD_TRACK_DISPATCHER_H_