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 <limits> | 7 #include <limits> |
8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/callback.h" |
| 11 #include "base/callback_helpers.h" |
9 #include "base/float_util.h" | 12 #include "base/float_util.h" |
10 #include "media/filters/chunk_demuxer.h" | 13 #include "media/filters/chunk_demuxer.h" |
| 14 #include "third_party/WebKit/public/platform/WebSourceBufferClient.h" |
11 | 15 |
12 namespace media { | 16 namespace media { |
13 | 17 |
14 static base::TimeDelta DoubleToTimeDelta(double time) { | 18 static base::TimeDelta DoubleToTimeDelta(double time) { |
15 DCHECK(!base::IsNaN(time)); | 19 DCHECK(!base::IsNaN(time)); |
16 DCHECK_NE(time, -std::numeric_limits<double>::infinity()); | 20 DCHECK_NE(time, -std::numeric_limits<double>::infinity()); |
17 | 21 |
18 if (time == std::numeric_limits<double>::infinity()) | 22 if (time == std::numeric_limits<double>::infinity()) |
19 return kInfiniteDuration(); | 23 return kInfiniteDuration(); |
20 | 24 |
21 // Don't use base::TimeDelta::Max() here, as we want the largest finite time | 25 // Don't use base::TimeDelta::Max() here, as we want the largest finite time |
22 // delta. | 26 // delta. |
23 base::TimeDelta max_time = base::TimeDelta::FromInternalValue(kint64max - 1); | 27 base::TimeDelta max_time = base::TimeDelta::FromInternalValue(kint64max - 1); |
24 double max_time_in_seconds = max_time.InSecondsF(); | 28 double max_time_in_seconds = max_time.InSecondsF(); |
25 | 29 |
26 if (time >= max_time_in_seconds) | 30 if (time >= max_time_in_seconds) |
27 return max_time; | 31 return max_time; |
28 | 32 |
29 return base::TimeDelta::FromMicroseconds( | 33 return base::TimeDelta::FromMicroseconds( |
30 time * base::Time::kMicrosecondsPerSecond); | 34 time * base::Time::kMicrosecondsPerSecond); |
31 } | 35 } |
32 | 36 |
33 WebSourceBufferImpl::WebSourceBufferImpl( | 37 WebSourceBufferImpl::WebSourceBufferImpl( |
34 const std::string& id, ChunkDemuxer* demuxer) | 38 const std::string& id, ChunkDemuxer* demuxer) |
35 : id_(id), | 39 : id_(id), |
36 demuxer_(demuxer), | 40 demuxer_(demuxer), |
| 41 client_(NULL), |
37 append_window_end_(kInfiniteDuration()) { | 42 append_window_end_(kInfiniteDuration()) { |
38 DCHECK(demuxer_); | 43 DCHECK(demuxer_); |
39 } | 44 } |
40 | 45 |
41 WebSourceBufferImpl::~WebSourceBufferImpl() { | 46 WebSourceBufferImpl::~WebSourceBufferImpl() { |
42 DCHECK(!demuxer_) << "Object destroyed w/o removedFromMediaSource() call"; | 47 DCHECK(!demuxer_) << "Object destroyed w/o removedFromMediaSource() call"; |
| 48 DCHECK(!client_); |
| 49 } |
| 50 |
| 51 void WebSourceBufferImpl::setClient(blink::WebSourceBufferClient* client) { |
| 52 DCHECK(client); |
| 53 DCHECK(!client_); |
| 54 client_ = client; |
43 } | 55 } |
44 | 56 |
45 bool WebSourceBufferImpl::setMode(WebSourceBuffer::AppendMode mode) { | 57 bool WebSourceBufferImpl::setMode(WebSourceBuffer::AppendMode mode) { |
46 if (demuxer_->IsParsingMediaSegment(id_)) | 58 if (demuxer_->IsParsingMediaSegment(id_)) |
47 return false; | 59 return false; |
48 | 60 |
49 switch (mode) { | 61 switch (mode) { |
50 case WebSourceBuffer::AppendModeSegments: | 62 case WebSourceBuffer::AppendModeSegments: |
51 demuxer_->SetSequenceMode(id_, false); | 63 demuxer_->SetSequenceMode(id_, false); |
52 return true; | 64 return true; |
(...skipping 16 matching lines...) Expand all Loading... |
69 return result; | 81 return result; |
70 } | 82 } |
71 | 83 |
72 void WebSourceBufferImpl::append( | 84 void WebSourceBufferImpl::append( |
73 const unsigned char* data, | 85 const unsigned char* data, |
74 unsigned length, | 86 unsigned length, |
75 double* timestamp_offset) { | 87 double* timestamp_offset) { |
76 base::TimeDelta old_offset = timestamp_offset_; | 88 base::TimeDelta old_offset = timestamp_offset_; |
77 demuxer_->AppendData(id_, data, length, | 89 demuxer_->AppendData(id_, data, length, |
78 append_window_start_, append_window_end_, | 90 append_window_start_, append_window_end_, |
79 ×tamp_offset_); | 91 ×tamp_offset_, |
| 92 base::Bind(&WebSourceBufferImpl::InitSegmentReceived, |
| 93 base::Unretained(this))); |
80 | 94 |
81 // Coded frame processing may update the timestamp offset. If the caller | 95 // Coded frame processing may update the timestamp offset. If the caller |
82 // provides a non-NULL |timestamp_offset| and frame processing changes the | 96 // provides a non-NULL |timestamp_offset| and frame processing changes the |
83 // timestamp offset, report the new offset to the caller. Do not update the | 97 // timestamp offset, report the new offset to the caller. Do not update the |
84 // caller's offset otherwise, to preserve any pre-existing value that may have | 98 // caller's offset otherwise, to preserve any pre-existing value that may have |
85 // more than microsecond precision. | 99 // more than microsecond precision. |
86 if (timestamp_offset && old_offset != timestamp_offset_) | 100 if (timestamp_offset && old_offset != timestamp_offset_) |
87 *timestamp_offset = timestamp_offset_.InSecondsF(); | 101 *timestamp_offset = timestamp_offset_.InSecondsF(); |
88 } | 102 } |
89 | 103 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 136 } |
123 | 137 |
124 void WebSourceBufferImpl::setAppendWindowEnd(double end) { | 138 void WebSourceBufferImpl::setAppendWindowEnd(double end) { |
125 DCHECK_GE(end, 0); | 139 DCHECK_GE(end, 0); |
126 append_window_end_ = DoubleToTimeDelta(end); | 140 append_window_end_ = DoubleToTimeDelta(end); |
127 } | 141 } |
128 | 142 |
129 void WebSourceBufferImpl::removedFromMediaSource() { | 143 void WebSourceBufferImpl::removedFromMediaSource() { |
130 demuxer_->RemoveId(id_); | 144 demuxer_->RemoveId(id_); |
131 demuxer_ = NULL; | 145 demuxer_ = NULL; |
| 146 client_ = NULL; |
| 147 } |
| 148 |
| 149 void WebSourceBufferImpl::InitSegmentReceived() { |
| 150 DVLOG(1) << __FUNCTION__; |
| 151 client_->initializationSegmentReceived(); |
132 } | 152 } |
133 | 153 |
134 } // namespace media | 154 } // namespace media |
OLD | NEW |