Commit fe40560f authored by xhwang's avatar xhwang Committed by Commit bot

CdmAdapter: Report size of the file read by CDM via FileIO.

We report when:
1, The first time a file is fully read.
2, After the CDM throws an error with a special system code.

BUG=413812
TEST=Tested and both new UMA show in about://histograms.

Review URL: https://codereview.chromium.org/568623003

Cr-Commit-Position: refs/heads/master@{#294843}
parent 4f941d6e
......@@ -19,6 +19,12 @@
namespace {
// Constants for UMA reporting of file size (in KB) via HistogramCustomCounts().
// Note that the histogram is log-scaled (rather than linear).
const uint32_t kSizeKBMin = 1;
const uint32_t kSizeKBMax = 512 * 1024; // 512MB
const uint32_t kSizeKBBuckets = 100;
#if !defined(NDEBUG)
#define DLOG_TO_CONSOLE(message) LogToConsole(message);
#else
......@@ -267,7 +273,9 @@ CdmAdapter::CdmAdapter(PP_Instance instance, pp::Module* module)
deferred_initialize_audio_decoder_(false),
deferred_audio_decoder_config_id_(0),
deferred_initialize_video_decoder_(false),
deferred_video_decoder_config_id_(0) {
deferred_video_decoder_config_id_(0),
last_read_file_size_kb_(0),
file_size_uma_reported_(false) {
callback_factory_.Initialize(this);
}
......@@ -759,6 +767,17 @@ void CdmAdapter::OnRejectPromise(uint32_t promise_id,
uint32_t system_code,
const char* error_message,
uint32_t error_message_length) {
// UMA to investigate http://crbug.com/410630
// TODO(xhwang): Remove after bug is fixed.
if (system_code == 0x27) {
pp::UMAPrivate uma_interface(this);
uma_interface.HistogramCustomCounts("Media.EME.CdmFileIO.FileSizeKBOnError",
last_read_file_size_kb_,
kSizeKBMin,
kSizeKBMax,
kSizeKBBuckets);
}
RejectPromise(promise_id,
error,
system_code,
......@@ -1082,6 +1101,25 @@ bool CdmAdapter::IsValidVideoFrame(const LinkedVideoFrame& video_frame) {
return true;
}
void CdmAdapter::OnFirstFileRead(int32_t file_size_bytes) {
PP_DCHECK(IsMainThread());
PP_DCHECK(file_size_bytes >= 0);
last_read_file_size_kb_ = file_size_bytes / 1024;
if (file_size_uma_reported_)
return;
pp::UMAPrivate uma_interface(this);
uma_interface.HistogramCustomCounts(
"Media.EME.CdmFileIO.FileSizeKBOnFirstRead",
last_read_file_size_kb_,
kSizeKBMin,
kSizeKBMax,
kSizeKBBuckets);
file_size_uma_reported_ = true;
}
#if !defined(NDEBUG)
void CdmAdapter::LogToConsole(const pp::Var& value) {
PP_DCHECK(IsMainThread());
......@@ -1189,7 +1227,10 @@ void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type,
// The CDM owns the returned object and must call FileIO::Close() to release it.
cdm::FileIO* CdmAdapter::CreateFileIO(cdm::FileIOClient* client) {
return new CdmFileIOImpl(client, pp_instance());
return new CdmFileIOImpl(
client,
pp_instance(),
callback_factory_.NewCallback(&CdmAdapter::OnFirstFileRead));
}
#if defined(OS_CHROMEOS)
......
......@@ -247,6 +247,9 @@ class CdmAdapter : public pp::Instance,
bool IsValidVideoFrame(const LinkedVideoFrame& video_frame);
// Callback to report |file_size_bytes| of the first file read by FileIO.
void OnFirstFileRead(int32_t file_size_bytes);
#if !defined(NDEBUG)
// Logs the given message to the JavaScript console associated with the
// CDM adapter instance. The name of the CDM adapter issuing the log message
......@@ -298,6 +301,9 @@ class CdmAdapter : public pp::Instance,
bool deferred_initialize_video_decoder_;
uint32_t deferred_video_decoder_config_id_;
uint32_t last_read_file_size_kb_;
bool file_size_uma_reported_;
DISALLOW_COPY_AND_ASSIGN(CdmAdapter);
};
......
......@@ -55,12 +55,17 @@ CdmFileIOImpl::ResourceTracker::~ResourceTracker() {
delete CdmFileIOImpl::file_lock_map_;
}
CdmFileIOImpl::CdmFileIOImpl(cdm::FileIOClient* client, PP_Instance pp_instance)
CdmFileIOImpl::CdmFileIOImpl(
cdm::FileIOClient* client,
PP_Instance pp_instance,
const pp::CompletionCallback& first_file_read_cb)
: state_(FILE_UNOPENED),
client_(client),
pp_instance_handle_(pp_instance),
callback_factory_(this),
io_offset_(0) {
io_offset_(0),
first_file_read_reported_(false),
first_file_read_cb_(first_file_read_cb) {
PP_DCHECK(IsMainThread());
PP_DCHECK(pp_instance); // 0 indicates a "NULL handle".
}
......@@ -336,6 +341,14 @@ void CdmFileIOImpl::OnFileRead(int32_t bytes_read) {
state_ = FILE_OPENED;
const uint8_t* data = local_buffer.empty() ?
NULL : reinterpret_cast<const uint8_t*>(&local_buffer[0]);
// Call this before OnReadComplete() so that we always have the latest file
// size before CDM fires errors.
if (!first_file_read_reported_) {
first_file_read_cb_.Run(local_buffer.size());
first_file_read_reported_ = true;
}
client_->OnReadComplete(
cdm::FileIOClient::kSuccess, data, local_buffer.size());
}
......
......@@ -35,7 +35,12 @@ class CdmFileIOImpl : public cdm::FileIO {
DISALLOW_COPY_AND_ASSIGN(ResourceTracker);
};
CdmFileIOImpl(cdm::FileIOClient* client, PP_Instance pp_instance);
// After the first successful file read, call |first_file_read_cb| to report
// the file size. |first_file_read_cb| takes one parameter: the file size in
// bytes.
CdmFileIOImpl(cdm::FileIOClient* client,
PP_Instance pp_instance,
const pp::CompletionCallback& first_file_read_cb);
// cdm::FileIO implementation.
virtual void Open(const char* file_name, uint32_t file_name_size) OVERRIDE;
......@@ -158,6 +163,11 @@ class CdmFileIOImpl : public cdm::FileIO {
// when read completes.
std::vector<char> cumulative_read_buffer_;
bool first_file_read_reported_;
// Callback to report the file size in bytes after the first successful read.
pp::CompletionCallback first_file_read_cb_;
DISALLOW_COPY_AND_ASSIGN(CdmFileIOImpl);
};
......
......@@ -11228,6 +11228,23 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<summary>Duration in milliseconds of HTML5 media (when known).</summary>
</histogram>
<histogram name="Media.EME.CdmFileIO.FileSizeKBOnError" units="KB">
<owner>xhwang@chromium.org</owner>
<summary>
Size in KB of the last file sucessfully read by the CDM through CDM FileIO
before a specific error happens. This is reported only when the error
happens, which should be rare.
</summary>
</histogram>
<histogram name="Media.EME.CdmFileIO.FileSizeKBOnFirstRead" units="KB">
<owner>xhwang@chromium.org</owner>
<summary>
Size in KB of the first file sucessfully read by the CDM through CDM FileIO.
This is recorded once per CDM instance.
</summary>
</histogram>
<histogram name="Media.EME.ClearKey.addKey" enum="MediaKeyException">
<owner>xhwang@chromium.org</owner>
<summary>addKey result using the Clear Key key system.</summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment