[M120 Migration][MM][CAPI] Fix the logic for media using capi player.
[platform/framework/web/chromium-efl.git] / media / mojo / services / playback_events_recorder.h
1 // Copyright 2020 The Chromium Authors
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 MEDIA_MOJO_SERVICES_PLAYBACK_EVENTS_RECORDER_H_
6 #define MEDIA_MOJO_SERVICES_PLAYBACK_EVENTS_RECORDER_H_
7
8 #include "base/time/time.h"
9 #include "media/mojo/mojom/playback_events_recorder.mojom.h"
10 #include "media/mojo/services/media_mojo_export.h"
11 #include "mojo/public/cpp/bindings/pending_remote.h"
12 #include "mojo/public/cpp/bindings/remote.h"
13 #include "third_party/abseil-cpp/absl/types/optional.h"
14
15 namespace media {
16
17 class MEDIA_MOJO_EXPORT PlaybackEventsRecorder final
18     : public mojom::PlaybackEventsRecorder {
19  public:
20   static void Create(
21       mojo::PendingReceiver<mojom::PlaybackEventsRecorder> receiver);
22
23   PlaybackEventsRecorder();
24   ~PlaybackEventsRecorder() final;
25
26   PlaybackEventsRecorder(const PlaybackEventsRecorder&) = delete;
27   PlaybackEventsRecorder& operator=(const PlaybackEventsRecorder&) =
28       delete;
29
30   // mojom::PlaybackEventsRecorder implementation.
31   void OnPlaying() final;
32   void OnPaused() final;
33   void OnSeeking() final;
34   void OnEnded() final;
35   void OnBuffering() final;
36   void OnBufferingComplete() final;
37   void OnError(const PipelineStatus& status) final;
38   void OnNaturalSizeChanged(const gfx::Size& size) final;
39   void OnPipelineStatistics(const PipelineStatistics& stats) final;
40
41  private:
42   class BitrateEstimator {
43    public:
44     BitrateEstimator();
45     ~BitrateEstimator();
46
47     void Update(const PipelineStatistics& stats);
48     void OnPause();
49
50    private:
51     base::TimeDelta time_elapsed_;
52     size_t audio_bytes_ = 0;
53     size_t video_bytes_ = 0;
54
55     absl::optional<PipelineStatistics> last_stats_;
56     base::TimeTicks last_stats_time_;
57   };
58
59   enum class BufferingState {
60     kInitialBuffering,
61     kBuffering,
62     kBuffered,
63   };
64
65   BufferingState buffering_state_ = BufferingState::kInitialBuffering;
66   base::TimeTicks buffering_start_time_;
67   base::TimeTicks last_buffering_end_time_;
68
69   BitrateEstimator bitrate_estimator_;
70 };
71
72 }  // namespace media
73
74 #endif  // MEDIA_MOJO_SERVICES_PLAYBACK_EVENTS_RECORDER_H_