- /************************************************************************
- * chxavplaylist.cpp
- * -----------------
- *
- * Synopsis:
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- ************************************************************************/
- // Standard includes...
- #include <limits.h>
- // Includes from this project...
- #include "chxavrandom.h"
- #include "chxavvector.h"
- #include "chxavtimevalue.h"
- #include "chxavplaylist.h"
- CHXAvPlaylist::CHXAvPlaylist() : m_default("")
- {}
- CHXAvPlaylist::~CHXAvPlaylist()
- {}
- void CHXAvPlaylist::Append(const CHXAvURLRep& url)
- {
- int n = m_urls.Nelements();
- m_urls.Resize(n+1);
- m_urls[n] = url;
- }
- void CHXAvPlaylist::Shuffle()
- {
- if (Length() > 2)
- {
- CHXAvURLRep empty;
- CHXAvVector<CHXAvURLRep> shuffled(Length());
- CHXAvTimeValue now;
- CHXAvTimeValue::now(now);
- RandomSequence r(now.usec());
- unsigned int div = RandomSequence::RandomMax / Length();
- for (int i = 0; i < Length(); ++i)
- {
- int slot = r.Random() / div;
- while (shuffled[slot] != empty)
- slot = (slot + 1) % Length();
- shuffled[slot] = m_urls[i];
- }
- m_urls = shuffled;
- }
- }
- int CHXAvPlaylist::Length() const
- {
- return m_urls.Nelements();
- }
- CHXAvPlaylistItr::CHXAvPlaylistItr(const CHXAvPlaylist& pl)
- : m_list(pl),
- m_current(0),
- m_loop(false),
- m_end(false)
- {}
- CHXAvPlaylistItr::CHXAvPlaylistItr(const CHXAvPlaylist& pl, int current)
- : m_list(pl),
- m_current(current),
- m_loop(false),
- m_end(false)
- {}
- CHXAvPlaylistItr::~CHXAvPlaylistItr()
- {}
- void CHXAvPlaylistItr::Loop(bool on)
- {
- m_loop = on;
- }
- bool CHXAvPlaylistItr::Loop() const
- {
- return m_loop;
- }
- void CHXAvPlaylistItr::Next()
- {
- m_end = false;
- if (m_current < (m_list.Length() - 1))
- ++m_current;
- else if (m_loop)
- m_current = 0;
- else
- m_end = true;
- }
- void CHXAvPlaylistItr::Prev()
- {
- m_end = false;
- if (m_current > 0)
- --m_current;
- else if (m_loop)
- m_current = m_list.Length() - 1;
- else
- m_end = true;
- }
- const CHXAvURLRep& CHXAvPlaylistItr::Current() const
- {
- if (m_current >= 0 && m_current < m_list.Length())
- return m_list.m_urls[m_current];
- return m_list.m_default;
- }
- bool CHXAvPlaylistItr::More() const
- {
- return (!m_end);
- }
- void CHXAvPlaylistItr::ResetBegin()
- {
- m_end = false;
- m_current = 0;
- }
- void CHXAvPlaylistItr::ResetEnd()
- {
- m_end = false;
- m_current = m_list.Length() - 1;
- }
- int CHXAvPlaylistItr::Offset() const
- {
- return m_current;
- }
- bool CHXAvPlaylistItr::operator==(const CHXAvPlaylistItr& pl) const
- {
- return (m_current == pl.m_current);
- }
- bool CHXAvPlaylistItr::operator!=(const CHXAvPlaylistItr& pl) const
- {
- return !(*this == pl);
- }
- bool CHXAvPlaylistItr::operator<=(const CHXAvPlaylistItr& pl) const
- {
- return (m_current <= pl.m_current);
- }
- bool CHXAvPlaylistItr::operator>=(const CHXAvPlaylistItr& pl) const
- {
- return (m_current >= pl.m_current);
- }