Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Side by Side Diff: media/blink/websourcebuffer_impl.cc

Issue 2643743002: Mojify demuxers and allow running {Chunk/FFmpeg}Demuxer in a Utility Process (Closed)
Patch Set: Rebase and make sure to unbind mojom::DemuxerPtr on the bound thread during termination Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/websourcebuffer_impl.h ('k') | media/filters/chunk_demuxer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/source_buffer.h"
17 #include "media/base/timestamp_constants.h" 18 #include "media/base/timestamp_constants.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(const std::string& id, 44 WebSourceBufferImpl::WebSourceBufferImpl(const std::string& id,
45 ChunkDemuxer* demuxer) 45 SourceBuffer* source_buffer)
46 : id_(id), 46 : id_(id),
47 demuxer_(demuxer), 47 source_buffer_(source_buffer),
48 client_(NULL), 48 client_(NULL),
49 append_window_end_(kInfiniteDuration) { 49 append_window_end_(kInfiniteDuration) {
50 DCHECK(demuxer_); 50 DCHECK(source_buffer_);
51 demuxer_->SetTracksWatcher( 51 source_buffer_->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(!source_buffer_)
58 << "Object destroyed w/o removedFromMediaSource() call";
58 DCHECK(!client_); 59 DCHECK(!client_);
59 } 60 }
60 61
61 void WebSourceBufferImpl::setClient(blink::WebSourceBufferClient* client) { 62 void WebSourceBufferImpl::setClient(blink::WebSourceBufferClient* client) {
62 DCHECK(client); 63 DCHECK(client);
63 DCHECK(!client_); 64 DCHECK(!client_);
64 client_ = client; 65 client_ = client;
65 } 66 }
66 67
67 bool WebSourceBufferImpl::setMode(WebSourceBuffer::AppendMode mode) { 68 bool WebSourceBufferImpl::setMode(WebSourceBuffer::AppendMode mode) {
68 if (demuxer_->IsParsingMediaSegment(id_)) 69 if (source_buffer_->IsParsingMediaSegment(id_))
69 return false; 70 return false;
70 71
71 switch (mode) { 72 switch (mode) {
72 case WebSourceBuffer::AppendModeSegments: 73 case WebSourceBuffer::AppendModeSegments:
73 demuxer_->SetSequenceMode(id_, false); 74 source_buffer_->SetSequenceMode(id_, false);
74 return true; 75 return true;
75 case WebSourceBuffer::AppendModeSequence: 76 case WebSourceBuffer::AppendModeSequence:
76 demuxer_->SetSequenceMode(id_, true); 77 source_buffer_->SetSequenceMode(id_, true);
77 return true; 78 return true;
78 } 79 }
79 80
80 NOTREACHED(); 81 NOTREACHED();
81 return false; 82 return false;
82 } 83 }
83 84
84 blink::WebTimeRanges WebSourceBufferImpl::buffered() { 85 blink::WebTimeRanges WebSourceBufferImpl::buffered() {
85 Ranges<base::TimeDelta> ranges = demuxer_->GetBufferedRanges(id_); 86 Ranges<base::TimeDelta> ranges = source_buffer_->GetBufferedRanges(id_);
86 blink::WebTimeRanges result(ranges.size()); 87 blink::WebTimeRanges result(ranges.size());
87 for (size_t i = 0; i < ranges.size(); i++) { 88 for (size_t i = 0; i < ranges.size(); i++) {
88 result[i].start = ranges.start(i).InSecondsF(); 89 result[i].start = ranges.start(i).InSecondsF();
89 result[i].end = ranges.end(i).InSecondsF(); 90 result[i].end = ranges.end(i).InSecondsF();
90 } 91 }
91 return result; 92 return result;
92 } 93 }
93 94
94 double WebSourceBufferImpl::highestPresentationTimestamp() { 95 double WebSourceBufferImpl::highestPresentationTimestamp() {
95 return demuxer_->GetHighestPresentationTimestamp(id_).InSecondsF(); 96 return source_buffer_->GetHighestPresentationTimestamp(id_).InSecondsF();
96 } 97 }
97 98
98 bool WebSourceBufferImpl::evictCodedFrames(double currentPlaybackTime, 99 bool WebSourceBufferImpl::evictCodedFrames(double currentPlaybackTime,
99 size_t newDataSize) { 100 size_t newDataSize) {
100 return demuxer_->EvictCodedFrames( 101 return source_buffer_->EvictCodedFrames(
101 id_, 102 id_, base::TimeDelta::FromSecondsD(currentPlaybackTime), newDataSize);
102 base::TimeDelta::FromSecondsD(currentPlaybackTime),
103 newDataSize);
104 } 103 }
105 104
106 bool WebSourceBufferImpl::append(const unsigned char* data, 105 bool WebSourceBufferImpl::append(const unsigned char* data,
107 unsigned length, 106 unsigned length,
108 double* timestamp_offset) { 107 double* timestamp_offset) {
109 base::TimeDelta old_offset = timestamp_offset_; 108 base::TimeDelta old_offset = timestamp_offset_;
110 bool success = demuxer_->AppendData(id_, data, length, append_window_start_, 109
111 append_window_end_, &timestamp_offset_); 110 bool success =
111 source_buffer_->AppendData(id_, data, length, append_window_start_,
112 append_window_end_, &timestamp_offset_);
112 113
113 // Coded frame processing may update the timestamp offset. If the caller 114 // Coded frame processing may update the timestamp offset. If the caller
114 // provides a non-NULL |timestamp_offset| and frame processing changes the 115 // provides a non-NULL |timestamp_offset| and frame processing changes the
115 // timestamp offset, report the new offset to the caller. Do not update the 116 // timestamp offset, report the new offset to the caller. Do not update the
116 // caller's offset otherwise, to preserve any pre-existing value that may have 117 // caller's offset otherwise, to preserve any pre-existing value that may have
117 // more than microsecond precision. 118 // more than microsecond precision.
118 if (timestamp_offset && old_offset != timestamp_offset_) 119 if (timestamp_offset && old_offset != timestamp_offset_)
119 *timestamp_offset = timestamp_offset_.InSecondsF(); 120 *timestamp_offset = timestamp_offset_.InSecondsF();
120 121
121 return success; 122 return success;
122 } 123 }
123 124
124 void WebSourceBufferImpl::resetParserState() { 125 void WebSourceBufferImpl::resetParserState() {
125 demuxer_->ResetParserState(id_, 126 source_buffer_->ResetParserState(id_, append_window_start_,
126 append_window_start_, append_window_end_, 127 append_window_end_, &timestamp_offset_);
127 &timestamp_offset_);
128 128
129 // TODO(wolenetz): resetParserState should be able to modify the caller 129 // TODO(wolenetz): resetParserState should be able to modify the caller
130 // timestamp offset (just like WebSourceBufferImpl::append). 130 // timestamp offset (just like WebSourceBufferImpl::append).
131 // See http://crbug.com/370229 for further details. 131 // See http://crbug.com/370229 for further details.
132 } 132 }
133 133
134 void WebSourceBufferImpl::remove(double start, double end) { 134 void WebSourceBufferImpl::remove(double start, double end) {
135 DCHECK_GE(start, 0); 135 DCHECK_GE(start, 0);
136 DCHECK_GE(end, 0); 136 DCHECK_GE(end, 0);
137 demuxer_->Remove(id_, DoubleToTimeDelta(start), DoubleToTimeDelta(end)); 137 source_buffer_->Remove(id_, DoubleToTimeDelta(start), DoubleToTimeDelta(end));
138 } 138 }
139 139
140 bool WebSourceBufferImpl::setTimestampOffset(double offset) { 140 bool WebSourceBufferImpl::setTimestampOffset(double offset) {
141 if (demuxer_->IsParsingMediaSegment(id_)) 141 if (source_buffer_->IsParsingMediaSegment(id_))
142 return false; 142 return false;
143 143
144 timestamp_offset_ = DoubleToTimeDelta(offset); 144 timestamp_offset_ = DoubleToTimeDelta(offset);
145 145
146 // http://www.w3.org/TR/media-source/#widl-SourceBuffer-timestampOffset 146 // http://www.w3.org/TR/media-source/#widl-SourceBuffer-timestampOffset
147 // Step 6: If the mode attribute equals "sequence", then set the group start 147 // Step 6: If the mode attribute equals "sequence", then set the group start
148 // timestamp to new timestamp offset. 148 // timestamp to new timestamp offset.
149 demuxer_->SetGroupStartTimestampIfInSequenceMode(id_, timestamp_offset_); 149 source_buffer_->SetGroupStartTimestampIfInSequenceMode(id_,
150 timestamp_offset_);
150 return true; 151 return true;
151 } 152 }
152 153
153 void WebSourceBufferImpl::setAppendWindowStart(double start) { 154 void WebSourceBufferImpl::setAppendWindowStart(double start) {
154 DCHECK_GE(start, 0); 155 DCHECK_GE(start, 0);
155 append_window_start_ = DoubleToTimeDelta(start); 156 append_window_start_ = DoubleToTimeDelta(start);
156 } 157 }
157 158
158 void WebSourceBufferImpl::setAppendWindowEnd(double end) { 159 void WebSourceBufferImpl::setAppendWindowEnd(double end) {
159 DCHECK_GE(end, 0); 160 DCHECK_GE(end, 0);
160 append_window_end_ = DoubleToTimeDelta(end); 161 append_window_end_ = DoubleToTimeDelta(end);
161 } 162 }
162 163
163 void WebSourceBufferImpl::removedFromMediaSource() { 164 void WebSourceBufferImpl::removedFromMediaSource() {
164 demuxer_->RemoveId(id_); 165 source_buffer_->RemoveId(id_);
165 demuxer_ = NULL; 166 source_buffer_ = NULL;
166 client_ = NULL; 167 client_ = NULL;
167 } 168 }
168 169
169 blink::WebMediaPlayer::TrackType mediaTrackTypeToBlink(MediaTrack::Type type) { 170 blink::WebMediaPlayer::TrackType mediaTrackTypeToBlink(MediaTrack::Type type) {
170 switch (type) { 171 switch (type) {
171 case MediaTrack::Audio: 172 case MediaTrack::Audio:
172 return blink::WebMediaPlayer::AudioTrack; 173 return blink::WebMediaPlayer::AudioTrack;
173 case MediaTrack::Text: 174 case MediaTrack::Text:
174 return blink::WebMediaPlayer::TextTrack; 175 return blink::WebMediaPlayer::TextTrack;
175 case MediaTrack::Video: 176 case MediaTrack::Video:
(...skipping 18 matching lines...) Expand all
194 trackInfo.kind = blink::WebString::fromUTF8(track->kind()); 195 trackInfo.kind = blink::WebString::fromUTF8(track->kind());
195 trackInfo.label = blink::WebString::fromUTF8(track->label()); 196 trackInfo.label = blink::WebString::fromUTF8(track->label());
196 trackInfo.language = blink::WebString::fromUTF8(track->language()); 197 trackInfo.language = blink::WebString::fromUTF8(track->language());
197 trackInfoVector.push_back(trackInfo); 198 trackInfoVector.push_back(trackInfo);
198 } 199 }
199 200
200 client_->initializationSegmentReceived(trackInfoVector); 201 client_->initializationSegmentReceived(trackInfoVector);
201 } 202 }
202 203
203 } // namespace media 204 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/websourcebuffer_impl.h ('k') | media/filters/chunk_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698