OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/html/MediaFragmentURIParser.h" | 27 #include "core/html/MediaFragmentURIParser.h" |
28 | 28 |
29 #include "platform/graphics/media/MediaPlayer.h" | |
30 #include "wtf/text/CString.h" | 29 #include "wtf/text/CString.h" |
31 #include "wtf/text/StringBuilder.h" | 30 #include "wtf/text/StringBuilder.h" |
32 #include "wtf/text/WTFString.h" | 31 #include "wtf/text/WTFString.h" |
33 | 32 |
34 namespace blink { | 33 namespace blink { |
35 | 34 |
36 const int secondsPerHour = 3600; | 35 const int secondsPerHour = 3600; |
37 const int secondsPerMinute = 60; | 36 const int secondsPerMinute = 60; |
38 const unsigned nptIdentiferLength = 4; // "npt:" | 37 const unsigned nptIdentiferLength = 4; // "npt:" |
39 | 38 |
(...skipping 16 matching lines...) Expand all Loading... |
56 // [ "." *DIGIT ] | 55 // [ "." *DIGIT ] |
57 if (input[position] != '.') | 56 if (input[position] != '.') |
58 return String(); | 57 return String(); |
59 | 58 |
60 digits.append(input[position++]); | 59 digits.append(input[position++]); |
61 while (position < length && isASCIIDigit(input[position])) | 60 while (position < length && isASCIIDigit(input[position])) |
62 digits.append(input[position++]); | 61 digits.append(input[position++]); |
63 return digits.toString(); | 62 return digits.toString(); |
64 } | 63 } |
65 | 64 |
66 double MediaFragmentURIParser::invalidTimeValue() | |
67 { | |
68 return MediaPlayer::invalidTime(); | |
69 } | |
70 | |
71 MediaFragmentURIParser::MediaFragmentURIParser(const KURL& url) | 65 MediaFragmentURIParser::MediaFragmentURIParser(const KURL& url) |
72 : m_url(url) | 66 : m_url(url) |
73 , m_timeFormat(None) | 67 , m_timeFormat(None) |
74 , m_startTime(MediaPlayer::invalidTime()) | 68 , m_startTime(std::numeric_limits<double>::quiet_NaN()) |
75 , m_endTime(MediaPlayer::invalidTime()) | 69 , m_endTime(std::numeric_limits<double>::quiet_NaN()) |
76 { | 70 { |
77 } | 71 } |
78 | 72 |
79 double MediaFragmentURIParser::startTime() | 73 double MediaFragmentURIParser::startTime() |
80 { | 74 { |
81 if (!m_url.isValid()) | 75 if (!m_url.isValid()) |
82 return MediaPlayer::invalidTime(); | 76 return std::numeric_limits<double>::quiet_NaN(); |
83 if (m_timeFormat == None) | 77 if (m_timeFormat == None) |
84 parseTimeFragment(); | 78 parseTimeFragment(); |
85 return m_startTime; | 79 return m_startTime; |
86 } | 80 } |
87 | 81 |
88 double MediaFragmentURIParser::endTime() | 82 double MediaFragmentURIParser::endTime() |
89 { | 83 { |
90 if (!m_url.isValid()) | 84 if (!m_url.isValid()) |
91 return MediaPlayer::invalidTime(); | 85 return std::numeric_limits<double>::quiet_NaN(); |
92 if (m_timeFormat == None) | 86 if (m_timeFormat == None) |
93 parseTimeFragment(); | 87 parseTimeFragment(); |
94 return m_endTime; | 88 return m_endTime; |
95 } | 89 } |
96 | 90 |
97 void MediaFragmentURIParser::parseFragments() | 91 void MediaFragmentURIParser::parseFragments() |
98 { | 92 { |
99 if (!m_url.hasFragmentIdentifier()) | 93 if (!m_url.hasFragmentIdentifier()) |
100 return; | 94 return; |
101 String fragmentString = m_url.fragmentIdentifier(); | 95 String fragmentString = m_url.fragmentIdentifier(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // time and an end time | 163 // time and an end time |
170 if (fragment.first != "t") | 164 if (fragment.first != "t") |
171 continue; | 165 continue; |
172 | 166 |
173 // http://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec/#np
t-time | 167 // http://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec/#np
t-time |
174 // Temporal clipping can be specified either as Normal Play Time (npt) R
FC 2326, as SMPTE timecodes, | 168 // Temporal clipping can be specified either as Normal Play Time (npt) R
FC 2326, as SMPTE timecodes, |
175 // SMPTE, or as real-world clock time (clock) RFC 2326. Begin and end ti
mes are always specified | 169 // SMPTE, or as real-world clock time (clock) RFC 2326. Begin and end ti
mes are always specified |
176 // in the same format. The format is specified by name, followed by a co
lon (:), with npt: being | 170 // in the same format. The format is specified by name, followed by a co
lon (:), with npt: being |
177 // the default. | 171 // the default. |
178 | 172 |
179 double start = MediaPlayer::invalidTime(); | 173 double start = std::numeric_limits<double>::quiet_NaN(); |
180 double end = MediaPlayer::invalidTime(); | 174 double end = std::numeric_limits<double>::quiet_NaN(); |
181 if (parseNPTFragment(fragment.second.characters8(), fragment.second.leng
th(), start, end)) { | 175 if (parseNPTFragment(fragment.second.characters8(), fragment.second.leng
th(), start, end)) { |
182 m_startTime = start; | 176 m_startTime = start; |
183 m_endTime = end; | 177 m_endTime = end; |
184 m_timeFormat = NormalPlayTime; | 178 m_timeFormat = NormalPlayTime; |
185 | 179 |
186 // Although we have a valid fragment, don't return yet because when
a fragment dimensions | 180 // Although we have a valid fragment, don't return yet because when
a fragment dimensions |
187 // occurs multiple times, only the last occurrence of that dimension
is used: | 181 // occurs multiple times, only the last occurrence of that dimension
is used: |
188 // http://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec
/#error-uri-general | 182 // http://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec
/#error-uri-general |
189 // Multiple occurrences of the same dimension: only the last valid o
ccurrence of a dimension | 183 // Multiple occurrences of the same dimension: only the last valid o
ccurrence of a dimension |
190 // (e.g., t=10 in #t=2&t=10) is interpreted, all previous occurrence
s (valid or invalid) | 184 // (e.g., t=10 in #t=2&t=10) is interpreted, all previous occurrence
s (valid or invalid) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 304 } |
311 | 305 |
312 if (offset < length && timeString[offset] == '.') | 306 if (offset < length && timeString[offset] == '.') |
313 fraction = collectFraction(timeString, length, offset).toDouble(); | 307 fraction = collectFraction(timeString, length, offset).toDouble(); |
314 | 308 |
315 time = (value1 * secondsPerHour) + (value2 * secondsPerMinute) + value3 + fr
action; | 309 time = (value1 * secondsPerHour) + (value2 * secondsPerMinute) + value3 + fr
action; |
316 return true; | 310 return true; |
317 } | 311 } |
318 | 312 |
319 } | 313 } |
OLD | NEW |