Debian Codegraph @

experimental/ffmpeg/SkVideoDecoder.h

raw
1 /*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkVideDecoder_DEFINED
9 #define SkVideDecoder_DEFINED
10
11 #include "include/core/SkImage.h"
12
13 extern "C" {
14 #include "libavcodec/avcodec.h"
15 #include "libavformat/avformat.h"
16 #include "libavformat/avio.h"
17 #include "libavutil/pixdesc.h"
18 #include "libswscale/swscale.h"
19 }
20
21 class SkStream;
22 class GrRecordingContext;
23
24 class SkVideoDecoder {
25 public:
26 explicit SkVideoDecoder(GrRecordingContext* = nullptr);
27 ~SkVideoDecoder();
28
29 void reset();
30 void setGrContext(GrRecordingContext* rContext) { fRecordingContext = rContext; }
31
32 bool loadStream(std::unique_ptr<SkStream>);
33 bool rewind();
34
35 SkISize dimensions() const;
36 double duration() const; // in seconds
37
38 // Returns each image in the video, or nullptr on eof
39 sk_sp<SkImage> nextImage(double* timeStamp = nullptr);
40
41 private:
42 sk_sp<SkImage> convertFrame(const AVFrame*);
43 double computeTimeStamp(const AVFrame*) const;
44
45 struct ConvertedColorSpace {
46 AVColorPrimaries fPrimaries;
47 AVColorTransferCharacteristic fTransfer;
48 // fCS is the converted skia form of the above enums
49 sk_sp<SkColorSpace> fCS;
50
51 // Init with illegal values, so our first compare will fail, forcing us to compute
52 // the skcolorspace.
53 ConvertedColorSpace();
54
55 void update(AVColorPrimaries, AVColorTransferCharacteristic);
56 };
57
58 GrRecordingContext* fRecordingContext = nullptr; // not owned by us
59
60 std::unique_ptr<SkStream> fStream;
61
62 AVIOContext* fStreamCtx = nullptr;
63 AVFormatContext* fFormatCtx = nullptr;
64 AVCodecContext* fDecoderCtx = nullptr;
65 int fStreamIndex = -1; // fFormatCtx->stream[...]
66
67 AVPacket fPacket;
68 AVFrame* fFrame = nullptr;
69 ConvertedColorSpace fCSCache;
70
71 enum Mode {
72 kProcessing_Mode,
73 kDraining_Mode,
74 kDone_Mode,
75 };
76 Mode fMode = kDone_Mode;
77 };
78
79 #endif
80