"git@developer.sourcefind.cn:zhaoyu6/sglang.git" did not exist on "5e7dd984fe0151198148b9cee6e613805e80998b"
FfmpegStream.h 1.98 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
#pragma once

#include <memory>
#include <unordered_map>
#include <utility>
#include "FfmpegHeaders.h"
#include "Interface.h"

/*
Class uses FFMPEG library to decode one media stream (audio or video).
*/
class FfmpegStream {
 public:
  FfmpegStream(
      AVFormatContext* inputCtx,
      int index,
      enum AVMediaType avMediaType,
      double seekFrameMargin);
  virtual ~FfmpegStream();

  // returns 0 - on success or negative error
  int openCodecContext();
  // returns stream index
  int getIndex() const {
    return index_;
  }
  // returns number decoded/sampled bytes
  std::unique_ptr<DecodedFrame> getFrameData(int getPtsOnly);
  // flush the stream at the end of decoding.
  // Return 0 on success and -1 when cache is drained
  void flush(int getPtsOnly, DecoderOutput& decoderOutput);
  // seek a frame
  int seekFrame(int64_t ts);
  // send an AVPacket
  int sendPacket(const AVPacket* packet);
  // receive AVFrame
  int receiveFrame();
  // receive all available frames from the internal buffer
  void receiveAvailFrames(int getPtsOnly, DecoderOutput& decoderOutput);
  // return media type
  virtual MediaType getMediaType() const = 0;
  // return media format
  virtual FormatUnion getMediaFormat() const = 0;
  // return start presentation timestamp
  virtual int64_t getStartPts() const = 0;
  // return end presentation timestamp
  virtual int64_t getEndPts() const = 0;
  // is the pts of most recent frame within range?
  bool isFramePtsInRange();
  // does the pts of most recent frame exceed range?
  bool isFramePtsExceedRange();

 protected:
  virtual int initFormat() = 0;
  // returns a decoded frame
  virtual std::unique_ptr<DecodedFrame> sampleFrameData() = 0;

 protected:
  AVFormatContext* const inputCtx_;
  const int index_;
  enum AVMediaType avMediaType_;

  AVCodecContext* codecCtx_{nullptr};
  AVFrame* frame_{nullptr};
  // pts of last decoded frame
  int64_t last_pts_{0};
  double seekFrameMargin_{1.0};
};