Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions | Variables
SkVideoDecoder.cpp File Reference
#include "experimental/ffmpeg/SkVideoDecoder.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkImage.h"
#include "include/core/SkStream.h"
#include "include/core/SkYUVAPixmaps.h"
#include "include/gpu/ganesh/SkImageGanesh.h"

Go to the source code of this file.

Classes

struct  av_transfer_characteristics
 

Macros

#define ExpandWP(index)   gWP[index].fX, gWP[index].fY
 

Enumerations

enum  Whitepoint {
  WP_D65 , WP_C , WP_DCI , WP_E ,
  WP_NB
}
 

Functions

static SkYUVColorSpace get_yuvspace (AVColorSpace space)
 
static skcms_TransferFunction compute_transfer (AVColorTransferCharacteristic t)
 
sk_sp< SkColorSpacemake_colorspace (AVColorPrimaries primaries, AVColorTransferCharacteristic transfer)
 
static bool check_err (int err, const int silentList[]=nullptr)
 
static int skstream_read_packet (void *ctx, uint8_t *dstBuffer, int dstSize)
 
static int64_t skstream_seek_packet (void *ctx, int64_t pos, int whence)
 
static sk_sp< SkImagemake_yuv_420 (GrRecordingContext *rContext, int w, int h, uint8_t *const data[], int const strides[], SkYUVColorSpace yuvSpace, sk_sp< SkColorSpace > cs)
 

Variables

const av_transfer_characteristics gTransfer [AVCOL_TRC_NB]
 
const SkPoint gWP [WP_NB]
 
const SkColorSpacePrimaries gPrimaries [AVCOL_PRI_NB]
 

Macro Definition Documentation

◆ ExpandWP

#define ExpandWP (   index)    gWP[index].fX, gWP[index].fY

Definition at line 83 of file SkVideoDecoder.cpp.

Enumeration Type Documentation

◆ Whitepoint

enum Whitepoint
Enumerator
WP_D65 
WP_C 
WP_DCI 
WP_E 
WP_NB 

Definition at line 68 of file SkVideoDecoder.cpp.

68 {
69 WP_D65,
70 WP_C,
71 WP_DCI,
72 WP_E,
73 WP_NB,
74};
@ WP_C
@ WP_E
@ WP_NB
@ WP_D65
@ WP_DCI

Function Documentation

◆ check_err()

static bool check_err ( int  err,
const int  silentList[] = nullptr 
)
static

Definition at line 116 of file SkVideoDecoder.cpp.

116 {
117 if (err >= 0) {
118 return false;
119 }
120
121 if (silentList) {
122 for (; *silentList; ++silentList) {
123 if (*silentList == err) {
124 return true; // we still report the error, but we don't printf
125 }
126 }
127 }
128
129 char errbuf[128];
130 const char *errbuf_ptr = errbuf;
131
132 if (av_strerror(err, errbuf, sizeof(errbuf)) < 0) {
133 errbuf_ptr = strerror(AVUNERROR(err));
134 }
135 SkDebugf("%s\n", errbuf_ptr);
136 return true;
137}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1

◆ compute_transfer()

static skcms_TransferFunction compute_transfer ( AVColorTransferCharacteristic  t)
static

Definition at line 49 of file SkVideoDecoder.cpp.

49 {
50 const av_transfer_characteristics* av = &gTransfer[AVCOL_TRC_BT709];
51 if ((unsigned)t < AVCOL_TRC_NB) {
52 av = &gTransfer[t];
53 }
54 if (av->alpha == 0) {
55 av = &gTransfer[AVCOL_TRC_BT709];
56 }
57
58 skcms_TransferFunction linear_to_encoded = {
59 av->gamma, std::pow(av->alpha, 1/av->gamma), 0, av->delta, av->beta, 1 - av->alpha, 0,
60 };
61 skcms_TransferFunction encoded_to_linear;
62 bool success = skcms_TransferFunction_invert(&linear_to_encoded, &encoded_to_linear);
63 SkASSERT(success);
64
65 return encoded_to_linear;
66}
#define SkASSERT(cond)
Definition SkAssert.h:116
const av_transfer_characteristics gTransfer[AVCOL_TRC_NB]
bool skcms_TransferFunction_invert(const skcms_TransferFunction *src, skcms_TransferFunction *dst)
Definition skcms.cc:1863

◆ get_yuvspace()

static SkYUVColorSpace get_yuvspace ( AVColorSpace  space)
static

Definition at line 16 of file SkVideoDecoder.cpp.

16 {
17 // this is pretty incomplete -- TODO: look to convert more AVColorSpaces
18 switch (space) {
19 case AVCOL_SPC_RGB: return kIdentity_SkYUVColorSpace;
20 case AVCOL_SPC_BT709: return kRec709_SkYUVColorSpace;
21 case AVCOL_SPC_SMPTE170M:
22 case AVCOL_SPC_SMPTE240M:
23 case AVCOL_SPC_BT470BG: return kRec601_SkYUVColorSpace;
24 default: break;
25 }
27}
@ kRec601_SkYUVColorSpace
Definition SkImageInfo.h:99
@ kRec709_SkYUVColorSpace
@ kIdentity_SkYUVColorSpace
maps Y->R, U->G, V->B
Definition SkImageInfo.h:93

◆ make_colorspace()

sk_sp< SkColorSpace > make_colorspace ( AVColorPrimaries  primaries,
AVColorTransferCharacteristic  transfer 
)

Definition at line 99 of file SkVideoDecoder.cpp.

100 {
101 if (primaries == AVCOL_PRI_BT709 && transfer == AVCOL_TRC_BT709) {
102 return SkColorSpace::MakeSRGB();
103 }
104
106 if ((unsigned)primaries < (unsigned)AVCOL_PRI_NB) {
107 p = &gPrimaries[primaries];
108 }
109
111 p->toXYZD50(&matrix);
112 return SkColorSpace::MakeRGB(compute_transfer(transfer), matrix);
113}
static skcms_TransferFunction compute_transfer(AVColorTransferCharacteristic t)
const SkColorSpacePrimaries gPrimaries[AVCOL_PRI_NB]
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkColorSpace > MakeRGB(const skcms_TransferFunction &transferFn, const skcms_Matrix3x3 &toXYZ)
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258

◆ make_yuv_420()

static sk_sp< SkImage > make_yuv_420 ( GrRecordingContext rContext,
int  w,
int  h,
uint8_t *const  data[],
int const  strides[],
SkYUVColorSpace  yuvSpace,
sk_sp< SkColorSpace cs 
)
static

Definition at line 165 of file SkVideoDecoder.cpp.

170 {
171 SkYUVAInfo yuvaInfo({w, h},
174 yuvSpace);
175 SkPixmap pixmaps[3];
176 pixmaps[0].reset(SkImageInfo::MakeA8(w, h), data[0], strides[0]);
177 w = (w + 1)/2;
178 h = (h + 1)/2;
179 pixmaps[1].reset(SkImageInfo::MakeA8(w, h), data[1], strides[1]);
180 pixmaps[2].reset(SkImageInfo::MakeA8(w, h), data[2], strides[2]);
181 auto yuvaPixmaps = SkYUVAPixmaps::FromExternalPixmaps(yuvaInfo, pixmaps);
182
184 rContext, yuvaPixmaps, skgpu::Mipmapped::kNo, false, std::move(cs));
185}
void reset()
Definition SkPixmap.cpp:32
@ kY_U_V
Plane 0: Y, Plane 1: U, Plane 2: V.
@ k420
1 set of UV values for each 2x2 block of Y values.
static SkYUVAPixmaps FromExternalPixmaps(const SkYUVAInfo &, const SkPixmap[kMaxPlanes])
SK_API sk_sp< SkImage > TextureFromYUVAPixmaps(GrRecordingContext *context, const SkYUVAPixmaps &pixmaps, skgpu::Mipmapped buildMips, bool limitToMaxTextureSize, sk_sp< SkColorSpace > imageColorSpace)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
SkScalar w
SkScalar h
static SkImageInfo MakeA8(int width, int height)

◆ skstream_read_packet()

static int skstream_read_packet ( void *  ctx,
uint8_t *  dstBuffer,
int  dstSize 
)
static

Definition at line 139 of file SkVideoDecoder.cpp.

139 {
140 SkStream* stream = (SkStream*)ctx;
141 int result = (int)stream->read(dstBuffer, dstSize);
142 if (result == 0) {
143 result = AVERROR_EOF;
144 }
145 return result;
146}
Type::kYUV Type::kRGBA() int(0.7 *637)
GAsyncResult * result

◆ skstream_seek_packet()

static int64_t skstream_seek_packet ( void *  ctx,
int64_t  pos,
int  whence 
)
static

Definition at line 148 of file SkVideoDecoder.cpp.

148 {
149 SkStream* stream = (SkStream*)ctx;
150 switch (whence) {
151 case SEEK_SET:
152 break;
153 case SEEK_CUR:
154 pos = (int64_t)stream->getPosition() + pos;
155 break;
156 case SEEK_END:
157 pos = (int64_t)stream->getLength() + pos;
158 break;
159 default:
160 return -1;
161 }
162 return stream->seek(SkToSizeT(pos)) ? pos : -1;
163}
SkPoint pos
constexpr size_t SkToSizeT(S x)
Definition SkTo.h:31

Variable Documentation

◆ gPrimaries

const SkColorSpacePrimaries gPrimaries[AVCOL_PRI_NB]
Initial value:
= {
[AVCOL_PRI_BT709] = { 0.640f, 0.330f, 0.300f, 0.600f, 0.150f, 0.060f, ExpandWP(WP_D65) },
[AVCOL_PRI_BT470M] = { 0.670f, 0.330f, 0.210f, 0.710f, 0.140f, 0.080f, ExpandWP(WP_C) },
[AVCOL_PRI_BT470BG] = { 0.640f, 0.330f, 0.290f, 0.600f, 0.150f, 0.060f, ExpandWP(WP_D65) },
[AVCOL_PRI_SMPTE170M] = { 0.630f, 0.340f, 0.310f, 0.595f, 0.155f, 0.070f, ExpandWP(WP_D65) },
[AVCOL_PRI_SMPTE240M] = { 0.630f, 0.340f, 0.310f, 0.595f, 0.155f, 0.070f, ExpandWP(WP_D65) },
[AVCOL_PRI_SMPTE428] = { 0.735f, 0.265f, 0.274f, 0.718f, 0.167f, 0.009f, ExpandWP(WP_E) },
[AVCOL_PRI_SMPTE431] = { 0.680f, 0.320f, 0.265f, 0.690f, 0.150f, 0.060f, ExpandWP(WP_DCI) },
[AVCOL_PRI_SMPTE432] = { 0.680f, 0.320f, 0.265f, 0.690f, 0.150f, 0.060f, ExpandWP(WP_D65) },
[AVCOL_PRI_FILM] = { 0.681f, 0.319f, 0.243f, 0.692f, 0.145f, 0.049f, ExpandWP(WP_C) },
[AVCOL_PRI_BT2020] = { 0.708f, 0.292f, 0.170f, 0.797f, 0.131f, 0.046f, ExpandWP(WP_D65) },
[AVCOL_PRI_JEDEC_P22] = { 0.630f, 0.340f, 0.295f, 0.605f, 0.155f, 0.077f, ExpandWP(WP_D65) },
}
#define ExpandWP(index)

Definition at line 85 of file SkVideoDecoder.cpp.

85 {
86 [AVCOL_PRI_BT709] = { 0.640f, 0.330f, 0.300f, 0.600f, 0.150f, 0.060f, ExpandWP(WP_D65) },
87 [AVCOL_PRI_BT470M] = { 0.670f, 0.330f, 0.210f, 0.710f, 0.140f, 0.080f, ExpandWP(WP_C) },
88 [AVCOL_PRI_BT470BG] = { 0.640f, 0.330f, 0.290f, 0.600f, 0.150f, 0.060f, ExpandWP(WP_D65) },
89 [AVCOL_PRI_SMPTE170M] = { 0.630f, 0.340f, 0.310f, 0.595f, 0.155f, 0.070f, ExpandWP(WP_D65) },
90 [AVCOL_PRI_SMPTE240M] = { 0.630f, 0.340f, 0.310f, 0.595f, 0.155f, 0.070f, ExpandWP(WP_D65) },
91 [AVCOL_PRI_SMPTE428] = { 0.735f, 0.265f, 0.274f, 0.718f, 0.167f, 0.009f, ExpandWP(WP_E) },
92 [AVCOL_PRI_SMPTE431] = { 0.680f, 0.320f, 0.265f, 0.690f, 0.150f, 0.060f, ExpandWP(WP_DCI) },
93 [AVCOL_PRI_SMPTE432] = { 0.680f, 0.320f, 0.265f, 0.690f, 0.150f, 0.060f, ExpandWP(WP_D65) },
94 [AVCOL_PRI_FILM] = { 0.681f, 0.319f, 0.243f, 0.692f, 0.145f, 0.049f, ExpandWP(WP_C) },
95 [AVCOL_PRI_BT2020] = { 0.708f, 0.292f, 0.170f, 0.797f, 0.131f, 0.046f, ExpandWP(WP_D65) },
96 [AVCOL_PRI_JEDEC_P22] = { 0.630f, 0.340f, 0.295f, 0.605f, 0.155f, 0.077f, ExpandWP(WP_D65) },
97};

◆ gTransfer

const av_transfer_characteristics gTransfer[AVCOL_TRC_NB]
Initial value:
= {
[AVCOL_TRC_BT709] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_GAMMA22] = { 1.0, 0.0, 1.0 / 2.2, 0.0 },
[AVCOL_TRC_GAMMA28] = { 1.0, 0.0, 1.0 / 2.8, 0.0 },
[AVCOL_TRC_SMPTE170M] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_SMPTE240M] = { 1.1115, 0.0228, 0.45, 4.0 },
[AVCOL_TRC_IEC61966_2_1] = { 1.055, 0.0031308, 1.0 / 2.4, 12.92 },
[AVCOL_TRC_IEC61966_2_4] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_10] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_12] = { 1.0993, 0.0181, 0.45, 4.5 },
}

Definition at line 37 of file SkVideoDecoder.cpp.

37 {
38 [AVCOL_TRC_BT709] = { 1.099, 0.018, 0.45, 4.5 },
39 [AVCOL_TRC_GAMMA22] = { 1.0, 0.0, 1.0 / 2.2, 0.0 },
40 [AVCOL_TRC_GAMMA28] = { 1.0, 0.0, 1.0 / 2.8, 0.0 },
41 [AVCOL_TRC_SMPTE170M] = { 1.099, 0.018, 0.45, 4.5 },
42 [AVCOL_TRC_SMPTE240M] = { 1.1115, 0.0228, 0.45, 4.0 },
43 [AVCOL_TRC_IEC61966_2_1] = { 1.055, 0.0031308, 1.0 / 2.4, 12.92 },
44 [AVCOL_TRC_IEC61966_2_4] = { 1.099, 0.018, 0.45, 4.5 },
45 [AVCOL_TRC_BT2020_10] = { 1.099, 0.018, 0.45, 4.5 },
46 [AVCOL_TRC_BT2020_12] = { 1.0993, 0.0181, 0.45, 4.5 },
47};

◆ gWP

const SkPoint gWP[WP_NB]
Initial value:
= {
[WP_D65] = { 0.3127f, 0.3290f },
[WP_C] = { 0.3100f, 0.3160f },
[WP_DCI] = { 0.3140f, 0.3510f },
[WP_E] = { 1/3.0f, 1/3.0f },
}

Definition at line 76 of file SkVideoDecoder.cpp.

76 {
77 [WP_D65] = { 0.3127f, 0.3290f },
78 [WP_C] = { 0.3100f, 0.3160f },
79 [WP_DCI] = { 0.3140f, 0.3510f },
80 [WP_E] = { 1/3.0f, 1/3.0f },
81};