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

Side by Side Diff: media/blink/webmediaplayer_util.cc

Issue 495353003: Move WebMediaPlayerImpl and its dependencies to media/blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exclude media/blink from Android GN builds for now like cc/blink does. Created 6 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/webmediaplayer_util.h" 5 #include "media/blink/webmediaplayer_util.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "media/base/media_keys.h" 10 #include "media/base/media_keys.h"
11 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" 11 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
12 12
13 namespace content { 13 namespace media {
14 14
15 // Compile asserts shared by all platforms. 15 // Compile asserts shared by all platforms.
16 16
17 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ 17 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
18 COMPILE_ASSERT( \ 18 COMPILE_ASSERT( \
19 static_cast<int>(blink::WebMediaPlayerClient::MediaKeyErrorCode ## name) == \ 19 static_cast<int>(blink::WebMediaPlayerClient::MediaKeyErrorCode ## name) == \
20 static_cast<int>(media::MediaKeys::k ## name ## Error), \ 20 static_cast<int>(MediaKeys::k ## name ## Error), \
21 mismatching_enums) 21 mismatching_enums)
22 COMPILE_ASSERT_MATCHING_ENUM(Unknown); 22 COMPILE_ASSERT_MATCHING_ENUM(Unknown);
23 COMPILE_ASSERT_MATCHING_ENUM(Client); 23 COMPILE_ASSERT_MATCHING_ENUM(Client);
24 #undef COMPILE_ASSERT_MATCHING_ENUM 24 #undef COMPILE_ASSERT_MATCHING_ENUM
25 25
26 base::TimeDelta ConvertSecondsToTimestamp(double seconds) { 26 base::TimeDelta ConvertSecondsToTimestamp(double seconds) {
27 double microseconds = seconds * base::Time::kMicrosecondsPerSecond; 27 double microseconds = seconds * base::Time::kMicrosecondsPerSecond;
28 return base::TimeDelta::FromMicroseconds( 28 return base::TimeDelta::FromMicroseconds(
29 microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5)); 29 microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5));
30 } 30 }
31 31
32 blink::WebTimeRanges ConvertToWebTimeRanges( 32 blink::WebTimeRanges ConvertToWebTimeRanges(
33 const media::Ranges<base::TimeDelta>& ranges) { 33 const Ranges<base::TimeDelta>& ranges) {
34 blink::WebTimeRanges result(ranges.size()); 34 blink::WebTimeRanges result(ranges.size());
35 for (size_t i = 0; i < ranges.size(); ++i) { 35 for (size_t i = 0; i < ranges.size(); ++i) {
36 result[i].start = ranges.start(i).InSecondsF(); 36 result[i].start = ranges.start(i).InSecondsF();
37 result[i].end = ranges.end(i).InSecondsF(); 37 result[i].end = ranges.end(i).InSecondsF();
38 } 38 }
39 return result; 39 return result;
40 } 40 }
41 41
42 blink::WebMediaPlayer::NetworkState PipelineErrorToNetworkState( 42 blink::WebMediaPlayer::NetworkState PipelineErrorToNetworkState(
43 media::PipelineStatus error) { 43 PipelineStatus error) {
44 DCHECK_NE(error, media::PIPELINE_OK); 44 DCHECK_NE(error, PIPELINE_OK);
45 45
46 switch (error) { 46 switch (error) {
47 case media::PIPELINE_ERROR_NETWORK: 47 case PIPELINE_ERROR_NETWORK:
48 case media::PIPELINE_ERROR_READ: 48 case PIPELINE_ERROR_READ:
49 return blink::WebMediaPlayer::NetworkStateNetworkError; 49 return blink::WebMediaPlayer::NetworkStateNetworkError;
50 50
51 // TODO(vrk): Because OnPipelineInitialize() directly reports the 51 // TODO(vrk): Because OnPipelineInitialize() directly reports the
52 // NetworkStateFormatError instead of calling OnPipelineError(), I believe 52 // NetworkStateFormatError instead of calling OnPipelineError(), I believe
53 // this block can be deleted. Should look into it! (crbug.com/126070) 53 // this block can be deleted. Should look into it! (crbug.com/126070)
54 case media::PIPELINE_ERROR_INITIALIZATION_FAILED: 54 case PIPELINE_ERROR_INITIALIZATION_FAILED:
55 case media::PIPELINE_ERROR_COULD_NOT_RENDER: 55 case PIPELINE_ERROR_COULD_NOT_RENDER:
56 case media::PIPELINE_ERROR_URL_NOT_FOUND: 56 case PIPELINE_ERROR_URL_NOT_FOUND:
57 case media::DEMUXER_ERROR_COULD_NOT_OPEN: 57 case DEMUXER_ERROR_COULD_NOT_OPEN:
58 case media::DEMUXER_ERROR_COULD_NOT_PARSE: 58 case DEMUXER_ERROR_COULD_NOT_PARSE:
59 case media::DEMUXER_ERROR_NO_SUPPORTED_STREAMS: 59 case DEMUXER_ERROR_NO_SUPPORTED_STREAMS:
60 case media::DECODER_ERROR_NOT_SUPPORTED: 60 case DECODER_ERROR_NOT_SUPPORTED:
61 return blink::WebMediaPlayer::NetworkStateFormatError; 61 return blink::WebMediaPlayer::NetworkStateFormatError;
62 62
63 case media::PIPELINE_ERROR_DECODE: 63 case PIPELINE_ERROR_DECODE:
64 case media::PIPELINE_ERROR_ABORT: 64 case PIPELINE_ERROR_ABORT:
65 case media::PIPELINE_ERROR_OPERATION_PENDING: 65 case PIPELINE_ERROR_OPERATION_PENDING:
66 case media::PIPELINE_ERROR_INVALID_STATE: 66 case PIPELINE_ERROR_INVALID_STATE:
67 return blink::WebMediaPlayer::NetworkStateDecodeError; 67 return blink::WebMediaPlayer::NetworkStateDecodeError;
68 68
69 case media::PIPELINE_ERROR_DECRYPT: 69 case PIPELINE_ERROR_DECRYPT:
70 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in 70 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in
71 // Webkit (see http://crbug.com/124486). 71 // Webkit (see http://crbug.com/124486).
72 return blink::WebMediaPlayer::NetworkStateDecodeError; 72 return blink::WebMediaPlayer::NetworkStateDecodeError;
73 73
74 case media::PIPELINE_OK: 74 case PIPELINE_OK:
75 NOTREACHED() << "Unexpected status! " << error; 75 NOTREACHED() << "Unexpected status! " << error;
76 } 76 }
77 return blink::WebMediaPlayer::NetworkStateFormatError; 77 return blink::WebMediaPlayer::NetworkStateFormatError;
78 } 78 }
79 79
80 namespace { 80 namespace {
81 81
82 // Helper enum for reporting scheme histograms. 82 // Helper enum for reporting scheme histograms.
83 enum URLSchemeForHistogram { 83 enum URLSchemeForHistogram {
84 kUnknownURLScheme, 84 kUnknownURLScheme,
(...skipping 21 matching lines...) Expand all
106 if (url.SchemeIs("blob")) return kBlobURLScheme; 106 if (url.SchemeIs("blob")) return kBlobURLScheme;
107 if (url.SchemeIs("data")) return kDataURLScheme; 107 if (url.SchemeIs("data")) return kDataURLScheme;
108 if (url.SchemeIs("filesystem")) return kFileSystemScheme; 108 if (url.SchemeIs("filesystem")) return kFileSystemScheme;
109 109
110 return kUnknownURLScheme; 110 return kUnknownURLScheme;
111 } 111 }
112 112
113 } // namespace 113 } // namespace
114 114
115 void ReportMediaSchemeUma(const GURL& url) { 115 void ReportMediaSchemeUma(const GURL& url) {
116 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), kMaxURLScheme); 116 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url),
117 kMaxURLScheme + 1);
scherkus (not reviewing) 2014/09/04 23:00:36 + 1 here intentional?
acolwell GONE FROM CHROMIUM 2014/09/05 00:23:44 Yes. This fixes a bug that was caught by Riley's U
117 } 118 }
118 119
119 } // namespace content 120 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698