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.
5 #ifndef MEDIA_MOJO_SERVICES_PLAYBACK_EVENTS_RECORDER_H_
6 #define MEDIA_MOJO_SERVICES_PLAYBACK_EVENTS_RECORDER_H_
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"
17 class MEDIA_MOJO_EXPORT PlaybackEventsRecorder final
18 : public mojom::PlaybackEventsRecorder {
21 mojo::PendingReceiver<mojom::PlaybackEventsRecorder> receiver);
23 PlaybackEventsRecorder();
24 ~PlaybackEventsRecorder() final;
26 PlaybackEventsRecorder(const PlaybackEventsRecorder&) = delete;
27 PlaybackEventsRecorder& operator=(const PlaybackEventsRecorder&) =
30 // mojom::PlaybackEventsRecorder implementation.
31 void OnPlaying() final;
32 void OnPaused() final;
33 void OnSeeking() 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;
42 class BitrateEstimator {
47 void Update(const PipelineStatistics& stats);
51 base::TimeDelta time_elapsed_;
52 size_t audio_bytes_ = 0;
53 size_t video_bytes_ = 0;
55 absl::optional<PipelineStatistics> last_stats_;
56 base::TimeTicks last_stats_time_;
59 enum class BufferingState {
65 BufferingState buffering_state_ = BufferingState::kInitialBuffering;
66 base::TimeTicks buffering_start_time_;
67 base::TimeTicks last_buffering_end_time_;
69 BitrateEstimator bitrate_estimator_;
74 #endif // MEDIA_MOJO_SERVICES_PLAYBACK_EVENTS_RECORDER_H_