Commit 353132b9 authored by scherkus@chromium.org's avatar scherkus@chromium.org

Introduce audio/video BufferingState to Pipeline.

This is a stepping stone towards having audio/video renderers accurately
report their buffering state. For now we use the Preroll() callback to
signal that enough data has been buffered.

Notable changes:
  - The kStarting/kStarted states have been merged into kPlaying
  - DoPlay() is now done implicitly after entering the kPlaying state
  - Transitioning from waiting to non-waiting states (or vice versa)
    now controls the starting and stopping of playback

BUG=144683

Review URL: https://codereview.chromium.org/276973004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269828 0039d316-1c4b-4281-b951-d872f2087c98
parent 987f8091
// Copyright 2014 The Chromium Authors. All rights reserved.
// 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 "base/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,
};
} // namespace media
#endif // MEDIA_BASE_BUFFERING_STATE_H_
This diff is collapsed.
......@@ -13,6 +13,7 @@
#include "base/threading/thread_checker.h"
#include "base/time/default_tick_clock.h"
#include "media/base/audio_renderer.h"
#include "media/base/buffering_state.h"
#include "media/base/demuxer.h"
#include "media/base/media_export.h"
#include "media/base/pipeline_status.h"
......@@ -58,14 +59,13 @@ typedef base::Callback<void(PipelineMetadata)> PipelineMetadataCB;
// [ InitXXX (for each filter) ] [ Stopping ]
// | |
// V V
// [ InitPreroll ] [ Stopped ]
// [ InitPrerolling ] [ Stopped ]
// |
// V
// [ Starting ] <-- [ Seeking ]
// [ Playing ] <-- [ Seeking ]
// | ^
// V |
// [ Started ] ----------'
// Seek()
// `---------------'
// Seek()
//
// Initialization is a series of state transitions from "Created" through each
// filter initialization state. When all filter initialization states have
......@@ -194,8 +194,7 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost {
kInitVideoRenderer,
kInitPrerolling,
kSeeking,
kStarting,
kStarted,
kPlaying,
kStopping,
kStopped,
};
......@@ -305,10 +304,6 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost {
// indepentent from seeking.
void DoSeek(base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb);
// Updates playback rate and volume and initiates an asynchronous play call
// sequence executing |done_cb| with the final status when completed.
void DoPlay(const PipelineStatusCB& done_cb);
// Initiates an asynchronous pause-flush-stop call sequence executing
// |done_cb| when completed.
void DoStop(const PipelineStatusCB& done_cb);
......@@ -316,6 +311,21 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost {
void OnAudioUnderflow();
// Collection of callback methods and helpers for tracking changes in
// buffering state and transition from paused/underflow states and playing
// states.
//
// While in the kPlaying state:
// - A waiting to non-waiting transition indicates preroll has completed
// and StartPlayback() should be called
// - A non-waiting to waiting transition indicates underflow has occurred
// and StartWaitingForEnoughData() should be called
void BufferingStateChanged(BufferingState* buffering_state,
BufferingState new_buffering_state);
bool WaitingForEnoughData() const;
void StartWaitingForEnoughData();
void StartPlayback();
void StartClockIfWaitingForTimeUpdate_Locked();
// Task runner used to execute pipeline tasks.
......@@ -377,6 +387,9 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost {
bool video_ended_;
bool text_ended_;
BufferingState audio_buffering_state_;
BufferingState video_buffering_state_;
// Temporary callback used for Start() and Seek().
PipelineStatusCB seek_cb_;
......
......@@ -860,7 +860,6 @@ class PipelineTeardownTest : public PipelineTest {
kFlushing,
kSeeking,
kPrerolling,
kStarting,
kPlaying,
};
......@@ -885,7 +884,6 @@ class PipelineTeardownTest : public PipelineTest {
case kFlushing:
case kSeeking:
case kPrerolling:
case kStarting:
DoInitialize(state, stop_or_error);
DoSeek(state, stop_or_error);
break;
......@@ -1107,18 +1105,6 @@ class PipelineTeardownTest : public PipelineTest {
EXPECT_CALL(*video_renderer_, SetPlaybackRate(0.0f));
EXPECT_CALL(*audio_renderer_, SetVolume(1.0f));
if (state == kStarting) {
if (stop_or_error == kStop) {
EXPECT_CALL(*audio_renderer_, Play())
.WillOnce(Stop(pipeline_.get(), stop_cb));
} else {
status = PIPELINE_ERROR_READ;
EXPECT_CALL(*audio_renderer_, Play())
.WillOnce(SetError(pipeline_.get(), status));
}
return status;
}
NOTREACHED() << "State not supported: " << state;
return status;
}
......@@ -1168,7 +1154,6 @@ INSTANTIATE_TEARDOWN_TEST(Stop, Pausing);
INSTANTIATE_TEARDOWN_TEST(Stop, Flushing);
INSTANTIATE_TEARDOWN_TEST(Stop, Seeking);
INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling);
INSTANTIATE_TEARDOWN_TEST(Stop, Starting);
INSTANTIATE_TEARDOWN_TEST(Stop, Playing);
INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer);
......@@ -1178,7 +1163,6 @@ INSTANTIATE_TEARDOWN_TEST(Error, Pausing);
INSTANTIATE_TEARDOWN_TEST(Error, Flushing);
INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
INSTANTIATE_TEARDOWN_TEST(Error, Prerolling);
INSTANTIATE_TEARDOWN_TEST(Error, Starting);
INSTANTIATE_TEARDOWN_TEST(Error, Playing);
INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing);
......
......@@ -248,6 +248,7 @@
'base/bit_reader_core.cc',
'base/bit_reader_core.h',
'base/bitstream_buffer.h',
'base/buffering_state.h',
'base/buffers.h',
'base/byte_queue.cc',
'base/byte_queue.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment