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