Bug 1350246 - [Part1] Implement a HLSDecoder as a MediaDecoder. draft
authorJames Cheng <jacheng@mozilla.com>
Fri, 05 May 2017 16:40:29 +0800
changeset 592553 1c869788b0c254abea17f49e0f0e3da50a13c3f5
parent 592552 2e3c7c758a3d08ccd58ad4f4359301d4f77af0ba
child 592554 c08f418676e12be06be7736594d8cb5cf6186df3
push id63431
push userbmo:jacheng@mozilla.com
push dateMon, 12 Jun 2017 12:38:14 +0000
bugs1350246
milestone55.0a1
Bug 1350246 - [Part1] Implement a HLSDecoder as a MediaDecoder. MozReview-Commit-ID: AROu6wdm9RZ
dom/media/hls/HLSDecoder.cpp
dom/media/hls/HLSDecoder.h
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_ */