Bug 734546: Add MPD classes to store MPD data; r=cpearce

This commit is contained in:
Steve Workman 2012-09-17 16:45:38 -04:00
parent ac33fb67d7
commit 3d5122d687
14 changed files with 1119 additions and 0 deletions

View File

@ -31,6 +31,10 @@ endif
PARALLEL_DIRS += locales
ifdef MOZ_DASH
PARALLEL_DIRS += dash
endif
DIRS = build
ifdef ENABLE_TESTS

View File

@ -61,6 +61,11 @@ ifeq (android,$(MOZ_WIDGET_TOOLKIT))
../system/android/$(LIB_PREFIX)neckosystem_s.$(LIB_SUFFIX)
endif
ifdef MOZ_DASH
SHARED_LIBRARY_LIBS += \
../dash/mpd/$(LIB_PREFIX)nkdashmpd_s.$(LIB_SUFFIX)
endif
LOCAL_INCLUDES = \
-I$(srcdir)/../base/src \
-I$(srcdir)/../dns \

24
netwerk/dash/Makefile.in Normal file
View File

@ -0,0 +1,24 @@
# -*- Mode: makefile; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- #
# vim: set ts=2 et sw=2 tw=80: #
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Contributor(s):
# Steve Workman <sworkman@mozilla.com
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
PARALLEL_DIRS = \
mpd \
$(NULL)
include $(topsrcdir)/config/rules.mk
DEFINES += -DIMPL_NS_NET

View File

@ -0,0 +1,122 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* AdaptationSet.cpp
*****************************************************************************
* Copyright(C) 2010 - 2012 Klagenfurt University
*
* Created on: Jan 27, 2012
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |AdaptationSet|
*
* Describes a type of media in a |Period| of time in the media presentation,
* e.g. an audio or video stream. Direct child of |Period|, which contains 1+
* available pieces of media, available during that time period.
* |AdaptationSet| itself contains one or more |Representations| which describe
* different versions of the media, most commonly different bitrate encodings.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#include "AdaptationSet.h"
namespace mozilla {
namespace net {
int32_t
AdaptationSet::GetWidth() const
{
return mWidth;
}
void
AdaptationSet::SetWidth(int32_t const aWidth)
{
mWidth = aWidth;
}
int32_t
AdaptationSet::GetHeight() const
{
return mHeight;
}
void
AdaptationSet::SetHeight(int32_t const aHeight)
{
mHeight = aHeight;
}
void
AdaptationSet::GetMIMEType(nsAString& aMIMEType) const
{
aMIMEType = mMIMEType;
}
void
AdaptationSet::SetMIMEType(nsAString const &aMIMEType)
{
NS_ENSURE_FALSE(aMIMEType.IsEmpty(),);
mMIMEType = aMIMEType;
}
Representation const *
AdaptationSet::GetRepresentation(uint32_t aIndex) const
{
NS_ENSURE_TRUE(aIndex < mRepresentations.Length(), nullptr);
return mRepresentations[aIndex];
}
void
AdaptationSet::AddRepresentation(Representation* aRep)
{
NS_ENSURE_TRUE(aRep,);
// Only add if it's not already in the array.
if (!mRepresentations.Contains(aRep)) {
mRepresentations.AppendElement(aRep);
}
}
uint16_t
AdaptationSet::GetNumRepresentations() const
{
return mRepresentations.Length();
}
void
AdaptationSet::EnableBitstreamSwitching(bool aEnable)
{
mIsBitstreamSwitching = aEnable;
}
bool
AdaptationSet::IsBitstreamSwitchingEnabled() const
{
return mIsBitstreamSwitching;
}
}//namespace net
}//namespace mozilla

View File

@ -0,0 +1,106 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* AdaptationSet.h
*****************************************************************************
* Copyright(C) 2010 - 2012 Klagenfurt University
*
* Created on: Jan 27, 2012
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |AdaptationSet|
*
* Describes a type of media in a |Period| of time in the media presentation,
* e.g. an audio or video stream. Direct child of |Period|, which contains 1+
* available pieces of media, available during that time period.
* |AdaptationSet| itself contains one or more |Representations| which describe
* different versions of the media, most commonly different bitrate encodings.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#ifndef ADAPTATIONSET_H_
#define ADAPTATIONSET_H_
#include "nsAutoPtr.h"
#include "nsString.h"
#include "nsTArray.h"
#include "Representation.h"
namespace mozilla {
namespace net {
class AdaptationSet
{
public:
AdaptationSet() :
mWidth(0),
mHeight(0),
mIsBitstreamSwitching(false)
{
MOZ_COUNT_CTOR(AdaptationSet);
}
virtual ~AdaptationSet() {
MOZ_COUNT_DTOR(AdaptationSet);
}
// Setters and getters for @width, @height and @mimetype.
int32_t GetWidth() const;
void SetWidth(int32_t const aWidth);
int32_t GetHeight() const;
void SetHeight(int32_t const aHeight);
void GetMIMEType(nsAString& aMIMEType) const;
void SetMIMEType(nsAString const &aMIMEType);
// Gets a list of media |Representation| objects for this |AdaptationSet|.
Representation const * GetRepresentation(uint32_t) const;
// Adds a media |Representation| to this |AdaptationSet|. Takes ownership to
// manage deletion.
void AddRepresentation(Representation* aRep);
// Returns the number of media |Representations|.
uint16_t GetNumRepresentations() const;
// En/Dis-ables switching between media |Representation|s.
void EnableBitstreamSwitching(bool const aEnable);
bool IsBitstreamSwitchingEnabled() const;
private:
// Array of media |Representations| to switch between.
nsTArray<nsAutoPtr<Representation> > mRepresentations;
// @width, height and @mimetype of this media stream.
int32_t mWidth;
int32_t mHeight;
nsString mMIMEType;
// If true, switching between media |Representation|s is allowed.
bool mIsBitstreamSwitching;
};
}
}
#endif /* ADAPTATIONSET_H_ */

91
netwerk/dash/mpd/MPD.cpp Normal file
View File

@ -0,0 +1,91 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* MPD.cpp
*****************************************************************************
* Copyright(C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |MPD| - Media Presentation Description
*
* Describes the media presentation. Top of the hierarchy in an MPD file.
* Contains one or a series of contiguous |Period|s, which contain 1+ available
* pieces of media, available during that time period, e.g. audio in various
* languages, a video component.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#include "nsTArray.h"
#include "MPD.h"
namespace mozilla {
namespace net {
void
MPD::AddPeriod(Period* aPeriod)
{
NS_ENSURE_TRUE(aPeriod,);
// Only add |Period| if it's not in the array already.
if (!mPeriods.Contains(aPeriod)) {
mPeriods.AppendElement(aPeriod);
}
}
Period const *
MPD::GetPeriod(uint32_t aIndex) const
{
NS_ENSURE_TRUE(aIndex < mPeriods.Length(), nullptr);
return mPeriods[aIndex];
}
uint32_t const
MPD::GetNumPeriods() const
{
return mPeriods.Length();
}
void
MPD::AddBaseUrl(nsAString const& aUrl)
{
NS_ENSURE_FALSE(aUrl.IsEmpty(),);
// Only add |BaseUrl| string if it's not in the array already.
if (!mBaseUrls.Contains(aUrl)) {
mBaseUrls.AppendElement(aUrl);
}
}
nsAString const&
MPD::GetBaseUrl(uint32_t aIndex) const
{
NS_ENSURE_TRUE(aIndex < mBaseUrls.Length(), NS_LITERAL_STRING(""));
return mBaseUrls[aIndex];
}
}//namespace net
}//namespace mozilla

90
netwerk/dash/mpd/MPD.h Normal file
View File

@ -0,0 +1,90 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* MPD.h
*****************************************************************************
* Copyright(C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |MPD| - Media Presentation Description
*
* Describes the media presentation. Top of the hierarchy in an MPD file.
* Contains one or a series of contiguous |Period|s, which contain 1+ available
* pieces of media, available during that time period, e.g. audio in various
* languages, a video component.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#ifndef MPD_H_
#define MPD_H_
#include "nsTArray.h"
#include "nsString.h"
#include "Period.h"
namespace mozilla {
namespace net {
class MPD
{
public:
MPD()
{
MOZ_COUNT_CTOR(MPD);
}
virtual ~MPD() {
MOZ_COUNT_DTOR(MPD);
}
// At least one media content |Period|s per Media Presentation. The |MPD|
// contains 1+ available pieces of media, available during that time period
// e.g. audio in various languages, a video component.
// |MPD| takes ownership of |Period| in |AddPeriod| and will manage deletion.
void AddPeriod(Period* aPeriod);
Period const * GetPeriod(uint32_t aIndex) const;
uint32_t const GetNumPeriods() const;
// Adds/Gets an absolute/relative |BaseURL| for the whole document.
// Note: A relative |BaseURL| for the whole document will use the URL for the
// MPD file itself as base.
void AddBaseUrl(nsAString const& aUrl);
nsAString const& GetBaseUrl(uint32_t aIndex) const;
bool HasBaseUrls() { return !mBaseUrls.IsEmpty(); }
private:
// List of media content |Period|s in this media presentation.
nsTArray<nsAutoPtr<Period> > mPeriods;
// List of |BaseURL|s which can be used to access the media.
nsTArray<nsString> mBaseUrls;
};
}//namespace net
}//namespace mozilla
#endif /* MPD_H_ */

View File

@ -0,0 +1,49 @@
# -*- Mode: makefile; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- #
# vim: set ts=2 et sw=2 tw=80: #
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Contributor(s):
# Steve Workman <sworkman@mozilla.com
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = necko
LIBRARY_NAME = nkdashmpd_s
LIBXUL_LIBRARY = 1
XPIDL_MODULE = necko_dashmpd
GRE_MODULE = 1
FORCE_STATIC_LIB = 1
CPPSRCS = \
MPD.cpp \
Period.cpp \
AdaptationSet.cpp \
Representation.cpp \
SegmentBase.cpp \
$(NULL)
EXPORTS = \
$(NULL)
LOCAL_INCLUDES = \
-I$(srcdir)/../manager/ \
-I$(topsrcdir)/content/base/src \
-I$(topsrcdir)/content/html/content/public \
-I$(topsrcdir)/content/html/content/src \
$(NULL)
include $(topsrcdir)/config/rules.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
DEFINES += -DIMPL_NS_NET

View File

@ -0,0 +1,98 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* Period.cpp
*****************************************************************************
* Copyright(C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |Period|
*
* Describes a period of time in the media presentation. Direct child of |MPD|.
* Alone, or one of a series of contiguous |Period|s, which contain 1+ available
* pieces of media, available during that time period, e.g. audio in various
* languages, a video component.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#include "nsAutoPtr.h"
#include "nsTArray.h"
#include "Period.h"
namespace mozilla {
namespace net {
AdaptationSet const *
Period::GetAdaptationSet(uint32_t aIndex) const
{
NS_ENSURE_TRUE(aIndex < mAdaptationSets.Length(), nullptr);
return mAdaptationSets[aIndex];
}
void
Period::AddAdaptationSet(AdaptationSet* aAdaptationSet)
{
NS_ENSURE_TRUE(aAdaptationSet,);
// Only add |AdaptationSet| ptr if it's not in the array already.
if (!mAdaptationSets.Contains(aAdaptationSet)) {
mAdaptationSets.AppendElement(aAdaptationSet);
}
}
uint16_t const
Period::GetNumAdaptationSets() const
{
return mAdaptationSets.Length();
}
double const
Period::GetStart() const
{
return mStart;
}
double const
Period::GetDuration() const
{
return mDuration;
}
void
Period::SetStart(double const aStart)
{
mStart = aStart;
}
void
Period::SetDuration(double const aDuration)
{
mDuration = aDuration;
}
}//namespace net
}//namespace mozilla

96
netwerk/dash/mpd/Period.h Normal file
View File

@ -0,0 +1,96 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* Period.h
*****************************************************************************
* Copyrigh(C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
#ifndef PERIOD_H_
#define PERIOD_H_
#include "nsTArray.h"
#include "AdaptationSet.h"
#include "Representation.h"
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |Period|
*
* Describes a period of time in the media presentation. Direct child of |MPD|.
* Alone, or one of a series of contiguous |Period|s, which contain 1+ available
* pieces of media, available during that time period, e.g. audio in various
* languages, a video component.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#include "nsAutoPtr.h"
namespace mozilla {
namespace net {
class Period
{
public:
Period()
{
MOZ_COUNT_CTOR(Period);
}
virtual ~Period() {
MOZ_COUNT_DTOR(Period);
}
// Gets/Adds |AdaptationSet|s of media for this media content |Period|.
AdaptationSet const * GetAdaptationSet(uint32_t aIndex) const;
// |Period| takes ownership of |AdaptationSet| here and will manage deletion.
void AddAdaptationSet(AdaptationSet* aAdaptationSet);
// Returns the num. of |AdaptationSet|s in this media content |Period|.
uint16_t const GetNumAdaptationSets() const;
// Gets/Sets the start time of this media content |Period| in seconds.
double const GetStart() const;
void SetStart(double const aStart);
// Gets/Sets the duration of this media content |Period| in seconds.
double const GetDuration() const;
void SetDuration(double const aDuration);
private:
// List of |AdaptationSet|s of media in this |Period|.
nsTArray<nsAutoPtr<AdaptationSet> > mAdaptationSets;
// Start time in seconds for this |Period|.
double mStart;
// Duration in seconds for this |Period|.
double mDuration;
};
}//namespace net
}//namespace mozilla
#endif /* PERIOD_H_ */

View File

@ -0,0 +1,120 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* Representation.cpp
*****************************************************************************
* Copyrigh(C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |Representation|
*
* Describes a particular version of a piece of media described in an
* |AdaptationSet|, a common example being a particular bitrate encoding for an
* audio or video stream. Direct child of |AdaptationSet|, which contains 1+
* available |Representation|s of the media.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#include "nsTArray.h"
#include "Representation.h"
namespace mozilla {
namespace net {
int64_t const
Representation::GetBitrate() const
{
return mBitrate;
}
void
Representation::SetBitrate(int64_t aBitrate)
{
mBitrate = aBitrate;
}
void
Representation::SetWidth(int32_t const aWidth)
{
mWidth = aWidth;
}
int32_t const
Representation::GetWidth() const
{
return mWidth;
}
void
Representation::SetHeight(int32_t aHeight)
{
mHeight = aHeight;
}
int32_t const
Representation::GetHeight() const
{
return mHeight;
}
void
Representation::AddBaseUrl(nsAString const& aUrl)
{
NS_ENSURE_FALSE(aUrl.IsEmpty(),);
// Only add if it's not already in the array.
if (!mBaseUrls.Contains(aUrl)) {
mBaseUrls.AppendElement(aUrl);
}
}
nsAString const &
Representation::GetBaseUrl(uint32_t aIndex) const
{
NS_ENSURE_TRUE(aIndex < mBaseUrls.Length(), NS_LITERAL_STRING(""));
return mBaseUrls[aIndex];
}
SegmentBase const*
Representation::GetSegmentBase() const
{
return mSegmentBase;
}
void
Representation::SetSegmentBase(SegmentBase* aBase)
{
NS_ENSURE_TRUE(aBase,);
// Don't reassign if the ptrs or contents are equal.
if (mSegmentBase != aBase
|| (mSegmentBase && (*mSegmentBase != *aBase))) {
mSegmentBase = aBase;
}
}
}//namespace net
}//namespace mozilla

View File

@ -0,0 +1,108 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* Representation.h
*****************************************************************************
* Copyrigh(C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |Representation|
*
* Describes a particular version of a piece of media described in an
* |AdaptationSet|, a common example being a particular bitrate encoding for an
* audio or video stream. Direct child of |AdaptationSet|, which contains 1+
* available |Representation|s of the media.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#ifndef REPRESENTATION_H_
#define REPRESENTATION_H_
#include "nsAutoPtr.h"
#include "nsString.h"
#include "nsTArray.h"
#include "SegmentBase.h"
namespace mozilla {
namespace net {
class Representation
{
public:
Representation() :
mBitrate(0),
mWidth(0),
mHeight(0),
mSegmentBase(nullptr)
{
MOZ_COUNT_CTOR(Representation);
}
virtual ~Representation() {
MOZ_COUNT_DTOR(Representation);
}
// Gets/Sets @bitrate in kbps.
int64_t const GetBitrate() const;
void SetBitrate(int64_t const aBitrate);
// Gets/Sets @width and @height for the media if it's video.
void SetWidth(int32_t const aWidth);
int32_t const GetWidth() const;
void SetHeight(int32_t const aHeight);
int32_t const GetHeight() const;
// Gets/Adds a |BaseURL| for the media files.
void AddBaseUrl(nsAString const& aUrl);
nsAString const& GetBaseUrl(uint32_t aIndex) const;
bool HasBaseUrls() const { return !mBaseUrls.IsEmpty(); }
// Gets/Sets a base |Segment| for the |Representation|.
SegmentBase const* GetSegmentBase() const;
// Takes ownership of |SegmentBase| to manage deletion.
void SetSegmentBase(SegmentBase* aBase);
private:
// Bitrate of the media in kbps.
int64_t mBitrate;
// Width and height of the media if video.
int32_t mWidth;
int32_t mHeight;
// List of absolute/relative |BaseURL|s which may be used to access the media.
nsTArray<nsString> mBaseUrls;
// The base |Segment| for the |Representation|.
nsAutoPtr<SegmentBase> mSegmentBase;
};
}//namespace net
}//namespace mozilla
#endif /* REPRESENTATION_H_ */

View File

@ -0,0 +1,106 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* SegmentBase.cpp
*****************************************************************************
* Copyrigh(C) 2010 - 2012 Klagenfurt University
*
* Created on: Jan 27, 2012
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |SegmentBase|
*
* Describes common initialization information for |Segment|s in a
* |Representation|.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#include "nsString.h"
#include "SegmentBase.h"
namespace mozilla {
namespace net {
void
SegmentBase::GetIndexRange(int64_t* aStartBytes, int64_t* aEndBytes) const
{
NS_ENSURE_TRUE(aStartBytes, );
NS_ENSURE_TRUE(aEndBytes, );
*aStartBytes = mIndexRangeStart;
*aEndBytes = mIndexRangeEnd;
}
void
SegmentBase::GetInitRange(int64_t* aStartBytes, int64_t* aEndBytes) const
{
NS_ENSURE_TRUE(aStartBytes, );
NS_ENSURE_TRUE(aEndBytes, );
*aStartBytes = mInitRangeStart;
*aEndBytes = mInitRangeEnd;
}
void
SegmentBase::SetIndexRange(nsAString const &aRangeStr)
{
SetRange(aRangeStr, mIndexRangeStart, mIndexRangeEnd);
}
void
SegmentBase::SetInitRange(nsAString const &aRangeStr)
{
SetRange(aRangeStr, mInitRangeStart, mInitRangeEnd);
}
void
SegmentBase::SetRange(nsAString const &aRangeStr,
int64_t &aStart,
int64_t &aEnd)
{
NS_ENSURE_TRUE(!aRangeStr.IsEmpty(), );
nsAString::const_iterator start, end, dashStart, dashEnd;
aRangeStr.BeginReading(start);
aRangeStr.EndReading(end);
dashStart = start;
dashEnd = end;
if (FindInReadable(NS_LITERAL_STRING("-"), dashStart, dashEnd)) {
nsAutoString temp(Substring(start, dashStart));
nsresult rv;
aStart = temp.ToInteger64(&rv);
NS_ENSURE_SUCCESS(rv, );
temp = Substring(dashEnd, end);
aEnd = temp.ToInteger64(&rv);
NS_ENSURE_SUCCESS(rv, );
}
}
}//namespace net
}//namespace mozilla

View File

@ -0,0 +1,100 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
* SegmentBase.h
*****************************************************************************
* Copyrigh(C) 2010 - 2012 Klagenfurt University
*
* Created on: Jan 27, 2012
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
* Contributors:
* Steve Workman <sworkman@mozilla.com>
*
* This Source Code Form Is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*****************************************************************************/
/* DASH - Dynamic Adaptive Streaming over HTTP
*
* DASH is an adaptive bitrate streaming technology where a multimedia file is
* partitioned into one or more segments and delivered to a client using HTTP.
*
* |SegmentBase|
*
* Describes common initialization information for |Segment|s in a
* |Representation|.
*
* Common class used by all DASH Profiles.
* Populated by implementation of MPD Parser.
* Used as data source by implementation of MPD Manager.
*
* |MPD|
* --> |Period|s of time.
* --> |AdaptationSet|s for each type or group of media content.
* --> |Representation|s of media, encoded with different bitrates.
* --> |Segment|s of media, identified by URL (+optional byte
* range.
*/
#ifndef SEGMENTBASE_H_
#define SEGMENTBASE_H_
#include "nsString.h"
namespace mozilla {
namespace net {
class SegmentBase
{
public:
SegmentBase() :
mInitRangeStart(0),
mInitRangeEnd(0),
mIndexRangeStart(0),
mIndexRangeEnd(0)
{
MOZ_COUNT_CTOR(SegmentBase);
}
virtual ~SegmentBase()
{
MOZ_COUNT_DTOR(SegmentBase);
}
bool operator==(SegmentBase const & other) const {
return (mInitRangeStart == other.mInitRangeStart
&& mInitRangeEnd == other.mInitRangeEnd
&& mIndexRangeStart == other.mIndexRangeStart
&& mIndexRangeEnd == other.mIndexRangeEnd);
}
bool operator!=(SegmentBase const & other) const {
return !(*this == other);
}
// Get/Set the byte range for the initialization bytes.
void GetInitRange(int64_t* aStartBytes, int64_t* aEndBytes) const;
void SetInitRange(nsAString const &aRangeStr);
// Get/Set the byte range for the index bytes.
void GetIndexRange(int64_t* aStartBytes, int64_t* aEndBytes) const;
void SetIndexRange(nsAString const &aRangeStr);
private:
// Parses the string to get a start and end value.
void SetRange(nsAString const &aRangeStr, int64_t &aStart, int64_t &aEnd);
// Start and end values for the init byte range.
int64_t mInitRangeStart;
int64_t mInitRangeEnd;
// Start and end values for the index byte range.
int64_t mIndexRangeStart;
int64_t mIndexRangeEnd;
};
}//namespace net
}//namespace mozilla
#endif /* SEGMENTBASE_H_ */