diff options
author | qinxialei <xialeiqin@gmail.com> | 2020-10-29 11:26:59 +0800 |
---|---|---|
committer | qinxialei <xialeiqin@gmail.com> | 2020-10-29 11:26:59 +0800 |
commit | e8d277081293b6fb2a5d469616baaa7a06f52496 (patch) | |
tree | 1179bb07d3927d1837d4a90bd81b2034c4c696a9 /src/gav1 | |
download | libgav1-e8d277081293b6fb2a5d469616baaa7a06f52496.tar.gz libgav1-e8d277081293b6fb2a5d469616baaa7a06f52496.tar.bz2 libgav1-e8d277081293b6fb2a5d469616baaa7a06f52496.zip |
Import Upstream version 0.16.0
Diffstat (limited to 'src/gav1')
-rw-r--r-- | src/gav1/decoder.h | 148 | ||||
-rw-r--r-- | src/gav1/decoder_buffer.h | 279 | ||||
-rw-r--r-- | src/gav1/decoder_settings.h | 144 | ||||
-rw-r--r-- | src/gav1/frame_buffer.h | 177 | ||||
-rw-r--r-- | src/gav1/status_code.h | 118 | ||||
-rw-r--r-- | src/gav1/symbol_visibility.h | 88 | ||||
-rw-r--r-- | src/gav1/version.h | 71 |
7 files changed, 1025 insertions, 0 deletions
diff --git a/src/gav1/decoder.h b/src/gav1/decoder.h new file mode 100644 index 0000000..da08da9 --- /dev/null +++ b/src/gav1/decoder.h @@ -0,0 +1,148 @@ +/* + * Copyright 2019 The libgav1 Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBGAV1_SRC_GAV1_DECODER_H_ +#define LIBGAV1_SRC_GAV1_DECODER_H_ + +#if defined(__cplusplus) +#include <cstddef> +#include <cstdint> +#include <memory> +#else +#include <stddef.h> +#include <stdint.h> +#endif // defined(__cplusplus) + +// IWYU pragma: begin_exports +#include "gav1/decoder_buffer.h" +#include "gav1/decoder_settings.h" +#include "gav1/frame_buffer.h" +#include "gav1/status_code.h" +#include "gav1/symbol_visibility.h" +#include "gav1/version.h" +// IWYU pragma: end_exports + +#if defined(__cplusplus) +extern "C" { +#endif + +struct Libgav1Decoder; +typedef struct Libgav1Decoder Libgav1Decoder; + +LIBGAV1_PUBLIC Libgav1StatusCode Libgav1DecoderCreate( + const Libgav1DecoderSettings* settings, Libgav1Decoder** decoder_out); + +LIBGAV1_PUBLIC void Libgav1DecoderDestroy(Libgav1Decoder* decoder); + +LIBGAV1_PUBLIC Libgav1StatusCode Libgav1DecoderEnqueueFrame( + Libgav1Decoder* decoder, const uint8_t* data, size_t size, + int64_t user_private_data, void* buffer_private_data); + +LIBGAV1_PUBLIC Libgav1StatusCode Libgav1DecoderDequeueFrame( + Libgav1Decoder* decoder, const Libgav1DecoderBuffer** out_ptr); + +LIBGAV1_PUBLIC Libgav1StatusCode +Libgav1DecoderSignalEOS(Libgav1Decoder* decoder); + +LIBGAV1_PUBLIC int Libgav1DecoderGetMaxBitdepth(void); + +#if defined(__cplusplus) +} // extern "C" + +namespace libgav1 { + +// Forward declaration. +class DecoderImpl; + +class LIBGAV1_PUBLIC Decoder { + public: + Decoder(); + ~Decoder(); + + // Init must be called exactly once per instance. Subsequent calls will do + // nothing. If |settings| is nullptr, the decoder will be initialized with + // default settings. Returns kStatusOk on success, an error status otherwise. + StatusCode Init(const DecoderSettings* settings); + + // Enqueues a compressed frame to be decoded. + // + // This function returns: + // * kStatusOk on success + // * kStatusTryAgain if the decoder queue is full + // * an error status otherwise. + // + // |user_private_data| may be used to associate application specific private + // data with the compressed frame. It will be copied to the user_private_data + // field of the DecoderBuffer returned by the corresponding |DequeueFrame()| + // call. + // + // NOTE: |EnqueueFrame()| does not copy the data. Therefore, after a + // successful |EnqueueFrame()| call, the caller must keep the |data| buffer + // alive until: + // 1) If |settings_.release_input_buffer| is not nullptr, then |data| buffer + // must be kept alive until release_input_buffer is called with the + // |buffer_private_data| passed into this EnqueueFrame call. + // 2) If |settings_.release_input_buffer| is nullptr, then |data| buffer must + // be kept alive until the corresponding DequeueFrame() call is completed. + // + // If the call to |EnqueueFrame()| is not successful, then libgav1 will not + // hold any references to the |data| buffer. |settings_.release_input_buffer| + // callback will not be called in that case. + StatusCode EnqueueFrame(const uint8_t* data, size_t size, + int64_t user_private_data, void* buffer_private_data); + + // Dequeues a decompressed frame. If there are enqueued compressed frames, + // decodes one and sets |*out_ptr| to the last displayable frame in the + // compressed frame. If there are no displayable frames available, sets + // |*out_ptr| to nullptr. + // + // Returns kStatusOk on success. Returns kStatusNothingToDequeue if there are + // no enqueued frames (in this case out_ptr will always be set to nullptr). + // Returns one of the other error statuses if there is an error. + // + // If |settings_.blocking_dequeue| is false and the decoder is operating in + // frame parallel mode (|settings_.frame_parallel| is true and the video + // stream passes the decoder's heuristics for enabling frame parallel mode), + // then this call will return kStatusTryAgain if an enqueued frame is not yet + // decoded (it is a non blocking call in this case). In all other cases, this + // call will block until an enqueued frame has been decoded. + StatusCode DequeueFrame(const DecoderBuffer** out_ptr); + + // Signals the end of stream. + // + // In non-frame-parallel mode, this function will release all the frames held + // by the decoder. If the frame buffers were allocated by libgav1, then the + // pointer obtained by the prior DequeueFrame call will no longer be valid. If + // the frame buffers were allocated by the application, then any references + // that libgav1 is holding on to will be released. + // + // Once this function returns successfully, the decoder state will be reset + // and the decoder is ready to start decoding a new coded video sequence. + StatusCode SignalEOS(); + + // Returns the maximum bitdepth that is supported by this decoder. + static int GetMaxBitdepth(); + + private: + DecoderSettings settings_; + // The object is initialized if and only if impl_ != nullptr. + std::unique_ptr<DecoderImpl> impl_; +}; + +} // namespace libgav1 +#endif // defined(__cplusplus) + +#endif // LIBGAV1_SRC_GAV1_DECODER_H_ diff --git a/src/gav1/decoder_buffer.h b/src/gav1/decoder_buffer.h new file mode 100644 index 0000000..37bcb29 --- /dev/null +++ b/src/gav1/decoder_buffer.h @@ -0,0 +1,279 @@ +/* + * Copyright 2019 The libgav1 Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBGAV1_SRC_GAV1_DECODER_BUFFER_H_ +#define LIBGAV1_SRC_GAV1_DECODER_BUFFER_H_ + +#if defined(__cplusplus) +#include <cstdint> +#else +#include <stdint.h> +#endif // defined(__cplusplus) + +#include "gav1/symbol_visibility.h" + +// All the declarations in this file are part of the public ABI. + +// The documentation for the enum values in this file can be found in Section +// 6.4.2 of the AV1 spec. + +typedef enum Libgav1ChromaSamplePosition { + kLibgav1ChromaSamplePositionUnknown, + kLibgav1ChromaSamplePositionVertical, + kLibgav1ChromaSamplePositionColocated, + kLibgav1ChromaSamplePositionReserved +} Libgav1ChromaSamplePosition; + +typedef enum Libgav1ImageFormat { + kLibgav1ImageFormatYuv420, + kLibgav1ImageFormatYuv422, + kLibgav1ImageFormatYuv444, + kLibgav1ImageFormatMonochrome400 +} Libgav1ImageFormat; + +typedef enum Libgav1ColorPrimary { + // 0 is reserved. + kLibgav1ColorPrimaryBt709 = 1, + kLibgav1ColorPrimaryUnspecified, + // 3 is reserved. + kLibgav1ColorPrimaryBt470M = 4, + kLibgav1ColorPrimaryBt470Bg, + kLibgav1ColorPrimaryBt601, + kLibgav1ColorPrimarySmpte240, + kLibgav1ColorPrimaryGenericFilm, + kLibgav1ColorPrimaryBt2020, + kLibgav1ColorPrimaryXyz, + kLibgav1ColorPrimarySmpte431, + kLibgav1ColorPrimarySmpte432, + // 13-21 are reserved. + kLibgav1ColorPrimaryEbu3213 = 22, + // 23-254 are reserved. + kLibgav1MaxColorPrimaries = 255 +} Libgav1ColorPrimary; + +typedef enum Libgav1TransferCharacteristics { + // 0 is reserved. + kLibgav1TransferCharacteristicsBt709 = 1, + kLibgav1TransferCharacteristicsUnspecified, + // 3 is reserved. + kLibgav1TransferCharacteristicsBt470M = 4, + kLibgav1TransferCharacteristicsBt470Bg, + kLibgav1TransferCharacteristicsBt601, + kLibgav1TransferCharacteristicsSmpte240, + kLibgav1TransferCharacteristicsLinear, + kLibgav1TransferCharacteristicsLog100, + kLibgav1TransferCharacteristicsLog100Sqrt10, + kLibgav1TransferCharacteristicsIec61966, + kLibgav1TransferCharacteristicsBt1361, + kLibgav1TransferCharacteristicsSrgb, + kLibgav1TransferCharacteristicsBt2020TenBit, + kLibgav1TransferCharacteristicsBt2020TwelveBit, + kLibgav1TransferCharacteristicsSmpte2084, + kLibgav1TransferCharacteristicsSmpte428, + kLibgav1TransferCharacteristicsHlg, + // 19-254 are reserved. + kLibgav1MaxTransferCharacteristics = 255 +} Libgav1TransferCharacteristics; + +typedef enum Libgav1MatrixCoefficients { + kLibgav1MatrixCoefficientsIdentity, + kLibgav1MatrixCoefficientsBt709, + kLibgav1MatrixCoefficientsUnspecified, + // 3 is reserved. + kLibgav1MatrixCoefficientsFcc = 4, + kLibgav1MatrixCoefficientsBt470BG, + kLibgav1MatrixCoefficientsBt601, + kLibgav1MatrixCoefficientsSmpte240, + kLibgav1MatrixCoefficientsSmpteYcgco, + kLibgav1MatrixCoefficientsBt2020Ncl, + kLibgav1MatrixCoefficientsBt2020Cl, + kLibgav1MatrixCoefficientsSmpte2085, + kLibgav1MatrixCoefficientsChromatNcl, + kLibgav1MatrixCoefficientsChromatCl, + kLibgav1MatrixCoefficientsIctcp, + // 15-254 are reserved. + kLibgav1MaxMatrixCoefficients = 255 +} Libgav1MatrixCoefficients; + +typedef enum Libgav1ColorRange { + // The color ranges are scaled by value << (bitdepth - 8) for 10 and 12bit + // streams. + kLibgav1ColorRangeStudio, // Y [16..235], UV [16..240] + kLibgav1ColorRangeFull // YUV/RGB [0..255] +} Libgav1ColorRange; + +typedef struct Libgav1DecoderBuffer { +#if defined(__cplusplus) + LIBGAV1_PUBLIC int NumPlanes() const { + return (image_format == kLibgav1ImageFormatMonochrome400) ? 1 : 3; + } +#endif // defined(__cplusplus) + + Libgav1ChromaSamplePosition chroma_sample_position; + Libgav1ImageFormat image_format; + Libgav1ColorRange color_range; + Libgav1ColorPrimary color_primary; + Libgav1TransferCharacteristics transfer_characteristics; + Libgav1MatrixCoefficients matrix_coefficients; + + // Image storage dimensions. + // NOTE: These fields are named w and h in vpx_image_t and aom_image_t. + // uint32_t width; // Stored image width. + // uint32_t height; // Stored image height. + int bitdepth; // Stored image bitdepth. + + // Image display dimensions. + // NOTES: + // 1. These fields are named d_w and d_h in vpx_image_t and aom_image_t. + // 2. libvpx and libaom clients use d_w and d_h much more often than w and h. + // 3. These fields can just be stored for the Y plane and the clients can + // calculate the values for the U and V planes if the image format or + // subsampling is exposed. + int displayed_width[3]; // Displayed image width. + int displayed_height[3]; // Displayed image height. + + int stride[3]; + uint8_t* plane[3]; + + // Spatial id of this frame. + int spatial_id; + // Temporal id of this frame. + int temporal_id; + + // The |user_private_data| argument passed to Decoder::EnqueueFrame(). + int64_t user_private_data; + // The |private_data| field of FrameBuffer. Set by the get frame buffer + // callback when it allocates a frame buffer. + void* buffer_private_data; +} Libgav1DecoderBuffer; + +#if defined(__cplusplus) +namespace libgav1 { + +using ChromaSamplePosition = Libgav1ChromaSamplePosition; +constexpr ChromaSamplePosition kChromaSamplePositionUnknown = + kLibgav1ChromaSamplePositionUnknown; +constexpr ChromaSamplePosition kChromaSamplePositionVertical = + kLibgav1ChromaSamplePositionVertical; +constexpr ChromaSamplePosition kChromaSamplePositionColocated = + kLibgav1ChromaSamplePositionColocated; +constexpr ChromaSamplePosition kChromaSamplePositionReserved = + kLibgav1ChromaSamplePositionReserved; + +using ImageFormat = Libgav1ImageFormat; +constexpr ImageFormat kImageFormatYuv420 = kLibgav1ImageFormatYuv420; +constexpr ImageFormat kImageFormatYuv422 = kLibgav1ImageFormatYuv422; +constexpr ImageFormat kImageFormatYuv444 = kLibgav1ImageFormatYuv444; +constexpr ImageFormat kImageFormatMonochrome400 = + kLibgav1ImageFormatMonochrome400; + +using ColorPrimary = Libgav1ColorPrimary; +constexpr ColorPrimary kColorPrimaryBt709 = kLibgav1ColorPrimaryBt709; +constexpr ColorPrimary kColorPrimaryUnspecified = + kLibgav1ColorPrimaryUnspecified; +constexpr ColorPrimary kColorPrimaryBt470M = kLibgav1ColorPrimaryBt470M; +constexpr ColorPrimary kColorPrimaryBt470Bg = kLibgav1ColorPrimaryBt470Bg; +constexpr ColorPrimary kColorPrimaryBt601 = kLibgav1ColorPrimaryBt601; +constexpr ColorPrimary kColorPrimarySmpte240 = kLibgav1ColorPrimarySmpte240; +constexpr ColorPrimary kColorPrimaryGenericFilm = + kLibgav1ColorPrimaryGenericFilm; +constexpr ColorPrimary kColorPrimaryBt2020 = kLibgav1ColorPrimaryBt2020; +constexpr ColorPrimary kColorPrimaryXyz = kLibgav1ColorPrimaryXyz; +constexpr ColorPrimary kColorPrimarySmpte431 = kLibgav1ColorPrimarySmpte431; +constexpr ColorPrimary kColorPrimarySmpte432 = kLibgav1ColorPrimarySmpte432; +constexpr ColorPrimary kColorPrimaryEbu3213 = kLibgav1ColorPrimaryEbu3213; +constexpr ColorPrimary kMaxColorPrimaries = kLibgav1MaxColorPrimaries; + +using TransferCharacteristics = Libgav1TransferCharacteristics; +constexpr TransferCharacteristics kTransferCharacteristicsBt709 = + kLibgav1TransferCharacteristicsBt709; +constexpr TransferCharacteristics kTransferCharacteristicsUnspecified = + kLibgav1TransferCharacteristicsUnspecified; +constexpr TransferCharacteristics kTransferCharacteristicsBt470M = + kLibgav1TransferCharacteristicsBt470M; +constexpr TransferCharacteristics kTransferCharacteristicsBt470Bg = + kLibgav1TransferCharacteristicsBt470Bg; +constexpr TransferCharacteristics kTransferCharacteristicsBt601 = + kLibgav1TransferCharacteristicsBt601; +constexpr TransferCharacteristics kTransferCharacteristicsSmpte240 = + kLibgav1TransferCharacteristicsSmpte240; +constexpr TransferCharacteristics kTransferCharacteristicsLinear = + kLibgav1TransferCharacteristicsLinear; +constexpr TransferCharacteristics kTransferCharacteristicsLog100 = + kLibgav1TransferCharacteristicsLog100; +constexpr TransferCharacteristics kTransferCharacteristicsLog100Sqrt10 = + kLibgav1TransferCharacteristicsLog100Sqrt10; +constexpr TransferCharacteristics kTransferCharacteristicsIec61966 = + kLibgav1TransferCharacteristicsIec61966; +constexpr TransferCharacteristics kTransferCharacteristicsBt1361 = + kLibgav1TransferCharacteristicsBt1361; +constexpr TransferCharacteristics kTransferCharacteristicsSrgb = + kLibgav1TransferCharacteristicsSrgb; +constexpr TransferCharacteristics kTransferCharacteristicsBt2020TenBit = + kLibgav1TransferCharacteristicsBt2020TenBit; +constexpr TransferCharacteristics kTransferCharacteristicsBt2020TwelveBit = + kLibgav1TransferCharacteristicsBt2020TwelveBit; +constexpr TransferCharacteristics kTransferCharacteristicsSmpte2084 = + kLibgav1TransferCharacteristicsSmpte2084; +constexpr TransferCharacteristics kTransferCharacteristicsSmpte428 = + kLibgav1TransferCharacteristicsSmpte428; +constexpr TransferCharacteristics kTransferCharacteristicsHlg = + kLibgav1TransferCharacteristicsHlg; +constexpr TransferCharacteristics kMaxTransferCharacteristics = + kLibgav1MaxTransferCharacteristics; + +using MatrixCoefficients = Libgav1MatrixCoefficients; +constexpr MatrixCoefficients kMatrixCoefficientsIdentity = + kLibgav1MatrixCoefficientsIdentity; +constexpr MatrixCoefficients kMatrixCoefficientsBt709 = + kLibgav1MatrixCoefficientsBt709; +constexpr MatrixCoefficients kMatrixCoefficientsUnspecified = + kLibgav1MatrixCoefficientsUnspecified; +constexpr MatrixCoefficients kMatrixCoefficientsFcc = + kLibgav1MatrixCoefficientsFcc; +constexpr MatrixCoefficients kMatrixCoefficientsBt470BG = + kLibgav1MatrixCoefficientsBt470BG; +constexpr MatrixCoefficients kMatrixCoefficientsBt601 = + kLibgav1MatrixCoefficientsBt601; +constexpr MatrixCoefficients kMatrixCoefficientsSmpte240 = + kLibgav1MatrixCoefficientsSmpte240; +constexpr MatrixCoefficients kMatrixCoefficientsSmpteYcgco = + kLibgav1MatrixCoefficientsSmpteYcgco; +constexpr MatrixCoefficients kMatrixCoefficientsBt2020Ncl = + kLibgav1MatrixCoefficientsBt2020Ncl; +constexpr MatrixCoefficients kMatrixCoefficientsBt2020Cl = + kLibgav1MatrixCoefficientsBt2020Cl; +constexpr MatrixCoefficients kMatrixCoefficientsSmpte2085 = + kLibgav1MatrixCoefficientsSmpte2085; +constexpr MatrixCoefficients kMatrixCoefficientsChromatNcl = + kLibgav1MatrixCoefficientsChromatNcl; +constexpr MatrixCoefficients kMatrixCoefficientsChromatCl = + kLibgav1MatrixCoefficientsChromatCl; +constexpr MatrixCoefficients kMatrixCoefficientsIctcp = + kLibgav1MatrixCoefficientsIctcp; +constexpr MatrixCoefficients kMaxMatrixCoefficients = + kLibgav1MaxMatrixCoefficients; + +using ColorRange = Libgav1ColorRange; +constexpr ColorRange kColorRangeStudio = kLibgav1ColorRangeStudio; +constexpr ColorRange kColorRangeFull = kLibgav1ColorRangeFull; + +using DecoderBuffer = Libgav1DecoderBuffer; + +} // namespace libgav1 +#endif // defined(__cplusplus) + +#endif // LIBGAV1_SRC_GAV1_DECODER_BUFFER_H_ diff --git a/src/gav1/decoder_settings.h b/src/gav1/decoder_settings.h new file mode 100644 index 0000000..ab22a4d --- /dev/null +++ b/src/gav1/decoder_settings.h @@ -0,0 +1,144 @@ +/* + * Copyright 2019 The libgav1 Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBGAV1_SRC_GAV1_DECODER_SETTINGS_H_ +#define LIBGAV1_SRC_GAV1_DECODER_SETTINGS_H_ + +#if defined(__cplusplus) +#include <cstdint> +#else +#include <stdint.h> +#endif // defined(__cplusplus) + +#include "gav1/frame_buffer.h" +#include "gav1/symbol_visibility.h" + +// All the declarations in this file are part of the public ABI. + +#if defined(__cplusplus) +extern "C" { +#endif + +// This callback is invoked by the decoder when it is done using an input frame +// buffer. When frame_parallel is set to true, this callback must not be +// nullptr. Otherwise, this callback is optional. +// +// |buffer_private_data| is the value passed in the EnqueueFrame() call. +typedef void (*Libgav1ReleaseInputBufferCallback)(void* callback_private_data, + void* buffer_private_data); + +typedef struct Libgav1DecoderSettings { + // Number of threads to use when decoding. Must be greater than 0. The library + // will create at most |threads| new threads. Defaults to 1 (no new threads + // will be created). + int threads; + // A boolean. Indicate to the decoder that frame parallel decoding is allowed. + // Note that this is just a request and the decoder will decide the number of + // frames to be decoded in parallel based on the video stream being decoded. + int frame_parallel; + // A boolean. In frame parallel mode, should Libgav1DecoderDequeueFrame wait + // until a enqueued frame is available for dequeueing. + // + // If frame_parallel is 0, this setting is ignored. + int blocking_dequeue; + // Called when the first sequence header or a sequence header with a + // different frame size (which includes bitdepth, monochrome, subsampling_x, + // subsampling_y, maximum frame width, or maximum frame height) is received. + Libgav1FrameBufferSizeChangedCallback on_frame_buffer_size_changed; + // Get frame buffer callback. + Libgav1GetFrameBufferCallback get_frame_buffer; + // Release frame buffer callback. + Libgav1ReleaseFrameBufferCallback release_frame_buffer; + // Release input frame buffer callback. + Libgav1ReleaseInputBufferCallback release_input_buffer; + // Passed as the private_data argument to the callbacks. + void* callback_private_data; + // A boolean. If set to 1, the decoder will output all the spatial and + // temporal layers. + int output_all_layers; + // Index of the operating point to decode. + int operating_point; + // Mask indicating the post processing filters that need to be applied to the + // reconstructed frame. Note this is an advanced setting and does not + // typically need to be changed. + // From LSB: + // Bit 0: Loop filter (deblocking filter). + // Bit 1: Cdef. + // Bit 2: SuperRes. + // Bit 3: Loop restoration. + // Bit 4: Film grain synthesis. + // All the bits other than the last 5 are ignored. + uint8_t post_filter_mask; +} Libgav1DecoderSettings; + +LIBGAV1_PUBLIC void Libgav1DecoderSettingsInitDefault( + Libgav1DecoderSettings* settings); + +#if defined(__cplusplus) +} // extern "C" + +namespace libgav1 { + +using ReleaseInputBufferCallback = Libgav1ReleaseInputBufferCallback; + +// Applications must populate this structure before creating a decoder instance. +struct DecoderSettings { + // Number of threads to use when decoding. Must be greater than 0. The library + // will create at most |threads| new threads. Defaults to 1 (no new threads + // will be created). + int threads = 1; + // Indicate to the decoder that frame parallel decoding is allowed. Note that + // this is just a request and the decoder will decide the number of frames to + // be decoded in parallel based on the video stream being decoded. + bool frame_parallel = false; + // In frame parallel mode, should DequeueFrame wait until a enqueued frame is + // available for dequeueing. + // + // If frame_parallel is false, this setting is ignored. + bool blocking_dequeue = false; + // Called when the first sequence header or a sequence header with a + // different frame size (which includes bitdepth, monochrome, subsampling_x, + // subsampling_y, maximum frame width, or maximum frame height) is received. + FrameBufferSizeChangedCallback on_frame_buffer_size_changed = nullptr; + // Get frame buffer callback. + GetFrameBufferCallback get_frame_buffer = nullptr; + // Release frame buffer callback. + ReleaseFrameBufferCallback release_frame_buffer = nullptr; + // Release input frame buffer callback. + ReleaseInputBufferCallback release_input_buffer = nullptr; + // Passed as the private_data argument to the callbacks. + void* callback_private_data = nullptr; + // If set to true, the decoder will output all the spatial and temporal + // layers. + bool output_all_layers = false; + // Index of the operating point to decode. + int operating_point = 0; + // Mask indicating the post processing filters that need to be applied to the + // reconstructed frame. Note this is an advanced setting and does not + // typically need to be changed. + // From LSB: + // Bit 0: Loop filter (deblocking filter). + // Bit 1: Cdef. + // Bit 2: SuperRes. + // Bit 3: Loop restoration. + // Bit 4: Film grain synthesis. + // All the bits other than the last 5 are ignored. + uint8_t post_filter_mask = 0x1f; +}; + +} // namespace libgav1 +#endif // defined(__cplusplus) +#endif // LIBGAV1_SRC_GAV1_DECODER_SETTINGS_H_ diff --git a/src/gav1/frame_buffer.h b/src/gav1/frame_buffer.h new file mode 100644 index 0000000..8132b61 --- /dev/null +++ b/src/gav1/frame_buffer.h @@ -0,0 +1,177 @@ +/* + * Copyright 2020 The libgav1 Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBGAV1_SRC_GAV1_FRAME_BUFFER_H_ +#define LIBGAV1_SRC_GAV1_FRAME_BUFFER_H_ + +// All the declarations in this file are part of the public ABI. This file may +// be included by both C and C++ files. + +#if defined(__cplusplus) +#include <cstddef> +#include <cstdint> +#else +#include <stddef.h> +#include <stdint.h> +#endif // defined(__cplusplus) + +#include "gav1/decoder_buffer.h" +#include "gav1/status_code.h" +#include "gav1/symbol_visibility.h" + +// The callback functions use the C linkage conventions. +#if defined(__cplusplus) +extern "C" { +#endif + +// This structure represents an allocated frame buffer. +typedef struct Libgav1FrameBuffer { + // In the |plane| and |stride| arrays, the elements at indexes 0, 1, and 2 + // are for the Y, U, and V planes, respectively. + uint8_t* plane[3]; // Pointers to the frame (excluding the borders) in the + // data buffers. + int stride[3]; // Row strides in bytes. + void* private_data; // Frame buffer's private data. Available for use by the + // release frame buffer callback. Also copied to the + // |buffer_private_data| field of DecoderBuffer for use + // by the consumer of a DecoderBuffer. +} Libgav1FrameBuffer; + +// This callback is invoked by the decoder to provide information on the +// subsequent frames in the video, until the next invocation of this callback +// or the end of the video. +// +// |width| and |height| are the maximum frame width and height in pixels. +// |left_border|, |right_border|, |top_border|, and |bottom_border| are the +// maximum left, right, top, and bottom border sizes in pixels. +// |stride_alignment| specifies the alignment of the row stride in bytes. +// +// Returns kLibgav1StatusOk on success, an error status on failure. +// +// NOTE: This callback may be omitted if the information is not useful to the +// application. +typedef Libgav1StatusCode (*Libgav1FrameBufferSizeChangedCallback)( + void* callback_private_data, int bitdepth, Libgav1ImageFormat image_format, + int width, int height, int left_border, int right_border, int top_border, + int bottom_border, int stride_alignment); + +// This callback is invoked by the decoder to allocate a frame buffer, which +// consists of three data buffers, for the Y, U, and V planes, respectively. +// +// The callback must set |frame_buffer->plane[i]| to point to the data buffers +// of the planes, and set |frame_buffer->stride[i]| to the row strides of the +// planes. If |image_format| is kLibgav1ImageFormatMonochrome400, the callback +// should set |frame_buffer->plane[1]| and |frame_buffer->plane[2]| to a null +// pointer and set |frame_buffer->stride[1]| and |frame_buffer->stride[2]| to +// 0. The callback may set |frame_buffer->private_data| to a value that will +// be useful to the release frame buffer callback and the consumer of a +// DecoderBuffer. +// +// Returns kLibgav1StatusOk on success, an error status on failure. + +// |width| and |height| are the frame width and height in pixels. +// |left_border|, |right_border|, |top_border|, and |bottom_border| are the +// left, right, top, and bottom border sizes in pixels. |stride_alignment| +// specifies the alignment of the row stride in bytes. +typedef Libgav1StatusCode (*Libgav1GetFrameBufferCallback)( + void* callback_private_data, int bitdepth, Libgav1ImageFormat image_format, + int width, int height, int left_border, int right_border, int top_border, + int bottom_border, int stride_alignment, Libgav1FrameBuffer* frame_buffer); + +// After a frame buffer is allocated, the decoder starts to write decoded video +// to the frame buffer. When the frame buffer is ready for consumption, it is +// made available to the application in a Decoder::DequeueFrame() call. +// Afterwards, the decoder may continue to use the frame buffer in read-only +// mode. When the decoder is finished using the frame buffer, it notifies the +// application by calling the Libgav1ReleaseFrameBufferCallback. + +// This callback is invoked by the decoder to release a frame buffer. +typedef void (*Libgav1ReleaseFrameBufferCallback)(void* callback_private_data, + void* buffer_private_data); + +// Libgav1ComputeFrameBufferInfo() and Libgav1SetFrameBuffer() are intended to +// help clients implement frame buffer callbacks using memory buffers. First, +// call Libgav1ComputeFrameBufferInfo(). If it succeeds, allocate y_buffer of +// size info.y_buffer_size and allocate u_buffer and v_buffer, both of size +// info.uv_buffer_size. Finally, pass y_buffer, u_buffer, v_buffer, and +// buffer_private_data to Libgav1SetFrameBuffer(). + +// This structure contains information useful for allocating memory for a frame +// buffer. +typedef struct Libgav1FrameBufferInfo { + size_t y_buffer_size; // Size in bytes of the Y buffer. + size_t uv_buffer_size; // Size in bytes of the U or V buffer. + + // The following fields are consumed by Libgav1SetFrameBuffer(). Do not use + // them directly. + int y_stride; // Row stride in bytes of the Y buffer. + int uv_stride; // Row stride in bytes of the U or V buffer. + size_t y_plane_offset; // Offset in bytes of the frame (excluding the + // borders) in the Y buffer. + size_t uv_plane_offset; // Offset in bytes of the frame (excluding the + // borders) in the U or V buffer. + int stride_alignment; // The stride_alignment argument passed to + // Libgav1ComputeFrameBufferInfo(). +} Libgav1FrameBufferInfo; + +// Computes the information useful for allocating memory for a frame buffer. +// On success, stores the output in |info|. +LIBGAV1_PUBLIC Libgav1StatusCode Libgav1ComputeFrameBufferInfo( + int bitdepth, Libgav1ImageFormat image_format, int width, int height, + int left_border, int right_border, int top_border, int bottom_border, + int stride_alignment, Libgav1FrameBufferInfo* info); + +// Sets the |frame_buffer| struct. +LIBGAV1_PUBLIC Libgav1StatusCode Libgav1SetFrameBuffer( + const Libgav1FrameBufferInfo* info, uint8_t* y_buffer, uint8_t* u_buffer, + uint8_t* v_buffer, void* buffer_private_data, + Libgav1FrameBuffer* frame_buffer); + +#if defined(__cplusplus) +} // extern "C" + +// Declare type aliases for C++. +namespace libgav1 { + +using FrameBuffer = Libgav1FrameBuffer; +using FrameBufferSizeChangedCallback = Libgav1FrameBufferSizeChangedCallback; +using GetFrameBufferCallback = Libgav1GetFrameBufferCallback; +using ReleaseFrameBufferCallback = Libgav1ReleaseFrameBufferCallback; +using FrameBufferInfo = Libgav1FrameBufferInfo; + +inline StatusCode ComputeFrameBufferInfo(int bitdepth, ImageFormat image_format, + int width, int height, int left_border, + int right_border, int top_border, + int bottom_border, + int stride_alignment, + FrameBufferInfo* info) { + return Libgav1ComputeFrameBufferInfo(bitdepth, image_format, width, height, + left_border, right_border, top_border, + bottom_border, stride_alignment, info); +} + +inline StatusCode SetFrameBuffer(const FrameBufferInfo* info, uint8_t* y_buffer, + uint8_t* u_buffer, uint8_t* v_buffer, + void* buffer_private_data, + FrameBuffer* frame_buffer) { + return Libgav1SetFrameBuffer(info, y_buffer, u_buffer, v_buffer, + buffer_private_data, frame_buffer); +} + +} // namespace libgav1 +#endif // defined(__cplusplus) + +#endif // LIBGAV1_SRC_GAV1_FRAME_BUFFER_H_ diff --git a/src/gav1/status_code.h b/src/gav1/status_code.h new file mode 100644 index 0000000..d7476ca --- /dev/null +++ b/src/gav1/status_code.h @@ -0,0 +1,118 @@ +/* + * Copyright 2019 The libgav1 Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBGAV1_SRC_GAV1_STATUS_CODE_H_ +#define LIBGAV1_SRC_GAV1_STATUS_CODE_H_ + +#include "gav1/symbol_visibility.h" + +// All the declarations in this file are part of the public ABI. This file may +// be included by both C and C++ files. + +// The Libgav1StatusCode enum type: A libgav1 function may return +// Libgav1StatusCode to indicate success or the reason for failure. +typedef enum { + // Success. + kLibgav1StatusOk = 0, + + // An unknown error. Used as the default error status if error detail is not + // available. + kLibgav1StatusUnknownError = -1, + + // An invalid function argument. + kLibgav1StatusInvalidArgument = -2, + + // Memory allocation failure. + kLibgav1StatusOutOfMemory = -3, + + // Ran out of a resource (other than memory). + kLibgav1StatusResourceExhausted = -4, + + // The object is not initialized. + kLibgav1StatusNotInitialized = -5, + + // An operation that can only be performed once has already been performed. + kLibgav1StatusAlready = -6, + + // Not implemented, or not supported. + kLibgav1StatusUnimplemented = -7, + + // An internal error in libgav1. Usually this indicates a programming error. + kLibgav1StatusInternalError = -8, + + // The bitstream is not encoded correctly or violates a bitstream conformance + // requirement. + kLibgav1StatusBitstreamError = -9, + + // The operation is not allowed at the moment. This is not a fatal error. Try + // again later. + kLibgav1StatusTryAgain = -10, + + // Used only by DequeueFrame(). There are no enqueued frames, so there is + // nothing to dequeue. This is not a fatal error. Try enqueuing a frame before + // trying to dequeue again. + kLibgav1StatusNothingToDequeue = -11, + + // An extra enumerator to prevent people from writing code that fails to + // compile when a new status code is added. + // + // Do not reference this enumerator. In particular, if you write code that + // switches on Libgav1StatusCode, add a default: case instead of a case that + // mentions this enumerator. + // + // Do not depend on the value (currently -1000) listed here. It may change in + // the future. + kLibgav1StatusReservedForFutureExpansionUseDefaultInSwitchInstead_ = -1000 +} Libgav1StatusCode; + +#if defined(__cplusplus) +extern "C" { +#endif + +// Returns a human readable error string in en-US for the status code |status|. +// Always returns a valid (non-NULL) string. +LIBGAV1_PUBLIC const char* Libgav1GetErrorString(Libgav1StatusCode status); + +#if defined(__cplusplus) +} // extern "C" + +namespace libgav1 { + +// Declare type aliases for C++. +using StatusCode = Libgav1StatusCode; +constexpr StatusCode kStatusOk = kLibgav1StatusOk; +constexpr StatusCode kStatusUnknownError = kLibgav1StatusUnknownError; +constexpr StatusCode kStatusInvalidArgument = kLibgav1StatusInvalidArgument; +constexpr StatusCode kStatusOutOfMemory = kLibgav1StatusOutOfMemory; +constexpr StatusCode kStatusResourceExhausted = kLibgav1StatusResourceExhausted; +constexpr StatusCode kStatusNotInitialized = kLibgav1StatusNotInitialized; +constexpr StatusCode kStatusAlready = kLibgav1StatusAlready; +constexpr StatusCode kStatusUnimplemented = kLibgav1StatusUnimplemented; +constexpr StatusCode kStatusInternalError = kLibgav1StatusInternalError; +constexpr StatusCode kStatusBitstreamError = kLibgav1StatusBitstreamError; +constexpr StatusCode kStatusTryAgain = kLibgav1StatusTryAgain; +constexpr StatusCode kStatusNothingToDequeue = kLibgav1StatusNothingToDequeue; + +// Returns a human readable error string in en-US for the status code |status|. +// Always returns a valid (non-NULL) string. +inline const char* GetErrorString(StatusCode status) { + return Libgav1GetErrorString(status); +} + +} // namespace libgav1 +#endif // defined(__cplusplus) + +#endif // LIBGAV1_SRC_GAV1_STATUS_CODE_H_ diff --git a/src/gav1/symbol_visibility.h b/src/gav1/symbol_visibility.h new file mode 100644 index 0000000..ad7498c --- /dev/null +++ b/src/gav1/symbol_visibility.h @@ -0,0 +1,88 @@ +/* + * Copyright 2019 The libgav1 Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBGAV1_SRC_GAV1_SYMBOL_VISIBILITY_H_ +#define LIBGAV1_SRC_GAV1_SYMBOL_VISIBILITY_H_ + +// This module defines the LIBGAV1_PUBLIC macro. LIBGAV1_PUBLIC, when combined +// with the flags -fvisibility=hidden and -fvisibility-inlines-hidden, restricts +// symbol availability when users use the shared object form of libgav1. The +// intent is to prevent exposure of libgav1 internals to users of the library, +// and to avoid ABI compatibility problems that changes to libgav1 internals +// would cause for users of the libgav1 shared object. +// +// Examples: +// +// This form makes a class and all of its members part of the public API: +// +// class LIBGAV1_PUBLIC A { +// public: +// A(); +// ~A(); +// void Foo(); +// int Bar(); +// }; +// +// A::A(), A::~A(), A::Foo(), and A::Bar() are all available to code linking to +// the shared object when this form is used. +// +// This form exposes a single class method as part of the public API: +// +// class B { +// public: +// B(); +// ~B(); +// LIBGAV1_PUBLIC int Foo(); +// }; +// +// In this examples only B::Foo() is available to the user of the shared object. +// +// Non-class member functions can also be exposed individually: +// +// LIBGAV1_PUBLIC void Bar(); +// +// In this example Bar() would be available to users of the shared object. +// +// Much of the above information and more can be found at +// https://gcc.gnu.org/wiki/Visibility + +#if !defined(LIBGAV1_PUBLIC) +#if defined(_WIN32) +#if defined(LIBGAV1_BUILDING_DLL) && LIBGAV1_BUILDING_DLL +#if defined(__GNUC__) +#define LIBGAV1_PUBLIC __attribute__((dllexport)) +#else +#define LIBGAV1_PUBLIC __declspec(dllexport) +#endif // defined(__GNUC__) +#elif defined(LIBGAV1_BUILDING_DLL) +#ifdef __GNUC__ +#define LIBGAV1_PUBLIC __attribute__((dllimport)) +#else +#define LIBGAV1_PUBLIC __declspec(dllimport) +#endif // defined(__GNUC__) +#else +#define LIBGAV1_PUBLIC +#endif // defined(LIBGAV1_BUILDING_DLL) && LIBGAV1_BUILDING_DLL +#else +#if defined(__GNUC__) && __GNUC__ >= 4 +#define LIBGAV1_PUBLIC __attribute__((visibility("default"))) +#else +#define LIBGAV1_PUBLIC +#endif +#endif // defined(_WIN32) +#endif // defined(LIBGAV1_PUBLIC) + +#endif // LIBGAV1_SRC_GAV1_SYMBOL_VISIBILITY_H_ diff --git a/src/gav1/version.h b/src/gav1/version.h new file mode 100644 index 0000000..78a573e --- /dev/null +++ b/src/gav1/version.h @@ -0,0 +1,71 @@ +/* + * Copyright 2019 The libgav1 Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBGAV1_SRC_GAV1_VERSION_H_ +#define LIBGAV1_SRC_GAV1_VERSION_H_ + +#include "gav1/symbol_visibility.h" + +// This library follows the principles described by Semantic Versioning +// (https://semver.org). + +#define LIBGAV1_MAJOR_VERSION 0 +#define LIBGAV1_MINOR_VERSION 16 +#define LIBGAV1_PATCH_VERSION 1 + +#define LIBGAV1_VERSION \ + ((LIBGAV1_MAJOR_VERSION << 16) | (LIBGAV1_MINOR_VERSION << 8) | \ + LIBGAV1_PATCH_VERSION) + +#if defined(__cplusplus) +extern "C" { +#endif + +// Returns the library's version number, packed in an int using 8 bits for +// each of major/minor/patch. e.g, 1.2.3 is 0x010203. +LIBGAV1_PUBLIC int Libgav1GetVersion(void); + +// Returns the library's version number as a string in the format +// 'MAJOR.MINOR.PATCH'. Always returns a valid (non-NULL) string. +LIBGAV1_PUBLIC const char* Libgav1GetVersionString(void); + +// Returns the build configuration used to produce the library. Always returns +// a valid (non-NULL) string. +LIBGAV1_PUBLIC const char* Libgav1GetBuildConfiguration(void); + +#if defined(__cplusplus) +} // extern "C" + +namespace libgav1 { + +// Returns the library's version number, packed in an int using 8 bits for +// each of major/minor/patch. e.g, 1.2.3 is 0x010203. +inline int GetVersion() { return Libgav1GetVersion(); } + +// Returns the library's version number as a string in the format +// 'MAJOR.MINOR.PATCH'. Always returns a valid (non-NULL) string. +inline const char* GetVersionString() { return Libgav1GetVersionString(); } + +// Returns the build configuration used to produce the library. Always returns +// a valid (non-NULL) string. +inline const char* GetBuildConfiguration() { + return Libgav1GetBuildConfiguration(); +} + +} // namespace libgav1 +#endif // defined(__cplusplus) + +#endif // LIBGAV1_SRC_GAV1_VERSION_H_ |