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