OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "webkit/media/webmediasourceclient_impl.h" | 5 #include "webkit/media/webmediasourceclient_impl.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "media/filters/chunk_demuxer.h" | 8 #include "media/filters/chunk_demuxer.h" |
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" |
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 static_cast<WebMediaSourceClient::AddStatus>( | 46 static_cast<WebMediaSourceClient::AddStatus>( |
47 demuxer_->AddId(id, type.utf8().data(), new_codecs)); | 47 demuxer_->AddId(id, type.utf8().data(), new_codecs)); |
48 | 48 |
49 if (result == WebMediaSourceClient::AddStatusOk) | 49 if (result == WebMediaSourceClient::AddStatusOk) |
50 *source_buffer = new WebSourceBufferImpl(id, demuxer_); | 50 *source_buffer = new WebSourceBufferImpl(id, demuxer_); |
51 | 51 |
52 return result; | 52 return result; |
53 } | 53 } |
54 | 54 |
55 double WebMediaSourceClientImpl::duration() { | 55 double WebMediaSourceClientImpl::duration() { |
56 double duration = demuxer_->GetDuration(); | 56 return demuxer_->GetDuration(); |
57 | |
58 // Make sure super small durations don't get truncated to 0 and | |
59 // large durations don't get converted to infinity by the double -> float | |
60 // conversion. | |
61 // | |
62 // TODO(acolwell): Remove when WebKit is changed to report duration as a | |
63 // double. | |
64 if (duration > 0.0 && duration < std::numeric_limits<double>::infinity()) { | |
65 duration = std::max(duration, | |
66 static_cast<double>(std::numeric_limits<float>::min())); | |
67 duration = std::min(duration, | |
68 static_cast<double>(std::numeric_limits<float>::max())); | |
69 } | |
70 | |
71 return static_cast<float>(duration); | |
72 } | 57 } |
73 | 58 |
74 void WebMediaSourceClientImpl::setDuration(double new_duration) { | 59 void WebMediaSourceClientImpl::setDuration(double new_duration) { |
75 DCHECK_GE(new_duration, 0); | 60 DCHECK_GE(new_duration, 0); |
76 demuxer_->SetDuration(new_duration); | 61 demuxer_->SetDuration(new_duration); |
77 } | 62 } |
78 | 63 |
79 void WebMediaSourceClientImpl::endOfStream( | 64 void WebMediaSourceClientImpl::endOfStream( |
80 WebMediaSourceClient::EndOfStreamStatus status) { | 65 WebMediaSourceClient::EndOfStreamStatus status) { |
81 media::PipelineStatus pipeline_status = media::PIPELINE_OK; | 66 media::PipelineStatus pipeline_status = media::PIPELINE_OK; |
82 | 67 |
83 switch (status) { | 68 switch (status) { |
84 case WebMediaSourceClient::EndOfStreamStatusNoError: | 69 case WebMediaSourceClient::EndOfStreamStatusNoError: |
85 break; | 70 break; |
86 case WebMediaSourceClient::EndOfStreamStatusNetworkError: | 71 case WebMediaSourceClient::EndOfStreamStatusNetworkError: |
87 pipeline_status = media::PIPELINE_ERROR_NETWORK; | 72 pipeline_status = media::PIPELINE_ERROR_NETWORK; |
88 break; | 73 break; |
89 case WebMediaSourceClient::EndOfStreamStatusDecodeError: | 74 case WebMediaSourceClient::EndOfStreamStatusDecodeError: |
90 pipeline_status = media::PIPELINE_ERROR_DECODE; | 75 pipeline_status = media::PIPELINE_ERROR_DECODE; |
91 break; | 76 break; |
92 default: | 77 default: |
93 NOTIMPLEMENTED(); | 78 NOTIMPLEMENTED(); |
94 } | 79 } |
95 | 80 |
96 if (!demuxer_->EndOfStream(pipeline_status)) | 81 if (!demuxer_->EndOfStream(pipeline_status)) |
97 DVLOG(1) << "EndOfStream call failed."; | 82 DVLOG(1) << "EndOfStream call failed."; |
98 } | 83 } |
99 | 84 |
100 } // namespace webkit_media | 85 } // namespace webkit_media |
OLD | NEW |