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