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/intreadwrite.h"
00024 #include "avcodec.h"
00025 #include "internal.h"
00026
00027 static av_cold int v410_encode_init(AVCodecContext *avctx)
00028 {
00029 if (avctx->width & 1) {
00030 av_log(avctx, AV_LOG_ERROR, "v410 requires width to be even.\n");
00031 return AVERROR_INVALIDDATA;
00032 }
00033
00034 avctx->coded_frame = avcodec_alloc_frame();
00035
00036 if (!avctx->coded_frame) {
00037 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00038 return AVERROR(ENOMEM);
00039 }
00040
00041 return 0;
00042 }
00043
00044 static int v410_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
00045 const AVFrame *pic, int *got_packet)
00046 {
00047 uint8_t *dst;
00048 uint16_t *y, *u, *v;
00049 uint32_t val;
00050 int i, j, ret;
00051
00052 if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4)) < 0)
00053 return ret;
00054 dst = pkt->data;
00055
00056 avctx->coded_frame->reference = 0;
00057 avctx->coded_frame->key_frame = 1;
00058 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00059
00060 y = (uint16_t *)pic->data[0];
00061 u = (uint16_t *)pic->data[1];
00062 v = (uint16_t *)pic->data[2];
00063
00064 for (i = 0; i < avctx->height; i++) {
00065 for (j = 0; j < avctx->width; j++) {
00066 val = u[j] << 2;
00067 val |= y[j] << 12;
00068 val |= (uint32_t) v[j] << 22;
00069 AV_WL32(dst, val);
00070 dst += 4;
00071 }
00072 y += pic->linesize[0] >> 1;
00073 u += pic->linesize[1] >> 1;
00074 v += pic->linesize[2] >> 1;
00075 }
00076
00077 pkt->flags |= AV_PKT_FLAG_KEY;
00078 *got_packet = 1;
00079 return 0;
00080 }
00081
00082 static av_cold int v410_encode_close(AVCodecContext *avctx)
00083 {
00084 av_freep(&avctx->coded_frame);
00085
00086 return 0;
00087 }
00088
00089 AVCodec ff_v410_encoder = {
00090 .name = "v410",
00091 .type = AVMEDIA_TYPE_VIDEO,
00092 .id = CODEC_ID_V410,
00093 .init = v410_encode_init,
00094 .encode2 = v410_encode_frame,
00095 .close = v410_encode_close,
00096 .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV444P10, PIX_FMT_NONE },
00097 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"),
00098 };