OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/media/webmediaplayer_util.h" | 5 #include "webkit/media/webmediaplayer_util.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 namespace webkit_media { | 9 namespace webkit_media { |
10 | 10 |
11 base::TimeDelta ConvertSecondsToTimestamp(double seconds) { | 11 base::TimeDelta ConvertSecondsToTimestamp(double seconds) { |
12 double microseconds = seconds * base::Time::kMicrosecondsPerSecond; | 12 double microseconds = seconds * base::Time::kMicrosecondsPerSecond; |
13 return base::TimeDelta::FromMicroseconds( | 13 return base::TimeDelta::FromMicroseconds( |
14 microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5)); | 14 microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5)); |
15 } | 15 } |
16 | 16 |
17 WebKit::WebTimeRanges ConvertToWebTimeRanges( | 17 WebKit::WebTimeRanges ConvertToWebTimeRanges( |
18 const media::Ranges<base::TimeDelta>& ranges) { | 18 const media::Ranges<base::TimeDelta>& ranges) { |
19 WebKit::WebTimeRanges result(ranges.size()); | 19 WebKit::WebTimeRanges result(ranges.size()); |
20 for (size_t i = 0; i < ranges.size(); i++) { | 20 for (size_t i = 0; i < ranges.size(); i++) { |
21 result[i].start = ranges.start(i).InSecondsF(); | 21 result[i].start = ranges.start(i).InSecondsF(); |
22 result[i].end = ranges.end(i).InSecondsF(); | 22 result[i].end = ranges.end(i).InSecondsF(); |
23 } | 23 } |
24 return result; | 24 return result; |
25 } | 25 } |
26 | 26 |
| 27 WebKit::WebMediaPlayer::NetworkState PipelineErrorToNetworkState( |
| 28 media::PipelineStatus error) { |
| 29 DCHECK_NE(error, media::PIPELINE_OK); |
| 30 |
| 31 switch (error) { |
| 32 case media::PIPELINE_ERROR_NETWORK: |
| 33 case media::PIPELINE_ERROR_READ: |
| 34 return WebKit::WebMediaPlayer::NetworkStateNetworkError; |
| 35 |
| 36 // TODO(vrk): Because OnPipelineInitialize() directly reports the |
| 37 // NetworkStateFormatError instead of calling OnPipelineError(), I believe |
| 38 // this block can be deleted. Should look into it! (crbug.com/126070) |
| 39 case media::PIPELINE_ERROR_INITIALIZATION_FAILED: |
| 40 case media::PIPELINE_ERROR_COULD_NOT_RENDER: |
| 41 case media::PIPELINE_ERROR_URL_NOT_FOUND: |
| 42 case media::DEMUXER_ERROR_COULD_NOT_OPEN: |
| 43 case media::DEMUXER_ERROR_COULD_NOT_PARSE: |
| 44 case media::DEMUXER_ERROR_NO_SUPPORTED_STREAMS: |
| 45 case media::DECODER_ERROR_NOT_SUPPORTED: |
| 46 return WebKit::WebMediaPlayer::NetworkStateFormatError; |
| 47 |
| 48 case media::PIPELINE_ERROR_DECODE: |
| 49 case media::PIPELINE_ERROR_ABORT: |
| 50 case media::PIPELINE_ERROR_OPERATION_PENDING: |
| 51 case media::PIPELINE_ERROR_INVALID_STATE: |
| 52 return WebKit::WebMediaPlayer::NetworkStateDecodeError; |
| 53 |
| 54 case media::PIPELINE_ERROR_DECRYPT: |
| 55 // TODO(xhwang): Change to use NetworkStateDecryptError once it's added in |
| 56 // Webkit (see http://crbug.com/124486). |
| 57 return WebKit::WebMediaPlayer::NetworkStateDecodeError; |
| 58 |
| 59 case media::PIPELINE_OK: |
| 60 case media::PIPELINE_STATUS_MAX: |
| 61 NOTREACHED() << "Unexpected status! " << error; |
| 62 } |
| 63 return WebKit::WebMediaPlayer::NetworkStateFormatError; |
| 64 } |
| 65 |
27 } // namespace webkit_media | 66 } // namespace webkit_media |
OLD | NEW |