buffering_state.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2014 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. #ifndef MEDIA_BASE_BUFFERING_STATE_H_
  5. #define MEDIA_BASE_BUFFERING_STATE_H_
  6. #include <string>
  7. #include "base/callback_forward.h"
  8. namespace media {
  9. enum BufferingState {
  10. // Indicates that there is no data buffered.
  11. //
  12. // Typical reason is data underflow and hence playback should be paused.
  13. BUFFERING_HAVE_NOTHING,
  14. // Indicates that enough data has been buffered.
  15. //
  16. // Typical reason is enough data has been prerolled to start playback.
  17. BUFFERING_HAVE_ENOUGH,
  18. BUFFERING_STATE_MAX = BUFFERING_HAVE_ENOUGH,
  19. };
  20. enum BufferingStateChangeReason {
  21. // The reason for the change is not known. This is a valid value for both
  22. // HAVE_NOTHING and HAVE_ENOUGH states. Notably, it is used with all
  23. // HAVE_ENOUGH events. The real cause of have HAVE_ENOUGH events is either
  24. // completion of initial pre-roll, or a resolution of the previous underflow's
  25. // cause. Interested observers can determine this by checking the most recent
  26. // state change events. This reason may also be provided for some HAVE_NOTHING
  27. // events where it is architecturally difficult to determine the cause.
  28. BUFFERING_CHANGE_REASON_UNKNOWN,
  29. // Renderer ran out of decoded frames because of delay getting more encoded
  30. // data from the demuxer. For src=, this indicates network slowness. For MSE
  31. // it means the data wasn't appended in time (probably also network slowness).
  32. DEMUXER_UNDERFLOW,
  33. // Renderer ran out of decoded frames because decoder couldn't keep up.
  34. DECODER_UNDERFLOW,
  35. // The local demuxer has the data, but the remote renderer (e.g. cast) hasn't
  36. // received it yet. Only possible during media "remoting".
  37. REMOTING_NETWORK_CONGESTION,
  38. BUFFERING_STATE_CHANGE_REASON_MAX = REMOTING_NETWORK_CONGESTION,
  39. };
  40. enum class SerializableBufferingStateType {
  41. kPipeline,
  42. kVideo,
  43. kAudio,
  44. };
  45. // A serializable combo of the state, type, and reason.
  46. template <SerializableBufferingStateType T>
  47. struct SerializableBufferingState {
  48. BufferingState state;
  49. BufferingStateChangeReason reason;
  50. // Only included in the serialized state if |type == kPipeline|
  51. bool suspended_start = false;
  52. };
  53. // Used to indicate changes in buffering state;
  54. using BufferingStateCB =
  55. base::RepeatingCallback<void(BufferingState, BufferingStateChangeReason)>;
  56. std::string BufferingStateToString(
  57. BufferingState state,
  58. BufferingStateChangeReason reason = BUFFERING_CHANGE_REASON_UNKNOWN);
  59. } // namespace media
  60. #endif // MEDIA_BASE_BUFFERING_STATE_H_