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

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

Issue 495353003: Move WebMediaPlayerImpl and its dependencies to media/blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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/buffered_data_source.h ('k') | media/blink/buffered_data_source_host_impl.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 "content/renderer/media/buffered_data_source.h" 5 #include "media/blink/buffered_data_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "content/public/common/url_constants.h"
11 #include "media/base/media_log.h" 10 #include "media/base/media_log.h"
12 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
13 12
14 using blink::WebFrame; 13 using blink::WebFrame;
15 14
16 namespace { 15 namespace {
17 16
18 // BufferedDataSource has an intermediate buffer, this value governs the initial 17 // BufferedDataSource has an intermediate buffer, this value governs the initial
19 // size of that buffer. It is set to 32KB because this is a typical read size 18 // size of that buffer. It is set to 32KB because this is a typical read size
20 // of FFmpeg. 19 // of FFmpeg.
21 const int kInitialReadBufferSize = 32768; 20 const int kInitialReadBufferSize = 32768;
22 21
23 // Number of cache misses we allow for a single Read() before signaling an 22 // Number of cache misses we allow for a single Read() before signaling an
24 // error. 23 // error.
25 const int kNumCacheMissRetries = 3; 24 const int kNumCacheMissRetries = 3;
26 25
27 } // namespace 26 } // namespace
28 27
29 namespace content { 28 namespace media {
30 29
31 class BufferedDataSource::ReadOperation { 30 class BufferedDataSource::ReadOperation {
32 public: 31 public:
33 ReadOperation(int64 position, int size, uint8* data, 32 ReadOperation(int64 position, int size, uint8* data,
34 const media::DataSource::ReadCB& callback); 33 const DataSource::ReadCB& callback);
35 ~ReadOperation(); 34 ~ReadOperation();
36 35
37 // Runs |callback_| with the given |result|, deleting the operation 36 // Runs |callback_| with the given |result|, deleting the operation
38 // afterwards. 37 // afterwards.
39 static void Run(scoped_ptr<ReadOperation> read_op, int result); 38 static void Run(scoped_ptr<ReadOperation> read_op, int result);
40 39
41 // State for the number of times this read operation has been retried. 40 // State for the number of times this read operation has been retried.
42 int retries() { return retries_; } 41 int retries() { return retries_; }
43 void IncrementRetries() { ++retries_; } 42 void IncrementRetries() { ++retries_; }
44 43
45 int64 position() { return position_; } 44 int64 position() { return position_; }
46 int size() { return size_; } 45 int size() { return size_; }
47 uint8* data() { return data_; } 46 uint8* data() { return data_; }
48 47
49 private: 48 private:
50 int retries_; 49 int retries_;
51 50
52 const int64 position_; 51 const int64 position_;
53 const int size_; 52 const int size_;
54 uint8* data_; 53 uint8* data_;
55 media::DataSource::ReadCB callback_; 54 DataSource::ReadCB callback_;
56 55
57 DISALLOW_IMPLICIT_CONSTRUCTORS(ReadOperation); 56 DISALLOW_IMPLICIT_CONSTRUCTORS(ReadOperation);
58 }; 57 };
59 58
60 BufferedDataSource::ReadOperation::ReadOperation( 59 BufferedDataSource::ReadOperation::ReadOperation(
61 int64 position, int size, uint8* data, 60 int64 position, int size, uint8* data,
62 const media::DataSource::ReadCB& callback) 61 const DataSource::ReadCB& callback)
63 : retries_(0), 62 : retries_(0),
64 position_(position), 63 position_(position),
65 size_(size), 64 size_(size),
66 data_(data), 65 data_(data),
67 callback_(callback) { 66 callback_(callback) {
68 DCHECK(!callback_.is_null()); 67 DCHECK(!callback_.is_null());
69 } 68 }
70 69
71 BufferedDataSource::ReadOperation::~ReadOperation() { 70 BufferedDataSource::ReadOperation::~ReadOperation() {
72 DCHECK(callback_.is_null()); 71 DCHECK(callback_.is_null());
73 } 72 }
74 73
75 // static 74 // static
76 void BufferedDataSource::ReadOperation::Run( 75 void BufferedDataSource::ReadOperation::Run(
77 scoped_ptr<ReadOperation> read_op, int result) { 76 scoped_ptr<ReadOperation> read_op, int result) {
78 base::ResetAndReturn(&read_op->callback_).Run(result); 77 base::ResetAndReturn(&read_op->callback_).Run(result);
79 } 78 }
80 79
81 BufferedDataSource::BufferedDataSource( 80 BufferedDataSource::BufferedDataSource(
82 const GURL& url, 81 const GURL& url,
83 BufferedResourceLoader::CORSMode cors_mode, 82 BufferedResourceLoader::CORSMode cors_mode,
84 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 83 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
85 WebFrame* frame, 84 WebFrame* frame,
86 media::MediaLog* media_log, 85 MediaLog* media_log,
87 BufferedDataSourceHost* host, 86 BufferedDataSourceHost* host,
88 const DownloadingCB& downloading_cb) 87 const DownloadingCB& downloading_cb)
89 : url_(url), 88 : url_(url),
90 cors_mode_(cors_mode), 89 cors_mode_(cors_mode),
91 total_bytes_(kPositionNotSpecified), 90 total_bytes_(kPositionNotSpecified),
92 streaming_(false), 91 streaming_(false),
93 frame_(frame), 92 frame_(frame),
94 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), 93 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]),
95 intermediate_read_buffer_size_(kInitialReadBufferSize), 94 intermediate_read_buffer_size_(kInitialReadBufferSize),
96 render_task_runner_(task_runner), 95 render_task_runner_(task_runner),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 media_has_played_ = true; 198 media_has_played_ = true;
200 UpdateDeferStrategy(false); 199 UpdateDeferStrategy(false);
201 } 200 }
202 201
203 void BufferedDataSource::MediaIsPaused() { 202 void BufferedDataSource::MediaIsPaused() {
204 DCHECK(render_task_runner_->BelongsToCurrentThread()); 203 DCHECK(render_task_runner_->BelongsToCurrentThread());
205 UpdateDeferStrategy(true); 204 UpdateDeferStrategy(true);
206 } 205 }
207 206
208 ///////////////////////////////////////////////////////////////////////////// 207 /////////////////////////////////////////////////////////////////////////////
209 // media::DataSource implementation. 208 // DataSource implementation.
210 void BufferedDataSource::Stop() { 209 void BufferedDataSource::Stop() {
211 { 210 {
212 base::AutoLock auto_lock(lock_); 211 base::AutoLock auto_lock(lock_);
213 StopInternal_Locked(); 212 StopInternal_Locked();
214 } 213 }
215 214
216 render_task_runner_->PostTask( 215 render_task_runner_->PostTask(
217 FROM_HERE, 216 FROM_HERE,
218 base::Bind(&BufferedDataSource::StopLoader, weak_factory_.GetWeakPtr())); 217 base::Bind(&BufferedDataSource::StopLoader, weak_factory_.GetWeakPtr()));
219 } 218 }
220 219
221 void BufferedDataSource::SetBitrate(int bitrate) { 220 void BufferedDataSource::SetBitrate(int bitrate) {
222 render_task_runner_->PostTask(FROM_HERE, 221 render_task_runner_->PostTask(FROM_HERE,
223 base::Bind(&BufferedDataSource::SetBitrateTask, 222 base::Bind(&BufferedDataSource::SetBitrateTask,
224 weak_factory_.GetWeakPtr(), 223 weak_factory_.GetWeakPtr(),
225 bitrate)); 224 bitrate));
226 } 225 }
227 226
228 void BufferedDataSource::Read( 227 void BufferedDataSource::Read(
229 int64 position, int size, uint8* data, 228 int64 position, int size, uint8* data,
230 const media::DataSource::ReadCB& read_cb) { 229 const DataSource::ReadCB& read_cb) {
231 DVLOG(1) << "Read: " << position << " offset, " << size << " bytes"; 230 DVLOG(1) << "Read: " << position << " offset, " << size << " bytes";
232 DCHECK(!read_cb.is_null()); 231 DCHECK(!read_cb.is_null());
233 232
234 { 233 {
235 base::AutoLock auto_lock(lock_); 234 base::AutoLock auto_lock(lock_);
236 DCHECK(!read_op_); 235 DCHECK(!read_op_);
237 236
238 if (stop_signal_received_) { 237 if (stop_signal_received_) {
239 read_cb.Run(kReadError); 238 read_cb.Run(kReadError);
240 return; 239 return;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 return; 525 return;
527 } 526 }
528 527
529 // If media is currently playing or the page indicated preload=auto or the 528 // If media is currently playing or the page indicated preload=auto or the
530 // the server does not support the byte range request or we do not want to go 529 // the server does not support the byte range request or we do not want to go
531 // too far ahead of the read head, use threshold strategy to enable/disable 530 // too far ahead of the read head, use threshold strategy to enable/disable
532 // deferring when the buffer is full/depleted. 531 // deferring when the buffer is full/depleted.
533 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); 532 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer);
534 } 533 }
535 534
536 } // namespace content 535 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/buffered_data_source.h ('k') | media/blink/buffered_data_source_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698