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 "internal.h"
00025 #include "bytestream.h"
00026
00027 static av_cold int encode_init(AVCodecContext *avctx)
00028 {
00029 avctx->coded_frame = avcodec_alloc_frame();
00030
00031 if (!avctx->coded_frame)
00032 return AVERROR(ENOMEM);
00033
00034 return 0;
00035 }
00036
00037 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
00038 const AVFrame *pic, int *got_packet)
00039 {
00040 int i, j, ret;
00041 int aligned_width = FFALIGN(avctx->width,
00042 avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64);
00043 int pad = (aligned_width - avctx->width) * 4;
00044 uint8_t *src_line;
00045 uint8_t *dst;
00046
00047 if ((ret = ff_alloc_packet2(avctx, pkt, 4 * aligned_width * avctx->height)) < 0)
00048 return ret;
00049
00050 avctx->coded_frame->reference = 0;
00051 avctx->coded_frame->key_frame = 1;
00052 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00053 src_line = pic->data[0];
00054 dst = pkt->data;
00055
00056 for (i = 0; i < avctx->height; i++) {
00057 uint16_t *src = (uint16_t *)src_line;
00058 for (j = 0; j < avctx->width; j++) {
00059 uint32_t pixel;
00060 uint16_t r = *src++ >> 6;
00061 uint16_t g = *src++ >> 6;
00062 uint16_t b = *src++ >> 4;
00063 if (avctx->codec_id == AV_CODEC_ID_R210)
00064 pixel = (r << 20) | (g << 10) | b >> 2;
00065 else
00066 pixel = (r << 22) | (g << 12) | b;
00067 if (avctx->codec_id == AV_CODEC_ID_AVRP)
00068 bytestream_put_le32(&dst, pixel);
00069 else
00070 bytestream_put_be32(&dst, pixel);
00071 }
00072 memset(dst, 0, pad);
00073 dst += pad;
00074 src_line += pic->linesize[0];
00075 }
00076
00077 pkt->flags |= AV_PKT_FLAG_KEY;
00078 *got_packet = 1;
00079 return 0;
00080 }
00081
00082 static av_cold int encode_close(AVCodecContext *avctx)
00083 {
00084 av_freep(&avctx->coded_frame);
00085
00086 return 0;
00087 }
00088
00089 #if CONFIG_R210_ENCODER
00090 AVCodec ff_r210_encoder = {
00091 .name = "r210",
00092 .type = AVMEDIA_TYPE_VIDEO,
00093 .id = AV_CODEC_ID_R210,
00094 .init = encode_init,
00095 .encode2 = encode_frame,
00096 .close = encode_close,
00097 .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE },
00098 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
00099 };
00100 #endif
00101 #if CONFIG_R10K_ENCODER
00102 AVCodec ff_r10k_encoder = {
00103 .name = "r10k",
00104 .type = AVMEDIA_TYPE_VIDEO,
00105 .id = AV_CODEC_ID_R10K,
00106 .init = encode_init,
00107 .encode2 = encode_frame,
00108 .close = encode_close,
00109 .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE },
00110 .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
00111 };
00112 #endif
00113 #if CONFIG_AVRP_ENCODER
00114 AVCodec ff_avrp_encoder = {
00115 .name = "avrp",
00116 .type = AVMEDIA_TYPE_VIDEO,
00117 .id = AV_CODEC_ID_AVRP,
00118 .init = encode_init,
00119 .encode2 = encode_frame,
00120 .close = encode_close,
00121 .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE },
00122 .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
00123 };
00124 #endif