data_source.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.
  4. #ifndef MEDIA_BASE_DATA_SOURCE_H_
  5. #define MEDIA_BASE_DATA_SOURCE_H_
  6. #include <stdint.h>
  7. #include "base/callback_forward.h"
  8. #include "media/base/media_export.h"
  9. namespace media {
  10. class MEDIA_EXPORT DataSource {
  11. public:
  12. using ReadCB = base::OnceCallback<void(int)>;
  13. enum { kReadError = -1, kAborted = -2 };
  14. DataSource();
  15. DataSource(const DataSource&) = delete;
  16. DataSource& operator=(const DataSource&) = delete;
  17. virtual ~DataSource();
  18. // Reads |size| bytes from |position| into |data|. And when the read is done
  19. // or failed, |read_cb| is called with the number of bytes read or
  20. // kReadError in case of error.
  21. virtual void Read(int64_t position,
  22. int size,
  23. uint8_t* data,
  24. DataSource::ReadCB read_cb) = 0;
  25. // Stops the DataSource. Once this is called all future Read() calls will
  26. // return an error. This is a synchronous call and may be called from any
  27. // thread. Once called, the DataSource may no longer be used and should be
  28. // destructed shortly thereafter.
  29. virtual void Stop() = 0;
  30. // Similar to Stop(), but only aborts current reads and not future reads.
  31. virtual void Abort() = 0;
  32. // Returns true and the file size, false if the file size could not be
  33. // retrieved.
  34. [[nodiscard]] virtual bool GetSize(int64_t* size_out) = 0;
  35. // Returns true if we are performing streaming. In this case seeking is
  36. // not possible.
  37. virtual bool IsStreaming() = 0;
  38. // Notify the DataSource of the bitrate of the media.
  39. // Values of |bitrate| <= 0 are invalid and should be ignored.
  40. virtual void SetBitrate(int bitrate) = 0;
  41. // Assume fully bufferred by default.
  42. virtual bool AssumeFullyBuffered() const;
  43. // By default this just returns GetSize().
  44. virtual int64_t GetMemoryUsage();
  45. };
  46. } // namespace media
  47. #endif // MEDIA_BASE_DATA_SOURCE_H_