00001 #ifndef _FRAME_H
00002 #define _FRAME_H
00003
00004 #include <string.h>
00005 #include "fourcc.h"
00006
00007 #ifdef __cplusplus
00008 extern "C" {
00009 #endif
00010
00011 typedef enum FrameType_
00012 {
00013 FMT_NONE = -1,
00014 FMT_RGB24 = 0,
00015 FMT_YV12,
00016 FMT_XVMC_IDCT_MPEG2,
00017 FMT_XVMC_MOCO_MPEG2,
00018 FMT_VIA_HWSLICE,
00019 FMT_IA44,
00020 FMT_AI44,
00021 FMT_ARGB32,
00022 FMT_RGBA32,
00023 FMT_YUV422P,
00024 FMT_ALPHA,
00025 } VideoFrameType;
00026
00027 typedef struct VideoFrame_
00028 {
00029 VideoFrameType codec;
00030 unsigned char *buf;
00031
00032 int width;
00033 int height;
00034 int bpp;
00035 int size;
00036
00037 long long frameNumber;
00038 long long timecode;
00039
00040 unsigned char *priv[4];
00041
00042 unsigned char *qscale_table;
00043 int qstride;
00044
00045 int interlaced_frame;
00046 int top_field_first;
00047 int repeat_pict;
00048 int forcekey;
00049
00050 int pitches[3];
00051 int offsets[3];
00052 } VideoFrame;
00053
00054 #ifdef __cplusplus
00055 }
00056 #endif
00057
00058 #ifdef __cplusplus
00059 static inline void init(
00060 VideoFrame *vf,
00061 VideoFrameType _codec, unsigned char *_buf,
00062 int _width, int _height, int _bpp, int _size,
00063 const int *p = 0, const int *o = 0) __attribute__ ((unused));
00064 static inline void clear(VideoFrame *vf, int fourcc) __attribute__ ((unused));
00065 static inline bool compatible(
00066 const VideoFrame *a, const VideoFrame *b) __attribute__ ((unused));
00067
00068 static inline void init(
00069 VideoFrame *vf,
00070 VideoFrameType _codec, unsigned char *_buf,
00071 int _width, int _height, int _bpp, int _size,
00072 const int *p, const int *o)
00073 {
00074 vf->codec = _codec;
00075 vf->buf = _buf;
00076 vf->width = _width;
00077 vf->height = _height;
00078
00079 vf->bpp = _bpp;
00080 vf->size = _size;
00081 vf->frameNumber = 0;
00082 vf->timecode = 0;
00083
00084 vf->qscale_table = 0;
00085 vf->qstride = 0;
00086
00087 vf->interlaced_frame = 1;
00088 vf->top_field_first = 1;
00089 vf->repeat_pict = 0;
00090 vf->forcekey = 0;
00091
00092
00093 memset(vf->priv, 0, 4 * sizeof(unsigned char *));
00094
00095 if (p)
00096 {
00097 memcpy(vf->pitches, p, 3 * sizeof(int));
00098 }
00099 else
00100 {
00101 if (FMT_YV12 == _codec || FMT_YUV422P == _codec)
00102 {
00103 vf->pitches[0] = _width;
00104 vf->pitches[1] = vf->pitches[2] = _width >> 1;
00105 }
00106 else
00107 {
00108 vf->pitches[0] = (_width * _bpp) >> 3;
00109 vf->pitches[1] = vf->pitches[2] = 0;
00110 }
00111 }
00112
00113 if (o)
00114 {
00115 memcpy(vf->offsets, o, 3 * sizeof(int));
00116 }
00117 else
00118 {
00119 if (FMT_YV12 == _codec)
00120 {
00121 vf->offsets[0] = 0;
00122 vf->offsets[1] = _width * _height;
00123 vf->offsets[2] = vf->offsets[1] + (vf->offsets[1] >> 2);
00124 }
00125 else if (FMT_YUV422P == _codec)
00126 {
00127 vf->offsets[0] = 0;
00128 vf->offsets[1] = _width * _height;
00129 vf->offsets[2] = vf->offsets[1] + (vf->offsets[1] >> 1);
00130 }
00131 else
00132 {
00133 vf->offsets[0] = vf->offsets[1] = vf->offsets[2] = 0;
00134 }
00135 }
00136 }
00137
00138 static inline void clear(VideoFrame *vf, int fourcc)
00139 {
00140 if (!vf)
00141 return;
00142
00143 if ((GUID_I420_PLANAR == fourcc) || (GUID_IYUV_PLANAR == fourcc) ||
00144 (GUID_YV12_PLANAR == fourcc))
00145 {
00146 int uv_height = vf->height >> 1;
00147
00148 memset(vf->buf + vf->offsets[0], 0, vf->pitches[0] * vf->height);
00149 memset(vf->buf + vf->offsets[1], 127, vf->pitches[1] * uv_height);
00150 memset(vf->buf + vf->offsets[2], 127, vf->pitches[2] * uv_height);
00151 }
00152 }
00153
00154 static inline bool compatible(const VideoFrame *a, const VideoFrame *b)
00155 {
00156 return a && b &&
00157 (a->codec == b->codec) &&
00158 (a->width == b->width) &&
00159 (a->height == b->height) &&
00160 (a->size == b->size) &&
00161 (a->offsets[0] == b->offsets[0]) &&
00162 (a->offsets[1] == b->offsets[1]) &&
00163 (a->offsets[2] == b->offsets[2]) &&
00164 (a->pitches[0] == b->pitches[0]) &&
00165 (a->pitches[1] == b->pitches[1]) &&
00166 (a->pitches[2] == b->pitches[2]);
00167 }
00168
00169 static inline void copy(VideoFrame *dst, const VideoFrame *src)
00170 {
00171 VideoFrameType codec = dst->codec;
00172 if (dst->codec != src->codec)
00173 return;
00174
00175 if (FMT_YV12 == codec)
00176 {
00177 int height0 = (dst->height < src->height) ? dst->height : src->height;
00178 int height1 = height0 >> 1;
00179 int height2 = height0 >> 1;
00180 int pitch0 = ((dst->pitches[0] < src->pitches[0]) ?
00181 dst->pitches[0] : src->pitches[0]);
00182 int pitch1 = ((dst->pitches[1] < src->pitches[1]) ?
00183 dst->pitches[1] : src->pitches[1]);
00184 int pitch2 = ((dst->pitches[2] < src->pitches[2]) ?
00185 dst->pitches[2] : src->pitches[2]);
00186
00187 memcpy(dst->buf + dst->offsets[0],
00188 src->buf + src->offsets[0], pitch0 * height0);
00189 memcpy(dst->buf + dst->offsets[1],
00190 src->buf + src->offsets[1], pitch1 * height1);
00191 memcpy(dst->buf + dst->offsets[2],
00192 src->buf + src->offsets[2], pitch2 * height2);
00193 }
00194 }
00195
00196 #endif
00197
00198 #endif
00199