| 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 "media/blink/websourcebuffer_impl.h" | 5 #include "media/blink/websourcebuffer_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "media/base/media_tracks.h" | 16 #include "media/base/media_tracks.h" |
| 17 #include "media/base/timestamp_constants.h" | 17 #include "media/base/timestamp_constants.h" |
| 18 #include "media/filters/chunk_demuxer.h" | 18 #include "media/filters/chunk_demuxer.h" |
| 19 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 19 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
| 20 #include "third_party/WebKit/public/platform/WebSourceBufferClient.h" | 20 #include "third_party/WebKit/public/platform/WebSourceBufferClient.h" |
| 21 | 21 |
| 22 namespace media { | 22 namespace media { |
| 23 | 23 |
| 24 static base::TimeDelta DoubleToTimeDelta(double time) { | 24 static base::TimeDelta DoubleToTimeDelta(double time) { |
| 25 DCHECK(!std::isnan(time)); | 25 DCHECK(!std::isnan(time)); |
| 26 DCHECK_NE(time, -std::numeric_limits<double>::infinity()); | 26 DCHECK_NE(time, -std::numeric_limits<double>::infinity()); |
| 27 | 27 |
| 28 if (time == std::numeric_limits<double>::infinity()) | 28 if (time == std::numeric_limits<double>::infinity()) |
| 29 return kInfiniteDuration(); | 29 return kInfiniteDuration; |
| 30 | 30 |
| 31 // Don't use base::TimeDelta::Max() here, as we want the largest finite time | 31 // Don't use base::TimeDelta::Max() here, as we want the largest finite time |
| 32 // delta. | 32 // delta. |
| 33 base::TimeDelta max_time = base::TimeDelta::FromInternalValue( | 33 base::TimeDelta max_time = base::TimeDelta::FromInternalValue( |
| 34 std::numeric_limits<int64_t>::max() - 1); | 34 std::numeric_limits<int64_t>::max() - 1); |
| 35 double max_time_in_seconds = max_time.InSecondsF(); | 35 double max_time_in_seconds = max_time.InSecondsF(); |
| 36 | 36 |
| 37 if (time >= max_time_in_seconds) | 37 if (time >= max_time_in_seconds) |
| 38 return max_time; | 38 return max_time; |
| 39 | 39 |
| 40 return base::TimeDelta::FromMicroseconds( | 40 return base::TimeDelta::FromMicroseconds( |
| 41 time * base::Time::kMicrosecondsPerSecond); | 41 time * base::Time::kMicrosecondsPerSecond); |
| 42 } | 42 } |
| 43 | 43 |
| 44 WebSourceBufferImpl::WebSourceBufferImpl( | 44 WebSourceBufferImpl::WebSourceBufferImpl(const std::string& id, |
| 45 const std::string& id, ChunkDemuxer* demuxer) | 45 ChunkDemuxer* demuxer) |
| 46 : id_(id), | 46 : id_(id), |
| 47 demuxer_(demuxer), | 47 demuxer_(demuxer), |
| 48 client_(NULL), | 48 client_(NULL), |
| 49 append_window_end_(kInfiniteDuration()) { | 49 append_window_end_(kInfiniteDuration) { |
| 50 DCHECK(demuxer_); | 50 DCHECK(demuxer_); |
| 51 demuxer_->SetTracksWatcher( | 51 demuxer_->SetTracksWatcher( |
| 52 id, base::Bind(&WebSourceBufferImpl::InitSegmentReceived, | 52 id, base::Bind(&WebSourceBufferImpl::InitSegmentReceived, |
| 53 base::Unretained(this))); | 53 base::Unretained(this))); |
| 54 } | 54 } |
| 55 | 55 |
| 56 WebSourceBufferImpl::~WebSourceBufferImpl() { | 56 WebSourceBufferImpl::~WebSourceBufferImpl() { |
| 57 DCHECK(!demuxer_) << "Object destroyed w/o removedFromMediaSource() call"; | 57 DCHECK(!demuxer_) << "Object destroyed w/o removedFromMediaSource() call"; |
| 58 DCHECK(!client_); | 58 DCHECK(!client_); |
| 59 } | 59 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 trackInfo.kind = blink::WebString::fromUTF8(track->kind()); | 194 trackInfo.kind = blink::WebString::fromUTF8(track->kind()); |
| 195 trackInfo.label = blink::WebString::fromUTF8(track->label()); | 195 trackInfo.label = blink::WebString::fromUTF8(track->label()); |
| 196 trackInfo.language = blink::WebString::fromUTF8(track->language()); | 196 trackInfo.language = blink::WebString::fromUTF8(track->language()); |
| 197 trackInfoVector.push_back(trackInfo); | 197 trackInfoVector.push_back(trackInfo); |
| 198 } | 198 } |
| 199 | 199 |
| 200 client_->initializationSegmentReceived(trackInfoVector); | 200 client_->initializationSegmentReceived(trackInfoVector); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace media | 203 } // namespace media |
| OLD | NEW |