1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78

media / base / buffering_state.h [blame]

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_BASE_BUFFERING_STATE_H_
#define MEDIA_BASE_BUFFERING_STATE_H_

#include <string>

#include "base/functional/callback_forward.h"

namespace media {

enum BufferingState {
  // Indicates that there is no data buffered.
  //
  // Typical reason is data underflow and hence playback should be paused.
  BUFFERING_HAVE_NOTHING,

  // Indicates that enough data has been buffered.
  //
  // Typical reason is enough data has been prerolled to start playback.
  BUFFERING_HAVE_ENOUGH,

  BUFFERING_STATE_MAX = BUFFERING_HAVE_ENOUGH,
};

enum BufferingStateChangeReason {
  // The reason for the change is not known. This is a valid value for both
  // HAVE_NOTHING and HAVE_ENOUGH states. Notably, it is used with all
  // HAVE_ENOUGH events. The real cause of have HAVE_ENOUGH events is either
  // completion of initial pre-roll, or a resolution of the previous underflow's
  // cause. Interested observers can determine this by checking the most recent
  // state change events. This reason may also be provided for some HAVE_NOTHING
  // events where it is architecturally difficult to determine the cause.
  BUFFERING_CHANGE_REASON_UNKNOWN,

  // Renderer ran out of decoded frames because of delay getting more encoded
  // data from the demuxer. For src=, this indicates network slowness. For MSE
  // it means the data wasn't appended in time (probably also network slowness).
  DEMUXER_UNDERFLOW,

  // Renderer ran out of decoded frames because decoder couldn't keep up.
  DECODER_UNDERFLOW,

  // The local demuxer has the data, but the remote renderer (e.g. cast) hasn't
  // received it yet. Only possible during media "remoting".
  REMOTING_NETWORK_CONGESTION,

  BUFFERING_STATE_CHANGE_REASON_MAX = REMOTING_NETWORK_CONGESTION,
};

enum class SerializableBufferingStateType {
  kPipeline,
  kVideo,
  kAudio,
};

// A serializable combo of the state, type, and reason.
template <SerializableBufferingStateType T>
struct SerializableBufferingState {
  BufferingState state;
  BufferingStateChangeReason reason;
  // Only included in the serialized state if |type == kPipeline|
  bool suspended_start = false;
};

// Used to indicate changes in buffering state;
using BufferingStateCB =
    base::RepeatingCallback<void(BufferingState, BufferingStateChangeReason)>;

std::string BufferingStateToString(
    BufferingState state,
    BufferingStateChangeReason reason = BUFFERING_CHANGE_REASON_UNKNOWN);

}  // namespace media

#endif  // MEDIA_BASE_BUFFERING_STATE_H_