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 "media/base/media_tracks.h" |
15 #include "media/base/timestamp_constants.h" | 16 #include "media/base/timestamp_constants.h" |
16 #include "media/filters/chunk_demuxer.h" | 17 #include "media/filters/chunk_demuxer.h" |
17 #include "third_party/WebKit/public/platform/WebSourceBufferClient.h" | 18 #include "third_party/WebKit/public/platform/WebSourceBufferClient.h" |
18 | 19 |
19 namespace media { | 20 namespace media { |
20 | 21 |
21 static base::TimeDelta DoubleToTimeDelta(double time) { | 22 static base::TimeDelta DoubleToTimeDelta(double time) { |
22 DCHECK(!std::isnan(time)); | 23 DCHECK(!std::isnan(time)); |
23 DCHECK_NE(time, -std::numeric_limits<double>::infinity()); | 24 DCHECK_NE(time, -std::numeric_limits<double>::infinity()); |
24 | 25 |
(...skipping 13 matching lines...) Expand all Loading... |
38 time * base::Time::kMicrosecondsPerSecond); | 39 time * base::Time::kMicrosecondsPerSecond); |
39 } | 40 } |
40 | 41 |
41 WebSourceBufferImpl::WebSourceBufferImpl( | 42 WebSourceBufferImpl::WebSourceBufferImpl( |
42 const std::string& id, ChunkDemuxer* demuxer) | 43 const std::string& id, ChunkDemuxer* demuxer) |
43 : id_(id), | 44 : id_(id), |
44 demuxer_(demuxer), | 45 demuxer_(demuxer), |
45 client_(NULL), | 46 client_(NULL), |
46 append_window_end_(kInfiniteDuration()) { | 47 append_window_end_(kInfiniteDuration()) { |
47 DCHECK(demuxer_); | 48 DCHECK(demuxer_); |
| 49 demuxer_->SetTracksWatcher( |
| 50 id, base::Bind(&WebSourceBufferImpl::InitSegmentReceived, |
| 51 base::Unretained(this))); |
48 } | 52 } |
49 | 53 |
50 WebSourceBufferImpl::~WebSourceBufferImpl() { | 54 WebSourceBufferImpl::~WebSourceBufferImpl() { |
51 DCHECK(!demuxer_) << "Object destroyed w/o removedFromMediaSource() call"; | 55 DCHECK(!demuxer_) << "Object destroyed w/o removedFromMediaSource() call"; |
52 DCHECK(!client_); | 56 DCHECK(!client_); |
53 } | 57 } |
54 | 58 |
55 void WebSourceBufferImpl::setClient(blink::WebSourceBufferClient* client) { | 59 void WebSourceBufferImpl::setClient(blink::WebSourceBufferClient* client) { |
56 DCHECK(client); | 60 DCHECK(client); |
57 DCHECK(!client_); | 61 DCHECK(!client_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 id_, | 95 id_, |
92 base::TimeDelta::FromSecondsD(currentPlaybackTime), | 96 base::TimeDelta::FromSecondsD(currentPlaybackTime), |
93 newDataSize); | 97 newDataSize); |
94 } | 98 } |
95 | 99 |
96 void WebSourceBufferImpl::append( | 100 void WebSourceBufferImpl::append( |
97 const unsigned char* data, | 101 const unsigned char* data, |
98 unsigned length, | 102 unsigned length, |
99 double* timestamp_offset) { | 103 double* timestamp_offset) { |
100 base::TimeDelta old_offset = timestamp_offset_; | 104 base::TimeDelta old_offset = timestamp_offset_; |
101 demuxer_->AppendData(id_, data, length, | 105 demuxer_->AppendData(id_, data, length, append_window_start_, |
102 append_window_start_, append_window_end_, | 106 append_window_end_, ×tamp_offset_); |
103 ×tamp_offset_, | |
104 base::Bind(&WebSourceBufferImpl::InitSegmentReceived, | |
105 base::Unretained(this))); | |
106 | 107 |
107 // Coded frame processing may update the timestamp offset. If the caller | 108 // Coded frame processing may update the timestamp offset. If the caller |
108 // provides a non-NULL |timestamp_offset| and frame processing changes the | 109 // provides a non-NULL |timestamp_offset| and frame processing changes the |
109 // timestamp offset, report the new offset to the caller. Do not update the | 110 // timestamp offset, report the new offset to the caller. Do not update the |
110 // caller's offset otherwise, to preserve any pre-existing value that may have | 111 // caller's offset otherwise, to preserve any pre-existing value that may have |
111 // more than microsecond precision. | 112 // more than microsecond precision. |
112 if (timestamp_offset && old_offset != timestamp_offset_) | 113 if (timestamp_offset && old_offset != timestamp_offset_) |
113 *timestamp_offset = timestamp_offset_.InSecondsF(); | 114 *timestamp_offset = timestamp_offset_.InSecondsF(); |
114 } | 115 } |
115 | 116 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 DCHECK_GE(end, 0); | 152 DCHECK_GE(end, 0); |
152 append_window_end_ = DoubleToTimeDelta(end); | 153 append_window_end_ = DoubleToTimeDelta(end); |
153 } | 154 } |
154 | 155 |
155 void WebSourceBufferImpl::removedFromMediaSource() { | 156 void WebSourceBufferImpl::removedFromMediaSource() { |
156 demuxer_->RemoveId(id_); | 157 demuxer_->RemoveId(id_); |
157 demuxer_ = NULL; | 158 demuxer_ = NULL; |
158 client_ = NULL; | 159 client_ = NULL; |
159 } | 160 } |
160 | 161 |
161 void WebSourceBufferImpl::InitSegmentReceived() { | 162 void WebSourceBufferImpl::InitSegmentReceived(scoped_ptr<MediaTracks> tracks) { |
162 DVLOG(1) << __FUNCTION__; | 163 DVLOG(1) << __FUNCTION__; |
163 client_->initializationSegmentReceived(); | 164 client_->initializationSegmentReceived(); |
164 } | 165 } |
165 | 166 |
166 } // namespace media | 167 } // namespace media |
OLD | NEW |