From f933441648ef6a71dee783d733aac17b9508b452 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Wed, 15 Dec 2010 15:17:42 -0800 Subject: Initial support for a true streaming player for mpeg2 transport streams. Change-Id: I153eec439d260a5524b21270e16d36940ec3161a --- .../foundation/AHierarchicalStateMachine.cpp | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 media/libstagefright/foundation/AHierarchicalStateMachine.cpp (limited to 'media/libstagefright/foundation/AHierarchicalStateMachine.cpp') diff --git a/media/libstagefright/foundation/AHierarchicalStateMachine.cpp b/media/libstagefright/foundation/AHierarchicalStateMachine.cpp new file mode 100644 index 0000000..30286d8 --- /dev/null +++ b/media/libstagefright/foundation/AHierarchicalStateMachine.cpp @@ -0,0 +1,97 @@ +#include + +#include +#include +#include + +namespace android { + +AState::AState(const sp &parentState) + : mParentState(parentState) { +} + +AState::~AState() { +} + +sp AState::parentState() { + return mParentState; +} + +void AState::stateEntered() { +} + +void AState::stateExited() { +} + +//////////////////////////////////////////////////////////////////////////////// + +AHierarchicalStateMachine::AHierarchicalStateMachine() { +} + +AHierarchicalStateMachine::~AHierarchicalStateMachine() { +} + +void AHierarchicalStateMachine::onMessageReceived(const sp &msg) { + sp save = mState; + + sp cur = mState; + while (cur != NULL && !cur->onMessageReceived(msg)) { + // If you claim not to have handled the message you shouldn't + // have called setState... + CHECK(save == mState); + + cur = cur->parentState(); + } + + if (cur != NULL) { + return; + } + + LOGW("Warning message %s unhandled in root state.", + msg->debugString().c_str()); +} + +void AHierarchicalStateMachine::changeState(const sp &state) { + if (state == mState) { + // Quick exit for the easy case. + return; + } + + Vector > A; + sp cur = mState; + for (;;) { + A.push(cur); + if (cur == NULL) { + break; + } + cur = cur->parentState(); + } + + Vector > B; + cur = state; + for (;;) { + B.push(cur); + if (cur == NULL) { + break; + } + cur = cur->parentState(); + } + + // Remove the common tail. + while (A.size() > 0 && B.size() > 0 && A.top() == B.top()) { + A.pop(); + B.pop(); + } + + mState = state; + + for (size_t i = 0; i < A.size(); ++i) { + A.editItemAt(i)->stateExited(); + } + + for (size_t i = B.size(); i-- > 0;) { + B.editItemAt(i)->stateEntered(); + } +} + +} // namespace android -- cgit v1.1