summaryrefslogtreecommitdiffstats
path: root/dom/media/hls
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
commitda4c7e7ed675c3bf405668739c3012d140856109 (patch)
treecdd868dba063fecba609a1d819de271f0d51b23e /dom/media/hls
parentAdding upstream version 125.0.3. (diff)
downloadfirefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz
firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/hls')
-rw-r--r--dom/media/hls/HLSDecoder.cpp46
-rw-r--r--dom/media/hls/HLSDecoder.h10
-rw-r--r--dom/media/hls/metrics.yaml70
3 files changed, 112 insertions, 14 deletions
diff --git a/dom/media/hls/HLSDecoder.cpp b/dom/media/hls/HLSDecoder.cpp
index 99bf4c0ff6..dbf2339bef 100644
--- a/dom/media/hls/HLSDecoder.cpp
+++ b/dom/media/hls/HLSDecoder.cpp
@@ -18,9 +18,11 @@
#include "mozilla/java/GeckoHLSResourceWrapperNatives.h"
#include "nsContentUtils.h"
#include "nsIChannel.h"
+#include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsThreadUtils.h"
#include "mozilla/dom/HTMLMediaElement.h"
+#include "mozilla/glean/GleanMetrics.h"
#include "mozilla/NullPrincipal.h"
#include "mozilla/StaticPrefs_media.h"
@@ -169,7 +171,8 @@ nsresult HLSDecoder::Load(nsIChannel* aChannel) {
mChannel = aChannel;
nsCString spec;
Unused << mURI->GetSpec(spec);
- ;
+ mUsageRecorded = false;
+
HLSResourceCallbacksSupport::Init();
mJavaCallbacks = java::GeckoHLSResourceWrapper::Callbacks::New();
mCallbackSupport = new HLSResourceCallbacksSupport(this);
@@ -253,13 +256,36 @@ void HLSDecoder::NotifyDataArrived() {
void HLSDecoder::NotifyLoad(nsCString aMediaUrl) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
- UpdateCurrentPrincipal(aMediaUrl);
+
+ nsCOMPtr<nsIURI> uri;
+ nsresult rv = NS_NewURI(getter_AddRefs(uri), aMediaUrl.Data());
+ NS_ENSURE_SUCCESS_VOID(rv);
+
+ RecordMediaUsage(uri);
+ UpdateCurrentPrincipal(uri);
+}
+
+void HLSDecoder::RecordMediaUsage(nsIURI* aMediaUri) {
+ if (mUsageRecorded) {
+ return;
+ }
+
+ nsresult rv;
+ nsCOMPtr<nsIURL> url = do_QueryInterface(aMediaUri, &rv);
+ NS_ENSURE_SUCCESS_VOID(rv);
+
+ // TODO: get hostname. See bug 1887053.
+ nsAutoCString mediaExt;
+ Unused << url->GetFileExtension(mediaExt);
+ glean::hls::MediaLoadExtra extra = {.mediaExtension = Some(mediaExt.get())};
+ glean::hls::media_load.Record(Some(extra));
+ mUsageRecorded = true;
}
// Should be called when the decoder loads media from a URL to ensure the
// principal of the media element is appropriately set for CORS.
-void HLSDecoder::UpdateCurrentPrincipal(nsCString aMediaUrl) {
- nsCOMPtr<nsIPrincipal> principal = GetContentPrincipal(aMediaUrl);
+void HLSDecoder::UpdateCurrentPrincipal(nsIURI* aMediaUri) {
+ nsCOMPtr<nsIPrincipal> principal = GetContentPrincipal(aMediaUri);
MOZ_DIAGNOSTIC_ASSERT(principal);
// Check the subsumption of old and new principals. Should be either
@@ -280,12 +306,8 @@ void HLSDecoder::UpdateCurrentPrincipal(nsCString aMediaUrl) {
}
already_AddRefed<nsIPrincipal> HLSDecoder::GetContentPrincipal(
- nsCString aMediaUrl) {
- nsCOMPtr<nsIURI> uri;
- nsresult rv = NS_NewURI(getter_AddRefs(uri), aMediaUrl.Data());
- NS_ENSURE_SUCCESS(rv, nullptr);
+ nsIURI* aMediaUri) {
RefPtr<dom::HTMLMediaElement> element = GetOwner()->GetMediaElement();
- NS_ENSURE_SUCCESS(rv, nullptr);
nsSecurityFlags securityFlags =
element->ShouldCheckAllowOrigin()
? nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT
@@ -294,9 +316,9 @@ already_AddRefed<nsIPrincipal> HLSDecoder::GetContentPrincipal(
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
}
nsCOMPtr<nsIChannel> channel;
- rv = NS_NewChannel(getter_AddRefs(channel), uri,
- static_cast<dom::Element*>(element), securityFlags,
- nsIContentPolicy::TYPE_INTERNAL_VIDEO);
+ nsresult rv = NS_NewChannel(
+ getter_AddRefs(channel), aMediaUri, static_cast<dom::Element*>(element),
+ securityFlags, nsIContentPolicy::TYPE_INTERNAL_VIDEO);
NS_ENSURE_SUCCESS(rv, nullptr);
nsCOMPtr<nsIPrincipal> principal;
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
diff --git a/dom/media/hls/HLSDecoder.h b/dom/media/hls/HLSDecoder.h
index 0f65457765..3624a8c3f4 100644
--- a/dom/media/hls/HLSDecoder.h
+++ b/dom/media/hls/HLSDecoder.h
@@ -47,6 +47,8 @@ class HLSDecoder final : public MediaDecoder {
// Called when Exoplayer start to load media. Main thread only.
void NotifyLoad(nsCString aMediaUrl);
+ bool IsHLSDecoder() const override { return true; }
+
private:
friend class HLSResourceCallbacksSupport;
@@ -61,8 +63,9 @@ class HLSDecoder final : public MediaDecoder {
return true;
}
- void UpdateCurrentPrincipal(nsCString aMediaUrl);
- already_AddRefed<nsIPrincipal> GetContentPrincipal(nsCString aMediaUrl);
+ void UpdateCurrentPrincipal(nsIURI* aMediaUri);
+ already_AddRefed<nsIPrincipal> GetContentPrincipal(nsIURI* aMediaUri);
+ void RecordMediaUsage(nsIURI* aMediaUri);
static size_t sAllocatedInstances; // Access only in the main thread.
@@ -72,6 +75,9 @@ class HLSDecoder final : public MediaDecoder {
java::GeckoHLSResourceWrapper::Callbacks::GlobalRef mJavaCallbacks;
RefPtr<HLSResourceCallbacksSupport> mCallbackSupport;
nsCOMPtr<nsIPrincipal> mContentPrincipal;
+ // There can be multiple media files loaded for one HLS content. Use this flag
+ // to ensure we only record once per content.
+ bool mUsageRecorded;
};
} // namespace mozilla
diff --git a/dom/media/hls/metrics.yaml b/dom/media/hls/metrics.yaml
new file mode 100644
index 0000000000..ea27b358ff
--- /dev/null
+++ b/dom/media/hls/metrics.yaml
@@ -0,0 +1,70 @@
+# 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/.
+
+# Adding a new metric? We have docs for that!
+# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html
+
+---
+$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
+$tags:
+ - 'Core :: Audio/Video'
+
+hls:
+ canplay_requested:
+ type: counter
+ description: >
+ Record when a page requests canPlayType for a HLS media type.
+ metadata:
+ tags:
+ - 'Core :: Audio/Video: Playback'
+ bugs:
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=1672751
+ data_reviews:
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=1672751#8
+ data_sensitivity:
+ - technical
+ notification_emails:
+ - media-alerts@mozilla.com
+ expires: 132
+
+ canplay_supported:
+ type: counter
+ description: >
+ Record when a canPlayType request supports HLS.
+ metadata:
+ tags:
+ - 'Core :: Audio/Video: Playback'
+ bugs:
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=1672751
+ data_reviews:
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=1672751#8
+ data_sensitivity:
+ - technical
+ notification_emails:
+ - media-alerts@mozilla.com
+ expires: 132
+
+ media_load:
+ type: event
+ description: >
+ Record the information about the HLS playback on Android using ExoPlayer.
+ The value of this event contains the media format.
+ metadata:
+ tags:
+ - 'Core :: Audio/Video: Playback'
+ bugs:
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=1672751
+ data_reviews:
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=1672751#8
+ data_sensitivity:
+ - technical
+ notification_emails:
+ - media-alerts@mozilla.com
+ extra_keys:
+ media_extension:
+ description: >
+ The extension in the media file name, could be 'ts' (for MPEG-TS), 'mp4',
+ 'aac', 'mp3', ...
+ type: string
+ expires: 132