00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00026 #include "avcodec.h"
00027 #include "libavutil/internal.h"
00028 
00029 typedef struct AuraDecodeContext {
00030     AVCodecContext *avctx;
00031     AVFrame frame;
00032 } AuraDecodeContext;
00033 
00034 static av_cold int aura_decode_init(AVCodecContext *avctx)
00035 {
00036     AuraDecodeContext *s = avctx->priv_data;
00037 
00038     s->avctx = avctx;
00039     
00040     if (avctx->width & 0x3)
00041         return -1;
00042     avctx->pix_fmt = PIX_FMT_YUV422P;
00043     avcodec_get_frame_defaults(&s->frame);
00044 
00045     return 0;
00046 }
00047 
00048 static int aura_decode_frame(AVCodecContext *avctx,
00049                              void *data, int *data_size,
00050                              AVPacket *pkt)
00051 {
00052     AuraDecodeContext *s=avctx->priv_data;
00053 
00054     uint8_t *Y, *U, *V;
00055     uint8_t val;
00056     int x, y;
00057     const uint8_t *buf = pkt->data;
00058 
00059     
00060     const int8_t *delta_table = (const int8_t*)buf + 16;
00061 
00062     if (pkt->size != 48 + avctx->height * avctx->width) {
00063         av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n",
00064                pkt->size, 48 + avctx->height * avctx->width);
00065         return -1;
00066     }
00067 
00068     
00069     buf += 48;
00070 
00071     if(s->frame.data[0])
00072         avctx->release_buffer(avctx, &s->frame);
00073 
00074     s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;
00075     s->frame.reference = 0;
00076     if(avctx->get_buffer(avctx, &s->frame) < 0) {
00077         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00078         return -1;
00079     }
00080 
00081     Y = s->frame.data[0];
00082     U = s->frame.data[1];
00083     V = s->frame.data[2];
00084 
00085     
00086     for (y = 0; y < avctx->height; y++) {
00087         
00088         val = *buf++;
00089         U[0] = val & 0xF0;
00090         Y[0] = val << 4;
00091         val = *buf++;
00092         V[0] = val & 0xF0;
00093         Y[1] = Y[0] + delta_table[val & 0xF];
00094         Y += 2; U++; V++;
00095 
00096         
00097         for (x = 1; x < (avctx->width >> 1); x++) {
00098             val = *buf++;
00099             U[0] = U[-1] + delta_table[val >> 4];
00100             Y[0] = Y[-1] + delta_table[val & 0xF];
00101             val = *buf++;
00102             V[0] = V[-1] + delta_table[val >> 4];
00103             Y[1] = Y[ 0] + delta_table[val & 0xF];
00104             Y += 2; U++; V++;
00105         }
00106         Y += s->frame.linesize[0] -  avctx->width;
00107         U += s->frame.linesize[1] - (avctx->width >> 1);
00108         V += s->frame.linesize[2] - (avctx->width >> 1);
00109     }
00110 
00111     *data_size=sizeof(AVFrame);
00112     *(AVFrame*)data= s->frame;
00113 
00114     return pkt->size;
00115 }
00116 
00117 static av_cold int aura_decode_end(AVCodecContext *avctx)
00118 {
00119     AuraDecodeContext *s = avctx->priv_data;
00120 
00121     if (s->frame.data[0])
00122         avctx->release_buffer(avctx, &s->frame);
00123 
00124     return 0;
00125 }
00126 
00127 AVCodec ff_aura2_decoder = {
00128     .name           = "aura2",
00129     .type           = AVMEDIA_TYPE_VIDEO,
00130     .id             = AV_CODEC_ID_AURA2,
00131     .priv_data_size = sizeof(AuraDecodeContext),
00132     .init           = aura_decode_init,
00133     .close          = aura_decode_end,
00134     .decode         = aura_decode_frame,
00135     .capabilities   = CODEC_CAP_DR1,
00136     .long_name      = NULL_IF_CONFIG_SMALL("Auravision Aura 2"),
00137 };