File: seekable_buffer.h

package info (click to toggle)
pytorch-vision 0.21.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,228 kB
  • sloc: python: 65,904; cpp: 11,406; ansic: 2,459; java: 550; sh: 265; xml: 79; objc: 56; makefile: 33
file content (45 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

#include "defs.h"

namespace ffmpeg {

/**
 * Class uses internal buffer to store initial size bytes as a seekable cache
 * from Media provider and let ffmpeg to seek and read bytes from cache
 * and beyond - reading bytes directly from Media provider
 */
enum class ImageType {
  UNKNOWN = 0,
  JPEG = 1,
  PNG = 2,
  TIFF = 3,
};

class SeekableBuffer {
 public:
  // @type is optional, not nullptr only is image detection required
  // \returns 1 is buffer seekable, 0 - if not seekable, < 0 on error
  int init(
      DecoderInCallback&& in,
      uint64_t timeoutMs,
      size_t maxSeekableBytes,
      ImageType* type);
  int read(uint8_t* buf, int size, uint64_t timeoutMs);
  int64_t seek(int64_t offset, int whence, uint64_t timeoutMs);
  void shutdown();

 private:
  bool readBytes(DecoderInCallback& in, size_t maxBytes, uint64_t timeoutMs);
  void setImageType(ImageType* type);

 private:
  DecoderInCallback inCallback_;
  std::vector<uint8_t> buffer_; // resized at init time
  long pos_{0}; // current position (SEEK_CUR iff pos_ < end_)
  long end_{0}; // current buffer size
  bool eof_{0}; // indicates the EOF
  bool isSeekable_{false}; // is callback seekable
};

} // namespace ffmpeg