Bug 1350246 - [Part1] Implement a HLSDecoder as a MediaDecoder.
MozReview-Commit-ID: AROu6wdm9RZ
new file mode 100644
--- /dev/null
+++ b/dom/media/hls/HLSDecoder.cpp
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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/. */
+
+#include "HLSDecoder.h"
+#include "AndroidBridge.h"
+#include "DecoderTraits.h"
+#include "HLSDemuxer.h"
+#include "HLSUtils.h"
+#include "MediaContainerType.h"
+#include "MediaDecoderStateMachine.h"
+#include "MediaFormatReader.h"
+#include "MediaPrefs.h"
+
+namespace mozilla {
+
+MediaDecoderStateMachine*
+HLSDecoder::CreateStateMachine()
+{
+ MOZ_ASSERT(NS_IsMainThread());
+
+ mReader =
+ new MediaFormatReader(this,
+ new HLSDemuxer(GetResource()),
+ GetVideoFrameContainer());
+
+ return new MediaDecoderStateMachine(this, mReader);
+}
+
+MediaDecoder*
+HLSDecoder::Clone(MediaDecoderInit& aInit)
+{
+ if (!IsEnabled()) {
+ return nullptr;
+ }
+ return new HLSDecoder(aInit);
+}
+
+bool
+HLSDecoder::IsEnabled()
+{
+ return MediaPrefs::HLSEnabled() && (jni::GetAPIVersion() >= 16);
+}
+
+bool
+HLSDecoder::IsSupportedType(const MediaContainerType& aContainerType)
+{
+ return false;
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/hls/HLSDecoder.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=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/. */
+
+#ifndef HLSDecoder_h_
+#define HLSDecoder_h_
+
+#include "MediaDecoder.h"
+
+namespace mozilla {
+class MediaFormatReader;
+
+class HLSDecoder final : public MediaDecoder
+{
+public:
+ // MediaDecoder interface.
+ explicit HLSDecoder(MediaDecoderInit& aInit) : MediaDecoder(aInit) { }
+
+ MediaDecoder* Clone(MediaDecoderInit& aInit) override;
+
+ MediaDecoderStateMachine* CreateStateMachine() override;
+
+ // Returns true if the HLS backend is pref'ed on.
+ static bool IsEnabled();
+
+ // Returns true if aContainerType is an HLS type that we think we can render
+ // with the a platform decoder backend.
+ // If provided, codecs are checked for support.
+ static bool IsSupportedType(const MediaContainerType& aContainerType);
+
+private:
+ RefPtr<MediaFormatReader> mReader;
+};
+
+} // namespace mozilla
+
+#endif /* HLSDecoder_h_ */