OLD | NEW |
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 "content/renderer/media/webmediaplayer_util.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "media/base/media_keys.h" | 9 #include "media/base/media_keys.h" |
10 #include "third_party/WebKit/public/web/WebMediaPlayerClient.h" | 10 #include "third_party/WebKit/public/web/WebMediaPlayerClient.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 // Compile asserts shared by all platforms. | 14 // Compile asserts shared by all platforms. |
15 | 15 |
16 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 16 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
17 COMPILE_ASSERT( \ | 17 COMPILE_ASSERT( \ |
18 static_cast<int>(WebKit::WebMediaPlayerClient::MediaKeyErrorCode ## name) == \ | 18 static_cast<int>(blink::WebMediaPlayerClient::MediaKeyErrorCode ## name) == \ |
19 static_cast<int>(media::MediaKeys::k ## name ## Error), \ | 19 static_cast<int>(media::MediaKeys::k ## name ## Error), \ |
20 mismatching_enums) | 20 mismatching_enums) |
21 COMPILE_ASSERT_MATCHING_ENUM(Unknown); | 21 COMPILE_ASSERT_MATCHING_ENUM(Unknown); |
22 COMPILE_ASSERT_MATCHING_ENUM(Client); | 22 COMPILE_ASSERT_MATCHING_ENUM(Client); |
23 #undef COMPILE_ASSERT_MATCHING_ENUM | 23 #undef COMPILE_ASSERT_MATCHING_ENUM |
24 | 24 |
25 base::TimeDelta ConvertSecondsToTimestamp(double seconds) { | 25 base::TimeDelta ConvertSecondsToTimestamp(double seconds) { |
26 double microseconds = seconds * base::Time::kMicrosecondsPerSecond; | 26 double microseconds = seconds * base::Time::kMicrosecondsPerSecond; |
27 return base::TimeDelta::FromMicroseconds( | 27 return base::TimeDelta::FromMicroseconds( |
28 microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5)); | 28 microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5)); |
29 } | 29 } |
30 | 30 |
31 WebKit::WebTimeRanges ConvertToWebTimeRanges( | 31 blink::WebTimeRanges ConvertToWebTimeRanges( |
32 const media::Ranges<base::TimeDelta>& ranges) { | 32 const media::Ranges<base::TimeDelta>& ranges) { |
33 WebKit::WebTimeRanges result(ranges.size()); | 33 blink::WebTimeRanges result(ranges.size()); |
34 for (size_t i = 0; i < ranges.size(); i++) { | 34 for (size_t i = 0; i < ranges.size(); i++) { |
35 result[i].start = ranges.start(i).InSecondsF(); | 35 result[i].start = ranges.start(i).InSecondsF(); |
36 result[i].end = ranges.end(i).InSecondsF(); | 36 result[i].end = ranges.end(i).InSecondsF(); |
37 } | 37 } |
38 return result; | 38 return result; |
39 } | 39 } |
40 | 40 |
41 WebKit::WebMediaPlayer::NetworkState PipelineErrorToNetworkState( | 41 blink::WebMediaPlayer::NetworkState PipelineErrorToNetworkState( |
42 media::PipelineStatus error) { | 42 media::PipelineStatus error) { |
43 DCHECK_NE(error, media::PIPELINE_OK); | 43 DCHECK_NE(error, media::PIPELINE_OK); |
44 | 44 |
45 switch (error) { | 45 switch (error) { |
46 case media::PIPELINE_ERROR_NETWORK: | 46 case media::PIPELINE_ERROR_NETWORK: |
47 case media::PIPELINE_ERROR_READ: | 47 case media::PIPELINE_ERROR_READ: |
48 return WebKit::WebMediaPlayer::NetworkStateNetworkError; | 48 return blink::WebMediaPlayer::NetworkStateNetworkError; |
49 | 49 |
50 // TODO(vrk): Because OnPipelineInitialize() directly reports the | 50 // TODO(vrk): Because OnPipelineInitialize() directly reports the |
51 // NetworkStateFormatError instead of calling OnPipelineError(), I believe | 51 // NetworkStateFormatError instead of calling OnPipelineError(), I believe |
52 // this block can be deleted. Should look into it! (crbug.com/126070) | 52 // this block can be deleted. Should look into it! (crbug.com/126070) |
53 case media::PIPELINE_ERROR_INITIALIZATION_FAILED: | 53 case media::PIPELINE_ERROR_INITIALIZATION_FAILED: |
54 case media::PIPELINE_ERROR_COULD_NOT_RENDER: | 54 case media::PIPELINE_ERROR_COULD_NOT_RENDER: |
55 case media::PIPELINE_ERROR_URL_NOT_FOUND: | 55 case media::PIPELINE_ERROR_URL_NOT_FOUND: |
56 case media::DEMUXER_ERROR_COULD_NOT_OPEN: | 56 case media::DEMUXER_ERROR_COULD_NOT_OPEN: |
57 case media::DEMUXER_ERROR_COULD_NOT_PARSE: | 57 case media::DEMUXER_ERROR_COULD_NOT_PARSE: |
58 case media::DEMUXER_ERROR_NO_SUPPORTED_STREAMS: | 58 case media::DEMUXER_ERROR_NO_SUPPORTED_STREAMS: |
59 case media::DECODER_ERROR_NOT_SUPPORTED: | 59 case media::DECODER_ERROR_NOT_SUPPORTED: |
60 return WebKit::WebMediaPlayer::NetworkStateFormatError; | 60 return blink::WebMediaPlayer::NetworkStateFormatError; |
61 | 61 |
62 case media::PIPELINE_ERROR_DECODE: | 62 case media::PIPELINE_ERROR_DECODE: |
63 case media::PIPELINE_ERROR_ABORT: | 63 case media::PIPELINE_ERROR_ABORT: |
64 case media::PIPELINE_ERROR_OPERATION_PENDING: | 64 case media::PIPELINE_ERROR_OPERATION_PENDING: |
65 case media::PIPELINE_ERROR_INVALID_STATE: | 65 case media::PIPELINE_ERROR_INVALID_STATE: |
66 return WebKit::WebMediaPlayer::NetworkStateDecodeError; | 66 return blink::WebMediaPlayer::NetworkStateDecodeError; |
67 | 67 |
68 case media::PIPELINE_ERROR_DECRYPT: | 68 case media::PIPELINE_ERROR_DECRYPT: |
69 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in | 69 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in |
70 // Webkit (see http://crbug.com/124486). | 70 // Webkit (see http://crbug.com/124486). |
71 return WebKit::WebMediaPlayer::NetworkStateDecodeError; | 71 return blink::WebMediaPlayer::NetworkStateDecodeError; |
72 | 72 |
73 case media::PIPELINE_OK: | 73 case media::PIPELINE_OK: |
74 case media::PIPELINE_STATUS_MAX: | 74 case media::PIPELINE_STATUS_MAX: |
75 NOTREACHED() << "Unexpected status! " << error; | 75 NOTREACHED() << "Unexpected status! " << error; |
76 } | 76 } |
77 return WebKit::WebMediaPlayer::NetworkStateFormatError; | 77 return blink::WebMediaPlayer::NetworkStateFormatError; |
78 } | 78 } |
79 | 79 |
80 } // namespace content | 80 } // namespace content |
OLD | NEW |