From 9745c4413bfd563177afa901a7bce7ebcfa4f5c8 Mon Sep 17 00:00:00 2001 From: Steve Workman Date: Mon, 17 Sep 2012 16:45:38 -0400 Subject: [PATCH] Bug 734546: Add MPD classes to store MPD data; r=cpearce --- netwerk/Makefile.in | 4 + netwerk/build/Makefile.in | 5 ++ netwerk/dash/Makefile.in | 24 ++++++ netwerk/dash/mpd/AdaptationSet.cpp | 122 ++++++++++++++++++++++++++++ netwerk/dash/mpd/AdaptationSet.h | 106 ++++++++++++++++++++++++ netwerk/dash/mpd/MPD.cpp | 91 +++++++++++++++++++++ netwerk/dash/mpd/MPD.h | 90 ++++++++++++++++++++ netwerk/dash/mpd/Makefile.in | 49 +++++++++++ netwerk/dash/mpd/Period.cpp | 98 ++++++++++++++++++++++ netwerk/dash/mpd/Period.h | 96 ++++++++++++++++++++++ netwerk/dash/mpd/Representation.cpp | 120 +++++++++++++++++++++++++++ netwerk/dash/mpd/Representation.h | 108 ++++++++++++++++++++++++ netwerk/dash/mpd/SegmentBase.cpp | 106 ++++++++++++++++++++++++ netwerk/dash/mpd/SegmentBase.h | 100 +++++++++++++++++++++++ 14 files changed, 1119 insertions(+) create mode 100644 netwerk/dash/Makefile.in create mode 100644 netwerk/dash/mpd/AdaptationSet.cpp create mode 100644 netwerk/dash/mpd/AdaptationSet.h create mode 100644 netwerk/dash/mpd/MPD.cpp create mode 100644 netwerk/dash/mpd/MPD.h create mode 100644 netwerk/dash/mpd/Makefile.in create mode 100644 netwerk/dash/mpd/Period.cpp create mode 100644 netwerk/dash/mpd/Period.h create mode 100644 netwerk/dash/mpd/Representation.cpp create mode 100644 netwerk/dash/mpd/Representation.h create mode 100644 netwerk/dash/mpd/SegmentBase.cpp create mode 100644 netwerk/dash/mpd/SegmentBase.h diff --git a/netwerk/Makefile.in b/netwerk/Makefile.in index 3ade3b676861..5beb5bf18fd0 100644 --- a/netwerk/Makefile.in +++ b/netwerk/Makefile.in @@ -31,6 +31,10 @@ endif PARALLEL_DIRS += locales +ifdef MOZ_DASH +PARALLEL_DIRS += dash +endif + DIRS = build ifdef ENABLE_TESTS diff --git a/netwerk/build/Makefile.in b/netwerk/build/Makefile.in index 20fcc68ec7d0..6bab9710e7a5 100644 --- a/netwerk/build/Makefile.in +++ b/netwerk/build/Makefile.in @@ -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 \ diff --git a/netwerk/dash/Makefile.in b/netwerk/dash/Makefile.in new file mode 100644 index 000000000000..3098a1496d88 --- /dev/null +++ b/netwerk/dash/Makefile.in @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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 diff --git a/netwerk/dash/mpd/AdaptationSet.h b/netwerk/dash/mpd/AdaptationSet.h new file mode 100644 index 000000000000..11cce3ba5b87 --- /dev/null +++ b/netwerk/dash/mpd/AdaptationSet.h @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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 > 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_ */ diff --git a/netwerk/dash/mpd/MPD.cpp b/netwerk/dash/mpd/MPD.cpp new file mode 100644 index 000000000000..6b48033e5b42 --- /dev/null +++ b/netwerk/dash/mpd/MPD.cpp @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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 diff --git a/netwerk/dash/mpd/MPD.h b/netwerk/dash/mpd/MPD.h new file mode 100644 index 000000000000..f82c075e384b --- /dev/null +++ b/netwerk/dash/mpd/MPD.h @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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 > mPeriods; + + // List of |BaseURL|s which can be used to access the media. + nsTArray mBaseUrls; +}; + +}//namespace net +}//namespace mozilla + +#endif /* MPD_H_ */ diff --git a/netwerk/dash/mpd/Makefile.in b/netwerk/dash/mpd/Makefile.in new file mode 100644 index 000000000000..da46ab4a0476 --- /dev/null +++ b/netwerk/dash/mpd/Makefile.in @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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 diff --git a/netwerk/dash/mpd/Period.h b/netwerk/dash/mpd/Period.h new file mode 100644 index 000000000000..5f51f417533b --- /dev/null +++ b/netwerk/dash/mpd/Period.h @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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 > 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_ */ diff --git a/netwerk/dash/mpd/Representation.cpp b/netwerk/dash/mpd/Representation.cpp new file mode 100644 index 000000000000..279e13fd3f5f --- /dev/null +++ b/netwerk/dash/mpd/Representation.cpp @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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 diff --git a/netwerk/dash/mpd/Representation.h b/netwerk/dash/mpd/Representation.h new file mode 100644 index 000000000000..7de1b1a60453 --- /dev/null +++ b/netwerk/dash/mpd/Representation.h @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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 mBaseUrls; + + // The base |Segment| for the |Representation|. + nsAutoPtr mSegmentBase; +}; + +}//namespace net +}//namespace mozilla + + +#endif /* REPRESENTATION_H_ */ diff --git a/netwerk/dash/mpd/SegmentBase.cpp b/netwerk/dash/mpd/SegmentBase.cpp new file mode 100644 index 000000000000..4793a55300de --- /dev/null +++ b/netwerk/dash/mpd/SegmentBase.cpp @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + + * + * 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 diff --git a/netwerk/dash/mpd/SegmentBase.h b/netwerk/dash/mpd/SegmentBase.h new file mode 100644 index 000000000000..7d7ceb12c85b --- /dev/null +++ b/netwerk/dash/mpd/SegmentBase.h @@ -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 + * Christian Timmerer + * Contributors: + * Steve Workman + * + * 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_ */