00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "avcodec.h"
00024 #include "get_bits.h"
00025
00026 static av_cold int v410_decode_init(AVCodecContext *avctx)
00027 {
00028 avctx->pix_fmt = PIX_FMT_YUV444P10;
00029 avctx->bits_per_raw_sample = 10;
00030
00031 if (avctx->width & 1) {
00032 av_log(avctx, AV_LOG_ERROR, "v410 requires width to be even.\n");
00033 return AVERROR_INVALIDDATA;
00034 }
00035
00036 avctx->coded_frame = avcodec_alloc_frame();
00037
00038 if (!avctx->coded_frame) {
00039 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00040 return AVERROR(ENOMEM);
00041 }
00042
00043 return 0;
00044 }
00045
00046 static int v410_decode_frame(AVCodecContext *avctx, void *data,
00047 int *data_size, AVPacket *avpkt)
00048 {
00049 AVFrame *pic = avctx->coded_frame;
00050 uint8_t *src = avpkt->data;
00051 uint16_t *y, *u, *v;
00052 uint32_t val;
00053 int i, j;
00054
00055 if (pic->data[0])
00056 avctx->release_buffer(avctx, pic);
00057
00058 if (avpkt->size < 4*avctx->height*avctx->width) {
00059 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00060 return AVERROR(EINVAL);
00061 }
00062
00063 pic->reference = 0;
00064
00065 if (avctx->get_buffer(avctx, pic) < 0) {
00066 av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
00067 return AVERROR(ENOMEM);
00068 }
00069
00070 pic->key_frame = 1;
00071 pic->pict_type = FF_I_TYPE;
00072
00073 y = (uint16_t *)pic->data[0];
00074 u = (uint16_t *)pic->data[1];
00075 v = (uint16_t *)pic->data[2];
00076
00077 for (i = 0; i < avctx->height; i++) {
00078 for (j = 0; j < avctx->width; j++) {
00079 val = AV_RL32(src);
00080
00081 u[j] = (val >> 2) & 0x3FF;
00082 y[j] = (val >> 12) & 0x3FF;
00083 v[j] = (val >> 22);
00084
00085 src += 4;
00086 }
00087
00088 y += pic->linesize[0] >> 1;
00089 u += pic->linesize[1] >> 1;
00090 v += pic->linesize[2] >> 1;
00091 }
00092
00093 *data_size = sizeof(AVFrame);
00094 *(AVFrame *)data = *pic;
00095
00096 return avpkt->size;
00097 }
00098
00099 static av_cold int v410_decode_close(AVCodecContext *avctx)
00100 {
00101 if (avctx->coded_frame->data[0])
00102 avctx->release_buffer(avctx, avctx->coded_frame);
00103
00104 av_freep(&avctx->coded_frame);
00105
00106 return 0;
00107 }
00108
00109 AVCodec ff_v410_decoder = {
00110 .name = "v410",
00111 .type = AVMEDIA_TYPE_VIDEO,
00112 .id = CODEC_ID_V410,
00113 .init = v410_decode_init,
00114 .decode = v410_decode_frame,
00115 .close = v410_decode_close,
00116 .capabilities = CODEC_CAP_DR1,
00117 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"),
00118 };