From: Limin Wang <lance.lmw...@gmail.com> Signed-off-by: Limin Wang <lance.lmw...@gmail.com> --- libavcodec/Makefile | 2 +- libavcodec/bitpacked.c | 125 ------------------------------------------------- libavcodec/s210dec.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 126 deletions(-) delete mode 100644 libavcodec/bitpacked.c create mode 100644 libavcodec/s210dec.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 8ae28e8..1d75cfe 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -243,7 +243,7 @@ OBJS-$(CONFIG_BINK_DECODER) += bink.o binkdsp.o OBJS-$(CONFIG_BINKAUDIO_DCT_DECODER) += binkaudio.o OBJS-$(CONFIG_BINKAUDIO_RDFT_DECODER) += binkaudio.o OBJS-$(CONFIG_BINTEXT_DECODER) += bintext.o cga_data.o -OBJS-$(CONFIG_S210_DECODER) += bitpacked.o +OBJS-$(CONFIG_S210_DECODER) += s210dec.o OBJS-$(CONFIG_BMP_DECODER) += bmp.o msrledec.o OBJS-$(CONFIG_BMP_ENCODER) += bmpenc.o OBJS-$(CONFIG_BMV_AUDIO_DECODER) += bmvaudio.o diff --git a/libavcodec/bitpacked.c b/libavcodec/bitpacked.c deleted file mode 100644 index 7bc5dbc..0000000 --- a/libavcodec/bitpacked.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * S210 decoder - * Copyright (c) 2017 Savoir-faire Linux, Inc - * Copyright (c) 2021 Limin Wang - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* Development sponsored by CBC/Radio-Canada */ - -/** - * @file - * s210dec - */ - -#include "avcodec.h" -#include "internal.h" -#include "get_bits.h" -#include "libavutil/imgutils.h" - -struct S210Context { - int (*decode)(AVCodecContext *avctx, AVFrame *frame, - const AVPacket *pkt); -}; - -static int s210_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame, - const AVPacket *avpkt) -{ - uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20; - uint64_t packet_size = (uint64_t)avpkt->size * 8; - GetBitContext bc; - uint16_t *y, *u, *v; - int ret, i, j; - - ret = ff_get_buffer(avctx, frame, 0); - if (ret < 0) - return ret; - - if (frame_size > packet_size) - return AVERROR_INVALIDDATA; - - if (avctx->width % 2) - return AVERROR_PATCHWELCOME; - - ret = init_get_bits(&bc, avpkt->data, avctx->width * avctx->height * 20); - if (ret) - return ret; - - for (i = 0; i < avctx->height; i++) { - y = (uint16_t*)(frame->data[0] + i * frame->linesize[0]); - u = (uint16_t*)(frame->data[1] + i * frame->linesize[1]); - v = (uint16_t*)(frame->data[2] + i * frame->linesize[2]); - - for (j = 0; j < avctx->width; j += 2) { - *u++ = get_bits(&bc, 10); - *y++ = get_bits(&bc, 10); - *v++ = get_bits(&bc, 10); - *y++ = get_bits(&bc, 10); - } - } - - return 0; -} - -static av_cold int s210_init_decoder(AVCodecContext *avctx) -{ - struct S210Context *bc = avctx->priv_data; - - if (!avctx->width || !avctx->height) - return AVERROR_INVALIDDATA; - - if (avctx->bits_per_coded_sample == 20 && - avctx->pix_fmt == AV_PIX_FMT_YUV422P10) - bc->decode = s210_decode_yuv422p10; - else - return AVERROR_INVALIDDATA; - - return 0; -} - -static int s210_decode(AVCodecContext *avctx, void *data, int *got_frame, - AVPacket *avpkt) -{ - struct S210Context *bc = avctx->priv_data; - int buf_size = avpkt->size; - AVFrame *frame = data; - int res; - - frame->pict_type = AV_PICTURE_TYPE_I; - frame->key_frame = 1; - - res = bc->decode(avctx, frame, avpkt); - if (res) - return res; - - *got_frame = 1; - return buf_size; - -} - -const AVCodec ff_s210_decoder = { - .name = "s210", - .long_name = NULL_IF_CONFIG_SMALL("10-bit 4:2:2 packed"), - .type = AVMEDIA_TYPE_VIDEO, - .id = AV_CODEC_ID_S210, - .priv_data_size = sizeof(struct S210Context), - .init = s210_init_decoder, - .decode = s210_decode, - .capabilities = AV_CODEC_CAP_EXPERIMENTAL, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, -}; diff --git a/libavcodec/s210dec.c b/libavcodec/s210dec.c new file mode 100644 index 0000000..7bc5dbc --- /dev/null +++ b/libavcodec/s210dec.c @@ -0,0 +1,125 @@ +/* + * S210 decoder + * Copyright (c) 2017 Savoir-faire Linux, Inc + * Copyright (c) 2021 Limin Wang + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* Development sponsored by CBC/Radio-Canada */ + +/** + * @file + * s210dec + */ + +#include "avcodec.h" +#include "internal.h" +#include "get_bits.h" +#include "libavutil/imgutils.h" + +struct S210Context { + int (*decode)(AVCodecContext *avctx, AVFrame *frame, + const AVPacket *pkt); +}; + +static int s210_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame, + const AVPacket *avpkt) +{ + uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20; + uint64_t packet_size = (uint64_t)avpkt->size * 8; + GetBitContext bc; + uint16_t *y, *u, *v; + int ret, i, j; + + ret = ff_get_buffer(avctx, frame, 0); + if (ret < 0) + return ret; + + if (frame_size > packet_size) + return AVERROR_INVALIDDATA; + + if (avctx->width % 2) + return AVERROR_PATCHWELCOME; + + ret = init_get_bits(&bc, avpkt->data, avctx->width * avctx->height * 20); + if (ret) + return ret; + + for (i = 0; i < avctx->height; i++) { + y = (uint16_t*)(frame->data[0] + i * frame->linesize[0]); + u = (uint16_t*)(frame->data[1] + i * frame->linesize[1]); + v = (uint16_t*)(frame->data[2] + i * frame->linesize[2]); + + for (j = 0; j < avctx->width; j += 2) { + *u++ = get_bits(&bc, 10); + *y++ = get_bits(&bc, 10); + *v++ = get_bits(&bc, 10); + *y++ = get_bits(&bc, 10); + } + } + + return 0; +} + +static av_cold int s210_init_decoder(AVCodecContext *avctx) +{ + struct S210Context *bc = avctx->priv_data; + + if (!avctx->width || !avctx->height) + return AVERROR_INVALIDDATA; + + if (avctx->bits_per_coded_sample == 20 && + avctx->pix_fmt == AV_PIX_FMT_YUV422P10) + bc->decode = s210_decode_yuv422p10; + else + return AVERROR_INVALIDDATA; + + return 0; +} + +static int s210_decode(AVCodecContext *avctx, void *data, int *got_frame, + AVPacket *avpkt) +{ + struct S210Context *bc = avctx->priv_data; + int buf_size = avpkt->size; + AVFrame *frame = data; + int res; + + frame->pict_type = AV_PICTURE_TYPE_I; + frame->key_frame = 1; + + res = bc->decode(avctx, frame, avpkt); + if (res) + return res; + + *got_frame = 1; + return buf_size; + +} + +const AVCodec ff_s210_decoder = { + .name = "s210", + .long_name = NULL_IF_CONFIG_SMALL("10-bit 4:2:2 packed"), + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_S210, + .priv_data_size = sizeof(struct S210Context), + .init = s210_init_decoder, + .decode = s210_decode, + .capabilities = AV_CODEC_CAP_EXPERIMENTAL, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +}; -- 1.8.3.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".