"vscode:/vscode.git/clone" did not exist on "fa763bac2e0be0ba99a2d51cca5a00e3ff739af9"
seekable_buffer.h 1.18 KB
Newer Older
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
46
// Copyright 2004-present Facebook. All Rights Reserved.

#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:
  // try to fill out buffer, returns true if EOF detected (seek will supported)
  bool init(
      DecoderInCallback&& in,
      ssize_t minSize,
      ssize_t maxSize,
      uint64_t timeoutMs);
  int read(uint8_t* buf, int size, uint64_t timeoutMs);
  int64_t seek(int64_t offset, int whence, uint64_t timeoutMs);
  void shutdown();
  ImageType getImageType() const {
    return imageType_;
  }

 private:
  DecoderInCallback inCallback_;
  std::vector<uint8_t> buffer_; // resized at init time
  ssize_t len_{0}; // current buffer size
  ssize_t pos_{0}; // current position (SEEK_CUR iff pos_ < end_)
  ssize_t end_{0}; // bytes in buffer [0, buffer_.size()]
  ssize_t eof_{0}; // indicates the EOF
  ImageType imageType_{ImageType::UNKNOWN};
};

} // namespace ffmpeg