00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MPF_CODEC_H
00020 #define MPF_CODEC_H
00021
00022
00023
00024
00025
00026
00027 #include "mpf_codec_descriptor.h"
00028
00029 APT_BEGIN_EXTERN_C
00030
00031
00032 typedef struct mpf_codec_vtable_t mpf_codec_vtable_t;
00033
00034 typedef struct mpf_codec_t mpf_codec_t;
00035
00036
00037 struct mpf_codec_t {
00038
00039 const mpf_codec_vtable_t *vtable;
00040
00041 const mpf_codec_attribs_t *attribs;
00042
00043 const mpf_codec_descriptor_t *static_descriptor;
00044 };
00045
00046
00047 struct mpf_codec_vtable_t {
00048
00049 apt_bool_t (*open)(mpf_codec_t *codec);
00050
00051 apt_bool_t (*close)(mpf_codec_t *codec);
00052
00053
00054 apt_bool_t (*encode)(mpf_codec_t *codec, const mpf_codec_frame_t *frame_in, mpf_codec_frame_t *frame_out);
00055
00056 apt_bool_t (*decode)(mpf_codec_t *codec, const mpf_codec_frame_t *frame_in, mpf_codec_frame_t *frame_out);
00057
00058
00059 apt_bool_t (*dissect)(mpf_codec_t *codec, void **buffer, apr_size_t *size, mpf_codec_frame_t *frame);
00060
00061
00062 apt_bool_t (*initialize)(mpf_codec_t *codec, mpf_codec_frame_t *frame_out);
00063 };
00064
00065
00066
00067
00068
00069
00070
00071
00072 static APR_INLINE mpf_codec_t* mpf_codec_create(
00073 const mpf_codec_vtable_t *vtable,
00074 const mpf_codec_attribs_t *attribs,
00075 const mpf_codec_descriptor_t *descriptor,
00076 apr_pool_t *pool)
00077 {
00078 mpf_codec_t *codec = (mpf_codec_t*)apr_palloc(pool,sizeof(mpf_codec_t));
00079 codec->vtable = vtable;
00080 codec->attribs = attribs;
00081 codec->static_descriptor = descriptor;
00082 return codec;
00083 }
00084
00085
00086
00087
00088
00089
00090 static APR_INLINE mpf_codec_t* mpf_codec_clone(mpf_codec_t *src_codec, apr_pool_t *pool)
00091 {
00092 mpf_codec_t *codec = (mpf_codec_t*)apr_palloc(pool,sizeof(mpf_codec_t));
00093 codec->vtable = src_codec->vtable;
00094 codec->attribs = src_codec->attribs;
00095 codec->static_descriptor = src_codec->static_descriptor;
00096 return codec;
00097 }
00098
00099
00100 static APR_INLINE apt_bool_t mpf_codec_open(mpf_codec_t *codec)
00101 {
00102 apt_bool_t rv = TRUE;
00103 if(codec->vtable->open) {
00104 rv = codec->vtable->open(codec);
00105 }
00106 return rv;
00107 }
00108
00109
00110 static APR_INLINE apt_bool_t mpf_codec_close(mpf_codec_t *codec)
00111 {
00112 apt_bool_t rv = TRUE;
00113 if(codec->vtable->close) {
00114 rv = codec->vtable->close(codec);
00115 }
00116 return rv;
00117 }
00118
00119
00120 static APR_INLINE apt_bool_t mpf_codec_encode(mpf_codec_t *codec, const mpf_codec_frame_t *frame_in, mpf_codec_frame_t *frame_out)
00121 {
00122 apt_bool_t rv = TRUE;
00123 if(codec->vtable->encode) {
00124 rv = codec->vtable->encode(codec,frame_in,frame_out);
00125 }
00126 return rv;
00127 }
00128
00129
00130 static APR_INLINE apt_bool_t mpf_codec_decode(mpf_codec_t *codec, const mpf_codec_frame_t *frame_in, mpf_codec_frame_t *frame_out)
00131 {
00132 apt_bool_t rv = TRUE;
00133 if(codec->vtable->decode) {
00134 rv = codec->vtable->decode(codec,frame_in,frame_out);
00135 }
00136 return rv;
00137 }
00138
00139
00140 static APR_INLINE apt_bool_t mpf_codec_dissect(mpf_codec_t *codec, void **buffer, apr_size_t *size, mpf_codec_frame_t *frame)
00141 {
00142 apt_bool_t rv = TRUE;
00143 if(codec->vtable->dissect) {
00144
00145 rv = codec->vtable->dissect(codec,buffer,size,frame);
00146 }
00147 else {
00148
00149 if(*size >= frame->size && frame->size) {
00150 memcpy(frame->buffer,*buffer,frame->size);
00151
00152 *buffer = (apr_byte_t*)*buffer + frame->size;
00153 *size = *size - frame->size;
00154 }
00155 else {
00156 rv = FALSE;
00157 }
00158 }
00159 return rv;
00160 }
00161
00162
00163 static APR_INLINE apt_bool_t mpf_codec_initialize(mpf_codec_t *codec, mpf_codec_frame_t *frame_out)
00164 {
00165 apt_bool_t rv = TRUE;
00166 if(codec->vtable->initialize) {
00167 rv = codec->vtable->initialize(codec,frame_out);
00168 }
00169 else {
00170 memset(frame_out->buffer,0,frame_out->size);
00171 }
00172 return rv;
00173 }
00174
00175 APT_END_EXTERN_C
00176
00177 #endif