| OLD | NEW |
| 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 #ifndef SERVICES_MEDIA_FRAMEWORK_PARTS_READER_H_ | 5 #ifndef SERVICES_MEDIA_FRAMEWORK_PARTS_READER_H_ |
| 6 #define SERVICES_MEDIA_FRAMEWORK_PARTS_READER_H_ | 6 #define SERVICES_MEDIA_FRAMEWORK_PARTS_READER_H_ |
| 7 | 7 |
| 8 #include <limits> |
| 8 #include <memory> | 9 #include <memory> |
| 9 | 10 |
| 10 #include "services/media/framework/result.h" | 11 #include "services/media/framework/result.h" |
| 11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 12 | 13 |
| 13 namespace mojo { | 14 namespace mojo { |
| 14 namespace media { | 15 namespace media { |
| 15 | 16 |
| 16 // Abstract base class for objects that read raw data on behalf of demuxes. | 17 // Abstract base class for objects that read raw data on behalf of demuxes. |
| 17 // This model is synchronous, because that's how ffmpeg works. | 18 // This model is synchronous, because that's how ffmpeg works. |
| 19 // TODO(dalesat): Make this model async and deal with it in FfmpegDemux. |
| 18 class Reader { | 20 class Reader { |
| 19 public: | 21 public: |
| 22 static constexpr size_t kFailed = std::numeric_limits<size_t>::max(); |
| 23 |
| 20 // Creates a Reader object for a given url. | 24 // Creates a Reader object for a given url. |
| 21 static Result Create(const GURL& gurl, std::shared_ptr<Reader>* reader_out); | 25 static Result Create(const GURL& gurl, std::shared_ptr<Reader>* reader_out); |
| 22 | 26 |
| 23 virtual ~Reader() {} | 27 virtual ~Reader() {} |
| 24 | 28 |
| 25 // Initializes the reader. | 29 // Initializes the reader. |
| 26 virtual Result Init(const GURL& gurl) = 0; | 30 virtual Result Init(const GURL& gurl) = 0; |
| 27 | 31 |
| 28 // Reads the given number of bytes into the buffer and returns the number of | 32 // Reads the given number of bytes into the buffer and returns the number of |
| 29 // bytes read. Returns -1 if the operation fails. | 33 // bytes read. Returns kFailed if the operation fails. |
| 30 virtual size_t Read(uint8_t* buffer, size_t bytes_to_read) = 0; | 34 virtual size_t Read(uint8_t* buffer, size_t bytes_to_read) = 0; |
| 31 | 35 |
| 32 // Gets the current position or -1 if the operation fails. | 36 // Gets the current position or -1 if the operation fails. |
| 33 virtual int64_t GetPosition() const = 0; | 37 virtual int64_t GetPosition() const = 0; |
| 34 | 38 |
| 35 // Seeks to the given position and returns it. Returns -1 if the operation | 39 // Seeks to the given position and returns it. Returns -1 if the operation |
| 36 // fails. | 40 // fails. |
| 37 virtual int64_t SetPosition(int64_t position) = 0; | 41 virtual int64_t SetPosition(int64_t position) = 0; |
| 38 | 42 |
| 39 // Returns the file size. Returns -1 if the operation fails or the size isn't | 43 // Returns the file size. Returns kFailed if the operation fails or the size |
| 40 // known. | 44 // isn't known. |
| 41 virtual size_t GetSize() const = 0; | 45 virtual size_t GetSize() const = 0; |
| 42 | 46 |
| 43 // Returns true if this object supports seeking, false otherwise. | 47 // Returns true if this object supports seeking, false otherwise. |
| 44 virtual bool CanSeek() const = 0; | 48 virtual bool CanSeek() const = 0; |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 } // namespace media | 51 } // namespace media |
| 48 } // namespace mojo | 52 } // namespace mojo |
| 49 | 53 |
| 50 #endif // MOJO_SERVICES_MEDIA_READER_H_ | 54 #endif // MOJO_SERVICES_MEDIA_READER_H_ |
| OLD | NEW |