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

Side by Side Diff: services/media/framework/parts/file_reader.cc

Issue 1814583002: Motown: New wrapper classes for ffmpeg format context and io context (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Tweaks based on feedback. Created 4 years, 9 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 | « no previous file | services/media/framework/parts/reader.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <cstdio> 5 #include <cstdio>
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "services/media/framework/parts/file_reader.h" 8 #include "services/media/framework/parts/file_reader.h"
9 #include "url/gurl.h" 9 #include "url/gurl.h"
10 10
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 28
29 if (fseek(file_, 0, SEEK_END) == 0) { 29 if (fseek(file_, 0, SEEK_END) == 0) {
30 size_ = ftell(file_); 30 size_ = ftell(file_);
31 if (fseek(file_, 0, SEEK_SET) < 0) { 31 if (fseek(file_, 0, SEEK_SET) < 0) {
32 fclose(file_); 32 fclose(file_);
33 file_ = nullptr; 33 file_ = nullptr;
34 return Result::kUnsupportedOperation; 34 return Result::kUnsupportedOperation;
35 } 35 }
36 } else { 36 } else {
37 size_ = -1; 37 size_ = kFailed;
38 } 38 }
39 39
40 return Result::kOk; 40 return Result::kOk;
41 } 41 }
42 42
43 size_t FileReader::Read(uint8_t* buffer, size_t bytes_to_read) { 43 size_t FileReader::Read(uint8_t* buffer, size_t bytes_to_read) {
44 return fread(buffer, 1, bytes_to_read, file_); 44 size_t bytes_read = fread(buffer, 1, bytes_to_read, file_);
45 if (bytes_read != bytes_to_read && ferror(file_) != 0) {
46 bytes_read = kFailed;
47 }
48 return bytes_read;
45 } 49 }
46 50
47 int64_t FileReader::GetPosition() const { 51 int64_t FileReader::GetPosition() const {
48 return ftell(file_); 52 return ftell(file_);
49 } 53 }
50 54
51 int64_t FileReader::SetPosition(int64_t position) { 55 int64_t FileReader::SetPosition(int64_t position) {
52 if (fseek(file_, position, SEEK_SET) < 0) { 56 if (fseek(file_, position, SEEK_SET) < 0) {
53 return -1; 57 return -1;
54 } 58 }
55 return position; 59 return position;
56 } 60 }
57 61
58 size_t FileReader::GetSize() const { 62 size_t FileReader::GetSize() const {
59 return size_; 63 return size_;
60 } 64 }
61 65
62 bool FileReader::CanSeek() const { 66 bool FileReader::CanSeek() const {
63 return true; 67 return true;
64 } 68 }
65 69
66 } // namespace media 70 } // namespace media
67 } // namespace mojo 71 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | services/media/framework/parts/reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698