Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1178)

Unified Diff: content/renderer/media/remote_media_stream_impl.cc

Issue 183973021: Add metrics to track the duration of tracks received over a PeerConnection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_common.gypi ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/remote_media_stream_impl.cc
diff --git a/content/renderer/media/remote_media_stream_impl.cc b/content/renderer/media/remote_media_stream_impl.cc
index 66bdb60821d460328d74c65a2bb76744a013e93a..c1560077181076db92a1951e2bb6249a3e495f20 100644
--- a/content/renderer/media/remote_media_stream_impl.cc
+++ b/content/renderer/media/remote_media_stream_impl.cc
@@ -8,8 +8,10 @@
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
+#include "content/common/media/media_stream_track_metrics_host_messages.h"
#include "content/renderer/media/media_stream.h"
#include "content/renderer/media/media_stream_dependency_factory.h"
+#include "content/renderer/render_thread_impl.h"
#include "third_party/WebKit/public/platform/WebString.h"
namespace content {
@@ -34,13 +36,26 @@ class RemoteMediaStreamTrackObserver
// webrtc::ObserverInterface implementation.
virtual void OnChanged() OVERRIDE;
+ // May be overridden by unit tests to avoid sending IPC messages.
+ virtual void SendLifetimeMessage(bool creation);
+
webrtc::MediaStreamTrackInterface::TrackState state_;
scoped_refptr<webrtc::MediaStreamTrackInterface> webrtc_track_;
blink::WebMediaStreamTrack webkit_track_;
+ bool sent_ended_message_;
DISALLOW_COPY_AND_ASSIGN(RemoteMediaStreamTrackObserver);
};
+// We need an ID that is unique for this observer, within the current
+// renderer process, for the lifetime of the observer object. The
+// simplest approach is to just use the object's pointer value. We
+// store it in a uint64 which will be large enough regardless of
+// platform.
+uint64 MakeUniqueId(RemoteMediaStreamTrackObserver* observer) {
+ return reinterpret_cast<uint64>(reinterpret_cast<void*>(observer));
+}
+
} // namespace content
namespace {
@@ -78,11 +93,19 @@ RemoteMediaStreamTrackObserver::RemoteMediaStreamTrackObserver(
const blink::WebMediaStreamTrack& webkit_track)
: state_(webrtc_track->state()),
webrtc_track_(webrtc_track),
- webkit_track_(webkit_track) {
+ webkit_track_(webkit_track),
+ sent_ended_message_(false) {
webrtc_track->RegisterObserver(this);
+
+ SendLifetimeMessage(true);
}
RemoteMediaStreamTrackObserver::~RemoteMediaStreamTrackObserver() {
+ // We send the lifetime-ended message here (it will only get sent if
+ // not previously sent) in case we never received a kEnded state
+ // change.
+ SendLifetimeMessage(false);
+
webrtc_track_->UnregisterObserver(this);
}
@@ -104,6 +127,10 @@ void RemoteMediaStreamTrackObserver::OnChanged() {
blink::WebMediaStreamSource::ReadyStateLive);
break;
case webrtc::MediaStreamTrackInterface::kEnded:
+ // This is a more reliable signal to use for duration, as
+ // destruction of this object might not happen until
+ // considerably later.
+ SendLifetimeMessage(false);
webkit_track_.source().setReadyState(
blink::WebMediaStreamSource::ReadyStateEnded);
break;
@@ -113,6 +140,32 @@ void RemoteMediaStreamTrackObserver::OnChanged() {
}
}
+void RemoteMediaStreamTrackObserver::SendLifetimeMessage(bool creation) {
+ // We need to mirror the lifetime state for tracks to the browser
+ // process so that the duration of tracks can be accurately
+ // reported, because of RenderProcessHost::FastShutdownIfPossible,
+ // which in many cases will simply kill the renderer process.
+ //
+ // RenderThreadImpl::current() may be NULL in unit tests.
+ RenderThreadImpl* render_thread = RenderThreadImpl::current();
+ if (render_thread) {
+ if (creation) {
+ RenderThreadImpl::current()->Send(
+ new MediaStreamTrackMetricsHost_AddTrack(
+ MakeUniqueId(this),
+ webkit_track_.source().type() ==
+ blink::WebMediaStreamSource::TypeAudio,
+ true));
+ } else {
+ if (!sent_ended_message_) {
+ sent_ended_message_ = true;
+ RenderThreadImpl::current()->Send(
+ new MediaStreamTrackMetricsHost_RemoveTrack(MakeUniqueId(this)));
+ }
+ }
+ }
+}
+
RemoteMediaStreamImpl::RemoteMediaStreamImpl(
webrtc::MediaStreamInterface* webrtc_stream)
: webrtc_stream_(webrtc_stream) {
« no previous file with comments | « content/content_common.gypi ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698