Correct gfx dependency for cast_receiver_app.
[chromium-blink-merge.git] / media / filters / file_data_source.cc
blob5aad3f93f813417c622144c9ae62b0e1c16714e0
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/filters/file_data_source.h"
7 #include <algorithm>
9 #include "base/logging.h"
11 namespace media {
13 FileDataSource::FileDataSource()
14 : force_read_errors_(false),
15 force_streaming_(false) {
18 FileDataSource::FileDataSource(base::File file)
19 : force_read_errors_(false),
20 force_streaming_(false) {
21 file_.Initialize(file.Pass());
24 bool FileDataSource::Initialize(const base::FilePath& file_path) {
25 DCHECK(!file_.IsValid());
26 return file_.Initialize(file_path);
29 void FileDataSource::Stop() {
32 void FileDataSource::Read(int64 position, int size, uint8* data,
33 const DataSource::ReadCB& read_cb) {
34 if (force_read_errors_ || !file_.IsValid()) {
35 read_cb.Run(kReadError);
36 return;
39 int64 file_size = file_.length();
41 CHECK_GE(file_size, 0);
42 CHECK_GE(position, 0);
43 CHECK_GE(size, 0);
45 // Cap position and size within bounds.
46 position = std::min(position, file_size);
47 int64 clamped_size = std::min(static_cast<int64>(size), file_size - position);
49 memcpy(data, file_.data() + position, clamped_size);
50 read_cb.Run(clamped_size);
53 bool FileDataSource::GetSize(int64* size_out) {
54 *size_out = file_.length();
55 return true;
58 bool FileDataSource::IsStreaming() {
59 return force_streaming_;
62 void FileDataSource::SetBitrate(int bitrate) {}
64 FileDataSource::~FileDataSource() {}
66 } // namespace media